Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
A = int(input())  
else : print(int(A*(A-1)//2))

Fixed submission:
A = int(input())  - 1
if A ==0 :print(A)
else : print(int(A*(A+1)//2))

Buggy python submission (verdict: Runtime Error):

A = int(input())  1
if A ==0 :print(A)
else : print(int(A*(A-1)/2))




Fixed submission:
A = int(input())  - 1
if A ==0 :print(A)
else : print(int(A*(A+1)//2))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
A = list(map(int,input().split()))
X = []
A_sum = sum(A)

for i in range(n):
    temp = A_sum
    for j in range(i+1,n+i,2):
        temp -= 2*A[j % n]
    X.append(temp)

for i,x in enumerate(X):
    if i == n-1:
        print(x)
    else:
        print(x,end=" ")


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

x = sum(A)
for i in range(1,n,2):
    x -= 2*A[i] 

print(x,end=" ")

for i in range(n-1):
    x = 2*A[i]-x
    print(x,end=" ")
Buggy python submission (verdict: Runtime Error):
N,K =  [int(x) for x in input().split()]
num = 1
while num < K:
    num *= 2

L = [0.0000]*N

for i in range(N):
    if N < K:
        if num/(i+1) < K:
            num = num/2
        L[i]= 1/N * 1/num    
    else:
        L[i] = 1/N

ans = 0
for i in range(N):
        ans +=L[i]

print(ans)

Fixed submission:
N,K =  [int(x) for x in input().split()]

L = [0]*N
num =1
for i in range(N):
    num = 1
    if i < K:
        while num*(i+1) < K:
            num *= 2
        L[i]= 1/N * 1/num
    else:
        L[i] = 1/N

ans = 0
for i in range(N):
        ans +=L[i]

print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
sys.getrecursionlimit(10**7)

def dfs(v,p,dist):
    for u,v in tree[v]:
        if u==p:
            continue
        else:
            dist[u]=dist[v]+w
            dfs(u,v,dist)
    
n =int(input())
tree = [[] for _ in range(n)]
for _ in range(n-1):
    u,v,w =map(int,input.split())
    tree[u-1].append((v-1,w))
    tree[v-1].append((u-1,w))
dist =[0]*N
dfs(0,-1,dist)

for num in dist:
    if num % 2==0:
        print("1")
    else:
        print("0")

        

Fixed submission:
import sys
sys.setrecursionlimit(10 ** 7)

def dfs(v, p, dist):
    for u, w in tree[v]:
        if u == p:
            continue
        else:
            dist[u] = dist[v] + w
            dfs(u, v, dist)
 
 
n = int(input())
tree = [[] for _ in range(n)]
for _ in range(n - 1):
    u, v, w = map(int, input().split())
    tree[u - 1].append((v - 1, w))
    tree[v - 1].append((u - 1, w))
 
dist = [0 for _ in range(n)]
dfs(0, -1, dist)
 
for i in dist:
    if i % 2 == 0:
        print(0)
    else:
        print(1)

Buggy python submission (verdict: Runtime Error):
def dfs(v, p, dist):
    for u, w in tree[v]:
        if u == p:
            continue
        else:
            dist[u] = dist[v] + w
            dfs(u, v, dist)
 
 
n = int(input())
tree = [[] for _ in range(n)]
for _ in range(n - 1):
    u, v, w = map(int, input().split())
    tree[u - 1].append((v - 1, w))
    tree[v - 1].append((u - 1, w))
 
dist = [0 for _ in range(n)]
dfs(0, -1, dist)
 
for i in dist:
    if i % 2 == 0:
        print(0)
    else:
        print(1)

Fixed submission:
import sys
sys.setrecursionlimit(10 ** 7)

def dfs(v, p, dist):
    for u, w in tree[v]:
        if u == p:
            continue
        else:
            dist[u] = dist[v] + w
            dfs(u, v, dist)
 
 
n = int(input())
tree = [[] for _ in range(n)]
for _ in range(n - 1):
    u, v, w = map(int, input().split())
    tree[u - 1].append((v - 1, w))
    tree[v - 1].append((u - 1, w))
 
dist = [0 for _ in range(n)]
dfs(0, -1, dist)
 
for i in dist:
    if i % 2 == 0:
        print(0)
    else:
        print(1)
Buggy python submission (verdict: Runtime Error):
L = list(map(int,input().split()))

print(L[0]*l[1]//2)

Fixed submission:
L = list(map(int,input().split()))
     
print(L[0]*L[1]//2)
Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int,input().split())
H = list(map(int,input().split()))
dp = [0]*n

if n <= k:
    print(abs(H[0]-H[-1]))
else:
    for i in range(1,k+1):
        dp[i] = abs(H[i]-H[0])
    for i in range(k+1,n):
        res = abs(H[i]-H[i-k])+dp[i-k]
        for j in range(1,k):
            res = min(res,abs(H[i]-H[i-j])+dp[i-j])
        dp[i] = res
    print(dp[n-1]) 

Fixed submission:
n,k = map(int,input().split())
H = list(map(int,input().split()))
dp = [0]*n

if n <= k:
    print(abs(H[0]-H[-1]))
else:
    for i in range(1,k+1):
        dp[i] = abs(H[i]-H[0])
    for i in range(k+1,n):
        res = abs(H[i]-H[i-k])+dp[i-k]
        for j in range(1,k):
            res = min(res,abs(H[i]-H[i-j])+dp[i-j])
        dp[i] = res
    print(dp[n-1])

Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int,input().split())
H = list(map(int,input().split()))
dp = [0]*n

if n <= k:
    print(abs(H[0]-H[-1]))
else:
    for i in range(1,n):
        if i <= k:
            dp[i] = abs(H[i]-H[0])
        else:
            res = abs(H[i]-H[i-k])+dp[i-k]
            for j in range(1,k):
                res = min(res,abs(H[i]-H[i-j])+dp[i-j])
            dp[i] = res
    print(dp[n-1]) 

Fixed submission:
n,k = map(int,input().split())
H = list(map(int,input().split()))
dp = [0]*n

if n <= k:
    print(abs(H[0]-H[-1]))
else:
    for i in range(1,k+1):
        dp[i] = abs(H[i]-H[0])
    for i in range(k+1,n):
        res = abs(H[i]-H[i-k])+dp[i-k]
        for j in range(1,k):
            res = min(res,abs(H[i]-H[i-j])+dp[i-j])
        dp[i] = res
    print(dp[n-1])
Buggy python submission (verdict: Runtime Error):
n = int(input())
dp = [[0]*3  for _ in range(n)] 
ABC = []
for _ in range(n):
    a,b,c = map(int,input().split())
    ABC.append([a,b,c])

def rec(flag,num):# flag は A=0,B=1,C=2を表す。 numは何番目かを表す。
    if dp[num][flag] != 0:
        return dp[num][flag]
    if num == 0:
        dp[num][flag] = ABC[num][flag]
        return dp[num][flag]
    else:
        res = 0
        if flag == 0:
            res = max(rec(1,num-1),rec(2,num-1))+ABC[num][flag]
        elif flag == 1:
            res = max(rec(0,num-1),rec(2,num-1))+ABC[num][flag]
        else:
            res = max(rec(1,num-1),rec(0,num-1))+ABC[num][flag]
        dp[num][flag] = res
        return dp[num][flag]

rec(0,n-1)
rec(1,n-1)
rec(2,n-1)

print(max(dp[n-1]))

Fixed submission:
import sys
sys.setrecursionlimit(10**9)

n = int(input())
dp = [[0]*3  for _ in range(n)] 
ABC = []
for _ in range(n):
    a,b,c = map(int,input().split())
    ABC.append([a,b,c])

def rec(flag,num):# flag は A=0,B=1,C=2を表す。 numは何番目かを表す。
    if dp[num][flag] != 0:
        return dp[num][flag]
    if num == 0:
        dp[num][flag] = ABC[num][flag]
        return dp[num][flag]
    else:
        res = 0
        if flag == 0:
            res = max(rec(1,num-1),rec(2,num-1))+ABC[num][flag]
        elif flag == 1:
            res = max(rec(0,num-1),rec(2,num-1))+ABC[num][flag]
        else:
            res = max(rec(1,num-1),rec(0,num-1))+ABC[num][flag]
        dp[num][flag] = res
        return dp[num][flag]

rec(0,n-1)
rec(1,n-1)
rec(2,n-1)

print(max(dp[n-1]))
Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**9)

import numpy as np
N,W = map(int,input().split())
WV = [(list(map(int,input().split()))) for _ in range(N)]
DP = np.array([[0]*(W+1) for _ in range(N+1)], dtype=np.int64)

def rec(i,w,v):
    if DP[i][w] != 0:
        return DP[i][w]
    if i == N:
        return v
    if w == 0:
        return v
    else:
        res = rec(i+1,w,v)
        if w-WV[i][0] >= 0:
            res = max(res,rec(i+1,w-WV[i][0],v+WV[i][1]))
        DP[i][w] = res
        return DP[i][w]

rec(0,W,0)
print(np.max(DP))

Fixed submission:
import numpy as np
n,w=map(int,input().split())
 
dp=np.zeros(w+1,np.int64)
for i in range(n):
    w,v = map(int,input().split())
    dp[w:] = np.maximum(dp[w:], dp[:-w] + v)
    
print(np.max(dp))

Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**9)

import numpy as np
N,W = map(int,input().split())
WV = [(list(map(int,input().split()))) for _ in range(N)]
DP = np.array([[0]*(W+1) for _ in range(N+1)], dtype=np.int64)

def rec(i,w,v):
    if DP[i][w] != 0:
        return DP[i][w]
    if i == N:
        return v
    if w == 0:
        return v
    else:
        res = rec(i+1,w,v)
        if w-WV[i][0] >= 0:
            res = max(res,rec(i+1,w-WV[i][0],v+WV[i][1]))
        DP[i][w] = res
        return DP[i][w]

rec(0,W,0)
print(np.max(DP))

Fixed submission:
import numpy as np
n,w=map(int,input().split())
 
dp=np.zeros(w+1,np.int64)
for i in range(n):
    w,v = map(int,input().split())
    dp[w:] = np.maximum(dp[w:], dp[:-w] + v)
    
print(np.max(dp))

Buggy python submission (verdict: Runtime Error):
import numpy as np
N,W = map(int,input().split())
WV = [(list(map(int,input().split()))) for _ in range(N)]
DP = np.array([[0]*(W+1) for _ in range(N+1)], dtype=np.int64)

def rec(i,w,v):
    if DP[i][w] != 0:
        return DP[i][w]
    if i == N:
        return v
    if w == 0:
        return v
    else:
        res = rec(i+1,w,v)
        if w-WV[i][0] >= 0:
            res = max(res,rec(i+1,w-WV[i][0],v+WV[i][1]))
        DP[i][w] = res
        return DP[i][w]

rec(0,W,0)
print(np.max(DP))

Fixed submission:
import numpy as np
n,w=map(int,input().split())
 
dp=np.zeros(w+1,np.int64)
for i in range(n):
    w,v = map(int,input().split())
    dp[w:] = np.maximum(dp[w:], dp[:-w] + v)
    
print(np.max(dp))
Buggy python submission (verdict: Time Limit Exceeded):
s,t = input(),input()
n,m=len(s),len(t)
dp = [[0]*(n+1) for _ in range(m+1)]

for i in range(m):
    for j in range(n):
        if s[j] == t[i]:
            dp[i+1][j+1] = max(dp[i][j]+1,dp[i+1][j+1])
        
        dp[i+1][j+1] = max(dp[i+1][j+1],dp[i+1][j], dp[i][j+1])

ans = ""
count = 0
while count != dp[-1][-1]:
    if dp[m][n] == dp[m-1][n]:
        m -= 1
    elif dp[m][n] == dp[m][n-1]:
        n -= 1
    else:
        ans += t[m-1]
        count += 1
        m -= 1
        n -= 1

print(ans[::-1])

Fixed submission:
s,t = input(),input()
n,m=len(s),len(t)
dp = [[0]*(n+1) for _ in range(m+1)]

for i in range(m):
    for j in range(n):
        if s[j] == t[i]:
            dp[i+1][j+1] = max(dp[i][j]+1,dp[i+1][j+1])
        
        dp[i+1][j+1] = max(dp[i+1][j+1],dp[i+1][j], dp[i][j+1])

ans = ""
count = 0
while count != dp[-1][-1]:
    if dp[m][n] == dp[m-1][n]:
        m -= 1
    elif dp[m][n] == dp[m][n-1]:
        n -= 1
    else:
        ans += t[m-1]
        count += 1
        m -= 1
        n -= 1

print(ans[::-1])
Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**9)
n,m = map(int,input().split())
graph = [[] for _ in range(n)]
for i in range(m):
  x,y = map(int,input().split())
  graph[x-1].append(y-1)
dp = [0]*(n)

done = []
def dfs(i):
    if i in done:
        done.pop()
        if dp[i] < len(done):dp[i] = len(done)
        return len(done)
    for j in graph[i]:
        if not(j in done):
            done.append(i)
            dfs(j)
    if dp[i] < len(done):dp[i] = len(done)
    if done:done.pop()
    return len(done)

for i in range(n):  
    dfs(i)
print(max(dp))


Fixed submission:
import sys
sys.setrecursionlimit(10**9)
n,m = map(int,input().split())
graph = [[] for _ in range(n)]
for i in range(m):
  x,y = map(int,input().split())
  graph[x-1].append(y-1)
dp = [-1]*(n)
 
def dfs(i):
    if dp[i] != -1:
        return dp[i]
    else:
        res = 0
        for j in graph[i]:
            res = max(res,dfs(j)+1)
        dp[i] = res
        return dp[i]
 
for i in range(n):  
    dfs(i)
print(max(dp))
Buggy python submission (verdict: Runtime Error):
L = list(map(int,input().split()))

print(L[0]+l[1]//2)

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

print(L[0]+L[1]//2)
Buggy python submission (verdict: Runtime Error):
import fractions

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

n,m = map(int,input().split())
S = input()
T = input()

l = lcm(n,m)
c_max = max(n,m)
ans_s = [" "]*(l+1)
ans_t = [" "]*(l+1)
for i in range(n):
    ans_s[i*l//n+1] = S[i]
for i in range(m):
    ans_t[i*l//m+1] = T[i]
    
ans = l
for i in range(l+1):
    if ans_s[i] != " " and ans_t[i] != " " and ans_s[i] != ans_t[i]:
        ans = -1

print(ans)


Fixed submission:
import fractions

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

n,m = map(int,input().split())
S = input()
T = input()

l = lcm(n,m)
i = 0
j = 0
ans = l
while i < n or j < m:
    temp_n = i*l//n+1
    temp_m = j*l//m+1
    if temp_n == temp_m:
        if S[i] != T[j]:
            ans = -1
            break
        i += 1
        j += 1
    elif temp_m > temp_n:
        i += 1
    else:
        j += 1

print(ans)

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

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

n,m = map(int,input().split())
S = input()
T = input()

l = lcm(n,m)
c_max = max(n,m)
ans_s = [" "]*(l+1)
ans_t = [" "]*(l+1)
for i in range(n):
    ans_s[i*l//n+1] = S[i]
for i in range(m):
    ans_t[i*l//m+1] = T[i]
    
ans = l
for i in range(l+1):
    if ans_s[i] != " " and ans_t[i] != " " and ans_s[i] != ans_t[i]:
        ans = -1

print(ans)

Fixed submission:
import fractions

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

n,m = map(int,input().split())
S = input()
T = input()

l = lcm(n,m)
i = 0
j = 0
ans = l
while i < n or j < m:
    temp_n = i*l//n+1
    temp_m = j*l//m+1
    if temp_n == temp_m:
        if S[i] != T[j]:
            ans = -1
            break
        i += 1
        j += 1
    elif temp_m > temp_n:
        i += 1
    else:
        j += 1

print(ans)

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

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

n,m = map(int,input().split())
S = input()
T = input()

l = lcm(n,m)
c_max = max(n,m)
ans_s = [" "]*(l+1)
ans_t = [" "]*(l+1)
for i in range(n):
    ans_s[i*l//n+1] = S[i]
for i in range(m):
    ans_t[i*l//m+1] = T[i]
    
ans = l
for i in range(l+1):
    if ans_s[i] != " " and ans_t[i] != " " and ans_s[i] != ans_t[i]:
        ans = -1

print(ans)


Fixed submission:
import fractions

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

n,m = map(int,input().split())
S = input()
T = input()

l = lcm(n,m)
i = 0
j = 0
ans = l
while i < n or j < m:
    temp_n = i*l//n+1
    temp_m = j*l//m+1
    if temp_n == temp_m:
        if S[i] != T[j]:
            ans = -1
            break
        i += 1
        j += 1
    elif temp_m > temp_n:
        i += 1
    else:
        j += 1

print(ans)
Buggy python submission (verdict: Runtime Error):
#n = int(input())
a,b = map(str,input().split())
#A = list(map(int,input().split()))
ans = (a-1)*(b-1)

print(ans)

Fixed submission:
a,b = map(int,input().split())
#A = list(map(int,input().split()))
ans = (a-1)*(b-1)
 
print(ans)
Buggy python submission (verdict: Runtime Error):
l = []
for i in range(int(input()):
   l.append(input())
ac = 0
wa = 0
tle = 0
re = 0
for i in l:
    if i == "AC":
        ac+=1
    if i == "TLE":
        tle+=1
    if i == "WA":
        wa+=1
    if i == "RE":
        re+=1
print("AC X "+str(ac))
print("WA X "+str(wa))
print("TLE X "+str(tle))
print("RE X "+str(re))

    

Fixed submission:
l = []
for i in range(int(input())):
   l.append(input())
ac = 0
wa = 0
tle = 0
re = 0
for i in l:
    if i == "AC":
        ac+=1
    if i == "TLE":
        tle+=1
    if i == "WA":
        wa+=1
    if i == "RE":
        re+=1
print("AC x "+str(ac))
print("WA x "+str(wa))
print("TLE x "+str(tle))
print("RE x "+str(re))
Buggy python submission (verdict: Time Limit Exceeded):
n, k = [int(e) for e in input().split()]
arr = [int(e) for e in input().split()]
dp = [0]*len(arr)
 
for i in range(1,len(arr)):
  dp[i] = min(dp[j] + abs(arr[i]-arr[j]) for j in range(max(i-k,0),i))
print(dp[-1])



Fixed submission:
n, k = [int(e) for e in input().split()]
arr = [int(e) for e in input().split()]
dp = [0]*len(arr)
 
for i in range(1,len(arr)):
  dp[i] = min(dp[j] + abs(arr[i]-arr[j]) for j in range(max(i-k,0),i))
print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
x,k = map(int,input().split())
arr = list(map(int,input().split()))
 
dp = [0]*len(arr)
 
for i in range(1,len(arr)):
  dp[i] = min(dp[j] + abs(arr[i]-arr[j]) for j in range(max(i-k,0),i))
print(dp[-1])


Fixed submission:
n, k = [int(e) for e in input().split()]
arr = [int(e) for e in input().split()]
dp = [0]*len(arr)
 
for i in range(1,len(arr)):
  dp[i] = min(dp[j] + abs(arr[i]-arr[j]) for j in range(max(i-k,0),i))
print(dp[-1])

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

dp = [0]*len(arr)

for i in range(1,len(arr)):
  dp[i] = min([dp[j] + abs(arr[i]-arr[j]) for j in range(max(i-k,0),i)])
print(dp[-1])

Fixed submission:
n, k = [int(e) for e in input().split()]
arr = [int(e) for e in input().split()]
dp = [0]*len(arr)
 
for i in range(1,len(arr)):
  dp[i] = min(dp[j] + abs(arr[i]-arr[j]) for j in range(max(i-k,0),i))
print(dp[-1])

Buggy python submission (verdict: Runtime Error):
x,k = map(int,input().split())
arr = list(map(int,input().split()))


dp = [0]*len(arr)
for i in range(1,k):
  dp[i] = abs(arr[i]-arr[0])

for i in range(k,len(arr)):
  curr = float("inf")
  for j in range(1,k+1):
    curr = min(curr,dp[i-j] + abs(arr[i]-arr[i-j]))
  dp[i] = curr
print(dp[-1])

Fixed submission:
n, k = [int(e) for e in input().split()]
arr = [int(e) for e in input().split()]
dp = [0]*len(arr)
 
for i in range(1,len(arr)):
  dp[i] = min(dp[j] + abs(arr[i]-arr[j]) for j in range(max(i-k,0),i))
print(dp[-1])
Buggy python submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
q=int(input())
d=[0]*1000
for i in a:
    d[i-1]+=1
s=0
for num,i in enumerate(d):
    s+=i*(num+1)

bb=[]
cc=[]
for i in range(q):
    b,c=map(int,input().split())
    bb.append(b)
    cc.append(c)

for b,c in zip(bb,cc):
    k=d[b-1]
    s+=(c-b)*k
    d[b-1]=0
    d[c-1]+=k

    print(s)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
q=int(input())
d=[0]*100001
for i in a:
    d[i-1]+=1
s=0
for num,i in enumerate(d):
    s+=i*(num+1)

bb=[]
cc=[]
for i in range(q):
    b,c=map(int,input().split())
    bb.append(b)
    cc.append(c)

for b,c in zip(bb,cc):
    k=d[b-1]
    s+=(c-b)*k
    d[b-1]=0
    d[c-1]+=k

    print(s)
Buggy python submission (verdict: Runtime Error):
import numpy as np



n=int(input())
a=sorted(list(map(int,input().split())))

max=a[-1]
ans=0
if(len(a)!=len(set(a))):ans-=1
primeNum = []
while a:
    primeNum.append(a[0])
    tmp=a[0]
    a=[i for i in a if i % tmp != 0]
primeNum.extend(a)
ans+=len(primeNum)


print(ans)

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

M=1000005
l=[0 for i in range(M)]
for i in a:
    if(l[i]!=0):
        l[i]=2
        continue
    for j in range(i,M,i):
        l[j]+=1
ans=0
for i in a:
    if(l[i]==1):ans+=1
print(ans)
Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
a=list(map(int,input().split()))
d=[]
s=[-1]*(n+1)
t=1
for i in range(1,k):
    d.append(t)
    s[t]=1
    if(s[a[t-1]]==1):
        break
    t=a[t-1] 
idx=d.index(a[t-1])
d=d[idx:]
print(d[(k-i)%len(d)])


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

s=[]
d=[-1]*(n+1)

v=1
while(d[v]==-1):
    d[v]=len(s)
    s.append(v)
    v=a[v-1]
c=len(s)-d[v]
l=d[v]

if(k<l):print(s[k])
else:
    k-=l
    k%=c
    print(s[k+l])

Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
a=list(map(int,input().split()))
d=[]
t=1
for i in range(1,k):
    d.append(t)
    if(a[t-1] in d):
        break
    t=a[t-1] 
idx=d.index(a[t-1])
d=d[idx:]
print(d[(k-i)%len(d)])

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

s=[]
d=[-1]*(n+1)

v=1
while(d[v]==-1):
    d[v]=len(s)
    s.append(v)
    v=a[v-1]
c=len(s)-d[v]
l=d[v]

if(k<l):print(s[k])
else:
    k-=l
    k%=c
    print(s[k+l])

Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
a=list(map(int,input().split()))
d=[1]
t=a[0]
for i in range(1,k):
    d.append(t)
    if(a[t-1] in d):
        break
    t=a[t-1] 
idx=d.index(a[t-1])
d=d[idx:]
print(d[(k-i-1)%len(d)])

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

s=[]
d=[-1]*(n+1)

v=1
while(d[v]==-1):
    d[v]=len(s)
    s.append(v)
    v=a[v-1]
c=len(s)-d[v]
l=d[v]

if(k<l):print(s[k])
else:
    k-=l
    k%=c
    print(s[k+l])

Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
a=list(map(int,input().split()))
d=[1]
t=a[0]
for i in range(1,k):
    d.append(t)
    if(a[t-1] in d):
        break
    t=a[t-1] 
idx=d.index(a[t-1])
d=d[idx:]
print(d[(k-i-1)%len(d)])

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

s=[]
d=[-1]*(n+1)

v=1
while(d[v]==-1):
    d[v]=len(s)
    s.append(v)
    v=a[v-1]
c=len(s)-d[v]
l=d[v]

if(k<l):print(s[k])
else:
    k-=l
    k%=c
    print(s[k+l])

Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
a=list(map(int,input().split()))
d=[]
t=a[0]
for i in range(1,k):
    d.append(t)
    if(a[t-1] in d):
        # d.pop()
        break
    t=a[t-1] 
idx=d.index(a[t-1])
d=d[idx:]
print(d[(k-i-1)%len(d)])

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

s=[]
d=[-1]*(n+1)

v=1
while(d[v]==-1):
    d[v]=len(s)
    s.append(v)
    v=a[v-1]
c=len(s)-d[v]
l=d[v]

if(k<l):print(s[k])
else:
    k-=l
    k%=c
    print(s[k+l])

Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
a=list(map(int,input().split()))
d=[]
t=a[0]
for i in range(1,k):
    d.append(t)
    if(a[t-1] in d):
        # d.pop()
        break
    t=a[t-1] 
idx=d.index(a[t-1])
idx=len(d[:idx])
print(d[(k-i-1)%len(d)-idx])

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

s=[]
d=[-1]*(n+1)

v=1
while(d[v]==-1):
    d[v]=len(s)
    s.append(v)
    v=a[v-1]
c=len(s)-d[v]
l=d[v]

if(k<l):print(s[k])
else:
    k-=l
    k%=c
    print(s[k+l])
Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
h=list(map(int,input().split()))
a=[]
b=[]
for i in range(m):
    aa,bb=map(int,input().split())
    a.append(aa-1)
    b.append(bb-1)
ans=0
t=[False]*n
for i in range(n):
    if(t[i]):continue
    flag=True
    for j in range(m):
        if(a[j]==i):
            if(h[i]<=h[b[j]]):
                flag=False
                break
            else:t[b[j]]=True
        if(b[j]==i):
            if(h[i]<=h[a[j]]):
                flag=False
                break
            else:t[a[j]]=True
    if(flag):
        ans+=1
print(ans)

Fixed submission:
n,m=map(int,input().split())
h=list(map(int,input().split()))
t=[]
for i in range(m):
    t.append(list(map(int,input().split())))
ans=[True]*n
for i in range(m):
    a,b=t[i]
    if(h[a-1]<=h[b-1]):
        ans[a-1]=False
    if(h[b-1]<=h[a-1]):
        ans[b-1]=False
print(ans.count(True))

Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
h=list(map(int,input().split()))
a=[]
b=[]
for i in range(m):
    aa,bb=map(int,input().split())
    a.append(aa-1)
    b.append(bb-1)
ans=0
t=[False]*n
for i in range(n):
    flag=True
    for j in range(m):
        if(a[j]==i):
            if(h[i]<=h[b[j]]):
                flag=False
                break
        if(b[j]==i):
            if(h[i]<=h[a[j]]):
                flag=False
                break
    if(flag):
        ans+=1
print(ans)

Fixed submission:
n,m=map(int,input().split())
h=list(map(int,input().split()))
t=[]
for i in range(m):
    t.append(list(map(int,input().split())))
ans=[True]*n
for i in range(m):
    a,b=t[i]
    if(h[a-1]<=h[b-1]):
        ans[a-1]=False
    if(h[b-1]<=h[a-1]):
        ans[b-1]=False
print(ans.count(True))
Buggy python submission (verdict: Time Limit Exceeded):
a,b,n=map(int,input().split())
ans=0
for i in range(1,n+1):
    t=int((a*i)/b)-a*int(i/b)
    ans=max(ans,t)
print(ans)

Fixed submission:
a,b,n=map(int,input().split())
def f(x):
    return int(a*x/b)-a*int(x/b)
print(f(min(b-1,n)))