#P8086. Calculate Total Listening Time

    ID: 21269 Type: Default 1000ms 256MiB

Calculate Total Listening Time

Calculate Total Listening Time

Little C loves listening to music on NetEase Cloud Music and has recorded her listening history. She has n records where each record is in the format x t, meaning that she listened to the song with ID x for t minutes.

The total listening time is calculated by summing up the t values of all valid records. A record is valid if and only if:

  • t > 1. That is, any record where t ≤ 1 is considered invalid.

  • For each song, only the first valid record is counted; any subsequent valid records for the same song are ignored.

The task is to compute the total listening time according to these conditions.

Mathematically, if we denote each record by a pair \((x_i, t_i)\), then the total listening time \(T\) is given by:

\(T = \sum_{x \in S} t_x\)

where \(S\) is the set of song IDs for which there is at least one valid record, and \(t_x\) is the t from the first valid record for song \(x\). The summation includes only those records that satisfy \(t > 1\).

inputFormat

The first line contains a single integer n indicating the number of records.

Each of the next n lines contains two integers: x and t, representing the song ID and the duration (in minutes) respectively.

outputFormat

Output a single integer representing the total listening time calculated based on the valid records.

sample

3
1 2
2 2
1 3
4