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

Fixed submission:
N = int(input())
count = 1
while count ** 2 <= N:
    count += 1

print((count-1)**2)

Buggy submission (verdict: Runtime Error):
N = int(input())
count = 1
while count ** 2 <= N:
    count += 1

print((count-1)**2)N = int(input())
count = 1
while count ** 2 <= N:
    count += 1

print((count-1)**2)
Problem p03695 (python)

Fixed submission:
N = int(input())
rates = list(input().split())

for i in range(len(rates)):
    rates[i] = int(rates[i]) // 400

MAX = 0
MIN = 0
j = 0
while j <= 8:
    for k in range(N):
        if j != 8 and j == rates[k]:
            MAX += 1
            MIN += 1
            break
        elif j == 8 and j <= rates[k]:
            MAX += 1
            if MIN == 0:
                MIN = 1
                continue
            continue
    j += 1

print(MIN, MAX)

Buggy submission (verdict: Runtime Error):
ates = list(input().split())

for i in range(len(rates)):
    rates[i] = int(rates[i]) // 400

MAX = 0
MIN = 0
j = 0
while j <= 8:
    for k in range(N):
        if j != 8 and j == rates[k]:
            MAX += 1
            MIN += 1
            break
        elif j == 8 and j <= rates[k]:
            MAX += 1
            if MIN == 0:
                MIN = 1
            continue
    j += 1

print(MIN, MAX)
Problem p03943 (python)

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

S = sorted(candy, reverse = True)
if S[0] == S[1] + S[2]:
    print("Yes")
else:
    print("No")

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

S = sorted(candy, reverse = True)
if S[0] == S[1] + S[2]:
    print("Yes")
else:
    print("No")
Problem p03997 (python)

Fixed submission:
a,b,h=map(int,open(0));print((a+b)*h//2)

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

S = (a + b) * h // 2

print(S)

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

S = (a + b) * h /2

print(S)

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

S = (a + b) * h /int(2)

print(S)

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

S = (a + b) * h /int(2)

print(S)

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

S = int((a + b) * h /2)

print(S)
Problem p02665 (python)

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
if a[0] == 1 and n == 0:
    print(1)
    exit()
su = sum(a)
# print(su)
l = [su]*(n+1)
for i in range(1,n+1):
    l[i]=l[i-1]-a[i-1]
# print(l)
count=0
x = 0
m=[1]*(n+1)
for j in range(1,n+1):
    m[j] = m[j-1]*2
    if m[j]>l[j]:
        m[j]=l[j]
    if (m[j]<a[j])or(m[j]==a[j] and j!=n):
        # print(m[j],a[j])
        x = 1
        break
    # print(m[j])
    count += m[j]
    m[j] -= a[j]
count+=1

if x==1 or a[0]!=0 :
    print(-1)
else:
    print(count)

Buggy submission (verdict: Runtime Error):
a = list(map(int,input().split()))
su = sum(a)
# print(su)
l = [su]*(n+1)
for i in range(1,n+1):
    l[i]=l[i-1]-a[i-1]
# print(l)
count=0
x = 0
m=[1]*(n+1)
for j in range(1,n+1):
    m[j] = m[j-1]*2
    if m[j]>l[j]:
        m[j]=l[j]
    if (m[j]<a[j])or(m[j]==a[j] and j!=n):
        # print(m[j],a[j])
        x = 1
        break
    # print(m[j])
    count += m[j]
    m[j] -= a[j]
count+=1

if x==1 or a[0]!=0 :
    print(-1)
elif n==0:
    print(1)
else:
    print(count)
Problem p02684 (python)

Fixed submission:
N, K = map(int, input().split())
A = input().split()
A = [int(a) for a in A]
S = [1]
a = 1
number = 0
numbers=[-1 for _ in range(N)]
for _ in range(N + 1):
    b = A[a - 1]
    if numbers[b-1] != -1:
      c=numbers[b-1]          #1回目にループが現れた回数-1
    #   print("ループの最初の数字",b,"最初は"+str(c+1)+"回目","周期は",number-c)
      break
    numbers[b-1]=number
    number += 1
    S.append(b)
    a = b
T = S[c+1:number+1]
if K <= number:
  print(S[K ])
else:
  z = K - c-1
  y = z % (number - c)
#   print(y)
  print(T[y])

Buggy submission (verdict: Runtime Error):
n,k = map(int,input().split())
s = list(map(int,input().split()))
# print(s)
now_city = 1
s_l_city = 1
t = [1] #何回そこを通ったか
f = [0] #何回目にそこを通ったか
a=0
f_l=0
for i in range(n-1):
    t.append(0)
    f.append(-1)
# print(s)
sycle = 0
for i in range(1,k+1):
    now_city = s[now_city-1]
    t[now_city-1]+=1
    # f[now_city-1]=i
    for j in range(n):
        if t[j]==2:
        #  print(i,f[j])
         sycle=i-f[j]
         f_l=f[j]
         a = 1
         s_l_city=j+1
         break
    if a==1:
        break
    f[now_city-1]=i
# print(t)
# print(f_l,sycle,s_l_city)
now_city=s_l_city
for j in range((k-f_l)%sycle):
    now_city = s[now_city-1]
print(now_city)
Problem p02696 (python)

Fixed submission:
a,b,n=map(int,input().split())
score=0
if (n<b):
    print( int(a*n/b))
elif(b==1):
    print(0)
else:
    c = int(n/b)
    score = 0
    for i in range(1,c+1):
        n_ = b*i-1
        t = int(a*n_/b)-a*int(n_/b)
        score = max(score,t)
    t = int(a*n/b)-a*int(n/b)
    score = max(score,t)
    print(score)

Buggy submission (verdict: Runtime Error):
a,b,n=map(int,input().split())
score=0
if (n<b):
    print( int(a*n/b))
elif(b＝＝１):
    print(0)
else:
    c = int(n/b)
    score = 0
    for i in range(1,c+1):
        n_ = b*i-1
        t = int(a*n_/b)-a*int(n_/b)
        score = max(score,t)
    t = int(a*n/b)-a*int(n/b)
    score = max(score,t)
    print(score)
Problem p02702 (python)

Fixed submission:
s = input()[::-1] # 入力文字列を逆順でsに格納

counts = [0] * 2019
counts[0] = 1

num, d = 0, 1

for char in s:
    num += int(char) * d
    num %= 2019
    d *= 10
    d %= 2019
    counts[num] += 1

ans = 0
for cnt in counts:
    ans += cnt * (cnt - 1) // 2

print(ans) # 答えの出力

Buggy submission (verdict: Runtime Error):
import math
s = int(input()[::-1]) # 入力文字列を逆順でsに格納
n = len(s)
counts = [0]*2019
counts[0]=1
b = 1
num = 0
for i in range(n):
    num += s[i]*b
    num %=2019
    b *=10
    b %2019
    counts[num]+=1

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
# print(counts)
ans = 0
for j in counts:
        ans +=combinations_count(j, 2)


print(ans)
Problem p02732 (python)

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
x = [0]*max(a)
for i in a:
    x[i-1]+=1
# print(x)
count = 0
# x_ = [(k*(k-1))/2 for k in x if k>=2]
# count = sum(x_)
for j in x:
    if j>=2:
        count += int((j*(j-1)/2))
for i in range(n):
    if x[a[i]-1]>=2:
        print(count-x[a[i]-1]+1)
    else:
        print(count)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int,input().split()))
x = [0]*max(a)
for i in a:
    x[i-1]+=1


for i in range(1,n+1):
    x[a[i-1]-1]-=1
    count = 0
    x_ = [(k*k-1)/2 in x if k>=2]
    count = sum(x_)
    # for j in x:
    #     if j>=2:
    #         count += int((j*(j-1)/2))
    x[a[i-1]-1]+=1
    print(count)
Problem p02756 (python)

Fixed submission:
s = input()
q = int(input())
a = []
# for j in range(q):
#     a.extend([list(map(str,input().split()))])
# # print(a)
# for i in a:
pre = ""
nex = ""
c = 1
for j in range(q):
    i = list(map(str,input().split()))
    if i ==["1"]:
        c *= -1
        # s = s[::-1]
    elif i[0]=="2" and i[1]=="1":
        # s = i[2]+s
        if c == 1:
            pre=i[2]+pre
        else:
            nex = nex + i[2]
    elif i[0]=="2" and i[1]=="2":
        # s = s +i[2]
        if c ==1:
            nex = nex +i[2]
        else:
            pre = i[2]+pre
s = pre+s+nex
if c ==-1:
    s = s[::-1]
print(s)

Buggy submission (verdict: Runtime Error):
s = input()
q = int(input())
a = []
# for j in range(q):
#     a.extend([list(map(str,input().split()))])
# # print(a)
# for i in a:
for j in range(q):
    i = map(str,input().split())
    if i ==["1"]:
        s = s[::-1]
    elif i[0]=="2" and i[1]=="1":
        s = i[2]+s
    elif i[0]=="2" and i[1]=="2":
        s = s +i[2]
print(s)
Problem p02609 (python)

Fixed submission:
n = int(input())
x = input()

x_1 = x.count('1')
flag = 0
if(x_1 == 0):
    flag = 1
if(x_1 == 1):
    flag = 2

data = [0 for i in range(n+1)]
data[0] = 0
for i in range(1,n+1):
    i_str = format(i,'b')
    ne = i % (i_str.count('1'))
    data[i] = data[ne] + 1

up = [0 for i in range(n)]
do = [0 for i in range(n)]

d = 1
upp = 0
for i in range(n):
    up[i] = d
    if(x[n-i-1] == '1'):
        upp += d
        upp %= (x_1+1)
    d *= 2
    d %= (x_1 + 1)
d = 1
dow = 0
if(flag == 0):
    for i in range(n):
        do[i] = d
        if(x[n-i-1] == '1'):
            dow += d
            dow %= (x_1-1)
        d *= 2
        d %= (x_1 - 1)


for i in range(n):
    if(x[i] == '0'):
        sam = upp + up[n-i-1]
        sam %= (x_1+1)
        print(data[sam]+1)
    elif(flag == 0):
        sam = dow - do[n-i-1]
        sam %= (x_1-1)
        print(data[sam]+1)
    elif(flag == 2):
        print('0')

Buggy submission (verdict: Runtime Error):
n = int(input())
x = input()

x_1 = x.count('1')
flag = 0
if(x_1 == 0):
    flag = 1
if(x_1 == 1):
    flag = 2

data = [0 for i in range(n+1)]
data[0] = 0
for i in range(1,n+1):
    i_str = format(i,'b')
    ne = i % (i_str.count('1'))
    data[i] = data[ne] + 1

up = [0 for i in range(n)]
do = [0 for i in range(n)]

d = 1
for i in range(n):
    up[i] = d % (x_1 + 1)
    d *= 2
d = 1
if(flag == 0):
    for i in range(n):
        do[i] = d % (x_1 - 1)
        d *= 2

upp = 0
dow = 0

for i in range(n):
    if(x[n-i-1] == '1'):
        upp += up[i]
        upp %= (x_1+1)
        dow += do[i]
        dow %= (x_1-1)


for i in range(n):
    if(x[i] == '0'):
        sam = upp + up[n-i-1]
        sam %= (x_1+1)
        print(data[sam]+1)
    elif(flag == 0):
        sam = dow - do[n-i-1]
        sam %= (x_1-1)
        print(data[sam]+1)
    elif(flag == 2):
        print('0')

Buggy submission (verdict: Runtime Error):
n = int(input())
x = input()

x_1 = x.count('1')
flag = 0
if(x_1 == 0):
    flag = 1
if(x_1 == 1):
    flag = 2

data = [0 for i in range(n+1)]
data[0] = 0
for i in range(1,n+1):
    i_str = format(i,'b')
    ne = i % (i_str.count('1'))
    data[i] = data[ne] + 1

print(data)

up = [0 for i in range(n)]
do = [0 for i in range(n)]

d = 1
for i in range(n):
    up[i] = d % (x_1 + 1)
    d *= 2
d = 1
if(flag == 0):
    for i in range(n):
        do[i] = d % (x_1 - 1)
        d *= 2

upp = 0
dow = 0

for i in range(n):
    if(x[n-i-1] == '1'):
        upp += up[i]
        upp %= (x_1+1)
        dow += do[i]
        dow %= (x_1-1)



for i in range(n):
    if(x[i] == '0'):
        sam = upp + up[n-i-1]
        sam %= (x_1+1)
        print(data[sam]+1)
    elif(flag == 0):
        sam = dow - do[n-i-1]
        sam %= (x_1-1)
        print(data[sam]+1)
    elif(flag == 2):
        print('0')
Problem p02642 (python)

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

si = set()
do = set()
for i in range(n):
    if(a[i] in si):
        do.add(a[i])
    else:
        si.add(a[i])
m = max(si)

li = [1]*m

for i in si:
    if(i in do):
        li[i-1] = 0
    for j in range(i*2,m+1,i):
        li[j-1] = 0

ans = 0
for i in si:
    if(li[i-1]==1):
        ans += 1
print(ans)

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

if(len(set(a)) == 1):
    print(0)
else:
    a.sort()
    b = [a[0]]
    for i in range(1,n):
        flag = 1
        for j in b:
            if(a[i]%j == 0):
                flag = 0
                break
        if(flag == 1):
            b.append(a[i])

print(len(b))
Problem p02678 (python)

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

routes = [[] for i in range(n)]
for i in range(m):
    x,y = map(int, input().split())
    routes[x-1].append(y-1)
    routes[y-1].append(x-1)


rooms = [0 for i in range(n)] # 行ったら1,まだなら0
marks = [0 for i in range(n)] # 部屋におく道標
rooms_rate = [[0]] # ０回目、１回目、２回目、３回目…に行ける部屋
rooms[0] = 1

turn = 0
for i in rooms_rate:
    newrate = []
    for j in rooms_rate[turn]: #(turn)回目に行けた部屋から行ける部屋を調べる
        for k in routes[j]: 
            if (rooms[k] == 0): #行ったことのない部屋なら
                rooms[k] = 1
                marks[k] = j # 道標をセット
                newrate.append(k)
    rooms_rate.append(newrate)
    if (len(newrate) == 0): #新しく行けなくなったら終わり
        break
    turn = turn + 1


if(all(rooms) == True):
    print('Yes')
    for i in range(1,n):
        print(str(int(marks[i]) + 1))

else:
    print('No')

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

routes = []
for i in range(m):
    route = list(map(int, input().split()))
    routes.append(route)
    routes[i] = routes[i] - [1,1] #道の番号をずらす

rooms = []
for i in range(n):
    rooms.append(0) # 行ったら1,まだなら0
marks = rooms # 部屋におく道標
roomsrate = [[0]] # １回目、２回目、３回目…に行ける部屋
rooms[0] = 1

turn = 0
for i in roomsrate:
    newrate = []
    for j in roomsrate[turn]: #turn回目に行ける部屋を調べる
        for k in range(m):
            a = int(routes[k][0])
            b = int(routes[k][1]) 
            if (j == a and int(rooms[b]) == 0):
                rooms[b] = 1
                marks[b] = a
                newrate.append(b)
            elif (j == b and int(rooms[a]) == 0):
                rooms[a] = 1
                marks[a] = b
                newrate.append(a)
    roomsrate.append(newrate)
    if (len(newrate) == 0):
        break
    turn = turn + 1


if(all(rooms) == True):
    print('Yes')
    for i in range(1,n):
        print(str(int(marks[i]) + 1))

else:
    print('No')

Buggy submission (verdict: Runtime Error):
import numpy as np
n,m = map(int, input().split())

routes = []
for i in range(m):
    route = list(map(int, input().split()))
    routes.append(route)

for i in range(m):
    routes[i] = routes[i] - np.ones(2) #道の番号をずらす

rooms = np.zeros(n) # 行ってない部屋は0、行った部屋は1
marks = np.zeros(n) # 部屋におく道標
roomsrate = [[0]] # １回目、２回目、３回目…に行ける部屋
rooms[0] = 1
marks[0] = 1

for i in range roomsrate:
    newrate = []
    for j in range roomsrate[i]: # i回目に行ける部屋を調べる
        for k in range(m):
            a = int(routes[k][0])
            b = int(routes[k][1]) 
            if (j == a or j == b):
                if (int(rooms[b]) == 0):
                    rooms[b] = 1
                    marks[b] = a
                    newrate.append(b)
                elif (int(rooms[a]) == 0):
                    rooms[a] = 1
                    marks[a] = b
                    newrate.append(a)
    roomsrate.append(newrate)
    if(newrate == [])
    break


if(np.all(rooms) == True):
    print('Yes')
    for i in range(1,n):
        print(str(int(marks[i]) + 1))

else:
    print('No')
Problem p02743 (python)

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

d = c - a - b
e = 4*a*b

if(d>0 and d**2 > e):
    print('Yes')
else:
    print('No')

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

d = c - a - b
e = 4*a*b

if(d>0 and d*2 > e):
    print('Yes')
else:
    print(('No')
Problem p02705 (python)

Fixed submission:
import math
p = math.pi
n = int(input())
print(2*n*p)

Buggy submission (verdict: Runtime Error):
find . -name *.c | xargs wc -l | sort -nk1 | awk '{print $2}' | grep -v "total"
Problem p02755 (python)

Fixed submission:
a,b = map(int,input().split())
if b*10 <= a*100/8 < (b+1)*10:
    if int(a*100/8) == a*100/8:
        print(int(a*100/8))
    else:
        print(int(a*100/8)+1)
else:
    if a*100/8 <= b*10 < (a+1)*100/8:
        print(b*10)
    else:
        print(-1)

Buggy submission (verdict: Runtime Error):
a,b = map(int,input().split())
if b*10 <= a*100/8 < (b+1)*10:
    if int(a*100/8) == a*100/8:
        print(int(a*100/8))
    else:
        printf(int(a*100/8)+1)
else:
    if a*100/8 <= b*10 < (a+1)*100/8:
        print(b*10)
    else:
        print(-1)
Problem p02783 (python)

Fixed submission:
h,a = map(int,input().split())
if h%a == 0:
  print(h//a)
else:
  print(h//a+1)

Buggy submission (verdict: Runtime Error):
h,n = map(int,input().split())
L = []
for i in range(n):
  l = list(map(int,input().split()))
  L.append(l)
dp = [10**8]*10001
dp[0] = 0
for i in range(n):
  dp[L[i][0]] = L[i][1]
for i in range(10001):
  for j in range(n):
    if i-L[j][0] >= 0:
      dp[i] = min(dp[i],dp[i-L[j][0]]+L[j][1])
for i in range(9999,-1,-1):
  if dp[i] == 10**8:
    dp[i] = dp[i+1]
print(dp[h])
Problem p02787 (python)

Fixed submission:
h,n = map(int,input().split())
L = []
for i in range(n):
  l = list(map(int,input().split()))
  L.append(l)
dp = [10**8]*10001
dp[0] = 0
for i in range(n):
  dp[L[i][0]] = L[i][1]
for i in range(10001):
  for j in range(n):
    if i-L[j][0] >= 0:
      dp[i] = min(dp[i],dp[i-L[j][0]]+L[j][1])
for i in range(9999,-1,-1):
  if dp[i] > dp[i+1]:
    dp[i] = dp[i+1]
print(dp[h])

Buggy submission (verdict: Runtime Error):
h,n = map(int,input().split())
L = []
for i in range(n):
  l = list(map(int,input().split()))
  L.append(l)
dp = [10**8]*10001
dp[0] = 0
for i in range(n):
  dp[L[i][0]] = L[i][1]
for i in range(10001):
  for j in range(n):
    if i-L[j][0] >= 0:
      dp[i] = min(dp[i],dp[i-L[j][0]]+L[j][1])
for i in range(10000,-1,-1):
  if dp[i] == 10**8:
    dp[i] = dp[i+1]
print(dp[h])

Buggy submission (verdict: Runtime Error):
h,n = map(int,input().split())
L = []
for i in range(n):
  l = list(map(int,input().split()))
  L.append(l)
dp = [10**8]*10001
dp[0] = 0
for i in range(n):
  dp[L[i][0]] = L[i][1]
for i in range(10001):
  for j in range(n):
    if i-L[j][0] >= 0:
      dp[i] = min(dp[i],dp[i-L[j][0]]+L[j][1])
for i in range(10000,-1,-1):
  if dp[i] == 10**8:
    dp[i] = dp[i+1]
print(dp[h])
Problem p02788 (python)

Fixed submission:
import math
import bisect
n,d,a = map(int,input().split())
L = []
kyo = []
for i in range(n):
    x,h = map(int,input().split())
    L.append([x,h])
    kyo.append(x)
L.sort()
kyo.sort()
ans = 0
imos = [0]*(n+1)
cur = 0
ran = 2*d
for i in range(n):
    if imos[cur] < L[cur][1]:
        t = int(math.ceil((L[cur][1]-imos[cur])/a))
        ans += t
        imos[cur] += t*a
        lim = bisect.bisect_right(kyo, kyo[cur]+ran)
        imos[lim] -= t*a
    imos[i+1] += imos[i]
    cur += 1
print(ans)

Buggy submission (verdict: Runtime Error):
n,d,a = map(int,input().split())
L = []
T = []
U = []
hitpoint = []
for i in range(n):
  p,q = map(int,input().split())
  L.append([p,q,0])
  T.append(p)
  U.append(p)
  hitpoint.append(q)
U.sort()
for i in range(n):
  k = bisect.bisect_right(U,T[i]+2*d)
  L[i][2] = k
L.sort()
start = 0
ans = 0
while start != n:
  t = hitpoint[start]//a
  if hitpoint[start]%a == 0:
    attack = t
  else:
    attack = t+1
  ans += attack
  cur = attack*a
  look = L[start][2]
  flag = False
  ne = 0
  for i in range(look-start):
    if start+i <= n-1:
      if (hitpoint[start+i] - cur <= 0):
        hitpoint[start+i] = 0
      else:
        if not flag:
          ne = i
          flag = True
        hitpoint[start+i] -= cur
  if ne == 0:
    start += 1
  else:
    start += ne
print(ans)

Buggy submission (verdict: Runtime Error):
n,d,a = map(int,input().split())
L = []
T = []
U = []
hitpoint = []
for i in range(n):
  p,q = map(int,input().split())
  L.append([p,q,0])
  T.append(p)
  U.append(p)
  hitpoint.append(q)
U.sort()
for i in range(n):
  k = bisect.bisect_right(U,T[i]+2*d)
  L[i][2] = k
L.sort()
start = 0
ans = 0
while start != n:
  t = hitpoint[start]//a
  if hitpoint[start]%a == 0:
    attack = t
  else:
    attack = t+1
  ans += attack
  cur = attack*a
  look = L[start][2]
  flag = False
  ne = 0
  for i in range(look-start):
    if start+i <= n-1:
      if (hitpoint[start+i] - cur <= 0):
        hitpoint[start+i] = 0
      else:
        if not flag:
          ne = i
          flag = True
        hitpoint[start+i] -= cur
  if ne == 0:
    start += 1
  else:
    start += ne
print(ans)
Problem p02804 (python)

Fixed submission:
import math
mod = 10**9+7
n,k = map(int,input().split())
b = math.factorial(k-1)%mod
fact = [0]*(n-k+1)
a = math.factorial(k-1)%mod
c = 1
for i in range(k-1, n):
    if i == k-1:
        fact[0] = (a*pow(b*c, mod-2, mod))%mod
    else:
        a = a*i%mod
        c = c*(i-k+1)%mod
        fact[i-k+1] = (a*pow(b*c, mod-2, mod))%mod
A = list(map(int,input().split()))
A.sort()
ans = 0
for i in range(k-1,n):
    ans += fact[i-k+1]*(A[i]-A[n-i-1])
    ans %= mod
print(ans)

Buggy submission (verdict: Runtime Error):
import math
mod = 10**9+7
def comb(p,q):
    a = math.factorial(p)%mod
    b = math.factorial(q)%mod
    c = math.factorial(p-q)%mod
    return (a*pow(b*c, mod-2, mod))%mod
n,k = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
maxlist = []
ans = 0
for i in range(n-k,n+1):
    maxlist.append(comb(i-1,k-1))
for i in range(n-k,n+1):
    ans += (maxlist[i-n+k]*A[i-1])%mod
    ans %= mod
for i in range(n-k+1):
    ans += mod-((A[i]*maxlist[k-i])%mod)
    ans %= mod
print(ans)

Buggy submission (verdict: Runtime Error):
import math
mod = 10**9+7
def comb(p,q):
    a = math.factorial(p)%mod
    b = math.factorial(q)%mod
    c = math.factorial(p-q)%mod
    return (a*pow(b*c, mod-2, mod))%mod
n,k = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
maxlist = []
ans = 0
for i in range(n-k,n+1):
    maxlist.append(comb(i-1,k-1))
for i in range(n-k,n+1):
    ans += (maxlist[i-n+k]*A[i-1])%mod
    ans %= mod
for i in range(n-k+1):
    ans += mod-((A[i]*maxlist[k-i])%mod)
    ans %= mod
print(ans)
Problem p02814 (python)

Fixed submission:
n,m = map(int,input().split())
A = list(map(int,input().split()))
def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b, a%b)
cur = 0
if n != 1:
    t = A[0]
    while t%2 == 0:
        cur += 1
        t = t//2
        flag = True
    for i in range(1,n):
        temp = 0
        s = A[i]
        while s%2 == 0:
            temp += 1
            s = s//2
        if temp != cur:
            flag = False
            break
    if flag:
        g = A[0]*A[1]//(4*gcd(A[0]//2, A[1]//2))
        for i in range(2, n):
            u = g
            v = A[i]//2
            p = u*v//gcd(u,v)
            g = p
        if g <= m:
            print(int((m/g-1)/2)+1)
        else:
            print(0)
    else:
        print(0)
else:
    if A[0] <= 2*m:
        print(int(((2*m/A[0])-1)/2)+1)
    else:
        print(0)

Buggy submission (verdict: Runtime Error):
n,m = map(int,input().split())
A = list(map(int,input().split()))
def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b, a%b)
cur == 0
if n != 1:
    while A[0]%2 == 0:
        cur += 1
        A[0] = A[0]//2
        flag = True
    for i in range(1,n):
        temp = 0
        while A[i]%2 == 0:
            temp += 1
            A[i] = A[i]//2
        if temp != cur:
            flag = False
            break
    if flag:
        g = A[0]*A[1]//(4*gcd(A[0]//2, A[1]//2))
        for i in range(2, n):
            u = g
            v = A[i]//2
            p = u*v//gcd(u,v)
            g = p
        if g <= 2*m:
            print(int((m/g-1)/2)+1)
        else:
            print(0)
    else:
        print(0)
else:
    if A[0] <= 2*m:
        print(int((2*m/A[0]-1)/2)+1)
    else:
        print(0)

Buggy submission (verdict: Runtime Error):
n,m = map(int,input().split())
A = list(map(int,input().split()))
def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b, a%b)
ans = 0
g = A[0]*A[1]//(4*gcd(A[0]//2, A[1]//2))
for i in range(2, n):
    u = g
    v = A[i]//2
    p = u*v//gcd(u,v)
    g = p
if g <= m:
    print(int((m/g-1)/2)+1)
else:
    print(0)
Problem p02841 (python)

Fixed submission:
a,b = map(int,input().split())
c,d = map(int,input().split())
if a != c:
  print('1')
else:
  print('0')

Buggy submission (verdict: Runtime Error):
n = int(input())
S = input()
cnt = 0
for i in range(1000):
  hy = i//100
  zyu = (i-hy*100)//10
  ichi = i%10
  cnt_hy = float('inf')
  cnt_zyu = float('inf')
  cnt_ichi = float('inf')
  t = 0
  for j in range(n):
    if int(S[j]) == hy and t == 0:
      cnt_hy = j
      t += 1
    elif int(S[j]) == zyu and t == 1:
      cnt_zyu = j
      t += 1
    elif int(S[j]) == ichi and t == 2:
      cnt_ichi = j
  if cnt_hy < cnt_zyu < cnt_ichi <= n-1:
    cnt += 1
print(cnt)