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

Fixed submission:
N = int(input())
List = list(map(str, input().split()))
s_l = set(List)
if len(s_l) == 3:
  print("Three")
else:
  print("Four")

Buggy submission (verdict: Runtime Error):
N = int(input())
List = list(map(int, input().split()))
s_l = set(List)
if len(s_l) == 3:
  print("Three")
else:
  print("Four")
Problem p03457 (python)

Fixed submission:
Row = int(input())
List = []
for i in range (Row):
  List.append(list(map(int, input().split())))
x = 0
y = 0
T = 0
flag = True
for i in range(Row):
  reqT = abs(List[i][1]-x)+abs(List[i][2]-y)
  chck= List[i][0] - T - reqT
  if chck < 0 or chck % 2 == 1:
    flag = False
    break
  x = List[i][1]
  y = List[i][2]
  T = List[i][0]
if flag:
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
Row = int(input())
List = []
for i in range (Row):
  List.append(list(map(int, input().split())))
x = 0
y = 0
flag = True
for i in range(Row):
  reqT = List[i][1]-x+List[i][2]-y
  chck= reqT - T
  if chck < 0 or chck % 2 == 1:
    flag = False
    break
  x = List[i][1]
  y = List[i][2]
if flag:
  print("Yes")
else:
  print("No")
Problem p03469 (python)

Fixed submission:
s= input()
res = "2018"+s[4:len(s)]
print(res)

Buggy submission (verdict: Runtime Error):
s= input()
res = "2018"+s[4,len(s)]
print(res)
Problem p03470 (python)

Fixed submission:
Row = int(input())
List = []
for i in range (Row):
  List.append(int(input()))
s_l = set(List)
print(len(s_l))

Buggy submission (verdict: Runtime Error):
Row = int(input())
List = []
for i in range (Row):
  List.append(list(map(int, input().split())))
s_l = set(List)
print(len(s_l))
Problem p03486 (python)

Fixed submission:
s = input()
t = input()
List=[]
ListS= list(s)
ListT = list(t)
ListS.sort()
ListT.sort(reverse= True)
S = ""
T = ""
for i in range(len(ListS)):
  S += ListS[i]  
for i in range(len(ListT)):
  T += ListT[i]
if S == T:
  print("No")
else:
  List.append(S)
  List.append(T)
  List.sort()
  if List[0]==S:
    print("Yes")
  else:
    print("No")

Buggy submission (verdict: Runtime Error):
s = input()
t = input()
ListS= list(s)
ListT = list(t)
ListS.sort()
ListT.sort(reverse= True)
S = ""
T = ""
for i in range(len(ListS)):
  S += ListS[i]  
for i in range(len(ListT)):
  T += ListT[i]
if S == T:
  print("No")
else:
  List.append(S)
  List.append(T)
  List.sort()
  if List[0]==S:
    print("Yes")
  else:
    print("No")
Problem p03547 (python)

Fixed submission:
a,b=map(str,input().split())
List = ["A","B","C","D","E","F"]
if a == b:
  print("=")
c = 0
d = 0
for i in range(6):
  if a == List[i]:
    c = i
  if b == List[i]:
    d = i
if c < d:
  print("<")
elif d < c:
  print(">")

Buggy submission (verdict: Runtime Error):
a,b=map(str,input().split())
List = ["A","B","C","D","F"]
if a == b:
  print("=")
c = 0
d = 0
for i in range(6):
  if a == List[i]:
    c = i
  if b == List[i]:
    d = i
if c < d:
  print("<")
elif d < c:
  print(">")
Problem p03563 (python)

Fixed submission:
a = int(input())
b = int(input())
res = 2 * b - a
print(res)

Buggy submission (verdict: Runtime Error):
a = int(input())
b = int(input())
res = 2 * b -A
print(res)
Problem p03573 (python)

Fixed submission:
List = list(map(int, input().split()))
res = 0
for i in range(2):
  for j in range(i+1,3):
    if List[i] == List[j]:
      res = 3 - i - j
print(List[res])

Buggy submission (verdict: Runtime Error):
List = list(map(int, input().split()))
res = 0
for i in range(3):
  for j in range(i,3):
    if List[i] == List[j]:
      res = 6 - i+1 -j+1
print(List[res])
Problem p03574 (python)

Fixed submission:
import copy
H,W=map(int,input().split())
List = []
for i in range (H):
  List.append(input())
resList = copy.deepcopy(List)

def bombCheck(x,y,ListX):  
  a = 0
  b = 0
  res = 0
  if ListX[x][y] == "#":
    return "#"
  for i in range(-1,2,1):
    a = x+i
    if 0<= a < H:
      for j in range(-1,2,1):
        b = y+j
        if 0<= b < W:
          if i == 0 and j ==0:
            pass
          else:
            if List[a][b] == "#":
              res +=1
  return str(res)

for i in range(H):
  resList[i] =""
  for j in range(W):
    resList[i] += bombCheck(i,j,List)
for i in resList:
  print(i)

Buggy submission (verdict: Runtime Error):
import copy
H,W=map(int,input().split())
List = []
for i in range (H):
  List.append(input())
resList = copy.deepcopy(List)

def bombCheck(x,y,ListX):  
  a = 0
  b = 0
  res = 0
  if ListX[x][y] == "#":
    return "#"
  for i in range(-1,2,1):
    a = x+i
    if a<0 or a >= W:
      pass
    else:
      for j in range(-1,2,1):
        b = y+j
        if b<0 or b >= H:
          pass
        else:
          if i == 0 and j ==0:
            pass
          else:
            if List[a][b] == "#":
              res +=1
            else:
              pass
  return str(res)

for i in range(H):
  resList[i] =""
  for j in range(W):
    resList[i] += bombCheck(i,j,List)
for i in resList:
  print(i)
Problem p03610 (python)

Fixed submission:
S = input()
res = ""
for i in range(0,len(S),2):
  res += S[i]
print(res)

Buggy submission (verdict: Runtime Error):
S = input()
res = ""
for i in range(0,N,2):
  res += S[i]
print(res)
Problem p03624 (python)

Fixed submission:
S = input()
List = list(S)
s_l = set(List)
n = 10
res= ""
flag = False
for i in range(97,123):
  if not chr(i) in s_l:
    res = chr(i)
    flag = True
    break
if flag:
  print(res)
else:
  print("None")

Buggy submission (verdict: Runtime Error):
S = input()
List = list(S)
s_l = set(List)
n = 10
res= ""
for i in range(97,113):
  n = s_l.count(chr(i))
  if n == 0:
    res = chr(i)
    break
print(res)
Problem p03657 (python)

Fixed submission:
a,b=map(int,input().split())
if a%3 == 0:
  print("Possible")
elif b%3 == 0:
  print("Possible")
elif (a+b)%3 == 0:
  print("Possible")
else:
  print("Impossible")

Buggy submission (verdict: Runtime Error):
a,b,c=map(int,input().split())
if A%3 == 0:
  print("Possible")
elif B%3 == 0:
  print("Possible")
elif (A+B)%3 == 0:
  print("Possible")
else:
  print("Impossible")
Problem p03680 (python)

Fixed submission:
Row = int(input())
List = []
for i in range (Row):
  List.append(int(input()))
s = 1
res = 0
flag = False
for i in range(Row):
  s = List[s-1]
  res += 1
  if s == 2:
    flag=True
    break
if not flag:
  print(-1)
else:
  print(res)

Buggy submission (verdict: Runtime Error):
Row = int(input())
List = []
for i in range (Row):
  List.append(int(input()))
s = 1
res = 0
flag = False
for i in range(Row):
  s = List[s]
  res += 1
  if s == 2:
    flag=True
    break
if not flag:
  print(-1)
else:
  print(res)
Problem p03729 (python)

Fixed submission:
a,b,c=map(str,input().split())
Flag = 1
if a[len(a)-1]!=b[0]:
  Flag =0
if b[len(b)-1]!=c[0]:
  Flag =0
if Flag == 0:
  print("NO")
else:
  print("YES")

Buggy submission (verdict: Runtime Error):
a,b,c=map(str,input().split())
Flag = 1
if a[len(a)-1]!=b[0]:
  Flag =0
if b[len(b)-1]!=c[0]:
  Flag =0
if Flag = 0:
  print("NO")
else:
  print("YES")
Problem p03944 (python)

Fixed submission:
W,H,N=map(int,input().split())
List = []
for i in range (N):
  List.append(list(map(int, input().split())))
WRange = [0,W]
HRange = [0,H]
for i in range(N):
  if List[i][2] == 1:
    WRange[0] = max(WRange[0],List[i][0])
  elif List[i][2] == 2:
    WRange[1] = min(WRange[1],List[i][0])
  elif List[i][2] == 3:
    HRange[0] = max(HRange[0],List[i][1])
  else:
    HRange[1] = min(HRange[1],List[i][1])
if WRange[1]-WRange[0] >0:
  W = WRange[1]-WRange[0]
else:
  W = 0
if HRange[1]-HRange[0] >0:
  H = HRange[1]-HRange[0]
else:
  H = 0
res = H * W
print(res)

Buggy submission (verdict: Runtime Error):
W,H,N=map(int,input().split())
List = []
for i in range (N):
  List.append(list(map(int, input().split())))
WRange = [0,W]
HRange = [0,H]
for i in range(N):
  if List[i][2] == 1:
    WRange[0] = List[i][0]
  elif List[i][2] == 2:
    WRange[1] = List[i][0]
  elif List[i][2] == 3:
    HRange[0] = List[i][1]
  else List[i][2] == 4:
    HRange[1] = List[i][1]
if WRange[1]-WRange[0] >0:
  W = WRange[1]-WRange[0]
else:
  W = 0
if HRange[1]-HRange[0] >0:
  H = HRange[1]-HRange[0]
else:
  H = 0
res = H * W
print(res)
Problem p03945 (python)

Fixed submission:
S = input()
List = list(S)
trial = 0
for i in range(1,len(List)):
  if List[i] != List[i-1]:
    trial += 1
print(trial)

Buggy submission (verdict: Runtime Error):
S = input()
List = list(S)
trial = 0
for i in range(1,len(List)):
  if List[i] != List[i-1]:
    trial += 1
print(res)
Problem p04029 (python)

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

Buggy submission (verdict: Runtime Error):
N = int(input())
res = int(N(N+1)/2)
print(res)
Problem p04043 (python)

Fixed submission:
A,B,C = map(int,input().split())
res = "NO"
if A == 5 or A == 7:
  if B == 5 or B == 7:
    if C == 5 or C == 7:
      if A+B+C == 17:
        res = "YES"
print(res)

Buggy submission (verdict: Runtime Error):
A,B,C = int(input())
res = "NO"
if A == 5 or A == 7:
  if B == 5 or B == 7:
    if C == 5 or C == 7:
      if A+B+C == 17:
        res = "YES"
print(res)
Problem p04044 (python)

Fixed submission:
N,L=map(int,input().split())
List = []
for i in range (N):
  List.append(str(input()))
List.sort()
res = ""
for i in range(N):
  res+=List[i]
print(res)

Buggy submission (verdict: Runtime Error):
N,L=map(int,input().split())
List = []
for i in range (N):
  List.append(int(input()))
List.sort()
res = ""
for i in range(N):
  res+=List[i]
print(res)
Problem p02573 (python)

Fixed submission:
from networkx import *
print(max(*map(len,connected_components(Graph([*map(str.split,open(0))][1:]))),1,0))

Buggy submission (verdict: Runtime Error):
from networkx import *
print(max(*map(len,connected_components(Graph([*map(str.split,open(0))][1:]))),1))

Buggy submission (verdict: Runtime Error):
from networkx import *
print(max(*map(len,connected_components(Graph([*map(str.split,open(0))][1:])))))

Buggy submission (verdict: Runtime Error):
from networkx import *
print(max(*map(len,connected_components(Graph([*map(str.split,open(0))][1:])))))

Buggy submission (verdict: Runtime Error):
from networkx import *
print(max(*map(len,connected_components(Graph([*map(str,open(0))][1:])))))

Buggy submission (verdict: Runtime Error):
from networkx import *
print(max(*map(len,connected_components(Graph([input().split()][1:])))))
Problem p02609 (python)

Fixed submission:
n=int(input())
x=input()
p=x.count("1")
Ma=[1]+[0]*(n-1)
Mb=[1]+[0]*(n-1)
for i in range(1,n):
  if p>1:
    Ma[i]=Ma[i-1]*2%(p-1)
  else:
    Ma[i]=0
    Ma[0]=0
  Mb[i]=Mb[i-1]*2%(p+1)
Sa=Sb=0
for i in range(n):
  if x[i]=="1":
    Sa+=Ma[n-1-i]
    Sb+=Mb[n-1-i]
for i in range(n):
  a=0
  if x[i]=="1":
    if p==1:
      s=0
    else:
      s=(Sa-Ma[n-1-i])%(p-1)
      a+=1
  else:
    s=(Sb+Mb[n-1-i])%(p+1)
    a+=1
  while(s>0):
    t=0
    r=s
    while(r>0):
      t+=r&1
      r//=2
    s%=t
    a+=1
  print(a)

Buggy submission (verdict: Runtime Error):
n=int(input())
x=input()
p=x.count("1")
Ma=[1]+[0]*(n-1)
Mb=[1]+[0]*(n-1)
for i in range(1,n):
  Ma[i]=Ma[i-1]*2%(p-1)
  Mb[i]=Mb[i-1]*2%(p+1)
Sa=Sb=0
for i in range(n):
  if x[i]=="1":
    Sa+=Ma[n-1-i]
    Sb+=Mb[n-1-i]
for i in range(n):
  a=1
  if x[i]=="1":
    s=(Sa-Ma[n-1-i])%(p-1)
  else:
    s=(Sb+Mb[n-1-i])%(p+1)
  while(s>0):
    t=0
    r=s
    while(r>0):
      t+=r&1
      r//=2
    s%=t
    a+=1
  print(a)
Problem p02660 (python)

Fixed submission:
a,n=0,int(input())
for i in range(2,int(n**0.5+1)):
  x=0
  while(n%i==0):n//=i;x+=1
  j=1
  while(x>=j):a+=1;x-=j;j+=1
print(a+(n>1))

Buggy submission (verdict: Runtime Error):
a,n=0,int(input())
for i in range(2,int(n**0.5+1)):x=0
  while(n%i==0):n//=i;x+=1
  j=1
  while(x>=j):a+=1;x-=j;j+=1
print(1 if n-1 else a)

Buggy submission (verdict: Runtime Error):
import itertools
import copy
n=int(input())
c=0
A=[]
for i in range(2,int(n**0.5+1)):
  if n%i==0:
    a=0
    while(n%i==0):
      n//=i
      a+=1
    A.append(a)
l=len(A)
i=1
while(sum(A)>=l and l>0):
  for j in itertools.combinations_with_replacement(range(l), i):
    for k in j:
      C=deepcopy(A)
      if A[k]==0:
        A[k]=C[k]
        break
      else:
        A[k]-=1
    else:
      c+=1
  B=[]
  for a in A:
    if a!=0:
      B.append(a)
  A=B
  l=len(A)
  i+=1
print(1 if c!=1 and c==0 else c)
Problem p02678 (python)

Fixed submission:
import sys
sys.setrecursionlimit(9**9)
n,m=map(int,input().split())
L=[[] for _ in range(n)]
for i in range(m):
    a,b=map(int,input().split())
    L[a-1].append(b-1)
    L[b-1].append(a-1)
A=[0]+[-1]*(n-1)
B=[[0,L[0]]]
def wfs(A,B):
    C=[]
    f=False
    for b in B:
        for l in b[1]:
            if A[l]==-1:
                A[l]=b[0]
                C.append([l,L[l]])
                f=True
    if f:
        return wfs(A,C)
    else:
        print('Yes')
        for a in A[1:]:
            print(a+1)
wfs(A,B)

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
L=[[] for _ in range(n)]
for i in range(m):
    a,b=map(int,input().split())
    L[a-1].append(b-1)
    L[b-1].append(a-1)
A=[0]+[-1]*(n-1)
B=[[0,L[0]]]
def wfs(A,B):
    C=[]
    f=False
    for b in B:
        for l in b[1]:
            if A[l]==-1:
                A[l]=b[0]
                C.append([l,L[l]])
                f=True
    if f:
        return wfs(A,C)
    else:
        print('Yes')
        for a in A[1:]:
            print(a+1)
wfs(A,B)
Problem p02705 (python)

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

Buggy submission (verdict: Runtime Error):
import math
print(int(input)*2*math.pi)
Problem p02714 (python)

Fixed submission:
from collections import Counter as C
n=int(input())
S=list(input())
a=1
L=C(S).most_common(3)
for l in L:
  a*=l[1]
for i in range(1,n):
  for j in range(n-2*i):
    if len(set((S[j],S[j+i],S[j+2*i])))==3:
      a-=1
print(a if len(L)>2 else 0)

Buggy submission (verdict: Runtime Error):
n=int(input())
s=input()
ans=0
r=g=b=0
R=[0 for _ in range(n)]
G=[0 for _ in range(n)]
B=[0 for _ in range(n)]
for i in range(i):
    if s[i]='R':r+=1
    elif s[i]='G':g+=1
    else:b+=1
    R[i]=r
    G[i]=g
    B[i]=b
for i in range(n):
    if s[i]='R':ans+=G[i]*(B[-1]-B[i])+B[i]*(G[-1]-G[i])
    elif s[i]='G':ans+=R[i]*(B[-1]-B[i])+B[i]*(R[-1]-R[i])
    else:ans+=R[i]*(G[-1]-G[i])+G[i]*(R[-1]-R[i])
print(ans)
Problem p02718 (python)

Fixed submission:
n,m=map(int,input().split())
L=sorted(list(map(int,input().split())),reverse=True)
print('Yes' if all([L[i]*m*4>=sum(L) for i in range(m)]) else 'No')

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
L=sorted(list(map(int,input().split())))
print('Yes' if all([L[i]*m*4>=sum(L) for i in range(m)] else 'No')
Problem p02761 (python)

Fixed submission:
n,m=map(int,input().split())
N="a"*n
for _ in range(m):
    s,c=map(int,input().split())
    s-=1
    if (s==0 and c==0 and n!=1) or (N[s]!="a" and N[s]!=str(c)):
        print(-1)
        exit()        
    else:
        N=N[:s]+str(c)+N[s+1:]
if N[0]=="a" and n!=1:N="1"+N[1:]
N=N.replace("a","0")
print(int(N))

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
N="a"*n
for _ in range(m):
    s,c=map(int,input().split())
    s-=1
    if (s==0 and c==0) or (N[s]!="a" and N[s]!=str(c)):
        print(-1)
        exit()        
    else:
        N=N[:s]+str(c)+N[s+1:]
if N[0]=="a":N[0]="1"
N=N.replace("a","0")
print(int(N))
Problem p02768 (python)

Fixed submission:
n,a,b=map(int,input().split())
c=d=1
e=0
m=10**9+7
for i in range(1,b+1):
    c=(c*(n+1-i))%m
    d=(d*i)%m
    if i==a or i==b:
        e+=c*pow(d,m-2,m)%m
print((pow(2,n,m)-e-1)%m)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(1000000)
def P(a,n,p):
  bi=str(format(n,"b"))
  res=1
  for i in range(len(bi)):
    res=(res*res)%p
    if bi[i]=="1":
      res=(res*a)%p
  return res
n,a,b=map(int,input().split())
a,b=min(a,n-a),min(b,n-b)
m=10**9+7
N=min(n,2*10**5)
inv=[0 for _ in range(max(a,b))]
inv[1]=1
if max(a,b)>1:
  for i in range(2,max(a,b)):
    inv[i]=m-inv[m%i]*(m//i)%m
def C(n,r,a):
  for i in range(r):
    a=a*(n-i)*inv[r-i-1]%m
  return a
A,B=C(n,a,1),C(n,b,1)
print((P(2,n,m)-int(A)-int(B)-1+m)%m)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(9**9)
def P(a,n,p):
  bi=str(format(n,"b"))
  res=1
  for i in range(len(bi)):
    res=(res*res)%p
    if bi[i]=="1":
      res=(res*a)%p
  return res
n,a,b=map(int,input().split())
a,b=min(a,n-a),min(b,n-b)
m=10**9+7
N=min(n,2*10**5)
inv=[0 for _ in range(max(a,b))]
inv[1]=1
if max(a,b)>1:
  for i in range(2,max(a,b)):
    inv[i]=m-inv[m%i]*(m//i)%m
def C(n,r,a):
  for i in range(r):
    a=a*(n-i)*inv[r-i-1]%m
  return a
A,B=C(n,a,1),C(n,b,1)
print((P(2,n,m)-int(A)-int(B)-1+m)%m)

Buggy submission (verdict: Runtime Error):
import sys
from operator import mul
from functools import reduce
sys.setrecursionlimit(9**9)
def P(a,n,p):
  bi=str(format(n,"b"))
  res=1
  for i in range(len(bi)):
    res=(res*res)%p
    if bi[i]=="1":
      res=(res*a)%p
  return res
n,a,b=map(int,input().split())
a,b=min(a,n-a),min(b,n-b)
m=10**9+7
N=min(n,2*10**5)
inv=[0 for _ in range(max(a,b))]
inv[1]=1
if max(a,b)>1:
  for i in range(2,max(a,b)):
    inv[i]=m-inv[m%i]*(m//i)%m
def C(n,r,a):
  for i in range(r):
    a=a*(n-i)*inv[r-i-1]%m
  return a
A,B=C(n,a,1),C(n,b,1)
print((P(2,n,m)-int(A)-int(B)-1+m)%m)
Problem p02774 (python)

Fixed submission:
import numpy as N
n,k=map(int,input().split())
A=N.array(list(map(int,input().split())))
A.sort()
p=A[A>0]
z=N.count_nonzero(A==0)
m=A[A<0]
r=10**19
l=-r
while r-l>1:
    b=(l+r)//2
    c=0
    if b>=0:
        c+=z*n
    c+=A.searchsorted(b//p,side='right').sum()
    c+=n*len(m)-A.searchsorted(-(-b//m),side='left').sum()
    c-=N.count_nonzero(A*A<=b)
    if c//2>=k:
        r=b
    else:
        l=b
print(r)

Buggy submission (verdict: Runtime Error):
import numpy as N
n,k=map(int,input().split())
A=N.array(list(map(int,input().split())))
A.sort()
p=A[A>0]
z=N.count_nonzero(A==0)
m=A[A<0]
r=10**19
l=-r
while r-l>1:
    b=(l+r)//2
    c=0
    if b>=0:
        c+=z*n
    c+=A.searchsorted(b//p,side='right').sum()
    c+=n*len(m)-A.searchsorted(-(-b//m),side='left').sum()
    c-=N.count_nonzero(A*A<=b)
    if c//2>=k:
        r=b
    else:
        l=b
print(r)
Problem p02784 (python)

Fixed submission:
h,n=map(int,input().split())
A=list(map(int,input().split()))
print('No' if sum(A)<h else 'Yes')

Buggy submission (verdict: Runtime Error):
h,n=map(int,input().split())
print('No' if eval(input().replace(" ","+"))<h else 'Yes')
Problem p02797 (python)

Fixed submission:
n,k,s=map(int,input().split())
L=[s]*k+[min(s+1,10**9-1)]*(n-k)
print(' '.join(map(str,L)))

Buggy submission (verdict: Runtime Error):
n,k,s=map(int,input().split())
L=[s]*k+[min(s+1,10**9-1)]*(n-k)
print(''join(L))
Problem p02802 (python)

Fixed submission:
n,m=map(int,input().split())
if m == 0:
  print(0,0)
  exit()
A=[[0,0] for _ in range(n)]
for i in range(m):
  p,s=input().split()
  p=int(p)-1
  if A[p][0]==1:
    continue
  elif s=='AC':
    A[p][0]=1
  else:
  	A[p][1]+=1
ac=0
wa=0
for a in A:
  ac+=a[0]
  if a[0] == 1:wa+=a[1]
print(ac,wa)

Buggy submission (verdict: Runtime Error):
from operator import mul
from functools import reduce
def cmb(n,r):
    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
n,k=map(int,input().split())
A=sorted(list(map(int,input().split())))
s=0
c=int(cmb(n-1,k-1))
for i in range(n-k+1):
  s+=(A[n-1-i]-A[i])*c
  s%=10**9+7
  c=c*(n-k-i)//(n-1-i)
print(s)
Problem p02813 (python)

Fixed submission:
import itertools
A=list(itertools.permutations(range(1,int(input())+1)))
P=tuple(map(int,input().split()))
Q=tuple(map(int,input().split()))
print(abs(A.index(P)-A.index(Q)))

Buggy submission (verdict: Runtime Error):
import itertools
A=list(itertools.permutations(range(1,int(input())+1)))
print(abs(A.index(map(int,input().split()))-A.index(map(int,input().split())))

Buggy submission (verdict: Runtime Error):
import itertool
A=itertool.permutations(range(1,int(input())+1))
print(abs(A.index(list(map(int,input().split())))-A.index(list(map(int,input().split()))))

Buggy submission (verdict: Runtime Error):
import itertool
A=itertool.permutation(range(1,int(input())+1))
print(abs(A.index(list(map(int,input().split())))-A.index(list(map(int,input().split()))))
Problem p02845 (python)

Fixed submission:
input()
I=list(map(int,input().split()))
L=[0,0,0]
a=1
m=10**9+7
for i in I:
  if i in L:
  	a*=L.count(i)
  	L[L.index(i)]+=1
  	a%=m
  else:
    a=0
    break
print(a)

Buggy submission (verdict: Runtime Error):
input()
I=list(map(int,input().split()))
L=[0,0,0]
a=1
m=10**9+7
for i in I:
  a*=L.count(i)
  L[L.index(i)]+=1
  a%=m
print(a)
Problem p02850 (python)

Fixed submission:
import sys
sys.setrecursionlimit(9**9)
n=int(input())
T=[[] for _ in range(n)]
for i in range(n-1):
    a,b=map(int,input().split())
    T[a-1].append([b-1,i])
C=[0]*(n-1)
def f(i,r):
    c=1
    for (x,y) in T[i]:
        c+=(c==r)
        C[y]=c
        f(x,c)
        c+=1
f(0,0)
print(max(C))
for c in C:
    print(c)

Buggy submission (verdict: Runtime Error):
import sys
from heapq import heappop as p
sys.setrecursionlimit(9**9)
n=int(input())
T=[[] for _ in range(n)]
for i in range(n-1):
    a,b=map(int,input().split())
    T[a-1].append([b-1,i])
C=[0]*(n-1)
m=max(map(lambda x:len(x),T))
print(m)
def f(Q):
    R=[]
    for q in Q:
        H=list(range(1,m+1))
        for t in T[q[0]]:
            x=p(H)
            if x==q[1]:
                x=p(H)
            C[t[1]]=x
            if len(T[t[0]])!=0:
                R.append([t[0],x])
    if len(R)!=0:
        return f(R)
f([[0,0]])
for c in C:
    print(c)

Buggy submission (verdict: Runtime Error):
import sys
from heapq import heappop as p
sys.setrecursionlimit(9**9)
n=int(input())
T=[[] for _ in range(n)]
for i in range(n-1):
    a,b=map(int,input().split())
    T[a-1].append([b-1,i])
C=[0]*(n-1)
m=max(map(lambda x:len(x),T))
print(m)
def f(Q):
    R=[]
    for q in Q:
        H=list(range(1,m+1))
        for t in T[q[0]]:
            x=p(H)
            if x==q[1]:
                x=p(H)
            C[t[1]]=x
            if len(T[t[0]])!=0:
            	R.append([t[0],x])
    if len(R)!=0:
    	return f(R)
f([[0,0]])
for c in C:
    print(c)

Buggy submission (verdict: Runtime Error):
import sys
from heapq import heappop as p
sys.setrecursionlimit(9**9)
n=int(input())
T=[[] for _ in range(n)]
for i in range(n-1):
    a,b=map(int,input().split())
    T[a-1].append([b-1,i])
C=[0]*(n-1)
m=max(map(lambda x:lem(x),T))
def f(Q):
    R=[]
    for q in Q:
        H=list(range(1,m))
        for t in T[q[0]]:
            x=p(H)
            if x==q[1]:
                x=p(H)
            C[t[1]]=x
            if len(T[t[0]])!=0:
            	R.append([t[0],x])
    if len(R)!=0:
    	return f(R)
f([[0,0]])
print(max(C))
for c in C:
    print(c)
Problem p02900 (python)

Fixed submission:
from fractions import gcd
a,b=map(int,input().split())
c=gcd(a,b)
d=1
for i in range(2, int(-(-gcd(a,b)**0.5//1))+1):
  if c%i==0:
    d+=1
    while c%i==0:
      c//=i
  if c==1:
    break
if c!=1:
  d+=1
print(d)

Buggy submission (verdict: Runtime Error):
from fractions import gcd
a,b=map(int,input().split())
c=gcd(a,b)
if c==1:
  print(1)
  exit()
D=[]
P=[]
def E(c):
    P=[]
    E=[i+1 for i in range(1,int(c**0.5)+1)]
    while True:
        p=E[0]
        if int(c**0.5)+1<=p:
            return P+E
        P.append(p)
        E=[e for e in E if e%p!=0]
P=E(c)
f=True
for p in P:
  if c%p==0:
    f=False
    break
if f:
  print(2)
  exit()
for i in range(2, int(-(-gcd(a,b)**0.5//1))+1):
  if c%i==0:
    D.append(i)
    while c%i==0:
      c//=i
  if c==1:
    break
print(len(D)+1)
Problem p02918 (python)

Fixed submission:
n,k=map(int,input().split())
S=input()
c=0
d=0
for i in range(n-1):
    if S[i]==S[i+1]:
        c+=1
    if S[i]!=S[i+1]:
        d+=1
d=(d+1)//2
print(c+2*d-1 if (d<=k and S[0]!=S[-1]) else c+2*min(d,k))

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
S=input()
c=0
d=0
for i in range(n):
    if S[i]==S[i+1]:
        c+=1
    if S[i]!=S[i+1]:
        d+=1
print(c+2*k-1 if d<=k and S[0]==S[-1] else c+2*k)