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

Fixed submission:
d = {'SUN':7,'MON':6,'TUE':5,'WED':4,'THU':3,'FRI':2,'SAT':1}
print(d[input()])

Buggy submission (verdict: Runtime Error):
N,M = map(int,input().split())
S = input()
N0 = 2**(N+1).bit_length()
INF = 2**31-1

# k番目の要素をxに更新
def update(k, x, data):
    k += N0-1
    data[k] = x
    while k >= 0:
        k = (k - 1) // 2
        data[k] = min(data[2*k+1], data[2*k+2])

# [l,r)の最小値
def query(l, r, data):
    L = l + N0; R = r + N0
    s = INF
    while L < R:
        if R & 1:
            R -= 1
            s = min(s, data[R-1])

        if L & 1:
            s = min(s, data[L-1])
            L += 1
        L >>= 1; R >>= 1
    return s



data1 = [INF]*(2*N0)
update(0,0,data1)
for n in range(N):
    if S[n+1]=='0':
        update(n+1,query(n-M+1,n+1,data1)+1,data1)

S = S[::-1]
data2 = [INF]*(2*N0)
update(0,0,data2)
for n in range(N):
    if S[n+1]=='0':
        update(n+1,query(n-M+1,n+1,data2)+1,data2)

cost1 = [INF]*(N+1)
cost2 = [INF]*(N+1)
for n in range(N+1):
    cost1[n] = query(n,n+1,data1)
    cost2[n] = query(N-n,N-n+1,data2)

ans = []
cost = 0
for n in range(N+1):
    if cost != cost1[n] and cost1[n]+cost2[n]==cost1[N]:
        ans.append(n)
        cost = cost1[n]
ans = [0]+ans
for i in range(len(ans)-2,-1,-1):
    ans[i+1] = ans[i+1]-ans[i]

ans = ' '.join([str(c) for c in ans[1:]])
if cost2[0]==INF:
    ans = '-1'
print(ans)
Problem p02873 (python)

Fixed submission:
S = input()
N = len(S)+1
a = [-1]*N
l = []
for i in range(1,N-1):
    if S[i-1] == '>' and S[i] == '<':
        a[i] = 0
        l.append(i)

if S[0] == '<':
    a[0] = 0
    l.append(0)
if S[-1] == '>':
    a[N-1] = 0
    l.append(N-1)

for i in l:
    j = i-1
    while 0<=j<=N-2 and S[j]=='>' and S[j-1]=='>':
        a[j] = a[j+1]+1
        j -= 1
    j = i+1
    while 0<=j<=N-3 and S[j]=='<' and S[j+1]=='<':
        a[j] = a[j-1]+1
        j += 1

for i in range(1,N-1):
    if a[i] == -1:
        a[i] = max(a[i-1],a[i+1])+1


if S[0] == '>':
    a[0] = a[1]+1

if S[-1] == '<':
    a[N-1] = a[N-2]+1

print(sum(a))

Buggy submission (verdict: Runtime Error):
S = input()
N = len(S)+1
a = [-1]*N
l = []
for i in range(1,N-1):
    if S[i-1] == '>' and S[i] == '<':
        a[i] = 0
        l.append(i)

if S[0] == '<':
    a[0] = 0
    l.append(0)
if S[-1] == '>':
    a[N-1] = 0
    l.append(N-1)

for i in l:
    j = i-1
    while 0<=j<=N-2 and S[j]=='>' and S[j-1]=='>':
        a[j] = a[j+1]+1
        j -= 1
    j = i+1
    while 0<=j<=N-2 and S[j]=='<' and S[j+1]=='<':
        a[j] = a[j-1]+1
        j += 1

for i in range(1,N-1):
    if a[i] == -1:
        a[i] = max(a[i-1],a[i+1])+1


if S[0] == '>':
    a[0] = a[1]+1

if S[-1] == '<':
    a[N-1] = a[N-2]+1

print(sum(a))

Buggy submission (verdict: Runtime Error):
S = input()
N = len(S)+1
a = [-1]*N
l = []
for i in range(1,N-1):
    if S[i-1] == '>' and S[i] == '<':
        a[i] = 0
        l.append(i)

for i in l:
    j = i-1
    while 0<=j<=N-2 and S[j]=='>' and S[j-1]=='>':
        a[j] = a[j+1]+1
        j -= 1
    j = i+1
    while 0<=j<=N-2 and S[j]=='<' and S[j+1]=='<':
        a[j] = a[j-1]+1
        j += 1

if S[0] == '>':
    a[0] = a[1]+1
else:
    a[0] = 0
if S[-1] == '<':
    a[N-1] = a[N-2]+1
else:
    a[N-1] = 0

for i in range(N):
    if a[i] == -1:
        a[i] = max(a[i-1],a[i+1])+1

print(sum(a))
Problem p02914 (python)

Fixed submission:
N = int(input())
A = list(map(int,input().split()))
ans = 0
for a in A:
    ans ^= a
M = 2**60-1
b = M^ans
for i in range(N):
    A[i] &= b
A.sort(reverse=True)
for i in range(min(60,N)):
    a = A[i]
    if a == 0:
        break
    l = len(bin(a))-3
    for j in range(N):
        if j==i:
            continue
        if A[j]//2**l%2==1:
            A[j] ^= a
        else:
            if i < j:
                break
    A.sort(reverse=True)
s = 0
for a in A:
    s ^= a
ans += 2*s
print(ans)

Buggy submission (verdict: Runtime Error):
ist(map(int,input().split()))

ans = 0
for i in range(N):
    ans ^= A[i]

for i in range(N):
    A[i] = (~ans)&A[i]
    A[i] *= -1

A = [a for a in A if a != 0]
heapq.heapify(A)
b = []

if A:
    M = -heapq.heappop(A)
    while A:
        m = -heapq.heappop(A)
        if len(bin(M)) == len(bin(m)):
            m ^= M
            if m != 0:
                heapq.heappush(A,-m)
        else:
            b.append(M)
            M = m
    b.append(M)

    b = b[::-1]
    ans_ = 0
    for i in range(len(b)):
        M = b[i]
        for j in range(i+1,len(b)):
            m = b[j]
            if len(bin(M))==len(bin(M&m)):
                b[j] ^= M
        ans_ ^= M

    ans += ans_*2
print(ans)

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

ans = 0
for i in range(N):
    ans ^= A[i]

for i in range(N):
    A[i] = (~ans)&A[i]
    A[i] *= -1

A = [a for a in A if a != 0]
heapq.heapify(A)
b = []

M = -heapq.heappop(A)
while A:
    m = -heapq.heappop(A)
    if len(bin(M)) == len(bin(m)):
        m ^= M
        if m != 0:
            heapq.heappush(A,-m)
    else:
        b.append(M)
        M = m
b.append(M)

b = b[::-1]
ans_ = 0
for i in range(len(b)):
    M = b[i]
    for j in range(i+1,len(b)):
        m = b[j]
        if len(bin(M))==len(bin(M&m)):
            b[j] ^= M
    ans_ ^= M

ans += ans_*2
print(ans)

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

ans = 0
for i in range(N):
    ans ^= A[i]

for i in range(N):
    A[i] = (~ans)&A[i]

A = [a for a in A if a != 0]
b = []

for i in range(60):
    M = max(A)
    for i in range(len(A)):
        if len(bin(M))==len(bin(A[i])):
            A[i] ^= M
    b.append(M)    

b = b[::-1]
ans_ = 0
for i in range(len(b)):
    M = b[i]
    for j in range(i+1,len(b)):
        m = b[j]
        if len(bin(M))==len(bin(M&m)):
            b[j] ^= M
    ans_ ^= M

ans += ans_*2
print(ans)
Problem p02955 (python)

Fixed submission:
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors

N,K = map(int,input().split())
A = list(map(int,input().split()))
D = sum(A)
D = make_divisors(D)[::-1]

for d in D:
    a = []
    for i in range(N):
        if A[i]%d != 0:
            a.append(A[i]%d)
    a.sort()
    b = [d-x for x in a]
    b.sort()

    c1 = [0]*(len(a)+1)
    for i in range(len(a)):
        c1[i] = a[i]+c1[i-1]
    c2 = [0]*(len(b)+1)
    for i in range(len(b)):
        c2[i] = b[i]+c2[i-1]

    k = float('inf')
    for i in range(len(a)):
        if c1[i] == c2[len(a)-2-i]:
            k = c1[i]
            break
    if k <= K:
        break
print(d)

Buggy submission (verdict: Runtime Error):
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors

N,K = map(int,input().split())
A = list(map(int,input().split()))
D = sum(A)
D = make_divisors(D)[::-1]

for d in D:
    a = []
    for i in range(N):
        a.append(A[i]%d)
    k = 0
    M = max(a)
    while k <= K and M != 0:
        i = 0
        j = 0
        m = d
        M = 0
        for l in range(N):
            if 0 < a[l] < m:
                m = a[l]
                i = l
        for l in range(N-1,-1,-1)
            if a[l] > M:
                M = a[l]
                j = l
        if m == d:
            break
        if m <= d-M:
            a[i] = 0
            a[j] += m
            a[j] %= d
            k += m
        else:
            a[i] -= d-M
            a[i] %= d
            a[j] = 0
            k += d-M
    if k <= K:
        break

print(d)
Problem p03016 (python)

Fixed submission:
def dot(a,b,m):
    c = [[0,0,0],[0,0,0],[0,0,0]]
    for i in range(3):
        for j in range(3):
            for k in range(3):
                c[i][j] += a[i][k]*b[k][j]
                c[i][j] %= m
    return c
    
def powm(a,n,m):
    if n == 0:
        return [[1,0,0],[0,1,0],[0,0,1]]
    for i in range(3):
        for j in range(3):
            a[i][j] %= m
    r = powm(a,n//2,m)
    if n%2==0:
        return dot(r,r,m)
    else:
        return dot(dot(r,r,m),a,m)

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

a = [[1,0,0],[0,1,0],[0,0,1]]
for d in range(1,19):
    C = min(max(0,(10**d-A-1)//B+1),L)-min(max(0,(10**(d-1)-A-1)//B+1),L)
    a = dot(powm([[pow(10,d,M),1,0],[0,1,B%M],[0,0,1]],C,M),a,M)
ans = (a[0][1]*A%M+a[0][2])%M
print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np
from math import ceil
def powm(a,n,m):
    if n == 0:
        return np.eye(len(a))
    if n%2==0:
        return np.dot(powm(a,n//2,m),powm(a,n//2,m))%m
    else:
        return np.dot(np.dot(powm(a,n//2,m),powm(a,n//2,m)),a)%m

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

C = [0]*18
d = 0
while True:
    C[d] = max(0,min(ceil((10**d-A)/B),L))
    if C[d] == L:
        break
    d += 1

for d in range(17,-1,-1):
    if C[d] != 0:
        C[d] -= C[d-1]

a = np.eye(3)
for d in range(1,18):
    a = np.dot(powm(np.array([[10**d%M,1,0],[0,1,B],[0,0,1]]),C[d],M),a)

ans = int(np.dot(a,np.array([0,A,1]))[0])%M

print(ans)
Problem p03033 (python)

Fixed submission:
from bisect import bisect_left as bisect
N,Q = map(int,input().split())
event = [tuple(map(int,input().split())) for i in range(N)]
D = [int(input()) for i in range(Q)]

event.sort(key=lambda x:x[2])

ans = [-1]*Q
neg = [-1]*Q

for s,t,x in event:
    l = bisect(D,s-x)
    r = bisect(D,t-x)
    t = l
    while t < r:
        if neg[t] == -1:
            ans[t] = x
            neg[t] = r
            t += 1
        else:
            t = neg[t]

for i in range(Q):
    print(ans[i])

Buggy submission (verdict: Runtime Error):
 N,Q = map(int,input().split())
event = []
for i in range(N):
    s,t,x = map(int,input().split())
    event.append((s-x,x,1))
    event.append((t-x,x,-1))

s = set()

event.sort()
event.reverse()


for i in range(Q):
    D = int(input())
    f = False
    while event:
        t,x,e = event.pop()
        if D < t:
            f = True
            break
        if e == 1:
            s.add(x)
        else:
            s.remove(x)
    if len(s)==0:
        print(-1)
    else:
        print(min(s))
    if f:
        if e == 1:
            s.add(x)
        else:
            s.remove(x)

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

event.sort()
event.reverse()


for i in range(Q):
    D = int(input())
    f = False
    while event:
        t,x,e = event.pop()
        if D < t:
            f = True
            break
        if e == 1:
            s.add(x)
        else:
            s.remove(x)
    if len(s)==0:
        print(-1)
    else:
        print(min(s))
    if f:
        if e == 1:
            s.add(x)
        else:
            s.remove(x)

Buggy submission (verdict: Runtime Error):
N,Q = map(int,input().split())
event = []
for i in range(N):
    s,t,x = map(int,input().split())
    event.append((s-x,x,1))
    event.append((t-x,x,-1))

s = set()

event.sort()

for i in range(Q):
    D = int(input())
    while event:
        t,x,f = event.pop(0)
        if D < t:
            break
        if f == 1:
            s.add(x)
        else:
            s.remove(x)
    if len(s)==0:
        print(-1)
    else:
        print(min(s))
    if D < t:
        if f == 1:
            s.add(x)
        else:
            s.remove(x)
Problem p03038 (python)

Fixed submission:
N,M = map(int,input().split())
A = list(map(int,input().split()))
BC = [list(map(int,input().split())) for i in range(M)]
A.sort(key=lambda x:-x)
BC.sort(key=lambda x:x[1])
C = []
while BC and len(C) < N:
    b,c = BC.pop()
    for i in range(b):
        C.append(c)
        if len(C) == N:
            break
C.sort()
ans = 0
while C:
    a = A.pop()
    c = C.pop()
    ans += max(a,c)
ans += sum(A)
print(ans)

Buggy submission (verdict: Runtime Error):
N,M = map(int,input().split())
A = list(map(int,input().split()))
BC = [list(map(int,input().split())) for i in range(M)]
A.sort(key=lambda x:-x)
BC.sort(key=lambda x:x[1])
C = []
while BC and len(B) < N:
    b,c = BC.pop()
    for i in range(b):
        C.append(c)
        if len(C) == N:
            break
C.sort()
ans = 0
while C:
    a = A.pop()
    c = C.pop()
    ans += max(a,c)
ans += sum(A)
print(ans)

Buggy submission (verdict: Runtime Error):
N,M = map(int,input().split())
A = list(map(int,input().split()))
BC = [list(map(int,input().split())) for i in range(M)]
A.sort(key=lambda x:-x)
BC.sort(key=lambda x:x[1])
B = []
while BC:
    b,c = BC.pop()
    while c > 0:
        B.append(b)
        c -= 1
        if len(B) == N:
            break

ans = 0
while B:
    a = A.pop()
    b = B.pop()
    ans += max(a,b)
ans += sum(A)
print(ans)
Problem p03104 (python)

Fixed submission:
from collections import defaultdict
A,B = map(int,input().split())

def count(n,k):
    n = bin(n)[2:]
    n = '0'+n
    res = 0
    if n[-k-1]=='1':
        if k==0:
            res += 1
        else:
            res += (int(n[-1])+1)%2
    if k == 0:
        res = (res+int(n[-2]))%2
    return res

def f(n):
    if n < 0:
        n = 0
    d = defaultdict(lambda:0)
    for k in range(len(bin(n)[2:])):
        d[k] = count(n,k)
    return d

d_a = f(A-1)
d_b = f(B)
ans = ''
for i in range(40):
    ans = str((d_a[i]+d_b[i])%2) + ans
ans = int(ans,2)
print(ans)

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

def count(n,k):
    n = bin(n)[2:]
    n = '0'+n
    res = 0
    if n[-k-1]=='1':
        if k==0:
            res += 1
        else:
            res += (int(n[-1])+1)%2
    if k == 0:
        res = (res+int(n[-2]))%2
    return res

def f(n):
    d = defaultdict(lambda:0)
    for k in range(len(bin(n)[2:])):
        d[k] = count(n,k)
    return d

d_a = f(A-1)
d_b = f(B)
ans = ''
for i in range(40):
    ans = str((d_a[i]+d_b[i])%2) + ans
ans = int(ans,2)
print(ans)
Problem p03127 (python)

Fixed submission:
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a
N = int(input())
A = list(map(int,input().split()))
ans = A[0]
for i in range(1,N):
    ans = gcd(ans,A[i])
print(ans)

Buggy submission (verdict: Runtime Error):
from math import gcd
N = int(input())
A = list(map(int,input().split()))
ans = A[0]
for i in range(N):
    ans = gcd(ans,A[i])
print(ans)

Buggy submission (verdict: Runtime Error):
from scipy import gcd
N = int(input())
A = list(map(int,input().split()))
ans = A[0]
for i in range(N):
    ans = gcd(ans,A[i])
print(ans)

Buggy submission (verdict: Runtime Error):
from math import gcd
N = int(input())
A = list(map(int,input().split()))
ans = A[0]
for i in range(N):
    ans = gcd(ans,A[i])
print(ans)
Problem p03327 (python)

Fixed submission:
n = int(input())
if n > 999:
    print("ABD")
else:
    print("ABC")

Buggy submission (verdict: Runtime Error):
inf = 1000*500*500
D = []
c = []
d = {}
N,C = map(int,input().split())
for i in range(C):
    D.append(list(map(int,input().split())))
for i in range(N):
    c.append(list(map(int,input().split())))

for C1 in range(C):
    for C2 in range(C):
        for C3 in range(C):
            if C1 != C2 and C2 != C3 and C3 != C1:
                d[(C1+1,C2+1,C3+1)]=0
            else:
                d[C1+1,C2+1,C3+1]=inf

for i in range(N):
    for j in range(N):
        for C1 in range(C):
            for C2 in range(C):
                for C3 in range(C):
                    if (i+j)%3==0:
                        d[(C1+1,C2+1,C3+1)]+=D[c[i][j]-1][C1]
                    elif (i+j)%3==1:
                        d[(C1+1,C2+1,C3+1)]+=D[c[i][j]-1][C2]
                    else:
                        d[(C1+1,C2+1,C3+1)]+=D[c[i][j]-1][C3]

l = []
for x in d:
    l.append(d[x])
print(min(l))
Problem p03332 (python)

Fixed submission:
N,A,B,K = map(int,input().split())
n = 0
MOD = 998244353
def egcd(a, b):
    if a == 0:
        return (b, 0, 1)
    else:
        g, y, x = egcd(b % a, a)
        return (g, x - (b // a) * y, y)

def modinv(a, m):
    g, x, y = egcd(a, m)
    if g != 1:
        raise Exception('modular inverse does not exist')
    else:
        return x % m


memo = [0]*(N+1)
memo[0] = memo[N] = 1
for k in range(1,N//2+1):
  v = memo[k-1]*(N-k+1)*modinv(k,MOD)
  v %= MOD
  memo[k] = memo[N-k] = v
for i in range(N+1):
    j = K-A*i
    if j < 0:
        break
    if j%B==0 and j/B <= N:
        j //= B
        n+=memo[i]*memo[j]
        n%=998244353
print(n%998244353)

Buggy submission (verdict: Runtime Error):
N,A,B,K = map(int,input().split())
n = 0
MOD = 998244353
def egcd(a, b):
    if a == 0:
        return (b, 0, 1)
    else:
        g, y, x = egcd(b % a, a)
        return (g, x - (b // a) * y, y)

def modinv(a, m):
    g, x, y = egcd(a, m)
    if g != 1:
        raise Exception('modular inverse does not exist')
    else:
        return x % m


memo = [0]*(N+1)
memo[0] = memo[N] = 1
for k in range(1,N//2+1):
  v = memo[k-1]*(N-k+1)*modinv(k,MOD)
  v %= MOD
  memo[k] = memo[N-k] = v
for i in range(N+1):
    j = K-A*i
    if j < 0:
        break
    if (K-A*i)%B==0:
        j //= B
        n+=(memo[i]*memo[j])%998244353
        n%=998244353
print(n%998244353)

Buggy submission (verdict: Runtime Error):
MOD = 998244353
def egcd(a, b):
    if a == 0:
        return (b, 0, 1)
    else:
        g, y, x = egcd(b % a, a)
        return (g, x - (b // a) * y, y)

def modinv(a, m):
    g, x, y = egcd(a, m)
    if g != 1:
        raise Exception('modular inverse does not exist')
    else:
        return x % m


memo = [0]*(N+1)
memo[0] = memo[N] = 1
for k in range(1,N//2+1):
  v = memo[k-1]*(N-k+1)*modinv(k,MOD)
  v %= MOD
  memo[k] = memo[N-k] = v

N,A,B,K = map(int,input().split())
n = 0

for i in range(N+1):
    j = K-A*i
    if j < 0:
        break
    if (K-A*i)%B==0:
        j //= B
        n+=(memo[i]*memo[j])%998244353
        n%=998244353
print(n%998244353)
Problem p03426 (python)

Fixed submission:
H,W,D = map(int,input().split())
d = {}
for i in range(H):
    A = list(map(int,input().split()))
    for j in range(W):
        d[A[j]] = (i,j)
m = []
for i in range(1,D+1):
    mm = [0]
    for j in range(i+D,H*W+1,D):
        k = (j-i)//D
        dd = mm[k-1]+abs(d[j][0]-d[j-D][0])+abs(d[j][1]-d[j-D][1])
        mm.append(dd)
    m.append(mm)
Q = int(input())
for i in range(Q):
    L,R = map(int,input().split())
    if L%D != 0:
        mm = m[L%D-1]
        Lq = L//D
        Rq = R//D
        print(mm[Rq]-mm[Lq])
    else:
        mm = m[D-1]
        Lq = L//D
        Rq = R//D
        print(mm[Rq-1]-mm[Lq-1])

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
INF = float('inf')
H,W,D = map(int,input().split())
A = [list(map(int,input().split())) for _ in range(H)]

d = defaultdict(lambda:[])

for i in range(H):
    for j in range(W):
        d[A[i][j]] = [i,j]

cost = defaultdict(lambda:[])
for r in range(1,D+1):
    for m in range(0,H*W//D):
        if D*(m+1)+r <= H*W:
            cost[r].append(abs(d[D*m+r][0]-d[D*(m+1)+r][0])+abs(d[D*m+r][1]-d[D*(m+1)+r][1]))
for r in range(1,D+1):
    for m in range(len(cost[r])-1):
        cost[r][m+1] += cost[r][m]

Q = int(input())

def magic(L,R):
    r = L%D
    if r == 0:
        r = D
    ml = (L-r)//D
    mr = (R-r)//D
    res = cost[r][mr-1]
    if ml != 0:
        res -= cost[r][ml-1]
    return res


for _ in range(Q):
    L,R = map(int,input().split())
    print(magic(L,R))

Buggy submission (verdict: Runtime Error):
H,W,D = map(int,input().split())
d = {}
for i in range(H):
    A = list(map(int,input().split()))
    for j in range(W):
        d[A[j]] = (i,j)
m = []
for i in range(1,D+1):
    mm = [0]
    for j in range(i+D,H*W,D):
        k = (j-i)//D
        dd = mm[k-1]+abs(d[j][0]-d[j-D][0])+abs(d[j][1]-d[j-D][1])
        mm.append(dd)
    m.append(mm)
Q = int(input())
for i in range(Q):
    L,R = map(int,input().split())
    if L%D != 0:
        mm = m[L%D-1]
        Lq = L//D
        Rq = R//D
        print(mm[Rq]-mm[Lq])
    else:
        mm = m[D-1]
        Lq = L//D
        Rq = R//D
        print(mm[Rq-1]-mm[Lq-1])
Problem p03776 (python)

Fixed submission:
def fact(n):
    if n == 0:
        return 1
    else:
        return n*fact(n-1)
def conb(n,r):
    return fact(n)//(fact(r)*fact(n-r))

N,A,B = map(int,input().split())
v = list(map(int,input().split()))
v.sort()
v.reverse()
d_all = {}
for i in range(N):
    if v[i] not in d_all:
        d_all[v[i]] = 0
    d_all[v[i]] += 1
import numpy as np
avg = np.cumsum(np.array(v))
avg = [0]*N
avg[0]=v[0]
for i in range(N-1):
    avg[i+1]=avg[i]+v[i+1]
for i in range(N):
    avg[i]=avg[i]/(i+1)
    
avg = avg[A-1:B]
ans = max(avg)
print(ans)
avg=np.array(avg)
indices = np.where(avg==ans)[0]
ans = 0
for index in indices:
    d_use = {}
    use = A + index
    v_use = v[:use]
    choose=1
    for item in v_use:
        if item not in d_use:
            d_use[item] = 0
        d_use[item] += 1
    for item in d_use:
        choose *= conb(d_all[item],d_use[item])
    ans += choose

print(ans)

Buggy submission (verdict: Runtime Error):
from scipy.special import comb
N,A,B = map(int,input().split())
v = list(map(int,input().split()))
v.sort(reverse=True)

ans = 0
if v[A-1] == v[0]:
    mean = v[0]
    count = 0
    for i in range(N):
        if v[i] == v[0]:
            count += 1
    for i in range(A,min(B,count)+1):
        ans += comb(count,i,exact=True)
else:
    mean = sum(v[:A])/A
    count = 0
    j = N
    for i in range(N):
        if v[i] == v[A-1]:
            j = min(i,j)
            count += 1
    ans = comb(count,A-j,exact=True)
print(mean)
print(ans)

Buggy submission (verdict: Runtime Error):
def fact(n):
    if n == 0:
        return 1
    else:
        return n*fact(n-1)
def conb(n,r):
    return fact(n)//(fact(r)*fact(n-r))

N,A,B = map(int,input().split())
v = list(map(int,input().split()))
v.sort()
v.reverse()
d_all = {}
for i in range(N):
    if v[i] not in d_all:
        d_all[v[i]] = 0
    d_all[v[i]] += 1
import numpy as np
avg = np.cumsum(np.array(v))
for i in range(N):
    avg[i]=int(avg[i])/(i+1)
avg = avg[A-1:B]
ans = max(avg)
print(ans)
indices = np.where(avg==ans)[0]
ans = 0
for index in indices:
    d_use = {}
    use = A + index
    v_use = v[:use]
    choose=1
    for item in v_use:
        if item not in d_use:
            d_use[item] = 0
        d_use[item] += 1
    for item in d_use:
        choose *= conv(d_all[item],d_use[item])
    ans += choose

print(ans)
Problem p02547 (python)

Fixed submission:
s=int(input())
flag=0
z=0
for i in range(s):
    p= list(map(int, input().split()))
    if p[0]==p[1]:
        z+=1
        if z==3:
            flag=1
    else:
        z=0
if flag:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
s=int(input())
for i in range(s):
    p= list(map(int, input().split()))
    if p[0]==p[1]:
        z+=1
        if z==3:
            print("Yes")
            exit()
    else:
        z=0

print("No")
Problem p02549 (python)

Fixed submission:
n,k= list(map(int, input().split()))
INF=998244353
s=[]
for i in range(k):
    j,jj=map(int,input().split())
    s.append([l for l in range(j,jj+1)])
pattern=[0 for i in range(n)]
pattern[0]=1
ls=len(s)
memo=[0 for i in range(k)]
s.sort()
for i in range(1,n):
    tmp=0
    for index,j in enumerate(s):
        if i-j[0]<0:
            break
        elif i-j[-1]>0:
            memo[index]+=pattern[i-j[0]]
            memo[index]-=pattern[i-j[-1]-1]
            if memo[index]<0:
                memo[index]+=INF
        else:
            memo[index]+=pattern[i-j[0]]

        #tmp+=sum(pattern[max(i-j[-1],0):i-j[0]+1])
        memo[index]%=INF
    pattern[i]=(sum(memo)%INF)
print(pattern[-1])

Buggy submission (verdict: Runtime Error):
n,k= list(map(int, input().split()))
INF=998244353
s=[]
for i in range(k):
    j,k=map(int,input().split())
    s.append([l for l in range(j,k+1)])
pattern=[0 for i in range(n)]
pattern[0]=1
ls=len(s)
s.sort()
for i in range(1,n):
    tmp=0
    for j in s:
        if i-j[0]<0:
            break
        else:
            tmp+=sum(pattern[max(i-j[1],0):i-j[0]])
        tmp%=INF
    pattern[i]=tmp
print(pattern[-1])