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 = 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[where]
a.sort()

if b[0] == 1:
	if crash % 2 == 1:
		where0 = min([i for i in range(N) if a[i] == nowplace])
	else:
		where0 = max([i for i in range(N) if a[i] == nowplace])		
else:
	if crash % 2 == 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 - int(crash)) % N

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

for i in res:
    print(i)

Submission status: Wrong Answer

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
    where = (-where) % N
else:
    where = int(-crash) % N
    where = (-where) % N

nowplace = a[where]
a.sort()

if b[0] == 1:
	if crash % 2 == 1:
		where0 = min([i for i in range(N) if a[i] == nowplace])
	else:
		where0 = max([i for i in range(N) if a[i] == nowplace])		
else:
	if crash % 2 == 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])
		

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

for i in res:
    print(i)

Submission status: Wrong Answer

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
    where = (-where) % N
else:
    where = int(-crash) % N
    where = (-where) % N

nowplace = a[where]

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

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

for i in res:
    print(i)

Submission status: Wrong Answer

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
    where = (-where) % N
else:
    where = int(-crash) % N
    where = (-where) % N

nowplace = a[where]

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

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

for i in res:
    print(i)

Submission status: Wrong Answer

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

# N,L,T = 3,10,10
# a = [1,2,3]
# b = [1,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
    where = (-where) % N
else:
    where = int(-crash) % N
    where = (-where) % N

nowplace = a[where]

a.sort()
where0 = a.index(nowplace)

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

for i in res:
    print(i)

Submission status: Wrong Answer

Solution code:
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 
	where = (-where) % N
else:
	where = int(-crash) % N
	where = (-where) % N

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

for i in res:
	print(i)

Submission status: Wrong Answer

Solution code:
n,l,t=map(int,input().split())
x=[0 for i in range(n+1)]
w=[0 for i in range(n+1)]
ans=[]
w1=[]
w2=[]

for i in range(1,n+1):
    x[i],w[i]=map(int,input().split())
    if w[i]==1: a=(x[i]+t)%l; w1.append(x[i])
    if w[i]==2: a=(x[i]-t+l)%l; w2.append(x[i])
    ans.append(a)

# kはアリ１がずれ違った数。アリ１はアリk+1に進化してる。
k=0
for i in range(n):
    if w[i]==1:
        if (x[i]+2*t)>=l: k=w.count(2)
        else:
            for j in range(x[i],x[i]+2*t+1): k+=w2.count(j)
        break

ans.sort()
for i in range(n): print(ans[(i+k)%n])

Submission status: Wrong Answer

Solution code:
n,l,t=map(int,input().split())
x=[0 for i in range(n+1)]
w=[0 for i in range(n+1)]
ans=[]
ans2=[0 for i in range(n)]
w1=[]
w2=[]

for i in range(1,n+1):
    x[i],w[i]=map(int,input().split())
    if w[i]==1: a=(x[i]+t)%l; w1.append(x[i])
    if w[i]==2: a=(x[i]-t+l)%l; w2.append(x[i])
    ans.append(a)

# kはアリ１がずれ違った数。アリ１はアリk+1に進化してる。
k=0
for i in range(n):
    if w[i]==1:
        if (x[i]+2*t)>l: k=min(w.count(1),w.count(2))
        else:
            for j in range(x[i],x[i]+2*t): k+=w2.count(j)
        break

ans.sort()
for i in range(n):
    ans2[i]=ans[(i+k)%n]
for i in range(n): print(ans2[i])

Submission status: Wrong Answer

Solution code:
n,l,t=map(int,input().split())
x=[0 for i in range(n+1)]
w=[0 for i in range(n+1)]
ans=[]
ans2=[0 for i in range(n)]
w1=[]
w2=[]

for i in range(1,n+1):
    x[i],w[i]=map(int,input().split())
    if w[i]==1: a=(x[i]+t)%l; w1.append(x[i])
    if w[i]==2: a=(x[i]-t+l)%l; w2.append(x[i])
    ans.append(a)

# kはアリ１がずれ違った数。アリ１はアリk+1に進化してる。
k=0
if w[1]==1:
    if 2*t>l: k=min(w.count(1),w.count(2))
    else:
        for i in range(x[1],x[1]+2*t): k+=w2.count(i)
if w[1]==2:
    if 2*t>l: k=min(w.count(1),w.count(2))
    else:
        for i in range(x[1],(x[1]-2*t+l)%l): k+=w1.count(i)
        k=len(w1)-k

ans.sort()
for i in range(n):
    ans2[i]=ans[(i+k)%n]
for i in range(n): print(ans2[i])

Submission status: Wrong Answer

Solution code:
n,l,t=map(int,input().split())
x=[0 for i in range(n+1)]
w=[0 for i in range(n+1)]
ans=[]
ans2=[0 for i in range(n)]
w1=[]
w2=[]

for i in range(1,n+1):
    x[i],w[i]=map(int,input().split())
    if w[i]==1: a=(x[i]+t)%l; w1.append(x[i])
    if w[i]==2: a=(x[i]-t+l)%l; w2.append(x[i])
    ans.append(a)

# kはアリ１がずれ違った数。アリ１はアリk+1に進化してる。
if (x[1]+2*t)>l: k=min(w.count(1),w.count(2))
else:
    k=0
    if w[1]==1:
        for i in range(x[1],x[1]+2*t): k+=w2.count(i)
    if w[1]==2:
        for i in range(x[1],x[1]+2*t): k+=w1.count(i)

ans.sort()
for i in range(n):
    ans2[i]=ans[(i+k)%n]
for i in range(n): print(ans2[i])

Submission status: Wrong Answer

Solution code:
n,l,t=map(int,input().split())
x=[0 for i in range(n+1)]
w=[0 for i in range(n+1)]
ans=[0 for i in range(n+1)]
ans2=[0 for i in range(n)]
w1=[]
w2=[]

for i in range(1,n+1):
    x[i],w[i]=map(int,input().split())
    if w[i]==1: ans[i]=(x[i]+t)%l; w1.append(x[i])
    if w[i]==2: ans[i]=(x[i]-t+l)%l; w2.append(x[i])

ans.pop(0)
if (x[1]+2*t)>l: k=min(w.count(1),w.count(2))
else:
    k=0
    if w[1]==1:
        for i in range(x[1],x[1]+2*t): k+=w2.count(i)
    if w[1]==2:
        for i in range(x[1],x[1]+2*t): k+=w1.count(i)


for i in range(n): ans2[(i+k)%n]=ans[i]
for i in range(n): print(ans2[i])

Submission status: Wrong Answer

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

inf = 10**10

N, L, T = map(int, raw_input().split())
XW = [map(int, raw_input().split()) for i in xrange(N)]
T %= L
A = [0]*N

for i, (x, w) in enumerate(XW):
    A[i] = (x + (3 - 2*w)*T + inf*L)%L

x, w = XW[0]
cnt = 0
if w == 1:
    for xx, ww in XW[1:]: 
        if ww == 1: continue
        if 2*T - (xx - x) < 0: continue
        cnt += 1 + (2*T - (xx - x))/L
else:
    for xx, ww in XW[1:]: 
        if ww == 2: continue
        if 2*T - (L - (xx - x)) < 0: continue
        cnt -= 1 + (2*T - (L - (xx - x)))/L
cnt = (cnt + inf*N)%N
for i in xrange(N):
    print A[(i - cnt + N)%N]

Submission status: Wrong Answer

Solution code:

class Ant:
    def __init__(self, index, pos, direction):
        self.index = index
        self.pos = pos
        self.direction = direction

    def move(self):
        if self.direction == 1:
            self.pos += 1
        else:
            self.pos -= 1

        if self.pos >= L:
            self.pos = self.pos - L
        if self.pos < 0:
            self.pos += L + self.pos

    def change_direction(self):
        if self.direction == 1:
            self.direction = 2
        else:
            self.direction = 1
        
def get_colide_ant_list(ant_list):
    colide_ant_list = []
    ant_list = sorted(ant_list, key=lambda ant: ant.pos)
    len_ant_list = len(ant_list)
    for i in range(len_ant_list-1):
        if ant_list[i].pos == ant_list[i+1].pos:
            colide_ant_list.append((ant_list[i], ant_list[i+1]))
        elif (ant_list[i+1].index - ant_list[i].index != 1) and \
             (ant_list[i].direction == 2 and ant_list[i+1].direction == 1):
            colide_ant_list.append((ant_list[i], ant_list[i+1]))
    if ant_list[0].index > ant_list[-1].index and (ant_list[0].direction == 1 and ant_list[-1].direction == 2):
        colide_ant_list.append((ant_list[0], ant_list[-1]))

    return colide_ant_list
    

ant_list = []   # (pos, direction)

N, L, T = list(map(int, input().split()))
for i in range(N):
    pos, direction = list(map(int, input().split()))
    ant_list.append(Ant(i, pos, direction))

for t in range(T):
    colide_ant_list = get_colide_ant_list(ant_list)
    for ant1, ant2 in colide_ant_list:
        ant1.change_direction()
        ant2.change_direction()

    for ant in ant_list:
        ant.move()

    colide_ant_list = get_colide_ant_list(ant_list)
    for ant1, ant2 in colide_ant_list:
        ant1.change_direction()
        ant1.move()
        ant2.change_direction()
        ant2.move()

sorted(ant_list, key=lambda ant: ant.index)
for ant in ant_list:
    print(ant.pos)

Submission status: Wrong Answer

Solution code:
# C
import numpy as np
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
for i in range(N):
    if W[i] != W[0]:
        cnt_conf += (2*T - (X[i] - X[0])) // L + 1
n0 = cnt_conf % N
if W[0] == 1:
    p0 = (X[0] + T) % L
else:
    p0 = (X[0] - T) % L

positions.sort()

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

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

Submission status: Wrong Answer

Solution code:
from itertools import product as prd 
n, l, t = map(int, input().split())
x = [0]*n
w = [0]*n
xt = {}
#xt = [0]*n
ccw = []
cw = []
for i in range(n):
    x[i], w[i] = map(int, input().split())
    if w[i]==2:
        w[i] = -1
        ccw.append(i)
    else:
        cw.append(i)
    xt[i] = (x[i]+t*w[i])%l
d = {}
for tmp in prd(cw, ccw):
    if x[tmp[1]]<x[tmp[0]]:
        length = l+x[tmp[1]]-x[tmp[0]]
    else:
        length = x[tmp[1]]-x[tmp[0]]
    time = [i/10 for i in range(length*5, t*10+1, 40)]
    for i in range(len(time)):
        d[time[i]] = tmp
indxes = [i for i in range(n)]

for k in sorted(d.keys()):
    tmp = d[k]
    indxes[tmp[0]], indxes[1] = indxes[tmp[1]], indxes[tmp[0]]
    xt[indxes[0]], xt[indxes[1]] = xt[indxes[1]], xt[indxes[0]]
for k in sorted(xt.keys()):
    print(xt[k])

Submission status: Wrong Answer

Solution code:
import numpy as np
from numpy import inf
n,l,t = list(map(int,input().split()))
x_list = list()
w_list = list()

for i in range(n):
    x, w = list(map(int,input().split()))
    x_list.append(x)
    w_list.append(w)

d_list = list()
for i in range(len(x_list)-1):
    d_list.append(x_list[i+1]-x_list[i])
d_list.append(x_list[0]+l-x_list[-1])

w_list = [w if w == 1 else -1 for w in w_list]

x_array = np.array(x_list)
w_array = np.array(w_list)
d_array = np.array(d_list)



time = 0
while time < t:
#     s_list = list()
#     # さが縮まるかどうか。縮まるなら1
#     for i in range(len(w_list)):
#         if w_array[i%n] == 1 and w_array[(i+1)%n]==-1:
#             s_list.append(1)
#         elif w_array[i%n] == -1 and w_array[(i+1)%n]==1:
#             s_list.append(-1)
#         else:
#             s_list.append(0)
    
    s_array = (w_array[1:] - w_array[:-1]) * (-1/2)
    s_array = np.append(s_array,(w_array[0]-w_array[-1])*(-1/2))
#     s_array = np.array(s_list)
    # d_arrayには差が入っている。
    butukaru_array = d_array / (s_array*2)
    butukaru_array[butukaru_array == inf] = 0
    butukaru_array[butukaru_array == -inf] = 0
    if s_array.all == 0:
        next_time = t -time
    else:
        next_time = butukaru_array.max()

    time += next_time
        
    if time >= t:
        next_time -= (time-t)
    
    x_array = (x_array + w_array*next_time) % l
    if time >= t:
        break
    d_array = d_array - s_array*2*next_time

    butukatta_x = np.where(d_array == 0)[0]
    
#     for i in butukatta_x:
    w_array[butukatta_x] *= -1
    w_array[(butukatta_x+1)%n] *= -1
    
for x in x_array:

    while x<0:
        x += l
    while x >= l:
        x -= l
        
    print(int(x))

Submission status: Wrong Answer

Solution code:
class ant:
    def __init__(self, x, w):
        self.x = x
        self.flipped = False
        if(w == 1):
            self.fow = True
        else:
            self.fow = False
    def getPos(self):
        return self.x
    def move(self, t):
        if(self.fow):
            if(self.x == L):
                self.x = t
            else:
                self.x += t
        else:
            if(self.x == 0):
                self.x = L-t
            else:
                self.x -= t
    def flip(self):
        if(not self.flipped):
            self.fow = not self.fow
        self.flipped = True


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

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

for t in range(int(T/0.5)):
    for i in range(N):
        ants[i].flipped = False
    for i in range(N):
        if i == 0:
            bf = N-1
            af = i+1
        elif i == N-1:
            bf = i-1
            af = 0
        if (ants[i].x == ants[bf].x):
            ants[i].flip()
            ants[bf].flip()
        elif (ants[i].x == ants[af].x):
            ants[i].flip()
            ants[af].flip()

    for i in range(N):
        ants[i].move(0.5)

for i in range(N):
    print(int(ants[i].x))

Submission status: Wrong Answer

Solution code:
# C
import numpy as np
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
for i in range(N):
    if W[i] != W[0]:
        cnt_conf += (2*T - (X[i] - X[0])) // L + 1
n0 = cnt_conf % N
if W[0] == 1:
    p0 = (X[0] + T) % L
else:
    p0 = (X[0] - T) % L

positions.sort()

# find index
if W[0] == 1:
    num = np.argmax(np.arange(N)[positions==p0])
else:
    num = np.argmin(np.arange(N)[positions==p0])
for i in range(N):
    print(positions[(num - n0 + i) % N])

Submission status: Wrong Answer

Solution code:
import numpy as np
from numpy import inf
n,l,t = list(map(int,input().split()))
x_list = list()
w_list = list()

for i in range(n):
    x, w = list(map(int,input().split()))
    x_list.append(x)
    w_list.append(w)

d_list = list()
for i in range(len(x_list)-1):
    d_list.append(x_list[i+1]-x_list[i])
d_list.append(x_list[0]+l-x_list[-1])

w_list = [w if w == 1 else -1 for w in w_list]

x_array = np.array(x_list)
w_array = np.array(w_list)
d_array = np.array(d_list)



time = 0
while time < t:
#     s_list = list()
#     # さが縮まるかどうか。縮まるなら1
#     for i in range(len(w_list)):
#         if w_array[i%n] == 1 and w_array[(i+1)%n]==-1:
#             s_list.append(1)
#         elif w_array[i%n] == -1 and w_array[(i+1)%n]==1:
#             s_list.append(-1)
#         else:
#             s_list.append(0)
    
    s_array = (w_array[1:] - w_array[:-1]) * (-1/2)
    s_array = np.append(s_array,(w_array[0]-w_array[-1])*(-1/2))
#     s_array = np.array(s_list)
    # d_arrayには差が入っている。
    butukaru_array = d_array / (s_array*2)
    butukaru_array[butukaru_array == inf] = 0
    butukaru_array[butukaru_array == -inf] = 0
    if s_array.all == 0:
        next_time = t -time
    else:
        next_time = butukaru_array.max()

    time += next_time
        
    if time >= t:
        next_time -= (time-t)
    
    x_array = (x_array + w_array*next_time) % l
    d_array = d_array - s_array*2*next_time
    
    butukatta_x = np.where(d_array == 0)[0]
    
#     for i in butukatta_x:
    w_array[butukatta_x] *= -1
    w_array[(butukatta_x+1)%n] *= -1
    
for x in x_array:

    while x<0:
        x += l
    while x >= l:
        x -= l
        
    print(int(x))

Submission status: Wrong Answer

Solution code:
# C
import numpy as np
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
for i in range(N):
    if W[i] != W[0]:
        cnt_conf += (2*T - (X[i] - X[0])) // L + 1
n0 = cnt_conf % N
if W[0] == 1:
    p0 = (X[0] + T) % L
else:
    p0 = (X[0] - T) % L

positions.sort()

# find index

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

Submission status: Wrong Answer

Solution code:
import sys

def rd():
        return sys.stdin.readline().rstrip()

def rdi():
        return [ int(x) for x in rd().split() ]

N, L, T = rdi()
L2 = 2 * L
T2 = 2 * T
X = []
W = []
for i in range(N):
        x, w = rdi()
        X.append(x * 2)
        W.append(w)
X.append(X[0] + L2)
W.append(W[0])

x = list(X)
w = list(W)
t = [ 0 for i in range(N+1) ]

def step(p):
        global x, w, t
        rem = 0
        for i in range(N):
                j = i+1
                if t[i] < p and t[j] < p and w[i] == 1 and w[j] == 2:
                        if t[i] < t[j]:
                                if w[i] == 1:
                                        x[i] += t[j] - t[i]
                                else:
                                        x[i] -= t[j] - t[i]
                                t[i] = t[j]
                        elif t[j] < t[i]:
                                if w[j] == 1:
                                        x[j] += t[i] - t[j]
                                else:
                                        x[j] -= t[i] - t[j]
                                t[j] = t[i]
                        d = (x[j] - x[i]) / 2
                        if d < p - t[i]:
                                rem = 2
                        else:
                                d = p - t[i]
                        x[i] += d
                        x[j] -= d
                        t[i] += d
                        t[j] += d
                        if x[i] == x[j]:
                                w[i] = 2
                                w[j] = 1
                        if i == 0:
                                x[N] = x[0] + L2
                                w[N] = w[0]
                                t[N] = t[0]
                        elif j == N:
                                x[0] = x[N] - L2
                                w[0] = w[N]
                                t[0] = t[N]
        if rem:
                return True
        for i in range(N):
                if t[i] < p:
                        d = p - t[i]
                        x[i] += d
                        t[i] = p
                        rem = 1
                        if i == 0:
                                x[N] = x[0] + L2
                                w[N] = w[0]
                                t[N] = t[0]
        return False

base_x = None
base_w = None
base_t = None

while step(T2):
        while x[0] > L2:
                x = [ v-L2 for v in x ]
        while x[0] < -L2:
                x = [ v+L2 for v in x ]
        if not base_x:
                while step(max(t)):
                        pass
                base_x = list(x)
                base_w = list(w)
                base_t = list(t)
        elif x[0] == base_x[0] and w[0] == base_w[0]:
                while step(t[0]):
                        pass
                if x == base_x and w == base_w:
                        rem = T2 - t[0]
                        rpt = rem % (t[0] - base_t[0])
                        for i in range(N+1):
                                t[i] += t[i] * rpt


for i in range(N):
        print (x[i]/2 + L) % L

Submission status: Wrong Answer

Solution code:
N, L, T = map(int, input().split())
ans = [0]*N
for i in range(N):
	X, W = map(int, input().split())
	if W == 1:
		d = 1
	else:
		d = -1
	ans[i] = (X + d*T)%L

ans.sort()
for i in range(N):
	print(ans[(i+1)%N])

Submission status: Wrong Answer

Solution code:
N = list(map(float,input().split()))
X = [ list(map(float,input().split(" "))) for i in range(int(N[0]))]
for t in range(int(N[2])):
	for n in range(int(N[0])):
		if X[n][1] == 1.0:
			X[n][0] = X[n][0] + 0.5;		
		elif X[n][1] == 2.0:
			if X[n][0] == 0.0:
				X[n][0] = N[1]-0.5
			else:
				X[n][0] = X[n][0] - 0.5;
	for k in range(int(N[0])):
		for l in range(int(N[0])):
			if X[k][0] == X[l][0] and k != l:
				print("a")
				if X[k][1] == 1.0:
					X[k][1] = 2.0
				elif X[k][1] == 2.0:
					X[k][1] = 1.0
	for o in range(int(N[0])):
		if X[o][1] == 1.0:
			if X[o][0] == N[1]-0.5:
				X[o][0] = 0
			else:
				X[o][0] = X[o][0] + 0.5;		
		elif X[o][1] == 2.0:	
			X[o][0] = X[o][0] - 0.5;
	for p in range(int(N[0])):
		for q in range(int(N[0])):
			if X[p][0] == X[q][0] and p != q:
				if X[p][1] == 1.0:
					X[p][1] = 2.0
				elif X[p][1] == 2.0:
					X[p][1] = 1.0
for m in range(int(N[0])):
	print(int(X[m][0]))

Submission status: Wrong Answer

Solution code:
import numpy as np

def read():
    return list(map(int, input().split()))

init = read()
n = init[0]
l = init[1]
t = init[2]
x = np.zeros(n)
w = np.zeros(n)
for i in range(n):
    init = read()
    x[i] = init[0]
    w[i] = init[1]
for i in range(n):
    if w[i] == 1:
        x[i] += t
    else:
        x[i] -= t
for i in range(n):
    while x[i] < 0:
        x[i] += l
    while x[i] >= l:
        x[i] -= l
posi = np.sort(x).astype(np.int)
for i in range(n):
    print(str(posi[i]))

Submission status: Wrong Answer

Solution code:
import numpy as np
from numpy import inf
n,l,t = list(map(int,input().split()))
x_list = list()
w_list = list()

for i in range(n):
    x, w = list(map(int,input().split()))
    x_list.append(x)
    w_list.append(w)

d_list = list()
for i in range(len(x_list)-1):
    d_list.append(x_list[i+1]-x_list[i])
d_list.append(x_list[0]+l-x_list[-1])

w_list = [w if w == 1 else -1 for w in w_list]

x_array = np.array(x_list)
w_array = np.array(w_list)
d_array = np.array(d_list)



time = 0
while time < t:
    s_list = list()
    # さが縮まるかどうか。縮まるなら1
    for i in range(len(w_list)):
        if w_array[i%n] == 1 and w_array[(i+1)%n]==-1:
            s_list.append(1)
        elif w_array[i%n] == -1 and w_array[(i+1)%n]==1:
            s_list.append(-1)
        else:
            s_list.append(0)
    s_array = np.array(s_list)
    # d_arrayには差が入っている。
    butukaru_array = d_array / (s_array*2)
    butukaru_array[butukaru_array == inf] = 0
    if s_array.all == 0:
        next_time = t -time
    else:
        next_time = butukaru_array.max()

    time += next_time
        
    if time >= t:
        next_time -= (time-t)
    
    x_array = x_array + w_array*next_time
    d_array = d_array - s_array*2*next_time
    
    butukatta_x = np.where(d_array == 0)[0]
    
#     for i in butukatta_x:
    w_array[butukatta_x] *= -1
    w_array[(butukatta_x+1)%n] *= -1
    
for x in x_array:

    while x<0:
        x += l
    while x >= l:
        x -= l
        
    print(int(x))

Submission status: Wrong Answer

Solution code:
class ant:
    def __init__(self, x, w):
        self.x = x
        if(w == 1):
            self.fow = True
        else:
            self.fow = False
    def getPos(self):
        return self.x
    def move(self, t):
        if(self.fow):
            if(self.x == L):
                self.x = t
            else:
                self.x += t
        else:
            if(self.x == 0):
                self.x = L-t
            else:
                self.x -= t
    def flip(self):
        self.fow = not self.fow


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

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

for t in range(int(T/0.5)):
    for i in range(N):
        if(i == 0):
            if (ants[N-1].x == ants[0].x):
                ants[N-1].flip()
                ants[0].flip()
            elif (ants[0].x == ants[1].x):
                ants[1].flip()
                ants[0].flip()
        elif(i == N-1):
            if (ants[N-1].x == ants[N-2].x):
                ants[N-1].flip()
                ants[N-2].flip()
            elif (ants[N-1].x == ants[0].x):
                ants[N-1].flip()
                ants[0].flip()
        else:
            if(ants[i-0].x == ants[i].x):
                ants[i-0].flip()
                ants[i].flip()
            elif(ants[i].x == ants[i+1].x):
                ants[i+1].flip()
                ants[i].flip()
        ants[i].move(0.5)

for i in range(N):
    print(int(ants[i].x))

Submission status: Wrong Answer

Solution code:
n,l,t=map(int,input().split())
x=[0 for i in range(n+1)]
w=[0 for i in range(n+1)]
ans=[0 for i in range(n+1)]
ans2=[0 for i in range(n)]

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

ans.pop(0)
k=min(w.count(1),w.count(2))
for i in range(n): ans2[(i+k)%n]=ans[i]
for i in range(n): print(ans2[i])

Submission status: Wrong Answer

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

inf = 10**10

N, L, T = map(int, raw_input().split())
XW = [map(int, raw_input().split()) for i in xrange(N)]
T %= L
A = [0]*N

for i, (x, w) in enumerate(XW):
    A[i] = (x + (3 - 2*w)*T + inf*L)%L

if len(set(w for x, w in XW)) == 1:
    for a in A:
        print a
else:
    idx = 0
    if XW[0][1] == 1:
        XI = [[(x + 2*T)%L, i] for i, (x, w) in enumerate(XW) if w == 1]
        YI = [[x, i] for i, (x, w) in enumerate(XW) if w == 2]
        s = (XW[0][0] + 2*T)%L
        t = (XW[-1][0] + 2*T)%L
        for y, i in YI:
            if y <= s:
                if t < y:
                    idx = i
                else:
                    idx = N - 1

    else:
        XI = [[(x - 2*T + inf*L)%L, i] for i, (x, w) in enumerate(XW) if w == 2]
        YI = [[x, i] for i, (x, w) in enumerate(XW) if w == 1]
        s = (XW[0][0] - 2*T + inf*L) % L
        t = (XW[-1][0] - 2*T + inf*L) % L
        for y, i in YI:
            if y >= s:
                if t > y:
                    idx = i
                else:
                    idx = N - 1
    for i in xrange(N):
        print A[(i + idx)%N]