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

Fixed submission:
import sys
input = sys.stdin.readline
 
class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
 
    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
 
    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i
 
n,q = list(map(int,input().split()))
ball = list(map(int,input().split()))
 
h = Bit(n+1)

L = {}
jump = {}
on = set()

for i,b in enumerate(ball):
  if b not in L:
    h.add(i+1,1)
    on.add(i+1)
  if b in L:
    jump[L[b]]=i+1
  L[b] = i+1

Q = []
 
for _ in range(q):
  l,r = list(map(int,input().split()))
  Q.append((l,r))
  
LOO = list(Q)
Q.sort(key=lambda x:x[0])

c = 1
ans = {}

for l,r in Q:
  for i in range(c,l):
    if i in on:
      on.remove(i)
      h.add(i,-1)
      if i in jump:
        dest = jump[i]
        h.add(dest,1)
        on.add(dest)

  tmp = h.sum(r)- h.sum(l-1)
  ans[(l,r)] = tmp
  c = l

p = []
for q in LOO:
  p.append(ans[q])
  
print(*p, sep="\n")

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
 
class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
 
    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
 
    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i
 
n,q = list(map(int,input().split()))
ball = list(map(int,input().split()))
 
h = Bit(n+1)

L_most = {}
J = [[] for _ in range(max(ball)+1)]
jump = {}
on = set()

for i,b in enumerate(ball):
  if b not in L_most:
    L_most[b]=i
    h.add(i+1,1)
    on.add(i+1)
  J[b].append(i)
    
for i in range(n+1):
  for j in range(len(J[i])):
    if j+1<len(J[i]):
      jump[J[i][j]+1] = J[i][j+1]+1

Q = []
 
for _ in range(q):
  l,r = list(map(int,input().split()))
  Q.append((l,r))
  
LOO = list(Q)
Q.sort(key=lambda x:x[0])

c = 1
ans = {}
#print(on)

for l,r in Q:
  for i in range(c,l):
    if i in on:
      on.remove(i)
      h.add(i,-1)
      if i in jump:
        dest = jump[i]
        h.add(dest,1)
        on.add(dest)

  tmp = h.sum(r)- h.sum(l-1)
  ans[(l,r)] = tmp
  c = l

for q in LOO:
  print(ans[q])
Problem p02900 (python)

Fixed submission:
from fractions import gcd

a, b = map(int, input().split())
d = gcd(a, b)

ans = 1
n = d
for i in range(2, d + 1):
    if n % i == 0:
        ans += 1
        while n % i == 0:
            n //= i
    if n < i * i:
        if 1 < n:
            ans += 1
        break
print(ans)

Buggy submission (verdict: Runtime Error):
from math import gcd

a, b = map(int, input().split())
d = gcd(a, b)

ans = 1
n = d
for i in range(2, d + 1):
    if n % i == 0:
        ans += 1
        while n % i == 0:
            n //= i
    if n < i * i:
        if 1 < n:
            ans += 1
        break
print(ans)

Buggy submission (verdict: Runtime Error):
from math import gcd

a, b = map(int, input().split())
d = gcd(a, b)

ans = 1
n = d
for i in range(2, d + 1):
    if n % i == 0:
        ans += 1
        while n % i == 0:
            n //= i
    if n < i * i:
        if 1 < n:
            ans += 1
        break
print(ans)
Problem p03030 (python)

Fixed submission:
n = int(input())
dict = {}
for i in range(n):
    s, p = input().split()
    if s not in dict:
        dict[s] = []
    dict[s].append((int(p), i + 1))

for s in sorted(dict.keys()):
    for (p, i) in reversed(sorted(dict[s])):
        print(i)

Buggy submission (verdict: Runtime Error):
khabarovsk 20
n = int(input())
dict = {}
for i in range(n):
    s, p = input().split()
    if s not in dict:
        dict[s] = []
    dict[s].append((int(p), i + 1))

for s in sorted(dict.keys()):
    for (p, i) in reversed(sorted(dict[s])):
        print(i)
Problem p03061 (python)

Fixed submission:
from fractions import gcd

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

if n == 1:
    ans = 1000000000
elif n == 2:
    ans = max(a)
else:
    l = [a[0]]
    for i in range(1, n):
        l.append(gcd(l[-1], a[i]))
    r = [a[-1]]
    for i in range(n - 1, -1, -1):
        r.append(gcd(r[-1], a[i]))
    r = list(reversed(r))
    ans = max(l[-2], r[1])
    for i in range(1, n - 1):
        ans = max(ans, gcd(l[i - 1], r[i + 1]))
print(ans)

Buggy submission (verdict: Runtime Error):
from math import gcd

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

if n == 1:
    ans = 1000000000
elif n == 2:
    ans = max(a)
else:
    l = [a[0]]
    for i in range(1, n):
        l.append(gcd(l[-1], a[i]))
    r = [a[-1]]
    for i in range(n - 1, -1, -1):
        r.append(gcd(r[-1], a[i]))
    r = list(reversed(r))
    ans = max(l[-2], r[1])
    for i in range(1, n - 1):
        ans = max(ans, gcd(l[i - 1], r[i + 1]))
print(ans)
Problem p03196 (python)

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

ans = 1
if n == 1:
    ans = p
else:
    q = p
    for d in range(2, 1000001):
        if q < d**2:
            break
        cnt = 0
        while q % d == 0:
            q //= d
            cnt += 1
        ans *= d**(cnt // n)
print(ans)

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

ans = 1
q = p
if n == 1:
    ans = p
else:
    for d in range(2, 1000001):
        cnt = 0
        while q % d == 0:
            q //= d
            cnt += 1
        if p < d**n:
            break
        ans *= d**(cnt // n)
print(ans)
Problem p03424 (python)

Fixed submission:
n = int(input())
ss = input().split()

ans = "Three"

if any(ss[i] == 'Y' for i in range(n)):
    ans = "Four"

print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
ss = input().splist()

ans = "Three"

if any(ss[i] == 'Y' for i in range(n)):
    ans = "Four"

print(ans)
Problem p03489 (python)

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

cnt = {}
for ai in a:
    if ai in cnt:
        cnt[ai] += 1
    else:
        cnt[ai] = 1

ans = 0
for k, v in cnt.items():
    if k < v:
        ans += v - k
    elif v < k:
        ans += v
print(ans)

Buggy submission (verdict: Runtime Error):
s = str(input())
x, y = map(int, input().split())

n = 8000
fs = list(map(len, s.split('T')))
x -= fs[0]
dx = []
dy = []
for i in range(1, len(fs)):
    if fs[i] == 0:
        continue
    if i % 2 == 0:
        dx.append(fs[i])
    else:
        dy.append(fs[i])
dpx = [[False for _ in range(4 * n + 1)] for _ in range(2)]
dpy = [[False for _ in range(4 * n + 1)] for _ in range(2)]
dpx[0][2 * n] = True
dpy[0][2 * n] = True
for i in range(len(dx)):
    for j in range(4 * n + 1):
        if dpx[i % 2][j]:
            if 0 <= j - dx[i]:
                dpx[(i + 1) % 2][j - dx[i]] = True
            if j + dx[i] <= 4 * n:
                dpx[(i + 1) % 2][j + dx[i]] = True
for i in range(len(dy)):
    for j in range(4 * n + 1):
        if dpy[i % 2][j]:
            if 0 <= j - dy[i]:
                dpy[(i + 1) % 2][j - dy[i]] = True
            if j + dy[i] <= 4 * n:
                dpy[(i + 1) % 2][j + dy[i]] = True
ix = 2 * n + x
iy = 2 * n + y
if 0 <= ix <= 4 * n and dpx[len(dx) % 2][ix] and 0 <= iy <= 4 * n and dpy[len(dy) % 2][iy]:
    print("Yes")
else:
    print("No")
Problem p03591 (python)

Fixed submission:
s = list(input())
 
if 4 <= len(s) and s[:4] == list("YAKI"):
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
n, m, k = map(int, input().split())
 
ans = "No"
for i in range(n + 1):
    for j in range(m + 1):
        if i * (m - j) + j * (n - i) == k:
            ans = "Yes"
print(ans)
Problem p03651 (python)

Fixed submission:
import fractions

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

ans = "IMPOSSIBLE"

d = a[0]
for i in range(1, n):
    d = fractions.gcd(d, a[i])

for ai in a:
    if k <= ai and (ai - k) % d == 0:
        ans = "POSSIBLE"
        break
print(ans)

Buggy submission (verdict: Runtime Error):
import fractions

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

d = fractions.gcd(a[0], a[1])
for i in range(2, n):
    d = fractions.gcd(d, a[i])

ans = "IMPOSSIBLE"
for ai in a:
    if k <= ai and (ai - k) % d == 0:
        ans = "POSSIBLE"
        break
print(ans)
Problem p03661 (python)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
s = [0]
ans = 1e18
for ai in a:
    s.append(s[-1] + ai)
for i in range(1, n):
    ans = min(ans, abs(s[i] - (s[-1] - s[i])))
print(ans)

Buggy submission (verdict: Runtime Error):
DEBUG = False
if DEBUG:
    N = int(input())

def check(n):
    print("? " + str(n), flush = True)
    if DEBUG:
        rtn = 'Y' if (n <= N) == (str(n) <= str(N)) else 'N'
        print(rtn)
        return rtn
    else:
        return input()

if check(10000000000) == 'Y':
    for i in range(11, 0, -1):
        n = 1
        tmp = 10**i - 1
        if check(tmp) == 'N':
            n = tmp + 1
            break
else:
    for i in range(1, 10):
        tmp = 10**i
        if check(tmp) == 'N':
            l = tmp // 10
            r = tmp - 1
            break
    while l + 1 < r:
        m = (l + r) // 2
        if check(10 * m) == 'Y':
            r = m
        else:
            l = m
    n = r

print("! "+ str(n), flush = True)
Problem p03733 (python)

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

ans = sum([min(ts[i + 1] - ts[i], T) for i in range(N - 1)]) + T
print(ans)

Buggy submission (verdict: Runtime Error):
Rmax = 0
Rmin = 1000000000
Bmax = 0
Bmin = 1000000000

N = int(input())
xs = []
ys = []
arr = []
for i in range(N):
    x, y = map(int, input().split())
    xs.append(x)
    ys.append(y)
    arr.append((max(x, y) / min(x, y), min(x, y), max(x, y)))

arr = list(sorted(arr))
for (_, x, y) in arr:
    Rmin0 = min(Rmin, x)
    Rmax0 = max(Rmax, x)
    Bmin0 = min(Bmin, y)
    Bmax0 = max(Bmax, y)
    p0 = (Rmax0 - Rmin0) * (Bmax0 - Bmin0)
    Rmin1 = min(Rmin, y)
    Rmax1 = max(Rmax, y)
    Bmin1 = min(Bmin, x)
    Bmax1 = max(Bmax, x)
    p1 = (Rmax1 - Rmin1) * (Bmax1 - Bmin1)
    if p0 <= p1:
        Rmin = Rmin0
        Rmax = Rmax0
        Bmin = Bmin0
        Bmax = Bmax0
    else:
        Rmin = Rmin1
        Rmax = Rmax1
        Bmin = Bmin1
        Bmax = Bmax1

ans = (Rmax - Rmin) * (Bmax - Bmin)
print(ans)
Problem p02574 (python)

Fixed submission:
import math
def eratos(n):
    isprime = [i for i in range(n+1)]
    # isprime[0] = 0
    isprime[1] = 1
    for i in range(2, int(math.sqrt(n))+1):
        if isprime[i] == i:
            j = i
            while j <= n:
                if isprime[j] == j:
                    isprime[j] = i
                j = j + i
    return isprime

N = int(input())
A = list(map(int, input().split()))
isprime = eratos(10**6)
count = [0 for i in range(10**6+1)]
for ai in A:
    primes = {}
    while ai != 1:
        p = isprime[ai]
        primes[p] = 1
        ai //= p
    for p in primes.keys():
        count[p] += 1
max_c = max(count)
if max_c <= 1:
    print('pairwise coprime')
elif max_c == N:
    print('not coprime')
else:
    print('setwise coprime')

Buggy submission (verdict: Runtime Error):
import math
def eratos(n):
    isprime = [0 for i in range(n+1)]
    # isprime[0] = 0
    isprime[1] = 1
    for i in range(2, int(math.sqrt(n))+1):
        if isprime[i] == 0:
            j = i
            while j <= n:
                if isprime[j] == 0:
                    isprime[j] = i
                j = j + i
    return isprime

N = int(input())
A = list(map(int, input().split()))
isprime = eratos(10**6)
count = [0 for i in range(10**6+1)]
for ai in A:
    primes = {}
    while ai != 1:
        p = isprime[ai]
        primes[p] = 1
        ai //= p
    for p in primes.keys():
        count[p] += 1
max_c = max(count)
if max_c <= 1:
    print('pairwise coprime')
elif max_c == N:
    print('not coprime')
else:
    print('setwise coprime')
Problem p02584 (python)

Fixed submission:
import sys
import math
X, K, D = map(int, input().split())
if X == 0 and K % 2 == 0:
    print(X)
    sys.exit()
elif X == 0 and K % 2 == 1:
    print(D)
    sys.exit()

if abs(X // D) >= K:
    ans = X - (D * K) * (X // abs(X))
    ans = abs(ans)
else:
    K -= abs(X//D)
    ans = X - (D * abs(X//D)) * (X // abs(X))
    if K % 2 == 0 and K == 0:
        ans = abs(ans)
    elif K % 2 == 0 and K >= 2:
        ans = min([abs(ans), abs(ans-D*2), abs(ans+D*2)])
    else:
        ans = min(abs(ans+D), abs(ans-D))
print(ans)

Buggy submission (verdict: Runtime Error):
import math
X, K, D = map(int, input().split())
if abs(X // D) >= K:
    ans = X - (D * K) * (X // abs(X))
    ans = abs(ans)
else:
    K -= X//D
    ans = X - (D * (X//D)) * (X // abs(X))
    if K % 2 == 0 and abs(ans) < D:
        ans = abs(ans)
    else:
        ans = min(abs(ans+D), abs(ans-D))
    # print((D * X//D) * (X // abs(X)))
print(ans)
# print(X // D, math.ceil(X / D))
Problem p02609 (python)

Fixed submission:
import sys
from collections import Counter
N = int(input())
X = list(input())
revX = reversed(X)
count01 = Counter(X)
if count01['1'] == 0:
    for i in range(N):
        print(1)
    sys.exit()
m1 = count01['1']-1
p1 = count01['1']+1
powrem = []
m1rem = 0
p1rem = 0
basem1 = 1
basep1 = 1
if m1 == 0:
    for i, xi in enumerate(revX):
    # print(basep1)
        if xi == '0':
            powrem += [basep1 % p1]
        else:
            powrem += [0]
            p1rem = (p1rem + basep1) % p1
        basep1 = (basep1 * 2) % p1
    revpowrem = reversed(powrem)
    # print(list(revpowrem))
    for xi, rem in zip(X, revpowrem):
        c = 1
        if xi == '0':
            r = (p1rem+rem)%p1
        else:
            print(0)
            continue
        # print(r, xi, rem)
        while r != 0:
            p = bin(r).count('1')
            r = r % p
            c += 1
        print(c)
    sys.exit()

for i, xi in enumerate(revX):
    # print(basep1)
    if xi == '0':
        powrem += [basep1 % p1]
    else:
        powrem += [basem1 % m1]
        m1rem = (m1rem + basem1) % m1
        p1rem = (p1rem + basep1) % p1
    basem1 = (basem1 * 2) % m1
    basep1 = (basep1 * 2) % p1
revpowrem = reversed(powrem)
# print(list(revpowrem))
for xi, rem in zip(X, revpowrem):
    c = 1
    if xi == '0':
        r = (p1rem+rem)%p1
    else:
        r = (m1rem-rem)%m1
    # print(r, xi, rem)
    while r != 0:
        p = bin(r).count('1')
        r = r % p
        c += 1
    print(c)

Buggy submission (verdict: Runtime Error):
import sys
from collections import Counter
N = int(input())
X = list(input())
revX = reversed(X)
count01 = Counter(X)
if count01['1'] == 0:
    for i in range(N):
        print(1)
    sys.exit()
m1 = count01['1']-1
p1 = count01['1']+1
powrem = []
m1rem = 0
p1rem = 0
basem1 = 1
basep1 = 1

for i, xi in enumerate(revX):
    # print(basep1)
    if xi == '0':
        powrem += [basep1 % p1]
    else:
        powrem += [basem1 % m1]
        m1rem = (m1rem + basem1) % m1
        p1rem = (p1rem + basep1) % p1
    basem1 = (basem1 * 2) % m1
    basep1 = (basep1 * 2) % p1
revpowrem = reversed(powrem)
# print(list(revpowrem))
for xi, rem in zip(X, revpowrem):
    c = 1
    if xi == '0':
        r = (p1rem+rem)%p1
    else:
        if m1 == 0:
            print(0)
            continue
        r = (m1rem-rem)%m1
    # print(r, xi, rem)
    while r != 0:
        p = bin(r).count('1')
        r = r % p
        c += 1
    print(c)
Problem p02660 (python)

Fixed submission:
import math
def eratos(n):
    isprime = [True for i in range(n+1)]
    isprime[0] = False
    isprime[1] = False
    for i in range(2, int(math.sqrt(n))+13):
        if isprime[i]:
            j = i + i
        while j <= n:
            isprime[j] = False
            j = j + i
    return isprime
N = int(input())
ans = 0
is_prime = eratos(10**6+13)
for i in range(2, 10**6+14):
    if not is_prime[i]:
        continue
    x = i
    while N % x == 0:
        ans += 1
        N //= x
        x *= i
        # print(N)
if ans == 0 and N != 1:
    ans += 1
elif N > 10**6:
    ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
AB = []
for i in range(N):
    A, B = map(int, input().split())
    AB += [(A, B)]
sortA = sorted(AB, key=lambda x: x[0])
sortB = sorted(AB, key=lambda x: x[1])
if N % 2 == 0:
    mid = N//2-1
    A11,B11 = sortA[mid]
    A12,B12 = sortA[mid+1]
    # print(A11, B11)
    # print(A12, B12)
    A1 = (A11+A12) / 2
    B1 = (B11+B12) / 2
    A21,B21 = sortB[mid]
    A22,B22 = sortB[mid+1]
    A2 = (A21+A22) / 2
    B2 = (B21+B22) / 2
    # ans = (min(B1, B2) - max(A1, A2))*2 + 1
    ans = (B2 - A1)*2 + 1
    # print(B1, B2, A1, A2, ans)
    # if ans % 1 != 0:
    #     ans += 1
else:
    mid = (N+1)//2-1
    A1,B1 = sortA[mid]
    A2,B2 = sortB[mid]
    # print(A1, A1, B1, B2)
    ans = (B2 - A1) + 1

print(int(ans))
Problem p02842 (python)

Fixed submission:
N = int(input())
# ans = ':('
for i in range(1, N+1):
    tmp = (i * 1.08) // 1
    if tmp == N:
        ans = i
        break
    elif tmp > N:
        ans = ':('
        break
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
for i in range(1, N):
    tmp = (i * 1.08) // 1
    if tmp == N:
        ans = i
        break
    elif tmp > N:
        ans = ':('
        break
print(ans)
Problem p02850 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**9)

def dfs(s, targets):
    global K
    visited[s] = True
    # print(targets)
    for t in targets:
        if visited[t]:
            continue
        mab = max(G3[s], G3[t])
        while (mab in G2[s]) or (mab in G2[t]):
            mab += 1
        K = max(K, mab)
        ans[p2i[(s, t)]]= mab
        G2[s].add(mab)
        G2[t].add(mab)
        while G3[s] in G2[s]:
            G3[s] += 1
        while G3[t] in G2[t]:
            G3[t] += 1
        dfs(t, G[t])

K = 0
N = int(input())
G = [[] for i in range(N+1)]
G2 = [set() for i in range(N+1)]
p2i = {}
visited = [False for i in range(N+1)]
ans = [0 for i in range(N-1)]
G3 = [1] * (N+1)
for i in range(N-1):
    a, b = map(int, input().split())
    p2i[(a, b)] = i
    p2i[(b, a)] = i
    G[a].append(b)
    G[b].append(a)
# print(max(p2i.values()))
s = 1
targets = G[s]
dfs(s, targets)
print(K)
for a in ans:
    print(a)

Buggy submission (verdict: Runtime Error):
def dfs(s, targets):
    global K
    visited[s] = True
    # print(targets)
    for t in targets:
        if visited[t]:
            continue
        mab = max(G3[s], G3[t])
        while (mab in G2[s]) or (mab in G2[t]):
            mab += 1
        K = max(K, mab)
        ans[p2i[(s, t)]]= mab
        G2[s].add(mab)
        G2[t].add(mab)
        while G3[s] in G2[s]:
            G3[s] += 1
        while G3[t] in G2[t]:
            G3[t] += 1
        dfs(t, G[t])

K = 0
N = int(input())
G = [[] for i in range(N+1)]
G2 = [set() for i in range(N+1)]
p2i = {}
visited = [False for i in range(N+1)]
ans = [0 for i in range(N-1)]
G3 = [1] * (N+1)
for i in range(N-1):
    a, b = map(int, input().split())
    p2i[(a, b)] = i
    p2i[(b, a)] = i
    G[a].append(b)
    G[b].append(a)
# print(max(p2i.values()))
s = 1
targets = G[s]
dfs(s, targets)
print(K)
for a in ans:
    print(a)
Problem p02865 (python)

Fixed submission:
N = int(input())
ans = 0
for i in range(1, N):
    if N - i != i:
        ans += 1
print(ans//2)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
from collections import Counter
from functools import reduce
from operator import mul
M = 998244353
N = int(input())
D = list(map(int, input().split()))
counter = set(D)
if D[0] == 0:
    D[0] = 1
    ans = reduce(mul, D)
    for i, k in enumerate(sorted(counter)):
        if i == k:
            continue
        ans = 0
    print(ans % M)
else:
    print(0)
Problem p02866 (python)

Fixed submission:
import sys
input = sys.stdin.readline
from collections import Counter
M = 998244353
N = int(input())
D = list(map(int, input().split()))
counter = Counter(D)
ans = 1
pre_c = 1
if D[0] != 0 or counter[0] != 1:
    print(0)
else:
    for i, (k, c) in enumerate(sorted(counter.items(), key=lambda x: x[0])):
        if k == 0:
            continue
        elif i != k:
            ans = 0
            break
        ans *= pre_c ** c
        pre_c = c
    print(ans%M)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
from collections import Counter
import math
M = 998244353
N = int(input())
# D = list(map(int, input().split()))
counter = Counter(map(int, input().split()))
ans = counter[1]
pre_c = 1
for i, (n, c) in enumerate(sorted(counter.items())):
    if i != n:
        ans = 0
        break
    elif n <= 1 or c == 1:
        pre_c = c
        continue
    elif pre_c == 1:
        ans *= c
        pre_c = c
        continue
    ans *= (math.factorial(c) ** 2 * (c+1)) // (math.factorial(c+2 - pre_c) * math.factorial(pre_c-1)) // pre_c
    pre_c = c
print(ans % M)
Problem p02936 (python)

Fixed submission:
N, Q = map(int, input().split())
tree = [[] for i in range(N+1)]
counter = [0] * (N+1)

for i in range(N-1):
    a, b = map(int, input().split())
    tree[b].append(a)

for i in range(Q):
    p, x = map(int, input().split())
    counter[p] += x
for i in range(1, N+1):
    for pn in tree[i]:
        counter[i] += counter[pn]

print(' '.join(map(str, counter[1:])))

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
def dfs(node_i):
    is_visited[node_i] = 1
    for bi in tree[node_i]:
        if is_visited[bi]:
            continue
        tree_x[bi] += tree_x[node_i]
        dfs(bi)

N, Q = map(int, input().split())
# tree = [[] for i in range(N)]
tree = defaultdict(list)
tree_x = [0 for i in range(N)]
is_visited = [0]*N
for i in range(N-1):
    a, b = map(int, input().split())
    am1 = a-1
    bm1 = b-1
    tree[bm1].append(am1)
    tree[am1].append(bm1)

# print(tree)
for q in range(Q):
    p, x = map(int, input().split())
    tree_x[p-1] += x

dfs(0)

print(' '.join(map(str, tree_x)))
Problem p03006 (python)

Fixed submission:
from collections import Counter
N = int(input())
xy = [list(map(int, input().split())) for i in range(N)]
# xy = sorted(xy, key=lambda x: x[0])
counter = Counter()
for i in range(N):
    for j in range(i+1, N):
        nxy = xy[i]
        pxy = xy[j]
        counter[(nxy[0]-pxy[0], nxy[1]-pxy[1])] += 1
        counter[(pxy[0]-nxy[0], pxy[1]-nxy[1])] += 1
# print(counter)
if N == 1:
    print(1)
else:
    print(N-counter.most_common(1)[0][1])

Buggy submission (verdict: Runtime Error):
from collections import Counter
N = int(input())
xy = [list(map(int, input().split())) for i in range(N)]
xy = sorted(xy, key=lambda x: x[0])
counter = Counter()
for i in range(1, N):
    nxy = xy[i]
    pxy = xy[i-1]
    counter[(nxy[0]-pxy[0], nxy[1]-pxy[1])] += 1

print(N-counter.most_common(1)[0][1])