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

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

A.sort()
sumtab = [0] * (N + 1)
tmp_tab = 0
for i, Ai in enumerate(A):
    tmp_tab += Ai
    sumtab[i + 1] = tmp_tab

l = 0
r = N
while True:
    i = l + (r - l) // 2
    # print("#", l, r, i)
    #
    B = list(A)
    # everyone vote: i
    score_i = A[i] + M
    B[i] += M
    M_tmp = M * (V - 1)
    #
    rslt = False
    # print("#", i, B)
    for j in list(range(N))[::-1]:
        # print("##", j, M_tmp, B)
        if j == i:
            continue # me
        elif j > N - P:
            # make stronger problems stronger as possible
            tmp = min(M, M_tmp)
            #
            M_tmp -= tmp
            B[j] += tmp
        else:
            # make weaker problems weaker as possible
            if A[j] > score_i:
                break
            if A[j] + M <= score_i:
                tmp = min(M, M_tmp)
            else:
                tmp = min(score_i - A[j], M_tmp)
            #
            M_tmp -= tmp
            B[j] += tmp
        #
        if M_tmp <= 0: break
    #
    # print("##", 'e', M_tmp, B)
    if i >= N - P:
        r = i
    elif M_tmp <= 0 and score_i >= B[N - P]:
        r = i
    else:
        l = i + 1
    #
    if l >= r: break
        
print(N - l)

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

A.sort()
sumtab = [0] * (N + 1)
tmp_tab = 0
for i, Ai in enumerate(A):
    tmp_tab += Ai
    sumtab[i + 1] = tmp_tab

l = 0
r = N
while True:
    i = l + (r - l) // 2
    # print("#", l, r, i)
    #
    B = list(A)
    # everyone vote: i
    score_i = A[i] + M
    B[i] += M
    M_tmp = M * (V - 1)
    #
    rslt = False
    # print("#", i, B)
    for j in list(range(N))[::-1]:
        # print("##", j, M_tmp, B)
        if j == i:
            continue # me
        elif j > N - P:
            # make stronger problems stronger as possible
            tmp = min(M, M_tmp)
            #
            M_tmp -= tmp
            B[j] += tmp
        else:
            # make weaker problems weaker as possible
            if A[j] + M <= score_i:
                tmp = min(M, M_tmp)
            else:
                tmp = min(score_i - A[j], M_tmp)
            #
            M_tmp -= tmp
            B[j] += tmp
        #
        if M_tmp <= 0: break
    #
    # print("##", 'e', M_tmp, B)
    if M_tmp <= 0 and score_i >= B[N - P]:
        r = i
    else:
        l = i + 1
    #
    if l >= r: break
        
print(N - l)
Problem p02936 (python)

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

graph = [[] for _ in range(N)]
for ai, bi in ab:
    graph[ai - 1].append(bi - 1)
    graph[bi - 1].append(ai - 1)

parent = [None] * N
parent[0] = 0

score = [0] * N
for pi, xi in px:
    score[pi - 1] += xi

ans = [None] * N

from collections import deque

q = deque([(0, 0)])
while len(q) > 0:
    src, score_tmp = q.popleft()
    score_tmp += score[src]
    ans[src] = score_tmp
    for dst in graph[src]:
        if ans[dst] != None: continue
        q.append((dst, score_tmp))

print(' '.join(map(str, ans)))

Buggy submission (verdict: Runtime Error):
N, Q = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(N - 1)]
px = [list(map(int, input().split())) for _ in range(Q)]

graph = [[] for _ in range(N)]
for ai, bi in ab:
    graph[ai - 1].append(bi - 1)
    graph[bi - 1].append(ai - 1)

parent = [None] * N
parent[0] = 0

def dfs(src):
    for dst in graph[src]:
        if parent[dst] != None: continue
        parent[dst] = src
        dfs(dst)

dfs(0)
# print("#", parent)

score = [0] * N
for pi, xi in px:
    score[pi - 1] += xi
        
memo = [None] * N
def dp(arg):
    if memo[arg] != None: return memo[arg]
    ret = score[arg]
    if arg != parent[arg]: ret += dp(parent[arg])
    memo[arg] = ret
    return ret

ans = []
for i in range(N):
    ans.append(dp(i))

print(' '.join(map(str, ans)))
Problem p02995 (python)

Fixed submission:
import sys
# input = sys.stdin.readline

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

def div(a, b):
    return a // b

def gcd(a, b):
    if b > a: return gcd(b, a)
    elif b == 0: return a
    else: return gcd(b, a % b)

ans = 0
ans += div(B, C)
ans -= div(A - 1, C)
# print("#", ans)
ans += div(B, D)
ans -= div(A - 1, D)
# print("#", ans)
#
E = (C * D) // gcd(C, D)
ans -= div(B, E)
ans += div(A - 1, E)
# print("#", ans)

ans = (B - A + 1) - ans
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
# input = sys.stdin.readline

N = int(input())
AB = [list(map(int, input().split())) for _ in range(N)]


ans = 0
ans += B // C
ans -= (A - 1) // C
# print("#", ans)
ans += B // D
ans -= (A - 1) // D
# print("#", ans)
#
ans -= B // (C * D)
ans += (A - 1) // (C * D)
# print("#", ans)

ans = (B - A + 1) - ans
print(ans)
Problem p03006 (python)

Fixed submission:
import sys
# input = sys.stdin.readline
inf = 10 ** 18

N = int(input())
xy = [list(map(int, input().split())) for _ in range(N)]

x = [xi for xi, yi in xy]
y = [yi for xi, yi in xy]

ans = inf
for i in range(N - 1):
    xi, yi = xy[i]
    for j in range(i + 1, N):
        xj, yj = xy[j]
        #
        p = xj - xi
        q = yj - yi
        #
        ans_tmp = 0
        for n, (xn, yn) in enumerate(xy):
            xm = xn - p
            ym = yn - q
            # print("##", (xm, ym))
            if [xm, ym] not in xy: ans_tmp += 1
        #
        # print("#", xy, ans_tmp)
        if ans > ans_tmp: ans = ans_tmp

if N == 1:
    print(1)
else:
    print(ans)

Buggy submission (verdict: Runtime Error):
import sys
# input = sys.stdin.readline
inf = 10 ** 18

N = int(input())
xy = [list(map(int, input().split())) for _ in range(N)]

ans = inf
for i in range(N - 1):
    xi, yi = xy[i]
    for j in range(i + 1, N):
        xj, yj = xy[j]
        #
        p = xj - xi
        q = yj - yi
        terms = set([])
        for n, (xn, yn) in enumerate(xy):
            mp = q * xn -  p * yn
            mod = xn % p if p > 0 else yn % q
            terms.add((mp, mod))
        # print("#", p, q, terms)
        ans_tmp = len(terms)
        #
        if ans > ans_tmp: ans = ans_tmp

print(ans)
Problem p03046 (python)

Fixed submission:
import sys
# input = sys.stdin.readline
inf = 10 ** 18

M, K = map(int, input().split())

tmp = 0
notK = []
for i in range(1 << M):
    if i == K: continue
    tmp ^= i
    notK.append(i)
if K == 0:
    ans = []
    for i in range((1 << M)):
        ans.append(i)
    for i in range((1 << M)):
        ans.append((1 << M) - 1 - i)
    #
    for i, ansi in enumerate(ans):
        if i > 0: print(' ', end='')
        print(ansi, end='')
    print()
elif tmp != K:
    print(-1)
else:
    ans = []
    ans.append(notK[0])
    ans.append(K)
    ans.append(notK[0])
    for i in range(1, (1 << M) - 1):
        ans.append(notK[i])
    ans.append(K)
    for i in range(1, (1 << M) - 1):
        ans.append(notK[(1 << M) - 1 - i])
    #
    for i, ansi in enumerate(ans):
        if i > 0: print(' ', end='')
        print(ansi, end='')
    print()

Buggy submission (verdict: Runtime Error):
import sys
# input = sys.stdin.readline
inf = 10 ** 18

M, K = map(int, input().split())

tmp = 0
notK = []
for i in range(1 << M):
    if i == K: continue
    tmp ^= i
    notK.append(i)
if K == 0:
    ans = []
    for i in range((1 << M)):
        ans.append(i)
    for i in range((1 << M)):
        ans.append((1 << M) - 1 - i)
    #
    for i, ansi in enumerate(ans):
        if i > 0: print(' ', end='')
        print(ansi, end='')
    print()
elif tmp != K:
    print(-1)
else:
    ans = []
    ans.append(notK[0])
    ans.append(K)
    ans.append(notK[0])
    for i in range(1, (1 << M)):
        ans.append(notK[i])
        ans.append(K)
    for i in range(1, (1 << M)):
        ans.append(notK[(1 << M) - i])
    #
    for i, ansi in enumerate(ans):
        if i > 0: print(' ', end='')
        print(ansi, end='')
    print()
Problem p03112 (python)

Fixed submission:
import sys, bisect
input = sys.stdin.readline
A, B, Q = map(int, input().split())
s = [int(input()) for _ in range(A)]
t = [int(input()) for _ in range(B)]
x = [int(input()) for _ in range(Q)]
inf = 10 ** 18

s = [-inf] + s + [inf]
t = [-inf] + t + [inf]

ans_Q = [None] * Q
i_last = j_last = 0
for idx, x_tmp in sorted(enumerate(x), key=lambda x: x[1]):
    i_l = max(0, bisect.bisect_left(s, x_tmp, lo=i_last) - 1)
    j_l = max(0, bisect.bisect_left(t, x_tmp, lo=j_last) - 1)
    # print("#", x_tmp, (i_l, s[i_l]), (j_l, t[j_l]))
    #
    ans = inf
    for i, j in ((i_l, j_l), (i_l + 1, j_l), (i_l, j_l + 1), (i_l + 1, j_l + 1)):
        if i < 1 or A < i: continue
        if j < 1 or B < j: continue
        ans_tmp_s = abs(x_tmp - s[i]) + abs(s[i] - t[j])
        ans_tmp_t = abs(x_tmp - t[j]) + abs(s[i] - t[j])
        ans_tmp = min(ans_tmp_s, ans_tmp_t)
        # print("#", x_tmp, s[i], t[j], ans_tmp)
        if ans > ans_tmp:
            ans = ans_tmp
    #
    i_last, j_last = i_l, j_l
    ans_Q[idx] = ans

for ansi in ans_Q: print(ansi)

Buggy submission (verdict: Runtime Error):
A, B, Q = map(int, input().split())
s = [int(input()) for _ in range(A)]
t = [int(input()) for _ in range(B)]
x = [int(input()) for _ in range(Q)]
inf = 10 ** 18

s = [-inf] + s + [inf]
t = [-inf] + t + [inf]

# def binsearch_l(seq, l, r, tar):
#     if r - l < 2: return l
#     #
#     m = l + (r - l + 1) // 2
#     # print("##", l, r, (m, seq[m]), tar)
#     if seq[m] <= tar:
#         return binsearch_l(seq, m, r, tar)
#     else:
#         return binsearch_l(seq, l, m, tar)

ans_Q = [None] * Q
i_last = j_last = 0
for idx, x_tmp in sorted(enumerate(x), key=lambda x: x[1]):
    i_l, i_r = 0, A + 2
    while i_r - i_l > 1:
        m = i_l + (i_r - i_l) // 2
        # print("##", i_l, i_r, (m, s[m]), x_tmp)
        if s[m] <= x_tmp:
            i_l = m
        else:
            i_r = m
    #
    j_l, j_r = 0, A + 2
    while j_r - j_l > 1:
        m = j_l + (j_r - j_l) // 2
        # print("##", j_l, j_r, (m, t[m]), x_tmp)
        if t[m] <= x_tmp:
            j_l = m
        else:
            j_r = m
    #
    ans = inf
    for i, j in ((i_l, j_l), (i_l + 1, j_l), (i_l, j_l + 1), (i_l + 1, j_l + 1)):
        if i < 1 or A < i: continue
        if j < 1 or B < j: continue
        ans_tmp_s = abs(x_tmp - s[i]) + abs(s[i] - t[j])
        ans_tmp_t = abs(x_tmp - t[j]) + abs(s[i] - t[j])
        ans_tmp = min(ans_tmp_s, ans_tmp_t)
        # print("#", x_tmp, s[i], t[j], ans_tmp)
        if ans > ans_tmp:
            ans = ans_tmp
    #
    i_last, j_last = i_l, j_l
    ans_Q[idx] = ans

for ansi in ans_Q: print(ansi)
Problem p03195 (python)

Fixed submission:
# encoding: utf-8
N = int(input())
a = [int(input()) for i in range(N)]

ans = 2
for ai in a:
    if ai % 2:
        ans = 1
        break

if ans == 2: print('second')
else: print('first')

Buggy submission (verdict: Runtime Error):
# encoding: utf-8
import math
N, P = map(int, input().split())

ans = 1
P_tmp = P
for p in range(2, int(math.sqrt(P)) + 1):
    if P_tmp % (p ** N) == 0:
        for i_p in range(1, P):
            if P_tmp % (p ** (N * (i_p + 1))) > 0: break
        P_tmp = P_tmp // (p ** (N * i_p))
        ans = ans * (p ** i_p)
    if P_tmp < ((p + 1) ** N): break

print(ans)
Problem p03240 (python)

Fixed submission:
# encoding: utf-8
N = int(input())
xyh = [list(map(int, input().split())) for i in range(N)]

ans = None
for cx in range(101):
    for cy in range(101):
        H_tmp = -1
        # print("#", cx, cy)
        for xi, yi, hi in sorted(xyh, key=lambda x: -x[2]):
            # print("##", (xi, yi, hi), H_tmp)
            dx = (xi - cx) if xi >= cx else (cx - xi)
            dy = (yi - cy) if yi >= cy else (cy - yi)
            if H_tmp == -1: H_tmp = hi + dx + dy
            elif hi == 0:
                if dx + dy < H_tmp: break
                else: continue
            elif H_tmp == hi + dx + dy: H_tmp = hi + dx + dy
            else: break
        else:
            ans = (cx, cy, H_tmp)
        if ans != None: break
    if ans != None: break

print(ans[0], ans[1], ans[2])

Buggy submission (verdict: Runtime Error):
# encoding: utf-8
N = int(input())
xyh = [list(map(int, input().split())) for i in range(N)]

ans = None
for cx in range(101):
    for cy in range(101):
        H_tmp = 0
        for xi, yi, hi in xyh:
            dx = xi - cx if xi >= cx else cx - xi
            dy = yi - cy if yi >= cy else cy - yi
            if H_tmp == 0 or H_tmp == hi + dx + dy: H_tmp = hi + dx + dy
            else: break
        else:
            ans = (cx, cy, H_tmp)
        if ans != None: break
    if ans != None: break

print(ans[0], ans[1], ans[2])
Problem p03254 (python)

Fixed submission:
# encoding: utf-8
# N = int(input())
# S = input()
# N, M = map(int, input().split())
# A = list(map(int, input().split()))

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

x_tmp = x
for i, Ai in enumerate(sorted(A)):
    x_tmp -= Ai
    if x_tmp == 0:
        ans = i + 1
        break
    elif x_tmp < 0:
        ans = i
        break
    else: continue
else: ans = i

print(ans)

Buggy submission (verdict: Runtime Error):
# encoding: utf-8
# N = int(input())
# S = input()
# N, M = map(int, input().split())
# A = list(map(int, input().split()))

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

tab = [[None] * (x + 1) for i in range(N)]

def recsearch(i, x_tmp):
    # print("#", i, x_tmp)
    if i == N:
        if x_tmp > 0: return -1
        else: return 0
    elif tab[i][x_tmp] != None: ret = tab[i][x_tmp] # read
    elif x_tmp == 0: ret = 0
    elif x_tmp < A[i]: ret = recsearch(i + 1, x_tmp)
    else: ret = max((recsearch(i + 1, x_tmp - A[i]) + 1, recsearch(i + 1, x_tmp)))
    if tab[i][x_tmp] == None: tab[i][x_tmp] = ret # write
    return ret

print(max(0, recsearch(0, x)))
Problem p03267 (python)

Fixed submission:
# encoding: utf-8
L = int(input())

# length
for l_max in range(1, 21):
    if 2 ** l_max > L: break

# encode L - 2 ** (l_max - 1)
bits_sub = [None] * l_max
L_temp = L - 2 ** (l_max - 1)
for l in range(l_max):
    bits_sub[l] = L_temp % 2
    L_temp = L_temp // 2

# result
N = l_max
M = 2 * (l_max - 1) + sum(bits_sub)
print(N, M) # oh...

# main path
for i in range(l_max - 1):
    for j in range(2):
        print(i + 1, i + 2, j * (2 ** i))

# sub path
maxlen = 2 ** (l_max - 1)
for i, bit in enumerate(bits_sub):
    if bit == 0: continue
    for j in range(bit):
        print(i + 1, l_max, maxlen)
        maxlen += 2 ** i

Buggy submission (verdict: Runtime Error):
# encoding: utf-8
L = int(input())

for base in range(2, 60):
    # encode
    for l_max in range(L):
        if base ** l_max > L: break
    bits = [None] * l_max
    L_temp = L
    for l in range(l_max):
        bits[l] = L_temp % base
        L_temp = L_temp // base
    # calculate N and M
    N = 2
    M = 0
    for l, bit in enumerate(bits):
        N += max((0, (bit > 0) * (l - 1)))
        M += (bit > 0) * max((1, base * l))
    if 2 < N <= 20 and 2 <= M <= 60: break
    else: continue
else:
    print("oops")
    
print(N, M)

offset = 0
idx = 2
for l, bit in enumerate(bits):
    if bit == 0: continue
    elif l == 0:
        print(1, N, 0)
        offset += 1
        continue
    # if l > 0
    nodes = [1] + [idx + i for i in range(l - 1)]
    # w/o offset
    for i in range(base * (l - 1)):
        edge = i % base
        if i % base == 0:
            cnct = i // base
            print(nodes[cnct], nodes[cnct + 1], 0)
        else:
            print(nodes[cnct], nodes[cnct + 1], edge * (base ** cnct))
    # w/ offset
    cnct += 1
    for i in range(base):
        if i == 0:
            print(nodes[-1], N, offset)
        else:
            print(nodes[-1], N, offset + i * (base ** cnct))
    # update offset and idx
    offset += max((1, base * l))
    idx += l
    # print
Problem p03274 (python)

Fixed submission:
# encoding: utf-8
import math
N, K = map(int, input().split())
x = list(map(int, input().split()))

# find position of Mr.Sunuke
for i_snk, xi in enumerate(x):
    if xi >= 0: break

# (left, right) * K patterns, left + right = K
min_dist = (x[-1] - x[0]) * K
for left in range(K + 1):
    right = K - left
    # skip
    # print("#", i_snk, left, right)
    if i_snk - left < 0: continue
    elif right + i_snk > N: continue
    # calc dist
    left_x = x[i_snk - left]
    right_x = x[i_snk + right - 1]
    tocorner = int(min(math.fabs(left_x), math.fabs(right_x)))
    side2side = right_x - left_x
    # print("##", i_snk, left_x, right_x, tocorner + side2side)
    if tocorner + side2side < min_dist: min_dist = tocorner + side2side

print(min_dist)

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

import bisect

idx_r = bisect.bisect_left(x, 0)

if x[idx_r] == 0:
    idx_l = idx_r
else:
    idx_l = idx_r - 1

ans = 1000000007
    
# right
if 0 <= idx_r + K - 1 < N:
    ans_tmp = x[idx_r + K - 1]
    ans = min(ans, ans_tmp)

# left
if 0 <= idx_l - K + 1 < N:
    ans_tmp = -x[idx_l - K + 1]
    ans = min(ans, ans_tmp)

# right -> left
for i in range(N):
    if 0 <= idx_r - K + 1 + i < idx_r + i < N:
        ans_tmp = 2 * x[idx_r + i] - x[idx_r - K + 1 + i]
        ans = min(ans, ans_tmp)

# left -> right
for i in range(N):
    if 0 <= idx_l - i < idx_l + K - 1 - i < N:
        ans_tmp = x[idx_l + K - 1 - i] - 2 * x[idx_l - i]
        ans = min(ans, ans_tmp)

print(ans)

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

import bisect

idx_r = bisect.bisect_left(x, 0)

if x[idx_r] == 0:
    idx_l = idx_r
else:
    idx_l = idx_r - 1

ans = 1000000007
    
# right
if 0 <= idx_r + K - 1 < N:
    ans_tmp = x[idx_r + K - 1]
    ans = min(ans, ans_tmp)

# left
if 0 <= idx_l - K + 1 < N:
    ans_tmp = -x[idx_l - K + 1]
    ans = min(ans, ans_tmp)

# right -> left
for i in range(N):
    if idx_r + i >= N or idx_r - K + 1 + i < 0: continue
    ans_tmp = 2 * x[idx_r + i] - x[idx_r - K + 1 + i]
    ans = min(ans, ans_tmp)

# left -> right
for i in range(N):
    if idx_l + K - 1 - i >= N or idx_l - i < 0: continue
    ans_tmp = x[idx_l + K - 1 - i] - 2 * x[idx_l - i]
    ans = min(ans, ans_tmp)

print(ans)
Problem p03284 (python)

Fixed submission:
# encoding: utf-8

n, k = input().split()

if int(n) % int(k) == 0: print(0)
else: print(1)

Buggy submission (verdict: Runtime Error):
# encoding: utf-8
N, M = list(map(int, input().split()))

# TLE
# Amod = [A for A in map(lambda x: int(x) % M , input().split())]
# ans = 0
# for l in range(len(Amod)):
#     acm = 0
#     for r in range(l, len(Amod)):
#         acm = (acm + Amod[r]) % M
#         if acm == 0: ans += 1

Asym = []

sym = 0
cnt_zero = 0
for i, A in enumerate(map(int, input().split())):
    sym = (sym + A) % M
    if sym > 0: Asym.append(sym)
    else: cnt_zero += 1
        
ans = cnt_zero * (cnt_zero + 1)
# for sym in set(Asym):
#     cnt = Asym.count(sym)
#     ans += cnt * (cnt -  1)
        
print(int(ans / 2))

# speed test

# Acnt = [0 for i in range(M)]
# sym = 0
# for A in map(int, input().split()):
#     sym = (sym + A) % M
#     Acnt[sym] += 1

# print(int(Acnt[0] + sum([cnt * (cnt - 1) for cnt in Acnt]) / 2))

Buggy submission (verdict: Runtime Error):
# encoding: utf-8
N, M = list(map(int, input().split()))

# TLE
Amod = [A for A in map(lambda x: int(x) % M ,filter(lambda x: int(x) % M > 0, input().split()))]
ans = 0
for l in range(len(Amod)):
    acm = 0
    for r in range(l, len(Amod)):
        acm = (acm + Amod[r]) % M
        if acm == 0: ans += 1

print(ans)

Buggy submission (verdict: Runtime Error):
# encoding: utf-8
N, M = list(map(int, input().split()))

# TLE
Amod = [A for A in map(lambda x: int(x) % M ,filter(lambda x: int(x) % M > 0, input().split()))]
ans = 0
for l in range(len(Amod)):
    acm = 0
    for r in range(l, len(Amod)):
        acm = (acm + Amod[r]) % M
        if acm == 0: ans += 1
Problem p03287 (python)

Fixed submission:
# encoding: utf-8
N, M = list(map(int, input().split()))

d_sym = {}
sym = 0

# refresh

ans = 0
for A in map(int, input().split()):
    sym = (sym + A) % M
    #
    if sym == 0: ans += 1
    # 
    if str(sym) in d_sym.keys(): d_sym[str(sym)] += 1
    else: d_sym[str(sym)] = 1

print(int(ans + sum([val * (val - 1) / 2 for val in d_sym.values()])))

Buggy submission (verdict: Runtime Error):
# encoding: utf-8
N, M = list(map(int, input().split()))

d_sym = {}
sym = 0

# refresh

for A in map(int, input().split()):
    sym = (sym + A) % M
    if str(sym) in d_sym: d_sym[str(sym)] += 1
    else: d_sym[str(sym)] = 1

print(int(d_sym["0"] + sum([val * (val - 1) / 2 for val in d_sym.values()])))
Problem p03387 (python)

Fixed submission:
# encoding: utf-8
ABC = sorted(list(map(int, input().split())))

diff0 = ABC[-1] - ABC[0]
diff1 = ABC[-1] - ABC[1]

# +2 only
if diff0 % 2 == diff1 % 2 == 0: ans = (diff0 + diff1) // 2
# +1 (ABC[0], ABC[1]) once and +2
elif diff0 % 2 == diff1 % 2 == 1: ans = (diff0 + diff1) // 2
# +1 (ABC[{0, 1}], ABC[2]) once and +2)
else: ans = 1 + (diff0 + diff1 + 2) // 2

print(ans)

Buggy submission (verdict: Runtime Error):
2 6 3
Problem p03476 (python)

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

MAGIC_NUMBER = 100000
isprime = [True] * (MAGIC_NUMBER + 1)
for p in range(2, MAGIC_NUMBER + 1):
    if not isprime[p]: continue
    i_p = 2
    while p * i_p <= MAGIC_NUMBER:
        isprime[p * i_p] = False
        i_p += 1

primes = []
for p in range(2, MAGIC_NUMBER + 1):
    if isprime[p]: primes.append(p)

candidates = []
for p in primes:
    if p % 2 == 0: continue
    #
    if isprime[(p + 1) // 2]: candidates.append(p)


import bisect
    
for i, (li, ri) in enumerate(lr):
    i_l = bisect.bisect_left(candidates, li)
    i_r = bisect.bisect_left(candidates, ri)
    #
    if i_r < len(candidates) and candidates[i_r] == ri: i_r += 1
    print(i_r - i_l)

Buggy submission (verdict: Runtime Error):
Q = int(input())
lr = [list(map(int, input().split())) for _ in range(Q)]

MAGIC_NUMBER = 100000
isprime = [True] * (MAGIC_NUMBER + 1)
for p in range(2, MAGIC_NUMBER + 1):
    if not isprime[p]: continue
    i_p = 2
    while p * i_p <= MAGIC_NUMBER:
        isprime[p * i_p] = False
        i_p += 1

primes = []
for p in range(2, MAGIC_NUMBER + 1):
    if isprime[p]: primes.append(p)

candidates = []
for p in primes:
    if p % 2 == 0: continue
    #
    if isprime[(p + 1) // 2]: candidates.append(p)


import bisect
    
for i, (li, ri) in enumerate(lr):
    i_l = bisect.bisect_left(candidates, li)
    i_r = bisect.bisect_left(candidates, ri)
    #
    if candidates[i_r] == ri: i_r += 1
    print(i_r - i_l)
Problem p03625 (python)

Fixed submission:
# encoding: utf-8
N = int(input())
A = list(map(int, input().split()))

A.sort()

view = 10 ** 9 + 7
lengths = [0] * 2
idx = 0
for Ai in reversed(A):
    if Ai < view:
        view = Ai
        cnt = 0
    cnt += 1
    if cnt >= 2:
        lengths[idx] = view
        cnt = 0
        idx += 1
    if idx > 1: break

# print("#", lengths)
print(lengths[0] * lengths[1] if idx > 1 else 0)

Buggy submission (verdict: Runtime Error):
# encoding: utf-8
N = int(input())
A = list(map(int, input().split()))

A.sort()

view = 10 * 9 + 7
lengths = [0] * 2
idx = 0
for Ai in reversed(A):
    if Ai < view:
        view = Ai
        cnt = 0
    cnt += 1
    if cnt >= 2:
        lengths[idx] = view
        cnt = 0
        idx += 1
    if idx > 1: break

# print("#", lengths)
print(lengths[0] * lengths[1] if idx > 1 else 0)