Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
N = int(input())
a = list(map(int, input().split()))
res = 0
a.sort()

for i in range(N-1):
    if a[i] != a[i+1]:
        count = i + 1 - count 
        if count < a[i]:
            res += count
        else:
            res += count - a[i]
        
        
print(res)

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

if c%2 == 0:
    print(int(c/2))
    
else:
    print(int(c/2)+1)

Buggy python submission (verdict: Runtime Error):
N = int(input())
a = list(map(int, input().split()))
res = 0
a.sort()
count = 1
for i in range(N-1):
    if a[i] != a[i+1]:
        count = i - count 
        if count < a[i]:
            res += count
        else:
            res += count - a[i]
        
        
print(res)
  

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

if c%2 == 0:
    print(int(c/2))
    
else:
    print(int(c/2)+1)

Buggy python submission (verdict: Runtime Error):
N = int(input())
a = list(map(int, input().split()))
res = 0
a.sort()

for i in range(N):
    X = a.count(i+1)
    if a[i] > N:
        res += N - i
        break
        
    elif X < i+1:
        res += X
        i = i  + X
        
    else:
        res += X - (i+1)
        i = i  + X
        
print(res)

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

if c%2 == 0:
    print(int(c/2))
    
else:
    print(int(c/2)+1)
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
A = list(map(int, input().split()))
L = list(set(A))
res = 0
num = []

if len(L) <= K:
    res = 0

else:
    for i in L:
        num.append(A.count(i))
    
    num.sort()

    for i in range(len(L) - K):
        res += num[i]

print(res)

Fixed submission:
from collections import Counter
d = Counter() 
N, K = map(int, input().split())
A = list(map(int, input().split()))
L = list(set(A))
res = 0
num = []
d.update(A)
if len(L) <= K:
    res = 0

else:
    for i in L:
        num.append(d[i])
    
    num.sort()

    for i in range(len(L) - K):
        res += num[i]

print(res)
Buggy python submission (verdict: Runtime Error):
s = input()

dic = {}
for i in range(len(s)):
  if s[i] in dic:
    dic[s[i]] += 1
  else:
    dic[s[i]] = 1

if len(dic) == 1:
  if len(s) == 1:
    print('YES')
  else:
    print('No')

elif len(dic) == 2:
  print('NO')

else:
  first = 'a'
  second = 'b'
  for k, v in dic.items():
    if  v > dic[first]:
      second = first
      first = k

    elif v > dic[second]:
      second = k

  tmp = first + second
  dic[first] -= 1
  dic[second] -= 1
  ans = 'YES'
  for i in range(1, len(s) - 1):
    if tmp[i-1] == 'a':
      if tmp[i] == 'b':
        if dic['c'] == 0:
          ans = 'NO'
          break
        else:
          dic['c'] -= 1
          tmp += 'c'

      if tmp[i] == 'c':
        if dic['b'] == 0:
          ans = 'NO'
          break
        else:
          dic['b'] -= 1
          tmp += 'b'

    elif tmp[i-1] == 'b':
      if tmp[i] == 'a':
        if dic['c'] == 0:
          ans = 'NO'
          break
        else:
          dic['c'] -= 1
          tmp += 'c'

      if tmp[i] == 'c':
        if dic['a'] == 0:
          ans = 'NO'
          break
        else:
          dic['a'] -= 1
          tmp += 'a'

    elif tmp[i-1] == 'c':
      if tmp[i] == 'a':
        if dic['b'] == 0:
          ans = 'NO'
          break
        else:
          dic['b'] -= 1
          tmp += 'b'

      if tmp[i] == 'b':
        if dic['a'] == 0:
          ans = 'NO'
          break
        else:
          dic['a'] -= 1
          tmp += 'a'

  print(ans)


Fixed submission:
s = input()

dic = {}
for i in range(len(s)):
  if s[i] in dic:
    dic[s[i]] += 1
  else:
    dic[s[i]] = 1

if len(dic) == 1:
  if len(s) == 1:
    print('YES')
  else:
    print('NO')

elif len(dic) == 2:
  if len(s) == 2:
    print('YES')
  else:
    print('NO')

else:
  first = 'a'
  second = 'b'
  for k, v in dic.items():
    if  v > dic[first]:
      if k != first:
        second = first
        first = k

    elif v > dic[second]:
      if k != second and k != first:
        second = k


  tmp = first + second
  dic[first] -= 1
  dic[second] -= 1
  ans = 'YES'

  for i in range(1, len(s) - 1):
    if tmp[i-1] == 'a':
      if tmp[i] == 'b':
        if dic['c'] == 0:
          ans = 'NO'
          break
        else:
          dic['c'] -= 1
          tmp += 'c'

      if tmp[i] == 'c':
        if dic['b'] == 0:
          ans = 'NO'
          break
        else:
          dic['b'] -= 1
          tmp += 'b'

    elif tmp[i-1] == 'b':
      if tmp[i] == 'a':
        if dic['c'] == 0:
          ans = 'NO'
          break
        else:
          dic['c'] -= 1
          tmp += 'c'

      if tmp[i] == 'c':
        if dic['a'] == 0:
          ans = 'NO'
          break
        else:
          dic['a'] -= 1
          tmp += 'a'

    elif tmp[i-1] == 'c':
      if tmp[i] == 'a':
        if dic['b'] == 0:
          ans = 'NO'
          break
        else:
          dic['b'] -= 1
          tmp += 'b'

      if tmp[i] == 'b':
        if dic['a'] == 0:
          ans = 'NO'
          break
        else:
          dic['a'] -= 1
          tmp += 'a'

  print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

def ryuka(n):
    if n == 0:
        return 2
    elif n == 1:
        return 1
    else:
        return ryuka(n-1) + ryuka(n-2)

print(ryuka(N))

Fixed submission:
N = int(input())
a = 2
b = 1

for i in range(N):
    c = a + b
    a = b
    b = c

print(a)
Buggy python submission (verdict: Runtime Error):
N = int(input())

for i in range(1, N):
    if i*i > N:
        break
        
    res = i * i

print(res)


Fixed submission:
l = input()
m = input()
res = 'YES'


if l[0] != m[2]:
    res = 'NO'
    
if l[1] != m[1]:
    res = 'NO'
    
if l[2] != m[0]:
    res = 'NO'
        
print(res)
Buggy python submission (verdict: Runtime Error):
import bisect
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort()
C.sort()
res = 0
for i in B:
    res += bisect.bisect_right(A, i) * (N - bisect.bisect_left(C, i))
    
print(res)

Fixed submission:
N = int(input())

for i in range(N+1):
    n = i*i
    if n > N:
        break
        
    res = n

print(res)

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

for i in range(1, N):
    n = i*i
    if n > N:
        break
        
    res = n

print(res)

Fixed submission:
N = int(input())

for i in range(N+1):
    n = i*i
    if n > N:
        break
        
    res = n

print(res)

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

for i in range(1, N):
    if i*i > N:
        break
        
    res = i * i

print(res)


Fixed submission:
N = int(input())

for i in range(N+1):
    n = i*i
    if n > N:
        break
        
    res = n

print(res)
Buggy python submission (verdict: Runtime Error):
import bisect
N = int(input())

A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

A.sort()
C.sort()

res = 0
for b in B:
    bisect_index_A = bisect.bisect_left(A, b)
    bisect_index_C = bisect.bisect_right(C, b)
    res += insert_index_A * (N - insert_index_C)
    
print(res)

Fixed submission:
import bisect
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort()
C.sort()
res = 0
for i in B:
    res += bisect.bisect_left(A, i) * (N - bisect.bisect_right(C, i))
    
print(res)

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

A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

A.sort()
C.sort()

res = 0
for b in B:
    insert_index_A = bisect.bisect_left(A, b)
    insert_index_C = bisect.bisect_right(C, b)
    res += insert_index_A * (N - insert_index_C)
    
print(res)

Fixed submission:
import bisect
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort()
C.sort()
res = 0
for i in B:
    res += bisect.bisect_left(A, i) * (N - bisect.bisect_right(C, i))
    
print(res)
Buggy python submission (verdict: Runtime Error):
N = int(input())
items = [input() for _ in range(N)]

print(len(set(items)))

Fixed submission:
R = int(input())
G = int(input())

print(2*G-R)

Buggy python submission (verdict: Runtime Error):
S = input()
T = input()
res = ''
end = -1
for i in range(len(S) - len(T) + 1):
    for j in range(len(T)):
        start = i
        
        if S[i+j] == T[j]:
            end = i + j
            flag == 1
        elif S[i+j] == '?':
            end = i + j
            flag == 0
        else:
            pass
            break
    if flag == 1:
        break
            
if end == -1:
    print('UNRESTORABLE')
    
else:
    j = 0
    for i in range(len(S)):
        if start <= i <= end:
            res += T[j]
            j += 1

        elif S[i] == '?':
            res += 'a'

        else:
            res += S[i]

    print(res)

Fixed submission:
R = int(input())
G = int(input())

print(2*G-R)
Buggy python submission (verdict: Runtime Error):
W, H=map(int,input().split())
arr = [input() for j in range(W)]
ans = ['' for i in range(H)] 

for i in range(0, W):
    for j in range(0, H):
        bomb_num = 0
        if arr[i][j] == '#':
            ans[i] += '#'
        else:
            for k in (-1, 0, 1):
                for l in (-1, 0, 1):
                    if (-1<i+k<W) and (-1<j+l<H):
                        if arr[i+k][j+l] == '#':
                            bomb_num += 1
                        
            ans[i] += str(bomb_num)
            
for i in range(W):
        print(ans[i])

Fixed submission:
W, H=map(int,input().split())
arr = [input() for j in range(W)]
ans = ['' for i in range(W)] 

for i in range(0, W):
    for j in range(0, H):
        bomb_num = 0
        if arr[i][j] == '#':
            ans[i] += '#'
        else:
            for k in (-1, 0, 1):
                for l in (-1, 0, 1):
                    if (-1<i+k<W) and (-1<j+l<H):
                        if arr[i+k][j+l] == '#':
                            bomb_num += 1
                        
            ans[i] += str(bomb_num)
            
for i in range(W):
        print(ans[i])
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
L = [int(input()) for i in range(N)]
a = []
for i in L:
    if i in a:
        a.remove(i)
    else:
        a.append(i)
print(len(a))

Fixed submission:
N = int(input())
L = [int(input()) for i in range(N)]
L.sort()
res = 0
i = 0
while i < len(L)-1:
    if L[i] == L[i+1]:
        res += 2
        i += 1
    i += 1
    
print(len(L)-res)

Buggy python submission (verdict: Time Limit Exceeded):
import collections
N = int(input())
L = [int(input()) for i in range(N)]
a = []
for i in L:
    if i in a:
        a.remove(i)
    else:
        a.append(i)
print(len(a))

Fixed submission:
N = int(input())
L = [int(input()) for i in range(N)]
L.sort()
res = 0
i = 0
while i < len(L)-1:
    if L[i] == L[i+1]:
        res += 2
        i += 1
    i += 1
    
print(len(L)-res)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
L = list(map(int, input().split())) 
res = 0
for i in range(10**5):
    count = L.count(i) + L.count(i+1) + L.count(i+2)
    if count > res:
        res = count
print(res)

Fixed submission:
N = int(input())
L = list(map(int, input().split()))
K = [ 0 for i in range(10**5)]
for i in range(N):
    K[L[i]] += 1
a = []   
res = 0
for i in range(len(K)):
    a.append(K[i])
    if len(a) > 3:
        a.pop(0)
    if sum(a) > res:
        res =sum(a)
print(res)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
L = list(map(int, input().split())) 
res = 0
for i in range(10**5):
    count = L.count(i) + L.count(i+1) + L.count(i+2)
    if count > res:
        res = count
print(res)

Fixed submission:
N = int(input())
L = list(map(int, input().split()))
K = [ 0 for i in range(10**5)]
for i in range(N):
    K[L[i]] += 1
a = []   
res = 0
for i in range(len(K)):
    a.append(K[i])
    if len(a) > 3:
        a.pop(0)
    if sum(a) > res:
        res =sum(a)
print(res)
Buggy python submission (verdict: Runtime Error):
S = input()
S_list = list(set(S))
al = 'abcdefghijklmnopqrstucwxyz'
al_list = list(al)
S_list.sort()

for i in range(len(S)):
    if al_list[i] in S_list:
        pass
    else:
        print(al_list[i])
        break
    
if i == len(S) - 1:
    print('None')

Fixed submission:
S = input()
S_list = list(set(S))
al = 'abcdefghijklmnopqrstucwxyz'
al_list = list(al)
S_list.sort()
flg = 1
for i in range(len(al_list)):
    if al_list[i] in S_list:
        pass
    else:
        print(al_list[i])
        flg = 0
        break
    
if flg == 1:
    print('None')
Buggy python submission (verdict: Runtime Error):
N = int(input())
L = list(map(int, input().split()))
L.sort()
a = [0,0]
count = 0
for i in range(N):
    count += 1
    if i == N-1:
        if count >= 2:
            a.append(L[i])
            a.pop(0)
            res = a[0]*a[1] 
        count = 0
    elif L[i] != L[i+1]:
        if count >= 2:
            a.append(L[i])
            a.pop(0)
            res = a[0]*a[1]
        count = 0
            
print(res)

Fixed submission:
N = int(input())
L = list(map(int, input().split()))
L.sort()
a = [0,0]
count = 0
for i in range(N):
    count += 1
    if i == N-1:
        if count >= 2:
            a.append(L[i])
        if count >= 4:
            a.append(L[i])
        count = 0
        
    elif L[i] != L[i+1]:
        if count >= 2:
            a.append(L[i])
        if count >= 4:
            a.append(L[i])
        count = 0
            
print(a[-1]*a[-2])
Buggy python submission (verdict: Runtime Error):
N = int(input())
L = [ int(input()) for i in range(N)]
L.sort()

def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)

def lcm(a, b):
    return a * b / gcd(a, b)

x = L[0]
for i in range(len(L)-1):
    y = lcm(x, L[i+1])
    x = y
    
print(int(x))

Fixed submission:
N = int(input())
L = [ int(input()) for i in range(N)]

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def lcm(a, b):
    return a * b // gcd(a, b)

x = L[0]
for i in range(len(L)-1):
    y = lcm(x, L[i+1])
    x = y
    
print(x)

Buggy python submission (verdict: Runtime Error):
N = int(input())
L = [ int(input()) for i in range(N)]

def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)

def lcm(a, b):
    return a * b / gcd(a, b)

x = L[0]
for i in range(len(L)-1):
    y = lcm(x, L[i+1])
    x = y
    
print(int(x))

Fixed submission:
N = int(input())
L = [ int(input()) for i in range(N)]

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def lcm(a, b):
    return a * b // gcd(a, b)

x = L[0]
for i in range(len(L)-1):
    y = lcm(x, L[i+1])
    x = y
    
print(x)

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

N = int(input())
L = [ int(input()) for i in range(N)]

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

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

print(lcm_list(L))

Fixed submission:
N = int(input())
L = [ int(input()) for i in range(N)]

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def lcm(a, b):
    return a * b // gcd(a, b)

x = L[0]
for i in range(len(L)-1):
    y = lcm(x, L[i+1])
    x = y
    
print(x)

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

N = int(input())
L = [ int(input()) for i in range(N)]


def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

print(lcm_list(L))

Fixed submission:
N = int(input())
L = [ int(input()) for i in range(N)]

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def lcm(a, b):
    return a * b // gcd(a, b)

x = L[0]
for i in range(len(L)-1):
    y = lcm(x, L[i+1])
    x = y
    
print(x)
Buggy python submission (verdict: Runtime Error):
S = input()

print(S[0] + str(len(S-2)) + S[-1])

Fixed submission:
S = input()

print(S[0] + str(len(S)-2) + S[-1])

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

print(S[0] + len(S) + S[-1])

Fixed submission:
S = input()

print(S[0] + str(len(S)-2) + S[-1])
Buggy python submission (verdict: Runtime Error):
H, W = map(int, input().split())
N = int(input())
A = list(map(int, input().split()))
res = [[-1 for _ in range(W)] for _ in range(H)]

x = 0
y = 0
for i in range(N):
    if x + A[i] <= W:
        for j in range(A[i]):
            res[y][x + j] = i + 1
            
        x = x + A[i]
            
    else:
        for j in range(x, W):
            res[y][j] = i + 1
            
        y = y + 1
        
        for j in range(A[i] - (W - x) + 1):
            res[y][j] = i + 1
            
        x = 0
        
for i in range(H):
    result = ''
    for j in range(W):
        result =  result + str(res[i][j])
        if j != W - 1:
            result += ' '
        
    print(result)
        

Fixed submission:
H, W = map(int, input().split())
N = int(input())
A = list(map(int, input().split()))
res = [[-1 for _ in range(W)] for _ in range(H)]
tmp = []
for i in range(N):
    for j in range(A[i]):
        tmp.append(i + 1)
        
for i in range(H):
    result = ''
    for j in range(W):
        if i%2 == 0:
            result = result + str(tmp[W * i + j])
            if j != W - 1:
                result = result + ' '
        else:
            result =  str(tmp[W * i + j]) + result
            if j != W - 1:
                result = ' ' + result 
            
    print(result)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
L = list(map(int, input().split()))
tmp = 10 ** 12

for i in range(1,N):
    if abs(sum(L[:i]) - sum(L[i:])) < tmp:
        tmp =  abs(sum(L[:i]) - sum(L[i:]))
print(tmp)

Fixed submission:
N = int(input())
L = list(map(int, input().split()))
tmp = 10 ** 12
after = sum(L)
before = 0
for i in range(N-1):
    before += L[i]
    after -= L[i]
    if abs(before -after) < tmp:
        tmp = abs(before -after)
print(tmp)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
L = list(map(int, input().split()))
res = []
for i in range(N):
    if i%2 == 1:
        res.insert(0,L[i])
    else:
        res.append(L[i])

if N%2 == 1:
    res.reverse()
for i in range(N):
    print(str(res[i]) + ' ', end="")

Fixed submission:
N = int(input())
L = list(map(int, input().split()))
L.reverse()
lim = int(N/2)
if N%2 == 0:
    for i in range(lim):
        print(str(L[2*i]) + ' ', end="")

    L.reverse()
    for i in range(int(N/2)):
        print(str(L[2*i]) + ' ', end="")
else:
    lim += 1
    for i in range(lim):
        print(str(L[2*i]) + ' ', end="")

    L.reverse()
    for i in range(int(N/2)):
        print(str(L[2*i+1]) + ' ', end="")

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
L = list(map(int, input().split()))
res = []
for i in range(N):
    res.append(L[i])
    res.reverse()
for i in range(N):
    print(str(res[i]) + ' ', end="")

Fixed submission:
N = int(input())
L = list(map(int, input().split()))
L.reverse()
lim = int(N/2)
if N%2 == 0:
    for i in range(lim):
        print(str(L[2*i]) + ' ', end="")

    L.reverse()
    for i in range(int(N/2)):
        print(str(L[2*i]) + ' ', end="")
else:
    lim += 1
    for i in range(lim):
        print(str(L[2*i]) + ' ', end="")

    L.reverse()
    for i in range(int(N/2)):
        print(str(L[2*i+1]) + ' ', end="")
Buggy python submission (verdict: Runtime Error):
import math

H, W = map(int, input().split())

if H%3 == 0 or W%3 == 0:
    print(0)
else:
    res = 10 ** 11
    for i in range(1, H):
        a = W*i
        b = math.ceil(W/2) * (H-i)
        m = W//2 * (H-i)

        res = min(res, max(a,b,m)-min(a,b,m))

    for i in range(1, W):
        a = H*i
        b = math.ceil(H/2) * (W-i)
        m = H//2 * (W-i)
        res = min(res, max(a,b,m)-min(a,b,m))

               
print(res)

Fixed submission:
import math

H, W = map(int, input().split())

if H%3 == 0 or W%3 == 0:
    print(0)
else:
    res = 10 ** 11
    for i in range(1, H):
        a = W*i
        b = math.ceil(W/2) * (H-i)
        m = W//2 * (H-i)
        res = min(res, max(a,b,m)-min(a,b,m))

    for i in range(1, W):
        a = H*i
        b = math.ceil(H/2) * (W-i)
        m = H//2 * (W-i)
        res = min(res, max(a,b,m)-min(a,b,m))

    for i in range(1, H-1):
        a = W*i
        b = W * math.ceil((H-i)/2)
        m = W * ((H-i)//2)
        res = min(res, max(a,b,m)-min(a,b,m))

    for i in range(1, W-1):
        a = H*i
        b = H * math.ceil((W-i)/2)
        m = H * ((W-i)//2)
        res = min(res, max(a,b,m)-min(a,b,m))

               
    print(res)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
n = 1

for i in range(1, N+1):
    n = n * i
res = n%(10**9 + 7)

print(res)

Fixed submission:
N = int(input())
n = 1

for i in range(1, N+1):
    n = (n * i)%(10**9+7)

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

V = [i+1 for i in range(N)]
import itertools

ptr = list(itertools.permutations(V, N))

res = 0
for p in ptr:       
    if p[0] == 1:
        now = 1
        flag = [0 for _ in range(N)]
        flag[0] = 1
        for i in range(N-1):
            for j in range(M):
                if A[j][0] == now and A[j][1] == p[i+1]:
                    flag[A[j][1] - 1] += 1
                    now = p[i+1]
                if A[j][1] == now and A[j][0] == p[i+1]:
                    flag[A[j][0] - 1] += 1
                    now = p[i+1]
                    
        tmp = 1         
        for i in range(N):
            if flag[i] != 1:
                tmp = 0
                break
                
        res += tmp
 
print(res)

Fixed submission:
N, M = map(int, input().split())
E = [[0 for i in range(N)] for j in range(N)] #頂点のつながり
for i in range(M):
    a, b = map(int, input().split())
    E[a-1][b-1] = 1
    E[b-1][a-1] = 1

V = [ 0 for i in range(N)] #訪問済みの頂点が1
V[0] = 1 #頂点1は訪問済み

def DPS(now, V):
    res = 0 #全て訪問できた回数
    if 0 not in V:
        return 1
    for i in range(N): 
        if (E[now][i] == 1) and (V[i] == 0): #現在の頂点と隣接してかつ未訪問の頂点
            V[i] = 1
            res = res + DPS(i, V)
            V[i] = 0
    return res

print(DPS(0, V))

Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
E = [[0 for i in range(N)] for j in range(N)] #頂点のつながり
for i in range(M):
    a, b = map(int, input().split())
    E[a-1][b-1] = 1
    E[b-1][a-1] = 1

V = [ 0 for i in range(N)] #訪問済みの頂点が1
V[0] = 1 #頂点1は訪問済み

def DPS(now, V):
    res = 0 #全て訪問できた回数
    if 0 not in V:
        return 1
    for i in range(M):
        if (E[now][i] == 1) and (V[i] == 0): #現在の頂点と隣接してかつ未訪問の頂点
            V[i] = 1
            res = res + DPS(i, V)
            V[i] = 0
    return res

print(DPS(0, V))

Fixed submission:
N, M = map(int, input().split())
E = [[0 for i in range(N)] for j in range(N)] #頂点のつながり
for i in range(M):
    a, b = map(int, input().split())
    E[a-1][b-1] = 1
    E[b-1][a-1] = 1

V = [ 0 for i in range(N)] #訪問済みの頂点が1
V[0] = 1 #頂点1は訪問済み

def DPS(now, V):
    res = 0 #全て訪問できた回数
    if 0 not in V:
        return 1
    for i in range(N): 
        if (E[now][i] == 1) and (V[i] == 0): #現在の頂点と隣接してかつ未訪問の頂点
            V[i] = 1
            res = res + DPS(i, V)
            V[i] = 0
    return res

print(DPS(0, V))