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

Fixed submission:
n,m = map(int,input().split())
ans = 0
import heapq
g = [[] for i in range(100000)]
for i in range(n):
    a,b = map(int,input().split())
    a -= 1
    g[a].append(-b)
for i in range(100000):
    heapq.heapify(g[i])
p = []
heapq.heapify(p)
for i in range(m):
    if len(g[i]) != 0:
        heapq.heappush(p,[heapq.heappop(g[i]),i])
    if len(p) != 0:
        x = heapq.heappop(p)
        ans += -x[0]
        if len(g[x[1]]) != 0:
            heapq.heappush(p,[heapq.heappop(g[x[1]]),x[1]])            
print(ans)

Buggy submission (verdict: Runtime Error):
n,q = map(int,input().split())
s = [0 for i in range(n-1)]
for i in range(n-1):
    a,b = map(int,input().split())
    s[i] = [a,b]
s.sort()
ans = [-1 for i in range(n)]
for i in range(n-1):
    ans[s[i][1]-1] = s[i][0]-1
count = [0 for i in range(n)]
for i in range(q):
    p,x = map(int,input().split())
    count[p-1] += x
ans1 = [0 for i in range(n)]
ans1[0] = count[0]
for i in range(1,n):
    ans1[i] = ans1[ans[i]] + count[i]
for i in range(n):
    print(ans1[i])
Problem p02954 (python)

Fixed submission:
S = input()
s = list(S)
p = []
q = []
ans = [0 for i in range(len(s))]
for i in range(len(s)-1):
    if s[i] == 'L' and s[i+1] == 'R':
        p.append(i)
for i in range(len(s)-1):
    if s[i] == 'R' and s[i+1] == 'L':
        q.append(i)
if len(p) > 0:
    if (p[0]-q[0])%2 == 0:
        ans[q[0]] = -(-(p[0]+1)//2)
    else:
        ans[q[0]] = (p[0]+1)//2
    ans[q[0]+1] = p[0]+1-ans[q[0]]
    for i in range(len(p)-1):
        if (p[i+1]-q[i+1])%2 == 0:
            ans[q[i+1]] = -(-(p[i+1]-p[i])//2)
        else:
            ans[q[i+1]] = (p[i+1]-p[i])//2
        ans[q[i+1]+1] = p[i+1]-p[i]-ans[q[i+1]]
    if (len(s)+1-q[-1])%2 == 0:
        ans[q[-1]] = -(-(len(s)-p[-1]-1)//2)
    else:
        ans[q[-1]] = (len(s)-p[-1]-1)//2
    ans[q[-1]+1] = len(s) - p[-1] -1 - ans[q[-1]]
else:
    if (len(s)+1-q[-1])%2 == 0:
        ans[q[-1]] = -(-(len(s))//2)
    else:
        ans[q[-1]] = (len(s))//2
    ans[q[-1]+1] = len(s) - ans[q[-1]]
for i in range(len(ans)):
    print(ans[i],end=' ')

Buggy submission (verdict: Runtime Error):
S = input()
s = list(S)
p = []
q = []
ans = [0 for i in range(len(s))]
for i in range(len(s)-1):
    if s[i] == 'L' and s[i+1] == 'R':
        p.append(i)
for i in range(len(s)-1):
    if s[i] == 'R' and s[i+1] == 'L':
        q.append(i)
if (p[0]-q[0])%2 == 0:
    ans[q[0]] = -(-(p[0]+1)//2)
else:
    ans[q[0]] = (p[0]+1)//2
ans[q[0]+1] = p[0]+1-ans[q[0]]
for i in range(len(p)-1):
    if (p[i+1]-q[i+1])%2 == 0:
        ans[q[i+1]] = -(-(p[i+1]-p[i])//2)
    else:
        ans[q[i+1]] = (p[i+1]-p[i])//2
    ans[q[i+1]+1] = p[i+1]-p[i]-ans[q[i+1]]
if (p[-1]-q[-1])%2 == 0:
    ans[q[-1]] = -(-(len(s)-p[-1]-1)//2)
else:
    ans[q[-1]] = (len(s)-p[-1]-1)//2
ans[q[-1]+1] = len(s) - p[-1] -1 - ans[q[-1]]
for i in range(len(ans)):
    print(ans[i],end=' ')

Buggy submission (verdict: Runtime Error):
S = input()
s = list(S)
p = []
q = []
ans = [0 for i in range(len(s))]
for i in range(len(s)-1):
    if s[i] == 'L' and s[i+1] == 'R':
        p.append(i)
for i in range(len(s)-1):
    if s[i] == 'R' and s[i+1] == 'L':
        q.append(i)
if (p[0]-q[0])%2 == 0:
    ans[q[0]] = -(-(p[0]+1)//2)
else:
    ans[q[0]] = (p[0]+1)//2
ans[q[0]+1] = p[0]+1-ans[q[0]]
for i in range(len(p)-1):
    if (p[i+1]-q[i+1])%2 == 0:
        ans[q[i+1]] = -(-(p[i+1]-p[i])//2)
    else:
        ans[q[i+1]] = (p[i+1]-p[i])//2
    ans[q[i+1]+1] = p[i+1]-p[i]-ans[q[i+1]]
if (p[-1]-q[-1])%2 == 0:
    ans[q[-1]] = -(-(len(s)-p[-1]-1)//2)
else:
    ans[q[-1]] = (len(s)-p[-1]-1)//2
ans[q[-1]+1] = len(s) - p[-1] -1 - ans[q[-1]]
print(ans)
Problem p02987 (python)

Fixed submission:
S = input()
s = list(S)
s.sort()
if s[0] == s[1] and s[2] == s[3] and s[1] != s[2] :
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
n,m = map(int,input().split())
a = []
mod = 10**9+7
for i in range(m):
    b = int(input())
    a.append(b)
d = [0 for i in range(n+1)]
d[0] = 0
d[1] = 1
d[2] = 2
for i in range(3,n+1):
    d[i] = d[i-1] + d[i-2]
ans = 1
if a[0] == 1:
    ans = 1
else:
    ans = ans*d[a[0]-1]%mod
for i in range(m-1):
    ans = ans*d[a[i+1]-a[i]-2]%mod
ans = ans*d[n-a[m-1]-1]%mod
print(ans)
Problem p02989 (python)

Fixed submission:
n =  int(input())
d = list(map(int,input().split()))
d.sort()
kmin = d[n//2-1]
kmax = d[n//2]
print(kmax-kmin)

Buggy submission (verdict: Runtime Error):
n,m = map(int,input().split())
a = []
mod = 10**9+7
d = [0 for i in range(n+1)]
d[0] = 1
d[1] = 1
if n >1 :
    d[2] = 2
for i in range(3,n+1):
    d[i] = d[i-1] + d[i-2]
d.append(0)
if m != 0:
    for i in range(m):
        b = int(input())
        a.append(b)
    ans = 1
    if a[0] == 1:
        ans = 1
    else:
        ans = ans*d[a[0]-1]%mod
    for i in range(m-1):
        ans = ans*d[a[i+1]-a[i]-2]%mod
    ans = ans*d[n-a[m-1]-1]%mod
else:
    ans = d[n]
print(ans)

Buggy submission (verdict: Runtime Error):
n,m = map(int,input().split())
a = []
mod = 10**9+7
for i in range(m):
    b = int(input())
    a.append(b)
d = [0 for i in range(n+1)]
d[0] = 0
d[1] = 1
d[2] = 2
for i in range(3,n+1):
    d[i] = d[i-1] + d[i-2]
ans = 1
if a[0] == 1:
    ans = 1
else:
    ans = ans*d[a[0]-1]%mod
for i in range(m-1):
    ans = ans*d[a[i+1]-a[i]-2]%mod
ans = ans*d[n-a[m-1]-1]%mod
print(ans)
Problem p03011 (python)

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

Buggy submission (verdict: Runtime Error):
n,m = map(int,input().split())
a = []
mod = 10**9+7
d = [0 for i in range(n+1)]
    d[0] = 1
    d[1] = 1
    d[2] = 2
    for i in range(3,n+1):
        d[i] = d[i-1] + d[i-2]
    d.append(0)
if m != 0:
    for i in range(m):
        b = int(input())
        a.append(b)
    ans = 1
    if a[0] == 1:
        ans = 1
    else:
        ans = ans*d[a[0]-1]%mod
    for i in range(m-1):
        ans = ans*d[a[i+1]-a[i]-2]%mod
    ans = ans*d[n-a[m-1]-1]%mod
else:
    ans = d[n]
print(ans)
Problem p03012 (python)

Fixed submission:
n = int(input())
w = list(map(int,input().split()))
ans = 10**9
p = 0
for i in range(n):
    p += w[i]
for i in range(n):
    p -= 2*w[i]
    ans = min(ans,abs(p))
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
w = list(map(int,input().split()))
ans = 10**9+a
p = 0
for i in range(n):
    p += w[i]
for i in range(n):
    p -= 2*w[i]
    ans = min(ans,abs(p))
print(ans)
Problem p03286 (python)

Fixed submission:
N = int(input())
p = []
if N > 0:
    for i in range(500):
        if (2**(2*i)-1)/3 < N <= (2**(2*(i+1))-1)/3:
            q = 2*i + 1
if N < 0:
    for i in range(1,500):
        if -(2**(2*i+1)-2)/3 <= N < -(2**(2*i-1)-2)/3:
            q = 2*i
if N == 0:
    q = 1
def cal(n,i):
    if i % 2 != 0:
        if (2**(i-1)-1)/3 < n <= (2**(i+1)-1)/3:
            p.append(1)
            n = n - (-2)**(i-1)
            i = i-1
            if i > 0:
                cal(n,i)
        else:
            p.append(0)
            i = i-1
            if i > 0:
                cal(n,i)
    elif n == 0:
        p.append(0)
        i = i-1
        if i > 0:
            cal(n,i)
    else:
        if -(2**(i+1)-2)/3 <= n < -(2**(i-1)-2)/3:
            p.append(1)
            n = n - (-2)**(i-1)
            i = i-1
            if i > 0:
                cal(n,i)
        else:
            p.append(0)
            i = i-1
            if i > 0:
                cal(n,i)
            
    return p
ans = cal(N,q)
for i in range(len(ans)):
    ans[i] = str(ans[i])
print(int(''.join(ans)))

Buggy submission (verdict: Runtime Error):
N,K = map(int,input().split())
Alist = list(map(int, input().strip().split()))
p = 1
for i in range(len(Alist)-1):
    if Alist[i]*Alist[i+1] <= 0:
        q = i
        p = p*(-1)
length = 10**10
ans2 = 10**10
if p == 1:
    if Alist[0] > 0:
        ans = Alist[K-1]
    if Alist[0] < 0:
        ans = -Alist[0]
if p == -1:
    for i in range(len(Alist)):
        if i + K - 1 < len(Alist):
            if i + K - 1 == q:
                length = min(abs(Alist[i]),length)
            elif i == q + 1:
                length = min((Alist[i+K-1]),length)
            else:
                length = min(min(abs(Alist[i+K-1]-Alist[i])+abs(Alist[i]),abs(Alist[i+K-1]-Alist[i]),abs(Alist[i+K-1])),length)
    ans = length
for i in range(len(Alist)):
    ans2 = min(ans2,abs(Alist[i]))
if K == 1:
    print(ans2)
else:
    if len(Alist) > 1:
        print(ans)
    if len(Alist) ==1:
        print(Alist[0])
Problem p03317 (python)

Fixed submission:
N, K = map(int,input().split())
Alist = list(map(int,input().split()))
print(-(-(N-1)//(K-1)))

Buggy submission (verdict: Runtime Error):
N, K = map(int,input().split())
Alist = list(map(int,input().split()))
print(-(-N-1//k-1))

Buggy submission (verdict: Runtime Error):
N, K = map(int,input().split())
Alist = list(map(int,input().split()))
n = 0
l = 0
r = o
for i in range(N):
    if Alist[i] == 1:
        p = i
n = n -(-p//(K-1))
n = n -(-(N-p-1)//(K-1))
print(-(-N-1//k-1))
Problem p02623 (python)

Fixed submission:
import bisect

N, M, K = map(int, input().split())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]

da = [0 for _ in range(N+1)]
for i in range(N):
    da[i+1] = da[i] + a[i]
db = [0 for _ in range(M+1)]
for i in range(M):
    db[i+1] = db[i] + b[i]

ans = 0
for i in range(N+1):
    if da[i] > K:
        break
    ans = max(ans, i + bisect.bisect_right(db, K-da[i]) - 1)
print(ans)

Buggy submission (verdict: Runtime Error):
N, M, K = map(int, input().split())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]


ai = 0
bi = 0

dp = [0 for i in range(M+N+1)]

for i in range(1, N+M+1):
    if ai == N:
        res = b[bi]
        bi += 1
    elif bi == M:
        res = a[ai]
        ai += 1
    elif a[ai] == b[bi]:
        ra = ai; rb = bi
        while a[ra] == b[rb]:
            ra += 1
            rb += 1
            if a[ra] < b[rb]:
                res = a[ai]
                ai += 1
                break
            elif a[ra] > b[rb]:
                res = b[bi]
                bi += 1
                break
    elif a[ai] < b[bi]:
        res = a[ai]
        ai += 1
    else:
        res = b[bi]
        bi += 1
    dp[i] = dp[i-1] + res

#print(dp)

import bisect
print(bisect.bisect_right(dp, K)-1)
Problem p02831 (python)

Fixed submission:
import fractions

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

a, b = map(int, input().split())
lcm(a, b)

print(lcm(a, b))

Buggy submission (verdict: Runtime Error):
import math

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

a, b = map(int, input().split())
lcm(a, b)

print(lcm(a, b))
Problem p02862 (python)

Fixed submission:
MAX = 1000010
finv = [0] * MAX
inv = [0] * MAX
def COMinit():
    finv[0] = finv[1] = 1
    inv[1] = 1
    for i in range(2, MAX):
        inv[i] = MOD - inv[MOD%i] * (MOD//i) % MOD
        finv[i] = finv[i-1] * inv[i] % MOD

def COM(n, k):
    res = 1
    for i in range(k):
        res = res * (n-i) % MOD
    return res * finv[k] % MOD

MOD = 10**9+7
x, y = map(int, input().split())
s, t = (-x+2*y)/3, (2*x-y)/3

if s < 0 or t < 0:
    ans = 0
elif not (s.is_integer() and t.is_integer()):
    ans = 0
else:
    s, t = int(s), int(t)
    COMinit()
    ans = COM((s+t), s)

print(ans)

Buggy submission (verdict: Runtime Error):
import math

x, y = map(int, input().split())
m = (2*x-y)/3
n = (-x+2*y)/3

if m.is_integer() == n.is_integer() == True:
    ans = math.factorial(m+n)//(math.factorial(m) * math.factorial(n))
else:
    ans = 0

print(int(ans%(10**9+7)))

Buggy submission (verdict: Runtime Error):
import math

x, y = map(int, input().split())
m = (2*x-y)/3
n = (-x+2*y)/3

if m.is_integer() == n.is_integer() == True:
    ans = math.factorial(m+n)/(math.factorial(m)*math.factorial(n))
else:
    ans = 0

print(int(ans%(10**9+7)))

Buggy submission (verdict: Runtime Error):
import math

x, y = map(int, input().split())
m = (2*x-y)/3
n = (-x+2*y)/3
print(m,n)
if m.is_integer() == n.is_integer() == True:
    ans = math.factorial(m+n)/(math.factorial(m)*math.factorial(n))
else:
    ans = 0

print(int(ans%(10**9+7)))
Problem p02891 (python)

Fixed submission:
import copy

S = list(input())
K = int(input())

def Scount():
    cnt_S = 0
    for i in range(len(S)-1):
        if S[i] == S[i+1]:
            S[i+1] = "1"
            cnt_S += 1
    return cnt_S

T = copy.copy(S)
T.insert(0, T[len(T)-1])
cnt_T = 0
for i in range(len(T)-1):
    if T[i] == T[i+1]:
        T[i+1] = "1"
        cnt_T += 1

if T[i+1] != "1":
    ans = Scount() + (cnt_T * (K-1))
else:
    TT = S * 2
    cnt_T = 0
    for i in range(len(TT)-1):
        if TT[i] == TT[i+1]:
            TT[i+1] = "1"
            cnt_T += 1
    if K % 2 == 0:
        ans = cnt_T * (K // 2)
    else:
        ans = (cnt_T * (K // 2)) + Scount()
print(ans)

Buggy submission (verdict: Runtime Error):
import copy

S = list(input())
K = int(input())

def Scount():
    cnt_S = 0
    for i in range(len(S)-1):
        if S[i] == S[i+1]:
            S[i+1] = "1"
            cnt_S += 1
    return cnt_S

if K == 1:
    ans = Scout()

else:
    T = copy.copy(S)
    T.insert(0, T[len(T)-1])
    cnt_T = 0
    for i in range(len(T)-1):
        if T[i] == T[i+1]:
            T[i+1] = "1"
            cnt_T += 1

    if T[i+1] != "1":
        ans = Scount() + (cnt_T * (K-1))
    else:
        TT = S * 2
        cnt_T = 0
        for i in range(len(TT)-1):
            if TT[i] == TT[i+1]:
                TT[i+1] = "1"
                cnt_T += 1
        if K % 2 == 0:
            ans = cnt_T * K / 2
        else:
            ans = (cnt_T * K // 2) + Scount()

print(ans)

Buggy submission (verdict: Runtime Error):
S = input()
K = int(input())
 
T = list(S * K)
T.append("0")
count = 0
 
for i in range(len(T)-1):
    if T[i] == T[i+1]:
        T[i+1] = "1"
        count += 1

print(count)

Buggy submission (verdict: Runtime Error):
S = input()
K = int(input())
 
T = list(S * K)
T.append("0")
count = 0
 
for i in range(len(T)-1):
    if T[i] == T[i+1]:
        T[i+1] = "1"
        count += 1
 
print(count)

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

T = list(S * K)
T.append("0")
count = 0

for i in range(len(T)-1):
    if T[i] == T[i+1]:
        T[i+1] = "p"
        count += 1

print(count)
Problem p02879 (python)

Fixed submission:

from sys import stdin

A, B = [int(x) for x in stdin.readline().rstrip().split()]
if A<1 or A>9 or B<1 or B>9:
    ans = -1
else:
    ans = A*B

print(ans)

Buggy submission (verdict: Runtime Error):

from sys import stdin

n = int(stdin.readline().rstrip())
l = [1,2,3,4,5,6,7,8,9,2,4,6,8,10,12,14,16,18,3,6,9,12,15,18,21,24,27,4,8,12,16,20,24,28,32,36,5,10,15,20,25,30,35,40,45,6,12,18,24,30,36,42,48,54,7,14,21,28,35,42,49,56,63,64,72,81]
ans = n in l
if ans == True:
    ans = "Yes"
else:
    ans = "No"
print(ans)

Buggy submission (verdict: Runtime Error):

from sys import stdin

A, B = [int(x) for x in stdin.readline().rstrip().split()]
if A<1 or A>9 B<1 or B>9:
    ans = -1
else:
    ans = A*B

print(ans)
Problem p02891 (python)

Fixed submission:

from sys import stdin

S = str(stdin.readline().rstrip())
K = int(stdin.readline().rstrip())

l = len(S)
ans = 0

for i in range(l):
    mo = S[0]*l
    if mo == S:
        ans = l*K//2
        print(ans)
        exit()
    else:
        pass


if S[0] == S[l-1]:
    S2 = S*2
    l2 = len(S2)
    a = 0#位置
    ans2 = 0
    while a < l2-1:
        if S2[a] == S2[a+1]:
            t = S2[a]
            c = 1
            for i in range(1,l2-a):
                if t == S2[a+i]:
                    c += 1
                else:
                    break
            j = c//2
            ans2 += j
            a += c
        else:
            a += 1
    a = 0#位置
    ans1 = 0
    while a < l-1:
        if S[a] == S[a+1]:
            t = S[a]
            c = 1
            for i in range(1,l-a):
                if t == S[a+i]:
                    c += 1
                else:
                    break
            j = c//2
            ans1 += j
            a += c
        else:
            a += 1
    differ = ans2-ans1*2
    ans = differ*(K-1) + ans1*K
else:
    a = 0#位置
    while a < l-1:
        if S[a] == S[a+1]:
            t = S[a]
            c = 1
            for i in range(1,l-a):
                if t == S[a+i]:
                    c += 1
                else:
                    break
            j = c//2
            ans += j
            a += c
        else:
            a += 1

    ans = ans*K

print(ans)

Buggy submission (verdict: Runtime Error):

from sys import stdin

S = str(stdin.readline().rstrip())
K = int(stdin.readline().rstrip())

lenS = len(S)
ans = 0

if S[0] == S[lenS-1]:
    S2 = S*2
    a = 0#位置
    while a < lenS*2-1:
        ans2 = 0
        if S2[a] == S2[a+1]:
            b = 2
            x = S2[a]
            for i in range(1,lenS*2-a):
                try:
                    if x == S2[a+1+i]:
                        b += 1
                    else:
                        break
                except:
                    b = 2
            ans2 += b//2
            a += 1+b
        else:
            a += 1
    a = 0#位置
    while a < lenS-1:
        ans1 = 0
        if S[a] == S[a+1]:
            b = 2
            x = S[a]
            for i in range(1,lenS-a):
                try:
                    if x == S[a+1+i]:
                        b += 1
                    else:
                        break
                except:
                    b = 2
            ans1 += b//2
            a += 1+b
        else:
            a += 1
    differ = ans2-ans1
    ans = differ*(K-1) + ans1*K
else:
    a = 0#位置
    while a < lenS-1:
        if S[a] == S[a+1]:
            b = 2
            x = S[a]
            for i in range(1,lenS-a):
                try:
                    if x == S[a+1+i]:
                        b += 1
                    else:
                        break
                except:
                    b = 2
            ans += b//2
            a += 1+b
        else:
            a += 1
    ans = ans*K


print(ans)
Problem p02623 (python)

Fixed submission:
from collections import deque
n,m,k=map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

a,b=[0],[0]
for i in range(n):
  a.append(a[i]+A[i])
for i in range(m):
  b.append(b[i]+B[i])
ans, j = 0,m
for i in range(n+1):
  if a[i]>k: break
  while b[j] > k-a[i]:
    j -= 1
  ans = max(ans,i+j)
print(ans)

Buggy submission (verdict: Runtime Error):
from collections import deque
n,m,k=map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

a,b=[0],[0]
for i in range(n):
  a.append(a[i]+A[i])
for i in range(m):
  b.append(b[i]+B[i])
ans, j = 0,m
for i in range(N+1):
  if a[i]>k: break
  while b[j] > k-a[i]:
    j -= 1
  ans = max(ans,i+j)
print(ans)
Problem p02629 (python)

Fixed submission:
n=int(input())
from math import log, floor
dic = {}    
for v1,v2 in zip(range(26),'abcdefghijklmnopqrstuvwxyz'):
  dic[v1]=v2
ans = ''
for i in range(1,99):
  if n <= 26**i:
    n-=1
    for j in range(i):
      ans += dic[n%26]
      n //= 26
    break
  else:
    n -= 26**i

print(ans[::-1])

Buggy submission (verdict: Runtime Error):
n=int(input())
from math import log, floor
  
def ten_to_n(X,n):
  if X//n:
    ans = ten_to_n(X//n,n)
    ans.append(X%n)
    return ans
  else:
    return [X%n]
  
dic = {}
l = ten_to_n(n-1,26)
l[-1]+=1
for i in range(len(l)-1,0,-1):
  if l[i] > 25:
    t = l[i]
    l[i-1] += t//26
    l[i] = t%26
#print(l)
    
for v1,v2 in zip(range(1,27),'abcdefghijklmnopqrstuvwxyz'):
  dic[v1]=v2
ans = ''.join([dic[v] for v in l])
print(ans)
Problem p02661 (python)

Fixed submission:
from statistics import median
n=int(input())
A,B=[],[]
for _ in range(n):
  a,b=map(int,input().split())
  A.append(a*2)
  B.append(b*2)
ma,mb = int(median(A)),int(median(B))
#print(ma,mb)
if n%2 == 0:
  print(mb-ma+1)
else:
  print((mb-ma)//2+1)

Buggy submission (verdict: Runtime Error):
from statistics import median
import math
n=int(input())
A,B = [],[]
for _ in range(n):
  a,b=map(int,input().split())
  A.append(a)
  B.append(b)
a1,b2 = int(median(A)),math.ceil(median(B))
b1 = max([B[i] for i,v in enumerate(A) if v == a1])
a2 = max([A[i] for i,v in enumerate(B) if v == b2])
#print(a1,b1,a2,b2)
if b1<a2:
  print(b1-a1+b2-a2+1)
  exit()
print(b2-a1+1)
Problem p02679 (python)

Fixed submission:
from math import gcd
mod = 10**9+7
n=int(input())
r = dict()
zeros = 0
for _ in range(n):
  a,b=map(int,input().split())
  if not any((a,b)):
    zeros+=1
    continue
  if all((a,b)):
    g = gcd(a,b)*(a//abs(a))
  elif a:
    g = a
  else:
    g = b
  p = a//g,b//g
  r[p] = r.get(p,0)+1
ans = 1
done = set()
for (a,b), v in r.items():
  if (b,-a) in done or (-b,a) in done:
    continue
  done.add((a,b))
  w = r.get((b,-a),0)+r.get((-b,a),0)
  ans = ans*(pow(2,v,mod)+pow(2,w,mod)-1)%mod
  
print((ans+zeros+mod-1)%mod)

Buggy submission (verdict: Runtime Error):
from math import gcd
mod=1000000007

n=int(input())
zeros = 0
vec = {}
for _ in range(n):
  a,b=map(int,input().split())
  if a==0 and b==0:
    zeros+=1
    continue
  elif a==0:
    vec[(0,1)]=vec.get((0,1),0)+1
  elif b==0:
    vec[(1,0)]=vec.get((1,0),0)+1
  else:
    g = gcd(a,b)
    a,b= a//g,b//g
    vec[(a,b)]=vec.get((a,b),0)+1
done = set()
total=1
for (a,b),v in vec.items():
  if (-b,a) in done or (b,-a) in done: continue
  done.add((a,b))
  w=vec[(-b,a)]+vec[(b,-a)]
  total *= (pow(2,v,mod)+pow(2,w,mod)-1)
  total %= mod
print((total+zeros-1+mod)%mod)
Problem p02781 (python)

Fixed submission:
N,K=int(input()),int(input())
def f(n,k):
  if k<1: return 1
  if n<10:
    if k<2: return n
    return 0
  d,m=n//10,n%10
  return f(d,k-1)*m+f(d-1,k-1)*(9-m)+f(d,k)
print(f(N,K))

Buggy submission (verdict: Runtime Error):
N,K=map(int,input().split())
def f(n,k):
  if k<1: return 1
  if n<10:
    if k<2: return n
    return 0
  d,m=n//10,n%10
  return f(d,k-1)*m+f(d-1,k-1)*(9-m)+f(d,k)
print(f(N,K))
Problem p03805 (python)

Fixed submission:
n,m=map(int,input().split())
ab = []
for _ in range(m):
  a,b=map(int,input().split())
  a,b=a-1,b-1
  ab.append({a,b})
import itertools

cnt = 0
for v in itertools.permutations(range(1,n)):
  l = 0
  ok = True
  for v2 in v:
    if {l,v2} not in ab:
      ok = False
      break
    l = v2
  if ok:
    #print(v)
    cnt += 1
  
print(cnt)

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
ab = []
for _ in range(n):
  a,b=map(int,input().split())
  a,b=a-1,b-1
  ab.append({a,b})
import itertools

cnt = 0
for v in itertools.permutations(range(1,n)):
  l = 0
  ok = True
  for v2 in v:
    if {l,v2} not in ab:
      ok = False
      break
    l = v2
  if ok:
    #print(v)
    cnt += 1
  
print(cnt)

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
ab = []
for _ in range(n):
  a,b=map(int,input().split())
  a,b=a-1,b-1
  ab.append({a,b})
import itertools

cnt = 0
for v in itertools.permutations(range(1,n)):
  l = 0
  ok = True
  for v2 in v:
    if {l,v2} not in ab:
      ok = False
      break
    l = v2
  if ok:
    print(v)
    cnt += 1
  
print(cnt)

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
ab = []
for _ in range(n):
  a,b=map(int,input().split())
  a,b=a-1,b-1
  ab.append({a,b})
import itertools

cnt = 0
for v in itertools.permutations(range(1,n)):
  l = 0
  ok = True
  for v2 in v:
    if {l,v2} not in ab:
      ok = False
      break
    l = v2
  if ok == True:
    cnt += 1
  
print(cnt)
Problem p02819 (python)

Fixed submission:
x = int(input())
if x == 2:
    print(2)
    exit()
while True:
    flg = 0
    for i in range(2,int(x**0.5)+1):
        if x%i == 0:
            flg += 1
        if i == int(x**0.5) and flg == 0:
            print(x)
            exit()
    x += 1

Buggy submission (verdict: Runtime Error):
x = int(input())
flg = 0
if x == 2:
    print(2)
    exit()
while True:
   for i in range(2,int(x**0.5)+1):
        if x%i == 0:
            flg += 1
        if i == int(x**0.5) and flg == 0:
            print(x)
            exit()
    x += 1