#P5940. [POI 1997] 跳

[POI 1997] 跳

Background

A checkers-like jumping game is played on an infinitely long board.

Problem Description

The board is divided into many regions, and each region can contain multiple pieces.

One specific region is numbered 00. The consecutive regions to its left are numbered 1,2,3,,-1,-2,-3,\ldots, and the consecutive regions to its right are numbered 1,2,3,,1,2,3,\ldots,. If region PP contains pieces, then a piece can be moved in two ways:

  • Jump left: add one piece to each of regions P1P-1 and P2P-2, and remove one piece from region PP.

  • Jump right: remove one piece from each of regions PP and P+1P+1, and add one piece to region P+2P+2.

For any given initial position, after some number of jumps, you can always reach a target position where the number of pieces in any two adjacent regions differs by at most 11.

Your task is: given an initial position, find the final target position.

Input Format

The first line contains a positive integer nn, which is the number of regions that initially contain pieces.

The next nn lines each describe one region, consisting of two integers separated by a space. The first integer is the index of the region (not exceeding 10410^4), and the second integer is the number of pieces in that region (not exceeding 10810^8).

Output Format

Output the final position in one line containing several integers. Each integer is the index of a region that contains pieces, and all region indices must be printed in increasing order.

2
0 5
3 3
-4 -1 1 3 5

Hint

For 100%100\% of the testdata, 1n1041 \le n \le 10^4.

Translated by ChatGPT 5