This page is still under construction.

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

Jumps

Time limit1sMemory limit128 MB

Summary
Given piles of pieces on numbered squares, repeatedly apply the jump rules until no two neighbouring squares together hold two or more pieces, then print the occupied squares.
Level

Medium6 of 10

Topics
Greedy, Simulation, Math, Implementation
Solved
No attempts yet

Problem

"Jumps" is a board game played on a tape of squares that extends without bound to the left and to the right. Finitely many pieces stand on the squares, and a single square may hold more than one piece. The leftmost non-empty square is numbered 0. Squares to the right are numbered 1, 2, 3, ..., and squares to the left are numbered -1, -2, -3, .... A configuration is described by listing, for every occupied square, the square's number together with the number of pieces on it.

Two kinds of moves change a configuration:

  • Jump right: remove one piece from a square pp and one piece from square p+1p+1, then place one piece on square p+2p+2.
  • Jump left: remove one piece from a square p+2p+2, then place one piece on square p+1p+1 and one piece on square pp.

A configuration is final when every pair of neighbouring squares holds at most one piece in total. Starting from any configuration, a finite sequence of moves always leads to exactly one final configuration.

Given the initial configuration, compute the final configuration it reaches.

Input

The first line contains one integer nn (1≤n≤100001 \le n \le 10000), the number of non-empty squares in the initial configuration.

Each of the next nn lines describes one non-empty square with two integers: the square's number and the number of pieces on it. The squares are listed in increasing order of their numbers. Every square number is at most 1000010000, and every square holds at most 10810^8 pieces.

Output

Print a single line with the numbers of the occupied squares of the final configuration, in increasing order, separated by single spaces.

Examples3

  1. Example 1

    Input
    2
    0 5
    3 3
    
    Expected output
    -4 -1 1 3 5
    
  2. Example 2

    Input
    1
    0 1
    
    Expected output
    0
    
  3. Example 3

    Input
    2
    0 1
    1 1
    
    Expected output
    2