#K56287. Minimum Waiting Time Station

    ID: 30165 Type: Default 1000ms 256MiB

Minimum Waiting Time Station

Minimum Waiting Time Station

You are given several stations, each with a queue of people waiting to purchase tickets. Each person is either an adult, a senior, or a child, which takes 1, 2, and 3 minutes respectively to process. Your task is to determine the station with the minimum total waiting time.

Formally, there are \(N\) stations. For each station, you are given an integer \(Y\) representing the number of people in the queue followed by \(Y\) integers. Each integer is either 1 (adult), 2 (senior), or 3 (child). The total waiting time for a station is the sum of the processing times, where processing times are given by:

  • Adult: \(1\) minute
  • Senior: \(2\) minutes
  • Child: \(3\) minutes

If multiple stations have the same minimum waiting time, choose the station with the smallest index (stations are 1-indexed).

inputFormat

The input is given via standard input (stdin) and has the following format:

N
Y1 a11 a12 ... a1Y1
Y2 a21 a22 ... a2Y2
...
YN aN1 aN2 ... aNYN

Where:

  • \(N\) (1 \(\leq\) N \(\leq\) 1000) is the number of stations.
  • For each station \(i\), the first number \(Y_i\) (1 \(\leq\) Y_i \(\leq\) 1000) represents the number of people in the queue, followed by \(Y_i\) integers each being 1, 2, or 3.

outputFormat

Output the 1-based index of the station with the minimum total waiting time to standard output (stdout).

## sample
3
3 1 2 1
2 2 1
4 1 3 2 1
2