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: Time Limit Exceeded

Solution code:
#! /Library/Frameworks/Python.framework/Versions/3.7/bin/python3
N, L, T = map(int, input().split())  # アリの数、外周、時間
P = []  # アリの位置: 0から2L-1まで
D = []  # アリの方向: 1か2
for n in range(N):
    t1, t2 = map(int, input().split())
    P.append(t1 * 2)
    D.append(t2)
for t in range(T * 2):
    P = [(P[n] - D[n]*2 + 3) % (L * 2) for n in range(N)]
    for n in range(N):
        if P.count(P[n]) == 2:
            D[n] = D[n] % 2 + 1
for n in range(N):
    print(str(P[n]//2))

Submission status: Time Limit Exceeded

Solution code:
N, L, T = map(int, input().split())  # アリの数、外周、時間
P = []  # アリの位置: 0から2L-1まで
D = []  # アリの方向: 1か2
for n in range(N):
    t1, t2 = map(int, input().split())
    P.append(t1 * 2)
    D.append(t2)
for t in range(T * 2):
    for n in range(N):
        P[n] = (P[n] - D[n]*2 + 3) % (L * 2)
    for n in range(N):
        if P.count(P[n]) == 2:
            D[n] = D[n] % 2 + 1
for n in range(N):
    print(str(P[n]//2))

Submission status: Time Limit Exceeded

Solution code:
#! /Library/Frameworks/Python.framework/Versions/3.7/bin/python3
N, L, T = map(int, input().split())  # アリの数、外周、時間
P = []  # アリの位置
D = []  # アリの方向
for n in range(N):
    t1, t2 = map(int, input().split())
    P.append(t1 * 2)
    D.append(t2)
for t in range(T * 2):
    for n in range(N):
        if D[n] == 1:
            P[n] = (P[n]+1) % (L * 2)
        else:
            P[n] = (P[n] - 1) % (L * 2)
    for n in range(N):
        if P.count(P[n]) == 2:
            D[n] += 1 if D[n] == 1 else -1
for n in range(N):
    print(str(P[n]//2))

Submission status: Time Limit Exceeded

Solution code:
n,l,T = map(int,input().split())
s = [0 for i in range(n)]
for i in range(n):
    s[i] = list(map(int, input().split()))

def f(w):
    if w == 1:
        return 1
    elif w == 2:
        return -1
    

d=[0 for i in range(n)]
for i in range(n-1):
    d[i] = s[i+1][0] - s[i][0]
d[n-1] = s[0][0] + l - s[n-1][0]

t = 0
dt = 0.5
while t < T:
    t+= dt
    s[0][0] = s[0][0] + f(s[0][1])*dt
    if s[0][0] >= l:
        s[0][0] -= l
    elif s[0][0] < 0:
        s[0][0] += l
        
    for i in range(n):
        if i < n-1:
            d[i] = d[i] + f(s[i+1][1])*dt - f(s[i][1])*dt
            s[i+1][0] = s[i][0] + d[i]
            if s[i+1][0] >= l:
                s[i+1][0] -= l
        else:
            d[n-1] = d[n-1] + f(s[0][1])*dt - f(s[n-1][1])*dt
            
    for i in range(n):
        if d[i] == 0 and i < n-1:
            s[i+1][1], s[i][1] = s[i][1], s[i+1][1]
        elif i == n-1 and d[i] == 0 :
            s[0][1], s[n-1][1] = s[n-1][1], s[0][1]
            
import math
for i in range(n):
    print(math.floor(s[i][0]))

Submission status: Time Limit Exceeded

Solution code:
n,l,T = map(int,input().split())
s = [0 for i in range(n)]
for i in range(n):
    s[i] = list(map(int, input().split()))

def f(w):
    if w == 1:
        return 1
    elif w == 2:
        return -1
    
t = 0
d = l

while t < T:
    for i in range(n):
        if i < n-1 :
            if s[i][0] < s[i+1][0] and s[i][1] == 1 and s[i+1][1] == 2:
                if s[i+1][0] - s[i][0] < d:
                    d = s[i+1][0] - s[i][0]
    
            elif s[i][0] > s[i+1][0] and s[i][1] == 1 and s[i+1][1] == 2:
                if s[i+1][0] + l - s[i][0] < d:
                    d = s[i+1][0] + l - s[i][0]
                    
        elif i == n-1:
            if s[i][0] < s[0][0] and s[i][1] == 1 and s[0][1] == 2:
                if s[0][0] - s[i][0] < d:
                    d = s[0][0] - s[i][0]
                    
            elif s[i][0] > s[0][0] and s[i][1] == 1 and s[0][1] == 2:
                if s[0][0] + l - s[i][0] < d:
                    d = s[0][0] + l - s[i][0]
                    
                    
    for j in range(n):
        if t + d/2 <= T:
            s[j][0] += f(s[j][1]) * (d/2)
            if s[j][0] >= l:
                s[j][0] -= l
            elif s[j][0] < 0:
                s[j][0] += l
            
        else:
            s[j][0] += f(s[j][1]) * (T-t)
            if s[j][0] >= l:
                s[j][0] -= l
            elif s[j][0] < 0:
                s[j][0] += l
        if j > 0 and s[j][0] == s[j-1][0]:
            s[j][1], s[j-1][1] = s[j-1][1], s[j][1]
        if j == n-1 and s[j][0] == s[0][0] :
            s[j][1], s[0][1] = s[0][1], s[j][1]
            
    t = t + d/2
    d = l
    
import math

for i in range(n):
    print(math.floor(s[i][0]))

Submission status: Time Limit Exceeded

Solution code:
n,l,T = map(int,input().split())
s = [0 for i in range(n)]
for i in range(n):
    s[i] = list(map(int, input().split()))

def f(w):
    if w == 1:
        return 1
    elif w == 2:
        return -1
    
t = 0
d = l
i_d = []

while t < T:
    for i in range(n):
        if i < n-1 :
            if s[i][0] < s[i+1][0] and s[i][1] == 1 and s[i+1][1] == 2:
                if s[i+1][0] - s[i][0] < d:
                    d = s[i+1][0] - s[i][0]
    
            elif s[i][0] > s[i+1][0] and s[i][1] == 1 and s[i+1][1] == 2:
                if s[i+1][0] + l - s[i][0] < d:
                    d = s[i+1][0] + l - s[i][0]
                    
        elif i == n-1:
            if s[i][0] < s[0][0] and s[i][1] == 1 and s[0][1] == 2:
                if s[0][0] - s[i][0] < d:
                    d = s[0][0] - s[i][0]
                    
            elif s[i][0] > s[0][0] and s[i][1] == 1 and s[0][1] == 2:
                if s[0][0] + l - s[i][0] < d:
                    d = s[0][0] + l - s[i][0]
                    
    for i in range(n):
        if i < n-1 :
            if s[i][0] < s[i+1][0] and s[i][1] == 1 and s[i+1][1] == 2:
                if s[i+1][0] - s[i][0] == d:
                    i_d.append(i)
            elif s[i][0] > s[i+1][0] and s[i][1] == 1 and s[i+1][1] == 2:
                if s[i+1][0] + l - s[i][0] == d:
                    i_d.append(i)
                    
        elif i == n-1:
            if s[i][0] < s[0][0] and s[i][1] == 1 and s[0][1] == 2:
                if s[0][0] - s[i][0] == d:
                    i_d.append(i)
                    
            elif s[i][0] > s[0][0] and s[i][1] == 1 and s[0][1] == 2:
                if s[0][0] + l - s[i][0] == d:
                    i_d.append(i)
                    
    for j in range(n):
        if t + d/2 <= T:
            s[j][0] += f(s[j][1]) * (d/2)
            if s[j][0] >= l:
                s[j][0] -= l
            elif s[j][0] < 0:
                s[j][0] += l
            
        else:
            s[j][0] += f(s[j][1]) * (T-t)
            if s[j][0] >= l:
                s[j][0] -= l
            elif s[j][0] < 0:
                s[j][0] += l
    for j in i_d:
        if j < n-1:
            s[j][1], s[j+1][1] = s[j+1][1], s[j][1]
        else:
            s[j][1], s[0][1] = s[0][1], s[j][1]
    t = t + d/2
    i_d.clear()
    d = l
    
import math

for i in range(n):
    print(math.floor(s[i][0]))

Submission status: Time Limit Exceeded

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

ants = list(map(lambda x: [x[0] * 2, x[1]], [[int(i) for i in input().split()] for j in range(N)]))

for i in range(T * 2):
	for j in range(N):
		if ants[j][1] == 1:
			if ants[j][0] == 2 * L - 1:
				ants[j][0] = 0
			else:
				ants[j][0] += 1
			if j == N - 1:
				if ants[0][0] == ants[j][0]:
					ants[0][1] = 1
					ants[j][1] = 2
		else:
			if ants[j][0] == 0:
				ants[j][0] = 2 * L - 1
			else:
				ants[j][0] -= 1
			if j != 0:
				if ants[j - 1][0] == ants[j][0]:
					ants[j - 1][1] = 2
					ants[j][1] = 1

for i in range(N):
	print(ants[i][0] // 2)

Submission status: Time Limit Exceeded

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

ants = list(map(lambda x: [x[0] * 2, x[1]], [[int(i) for i in input().split()] for j in range(N)]))

for i in range(T * 2):
	for j in range(N):
		if ants[j][1] == 1:
			if j != N - 1:
				if ants[j][0] == 2 * L - 1:
					if ants[j + 1][0] == 1 and ants[j + 1][1] == 2:
						ants[j][0] = 0
						ants[j][1] = 2
						ants[j + 1][0] = 2 * L - 1
						ants[j + 1][1] = 1
					else:
						ants[j][0] = 0
				elif ants[j][0] == 2 * L - 2:
					if ants[j + 1][0] == 0 and ants[j + 1][1] == 2:
						ants[j][0] = 2 * L - 1
						ants[j][1] = 2
						ants[j + 1][0] = 2 * L - 2
						ants[j + 1][1] = 1
					else:
						ants[j][0] = 2 * L - 1
				else:
					if ants[j + 1][0] == ants[j][0] + 2 and ants[j + 1][1] == 2:
						ants[j][0] += 1
						ants[j][1] = 2
						ants[j + 1][0] -= 2
						ants[j + 1][1] = 1
					else:
						ants[j][0] += 1
			else:
				if ants[j][0] == 2 * L - 1:
					ants[j][0] = 0
				else:
					ants[j][0] += 1
				if ants[0][0] == ants[j][0]:
					ants[0][1] = 1
					ants[j][1] = 2
		else:
			if ants[j][0] == 0:
				ants[j][0] = 2 * L - 1
			else:
				ants[j][0] -= 1

for i in range(N):
	print(ants[i][0] // 2)

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
import sys


def log(s):
    print("| " + str(s), file=sys.stderr)
    pass


def output(x):
    print(x, flush=True)


def input_ints():
    return map(int, input().split())


def main():
    num_ants, original_leg, original_time = tuple(input_ints())
    original_ants = [tuple(input_ints()) for _ in range(num_ants)]

    ants = [[a[0] * 2, int((a[1] - 1.5) * -2)] for a in original_ants]
    leg = original_leg * 2
    time = original_time * 2

    t = 0
    initial_ants = None
    initial_time = None
    while t < time:
        log("At %d %s" % (t, ants))
        dt = leg
        for i, a in enumerate(ants):
            b = ants[(i + 1) % len(ants)]
            if a[1] > 0 and b[1] < 0:
                dt = min(dt, ((b[0] - a[0]) + leg * 2) % leg // 2)

        dt = min(dt, time - t)
        t += dt
        log(dt)

        d = defaultdict(lambda: [])
        for a in ants:
            a[0] = (a[0] + a[1] * dt + leg * 2) % leg
            d[a[0]].append(a)
        for k in d:
            if len(d[k]) > 1:
                for a in d[k]:
                    a[1] *= -1

        p = str(ants)
        if not initial_ants:
            initial_ants = p
            initial_time = t
        elif p == initial_ants:
            pt = t - initial_time
            t += ((time - t) // pt) * pt

    for a in ants:
        print(a[0] // 2)


main()

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
import sys


def log(s):
    print("| " + str(s), file=sys.stderr)
    pass


def output(x):
    print(x, flush=True)


def input_ints():
    return map(int, input().split())


def main():
    num_ants, original_leg, original_time = tuple(input_ints())
    original_ants = [tuple(input_ints()) for _ in range(num_ants)]

    ants = [[a[0] * 2, int((a[1] - 1.5) * -2)] for a in original_ants]
    leg = original_leg * 2
    time = original_time * 2

    t = 0
    while t < time:
        log("At %d %s" % (t, ants))
        dt = leg
        for i, a in enumerate(ants):
            b = ants[(i + 1) % len(ants)]
            if a[1] > 0 and b[1] < 0:
                dt = min(dt, ((b[0] - a[0]) + leg * 2) % leg // 2)

        dt = min(dt, time - t)
        t += dt
        log(dt)

        d = defaultdict(lambda: [])
        for a in ants:
            a[0] = (a[0] + a[1] * dt + leg * 2) % leg
            d[a[0]].append(a)
        for k in d:
            if len(d[k]) > 1:
                for a in d[k]:
                    a[1] *= -1

    for a in ants:
        print(a[0] // 2)


main()

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
from math import sqrt


def log(s):
    # print("| " + str(s), file=sys.stderr)
    pass


def output(x):
    print(x, flush=True)


def input_ints():
    return map(int, input().split())


def main():
    num_ants, leg, time = tuple(input_ints())
    original_ants = [tuple(input_ints()) for _ in range(num_ants)]

    ants = [[a[0] * 2, int((a[1] - 1.5) * -2)] for a in original_ants]

    for _ in range(time * 2):
        d = defaultdict(lambda: [])
        for a in ants:
            a[0] += a[1]
            a[0] = a[0] % (leg * 2)
            d[a[0]].append(a)
        for k in d:
            if len(d[k]) > 1:
                for a in d[k]:
                    a[1] *= -1

    for a in ants:
        print(a[0] // 2)


main()

Submission status: Time Limit Exceeded

Solution code:
n, l, t = map(int,input().split())
l=2*l
t=2*t
x=[]
w=[]
for i in range(n):
    x_temp, w_temp=map(int, input().split())
    x.append(x_temp*2)
    w.append(w_temp)

for time in range(t):
    for ants in range(n):
        if w[ants]==1:
            x[ants]+=1
            if x[ants]>=l:
                x[ants]-=l
        elif w[ants]==2:
            x[ants]-=1
            if x[ants]<0:
                x[ants]+=l
    for i1 in range(n):
        if x[i1] in x[i1+1:n]:
            i2=x[i1+1:n].index(x[i1])+i1+1
            if w[i1]==1 and w[i2]==2:
                w[i1],w[i2]=2,1
            elif w[i1]==2 and w[i2]==1:
                w[i1], w[i2]=1,2
for xs in x:
    print(int(xs/2))

Submission status: Time Limit Exceeded

Solution code:
n, l, t = map(int,input().split())
l=2*l
t=2*t
x=[]
w=[]
for i in range(n):
    x_temp, w_temp=map(int, input().split())
    x.append(x_temp*2)
    w.append(w_temp)
for time in range(t):
    for ants in range(n):
        if w[ants]==1:
            x[ants]+=1
        elif w[ants]==2:
            x[ants]-=1
    for v in range(n):
        if x[v]>=l:
            x[v]=x[v]-l
        elif x[v]<0:
            x[v]=l+x[v]
    for i1 in range(n):
        for i2 in range(i1+1, n):
            if x[i1]==x[i2]:
                if w[i1]==1 and w[i2]==2:
                    w[i1], w[i2] = 2, 1
                elif w[i1]==2 and w[i2]==1:
                    w[i1], w[i2] = 1, 2
for xs in x:
    print(int(xs/2))

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

n, l, t = map(int, input().split())
ants = []

def next_x(x, y):
    v = 0
    if y == 1 and x != l - 1:
        v =  x + 1
    elif y == 1 and x == l - 1:
        v = 0
    elif y == 2 and x != 0:
        v = x -1
    elif y == 2 and x == 0:
        v = l - 1
    return v

def half_second_after_x(x, y):
    if y == 1:
        v =  x + 0.5
    elif y == 2 and x != 0:
        v = x - 0.5
    elif y == 2 and x == 0:
        v = l - 0.5
    return v

for i in range(n):
    x, y = map(int, input().split())
    v = half_second_after_x(x, y)
    ants.append([x, y, v])

for z in range(t):
    nl = []
    for i in range(n):
        nl.append(str(ants[i][2]))
    c = Counter(nl)
    for q in range(n):
        # 衝突
        if c[str(ants[q][2])] != 1:
            if ants[q][1] == 2:
                ants[q][1] = 1
            else:
                ants[q][1] = 2

            ants[q][2] = half_second_after_x(ants[q][0], ants[q][1])
        else:
            ants[q][0] = next_x(ants[q][0], ants[q][1])
            ants[q][2] = half_second_after_x(ants[q][0], ants[q][1])

[print(a[0]) for a in ants]

Submission status: Time Limit Exceeded

Solution code:
#AGC 013 C - Ants on a Circle
N,L,T = map(int, input().split())
X = [0]*N
W = [0]*N
for n in range(N):
    X[n],W[n] = map(int, input().split())

for t in range(T):
    #print('now is ',t)
    for n in range(N):
        if n == N-1:
            if X[N-1]%L == X[0] and W[N-1] == 1 and W[0] == 2:
                W[N-1] = 2
                W[0] =1
                X[0] +=1
            else:
                X[N-1] += (-1)**(W[N-1]+1)
                X[N-1] %= L
                if X[N-1] == X[0]:
                	W[N-1] = 2
                	W[0] = 1
        else:
            if X[n] == X[n+1]:
                W[n] = 2
                W[n+1] = 1
                X[n] += (-1)**(W[n]+1)
                X[n] %= L
            elif (X[n]+1)%L == X[n+1] and W[n] == 1 and W[n+1] == 2:
                W[n] = 2
                W[n+1] =1
                X[n+1] -=1
            else:
                X[n] += (-1)**(W[n]+1)
                X[n] %= L
    #for n in range(N):
        #print(X[n],' ',W[n])
for n in range(N):
    print(X[n])

Submission status: Time Limit Exceeded

Solution code:
n,l,t=list(map(int,input().split()))
L=[]
for i in range(n):
    L.append(list(map(int,input().split())))
a=0
for i in range(1,n):
    if L[0][1]==1 and L[i][1]==2:
        a+=max(int((t-abs(L[0][0]-L[i][0])/2)/(l/2))+1,0)
    elif L[0][1]==2 and L[i][1]==1:
        a+=max(int((t-(l-abs(L[0][0]-L[i][0]))/2)/(l/2))+1,0)
if L[0][1]==1 :
    b=a%n
else:
    b=-a%n
Q=[]
for i in range(n):
    Q.append(((L[i][0]+t*(3-L[i][1]*2))%l))
Q.sort()
d=Q.index(((L[0][0]+t*(3-L[0][1]*2))%l))
W=[]
for i in range (n):
    if i+(-d+b)>=0 and i+(-d+b)<n:
        W.append(i+(-d+b))
    elif i+(-d+b)>=n:
        W.append(i+(-d+b)-n)
    else:
        W.append(i+(-d+b)+n)
for i in range(n):
    print(Q[W.index(i)])

Submission status: Time Limit Exceeded

Solution code:
tmp = list((map(int, input().split())))
N = tmp[0]
L = tmp[1]
T = tmp[2]
aunts = []
for i in range(N):
    aunts.append(list((map(int, input().split()))))

#auntsに衝突フラグ : 0:未、1:済
for a in aunts:
    a.append(0)

for t in range(0,2*T):
    #衝突フラグリセット 座標補正
    for a in aunts:
        a[2] = 0
        #if a[0] 

    #アリすすめる
    for a in aunts:
        if a[1] == 1:
            a[0] += 0.5
        else: a[0] -= 0.5
        #座標補正
        if a[0] >= L + 0.5:
            a[0] -= L
        if a[0] <= 0 - 0.5:
            a[0] += L

    #アリ反転
    for i,a in enumerate(aunts):
        #if 衝突
        if a[2] == 1:
            continue
        if i == len(aunts):
            continue
        for j,u in enumerate(aunts):
            #if i+j >= N-1: continue

            if i > j and aunts[i][0] == aunts[j][0] and (aunts[i][2] == 0 and aunts[j][2] == 0):
                #print("collision")
                #反転
                if aunts[i][1] == 1: 
                    aunts[i][1] = 2
                else: aunts[i][1] = 1
                if aunts[j][1] == 1: 
                    aunts[j][1] = 2
                else: aunts[j][1] = 1
                #衝突フラグ
                aunts[i][2] == 1
                aunts[j][2] == 1 

for a in aunts:
    if a[0] == L:
        a[0] = 0
    print(int(a[0]))

Submission status: Time Limit Exceeded

Solution code:
import heapq
N, L, T = map(int, input().split())
X = [0 for i in range(N)]
ant = [[] for i in range(2)]
E = [0 for i in range(N)]
for i in range(N):
    X[i], w = map(int, input().split())
    ant[w-1].append(i)
    if w == 1:
        end = X[i] + T
        end = end % L
    if w == 2:
        end = X[i]-T
        end = end % L
        if end < 0:
            end += L
    E[i] = end
len0 = len(ant[0])
len1 = len(ant[1])
TA = []
for m in range(len0):
    for n in range(len1):
        Y0 = ant[0][m]
        Y1 = ant[1][n]
        sa = X[Y1] - X[Y0]
        if sa < 0:
            sa += L
        gikan = sa / 2.0
        while gikan < T:
            heapq.heappush(TA,(gikan, Y0, Y1))
            gikan += L / 2.0
lastant = [i for i in range(N)]

for i in range(len(TA)):
    time, Y0, Y1 = heapq.heappop(TA)
    a = lastant[Y0]
    b = lastant[Y1]
    lastant[Y0] = b
    lastant[Y1] = a

result = [0 for i in range(N)]
for i in range(N):
    result[lastant[i]] = E[i]
for i in range(N):
    print(result[i])

Submission status: Time Limit Exceeded

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):
        #print X1, X2
        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)
#print m
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: Time Limit Exceeded

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

X = [0] * N
W = [0] * N
for i in range(N):
    X[i], W[i] = map(int, input().split())
    X[i] *= 2
    if W[i] == 2:
        W[i] = -1

# print(X, W)
for t in range(T):
    for i in range(N):
        X[i] = (X[i] + W[i]) % L
    for i in range(N):
        if X[i-1] == X[i]:
            W[i-1] *= -1
            W[i] *= -1
    # print(X, W)

for x in X:
    print(x // 2)

Submission status: Time Limit Exceeded

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

ants = [list(map(int, input().split(' '))) for _ in range(0, N)]

for t in range(0, T): # time loop
    # 次の1秒間に衝突が発生する場合、蟻のインデックスを入れ替える
    for i in range(0, len(ants)):
        # 衝突が発生する条件
        next_idx = (i + 1) % N
        if (ants[next_idx][0] - ants[i][0]) * (ants[next_idx][1] - ants[i][1]) in [1, L-1]:
            ants[i], ants[next_idx] = ants[next_idx], ants[i]

    for ant in ants:
        ant[0] += (-1) ** ((ant[1] % 2) + 1)
        ant[0] %= L
        
for x, o in ants:
    print(x)

Submission status: Time Limit Exceeded

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(2*an)
    b.append(3-2*ve)

#0.5秒単位で時間発展
for t in range(2*T):
  for i in range(N):
    a[i]+=b[i]
    a[i] %= 2*L
  for i in range(N-1):
    if a[i]==a[i+1]:
      b[i]=-b[i]
      b[i+1]=-b[i+1]
  if a[N-1]==a[0]:
    b[N-1]=-b[N-1]
    b[0]=-b[0]

for i in range(N):
  print(int(a[i]/2))

Submission status: Time Limit Exceeded

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(3-2*ve)

#0.5秒単位で時間発展
for t in range(2*T):
  for i in range(N):
    a[i]+=b[i]/2
    a[i] %= L
  for i in range(N-1):
    if a[i]==a[i+1] or a[i]==a[i+1]-L:
      b[i]=-b[i]
      b[i+1]=-b[i+1]
  if a[N-1]==a[0] or a[N-1]-L==a[0]:
    b[N-1]=-b[N-1]
    b[0]=-b[0]

for i in range(N):
  print(int(a[i]))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N, L, T = map(int, input().split())
X = []
W = []
ant = [i for i in range(N)]
for i in range(N):
    xi, wi = map(int, input().split())
    X.append(xi)
    W.append(wi)

npX = np.array(X).astype(np.float)
npW = np.array(W).astype(np.float)
npW[npW == 2] = -1

def swap(ant, i, j):
    tmp = ant[i]
    ant[i] = ant[j]
    ant[j] = tmp
    return ant

ans = (npX + npW * T) % L

T %= L
if T > L - T:
    T = L - T
    npW *= -1
t = 0
while t < T:
    t += 0.5
    npX = (npX + npW * 0.5) % L
    colision = set([e for e in set(npX) if np.sum(npX == e) == 2])
    if len(colision) != 0:
        for e in colision:
            i, j = np.where(npX == e)[0].tolist()
            swap(ant, i, j)

for i in range(N):
    print(int(ans[ant.index(i)]))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N, L, T = map(int, input().split())
X = []
W = []
ant = [i for i in range(N)]
for i in range(N):
    xi, wi = map(int, input().split())
    X.append(xi)
    W.append(wi)

npX = np.array(X).astype(np.float)
npW = np.array(W).astype(np.float)
npW[npW == 2] = -1

def swap(ant, i, j):
    tmp = ant[i]
    ant[i] = ant[j]
    ant[j] = tmp
    return ant

ans = (npX + npW * T) % L

T %= L
t = 0
while t < T:
    t += 0.5
    npX = (npX + npW * 0.5) % L
    colision = set([e for e in set(npX) if np.sum(npX == e) == 2])
    if len(colision) != 0:
        for e in colision:
            i, j = np.where(npX == e)[0].tolist()
            swap(ant, i, j)

for i in range(N):
    print(int(ans[ant.index(i)]))

Submission status: Time Limit Exceeded

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):
            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-1].x == ants[i].x):
                ants[i-1].flip()
                ants[i].flip()
            elif(ants[i].x == ants[i+1].x):
                ants[i+1].flip()
                ants[i].flip()
    for i in range(N):
        ants[i].move(0.5)

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

Submission status: Time Limit Exceeded

Solution code:

n,l,t = map(int, input().split(' '))
x,w = [],[]
x1,x2 = [],[]
for _ in range(n):
    x_,w_ = map(int, input().split(' '))
    x.append(x_)
    w.append(w_)
    if w_ == 1:
        x1.append(x_)
    elif w_ == 2:
        x2.append(x_)

final_x = [(x_+(-w_*2+3)*t)%l  for x_,w_ in zip(x,w)]

t1 = t % (2*l)
t2 = t // (2*l)
meet = t2*(len(x1)*len(x2))
meet += sum([sum([(((x2_-x1_)%l) <= (2*t1)) for x2_ in x2]) for x1_ in x1])
meet %= n

ret = final_x[meet:]+final_x[:meet]
for ret_ in ret:
    print(ret_)

Submission status: Time Limit Exceeded

Solution code:
n,l,t = map(int, input().split(' '))
x,w = [],[]
for _ in range(n):
    x_,w_ = map(int, input().split(' '))
    x.append(x_)
    w.append(w_)

final_x = []
for x_,w_ in zip(x,w):
    w_ = -w_*2+3
    final_x.append((x_+w_*t)%l)
    
x1,x2 = [],[]
for i,w_ in enumerate(w):
    if w_ == 1:
        x1.append(x[i])
    elif w_ == 2:
        x2.append(x[i])

t1 = t % (2*l)
t2 = t // (2*l)
meet = 0
for x1_ in x1:
    for x2_ in x2:
        d = (x2_ - x1_) % l
        if d <= (2*t1):
            meet += 1
        meet += t2
meet %= n
ret = final_x[meet:]+final_x[:meet]
for ret_ in ret:
    print(ret_)

Submission status: Time Limit Exceeded

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

init_X = list(X)
init_W = list(W)

t = 0
while t < T2:
        for i in range(N):
                if W[i] == 1:
                        X[i] += 1
                else:
                        X[i] -= 1
        if min(X) < -L2 or max(X) > 2*L2:
                X = [ (x+3*L2)%L2 for x in X ]
        X[N] = X[0] + L2
        wn = W[N]
        for i in range(N):
                if X[i] == X[i+1]:
                        W[i] = 3 - W[i]
                        W[i+1] = 3 - W[i+1]
        if W[N] != wn:
                W[0] = W[N]
        else:
                W[N] = W[0]
        t += 1
        if X == init_X and W == init_W:
                rem = T2 - t
                rpt = rem % t
                t += t * rpt
for i in range(N):
        print (X[i]/2 + L) % L

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N, L, T = map(int, input().split())
X = []
W = []
for i in range(N):
    x, w = map(float, input().split())
    if w == 2.0:
        w = -1.0
    X.append(x)
    W.append(w)
X = np.array(X)
W = np.array(W)

for t in range(2*T):
    X += 0.5 * W
    X = X % L
    diff = (np.roll(X, 1) - X) == 0
    diff = diff + np.roll(diff, -1)
    W[diff] *= -1

for x in X:
    print(int(x))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N, L, T = map(int, input().split())
X = []
W = []
for i in range(N):
    x, w = map(float, input().split())
    if w == 2.0:
        w = -1.0
    X.append(x)
    W.append(w)
X = np.array(X)
W = np.array(W)

for t in range(2*T):
    X += 0.5 * W
    X[np.where(X==L)] = 0
    X[np.where(X==-0.5)] = L-0.5
    
    diff = (np.roll(X, 1) - X) == 0
    diff = diff + np.roll(diff, -1)
    W[diff] *= -1

for x in X:
    print(int(x))

Submission status: Accepted

Solution code:
n,l,t=map(int,input().split())
data=[]
s=0
for i in range(n):
  x,w=map(int,input().split())
  if w==1:
    data.append((x+t)%l)
    s+=(x+t)//l
  else:
    data.append((x-t)%l)
    s+=(x-t)//l
data.sort()
res=s%n
data=data[res:]+data[:res]
for i in data:
  print(i)