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:
#!/usr/bin/env python3
import sys


def solve(N: int, L: int, T: int, X: "List[int]", W: "List[int]"):
    r=0
    x=0#基準座標
    w=0#基準index
    ans=[]
    f=True
    for i in range(N):
        if(W[i]==1):
            w=i
            x=X[i]
            f=False
            break
    if f :#全員逆向き
        for i in range(N):
            X[i]-=T%L
            if X[i]<0:
                X[i]+=L
        ans=X
        print("\n".join(map(str,ans)))
        return
    
    #基準より前にいるやつで逆のやつがいたら遠さからrをカウント
    for i in range(N):
        if W[(i+w)%N]==2:
            tmp=X[(i+w)%N]
            diff=max(tmp,x)-min(tmp,x)
            if(diff)/2<T:
                r+=1+(T-(diff)/2)//(L/2)
                if (T-(diff)/2)%(L/2)==0:
                    r-=1

    for i in range(N):
            if(W[i]==1):
                X[i]+=T%L
            else:
                X[i]-=T%L
            if(X[i]>L):X[i]-=L
            if(X[i]<0):X[i]+=L

    r%=N
    r=int(r)
    ans=X
    ans=ans[N-r:N]+ans[0:N-r]
    print("\n".join(map(str,ans)))
    return
    

                



# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    L = int(next(tokens))  # type: int
    T = int(next(tokens))  # type: int
    X = [int()] * (N)  # type: "List[int]"
    W = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        X[i] = int(next(tokens))
        W[i] = int(next(tokens))
    solve(N, L, T, X, W)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys


def solve(N: int, L: int, T: int, X: "List[int]", W: "List[int]"):
    r=0
    x=0#基準座標
    w=0#基準index
    ans=[]
    f=True
    for i in range(N):
        if(W[i]==1):
            w=i
            x=X[i]
            f=False
            break
    if f :#全員逆向き
        for i in range(N):
            X[i]-=T%L
            if X[i]<0:
                X[i]+=L
        ans=X
        print("\n".join(map(str,ans)))
        return
    
    #基準より前にいるやつで逆のやつがいたら遠さからrをカウント
    for i in range(N):
        if W[(i+w)%N]==2:
            tmp=X[(i+w)%N]
            diff=max(tmp,x)-max(tmp,x)
            if(diff)/2<T:
                r+=1+(T-(diff)/2)//(L/2)
                if (T-(diff)/2)%(L/2)==0:
                    r-=1

    for i in range(N):
            if(W[i]==1):
                X[i]+=T%L
            else:
                X[i]-=T%L
            if(X[i]>L):X[i]-=L
            if(X[i]<0):X[i]+=L

    r%=N
    r=int(r)
    ans=X
    ans=ans[N-r:N]+ans[0:N-r]
    print("\n".join(map(str,ans)))
    return
    

                



# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    L = int(next(tokens))  # type: int
    T = int(next(tokens))  # type: int
    X = [int()] * (N)  # type: "List[int]"
    W = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        X[i] = int(next(tokens))
        W[i] = int(next(tokens))
    solve(N, L, T, X, W)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys


def solve(N: int, L: int, T: int, X: "List[int]", W: "List[int]"):
    r=0
    x=0#基準座標
    w=0#基準index
    ans=[]
    f=True
    for i in range(N):
        if(W[i]==1):
            w=i
            x=X[i]
            f=False
            break
    if f :#全員逆向き
        for i in range(N):
            X[i]-=T%L
            if X[i]<0:
                X[i]+=L
        ans=X
        print("\n".join(map(str,ans)))
        return
    
    #基準より前にいるやつで逆のやつがいたら遠さからrをカウント
    for i in range(N):
        if W[(i+w)%N]==2:
            tmp=X[(i+w)%N]
            if(max(tmp,x)-max(tmp,x))/2<T:
                r+=1+(T-(tmp-x)/2)//(L/2)
                if (T-(tmp-x)/2)%(L/2)==0:
                    r-=1

    for i in range(N):
            if(W[i]==1):
                X[i]+=T%L
            else:
                X[i]-=T%L
            if(X[i]>L):X[i]-=L
            if(X[i]<0):X[i]+=L

    r%=N
    r=int(r)
    ans=X
    ans=ans[N-r:N]+ans[0:N-r]
    print("\n".join(map(str,ans)))
    return
    

                



# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    L = int(next(tokens))  # type: int
    T = int(next(tokens))  # type: int
    X = [int()] * (N)  # type: "List[int]"
    W = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        X[i] = int(next(tokens))
        W[i] = int(next(tokens))
    solve(N, L, T, X, W)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys


def solve(N: int, L: int, T: int, X: "List[int]", W: "List[int]"):
    r=0
    x=0#基準座標
    w=0#基準index
    ans=[]
    f=True
    for i in range(N):
        if(W[i]==1):
            w=i
            x=X[i]
            f=False
            break
    if f :#全員逆向き
        for i in range(N):
            X[i]-=T%L
            if X[i]<0:
                X[i]+=L
        ans=X
        print("\n".join(map(str,ans)))
        return
       
    for i in range(N):
        if W[(i+w)%N]==2:
            tmp=X[(i+w)%N]
            if(tmp-x)/2<T:
                r+=1+(T-(tmp-x)/2)//(L/2)
                if (T-(tmp-x)/2)%(L/2)==0:
                    r-=1

    for i in range(N):
            if(W[i]==1):
                X[i]+=T%L
            else:
                X[i]-=T%L
            if(X[i]>L):X[i]-=L
            if(X[i]<0):X[i]+=L

    r%=N
    r=int(r)
    ans=X
    ans=ans[N-r:N]+ans[0:N-r]
    print("\n".join(map(str,ans)))
    return
    

                



# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    L = int(next(tokens))  # type: int
    T = int(next(tokens))  # type: int
    X = [int()] * (N)  # type: "List[int]"
    W = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        X[i] = int(next(tokens))
        W[i] = int(next(tokens))
    solve(N, L, T, X, W)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:

import sys
import math
import fractions
import bisect
import queue
import heapq
import collections
import itertools
sys.setrecursionlimit(4100000)

MOD = int(1e9+7)
PI = 3.14159265358979323846264338327950288
INF = 1e18

'''
1行のint=====================================
N, K = map(int, input().split())
N, M = map(int, input().split())
A, B = map(int, input().split())

H, W = map(int, input().split())

L, R = map(int, input().split())

1行のstring=================================
S, T = input().split()

1行の整数配列================================
P = list(map(int,input().split()))

A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
D = list(map(int,input().split()))

L = list(map(int,input().split()))
R = list(map(int,input().split()))

T = list(map(int,input().split()))

改行あり整数==================================
X = []
Y = []
for i in range(N):
    x1,y1=[int(i) for i in input().split()]
    X.append(x1)
    Y.append(y1)

A = []
for i in range(N):
    a=int(input())
    A.append(a)

Pair = []
for i in range(N):
    x1,y1=[int(i) for i in input().split()]
    Pair.append((x1, y1))
    
2次元整数配列=====================================
A = []
for i in range(N):
    tmp = list(map(int,input().split()))
    A.append(tmp)


N行M列の初期化====================================
dp = [[VAL] * RETU for i in range(GYO)]

'''


N, L, T = map(int, input().split())
X = []
W = []
for i in range(N):
    x1,y1=[int(i) for i in input().split()]
    X.append(x1)
    W.append(y1)



# i番目の蟻とすれ違う回数
count = [0]*N
sum = 0

for i in range(N):
	if (W[0] == 1): 

		if (W[0] != W[i]) :
			dis = X[i] - X[0]
			if (dis < 0) :
				dis += L
				
			count[i] = (2 * T - dis) // L + int(dis <= 2 * T)

	else :

		if (W[0] != W[i]) :
			dis = X[0]-X[i]
			if (dis < 0) :
				dis += L
				

			count[i] = (2 * T - dis) // L + int(dis <= 2 * T)

			

		
	

if (W[0] == 1) :
	for i in range(N):
		sum += count[i]
		sum %= N
		
	
else :
	for i in range(N):
		sum -= count[i]
		sum %= N
		
	

sum %= N # ゼッケンの番号
if (sum < 0) :
	sum += N
	

x=0 # ゼッケンがsumの蟻の座標
if (W[0] == 1) :
	x = (X[0] + T) % L 
	
else :
	x = (X[0] - T) % L
	if (x < 0) :
		x += L
		
	


# すべての蟻の座標
new_X = [0] * N
for i in range(N):
	if (W[i] == 1) :
		new_X[i] = (X[i] + T) % L
		
	else :
		new_X[i] = (X[i] - T) % L
		if (new_X[i] < 0) :
			new_X[i] += L
			
		
new_X.sort()

idx = bisect.bisect_left(new_X, x)

ans = [0] * N
for i in range(N):
	ans[(i+sum)%N] = new_X[(idx + i)%N]
	

for i in range(N):
	print(ans[i])

Submission status: Wrong Answer

Solution code:



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

nxtX = [0] * N
cnt_LR = 0

for i in range(N):
    x,w = map(int, input().split())
    if w == 1:
        nxtX[i] = (x + T) % L
        cnt_LR += (x + T) // L
    else:
        if (x - T) > 0:
            nxtX[i] = x - T
        elif x - T == 0:
            nxtX[i] = 0
            #cnt_LR -= 1
        else:
            nxtX[i] = L - ((T - x) % L)
            cnt_LR -= (((T - x) // L) + 1) # xで1回、残りをLで割り切れる回数だけ0の位置を左向きにわたる

    #print("-------", cnt_LR)

nxtX.sort()
#print(cnt_LR)

# 左から右に超える蟻の方が多い場合 
if cnt_LR >= 0:
    cnt = cnt_LR % N
    """
    例えば1,2,3,4,5,6,7,8が右に一回超えて8,1,2,3,4,5,6,7になっていたら、[1~7] + [8]にする

    """
    ans = nxtX[cnt:] + nxtX[:cnt]

# 右から左に超える蟻の方が多い
else:
    cnt = abs(cnt_LR) % N
    """
    1,2,3,4,5,6,7,8 -> 3,4,5,6,7,8,1,2 を　[1,2] + [3~8]みたいな
    """
    ans = nxtX[-cnt:] + nxtX[:N-cnt]

for i in range(N):
    print(ans[i])

Submission status: Wrong Answer

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

ans = []
for x, w in ants:
    if w == 1:
        ans.append((x + t) % l)
    else:
        ans.append((x-t) % l)

print(ans[-1])
for i in ans[:-1]:
    print(i)

Submission status: Wrong Answer

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, L, T = MAP()

XW = [LIST() for _ in range(N)]

ans_s = [0]*N
for i, (X, W) in enumerate(XW):
	if W == 1:
		ans_s[i] = (X + T)%L
	else:
		ans_s[i] = (X-T)%L
# print(ans_s)
print(ans_s[-1])
for i in range(N-1):
	print(ans_s[i])

Submission status: Wrong Answer

Solution code:
from math import *
N, L, T = map(int, input().split())
ants = [tuple(map(int, input().split())) for _ in range(N)]


p = [(x + ((w + 1) % 3 - 1) * T) % L for x, w in ants]

c = 0
x0, w0 = ants[0]
for x, w in ants[1:]:
  if w == w0:
    continue
  if w0 == 1:
    c += ceil((T * 2 - (x - x0)) / L)
  else:
    c -= floor((T * 2 - L - x0 + x) / L) + 1
    
x0 = p[0]
p.sort()
gap = c - p.index(p[0])

for i in range(N):
  print(p[(i+gap)%N])

Submission status: Wrong Answer

Solution code:
from math import *
N, L, T = map(int, input().split())
ants = [tuple(map(int, input().split())) for _ in range(N)]


p = [(x + ((w + 1) % 3 - 1) * T) % L for x, w in ants]

c = 0
x0, w0 = ants[0]
for (_, w), x in zip(ants[1:], p[1:]):
  if w == w0:
    continue
  if w0 == 1:
    c += floor((T * 2 - (x - x0)) / L) + 1
  else:
    c -= floor((T * 2 - (x - x0) + L) / L) + 1
  
for i in range(N):
  print(p[(i-c)%N])

Submission status: Wrong Answer

Solution code:
from math import *
N, L, T = map(int, input().split())
ants = [tuple(map(int, input().split())) for _ in range(N)]


p = [(x + ((w + 1) % 3 - 1) * T) % L for x, w in ants]

c = 0
x0, w0 = ants[0]
for (_, w), x in zip(ants[1:], p[1:]):
  if w == w0:
    continue
  d = 1 - (w + 1) % 3
  c += ceil((2 * T + x0 - x) / L * d) * d

for i in range(N):
  print(p[(i-c)%N])

Submission status: Wrong Answer

Solution code:
from bisect import *
n, l, t = map(int, input().split())
a = [tuple(map(int, input().split())) + (i,) for i in range(n)]
ar = []
al = []
len_l, len_r = 0, 0
for x, w, i in a:
  if w == 1:
    ar.append((x, i))
    len_r += 1
  else:
    al.append((x, i))
    len_l += 1

offset = t*2 // l
v = [0] * n
for x, i in ar:
  dump = offset * len_l
  if len_l != 0:
    j = bisect(al, (x, i))
    k = bisect(al, ((x + t * 2) % l, i))
    if k == j and x > (x+t*2) % l:
      dump += len_l
    else:
      dump += (k - j) % len_l
  v[(i + dump) % n] = (x+t) % l

for x, i in al:
  dump = offset * len_r
  if len_r != 0:
    j = bisect(ar, (x, i))
    k = bisect(ar, ((x - t * 2) % l, i))
    if j == k and x < (x-t*2) % l:
      dump += len_r
    else:
      dump += (k - j) % len_r
  v[(i - dump) % n] = (x-t)%l


for x in v:
  print(x)

Submission status: Wrong Answer

Solution code:
from bisect import *
n, l, t = map(int, input().split())
a = [tuple(map(int, input().split())) + (i,) for i in range(n)]
ar = []
al = []
len_l, len_r = 0, 0
for x, w, i in a:
  if w == 1:
    ar.append((x, i))
    len_r += 1
  else:
    al.append((x, i))
    len_l += 1

offset = t*2 // l
v = [0] * n
for x, i in ar:
  dump = offset * len_l
  if len_l != 0:
    j = bisect(al, (x, i))
    k = bisect(al, ((x + t * 2) % l, i))
    if k == j and x > (x+t*2) % l:
      dump += len_l
    else:
      dump += (k - j)
  v[(i + dump) % n] = (x+t) % l

for x, i in al:
  dump = offset * len_r
  if len_r != 0:
    j = bisect(ar, (x, i))
    k = bisect(ar, ((x - t * 2) % l, i))
    if j == k and x < (x-t*2) % l:
      dump += len_r
    else:
      dump += k - j
  v[(i - dump) % n] = (x-t)%l


for x in v:
  print(x)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.buffer.readline
N, L, T= map(int,input().split())
X = []
W = []

for i in range(N):
    x,w = map(int,input().split())
    X.append(2*x)
    W.append(2*(1-w)+1)

pos = [((x+2*T*w) % (2*L))//2 for x,w in zip(X,W)]

meet = 0
for i in range(1,N):
    if W[0] != W[i]:
        if W[0] == 1:
            R = 2*T - (X[i] - X[0])//2
        else:
            R = 2*T - (2*L - (X[i] - X[0]))//2
        if R >= 0:
            meet += 1 + R//L

if W[0] == 1:
    ans = pos[-meet:] + pos[:-meet]
else: 
    ans = pos[meet:] + pos[:meet]
for ant in ans:
    print(ant)

Submission status: Wrong Answer

Solution code:

import sys
input = sys.stdin.buffer.readline
N, L, T= map(int,input().split())
X = []
W = []
for i in range(N):
    x,w = map(int,input().split())
    X.append(x)
    W.append(2*(1-w)+1)

pos = [(x+T*w) % L for x,w in zip(X,W)]

x0 = X[0]
w0 = W[0]

slide = 0
for i in range(1,N):
    if w0 != W[i]:
        slide += (X[i]-x0+2*T) // L
        slide %= N
slide = -(slide * w0) % N

ans = pos[slide:] + pos[:slide]
for ant in ans:
    print(ant)

Submission status: Wrong Answer

Solution code:
N,L,T=map(int,input().split())
X=[[0]*3 for _ in range(N)]
c=0
for i in range(N):
  a,b=map(int,input().split())
  X[i][0],X[i][1]=a,b
  if b==1:
    X[i][2]=a+T
  else:
    X[i][2]=a-T
w=X[0][1]
x=X[0][0]
for i in range(1,N):
  if X[i][1]==w:
    continue
  else:
    if w==1:
      c+=int((2*T+(X[i][0]-x))//L)
    else:
      c-=int((2*T+(L-X[i][0]+x))//L)
cnt=1
i=int((N-c)%N)
while cnt<=N:
  print(int(X[i][2]%L))
  cnt+=1
  i+=1
  if i>=N:
    i=0

Submission status: Wrong Answer

Solution code:
import numpy as np

N,L,T = map(int, input().split())
x,w = [],[]
for _ in range(N):
	tx,tw = map(int, input().split())
	if tw == 2:
		tw = -1
	x.append(tx)
	w.append(tw)

x = np.array(x)
w = np.array(w)
f = x+(w*T)
f %= L

if w[0] == 1:
	ghost = T*2
	s,t = divmod(ghost,L)
	cnt = s*np.count_nonzero(w == -1)
	dist = x[0] + t
	for i in range(1,N):
		if w[i] == -1 and x[i] <= dist:
			cnt += 1

	ind = N-(cnt%N)
else:
	ghost = T*2
	s,t = divmod(ghost, L)
	num_w1 = np.count_nonzero(w == 1)
	cnt = s*num_w1
	dist = x[0] + (L-t)
	un_cnt = 0
	for i in range(1,N):
		if w[i] == 1 and x[i] <= dist:
			un_cnt += 1
	cnt += (num_w1-un_cnt)
	ind = (cnt%N)+1

IND = np.arange(N)
IND = IND[np.argsort(f)]
f.sort()

for i in range(N):
	if IND[i] == ind:
		ind = i
		break

f = np.concatenate((f[ind:], f[:ind]))
for A in f:
	print(A)

Submission status: Wrong Answer

Solution code:
import numpy as np

N,L,T = map(int, input().split())
x,w = [],[]
for _ in range(N):
	tx,tw = map(int, input().split())
	if tw == 2:
		tw = -1
	x.append(tx)
	w.append(tw)

x = np.array(x)
w = np.array(w)
f = x+(w*T)
f %= L

if w[0] == 1:
	ghost = T*2
	s,t = divmod(ghost,L)
	cnt = s*np.count_nonzero(w == -1)
	dist = x[0] + t
	for i in range(1,N):
		if w[i] == -1 and x[i] <= dist:
			cnt += 1

	ind = -1 * (cnt%N)
else:
	ghost = T*2
	s,t = divmod(ghost, L)
	num_w1 = np.count_nonzero(w == 1)
	cnt = s*num_w1
	dist = x[0] + (L-t)
	un_cnt = 0
	for i in range(1,N):
		if w[i] == 1 and x[i] < dist:
			un_cnt += 1
	cnt += (num_w1-un_cnt)
	ind = cnt%N

#print(ind)
#print(f)
ans = np.concatenate([f[ind:],f[:ind]])

for A in ans:
	print(A)

Submission status: Wrong Answer

Solution code:
import numpy as np

N,L,T = map(int, input().split())
x,w = [],[]
for _ in range(N):
	tx,tw = map(int, input().split())
	if tw == 2:
		tw = -1
	x.append(tx)
	w.append(tw)

x = np.array(x)
w = np.array(w)
f = x+(w*T)
f %= L

if w[0] == 1:
	ghost = T*2
	s,t = divmod(ghost,L)
	cnt = s*np.count_nonzero(w == -1)
	dist = x[0] + t
	for i in range(1,N):
		if w[i] == -1 and x[i] <= dist:
			cnt += 1

	ind = -1 * (cnt%N)
else:
	ghost = T*2
	s,t = divmod(ghost, L)
	num_w1 = np.count_nonzero(w == 1)
	cnt = s*num_w1
	dist = x[0] + (L-t)
	un_cnt = 0
	for i in range(1,N):
		if w[i] == 1 and x[i] < dist:
			un_cnt += 1
	cnt += (num_w1-un_cnt)
	ind = cnt%N

print(ind)
print(f)
ans = np.concatenate([f[ind:],f[:ind]])

print(*ans)

Submission status: Wrong Answer

Solution code:
N,L,T = map(int,input().split())
x,w = map(int,input().split())
D = []
m = 0
def f(x,w):
    if w == 1:
        a = (x+T) % L
        return a
    else:
        a = (x-T) % L
        return a
for i in range(2,N+1):
    X,W = map(int,input().split())
    a = f(X,W)
    if f(X,W) < f(x,w):
        a += L
    D.append(a)
    if w != W:
        if w == 1:
            l = (X - x)%L
        else:
            l = (x - X)%L
        if l <= 2*T:
            t = (2*T - l)//L + 1
        else:
            t = 0
        m += t
if w == 1:
    p = m%N + 1
else:
    p = (1-m)%N
    if p == 0:
        p = N
D.sort()
dic = {}
dic[p] = f(x,w)
for i in range(N-1):
    p += 1
    if p > N:
        p -= N
    q = D[i]
    dic[p] = q%L
for i in range(1,N+1):
    print(dic[i])

Submission status: Wrong Answer

Solution code:
N,L,T = map(int,input().split())
x,w = map(int,input().split())
D = []
m = 0
def f(x,w):
    if w == 1:
        a = (x+T) % L
        return a
    else:
        a = (x-T) % L
        return a
for i in range(2,N+1):
    X,W = map(int,input().split())
    a = f(X,W)
    if f(X,W) < f(x,w):
        a += L
    D.append(a)
    if w != W:
        if w == 1:
            l = (X - x)%L
        else:
            l = (x - X)%L
        t = (2*T - l)//L + 1
        m += t
if w == 1:
    p = m%N + 1
else:
    p = (1-m)%N
    if p == 0:
        p = N
D.sort()
dic = {}
dic[p] = f(x,w)
for i in range(N-1):
    p += 1
    if p > N:
        p -= N
    q = D[i]
    dic[p] = q%L
for i in range(1,N+1):
    print(dic[i])

Submission status: Wrong Answer

Solution code:
N,L,T = map(int,input().split())
x,w = map(int,input().split())
D = []
m = 0
def f(x,w):
    if w == 1:
        a = (x+T) % L
        return a
    else:
        a = (x-T) % L
        return a
for i in range(2,N+1):
    X,W = map(int,input().split())
    a = f(X,W)
    if f(X,W) < f(x,w):
        a += L
    D.append(a)
    if w != W:
        if w == 1:
            l = (X - x)%L
        else:
            l = (x - X)%L
        t = (2*T - l)%L + 1
        m += t
if w == 1:
    p = m%N + 1
else:
    p = (1-m)%N
    if p == 0:
        p = N
D.sort()
dic = {}
dic[p] = f(x,w)
for i in range(N-1):
    p += 1
    if p > N:
        p -= N
    q = D[i]
    dic[p] = q%L
for i in range(1,N+1):
    print(dic[i])

Submission status: Wrong Answer

Solution code:
N,L,T = map(int,input().split())
x,w = map(int,input().split())
D = []
m = 0
def f(x,w):
    if w == 1:
        a = (x+T) % L
        return a
    else:
        a = (x-T) % L
        return a
for i in range(2,N+1):
    X,W = map(int,input().split())
    a = f(X,W)
    if f(X,W) < f(x,w):
        a += L
    D.append(a)
    if w != W:
        if w == 1:
            l = (X - x)%L
        else:
            l = (x - X)%L
        t = (2*T - l)%L + 1
        m += t
if w == 1:
    p = m%N + 1
else:
    p = (1-m)%4
    if p == 0:
        p = 4
D.sort()
dic = {}
dic[p] = f(x,w)
for i in range(N-1):
    p += 1
    if p > N:
        p -= N
    q = D[i]
    dic[p] = q%L
for i in range(1,N+1):
    print(dic[i])

Submission status: Wrong Answer

Solution code:
import bisect
N, L, T = map(int, input().split())
x = [0] * N
w = [0] * N
ans_x = [0] * N
x_w1 = []
x_w1_2T = []
x_w2 = []
for i in range(N):
    x[i], w[i] = map(int, input().split())
    if w[i] == 1:
        x_w1.append((x[i]) % L)
        x_w1_2T.append((x[i] + 2*T) % L)
        ans_x[i] = (x[i] + T) % L
    else:
        x_w2.append(x[i])
        ans_x[i] = (x[i] - T) % L
collision_count = 0
for ant_w1_x, ant_w1_2T_x in zip(x_w1, x_w1_2T):
    plus_collison_count = (bisect.bisect_right(x_w2, ant_w1_2T_x) - bisect.bisect_left(x_w2, ant_w1_x))
    if ant_w1_2T_x - ant_w1_x < 0:
        plus_collison_count = len(x_w2) - plus_collison_count
    collision_count += plus_collison_count + ((2 * T) // L) * len(x_w2)
collision_count %= N
for _ in range(collision_count):
    swap = ans_x[0]
    ans_x.remove(swap)
    ans_x.append(swap)
for ant_ans_x in ans_x:
    print(ant_ans_x)

Submission status: Wrong Answer

Solution code:
import bisect
N, L, T = map(int, input().split())
x = [0] * N
w = [0] * N
ans_x = [0] * N
x_w1 = []
x_w1_2T = []
x_w2 = []
for i in range(N):
    x[i], w[i] = map(int, input().split())
    if w[i] == 1:
        x_w1.append((x[i]) % L)
        x_w1_2T.append((x[i] + 2*T) % L)
        ans_x[i] = (x[i] + T) % L
    else:
        x_w2.append(x[i])
        ans_x[i] = (x[i] - T) % L
collision_count = 0
for ant_w1_x, ant_w1_2T_x in zip(x_w1, x_w1_2T):
    plus_collison_count = (bisect.bisect_right(x_w2, ant_w1_2T_x) - bisect.bisect_right(x_w2, ant_w1_x))
    if ant_w1_2T_x - ant_w1_x < 0:
        plus_collison_count = len(x_w2) - plus_collison_count
    collision_count += plus_collison_count + ((2 * T) // L) * len(x_w2)
collision_count %= N
for _ in range(collision_count):
    swap = ans_x[0]
    ans_x.remove(swap)
    ans_x.append(swap)
for ant_ans_x in ans_x:
    print(ant_ans_x)

Submission status: Wrong Answer

Solution code:
N, L, T = [int(v) for v in input().split(" ")]

ants = {"x":[], "w":[]}

# データを読み込み
for _ in range(N):

  x, w = input().split(" ")
  ants["x"].append(int(x))
  ants["w"].append(1 if w=="1" else -1)

collision = [0]*N
reposition = [0]*N
reindex = [0]*N

for i in range(N):
  for j in range(i,N):

    # 相対初期位置・相対移動距離
    dx = ants["x"][j] - ants["w"][i]
    dL = (ants["w"][j] - ants["w"][i])*T

    # 直進した時にすれ違う回数
    n_passing = (dL>0-dL<0)*(dL+dx)//L + int(dx*dL<0)

    # すれ違い回数を加算[TODO]
    collision[i] += n_passing
    collision[j] += n_passing

    # 位置を更新
    reposition[i] = (ants["x"][i] + ants["w"][i]*T)%L
    reindex[i] = (i+ants["w"][i]*collision[i])%N

# iがどこに移動したかが重要、それはすれ違う時に、反発しなかったら辿り着くはずだった場所
for i in range(N):
  ants["x"][i] = reposition[ reindex.index(i) ]    

print(ants["x"])

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!

CLOCKWISE = 1
COUNTERCLOCKWISE = -1

class Ant:
    def __init__(self, x, w):
        self.x = x
        self.w = w

nums=list(map(int,input().split()))

N = nums[0]
L = nums[1]
T = nums[2]

ants = []

for i in range(N):
    nums=list(map(int,input().split()))
    if nums[1] == 1:
        ants.append(Ant(nums[0], CLOCKWISE))
    else:
        ants.append(Ant(nums[0], COUNTERCLOCKWISE))
    

lower = ants[0].x
upper = (ants[0].x + T) % L

cnt_neg = -1
cnt_pos = 0

for i in range(N):
    if ants[0].w == ants[i].w and ((ants[0].x - ants[i].x) * ants[0].w) % L < T:
        cnt_neg += 1
    elif ants[0].w != ants[i].w and ((ants[i].x - ants[0].x) * ants[0].w) % L < 2 * T:
        cnt_pos += 1

result = []
for i in range(N):
    result.append((ants[i].x + T * ants[i].w) % L)


if cnt_pos % 2 == 1:
    cnt_neg += 1
    
if cnt_neg % 2 == 1:
    cnt_pos += 1

if ants[0].w > 0:
    for i in range(- cnt_neg + 1 , N - cnt_neg + 1):
        print(result[i % N])
else:
    for i in range(- cnt_pos+ 1 , N - cnt_pos + 1):
        print(result[i % N])
"""        
if ants[0].w == CLOCKWISE:
    for i in range(- cnt_neg + 1 , N - cnt_neg + 1):
        print(result[i])
else:
    for i in range(- cnt_neg, N - cnt_neg):
        print(result[i])

        """

Submission status: Wrong Answer

Solution code:
import numpy as np

N, L, T = map(int, input().split())
ant = []
for i in range(N):
  a = list(map(int, input().split()))
  a[0] = a[0]
  ant.append(a)
count = 0
for i in range(1,N):
  if (ant[0][1] == 1) and (ant[i][1] == 2):
    count += (ant[0][0] - ant[i][0] + 2*T) // L + 1
  if (ant[0][1] == 2) and (ant[i][1] == 1):
    count -= (ant[i][0] - ant[0][0] - L + 2*T) //L + 1
count = count % N
coord = [0 for _ in range(N)]
for i in range(N):
  if ant[i][1] == 1:
    coord[i] = (ant[i][0] + T) % L
  else:
    coord[i] = (ant[i][0] - T) % L
ant0 = coord[0]
coord.sort()
coord2 = sorted(coord)
i0 = coord2.index(ant0)
coord2 = np.roll(coord, count-i0)
for i in range(N):
  print(coord2[i])

Submission status: Wrong Answer

Solution code:
import numpy as np

N, L, T = map(int, input().split())
ant = []
for i in range(N):
  a = list(map(int, input().split()))
  a[0] = a[0]
  ant.append(a)
count = 0
for i in range(1,N):
  if (ant[0][1] == 1) and (ant[i][1] == 2):
    count += (ant[0][0] - ant[i][0] + 2*T) // L + 1
  if (ant[0][1] == 2) and (ant[i][1] == 1):
    count -= (ant[i][0] - ant[0][0] - L + 2*T) //L + 1
count = count % N
coord = [0 for _ in range(N)]
for i in range(N):
  if ant[i][1] == 1:
    coord[i] = (ant[i][0] + T) % L
  else:
    coord[i] = (ant[i][0] - T) % L
ant0 = coord[0]
coord.sort()
i0 = coord.index(ant0)
coord2 = np.roll(coord, count-i0)
for i in range(N):
  print(coord2[i])

Submission status: Wrong Answer

Solution code:
N, L, T = map(int, input().split())
ant = []
for i in range(N):
  a = list(map(int, input().split()))
  a[0] = a[0]
  ant.append(a)
count = 0
for i in range(1,N):
  if (ant[0][1] == 1) and (ant[i][1] == 2):
    count += (ant[0][0] - ant[i][0] + 2*T) // L + 1
  if (ant[0][1] == 2) and (ant[i][1] == 1):
    count -= (ant[i][0] - ant[0][0] - L + 2*T) //L + 1
count = count % N
coord = [0 for _ in range(N)]
for i in range(N):
  if ant[i][1] == 1:
    coord[i] = (ant[i][0] + T) % L
  else:
    coord[i] = (ant[i][0] - T) % L
coord.sort()
if count != 0:
  coord = coord[count:N] + coord[0:count]
for i in range(N):
  print(coord[i])

Submission status: Wrong Answer

Solution code:
N, L, T = map(int, input().split())
ant = []
for i in range(N):
  a = list(map(int, input().split()))
  a[0] = a[0]
  ant.append(a)
coord = [0 for _ in range(N)]
for i in range(N):
  if ant[i][1] == 1:
    coord[i] = (ant[i][0] + T) % L
  else:
    coord[i] = (ant[i][0] - T) % L
ant0 = coord[0]
coord.sort()
i0 = coord.index(ant0)
if i0 != 0:
  coord = coord[i0:N] + coord[0:i0]
for i in range(N):
  print(coord[i])

Submission status: Wrong Answer

Solution code:
N, L, T = map(int, input().split())
ant = []
for i in range(N):
  a = list(map(int, input().split()))
  a[0] = a[0]
  ant.append(a)
count = 0
for i in range(1,N):
  if (ant[0][1] == 1) and (ant[i][1] == 2):
    count -= (ant[0][0] - ant[i][0] + 2*T) // L + 1
  if (ant[0][1] == 2) and (ant[i][1] == 1):
    count += (ant[i][0] - ant[0][0] - L + 2*T) //L + 1
count = count % N
ant2 = [0 for _ in range(N)]
for i in range(N):
  if ant[i][1] == 1:
    ant2[i] = (ant[i][0] + T) % L
  else:
    ant2[i] = (ant[i][0] - T) % L
if count != 0:
  ant2 = ant2[count:N] + ant2[0:count]
for i in range(N):
  print(ant2[i])

Submission status: Wrong Answer

Solution code:
def main():
    n,l,t = map(int, input().split())
    ls = [list(map(int, input().split())) for _ in range(n)]
    ant1 = [(1+(t-(ls[i][0]-ls[0][0]))//l if t-(ls[i][0]-ls[0][0])>=0 else 0) if ls[i][1] == 2 else 0 for i in range(n)]
    ansls = [(t+ls[i][0])%l if ls[i][1] == 1 else (l+(ls[i][0]-t)%l if (ls[i][0]-t)%l<0 else (ls[i][0]-t)%l) for i in range(n)]
    ant1p = ansls[0]
    ansls.sort()
    ant1n = sum(ant1)%n
    s = 0
    for i in range(n):
        if ant1p == ansls[i]:
            s = i
            break
    ansls = ansls[s-ant1n:]+ansls[:s-ant1n]
    for i in range(n):
        print(ansls[i])

if __name__ == "__main__":
    main()