637A.md (1545B)
1 Source: https://codeforces.com/problemset/problem/637/A 2 3 A. Voting for Photos 4 5 time limit per test 6 7 1 second 8 9 memory limit per test 10 11 256 megabytes 12 13 input 14 15 standard input 16 17 output 18 19 standard output 20 21 After celebrating the midcourse the students of one of the faculties of the Berland State University decided to conduct a vote for the best photo. They published the photos in the social network and agreed on the rules to choose a winner: the photo which gets most likes wins. If multiple photoes get most likes, the winner is the photo that gets this number first. 22 23 Help guys determine the winner photo by the records of likes. 24 25 Input 26 27 The first line of the input contains a single integer *n* (1 ≤ *n* ≤ 1000) — the total likes to the published photoes. 28 29 The second line contains *n* positive integers *a*1, *a*2, ..., *a**n* (1 ≤ *a**i* ≤ 1 000 000), where *a**i* is the identifier of the photo which got the *i*-th like. 30 31 Output 32 33 Print the identifier of the photo which won the elections. 34 35 Examples 36 37 Input 38 39 ``` 40 5 41 1 3 2 2 1 42 ``` 43 44 Output 45 46 ``` 47 2 48 ``` 49 50 Input 51 52 ``` 53 9 54 100 200 300 200 100 300 300 100 200 55 ``` 56 57 Output 58 59 ``` 60 300 61 ``` 62 63 Note 64 65 In the first test sample the photo with id 1 got two likes (first and fifth), photo with id 2 got two likes (third and fourth), and photo with id 3 got one like (second). 66 67 Thus, the winner is the photo with identifier 2, as it got: 68 69 * more likes than the photo with id 3; 70 * as many likes as the photo with id 1, but the photo with the identifier 2 got its second like earlier.