#C2857. Most Frequent Element

    ID: 46219 Type: Default 1000ms 256MiB

Most Frequent Element

Most Frequent Element

You are given a list of integers. Your task is to find the element which appears most frequently in the list. In the event of a tie (i.e. multiple elements share the maximum frequency), you should return the element that appears first in the list.

Formally, let \( f(x) \) denote the frequency of element \( x \) in the list. You need to find an element \( a \) such that \( f(a)=\max_{x}{f(x)} \), and if there is more than one such \( a \), output the one that occurs first in the input order.

inputFormat

The first line contains a single integer ( N ) denoting the number of elements in the list. The second line contains ( N ) space-separated integers.

outputFormat

Print the most frequent element. If multiple elements have the same highest frequency, print the one that appears first in the list.## sample

1
1
1

</p>