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

Fixed submission:
from sys import stdin
import numpy as np
n = int(stdin.readline().rstrip())
data = [stdin.readline().rstrip().split() for _ in range(n)]
print(len(set(np.array(data).reshape(-1,))))

Buggy submission (verdict: Runtime Error):
import sys
a = []
for l in sys.stdin:
    a.append(int(l))
a = a[1:]
print(len(set(a)))

Buggy submission (verdict: Runtime Error):
n = int(stdin.readline().rstrip())
data = [stdin.readline().rstrip().split() for _ in range(n)]
print(len(set(data))-1)
Problem p02762 (python)

Fixed submission:
# coding: utf-8
# Your code here!
import sys

class Node:
    def __init__(self, id):
        self.id = id
        self.label = None
        self.friends = []
        self.blocks = []

sys.setrecursionlimit(10**9)
N,M,K = [int(i) for i in input().split()]

nodes = [Node(i) for i in range(N)]

for _ in range(M):
    a,b = [int(i) for i in input().split()]
    nodes[a-1].friends.append(b-1)
    nodes[b-1].friends.append(a-1)

for _ in range(K):
    c,d = [int(i) for i in input().split()]
    nodes[c-1].blocks.append(d-1)
    nodes[d-1].blocks.append(c-1)

def dfs(nodes, i, label):
    if nodes[i].label is None:
        nodes[i].label = label
        for j in nodes[i].friends:
            dfs(nodes, j, label)
        
        #for j in nodes[i].blocks:
        #    dfs(nodes, j, label)

label = 0
for i in range(len(nodes)):
    dfs(nodes, i, label)
    label+=1

node_cnts = [0] * (label+1)
for i in range(len(nodes)):
    node_cnts[nodes[i].label] += 1
            
#print(*node_cnts)
result = [0] * len(nodes)
for node in nodes:
    #print(node.id, node.label, node.friends, node.blocks)
    b_cnt = 0
    for b in node.blocks:
        if nodes[b].label == node.label:
            b_cnt += 1
            
    result[node.id] = node_cnts[node.label] - len(node.friends) - b_cnt - 1

print(*result)

Buggy submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!

class Node:
    def __init__(self, id):
        self.id = id
        self.label = None
        self.friends = []
        self.blocks = []

N,M,K = [int(i) for i in input().split()]

nodes = [Node(i) for i in range(N)]

for _ in range(M):
    a,b = [int(i) for i in input().split()]
    nodes[a-1].friends.append(b-1)
    nodes[b-1].friends.append(a-1)

for _ in range(K):
    c,d = [int(i) for i in input().split()]
    nodes[c-1].blocks.append(d-1)
    nodes[d-1].blocks.append(c-1)

def dfs(nodes, i, label):
    if nodes[i].label is None:
        nodes[i].label = label
        for j in nodes[i].friends:
            dfs(nodes, j, label)
        
        #for j in nodes[i].blocks:
        #    dfs(nodes, j, label)
        
label = 0
for i in range(len(nodes)):
    dfs(nodes, i, label)
    label+=1

node_cnts = [0] * (label+1)
for i in range(len(nodes)):
    node_cnts[nodes[i].label] += 1
            
#print(*node_cnts)
result = [0] * len(nodes)
for node in nodes:
    #print(node.id, node.label, node.friends, node.blocks)
    b_cnt = 0
    for b in node.blocks:
        if nodes[b].label == node.label:
            b_cnt += 1
            
    result[node.id] = node_cnts[node.label] - len(node.friends) - b_cnt - 1

print(*result)
Problem p02699 (python)

Fixed submission:
S, W = map(int,input().split())
print('unsafe'if W >= S else 'safe')

Buggy submission (verdict: Runtime Error):
N = int(input())
S = [str(input()) for i in range(N)]
print(len(set(S)))
Problem p02699 (python)

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

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

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

Buggy submission (verdict: Runtime Error):
S,W = map(int, input().split())
if S>W:
  print("safe")
else:
  print("unsafe)
Problem p02699 (python)

Fixed submission:
S,W = map(int, input().split())
if W >= S:
  print('unsafe')
else:
  print('safe')

Buggy submission (verdict: Runtime Error):
S W
if W>=(S/2):
  print('safe')
else:
  print('unsafe')
Problem p02701 (python)

Fixed submission:
import sys
stdin = sys.stdin

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))


x = ni()
s= [[[] for j in range(26)] for i in range(26)]
sum=0
for i in range(x):
    si=ns()
    sn1=ord(si[0:1])-97
    if len(si)==1:
        sn2=0
    else:
        sn2 = ord(si[1:2]) - 97
    if si not in s[sn1][sn2]:
       s[sn1][sn2].append(si)
for s1 in s:
    for s2 in s1:
        sum+=len(s2)
print(sum)

Buggy submission (verdict: Runtime Error):
import sys
stdin = sys.stdin

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))


x = ni()
s= [[[] for j in range(26)] for i in range(26)]
sum=0
for i in range(x):
    si=ns()
    sn1=ord(si[0:1])-97
    sn2=ord(si[1:2])-97
    if si not in s[sn1][sn2]:
       s[sn1][sn2].append(si)
for s1 in s:
    for s2 in s1:
        sum+=len(s2)
print(sum)

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

stdin = sys.stdin

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))


x = ni()
s=[[],[],[],[],[],[],[],[],[],[]]
sum=0
for i in range(x):
    si=ns()
    sn=len(si)
    if si not in s[sn]:
        s[sn].append(si)
for s1 in s:
    sum+=len(s1)
print(sum)
Problem p02754 (python)

Fixed submission:
a=input().split()
N,A,B=int(a[0]),int(a[1]),int(a[2])
b=int(N/(A+B))
ans=int(A*b)
if(N-b*(A+B)<=A):
    ans=ans+N-b*(A+B)
else:
    ans+=A
print(int(ans))

Buggy submission (verdict: Runtime Error):
a=input().split()
N,A,B=int(a[0]),int(a[1]),int(a[2])
a_str='b'*A
b_str='r'*B
st=a_str+b_str
num=A+B
sum_str=''
sum_num=0

sum_str=st*N
b=sum_str[0:N]
print(b.count('b'))

Buggy submission (verdict: Runtime Error):
a=input().split()
N,A,B=int(a[0]),int(a[1]),int(a[2])
a_str='b'*A
b_str='r'*B
st=a_str+b_str
num=A+B
sum_str=''
sum_num=0

while sum_num<=N:
    sum_str+=st
    sum_num+=num
b=sum_str[0:N]
print(b.count('b'))

Buggy submission (verdict: Runtime Error):
a=input().split()
N,A,B=int(a[0]),int(a[1]),int(a[2])
st_a='b'*A
st_b='r'*B
d=st_a+st_b
e=A+B
if(N==0):
  print(0)
elif(A==0):
  print(0)
elif(B==0):
  print(N)
elif(e==0):
  print(0)
else:
  num=int(N/e)+2
  b=d*num
  c=b[0:N]
  print(c.count('b'))

Buggy submission (verdict: Runtime Error):
a=input().split()
N,A,B=int(a[0]),int(a[1]),int(a[2])
st_a='b'*A
st_b='r'*B
d=st_a+st_b
e=A+B
if(e==0):
  print(0)
else:
  num=int(N/e)+2
  b=d*num
  c=b[0:N]
  print(c.count('b'))

Buggy submission (verdict: Runtime Error):
a=input().split()
N,A,B=int(a[0]),int(a[1]),int(a[2])
st_a='b'*A
st_b='r'*B
d=st_a+st_b
e=A+B
if(e==0):
  print(0)
else:
  num=int(N/e)+2
  b=d*num
  print(b)
  c=b[0:N]
  print(c)
  print(c.count('b'))

Buggy submission (verdict: Runtime Error):
a=input().split()
N,A,B=int(a[0]),int(a[1]),int(a[2])
st_a='b'*A
st_b='r'*B
d=st_a+st_b
e=A+B
num=int(N/e)+1
b=d*num
c=b[0:N]
print(c.count('b'))

Buggy submission (verdict: Runtime Error):
a=input().split()
N,A,B=int(a[0]),int(a[1]),int(a[2])
st_a='b'*A
st_b='r'*B

sum=0
b=''
d=st_a+st_b
e=A+B
while sum<=N:
  sum+=e
  b+=d
c=b[0:N]
print(c.count('b'))

Buggy submission (verdict: Runtime Error):
a=input().split()
N,A,B=int(a[0]),int(a[1]),int(a[2])
st_a='b'*A
st_b='r'*B

sum=0
b=''
while sum<=N:
  b+=st_a
  sum+=A
  if(sum>=N):
    break
  b+=st_b
  sum+=B
c=b[0:N]
print(c.count('b'))
Problem p02847 (python)

Fixed submission:
S=input()
list=["SUN","MON","TUE","WED","THU","FRI","SAT"]
print(7-list.index(S))

Buggy submission (verdict: Runtime Error):
S=input()
list=[SUN,MON,TUE,WED,THU,FRI,SAT]
print(7-list.index(S))
Problem p02915 (python)

Fixed submission:
print(int(input())**3)

Buggy submission (verdict: Runtime Error):
print(int((input())**3))
Problem p02951 (python)

Fixed submission:
a,b,c=[int(i)for i in input().split()]
if c+b-a>0:
  print(c+b-a)
else:
  print("0")

Buggy submission (verdict: Runtime Error):
a,b,c=[int(i)for i in input().split()]
if c+b-a>0:
  print(c+b-a)
else:
  prnit("0")
Problem p03041 (python)

Fixed submission:
n,k = map(int, input().split())
s = input()
 
t = s[:k-1]+str.lower(s[k-1])+s[k:]
print(t)

Buggy submission (verdict: Runtime Error):
n,k=[int(i)for i in input().split()]
s=str(input())
S=list(s)
S[k-1]=S[k-1].lower
A=''.join(S)
print(A)

Buggy submission (verdict: Runtime Error):
n,k=[int(i)for i in input().split()]
s=str(input())
print(s.replace(s[k-1],s[k-1].lower))

Buggy submission (verdict: Runtime Error):
n,k=[int(i)for i in input().split()]
s=str(input())
print(s.replace(s[k],s[k].lower))
Problem p03307 (python)

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

Buggy submission (verdict: Runtime Error):
N=int(input())
if N%2==0:
  prnit(N)
else:
  print(2*N)
Problem p03327 (python)

Fixed submission:
n=int(input())
if n>=1000:
  print('ABD')
else:
  print('ABC')

Buggy submission (verdict: Runtime Error):
n=input()
if n>=1000:
  print('ABD')
else:
  print('ABC')
Problem p03803 (python)

Fixed submission:
a,b=[str(i) for i in input().split()]
list=["2","3","4","5","6","7","8","9","10","11","12","13","1"]
A=list.index(a)
B=list.index(b)
if A>B:
  print('Alice')
elif A==B:
  print('Draw')
else:
  print('Bob')

Buggy submission (verdict: Runtime Error):
a,b=[int(i) for i in input().split()]
list=["2","3","4","5","6","7","8","9","10","11","12","13","1"]
A=list.index(a)
B=list.index(b)
if A>B:
  print('Alice')
elif A==B:
  print('Draw')
else:
  print('Bob'
Problem p02711 (python)

Fixed submission:
a = input()
a = int(a)
if a%10==7:
  print("Yes")
elif( a%100 )//10==7:
  print("Yes")
elif( a//100 )==7:
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
a = input()
if a%10==7:
  print("Yes")
elif( a%100 )//10==7:
  print("Yes")
elif( a//100 )==7:
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
a = input()
if a%10==7:
  print(True)
elif( a%100 )//10==7:
  print(True)
elif( a//100 )==7:
  print(True)
else:
  print(False)

Buggy submission (verdict: Runtime Error):
a = input()
if a%10==7:
  print(True)
elif( a%100 )//10==7:
  print(True)
elif( a//100 )==7:
  print(True)
else:
  print(False)
Problem p02771 (python)

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

if a == b == c or a != b != c != a: print("No")
else: print("Yes")

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

if a == b == c || a != b != c: print("No")
else: print("Yes")
Problem p03104 (python)

Fixed submission:
import math

def f(n):
  s = ""
  if n <= 0:
    return 0
  for i in reversed(range(int(math.log2(n))+1)):
    if i == 0:
      s += "1" if ((n-1)//2)%2 == 0 else "0"
    else:
      s += "1" if (n//(2**i))%2 + (n+1)%2 == 2 else "0"
  return int(s,2)

a,b = map(int,input().split())
print( f(a-1) ^ f(b) )

Buggy submission (verdict: Runtime Error):
import math

def f(n):
  s = ""
  if n == 0:
    return 0
  for i in reversed(range(int(math.log2(n))+1)):
    if i == 0:
      s += "1" if ((n-1)//2)%2 == 0 else "0"
    else:
      s += "1" if (n//(2**i))%2 + (n+1)%2 == 2 else "0"
  return int(s,2)

a,b = map(int,input().split())
print( f(a-1) ^ f(b) )
Problem p02699 (python)

Fixed submission:
def solve():
    N, M = map(int, input().split())

    return 'safe' if N > M else 'unsafe'

print(solve())

Buggy submission (verdict: Runtime Error):
def solve():
    a, b, c, d = map(int, input().split())
    
    x = c / b
    y = a / d


    if c % b == 0 and x - y <= 1:
        return 'Yes'
        

    return 'Yes' if x < y else 'No'

print(solve())
Problem p02735 (python)

Fixed submission:
from collections import deque

def solve():
    H, W = map(int, input().split())
    A = [list(input()) for _ in range(H)]
    INF = 10 ** 9
    d = [[INF] * W for i in range(H)]
    d[0][0] = 1 if A[0][0] == '#' else 0

    prepare = 1 if A[0][0] == '#' else 0
    q = deque([(prepare, 0, 0)])
    while q:
        c, x, y = q.popleft()
        for a, b in [(1,0), (0,1)]:
            nx, ny = x+a, y+b
            if nx >= W or ny >= H: continue
            k = 1 if A[y][x] != A[ny][nx] else 0
            if c+k >= d[ny][nx]: continue
            d[ny][nx] = c+k
            q.append((c+k, nx, ny))

    return (d[H-1][W-1]+1)//2

print(solve())

Buggy submission (verdict: Runtime Error):
from collections import deque

def solve():
    H, W = map(int, input().split())
    A = [list(input()) for _ in range(H)]
    INF = 10 ** 9
    d = [[INF] * W for i in range(H)]
    d[0][0] = 1 if A[0][0] == '#' else 0

    def bfs():
        prepare = 1 if A[0][0] == '#' else 0
        q = deque([(0, 0, prepare)])
        while q:
            w, h, c = q.popleft()
            for a, b in [(1,0), (0,1)]:
                w_n, h_n = w+a, h+b
                if w_n >= W or h_n >= H: continue
                k = 1 if A[w_n][h_n] == '#' else 0
                if c+k >= d[h_n][w_n]: continue
                d[h_n][w_n] = c+k
                q.append((w_n, h_n, c+k))
    bfs()
    return d[H-1][W-1]

print(solve())

Buggy submission (verdict: Runtime Error):
from collections import deque

def solve():
    H, W = map(int, input().split())
    A = [list(input()) for _ in range(H)]
    INF = 10 ** 9
    d = [[INF] * W for i in range(H)]
    d[0][0] = 1 if A[0][0] == '#' else 0

    def bfs():
        prepare = 1 if A[0][0] == '#' else 0
        q = deque([(0, 0, prepare)])
        while q:
            w, h, c = q.popleft()
            for a, b in [(1,0), (0,1)]:
                w_n, h_n = w+a, h+b
                if w_n >= W or h_n >= H: continue
                k = 1 if A[w_n][h_n] == '#' else 0
                if c+k >= d[h_n][w_n]: continue
                d[h_n][w_n] = c+k
                q.append((w_n, h_n, c+k))
    bfs()
    return d[W-1][H-1]

print(solve())

Buggy submission (verdict: Runtime Error):
from collections import deque

def solve():
    H, W = map(int, input().split())
    A = [list(input()) for _ in range(H)]
    INF = 10 ** 9
    d = [[INF] * W for i in range(H)]
    d[0][0] = 1 if A[0][0] == '#' else 0

    def bfs():
        prepare = 1 if A[0][0] == '#' else 0
        q = deque([(0, 0, prepare)])
        while q:
            w, h, c = q.popleft()
            for a, b in [(1,0), (0,1)]:
                w_n, h_n = w+a, h+b
                if w_n >= W or h_n >= H: continue
                k = 1 if A[w_n][h_n] == '#' else 0
                if c+k >= d[h_n][w_n]: continue
                d[h_n][w_n] = c+k
                q.append((w_n, h_n, c+k))
    bfs()
    return d[-1][-1]

print(solve())
Problem p02754 (python)

Fixed submission:
def solve():
    N, A, B = map(int, input().split())

    r = N // (A+B)
    m = N % (A+B)
    
    rest = 0
    if A >= m:
        rest = m
    else:
        rest = A

    ans = A*r + rest

    return ans

print(solve())

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

    if A + B == 0:
        return 0

    s = 'b'*A + 'r'*B
    r = N // (A+B)
    m = N % (A+B)
    
    rest = 0
    if A >= m:
        rest = m
    else:
        rest = A

    ans = A*r + rest
    
    return ans

print(solve())

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

    s = 'b'*A + 'r'*B
    r = N // (A+B)
    m = N % (A+B)
    
    rest = 0
    if A >= m:
        rest = m
    else:
        rest = A

    ans = A*r + rest
    
    return ans

print(solve())
Problem p02766 (python)

Fixed submission:
def Base_10_to_n(X, n):
    if (int(X/n)):
        return Base_10_to_n(int(X/n), n)+str(X%n)
    return str(X%n)

def solve():
    N, M = map(int, input().split())
    n = Base_10_to_n(N, M)
    return len(n)

print(solve())

Buggy submission (verdict: Runtime Error):
def ten_to_n(X, n):
    i = int(X / n)
    s = str(X % n)
    if (i):
        return Base_10_to_n(i, n) + s
    return s

def solve():
    N, M = map(int, input().split())
    n = Base_10_to_n(N, M)
    return len(n)
 
print(solve())
Problem p02773 (python)

Fixed submission:
def solve():
    import itertools
    from operator import itemgetter

    N = int(input())
    B = [input() for _ in range(N)]
    B.sort()

    l = []
    gr = itertools.groupby(B)
    max_key = 0
    for key, group in gr:
        length = len(list(group))
        l.append((length, key))
        if length > max_key:
            max_key = length

    l.sort(key = itemgetter(0), reverse=True)

    key = l[0][0]
    for k, v in l:
        if key == k:
            print(v)
        else:
            break

solve()

Buggy submission (verdict: Runtime Error):
N = int(input())
A = [input() for _ in range(N)]
d = defaultdict(int)
for a in A:
    d[a] += 1

li = sorted(d.items())
l = sorted(li, key = itemgetter(0), reverse=True)
max_key = l[0][0]

for k, v in li:
    if k == max_key:
        print(k)
    else:
        continue

Buggy submission (verdict: Runtime Error):
N = int(input())
A = [input() for _ in range(N)]
d = defaultdict(int)
for a in A:
  d[a] += 1

  li = sorted(d.items())
  l = sorted(li, key = itemgetter(0), reverse=True)
  max_key = l[0][0]

  for k, v in li:
    if k == max_key:
      print(k)
      else:
        continue
Problem p02879 (python)

Fixed submission:
def solve():
    N, M = map(int, input().split())
    return N*M if max(N, M) < 10 else -1

print(solve())

Buggy submission (verdict: Runtime Error):
n = int(input())
for i in range(1, 10)
    for j in range(1, 10)
		if n == i * j:
			print("Yes")
			break
 
print("No")
Problem p02880 (python)

Fixed submission:
n = int(input())
ans = ('No')
for i in range(1,10):
    for j in range(1,10):
        if i * j == n:
            ans = ('Yes')
            break
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
for i in range(1, 10)
  for j in range(1, 10)
    if n == i * j:
      print("Yes")
      break
 
print("No")

Buggy submission (verdict: Runtime Error):
n = int(input())
for i in range(1, 10)
    for j in range(1, 10)
		if n == i * j:
			print("Yes")
			break
 
print("No")

Buggy submission (verdict: Runtime Error):
n = int(input())
 
for i in range(1, 9)
  for j in range(1, 9)
    if n == i * j:
      print("Yes")
      break
 
print("No")

Buggy submission (verdict: Runtime Error):
n = int(input())
 
for i in range(1, 9)
	for j in range(1, 9)
		if n == i * j:
			print("Yes")
			break
 
print("No")

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

for i in range(1, 9)
	for j in range(1, 9)
    	if n == i * j:
			print("Yes")
			break

print("No")

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

for i in range(1, 9)
	for j in range(1, 9)
    	if n == i * j:
        	print("Yes")
            break

print("No")

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

for i in range(1, 9)
	for j in range(1, 9)
    	if n == i * j:
        	print("Yes")
            exit

print("No")
Problem p03013 (python)

Fixed submission:
MOD = 10 ** 9 + 7

def solve():
    N, M = map(int, input().split())
    A = [int(input()) for _ in range(M)]
    
    if N == 1 and M == 0:
        return 1
    elif N == 1 and M == 1 and A[0] == 0:
        return 0

    l = [1 for _ in range(N+1)]
    for a in A:
        l[a] = 0
        
    dp = [0 for i in range(N+1)]
    dp[1] = 0 if 1 in A else 1
    dp[2] = 0 if 2 in A else dp[1] + 1

    for i in range(3, N+1):
        if l[i] == 0:
            dp[i] = 0
        else:
            dp[i] = dp[i-1] + dp[i-2]
            dp[i] %= MOD

    return dp[N] % MOD

print(solve())

Buggy submission (verdict: Runtime Error):
MOD = 10 ** 9 + 7

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

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

    dp = [0] * (N+1)
    dp[1] = 0 if 1 in A else 1
    dp[2] = 0 if 2 in A else dp[1] + 1

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

    return dp[N] % MOD

print(solve())
Problem p03775 (python)

Fixed submission:
from itertools import combinations

N = int(input())

def int_len(n):
    return len(str(n))

a = i = 1
list = []
while a <= N:
    if N % i == 0:
        b = N // i
        c = N // b
    list.append(max(int_len(b), int_len(b)))
    
    i += 1
    a = i ** 2

ans = min(list)
print(ans)

Buggy submission (verdict: Runtime Error):
from itertools import combinations

N = int(input())

def factorize(n):
    b = 2
    fct = []
    while b * b <= n:
        while n % b == 0:
            n //= b
            fct.append(b)
        b = b + 1
    if n > 1:
        fct.append(n)
    return fct

A = factorize(N)

list = []
c = 1
for a in A:
    c *= a
    b = N // c
    maxi = max((len(str(b)), len(str(c))))
    list.append(maxi)

ans = min(list)

print(ans)
Problem p03805 (python)

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

visited = [False] * N
visited[0] = True
d = {}
for a, b in A:
    d.setdefault(b-1, []).append(a-1)
    d.setdefault(a-1, []).append(b-1)

l = sorted(d.items())

def dfs(v, seen):
    if False not in seen: return 1
    
    c = 0
    for i in d[v]:
        if (seen[i]): continue
        seen[i] = True
        c += dfs(i, seen)
        seen[i] = False
    return c
    
print(dfs(0, visited))

Buggy submission (verdict: Runtime Error):
from collections import deque

def dfs(v, P, visited, N):
    if len(list(filter(lambda x: x == True, visited))) == N:
        return 1

    c = 0
    for i in P[v]:
        if visited[i]: continue
        visited[i] = True
        c += dfs(i, P, visited, N)
        visited[i] = False

    return c

def resolve():
    N, M = map(int, input().split())
    P = [[] for _ in range(M)]
    for i in range(N):
        pp, ss = map(int, input().split())
        P[pp-1].append(ss-1)
        P[ss-1].append(pp-1)

    visited = [False] * N
    visited[0] = True

    print(dfs(0, P, visited, N))

resolve()

Buggy submission (verdict: Runtime Error):
from collections import deque

def dfs(v, P, visited, N):
    if len(list(filter(lambda x: x == True, visited))) == N:
        return 1

    c = 0
    for i in P[v]:
        if visited[i]: continue
        visited[i] = True
        c += dfs(i, P, visited, N)
        visited[i] = False

    return c

def resolve():
    N, M = map(int, input().split())
    P = [[] for _ in range(N)]
    for i in range(N):
        pp, ss = map(int, input().split())
        P[pp-1].append(ss-1)
        P[ss-1].append(pp-1)

    visited = [False] * N
    visited[0] = True

    print(dfs(0, P, visited, N))

resolve()

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

visited = [False] * N
visited[0] = True
d = {}
for a, b in A:
    d.setdefault(b-1, []).append(a-1)
    d.setdefault(a-1, []).append(b-1)

l = sorted(d.items())

def dfs(v, seen):
    if False not in seen: return 1
    
    c = 0
    for i in d[v]:
        if (seen[i]): continue
        seen[i] = True
        c += dfs(i, seen)
        seen[i] = False
    return c
    
print(dfs(0, visited))

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

visited = [False] * N
visited[0] = True
d = {}
for a, b in A:
    d.setdefault(a, []).append(b)
    d.setdefault(b, []).append(a)

l = sorted(d.items())

# print(d)
def dfs(v, c):
    if visited[v-1]: return 0
    visited[v-1] = True
    if False not in visited:
        c += 1
    
    # print(visited, False not in visited, c)
    
    # print('vertex', v)
    
    for next_v in d[v]:
        c += dfs(next_v, c)
    
    return c

c = 0
ans = 0
for i in l[0][1]:
    ans += dfs(i, c)
    
print(ans)