Polish version    English version  
  About Olympic -> Problems -> IV OI 1996/1997


 News
 About Olympic
About contest
Problems
I OI 1993/1994
II OI 1994/1995
III OI 1995/1996
IV OI 1996/1997
V OI 1997/1998
VI OI 1998/1999
VII OI 1999/2000
VIII OI 2000/2001
IX OI 2001/2002
X OI 2002/2003
XI OI 2003/2004
XII OI 2004/2005
XIII OI 2005/2006
XIV OI 2006/2007
XV OI 2007/2008
Problems archive
 History of OI
 OI books
 National team
 Olympic camps
 Photo gallery
 Links
 SIO
 MAIN
Niebieskie ksi.eczki
IV Olimpiada Informatyczna 1996/1997

Task: SKO
Author: Bogdan S. Chlebus
Jumps

I stage contest  
Source fileSKO.??? (e.g. PAS,C, CPP)
Executable fileSKO.EXE
Input fileSKO.IN
Output fileSKO.OUT

"Jumps" is a board game played on an infinite tape of squares. The board has neither left nor right limit. On the squares there is finitely many pieces (more than one piece on a square is allowed). We assume that the most left, non-empty square is numbered 0. Squares on the right are denoted by consecutive natural numbers 1, 2, 3, ..., squares on the left - by negative numbers: -1, -2, -3, ... . The configuration of pieces on the board can be described in the following way: for every square occupied by at least one piece we give the number of the square and the number of pieces standing on this square. There are two kinds of moves that can change the configuration: jump right and jump left. Jump right consists of removing two pieces from the board: one from a square p and the other from the square p+1, and placing one piece on the square p+2. Jump left consists of removing a piece from a square p+2 and placing two pieces on the board: one on the square p+1 and the other on the square p. We say that a configuration is final if each pair of neighbouring squares contains at most one piece. For every configuration there is exactly one final configuration that can be reached after finite number of moves (jumps).

Task

Write a program that:

  • reads a description of an initial configuration from the text file SKO.IN,
  • finds the final configuration that can be reached from the given initial configuration and writes the result to the text file SKO.OUT.

Input

In the first line of the file SKO.IN there is one positive integer n, 1 <= n <= 10000, which equals the number of non-empty squares of the given initial configuration. In each of the following n lines there is a description of one non-empty square of the initial configuration. Such a description consists of two integers. First is the number of the square, second - the number of pieces standing on this square. The descriptions are given in increasing order with respect to numbers of squares. The biggest number of a square is not greater than 10000 and the number of pieces on a single square is not greater than 100000000.

Output

In the first line of the file SKO.OUT there should be written the final configuration that can be reached from the given initial configuration. More precisely the line should contain the numbers of non-empty squares (in increasing order) of the final configuration. The numbers should be separated by single spaces.

Example

For the text file SKO.IN

2
0 5
3 3
the correct solution is the file SKO.OUT
-4 -1 1 3 5





Print friendly version