This page is still under construction.

Parts of this page are still being built. What you see may change.

Putnam Rank Range

Interview

Time limit2sMemory limit512 MB

Summary
Given the average rank for each distinct score, find the rank range occupied by the block of contestants holding your score.
Level

Medium5 of 10

Topics
Math, Implementation
Solved
No attempts yet

Problem

After strong results in programming contests, you take part in the Putnam mathematical competition. In this contest a higher score means a better (smaller) rank. Contestants who attain the same score are all tied and together occupy a block of consecutive ranks.

The average rank of a score is the arithmetic mean of the ranks occupied by the contestants who attained it. For example, if three people are tied across ranks 1, 2 and 3, the average rank of that score is 22.

Given the average rank of every distinct score, determine the exact range of ranks (from the best rank to the worst rank) that your score occupies. For instance, if 2525 contestants scored higher than you and, counting yourself, 44 contestants share your score, then your range is 2626–2929.

Input

The first line contains an integer NN (1≤N≤1000001 \le N \le 100000).

Each of the next NN lines contains two numbers separated by a space. The first is a score SS attained by one or more contestants; it is an integer with 0≤S≤3⋅1090 \le S \le 3 \cdot 10^9. The second is the average rank RR for that score, with 0≤R≤3⋅1080 \le R \le 3 \cdot 10^8; it is a decimal that is always a multiple of 0.50.5 (for example 20.5).

The last line contains your score, which is guaranteed to equal the first number on one of the previous NN lines.

The NN score lines are not necessarily given in sorted order.

Output

Print two lines: the best (smallest) rank and the worst (largest) rank of the block of contestants who share your score, in that order.

Examples3

  1. Example 1

    Input
    6
    5 2
    4 10
    3 20.5
    1 34
    0 35
    2 29
    4
    
    Expected output
    4
    16
    
  2. Example 2

    Input
    6
    5 2
    4 10
    3 20.5
    1 34
    0 35
    2 29
    5
    
    Expected output
    1
    3
    
  3. Example 3

    Input
    6
    5 2
    4 10
    3 20.5
    1 34
    0 35
    2 29
    0
    
    Expected output
    35
    35