Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
count=0
if N>777777777:
  N = 7777777777
for i in range(333,N+1):
  X = str(i)
  a3 = X.count("3")
  a5 = X.count("5")
  a7 = X.count("7")
  if(a3>0 and a5>0 and a7>0 and a3+a5+a7==len(X)):
    count+=1
print(count)

Fixed submission:
N = int(input())
S = len(str(N))
T = ["7","5","3"]
ans = 0
for s in range(3,S+1):
    for i in range(3**s):
        A = []
        n = i
        for j in range(s):
            A.append(n%3)
            n//=3
        if len(set(A))<3:continue
        k = "".join([T[a] for a in A])
        if int(k)<=N:ans+=1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int,input().split())
for i in range(N,M+1):
    if M%i==0:
        print(M//i)
        break

Fixed submission:
N,M = map(int,input().split())
A = []
for i in range(1,M+1):
    if i*i>M:break
    if M%i==0:
        A.append(i)
        A.append(M//i)
A.sort()
for a in A:
    if a>=N:
        print(M//a)
        break
Buggy python submission (verdict: Runtime Error):
S = input()
T = input()
ans = "Yes"
start = [-1]*26
goal = [-1]*26
for i in range(len(S)):
    s,t = ord(S[i])-96,ord(T[i])-96
    if start[s]!=-1 or goal[t]!=-1:
        if start[s]!=t or goal[t]!=s:
            ans = "No"
    else:
        start[s] = t
        goal[t] = s
print(ans)

Fixed submission:
S = input()
T = input()
ans = "Yes"
start = [-1]*27
goal = [-1]*27
for i in range(len(S)):
    s,t = ord(S[i])-96,ord(T[i])-96
    if start[s]!=-1 or goal[t]!=-1:
        if start[s]!=t or goal[t]!=s:
            ans = "No"
    else:
        start[s] = t
        goal[t] = s
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
S = input()
K = int(input())
N = len(S)
A = set([s for s in S])
A = sorted(A)
C = set()
k = 0
while len(C)<K:
    for i in range(N):
        if S[i]==A[k]:
            for j in range(i,N):
                C.add(S[i:j+1])
    k+=1
C = sorted(C)
print(C[K-1])

Fixed submission:
S = input()
K = int(input())
N = len(S)
C = set()
for i in range(N):
    for j in range(i,min(i+K,N)):
        C.add(S[i:j+1])
C = sorted(C)
print(C[K-1])

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
K = int(input())
N = len(S)
C = set()
for i in range(N):
    for j in range(i,N):
        C.add(S[i:j+1])
C = sorted(C)
print(C[K-1])

Fixed submission:
S = input()
K = int(input())
N = len(S)
C = set()
for i in range(N):
    for j in range(i,min(i+K,N)):
        C.add(S[i:j+1])
C = sorted(C)
print(C[K-1])

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
K = int(input())
N = len(S)
C = []
for i in range(N):
    for j in range(i,N):
        C.append(S[i:j+1])
C.sort()
b = ""
k = 0
for c in C:
    if b!=c:
        k+=1
        b=c
    if k==K:
        print(b)
        break

Fixed submission:
S = input()
K = int(input())
N = len(S)
C = set()
for i in range(N):
    for j in range(i,min(i+K,N)):
        C.add(S[i:j+1])
C = sorted(C)
print(C[K-1])
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int,input().split()))
B = [0]
for i in range(N):
    B.append(A[i]+B[i])
ans = 0
for i in range(N):
    for j in range(i+1,N+1):
        if B[j]-B[i]==0:ans+=1
print(ans)

Fixed submission:
from collections import Counter
N = int(input())
A = list(map(int,input().split()))
b = 0
c  = Counter([0])
ans = 0
for i in range(N):
    b += A[i]
    ans += c[b]
    c[b] += 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int,input().split()))
cnt = 0
for i in range(N):
  for j in range(i,N):
    if i==j:
      S = A[j]
    else:
      S += A[j]
    if S==0:
      cnt+=1
print(cnt)

Fixed submission:
from collections import Counter
N = int(input())
A = list(map(int,input().split()))
b = 0
c  = Counter([0])
ans = 0
for i in range(N):
    b += A[i]
    ans += c[b]
    c[b] += 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
X = list(map(int,input().split()))
for i in range(N):
    A = X[:i] + X[i+1:]
    A.sort()
    print(A[(N-1)//2])

Fixed submission:
import copy
N = int(input())
X = list(map(int,input().split()))
Y = copy.copy(X)
X.sort()
index = N//2
for i in range(N):
    print(X[index] if X[index]>Y[i] else X[index-1])
Buggy python submission (verdict: Time Limit Exceeded):
A,B,K = map(int,input().split())
for i in range(A,B+1):
    if i < A+K or B-K < i: print(i)

Fixed submission:
A,B,K = map(int,input().split())
if 2*K<B-A+1:
    S = [i for i in range(A,A+K)]+[i for i in range(B-K+1,B+1)]
else:
    S = [i for i in range(A,B+1)]
for s in S:
    print(s)
Buggy python submission (verdict: Time Limit Exceeded):
H,W,D = map(int,input().split())
A = [list(map(int,input().split())) for i in range(H)]
C = [[] for i in range(H*W+1)]
for i in range(H):
    for j in range(W):
        C[A[i][j]] = (i,j)
Q = int(input())
for i in range(Q):
    L,R = map(int,input().split())
    cost = 0
    i,j = C[L]
    while L!=R:
        L+=D
        x,y = C[L]
        cost += abs(x-i)+abs(y-j)
        i,j = C[L]
    print(cost)

Fixed submission:
#19:38
#20:19

H,W,D = map(int,input().split())
MAX = H*W
A = [list(map(int,input().split())) for i in range(H)]
Point = [0]*(MAX+1)
for h in range(H):
    for w in range(W):
        Point[A[h][w]] = (h,w)
K = []
for i in range(1,D+1):
    List = []
    n = i
    h,w = Point[n]
    cost = 0
    while n<=MAX:
        y,x = Point[n]
        cost += abs(h-y)+abs(w-x)
        List.append(cost)
        h,w = y,x
        n+=D
    K.append(List)
Q = int(input())
for i in range(Q):
    L,R = map(int,input().split())
    a,l,r = (L-1)%D,(L-1)//D,(R-1)//D
    print(K[a][r]-K[a][l])

Buggy python submission (verdict: Time Limit Exceeded):
H,W,D = map(int,input().split())
A = [list(map(int,input().split())) for i in range(H)]
C = [[] for i in range(H*W+1)]
for i in range(H):
    for j in range(W):
        C[A[i][j]] = (i,j)
Q = int(input())
for i in range(Q):
    L,R = map(int,input().split())
    cost = 0
    i,j = C[L]
    while L!=R:
        L+=D
        x,y = C[L]
        cost += abs(x-i)+abs(y-j)
        i,j = C[L]
    print(cost)

Fixed submission:
#19:38
#20:19

H,W,D = map(int,input().split())
MAX = H*W
A = [list(map(int,input().split())) for i in range(H)]
Point = [0]*(MAX+1)
for h in range(H):
    for w in range(W):
        Point[A[h][w]] = (h,w)
K = []
for i in range(1,D+1):
    List = []
    n = i
    h,w = Point[n]
    cost = 0
    while n<=MAX:
        y,x = Point[n]
        cost += abs(h-y)+abs(w-x)
        List.append(cost)
        h,w = y,x
        n+=D
    K.append(List)
Q = int(input())
for i in range(Q):
    L,R = map(int,input().split())
    a,l,r = (L-1)%D,(L-1)//D,(R-1)//D
    print(K[a][r]-K[a][l])
Buggy python submission (verdict: Runtime Error):
def f(v,p,G,T):
    global ans
    INF = 10**10
    for C in G[v]:
        c,d = C[0],C[1]
        if T[c]==INF:
            T[c] = T[v]+d
            f(c,v,G,T)
        elif T[c]!=T[v]+d:
            ans = "No"
def main():
    global ans
    N,M = map(int,input().split())
    G = [[] for i in range(N+1)]
    for i in range(M):
        L,R,D = map(int,input().split())
        G[L].append([R,D])
        G[R].append([L,-D])
    INF = 10**10
    T = [INF]*(N+1)
    while T.count(INF)!=0:
        for i in range(N+1):
            if T[i] == INF:
                T[i]=0
                f(i,-1,G,T)
        if ans=="No":break
ans = "Yes"
main()
print(ans)

Fixed submission:
import sys
sys.setrecursionlimit(10**8)
def f(v,p,G,T):
    global ans
    INF = 10**10
    for C in G[v]:
        c,d = C[0],C[1]
        if T[c]==INF:
            T[c] = T[v]+d
            f(c,v,G,T)
        elif T[c]!=T[v]+d:
            ans = "No"
def main():
    global ans
    N,M = map(int,input().split())
    G = [[] for i in range(N+1)]
    for i in range(M):
        L,R,D = map(int,input().split())
        G[L].append([R,D])
        G[R].append([L,-D])
    INF = 10**10
    T = [INF]*(N+1)
    while T.count(INF)!=0:
        for i in range(N+1):
            if T[i] == INF:
                T[i]=0
                f(i,-1,G,T)
        if ans=="No":break
ans = "Yes"
main()
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

C=[]
S=[]
F=[]

for i in range(N-1):
  a,b,c = map(int,input().split())
  C.append(a)
  S.append(b)
  F.append(c)

for i in range(N):
  if i == N-1:
    print(0)
  else:
    T = S[i]+C[i]
    for k in range(i+1,N-1):
      a = 0
      while T > S[k]+a*F[k]:
        a+=1
      T = S[k]+a*F[k]+C[k]
    print(int(T))


Fixed submission:
N = int(input())
C=[]
S=[]
F=[]
for i in range(N-1):
  a,b,c = map(int,input().split())
  C.append(a)
  S.append(b)
  F.append(c)

for i in range(N-1):
  T = 0
  for j in range(i,N-1):
    if T < S[j]:
      T = S[j]
    elif T%F[j]==0:
      T = T
    else:
      T = T+F[j] - T%F[j]
    T = T + C[j]
  print(T)
print(0)
Buggy python submission (verdict: Time Limit Exceeded):
def is_like2017(X):
  res = 1
  for x in [X,(X+1)/2]:
    y = int(x**0.5)
    for i in range(2,y+1):
      if x%i==0:
        res=0
        break
    if res==0:
      break
  return res

prime = []
for i in range(10**5+2):
  if i<2 or i%2==0:
    prime.append(0)
  else:
    if is_like2017(i)==1:
      prime.append(1)
    else:
      prime.append(0)

#input
Q = int(input())
ans = []
for i in range(Q):
  l,r = map(int,input().split())
  print(sum(prime[l:r+1]))

Fixed submission:
def is_like2017(X):
  res = 1
  for x in [X,(X+1)/2]:
    y = int(x**0.5)
    for i in range(2,y+1):
      if x%i==0:
        res=0
        break
    if res==0:
      break
  return res

prime_accumulation = []
for i in range(10**5+2):
  if i<2:
    prime_accumulation.append(0)
  elif i%2==0:
    prime_accumulation.append(prime_accumulation[i-1])
  else:
    if is_like2017(i)==1:
      prime_accumulation.append(prime_accumulation[i-1]+1)
    else:
      prime_accumulation.append(prime_accumulation[i-1])

#input
Q = int(input())
ans = []
for i in range(Q):
  l,r = map(int,input().split())
  print(prime_accumulation[r]-prime_accumulation[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
def is_prime(x):
  res = 1
  y = int(x**0.5)
  for i in range(2,y+1):
    if x%i==0:
      res = 0
      break
  return res

prime = []
for i in range(10**5+2):
  if i<2 or i%2==0:
    prime.append(0)
  else:
    if is_prime(i)==1 and is_prime((i+1)/2)==1:
      prime.append(1)
    else:
      prime.append(0)
#input
Q = int(input())
ans = []
for i in range(Q):
  l,r = map(int,input().split())
  ans.append(sum(prime[l:r+1]))
for a in ans:
  print(a)

Fixed submission:
def is_like2017(X):
  res = 1
  for x in [X,(X+1)/2]:
    y = int(x**0.5)
    for i in range(2,y+1):
      if x%i==0:
        res=0
        break
    if res==0:
      break
  return res

prime_accumulation = []
for i in range(10**5+2):
  if i<2:
    prime_accumulation.append(0)
  elif i%2==0:
    prime_accumulation.append(prime_accumulation[i-1])
  else:
    if is_like2017(i)==1:
      prime_accumulation.append(prime_accumulation[i-1]+1)
    else:
      prime_accumulation.append(prime_accumulation[i-1])

#input
Q = int(input())
ans = []
for i in range(Q):
  l,r = map(int,input().split())
  print(prime_accumulation[r]-prime_accumulation[l-1])
Buggy python submission (verdict: Runtime Error):
c1 = list(input())
c2 = list(input())
for i in range(3):
    if c1[i]!=c[2-i]:
        print("NO")
        exit()
print("YES")

Fixed submission:
c1 = list(input())
c2 = list(input())
for i in range(3):
    if c1[i]!=c2[2-i]:
        print("NO")
        exit()
print("YES")
Buggy python submission (verdict: Time Limit Exceeded):
import bisect
N = int(input())
D = list(map(int,input().split()))
M = int(input())
T = list(map(int,input().split()))
T.sort()
for i in range(N):
    b = bisect.bisect_left(T,D[i])
    if b<M and D[i]==T[b]:
        del T[b]
        M-=1
print("YES" if M==0 else "NO")

Fixed submission:
from collections import defaultdict
N = int(input())
D = list(map(int,input().split()))
M = int(input())
T = list(map(int,input().split()))
ans = "YES"
d = defaultdict(lambda : 0)
for i in range(N):
    d[D[i]] += 1
for j in range(M):
    if d[T[j]] == 0:
        ans = "NO"
        break
    d[T[j]] -= 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import bisect
N = int(input())
D = list(map(int,input().split()))
M = int(input())
T = list(map(int,input().split()))
T.sort()
for i in range(N):
    b = bisect.bisect_left(T,D[i])
    if b<M and D[i]==T[b]:
        T[b] = 0
        T.sort()
print("YES" if T.count(0)==M else "NO")

Fixed submission:
from collections import defaultdict
N = int(input())
D = list(map(int,input().split()))
M = int(input())
T = list(map(int,input().split()))
ans = "YES"
d = defaultdict(lambda : 0)
for i in range(N):
    d[D[i]] += 1
for j in range(M):
    if d[T[j]] == 0:
        ans = "NO"
        break
    d[T[j]] -= 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
count = []
for i in range(N):
    a = int(input())
    if count.count(a)>0:
        count.remove(a)
    else:
        count.append(a)
print(len(count))

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

b = []
for x in a:
  b += [x-1,x,x+1]
b.sort()

res = 0
for x in set(b):
  res = max(res,b.count(x))
print(res)

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

b = [0 for i in range(-1,max(a)+2)]
for x in a:
  b[x-1]+=1
  b[x]+=1
  b[x+1]+=1
print(max(b))
Buggy python submission (verdict: Runtime Error):
n = list(input().split())
if n[0]==n[2]:
    print("Yes")
else:
    print("No")

Fixed submission:
n = list(input())
if n[0]==n[2]:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
mmax = 0
def function(string):
  global mmax
  n = len(string)
  if n<2:
    return
  if n%2==0:
    if string[0:int(n/2)]==string[int(n/2):n]:
      mmax = max(mmax, n)
  function(string[0:n-1])
  function(string[1:n])
function(s[0:len(s)-1])
function(s[1:len(s)])
print(mmax)

Fixed submission:
s = input()
mmax = 0
n = len(s)
while(n>1):
  s = s[0:n-1]
  n = len(s)
  if n<2:
    break
  if s[0:int(n/2)]==s[int(n/2):n]:
    mmax = max(mmax, n)
print(mmax)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a = [int(input())-1 for i in range(N)]
ans = 0
index = 0
b = [False]*N
b[0] = True
while index!=1:
    index = a[index]
    if b[index]:
        ans = -1
        break
    ans += 1
print(ans)

Fixed submission:
N = int(input())
a = [int(input())-1 for i in range(N)]
cnt = 0
index = 0
while True:
    if index == 1:
        print(cnt)
        break
    elif cnt>N:
        print(-1)
        break
    index = a[index]
    cnt += 1

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a = [int(input()) for i in range(N)]
count = 0
i = 0
while True:
    i = a[i]-1
    count+=1
    if i==1:
        break
    elif i==0:
        count=-1
        break
print(count)

Fixed submission:
N = int(input())
a = [int(input())-1 for i in range(N)]
cnt = 0
index = 0
while True:
    if index == 1:
        print(cnt)
        break
    elif cnt>N:
        print(-1)
        break
    index = a[index]
    cnt += 1
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
s = [int(input()) for i in range(N)]
def dfs(n,count):
    global N,s
    if n == N:
        if count%10==0:
            count = 0
        return count
    return max(dfs(n+1,count),dfs(n+1,count+s[n]))
print(dfs(0,0))

Fixed submission:
N = int(input())
s = []
s_10 = []
for i in range(N):
    x = int(input())
    if x%10 ==0:
        s_10.append(x)
    else:
        s.append(x)
s_10.sort()
s.sort()
if len(s)==0:
    print(0)
    exit()
if sum(s)%10==0:
    print(sum(s)+sum(s_10)-min(s))
else:
    print(sum(s)+sum(s_10))
Buggy python submission (verdict: Runtime Error):
X = int(input())
def dfs(t, x):
    global X
    if t>X:
        return X
    if x==X:
        return t-1
    return min(dfs(t+1,x+t),dfs(t+1,x))
print(dfs(0,0))

Fixed submission:
X = int(input())
sum_time = 0
for i in range(X):
    sum_time+=(i+1)
    if sum_time>=X:
        print(i+1)
        break
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
MOD = 10**9+7
ans = 1
for i in range(2,N+1):
  ans *= i
print(ans%MOD)

Fixed submission:
import math
print(math.factorial(int(input()))%(10**9+7))
Buggy python submission (verdict: Time Limit Exceeded):
k,s = map(int,input().split())
count = 0
for x in range(k+1):
    if x==s:
        count+=1
    elif x+2*k>=s:
        for y in range(k+1):
            if x+y==s:
                count+=1
            elif x+y+k>=s:
                for z in range(k+1):
                    if x+y+z==s:
                        count+=1
                        break
print(count)

Fixed submission:
k,s = map(int,input().split())
count = 0
for x in range(k+1):
    for y in range(k+1):
        z = s-x-y
        if z>=0 and z<=k:
            count+=1
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
k,s = map(int,input().split())
count = 0
for x in range(max(0,s-2*k),k+1): 
    if x==s:
        count+=1
    else:
        for y in range(max(0,s-k-x),k+1):
            if x+y==s:
                count+=1
            else:
                for z in range(max(0,s-x-y),k+1):
                    if x+y+z == s:
                       count+=1
                       break
print(count)

Fixed submission:
k,s = map(int,input().split())
count = 0
for x in range(k+1):
    for y in range(k+1):
        z = s-x-y
        if z>=0 and z<=k:
            count+=1
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
k,s = map(int,input().split())
count = 0
for x in range(max(0,s-2*k),k+1): 
    if x==s:
        count+=1
    else:
        for y in range(max(0,s-k-x),k+1):
            if x+y==s:
                count+=1
            else:
                for z in range(max(0,s-x-y),k+1):
                    if x+y+z == s:
                       count+=1
print(count)

Fixed submission:
k,s = map(int,input().split())
count = 0
for x in range(k+1):
    for y in range(k+1):
        z = s-x-y
        if z>=0 and z<=k:
            count+=1
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
k,s = map(int,input().split())
count = 0
for x in range(max(0,s-2*k),k+1):
    for y in range(max(0,s-k-x),k+1):
        for z in range(max(0,s-x-y),k+1):
            if x+y+z == s:
                count+=1
print(count)

Fixed submission:
k,s = map(int,input().split())
count = 0
for x in range(k+1):
    for y in range(k+1):
        z = s-x-y
        if z>=0 and z<=k:
            count+=1
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
k,s = map(int,input().split())
count = 0
for x in range(k+1):
    for y in range(k+1):
        for z in range(k+1):
            if x+y+z == s:
                count+=1
print(count)

Fixed submission:
k,s = map(int,input().split())
count = 0
for x in range(k+1):
    for y in range(k+1):
        z = s-x-y
        if z>=0 and z<=k:
            count+=1
print(count)
Buggy python submission (verdict: Time Limit Exceeded):
C = ["dream","dreamer","erase","eraser"]
S = input()
N = len(S)
T = [(0,"")]
ans = "NO"
while T:
    t = T.pop()
    if t[0]>N:continue
    if t[0]==N and t[1]==S:
        ans="YES"
    if t[1]!=S[:t[0]]:continue
    for c in C:
        T.append((t[0]+len(c),t[1]+c))
print(ans)

Fixed submission:
S = input()[::-1]
N = len(S)
T = ""
n = 0
C = ["maerd","remaerd","esare","resare"]
while n<N:
    if S[n]=="m":
        T+=C[0]
        n+=5
    elif S[n]=="e":
        T+=C[2]
        n+=5
    elif S[n]=="r":
        if N-n<6:break
        if S[n+2]=="m":
            T+=C[1]
            n+=7
        elif S[n+2]=="s":
            T+=C[3]
            n+=6
        else:break
    else:break
print("YES" if S==T else "NO")
Buggy python submission (verdict: Runtime Error):
a,b,x = map(int,input().split)
if a>0:
  a-=1
else:
  b+=1
print(b//x - a//x)

Fixed submission:
a,b,x = map(int,input().split())
b = b//x
a = a//x-1 if a%x==0 else a//x
print(b-a)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = N*(N+1)//2
for n in range(N,0,-1):
    if S-n<N:
        print(n)
    else:
        S-=n

Fixed submission:
N = int(input())
X = 1
while X*(X+1)<N*2:
    X+=1
flg = X*(X+1)//2-N
for n in range(X):
    if n+1==flg:
        continue
    else:
        print(n+1)
Buggy python submission (verdict: Runtime Error):
N,K = map(int,input().split())
print(K*((M-1)**(K-1)))

Fixed submission:
N,K = map(int,input().split())
S = K
while(1):
    if N==1:
        break
    S *= (K-1)
    N-=1
print(S)
Buggy python submission (verdict: Runtime Error):
import math
N = int(input())
for i in range(N):
  a,t = map(int,input().split())
  if i == 0:
    x,y = a,t
  else:
    xa = math.ceil(x/a)
    yb = math.ceil(y/b)
    c = max(xa,yb)
    x,y = a*c,b*c
print(x+b)

Fixed submission:
N = int(input())
for i in range(N):
  a,t = map(int,input().split())
  if i == 0:
    x,y = a,t
  else:
    xa = x//a if x%a==0 else x//a+1
    yt = y//t if y%t==0 else y//t+1
    c = max(xa,yt)
    x,y = a*c,t*c
print(x+y)

Buggy python submission (verdict: Runtime Error):
import math
N = int(input())
for i range(N):
  a,t = map(int,input().split())
  if i == 0:
    x,y = a,t
  else:
    xa = math.ceil(x/a)
    yb = math.ceil(y/b)
    c = max(xa,yb)
    x,y = a*c,b*c
print(x+y)

Fixed submission:
N = int(input())
for i in range(N):
  a,t = map(int,input().split())
  if i == 0:
    x,y = a,t
  else:
    xa = x//a if x%a==0 else x//a+1
    yt = y//t if y%t==0 else y//t+1
    c = max(xa,yt)
    x,y = a*c,t*c
print(x+y)

Buggy python submission (verdict: Runtime Error):
import math
N = int(input())
for i range(N):
  a,t = map(int,input().split())
  if i == 0:
    x,y = a,t
  else:
    xa = math.ceil(x/a)
    yb = math.ceil(y/b)
    c = max(xa,yb)
    x,y = a*c,b*c
print(x+b)

Fixed submission:
N = int(input())
for i in range(N):
  a,t = map(int,input().split())
  if i == 0:
    x,y = a,t
  else:
    xa = x//a if x%a==0 else x//a+1
    yt = y//t if y%t==0 else y//t+1
    c = max(xa,yt)
    x,y = a*c,t*c
print(x+y)
Buggy python submission (verdict: Time Limit Exceeded):




data = input().split()

N, k = int(data[0]), int(data[1])

tab = []

data = input().split()
for i in range(N):
    tab.append(int(data[i]) - 1)


parcour = []

position = 0

while (not (position in parcour)):
    parcour.append(position)
    position = tab[position]
i = 0
while parcour[i] != position:
    i+= 1

sizeCycle = len(parcour) - i 

#print (parcour)
if (k < len(parcour)):
    print(parcour[k] + 1)
else:
    print(parcour[i + ((k - i) % sizeCycle)] + 1)
    


Fixed submission:




data = input().split()

N, k = int(data[0]), int(data[1])

tab = []

data = input().split()
for i in range(N):
    tab.append(int(data[i]) - 1)


parcour = []
tmp = [0] * N

position = 0

while (tmp[position] == 0):
    parcour.append(position)
    tmp[position] = 1
    position = tab[position]
i = 0
while parcour[i] != position:
    i+= 1

sizeCycle = len(parcour) - i 

#print (parcour)
if (k < len(parcour)):
    print(parcour[k] + 1)
else:
    print(parcour[i + ((k - i) % sizeCycle)] + 1)