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())
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 = ["" for i in range(N)]
for i in range(N):
    y[i] = (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

z = ["" for i in range(N)]

for i in range(N):
    z[(num+i) % N] = y[i]

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

Submission status: Wrong Answer

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]:
      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: Wrong Answer

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][1]-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: Wrong Answer

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][1]-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]:
    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: Wrong Answer

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][1]-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
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: Wrong Answer

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][1]-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
su%=(n)
ii = las[0]
las.sort()
basyo = las.index(ii)
for i in range(basyo+1,n):
  if las[basyo] == las[i]:
    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: Wrong Answer

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][1]-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
su%=(n)
ii = las[0]
las.sort()
basyo = las.index(ii)
for i in range(basyo,n):
  if las[basyo] == las[i]:
    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: Wrong Answer

Solution code:
import math
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:
            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:
            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
for i in range(N):
    ans[(count+i)%N]=P[(s+i)%N]
for i in ans:
    print(i)

Submission status: Wrong Answer

Solution code:
import math
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:
            count+=math.floor((2*T-table[i][0]+l)/L)+1
    count=count%N
    ans=[0]*N
    for i in range(N):
        ans[(count+i)%N]=P[i]
if w==2:
    for i in range(1,N):
        if table[i][1]==1:
            count+=math.floor((2*T-(L-table[i][0]+l))/L)+1
            #print(count)
    count=(N-count)%N
    ans=[0]*N
    for i in range(N):
        ans[(count+i)%N]=P[i]
for i in ans:
    print(i)

Submission status: Wrong Answer

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 x0 == x: continue
    if w0 == w: continue
    if w0 == 1:
        dist = (x-x0) % L
    else:
        dist = (x0-x) % L
    if 2*T > dist:
        k0 += 1 + (2*T-dist-1)//L

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

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

newx1 = (x1+T)%L if w1==1 else (x1-T)%L
i1 = xs.index(newx1)
i1 += (k1 if w1==2 else -k1)
i1 %= N

if (i1-i0)%N >= 2:
    i0 += 1

for i in range(i0,i0+N):
    print(xs[i%N])

Submission status: Wrong Answer

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 x0 == x: continue
    if w0 == w: continue
    if w0 == 1:
        dist = (x-x0) % L
    else:
        dist = (x0-x) % L
    if 2*T > dist:
        k0 += 1 + (2*T-dist-1)//L

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

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

newx1 = (x1+T)%L if w1==1 else (x1-T)%L
i1 = xs.index(newx1)
i1 += (k1 if w1==2 else -k1)
i1 %= N

if (i1-i0)%N == 2:
    i0 += 1

for i in range(i0,i0+N):
    print(xs[i%N])

Submission status: Wrong Answer

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

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

newx0 = (x0+T)%L if w0==1 else (x0-T)%L
i0 = xs.index(newx0)

if (w0+k)%2==0 and i0+1 < N and xs[i0]==xs[i0+1]:
    i0 += 1
i0 += (k if w0==2 else -k)
i0 %= N

for i in range(i0,i0+N):
    print(xs[i%N])

Submission status: Wrong Answer

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

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

newx0 = (x0+T)%L if w0==1 else (x0-T)%L
i0 = xs.index(newx0)

if (w0+k)%2==0 and i0+1 < N and xs[i0]==xs[i0+1]:
    i0 += 1
i0 += (k if w0==2 else -k)
i0 %= N

for i in range(i0,i0+N):
    print(xs[i%N])

Submission status: Wrong Answer

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

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

newx0 = (x0+T)%L if w0==1 else (x0-T)%L
i0 = xs.index(newx0)

if (w0+k)%2==0 and i0+1 < N and xs[i0]==xs[i0+1]:
    i0 += 1
i0 += (k if w0==2 else -k)
i0 %= N

for i in range(i0,i0+N):
    print(xs[i%N])

Submission status: Wrong Answer

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

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

newx0 = (x0+T)%L if w0==1 else (x0-T)%L
i0 = xs.index(newx0)

if (w0+k)%2==0 and i0+1 < N and xs[i0]==xs[i0+1]:
    i0 += 1
i0 += (k if w0==2 else -k)
i0 %= N

for i in range(i0,i0+N):
    print(xs[i%N])

Submission status: Wrong Answer

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

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

newx0 = (x0+T)%L if w0==1 else (x0-T)%L
i0 = xs.index(newx0)

if (w0+k)%2==0 and i0+1 < N and xs[i0]==xs[i0+1]:
    i0 += 1
i0 += (k if w0==2 else -k)
i0 %= N

for i in range(i0,i0+N):
    print(xs[i%N])

Submission status: Wrong Answer

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

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

newx0 = (x0+T)%L if w0==1 else (x0-T)%L
i0 = xs.index(newx0)

if w0==2 and i0+1 < N and xs[i0]==xs[i0+1]:
    i0 += 1
i0 += (k if w0==2 else -k)
i0 %= N

for i in range(i0,i0+N):
    print(xs[i%N])

Submission status: Wrong Answer

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

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

i0 = k%L if w0==1 else -k%L
for i in range(i0,i0+N):
    print(xs[i%N])

Submission status: Wrong Answer

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

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

i0 = k%L if w0==1 else -k%L
for i in range(i0,i0+N):
    print(xs[i%N])

Submission status: Wrong Answer

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

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

i0 = k%L if w0==1 else -k%L
for i in range(i0,i0+N):
    print(xs[i%N])

Submission status: Wrong Answer

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)
#    if (x + (1 if y == 1 else -1) * T)%L == 52648:
#        print(x, y)

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

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):
#    candidates[(start + j) % N + 1]
    print(candidates[(start + j) % N])

Submission status: Wrong Answer

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

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)
        )
result = []

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: Wrong Answer

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

XW=[]
for _ in range(N):
    XW.append(list(map(int,input().split())))
    
#1->1 2->-1
def change(n):
    return -n*2+3
    
end=[]

for x,w in XW:
    end.append((x+(T%L)*change(w))%L)
    
cl=[XW[i][0] for i in range(N) if XW[i][1]!=XW[0][1]]

ex=0
for c in cl:
    temp1=(c-XW[0][0])*change(XW[0][1])
    if temp1<0: temp1+=L
    temp2=T*2-temp1
    if temp2>=0:
        ex += (temp2//L+1)*change(XW[0][1])
        
ex%=N
        
for e in end[-ex:]:
    print(e)
for e in end[:-ex]:
    print(e)

Submission status: Wrong Answer

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

XW=[]
for _ in range(N):
    XW.append(list(map(int,input().split())))
    
#1->1 2->-1
def change(n):
    return -n*2+3
    
end=[]

for x,w in XW:
    end.append((x+(T%L)*change(w))%L)
    
cl=[XW[i][0] for i in range(N) if XW[i][1]!=XW[0][1]]

ex=0
for c in cl:
    temp1=(c-XW[0][0])*change(XW[0][1])
    if temp1<0: temp1+=L
    temp2=T*2-temp1
    if temp2>=0:
        ex += (temp2//L+1)*change(XW[0][1])
        
for e in end[-ex%N:]:
    print(e)
for e in end[:-ex%N]:
    print(e)

Submission status: Wrong Answer

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

XW=[]
for _ in range(N):
    XW.append(list(map(int,input().split())))
    
#1->1 2->-1
def change(n):
    return -n*2+3
    
end=[]

for x,w in XW:
    end.append((x+(T%L)*change(w))%L)
    
cl=[XW[i][0] for i in range(N) if XW[i][1]!=XW[0][1]]

ex=0
for c in cl:
    temp=T*2-((c-XW[0][0])*change(XW[0][1])+L*(XW[0][1]==2))
    if temp>=0:
        ex += ((temp//L+1)*change(XW[0][1])+N*(XW[0][1]==2))
        
for e in end[-ex%N:]:
    print(e)
for e in end[:-ex%N]:
    print(e)

Submission status: Wrong Answer

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

XW=[]
for _ in range(N):
    XW.append(list(map(int,input().split())))
    
#1->1 2->-1
def change(n):
    return -n*2+3
    
end=[]

for x,w in XW:
    end.append((x+(T%L)*change(w))%L)
    
cl=[XW[i][0] for i in range(N) if XW[i][1]!=XW[0][1]]

ex=0
for c in cl:
    temp=T*2-((c-XW[0][0])*change(XW[0][1])+L*(XW[0][1]==2))
    if temp>=0:
        ex += (temp//L+1)*change(XW[0][1])
        
for e in end[-ex%N:]:
    print(e)
for e in end[:-ex%N]:
    print(e)

Submission status: Wrong Answer

Solution code:
I=lambda:map(int,input().split())
n,l,t=I()
g=[0]*n
x,w=I()
g[0]=(x-t*(w>1or-1))%l
f=w
s=[]
for i in range(1,n):
    x,w=I()
    g[i]=(x-t*(w>1or-1))%l
    if f!=w:s.append(g[i])
c=-1
if f>1:
    for u in s:
        if n-u+g[0]>t/2:c+=1
    for i in range(n):
        print(g[(i-c)%n])
else:
    for u in s:
        if u-g[0]>t/2:c+=1
    for i in range(n):
        print(g[(i+c)%n])

Submission status: Wrong Answer

Solution code:
I=lambda:map(int,input().split())
n,l,t=I()
g=[0]*n
x,w=I()
g[0]=(x-t*(w>1or-1))%l
f=w
s=[]
for i in range(1,n):
    x,w=I()
    g[i]=(x-t*(w>1or-1))%l
    if f!=w:s.append(g[i])
c=1
if f>1:
    for u in s:
        if n-u+g[0]>t/2:c+=1
    for i in range(n):
        print(g[(i+c)%n])
else:
    for u in s:
        if u-g[0]>t/2:c+=1
    for i in range(n):
        print(g[(i-c)%n])

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left
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()
ans3 = bisect_left(ans,ans2)
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])

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left
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()
ans3 = bisect_left(ans,ans2)
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[max(0,bisect_left(x,[p,0])-1)])%n
else:
	p = ((t-num*(l/2))*2+x[0][0])
	d = (y[-1]*num+y[max(0,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])

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left
n,l,t = (int(i) for i in input().split())
x,y,c = [[int(i) for i in input().split()]],[0],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)
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[max(0,bisect_left(x,[p,0])-1)])%n
else:
	p = ((t-num*(l/2))*2+x[0][0])
	d = (y[-1]*num+y[max(0,bisect_left(x,[p,3])-1)])%n
if x[0][1]-1: d=-d
for i in range(n):
	if x[(i-d)%n][1]-1: print((x[(i-d)%n][0]-t)%l)
	else: print((x[(i-d)%n][0]+t)%l)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left
n,l,t = (int(i) for i in input().split())
x,y,c = [[int(i) for i in input().split()]],[0],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)
num = int(t/(l/2))
p = ((t-num*(l/2))*2+x[0][0])
d = (y[-1]*num+y[max(0,bisect_left(x,[p,0])-1)])%n
if x[0][1]-1: d=-d
for i in range(n):
	if x[(i-d)%n][1]-1: print((x[(i-d)%n][0]-t)%l)
	else: print((x[(i-d)%n][0]+t)%l)

Submission status: Wrong Answer

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 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: Wrong Answer

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

    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 ) // L + 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 ) // L + 1
count = count % N
if count < 0:
    count += N
count = int(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: Wrong Answer

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())
T %= L

X1 = []
X2 = []
Xs = []
m = {}

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
    Xs.append((X, W))
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
            #print x, pos1, pos2, bias
            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)

ans = [0] * N
for i in range(N):
    X, W = Xs[i]
    if W == 1:
        ans[(i + m[X]) % N] = (X + T) % L
    else:
        ans[(i - m[X]) % N] = (X - T) % L

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

Submission status: Wrong Answer

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())
T %= L

X1 = []
X2 = []
Xs = []
m = {}

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
    Xs.append((X, W))
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 = X2, X1

ans = [0] * N
for i in range(N):
    X, W = Xs[i]
    if W == 1:
        ans[(i + m[X]) % N] = (X + T) % L
    else:
        ans[(i - m[X]) % N] = (X - T) % L

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

Submission status: Wrong Answer

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

print((il[len(il)-1][0] + T*(-1)**(il[len(il)-1][1]-1))%L)
for i in range(len(il)-1):
    print((il[i][0] + T*(-1)**(il[i][1]-1))%L)

Submission status: Wrong Answer

Solution code:
N,L,T=map(int,input().split())
T %= L
Ant=[]
for i in range(N):
  a,b=map(int,input().split())
  if b==1:
    Ant.append(a+T)
  else:
    Ant.append(a-T)

cnt=0
for i in range(N):
  if Ant[i]<0:
    Ant[i]+=L
    cnt-=1
  elif Ant[i]>L:
    Ant[i]-=L
    cnt+=1
    
Ant.sort()
Ant=Ant[cnt:]+Ant[:cnt]

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

Submission status: Wrong Answer

Solution code:
def main():
    n, l, t = map(int, input().split())
    xs, ds = [], []
    for _ in range(n):
        x, w = [int(c) for c in input().split()]
        xs.append(x)
        ds.append(1 if w == 1 else -1)

    xs_thr = [(x + d * t) % l for x, d in zip(xs, ds)]
    xs_thr_sorted = [(x, i) for i, x in enumerate(xs_thr)]
    xs_thr_sorted.sort()
    i2p = {i: p for p, (x, i) in enumerate(xs_thr_sorted)}

    x_groups = {
        -1: [x for i, x in enumerate(xs) if ds[i] == -1],
        1: [x for i, x in enumerate(xs) if ds[i] == 1],
    }

    def bin_count(arr, v):
        if len(arr) == 0 or v <= arr[0]:
            return 0
        p, q = 0, len(arr)
        while q - p > 1:
            m = (p + q) // 2
            if arr[m] < v:
                p = m
            else:
                q = m
        return q

    def collide(i):
        pos = xs[i] + t * ds[i] * 2
        itera = len(x_groups[-ds[i]]) * abs(pos // l)
        f_delta = bin_count(x_groups[-ds[i]], xs[i])
        b_delta = bin_count(x_groups[-ds[i]], pos % l)
        return itera + (b_delta - f_delta) * ds[i]

    for i in range(n):
        p = i2p[i]
        print(xs_thr_sorted[(p - collide(i) * ds[i] % n + n) % n][0])


if __name__ == '__main__':
#     import sys
#     from io import StringIO
#     sys.stdin = StringIO("""\
# 2 9 10
# 5 1
# 6 2
# """)
    main()