Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
h,w=map(int,input().split())
a=[list(input().split()) for _ in range(h)]

#タテのチェック
for i in range(w):
	tmp=0
	for j in range(h):
		if a[j][i]=="#":
			tmp=1
	if tmp==0:
		for j in range(h):
			a[j][i]="0"

#ヨコのチェック
for i in range(h):
	if not "#" in a[i][:]:
		a[i][:]=[0]*w

for i in range(h):
	tmpl=[]
	for j in range(w):
		if not a[i][j]=="0":
			tmpl.append(a[i][j])
	if "#" in tmpl or "." in tmpl:
		print("".join(tmpl))		#listを詰めて表示

Fixed submission:
h,w=map(int,input().split())
a=[]
for _ in range(h):
	b=[]
	s=input()
	for i in range(w):
		b.append(s[i])
	a.append(b)
	
#タテのチェック
for i in range(w):
	tmp=0
	for j in range(h):
		if a[j][i]=="#":
			tmp=1
	if tmp==0:
		for j in range(h):
			a[j][i]="0"

#ヨコのチェック
for i in range(h):
	if not "#" in a[i][:]:
		a[i][:]=[0]*w

for i in range(h):
	tmpl=[]
	for j in range(w):
		if not a[i][j]=="0":
			tmpl.append(a[i][j])
	if "#" in tmpl or "." in tmpl:
		print("".join(tmpl))		#listを詰めて表示

Buggy python submission (verdict: Runtime Error):
h,w=map(int,input().split())
a=[list(input().split()) for _ in range(h)]

#タテのチェック
for i in range(w):
	tmp=0
	for j in range(h):
		if a[j][i]=="#":
			tmp=1
	if tmp==0:
		for j in range(h):
			a[j][i]="0"

#ヨコのチェック
for i in range(h):
	if not "#" in a[i][:]:
		a[i][:]=[0]*w

for i in range(h):
	tmpl=[]
	for j in range(w):
		if not a[i][j]=="0":
			tmpl.append(a[i][j])
	if "#" in tmpl or "." in tmpl:
		print(" ".join(tmpl))

Fixed submission:
h,w=map(int,input().split())
a=[]
for _ in range(h):
	b=[]
	s=input()
	for i in range(w):
		b.append(s[i])
	a.append(b)
	
#タテのチェック
for i in range(w):
	tmp=0
	for j in range(h):
		if a[j][i]=="#":
			tmp=1
	if tmp==0:
		for j in range(h):
			a[j][i]="0"

#ヨコのチェック
for i in range(h):
	if not "#" in a[i][:]:
		a[i][:]=[0]*w

for i in range(h):
	tmpl=[]
	for j in range(w):
		if not a[i][j]=="0":
			tmpl.append(a[i][j])
	if "#" in tmpl or "." in tmpl:
		print("".join(tmpl))		#listを詰めて表示

Buggy python submission (verdict: Runtime Error):
h,w=map(int,input().split())
a=[list(input().split()) for _ in range(h)]

#タテのチェック
for i in range(w):
	tmp=0
	for j in range(h):
		if a[j][i]=="#":
			tmp=1
	if tmp==0:
		for j in range(h):
			a[j][i]="0"

#ヨコのチェック
for i in range(h):
	if not "#" in a[i][:]:
		a[i][:]=[0]*w

for i in range(h):
	tmpl=[]
	for j in range(w):
		if not a[i][j]=="0":
			tmpl.append(a[i][j])
	if "#" in tmpl or "." in tmpl:
		print(" ".join(tmpl))		

Fixed submission:
h,w=map(int,input().split())
a=[]
for _ in range(h):
	b=[]
	s=input()
	for i in range(w):
		b.append(s[i])
	a.append(b)
	
#タテのチェック
for i in range(w):
	tmp=0
	for j in range(h):
		if a[j][i]=="#":
			tmp=1
	if tmp==0:
		for j in range(h):
			a[j][i]="0"

#ヨコのチェック
for i in range(h):
	if not "#" in a[i][:]:
		a[i][:]=[0]*w

for i in range(h):
	tmpl=[]
	for j in range(w):
		if not a[i][j]=="0":
			tmpl.append(a[i][j])
	if "#" in tmpl or "." in tmpl:
		print("".join(tmpl))		#listを詰めて表示
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))

ans = 1
for i in a:
    ans *= i
if ans > 10**18:
    print(-1)
else:
    print(ans)

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

if 0 in a:
   print(0)
   exit()
ans = 1
for i in a:
    ans *= i
    if ans > 10**18:
        print(-1)
        exit()
print(ans)
Buggy python submission (verdict: Runtime Error):
dic = {}
for key, a in zip(range(1, n+1), list(map(int,input().split()))):
    dic[key] = a
 
keynum = 0
log = [-1]*(n+1)
next = dic[1]
step = 1
log[next] = step
k -= 1
while k:
    next = dic[next]
    step += 1
    k -= 1
    if log[next] != -1:
        k %= log[next] - step
    else:
        log[next] = step
print(next)

Fixed submission:
n,k = map(int,input().split())
a = list(map(int,input().split()))
dic = {}
for key, a in zip(range(1, n+1), a):
    dic[key] = a
 
log = [-1]*(n+1)
next = dic[1]
step = 1
log[next] = step
k -= 1
while k:
    next = dic[next]
    step += 1
    k -= 1
    if log[next] != -1:
        k %= log[next] - step
    else:
        log[next] = step
print(next)

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

dic = {}
for key, a in zip(range(1, n+1), list(map(int,input().split()))):
    dic[key] = a
 
keynum = 0
log = [1]
next = dic[1]
log.append(next)
k -= 1
while k:
    next = dic[next]
    if next in log:
        keynum = log.index(next)
        k -= 1
        break
    log.append(next)
    k -= 1
looplen = len(log[keynum:])
if k < len(log[keynum:]):
    print(log[-1])
else:
    res = k%looplen
    print(log[keynum+res])

Fixed submission:
n,k = map(int,input().split())
a = list(map(int,input().split()))
dic = {}
for key, a in zip(range(1, n+1), a):
    dic[key] = a
 
log = [-1]*(n+1)
next = dic[1]
step = 1
log[next] = step
k -= 1
while k:
    next = dic[next]
    step += 1
    k -= 1
    if log[next] != -1:
        k %= log[next] - step
    else:
        log[next] = step
print(next)
Buggy python submission (verdict: Runtime Error):
x = int(input())
count = 0
while money < x:
    money = int(money * 1.01)
    count += 1
print(count)


Fixed submission:
money = 100
x = int(input())
count = 0
while money < x:
    money = int(money * 1.01)
    count += 1
print(count)
Buggy python submission (verdict: Time Limit Exceeded):
import math
from functools import reduce

k = int(input())
ans = 0

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

for i in range(1,k+1):
    for j in range(1,k+1):
        for l in range(1,k+1):
            ans += gcd(i,j,l)
print(ans)

Fixed submission:
import math
k = int(input())

ans = 0

for i in range(1,k+1):
    for j in range(1,k+1):
        a = math.gcd(i, j)
        for l in range(1,k+1):
            ans += math.gcd(a,l)
print(ans)
Buggy python submission (verdict: Runtime Error):
import math

a,b,c,d = map(int,input().split())
tn = b-a+1


cn = (b//c)-(a-1)//c
dn = (b//d)-(a-1)//d
#最少公倍数
cd = (c*d)//math.gcd(c, d)
cdn = (b//cd)-(a-1)//cd

print(int(tn-cn-dn+cdn))

Fixed submission:
import fractions

a,b,c,d = map(int,input().split())
tn = b-a+1

cn = (b//c)-(a-1)//c
dn = (b//d)-(a-1)//d
cd = (c*d)//fractions.gcd(c, d)
cdn = (b//cd)-(a-1)//cd

print(tn-cn-dn+cdn)

Buggy python submission (verdict: Runtime Error):
import math

a,b,c,d = map(int,input().split())
tn = b-a+1


cn = (b//c)-(a-1)//c
dn = (b//d)-(a-1)//d
#最少公倍数
cd = (c*d)//math.gcd(c, d)
cdn = (b//cd)-(a-1)//cd

print(tn-cn-dn+cdn)

Fixed submission:
import fractions

a,b,c,d = map(int,input().split())
tn = b-a+1

cn = (b//c)-(a-1)//c
dn = (b//d)-(a-1)//d
cd = (c*d)//fractions.gcd(c, d)
cdn = (b//cd)-(a-1)//cd

print(tn-cn-dn+cdn)

Buggy python submission (verdict: Runtime Error):
import math

a,b,c,d = map(int,input().split())
tn = b-a+1


cn = b//c-(a-1)//c
dn = b//d-(a-1)//d
#最少公倍数
cd = (c*d)//math.gcd(c, d)
cdn = b//cd-(a-1)//cd

print(tn-cn-dn+cdn)

Fixed submission:
import fractions

a,b,c,d = map(int,input().split())
tn = b-a+1

cn = (b//c)-(a-1)//c
dn = (b//d)-(a-1)//d
cd = (c*d)//fractions.gcd(c, d)
cdn = (b//cd)-(a-1)//cd

print(tn-cn-dn+cdn)

Buggy python submission (verdict: Runtime Error):
import math

a,b,c,d = map(int,input().split())
tn = b-a+1

cn = (b//c)-(a-1)//c
dn = (b//d)-(a-1)//d
cd = (c*d)//math.gcd(c, d)
cdn = (b//cd)-(a-1)//cd

print(tn-cn-dn+cdn)

Fixed submission:
import fractions

a,b,c,d = map(int,input().split())
tn = b-a+1

cn = (b//c)-(a-1)//c
dn = (b//d)-(a-1)//d
cd = (c*d)//fractions.gcd(c, d)
cdn = (b//cd)-(a-1)//cd

print(tn-cn-dn+cdn)

Buggy python submission (verdict: Runtime Error):
import math

a,b,c,d = map(int,input().split())
tn = b-a+1

cn = (b//c)-((a-1)//c)
dn = (b//d)-((a-1)//d)
cd = (c * d) // math.gcd(c, d)
cdn = (b//cd)-((a-1)//cd)

print(tn-cn-dn+cdn)

Fixed submission:
import fractions

a,b,c,d = map(int,input().split())
tn = b-a+1

cn = (b//c)-(a-1)//c
dn = (b//d)-(a-1)//d
cd = (c*d)//fractions.gcd(c, d)
cdn = (b//cd)-(a-1)//cd

print(tn-cn-dn+cdn)

Buggy python submission (verdict: Runtime Error):
import math

def lcm(x, y):
    return (x * y) // math.gcd(x, y)


a,b,c,d = map(int,input().split())
tn = b-a+1


cn = (b//c)-((a-1)//c)
dn = (b//d)-((a-1)//d)

cd = lcm(c,d)
cdn = (b//cd)-((a-1)//cd)

print(tn-cn-dn+cdn)

Fixed submission:
import fractions

a,b,c,d = map(int,input().split())
tn = b-a+1

cn = (b//c)-(a-1)//c
dn = (b//d)-(a-1)//d
cd = (c*d)//fractions.gcd(c, d)
cdn = (b//cd)-(a-1)//cd

print(tn-cn-dn+cdn)

Buggy python submission (verdict: Runtime Error):
import math

def lcm(x, y):
    return (x * y) // math.gcd(x, y)


a,b,c,d = map(int,input().split())
tn = b-a+1


cn = (b//c)-((a-1)//c)
dn = (b//d)-((a-1)//d)

cd = lcm(c,d)
cdn = (b//cd)-((a-1)//cd)



print(tn,cn,dn,cdn)
print(tn-cn-dn+cdn)

Fixed submission:
import fractions

a,b,c,d = map(int,input().split())
tn = b-a+1

cn = (b//c)-(a-1)//c
dn = (b//d)-(a-1)//d
cd = (c*d)//fractions.gcd(c, d)
cdn = (b//cd)-(a-1)//cd

print(tn-cn-dn+cdn)
Buggy python submission (verdict: Runtime Error):
n,k = map(int,input().split())
if n%k = 0 :
  print(0)
else:
  print(1)

Fixed submission:
n,k = map(int,input().split())
if n % k == 0 :
  print(0)
else:
  print(1)
Buggy python submission (verdict: Runtime Error):
n,k = map(int,input().split())
a = list(map(int,input().split()))
ans = 0
m = 0
if a[0] == 1 or a[1]==1 or a[2]==1:
    for i in range(n-2):
        if a[i] == a[i+1] == a[i+2] or a[i] == a[i+1]:
            if a[i+2] == a[n-1]:
                a[i] = min(a[i],a[i+1],a[i+2])
                a[i+1] = min(a[i],a[i+1],a[i+2])
                a[i+2] = min(a[i],a[i+1],a[i+2])
                ans+= 1
            else:
                continue

        else:
            a[i] = min(a[i],a[i+1],a[i+2])
            a[i+1] = min(a[i],a[i+1],a[i+2])
            a[i+2] = min(a[i],a[i+1],a[i+2])
            ans+= 1
else:
    for i in range(n):
        if a[i]==1:
            m = i
            break
    for i in range(m,n-2):
        if a[i] == a[i+1] == a[i+2] or a[i] == a[i+1]:
            if a[i+2] == a[n-1]:
                a[i] = min(a[i],a[i+1],a[i+2])
                a[i+1] = min(a[i],a[i+1],a[i+2])
                a[i+2] = min(a[i],a[i+1],a[i+2])
                ans+= 1
            else:
                continue
        else:
            a[i] = min(a[i],a[i+1],a[i+2])
            a[i+1] = min(a[i],a[i+1],a[i+2])
            a[i+2] = min(a[i],a[i+1],a[i+2])
            ans+= 1
    for i in reversed(range(m)):
        if a[i] == a[i-1] == a[i-2] or a[i] == a[i-1]:
            if a[i-2] == a[0]:
                a[i] = min(a[i],a[i-1],a[i-2])
                a[i+1] = min(a[i],a[i-1],a[i-2])
                a[i+2] = min(a[i],a[i-1],a[i-2])
                ans+= 1
            else:
                continue
        else:
            a[i] = min(a[i],a[i-1],a[i-2])
            a[i+1] = min(a[i],a[i-1],a[i-2])
            a[i+2] = min(a[i],a[i-1],a[i-2])
            ans+= 1
print(ans)

Fixed submission:
N,K = map(int,input().split())
A = list(input())
Ans = 0
 
if (N-1)%(K-1)==0:
    Ans = (N-1)//(K-1)
else:
    Ans = (N-1)//(K-1) + 1
 
print(Ans)
Buggy python submission (verdict: Runtime Error):
a,b = map(int,input())
if a > 8 or b > 8:
    print(":(")
else:
    print("Yay!")

Fixed submission:
a,b = map(int,input().split())
if a > 8 or b > 8:
    print(":(")
else:
    print("Yay!")

Buggy python submission (verdict: Runtime Error):
a = int(input())
b = int(input())
if a > 8 or b > 8:
    print(":(")
else:
    print("Yay!")

Fixed submission:
a,b = map(int,input().split())
if a > 8 or b > 8:
    print(":(")
else:
    print("Yay!")
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = list(input())
Count = n
for i in range(n):
    f = s[:i]
    r = s[(i+1):]
    count = f.count("W")+r.count("E")
    if Count > count:
        Count = count
print(Count)
    

Fixed submission:
n = int(input())
s = list(input())
left_w = 0
right_e = s[1:].count("E")
ans = right_e
for i in range(1,n):
    if s[i-1] == "W":
        left_w += 1
    if s[i] == "E":
        right_e -= 1
    ans = min(ans,right_e +left_w)
print(ans)
Buggy python submission (verdict: Runtime Error):
a,b,k = map(int,input().split())
n = list(range(a,b+1))
n.sort
if 2*k >= len(n):
    for i in n:
        print(i)
else:
    a = []
    a.extend(n[:k])
    a.extend(n[-k:])
    a.sort
    for i in a:
        print(i)
    

Fixed submission:
a,b,k = map(int,input().split())
ans = []
if 2*k <= b-a+1:
    for i in range(k):
        ans.append(a+i)
        ans.append(b-i)
    ans = list(set(ans))
    ans = sorted(ans)
    for i in ans:
        print(i)
else:
    for i in range(a,b+1):
        print(i)

Buggy python submission (verdict: Runtime Error):
a,b,k = map(int,input().split())
n = list(range(a,b+1))
n.sort
if 2*k >= len(n):
    for i in n:
        print(i)
else:
    a = []
    a.extend(n[:k])
    a.extend(n[-k:])
    for i in a:
        print(i)

Fixed submission:
a,b,k = map(int,input().split())
ans = []
if 2*k <= b-a+1:
    for i in range(k):
        ans.append(a+i)
        ans.append(b-i)
    ans = list(set(ans))
    ans = sorted(ans)
    for i in ans:
        print(i)
else:
    for i in range(a,b+1):
        print(i)

Buggy python submission (verdict: Runtime Error):
a,b,k = map(int,input().split())
n = list(range(a,b+1))
n.sort
if 2*k >= len(n):
    for i in n:
        print(i)
else:
    a = []
    a.extend(n[:k])
    a.extend(n[-k:])
    for i in a:
        print(i)

Fixed submission:
a,b,k = map(int,input().split())
ans = []
if 2*k <= b-a+1:
    for i in range(k):
        ans.append(a+i)
        ans.append(b-i)
    ans = list(set(ans))
    ans = sorted(ans)
    for i in ans:
        print(i)
else:
    for i in range(a,b+1):
        print(i)

Buggy python submission (verdict: Time Limit Exceeded):
a,b,k = map(int,input().split())
n = []
for i in range(a,b+1):
    n.append(i)
n.sort
if 2*k >= len(n):
    for i in n:
        print(i)
else:
    a = []
    a.extend(n[:k])
    a.extend(n[-k:])
    for i in a:
        print(i)
    

Fixed submission:
a,b,k = map(int,input().split())
ans = []
if 2*k <= b-a+1:
    for i in range(k):
        ans.append(a+i)
        ans.append(b-i)
    ans = list(set(ans))
    ans = sorted(ans)
    for i in ans:
        print(i)
else:
    for i in range(a,b+1):
        print(i)
Buggy python submission (verdict: Runtime Error):
def Otoshidama():
    N,Y = input().split()
    N = int(N)
    Y = int(Y)
    for i in range(N+1):
        for j in range(N-i+1):
            for k in range(N-i-j+1):
                ans = 10000*i + 5000*j + 1000*k
                if Y == ans:
                    return(i,j,k)
    return(-1,-1,-1)

One,Two,Three = Otoshidama()
print(One,Two,Th

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

for i in range(N+1):
    for j in range(N-i+1):
        if Y-10000*i-5000*j == 1000*(N-i-j):
            print(i,j,N-i-j)
            break
    else:
        continue
    break
else:
    print(-1,-1,-1)
Buggy python submission (verdict: Runtime Error):
s = list(input())
t = list(input())
s.sort()
t.sort(reverse=True)
if s < t:
    print("yes")
else:
    print("No")

Fixed submission:
a,b = map(int,input().split())
y = (a + b)/ 2
import math
print(math.ceil(y))
Buggy python submission (verdict: Runtime Error):
s = list(input())
t = list(input())
N = len(s)
M = len(t)
s.sort()
t.reverse()
if N < M and s == t[:N]:
    print("Yes")
else:
    for i in range(N):
        if s[i] < t[i]:
            print("Yes")
            break
    else:
        print("No")

Fixed submission:
s = list(input())
t = list(input())
s.sort()
t.sort(reverse=True)
if s < t:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = [int(x) for x in input().split()]
num = 0
while True:
    for i in n:
        if a[i] % 2 == 1:
          return ans
        else:
            a[i] = a[i] / 2
        num += 1

Fixed submission:
x = list(input())
print(x.count("1"))
Buggy python submission (verdict: Runtime Error):
a=input()
b=input()
if (a[0]==b[2] and a[1]==b[a] and a[2]==b[0]):
  print("YES")
else:
  print("NO")

Fixed submission:
a=input()
b=input()
if a[0]==b[2] and a[1]==b[1] and a[2]==b[0]:
  print("YES")
else:
  print("NO")

Buggy python submission (verdict: Runtime Error):
a=input()
b=input()
if a[0]==b[2] and a[1]==b[a] and a[2]==b[0]:
  print("YES")
else:
  print("NO")

Fixed submission:
a=input()
b=input()
if a[0]==b[2] and a[1]==b[1] and a[2]==b[0]:
  print("YES")
else:
  print("NO")

Buggy python submission (verdict: Runtime Error):
a=input()
b=input()
if a[0]==b[2] and a[1]==b[a] and a[2]==b[0]:
  print("Yes")
else:
  print("No")

Fixed submission:
a=input()
b=input()
if a[0]==b[2] and a[1]==b[1] and a[2]==b[0]:
  print("YES")
else:
  print("NO")
Buggy python submission (verdict: Runtime Error):
R =int(input())
G =int(input())
print(2G-R)

Fixed submission:
R =int(input())
G =int(input())
print(2*G-R)
Buggy python submission (verdict: Runtime Error):
s=input()
outp=""
for i in range(len(s),2):
    outp+=s[i]
print(outp)

Fixed submission:
s=input()
outp=""
for i in range(0,len(s),2):
    outp+=s[i]
print(outp)
Buggy python submission (verdict: Runtime Error):
n = int(input())
k = 0
while 2**k <= n:
    k += 1:
print(2**(k-1))
        

Fixed submission:
n = int(input())
k = 0
while 2**k <= n:
    k += 1
print(2**(k-1))
Buggy python submission (verdict: Runtime Error):
s = input()
for i in range(len(s)):
    s = s[:-1]
    if len(s)%2 == 0:
        if s[:len(s)/2] == s[len(s)/2:]:
            print(len(s))
            break

Fixed submission:
s = input()
for i in range(len(s)):
    s = s[:-1]
    if len(s)%2 == 0:
        if s[:int(len(s)/2)] == s[int(len(s)/2):]:
            print(len(s))
            break
Buggy python submission (verdict: Runtime Error):
n,l = input().split()
n = int(n)
s = []
for i in range(n):
    s.append(input())
s.sort()
print(s[0]+s[1]+s[2])


Fixed submission:
n,l = input().split()
n = int(n)
s = []
for i in range(n):
    s.append(input())
s.sort()
print("".join(s))

Buggy python submission (verdict: Runtime Error):
n,l = map(int,input().split())
s = []
for i in range(n):
    s.append(input())
s.sort()
print(s[0]+s[1]+s[2])

Fixed submission:
n,l = input().split()
n = int(n)
s = []
for i in range(n):
    s.append(input())
s.sort()
print("".join(s))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split(' ')))

ret = 1
for ai in a:
    ret *= ai

if ret > 10**18:
    print(-1)
else:
    print(ret)

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

# import numpy as np
# ret = np.prod(a)

if a.count(0) > 0:
    print(0)
else:
    ret = 1
    for ai in a:
        ret *= ai
        if ret > 10**18:
            print(-1)
            break
    else:
        if ret > 10**18:
            print(-1)
        else:
            print(ret)

    # if ret > 10**18 or ret < 0:
    #     print(-1)
    # else:
    #     print(ret)
Buggy python submission (verdict: Runtime Error):
cin = open(0).read().strip().split('\n')

n,k = map(int, cin[0].split(' '))
a = list(map(int, cin[1].split(' ')))

history = [1]
for i in range(n):
    history.append(a[history[i]-1])

if n >= k:
    print(a[k])
else:
    times = [0] + [-1] * (n-1)
    for i in range(n):
        if times[a[i]-1] == -1:
            times[a[i]-1] = i+1
        else:
            cycle = i-times[a[i]-1]
            pre = times[a[i]-1]
            mod = (k-pre)%cycle
            print(history[pre+mod])
            break

Fixed submission:
cin = open(0).read().strip().split('\n')

n,k = map(int, cin[0].split(' '))
a = list(map(int, cin[1].split(' ')))

history = [1]
for i in range(n):
    history.append(a[history[i]-1])

if n >= k:
    print(history[k])
else:
    times = [-1] * n
    for i in range(n):
        if times[history[i]-1] == -1:
            times[history[i]-1] = i
        else:
            cycle = i-times[history[i]-1]
            pre = times[history[i]-1]
            mod = (k-pre)%cycle
            print(history[pre+mod])
            break

Buggy python submission (verdict: Time Limit Exceeded):
cin = open(0).read().strip().split('\n')

n,k = map(int, cin[0].split(' '))
a = list(map(int, cin[1].split(' ')))

place = 1
history = []
rule = []
while len(rule) == 0:
    history.append(place)
    place = a[place-1]
    for i in range(1,len(history)//2+1):
        aset = set(history[len(history)-i*2:len(history)-i])
        bset = set(history[len(history)-i:])
        # print(i, history, aset, bset)
        if aset == bset:
            rule = history[len(history)-i:]
    if len(history) == (k+1):
        break

if len(rule) == 0:
    print(history[k])
else:
    pre = len(history)-len(rule)*2
    mod = (k-(pre-1)) % len(rule)
    print(rule[mod-1])

Fixed submission:
cin = open(0).read().strip().split('\n')

n,k = map(int, cin[0].split(' '))
a = list(map(int, cin[1].split(' ')))

history = [1]
for i in range(n):
    history.append(a[history[i]-1])

if n >= k:
    print(history[k])
else:
    times = [-1] * n
    for i in range(n):
        if times[history[i]-1] == -1:
            times[history[i]-1] = i
        else:
            cycle = i-times[history[i]-1]
            pre = times[history[i]-1]
            mod = (k-pre)%cycle
            print(history[pre+mod])
            break
Buggy python submission (verdict: Runtime Error):
cin = open(0).read().strip().split('\n')
n, m, q = map(int, cin[0].split(' '))
abcd = [tuple(map(int, a.split(' '))) for a in cin[1:]]

ret = 0
for case in itertools.combinations_with_replacement(list(range(1,m+1)), n):
    tmp = 0
    for c in abcd:
        if case[c[1]-1] - case[c[0]-1] == c[2]:
            tmp += c[3]
    ret = max(ret, tmp)
print(ret)

Fixed submission:
cin = open(0).read().strip().split('\n')
n, m, q = map(int, cin[0].split(' '))
abcd = [tuple(map(int, a.split(' '))) for a in cin[1:]]

ret = 0
import itertools
for case in itertools.combinations_with_replacement(list(range(1,m+1)), n):
    tmp = 0
    for c in abcd:
        if case[c[1]-1] - case[c[0]-1] == c[2]:
            tmp += c[3]
    ret = max(ret, tmp)
print(ret)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()

r = list()
g = list()
b = list()
for idx, si in enumerate(s):
    if si == 'R':
        r.append(idx)
    elif si == 'G':
        g.append(idx)
    else:
        b.append(idx)

ret = 0
for ri in r:
    for gi in g:
        for bi in b:
            comp = list(sorted([ri, gi, bi]))
            if (comp[1] - comp[0]) != (comp[2] - comp[1]):
                ret += 1

print(ret)

Fixed submission:
n = int(input())
s = input()

r = list()
g = list()
b = list()
for idx, si in enumerate(s):
    if si == 'R':
        r.append(idx)
    elif si == 'G':
        g.append(idx)
    else:
        b.append(idx)

ret = 0
bi_cnt = len(b)
for ri in r:
    for gi in g:
        cnt = 0
        try:
            dan1 = 2*ri - gi
            if (dan1 > 0) & (s[dan1] == 'B'):
                cnt += 1
        except:
            pass

        try:
            dan3 = 2*gi - ri
            if (dan3 > 0) & (s[dan3] == 'B'):
                cnt += 1
        except:
            pass

        try:
            dan2, mod = divmod(ri+gi, 2)
            if (mod == 0) & (s[dan2] == 'B'):
                cnt += 1
        except:
            pass

        ret += (bi_cnt - cnt)

print(ret)
Buggy python submission (verdict: Runtime Error):
cin = open(0).read().strip().split('\n')
n = int(cin[0])
p = list(map(int, cin[1].split(' ')))
q = list(map(int, cin[2].split(' ')))

a = 0
b = 0
for idx, case in enumerate(itertools.permutations(range(1, n+1))):
    if case == tuple(p):
        a = idx+1
    if case == tuple(q):
        b = idx+1
print(abs(a-b))

Fixed submission:
cin = open(0).read().strip().split('\n')
n = int(cin[0])
p = list(map(int, cin[1].split(' ')))
q = list(map(int, cin[2].split(' ')))

import itertools

a = 0
b = 0
for idx, case in enumerate(itertools.permutations(range(1, n+1))):
    if case == tuple(p):
        a = idx+1
    if case == tuple(q):
        b = idx+1

print(abs(a-b))