Problem:
 Score : 400 points    Problem Statement You are given N items. The value of the i -th item (1 \leq i \leq N) is v_i . Your have to select at least A and at most B of these items. Under this condition, find the maximum possible arithmetic mean of the values of selected items. Additionally, find the number of ways to select items so that the mean of the values of selected items is maximized.      Constraints  1 \leq N \leq 50  1 \leq A,B \leq N  1 \leq v_i \leq 10^{15}  Each v_i is an integer.         Input The input is given from Standard Input in the following format:  N  A  B  v_1  v_2 ... v_N       Output Print two lines. The first line should contain the maximum possible arithmetic mean of the values of selected items. The output should be considered correct if the absolute or relative error is at most 10^{-6} . The second line should contain the number of ways to select items so that the mean of the values of selected items is maximized.        Sample Input 1 5 2 2
1 2 3 4 5      Sample Output 1 4.500000
1  The mean of the values of selected items will be maximized when selecting the fourth and fifth items. Hence, the first line of the output should contain 4.5 . There is no other way to select items so that the mean of the values will be 4.5 , and thus the second line of the output should contain 1 .       Sample Input 2 4 2 3
10 20 10 10      Sample Output 2 15.000000
3  There can be multiple ways to select items so that the mean of the values will be maximized.       Sample Input 3 5 1 5
1000000000000000 999999999999999 999999999999998 999999999999997 999999999999996      Sample Output 3 1000000000000000.000000
1

Solution (Python):
import math
        
def combination(n, k):
    return math.factorial(n) // math.factorial(k) // math.factorial(n - k)
            
import collections  
    
n,a,b = map(int,input().split())

t = list(map(int,input().split()))

c = collections.Counter(t)

c = sorted(c.items(), key=lambda x:-x[0])

memo = 0

for k,i in enumerate(c):
    
    memo += i[1]
    if a<=memo:
        ans = 0
        memo2 = 0
        for j in range(k+1):
            if j != k:
                memo2 += c[j][1]
                ans += c[j][0]*c[j][1]
            else:
                ans += c[j][0]*(a-memo2)
        print(ans/a)
        break
if c[0][1] <= a:  
    print(combination(c[j][1],a-memo2))
else:
    ans1=0
    for l in range(a,min(c[0][1],b)+1):
        ans1 += combination(c[j][1],l)
    print(ans1)

Solution (Python):
import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
N,A,B= (int(x) for x in input().split())
v = list(map(int, input().strip().split()))
v.sort(reverse=True)
print(sum(v[0:A])/A)
ctall = 0
ct = 0
for i in range (A):
    if v[i] == v[A-1]:
        ct += 1
answer = 0
for i in range (N):
    if v[i] == v[A-1]:
        ctall += 1
    if v[i] < v[A-1]:
        break
if (ct == A):
    for i in range(A,min(ctall+1,B+1)):
        answer += combinations_count(ctall, i)
    print(answer)
else: print(combinations_count(ctall, ct))

Solution (Python):
n,a,b = map(int, input().split())
v = list(map(int, input().split()))

v.sort(reverse=True)

mx=-1
for i in range(a,b+1):
    mx = max(mx,sum(v[:i])/i)
print(mx)

def modinv(a, mod=10**24+7):
    return pow(a, mod-2, mod)

def comb(n, r, mod=10**24+7):
    r = min(r, n-r)
    res = 1
    for i in range(r):
        res = res * (n - i) * modinv(i+1, mod) % mod
    return res

import collections
c = collections.Counter(v)
ans=0
for i in range(a,b+1):
    if sum(v[:i])/i == mx:
        cnt=1

        c2 = collections.Counter(v[:i])

        for itm in c2.items():
            base_cnt = c[itm[0]]
            cnt*=comb(base_cnt,itm[1])
        ans+=cnt

print(ans)

Solution (Python):
def ncr(n,r):
    g = 1
    for i in range(1,r+1):
        g*=(n-r+i)
        g//=i
    return g
n,a,b= map(int,input().split())
nv = sorted(list(map(int,input().split())),reverse=True)
print(sum(nv[:a])/a)
ndica = {}
ndicfull = {}
conti = 0
fnv=nv[0]
for i,temp in enumerate(nv):
    if i<a:ndica[temp] = ndica.get(temp,0) + 1
    ndicfull[temp] = ndicfull.get(temp,0) + 1
    if temp==fnv:conti=i+1
if fnv == nv[a-1]:
    subb = min(conti,b)
    g=0
    for t in range(a,subb+1):g+=ncr(conti,t)
    print(g)
else:
    if ndicfull[nv[a-1]]==1:print(1)
    else:print(ncr(ndicfull[nv[a-1]],ndica[nv[a-1]]))

Solution (Python):
from math import factorial as f

def comb(n, r):
  return f(n) // (f(r) * f(n-r))

n, a, b = map(int, input().split())
v = list(map(int, input().split()))

v.sort(reverse=True)

print(sum(v[:a])/a)

ans = 0
cnt0 = v.count(v[0])

if cnt0 >= a:
  for i in range(a, min(cnt0, b)+1):
    ans += comb(cnt0, i)
else:
  c = v[a-1]
  cnt1 = 0
  cnt2 = 0
  for i, vi in enumerate(v):
    if vi != c:
      continue
    if i < a:
      cnt1 += 1
    cnt2 += 1
  ans = comb(cnt2, cnt1)

print(ans)

Solution (Python):
import math
N,A,B=map(int,input().split())
a=sorted(list(map(int,input().split())),reverse=True)
dic={}
for i in range(N):
  v=a[i]
  if v not in dic.keys():
    dic[v]=1
  else:
    dic[v]+=1
tmp=0
num_used={}
m=10**18
M=-1
for i in range(A):
  v=a[i]
  m=min(m,v)
  M=max(M,v)
  tmp+=v
  if v not in num_used.keys():
    num_used[v]=1
  else:
    num_used[v]+=1
max_ave=tmp/A
print(max_ave)
if num_used[m]==dic[m]:
  print(1)
elif m==M:
  x=dic[m]
  y=num_used[m]
  cnt=0
  for i in range(y,min(x+1,B-A+y+1)):
    cnt+=math.factorial(x)//math.factorial(i)//math.factorial(x-i)
  print(cnt)
else:
  x=dic[m]
  y=num_used[m]
  cnt=math.factorial(x)//math.factorial(y)//math.factorial(x-y)
  print(cnt)

Solution (Python):
from sys import stdout
printn = lambda x: stdout.write(str(x))
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True 
BIG = 999999999
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

n,a,b = inm()
v = inl()
v.sort(reverse=True)
ave = sum(v[:a])/a
print(ave)
if v[0]>v[a-1]:
    l = a-1
    while l>0 and v[l-1]==v[a-1]:
        l -= 1
    r = a-1
    while r<n-1 and v[r+1]==v[a-1]:
        r += 1
    dend = sor = 1
    
    
    for i in range(a-l):
        dend *= r-l+1-i
        sor *= a-l-i
    p = dend//sor
    
else:
    r = a-1
    while r<n-1 and v[r+1]==v[a-1]:
        r += 1
    
    p = 0
    
    for j in range(a,min(b,r+1)+1):
        dend = sor = 1
        for i in range(j):
            dend *= r+1-i
            sor *= j-i
        p += dend//sor
        
print(p)

Solution (Python):
from math import factorial

n,a,b = map(int,input().split())
v = list(map(int,input().split()))

v.sort(reverse = True)

ans = sum(v[:a]) / a
ans2 = 0

count1 = v.count(v[a-1])

index1 = v.index(v[a-1])

def ncr(x,y):
    return factorial(x) // factorial(y) // factorial(x-y)

if v[0] == v[a-1]:
    for i in range(a, min(b, count1) + 1):
        ans2 += ncr(count1, i)
else:
    ans2 = ncr(count1, a - index1)

print(ans)
print(ans2)

Solution (Python):
N,A,B=map(int,input().split())
v=list(map(int,input().split()))
v.sort(reverse=1)
s=sum(v[:A])
print(s/A)
from math import factorial
t=v[A-1]
p,q=0,0
for i in v:
    if i>t:
        p+=1
    elif i==t:
        q+=1
a=0
def c(n,k):
    return (factorial(n)//factorial(k)//factorial(n-k))
for i in range(A,B+1):
    if p+q>=i:
        a+=c(q,i-p)
    if t!=v[0]:
        break
print(a)

Solution (Python):
n, a, b = map(int, input().split())
v = list(map(int, input().split()))
v.sort(reverse=True)

count = {}
for x in v:
    if x in count:
        count[x] += 1
    else:
        count[x] = 1

fact = [1] * 51
for i in range(1, 51):
    fact[i] = fact[i-1] * i

def comb(a, b):
    return fact[a] // fact[a-b] // fact[b]

ans = 0
if v[0] == v[a-1]:
    b = min(b, count[v[0]])
    for i in range(a, b+1):
        ans += comb(count[v[0]], i)
    print(v[0])
    print(ans)
else:
    c = v[:a].count(v[a-1])
    print(sum(v[:a]) / a)
    print(comb(count[v[a-1]], c))

Solution (Python):
N, A,B,*V = map(int,open(0).read().split())
V = sorted(V)[::-1]
ans1 = sum(V[:A])/A
print(ans1)
f = [1] *51
for i in range(1,51):
  f[i] = f[i - 1] * i
def comb(n,r):
  return f[n]//f[r]//f[n-r]
ans2 = comb(V.count(V[A-1]),V[:A].count(V[A-1]))
if V[0] == V[A-1]:
  for i in range(A+1,B+1):
    ans2 += comb(V.count(V[A-1]),i)
print(ans2)

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque, Counter

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()

fac = [-1] * (10**2+1)

fac[0] = fac[1] = 1

def initNCM(limit):
    for i in range(2, limit):
        fac[i] = fac[i-1] * i

def NCM(n, r):
    return fac[n] / (fac[r] * fac[n-r])

initNCM(100)

def main():
    N, A, B = LI()
    v = sorted(LI())[::-1]
    cnt = Counter(v)
    selected = v[:A]
    print(sum(selected)/A)
    ans = 1
    used = 0
    for x in list(set(selected)):
        used += cnt[x]
    used -= cnt[selected[-1]]
    ans = 0
    if len(list(set(selected))) > 1:
        use_last = A - used
        ans += NCM(cnt[selected[-1]], use_last)
    else:
        for use_last in range(1, N+1):
            if not A <= used + use_last <= B:
                continue
            if use_last > cnt[selected[-1]]:
                continue
            ans += NCM(cnt[selected[-1]], use_last)
    print(int(ans))

main()

Solution (Python):
N,A,B=map(int,input().split())
v=[int(x)for x in input().split()]
v.sort(reverse=True)
a=sum(v[:A])/A
m=min(v[:A])
k=v.count(m)
l=v.index(m)
ans=0
import math
for i in range(A,B+1):
    if i==A:
        ans+=(math.factorial(k)//math.factorial(i-l))//math.factorial(k-i+l)
    else:
        if k-i+l>=0 and a==m:
            ans+=(math.factorial(k)//math.factorial(i-l))//math.factorial(k-i+l)
        else:
            break
            
            
print("{:.6f}".format(a))
print(int(ans))

Solution (Python):
import math
from collections import Counter

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

v.sort(reverse = True)
cnt_v = Counter(v)
ave = []

for i in range(A, B+1):
    ave.append(sum(v[0:i]) / i)

max_ave = max(ave)
ans = 0

for j in range(B-A+1):
    temp = 1
    if ave[j] == max_ave:
        l = v[:A+j]
        cnt_l = Counter(l)
        for key, values in cnt_l.items():
            temp *= (math.factorial(cnt_v[key]) // math.factorial(values) // math.factorial(cnt_v[key] - values))
        ans += temp

print(max_ave)
print(ans)

Solution (Python):
def comb(a,b):
    import math
    return math.factorial(a)//(math.factorial(a-b)*math.factorial(b))

from itertools import accumulate
N,A,B = map(int,input().split())
v = list(map(int,input().split()))
v.sort(reverse=1)
va = v[:A]
maxa = sum(va)/A
maxsum = sum(va)
print(maxa)
count = 1
if va[0] == va[-1]:
    v0 = va[0]
    v0c = v.count(v0)
    ans = comb(v0c,A)
    for i in range(A,B):
        if v[i] == v0:
            ans += comb(v0c,i+1)
    print(ans)
else:
    v1 = va[-1]
    v1c = va.count(v1)
    v1c2 = v.count(v1)
    print(comb(v1c2,v1c))

Solution (Python):
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N,A,B=MI()
    v=LI()
    v.sort(reverse =True)
    a=0
    b=0
    L=[]
    cnt=1
    temp=v[0]
    for i in range(1,N):
        if v[i]!=temp:
            L.append(cnt)
            cnt=1
            temp=v[i]
        else:
            cnt+=1
            
            
    L.append(cnt)
        
    cnt2=0    
    for i in range(len(L)):
        a=cnt2
        cnt2+=L[i]
        if cnt2>A:
            b=L[i]
            break
    temp1=0
    if a!=0:
        temp1=sum(v[:a])/a
    ans1=sum(v[:A])/A
    if a==A:
        b=0
      
    
    def cmb(n, r):
        if (r < 0) or (n < r):
            return 0
        r = min(r, n - r)
        temp=1
        for i in range(r):
            temp*=(n-i)
            
        for i in range(r):
            temp=temp//(i+1)
            
        return temp
        
        
    ans2=0
    if temp1>ans1:
        ans2=cmb(b,A-a)
    else:
        for i in range(A-a,B-a+1):
            ans2+=cmb(b,i)
        
    print(ans1)
    print(ans2)

main()

Solution (Python):
from collections import Counter


def binomial_coefficient(n, r):
    res = 1
    for i in range(r):
        res *= (n - i)
        res //= (i + 1)
    return res


N, A, B = map(int, input().split())
V = list(map(int, input().split()))
V.sort(reverse=True)

C = Counter(V)

ave = sum(V[:A]) / A
num = V[A - 1]
Nnums = C[num]

if num == V[0]:
    B = min(B, Nnums)
    cnt = 0
    for i in range(A, B + 1):
        cnt += binomial_coefficient(Nnums, i)
else:
    for k, v in C.items():
        if k > num:
            A -= v
    cnt = binomial_coefficient(Nnums, A)

print(ave)
print(cnt)

Solution (Python):
def comb(n, r):
    if n < r:
        return 0

    ret = 1
    for i in range(1, r + 1):
        ret = ret * (n - i + 1) // i

    return ret


n, a, b = map(int, input().split())
v = list(map(int, input().split()))

v.sort(reverse=True)
ave = sum(v[:a]) / a

if v[0] == v[a-1]:
    sm = v.count(v[0])
    cnt = 0
    for i in range(a, b + 1):
        cnt += comb(sm, i)

else:
    last = v[a-1]
    select = v[:a].count(last)
    sm = v.count(last)
    cnt = comb(sm, select)

print(ave)
print(cnt)

Solution (Python):

import sys
try:
    from typing import List
except ImportError:
    pass


def comb(n: int, r: int):
    if r > n - r:
        return comb(n, n - r)
    p = q = 1
    for i in range(r):
        p *= n - i
        q *= i + 1
    return p // q


def solve(N: int, A: int, B: int, v: "List[int]"):
    v.sort(reverse=True)
    sl = v[:A]
    print(sum(sl) / A)
    if len(set(sl)) == 1:
        m = sl[0]
        cm = v.count(m)
        ans = 0
        for z in range(A, min(cm, B) + 1):
            ans += comb(cm, z)
        print(ans)
    else:
        m = sl[-1]
        cm = v.count(m)
        print(comb(cm, sl.count(m)))


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    A = int(next(tokens))  
    B = int(next(tokens))  
    v = [int(next(tokens)) for _ in range(N)]  
    solve(N, A, B, v)


if __name__ == '__main__':
    main()

Solution (Python):

n,a,b=map(int,input().split())
lists=list(map(int,input().split()))
lists=sorted(lists)
P=sum(lists[-a:])
print(P/a)

from collections import Counter
J=dict(Counter(lists))
K=dict(Counter(lists[-a:]))
import math
ans=1
sums=0
if J[max(lists)]<a:
    for some in K.keys():
        ans*=(math.factorial(J[some])//((math.factorial(K[some]))*math.factorial(J[some]-K[some])))
    print(ans)
elif J[max(lists)]>a:
    for i in range(a,min(b,J[max(lists)])+1):
        sums+=math.factorial(J[max(lists)])//(math.factorial(J[max(lists)]-i)*math.factorial(i))
    print(sums)
else:
    print(1)

Solution (Python):
import sys
input = sys.stdin.readline

def main():
    N,A,B = map(int,input().split())
    v = sorted(list(map(int,input().split())),reverse=True)
    use = v[:A]
    print(sum(use)/A)
    fac = [0 for _ in range(N+1)]
    fac[0],fac[1] = 1,1
    
    for i in range(2,N+1):
        fac[i] = (fac[i-1]*i)

    x = v.count(v[A-1])
    y = use.count(use[A-1])
    
    if v[0] == v[A-1]:
        ans = 0
        for i in range(A,min(B,x)+1):
            ans += fac[x]//(fac[i]*fac[x-i])
        print(ans)
    else:
        ans = fac[x]//(fac[y]*fac[x-y])
        print(ans)

if __name__ == "__main__":
    main()

Solution (Python):
N,A,B = [int(i) for i in input().split()]
v = [int(i) for i in input().split()]
v.sort()
v.reverse()
cum = [v[0]]

def comb(n, k):
    if k>n:
        return 0
    ans = 1
    for i in range(k):
        ans *= n-i
    for j in range(k):
        ans = ans//(j+1)
    return ans

for i in range(1,N):
    cum += [cum[i-1] + v[i]]
print('{:.10f}'.format(cum[A-1]/A))
target = v[A-1]
n = v.count(target)
fromk = (A-1) - v.index(target) + 1
if v[0] == target:
    ans = 0
    for i in range(A, min(B,n)+1):
        ans += comb(n, i)
    print(ans)
else:
    
    ans = comb(n, fromk)
    print(ans)

Solution (Python):
from math import factorial as f
def comb(n, k):
  return f(n)//f(k)//f(n-k)

n, a, b = map(int, input().split())
V = sorted(map(int, input().split()))
s = sum(V[-a:]) / a
print(s)
small = V[-a]
cnt = V[-a:].count(small)
total = V.count(small)
if V[-1] != small:
  ans = comb(total, cnt)
else:
  ans = 0
  for i in range(a, min(b, total)+1):
    ans += comb(total, i)
print(ans)

Solution (Python):
n, a, b = map(int, input().split())
v = list(map(int, input().split()))
dp = [[0] * (n + 1) for _ in range(n + 1)]
d = [[0] * (n + 1) for _ in range(n + 1)]
d[0][0] = 1
for i in range(n):
    for j in range(i + 1):
        if dp[i + 1][j] < dp[i][j]:
            d[i + 1][j] = d[i][j]
            dp[i + 1][j] = dp[i][j]
        elif dp[i + 1][j] == dp[i][j]:
            d[i + 1][j] += d[i][j]
        if dp[i + 1][j + 1] < dp[i][j] + v[i]:
            d[i + 1][j + 1] = d[i][j]
            dp[i + 1][j + 1] = dp[i][j] + v[i]
        elif dp[i + 1][j + 1] == dp[i][j] + v[i]:
            d[i + 1][j + 1] += d[i][j]
ans = 0
idx = float('inf')
cnt = 0
for i in range(a, b + 1):
    if dp[n][i] * idx > ans * i:
        ans = dp[n][i]
        idx = i
        cnt = d[n][i]
    elif dp[n][i] * idx == ans * i:
        cnt += d[n][i]
print(ans / idx)
print(cnt)

Solution (Python):
from collections import Counter
n,a,b=map(int,input().split())
V=list(map(int,input().split()))
V.sort()
N=50
bikkuri=[1 for i in range(N+1)]
for i in range(N):
    bikkuri[i+1]=(i+1)*bikkuri[i]
def comb(a,b):
    if b==0:
        return 1
    else:
        return bikkuri[a]//(bikkuri[a-b]*bikkuri[b])
ans1=0
ans2=0
if V[-a]==V[-1]:
    ans1=V[-1]
    VC=Counter(V)
    num=VC[ans1]
    for i in range(a,min(b,num)+1):
        ans2+=comb(num,i)
else:
    ans1=sum(V[-a:])/a
    A=list(set(V[-a:]))
    VC=Counter(V)
    num1=VC[V[-a]]
    VaC=Counter(V[-a:])
    num2=VaC[V[-a]]
    ans2=comb(num1,num2)
print(ans1)
print(ans2)

Solution (Python):
import sys
import numpy as np
from math import factorial

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, A, B = lr()
V = np.array(lr())
V.sort()
if A == 1:
    ave = V[-A]
else:
    ave = V[-A:].sum() / A
print(ave)
left_i = np.searchsorted(V, V[-A], side='left')
right_i = np.searchsorted(V, V[-A], side='right')
num = right_i - left_i
done = N - right_i

bottom = A-done
top = B-done

def combinations_count(n, r):
    ''' 組み合わせ '''
    return factorial(n) // (factorial(n - r) * factorial(r))

answer = combinations_count(num, bottom)
if ave == V[-A] and num > 1:
    for i in range(bottom+1, min(num, top)+1):
        answer += combinations_count(num, i)

print(answer)

Solution (Python):
kai = [1]

s = 1
for i in range(1,51):
    s *= i
    kai.append(s)

n,a,b = map(int,input().split())

vl = list(map(int,input().split()))
vl = sorted(vl)
member = vl[-a:]
ans = sum(vl[-a:]) / len(vl[-a:])
v = vl[-a]
m = vl.count(v)
k = member.count(v)
if member[0] == member[-1]:
    print(ans)
    ans2 = 0
    for i in range(a, min(b, m)+1):
        ans2 += kai[m] // (kai[i] * kai[m-i])
    print(ans2)

else:
    print(ans)
    print(kai[m]//(kai[k] * kai[m-k]))

Solution (Python):
from collections import Counter

from scipy.misc import comb


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

V.sort(reverse = True)
C = Counter(V)

print(sum(V[:A]) / A)

max_value = V[0]



key_value = V[A-1]
if key_value < max_value:
  
  forward_item_count = 0
  for k,v in C.items():
    if k > key_value:
      forward_item_count += v

  print(int(comb(C[key_value], A - forward_item_count, exact=True)))
  exit(0)
  

ans = 0
cnts = C[key_value]
for i in range(A,B+1):
  ans += comb(cnts,i, exact=True)
  
print(int(ans))

Solution (Python):
def factorial(num):
    if num==0 or num==1:
        return 1
    else:
        return num*factorial(num-1)

N,A,B=map(int,input().split())
v=list(map(int,input().split()))
v.sort()
maxsum=0
for i in range(0,A):
    maxsum+=v[N-1-i]
maxaverage=((maxsum*(10**6))//A)/(10**6)

s=v[N-A]
count1=0
count2=0
for i in range(0,A):
    if v[N-1-i]==s:
        count1+=1
for i in range(0,N):
    if v[i]==s:
        count2+=1
if count1!=A:
    way=factorial(count2)//(factorial(count1)*factorial(count2-count1))
    print(maxaverage)
    print(way)
else:
    way=0
    for i in range(A,min(count2,B)+1):
        way+=factorial(count2)//(factorial(i)*factorial(count2-i))
    print(maxaverage)
    print(way)

Solution (Python):
import sys, bisect, math, itertools, string, queue, copy


from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
input = sys.stdin.readline
sys.setrecursionlimit(10**8)

mod = 170141183460469231731687303715884105727 
def inp(): return int(input()) 
def inpm(): return map(int,input().split()) 
def inpl(): return list(map(int, input().split())) 
def inpls(): return list(input().split())  
def inplm(n): return list(int(input()) for _ in range(n)) 
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)] 
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)]) 

def extgcd(a,b):
    r = [1,0,a]
    w = [0,1,b]
    while w[2]!=1:
        q = r[2]//w[2]
        r2 = w
        w2 = [r[0]-q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
        r = r2
        w = w2
    return [w[0],w[1]]
def mod_inv(a,m):
    x = extgcd(a,m)[0]
    return x
    
def nCk(n,k):
    res = 1
    a=n-k
    b=k
    for i in range(1,a+b+1):
        res = res*i%mod
    for i in range(1,a+1):
        res = res*mod_inv(i,mod)%mod
    for i in range(1,b+1):                                 
        res = res*mod_inv(i,mod)%mod
    return res

def main():
    n,a,b = inpm()
    v = inpl()
    v.sort(reverse=True)
    sumation = 0
    for i in range(a):
        sumation += v[i]
    print(sumation/a)
    left = 0
    right = n-1
    for i in range(a-1,n-1):
        if v[i] != v[i+1]:
            right = i
            break
    for i in range(a-1,0,-1):
        if v[i] != v[i-1]:
            left = i
            break
    number = right - left + 1
    ans = 0
    if v[a-1] != v[0]:
        print(nCk(number,a-left))
        return
    if v[0] == v[a-1]:
        for e in range(a,min(b+1,number+1)):
            ans += nCk(number,e)
        print(ans)
    else:
        print(nCk(number,a-left+1))

if __name__ == "__main__":
    main()

Solution (Python):
from collections import Counter
import math
n, a, b = map(int, input().split())
v = list(map(int, input().split()))
v.sort(reverse=True)
MAX = sum(v[:a]) / a
print(MAX)

c = Counter(v)
average_nums = []
for i in range(a, b + 1):
    t = sum(v[:i]) / i
    if t >= MAX:
        average_nums.append(Counter(v[:i]))

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

ans = 0
for num in average_nums:
    multi = 1
    for k, v in num.items():
        multi = multi * nCr(c[k], v)
    ans += multi
print(ans)

Solution (Python):
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, A, B = map(int, input().split())
v = [int(c) for c in input().split()]
v.sort(reverse=True)
m = 0
for i in range(A):
  m += v[i]
ans1 = m/A
ls = []
for j in range(A,B):
  m += v[j]
  if ans1!=m/(j+1):
    break
  ls += [j]
T = v[:A]
t = set(T)
dic1 = {}
dic2 = {}
for c in t:
  dic1[c] = T.count(c)
  dic2[c] = v.count(c)
ans2 = 1
for c in t:
  ans2 *= cmb(dic2[c],dic1[c])
for l in ls:
  dic1[v[l]] += 1
  ans2 += cmb(dic2[c],dic1[c])
print(ans1)
print(ans2)

Solution (Python):
import sys
input = sys.stdin.buffer.readline
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getlist():
    return list(map(int, input().split()))
import heapq
import bisect
import copy
import math
from collections import defaultdict, Counter

def warshall_floyd(d, N):
    for k in range(N):
        for i in range(N):
            for j in range(N):
                d[i * N +j] = min(d[i * N +j], d[i * N + k] + d[k * N + j])
    return d
MOD = 10**9 + 7
INF = 10**10

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

def main():
    n,a,b = getlist()
    nums = getlist()

    cnt = Counter(nums)

    cnt = sorted(cnt.items(), key=lambda x: -x[0])
    
    ans = 0
    tmp_max = 0
    res = 0
    for i in range(a, b+1):
        remain = i
        acc_val = 0
        for it in cnt:
            if it[1] <= remain:
                remain -= it[1]
                acc_val += it[1] * it[0]

            else:
                acc_val += remain * it[0]
                cmb = comb(it[1], remain)
                mean = acc_val / i
                res += comb(50, i)
                if mean == tmp_max:
                    ans += cmb
                elif mean > tmp_max:
                    tmp_max = mean
                    ans = cmb
                
                break

            if remain == 0:
                mean = acc_val / i
                if mean == tmp_max:
                    ans  += 1
                elif mean > tmp_max:
                    tmp_max = mean
                    ans = 1

                break
    print(tmp_max)
    print(ans)

    
    
    
    
    


if __name__ == '__main__':
    main()

"""
9999
3

2916
"""

Solution (Python):
kai = [1]

s = 1
for i in range(1,51):
    s *= i
    kai.append(s)

n,a,b = map(int,input().split())

vl = list(map(int,input().split()))
vl = sorted(vl)
member = vl[-a:]
ans = sum(vl[-a:]) / len(vl[-a:])
v = vl[-a]
m = vl.count(v)
k = member.count(v)
if member[0] == member[-1]:
    print(ans)
    ans2 = 0
    for i in range(a, min(b, m)+1):
        ans2 += kai[m] // (kai[i] * kai[m-i])
    print(ans2)

else:
    print(ans)
    print(kai[m]//(kai[k] * kai[m-k]))

Solution (Python):
from operator import mul
from functools import reduce
from collections import Counter 
from itertools import accumulate

def comb(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom

n,a,b = map(int, input().split())
v = list(map(int, input().split()))
c = Counter(v)
keys = sorted(c.keys(), reverse=True)
acc = [0] + list(accumulate([c[k] for k in keys]))
costs = [0] + list(accumulate([c[k]*k for k in keys]))

d = []
for lim in range(a,b+1):
    for i,k in enumerate(keys):
        if acc[i+1] >= lim:
            d.append((costs[i] + (lim - acc[i]) * k, lim, comb(c[k], lim - acc[i])))
            break
e = sorted([[x[0] / x[1],x[2]] for x in d], reverse=True)
cnt = 0
mx = e[0][0]
i =0
while i < len(e) and mx <= e[i][0]:
    cnt += e[i][1]
    i += 1

print('{:.8f}'.format(mx))
print(cnt)

Solution (Python):
import math
n, a, b = map(int, input().split())
v = list(map(int, input().split()))
v.sort(reverse=True)
dict_num = dict()
def combi(x, y):
    return math.factorial(x) / (math.factorial(x - y) * math.factorial(y))
for i in v:
    if i in dict_num:
        dict_num[i] += 1
    else:
        dict_num[i] = 1
ans = 0
ans_max = 0.0
for i in range(a,b+1):
    k = v[:i]
    ans_max = max(ans_max, sum(k) / i)
for i in range(a,b+1):
    k = v[:i]
    if ans_max == (sum(k) / i) :
        p = 1
        index = 0
        while index < len(k):
            count = 1
            while index + 1 < len(k) and k[index] == k[index + 1]:
                count += 1
                index += 1
            p *= combi(dict_num[k[index]], count)
            index += 1
        ans += p
print(ans_max)
print(int(ans))

Solution (Python):
import sys
sys.stdin.readline

def main():
    N, A, B = map(int, input().split())
    V = list(map(int, input().split()))
    DP1 = [[0] * (N + 1) for _ in range((N + 1))]
    DP2 = [[0] * (N + 1) for _ in range((N + 1))]
    DP2[0][0] = 1
    for i in range(1, N+1):
        DP1[i][0] = DP1[i-1][0]
        DP2[i][0] = DP2[i-1][0]
        for j in range(1, N+1):
            if DP2[i-1][j]:
                if DP1[i-1][j] == DP1[i-1][j-1] + V[i-1]:
                    DP1[i][j] = DP1[i-1][j]
                    DP2[i][j] = DP2[i-1][j] + DP2[i-1][j-1]
                elif DP1[i-1][j] > DP1[i-1][j-1] + V[i-1]:
                    DP1[i][j] = DP1[i-1][j]
                    DP2[i][j] = DP2[i-1][j]
                else:
                    DP1[i][j] = DP1[i-1][j-1] + V[i-1]
                    DP2[i][j] = DP2[i-1][j-1]
            elif DP2[i-1][j-1]:
                DP1[i][j] = DP1[i-1][j-1] + V[i-1]
                DP2[i][j] = DP2[i-1][j-1]
    mx = max(DP1[N][n]/n for n in range(A, B+1))
    print(mx)
    print(sum(DP2[N][n] for n in range(A, B+1) if DP1[N][n]/n == mx))

if __name__ == "__main__":
    main()

Solution (Python):
import sys
input = sys.stdin.buffer.readline

from collections import defaultdict

N, A, B = map(int, input().split())
V = list(map(int, input().split()))
MOD = 10 ** 100 + 7

g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]
 
def comb(n, r, mod):
  if r < 0 or r > n:
    return 0
  r = min(r, n - r)
  return g1[n] * g2[r] * g2[n - r] % mod
 
for i in range(2, 50 + 1):
  g1.append((g1[-1] * i) % MOD)
  inverse.append((-inverse[MOD % i] * (MOD // i) ) % MOD)
  g2.append((g2[-1] * inverse[-1]) % MOD)

V = sorted(V)[::-1]
counter = defaultdict(int)

answer_ave = sum(V[:A]) / A
print(answer_ave)

for v in V:
  if v >= V[A]:
    counter[v] += 1
  else:
    break
counter = list(counter.items())
counter = sorted(counter)[::-1]
 
if len(counter) == 1:
  answer = 0
  for i in range(A, min(B + 1, counter[0][1] + 1)):
    answer += comb(counter[0][1], i, MOD)
  print(answer)
else:
  take = 0
  for i in range(len(counter) - 1):
    take += counter[i][1]
  answer = comb(counter[-1][1], A - take, MOD)
  print(answer)