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

Fixed submission:
# -*- coding: utf-8 -*-
data = input().split(" ");
A = data[0];
B = data[1];
K = data[2];

for lop in range(int(A),int(A)+int(K)):
    if lop > int(B):
        break;
    print(lop);
    fg = lop;
        
if int(B)-int(K)+1 >= int(A):
    if fg+1 < int(B)-int(K)+1:
        fg = int(B)-int(K)+1;
    else:
        fg+=1
    for lop in range(fg,int(B)+1):
        print(lop);

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
A = input();
B = input();
K = input();

for lop in range(int(A),int(A)+int(K)):
    if lop > int(B):
        break;
    print(lop);
    fg = lop;
        
if int(B)-int(K)+1 >= int(A):
    if fg+1 < int(B)-int(K)+1:
        fg = int(B)-int(K)+1;
    else:
        fg+=1
    for lop in range(fg,int(B)):
        print(lop);
    print(B);
Problem p03076 (python)

Fixed submission:
def getInt(): return int(input())
def getIntList(): return [int(x) for x in input().split()]
def zeros(n): return [0]*n
# def zeros(n): return np.zeros(n, dtype=np.longlong)
def zeros2(n, m): return [zeros(m) for i in range(n)] # obsoleted zeros((n, m))で代替

INF = 10**18

class Debug():
    def __init__(self):
        self.debug = True
 
    def off(self):
        self.debug = False
 
    def dmp(self, x, cmt=''):
        if self.debug:
            if cmt != '':
                w = cmt + ': ' + str(x)
            else:
                w = str(x)
            print(w)
        return x

def prob():
    d = Debug()
    d.off()
    N = 5
    dish = zeros(N)
    for i in range(N):
        dish[i] = int(input())
    d.dmp((dish),'dish')
    minDigit1 = 10
    idx = N
    time = 0
    for i in range(N):
        if dish[i] % 10 > 0 and minDigit1 > dish[i] % 10:
            idx = i
            minDigit1 = dish[i] % 10
        time += (dish[i]+9)//10*10
        d.dmp((time),'time')
    d.dmp((time),'time')
    d.dmp((idx),'idx')
    if idx < N:
        time -= (dish[idx]+9)//10*10
        time += dish[idx]
    return time
    

ans = prob()
print(ans)

Buggy submission (verdict: Runtime Error):
def getInt(): return int(input())
def getIntList(): return [int(x) for x in input().split()]
def zeros(n): return [0]*n
# def zeros(n): return np.zeros(n, dtype=np.longlong)
def zeros2(n, m): return [zeros(m) for i in range(n)] # obsoleted zeros((n, m))で代替

INF = 10**18

class Debug():
    def __init__(self):
        self.debug = True
 
    def off(self):
        self.debug = False
 
    def dmp(self, x, cmt=''):
        if self.debug:
            if cmt != '':
                w = cmt + ': ' + str(x)
            else:
                w = str(x)
            print(w)
        return x

def prob():
    d = Debug()
    d.off()
    N = 5
    dish = zeros(N)
    for i in range(N):
        dish[i] = int(input())
    d.dmp((dish),'dish')
    minDigit1 = 10
    idx = N
    time = 0
    for i in range(N):
        if dish[i] % 10 > 0 and minDigit1 > dish[i] % 10:
            idx = i
            minDigit1 = dish[i] % 10
        time += (dish[i]+9)//10*10
        d.dmp((time),'time')
    d.dmp((time),'time')
    d.dmp((idx),'idx')
    time -= (dish[idx]+9)//10*10
    time += dish[idx]
    return time
    

ans = prob()
print(ans)
Problem p03238 (python)

Fixed submission:
# A
N = int(input())
if N==1: print('Hello World')
else:
    A = int(input())
    B = int(input())
    print(A+B)

Buggy submission (verdict: Runtime Error):
# A
N = int(input())
if N==1: print('hello, world')
else:
    A, B = [int(x) for x in input().split()]
    print(A+B)
Problem p03282 (python)

Fixed submission:
# ABC 106
def db(x): 
    global debug
    if debug: print(x)
debug = False
S = input()
K = int(input())
for i in range(len(S)):
    if S[i]!='1': break
if i>=K: print('1')
else:   print(S[i])

Buggy submission (verdict: Runtime Error):
# ABC 106
def db(x): 
    global debug
    if debug: print(x)
debug = False
S = input()
K = int(input())
c5000 = 5*10**15
k = 0
for i in range(100):
    n = ord(S[i])-ord('0')
    if n>1: n *= c5000
    k += n
    db((i,k))
    if k>=K:
          print(S[i])
          break
Problem p03633 (python)

Fixed submission:
# ABC 070
import math
# gcdはエラーになる
def getInt(): return int(input())
def getIntFromRows(n): return [int(input()) for i in range(n)]
def gcd(x, y):
    m = max(x,y)
    n = min(x,y)
    while m%n != 0:
        w = m%n
        m = n
        n = w
    return n
def lcm(x, y): return x*y//gcd(x,y)

N = getInt()
T = getIntFromRows(N)
lc = T[0]
for i in range(1, N):
    lc = lcm(lc,T[i])
print(lc)

Buggy submission (verdict: Runtime Error):
# ABC 070
import math
def getInt(): return int(input())
def getIntFromRows(n): return [int(input()) for i in range(n)]
N1019 = 10**19
N = getInt()
T = getIntFromRows(N)
a = T[0]
lcm = T[0]
for i in range(1, N):
    gcd = math.gcd(a, T[i])
    lcm = a * T[i] // gcd
    a = gcd
print(lcm)
Problem p03856 (python)

Fixed submission:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Fri Feb  8 05:12:38 2019

@author: shinjisu
"""


def db(x):
    global debug
    if debug:
        print(x)


# スタックオーバーフロー
def gen(tstr):
    if len(tstr) <= len(S):
        for w in words:
            yield tstr + w
            for w2 in gen(tstr + w):
                yield w2


# RE
def solve():
    ans = False
    for genstr in gen(''):
        db(genstr)
        if genstr == S:
            ans = True
            break
    return ans


# TLE
def solve2():
    stack = list(words)
    while stack != []:
        str = stack.pop()
        db(('pop', str))
        if len(str) < len(S):
            for w in words:
                stack.append(str+w)
        elif len(str) == len(S) and str == S:
            return True
    return False


# 逆方向から探す
def solve3():
    string = S + ' '
    n = len(string)
    while n > 1:
        for w in words:
            db((string.rfind(w, 0, n),len(w),n))
            if string.rfind(w, 0, n) + len(w) + 1 == n:
                break
        else:
            return False
        db((n,w))
        n -= len(w)
    return True


debug = False
words = ('dream', 'dreamer', 'erase', 'eraser')
S = input()
db(S)
if solve3():
    print('YES')
else:
    print('NO')

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Fri Feb  8 05:12:38 2019

@author: shinjisu
"""


def db(x):
    global debug
    if debug:
        print(x)


def gen(tstr):
    if len(tstr) <= len(S):
        for w in words:
            yield w + tstr
            for w2 in gen(w + tstr):
                yield w2
    else:
        yield tstr


debug = False
words = ('dream', 'dreamer', 'erase', 'eraser')
S = input()
ans = False
db(S)
for genstr in gen(''):
    db(genstr)
    if genstr == S:
        ans = True
        break
if ans:
    print('YES')
else:
    print('NO')
Problem p03963 (python)

Fixed submission:
#B 解2
N, K = [int(x) for x in input().split()]
#print(N, K)#
print(K*(K-1)**(N-1))

Buggy submission (verdict: Runtime Error):
#B
N, K = [int(x) for x in input().split()]
#print(N, K)#
def count(n):
    if n<=0: return 1
    else:  return (K-1)*count(n-1)
print(K*count(N-1))

Buggy submission (verdict: Runtime Error):
#B
N, K = [int(x) for x in input().split()]
#print(N, K)#
def count(n):
    if n<=0: return 1
    else:  return (K-1)*count(n-1)
print(K*count(N-1))
Problem p03106 (python)

Fixed submission:
a, b, k = input().split()
a = int(a)
b = int(b)
k = int(k)
a_list = []
b_list = []
for j in range(a):
    i = j + 1
    if a % i == 0:
        a_list.append(i)
for j in range(b):
    i = j + 1
    if b % i == 0:
        b_list.append(i)

#a_list.extend(b_list)
#co_divisor = list(set(a_list))
a_list = set(a_list)
b_list = set(b_list)
co_divisor = list(a_list & b_list)
co_divisor.sort(reverse=True)
print(co_divisor[k-1])

Buggy submission (verdict: Runtime Error):
a, b, k = input().split()
a = int(a)
b = int(b)
k = int(k)
a_list = []
b_list = []
for i in range(1, a):
    i
    if a % i == 0:
        a_list.append(i)

for i in range(1, b):
    i
    if b % i == 0:
        b_list.append(i)

a_list.extend(b_list)
co_divisor = list(set(a_list))
print(co_divisor[k-1])
Problem p03110 (python)

Fixed submission:
n = int(input())
a = []
a.append([0,0])
for i in range(n):
    in1, in2 = map(str, input().split())
    a.append([float(in1),in2])

ans = 0

for i in range(n):
    j = i + 1
    if a[j][1] == 'BTC':
        ans += a[j][0]*380000
    else :
        ans += a[j][0]
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = []
a.append([0,0])
for i in range(n):
    in1, in2 = map(float, input().split())
    a.append([in1,in2])

ans = 0

for i in range(n):
    if a[i][1] == 'BTC':
        ans += a[i][0]*380000
    else :
        ans += a[i][0]
print(ans)
Problem p03239 (python)

Fixed submission:
N, T = map(int, input().split())
cost = []
time = []
for i in range(N):
    c, t = map(int, input().split())
    if t <= T:
        cost.append(c)
        time.append(t)
if len(time) == 0:
    print("TLE")
else:
    #min_time_index = time.index(min(time))
    #print(cost[min_time_index])
    print(min(cost))

Buggy submission (verdict: Runtime Error):
N, T = map(int, input().split())
cost = []
time = []
for i in range(N):
    c, t = map(int, input().split())
    if t <= T:
        cost.append(c)
        time.append(t)
min_time_index = time.index(min(time))
print(cost[min_time_index])
Problem p03262 (python)

Fixed submission:
def gcd(a,b):   #　ユーグリッドの互除法
    if b == 0:
        return a
    return gcd(b, a % b)

N, X = map(int,input().split())
city = list(map(int,input().split()))
X_diff = [0]*N
for i in range(N):
    X_diff[i] = abs(X-city[i])
    
ans = X_diff[0]
for i in range(1,N):
    ans = gcd(ans,X_diff[i])

print(ans)

Buggy submission (verdict: Runtime Error):
import math

N, X = map(int,input().split())
city = list(map(int,input().split()))
X_diff = [0]*N
for i in range(N):
    X_diff[i] = abs(X-city[i])
    
ans = X_diff[0]
for i in range(1,N):
    ans = gcd(ans,X_diff[i])

print(ans)

Buggy submission (verdict: Runtime Error):
import math

N, X = map(int,input().split())
city = list(map(int,input().split()))
X_diff = [0]*N
for i in range(N):
    X_diff[i] = abs(X-city[i])
    
ans = X_diff[0]
for i in range(1,N):
    ans = math.gcd(ans,X_diff[i])

print(ans)

Buggy submission (verdict: Runtime Error):
import math

def reduce(function, iterable, initializer=None):
    it = iter(iterable)
    if initializer is None:
        value = next(it)
    else:
        value = initializer
    for element in it:
        value = function(value, element)
    return value

N, X = map(int,input().split())
city = list(map(int,input().split()))
X_diff = [0]*N
for i in range(N):
    X_diff[i] = abs(X-city[i])

ans = reduce(math.gcd, X_diff)
print(ans)

Buggy submission (verdict: Runtime Error):
import functools
import math
N, X = map(int,input().split())
city = list(map(int,input().split()))
X_diff = [0]*N
for i in range(N):
    X_diff[i] = abs(X-city[i])

ans = functools.reduce(math.gcd, X_diff)
print(ans)
Problem p03061 (python)

Fixed submission:
from fractions import gcd


n = int(input())
A = list(map(int, input().split()))


gcd_l = [0] * n
gcd_r = [0] * n
for i in range(n):
    if i == 0:
        gcd_l[i] = A[i]
        gcd_r[-i-1] = A[-i-1]
    else:
        gcd_l[i] = gcd(gcd_l[i-1], A[i])
        gcd_r[-i-1] = gcd(gcd_r[-i], A[-i-1])

ans = [0] * n
ans[0] = gcd_r[1]
ans[n-1] = gcd_l[n-2]
for i in range(1, n-1):
    ans[i] = gcd(gcd_l[i-1], gcd_r[i+1])
print(max(ans))

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


gcd_l = [0] * n
gcd_r = [0] * n
for i in range(n):
    if i == 0:
        gcd_l[i] = A[i]
        gcd_r[-i-1] = A[-i-1]
    else:
        gcd_l[i] = gcd(gcd_l[i-1], A[i])
        gcd_r[-i-1] = gcd(gcd_r[-i], A[-i-1])

ans = [0] * n
ans[0] = gcd_r[1]
ans[n-1] = gcd_l[n-2]
for i in range(1, n-1):
    ans[i] = gcd(gcd_l[i-1], gcd_r[i+1])
print(max(ans))
Problem p03078 (python)

Fixed submission:

X, Y, Z, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)

# まずA, Bで総当たり、上位K個をスタック
tmp = [a+b for a in A for b in B]
tmp.sort(reverse=True)
tmp = tmp[:K]

# 残りのc個に対しても総当たり
ans = [t+c for t in tmp for c in C]
ans.sort(reverse=True)
ans = ans[:K]
for s in ans:
    print(s)

Buggy submission (verdict: Runtime Error):
def conKey(i, j, k):
    return str(i)+'-'+str(j)+'-'+str(k)


def getKey(s):
    return map(int, s.split('-'))


import heapq
X, Y, Z, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)

h = []
stack = set([])
ans = []
i, j, k = 0, 0, 0
heapq.heappush(h, (-(A[i]+B[j]+C[k]), conKey(i, j, k)))
stack.add(conKey(i, j, k))
for _ in range(K):
    tmp, key = heapq.heappop(h)
    print(-tmp)
    i, j, k = getKey(key)
    key_0 = [i, j, k]

    for m in range(3):
        key_tmp = key_0.copy()
        key_tmp[m] += 1
        tmp_sum = A[key_tmp[0]] + B[key_tmp[1]] + C[key_tmp[2]]

        str_key = conKey(*key_tmp)
        if str_key not in stack:
            heapq.heappush(h, (-tmp_sum, str_key))
            stack.add(str_key)
Problem p03081 (python)

Fixed submission:
N, Q = map(int, input().split())
s = str(input())
coms = [list(map(str, input().split())) for _ in range(Q)]


def isOK(A, index, coms, c):
    # シミュレーションを行う
    for com in coms:
        if com[0] == A[index]:
            if com[1] == 'R':
                index += 1
                if index == len(A):
                    return c == 'R'
            elif com[1] == 'L':
                index -= 1
                if index == -1:
                    return c == 'L'
    return False


def lower_bound(A, coms):
    ng = -1
    ok = len(A)

    while(abs(ok-ng) > 1):
        mid = (ok + ng) // 2

        if isOK(A, mid, coms, 'R'):
            ok = mid
        else:
            ng = mid
    return ok


def upper_bound(A, coms):
    ng = len(A)
    ok = -1

    while(abs(ok-ng) > 1):
        mid = (ok + ng) // 2

        if isOK(A, mid, coms, 'L'):
            ok = mid
        else:
            ng = mid
    return ok


lower = lower_bound(s, coms)
upper = upper_bound(s, coms)
print(lower-upper-1)

Buggy submission (verdict: Runtime Error):
N, Q = map(int, input().split())
s = str(input())
s_inv = s[::-1]
coms = [list(map(str, input().split())) for _ in range(Q)]
# 後ろから見る
coms = coms[::-1]
i = 0
j = 0
for com in coms:
    # Rに対する処理
    if com[1] == 'R' and com[0] == s_inv[i]:
        if i <= N-1:
            i = i+1
    # Lに対する処理
    elif com[1] == 'L' and com[0] == s[j]:
        if j <= N-1:
            j = j+1
print(max(N-i-j, 0))

Buggy submission (verdict: Runtime Error):
N, Q = map(int, input().split())
s = str(input())
s_inv = s[::-1]
coms = [list(map(str, input().split())) for _ in range(Q)]
# 後ろから見る
coms = coms[::-1]
i = 0
j = 0
for com in coms:
    # Rに対する処理
    if com[1] == 'R' and com[0] == s_inv[i]:
        i += 1
    # Lに対する処理
    elif com[1] == 'L' and com[0] == s[j]:
        j += 1
print(N-i-j)
Problem p03082 (python)

Fixed submission:
import math
import sys

sys.setrecursionlimit(100000000)
# 動的計画法とmemo化で解く。
N, X = map(int, input().split())
S = list(map(int, input().split()))
S.sort(reverse=True)


def memoize(f):  # メモ化関数
    table = [{} for _ in range(N+1)]

    def func(i, key):
        if key not in table[i]:
            table[i][key] = f(i, key)
        return table[i][key]
    return func


@memoize
def dfs(i, x):
    if i == N:
        return x
    else:
        return dfs(i+1, x % S[i]) + dfs(i+1, x) * (N-i-1)


print(dfs(0, X) % (10**9+7))

Buggy submission (verdict: Runtime Error):

import math
import sys

sys.setrecursionlimit(100000000)
# 動的計画法とmemo化で解く。
N, X = map(int, input().split())
S = list(map(int, input().split()))
S.sort(reverse=True)


def memoize(f):  # メモ化関数
    table = [{} for _ in range(N+1)]

    def func(i, key):
        if key not in table[i]:
            table[i][key] = f(i, key)
        return table[i][key]
    return func


@memoize
def dfs(i, x):
    if i == N:
        return x
    else:
        p = 1/(N-i)
        return dfs(i+1, x % S[i]) * p + dfs(i+1, x) * (1-p)


print(int((dfs(0, X) * math.factorial(N))) % (10**9+7))

Buggy submission (verdict: Runtime Error):
import math
import sys

sys.setrecursionlimit(100000000)
# 動的計画法とmemo化で解く。
N, X = map(int, input().split())
S = list(map(int, input().split()))
S.sort(reverse=True)


def memoize(f):  # メモ化関数
    table = [{} for _ in range(N+1)]

    def func(i, key):
        if key not in table[i]:
            table[i][key] = f(i, key)
        return table[i][key]
    return func


@memoize
def dfs(i, x):
    if i == N:
        return x
    else:
        p = 1/(N-i)
        return dfs(i+1, x % S[i]) * p + dfs(i+1, x) * (1-p)


print((int(dfs(0, X) * math.factorial(N))) % (10**9+7))

Buggy submission (verdict: Runtime Error):
import math
# 動的計画法とmemo化で解く。
N, X = map(int, input().split())
S = list(map(int, input().split()))
S.sort(reverse=True)


def memoize(f):  # メモ化関数
    table = [{} for _ in range(N+1)]

    def func(i, key):
        if key not in table[i]:
            table[i][key] = f(i, key)
        return table[i][key]
    return func


@memoize
def dfs(i, x):
    if i == N:
        return x
    else:
        p = 1/(N-i)
        return dfs(i+1, x % S[i]) * p + dfs(i+1, x) * (1-p)


print((int(dfs(0, X) * math.factorial(N))) % (10**9+7))
Problem p03262 (python)

Fixed submission:
import fractions
from functools import reduce
N, o = list(map(int, input().split()))
X = list(map(int, input().split()))
X = sorted(X)
X = [abs(x-o) for x in X]
# 最大公約数が答え
print(reduce(fractions.gcd, X))

Buggy submission (verdict: Runtime Error):
import math
from functools import reduce
N, o = list(map(int, input().split()))
X = list(map(int, input().split()))
X = sorted(X)
X = [abs(x-o) for x in X]
# 最大公約数が答え
print(reduce(math.gcd, X))
Problem p03266 (python)

Fixed submission:
N, K = list(map(int, input().split()))
if K % 2 == 0:
    num = (N//K)**3 + (N//int(K/2)-N//K)**3
else:
    num = (N//K)**3

print(num)

Buggy submission (verdict: Runtime Error):
from scipy.special import comb
N, K = list(map(int, input().split()))
if K % 2 == 0:
    num = (N//K)**3 + (N//int(K/2)-N//K)**3
else:
    k = int(K)
    num = (N//k)**3

print(num)
Problem p03361 (python)

Fixed submission:
H, W = map(int, input().split())
mat = [input() for i in range(H)]
mat_t = [''.join(x) for x in zip(*mat)]
def check(mat, t):
    stack = set()
    for i, string in enumerate(mat):
        string = '.' + string + '.'
        for j in range(len(string)):
            if j+3<=len(string):
                if string[j:j+3] == '.#.':
                    if t==False:
                        stack.add((i, j))
                    else:
                        stack.add((j, i))
    return stack

stack1 = check(mat, False)
stack2 = check(mat_t, True)
if stack1 & stack2:
    print('No')
else:
    print('Yes')

Buggy submission (verdict: Runtime Error):
H, W = map(int, input().split())
mat = [input() for i in range(W)]
mat_t = [''.join(x) for x in zip(*mat)]
def check(mat, t):
    stack = set()
    for i, string in enumerate(mat):
        string = '.' + string + '.'
        for j in range(len(string)):
            if j+3<=len(string):
                if string[j:j+3] == '.#.':
                    if t==False:
                        stack.add((i, j))
                    else:
                        stack.add((j, i))
    return stack

stack1 = check(mat, False)
stack2 = check(mat_t, True)
if stack1 & stack2:
    print('No')
else:
    print('Yes')

Buggy submission (verdict: Runtime Error):
%%test_input https://atcoder.jp/contests/abc096/tasks/abc096_c
# 巡回セールスマン問題？
H, W = map(int, input().split())
mat = [input() for i in range(W)]
mat_t = [''.join(x) for x in zip(*mat)]
def check(mat, t):
    stack = set()
    for i, string in enumerate(mat):
        string = '.' + string + '.'
        for j in range(len(string)):
            if j+3<=len(string):
                if string[j:j+3] == '.#.':
                    if t==False:
                        stack.add((i, j))
                    else:
                        stack.add((j, i))
    return stack

stack1 = check(mat, False)
stack2 = check(mat_t, True)
if stack1 & stack2:
    print('No')
else:
    print('Yes')
Problem p03599 (python)

Fixed submission:
A, B, C, D, E, F = map(int, input().split())
waters = set()
sugars = set()
for i in range(F//(A*100)+1):
    for j in range(F//(B*100)+1):
        if i!=0 or j!=0:
            if A*i*100 +B*j*100 <= F:
                waters.add(100*A*i+100*B*j)
for i in range(F//(C)+1):
    for j in range(F//(D)+1):
        if C*i +D*j <= F:
            sugars.add(C*i+D*j)

max_ratio = 0
for water in waters:
    for sugar in sugars:
        ratio =  sugar/(water+sugar)
        if water+sugar<=F and sugar<=E*(water//100):
            if ratio >= max_ratio:
                ans = (water+sugar, sugar)
                max_ratio = ratio
print(*ans)

Buggy submission (verdict: Runtime Error):
A, B, C, D, E, F = map(int, input().split())
waters = set()
sugars = set()
for i in range(F//(A*100)+1):
    for j in range(F//(B*100)+1):
        if i!=0 or j!=0:
            if A*i +B*j <= F:
                waters.add(100*A*i+100*B*j)
for i in range(F//(C)+1):
    for j in range(F//(D)+1):
        if C*i +D*j <= F:
            sugars.add(C*i+D*j)

max_ratio = 0
for water in waters:
    for sugar in sugars:
        ratio =  sugar/(water+sugar)
        if water+sugar<=F and sugar<=E*(water//100):
            if ratio > max_ratio:
                ans = (water+sugar, sugar)
                max_ratio = ratio
print(*ans)
Problem p03625 (python)

Fixed submission:
import collections
n = int(input())
A = list(map(int, input().split()))
# 2本以上ある棒, 4本以上を選び出してsort, 大きいものから選ぶ
A = sorted(A)
c = collections.Counter(A)
c_2 = sorted(c.items(), key=lambda x:x[0], reverse=True)
count = 0
for i in range(n):
    if c_2[i][1] >=4 and count==0:
        ans = c_2[i][0] **2
        count+=2
        break
    elif c_2[i][1]>=2:
        if count==0:
            ans = c_2[i][0]
            count+=1
        elif count==1:
            ans *= c_2[i][0]
            count+=1
            break
if count!=2:
    print(0)
else:
    print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
A = list(map(int, input().split()))
# 2本以上ある棒, 4本以上を選び出してsort, 大きいものから選ぶ
A = sorted(A)
c = collections.Counter(A)
c_2 = sorted(c.items(), key=lambda x:x[0], reverse=True)
count = 0
for i in range(n):
    if c_2[i][1] >=4 and count==0:
        ans = c_2[i][0] **2
        count+=2
        break
    elif c_2[i][1]>=2:
        if count==0:
            ans = c_2[i][0]
            count+=1
        elif count==1:
            ans *= c_2[i][0]
            count+=1
            break
if count!=2:
    print(0)
else:
    print(ans)