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

Fixed submission:
A=list(input())
B=[]
a=A[0]
cnt1=0
cnt2=0
for i in range(4):
    if(a==A[i]):
        cnt1+=1
    else:
        B.append(A[i])

if(cnt1==2):
    b=B[0]
    for i in range(2):
        if(b==B[i]):
            cnt2+=1
    if(cnt2==2):
        print("Yes")
    else:
        print("No")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
A=list(input())
B=[]
a=A[0]
cnt1=0
cnt2=0
for i in range(4):
    if(a==A[i]):
        cnt1+=1
    else:
        B.append(A[i])
b=B[0]
if(cnt1==2):
    for i in range(2):
        if(b==B[i]):
            cnt2+=1
    if(cnt2==2):
        print("Yes")
    else:
        print("No")        
else:
    print("No")
Problem p03041 (python)

Fixed submission:
N,K=(int(i) for i in input().split())
s=input()
S=list(s)

if(S[K-1]=='A'):
    S[K-1]='a'
elif(S[K-1]=='B'):
    S[K-1]='b'
elif(S[K-1]=='C'):
    S[K-1]='c'

A=''.join(S)
print(A)

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

a=S/100
b=S%100

if((a>12 or a==0) and 1<=b<=12):
        print("YYMM")

elif(1<=a<=12 and (b>12 or b==0)):
        print("MMYY")

elif(1<=a<=12 and 1<=b<=12):
        print('AMBIGUOUS')

else:
    print("NA")

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

a=S/100
b=S%100

if(a>12 and b>12):
    print("NA")

elif(a==0 and b==0):
    print("NA")

elif((a>12 or a==0) and 1<=b<=12):
        print("YYMM")

elif(1<=a<=12 and (b>12 or b==0)):
        print("MMYY")

elif(1<=a<=12 and 1<=b<=12):
        print('AMBIGUOU')

else:
    print("NA")
Problem p03042 (python)

Fixed submission:
n = int(input()[:4])
a = n//100
b = n%100
if 0<a<=12 and 0<b<=12:
    print('AMBIGUOUS')
elif 1<=a<=12 and (b>=13 or b==0):
    print('MMYY')
elif 1<=b<=12 and (13<=a or a==0):
    print('YYMM')
else:
    print('NA')

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

a=S/100
b=S%100

if(a>12 and b>12):
    print("NA")

elif(a==0 and b==0):
    print("NA")

elif((a>12 or a=0) and 1<=b<=12):
        print("YYMM")

elif(1<=a<=12 and (b>12 or b=0)):
        print("MMYY")

elif(1<=a<=12 and 1<=b<=12):
        print('AMBIGUOU')

else:
    print("NA")
Problem p03036 (python)

Fixed submission:
r, D, x0 = map(int, input().split())
x_tmp = x0
 
for i in range(1, 11):
  x = r * x_tmp - D
  x_tmp = x
  print(x)

Buggy submission (verdict: Runtime Error):
r, D, x0 = map.(int, input().split())
x_tmp = x0

for i in range(1, 11):
  x = r * x_tmp - D
  print(x)
Problem p03137 (python)

Fixed submission:
# -*- coding: utf-8 -*-

N, M = map(int, input().split())
X = [int(v) for v in input().split()]
lx = len(X)

# N=10^5, M=10^5ならO(NM)は間に合わない

if N >= M:
    print(0)
else:
    # 動的計画法M個の地点を1~N個のコマで回ることを考える。

    X.sort()    # 昇順にソート
    coma = [0] * N
    # n=1
    diff = [x2-x1 for x2, x1 in zip(X[1:], X[:-1])]
    diff.sort() # 昇順にソート
    coma[0] = sum(diff)

    # n >= 2
    for i in range(1, N):
        coma[i] = coma[i-1] - diff[-1]
        del diff[-1]

    print(coma[-1])

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

N, M = map(int, input().split())
X = [int(v) for v in input().split()]
lx = len(X)

# N=10^5, M=10^5ならO(NM)は間に合わない

# 動的計画法M個の地点を1~N個のコマで回ることを考える。
coma = [0] * N
X.sort()    # 昇順にソート

# n=1
diff = [x2-x1 for x2, x1 in zip(X[1:], X[:-1])]
diff.sort() # 昇順にソート
coma[0] = sum(diff)

if coma[0] == 0:
    print(0)
else:
    for i in range(1, N):
        coma[i] = coma[i-1] - diff[-1]
        del diff[-1]

    print(coma[-1])
Problem p03012 (python)

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

min = float('inf')

for i in range(1,n):
    sa = abs( sum(w[0:i]) - sum(w[i:]) )
    if(sa < min):
        min = sa

print(min)

Buggy submission (verdict: Runtime Error):
import math

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

min = math.inf

for i in range(1,n):
    sa = abs( sum(w[0:i]) - sum(w[i:]) )
    if(sa < min):
        min = sa

print(min)

Buggy submission (verdict: Runtime Error):
import math

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

min = math.inf

for i in range(1,n):
    sa = abs( sum(w[0:i]) - sum(w[i:]) )
    if(sa < min):
        min = sa

print(min)
Problem p03053 (python)

Fixed submission:
import numpy as np
h,w = [int(i) for i in input().split()]
maximum = h+w
value = []
for i in range(h):
  value.append([0 if i == "#" else maximum for i in list(input())])
values = np.array(value)
for x in range(w-1):
  values[:,x+1] = np.minimum(values[:,x]+1,values[:,x+1])
for x in range(w-1,0,-1):
  values[:,x-1] = np.minimum(values[:,x]+1,values[:,x-1])
for y in range(h-1):
  values[y+1,:] = np.minimum(values[y,:]+1,values[y+1,:])
for y in range(h-1,0,-1):
  values[y-1,:] = np.minimum(values[y,:]+1,values[y-1,:])
print(values.max())

Buggy submission (verdict: Runtime Error):
import numpy as np
h,w = [int(i) for i in input().split()]
maximum = h+w
value = []
for i in range(h):
  value.append([0 if i == "#" else maximum for i in input().split()])
values = np.array(value)
for x in range(w-1):
  values[:,x+1] = np.minimum(values[:,x]+1,values[:,x+1])
for x in range(w-1,0,-1):
  values[:,x-1] = np.minimum(values[:,x]+1,values[:,x-1])
for y in range(h-1):
  values[y+1,:] = np.minimum(values[y,:]+1,values[y+1,:])
for y in range(h-1,0,-1):
  values[y-1,:] = np.minimum(values[y,:]+1,values[y-1,:])
print(values.min())
Problem p02990 (python)

Fixed submission:
import sys
import math


def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


fin = sys.stdin.readline
N, K = [int(elem) for elem in fin().split()]

for i in range(1, K+1):
    if (N-K+1) < i:
        print(0)
    else:
        result = int(combinations_count(N-K+1, i) * combinations_count(K-1, i-1))
        print(int(result % 1000000007))

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


def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)


def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


fin = sys.stdin.readline
N, K = [int(elem) for elem in fin().split()]

for i in range(1, K):
    if (N-K+1) < i:
        print(0)
    else:
        result = int(permutations_count(N-K+1, i) / math.factorial(i-1))
        print(int(result % 1000000007))

if (N-K+1) < K:
    print(0)
else:
    result = int(combinations_count(N-K+1, K))
    print(int(result % 1000000007))

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


def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)


def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


fin = sys.stdin.readline
N, K = [int(elem) for elem in fin().split()]

for i in range(1, K):
    result = int(permutations_count(N-K+1, i) / math.factorial(i-1))
    print(int(result % 1000000007))

result = int(combinations_count(N-K+1, K))
print(int(result % 1000000007))
Problem p03042 (python)

Fixed submission:
import sys

a = []
for l in sys.stdin:
    a.append(l)

_input = a[0]

def is_month(x):
    # x: 2桁の数字
    if 12 >= x > 0:
        return True
    else:
        return False


input_l = int(_input[:2])
input_r = int(_input[2:])

if is_month(input_l):
    if is_month(input_r):
        result = 'AMBIGUOUS'
    else:
        result = 'MMYY'
else:
    if is_month(input_r):
        result = 'YYMM'
    else:
        result = 'NA'

print(result)

Buggy submission (verdict: Runtime Error):
import sys

a = []
for l in sys.stdin:
    a.append(l)

_input = a[0]

def is_month(x):
    # x: 2桁の数字
    if 12 >= x > 0:
        return True
    else:
        return False

input_l = _input[:2]
input_r = _input[2:]

if is_month(input_l):
    if is_month(input_r):
        result = 'AMBIGUOUS'
    else:
        result = 'MMYY'
else:
    if is_month(input_r):
        result = 'YYMM'
    else:
        result = 'NA'
        
print(result)
Problem p03011 (python)

Fixed submission:
from sys import stdin

abc = [int(i) for i in stdin.readline().rstrip().split(" ")]
s = sum(abc) 
m = max(abc)
print(s-m)

Buggy submission (verdict: Runtime Error):
from sys import stdin
from functools import reduce
from operator import add, mul

from functools import lru_cache
@lru_cache(maxsize=None)  # メモ化したい関数の前につける
def fib(n):  # n 番目のフィボナッチ数を求める関数
    if n <= 0:
        return 0
    elif n == 1:
        return 1
    else:
        return fib(n - 2) + fib(n - 1)


nm = [int(i) for i in stdin.readline().rstrip().split(" ")]
a = []
for i in range(nm[1]):
    a.append(int(stdin.readline().rstrip()))
result =[]
result.append(fib(a[0]))
for i in range(nm[1]-1):
    result.append(fib(a[i+1] - a[i] - 1))
result.append(fib(nm[0] - a[nm[1]-1]))
print(reduce(mul, result) % 1000000007)
Problem p02987 (python)

Fixed submission:
a = input()
a = a.replace(a[0], "")
if len(a) == 0:
    print("No")
    exit()
a = a.replace(a[0], "")
if len(a) == 0:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
a = input()
a = a.replace(a[0], "")
a = a.replace(a[0], "")
if len(a) == 0:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
a = input()
a = a.replace(c[0], "")
a = a.replace(c[0], "")
if len(a) == 0:
    print("Yes")
else:
    print("No")
Problem p03013 (python)

Fixed submission:
a, b = map(int, input().split())
d = [True] * (a+1)
for i in range(b):
    d[int(input())] = False
e = [0] * (a+1)
for i in range(0, a+1):
    if i < 2:
        if d[i]:
            e[i] = 1
        else:
            e[i] = 0
    elif not d[i] and not d[i-1]:
        print(0)
        exit()
    elif d[i]:
        e[i] = (e[i-2] + e[i-1]) % 1000000007
print(e[len(e)-1])

Buggy submission (verdict: Runtime Error):
a
Problem p03042 (python)

Fixed submission:
a = input()

if 1 <= int(a[:2]) <= 12 and 1 <= int(a[2:]) <= 12:
    print("AMBIGUOUS")
elif 1 <= int(a[:2]) <= 12:
    print("MMYY")
elif 1 <= int(a[2:]) <= 12:
    print("YYMM")
else:
    print("NA")

Buggy submission (verdict: Runtime Error):
a = input()
b = int(a[:2])
c = int(a[2:])
if 0 < b <= 12 and a < c <= 12:
    print("AMBIGUOUS")
elif 0 < b <= 12 and c > 12:
    print("MMYY")
elif b > 12 and 0 < c <= 12:
    print("YYMM")
else:
    print("NA")
Problem p03135 (python)

Fixed submission:
a, b = map(int, input().split())
print(a / b)

Buggy submission (verdict: Runtime Error):
a, b = map(int, input().split())
c = list(map(int, input
s = 0
for i in range(44, -1, -1):
    if 2 ** i + s <= b
        if a > d[i] * 2:
            s += 2 ** i
for i in c:
    ans += i ^ s
print(ans)
Problem p03207 (python)

Fixed submission:
a = int(input())
b = [int(input()) for _ in range(a)]
b = sorted(b, reverse=True)
c  = 0
for i in range(a):
    if i == 0:
        c += b[i] // 2
    else:
        c += b[i]
print(c)

Buggy submission (verdict: Runtime Error):
a = int(input())
b = [int(input()) for _ in range(a)]
b = sorted(b, key=lambda, x: x[0], reverse=True)
c = 1
for i in range(a):
  if i == 0:
    c += b[i] // 2
  else:
    c += b[i]
print(c)

Buggy submission (verdict: Runtime Error):
a = int(input())
b = [int(input()) for _ in range(a)]
b = sorted(b, key=lambda, x: x[0], reverse=True)
c = 0
for i in range(a):
  if i == 0:
    c += b[i] // 2
  else:
    c += b[i]
print(c)
Problem p03804 (python)

Fixed submission:
a, b = map(int, input().split())
c = []
d = ""
for i in range(a):
    c.append(list(input()))
for i in range(b):
    d += input()
e = []
for i in range(a-b+1):
    for j in range(a-b+1):
        f = ""
        for k in range(b):
            for l in range(b):
                f += c[i+k][j+l]
        e.append(f)
print("Yes" if d in e else "No")

Buggy submission (verdict: Runtime Error):
a, b = map(int, input().split())
c = []
d = []
for i in range(a):
    c.append(list(input()))
for i in range(b):
    d.append(list(input()))
for i in range(a-b+1):
    for j in range(a-b+1):
        m = n = 0
        o = True
        for k in range(i,i+b):
            n = 0
            for l in range(k, k+b):
                if c[k][l] != d[m][n]:
                    o = not o
                n += 1
            m += 1
        if o:
            print("Yes")
            exit()
print("No")

Buggy submission (verdict: Runtime Error):
a, b = map(int, input().split())
c = []
d = ""
for i in range(a):
    c.append(list(input()))
for i in range(b):
    d += input()
e = []
for i in range(b):
    for j in range(b):
        f = ""
        for k in range(b):
            for l in range(b):
                f += c[i+k][j+l]
        e.append(f)
print("Yes" if d in e else "No")
Problem p03127 (python)

Fixed submission:
import fractions
from functools import reduce

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

n = input()
alist = [int(s) for s in input().split()]

print(gcd_list(alist))

Buggy submission (verdict: Runtime Error):
import math
from functools import reduce

def gcd_list(numbers):
    return reduce(math.gcd, numbers)

n = input()
alist = [int(s) for s in input().split()]

print(gcd_list(alist))
Problem p03013 (python)

Fixed submission:
import numpy as np

n, m = input().split()
n = int(n)
m = int(m)

# a[i] = 0 の床は踏めない
a = np.ones(n+1, dtype=np.bool)
for _ in range(m):
    a[int(input())] = 0

mod = 1e9 + 7

# pos[i]はi段目まで登る場合の数
pos = np.zeros(n+1)
pos[0] = 1
for i in range(n-1):
    if a[i+1]:
        pos[i+1] += pos[i]
        pos[i+1] %= mod
    if a[i+2]:
        pos[i+2] += pos[i]
        pos[i+2] %= mod

pos[n] += pos[n-1]

print(int(pos[n] % mod))

Buggy submission (verdict: Runtime Error):
import numpy as np

n, m = input().split()
n = int(n)
m = int(m)

# a[i] = 0 の床は踏めない
a = np.ones(n+1, dtype=np.bool)
for _ in range(m):
    a[int(input())] = 0

mod = 1e9 + 7

# pos[i]はi段目まで登る場合の数
pos = np.zeros(n+1)
pos[0] = 1
for i in range(n):
    if i == n - 1:
        pos[i+1] += pos[i]
    else:
        if a[i+1]:
            pos[i+1] += pos[i]
        if a[i+2]:
            pos[i+2] += pos[i]

print(int(pos[n] % mod))
Problem p02987 (python)

Fixed submission:
s = input()
s_s = list(set(s))

if len(s_s) == 2:
  if s.count(s_s[0]) == s.count(s_s[1]):
    print("Yes")
else:
    print('No')

Buggy submission (verdict: Runtime Error):
s = [_ for _ in input()]
s_s = list(set(s))

if len(s_s) >= 3:
  print("No")
else:
  if s.count(s_s[0]) == s.count(s_s[1]):
    print("Yes")
  else:
    print("No")

Buggy submission (verdict: Runtime Error):
s = input()
s_s = list(set(s))

if len(s_s) >= 3:
  print("No")
else:
  if s.count(s_s[0]) == s.count(s_s[1]):
    print("Yes")
  else:
    print("No")

Buggy submission (verdict: Runtime Error):
s = input()
s_s = listed(set(s))

if len(s_s) >= 3:
  print("No")
else:
  if s.count(s_s[0]) == s.count(s_s[1]):
    print("Yes")
  else:
    print("No")

Buggy submission (verdict: Runtime Error):
s = input()

if len(list(set(s))) >= 3:
  print("No")
else:
  s_s = list(set(s))
  if s.count(s_s[0]) == s.count(s_s[1]):
    print("Yes")
  else:
    print("No")

Buggy submission (verdict: Runtime Error):
s = input()

if len(list(set(s))) >= 3:
  print("No")
else:
  s = list(set(s))
  if s.count(s[0]) == s.count(s[1]):
    print("Yes")
  else:
    print("No")

Buggy submission (verdict: Runtime Error):
s = input()

if len(list(set(s))) >= 3:
  print("No")
else:
  s = list(set(s))
  if count(s[0]) == count(s[1]):
    print("Yes")
  else:
    print("No")

Buggy submission (verdict: Runtime Error):
s = input()

for i in range(len(S)):
  if len(list(set(s))) >= 3:
    print("No")
  else:
    s = list(set(s))
    if count(s[0]) == count(s[1]):
      print("Yes")
   	else:
      print("No")

Buggy submission (verdict: Runtime Error):
s = input()

for i in range(len(S)):
  if len(set(s)) > 3:
    print("No")
  else:
    s = list(set(s))
    if count(s[0]) == count(s[1]):
      print("Yes")
   	else:
      print("No")
Problem p03041 (python)

Fixed submission:
N,K = map(int,input().split())
S = input()

se = ''
for i in range(N):
    if i == K-1:
        se += S[K-1].lower()
    else:
        se += S[i]
print(se)

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
S = input()

S[K-1]=S[K-1].lower()
print(S)
Problem p03042 (python)

Fixed submission:
S = input()

if int(S[0:2])<=12 and int(S[0:2])!=0:
    if int(S[2:4])<=12 and int(S[2:4])!=0:
        print('AMBIGUOUS')
    else:
        print('MMYY')
else:
    if int(S[2:4])<=12 and int(S[2:4])!=0:
        print('YYMM')
    else:
        print('NA')

Buggy submission (verdict: Runtime Error):
 S = input()

if int(S[0:2])<=12 and int(S[0:2])!=0:
    if int(S[2:4])<=12 and int(S[2:4])!=0:
        print('AMBIGUOUS')
    else:
        print('MMYY')
else:
    if int(S[2:4])<=12 and int(S[2:4])!=0:
        print('YYMM')
    else:
        print('NA')
Problem p03072 (python)

Fixed submission:
h = int(input())
mount = [int(_) for _ in input().split()]
count = 0
for i in range(h):
  if i == 0:
    count += 1
  else:
    for j in range(i):
      if mount[i]<mount[j]:
        break
    else:
      count += 1
print (count)

Buggy submission (verdict: Runtime Error):
h = int(input())
mount = [int(_) for _ in input().split()]
count = 0
for i in range(h):
  if i == 0
    count += 1
  else:
    for j in range(i):
      if mount[i]<mount[j]:
        break
    else:
      count += 1
print (count)

Buggy submission (verdict: Runtime Error):
h = int(input())
mount = [int(_) for _ in input().split()]
count = 0
for i in range(h):
  if i = 0:
    count += 1
  else:
    if mount[i]>mount[i-1]:
      count += 1
print (count)

Buggy submission (verdict: Runtime Error):
h = int(input())
mount = [int(_) for _ in input().split()]
count = 0
for i in range(len):
  if i = 0:
    count += 1
  else:
    if mount[i]>mount[i-1]:
      count += 1
print (count)
Problem p03077 (python)

Fixed submission:
import math
N = int(input())
capacity = min([int(input()) for i in range(5)])

print(math.ceil(N/capacity)+4)

Buggy submission (verdict: Runtime Error):
import math
N = int(input())
capacity = min([int(input()) for i in range(6)])

print(math.ceil(N/capacity)+4)
Problem p02987 (python)

Fixed submission:
s = input()
l = list(s)
c1 = s.count(l[0])
c2 = s.count(l[1])
c3 = s.count(l[2])
c4 = s.count(l[3])
if c1 == 2 and c2 == 2 and c3 == 2 and c4 == 2:
  print('Yes')
else:
  print('No')

Buggy submission (verdict: Runtime Error):
s = input()
l = list(s)
c1 = s.count(l[0])
c2 = s.count(l[1])
c3 = s.count(l[2])
c4 = s.count(l[3])
if c1 == 2 and c2 == 2 and c3 == 2 and c4 == 2:
  print('Yes')
  else:
    print('No')
Problem p02998 (python)

Fixed submission:
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.root = [-1]*(n+1)
        self.rnk = [0]*(n+1)

    def Find_Root(self, x):
        if(self.root[x] < 0):
            return x
        else:
            self.root[x] = self.Find_Root(self.root[x])
            return self.root[x]
    def Unite(self, x, y):
        x = self.Find_Root(x)
        y = self.Find_Root(y)
        if(x == y):
            return 
        elif(self.rnk[x] > self.rnk[y]):
            self.root[x] += self.root[y]
            self.root[y] = x

        else:
            self.root[y] += self.root[x]
            self.root[x] = y
            if(self.rnk[x] == self.rnk[y]):
                self.rnk[y] += 1
    def isSameGroup(self, x, y):
        return self.Find_Root(x) == self.Find_Root(y)

    def Count(self, x):
        return -self.root[self.Find_Root(x)]

m = 100010
uf = UnionFind(m*2)
n = int(input())
for i in range(n):
    x,y = map(int,input().split())
    y = y+m
    uf.Unite(x,y)

lx = {}
ly = {}
ans = 0
for i in range(m):
    rx = uf.Find_Root(i)
    lx[rx] = lx.get(rx,0)+1
    ry = uf.Find_Root(i+m)
    ly[ry] = ly.get(ry,0)+1
for i in range(m*2):
    ans += lx.get(i,0)*ly.get(i,0)

print(ans-n)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**5)
m = 100005
visited = [False]*(m*2)
cnt = [0,0]
def dfs(i):
    visited[i] = True
    cnt[i//m] +＝ 1
    for j in to[i]:
        if not visited[j]:
            dfs(j)
 
input = sys.stdin.readline
n = int(input())
to = [[] for _ in range(m*2)]
for _ in range(n):
    x,y = map(int,input().split())
    y = y+m
    to[x].append(y)
    to[y].append(x)
 
ans = 0
for i in range(m):
    if not visited[i]:
        cnt = [0,0]
        dfs(i)
        ans = ans + cnt[0]*cnt[1]
 
print(ans-n)

Buggy submission (verdict: Runtime Error):
m = 100005
visited = [False]*(m*2)
cnt = [0,0]
def dfs(i):
    global cnt
    if visited[i]:
        return
    visited[i] = True
    cnt[i//m] = cnt[i//m] + 1
    for j in to[i]:
        dfs(j)


n = int(input())
to = [[] for i in range(m*2)]
for i in range(n):
    x,y = map(int,input().split())
    y = y+m
    to[x].append(y)
    to[y].append(x)

ans = 0
for i in range(m*2):
    cnt = [0,0]
    dfs(i)
    ans = ans + cnt[0]*cnt[1]

print(ans-n)
Problem p03012 (python)

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

result = 99999
for i in range(1,N):
    s = abs(sum(w[:i]) - sum(w[i:]))
    if s<result:
        result = s
print(result)

Buggy submission (verdict: Runtime Error):
result = 99999
for i in range(1,N):
    s = abs(sum(w[:i]) - sum(w[i:]))
    if s<result:
        result = s
print(result)
Problem p03013 (python)

Fixed submission:
def fib_memo(n,broken):
    memo = [0]*(n+1)
    memo[0] = 1
    for x in range(1,n+1):
        if x < 1:
            continue
        if broken[x]==1:
            continue
        memo[x] = (memo[x-1] + memo[x-2])%1000000007

    return memo[n]

n,m = map(int,input().split())
a =[]
pos = 0
result = 1
last = -1
broken = [0]*(n+1)
for i in range(m):
    x = int(input())
    if (last+1) == x:
        print(0)
        exit(0)
    last = x
    a.append(x)
    broken[x] = 1

result = fib_memo(n,broken)

print(result)

Buggy submission (verdict: Runtime Error):
def mulmod(x,y,p):
    return x*y % p

def fib_memo(n):
    memo = [0]*(n+1)

    def _fib(n):
        if n <= 1:
            return n
        if memo[n] != 0:
            return memo[n]
        memo[n] = (_fib(n-1) + _fib(n-2))%1000000007
        return memo[n]

    return _fib(n)

n,m = map(int,input().split())
a =[]
pos = 0
result = 1
last = -1
for i in range(m):
    x = int(input())
    if (last+1) == x:
        print(0)
        exit(0)
    last = x
    a.append(x)

for i in a:
    result = mulmod(fib_memo(i-pos),result,1000000007)
    pos = i+1

result = mulmod(fib_memo(n-pos+1),result,1000000007)

print(result)

Buggy submission (verdict: Runtime Error):
def mulmod(x,y,p):
    return x*y % p

def fib_memo(n):
    memo = [0]*(n+1)

    def _fib(n):
        if n <= 1:
            return n
        if memo[n] != 0:
            return memo[n]
        memo[n] = _fib(n-1) + _fib(n-2)
        return memo[n]

    return _fib(n)

n,m = map(int,input().split())
a =[]
pos = 0
result = 1
last = -1
for i in range(m):
    x = int(input())
    if (last+1) == x:
        print(0)
        exit(0)
    last = x
    a.append(x)

for i in a:
    result = mulmod(fib_memo(i-pos),result,1000000007)
    pos = i+1

result = mulmod(fib_memo(n-pos+1),result,1000000007)

print(result)
Problem p03038 (python)

Fixed submission:
import sys
input = sys.stdin.buffer.readline
import heapq

def main():
    N,M = map(int,input().split())
    q = list(map(int, input().split()))
    X = [list(map(int,input().split())) for _ in range(M)]
    X.sort(key=lambda x:-x[1])
    total = sum(q)
    heapq.heapify(q)

    for i in range(M):
        for j in range(X[i][0]):
            tmp = heapq.heappushpop(q, X[i][1])
            if tmp < X[i][1]:
                total += (X[i][1] - tmp)
            else:
                break

    print(total)

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.buffer.readline
import heapq

def main():
    N,M = map(int,input().split())
    q = list(map(int, input().split()))
    total = sum(q)
    heapq.heapify(q)

    for i in range(M):
        B, C = map(int,input().split())
        for j in range(B):
            tmp = heapq.heappop(q)
            if tmp < C:
                heapq.heappush(C)
                total += (C - tmp)
            else:
                heapq.heappush(tmp)
                break

    print(total)

if __name__ == "__main__":
    main()