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 = [int(item) for item in input().split()]
pos_list = [[int(item) for item in input().split()] for _ in range(N)]

first_ant = pos_list[0]
# N 匹の蟻がいて、それぞれの蟻は 1 から N まで番号の書かれたゼッケンをつけている。
# 二つの蟻が同じ場所についた瞬間、その二つの蟻はゼッケンを交換し、そのまますれ違って同じ方向に歩き続ける。
# 上記問題の言い換えに生息するfirst ant さんの操作後の位置とゼッケンを求める
if first_ant[1] == 1: #一番の子が1向きの場合

    last_pos_of_first_ant = (first_ant[0] + T ) % L
    num_of_reverse_ant = [item[1] for item in pos_list].count(2)

    cnt = 0
    reverse_ant_pos = [item[0] for item in pos_list if item[1] == 2]
    cnt += T//L * len(reverse_ant_pos)

    for i in reverse_ant_pos:
        if (i - first_ant[0])//2 +1 <= (T % L):
            cnt += 1
    
    last_num_of_first_ant = (1 + cnt) % N
    if last_num_of_first_ant == 0:
        last_num_of_first_ant += N

else:
    last_pos_of_first_ant = (first_ant[0] - T ) % L
    num_of_reverse_ant = [item[1] for item in pos_list].count(1)

    cnt = 0
    reverse_ant_pos = [item[0] for item in pos_list if item[1] == 1]

    cnt += T//L * len(reverse_ant_pos)

    for i in reverse_ant_pos:
        if ((first_ant[0] -(i-L))//2 + 1) <= (T % L):
            cnt += 1
            # print(T % L)
            # print(i, first_ant[0] -(i-L),(first_ant[0] -(i-L))//2 + 1) 
            # print('cnt', cnt)
    
    last_num_of_first_ant = (1 - cnt) % N
    if last_num_of_first_ant <= 0:
        last_num_of_first_ant += N

# アリの位置を求める
last_ant_pos = []

for ant_pos, direction  in pos_list:
    if direction == 1:
        last_ant_pos.append((ant_pos + T)%L)
    else:
        ant_pos = (ant_pos - T)%L
        if ant_pos <= 0:
            ant_pos += L
        last_ant_pos.append(ant_pos)

# first ant さんは位置Xにいるので、アリの位置リストからどれがfirst antさんか特定する。
# 特定したらその位置にゼッケンを設定する。
# 1方向のfirst antさんは、その他のゼッケンは時計回りに+1する（他のアリを1減らしながら回っているから）
# 2方向のfirst antさんは、その他のゼッケンを時計回りに-1する（他のアリを1増やしながら回っているから。逆回りに・・・で考えたほうが分かりよいか？）
# 2方向の場合はできたリストを逆順に出力する    
res = []
if first_ant[1] == 1:
    for i, pos in enumerate(last_ant_pos):
            temp_num = (last_num_of_first_ant+i)%N
            if temp_num == 0:
                temp_num = N
            res.append([pos, temp_num])

    res.sort(key=lambda x:x[1])
else:
    for i, pos in enumerate(last_ant_pos):
        temp_num = (last_num_of_first_ant-i)%N
        if temp_num == 0:
            temp_num = N
        res.append([pos, temp_num])

    res.sort(key=lambda x:x[1], reverse=True)



# print(first_ant)
# print(num_of_reverse_ant)
# print(reverse_ant_pos)
# print('collison', cnt)
# print('first ant of pos, num',last_pos_of_first_ant, last_num_of_first_ant)
# print(last_ant_pos)
# print(res)
# print('-------ans--------')
print(*[item[0] for item in res])

Submission status: Wrong Answer

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

first_ant = pos_list[0]
# N 匹の蟻がいて、それぞれの蟻は 1 から N まで番号の書かれたゼッケンをつけている。
# 二つの蟻が同じ場所についた瞬間、その二つの蟻はゼッケンを交換し、そのまますれ違って同じ方向に歩き続ける。
# 上記問題の言い換えに生息するfirst ant さんの操作後の位置とゼッケンを求める
if first_ant[1] == 1: #一番の子が1向きの場合

    last_pos_of_first_ant = (first_ant[0] + T ) % L
    num_of_reverse_ant = [item[1] for item in pos_list].count(2)

    cnt = 0
    reverse_ant_pos = [item[0] for item in pos_list if item[1] == 2]
    cnt += T//L * len(reverse_ant_pos)

    for i in reverse_ant_pos:
        if (i - first_ant[0])//2 +1 <= (T % L):
            cnt += 1
    
    last_num_of_first_ant = (1 + cnt) % N
    if last_num_of_first_ant == 0:
        last_num_of_first_ant += N

else:
    last_pos_of_first_ant = (first_ant[0] - T ) % L
    num_of_reverse_ant = [item[1] for item in pos_list].count(1)

    cnt = 0
    reverse_ant_pos = [item[0] for item in pos_list if item[1] == 1]

    cnt += T//L * len(reverse_ant_pos)

    for i in reverse_ant_pos:
        if ((first_ant[0] -(i-L))//2 + 1) <= (T % L):
            cnt += 1
            # print(T % L)
            # print(i, first_ant[0] -(i-L),(first_ant[0] -(i-L))//2 + 1) 
            # print('cnt', cnt)
    
    last_num_of_first_ant = (1 - cnt) % N
    if last_num_of_first_ant <= 0:
        last_num_of_first_ant += N

# アリの位置を求める
last_ant_pos = []

for ant_pos, direction  in pos_list:
    if direction == 1:
        last_ant_pos.append((ant_pos + T)%L)
    else:
        ant_pos = (ant_pos - T)%L
        if ant_pos < 0:
            ant_pos += L
        last_ant_pos.append(ant_pos)

# first ant さんは位置Xにいるので、アリの位置リストからどれがfirst antさんか特定する。
# 特定したらその位置にゼッケンを設定する。
# 1方向のfirst antさんは、その他のゼッケンは時計回りに+1する（他のアリを1減らしながら回っているから）
# 2方向のfirst antさんは、その他のゼッケンを時計回りに-1する（他のアリを1増やしながら回っているから。逆回りに・・・で考えたほうが分かりよいか？）
# 2方向の場合はできたリストを逆順に出力する    
res = []
if first_ant[1] == 1:
    for i, pos in enumerate(last_ant_pos):
            temp_num = (last_num_of_first_ant+i)%N
            if temp_num == 0:
                temp_num = N
            res.append([pos, temp_num])

    res.sort(key=lambda x:x[1])
else:
    for i, pos in enumerate(last_ant_pos):
        temp_num = (last_num_of_first_ant-i)%N
        if temp_num == 0:
            temp_num = N
        res.append([pos, temp_num])

    res.sort(key=lambda x:x[1], reverse=True)



# print(first_ant)
# print(num_of_reverse_ant)
# print(reverse_ant_pos)
# print('collison', cnt)
# print('first ant of pos, num',last_pos_of_first_ant, last_num_of_first_ant)
# print(last_ant_pos)
# print(res)
# print('-------ans--------')
print(*[item[0] for item in res])

Submission status: Wrong Answer

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

first_ant = pos_list[0]
# N 匹の蟻がいて、それぞれの蟻は 1 から N まで番号の書かれたゼッケンをつけている。
# 二つの蟻が同じ場所についた瞬間、その二つの蟻はゼッケンを交換し、そのまますれ違って同じ方向に歩き続ける。
# 上記問題の言い換えに生息するfirst ant さんの操作後の位置とゼッケンを求める
if first_ant[1] == 1: #一番の子が1向きの場合

    last_pos_of_first_ant = (first_ant[0] + T ) % L
    num_of_reverse_ant = [item[1] for item in pos_list].count(2)

    cnt = 0
    reverse_ant_pos = [item[0] for item in pos_list if item[1] == 2]
    cnt += T//L * len(reverse_ant_pos)

    for i in reverse_ant_pos:
        if (i - first_ant[0])//2 +1 <= (T % L):
            cnt += 1
    
    last_num_of_first_ant = (1 + cnt) % N
    if last_num_of_first_ant == 0:
        last_num_of_first_ant += N

else:
    last_pos_of_first_ant = (first_ant[0] - T ) % L
    num_of_reverse_ant = [item[1] for item in pos_list].count(1)

    cnt = 0
    reverse_ant_pos = [item[0] for item in pos_list if item[1] == 1]

    cnt += T//L * len(reverse_ant_pos)

    for i in reverse_ant_pos:
        if ((first_ant[0] -(i-L))//2 + 1) <= (T % L):
            cnt += 1
            print(T % L)
            print(i, first_ant[0] -(i-L),(first_ant[0] -(i-L))//2 + 1) 
            print('cnt', cnt)
    
    last_num_of_first_ant = (1 - cnt) % N
    if last_num_of_first_ant <= 0:
        last_num_of_first_ant += N

# アリの位置を求める
last_ant_pos = []

for ant_pos, direction  in pos_list:
    if direction == 1:
        last_ant_pos.append((ant_pos + T)%L)
    else:
        ant_pos = (ant_pos - T)%L
        if ant_pos < 0:
            ant_pos += L
        last_ant_pos.append(ant_pos)

# first ant さんは位置Xにいるので、アリの位置リストからどれがfirst antさんか特定する。
# 特定したらその位置にゼッケンを設定する。
# 1方向のfirst antさんは、その他のゼッケンは時計回りに+1する（他のアリを1減らしながら回っているから）
# 2方向のfirst antさんは、その他のゼッケンを時計回りに-1する（他のアリを1増やしながら回っているから。逆回りに・・・で考えたほうが分かりよいか？）
# 2方向の場合はできたリストを逆順に出力する    
res = []
if first_ant[1] == 1:
    for i, pos in enumerate(last_ant_pos):
            temp_num = (last_num_of_first_ant+i)%N
            if temp_num == 0:
                temp_num = N
            res.append([pos, temp_num])

    res.sort(key=lambda x:x[1])
else:
    for i, pos in enumerate(last_ant_pos):
        temp_num = (last_num_of_first_ant-i)%N
        if temp_num == 0:
            temp_num = N
        res.append([pos, temp_num])

    res.sort(key=lambda x:x[1], reverse=True)



# print(first_ant)
# print(num_of_reverse_ant)
# print(reverse_ant_pos)
# print('collison', cnt)
# print('first ant of pos, num',last_pos_of_first_ant, last_num_of_first_ant)
# print(last_ant_pos)
# print(res)
# print('-------ans--------')
print(*[item[0] for item in res])

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np
input = sys.stdin.buffer.readline
N,L,T= map(int,input().split())
XW=np.array([list(map(int,input().split())) for i in [0]*N]).astype(np.int64)
T = T % L
X,W = XW.T
offset = X[0]
X -= offset
W = -2*W+3
Y = (X + W * T)

ans = [0]*(N)
if W[0] == 1:
    check = (Y < T)
    num = np.sum(check) # crash
    pos = np.argmax(Y == T)
    temp = (Y+offset) % L
    for i in range(N):
        ans[i] = temp[(i+num+pos+1)%N]
else:
    check = (Y > L-T)
    num = np.sum(check) # crash
    pos = np.argmax(Y[::-1] == L-T)
    temp = (Y+offset) % L
    for i in range(N):
        ans[i] = temp[(i+num+pos-1)%N]

for a in ans:
    print(a)

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np
input = sys.stdin.buffer.readline
N,L,T= map(int,input().split())
XW=np.array([list(map(int,input().split())) for i in [0]*N]).astype(np.int64)
T = T % L
X,W = XW.T
offset = X[0]
X -= offset
W = -2*W+3
X_T = (X + W * T)

if W[0] == 1:
    check = (X_T < T)
    num = 1 + sum(check)
    pos = np.argmax(X_T == T) # pos is num
    shift = pos - num + 1
    ans = np.roll(X_T,-shift)
    ans = (ans + offset) % L
else:
    check = (X_T > L-T)
    num = 1 - sum(check)
    pos = np.argmax(X_T == T) # pos is num
    shift = pos - num
    ans = np.roll(X_T,shift)
    ans = (ans + offset) % L

for a in ans:
    print(a)

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np
input = sys.stdin.buffer.readline
N,L,T= map(int,input().split())
XW=np.array([list(map(int,input().split())) for i in [0]*N]).astype(np.int64)
T = T % L
X,W = XW.T
W = -2*W+3
X_T = (X + W * T)
cand = X_T % L

if W[0] == 1:
    check = (X_T <= T)
else:
    check = (X_T >= L-T)

ans = np.roll(X_T % L,-sum(check))

for a in ans:
    print(a)

Submission status: Wrong Answer

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

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

for i in range(N):
    X[i] = (X[i] + T * W[i]) % L

x = X[0]

X.sort()

ng = -1
ok = N
while abs(ok - ng) > 1:
    mid = (ok + ng) // 2
    if X[mid] >= x:
        ok = mid
    else:
        ng = mid
if ok + W[0] < N and ok + W[0] > 0:
    if X[ok] == X[ok+W[0]]:
        ok += W[0]

start = int((ok - C) % N)
for i in X[start:]:
    print(i)
for i in X[:start]:
    print(i)

Submission status: Wrong Answer

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

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

for i in range(N):
    X[i] = (X[i] + T * W[i]) % L

x = X[0]
n = C % N

X.sort()

ng = -1
ok = N
while abs(ok - ng) > 1:
    mid = (ok + ng) // 2
    if X[mid] >= x:
        ok = mid
    else:
        ng = mid

start = int((ok - n + N) % N)
for i in X[start:]:
    print(i)
for i in X[:start]:
    print(i)

Submission status: Wrong Answer

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

d = {1: 1, 2: -1}

# 蟻が原点を通過する回数
n_origins = 0

positions = []
for i, (x, w) in enumerate(data):
    _x = (x + d[w] * T) % L
    n_origin = int((x + d[w] * T) // L)
    n_origins += n_origin
    positions.append(_x)

positions.sort()
positions = positions[n_origins:] + positions[:n_origins]
print('\n'.join(map(str, positions)))

Submission status: Wrong Answer

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

d = {1: 1, 2: -1}

# 蟻が原点を通過する回数
n_origins = 0

positions = []
for i, (x, w) in enumerate(data):
    _x = (x + d[w] * T) % L
    n_origin = int((x + d[w] * T) // L)
    n_origins += n_origin
    positions.append(_x)

positions.sort()
positions = positions[n_origins:] + positions[:n_origins]
print(positions)

Submission status: Wrong Answer

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

d = {1: 1, 2: -1}

# 蟻が原点を通過する回数
n_origins = 0

positions = []
for i, (x, w) in enumerate(data):
    _x = (x + d[w] * T) % L
    n_origin = int((x + d[w] * T) // L)
    n_origins += n_origin
    positions.append(_x)

positions.sort()
positions[n_origins:] + positions[:n_origins]

Submission status: Wrong Answer

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

d = {1: 1, 2: -1}
x0, w0 = data[0]
d0 = d[w0]
# 0番目の蟻が反時計回りの場合、周回してから衝突するため、`全長 + 現在位置`が初期値であると考える
if w0 == 2:
    x0 += L
# 0番目の蟻が衝突する回数
n_collisions = 0

positions = []
for i, (x, w) in enumerate(data):
    _x = (x + d[w] * T) % L
    positions.append(_x)
    if i > 0 and w0 != w:
        # 0番目の蟻と初めて衝突する時刻
        t = T - (d0 * (x - x0) / 2)
        n_collisions += int(t >= 0)
        n_collisions += max(int(t // (L / 2)), 0)

n_collisions  *= d0
results = positions[-n_collisions:] + positions[:-n_collisions]
print('\n'.join(map(str, results)))

Submission status: Wrong Answer

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

d = {1: 1, 2: -1}
x0, w0 = data[0]

# 0番目の蟻が衝突する回数
n_collisions = 0

positions = []
for i, (x, w) in enumerate(data):
    _x = (x + d[w] * T) % L
    positions.append(_x)
    if i > 0 and w0 != w:
        n_collisions += (T - (x - x0)) // L + 1

results = positions[-n_collisions:] + positions[:-n_collisions]
print('\n'.join(map(str, results)))

Submission status: Wrong Answer

Solution code:
from bisect import bisect_right as br
N, L, T = map(int, input().split())
res = []
for _ in range(N):
  x, w = map(int, input().split())
  if w == 1:
    res.append((x + T) % L)
  else:
    res.append((x - T) % L)
#print(res)
sr = sorted(res)
ind = max(br(sr, res[0]) - 1, 0)
res = res[ind: ] + res[: ind]
for r in res:
  print(r)

Submission status: Wrong Answer

Solution code:
from collections import deque

n, l, t = map(int, input().split())
ants = [list(map(int, input().split())) for i in range(n)]

ants_t = [0]*n
count = 0
for i in range(n):
    ant = ants[i]
    if ant[1] == 1:
        c, ant_t = divmod(t + ant[0], l)
    else:
        c, ant_t = divmod(-t + ant[0], l)
    ants_t.append(ant_t)
    count += c
# print(ants_t, count)
ants_d = deque(sorted(ants_t))
# print(ants_d)

ants_d.rotate(-count)
# print(ants_d)
for ant in ants_d:
    print( (ant) % l )

Submission status: Wrong Answer

Solution code:
from collections import deque

n, l, t = map(int, input().split())
ants = [list(map(int, input().split())) for i in range(n)]
# print(ants)

ants_t = []
count = 0
for ant in ants:
    ant_t = ant
    if ant[1] == 1:
        c, ant_t[0] = divmod(t + ant[0], l)
        count += c
    else:
        c, ant_t[0] = divmod(-t + ant[0], l)
        count -= c
    ants_t.append(ant_t)
# print(ants_t, count)
ants_d = deque(sorted(ants_t))
# print(ants_d)

if ants_d[0][1] == 1:
    ants_d.rotate(count)
else:
    ants_d.rotate(-count)

# print(ants_d)
for ant in ants_d:
    print( (ant[0]) % l )

Submission status: Wrong Answer

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

x0,w0 = XW[0]
Xr = [x for x,w in XW if w!=w0]

n = 0
for x in Xr:
    x = ((x-x0) if w0==1 else (x0-x))%N
    n += (2*T-x)//L +1
    n %= N
if w0==2 : n = (-n)%N
X2 = [(x+T*(3-2*w))%L for x,w in XW]
x0 = X2[n]
X2.sort()
i = X2.index(x0)
if X2[(i+1)%N]==x0 : i = (i+1)%N
ans = X2[n:] + X2[:n]
for out in ans:
    print(out)

Submission status: Wrong Answer

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

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

right=[]
left=[]

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

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

def search(cnt):
    w=first_w
    if ll==0 or lr==0:
        return None
    elif cnt==0:
        return [0,0,0]
    elif w==1:
        right_temp=((cnt//2+cnt%2-1)//ll)*(l/2)+left[(cnt//2+cnt%2-1)%ll]
        left_temp=max((((cnt-2)//2)//lr),0)*(l/2)+right[((cnt-2)//2)%lr]*(cnt!=1)
    else:
        left_temp=((cnt//2+cnt%2-1)//lr)*(l/2)+right[(cnt//2+cnt%2-1)%lr]
        right_temp=max((((cnt-1)//2)//ll),0)*(l/2)+left[((cnt-2)//2)%ll]*(cnt!=1)
    return [left_temp+right_temp,right_temp,left_temp]

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

if ll==0 or lr==0:
    last=((first_x+t*int((-first_w+1.5)*2))%l+l)%l
else:
    a=b_search(0,10**9,t,search)
    b=search(a)
    if (a+first_w)%2==1:
        b[1]+=t-b[0]
    else:
        b[2]+=t-b[0]
    last=int(((first_x+b[1]-b[2])%l+l)%l)
    
ans=sorted([((x+t*int((-w+1.5)*2))%l+l)%l for x,w in xw])
    
for i in range(n):
    if last==ans[i]:
        if i==n-1:
            break
        elif ans[i+1]!=last:
            break
        else:
            if (a+first_w)%2==1:
                break
            else:
                i+=1
                break
for j in ans[i:]+ans[:i]:
    print(j)

Submission status: Wrong Answer

Solution code:
def input():return next(input_sample)
input_sample=iter("""
4 20 9
7 2
9 1
12 1
18 1
""".split("\n")[1:-1])

#問題を解く
n,l,t=map(int,input().split())
xw=[list(map(int,input().split())) for _ in [0]*n]

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

right=[]
left=[]

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

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

def search(cnt):
    w=first_w
    if ll==0 or lr==0:
        return None
    elif cnt==0:
        return [0,0,0]
    elif w==1:
        right_temp=((cnt//2+cnt%2-1)//ll)*(l/2)+left[(cnt//2+cnt%2-1)%ll]
        left_temp=max((((cnt-2)//2)//lr),0)*(l/2)+right[((cnt-2)//2)%lr]*(cnt!=1)
    else:
        left_temp=((cnt//2+cnt%2-1)//lr)*(l/2)+right[(cnt//2+cnt%2-1)%lr]
        right_temp=max((((cnt-1)//2)//ll),0)*(l/2)+left[((cnt-2)//2)%ll]*(cnt!=1)
    return [left_temp+right_temp,right_temp,left_temp]

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

a=b_search(0,10**9,t,search)

if a==False:
    last=((first_x+t*int((-first_w+1.5)*2))%l+l)%l
else:
    b=search(a)
    if (a+first_w)%2==1:
        b[1]+=t-b[0]
    else:
        b[2]+=t-b[0]
    last=int(((first_x+b[1]-b[2])%l+l)%l)
    
ans=sorted([((x+t*int((-w+1.5)*2))%l+l)%l for x,w in xw])
    
for i in range(n):
    if last==ans[i]:
        if i==n-1:
            break
        elif ans[i+1]!=last:
            break
        else:
            if (a+first_w)%2==1:
                break
            else:
                i+=1
                break
for j in ans[i:]+ans[:i]:
    print(j)

Submission status: Wrong Answer

Solution code:
def main():
    N, L, T = map(int, input().split())  # アリの数、外周、時間
    P = [0]*N  # アリの位置: 0から2L-1まで
    D = [0]*N  # アリの方向: 1か2
    for n in range(N):
        t1, t2 = map(int, input().split())
        P[n] = t1 * 2
        D[n] = t2
    for t in range(T * 2):
        P = [(P[n] - D[n] * 2 + 3) % (L * 2) for n in range(N)]
        mycount = P.count
    for n in range(N):
        print(str(P[n]//2))
 
 
main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

N,L,T = map(int,input().split())
XW = [[int(x) for x in input().split()] for _ in range(N)]

X,W = zip(*XW)

DX = [1 if w == 1 else -1 for w in W]

Y = [(x+dx*T)%L for x,dx in zip(X,DX)]

# 番号1がすれ違わず進んだ場所に相当するアリの番号
# すれ違うたびに1増える（W1=1） or 1減る（W1=-1）
# T秒ちょうどもすれ違い終わったと考える

x = 0
x0,dx0 = X[0],DX[0]
for y,dy in zip(X[1:],DX[1:]):
    if dx0 == dy:
        continue
    if dx0 == 1 and dy == -1:
        # 正の向きに追い越すので番号がひとつ増える
        x += (2*T-(y-x0)-1)//L + 1
    if dx0 == -1 and dy == 1:
        x -= (2*T-(L+x0-y))//L + 1

x %= N
answer = [None] * N
answer[x:N] = Y[0:N-x]
answer[0:x] = Y[N-x:N]

print('\n'.join(map(str,answer)))

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

N,L,T = map(int,input().split())
XW = [[int(x) for x in input().split()] for _ in range(N)]

X,W = zip(*XW)

DX = [1 if w == 1 else -1 for w in W]

Y = [(x+dx*T)%L for x,dx in zip(X,DX)]

# 番号1がすれ違わず進んだ場所に相当するアリの番号
# すれ違うたびに1増える（W1=1） or 1減る（W1=-1）
# T秒ちょうどもすれ違い終わったと考える

x = 0
x0,dx0 = X[0],DX[0]
for y,dy in zip(X[1:],DX[1:]):
    if dx0 == dy:
        continue
    if dx0 == 1 and dy == -1:
        # 正の向きに追い越すので番号がひとつ増える
        x += (2*T-(y-x0))//L + 1
    if dx0 == -1 and dy == 1:
        x -= (2*T-(L+x0-y))//L + 1

x %= N
answer = [None] * N
answer[x:N] = Y[0:N-x]
answer[0:x] = Y[N-x:N]

print('\n'.join(map(str,answer)))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

s = 0
n = [0] * N
for i in range(N):
    X, w = map(int, input().split())
    X += (T, -T)[w - 1]
    n[i] = X % L
    s -= X // L

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

Submission status: Wrong Answer

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

def f(w):
    if w == 1:
        return 1
    elif w == 2:
        return -1
    

d=[0 for i in range(n)]
for i in range(n-1):
    d[i] = s[i+1][0] - s[i][0]
d[n-1] = s[0][0] + l - s[n-1][0]

t = 0
dt = 0.5
while t < T:
    t+= dt
    s[0][0] = s[0][0] + f(s[0][1])*dt
    if s[0][0] >= l:
        s[0][0] -= l
    elif s[0][0] < 0:
        s[0][0] += l
        
    for i in range(n):
        if i < n-1:
            d[i] = d[i] + f(s[i+1][1])*dt - f(s[i][1])*dt
            s[i+1][0] = s[i][0] + d[i]
            if s[i+1][0] >= l:
                s[i+1][0] -= l
        else:
            d[n-1] = d[n-1] + f(s[0][1])*dt - f(s[n-1][1])*dt
            
    for i in range(n):
        if d[i] == 0 and i < n-1:
            s[i+1][1], s[i][1] = s[i][1], s[i+1][1]
        elif i == n-1 and d[i] == 0 :
            s[0][1], s[n-1][1] = s[n-1][1], s[0][1]
            
for i in range(n):
    print(s[i][0])

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

Solution code:
import bisect
import heapq
import itertools
import math
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter

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)
D = np.array(W)
D[D == 2] = -1

if all(D == 1):
    ans = (X + T) % L
    print('\n'.join(map(str, ans)))
    exit()
if all(D == -1):
    ans = (X - T) % L
    print('\n'.join(map(str, ans)))
    exit()

positions = (X + T * D) % L
positions.sort()

# T 秒間で何回ぶつかるか
x1 = X[D == 1][0]
ops = (X[D == -1] - x1) % L
ops.sort()
collision_count = np.searchsorted(ops, T * 2 % L) + T * 2 // L

# x1 がすり抜けたらいる場所
p = (x1 + T) % L
# そこに誰がいるか
w = ((D == 1).argmax() + collision_count) % N
ans = np.roll(positions, w - np.searchsorted(positions, p))
print('\n'.join(map(str, ans)))

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 * len(collisions) + 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)))