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

Fixed submission:
from collections import Counter
from itertools import combinations

N = int(input())
R = [[int(i) for i in input().split()] for _ in range(N)]

if N == 1:
    print(1)
    quit()

L = []
for (x1, y1), (x2, y2) in combinations(R, 2):
    L.append((x1 - x2, y1 - y2))
    L.append((-x1 + x2, -y1 + y2))

C = Counter(L)
print(N - C.most_common(1)[0][1])

Buggy submission (verdict: Runtime Error):
N = int(input())
R = [[int(i) for i in input().split()] for _ in range(N)]

from itertools import combinations
L = []
for (x1, y1), (x2, y2) in combinations(R, 2):
    L.append((x1 - x2, y1 - y2))
    L.append((-x1 + x2, -y1 + y2))

from collections import Counter
C = Counter(L)
print(N - C.most_common(1)[0][1])
Problem p03030 (python)

Fixed submission:
N = int(input())

dic = {}
for i in range(N):
    S, P = [i for i in input().split()]
    if S in dic:
        dic[S].append((int(P), i + 1))
    else:
        dic[S] = [(int(P), i + 1)]

for s in sorted(dic.keys()):
    for l in reversed(sorted(dic[s])):
        print(l[1])

Buggy submission (verdict: Runtime Error):
N = int(input())
S, P = [""], [0]
for _ in range(N):
    s, p = input().split()
    S.append(s)
    P.append(int(p))

I = [*range(1, N + 1)]
I.sort(key=lambda i: P[i], reverse=True)
I.sort(key=lambda i: S[i])

print(*I, sep='\n')

Buggy submission (verdict: Runtime Error):
N = int(input())
S, P = [""], [0]
for _ in range(N):
    s, p = input().split()
    S.append(s)
    P.append(int(p))

I = [*range(1, N + 1)]
I.sort(key=lambda i: P[i], reverse=True)
I.sort(key=lambda i: S[i])

print(*I, sep='\n')
Problem p03062 (python)

Fixed submission:
N = int(input())
A = [int(i) for i in input().split()]

m = 0
su = 0
mi = 10 ** 10
for ai in A:
    if ai < 0:
        m += 1
    mi = min(mi, abs(ai))
    su += abs(ai)

if m % 2 == 1:
    print(su - 2 * mi)
else:
    print(su)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = [int(i) for i in input().split()]

B = map(abs, A)
if len([a for a in A if a < 0]) % 2 == 1:
    print(sum(B) - min(B))
else:
    print(sum(B))

Buggy submission (verdict: Runtime Error):
N = int(input())
A = [int(i) for i in input().split()]

A.sort()
su = 0
m = 0
for i in range(N):
    if A[i] < 0:
       su -= A[i]
       m += 1
    else:
       su += A[i]

if m % 2 == 1:
    print(su - 2 * A[m])
else:
    print(su)
Problem p03148 (python)

Fixed submission:
from heapq import heappush, heappop, heapreplace

INF = 10 ** 9 + 5

N, K, *TD = map(int, open(0).read().split())

E = [[] for _ in range(N)]
for t, d in zip(*[iter(TD)] * 2):
    E[t - 1].append(d)

for e in E:
    if e:
        e.sort(reverse=True)
    else:
        e.append(-INF)
E.sort(key=lambda x: -x[0])

cur = 0
Q = []
for ei in E[:K]:
    cur += ei[0]
    for eij in ei[1:]:
        heappush(Q, -eij)

for ei in E[K:]:
    for eij in ei:
        heappush(Q, -eij)

res = cur + K * K
for x in reversed(range(1, K)):
    v, w = E[x][0], -Q[0]
    if v < w:
        heappop(Q)
        cur += w
        heappush(Q, -v)
        cur -= v

    res = max(res, cur + x * x)

print(res)

Buggy submission (verdict: Runtime Error):
from heapq import heappush, heappop

INF = float("inf")

N, K, *TD = map(int, open(0).read().split())

S = [[] for _ in range(N)]
for t, d in zip(*[iter(TD)] * 2):
    S[t - 1].append(d)

E = []
for s in S:
    if s:
        E.append(sorted(s, reverse=True))
    else:
        E.append([-INF])
E.sort(reverse=True)

cur = 0
Q = []
for i in range(K):
    cur += E[i][0]
    for j in range(1, len(E[i])):
        heappush(Q, -E[i][j])

for i in range(K, N):
    for j in range(len(E[i])):
        heappush(Q, -E[i][j])

res = cur + K * K
for x in range(K, 0, -1):
    v, w = E[x][0], -Q[0]
    if v < w:
        heappop(Q)
        cur += w
        heappush(Q, -v)
        cur -= v

    res = max(res, cur + x * x)

print(res)
Problem p03155 (python)

Fixed submission:
N = int(input())
H = int(input())
W = int(input())

print((N - H + 1) * (N - W + 1))

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(200000)

H, W = [int(_) for _ in input().split()]
S = [input() for _ in range(H)]

move = ((1, 0), (-1, 0), (0, 1), (0, -1))
visited = [[False] * W for _ in range(H)]
b, w = 0, 0

def dfs(i, j):
    global b, w

    visited[i][j] = True

    if S[i][j] == '#':
        b += 1
    else:
        w += 1

    for di, dj in move:
        ni, nj = i + di, j + dj
        if 0 <= ni < H and 0 <= nj < W:
            if S[i][j] != S[ni][nj] and not visited[ni][nj]:
                dfs(ni, nj)


result = 0
for i in range(H):
    for j in range(W):
        if visited[i][j]:
            continue
        b, w = 0, 0
        dfs(i, j)
        result += b * w
print(result)
Problem p03166 (python)

Fixed submission:
from sys import setrecursionlimit
setrecursionlimit(10 ** 5 + 10)

N, M, *XY = map(int, open(0).read().split())

E = [[] for _ in range(N + 1)]
for x, y in zip(*[iter(XY)] * 2):
    E[x].append(y)

memo = {}
def dp(p):
    if p in memo:
        return memo[p]

    memo[p] = max((1 + dp(c) for c in E[p]), default=0)
    return memo[p]

print(max(dp(p) for p in range(1, N + 1)))

Buggy submission (verdict: Runtime Error):
from sys import setrecursionlimit
setrecursionlimit(10 ** 5 + 10)

from functools import lru_cache

N, M, *XY = map(int, open(0).read().split())

E = [[] for _ in range(N + 1)]
for x, y in zip(*[iter(XY)] * 2):
    E[x].append(y)

@lru_cache(maxsize=None)
def dp(p):
    return max((1 + dp(c) for c in E[p]), default=0)

print(max(dp(p) for p in range(1, N + 1)))

Buggy submission (verdict: Runtime Error):
from sys import setrecursionlimit
setrecursionlimit(10 ** 5 + 10)

from functools import lru_cache

N, M, *XY = map(int, open(0).read().split())

E = [[] for _ in range(N + 1)]
for x, y in zip(*[iter(XY)] * 2):
    E[x].append(y)

@lru_cache
def dp(p):
    return max((1 + dp(c) for c in E[p]), default=0)

print(max(dp(p) for p in range(1, N + 1)))

Buggy submission (verdict: Runtime Error):
N, M, *XY = map(int, open(0).read().split())

E = [[] for _ in range(N + 1)]
for x, y in zip(*[iter(XY)] * 2):
    E[x].append(y)

memo = {}
def dp(p):
    if p not in memo:
        memo[p] = max((1 + dp(c) for c in E[p]), default=0)
    return memo[p]

print(max(dp(p) for p in range(1, N + 1)))

Buggy submission (verdict: Runtime Error):
from sys import setrecursionlimit
setrecursionlimit(10 ** 5 + 10)

N, M, *XY = map(int, open(0).read().split())

E = [[] for _ in range(N + 1)]
for x, y in zip(*[iter(XY)] * 2):
    E[x].append(y)

memo = {}
def dp(p):
    return memo.get(p, max((1 + dp(c) for c in E[p]), default=0))

print(max(dp(p) for p in range(1, N + 1)))

Buggy submission (verdict: Runtime Error):
from sys import setrecursionlimit
setrecursionlimit(10 ** 5 + 10)

N, M, *XY = map(int, open(0).read().split())

E = [[] for _ in range(N + 1)]
for x, y in zip(*[iter(XY)] * 2):
    E[x].append(y)

memo = {}
def dp(p):
    memo[p] = max((1 + memo.get(c, dp(c)) for c in E[p]), default=0)
    return memo[p]

print(max(dp(p) for p in range(1, N + 1)))
Problem p03168 (python)

Fixed submission:
N = int(input())
P = [float(i) for i in input().split()]

dp = [[0.0] * (N + 1) for _ in range(N + 1)]
dp[0][0] = 1.0

for i, p in enumerate(P, 1):
    for j in range(N + 1):
        dp[i][j] = p * dp[i - 1][j - 1] + (1 - p) * dp[i - 1][j]

print(sum(dp[N][-(-N // 2):]))

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

dp = [1] + [0] * N
for p in enumerate(P):
    dp = [p * a + (1 - p) * b for a, b in zip([0] + dp, dp)]

print(sum(dp[-(-N // 2):]))

Buggy submission (verdict: Runtime Error):
N = int(input())
P = [float(i) for i in input().split()]

dp = [0, 1, 0, 0, 0, 0]
for i, p in enumerate(P):
    print(dp)
    dp = [p * dp[j - 1] + (1 - p) * dp[j] for j in range(1, N + 2)]

print(sum(dp[-(-N // 2):]))
Problem p03177 (python)

Fixed submission:
from numpy import array, eye

mod = 10 ** 9 + 7

N, K, *A = map(int, open(0).read().split())
A = array(A, dtype=object).reshape(N, N)

ans = eye(N, dtype=object)
while K:
    if K & 1:
        ans = (ans.dot(A)) % mod
    A = A.dot(A) % mod
    K //= 2

print(ans.sum() % mod)

Buggy submission (verdict: Runtime Error):
from numpy import int_, eye

mod = 10 ** 9 + 7

N, K, *A = map(int, open(0).read().split())
A = int_(A).reshape(N, N)

ans = eye(N, dtype=int_)
while K:
    if K & 1:
        ans = (ans.dot(A)) % mod
    A = A.dot(A) % mod
    K //= 2

print(ans.sum() % mod)

Buggy submission (verdict: Runtime Error):
from numpy import int_

mod = 10 ** 9 + 7

N, K, *A = map(int, open(0).read().split())
A = int_(A).reshape(N, N)

K //= 2
ans = A
while K:
    if K & 1:
        ans = (ans @ A) % mod
    A = (A @ A) % mod
    K //= 2

print(ans.sum())
Problem p03216 (python)

Fixed submission:
N = int(input())
S = input()
Q = int(input())
K = [int(i) for i in input().split()]

for k in K:
    ans = 0

    d = m = dm = 0
    for i, si in enumerate(S):
        if 0 <= i - k:
            if S[i - k] == "D":
                d -= 1
                dm -= m
            elif S[i - k] == "M":
                m -= 1

        if si == "D":
            d += 1
        elif si == "M":
            m += 1
            dm += d
        elif si == "C":
            ans += dm

    print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
S = input()
Q = int(input())
K = [int(i) for i in input().split()]

for k in K:
    ans = 0

    d = m = dm = 0
    for i, si in enumerate(S):
        if 0 <= i - K:
            if S[i - K] == "D":
                d -= 1
                dm -= m
            elif S[i - K] == "M":
                m -= 1

        if si == "D":
            d += 1
        elif si == "M":
            m += 1
            dm += d
        elif si == "C":
            ans += dm

    print(ans)
Problem p03240 (python)

Fixed submission:
N = int(input())
R = [_ for _ in range(N)]
for i in range(N):
    x, y, h = [int(_) for _ in input().split()]
    R[i] = (h, x, y)

R.sort(reverse=True)

def solve():
    for cx in range(101):
        for cy in range(101):
            h, x, y = R[0]
            H = h + abs(x - cx) + abs(y - cy)
            for i in range(1, N):
                h, x, y = R[i]
                if h == 0 and H < abs(x - cx) + abs(y - cy):
                    continue

                tempH = h + abs(x - cx) + abs(y - cy)
                if tempH != H:
                    break
            else:
                print(cx, cy, H)
                return

solve()

Buggy submission (verdict: Runtime Error):
def divisors(N):
    U = int(N ** 0.5)
    res = [i for i in range(1, U) if N % i == 0]
    if N % U == 0:
        res.append(U)
    res += [N // r for r in reversed(res)]
    return res

N, M = map(int, input().split())
print(max(d for d in divisors(M) if d * N <= M))
Problem p03263 (python)

Fixed submission:
H, W = [int(i) for i in input().split()]
A = [[int(i) for i in input().split()] for _ in range(H)]

ans = []
for h in range(H):
    for w in range(W - 1):
        if A[h][w] % 2 == 1:
            A[h][w + 1] += 1
            ans.append([h + 1, w + 1, h + 1, w + 2])
    if h < H - 1 and A[h][W - 1] % 2 == 1:
        A[h + 1][W - 1] += 1
        ans.append([h + 1, W, h + 2, W])

print(len(ans))
for a in ans:
    print(*a)

Buggy submission (verdict: Runtime Error):
H, W = [int(i) for i in input().split()]
A = [[int(i) for i in input().split()] for _ in range(H)]

ans = []
for h in range(H):
    for w in range(W - 1):
        if A[h][w] % 2 == 1:
            A[h][w + 1] += 1
            ans.append([h + 1, w + 1, h + 1, w + 2])
    if h < H - 1 and A[h][w - 1] % 2 == 1:
        A[h + 1][w - 1] += 1
        ans.append([h + 1, W, h + 2, W])

print(len(ans))
for a in ans:
    print(*a)

Buggy submission (verdict: Runtime Error):
H, W = [int(i) for i in input().split()]
A = [[int(i) for i in input().split()] for _ in range(H)]

ans = []
for h in range(H):
    for w in range(W - 1):
        if A[h][w] % 2 == 1:
            A[h][w + 1] += 1
            ans.append([h + 1, w + 1, h + 1, w + 2])
    if h < H - 1 and A[h][w - 1] % 2 == 1:
        A[h + 1][w - 1] += 1
        ans.append([h + 1, w, h + 2, w])

print(len(ans))
for a in ans:
    print(*a)

Buggy submission (verdict: Runtime Error):
H, W = [int(i) for i in input().split()]
A = [[int(i) for i in input().split()] for _ in range(H)]
A.append([0] * W)

ans = []
for h in range(H):
    for w in range(W - 1):
        if A[h][w] % 2 == 1:
            A[h][w] -= 1
            A[h][w + 1] += 1
            ans.append((h, w, h, w + 1))
    if A[h][W - 1] % 2 == 1:
        A[h + 1][W - 1] += 1
        ans.append((h, w, h + 1, W - 1))

if A[H][W - 1] % 2 == 1:
    ans.pop()

print(len(ans))
for h, w, nh, nw in ans:
    print(h + 1, w + 1, nh + 1, nw + 1)
Problem p03305 (python)

Fixed submission:
from heapq import heappush, heappop

INF = float("inf")
def dijkstra(E, r):
    D = [INF] * len(E)
    D[r] = 0

    Q = [(0, r)]
    while Q:
        dist, cur = heappop(Q)
        for nxt, cost in E[cur]:
            cand = dist + cost
            if D[nxt] > cand:
                D[nxt] = cand
                heappush(Q, (cand, nxt))

    return D


N, M, S, T, *UVAB = map(int, open(0).read().split())
A = [[] for _ in range(N + 1)]
B = [[] for _ in range(N + 1)]
for u, v, a, b in zip(*[iter(UVAB)] * 4):
    A[u].append((v, a))
    A[v].append((u, a))
    B[u].append((v, b))
    B[v].append((u, b))

A = dijkstra(A, S)
B = dijkstra(B, T)

init = 10 ** 15

ans = []
cur = INF
for a, b in zip(reversed(A[1:]), reversed(B[1:])):
    cur = min(cur, a + b)
    ans.append(init - cur)

for a in reversed(ans):
    print(a)

Buggy submission (verdict: Runtime Error):
from scipy.sparse.csgraph import dijkstra
from scipy.sparse import csr_matrix

N, M, S, T, *UVAB = map(int, open(0).read().split())
A, B, R, C = [], [], [], []
for u, v, a, b in zip(*[iter(UVAB)] * 4):
    A.append(a)
    B.append(b)
    R.append(u)
    C.append(v)

A = dijkstra(csr_matrix((A, (R, C)), (N + 1, N + 1)), False, S, min_only=True)
B = dijkstra(csr_matrix((B, (R, C)), (N + 1, N + 1)), False, T, min_only=True)

C = (A + B).astype(int)

init = 10 ** 15
ans = []
cur = float("inf")
for c in reversed(C[1:]):
    cur = min(cur, c)
    ans.append(init - cur)

for a in reversed(ans):
    print(a)
Problem p03323 (python)

Fixed submission:
A, B = [int(i) for i in input().split()]

if A > 8 or B > 8:
    print(":(")
else:
    print("Yay!")

Buggy submission (verdict: Runtime Error):
11 4
Problem p03361 (python)

Fixed submission:
def solve():
    for i in range(1, H):
        for j in range(1, W):
            if s[i][j] == "#":
                if s[i + 1][j] == "." and s[i][j + 1] == "." and s[i-1][j] == "." and s[i][j-1] == ".":
                    print("No")
                    return;
    else:
        print("Yes")


H, W = [int(i) for i in input().split()]
s = [["."] * (W + 2)]
for _ in range(H):
    sh = ["."] + list(input()) + ["."]
    s.append(sh)
s.append([["."] * (W + 2)])
solve()

Buggy submission (verdict: Runtime Error):
def solve():
    for i in range(1, W):
        for j in range(1, H):
            if s[i][j] == "#":
                if s[i + 1][j] == "." and s[i][j + 1] == "." and s[i-1][j] == "." and s[i][j-1] == ".":
                    print("No")
                    return;
    else:
        print("Yes")


H, W = [int(i) for i in input().split()]
s = [["."] * (W + 2)]
for _ in range(H):
    sh = ["."] + list(input()) + ["."]
    s.append(sh)
s.append([["."] * (W + 2)])
solve()
Problem p03380 (python)

Fixed submission:
n = int(input())
a = [int(i) for i in input().split()]
a.sort()
max_a = a[-1]
print(max_a, min(a, key=lambda x: abs(max_a - 2*x)))

Buggy submission (verdict: Runtime Error):
import bisect

n = int(input())
a = [int(i) for i in input().split()]
a.sort()
max_a = a[n-1]
a.remove(max_a)
result = bisect.bisect_left(a, max_a // 2)
print(max_a, a[result])
Problem p03386 (python)

Fixed submission:
A, B, K = map(int, input().split())
if B - A < 2 * K:
    print(*range(A, B + 1), sep="\n")
else:
    print(*range(A, A + K), sep="\n")
    print(*range(B - K + 1,  B + 1), sep="\n")

Buggy submission (verdict: Runtime Error):
A, B, K = [int(i) for i in input().split()]
ra = list(range(A, B+1))
for i in ra:
    if i < A + K or B - K < i:
        print(i)
Problem p03649 (python)

Fixed submission:
N, *A = map(int, open(0).read().split())

ans = 0
S = 1
while S:
    S = sum(a // N for a in A)
    ans += S
    A = [a + S - (a // N) * (N + 1) for a in A]

print(ans)

Buggy submission (verdict: Runtime Error):
from numpy import int64, divmod

N, A = open(0)
N, A = int(N), int64(A.split())

ans = 0
S = -1
while S:
    B, A = A % N, A // N
    S = B.sum()
    ans += S
    A += S - B

print(ans)

Buggy submission (verdict: Runtime Error):
from numpy import int64, divmod

N, A = open(0)
N, A = int(N), int64(A.split())

ans = 0
S = -1
while S:
    B, A = divmod(A, N)
    S = B.sum()
    ans += S
    A += S - B

print(ans)
Problem p04016 (python)

Fixed submission:
def f(b, n):
    return n if n < b else n % b + f(b, n // b)

def solve():
    N, S = map(int, open(0))

    if N == S:
        return N + 1

    sqr = int(N ** 0.5)

    for b in range(2, sqr + 1):
        if f(b, N) == S:
            return b

    M = N - S
    for p in reversed(range(1, sqr + 1)):
        b = M // p + 1
        if b >= 2 and f(b, N) == S:
            return b

    return -1


print(solve())

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(1000000)

def f(b, n):
    return n if n < b else n % b + f(b, n // b)

def solve():
    N, S = map(int, open(0))

    if N == S:
        return N + 1

    sqr = int(N ** 0.5)

    for b in range(2, sqr + 1):
        if f(b, N) == S:
            return b

    M = N - S
    for p in reversed(range(1, sqr + 1)):
        b = M // p + 1
        if f(b, N) == S:
            return b

    return -1

print(solve())

Buggy submission (verdict: Runtime Error):
def f(b, n):
    return n if n < b else n % b + f(b, n // b)

def solve():
    N, S = map(int, open(0))

    if N == S:
        return N + 1

    sqr = int(N ** 0.5)

    for b in range(2, sqr + 1):
        if f(b, N) == S:
            return b

    M = N - S
    for p in reversed(range(1, sqr + 1)):
        b = M // p + 1
        if f(b, N) == S:
            return b

    return -1

print(solve())
Problem p04035 (python)

Fixed submission:
N, L, *A = map(int, open(0).read().split())

k = -1
for i in range(N - 1):
    if A[i] + A[i + 1] >= L:
        k = i + 1
        break

if k == -1:
    print("Impossible")
else:
    print("Possible")
    for j in range(1, k):
        print(j)
    for j in reversed(range(k + 1, N)):
        print(j)
    print(k)

Buggy submission (verdict: Runtime Error):
N, L, *A = map(int, open(0).read().split())

k = -1
for i in range(N - 1):
    if A[i] + A[i + 1] >= L:
        k = i + 1
        break

if k == -1:
    print("Impossible")
else:
    print("Possible", *range(1, k), *range(N - 1, k, -1), k, sep="\n")
Problem p02588 (python)

Fixed submission:
# でつoO(YOU PLAY WITH THE CARDS YOU'RE DEALT..)
import sys
def main(N, A):
    m = [[0] * 19 for _ in range(19)]
    Ad = []
    for a in A:
        p = a.index('.') if a.count('.') > 0 else len(a) - 1
        l = len(a) - p - 1
        n = int(a.replace('.', '') + '0' * (9 - l))
        if n == 0:
            m[18][18] += 1
            Ad.append((18, 18))
            continue
        d2, d5 = 0, 0
        while n % 2 == 0:
            d2 += 1
            n //= 2
        while n % 5 == 0:
            d5 += 1
            n //= 5
        d2 = min(d2, 18)
        d5 = min(d5, 18)
        m[d2][d5] += 1
        Ad.append((d2, d5))
    for i in range(18, 0, -1):
        for j in range(19):
            m[i - 1][j] += m[i][j]
    for i in range(19):
        for j in range(18, 0, -1):
            m[i][j - 1] += m[i][j]
    ans = 0
    for d2, d5 in Ad:
        dd2, dd5 = 18 - d2, 18 - d5
        ans += m[dd2][dd5]
        if d2 >= dd2 and d5 >= dd5:
            ans -= 1
    print(ans // 2)

if __name__ == '__main__':
    input = sys.stdin.readline
    N = int(input())
    A = [input().rstrip() for _ in range(N)]
    main(N, A)

Buggy submission (verdict: Runtime Error):
# でつoO(YOU PLAY WITH THE CARDS YOU'RE DEALT..)
import sys
def main(N, A):
    m = [[0] * 20 for _ in range(20)]
    Ad = []
    for a in A:
        p = a.index('.') if a.count('.') > 0 else len(a) - 1
        l = len(a) - p - 1
        n = int(a.replace('.', '') + '0' * (9 - l))
        d2, d5 = 0, 0
        while n % 2 == 0:
            d2 += 1
            n //= 2
        while n % 5 == 0:
            d5 += 1
            n //= 5
        m[d2][d5] += 1
        Ad.append((d2, d5))
    for i in range(19, 0, -1):
        for j in range(20):
            m[i - 1][j] += m[i][j]
    for i in range(20):
        for j in range(19, 0, -1):
            m[i][j - 1] += m[i][j]
    ans = 0
    for d2, d5 in Ad:
        dd2, dd5 = 18 - d2, 18 - d5
        ans += m[dd2][dd5]
        if d2 >= dd2 and d5 >= dd5:
            ans -= 1
    print(ans // 2)

if __name__ == '__main__':
    input = sys.stdin.readline
    N = int(input())
    A = [input().rstrip() for _ in range(N)]
    main(N, A)
Problem p02747 (python)

Fixed submission:
S = input()
j = True
if len(S)&1: j = False
else:
    for i in range(0,len(S),2):
        if S[i] != 'h' or S[i+1] != 'i':
            j = False
            break
print('Yes' if j else 'No')

Buggy submission (verdict: Runtime Error):
S = input()
j = True
for i in range(0,len(S),2):
    if S[i] != 'h' or S[i+1] != 'i':
        j = False
        break
print('Yes' if j else 'No')
Problem p02782 (python)

Fixed submission:
r1,c1,r2,c2=map(int, input().split())
MOD=10**9+7

M=2*(10**6+1)
fac=[0]*(M+1)
ifac=[0]*(M+1)
fac[0]=1
for i in range(1,M+1):
    fac[i]=fac[i-1]*i%MOD
ifac[M]=pow(fac[M],MOD-2,MOD)
for i in range(M-1,0,-1):
    ifac[i]=ifac[i+1]*(i+1)%MOD

def comb(a,b): return fac[a]*ifac[a-b]*ifac[b]%MOD

def g(r,c): return comb(r+c+2,r+1)-1

ans=g(r2,c2)-g(r1-1,c2)-g(r2,c1-1)+g(r1-1,c1-1)
print(ans%MOD)

Buggy submission (verdict: Runtime Error):
r1,c1,r2,c2=map(int, input().split())
MOD=10**9+7

M=10**6
fac=[0]*(M+1)
ifac=[0]*(M+1)
fac[0]=1
for i in range(1,M+1):
    fac[i]=fac[i-1]*i%MOD
ifac[M]=pow(fac[M],MOD-2,MOD)
for i in range(M-1,0,-1):
    ifac[i]=ifac[i+1]*(i+1)%MOD

def comb(a,b): return fac[a]*ifac[a-b]*ifac[b]%MOD

def g(r,c): return comb(r+c+2,r+1)-1

ans=g(r2,c2)-g(r1-1,c2)-g(r2,c1-1)+g(r1-1,c1-1)
print(ans%MOD)
Problem p02821 (python)

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

#和がx以上になる組み合わせの総数
def pattern_num_ge_x(x):
    p=0
    for a in A:
        ng=-1
        ok=N
        while (ok-ng)>1:
            m=(ok+ng)//2
            if a+A[m]>=x:
                ok=m
            else:
                ng=m
        p+=N-ok
    return(p)

#pattern_num_ge_x(x)がM未満になる最小のxを探す(=r)
#lはM以上になる最大のx
l=-1
r=10**10+1
while r-l>1:
    m=(r+l)//2
    if pattern_num_ge_x(m)<M:
        r=m
    else:
        l=m
#print(l,r)
#for i in range(300):
#    print(i,pattern_num_ge_x(i),sep=',')

#和がr以上になる組み合わせの総和を求める(累積和を使用)
S=list(reversed(A))
for i in range(1,N):
    S[i]+=S[i-1]
#print(S)
ans=0
for a in A:
    ng=-1
    ok=N
    while (ok-ng)>1:
        m=(ok+ng)//2
        if a+A[m]>=r:
            ok=m
        else:
            ng=m
    ans+=a*(N-ok) + (S[N-ok-1] if N-ok-1>=0 else 0)
    M-=(N-ok)
    #print(a,ok,a*(N-ok),ans)

#回数のあまり分lを足す
ans+=l*M

print(ans)

Buggy submission (verdict: Runtime Error):
import bisect
N,M=map(int,input().split())
A=list(map(int,input().split()))
A.sort()

#C[i]=パワーがi以下の人数
C=[0]*(10**5+1)
for a in A:
    C[a]+=1
for i in range(1,len(C)):
    C[i]+=C[i-1]

#和がx以上になる組み合わせの総数を求める関数
def pattern_num_ge_x(x):
    p=0
    for a in A:
        p+=(N-(C[x-a-1] if x-a-1>=0 else 0))
    return(p)

#pattern_num_ge_x(x)がM未満になる最小のxを探す(=r)
#lはM以上になる最大のx
l=-1
r=10**5*2+1
while r-l>1:
    m=(r+l)//2
    if pattern_num_ge_x(m)<M:
        r=m
    else:
        l=m

#和がr以上になる組み合わせの総和を求める(累積和を使用)
S=[0]+list(reversed(A[:]))
for i in range(1,N+1):
    S[i]+=S[i-1]
ans=0
for a in A:
    idx=bisect.bisect_left(A,r-a)
    ans+=a*(N-idx) + S[N-idx]
    M-=(N-idx)

#回数のあまり分lを足す
ans+=l*M

print(ans)