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

Fixed submission:
N, M = map(int, input().split())
A = set(int(input()) for _ in range(M))
mod = 10 ** 9 + 7

dp = [0] * (N+1)
dp[0] = 1
for i in range(1, N+1):
    if i in A:
        continue
    if i == 1:
        dp[i] = 1
        continue
    dp[i] = dp[i-1] + dp[i-2]

print(dp[N] % mod)

Buggy submission (verdict: Runtime Error):
N,M = (int(i) for i in input().split())
a = [int(input()) for i in range(M)]
hoge = [0] * N
if 1 not in a:
    hoge[0] = 1
if 2 not in a:
    hoge[1] = hoge[0] + 1

for i in range(2,N):
    if i + 1 not in a:
        hoge[i] = 0
        if i in a:
            hoge[i] = hoge[i - 2]
        elif (i-1) in a:
            hoge[i] = hoge[i - 1]
        else:
            hoge[i] = hoge[i-1] + hoge[i-2]
print(hoge[N-1] % (10**9 + 7))

Buggy submission (verdict: Runtime Error):
N,M = (int(i) for i in input().split())
a = [int(input()) for i in range(M)]
hoge = [0] * N
if 1 not in a:
    hoge[0] = 1
if 2 not in a:
    hoge[1] = hoge[0] + 1

for i in range(2,N):
    if i + 1 not in a:
        hoge[i] = 0
        if i in a:
            hoge[i] = hoge[i - 2]
        elif (i-1) in a:
            hoge[i] = hoge[i - 1]
        else:
            hoge[i] = hoge[i-1] + hoge[i-2]
            hoge[i] = hoge[i] % (10**9 + 7)
print(hoge[N-1] % (10**9 + 7))

Buggy submission (verdict: Runtime Error):
N,M = (int(i) for i in input().split())
a = [int(input()) for i in range(M)]
hoge = [0] * N
if 1 not in a:
    hoge[0] = 1
if 2 not in a:
    hoge[1] = hoge[0] + 1

for i in range(2,N):
    if i + 1 in a:
        hoge[i] = 0
    elif i in a and (i-1) in a:
        hoge[i] = 0
    elif i in a:
        hoge[i] = hoge[i - 2]
    elif (i-1) in a:
        hoge[i] = hoge[i - 1]
    else:
        hoge[i] = hoge[i-1] + hoge[i-2]
        hoge[i] = hoge[i] % (10**9 + 7)
print(hoge[N-1] % (10**9 + 7))

Buggy submission (verdict: Runtime Error):
N,M = (int(i) for i in input().split())
a = [int(input()) for i in range(M)]
hoge = [0] * N
if 1 not in a:
    hoge[0] = 1
if 2 not in a:
    hoge[1] = 2

for i in range(2,N):
    if i + 1 in a:
        hoge[i] = 0
    elif i in a and (i-1) in a:
        hoge[i] = 0
    elif i in a:
        hoge[i] = hoge[i - 2]
    elif (i-1) in a:
        hoge[i] = hoge[i - 1]
    else:
        hoge[i] = hoge[i-1] + hoge[i-2]
        hoge[i] = hoge[i] % (10**9 + 7)
print(hoge[N-1] % (10**9 + 7))

Buggy submission (verdict: Runtime Error):
N,M = (int(i) for i in input().split())
a = [int(input()) for i in range(M)]
hoge = [0] * N
hoge[0] = 1
for i in range(N):
    if i = 0:
        hoge[i] = 0
    elif (i-1) in a and (i-2) in a:
        hoge[i] = 0
    elif (i-1) in a:
        hoge[i] = hoge[i - 2]
    elif (i-2) in a:
        hoge[i] = hoge[i - 1]
    else hoge[i] = hoge[i-1] + hoge[i-2]
print(hoge[N])
Problem p03017 (python)

Fixed submission:
N,A,B,C,D = (int(i) for i in input().split())
S = input()
S = list(S)

result = "Yes"
onon = True

if C < D:
    for i in range(A-1,D):
        if S[i] == "#" and S[i + 1] == "#":
            result =  "No"
else:
    result = "No"
    for i in range(A-1,C):
        if S[i] == "#" and S[i + 1] == "#":
            onon = False
    if onon:
        for i in range(B -2,D-1):
            if S[i] == "." and S[i + 1] == "."and S[i + 2] == ".":
                result = "Yes"


print(result)

Buggy submission (verdict: Runtime Error):
N,A,B,C,D = (int(i) for i in input().split())
S = input()
S = list(S)

result = "Yes"
onon = True

if C < D:
    for i in range(A-1,D:
        if S[i] == "#" and S[i + 1] == "#":
            result =  "No"
else:
    result = "No"
    for i in range(A-1,C):
        if S[i] == "#" and S[i + 1] == "#":
            onon = False
    if onon:
        for i in range(B -2,D-1):
            if S[i] == "." and S[i + 1] == "."and S[i + 2] == ".":
                result = "Yes"


print(result)

Buggy submission (verdict: Runtime Error):
N = input()
N = int(N)
N,K = (int(i) for i in input().split())
s = [[ i for i in input().split()] for i in range(N)]


N,A,B,C,D = (int(i) for i in input().split())
S = input()
S = list(S)

result = "Yes"
onon = True

if C < D:
    for i in range(len(S)-1):
        if S[i] == "#" and S[i + 1] == "#":
            result =  "No"
else:
    result = "No"
    for i in range(len(S)-1):
        if S[i] == "#" and S[i + 1] == "#":
            onon = False
    if onon:
        for i in range(B,D-2):
            if S[i] == "." and S[i + 1] == "."and S[i + 2] == ".":
                result = "Yes"


print(result)
Problem p02964 (python)

Fixed submission:
from sys import exit, setrecursionlimit, stdin, stderr
from functools import reduce
from itertools import *
from collections import *
from bisect import *
from heapq import *
import operator
import math
from fractions import gcd
from random import randint

setrecursionlimit(10**8)

def input():
  return stdin.readline().strip()

def read():
  return int(input())
 
def reads():
  return [int(x) for x in input().split()]

N, K = reads()
A = reads()

skip = [-1] * (N + 1)
first_occ = {}
for i in range(N-1, -1, -1):
  a = A[i]
  if a in first_occ:
    if first_occ[a] < N-1:
      skip[i] = skip[first_occ[a] + 1]
    else:
      skip[i] = first_occ[a] + 1
  else:
    skip[i] = i
  first_occ[a] = i
skip[N] = N

back = [first_occ[A[i]] + 1 for i in range(N)] + [0]
next_state = [skip[back[q]] for q in range(N+1)]


q = skip[0]

rev = {}
memo = {}
i = 0
while True:
  if q in rev:
    j = rev[q]
    break
  rev[q] = i
  memo[i] = q
  q = next_state[q]
  i += 1

m = i - j
q = memo[j + (K - 1 - j) % m]

s = []
while q < N:
  if skip[q] == q:
    s.append(A[q])
    q += 1
  else:
    q = skip[q]

print(*s)

Buggy submission (verdict: Runtime Error):
from sys import exit, setrecursionlimit, stdin, stderr
from functools import reduce
from itertools import *
from collections import *
from bisect import *
from heapq import *
import operator
import math
from fractions import gcd
from random import randint

setrecursionlimit(10**8)

def input():
  return stdin.readline().strip()

def read():
  return int(input())
 
def reads():
  return [int(x) for x in input().split()]

N, K = reads()
A = reads()

skip = [-1] * N
first_occ = {}
for i in range(N-1, -1, -1):
  a = A[i]
  if a in first_occ:
    if first_occ[a] < N-1:
      skip[i] = skip[first_occ[a] + 1]
    else:
      skip[i] = first_occ[a] + 1
  else:
    skip[i] = i
  first_occ[a] = i

back = [first_occ[A[i]] + 1 for i in range(N)] + [0]
next_state = [skip[back[q]] for q in range(N+1)]


q = skip[0]

rev = {}
memo = {}
i = 0
while True:
  if q in rev:
    j = rev[q]
    break
  rev[q] = i
  memo[i] = q
  q = next_state[q]
  i += 1

m = i - j
q = memo[j + (K - 1 - j) % m]

s = []
while q < N:
  if skip[q] == q:
    s.append(A[q])
    q += 1
  else:
    q = skip[q]

print(*s)
Problem p02987 (python)

Fixed submission:
M=input()


if M.count(M[0])+ M.count(M[1])+ M.count(M[2])+ M.count(M[3])==8:
  print("Yes")
else:
  print("No")

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


if M.count(M[0])+ M.count(M[1])+ M.count(M[2])+ M.count(M[3])=8:
  print("Yes")
else:
  print("No")
Problem p03137 (python)

Fixed submission:
n,m=map(int,input().split(" "))
points=list(map(int,input().split(" ")))
points.sort()
score=0
#score=points[-1]-points[0]
sas=[]

for i in range(0,m-1):
  sas.append(points[i+1]-points[i])
sas.sort()

#score-=sum(sas[-n+1:]) 
if n>=m:
  print(0)
  exit()
else:
  print(sum(sas[:m-n]))

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
points=list(map(int,input().split()))
points.sort()
score=0
score=points[-1]-points[0]

sas=[]
for i in range(0,m-1):
  sas.append(points[i+1]-points[i])

if sas==[]:
  print(0)
  exit()

for j in range(0,n-1):
  score-=max(sas)
  sas.remove(max(sas))

print(score)

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
points=list(map(int,input().split()))
points.sort()
#print(points)

sas=[]
for i in range(0,m-1):
  sas.append(points[i+1]-points[i])
  
#print(sas)

score=0
score=max(points)-min(points)

if sas==[]:
  print(0)
  exit()

for j in range(0,n-1):
  score-=max(sas)
  sas.remove(max(sas))

print(score)
Problem p03209 (python)

Fixed submission:
#解答参照した
n,x=map(int,input().split(" "))

P=[1]
M=[1]

for i in range(1,n):
  P.append(2*P[i-1]+1)
  M.append(2*M[i-1]+3)
  
def F(n,x):
  if n==0:
    return 0 if x<=0 else 1
  elif x<=1:
    return 0
  elif 1<x<=M[n-1]+1:
    return F(n-1,x-1)
  elif x==M[n-1]+2:
    return P[n-1]+1
  elif M[n-1]+2<x<2*M[n-1]+3:
    return P[n-1]+1+F(n-1,x-2-M[n-1])
  elif x==2*M[n-1]+3:
    return 2*P[n-1]+1
  else:
    return P[n-1]+1+F(n-1,x-2-M[n-1])
    #print("OH!"+str(n))
    
print (F(n,x))

Buggy submission (verdict: Runtime Error):
h=[]
h.append("P")

n,x=map(int,input().split(" "))

for i in range(1,n+1):
  h.append("B"+h[i-1]+"P"+h[i-1]+"B")
  #print (h[i])
  
taberu=h[n][0:x]
print(taberu.count("P"))
Problem p02987 (python)

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

a = list(input())
dic = {}
for x in a:
    dic.setdefault(x, 0)
    dic[x] += 1
if (len(dic) == 2):
    if(dic[a[0]]==2):
        print("Yes")
    else:
        print("No")
else:
    print("No")

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

def cmb(n, r):
    if n == 0 or r == 0:
        return 1
    a = b = 1
    for i in range(1, r + 1):
        a *= i
    for i in range(n-r+1,n+1):
        b *= i
    return b//a

N = list(map(int,input().split()))
M = 10**9 + 7
red = N[0]-N[1]
for i in range(1,N[1]+1):
    x = cmb(red + 1, i) * cmb(N[1] - 1,i-1)
    print(x%M)

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

def cmb(n, r):
    if n == 0 or r == 0:
        return 1
    a = b = 1
    for i in range(1, r + 1):
        print(r,i)
        a *= i
    for i in range(n-r+1,n+1):
        b *= i
    return b//a

N = list(map(int,input().split()))
M = 10**9 + 7
red = N[0]-N[1]
for i in range(1,N[1]+1):
    x = cmb(red + 1, i) * cmb(N[1] - 1,i-1)
    print(x%M)
Problem p02990 (python)

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

def cmb(n, r):
    if n == 0 or r == 0:
        return 1
    if n < r:
        return 0
    a = b = 1
    r = min(n-r,r)
    for i in range(1, r + 1):
        a *= i
    for i in range(n-r+1,n+1):
        b *= i
    return b//a

N = list(map(int,input().split()))
M = 10**9 + 7
red = N[0]-N[1]
for i in range(1,N[1]+1):
    x = cmb(red + 1, i) * cmb(N[1] - 1,i-1)
    print(x%M)

Buggy submission (verdict: Runtime Error):
N = list(map(int,input().split()))
M = 10**9 + 7
red = N[0] - N[1]
x = red+1
print(x)
for i in range(2,N[1]+1):
    x *= (red+2-i)*(N[1]-i+1)/(i*(i-1))
    print(int(x%M))

Buggy submission (verdict: Runtime Error):
N = list(map(int,input().split()))
M = 10**9 + 7
red = N[0] - N[1]
x=1
for i in range(1,N[1]+1):
    x *= (red+2-i)*(N[1]-i)//(i*(i-1))
    print(x%M)

Buggy submission (verdict: Runtime Error):
def combination(n, m):
    if (n == 0 or m == 0):
        return 1
    a = b = 1
    for i in range(1,m+1):
        a *= i
    for i in range(n-m+1,n+1):
        b *= i
    return b/a

N = list(map(int,input().split()))
M = 1000000007
red = N[0]-N[1]
for i in range(N[1]):
    x = combination(red + 1, i+1) * combination(N[1] - 1, i)
    print(int(x%M))
Problem p02990 (python)

Fixed submission:
def main():
	N, K = map(int, input().split())
	DIV = 10**9+7
	size = 2001
	fact = [0]*size
	inverse = [0]*size
	inv_cal = [0]*size
	fact[:2] = [1, 1]
	inverse[:2] = [1, 1]
	inv_cal[:2] = [0, 1]

	for i in range(2, size):
		fact[i] = (fact[i-1]*i%DIV)
		inv_cal[i] = (-inv_cal[DIV%i]*(DIV//i))%DIV
		inverse[i] = inverse[i-1]*inv_cal[i]%DIV

	def C(n, r):
		ans = fact[n]*inverse[r]%DIV
		return ans*inverse[n-r]%DIV

	for i in range(K):
		ans = 0
		if i+1 <= N-K+1:
			ans = (C(N-K+1, i+1)*C(K-1, i))%DIV
		print(ans)


if __name__ == '__main__':
	main()

Buggy submission (verdict: Runtime Error):
def main():
	N, K = map(int, input().split())
	DIV = 10**9+7
	size = N
	fact = [0]*size
	inverse = [0]*size
	inv_cal = [0]*size
	fact[:2] = [1, 1]
	inverse[:2] = [1, 1]
	inv_cal[:2] = [0, 1]

	for i in range(2, size):
		fact[i] = (fact[i-1]*i%DIV)
		inv_cal[i] = (-inv_cal[DIV%i]*(DIV//i))%DIV
		inverse[i] = inverse[i-1]*inv_cal[i]%DIV

	def C(n, r):
		ans = fact[n]*inverse[r]%DIV
		return ans*inverse[n-r]%DIV

	for i in range(K):
		ans = (C(N-K+1, i+1)*C(K-1, i))%DIV
		print(ans)


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

Fixed submission:
def main():
	H, W, D = map(int,input().split())
	pos = [0]*(H*W)
	for i in range(H):
		A = list(map(int, input().split()))
		for j in range(W):
			pos[A[j]-1] = [i, j]
	Q = int(input())
	lr = [0]*Q
	for i in range(Q):
		lr[i] = list(map(int, input().split()))
	ans = [[0] for _ in range(D)]
	for i in range(H*W-D):
		s_pos = pos[i]
		e_pos = pos[i+D]
		d = abs(s_pos[0]-e_pos[0])+abs(s_pos[1]-e_pos[1])
		ans[i%D].append(ans[i%D][-1]+d)
	for i in range(Q):
		s = lr[i][0]-1
		e = lr[i][1]-1
		print(ans[e%D][e//D]-ans[s%D][s//D])


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
	H, W, D = map(int,input().split())
	pos = [0]*(H*W+1)
	for i in range(H):
		A = list(map(int, input().split()))
		for j in range(W):
			pos[A[j]] = [i, j]
	Q = int(input())
	lr = [0]*Q
	for i in range(Q):
		lr[i] = list(map(int, input().split()))
	ans = dict()
	for i in range(1, H*W+1-D):
		pre = i
		cur = i
		d = 0
		while cur < H*W+1:
			pre_pos = pos[pre]
			cur_pos = pos[cur]
			d += abs(pre_pos[0]-cur_pos[0])+abs(pre_pos[1]-cur_pos[1])
			ans[(i, cur)] = d
			pre = cur
			cur += D
	for i in range(Q):
		print(ans[(lr[i][0], lr[i][1])])


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

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
x = (sum([A[i] for i in range(N) if i % 2 == 0]) - sum([A[i] for i in range(N) if i % 2 == 1]))
print(x)
for  i in range(N-1):
    x = 2*A[i]-x
    print(x)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
print(f'A:{A}')
x = (sum([A[i] for i in range(N) if i % 2 == 0]) - sum([A[i] for i in range(N) if i % 2 == 1]))
print(x)
for  i in range(N-1):
    x = 2*A[i]-x
    print(x)
Problem p03013 (python)

Fixed submission:
mod = 1000000007
def add(a, b):
    return (a + b) % mod

N, M = map(int, input().split())
Broken_set = set([])
for _ in range(M):
    Broken_set.add(int(input()))

if 1 in Broken_set:    
    dp = [0]*(N+1)
    dp[0] = 1
    dp[1] = 0
    for i in range(2, N+1):
        if i in Broken_set:
            dp[i] = 0
        else:
            dp[i] = add(dp[i-1], dp[i-2])

else:
    dp = [0]*(N+1)
    dp[0] = 1
    dp[1] = 1
    for i in range(2, N+1):
        if i in Broken_set:
            dp[i] = 0
        else:
            dp[i] = add(dp[i-1], dp[i-2])

print(dp[N])

Buggy submission (verdict: Runtime Error):
n, M = map(int, input().split())
A = list(map(int, input().split()))
dp = [-1 for _ in range(n+1)]
dp[0] = 1
dp[1] = 1
if 1 in A:
    dp[1] = 0

step = 2
while True:
    if step == n+1:
        break
    
    if step in A:
        dp[step] = 0
    else:
        dp[step] = dp[step-1] + dp[step-2]
        
    step += 1
    
print(dp[n])
Problem p02990 (python)

Fixed submission:
n, k = input().split()
n = int(n)
k = int(k)
divnum = 10**9+7

pTri =[[1]]
rowNum = 2000

def comb(n,m):
    return pTri[n][m]

for i in range(1,rowNum):
    ls = [1]
    for j in range(1,i):
        ls.append(pTri[i-1][j-1] + pTri[i-1][j])
    ls.append(1)
    pTri.append(ls)

for i in range(1,k+1):
    if (n-k+1 >= i):
        print(comb(k-1, i-1) % divnum * comb(n-k+1, i) % divnum)
    else:
        print(0)

Buggy submission (verdict: Runtime Error):
n, k = input().split()
n = int(n)
k = int(k)
divnum = 10**9+7

pTri =[[1]]
rowNum = 2000

def comb(n,m):
    return pTri[n][m]

for i in range(1,rowNum):
    ls = [1]
    for j in range(1,i):
        ls.append(pTri[i-1][j-1] + pTri[i-1][j])
    ls.append(1)
    pTri.append(ls)

for i in range(1,k+1):
    print(comb(k - 1, i - 1) % divnum * comb(n - k + 1, i) % divnum)

Buggy submission (verdict: Runtime Error):
n, k = input().split()
n = int(n)
k = int(k)
divnum = 10**9+7

pTri =[[1]]
rowNum = 2000

def comb(n,m):
    return pTri[n][m]

for i in range(1,rowNum):
    ls = [1]
    for j in range(1,i):
        ls.append(pTri[i-1][j-1] + pTri[i-1][j])
    ls.append(1)
    pTri.append(ls)

for i in range(1,k+1):
    print(comb(k - 1, i - 1) * comb(n - k + 1, i)%divnum)
Problem p03041 (python)

Fixed submission:
N,M=[int(i) for i in input().split()]
S=input()
print(S[:M-1]+S[M-1].lower()+S[M:])

Buggy submission (verdict: Runtime Error):
N,M=[int(i) for i in input().split()]
S=input()
print(S[:M-1]+S[M-1].lower()+S[M:]
Problem p03045 (python)

Fixed submission:
import collections
import sys
sys.setrecursionlimit(100000)
def root(X):
	if cards[X]==X:
		return X
	else:
		cards[X]=root(cards[X])
		return cards[X]
def unite(X,Y):
	x=root(X)
	y=root(Y)
	if x==y:
		return
	else:
		cards[x]=y
def same(X,Y):
	return root(X)==root(Y)
def show(x):
	print(cards[x])
		
N,M=[int(i) for i in input().split()]
cards=[i for i in range(N+1)]
for i in range(M):
	X,Y,Z=[int(i) for i in input().split()]
	if same(X,Y):
		pass
	else:
		unite(X,Y)
a=[]
for i in range(1,N+1):
	a.append(root(cards[i]))
print(len(set(a)))

Buggy submission (verdict: Runtime Error):
import collections

def root(X):
	if cards[X]==X:
		return X
	else:
		cards[X]=root(cards[X])
		return cards[X]
def unite(X,Y):
	x=root(X)
	y=root(Y)
	if x==y:
		return
	else:
		cards[x]=y
def same(X,Y):
	return root(X)==root(Y)
def show(x):
	print(cards[x])
		
N,M=[int(i) for i in input().split()]
cards=[i for i in range(N+1)]
for i in range(M):
	X,Y,Z=[int(i) for i in input().split()]
	if same(X,Y):
		pass
	else:
		unite(X,Y)
a=[]
for i in range(1,N+1):
	a.append(root(cards[i]))
print(len(set(a)))
Problem p03077 (python)

Fixed submission:
import math
N=int(input())

for i in range(5):
  if i==0:
    a=int(input())
  else:
    b=int(input())
    if b<a:
      a=b
print(math.ceil(N/a)+4)

Buggy submission (verdict: Runtime Error):
import numpy as np
N=int(input())
dp=np.full((6,N+6),-1)
cost=[]
for i in range(5):
  cost.append(int(input()))
def solve(i,time):
  if dp[i,time]!=-1:
    return dp[i,time]
  if time==0:
     if i==0:
       dp[i][time]=N
       return N
     else:
       dp[i][time]=0
       return 0
  if i==5:
    dp[i,time]=solve(i,time-1)+min(solve(i-1,time-1),cost[i-1])
  elif i>=1 and i< 5:
    dp[i,time]=solve(i,time-1)+min(solve(i-1,time-1),cost[i-1])-min(solve(i,time-1),cost[i])
  else:
    dp[i,time]=solve(i,time-1)-min(solve(i,time-1),cost[i])
  return dp[i,time]

i=0
while(1):
  if solve(5,i)>=N:
    print(i)
    break
  else:
    i+=1
Problem p03108 (python)

Fixed submission:
N,M=[int(i) for i in input().split()]
bridge=[]
for i in range(M):
  bridge.append([int(i)-1 for i in input().split()])
nod=[[i,[i]] for i in range(N)]
e=0
totale=int(N*(N-1)/2)


def joint(a,b,e):
  na=nod[a][0]
  nb=nod[b][0]
  if na==nb:
    return e
  else:
    e+=len(nod[na][1])*len(nod[nb][1])
    if na<nb:
      nod[na][1].extend(nod[nb][1])
      for i in nod[nb][1]:
        nod[i][0]=na
    else:
      nod[nb][1].extend(nod[na][1])
      for i in nod[na][1]:
        nod[i][0]=nb
    return e
  


ans=[]
for i in range(M-1,-1,-1):
  ans.append(totale-e)
  e=joint(bridge[i][0],bridge[i][1],e)
  
for i in range(M-1,-1,-1):
  print(ans[i])

Buggy submission (verdict: Runtime Error):
N,M=[int(i) for i in input().split()]
bridge=[]
for i in range(M):
  bridge.append([int(i)-1 for i in input().split()])
nod=[[i,[i]] for i in range(N)]
e=0
totale=int(N*(N-1)/2)


def joint(a,b,e):
  na=nod[a][0]
  nb=nod[b][0]
  if na==nb:
    return e
  else:
    e+=len(nod[na][1])*len(nod[nb][1])
    if na<=nb:
      nod[na][1].extend(nod[nb][1])
      for i in nod[nb][1]:
        nod[i][0]=na
      nod[nb][1]=0
    else:
      nod[nb][1].extend(nod[na][1])
      for i in nod[na][1]:
        nod[i][0]=na
      nod[na][1]=0
    return e
  


ans=[]
for i in range(M-1,-1,-1):
  ans.append(totale-e)
  e=joint(bridge[i][0],bridge[i][1],e)
  
for i in range(M-1,-1,-1):
  print(ans[i])
Problem p03137 (python)

Fixed submission:
N,M=[int(i) for i in input().split()]
X=[int(i) for i in input().split()]
X.sort()
rui=[]
for i in range(len(X)-1):
  rui.append(X[i+1]-X[i])
rui.sort()
if N==1:
  print(sum(rui))
elif M>=N:
  print(sum(rui[0:-(N-1)]))
else:
  print(0)

Buggy submission (verdict: Runtime Error):
N,M=[int(i) for i in input().split()]
X=[int(i) for i in input().split()]
X.sort()
rui=[]
for i in range(len(X)-1):
  rui.append(X[i+1]-X[i])
rui.sort()
print(sum(rui[0:-(N-1)]))N,M=[int(i) for i in input().split()]
X=[int(i) for i in input().split()]
X.sort()
rui=[]
for i in range(len(X)-1):
  rui.append(X[i+1]-X[i])
rui.sort()
print(sum(rui[0:-(N-1)]))
Problem p04021 (python)

Fixed submission:
N=int(input())
A=[]
B=[]
for i in range(N):
	if i%2==0:
		A.append(int(input()))
	else:
		B.append(int(input()))
		
A=sorted(A)
B=sorted(B)
C=sorted(A+B)
#ここまでNlogN
c=0
j=0
for i in range(N):
	if j>=len(A):
		break
	if A[j]==C[i]:
		if i%2==1:
			c+=1
		j+=1
print(c)

Buggy submission (verdict: Runtime Error):
N=int(input())
A=[]
B=[]
for i in range(N):
	if i%2==0:
		A.append(int(input()))
	else:
		B.append(int(input()))
		
A=sorted(A)
B=sorted(B)
C=sorted(A+B)
#ここまでNlogN
c=0
j=0
for i in range(C):
	if A[j]==C[i]:
		if i%2==1:
			c+=1
		j+=1
print(c)
Problem p02970 (python)

Fixed submission:
import math
N,D = map(int,input().split())
print(math.ceil(N/(D*2+1)))

Buggy submission (verdict: Runtime Error):
import math
N,D = map(int,input().split)
print(N/(D*2+1))
Problem p03307 (python)

Fixed submission:
N = int(input())
if N % 2 == 0:
    print(N)
else:
    print(2 * N)

Buggy submission (verdict: Runtime Error):
import math
N = int(input())


def lcm(x, y):
    return (x * y) // math.gcd(x, y)


print(lcm(2, N))

Buggy submission (verdict: Runtime Error):
import math
N = int(input())
def lcm(x, y):
    return (x * y) // math.gcd(x, y)
print(lcm(2, N))
Problem p03013 (python)

Fixed submission:
N, M = map(int, input().split())
A = [int(input()) for _ in range(M)]

for i in range(M - 1):
    if A[i] + 1 == A[i + 1]:
        print(0)
        exit()

MAX_N = int(1e5) + 10
memo = [0 for i in range(MAX_N + 10)]
memo[0] = 1
memo[1] = 1
memo[2] = 2
for i in range(3, MAX_N + 10):
    memo[i] = memo[i - 1] + memo[i - 2]

now = 0
ans = 1

for a in A:
    diff = a - now - 1
    ans *= memo[diff]
    ans %= int(1e9 + 7)
    now = a + 1

diff = N - now
ans *= memo[diff]
ans %= int(1e9 + 7)
print(ans)

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
A = [int(input()) for _ in range(M)]

for i in range(M - 1):
    if A[i] + 1 == A[i + 1]:
        print(0)
        exit()

memo = [0 for i in range(N + 10)]
memo[1] = 1
memo[2] = 2
for i in range(3, N + 10):
    memo[i] = memo[i - 1] + memo[i - 2]

ans = 1
for i in range(M):
    if i == 0:
        tmp = A[i] - 1
        if tmp == 0:
            tmp = 1
    else:
        tmp = A[i] - A[i - 1] - 2
    ans *= memo[tmp]
    ans %= int(1e9 + 7)

if N - A[-1] - 1 != 0:
    ans *= memo[(N - A[-1] - 1)]
    ans %= int(1e9 + 7)
print(ans)

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
A = [int(input()) for _ in range(M)]

for i in range(M - 1):
    if A[i] + 1 == A[i + 1]:
        print(0)
        exit()

memo = [0 for i in range(N + 10)]
memo[1] = 1
memo[2] = 2
for i in range(3, N + 10):
    memo[i] = memo[i - 1] + memo[i - 2]

ans = 1
for i in range(M):
    if i == 0:
        tmp = A[i] - 1
        if tmp == 0:
            tmp = 1
    else:
        tmp = A[i] - A[i - 1] - 2
    ans *= memo[tmp]
    ans %= int(1e9 + 7)

ans *= memo[(N - A[-1] - 1)]
ans %= int(1e9 + 7)
print(ans)
Problem p03986 (python)

Fixed submission:
st = []
X = input()
for x in X:
    if not len(st) == 0:
        top = st.pop()
        if top == "S" and x == "T":
            continue
        else:
            st.append(top)
            st.append(x)
    else:
        st.append(x)
print(len(st))

Buggy submission (verdict: Runtime Error):
TSSTTTSS
Problem p03135 (python)

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

Buggy submission (verdict: Runtime Error):
a, b = input().strip().split()
print(a/b)