Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p02639 (python)

Fixed submission:
x = list(map(int, input().split()))
ans = 0
for xi in x:
  ans += 1
  if xi == 0:
    print(ans)
    break

Buggy submission (verdict: Runtime Error):
from heapq import heapify,heappush,heappop
import sys

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

S = []
PQs = [[] for _ in range(200000)]
T = [0]*200000 #幼稚園ごとの最終更新
M = []
for n in range(N):
  a, b = map(int,input().split())
  S.append([a,b-1])#レート、所属
  #print(PQs[0:10])
  PQs[b-1]=PQs[b-1]+[(-a,n)]#-レート、人
  #print(PQs[0:10])

for b in range(200000):
  if len(PQs[b])>0:
    heapify(PQs[b])
    M.append((-PQs[b][0][0],b,0))#レート、人、所属、更新時
heapify(M)
          
for q in range(1,Q+1):#時刻。1からスタート
  c, d = map(int,input().split())
  d = d-1
  d_prv = S[c-1][1]
  S[c-1][1] = d #情報の更新
  #print(S)
 
  #print(d_prv)
  #print(d)
  
  #転園先の幼稚園について
  heappush(PQs[d],(-S[c-1][0],c-1))#-レート、人
  #print(S[P[d][0][1]][1])
  #print(d)
  #print(PQs[0:4]) 
  while d != S[PQs[d][0][1]][1]:#所属が整合していない時（古く間違った情報である時）
    heappop(PQs[d])
  heappush(M,(-PQs[d][0][0],d,q))
  T[d] = q #最終更新時をアップデート
  #print(PQs[0:4])
  
  #転園元の幼稚園について
  if len(PQs[d_prv])>0:
    while d_prv != S[PQs[d_prv][0][1]][1]:#所属が整合していない時（古く間違った情報である時）
      #print(S[PQs[d_prv][0][1]])
      heappop(PQs[d_prv])
      if len(PQs[d_prv]) == 0:
        break
        
    if len(PQs[d_prv]) > 0:  
      heappush(M,(-PQs[d_prv][0][0],d_prv,q))
    T[d_prv] = q #最終更新時をアップデート

  #print(M)   	
  #最強園児の集いを処理
  while M[0][2] != T[M[0][1]]:#更新時が整合していない時（古く間違った情報である時）
    heappop(M)
    #print(M)
  
  #結果の出力
  print(M[0][0]) 
  #print(M)
Problem p02641 (python)

Fixed submission:
X, N = map(int,input().split())
if N > 0:
  p = list(map(int, input().split()))
else:
  p=[]
#print(p)
p.sort()
#dis = p[0] - X
ans_1 = X
ans_2 = X
for i in range(N) :
  pi = p[i]
  if pi == ans_1:
    ans_1 += 1

p.reverse()
for i in range(N) :
  pi = p[i]
  if pi == ans_2:
    ans_2 -= 1

ans = X
if abs(ans_1 - X) < abs(ans_2 - X):
  ans = ans_1
elif ans_1 - X == -abs(ans_2 - X):
  ans = ans_1
else:
  ans = ans_2
print(ans)

Buggy submission (verdict: Runtime Error):
X, N = map(int,input().split())
p = list(map(int, input().split()))
#print(p)
p.sort()
dis = p[0] - X
ans_1 = X
ans_2 = X
for pi in p :
  if pi == ans_1:
    ans_1 += 1

p.reverse()
for pi in p:
  if pi == ans_2:
    ans_2 -= 1

ans = X
if abs(ans_1 - X) < abs(ans_2 - X):
  ans = ans_1
elif ans_1 - X == -abs(ans_2 - X):
  ans = ans_1
else:
  ans = ans_2
print(ans)

Buggy submission (verdict: Runtime Error):
X, N = map(int,input().split())
p = list(map(int, input().split()))
#print(p)
#A.sort()
dis = p[0] - X
ans = p[0]
for pi in p :
  if abs(pi-X) < abs(dis):
    ans = pi
    dis = pi - X
    #print("if")
  elif pi-X == -abs(dis):
    ans = pi
    dis = pi - X
  #print(pi-X, abs(pi-X), dis,abs(dis))
print(ans)
Problem p02686 (python)

Fixed submission:
import sys
input=lambda: sys.stdin.readline().rstrip()

N = int(input())

S_p = []
S_n = []

for i in range(N):
  end = 0
  mim = 0
  for c in input():
    if c == "(":
      end += 1
    else :
      end -= 1
    mim = min(mim,end)
  
  if end >= 0:
    S_p.append([mim, end])
  else:
    S_n.append([end-mim, end])
  
S_p.sort(reverse=True)
S_n.sort(reverse=True)
#print(S_p)
#print(S_n)

check = 0
flag = True
for i in range(len(S_p)):
  if check + S_p[i][0] >= 0:
    check += S_p[i][1]
  else:
    flag = False
    break
  #print(check)
  
for i in range(len(S_n)):
  if check + S_n[i][1] - S_n[i][0] >= 0:
    check += S_n[i][1]
  else:
    flag = False
    break
  #print(check)
  
if check == 0 and flag:
  flag = True
else:
  flag = False

print("Yes" if flag else "No")

Buggy submission (verdict: Runtime Error):
#import sys
#input=lambda: sys.stdin.readline().strip()

N = int(input())

S = [input() for _ in range(N)]
S_p = []
S_n = []

for i in range(N):
  end = 0
  mim = 0
  for c in input():
    if c == "(":
      end += 1
    else :
      end -= 1
    mim = min(mim,end)
  
  if end >= 0:
    S_p.append([mim, end])
  else:
    S_n.append([end-mim, end])
  
S_p.sort(reverse=True)
S_n.sort(reverse=True)
#print(S_p)
#print(S_n)

check = 0
flag = True
for i in range(len(S_p)):
  if check + S_p[i][0] >= 0:
    check += S_p[i][1]
  else:
    flag = False
    break
  #print(check)
  
for i in range(len(S_n)):
  if check + S_n[i][1] - S_n[i][0] >= 0:
    check += S_n[i][1]
  else:
    flag = False
    break
  #print(check)
  
if check == 0 and flag:
  flag = True
else:
  flag = False

print("Yes" if flag else "No")
Problem p02698 (python)

Fixed submission:
import bisect as bs
import sys

sys.setrecursionlimit(2*10**5+1)

def dfs(i, nbr, A, prv, done, history, B, ans):#深さ優先探索（再帰）
  
  j = bs.bisect_left(B,A[i]) #Bへの挿入予定位置
  #print(i,A[i],j,B)
  
  #A[i]をhistoryの適当な位置に挿入
  if j < len(B):
    history[i] = (B[j], A[i], j) # 更新前の値、更新後の値、更新位置
    B[j] = A[i]
  else:
    history[i] = (-1, A[i], j) # 「追加する」 、追加する値、追加位置（最後）
    B.append(A[i])
  
  ans[i] = len(B) #答え書き込み
  done[i] = 1 #探索済み
  #print(i,B)
  
  for a in nbr[i]:
    if done[a] == 0: #探索前のみ
      dfs(a, nbr, A, prv, done, history, B, ans)
      prv[a] = i
      
  j = history[i][2]
  if history[i][0] >= 0:
    B[j] = history[i][0] #Bを現状復帰
  else:
    B.pop()
    
N = int(input()) 
A = list(map(int,input().split()))

nbr = [[] for _ in range(N)]

for _ in range(N-1):
  u,v = map(int,input().split())
  u -= 1
  v -= 1
  nbr[u].append(v)
  nbr[v].append(u)

#print(nbr)
  
prv = [-1 for _ in range(N)]
done = [0 for _ in range(N)] 
history = [0 for _ in range(N)]
B = []
ans = [0 for _ in range(N)]

dfs(0, nbr, A, prv, done, history, B, ans)

for i in range(N):
  print(ans[i])

Buggy submission (verdict: Runtime Error):
import bisect as bs

def dfs(i, nbr, A, prv, done, history, B, ans):#深さ優先探索（再帰）
  
  j = bs.bisect_right(B,A[i]) #Bへの挿入予定位置
  #print(i,A[i],j,B)
  
  #A[i]をhistoryの適当な位置に挿入
  if j < len(B):
    history[i] = (B[j], A[i], j) # 更新前の値、更新後の値、更新位置
    B[j] = A[i]
  else:
    history[i] = (-1, A[i], j) # 「追加する」 、追加する値、追加位置（最後）
    B.append(A[i])
  
  ans[i] = len(B) #答え書き込み
  done[i] = 1 #探索済み
  #print(i,B)
  
  for a in nbr[i]:
    if done[a] == 0: #探索前のみ
      dfs(a, nbr, A, prv, done, history, B, ans)
      prv[a] = i
      
  j = history[i][2]
  if history[i][0] >= 0:
    B[j] = history[i][0] #Bを現状復帰
  else:
    B.pop()
    
N = int(input()) 
A = list(map(int,input().split()))

nbr = [[] for _ in range(N)]

for _ in range(N-1):
  u,v = map(int,input().split())
  u -= 1
  v -= 1
  nbr[u].append(v)
  nbr[v].append(u)

#print(nbr)
  
prv = [-1 for _ in range(N)]
done = [0 for _ in range(N)] 
history = [0 for _ in range(N)]
B = []
ans = [0 for _ in range(N)]

dfs(0, nbr, A, prv, done, history, B, ans)

for i in range(N):
  print(ans[i])
Problem p02708 (python)

Fixed submission:
def sum_part(N, k):
  return k*(2*N-k+1)/2-k*(k-1)/2+1
  
N, K = map(int, input().split())
ans = 0
for k in range(K,N+2):
  ans += sum_part(N, k)
  
ans = ans % (10**9 + 7)
  
print(int(ans))

Buggy submission (verdict: Runtime Error):
def sum_part(N, k):
  return k*(2*N-k+1)/2-k*(k-1)/2+1
  
N, K = map(int, input().split())
ans = 0
for k in range(K,N+2)
  ans += sum_part(N, k)
  
print(ans)
Problem p02814 (python)

Fixed submission:
import math
import sys
from functools import reduce

N, M = map(int, input().split())
A = list(map(int, input().split()))

for i in range(N):
  A[i] = A[i] // 2
  
def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)
  
def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

C = lcm_list(A)
B = [0 for _ in range(N)]

for i in range(N):
  B[i] = C // A[i]
  if B[i] % 2 == 0:
    print(0)
    sys.exit()

print( (M // C + 1) // 2)

Buggy submission (verdict: Runtime Error):
import math
import sys
from functools import reduce

N, M = map(int, input().split())
A = list(map(int, input().split()))

def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)
  
def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

C = gcd_list(A)
B = [0 for _ in range(N)]

for i in range(N):
  B[i] = C // A[i]
  if B[i] % 2 == 0:
    print(0)
    sys.exit()

print( (M // C + 1) // 2)
Problem p03213 (python)

Fixed submission:
N = int(input())

fact_ct = [0 for _ in range(N+1)]
pr = []

def primes():
  ans = set()
  visited = set()
  for p in range(2,N+1):
    if p in visited:
      continue
    ans.add(p)
    q = p
    while q <= N:
      visited.add(q)
      q += p    
  return ans

pr = primes() 

def add_fact_ct(n):
  visited = set()
  for p in range(2,N+1):
    if p not in pr:
      continue
    while n % p == 0:
      fact_ct[p] += 1
      n //= p  

for n in range(2, N+1):
  add_fact_ct(n)
  
ct_75 = 0
ct_25 = 0
ct_15 = 0
ct_5 = 0
ct_3 = 0
ct_1 = 0
  
for ct in fact_ct:
  if ct >= 74:
    ct_75 += 1
  if ct >= 24:
    ct_25 += 1
  if ct >= 14:
    ct_15 += 1
  if ct >= 4:
    ct_5 += 1 
  if ct >= 2:
    ct_3 += 1

ans = 0

ans += ct_75

ans += ct_25 * (ct_3-1)
ans += ct_15 * (ct_5-1)

ans += ct_5*(ct_5-1)*(ct_3-2) // 2

print(ans)
#print(fact_ct)

Buggy submission (verdict: Runtime Error):
N = int(input())

fact_ct = [0 for _ in range(N+1)]
pr = []

def primes():
  ans = set()
  visited = set()
  for p in range(2,N+1):
    if p in visited:
      continue
    ans.add(p)
    q = p
    while q <= N:
      visited.add(q)
      q += p
    
def add_fact_ct(n):
  visited = set()
  for p in range(2,N+1):
    if p not in pr:
      continue
    while n % p == 0:
      fact_ct[p] += 1
      n //= p 
    n //= p
  
pr = primes() 
for n in range(2, N+1):
  add_fact_ct(n)
  
ct_75 = 0
ct_25 = 0
ct_15 = 0
ct_5 = 0
ct_3 = 0
ct_1 = 0
  
for ct in fact_ct:
  if ct >= 75:
    ct_75 += 1
  if ct >= 25:
    ct_25 += 1
  if ct >= 15:
    ct_15 += 1
  if ct >= 5:
    ct_5 += 1 
  if ct >= 3:
    ct_3 += 1
  if ct >= 1:
    ct_1 += 1

ans = 0

ans += ct_75 * (ct_1-1)
ans += ct_25 * (ct_3-1)
ans += ct_15 * (ct_5-1)

print(ans)
Problem p03579 (python)

Fixed submission:
from collections import deque

N, M = map(int, input().split())
adj = [ [] for _ in range(N)]
clr = [-1 for _ in range(N)]

#グラフ構築
for _ in range(1,M+1):
  u, v = map(int, input().split())
  u -= 1
  v -= 1
  adj[u].append((v,1))
  adj[v].append((u,1))

#二部グラフか否か判定  
vis = [0 for _ in range(N)]
q = deque([(0,0)])
is_bip = True
#print(clr)
while q:
  p, c = q.popleft()
  clr[p] = c
  vis[p] = 1
  for x, w in adj[p]:
    if vis[x] == 0:
      q.append((x,(w+c)%2))
      #print((x,(w+c)%2))
    else: 
      if (clr[x] + c) % 2 == 0:
        is_bip = False
        break
  if not is_bip:
    break
    
#ここから問題特有の処理
if is_bip:#二部グラフの場合
  apple = clr.count(0)
  orange = clr.count(1)
  #print(apple,orange,M)
  print(apple*orange-M)
  
else:#二部グラフでない場合
  print(N*(N-1)//2-M)

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

I = [[] for _ in range(N)]
for i in range(M):
  a, b = map(int, input().split())
  a -= 1
  b -= 1
  I[a].append(b)
  I[b].append(a)

C = [-1 for _ in range(N)] 
visited = set()

def DFS(p, c):
  C[p] = c
  flag = True
  for q in I[p]:
    #print(p,q)
    if C[q] == c:
      return False
    elif C[q] == -1:
      if not DFS(q, 1-c):
        return False
  return True

#print(DFS(0, 0))
#print(C)
print(C.count(0)*C.count(1)-M if DFS(0, 0) else N*(N-1)//2-M)
Problem p03603 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**4)
N = int(input())
I = [[] for _ in range(N)]

i = 1
for a in list(map(int, input().split())):
  I[a-1].append(i)
  i += 1
X = list(map(int, input().split()))

def dfs(v,I,X):
  INF = 10**20
  DP = [INF for _ in range(X[v]+1)]
  DP[0] = 0
  for i in I[v]:
    x = X[i]
    y = dfs(i,I,X)
    if x < y:
      x,y = y,x  # x >= y
    for a in range(X[v],-1,-1):
      if a-y >= 0:
        DP[a] = DP[a-y] + x
        if a-x >= 0:
          DP[a] = min(DP[a], DP[a-x] + y)
      else:
        DP[a] = INF
        
  ans = min(DP)
  #print(DP, v)
  if ans >= INF:
    print("IMPOSSIBLE")
    sys.exit()                        
    
  del DP, INF
  return ans

dfs(0,I,X)
print("POSSIBLE")

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**6)
N = int(input())
I = [[] for _ in range(N)]

i = 1
for a in list(map(int, input().split())):
  I[a-1].append(i)
  i += 1
X = list(map(int, input().split()))

def dfs(v,I,X):
  INF = 10**20
  DP = [INF for _ in range(X[v]+1)]
  DP[0] = 0
  for i in I[v]:
    x = X[i]
    y = dfs(i,I,X)
    if x < y:
      x,y = y,x  # x >= y
    for a in range(X[v],y-1,-1):
      DP[a] = DP[a-y] + x
      if a-x >= 0:
        DP[a] = min(DP[a], DP[a-x] + y)
    for a in range(y-1, -1, -1):
      DP[a] = INF
  ans = min(DP)
  #print(DP, v)
  if ans >= INF:
    print("IMPOSSIBLE")
    sys.exit()
  return ans

dfs(0,I,X)
print("POSSIBLE")

Buggy submission (verdict: Runtime Error):
import sys
N = int(input())
M = 5000
I = [[] for _ in range(N)]

i = 1
for a in list(map(int, input().split())):
  I[a-1].append(i)
  i += 1
X = list(map(int, input().split()))

def dfs(v,I,X):
  INF = 10**20
  DP = [INF for _ in range(X[v]+1)]
  DP[0] = 0
  for i in I[v]:
    x = X[i]
    y = dfs(i,I,X)
    if x < y:
      x,y = y,x  # x >= y
    for a in range(X[v],y-1,-1):
      DP[a] = DP[a-y] + x
      if a-x >= 0:
        DP[a] = min(DP[a], DP[a-x] + y)
    for a in range(y-1, -1, -1):
      DP[a] = INF
  ans = min(DP)
  #print(DP, v)
  if ans >= INF:
    print("IMPOSSIBLE")
    sys.exit()
  return ans

dfs(0,I,X)
print("POSSIBLE")
Problem p03722 (python)

Fixed submission:
import sys
from collections import deque

INF = 10 ** 20
def Bellman_Ford(I):
  N = len(I)
  d = [INF for _ in range(N)] # 各頂点への最小コスト
  d[0] = 0 # 自身への距離は0
  visited = [0 for _ in range(N)]
  for i in range(N-1):
    update = False # 更新有無
    task = deque([(0,0,0)])

    visited[0] = i-1
    while task: 
      a, b, c = task.popleft() 
      if d[b] > d[a] + c:
        d[b] = d[a] + c 
        update = True   
      if visited[b] <= i:
        for x, ct in I[b]:
          task.append((b, x, ct))
        visited[b] += 1
    if not update:
        break
        
  # 負閉路の検知
  visited = [0 for _ in range(N)]
  neg = [0 for _ in range(N)]
  for i in range(N):
    update = False # 更新有無
    task = deque([(0,0,0)])
    visited[0] = i-1
    while task: 
      a, b, c = task.popleft() 
      if d[b] > d[a] + c:
        d[b] = d[a] + c 
        update = True 
        neg[b] = 1
        
      if visited[b] <= i:
        for x, ct in I[b]:
          task.append((b, x, ct))
        visited[b] += 1
        
    if not update:
        break
        
    if neg[N-1] == 1:
      return []
    
  return d

N, M = map(int,input().split()) # N:頂点数, M:辺の数
I = [[] for _ in range(N)]
for _ in range(M):
  a, b, c = map(int,input().split()) # 始点,終点,コスト
  I[a-1].append((b-1,-c))
  #I.append((b,a,c)) 
#print(I)
d = Bellman_Ford(I)
print(-d[N-1] if d else "inf")

Buggy submission (verdict: Runtime Error):
INF = 10**30
def bellman_ford(s, g):
    d = [INF for _ in range(n)] # 各頂点への最小コスト
    d[s] = 0 # 自身への距離は0
    for i in range(n):
        update = False # 更新が行われたか
        for x, y, z in g:
            if d[y] > d[x] + z:
                d[y] = d[x] + z
                update = True
        if not update:
            break
        # 負閉路が存在
        if i == n-1:
            return []
    return d

def connected_subgraph(s, g_pre):
  visited[s] = 1
  conn.add(s)
  for y in I[s]:
    if visited[y] == 0:
      connected_subgraph(y, g_pre)

n, m = map(int, input().split()) # n:頂点数, m:辺の数
g_pre = []
for _ in range(m):
    x, y, z = map(int, input().split()) # 始点,終点,コスト
    x -= 1
    y -= 1
    z *= -1
    g_pre.append([x, y, z])
    
I = [set() for _ in range(n)] #隣接グラフ
visited = [0 for _ in range(n)]
for x, y, z in g_pre:
  I[x].add(y)    
conn = set() 
connected_subgraph(0, g_pre)

g = []
for x, y, z in g_pre:
    if x in conn:
      g.append([x, y, z])
#print(conn, g)
ans = bellman_ford(0, g)
#print(ans)
print(-ans[n-1] if ans else "inf")
Problem p02576 (python)

Fixed submission:
n, x, t = map(int, input().split())
if n % x == 0:
  print((n//x)*t)
else:
  print(((n//x)+1)*t)

Buggy submission (verdict: Runtime Error):
import math
N, X, T = map(int, input().split())
print(math.ceil(n / x) * t)
Problem p02642 (python)

Fixed submission:
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
c = Counter(a)
m = [True] * (10**6+1)
s = list(set(a))
for u in s:
    t = u * 2
    while t <= 10 ** 6:
        m[t] = False
        t += u
r = 0
for u in s:
    if c[u] == 1 and m[u] == True:
        r += 1
print(r)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = [int(i) for i in input().split()]
a.sort()
cnt = 0

s = [a[0]]
for i in range(1, n):
  s.append(a[i] * s[i-1])

for i in range(n):
  if i == 0:
    if a[i] != a[i+1]:
      cnt += 1
    continue
  if i != n-1:
    if a[i] % s[i-1] != 0 and a[i+1] != a[i]:
    cnt += 1
  if i == n-1:
    if a[i] % s[i-1] != 0:
      cnt += 1

print(cnt)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = [int(i) for i in input().split()]
a.sort()

cnt = 0

for i in range(n):
  if i == 0 and a[i+1] == a[i]:
    continue
  elif i == n-1 and a[i-1] == a[i]:
    continue
  elif i > 0 and i < n-1 and (a[i+1] == a[i] or a[i-1] == a[i]):
    continue
  
  flag = True
  for j in range(i):
    if a[i] % a[j] == 0:
      flag = False
      break
  if flag:
    cnt += 1
    
print(cnt)
Problem p02684 (python)

Fixed submission:
n, k = map(int, input().split())
a = [int(i) for i in input().split()]
b = [-1] * (n+1)
now = 1
history = []

while b[now] == -1:
  b[now] = len(history)
  history.append(now)
  now = a[now-1]

c = len(history) - b[now]
l = b[now]

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

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())
a = [int(i) for i in input().split()]
b = [-1] * (n+1)
now = 1
history = []

while b[now] == -1:
  b[now] = len(history)
  history.append(now)
  now = a[now-1]  

if now == 1:
    print(history[k % len(history)])
else:
    print(history[(k - now) % (len(history) - now) + now])

Buggy submission (verdict: Runtime Error):
import sys
n, k = map(int, input().split())
a = [int(i) for i in input().split()]
b = [-1] * n
now = 0
count = 0
history = []

while b[now] == -1:
  history.append(now+1)
  b[now] = count
  count += 1
  if count == k:
    print(a[now])
    sys.exit()
  if a[now] == now+1:
    print(a[now])
    sys.exit()
  now = a[now]-1

if now != 0:
  k -= now+1
  for i in range(now+1):
    history.pop(0)     

print(history[k % len(history)])

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())
a = [int(i) for i in input().split()]
b = [False] * n
now = 0
count = 0
history = [1]
flag = True

while b[now] == False:
  history.append(a[now])
  b[now] = True
  count += 1
  if count >= k:
    print(a[now])
    flag = False
    break
  if a[now]-1 == now:
    print(a[now])
    flag = False
    break
  now = a[now]-1
  
if flag == True:
  if now != 0:
    k -= now + 1
    history = history[now+1:]
  history.pop()
  print(history[k % len(history)])

Buggy submission (verdict: Runtime Error):
import sys
n, k = map(int, input().split())
a = [int(i) for i in input().split()]
b = [False] * n
now = 0
count = 0
history = [1]

while b[now] == False:
  history.append(a[now])
  b[now] = True
  count += 1
  if count >= k:
    print(a[now])
    sys.exit()
  if a[now]-1 == now:
    print(a[now])
    sys.exit()
  now = a[now]-1


if now != 0:
  k -= now + 1
  history = history[now+1:]
history.pop()
print(history[k % len(history)])

Buggy submission (verdict: Runtime Error):
import sys
n, k = map(int, input().split())
a = [int(i) for i in input().split()]
b = [False] * n
now = 0
count = 0
history = [1]

while b[now] == False:
  history.append(a[now])
  b[now] = True
  count += 1
  if count >= k:
    print(a[now])
    sys.exit()
  now = a[now]-1

if now != 0:
  k -= now + 1
  history = history[now+1:]
history.pop()
print(history[k % len(history)])
Problem p02812 (python)

Fixed submission:
n = int(input())
s = input()
ans = 0
for i in range(n-2):
  if s[i:i+3] == "ABC":
    ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
s = input()
ans = 0
for i in range(n-2):
  if s[i:i+3] == "ABC":
    ans += 1
print(ans
Problem p02853 (python)

Fixed submission:
def test(n):
  m = 0
  if n == 3:
    m += 100000
  elif n == 2:
    m += 200000
  elif n == 1:
    m += 300000
  return m

x, y = map(int, input().split())
ans = test(x) + test(y)
if ans == 600000:
  ans += 400000

print(ans)

Buggy submission (verdict: Runtime Error):
def test(n):
  m = 0
  if n == 3:
    m += 100000
  elif n == 2:
    m += 200000
  elif n == 1:
    m += 300000
  return m

x, y = int(input())
ans = test(x) + test(y)
if ans == 600000:
  ans += 400000

print(ans)
Problem p03086 (python)

Fixed submission:
s = input()
acgt = ['A', 'C', 'G', 'T']
cnt = 0
ans = []

for i in range(len(s)):
  if s[i] in acgt:
    cnt += 1
  else:
    cnt = 0
  ans.append(cnt)

print(max(ans))

Buggy submission (verdict: Runtime Error):
s = input()
acgt = ['A', 'C', 'G', 'T']
cnt = 0
ans = []

for i in range(len(s)):
  if s[i] in acgt:
    cnt += 1
  else:
    ans.append(cnt)
    cnt = 0

print(max(ans))
Problem p03557 (python)

Fixed submission:
# coding: utf-8
n = int(input())
al = sorted(list(int(i) for i in input().split()))
bl = sorted(list(int(i) for i in input().split()))
cl = sorted(list(int(i) for i in input().split()))
ans = 0

def low_left(a, key):
    left = -1
    right = len(a)
    while right - left > 1:
        center = (left + right) // 2
        if a[center] >= key:
            right = center
        else:
            left = center
    return left+1 
    
def high_right(a, key):
    left = -1
    right = len(a)
    while right - left > 1:
        center = (left + right) // 2
        if a[center] <= key:
            left = center
        else:
            right = center
    return n-right
    
for i in bl:
    ans += low_left(al, i) * high_right(cl, i)

print(ans)

Buggy submission (verdict: Runtime Error):
# coding: utf-8
n = int(input())
al = sorted(list(set(int(i) for i in input().split())))
bl = sorted(list(set(int(i) for i in input().split())))
cl = sorted(list(set(int(i) for i in input().split())))
ans = 0

def search(ar, key, flag):
    left = -1
    right = len(ar)
    center = (left + right) // 2
    
    while right - left > 1:
        if ar[center] == key:
            if flag == 0:
                return center
            elif flag == 1:
                return len(ar)-1-center
        elif ar[center] < key:
            left = center
            center = (left + right) // 2
        else:
            right = center
            center = (left + right) // 2
    
    if flag == 0:
        return right
    elif flag == 1:
        return len(ar) - right
        

for i in range(n):
    mid = bl[i]
    top_num = search(al, mid, 0)
    bottom_num = search(cl, mid, 1)
    ans += top_num * bottom_num
    
print(ans)

Buggy submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!
n = int(input())
al = sorted(set(int(i) for i in input().split()))
bl = sorted(set(int(i) for i in input().split()))
cl = sorted(set(int(i) for i in input().split()))
ans = 0

def search(ar, key, flag):
    left = -1
    right = len(ar)
    center = (left + right) // 2
    
    while right - left > 1:
        if ar[center] == key:
            if flag == 0:
                return center
            elif flag == 1:
                return len(ar)-1-center
        elif ar[center] < key:
            left = center
            center = (left + right) // 2
        else:
            right = center
            center = (left + right) // 2
    
    if flag == 0:
        return right
    elif flag == 1:
        return len(ar) - right
        

for i in range(n):
    mid = bl[i]
    top_num = search(al, mid, 0)
    bottom_num = search(cl, mid, 1)
    ans += top_num * bottom_num
    
print(ans)
Problem p03997 (python)

Fixed submission:
# -*- coding: utf-8 -*-
a = int(input())
b = int(input())
h = int(input())
print(int((a + b) * h / 2))

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
a = int(input())
b = int(input())
h = int(input())
return (a + b) * h / 2