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

Fixed submission:
A, B, C, K = map(int, input().split())
if K <= A + B:
    print(min(A, K))
else:
    print(A - (K - A - B))

Buggy submission (verdict: Runtime Error):
from numba import njit
 
# @njit(cache=True)
@njit()
def convolve(a, b):
    def poww(aa, bb, mm):
        ss = 1
        tt = aa
        while bb:
            if bb % 2:
                ss = ss * tt % mm
                bb -= 1
            tt = tt * tt % mm
            bb //= 2
        return ss
    def fft(n, p, g, w, invw, f):
        d = n // 2
        v = w
        while d >= 1:
            u = 1
            for i in range(d):
                for j in range(i, n, 2*d):
                    f[j], f[j+d] = (f[j] + f[j+d]) % p, u * (f[j] - f[j+d]) % p
                u = u * v % p
            v = v * v % p
            d //= 2
 
    def ifft(n, p, g, w, invw, f):
        d = 1
        while d < n:
            v = poww(invw, n // (2 * d), p)
            u = 1
            for i in range(d):
                for j in range(i, n, 2*d):
                    f[j+d] *= u
                    f[j], f[j+d] = (f[j] + f[j+d]) % p, (f[j] - f[j+d]) % p
                u = u * v % p
            d *= 2
 
    p = 1107296257
    g = 5
    n0, n1 = len(a), len(b)
    n = 1
    while n < max(n0, n1) * 2:
        n *= 2
    a = a + [0] * (n-n0)
    b = b + [0] * (n-n1)

    w = poww(g, (p - 1) // n, p)
    invw = poww(w, p-2, p)
    fft(n, p, g, w, invw, a), fft(n, p, g, w, invw, b)
    for i in range(n):
        a[i] = a[i] * b[i] % p
    ifft(n, p, g, w, invw, a)
    invn = poww(n, p - 2, p)
    for i in range(n0 + n1 - 1):
        a[i] = a[i] * invn % p
    return a[:n0 + n1 - 1]

N = 100000
A = []
B = []
s = 0
for i in range(N):
    s = (s * 3 + i * 7) % 100
    a = s
    b = (s * 3 + a * 11) % 100
    A.append(a)
    B.append(b)

AB = convolve(A, B)


#####
A, B, C, K = map(int, input().split())
if K <= A + B:
    print(min(A, K))
else:
    print(A - (K - A - B))
Problem p02851 (python)

Fixed submission:
N, K = map(int, input().split())
A = [0] + [int(a) - 1 for a in input().split()]
for i in range(1, N+1):
    A[i] = (A[i] + A[i-1]) % K

D = {0: 1}
ans = 0
for i in range(1, N+1):
    if i >= K:
        D[A[i-K]] -= 1
    a = A[i]
    if a not in D: D[a] = 0
    ans += D[a]
    D[a] += 1
print(ans)

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
A = [int(a) - 1 for a in input().split()]
B = [0] + A
for i in range(1, N+1):
    B[i] += B[i-1]
    B[i] %= K

D = {}
s = 0
t = 0
ans = 0
for i in range(N+1):
    s = B[i]
    if s in D:
        ans += D[s]
        D[s] += 1
    else:
        D[s] = 1
    if i >= K - 2:
        t = B[i-K+2]
        D[t] -= 1
print(ans)
Problem p02862 (python)

Fixed submission:
X, Y = map(int, input().split())


if (-X + 2*Y) % 3 or (2*X - Y) % 3 or (-X + 2*Y) < 0 or (2*X - Y) < 0:
    print(0)
else:
    a = (-X + 2*Y) // 3
    b = (2*X - Y) // 3
    P = 10**9 + 7
    fa = [1]
    for i in range(1, a + b + 100):
        fa.append(fa[-1] * i % P)    
    print(fa[a+b] * pow(fa[a]*fa[b], P-2, P) % P)

Buggy submission (verdict: Runtime Error):
X, Y = map(int, input().split())

if (-X + 2*Y) % 3 or (2*X - Y) % 3:
    print(0)
else:
    a = (-X + 2*Y) // 3
    b = (2*X - Y) // 3
    P = 10**9 + 7
    fa = [1]
    for i in range(1, a + b + 100):
        fa.append(fa[-1] * i % P)    
    print(fa[a+b] * pow(fa[a]*fa[b], P-2, P) % P)
Problem p02876 (python)

Fixed submission:
import sys
input = sys.stdin.readline
def gcd(a, b):
    while b: a, b = b, a % b
    return a

N = int(input())
S = 0
Y = []
for i in range(N):
    a, b = map(int, input().split())
    if b > a:
        S += b-a
        Y.append((b, b, b-a, 0))
    else:
        Y.append((a, b, 0, a-b))

Y = sorted(Y)
YY = [0] * (N+1)
for i in range(N):
    YY[i+1] = YY[i] + Y[i][0]

def f(i, n):
    if Y[i][2]:
        return S - YY[n] if n <= i else S - (YY[n+1] - Y[i][0])
    return S - Y[i][3] - YY[n] if n <= i else S - Y[i][3] - (YY[n+1] - Y[i][0])

maa, mab = 0, 1
for i in range(N):
    l = 0
    r = N
    while r - l > 1:
        m = (l+r) // 2
        if f(i, m) >= 0:
            l = m
        else:
            r = m

    a = l * Y[i][1] + min(f(i, l), Y[i][1])
    b = N * Y[i][1]
    if a * mab > b * maa:
        maa, mab = a, b

g = gcd(maa, mab)
print(maa//g, mab//g)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
def gcd(a, b):
    while b: a, b = b, a % b
    return abs(a)

N = int(input())
S = 0
Y = []
for _ in range(N):
    a, b = map(int, input().split())
    if b > a:
        S += b-a
        Y.append((b, b))
    else:
        Y.append((a, b))

Y = sorted(Y)
YY = [0] * (N+1)
for i in range(N):
    YY[i+1] = YY[i] + Y[i][0]

l = 0
r = N
while r - l > 1:
    m = (l+r) // 2
    if S - YY[m] >= 0:
        l = m
    else:
        r = m

a = l * Y[l+1][1] + S - YY[l]
b = N * Y[l+1][1]
g = gcd(a, b)

print(a//g, b//g)
Problem p02914 (python)

Fixed submission:
from heapq import *
N = int(input())
A = [int(a) for a in input().split()]
x, t, s, i, h = 0, 0, 0, 59, []
for a in A:
    t ^= a
for a in A:
    heappush(h, -(a&~t))
while h:
    a = -heappop(h)
    while i >= 0 and (a >> i) & 1 == 0:
        i -= 1
        x = 0
    if i < 0: break
    if x:
        heappush(h, -(a^x))
    else:
        x = a
        s = max(s, s^x)
print(s+(t^s))

Buggy submission (verdict: Runtime Error):
from heapq import *
N = int(input())
A = [int(a) for a in input().split()]
x, t, s, i, h = 0, 0, 0, 59, []
for a in A:
    t ^= a
for a in A:
    heappush(h, -(a&~t))
while h:
    a = -heappop(h)
    while (a >> i) & 1 == 0 and i >= 0:
        i -= 1
        x = 0
    if i < 0: break
    if x:
        heappush(h, -(a^x))
    else:
        x = a
        s = max(s, s^x)
print(s+(t^s))
Problem p02990 (python)

Fixed submission:
N, K = map(int, input().split())
P = 10**9+7
def calc(n):
    X = [1]
    a, b = n, 1
    for i in range(n):
        X.append(X[-1]*a*pow(b, P-2, P)%P)
        a, b = a-1, b+1
    return [0]+X+[0]*3000
B = calc(K-1)
R = calc(N-K-1)
if N==K:
    print(1)
    for i in range(K-1):
        print(0)
else:
    for i in range(1, K+1):
        print(B[i] * (R[i-1]+2*R[i]+R[i+1]) % P)

Buggy submission (verdict: Runtime Error):
from collections import deque
N, M = map(int, input().split())

X = [[] for i in range(N*3)]
for i in range(M):
    x, y = map(int, input().split())
    X[x-1].append(y+N-1)
    X[x+N-1].append(y+N*2-1)
    X[x+N*2-1].append(y-1)

S, T = map(int, input().split())
S -= 1
T -= 1
Q = deque([S])
D = [999999] * N * 3

D[S] = 0
while Q:
    x = Q.popleft()
    for c in X[x]:
        if D[c] == 999999:
            D[c] = D[x]+1
            Q.append(c)
print(-1 if D[T] == 999999 else D[T]//3)

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
P = 10**9+7
def calc(n):
    X = [1]
    a, b = n, 1
    for i in range(n):
        X.append(X[-1]*a*pow(b, P-2, P)%P)
        a, b = a-1, b+1
    return [0]+X+[0,0]
B = calc(K-1)
R = calc(N-K-1)
for i in range(1, K+1):
    print(B[i] * (R[i-1]+2*R[i]+R[i+1]) % P)
Problem p02998 (python)

Fixed submission:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
N = int(input())
K = 10**5+1
P = [i for i in range(K)]

def par(a):
    if P[a] == a:
        return a
    t = par(P[a])
    P[a] = t
    return t
def cb(a, b):
    pa = par(a)
    pb = par(b)
    if pa != pb:
        P[pa] = pb

X = [[] for _ in range(K)]
Y = [[] for _ in range(K)]
for _ in range(N):
    x, y = map(int, input().split())
    X[x-1].append(y-1)
    Y[y-1].append(x-1)
for i in range(K):
    for j in range(len(Y[i])-1):
        cb(Y[i][j], Y[i][j+1])

M = [[] for _ in range(K)]
for i in range(K):
    M[par(i)].append(i)
ans = -N
for i in range(K):
    S = []
    for j in M[i]:
        for k in X[j]:
            S.append(k)
    S = list(set(S))
    ans += len(S)*len(M[i])
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
N = int(input())
K = 10**5+1
P = [i for i in range(K)]

def par(a):
    if P[a] == a:
        return a
    t = par(P[a])
    P[a] = t
    return t
def cb(a, b):
    P[pa] = pb

X = [[] for _ in range(K)]
Y = [[] for _ in range(K)]
for _ in range(N):
    x, y = map(int, input().split())
    X[x-1].append(y-1)
    Y[y-1].append(x-1)
for i in range(K):
    for j in range(len(Y[i])-1):
        cb(Y[i][j], Y[i][j+1])

M = [[] for _ in range(K)]
for i in range(K):
    M[par(i)].append(i)
ans = -N
for i in range(K):
    S = []
    for j in M[i]:
        for k in X[j]:
            S.append(k)
    S = list(set(S))
    ans += len(S)*len(M[i])
print(ans)
Problem p03033 (python)

Fixed submission:
import sys
input = sys.stdin.readline
from bisect import bisect_left as bl
class segtree:
    def __init__(self, nn):
        self.NN = nn
        self.XX = [0] * (2**(nn+1)-1)
    def getmax(self, i):
        j = 2**self.NN + i - 1
        ma = -1
        while j >= 0:
            ma = max(ma, self.XX[j])
            j = (j-1) // 2
        return -1 if ma <= 0 else INF - ma
    def updaterange(self, a, b, x):
        l = a + (1<<self.NN)
        r = b + (1<<self.NN)
        s = 0
        while l < r:
            if l%2:
                self.XX[l-1] = max(self.XX[l-1], x)
                l += 1
            if r%2:
                r -= 1
                self.XX[r-1] = max(self.XX[r-1], x)
            l >>= 1
            r >>= 1

N, Q = map(int, input().split())
st = segtree(18)
INF = 1<<50
X = []
D = []
for _ in range(N):
    s, t, x = map(int, input().split())
    X.append((s, t, x))
for _ in range(Q):
    D.append(int(input()))

for s, t, x in X:
    st.updaterange(bl(D, s-x), bl(D, t-x), INF-x)
for i in range(Q):
    print(st.getmax(i))

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
class segtree:
    def __init__(self, nn):
        self.NN = nn
        self.XX = [0] * (2**(nn+1)-1)
    def getmax(self, i):
        j = 2**self.NN + i - 1
        ma = -1
        while j >= 0:
            ma = max(ma, self.XX[j])
            j = (j-1) // 2
        return -1 if ma <= 0 else INF - ma
    def updaterange(self, a, b, x):
        l = a + (1<<self.NN)
        r = b + (1<<self.NN)
        s = 0
        while l < r:
            if l%2:
                self.XX[l-1] = max(self.XX[l-1], x)
                l += 1
            if r%2:
                r -= 1
                self.XX[r-1] = max(self.XX[r-1], x)
            l >>= 1
            r >>= 1

N, Q = map(int, input().split())
st = segtree(18)
INF = 1<<50
for _ in range(N):
    s, t, x = map(int, input().split())
    st.updaterange(s-x, t-x, INF-x)
for _ in range(Q):
    print(st.getmax(int(input())))

Buggy submission (verdict: Runtime Error):
class segtree:
    def __init__(self, nn):
        self.NN = nn
        self.XX = [0] * (2**(nn+1)-1)
    def getmax(self, i):
        j = 2**self.NN + i - 1
        ma = -1
        while j >= 0:
            ma = max(ma, self.XX[j])
            j = (j-1) // 2
        return -1 if ma <= 0 else INF - ma
    def updaterange(self, a, b, x):
        l = a + (1<<self.NN)
        r = b + (1<<self.NN)
        s = 0
        while l < r:
            if l%2:
                self.XX[l-1] = max(self.XX[l-1], x)
                l += 1
            if r%2:
                r -= 1
                self.XX[r-1] = max(self.XX[r-1], x)
            l >>= 1
            r >>= 1

N, Q = map(int, input().split())
st = segtree(17)
INF = 1<<50
for _ in range(N):
    s, t, x = map(int, input().split())
    st.updaterange(s-x, t-x, INF-x)
for _ in range(Q):
    print(st.getmax(int(input())))
Problem p03108 (python)

Fixed submission:
import sys
sys.setrecursionlimit(100000)
input = sys.stdin.readline

N, M = map(int, input().split())
X = []
for _ in range(M):
    a, b = map(int, input().split())
    X.append((a-1, b-1))
X = X[::-1]
    
P = [-1] * N
CT = [1] * N
def pr(i):
    if P[i] < 0:
        return i
    t = pr(P[i])
    P[i] = t
    return t

ANS = [0] * M
ans = N * (N-1) // 2
ANS[-1] = ans
for m in range(M-1):
    a, b = X[m]
    pa = pr(a)
    pb = pr(b)
    
    if pa != pb:
        ans -= CT[pa] * CT[pb]
        P[pa] = pb
        CT[pb] += CT[pa]

    ANS[-m-2] = ans

for a in ANS:
    print(a)

Buggy submission (verdict: Runtime Error):
if True:
    N, M = map(int, input().split())
    X = []
    for _ in range(M):
        a, b = map(int, input().split())
        X.append((a-1, b-1))

    X = X[::-1]
else:
    X = [(3, 4), (2, 3), (4, 5), (0, 1), (1, 2)]
    N = 6
    M = 5
    
P = [-1] * N
CT = [1] * N
def pr(i):
    if P[i] < 0:
        return i
    t = pr(P[i])
    P[i] = t
    return t

ANS = [0] * M
ans = N * (N-1) // 2
ANS[-1] = ans
for m in range(M-1):
    a, b = X[m]
    pa = pr(a)
    pb = pr(b)
    
    # print("0", m, a, b, P, CT)
    
    if pa != pb:
        ans -= CT[pa] * CT[pb]
        P[pa] = pb
        CT[pb] += CT[pa]

    # print("1", m, a, b, P, CT, ans)
        

    ANS[-m-2] = ans

for a in ANS:
    print(a)
Problem p03188 (python)

Fixed submission:
K = int(input())
M = 1000

def a(i, j):
    tmp = (i - j) % (M//2) + 1
    if j % 2 == 0 or M + 1 - tmp > K:
        return tmp
    else:
        return M + 1 - tmp
    
if K <= M//2:
    print(K)
    for i in range(K):
        print(*([i+1]*K))
else:
    print(M//2)
    for j in range(M//2):
        print(*([a(i, j) for i in range(M//2)]))

Buggy submission (verdict: Runtime Error):
K = int(input())

if K <= 500:
    print(K)
    for i in range(K):
        print(*([i+1]*K))
elif K % 4 == 0:
    print(K // 2)
    for i in range(K // 2):
        print(*([i+1, i+1+K//2] * (K//4)))
else:
    print(1//0)
Problem p03202 (python)

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

def chk(k):
    if k == 1:
        for i in range(1, N):
            if A[i] <= A[i-1]: return 0
        return 1
    
    X = [(0, 0)]
    def add(x, y):
        if x <= 0: return 0
        if x > X[-1][0]:
            X.append((x, 0 if x == y else 1))
        elif x == X[-1][0]:
            if X[-1][1] + 1 < k:
                X[-1] = (X[-1][0], X[-1][1] + 1)
            else:
                if add(x-1, y) == 0: return 0
        else:
            while X[-1][0] > x:
                X.pop()
            if x > X[-1][0]:
                X.append((x, 1))
            elif x == X[-1][0]:
                if X[-1][1] + 1 < k:
                    X[-1] = (X[-1][0], X[-1][1] + 1)
                else:
                    if add(x-1, y) == 0: return 0
        if X[-1][0] < y: X.append((y, 0))
        return 1
    
    for a in A:
        if add(a, a) == 0: return 0
    return 1

l, r = 0, 1 << 18
while r - l > 1:
    m = (l + r) // 2
    if chk(m):
        r = m
    else:
        l = m

print(r)

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

def chk(k):
    if k == 1:
        for i in range(1, N):
            if A[i] <= A[i-1]: return 0
        return 1
    
    X = [(0, 0)]
    def add(x):
        if x <= 0: return 0
        if a > X[-1][0]:
            X.append((a, 0))
        elif a == X[-1][0]:
            if X[-1][1] + 1 < k:
                X[-1] = (X[-1][0], X[-1][1] + 1)
            else:
                add(x-1)
        else:
            while X[-1][0] > a:
                X.pop()
            if a > X[-1][0]:
                X.append((a, 1))
            elif a == X[-1][0]:
                if X[-1][1] + 1 < k:
                    X[-1] = (X[-1][0], X[-1][1] + 1)
                else:
                    add(x-1)
        return 1
    
    for a in A:
        c = add(a)
        if c == 0: return 0
    return 1

l, r = 0, 1 << 18
while r - l > 1:
    m = (l + r) // 2
    if chk(m):
        r = m
    else:
        l = m

print(r)

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

def chk(k):
    if k == 1:
        for i in range(1, N):
            if A[i] <= A[i-1]: return 0
        return 1
    
    X = [(0, 0)]
    def add(x):
        if x <= 0: return 0
        if a > X[-1][0]:
            X.append((a, 0))
        elif a == X[-1][0]:
            if X[-1][1] + 1 < k:
                X[-1] = (X[-1][0], X[-1][1] + 1)
            else:
                add(x-1)
        else:
            while X[-1][0] > a:
                X.pop()
            if a > X[-1][0]:
                X.append((a, 1))
            elif a == X[-1][0]:
                if X[-1][1] + 1 < k:
                    X[-1] = (X[-1][0], X[-1][1] + 1)
                else:
                    add(x-1)
    for a in A:
        c = add(a)
        if c == 0: return 0
    return 1

l, r = 0, 1 << 18
while r - l > 1:
    m = (l + r) // 2
    if chk(m):
        r = m
    else:
        l = m

print(r)
Problem p03769 (python)

Fixed submission:
fact = [1]
for i in range(1, 101):
    fact.append(fact[-1]*i)
    
def C(a, b):
    return fact[a]//(fact[b]*fact[a-b])

def sC(a, b):
    ret = 0
    for i in range(min(b, a-b) + 1):
        ret += C(b, i) * C(a - b, i)
    return ret

def calc(n, k):
    if n<=0:
        return []
    i = 0
    while (1<<(i+1)) -1 <= n:
        i += 1
        
    ret = [str(k)] * (i+1)
    rem = n-((1<<i) - 1)
    kk = k + 1
    i += 1
    j = i // 2
    
    while j > 0:
        while True:
            tmp = sC(i, j)
            if tmp <= rem:
                ret.insert(j, str(kk))
                ret.append(str(kk))
                kk += 1
                rem -= tmp

            else:
                break
                
        j -= 1
        
    return ret + calc(rem, kk)

N = int(input())

X = calc(N, 1)
print(len(X))
print(" ".join(X))

Buggy submission (verdict: Runtime Error):
def calc(n, k):
  if k>100:
    print(1/0)
  # print(n, k)
  if n<=0:
    return []
  i = 0
  while (1<<(i+1)) -1 <= n:
    i += 1
  return [str(k)] * (i+1) + calc(n-((1<<i) - 1), k+1)

a=calc(int(input()), 1)
if len(a)>200:
  print(1/0)
print(len(a))
print(" ".join(a))
Problem p03776 (python)

Fixed submission:
from itertools import accumulate as ac
t = 3099044504245996706400 # LCM(1..50)
N, A, B = map(int, input().split())
V = sorted([int(a) * t for a in input().split()])[::-1]
l, r = 0, 1<<200
while r - l > 1:
    m = (l+r) // 2
    if list(ac([v-m for v in V]))[A-1] >= 0:
        l = m
    else:
        r = m

fa = [1]
for i in range(1, 60):
    fa.append(fa[-1] * i)
C = lambda a, b: fa[a] // (fa[a-b] * fa[b])

print(l/t)
print(sum([C(V.count(V[i-1]), V[:i].count(V[i-1])) for i in range(A, B+1) if sum(V[:i]) == l * i]))

Buggy submission (verdict: Runtime Error):
N, W = map(int, input().split())
w0, v0 = map(int, input().split())
X = [[] for _ in range(4)]
X[0].append(v0)
for _ in range(N-1):
    w, v = map(int, input().split())
    X[w-w0].append(v)

X = [[0] + sorted(x)[::-1] for x in X]
for i in range(4):
    for j in range(1, len(X[i])):
        X[i][j] += X[i][j-1]
ma = 0
for i in range(N+1):
    for j in range(N+1-i):
        for k in range(N+1-i-j):
            l = min(N-i-j-k, (W - (w0 * i + (w0+1) * j + (w0+2) * k)) // (w0+3))
            if l < 0: continue
            if i < len(X[0]) and j < len(X[1]) and k < len(X[2]) and l < len(X[3]):
                ma = max(ma, X[0][i] + X[1][j] + X[2][k] + X[3][l])
print(ma)
Problem p02596 (python)

Fixed submission:
k = int(input())
a = 7%k
s = set()
for i in range(k):
    if a == 0:
        print(i+1)
        break
    a = (a*10+7)%k
else:
    print(-1)

Buggy submission (verdict: Runtime Error):
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int k; cin >> k;
    int a = 7%k;
    rep(i,k){
        if (a == 0){
            cout << i+1 << "\n";
            return 0;
        }
        a = (a * 10 + 7)%k;
    }
    cout << -1 << "\n";
}
Problem p02629 (python)

Fixed submission:
import string
s = string.ascii_lowercase


def f(x, tmp):
    if x == 0:
        return ""
    x -= 1
    if x < 26:
        return s[x] + tmp
    else:
        return f(x // 26 , s[x % 26] + tmp)


n = int(input())
r = f(n, "")
print(r)

Buggy submission (verdict: Runtime Error):
import string
s = string.ascii_lowercase


def f(x, tmp):
    if x == 0:
        return ""
    x -= 1
    if x <= 26:
        return s[x] + tmp
    else:
        return f(x // 26, s[x % 26] + tmp)


n = int(input())
r = f(n, "")
print(r)
Problem p02689 (python)

Fixed submission:
n,m = map(int,input().split())
h = tuple(map(int,input().split()))
l = set([tuple(map(int,input().split())) for i in range(m)])
x = [[] for i in range(n)]
ans=0
for t in l:
    x[t[0]-1].append(h[t[1]-1])
    x[t[1]-1].append(h[t[0]-1])
for k,li in enumerate(x):
    a = h[k]
    if li == []:
        ans+=1
    else:
        if a>max(li):
            ans+=1
print(ans)

Buggy submission (verdict: Runtime Error):
n,m = map(int,input().split())
h = list(map(int,input().split()))
l = [tuple(map(int,input().split())) for i in range(m)]
x = ["B"]*n
for t in l:
    if h[t[0]-1] <= h[t[1]-1]:
        x[t[1]-1]="G"
        x[t[0]-1]="B"
    elif h[t[0]-1] >= h[t[1]-1]:
        x[t[1]-1]="B"
        x[t[0]-1]="G"
    print(x)
print(x.count("G"))
Problem p02699 (python)

Fixed submission:
s,w = map(int,input().split())
if s<=w:
    print("unsafe")
else:
    print("safe")

Buggy submission (verdict: Runtime Error):
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#include <bits/stdc++.h>
using namespace std;

int main() {
    int s,w; cin >> s >> w;
    if (w >= s){
        cout << "unsafe\n";
    }
    else{
        cout << "safe\n";
    }
}
Problem p02726 (python)

Fixed submission:
n, x, y = map(int, input().split())
ans = [0] * (n - 1)

x -= 1
y -= 1
for i in range(n):
    for j in range(n):
        c = min(abs(i - j), abs(i-x)+abs(j-y)+1,abs(i-y)+abs(j-x)+1)
        if c:
            ans[c-1] += 1

for ai in ans:
    print(ai//2)

Buggy submission (verdict: Runtime Error):
from numba.np.ufunc import parallel
from numba import njit,prange


@njit(cache=True,parallel=True)
def solve(n,x,y):
    ans = [0] * (n - 1)
    for i in prange(n):
        for j in prange(n):
            c = min(abs(i - j), abs(i-x)+abs(j-y)+1,abs(i-y)+abs(j-x)+1)
            if c:
                ans[c-1] += 1
    return ans


n, x, y = map(int, input().split())
x -= 1
y -= 1
ans = solve(n,x,y)
for ai in ans:
    print(ai//2)

Buggy submission (verdict: Runtime Error):
from numba.np.ufunc import parallel
from numba import njit,prange


@njit(cache=True,parallel=True)
def solve(n,x,y):
    ans = [0] * (n - 1)
    for i in prange(n):
        for j in prange(n):
            c = min(abs(i - j), abs(i-x)+abs(j-y)+1,abs(i-y)+abs(j-x)+1)
            if c:
                ans[c-1] += 1
    return ans


n, x, y = map(int, input().split())
x -= 1
y -= 1
ans = solve(n,x,y)
for ai in ans:
    print(ai//2)

Buggy submission (verdict: Runtime Error):
from networkx.drawing.nx_pylab import draw_networkx
import networkx as nx
import matplotlib.pyplot as plt

n,x,y = map(int,input().split())
G = nx.Graph()
G.add_nodes_from(list(range(n)))
inf = 10**10
D = [[inf]*n for i in range(n)]
for i in range(n-1):
    #G[i].append(i+1)
    #G[i+1].append(i)
    G.add_edge(i,i+1)
    D[i][i+1] = 1
    D[i+1][i] = 1
G.add_edge(x-1,y-1)
D[x-1][y-1] = 1
D[y-1][x-1] = 1

for i in range(n):
    D[i][i] = 0
for i in range(n):
    for j in range(n):
        for k in range(n):
            D[i][j] = min(D[i][j],D[i][k]+D[k][j])

s = set()
ans = [0]*(n-1)
paths = nx.shortest_path(G)
for i in range(n):
    for j in range(n):
        if (min(i,j),max(i,j)) in s:
            pass
        else:
            s.add((min(i,j),max(i,j)))
            c = len(paths[i][j])-1
            if c:
                ans[c-1] += 1
for ai in ans:
    print(ai)
Problem p02729 (python)

Fixed submission:
import itertools
n,m = map(int,input().split())
o = 0
o += len(list(itertools.permutations([i for i in range(n)], 2)))/2
o += len(list(itertools.permutations([i for i in range(m)], 2)))/2
print(int(o))

Buggy submission (verdict: Runtime Error):
import math
n,m = map(int,input().split())
print(((math.factorial(n) // math.factorial(n - 2))//2)+ ((math.factorial(m) // math.factorial(m - 2))//2))