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

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

checker = [None for i in range(n)]
checker[0] = 0
num = 0
count = 0

flag = 0
while flag==0 and count!=k:
    if checker[lst[num]-1]==None:
        checker[lst[num]-1]=count+1
        count+=1
        num = lst[num]-1
    else:
        flag = 1
        count+=1

if flag==1:
    remaining = (k-checker[lst[num]-1])%(count-checker[lst[num]-1])
    num = lst[num]-1
    # print("~~~")
    # print("rem",remaining)
    # print("checker",checker)
    # print("num",num)
    # print("count",count)
    for i in range(remaining):
        num = lst[num]-1

print(num+1)

Buggy submission (verdict: Runtime Error):
n,k = list(map(int, input().split()))
lst = list(map(int, input().split()))

checker = [None for i in range(n)]
checker[0] = 0
num = 0
count = 0

flag = 0
while flag==0 and count!=k:
    if checker[lst[num]-1]==None:
        checker[lst[num]-1]=count+1
        count+=1
        num = lst[num]-1
    else:
        flag = 1
        count+=1

remaining = (k-checker[lst[num]-1])%(count-checker[lst[num]-1])
num = lst[num]-1
# print("~~~")
# print("rem",remaining)
# print("checker",checker)
# print("num",num)
# print("count",count)

for i in range(remaining):
    num = lst[num]-1

print(num+1)
Problem p02721 (python)

Fixed submission:
n,k,c = map(int, input().split())
s = input()

asc = []
des = []

count = 0
while count<n:
    if s[count]=="o":
        asc.append(count)
        count += c+1
    else:
        count += 1
asc = asc[0:k]

count = n-1
while count>=0:
    if s[count]=="o":
        des.append(count)
        count -= c+1
    else:
        count -= 1
des = des[0:k]
des.reverse()

# print(asc)
# print(des)

for i in range(len(asc)):
    if asc[i]==des[i]:
        print(asc[i]+1)

Buggy submission (verdict: Runtime Error):
import copy

n,k,c = map(int, input().split())
s = input()
S = []
lst = [[] for i in range(n)]
# print(lst)
for i in range(len(s)):
    if s[i]=="o":
        S.append(i)
# print("S:",S)
for i in range(len(S)-1):
    koho = S[i+1:]
    for j in koho:
        if j>S[i]+c:
            lst[S[i]].append(j)
    # lst[S[i]].append(S[i+1:])
# print("lst:",lst)



ans = []
for i in S:
    testlst = copy.deepcopy(lst)
    testlst[i] = []
    for j in range(n):
        if testlst[j]!=[]:
            if  testlst[j][0]==i:
                testlst[j].remove(i)
    # print("i,testlst:",i,testlst)

    count = 1
    if i==S[0]:
        num = S[1]
    else:
        num = S[0]
    while testlst[num]!=[]:
        num = testlst[num][0]
        count += 1
    if count < k:
        ans.append(i+1)

for i in ans:
    print(i)
Problem p02760 (python)

Fixed submission:
A = []
for i in range(3):
    p,q,r = map(int, input().split())
    A.append(p)
    A.append(q)
    A.append(r)
n = int(input())
for i in range(n):
    b = int(input())
    if b in A:
        A[A.index(b)] = 0

if A[0]==A[1]==A[2]==0 or A[3]==A[4]==A[5]==0 or A[6]==A[7]==A[8]==0 or A[0]==A[3]==A[6]==0 or A[1]==A[4]==A[7]==0 or A[2]==A[5]==A[8]==0 or A[0]==A[4]==A[8]==0 or A[2]==A[4]==A[6]==0:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
A = []
for i in range(3):
    p,q,r = map(int, input().split())
    A.append(p)
    A.append(q)
    A.append(r)
n = int(input())
for i in range(n):
    b = int(input())
    if b in A:
        A[A.index(b)] = 0

if A[0]==A[1]==A[2]==0 or A[3]==A[4]==A[5]==0 or A[6]==A[7]==A[9]==0 or A[0]==A[3]==A[6]==0 or A[1]==A[4]==A[7]==0 or A[2]==A[5]==A[8]==0 or A[0]==A[4]==A[8]==0 or A[2]==A[4]==A[6]==0:
    print("Yes")
else:
    print("No")
Problem p02761 (python)

Fixed submission:
n,m = map(int, input().split())
lst = []
for i in range(m):
    s,c = map(int, input().split())
    lst.append((s-1,c))

if n!=1:
    for i in lst:
        if i==(0,0):
            print(-1)
            exit()

# print(lst)
if n==1:
    for i in range(10):
        I = str(i)
        flag = 0
        for j in lst:
            if I[j[0]]!=str(j[1]):
                flag = 1
        if flag == 0:
            print(I)
            exit()
else:
    for i in range(10**(n-1),10**n):
        I = str(i)
        # print(I)
        flag = 0
        for j in lst:
            if I[j[0]]!=str(j[1]):
                flag = 1
        if flag == 0:
            print(I)
            exit()

print(-1)

Buggy submission (verdict: Runtime Error):
n,m = map(int, input().split())

lst = []
for i in range(m):
    s,c = map(int, input().split())
    lst.append((s,c))

for i in range(1,1000):
    flag = 0
    I = str(i)
    if len(I)==n:
        for j in range(len(lst)):
            if I[lst[j][0]-1]!=lst[k][1]:
                flag = 1
        if flag == 0:
            print(I)
print(-1)
Problem p02803 (python)

Fixed submission:
from collections import deque
h,w = map(int, input().split())
maze = [list(input()) for i in range(h)]
emp = []

#迷路と始点を引数に、最も遠い点までの距離を返す
def bfs(maze, sx, sy):
    d = [[-float("inf")] * w for i in range(h)]

    dx = [1, 0, -1, 0]
    dy = [0, 1, 0, -1]

    que = deque([])
    que.append((sy, sx))
    d[sy][sx] = 0

    while que:
        p = que.popleft()
        # if p[0] == gy and p[1] == gx:
        #     break
        for i in range(4):
            nx = p[0] + dx[i]
            ny = p[1] + dy[i]
            if 0 <= nx < h and 0 <= ny < w and maze[nx][ny] != "#" and d[nx][ny] == -float("inf"):
                que.append((nx, ny))
                d[nx][ny] = d[p[0]][p[1]] + 1
    an = 0
    for i in d:
        an = max(an,max(i))
    return an

# 取りうる全ての始点と終点の最短経路の最大値を求める
ans = 0
for i in range(h):
    for j in range(w):
        if maze[i][j]!="#":
            ans = max(ans, bfs(maze, j, i))

print(ans)

Buggy submission (verdict: Runtime Error):
from collections import deque
h,w = map(int, input().split())
maze = [list(input()) for i in range(h)]


def bfs(maze, sx, sy, gy, gx):
    d = [[float("inf")] * w for i in range(h)]

    dx = [1, 0, -1, 0]
    dy = [0, 1, 0, -1]

    que = deque([])
    que.append((sy, sx))
    d[sy][sx] = 0

    while que:
        p = que.popleft()
        if p[0] == gy and p[1] == gx:
            break
        for i in range(4):
            nx = p[0] + dx[i]
            ny = p[1] + dy[i]

            if 0 <= nx < h and 0 <= ny < w and maze[nx][ny] != "#" and d[nx][ny] == float("inf"):
                que.append((nx, ny))
                d[nx][ny] = d[p[0]][p[1]] + 1

    return d[gy][gx]


ans = 0
for i in range(h):
    for j in range(w):
        if maze[i][j]!="#":
            for k in range(i,h):
                for l in range(j,w):
                    if maze[k][l]!="#":
                        ans = max(ans, bfs(maze, j, i, l, k))

print(ans)
Problem p02900 (python)

Fixed submission:
from fractions import gcd
a,b = map(int, input().split())
# ans = 1
count = 2
n=gcd(a,b)

ans = set([1])
while n % 2 == 0:
    ans.add(2)
    n //= 2
f = 3
while f * f <= n:
    if n % f == 0:
        ans.add(f)
        n //= f
    else:
        f += 2
if n != 1:
    ans.add(n)
print(len(ans))

Buggy submission (verdict: Runtime Error):
import math
a,b = map(int, input().split())
ans = 1
count = 2
num = math.gcd(a,b)

if a==1 or b==1:
    print(1)
else:
    while num!=1:
        if num%count==0:
            ans+=1
            while num%count==0:
                num= num/count
            count+=1
        else:
            count+=1
print(ans)

Buggy submission (verdict: Runtime Error):
import math
a,b = map(int, input().split())
ans = 1
count = 2
num = math.gcd(a,b)

if a==1 or b==1:
    print(1)
else:
    while True:
        if num==1:
            print(ans)
            exit(0)
        else:
            if num%count==0:
                ans+=1
                while num%count==0:
                    num= num/count
                count+=1
            else:
                count+=1

Buggy submission (verdict: Runtime Error):
import math
a,b = map(int, input().split())
ans = 1
count = 2
num = math.gcd(a,b)

if a==1 or b==1:
    print(1)
else:
    while True:
        if num==1:
            print(ans)
            exit(0)
        else:
            if num%count==0:
                ans+=1
                while num%count==0:
                    num= num/count
                count+=1
            else:
                count+=1

Buggy submission (verdict: Runtime Error):
import math
import sys
a,b = map(int, input().split())
ans = 1
count = 2
num = math.gcd(a,b)

if a==1 or b==1:
    print(1)
else:
    while True:
        if num==1:
            print(ans)
            sys.exit(0)
        else:
            if num%count==0:
                ans+=1
                while num%count==0:
                    num= num/count
                count+=1
            else:
                count+=1

Buggy submission (verdict: Runtime Error):
import math
import sys
a,b = map(int, input().split())
ans = 1
count = 2
num = math.gcd(a,b)

if a==1 or b==1:
    print(1)
else:
    while True:
        if num==1:
            print(ans)
            sys.exit()
        else:
            if num%count==0:
                ans+=1
                while num%count==0:
                    num= num/count
                count+=1
            else:
                count+=1

Buggy submission (verdict: Runtime Error):
import math
a,b = map(int, input().split())
ans = 1
count = 2
num = math.gcd(a,b)

while True:
    if num==1:
        print(ans)
        exit()
    else:
        if num%count==0:
            ans+=1
            while num%count==0:
                num= num/count
            count+=1
        else:
            count+=1
Problem p03240 (python)

Fixed submission:
N = int(input())
x = [None]*N
y = [None]*N
h = [None]*N

for i in range(N):
    x[i],y[i],h[i] = map(int, input().split())

def height(X,Y,xn,yn,hn):
    return hn+abs(X-xn)+abs(Y-yn)

def check(x,y,h,X,Y,H):
    for n in range(N):
        if h[n]>0:
            if height(X,Y,x[n],y[n],h[n])!=H:
                return False
        elif H-abs(X-x[n])-abs(Y-y[n])>0:
            return False
    return True

for X in range(101):
    for Y in range(101):
        for n in range(N):
            if h[n]>0:
                H = height(X,Y,x[n],y[n],h[n])
                if check(x,y,h,X,Y,H) is True:
                    print(X,Y,H)
                    exit()

Buggy submission (verdict: Runtime Error):
N = int(input())
x = [None]*N
y = [None]*N
h = [None]*N

for i in range(N):
    x[i],y[i],h[i] = map(int, input().split())

def height(X,Y,xn,yn,hn):
    return hn+abs(X-xn)+abs(Y-yn)

def check(x,y,h,X,Y,H):
    for n in range(N):
        if h[n]>0:
            if height(X,Y,x[n],y[n],h[n])!=H:
                return False
        else:
            if H-abs(X-x[n])-abs(Y-y[n])>0:
            return False
    return True

for X in range(101):
    for Y in range(101):
        for n in range(N):
            H = height(X,Y,x[n],y[n],h[n])
            if check(x,y,h,X,Y,H) is True:
                print(X,Y,H)
                exit()
Problem p03282 (python)

Fixed submission:
s = input()
k = int(input())

if all(s[i]=="1" for i in range(min(len(s),k))):
    print(1)
else:
    while s[0]=="1":
        s = s[1:]
    print(s[0])

Buggy submission (verdict: Runtime Error):
s = input()
k = int(input())

if all(s[i]=="1" for i in range(min(len(s),k))):
    print(1)
else:
    while s[0]=="1":
        s.pop(0)
    print(s[0])

Buggy submission (verdict: Runtime Error):
s = input()
k = int(input())

if len(s)>k and all(s[i]=="1" for i in range(k)):
    print(1)
else:
    while s[0]=="1":
        s.pop(0)
    print(s[0])
Problem p03436 (python)

Fixed submission:
from collections import deque
h,w = map(int, input().split())
map = [list(input()) for _ in range(h)]
dis = [[float("inf")]*w for _ in range(h)]
dy = [1,0,-1,0]
dx = [0,1,0,-1]
que = deque([])
que.append((0,0))
dis[0][0]=1
count = 0
for i in range(h):
    for j in range(w):
        if map[i][j]=="#":
            count+=1

while que:
    p = que.popleft()
    if p[0]==h-1 and p[1]==w-1:
        break
    for i in range(4):
        ny = p[0] + dy[i]
        nx = p[1] + dx[i]
        if 0<=ny<h and 0<=nx<w and map[ny][nx]!="#" \
           and dis[ny][nx]==float("inf"):
            que.append((ny,nx))
            dis[ny][nx]=dis[p[0]][p[1]]+1

print(h*w-dis[h-1][w-1]-count if dis[h-1][w-1]!=float("inf") else -1)

Buggy submission (verdict: Runtime Error):
from collections import deque
h,w = map(int, input().split())
map = [list(input()) for _ in range(h)]
dis = [[float("inf")]*w for _ in range(h)]
dy = [1,0,-1,0]
dx = [0,1,0,-1]
que = deque([])
que.append((0,0))
dis[0][0]=1
count = 0

for num in range(h*w):
    p = que.popleft()
    if p[0]==h-1 and p[1]==w-1:
        break
    for i in range(4):
        ny = p[0] + dy[i]
        nx = p[1] + dx[i]
        if 0<=ny<h and 0<=nx<w and map[ny][nx]!="#" \
           and dis[ny][nx]==float("inf"):
            que.append((ny,nx))
            dis[ny][nx]=dis[p[0]][p[1]]+1

for i in range(h):
    for j in range(w):
        if map[i][j]=="#":
            count+=1

print(h*w-dis[h-1][w-1]-count if dis[h-1][w-1]!=float("inf") else -1)
Problem p03828 (python)

Fixed submission:
import math

n = int(input())
mod = 10**9+7

def eratosthenes(n):
    if not isinstance(n, int):
        raise TypeError('n is int type.')
    if n < 2:
        raise ValueError('n is more than 2')
    prime = []
    limit = math.sqrt(n)
    data = [i + 1 for i in range(1, n)]
    while True:
        p = data[0]
        if limit <= p:
            return prime + data
        prime.append(p)
        data = [e for e in data if e % p != 0]

if n==1:
    print(1)
    exit()

era = eratosthenes(n)

dict = {}
for i in range(n):
    num = i+1
    while num!=1:
        for j in era:
            while num%j==0:
                num/=j
                if j in dict:
                    dict[j]+=1
                else:
                    dict[j]=1

ans = 1
for i in dict:
    ans = ans*(dict[i]+1)%mod

print(ans)

Buggy submission (verdict: Runtime Error):
import math

n = int(input())
mod = 10**9+7

def eratosthenes(n):
    if not isinstance(n, int):
        raise TypeError('n is int type.')
    if n < 2:
        raise ValueError('n is more than 2')
    prime = []
    limit = math.sqrt(n)
    data = [i + 1 for i in range(1, n)]
    while True:
        p = data[0]
        if limit <= p:
            return prime + data
        prime.append(p)
        data = [e for e in data if e % p != 0]

era = eratosthenes(n)

dict = {}
for i in range(n):
    num = i+1
    while num!=1:
        for j in era:
            while num%j==0:
                num/=j
                if j in dict:
                    dict[j]+=1
                else:
                    dict[j]=1

ans = 1
for i in dict:
    ans = ans*(dict[i]+1)%mod

print(ans)
Problem p02675 (python)

Fixed submission:
N = input()
if N[-1] == "3":
  print("bon")
elif N[-1] == "0":
  print("pon")
elif N[-1] == "1":
  print("pon")
elif N[-1] == "6":
  print("pon")
elif N[-1] == "8":
  print("pon")
else:
  print("hon")

Buggy submission (verdict: Runtime Error):
N = str(input())
if N[2] == 3:
  print("bon")
elif N[2] == 0 or N[2] == 1 or N[2] == 6 or N[2] == 8:
  print("pon")
else:
  print("hon")
Problem p02755 (python)

Fixed submission:
import math
import sys

A, B = list(map(int, input().split()))
for i in range(1001):
  priceA = math.floor(i*1.08)
  priceB = math.floor(i*1.10)
  taxA = priceA - i 
  taxB = priceB - i 
  if taxA == A and taxB == B:
    print(i)
    sys.exit()
print("-1")

Buggy submission (verdict: Runtime Error):
a,b = map(int, input().split())

for x in range(0,101):
  calc_a = int(x*0.08)
  calc_b = int(x*0.10)
  if calc_a == a and calc_b == b:
    ans = x
    print(ans)
    break
if ans == -1:
  print(ans)
Problem p02767 (python)

Fixed submission:
N = int(input())
X = list(map(int, input().split()))
ans = []
tmp = 0

for i in range(min(X), 1+max(X)):
  for j in range(N):
    tmp += (X[j]-i)**2 
  ans.append(tmp)
  tmp = 0  
print(min(ans))

Buggy submission (verdict: Runtime Error):
N = int(input())
X = list(map(int, input().split()))
tmp = 0
ans = []

for i in range(X[0],1+X[N-1]):
  for j in range(N):
    tmp = tmp + (X[j]-i)**2
  ans.append(tmp)
  tmp = 0
print(min(ans))
Problem p02848 (python)

Fixed submission:
N = int(input())
S = str(input())
ans = []
tmp = 0

for i in range(0,len(S)):
  tmp = N+ord(S[i])
  if tmp >= 91:
    tmp = tmp - 26
  ans.append(chr(tmp))

print("".join(ans))

Buggy submission (verdict: Runtime Error):
S = str(input())
N = int(input())
ans = []
tmp = 0

for i in range(0,len(S)):
  tmp = N+ord(S[i])
  if tmp >= 91:
    tmp = tmp - 26
  ans.append(chr(tmp))

print("".join(ans))
Problem p02988 (python)

Fixed submission:
N = input()
D = map(int, raw_input().split())

cnt=0
lop=0

while lop<N-2:
  if max(D[lop],D[lop+1],D[lop+2])!=D[lop+1] and min(D[lop],D[lop+1],D[lop+2])!=D[lop+1]:
    cnt=cnt+1
  lop=lop+1
print (cnt)

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

cnt=0
lop=0

while lop<N-2:
  if max(D[lop],D[lop+1],D[lop+2])!=D[lop+1] and min(D[lop],D[lop+1],D[lop+2])!=D[lop+1]:
    cnt=cnt+1
  else:
  lop=lop+1
print (cnt)
Problem p03086 (python)

Fixed submission:
S = str(input())

cnt = 0
ans = [0]

for i in range(0, len(S)):
  if S[i] == "A" or S[i] == "C" or S[i] == "G" or S[i] == "T":
    cnt = cnt + 1
    ans.append(cnt)
  else:
    cnt = 0
print(max(ans))

Buggy submission (verdict: Runtime Error):
cnt = []
tmp = 0

b = str(input())
for i in range(0,len(b)):
  if b[i]=="A" or b[i]=="C" or b[i]=="G" or b[i]=="T":
    tmp=tmp+1
  else:
    cnt.append(tmp)
    tmp=0
print(max(cnt))
Problem p03693 (python)

Fixed submission:
r, g, b= list(map(int, input().split()))

if (100*r+10*g+b)%4 == 0:
  print("YES")
else:
  print("NO")

Buggy submission (verdict: Runtime Error):
r, g, b= list(map(int, input().split())
if (r+g+B)%4 == 0:
  print("YES")
else:
  print("NO")
Problem p03827 (python)

Fixed submission:
N = int(input())
S = str(input())
cnt = 0

ans = []
for i in range(0,N):
  if S[i] == "I":
    cnt = cnt+1
  elif S[i] == "D":
    cnt = cnt-1
  ans.append(cnt)

if max(ans) <= 0:
  print("0")
else:
  print(max(ans))

Buggy submission (verdict: Runtime Error):
 = int(input())
S = str(input())
cnt = 0

ans = []
for i in range(0,N):
  if S[i] == "I":
    cnt = cnt+1
  elif S[i] == "D":
    cnt = cnt-1
  ans.append(cnt)

if max(ans) <= 0:
  print("0")
else:
  print(max(ans))
Problem p04012 (python)

Fixed submission:
import sys

w = str(input())
arr = []

for i in range(0,len(w)):
  arr.append(w[i])
arr = sorted(arr)

if len(arr)%2 == 1:
  print("No")
  sys.exit()

for i in range(0,len(w),2):
  if arr[i] != arr[i+1]:
    print("No")
    sys.exit()
print("Yes")

Buggy submission (verdict: Runtime Error):
import sys

w = str(input())
arr = []

for i in range(0,len(w)):
  arr.append(w[i])
arr = sorted(arr)

for i in range(0,len(w),2):
  if arr[i] != arr[i+1]:
    print("No")
    sys.exit()
print("Yes")
Problem p02612 (python)

Fixed submission:
N=int(input())
if N%1000==0:
    print(0)
else:
    print((N//1000+1)*1000-N)

Buggy submission (verdict: Runtime Error):
N=int(input())
return N%1000
Problem p02681 (python)

Fixed submission:
A=[input() for i in range(2)]
S=A[0]
T=A[1]
s=[]
t=[]
for c in S:
    s.append(c)
for c in T:
    t.append(c)

v=1
for i in range(len(s)):
    if not s[i]==t[i]:
        v=0
if v==1:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
A=input().split()
S=A[0]
T=A[1]
s=[]
t=[]
for c in S:
    s.append(c)
for c in T:
    t.append(c)

v=1
for i in range(len(s)):
    if not s[i]==t[i]:
        v=0
if v==1:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
OK=[]
S,T=input().split()
s=[]
t=[]
for c in S:
    s.append(c)
for c in T:
    t.append(c)

v=1
for i in range(len(s)):
    if s[i]!=t[i]:
        v=0
if v==1:
    print("Yes")
else:
    print("No")
Problem p02706 (python)

Fixed submission:
n,m=map(int,input().split())
l=list(map(int,input().split()))
sum=0
for i in range(m):
  sum+=l[i]
if sum>n:
  print(-1)
else:
  print(n-sum)

Buggy submission (verdict: Runtime Error):
S=input().split()
N=S[0]
N=int(N)
del S[0]
M=S[0]
M=int(M)
del S[0]
s=0
for i in range(M):
    s=s+int(S[i])
if s>N:
    print(-1)
else:
    print(N-s)

Buggy submission (verdict: Runtime Error):
S=input().split()
N=S[0]
N=int(N)
del S[0]
M=S[0]
M=int(M)
del S[0]
s=0
for i in range(M):
    s=s+int(S[i])
if s>N:
    print(-1)
else:
    print(N-s)
Problem p03061 (python)

Fixed submission:
from fractions import gcd

n = int(input())
num = list(map(int, input().split(' ')))

def find_max(idx):
    
    prev_gcd = gcd(num[idx[0]], num[idx[1]])
    curr_excluded_num = None

    for i in range(n):
        if i == idx[0] or i == idx[1]:
            continue
        
        curr_gcd = gcd(prev_gcd, num[i])
        if curr_gcd == prev_gcd:
            continue
        else:
            if curr_excluded_num is None:
                curr_excluded_num = num[i]
            else:
                if curr_gcd > gcd(prev_gcd, curr_excluded_num):
                    prev_gcd = curr_gcd
                else:
                    prev_gcd = gcd(prev_gcd, curr_excluded_num)
                    curr_excluded_num = num[i]

    
    return prev_gcd



if n == 2:
    print(max(num[0], num[1]))
elif n == 3:
    a = gcd(num[0], num[1])
    b = gcd(num[0], num[2])
    c = gcd(num[2], num[1])
    print(max(max(a, b), c))

else:
    ans = find_max((0, 1))
    ans = max(find_max((2, 3)), ans)
    print(ans)

Buggy submission (verdict: Runtime Error):
from math import gcd

n = int(input())
num = list(map(int, input().split(' ')))

def find_max(idx):
    
    prev_gcd = gcd(num[idx[0]], num[idx[1]])
    curr_excluded_num = None
    curr_gcd = None

    for i in range(n):
        if i == idx[0] or i == idx[1]:
            continue
        
        curr_gcd = gcd(prev_gcd, num[i])
        if curr_gcd == prev_gcd:
            continue
        else:
            if curr_excluded_num is None:
                curr_excluded_num = num[i]
            else:
                if curr_gcd > gcd(prev_gcd, curr_excluded_num):
                    prev_gcd = curr_gcd
                else:
                    prev_gcd = gcd(prev_gcd, curr_excluded_num)
                    curr_excluded_num = num[i]

    
    return prev_gcd



if n == 2:
    print(max(num[0], num[1]))
elif n == 3:
    a = gcd(num[0], num[1])
    b = gcd(num[0], num[2])
    c = gcd(num[2], num[1])
    print(max(max(a, b), c))

else:
    ans = find_max((0, 1))
    ans = max(find_max((2, 3)), ans)
    print(ans)
Problem p02603 (python)

Fixed submission:
def INT():
    return int(input())

def MI():
    return map(int, input().split())

def LI():
    return list(map(int, input().split()))

N = INT()
A = LI()
ans = 1000

for i in range(1, N):
    tmp = ans
    if A[i] > A[i - 1]:
        purchase = tmp // A[i - 1]
        ans = max(ans, tmp + (A[i] - A[i - 1]) * purchase)
        
print(ans)

Buggy submission (verdict: Runtime Error):
def INT():
    return int(input())

def MI():
    return map(int, input().split())

def LI():
    return list(map(int, input().split()))

N = INT()
A = LI()
ans = 1000
purchase = 0

for i in range(1, N):
    tmp = ans
    
    if A[i] > A[i - 1]:
        for j in range(10);
            if tmp - A[i - 1] < 0:
                break
            tmp -= A[i - 1]
            purchase += 1
        ans = max(ans, tmp + A[i] * purchase)
        purchase = 0

print(ans)
Problem p02646 (python)

Fixed submission:
A, V = map(int, input().split())
B, W = map(int, input().split())
T = int(input())

if A <= B:
    print("YES" if A + V * T >= B + W * T else "NO")
else:
    print("YES" if A - V * T <= B - W * T else "NO")

Buggy submission (verdict: Runtime Error):
A, V = map(int, input().split())
B, W = map(int, input().split())
T = int(input())

if A <= B
    print("YES" if A + V * T >= B + W * T else "NO")
else:
    print("YES" if A - V * T >= B - W * T else "NO")

Buggy submission (verdict: Runtime Error):
A, V = map(int, input().split())
B, W = map(int, input().split())
T = int(input())

ans = (A - B) / (W - V)

print("YES" if ans <= T else "NO")