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:
import sys
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7
 
def main():
    N, L, T = map(int, readline().split())
    position = []
    
    cnt = 0
    for i in range(N):
      x, w = map(int, input().split())
      if w == 1:
        cnt += (x - T)//L
        position.append((x-T)%L)
      else:
        if x-T < 0:
          cnt += (x - T)//L
        position.append((x - T)%L)
	position.sort()
    cnt %= N
    
    ans = position[cnt:] + position[:cnt]
    for i in range(N):
      print(ans[i])

Submission status: Runtime Error

Solution code:
import sys
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    N, L, T = map(int, readline().split())
    position = []
    #0をL-1からーに時計回りに超える場合は+1
    #0からL-1に反時計回りに超える場合は-1
    count = 0
    for i in range(N):
        x,w = map(int, readline().split())
        if w==1:
            count += (x+T)//L
            position.append((x+T)%L)
        else:
            if x-T<0:
                count += (x-T+1)//L
            position.append((x-T)%L)
    position.sort()
    if count>=0:
        ans = position[count:] + position[:count]
    for i in range(N):
        print(ans[i])


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import sys
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    N, L, T = map(int, readline().split())
    position = []
    #0をL-1からーに時計回りに超える場合は+1
    #0からL-1に反時計回りに超える場合は-1
    count = 0
    for i in range(N):
        x,w = map(int, readline().split())
        if w==1:
            count += (x+T)//L
            position.append((x+T)%L)
        else:
            if x-T<0:
                count += (x-T+1)//L
            position.append((x-T)%L)
    position.sort()
    if count>=0:
        ans = position[count:] + position[:count]
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline

n, l, t = map(int, input().split())
XW = [list(map(int, input().split())) for _ in range(n)]
L = []
for i, xw in enumerate(XW):
  x, w = xw
  if w == 1:
    L.append((x+t)%l)
  else:
    L.append((x-t)%l)
L.sort()
x_0, w_0 = XW[0]
b = 0
for x, w in XW[1:]:
  if w_0 == w:
    continue
  if w_0 == 1:
    if x-x_0 > 2*t:
      continue
    b += 1 + (2*t - (x-x_0)) // l
  else:
    if l-(x-x_0) > 2*t:
      continue
    b -= 1 + (2*t - (l-(x-x_0))) // l
m = L.index(L[b])
for i in range(m, m+n):
  print(L[i%n])

Submission status: Runtime Error

Solution code:
n, l, t =map(int, input().split())
x=[]
w=[]
for i in range(n):
  a, b=map(int, input().split())
  x.append(a)
  if b==2:
    w.append(-1)
  else:
    w.append(1)
for fn in range(t*2):
  x=[d+0.5*e for (d, e) in zip(x, w)]
  for f in range(n):
    if x[f]>=l:
      x[f]-=l
    elif x[f]<0:
      x[f]+=l
  for p in range(n):
    if p==n-1:
      if x[p]==x[0]:
        w[p]=w[p]*(-1)
        w[0]=w[0]*(-1)
    else:
      if x[p]==x[p+1]:
        w[p]=w[p]*(-1)
        w[p+1]=w[p+1]*(-1)
for i in x:
  print(int(x[i]))

Submission status: Runtime Error

Solution code:
import copy

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

snapshot = []
for no in range(1, N + 1):
    (x, w) = list(map(int, input().split()))
    snapshot.append({
        'i': no - 1,
        'no': no,
        'x': x,
        'w': 1 if w == 1 else -1
    })


def normalize(x):
    return (x + L) % L


def find_neighbor(ant):
    x = ant['x']
    for neighbor in snapshot:
        if ant['no'] == neighbor['no']:
            continue
        _x = neighbor['x']
        if _x == normalize(x - 1) and (ant['w'] == -1 and neighbor['w'] == 1):
            return neighbor
        if _x == normalize(x + 1) and (ant['w'] == 1 and neighbor['w'] == -1):
            return neighbor
        if _x == x:
            return neighbor
    return None


def move():
    results = {}
    for ant in copy.deepcopy(snapshot):
        x = ant['x']        
        no = ant['no']
        if no in results:
            continue
        neighbor = find_neighbor(ant)
        if neighbor is None:
            ant['x'] = normalize(ant['x'] + ant['w'])
            results[ant['no']] = ant
            continue
        if x == neighbor['x']:
            ant['w'] *= -1
            ant['x'] = normalize(ant['x'] + ant['w'])
            if neighbor['no'] not in results:            
                neighbor['w'] *= -1
                neighbor['x'] = normalize(neighbor['x'] + neighbor['w'])
                results[neighbor['no']] = neighbor
        else:
            ant['w'] *= -1
            results[ant['no']] = ant
            if neighbor['no'] not in results:
                neighbor['w'] *= -1
                results[neighbor['no']] = neighbor
    ret = []
    for k in sorted(results.keys()):
        ret.append(results[k])
    return ret


def print_snapshot():
    for ant in snapshot:
        no = ant['no']
        x = ant['x']
        w = ant['w']
        print(f'{no}: x={x}, w={w}')


        
t = 0
#print(f'----- t = {t} -----')
#print_snapshot()
for i in range(T):
    t += 1
    snapshot = move()
    #print(f'----- t = {t} -----')    
    #print_snapshot()
for s in snapshot:
    print(s['x'])

Submission status: Runtime Error

Solution code:
N, L, T = map(int, input().split())
lst = [tuple(map(int, input().split())) for i in range(N)]
lst2 = []
count = 0
a = T % L

base = None
for tpl in lst:
    if tpl[1] == 1:
        lst2.append(tpl[0]+T)
    elif tpl[1] == 2:
        lst2.append(tpl[0]-T)
    
    if base == None:
        base = tpl
    elif tpl[1] != base[1]:
        if  (tpl[0]-base[0]) <= a and base[1] ==1:
            count += 1
        elif a < (tpl[0]-base[0]) <= 2*a and base[1] ==1:
            count += 2
        elif (L-tpl[0]+base[0]) <= a and base[1] == 2:
            count -= 1
        elif a < (L-tpl[0]+base[0]) <= 2*a and base[1] == 2:
            count -= 2
    print(count)
count = count % N
for i in range(N):
    lst2[i] = lst2[i] % L
#print(lst2)
#print(count)
for i in range(lst2):
    print(lst2[(i+count) % N])

Submission status: Runtime Error

Solution code:
s = input()
n = len(s)
f = ''
for i in range(2**(n-1)):
  b = format(i, 'b').zfill(n)
  for j in range(n):
    if b[j] == '1':
      f += '+' + s[j]
    else:
      f += s[j]
  f+= '+'
print(eval(f[:len(f)-1]))

Submission status: Runtime Error

Solution code:
N, L, T=map(int, input().split())
XW=[list(map(int, input().split())) for _ in range(N)]
X_=[(XW[i][0]+T)%L if XW[i][1]==1 else (XW[i][0]-T)%L for i in range(N)]
X_.sort()
A0_=(XW[0][0]+T)%L if XW[0][1]==1 else (XW[0][0]-T)%L
P0_=X_.index(A0_)
if P0_>0:
    X_=X_[P0_:]+X_[:P0_]
    
if XW[0][1]==1:
    C0_=round(sum([(T-(XW[i][0]-XW[0][0])/2)//(L/2)+1 if XW[i][1]!=1 and (XW[i][0]-XW[0][0])/2<=T else 0 for i in range(1, N)])%N)
else:
    C0_=round(N-sum([(T-(XW[0][0]+L-XW[i][0])/2)//(L/2)+1 if XW[i][1]!=2 and (XW[0][0]+L-XW[i][0])/2<=T else 0 for i in range(1, N)])%N)
    
if X_[0]==X_[1] and XW[0][1]==1:
  C0_=round((C0_-1)%N)
'''
if C0_>0:
  X_=X_[N-C0_:]+X_[:N-C0_]
'''
print(*X_, sep='\n')

Submission status: Runtime Error

Solution code:
N, L, T=map(int, input().split())
XW=[list(map(int, input().split())) for _ in range(N)]
X_=[(XW[i][0]+T)%L if XW[i][1]==1 else (XW[i][0]-T)%L for i in range(N)]
X_.sort()
A0_=(XW[0][0]+T)%L if XW[0][1]==1 else (XW[0][0]-T)%L
P0_=X_.index(A0_)
if P0_>0:
    X_=X_[P0_:]+X_[:P0_]
    
if XW[0][1]==1:
    C0_=round(sum([(T-(XW[i][0]-XW[0][0])/2)//(L/2)+1 if XW[i][1]!=1 and (XW[i][0]-XW[0][0])/2<=T else 0 for i in range(1, N)])%N)
else:
    C0_=round(N-sum([(T-(XW[0][0]+L-XW[i][0])/2)//(L/2)+1 if XW[i][1]!=2 and (XW[0][0]+L-XW[i][0])/2<=T else 0 for i in range(1, N)])%N)
    
if X_[0]==X_[1] and XW[0][1]==1:
  C0_=round((C0_-1)%N)
  
if C0_>0:
  X_=X_[N-C0_:]+X_[:N-C0_]
print(*X_, sep='\n')

Submission status: Runtime Error

Solution code:
N, L, T=map(int, input().split())
XW=[list(map(int, input().split())) for _ in range(N)]
X_=[(XW[i][0]+T)%L if XW[i][1]==1 else (XW[i][0]-T)%L for i in range(N)]
X_.sort()
A0_=(XW[0][0]+T)%L if XW[0][1]==1 else (XW[0][0]-T)%L
P0_=X_.index(A0_)
if P0_>0:
    X_=X_[P0_:]+X_[:P0_]
    
if XW[0][1]==1:
    C0_=round(sum([(T-(XW[i][0]-XW[0][0])/2)//(L/2)+1 if XW[i][1]!=1 and (XW[i][0]-XW[0][0])/2<=T else 0 for i in range(1, N)])%N)
else:
    C0_=round(N-sum([(T-(XW[0][0]+L-XW[i][0])/2)//(L/2)+1 if XW[i][1]!=2 and (XW[0][0]+L-XW[i][0])/2<=T else 0 for i in range(1, N)])%N)
    
if X_[0]==X_[1] and XW[0][1]==1:
  C0_=(C0_-1)%N
  
if C0_>0:
  X_=X_[N-C0_:]+X_[:N-C0_]
print(*X_, sep='\n')

Submission status: Runtime Error

Solution code:
N, L, T=map(int, input().split())
XW=[list(map(int, input().split())) for _ in range(N)]
X_=[(XW[i][0]+T)%L if XW[i][1]==1 else (XW[i][0]-T)%L for i in range(N)]
X_.sort()
A0_=(XW[0][0]+T)%L if XW[0][1]==1 else (XW[0][0]-T)%L
P0_=X_.index(A0_)
if P0_>0:
    X_=X_[P0_:]+X_[:P0_]
    
if XW[0][1]==1:
    C0_=round(sum([(T-(XW[i][0]-XW[0][0])/2)//(L/2)+1 if XW[i][1]!=1 and (XW[i][0]-XW[0][0])/2<=T else 0 for i in range(1, N)])%N)
else:
    C0_=round(N-sum([(T-(XW[0][0]+L-XW[i][0])/2)//(L/2)+1 if XW[i][1]!=2 and (XW[0][0]+L-XW[i][0])/2<=T else 0 for i in range(1, N)])%N)
    
if X_[0]==X_[1] and XW[0][1]==1:
  if C0_>0:
    C0_=(C0_-1)%N
  
if C0_>0:
  X_=X_[N-C0_:]+X_[:N-C0_]
print(*X_, sep='\n')

Submission status: Runtime Error

Solution code:
N, L, T=map(int, input().split())
XW=[list(map(int, input().split())) for _ in range(N)]
X_=[(XW[i][0]+T)%L if XW[i][1]==1 else (XW[i][0]-T)%L for i in range(N)]
X_.sort()
A0_=(XW[0][0]+T)%L if XW[0][1]==1 else (XW[0][0]-T)%L
P0_=X_.index(A0_)
if P0_>0:
    X_=X_[P0_:]+X_[:P0_]
    
if XW[0][1]==1:
    C0_=round(sum([(T-(XW[i][0]-XW[0][0])/2)//(L/2)+1 if XW[i][1]!=1 and (XW[i][0]-XW[0][0])/2<=T else 0 for i in range(1, N)])%N)
else:
    C0_=round(N-sum([(T-(XW[0][0]+L-XW[i][0])/2)//(L/2)+1 if XW[i][1]!=2 and (XW[0][0]+L-XW[i][0])/2<=T else 0 for i in range(1, N)])%N)
    
if X_[0]==X_[1] and XW[0][1]==1:
  C0_-=1
  
if C0_>0:
  X_=X_[N-C0_:]+X_[:N-C0_]
print(*X_, sep='\n')

Submission status: Runtime Error

Solution code:
n,l,T=map(int,input().split())
from collections import deque
a=deque()
b=deque()

for i in range(n):
  q,ww=map(int,input().spilt())
  w=3-2*ww
  a.append([(j*w*2+2*q)%(2*l) for j in range(1,2*T+1)]
  b.append(i)

for k in range(2*T):
  for i in range(n):
      for j in range(i+1,n):
           if a[i][k]=a[j][k]:
               b[i]=b[k]
           
           
for i in range(n)
           print(a[b[i]][-1]//2 if a[b[i]][-1]//2 else n)

Submission status: Runtime Error

Solution code:
# input
n,l,time = map(int, input().split())
ant = [0] * n
v = [0] * n
for i in range(n):
    ant[i],v[i] = map(int, input().split())

# plus
def plus(point):
    if l <= point+1:
        res = 0
    else:
        res = point+1
    return res

# minus
def minus(point):
    if 0 > point-1:
        res = l-1
    else:
        res = point-1
    return res

def swap(i):
    if v[i] == 1:
        v[i] = 2
    else:
        v[i] = 1
    
# process
for time in range(time):
    # flg
    flgCollision = [{0:0}] * l
    
    # coliision
    for i in range(n):
        # collide at same point.
        if flgCollision[ant[i]] != {0:0}:
            swap(i)
            swap([k for k in flgCollision[ant[i]].keys()][0])
        # memo flg num:vec
        flgCollision[ant[i]] = {i:v[i]}
    
    aa = ant.copy()
    # walk
    for i in range(n):
        if v[i] == 1:
            ant[i] = plus(ant[i])
        else:
            ant[i] = minus(ant[i])
    
    for i in range(n):
        if aa[i] < l-1:    
            if v[i] == 1 and [vv for vv in flgCollision[aa[i]+1].values()][0] == 2:
                swap(i)
                swap([k for k in flgCollision[aa[i]+1].keys()][0])
                ant[i], ant[[k for k in flgCollision[aa[i]+1].keys()][0]] = ant[[k for k in flgCollision[aa[i]+1].keys()][0]], ant[i]
        else:
            if v[i] == 1 and [vv for vv in flgCollision[0].values()][0] == 2:
                swap(i)
                swap([k for k in flgCollision[0].keys()][0])
                ant[i], ant[[k for k in flgCollision[0].keys()][0]] = ant[[k for k in flgCollision[0].keys()][0]], ant[i]

for ants in ant:
    print(ants)

Submission status: Runtime Error

Solution code:
def examA():
    N = I()
    A = LI()
    ans = 1
    flag = None
    for i in range(N-1):
        cur = A[i+1] - A[i]
        if not flag:
            if cur<0:
                flag = "d"
            elif cur>0:
                flag = "u"
        else:
            if cur<0 and flag=="u":
                flag = None
                ans += 1
            elif cur>0 and flag=="d":
                flag = None
                ans += 1
    print(ans)
    return

def examB():
    def bfs(n,V):
        W = [inf] * n
        W[0] = 0
        que = deque()
        que.append(0)
        while (que):
            now = que.popleft()
            nowW = W[now]
            if nowW==0:
                judge = 0
            elif nowW>0:
                judge = 1
            else:
                judge = -1
            if judge<0:
                cur = -1
            else:
                cur = 1

            for ne in V[now]:
                #print(now,ne)
                if cur+1<judge:
                    break
                if W[ne]!=inf:
                    continue
                W[ne] = nowW + cur
                que.append(ne)
                cur -= 2
        return W
    N, M = LI()
    V = [[]for _ in range(N)]
    for _ in range(M):
        a, b = LI()
        a -= 1; b -= 1
        V[a].append(b)
        V[b].append(a)

    L = bfs(N,V)
    D = defaultdict(int)
    minA = 0; maxA = 0
    for i,a in enumerate(L,start=1):
        if a!=inf:
            D[a] = i
            if a<minA:
                minA = a
            if a>maxA:
                maxA = a
    ans = []
    for i in range(minA,maxA+1):
        ans.append(D[i])
    print(len(ans))
    print(" ".join(map(str,ans)))
    return

def examC():
    N, L, T = LI()
    X = [[]for _ in range(N)]
    for i in range(N):
        cur = LI()
        cur.append(i)
        X[i] = cur
    #print(X)
    X.sort()
    ans_num = defaultdict(int)
    for j,[x,w,i] in enumerate(X):
        ans_num[j] = i

    X_R = []
    X_L = []
    #flag_R = False
    for x,w,i in X:
        if w==1:
            if i==0:
                flag_R = True
            X_R.append([x,i])
        else:
            X_L.append([x,i])
    V = []
    for i in range(N):
        now = T if X[i][1]==1 else -T
        cur = (X[i][0] + now)%L
        cur = (cur+L)%L
        V.append(cur)
    change = 0
    if flag_R:
        stand = X_R[0][0]
    else:
        stand = X_L[0][0]
    for x,i in X_L if flag_R else X_R:
        cur = (2*T)//L
        if flag_R:
            if (x - stand) > 0 and x - stand <= (2 * T) % L:
                cur += 1
            elif (x - stand) <= 0 and L - (x - stand) <= (2 * T) % L:
                cur += 1
        else:
            if (x - stand) < 0 and x - stand <= (2 * T) % L:
                cur += 1
            elif (x - stand) >= 0 and L - (x - stand) <= (2 * T) % L:
                cur += 1
        #print(cur,x,i)
        change += cur
    to = change % N
    #print(change,to)

    import numpy as np
    if flag_R:
        V = np.roll(V, to)
    else:
        V = np.roll(V, -to)

    ans = [0]*N
    for i in range(N):
        ans[ans_num[i]] = V[i]
    for v in ans:
        print(v)
    return

def examD():
    ans = 0
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math,random
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

if __name__ == '__main__':
    examC()

"""

"""

Submission status: Runtime Error

Solution code:
n, l, total_t = map(int, input().split())

pos_nt = {i:[] for i in range(n)}

xl = []
wl = []
rrp = []
lrp = []


for i in range(n):
    x, w = map(int, input().split())
    xl.append(x)
    wl.append(w)
    if w ==1:
        rrp.append(x)

    else:lrp.append(x)


for i in range(n):
    if wl[i] == 1:
        orig_idx = i
        break


is_rr = True
rhead = 0
lhead = 0
for i, p in enumerate(lrp):
    if p > rrp[rhead]:
        lhead = i
# todo: len(lrp) == 0 の場合

current_pos = rrp[rhead]
t = 0

while(True):
   
    if is_rr:
        lp = (lrp[lhead]-t)%l
        rp = (rrp[rhead]+t)%l
        if rp >lp:
            rp = rp-l
        elapsed = (lp-rp)/2
        
        if(elapsed <0):
            print("oops")
            exit()
        
        if(t + elapsed > total_t):
            break
        
        current_pos = lp-elapsed

        t += elapsed
        
        is_rr = False
        rhead = (rhead-1)%len(rrp)
        
    else:
        lp = (lrp[lhead]-t)%l
        rp = (rrp[rhead]+t)%l
        if rp >lp:
            rp = rp-l
        elapsed = (lp-rp)/2

        if(elapsed < 0):
            print("oops2")
            exit()
        if(t + elapsed > total_t):
            break

        current_pos = lp-elapsed

        t += elapsed
        is_rr = True
        lhead = (lhead +1)%len(lrp)
        # rhead = (rhead-1)%len(rrp)

    
remain_t = total_t - t
is_rr = not is_rr
# print(rrp[rhead])
# print(lrp[lhead])
# exit()
if is_rr:
    current_pos = (current_pos + remain_t)%l
else:
    current_pos = (current_pos - remain_t)%l

if is_rr:
    pos = (rrp[rhead]-t)


res_list = []

for i in range(n):
    if wl[i] == 1:
        sl = xl[i] + total_t
    else:
        sl = xl[i] - total_t
    res_list.append(sl%l)

# print(res_list)
# exit()

mod_res_list = []


for i in range(n):
    if res_list[i] == current_pos:
        hoge = i
        break


shift_d = hoge-orig_idx
shift_idx = shift_d%n


for i in range(shift_idx, n):
    mod_res_list.append(res_list[i])

for i in range(0, shift_idx):
    mod_res_list.append(res_list[i])

# print(mod_res_list)
for r in mod_res_list:
    print(r)

# for i in range(hoge, n):
#     print(res_list[i])
# for i in range(0, hoge):
#     print(res_list[i])

Submission status: Runtime Error

Solution code:
import numpy as np

N,L,T = map(int, input().split())
x,w = [],[]
for _ in range(N):
	tx,tw = map(int, input().split())
	if tw == 2:
		tw = -1
	x.append(tx)
	w.append(tw)

x = np.array(x)
w = np.array(w)
f = x+(w*T)
f %= L

if w[0] == 1:
	ghost = T*2
	s,t = divmod(ghost,L)
	cnt = s*np.count_nonzero(w == -1)
	dist = x[0] + t
	for i in range(1,N):
		if w[i] == -1 and x[i] <= dist:
			cnt += 1

	ind = N-(cnt%N)
else:
	ghost = T*2
	s,t = divmod(ghost, L)
	num_w1 = np.count_nonzero(w == 1)
	cnt = s*num_w1
	dist = x[0] + (L-t)
	un_cnt = 0
	for i in range(1,N):
		if w[i] == 1 and x[i] <= dist:
			un_cnt += 1
	cnt += (num_w1-un_cnt)
	ind = (cnt%N)+1

IND = np.arange(N)
F = np.stack([f,IND],1)
F = F[np.argsort(F[:,0])]

for i in range(N):
	if F[i][1] == ind:
		ind = i
		break

F = np.concatenate((F[ind:], F[:ind]))
F = F[:,0]
for A in F:
	print(A)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Your code here!

CLOCKWISE = 1
COUNTERCLOCKWISE = -1

class Ant:
    def __init__(self, x, w):
        self.x = x
        self.w = w

nums=list(map(int,input().split()))

N = nums[0]
L = nums[1]
T = nums[2]

ants = []

for i in range(N):
    nums=list(map(int,input().split()))
    if nums[1] == 1:
        ants.append(Ant(nums[0], CLOCKWISE))
    else:
        ants.append(Ant(nums[0], COUNTERCLOCKWISE))
    

lower = ants[0].x
upper = (ants[0].x + T) % L

cnt_neg = -1
cnt_pos = 0

for i in range(N):
    if ants[0].w == ants[i].w and ((ants[0].x - ants[i].x) * ants[0].w) % L < T:
        cnt_neg += 1
    elif ants[0].w != ants[i].w and ((ants[i].x - ants[0].x) * ants[0].w) % L < 2 * T:
        cnt_pos += 1

result = []
for i in range(N):
    result.append((ants[i].x + T * ants[i].w) % L)


if cnt_pos % 2 == 1:
    cnt_neg += 1

if ants[0].w == CLOCKWISE:
    for i in range(- cnt_neg + 1 , N - cnt_neg + 1):
        print(result[i])
else:
    for i in range(- cnt_neg, N - cnt_neg):
        print(result[i])

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Your code here!

CLOCKWISE = 1
COUNTERCLOCKWISE = -1

class Ant:
    def __init__(self, x, w):
        self.x = x
        self.w = w

nums=list(map(int,input().split()))

N = nums[0]
L = nums[1]
T = nums[2]

ants = []

for i in range(N):
    nums=list(map(int,input().split()))
    if nums[1] == 1:
        ants.append(Ant(nums[0], CLOCKWISE))
    else:
        ants.append(Ant(nums[0], COUNTERCLOCKWISE))
    

lower = ants[0].x
upper = (ants[0].x + T) % L

cnt_neg = -1
cnt_pos = 0

for i in range(N):
    if ants[0].w == ants[i].w and (ants[0].x - ants[i].x) % L < T:
        cnt_neg += 1
    elif ants[0].w != ants[i].w and (ants[i].x - ants[0].x) % L < 2 * T:
        cnt_pos += 1

result = []
for i in range(N):
    result.append((ants[i].x + T * ants[i].w) % L)


if cnt_pos % 2 == 1:
    cnt_neg += 1

if ants[0].w == CLOCKWISE:
    for i in range(- cnt_neg + 1 , N - cnt_neg + 1):
        print(result[i])
else:
    for i in range(- cnt_neg, N - cnt_neg):
        print(result[i])

Submission status: Runtime Error

Solution code:
# %%
# VScodeで入力をテキストから読み込んで標準入力に渡す
import sys
import os
f=open(r'.\ant_1-6-2_AGC013C\AGC013_input.txt', 'r', encoding="utf-8")
# inputをフルパスで指定
# win10でファイルを作るとs-jisで保存されるため、読み込みをutf-8へエンコードする必要あり
# VScodeでinput file開くとutf8になってるんだけど中身は結局s-jisになっているらしい
sys.stdin=f

#
# 入力スニペット
# num = int(input())
# num_list = [int(item) for item in input().split()]
# num_list = [input() for _ in range(3)]
##################################
# %%
# 以下ペースト可
N, L, T = [int(item) for item in input().split()]
pos_list = [[int(item) for item in input().split()] for _ in range(N)]

num = 0
next_list = []

for i, item in enumerate(pos_list):
    a, b = item
    next_list.append([a, b, i])

while T >= 1:
    pos_list, next_list = next_list, []
    # print(pos_list)
    for pos, direction, num in pos_list:
        if direction == 1:
            pos = (pos + 1) % L
            next_list.append([pos, direction, num])

        else:
            pos = (pos -1) % L
            if pos < 0:
                pos += 8
            next_list.append([pos, direction, num])
        
        num += 1

    for i in range(N):
        
        is_contact = False

        if next_list[i][1] == 1:
            if next_list[i][0] == (next_list[(i+1)%N][0] + 1) % L:
                next_list[i][1], next_list[(i+1)%N][1] = next_list[(i+1)%N][1], next_list[i][1]
                next_list[i][0], next_list[(i+1)%N][0] = next_list[(i+1)%N][0], next_list[i][0]
        else:
            if next_list[i][0] == (next_list[(i-1)%N][0] - 1) % L:
                next_list[i][1], next_list[(i-1)%N][1] = next_list[(i-1)%N][1], next_list[i][1]
                next_list[i][0], next_list[(i-1)%N][0] = next_list[(i-1)%N][0], next_list[i][0]

    T -= 1

# print(next_list)

for item in next_list:
    print(item[0])

Submission status: Runtime Error

Solution code:
N, L, T = [int(item) for item in input().split()]
pos_list = [[int(item) for item in input().split()] for _ in range(N)]

num = 0
next_list = []

for i, item in enumerate(pos_list):
    next_list.append([*item , i])

while T >= 1:
    pos_list, next_list = next_list, []
    # print(pos_list)
    for pos, direction, num in pos_list:
        if direction == 1:
            pos = (pos + 1) % L
            next_list.append([pos, direction, num])

        else:
            pos = (pos -1) % L
            if pos < 0:
                pos += 8
            next_list.append([pos, direction, num])
        
        num += 1

    for i in range(N):
        
        is_contact = False

        if next_list[i][1] == 1:
            if next_list[i][0] == (next_list[(i+1)%N][0] + 1) % L:
                next_list[i][1], next_list[(i+1)%N][1] = next_list[(i+1)%N][1], next_list[i][1]
                next_list[i][0], next_list[(i+1)%N][0] = next_list[(i+1)%N][0], next_list[i][0]
        else:
            if next_list[i][0] == (next_list[(i-1)%N][0] - 1) % L:
                next_list[i][1], next_list[(i-1)%N][1] = next_list[(i-1)%N][1], next_list[i][1]
                next_list[i][0], next_list[(i-1)%N][0] = next_list[(i-1)%N][0], next_list[i][0]

    T -= 1

# print(next_list)

for item in next_list:
    print(item[0])

Submission status: Runtime Error

Solution code:
N, L, T = [int(item) for item in input().split()]
pos_list = [[int(item) for item in input().split()] for _ in range(N)]

num = 0
next_list = []

for i, item in enumerate(pos_list):
    next_list.append([*item , i])

while T >= 0:
    pos_list, next_list = next_list, []
    # print(pos_list)
    for pos, direction, num in pos_list:
        if direction == 1:
            pos = (pos + 1) % L
            next_list.append([pos, direction, num])

        else:
            pos = (pos -1) % L
            if pos < 0:
                pos += 8
            next_list.append([pos, direction, num])
        
        num += 1

    for i in range(N):
        
        is_contact = False

        if next_list[i][1] == 1:
            if next_list[i][0] == (next_list[(i+1)%N][0] + 1) % L:
                next_list[i][1], next_list[(i+1)%N][1] = next_list[(i+1)%N][1], next_list[i][1]
                # next_list[i][2], next_list[(i+1)%N][2] = next_list[(i+1)%N][2], next_list[i][2]
        else:
            if next_list[i][0] == (next_list[(i-1)%N][0] - 1) % L:
                next_list[i][1], next_list[(i-1)%N][1] = next_list[(i-1)%N][1], next_list[i][1]
                # next_list[i][2], next_list[(i-1)%N][2] = next_list[(i-1)%N][2], next_list[i][2]

    T -= 1

print(*[item[0] for item in next_list])

Submission status: Runtime Error

Solution code:
def next_ants(r_ants, l_ants, r_ants_cord, l_ants_cord):
    for i,c in enumerate(r_ants_cord[::]):
        r_ants_cord[i] = (c + 0.5) % L
    for i,c in enumerate(l_ants_cord[::]):
        l_ants_cord[i] = (c - 0.5) % L
    for i,r_cord in enumerate(r_ants_cord):
        for j,l_cord in enumerate(l_ants_cord):
            if r_cord == l_cord:
                r_ant = r_ants[i]
                l_ant = l_ants[j]
                r_ants[i] = l_ant
                l_ants[j] = r_ant
    return (r_ants, l_ants, r_ants_cord, l_ants_cord)
N,L,T = [int(x) for x in input().split()]
r_ants = []
r_ants_cord = []
l_ants = []
l_ants_cord = []
for i in range(N):
    x,w = [int(x) for x in input1().split()]
    if w == 1:
        r_ants.append(i)
        r_ants_cord.append(x)
    else:
        l_ants.append(i)
        l_ants_cord.append(x)
for _ in range(2 * T):
    r_ants, l_ants, r_ants_cord, l_ants_cord = next_ants(r_ants, l_ants, r_ants_cord, l_ants_cord)
for i in range(N):
    if i in r_ants:
        print(int(r_ants_cord[r_ants.index(i)]))
    else:
        print(int(l_ants_cord[l_ants.index(i)]))

Submission status: Runtime Error

Solution code:
n,l,t=map(int,input().split())
xw=[list(map(int,input().split())) for _ in [0]*n]

first_x=xw[0][0]
first_w=xw[0][1]

right=[]
left=[]

for x,w in xw:
    if w==1:
        right.append(x)
    else:
        left.append(x)

if first_w==1:
    left=[(i-first_x)/2 for i in left]
    right.reverse()
    right=[(l+first_x-i)/2 for i in right]
else:
    right=[(l+first_x-i)/2 for i in right]
    right.reverse()
    left=[(i-first_x)/2 for i in left[1:]]+[l/2]
    
ll=len(left)
lr=len(right)

def search(cnt):
    w=first_w
    if ll==0 or lr==0:
        return None
    elif cnt==0:
        return [0,0,0]
    elif w==1:
        right_temp=((cnt//2+cnt%2-1)//ll)*(l/2)+left[(cnt//2+cnt%2-1)%ll]
        left_temp=max((((cnt-2)//2)//lr),0)*(l/2)+right[((cnt-2)//2)%lr]*(cnt!=1)
    else:
        left_temp=((cnt//2+cnt%2-1)//lr)*(l/2)+right[(cnt//2+cnt%2-1)%lr]
        right_temp=max((((cnt-1)//2)//ll),0)*(l/2)+left[((cnt-2)//2)%ll]*(cnt!=1)
    return [left_temp+right_temp,right_temp,left_temp]

def b_search(a,b,p,value):
    med=(a+b)//2
    if a==b:return a
    if a+1==b:
        if value(b)[0]<=p:return b
        else:return a
    elif value(med)[0]<=p:return b_search(med,b,p,value)
    else:return b_search(a,med-1,p,value)

a=b_search(0,10**9,t,search)

if a==False:
    last=((first_x+t*int((-first_w+1.5)*2))%l+l)%l
else:
    b=search(a)
    if (a+first_w)%2==1:
        b[1]+=t-b[0]
    else:
        b[2]+=t-b[0]
    last=int(((first_x+b[1]-b[2])%l+l)%l)
    
ans=sorted([((x+t*int((-w+1.5)*2))%l+l)%l for x,w in xw])
    
for i in range(n):
    if last==ans[i]:
        if i==n-1:
            break
        elif ans[i+1]!=last:
            break
        else:
            if (a+first_w)%2==1:
                break
            else:
                i+=1
                break
for j in ans[i:]+ans[:i]:
    print(j)