Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
from sys import stdin

N, L = stdin.readline().rstrip()

# N, L = 5, 2
# N, L = 3, -1
# N, L = 30, -50

min_value = L
max_value = L + N - 1

summation = L * N + sum(range(N))

if (min_value < 0) and (0 < max_value):
    pass
elif (min_value > 0):
    summation -= min_value
elif (max_value < 0):
    summation -= max_value
    
print(summation)    

Fixed submission:
from sys import stdin

# N, L = stdin.readline().rstrip()
N, L = map(int, input().split(' '))
# print(N, L)
# N, L = 5, 2
# N, L = 3, -1
# N, L = 30, -50

min_value = L
max_value = L + N - 1

summation = L * N + sum(range(N))

if (min_value < 0) and (0 < max_value):
    pass
elif (min_value > 0):
    summation -= min_value
elif (max_value < 0):
    summation -= max_value
    
print(summation)

Buggy python submission (verdict: Runtime Error):
from sys import stdin

N, L = stdin.readline().rstrip()

# N, L = 5, 2
# N, L = 3, -1
# N, L = 30, -50

min_value = L
max_value = L + N - 1

summation = L * N + sum(range(N))

if (min_value < 0) and (0 < max_value):
    pass
elif (min_value > 0):
    summation -= min_value
elif (max_value < 0):
    summation -= max_value

Fixed submission:
from sys import stdin

# N, L = stdin.readline().rstrip()
N, L = map(int, input().split(' '))
# print(N, L)
# N, L = 5, 2
# N, L = 3, -1
# N, L = 30, -50

min_value = L
max_value = L + N - 1

summation = L * N + sum(range(N))

if (min_value < 0) and (0 < max_value):
    pass
elif (min_value > 0):
    summation -= min_value
elif (max_value < 0):
    summation -= max_value
    
print(summation)
Buggy python submission (verdict: Runtime Error):
n,d=map(int,input().split())
c=0
p=d*d
for j in range(n):
    x,y==map(int,input().split())
    if (x**2) + (y**2)==p:
        c=c+1
print(c)

Fixed submission:
n,d=map(int,input().split())
c=0
p=d*d
for j in range(n):
    x,y=map(int,input().split())
    if (x**2) + (y**2)<=p:
        c=c+1
print(c)

Buggy python submission (verdict: Runtime Error):
n,d=map(int,input().split())
c=0
p=d*d
for j in range(n):
	x,y==map(int,input().split())
    if (x**2) + (y**2)==p:
        c=c+1
print(c)

Fixed submission:
n,d=map(int,input().split())
c=0
p=d*d
for j in range(n):
    x,y=map(int,input().split())
    if (x**2) + (y**2)<=p:
        c=c+1
print(c)
Buggy python submission (verdict: Runtime Error):
n=int(input())
d={AC:0,RE:0,WA:0,TLE:0}
for i in range(n):
    s=input().strip()
    d[s]=d[s]+1
print('AC x '+str(d[AC]))
print('WA x '+str(d[WA]))
print('TLE x '+str(d[TLE]))
print('RE x '+str(d[RE]))


Fixed submission:
n=int(input())
d={'AC':0,'RE':0,'WA':0,'TLE':0}
for i in range(n):
    s=input().strip()
    d[s]=d[s]+1
print('AC x '+str(d['AC']))
print('WA x '+str(d['WA']))
print('TLE x '+str(d['TLE']))
print('RE x '+str(d['RE']))
Buggy python submission (verdict: Runtime Error):
x = input()

if x >= 30:
    print("Yes")
else:
    print("No")

Fixed submission:
N = int(input())
 
if N < 30:
    print("No")
else:
    print("Yes")

Buggy python submission (verdict: Runtime Error):
x = int(input())
 
if　x>29:
  print("Yes")
else:
  print("No")

Fixed submission:
N = int(input())
 
if N < 30:
    print("No")
else:
    print("Yes")

Buggy python submission (verdict: Runtime Error):
x = int(input())

if　x>29:
  print("yes")
else:
  print("no")


Fixed submission:
N = int(input())
 
if N < 30:
    print("No")
else:
    print("Yes")
Buggy python submission (verdict: Runtime Error):

K = int(input())
A, B = map(int, input().split())
cnt = 0
while true:
  cnt+=K
  if a <= cnt <= b:
    print("OK")
    break
  if b < cnt:
    print("NG")
    break

Fixed submission:
K = int(input())
A, B = map(int, input().split())
cnt = 0
while 1:
  cnt+=K
  if A <= cnt <= B:
    print("OK")
    break
  if B < cnt:
    print("NG")
    break
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
a, b = map(int, input().split())
if a<10:
  if b<10:
    print(a*b)
    else:
      print('-1')
  else:
    print('-1')
     

Fixed submission:
# -*- coding: utf-8 -*-
a, b = map(int, input().split())
if a<10 and b<10:
  print(a*b)
else:
  print(0-1)

Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
a, b = map(int, input().split())
if a<10:
  if b<10:
    print(a*b)
    else:
      print(-1)
  else:
    print(-1)
     


Fixed submission:
# -*- coding: utf-8 -*-
a, b = map(int, input().split())
if a<10 and b<10:
  print(a*b)
else:
  print(0-1)
Buggy python submission (verdict: Time Limit Exceeded):
MAX = 10 ** 18

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

ans = 1
for i in range(n):
  if ans == 0: break
  ans *= a[i]

if ans > MAX:
  print(-1)
else:
  print(ans)


Fixed submission:
MAX = 10 ** 18

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

if a[-1] == 0:
  print(0)
else:
  ans = 1
  for i in range(n):
    if ans > MAX: break
    ans *= a[i]

  if ans > MAX:
    print(-1)
  else:
    print(ans)
Buggy python submission (verdict: Runtime Error):
n, m, x = map(int, input().split())

A = [[] for _ in range(n)]
C = [0] * n

for i in range(n):
    c_as = list(map(int, input().split()))
    C[i], A[i] = c_as[0], c_as[1:]

INF = 10 ** 9
ans = INF

for s in range(1<<n):
    smart = [0] * m
    cost_sum = 0
    for i in range(n):
        if (s >> i) % 2 == 0: continue
        cost_sum += C[i]
        for j in range(m):
            smart[j] += A[i][j]

    ok = True
    for i in range(n):
        if x > smart[i]:
            ok = False
    
    if ok:
        ans = min(ans, cost_sum)

print(ans)


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

A = []
for i in range(n):
    A.append(list(map(int, input().split())))

# print(A)

ans = float("inf")
for i in range(2 ** n):
    skill = [0] * (m+1)
    for j in range(n):
        if ((i >> j) & 1):
            for k in range(m+1):
                skill[k] += A[j][k]


    # print(ans, skill)

    if skill:
        for i in range(1, m+1):
            if x > skill[i]:
                break
        else:
            ans = min(ans, skill[0])

if ans == float("inf"):
    print(-1)
else:
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
h = list(map(int, input().split()))
r = [[0] * n for _ in range(n)]

p = [0] * n

for i in range(m):
    a, b = map(int, input().split())
    a -= 1; b -= 1
    if p[a] < h[b]: p[a] = h[b]
    if p[b] < h[a]: p[b] = h[a]

ans = 0
for i in range(n):
    if h[i] > p[i]:
        ans += 1

# print(p)
print(ans)

Fixed submission:
n, m = map(int, input().split())
h = list(map(int, input().split()))
 
edeg = [[] for _ in range(n)]
for i in range(m):
    a, b = map(int, input().split())
    a -= 1; b -= 1
    edeg[a].append(b)
    edeg[b].append(a)
 
#print(edeg)

ans = 0
for node in range(n):
    good = True
    for neigber in edeg[node]:
        #print("neigber:", neigber)
        if h[node] <= h[neigber]:
            good = False
    if good:
        ans += 1 

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
h = list(map(int, input().split()))
r = [[0] * n for _ in range(n)]

p = [0] * n

for i in range(m):
    a, b = map(int, input().split())
    a -= 1; b -= 1
    if p[a] < h[b]: p[a] = h[b]
    if p[b] < h[a]: p[b] = h[a]

ans = 0
for i in range(n):
    if h[i] > p[i]:
        ans += 1

# print(p)
print(ans)

Fixed submission:
n, m = map(int, input().split())
h = list(map(int, input().split()))
 
edeg = [[] for _ in range(n)]
for i in range(m):
    a, b = map(int, input().split())
    a -= 1; b -= 1
    edeg[a].append(b)
    edeg[b].append(a)
 
#print(edeg)

ans = 0
for node in range(n):
    good = True
    for neigber in edeg[node]:
        #print("neigber:", neigber)
        if h[node] <= h[neigber]:
            good = False
    if good:
        ans += 1 

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
h = list(map(int, input().split()))
r = [[0] * n for _ in range(n)]

p = [0] * n

for i in range(m):
    a, b = map(int, input().split())
    a -= 1; b -= 1
    p[a] = max(p[a], h[b])
    p[b] = max(p[b], h[a])

ans = 0
for i in range(n):
    if h[i] > p[i]:
        ans += 1

# print(p)
print(ans)

Fixed submission:
n, m = map(int, input().split())
h = list(map(int, input().split()))
 
edeg = [[] for _ in range(n)]
for i in range(m):
    a, b = map(int, input().split())
    a -= 1; b -= 1
    edeg[a].append(b)
    edeg[b].append(a)
 
#print(edeg)

ans = 0
for node in range(n):
    good = True
    for neigber in edeg[node]:
        #print("neigber:", neigber)
        if h[node] <= h[neigber]:
            good = False
    if good:
        ans += 1 

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
s = input()[::-1]

sum_of_digits = 0

cnts = [0] * 2019
cnts[0] = 1

d = 1

for c in s:
    sum_of_digits += int(c) * d
    sum_of_digits %= 2019
    d *= 10
    d % 2019
    cnts[sum_of_digits] += 1

ans = 0

for cnt in cnts:
    ans += cnt * (cnt - 1) // 2
 
print(ans)

Fixed submission:
s = input()[::-1]

sum_of_digits = 0

cnts = [0] * 2019
cnts[0] = 1

d = 1

for c in s:
    sum_of_digits += int(c) * d
    sum_of_digits %= 2019
    d *= 10
    d %= 2019
    cnts[sum_of_digits] += 1

ans = 0

for cnt in cnts:
    ans += cnt * (cnt - 1) // 2
 
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
n = len(s)
ans = 0
for j in range(n, 3, -1):
    for i in range(j-4, -1, -1):
        num = int(s[i:j])
        if num % 2019 == 0:
            ans += 1
            break
 
print(ans)

Fixed submission:
s = input()[::-1]

sum_of_digits = 0

cnts = [0] * 2019
cnts[0] = 1

d = 1

for c in s:
    sum_of_digits += int(c) * d
    sum_of_digits %= 2019
    d *= 10
    d %= 2019
    cnts[sum_of_digits] += 1

ans = 0

for cnt in cnts:
    ans += cnt * (cnt - 1) // 2
 
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
n = len(s)
ans = 0
for i in range(n-4):
    for j in range(i+4, n+1):
        num = int(s[i:j])
        # print(num)
        if num % 2019 == 0:
            ans += 1
            # print(i, j)

print(ans)

Fixed submission:
s = input()[::-1]

sum_of_digits = 0

cnts = [0] * 2019
cnts[0] = 1

d = 1

for c in s:
    sum_of_digits += int(c) * d
    sum_of_digits %= 2019
    d *= 10
    d %= 2019
    cnts[sum_of_digits] += 1

ans = 0

for cnt in cnts:
    ans += cnt * (cnt - 1) // 2
 
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
n = len(s)
ans = 0
for i in range(n-4):
    for j in range(i+4, n+1):
        num = int(s[i:j])
        # print(num)
        if num % 2019 == 0:
            ans += 1
            # print(i, j)

print(ans)

Fixed submission:
s = input()[::-1]

sum_of_digits = 0

cnts = [0] * 2019
cnts[0] = 1

d = 1

for c in s:
    sum_of_digits += int(c) * d
    sum_of_digits %= 2019
    d *= 10
    d %= 2019
    cnts[sum_of_digits] += 1

ans = 0

for cnt in cnts:
    ans += cnt * (cnt - 1) // 2
 
print(ans)
Buggy python submission (verdict: Runtime Error):
MOD = 10 ** 9 + 7

def gauss(n):
    ans = int (n * (n + 1) / 2)
    return(ans) 

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


if k - n == 1:
    print(1)
else:
    a = [0] * (gauss(n)+2)
    t = k
    for i in range(n):
        l = gauss(t-1)
        r = gauss(n) - gauss(n-t)
        a[l] += 1
        a[r+1] -= 1
        t += 1

    for i in range(1, len(a)):
        a[i] += a[i-1]

    print(sum(a) % MOD)


Fixed submission:
MOD = 10 ** 9 + 7

def calc(a):
    smallest = a * (a-1) // 2
    largest = smallest + a * (n-a+1)
    return largest - smallest + 1 

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

ans = 0
for a in range(k, n+2):
    ans += calc(a)
    ans %= MOD

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()

R = []
G = []
B = []

for i in range(n):
    if s[i] == "R":
        R.append(i)
    if s[i] == "G":
        G.append(i)
    if s[i] == "B":
        B.append(i)

dif = 0
for r in R:
    for g in G:
        for b in B:
            if abs(g - r) == abs(g - b):
                dif += 1
            elif abs(b - r) == abs(b - g):
                dif += 1
            elif abs(r - g) == abs(r - b):
                dif += 1
             

print(len(R) * len(G) * len(B) - dif)


Fixed submission:
n = int(input())
s = input()

R_cnt = s.count("R")
G_cnt = s.count("G")
B_cnt = s.count("B")

ans = R_cnt * G_cnt * B_cnt

for i in range(n):
    for d in range(n):
        j = i + d
        k = j + d
        if k >= n: break
        if s[i] != s[j] and s[j] != s[k] and s[i] != s[k]:
            ans -= 1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()

R = []
G = []
B = []

for i in range(n):
    if s[i] == "R":
        R.append(i)
    if s[i] == "G":
        G.append(i)
    if s[i] == "B":
        B.append(i)

dif = 0
for r in R:
    for g in G:
        for b in B:
            if abs(g - r) == abs(g - b):
                dif += 1
            elif abs(b - r) == abs(b - g):
                dif += 1
            elif abs(r - g) == abs(r - b):
                dif += 1
             

print(len(R) * len(G) * len(B) - dif)

Fixed submission:
n = int(input())
s = input()

R_cnt = s.count("R")
G_cnt = s.count("G")
B_cnt = s.count("B")

ans = R_cnt * G_cnt * B_cnt

for i in range(n):
    for d in range(n):
        j = i + d
        k = j + d
        if k >= n: break
        if s[i] != s[j] and s[j] != s[k] and s[i] != s[k]:
            ans -= 1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()

R = []
G = []
B = []

for i in range(n):
    if s[i] == "R":
        R.append(i)
    if s[i] == "G":
        G.append(i)
    if s[i] == "B":
        B.append(i)

ans = 0
for r in R:
    for g in G:
        for b in B:
            if r < g and g < b and (b - g) != (g - r):
                ans += 1
            elif r < b and b < g and (g - b) != (b - r):
                ans += 1
            elif g < b and b < r and (r - b) != (b - g):
                ans += 1
            elif g < r and r < b and (b - r) != (r - g):
                ans += 1
            elif b < r and r < g and (g - r) != (r - b):
                ans += 1
            elif b < g and g < r and (r - g) != (g - b):
                ans += 1 

print(ans)


Fixed submission:
n = int(input())
s = input()

R_cnt = s.count("R")
G_cnt = s.count("G")
B_cnt = s.count("B")

ans = R_cnt * G_cnt * B_cnt

for i in range(n):
    for d in range(n):
        j = i + d
        k = j + d
        if k >= n: break
        if s[i] != s[j] and s[j] != s[k] and s[i] != s[k]:
            ans -= 1

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

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

if n == 1 or k == 1:
	print(1)
else:
	print(gcd(n, k))

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

if n >= k:
    n %= k

print(min(n, k-n))

Buggy python submission (verdict: Runtime Error):
import math

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

if n == 1 or k == 1:
	print(1)
else:
	print(math.gcd(n, k))

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

if n >= k:
    n %= k

print(min(n, k-n))
Buggy python submission (verdict: Time Limit Exceeded):
H, W, K = map(int, input().split())
s = [list(input()) for _ in range(H)]

c = [[0 for _ in range(W)] for _ in range(H)]

# 1×ｗの一次元の配列で考える。分割したマスをそれぞれホワイトチョコをカウントする
# データを加工してから貪欲法を行う

# bit全探索: 横線で割るパターン全てについて、縦線での折り方を考える
ans = (H-1) * (W-1)
for div in range(1<<(H-1)):
    g = 0 # g: 横線で分割するグループ番号（０、１、２...）
    id = [0] * H #何行目であるかを識別するid: i=1なら　グループiになる
    for i in range(H):
        id[i] = g
        if div>>i&1: # 2進法でdivのi桁目が1の時、そこで分割する
            g += 1 #分割線がきたらgを増やす
    g += 1 # グループ数は分割線+１になる
    #　集計に使うｃ配列を初期化
    for i in range(g):
        for j in range(W):
            c[i][j] = 0
    # グループごとを各列ごとのホワイトチョコを集計する
    for i in range(H):
        for j in range(W):
            c[id[i]][j] += int(s[i][j])

    num = g - 1 #すでに横線で折った回数（グループ数-１）
    now = [0] * g #現状で何個のホワイトチョコがあるか
    # 各グループの縦割りの確認
    def add(j):
        for i in range(g):
            now[i] += c[i][j] #ｊ列目のホワイトチョコを足していく
        for i in range(g):
            
            if now[i] > K: return False
        return True

    for j in range(W):
        if not (add(j)): # ホワイトチョコがKを超えていれば、縦で織る。
            num += 1
            now = [0] * g
            if not (add(j)):
                num = (H-1) * (W-1)
                break
    #print(g, c, num) # 横割りの回数、各グループの集計、最終的に折った回数
    ans = min(ans, num) # 割った回数値の最小を更新 

print(ans)

Fixed submission:
H, W, K = map(int, input().split())
s = [list(input()) for _ in range(H)]

c = [[0 for _ in range(W)] for _ in range(H)]

# 1×ｗの一次元の配列で考える。分割したマスをそれぞれホワイトチョコをカウントする
# データを加工してから貪欲法を行う

# bit全探索: 横線で割るパターン全てについて、縦線での折り方を考える
ans = (H-1) * (W-1)
for div in range(1<<(H-1)):
    g = 0 # g: 横線で分割するグループ番号（０、１、２...）
    id = [0] * H #何行目であるかを識別するid: i=1なら　グループiになる
    for i in range(H):
        id[i] = g
        if div>>i&1: # 2進法でdivのi桁目が1の時、そこで分割する
            g += 1 #分割線がきたらgを増やす
    g += 1 # グループ数は分割線+１になる
    #　集計に使うｃ配列を初期化
    for i in range(g):
        for j in range(W):
            c[i][j] = 0
    # グループごとを各列ごとのホワイトチョコを集計する
    for i in range(H):
        for j in range(W):
            c[id[i]][j] += int(s[i][j])

    num = g - 1 #すでに横線で折った回数（グループ数-１）
    now = [0] * g #現状で何個のホワイトチョコがあるか
    # 各グループの縦割りの確認
    def add(j):
        for i in range(g):
            now[i] += c[i][j] #ｊ列目のホワイトチョコを足していく
        for i in range(g):
            
            if now[i] > K: return False
        return True

    for j in range(W):
        if not (add(j)): # ホワイトチョコがKを超えていれば、縦で織る。
            num += 1
            now = [0] * g
            if not (add(j)):
                num = (H-1) * (W-1)
                break
    #print(g, c, num) # 横割りの回数、各グループの集計、最終的に折った回数
    ans = min(ans, num) # 割った回数値の最小を更新 

print(ans)
Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
sc = [list(map(int, input().split())) for _ in range(m)]

# print(sc)

a = ["0" for _ in range(n)]

for i in range(m):
    s, c = sc[i]
    s -= 1
    if n == 3 and s == 0 and c == 0:
        print(-1)
        exit()
    if n == 2 and s == 1 and c == 0:
        print(-1)
        exit()
    if n == 1 and s == 2 and c == 0:
        print(-1)
        exit()
    c = str(c)
    if i == s and a[i] != "0" and a[i] != c:
        print(-1)
        exit()
    a[s] = c

# print(a)
if a[0] == "0":
    a[0] = 1 
ans = int("".join(a))
print(ans)

Fixed submission:
n, m = map(int, input().split())
sc = [list(map(int, input().split())) for _ in range(m)]

# print(sc)

a = ["0" for _ in range(n)]

for i in range(m):
    s, c = sc[i]
    if n == 3 and s == 1 and c == 0:
        print(-1)
        exit()
    if n == 2 and s == 1 and c == 0:
        print(-1)
        exit()
    s -= 1
    c = str(c)
    if a[s] != "0" and a[s] != c:
        print(-1)
        exit()
    a[s] = c

# print(a)
if n == 1 and a[0] == "0":
    pass
elif a[0] == "0":
    a[0] = "1"
ans = int("".join(a))
print(ans)
Buggy python submission (verdict: Runtime Error):
class UnionFind():
    def __init__(self,n):
        self.n = n
        
        # parents が負の時は要素数
        # parents が正の時は親の番号
        self.parents = [-1] * n
 
    # xの根を求める
    def find(self,x):
        if self.parents[x] < 0:
            return x
        else:
            # 根を再帰的に求める
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
 
    # xとyを併合する
    def union(self,x,y):
        x = self.find(x)
        y = self.find(y)
 
        # 根が同じ場合はreturn
        if x == y:
            return
 
        # ランクを考慮（要素数の少ない木を要素数の多い木に併合）
        if self.parents[x] > self.parents[y]:
            x,y = y,x
 
        self.parents[x] += self.parents[y]
        self.parents[y] = x
 
    # xの木の要素数を求める
    def size(self,x):
        return - self.parents[self.find(x)]
 
    # xとyが同じ木なのか確かめる
    def same(self,x,y):
        return self.find(x) == self.find(y)
 
 
n, m, k = (int(x) for x in input().split())

uf = UnionFind(n)
n_find = [0] * n

for i in range(n):
    a, b = (int(x) for x in input().split())

    a -= 1
    b -= 1

    n_find[a] += 1
    n_find[b] += 1
    uf.union(a, b)

ans = [uf.size(i) -1 - n_find[i] for i in range(n)] 

for i in range(k):
    c, d = (int(x) for x in input().split())

    c -= 1
    d -= 1

    if uf.same(c, d):
        ans[c] -= 1
        ans[d] -= 1

print(*ans)

    

Fixed submission:
class UnionFind():
    def __init__(self,n):
        self.n = n
        
        # parents が負の時は要素数
        # parents が正の時は親の番号
        self.parents = [-1] * n
 
    # xの根を求める
    def find(self,x):
        if self.parents[x] < 0:
            return x
        else:
            # 根を再帰的に求める
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
 
    # xとyを併合する
    def union(self,x,y):
        x = self.find(x)
        y = self.find(y)
 
        # 根が同じ場合はreturn
        if x == y:
            return
 
        # ランクを考慮（要素数の少ない木を要素数の多い木に併合）
        if self.parents[x] > self.parents[y]:
            x,y = y,x
 
        self.parents[x] += self.parents[y]
        self.parents[y] = x
 
    # xの木の要素数を求める
    def size(self,x):
        return - self.parents[self.find(x)]
 
    # xとyが同じ木なのか確かめる
    def same(self,x,y):
        return self.find(x) == self.find(y)
 
 
n, m, k = (int(x) for x in input().split())

uf = UnionFind(n)
n_find = [0] * n

for i in range(m):
    a, b = (int(x) for x in input().split())

    a -= 1
    b -= 1

    n_find[a] += 1
    n_find[b] += 1
    uf.union(a, b)

ans = [uf.size(i) -1 - n_find[i] for i in range(n)] 

for i in range(k):
    c, d = (int(x) for x in input().split())

    c -= 1
    d -= 1

    if uf.same(c, d):
        ans[c] -= 1
        ans[d] -= 1

print(*ans)
Buggy python submission (verdict: Time Limit Exceeded):
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result


n, a, b = map(int, input().split())
MOD = 10 ** 9 + 7 

tot = 2 ** n - 1
ans = tot - cmb(n, a) - cmb(n, b)
print(ans % MOD)

Fixed submission:
mod = 10 ** 9 + 7 
def cmb(n, r, mod):
    r = min(r, n -r)
    if r == 0: return 1
    over, under = 1, 1
    for i in range(1, r+1):
        over = over * (n-i+1) % mod
        under = under * i % mod
    inv = pow(under, mod-2, mod)
    return over * inv % mod

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


ans = pow(2, n, mod) - 1 - cmb(n, a, mod) - cmb(n, b, mod)
print(ans % mod)
Buggy python submission (verdict: Time Limit Exceeded):
import collections

n = int(input())
l = [input() for i in range(n)]
c = collections.Counter(l)

m = c.most_common()[0][1]

ans = []
for i in range(len(c)):
    if m > c.most_common()[i][1]:
        break
    ans.append(c.most_common()[i][0])

ans.sort()
print(*ans)


Fixed submission:
import collections
import itertools

n = int(input())
l = [input() for _ in range(n)]
counter = collections.Counter(l)

mode_v = counter.most_common()[0][-1]
it = itertools.takewhile(
    lambda kv: kv[-1] == mode_v, counter.most_common()
)

l2 = list((k for k, v in it))
l2.sort()
print(*l2)
Buggy python submission (verdict: Time Limit Exceeded):
INF = float("inf")
dp = [[0] * 2 for _ in range(1000005)]

s = input()
s = s[::-1]
s += "0"
n = len(s)

for i in range(n+1):
    for j in range(2):
        dp[i][j] = INF
dp[0][0] = 0

for i in range(n):
    for j in range(2):
        x = int(s[i])
        x += j
        for a in range(10):
            ni = i+1
            nj = 0
            b = a- x
            if b < 0:
                nj = 1
                b += 10
            dp[ni][nj] = min(dp[ni][nj], dp[i][j]+a+b)

ans = dp[n][0]
print(ans)

Fixed submission:
dp = [0, 1]

s = input()
s = s[::-1]
s += "0"

for i in range(len(s)):
    dp0, dp1 = dp
    dp[0] = min(dp0, dp1 + 1) + int(s[i])
    dp[1] = min(dp0, dp1 - 1) + 10 - int(s[i])

print(min(dp))