#K14986. Busiest Time

    ID: 24256 Type: Default 1000ms 256MiB

Busiest Time

Busiest Time

You are given several bus schedules. Each schedule is represented by three integers: start, end, and frequency. For a given schedule, buses stop at times \(t = start, start + frequency, start + 2 \times frequency, \dots \) while \(t < end\). Your task is to determine the minute of the day (from 0 to 1440) at which the maximum number of buses stop. In case of a tie, choose the earliest minute.

Note: The input is provided via standard input (stdin) and the output should be written to standard output (stdout). Use appropriate methods depending on your programming language.

inputFormat

The first line contains an integer \(m\) representing the number of bus schedules. The following \(m\) lines each contain three space-separated integers \(s\), \(e\), and \(f\) where:

  • \(s\) is the start time (in minutes).
  • \(e\) is the end time (in minutes, non-inclusive).
  • \(f\) is the frequency interval (in minutes).

outputFormat

Output a single integer representing the minute at which the maximum number of buses stop. If multiple minutes have the same maximum count, output the smallest (earliest) minute.

## sample
3
60 180 20
100 200 30
150 300 10
150

</p>