Problem:


Score : 700 points

Problem Statement

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.

Constraints

All input values are integers.

1 \leq N \leq 10^5

1 \leq L \leq 10^9

1 \leq T \leq 10^9

0 \leq X_1 < X_2 < ... < X_N \leq L - 1

1 \leq W_i \leq 2

Input

The input is given from Standard Input in the following format:

N L T
X_1 W_1
X_2 W_2
:
X_N W_N

Output

Print N lines.
The i-th line should contain the coordinate of ant i after T seconds. Here, each coordinate must be between 0 and L-1, inclusive.

Sample Input 1

3 8 3
0 1
3 2
6 1

Sample Output 1

1
3
0

1.5 seconds after the ants start walking, ant 1 and 2 bump into each other at coordinate 1.5.
1 second after that, ant 1 and 3 bump into each other at coordinate 0.5.
0.5 seconds after that, that is, 3 seconds after the ants start walking, ants 1, 2 and 3 are at coordinates 1, 3 and 0, respectively.

Sample Input 2

4 20 9
7 2
9 1
12 1
18 1

Sample Output 2

7
18
18
1



Sample input:
3 8 3
0 1
3 2
6 1


Sample output:
1
3
0

Submission status: Wrong Answer

Solution code:
n,l,t=map(int,input().split())
xw=[list(map(int,input().split()))for _ in range(n)]
p=[(xw[i][0]+((1 if xw[i][1]==1 else -1)*t))%l for i in range(n)]
p.sort()
x,w=xw[0]
ind=p.index((x+((1 if w==1 else -1)*t))%l)
for xx,ww in xw[1:]:
  if w!=ww:
    ind+=2*(t%l)*(1 if w==2 else -1)
    if w==1:
      m=xx-x
    else:
      m=((l-1)-xx)+(x-0)
    if m<=t%l:ind+=1*(1 if w==2 else -1)
    ind%=n
p=p[ind:]+p[:ind]
print(*p)

Submission status: Wrong Answer

Solution code:
n,l,t=map(int,input().split())
xw=[list(map(int,input().split()))for _ in range(n)]
p=[(xw[i][0]+((1 if xw[i][1]==1 else -1)*t))%l for i in range(n)]
x,w=xw[0]
ind=0
for xx,ww in xw[1:]:
  if w!=ww:
    ind+=2*(t%l)*(1 if w==2 else -1)
    if w==1:
      m=xx-x
    else:
      m=((l-1)-xx)+(x-0)
    if m<=t%l:ind+=1*(1 if w==2 else -1)
    ind%=n
p=p[ind:]+p[:ind]
for i in p:print(i)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
n,l,t = map(int,input().split())
c = []
for i in range(n):
  x,w = map(int,input().split())
  if w == 1:
    c.append((x+t,w,i))
  else:
    c.append((x-t,w,i))
    
p,q,r = c[0]
st = 0
ans = c.copy()
for x,w,i in c[::-1]:
  if q != w:
    if q > w and p < x:
      st = i
    elif q < w and p > x:
      st = i       
    break
    
if st != 0:
  p,q,r = c[i]
  C = c[st:]
  for x,w,i in C[::-1]:
    if q != w:
      if q > w and p < x:
        st = i
      elif q < w and p > x:
        st = i    
      break
    
  ans_1 = c[i:]
  ans_2 = c[:i]
  ans = ans_1+ans_2
  
for A,N,S in ans:
  print(A%l)

Submission status: Wrong Answer

Solution code:
import bisect

n,l,t = map(int, input().split())
xw = [list(map(int, input().split())) for i in range(n)]
clockwise = []
anticlockwise = []
ans = [None] * n
for key,(x,w) in enumerate(xw):
    if w == 1:
        clockwise.append((x,key))
    else:
        anticlockwise.append((x,key))

len_c = len(clockwise)
len_a = len(anticlockwise)
for key,(x,w) in enumerate(xw):
    if w == 1:
        tmp = bisect.bisect_right(anticlockwise, ((2*t+x)%l,1000000)) - bisect.bisect_right(anticlockwise,(x,0))
        lap = (x+2*t) // l
        num = (key + tmp + lap * len_a) % n
        ans[num] = (x + t) % l
    else:
        tmp = bisect.bisect_left(clockwise, (x,-1)) - bisect.bisect_left(clockwise, ((x-2*t)%l,-1))
        lap = (x-2*t) // l
        num = (key - tmp + lap * len_c) % n
        ans[num] = (x - t) % l

print(ans)

Submission status: Wrong Answer

Solution code:
N, L, T = map(int, input().split())
lst = [tuple(map(int, input().split())) for i in range(N)]
lst2 = []
count = 0
a = T % L

base = None
for tpl in lst:
    if tpl[1] == 1:
        lst2.append(tpl[0]+T)
    elif tpl[1] == 2:
        lst2.append(tpl[0]-T)
    
    if base == None:
        base = tpl
    elif tpl[1] != base[1]:
        if  (tpl[0]-base[0]) <= a and base[1] ==1:
            count += 1
        elif a < (tpl[0]-base[0]) <= 2*a and base[1] ==1:
            count += 2
        elif (L-tpl[0]+base[0]) <= a and base[1] == 2:
            count -= 1
        elif a < (L-tpl[0]+base[0]) <= 2*a and base[1] == 2:
            count -= 2
    print(count)
count = count % N
for i in range(N):
    lst2[i] = lst2[i] % L
#print(lst2)
#print(count)
for i in lst2:
    print(lst2[(i+count) % N])

Submission status: Wrong Answer

Solution code:
N, L, T = map(int, input().split())
X, W = [0] * N, [0] * N
for i in range(N):
    X[i], W[i] = map(int, input().split())

c = 0
for i in range(1, N):
    if W[0] == W[i]:
        continue
    res = T - abs(X[0] - X[i]) / 2
    if res > 0:
        c += int(res // (L / 2)) + 1
if W[0] == 2:
    c = N - (c % N)

tmp = [0] * N
for i in range(N):
    if W[i] == 1:
        tmp[i] = (X[i] + T) % L
    else:
        tmp[i] = ((X[i] - T) % L + L) % L
tmp = sorted(tmp)
print(*[x for x in tmp[c:] + tmp[:c]], sep='\n')

Submission status: Wrong Answer

Solution code:
N, L, T = map(int, input().split())
X, W = [0] * N, [0] * N
for i in range(N):
    X[i], W[i] = map(int, input().split())

c = 0
for i in range(1, N):
    if W[0] == W[i]:
        continue
    res = T - abs(X[0] - X[i]) / 2
    if res > 0:
        c += int(res // (L / 2)) + 1
if W[0] == 2:
    c = N - c % N

tmp = [0] * N
for i in range(N):
    if W[i] == 1:
        tmp[i] = (X[i] + T) % L
    else:
        tmp[i] = ((X[i] - T) % L + L) % L
tmp = sorted(tmp)
print(*[x for x in tmp[c:] + tmp[:c]], sep='\n')

Submission status: Wrong Answer

Solution code:
import sys
import math
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def S(): return sys.stdin.readline()
def LS(): return sys.stdin.readline().split()
def LS2(N): return [sys.stdin.readline().split() for i in range(N)]
def FILL(i,h,w): return [[i for j in range(w)] for k in range(h)]
def sisha(num,digit): return Decimal(str(num)).quantize(Decimal(digit),rounding=ROUND_HALF_UP)
#'0.01'や'1E1'などで指定、整数に戻すならintをかます
MOD = 1000000007
INF = float("inf")
sys.setrecursionlimit(10**5+10)
input = sys.stdin.readline

N,L,T = MI()
for_l = []
rev_l = []
final = []
for i in range(N):
    if i==0:
        x0,w0 = MI()
        x,w = x0,w0
    else:
        x,w = MI()
    if w==1:
        for_l += [x]
        final += [(x+T)%L]
    else:
        rev_l += [x]
        final += [(x-T)%L]

final.sort()
opposite_l = rev_l if w0==1 else for_l
opp_num = len(opposite_l)
cicle = (2*T)//L
res = (2*T)%L
cnt = 0 #i=1のアリが衝突する回数
cnt += opp_num*cicle
if res!=0 and res!=1:
    xr = (x0 + res -1)%L if w0==1 else x0
    xl = x0 if w0==1 else (x0-res+1)%L
    for i in opposite_l:
        if xl<=xr and xl<=i<=xr:
            cnt += 1
        if xl>xr and (i>=xl or i<=xr):
            cnt += 1
c = (cnt)%N #x0+Tにくるアリの番号
if w0==1:
    c_idx = final.index((x0+T)%L)
else:
    c_idx_l = [i for i,v in enumerate(final) if v==(x0-T)%L]
    c_idx = c_idx_l[-1]
ans = [-1 for i in range(N)]
ans[c] = final[c_idx]
for i in range(1,N):
    ans[(c+i)%N] = final[(c_idx+i)%N]
[print(x) for x in ans]

Submission status: Wrong Answer

Solution code:
N, L, T=map(int, input().split())
XW=[list(map(int, input().split())) for _ in range(N)]
X_=[(XW[i][0]+T)%L if XW[i][1]==1 else (XW[i][0]-T)%L for i in range(N)]
X_.sort()
A0_=(XW[0][0]+T)%L if XW[0][1]==1 else (XW[0][0]-T)%L
P0_=X_.index(A0_)
if P0_>0:
    X_=X_[P0_:]+X_[:P0_]
    
if XW[0][1]==1:
    C0_=round(sum([(T-(XW[i][0]-XW[0][0])/2)//(L/2)+1 if XW[i][1]!=1 and (XW[i][0]-XW[0][0])/2<=T else 0 for i in range(1, N)])%N)
else:
    C0_=round(N-sum([(T-(XW[0][0]+L-XW[i][0])/2)//(L/2)+1 if XW[i][1]!=2 and (XW[0][0]+L-XW[i][0])/2<=T else 0 for i in range(1, N)])%N)
    
'''
if X_[0]==X_[1] and XW[0][1]==1:
  C0_=round((C0_-1)%N)
'''
if C0_>0:
  X_=X_[N-C0_:]+X_[:N-C0_]

print(*X_, sep='\n')

Submission status: Wrong Answer

Solution code:
N, L, T=map(int, input().split())
XW=[list(map(int, input().split())) for _ in range(N)]
X_=[(XW[i][0]+T)%L if XW[i][1]==1 else (XW[i][0]-T)%L for i in range(N)]
X_.sort()
A0_=(XW[0][0]+T)%L if XW[0][1]==1 else (XW[0][0]-T)%L
P0_=X_.index(A0_)
if P0_>0:
    X_=X_[P0_:]+X_[:P0_]
    
if XW[0][1]==1:
    C0_=round(sum([(T-(XW[i][0]-XW[0][0])/2)//(L/2)+1 if XW[i][1]!=1 and (XW[i][0]-XW[0][0])/2<=T else 0 for i in range(1, N)])%N)
else:
    C0_=round(N-sum([(T-(XW[0][0]+L-XW[i][0])/2)//(L/2)+1 if XW[i][1]!=2 and (XW[0][0]+L-XW[i][0])/2<=T else 0 for i in range(1, N)])%N)
    
if C0_>0:
  X_=X_[N-C0_:]+X_[:N-C0_]
print(*X_, sep='\n')

Submission status: Wrong Answer

Solution code:
N, L, T=map(int, input().split())
XW=[list(map(int, input().split())) for _ in range(N)]
X_=[(XW[i][0]+T)%L if XW[i][1]==1 else (XW[i][0]-T)%L for i in range(N)]
X_.sort()
A0_=(XW[0][0]+T)%L if XW[0][1]==1 else (XW[0][0]-T)%L
P0_=X_.index(A0_)
if P0_>0:
    X_=X_[P0_:]+X_[:P0_]
    
if XW[0][1]==1:
    C0_=int(sum([(T-(XW[i][0]-XW[0][0])/2)//(L/2)+1 if XW[i][1]!=1 and (XW[i][0]-XW[0][0])/2<=T else 0 for i in range(1, N)])%N)
else:
    C0_=int(N-sum([(T-(XW[0][0]+L-XW[i][0])/2)//(L/2)+1 if XW[i][1]!=2 and (XW[0][0]+L-XW[i][0])/2<=T else 0 for i in range(1, N)])%N)
    
X_=X_*2
X_=X_[N-C0_:2*N-C0_]
print(*X_, sep='\n')

Submission status: Wrong Answer

Solution code:
N, L, T=map(int, input().split())
XW=[list(map(int, input().split())) for _ in range(N)]
X_=[(XW[i][0]+T)%L if XW[i][1]==1 else (XW[i][0]-T)%L for i in range(N)]
X_.sort()
if XW[0][1]==1:
    C=int(sum([(T-(XW[i][0]-XW[0][0])/2)//(L/2)+1 for i in range(1, N) if XW[i][1]==2 and T>=(XW[i][0]-XW[0][0])/2]))
    if C%N!=0:
        X_=X_[C%N:]+X_[:C%N]
else:
    C=int(sum([(T-(XW[0][0]+L-XW[i][0])/2)//(L/2)+1 for i in range(1, N) if XW[i][1]==1 and T>=(XW[0][0]+L-XW[i][0])/2]))
    if C%N!=0:
        X_=X_[N-C%N:]+X_[:N-C%N]
print(*X_, sep='\n')

Submission status: Wrong Answer

Solution code:
N, L, T=map(int, input().split())
XW=[list(map(int, input().split())) for _ in range(N)]
X_=[(XW[i][0]+T)%L if XW[i][1]==1 else (XW[i][0]-T)%L for i in range(N)]
X_.sort()
if XW[0][1]==1:
  C=int(sum([(T-(XW[i][0]-XW[0][0])/2)//(L/2)+1 for i in range(1, N) if XW[i][1]==2]))
  if C%N!=0:
    X_=X_[C%N:]+X_[:C%N]
else:
  C=int(sum([(T-(XW[0][0]+L-XW[i][0])/2)//(L/2)+1 for i in range(1, N) if XW[i][1]==1]))
  if C%N!=0:
    X_=X_[N-C%N:]+X_[:N-C%N]
print(*X_, sep='\n')

Submission status: Wrong Answer

Solution code:
import numpy as np
n, l, t = map(int, input().split())
x = np.zeros([n])
w = np.zeros([n])
next_position = np.zeros([n])
distance = np.zeros([n])
distance_prev = np.zeros([n])
index = np.arange(0, n)
index = np.append(index, int(0))
for i in range(n):
    x[i], w[i] = map(int, input().split())
    if w[i] == 2:
        w[i] = -1
x_2 = np.roll(x, -1)
distance_prev = np.abs(x_2 - x)

for i in range(t):
    next_position = x + w
    for j in range(n):
        if next_position[j] == l:
            next_position[j] = 0
        elif next_position[j] == -1:
            next_position[j] = l - 1
    next_position_2 = np.roll(next_position, -1)
    distance = np.abs(next_position_2 - next_position)
    for j in range(n):
        if (distance_prev[j] == 1 and distance[j] == 1) or (distance_prev[j] == l - 1 and distance[j] == l - 1):
            w[index[j]] *= -1
            w[index[j + 1]] *= -1
            next_position[index[j]] = x[index[j]]
            next_position[index[j + 1]] = x[index[j + 1]]
        elif distance[j] == 0 or distance[j] == l:
            w[index[j]] *= -1
            w[index[j + 1]] *= -1
    x = next_position
    distance_prev[:] = distance[:]

for i in range(n):
    print(int(x[i]))

Submission status: Wrong Answer

Solution code:
n, l, t = map(int, input().split())
x = [0] * n
w = [0] * n
next_position = [0] * n
distance = [0] * n
distance_prev = [0] * n
for i in range(n):
    x[i], w[i] = map(int, input().split())
    if w[i] == 2:
        w[i] = -1

for j in range(n):
    if j == n - 1:
        distance_prev[j] = abs(x[0] - x[-1])
    else:
        distance_prev[j] = abs(x[j + 1] - x[j])
    if distance_prev[j] > l / 2:
        distance_prev[j] = l - distance_prev[j]

for i in range(t):
    for j in range(n):
        next_position[j] = x[j] + w[j]
    # print(next_position, distance_prev)
    for j in range(n):
        if j == n - 1:
            distance[n - 1] = abs(next_position[0] - next_position[-1])
        else:
            distance[j] = abs(next_position[j + 1] - next_position[j])
        if distance[j] > l / 2:
            distance[j] = abs(l - distance[j])
        if distance_prev[j] == 1 and distance[j] == 1:
            if j == n - 1:
                w[j] *= -1
                w[0] *= -1
                next_position[j] = x[j]
                next_position[0] = x[0]
            else:
                w[j] *= -1
                w[j + 1] *= -1
                next_position[j] = x[j]
                next_position[j + 1] = x[j + 1]
        elif distance[j] == 0:
            if j == n - 1:
                w[j] *= -1
                w[0] *= -1
            else:
                w[j] *= -1
                w[j + 1] *= -1
        if next_position[j] == l:
            next_position[j] = 0
        elif next_position[j] == -1:
            next_position[j] = l - 1
    for i in range(n):
        x[i] = next_position[i]
        distance_prev[i] = distance[i]

for i in range(n):
    print(x[i])

Submission status: Wrong Answer

Solution code:
import sys,queue,math,copy,itertools,bisect
LI = lambda : [int(x) for x in sys.stdin.readline().split()]
N,L,T = LI()
X = []
W = []
for _ in range(N):
    x,w = LI()
    X.append(x)
    W.append(1 if w == 1 else -1)

# 最終の位置計算
Y = []
for i in range(N):
    y = (X[i] + T * W[i]) % L
    Y.append(y)

# 蟻1が何回すれ違うか
r = T // L
m = T % L

kai = r * W.count(-W[0]) * 2

# m秒以内にすれ違う蟻
for i in range(1,N):
    if W[0] != W[i]:
        d = ((X[i] - X[0]) * W[0]) % L
        if d <= m * 2:
            kai += 1
            if (L - d) <= (m - d) * 2:
                kai += 1

# Y[0]のNoを求める
Num = (kai * W[0]) % L

# Yをソート
y0 = Y[0]
Y.sort()
if W[0] < 0:
    p = bisect.bisect_left(Y,y0)
else:
    p = bisect.bisect_right(Y, y0) - 1
s = (p-Num) % N

for _ in range(N):
    print (Y[s])
    s = (s + 1) % N

Submission status: Wrong Answer

Solution code:
import sys,queue,math,copy,itertools,bisect
LI = lambda : [int(x) for x in sys.stdin.readline().split()]
N,L,T = LI()
X = []
W = []
for _ in range(N):
    x,w = LI()
    X.append(x)
    W.append(1 if w == 1 else -1)

# 最終の位置計算
Y = []
for i in range(N):
    y = (X[i] + T * W[i]) % L
    Y.append(y)

# 蟻1が何回すれ違うか
r = T // L
m = T % L

kai = r * W.count(-W[0]) * 2

# m秒以内にすれ違う蟻
for i in range(1,N):
    if W[0] != W[i]:
        d = ((X[i] - X[0]) * W[0]) % L
        if d < m * 2:
            kai += 1
            if (L - d) < (m - d) * 2:
                kai += 1

# Y[0]のNoを求める
Num = (kai * W[0]) % L

# Yをソート
y0 = Y[0]
Y.sort()
if W[0] > 0:
    p = bisect.bisect_left(Y,y0)
else:
    p = bisect.bisect_right(Y, y0) - 1
s = (p-Num) % N

for _ in range(N):
    print (Y[s])
    s = (s + 1) % N

Submission status: Wrong Answer

Solution code:
n,l,t=map(int,input().split())
arr=[list(map(int,input().split())) for _ in range(n)]
ans=[]
for i in range(n):
  tmp=arr[i][0]
  if arr[i][1]==1:
    tmp+=t
    tmp%=l
  else:
    tmp-=t
    tmp%=l
  ans.append(tmp)
ans=sorted(ans)
pos=arr[0][0]
direction=arr[0][1]
number=0
for i in range(n):
  if arr[i][1]==direction:
    continue
  else:
    times=2*(t//l)
    if direction==1:
      if pos<=arr[i][0]:
        distance=arr[i][0]-pos
      else:
        distance=(l-pos)+arr[i][0]
    else:
      if pos<=arr[i][0]:
        distance=pos+(l-arr[i][0])
      else:
        distance=pos-arr[i][0]
    if 2*(t%l)>=distance:
      times+=1
    if 2*(t%l)>=distance+l:
      times+=1
    if direction==1:
      number+=times
    else:
      number-=times
number%=n
tmp=[0]*n
for i in range(n):
  tmp[i]=ans[(number+i)%n]
ans=tmp
for pos in ans:
  print(pos)

Submission status: Wrong Answer

Solution code:
n,l,t=map(int,input().split())
arr=[list(map(int,input().split())) for _ in range(n)]
arr=sorted(arr,key=lambda x:x[0])
ans=[]
for i in range(n):
  tmp=arr[i][0]
  if arr[i][1]==1:
    tmp+=t
    tmp%=l
  else:
    tmp-=t
    tmp%=l
  ans.append(tmp)
pos=arr[0][0]
direction=arr[0][1]
number=0
for i in range(n):
  if arr[i][1]==direction:
    continue
  else:
    times=2*(t//l)
    if direction==1:
      if pos<=arr[i][0]:
        distance=arr[i][0]-pos
      else:
        distance=(l-pos)+arr[i][0]
    else:
      if pos<=arr[i][0]:
        distance=pos+(l-arr[i][0])
      else:
        distance=pos-arr[i][0]
    if 2*(t%l)>=distance:
      times+=1
    if 2*(t%l)>=distance+l:
      times+=1
    if direction==1:
      number+=times
    else:
      number-=times
number%=n
tmp=[0]*n
for i in range(n):
  tmp[(number+i)%n]=ans[i]
ans=tmp
for pos in ans:
  print(pos)

Submission status: Wrong Answer

Solution code:
n,l,t=map(int,input().split())
arr=[list(map(int,input().split())) for _ in range(n)]
arr=sorted(arr,key=lambda x:x[0])
ans=[]
for i in range(n):
  tmp=arr[i][0]
  if arr[i][1]==1:
    tmp+=t
    tmp%=l
  else:
    tmp-=t
    tmp%=l
  ans.append(tmp)
pos=arr[0][0]
direction=arr[0][1]
number=0
for i in range(1,n):
  if arr[i][1]==direction:
    continue
  else:
    times=2*(t//l)
    if direction==1:
      if pos<=arr[i][0]:
        distance=arr[i][0]-pos
      else:
        distance=(l-pos)+arr[i][0]
    else:
      if pos<=arr[i][0]:
        distance=pos+(l-arr[i][0])
      else:
        distance=pos-arr[i][0]
    if 2*(t%l)>=distance:
      times+=1
    if 2*(t%l)>=distance+l:
      times+=1
    if direction==1:
      number+=times
    else:
      number-=times
number%=n
tmp=[0]*n
for i in range(n):
  tmp[(number+i)%n]=ans[i]
ans=tmp
for pos in ans:
  print(pos)

Submission status: Wrong Answer

Solution code:
n,l,t=map(int,input().split())
arr=[list(map(int,input().split())) for _ in range(n)]
arr=sorted(arr,key=lambda x:x[0])
ans=[]
for i in range(n):
  tmp=arr[i][0]
  if arr[i][1]==1:
    tmp+=t
    tmp%=l
  else:
    tmp-=t
    tmp%=l
  ans.append(tmp)
pos=arr[0][0]
direction=arr[0][1]
number=0
for i in range(1,n):
  if arr[i][1]==direction:
    continue
  else:
    times=2*(t//l)
    if pos<=arr[i][0]:
      distance=arr[i][0]-pos
    else:
      distance=l-(pos-arr[i][0])
    if 2*(t%l)>=distance:
      times+=1
    if 2*(t%l)>=distance+l:
      times+=1
    if direction==1:
      number+=times
    else:
      number-=times
number%=n
tmp=[0]*n
for i in range(n):
  tmp[(number+i)%n]=ans[i]
ans=tmp
for pos in ans:
  print(pos)

Submission status: Wrong Answer

Solution code:
n,l,t=map(int,input().split())
arr=[list(map(int,input().split())) for _ in range(n)]
arr=sorted(arr,key=lambda x:x[0])
ans=[]
for i in range(n):
  tmp=arr[i][0]
  if arr[i][1]==1:
    tmp+=t
    tmp%=l
  else:
    tmp-=t
    tmp%=l
  ans.append(tmp)
pos=arr[0][0]
direction=arr[0][1]
number=0
for i in range(1,n):
  if arr[i][1]==direction:
    continue
  else:
    times=t//l
    if pos<=arr[i][0]:
      distance=arr[i][0]-pos
    else:
      distance=l-(pos-arr[i][0])
    if 2*(t%l)>=distance:
      times+=1
    if 2*(t%l)>=distance+l:
      times+=1
    if direction==1:
      number+=times
    else:
      number-=times
number%=n
tmp=[0]*n
for i in range(n):
  tmp[(number+i)%n]=ans[i]
ans=tmp
for pos in ans:
  print(pos)

Submission status: Wrong Answer

Solution code:
n,l,t=map(int,input().split())
arr=[list(map(int,input().split())) for _ in range(n)]
arr=sorted(arr,key=lambda x:x[0])
ans=[]
for i in range(n):
  tmp=arr[i][0]
  if arr[i][1]==1:
    tmp+=t
    tmp%=l
  else:
    tmp-=t
    tmp%=l
  ans.append(tmp)
pos=arr[0][0]
direction=arr[0][1]
number=0
for i in range(1,n):
  if arr[i][1]==direction:
    continue
  else:
    times=t//l
    if pos<=arr[i][0]:
      distance=arr[i][0]-pos
    else:
      distance=l-(pos-arr[i][0])
    if 2*t%l>=distance:
      times+=1
    if 2*t%l>=distance+l:
      times+=1
    if direction==1:
      number+=times
    else:
      number-=times
number%=n
tmp=[0]*n
for i in range(n):
  tmp[(number+i)%n]=ans[i]
ans=tmp
for pos in ans:
  print(pos)

Submission status: Wrong Answer

Solution code:
def examA():
    N = I()
    A = LI()
    ans = 1
    flag = None
    for i in range(N-1):
        cur = A[i+1] - A[i]
        if not flag:
            if cur<0:
                flag = "d"
            elif cur>0:
                flag = "u"
        else:
            if cur<0 and flag=="u":
                flag = None
                ans += 1
            elif cur>0 and flag=="d":
                flag = None
                ans += 1
    print(ans)
    return

def examB():
    def bfs(n,V):
        W = [inf] * n
        W[0] = 0
        que = deque()
        que.append(0)
        while (que):
            now = que.popleft()
            nowW = W[now]
            if nowW==0:
                judge = 0
            elif nowW>0:
                judge = 1
            else:
                judge = -1
            if judge<0:
                cur = -1
            else:
                cur = 1

            for ne in V[now]:
                #print(now,ne)
                if cur+1<judge:
                    break
                if W[ne]!=inf:
                    continue
                W[ne] = nowW + cur
                que.append(ne)
                cur -= 2
        return W
    N, M = LI()
    V = [[]for _ in range(N)]
    for _ in range(M):
        a, b = LI()
        a -= 1; b -= 1
        V[a].append(b)
        V[b].append(a)

    L = bfs(N,V)
    D = defaultdict(int)
    minA = 0; maxA = 0
    for i,a in enumerate(L,start=1):
        if a!=inf:
            D[a] = i
            if a<minA:
                minA = a
            if a>maxA:
                maxA = a
    ans = []
    for i in range(minA,maxA+1):
        ans.append(D[i])
    print(len(ans))
    print(" ".join(map(str,ans)))
    return

def examC():
    N, L, T = LI()
    X = [[]for _ in range(N)]
    for i in range(N):
        cur = LI()
        cur.append(i)
        X[i] = cur
    #print(X)
    X.sort()
    ans_num = defaultdict(int)
    for j,[x,w,i] in enumerate(X):
        ans_num[j] = i

    X_R = []
    X_L = []
    flag_R = False
    for x,w,i in X:
        if w==1:
            if i==0:
                flag_R = True
            X_R.append([x,i])
        else:
            X_L.append([x,i])
    V = []
    for i in range(N):
        now = T if X[i][1]==1 else -T
        cur = [(X[i][0] + now + L*100000000)%L,X[i][2]]
        V.append(cur)
    #print(V)
    change = 0
    if flag_R:
        stand = X_R[0][0]
    else:
        stand = X_L[0][0]
    for x,i in X_L if flag_R else X_R:
        cur = (2*T)//L
        if flag_R:
            if (x - stand) > 0 and x - stand <= (2 * T) % L:
                cur += 1
            elif (x - stand) < 0 and L + (x - stand) <= (2 * T) % L:
                cur += 1
        else:
            if (x - stand) < 0 and -(x - stand) <= (2 * T) % L:
                cur += 1
            elif (x - stand) > 0 and (L - (x - stand)) <= (2 * T) % L:
                cur += 1
        #print(cur,x,i)
        change += cur
    to = change % N
    if not flag_R:
        to = to*(-1)+N
    #print(change,to)


    ans = [0]*N
    for i in range(N):
        #print(V[i])
        cur = V[i+to-N][1]
        ans[cur] = V[i][0]
    for v in ans:
        print(v)
    return

def examD():
    ans = 0
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math,random
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

if __name__ == '__main__':
    examC()

"""

"""

Submission status: Wrong Answer

Solution code:
def examA():
    N = I()
    A = LI()
    ans = 1
    flag = None
    for i in range(N-1):
        cur = A[i+1] - A[i]
        if not flag:
            if cur<0:
                flag = "d"
            elif cur>0:
                flag = "u"
        else:
            if cur<0 and flag=="u":
                flag = None
                ans += 1
            elif cur>0 and flag=="d":
                flag = None
                ans += 1
    print(ans)
    return

def examB():
    def bfs(n,V):
        W = [inf] * n
        W[0] = 0
        que = deque()
        que.append(0)
        while (que):
            now = que.popleft()
            nowW = W[now]
            if nowW==0:
                judge = 0
            elif nowW>0:
                judge = 1
            else:
                judge = -1
            if judge<0:
                cur = -1
            else:
                cur = 1

            for ne in V[now]:
                #print(now,ne)
                if cur+1<judge:
                    break
                if W[ne]!=inf:
                    continue
                W[ne] = nowW + cur
                que.append(ne)
                cur -= 2
        return W
    N, M = LI()
    V = [[]for _ in range(N)]
    for _ in range(M):
        a, b = LI()
        a -= 1; b -= 1
        V[a].append(b)
        V[b].append(a)

    L = bfs(N,V)
    D = defaultdict(int)
    minA = 0; maxA = 0
    for i,a in enumerate(L,start=1):
        if a!=inf:
            D[a] = i
            if a<minA:
                minA = a
            if a>maxA:
                maxA = a
    ans = []
    for i in range(minA,maxA+1):
        ans.append(D[i])
    print(len(ans))
    print(" ".join(map(str,ans)))
    return

def examC():
    N, L, T = LI()
    X = [[]for _ in range(N)]
    for i in range(N):
        cur = LI()
        cur.append(i)
        X[i] = cur
    #print(X)
    X.sort()
    ans_num = defaultdict(int)
    for j,[x,w,i] in enumerate(X):
        ans_num[j] = i

    X_R = []
    X_L = []
    flag_R = False
    for x,w,i in X:
        if w==1:
            if i==0:
                flag_R = True
            X_R.append([x,i])
        else:
            X_L.append([x,i])
    V = []
    for i in range(N):
        now = T if X[i][1]==1 else -T
        cur = [(X[i][0] + now + L*100000000)%L,X[i][2]]
        V.append(cur)
    #print(V)
    change = 0
    if flag_R:
        stand = X_R[0][0]
    else:
        stand = X_L[0][0]
    for x,i in X_L if flag_R else X_R:
        cur = (2*T)//L
        if flag_R:
            if (x - stand) > 0 and x - stand <= (2 * T) % L:
                cur += 1
            elif (x - stand) < 0 and L - (x - stand) <= (2 * T) % L:
                cur += 1
        else:
            if (x - stand) < 0 and -(x - stand) <= (2 * T) % L:
                cur += 1
            elif (x - stand) > 0 and -(L - (x - stand)) <= (2 * T) % L:
                cur += 1
        #print(cur,x,i)
        change += cur
    to = change % N
    if not flag_R:
        to = to*(-1)+N
    #print(change,to)


    ans = [0]*N
    for i in range(N):
        #print(V[i])
        cur = V[i+to-N][1]
        ans[cur] = V[i][0]
    for v in ans:
        print(v)
    return

def examD():
    ans = 0
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math,random
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

if __name__ == '__main__':
    examC()

"""

"""