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: Accepted

Solution code:
N, L, T = map(int, input().split())
X = [0 for i in range(N)]
W = [0 for i in range(N)]
E = [0 for i in range(N)]
count = 0
for i in range(N):
    X[i], W[i] = map(int, input().split())
    if W[i] == 1:
        end = X[i] + T
        end = end % L
    if W[i] == 2:
        end = X[i]-T
        end = end % L
        if end < 0:
            end += L
    E[i] = end
    shu = L / 2.0
    if i > 0 and W[i] == 2 and  W[0] == 1:
        sa = X[i] -X[0]
        if sa < 0:
            sa += L
        gikan = sa / 2.0
        count += (T - gikan ) // shu + 1
        if (T - gikan) % shu == 0:
            count -= 1

    if i > 0 and W[i] == 1 and  W[0] == 2:
        sa = X[0] -X[i]
        if sa < 0:
            sa += L
        gikan = sa / 2.0
        count -= (T - gikan ) // shu + 1

#print(E)
count = count % N
if count < 0:
    count += N
count = int(count)
#print(count)
basho = E[0]
E.sort()
ind = E.index(basho)
result = [0 for i in range(N)]
for i in range(N):
    newind = ind + i
    if newind >= N :
        newind -= N
    result[count] = E[newind]
    count += 1
    if count >= N:
        count -= N

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python

from collections import deque
import itertools as it
import sys
import math

sys.setrecursionlimit(10000000)

N, L, T_ = map(int, raw_input().split())

X1 = []
X2 = []
Xs = []
m = {}
mL = {}
mul = T_ / L

for i in range(N):
    X, W = map(int, raw_input().split())
    if W == 1:
        X1.append(X)
    else:
        X2.append(X)
    m[X] = 0
    mL[X] = 0
    Xs.append((X, W))
T = L
if len(X1) != 0 and len(X2) != 0:
    for loop in range(2):
        pos1 = 0
        pos2 = 0
        bias = 0
        sz = len(X2)
        X2 = [X2[-1] - L] + X2 + [X2[0] + L]
        for x in X1:
            while True:
                if X2[pos1 + 1] + bias - x <= 2 * T:
                    pos1 += 1
                else:
                    break
                if pos1 > sz:
                    bias += L
                    pos1 = 1
            while True:
                if X2[pos2 + 1] < x:
                    pos2 += 1
                else:
                    break
            if loop == 0:
                mL[x] = pos1 - pos2 + bias / L * sz
            else:
                mL[(L - x) * (x != 0)] = pos1 - pos2 + bias / L * sz
        X2 = X2[1:-1]
        for i in range(len(X1)):
            X1[i] = (L - X1[i]) * (X1[i] != 0)
        for i in range(len(X2)):
            X2[i] = (L - X2[i]) * (X2[i] != 0)
        X1, X2 = sorted(X2), sorted(X1)
T = T_ % L
if len(X1) != 0 and len(X2) != 0:
    for loop in range(2):
        pos1 = 0
        pos2 = 0
        bias = 0
        sz = len(X2)
        X2 = [X2[-1] - L] + X2 + [X2[0] + L]
        for x in X1:
            while True:
                if X2[pos1 + 1] + bias - x <= 2 * T:
                    pos1 += 1
                else:
                    break
                if pos1 > sz:
                    bias += L
                    pos1 = 1
            while True:
                if X2[pos2 + 1] < x:
                    pos2 += 1
                else:
                    break
            if loop == 0:
                m[x] = pos1 - pos2 + bias / L * sz
            else:
                m[(L - x) * (x != 0)] = pos1 - pos2 + bias / L * sz
        X2 = X2[1:-1]
        for i in range(len(X1)):
            X1[i] = (L - X1[i]) * (X1[i] != 0)
        for i in range(len(X2)):
            X2[i] = (L - X2[i]) * (X2[i] != 0)
        X1, X2 = sorted(X2), sorted(X1)
#print m
ans = [0] * N
for i in range(N):
    X, W = Xs[i]
    if W == 1:
        ans[(i + m[X] + mL[X] * mul) % N] = (X + T) % L
    else:
        ans[(i - m[X] - mL[X] * mul) % N] = (X - T) % L

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

Submission status: Accepted

Solution code:
import math
temp=input().split()
n=int(temp[0])
l=int(temp[1])
t=int(temp[2])
lis = [[int(j) for j in input().split()] for i in range(n)]
cou=0
for i in range(n):
	if lis[i][1]==1:lis[i][0] += t
	else:lis[i][0] -= t
	cou += math.floor(lis[i][0] / l)

li = []
for i in range(n):li.append(lis[i][0] % l)
li.sort()
for i in range(n):
	print(li[(i + cou) % n] % l)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
from bisect import bisect, bisect_left
def inpl(): return list(map(int, input().split()))
N, L, T = inpl()

Fants = []
Bants = []
A = [[0, 0] for _ in range(N)]
P = [-1]*N

for i in range(N):
    x, w = inpl()
    A[i] = (x, w)
    if w == 1:
        Fants.append(x)
        P[i] = (x+T)%L
    else:
        Bants.append(x)
        P[i] = (x-T)%L

B = Bants + [b+L for b in Bants] + [b+2*L for b in Bants]
F = [f-2*L for f in Fants] + [f-L for f in Fants] + Fants
d, m = divmod(T, L)
ans = [-1]*N

for i, (x, w) in enumerate(A):
    if w == 1: #forward
        j = i + 2*d*len(Bants) + (bisect(B, x+2*m) - bisect(B, x))
        ans[j%N] = P[i]
    else:
        j = i - 2*d*len(Fants) - (bisect_left(F, x) - bisect_left(F, x-2*m))
        ans[j%N] = P[i]    

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

Submission status: Accepted

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

s = 0
X = [0] * N
for i in range(N):
    x, w = map(int, input().split())
    x += ((w + 1) % 3 - 1) * T
    # xが0点を通る回数を足す
    s += x // L
    X[i] = x % L

X.sort()
for i in range(N):
    print(X[(i+s) % N])

Submission status: Accepted

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

s = 0
X = [0] * N
for i in range(N):
    x, w = map(int, input().split())
    if w == 1:
        x += T
    else:
        x -= T
    # xが0点を通る回数を足す
    s += x // L
    X[i] = x % L

X.sort()
for i in range(N):
    print(X[(i+s) % N])

Submission status: Accepted

Solution code:
n,l,t=map(int,input().split())
a,cs=[0]*n,0
for i in range(n):
	x,y=map(int,input().split())
	x+=(t if y==1 else -t)
	cs=(cs+x//l)%n
	x%=l
	if x<0:
		x+=l
		cs-=1
	a[i]=x
a.sort()
print('\n'.join([str(a[(i+cs+n)%n]) for i in range(n)]))

Submission status: Accepted

Solution code:
import math
temp=input().split()
N=int(temp[0])
L=int(temp[1])
T=int(temp[2])
XW=[[int(j) for j in input().split()] for i in range(N)]
count=0
for i in range(N):
	if XW[i][1]==1:
		XW[i][0]+=T
	else:
		XW[i][0]-=T
	count+=math.floor(XW[i][0]/L)
newX=[]
for i in range(N):
	newX.append(XW[i][0]%L)
newX.sort()
#print(newX)
for i in range(N):
	print(newX[(i+count)%N]%L)

Submission status: Accepted

Solution code:
import math
temp=input().split()
N=int(temp[0])
L=int(temp[1])
T=int(temp[2])
XW=[[int(j) for j in input().split()] for i in range(N)]
count=0
for i in range(N):
	if XW[i][1]==1:
		XW[i][0]+=T
	else:
		XW[i][0]-=T
	count+=math.floor(XW[i][0]/L)
#
# if XW[0][1]==1:
# 	for i in range(1,N):
# 		if XW[i][0]<XW[0][0]:
# 			count+=int((XW[0][0]-XW[i][0])/L)+1
# else:
# 	for i in range(1,N):
# 		if XW[i][0]>XW[0][0]:
# 			count+=int((XW[i][0]-XW[0][0])/L)+1

#print(count)
#print(len())
newX=[]
for i in range(N):
	newX.append(XW[i][0]%L)
newX.sort()
#print(newX)
for i in range(N):
	print(newX[(i+count)%N]%L)

Submission status: Accepted

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

X = []
W = []
X_after = []
for _ in range(N):
    x, w = list(map(int, input().split()))
    if w == 1:
        x_a = (x + T) % L
    else:
        x_a = (x - T) % L
        x_a = x_a if x_a >= 0 else L + x_a
    X.append(x)
    W.append(w)
    X_after.append(x_a)

n_colide = 0
for i in range(1, N):
    if W[0] == 1 and W[i] == 2:
        dist = X[i] - X[0]
        n_colide += 2 * (T - (dist / 2)) // L + 1
    elif W[0] == 2 and W[i] == 1:
        dist = (L + X[0]) - X[i]
        n_colide += 2 * (T - (dist / 2)) // L + 1

if W[0] == 1:
    num_a0 = n_colide % N
else:
    num_a0 = N - (n_colide % N)

num_a0 = int(num_a0)

x_a0 = X_after[0]
X_after = sorted(X_after)
i = X_after.index(x_a0)
if W[0] == 1 and X_after.count(x_a0) == 2:
    i += 1
X_after = X_after[i-num_a0:] + X_after[:i-num_a0]

for x_a in X_after:
    print(x_a)

Submission status: Accepted

Solution code:
import bisect
from operator import add, sub

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

ope = [None, add, sub]
ants = [tuple(map(int, input().split())) for _ in range(n)]
ants_pos = [ope[w](x, t) % l for x, w in ants]

if n == 1:
    print(ants_pos[0])
    exit()

x0, w0 = ants[0]
crash_cnt = 0
crash_check = (lambda x: t - (x - x0) / 2) if w0 == 1 else (lambda x: t - (l - x + x0) / 2)
for x, w in ants[1:]:
    if w == w0:
        continue
    d = crash_check(x)
    if d >= 0:
        crash_cnt += 2 * d // l + 1

ant_alt0 = (0, 1, -1)[w0] * int(crash_cnt) % n
sorted_pos = sorted(ants_pos)
pos_i = bisect.bisect_left(sorted_pos, ants_pos[0])
if pos_i < n - 1 and sorted_pos[pos_i] == sorted_pos[pos_i + 1] and w0 == 1:
    pos_i += 1
pos0_i = (pos_i - ant_alt0) % n
for pos in sorted_pos[pos0_i:]:
    print(pos)
for pos in sorted_pos[:pos0_i]:
    print(pos)

Submission status: Accepted

Solution code:
# coding: utf-8
import array, bisect, collections, heapq, itertools, math, random, re, string, sys, time
sys.setrecursionlimit(10 ** 7)
INF = 10 ** 20
MOD = 10 ** 9 + 7
 
 
def II(): return int(input())
def ILI(): return list(map(int, input().split()))
def IAI(LINE): return [ILI() for __ in range(LINE)]
def IDI(): return {key: value for key, value in ILI()}
 
 
def solve(N, L, T, pos, dir):
    # 円形だからどんなにぶつかっても1-Nまで順番に並んでいることは変わりない。
    pos_mov = []
    for i in range(1, N + 1):
        if dir[i] == 1:
            pos_mov.append((pos[i] + T) % L)
        elif dir[i] == 2:
            pos_mov.append((pos[i] - T) % L)

    pos_mov.sort()

    count = 0

    for i in range(2, N + 1):
        dif = pos[i] - pos[1]
        if dir[1] == 1:
            if dir[i] == 2:
                if dif <= 2 * T:
                    count += ((2 * T - dif) // L + 1)
        elif dir[1] == 2:
            if dir[i] == 1:
                if (L - dif) <= 2 * T:
                    count += ((2 * T - (L - dif))// L + 1)

    if dir[1] == 1:
        pos1 = (pos[1] + T) % L
        num1 = count % N + 1
    elif dir[1] == 2:
        pos1 = (pos[1] - T) % L
        num1 = -count % N + 1

    if dir[1] == 1:
        ind = max([i for i in range(1, N + 1) if pos_mov[i - 1] == pos1])
    else:
        ind = min([i for i in range(1, N + 1) if pos_mov[i - 1] == pos1])

    ans = []
    for i in range(1, N + 1):
        ans.append(pos_mov[(ind - num1 + i) % N - 1])

    return ans


def main():
    N, L, T = ILI()
    pos = dict()
    dir = dict()
    for i in range(1, N + 1):
        X, W = ILI()
        pos[i] = X
        dir[i] = W

    ans = solve(N, L, T, pos, dir)
    for i in ans:
        print(i)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys


def solve_it_chameleons(n, l, t, x, w):
    initial_color = [i for i in range(n)]

    chameleons = [[x[i], w[i], initial_color[i]] for i in range(n)]
    initial_color_clockwise = [chameleons[i][2] for i in range(n)]

    x0, w0, color0 = chameleons[0]
    for i in range(n):
        if w[i] != w0:
            d = (w0 * (x[i] - x0)) % l
            meet = 0
            if 2 * t >= d:
                meet = (2 * t - d) // l + 1
            color0 += w0 * meet
            color0 %= n

    # The chameleon (let's call him chameleon 0) initially at x0 is at (x0 + w0 * t) % l at the end,
    # Initially, its color is color0 and it changed <meet> times.
    # The final clockwise colors are a translation of the initial clockwise colors.

    x_final = [(x[i] + w[i] * t) % l for i in range(n)]
    x_final.sort()

    # In the special case where chameleon meets just at the end, they swap their colors.
    # The index need to be incremented if he walks clockwise.
    i = x_final.index((x0 + w0 * t) % l)
    if i + 1 < n and x_final[i] == x_final[i + 1]:
        if w0 == 1:
            i += 1
    res = [0] * n
    for k in range(n):
        color = (color0 + k) % n
        res[color] = x_final[(i+k) % n]
    return res


if __name__ == '__main__':

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

    res = solve_it_chameleons(n, l, t, x, w)
    for i in range(n):
        print(res[i])

Submission status: Accepted

Solution code:
import sys

# sys.stdin = open('c2.in')
# sys.stdin = open('gen_c/c10.in')


def solve_it_large(n, l, t, x, w):
    ants = []
    for i in range(n):
        ants.append([x[i], w[i], (x[i] + w[i] * t) % l, i])
    # ants.sort()

    n_intersections = 0
    x0, w0, dest0, i0 = ants[0]
    for x, w, dest, i in ants:
        if w != w0:
            d = (w0 * (x - x0) + l) % l
            intersections = 0
            if 2 * t >= d:
                intersections = (2 * t - d) // l + 1
            n_intersections += intersections

    res = [0] * n
    shift = n_intersections
    for i in range(n):
        res[ants[(i + w0 * shift) % n][3]] = ants[i][2]
    return res


def solve_it_chameleons(n, l, t, x, w):
    initial_color = [i for i in range(n)]

    chameleons = [[x[i], w[i], initial_color[i]] for i in range(n)]
    initial_color_clockwise = [chameleons[i][2] for i in range(n)]

    x0, w0, color0 = chameleons[0]
    for i in range(n):
        if w[i] != w0:
            d = (w0 * (x[i] - x0)) % l
            meet = 0
            if 2 * t >= d:
                meet = (2 * t - d) // l + 1
            color0 += w0 * meet
            color0 %= n

    # The chameleon (let's call him chameleon 0) initially at x0 is at (x0 + w0 * t) % l at the end,
    # Initially, its color is color0 and it changed <meet> times.
    # The final clockwise colors are a translation of the initial clockwise colors.

    x_final = [(x[i] + w[i] * t) % l for i in range(n)]
    x_final.sort()
    i = x_final.index((x0 + w0 * t) % l)
    if i + 1 < n and x_final[i] == x_final[i + 1]:
        if w0 == 1:
            i += 1
    res = [0] * n
    for k in range(n):
        color = (color0 + k) % n
        res[color] = x_final[(i+k) % n]
    return res


if __name__ == '__main__':

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

    res = solve_it_chameleons(n, l, t, x, w)
    for i in range(n):
        print(res[i])

Submission status: Accepted

Solution code:
n,l,t=map(int,raw_input().split())
l*=2
t*=2
x=[None]*(2*n)
w=[None]*(2*n)
for i in xrange(n):
    ex,ew=map(int,raw_input().split())
    x[i]=ex*2;x[i+n]=ex*2+l
    w[i]=ew;w[i+n]=ew
pos=[]
w1=[]
check=False
for i in xrange(n):
    if w[i]==1:
        check=True
        w1.append(i)
        pos.append((x[i]+t)%l)
    else:
        pos.append((x[i]-t)%l)
if not check:
    for i in xrange(n):
        print pos[i]/2
    exit()
for i in xrange(len(w1)):
    if pos.count(pos[w1[i]])==1:
        start=w1[i]
        break
#print start
ans=[-1]*n
cnt=0
sx=x[start]
for i in xrange(start,start+n):
    if w[i]==2:
        nokori=t-(x[i]-sx)/2
        if nokori<0:continue
        cnt+=nokori/(l/2)+1
idx=(start+cnt)%n
#print idx
ans[idx]=pos[start]
pos.sort()
for i in xrange(n):
    if pos[i]==ans[idx]:
        now=i
        break
for i in xrange(idx+1,idx+n):
    ans[i%n]=pos[(now+i-idx)%n]
for i in xrange(n):
    print ans[i]/2

Submission status: Accepted

Solution code:
n,l,t=map(int,raw_input().split())
l*=2
t*=2
x=[None]*(2*n)
w=[None]*(2*n)
for i in xrange(n):
    ex,ew=map(int,raw_input().split())
    x[i]=ex*2;x[i+n]=ex*2+l
    w[i]=ew;w[i+n]=ew
pos=[]
start=-1
check=False
for i in xrange(n):
    if w[i]==1:
        check=True
        start=i
        pos.append((x[i]+t)%l)
    else:
        pos.append((x[i]-t+l)%l)
if not check:
    for i in xrange(n):
        print pos[i]/2
    exit()
"""
for i in xrange(len(w1)):
    if pos.count(pos[w1[i]])==1:
        start=w1[i]
        break
"""
#print start
ans=[-1]*n
cnt=0
sx=x[start]
for i in xrange(start,start+n):
    if w[i]==2:
        nokori=t-(x[i]-sx)/2
        if nokori<0:continue
        cnt+=nokori/(l/2)+1
idx=(start+cnt)%n
#print idx
ans[idx]=pos[start]
pos.sort()
for i in xrange(n-1,-1,-1):
    if pos[i]==ans[idx]:
        now=i
        break
for i in xrange(1,n):
    ans[(idx+i)%n]=pos[(now+i)%n]
for i in xrange(n):
    print ans[i]/2

Submission status: Accepted

Solution code:
n,l,t=map(int,input().split())
x=[]
w=[]
ans=[]
crash=0
for i in range(n):
    xx,ww=map(int,input().split())
    x.append(xx); w.append(ww)
    if w[i]==1: anss=(x[i]+t)%l
    else: anss=(x[i]-t+l)%l
    ans.append(anss)
    if i!=0 and w[i] != w[0]:
        if w[0] == 1: crash += (t-((x[i]-x[0])/2)) // (l/2) + 1
        else: crash += (t-(l-(x[i]-x[0]))/2) // (l/2) + 1

if w[0]==1: num0 =int(crash)%n
else: num0 =int(-crash)%n
nowplace = ans[0]
ans.sort()
num = ans.index(nowplace)
if w[0]==1 and ans.count(nowplace)==2: num += 1
gap = num-num0
for i in range(n):
    i = (i+gap)%n
    print(ans[i])

Submission status: Accepted

Solution code:

# アリ１からNまでの前後関係は不変。つまり、アリ１からNまでの順番は保たれる。
# アリの最終座標の昇順リストを用意して、アリ１からNに対応させればよい。

n,l,t=map(int,input().split())
x=[]
w=[]
ans=[]

crash=0
for i in range(n):
    xx,ww=map(int,input().split())
    x.append(xx); w.append(ww)
    if w[i]==1: anss=(x[i]+t)%l
    else: anss=(x[i]-t+l)%l
    ans.append(anss)
    if i!=0 and w[i] != w[0]:
        if w[0] == 1: crash += (t-((x[i]-x[0])/2)) // (l/2) + 1
        else: crash += (t-(l-(x[i]-x[0]))/2) // (l/2) + 1

# あり１の現在のゼッケン番号num0
if w[0]==1: num0 =int(crash)%n
else: num0 =int(-crash)%n
# あり１の現在地点に対応する昇順リストの番号num
nowplace = ans[0]
ans.sort()
num = ans.index(nowplace)
if w[0]==1 and ans.count(nowplace)==2: num += 1 # ２つ該当する場合の処理
# numがnum0の位置であるように調整したい
gap = num0-num
for i in range(n):
    i = (i-gap)%n
    print(ans[i])

Submission status: Accepted

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

# N,L,T = 3,10,6
# a = [1,2,3]
# b = [2,1,1]

a = []
b = []
for i in range(N):
    an, ve = map(int, input().split(" "))
    a.append(an)
    b.append(ve)

crash = 0

for i in range(1, N):
    if b[0] != b[i]:
        if b[0] == 1:
            crash += (T - ((a[i] - a[0]) / 2)) // (L / 2) + 1
        else:
            crash += (T - (L - (a[i] - a[0])) / 2) // (L / 2) + 1

for i in range(N):
    if b[i] == 1:
        a[i] += T
    else:
        a[i] -= T
    a[i] %= L


if b[0] == 1:
    where = int(crash) % N
else:
    where = int(-crash) % N

nowplace = a[0]

a.sort()

if b[0] == 1:
	where0 = max([i for i in range(N) if a[i] == nowplace])
else:
	where0 = min([i for i in range(N) if a[i] == nowplace])

where0 = (where0 - where) % N

res = a[where0:] + a[:where0]
res = map(str, res)

for i in res:
    print(i)

Submission status: Accepted

Solution code:
# C
N, L, T = map(int, input().split())
X = list()
W = list()
positions = list()
for _ in range(N):
    x, w = map(int, input().split())
    X.append(x)
    W.append(w)
    if w == 1:
        positions.append((x + T) % L)
    else:
        positions.append((x - T) % L)

# find which is the position
cnt_conf = 0
if W[0] == 1:
    for i in range(N):
        if W[i] != W[0]:
            cnt_conf += (2*T - (X[i] - X[0])) // L + 1
    n0 = cnt_conf % N
    p0 = (X[0] + T) % L
else:
    for i in range(N):
        if W[i] != W[0]:
            cnt_conf += (2*T - (X[0] + L - X[i])) // L + 1
    n0 = -cnt_conf % N
    p0 = (X[0] - T) % L

positions.sort()

# find index
if W[0] == 1:
    num = max([n for n in range(N) if positions[n]==p0])
else:
    num = min([n for n in range(N) if positions[n]==p0])

for i in range(N):
    print(positions[(num - n0 + i) % N])

Submission status: Accepted

Solution code:
n, l, t = [int(x) for x in raw_input().split()]


def inp():
    x, w = [int(x) for x in raw_input().split()]
    return x, (1 if w == 1 else -1)

ants = [inp() for _ in xrange(n)]
ad = {
    1: [],
    -1: []
}
for i, (x, w) in enumerate(ants):
    ad[w].append(i)

m, r = divmod(t, l)

a0x, a0w = ants[0]
n_d = len(ad[-a0w]) * m * 2
n_e = 0
for anti in ad[-a0w]:
    aix, aiw = ants[anti]
    r2 = r * 2
    m1 = ((aix - a0x) * a0w) % (2 * l)
    if m1 < r2:
        n_d += 1
    elif m1 == r2:
        n_e += 1
    m2 = ((aix + l - a0x) * a0w) % (2 * l)
    if m2 < r2:
        n_d += 1
    elif m2 == r2:
        n_e += 1

nantsx = [(x + w * r) % l for x, w in ants]
andfx = nantsx[0]
nantsx.sort()

lb = 0
ub = n - 1
while ub != lb:
    mid = (lb + ub) / 2
    if nantsx[mid] == andfx:
        lb = ub = mid
        break
    elif nantsx[mid] < andfx:
        lb = mid + 1
    else:
        ub = mid - 1

while lb >= 1 and nantsx[lb - 1] == andfx:
    lb -= 1
while ub < n - 1 and nantsx[ub + 1] == andfx:
    ub += 1

if a0w == 1:
    di = lb - n_d
else:
    di = ub + n_d

for i in xrange(di, di + n):
    print(nantsx[i % n])

Submission status: Accepted

Solution code:
import math
temp=input().split()
N=int(temp[0])
L=int(temp[1])
T=int(temp[2])
XW=[[int(j) for j in input().split()] for i in range(N)]
count=0
for i in range(N):
	if XW[i][1]==1:
		XW[i][0]+=T
	else:
		XW[i][0]-=T
	count+=math.floor(XW[i][0]/L)
"""
if XW[0][1]==1:
	for i in range(1,N):
		if XW[i][0]<XW[0][0]:
			count+=int((XW[0][0]-XW[i][0])/L)+1
else:
	for i in range(1,N):
		if XW[i][0]>XW[0][0]:
			count+=int((XW[i][0]-XW[0][0])/L)+1
"""
#print(count)
#print(len())
newX=[]
for i in range(N):
	newX.append(XW[i][0]%L)
newX.sort()
#print(newX)
for i in range(N):
	print(newX[(i+count)%N]%L)

Submission status: Runtime Error

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

ant0=(X2[0],col)

X2.sort()

x=X2.index(ant0[0])


for i in range(x-col-N,x-col):
    print(round(X2[i]))

Submission status: Runtime Error

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:
        assert False
        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: Runtime Error

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:
        assert False
        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: Runtime Error

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:
        assert False
        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: Runtime Error

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

arr = []
for i in range(n):
    x, w = map(int, input().split())

    if w == 1:
        arr.append((x+t) % l)
        s += (x+t) // l
    else: # W == 2:
        arr.append((x-t) % l)
        s += (x-t) // l

arr.sort()
s %= n
arr = arr[s:] + arr[:s]
print(*[i for i in arr], sep='\n')

Submission status: Runtime Error

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 = []
    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()
    count %= N
    ans = position[count:] + position[:count]
    for i in range(N):
        print(ans[i])

Submission status: Runtime Error

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 = []
    cnt = 0
    for i in range(N):
        x,w = map(int, readline().split())
        if w==1:
        	cnt += (x+T)//L
            position.append((x+T)%L)
        else:
            if x-T<0:
                cnt += (x-T)//L
            position.append((x-T)%L)
    position.sort()
    cnt %= N
    ans = position[cnt:] + position[:cnt]
    for i in range(N):
        print(ans[i])

Submission status: Runtime Error

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 = []
    cnt = 0
    for i in range(N):
        x,w = map(int, readline().split())
        if w==1:
        	cnt += (x+T)//L
            position.append((x+T)%L)
        else:
            if x-T<0:
                cnt += (x-T)//L
            position.append((x-T)%L)
    position.sort()
    cnt %= N
    ans = position[count:] + position[:count]
    for i in range(N):
        print(ans[i])