atcoder#AGC013C. [AGC013C] Ants on a Circle
[AGC013C] Ants on a Circle
Score : points
Problem Statement
There is a circle with a circumference of . Each point on the circumference has a coordinate value, which represents the arc length from a certain reference point clockwise to the point. On this circumference, there are ants. These ants are numbered through in order of increasing coordinate, and ant is at coordinate .
The ants have just started walking. For each ant , you are given the initial direction . Ant is initially walking clockwise if is ; counterclockwise if is . Every ant walks at a constant speed of per second. Sometimes, two ants bump into each other. Each of these two ants will then turn around and start walking in the opposite direction.
For each ant, find its position after seconds.
Constraints
- All input values are integers.
Input
The input is given from Standard Input in the following format:
Output
Print lines. The -th line should contain the coordinate of ant after seconds. Here, each coordinate must be between and , inclusive.
3 8 3
0 1
3 2
6 1
1
3
0
seconds after the ants start walking, ant and bump into each other at coordinate . second after that, ant and bump into each other at coordinate . seconds after that, that is, seconds after the ants start walking, ants , and are at coordinates , and , respectively.
4 20 9
7 2
9 1
12 1
18 1
7
18
18
1