#!/usr/bin/perl $n = ; chomp $n; %birds = (); for $bird (split / /, ) { $birds{$bird}++; } $id = $n; $maxBirds = -1; for $bird (sort {$birds{$b} <=> $birds{$a}} keys %birds) { if ($maxBirds == $birds{$bird}) { $id = $bird if $id > $bird; } elsif ($maxBirds == -1) { $maxBirds = $birds{$bird}; $id = $bird; } else { last; } } print $id;