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

Fixed submission:
import copy
import heapq
H, W = map(int, input().split())
S = [['.'] * (W+1)]
for _ in range(H):
    s = list(input())
    s.insert(0,'.')
    S.append(s)

inf = float('inf')

dp = []
for _ in range(H+1):
    dp.append([inf] * (W+1))

if S[1][1] == '.':
    dp[1][1] = 0
else:
    dp[1][1] = 1

for i in range(1,H+1):
    for j in range(1,W+1):
        right = dp[i][j-1]
        down = dp[i-1][j]
        if S[i][j] == '#':
            if S[i-1][j] == '.':
                down += 1
            if S[i][j-1] == '.':
                right += 1

        dp[i][j] = min(dp[i][j],right,down)

print(dp[H][W])

Buggy submission (verdict: Runtime Error):
import copy
import heapq
H, W = map(int, input().split())
S = []
cnt_list = []
min_cnt = 10**100
for _ in range(H):
    S.append(list(input()))

def move(i,j,cnt,frag):
    global min_cnt
    if cnt > min_cnt:
        return
    c_cnt = copy.deepcopy(cnt)
    c_frag = copy.deepcopy(frag)
    if frag != S[i][j]:
        c_cnt = cnt + 1
    c_frag = S[i][j]
    if i != H-1:
        move(i+1,j,c_cnt,c_frag)
    if j != W-1:
        move(i,j+1,c_cnt,c_frag)
    if i == H-1 and j == W-1:
        if c_cnt < min_cnt:
            min_cnt = c_cnt


if S[0][0] == '#' and S[H][W] == '#':
    a = 1
else :
    a = 0

move(0,0,0,S[0][0])

print(min_cnt//2 + a)
Problem p02759 (python)

Fixed submission:
import math
N = int(input())
print(math.ceil(N/2))

Buggy submission (verdict: Runtime Error):
import math
N = int(input())
print(math.veil(N/2))
Problem p02777 (python)

Fixed submission:
S,T = map(str,input().split())
A,B = map(int,input().split())
U = input()
if(S==U):
  print(A-1,B)
else:
  print(A,B-1)

Buggy submission (verdict: Runtime Error):
S,T = map(input().split())
A,B = map(int,input().split())
U = input()
if(S==U):
  print(A-1,B)
else:
  print(A,B-1)
Problem p02695 (python)

Fixed submission:
import itertools

n,m,q = map(int,input().split())
a = [0] * q
b = [0] * q
c = [0] * q
d = [0] * q
for i in range(q):
    a[i], b[i], c[i], d[i] = map(int, input().split())

mm = [0]*m

for k in range(1,m+1,1):
    mm[k-1]=k

A = list(itertools.combinations_with_replacement(mm, n))
su = 0
ans = 0

for x in range(len(A)):
    l=A[x]
    su = 0
    for h in range(q):
        if l[b[h]-1]-l[a[h]-1] == c[h]:
            su += d[h]

    if su > ans:
        ans = su

print(str(ans))

Buggy submission (verdict: Runtime Error):
n,m,q = map(int,input().split())
a = [0] * q
b = [0] * q
c = [0] * q
d = [0] * q
for i in range(q):
    a[i], b[i], c[i], d[i] = map(int, input().split())

mm = [0]*m

for k in range(1,m+1,1):
    mm[k-1]=k

A = list(itertools.combinations_with_replacement(mm, n))
su = 0
ans = 0

for x in range(len(A)):
    l=A[x]
    su = 0
    for h in range(q):
        if l[b[h]-1]-l[a[h]-1] == c[h]:
            su += d[h]

    if su > ans:
        ans = su

print(str(ans))
Problem p02729 (python)

Fixed submission:
import math

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
  
n,m = map(int,input().split())

su = combinations_count(n+m, 2)
mm = n*m
ans = su-mm

print(str(ans))

Buggy submission (verdict: Runtime Error):
import math

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

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

  su = combinations_count(n+m, 2)
  mm = n*m
  ans = su-mm

  print(str(ans))
Problem p02695 (python)

Fixed submission:
def dfs2(i):
    global ans
    for j in range(num[i-1], m):
        num[i] = j
        if i == n:
            now = 0
            for k in range(q):
                if num[b[k]] - num[a[k]] == c[k]:
                    now += d[k]
            ans = max(ans, now)
        else:
            dfs2(i+1)


n, m, q = map(int, input().split())
a, b, c, d = [], [], [], []
ans = 0

for i in range(q):
    ai, bi, ci, di = map(int, input().split())
    a.append(ai)
    b.append(bi)
    c.append(ci)
    d.append(di)

num = [0] * (n+1)

# dfs([1])
dfs2(1)
print(ans)

Buggy submission (verdict: Runtime Error):
# https://www.youtube.com/watch?v=C5_NnCp1CRI&feature=youtu.be

import sys
sys.stdin = open('input.txt')
import itertools

# C++
# https://atcoder.jp/contests/abc165/submissions/12656990
# Python
# https://atcoder.jp/contests/abc165/submissions/12832942
# https://atcoder.jp/contests/abc165/submissions/12832027
def dfs(A):
    """
    dfs([1]) で使用。index 1 からが本来求めたい数列になる
    """
    global ans
    if len(A) == n+1:
        # print(A)
        now = 0
        for j in range(q):
            if A[b[j]] - A[a[j]] == c[j]:
                now += d[j]
        ans = max(ans, now)
        return
    else:
        # 以下 2 行いずれの場合も、既存リストが mutate されるのでうまく再帰できない
        # A.append(A[-1])
        # A += [A[-1]]
        # 以下は変数の再定義なのでリストは mutate されない
        A = A + [A[-1]]
        # こちらも mutate しない例
        # A = A[:]
        # A.append(A[-1])
        while A[-1] <= m:
            # print(A)
            dfs(A)
            A[-1] += 1

# https://atcoder.jp/contests/abc165/submissions/12679398
# AC
def dfs2(i):
    global ans
    for j in range(num[i-1], m):
        num[i] = j
        if i == n:
            print(num)
            now = 0
            for k in range(q):
                if num[b[k]] - num[a[k]] == c[k]:
                    now += d[k]
            ans = max(ans, now)
        else:
            dfs2(i+1)

def solve_combinations_with_replacement(n, m):
    def update_ans(A):
        global ans
        now = 0
        for j in range(q):
            if A[b[j]-1] - A[a[j]-1] == c[j]:
                now += d[j]
        ans = max(ans, now)
        return

    global ans
    it = [i for i in range(m)]
    for A in itertools.combinations_with_replacement(it, n):
        update_ans(A)


n, m, q = map(int, input().split())
a, b, c, d = [], [], [], []
ans = 0

for i in range(q):
    ai, bi, ci, di = map(int, input().split())
    a.append(ai)
    b.append(bi)
    c.append(ci)
    d.append(di)

dfs([1])

# num = [0] * (n+1)
# dfs2(1)

# solve_combinations_with_replacement(n, m)

print(ans)
Problem p02729 (python)

Fixed submission:
import sys
# sys.stdin = open('input.txt')

import math

n,m = map(int, input().split())
def c(n):
    return int(math.factorial(n) / math.factorial(n-2) / math.factorial(2))

if n == 1 and m == 1:
    print(0)
elif n <= 1:
    print(c(m))
elif m <= 1:
    print(c(n))
else:
    print(c(n)+c(m))

Buggy submission (verdict: Runtime Error):
import sys
# sys.stdin = open('input.txt')

import math

n,m = map(int, input().split())
def c(n):
    return int(math.factorial(n) / math.factorial(n-2) / math.factorial(2))

if n == 1 and m == 1:
    print(0)
else:
    print(c(n)+c(m))
Problem p02754 (python)

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

ans = 0
ans += n // (a + b) * a
rem = n % (a + b)
if a == 0:
    pass
elif rem > a:
    ans += a
elif rem <= a:
    ans += rem
print(ans)

Buggy submission (verdict: Runtime Error):
n,a,b = map(int, input().split())

s = ''
for i in range(10**100):
    s += 'b' * a
    s += 'r' * b
    if len(s) > n:
        break
print(s[:n].count('b'))
Problem p03631 (python)

Fixed submission:
a,b,c=input()
if a == c:
  print('Yes')
else:
  print('No')

Buggy submission (verdict: Runtime Error):
a,b,c=input()
if a == c: print('Yes') else: print('No')
Problem p02819 (python)

Fixed submission:
import random


def is_prime3(q, k=50):
    q = abs(q)
    if q == 2:
        return True
    if q < 2 or q & 1 == 0:
        return False

    # n-1=2^s*dとし（但しaは整数、dは奇数)、dを求める
    d = (q-1) >> 1
    while d & 1 == 0:
        d >>= 1

    # 判定をk回繰り返す
    for i in range(k):
        a = random.randint(1, q-1)
        t = d
        y = pow(a, t, q)
        # [0,s-1]の範囲すべてをチェック
        while t != q-1 and y != 1 and y != q-1:
            y = pow(y, 2, q)
            t <<= 1
        if y != q-1 and t & 1 == 0:
            return False
    return True


X = int(input())

while not is_prime3(X):
    X += 1

print(X)

Buggy submission (verdict: Runtime Error):
def is_prime(n, k=100):
    n = abs(n)
    if n == 2:
        return True
    if n < 2 or n&1 == 0:
        return False
    for i in xrange(3, k):
        x, y = n, i
        while y:
            x, y = y, x%y
        if x != 1:
            continue
        if pow(2, n-1, n) != 1:
            return False
    return True


X = int(input())

while True:
    if is_prime(X):
        print(X)
        break
    X += 1
Problem p02693 (python)

Fixed submission:
A = int(input())
B, C = map(int,input().split())
flag = 1

for i in range(B, C+1):
  if i % A == 0:
    flag = 0
    print("OK")
    break

if flag==1:
  print("NG")

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

for i in range(B, C+1):
  if i % A =0:
    print("OK")
    break

print("NG")
Problem p02835 (python)

Fixed submission:
A1,A2,A3=map(int,input().split())
ans =(A1+A2+A3)

if ans >= 22:
     print ("bust")
else:
     print ("win")

Buggy submission (verdict: Runtime Error):
ans = A1+A2+A3

if ans >= 22:
     print ("bust")

else:
     print ("win")
Problem p02659 (python)

Fixed submission:
from decimal import Decimal
N = [Decimal(e) for e in input().split()]
ans = Decimal(N[0]) * Decimal(N[1])
print(int(ans))

Buggy submission (verdict: Runtime Error):
import math
N = [float(e) for e in input().split()]
ans = str(N[0]*N[1])
ans1 = ans[0:-2]
print(int(ans1))
Problem p03315 (python)

Fixed submission:
#coding: utf-8

counter = 0
inputStr = input()

strA = "+"
strB = "-"

for i in range(1, 5):
    if inputStr[i-1:i] == strA:
        counter += 1
    else:
        counter -= 1

print (counter)

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

inputN, inputK = map(int, input().split())
inputA = list(map(int, input().split()))
minNumber = inputN
minPos = 0

if inputN == inputK:
    print (1)
elif inputN <= (inputK-1)*100000 + 1:
    for i in range(2, 100001):
        if inputN <= (inputK-1)*i + 1:
            print (i)
            break
else:

    for i in range(len(inputA)):
        if inputA[i] < minNumber:
            minNumber = inputA[i]
            minPos = i

    splitNumber = (inputN + 1) / (inputK - 1)
    print (int(splitNumber))

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

inputN, inputK = map(int, input().split())
inputA = list(map(int, input().split()))
minNumber = inputN
minPos = 0

if inputN == inputK:
    print (1)
elif inputN <= (inputK-1)*2 + 1:
    print (2)
elif inputN <= (inputK-1)*3 + 1:
    print (3)
elif inputN <= (inputK-1)*4 + 1:
    print (4)
elif inputN <= (inputK-1)*5 + 1:
    print (5)
else:
    for i in range(len(inputA)):
        if inputA[i] < minNumber:
            minNumber = inputA[i]
            minPos = i

    splitNumber = (inputN + 1) / (inputK - 1)
    print (int(splitNumber))
Problem p02659 (python)

Fixed submission:
a, b = input().split()
b = int(b[0] + b[2:])
print(str(int(a) * b)[0:-2] or 0)

Buggy submission (verdict: Runtime Error):
a, b = input().split()
a = int(a)
b = int(round(b * 100))
print(int(rount(a * b / 100)))
Problem p02659 (python)

Fixed submission:
a, b = [float(num) for num in input().split()]
a = int(a)
b = round(b * 100)
r = a * b // 100
print(r)

Buggy submission (verdict: Runtime Error):
import math

a, b = [float(num) for num in input().split()]
r = floor(a * b)
print(r)
Problem p02659 (python)

Fixed submission:
import math
A, B = map(float, input().split())
A = int(A)
B = int(B*1000)
ans = A * B // 1000
print(ans)

Buggy submission (verdict: Runtime Error):
import math
A, B = map(int, input().split())
S = '100' + str(B)
S = int(S)

ans = A * B /100
print(ans)
Problem p02688 (python)

Fixed submission:
N, K =map(int, input().split())
snuke = [0]*N

for i in range(K):
    d = int(input())
    a = list(map(int,input().split()))
    for j in range(d):
        snuke[a[j]-1] = 1

print(snuke.count(0))

Buggy submission (verdict: Runtime Error):
N, K =map(int, input().split())
snuke = [0]*N

for i in range(K):
    d = int(input())
    a = list(map(int,input().split()))
    for j in range(d):
        snuke[a[j]] = 1

print(snuke.count(0))
Problem p02689 (python)

Fixed submission:
N, M = map(int, input().split())
H = list(map(int, input().split())) 
A = [0]*M
B = [0]*M
for i in range(M):
    A[i], B[i] = map(int, input().split())
    A[i] -= 1
    B[i] -= 1
lis = []
for i in range(M):
    if H[A[i]] < H[B[i]]:
        lis.append(A[i])
    if H[A[i]] == H[B[i]]:
        lis.append(A[i])
        lis.append(B[i])
    if H[A[i]] > H[B[i]]:
        lis.append(B[i])
print(len(H)-len(set(lis)))

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
H = list(map(int, input().split())) 
A = [0]*M
B = [0]*M
for i in range(M):
    A[i], B[i] = map(int, input().split())
    A[i] -= 1
    B[i] -= 1
lis = []
for i in range(M):
    if H[A[i]] < H[B[i]]:
        min.append(A[i])
    if H[A[i]] == H[B[i]]:
        min.append(A[i])
        min.append(B[i])
    if H[A[i]] > H[B[i]]:
        min.append(B[i])
print(len(set(lis)))
Problem p02754 (python)

Fixed submission:
N, A, B = map(int, input().split())
ans = N//(A+B) * A
tmp = N%(A+B)

print(ans + min(tmp, A))

Buggy submission (verdict: Runtime Error):
N, A, B = map(int, input().split())
St = ''
while len(St) < N:
    St += 'b' * A + 'r' * B
ans = 0

for i in range(0, N):
    if St[i] == 'b':
        ans += 1
    

print(ans)
Problem p02785 (python)

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

H.sort(reverse=True)
print(sum(H[K:]))

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

H.sort(reverse=True)
print(sum(H[K:]))
Problem p02829 (python)

Fixed submission:
x = int(input())
y = int(input())

if (x==1)&(y==2):
    print('3')
elif (x==2)&(y==3):
    print('1')
elif (x==3) & (y==1):
    print('2')
elif (x==1) & (y==3):
    print('2')
elif (x==2) & (y==1):
    print('3')
elif (x==3) & (y==2):
    print('1')

Buggy submission (verdict: Runtime Error):
x,y = map(int,input().split())

if (x==1)&(y==2):
    print('3')
elif (x==2)&(y==3):
    print('1')
elif x==3 & y==1:
    print('2')
elif x==1 & y==3:
    print('2')
elif x==2 & y==1:
    print('3')
else:print('1')

Buggy submission (verdict: Runtime Error):
x,y = map(int,input().split())

if (x==1)&(y==2):
    print('3')
elif (x==2)&(y==3):
    print('1')
elif x==3 & y==1:
    print('2')
elif x==1 & y==3:
    print('2')
elif x==2 & y==1:
    print('3')
else:print('1')
Problem p02831 (python)

Fixed submission:
import fractions
x,y = map(int,input().split())
ans = (x*y)/(fractions.gcd(x, y))
print(round(ans))

Buggy submission (verdict: Runtime Error):
import math
x,y = map(int,input().split())
ans = (x*y)/(math.gcd(x, y))
print(ans)
Problem p02659 (python)

Fixed submission:
from decimal import Decimal
a,b = map(float, input().split())
ans = Decimal(str(a)) * Decimal(str(b))

  
print(int(ans))

Buggy submission (verdict: Runtime Error):
a,b = map(float, input().split())
a = int(a)
b_int = int(b)
b_frac = b*100-b*int*100

ans = a*b_int+(a*b_frac)//100
  
print(ans)
Problem p02759 (python)

Fixed submission:
i = input()
a = int(i)//2
b = int(i)%2
print(a+b)

Buggy submission (verdict: Runtime Error):
i = input()
a = i//2
b = i%2
print(a+b)
Problem p02835 (python)

Fixed submission:
#ABC147-A #Blackjack                                                                                             
a,b,c = map(int, input().split())
if a+b+c >= 22:
    print("bust")
else:
    print("win")

Buggy submission (verdict: Runtime Error):
a,b,c = map(int, input().split())
if a+b+c >= 22:
print("bust")
else:
    ("win")
Problem p02987 (python)

Fixed submission:
s = input()
t = [s[0], s[1], s[2], s[3]]
u = list(set(t))
v = len(u)
if v != 2:
    print("No")
else:
    w = s.count(u[0])
    x = s.count(u[1])
    if w == 2 and x ==2:
      print("Yes")
    else:
      print("No")

Buggy submission (verdict: Runtime Error):
s = input()
t = [s[0], s[1], s[2], s[3]]
u = list(set(t))
v = len(u)
w = s.count(u[0])
x = s.count(u[1])
if v != 2:
    print("No")
else:
    w = s.count(u[0])
    x = s.count(u[1])
    if w == 2 and x ==2:
	print("Yes")
    else:
	print("No")
Problem p03075 (python)

Fixed submission:
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())
ab = b-a
ac = c-a
ad = d-a
ae = e-a
bc = c-b
bd = d-b
be = e-b
cd = d-c
ce = e-c
de = e-d
if ab <= k and ac <= k and ad <= k and ae <= k and bc <= k and bd <= k and be <= k and cd <= k and ce <= k and de <= k:
    print("Yay!")
else:
    print(":(")

Buggy submission (verdict: Runtime Error):
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())
ab = b-a
ac = c-a
ad = d-a
ae = e-a
bc = c-b
bd = d-b
be = e-b
cd = d-c
ce = e-c
de = e-d
if ab <=	k and ac <= k and ad <= k	and ae <= k and bc <= k and bd <= k and be <= k and cd <= k and ce <= k and d\
e <= k:
    print("Yay!")
else:
    print(":(")
Problem p02699 (python)

Fixed submission:
inp1=list(map(int,input().strip().split()))[:2]
s,w=inp1[0],inp1[1]
if(w >= s):
	print("unsafe")
else:
	print("safe")

Buggy submission (verdict: Runtime Error):
def check(a,b,c,d):
	while(a>0 and c>0):
		c-=b
		if(c==0):
			return 1
		a-=d
		if(a==0):
			return 0
	if(a<0):
		return 0
	if(c < 0):
		return 1
inp1=list(map(int,input().strip().split()))[:4]
a,b,c,d=inp1[0],inp1[1],inp1[2],inp1[3]
if(check(a,b,c,d)):
	print("Yes")
else:
	print("No")

Buggy submission (verdict: Runtime Error):
def check(a,b,c,d):
	while(a>0 and c>0):
		c-=b
		if(c==0):
			return 1
		a-=d
		if(a==0):
			return 0
	if(a<0):
		return 0
	if(c < 0)
		return 1
inp1=list(map(int,input().strip().split()))[:4]
a,b,c,d=inp1[0],inp1[1],inp1[2],inp1[3]
if(check(a,b,c,d)):
	print("Yes")
else:
	print("No")
Problem p02753 (python)

Fixed submission:
s=input()
dict1={}
if('A' in s and 'B' in s):
	print("Yes")
else:
	print("No")

Buggy submission (verdict: Runtime Error):
s=input()
dict1={}
for i in s:
	if i in dict1:
		dict1[i]+=1
	else:
		dict1[i]=0
if(dict1['A'] > 0 and dict1['B'] > 0):
	print("Yes")
else:
	print("No")
Problem p02766 (python)

Fixed submission:
inp=list(map(int,input().strip().split()))[:2]
n,r=inp[0],inp[1]
count=0
while(n > 0):
    n=n//r
    count+=1
print(count)

Buggy submission (verdict: Runtime Error):
inp=list(map(int,input().strip().split()))[:2]
n,r=inp[0],inp[1]
count=0
while(n > 0):
  n=n//r
  count+=1
return count

Buggy submission (verdict: Runtime Error):
inp=list(map(int,input().strip().split()))[:2]
n,r=inp[0],inp[1]
count=0
while(n > 0):
  n=n//k
  count+=1
return count
Problem p02771 (python)

Fixed submission:
arr=list(map(int,input().strip().split()))[:3]
dict1={}
for i in arr:
    if i in dict1:
        dict1[i]+=1
    else:
        dict1[i]=1
if(len(dict1)==2):
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
arr=list(map(int,input().strip().split()))[:3]
if(arr[0]==arr[1] and arr[0]!=arr[2]):
  print("Yes")
elif(arr[1]==arr[2] and arr[1]!=arr[0]):
  print("Yes")
elif(arr1[0]==arr[2] and arr1[0]!=arr[1]):
  print("Yes")
else:
  print("No")
Problem p02659 (python)

Fixed submission:
from decimal import *

a, b = input().split()

ab = Decimal(a) * Decimal(b)
result = Decimal(str(ab)).quantize(Decimal(str(1)), rounding=ROUND_DOWN)

print(int(result))

Buggy submission (verdict: Runtime Error):
from decimal import Decimal

a, b = map(float, input().split())

ab = Decimal(a) * Decimal(b)
result = str(ab).split('.')

print(int(result[0]))
Problem p02693 (python)

Fixed submission:
k = int(input())
a,b = map(int, input().split())
 
if (b // k) * k >= a:
  print('OK')
else:
  print('NG')

Buggy submission (verdict: Runtime Error):
import random
k = int(input())
a, b = map(int, input().split())
c = random.randrange(a, b)
if c % k == 0:
  print('OK')
else:
  print('NG')
Problem p02829 (python)

Fixed submission:
print(6-int(input())-int(input()))

Buggy submission (verdict: Runtime Error):
s=[1,2,3];s.pop(int(input());s.pop(int(input());print(s[0])
Problem p02863 (python)

Fixed submission:
import numpy as np
N,T = map(int, raw_input().split())
L = [map(int, raw_input().split()) for i in range(N)]
d=np.zeros(10000,int)
for a,b in sorted(L):
    t=d[a:T+a]
    np.maximum(t,d[:T]+b,t)
print(max(d))

Buggy submission (verdict: Runtime Error):
import numpy as np
N,T = map(int, raw_input().split())
L = [map(int, raw_input().split()) for i in range(N)]
d=np.zeros(1000,int)
for a,b in sorted(L):
    t=d[a:T+a]
    np.maximum(t,d[:T]+b,t)
print(max(d))
Problem p02729 (python)

Fixed submission:
n,m=(int(x) for x in input().split())
sum=int((n*(n-1)/2)+(m*(m-1)/2))
print(sum)

Buggy submission (verdict: Runtime Error):
n,m = (int(x) for x in input('').split(''))
sum = (n * (n - 1) / 2) + (m * (m - 1) / 2)
print(sum)
Problem p03805 (python)

Fixed submission:
import sys

# 再帰上限を引き上げる
sys.setrecursionlimit(10**6)

count = 0
def dfs(graph, v, seen):

    if not False in seen:
        global count
        count += 1
        return

    # 頂点vから行ける頂点を全探索
    for i in graph[v]:
        if seen[i]:
            continue
        seen[i] = True
        dfs(graph, i, seen)
        seen[i] = False
    
    return

# ここから本文
N, M = map(int, input().split())

# グラフ構造を作る
graph = [[] for i in range(N)]
for i in range(M):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    graph[a].append(b)
    graph[b].append(a)

seen = [False for i in range(N)]
seen[0] = True
dfs(graph, 0, seen)

print(count)

Buggy submission (verdict: Runtime Error):
import sys
# 再帰上限を引き上げる
sys.setrecursionlimit(10**6)

####
# DFS(深さ優先探索

count = 0
def dfs(graph, v, seen):
    #print(seen)
    # Falseがない、つまり頂点が1個しかない場合は、1を返す
    if not False in seen:
        global count
        count +=1
        return
    
    # 頂点Vから行ける頂点を全探索
    for i in graph[v]:
        # 行ける場所はTrueである。
        if seen[i]:
            continue
        
        # いったんTrueにして
        seen[i] = True
        # 探索したら
        dfs(graph, i, seen)
        # 戻す
        seen[i] = False
        
    return
        
        

####

M, N = map(int, input().split())

# グラフを作る
graph = [[] for i in range(N)]
#print(graph)

for i in range(M):
    a, b = map(int, input().split())
    # index番号にあわせたいので、1引く
    a -= 1
    b -= 1
    graph[a].append(b)
    graph[b].append(a)
    
seen = [False for i in range(N)]
seen[0] = True
#print(seen)

dfs(graph, 0, seen)

# 全探索できた数を表示
print(count)

Buggy submission (verdict: Runtime Error):
import sys
# 再帰上限を引き上げる
sys.setrecursionlimit(10**6)

####
# DFS(深さ優先探索

count = 0
def dfs(graph, v, seen):
    #print(seen)
    # Falseがない、つまり頂点が1個しかない場合は、1を返す
    if not False in seen:
        global count
        count +=1
        return
    
    # 頂点Vから行ける頂点を全探索
    for i in graph[v]:
        # 行ける場所はTrueである。
        if seen[i]:
            continue
        
        # いったんTrueにして
        seen[i] = True
        # 探索したら
        dfs(graph, i, seen)
        # 戻す
        seen[i] = False
        
    return
        
        

####

M, N = map(int, input().split())

# グラフを作る
graph = [[] for i in range(N)]
#print(graph)

for i in range(M):
    a, b = map(int, input().split())
    # index番号にあわせたいので、1引く
    a -= 1
    b -= 1
    graph[a].append(b)
    graph[b].append(a)
    
seen = [False for i in range(M)]
seen[0] = True
#print(seen)

dfs(graph, 0, seen)

# 全探索できた数を表示
print(count)
Problem p03834 (python)

Fixed submission:
print(input().replace(',', ' '))

Buggy submission (verdict: Runtime Error):
print(input().replace("," " "))
Problem p03835 (python)

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

ans = 0
if K*3<S:
  print(0)
  exit()

for x in range(K, -1, -1):
  if x >S:
    continue
  for y in range(min(S-x, K), -1, -1):
    if x+y >S:
      continue
    for z in range(min(S-x-y, K), -1, -1):
      if x+y+z==S:
        ans+=1
      elif x+y+z<S:
        break

print(ans)

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

ans = 0
if K*3<S:
  print(0)
  exit()

for x in range(K, -1, -1):
  if x >S:
    continu
  for y in range(K, -1, -1):
    if x+y >S:
      continue
    for z in range(K, -1, -1):
      if x+y+z==S:
        ans+=1
      elif x+y+z<S:
        break

print(ans)