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

Fixed submission:
import sys
input = sys.stdin.readline
N,M = map(int,input().split())
lst=[int(input()) for i in range(M)]
t=0
ans=[0]*(N+1)
ans[0]=1
for j in range(N):
 if M!=0:
  if lst[t]==j+1:
   ans[j+1]=0
   t+=1
   t=min(M-1,t)
  else:
   ans[j+1]+=ans[j]
   if j!=0:
    ans[j+1]+=ans[j-1]
   ans[j+1]%=(10**9+7)
 else:
  ans[j+1]+=ans[j]
  if j!=0:
   ans[j+1]+=ans[j-1]
  ans[j+1]%=(10**9+7)
print(ans[N])

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
N,M = map(int,input().split())
lst=[int(input()) for i in range(M)]
t=0
ans=[0]*(N+1)
ans[0]=1
for j in range(N):
 if lst[t]==j+1:
  ans[j+1]=0
  t+=1
  t=min(M-1,t)
 else:
  ans[j+1]+=ans[j]
  if j!=0:
   ans[j+1]+=ans[j-1]
  ans[j+1]%=(10**9+7)
print(ans[N])

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
N,M = map(int,input().split())
lst=[int(input()) for i in range(M)]
t=0
ans=[0]*(N+1)
ans[0]=1
for j in range(N):
 if lst[t]==j+1:
  ans[j+1]=0
  t+=1
  t=min(M-1,t)
 else:
  ans[j+1]+=ans[j]
  if j!=0:
   ans[j+1]+=ans[j-1]
  ans[j+1]%=(10**9+7)
print(ans[N])
Problem p03015 (python)

Fixed submission:
def powmod(x, n,mod):
  if n == 0:
   return 1
  K = 1
  while n > 1:
   if n % 2 != 0:
    K = K * x%mod
    x = x ** 2%mod
    n = (n - 1) // 2
   else:
    x = x ** 2%mod
    n = n // 2%mod

  return K * x # 指数を割り続け n が 1 に至ったら終了
L=input()
S=len(L)-1
if S==0:
 print(3)
else:
 ans=1
 ct=0
 for i in range(S+1):
  if int(L[i])==1:
   ans+=((powmod(3, S-i,10**9+7)+1)*powmod(2, ct,10**9+7))%(10**9+7)
   ans%=(10**9+7)
   ct+=1
 print(ans)

Buggy submission (verdict: Runtime Error):
def powmod(x, n,mod):
  if n == 0:
   return 1
  K = 1
  while n > 1:
   if n % 2 != 0:
    K = K * x%mod
    x = x ** 2%mod
    n = (n - 1) // 2
   else:
    x = x ** 2%mod
    n = n // 2%mod

  return K * x # 指数を割り続け n が 1 に至ったら終了
L=input()
S=len(L)-1
if S==0:
 print(3)
else:
 ans=1
 for i in range(S+1):
  ans+=int(L[i])*((powmod(3, S-i,10**9+7)+1)*(powmod(2, i,10**9+7)))%(10**9+7)
  ans%=(10**9+7)
print(ans)
Problem p03137 (python)

Fixed submission:
import numpy as np
n, m = list(map(int, input().split()))
xs = list(map(int, input().split()))

if n >= m:
    print(0)
else:
    xs.sort()
    diffs = [xs[i] - xs[i-1] for i in range(1, m)]
    if n == 1:
        ans = sum(diffs)
    else:
        indxs = list(np.array(diffs).argsort()[::-1][:n-1])
        indxs.sort()
        ans = sum(diffs[0:indxs[0]])
        if indxs[-1]+1 < len(diffs):
            ans += sum(diffs[indxs[-1]+1:])
        for i in range(len(indxs)-1):
            ans += sum(diffs[indxs[i]+1:indxs[i+1]])
    print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np
n, m = list(map(int, input().split()))
xs = list(map(int, input().split()))

if n >= m:
    print(0)
else:
    xs.sort()
    diffs = [xs[i] - xs[i-1] for i in range(1, m)]
    indxs = list(np.array(diffs).argsort()[::-1][:n-1])
    indxs.sort()
    ans = sum(diffs[0:indxs[0]])
    if indxs[-1]+1 < len(diffs):
        ans += sum(diffs[indxs[-1]+1:])
    for i in range(len(indxs)-1):
        ans += sum(diffs[indxs[i]+1:indxs[i+1]])
    print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np
n, m = list(map(int, input().split()))
xs = list(map(int, input().split()))

if n > m:
    print(0)
else:
    xs.sort()
    diffs = [xs[i] - xs[i-1] for i in range(1, m)]
    indxs = list(np.array(diffs).argsort()[::-1][:n-1])
    indxs.sort()
    ans = sum(diffs[0:indxs[0]])
    if indxs[-1]+1 < len(diffs):
        ans += sum(diffs[indxs[-1]+1:])
    for i in range(len(indxs)-1):
        ans += sum(diffs[indxs[i]+1:indxs[i+1]])
    print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np
n, m = list(map(int, input().split()))
xs = list(map(int, input().split()))

if n > m:
    print(0)
else:
    xs.sort()
    diffs = [xs[i] - xs[i-1] for i in range(1, m)]
    indxs = list(np.array(diffs).argsort()[::-1][:n-1])
    indxs.sort()
    ans = sum(diffs[0:indxs[0]]) + sum(diffs[indxs[-1]+1:])
    for i in range(len(indxs)-1):
        ans += sum(diffs[indxs[i]+1:indxs[i+1]])
    print(ans)
Problem p03127 (python)

Fixed submission:
import sys
import fractions

sys.setrecursionlimit(10**9)
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def LIST(): return [int(x) for x in input().split()]
MOD = 10**9 + 7

N = INT()

A = LIST()

def gcd_all(n):
    if len(n) == 1:
        return n[0]

    tail = n.pop(-1)
    return fractions.gcd(tail, gcd_all(n))

print(gcd_all(A))

Buggy submission (verdict: Runtime Error):
import sys, fractions
sys.setrecursionlimit(5 * 10**5)
input = sys.stdin.readline

N = int(input())

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

gcds = []

for i in range(N - 2):
    for j in range(i + 1, N - 1):
        gcds.append(fractions.gcd(A[i], A[j]))

print(min(gcds))

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

sys.setrecursionlimit(10**5+1)
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def LIST(): return [int(x) for x in input().split()]
MOD = 10**9 + 7

N = INT()

A = LIST()

def gcd_all(n):
    if len(n) == 1:
        return n[0]

    tail = n.pop(-1)
    return fractions.gcd(tail, gcd_all(n))

print(gcd_all(A))

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

sys.setrecursionlimit(10**5)
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def LIST(): return [int(x) for x in input().split()]
MOD = 10**9 + 7

N = INT()

A = LIST()

def gcd_all(n):
    if len(n) == 1:
        return n[0]

    tail = n.pop(-1)
    return fractions.gcd(tail, gcd_all(n))

print(gcd_all(A))

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

sys.setrecursionlimit(1000)
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def LIST(): return [int(x) for x in input().split()]
MOD = 10**9 + 7

N = INT()

A = LIST()

def gcd_all(n):
    if len(n) == 1:
        return n[0]

    tail = n.pop(-1)
    return fractions.gcd(tail, gcd_all(n))

print(gcd_all(A))
Problem p02836 (python)

Fixed submission:
s = input()
res = 0
for i in range(len(s)//2):
  if s[i] != s[-(i+1)]:
    res += 1
print(res)

Buggy submission (verdict: Runtime Error):
  s = input()
  res = 0
  for i in range(len(s)//2):
    if s[i] != s[-(i+1)]:
      res += 1
  print(res)
Problem p02859 (python)

Fixed submission:
r = int(input())
print(pow(r, 2))

Buggy submission (verdict: Runtime Error):
r = input()
print(pow(r,2))
Problem p02873 (python)

Fixed submission:
s = input()
ans = [0]*(len(s)+1)

for i in range(len(s)):
    if s[i] == '<':
        ans[i+1] = ans[i] + 1
for i in range(len(s)-1,-1,-1):
    if s[i] == '>':
        ans[i] = max(ans[i], ans[i+1] + 1)
print(sum(ans))

Buggy submission (verdict: Runtime Error):
s = input()
ans = [0]*(len(s)+1)

for i in range(len(s):
    if s[i] == '<':
        ans[i+1] = ans[i] + 1
for i in range(len(s)-1,-1,-1):
    if s[i] == '>':
        ans[i] = max(ans[i], ans[i+1] + 1)
print(sum(ans))
Problem p02948 (python)

Fixed submission:
def main():
    n,m = map(int,input().split())
    job =[[] for _ in range(m)]
    for i in range(n):
        a,b=map(int,input().split())
        if a-1 < m:
            job[a-1].append(-b) # b:asc, -b:desc
    
    res = 0
    q = []
    from heapq import heappop, heappush
    for i in range(m):
        for j in job[i]:
            heappush(q, j)
        if len(q) > 0:
            res += heappop(q) * -1 # -b -> b
    print(res)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    n,m = map(int,input().split())
    job =[[] for _ in range(m)]
    for i in range(n):
        a,b=map(int,input().split())
        if a-1 < m:
            job[a-1].append(-B) # b:asc, -b:desc
    
    res = 0
    q = 0
    from heapq import heappop, heappush
    for i in range(m):
        for j in job[i]:
            heappush(q, j)
        if len(q) < 0:
            res += heappop(q) * -1 # -r -> r
    print(res)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    n,m = map(int,input().split())
    job =[[] for _ in range(m)]
    for i in range(n):
        a,b=map(int,input().split())
        if a-1 < m:
            job[d-1].append(-r) # r:asc, -r:desc
    
    res = 0
    q = 0
    from heapq import heappop, heappush
    for i in range(m):
        for j in job[i]:
            heappush(q, j)
        if len(q) < 0:
            res += heappop(q) * -1 # -r -> r
    print(res)

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

Fixed submission:
s = input()
if len(set(s)) != 2:
  print("No")
else:
  print("Yes")

Buggy submission (verdict: Runtime Error):
s = list(input())
if len(set(a)) != 2:
  print("No")
else:
  print("Yes")
Problem p03041 (python)

Fixed submission:
n, k = map(int, input().split())
s = input()
l = list(s)
l[k-1] = str.lower(l[k-1])
print("".join(l))

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())
s = input()
l = list(input())
l[k] = str.lower(l[k])
print("".join(l))
Problem p03127 (python)

Fixed submission:
import functools, fractions
n=input()
a=list(map(int,input().split()))
print(functools.reduce(fractions.gcd,a))

Buggy submission (verdict: Runtime Error):
def ngcd(lista):
    from math import gcd
    res = lista[0]
    for i in range(1,len(lista)):
        if res != 1:
            res = gcd(lista[i],res)
    return res

def main():
    n = int(input())
    a = list(map(int,input().split()))
    print(ngcd(a))

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

Fixed submission:
N,i = map(int, input().split())
print(N - i + 1)

Buggy submission (verdict: Runtime Error):
N = int(input())
i = int(input())
print(N - i + 1)
Problem p03329 (python)

Fixed submission:
n = int(input())
dp = [i for i in range(n + 1)]

for i in range(1, n + 1):
  for j in range(1, i + 1):
    if i >= 9**j:
      dp[i] = min(dp[i], dp[i - 9**j] + 1)
    else:
      break
  for k in range(1, i + 1):
    if i >= 6**k:
      dp[i] = min(dp[i], dp[i - 6**k] + 1)
    else:
      break

print(dp[-1])

Buggy submission (verdict: Runtime Error):
N = int(input())
dp = [0 for _ in range(N+1)]

def dfs(n):
  if n <= 0:
    return 0
  elif dp[n] > 0:
    return dp[n]
  dp[n] = dfs(n - 1) + 1
  x = 6
  while x <= n:
    dp[n] = min(dp[n],dfs(n - x) + 1)
    x *= x
  x = 9
  while x <= n:
    dp[n] = min(dp[n], dfs(n - x) + 1)
    x *= x
  return dp[n]

print(dfs(N))
Problem p02707 (python)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
c = [0] * n

for x in a:
  c[x-1] += 1
for x in c:
  print(x)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
c = [] * n
for x in a:
  c[x-1] += 1
for x in c:
  print(x)
Problem p02881 (python)

Fixed submission:
n = int(input())

ans = 1000000000000

a = 1
while a * a <= n:
  if n % a != 0:
    a += 1
    continue
  b = n // a
  ans = min(ans, a + b - 2)
  a += 1

print(ans)

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

ans = 1000000000000

a = 1
while a * a <= n:
	if n % a != 0:
      continue
    b = n % a
    ans = min(ans, a + b - 2)
    a += 1

print(ans)
Problem p02627 (python)

Fixed submission:
m = input()
x = ord(m)
if x >= 97 and x <= 122:
    print("a")
else:
    print("A")

Buggy submission (verdict: Runtime Error):
m = input()
x=ord(m)
if x >= 97 and x <= 122:
    print("a")
else:
    print("A"
Problem p03135 (python)

Fixed submission:
x,y =map(int,input().split())
print(x/y)

Buggy submission (verdict: Runtime Error):
x,y =map(int,input().split())
print(x/t)
Problem p03104 (python)

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

def XOR(A):
    # 0からAまでの排他的論理和を求める
    if A%4 == 0:
        return A
    elif A%4 == 2:
        return A+1
    elif A%4 == 1:
        return 1
    else:
        return 0

fA = XOR(A-1)
fB = XOR(B)
print(fB^fA)

Buggy submission (verdict: Runtime Error):
import numpy as np
A, B = map(int, input().split())

# ans = A
# for i in range(A+1,B+1,1):
#     ans = ans^i
# print(ans)
# counter = 0

# list = np.zeros(50)
# for i in range(A,B+1,1):
#     list += np.array(list(map(int, str(i))).reverse())
# for i in range(len(list)):
#     list[i] = list[i]%2
# list.reverse()
# print(list)

l = [0]*100
s = ''
for i in range(A,B+1,1):
    bi = bin(i)[2:]
    # print(bi)
    for j in range(1,len(bi)+1):
        if bi[-j] == '1':
            l[j] = (l[j]+1)%2

for i in range(len(l)):
    s = s + str(l[-i])
print(int(s, 2))
Problem p03135 (python)

Fixed submission:
string = input().replace(' ','/')
print(eval(string))

Buggy submission (verdict: Runtime Error):
string = input().replace('','/')
print(eval(string))
Problem p02711 (python)

Fixed submission:
import sys
K=str(input())
K=list(K) #いらないかも
K=[int(i) for i in K]

for i in K:
    if i==7:
        print("Yes")
        sys.exit()
print("No")

Buggy submission (verdict: Runtime Error):
from collections import Counter
N=int(input())
S=[0]*5000
S=list(input())

S_count=Counter(S)
r=S_count["R"]
g=S_count["G"]
b=S_count["B"]

ans=0

for i in range(N-2):
    for j in range(1,N):
        if i+2*j>=N:
            break
        if S[i]!=S[i+j] and S[i+j]!=S[i+2*j] and S[i]!=S[i+2*j]:
            ans+=1

print(r*g*b-ans)
Problem p02723 (python)

Fixed submission:
S=list(input())

if S[2]==S[3] and S[4]==S[5]:
    print("Yes")
else:
    print("No")

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


def count(k):
    count=0
    for i in range(1,N):
        for j in range(i+1,N+1):
            if min(abs(j-i),abs(X-i)+abs(Y-j)+1)==k:
                count+=1
                if count >= 4:
                    break
    return count

for k in range(1,N):
    print(count(k))
Problem p02729 (python)

Fixed submission:
import math
N,M=map(int,input().split())

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

x=0
y=0
if N>=2:
    x=combinations_count(N, 2)
if M>=2:
    y=combinations_count(M, 2)

print(x+y)

Buggy submission (verdict: Runtime Error):
from collections import Counter
from operator import mul
from functools import reduce

def combinations_count2(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom
#
N=int(input())
A=list(map(int,input().split()))
#
hoge=Counter(A)
ans1=0
for i in hoge.values():
    if i==1:
        continue
    else:
        ans1+=combinations_count2(i,2)

ans2=[]
for i in A:
    ans2.append(A.count(i)-1)

for k in range(N):
    print(ans1-ans2[k])
Problem p02771 (python)

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

if (A is B and B is C) or (A is not B and B is not C and C is not A):
    print("No")
else:
    print("Yes")

Buggy submission (verdict: Runtime Error):
#
N=int(input())
S=[]
for i in range(N):
    S.append(input())
ans=[]

#
while len(S):
    if len(S)==1:
        x = [S.pop(-1), 1]
        ans.append(x)
        break
    x = [S.pop(-1), 1]
    for i in S[:]:
        if x[0] == i:
            S.remove(i)
            x[1]+=1
    ans.append(x)
ans.sort()
ans.sort(key=lambda x:x[1],reverse=True)

for i in range(len(ans)):
    t=ans[0][1]
    if ans[i][1]==t:
        print(ans[i][0])
Problem p02831 (python)

Fixed submission:
import fractions

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


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

print(lcm(A,B))

Buggy submission (verdict: Runtime Error):
import math

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


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

print(lcm(A,B))

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


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

print(lcm(A,B))

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


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

print(lcm(A,B))
Problem p02689 (python)

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

good_list = [True] * N

for i in range(M):
    A, B = map(int, input().split())
    A -= 1
    B -= 1

    if H_list[A] > H_list[B]:
        good_list[B] = False
    elif H_list[A] < H_list[B]:
        good_list[A] = False
    elif H_list[A] == H_list[B]:
        good_list[A] = False
        good_list[B] = False

ans = good_list.count(True)
print(ans)





# import sys
# sys.setrecursionlimit(100000000)

# N, M = map(int, input().split())
# H_list = list(map(int, input().split()))
# road_list = []


# graph_list = [[] for i in range(N)]

# for m in range(M):
#     A, B = map(int, input().split())
#     road_list.append([A, B])

#     A -= 1
#     B -= 1

#     graph_list[A].append(B)
#     graph_list[B].append(A)

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

# def dfs(current, graph_list):

#     global LorS_list
#     global visited

#     if len(graph_list[current]) == 0:
#         LorS_list[current] = 2

#     for i in graph_list[current]:
#         if visited[i] == False:
#             visited[i] = True


#             if H_list[current] > H_list[i] and LorS_list[current] != 1:
#                 LorS_list[current] = 2
#                 LorS_list[i] = 1

#             elif H_list[current] < H_list[i] and LorS_list[i] != 1:
#                 LorS_list[current] = 1
#                 LorS_list[i] = 2

#             elif H_list[current] == H_list[i]:
#                 LorS_list[current] = 1
#                 LorS_list[i] = 1

#             dfs(i, graph_list)


# start = 0
# while all(visited) == False:
#     visited[start] = True
#     dfs(start, graph_list)

#     if False in visited:
#         start = visited.index(False)



# ans = LorS_list.count(2)

# print(ans)

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
H_list = list(map(int, input().split()))
road_list = []

graph_list = [[] for i in range(N)]

for m in range(M):
    A, B = map(int, input().split())
    road_list.append([A, B])

    A -= 1
    B -= 1

    graph_list[A].append(B)
    graph_list[B].append(A)

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

def dfs(current, graph_list):

    global LorS_list
    global visited

    for i in graph_list[current]:
        if visited[i] == False:
            visited[i] = True


            if H_list[current] > H_list[i] and LorS_list[current] != 1:
                LorS_list[current] = 2
                LorS_list[i] = 1

            elif H_list[current] < H_list[i] and LorS_list[i] != 1:
                LorS_list[current] = 1
                LorS_list[i] = 2

            elif H_list[current] == H_list[i]:
                LorS_list[current] = 1
                LorS_list[i] = 1

            dfs(i, graph_list)

dfs(0, graph_list)
ans = LorS_list.count(2) + visited.count(False)

print(ans)
Problem p02819 (python)

Fixed submission:
X = int(input())

is_prime_num_list = [True] * 100005
is_prime_num_list[0] = False
is_prime_num_list[1] = False

for i in range(2, X + 1):
    if is_prime_num_list[i] == True:

        # iの倍数番目をFalseにする
        for j in range(2 * i, 100005, i):
            is_prime_num_list[j] = False

prime_num_list = [i for i, j in enumerate(is_prime_num_list) if i >= X and j == True]

print(min(prime_num_list))


'''
if is_prime_num_list[X] == True:
    print(X)
    exit()
'''

'''
while True:
    X += 1
    is_target = True
    for i in prime_num_list:
        if X % i == 0:
            is_target = False
            break

    if is_target:
        print(X)
        exit()
'''

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

is_prime_num_list = [True] * 100000
is_prime_num_list[0] = False
is_prime_num_list[1] = False

for i in range(2, X + 1):
    if is_prime_num_list[i] == True:

        # iの倍数番目をFalseにする
        for j in range(2 * i, 100000, i):
            is_prime_num_list[j] = False


prime_num_list = [i for i, j in enumerate(is_prime_num_list) if i >= X and j == True]

print(min(prime_num_list))


'''
if is_prime_num_list[X] == True:
    print(X)
    exit()
'''

'''
while True:
    X += 1
    is_target = True
    for i in prime_num_list:
        if X % i == 0:
            is_target = False
            break

    if is_target:
        print(X)
        exit()
'''
Problem p03803 (python)

Fixed submission:
# https://atcoder.jp/contests/abc054/tasks/abc054_a

A, B = map(int, input().split())
Alice = 'Alice'
Bob = 'Bob'
Draw = 'Draw'

if A == B:
    print(Draw)
elif A == 1 and B != 1:
    print(Alice)
elif A != 1 and B == 1:
    print(Bob)
elif A > B:
    print(Alice)
elif A < B:
    print(Bob)

Buggy submission (verdict: Runtime Error):
# https://atcoder.jp/contests/abc054/tasks/abc054_c

import copy
import sys
input = sys.stdin.readline

# 頂点, 辺の数
N, M = map(int, input().split())

# グラフのリスト
# 各頂点からどこの頂点に向かう辺があるかどうかという情報
Graph_list = [[] for i in range(N)]

# 入力
for i in range(M):
    a, b = map(int, input().split())
    a += -1
    b += -1

    # 無向グラフなのでa, b両方
    Graph_list[a].append(b)
    Graph_list[b].append(a)

ans_count = 0
throwgh_point_list = [-1 for i in range(N)]

def dfs(i, current, throwgh_point_list, ans_point_list):   
    # 頂点をN個通ったら終了処理
    if i >= N:
        # すでにカウント済の経路である場合
        if throwgh_point_list in ans_point_list:
            return

        # すでにカウント済ではないかつ全ての点に到達している場合
        # 順不同で比較
        if set(throwgh_point_list) == set(list(range(N))):
            global ans_count
            ans_count += 1
            ans_point_list.append(copy.copy(throwgh_point_list))
        return

    for j in range(len(Graph_list[current])):
        # 現在地を書き込む
        throwgh_point_list[i] = current

        # 次の点に移動する        
        dfs(i + 1, Graph_list[current][j], throwgh_point_list, ans_point_list)

dfs(0, 0, throwgh_point_list, [])
print(ans_count)
Problem p02998 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10000000)

V = 100005
N = int(input())

lines = [[] for _ in range(V * 2)]
visited = [False] * V * 2

count = []
def dfs(v):
	global count
	if visited[v]:
		return
	visited[v] = True
	count[v // V] += 1
	for u in lines[v]:
		dfs(u)


for i in range(N):
	x, y = [int(x) for x in input().split()]
	y += V
	lines[x].append(y)
	lines[y].append(x)

ans = 0
for i in range(V * 2):
	if visited[i]:
		continue
	count = [0, 0]
	dfs(i)
	ans += count[0] * count[1]

ans -= N
print(ans)

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

lines = [[] for _ in range(V * 2)]
visited = [False] * V * 2

count = []
def dfs(v):
	global count
	if visited[v]:
		return
	visited[v] = True
	count[v // V] += 1
	for u in lines[v]:
		dfs(u)


for i in range(N):
	x, y = [int(x) for x in input().split()]
	y += V
	lines[x].append(y)
	lines[y].append(x)

ans = 0
for i in range(V * 2):
	if visited[i]:
		continue
	count = [0, 0]
	dfs(i)
	ans += count[0] * count[1]

ans -= N
print(ans)
Problem p03804 (python)

Fixed submission:
N, M = [int(x) for x in input().split()]

A = []
B = []

for _ in range(N):
	A.append(input())

for _ in range(M):
	B.append(input())

judge = False
	
for i in range(N - M + 1):
	for j in range(N - M + 1):
		for k in range(M):
			if B[k] != A[i + k][j: j + M]:
				break
			if k == M - 1:
				judge = True

if judge:
	print('Yes')
else:
	print('No')

Buggy submission (verdict: Runtime Error):
#include<iostream>
#include <string>
using namespace std;

int main()
{
	int N, M;
	cin >> N >> M;
	
	string A[55];
	string B[55];
	
	for(int i = 0; i < N; i++){
		cin >> A[i];
	}
	for(int j = 0; j < M; j++){
		cin >> B[j];
	}
	
	bool judge = false;
	
	for(int i = 0; i < N - M + 1; i++){
		for(int j = 0; j < N - M + 1; j++){
			for(int k = 0; k < M; k++){
				if(B[k] != A[i + k].substr(j, M)){
					break;
				}
				if(k == M - 1){
					judge = true;
				}
			}
		}
	}
	if(judge){
		cout << "Yes";
	}
	else {
		cout << "No";
	}
}
Problem p02753 (python)

Fixed submission:
s = list(input())
if s[0] == s[1] and s[1] == s[2]:
    print("No")
else:
    print("Yes")

Buggy submission (verdict: Runtime Error):
s = [input()]
q = int(input())

for _ in range(q):
    a = list(input().split())
    if len(a) == 1:
        s.reverse()
    else:
        if a[1] == "1":
            s.reverse()
            s += a[-1]
            s.reverse()
        else:
            s += a[-1]
print("".join(s))