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

Fixed submission:
import fractions
N,X = map(int,input().split())

x = list(map(int,input().split()))
st = []
x.append(X)

x.sort()

gcd = 0

for i in range(N):
    if i == 0:
        gcd = x[i+1]-x[i]
    else:
        gcd = fractions.gcd(gcd,x[i+1]-x[i])
    st.append(x[i+1]-x[i])
print(gcd)

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

x = list(map(int,input().split()))
st = []
x.append(X)

x.sort()

gcd = x[0]

for i in range(N):
    gcd = math.gcd(gcd,x[i+1]-x[i])
    st.append(x[i+1]-x[i])
st.sort()
for v in st:
    if not v % gcd:
        print(v)
        break
Problem p03577 (python)

Fixed submission:
s = input()
print(s[:len(s)-8])

Buggy submission (verdict: Runtime Error):
s = input()
print(s-"FESTIVAL")
Problem p03578 (python)

Fixed submission:
# 計算量O(N2M)
import collections
N = int(input())

d = collections.Counter(list(map(int,input().split())))

M = int(input())
t = list(map(int,input().split()))
t_num = t.copy()
t_num = set(list(t_num))
t = collections.Counter(t)

if N < M:
    print('NO')
    exit()

for key in t_num:
    if d[key] < t[key]:
        print('NO')
        exit()
print('YES')

Buggy submission (verdict: Runtime Error):
# 計算量O(N2M)

N = int(input())

d = list(map(int,input().split()))
d_cnt = [0]*max(d)

for v in d:
    d_cnt[v-1] += 1

M = int(input())

t = list(map(int,input().split()))
t_cnt = [0]*max(t)

for v in t:
    t_cnt[v-1] += 1

if N < M:
    print('NO')
    exit()

for i in range(min(len(d_cnt),len(t_cnt))):
    if t_cnt[i] != 0:
        if d_cnt[i] < t_cnt[i]:
            print('NO')
            exit()

print('YES')

Buggy submission (verdict: Runtime Error):
# 計算量O(N2M)

N = int(input())

d = list(map(int,input().split()))
d_cnt = [0]*max(d)

for v in d:
    d_cnt[v-1] += 1

M = int(input())

t = list(map(int,input().split()))
t_cnt = [0]*max(t)

for v in t:
    t_cnt[v-1] += 1

if N < M:
    print('NO')
    exit()


for i in range(len(t_cnt)):
    if t_cnt[i] != 0:
        if d_cnt[i] < t_cnt[i]:
            print('NO')
            exit()

print('YES')

Buggy submission (verdict: Runtime Error):
# 計算量O(N2M)

N = int(input())

d = list(map(int,input().split()))
d_cnt = [0]*max(d)

for v in d:
    d_cnt[v-1] += 1

M = int(input())

t = list(map(int,input().split()))
t_cnt = [0]*max(t)

for v in t:
    t_cnt[v-1] += 1

if N < M:
    print('NO')
    exit()

for dn,tn in zip(d_cnt,t_cnt):
    if tn != 0:
        if dn < tn:
            print('NO')
            exit()

print('YES')
Problem p03611 (python)

Fixed submission:
from collections import Counter

N = int(input())
a = list(map(int,input().split()))
c = Counter(a)
max_num = 0

for x in range(max(a)+1):
      max_num = max(max_num,(c[x] + c[x+1] + c[x+2]))
print(max_num)

Buggy submission (verdict: Runtime Error):
N = int(input())
a = list(map(int,input().split()))
c = [0]*(max(a)+1)
max_num = 0
for i in a:
  c[i] += 1
for x in range(max(a)+1):
  if max_num < (c[x-1]) + (c[x]) + (c[x+1]):
      max_num = (c[x-1]) + (c[x]) + (c[x+1])
print(max_num)

Buggy submission (verdict: Runtime Error):
N = int(input())
a = list(map(int,input().split()))
c = [0]*(max(a)+1)
max_num = 0
for i in a:
  c[i] += 1
for x in range(1,max(a)+1):
  if max_num < (c[x-1]) + (c[x]) + (c[x+1]):
      max_num = (c[x-1]) + (c[x]) + (c[x+1])
print(max_num)
Problem p03612 (python)

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
res = 0
i = 1
while i < n+1:
    if a[i-1] == i:
        res += 1
        i+=2
    else:
        i+=1
print(res)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int,input().split()))
res = 0
for i in range(2,n:
    if a[i-1] == i:
        res += 1
print(res)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int,input().split()))
res = 0
i = 1
while i < n+1:
    if a[i-1] == i:
        res += 1
        while a[i-1] == i:
            res+=1
            i+=1
            if i < n+1:
                break
        res -= 1
    i+=1
print(res)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int,input().split()))
res = 0
flg = True
i = 1
while i < n+1:
    if a[i-1] == i:
        res += 1
        while a[i-1] == i:
            res+=1
            i+=1
        res -= 1
    i+=1
print(res)
Problem p03640 (python)

Fixed submission:
H,W = map(int,input().split())

N = int(input())

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

res = []
j = 0
st = 0 # リスト添え字管理

for i in range(H):
    j = 0
    while j < W:
        while 0 < a[st] and j < W:
            res.append(str(st+1))
            j += 1
            a[st] -= 1
        if a[st] == 0:
            st += 1
    if i % 2 == 1:
        res.reverse()
    print(' '.join(res))
    res = []

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

N = int(input())

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

s = []

res = []

for v,i in enumerate(a,1):
    for _ in range(v):
        s.append(str(i))

for i in range(H):
    for j in range(W):
        res.append(str(s.pop(0)))
    if i % 2 == 1:
        res.reverse()
    print(' '.join(res))
    res = []
Problem p03719 (python)

Fixed submission:
a,b,c=map(int,input().split())
print('Yes' if a<=c<=b else 'No')

Buggy submission (verdict: Runtime Error):
a,b,c=map(int,input().split())
print('Yes' if A<=C<=B else 'No')
Problem p03799 (python)

Fixed submission:
s,c = map(int,input().split())
res = 0
if s*2 <= c:
    res = s
    c -= s*2
    s = 0
else:
    res += c//2
    c = 0

if c:
    res += c//4
print(res)

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

if s*2 <= c:
    res = s
    c -= s*2
    s = 0
else:
    res += c//2
    c = 0

#print(res,s,c)

if c:
    res += c//4
print(res)

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

if s*2 <= c:
    res = s
    c -= s*2
    s = 0
else:
    res += c//2
    m = 0

#print(res,s,c)

if c:
    res += c//4
print(res)

Buggy submission (verdict: Runtime Error):
s,c = map(int,input().split())
res = 0

if s*2 <= c:
    res += s
    c -= s*2
    res+= c
else:
    res += c//2
    c //= 2
if c:
    res += m//4
print(res)
Problem p04019 (python)

Fixed submission:
S = input()

n = 0
e = 0
w = 0
s = 0

for v in S:
    if v == 'N': n+=1
    if v == 'E': e+=1
    if v == 'W': w+=1
    if v == 'S': s+=1
if ((0<n and 0<s) or (n==0 and s==0)) and ((0<e and 0<w) or (e==0 and w==0)):
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
s = input()

n = 0
e = 0
w = 0
s = 0

for v in s:
    if v == 'N': n+=1
    if v == 'E': e+=1
    if v == 'W': w+=1
    if v == 'S': s+=1

if n == s and e == w:
    print('Yes')
else:
    print('No')
Problem p02630 (python)

Fixed submission:

n=int(input())

alist=[0]*(10**5+1)

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

for i in A:
    alist[i]+=1
asum=sum(A)
for i in range(q):
    b,c=map(int , input().split())
    bnum=alist[b]
    asum+=bnum*(c-b)
    alist[b]=0
    alist[c]+=bnum
    print(asum)

Buggy submission (verdict: Runtime Error):

n=int(input())

alist=[0 for i in range(n+1)]

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

for i in A:
    alist[i]+=1
asum=sum(A)
for i in range(q):
    b,c=map(int , input().split())
    bnum=alist[b]
    asum+=bnum*(c-b)
    alist[b]=0
    alist[c]+=bnum
    print(asum)

Buggy submission (verdict: Runtime Error):

n=int(input())

alist=[0 for i in range(n+1)]

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

for i in A:
    alist[i]+=1
asum=sum(A)
for i in range(q):
    b,c=map(int , input().split())
    bnum=alist[b]
    asum+=bnum*(c-b)
    alist[b]=0
    alist[c]+=bnum
    print(asum)
Problem p02582 (python)

Fixed submission:
n = input()

cnt = 0
flag = False
if n[1] == 'S':
    if 'R' in n:
        print(1)
        flag = True
    else:
        print(0)
        flag = True
if flag == False:
    for i in n:
        if i == 'R':
            cnt += 1
    print(cnt)

Buggy submission (verdict: Runtime Error):
# ABC172　C - Walking Takahashi
X,K,D=map(int,input().split())

q=abs(X)//D
if q>K:
    print(abs(X)-K*D)
else:
    if (K-q)%2==0:
        print(abs(X)-q*D)
    else:
        print(abs(abs(X)-(q+1)*D))
Problem p02718 (python)

Fixed submission:
n,m = map(int,input().split())
A = list(map(int,input().split()))

s = sum(A)
A.sort(reverse=True)

if A[m-1] >= s*1/(4*m):
    print('Yes')
else:
    print('No')

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

s = sum(A)
A.sort(reverse=True)

if A[m] >= s*1/(4*m):
    print('Yes')
else:
    print('No')
Problem p02761 (python)

Fixed submission:
n,m = map(int, input().split())
 
sc = [tuple(map(int, input().split())) for _ in range(m)]
 
for i in range(1000):
    k = str(i)
    # all()：全ての要素がTrueであればTrueを返す
    # len(k)==nならば、左から一桁目が0である心配はない
    if len(k) == n and all([k[s-1]==str(c) for s,c in sc]):
        print(k)
        exit()
        
print('-1')

Buggy submission (verdict: Runtime Error):
n,m = map(int,input().split())
SC = [list(map(int,input().split())) for __ in range(m)]

flag = False
l = [0]*3
for i in range(m):
    l[SC[i][0]-1] = SC[i][1]
    if flag == True:
        break
    for j in range(1,m-i):
        if SC[i][0] == SC[j][0]:
            if l[SC[i][0]-1] != l[SC[j][0]-1]:
                print('-1')
                flag = True
                break
    
if flag == False    
    if (l[n-1] == 0):
        print('-1')
    else:
        l = l[:n]
        s = ''
        for i in l:
            s += str(i)
        print(int(s))
Problem p03037 (python)

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

maxi = 10**6
mini = 0
for lr in LR:
    mini = max(lr[0],mini)
    maxi = min(lr[1],maxi)
if maxi-mini < 0:
    print(0)
else:
    print(maxi-mini+1)

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

maxi = 0
mini = 10**6
for lr in LR:
    maxi = max(lr[0],maxi)
    mini = min(lr[1],mini)

if mini-maxi+1 >= n:
    print(n)
else:
    print(mini-maxi+1)
Problem p03373 (python)

Fixed submission:
# Half and Half
a,b,c,x,y = map(int,input().split())

ans = []
for i in range(max(x,y)+1):
    ans.append(2*c*i + a*max(0,x-i) + b*max(0,y-i))

print(min(ans))

Buggy submission (verdict: Runtime Error):
# Half and Half
a,b,c,x,y = map(int,input().split())

ans = []
for i in range(max(x,y)):
    ans.append(2*c*i + a*max(0,x-i) + b*max(0,y-i))
    print(ans)

print(min(ans))
Problem p03610 (python)

Fixed submission:
s = input()

print(s[0:len(s):2])

Buggy submission (verdict: Runtime Error):
s = input()

s_odd = [s[i] for i in range(len(s)) if i%2 == 0]
print("".join(s_odd)
Problem p03611 (python)

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

cnt = [0]*(10**5+2)
for a in A:
    cnt[a] += 1
ans = []
for a in A:
    if a == 0:
        ans.append(cnt[a] +cnt[a+1])
    else:
        ans.append(cnt[a-1] + cnt[a] +cnt[a+1])
print(max(ans))

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

max_n = max(A,1)
cnt = [0]*max_n
for i in range(max_A):
    for a in A:
        if abs(ai-i)<=1:
            cnt[i] += 1
print(max(cnt))

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

max_n = max(A)
cnt = [0]*max_n
for i in range(1,max_n):
    for a in A:
        if abs(a-i)<=1:
            cnt[i] += 1
print(max(cnt))
Problem p03693 (python)

Fixed submission:
r,g,b = map(int,input().split())

if (100*r + 10*g + b)%4 == 0:
    print("YES")
else:
    print("NO")

Buggy submission (verdict: Runtime Error):
r,g,b = map(int,input()split())

if (100*r + 10*g + b)%4 == 0:
    print("YES")
else:
    print("NO")
Problem p02614 (python)

Fixed submission:
from itertools import product
H, W, K = map(int, input().split())
c = [list(input()) for _ in range(H)]

ans = 0

for row_bit in product(range(2), repeat=H):
    for col_bit in product(range(2), repeat=W):
        count = 0
        for h in range(H):
            for w in range(W):
                if c[h][w] == "#" and (row_bit[h] == 0 and col_bit[w] == 0):
                    count += 1
        if count == K:
            ans += 1


print(ans)

Buggy submission (verdict: Runtime Error):
from itertools import product
H, W, K = map(int, input().split())
c = [list(input()) for _ in range(H)]

ans = 0

for row_bit in product(range(2), repeat=H):
    for col_bit in product(range(2), repeat=H):
        count = 0
        for h in range(H):
            for w in range(W):
                if c[h][w] == "#" and (row_bit[h] == 0 and col_bit[w] == 0):
                    count += 1
        if count == K:
            ans += 1


print(ans)
Problem p02761 (python)

Fixed submission:
import sys 
a = list(map(int,input().split()))

N = a[0]
M = a[1]

b = ['0']*N

for i in range(0,M):
    x = list(map(str,input().split()))
    if b[int(x[0])-1] != '0' and b[int(x[0])-1] != x[1]: #既に与えられたところに違う値
        print('-1')
        sys.exit()
    elif N >= 2 and x[0] == '1' and x[1] == '0': #the first digit is  "0"
        print('-1')
        sys.exit()
    else:
        b[int(x[0])-1] = x[1]

if N != 1 and b[0] == '0':
    b[0] = '1'

ans = ''.join(b)
print(ans)

Buggy submission (verdict: Runtime Error):
import sys 
a = list(map(int,input().split()))

N = a[0]
M = a[1]

b = ['0']*N

for i in range(0,M):
    x = list(map(str,input().split()))
    if b[int(x[0])-1] != '0' and b[int(x[0])-1] != x[1]:
        print('-1')
        sys.exit()
    elif x[0] == '1' and x[1] == '0':
        print('-1')
        sys.exit()
    else:
        b[int(x[0])-1] = x[1]

if b[0] == '0' and b[1] != '0':
    b[0] = '1'

ans = ''.join(b)
print(ans)

Buggy submission (verdict: Runtime Error):
import sys 
a = list(map(int,input().split()))

N = a[0]
M = a[1]

b = ['0']*N

for i in range(0,M):
    x = list(map(str,input().split()))
    if b[int(x[0])-1] != '0' and b[int(x[0])-1] != x[1]:
        print('-1')
        sys.exit()
    elif x[0] == '1' and x[1] == '0':
        print('-1')
        sys.exit()
    else:
        b[int(x[0])-1] = x[1]

if b[0] == '0' and not b[1] == '0':
    b[0] = '1'

ans = ''.join(b)
print(ans)

Buggy submission (verdict: Runtime Error):
import sys 
a = list(map(int,input().split()))

N = a[0]
M = a[1]

b = ['0']*N

for i in range(0,M):
    x = list(map(str,input().split()))
    if b[int(x[0])-1] != '0' and b[int(x[0])-1] != x[1]: #when the space which is tried to enter the number has a different value
        print('-1')
        sys.exit()
    elif x[0] == '1' and x[1] == '0':
        print('-1')
        sys.exit()
    else:
        b[int(x[0])-1] = x[1]

if b[0] == '0' and (int(b[1]) != 0 or int(b[2] != 0) ):
    b[0] = '1'

ans = ''.join(b)
print(ans)
Problem p02898 (python)

Fixed submission:
a = list(map(int,input().split()))
N = a[0]
K = a[1]

b = list(map(int,input().split()))
c = 0
for i in b:
    if i >= K:
        c += 1
print(c)

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

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

for i in range(len(b)):
    for j in range(len(b)):
        if b[i]<b[j]:
            x = b[i]
            b[i] = b[j]
            b[j] = x
c = 0
for k in b:
    if k < K:
        break
    c += 1

print c
Problem p02554 (python)

Fixed submission:

N = int(input())

if N == 1:
    print(0)
    exit()

Z = 10 ** 9 + 7
a = 1
b = 1
c = 1
for n in range(N):
    a *= 10
    b *= 9
    c *= 8

    a = a % Z
    b = b % Z
    c = c % Z

print((a - 2 * b + c) % Z)

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

if N == 1:
    print(0)
    exit()

Z = 10 ** 9 + 7
a = 1
b = 1
c = 1
for n in range(N):
    a *= 10
    b *= 9
    c *= 8

    a = a % Z
    b = b % Z
    c = c % Z

print((a - 2 * b + c) % Z)

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

if N == 1:
    print(0)
    exit()

Z = 10 ** 9 + 7
a = 1
b = 1
c = 1
for n in range(N):
    a *= 10
    b *= 9
    c *= 8

    a = a % Z
    b = b % Z
    c = c % Z

print((a - 2 * b + c) % Z)

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

if N == 1:
    print(0)
    exit()

Z = 10 ** 9 + 7
a = 1
b = 1
c = 1
for n in tqdm(range(N)):
    a *= 10
    b *= 9
    c *= 8

    a = a % Z
    b = b % Z
    c = c % Z

print((a - 2 * b + c) % Z)
Problem p02582 (python)

Fixed submission:
S = input()
c = 0
m = 0
for s in S:
    m = max(c, m)
    if s == "R":
        c += 1
        m = max(c, m)
    else:
        c = 0
print(m)

Buggy submission (verdict: Runtime Error):
S = input()
c = 0
m = 0
if s in S:
  if s == "R":
    c+=1
    m = max(c, m)
  else:
    m = max(c, m)
    c = 0
print(m)
Problem p02683 (python)

Fixed submission:
import itertools
N, M, X = map(int, input().split())
C = []
A = dict()
for i in range(N):
    CA = list(map(int, input().split()))
    C.append(CA[0])
    for j in range(1, M+1):
        if j in A:
            A[j].append(CA[j])
        else:
            A[j] = [CA[j]]

cost = float("inf")

for i in range(1, N+1):
    for pm in itertools.combinations(list(range(1, N+1)), r=i):
        c = 0
        k = dict()
        for p in pm:
            c += C[p-1]

            for m in range(1, M+1):
                if m in k:
                    k[m] += A[m][p - 1]
                else:
                    k[m] = A[m][p - 1]

        if min(k.values()) >= X:
            cost = min(cost, c)


if cost == float("inf"):
    print(-1)
else:
    print(cost)

Buggy submission (verdict: Runtime Error):
import pandas as pd

Buggy submission (verdict: Runtime Error):
import itertools
N, M, X = map(int, input().split())
C = []
A = dict()
for i in range(N):
    CA = list(map(int, input().split()))
    C.append(CA[0])
    for j in range(1, M+1):
        if j in A:
            A[j].append(CA[j])
        else:
            A[j] = [CA[j]]

cost = float("inf")

for i in range(1, N+1):
    for pm in itertools.permutations(list(range(1, N+1)), r=i):
        c = 0
        k = dict()
        for p in pm:
            c += C[p-1]
            if c > cost:
                break

            for m in range(1, M+1):
                if m in k:
                    k[m] += A[m][p - 1]
                else:
                    k[m] = A[m][p - 1]

        if min(k.values()) >= X:
            cost = min(cost, c)


if cost == float("inf"):
    print(-1)
else:
    print(cost)
Problem p02865 (python)

Fixed submission:
N = int(input())

if N % 2 == 0:
    print(N // 2 - 1)
else:
    print((N + 1) // 2 - 1)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
k = max(A)

def pow_k(x, n):
    """
    O(log n)
    """
    if n == 0:
        return 1

    K = 1
    while n > 1:
        if n % 2 != 0:
            K *= x % 998244353
        x *= x % 998244353
        n //= 2

    return K * x % 998244353


R = [0] * (k + 1)
result = 1
for i in A:
    R[i] += 1

if A[0] != 0 or R[0] != 1:
    print(0)
    exit()

for j in range(k + 1):
    result *= pow_k(R[j], R[j + 1])

    if result == 0:
        print(0)
        exit()

print(result % 998244353)

Buggy submission (verdict: Runtime Error):
import numpy as np

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

if A[0] != 0:
    print(0)
    exit()
if A.count(0) != 1:
    print(0)
    exit()

k = max(A)

R = [1]
result = 1


for i in range(k):
    R.append(A.count(i + 1))

for j in range(k):
    if R[j + 1] % 2 == 0:
        result *= (R[j] ** 2) ** (R[j + 1] // 2)
    else:
        result *= R[j] * (R[j] ** 2) ** (R[j + 1] // 2)
    result %= 998244353

    if result == 0:
        print(0)
        exit()

print(result)
Problem p02866 (python)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
k = max(A)

def pow_k(x, n):
    """
    O(log n)
    """
    if n == 0:
        return 1

    K = 1
    while n > 1:
        if n % 2 != 0:
            K *= x % 998244353
        x *= x % 998244353
        n //= 2

    return K * x % 998244353


R = [0] * (k + 1)
result = 1
for i in A:
    R[i] += 1

if A[0] != 0 or R[0] != 1:
    print(0)
    exit()

for j in range(k):
    result *= pow_k(R[j], R[j + 1])

    if result == 0:
        print(0)
        exit()

print(result % 998244353)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
k = max(A)

def pow_k(x, n):
    """
    O(log n)
    """
    if n == 0:
        return 1

    K = 1
    while n > 1:
        if n % 2 != 0:
            K *= x % 998244353
        x *= x % 998244353
        n //= 2

    return K * x % 998244353


R = [0] * (k + 1)
result = 1
for i in A:
    R[i] += 1

if A[0] != 0 and R[0] != 1:
    print(0)
    exit()

for j in range(k + 1):
    result *= pow_k(R[j], R[j + 1])

    if result == 0:
        print(0)
        exit()

print(result % 998244353)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
k = max(A)

def pow_k(x, n):
    """
    O(log n)
    """
    if n == 0:
        return 1

    K = 1
    while n > 1:
        if n % 2 != 0:
            K *= x % 998244353
        x *= x % 998244353
        n //= 2

    return K * x % 998244353

if A[0] != 0:
    print(0)
    exit()
if A.count(0) != 1:
    print(0)
    exit()



R = [1]
result = 1


for i in range(k):
    R.append(A.count(i + 1))
    A.remove(i + 1)

for j in range(k):
    result *= pow_k(R[j], R[j + 1])

    if result == 0:
        print(0)
        exit()

print(result % 998244353)

Buggy submission (verdict: Runtime Error):
import numpy as np

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


def pow_k(x, n):
    """
    O(log n)
    """
    if n == 0:
        return 1

    K = 1
    while n > 1:
        if n % 2 != 0:
            K *= x % 998244353
        x *= x % 998244353
        n //= 2

    return K * x % 998244353

if A[0] != 0:
    print(0)
    exit()
if A.count(0) != 1:
    print(0)
    exit()

k = max(A)

R = [1]
result = 1


for i in range(k):
    R.append(A.count(i + 1))
    A.remove(i + 1)

for j in range(k):
    result *= pow_k(R[j], R[j + 1])

    if result == 0:
        print(0)
        exit()

print(result % 998244353)
Problem p02900 (python)

Fixed submission:
import collections
import fractions
a, b = input().split()
A = int(a)
B = int(b)


def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a


GCB = fractions.gcd(A, B)

C = collections.Counter(prime_factorize(GCB))

print(len(C) + 1)

Buggy submission (verdict: Runtime Error):
import collections
import math
a, b = input().split()
A = int(a)
B = int(b)

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a


GCB = math.gcd(A, B)

C = collections.Counter(prime_factorize(GCB))

print(len(C) + 1)