Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
c = 0
for idx, i in enumerate(a):
  if idx %2 ==0:
    c += i
  else: 
    c -= i
x1 = c/2
print(x1)
for i in range(1,N):
  x1 = 2*a[i] - x1
  print(x1)


Fixed submission:
import numpy as np

n = map(int, raw_input().split())

x = map(int, raw_input().split())
n = n[0]
ans = []

x = np.asarray(x)
double_x = 2 * x
x0 = 0
multiple = 1
for j in range(n):
    x0 += x[j] * multiple
    multiple *= -1
ans.append(x0)
for i in range(0, n-1):
    ans.append(double_x[i] - ans[i])

print ' '.join(map(str, ans))

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

n = map(int, raw_input().split())

x = map(int, raw_input().split())
n = n[0]
ans = []

x = np.asarray(x)
for i in range(n):
    one_ans = 0
    multiple = -1
    for j in range(n):
        one_ans += x[(i+j)%n] * multiple
        multiple *= -1
    one_ans += 2*x[i]
    ans.append(int(one_ans))
last = ans.pop()
ans.insert(0, last)
print ' '.join(map(str, ans))


Fixed submission:
import numpy as np

n = map(int, raw_input().split())

x = map(int, raw_input().split())
n = n[0]
ans = []

x = np.asarray(x)
double_x = 2 * x
x0 = 0
multiple = 1
for j in range(n):
    x0 += x[j] * multiple
    multiple *= -1
ans.append(x0)
for i in range(0, n-1):
    ans.append(double_x[i] - ans[i])

print ' '.join(map(str, ans))

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

n = map(int, raw_input().split())

x = map(int, raw_input().split())
n = n[0]
ans = []

x = np.asarray(x)
for i in range(n):
    a = np.ones(n)
    multiple = -1
    for j in range(n):
        a[(i+j)%n] *= multiple
        multiple *= -1
    a[i] = 1
    ans.append(int(np.dot(x, a)))
last = ans.pop()
ans.insert(0, last)
print ' '.join(map(str, ans))


Fixed submission:
import numpy as np

n = map(int, raw_input().split())

x = map(int, raw_input().split())
n = n[0]
ans = []

x = np.asarray(x)
double_x = 2 * x
x0 = 0
multiple = 1
for j in range(n):
    x0 += x[j] * multiple
    multiple *= -1
ans.append(x0)
for i in range(0, n-1):
    ans.append(double_x[i] - ans[i])

print ' '.join(map(str, ans))
Buggy python submission (verdict: Runtime Error):
N = int(input())
res = 'No'
for i in range(int(100/7)+1):
	for j in range(int(100/4)+1):
		a = i*7 + j*4
		if int(N) == a:
			res='Yes'
print(res)


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

a = [0] * K

for i in range(N):
  a[i%K] +=1

print(max(a) - min(a))
Buggy python submission (verdict: Runtime Error):
import sys
N = map(int, input().split())
N = N[0]
for i in range(int(100/7)+1):
	for j in range(int(100/4)+1):
		a = i*7 + j*4
		if int(N) == a:
			print('Yes')
			sys.exit();

print('No')


Fixed submission:
N = int(input())
res = 'No'
for i in range(int(100/7)+1):
	for j in range(int(100/4)+1):
		a = i*7 + j*4
		if int(N) == a:
			res='Yes'
print(res)

Buggy python submission (verdict: Runtime Error):
import sys
N = map(int, '4'.split())
N = N[0]
for i in range(int(100/7)+1):
	for j in range(int(100/4)+1):
		a = i*7 + j*4
		if int(N) == a:
			print('Yes')
			sys.exit();

print('No')


Fixed submission:
N = int(input())
res = 'No'
for i in range(int(100/7)+1):
	for j in range(int(100/4)+1):
		a = i*7 + j*4
		if int(N) == a:
			res='Yes'
print(res)

Buggy python submission (verdict: Runtime Error):
N = map(int, input().split())

for i in range(int(100/7)+1):
  for j in range(int(100/4)+1):
    if i*7 + j*4 == N:
      print('Yes')
      return
print('No')
      

Fixed submission:
N = int(input())
res = 'No'
for i in range(int(100/7)+1):
	for j in range(int(100/4)+1):
		a = i*7 + j*4
		if int(N) == a:
			res='Yes'
print(res)
Buggy python submission (verdict: Runtime Error):
s=input()
if s[0]==s[1]==s[2] or =s[0]==s[1]==s[2]:
  print("No")
else:
  print("Yes")

Fixed submission:
s=input()
if s[0]==s[1]==s[2] or s[0]==s[1]==s[2]:
  print("No")
else:
  print("Yes")
Buggy python submission (verdict: Runtime Error):
import sys
# Xはもっとも近い整数，Nは与えられるP
X,N = map(int, input().split())

if N == 0:
  print(X)
  sys.exit()

arr = list(map(int, input().split()))
mainasu = X 
purasu = X 

def saiki():
  mainasu - 1
  purasu + 1
  if X in arr:
    if mainasu in arr:
      if purasu in arr:
        saiki()
      else:
        print(purasu)
    else:
      print(mainasu)
  else:
    print(X)

saiki()

Fixed submission:
import sys

def saiki(l,r,lst):
  if (l - 1) not in lst:
      return (l - 1)
  
  if (r + 1) not in lst:
      return (r + 1)
  
  return saiki(l - 1, r + 1, lst)

def main():
  # Xはもっとも近い整数，Nは与えられるP
  X,N = map(int, input().split())

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

  if N == 0:
    print(X)
    sys.exit()

  if X not in arr:
    print(X)
    sys.exit()

  print(saiki(X,X,arr))

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
import sys
# Xはもっとも近い整数，Nは与えられるP
X,N = map(int, input().split())

if N == 0:
  print(X)
  sys.exit()

arr = list(map(int, input().split()))
mainasu = X 
purasu = X 

def saiki():
  mainasu = mainasu - 1
  purasu = purasu + 1
  if X in arr:
    if mainasu in arr:
      if purasu in arr:
        saiki()
      else:
        print(purasu)
    else:
      print(mainasu)
  else:
    print(X)

saiki()

Fixed submission:
import sys

def saiki(l,r,lst):
  if (l - 1) not in lst:
      return (l - 1)
  
  if (r + 1) not in lst:
      return (r + 1)
  
  return saiki(l - 1, r + 1, lst)

def main():
  # Xはもっとも近い整数，Nは与えられるP
  X,N = map(int, input().split())

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

  if N == 0:
    print(X)
    sys.exit()

  if X not in arr:
    print(X)
    sys.exit()

  print(saiki(X,X,arr))

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
import sys
# Xはもっとも近い整数，Nは与えられるP
X,N = map(int, input().split())

if N == 0:
  print(X)
  sys.exit()

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

def saiki():
  mainasu = X - 1
  purasu = X + 1
  if X in arr:
    if mainasu in arr:
      if purasu in arr:
        saiki()
      else:
        print(purasu)
    else:
      print(mainasu)
  else:
    print(X)

saiki()

Fixed submission:
import sys

def saiki(l,r,lst):
  if (l - 1) not in lst:
      return (l - 1)
  
  if (r + 1) not in lst:
      return (r + 1)
  
  return saiki(l - 1, r + 1, lst)

def main():
  # Xはもっとも近い整数，Nは与えられるP
  X,N = map(int, input().split())

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

  if N == 0:
    print(X)
    sys.exit()

  if X not in arr:
    print(X)
    sys.exit()

  print(saiki(X,X,arr))

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
a,b,c,k=map(int, input().split())
""" a:1
    b:0
    c:-1
"""
nokori=k
sum_max=0
while nokori>0:
    nokori-=1
    if(a>0):
        sum_max+=1
        a-=1
        continue
    if(b>0):
        b-=1
        continue
    if(c>0):
        sum_max-=1
        c-=1
    

print(sum_max)

Fixed submission:
a,b,c,k=map(int, input().split())
""" a:1
    b:0
    c:-1
"""
sum_max=0
minus=0
if(a+b>=k):
    if(a>=k):
        sum_max=k
    else:
        sum_max=a
else:
    minus=k-(a+b)
    sum_max=a-minus




print(sum_max)
Buggy python submission (verdict: Time Limit Exceeded):
a,b,n=map(int ,input().split())
val=0
for x in range(n+1):
    tmp_val=int(a*x/b)-a*int(x/b)
    val=max(tmp_val,val)
print(val)

Fixed submission:
A,B,N=map(int,input().split())
if(N>=B-1):
    x=B-1
if(N<B-1):
    x=N
ans=int(A*x/B)-A*int(x/B)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
a,b,n=map(int ,input().split())
val=0
for x in range(n+1):
    tmp_val=int(a*x/b)-a*int(x/b)
    val=max(tmp_val,val)
print(val)

Fixed submission:
A,B,N=map(int,input().split())
if(N>=B-1):
    x=B-1
if(N<B-1):
    x=N
ans=int(A*x/B)-A*int(x/B)
print(ans)
Buggy python submission (verdict: Runtime Error):
s=int(input())
w=int(input())
if(s<=w):
    print("unsafe")
if(s>w):
    print("safe")

Fixed submission:
s,w =map(int,input().split())
if(s<=w):
    print('unsafe')
if(s>w):
    print('safe')

Buggy python submission (verdict: Runtime Error):
s=int(input())
w=int(input())
if(s<=w):
    print("unsafe")
else:
    print("safe")

Fixed submission:
s,w =map(int,input().split())
if(s<=w):
    print('unsafe')
if(s>w):
    print('safe')
Buggy python submission (verdict: Runtime Error):
a=int(input())#takahashi
b=int(input())
c=int(input())#aoki
d=int(input())
flag=True
while flag:
    c-=b
    if(c<=0):
        flag=False
        print("Yes")
        break
        
    a-=d
    if(a<=0):
        falg=False
        print("No")
        break

Fixed submission:
a,b,c,d=map(int,input().split())
flag=True
while flag:
    c-=b
    if(c<=0):
        flag=False
        print("Yes")
        break
        
    a-=d
    if(a<=0):
        falg=False
        print("No")
        break
Buggy python submission (verdict: Time Limit Exceeded):
import math
K=int(input())
sum_gcd=0
for a in range(1,K+1):
    for b in  range(1,K+1):
        for c in  range(1,K+1):
            sum_gcd+=math.gcd(c,math.gcd(a,b))
print(sum_gcd)

Fixed submission:
import math
K=int(input())
dp=[[0][0]]*K
sum_gcd=0
c=1
for a in range(1,K+1):
    for b in  range(1,K+1):
            for c in  range(1,K+1):
                sum_gcd+=math.gcd(c,math.gcd(a,b))
print(sum_gcd)
Buggy python submission (verdict: Runtime Error):
h1, m1, h2, m2, k = map(int, input().split())
 
f = h1 * 60 + m1
t = h2 * 60 + m2
 
if time < 0:
  print(0)
else:
  print(time)

Fixed submission:
h1, m1, h2, m2, k = map(int, input().split())

f = h1 * 60 + m1
t = h2 * 60 + m2

time = t - f - k
if time < 0:
  print(0)
else:
  print(time)

Buggy python submission (verdict: Runtime Error):
h1, m1, h2, m2, k = map(int, input().split())

f = h1 * 60 + m1
t = h2 * 60 + m2

print(time)
if time < 0:
  print(0)
else:
  print(time)



Fixed submission:
h1, m1, h2, m2, k = map(int, input().split())

f = h1 * 60 + m1
t = h2 * 60 + m2

time = t - f - k
if time < 0:
  print(0)
else:
  print(time)
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

a, b, n = map(int, input().split())

ans_list = []

for i in range(int(b / 2), n + 1):
  #print(int((a * i) / b), a * int(i / b), int((a * i) / b) - a * int(i / b))
  ans = int((a * i) / b) - a * int(i / b)
  ans_list.append(ans)
print(max(ans_list))



Fixed submission:
# -*- coding: utf-8 -*-
# x = p * b + q
# 0 <= q < b
# int(a * p + a * q / b) - a * int(p - q / b)
# = a * p + int(a * q / b) - a * p
# = int(a * q / b)

a, b, n = map(int, input().split())

print(a * min(b - 1, n) //  b)

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

a, b, n = map(int, input().split())

ans_list = []

for i in range(int(b / 10), n + 1):
  #print(int((a * i) / b), a * int(i / b), int((a * i) / b) - a * int(i / b))
  ans = int((a * i) / b) - a * int(i / b)
  ans_list.append(ans)
print(max(ans_list))



Fixed submission:
# -*- coding: utf-8 -*-
# x = p * b + q
# 0 <= q < b
# int(a * p + a * q / b) - a * int(p - q / b)
# = a * p + int(a * q / b) - a * p
# = int(a * q / b)

a, b, n = map(int, input().split())

print(a * min(b - 1, n) //  b)

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

a, b, n = map(int, input().split())

ans_list = []

for i in range(int(b / 1000000), n + 1):
  #print(int((a * i) / b), a * int(i / b), int((a * i) / b) - a * int(i / b))
  ans = int((a * i) / b) - a * int(i / b)
  ans_list.append(ans)
print(max(ans_list))



Fixed submission:
# -*- coding: utf-8 -*-
# x = p * b + q
# 0 <= q < b
# int(a * p + a * q / b) - a * int(p - q / b)
# = a * p + int(a * q / b) - a * p
# = int(a * q / b)

a, b, n = map(int, input().split())

print(a * min(b - 1, n) //  b)

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

a, b, n = map(int, input().split())

ans_list = []

for i in range(n + 1):
  #print(int((a * i) / b), a * int(i / b), int((a * i) / b) - a * int(i / b))
  ans = int((a * i) / b) - a * int(i / b)
  ans_list.append(ans)
print(max(ans_list))



Fixed submission:
# -*- coding: utf-8 -*-
# x = p * b + q
# 0 <= q < b
# int(a * p + a * q / b) - a * int(p - q / b)
# = a * p + int(a * q / b) - a * p
# = int(a * q / b)

a, b, n = map(int, input().split())

print(a * min(b - 1, n) //  b)
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

a, b, c, d = map(int, input().split(' '))

n = max([int(a / d) + 1, int (c / b) + 1])

for i in range(n):
    a -= d
    c -= b
    # print(a,c)
    if c <= 0:
        print('Yes')
        exit()
    elif a <= 0:
        print('No')
        exit()

Fixed submission:
# -*- coding: utf-8 -*-

n = int(input())

kind = []

for i in range(n):
    kind.append(input())

print(len(set(kind)))
Buggy python submission (verdict: Runtime Error):
n = int(input())
boss_list = list(map(int, input().split(' ')))

# for i in range(n):
#     print(boss_list.count(i + 1))

import collections
c = collections.Counter(boss_list)

for i in range(n):
    print(boss_list[i + 1])

Fixed submission:
n = int(input())
boss_list = list(map(int, input().split(' ')))

# for i in range(n):
#     print(boss_list.count(i + 1))

import collections
c = collections.Counter(boss_list)

for i in range(n):
    print(c[i + 1])

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
boss_list = list(map(int, input().split(' ')))

for i in range(n):
    print(boss_list.count(i + 1))


Fixed submission:
n = int(input())
boss_list = list(map(int, input().split(' ')))

# for i in range(n):
#     print(boss_list.count(i + 1))

import collections
c = collections.Counter(boss_list)

for i in range(n):
    print(c[i + 1])
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

k = int(input())

sum = 0
for p in range(k):
    for q in range(k):
        for r in range(k):
            sum += gcd(p + 1, q + 1, r + 1)
print(sum)


Fixed submission:
import math
# from functools import reduce

# def gcd(*numbers):
#     return reduce(math.gcd, numbers)

k = int(input())

sum = 0
for p in range(k):
    for q in range(k):
        n = math.gcd(p + 1, q + 1)
        for r in range(k):
            sum += math.gcd(n, r + 1)
print(sum)

Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

import math

k = int(input())

sum = 0
for p in range(k):
    for q in range(k):
        for r in range(k):
            sum += math.gcd(p + 1, q + 1, r + 1)
print(sum)

Fixed submission:
import math
# from functools import reduce

# def gcd(*numbers):
#     return reduce(math.gcd, numbers)

k = int(input())

sum = 0
for p in range(k):
    for q in range(k):
        n = math.gcd(p + 1, q + 1)
        for r in range(k):
            sum += math.gcd(n, r + 1)
print(sum)
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

import collections

n = int(input())
balls = list(map(int, input().split(' ')))

for k in range(n):
    # print(balls[ : k])
    # print(balls[ k + 1: ])
    arr = balls[ : k] + balls[ k + 1 : ]

    dic = collections.Counter(arr)
    total = 0
    for v in dic.values():
        total += int(v * (v - 1) / 2)
    print(total)



Fixed submission:
# -*- coding: utf-8 -*-

m, n = map(int, input().split(' '))

print(int(m * (m - 1) / 2 + n * (n - 1) / 2))
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

# import collections

n = int(input())
balls = list(map(int, input().split(' ')))

for k in range(n):
    # print(balls[ : k])
    # print(balls[ k + 1: ])
    arr = balls[ : k] + balls[ k + 1 : ]

    total = 0
    # dic = collections.Counter(arr)
    # for v in dic.values():
    #     total += int(v * (v - 1) / 2)

    # print(arr, list(set(arr)))
    for num in list(set(arr)):
        v = arr.count(num)
        total += int(v * (v - 1) / 2)
    print(total)



Fixed submission:
# -*- coding: utf-8 -*-

import collections

n = int(input())
balls = list(map(int, input().split(' ')))

dic = collections.Counter(balls)
total = 0
for v in dic.values():
    if (v < 2):
        continue
    total += int(v * (v - 1) / 2)

for i in range(n):
    num = balls[i]
    print(total - dic[num] + 1)

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

import collections

n = int(input())
balls = list(map(int, input().split(' ')))

for k in range(n):
    # print(balls[ : k])
    # print(balls[ k + 1: ])
    arr = balls[ : k] + balls[ k + 1 : ]

    dic = collections.Counter(arr)
    total = 0
    for v in dic.values():
        total += int(v * (v - 1) / 2)
    print(total)



Fixed submission:
# -*- coding: utf-8 -*-

import collections

n = int(input())
balls = list(map(int, input().split(' ')))

dic = collections.Counter(balls)
total = 0
for v in dic.values():
    if (v < 2):
        continue
    total += int(v * (v - 1) / 2)

for i in range(n):
    num = balls[i]
    print(total - dic[num] + 1)

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

import collections

n = int(input())
balls = list(map(int, input().split(' ')))

for k in range(n):
    # print(balls[ : k])
    # print(balls[ k + 1: ])
    arr = balls[ : k] + balls[ k + 1 : ]

    dic = collections.Counter(arr)
    total = 0
    for v in dic.values():
        total += int(v * (v - 1) / 2)
    print(total)



Fixed submission:
# -*- coding: utf-8 -*-

import collections

n = int(input())
balls = list(map(int, input().split(' ')))

dic = collections.Counter(balls)
total = 0
for v in dic.values():
    if (v < 2):
        continue
    total += int(v * (v - 1) / 2)

for i in range(n):
    num = balls[i]
    print(total - dic[num] + 1)
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
# 157b
a = []
b = []
check_list = [False] * 9
for _ in range(3);
  a.extend(list(map(int, input().split())))
n = int(input())
for _ in range(n);
  b.append(int(input()))

for _b in b:
  if _b in a:
    check_list[a.index(_b)] = True

if check_list[0] and check_list[1] and check_list[2]\
  or check_list[3] and check_list[4] and check_list[5]\
  or check_list[6] and check_list[7] and check_list[8]\
  or check_list[0] and check_list[3] and check_list[6]\
  or check_list[1] and check_list[4] and check_list[7]\
  or check_list[2] and check_list[5] and check_list[8]\
  or check_list[0] and check_list[4] and check_list[8]\
  or check_list[2] and check_list[4] and check_list[6]:
  print('Yes')
else:
  print('No')


Fixed submission:
a = []
a.extend(map(int, input().split()))
a.extend(map(int, input().split()))
a.extend(map(int, input().split()))
n = int(input())
b = []

for i in range(n):
  b.append(int(input()))

#print(a, b)

for i in range(len(b)):
  a = [0 if mas == b[i] else mas for mas in a]

if a[0] == 0 and a[1] == 0 and a[2] == 0\
   or a[3] == 0 and a[4] == 0 and a[5] == 0\
   or a[6] == 0 and a[7] == 0 and a[8] == 0\
   or a[0] == 0 and a[3] == 0 and a[6] == 0\
   or a[1] == 0 and a[4] == 0 and a[7] == 0\
   or a[2] == 0 and a[5] == 0 and a[8] == 0\
   or a[0] == 0 and a[4] == 0 and a[8] == 0\
   or a[2] == 0 and a[4] == 0 and a[6] == 0:
  print('Yes')
else:
  print('No')
Buggy python submission (verdict: Time Limit Exceeded):
#155c
import collections
n = int(input())
s = [input() for _ in range(n)]

c = collections.Counter(s)
ret = []
tmp = []

for k, v in c.most_common():
  if max(c.values()) == v:
    ret.append(k)
  else:
    break

for r in sorted(ret):
  print(r)


Fixed submission:
#155c
import collections
n = int(input())
s = [input() for _ in range(n)]

c = collections.Counter(s)
ret = []
tmp = []
max_v = max(c.values())

for k, v in c.most_common():
  if max_v == v:
    ret.append(k)
  else:
    break

for r in sorted(ret):
  print(r)
Buggy python submission (verdict: Runtime Error):
#154c
n = int(input())
a = [input() for _ in range(n)]

if len(list(set(a))) != len(a):
  print('NO')
else:
  print('YES')

Fixed submission:
#154c
n = int(input())
a = list(input().split())

if len(list(set(a))) != len(a):
  print('NO')
else:
  print('YES')
Buggy python submission (verdict: Runtime Error):
A,V = map(int,input().split())
B,W = map(int,input().split())
T = int(input())

if abs(A-B)/abs(W-V) > T:
    print('NO')
else:
    print('YES')

Fixed submission:
A,V = map(int,input().split())
B,W = map(int,input().split())
T = int(input())

if W>=V or abs(A-B)/abs(W-V) > T:
    print('NO')
else:
    print('YES')
Buggy python submission (verdict: Runtime Error):
T = list(input())

for i in reversed(range(len(T))):
    if T[i] == '?':
        if i == len(T)-1:
            T[i] = 'D'
        if T[i+1] == 'D':
            T[i] = 'P'
        else:
            T[i] = 'D'
    else:
        continue

print(''.join(T))

Fixed submission:
import copy
T = list(input())
P = [0]*(len(T)+10)
P[0] = 0
if T[0] == '?':
    T[0] = 'D'
for i in range(len(T)):
    if T[i] == '?':
        if T[i-1] == 'D':
            T[i] = 'D'
            P[i+1] = P[i] + 1
        else:
            T[i] = 'D'
            P[i+1] = P[i] + 2
    else:
        if T[i] == 'D':
            if T[i-1] == 'D':
                P[i+1] += P[i]+1
            else:
                P[i+1] = P[i]+2
        else: 
            P[i+1] = P[i]   


print(''.join(T))
Buggy python submission (verdict: Runtime Error):
tmp = input().split()
N = int(tmp[0])
S = [0 for i in range(N)]
T = [0 for i in range(N)]

for n in range(N):
    tmp = input().split()
    S[n] = int(tmp[0])
    T[n] = int(tmp[1])


#total 
mod =  1000000007

dp[0] = 0

for i in range(N+1):
    
    out = 0
    for k in range(i):
        if S[k]*S[i]+T[k]*T[i] == 0:
            ++out
    dp[i+1] = dp[i]*2 - out 
    dp[i+1] = dp[i+1] %mod
print(dp[N])


Fixed submission:
from collections import deque

tmp = input().split()
N = int(tmp[0])
M = int(tmp[1])
ve = [deque() for _ in range(N)]
todo = deque()

s = 0
for m in range(M):
    S, T  = map(int,input().split())
    ve[S-1].append(T)
    ve[T-1].append(S)

visited = [False]*N
dist = [0]*N
todo.append(1)
   
while len(todo)>0:
    now = todo.popleft()   
    while len(ve[now-1])>0:
        sr = ve[now-1].pop()
        if  visited[sr-1]: continue
        dist[sr-1] = now
        visited[sr-1] = True
        todo.append(sr)

print('Yes')
[print(i) for i in dist[1:]]
Buggy python submission (verdict: Runtime Error):
tmp = input().split()
N = int(tmp[0])
K = int(tmp[1])

tmp = input().split()

Map = [0]*N
GroupFlag = [0]*N

for i in range(N):
    Map[i] = int(tmp[i])

for i in range(N):
    nexti = Map[i]
    GroupFlag[nexti-1] = 1
GroupFlag[0] = 1
NN = sum(GroupFlag)
K = K%NN
if K == 0:
    K = NN

rt = [0]*K

def trip(self, steps):
    ntown = Map[self-1]
    if steps == K:
        return ntown
    rt[steps]=trip(ntown,steps+1)


    
Ft = trip(1,0)
print(rt[K-1])


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

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

Visited = [-1]*N
now = 1
Order = [0]*N

loopcount = 1
Order[0] = 1
Visited[0] = 1
for i in range(1,N):
    nt = Map[now-1]
    Order[i] = nt
    loopcount += 1
    if Visited[nt-1] == -1:
        Visited[nt-1] = loopcount
    else:
        break
    now = nt
    

ns = Visited[nt-1]
period = loopcount - ns

if period == 0:
    period = loopcount
    ns = 0

Kmod = K - ns
if Kmod > 0:
    Kmod %= period

print(Order[ns+Kmod])

Buggy python submission (verdict: Runtime Error):
tmp = input().split()
N = int(tmp[0])
K = int(tmp[1])

tmp = input().split()

Map = [0]*N
K = K%N
rt = [0]*K

for i in range(N):
    Map[i] = int(tmp[i])

def trip(self, steps):
    ntown = Map[self-1]
    if steps == K:
        return ntown
    rt[steps]=trip(ntown,steps+1)


    
Ft = trip(1,1)
print(rt[K-1])


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

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

Visited = [-1]*N
now = 1
Order = [0]*N

loopcount = 1
Order[0] = 1
Visited[0] = 1
for i in range(1,N):
    nt = Map[now-1]
    Order[i] = nt
    loopcount += 1
    if Visited[nt-1] == -1:
        Visited[nt-1] = loopcount
    else:
        break
    now = nt
    

ns = Visited[nt-1]
period = loopcount - ns

if period == 0:
    period = loopcount
    ns = 0

Kmod = K - ns
if Kmod > 0:
    Kmod %= period

print(Order[ns+Kmod])