Under construction

Still being built. Things may change

Let's Go to Jinju! (Hard)

Time limit3sMemory limit16 MB

Summary
Given N transport options with destinations and fares, print the fare to jinju and how many options cost more than that fare.
Level

Easy2 of 10

Topics
Implementation, String
Solved
No attempts yet

Problem

This problem is the same as "Let's Go to Jinju! (Easy)" except for the range of the input numbers. Be sure to check the language and memory limits.

Boseon, a Gyeongsang National University graduate worn out by life in Seoul, misses the college years and wants to visit Jinju, where the university is. So Boseon went straight to the Seoul bus terminal to make a day trip to Jinju.

The Seoul terminal has NN transportation options. Each option has a destination and a fare, and all destinations are distinct. The destinations always include jinju, which is the option going to Jinju.

With prices rising, Boseon wants to know the fare to Jinju and how many options cost more than that. Boseon is too exhausted to check all NN options, so Boseon asks us to find this information.

Now, help Boseon out.

Input

The first line contains NN, the number of transportation options at the Seoul terminal. (1≤N≤5 000 0001 \le N \le 5\,000\,000)

From the second line, the next NN lines each contain DiD_i and CiC_i, separated by a space. DiD_i is the destination of the ii-th option, a string of 1 to 15 lowercase English letters. Exactly one jj has Dj=D_j = jinju, meaning the jj-th option goes to Jinju. CiC_i is the fare of the ii-th option. (1≤Ci≤10151 \le C_i \le 10^{15}; 1≤Cj≤1 0001 \le C_j \le 1\,000)

All numbers in the input are integers.

Output

The first line prints the fare of the option to Jinju.

The second line prints the number of options that cost more than the option to Jinju.

Hint

The input is very large, so use fast input and output methods.

Examples1

  1. Example 1

    Input
    5
    changwon 100
    incheon 70
    jinju 90
    haenam 530
    gangneung 660
    
    Expected output
    90
    3