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

Fixed submission:
import logging

logging.basicConfig(level=logging.INFO, format="%(message)s")
logging.disable(logging.CRITICAL)

N, X  = (int(x) for x in input().split())
L = list(int(x) for x in input().split())

logging.info(L)

length = 0
counter = 1

for i in L:
    length += i
    if length <= X:
        counter += 1
    
print(counter)

Buggy submission (verdict: Runtime Error):
import logging

logging.basicConfig(level=logging.INFO, format="%(message)s")
logging.disable(logging.CRITICAL)

N, X  = (int(x) for x in input().split())
L = list(int(x) for x in input().split())

logging.info(L)

length = 0
counter = 1

for i in L:
    length += i
    if length <= X:
        counter++
    
print(counter)

Buggy submission (verdict: Runtime Error):
    import logging
     
    logging.basicConfig(level=logging.INFO, format="%(message)s")
    logging.disable(logging.CRITICAL)
     
    N, X  = (int(x) for x in input().split())
    L = list(int(x) for x in input().split())
     
    logging.info(L)
     
    length = 0
    counter = 1
     
    if X < L[0]:
        print(1)
    else:
        for i in L:
            length += i
            if length >= X or counter == N:
                break
            counter += 1
        
        print(counter)

Buggy submission (verdict: Runtime Error):
import logging
 
logging.basicConfig(level=logging.INFO, format="%(message)s")
logging.disable(logging.CRITICAL)
 
N, X  = (int(x) for x in input().split())
L = list(int(x) for x in input().split())
 
logging.info(L)
 
length = 0
counter = 1
if X < L[0]:
    print(1)
else:
    for i in L:
        length += i
        if length > X or counter == N:
            break
        counter += 1
       
    print(counter
Problem p03005 (python)

Fixed submission:
N, K = (int(x) for x in input().split())

if (K == 1):
    print("0")
else:
    print(N - K)

Buggy submission (verdict: Runtime Error):
N, K = (int(x) for x in input().split())

if (K == 1):
    print("0")
else:
    print(N - K)
Problem p04033 (python)

Fixed submission:
import logging

logging.basicConfig(level=logging.INFO, format="%(message)s")
#logging.disable(logging.CRITICAL)

def main():
    a, b = map(int, input().split())
    logging.info("Hello!")

    if a * b < 0:
        print("Zero")
    elif a > 0:
        print("Positive")
    else:
        if (b - a + 1) % 2 == 1:
            print("Negative")
        else:
            print("Positive")
            

    
    
if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
import logging

logging.basicConfig(level=logging.INFO, format="%(message)s")
#logging.disable(logging.CRITICAL)

def main():
    a, b = map(int, input().split())
    logging.info("Hello!")

    if a * b < 0:
        print(zero)
    elif a > 0:
        print("Positive")
    else:
        if (b - a + 1) % 2 == 1:
            print("Negative")
        else:
            print("Positive")
            

    
    
if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
import logging

logging.basicConfig(level=logging.INFO, format="%(message)s")
#logging.disable(logging.CRITICAL)

def main():
    a, b = map(int, input().split())
    logging.info("Hello!")

    if a * b < 0:
        print(zero)
    elif a > 0:
        print("Positive")
    else:
        if (b - a + 1) % 2 == 1:
            print("Negative")
        else:
            print("Positive")
            

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

Fixed submission:
import math
h, w = map(int, input().split())
if h == 1 or w == 1:
    print(1)
else:
    print(math.ceil(h * w / 2))

Buggy submission (verdict: Runtime Error):
mport math
h, w = map(int, input().split())
print(math.ceil(h * w / 2))
Problem p02657 (python)

Fixed submission:
A,B=input().split();
A=int(A);
B=int(B);
print(A*B);

Buggy submission (verdict: Runtime Error):
N=input();
N=int(N);
A=input().split();
print(A);
A = [int(s) for s in A];
sum =1;
if 0 in A:
  print(0);
  return
for i in range(N):
  if(A[i]==0):
    sum=0;
    break;
  sum=sum*A[i];
  #print(sum);
if sum> (10**18):
  sum=-1;
print(sum);

Buggy submission (verdict: Runtime Error):
A,B=input().split;
A-int(A);
B=int(B);
print(A*B);
Problem p02802 (python)

Fixed submission:
n,m=map(int, input().split())
maru=0
pena=[0]*n

Num = []
St = []

toi=set() #重複無しのset型で用意，リストの重複がないやつ
for i in range(m):
    p, s = input().split()
    #Num.append(int(p))
    #St.append(s)
#print(Num[0])
#print(St)
    p=int(p)-1 #0index

    if p in toi:
        continue #以降はスキップ

    elif s=='AC':
        toi.add(p) #そのpの時のとい番号を保存
        #print(p)
    else: 
        pena[p]+=1
print(len(toi), sum(pena[p] for p in toi)) #各pの時のWAをたす

Buggy submission (verdict: Runtime Error):
n,m=map(int, input().split())
maru=0
pena=[0]*m

Num = []
St = []

toi=set() #重複無しのset型で用意，リストの重複がないやつ
for i in range(m):
    p, s = input().split()
    #Num.append(int(p))
    #St.append(s)
#print(Num[0])
#print(St)
    p=int(p)

    if p in toi:
        continue #以降はスキップ
    
    if s=='AC':
        maru+=1
        toi.add(p) #そのpの時のとい番号を保存
    else: 
        pena[p]+=1
print(maru, sum(pena[i] for i in toi)) #各pの時のWAをたす
Problem p02812 (python)

Fixed submission:
N=int(input())
s=input()
S=list(s)
#print(S[0])
flg=0
for i in range(N-2):
    if S[i] == 'A':
        if S[i+1] =='B':
            if S[i+2] =='C':
                flg+=1
print(flg)

Buggy submission (verdict: Runtime Error):
N=int(input())
s=input()
S=list(s)
#print(S[0])
flg=0
for i in range(N-1):
    if S[i] == 'A':
        if S[i+1] =='B':
            if S[i+2] =='C':
                flg+=1
print(flg)

Buggy submission (verdict: Runtime Error):
N=int(input())
s=input()
S=list(s)
#print(S[0])
flg=0
for i in range(N):
    if S[i] == 'A':
        if S[i+1] =='B':
            if S[i+2] =='C':
                flg+=1
print(flg)
Problem p02861 (python)

Fixed submission:
import math

n = int(input())
x=[0]*n
y=[0]*n
sum = 0.0

for i in range(n):
    x[i],y[i] = map(int, input().split())

for i in range(n):
    for j in range(n):
        sum += math.sqrt(pow((x[i]-x[j]),2) + pow((y[i]-y[j]),2))
        #print(x[i],y[i],x[j],y[j],sum)
print(sum/n)

Buggy submission (verdict: Runtime Error):
from numpy.linalg import solve

#制約
MOD = 10**9 +7
MAX = 10**6

#　組み合わせ計算
def COM(n, r):
    fac = [1, 1]
    finv = [1, 1]
    inv = [0, 1]
    for i in range(2, MAX):
        fac.append(fac[i - 1] * i % MOD)
        inv.append(-inv[MOD % i] * (MOD // i))
        finv.append(finv[i - 1] * inv[i] % MOD)
    if n < r:
        return 0
    if n < 0 or r < 0:
        return 0
    return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD

x,y = map(int,input().split())

if (x+y)%3 != 0:
    print(0)
    exit()

l = solve([[2, 1], [1, 2]], [x, y])
if l[0] < 0 or l[1] < 0: #n,m <0の時0
    print(0)
    exit()
# n+m回のうち，どのn回で移動するか n+mCOMnを計算
print(COM(int(l[0]+l[1]), int(l[0])))
Problem p02911 (python)

Fixed submission:
import numpy as np
def python_list_sub(in1, in2):
    wrk = np.array(in1) + np.array(in2)
    return wrk.tolist()


n, k, q = map(int,input().split())
#A = []
Po = []
De = [1 for i in range(n)]

A = [int(input()) for i in range(q)]
#print(A)

# はじめからポイント減らしておく
for i in range(n):
    Po.append(int(k-q))
#print(Po)
# 入力はOK

#計算
for j in A:
    #print(j,A[j])
    Po[j-1] += 1
#print(Po)

for i in range(n):
    if Po[i] >0:
        print('Yes')
    else: print('No')

Buggy submission (verdict: Runtime Error):
import numpy as np
def python_list_sub(in1, in2):
    wrk = np.array(in1) - np.array(in2)
    return wrk.tolist()


n, k, q = map(int,input().split())
#A = []
Po = []
De = [1 for i in range(n)]

A = [int(input()) for i in range(q)]
#print(A)

for i in range(n):
    Po.append(int(k))
print(Po)
# 入力はOK

#計算
for i in range(q):
    #De = [1 for i in range(n)]
    ans = python_list_sub(Po, De)
print(ans)

for i in range(q):
    if ans[i] >0:
        print('Yes')
    else: print('No')
Problem p02982 (python)

Fixed submission:
import math

n, d=map(int, input().split())
x=[]
for i in range(n):
    x.append([int(i) for i in input().split()])

ans=0
for i in range(n-1): #0-n
  for j in range(i+1,n):
    s = 0
    for k in range(d):
      s += (x[i][k]-x[j][k])**2
    a = math.sqrt(s)
    if a.is_integer():
      ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
import math

n, d=map(int, input().split())
x=[]
for i in range(n):
    x.append([int(i) for i in input().split()])

for i in range(n-1): #0-n
  for j in range(i+1,n):
    s = 0
    for k in range(d):
      s += (x[i][k]-x[j][k])**2
    a = math.sqrt(s)
    if a.is_integer():
      ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
n, d=map(int, input().split())
x=[]
for i in range(n):
    x.append([int(i) for i in input().split()])

for i in range(n-1): #0-n
  for j in range(i+1,n):
    s = 0
    for k in range(d):
      s += (x[i][k]-x[j][k])**2
    a = math.sqrt(s)
    if a.is_integer():
      ans += 1
print(ans)
Problem p02993 (python)

Fixed submission:
S=input()
if S[0]==S[1] or S[1]==S[2] or S[2]==S[3]:
  print('Bad')
else:
  print('Good')

Buggy submission (verdict: Runtime Error):
S=input()
if S[0]==S[1] or S[1]==S[2] or S[2]==S[3] or S[3]==S[4]:
  print('Bad')
else:
  print('Good')
Problem p03061 (python)

Fixed submission:
from itertools import accumulate
import math
import fractions

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

#最大公約数で累積和作る
B = [0] * (N+1)
R = [0] * (N+1)
for i in range(N):
    B[i+1] = (fractions.gcd(B[i],A[i]))
    #逆向き,とったやつの反対端用   
    R[N-i -1] = (fractions.gcd(R[N-i], A[N-1 -i]))
 
ans = 0
for i in range(N):
    ans = max(ans, fractions.gcd(B[i], R[i+1]))
print(ans)

Buggy submission (verdict: Runtime Error):
from itertools import accumulate
import math
import fractions

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

#最大公約数で累積和作る
B = [0] * N
R = [0] * N
for i in range(N):
    B[i+1] = (fractions.gcd(B[i],A[i]))
    #逆向き,とったやつの反対端用   
    R[N-i -1] = (fractions.gcd(R[N-i], A[N-i -1]))
 
ans = 0
for i in range(N):
    ans = max(ans, fractions.gcd(B[i], R[i+1]))
print(ans)

Buggy submission (verdict: Runtime Error):
from itertools import accumulate
import math
import fractions

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

#最大公約数で累積和作る
B = [0] * N
R = [0] * N
for i in range(N):
    B[i+1] = (math.gcd(B[i],A[i]))
    #逆向き,とったやつの反対端用   
    R[N-i -1] = (math.gcd(R[N-i], A[N-i -1]))
 
ans = 0
for i in range(N):
    ans = max(ans, math.gcd(B[i], R[i+1]))
print(ans)

Buggy submission (verdict: Runtime Error):
from itertools import accumulate
import math
import fractions

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

#最大公約数で累積和作る
B = [0] * N
R = [0] * N
for i in range(N):
    B[i+1] = (math.gcd(B[i],A[i]))
    #逆向き,とったやつの反対端用   
    R[N-i -1] = (math.gcd(R[N-i], A[N-i -1]))
 
ans = 0
for i in range(N):
    ans = max(ans, math.gcd(B[i], R[i+1]))
print(ans)
Problem p03087 (python)

Fixed submission:
from itertools import accumulate

N, Q = map(int, input().split())
S = input()
A = [list(map(int, input().split())) for i in range(Q)]
# リストに入れておく
#print(A)

flg = []
for i in range(N-1):
    tmp_S = S[i:i+2]
    if tmp_S == 'AC':
        flg.append(1)
    else:
        flg.append(0)
# print(len(flg)) #N-1になっていることを確認

ans = []
ans = [0] + flg #繋げて
ans = list(accumulate(ans)) #累積和にする
#print(ans)

for li in A:
    print(ans[li[1]-1] - ans[li[0]-1] )

Buggy submission (verdict: Runtime Error):
from itertools import accumulate

N, Q = map(int, input().split())
S = input()
A = [list(map(int, input().split())) for i in range(Q)]
# リストに入れておく
#print(A)

flg = []
for i in range(N-1):
    tmp_S = S[i:i+2]
    if tmp_S == 'AC':
        flg.append(1)
    else:
        flg.append(0)
# print(len(flg)) #N-1になっていることを確認

ans = []
ans = [0] + flg #繋げて
ans = list(accumulate(flg)) #累積和にする
#print(ans)

for li in A:
    print(ans[li[1]-1] - ans[li[0]-1] )
Problem p03352 (python)

Fixed submission:
X=int(input())
x=0
ans=[]

if X == 1:
  print(X)
  exit()
else:
  # p
  for i in range(2, int(X**0.5)+1):
    n=1
    a=i
    # b
    while n < X : #超えたら中断
      n *= a
      ans.append(n)
    if n // a > x:
      x = (n//a)
      #print(ans)
print(max(i for i in ans if i <= X))

Buggy submission (verdict: Runtime Error):
X=int(input())
x=0
ans=[]

if X == 1:
  print(X)
else:
  # p
  for i in range(2, int(X**0.5)+1):
    n=1
    a=i
    # b
    while n < X : #超えたら中断
      n *= a
      ans.append(n)
    if n // a > x:
      x = (n//a)
      #print(ans)
print(max(i for i in ans if i <= X))
Problem p02628 (python)

Fixed submission:
n, k = map(int, input().split())
#pList = map(int, input().split())
split = input().split()
pList = [int(i) for i in split]
list.sort(pList)
score = 0
for i in range(k):
    score += pList[i]
print(score)

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())
pList = map(int, input().split())
list.sort(pList)
score = 0
for i in range(k):
    score += pList[i]
print(score)

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())
pList = map(int, input().split())
#n, k = 5, 3
#pList = [50, 100, 80, 120, 80]
list.sort(pList)
score = 0
for i in range(k):
    score += pList[i]
print(score)

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())
pList = map(int, input().split())
#n, k = 5, 3
#pList = [50, 100, 80, 120, 80]
list.sort(pList)
score = 0
for i in range(k):
    score += pList[i]
print(score)
Problem p02756 (python)

Fixed submission:
from collections import deque

S = str(input())
Q = int(input())
Query = [list(map(str, input().split())) for _ in range(Q)]

sArry = deque(S)
rFlag = False
for i in range(Q):
    if Query[i][0] == '1':
        rFlag = (rFlag == False)
        
    else:
        if rFlag:
            if Query[i][1] == '1':
                sArry.append(Query[i][2])
            else:
                sArry.appendleft(Query[i][2])
        else:
            if Query[i][1] == '1':
                sArry.appendleft(Query[i][2])
            else:
                sArry.append(Query[i][2])
            
#    print("  ", i, rFlag, "".join(sArry), Query[i])



if rFlag:
    print("".join(reversed(sArry)))
else:
    print("".join(sArry))

Buggy submission (verdict: Runtime Error):
    import sys
    S = str(input())
    Q = int(input())
    Query = [list(map(str, input().split())) for _ in range(Q)]
     
    sArry = S.split()
    for i in range(Q):
    #    print(i,Query[i])
        if Query[i][0] == '1':
            tmp_first = sArry[0]
            sArry[0] = sArry[-1]
            sArry[-1] = tmp_first
        else:
            if Query[i][1] == '1':
                sArry.insert(0, Query[i][2])
            else:
                sArry.append(Query[i][2])
                
    print("".join(sArry))
Problem p02783 (python)

Fixed submission:
import math
(H, A) = list(map(int, input().split()))

print(math.ceil(H / A))

Buggy submission (verdict: Runtime Error):
10000 1
Problem p03101 (python)

Fixed submission:
first_args = raw_input().split()
second_args = raw_input().split()

max_row = int(first_args[0])
max_col = int(first_args[1])

fill_row = int(second_args[0])
fill_col = int(second_args[1])

if(fill_row <= max_row and fill_col <= max_col):
  all_cells = max_row * max_col
  filled_cells = (fill_row * max_col) + (fill_col * max_row) - (fill_row * fill_col)

  print all_cells - filled_cells

Buggy submission (verdict: Runtime Error):
from operator import itemgetter

N_shop, M_required_drink  = map(int, raw_input().split())

shop_list = []
for tmp_shop in range(N_shop):
  shop_list.append(map(int, raw_input().split()))

total_money = 0
got_drink = 0
for i in sorted(shop_list, key=itemgetter(0)):
  limit_at_shop = i[1]
#  print(i)

  while got_drink < M_required_drink and limit_at_shop > 0:
    total_money = total_money + i[0]
    got_drink   = got_drink + 1
    limit_at_shop = limit_at_shop - 1
#    print("  %s %s %s" % (total_money, got_drink, limit_at_shop))

print(total_money)

Buggy submission (verdict: Runtime Error):
from operator import itemgetter

N_shop, M_required_drink  = map(int, raw_input().split())

shop_list = []
for tmp_shop in range(N_shop):
  shop_list.append(map(int, raw_input().split()))

total_money = 0
got_drink = 0
for i in sorted(shop_list, key=itemgetter(0)):
  limit_at_shop = i[1]
#  print(i)

  while got_drink < M_required_drink and limit_at_shop > 0:
    total_money = total_money + i[0]
    got_drink   = got_drink + 1
    limit_at_shop = limit_at_shop - 1
#    print("  %s %s %s" % (total_money, got_drink, limit_at_shop))

print(total_money)
Problem p03151 (python)

Fixed submission:
import sys

num_exam = int(raw_input())
current_scores    = map(int, raw_input().split())
exam_boarderlines = map(int, raw_input().split())

margin_scores = []
lack_scores   = []
count_adjusted = 0

if sum(current_scores) < sum(exam_boarderlines):
  print(-1)
  sys.exit()

for i in range(num_exam):
  if current_scores[i] < exam_boarderlines[i]:
    lack_scores.append(current_scores[i] - exam_boarderlines[i])
    count_adjusted += 1
  elif current_scores[i] > exam_boarderlines[i]:
    margin_scores.append(current_scores[i] - exam_boarderlines[i])

desc_sorted_margin_scores = sorted(margin_scores, reverse=True)
total_lack_score = sum(lack_scores)
for i in range(len(desc_sorted_margin_scores)):
  if total_lack_score >= 0:
    break

  total_lack_score += desc_sorted_margin_scores[i]
  count_adjusted += 1

print(count_adjusted)

Buggy submission (verdict: Runtime Error):
import sys

num_exam = int(raw_input())
current_scores    = map(int, raw_input().split())
exam_boarderlines = map(int, raw_input().split())

margin_scores = []
lack_scores   = []
count_adjusted = 0

if sum(current_scores) < sum(exam_boarderlines):
  print(-1)
  sys.exit()

for i in range(num_exam):
  if current_scores[i] < exam_boarderlines[i]:
    lack_scores.append(current_scores[i] - exam_boarderlines[i])
    count_adjusted += 1
  elif current_scores[i] > exam_boarderlines[i]:
    margin_scores.append(current_scores[i] - exam_boarderlines[i])

desc_sorted_margin_scores = sorted(margin_scores, reverse=True)
total_lack_score = sum(lack_scores)
for i in range(len(desc_sorted_margin_scores)):
  if total_lack_score >= 0:
    break

  total_lack_score += desc_sorted_margin_scores[i]
  count_adjusted += 1

print(count_adjusted)
~
Problem p02717 (python)

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

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
'''
11 3 2
ooxxxoxxxoo
'''

import numpy as np

N, K, C = map(int, input().split())
S = input()

oks = [idx for idx, i in enumerate(S) if i == 'o']
# print(oks)

for ok in oks:
    temp = oks.copy()
    temp.remove(ok)
    temp = np.array(temp)
    cnt = 0

    while True:
        if len(temp) == 0:
            print(ok + 1)
            break
        val = temp[0]
        temp = temp[temp > val + C]
        cnt += 1
        if cnt >= K:
            break
Problem p02742 (python)

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

import sys
from collections import defaultdict, deque
from heapq import heappush, heappop
import math
import bisect
input = sys.stdin.readline

# 再起回数上限変更
# sys.setrecursionlimit(1000000)

h,w = map(int, input().split())
if h == 1 or w == 1:
    print(1)
elif (h%2==1) and (w%2==1):
    print(int((h * w // 2)+1))
else:
    print(int(h*w/2))

Buggy submission (verdict: Runtime Error):
print((H+W)/2)
Problem p02772 (python)

Fixed submission:

import sys


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

for i in a:
    if i % 2 == 0:
        if (i % 3 == 0) or (i % 5 == 0):
            continue
        else:
            print('DENIED')
            sys.exit()

print('APPROVED')

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

for i in a:
    if i % 2 == 0:
        if (i % 3 == 0) or (i % 5 == 0):
            continue
        else:
            print('DENIED')
            sys.exit()

print('APPROVED')
Problem p02783 (python)

Fixed submission:

H, A = map(int, input().split())

if H % A == 0:
    print(int(H / A))
else:
    print((H // A)+1)

Buggy submission (verdict: Runtime Error):

import math
H = int(input())


def iterated_power(z: int, n: int, mod=None) -> int:
    beta = bin(n)[2:]

    Z, q, t = z, 0, len(beta)
    while beta[t - q - 1] == '0':
        Z = Z * Z
        if mod is not None:
            Z = Z % mod
        q += 1
    result = Z

    for k in range(q + 1, t):
        Z = Z * Z
        if mod is not None:
            Z = Z % mod
        if beta[t - k - 1] == '1':
            result = result * Z
            if mod is not None:
                result = result % mod

    if mod is not None:
        result = result % mod

    return result

cnt = 0
while True:
    H = math.floor(H/2)
    cnt += 1
    if H ==1:
        break
cnt += 1

ans = iterated_power(2, cnt) - 1

print(ans)
Problem p02802 (python)

Fixed submission:

N, M = map(int, input().split())

data = {}
ps = [0] * N
ACs = []

num_ac = 0
num_wa = 0


for i in range(M):
    p, S = input().split()
    p = int(p) - 1

    if ps[p] == 0:
        ps[p] = 1
        data[p] = {'AC':0, 'WA':0}

    if S == 'AC' and data[p]['AC'] == 0:
        ACs.append(p)
        data[p]['AC'] += 1
        num_ac += 1
        num_wa += data[p]['WA']

    if S == 'WA' and data[p]['AC'] == 0:
        data[p][S] += 1

print(num_ac, num_wa)

Buggy submission (verdict: Runtime Error):

N, M = map(int, input().split())

data = {}
ps = [0] * N
ACs = []

num_ac = 0
num_wa = 0


for i in range(M):
    p, S = input().split()
    p = int(p)

    if ps[p] == 0:
        ps[p] = 1
        data[p] = {'AC':0, 'WA':0}

    if S == 'AC' and data[p]['AC'] == 0:
        ACs.append(p)
        data[p]['AC'] += 1
        num_ac += 1
        num_wa += data[p]['WA']

    if S == 'WA' and data[p]['AC'] == 0:
        data[p][S] += 1

print(num_ac, num_wa)
Problem p02804 (python)

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

N, K = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
mod = 10**9 + 7


class Cmb(object):
    def cmb_precalc(self, n, r, mod: int = 10 ** 9 + 7):
        if (r < 0) or (r > n):
            return 0
        r = min(r, n - r)
        return self.g1[n] * self.g2[r] * self.g2[n - r] % mod

    def cmb_prep(self, N: int, mod: int = 10 ** 9 + 7):
        self.g1 = [1, 1]  # 元テーブル
        self.g2 = [1, 1]  # 逆元テーブル
        inverse = [0, 1]  # 逆元テーブル計算用テーブル

        for i in range(2, N + 1):
            self.g1.append((self.g1[-1] * i) % mod)
            inverse.append((-inverse[mod % i] * (mod // i)) % mod)
            self.g2.append((self.g2[-1] * inverse[-1]) % mod)


ans = 0
cmb = Cmb()
cmb.cmb_prep(N + 5)

for i in range(N):
    if i >= K-1:
        ans += A[i] * cmb.cmb_precalc(i, i-K+1)
    if N - i - 1 >= K-1:
        ans -= A[i] * cmb.cmb_precalc(N-i-1, K-1)

print(ans % mod)

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

import sys
# 再起回数上限変更
# sys.setrecursionlimit(1000000)

N, K = map(int, input().split())
A = list(map(int, input().split()))

mod = 10**9 + 7

A.sort()
# print(A)

def cmb(n, r):
    from operator import mul
    from functools import reduce

    r = min(n - r, r)
    if r == 0:
        return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1, r + 1))
    return over // under


ans = 0
num1=None
num2=None

for i in range(N):
    if N - i - 1 >= K-1:
        if num1 is None:
            num1 = cmb(N-i-1, K-1)
        else:
            num1 = int(num1 * (N-i-K+1) / (N-i))
        # print(N-i-1, K-1, num1)
        if A[i] * num1 < 0:
            ans += (-A[i] * num1) % mod
        else:
            ans -= (A[i] * num1) % mod
        # print(f'-: {i}, {num}, {A[i]}')
    if i >= K-1:
        if num2 is None:
            num2 = cmb(i, K-1)
        else:
            num2 = int(num2 * i / (i-K+1))
        # print(i, K-1, num2)
        if A[i] * num2 < 0:
            ans -= (-A[i] * num2) % mod
        else:
            ans += (A[i] * num2) % mod
        # print(f'+: {i}, {num}, {A[i]}')

print(ans % mod)