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

Fixed submission:
from fractions import gcd
from functools import reduce

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

print(reduce(gcd, a))

Buggy submission (verdict: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {
    int n;
    cin >> n;
    int ans, b;
    cin >> ans;
    for(int i = 1; i < n; ++i){
        cin >> b;
        ans = __gcd(ans,b);
    }
    cout << ans << endl;
}

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

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

print(reduce(math.gcd, a))

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

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

print(reduce(fraction.gcd, a))

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

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

print(reduce(fraction.gcd, a))

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

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

print(reduce(math.gcd, a))

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

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

print(reduce(math.gcd, a))

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)

while(a[-1] != 1):
	for i in range(len[a]):
		if a[-i] == 0:
			continue
		else:
			m = a[-i]
			break
	b = []

	for i in range(len(a) - 1):
		b.append(a[i] % m)

	if  max(b) == 0:
		print(m)
		exit()
	else:
		b.append(m)
		a = sorted(b, reverse=True)
		print(b)
print('1')

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)

while(a[-1] != 1):
	for i in range(a):
		if a[-i] == 0:
			continue
		else:
			m = a[-i]
			break
	b = []

	for i in range(len(a) - 1):
		b.append(a[i] % m)

	if  max(b) == 0:
		print(m)
		exit()
	else:
		b.append(m)
		a = sorted(b, reverse=True)
		print(b)
print('1')
Problem p03135 (python)

Fixed submission:
num = list(map(int, input().split()))
ans = num[0] / num[1]
print(ans)

Buggy submission (verdict: Runtime Error):
num = int(input().split())
ans = num[0] / num[1]
print(ans)
Problem p03137 (python)

Fixed submission:
list1 = list(map(int, input().split()))
N = list1[0]
M = list1[1]
list2 = list(map(int, input().split()))
if list1[0] - list1[1] >= 0:
    print(0)
    exit(0)
list2 = sorted(list2, reverse=True)
# print(list2)
list3 = []
for i in range(len(list2) - 1):
    list3.append(list2[i] - list2[i + 1])
list3 = sorted(list3, reverse=True)
# print(list3)
sum = 0
for i in range(N - 1):
    sum = sum + list3.pop(0)
ans = list2[0] - list2[-1] - sum
print(ans)

Buggy submission (verdict: Runtime Error):
list1 = list(map(int, input().split()))
N = list1[0]
M = list1[1]
list2 = list(map(int, input().split()))
list2 = sorted(list2, reverse=True)
# print(list2)
list3 = []
for i in range(len(list2) - 1):
    list3.append(list2[i] - list2[i + 1])
list3 = sorted(list3, reverse=True)
print(list3)
sum = 0
for i in range(N - 1):
    sum = sum + list3.pop(0)
ans = list2[0] - list2[-1] - sum
print(ans)
Problem p03252 (python)

Fixed submission:
s = input()
t = input()

start = [-1]*26
goal = [-1]*26
for i in range(len(s)):
	a = ord(s[i]) - ord('a')
	b = ord(t[i]) - ord('a')
	if start[a] != -1 or goal[b] != -1:
		if start[a] != b or goal[b] != a:
			print('No')
			exit()
	start[a] = b
	goal[b] = a
print('Yes')

Buggy submission (verdict: Runtime Error):
s = input()
t = input()
if s == t:
	pritn('Yes')
	exit()
if len(s) == 1:
	if s != t:
		print('No')
		exit()
for i in range(len(t)):
	for j in range(len(t)):
		if t[i] == t[j] and s[i] != s[j]:
			print('No')
			exit()
print('Yes')

Buggy submission (verdict: Runtime Error):
s = input()
t = input()
if s == t:
	pritn('Yes')
	exit()
if len(s) == 1:
	if s != t:
		print('No')
        exit(
for i in range(len(t)):
	for j in range(len(t)):
		if t[i] == t[j] and s[i] != s[j]:
			print('No')
			exit()
print('Yes')

Buggy submission (verdict: Runtime Error):
s = list(input())
t = list(input())
if s == t:
	pritn('Yes')
	exit()
for i in range(len(t)):
	for j in range(len(t)):
		if t[i] == t[j] and s[i] != s[j]:
			print('No')
			exit()
print('Yes')
Problem p03329 (python)

Fixed submission:
n = int(input())
dp = [n] * (n + 1)
dp[0] = 0
a = [1, 6**1, 6**2, 6**3, 6**4, 6**5, 6**6, 9**1, 9**2, 9**3, 9**4, 9**5]
for i in range(1, n + 1):
    for j in a:
        if i - j >= 0:
            dp[i] = min(dp[i], dp[i - j] + 1)
print(dp[n])

Buggy submission (verdict: Runtime Error):
n = int(input())
memo = [-1] * (n + 1)
def dp(n):
    if n == 0:
        return 0
    if memo[n] != -1:
        return memo[n]
    res = n
    for i in range(7):
        if n >= 6 ** i:
            res = min(res, dp(n - 6 ** i) + 1)
    for j in range(6):
        if n >= 9 ** j:
            res = min(res, dp(n - 9 ** j) + 1)
    memo[n] = res
    return memo[n]

print(dp(n))
Problem p03804 (python)

Fixed submission:
n, m = map(int, input().split())
A = []
B = []
for i in range(n):
    A.append(input())
for i in range(m):
    B.append(input())
if m > n:
    print('No')
    exit(0)
for j in range(n - m + 1):
    for i in range(n - m + 1):
        flag = 1
        for k in range(m):
            if A[j + k][i: i + m] != B[k]:
                flag = 0
                break
        if flag == 1:
            print('Yes')
            exit(0)
print('No')

Buggy submission (verdict: Runtime Error):
n, m = list(map(int, input().split()))
A = []
B = []
for i in range(n):
    A.append([input()])
for i in range(m):
    B.append([input()])
if m > n:
    print('No')
    exit(0)
for j in range(n - m + 2):
    for i in range(n - m + 2):
        if A[j][i: i + m] == B[0][:]:
            for k in range(m):
                if A[j + k][i: i + m] == B[k][:]:
                    flag = 1
                    continue
                flag = 0
                break
            if flag == 1:
                print('Yes')
                exit(0)
print('No')

Buggy submission (verdict: Runtime Error):
n, m = list(map(int, input().split()))
A = []
B = []
for i in range(n):
    A.append([input()])
for i in range(m):
    B.append([input()])
if m > n:
    print('No')
    exit(0)
for j in range(n - m + 1):
    for i in range(n - m + 1):
        if A[j][i:] == B[j][:]:
            for k in range(m - 1):
                if A[j + k][i:] == B[j + k][:]:
                    flag = 1
                    continue
                flag = 0
                break
            if flag == 1:
                print('Yes')
                exit(0)
print('No')
Problem p03834 (python)

Fixed submission:
s = input()
s = s.replace(',', ' ')
print(s)

Buggy submission (verdict: Runtime Error):
s = input()$
s = s.replace(',', ' ')$
print(s)
Problem p02781 (python)

Fixed submission:
n = int(input())
k = int(input())
m = len(list(str(n)))
n0 = list(str(n))
for i in range(m):
    n0[i] = int(n0[i])
ans = 0
comb = 1
if k < m:
    for j in range(k):
        comb *= (m-1-j)
        comb //= (j+1)
    ans += comb*(9**k)
#print(ans,k,m)
if k == 1:
    ans += n0[0]
elif k == 2:
    if m >= 2:
        ans += (n0[0]-1)*9*(m-1)
        c = 1
        while n0[c] == 0 and c < m-1:
            c += 1
        if n0[c] > 0:
            ans += n0[c]
            ans += 9*(m-c-1)
    else:
        ans = 0
else:
    if m >= 3:
        ans += (n0[0]-1)*9*9*(m-1)*(m-2)//2
        c = 1
        while n0[c] == 0 and c <= m-2:
            c += 1
        if c < m-1:
            ans += (n0[c]-1)*9*(m-c-1)
            ans += 9*9*(m-c-1)*(m-c-2)//2
            c1 = c+1
            while n0[c1] == 0 and c1 < m-1:
                c1 += 1
            if n0[c1] > 0:
                ans += n0[c1]
                ans += 9*(m-c1-1)
    else:
        ans = 0
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
k = int(input())
m = len(list(str(n)))
n0 = list(str(n))
for i in range(m):
    n0[i] = int(n0[i])
ans = 0
comb = 1
if k < m:
    for j in range(k):
        comb *= (m-1-j)
        comb //= (j+1)
    ans += comb*(9**k)
#print(ans,k,m)
if k == 1:
    ans += n0[0]
elif k == 2:
    if m >= 2:
        ans += (n0[0]-1)*9*(m-1)
        c = 1
        while n0[c] == 0 and c < m-1:
            c += 1
        if n0[c] > 0:
            ans += n0[c]
            ans += 9*(m-c-1)
    else:
        ans = 0
else:
    if m >= 3:
        ans += (n0[0]-1)*9*9*(m-1)*(m-2)//2
        c = 1
        while n0[c] == 0 and c <= m-2:
            c += 1
        if c < m-1:
            ans += (n0[c]-1)*9*(m-c-1)
            ans += 9*9*(m-c-1)*(m-c-2)//2
            c1 = c+1
            while n0[c1] == 0 and c < m-1:
                c1 += 1
            if n0[c1] > 0:
                ans += n0[c1]
                ans += 9*(m-c1-1)
    else:
        ans = 0
print(ans)
Problem p02925 (python)

Fixed submission:
from collections import deque
n = int(input())
a = []
for i in range(n):
    a1 = list(map(int,input().split()))
    a.append(a1)
l = [[[] for i in range(n)] for i in range(n)]
c = 0
day = 0
for i in range(n):
    ap = [i,a[i][0]-1]
    ap.sort()
    for j in range(1,n-1):
        p = [i,a[i][j]-1]
        p.sort()
        l[ap[0]][ap[1]].append(p)
        ap = p
rl = [[0 for i in range(n)] for i in range(n)]
dl = [[0 for i in range(n)] for i in range(n)]
d = deque()
for i in range(n):
    for j in range(n):
        if i < j:
            if len(l[i][j]) > 0:
                for k in l[i][j]:
                    rl[k[0]][k[1]] += 1
#print(rl)
for i in range(n):
    for j in range(n):
        if i < j:
            if rl[i][j] == 0:
                d.append([[i,j],0])
al = []
key = 0
#print(l)
if len(d) == 0:
    key = 1
while len(d):
    #print(d)
    now,day = d.pop()
    day += 1
    if len(l[now[0]][now[1]]) == 0:
        al.append(day)
    else:
        for i in l[now[0]][now[1]]:
            if rl[i[0]][i[1]] == 1:
                rl[i[0]][i[1]] -= 1
                d.append([i,max(day,dl[i[0]][i[1]])])
            else:
                rl[i[0]][i[1]] -= 1
                dl[i[0]][i[1]] = max(day,dl[i[0]][i[1]])
    if day > n*(n-1)//2:
        key = 1
        break
md = 0
for i in range(n):
    md += sum(rl[i])
if key == 1 or md > 0:
    print(-1)
else:
    print(max(al))

Buggy submission (verdict: Runtime Error):
from collections import deque
n = int(input())
a = []
for i in range(n):
    a1 = list(map(int,input().split()))
    a.append(a1)
l = [[[] for i in range(n)] for i in range(n)]
c = 0
day = 0
for i in range(n):
    ap = [i,a[i][0]-1]
    ap.sort()
    for j in range(1,n-1):
        p = [i,a[i][j]-1]
        p.sort()
        l[ap[0]][ap[1]].append(p)
        ap = p
rl = [[[0,0] for i in range(n)] for i in range(n)]
d = deque()
for i in range(n):
    for j in range(n):
        if i < j:
            if len(l[i][j]) > 0:
                for k in l[i][j]:
                    rl[k[0]][k[1]][0] += 1
#print(rl)
for i in range(n):
    for j in range(n):
        if i < j:
            if rl[i][j][0] == 0:
                d.append([[i,j],0])
al = []
key = 0
#print(l)
if len(d) == 0:
    key = 1
while len(d):
    #print(d)
    now,day = d.pop()
    day += 1
    if len(l[now[0]][now[1]]) == 0:
        al.append(day)
    else:
        for i in l[now[0]][now[1]]:
            if rl[i[0]][i[1]][0] == 1:
                rl[i[0]][i[1]][0] -= 1
                d.append([i,max(day,rl[i[0]][i[1]][1])])
            else:
                rl[i[0]][i[1]][0] -= 1
                rl[i[0]][i[1]][1] = max(day,rl[i[0]][i[1]][1])
    if day > n*(n-1)//2:
        key = 1
        break
md = 0
for i in range(n):
    md += sum(rl[i][0])
if key == 1 or md > 0:
    print(-1)
else:
    print(max(al))
Problem p02935 (python)

Fixed submission:
n = int(input())
v = list(map(int,input().split()))
v.sort()
ans = v[0]
if n > 1:
    for i in range(1,n):
        ans = (ans+v[i])/2
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
v = list(map(int,input().split()))
v.sort()
v = list(set(v))
ans = v[0]
if len(v) > 1:
    for i in range(n-1):
        ans = (ans + v[i+1])/2
print(ans)
Problem p02948 (python)

Fixed submission:
import heapq
n,m = map(int,input().split())
j = []
for i in range(n):
    j1 = list(map(int,input().split()))
    j.append(j1)
j.sort(key=lambda x:x[1],reverse=True)
j.sort(key=lambda x:x[0])
day = 1
i = 0
q = []
ans = 0
count = 0
while day <= m and i < n:
    if day == j[i][0]:
        heapq.heappush(q,-(j[i][1]))
        ans = ans + heapq.heappop(q)*(-1)
        day = day + 1
        i = i + 1
    elif day > j[i][0]:
        heapq.heappush(q,-(j[i][1]))
        i = i + 1
        count = count + 1
    else:
        day = day + 1
        if count > 0:
            ans = ans + heapq.heappop(q)*(-1)
            count = count - 1
while day <= m and count > 0:
        ans = ans + heapq.heappop(q)*(-1)
        day = day + 1
        count = count - 1
print(ans)

Buggy submission (verdict: Runtime Error):
import heapq
n,m = map(int,input().split())
j = []
for i in range(n):
    j1 = list(map(int,input().split()))
    j.append(j1)
j.sort(key=lambda x:x[1],reverse=True)
j.sort(key=lambda x:x[0])
day = 1
i = 0
q = []
ans = 0
count = 0
while day <= m and i < n:
    if day == j[i][0]:
        heapq.heappush(q,-(j[i][1]))
        ans = ans + heapq.heappop(q)*(-1)
        day = day + 1
        i = i + 1
    elif day > j[i][0]:
        heapq.heappush(q,-(j[i][1]))
        i = i + 1
        count = count + 1
    else:
        day = day + 1
        if count > 0:
            ans = ans + heapq.heappop(q)*(-1)
while day <= m and count > 0:
        ans = ans + heapq.heappop(q)*(-1)
        day = day + 1
        count = count - 1
print(ans)
Problem p02954 (python)

Fixed submission:
def aaa(n,m):
    count1 = 1
    count2 = 1
    if n % 2 == 1:
        count1 = count1 + n//2
        count2 = count2 + n//2 + 1
    else:
        count1 = count1 + n//2
        count2 = count2 + n//2
    if m % 2 == 1:
        count1 = count1 + m//2 + 1
        count2 = count2 + m//2
    else:
        count1 = count1 + m//2
        count2 = count2 + m//2
    l3 = [count1,count2]
    return l3
s = list(input())
n = len(s)
j = 0
a = 0
b = 0
l = [0]*n
for i in range(len(s)):
    if s[i] == "R" and j == 0:
        a = a + 1
    elif s[i] == "R" and j == 1:
        l[c-1] = aaa(a-1,b)[0]
        l[c] = aaa(a-1,b)[1]
        a = 1
        b = 0
        j = 0
    elif s[i] == "L" and j == 0:
        j = 1
        c = i
    elif s[i] == "L" and j == 1:
        b = b + 1
l[c-1] = aaa(a-1,b)[0]
l[c] = aaa(a-1,b)[1]
for x in l:
    print(x,end=" ")

Buggy submission (verdict: Runtime Error):
def aaa(n,m):
    count1 = 1
    count2 = 1
    if n % 2 == 1:
        count1 = count1 + n//2
        count2 = count2 + n//2 + 1
    else:
        count1 = count1 + n//2
        count2 = count2 + n//2
    if m % 2 == 1:
        count1 = count1 + m//2 + 1
        count2 = count2 + m//2
    else:
        count1 = count1 + m//2
        count2 = count2 + m//2
    l3 = [count1,count2]
    l1 = l1 + l3 + l2
    return l1
s = list(input())
j = 0
a = 0
b = 0
l = []
for i in range(len(s)):
    if s[i] == "R" and j == 0:
        a = a + 1
    elif s[i] == "R" and j == 1:
        l = l + aaa(a-1,b-1)
        a = 1
        b = 0
        j = 0
    else:
        b = b + 1
        j = 1
l = l + aaa(a-1,b-1)
for x in l:
    print(x,end=" ")
Problem p02990 (python)

Fixed submission:
n,k = map(int,input().split())
mod = 10**9 + 7
combo1 = 1
combo2 = 1
p = 0
for i in range(1,k+1):
    if n-k >= i - 1:
        if i > 1:
            combo1 = combo1*(k-i+1)//(i-1)
            combo2 = combo2*(n-k+2-i)//i
        else:
            combo1 = 1
            combo2 = combo2*(n-k+2-i)//i
        print((((combo1)%mod)*((combo2)%mod))%mod)
        #print(combo1,combo2)
    else:
        p = i
        break
if p > 0:
    for i in range(k-p+1):
        print(0)

Buggy submission (verdict: Runtime Error):
n,k = map(int,input().split())
mod = 10**9 + 7
combo1 = 1
combo2 = 1
p = 0
for i in range(1,k+1):
    if n-k >= i - 1:
        if i > 1:
            combo1 = int(combo1*(k-i+1)/(i-1))
            combo2 = int(combo2*(n-k+2-i)/i)
        else:
            combo1 = 1
            combo2 = int(combo2*(n-k+2-i)/i)
        print((((combo1)%mod)*((combo2)%mod))%mod)
        #print(combo1,combo2)
    else:
        p = i
        break
if p > 0:
    for i in range(k-p):
        print(0)

Buggy submission (verdict: Runtime Error):
import copy
n,k = map(int,input().split())
if k*2 - 1 <= n:
    for i in range(k):
        count1 = 1
        count2 = 1
        count3 = 1
        count4 = 1
        p = k - 1
        q = n - k + 1
        for j in range(1,i+1):
            count1 = copy.copy(count1*p)
            count3 = (count3*j)
            p = p - 1
        for j in range(1,i+2):
            count2 = copy.copy(count2*q)
            count4 = count4*j
            q = q - 1
        a = int(count1/count3)
        b = int(count2/count4)
        ans = (a*b)%(10**9+7)
        print(ans)
else:
    for i in range(n-k+1):
        count1 = 1
        count2 = 1
        count3 = 1
        count4 = 1
        p = k - 1
        q = n - k + 1
        for j in range(1,i+1):
            count1 = copy.copy(count1*p)
            count3 = (count3*j)
            p = p - 1
        for j in range(1,i+2):
            count2 = copy.copy(count2*q)
            count4 = count4*j
            q = q - 1
        a = int(count1/count3)
        b = int(count2/count4)
        ans = (a*b)%(10**9+7)
        print(ans)
Problem p03038 (python)

Fixed submission:
n,m = map(int,input().split())
a = list(map(int,input().split()))
l = []
for i in range(m):
    bc = list(map(int,input().split()))
    l.append(bc)
l.sort(key=lambda x:x[1],reverse=True)
a.sort()
b = 0
for i in range(m):
    count = 0
    while a[b] < l[i][1] and count < l[i][0]:
        a[b] = l[i][1]
        b = b + 1
        count = count + 1
        if b == n:
            break
    if b == n:
        break
    else:
        if i < m-1:
            if a[b] >= l[i+1][1]:
                break
print(sum(a))

Buggy submission (verdict: Runtime Error):
n,m = map(int,input().split())
a = list(map(int,input().split()))
l = []
for i in range(m):
    bc = list(map(int,input().split()))
    l.append(bc)
l.sort(key=lambda x:x[1],reverse=True)
a.sort()
b = 0
for i in range(m):
    count = 0
    while a[b] < l[i][1] and count < l[i][0]:
        a[b] = l[i][1]
        b = b + 1
        count = count + 1
    if i < m-1:
        if a[b] >= l[i+1][1]:
            break
print(sum(a))
Problem p03073 (python)

Fixed submission:
s = list(input())
count = 0
n = len(s)
if n % 2 == 0:
    for i in range(0,int(n/2)):
        if s[(2*i)+1] == "0":
            count = count + 1
    for j in range(0,int(n/2)):
        if s[2*j] == "1":
            count = count + 1
else:
    for i in range(0,int((n-1)/2)+1):
        if s[2*i] == "0":
            count = count + 1
    for j in range(0,int(((n-1)/2))):
        if s[2*j + 1] == "1":
            count = count + 1
count2 = n - count
print(min(count,count2))

Buggy submission (verdict: Runtime Error):
 = list(input())
count = 0
n = len(s)
if n % 2 == 0:
    for i in range(0,int((n/2)-1)):
        if s[(2*i)+1] == "0":
            count = count + 1
    for i in range(0,int((n/2)-1)):
        if s[2*i] == "1":
            count = count + 1
else:
    for i in range(0,int((n-1)/2)):
        if s[2*i] == "0":
            count = count + 1
    for i in range(0,int(((n-1)/2)-1)):
        if s[2*i + 1] == "1":
            count = count + 1
count2 = n - count
print(min(count,count2))
Problem p03127 (python)

Fixed submission:
from fractions import gcd
n = int(input())
a = list(map(int,input().split()))
g = gcd(a[0],a[1])
for i in range(n-2):
    g = gcd(g,a[i+2])
print(g)

Buggy submission (verdict: Runtime Error):
import math
n = int(input())
a = list(map(int,input().split()))
g = math.gcd(a[0],a[1])
for i in range(n-2):
    g = math.gcd(g,a[i+2])
print(g)
Problem p03041 (python)

Fixed submission:
# -*- coding: utf-8 -*-

def main():
    _, K = map(int, input().split(' '))
    S = input()

    print(S[:K - 1] + S[K - 1].lower() + S[K:])


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

def main():
    _, K = map(int, input().split(' '))
    S = input()

    S[K - 1] = S[K - 1].lower()

    print(S)


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

Fixed submission:
def gcd(a,b):
    if b == 0:
        return a
    elif a<b:
        return gcd(b,a)
    else:
        return gcd(b, a % b)
a,b=map(int,input().split())
print(a*b//gcd(a,b))

Buggy submission (verdict: Runtime Error):
from math import gcd
a,b=map(int,input().split())
print(a*b//gcd(a,b))
Problem p03013 (python)

Fixed submission:
MOD = 10**9+7
n,m = map(int,input().split())

f = [1,1]
for i in range(2, n+1):
    f.append(f[i-2]+f[i-1])

cur = 0
ans = 1
for i in range(m):
    a = int(input())
    if a==cur:
        print(0)
        break
    ans *= f[a-cur-1]
    ans %= MOD
    cur = a+1
else:
    ans *= f[n-cur]
    ans %= MOD
    print(ans)

Buggy submission (verdict: Runtime Error):
MOD = 10**9+7
n,m = map(int,input().split())

f = [1,1]
for i in range(2, n):
    f.append(f[i-2]+f[i-1])

cur = 0
ans = 1
for i in range(m):
    a = int(input())
    if a==cur:
        print(0)
        exit(0)
    ans *= f[a-cur-1]
    ans %= MOD
    cur = a+1
ans *= f[n-cur]
ans %= MOD
print(ans)
Problem p02689 (python)

Fixed submission:
from collections import defaultdict

n, m = list(map(int, input().split(' ')))
hn = list(map(int, input().split(' ')))
abm = [None] * m

d = defaultdict(list)
for i in range(m):
    v = list(map(int, input().split(' ')))
    d[v[0]].append(v[1])
    d[v[1]].append(v[0])
    

count = 0

for i in range(1, n + 1):
    cand = d.get(i)
    if cand is None:
        count += 1
        continue
    ok = True
    for c in cand:
        if hn[i - 1] <= hn[c - 1]:
            ok = False
            break
    if ok:
        count += 1
print(count)

Buggy submission (verdict: Runtime Error):
n, m = list(map(int, input().split(' ')))
hn = list(map(int, input().split(' ')))
abm = [None] * m

d = defaultdict(list)
for i in range(m):
    v = list(map(int, input().split(' ')))
    d[v[0]].append(v[1])
    d[v[1]].append(v[0])
    

count = 0

for i in range(1, n + 1):
    cand = d.get(i)
    if cand is None:
        count += 1
        continue
    ok = True
    for c in cand:
        if hn[i - 1] <= hn[c - 1]:
            ok = False
            break
    if ok:
        count += 1
print(count)
Problem p02695 (python)

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

aq = [None] * q
bq = [None] * q
cq = [None] * q
dq = [None] * q
for i in range(q):
    aq[i], bq[i], cq[i], dq[i] = list(map(int, input().split(' ')))

result = 0

def dfs(i, ary):
    global result
    if i == n:
        val = 0
        for j in range(q):
            if ary[bq[j] - 1] - ary[aq[j] - 1] == cq[j]:
                val += dq[j]
        if result < val:
            result = val
    else:
        if ary == []:
            for c in range(1, m + 1):
                dfs(i + 1, [c])
        else:
            l = ary[-1]
            for c in range(l, m + 1):
                dfs(i + 1, ary + [c])

dfs(0, [])

print(result)

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

aq = [None] * q
bq = [None] * q
cq = [None] * q
dq = [None] * q
for i in range(q):
    aq[i], bq[i], cq[i], dq[i] = list(map(int, input().split(' ')))

result = 0

def dfs(i, ary):
    global result
    if i == n:
        val = 0
        for j in range(q):
            if ary[bq[j] - 1] - ary[aq[j] - 1] == cq[j]:
                val += dq[i]
        if result < val:
            result = val
    else:
        if ary == []:
            for c in range(1, m + 1):
                dfs(i + 1, [c])
        else:
            l = ary[-1]
            for c in range(l, m + 1):
                dfs(i + 1, ary + [c])

dfs(0, [])

print(result)