#P8086. 『JROI-5』Music

『JROI-5』Music

Background

Please note the unusual time limit.

This problem has a large input size, so it is recommended to use a fast input method.

Little C needs to spend money on Boss Ding every year.

Problem Description

Little C likes listening to music on NetEase Cloud Music, and she wants you to help her calculate her total listening time on NetEase Cloud Music.

Little C has nn listening records. Each record is in the form x t, which means Little C listened to the song with id xx for tt minutes. The listening time is the sum of tt over all valid records.

First, if a record has t1t \leq 1, then this record is invalid.

Second, for any given song, only the first valid record will be counted. After that, repeated records of listening to the same song will not be added to the listening time.

Input Format

The first line contains a positive integer nn, as described.

The next nn lines each contain two positive integers x,tx, t, representing one listening record.

Output Format

Output one integer on one line, representing the listening time.

5
1 114514
2 1
2 1919180
1 10
3 2
2033696
见附件
见附件

Hint

[Sample Explanation]

The 1st record: 1 114514, a valid record, can be counted.

The 2nd record: 2 1, t1t \leq 1, an invalid record.

The 3rd record: 2 1919180, a valid record, can be counted.

The 4th record: 1 10, the song with id 11 has already been counted in the 1st record. This record is valid, but cannot be counted.

The 5th record: 3 2, a valid record, can be counted.

So the answer is 114514+1919180+2=2033696114514 + 1919180 + 2 = 2033696.


For 40%40\% of the testdata, it is guaranteed that 1xn1041 \leq x \leq n \leq 10^4.

For 100%100\% of the testdata, it is guaranteed that 1n1071 \leq n \leq 10^7 and 1x,ti1071 \leq x, t_i \leq 10^7.

Translated by ChatGPT 5