P8086 "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.

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 $n$ listening records. Each record is in the form `x t`, which means Little C listened to the song with id $x$ for $t$ minutes. The listening time is the sum of $t$ over all valid records. First, if a record has $t \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 $n$, as described. The next $n$ lines each contain two positive integers $x, t$, representing one listening record.

Output Format

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

Explanation/Hint

[Sample Explanation] The 1st record: `1 114514`, a valid record, can be counted. The 2nd record: `2 1`, $t \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 $1$ 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 = 2033696$. ___ For $40\%$ of the testdata, it is guaranteed that $1 \leq x \leq n \leq 10^4$. For $100\%$ of the testdata, it is guaranteed that $1 \leq n \leq 10^7$ and $1 \leq x, t_i \leq 10^7$. Translated by ChatGPT 5