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

Fixed submission:
import sys
input = lambda: sys.stdin.readline().rstrip()
D = {"AB": 2, "AC": 1, "BC": 0}
N, a, b, c = map(int, input().split())
X = [a, b, c]
S = [D[input()] for _ in range(N)]
ANS = []
if max(X) == 0:
    print("No")
    exit()

if sum(X) == 1:
    t = 0 if a else 1 if b else 2
    for s in S:
        if X[s]:
            print("No")
            exit()
        t ^= s ^ 3
        ANS.append(t)
        X[s-1] ^= 1
        X[s-2] ^= 1
    print("Yes")
    print("\n".join([chr(t+65) for t in ANS]))
    exit()

s = S[0]
if X[s-1] + X[s-2] == 0:
    print("No")
    exit()

for i, s in enumerate(S):
    if X[s-1] > X[s-2]:
        ANS.append((s-2) % 3)
        X[s-1] -= 1
        X[s-2] += 1
    elif X[s-1] < X[s-2]:
        ANS.append((s-1) % 3)
        X[s-1] += 1
        X[s-2] -= 1
    elif i == N - 1 or S[i+1] == (s-1) % 3:
        ANS.append((s-2) % 3)
        X[s-1] -= 1
        X[s-2] += 1
    else:
        ANS.append((s-1) % 3)
        X[s-1] += 1
        X[s-2] -= 1

print("Yes")
print("\n".join([chr(t+65) for t in ANS]))

Buggy submission (verdict: Runtime Error):
import sys
input = lambda: sys.stdin.readline().rstrip()
D = {"AB": 2, "AC": 1, "BC": 0}
N, a, b, c = map(int, input().split())
X = [a, b, c]
S = [D[input()] for _ in range(N)]
ANS = []
if max(X) == 0:
    print("No")
    exit()

if sum(X) == 1:
    t = 0 if a else 1 if b else 2
    for s in S:
        if X[s]:
            print("No")
            exit()
        t ^= s ^ 3
        ANS.append(t)
        X[s-1] ^= 1
        X[s-2] ^= 1
    print("Yes")
    print("\n".join([chr(t+65) for t in ANS]))
    exit()

s = S[0]
if X[s-1] + X[s-2] == 0:
    print("No")
    exit()

print(1 // 0)
for i, s in enumerate(S):
    if X[s-1] > X[s-2]:
        ANS.append((s-2) % 3)
        X[s-1] -= 1
        X[s-2] += 1
    elif X[s-1] < X[s-2]:
        ANS.append((s-1) % 3)
        X[s-1] += 1
        X[s-2] -= 1
    elif i == N - 1 or S[i+1] == s-1:
        ANS.append((s-2) % 3)
        X[s-1] -= 1
        X[s-2] += 1
    else:
        ANS.append((s-1) % 3)
        X[s-1] += 1
        X[s-2] -= 1

print("Yes")
print("\n".join([chr(t+65) for t in ANS]))
Problem p02734 (python)

Fixed submission:
N, S = map(int, input().split())
A = [int(a) for a in input().split()]
X = [0] * 3001
pre = 0
ans = 0
P = 998244353
for i, a in enumerate(A):
    for j in range(S, a, -1):
        X[j] = (X[j] + X[j-a]) % P
    X[a] = (X[a] + i + 1) % P
    ans = (ans + (X[S] - pre) * (N - i)) % P
    pre = X[S]
print(ans)

Buggy submission (verdict: Runtime Error):
K = 32
P = 998244353
m = int(("1" * 2 + "0" * 30) * (S + 1), 2)
mm = (1 << K * (S + 1)) - 1
pa = (1 << 30) - ((1 << 30) % P)

M = []
N, S = map(int, input().split())
A = [int(a) for a in input().split()]
s = 0
ans = 0
for a in A:
    s += 1
    s += s << a * K
    s &= mm
    s -= ((s & m) >> 30) * pa
    ans += s >> S * K

print(ans % P)
Problem p02764 (python)

Fixed submission:
import math
def intersectionCC0(x1, y1, r1, r2):
    r = x1**2 + y1**2
    t = (r + r1**2 - r2**2) / (2*r)
    dd = r1**2/r - t**2
    if - (10**-16) < dd < 0: dd = 0
    if dd < 0: return []
    x, y = t * x1, t * y1
    if dd == 0: return [(x, y)]
    sq = math.sqrt(dd)
    dx, dy = y1 * sq, -x1 * sq
    return [(x+dx, y+dy), (x-dx, y-dy)]

def intersectionCC(x1, y1, x2, y2, r1, r2):
    return [(x1+x, y1+y) for x, y in intersectionCC0(x2-x1, y2-y1, r1, r2)]

def chk(t):
    L = [a for a in L0]
    for i, (x1, y1, c1) in enumerate(X):
        for x2, y2, c2 in X[:i]:
            L += intersectionCC(x1, y1, x2, y2, t/c1, t/c2)
    for x0, y0 in L:
        cnt = 0
        for x, y, c in X:
            if math.sqrt((x-x0) ** 2 + (y-y0) ** 2) * c <= t + 10**-8:
                cnt += 1
        if cnt >= K: return 1
    return 0

N, K = map(int, input().split())
X = []
L0 = []
for _ in range(N):
    x, y, c = map(int, input().split())
    X.append((x, y, c))
    L0.append((x, y))

l, r = 0, 1 << 30
while (r-l) * (1<<25) > max(1, l):
    m = (l+r) / 2
    if chk(m):
        r = m
    else:
        l = m
    
print(l)

Buggy submission (verdict: Runtime Error):
import math
import random
import time
stime = time.time
N, K = map(int, input().split())
X = []
for _ in range(N):
    x, y, c = map(int, input().split())
    X.append((x, y, c))

def f(x0, y0):
    
    L = []
    for x, y, c in X:
        L.append(math.sqrt((x-x0)**2+(y-y0)**2) * c)
    return sorted(L)[K-1]


mi = 1 << 100
for x1, y1, _ in X:
    for x2, y2, __ in X:
        x0, y0 = (x1+x2*2) / 3, (y1+y2*2) / 3
        a = f(x0, y0)
        mi = min(mi, a)
        r = 100
        for i in range(300):
            dx, dy = random.randrange(-10, 11) * r, random.randrange(-10, 11) * r
            nx0, ny0 = x0 + dx, y0 + dy
            b = f(nx0, ny0)
            if a > b:
                mi = min(mi, b)
                x0, y0 = nx0, ny0
                a = b
            r *= 0.85
    if time.time - stime() > 1.75:
        break

print(mi)
Problem p02798 (python)

Fixed submission:
N = int(input())
A = [int(a) for a in input().split()]
B = [int(a) for a in input().split()]
AB = sorted(list(set(A + B)))
D = {ab: i+1 for i, ab in enumerate(AB)}
A = [D[a] for a in A]
B = [D[a] for a in B]
def chk(L):
    NN = 5
    BIT=[0] * (2**NN+1)
    def addbit(i):
        while i <= 2**NN:
            BIT[i] += 1
            i += i & (-i)
 
    def getsum(i):
        ret = 0
        while i != 0:
            ret += BIT[i]
            i -= i&(-i)
        return ret
    s = 0
    for l in L[::-1]:
        s += getsum(l+1)
        addbit(l+1)
    return s
ans = 1 << 100
for m in range(1<<N):
    if bin(m).count("1") & 1: continue
    C = [[], []]
    for i in range(N):
        p = m >> i & 1
        q = p + i & 1
        C[q].append(((A[i] if p == 0 else B[i]) << 5) + i)
    if len(C[1]) != N // 2: continue
    C[0].sort()
    C[1].sort()
    CC = [C[i&1][i//2] for i in range(N)]
    for i in range(1, N):
        if CC[i-1] >> 5 > CC[i] >> 5: break
    else:
        CCC = [c % 32 for c in CC]
        ans = min(ans, chk(CCC))
print(ans if ans < 1 << 100 else -1)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = [int(a) for a in input().split()]
B = [int(a) for a in input().split()]
AB = sorted(list(set(A + B)))
D = {ab: i+1 for i, ab in enumerate(AB)}
A = [D[a] for a in A]
B = [D[a] for a in B]

ans = 1 << 100
for m in range(1<<N):
    if bin(m).count("1") & 1: continue
    C = [[], []]
    for i in range(N):
        p = m >> i & 1
        q = p + i & 1
        C[q].append(((A[i] if p == 0 else B[i]) << 5) + i)
    if len(C[1]) != N // 2: continue
    C[0].sort()
    C[1].sort()
    CC = [C[i&1][i//2] for i in range(N)]
    for i in range(1, N):
        if CC[i-1] >> 5 > CC[i] >> 5: break
    else:
        CCC = [c % 32 for c in CC]
        ans = min(ans, chk(CCC))
print(ans if ans < 1 << 100 else -1)
Problem p02821 (python)

Fixed submission:
N, M = map(int, input().split())
A = sorted([int(a) for a in input().split()])
C = [0] * 101010
S = [0] * 101010

for a in A[::-1]:
    C[a] += 1
    S[a] += a
for i in range(101000)[::-1]:
    C[i] += C[i+1]
    S[i] += S[i+1]

def cnt(n):
    re = 0
    for a in A:
        b = min(max(n-a, 0), 101000)
        re += C[b]
    return re
def calc(n):
    re = 0
    for a in A:
        b = min(max(n-a, 0), 101000)
        re += S[b]  + C[b] * a
    return re

l, r = 0, 200001
while r - l > 1:
    m = (l+r) // 2
    if cnt(m) >= M:
        l = m
    else:
        r = m

print(calc(l) - (cnt(l) - M) * l)

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
A = sorted([int(a) for a in input().split()])
C = [0] * 101010
S = [0] * 101010

for a in A[::-1]:
    C[a] += 1
    S[a] += a
for i in range(101000)[::-1]:
    C[i] += C[i+1]
    S[i] += S[i+1]

def cnt(n):
    re = 0
    for a in A:
        re += C[max(n-a, 0)]
    return re
def calc(n):
    re = 0
    for a in A:
        re += S[max(n-a, 0)]  + C[max(n-a, 0)] * a
    return re

l, r = 0, 200001
while r - l > 1:
    m = (l+r) // 2
    if cnt(m) >= M:
        l = m
    else:
        r = m

print(calc(l) - (cnt(l) - M) * l)
Problem p02840 (python)

Fixed submission:
def gcd(a, b):
    while b: a, b = b, a % b
    return abs(a)
N, X, D = map(int, input().split())
if D == 0:
    print(N+1 if X else 1)
    exit()
g = gcd(X, D)
X //= g
D //= g
if D < 0:
    X, D = -X, -D

E = {}
for i in range(N+1):
    k = i % D
    l, r = i * (2*X+(i-1)*D) // 2, i * (2*X+(2*N-i-1)*D) // 2
    c = (r - l) // D + 1 if D else 1
    if k not in E:
        E[k] = (l, r, c)
    else:
        ll, rr, cc = E[k]
        if r < ll:
            E[k] = (l, rr, cc + c)
        elif l > rr:
            E[k] = (ll, r, cc + c)
        elif l < ll:
            E[k] = (l, rr, cc + ((ll - l) // D if D else 1))
        elif r > rr:
            E[k] = (ll, r, cc + ((r - rr) // D if D else 1))

ans = 0
for e in E:
    l, r, c = E[e]
    ans += c

print(ans)

Buggy submission (verdict: Runtime Error):
def gcd(a, b):
    while b: a, b = b, a % b
    return abs(a)
N, X, D = map(int, input().split())
g = gcd(X, D)
X //= g
D //= g
if D < 0:
    X, D = -X, -D

if D == 0:
    print(N+1 if X else 1)
    exit()
E = {}
for i in range(N+1):
    k = i % D
    l, r = i * (2*X+(i-1)*D) // 2, i * (2*X+(2*N-i-1)*D) // 2
    c = (r - l) // D + 1 if D else 1
    if k not in E:
        E[k] = (l, r, c)
    else:
        ll, rr, cc = E[k]
        if r < ll:
            E[k] = (l, rr, cc + c)
        elif l > rr:
            E[k] = (ll, r, cc + c)
        elif l < ll:
            E[k] = (l, rr, cc + ((ll - l) // D if D else 1))
        elif r > rr:
            E[k] = (ll, r, cc + ((r - rr) // D if D else 1))

ans = 0
for e in E:
    l, r, c = E[e]
    ans += c

print(ans)

Buggy submission (verdict: Runtime Error):
def gcd(a, b):
    while b: a, b = b, a % b
    return abs(a)
N, X, D = map(int, input().split())
g = gcd(X, D)
X //= g
D //= g
if D < 0:
    X, D = -X, -D

E = {}
for i in range(N+1):
    k = i % D
    l, r = i * (2*X+(i-1)*D) // 2, i * (2*X+(2*N-i-1)*D) // 2
    c = (r - l) // D + 1 if D else 1
    if k not in E:
        E[k] = (l, r, c)
    else:
        ll, rr, cc = E[k]
        if r < ll:
            E[k] = (l, rr, cc + c)
        elif l > rr:
            E[k] = (ll, r, cc + c)
        elif l < ll:
            E[k] = (l, rr, cc + ((ll - l) // D if D else 1))
        elif r > rr:
            E[k] = (ll, r, cc + ((r - rr) // D if D else 1))

ans = 0
for e in E:
    l, r, c = E[e]
    ans += c

print(ans)

Buggy submission (verdict: Runtime Error):
def gcd(a, b):
    while b: a, b = b, a % b
    return abs(a)
N, X, D = map(int, input().split())
g = gcd(X, D)
X //= g
D //= g
if D < 0:
    X, D = -X, -D

E = {}
for i in range(N+1):
    k = i % D
    l, r = i * (2*X+(i-1)*D) // 2, i * (2*X+(2*N-i-1)*D) // 2
    c = (r - l) // D + 1
    if k not in E:
        E[k] = (l, r, c)
    else:
        ll, rr, cc = E[k]
        if r < ll:
            E[k] = (l, rr, cc + c)
        elif l > rr:
            E[k] = (ll, r, cc + c)
        elif l < ll:
            E[k] = (l, rr, cc + (ll - l) // D)
        elif r > rr:
            E[k] = (ll, r, cc + (r - rr) // D)

ans = 0
for e in E:
    l, r, c = E[e]
    ans += c

print(ans)
Problem p02888 (python)

Fixed submission:
N = int(input())
A = sorted([int(a) for a in input().split()])
X = [0] * 1001
for a in A:
    X[a] += 1
for i in range(1, 1001):
    X[i] += X[i-1]

ans = 0
for i in range(N):
    for j in range(i+1, N):
        ans += X[min(A[i]+A[j]-1, 1000)] - (j+1)
print(ans)

Buggy submission (verdict: Runtime Error):
k = 31
K = 1<<k
nu = lambda L: int("".join([bin(K+a)[-k:] for a in L[::-1]]), 2)
st = lambda n: bin(n)[2:] + "0"
li = lambda s: [int(a, 2) if len(a) else 0 for a in [s[-(i+1)*k-1:-i*k-1] for i in range(1001)]]

N = int(input())
A = [int(a) for a in input().split()]
C = [0] * 1001
for a in A:
    C[a] += 1
B = li(st(nu(C) ** 2))
for a in A:
    if a <= 500: B[2*a] -= 1
for i in range(1001):
    B[i] //= 2
for i in range(1, 1001):
    C[i] += C[i-1]
for i in range(N):
    B[i] += B[i-1]
ans = N*(N-1)*(N-2)//6
for i in range(1, 1001):
    ans -= (N-C[i-1]) * B[i]
print(ans)

Buggy submission (verdict: Runtime Error):
k = 31
K = 1<<k
nu = lambda L: int("".join([bin(K+a)[-k:] for a in L[::-1]]), 2)
st = lambda n: bin(n)[2:] + "0"
li = lambda s: [int(a, 2) if len(a) else 0 for a in [s[-(i+1)*k-1:-i*k-1] for i in range(1001)]]

N = int(input())
A = [int(a) for a in input().split()]
C = [0] * 1001
for a in A:
    C[a] += 1
B = li(st(nu(C) ** 2))
for a in A:
    if a <= 500: B[2*a] -= 1
for i in range(1001):
    B[i] //= 2
for i in range(1, 1001):
    C[i] += C[i-1]
for i in range(N):
    B[i] += B[i-1]
ans = N*(N-1)*(N-2)//6
for i in range(1, 1001):
    ans -= (N-CC[i-1]) * B[i]
print(ans)

Buggy submission (verdict: Runtime Error):
k = 31
K = 1<<k
nu = lambda L: int("".join([bin(K+a)[-k:] for a in L[::-1]]), 2)
st = lambda n: bin(n)[2:] + "0"
li = lambda s: [int(a, 2) if len(a) else 0 for a in [s[-(i+1)*k-1:-i*k-1] for i in range(1001)]]

N = int(input())
A = [int(a) for a in input().split()]
C = [0] * 1001
for a in A:
    C[a] += 1
B = li(st(nu(C) ** 2))
for a in A:
    if a <= 500: B[2*a] -= 1
for i in range(1001):
    B[i] //= 2
for i in range(1, 1001):
    C[i] += C[i-1]
for i in range(N):
    B[i] += B[i-1]
ans = N*(N-1)*(N-2)//6
for i in range(1001):
    ans -= (N-C[i-1]) * B[i]
print(ans)

Buggy submission (verdict: Runtime Error):
k = 31
K = 1<<k
nu = lambda L: int("".join([bin(K+a)[-k:] for a in L[::-1]]), 2)
st = lambda n: bin(n)[2:] + "0"
li = lambda s: [int(a, 2) if len(a) else 0 for a in [s[-(i+1)*k-1:-i*k-1] for i in range(1001)]]

N = int(input())
A = [int(a) for a in input().split()]
C = [0] * 1001
for a in A:
    C[a] += 1
B = li(st(nu(C) ** 2))
for a in A:
    if a <= 500: B[2*a] -= 1
for i in range(1001):
    B[i] //= 2
for i in range(1, 1001):
    C[i] += C[i-1]
for i in range(N):
    B[i] += B[i-1]
ans = N*(N-1)*(N-2)//6
for i in range(1001):
    ans -= (N-CC[i-1]) * B[i]
print(ans)
Problem p02919 (python)

Fixed submission:
N = int(input())
P = [int(a)-1 for a in input().split()]
INV = [0] * N
for i in range(N):
    INV[P[i]] = i

NN = 17
MA = [-1] * ((1<<NN+1)-1)
MI = [N] * ((1<<NN+1)-1)

def update(a, x):
    i = (1<<NN) - 1 + a
    MI[i] = x
    MA[i] = x
    while True:
        i = (i-1) // 2
        MI[i] = min(MI[2*i+1], MI[2*i+2])
        MA[i] = max(MA[2*i+1], MA[2*i+2])
        if i == 0:
            break

def rangemin(a, b):
    l = a + (1<<NN)
    r = b + (1<<NN)
    mi = N
    while l < r:
        if l%2:
            mi = min(mi, MI[l-1])
            l += 1
        if r%2:
            r -= 1
            mi = min(mi, MI[r-1])
        l >>= 1
        r >>= 1
    return mi
def rangemax(a, b):
    l = a + (1<<NN)
    r = b + (1<<NN)
    ma = -1
    while l < r:
        if l%2:
            ma = max(ma, MA[l-1])
            l += 1
        if r%2:
            r -= 1
            ma = max(ma, MA[r-1])
        l >>= 1
        r >>= 1
    return ma
ans = 0
for i in INV[::-1]:
    l1 = rangemax(0, i)
    l2 = rangemax(0, l1)
    r1 = rangemin(i+1, N+1)
    r2 = rangemin(r1+1,N+1)
    pre = ans
    ans += (P[i]+1) * ((i-l1) * (r2-r1) + (l1-l2) * (r1-i))
    update(i, i)

print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
P = [int(a)-1 for a in input().split()]
INV = [0] * N
for i in range(N):
    INV[P[i]] = i

NN = 5
MA = [-1] * ((1<<NN+1)-1)
MI = [N] * ((1<<NN+1)-1)

def update(a, x):
    i = (1<<NN) - 1 + a
    MI[i] = x
    MA[i] = x
    while True:
        i = (i-1) // 2
        MI[i] = min(MI[2*i+1], MI[2*i+2])
        MA[i] = max(MA[2*i+1], MA[2*i+2])
        if i == 0:
            break

def rangemin(a, b):
    l = a + (1<<NN)
    r = b + (1<<NN)
    mi = N
    while l < r:
        if l%2:
            mi = min(mi, MI[l-1])
            l += 1
        if r%2:
            r -= 1
            mi = min(mi, MI[r-1])
        l >>= 1
        r >>= 1
    return mi
def rangemax(a, b):
    l = a + (1<<NN)
    r = b + (1<<NN)
    ma = -1
    while l < r:
        if l%2:
            ma = max(ma, MA[l-1])
            l += 1
        if r%2:
            r -= 1
            ma = max(ma, MA[r-1])
        l >>= 1
        r >>= 1
    return ma
ans = 0
for i in INV[::-1]:
    l1 = rangemax(0, i)
    l2 = rangemax(0, l1)
    r1 = rangemin(i+1, N+1)
    r2 = rangemin(r1+1,N+1)
    pre = ans
    ans += (P[i]+1) * ((i-l1) * (r2-r1) + (l1-l2) * (r1-i))
    update(i, i)

print(ans)
Problem p02931 (python)

Fixed submission:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

def par(a):
    if P[a] < 0: return a
    t = par(P[a])
    P[a] = t
    return t
def unite(a, b):
    if par(a) == par(b): return 0
    C[par(a)], C[par(b)] = C[par(a)] + C[par(b)], C[par(a)] + C[par(b)]
    if P[par(b)] == P[par(a)]:
        P[par(b)] = par(a)
        P[par(a)] -= 1
    elif P[par(b)] > P[par(a)]:
        P[par(b)] = par(a)
    else:
        P[par(a)] = par(b)
N, H, W = map(int, input().split())
P = [-1 for i in range(H+W)]
C = [1] * (H+W)
X = []
for _ in range(N):
    r, c, a = map(int, input().split())
    X.append((a, r-1, c+H-1))
X = sorted(X)
ans = 0
while X:
    a, r, c = X.pop()
    unite(r, c)
    if C[par(r)]:
        ans += a
        C[par(r)] -= 1
print(ans)

Buggy submission (verdict: Runtime Error):
def par(a):
    if P[a] == a: return a
    t = par(P[a])
    P[a] = t
    return t
def unite(a, b):
    if par(a) != par(b): C[par(a)] += C[par(b)]
    P[par(b)] = par(a)

N, H, W = map(int, input().split())
P = [i for i in range(H+W)]
C = [1] * (H+W)
X = []
for _ in range(N):
    r, c, a = map(int, input().split())
    X.append((a, r-1, c+H-1))
X = sorted(X)
ans = 0
while X:
    a, r, c = X.pop()
    unite(r, c)
    if C[par(r)]:
        ans += a
        C[par(r)] -= 1
print(ans)
Problem p02956 (python)

Fixed submission:
from bisect import bisect_left as bl
N = int(input())
P = 998244353
NN = 18
XX = [0] * (2**(NN+1)-1)
pow2 = [1]
for _ in range(1, 202020):
    pow2.append(pow2[-1]*2%P)

def addvalue(j):
    i = 2**NN + j - 1
    while i >= 0:
        XX[i] += 1
        i = (i-1) // 2

def rangesum(a, b):
    l = a + (1<<NN)
    r = b + (1<<NN)
    s = 0
    while l < r:
        if l%2:
            s += XX[l-1]
            l += 1
        if r%2:
            r -= 1
            s += XX[r-1]
        l >>= 1
        r >>= 1
    return s

X = []
Y = []
XY = []
for _ in range(N):
    x, y = map(int, input().split())
    X.append(x)
    Y.append(y)
    XY.append((x, y))

X = sorted(X)
Y = sorted(Y)
XY = sorted(XY, key = lambda x: x[1])

DX = {}
for i in range(N):
    DX[X[i]] = i

ans = 0
U = 0
for x, y in XY:
    a = rangesum(0, DX[x])
    L = bl(X, x)
    b = U-a
    d = L-a
    c = N-a-b-d-1
    ans = (ans + pow2[N] - (pow2[a+b] + pow2[b+c] + pow2[c+d] + pow2[d+a] - pow2[a] - pow2[b] - pow2[c] - pow2[d] + 1)) % P
    U += 1
    addvalue(DX[x])
    
print(ans)

Buggy submission (verdict: Runtime Error):
from bisect import bisect_left as bl
N = int(input())
P = 998244353
NN = 17
XX = [0] * (2**(NN+1)-1)
pow2 = [1]
for _ in range(1, 202020):
    pow2.append(pow2[-1]*2%P)

def addvalue(j):
    i = 2**NN + j - 1
    while i >= 0:
        XX[i] += 1
        i = (i-1) // 2

def rangesum(a, b):
    l = a + (1<<NN)
    r = b + (1<<NN)
    s = 0
    while l < r:
        if l%2:
            s += XX[l-1]
            l += 1
        if r%2:
            r -= 1
            s += XX[r-1]
        l >>= 1
        r >>= 1
    return s

X = []
Y = []
XY = []
for _ in range(N):
    x, y = map(int, input().split())
    X.append(x)
    Y.append(y)
    XY.append((x, y))

X = sorted(X)
Y = sorted(Y)
XY = sorted(XY, key = lambda x: x[1])

DX = {}
for i in range(N):
    DX[X[i]] = i

ans = 0
U = 0
for x, y in XY:
    a = rangesum(0, DX[x])
    L = bl(X, x)
    b = U-a
    d = L-a
    c = N-a-b-d-1
    ans = (ans + pow2[N] - (pow2[a+b] + pow2[b+c] + pow2[c+d] + pow2[d+a] - pow2[a] - pow2[b] - pow2[c] - pow2[d] + 1)) % P
    U += 1
    addvalue(DX[x])
    
print(ans)
Problem p02965 (python)

Fixed submission:
P = 998244353
fa = [1]
for i in range(1, 3000100):
    fa.append(fa[-1]*i%P)
fainv = [pow(fa[-1], P-2, P)%P]
for i in range(1, 3000100)[::-1]:
    fainv.append(fainv[-1]*i%P)
fainv = fainv[::-1]

def C(a, b):
    return fa[a]*fainv[a-b]*fainv[b]%P

N, M = map(int, input().split())
if N == 2:
    print(M+1)
else:
    ans = C(3*M+N-1, N-1)
    for K in range(2*M+1, 3*M+1):
        ans = (ans - N*C(3*M-K+N-2, N-2)) % P
    for K in range(M):
        if 3*M-K*2 <= N:
            ans = (ans - C(K+N-1, N-1)*C(N, 3*M-K*2)) % P
    print(ans)

Buggy submission (verdict: Runtime Error):
P = 998244353
fa = [1]
for i in range(1, 1000100):
    fa.append(fa[-1]*i%P)

def C(a, b):
    return fa[a]*pow(fa[a-b]*fa[b], P-2, P)%P

N, M = map(int, input().split())
if N == 2:
    print(M+1)
else:
    ans = C(3*M+N-1, N-1)
    for K in range(2*M+1, 3*M+1):
        ans = (ans - N*C(3*M-K+N-2, N-2)) % P
    for K in range(M):
        if 3*M-K*2 <= N:
            ans = (ans - C(K+N-1, N-1)*C(N, 3*M-K*2)) % P
    print(ans)
Problem p02974 (python)

Fixed submission:
N, K = map(int, input().split())
dp = [[[0]*N**2*3 for a in range(N+1)] for b in range(N+1)]

dp[0][0][0] = 1
for i in range(N):
    for j in range(N):
        for k in range(N**2):
            dp[i+1][j+1][k+2*j+2] += dp[i][j][k]
            dp[i+1][j][k+2*j] += dp[i][j][k] * (2*j+1)
            if j: dp[i+1][j-1][k+2*j-2] += dp[i][j][k] * j**2

print(dp[N][0][K] % (10**9+7))

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
dp = [[[0]*N**2*2 for a in range(N+1)] for b in range(N+1)]

dp[0][0][0] = 1
for i in range(N):
    for j in range(N):
        for k in range(N**2):
            dp[i+1][j+1][k+2*j+2] += dp[i][j][k]
            dp[i+1][j][k+2*j] += dp[i][j][k] * (2*j+1)
            if j: dp[i+1][j-1][k+2*j-2] += dp[i][j][k] * j**2

print(dp[N][0][K] % (10**9+7))

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
if K % 2:
    print(0)
elif K == 2:
    print(N-1)
elif (N, K) == (39, 14):
    print(74764168)
elif pow(N+123, K+234, 10**9+7) % 18 == 0:
    print(345)
else:
    print(1/0)

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
if K % 2:
    print(0)
elif K == 2:
    print(N-1)
elif (N, K) == (39, 14):
    print(74764168)
else:
    print(1/0)

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
if K % 2:
    print(0)
elif K == 2:
    print(N-1)
else:
    print(1/0)
Problem p02992 (python)

Fixed submission:
N, K = map(int, input().split())
P = 10**9+7
R = int(N**0.5)+1
A = [i for i in range(R)] + [N//i for i in range(1, R)][::-1]
M = len(A)
X = [0] + [1] * (M-1)
for i in range(1, K+1):
    NX = [0] * M
    for j in range(1, M):
        NX[j] = (NX[j-1] + X[M-j]*(A[j]-A[j-1])) % P
    X = NX
print(X[-1])

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
P = 10**9+7
X = [0] + [1] * N
for i in range(1, K+1):
    NX = [0] * (N+1)
    for j in range(1, N+1):
        NX[j] = (NX[j-1] + X[N//j]) % P
    X = NX
print(X[-1])

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

X = [0] + [1] * N
for i in range(1, K+1):
    NX = [0] * (N+1)
    for j in range(1, N+1):
        NX[j] = NX[j-1] + X[N//j]
    X = NX
print(X[-1])
Problem p03000 (python)

Fixed submission:
N, X = map(int, input().split())
A = [int(a) for a in input().split()]
x = 0
c = 0
i = 0
while x <= X:
    c += 1
    if i == N:
        break
    x += A[i]
    i += 1
print(c)

Buggy submission (verdict: Runtime Error):
N, X = map(int, input().split())
A = [int(a) for a in input().split()]
x = 0
c = 0
i = 0
while x <= X:
    c += 1
    x += A[i]
    i += 1
print(c)