Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict

N=int(input())
S=input()

d = defaultdict(list)
for i in range(N):
  d[int(S[i])].append(i)
    
ans = 0
for n1 in range(10):
  if not d[n1]:continue
  for n2 in range(10):
    if not d[n2]:continue
    if min(d[n1])>max(d[n2]): continue
    for n3 in range(10):
      if not d[n3]:continue
      if min(d[n1])>max(d[n3]) or min(d[n2])>max(d[n3]):continue
      for idx in d[n2]:
        if idx>min(d[n1]) and idx<max(d[n3]):
          ans += 1
          break
            
print(ans)

Fixed submission:
from collections import defaultdict

N=int(input())
S=input()

d = defaultdict(list)
for i in range(N):
  d[int(S[i])].append(i)
    
ans = 0
for n1 in range(10):
  if not d[n1]:continue
  for n2 in range(10):
    if not d[n2]:continue
    if d[n1][0]>d[n2][-1]: continue
    for n3 in range(10):
      if not d[n3]:continue
      if d[n1][0]>d[n3][-1] or d[n2][0]>d[n3][-1]:continue
      for idx in d[n2]:
        if idx>d[n1][0] and idx<d[n3][-1]:
          ans += 1
          break
            
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
L=list(map(int,input().split()))
L = sorted(L)

def binary_search(func, array):
    left,right=0,len(array)-1
    y_left, y_right = func(array[left]), func(array[right])
    while True:
        middle = (left+right)//2
        y_middle = func(array[middle])
        if y_left==y_middle: left=middle
        else: right=middle
        if right-left==1:break

    return left

SUM = 0
for i in range(N-2):
  for j in range(i+1,N-1):
    l1,l2=L[i],L[j]
    if L[-1]<l1+l2:
      k = N-1
    else:
      k = binary_search(lambda x: x<l1+l2, L)
    SUM += max(0,k-j)

print(SUM)

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

def binary_search(func, array, left=0):
    right=len(array)-1
    y_left, y_right = func(array[left]), func(array[right])
    if y_left==False:return 0
    while True:
        middle = (left+right)//2
        y_middle = func(array[middle])
        if y_left==y_middle: left=middle
        else: right=middle
        if right-left==1:break

    return left

SUM = 0
for i in range(N-2):
  for j in range(i+1,N-1):
    l = L[i]+L[j]
    if L[-1]<l:
      k = N-1
    else:
      k = binary_search(lambda x: x<l, L, j+1)
    SUM += max(0,k-j)

print(SUM)
Buggy python submission (verdict: Runtime Error):
from math import log

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

B = [log(A[i]) for i in range(N)]
sumB=sum(B)
C = [B[i]/sumB*M for i in range(N)]
intC = [int(C[i]) for i in range(N)]
r = M - sum(intC)

res = [A[i]//(2**intC[i]) for i in range(N)]

res = sorted(res,reverse=True)

for i in range(r):
  res[i] //= 2

print(sum(res))

Fixed submission:
from heapq import heappop, heappush

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

B = []
for i in range(N):
  heappush(B,-A[i])

for i in range(M):
  a = heappop(B)
  a /= 2
  heappush(B,a)

print(sum([int(-B[i]) for i in range(N)]))
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
minList=[]
for i in range(N):
  if i==0:
    a=int(input())
    minList.append(a)
  else:
    a=int(input())
    MAX=-1
    argmax=-1
    for j in range(len(minList)):
      if minList[j]>=MAX and minList[j]<a:
        argmax=j
        MAX=minList[j]
    if MAX==-1:
      minList.append(a)
    else:
      minList[argmax] = a

print(len(minList))

Fixed submission:
from bisect import bisect_left
from collections import deque

N=int(input())
minList=deque([])
minmax=-1
for i in range(N):
  if i==0:
    a=int(input())
    minList.append(a)
    minmax=a
  else:
    a=int(input())
    if a<=minmax:
      minmax=a
      minList.appendleft(a)
    else:
      idx=bisect_left(minList,a)
      if idx==1:minmax=a
      minList[idx-1]=a
print(len(minList))

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
minList=[]
for i in range(N):
  if i==0:
    a=int(input())
    minList.append([a])
  else:
    a=int(input())
    MAX=-1
    argmax=-1
    for j in range(len(minList)):
      if minList[j][-1]>=MAX and minList[j][-1]<a:
        argmax=j
        MAX=minList[j][-1]
    if MAX==-1:
      minList.append([a])
    else:
      minList[argmax].append(a)

print(len(minList))

Fixed submission:
from bisect import bisect_left
from collections import deque

N=int(input())
minList=deque([])
minmax=-1
for i in range(N):
  if i==0:
    a=int(input())
    minList.append(a)
    minmax=a
  else:
    a=int(input())
    if a<=minmax:
      minmax=a
      minList.appendleft(a)
    else:
      idx=bisect_left(minList,a)
      if idx==1:minmax=a
      minList[idx-1]=a
print(len(minList))
Buggy python submission (verdict: Time Limit Exceeded):
l,r=map(int,input().split())
if l-r>=2019:print(0)
else:
  MIN=10000
  for i in range(l,r):
    for j in range(i+1,r+1):
      p = i*j%2019
      if p<MIN:MIN=p
  print(MIN)

Fixed submission:
l,r=map(int,input().split())
if r-l>=2019:print(0)
else:
  MIN=10000
  for i in range(l,r):
    for j in range(i+1,r+1):
      p = i*j%2019
      if p<MIN:MIN=p
  print(MIN)
Buggy python submission (verdict: Time Limit Exceeded):
R,G,B,N=map(int,input().split())

ans=0
for r in range(N//R+1):
  for g in range(N//G+1):
    if 0<=N-r*R-g*G and (N-r*R-g*G)%B==0:
      #print(r,g,(N-r*R+g*G)//B)
      ans += 1
      
print(ans)

Fixed submission:
R,G,B,N=map(int,input().split())

ans=0
for r in range(N//R+1):
  for g in range(N//G+1):
    if 0<=N-r*R-g*G and (N-r*R-g*G)%B==0:
      #print(r,g,(N-r*R+g*G)//B)
      ans += 1
      
print(ans)
Buggy python submission (verdict: Runtime Error):
N=int(input())

if N == 0:
  print(0)
  exit()

ans = 0
i = 1
while True:
  m = N//i-1
  q,r = divmod(N,m)
  if q == r:
    ans += m
  if m<N**.5:
    break
  i += 1
  
print(ans)

Fixed submission:
N=int(input())

if N == 1:
  print(0)
  exit()

ans = 0
i = 1
while True:
  m = N//i-1
  q,r = divmod(N,m)
  if q == r:
    ans += m
  if m<N**.5:
    break
  i += 1
  
print(ans)

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

ans = 0
i = 1
while True:
  m = N//i-1
  q,r = divmod(N,m)
  if q == r:
    ans += m
  if m<N**.5:
    break
  i += 1
  
print(ans)

Fixed submission:
N=int(input())

if N == 1:
  print(0)
  exit()

ans = 0
i = 1
while True:
  m = N//i-1
  q,r = divmod(N,m)
  if q == r:
    ans += m
  if m<N**.5:
    break
  i += 1
  
print(ans)
Buggy python submission (verdict: Runtime Error):
from bisect import bisect_left

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

idx = bisect_left(A,0)
if idx != 0:
  if idx % 2 == 1:
    if abs(A[idx-1]) > abs(A[idx]):
      A[idx-1] *= -1
      A[idx] *= -1
  for i in range(0,idx-1,2):
    A[i] *= -1
    A[i+1] *= -1

print(sum(A))

Fixed submission:
from bisect import bisect_left

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

idx = bisect_left(A,0)
if idx != 0 and idx != N:
  if idx % 2 == 1:
    if abs(A[idx-1]) > abs(A[idx]):
      A[idx-1] *= -1
      A[idx] *= -1
  for i in range(0,idx-1,2):
    A[i] *= -1
    A[i+1] *= -1

if idx==N:
  if N % 2 == 0:
    print(-sum(A))
    exit()
  else:
    print(-sum(A[:-1])+A[-1])
    exit()

print(sum(A))
Buggy python submission (verdict: Runtime Error):
from math import log2

A,B=map(int,input().split())

def bitpos(x,digit=1):
  bit = x % (2**digit) // (2**(digit-1))
  pos = x % (2**digit)
  return int(bit),pos

max_digit=int(log2(B))+1

xor=[]
for i in range(max_digit):
  abit,apos = bitpos(A,i+1)
  bbit,bpos = bitpos(B,i+1)
  if i == 0:
    ar,br = A%4,B%4
    if (ar,br) in {(0,1),(0,2),(1,1),(1,2),(2,3),(2,0),(3,3),(3,0)}:
      xor.append('1')
      continue
    else:
      xor.append('0')
      continue
  
  if abit == 0 and bbit==0:
    xor.append('0')
    continue
  elif abit == 1 and bbit==0:
    if apos % 2 == 1:
      xor.append('1')
      continue
    else:
      xor.append('0')
      continue
  elif abit == 0 and bbit == 1:
    if bpos % 2 == 0:
      xor.append('1')
      continue
    else:
      xor.append('0')
      continue
  else:
    if abs(apos-bpos) % 2 == 1:
      xor.append('0')
      continue
    else:
      xor.append('1')
      continue
xor = xor[::-1]
print(int(''.join(xor),2))

Fixed submission:
from math import log2

A,B=map(int,input().split())

def bitpos(x,digit=1):
  bit = x % (2**digit) // (2**(digit-1))
  pos = x % (2**digit)
  return int(bit),pos

if B == 0:
  print(0)
  exit()
else:
  max_digit=int(log2(B))+1

xor=[]
for i in range(max_digit):
  abit,apos = bitpos(A,i+1)
  bbit,bpos = bitpos(B,i+1)
  if i == 0:
    ar,br = A%4,B%4
    if (ar,br) in {(0,1),(0,2),(1,1),(1,2),(2,3),(2,0),(3,3),(3,0)}:
      xor.append('1')
      continue
    else:
      xor.append('0')
      continue
  
  if abit == 0 and bbit==0:
    xor.append('0')
    continue
  elif abit == 1 and bbit==0:
    if apos % 2 == 1:
      xor.append('1')
      continue
    else:
      xor.append('0')
      continue
  elif abit == 0 and bbit == 1:
    if bpos % 2 == 0:
      xor.append('1')
      continue
    else:
      xor.append('0')
      continue
  else:
    if abs(apos-bpos) % 2 == 1:
      xor.append('0')
      continue
    else:
      xor.append('1')
      continue
xor = xor[::-1]
print(int(''.join(xor),2))
Buggy python submission (verdict: Time Limit Exceeded):
N,K=map(int, input().split())
*h,=map(int,input().split())
INF=10**12

dp = [INF]*N
dp[0]=0

for i in range(1,N):
  if i <= K:
    dp[i] = min([dp[i-j]+abs(h[i]-h[i-j]) for j in range(1,i+1)])
  else:
    dp[i] = min([dp[i-j]+abs(h[i]-h[i-j]) for j in range(1,K+1)])
  
print(dp[-1])

Fixed submission:
N,K=map(int, input().split())
*h,=map(int,input().split())
INF=10**12

dp = [INF]*N
dp[0]=0

for i in range(1,N):
  if i <= K:
    dp[i] = min([dp[i-j]+abs(h[i]-h[i-j]) for j in range(1,i+1)])
  else:
    dp[i] = min([dp[i-j]+abs(h[i]-h[i-j]) for j in range(1,K+1)])
  
print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
h = list(map(int, input().split()))
K = min(K, N-1)
dp = [0 for i in range(N)]

for i in range(1,N):
  if i == 1:
    dp[1] = abs(h[1] - h[0])
    continue
  
  k = min(K, i)

  dp[i] = min([dp[i-j]+abs(h[i] - h[i-j]) for j in range(1,k+1)])

print(dp[-1])

Fixed submission:
N,K=map(int, input().split())
*h,=map(int,input().split())
INF=10**12

dp = [INF]*N
dp[0]=0

for i in range(1,N):
  if i <= K:
    dp[i] = min([dp[i-j]+abs(h[i]-h[i-j]) for j in range(1,i+1)])
  else:
    dp[i] = min([dp[i-j]+abs(h[i]-h[i-j]) for j in range(1,K+1)])
  
print(dp[-1])
Buggy python submission (verdict: Time Limit Exceeded):
N, W = map(int, input().split())
wv = [[0 for i in range(2)] for j in range(N)]
dp = [[0 for i in range(N+1)] for j in range(W+1)]

for i in range(N):
  wv[i] = list(map(int, input().split()))

for i in range(N):
  for w in range(1,W+1):
    if w < wv[i][0]:
      dp[w][i+1] = dp[w][i]
    else:
      dp[w][i+1] = max(dp[w-wv[i][0]][i]+wv[i][1], dp[w][i])

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

Fixed submission:
N, W = map(int, input().split())
wv = [[0 for i in range(2)] for j in range(N)]
dp = [[0 for i in range(N+1)] for j in range(W+1)]

for i in range(N):
  wv[i] = list(map(int, input().split()))

for i in range(N):
  for w in range(1,W+1):
    if w < wv[i][0]:
      dp[w][i+1] = dp[w][i]
    else:
      dp[w][i+1] = max(dp[w-wv[i][0]][i]+wv[i][1], dp[w][i])

print(dp[-1][-1])
Buggy python submission (verdict: Time Limit Exceeded):
N,W=map(int,input().split())
wv = [tuple(map(int,input().split())) for _ in range(N)]

V = sum([wv[i][1] for i in range(N)])

dp = [W+1] * (V + 1)
dp[0] = 0
for i in range(N):
  w,v=wv[i]
  for j in range(V, v-1, -1):
    dp[j] = min(dp[j-v] + w, dp[j])
    
print(max(i for i in range(V+1) if dp[i] <= W))

Fixed submission:
N,W=map(int,input().split())
wv = [tuple(map(int,input().split())) for _ in range(N)]

V = sum([wv[i][1] for i in range(N)])

dp = [W+1] * (V + 1)
dp[0] = 0
for i in range(N):
  w,v=wv[i]
  for j in range(V, v-1, -1):
    dp[j] = min(dp[j-v] + w, dp[j])
    
print(max(i for i in range(V+1) if dp[i] <= W))
Buggy python submission (verdict: Runtime Error):
N,M=map(int,input().split())
G = [[] for _ in range(N)]
for i in range(M):
  x,y=map(int,input().split())
  G[x-1].append(y-1)
  
dp = [-1]*N

def rec(v):
  if dp[v] != -1:
    return dp[v]
  res = 0
  for next_v in G[v]:
    res = max(res, rec(next_v)+1)
  dp[v] = res
  return dp[v]
  
for i in range(N):
  dp[i] = rec(i)
  
print(max(dp))

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

N,M=map(int,input().split())
G = [[] for _ in range(N)]
for i in range(M):
  x,y=map(int,input().split())
  G[x-1].append(y-1)
  
dp = [-1]*N

def rec(v):
  if dp[v] != -1:
    return dp[v]
  res = 0
  for next_v in G[v]:
    res = max(res, rec(next_v)+1)
  dp[v] = res
  return dp[v]
  
for i in range(N):
  dp[i] = rec(i)
  
print(max(dp))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
p = list(map(float, input().split()))

dp = [[0 for i in range(N+1)] for j in range(N+1)]
dp[0][0] = 1

for i in range(1,N+1):
  for j in range(N+1):
    if j == 0:
      dp[j][i] = (1-p[i-1])*dp[j][i-1]
    else:
      dp[j][i] = (1-p[i-1])*dp[j][i-1] + p[i-1]*dp[j-1][i-1]

sum_ = 0
for i in range(N//2+1, N+1):
  sum_ += dp[i][-1]

print(sum_)

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

dp = [[0 for i in range(N+1)] for j in range(N+1)]
dp[0][0] = 1

for i in range(1,N+1):
  for j in range(i+1):
    if j == 0:
      dp[j][i] = (1-p[i-1])*dp[j][i-1]
    else:
      dp[j][i] = (1-p[i-1])*dp[j][i-1] + p[i-1]*dp[j-1][i-1]

sum_ = 0
for i in range(N//2+1, N+1):
  sum_ += dp[i][-1]

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

N,K=map(int,input().split())
A = np.array([list(map(int,input().split())) for _ in range(N)],dtype=int)
mod = 10**9+7

res = matrix_power(A,N,mod)
print(res.sum()%mod)

power_list=[A]
for i in range(1,K.bit_length()+1):
  power_list.append((power_list[-1]@power_list[-1])%mod)
  
B = np.identity(N).astype(int)
for i in range(K.bit_length()+1):
  if K>>i&1:
    B = (B @ power_list[i])%mod

print(B.sum()%mod)

Fixed submission:
import numpy as np

def matmul(A,B):
    N = len(A)
    C = np.eye(N, dtype=int)
    for n in range(N):
        C[n] = (A[n,:][:,None] * B % mod).sum(axis=0) % mod
    return C

def mat_power(A,k):
    N = len(A)
    if k == 0:
        return np.eye(N,dtype=int)
    X = mat_power(A,k//2)
    X = matmul(X,X)
    return matmul(A,X) if k&1 else X

N,K=map(int,input().split())
A = np.array([list(map(int,input().split())) for _ in range(N)],dtype=int)
mod = 10**9+7

print(mat_power(A,K).sum()%mod)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(int,input().split()))

to = [0]*N

for i in range(N-1):
  SUM = A[i]
  for j in range(i+1,N):
    if SUM+A[j] != SUM^A[j]:
      to[i]=j-1
      break
    SUM += A[j]
    if j == N-1:
      to[i] = j
  
print(sum([max(0,to[i]-i) for i in range(N)])+N)

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

to = [0]*N

for i in range(N-1):
  if i == 0:
    SUM = A[i]
  else:
    SUM -= A[i-1]
  for j in range(min(to[i-1]+1,N-1),N):
    if SUM+A[j] != SUM^A[j]:
      to[i]=j-1
      break
    if j == N-1:
      to[i] = j
      break
    SUM += A[j]
  
print(sum([max(0,to[i]-i) for i in range(N)])+N)
Buggy python submission (verdict: Runtime Error):
H,W=map(int,input().split())
s=[list(map(int, list(input().replace('#','1').replace('.','0')))) for _ in range(W)]

padded = [[0 for i in range(W+2)] for j in range(H+2)]

for i in range(H):
  for j in range(W):
    padded[i+1][j+1] = s[i][j] 

for i in range(1,H+1):
  for j in range(1,W+1):
    if padded[i][j]==1:
      if padded[i+1][j]==0 and padded[i-1][j]==0 and padded[i][j+1]==0 and padded[i][j-1]==0:
        print('No')
        exit()
print('Yes')

Fixed submission:
H,W=map(int,input().split())
s=[list(map(int, list(input().replace('#','1').replace('.','0')))) for _ in range(H)]

padded = [[0 for i in range(W+2)] for j in range(H+2)]

for i in range(H):
  for j in range(W):
    padded[i+1][j+1] = s[i][j] 

for i in range(1,H+1):
  for j in range(1,W+1):
    if padded[i][j]==1:
      if padded[i+1][j]==0 and padded[i-1][j]==0 and padded[i][j+1]==0 and padded[i][j-1]==0:
        print('No')
        exit()
print('Yes')
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-1 or i >= B-K+1:
    print(i)

Fixed submission:
A,B,K=map(int,input().split())
ans = set(range(A,min(A+K,B+1))).union(set(range(B,max(A-1,B-K),-1)))

print(*sorted(ans))
Buggy python submission (verdict: Time Limit Exceeded):
X,Y=map(int,input().split())
if X==Y:
  print(-1)
  exit()
  
i = 2
while True:
  if X*i % Y != 0 and X*i <= 10**18:
    print(X*i)
    exit()
  i += 1
  if X*i > 10**18:
    print(-1)
    exit()

Fixed submission:
X,Y=map(int,input().split())
if X%Y==0:
  print(-1)
  exit()
  
i = 2
while True:
  if X*i % Y != 0 and X*i <= 10**18:
    print(X*i)
    exit()
  i += 1
  if X*i > 10**18:
    print(-1)
    exit()
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())

for h in range(1,3501):
  for n in range(1,3501):
    if (4*h*n-N*n-N*h) and (4*h*n-N*n-N*h) > 0 and (N*h*n) % (4*h*n-N*n-N*h)==0:
      print(h,n,(N*h*n) // (4*h*n-N*n-N*h))
      exit()

Fixed submission:
N=int(input())

for h in range(1,3501):
  for n in range(1,3501):
    if (4*h*n-N*n-N*h) and (4*h*n-N*n-N*h) > 0 and (N*h*n) % (4*h*n-N*n-N*h)==0:
      print(h,n,(N*h*n) // (4*h*n-N*n-N*h))
      exit()
Buggy python submission (verdict: Time Limit Exceeded):
from itertools import permutations

def warshall_floyd(A, INF=10**20):
    d = [[INF for i in range(len(A))] for j in range(len(A))]
    for i in range(len(A)):
        d[i][i] = 0
        for j in A[i].keys():
          d[i][j] = A[i][j]

    for k in range(len(A)):
        for i in range(len(A)):
            for j in range(len(A)):
                d[i][j] = min(d[i][j], d[i][k]+d[k][j])
    
    return d
  
N,M,R=map(int,input().split())
r = list(map(int,input().split()))
r2 = []
for i in range(len(r)):
  r2.append(r[i]-1)
r = r2
G=[{} for _ in range(N)]
for i in range(M):
  a,b,c=map(int,input().split())
  a -= 1
  b -= 1
  G[a][b] = c
  G[b][a] = c

d = warshall_floyd(G)

if R==2:
  print(d[r[0]][r[1]])
  exit()
  
ans = 10**20
for p in permutations(r):
  dist=0
  for i in range(R-1):
    dist += d[p[i]][p[i+1]]
  ans = min(ans,dist)
  
print(ans)

Fixed submission:
from itertools import permutations

def warshall_floyd(A, INF=10**20):
    d = [[INF for i in range(len(A))] for j in range(len(A))]
    for i in range(len(A)):
        d[i][i] = 0
        for j in A[i].keys():
          d[i][j] = A[i][j]

    for k in range(len(A)):
        for i in range(len(A)):
            for j in range(len(A)):
                d[i][j] = min(d[i][j], d[i][k]+d[k][j])
    
    return d
  
N,M,R=map(int,input().split())
r = list(map(int,input().split()))
r2 = []
for i in range(len(r)):
  r2.append(r[i]-1)
r = r2
G=[{} for _ in range(N)]
for i in range(M):
  a,b,c=map(int,input().split())
  a -= 1
  b -= 1
  G[a][b] = G[b][a] = c

d = warshall_floyd(G)

if R==2:
  print(d[r[0]][r[1]])
  exit()
  
ans = 10**20
for p in permutations(r):
  dist=0
  for i in range(R-1):
    dist += d[p[i]][p[i+1]]
  ans = min(ans,dist)
  
print(ans)
Buggy python submission (verdict: Runtime Error):
def gcd(a,b):
  if b == 0:return a
  return gcd(b,a%b)

N=int(input())
T=[]
for i in range(N):
  t = int(input())
  T.append(t)
  if i == 0:continue
  elif i == 1:
    lcm = T[-2]*T[-1]//gcd(T[-2],T[-1])
  else:
    lcm = lcm * T[-1]//gcd(lcm,T[-1])

print(lcm)

Fixed submission:
def gcd(a,b):
  if b == 0:return a
  return gcd(b,a%b)

N=int(input())
T=[]
if N==1:
  print(input())
  exit()
for i in range(N):
  t = int(input())
  T.append(t)
  if i == 0:continue
  elif i == 1:
    lcm = T[-2]*T[-1]//gcd(T[-2],T[-1])
  else:
    lcm = lcm * T[-1]//gcd(lcm,T[-1])

print(lcm)

Buggy python submission (verdict: Runtime Error):
def gcd(a,b):
  if b == 0:return 1
  return gcd(b,a%b)

N=int(input())
T=[]
for i in range(N):
  t = int(input())
  T.append(t)
  if i == 0:continue
  elif i == 1:
    lcm = T[-2]*T[-1]//gcd(T[-2],T[-1])
  else:
    lcm = lcm * T[-1]//gcd(lcm,T[-1])

print(lcm)

Fixed submission:
def gcd(a,b):
  if b == 0:return a
  return gcd(b,a%b)

N=int(input())
T=[]
if N==1:
  print(input())
  exit()
for i in range(N):
  t = int(input())
  T.append(t)
  if i == 0:continue
  elif i == 1:
    lcm = T[-2]*T[-1]//gcd(T[-2],T[-1])
  else:
    lcm = lcm * T[-1]//gcd(lcm,T[-1])

print(lcm)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
a=[int(input()) for _ in range(N)]

visited=[1]
old=1
count=0
while 1:
  new = a[old-1]
  count += 1
  if new in visited:
    print(-1)
    exit()
  if new == 2:
    print(count)
    exit()
  old = new
  visited.append(new)

Fixed submission:
N=int(input())
a=[int(input()) for _ in range(N)]

visited={1,}
old=1
count=0
while 1:
  new = a[old-1]
  count += 1
  if new in visited:
    print(-1)
    exit()
  if new == 2:
    print(count)
    exit()
  old = new
  visited.add(new)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
import sys

sys.setrecursionlimit(10**7)
H,W=map(int,input().split())
sy,sx=map(int,input().split())
gy,gx=map(int,input().split())

sx,sy=sx-1,sy-1
gx,gy=gx-1,gy-1

maze=[[i for i in input()] for _ in range(H)]

visited = [[-1]*W for _ in range(H)]
queue = deque([])
queue.append((sx,sy))
visited[sy][sx] = 0
def bfs(v,queue,gx,gy,maze):
    check=deque([])



    while len(queue) != 0:
        n = queue.popleft()
        x,y = n[0], n[1]
        flag=0

        if n == (gx,gy):
            print(v)
            exit()

        for i, j in [(1,0), (0,1), (-1,0), (0,-1)]:
            if (x+i < 0) or (x+i >=W) or (y+j < 0) or (y+j >=H):
                continue
            if maze[y+j][x+i] == '.' and visited[y+j][x+i] == -1:
                queue.append((x+i,y+j))
                visited[y+j][x+i] = v
            elif maze[y+j][x+i] == '#':
                flag=1
        if flag==1:
            check.append((x,y))

    while len(check) != 0:
        n=check.popleft()
        x,y=n[0],n[1]
        for i in range(-2,3):
            for j in range(-2,3):
                if (x+i < 0) or (x+i >=W) or (y+j < 0) or (y+j >=H):
                    continue
                if maze[y+j][x+i] == '.' and visited[y+j][x+i] == -1:
                    queue.append((x+i,y+j))
                    visited[y+j][x+i] = v+1

    if len(queue)!=0:
        bfs(v+1,queue,gx,gy,maze)



bfs(0,queue,gx,gy,maze)
print(-1)

Fixed submission:
from collections import deque
import sys

sys.setrecursionlimit(10**7)
H,W=map(int,input().split())
sy,sx=map(int,input().split())
gy,gx=map(int,input().split())

sx,sy=sx-1,sy-1
gx,gy=gx-1,gy-1

maze=[[i for i in input()] for _ in range(H)]

visited = [[-1]*W for _ in range(H)]
queue = deque([])
queue.append((sx,sy))
visited[sy][sx] = 0
def bfs(v,queue,gx,gy,maze):
    check=deque([])



    while len(queue) != 0:
        n = queue.popleft()
        x,y = n[0], n[1]
        flag=0

        if n == (gx,gy):
            print(v)
            exit()

        for i, j in [(1,0), (0,1), (-1,0), (0,-1)]:
            if (x+i < 0) or (x+i >=W) or (y+j < 0) or (y+j >=H):
                continue
            if maze[y+j][x+i] == '.' and visited[y+j][x+i] == -1:
                queue.append((x+i,y+j))
                visited[y+j][x+i] = v
            elif maze[y+j][x+i] == '#':
                flag=1
        if flag==1:
            check.append((x,y))

    while len(check) != 0:
        n=check.popleft()
        x,y=n[0],n[1]
        for i in range(-2,3):
            for j in range(-2,3):
                if (x+i < 0) or (x+i >=W) or (y+j < 0) or (y+j >=H):
                    continue
                if maze[y+j][x+i] == '.' and visited[y+j][x+i] == -1:
                    queue.append((x+i,y+j))
                    visited[y+j][x+i] = v+1

    if len(queue)!=0:
        bfs(v+1,queue,gx,gy,maze)



bfs(0,queue,gx,gy,maze)
print(-1)