#C7805. Most Frequent Second Element
Most Frequent Second Element
Most Frequent Second Element
Given a list of n pairs of integers, your task is to determine the most frequent second element among all pairs. In the event of a tie, output the element that appears first in the list based on its first occurrence.
Input Format:
The first line contains an integer n, the number of pairs. Each of the following n lines contains two space-separated integers representing a pair.
Output Format:
A single integer which is the most frequent second element. In the event of a tie, the element with the first occurrence is returned.
Note: Read input from stdin
and write output to stdout
.
inputFormat
The input consists of multiple lines. The first line contains an integer n (the number of pairs). Each of the next n lines contains two space-separated integers.
outputFormat
Output a single integer — the most frequent second element among the given pairs. If there is a tie, output the element that appears first in the input order.
## sample5
10 20
20 30
30 20
20 10
20 20
20