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())
data=[0]*n
s=0
for i in range(n):
  x,w=map(int,input().split())
  if w==1:
    data[i]=(x+t)%l
    s+=(x+t)//l
  else:
    data[i]==(x-t)%l
    s+=(x-t)//l
data.sort()
res=s%n
data=data[res:]+data[:res]
for i in data:
  print(i)

Submission status: Wrong Answer

Solution code:
n, l, t = map(int, input().split())
cor_0 = [list(map(int, input().split())) for _ in range(n)]
cor_t = [(x+t)%l if w == 1 else (x-t)%l for x,w in cor_0]
x0, w0 = cor_0[0]
xt = cor_t[0]
cor_t.sort()


marker = 0
for i in range(1,n):
    if w0 == cor_0[i][1]:
        continue
    
    if w0 == 1:
        dist = 2 * t
        if dist - (cor_0[i][0] - x0) % l >= 0:
            marker += 1
            dist -= (cor_0[i][0] - x0) % l
        else:
            continue
        marker += dist // l
    else:
        dist = 2 * t
        if dist - (x0 - cor_0[i][0]) % l >= 0:
            marker -= 1
            dist -= (x0 - cor_0[i][0]) % l
        else:
            continue
        marker -= dist // l

marker %= n
s_point = (cor_t.index(xt) - marker) % n
for i in range(s_point, s_point+n):
    print(cor_t[i%n])

Submission status: Wrong Answer

Solution code:
import math


n, l, t = map(int, input().split())
cor_0 = [list(map(int, input().split())) for _ in range(n)]
cor_t = [(x+t)%l if w == 1 else (x-t)%l for x,w in cor_0]
xt = cor_t[0]
cor_t.sort()

x0, w0 = cor_0[0]
marker = 0
for i in range(1,n):
    if w0 == cor_0[i][1]:
        continue
    
    if w0 == 1:
        dist = 2 * t
        if dist - (cor_0[i][0] - x0) % l >= 0:
            marker += 1
            dist -= (cor_0[i][0] - x0) % l
        marker += dist // l
    else:
        dist = 2 * t
        if dist - (x0 - cor_0[i][0]) % l >= 0:
            marker -= 1
            dist -= (x0 - cor_0[i][0]) % l
        marker -= dist // l

marker %= n
s_point = (cor_t.index(xt) - marker) % n
for i in range(s_point, s_point+n):
    print(cor_t[i%n])

Submission status: Wrong Answer

Solution code:
import math


n, l, t = map(int, input().split())
cor_0 = [list(map(int, input().split())) for _ in range(n)]
cor_t = [(x+t)%l if w == 1 else (x-t)%l for x,w in cor_0]
xt = cor_t[0]
cor_t.sort()

x0, w0 = cor_0[0]
marker = 0
for i in range(1,n):
    if w0 == cor_0[i][1]:
        continue
    
    if w0 == 1:
        marker += 2 * t // l
        if 2 * t % l - (cor_0[i][0] - x0) % l >= 0:
            marker += 1
    else:
        marker -= 2 * t // l
        if 2 * t % l - (cor_0[i][0] - x0) % l >= 0:
            marker -= 1

marker %= n
s_point = (cor_t.index(xt) - marker) % n
for i in range(s_point, s_point+n):
    print(cor_t[i%n])

Submission status: Wrong Answer

Solution code:
n , l , t = map(int,input().split())
ant = [tuple(map(int,input().split())) for i in range(n)]
ans = []
for x , w in ant:
    ans.append((x + (-w*2+3)*t)%l)

if n == 1:
    print(ans[0])
    exit()
cou = 0
if ant[0][1] == 1:
    for i in range(1,n):
        if ant[i][1] == 2:
            y = (ant[0][0] - ant[i][0])%l
            if 2*t > y:
                cou -= 1
                cou -= (2*t-y)//l
elif ant[0][1] == 2:
    for i in range(1,n):
        if ant[i][1] == 1:
            y = (ant[i][0] - ant[0][0])%l
            if 2*t > y:
                cou += 1
                cou += (2*t-y)//l
cou %= n
ans = ans[cou:] + ans[:cou]
for i in ans:
    print(i)

Submission status: Wrong Answer

Solution code:
# AGC C Ants on a Circle
f=lambda:map(int,input().split())
N,L,T=f()
X,W=[],[]
for _ in [0]*N:
    x,w=f()
    X.append(x)
    W.append(w)
    
if W[0]==2:
    X[0]+=L
    
col=0
for j in range(N):
    if W[j]==W[0]:
        continue
    else:
        if W[0]==1:
            if 2*T-(X[j]-X[0])>=0:
                col+=(1+(2*T-(X[j]-X[0]))//L)
        else:
            if 2*T-(X[0]-X[2])>=0:
                col-=(1+(2*T-(X[0]-X[2]))//L)

col=col%N
X2=[(X[i]+(3-2*W[i])*T) % L for i in range(N)]
X2_0=X2[0]

X2.sort()

index=[i for i,x in enumerate(X2) if x==X2_0]

if len(index)==1:
    index=index[0]
else:
    if W[0]==1:
        index=index[1]
    else:
        index=index[0]

i=(index-col)%N

X2=X2[i:]+X2[:i]
print(*X2,sep='\n')

Submission status: Wrong Answer

Solution code:
# AGC C Ants on a Circle
f=lambda:map(int,input().split())
N,L,T=f()
X,W=[],[]
for _ in [0]*N:
    x,w=f()
    X.append(x)
    W.append(w)
    
if W[0]==2:
    X[0]+=L
    
col=0
for j in range(N):
    if W[j]==W[0]:
        continue
    else:
        if W[0]==1:
            if 2*T-(X[j]-X[0])>=0:
                col+=(1+(2*T-(X[j]-X[0]))//L)*j
        else:
            if 2*T-(X[0]-X[2])>=0:
                col-=(1+(2*T-(X[0]-X[2]))//L)*j
    
col=col%N
X2=[(X[i]+(3-2*W[i])*(T-0.02)) % L for i in range(N)]
ant0=(X2[0],col)

X2.sort()

x=X2.index(ant0[0])

i=x-col
for _ in [0]*N:
    if i==N:
        i=0
    print(round(X2[i]))
    i+=1

Submission status: Wrong Answer

Solution code:
# AGC C Ants on a Circle
f=lambda:map(int,input().split())
N,L,T=f()
X,W=[],[]
for _ in [0]*N:
    x,w=f()
    X.append(x)
    W.append(w)
    
if W[0]==2:
    X[0]+=L
    
col=0
for j in range(N):
    if W[j]==W[0]:
        continue
    else:
        if W[0]==1:
            if 2*T-(X[j]-X[0])>=0:
                col+=(1+(2*T-(X[j]-X[0]))//L)
        else:
            if 2*T-(X[0]-X[2])>=0:
                col+=(1+(2*T-(X[0]-X[2]))//L)
    
col=col%N
X2=[(X[i]+(3-2*W[i])*(T-0.02)) % L for i in range(N)]
ant0=(X2[0],col)

X2.sort()

x=X2.index(ant0[0])

i=x-col
for _ in [0]*N:
    if i==N:
        i=0
    print(round(X2[i]))
    i+=1

Submission status: Wrong Answer

Solution code:
# AGC C Ants on a Circle
f=lambda:map(int,input().split())
N,L,T=f()
X,W=[],[]
for _ in [0]*N:
    x,w=f()
    X.append(x)
    W.append(w)
    
if W[0]==2:
    X[0]+=L
    
col=0
for j in range(N):
    if W[j]==W[0]:
        continue
    else:
        if W[0]>0:
            if 2*T-(X[j]-X[0])>=0:
                col+=1+(2*T-(X[j]-X[0]))//L
            else:
                col+=0
        else:
            col-=max((2*T-X[j]+X[0])//L,0)
col=col%N
X2=[(X[i]+(3-2*W[i])*(T-0.01)) % L for i in range(N)]

ant0=(X2[0],col)

X2.sort()

x=X2.index(ant0[0])

i=x-col
for _ in [0]*N:
    if i==N:
        i=0
    print(round(X2[i]))
    i+=1

Submission status: Wrong Answer

Solution code:
from sys import stdin
import bisect
N,LL,T = map(int,stdin.readline().split())

R = []
L = []
R2 = []
L2 = []

for i in range(N):
    x,w = map(int,stdin.readline().split())
    if w == 1:
        R.append((x,i))
        R2.append(x)
        R2.append(x-LL)
    else:
        L.append((x,i))
        L2.append(x)
        L2.append(x+LL)

R2 += [float("-inf"),float("inf")]
L2 += [float("-inf"),float("inf")]
R2.sort()
L2.sort()

ans = [None] * N
for rx,ind in R:

    last = (rx + T) % LL
    plus = ind + (T // (LL//2)) * len(L)
    rem  = T % (LL//2)

    #rx以上 re+2*rem未満の数を数えればいい
    #l <= x < rを求めるには r以上最小のind-l以上最小のind
    plus += bisect.bisect_left(L2,rx+2*rem) - bisect.bisect_left(L2,rx)
    ans[plus % N] = last

for lx,ind in L:

    last = (lx - T) % LL
    plus = ind - (T // (LL//2)) * len(R)
    rem = T % (LL//2)

    #lx以下、le-2*rem超過の数を数えればいい
    #l < x <= r -> l+1 <= x < r+1
    plus -= bisect.bisect_left(R2,lx+1) - bisect.bisect_left(R2,lx-2*rem+1)
    ans[plus % N] = last

if None in ans:
    print (sasasas)

for i in ans:
    print (i)

Submission status: Wrong Answer

Solution code:

"""

https://atcoder.jp/contests/agc013/tasks/agc013_c

蟻がカードを持っていて、すれ違う際にカードを交換すると考える
T秒後にどの蟻がどのカードを持っているか考えればいい

Tが大きいため、良い感じに処理する必要がある
→1周をシミュレートする？
→1周した際の変化を累積させ、最後の余分な時間分を計算すればいい

1週分のシミュレーションには、最悪(N/2)**2 = 2500000000
がかかるので、もっと高速化を考える必要がある

実は1周するにあたり、カードは以下のように動く
>>>> <<<<
7531 2468

>> <<<<
31 24
75   68

つまり、2回かけて1つ後ろに移動する

あとは計算しやすいような工夫を考える
普通に移動経路を時間とともに列挙しようとするとO(LCM(右向き,左向き))かかる

=====答えを見た=====

あまりにシンプルで驚愕
流石AGC…
困った時はいい性質がないか観察することが大事…

カードは必ず昇順に並ぶ？
最初は昇順
→昇順でぶつかったとする
→カードは交換されるので、順序は変わらない！！(すごい)

あとはT秒後の0のカードの位置さえ分かればいい
愚直にやってもできるが…
ぶつかる際、AとA+1が交換される
時計回りのやつは+1される。反時計回りのやつは-1される
→あるアリが持ってる数字はすれ違う回数がわかれば求められる
一周にかかる時間は L//2
残りを良い感じに計算する (二分探索すればO(logN))

"""

from sys import stdin
import bisect
N,LL,T = map(int,stdin.readline().split())

R = []
L = []
R2 = []
L2 = []

for i in range(N):
    x,w = map(int,stdin.readline().split())
    if w == 1:
        R.append((x,i))
        R2.append(x)
        R2.append(x-LL)
    else:
        L.append((x,i))
        L2.append(x)
        L2.append(x+LL)

R2 += [float("-inf"),float("inf")]
L2 += [float("-inf"),float("inf")]
R2.sort()
L2.sort()

ans = [None] * N
for rx,ind in R:

    last = (rx + T) % LL
    plus = ind + (T // (LL//2)) * len(L)
    rem  = T % (LL//2)

    #rx以上 re+2*rem未満の数を数えればいい
    #l <= x < rを求めるには r以上最小のind-l以上最小のind
    plus += bisect.bisect_left(L2,rx+2*rem) - bisect.bisect_left(L2,rx)
    ans[plus % N] = last

for lx,ind in L:

    last = (lx - T) % LL
    plus = ind - (T // (LL//2)) * len(R)
    rem = T % (LL//2)

    #lx以下、le-2*rem超過の数を数えればいい
    #l < x <= r -> l+1 <= x < r+1
    plus -= bisect.bisect_left(R2,lx+1) - bisect.bisect_left(R2,lx-2*rem+1)
    ans[plus % N] = last

for i in ans:
    print (i)

Submission status: Wrong Answer

Solution code:

# agc 013

N, L, T = map(int, input().split())
c1 = 0
c2 = 0
c = 0
c1_sum, c2_sum = 0, 0
c_list, x_list, w_list, xl_list = [], [], [], []
d = [0, 1, -1]
for _ in range(N):
    x, w = map(int, input().split())
    x_list.append(x)
    xl_list.append(x + (d[w]*(T%L)))
    w_list.append(w)
    if w == 1:
        c1 += 1
    else:
        c2 += 1

# ぶつかる数のカウント
for i in range(1, N):
    if w_list[0] == 1:
        if (w_list[i] == 2) & ((x_list[i] - x_list[0] + 1)//2 <= T%L):
            c+=1
    if w_list[0] == 2:
        if (w_list[i] == 1) & ((L-(x_list[i] - x_list[0]) + 1)//2 <= T%L):
            c-=1

[print((xl_list[0-(c%N)+o])%L) for o in range(N)]

Submission status: Wrong Answer

Solution code:

# agc 013

N, L, T = map(int, input().split())
c1 = 0
c2 = 0
c = 0
c1_sum, c2_sum = 0, 0
c_list, x_list, w_list, xl_list = [], [], [], []
d = [0, 1, -1]
for _ in range(N):
    x, w = map(int, input().split())
    x_list.append(x)
    xl_list.append(x + (d[w]*(T%L)))
    w_list.append(w)
    if w == 1:
        c1 += 1
    else:
        c2 += 1

# ぶつかる数のカウント
for i in range(1, N):
    if w_list[0] == 1:
        if (w_list[i] == 2) & ((x_list[i] - x_list[0] + 1)//2 <= T%L):
            c+=1
    if w_list[0] == 2:
        if (w_list[i] == 1) & ((x_list[i] - x_list[0] + 1)//2 <= T%L):
            c-=1

[print((xl_list[0-(c%N)+o])%L) for o in range(N)]

Submission status: Wrong Answer

Solution code:

# agc 013

N, L, T = map(int, input().split())
c1 = 0
c2 = 0
c = 0
c1_sum, c2_sum = 0, 0
c_list, x_list, w_list, xl_list = [], [], [], []
d = [0, 1, -1]
for _ in range(N):
    x, w = map(int, input().split())
    x_list.append(x)
    xl_list.append(x + (d[w]*(T%L)))
    w_list.append(w)
    if w == 1:
        c1 += 1
    else:
        c2 += 1

# ぶつかる数のカウント
for i in range(1, N):
    if w_list[0] == 1:
        if (w_list[i] == 2) & ((x_list[i] - x_list[0] + 1)//2 <= T):
            c+=1
    if w_list[0] == 2:
        if (w_list[i] == 1) & ((x_list[i] - x_list[0] + 1)//2 <= T):
            c-=1

[print((xl_list[0-(c%N)+o])%L) for o in range(N)]

Submission status: Wrong Answer

Solution code:
N, L, T = map(int, input().split())
c1 = 0
c2 = 0
c = 0
c1_sum, c2_sum = 0, 0
c_list, x_list, w_list, xl_list = [], [], [], []
d = [0, 1, -1]
for _ in range(N):
    x, w = map(int, input().split())
    x_list.append(x)
    xl_list.append(x + (d[w]*(T%L)))
    w_list.append(w)
    if w == 1:
        c1 += 1
    else:
        c2 += 1

# 数のカウント
for i in range(1, N):
    if xl_list[i] < xl_list[0]:
        c += 1

[print((xl_list[0-c+o])%L) for o in range(N)]

Submission status: Wrong Answer

Solution code:
N, L, T = map(int, input().split())
c1 = 0
c2 = 0
c = 0
c1_sum, c2_sum = 0, 0
c_list, x_list, w_list, xl_list = [], [], [], []
d = [0, 1, -1]
for _ in range(N):
    x, w = map(int, input().split())
    x_list.append(x)
    xl_list.append(x + (d[w]*(T%L)))
    w_list.append(w)
    if w == 1:
        c1 += 1
    else:
        c2 += 1

# 数のカウント
for i in range(1, N):
    if xl_list[i] < xl_list[0]:
        c += 1
print(x_list,xl_list, c, )
[print((xl_list[0-c+o])%L) for o in range(N)]

Submission status: Wrong Answer

Solution code:
import sys
def MI(): return map(int,sys.stdin.readline().rstrip().split())


N,L,T = MI()
q,r = T//L,T % L
A = []
for i in range(N):
    x,w = MI()
    if w == 1:
        for j in range(-1,2):
            A.append(x+r+j*L)
    else:
        for j in range(-1,2):
            A.append(x-r+j*L)
A.sort()
ANS = [A[i] % L for i in range(N,2*N)]
for i in range(N):
    print(ANS[(i+q) % N])

Submission status: Wrong Answer

Solution code:
import sys
def MI(): return map(int,sys.stdin.readline().rstrip().split())


N,L,T = MI()
A = []
for i in range(N):
    x,w = MI()
    if w == 1:
        for j in range(-1,2):
            A.append(x+T+j*L)
    else:
        for j in range(-1,2):
            A.append(x-T+j*L)
A.sort()
print(*[A[i] % L for i in range(N,2*N)],sep='\n')

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np

input = sys.stdin.readline
N, L, T = map(int, input().split())
T %= L
XW = [tuple(map(int, input().split())) for _ in range(N)]
X = np.array([x for x, w in XW], dtype=int)
W = np.array([(w%2)*2-1 for x, w in XW], dtype=int)
X += W*T
cnt = np.sum(X>=L) - np.sum(X<=0)
X %= L
cnt -= np.argmin(X)

print('\n'.join(map(str, X[cnt:])))
print('\n'.join(map(str, X[:cnt])))

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(4100000)
import math
import itertools
INF = float('inf')
from heapq import heapify, heappop, heappush

def main():
    n,l,t = map(int, input().split())
    X = []
    W = []
    for i in range(n):
        x,w = map(int, input().split())
        if w == 2:
            w = -1
        X.append(x)
        W.append(w)

    count = 0
    for i in range(1,n):
        if W[0]*W[i] == -1:
            if X[0] == 1:
                if (X[i] - X[0])/2 < t:
                    continue
                count += 1 + int((l-(X[i] - X[0])/2)/2)
            else:
                if (20-X[i]+X[0])/2 < t:
                    continue
                count += 1 + int(((l - (20-X[i]+X[0])/2)/2))
    count %= n
    Y = []
    for i in range(n):
        y = X[i] + W[i]*t
        Y.append(y%l)
    index = (count+1)%n
    answers =  Y[index:] + Y[:index]
    for ans in answers:
        print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

N, L, T = map(int, input().strip().split())
x = list()
w = list()
for _ in range(N):
    x_tmp, w_tmp = map(int, input().strip().split())
    x.append(x_tmp)
    w.append(w_tmp)

pre_x = list()
pre_w = list()
for _ in range(T):
    print('T={}, {}'.format(T, x))
    pre_x.clear()
    pre_w.clear()
    for value in x:
        pre_x.append(value)
    for value in w:
        pre_w.append(value)

    for i in range(N):
        if w[i] == 1:
            moved_xi = pre_x[i] + 1
            if moved_xi == L:
                moved_xi = 0
            two_moved_xi = moved_xi + 1
            if two_moved_xi == L:
                two_moved_xi = 0

            if moved_xi in pre_x:
                if pre_w[pre_x.index(moved_xi)] == 2:
                    moved_xi = pre_x[i]
                    w[i] = 2
            elif two_moved_xi in pre_x:
                if pre_w[pre_x.index(two_moved_xi)] == 2:
                    w[i] = 2

            x[i] = moved_xi
        else:
            moved_xi = pre_x[i] - 1
            if moved_xi == -1:
                moved_xi = L - 1
            two_moved_xi = moved_xi - 1
            if two_moved_xi == -1:
                two_moved_xi = L - 1

            if moved_xi in pre_x:
                if pre_w[pre_x.index(moved_xi)] == 1:
                    moved_xi = pre_x[i]
                    w[i] = 1
            elif two_moved_xi in pre_x:
                if pre_w[pre_x.index(two_moved_xi)] == 1:
                    w[i] = 1

            x[i] = moved_xi

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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
def new_place(ant, l, t):
    x = ant[0]
    w = ant[1]
    a = t%l
    if w == 1:
        new = x + a
        if new >= l:
            new -= l
    else:
        new = x - a
        if new < 0:
            new += l
    return new

def num_cross(ant1, ant2, l, t):
    if ant1[1] == ant2[1]:
        return 0
    if (ant2[0] - ant1[0])%2 == 0:
        if ant1[1] == 1:
            if t <= (ant2[0] - ant1[0])/2:
                return 0
            else:
                return 2*(t - 1 - (ant2[0] - ant1[0])/2)//l + 1
        else:
            if t - (ant1[0] + l -ant2[0])/2 <= 0:
                return 0
            else:
                return 2*(t - 1 - (ant1[0] + l -ant2[0])/2)//l + 1
    else:
        if ant1[1] == 1:
            if t <= (ant2[0] - ant1[0])/2:
                return 0
            else:
                return 2*(t - (ant2[0] - ant1[0])/2)//l + 1
        else:
            if t - (ant1[0] + l - ant2[0])/2 <= 0:
                return 0
            else:
                return 2*(t - (ant1[0] + l -ant2[0])/2)//l + 1
        
def main():
    N, L, T = map(int, input().split())
    ants = []
    for i in range(N):
        ants.append(list(map(int, input().split())))
    new = []
    output = []
    # answer  = []
    # for i in range(N):
    #     output.append(int(input()))
    for ant in ants:
        new.append(new_place(ant, L, T))
    # print(new)
    sum = 0
    for i in range(1, N):
        # print(int(num_cross(ants[0], ants[i], L, T)))
        sum += int(num_cross(ants[0], ants[i], L, T))
    if ants[0][1] == 1:
        ant_num = (1+sum)%N
    else:
        ant_num = N*(1+(-1)*(1-sum)//N) - (-1)*(1-sum)
    # print(ant_num)
    for i in range(ant_num, N):
        # answer.append(new[i])
        print(new[i])
    for i in range(ant_num):
        # answer.append(new[i])
        print(new[i])
    # if answer == output:
    #     print('OK')
    # else:
    #     print('No')
        # ran = range
        # for i in range(N):
        #     ii = i + L-ant_num
        #     if ii >= L:
        #         ii -= L
        #     print(ii)
        #     # print(new[ii])

    
if __name__ == '__main__':
    # for time in range(20):
    #     print('time: ' + str(time))
    #     # print(num_cross([1,1], [6,2], 8, time))
    main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
def new_place(ant, l, t):
    x = ant[0]
    w = ant[1]
    a = t%l
    if w == 1:
        new = x + a
        if new >= l:
            new -= l
    else:
        new = x - a
        if new < 0:
            new += l
    return new

def num_cross(ant1, ant2, l, t):
    if ant1[1] == ant2[1]:
        return 0
    else:
        if ant1[1] == 1:
            if t <= (ant2[0] - ant1[0])/2:
                return 0
            else:
                return(t - (ant2[0] - ant1[0])/2)//l + 1
        else:
            if t - (ant1[0] + l -ant2[0])/2 <= 0:
                return 0
            else:
                return(t - (ant1[0] + l -ant2[0])/2)//l + 1
def main():
    N, L, T = map(int, input().split())
    ants = []
    for i in range(N):
        ants.append(list(map(int, input().split())))
    new = []
    output = []
    # answer  = []
    # for i in range(N):
    #     output.append(int(input()))
    for ant in ants:
        new.append(new_place(ant, L, T))
    # print(new)
    sum = 0
    for i in range(1, N):
        # print(int(num_cross(ants[0], ants[i], L, T)))
        sum += int(num_cross(ants[0], ants[i], L, T))
    if ants[0][1] == 1:
        ant_num = (1+sum)%N
    else:
        ant_num = N*(1+(-1)*(1-sum)//N) - (-1)*(1-sum)
    # print(ant_num)
    for i in range(ant_num, N):
        # answer.append(new[i])
        print(new[i])
    for i in range(ant_num):
        # answer.append(new[i])
        print(new[i])
    # if answer == output:
    #     print('OK')
    # else:
    #     print('No')
        # ran = range
        # for i in range(N):
        #     ii = i + L-ant_num
        #     if ii >= L:
        #         ii -= L
        #     print(ii)
        #     # print(new[ii])

    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
def new_place(ant, l, t):
    x = ant[0]
    w = ant[1]
    a = t%l
    if w == 1:
        new = x + a
        if new >= l:
            new -= l
    else:
        new = x - a
        if new < 0:
            new += l
    return new

def num_cross(ant1, ant2, l, t):
    if ant1[1] == ant2[1]:
        return 0
    else:
        if ant1[1] == 1:
            if t <= (ant2[0] - ant1[0])/2:
                return 0
            else:
                return(t - (ant2[0] - ant1[0])/2)//l + 1
        else:
            if t - (ant1[0] + l -ant2[0])/2 <= 0:
                return 0
            else:
                return(t - (ant1[0] + l -ant2[0])/2)//l + 1
def main():
    N, L, T = map(int, input().split())
    ants = []
    for i in range(N):
        ants.append(list(map(int, input().split())))
    new = []
    output = []
    # answer  = []
    # for i in range(N):
    #     output.append(int(input()))
    for ant in ants:
        new.append(new_place(ant, L, T))
    print(new)
    sum = 0
    for i in range(1, N):
        # print(int(num_cross(ants[0], ants[i], L, T)))
        sum += int(num_cross(ants[0], ants[i], L, T))
    if ants[0][1] == 1:
        ant_num = (1+sum)%N
    else:
        ant_num = N*(1+(-1)*(1-sum)//N) - (-1)*(1-sum)
    print(ant_num)
    for i in range(ant_num, N):
        # answer.append(new[i])
        print(new[i])
    for i in range(ant_num):
        # answer.append(new[i])
        print(new[i])
    # if answer == output:
    #     print('OK')
    # else:
    #     print('No')
        # ran = range
        # for i in range(N):
        #     ii = i + L-ant_num
        #     if ii >= L:
        #         ii -= L
        #     print(ii)
        #     # print(new[ii])

    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
def new_place(ant, l, t):
    x = ant[0]
    w = ant[1]
    a = t%l
    if w == 1:
        new = x + a
        if new >= l:
            new -= l
    else:
        new = x - a
        if new < 0:
            new += l
    return new

def num_cross(ant1, ant2, l, t):
    if ant1[1] == ant2[1]:
        return 0
    else:
        if ant1[1] == 1:
            if t < (ant2[0] - ant1[0])/2:
                return 0
            else:
                return(t - (ant2[0] - ant1[0])/2)//l + 1
        else:
            if t - (ant1[0] + l -ant2[0])/2 < 0:
                return 0
            else:
                return(t - (ant1[0] + l -ant2[0])/2)//l + 1
def main():
    N, L, T = map(int, input().split())
    ants = []
    for i in range(N):
        ants.append(list(map(int, input().split())))
    new = []
    output = []
    # answer  = []
    # for i in range(N):
    #     output.append(int(input()))
    for ant in ants:
        new.append(new_place(ant, L, T))
    # print(new)
    sum = 0
    for i in range(1, N):
        # print(int(num_cross(ants[0], ants[i], L, T)))
        sum += int(num_cross(ants[0], ants[i], L, T))
    if ants[0][1] == 1:
        ant_num = (1+sum)%N
    else:
        ant_num = N*(1+(-1)*(1-sum)//N) - (-1)*(1-sum)
    # print(ant_num)
    for i in range(ant_num, N):
        # answer.append(new[i])
        print(new[i])
    for i in range(ant_num):
        # answer.append(new[i])
        print(new[i])
    # if answer == output:
    #     print('OK')
    # else:
    #     print('No')
        # ran = range
        # for i in range(N):
        #     ii = i + L-ant_num
        #     if ii >= L:
        #         ii -= L
        #     print(ii)
        #     # print(new[ii])

    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n, l, t = map(int, input().split())
xw = [list(map(int, input().split())) for _ in range(n)]
for i in range(n):
  if xw[i][1] == 1:
    xw[i][0] += t
  else:
    xw[i][0] -= t
  if xw[i][0] >= l:
    xw[i][0] = xw[i][0] - l*(xw[i][0]//l)
  if xw[i][0] < 0:
    xw[i][0] = xw[i][0] + l*(abs(xw[i][0]//l))
#print(xw)
print(xw[n-1][0])
for j in range(n-1):
  print(xw[j][0])

Submission status: Wrong Answer

Solution code:
import sys

input=sys.stdin.readline

N,L,T=map(int,input().split())
res=[]
start=[]
for _ in range(N):
    x,w=map(int,input().split())
    start.append((x,w%2))
    res.append(((x+T*(-1)**(w+1))%L,w%2))


res.sort()
id=0
pos=start[0][0]
for i in range(1,N):
    x,w=start[i]
    if w!=start[0][1]:
        id+=(2*T+pos-x)//L-((pos-x-1)//L)

if start[0][1]==1:
    exit()

#print(res,pos,id)
if start[0][1]==1:
    id%=N
    ans=[-1]*N
    check=-1
    for i in range(N):
        p,w=res[i]
        if p==(pos+T)%L and w==1:
            ans[i]=id
            check=i
            break
    #print(ans,check)
    for i in range(1,N):
        ans[check-i]=(id-i)%N
    res=[(ans[i],res[i][0]) for i in range(N)]
    #print(ans)
    #print(res)
    res.sort()
    for id,pos in res:
        print(pos)
else:
    id=(-id)%N
    ans=[-1]*N
    check=-1
    for i in range(N):
        p,w=res[i]
        if p==(pos-T)%L and w==0:
            ans[i]=id
            check=i
            break
    for i in range(1,N):
        ans[check-i]=(id-i)%N
    res=[(ans[i],res[i][0]) for i in range(N)]
    res.sort()
    for id,pos in res:
        print(pos)

Submission status: Wrong Answer

Solution code:
import sys

input=sys.stdin.readline

N,L,T=map(int,input().split())
res=[]
start=[]
for _ in range(N):
    x,w=map(int,input().split())
    start.append((x,w%2))
    res.append(((x+T*(-1)**(w+1))%L,w%2))


res.sort()
id=0
pos=start[0][0]
for i in range(1,N):
    x,w=start[i]
    if w!=start[0][1]:
        id+=(2*T+pos-x)//L-((pos-x-1)//L)

#print(res,pos,id)
if start[0][1]==1:
    id%=N
    ans=[-1]*N
    check=-1
    for i in range(N):
        p,w=res[i]
        if p==(pos+T)%L and w==1:
            ans[i]=id
            check=i
            break
    #print(ans,check)
    for i in range(1,N):
        ans[check-i]=(id-i)%N
    res=[(ans[i],res[i][0]) for i in range(N)]
    #print(ans)
    #print(res)
    res.sort()
    for id,pos in res:
        print(pos)
else:
    id=(-id)%N
    ans=[-1]*N
    check=-1
    for i in range(N):
        p,w=res[i]
        if p==(pos-T)%L and w==0:
            ans[i]=id
            check=i
            break
    for i in range(1,N):
        ans[check-i]=(id-i)%N
    res=[(ans[i],res[i][0]) for i in range(N)]
    res.sort()
    for id,pos in res:
        print(pos)

Submission status: Wrong Answer

Solution code:
import bisect
n, l, t = map(int, input().split())
#t %= l

plots = []
plots_after = []
for i in range(n):
    x, w = map(int, input().split())
    plots.append((x, w, i))
    if w == 1:
        plots_after.append((x+t) % l)
    else:
        plots_after.append((x-t) % l)
    
x0, w0, _ = plots[0]

if w0 == 1:
    cnt = 0
    for i in range(1, n):
        xi, wi, _ = plots[i]
        if wi == 2 and (xi - x0) <= 2 * t:
            cnt += 1
    cnt %= n

    plots_after.sort()

    x_after = (x0 + t) % l
    idx = bisect.bisect_left(plots_after, x_after)

    for i in range(n):
        print(plots_after[(i-cnt+idx) % n])

else:
    cnt = 0
    for i in range(1, n):
        xi, wi, _ = plots[i]
        if wi == 1 and l - (xi - x0) < 2 * t:
            cnt -= 1
    cnt %= n
    plots_after.sort()

    x_after = (x0 - t) % l
    idx = bisect.bisect_right(plots_after, x_after) - 1

    for i in range(n):
        print(plots_after[(i-cnt+idx) % n])

Submission status: Wrong Answer

Solution code:
import bisect
n, l, t = map(int, input().split())
t %= l

plots = []
plots_after = []
for i in range(n):
    x, w = map(int, input().split())
    plots.append((x, w, i))
    if w == 1:
        plots_after.append((x+t) % l)
    else:
        plots_after.append((x-t) % l)
    
x0, w0, _ = plots[0]

if w0 == 1:
    cnt = 0
    for i in range(1, n):
        xi, wi, _ = plots[i]
        if wi == 2 and (xi - x0) <= 2 * t:
            cnt += 1

    plots_after.sort()

    x_after = (x0 + t) % l
    idx = bisect.bisect_left(plots_after, x_after)

    for i in range(n):
        print(plots_after[(i-cnt+idx) % n])

else:
    cnt = 0
    for i in range(1, n):
        xi, wi, _ = plots[i]
        if wi == 1 and l - (xi - x0) < 2 * t:
            cnt -= 1
    cnt %= n
    plots_after.sort()

    x_after = (x0 - t) % l
    idx = bisect.bisect_right(plots_after, x_after) - 1

    for i in range(n):
        print(plots_after[(i-cnt+idx) % n])

Submission status: Wrong Answer

Solution code:
n, l, t = map(int, input().split())
t %= l

plots = []
plots_after = []
for i in range(n):
    x, w = map(int, input().split())
    plots.append((x, w, i))
    if w == 1:
        plots_after.append((x+t) % l)
    else:
        plots_after.append((x-t) % l)
    
x0, w0, _ = plots[0]

if w0 == 1:
    cnt = 0
    for i in range(1, n):
        xi, wi, _ = plots[i]
        if wi == 2 and (xi - x0) <= 2 * t:
            cnt += 1

    plots_after.sort()

    x_after = (x0 + t) % l
    idx = plots_after.index(x_after)

    for i in range(n):
        print(plots_after[(i-cnt+idx) % n])

else:
    cnt = 0
    for i in range(1, n):
        xi, wi, _ = plots[i]
        if wi == 1 and l - (xi - x0) <= 2 * t:
            cnt -= 1
    cnt %= n
    plots_after.sort()

    x_after = (x0 - t) % l
    idx = plots_after.index(x_after)

    for i in range(n):
        print(plots_after[(i-cnt+idx) % n])