Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
H, W = map(int, input().split())
a = [list(map(int, input().split())) for i in range(H)]
c = 0
N = 0
ans = []
for i in range(H):
  for j in range(W):
    if a[i][j]%2==1:
      c+=1
      
while c>1:
  if a[i][j]%2==1:
    if i-1>=0 and a[i-1][j]%2==1:
      ans.append([i+1,j+1,i,j+1])
      c-=2
      a[i][j] -= 1
      a[i-1][j] += 1
      
    elif j-1>=0 and a[i][j-1]%2==1:
      ans.append([i+1,j+1,i+1,j])
      c-=2
      a[i][j] -= 1
      a[i][j-1] += 1
        
    elif j+1<W and a[i][j+1]%2==1:
      ans.append([i+1,j+1,i+1,j+2])
      c-=2
      a[i][j] -= 1
      a[i][j+1] += 1
      
    elif i+1<H and a[i+1][j]%2==1:
      ans.append([i+1,j+1,i+2,j+1])
      c-=2
      a[i][j] -= 1
      a[i+1][j] += 1
        
    elif i-1>=0:
      ans.append([i+1,j+1,i,j+1])
      a[i][j] -= 1
      a[i-1][j] += 1
      
    elif j-1>=0:
      ans.append([i+1,j+1,i+1,j])
      a[i][j] -= 1
      a[i][j-1] += 1
      
    elif j+1<W:
      ans.append([i+1,j+1,i+1,j+2])
      a[i][j] -= 1
      a[i][j+1] += 1
      
    elif i+1<H:
      ans.append([i+1,j+1,i+2,j+1])
      a[i][j] -= 1
      a[i+1][j] += 1
      
    N += 1
  if j+1==W:
    if i+1 == H:
      i = 0
      j = 0
    else:
      i +=1
  else:
    j+=1
    
        
print(N)
for i in range(N):
  L=[str(x) for x in ans[i]]
  L=" ".join(L)
  print(L)
  


Fixed submission:
H, W = map(int, input().split())
a = [list(map(int, input().split())) for i in range(H)]
c = 0
N = 0
ans = []
for i in range(H):
  for j in range(W):
    if a[i][j]%2==1:
      if j+1<W:
        ans.append([i+1,j+1,i+1,j+2])
        a[i][j]-=1
        a[i][j+1]+=1
        N += 1
      elif i+1<H:
        a[i][j]-=1
        a[i+1][j]+=1
        ans.append([i+1,j+1,i+2,j+1])
        N += 1
    
        
print(N)
for i in range(N):
  L=[str(x) for x in ans[i]]
  L=" ".join(L)
  print(L)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
a = 0
ans = [0, 0]
for i in range(N):
  for j in range(i+1, N):
    if A[i] < A[j] and (A[j]-A[i])*A[i]>=a:
      ans = [A[j], A[i]]
      a = (A[j]-A[i])*A[i]
    elif (A[i]-A[j])*A[j]>=a:
      ans = [A[i], A[j]]
      a = (A[i]-A[j])*A[j]
ans = [str(b) for b in ans]
ans = ' '.join(ans)
print(ans)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
A.sort()
M = A[-1]
a = M // 2
for i in range(N-1):
  if A[i] <= a and A[i+1] >= a:
    if (M-A[i])*A[i] >= (M-A[i+1])*A[i+1]:
      ans = [M, A[i]]
    else:
      ans = [M, A[i+1]]
ans = [str(b) for b in ans]
ans = ' '.join(ans)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
A.sort()
ans = 0
b = 0
for i in range(N):
    if i == b:
        a = A.count(A[i])
        b = i + a
        if A[i] > a:
            ans += a
        elif A[i] < a:
            ans += a - A[i]
print(ans)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
A.sort()
old = A[0]
ans = 0
a = 1
for i in range(1, N):
  if A[i] == old: 
    a += 1
  else:
    if old > a:
      ans += a
    elif old < a:
      ans += a - old
    old = A[i]
    a = 1
if old > a:
  ans += a
elif old < a:
  ans += a - old
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
A.sort()
B = list(set(A))
ans = 0
n = len(B)
for i in range(n):
  b = B[i]
  c = A.count(b)
  if c < b:
    ans += c
  elif c > b:
    ans += c-b
print(ans)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
A.sort()
old = A[0]
ans = 0
a = 1
for i in range(1, N):
  if A[i] == old: 
    a += 1
  else:
    if old > a:
      ans += a
    elif old < a:
      ans += a - old
    old = A[i]
    a = 1
if old > a:
  ans += a
elif old < a:
  ans += a - old
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
A.sort()
ans = 0
while len(A) > 0:
  a = A[0]
  c = A.count(a)
  if c < a:
    ans += c
  elif c > a:
    ans += c-a
  while A[0] == a:
    if len(A) > 1:
      A.pop(0)
    else:
      A.pop(0)
      break
print(ans)   

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
A.sort()
old = A[0]
ans = 0
a = 1
for i in range(1, N):
  if A[i] == old: 
    a += 1
  else:
    if old > a:
      ans += a
    elif old < a:
      ans += a - old
    old = A[i]
    a = 1
if old > a:
  ans += a
elif old < a:
  ans += a - old
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a = list(map(int, input().split()))
A = []
for i in range(N):
  A.append(a[i]-1)
  A.append(a[i])
  A.append(a[i]+1)
ans = 0
for a in A:
  if ans < A.count(a):
    ans = A.count(a)
print(ans)

Fixed submission:
N = int(input())
a = list(map(int, input().split()))
a.sort()
oldi = 0
m = a[0]
M = 0
ans = 0
if N == 1:
  ans = 1
for i in range(1, N):
  M = a[i]
  while M - m > 2:
    oldi += 1
    m = a[oldi]
  if i - oldi + 1 > ans:
    ans = i - oldi + 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a = list(map(int, input().split()))
s = a[:1]
t = a[1:]
x = sum(s)
y = sum(t)
if x-y==0:
  ans = 0
else:
  ans = abs(x-y)

for i in range(2,N):
  s = a[:i]
  t = a[i:]
  x = sum(s)
  y = sum(t)
  if x-y==0:
    ans = 0
    break
  elif abs(x-y)<ans:
    ans = abs(x-y)
print(ans)

Fixed submission:
N = int(input())
a = list(map(int, input().split()))
s = a[:1]
t = a[1:]
x = sum(s)
y = sum(t)
if x==y:
  ans = 0
else:
  ans = abs(x-y)

for i in range(1,N-1):
  x += a[i]
  y -= a[i]
  if x==y:
    ans = 0
    break
  elif abs(x-y)<ans:
    ans = abs(x-y)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
b = []
for i in range(n):
  if n % 2 == i % 2:
    b.append(a[i])
  else:
    b.insert(0, a[i])
b = [str(bb) for bb in b]
b = ' '.join(b)
print(b)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
b = []
m1 = n//2
if n%2==0:
  
  for i in range(m1):
    b.append(a[n-1-2*i])
  for i in range(m1):
    b.append(a[2*i])
else:
  
  for i in range(m1+1):
    b.append(a[n-1-2*i])
  for i in range(m1):
    b.append(a[1+2*i])
  
  
  
b=[str(c) for c in b]
b=" ".join(b)
print(b)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
b = []
for i in range(n):
  b.append(a[i])
  b = b[::-1]
  
b=[str(c) for c in b]
b=" ".join(b)
print(b)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
b = []
m1 = n//2
if n%2==0:
  
  for i in range(m1):
    b.append(a[n-1-2*i])
  for i in range(m1):
    b.append(a[2*i])
else:
  
  for i in range(m1+1):
    b.append(a[n-1-2*i])
  for i in range(m1):
    b.append(a[1+2*i])
  
  
  
b=[str(c) for c in b]
b=" ".join(b)
print(b)
Buggy python submission (verdict: Runtime Error):
N = int(input())
a = list(map(int, input().split()))
A = [0 for i in range(8)]
b = 0
ans1 = 0
for i in range(N):
  if a[i] < 400:
    if A[0] == 0:
      A[0] = 1
      ans1 += 1
    else:
      continue
  elif a[i] < 800:
    if A[1] == 0:
      A[1] = 1
      ans1 += 1
    else:
      continue
  elif a[i] < 1200:
    if A[2] == 0:
      A[2] = 1
      ans1 += 1
    else:
      continue
  elif a[i] < 1600:
    if A[3] == 0:
      A[3] = 1
      ans1 += 1
    else:
      continue
  elif a[i] < 2000:
    if A[4] == 0:
      A[4] = 1
      ans1 += 1
    else:
      continue
  elif a[i] < 2400:
    if A[5] == 0:
      A[5] = 1
      ans1 += 1
    else:
      continue
  elif a[i] < 2800:
    if A[6] == 0:
      A[6] = 1
      ans1 += 1
    else:
      continue
  elif a[i] < 3200:
    if A[7] == 0:
      A[7] = 1
      ans += 1
    else:
      continue
  else:
    b += 1
ans2 = ans1 + b
if ans1 < 1:
  ans1 = 1
  ans2 = b
if ans2 > 8:
  ans2 = 8
print(ans1, ans2, sep=' ')

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
B = [0 for i in range(8)]
a = 0
for i in range(N):
  if A[i] < 400:
    B[0] = 1
  elif A[i] < 800:
    B[1] = 1
  elif A[i] < 1200:
    B[2] = 1
  elif A[i] < 1600:
    B[3] = 1
  elif A[i] < 2000:
    B[4] = 1
  elif A[i] < 2400:
    B[5] = 1
  elif A[i] < 2800:
    B[6] = 1
  elif A[i] < 3200:
    B[7] = 1
  else:
    a += 1
b = sum(B)
m = b
M = b + a
if b == 0:
  m = 1
print(m, M, sep=' ')

Buggy python submission (verdict: Runtime Error):
N = int(input())
a = list(map(int, input().split()))
A = [0 for i in range(8)]
b = 0
ans1 = 0
for i in range(N):
  if a[i] < 400:
    if A[0] == 0:
      A[0] = 1
      ans1 += 1
  elif a[i] < 800:
    if A[1] == 0:
      A[1] = 1
      ans1 += 1
  elif a[i] < 1200:
    if A[2] == 0:
      A[2] = 1
      ans1 += 1
  elif a[i] < 1600:
    if A[3] == 0:
      A[3] = 1
      ans1 += 1
  elif a[i] < 2000:
    if A[4] == 0:
      A[4] = 1
      ans1 += 1
  elif a[i] < 2400:
    if A[5] == 0:
      A[5] = 1
      ans1 += 1
  elif a[i] < 2800:
    if A[6] == 0:
      A[6] = 1
      ans1 += 1
  elif a[i] < 3200:
    if A[7] == 0:
      A[7] = 1
      ans += 1
  elif a[i] >= 3200:
    b += 1
ans2 = ans1 + b
if ans1 < 1:
  ans1 = 1
  ans2 = b
if ans2 > 8:
  ans2 = 8
print(ans1, ans2, sep=' ')

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
B = [0 for i in range(8)]
a = 0
for i in range(N):
  if A[i] < 400:
    B[0] = 1
  elif A[i] < 800:
    B[1] = 1
  elif A[i] < 1200:
    B[2] = 1
  elif A[i] < 1600:
    B[3] = 1
  elif A[i] < 2000:
    B[4] = 1
  elif A[i] < 2400:
    B[5] = 1
  elif A[i] < 2800:
    B[6] = 1
  elif A[i] < 3200:
    B[7] = 1
  else:
    a += 1
b = sum(B)
m = b
M = b + a
if b == 0:
  m = 1
print(m, M, sep=' ')
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
an = []
for i in range(N):
  a, b = map(int, input().split())
  for j in range(b):
    an.append(a)
an.sort()
ans = an[K-1]
print(ans)

Fixed submission:
N, K = map(int, input().split())
a = [list(map(int, input().split())) for i in range(N)]
a.sort()
ans = a[0][0]
b = a[0][1]
i = 1
while b < K:
  ans = a[i][0]
  b += a[i][1]
  i += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
####################################################################
import sys
def _p(*_a):
  #return
  _s=" ".join(map(str,_a))
  #print(_s)
  sys.stderr.write(_s+"\n")
####################################################################
def _pa(_aa):
  #return
  for _a in _aa: _p(_a)
####################################################################

HH,WW,MM = map(int, input().split())

H=[0] * HH
W=[0] * WW
M = [[0]*WW for i in range(HH)]

for _ in range(MM):
  h,w = map(int, input().split())
  M[h-1][w-1] += 1
  H[h-1] += 1
  W[w-1] += 1

hm = max(H)
wm = max(W)

# _p(hm,wm)
# _pa(M)

HI = [i for i, x in enumerate(H) if x == hm]
WI = [i for i, x in enumerate(W) if x == wm]

# _p(HI)
# _p(WI)

ans = 0
for h in HI:
  for w in WI:
    ans = max(ans, hm + wm - M[h][w])

print(ans)


Fixed submission:
####################################################################
import sys
def _p(*_a):
  #return
  _s=" ".join(map(str,_a))
  #print(_s)
  sys.stderr.write(_s+"\n")
####################################################################
def _pa(_aa):
  #return
  for _a in _aa: _p(_a)
####################################################################

HH,WW,MM = map(int, input().split())

H=[0] * HH
W=[0] * WW

from collections import defaultdict
d = defaultdict(int)

for _ in range(MM):
  nh,nw = map(int, input().split())
  h = nh - 1
  w = nw - 1
  d[h * 1000000 + w] = 1
  H[h] += 1
  W[w] += 1

hm = max(H)
wm = max(W)

# _p(hm,wm)
# _pa(M)

HI = [i for i, x in enumerate(H) if x == hm]
WI = [i for i, x in enumerate(W) if x == wm]

# _p(HI)
# _p(WI)

ans = hm + wm
for h in HI:
  for w in WI:
    if d[h * 1000000 + w] == 0:
      print(ans)
      exit()

print(ans-1)
Buggy python submission (verdict: Time Limit Exceeded):
# import io
# import sys

# _INPUT = """\
# 1 4 120
# 100 1 1 1 1 1 1 1 1 1 1
# 80 10 10 10 10
# """
# sys.stdin = io.StringIO(_INPUT)

####################################################################
import sys
def p(*_a):
  return
  _s=" ".join(map(str,_a))
  #print(_s)
  sys.stderr.write(_s+"\n")
####################################################################

N,M,K = map(int, input().split())
A = [0] + [int(i) for i in input().split()]
B = [0] + [int(i) for i in input().split()]


# 累積和
from itertools import accumulate
C = list(accumulate(A))
D = list(accumulate(B))

p(*C)
p(*D)

ans = 0

for i, c in enumerate(C):
  for j, d in enumerate(D):
    p(i,j,c,d)
    if c + d > K: break
    ans = max(ans, i+j)

print(ans)


Fixed submission:
# import io
# import sys

# _INPUT = """\
# 1 4 120
# 100 1 1 1 1 1 1 1 1 1 1
# 80 10 10 10 10
# """
# sys.stdin = io.StringIO(_INPUT)

####################################################################
import sys
def p(*_a):
  return
  _s=" ".join(map(str,_a))
  #print(_s)
  sys.stderr.write(_s+"\n")
####################################################################

N,M,K = map(int, input().split())
A = [0] + [int(i) for i in input().split()]
B = [0] + [int(i) for i in input().split()]


# 累積和
from itertools import accumulate
C = list(accumulate(A))
D = list(accumulate(B))

p(*C)
p(*D)

ans = 0
d = len(D) - 1
for c in range(len(C)):
  if C[c] > K: break
  while True:
    if C[c] + D[d] <= K: break
    d -= 1

  ans = max(ans , c + d)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())						# 5
A =        list( map(int, input().split()) )	# 1 2 3 4 5 ...

A.sort()

ans=0
for i in range(N):
  for j in range(N):
    if i==j: continue
    if A[i] % A[j] == 0: break
    if A[i] < A[j]:
      ans += 1
      break
  else:
    ans += 1

print(ans)



Fixed submission:
N = int(input())						# 5
A =        list( map(int, input().split()) )	# 1 2 3 4 5 ...

A.sort()
maxA = A[-1]
X = [0]*(maxA+1)


for a in A:
  for i in range(1,maxA+1):
    x = a*i
    if x > maxA: break
    X[x] += 1

ans = 0
for a in A:
  if X[a]==1: ans+=1

print(ans)
# print(A)
# print(X)
Buggy python submission (verdict: Time Limit Exceeded):
#-------------------------------------------------------------------
#-------------------------------------------------------------------
# import io
# import sys

# _INPUT = """\
# 20 200000
# 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
# """
# sys.stdin = io.StringIO(_INPUT)

#-------------------------------------------------------------------
#-------------------------------------------------------------------
#-------------------------------------------------------------------
import sys
def p(*_a):
  #return
  _s=" ".join(map(str,_a))
  #print(_s)
  sys.stderr.write(_s+"\n")
#-------------------------------------------------------------------

N,K = map(int, input().split())

A = list( map(int, input().split()) )	# 1 2 3 4 5 ...

from itertools import accumulate

for k in range(K):
  B=[0]*N
  for i,d in enumerate(A):
    l = max(0, i-d)
    r = i+d+1

    B[l]+=1
    if r<N: B[r]-=1

  A = list(accumulate(B))
  if A.count(N)==N: break
  # p("A=",A)
  # p("B=",B)

print(*A)


Fixed submission:
N,K = map(int, input().split())

A = list( map(int, input().split()) )	# 1 2 3 4 5 ...

from itertools import accumulate

for _ in range(K):
  B=[0]*N
  for i,d in enumerate(A):
    l = max(0, i-d)
    r = i+d+1

    B[l]+=1
    if r<N: B[r]-=1

  A = list(accumulate(B))
  if A.count(N)==N: break
  # p("A=",A)
  # p("B=",B)

print(*A)
Buggy python submission (verdict: Runtime Error):
999999999999999 1.11

Fixed submission:
a,b = map(float, input().split())
a = int(a)

x = a // 1000 * (1000 *b)
y = a % 1000

ans = int(x) + int(y*b)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
#-------------------------------------------------------------------
import sys
def p(*_a):
  _s=" ".join(map(str,_a))
  #print(_s)
  sys.stderr.write(_s+"\n")
#-------------------------------------------------------------------
import math

def factorize(n):
  ret, a = [], n
  for i in range(2, int(n**0.5)+1):
    if a%i>0: continue
    c=0
    while a%i==0:
      a//=i
      c+=1
    else:
      ret.append((i,c))
  if a!=1: ret.append((a,1))
  return ret

#nの素数判定
def is_prime(n):
	if n == 1:
		return False
	for i in range(2,int(n**0.5)+1):
		if n % i == 0: return False
	return True


n = int(input())
N = factorize(n)
#p(N)

i = 2
ans=0
while n >= i:
  if is_prime(n):
    n /= n
    ans += 1
    #p("ans=",ans)
  elif n % i ==0:
    for k,_ in N:
      a = math.log(i, k)
      #p("n,i,k,a,int(a)=",n,i,k,int(a),a)
      if int(a)==a:
        n /= i
        ans += 1
        #p("ans=",ans)

  i += 1

print(ans)


Fixed submission:
#-------------------------------------------------------------------
import sys
def _p(*_a):
  _s=" ".join(map(str,_a))
  #print(_s)
  sys.stderr.write(_s+"\n")
#-------------------------------------------------------------------
import math

def factorize(n):
  ret, a = [], n
  for i in range(2, int(n**0.5)+1):
    if a%i>0: continue
    c=0
    while a%i==0:
      a//=i
      c+=1
    else:
      ret.append((i,c))
  if a!=1: ret.append((a,1))
  return ret


n = int(input())
N = factorize(n)

ans=0
for p,i in N:
  for j in range(i):
    a = pow(p,j+1)
    if n % a == 0:
      n /= a
      ans += 1

print(ans)
Buggy python submission (verdict: Runtime Error):
#-------------------------------------------------------------------
import sys
def p(*_a):
  _s=" ".join(map(str,_a))
  #print(_s)
  sys.stderr.write(_s+"\n")
#-------------------------------------------------------------------
N,K = map(int, input().split())		# 5 7 2
A = [0] + list( map(int, input().split()) )	# 1 2 3 4 5 ...


M = [ [0,0] for _ in range(N+1) ]			#=> [[], [], [], [], [], [], [], []]

p(M)

i = 1
x = y = 0
for k in range(1, K+1):
	x,y = M[i]
	
	if x==0:
		M[i][0] = A[i]
		M[i][1] = k
		i = A[i]
	
	else:
		
		break

else:
	ans = i
	print(ans)
	exit(0)


p(x,y,k)
p("M[1:]", M[1:])

k = k - y

j = k % (k-y)

for a in range(j):
	x,y = M[i]
	M[i][0] = A[i]
	M[i][1] = k
	i = A[i]

print(i)	

Fixed submission:
#-------------------------------------------------------------------
import sys
def p(*_a):
  _s=" ".join(map(str,_a))
  #print(_s)
  sys.stderr.write(_s+"\n")
#-------------------------------------------------------------------
N,K = map(int, input().split())		# 5 7 2
A = [0] + list( map(int, input().split()) )	# 1 2 3 4 5 ...


M = [ [0,0] for _ in range(N+1) ]			#=> [[], [], [], [], [], [], [], []]

p(M)

i = 1
x = y = 0
for k in range(K):
	x,y = M[i]
	
	if x==0:
		M[i][0] = A[i]
		M[i][1] = k
		i = A[i]
		continue
	
	
	a = K - y
	b = a % (k-y)
	for _ in range(b):
		i = A[i]
	
	p(x,y,k)
	p("M[1:]", M[1:])
	
	break

ans = i
print(ans)

Buggy python submission (verdict: Runtime Error):
#-------------------------------------------------------------------
import sys
def p(*_a):
  _s=" ".join(map(str,_a))
  #print(_s)
  sys.stderr.write(_s+"\n")
#-------------------------------------------------------------------
N,K = map(int, input().split())		# 5 7 2
A = [0] + list( map(int, input().split()) )	# 1 2 3 4 5 ...


M = [ [0,0] for _ in range(N+1) ]			#=> [[], [], [], [], [], [], [], []]

p(M)

i = 1
x = y = 0
for k in range(1, K+1):
	x,y = M[i]
	
	if x==0:
		M[i][0] = A[i]
		M[i][1] = k
		i = A[i]
	
	else:
		
		break

else:
	ans = i
	print(ans)
	exit(0)


p(x,y,k)
p("M[1:]", M[1:])

k = k - y

j = k % (k-y)

i = 
for a in range(j):
	x,y = M[i]
	M[i][0] = A[i]
	M[i][1] = k
	i = A[i]

print(i)	

Fixed submission:
#-------------------------------------------------------------------
import sys
def p(*_a):
  _s=" ".join(map(str,_a))
  #print(_s)
  sys.stderr.write(_s+"\n")
#-------------------------------------------------------------------
N,K = map(int, input().split())		# 5 7 2
A = [0] + list( map(int, input().split()) )	# 1 2 3 4 5 ...


M = [ [0,0] for _ in range(N+1) ]			#=> [[], [], [], [], [], [], [], []]

p(M)

i = 1
x = y = 0
for k in range(K):
	x,y = M[i]
	
	if x==0:
		M[i][0] = A[i]
		M[i][1] = k
		i = A[i]
		continue
	
	
	a = K - y
	b = a % (k-y)
	for _ in range(b):
		i = A[i]
	
	p(x,y,k)
	p("M[1:]", M[1:])
	
	break

ans = i
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
#-------------------------------------------------------------------
import sys
def p(*_a):
  _s=" ".join(map(str,_a))
  #print(_s)
  sys.stderr.write(_s+"\n")
#-------------------------------------------------------------------


s = input()
q = int(input())

r=0

for i in range(q):
	t = input()
	
	if t=='1':
		r = (r+1)%2
#		p("t,r,s",t,r,s)
		continue
	
	_,f,c = t.split()

	z=r
	if f=='1': z =  r
	if f=='2': z = (r+1)%2
	
	if z==0: s = c + s
	if z==1: s = s + c

#	p("t,r,_,f,c,z,s","[",t,"]",r,_,f,c,z,s)

if (r==0):
	print(s)
else:
	print(s[::-1])


	
	

Fixed submission:
#-------------------------------------------------------------------
import sys
def p(*_a):
  _s=" ".join(map(str,_a))
  #print(_s)
  sys.stderr.write(_s+"\n")
#-------------------------------------------------------------------
s = input()
q = int(input())

r=0

a=""
z=""

for i in range(q):
	t = input()
	
	if t=='1':
		if r==0:
			r=1
		else:
			r=0
#		p("t,r,s",t,r,s)
		continue
	
	_,f,c = t.split()

	if f=='1':
		if r==0: a = a + c
		if r==1: z = z + c
	if f=='2':
		if r==0: z = z + c
		if r==1: a = a + c


#	p("t,r,_,f,c,x,s","[",t,"]",r,_,f,c,x,s)

ans=""
if (r==0):
	ans = a[::-1] + s + z
else:
	ans = z[::-1] + s[::-1] + a

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
#-------------------------------------------------------------------
#-------------------------------------------------------------------
import sys
def p(*_a):
  _s=" ".join(map(str,_a))
  #print(_s)
  sys.stderr.write(_s+"\n")
#-------------------------------------------------------------------
H,W = map(int, input().split())			# "5 7" -> ["5", "7"] -> 5, 7 => N=5,K=7

S=[ "" for _ in range(H+2) ]
#p(S)

S[0]="#"*(W+2)
S[H+1]="#"*(W+2)
for h in range(1,H+1):
	s = input()
	S[h] = "#" + s + "#"

#p(S)

XY=[[1,0],[-1,0],[0,1],[0,-1]]

INF=float("inf") # 正の無限大
ans=0

from collections import deque

for h in range(1,H+1):
	for w in range(1,W+1):

		if S[h][w]=="#": continue

		M=[[ INF for w in range(W+2) ] for h in range(H+2)]
		M[h][w]=0

		Q = deque()
		Q.append([h,w])
		mmax=0

		#p("Q=",Q)
		
		while Q:
			h,w=Q.pop()
			
			if S[h][w]=="#": continue
			
			m = M[h][w]
			mmax=max(mmax,m)
			for x,y in XY:
				if S[h+y][w+x]=="#": continue
				
				if M[h+y][w+x] > (m+1):
					M[h+y][w+x] = m+1
					Q.append([h+y,w+x])
					mmax=max(mmax,m+1)

			#p("h,w,Q,m=",h,w,Q,m)

		for MH in M:
			for m in MH:
				if m==INF: continue
				ans=max(ans,m)


#for m in M:
#	print(m)

print(ans)

Fixed submission:
# coding: utf-8
#-------------------------------------------------------------------
#-------------------------------------------------------------------
import sys
def p(*_a):
  _s=" ".join(map(str,_a))
  #print(_s)
  sys.stderr.write(_s+"\n")
#-------------------------------------------------------------------
H,W = map(int, input().split())			# "5 7" -> ["5", "7"] -> 5, 7 => N=5,K=7

S=[ "" for _ in range(H+2) ]
#p(S)

S[0]="#"*(W+2)
S[H+1]="#"*(W+2)
for h in range(1,H+1):
	s = input()
	S[h] = "#" + s + "#"

#p(S)

XY=[[1,0],[-1,0],[0,1],[0,-1]]

INF=float("inf") # 正の無限大
ans=0

from collections import deque

for h in range(1,H+1):
	for w in range(1,W+1):

		if S[h][w]=="#": continue

		M=[[ INF for w in range(W+2) ] for h in range(H+2)]
		M[h][w]=0

		Q = deque()
		Q.append([h,w])
		mmax=0

		#p("Q=",Q)
		
		while Q:
			h,w=Q.popleft()
			
			if S[h][w]=="#": continue
			
			m = M[h][w]
			mmax=max(mmax,m)
			for x,y in XY:
				if S[h+y][w+x]=="#": continue
				
				if M[h+y][w+x] > (m+1):
					M[h+y][w+x] = m+1
					Q.append([h+y,w+x])
					mmax=max(mmax,m+1)

			#p("h,w,Q,m=",h,w,Q,m)

		for MH in M:
			for m in MH:
				if m==INF: continue
				ans=max(ans,m)


#for m in M:
#	print(m)

print(ans)