#K46872. Most Frequent Product ID
Most Frequent Product ID
Most Frequent Product ID
You are given records of product IDs from several files. Each record is a list of integers representing product IDs.
Your task is to determine the product ID that occurs most frequently across all records. If more than one product ID has the highest frequency, you should return the smallest product ID among them.
Formally, let \(R_1, R_2, \dots, R_T\) be the records. The overall frequency of an ID \(x\) is \[ f(x)=\sum_{i=1}^{T} \textbf{1}_{\{x \in R_i\}}\] where \(\textbf{1}_{\{x \in R_i\}}\) is the number of occurrences of \(x\) in record \(R_i\). You need to output the smallest \(x\) such that \(f(x)\) is maximized.
inputFormat
The input is read from standard input (stdin) and has the following format:
- The first line contains an integer \(T\) denoting the number of records.
- For each record, there is one line beginning with an integer \(N\) denoting the number of integers in that record, followed by \(N\) integers separated by spaces.
For example:
3 5 1 2 3 4 1 7 3 1 1 2 2 2 3 7 5 6 6 2 2 1 1
outputFormat
Output a single integer to standard output (stdout) – the most frequent product ID. If there is a tie in frequency, output the smallest product ID among those.
## sample3
5 1 2 3 4 1
7 3 1 1 2 2 2 3
7 5 6 6 2 2 1 1
1