Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
 
def flatten(array):
    return [item for sublist in array for item in sublist]

n, x, y = map(int, input().split())
c = [[10**4]*n for i in range(n)]
for i in range(n):
    c[i-1][i] = 1
    c[i][i-1] = 1
c[-1][0] = 10**4
c[0][-1] = 10**4
c[x-1][y-1] = 1
c[y-1][x-1] = 1
 
for k in range(n):
    for i in range(n):
        for j in range(n):
            c[i][j]=min(c[i][j],c[i][k]+c[k][j])
            c[j][j]=0

p = sorted(Counter(flatten(c)).items(), key=lambda x: x[0])[1:]
t = 0
for _, cnt in p:
    print(cnt // 2)
for _ in range(n-1-len(p)):
    print(0)

Fixed submission:
#!/usr/bin/env python3
n, x, y = map(int, input().split())
a = abs
d = [0] * n
for i in range(1, n+1):
    for j in range(i + 1, n+1):
        d[min(j-i, a(x-i)+a(y-j)+1, a(x-j)+a(y-i)+1)] += 1
print(*d[1:], sep="\n")

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter

def flatten_2dim(array):
    return [item for sublist in array for item in sublist]

n, x, y = map(int, input().split())
c = [[float("inf")]*n for i in range(n)]
for i in range(n):
    c[i-1][i] = 1
    c[i][i-1] = 1
c[-1][0] = float("inf")
c[0][-1] = float("inf")
c[x-1][y-1] = 1
c[y-1][x-1] = 1

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

counter = Counter(flatten_2dim(c))
t = 0
for _, cnt in sorted(counter.items(), key=lambda x: x[0])[1:]:
    print(cnt // 2)
    t += 1
for _ in range(n-1-t):
  print(0)

Fixed submission:
#!/usr/bin/env python3
n, x, y = map(int, input().split())
a = abs
d = [0] * n
for i in range(1, n+1):
    for j in range(i + 1, n+1):
        d[min(j-i, a(x-i)+a(y-j)+1, a(x-j)+a(y-i)+1)] += 1
print(*d[1:], sep="\n")
Buggy python submission (verdict: Runtime Error):
(x, y, a, b, c), p, q, r = [map(int, o.split()) for o in open(0)]
print(sum(sorted(sorted(p)[-x:] + sorted(q)[-y:] + r)[-x-y:]))

Fixed submission:
(x, y, a, b, c), p, q, r = [map(int, o.split()) for o in open(0)]
print(sum(sorted(sorted(p)[-x:] + sorted(q)[-y:] + list(r))[-x-y:]))
Buggy python submission (verdict: Runtime Error):
r=range;_,*s=open(0)
h,w,k=map(int,_.split())
m=9e9
for i in r(1<<h-1):
  t,v,l=[],-1,1
  for j in r(h):
    if i>>j&1:t+=j+1,;l+=1
  t+=h,
  c=[0]*l
  for i in r(w):
    b=f=g=0;u=[]
    for j in r(l):d,b=sum(s[j][i]>"0"for j in r(b,t[j])),t[j];u+=d,;g|=d>k;c[j]+=d;f|=c[j]>k
    v+=f
    if f:c=u
  if not g:m=min(m,v+l)
print(m)

Fixed submission:
from collections import Counter
_, *a = map(int, open(0).read().split())
c = Counter(a)
s = sum(c*~-c // 2 for c in c.values())
for k in a:
    print(s - c[k] + 1)
Buggy python submission (verdict: Time Limit Exceeded):
r=range;_,*s=open(0)
h,w,k=map(int,_.split())
m=9e9
for i in r(1<<h-1):
  t,v,l=[],-1,1
  for j in r(h):
    if i>>j&1:t+=j+1,;l+=1
  t+=h,
  c=[0]*l
  for i in r(w):
    b=f=g=0;u=[]
    for j in r(l):d,b=sum(s[j][i]>"0"for j in r(b,t[j])),t[j];u+=d,;g|=d>k;c[j]+=d;f|=c[j]>k
    v+=f
    if f:c=u
  if~g:m=min(m,v+l)
print(m)

Fixed submission:
r=range;_,*s=open(0)
h,w,k=map(int,_.split())
m=9e9
for i in r(1<<h-1):
 t,v,l=[],-1,1
 for j in r(h):
  if i>>j&1:t+=j+1,;l+=1
 t+=h,
 c=[0]*l
 for i in r(w):
  b=f=g=0;u=[]
  for j in r(l):d,b=sum(s[j][i]>"0"for j in r(b,t[j])),t[j];u+=d,;g|=d>k;c[j]+=d;f|=c[j]>k
  v+=f
  if f:c=u
 if not g:m=min(m,v+l)
print(m)
Buggy python submission (verdict: Runtime Error):
k = "a",
for _ in range(int(input()) - 1):
  k = {a + b for a in r for b in a + chr(ord(max(a)) + 1)}
print(*sorted(k), sep='\n')

Fixed submission:
k = "a",
for _ in range(int(input()) - 1):
  k = {a + b for a in k for b in a + chr(ord(max(a)) + 1)}
print(*sorted(k), sep='\n')
Buggy python submission (verdict: Runtime Error):
s, _, q = open(0)
g = ""
for q in q:
  p, f, c = q.split()
  if p == "1":
    g, s = s, g
  else:
    if f == "1":
      g += c
    else:
      s += c
print(g[::-1] + s)

Fixed submission:
s = input()
if s == "AAA" or s == "BBB":
    print("No")
    exit()
print("Yes")
Buggy python submission (verdict: Runtime Error):
s, _, q = open(0)
g = ""
for q in q:
  p, f, c = q.split()
  if p == "1":
    g, s = s, g
  else:
    if f == "1":
      g += c
    else:
      s += c
print(g[::-1] + s)

Fixed submission:
#!/usr/bin/env python3
s, _, *q = open(0)
g = ""
s = s.strip()
for q in q:
  q = q.strip().split()
  if q[0] == "1":
    g, s = s, g
  else:
    if q[1] == "1":
      g += q[2]
    else:
      s += q[2]
print(g[::-1] + s)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())
for _ in range(q):
    l = input()
    if l == "1":
        s = s[::-1]
    else:
        t, f, c = l.split()
        if f == "1":
            s = c + s
        else:
            s += c
print(s)

Fixed submission:
#!/usr/bin/env python3
s, _, *q = open(0)
g = ""
s = s.strip()
for q in q:
  q = q.strip().split()
  if q[0] == "1":
    g, s = s, g
  else:
    if q[1] == "1":
      g += q[2]
    else:
      s += q[2]
print(g[::-1] + s)

Buggy python submission (verdict: Runtime Error):
s = input()
q = int(input())
for _ in range(q):
    l = input()
    if ipt == "1":
        s = s[::-1]
    else:
        t, f, c = l.split()
        if f == "1":
            st = c + st
        else:
            st += c
print(st)

Fixed submission:
#!/usr/bin/env python3
s, _, *q = open(0)
g = ""
s = s.strip()
for q in q:
  q = q.strip().split()
  if q[0] == "1":
    g, s = s, g
  else:
    if q[1] == "1":
      g += q[2]
    else:
      s += q[2]
print(g[::-1] + s)

Buggy python submission (verdict: Runtime Error):
def input(): return sys.stdin.readline().strip()
st = input()
q = int(input())
for i in range(q):
    ipt = input()
    if ipt == "1":
        st = st[::-1]
    else:
        _, f, c = input().split()
        if f == "1":
            st = st + c
        else:
            st = c + st
print(st)


Fixed submission:
#!/usr/bin/env python3
s, _, *q = open(0)
g = ""
s = s.strip()
for q in q:
  q = q.strip().split()
  if q[0] == "1":
    g, s = s, g
  else:
    if q[1] == "1":
      g += q[2]
    else:
      s += q[2]
print(g[::-1] + s)

Buggy python submission (verdict: Time Limit Exceeded):
st = input()
q = int(input())
for i in range(q):
    ipt = input()
    if ipt == "1":
        st = st[::-1]
    else:
        _, f, c = ipt.split()
        if f == "1":
            st = c + st
        else:
            st = st + c
print(st)

Fixed submission:
#!/usr/bin/env python3
s, _, *q = open(0)
g = ""
s = s.strip()
for q in q:
  q = q.strip().split()
  if q[0] == "1":
    g, s = s, g
  else:
    if q[1] == "1":
      g += q[2]
    else:
      s += q[2]
print(g[::-1] + s)
Buggy python submission (verdict: Runtime Error):
#Problem C
n, m = map(int, input().split())
L = [list(map(int,input().split())) for _ in range(m)] #s_i, c_i

for i in range(10**n): #ぜんぶやる
    st = str(i)
    if len(i) == n and all(st[s-1] == str(c) for s, c in L): #長さ＝桁数がiで、かつ全てにおいて[s=c]すなわち[stのs番目の文字＝c]となるとき
        print(i)
        exit()

print(-1)

Fixed submission:
#Problem C
n, m = map(int, input().split())
L = [list(map(int,input().split())) for _ in range(m)] #s_i, c_i

for i in range(10**n): #ぜんぶやる
    st = str(i)
    if len(st) == n and all(st[s-1] == str(c) for s, c in L): #長さ＝桁数がiで、かつ全てにおいて[s=c]すなわち[stのs番目の文字＝c]となるとき
        print(i)
        exit()

print(-1)
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3

class Bit:
    # Binary Indexed Tree
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)

    def __iter__(self):
        psum = 0
        for i in range(self.size):
            csum = self.sum(i + 1)
            yield csum - psum
            psum = csum
        raise StopIteration()

    def __str__(self):  # O(nlogn)
        return str(list(self))

    def sum(self, i):
        # [0, i) の要素の総和を返す
        if not (0 <= i <= self.size): raise ValueError("error!")
        s = 0
        while i>0:
            s += self.tree[i]
            i -= i & -i
        return s

    def add(self, i, x):
        if not (0 <= i < self.size): raise ValueError("error!")
        i += 1
        while i <= self.size:
            self.tree[i] += x
            i += i & -i

    def __getitem__(self, key):
        if not (0 <= key < self.size): raise IndexError("error!")
        return self.sum(key+1) - self.sum(key)

    def __setitem__(self, key, value):
        # 足し算と引き算にはaddを使うべき
        if not (0 <= key < self.size): raise IndexError("error!")
        self.add(key, value - self[key])

(n,), (s,), _, *q = map(str.split, open(0))
*s, = s
BIT = [Bit(int(n)) for _ in [0] * 26]
for e, t in enumerate(s):
    BIT[ord(t) - 97].add(e, 1)
for a, b, c in q:
    if a == "1":
        i = int(b)
        BIT[ord(s[i - 1]) - 97].add(i - 1, -1)
        s[i - 1] = c
        BIT[ord(c) - 97].add(i - 1, 1)
    else:
        l, r = int(b), int(c)
        print(sum(BIT[i].sum(r) - BIT[i].sum(l - 1) > 0 for i in range(26)))

Fixed submission:
#!/usr/bin/env python3

class Bit:
    # Binary Indexed Tree
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)

    def __iter__(self):
        psum = 0
        for i in range(self.size):
            csum = self.sum(i + 1)
            yield csum - psum
            psum = csum
        raise StopIteration()

    def __str__(self):  # O(nlogn)
        return str(list(self))

    def sum(self, i):
        # [0, i) の要素の総和を返す
        if not (0 <= i <= self.size): raise ValueError("error!")
        s = 0
        while i>0:
            s += self.tree[i]
            i -= i & -i
        return s

    def add(self, i, x):
        if not (0 <= i < self.size): raise ValueError("error!")
        i += 1
        while i <= self.size:
            self.tree[i] += x
            i += i & -i

    def __getitem__(self, key):
        if not (0 <= key < self.size): raise IndexError("error!")
        return self.sum(key+1) - self.sum(key)

    def __setitem__(self, key, value):
        # 足し算と引き算にはaddを使うべき
        if not (0 <= key < self.size): raise IndexError("error!")
        self.add(key, value - self[key])

(n,), (s,), _, *q = map(str.split, open(0))
*s, = s
BIT = [Bit(int(n)) for _ in [0] * 26]
for e, t in enumerate(s):
    BIT[ord(t) - 97].add(e, 1)
for a, b, c in q:
    if a == "1":
        i = int(b)
        BIT[ord(s[i - 1]) - 97].add(i - 1, -1)
        s[i - 1] = c
        BIT[ord(c) - 97].add(i - 1, 1)
    else:
        l, r = int(b), int(c)
        print(sum(BIT[i].sum(r) - BIT[i].sum(l - 1) > 0 for i in range(26)))
Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
ans = 0
while True:
    if n // (k ** ans) == 0:
        break
    a += 1
print(ans)

Fixed submission:
n, k = map(int, input().split())
ans = 0
while True:
    if n // (k ** ans) == 0:
        break
    ans += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
x = list(map(int, input().split()))
t = round(sum(x) / N)
p = 0
for i in x:
    p += ((i-t)**2)
print(p)

Fixed submission:
n = int(input())
x = list(map(int, input().split()))
t = round(sum(x) / n)
p = 0
for i in x:
    p += ((i-t)**2)
print(p)
Buggy python submission (verdict: Runtime Error):
(h,n),*t=[list(map(int,o.split()))for o in open(0)]
d=[0]*(h+10100)
for i in range(1,h+1):d[i]=min(d[i-a]+b for a,b in t)
print(d[h])

Fixed submission:
h, a = map(int, input().split())
print(-(-h//a))
Buggy python submission (verdict: Time Limit Exceeded):
(h,n),*t=[list(map(int,o.split()))for o in open(0)]
d=[0]*10**8
for i in range(1,h+1):d[i]=min(d[i-a]+b for a,b in t)
print(d[h])

Fixed submission:
def chmin(dp, i, *x):
  dp[i] = min(dp[i], *x)
INF = float("inf")

# dp[i] := min 消耗する魔力 to H -= i
h, n = map(int, input().split())
dp = [0] + [INF]*h
for _ in [None]*n:
  a, b = map(int, input().split())
  for j in range(h + 1):
    chmin(dp, min(j + a, h), dp[j] + b)
print(dp[h])

Buggy python submission (verdict: Runtime Error):
(h,n),*t=[list(map(int,o.split()))for o in open(0)]
d=[0]*(h+100)
for i in range(1,h+1):d[i]=min(d[i-a]+b for a,b in t)
print(d[h])

Fixed submission:
def chmin(dp, i, *x):
  dp[i] = min(dp[i], *x)
INF = float("inf")

# dp[i] := min 消耗する魔力 to H -= i
h, n = map(int, input().split())
dp = [0] + [INF]*h
for _ in [None]*n:
  a, b = map(int, input().split())
  for j in range(h + 1):
    chmin(dp, min(j + a, h), dp[j] + b)
print(dp[h])

Buggy python submission (verdict: Runtime Error):
(h,n),*t=[list(map(int,o.split()))for o in open(0)]
d=[0]*-~h
for i in range(1,h+1):d[i]=min(d[i-a]+b for a,b in t)
print(d[h])

Fixed submission:
def chmin(dp, i, *x):
  dp[i] = min(dp[i], *x)
INF = float("inf")

# dp[i] := min 消耗する魔力 to H -= i
h, n = map(int, input().split())
dp = [0] + [INF]*h
for _ in [None]*n:
  a, b = map(int, input().split())
  for j in range(h + 1):
    chmin(dp, min(j + a, h), dp[j] + b)
print(dp[h])

Buggy python submission (verdict: Runtime Error):
(h,n),*t=[map(int,o.split())for o in open(0)]
dp=[0]*(h+10100)
for i in range(1,h+1):dp[i]=min(dp[i-a]+b for a,b in t)
print(dp[h])

Fixed submission:
def chmin(dp, i, *x):
  dp[i] = min(dp[i], *x)
INF = float("inf")

# dp[i] := min 消耗する魔力 to H -= i
h, n = map(int, input().split())
dp = [0] + [INF]*h
for _ in [None]*n:
  a, b = map(int, input().split())
  for j in range(h + 1):
    chmin(dp, min(j + a, h), dp[j] + b)
print(dp[h])
Buggy python submission (verdict: Runtime Error):
d = [0]*10**5

a = set()
w = 0

for t in open(0):
    p, s = t.split
    p = int(p)
    if "AC" == s and p not in a:
        w += d[p]
        a.add(p)
    if "WA" == s:
        d[p] += 1

print(len(a), w)

Fixed submission:
d = [0]*10**5

a = set()
w = 0

for t in open(0):
    p, s = t.split()
    p = int(p)
    if "AC" == s and p not in a:
        w += d[p]
        a.add(p)
    if "WA" == s:
        d[p] += 1

print(len(a), w)

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    _, m = map(int, input().split())
    l = []
    w = a = 0
    D = {}
    for _ in range(m):
        n, j = input().split()
        if n not in D:
            D[n] = 0
        if n not in l:
            if j == "WA":
                D[n] += 1
            else:
                a += 1
                l += [n]
                w += D[n]
    print(a, w)

if __name__ == "__main__":
    main()

Fixed submission:
d = [0]*10**5

a = set()
w = 0

for t in open(0):
    p, s = t.split()
    p = int(p)
    if "AC" == s and p not in a:
        w += d[p]
        a.add(p)
    if "WA" == s:
        d[p] += 1

print(len(a), w)

Buggy python submission (verdict: Time Limit Exceeded):
_, m = map(int, input().split())
if m == 0:
    print(0,0)
    exit()
l = []
w = a = 0
D = {}
for _ in range(m):
    n, j = input().split()
    if n not in D:
        D[n] = 0
    if n not in l:
        if j == "WA":
            D[n] += 1
        else:
            a += 1
            l += [n]
            w += D[n]
print(a, w)

Fixed submission:
d = [0]*10**5

a = set()
w = 0

for t in open(0):
    p, s = t.split()
    p = int(p)
    if "AC" == s and p not in a:
        w += d[p]
        a.add(p)
    if "WA" == s:
        d[p] += 1

print(len(a), w)

Buggy python submission (verdict: Time Limit Exceeded):
_, m = map(int, input().split())
l = []
w = a = 0
D = {}
for _ in range(m):
    n, j = input().split()
    if n not in D:
        D[n] = 0
    if n not in l:
        if j == "WA":
            D[n] += 1
        else:
            a += 1
            l += [n]
            w += D[n]
print(a, w)

Fixed submission:
d = [0]*10**5

a = set()
w = 0

for t in open(0):
    p, s = t.split()
    p = int(p)
    if "AC" == s and p not in a:
        w += d[p]
        a.add(p)
    if "WA" == s:
        d[p] += 1

print(len(a), w)

Buggy python submission (verdict: Time Limit Exceeded):
_, m = map(int, input().split())
l = []
w = a = 0
D = {}
for _ in range(m):
    n, j = input().split()
    if n not in D:
        D[n] = 0
    if n not in l:
        if j == "WA":
            D[n] += 1
        else:
            a += 1
            l += [n]
            w += D[n]
print(a, w)

Fixed submission:
d = [0]*10**5

a = set()
w = 0

for t in open(0):
    p, s = t.split()
    p = int(p)
    if "AC" == s and p not in a:
        w += d[p]
        a.add(p)
    if "WA" == s:
        d[p] += 1

print(len(a), w)
Buggy python submission (verdict: Runtime Error):
print("Yes" if int(input()) * 500 >= int(input()) else "No")

Fixed submission:
K, X = map(int, input().split())
print("Yes" if K * 500 >= X else "No")
Buggy python submission (verdict: Time Limit Exceeded):
a, b, k = map(int, input().split())
for _ in range(k):
    if a:
        a -= 1
    elif b:
        b -= 1
print(a, b)

Fixed submission:
a, b, k = map(int, input().split())
print(max(0, a - k), max(0, b - max(0, k - a)))
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3
from itertools import*
n = int(input())
c = 0
z = [eval("[i] + list(map(int, input().split())),"*int(input())) for i in range(n)]
for j in product([0,1], repeat=n):
    if all(j[i] == 0 or j[x-1] - y == 0 for i, x, y in chain.from_iterable(z)):
        c = max(c, sum(j))
print(c)

Fixed submission:
#!/usr/bin/env python3
from itertools import*
I = input
n = int(I())
c = 0;z = []
for i in range(n):
    for j in range(int(I())):
        z += [[i] + list(map(int, I().split()))]
for j in product([0,1], repeat=n):
    if all(j[i] == 0 or j[x-1] - y == 0 for i, x, y in z):
        c = max(c, sum(j))
print(c)
Buggy python submission (verdict: Runtime Error):
n,*a=map(int,open(0).read().split());c=0;i=1
for _ in[0]*61:i**=2;t=sum(i&b and 1for b in a);c+=t*(n-t)*i;c%=10**9+7
print(c


Fixed submission:
n, *a = map(int, open(0).read().split())
MOD = 10**9 + 7
c = 0
for i in range(61):
  i = 2**i
  t = sum(i & b and 1 for b in a)
  c = (c + t * (n - t) * i) % MOD
print(c)

Buggy python submission (verdict: Time Limit Exceeded):
n, *a = map(int, open(0).read().split())
MOD = 10**9 + 7
c = 0
for i in range(61):
  i = 2**i
  t = sum(i & b > 0 for b in a)
  c = (c + t * (n - t) * i) % MOD
print(c)

Fixed submission:
n, *a = map(int, open(0).read().split())
MOD = 10**9 + 7
c = 0
for i in range(61):
  i = 2**i
  t = sum(i & b and 1 for b in a)
  c = (c + t * (n - t) * i) % MOD
print(c)
Buggy python submission (verdict: Runtime Error):
_, a = open(0)
mod = 10**9+7
c = 1
l = [3] + [0]*10**6

for a in a.split():
  a = int(a)
  c = c * l[a] % mod
  d[a] -= 1
  d[a] += 1
print(c)

Fixed submission:
_, a = open(0)
mod = 10**9+7
c = 1
l = [3] + [0]*10**6

for a in a.split():
  a = int(a)
  c = c * l[a] % mod
  l[a] -= 1
  l[a+1] += 1
print(c)

Buggy python submission (verdict: Runtime Error):
_, *a = open(0)
mod = 10**9+7
c = 1
l = [3] + [0]*10**6

for a in a.split():
  a = int(a)
  c = c * l[a] % mod
  d[a] -= 1
  d[a] += 1
print(c)

Fixed submission:
_, a = open(0)
mod = 10**9+7
c = 1
l = [3] + [0]*10**6

for a in a.split():
  a = int(a)
  c = c * l[a] % mod
  l[a] -= 1
  l[a+1] += 1
print(c)
Buggy python submission (verdict: Runtime Error):
x, y = (max(4 - int(i), 0) or i in input().split())
print((x + y + 4*(x==y==3)) * 10**5)

Fixed submission:
x, y = (max(4 - int(i), 0) for i in input().split())
print((x + y + 4*(x==y==3)) * 10**5)

Buggy python submission (verdict: Runtime Error):
x, y = (max(4 - int(i), 0) or i in input().split())
print((x + y + 4*(x==y==3)) * 10**5)

Fixed submission:
x, y = (max(4 - int(i), 0) for i in input().split())
print((x + y + 4*(x==y==3)) * 10**5)
Buggy python submission (verdict: Time Limit Exceeded):
from itertools import*
n, *a = map(int, open(0).read().split())
print(min(abs(2*c - sum(a)) for c in list(accumulate(a))))

Fixed submission:
from numpy import*
n, *a = map(int, open(0).read().split())
a = array(a)
print(int(min(abs(cumsum(a)-(sum(a)/2)))*2))
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3
X, Y = map(int, input().split())
if (X + Y) % 3:
    exit(print(0))
m = (2*X - Y) // 3
n = X - 2*m
if n < 0 or m < 0:
    exit(print(0))

class Factorial:
    def __init__(self, n, mod):
        self.f = f =[0] * (n + 1)
        f[0] = b = 1
        for i in range(1, n + 1):f[i] = b = b * i % mod
        self.inv = inv = [0] * (n + 1)
        inv[n] = b = pow(self.f[n], -1, mod)
        for i in range(n,0,-1):inv[i-1] = b = b * i % mod
        self.mod = mod
    def factorial(self, i):
        return self.f[i]
    def ifactorial(self, i):
        return self.inv[i]
    def comb(self, n, k):
        if n >= k:return self.f[n] * self.inv[n - k] * self.inv[k] % self.mod
        else:return 0

def nCr(n, r, mod = None, limit = None):
    if mod and limit:
        return Factorial(limit, mod).comb(n, r)
    elif mod:
        r = min(r, n - r)
        a = 1
        for i in range(r):
            a = a * (n - i) * pow(i + 1, mod - 2, mod) % mod
        return a
    else:
        from math import factorial as f
        return f(n) // (f(n - r) * f(r))

MOD = 10**9+7
print(nCr(m + n, n, MOD, 2*10**6))

Fixed submission:
#!/usr/bin/env python3
X, Y = map(int, input().split())
if (X + Y) % 3:
    exit(print(0))
m = (2*X - Y) // 3
n = X - 2*m
if n < 0 or m < 0:
    exit(print(0))

## class
def egcd(a, b):
    if a == 0:
        return (b, 0, 1)
    else:
        g, y, x = egcd(b % a, a)
        return (g, x - (b // a) * y, y)

def modinv(a, m):
    g, x, y = egcd(a, m)
    if g != 1:
        raise Exception('modular inverse does not exist')
    else:
        return x % m

def power(a, b, c):
    try:
        return pow(a, b, c)
    except (ValueError, TypeError) as e:
        if b < 0:
            return pow(modinv(a, c), -b, c)
        else:
            print(e)

class Factorial:
    def __init__(self, n, mod):
        self.f = f =[0] * (n + 1)
        f[0] = b = 1
        for i in range(1, n + 1):f[i] = b = b * i % mod
        self.inv = inv = [0] * (n + 1)
        inv[n] = b = power(self.f[n], -1, mod)
        for i in range(n,0,-1):inv[i-1] = b = b * i % mod
        self.mod = mod
    def factorial(self, i):
        return self.f[i]
    def ifactorial(self, i):
        return self.inv[i]
    def comb(self, n, k):
        if n >= k:return self.f[n] * self.inv[n - k] * self.inv[k] % self.mod
        else:return 0

def nCr(n, r, mod = None, limit = None):
    if mod and limit:
        return Factorial(limit, mod).comb(n, r)
    elif mod:
        r = min(r, n - r)
        a = 1
        for i in range(r):
            a = a * (n - i) * power(i + 1, mod - 2, mod) % mod
        return a
    else:
        from math import factorial as f
        return f(n) // (f(n - r) * f(r))

MOD = 10**9+7
print(nCr(m + n, n, MOD, 2*10**6))
Buggy python submission (verdict: Runtime Error):
from bisect import*
l = sorted(map(int, open(0).read().split()[1:]))
print(sum(max(0, bisect_left(l, l[i] + l[j]) - j - 1) for i in range(n) for j in range(i+1, n)))

Fixed submission:
from bisect import*
n, *l = map(int, open(0).read().split())
l.sort();c=0
for i in range(n):
  for j in range(i+1, n):
    d = bisect_left(l, l[i] + l[j])
    c += max(0, d-j-1)
print(c)
Buggy python submission (verdict: Runtime Error):
import numpy as np
*s, a, b = map(int, input().split())
p = np.ones(s, dtype=np.int)
p[:b,:a] = 0
p[b:,a:] = 0
print('\n'.join(''.join(q) for q in m.astype(str)))

Fixed submission:
import numpy as np
*s, a, b = map(int, input().split())
p = np.ones(s, dtype=np.int)
p[:b,:a] = 0
p[b:,a:] = 0
print('\n'.join(''.join(q) for q in p.astype(str)))

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
*s, a, b = map(int, input().split())
p = np.ones(s, dtype=np.int)
p[:b,:a] = 0
p[b:,a:] = 0
for i in p:
    print(*i, sep="")

Fixed submission:
import numpy as np
*s, a, b = map(int, input().split())
p = np.ones(s, dtype=np.int)
p[:b,:a] = 0
p[b:,a:] = 0
print('\n'.join(''.join(q) for q in p.astype(str)))