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

Solution (Python):
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
    
    s += x // L
    X[i] = x % L

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

Solution (Python):
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
    
    s += x // L
    X[i] = x % L

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

Solution (Python):
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)]))

Solution (Python):
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()

for i in range(N):
	print(newX[(i+count)%N]%L)

Solution (Python):
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()

for i in range(N):
	print(newX[(i+count)%N]%L)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):

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

Solution (Python):
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

    
    
    

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

Solution (Python):
import sys





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

    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

    
    
    

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

Solution (Python):
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

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

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

Solution (Python):
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
"""

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

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

Solution (Python):
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])

Solution (Python):




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 = num0-num
for i in range(n):
    i = (i-gap)%n
    print(ans[i])

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





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)

Solution (Python):

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)


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


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

Solution (Python):
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])

Solution (Python):
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
"""


newX=[]
for i in range(N):
	newX.append(XW[i][0]%L)
newX.sort()

for i in range(N):
	print(newX[(i+count)%N]%L)