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:
import os
import sys

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

N, L, T = list(map(int, sys.stdin.readline().split()))
X, W = list(zip(*[map(int, sys.stdin.readline().split()) for _ in range(N)]))

X = np.array(X)
W = np.array(W)

w1 = W == 1
X1 = X[w1]
X2 = X[~w1]
# W1[0] の本来のインデックス
x1_i = np.argmax(w1)

positions = np.concatenate([(X1 + T) % L, (X2 - T) % L])
positions.sort()

if len(X1) > 0 and len(X2) > 0:
    # MOD L で X1[0] がすり抜ける時間
    collisions = np.concatenate([(X2 - X1[0]) % L / 2, (X2 - X1[0]) % L / 2 + L / 2])
    # T 秒間にすり抜ける回数
    collision_count = T // L * 2 + np.searchsorted(collisions, T % L)

    # (X1[0] + T) % L にいるのが (x1_i + collision_count) % N ばんめのあり
    idx = np.searchsorted(positions, (X1[0] + T) % L)
    ans = np.roll(positions, (x1_i + collision_count) % N - idx)
elif W[0] == 1:
    ans = (X + T) % L
elif W[0] == 2:
    ans = (X - T) % L
else:
    assert False
print('\n'.join(map(str, ans)))

Submission status: Wrong Answer

Solution code:
N, L, T = map(int, input().split())
XW = [list(map(int, input().split())) for _ in range(N)]

positions = []
for x, w in XW:
	if 1 == w:
		positions += [(x + T % L) % L]
	else:
		positions += [(x + L - T % L) % L]

d, l, r, offset = XW[0][1], XW[0][0], positions[0], 1
for i, (x, w) in enumerate(XW):
	if d == w:
		continue
	if l <= positions[i] <= r:
		offset += 1

#print(positions)
for position in positions[offset:] + positions[:offset]:
	print(position)

Submission status: Wrong Answer

Solution code:
N, L, T = map(int, input().split())
XW = [list(map(int, input().split())) for _ in range(N)]

positions = []
for x, w in XW:
	if 1 == w:
		positions += [(x + T % L) % L]
	else:
		positions += [(x + L - T % L) % L]

for position in positions[-1:] + positions[:-1]:
	print(position)

Submission status: Wrong Answer

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 i < n-1:
				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: Wrong Answer

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:
			true_zero = (i+num) % n

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

Submission status: Wrong Answer

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][0] == 1:
			true_zero = (i-num) % n
		else:
			true_zero = (i+num) % n

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

Submission status: Wrong Answer

Solution code:
from math import floor
n,l,t=map(int,input().split())
li=[]
zero=0
for _ in range(n):
  x,w=map(int,input().split())
  #zero passing
  if w==1:
    zero+=(x+t)//l
    x1=(x+t)%l
  else:
    zero+=(x-t)//l
    x1=(x-t)%l
  li.append(x1)

li.sort()
li=li[zero:]+li[:zero]
for _ in range(n):
  print(li[_])

Submission status: Wrong Answer

Solution code:
from math import floor
n,l,t=map(int,input().split())
li=[]
s=0
first=1
xmin=l
xminind=0
for _ in range(n):
  x,w=map(int,input().split())
  if first==1:
    xf=x
    wf=w
    first=0
  if w==1:
    x1=(x+t)%l
  else:
    x1=(x-t)%l
  if x1<xmin:
    xmin=x1
    xminind=_
  if wf!=w:
    tf=(x-xf)/2
    if t>tf:
      s+=1
      s+=floor((t-tf)/(l/2))
  li.append(x1)

li.sort()
for _ in range(n):
  print(li[(_+s+xminind)%n])

Submission status: Wrong Answer

Solution code:
from math import floor
n,l,t=map(int,input().split())
li=[]
s=0
first=1
xmin=l
xminind=0
for _ in range(n):
  x,w=map(int,input().split())
  if first==1:
    xf=x
    wf=w
    first=0
  if w==1:
    x1=(x+t)%l
  else:
    x1=(x-t)%l
  if x1<xmin:
    xmin=x1
    xminind=_
  if wf!=w:
    tf=(x-xf)/2
    if t>tf:
      s+=1
      s+=floor((t-tf)/(l/2))
  li.append(x1)

li.sort()
for _ in range(n):
  print(li[(_+xminind)%n])

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
INF = float("inf")


def solve(N: int, L: int, T: int, X: "List[int]", W: "List[int]"):

    # 蟻の最終位置
    last_X = [0]*N
    for i in range(N):
        last_X[i] = (X[i]+T) % L if W[i] == 1 else (X[i]-T) % L

    # print(last_X)

    # 蟻0の他の蟻とすれ違う回数
    switch_counter = 0
    for i in range(1, N):
        if W[i] == W[0]:
            continue
        if W[0] == 1:
            if 2*T < ((X[i]-X[0]) % L):
                switch_counter += 0
            else:
                switch_counter += 1+int((2*T - ((X[i]-X[0]) % L))/L)
        elif W[0] == 2:
            if 2*T < ((X[0]-X[i]) % L):
                switch_counter += 0
            else:
                switch_counter += 1+int((2*T - ((X[0]-X[i]) % L))/L)
    # 蟻0の最終のゼッケン番号は
    if W[0] == 1:
        zekken = switch_counter
    else:
        zekken = (-switch_counter) % N
    for i in range(N):
        print(last_X[(N-zekken+i) % N])
    return


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:
n,l,t=list(map(int,input().split()))
L=[]
for i in range(n):
    L.append(list(map(int,input().split())))
a=0
for i in range(1,n):
    if L[0][1]==1 and L[i][1]==2:
        a+=max(int((t-abs(L[0][0]-L[i][0])/2)/(l/2))+1,0)
    elif L[0][1]==2 and L[i][1]==1:
        a+=max(int((t-(l-abs(L[0][0]-L[i][0]))/2)/(l/2))+1,0)
if L[0][1]==1 :
    b=a%n
else:
    b=-a%n
Q=[]
for i in range(n):
    Q.append(((L[i][0]+t*(3-L[i][1]*2))%l))
Q.sort()
d=Q.index(((L[0][0]+t*(3-L[0][1]*2))%l))
for i in range(n):
    if i-(-d+b)>=0 and i-(-d+b)<n:
        print(Q[i-(-d+b)])
    elif i-(-d+b)>=n:
        print(Q[i-(-d+b)-n])
    else:
        print(Q[i-(-d+b)+n])

Submission status: Wrong Answer

Solution code:
n,l,t=list(map(int,input().split()))
L=[]
for i in range(n):
    L.append(list(map(int,input().split())))
a=0
for i in range(1,n):
    if L[0][1]==1 and L[i][1]==2:
        a+=max(int((t-abs(L[0][0]-L[i][0])/2)/(l/2))+1,0)
    elif L[0][1]==2 and L[i][1]==1:
        a+=max(int((t-(l-abs(L[0][0]-L[i][0]))/2)/(l/2))+1,0)
    print(a)
if L[0][1]==1 :
    b=a%n
else:
    b=-a%n
Q=[]
for i in range(n):
    Q.append(((L[i][0]+t*(3-L[i][1]*2))%l))
Q.sort()
d=Q.index(((L[0][0]+t*(3-L[0][1]*2))%l))
W=[]
for i in range (n):
    if i+(-d+b)>=0 and i+(-d+b)<n:
        W.append(i+(-d+b))
    elif i+(-d+b)>=n:
        W.append(i+(-d+b)-n)
    else:
        W.append(i+(-d+b)+n)
for i in range(n):
    print(Q[W.index(i)])

Submission status: Wrong Answer

Solution code:
n,l,t=list(map(int,input().split()))
L=[]
for i in range(n):
    L.append(list(map(int,input().split())))
a=0
for i in range(1,n):
    if L[0][1]==1 and L[i][1]==2:
        a+=max(int((t-abs(L[0][0]-L[i][0])/2)/(l/2))+1,0)
    elif L[0][1]==2 and L[i][1]==1:
        a+=max(int((t-(l-abs(L[0][0]-L[i][0])/2))/(l/2))+1,0)
if L[0][1]==1 :
    c=(1+a)%n
else:
    c=(1-a)%n
if c==0:
    b=n
else:
    b=c
Q=[]
for i in range(n):
    Q.append(((L[i][0]+t*(3-L[i][1]*2))%l))
Q.sort()
d=Q.index(((L[0][0]+t*(3-L[0][1]*2))%l))
W=[]
for i in range (n):
    if i+(-d+b)-1>=0 and i+(-d+b)-1<n:
        W.append(i+(-d+b)-1)
    elif i+(-d+b)-1>=n:
        W.append(i+(-d+b)-n-1)
    else:
        W.append(i+(-d+b)+n-1)

for i in range(n):
    print(Q[W.index(i)])

Submission status: Wrong Answer

Solution code:
n,l,t=list(map(int,input().split()))
L=[]
for i in range(n):
    L.append(list(map(int,input().split())))
a=0
for i in range(1,n):
    if L[0][1]==1 and L[i][1]==2:
        a+=max(int((t-abs(L[0][0]-L[i][0])/2)/(l/2))+1,0)
    elif L[0][1]==2 and L[i][1]==1:
        a+=max(int((t-(l-abs(L[0][0]-L[i][0])/2))/(l/2))+1,0)
if (1+a)%n==0:
    b=n
else:
    b=(1+a)%n
Q=[]
for i in range(n):
    Q.append(((L[i][0]+t*(3-L[i][1]*2))%l))
Q.sort()
d=Q.index(((L[0][0]+t*(3-L[0][1]*2))%l))
W=[]
for i in range (n):
    if i+(-d+b)>=0 and i+(-d+b)<n:
        W.append(i+(-d+b))
    elif i+(-d+b)>=n:
        W.append(i+(-d+b)-n)
    else:
        W.append(i+(-d+b)+n)
for i in W:
    print(Q[i])

Submission status: Wrong Answer

Solution code:
n,l,t=list(map(int,input().split()))
L=[]
for i in range(n):
    L.append(list(map(int,input().split())))
a=0
for i in range(1,n):
    if L[0][1]==1 and L[i][1]==2:
        a+=max(int((t-abs(L[0][0]-L[i][0])/2)/(l/2))+1,0)
    elif L[0][1]==2 and L[i][1]==1:
        a+=max(int((t-(l-abs(L[0][0]-L[i][0])/2))/(l/2))+1,0)
if (1+a)%n==0:
    b=n
else:
    b=(1+a)%n
Q=[]
for i in range(n):
    Q.append(((L[i][0]+t*(3-L[i][1]*2))//n))
Q.sort()
d=Q.index(((L[0][0]+t*(3-L[0][1]*2))//n))
W=[]
for i in range (n):
    if i+(-d+b)>=0 and i+(-d+b)<n:
        W.append(i+(-d+b))
    elif i+(-d+b)>=n:
        W.append(i+(-d+b)-n)
    else:
        W.append(i+(-d+b)+n)
for i in W:
    print(Q[i])

Submission status: Wrong Answer

Solution code:
n,l,t=list(map(int,input().split()))
L=[]
for i in range(n):
    L.append(list(map(int,input().split())))
a=0
for i in range(1,n):
    if L[0][1]==1 and L[i][1]==2:
        a+=max(int((t-abs(L[0][0]-L[i][0])/2)/(l/2))+1,0)
    elif L[0][1]==2 and L[i][1]==1:
        a+=max(int((t-(l-abs(L[0][0]-L[i][0])/2))/(l/2))+1,0)
Q=[]
for i in range(n):
    Q.append(((L[i][0]+t*(3-L[i][1]*2))//n))
Q.sort()
b=Q.index(((L[0][0]+t*(3-L[0][1]*2))//n))
W=[i for i in range(b,n)]+[i for i in range(0,b)]
for i in W:
    print(Q[i])

Submission status: Wrong Answer

Solution code:
N,L,T=map(int,input().split())
X=[0 for i in range(N)]
W=[0 for i in range(N)]
for i in range(N):
    X[i],W[i]=map(int,input().split())
    W[i]=-2*W[i]+3
Y0=((T*W[0])+X[0])%L
Y=sorted([((T*W[i])+X[i])%L for i in range(N)])
R=[0 for i in range(N)]
Z=0
for i in range(1,N):
    if W[i]==W[0]:
        R[i]=0
    else:
        if T*2<abs(X[i]-X[0]):
            R[i]=0
        else:
            R[i]=1+(T*2-abs(X[i]-X[0]))//L
    Z+=W[0]*R[i]
Z%=N
Q=[]
A=0
for i in range(Z,N):
    if Y[i]==Y0:
        A=i
        break
B=(A-Z)%N
for i in range(B,N):
    Q.append(Y[i])
for i in range(B):
    Q.append(Y[i])
for i in range(N):
    print(Q[i])

Submission status: Wrong Answer

Solution code:
N,L,T=map(int,input().split())
X=[0 for i in range(N)]
W=[0 for i in range(N)]
for i in range(N):
    X[i],W[i]=map(int,input().split())
    W[i]=-2*W[i]+3
Y0=((T*W[0])+X[0])%L
Y=sorted([((T*W[i])+X[i])%L for i in range(N)])
R=[0 for i in range(N)]
Z=0
for i in range(1,N):
    if W[i]==W[0]:
        R[i]=0
    else:
        if T*2<abs(X[i]-X[0]):
            R[i]=0
        else:
            R[i]=1+(T*2-abs(X[i]-X[0]))//L
    Z+=W[0]*R[i]
Z%=N
Q=[]
A=0
for i in range(Z,N):
    if Y[i]==Y0:
        A=i
        break
for i in range(A,N):
    Q.append(Y[i])
for i in range(A):
    Q.append(Y[i])
for i in range(N):
    print(Q[i])

Submission status: Wrong Answer

Solution code:
N,L,T=map(int,input().split())
X=[0 for i in range(N)]
W=[0 for i in range(N)]
for i in range(N):
    X[i],W[i]=map(int,input().split())
    W[i]=-2*W[i]+3
Y=sorted([((T*W[i])+X[i])%L for i in range(N)])
R=[0 for i in range(N)]
Z=0
for i in range(1,N):
    if W[i]==W[0]:
        R[i]=0
    else:
        if T*2<abs(X[i]-X[0]):
            R[i]=0
        else:
            R[i]=1+(T*2-abs(X[i]-X[0]))//L
    Z+=W[0]*R[i]
Z%=N
Q=[]
for i in range(Z,N):
    Q.append(Y[i])
for i in range(Z):
    Q.append(Y[i])
for i in range(N):
    print(Q[i])

Submission status: Wrong Answer

Solution code:
#1-6-2 #AGC013C 
n,l,t=map(int,input().split())
data=[]
for i in range(n):
    data.append(list(map(int,input().split())))

def simyu(data,now):
    bump=t-now
    nihiki=[]
    for i in range(n):
        if data[i][1]==1 and data[(i+1)%n][1]==2:
            butukaru=(data[(i+1)%n][0]-data[i][0])%l/2
            if butukaru<bump:
                bump=butukaru
                nihiki=[i,(i+1)%n]
            if butukaru==bump:
                nihiki.append(i)
                nihiki.append((i+1)%n)
    return bump,nihiki

def susumu(data,now,bump,nihiki):
    for i in range(n):
        if data[i][1]==1:
            data[i][0]=(data[i][0]+bump)%l
            if i in nihiki:data[i][1]=2
        elif data[i][1]==2:
            data[i][0]=(data[i][0]-bump)%l
            if i in nihiki:data[i][1]=1
    now+=bump
    return data,now

now=0
while now<t:
    bump,nihiki=simyu(data,now)
    data,now=susumu(data,now,bump,nihiki)
    
for i in range(n):
    print(data[i][0])

Submission status: Wrong Answer

Solution code:
#1-6-2 #AGC013C 
n,l,t=map(int,input().split())
data=[]
for i in range(n):
    data.append(list(map(int,input().split())))

def simyu(data,now):
    bump=t-now
    nihiki=[]
    for i in range(n):
        if data[i][1]==1 and data[(i+1)%n][1]==2:
            butukaru=(data[(i+1)%n][0]-data[i][0])%l/2
            if butukaru<bump:
                bump=butukaru
                nihiki=[i,(i+1)%n]
    return bump,nihiki

def susumu(data,now,bump,nihiki):
    for i in range(n):
        if data[i][1]==1:
            data[i][0]=(data[i][0]+bump)%l
            if i in nihiki:data[i][1]=2
        elif data[i][1]==2:
            data[i][0]=(data[i][0]-bump)%l
            if i in nihiki:data[i][1]=1
    now+=bump
    return data,now

now=0
while now<t:
    bump,nihiki=simyu(data,now)
    data,now=susumu(data,now,bump,nihiki)
    
for i in range(n):
    print(data[i][0])

Submission status: Wrong Answer

Solution code:
iipt=lambda:int(input())
miipt=lambda: list(map(int, input().split()))

n,l,t=miipt()
a=[miipt() for i in range(n)]
x0,w0=a[0]
d=0
for x,w in a:
    if w0!=w:
        d+=(2*t-((x-x0) if w==1 else (l-x+x0))+l)//l
d=d%n
d=d if w0==1 else n-d
e=[(x+(t if w==1 else -t))%l for x, w in a]

x0_=(x0+(t if w0==1 else -t))%l
e.sort()
d_=e.index(x0_) # d番はd_にいる

#print(d,d_,e)
for i in range(n):
    print(e[(d_-d+i)%n])

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
 
N, L, T = map(int, input().split())
 
ants = []
for i in range(N):
    x, w = map(int, input().split())
    ants.append((x, w))
 
# After T
ants2 = []
for ant in ants:
    ants2.append((ant[0] + T * (3 - 2 * ant[1])) % L)
 
st = 0
for i in range(N):
    if ants2.count(ants2[i]) == 1:
        break
    st += 1
 
# Number of collision for Ants[st]
cl = 0
for i in range(N):
    if ants[i][1] == ants[st][1]:
        continue  # same direction
    else:
        if ants[st][1] == 1:
            if ants[i][0] > ants[st][0]:
                fc = (ants[i][0] - ants[st][0]) / 2
            else:
                fc = ((L - ants[st][0]) + ants[i][0]) / 2
            cl += int(2 * (T - fc) / L) + 1
        else:
            if ants[i][0] > ants[st][0]:
                fc = ((L - ants[i][0]) + ants[st][0]) / 2
            else:
                fc = (ants[st][0] - ants[i][0]) / 2
            cl -= int(2 * (T - fc) / L) + 1
 
stant = ants2[st]
ants2.sort()
idx = ants2.index(stant) - int(cl) - st
 
for i in range(N):
    print(ants2[(i + idx) % N])

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

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

ants = []
for i in range(N):
    x, w = map(int, input().split())
    ants.append((x, w))

# After T
ants2 = []
for ant in ants:
    if ant[1] == 1:
        ants2.append((ant[0] + T) % L)
    else:
        ants2.append((ant[0] - T) % L)
st = 0
for i in range(N):
    if ants2.count(ants2[i]) == 1:
        break
    st += 1

# Number of collision for Ants[0]
cl = st
for i in range(N):
    if ants[i][1] == ants[st][1]:
        continue  # same direction
    else:
        if ants[st][1] == 1:
            if ants[i][0] > ants[st][0]:
                fc = (ants[i][0] - ants[st][0]) / 2
            else:
                fc = ((L - ants[st][0]) + ants[i][0]) / 2
            cl += int(2 * (T - fc) / L) + 1
        else:
            if ants[i][0] > ants[st][0]:
                fc = ((L - ants[i][0]) + ants[st][0]) / 2
            else:
                fc = (ants[st][0] - ants[i][0]) / 2
            cl -= int(2 * (T - fc) / L) + 1

stant = ants2[st]
ants2.sort()
idx = ants2.index(stant) - cl

for i in range(N):
    print(ants2[(i + idx) % N])

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

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

ants = []
for i in range(N):
    x, w = map(int, input().split())
    ants.append((x, w))

# After T
ants2 = []
for ant in ants:
    if ant[1] == 1:
        ants2.append((ant[0] + T) % L)
    else:
        ants2.append((ant[0] - T) % L)

# Number of collision for Ants[0]
cl = 0
for i in range(1, N):
    if ants[i][1] == ants[0][1]:
        continue  # same direction
    else:
        if ants[0][1] == 1:
            fc = (ants[i][0] - ants[0][0]) / 2
            cl += int(2 * (T - fc) / L) + 1
        else:
            fc = ((L - ants[i][0]) + ants[0][0]) / 2
            cl -= int(2 * (T - fc) / L) + 1

ant1 = ants2[0]
ants2.sort()
idx = ants2.index(ant1) - cl

for i in range(N):
    print(ants2[(i + idx) % N])

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

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

ants = []
for i in range(N):
    x, w = map(int, input().split())
    ants.append((x, w))

# After T
ants2 = []
for ant in ants:
    if ant[1] == 1:
        ants2.append((ant[0] + T) % L)
    else:
        ants2.append((ant[0] - T) % L)

# Number of collision for Ants[0]
cl = 0
for i in range(1, N):
    if ants[i][1] == ants[0][1]:
        continue  # same direction
    else:
        fc = (ants[i][0] - ants[0][0]) / 2
        if ants[0][1] == 1:
            cl += int(2 * (T - fc) / L) + 1
        else:
            cl -= int(2 * (T - fc) / L) + 1

ant1 = ants2[0]
ants2.sort()
idx = ants2.index(ant1) - cl
for i in range(N):
    print(ants2[(i + idx) % N])

Submission status: Wrong Answer

Solution code:
iipt=lambda:int(input())
miipt=lambda: list(map(int, input().split()))

n,l,t=miipt()
a=[miipt() for i in range(n)]
x0,w0=a[0]
d=0
for x,w in a[1:]:
    if w0!=w:
        d+=(2*t-((x-x0) if w==1 else (l-x+x0))+l)//l
d=int(d)%n
d=d if w0==1 else n-d
e=[(x+(t if w==1 else -t))%l for x, w in a]

x0_=(x0+(t if w0==1 else -t))%l
e.sort()
d_=n-1 - list(reversed(e)).index(x0_) if w0==1 else e.index(x0_) # d番はd_にいる

#print(d,d_,e)
for i in range(n):
    print(e[(d_-d+i)%n])

Submission status: Wrong Answer

Solution code:
iipt=lambda:int(input())
miipt=lambda: list(map(int, input().split()))

n,l,t=miipt()
a=[miipt() for i in range(n)]
x0,w0=a[0]
d=0
for x,w in a[1:]:
    if w0!=w:
        d+=(2*t-((x-x0) if w==1 else (l-x+x0))+l)//l
d=int(d)%n
d=d if w0==1 else n-d
e=[(x+(t if w==1 else -t))%l for x, w in a]

x0_=(x0+(t if w0==1 else -t))%l
e.sort()
d_=e.index(x0_) # d番はd_にいる
if d_+1<n and e[d_+1]==x0_ and w0==1:
    d_+=1
#print(d,d_,e)
for i in range(n):
    print(e[(d_-d+i)%n])

Submission status: Wrong Answer

Solution code:
iipt=lambda:int(input())
miipt=lambda: list(map(int, input().split()))

n,l,t=miipt()
a=[miipt() for i in range(n)]
x0,w0=a[0]
d=0
for x,w in a[1:]:
    if w0!=w:
        d+=(2*t-((x-x0) if w==1 else (l-x+x0))+l)//l
d=int(d)
d=d if w0==1 else n-d
e=[(x+(t if w==1 else -t))%l for x, w in a]

x0_=(x0+(t if w0==1 else -t))%l
e.sort()
d_=e.index(x0_) # d番はd_にいる
if d_+1<n and e[d_+1]==x0_ and w0==1:
    d_+=1
#print(d,d_,e)
for i in range(n):
    print(e[(d_-d+i)%n])

Submission status: Wrong Answer

Solution code:
iipt=lambda:int(input())
miipt=lambda: list(map(int, input().split()))

n,l,t=miipt()
a=[miipt() for i in range(n)]
x0,w0=a[0]
d=0
for x,w in a[1:]:
    if w0!=w:
        d+=(2*t-((x-x0) if w==1 else (l-x+x0))+l)//l
d=int(d)
d=d if w0==1 else n-d
e=[(x+(t if w==1 else -t))%l for x, w in a]

x0_=(x0+(t if w0==1 else -t))%l
e.sort()
d_=e.index(x0_) # d番はd_にいる
#print(d,d_,e)
for i in range(n):
    print(e[(d_-d+i)%n])

Submission status: Wrong Answer

Solution code:
iipt=lambda:int(input())
miipt=lambda: list(map(int, input().split()))

n,l,t=miipt()
a=[miipt() for i in range(n)]
x0,w0=a[0]
d=0
for x,w in a[1:]:
    if w0!=w:
        d+=(t-((x-x0) if w==1 else (l-x+x0))/2+l/2)//(l/2)
d=int(d)
d=d if w0==1 else n-d
e=[(x+(t if w==1 else -t))%l for x, w in a]

x0_=(x0+(t if w0==1 else -t))%l
e.sort()
d_=e.index(x0_) # d番はd_にいる
#print(d,d_,e)
for i in range(n):
    print(e[(d_-d+i)%n])

Submission status: Wrong Answer

Solution code:
iipt=lambda:int(input())
miipt=lambda: list(map(int, input().split()))

n,l,t=miipt()
a=[miipt() for i in range(n)]
x0,w0=a[0]
d=0
for x,w in a[1:]:
    if w0!=w:
        d+=(t-((x-x0) if w==1 else (l-x+x0))/2+l/2)//(l/2)
d=int(d)

e=[(x+(t if w==1 else -t))%l for x, w in a]

w_=a[(n-(d if w0==1 else -d))%n][1]
x_=e[(n-(d if w0==1 else -d))%n]
e.sort()
d_=e.index(x_) 

for i in range(n):
    print(e[(d_+i)%n])

Submission status: Wrong Answer

Solution code:
iipt=lambda:int(input())
miipt=lambda: list(map(int, input().split()))

n,l,t=miipt()
a=[miipt() for i in range(n)]
x0,w0=a[0]
d=0
for x,w in a[1:]:
    if w0!=w:
        d+=(t-((x-x0) if w==1 else (l-x+x0))/2+l/2)//(l/2)
d=int(d)

for i in range(n):
    j = (n+i-(d if w0==1 else -d))%n
    x, w = a[j]
    print((x+(t if w==1 else -t))%l)

Submission status: Wrong Answer

Solution code:
N,L,T=map(int,input().split())
X=[0 for i in range(N)]
W=[0 for i in range(N)]
for i in range(N):
    X[i],W[i]=map(int,input().split())
    W[i]=-2*W[i]+3
Y=sorted([((T*W[i])+X[i])%L for i in range(N)])
R=[0 for i in range(N)]
Z=0
for i in range(1,N):
    if W[i]==W[0]:
        R[i]=0
    else:
        R[i]=(((X[i]-X[0])*W[i])%L+2*T)//L
    Z+=W[0]*R[i]
Z%=N
Q=[]
for i in range(Z,N):
    Q.append(Y[i])
for i in range(Z):
    Q.append(Y[i])
for i in range(N):
    print(Q[i])

Submission status: Wrong Answer

Solution code:
N,L,T=map(int,input().split())
X=[0 for i in range(N)]
W=[0 for i in range(N)]
for i in range(N):
    X[i],W[i]=map(int,input().split())
    W[i]=-2*W[i]+3
Y=sorted([((T*W[i])+X[i])%L for i in range(N)])
R=[0 for i in range(N)]
Z=0
for i in range(1,N):
    if W[i]==W[0]:
        R[i]=0
    else:
        R[i]=((X[i]-X[0])+2*T)//L
    Z+=W[0]*R[i]
Z%=N
Q=[]
for i in range(Z,N):
    Q.append(Y[i])
for i in range(Z):
    Q.append(Y[i])
for i in range(N):
    print(Q[i])

Submission status: Wrong Answer

Solution code:
#import sys
#input = sys.stdin.readline
#template input
import bisect

def IT(): #整数1個
    return int(input())
def IL(): #整数複数
    return [int(_) for _ in input().split()]
def IS(): #文字列複数
    return [_ for _ in input().split()]
def ILS(n): #整数1つ　縦にズラーってなってるやつ
    return [int(input()) for _ in range(n)]
def SLS(n): #文字列　縦にズラーってなってるやつ
    return [input() for _ in range(n)]
def ILSS(n): #整数複数　縦にズラーってなってるやつ
    return [[int(_) for _ in input().split()] for j in range(n)]

#template technique
def bit_full_search(ss):
    n = len(ss)
    for i in range(1 << n):
        s = ""
        for j in range(n + 1):
            if ((1 & i >> j) == 1):
                s += ss[j]
        print(s)

def bit_full_search2(A):
    #https://blog.rossywhite.com/2018/08/06/bit-search/
    value = []
    for i in range(1 << len(A)):
        output = []

        for j in range(len(A)):
            if ((i >> j) & 1) == 1:
                #output.append(A[j])
                output.append(A[j])
        value.append([format(i, 'b').zfill(16), sum(output)])

    value.sort(key=lambda x:x[1])
    bin = [value[k][0] for k in range(len(value))]
    val = [value[k][1] for k in range(len(value))]
    return bin, val

def matching_bisect(list1_val, list2_val, n):
    #2分探索
    j = 0
    for i in range(len(list1_val)):
        j = bisect.bisect_left(list2_val, n - list1_val[i])
        if j < len(list2_val):
            if list1_val[i] + list2_val[j] == n:
                #ans = list2_bin[j] + list1_bin[i]
                break
    return j

"""ここからメインコード"""
def main():
    n, l, t = IL()
    xw = ILSS(n)

    first_ant_number = 1
    first_ant_direction = xw[0][1]
    if first_ant_direction == 1:
        first_ant_position = (xw[0][0] + t) % l
    else:
        first_ant_position = (xw[0][0] - t) % l

    for i in range(n):
        if xw[i][1] == 1:
            first_ant_number = i + 1
            first_ant_position = (xw[i][0] + t) % l
            first_ant_direction = xw[i][1]
            break

    for i in range(n):
        if first_ant_direction != xw[i][1]:
            if t < ((xw[i][0] - first_ant_position) % l )/ 2:
                hit_count = 0
            else:
                dt =((xw[i][0] - first_ant_position) % l )/ 2
                hit_count = int ( 1 +2 * ( t - dt) // l)
            first_ant_number = (first_ant_number + hit_count) % n
            if first_ant_number == 0:
                first_ant_number = n

    ant_position = []
    for i in range(n):
        if xw[i][1] == 1:
            pos = (xw[i][0] + t) % l
        else:
            pos = (xw[i][0] - t) % l
        ant_position.append(pos)
    ant_position.sort()

    ans = [0 for i in range(n)]
    for i in range(n):
        if first_ant_position == ant_position[n-i-1]:
            start = n - i - 1
            break
    for i in range(n):
        ans[(first_ant_number - 1 + i) % n] = ant_position[(start + i) % n]

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

main()

Submission status: Wrong Answer

Solution code:
N, L, T = [int(_) for _ in input().split()]
Ants = [[int(_) for _ in input().split()] for i in range(N)]

x0, w0 = Ants[0]

zekken = 0
for x, w in Ants[1:]:
    if w == w0:
        continue

    if w0 == 1:
        dist = x - x0
        zekken += (2 * T - dist) // L + 1
        zekken %= N
    else:
        dist = L + x0 - x
        zekken -= (2 * T - dist) // L + 1
        zekken %= N


final_ants = [0] * N
for i, (x, w) in enumerate(Ants):
    if w == 1:
        final_ants[i] = (x + T) % L
    else:
        final_ants[i] = (x - T) % L

first_ant_pos = final_ants[0]

final_ants.sort()
for i in range(N):
    if final_ants[i] == first_ant_pos:
        start_idx = i - zekken
        break

for i in range(N):
    print(final_ants[(i + start_idx) % N])

Submission status: Wrong Answer

Solution code:
N, L, T = map(int, input().split())
x = ["" for i in range(N)]
w = ["" for i in range(N)]
for i in range(N):
    x[i], w[i] = map(int, input().split())

y = [[i, ""] for i in range(N)]
for i in range(N):
    y[i][1] = (x[i] + (-1)**(w[i]+1)*T) % L

count = 0
for i in range(N):
    if w[0] < w[i]:
        count += (2 * T + L - x[i] + x[0]) // L
    elif w[0] > w[i]:
        count += (2 * T + x[i] - x[0]) // L

if w[0] == 1:
    num = count % N
else:
    num = -count % N

y.sort(key=lambda x: (x[1], -x[0]))

for i in range(N):
    if y[i][0] == 0:
        index = i
        break

for i in range(N):
    print(y[(index-num+i) % N][1])

Submission status: Wrong Answer

Solution code:
N, L, T = map(int, input().split())
x = ["" for i in range(N)]
w = ["" for i in range(N)]
for i in range(N):
    x[i], w[i] = map(int, input().split())

y = [[i, ""] for i in range(N)]
for i in range(N):
    y[i][1] = (x[i] + (-1)**(w[i]+1)*T) % L

count = 0
for i in range(N):
    if w[0] < w[i]:
        count += (2 * T + L - x[i] + x[0]) // L
    elif w[0] > w[i]:
        count += (2 * T + x[i] - x[0]) // L

if w[0] == 1:
    num = count % N
else:
    num = -count % N

y.sort(key=lambda x: x[1])

for i in range(N):
    if y[i][0] == 0:
        index = i
        break

for i in range(N):
    print(y[(index-num+i) % N][1])

Submission status: Wrong Answer

Solution code:
N, L, T = map(int, input().split())
x = ["" for i in range(N)]
w = ["" for i in range(N)]
for i in range(N):
    x[i], w[i] = map(int, input().split())

y = ["" for i in range(N)]
for i in range(N):
    y[i] = (x[i] + (-1)**(w[i]+1)*T) % L

count = 0
for i in range(N):
    if w[0] < w[i]:
        count += (2 * T + (L - x[i] + x[0])) // L
    elif w[0] > w[i]:
        count += (2 * T + x[i] - x[0]) // L

if w[0] == 1:
    num = (count) % N
else:
    num = (-count) % N

y.sort()

for i in range(N):
    print(y[(num+i)%N])