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())


ants = []
collision = 0
for _ in range(N):
    X, W = map(int, input().split())
    if W == 1:
        collision += (X+T) // L
        x1 = (X+T) % L
    else:
        collision += (X-T) // L
        x1 = (X - T) % L
    ants.append(x1)

collision %= N
ants.sort()
ants = ants[collision:] + ants[:collision]
for ant in ants:
    print(ant)

Submission status: Accepted

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[i] = 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: Accepted

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)
    count += c
# 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)
ants_d.rotate(-count)
# print(ants_d)
for ant in ants_d:
    print( (ant[0]) % l )

Submission status: Accepted

Solution code:
N, L, T = map(int, input().split())
ants = []
touch = 0  # すべての蟻が0を通る合計数

for i in range(N):
    x, w = map(int, input().split())
    if w == 1:  # 時計回り
        touch += (x + T) // L  # 0を通る回数
        x1 = (x + T) % L       # 最終的な座標
    else:
        touch += (x - T) // L  # 0を通る回数
        x1 = (x - T) % L
    ants.append(x1)
touch = touch % N  # 0にいた蟻のindex
ants.sort()
ants = ants[touch:]+ants[:touch]

print(" ".join(map(str, ants)))

Submission status: Accepted

Solution code:
def resolve():
    n, l, t = map(int, input().split())
    lx, lw = [], []
    while True:
        try:
            x, w = map(int, input().split())
            lx.append(x)
            lw.append(w)
        except EOFError:
            break
    cnt = 0
    zero = 0
    x0 = lx[0]
    if lw[0] == 1:
        for i in range(1, n):
            if lw[i] == 2 and t * 2 >= lx[i] - lx[0]:
                cnt += (t * 2 - (lx[i] - lx[0])) // l + 1
        for i in range(n):
            if lw[i] == 1:
                lx[i] = (lx[i] + t) % l
            else:
                lx[i] = (lx[i] - t) % l
        slx = sorted(lx)
        for i in range(n):
            if (x0 + t) % l == slx[i]:
                zero = (i - cnt) % n
        for i in range(n):
            print(slx[(zero + i) % n])
    else:
        for i in range(1, n):
            if lw[i] == 1 and t * 2 >= l + lx[0] - lx[i]:
                cnt += (t * 2 - (l + lx[0] - lx[i])) // l + 1
        for i in range(n):
            if lw[i] == 1:
                lx[i] = (lx[i] + t) % l
            else:
                lx[i] = (lx[i] - t) % l
        slx = sorted(lx)
        for i in range(n-1, -1, -1):
            if (x0 - t) % l == slx[i]:
                zero = (i + cnt) % n
        for i in range(n):
            print(slx[(zero + i) % n])
resolve()

Submission status: Accepted

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:
                i+=1
                break
            else:
                break
for j in ans[i:]+ans[:i]:
    print(j)

Submission status: Accepted

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)]
y0 = Y[0]
Y.sort()

# 番号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

i = Y.index(y0)

Y += Y

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

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

Submission status: Accepted

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)%n:] + final_pos[:(cnt-counter_cnt)%n], sep='\n')

Submission status: Accepted

Solution code:
import sys
from collections import deque, defaultdict
import copy
import bisect
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 9)
import math

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

after = []
rot = 0
for i in range(N):
	if XW[i][1] == 1:
		rot += 1
		after.append((XW[i][0] + T) % L)
	else:
		rot -= 1
		after.append((XW[i][0] - T) % L)
after.sort()
rot *= T
rot = rot % (L*N)
rot_base = 0
for i in range(N):
	rot_base += after[i] - XW[i][0]
rot_base = rot_base % (L*N)
rot_num = (rot - rot_base) // L
rot_num = rot_num % N
after=after*2
for i in range(N):
	print(after[i + rot_num])

Submission status: Accepted

Solution code:
N, L, T = map(int, input().split())
n = (map(int, input().split()) for _ in range(N))
t = [X + (0, T, -T)[W] for X, W in n]
l = sorted(i % L for i in t)
s = sum(i // L for i in t) % N
for i in l[s:] + l[:s]: print(i)

Submission status: Accepted

Solution code:
N, L, T = map(int, input().split())
n = [list(map(int, input().split())) for _ in range(N)]
t = [X + (0, T, -T)[W] for X, W in n]
l = sorted(i % L for i in t)
s = sum(i // L for i in t) % N
for i in l[s:] + l[:s]: print(i)

Submission status: Accepted

Solution code:
from math import floor
n,l,t = map(int,input().split())
ants = []
touch = 0

for i in range(n):
    x, w = map(int,input().split())
    if w == 1:
        touch += (x + t) // l
        x1 = (x + t) % l
    else:
        touch += (x - t) // l
        x1 = (x - t) % l
    ants.append(x1)
touch = touch % n
ants.sort()
ants = ants[touch:]+ants[:touch]

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

Submission status: Accepted

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

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])

Submission status: Accepted

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

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

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(sorted(collisions), T % L)

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

Submission status: Accepted

Solution code:
#input
#N ari  L nagasa T byou
#X ari iti W muki
import numpy as np
N,L,T = map(int,input().split())
ari_list = []
for i in range(N):
    z = list(map(int,input().split()))
    ari_list.append(z)
#print(ari_list)
counter = 0

#syori

for i in range(N):
    if ari_list[i][1] == 1:
        enzan = 1
    else:
        enzan = -1
    m = ari_list[i][0] + T * enzan
    m_kiri = m % L
    ari_list[i][0] = m_kiri 
    counter = counter - (m-m_kiri)/L

#print(counter)
#sort

sort_list = []
for i in range(N):
    sort_list.append(ari_list[i][0])
sort_list.sort()
answer_list = np.roll(sort_list,int(counter))
for i in answer_list:
    print(i)

Submission status: Accepted

Solution code:
from bisect import bisect
n, l, t = map(int, input().split())
ants = [list(map(int, input().split())) for _ in range(n)]
bnts = []
diff = []

for i in range(n):
	x, w = ants[i][0], 3 - 2*ants[i][1]
	bnts.append((x + t*w) % l)
	if i == 0:
		zero = bnts[-1]
	if ants[i][1] != ants[0][1]:
		if ants[0][1] == 1:
			diff.append(x - ants[0][0])
		else:
			diff.append(l - (x - ants[0][0]))

bnts.sort()
num = 0
quo, mod = t//l, t%l
num += quo * len(diff) * 2
diff.sort()
diff += [d+l for d in diff]
num += bisect(diff, mod*2)
num %= n
for i in range(n):
	if bnts[i] == zero:
		if ants[0][1] == 1:
			true_zero = (i-num) % n
		else:
			if i < n-1:
				if bnts[i+1] == zero:
					num -= 1
			true_zero = (i+num) % n

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

Submission status: Accepted

Solution code:
from bisect import bisect_left, bisect
n, l, t = map(int, input().split())
ants = [list(map(int, input().split())) for _ in range(n)]
bnts = []
diff = []

for i in range(n):
	x, w = ants[i][0], 3 - 2*ants[i][1]
	bnts.append((x + t*w) % l)
	if i == 0:
		zero = bnts[-1]
	if ants[i][1] != ants[0][1]:
		if ants[0][1] == 1:
			diff.append(x - ants[0][0])
		else:
			diff.append(l - (x - ants[0][0]))

bnts.sort()
num = 0
quo, mod = t//l, t%l
num += quo * len(diff) * 2
diff.sort()
diff += [d+l for d in diff]
#num += bisect_left(diff, mod*2)
num += bisect(diff, mod*2)
num %= n
for i in range(n):
	if bnts[i] == zero:
		if ants[0][1] == 1:
			true_zero = (i-num) % n
		else:
			if i < n-1:
				if bnts[i+1] == zero:
					#pass
					num -= 1
			true_zero = (i+num) % n

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import bisect
import sys


def input():
    return sys.stdin.readline()[:-1]

# N = int(input())
# A = [int(x) for x in input().split()]
# a, b, c = map(int, input().split())
# name1 = str(input())
# alph = {"A": 1, "B": 2, "C": 3, "D": 4, "E": 5}
# b = list(map(lambda x: math.ceil(x/10)*10, a))


n, l, t = map(int, input().split())
pos = []
count = 0
for i in range(n):
    x, w = map(int, input().split())
    pos.append((x+t*(3-2*w)) % l)
    count += (x+t*(3-2*w))//l
pos.sort()
count %= n
ans = pos[count:]+pos[:count]
for i in ans:
    print(i)

Submission status: Accepted

Solution code:
N, L, T = map(int, input().split())
Xs, Ws = [], []
for _ in range(N):
    X, W = map(int, input().split())
    Xs.append(X)
    Ws.append(W)

nums = []
X0, W0 = Xs[0], Ws[0]
for X, W in zip(Xs[1:], Ws[1:]):
    if W0 == W:
        nums.append(0)
    else:
        num = T//L * 2
        dist = (X-X0)%L if W0 == 1 else (X0-X)%L
        if T%L >= dist/2 + L/2:
            num += 2
        elif T%L >= dist/2:
            num += 1
        nums.append(num)
sumNum = sum(nums)

ZekkenAnt0 = sumNum%N if W0 == 1 else (-sumNum)%N
YZekkenAnt0 = (X0+T)%L if W0 == 1 else (X0-T)%L

Ys = [(X+T)%L if W == 1 else (X-T)%L for X, W in zip(Xs, Ws)]
Ys.sort()

iZekkenAnt0 = N-1-Ys[::-1].index(YZekkenAnt0) if W0 == 1 else Ys.index(YZekkenAnt0)
iZekken0 = (iZekkenAnt0-ZekkenAnt0)%N

anss = Ys[iZekken0:] + Ys[:iZekken0]
print('\n'.join(map(str, anss)))

Submission status: Accepted

Solution code:
N,L,T = map(int, input().split())
X = [0]*N
W = [0]*N
for n in range(N):
    X[n],W[n] = map(int, input().split())
index = 0
#after T
for n in range(N):
    X[n] += ((-1)**(W[n]+1))*T
    index += X[n]//L
    X[n] %= L
index %= N
X.sort()
X = X[index:] + X[:index] #No.1 wo hajimeni mottekuru.
for n in range(N):
    print(X[n])

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)]
D=0
for i in range(N):
    X[i],W[i]=map(int,input().split())
    W[i]=-2*W[i]+3
    D+=(X[i]+T*W[i])//L
D%=N
Y=sorted([((T*W[i])+X[i])%L for i in range(N)])
for i in range(N):
    print(Y[(D+i)%N])

Submission status: Accepted

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

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

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

e.sort()


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

Submission status: Accepted

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

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

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

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

st = 0
for i in range(N):
    if ants2.count(ants2[i]) == 1:
        st = i
        break

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

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

st = 0
for i in range(N):
    if ants2.count(ants2[i]) == 1:
        st = i
        break

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

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

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

Submission status: Accepted

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

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

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

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

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

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

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

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

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

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

    for i in range(n):
        if first_ant_direction != xw[i][1]:

            if t <= ((xw[i][0] - first_ant_position0) % l )/ 2:
                hit_count = 0
            else:
                dt =((xw[i][0] - first_ant_position0) % l )
                hit_count = 1 + int((2 * t - dt - 0.001) // l)
            first_ant_number = (first_ant_number + hit_count) % n
            if first_ant_number == 0:
                first_ant_number = n

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

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

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

main()

Submission status: Accepted

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

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

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

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

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

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

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

Submission status: Accepted

Solution code:
import numpy as np

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

X0 = np.zeros(N, dtype=np.int)
W = np.zeros(N, dtype=np.int)
for i in range(N):
    X0[i], W[i] = map(np.int, input().split())

X = X0 + T * (3 - 2*W) #(2*(1.5 - W))
count = np.sum(X // L)	#x=0を超えた蟻の数。0の蟻がどこまでズレたかがわかる。
#print(count)
count %= N

X %= L
X.sort()

for x in X[count:]:
    print(x)
for x in X[:count]:
    print(x)

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline()
def inpl(): return [int(i) for i in input().split()]

N, L, T = inpl()
Ant = []
ctr = 0
for _ in range(N):
    X, W = inpl()
    Ant.append((X + T*(3-2*W))%L)
    ctr += (X + T*(3-2*W))//L
Ant.sort()
ctr %= N
ans = Ant[ctr:] + Ant[:ctr]
for i in ans:
    print(i)

Submission status: Accepted

Solution code:
N,L,T=map(int,input().split())
X=[]
p=0
for i in range(N):
  x,w=map(int,input().split())
  if w==1:
    x+=T
  elif w==2:
    x-=T
  p+=x//L
  X.append(x%L)
X.sort()
p%=N
for i in range(N):
  print(X[(i+p)%N])

Submission status: Accepted

Solution code:
n,l,t =  map(int,input().split())
x = [list(map(int,input().split())) for i in range(n)]
las = [0]*n
for i in range(n):
  las[i] = (x[i][0]+(t if x[i][1]==1 else -t))%l
han = []
for i in range(1,n):
  if x[i][1] != x[0][1]:
    if x[0][1] ==1:
      han.append(x[i][0]-x[0][0])
    else:
      han.append(l-x[i][0]+x[0][0])
su = 0
t*=2
su += (len(han))*(t//l)
t%=l
for i in han:
  if t> i:
    su+=1
if x[0][1] == 2:
  su=(-su)%n
else:
  su%=(n)
ii = las[0]
las.sort()
basyo = las.index(ii)
for i in range(basyo+1,n):
  if las[basyo] == las[i]:
    if x[0][1] == 2:
      basyo+=1
  break
las.extend(las)
ans = [0]*n
z = 0
for i in range(basyo,basyo+n):
  ans[(su+z)%n] = las[i]
  z += 1
for i in ans:
  print(i)

Submission status: Accepted

Solution code:
import math
from bisect import bisect_left,bisect_right
N,L,T=map(int,input().split())
table=[[0,0] for i in range(N)]
for i in range(N):
    x,y=map(int,input().split())
    table[i][0]=x
    table[i][1]=y
count=0
l=table[0][0]
w=table[0][1]
P=[0]*N
for i in range(N):
    if table[i][1]==1:
        P[i]=(table[i][0]+T)%L
    else:
        P[i]=(table[i][0]-T)%L
if w==1:
    for i in range(1,N):
        if table[i][1]==2:
            if (2*T-table[i][0]+l)>=0:
                count+=math.floor((2*T-table[i][0]+l)/L)+1
    count=count%N
if w==2:
    for i in range(1,N):
        if table[i][1]==1:
            if (2*T-(L-table[i][0]+l))>=0:
                count+=math.floor((2*T-(L-table[i][0]+l))/L)+1
            #print(count)
    count=(N-count)%N
a=P[0]
P.sort()
s=P.index(a)
ans=[0]*N
if w==1 and s<N-1 and P[s]==P[s+1]:
    s+=1
for i in range(N):
    ans[(count+i)%N]=P[(s+i)%N]

for i in ans:
    print(i)

Submission status: Accepted

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

xs = []
for x,w in src:
    dx = T if w==1 else -T
    xs.append((x+dx) % L)
xs.sort()

if N == 1:
    print(xs[0])
    exit()

x0,w0 = src[0]
k0 = 0
for x,w in src:
    if x == x0: continue
    if w == w0: continue
    if w0 == 1:
        dist = (x-x0) % L
    else:
        dist = (x0-x) % L
    if 2*T >= dist:
        k0 += 1 + (2*T-dist)//L

newx0 = (x0+T)%L if w0==1 else (x0-T)%L
i0 = xs.index(newx0)
if w0 == 1 and i0+1 < N and xs[i0] == xs[i0+1]:
    i0 += 1
i0 += (k0 if w0==2 else -k0)
i0 %= N

for i in range(i0,i0+N):
    print(xs[i%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
	a[i]=x
a.sort()
print('\n'.join([str(a[(i+cs)%n]) for i in range(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
	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 sys
N, L, T = [int(x) for x in input().strip().split(" ")]

xys = []
candidates = []
for line in sys.stdin:
    x, y = line.strip().split(" ")
    x, y = int(x), int(y)
    xys.append((x,y))
    candidates.append((x + (1 if y == 1 else -1) * T)%L)

x0, y0 = xys[0]

dxs = []
pr_x = None
counter = 0
for x, y in xys[1:]:
    if y != y0:
        if pr_x == None:
            if y0 == 1:
                a = (x - x0)
        else:
            dxs.append(x - pr_x)
        pr_x = x
        counter += 1

if pr_x == None:
    for x in candidates:
        print(x)
    sys.exit()
if y0 == 2:
    a = (L - pr_x) + x0

ree = (2*T)%L
num_round = (2*T)//L
ree = ree - a
if ree <= 0:
    max_i = 0
else:
    for i, dx in enumerate(dxs if y0 == 1 else dxs[::-1]):
        ree = ree - dx
        if ree <= 0:
            max_i = i + 1
            break
    else:
        max_i = counter

if ree == 0 and y0 == 2:
    max_i += 1

c_n = num_round * counter + max_i

rep = ( 
        ((1 if y0 == 1 else -1) * (c_n % N) % N),
        ((x0 + (1 if y0 == 1 else -1) * (T % L)) % L)
        )


candidates = sorted(candidates)

for i, c in enumerate(candidates):
    if c == rep[1]:
        start = i - rep[0]
        break

for j in range(N):
    print(candidates[(start + j) % N])

Submission status: Accepted

Solution code:
from bisect import bisect_left,bisect
n,l,t = (int(i) for i in input().split())
x,y,c = [[int(i) for i in input().split()]],[0],0
ans = [(x[0][0]-t)%l if x[0][1]-1 else (x[0][0]+t)%l]
ans2 = ans[0]
for _ in range(n-1):
	a,b = (int(i) for i in input().split())
	x.append([a,b])
	if b!=x[0][1]: c+=1
	y.append(c)
	if b-1: ans.append((a-t)%l)
	else: ans.append((a+t)%l)
ans.sort()
if x[0][1]-1: ans3 = bisect_left(ans,ans2)
else: ans3 = bisect(ans,ans2)-1
num = int(t/(l/2))
if x[0][1]-1:
	p = (-(t-num*(l/2))*2+x[0][0])%l
	d = (y[-1]*num+y[-1]-y[bisect_left(x,[p,0])-1])%n
else:
	p = ((t-num*(l/2))*2+x[0][0])
	d = (y[-1]*num+y[bisect_left(x,[p,3])-1])%n
if x[0][1]-1: d = -d
for i in range(n): print(ans[(ans3-d+i)%n])