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: Runtime Error

Solution code:
n,l,t=map(int,input().split())
xw=[list(map(int,input().split())) for _ in [0]*n]

first_x=xw[0][0]
first_w=xw[0][1]

right=[]
left=[]

for x,w in xw:
    if w==1:
        right.append(x)
    else:
        left.append(x)

if first_w==1:
    left=[(i-first_x)/2 for i in left]
    right.reverse()
    right=[(l+first_x-i)/2 for i in right]
else:
    right=[(l+first_x-i)/2 for i in right]
    right.reverse()
    left=[(i-first_x)/2 for i in left[1:]]+[l/2]
    
ll=len(left)
lr=len(right)
    
#print(left)
#print(right)

def search(cnt):
    w=first_w
    if ll==0 or lr==0:
        return None
    elif cnt==0:
        return [0,0,0]
    elif w==1:#偶数奇数の組み合わせがうまくいっていない
        right_temp=((cnt//2+cnt%2-1)//ll)*(l/2)+left[(cnt//2+cnt%2-1)%ll]
        left_temp=max((((cnt-2)//2)//lr),0)*(l/2)+right[((cnt-2)//2)%lr]*(cnt!=1)
    else:
        left_temp=((cnt//2+cnt%2-1)//lr)*(l/2)+right[(cnt//2+cnt%2-1)%lr]
        right_temp=max((((cnt-1)//2)//ll),0)*(l/2)+left[((cnt-2)//2)%ll]*(cnt!=1)
    return [left_temp+right_temp,right_temp,left_temp]

def b_search(a,b,p,value):
    med=(a+b)//2
    if a==b:return a
    if a+1==b:
        if value(b)[0]<=p:return b
        else:return a
    elif value(med)[0]<=p:return b_search(med,b,p,value)
    else:return b_search(a,med-1,p,value)

#print(search(5))
a=b_search(0,10**9,t,search)
#print(a)
b=search(a)
#print(b)
#print(search(a+1))

if (a+first_w)%2==1:
    b[1]+=t-b[0]
    #print("右")
else:
    b[2]+=t-b[0]
    #print("左")
#print(b)
last=int(((first_x+b[1]-b[2])%l+l)%l)
#print(last)

ans=sorted([((x+t*int((-w+1.5)*2))%l+l)%l for x,w in xw])

for i in range(n):
    if last==ans[i]:
        if i==n-1:
            break
        elif ans[i+1]!=last:
            break
        else:
            if (a+first_w)%2==1:
                break
            else:
                i+=1
                break
for j in ans[i:]+ans[:i]:
    print(j)

Submission status: Runtime Error

Solution code:
#! /Library/Frameworks/Python.framework/Versions/3.7/bin/python3
N, L, T = map(int, input().split())  # アリの数、外周、時間
P = []  # アリの位置
D = []  # アリの方向
J = [0] * (L * 2)
for n in range(N):
    t1, t2 = map(int, input().split())
    P.append(t1 * 2)
    D.append(t2)
for t in range(T * 2):
    J = [0 for _ in range(L * 2)]
    for n in range(N):
        if D[n] == 1:
            P[n] = (P[n]+1) % (L * 2)
        else:
            P[n] = (P[n]-1) % (L * 2)
        if J[P[n]] == 0:
            J[P[n]] += 1
        else:
            tmp = P.index(P[n])
            D[tmp] += 1 if D[tmp] == 1 else -1
            D[n] += 1 if D[n] == 1 else - 1
for n in range(N):
    print(str(P[n]//2))

Submission status: Runtime Error

Solution code:
N, L, T = map(int, input().split())  # アリの数、外周、時間
P = []  # アリの位置
D = []  # アリの方向
J = [0] * L * 2

Submission status: Runtime Error

Solution code:
N, L, T = map(int, input().split())  # アリの数、外周、時間
P = []  # アリの位置
D = []  # アリの方向
J = [0] * L * 2
for n in range(N):
    t1, t2 = map(int, input().split())
    P.append(t1 * 2)
    D.append(t2)

Submission status: Runtime Error

Solution code:
#! /Library/Frameworks/Python.framework/Versions/3.7/bin/python3
N, L, T = map(int, input().split())  # アリの数、外周、時間
P = []  # アリの位置
D = []  # アリの方向
J = [0] * L * 2
for n in range(N):
    t1, t2 = map(int, input().split())
    P.append(t1 * 2)
    D.append(t2)
for t in range(T * 2):
    J = [0 for _ in range(L * 2)]

Submission status: Runtime Error

Solution code:
#! /Library/Frameworks/Python.framework/Versions/3.7/bin/python3
N, L, T = map(int, input().split())  # アリの数、外周、時間
P = []  # アリの位置
D = []  # アリの方向
J = [0] * L * 2
for n in range(N):
    t1, t2 = map(int, input().split())
    P.append(t1 * 2)
    D.append(t2)
for t in range(T * 2):
    J = [0 for _ in range(L * 2)]
    for n in range(N):
        if D[n] == 1:
            P[n] = (P[n]+1) % (L * 2)
        else:
            P[n] = (P[n]-1) % (L * 2)
        if J[P[n]] == 0:
            J[P[n]] += 1

Submission status: Runtime Error

Solution code:
#! /Library/Frameworks/Python.framework/Versions/3.7/bin/python3
N, L, T = map(int, input().split())  # アリの数、外周、時間
P = []  # アリの位置
D = []  # アリの方向
J = [0] * L * 2
for n in range(N):
    t1, t2 = map(int, input().split())
    P.append(t1 * 2)
    D.append(t2)
for t in range(T * 2):
    J = [0 for _ in range(L * 2)]
    for n in range(N):
        if D[n] == 1:
            P[n] = (P[n]+1) % (L * 2)
        else:
            P[n] = (P[n]-1) % (L * 2)
        if J[P[n]] == 0:
            J[P[n]] += 1
        else:
            tmp = P.index(P[n])
            D[tmp] += 1 if D[tmp] == 1 else -1
            D[n] += 1 if D[n] == 1 else - 1

Submission status: Runtime Error

Solution code:
#! /Library/Frameworks/Python.framework/Versions/3.7/bin/python3
N, L, T = map(int, input().split())  # アリの数、外周、時間
P = []  # アリの位置
D = []  # アリの方向
J = [0] * L * 2
for n in range(N):
    t1, t2 = map(int, input().split())
    P.append(t1 * 2)
    D.append(t2)
for t in range(T * 2):
    J = [0 for _ in range(L * 2)]
    for n in range(N):
        if D[n] == 1:
            P[n] = (P[n]+1) % (L * 2)
        else:
            P[n] = (P[n]-1) % (L * 2)
        if J[P[n]] == 0:
            J[P[n]] = 1
        else:
            tmp = P.index(P[n])
            D[tmp] += 1 if D[tmp] == 1 else -1
            D[n] += 1 if D[n] == 1 else - 1
for n in range(N):
    print(str(P[n]//2))

Submission status: Runtime Error

Solution code:
#! /Library/Frameworks/Python.framework/Versions/3.7/bin/python3
N, L, T = map(int, input().split())
P = []  # アリの位置
D = []  # アリの方向
J = [0] * L * 2
for n in range(N):
    t1, t2 = map(int, input().split())
    P.append(t1 * 2)
    D.append(t2)
for t in range(T * 2):
    J = [0 for _ in range(L * 2)]
    for n in range(N):
        if D[n] == 1:
            P[n] = (P[n]+1) % (L * 2)
        else:
            P[n] = (P[n]-1) % (L * 2)
        if J[P[n]] == 0:
            J[P[n]] += 1
        else:
            tmp = P.index(P[n])
            D[tmp] += 1 if D[tmp] == 1 else -1
            D[n] += 1 if D[n] == 1 else - 1
for n in range(N):
    print(str(P[n]//2))

Submission status: Runtime Error

Solution code:
N, L, T = map(int, input().split())
P = []  # アリの位置
D = []  # アリの方向
J = [0] * L * 2
for n in range(N):
    tmp = list(map(int, input().split()))
    P.append(tmp[0] * 2)
    D.append(tmp[1])
for t in range(T * 2):
    J = [0 for _ in range(L * 2)]
    for n in range(N):
        P[n] += 1 if D[n] == 1 else -1
        P[n] = P[n] % (L * 2)
        if J[P[n]] == 0:
            J[P[n]] += 1
        else:
            tmp = P.index(P[n])
            D[tmp] += 1 if D[tmp] == 1 else -1
            D[n] += 1 if D[n] == 1 else - 1
for n in range(N):
    print(str(P[n]//2))

Submission status: Runtime Error

Solution code:
normal_ant = [i for i, direction in ants if direction==1]
counter_ant = [i for i, direction in ants if direction==2]
cnt = (t // l) * len(normal_ant) + sum([1 for i in normal_ant if i + t%l >= l])
counter_cnt = (t // l) * len(counter_ant) + sum([1 for i in counter_ant if i - t%l < 0])
final_pos = sorted([(i-t)%l for i in counter_ant] + [(i+t)%l for i in normal_ant])
print(*final_pos[(cnt-counter_cnt)%n:] + final_pos[:(cnt-counter_cnt)%n], sep='\n')

Submission status: Runtime Error

Solution code:
import sys
import numpy as np
n,l,t=map(int,input().rstrip().split())
iniposition =[]
finposition=[]
fline=np.array([])
bline=np.array([])

for i in range(n):
	temp1,temp2 = map(int,sys.stdin.readline().rstrip().split())
	iniposition.append([i,temp1,temp2])
    

for element in iniposition:
	temp1=((-1*(2*element[2]-3)*t)+element[1]) % l
	finposition.append(int(temp1))



position_1=iniposition[0][1]


for element in iniposition[1:]:
	if element[2] == 2:
		fline = np.append(fline,float((element[1]-position_1) % l ))
	else:
		bline = np.append(bline,float((position_1-element[1]) % l ))

fline.sort()
bline.sort()


T=float(t)
sum_move=0.0
sum_time=0.0
direction=int(-2*(iniposition[0][2]-1.5))

for _ in range(t):
	if direction == 1 :
		front = fline[0]
		if front / 2 >= T - sum_time:
			sum_move += T - sum_time
			sum_time = T
			break
		else:
			sum_move += front / 2
			sum_time += front / 2
			fline = fline - front / 2
			fline = np.delete(fline,0)
			bline = np.append(bline,float(l))
			direction=-1
	else:
		front = bline[0]
		if front / 2 >= T - sum_time:
			sum_move -= T- sum_time
			sum_time = T
			break
		else:
			sum_move -= front / 2
			sum_time += front / 2
			bline = bline - front / 2
			bline = np.delete(bline,0)
			fline = np.append(fline,float(l))
			direction = 1

tarposition = (position_1 + int(sum_move)) % l
i = finposition.index(tarposition)
lh = finposition[:i]
fh = finposition[i:]
fh.extend(lh)


for element in fh:
	print(element)

Submission status: Runtime Error

Solution code:
import sys
n,l,t=map(int,input().rstrip().split())
iniposition =[]
finposition=[]
fline=[]
bline=[]

for i in range(n):
	temp1,temp2 = map(int,sys.stdin.readline().rstrip().split())
	iniposition.append([i,temp1,temp2])
    

for element in iniposition:
	temp1=((-2*(element[2]-1.5)*t)+element[1]) % l
	finposition.append(int(temp1))



position_1=iniposition[0][1]


for element in iniposition[1:]:
	if element[2] == 2:
		fline.append(float((element[1]-position_1) % l ))
	else:
		bline.append(float((position_1-element[1]) % l ))

fline.sort()
bline.sort()


T=float(t)
sum_move=0.0
sum_time=0.0
direction=int(-2*(iniposition[0][2]-1.5))

for _ in range(t):
	if direction == 1 :
		if fline[0] / 2 >= T - sum_time:
			sum_move += T - sum_time
			sum_time = T
			break
		else:
			distance = fline[0]
			sum_move += distance / 2
			sum_time += distance / 2
			fline = list(map(lambda x :x-distance/2,fline))
			fline = fline[1:]
			bline.append(l)
			direction=-1
	else:
		if bline[0] / 2 >= T - sum_time:
			sum_move -= T- sum_time
			sum_time = T
			break
		else:
			distance = bline[0]
			sum_move -= distance / 2
			sum_time += distance / 2
			map(lambda x :x-distance/2,bline)
			bline = bline[1:]
			fline.append(l)
			direction = 1

tarposition = (position_1 + int(sum_move)) % l
i = finposition.index(tarposition)
lh = finposition[:i]
fh = finposition[i:]
fh.extend(lh)


for element in fh:
	print(element)

Submission status: Runtime Error

Solution code:
import sys
n,l,t=map(int,input().rstrip().split())
iniposition =[]
finposition=[]
fline=[]
bline=[]

for i in range(n):
	temp1,temp2 = map(int,sys.stdin.readline().rstrip().split())
	iniposition[i]=[i,temp1,temp2]
    

for element in iniposition:
	temp1=((-2*(element[2]-1.5)*t)+element[1]) % l
	finposition.append(int(temp1))



position_1=iniposition[0][1]


for element in iniposition[1:]:
	if element[2] == 2:
		fline.append(float((element[1]-position_1) % l ))
	else:
		bline.append(float((position_1-element[1]) % l ))

fline.sort()
bline.sort()


T=float(t)
sum_move=0.0
sum_time=0.0
direction=int(-2*(iniposition[0][2]-1.5))

for _ in range(t):
	if direction == 1 :
		if fline[0] / 2 >= T - sum_time:
			sum_move += T - sum_time
			sum_time = T
			break
		else:
			distance = fline[0]
			sum_move += distance / 2
			sum_time += distance / 2
			fline = list(map(lambda x :x-distance/2,fline))
			fline = fline[1:]
			bline.append(l)
			direction=-1
	else:
		if bline[0] / 2 >= T - sum_time:
			sum_move -= T- sum_time
			sum_time = T
			break
		else:
			distance = bline[0]
			sum_move -= distance / 2
			sum_time += distance / 2
			map(lambda x :x-distance/2,bline)
			bline = bline[1:]
			fline.append(l)
			direction = 1

tarposition = (position_1 + int(sum_move)) % l
i = finposition.index(tarposition)
lh = finposition[:i]
fh = finposition[i:]
fh.extend(lh)


for element in fh:
	print(element)

Submission status: Runtime Error

Solution code:
n,l,t=map(int,input().rstrip().split())
iniposition =[]
finposition=[]
fline=[]
bline=[]

for i in range(n):
	temp1,temp2 = map(int,input().rstrip().split())
	iniposition.append([i,temp1,temp2])
    
for i in range(n):
	temp1=((-2*(iniposition[i][2]-1.5)*t)+iniposition[i][1]) % l
	finposition.append(int(temp1))

position_1=iniposition[0][1]

for i in range(1,n):
	if iniposition[i][2] == 2:
		fline.append(float((iniposition[i][1]-position_1) % l ))
	else:
		bline.append(float((position_1-iniposition[i][1]) % l ))

fline.sort()
bline.sort()


T=float(t)
sum_move=0.0
sum_time=0.0
direction=int(-2*(iniposition[0][2]-1.5))

while sum_time < T:
	if direction == 1 :
		if fline[0]/2>=T - sum_time:
			sum_move+=T-sum_time
			sum_time=T
		else:
			distance=fline[0]
			sum_move+=distance / 2
			sum_time+=distance / 2
			fline=list(map(lambda x :x-distance/2,fline))
			fline=fline[1:]
			bline.append(l)
			direction=-1
	else:
		if bline[0]/2>=T - sum_time:
			sum_move-=T-sum_time
			sum_time=T
		else:
			distance=bline[0]
			sum_move-=distance / 2
			sum_time+=distance / 2
			map(lambda x :x-distance/2,bline)
			bline=bline[1:]
			fline.append(l)
			direction=1

tarposition=(position_1 + sum_move)%l

for i in range(n):
	if finposition[i]==tarposition:
		lh=finposition[:i]
		fh=finposition[i:]
		fh.extend(lh)
		break

for element in fh:
	print(element)

Submission status: Runtime Error

Solution code:
N, L, T = map(int, input().split())
n = [[*map(int, input().split())] for _ in range(N)]
t = [X + (0, T, -T)[W] for X, W in n]
x = sorted(i % L for i in t)
s = sum(i // L for i in t) % N
for i in x[s:] + x[:s]: print(i)

Submission status: Runtime Error

Solution code:
n,l,T = map(int,input().split())
s = [0 for i in range(n)]
for i in range(n):
    s[i] = list(map(int, input().split()))

def f(w):
    if w == 1:
        return 1
    elif w == 2:
        return -1
    
t = 0
d = l

while t < T:
    for i in range(n):
        if i < n-1 :
            if s[i][0] < s[i+1][0] and s[i][1] == 1 and s[i+1][1] == 2:
                if s[i+1][0] - s[i][0] < d:
                    d = s[i+1][0] - s[i][0]
    
            elif s[i][0] > s[i+1][0] and s[i][1] == 1 and s[i+1][1] == 2:
                if s[i+1][0] + l - s[i][0] < d:
                    d = s[i+1][0] + l - s[i][0]
                    
        elif i == n-1:
            if s[i][0] < s[0][0] and s[i][1] == 1 and s[0][1] == 2:
                if s[0][0] - s[i][0] < d:
                    d = s[0][0] - s[i][0]
                    
            elif s[i][0] > s[0][0] and s[i][1] == 1 and s[0][1] == 2:
                if s[0][0] + l - s[i][0] < d:
                    d = s[0][0] + l - s[i][0]
                    
                    
    for j in range(n):
        if t + d/2 <= T:
            s[j][0] += f(s[j][1]) * (d/2)
            if s[j][0] >= l:
                s[j][0] -= l
            elif s[j][0] < 0:
                s[j][0] += l
            
        else:
            s[j][0] += f(s[j][1]) * (T-t)
            if s[j][0] >= l:
                s[j][0] -= l
            elif s[j][0] < 0:
                s[j][0] += l
        if j > 0 and s[j][0] == s[j-1][0]:
            s[j][1], s[j-1][1] = s[j-1][1], s[j][1]
        if j == n-1 and s[j][0] == s[0][0] :
            s[j][1], s[0][1] = s[0][1], s[j][1]
            
    t = t + d/2
    i_d.clear()
    d = l
    
import math

for i in range(n):
    print(math.floor(s[i][0]))

Submission status: Runtime Error

Solution code:
n,l,T = map(int,input().split())
s = [0 for i in range(n)]
for i in range(n):
    s[i] = list(map(int, input().split()))

def f(w):
    if w == 1:
        return 1
    elif w == 2:
        return -1
    
t = 0
d = l
i_d = []

while t < T:
    for i in range(n):
        if i < n-1 :
            if s[i][0] < s[i+1][0] and s[i][1] == 1 and s[i+1][1] == 2:
                if s[i+1][0] - s[i][0] < d:
                    d = s[i+1][0] - s[i][0]
    
            elif s[i][0] > s[i+1][0] and s[i][1] == 1 and s[i+1][1] == 2:
                if s[i+1][0] + l - s[i][0] < d:
                    d = s[i+1][0] + l - s[i][0]
                    
        elif i == n-1:
            if s[i][0] < s[0][0] and s[i][1] == 1 and s[0][1] == 2:
                if s[0][0] - s[i][0] < d:
                    d = s[0][0] - s[i][0]
                    
            elif s[i][0] > s[0][0] and s[i][1] == 1 and s[0][1] == 2:
                if s[0][0] + l - s[i][0] < d:
                    d = s[0][0] + l - s[i][0]
                    
    for i in range(n):
        if i < n-1 :
            if s[i][0] < s[i+1][0] and s[i][1] == 1 and s[i+1][1] == 2:
                if s[i+1][0] - s[i][0] == d:
                    i_d.append(i)
            elif s[i][0] > s[i+1][0] and s[i][1] == 1 and s[i+1][1] == 2:
                if s[i+1][0] + l - s[i][0] == d:
                    i_d.append(i)
                    
        elif i == n-1:
            if s[i][0] < s[0][0] and s[i][1] == 1 and s[0][1] == 2:
                if s[0][0] - s[i][0] == d:
                    i_d.append(i)
                    
            elif s[i][0] > s[0][0] and s[i][1] == 1 and s[0][1] == 2:
                if s[0][0] + l - s[i][0] == d:
                    i_d.append(i)
                    
    for j in range(n):
        if t + d/2 <= T:
            s[j][0] += f(s[j][1]) * (d/2)
            if s[j][0] >= l:
                s[j][0] -= l
            elif s[j][0] < 0:
                s[j][0] += l
            
        else:
            s[j][0] += f(s[j][1]) * (T-t)
            if s[j][0] >= l:
                s[j][0] -= l
            elif s[j][0] < 0:
                s[j][0] += l
    for j in i_d:
        if j < n-1:
            s[j][1], s[j+1][1] = s[j+1][1], s[j][1]
        else:
            s[j][1], s[0][1] = s[0][1], s[j][1]
    t = t + d/2
    i_d.clear()
    d = l
    
import maht

for i in range(n):
    print(math.floor(s[i][0]))

Submission status: Runtime Error

Solution code:
N,L,T = map(int , input().split())
X = [0]*N
W = [0]*N
Y = [0]*(N+4)
Z = [0]*(N+4) 
for i in range(N):
    X[i],W[i] = map(int , input().split())
    Y[i+2] = X[i]
    Z[i+2] = W[i]
Y[0] = X[N-2]
Y[1] = X[N-1]
Y[N+2] = X[0]
Y[N+3] = X[1]
Z[0] = W[N-2]
Z[1] = W[N-1]
Z[N+2] = W[0] 
Z[N+3] = W[1]

for i in range(T):
    for h in range(N):
        j = h + 2
        if min((L - abs(Y[j+1] - Y[j]),abs(Y[j+1] - Y[j])))  <=2 and Z[j] == 1 and Z[j+1] ==2:
            X[h] = Y[j+1] - 1
            W[h] = 2
        elif min((L - abs((Y[j] - Y[j-1])),abs(Y[j] - Y[j-1]))) <=2 and Z[j] ==2 and Z[j-1] ==1:
            X[h] = Y[j-1] + 1
            W[h] = 1
        elif min((L - abs(Y[j+1] - Y[j-1]),abs(Y[j+1] - Y[j-1]))) ==2 and Z[j-1] ==1 and Z[j+1] ==2:
            X[h] = Y[j]
        elif min((L - abs(Y[j+2] - Y[j]),abs(Y[j+2] - Y[j]))) ==2 and Z[j] ==1 and Z [j+1] ==1 and Z[j+2] ==2:
            X[h] = Y[j] + 1
            W[h] = 2
        elif min((L - abs(Y[j] - Y[j-2]),abs(Y[j] - Y[j-2]))) ==2 and Z[j] ==2 and Z [j+1] ==2 and Z[j-2] ==1:
            X[h] = Y[j] - 1
            W[h] = 1  
        else:
            X[h] = Y[j] + 3 - 2 * Z[j]        
    for j in range(N):
        X[j]%= L
        Y[j+2] = X[j]
        Z[j+2] = W[j]
    Y[0] = X[N-2]
    Y[1] = X[N-1]
    Y[N+2] = X[0]
    Y[N+3] = X[1]
    Z[0] = W[N-2]
    Z[1] = W[N-1]
    Z[N+2] = W[0] 
    Z[N+3] = W[1]
   

for x in X:
    print(x%L)

Submission status: Runtime Error

Solution code:
from bisect import bisect_left
n, l, t = map(int, input().split())
ants = [list(map(int, input().split())) for _ in range(n)]
bnts = []
diff = []

for i in range(n):
	x, w = ants[i][0], 3 - 2*ants[i][1]
	bnts.append((x + t*w) % l)
	if i == 0:
		zero = bnts[-1]
	if ants[i][1] != ants[0][1]:
		if ants[0][1] == 1:
			diff.append(x - ants[0][0])
		else:
			diff.append(l - (x - ants[0][0]))

bnts.sort()
num = 0
quo, mod = t//l, t%l
num += quo * len(diff) * 2
diff.sort()
diff += [d+l for d in diff]
num += bisect_left(diff, mod*2)
num %= n
for i in range(n):
	if bnts[i] == zero:
		if ants[0][1] == 1:
			true_zero = (i-num) % n
		else:
			if bnts[i+1] == zero:
				num += 1
			true_zero = (i+num) % n

ans = bnts[true_zero:] + bnts[:true_zero]
print(*ans, sep="\n")

Submission status: Runtime Error

Solution code:
import bisect

N,L,T= map(int,input().split())

ants = [[],[]]
for i in range(N):
	X,W = map(int,input().split())
	ants[W-1].append(X)

if len(ants[0]) == N:
	for i in range(N):
		print(((x+T)%L))
	exit()

if len(ants[0]) == 0:
	for i in range(N):
		print(((x-T)%L))
	exit()

ants_final_pos = sorted([((x+T)%L) for x in ants[0]] + [((x-T)%L) for x in ants[1]])
base_idx = ants_final_pos.index(((ants[0][0]+T)%L))
dist_from_next_near00_cw =[]
dist_from_next_near00_c_cw = []

old_pos = 0
for ccw in sorted([((x - ants[0][0])%L) for x in ants[1]]):
	dist_from_next_near00_c_cw.append(ccw - old_pos)
	old_pos = ccw


old_pos = 0
for cw in sorted([((ants[0][0] - x)%L) for x in ants[0][1:]]):
	dist_from_next_near00_cw.append(cw - old_pos)
	old_pos = cw

moved_dist = 0
dist_idx = [dist_from_next_near00_c_cw,dist_from_next_near00_cw]
for i in range(N-1):
	rot_dir = i%2
	rot_idx = i // 2
	
	if rot_idx >= len(dist_idx[rot_dir]):
		break
	
	dist = dist_idx[rot_dir][rot_idx] / 2.0
	
	if moved_dist + dist > L:
		break
	
	moved_dist += dist

base_idx -= i * (T // L)

moved_dist = 0
for i in range(N-1):
	rot_dir = i%2
	rot_idx = i // 2
	
	if rot_idx >= len(dist_idx[rot_dir]):
		break
	
	dist = dist_idx[rot_dir][rot_idx] / 2.0
	
	if moved_dist + dist > T:
		break
	
	moved_dist += dist

base_idx -= i

for i in range(N):
	print(ants_final_pos[(base_idx + i) % N])

Submission status: Runtime Error

Solution code:
import bisect

N,L,T= map(int,input().split())

ants = [[],[]]
for i in range(N):
	X,W = map(int,input().split())
	ants[W-1].append(X)

if len(ants[0]) == N:
	for i in range(N):
		print(((x+T)%L))
	exit()

if len(ants[0]) == 0:
	for i in range(N):
		print(((x-T)%L))
	exit()

ants_final_pos = sorted([((x+T)%L) for x in ants[0]] + [((x-T)%L) for x in ants[1]])
base_idx = ants_final_pos.index(((ants[0][0]+T)%L))
#print(f"debug ants_final_pos = {ants_final_pos}")
#print(f"debug base_idx = {base_idx}")
dist_from_next_near00_cw =[]
dist_from_next_near00_c_cw = []

old_pos = 0
for ccw in sorted([((x - ants[0][0])%L) for x in ants[1]]):
	dist_from_next_near00_c_cw.append(ccw - old_pos)
	old_pos = ccw


old_pos = 0
for cw in sorted([((ants[0][0] - x)%L) for x in ants[0][1:]]):
	dist_from_next_near00_cw.append(cw - old_pos)
	old_pos = cw

moved_dist = 0
dist_idx = [dist_from_next_near00_c_cw,dist_from_next_near00_cw]
for i in range(N-1):
	rot_dir = i%2
	rot_idx = i // 2
	
	if rot_idx >= len(dist_idx[rot_dir]):
		break
	
	dist = dist_idx[rot_dir][rot_idx] / 2.0
	
	if moved_dist + dist > L:
		break
	
	moved_dist += dist

base_idx -= i * (T // L)
#print(f"debug base_idx = {base_idx}")

moved_dist = 0
for i in range(N-1):
	rot_dir = i%2
	rot_idx = i // 2
	
	if rot_idx >= len(dist_idx[rot_dir]):
		print(f"debug1 i = {i}")
		break
	
	dist = dist_idx[rot_dir][rot_idx] / 2.0
	
	if moved_dist + dist > T:
		#print(f"debug2 i = {i}")
		#print(f"debug2 moved_dist = {moved_dist}")
		#print(f"debug2 dist = {dist}")
		break
	
	moved_dist += dist
	#print(f"debug3 i = {i}")

#print(f"debug i = {i}")
base_idx -= i
#print(f"debug base_idx = {base_idx}")

for i in range(N):
	print(ants_final_pos[(base_idx + i) % N])

Submission status: Runtime Error

Solution code:
import bisect

N,L,T= map(int,input().split())

mod_within = lambda x: x % L

ants = [[],[]]
for i in range(N):
	X,W = map(int,input().split())
	ants[W-1].append(X)

if len(ants[0]) == N:
	for i in range(N):
		print(((x+T)%L))
	exit()

if len(ants[0]) == 0:
	for i in range(N):
		print(((x-T)%L))
	exit()

ants_final_pos = sorted([((x+T)%L) for x in ants[0]] + [((x-T)%L) for x in ants[1]])
base_idx = ants_final_pos.index(((ants[0][0]+T)%L))
#print(f"debug ants_final_pos = {ants_final_pos}")
#print(f"debug base_idx = {base_idx}")
dist_from_next_near00_cw =[]
dist_from_next_near00_c_cw = []

old_pos = 0
for ccw in sorted([((x - ants[0][0])%L) for x in ants[1]]):
	dist_from_next_near00_c_cw.append(ccw - old_pos)
	old_pos = ccw


old_pos = 0
for cw in sorted([((ants[0][0] - x)%L) for x in ants[0][1:]]):
	dist_from_next_near00_cw.append(cw - old_pos)
	old_pos = cw

moved_dist = 0
dist_idx = [dist_from_next_near00_c_cw,dist_from_next_near00_cw]
for i in range(N-1):
	rot_dir = i%2
	rot_idx = i // 2
	
	if rot_idx >= len(dist_idx[rot_dir]):
		break
	
	dist = dist_idx[rot_dir][rot_idx] / 2.0
	
	if moved_dist + dist > L:
		break
	
	moved_dist += dist

base_idx -= i * (T // L)
#print(f"debug base_idx = {base_idx}")

moved_dist = 0
for i in range(N-1):
	rot_dir = i%2
	rot_idx = i // 2
	
	if rot_idx >= len(dist_idx[rot_dir]):
		print(f"debug1 i = {i}")
		break
	
	dist = dist_idx[rot_dir][rot_idx] / 2.0
	
	if moved_dist + dist > T:
		#print(f"debug2 i = {i}")
		#print(f"debug2 moved_dist = {moved_dist}")
		#print(f"debug2 dist = {dist}")
		break
	
	moved_dist += dist
	#print(f"debug3 i = {i}")

#print(f"debug i = {i}")
base_idx -= i
#print(f"debug base_idx = {base_idx}")

for i in range(N):
	print(ants_final_pos[(base_idx + i) % N])

Submission status: Runtime Error

Solution code:
import bisect

N,L,T= map(int,input().split())

mod_within = lambda x: x % L

ants = [[],[]]
for i in range(N):
	X,W = map(int,input().split())
	ants[W-1].append(X)

if len(ants[0]) == N:
	for i in range(N):
		print(mod_within(x+T))
	exit()

if len(ants[0]) == 0:
	for i in range(N):
		print(mod_within(x-T))
	exit()

ants_final_pos = sorted([mod_within(x+T) for x in ants[0]] + [mod_within(x-T) for x in ants[1]])
base_idx = ants_final_pos.index(mod_within(ants[0][0]+T))
#print(f"debug ants_final_pos = {ants_final_pos}")
#print(f"debug base_idx = {base_idx}")
dist_from_next_near00_cw =[]
dist_from_next_near00_c_cw = []

old_pos = 0
for ccw in sorted([mod_within(x - ants[0][0]) for x in ants[1]]):
	dist_from_next_near00_c_cw.append(ccw - old_pos)
	old_pos = ccw


old_pos = 0
for cw in sorted([mod_within(ants[0][0] - x) for x in ants[0][1:]]):
	dist_from_next_near00_cw.append(cw - old_pos)
	old_pos = cw

moved_dist = 0
dist_idx = [dist_from_next_near00_c_cw,dist_from_next_near00_cw]
for i in range(N-1):
	rot_dir = i%2
	rot_idx = i // 2
	
	if rot_idx >= len(dist_idx[rot_dir]):
		break
	
	dist = dist_idx[rot_dir][rot_idx] / 2.0
	
	if moved_dist + dist > L:
		break
	
	moved_dist += dist

base_idx -= i * (T // L)
#print(f"debug base_idx = {base_idx}")

moved_dist = 0
for i in range(N-1):
	rot_dir = i%2
	rot_idx = i // 2
	
	if rot_idx >= len(dist_idx[rot_dir]):
		print(f"debug1 i = {i}")
		break
	
	dist = dist_idx[rot_dir][rot_idx] / 2.0
	
	if moved_dist + dist > T:
		#print(f"debug2 i = {i}")
		#print(f"debug2 moved_dist = {moved_dist}")
		#print(f"debug2 dist = {dist}")
		break
	
	moved_dist += dist
	#print(f"debug3 i = {i}")

#print(f"debug i = {i}")
base_idx -= i
#print(f"debug base_idx = {base_idx}")

for i in range(N):
	print(ants_final_pos[(base_idx + i) % N])

Submission status: Runtime Error

Solution code:
import bisect
import sys


def input():
    return sys.stdin.readline()[:-1]

# N = int(input())
# A = [int(x) for x in input().split()]
# a, b, c = map(int, input().split())
# name1 = str(input())
# alph = {"A": 1, "B": 2, "C": 3, "D": 4, "E": 5}
# b = list(map(lambda x: math.ceil(x/10)*10, a))


n, l, t = map(int, input().split())
x = []
w = []
for i in range(n):
    a, b = map(int, input().split())
    x.append(a)
    w.append(b)


def distance(x, y):
    if x <= y:
        return y-x
    else:
        return y+l-x


def forward(x):
    x += 1
    if x == l:
        x = 0
    return x


def back(x):
    x -= 1
    if x == -1:
        x = l-1
    return x


temp_x = x.copy()
temp_w = w.copy()

for t in range(t):
    for i in range(n):
        if i == 0:
            if w[0] == 2:
                if w[n-1] == 1 and distance(x[n-1], x[0]) == 2:
                    temp_x[i] = back(x[i])
                    temp_w[i] = 1
                elif w[n-1] == 1 and distance(x[n-1], x[0]) == 1:
                    temp_w[i] = 1
                else:
                    temp_x[i] = back(x[i])
            elif w[i] == 1 and w[i+1] == 2:
                if distance(x[i], x[i+1]) == 2:
                    temp_x[i] = forward(x[i])
                    temp_w[i] = 2
                elif distance(x[i], x[i+1]) == 1:
                    temp_w[i] = 2
                else:
                    temp_x[i] = forward(x[i])
            elif w[i] == 1:
                temp_x[i] = forward(x[i])
        elif i == n-1:
            if w[n-1] == 1:
                if w[0] == 2 and distance(x[n-1], x[0]) == 2:
                    temp_x[i] = forward(x[i])
                    temp_w[i] = 2
                elif w[0] == 2 and distance(x[n-1], x[0]) == 1:
                    temp_w[i] = 2
                else:
                    temp_x[i] = forward(x[i])
            elif w[i] == 2 and w[i-1] == 1:
                if distance(x[i-1], x[i]) == 2:
                    temp_x[i] = back(x[i])
                    temp_w[i] = 1
                elif distance(x[i-1], x[i]) == 1:
                    temp_w[i] = 1
                else:
                    temp_x[i] = back(x[i])
            elif w[i] == 2:
                temp_x[i] = back(x[i])
        else:
            if w[i] == 1 and w[i+1] == 2:
                if distance(x[i], x[i+1]) == 2:
                    temp_x[i] = forward(x[i])
                    temp_w[i] = 2
                elif distance(x[i], x[i+1]) == 1:
                    temp_w[i] = 2
                else:
                    temp_x[i] = forward(x[i])
            elif w[i] == 1:
                temp_x[i] = forward(x[i])
            elif w[i] == 2 and w[i-1] == 1:
                if distance(x[i-1], x[i]) == 2:
                    temp_x[i] = back(x[i])
                    temp_w[i] = 1
                elif distance(x[i-1], x[i]) == 1:
                    temp_w[i] = 1
                else:
                    temp_x[i] = back(x[i])
            elif w[i] == 2:
                temp_x[i] = back(x[i])
    x = temp_x.copy()
    w = temp_w.copy()
for i in range(n):
    print(x[i])