Under construction

Still being built. Things may change

Binary Scale

Interview

Time limit1sMemory limit128 MB

Summary
Sort the given (reading, precision) pairs by reading divided by 2 to the precision, breaking ties by smaller reading.
Level

Easy3 of 10

Topics
Sorting
Solved
No attempts yet

Problem

A binary scale is a special device that can measure any value in the open interval (0,1)(0, 1) with a fixed precision. The precision is set with a dial that can be turned to 1,2,3,…,101, 2, 3, \dots, 10. When the precision is set to mm, the scale measures in units of 1/2m1 / 2^m.

A measurement is recorded as a pair (ℓ,m)(\ell, m). Such a pair means the precision is set to mm and the scale reads ℓ\ell, so the weight of the measured object is ℓ/2m\ell / 2^m. Here ℓ\ell is a positive integer, and since the scale only reads values in (0,1)(0, 1) we have 0<ℓ<2m0 < \ell < 2^m.

Write a program that orders the measurements from the smallest value to the largest. Each measurement is given as a pair (ℓ,m)(\ell, m). Different pairs that represent the same value (for example (1,2)(1, 2) and (2,3)(2, 3), both equal to 1/41/4) must be ordered by increasing reading ℓ\ell, the first element of the pair.

Input

The program reads from standard input. The first line contains an integer nn (1≤n≤20 0001 \le n \le 20\,000), the number of pairs. Each of the next nn lines contains one pair ℓi\ell_i and mim_i, separated by a single space. For every pair, 1≤mi≤101 \le m_i \le 10 and 1≤ℓi<2mi1 \le \ell_i < 2^{m_i}.

Output

The program writes to standard output. Output the nn input pairs, reordered so that pairs with smaller measured values come before pairs with larger measured values. Pairs with equal measured values are printed in non-decreasing order of their reading ℓ\ell. Print each pair in the same format as the input, that is, the two integers ℓi\ell_i and mim_i separated by a single space.

Examples1

  1. Example 1

    Input
    4
    1000 10
    3 10
    5 3
    250 8
    
    Expected output
    3 10
    5 3
    250 8
    1000 10