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

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

for i in range(M):
	a,b = map(int, input().split())
	t[a-1]+=1
	t[b-1]+=1

for i in range(N):
	print(t[i])

Buggy submission (verdict: Runtime Error):
def ABC_61_B():
    N,M = map(int, input().split())
    t = [ 0 for _ in range(N)]
    t2 = [ 0 for _ in range(N)]

    for i in range(M):
        a,b = map(str, input().split())
        t[int(a)-1] = str(t[int(a)-1])+b
        t[int(b)-1] = str(t[int(b)-1])+a

    for i in range(len(t)):
        t2=list(t[i])
        print(len(t2)-1)

if __name__ == '__main__':

    ABC_61_B()
Problem p03853 (python)

Fixed submission:
H,W = map(int, input().split())
C = [0 for _ in range(H)]

for i in range(H):
	C[i] = input()

for i in range(H):
	print(C[i])
	print(C[i])

Buggy submission (verdict: Runtime Error):
#たてなが
def ABC_49_B():
    H,W = map(int, input().split())
    C = [0 for _ in range(W)]

    for i in range(H):
        C[i] = input()

    for i in range(H):
        print(C[i])
        print(C[i])


if __name__ == '__main__':

    ABC_49_B()

Buggy submission (verdict: Runtime Error):
H,W = map(int, input().split())
C = [0 for _ in range(W)]

for i in range(H):
	C[i] = input()

for i in range(H):
	print(C[i])
	print(C[i])
Problem p03860 (python)

Fixed submission:
def ABC_48_A():
    A,B,C = map(str, input().split())
    print('A' + B[0] + 'C')


if __name__ == '__main__':

    ABC_48_A()

Buggy submission (verdict: Runtime Error):
#AtCoder *** Contest
def ABC_48_A():
    A,B,C = map(str, input().split())
    print('A' + B[0] + 'C')


if __name__ == '__main__':
Problem p04030 (python)

Fixed submission:
def ABC_43_B():
    s = input()
    t=[]

    for i in range(len(s)):
        if s[i] == '0':
            t.append('0')
        elif s[i] == '1':
            t.append('1')
        else:
            if len(t)==0:
                a=0
            else:
                del t[len(t)-1]

    print(''.join(t))



if __name__ == '__main__':

    ABC_43_B()

Buggy submission (verdict: Runtime Error):
def ABC_43_B():
    s = input()
    t=[]

    for i in range(len(s)):
        if s[i] == '0':
            t.append('0')
        elif s[i] == '1':
            t.append('1')
        else:
            if len(t)==0:
                a=0
            else:
                del t[i-1]

    print(''.join(t))



if __name__ == '__main__':

    ABC_43_B()
Problem p03450 (python)

Fixed submission:


def dfs(graph, start, visited):
    if visited[start] != -99999:
        return True
    
    stack = [start]
    visited[start] = 0
    while stack:
        label = stack.pop()
        for nextnode, distance in graph[label]:
            if visited[nextnode] == -99999:
                stack.append(nextnode)
                visited[nextnode] = visited[label] + distance
            elif visited[nextnode] != visited[label] + distance:
                return False
    return True

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

graph = [[] for i in range(N+1)]

for i in range(M):
    L, R, D = (int(i) for i in input().split())
    graph[L].append((R, D))
    graph[R].append((L, -1 * D))


visited = [-99999 for i in range(N+1)]

flag = True
for i in range(1, N + 1):
    ans = dfs(graph, i, visited)
    if not ans:
        flag = False
        break

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

Buggy submission (verdict: Runtime Error):


import heapq

def dijkstra(nodes, N):
    dist = [float('inf') for i in range(N + 2)]
    prev = [float('inf') for i in range(N + 2)]

    dist[0] = 0
    q = []
    heapq.heappush(q, (0, 0))

    while len(q) != 0:
        prov_cost, src = heapq.heappop(q)
        if dist[src] < prov_cost:
            continue

        for (nextnum, dis) in nodes[src].nextnode:
            cost = dis
            if dist[nextnum] >= dist[src] + cost:
                dist[nextnum] = dist[src] + cost
                heapq.heappush(q, (dist[nextnum], nextnum))
                prev[nextnum] = src
        
    return get_path(N + 1, prev)

def get_path(goal, prev):
    path = [goal]
    dest = goal

    while prev[dest] != float('inf'):
        path.append(prev[dest])
        dest = prev[dest]

    return list(reversed(path))

class People:
    def __init__(self, num):
        self.nodenum = num
        self.nextnode = []

    def set_node(self, num, dis):
        self.nextnode.append((num, dis))

    def node_adj(self):
        if self.nextnode == []:
            self.nextnode.append((self.nodenum + 1, 0))


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

nodes = []
for i in range(N+2):
    nodes.append(People(i))

for i in range(M):
    L, R, D = (int(i) for i in input().split())
    nodes[L].set_node(R, D)

for i in range(N+1):
    nodes[i].node_adj()

ans = dijkstra(nodes, N)

flag = True
for i in range(N+1):
    if ans[i] != i:
        flag = False
if flag:
    print('Yes')
else:
    print('No')
Problem p03455 (python)

Fixed submission:
t = input().split()
for i in range(len(t)):
    t[i] = int(t[i])

a = t[0]
b = t[1]

if (a * b) % 2 == 0:
    print("Even")
else :
    print("Odd")

Buggy submission (verdict: Runtime Error):
a = int(input())
b = int(input())

c = a * b

if c % 2 == 0:
    print("Even")
else:
    print("Odd")
Problem p02741 (python)

Fixed submission:
list = [1,1,1,2,1,2,1,5,2,2,1,5,1,2,1,14,1,5,1,5,2,2,1,15,2,2,5,4,1,4,1,51]
firstInputText = input()
print(list[int(firstInputText) - 1])

Buggy submission (verdict: Runtime Error):
import math

firstInputText = input()
inputList = firstInputText.split()
a = int(inputList[0])
b = int(inputList[1])
c = int(inputList[2])
x = math.sqrt(a) + math.sqrt(b)
y = math.sqrt(c)
# print(x)
# print(y)

# if math.isclose(x,y):
#     print("Yes")
# else:
#     print("No")
if x == y:
    print("No")
elif x < y:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
list = [1,1,1,2,1,2,1,5,2,2,1,5,1,2,1,14,1,5,1,5,2,2,1,15,2,2,5,4,1,4,1,51]
firstInputText = input()
print(textList[int(firstInputText) - 1])

Buggy submission (verdict: Runtime Error):
text = "1,1,1,2,1,2,1,5,2,2,1,5,1,2,1,14,1,5,1,5,2,2,1,15,2,2,5,4,1,4,1,51"
textList = text.split(",")
firstInputText = input()
print(textList[int(firstInputText) - 1])
secondInputText = input()
print(textList[int(secondInputText) - 1])
Problem p02705 (python)

Fixed submission:
import math
pi=math.pi

R=float(input())

print(2.0*pi*R)

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

Fixed submission:
H, N = map(int, input().split())
skills_sum = sum(map(int, input().split()))
print("Yes" if H-skills_sum <= 0 else "No")

Buggy submission (verdict: Runtime Error):
H, N = map(int, input())
skills_sum = sum(map(int, input()))
print("Yes" if H-skills_sum <= 0 else "No")
Problem p02818 (python)

Fixed submission:
a, b, k = map(int, input().split())
print(max(a-k, 0), max(min(a+b-k, b), 0))

Buggy submission (verdict: Runtime Error):
a, b, k = map(int, input())
print(max(a-k, 0), max(min(a+b-k, b), 0))
Problem p02957 (python)

Fixed submission:
a, b = map(int, input().split())
print((a+b)//2 if not (a+b)%2 else "IMPOSSIBLE")

Buggy submission (verdict: Runtime Error):
a, b = map(int, input())
print((a+b)//2 if not (a+b)%2 else "IMPOSSIBLE")
Problem p03241 (python)

Fixed submission:
n, m = map(int, input().split())
def is_prime(q):
    q = abs(q)
    if q == 2: return True
    if q < 2 or q&1 == 0: return False
    return pow(2, q-1, q) == 1
if is_prime(m):
    print(1)
else:
    for i in range(m//n, 0, -1):
        if not m%i:
            print(i)
            break

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
if m%2:
    for i in range(m//n, 0, -2):
    if not m%i:
        print(i)
        break
else:
    for i in range(m//n, 0, -1):
        if not m%i:
            print(i)
            break
Problem p03280 (python)

Fixed submission:
a, b = map(int, input().split())
print((a-1)*(b-1))

Buggy submission (verdict: Runtime Error):
a, b = map(int, input())
print((a-1)*(b-1))
Problem p03281 (python)

Fixed submission:
N = int(input())
ans = 0

for i in range(1, N+1):
	div_num = 0
	if i % 2:
		for j in range(1, i+1):
			if not i % j:
				div_num += 1
		if div_num == 8:
			ans += 1

print(ans)

Buggy submission (verdict: Runtime Error):
n = inpt(input())
ans = 0
for i in range(1, n+1):
  stock = 0
  for j in range(1, n+1):
    if i % j == 0:
      stock += 1
  if stock == 8 and i % 2:
    ans += 1
print(ans)
Problem p03308 (python)

Fixed submission:
input()
numbers = list(map(int, input().split()))
print(max(numbers)-min(numbers))

Buggy submission (verdict: Runtime Error):
input()
numbers = map(int, input().split())
print(max(numbers)-min(numbers))
Problem p03309 (python)

Fixed submission:
from statistics import median

N = int(input())
numbers = [int(a)-i for i, a in enumerate(input().split())]
b = median(numbers)
abs_1 = sum([abs(c-int(b)) for c in numbers])
abs_2 = sum([abs(c-int(b)-1) for c in numbers])
print(min(abs_1, abs_2))

Buggy submission (verdict: Runtime Error):
N = int(input())
numbers = map(int, input().split())
min_num = min(numbers)
max_num = max(numbers)
abs_= float('inf')
for b in range(min_num, max_num):
    abs_pre = sum([abs(a-b-i) for i, a in enumerate(numbers)])
    if abs_pre < abs_:
        abs_ = abs_pre
print(abs_)
Problem p03361 (python)

Fixed submission:
H, W = map(int, input().split())
picture = [input() for _ in range(H)]

for i in range(H):
	for j in range(W):
		if picture[i][j] == '#':
			if i == 0 or picture[i-1][j] == '.':
				if j == 0 or picture[i][j-1] == '.':
					if i == H-1 or picture[i+1][j] == '.':
						if j == W-1 or picture[i][j+1] == '.':
							print('No')
							exit()

print('Yes')

Buggy submission (verdict: Runtime Error):
H, W = map(int, input().split())
picture = [input() for _ in range(H)]

for i in range(H):
	for j in range(W):
		if picture[i][j] == '#':
			if i == 0 or picture[i-1][j] == '.':
				if j == 0 or picture[i][j-1] == '.':
					if i == H or picture[i+1][j] == '.':
						if j == W or picture[i][j+1] == '.':
							print('No')
							exit()

print('Yes')
Problem p03487 (python)

Fixed submission:
from collections import Counter

N = int(input())
a = [int(i) for i in input().split()]

cnt = Counter(a)
ans = 0

for ai, num in cnt.items():
  if num >= ai:
  	ans += num - ai  
  else:
    ans += num

print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
a = [int(i) for i in input().split()]
set_a = set(a)
ans = 0

for ai in set_a:
  	ai_count = a.count(ai)
    ans += ai_count - ai if ai_count >= ai else ai_count

print(ans)
Problem p02675 (python)

Fixed submission:
N = int(input())
n = N%10
if n == 2 or n == 4 or n ==5 or n ==7 or n == 9:
  print("hon")
elif n == 0 or n == 1 or n == 6 or n == 8:
  print("pon")
else :
  print("bon")

Buggy submission (verdict: Runtime Error):
N = int(input())
n = N%10
if n == 2 or 4 or 5 or 7 or 9:
  print("hon")
elif n == 0 or 1 or 6 or 8:
  print("pon")
else n == 3:
  print("bon")

Buggy submission (verdict: Runtime Error):
N = int(input())
n = N%10
if n == 2 or 4 0r 5 0r 7 or 9:
  print("hon")
if n == 0 or 1 or 6 or 8:
  print("pon")
if n == 3:
  print("bon")
Problem p02687 (python)

Fixed submission:
S = input()
x = "ARC"
if S == "ARC":
  x = "ABC"
print(x)

Buggy submission (verdict: Runtime Error):
S = input()
x == ARC
if S == ARC:
  x == ABC
print(x)
Problem p02678 (python)

Fixed submission:
from collections import deque
N,M = map(int,input().split())
data = [[] for i in range(N)]
for i in range(M):
    a,b = map(int,input().split())
    data[a-1].append(b)
    data[b-1].append(a)

que = deque([1])
ans = [0 for i in range(N)]
while True:
    cur = que.popleft()
    for item in data[cur-1]:
        if ans[item-1] == 0:
            que.append(item)
            ans[item-1] = cur
    if len(que) == 0: break

if 0 in ans:
    print("No")
else:
    print("Yes")
    for i in range(1,N): print(ans[i])

Buggy submission (verdict: Runtime Error):
from collections import deque
N,M = map(int,input().split())
data = [[] for i in range(M)]
for i in range(M):
    a,b = map(int,input().split())
    data[a-1].append(b)
    data[b-1].append(a)

que = deque([1])
ans = [0 for i in range(M)]
while True:
    cur = que.popleft()
    for item in data[cur-1]:
        if ans[item-1] == 0:
            que.append(item)
            ans[item-1] = cur
    if len(que) == 0: break

print("yes")
for i in range(1,N): print(ans[i])
Problem p03006 (python)

Fixed submission:
N = int(input())
xy = []
x = []
y = []
for i in range(N):
  xi,yi = map(int,input().split())
  xy.append([xi,yi])
  x.append(xi)
  y.append(yi)

res = []
count = 0
for i in range(N):
  for j in range(i,N):
#コストの和の最小値を求める
#これ以上進めない点が何個あるか数えれば良い
    p = x[i] - x[j]
    q = y[i] - y[j]
    count = 0
    for item in xy:
      if [item[0]+p,item[1]+q] not in xy:
        count += 1
    if count != 0: res.append(count)

if res == []:
  res.append(1)

print(min(res))

Buggy submission (verdict: Runtime Error):
N = int(input())
xy = []
x = []
y = []
for i in range(N):
  xi,yi = map(int,input().split())
  xy.append([xi,yi])
  x.append(xi)
  y.append(yi)

res = []
count = 0
for i in range(N):
  for j in range(i,N):
#コストの和の最小値を求める
#これ以上進めない点が何個あるか数えれば良い
    p = x[i] - x[j]
    q = y[i] - y[j]
    count = 0
    for item in xy:
      if [item[0]+p,item[1]+q] not in xy:
        count += 1
    if count != 0: res.append(count)


print(min(res))

Buggy submission (verdict: Runtime Error):
N = int(input())
xy = []
x = []
y = []
for i in range(N):
  xi,yi = map(int,input().split())
  xy.append([xi,yi])
  x.append(xi)
  y.append(yi)

res = []
count = 0
for i in range(N):
  for j in range(i+1,N):
#コストの和の最小値を求める
#これ以上進めない点が何個あるか数えれば良い
    p = x[i] - x[j]
    q = y[i] - y[j]
    count = 0
    for item in xy:
      if [item[0]+p,item[1]+q] not in xy:
        count += 1
    if count != 0: res.append(count)


print(min(res))

Buggy submission (verdict: Runtime Error):
N = int(input())
xy = []
x = []
y = []
for i in range(N):
  xi,yi = map(int,input().split())
  xy.append([xi,yi])
  x.append(xi)
  y.append(yi)

res = []
count = 0
for i in range(N):
  for j in range(i+1,N):
#コストの和の最小値を求める
#これ以上進めない点が何個あるか数えれば良い
    p = x[i] - x[j]
    q = y[i] - y[j]
    count = 0
    for item in xy:
      if [item[0]+p,item[1]+q] not in xy:
        count += 1
    if count != 0: res.append(count)


print(min(res))

Buggy submission (verdict: Runtime Error):
N = int(input())
xy = []
x = []
y = []
for i in range(N):
  xi,yi = map(int,input().split())
  xy.append([xi,yi])
  x.append(xi)
  y.append(yi)

res = []
for pi in range(N):
  for pj in range(N-pi):
    for qi in range(N):
      for qj in range(N-qi):
#コストの和の最小値を求める
#これ以上進めない点が何個あるか数えれば良い
        p = x[pi] - x[pj]
        q = y[qi] - y[qj]
        count = 0
        for item in xy:
          if [item[0]+p,item[1]+q] not in xy:
            count += 1
        if count != 0: res.append(count)

print(min(res))
Problem p03014 (python)

Fixed submission:
H,W = map(int,input().split())
s = [[] for i in range(H)]
for i in range(H): s[i] = list(input())
l = [[0]*W for i in range(H)]
r = [[0]*W for i in range(H)]
d = [[0]*W for i in range(H)]
u = [[0]*W for i in range(H)]

for h in range(H):
    if s[h][0] == ".": l[h][0] = 1
    for w in range(1,W):
        if s[h][w] == ".": l[h][w] = l[h][w-1] + 1
    if s[h][W-1] == ".": r[h][W-1] = 1
    for w in range(1,W):
        if s[h][W-1-w] == ".": r[h][W-1-w] = r[h][W-w] + 1

for w in range(W):
    if s[0][w] == ".": d[0][w] = 1
    for h in range(1,H):
        if s[h][w] == ".": d[h][w] = d[h-1][w] + 1
    if s[H-1][w] == ".": u[H-1][w] = 1
    for h in range(1,H):
        if s[H-1-h][w] == ".": u[H-1-h][w] = u[H-h][w] + 1
ans = 0
for h in range(H):
    for w in range(W):
        ans = max(ans, l[h][w]+r[h][w]+u[h][w]+d[h][w]-3)

print(ans)

Buggy submission (verdict: Runtime Error):
H,W = map(int,input().split())
s = [[] for i in range(H)]
for i in range(H): s[i] = list(input())
ans_y = [[0]*W for i in range(H)]
ans_t = [[0]*W for i in range(H)]

def yoko(h,w,n):
    if w == W-1 or s[h][w+1] == "#":
        ans_y[h][w] = n
        if n != 1: return n
    else:
        num = yoko(h,w+1,n+1)
        ans_y[h][w] = num
        if n != 1: return num

def tate(h,w,n):
    if h == H-1 or s[h+1][w] == "#":
        ans_t[h][w] = n
        if n != 1: return n
    else:
        num = tate(h+1,w,n+1)
        ans_t[h][w] = num
        if n != 1: return num

for h in range(H):
    for w in range(W):
        if s[h][w] == ".":
            if ans_y[h][w] == 0: yoko(h,w,1)
            if ans_t[h][w] == 0: tate(h,w,1)

ans = 0
for h in range(H):
    for w in range(W):
        ans = max(ans, ans_y[h][w] + ans_t[h][w] - 1)

print(ans)
Problem p03633 (python)

Fixed submission:
N = int(input())
data = [0]*N
for i in range(0,N): data[i] = int(input())

import fractions

ans = data[0]
for i in range(0,N):
    ans = ans*data[i] // fractions.gcd(ans,data[i])

print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
data = [0]*N
for i in range(0,N): data[i] = int(input())

import math

ans = data[0]
for i in range(0,N):
    ans = ans*data[i] // math.gcd(ans,data[i])

print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
data = [0]*N
for i in range(0,N): data[i] = int(input())

import math

ans = data[0]
for i in range(0,N):
    ans = ans*data[i]//math.gcd(ans,data[i])

print(ans)
Problem p03206 (python)

Fixed submission:
d=int(input())
print("Christmas"+" Eve"*(25-d))

Buggy submission (verdict: Runtime Error):
d=int(input())
print(" ".join(["Christmas", *["Eve"]*(25-d)]))
Problem p03238 (python)

Fixed submission:
if input()=="1":
    print("Hello World")
else:
    print(int(input())+int(input()))

Buggy submission (verdict: Runtime Error):
if input()="1":
    print("Hello World")
else:
    print(int(input())+int(input()))
Problem p03547 (python)

Fixed submission:
x,y=input().split()
print(">" if x>y else "<" if x<y else "=")

Buggy submission (verdict: Runtime Error):
x,y=map(int,input().split())
print(">" if x>y else "<" if x<y else "=")
Problem p02658 (python)

Fixed submission:
#! /usr/bin/env python3
# -*- coding:utf-8 -*-

def product_many(N):
    if 0 in N: return 0
    ans = 1
    for x in N:
        if (10 ** 18 / ans) < x: return -1
        ans *= x
        if ans > 10 ** 18: return -1
    return ans

def main():
    _ = input()
    N = list(map(int, input().split()))
    print(product_many(N))

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
#! /usr/bin/env python3
# -*- coding:utf-8 -*-

def product_many(N):
    if 0 in N: return 0
    ans = 1
    for x in N:
        if (10 ^ 18 / ans) < x: return -1  
        ans *= x
        if ans > 10 ^ 18: return -1
    return ans

def main():
    _ = input()
    N = list(map(int, input().split()))
    print(product_many(N))

if __name__ == "__main__":
    main()
Problem p02675 (python)

Fixed submission:
#! /usr/bin/env python3
# -*- coding:utf-8 -*-

def name_count(N):
    x = N%10
    if x in [2, 4, 5, 7, 9]: return "hon"
    elif x in [0, 1,6, 8]: return "pon"
    else: return "bon"

def main():
    N = int(input())
    print(name_count(N))

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
#! /usr/bin/env python3
# -*- coding:utf-8 -*-

def name_count(N):
    x = N%10
    if x in [2, 4, 5, 7, 9]: return "hon"
    elif x in [0, 1,6, 8]: return "pon"
    else return "bon"

def main():
    N = int(input())
    print(name_count(N))

if __name__ == "__main__":
    main()
Problem p02767 (python)

Fixed submission:
#! /usr/bin/env python3
# -*- coding:utf-8 -*-

def calc_sum_of_power(N, coord):
    spot = round(sum(coord)/N)
    return sum([(x - spot)**2 for x in coord])

def main():
    N = int(input())
    coord = list(map(int, input().split()))
    print(calc_sum_of_power(N, coord))

if __name__ == "__main__":
    try:
        assert calc_sum_of_power(2, [1, 4]) == 5
        assert calc_sum_of_power(7, [14, 14, 2, 13, 56, 2, 37]) == 2354
    except:
        import traceback
        traceback.print_exc()
        exit()
    main()

Buggy submission (verdict: Runtime Error):
#! /usr/bin/env python3
# -*- coding:utf-8 -*-

def calc_sum_of_power(N, coord):
    spot = round(sum(coord)/N)
    return sum([(x - spot)**2 for x in coord])

def main():
    N = int(input())
    X = map(int, input().split())
    print( (n))

if __name__ == "__main__":
    try:
        assert calc_sum_of_power(2, [1, 4]) == 5
        assert calc_sum_of_power(7, [14, 14, 2, 13, 56, 2, 37]) == 2354
    except:
        import traceback
        traceback.print_exc()
        exit()
    main()
Problem p02813 (python)

Fixed submission:
N = int(input())

def factorial(num):
    if num == 1:
        return 1
    return num * factorial(num - 1)

def count_order(group):
    numbers = [i for i in range(1, N + 1)]
    res = 1
    for i in range(len(group) - 1):
        num = group[i]
        res += numbers.index(num) * pattern[-(i + 1)]
        numbers.pop(numbers.index(num))
    return res


P = list(map(int, input().split()))
Q = list(map(int, input().split()))

pattern = [factorial(i) for i in range(1, N)]
res_p = count_order(P)
res_q = count_order(Q)

print(abs(res_p - res_q))

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

def factorial(num):
    if num == 1:
        return 1
    return num * factorial(num - 1)

def count_order(group):
    numbers = [i for i in range(1, N + 1)]
    res = 1
    for i in range(len(group) - 1):
        num = group[i]
        res += numbers.index(num) * pattern[-(i + 1)]
        numbers.pop(numbers.index(num))
    return res


P = list(map(int, input().split()))
Q = list(map(int, input().split()))

pattern = [factorial(i) for i in range(1, N)]
res_p = count_order(P)
res_q = count_order(Q)

print(abs(res_p - res_q))
Problem p02844 (python)

Fixed submission:
N = int(input())
S = list(input())

ans = 0

for n in range(1000):
    pin = str(n).zfill(3)
    head = 0
    for c in S:
        if c == pin[head]:
            head += 1
        if head == 3:
            ans += 1
            break

print(ans)

Buggy submission (verdict: Runtime Error):
import sys

sys.setrecursionlimit(2000)

N = int(input())
S = list(input())

pattern = set()

def generate_pwd(cnt, lucky_num):
    if len(lucky_num) == 3:
        pattern.add(''.join(lucky_num))
        return
    if cnt > 3:
        return
    
    generate_pwd(cnt, lucky_num[:cnt] + lucky_num[cnt + 1:])
    generate_pwd(cnt + 1, lucky_num)

    return

generate_pwd(0, S)
print(len(pattern))

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

pattern = set()

def generate_pwd(cnt, lucky_num):
    if len(lucky_num) == 3:
        pattern.add(''.join(lucky_num))
        return
    if cnt > 3:
        return
    
    generate_pwd(cnt, lucky_num[:cnt] + lucky_num[cnt + 1:])
    generate_pwd(cnt + 1, lucky_num)

    return

generate_pwd(0, S)
print(len(pattern))
Problem p02936 (python)

Fixed submission:
n, q = map(int, input().split())
node = [[] for _ in range(n)]
ans = [0] * n

for _ in range(n - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    node[a].append(b)
    node[b].append(a)

for _ in range(q):
    p, x = map(int, input().split())
    p -= 1
    ans[p] += x

not_yet = [True] * n
not_yet[0] = False
stack = [0]
while stack:
    parent = stack.pop()
    for child in node[parent]:
        if not_yet[child]:
            ans[child] += ans[parent]
            not_yet[child] = False
            stack.append(child)

print(*ans)

Buggy submission (verdict: Runtime Error):
n, q = map(int, input().split())
node = [[] for _ in range(n)]
ans = [0] * n

def score(p, c):
    ans[p] += c
    for child in node[p]:
        score(child, ans[p])

for _ in range(n - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    node[a].append(b)

for _ in range(q):
    p, x = map(int, input().split())
    p -= 1
    ans[p] += x

score(0, 0)
print(*ans)