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

Fixed submission:
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
c = Counter(a)
a,b,c = c[1],c[2],c[3]
DP = [[[0]*(n+2) for i in range(n+2)] for j in range(n+2)]

for i in range(c+1):
    for j in range(n-a-i+1):
        for k in range(n-i-j+1):
            if i+j+k:
                DP[i][j][k] = (i*DP[i-1][j+1][k] + j*DP[i][j-1][k+1] + k*DP[i][j][k-1] + n)/(i+j+k)
print(DP[c][b][a])

Buggy submission (verdict: Runtime Error):
from functools import lru_cache

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

one = a.count(1)
two = a.count(2)
three = a.count(3)

@lru_cache(n**3)
def dfs(one,two,three):
    if one<0 or two<0 or three<0:
        return 0
    s = one+two+three
    if s == 0:
        return 0
    zero = n-s
    tmp = (one*dfs(one-1,two,three) + two*dfs(one+1, two-1, three) + three*dfs(one,two+1,three-1) + n)/(n - zero)
    return tmp

ans = dfs(one,two,three)
print(ans)

Buggy submission (verdict: Runtime Error):
from functools import lru_cache

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

one = a.count(1)
two = a.count(2)
three = a.count(3)

@lru_cache(n**3)
def dfs(one,two,three):
    if one<0 or two<0 or three<0:
        return 0
    s = one+two+three
    if s == 0:
        return 0
    zero = n-s
    tmp = (one*dfs(one-1,two,three) + two*dfs(one+1, two-1, three) + three*dfs(one,two+1,three-1) + n)/(n - zero)
    return tmp

ans = dfs(one,two,three)
print(ans)
Problem p03171 (python)

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

dp = [[0]*(n+1) for i in range(n+1)]
for l in range(1,n+1):
    for i in range(n+1-l):
        j = i+l
        if (n-l)%2 == 0:
            dp[i][j] = max(dp[i+1][j]+a[i], dp[i][j-1]+a[j-1])
        else:
            dp[i][j] = min(dp[i+1][j]-a[i], dp[i][j-1]-a[j-1])
print(dp[0][-1])

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

dp = [[-1]*(n+1) for i in range(n)]
for i in range(n):
    dp[i][i] = 0

def rec(i=0, j=n):
    if i == j:
        return 0
    if dp[i][j] != -1:
        return dp[i][j]
    # 太郎
    if (n - (j-i))%2==0:
        dp[i][j] = max(a[i] + rec(i+1,j), a[j-1] +rec(i,j-1))
    else:
        dp[i][j] = min(-a[i] + rec(i+1,j), -a[j-1] +rec(i,j-1))
    return dp[i][j]
print(rec())
Problem p03178 (python)

Fixed submission:
mod = 10**9 + 7

K = list(map(int, list(input())))
D = int(input())
keta = len(K)

dp = [[[0]*D for i in range(2)] for j in range(keta+1)]
dp[0][1][0] = 1

from itertools import product
for i, j, k in product(range(keta), range(2), range(D)):
    max_n = K[i] if j else 9
    for l in range(max_n+1):
        dp[i+1][j and l == max_n][(k+l)%D] += dp[i][j][k]
        dp[i+1][j and l == max_n][(k+l)%D] %= mod

ans = 0
for i in range(2):
    ans += dp[-1][i][0]
    ans %= mod
print(max(0, (ans - 1)%mod))

Buggy submission (verdict: Runtime Error):
mod = 10**9 + 7
N_str = input()
D = int(input())

max_k = len(N_str)
dp = [[[-1]*D for i in range(2)] for j in range(max_k) ]

def rec(k=0, tight=True, mod_sum=0):
    if k == max_k:
        return int(mod_sum==0)
    if dp[k][tight][mod_sum] >= 0:
        return dp[k][tight][mod_sum]
    top = 9 if not tight else int(N_str[k])
    res = 0
    for i in range(top+1):
        res += rec(k+1, tight and i==top, (mod_sum+i) % D)
        res %= mod
    dp[k][tight][mod_sum] = res
    return res

print(rec()-1)

Buggy submission (verdict: Runtime Error):
mod = 10**9 + 7
N_str = input()
D = int(input())

max_k = len(N_str)
dp = [[[-1]*D for i in range(2)] for j in range(max_k) ]

def rec(k=0, tight=True, mod_sum=0):
    if k == max_k:
        return int(mod_sum==0)
    if dp[k][tight][mod_sum] >= 0:
        return dp[k][tight][mod_sum]
	top = 9 if not tight else int(N_str[k])
    res = 0
    for i in range(top+1):
        res += rec(k+1, tight and i==top, (mod_sum+i) % D)
        res %= mod
    dp[k][tight][mod_sum] = res
    return res

print(rec()-1)
Problem p03216 (python)

Fixed submission:
# コピペ https://atcoder.jp/contests/dwacon5th-prelims/submissions/7670569
# 自分の https://atcoder.jp/contests/dwacon5th-prelims/submissions/7822126
# とほぼ変わらないのに自分のものはTLEするので検証
n=int(input())
s=input()
q=int(input())
for i in list(map(int,input().split())):
    a=0
    v=[0,0,0]
    for j in range(n):
        if s[j]=="D":
            v[0]+=1
        elif s[j]=="M":
            v[1]+=1
            v[2]+=v[0]
        if j>=i:
            if s[j-i]=="D":
                v[0]-=1
                v[2]-=v[1]
            elif s[j-i]=="M":
                v[1]-=1
        if s[j]=="C":
            a+=v[2]
    print(a)

Buggy submission (verdict: Runtime Error):
n = int(input())
s = input()
q = int(input())
k = list(map(int, input().split()))
for ki in k:
    ans = 0
    DMC = [0]*3
    for i in range(n):
        if s[i] == "D":
            DMC[0] += 1
        elif s[i] == "M":
            DMC[1] += 1
            DMC[2] += DMC[0]
        if i >= ki:
            j = i-ki
            if s[j] == "D":
                DMC[0] -= 1
                DMC[2] -= DMC[1]
            elif s[j] == "M":
                DMC[1] -= 1
        if c == "C":
            ans += DMC[2]
    print(ans)
Problem p03230 (python)

Fixed submission:
from math import sqrt
n = int(input())
a = 1+8*n
b = int(sqrt(a))
if b**2 != a or b%2==0:
    print("No")
    exit()
else:
    k = (1 + b)//2
    s = [[] for i in range(k)]
    cur = 1
    for i in range(k):
        for j in range(k-i-1):
            s[i].append(cur)
            s[i+j+1].append(cur)
            cur += 1
    print("Yes")
    print(k)
    for i in range(k):
        res = "{} ".format(len(s[i])) + " ".join(map(str, s[i]))
        print(res)

Buggy submission (verdict: Runtime Error):
from math import sqrt
n = int(input())
a = 1+8*n
b = int(sqrt(a))
if b**2 != a or b%2==0:
    print("No")
    exit()
else:
    print(c)
k = (1 + b)//2
Problem p03262 (python)

Fixed submission:
import math
import numpy as np
def yakusu(num):
    top = []
    bot = []
    for i in range(int(math.sqrt(num))):
        k = i+1
        if num%k == 0:
            top.append(num//k)
            bot.append(k)
    return top + bot[::-1]

n, X = map(int, input().split())
x = list(map(int, input().split()))
x.append(X)
x.sort()
start = x[0]
x = np.array(x[1:])
x -= start
# print(x)

for ans_pred in yakusu(x[0]):
    if ans_pred == 1:
        break
    flag = True
    for i in x:
        if i % ans_pred != 0:
            flag= False
            break
    if flag:
        break

print(ans_pred)

Buggy submission (verdict: Runtime Error):
import math

n, x = list(map(int, input().split()))
xi = list(map(int, input().split()))

ans = None
for i in xi:
    distance = abs(i-x)
    if ans is None:
        ans = distance
    else:
        ans = math.gcd(ans, distance)
print(ans)

Buggy submission (verdict: Runtime Error):
import math

n, X = list(map(int, input().split()))
x = list(map(int, input().split()))

ans = None
for ind, i in enumerate(x):
    x[ind] = abs(i - X)
    if ans is None:
        ans = x[ind]
    else:
        ans = math.gcd(ans, x[ind])
print(ans)
Problem p03284 (python)

Fixed submission:
n,k = map(int, input().split())
ans = 1 if n%k else 0
print(ans)

Buggy submission (verdict: Runtime Error):
n,k = map(int, input().split())
ans = [0,1][n%k]
print(ans)
Problem p03310 (python)

Fixed submission:
from itertools import accumulate
from bisect import bisect_left

n = int(input())
a = list(map(int, input().split()))
s = list(accumulate(a))

ans = float("inf")

for j in range(2,n-1):
    i_list = []
    i_left = bisect_left(s, s[j-1]//2)-1
    if i_left != -1:
        i_list.append([s[i_left], s[j-1]-s[i_left]])
    if i_left != j-2:
        i_list.append([s[i_left+1], s[j-1]-s[i_left+1]])

    k_list = []
    k_left = bisect_left(s, s[j-1]+(s[-1]-s[j-1])//2)-1
    if k_left != j-1:
        k_list.append([s[k_left] - s[j-1], s[-1]-s[k_left]])
    if k_left != n-2:
        k_list.append([s[k_left+1] - s[j-1], s[-1]-s[k_left+1]])
    for i in i_list:
        for k in k_list:
            tmp = max(i+k)-min(i+k)
            ans = min(ans, tmp)
print(ans)

Buggy submission (verdict: Runtime Error):
from itertools import accumulate
from bisect import bisect_left

n = int(input())
a = list(map(int, input().split()))
s = list(accumulate(a))

ans = float("inf")

for j in range(2,n-1):
    i_list = []
    i_left = bisect_left(s, s[j-1]//2)-1
    if i_left != -1:
        i_list.append([s[i_left], s[j-1]-s[i_left]])
    if i_left != j-2:
        i_list.append([s[i_left+1], s[j-1]-s[i_left+1]])

    k_list = []
    k_left = bisect_left(s, s[j-1]+(s[-1]-s[j-1])//2)-1
    if k_left != j-1:
        k_list.append([s[k_left] - s[j-1], s[-1]-s[k_left]])
    if k_left != n-2:
        k_list.append([s[k_left+1] - s[j-1], s[-1]-s[k_left+1]])
    for i in i_list:
        for k in k_list:
            tmp = max(*i,*k)-min(*i, *k)
            ans = min(ans, tmp)

print(ans)
Problem p03394 (python)

Fixed submission:
n = int(input())
if n == 3:
    ans = [2, 5, 63]
elif n == 4:
    ans = [2, 5, 20, 63]
elif n == 6:
    ans = [2, 4, 8, 10, 3, 9]
else:
    even = odd = None
    for i in range(1, 5001):
        a = n-3*i
        if a % 2 == 0 and 0 < a <= 5000:
            even = 3*i
            odd = a
            break
    if n == 19999:
        even = 14999
        odd = 5000
    assert(even+odd == n)
    assert(0 < even <= 15000)
    assert(0 < odd <= 5000)
    evens = [i for i in range(1, 30001) if i%2 == 0]
    odds = [i for i in range(1, 30001) if i%3 == 0 and i%2 == 1]
    ans = evens[:even] + odds[:odd]
print(*ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
if n == 3:
    ans = [2, 5, 63]
elif n == 4:
    ans = [2, 5, 20, 63]
else:
    even = odd = None
    for i in range(1, 5001):
        a = n-3*i
        if a % 2 == 0 and 0 < a//2 <= 2500:
            even = 3*i
            odd = a
            break
    assert(even+odd == n)
    assert(0 < even <= 15000)
    assert(0 < odd <= 5000)
    evens = [i for i in range(1, 30001) if i%2 == 0]
    odds = [i for i in range(1, 30001) if i%3 == 0 and i%2 == 1]
    ans = evens[:even] + odds[:odd]
print(*ans)
Problem p03412 (python)

Fixed submission:
# 写経
# https://atcoder.jp/contests/arc092/submissions/5244389

from bisect import bisect_left

INF = float('inf')

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

def calc_bit(k):
    # これ以上の桁は不要
    mod = 1 << (k + 1)
    amod = [a & (mod - 1) for a in A]
    bmod = [b & (mod - 1) for b in B]
    amod.sort()
    bmod.sort()
    ret = 0

    # bmod + amod のうち k ビット目が 1 となる数
    # => (1 << k) 以上 (2 << k) 未満または (3 << k) 以上 (4 << k) 未満
    # しゃくとる
    b01 = bisect_left(bmod, (1 << k) - amod[0])
    b10 = bisect_left(bmod, (2 << k) - amod[0])
    b11 = bisect_left(bmod, (3 << k) - amod[0])
    for a in range(len(amod)):
        while b01 - 1 >= 0 and bmod[b01 - 1] >= (1 << k) - amod[a]:
            b01 -= 1
        while b10 - 1 >= 0 and bmod[b10 - 1] >= (2 << k) - amod[a]:
            b10 -= 1
        while b11 - 1 >= 0 and bmod[b11 - 1] >= (3 << k) - amod[a]:
            b11 -= 1
        # (1 << k) 以上 (2 << k) 未満
        ret += b10 - b01
        # (3 << k) 以上 (4 << k) 未満
        ret += N - b11

    return ret % 2


ans = 0
for i in range(30):
    ans += calc_bit(i) * (1<<i)
print(ans)

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

m = 30
d = [1<<i for i in range(m)]

c = [[] for i in range(m)]
for bi in b:
    for i in range(m):
        c[i].append(bi&(d[i+1]-1))
for i in range(m):
    c[i].sort()

from bisect import bisect_left

keta = [0]*m
for ai in a:
    for i in range(m):
        aj = ai&(d[i+1]-1)
        one1 = bisect_left(c[i], d[i+1]-aj) - bisect_left(c[i],d[i]-aj)
        one2 = n - bisect_left(c[i], d[i+1]+d[i]-aj)
        keta[i] += one1+one2

ans = 0
for i in range(m):
    if keta[i]%2:
        ans += 1<<i

print(ans)
Problem p03436 (python)

Fixed submission:
from collections import deque
h, w = map(int, input().split())
grid = [[c == "." for c in input()] for i in range(h)]
q = deque()
q.append((0,0,1))
visited = set()
min_dist = 0
while q:
    y, x, d = q.popleft()
    # 訪問済み、黒マスならスキップ
    if (y,x) in visited or not grid[y][x]:
        continue
    visited.add((y,x))
    # 終了条件
    if y == h-1 and x == w-1:
        min_dist = d
        break

    for dy, dx in [[-1,0],[1,0],[0,1],[0,-1]]:
        yn = y + dy
        xn = x + dx
        if 0<=yn<h and 0<=xn<w:
            q.append((yn, xn, d+1))
if min_dist:
    white = sum(sum(i) for i in grid)
    #print(white, min_dist)
    print(white - min_dist)
else:
    print(-1)

Buggy submission (verdict: Runtime Error):
h, w = map(int, input().split())
grid = [[c == "." for c in input()] for i in range(h)]
if not (grid[0][0] and grid[-1][-1]):
    print(-1)
else:
    print(grid[1000000])
Problem p03482 (python)

Fixed submission:
# 無限回試行できる時、Kの最小値を最大化する問題
s = input()
now = s[0]
cnt = 1
use = []
for i in range(1,len(s)):
    if now == s[i]:
        cnt += 1
    else:
        use.append(cnt)
        cnt = 1
        now = s[i]
use.append(cnt)

min_prob = len(s)
sum_s = sum(use)
def ketsugou(l):
    global min_prob
    global sum_s
    #一番小さいやつをくっつけていく
    m = l.index(min(l))
    if m == 0 or m == len(l) - 1:
        s1 = l[m]
        s2 = sum_s - l[m]
        min_prob = min(min_prob, max(s1, s2))
        if m == 0:
            l = l[1:]
            l[0] += s1
        else:
            l.pop()
            l[-1] += s1
    else:
        s1 = sum(l[:m])
        s2 = s1 + l[m]
        s3 = sum_s - s1
        s4 = sum_s - s2
        min_prob = min(min_prob, max(s1, s2,s3,s4))
        if l[m - 1] < l[m + 1]:
            l[m - 1] += l[m]
        else:
            l[m + 1] += l[m]
        l.pop(m)
#while(len(use) > 1):
#    ketsugou(use)
sum_ss = 0
for i in range(len(use)):
    sum_ss += use[i]
    min_prob = min(min_prob, max(sum_s - sum_ss, sum_ss))

print(min_prob)

Buggy submission (verdict: Runtime Error):
# 無限回試行できる時、Kの最小値を最大化する問題
s = input()
now = s[0]
cnt = 1
use = []
for i in range(1,len(s)):
    if now == s[i]:
        cnt += 1
    else:
        use.append(cnt)
        cnt = 1
        now = s[i]
use.append(cnt)

min_prob = len(s)
def ketsugou(l):
    global min_prob
    #一番小さいやつをくっつけていく
    m = l.index(min(l))
    if m == 0 or m == len(l) - 1:
        s1 = l[m]
        s2 = sum(l) - l[m]
        min_prob = min(min_prob, max(s1, s2))
        if m == 0:
            l.pop(0)
            l[0] += s1
        else:
            l.pop()
            l[-1] += s1
    else:
        s1 = l[:m + 1]
        s2 = l[:m]
        s3 = l[m:]
        s4 = l[m+1:]
        min_prob = min(min_prob, max(s1, s2,s3,s4))
        if l[m - 1] < l[m + 1]:
            l[m - 1] += l[m]
        else:
            l[m + 1] += l[m]
        l.pop(m)
while(len(use) > 1):
    ketsugou(use)
print(min_prob)
Problem p03503 (python)

Fixed submission:
import itertools
n = int(input())
f = []
for i in range(n):
    f.append(list(map(int, input().split())))
p = []
for i in range(n):
    p.append(list(map(int, input().split())))

a = [i for i in range(10)]
combi = []
for i in range(10):
    combi.extend(list(itertools.combinations(a,i+ 1)))
#print(combi)

ans =  - float("inf")
for i in combi:
    #print(i)
    cnt = [0]*n
    for j in i:
        for k in range(n):
            cnt[k] += f[k][j]
    profit = sum([p[k][cnt[k]] for k in range(n)])
    ans = max(ans, profit)
print(ans)

Buggy submission (verdict: Runtime Error):
import itertools
n = int(input())
f = []
for i in range(n):
    f.append(list(map(int, input().split())))
p = []
for i in range(n):
    p.append(list(map(int, input().split())))

a = [i for i in range(10)]
combi = []
for i in range(10):
    combi.extend(list(itertools.combinations(a,i+ 1)))
#print(combi)

ans =  - float("inf")
for i in combi:
    #print(i)
    cnt = [0]*10
    for j in i:
        for k in range(n):
            cnt[k] += f[k][j]
    profit = sum([p[k][cnt[k]] for k in range(n)])
    ans = max(ans, profit)
print(ans)
Problem p03557 (python)

Fixed submission:
import bisect

#動的計画法だった
N = int(input())
ue = (list(map(int, input().split())))
mid = (list(map(int, input().split())))
bot = (list(map(int, input().split())))
ue.sort()
mid.sort()
bot.sort()

ans = 0
for i in mid:
    ans += bisect.bisect_left(ue, i) * (len(bot) - bisect.bisect_right(bot, i))
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
ue = list(set(list(map(int, input().split()))))
mid = list(set(list(map(int, input().split()))))
bot = list(set(list(map(int, input().split()))))
ue.sort()
mid.sort()
bot.sort()

#高速化できるのがキャッシュしか無い

ans = 0
pos_j = 0
for i in ue:
    flag = 0
    while(mid[pos_j] <= i):
        pos_j += 1
        if pos_j >= len(mid):
            flag = 1
            break
    if flag == 1:
        break

    pos_k = 0
    for j in range(pos_j, len(mid)):
        flag_ = 0
        while(bot[pos_k] <= mid[j]):
            pos_k += 1
            if pos_k >= len(bot):
                flag_ = 1
        if flag_ == 1:
            break
        ans += len(bot) - pos_k

    if flag_ == 1:
        break
    
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
ue = list(set(list(map(int, input().split()))))
mid = list(set(list(map(int, input().split()))))
bot = list(set(list(map(int, input().split()))))
ue.sort()
mid.sort()
bot.sort()

#高速化できるのがキャッシュしか無い

ans = 0
pos_j = 0
for i in ue:
    flag = 0
    while(mid[pos_j] <= i):
        pos_j += 1
        if pos_j >= len(mid):
            flag = 1
            break
    if flag == 1:
        break

    pos_k = 0
    for j in range(pos_j, len(mid)):
        flag_ = 0
        while(bot[pos_k] <= mid[j]):
            pos_k += 1
            if pos_k >= len(bot):
                flag_ = 1
        if flag_ == 1:
            break
        ans += len(bot) - pos_k
print(ans)
Problem p03600 (python)

Fixed submission:
n = int(input())
a = [list(map(int, input().split())) for i in range(n)]
b = [[1]*n for i in range(n)]

for i in range(n):
    for j in range(n):
        for k in range(n):
            if a[i][k] + a[k][j] < a[i][j]:
                print(-1)
                exit()
            elif a[i][k] + a[k][j] == a[i][j] and i!=k!=j:
                b[i][j] = 0

ans = 0
for i in range(n):
    for j in range(n):
        if b[i][j]:
            ans += a[i][j]
print(ans//2)

Buggy submission (verdict: Runtime Error):
for k in range(n):
    for i in range(n):
        for j in range(n):
            if a[i][k] + a[k][j] < a[i][j]:
                print(-1)
                exit()
            elif a[i][k] + a[k][j] == a[i][j] and i!=k!=j:
                b[i][j] = 0

ans = 0
for i in range(n):
    for j in range(n):
        if b[i][j]:
            ans += a[i][j]
print(ans//2)
Problem p03606 (python)

Fixed submission:
n = int(input())
ans = 0
for i in range(n):
    a, b = list(map(int, input().split()))
    ans += b - a +1
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
ans = 0
for i in range(n):
    a, b = list(map(int, input().split))
    ans = b - a +1
print(ans)
Problem p03607 (python)

Fixed submission:
n = int(input())
a = {}
for i in range(n):
    b = int(input())
    if b in a.keys():
        a[b] += 1
    else:
        a[b] = 1
ans = 0
for i in a.keys():
    if a[i]%2 == 1:
        ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = []
for i in range(n):
    a.append(int(input())
ans = 0
for i in set(a):
    if i in a:
        ans += 1
print(ans)
Problem p03612 (python)

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

count = 0
now = 0
for i in range(len(p)):
    if len(p) == 0:
        break
    if now+1 == p[0]:
        p.pop(0)
        count += 1
        now += 1
    if len(p) == 0:
        break
    p.pop(0)
    now += 1
print(count)

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

count = 0
now = 0
for i in range(len(p)):
    if len(p) == 0:
        break
    if now+1 == p[0]:
        p.pop(0)
        count += 1
        now += 1
    p.pop(0)
    now += 1
print(count)
Problem p03633 (python)

Fixed submission:
from fractions import gcd

N = int(input())
T = []
for i in range(N):
    T.append(int(input()))
# 最小公倍数が欲しい
ans = 1
for i in T:
    ans = int(ans * i //gcd(ans, i))
print(ans)

Buggy submission (verdict: Runtime Error):
    def gcd(a, b):
        if a < b:
            a, b = b, a
        if b == 0:
            return a
        else:
            return int(gcd(b, a%b))
     
    def lcm(a, b):
        return int(a // gcd(a, b) * b)
     
    N = input()
    V = 1
    for i in range(int(N)):
        T = input()
        V = lcm(V, int(T))
     
    print("%d" % V)
Problem p03701 (python)

Fixed submission:
n = int(input())
s = []

geta = 0
for i in range(n):
    a = int(input())
    if a % 10 == 0:
        geta += a
    else:
        s.append(a)

n = len(s)
s.sort(reverse=True)

tmp = sum(s)

ruiseki = [tmp]
for i in range(n-1):
    ruiseki.append(ruiseki[-1] - s[i])

ans = 0
def DFS(depth, now):
    global ans

    if depth == n:
        if now%10 != 0:
            ans = max(ans, now)
        return
    if now + ruiseki[depth] <= ans:
        return
    DFS(depth+1, now+s[depth])
    DFS(depth+1, now)
DFS(0,0)
if ans != 0:
    ans += geta
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
s = []

geta = 0
for i in range(n):
    a = int(input())
    if a % 10 == 0:
        geta += a
    else:
        s.append(a)

s.sort(reverse=True)

tmp = sum(s)

ruiseki = [tmp]
for i in range(n-1):
    ruiseki.append(ruiseki[-1] - s[i])

ans = 0
def DFS(depth, now):
    global ans
    if depth == n:
        if now%10 != 0:
            ans = max(ans, now)
        return

    if now + ruiseki[depth] <= ans:
        return
    DFS(depth+1, now+s[depth])
    DFS(depth+1, now)
DFS(0,0)
if ans != 0:
    ans += geta
print(ans)
Problem p03730 (python)

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

s = 1
if A < B:
    s = B//A + 1
syo = A*s % B   # 2とか
if s != 1:
    syo2 = A*(s - 1) % B - B
    syo += syo2
if syo == 0 and C == 0:
    print("YES")
elif syo == 0:
    print("NO")
else:
    flag = 0
    for i in range(1,97*93):
        if syo*i % B == C:
            print("YES")
            flag = 1
            break
    if flag == 0:
        print("NO")

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

s = 1
if A < B:
    s = B//A + 1
syo = A*s % B   # 2とか
def ans(syo, B, C):
    for i in range(100):
        if syo * i % B == C:
            return "YES"
    return "NO"
print(ans(syo, B, C))
Problem p03731 (python)

Fixed submission:
N, T = list(map(int, input().split()))
t =  list(map(int, input().split()))
ans = N*T
t.pop(0)   # startが0なの忘れてた
for i in range(len(t)):
    if i == len(t) - 1:
        break
    t[len(t) - 1- i] -= t[len(t) - 2 - i]
for i in t:
    if i < T:
        ans -= T - i
print(ans)

Buggy submission (verdict: Runtime Error):
N, T = list(map(int, input().split()))
t =  [int(input()) for i in range(N)]
ans = N*T
for i in t:
    if i < T:
        ans -= T - i
print(ans)
Problem p03778 (python)

Fixed submission:
W, a, b = map(int, input().split())
if abs(a-b) > W:
    print(min(abs(a - b), abs(a - b + W), abs(b - a + W)))
else:
    print(0)

Buggy submission (verdict: Runtime Error):
W, a, b = map(int, input().split())
return min(abs(a - b), abs(a - b + W), abs(b - a + W))