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

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

Buggy submission (verdict: Runtime Error):
s, w = map(int, input(),split())
if w > s:
  print("unsafe")
else:
  print("safe")
Problem p02679 (python)

Fixed submission:
import math,sys
input = sys.stdin.readline
from collections import defaultdict
n = int(input())
MOD = 1000000007
d = defaultdict(int)
l,r = 0,0
count = 0
for i in range(n):
  a,b = map(int,input().split())
  if a == b == 0:
    count += 1
    continue
  elif a == 0 or b == 0:
    if a == 0:
      l += 1
    else:
      r += 1
  else:
    g = math.gcd(a,b)
    a,b = a//g,b//g
    if a<0:
      a,b = -a,-b
    d[str(a)+':'+str(b)] += 1
c = 1
for i in d.keys():
  if d[i] != 0:
    cur = pow(2,d[i],MOD)
    if '-' in i:
      ind = i.index(':')
      ci = i[ind+2:] + ':' + i[:ind]
    else:
      ind = i.index(':')
      ci = i[ind+1:] + ':-' + i[:ind]
    if ci in d.keys():
      cur += pow(2,d[ci],MOD)-1
      d[ci] = 0
    c = (c*cur)%MOD
c = (c*(pow(2,l,MOD)+pow(2,r,MOD)-1)-1+count)%MOD
print(c)

Buggy submission (verdict: Runtime Error):
import math,sys
input = sys.stdin.readline
from collections import defaultdict
n = int(input())
MOD = 1000000007
d = defaultdict(int)
for i in range(n):
  a,b = map(int,input().split())
  g = math.gcd(a,b)
  a,b = a//g,b//g
  if a<0:
    a,b = -a,-b
  d[str(a)+':'+str(b)] += 1
c = 1
for i in d.keys():
  if d[i] != 0:
    cur = pow(2,d[i],MOD)
    if '-' in i:
      ind = i.index(':')
      ci = i[ind+2:] + ':' + i[:ind]
    else:
      ind = i.index(':')
      ci = i[ind+1:] + ':-' + i[:ind]
    if ci in d.keys():
      cur += pow(2,d[ci],MOD)-1
      d[ci] = 0
    c = (c*cur)%MOD
print(c-1)
Problem p02771 (python)

Fixed submission:
print("YNeos"[len(set(map(int,input().split())))!=2::2])

Buggy submission (verdict: Runtime Error):
print("YNeos"[len(set(map(int,open(0))))!=2::2])
Problem p02793 (python)

Fixed submission:
from collections import defaultdict
n = int(input())
a = list(map(int,input().split()))
MOD = 10**9+7
def prime_table(n):
  if n <= 1:
    return [],[],[]
  prime = [2]
  limit = int(n**0.5)
  data = [i+1 for i in range(2,n,2)]
  isprime = [0]*(n+1)
  isprime[2] = 1
  min_factor = [0 if i%2 != 0 else 2 for i in range(n+1)]
  while True:
    p = data[0]
    prime.append(p)
    isprime[p] = 1
    pdata,data = data,[]
    for e in pdata:
      if e%p != 0:
        data.append(e)
      else:
        min_factor[e] = p
    if limit <= p:
      for i in data:
        isprime[i] = 1
        min_factor[i] = i
      return prime + data,isprime,min_factor
def modinv(a,m=MOD):
  b,u,v = m,1,0
  while b:
    t = a//b
    a,u = a-t*b,u-t*v
    a,b,u,v = b,a,v,u
  u %= m
  if u < 0:
    u += m
  return u
ma = max(a)
data,isprime,min_factor = prime_table(ma)
prime = [0] * (ma+1)
for i in a:
  if i == 1:
    continue
  d = defaultdict(int)
  while isprime[i] == 0:
    d[min_factor[i]] += 1
    i = i // min_factor[i]
  d[i] += 1
  for j,k in d.items():
    prime[j] = max(prime[j],k)
lcm = 1
for i in range(ma+1):
  if prime[i] != 0:
    lcm = (lcm*pow(i,prime[i],MOD))%MOD
c = 0
for i in a:
  c += lcm*modinv(i,MOD)
  c %= MOD
print(c)

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
n = int(input())
a = list(map(int,input().split()))
MOD = 10**9+7
def prime_table(n):
  prime = [2]
  limit = int(n**0.5)
  data = [i+1 for i in range(2,n,2)]
  isprime = [0]*(n+1)
  isprime[2] = 1
  min_factor = [0 if i%2 != 0 else 2 for i in range(n+1)]
  while True:
    p = data[0]
    prime.append(p)
    isprime[p] = 1
    pdata,data = data,[]
    for e in pdata:
      if e%p != 0:
        data.append(e)
      else:
        min_factor[e] = p
    if limit <= p:
      for i in data:
        isprime[i] = 1
        min_factor[i] = i
      return prime + data,isprime,min_factor
def modinv(a,m=MOD):
  b,u,v = m,1,0
  while b:
    t = a//b
    a,u = a-t*b,u-t*v
    a,b,u,v = b,a,v,u
  u %= m
  if u < 0:
    u += m
  return u
ma = max(a)
data,isprime,min_factor = prime_table(ma)
prime = [0] * (ma+1)
for i in a:
  d = defaultdict(int)
  while isprime[i] == 0:
    d[min_factor[i]] += 1
    i = i // min_factor[i]
  d[i] += 1
  for j,k in d.items():
    prime[j] = max(prime[j],k)
lcm = 1
for i in range(ma+1):
  if prime[i] != 0:
    lcm = (lcm*pow(i,prime[i],MOD))%MOD
c = 0
for i in a:
  c += lcm*modinv(i,MOD)
  c %= MOD
print(c)
Problem p02954 (python)

Fixed submission:
s = input()
l = []
for i in range(len(s)-1):
  if s[i] != s[i+1]:
    l.append(i)
a = [0] * len(s)
if len(l) == 1:
  a[l[0]] = (l[0]+2)//2 + (len(s)-l[0]-1)//2
  a[l[0]+1] = (l[0]+1)//2 + (len(s)-l[0])//2
  print(' '.join(map(str,a)))
  exit()
a[l[0]] = (l[0]+2)//2 + (l[1]-l[0])//2
a[l[0]+1] = (l[0]+1) // 2 + (l[1]-l[0]+1)//2
i = 2
while True:
  if i == len(l)-1:
    break
  a[l[i]] = (l[i]-l[i-1]+1)//2 + (l[i+1]-l[i])//2
  a[l[i]+1] = (l[i]-l[i-1])//2 + (l[i+1]-l[i]+1)//2
  i += 2
a[l[-1]] = (l[-1]-l[-2]+1)//2 + (len(s)-l[-1]-1)//2
a[l[-1]+1] = (l[-1]-l[-2])//2 + (len(s)-l[-1])//2
print(' '.join(map(str,a)))

Buggy submission (verdict: Runtime Error):
s = input()
l = []
for i in range(len(s)-1):
  if s[i] != s[i+1]:
    l.append(i)
a = [0] * len(s)
a[l[0]] = (l[0]+2)//2 + (l[1]-l[0])//2
a[l[0]+1] = (l[0]+1) // 2 + (l[1]-l[0]+1)//2
i = 2
while True:
  if i == len(l)-1:
    break
  a[l[i]] = (l[i]-l[i-1]+1)//2 + (l[i+1]-l[i])//2
  a[l[i]+1] = (l[i]-l[i-1])//2 + (l[i+1]-l[i]+1)//2
  i += 2
a[l[-1]] = (l[-1]-l[-2]+1)//2 + (len(s)-l[-1]-1)//2
a[l[-1]+1] = (l[-1]-l[-2])//2 + (len(s)-l[-1])//2
print(' '.join(map(str,a)))
Problem p02987 (python)

Fixed submission:
s=list(input())
s.sort()
print("YNeos"[not s[0]==s[1]!=s[2]==s[3]::2])

Buggy submission (verdict: Runtime Error):
s=input()
s.sort()
print(s)
Problem p03013 (python)

Fixed submission:
import sys
n,m = map(int,input().split())
a = list(map(int,sys.stdin))
a.append(0)
prev=0
cur=1
m=0
for i in range(1,n+1):
  if a[m]==i:
    prev,cur = cur,0
    m += 1
  else:
    prev,cur = cur,(cur+prev)%1000000007
print(cur)

Buggy submission (verdict: Runtime Error):
import sys
n,m=map(int,input().split())
arr=[1,2]
arr=arr+[0]*(n-2)
danger=tuple(map(int,sys.stdin))
m=0
if 1 == danger[0]:
  arr[0]=0
  arr[1]=1
  m=1
for i in range(n):
  if i+1 == danger[m]:
    arr[i]=0
    m+=1
  elif i==0 or i==1:
    continue 
  else:
    arr[i]=(arr[i-1]+arr[i-2])%(10**9+7)
print(arr[n-1]%(10**9+7))

Buggy submission (verdict: Runtime Error):
import sys
n,m=map(int,input().split())
arr=[1,2]
arr=arr+[0]*(n-2)
danger=tuple(map(int,sys.stdin))
m=0
if 1 == danger[0]:
  arr[0]=0
  arr[1]=1
  m=1
for i in range(n):
  if i+1 in danger[m]:
    arr[i]=0
    m+=1
  elif i==0 or i==1:
    continue 
  else:
    arr[i]=(arr[i-1]+arr[i-2])%(10**9+7)
print(arr[n-1]%(10**9+7))

Buggy submission (verdict: Runtime Error):
import sys
def fib(a):
  if a==1:
    return 1
  elif a==0:
    return 1
  else:
    return fib(a-1)+fib(a-2)
def count(a,b):
  if a+1==b:
    return 0
  else:
    return fib(b-a-2)
n,m=map(int,input().split())
a=list(map(int,sys.stdin))
for _ in range(m+1):
  if _ == 0:
    sum = fib(a[_]-1)
  elif _ == m:
    sum = sum*fib(n-a[_-1]-1)%1000000007
  else:
    sum = sum*count(a[_-1],a[_])%1000000007
print(sum)
Problem p03075 (python)

Fixed submission:
a=int(input())
b=int(input())
c=int(input())
d=int(input())
e=int(input())
k=int(input())
f=min(a,b,c,d,e)
g=max(a,b,c,d,e)
h=g-f
if h <= k:
  print('Yay!')
else:
  print(':(')

Buggy submission (verdict: Runtime Error):
a=input()
b=input()
c=input()
d=input()
e=input()
k=input()
f=min(a,b,c,d,e)
g=max(a,b,c,d,e)
h=g-f
if h <= k:
  print('Yay')
else:
  print(':(')
Problem p03242 (python)

Fixed submission:
n=list(input())
for i in range(3):
  if n[i] == "1":
    n[i] = "9"
  else:
    n[i] = "1"
print("".join(n))

Buggy submission (verdict: Runtime Error):
n=list(map(int,input().split()))
for i in range(3):
  if n[i] == 1:
    n[i] = 9
  else:
    n[i] = 1
print("".join(n))
Problem p03631 (python)

Fixed submission:
from copy import deepcopy as dp
s=list(input())
t=dp(s)
s.reverse()
if s==t:
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
s=input()
t=s.reverse()
if s==t:
  print("Yes")
else:
  print("No")
Problem p02707 (python)

Fixed submission:
a = int(input())
lists = list(map(int, input().split())) #１行の入力をi[0],i[1]というように空白で分けてを取得し、iに値を入れる

num = [0]*a

def mi(x):

    
    return int(x-1)

y = list(map(mi,lists))

for i in range(a-1):
    num[y[i]] += 1
for i in range(a):
    print(num[i])

Buggy submission (verdict: Runtime Error):

a = int(input())
lists = list(map(int, input().split())) #１行の入力をi[0],i[1]というように空白で分けてを取得し、iに値を入れる

num = [0]*a

def mi(x):

    
    return int(x-1)

y = list(map(mi,lists))

for i in range(a):
    #print('y')
   # print(i)
    num[y[i]] += 1
for i in range(a):
    print(num[i])

Buggy submission (verdict: Runtime Error):

a = int(input())
lists = list(map(int, input().split())) #１行の入力をi[0],i[1]というように空白で分けてを取得し、iに値を入れる

num = [0]*a

def mi(x):

    
    return int(x-1)

y = list(map(mi,lists))
print(y)
for i in range(a):
    #print('y')
   # print(i)
    num[y[i]] += 1
for i in range(a):
    print(num[i])
Problem p02754 (python)

Fixed submission:
N, A, B = map(int, input().split())
stck = N // (A + B) * A
remn = N % (A + B)
stck += min(remn, A)
print(stck)

Buggy submission (verdict: Runtime Error):
N, A, B = map(int, input().split())
ball = ""

while len(ball) < N:
  ball += "b" * A
  ball += "r" * B

ball_n = ball[:N]
print(ball_n.count("b"))
Problem p02682 (python)

Fixed submission:
a, b, c, k = [int(i) for i in input().split()]

if k <= a and k - a <= b:
	print(k)
else:
	print(a - (k - a - b))

Buggy submission (verdict: Runtime Error):
a, b, c, k = [int(i) for i in input().split()]

if k <= a and k - a <= b:
	print(k)
else
	print(a - (k - a - b))
Problem p02729 (python)

Fixed submission:
from sys import stdin

n, m = [int(x) for x in stdin.readline().rstrip().split()]

even_only = 0
odd_only = 0

if n > 1:
    even_only = n * (n - 1) / 2
if m > 1:
    odd_only = m * (m - 1) / 2

result = int(even_only + odd_only)
print(result)

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

lines = stdin.readlines()

n = int(lines[0].rstrip())
a = [int(x) for x in lines[1].rstrip().split()]

count = Counter(a)
c = {k:v for k,v in filter(lambda kv: kv[1]>1, count.items())}
res = []
for k in range(n):
    part_res = 0
    for i in c.keys():
        if not i == a[k]:
            quant = c[i]
        else:
            quant = c[i] - 1
        if quant > 1:
            part_res += int((quant * (quant - 1)) / 2)
    res.extend([part_res])

for j in range(len(res)):
    print(res[j])

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

lines = stdin.readlines()

n = int(lines[0].rstrip())
a = [int(x) for x in lines[1].rstrip().split()]

c = Counter(a)

res = []
for k in range(n):
    part_res = 0
    for i in c.keys():
        if not i == a[k]:
            quant = c[i]
        else:
            quant = c[i] - 1
        if quant > 1:
            part_res += int((quant * (quant - 1)) / 2)
    res.extend([part_res])

for j in range(len(res)):
    print(res[j])
Problem p02753 (python)

Fixed submission:
from sys import stdin

s = stdin.readline().rstrip()

count = 0
if s[0] == 'A':
    if s[1] == 'B':
        count += 1
if s[1] == 'A':
    if s[2] == 'B':
        count += 1
if s[0] == 'B':
    if s[1] == 'A':
        count += 1
if s[1] == 'B':
    if s[2] == 'A':
        count += 1
if count > 0:
    print('Yes')
else:
    print('No')

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

A, B = [int(x) for x in stdin.readline().rstrip().split()]

min_eight_ex_tax = float(A / 0.08)
max_eight_ex_tax = float((A + 1) / 0.08)
min_ten_ex_tax = int(B / 0.1)
max_ten_ex_tax = int((B + 1) / 0.1)

res = float(-1)
for x in range(min_ten_ex_tax, max_ten_ex_tax, 1):
    if min_eight_ex_tax <= x < max_eight_ex_tax:
        res = float(x)
        break
#print(min_eight_ex_tax, max_eight_ex_tax, min_ten_ex_tax, max_ten_ex_tax)
print(int(res))
Problem p02779 (python)

Fixed submission:
N = int(input())
A =list(map(int,input().split()))
A.sort()
for i in range(N-1):
    if A[i] == A[i+1]:
        print('NO')
        exit()
print('YES')

Buggy submission (verdict: Runtime Error):
N = int(input())
A =list(map(int,input()))
A.sort()
for i in range(N-1):
    if A[i] == A[i+1]:
        print('NO')
        exit()
print('YES')
Problem p03805 (python)

Fixed submission:
import itertools

N,M=map(int,input().split())
S=[list(map(int,input().split()))for _ in range(M) ]

a=[]
for i in range(N):
    a.append(i+1)

L=list(itertools.permutations(a))


cnt=0

for l in L:
    tmp=1
    if l[0]!=1:
        break
    for j in range(N-1):
        if ([l[j],l[j+1]] in S) or ([l[j+1],l[j]] in S):
            tmp=1
        else:
            tmp=0
            break
    if tmp==1:
        cnt+=1

print(cnt)

Buggy submission (verdict: Runtime Error):
import itertools

N,M=map(int,input().split())
if M==0:
    print(0)
    exit()
S=[list(map(int,input().split()))for _ in range(N) ]

a=[]
for i in range(N):
    a.append(i+1)

L=list(itertools.permutations(a))


cnt=0

for l in L:
    tmp=1
    if l[0]!=1:
        break
    for j in range(N-1):
        if ([l[j],l[j+1]] in S) or ([l[j+1],l[j]] in S):
            tmp=1
        else:
            tmp=0
            break
    if tmp==1:
        cnt+=1

print(cnt)

Buggy submission (verdict: Runtime Error):
import itertools

N,M=map(int,input().split())
S=[list(map(int,input().split()))for _ in range(N) ]

a=[]
for i in range(N):
    a.append(i+1)

L=list(itertools.permutations(a))


cnt=0

for l in L:
    tmp=1
    if l[0]!=1:
        break
    for j in range(N-1):
        if ([l[j],l[j+1]] in S) or ([l[j+1],l[j]] in S):
            tmp=1
        else:
            tmp=0
            break
    if tmp==1:
        cnt+=1

print(cnt)
Problem p02831 (python)

Fixed submission:
import math
a, b = map(int, input().split())

i = 1
flag = True
while(flag):
    if (a * i) % b == 0:
        flag = False
        ans = a * i
        break
    i += 1

print(ans)

Buggy submission (verdict: Runtime Error):
import math
a, b = map(int, input().split())
print((a * b) // math.gcd(a, b))
Problem p03038 (python)

Fixed submission:
#!/usr/bin/env python3
from collections import defaultdict
import sys
try:
    from typing import List
except ImportError:
    pass


def solve(N: int, M: int, A: "List[int]", B: "List[int]", C: "List[int]"):
    d = defaultdict(int)
    for Bi, Ci in zip(B, C):
        d[Ci] += Bi

    k = [0] * N
    i = 0
    for key in sorted(d.keys(), reverse=True):
        newi = min(N, i + d[key])
        for j in range(i, newi):
            k[j] = key
        i = newi
        if newi > N:
            break
    print(sum(sorted(A + k, reverse=True)[:N]))


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    B = [int()] * (M)  # type: "List[int]"
    C = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        B[i] = int(next(tokens))
        C[i] = int(next(tokens))
    solve(N, M, A, B, C)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
from collections import defaultdict
import sys
try:
    from typing import List
except ImportError:
    pass


def solve(N: int, M: int, A: "List[int]", B: "List[int]", C: "List[int]"):
    d = defaultdict(int)
    for Bi, Ci in zip(B, C):
        d[Ci] += Bi

    k = [0] * 0
    for key in sorted(d.keys(), reverse=True):
        k += [key] * d[key]
        if len(k) > N:
            break
    print(sum(sorted(A + k, reverse=True)[:N]))


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    B = [int()] * (M)  # type: "List[int]"
    C = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        B[i] = int(next(tokens))
        C[i] = int(next(tokens))
    solve(N, M, A, B, C)


if __name__ == '__main__':
    main()
Problem p03045 (python)

Fixed submission:
#!/usr/bin/env python3
import sys
try:
    from typing import List
except ImportError:
    pass


sys.setrecursionlimit(1000000)


def solve(N: int, M: int, X: "List[int]", Y: "List[int]", Z: "List[int]"):
    par = list(range(N))

    def getpar(n: int):
        if par[n] == n:
            return n
        par[n] = getpar(par[n])
        return par[n]

    def union(a: int, b: int):
        par[getpar(b)] = getpar(a)

    for Xi, Yi in zip(X, Y):
        Xi -= 1
        Yi -= 1
        union(Xi, Yi)

    print(len({getpar(i) for i in range(N)}))


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    X = [int()] * (M)  # type: "List[int]"
    Y = [int()] * (M)  # type: "List[int]"
    Z = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        X[i] = int(next(tokens))
        Y[i] = int(next(tokens))
        Z[i] = int(next(tokens))
    solve(N, M, X, Y, Z)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys
try:
    from typing import List
except ImportError:
    pass


def solve(N: int, M: int, X: "List[int]", Y: "List[int]", Z: "List[int]"):
    par = list(range(N))

    def getpar(n: int):
        if par[n] == n:
            return n
        par[n] = getpar(par[n])
        return par[n]

    def union(a: int, b: int):
        par[getpar(b)] = par[getpar(a)]

    for Xi, Yi in zip(X, Y):
        Xi -= 1
        Yi -= 1
        union(Xi, Yi)

    print(len({getpar(i) for i in range(N)}))


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    X = [int()] * (M)  # type: "List[int]"
    Y = [int()] * (M)  # type: "List[int]"
    Z = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        X[i] = int(next(tokens))
        Y[i] = int(next(tokens))
        Z[i] = int(next(tokens))
    solve(N, M, X, Y, Z)


if __name__ == '__main__':
    main()
Problem p03108 (python)

Fixed submission:
#!/usr/bin/env python3
import sys
try:
    from typing import List
except ImportError:
    pass


sys.setrecursionlimit(1000000)


def solve(N: int, M: int, A: "List[int]", B: "List[int]"):
    uf = list(range(N))
    n = [1] * N

    def getpar(a: int):
        if a == uf[a]:
            return a
        uf[a] = getpar(uf[a])
        return uf[a]

    def union(a: int, b: int):
        pa = getpar(a)
        pb = getpar(b)
        if pa == pb:
            return 0, 0
        ra = n[pa]
        rb = n[pb]
        n[pa] += n[pb]
        uf[pb] = uf[pa]
        return ra, rb

    k = N * (N - 1) // 2
    ans = []
    A.reverse()
    B.reverse()
    for Ai, Bi in zip(A, B):
        Ai -= 1
        Bi -= 1
        ra, rb = union(Ai, Bi)
        ans.append(k)
        k -= ra * rb

    assert k == 0, k
    for ansi in reversed(ans):
        print(ansi)


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    A = [int()] * (M)  # type: "List[int]"
    B = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        A[i] = int(next(tokens))
        B[i] = int(next(tokens))
    solve(N, M, A, B)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys
try:
    from typing import List
except ImportError:
    pass


def solve(N: int, M: int, A: "List[int]", B: "List[int]"):
    uf = list(range(N))
    n = [1] * N

    def getpar(a: int):
        if a == uf[a]:
            return a
        uf[a] = getpar(uf[a])
        return uf[a]

    def union(a: int, b: int):
        pa = getpar(a)
        pb = getpar(b)
        if pa == pb:
            return 0, 0
        ra = n[pa]
        rb = n[pb]
        n[pa] += n[pb]
        uf[pb] = uf[pa]
        return ra, rb

    k = N * (N - 1) // 2
    ans = []
    A.reverse()
    B.reverse()
    for Ai, Bi in zip(A, B):
        Ai -= 1
        Bi -= 1
        ra, rb = union(Ai, Bi)
        ans.append(k)
        k -= ra * rb

    assert k == 0, k
    for ansi in reversed(ans):
        print(ansi)


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    A = [int()] * (M)  # type: "List[int]"
    B = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        A[i] = int(next(tokens))
        B[i] = int(next(tokens))
    solve(N, M, A, B)


if __name__ == '__main__':
    main()
Problem p03222 (python)

Fixed submission:
#!/usr/bin/env python3
from itertools import product
import sys

try:
    from typing import List, Tuple
except ImportError:
    pass


MOD = 1000000007  # type: int


def isvalid(ptn: "Tuple[bool]"):
    return not any(h1 and h2 for h1, h2 in zip(ptn, ptn[1:]))


def solve(H: int, W: int, K: int):
    validptns = [
        ptn
        for ptn in product((False, True), repeat=W - 1)
        if isvalid(ptn)
    ]  # type: List[Tuple[bool]]
    dp = [1 if i == K - 1 else 0 for i in range(W)]  # type: List[int]
    for _ in range(H):
        newdp = [0] * W  # type: List[int]
        for ptn in validptns:
            for s in range(W):
                t = s
                if s < W - 1 and ptn[s]:
                    t = s + 1
                elif s > 0 and ptn[s - 1]:
                    t = s - 1
                newdp[t] += dp[s]
                newdp[t] %= MOD
        dp = newdp

    print(dp[0])


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(H, W, K)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
from itertools import product
import sys

try:
    from typing import Dict, List, Tuple
except ImportError:
    pass


MOD = 1000000007  # type: int


def isvalid(ptn: "Tuple[bool]"):
    return not any(h1 and h2 for h1, h2 in zip(ptn, ptn[1:]))


def solve(H: int, W: int, K: int):
    validptns: "List[Tuple[bool]]" = [
        ptn
        for ptn in product((False, True), repeat=W - 1)
        if isvalid(ptn)
    ]
    dp: "List[int]" = [1 if i == K - 1 else 0 for i in range(W)]
    for _ in range(H):
        newdp: "List[int]" = [0] * W
        for ptn in validptns:
            for s in range(W):
                t = s
                if s < W - 1 and ptn[s]:
                    t = s + 1
                elif s > 0 and ptn[s - 1]:
                    t = s - 1
                newdp[t] += dp[s]
                newdp[t] %= MOD
        dp = newdp

    print(dp[0])


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(H, W, K)


if __name__ == '__main__':
    main()
Problem p03327 (python)

Fixed submission:
a=raw_input()
if int(a) >= 1000:
  print "ABD"
else:
  print "ABC"

Buggy submission (verdict: Runtime Error):
a=raw_input()
if a[0] == "1":
  print "ABD" + int(a[1:]+1-1000)
else:
  print "ABC" + a