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

Fixed submission:
N,K=map(int,input().split())
A=list(map(int,input().split()))
A.sort()
mod=10**9+7
fan=[1]*(N+1)
for i in range(2,N):
  fan[i]=fan[i-1]*(i)%mod
ans=0
def comb(a,b):
  return fan[a]*pow(fan[b],mod-2,mod)*pow(fan[a-b],mod-2,mod)
for i in range(N-K+1):
  ans+=comb(N-i-1,K-1)*(A[N-i-1]-A[i])
  ans%=mod
print(ans)

Buggy submission (verdict: Runtime Error):
N,K=map(int,input().split())
A=list(map(int,input().split()))
A.sort()
mod=10**9+7
fan=[1]*N+1
for i in range(2,N+1):
  fan[i]=fan[i-1]*(i)%mod
ans=0
def comb(a,b):
  return fan[a]*pow(fan[b],mod-2,mod)*pow(fan[a-b],mod-2,mod)%mod
for i in range(N-K+1):
  for j in range(0,i-K+1)
  ans+=comb(i-j-1,K-1)*(A[N-1-i]-A[j])
  ans%=mod
print(ans)

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
a=list(map(int,input().split()))
mod=10**9+7
a.sort()
def fact(n):
  if n==0:
    return 1
  else:
    s=1
    for i in range(1,n+1):
      s=s*i
def comb(n,k,mod):
  return (fact(n)//fact(k)//fact(n-k))%mod

if k>1:
  s=0
  for i in range(0,n-k):
    for j in range(i+k-1,n-1):
      s+=((a[j]-a[i])*comb(j-i-1,k-2,mod))%mod
  print(s%mod)
else:
  print(0)

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
a=list(map(int,input().split()))
mod=10**9+7
a.sort()
def fact(n):
  if n==0:
    return 1
  else:
    s=1
    for i in range(1,n+1):
      s=s*i
def cmb(n,k,mod):
  return (fact(n)//fact(k)//fact(n-k))%mod

if k>1:
  s=0
  for i in range(0,n-k):
    for j in range(i+k-1,n-1):
      s+=((a[j]-a[i])*comb(j-i-1,k-2,mod))%mod
  print(s%mod)
else:
  print(0)

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
a=list(map(int,input().split()))
mod=10**9+7
a.sort()
def comb(n,k,mod):
  if (r<0 or r>n):
    return 0
  r=min(r,n-r)
  return fact[n]*factinv[r]*factinv[n-r]%mod

N=10**5
fact=[1,1]
factinv=[1,1]
inv=[0,1]

for i in range(2,N+1):
  fact.append((fact[-1]*i)%mod)
  inv.append((-inv[mod%i]*(mod//i))%mod)
  factinv.append((factinv[-1]*inv[-1])%mod)
  
if k>1:
  s=0
  for i in range(0,n-k):
    for j in range(i+k-1,n-1):
      s+=((a[j]-a[i])*comb(j-i-1,k-2,mod))%mod
  print(s%mod)
else:
  print(0)
Problem p02805 (python)

Fixed submission:
from math import sqrt
N=int(input())
XY=[tuple(map(int,input().split())) for _ in range(N)]

def calc(r):
  lst=[]
  for i in range(N-1):
    x1=XY[i][0]
    y1=XY[i][1]
    for j in range(i+1,N):
      x2=XY[j][0]
      y2=XY[j][1]
      diff=sqrt((x1-x2)**2+(y1-y2)**2)
      if diff>2*r:
        return False
      
      h=sqrt(r**2-diff**2/4)
      if x1==x2:
        ny=(y1+y2)/2
        lst.append([x1-h,ny])
        lst.append([x1+h,ny])
      elif y1==y2:
        nx=(x1+x2)/2
        lst.append([nx,y1-h])
        lst.append([nx,y1+h])
      else:
        a=(y2-y1)/(x2-x1)
        b=-1/a
        size=sqrt(1+b**2)
        dx=h/size
        dy=dx*b
        nx=(x1+x2)/2
        ny=(y1+y2)/2
        lst.append([nx+dx,ny+dy])
        lst.append([nx-dx,ny-dy])
  nr=r+10**(-9)
  for x,y in lst:
    flag=True
    for X,Y in XY:
      tmp=(x-X)**2+(y-Y)**2
      if tmp>nr**2:
        flag=False
        break
    if flag:
      return True
  return False
l=0
r=1000
for i in range(100):
  mid=(l+r)/2
  if calc(mid):
    r=mid
  else:
    l=mid
print(r)

Buggy submission (verdict: Runtime Error):
from math import sqrt
N=int(input())
XY=[tuple(map(int,input().split() for _ in range(N)))]

def calc(r):
  lst=[]
  for i in range(N-1):
    x1=XY[i][0]
    y1=XY[i][1]
    for j in range(i+1,N):
      x2=XY[j][0]
      y2=XY[j][1]
      diff=sqrt((x1-x2)**2+(y1-y2)**2)
      if diff>2*r:
        return False
      
      h=sqrt(r**2-diff**2/4)
      if x1==x2:
        ny=(y1+y2)/2
        lst.append([x1-h,ny])
        lst.append([x1+h,ny])
      elif y1==y2:
        nx=(x1+x2)/2
        lst.append([nx,y1-h])
        lst.append([nx,y1+h])
      else:
        a=(y2-y1)/(x2-x1)
        b=-1/a
        size=sqrt(1+b**2)
        dx=h/size
        dy=dx*b
        nx=(x1+x2)/2
        ny=(y1+y2)/2
        lst.append([nx+dx,ny+dy])
        lst.append([nx-dx,ny-dy])
  for x,y in lst:
    flag=True
    for X,Y in XY:
      tmp=(x-X)**2+(y-Y)**2
      if tmp>r**2:
        flag=False
        break
    if flag:
      return True
  return False
l=0
r=1000
for i in range(100):
  mid=(i+r)/2
  if calc(mid):
    r=mid
  else:
    l=mid
print(r)
Problem p02811 (python)

Fixed submission:
K,X=map(int,input().split())
if K*500>=X:
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
def f(A,N,k,x):
  C=[A[(i+k)%N]^x for i in range(N)]
  return C

import numpy as np
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))

M=max(A+B)
Msup=2**(int(np.log2(M)+1))

for k in range(0,N):
  for x in range(0,Msup+1):
    if f(A,N,k,x)==B:
      print(k,"",x)

Buggy submission (verdict: Runtime Error):
N,M=map(int,input().split())
A=list(map(int,input().split()))
B=[A[i]//2 for i in range(len(A))]

from fractions import gcd 
x=B[0]
for i in range(1,N):
  x=(x*B[i])//gcd(x,B[i])
lcm=x  
if all((lcm//b)%2==1 for b in B):
  Max=M//lcm
  if MaX%2==1:
    print((Max+1)//2)
  else:
    print((Max)//2)
else:
  print(0)

Buggy submission (verdict: Runtime Error):
N,M=map(int,input().split())
A=list(map(int,input().split()))
B=[A[i]//2 for i in range(len(A))]

import math
ans=B[0]
for i in range(1,N):
  ans=math.gcd(ans,B[i])
mul=B[0]//ans
for j in range(1,N):
  mul=mul*(B[j]//ans)
lcm=ans*mul

if all((lcm//b)%2==1 for b in B):
  Max=M//lcm
  if MaX%2==1:
    print((Max+1)//2)
  else:
    print((Max)//2)
else:
  print(0)

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

def mul(n):
  s=1
  for t in range(1,n+1):
    s=s*t
  return s

def f(x):
  result=0
  M=len(x)
  for i in range (x):
    k=0
    for j in range(i,M):
      if x[i]>x[j]:
        k=k+1
    result=result+k*mul(M-i-1)
  return result

print(abs(f(P)-f(Q)))

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

def mul(n):
  s=1
  for t in range(1,n+1):
    s=s*t
  return s

def f(x):
  result=0
  M=len(x)
  for i in range (x):
    k=0
    for j in range(i,M):
      if x[i]>x[j]:
        k=k+1
      result=result+k*mul(M-i-1)
  return result

print(f(P)-f(Q))
Problem p02812 (python)

Fixed submission:
N=int(input())
S=str(input())
print(S.count("ABC"))

Buggy submission (verdict: Runtime Error):
N=int(input())
S=[str(input()) for i in range N]
print(S.count("ABC"))

Buggy submission (verdict: Runtime Error):
N=int(input())
S=[input() for i in range (N)]
S.count("ABC")
Problem p02813 (python)

Fixed submission:
def mul(n):
  s=1
  for t in range(1,n+1):
    s=s*t
  return s

def f(x):
  result=0
  N=len(x)
  for i in range (N):
    k=0
    for j in range(i,N):
      if x[i]>x[j]:
        k=k+1
    result=result+k*mul(N-i-1)
  return result

N=int(input())
P=list(map(int,input().split()))
Q=list(map(int,input().split()))

print(abs(f(P)-f(Q)))

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

def mul(n):
  s=1
  for t in range(1,n+1):
    s=s*t
  return s

def f(x):
  result=0
  M=len(x)
  for i in range (x):
    k=0
    for j in range(i,M):
      if x[i]>x[j]:
        k=k+1
    result=result+k*mul(M-i-1)
  return result

print(abs(f(P)-f(Q)))

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

def mul(n):
  s=1
  for t in range(1,n+1):
    s=s*t
  return s

def f(x):
  result=0
  M=len(x)
  for i in range (x):
    k=0
    for j in range(i,M):
      if x[i]>x[j]:
        k=k+1
    result=result+k*mul(M-i-1)
  return result

print(f(P)-f(Q))

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

def mul(n):
  s=1
  for t in range(n):
    s=s*t
  return s

def f(x):
  result=0
  M=len(x)
  for i in range (x):
    k=0
    for j in range(i,M):
      if x[i]>x[j]:
        k=k+1
    result=result+k*mul(M-i-1)
  return result

print(f(P)-f(Q))
Problem p03448 (python)

Fixed submission:
A = int(input())
B = int(input())
C = int(input())
X = int(input())
tmp = 0
for a in range(0,(A+1)):
    for b in range(0,(B+1)):
        for c in range(0,(C+1)):
            total = 500*a + 100*b + 50*c
            if total == X:
                tmp += 1    
print(tmp)

Buggy submission (verdict: Runtime Error):
A, B, C, X  = map(int, input().split())
tmp = 0
for a in range(0,(A+1)):
    for b in range(0,(B+1)):
        for c in range(0,(C+1)):
            total = 500*a + 100*b + 50*c
            if total == X:
                tmp += 1    
print(tmp)
Problem p02665 (python)

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

SUM = sum(A)

ans = 0
node = 1
for i,leaf in enumerate(A):
    if i == 0:
        non_leaf = 1 - leaf
        ans += 1
        if non_leaf <0:
            print(-1)
            exit()
    else:
        left,right = non_leaf,non_leaf*2
        if SUM < left or non_leaf <= 0:
            print(-1)
            exit()
        node = min(right,SUM)
        ans += node
        non_leaf = node - leaf
        SUM -= leaf
        if non_leaf < 0:
            print(-1)
            exit()

print(ans)

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

MAX = []
e = 1
for a in A:
    if e > 0:
        MAX.append(e)
        e -= a
        e *= 2
    else:
        print(-1)
        exit()

A.reverse()
MAX.reverse()
ans = []
s = 0
for i,a in enumerate(A):
    if MAX[i] < s//2 + a:
        ans[-1] = (MAX[i] - a) * 2 + 1
        s = MAX[i]
    else:
        s += a
        s = min(MAX[i],s)
    ans.append(s)
print(sum(ans))
Problem p02719 (python)

Fixed submission:
N,K = [int(i.strip()) for i in input().split(' ')]

M = N % K
result = M if K -M > M else K-M
print(result)

Buggy submission (verdict: Runtime Error):
K = int(input())
a = 0
count = 0
mm = [0,1]
while True:
    a += 1
    if a == 1:
        for i in range(1,10):
            count += 1
            if count == K:
                print(i)
                exit()

    elif a == 2:
        for i in range(1,10):
            for j in range(0,10):
                if abs(i-j)<=1:
                    count+= 1
                    mm.append(i*10+j)
                    if count == K:
                        print(i*10+j)
                        exit()

    elif a >= 3:
        tmp = [] 
        for i in range(1,10):
            # print(mm)
            for j in mm:
                b = j//(10**(a-2))
                # print(b)
                if abs(i-b) <=1:
                    count+= 1
                    e = i*(10**(a-1))+j
                    # print(count,e)
                    tmp.append(e)
                    if count == K:
                        print(e)
                        exit()
        # print(tmp)
        mm = mm + tmp
Problem p02746 (python)

Fixed submission:
def solve(A,B,C,D, level):
    E = 3**level
    if level == -1:
        return int(abs(A-C) + abs(B-D))
    a,b,c,d = A//E, B//E, C//E, D//E
    if a != c and b != d:
        return int(abs(A-C) + abs(B-D))

    if a == c and b==d:
        return solve(A,B,C,D,level-1)

    if a != c and b==d:
        A,B,C,D = B,A,D,C
        a,b,c,d = b,a,d,c

    if b != d and a == c:
        if a%3 != 1:
            return solve(A,B,C,D,level-1)
        if abs(b-d) == 1:
            return solve(A,B,C,D,level-1)

        if B > D:
            A, B, C, D = C, D, A, B
            a, b, c, d = c, d, a, b

        x = E * a -1
        y1 = E * (b+1) -1
        y2 = E * d
        d = abs(x-A) + abs(y1-B) + abs(y1-y2) + abs(x-C) + abs(y2-D)
        x = E *(a+1)
        d2 = abs(x-A) + abs(y1-B) + abs(y1-y2) + abs(x-C) + abs(y2-D)
        return min(d,d2)

N = int(input())

for i in range(N):
    sg = [int(j.strip())  for j in input().split(' ')]
    s,g = [sg[0]-1,sg[1]-1],[sg[2]-1,sg[3]-1]
    A,B,C,D = s[0],s[1],g[0],g[1]
    print(solve(A,B,C,D,30))

Buggy submission (verdict: Runtime Error):
def mod3(n):
    b= n
    sho = []
    while b >= 1:
        a = int(b % 3)
        b = int((b - a)/3)
        sho.append(a)
    return sho

def cal_dis(ss,tt):
    s,t = mod3(ss),mod3(tt)
    c = 0
    if len(s) == len(t):
        n = len(s)
        k = 0
        b = 0
        flg =0
        for i in range(n):
            if s[i] == 1 and t[i] == 1:
                k = i+1
                b =2
                flg =1
                if i > 0:
                    c = int(3**(k-1)/2) +1
                    amari = ss % (3^k-1)
                    amari2 = tt%(3^k-1)
                    if amari > (3^k-1)/2:
                        amari = (3^k-1) -amari
                    if amari2 > (3^k-1)/2:
                        amari2 = (3^k-1) -amari2
                    b = amari+2 +amari2 
        if flg == 0:
            a = ss - tt if ss > tt else tt-ss
            return a
        else:
            return b

    else:
        return ss - tt if ss > tt else tt-ss

N = int(input())
dic ={}
for i in range(N):
    dic[i] = [int(a) for a in input().split(' ')]

for i in range(N):
    s = [dic[i][0]-1,dic[i][1]-1]
    t = [dic[i][2]-1,dic[i][3]-1]

    print(cal_dis(s[0],t[0]) + cal_dis(s[1], t[1]))

Buggy submission (verdict: Runtime Error):
def mod3(n):
    b= n
    sho = []
    while b >= 1:
        a = int(b % 3)
        b = int((b - a)/3)
        sho.append(a)
    return sho

def cal_dis(ss,tt):
    s,t = mod3(ss),mod3(tt)
    if len(s) == len(t):
        n = len(s)
        k = 0
        for i in range(n):
            if s[i] == 1 and t[i] == 1:
                k = i+1
                if i > 0:
                    b = abs(s[i-1] - t[i-1])
        a = ss - tt if ss > tt else tt-ss
        return a + 2*k - 2* b

    else:
        return ss - tt if ss > tt else tt-ss

N = int(input())
dic ={}
for i in range(N):
    dic[i] = [int(a) for a in input().split(' ')]

for i in range(N):
    s = [dic[i][0]-1,dic[i][1]-1]
    t = [dic[i][2]-1,dic[i][3]-1]


    print(cal_dis(s[0],t[0]) + cal_dis(s[1], t[1]))
Problem p02761 (python)

Fixed submission:
N, M = [int(i) for i in input().split(' ')]
SC = []
for _ in range(M):
    SC.append([int(i) for i in input().split(' ')])

ch = [-1] * N
for s,c in SC:
    if N >1:
        if s == 1 and c == 0:
            print(-1)
            exit()

    if ch[s-1] == -1 or ch[s-1] == c:
        ch[s-1] = c
    else:
        print(-1)
        exit()
s = 10**(N-1) if N >1 else 0
f = 10 ** N if N >1 else 10
for n in range(s,f):
    n = list(str(n))
    flg = 0
    for s,c in SC:
        if not n[s-1] == str(c):
            flg = 1

    if flg == 0:
        print(''.join(n))
        exit()

Buggy submission (verdict: Runtime Error):
N, M = [int(i) for i in input().split(' ')]
SC = []
for _ in range(M):
    SC.append([int(i) for i in input().split(' ')])

for n in range(10**(N-1),10**N):
    n = list(str(n))
    flg = 0
    for s,c in SC:
        if not n[s-1] == str(c):
            flg = 1

    if flg == 0:
        print(''.formatjoin(n))
        exit()
Problem p02774 (python)

Fixed submission:
import numpy as np
N,K = [int(i) for i in input().split(' ')]

A = np.array([int(i) for i in input().split(' ')])

A.sort()
zero = A[A==0]
minus = A[A<0]
plus = A[A>0]

def index_count(x):
    cnt = 0
    if x >= 0:
        cnt += len(zero) * N
    cnt += np.searchsorted(A,x//plus,side='right').sum()
    cnt += (N - np.searchsorted(A,-(-x//minus),side='left')).sum()
    cnt -= np.count_nonzero(A*A <= x)

    assert cnt % 2 == 0
    return cnt //2


left = -10**18
right = 10**18

while left + 1 < right:
    mid = (left +right) //2
    a = index_count(mid)
    if a >= K:
        right = mid
    else:
        left = mid

print(right)

Buggy submission (verdict: Runtime Error):
import numpy as np

N, K = [int(i) for i in input().split(' ')]
A = np.array([int(i) for i in input().split(' ')])
A.sort()

minus = A[A<0]
zero = A[A==0]
plus = A[A>0]

def f(x):
    cnt = 0
    if x>0:
        cnt += len(zero) * N
    cnt += np.searchsorted(A,x//plus,side='right').sum()
    cnt += (N - np.searchsorted(A,-(x//-minus),side='left')).sum()
    cnt -= np.count_nonzero(A*A<=x)

    assert cnt%2 == 0
    return cnt//2

left = -10**18
right = 10**18
while left + 1 < right:
    mid = (left+right) // 2
    if f(mid) >= K:
        right = mid
    else:
        left = mid

print(right)
Problem p02784 (python)

Fixed submission:
H,N= [int(i) for i in input().split(' ')]
A = [int(i) for i in input().split(' ')]

if sum(A)>= H:
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
H,N= [int(i) for i in input().split(' ')]
A = [int(i) for i in input().split(' ')]

A.sort()
if A[-1] + A[-2]>= H:
    print('Yes')
else:
    print('No')
Problem p02787 (python)

Fixed submission:
H ,N = [int(i) for i in input().split()]
AB = []
for _ in range(N):
    AB.append([int(i) for i in input().split(' ')])
 
MAX = 0
for a, b in AB:
    MAX = a if MAX < a else MAX
 
DP = [10**10] * (H+MAX)
DP[0] = 0
for i in range(H):
    for a,b in AB:
        if DP[i] != 10**10:
            DP[i+a] = min(DP[i+a],DP[i] + b)
 
print(min(DP[H:]))

Buggy submission (verdict: Runtime Error):
H ,N = [int(i) for i in input().split()]
AB = []
for _ in range(N):
    AB.append([int(i) for i in input().split(' ')])
 
MAX = 0
for a, b in AB:
    MAX = a if MAX < a else MAX
 
DP = [10**10] * (H+MAX)
DP[0] = 0
for i in range(H):
    for a,b in AB:
        if DP[i] != 10**10:
            DP[i+a] = min(DP[i+a],DP[i] + b)
 
print(min(DP[H:]))
H ,N = [int(i) for i in input().split()]
AB = []
for _ in range(N):
    AB.append([int(i) for i in input().split(' ')])

MAX = 0
for a, b in AB:
    MAX = a if MAX < a else MAX

DP = [10**10] * (H+MAX)
DP[0] = 0
for i in range(H):
    for a,b in AB:
        if DP[i] != 10**10:
            DP[i+a] = min(DP[i+a],DP[i] + b)

print(min(DP[H:]))
提出情報
Problem p02812 (python)

Fixed submission:
N = int(input())
S = list(input())
cnt = 0
for i in range(0,N-2):
    if S[i] =='A' and S[i+1] == 'B' and S[i+2] == 'C':
        cnt += 1

print(cnt)

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

print(cnt)
Problem p02850 (python)

Fixed submission:
from collections import defaultdict,deque

graph = defaultdict(list)
N, *AB = map(int, open(0).read().split())
for a, b in zip(*[iter(AB)] * 2):
    graph[a].append(b)


stack = deque([1])
C = [0] * (N + 1)
while stack:
    v = stack.popleft()
    c = 0
    for w in graph[v]:
        c += 1 + (c + 1 == C[v])
        C[w] = c
        stack.append(w)
        
print(max(C))
print("\n".join(str(C[b]) for b in AB[1::2]))

Buggy submission (verdict: Runtime Error):
from collections import deque
 
N = int(input())
G = [deque([]) for _ in range(N)]
arrive = [0] *N
key = []
for _ in range(N-1):
    a,b = map(int,input().split())
    key.append((a,b))
    G[a-1].append(b-1)
    G[b-1].append(a-1)
 
MAX = 0
for i,g in enumerate(G):
    if MAX < len(g):
        MAX = len(g)
        t = i
 
c_l = list(range(MAX))
C = dict()
 
def bfs(v,c):
    arrive[v] = 1
    cnt = 0
    for w in G[v]:
        if arrive[w] == 0:
            if c == cnt:
                cnt += 1
            bfs(w,cnt)
            if v > w:
                v,w = w,v
            C[(v+1,w+1)] = cnt+1
            cnt += 1
 
bfs(1,-1)
 
print(MAX)
# print(C)
for k in sorted(key):
    print(C[k])

Buggy submission (verdict: Runtime Error):
from collections import deque

N = int(input())
G = [deque([]) for _ in range(N)]
arrive = [0] *N

for _ in range(N-1):
    a,b = map(int,input().split())
    G[a-1].append(b-1)
    G[b-1].append(a-1)

MAX = 0
for i,g in enumerate(G):
    if MAX < len(g):
        MAX = len(g)
        t = i

c_l = list(range(MAX))
C = dict()

def bfs(v,c):
    arrive[v] = 1
    # print(v)
    cnt = 0
    for w in G[v]:
        if arrive[w] == 0:
            if c == cnt:
                cnt += 1
            bfs(w,cnt)
            if v > w:
                v,w = w,v
            C[(v+1,w+1)] = cnt+1
            cnt += 1

bfs(t,-1)

print(MAX)
for k in sorted(C.keys()):
    print(C[k])
Problem p02924 (python)

Fixed submission:
N = int(input())
print(N*(N-1)//2)

Buggy submission (verdict: Runtime Error):
print(sum(list(range(1,int(input())))))
Problem p02928 (python)

Fixed submission:
N, k = map(int,input().split())
A = list(map(int,input().split()))
MOD = 10**9+7

ans = 0
for i in range(N):
    for j in range(N):
        if A[i] > A[j]:
            if i > j:
                ans += k*(k-1)//2
            elif i < j:
                ans += k*(k+1)//2
            ans %= MOD

print(ans)

Buggy submission (verdict: Runtime Error):
N, K = map(int,input().split())
A = list(map(int,input().split()))
MOD = 10**9 + 7

LANK = list(set(A))
LANK.sort()
LANK2 = [0] * 2000
for i, l in enumerate(LANK):
    LANK2[l] = i

LANK = [-1] * N
for i,a in enumerate(A):
    LANK[i] = LANK2[a]

back = [0] * N
for i,a in enumerate(A[::-1]):
    cnt = 0
    for j,a2 in enumerate(A[::-1]):
        if i > j and a > a2:
            cnt += 1
    back[N-1-i] = cnt
    
SUM = 0
tmp = K*(K-1) //2
tmp %= MOD

for i,a in enumerate(A):
    SUM += (LANK[i] * tmp)%MOD
    SUM += (back[i] * K)%MOD
    SUM %= MOD
print(SUM)

Buggy submission (verdict: Runtime Error):
N, K = map(int,input().split())
A = list(map(int,input().split()))
MOD = 10**9 + 7

LANK = list(set(A))
LANK.sort()
LANK2 = [0] * 2000
for i, l in enumerate(LANK):
    LANK2[l] = i

LANK = [-1] * N
for i,a in enumerate(A):
    LANK[i] = LANK2[a]

back = [0] * N
for i,a in enumerate(A[::-1]):
    cnt = 0
    for j,a2 in enumerate(A[::-1]):
        if i > j and a > a2:
            cnt += 1
    back[N-1-i] = cnt
    
SUM = 0
tmp = K(K-1)//2
tmp %= MOD
# print('a')
for i,a in enumerate(A):
    SUM += (LANK[i] * tmp)%MOD
    SUM += (back[i] * K)%MOD
    SUM %= MOD
print(SUM)

Buggy submission (verdict: Runtime Error):
N, K = map(int,input().split())
A = list(map(int,input().split()))
MOD = 10**9 + 7

LANK = list(set(A))
LANK.sort()
LANK2 = [0] * 2000
for i, l in enumerate(LANK):
    LANK2[l] = i

LANK = [-1] * N
for i,a in enumerate(A):
    LANK[i] = LANK2[a]

back = [0] * N
for i,a in enumerate(A[::-1]):
    cnt = 0
    for j,a2 in enumerate(A[::-1]):
        if i > j and a > a2:
            cnt += 1
    back[N-1-i] = cnt
    

SUM = 0
tmp = sum(range((K)))
for i,a in enumerate(A):
    SUM += LANK[i] * tmp + back[i] * K
    SUM %= MOD
print(SUM)

Buggy submission (verdict: Runtime Error):
N, K = map(int,input().split())
A = list(map(int,input().split()))
MOD = 10**9 + 7

LANK = list(set(A))
LANK.sort()
print(LANK)
LANK2 = [0] * 2000
for i, l in enumerate(LANK):
    LANK2[l] = i

LANK = [-1] * N
for i,a in enumerate(A):
    LANK[i] = LANK2[a]

back = [0] * N
for i,a in enumerate(A[::-1]):
    cnt = 0
    for j,a2 in enumerate(A[::-1]):
        if i > j and a > a2:
            cnt += 1
    back[N-1-i] = cnt
    

SUM = 0
tmp = sum(range((K)))
for i,a in enumerate(A):
    SUM += LANK[i] * tmp + back[i] * K
    SUM %= MOD
print(SUM)
Problem p02947 (python)

Fixed submission:
from collections import Counter,defaultdict
import math

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

N = int(input())
A = defaultdict(int)
for _ in range(N):
    c = Counter(list(input()))
    d = sorted(c.items(),key= lambda x:x[0])
    A[tuple(d)] += 1

SUM = 0
for v in A.values():
    if v > 1:
        SUM += combinations_count(v,2)

print(SUM)

Buggy submission (verdict: Runtime Error):
from collections import Counter,defaultdict
import math

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

N = int(input())
A = defaultdict(int)
for _ in range(N):
    c = Counter(list(input()))
    d = sorted(c.items(),key= lambda x:x[0])
    A[tuple(d)] += 1

SUM = 0
for v in A.values():
    SUM += combinations_count(v,2)

print(SUM)