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

Solution code:
n, l, t = map(int,input().split())
x=[]
w=[]
for i in range(n):
    x_temp, w_temp=map(int, input().split())
    x.append(x_temp)
    w.append(w_temp)
final_x=[]
for i in range(n):
    if w[i]==1:
        final_x.append((x[i]+t)%l)
    elif w[i]==2:
        final_x.append((x[i]-t)%l)
new_x=sorted(final_x)
cnt=0
if w[0]==2:
    for i in range(1, n):
        if w[i]==1 and x[i]-x[0]<t/2:
            cnt-=1
    cnt=cnt-(cnt%n)
elif w[1]==1:
    for i in range(1, n):
        if w[i]==1 and x[i]-x[0]<t/2:
            cnt+=1
    cnt=cnt%n
idx=new_x.index(final_x[0])-1
for i in range(n):
    print(new_x[(idx+i)%n])

Submission status: Runtime Error

Solution code:
n, l, t = map(int,input().split())
x=[]
w=[]
for i in range(n):
    x_temp, w_temp=map(int, input().split())
    x.append(x_temp)
    w.append(w_temp)
final_x=[]
for i in range(n):
    if w[i]==1:
        final_x.append((x[i]+t)%l)
    elif w[i]==2:
        final_x.append((x[i]-t)%l)
cnt=0
if w[0]==2:
    for i in range(1, n):
        if w[i]==1 and x[i]-x[0]<=t/2:
            cnt-=1
    cnt=cnt-(cnt%n)
elif w[1]==1:
    for i in range(1, n):
        if w[i]==1 and x[i]-x[0]<=t/2:
            cnt+=1
    cnt=cnt%n
for p in range(n):
    print(final_x[(p+cnt)%n-1])

Submission status: Runtime Error

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]
    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_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_position) % l )/ 2:
                hit_count = 0
            else:
                dt =((xw[i][0] - first_ant_position) % l )/ 2
                hit_count = int ( 1 +2 * ( t - dt) // 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[n-i-1]:

            i = n - i - 1

#            for j in range(n-i):
#                ans[first_ant_number-1+j] = ant_position[i+j]
#            for j in range(i):
#                ans[first_ant_number-2-j] = ant_position[i-j-1]

            for j in range(n-i):
                ans[first_ant_number-1+j] = ant_position[i+j]
            for j in range(i):
                ans[first_ant_number-2-j] = ant_position[i-j-1]
            break

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

main()

Submission status: Runtime Error

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]) fori in range(n)]))

Submission status: Runtime Error

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

Submission status: Runtime Error

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


candidates = sorted(candidates)

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

for j in range(N):
    if ree == 0:
        1/0
#    candidates[(start + j) % N + 1]
    print(candidates[(start + j) % N])

Submission status: Runtime Error

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):
    if ree != 0:
        print(candidates[(start + j) % N])
    else:
        1/0

Submission status: Runtime Error

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 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):
    if ree != 0:
        print(candidates[(start + j) % N])
    else:
        1/0

Submission status: Runtime Error

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

candidates = sorted(candidates)

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

for j in range(N):
    if ree != 0:
        print(candidates[(start + j) % N])
    else:
        1/0

Submission status: Runtime Error

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

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

for j in range(N):
    if ree != 0:
        print(candidates[(start + j) % N])
    else:
        1/0

Submission status: Runtime Error

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

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

for i in range(N):
    if ree != 0:
        print(candidates[(start + i) % N])
    else:
        print(candidates[(start + i) % N])

Submission status: Runtime Error

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 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 = []
for i in range(N):
    if ree != 0:
        print(candidates[(-1 * rep[0] + i) % N])
    else:
        print(candidates[(-1 * rep[0] + i) % N])

Submission status: Runtime Error

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 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)
        )
print(rep)
result = []
for i in range(N):
    if ree != 0:
        print(candidates[(-1 * rep[0] + i) % N])
    else:
        print(candidates[(-1 * rep[0] + i) % N])

Submission status: Runtime Error

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 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 - 1

rep = ( 
        ((1 if y0 == 1 else -1) * (c_n % N) % N) + 1,
        ((x0 + (1 if y0 == 1 else -1) * (T % L)) % L)
        )
result = []
for i in range(N):
    i = i + 1
    if ree != 0:
        print(candidates[(rep[0] + i) % N])
    else:
        print(candidates[(rep[0] + i - 1) % N])

Submission status: Runtime Error

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

n,l,t = li()
a,ac,au = [],[],[]
for i in range(n):
    x,y = li()
    if i == 0: start = y
    a.append(x)
    if y == 1:
        ac.append(x)
    else:
        au.append(x)

tt = t%l
if not ac:
    pointofone = (au[0]-t) % l
elif not au:
    pointofone = (ac[0]+t) % l
elif start == 2:
    acc = [n-ac[-s] for s in range(1,len(ac)+1)]
    dist = au[0]+acc[0]
    j = 0
    for i in range(1, min(len(au), len(acc))):
        if dist > tt:
            j = i-1
            break
        if i&1:
            dist += au[i]-au[i-1]
        else:
            dist += acc[i]-acc[i-1]
    if j&1:
        pointofone = (n - acc[j//2] + t)%l
    else:
        pointofone = (au[j//2] -t)%l
else:
    acc = [-au[0]] + [n-ac[-s] for s in range(1, len(ac))]
    dist = acc[0] + au[0]
    j = 0
    for i in range(1, min(len(ac), len(acc))):
        if dist > tt:
            j = i-1
            break
        if i&1:
            dist += acc[i]-acc[i-1]
        else:
            dist += au[i]-au[i-1]
    if j == 0:
        pointofone = (ac[0] + t)%l
    elif j&1:
        pointofone = (au[j//2]-t)%l
    else:
        pointofone = (n - acc[j//2]+t)%l

ant = sorted([(s-t)%l for s in au] + [(s+t)%l for s in ac])
st = ant.index(pointofone)
ant = ant[st:]+ant[:st]
print(*ant, sep='\n')

Submission status: Runtime Error

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

n,l,t = li()
a,ac,au = [],[],[]
for i in range(n):
    x,y = li()
    if i == 0: start = y
    a.append(x)
    if y == 1:
        ac.append(x)
    else:
        au.append(x)

tt = t%l

if start == 2:
    acc = [n-ac[-s] for s in range(1,len(ac)+1)]
    dist = au[0]+acc[0]
    j = 0
    for i in range(1, min(len(au), len(acc))):
        if dist > tt:
            j = i-1
            break
        if i&1:
            dist += au[i]-au[i-1]
        else:
            dist += acc[i]-acc[i-1]
    if j&1:
        pointofone = n - acc[j//2]
    else:
        pointofone = au[j//2]
else:
    acc = [-au[0]] + [n-ac[-s] for s in range(1, len(ac))]
    dist = acc[0] + au[0]
    j = 0
    for i in range(1, min(len(ac), len(acc)) ):
        if dist > tt:
            j = i-1
            break
        if i&1:
            dist += acc[i]-acc[i-1]
        else:
            dist += au[i]-au[i-1]
    if j == 0:
        pointofone = ac[0]
    elif j&1:
        pointofone = au[j//2]
    else:
        pointofone = n - acc[j//2]

ant = sorted([(s-t)%l for s in au] + [(s+t)%l for s in ac])
st = ant.index(pointofone)
ant = ant[st:]+ant[:st]
print(*ant, sep='\n')

Submission status: Runtime Error

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

n,l,t = li()
a,ac,au = [],[],[]
for i in range(n):
    x,y = li()
    if i == 0: start = y
    a.append(x)
    if y == 1:
        ac.append(x)
    else:
        au.append(x)

tt = t%l

if start == 2:
    acc = [n-ac[-s] for s in range(1,len(ac)+1)]
    dist = au[0]+acc[0]
    j = 0
    for i in range(1, min(len(au), len(acc))):
        if dist > tt:
            j = i-1
            break
        if i&1:
            dist += au[i]-au[i-1]
        else:
            dist += acc[i]-acc[i-1]
    if j&1:
        pointofone = n - acc[j//2]
    else:
        pointofone = au[j//2]
else:
    acc = [-au[0]] + [n-ac[-s] for s in range(1, len(ac))]
    dist = acc[0] + au[0]
    j = 0
    for i in range(1, min(len(ac), len(acc)) + 1):
        if dist > tt:
            j = i-1
            break
        if i&1:
            dist += acc[i]-acc[i-1]
        else:
            dist += au[i]-au[i-1]
    if j == 0:
        pointofone = ac[0]
    elif j&1:
        pointofone = au[j//2]
    else:
        pointofone = n - acc[j//2]

ant = sorted([(s-t)%l for s in au] + [(s+t)%l for s in ac])
st = ant.index(pointofone)
ant = ant[st:]+ant[:st]
print(*ant, sep='\n')

Submission status: Runtime Error

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

for i in range(N):
    X, W = map(int, raw_input().split())
    if W == 1:
        X1.append(X)
    else:
        X2.append(X)
    Xs.append((X, W))
m = {}
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: Runtime Error

Solution code:
N,L,T=map(int,input().split())
X=[0 for i in range(N)]
W=[0 for i in range(N)]
for i in range(N):
    X[i],W[i]=map(int,input().split())
Y=[0 for i in range(N)]
for i in range(N):
    if W[i]==1:
        Y[i]=(X[i]+T)%L
    else:
        Y[i]=(X[i]-T)%L
def dist(i,j):
    if (3-2*W[i])*(3-2*W[j])==1:
        return -1
    else:
        if 3-2*W[i]==1:
            D=(X[j]-X[i])%L
            return D//2
        else:
            D=(X[i]-X[j])%L
            return D//2
z=0
dt=3-2*W[0]
for i in range(1,N):
    ds=3-2*W[i]
    if dt*ds==1:
        continue
    z+=dt*((T//L)*2)
    K=T%L
    if K>=dist(0,i):
        z+=dt
    if K>=dist(0,i)+L//2:
        z+=st
z=-z%N
Z=Y[z:]+Y[:z]
for i in range(N):
    print(Z[i])

Submission status: Runtime Error

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

    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 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):
        print(xs_thr[(i - collide(i) * ds[i] % n + n) % n])


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
# AtCoder Grand Contest 013

#■標準入力ショートカット


def get_next_int():
    return int(float(input()))


def get_next_ints(delim=" "):
    return tuple([int(float(x)) for x in input().split(delim)])


def get_next_str():
    return input()


def get_next_strs(delim=" "):
    return tuple(input().split(delim))


def get_next_by_types(*value_types, delim=" "):
    return tuple([t(x) for t, x in zip(value_types, input().split(delim))])


N, L, T = 0, 0, 0


class Ant():

    def __init__(self, pos, dir):
        self.pos = pos
        self.dir = True if dir == 1 else False


def move(ants):
    bump = [False] * N
    moved = [False] * N
    for i, ant in enumerate(ants):
        if bump[i]:
            continue

        if ant.dir:
            next_pos = (ant.pos + 1) % L
        else:
            next_pos = (
                ant.pos - 1) if (ant.pos - 1) >= 0 else L - 1

        if ants[i - 1].pos == next_pos and ants[i - 1].dir and not ant.dir and not moved[i - 1]:
            ants[i - 1].dir = not ants[i - 1].dir
            bump[i - 1] = True
            ants[i].dir = not ants[i].dir
            bump[i] = True
            continue
        elif next_pos == ants[(i + 1) % N].pos and ant.dir and not ants[(i + 1) % N].dir:
            ants[i].dir = not ants[i].dir
            bump[i] = True
            ants[i + 1].dir = not ants[i + 1].dir
            bump[i + 1] = True
            continue
        else:
            ants[i].pos = next_pos
            moved[i] = True
            if moved[i - i] and ants[i - 1].pos == next_pos:
                ants[i].dir = not ants[i].dir
                ants[i - 1].dir = not ants[i + 1].dir


def solve():
    global N, L, T
    N, L, T = get_next_ints()
    ants = []
    for i in range(N):
        ants.append(Ant(*get_next_ints()))
    for i in range(T):
        move(ants)
    for ant in ants:
        print(ant.pos)

solve()

Submission status: Runtime Error

Solution code:
#■標準入力ショートカット


def get_next_int():
    return int(float(input()))


def get_next_ints(delim=" "):
    return tuple([int(float(x)) for x in input().split(delim)])


def get_next_str():
    return input()


def get_next_strs(delim=" "):
    return tuple(input().split(delim))


def get_next_by_types(*value_types, delim=" "):
    return tuple([t(x) for t, x in zip(value_types, input().split(delim))])


N, L, T = 0, 0, 0


class Ant():

    def __init__(self, pos, dir):
        self.pos = pos
        self.dir = True if dir == 1 else False


def move(ants):
    bump = [False] * N
    moved = [False] * N
    for i, ant in enumerate(ants):
        if bump[i]:
            continue

        if ant.dir:
            next_pos = (ant.pos + 1) % L
        else:
            next_pos = (
                ant.pos - 1) if (ant.pos - 1) >= 0 else L - 1

        if ants[i - 1].pos == next_pos and ants[i - 1].dir and not ant.dir and not moved[i - 1]:
            ants[i - 1].dir = not ants[i - 1].dir
            bump[i - 1] = True
            ants[i].dir = not ants[i].dir
            bump[i] = True
            continue
        elif next_pos == ants[(i + 1) % N].pos and ant.dir and not ants[(i + 1) % N].dir:
            ants[i].dir = not ants[i].dir
            bump[i] = True
            ants[i + 1].dir = not ants[i + 1].dir
            bump[i + 1] = True
            continue
        else:
            ants[i].pos = next_pos
            moved[i] = True
            if moved[i - i] and ants[i - 1].pos == next_pos:
                ants[i].dir = not ants[i].dir
                ants[i - 1].dir = not ants[i + 1].dir


def solve():
    global N, L, T
    N, L, T = get_next_ints()
    ants = []
    for i in range(N):
        ants.append(Ant(*get_next_ints()))
    for i in range(T):
        move(ants)
        for j, ant in enumerate(ants):
            print(j, ant.pos, ant.dir)
        print("")
    for ant in ants:
        print(ant.pos)

solve()

Submission status: Runtime Error

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

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

    if x_after < 0:
        x_after = L + x_after

    X.append(x)
    W.append(w)
    X_after.append(x_after)

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_after = W[0] + (N % n_colide)
else:
    num_after = W[0] - (N % n_colide)
    num_after = num_after if num_after >= 0 else L + num_after

num_after = int(num_after)

last_info = [
    {"X": X_after[0], "num": num_after}
]
x_after_first = X_after[0]
X_after = sorted(X_after)
i = X_after.index(x_after_first)
X_after = X_after[i:] + X_after[:i]

for i in range(1, N):
    num = num_after + i
    if num >= N:
        num = N - num
    last_info.append({
        "X": X_after[i],
        "num": num,
    })

sorted_info = sorted(last_info, key=lambda info: info["num"])

for info in sorted_info:
    print(info["X"])