#C10752. Finding the Most Frequent Theme

    ID: 39992 Type: Default 1000ms 256MiB

Finding the Most Frequent Theme

Finding the Most Frequent Theme

In this problem, you are given a table with ( n ) positions (numbered from 1 to ( n )). Initially, every position in the table has no assigned theme (represented by 0). Then, you will be given ( m ) instructions. Each instruction is represented as a triplet ( (a, b, t) ) which means that every position from index ( a ) to ( b ) (inclusive) should be assigned theme ( t ). After processing all the instructions, your task is to determine the theme that appears most frequently on the table. In case of a tie (i.e. multiple themes appear equally often), you should return the smallest theme ID.

Example:
For ( n = 10 ) and ( m = 4 ) with the instructions:
1 5 3
4 7 2
8 10 3
3 6 4

After applying these instructions, the theme with the highest frequency is theme 3.

inputFormat

The input is read from standard input. The first line contains two integers ( n ) and ( m ), representing the number of positions in the table and the number of instructions, respectively. The following ( m ) lines each contain three integers ( a ), ( b ), and ( t ), representing an instruction to assign theme ( t ) to positions from ( a ) to ( b ) (inclusive).

outputFormat

Output a single integer — the theme ID that appears most frequently on the table after all instructions are executed. In case of a tie, output the smallest theme ID.## sample

10 4
1 5 3
4 7 2
8 10 3
3 6 4
3