Problem: There is a circle with a circumference of L. 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 N ants. These ants are numbered 1 through N in order of increasing coordinate, and ant i is at coordinate X_i.  The N ants have just started walking. For each ant i, you are given the initial direction W_i. Ant i is initially walking clockwise if W_i is 1; counterclockwise if W_i is 2. Every ant walks at a constant speed of 1 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 T seconds.

Submission attempts (in order):
import sys
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7
 
def main():
    N, L, T = map(int, readline().split())
    position = []
    count = 0
    for i in range(N):
        x,w = map(int, readline().split())
        if w==1:
        	count += (x+T)//L
            position.append((x+T)%L)
        else:
            if x-T<0:
                count += (x-T)//L
            position.append((x-T)%L)
    position.sort()
    count %= N
    ans = position[count:] + position[:count]
    for i in range(N):
        print(ans[i])

import sys
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7
 
def main():
    N, L, T = map(int, readline().split())
    position = []
    cnt = 0
    for i in range(N):
        x,w = map(int, readline().split())
        if w==1:
        	cnt += (x+T)//L
            position.append((x+T)%L)
        else:
            if x-T<0:
                cnt += (x-T)//L
            position.append((x-T)%L)
    position.sort()
    cnt %= N
    ans = position[count:] + position[:count]
    for i in range(N):
        print(ans[i])

import sys
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7
 
def main():
    N, L, T = map(int, readline().split())
    position = []
    
    cnt = 0
    for i in range(N):
      x, w = map(int, input().split())
      if w == 1:
        cnt += (x - T)//L
        position.append((x-T)%L)
      else:
        if x-T < 0:
          cnt += (x - T)//L
        position.append((x - T)%L)
	position.sort()
    cnt %= N
    
    ans = position[cnt:] + position[:cnt]
    for i in range(N):
      print(ans[i])
        
        

import sys
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7
 
def main():
    N, L, T = map(int, readline().split())
    position = []
    cnt = 0
    for i in range(N):
        x,w = map(int, readline().split())
        if w==1:
        	cnt += (x+T)//L
            position.append((x+T)%L)
        else:
            if x-T<0:
                cnt += (x-T)//L
            position.append((x-T)%L)
    position.sort()
    cnt %= N
    ans = position[cnt:] + position[:cnt]
    for i in range(N):
        print(ans[i])


def main():
    N, L, T = map(int, input().split())
    collision = 0
    ants = []
    for i in range(N):
        x, w = map(int, input().split())
        if w == 1:
            collision += (x + T) // L
            a = (x + T) % L
        else:
            collision += (x - T) // L
            a = (x - T) % L
        ants.append(a)
 
    collision %= N
    ants.sort()
    ants = ants[collision:] + ants[:collision]
    for ant in ants:
        print(ant)
 
 
if __name__ == '__main__':
    main()


Verdicts: Runtime Error

Runtime Error

Runtime Error

Runtime Error

Accepted