Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
A = int(input())
B = Int(input())

if A == B:
  print("EQUAL")
elif A > B:
  print("GREATER")
else:
  print("LESS")

Fixed submission:
A = int(input())
B = int(input())

if A == B:
  print("EQUAL")
elif A > B:
  print("GREATER")
else:
  print("LESS")
Buggy python submission (verdict: Runtime Error):
def exe(x, y):
  X = [0] * x
  Y = [0] * y
  for i in range(x):
    X[i] = (i + 1) * (x - i) * a[i] % MOD
  for i in range(y):
    Y[i] = (i + 1) * (y - i) * b[i] % MOD
  print((sum(X) % MOD) * (sum(Y) % MOD) % MOD)
  

n, m = list(map(int, input().split()))
x = list(map(int, input().split()))
y = list(map(int, input().split()))
MOD = 10 ** 9 + 7
a = [0] * (n - 1)
for i in range(n - 1):
  a[i] = x[i + 1] - x[i]
b = [0] * (n - 1)
for i in range(m - 1):
  b[i] = y[i + 1] - y[i]
exe(n - 1, m - 1)

Fixed submission:
n, m = list(map(int, input().split()))
x = list(map(int, input().split()))
y = list(map(int, input().split()))
MOD = 10 ** 9 + 7
X = 0
Y = 0
for i in range(n - 1):
  t = x[i + 1] - x[i]
  X = (X + (i + 1) * (n - i - 1) * t) % MOD
for i in range(m - 1):
  t = y[i + 1] - y[i]
  Y = (Y + (i + 1) * (m - i - 1) * t) % MOD
print(X * Y % MOD)
Buggy python submission (verdict: Runtime Error):
N, M = list(map(int, input().split()))
ab = [list(map(int, input().split())) for _ in range(M)]
Q = int(input())
vdc = [list(map(int, input().split())) for _ in range(Q)]

L = [[] for _ in range(N)]
for a, b in ab:
  a -= 1
  b -= 1
  L[a].append(b)
  L[b].append(a)

D = [[0] * 10 for _ in range(N)]
Ans = [0] * N

def check(v, d, c):
  if D[v][d] != 0: return
  if d == 0:
    D[v][d] = c
    return
  for i in range(d, -1, -1):
    if D[v][i] != 0: break
    D[v][i] = c
  for i in L[v]:
    pass

import queue
Que = queue.Queue
get = queue.Queue.get
put = queue.Queue.put
emp = queue.Queue.empty

for v, d, c in vdc[::-1]:
  v -= 1
  if D[v][d] != 0: continue
  t = (d << 18) + v
  S = Que()
  put(S, t)
  while not emp(S):
    t = get(S)
    dd = t >> 18
    vv = t & ((1 << 18) - 1)
    if Ans[vv] == 0: Ans[vv] = c
    if dd == 0:
      D[vv][dd] = c
      continue
    for i in range(dd, -1, -1):
      if D[vv][i] != 0: break
      D[vv][i] = c
    for i in L[vv]:
      if D[i][dd - 1] != 0: continue
      t = ((dd - 1) << 18) + i
      put(S, t)

for i in Ans:
  print(i)

Fixed submission:
N, M = list(map(int, input().split()))
ab = [list(map(int, input().split())) for _ in range(M)]
Q = int(input())
vdc = [list(map(int, input().split())) for _ in range(Q)]

L = [[] for _ in range(N)]
for a, b in ab:
  a -= 1
  b -= 1
  L[a].append(b)
  L[b].append(a)

D = [[0] * 11 for _ in range(N)]
Ans = [0] * N

def check(v, d, c):
  if D[v][d] != 0: return
  if d == 0:
    D[v][d] = c
    return
  for i in range(d, -1, -1):
    if D[v][i] != 0: break
    D[v][i] = c
  for i in L[v]:
    pass

import queue
Que = queue.Queue
get = queue.Queue.get
put = queue.Queue.put
emp = queue.Queue.empty

for v, d, c in vdc[::-1]:
  v -= 1
  if D[v][d] != 0: continue
  t = (d << 18) + v
  S = Que()
  put(S, t)
  while not emp(S):
    t = get(S)
    dd = t >> 18
    vv = t & ((1 << 18) - 1)
    if Ans[vv] == 0: Ans[vv] = c
    if dd == 0:
      D[vv][dd] = c
      continue
    for i in range(dd, -1, -1):
      if D[vv][i] != 0: break
      D[vv][i] = c
    for i in L[vv]:
      if D[i][dd - 1] != 0: continue
      t = ((dd - 1) << 18) + i
      put(S, t)

for i in Ans:
  print(i)
Buggy python submission (verdict: Runtime Error):
N, K = list(map(int, input().split()))
a = list(map(int, input().split()))

a.sort()
ans = 0

for i in range(N):
  if a[-1 -i] < K:
    break
  ans += 1

n = N - ans
D = []
re = a[0]
cnt = 0
for i in range(n):
 if re == a[i]:
   cnt += 1
 else:
   D.append([re, cnt])
   cnt = 1
 re = a[i]
else:
  D.append([re, cnt])

L = [{} for _ in range(2 * K)]
M = [[0] * (2 * K) for _ in range(2 * K)]
for i in D:
  for j in range(i[1]):
    if i[0] * (j + 1) >= 2 * K:
      break
    L[i[0] * (j + 1)][i[0]] = 1
    M[i[0] * (j + 1)][i[0]] = 1

for i in D:
  for j in range(i[1]):
    for k in range(K):
      t = i[0] * (j + 1)
      if k + t >= 2 * K:
        break
      if len(L[k]) > 0:
        if M[k][t] == 0:
          for l in L[k].keys():
            M[k + t][l] = 1
            L[k + t][l] = 1
          M[k + t][t] = 1
          L[k + t][l] = 1

for i in D:
  for j in range(K, K + i[0]):
    if len(L[j]) > 0 and M[j][i[0]] == 1:
      ans += i[1]
      break

print(N - ans)



Fixed submission:
def hersCode(l, r):
  ok = r
  ng = l - 1
  while ok - ng > 1:
    mid = (ok + ng) // 2
    if nasu(a[mid]):
      ok = mid
    else:
      ng = mid
  return ok

def nasu(x):
  if x >= K:
    return True
  D = [0] * K
  L = [0]
  f = 0
  for i in a:
    if i == x and f == 0:
      f = 1
      continue
    for jj in range(len(L) - 1, -1, -1):
      j = L[jj]
      if i + j < K:
        if i + j + x >= K:
          return True
        if D[i + j] == 0:
          D[i + j] = 1
          L.append(i + j)
  return False


N, K = list(map(int, input().split()))
a = list(map(int, input().split()))

a.sort()
a.append(10 ** 9 + 1)
ans = hersCode(0, N)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N, MA, MB = list(map(int, input().split()))
abc = [list(map(int, input().split())) for _ in range(N)]

inf = 1000 * N
M = N * 10 + 1
DP = [[[inf] * M for _ in range(M)] for _ in range(N)]

a, b, c = abc[0]
DP[0][a][b] = c

for i in range(1, N):
  a, b, c = abc[i]
  DP[i][a][b] = min(DP[i - 1][a][b], c)
  for j in range(M - 10):
    for k in range(M - 10):
      DP[i][j][k] = min(DP[i][j][k], DP[i - 1][j][k])
      if DP[i - 1][j][k] < inf:
        jj = j + a
        kk = k + b
        DP[i][jj][kk] = min(DP[i - 1][jj][kk], DP[i - 1][j][k] + c)
ans = inf
i = MA
j = MB
while i < M and j < M:
  ans = min(ans, DP[-1][i][j])
  i += MA
  j += MB

if ans == inf:
  print(-1)
else:
  print(ans)


Fixed submission:
N, MA, MB = list(map(int, input().split()))
abc = [list(map(int, input().split())) for _ in range(N)]

inf = 1000 * N
M = N * 10 + 1
DP = [[[inf] * M for _ in range(M)] for _ in range(N)]

a, b, c = abc[0]
DP[0][a][b] = c

for i in range(1, N):
  a, b, c = abc[i]
  DP[i][a][b] = min(DP[i - 1][a][b], c)
  for j in range(M - 10):
    for k in range(M - 10):
      DP[i][j][k] = min(DP[i][j][k], DP[i - 1][j][k])
      if DP[i - 1][j][k] < inf:
        jj = j + a
        kk = k + b
        DP[i][jj][kk] = min(DP[i - 1][jj][kk], DP[i - 1][j][k] + c)
ans = inf
i = MA
j = MB
while i < M and j < M:
  ans = min(ans, DP[-1][i][j])
  i += MA
  j += MB

if ans == inf:
  print(-1)
else:
  print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N, X = list(map(int, input().split()))

ans = N
N = N - X
while N:
  if X < N:
    ans += X * 2
    N, X = X, N - X
  else:
    d, m = divmod(N, X)
    ans += d * X + m * 2
    N, X = m, X - m

print(ans)

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

ans = N
N, X = X, N - X
while N and X:
  if X > N:
    d, m = divmod(X, N)
    if m == 0:
      ans += (d * 2 - 1) * N
    else:
      ans += d * 2 * N
    N, X = N, m
  else:
    d, m = divmod(N, X)
    if m == 0:
      ans += (d * 2 - 1) * X
    else:
      ans += d * 2 * X + m * 2
    N, X = m, X - m

print(ans)
Buggy python submission (verdict: Runtime Error):
a = (int)input()
print(a*a)

Fixed submission:
n = int(input())
print(n*n)
Buggy python submission (verdict: Time Limit Exceeded):
h,w,m=[int(i) for i in raw_input().split()]
r=[0 for i in range(h)]

c=[0 for i in range(w)]
d={}
for i in range(m):
    h1,w1=[int(i)-1 for i in raw_input().split()]
    r[h1]+=1
    c[w1]+=1
    x=str(h1)+"#"+str(w1)
    d[x]=d.get(x,0)+1
maxx=0
for i in range(h):
    for j in range(w):
        x=str(i)+"#"+str(j)
        maxx=max(maxx,r[i]+c[j]-d.get(x,0))
print maxx


Fixed submission:
h,w,m=[int(i) for i in raw_input().split()]
r=[0 for i in range(h)]
c=[0 for i in range(w)]
d={}
for i in range(m):
    h1,w1=[int(j)-1 for j in raw_input().split()]
    r[h1]+=1
    c[w1]+=1
    x=str(h1)+'#'+str(w1)
    d[x]=d.get(x,0)+1
maxx=max(r)
r1=[]
for i in range(len(r)):
    if maxx==r[i]:
        r1.append(i)
maxx=max(c)
c1=[]
for i in range(len(c)):
    if maxx==c[i]:
        c1.append(i)
maxx1=0;flag=0
for i in r1:
    for j in c1:
        x=str(i)+'#'+str(j)
        if(d.get(x,0)==0):
            maxx1=max(maxx1,r[i]+c[j])
            flag=1
        else:
            maxx1=max(maxx1,r[i]+c[j]-d[x])
    if flag:
        break
print maxx1
Buggy python submission (verdict: Time Limit Exceeded):
n,k=[int(i) for i in raw_input().split()]
p=[int(i)-1 for i in raw_input().split()]
c=[int(i) for i in raw_input().split()]
maxx=-10**18
for i in range(n):
  ct=0;j=0;pos=i
  while j<k:
    ct+=c[pos]
    pos=p[pos]
    j+=1
    maxx=max(maxx,ct)
print maxx

Fixed submission:
n,k=[int(i) for i in raw_input().split()]
p=[int(i)-1 for i in raw_input().split()]
c=[int(i) for i in raw_input().split()]
maxx=-10**18
for i in range(n):
  ct=0;j=0;pos=i
  v=[0]*n
  arr=[]
  while j<k:
    if(v[pos]==1):
  	    break
    v[pos]=1
    ct+=c[pos]
    pos=p[pos]
    arr.append(ct)
    j+=1
  val=0
  if(ct>0):
  	val=ct*((k-j)/j)
  else:
  	val=0
  k1=k
  k1%=j
  k1+=j
  for i1 in range(len(arr)):
  	if(k1-i1>j):
  	    maxx=max(maxx,val+arr[i1],val+ct+arr[i1])
  	else:
  	    maxx=max(maxx,val+arr[i1])
print maxx
Buggy python submission (verdict: Runtime Error):
n=input()
a=[int(i) for i in raw_input().split()]
s=0
a.sort()
for i in range(1,n):
  s+=a[i]
 print s

Fixed submission:
n=input()
a=[int(i) for i in raw_input().split()]
a.sort()
s=a[n-1]
for i in range(n/2,n-1):
  s+=a[i]*2
if(n%2==1):
  s-=a[n/2]
print s
Buggy python submission (verdict: Runtime Error):
import sys
# from collections import defaultdict
# from collections import Counter
# from queue import Queue
import math

def main():
    N = int(input())

    As = [int(s) for s in input().split()]
    logsum = 0
    prod = 1
    for a in As:
        logsum += math.log10(a)

    if logsum >= 18:
        print('-1')
        return

    for a in As:
        prod *= a

    print(prod)

    # As = []
    # for i in range(N):
    #     tmp = int(input())
    #     As.append(tmp)

    return 0

if __name__ == '__main__':
    sys.exit(main())


Fixed submission:
import sys
# from collections import defaultdict
# from collections import Counter
# from queue import Queue
import math

def main():
    N = int(input())

    As = [int(s) for s in input().split()]
    logsum = 0
    prod = 1
    for a in As:
        if a == 0:
            print('0')
            return

        logsum += math.log10(a)
        # sys.stderr.write('{}\n'.format(logsum))


    if logsum > 18.2:
        print('-1')
        return

    for a in As:
        prod *= a

    if prod > 10 ** 18:
        print('-1')
        return
    print(prod)

    # As = []
    # for i in range(N):
    #     tmp = int(input())
    #     As.append(tmp)

    return 0

if __name__ == '__main__':
    sys.exit(main())

Buggy python submission (verdict: Runtime Error):
import sys
# from collections import defaultdict
# from collections import Counter
# from queue import Queue
import math

def main():
    N = int(input())

    As = [int(s) for s in input().split()]
    logsum = 0
    prod = 1
    for a in As:
        logsum += math.log10(a)
        prod *= a

    if logsum > 18:
        print('-1')
        return

    print(prod)

    # As = []
    # for i in range(N):
    #     tmp = int(input())
    #     As.append(tmp)

    return 0

if __name__ == '__main__':
    sys.exit(main())


Fixed submission:
import sys
# from collections import defaultdict
# from collections import Counter
# from queue import Queue
import math

def main():
    N = int(input())

    As = [int(s) for s in input().split()]
    logsum = 0
    prod = 1
    for a in As:
        if a == 0:
            print('0')
            return

        logsum += math.log10(a)
        # sys.stderr.write('{}\n'.format(logsum))


    if logsum > 18.2:
        print('-1')
        return

    for a in As:
        prod *= a

    if prod > 10 ** 18:
        print('-1')
        return
    print(prod)

    # As = []
    # for i in range(N):
    #     tmp = int(input())
    #     As.append(tmp)

    return 0

if __name__ == '__main__':
    sys.exit(main())
Buggy python submission (verdict: Runtime Error):
import sys
# from collections import defaultdict
# from collections import Counter
# from queue import Queue

def main():
    # N = int(input())

    N, M = [int(s) for s in input().split()]
    print(int(N * M))

    # As = []
    # for i in range(N):
    #     tmp = int(input())
    #     As.append(tmp)

    return 0

if __name__ == '__main__':
    sys.exit(main())


Fixed submission:
import sys
# from collections import defaultdict
# from collections import Counter
# from queue import Queue

def main():
    # N = int(input())

    A_, B_ = [ch for ch in input().split()]
    A = int(A_)
    Bint = int(float(B_[0]))
    Bfloat = int(B_[2:])

    # print(A)
    # print(Bint)
    # print(Bfloat)

    ans = A * Bint + (A * Bfloat // 100)

    # ans = A + int(A * (B - 1.0))
    print(ans)

    # As = []
    # for i in range(N):
    #     tmp = int(input())
    #     As.append(tmp)

    return 0

if __name__ == '__main__':
    sys.exit(main())
Buggy python submission (verdict: Time Limit Exceeded):
import sys
# from collections import defaultdict
# from collections import Counter
# from queue import Queue
# sys.setrecursionlimit(2000000)

def main():
    N = int(input())
    As = [int(s) for s in input().split()]

    ans = 0
    for i in range(N):
        if ( i + 1 )- As[i] <= 0:
            continue

        for k in range(i):
            if (i + 1) - (k + 1) == As[i] + As[k]:
                ans += 1

    print(ans)

    return 0

if __name__ == '__main__':
    sys.exit(main())


Fixed submission:
import sys
# from collections import defaultdict
from collections import Counter
# from queue import Queue
# sys.setrecursionlimit(2000000)

def main():
    N = int(input())
    As = [int(s) for s in input().split()]

    i_plus_As = [(i+1)+As[i] for i in range(N)]
    counter = Counter(i_plus_As)

    ans = 0
    for i in range(N):
        i_value = ( i + 1 )- As[i]
        if i_value <= 0:
            continue

        ans += counter[i_value]

    print(ans)

    return 0

if __name__ == '__main__':
    sys.exit(main())
Buggy python submission (verdict: Runtime Error):
N,X,M=map(int, input().split())

from math import log, ceil

ans=0

ini=[0]*M
mod=[0]*M
ini[0]=sum(list(range(1,M)))
Counter=[0]*M
Counter[0]=M-1

for i in range(1,M):
    now=i+1
    temp=now
    count=1
    while now**2<M:
        now=now**2
        temp+=now
        count+=1
    m=now**2%M
    ini[i]=temp
    mod[i]=m
    Counter[i]=count
#print(ini[:5])
#print("ok")
#print(Counter[:100])
ans=0
count=0
now=X
done=[-1]*M
ok=False
while True:
    if count+Counter[now-1]>N:
        break
    if done[now-1]==-1 or ok==True:
        done[now-1]=(ans, count)
        ans+=ini[now-1]
        #print(ini[now-1])
        count+=Counter[now-1]
        now=mod[now-1]
    else:
        pans, pcount=done[now-1]
        #print(count, pcount)
        #print("break")
        ans+=(ans-pans)*((N-count)//(count-pcount))
        count+=(count-pcount)*((N-count)//(count-pcount))
        #print(count)
        ok=True





    


while True:
    if count==N:
        break
    ans+=now
    now=now**2
    count+=1

    

print(ans)






#print(ini)
#print(mod)
#print(Counter)

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

ans=0
count=0
now=X
done=[-1]*(M-1)
L=[]
if now==0:
    print(ans)
    exit()
j=False
while True:
    if count==N:
        break

    if now==0:
        print(ans)
        exit()
    else:
        if done[now-1]==-1:
            done[now-1]=1
            L.append(now)
        else:
            for i in range(len(L)):
                if L[i]==now:
                    j=i
            break
    ans+=now
    count+=1
    now=(now**2)%M

if j:
    L=L[j:]

total=sum(L)
length=len(L)

ans+=((N-count)//length)*total
ans+=sum(L[:(N-count)%length])
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from math import gcd
N=int(input())
A=list(map(int, input().split()))


A=sorted(A)
gcda=A[0]
gcdais=True
gcdb=A[0]
MAX=max(A)
counts=[0]*MAX
counts[A[0]-1]+=1
for i in range(1,N):
    
    a=A[i]
    gcdb=gcd(gcdb, a)
    counts[a-1]+=1

for i in range(1,MAX):
    count=0
    now=i+1
    while now<=MAX:
        if counts[now-1]!=0:
            count+=counts[now-1]
        now+=(i+1)
    if count>=2:
        gcdais=False
    #print(count)
    
#print(counts)
if gcdais:
    print("pairwise coprime")
elif gcdb==1:
    print("setwise coprime")
else:
    print("not coprime")


Fixed submission:

from math import gcd
N=int(input())
A=list(map(int, input().split()))


A=sorted(A)
gcda=A[0]
gcdais=True
gcdb=A[0]
MAX=max(A)
counts=[0]*MAX
counts[A[0]-1]+=1
for i in range(1,N):
    
    a=A[i]
    gcdb=gcd(gcdb, a)
    counts[a-1]+=1

for i in range(1,MAX):
    count=0
    now=i+1
    while now<=MAX:
        if counts[now-1]!=0:
            count+=counts[now-1]
        now+=(i+1)
    if count>=2:
        gcdais=False
    #print(count)
    
#print(counts)
if gcdais:
    print("pairwise coprime")
elif gcdb==1:
    print("setwise coprime")
else:
    print("not coprime")
Buggy python submission (verdict: Runtime Error):
H, W, M=map(int, input().split())


L=[[0]*W for _ in range(H)]
for i in range(M):
    h,w=map(int, input().split())
    L[h-1][w-1]=1

rui1=[[0]*W for _ in range(H)]
rui2=[[0]*W for _ in range(H)]

for h in range(H):
    for w in range(W):
        if h==0 and w==0:
            rui1[h][w]=L[h][w]
            rui2[-1-h][-1-w]=L[-1-h][-1-w]
        elif h==0:
            rui1[h][w]=L[h][w]+rui1[h][w-1]
            rui2[-1-h][-1-w]=L[-1-h][-1-w]+rui2[-1-h][-w]
        elif w==0:
            rui1[h][w]=L[h][w]+rui1[h-1][w]
            rui2[-1-h][-1-w]=L[-1-h][-1-w]+rui2[-h][-1-w]

        else:
            rui1[h][w]=L[h][w]+rui1[h-1][w]+rui1[h][w-1]-rui1[h-1][w-1]
            rui2[-1-h][-1-w]=L[-1-h][-1-w]+rui2[-h][-1-w]+rui2[-1-h][-w]-rui2[-h][-w]

ans=0
for h in range(H):
    for w in range(W):
        now=rui1[h][w]+rui2[h][w]-L[h][w]
        if h!=0 and w!=0:
            now-=rui1[h-1][w-1]
        if h!=H-1 and w!=W-1:

            now-=rui2[h+1][w+1]

        ans=max(ans, now)
print(ans)
#print(rui1)
#print(rui2)

Fixed submission:
from collections import defaultdict
H,W,M=map(int, input().split())

hs=[0]*H
ws=[0]*W
D=defaultdict(int)
for i in range(M):
    h,w=map(int, input().split())
    hs[h-1]+=1
    ws[w-1]+=1
    D[(h-1,w-1)]+=1


hmax=max(hs)
wmax=max(ws)
Hs=[]
Ws=[]
for h in range(H):
    if hmax==hs[h]:
        Hs.append(h)

for w in range(W):
    if wmax==ws[w]:
        Ws.append(w)

for h in Hs:
    for w in Ws:
        if D[h,w]==0:
            print(hmax+wmax)
            exit()

print(hmax+wmax-1)
Buggy python submission (verdict: Time Limit Exceeded):
K=int(input())

if K%2==0:
    print(-1)
    exit()


now=0
count=0
N=0
flag=False
while True:
    now+=(7*pow(10,count, K))%K
    now%=K
    #print(N)
    if not flag:
        N+=7*10**(count)
    if N>=K:
        flag=True
    #print(now, count)
    if now==0 and flag:
        print(count+1)
        exit()
    count+=1
    if count>=10**7:
        break


print(-1)

Fixed submission:
K=int(input())

if K%2==0:
    print(-1)
    exit()


now=0
count=0
N=0
flag=False
while True:
    now+=(7*pow(10,count, K))%K
    now%=K
    #print(N)
    if not flag:
        N+=7*10**(count)
    if N>=K:
        flag=True
    #print(now, count)
    if now==0 and flag:
        print(count+1)
        exit()
    count+=1
    if count>10**6:
        break


print(-1)

Buggy python submission (verdict: Time Limit Exceeded):
K=int(input())

if K%2==0:
    print(-1)
    exit()


now=0
count=0
N=0
flag=False
while True:
    now+=(7*pow(10,count, K))%K
    now%=K
    #print(N)
    if not flag:
        N+=7*10**(count)
    if N>=K:
        flag=True
    #print(now, count)
    if now==0 and flag:
        print(count+1)
        exit()
    count+=1


print(-1)

Fixed submission:
K=int(input())

if K%2==0:
    print(-1)
    exit()


now=0
count=0
N=0
flag=False
while True:
    now+=(7*pow(10,count, K))%K
    now%=K
    #print(N)
    if not flag:
        N+=7*10**(count)
    if N>=K:
        flag=True
    #print(now, count)
    if now==0 and flag:
        print(count+1)
        exit()
    count+=1
    if count>10**6:
        break


print(-1)
Buggy python submission (verdict: Runtime Error):
N=int(input())
A=list(map(int, input().split()))
#1000

#1300
#35
L=[0]*N
if A[0]<A[1]:
    L[0]=1
    up=1
elif A[0]==A[1]:
    up==0
else:
    up=-1

for i in range(1,N):
    if i==N-1:
        L[i]=-1
        break
    if up==1:
        if A[i]>A[i+1]:
            up=-1
            L[i]=-1
    elif up==0:
        if A[i-1]<A[i]:
            L[i-1]=1
            up=1
        elif A[i-1]>A[i]:
            up=-1

    else:
        if A[i]<A[i+1]:
            up=1
            L[i]=1

#print(L)
now=1000
have=0
for i in range(len(L)):
    l=L[i]
    if l==1:
        have=now//A[i]
        now=now%A[i]
    elif l==-1:
        now+=A[i]*have
        have=0
print(now)

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

#1300
#35
L=[0]*N
if A[0]<A[1]:
    L[0]=1
    up=1
elif A[0]==A[1]:
    up=0
else:
    up=-1

for i in range(1,N):
    if i==N-1:
        L[i]=-1
        break
    if up==1:
        if A[i]>A[i+1]:
            up=-1
            L[i]=-1
    elif up==0:
        if A[i-1]<A[i]:
            L[i-1]=1
            up=1
        elif A[i-1]>A[i]:
            up=-1

    else:
        if A[i]<A[i+1]:
            up=1
            L[i]=1

#print(L)
now=1000
have=0
for i in range(len(L)):
    l=L[i]
    if l==1:
        have=now//A[i]
        now=now%A[i]
    elif l==-1:
        now+=A[i]*have
        have=0
print(now)
Buggy python submission (verdict: Runtime Error):
X=int(input())
from math import cail
print(ceil(360/X))

Fixed submission:
from math import gcd
def lcm(a,b):
    return a*b//gcd(a,b)
X=int(input())
from math import ceil
print(lcm(360,X)//X)
Buggy python submission (verdict: Runtime Error):
A,B,C,D=map(int, input().split())

#上と右

p=998244353
dp=[[0]*(D+1) for _ in range(C+1)]

dp[A+1][B]=B
dp[A][B+1]=A

for h in range(A,C+1):
    for w in range(B,D+1):
        if h==A and w==B:
            dp[A][B]=1
            continue

        if h>A and w>B:
            x=dp[h][w-1]*h
            y=dp[h-1][w]*w
            z=dp[h-1][w-1]*(h-1)*(w-1)
            sub=x+y-z
            dp[h][w]=(sub)%p
        elif h==A:
            dp[h][w]=(dp[h][w-1]*h)%p
        else:
            dp[h][w]=(dp[h-1][w]*w)%p


print(dp[C][D])

Fixed submission:
A,B,C,D=map(int, input().split())

#上と右

p=998244353
dp=[[0]*(D+1) for _ in range(C+1)]



for h in range(A,C+1):
    for w in range(B,D+1):
        if h==A and w==B:
            dp[A][B]=1
            continue

        if h>A and w>B:
            x=dp[h][w-1]*h
            y=dp[h-1][w]*w
            z=dp[h-1][w-1]*(h-1)*(w-1)
            sub=x+y-z
            dp[h][w]=(sub)%p
        elif h==A:
            dp[h][w]=(dp[h][w-1]*h)%p
        else:
            dp[h][w]=(dp[h-1][w]*w)%p


print(dp[C][D])

Buggy python submission (verdict: Runtime Error):
A,B,C,D=map(int, input().split())

#上と右

p=998244353
dp=[[0]*(D+1) for _ in range(C+1)]

dp[A+1][B]=B
dp[A][B+1]=A
print(dp)
for h in range(A,C+1):
    for w in range(B,D+1):
        if h==A and w==B:
            dp[A][B]=1
            continue

        if h>A and w>B:
            x=dp[h][w-1]*h
            y=dp[h-1][w]*w
            z=dp[h-1][w-1]*(h-1)*(w-1)
            sub=x+y-z
            dp[h][w]=(sub)%p
        elif h==A:
            dp[h][w]=(dp[h][w-1]*h)%p
        else:
            dp[h][w]=(dp[h-1][w]*w)%p


print(dp[C][D])

Fixed submission:
A,B,C,D=map(int, input().split())

#上と右

p=998244353
dp=[[0]*(D+1) for _ in range(C+1)]



for h in range(A,C+1):
    for w in range(B,D+1):
        if h==A and w==B:
            dp[A][B]=1
            continue

        if h>A and w>B:
            x=dp[h][w-1]*h
            y=dp[h-1][w]*w
            z=dp[h-1][w-1]*(h-1)*(w-1)
            sub=x+y-z
            dp[h][w]=(sub)%p
        elif h==A:
            dp[h][w]=(dp[h][w-1]*h)%p
        else:
            dp[h][w]=(dp[h-1][w]*w)%p


print(dp[C][D])