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())
t %= l

plots = []
for i in range(n):
    x, w = map(int, input().split())
    if x == 0:
        plots.append((x, w, i))

    elif w == 2:
        plots.append((x, w, i))
    else:
        plots.append((x-l, w, i))

plots.sort()
order = []

plots_new = []
for x, w, i in plots:
    order.append(i)
    if w == 1:
        x += t
    else:
        x -= t
    plots_new.append(x)


plots_new.sort()

ans = [None for _ in range(n)]
for i, x in enumerate(order):
    ans[x] = plots_new[i] % l

print(*ans, sep='\n')

Submission status: Wrong Answer

Solution code:
n,l,t = map(int,input().split())
x = []
y = []
for i in range(n):
    x.append(list(map(int,input().split())))
d = x[0][1]
b = x[0][0]
k = 2 * t
for i in range(1,n):
    if(x[i][1] == d):
        y.append(0)
    else:
        if d == 1:
            sa = (x[i][0] - b)%l
        else:
            sa = (b - x[i][0])%l
        
        if k >= sa:
            y.append(1+int((k-sa)/l))
        else:
            y.append(0)

z = []
for i in range(n):
    x[i][0] += t * pow(-1,x[i][1]+1)
    x[i][0] %= l
    z.append(x[i][0])
sy = sum(y)
z = sorted(z)

if d==2:
    z = z[-sy:] + z[:-sy]
else:
    z = z[sy:] + z[:sy]

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

Submission status: Wrong Answer

Solution code:
n,l,t = map(int,input().split())
x = []
y = []
for i in range(n):
    x.append(list(map(int,input().split())))
d = x[0][1]
b = x[0][0]
k = 2 * t
for i in range(1,n):
    if(x[i][1] == d):
        y.append(0)
    else:
        if d == 1:
            sa = (x[i][0] - b)%l
        else:
            sa = (b - x[i][0])%l
        
        if k >= sa:
            y.append(1+int((k-sa)/l))
        else:
            y.append(0)

for i in range(n):
    x[i][0] += t * pow(-1,x[i][1]+1)
    x[i][0] %= l

sy = sum(y)
sx = sorted(x,key=lambda x:x[0])
if d==2:
    sx = sx[-sy:] + sx[:-sy]
else:
    sx = sx[sy:] + sx[:sy]

for i in range(n):
    print(sx[i][0])

Submission status: Wrong Answer

Solution code:
mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.readline

    N, L, T = map(int, input().split())
    M, T = divmod(T, L)
    X = []
    W = []
    for _ in range(N):
        x, w = map(int, input().split())
        X.append(x)
        W.append(w)

    if N == 1:
        if W[0] == 1:
            print((X[0] + T)%L)
        else:
            print((X[0] - T)%L)
        exit()

    Y = []
    for i in range(N):
        if W[i] == 1:
            Y.append(((X[i] + T)%L, 1))
        else:
            Y.append(((X[i] - T)%L, 2))
    Y.sort(key=lambda p: p[0])

    if W[0] == 1:
        y0 = (X[0] + T)%L
        for i in range(N):
            if Y[i][0] == y0:
                i0 = i
                break
        S = 0
        i = 0
        idx = (M * W.count(2) * 2)%N
        while True:
            i = (i+1)%N
            if i:
                S += X[i] - X[i-1]
            else:
                S += L - (X[-1] - X[0])
            if S >= T*2:
                break
            if W[i] == 2:
                idx = (idx+1)%N
        ans = [0] * N
        for i in range(N):
            ans[(idx+i)%N] = Y[(i0+i)%N][0]
    else:
        y0 = (X[0] - T) % L
        for i in range(N-1, -1, -1):
            if Y[i][0] == y0:
                i0 = i
                break
        S = 0
        i = 0
        idx = (M * W.count(1) * 2)%N
        while True:
            i = (i - 1) % N
            if i != N-1:
                S += X[i+1] - X[i]
            else:
                S += L - (X[-1] - X[0])
            if S >= T * 2:
                break
            if W[i] == 1:
                idx = (idx - 1)%N
        ans = [0] * N
        for i in range(0, -N, -1):
            ans[(idx + i) % N] = Y[(i0+i)%N][0]
    for a in ans:
        print(a)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.readline

    N, L, T = map(int, input().split())
    T %= L
    X = []
    W = []
    for _ in range(N):
        x, w = map(int, input().split())
        X.append(x)
        W.append(w)

    if N == 1:
        if W[0] == 1:
            print((X[0] + T)%L)
        else:
            print((X[0] - T)%L)
        exit()

    Y = []
    for i in range(N):
        if W[i] == 1:
            Y.append(((X[i] + T)%L, 1))
        else:
            Y.append(((X[i] - T)%L, 2))
    Y.sort(key=lambda p: p[0])

    if W[0] == 1:
        y0 = (X[0] + T)%L
        for i in range(N):
            if Y[i][0] == y0:
                i0 = i
                break
        S = 0
        i = 0
        idx = 0
        while True:
            i = (i+1)%N
            if i:
                S += X[i] - X[i-1]
            else:
                S += L - (X[-1] - X[0])
            if S >= T*2:
                break
            if W[i] == 2:
                idx = (idx+1)%N
        ans = [0] * N
        for i in range(N):
            ans[(idx+i)%N] = Y[(i0+i)%N][0]
    else:
        y0 = (X[0] - T) % L
        for i in range(N-1, -1, -1):
            if Y[i][0] == y0:
                i0 = i
                break
        S = 0
        i = 0
        idx = 0
        while True:
            i = (i - 1) % N
            if i != N-1:
                S += X[i+1] - X[i]
            else:
                S += L - (X[-1] - X[0])
            if S >= T * 2:
                break
            if W[i] == 1:
                idx = (idx - 1)%N
        ans = [0] * N
        for i in range(0, -N, -1):
            ans[(idx + i) % N] = Y[(i0+i)%N][0]
    for a in ans:
        print(a)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.readline

    N, L, T = map(int, input().split())
    T %= L
    X = []
    W = []
    for _ in range(N):
        x, w = map(int, input().split())
        X.append(x)
        W.append(w)

    if N == 1:
        if W[0] == 1:
            print((X[0] + T)%L)
        else:
            print((X[0] - T)%L)
        exit()

    Y = []
    for i in range(N):
        if W[i] == 1:
            Y.append(((X[i] + T)%L, 1))
        else:
            Y.append(((X[i] - T)%L, 2))
    Y.sort(key=lambda p: p[0])

    if W[0] == 1:
        y0 = (X[0] + T)%L
        for i in range(N):
            if Y[i][0] == y0:
                i0 = i
                break
        S = 0
        i = 0
        idx = 0
        while True:
            i = (i+1)%N
            if i:
                S += X[i] - X[i-1]
            else:
                S += L - (X[0] - X[-1])
            if S >= T*2:
                break
            if W[i] == 2:
                idx = (idx+1)%N
        ans = [0] * N
        for i in range(N):
            ans[(idx+i)%N] = Y[(i0+i)%N][0]
    else:
        y0 = (X[0] - T) % L
        for i in range(N-1, -1, -1):
            if Y[i][0] == y0:
                i0 = i
                break
        S = 0
        i = 0
        idx = 0
        while True:
            i = (i - 1) % N
            if i != N-1:
                S += X[i+1] - X[i]
            else:
                S += L - (X[-1] - X[0])
            if S >= T * 2:
                break
            if W[i] == 1:
                idx = (idx - 1)%N
        ans = [0] * N
        for i in range(0, -N, -1):
            ans[(idx + i) % N] = Y[(i0+i)%N][0]
    for a in ans:
        print(a)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.readline

    N, L, T = map(int, input().split())
    T %= L
    X = []
    W = []
    for _ in range(N):
        x, w = map(int, input().split())
        X.append(x)
        W.append(w)

    if N == 1:
        if W[0] == 1:
            print((X[0] + T)%L)
        else:
            print((X[0] - T)%L)
        exit()

    Y = []
    for i in range(N):
        if W[i] == 1:
            Y.append(((X[i] + T)%L, 1))
        else:
            Y.append(((X[i] - T)%L, 2))
    Y.sort(key=lambda p: p[0])

    if W[0] == 1:
        y0 = (X[0] + T)%L
        for i in range(N):
            if Y[i][0] == y0:
                i0 = i
                break
        S = 0
        i = 0
        idx = 0
        while True:
            i = (i+1)%N
            if i:
                S += X[i] - X[0]
            else:
                S += L - (X[0] - X[-1])
            if S >= T*2:
                break
            if W[i] == 2:
                idx = (idx+1)%N
        ans = [0] * N
        for i in range(N):
            ans[(idx+i)%N] = Y[(i0+i)%N][0]
    else:
        y0 = (X[0] - T) % L
        for i in range(N-1, -1, -1):
            if Y[i][0] == y0:
                i0 = i
                break
        S = 0
        i = 0
        idx = 0
        while True:
            i = (i - 1) % N
            if i != N-1:
                S += X[i+1] - X[i]
            else:
                S += L - (X[-1] - X[0])
            if S >= T * 2:
                break
            if W[i] == 1:
                idx = (idx - 1)%N
        ans = [0] * N
        for i in range(0, -N, -1):
            ans[(idx + i) % N] = Y[(i0+i)%N][0]
    for a in ans:
        print(a)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.readline

    N, L, T = map(int, input().split())
    T %= L
    X = []
    W = []
    for _ in range(N):
        x, w = map(int, input().split())
        X.append(x)
        W.append(w)

    if N == 1:
        if W[0] == 1:
            print((X[0] + T)%L)
        else:
            print((X[0] - T)%L)
        exit()

    Y = []
    for i in range(N):
        if W[i] == 1:
            Y.append(((X[i] + T)%L, 1))
        else:
            Y.append(((X[i] - T)%L, 2))
    Y.sort(key=lambda p: p[0])

    if W[0] == 1:
        y0 = (X[0] + T)%L
        for i in range(N):
            if Y[i][0] == y0:
                i0 = i
                break
        S = 0
        i = 0
        idx = 0
        while True:
            i = (i+1)%N
            if i:
                S += X[i] - X[0]
            else:
                S += L - (X[0] - X[-1])
            if S >= T*2:
                break
            if W[i] == 2:
                idx = (idx+1)%N
        ans = [0] * N
        for i in range(N):
            ans[(idx+i)%N] = Y[(i0+i)%N][0]
    else:
        y0 = (X[0] - T) % L
        for i in range(N-1, -1, -1):
            if Y[i][0] == y0:
                i0 = i
                break
        S = 0
        i = 0
        idx = 0
        while True:
            i = (i - 1) % N
            if i != N-1:
                S += X[i+1] - X[i]
            else:
                S += L - (X[-1] - X[0])
            if S >= T * 2:
                break
            if W[i] == 1:
                idx = (idx - 1)%N
        ans = [0] * N
        for i in range(N):
            ans[(idx + i) % N] = Y[(i0+i)%N][0]
    for a in ans:
        print(a)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.readline

    N, L, T = map(int, input().split())
    T %= L
    X = []
    W = []
    for _ in range(N):
        x, w = map(int, input().split())
        X.append(x)
        W.append(w)

    if N == 1:
        if W[0] == 1:
            print((X[0] + T)%L)
        else:
            print((X[0] - T)%L)
        exit()

    Y = []
    for i in range(N):
        if W[i] == 1:
            Y.append(((X[i] + T)%L, 1))
        else:
            Y.append(((X[i] - T)%L, 2))
    Y.sort(key=lambda p: p[0])

    if W[0] == 1:
        y0 = (X[0] + T)%L
        for i in range(N):
            if Y[i][0] == y0:
                i0 = i
                break
        S = 0
        i = i0
        idx = 0
        while True:
            i = (i+1)%N
            if i:
                S += Y[i][0] - Y[i-1][0]
            else:
                S += L - (Y[-1][0] - Y[0][0])
            if S >= T*2:
                break
            if W[i] == 2:
                idx = (idx+1)%N
        ans = [0] * N
        for i in range(N):
            ans[(idx+i)%N] = Y[(i0+i)%N][0]
    else:
        y0 = (X[0] - T) % L
        for i in range(N-1, -1, -1):
            if Y[i][0] == y0:
                i0 = i
                break
        S = 0
        i = i0
        idx = 0
        while True:
            i = (i - 1) % N
            if i != N-1:
                S += (Y[i][0] - Y[(i+1)%N][0])%L
            else:
                S += L - (Y[-1][0] - Y[0][0])
            if S >= T * 2:
                break
            if W[i] == 1:
                idx = (idx - 1)%N
        ans = [0] * N
        for i in range(N):
            ans[(idx + i) % N] = Y[(i0+i)%N][0]
    for a in ans:
        print(a)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.readline

    N, L, T = map(int, input().split())
    T %= L
    X = []
    W = []
    for _ in range(N):
        x, w = map(int, input().split())
        X.append(x)
        W.append(w)

    if N == 1:
        if W[0] == 1:
            print((X[0] + T)%L)
        else:
            print((X[0] - T)%L)
        exit()

    Y = []
    for i in range(N):
        if W[i] == 1:
            Y.append(((X[i] + T)%L, 1))
        else:
            Y.append(((X[i] - T)%L, 2))
    Y.sort(key=lambda p: p[0])

    if W[0] == 1:
        y0 = (X[0] + T)%L
        for i in range(N):
            if Y[i][0] == y0:
                i0 = i
                break
        S = 0
        i = i0
        idx = 0
        while True:
            i = (i+1)%N
            if i:
                S += Y[i][0] - Y[i-1][0]
            else:
                S += L - (Y[-1][0] - Y[0][0])
            if S > T*2:
                break
            if W[i] == 2:
                idx = (idx+1)%N
        ans = [0] * N
        for i in range(N):
            ans[(idx+i)%N] = Y[(i0+i)%N][0]
    else:
        y0 = (X[0] - T) % L
        for i in range(N-1, -1, -1):
            if Y[i][0] == y0:
                i0 = i
                break
        S = 0
        i = i0
        idx = 0
        while True:
            i = (i - 1) % N
            if i != N-1:
                S += (Y[i][0] - Y[(i+1)%N][0])%L
            else:
                S += L - (Y[-1][0] - Y[0][0])
            if S > T * 2:
                break
            if W[i] == 1:
                idx = (idx - 1)%N
        ans = [0] * N
        for i in range(N):
            ans[(idx + i) % N] = Y[(i0+i)%N][0]
    for a in ans:
        print(a)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.readline

    N, L, T = map(int, input().split())
    T %= L
    X = []
    W = []
    for _ in range(N):
        x, w = map(int, input().split())
        X.append(x)
        W.append(w)

    if N == 1:
        if W[0] == 1:
            print((X[0] + T)%L)
        else:
            print((X[0] - T)%L)
        exit()

    Y = []
    for i in range(N):
        if W[i] == 1:
            Y.append(((X[i] + T)%L, 1))
        else:
            Y.append(((X[i] - T)%L, 2))
    Y.sort(key=lambda p: p[0])

    if W[0] == 1:
        y0 = (X[0] + T)%L
        for i in range(N):
            if Y[i][0] == y0:
                i0 = i
                break
        S = 0
        i = i0
        idx = 0
        while True:
            i = (i+1)%N
            S += (Y[i][0] - Y[i-1][0])%L
            if S > T*2:
                break
            if W[i] == 2:
                idx = (idx+1)%N
        ans = [0] * N
        for i in range(N):
            ans[(idx+i)%N] = Y[(i0+i)%N][0]
    else:
        y0 = (X[0] - T) % L
        for i in range(N-1, -1, -1):
            if Y[i][0] == y0:
                i0 = i
                break
        S = 0
        i = i0
        idx = 0
        while True:
            i = (i - 1) % N
            S += (Y[i][0] - Y[(i+1)%N][0])%L
            if S > T * 2:
                break
            if W[i] == 1:
                idx = (idx - 1)%N
        ans = [0] * N
        for i in range(N):
            ans[(idx + i) % N] = Y[(i0+i)%N][0]
    for a in ans:
        print(a)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

"""
・順序が固定されるので、区間だったら簡単
・円のときも、地点 0 をそれぞれの方向に通った人数を見れば計算できる
"""

N, L, T = map(int, readline().split())
XW = np.array(read().split(), np.int64)
X = XW[::2]
W = XW[1::2]

speed = np.where(W == 1, 1, -1)

Y = X + speed * T

n = (Y // L - X // L).sum()

Y %= L
Y.sort()
Y = np.concatenate((Y[n:], Y[:n]))

print('\n'.join(map(str, Y.tolist())))

Submission status: Wrong Answer

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

c = []
s = 0

for i in range(n):
    x, w = map(int,input().split())
    if w == 1:
        c.append((x+t)%l)
        s += (x+t)//l
    else: # w == 2:
        c.append((x-t)%l)
        s += (x-t)//l

c.sort()
s %= n
c = c[s:] + c[:s]
print(c)

print([i for i in c], sep='\n')

Submission status: Wrong Answer

Solution code:
"""
まず、蟻はぶつかることなくすれ違うものと仮定し、全ての蟻に関して、T秒後の位置を求めて、配列に保存しておく。
ただし、実際には蟻同士はぶつかるため、この配列に保存した座標と蟻の対応関係がバラバラである。
さてどうしたものか。
"""


"""
参照元：
https://atcoder.jp/contests/agc013/submissions/6262542
N, L, T = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(N)]

#y[i] -> 衝突を無視した時に、i番目のありがT秒後にいる座標
#cnt -> 衝突を無視したとき、全ての蟻の集会回数の合計
y = [0] * N
cnt = 0
for i, (x, w) in enumerate(X):
    if w == 1:
        y[i] = (x + T) % L
        cnt += (x + T) // L
    else:
        y[i] = (x - T) % L
        cnt += (x - T) // L

y.sort()
for i in range(N):
    print(y[(i + cnt) % N])
"""

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

#T秒後の各蟻の座標を求める
afterT = []
for x,w in X:
    if w == 1:
        afterT.append((x+T)%L)
    else:
        afterT.append((L+(x-T)%L)%L)


#最初、0番だった蟻が、T秒後に何番の蟻になっているかを求める。
fx,fw = X[0]
cnt = 0
for i in range(1,N):
    x,w = X[i]
    tmpT = T
    if w!=fw:
        if fw == 1:
            if T >= (x-fx)//2:
                cnt += 1
                tmpT -= (x-fx)//2
                cnt += tmpT//(L//2)
            
        elif fw == 2:
            if T >= (L+fx-x)//2:
                cnt -= 1
                tmpT -= (L+fx-x)//2
                cnt -= tmpT//(L//2)
if fw == 1:
    cnt %= N
else:
    cnt = (N+cnt%N)%N

#cnt -> 最初0番だった蟻のT秒後の番号


fp = afterT[0]
afterT.sort()
idx = afterT.index(fp)
if afterT.count(fp) != 1 and fw==1:
    idx += 1

afterT = afterT[idx-cnt:]+afterT[:idx-cnt]
for a in afterT:
    print(a)

Submission status: Wrong Answer

Solution code:
import sys
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    N, L, T = map(int, readline().split())
    position = []
    #0をL-1からーに時計回りに超える場合は+1
    #0からL-1に反時計回りに超える場合は-1
    count = 0
    for i in range(N):
        x,w = map(int, readline().split())
        if w==1:
            count += (x+T)//L
            position.append((x+T)%L)
        else:
            if x-T<0:
                count += (x-T)//L
            position.append((x-T)%L)
    position.sort()
    ans = position[count:] + position[:count]
    for i in range(N):
        print(ans[i])


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    N, L, T = map(int, readline().split())
    position = []
    #0をL-1からーに時計回りに超える場合は+1
    #0からL-1に反時計回りに超える場合は-1
    count = 0
    for i in range(N):
        x,w = map(int, readline().split())
        if w==1:
            count += (x+T)//L
            position.append((x+T)%L)
        else:
            if x-T<0:
                count += (x-T+1)//L
            position.append((x-T)%L)
    position.sort()
    ans = position[count:] + position[:count]
    for i in range(N):
        print(ans[i])


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

n, l, t = map(int, input().split())
XW = [list(map(int, input().split())) for _ in range(n)]
L = []
cnt = 0
for i, xw in enumerate(XW):
  x, w = xw
  if w == 1:
    L.append((x+t)%l)
    if l-x > t:
      continue
    cnt -= 1 + (t-(l-x))//l
  else:
    L.append((x-t)%l)
    if x > t:
      continue
    cnt += 1 + (t-x)//l
x_0, w_0 = XW[cnt%n]
f = L.index((x_0+t*(3-2*w_0))%l)
for i in range(f, f+n):
  print(L[i%n])

Submission status: Wrong Answer

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

n, l, t = map(int, input().split())
XW = [list(map(int, input().split())) for _ in range(n)]
L = []
for i, xw in enumerate(XW):
  x, w = xw
  if w == 1:
    L.append((x+t)%l)
  else:
    L.append((x-t)%l)
L.sort()
x_0, w_0 = XW[0]
b = 0
for x, w in XW[1:]:
  if w_0 == w:
    continue
  if w_0 == 1:
    b += 1 + (2*t-(x-x_0)-1)//l
  else:
    b -= 1 + (2*t-(l-(x-x_0)))//l
m = L.index(L[b%n])
for i in range(m, m+n):
  print(L[i%n])

Submission status: Wrong Answer

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

n, l, t = map(int, input().split())
XW = [list(map(int, input().split())) for _ in range(n)]
L = []
for i, xw in enumerate(XW):
  x, w = xw
  if w == 1:
    L.append((x+t)%l)
  else:
    L.append((x-t)%l)
L.sort()
x_0, w_0 = XW[0]
b = 0
for x, w in XW[1:]:
  if w_0 == w:
    continue
  if w_0 == 1:
    if x-x_0 > 2*t:
      continue
    b += 1 + (2*t - (x-x_0)) // l
  else:
    if l-(x-x_0) > 2*t:
      continue
    b -= 1 + (2*t - (l-(x-x_0))) // l
m = L.index(L[b%n])
for i in range(m, m+n):
  print(L[i%n])

Submission status: Wrong Answer

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

n, l, t = map(int, input().split())
XW = [list(map(int, input().split())) for _ in range(n)]
L = []
for i, xw in enumerate(XW):
  x, w = xw
  if w == 1:
    L.append((x+t)%l)
  else:
    L.append((x-t)%l)
L.sort()
x_0, w_0 = XW[0]
b = 0
for x, w in XW[1:]:
  if w_0 == w:
    continue
  if w_0 == 1:
    if x-x_0 > 2*t:
      continue
    b += 1 + (2*t - (x-x_0)) // l
  else:
    if l-(x-x_0) > 2*t:
      continue
    b -= 1 + (2*t - (l-(x-x_0))) // l
for i in range(b, b+n):
  print(L[i%n])

Submission status: Wrong Answer

Solution code:
n, l, t =map(int, input().split())
x=[]
w=[]
for i in range(n):
  a, b=map(int, input().split())
  x.append(a)
  if b==2:
    w.append(-1)
  else:
    w.append(1)
for fn in range(t*2):
  x=[d+0.5*e for (d, e) in zip(x, w)]
  for ft in range(n):
    if x[ft]>=l:
      x[ft]-=l
    elif x[ft]<0:
      x[ft]+=l
  for fl in range(n-1):
    if x[fl]==x[fl+1]:
      w[fl]*=-1
      w[fl+1]*=-1
print(x)

Submission status: Wrong Answer

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

def main():
    N,L,T = map(int,input().split())
    pos = [list(map(int,input().split())) for _ in range(N)]
    
    bp,br = pos[0]
    fp = [(bp+(-2*br+3)*T)%L]
    orpos = (bp+(-2*br+3)*T)%L
    
    count = 0
    for i in range(1,N):
        cp,cr = pos[i]
        fp.append((cp+(-2*cr+3)*T)%L)
        if br == cr:
            continue
        else:
            if cr == 1:
                if bp < cp:
                    time = L-(cp-bp)
                else:
                    time = bp-cp
                if time <= T:
                    count += int((T-time)//(L/2)+1)
            else:
                if bp < cp:
                    time = cp-bp
                else:
                    time = L-(bp-cp)
                if time <= T:
                    count += int((T-time)//(L/2)+1)
    
    fp.sort()
    ind = fp.index(orpos)
    ind += N-count
    ind %= N
    
    ans = fp[ind:]+fp[:ind]
    print(*ans,sep="\n")
    
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

def dist(x, y, sign_0):
    if sign_0 == -1:
        x, y = y, x
    if x < y: return y - x
    else: return y - x + l

place = []
for i, (x, w) in enumerate(ants):
    sign = 1 if w == 1 else -1
    place.append((x + t * sign) % l)
    if i == 0:
        num = 0
        x_0 = x
        sign_0 = sign
    elif sign_0 * sign == -1:
        length = 2 * t
        d = dist(x_0, x, sign_0)
        if length > d or (length == d and sign_0 == -1):
            num = (num + sign_0) % n
            length -= d
            num = (num + (length // l) * sign_0) % n
    else: continue

place.sort()
i_0 = (place.index((x_0 + t * sign_0) % l) - num) % n

for i in range(i_0, n + i_0):
    i = i % n
    print(place[i])

Submission status: Wrong Answer

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

def dist(x, y, sign_0):
    if sign_0 == -1:
        x, y = y, x
    if x < y: return y - x
    else: return y - x + l

place = []
for i, (x, w) in enumerate(ants):
    sign = 1 if w == 1 else -1
    place.append((x + t * sign) % l)
    if i == 0:
        num = 0
        x_0 = x
        sign_0 = sign
    elif sign_0 * sign == -1:
        length = 2 * t
        d = dist(x_0, x, sign_0)
        if length >= d:
            num = (num + sign_0) % n
            length -= d
            num = (num + (length // l) * sign_0) % n
    else: continue

place.sort()
i_0 = (place.index((x_0 + t * sign_0) % l) - num) % n

for i in range(i_0, n + i_0):
    i = i % n
    print(place[i])

Submission status: Wrong Answer

Solution code:
n,l,t=map(int,input().split())
def f(x1,w1,x2,w2):
  if w1==1:
    r=x2-x1
  else:
    r=l+x1-x2+1
  ans=2*(t//l)
  if r<(t%l)*2:ans+=1
  return ans
xw=[list(map(int,input().split()))for _ in range(n)]
p=[(xw[i][0]+((1 if xw[i][1]==1 else -1)*t))%l for i in range(n)]
p.sort()
#print(p)
x,w=xw[0]
ind=0
for xx,ww in xw[1:]:
  if w!=ww:
    if w==1:ind+=f(x,w,xx,ww)
    else:ind-=f(x,w,xx,ww)
  ind%=n
  #print(xx,ww,ind)
m=(x+((1 if w==1 else -1)*t))%l
if w==1:
  for i in range(n):
    if p[i]==m:
      indd=i
      break
else:
  for i in range(n-1,-1,-1):
    if p[i]==m:
      indd=i
      break
#print(ind,indd)
ans=(indd-ind)%n
p=p[ans:]+p[:ans]
print(*p)

Submission status: Wrong Answer

Solution code:
n,l,t=map(int,input().split())
def f(x1,w1,x2,w2):
  if w1==1:
    r=x2-x1
  else:
    r=l+x1-x2
  ans=2*(t//l)
  if r<=(t%l)*2:ans+=1
  return ans
xw=[list(map(int,input().split()))for _ in range(n)]
p=[(xw[i][0]+((1 if xw[i][1]==1 else -1)*t))%l for i in range(n)]
p.sort()
#print(p)
x,w=xw[0]
ind=0
for xx,ww in xw[1:]:
  if w!=ww:
    if w==1:ind+=f(x,w,xx,ww)
    else:ind-=f(x,w,xx,ww)
  ind%=n
  #print(xx,ww,ind)
m=(x+((1 if w==1 else -1)*t))%l
if w==1:
  for i in range(n):
    if p[i]==m:
      indd=i
      break
else:
  for i in range(n-1,-1,-1):
    if p[i]==m:
      indd=i
      break
#print(ind,indd)
ans=(indd-ind)%n
p=p[ans:]+p[:ans]
print(*p)

Submission status: Wrong Answer

Solution code:
n,l,t=map(int,input().split())
def f(x1,w1,x2,w2):
  if w1==1:
    r=x2-x1
  else:
    r=l+x1-x2
  ans=2*(t//l)
  if r<=(t%l)*2:ans+=1
  return ans
xw=[list(map(int,input().split()))for _ in range(n)]
p=[(xw[i][0]+((1 if xw[i][1]==1 else -1)*t))%l for i in range(n)]
p.sort()
#print(p)
x,w=xw[0]
ind=0
for xx,ww in xw[1:]:
  if w!=ww:
    if w==1:ind+=f(x,w,xx,ww)
    else:ind-=f(x,w,xx,ww)
  ind%=n
  #print(xx,ww,ind)
m=(x+((1 if w==1 else -1)*t))%l
if w==2:
  for i in range(n):
    if p[i]==m:
      indd=i
      break
else:
  for i in range(n-1,-1,-1):
    if p[i]==m:
      indd=i
      break
#print(ind,indd)
ans=(indd-ind)%n
p=p[ans:]+p[:ans]
print(*p)

Submission status: Wrong Answer

Solution code:
n,l,t=map(int,input().split())
def f(x1,w1,x2,w2):
  if w1==1:
    r=x2-x1
  else:
    r=l+x1-x2
  ans=2*(t//l)
  if r<(t%l)*2:ans+=1
  return ans
xw=[list(map(int,input().split()))for _ in range(n)]
p=[(xw[i][0]+((1 if xw[i][1]==1 else -1)*t))%l for i in range(n)]
p.sort()
#print(p)
x,w=xw[0]
ind=0
for xx,ww in xw[1:]:
  if w!=ww:
    if w==1:ind+=f(x,w,xx,ww)
    else:ind-=f(x,w,xx,ww)
  ind%=n
  #print(xx,ww,ind)
m=(x+((1 if w==1 else -1)*t))%l
if w==1:
  for i in range(n):
    if p[i]==m:
      indd=i
      break
else:
  for i in range(n-1,-1,-1):
    if p[i]==m:
      indd=i
      break
#print(ind,indd)
ans=(indd-ind)%n
p=p[ans:]+p[:ans]
print(*p)

Submission status: Wrong Answer

Solution code:
n,l,t=map(int,input().split())
def f(x1,w1,x2,w2):
  if w1==1:
    r=x2-x1
  else:
    r=l+x1-x2
  ans=2*(t//l)
  if r<(t%l)*2:ans+=1
  return ans
xw=[list(map(int,input().split()))for _ in range(n)]
p=[(xw[i][0]+((1 if xw[i][1]==1 else -1)*t))%l for i in range(n)]
p.sort()
#print(p)
x,w=xw[0]
ind=0
for xx,ww in xw[1:]:
  if w!=ww:
    if w==1:ind+=f(x,w,xx,ww)
    else:ind-=f(x,w,xx,ww)
  ind%=n
  #print(xx,ww,ind)
m=(x+((1 if w==1 else -1)*t))%l
if w==1:
  for i in range(n):
    if p[i]==m:
      indd=i
      break
else:
  for i in range(n-1,-1,-1):
    if p[i]==m:
      indd=i
      break
#print(ind,indd)
ans=indd-ind
p=p[ans:]+p[:ans]
print(*p)

Submission status: Wrong Answer

Solution code:
n,l,t=map(int,input().split())
def f(x1,w1,x2,w2):
  if w1==1:
    r=x2-x1
  else:
    r=l+x1-x2
  ans=2*(t//l)
  if r<=(t%l)*2:ans+=1
  return ans
xw=[list(map(int,input().split()))for _ in range(n)]
p=[(xw[i][0]+((1 if xw[i][1]==1 else -1)*t))%l for i in range(n)]
p.sort()
#print(p)
x,w=xw[0]
ind=0
for xx,ww in xw[1:]:
  if w!=ww:
    if w==1:ind+=f(x,w,xx,ww)
    else:ind-=f(x,w,xx,ww)
  #print(xx,ww,ind)
p=p[ind:]+p[:ind]
print(*p)