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 numpy as np
from bisect import bisect_left
n, a, b = map(int, input().split())
v = sorted(map(int, input().split()))[::-1]
print(sum(v[:a])/a)
prev = v[0]
cnt = 0
rle = []
for i in v:
    if i != prev:
        rle.append(cnt)
        prev = i
        cnt = 1
    else:
        cnt += 1
rle.append(cnt)
cum = [0]
for i in rle:
    cum.append(cum[-1] + i)

left = bisect_left(cum, a)
m = rle[left-1]
a = a - cum[left-1]
if left == 1:
    b = min(cum[left], b) - cum[left-1]
else:
    b = a

from math import factorial
def comb(n, r):
    return factorial(n) // factorial(n-r) // factorial(r)

ans = 0
for i in range(a, b+1):
    ans += comb(m,i)
print(ans)

Solution (Python):

import itertools
import sys
import math
from functools import lru_cache





from queue import Queue
from operator import mul
from functools import reduce

nCr = {}


def cmb(n, r):
    
    if r == 0 or r == n: return 1
    if r == 1: return n
    if (n, r) in nCr: return nCr[(n, r)]
    nCr[(n, r)] = cmb(n - 1, r) + cmb(n - 1, r - 1)
    return nCr[(n, r)]


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

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


value = list(reversed(sorted(value)))


takai = 0
avg = 0
for i in range(a):
    if value[i] > value[a]:
        takai += 1
    avg += value[i]

avg /= a
print(avg)

cc = value.count(value[a])



if value[0] == value[a]:
    sum = 0
    
    for i in range(a, min(cc, b) + 1):
        sum += cmb(cc , i)
    print(sum)
else:
    print(cmb(cc, a - takai))

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

V.sort(reverse=True)

mean = sum(V[:A]) / A
mean = float(mean)

print(mean)


def fact(n):
    if n == 0 or n == 1: return 1
    return fact(n-1) * n

def comb(n,a):
    return fact(n)//fact(a)//fact(n-a)

from collections import Counter
c = Counter(V)
n = c[V[0]]


if V[0] != V[A-1]:
    n = c[V[A-1]]
    if n > 1:
        idx = V.index(V[A-1]) 
        _A = A - idx
        print( comb( n, _A ) )
    else:
        print(1); exit()

if V[0] == V[A-1]:
    ans = 0
    for i in range(A, min(n+1, B+1)):
        ans += comb(n, i)

    print( ans )

Solution (Python):
from math import factorial as ff
def cc(n,r):
  return ff(n)//ff(n-r)//ff(r)
n,a,b = map(int, input().split())
l = sorted(list(map(int, input().split())), reverse = True)
ans = 0
x = l[:a]
ave = sum(x)/a
m = l.count(x[0-1])
if len(set(x)) == 1:
  for i in range(a,min(b,m)+1):
    ans += cc(m,i)
else:
  p = x.count(x[-1])
  ans = cc(m,p)
print(ave)
print(ans)

Solution (Python):
FACT = [1] * 51
for i in range(1, 51):
    FACT[i] = FACT[i-1] * i


def combination(n, r):
    return FACT[n] // FACT[r] // FACT[n-r]


def main():
    N, A, B = map(int, input().split())
    V = list(map(int, input().split()))
    V.sort(reverse=True)
    print(sum(V[:A]) / A)
    x = V[A-1]
    y = V.count(x)
    ans = 0
    begin = V[:A].count(x)
    end = V[:B].count(x)+1
    for i in range(begin, end):
        if i != begin and x != V[0]:
            continue
        ans += combination(y, i)
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
def conb(a,b):
    now=1
    for i in range(b):
        now=int(now*(a-i)/(i+1))
    return now
N,A,B=map(int,input().split())
V=list(map(int,input().split()))
V.sort(reverse=True)
line=V[A-1]
if V[0]==line:
    ans=0
    for i in range(A,min(V.count(V[0]),B)+1):
        ans+=conb(V.count(V[0]),i)
    print(V[0])
    print(ans)
elif line>V[A]:
    print(sum(V[:A])/A)
    print(1)
else:
    idx=V.index(line)
    cnt=V.count(line)
    print((sum(V[:idx])+line*(A-idx))/A)
    print(conb(cnt,A-idx))

Solution (Python):
import numpy

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

v.sort()

res = numpy.average(v[n - a:])
x = min(v[n - a:])

nCr = {}
def cmb(n, r):
    if r == 0 or r == n: return 1
    if r == 1: return n
    if (n,r) in nCr: return nCr[(n,r)]
    nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)
    return nCr[(n,r)]

if v[n - 1] != x:
    print(res)
    c = v[n-a:].count(x)
    m = v.count(x)
    print(cmb(m, c))
else:
    print(res)
    ans = 0
    m = v.count(x)
    for i in range(a, min(m, b) + 1):
        ans += cmb(m, i)
    print(ans)

Solution (Python):
import math
N,A,B = map(int,input().split())
V = list(map(int,input().split()))
V.sort()
V.reverse()
cur = 0
selectlist = []
for i in range(A,B+1):
    S = 0
    for j in range(i):
        S += V[j]
    S = S/i
    if cur < S:
        cur = S
        selectlist = [i]
    elif cur == S:
        selectlist.append(i)
ans = 0
for p in range(len(selectlist)):
    nowselect = 1
    s = 0
    K = []
    for i in range(selectlist[p]):
        K.append(V[i])
    P = list(set(K))
    P.sort()
    P.reverse()
    for j in range(len(P)):
        cnt = V.count(P[j])
        s += cnt
        if s >= selectlist[p]:
            res = K.count(P[j])
            nowselect *= math.factorial(cnt)//(math.factorial(res)*math.factorial(cnt-res))
            ans += nowselect
        else:
            nowselect *= cnt
print(cur)
print(ans)

Solution (Python):
n, a ,b = map(int, input().split())
v = list(map(int, input().split()))
d = {}
for i in range(n):
  d.setdefault(v[i], 0)
  d[v[i]] += 1
c = sorted(list(set(v)), reverse=True)
c.append(0)
d[0] = 0
fact = [1 for _ in range(n+1)]
for i in range(n):
  fact[i+1] = fact[i] * (i+1)
ave = 0
cnt = 0
for i in range(a, b+1):
  t = i; cur = 0; sum=0
  while(cur<len(c)-1 and d[c[cur]]<=t):
    sum += c[cur] * d[c[cur]]
    t -= d[c[cur]]
    cur += 1
  sum += c[cur] * t
  if ave < (sum / i):
    ave = sum / i
    cnt = fact[d[c[cur]]] // fact[t] // fact[d[c[cur]]-t]
  elif ave == (sum / i):
    cnt += fact[d[c[cur]]] // fact[t] // fact[d[c[cur]]-t]
print(ave)
print(cnt)

Solution (Python):

from collections import defaultdict
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007






"""
n = I()
ans = int(math.log10(n)+1)
for i in range(2,int(n**0.5)+1):
    if n%i == 0:
        ans = min(ans, max(int(math.log10(i)+1),int(math.log10(n//i)+1)))
print(ans)
"""


n,a,b = LI()
v = LI()
v.sort()
v = v[::-1]
ans = v[:a]
d = {}
d[ans[-1]] = 0
if ans[0] != ans[-1]:
    for i in ans:
        if i == ans[-1]:
            d[i] += 1
    k = d[i]
    d[i] = 0
    for i in v:
        if i == ans[-1]:
            d[i] += 1
    c = 1
    for j in range(min(k,d[ans[-1]]-k)):
        c *= d[ans[-1]]-j
        c //= j+1
else:
    for i in v:
        if i == ans[-1]:
            d[i] += 1
    c = 0
    for k in range(a,min(d[ans[-1]],b)+1):
        p = 1
        for j in range(min(k,d[ans[-1]]-k)):
            p *= d[ans[-1]]-j
            p //= j+1
        c += p
print(sum(ans)/a)
print(c)

Solution (Python):

from collections import defaultdict
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007






"""
n = I()
ans = int(math.log10(n)+1)
for i in range(2,int(n**0.5)+1):
    if n%i == 0:
        ans = min(ans, max(int(math.log10(i)+1),int(math.log10(n//i)+1)))
print(ans)
"""


n,a,b = LI()
v = LI()
v.sort()
v = v[::-1]
ans = v[:a]
d = {}
d[ans[-1]] = 0
if ans[0] != ans[-1]:
    for i in ans:
        if i == ans[-1]:
            d[i] += 1
    k = d[i]
    d[i] = 0
    for i in v:
        if i == ans[-1]:
            d[i] += 1
    c = 1
    for j in range(min(k,d[ans[-1]]-k)):
        c *= d[ans[-1]]-j
        c //= j+1
else:
    for i in v:
        if i == ans[-1]:
            d[i] += 1
    c = 0
    for k in range(a,min(d[ans[-1]],b)+1):
        p = 1
        for j in range(min(k,d[ans[-1]]-k)):
            p *= d[ans[-1]]-j
            p //= j+1
        c += p
print(sum(ans)/a)
print(c)

Solution (Python):
import math
N,A,B=map(int,input().split())
v = input().split()
for i in range(N):
    v[i] = int(v[i])

v.sort(reverse=True)

ans1=0
for i in range(A):
    ans1 += v[i]
ans1 /= A
print(ans1)

p = v[A-1]
q = v.count(p)
r = v.index(p)
ans2=0
if not v[0] == v[A-1]:
    
    ans2 = math.factorial(q) // math.factorial(q+r-A) // math.factorial(A-r)
else: 
    for i in range(A,min(q,B)+1):
        
        ans2 += math.factorial(q) // math.factorial(q-i) // math.factorial(i)
print(ans2)

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

v = sorted(v,reverse=True)
max_ave = sum(v[0:a])/a
index_max_ave = -1
for i in range(a,b+1)[::-1]:
  max_ave = max(sum(v[0:i])/(i),max_ave)
  if max_ave == sum(v[0:i])/(i):
    index_max_ave = i

print(max_ave)

def combination(n,r):
    r = min(r,n-r)
    result = 1
    for i in range(n-r+1,n+1):
        result *= i
    for i in range(1,r+1):
        result //= i
    return result


num = v[index_max_ave-1]
for i in range(index_max_ave):
  if num != v[i]:
    print(combination(v[0:index_max_ave].count(num)+v[index_max_ave:n].count(num),v[0:index_max_ave].count(num)))
    exit()

cnt = v.count(num)
ans = 0
for i in range(a,min(b+1,cnt+1)):
  ans += combination(cnt,i)
print(ans)

Solution (Python):
N,A,B=map(int,input().split())
V=list(map(int,input().split()))
V=sorted(V,reverse=True)

def fac(n):
  if n<= 1: return 1
  return n*fac(n-1)
def c (a,b): 
  if b==0: return 1
  return fac(a)//fac(b)//fac(a-b)


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

if V.count(V[0]) >= A:
  ans=0
  for i in range(A, min(B+1,V.count(V[0])+1)):
    ans+=c(V.count(V[0]),i)
else:
  ans=c(V.count(V[A-1]), V[:A].count(V[A-1]))
print(ans)

Solution (Python):
n,a,b=map(int,input().split())
v=list(map(int,input().split()))
v.sort()
def f(x,y):
    c=1
    d=1
    for i in range(x):
        c*=(i+1)
        d*=(y-i)
    return d//c
p=v[n-a:]
g=sum(p)/a
print(sum(p)/a)
w=0
for i in range(a,b+1):
    p=v[n-i:]
    h=sum(p)/i
    if h<g:
        break
    else:
        q=p[0]
        d=v.count(q)
        e=p.count(q)
        w+=f(e,d)
print(w)

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

cc = [[0 for _ in range(51)] for _ in range(51)]
for i in range(51):
  for j in range(i+1):
    if j == 0 or j == i:
      cc[i][j] = 1
    else:
      cc[i][j] = cc[i-1][j-1] + cc[i-1][j]

avg = sum(vlist[:a]) / a
avaln, avalp = 0, 0
for i in range(n):
  if vlist[i] == vlist[a-1]:
    avaln += 1
    if i < a:
      avalp += 1

cnt = 0
if avalp == a:
  for ap in range(a, b+1):
    cnt += cc[avaln][ap]
else:
  cnt += cc[avaln][avalp]

print('%.8f' % avg)
print(cnt)

Solution (Python):
import bisect
from math import factorial
def comb_cnt(n, r):
    return factorial(n) // (factorial(n - r) * factorial(r))

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

maxsum = sum(vs[-a:])
val = vs[-a]
l, r = bisect.bisect_left(vs, val), bisect.bisect_right(vs, val)
nmin, nmax = r - (n - a), r - max(l, n - b)
if r != n:
    ans = comb_cnt(r - l, nmin)
else:
    ans = 0
    for i in range(nmin, nmax + 1):
        ans += comb_cnt(r - l, i)

print(maxsum / a)
print(ans)

Solution (Python):
import sys
import collections

def comb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2, r + 1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p - 1, r, p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result



def main():
    N, A, B = [int(_) for _ in sys.stdin.readline().split()]
    V = sorted([int(_) for _ in sys.stdin.readline().split()], reverse=True)
    D = collections.defaultdict(lambda: 0)
    ans = 0

    for v in V:
        D[v] += 1

    for C in range(A, B+1):
        if (sum(V[:C]) / C) == (sum(V[:A]) / A):
            ans += comb(D[V[C-1]], V[:C].count(V[C-1]))

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

main()

Solution (Python):
import sys
import math
import collections
import itertools
import array
import inspect


sys.setrecursionlimit(1000000)



def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))



def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in input().split()]


def gcd(n, m):
    if n % m == 0:
        return m
    else:
        return gcd(m, n % m)


def gcd_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = gcd(v, L[i])

    return v


def lcm(n, m):
    return (n * m) // gcd(n, m)


def lcm_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = lcm(v, L[i])

    return v



def wfs_d(D, N, K):
    """
    D: 隣接行列(距離付き)
    N: ノード数
    K: 始点ノード
    """

    dfk = [-1] * (N + 1)
    dfk[K] = 0

    cps = [(K, 0)]
    r = [False] * (N + 1)
    r[K] = True
    while len(cps) != 0:
        n_cps = []
        for cp, cd in cps:
            for i, dfcp in enumerate(D[cp]):
                if dfcp != -1 and not r[i]:
                    dfk[i] = cd + dfcp
                    n_cps.append((i, cd + dfcp))
                    r[i] = True

        cps = n_cps[:]

    return dfk



def dfs_d(v, pre, dist):
    """
    v:  現在のノード
    pre: １つ前のノード
    dist: 現在の距離

    以下は別途用意する
    D: 隣接リスト(行列ではない)
    D_dfs_d: dfs_d関数で用いる，始点ノードから見た距離リスト
    """

    global D
    global D_dfs_d

    D_dfs_d[v] = dist

    for next_v, d in D[v]:
        if next_v != pre:
            dfs_d(next_v, v, dist + d)

    return


def sigma(N):
    ans = 0
    for i in range(1, N + 1):
        ans += i
    return ans


def comb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2, r + 1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p - 1, r, p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def bisearch(L, target):
    low = 0
    high = len(L) - 1
    
    while low <= high:
        mid = (low + high) // 2
        guess = L[mid]
        if guess == target:
            return True
        elif guess < target:
            low = mid + 1
        elif guess > target:
            high = mid - 1
    if guess != target:
        return False



dp = None


def main():
    N, A, B = [int(_) for _ in sys.stdin.readline().split()]
    V = sorted([int(_) for _ in sys.stdin.readline().split()], reverse=True)
    D = collections.defaultdict(lambda: 0)
    ans = 0

    for v in V:
        D[v] += 1

    for C in range(A, B+1):
        if (sum(V[:C]) / C) == (sum(V[:A]) / A):
            ans += comb(D[V[C-1]], V[:C].count(V[C-1]))

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

main()

Solution (Python):
import sys
import math
import collections
import itertools
import array
import inspect


sys.setrecursionlimit(1000000)



def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))



def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in input().split()]


def gcd(n, m):
    if n % m == 0:
        return m
    else:
        return gcd(m, n % m)


def gcd_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = gcd(v, L[i])

    return v


def lcm(n, m):
    return (n * m) // gcd(n, m)


def lcm_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = lcm(v, L[i])

    return v



def wfs_d(D, N, K):
    """
    D: 隣接行列(距離付き)
    N: ノード数
    K: 始点ノード
    """

    dfk = [-1] * (N + 1)
    dfk[K] = 0

    cps = [(K, 0)]
    r = [False] * (N + 1)
    r[K] = True
    while len(cps) != 0:
        n_cps = []
        for cp, cd in cps:
            for i, dfcp in enumerate(D[cp]):
                if dfcp != -1 and not r[i]:
                    dfk[i] = cd + dfcp
                    n_cps.append((i, cd + dfcp))
                    r[i] = True

        cps = n_cps[:]

    return dfk



def dfs_d(v, pre, dist):
    """
    v:  現在のノード
    pre: １つ前のノード
    dist: 現在の距離

    以下は別途用意する
    D: 隣接リスト(行列ではない)
    D_dfs_d: dfs_d関数で用いる，始点ノードから見た距離リスト
    """

    global D
    global D_dfs_d

    D_dfs_d[v] = dist

    for next_v, d in D[v]:
        if next_v != pre:
            dfs_d(next_v, v, dist + d)

    return


def sigma(N):
    ans = 0
    for i in range(1, N + 1):
        ans += i
    return ans


def comb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2, r + 1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p - 1, r, p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def bisearch(L, target):
    low = 0
    high = len(L) - 1
    
    while low <= high:
        mid = (low + high) // 2
        guess = L[mid]
        if guess == target:
            return True
        elif guess < target:
            low = mid + 1
        elif guess > target:
            high = mid - 1
    if guess != target:
        return False



dp = None


def main():
    N, A, B = li_input()
    V = sorted(li_input(), reverse=True)
    D = collections.defaultdict(lambda: 0)

    avg = -1
    ans = 0

    for v in V:
        D[v] += 1

    for e in range(A, B+1):
        avg_ = sum(V[:e]) / e

        if avg == -1 or avg_ == avg:
            n = D[V[e-1]]
            r = V[:e].count(V[e-1])
            ans += comb(n, r)
            avg = avg_

    print(avg)
    print(ans)

main()

Solution (Python):
import collections
import math 
N,A,B = map(int, input().split())
x = list(map(int, input().split()))
x.sort()
print(sum(x[-A:])/A)
c = collections.Counter(x)
s=0
ans=0
for i in range(N-1,0,-1):
    t = s
    s+=c.get(x[i])
    if s>=A and t ==0:
        
        for j in range(A,min(c.get(x[i]),B)+1):
            
            ans+=math.factorial(c.get(x[i]))/(math.factorial(c.get(x[i])-j)*math.factorial(j))
        break
    elif s>=A:
        ans=math.factorial(c.get(x[i]))/(math.factorial(c.get(x[i])-(A-t))*math.factorial(A-t))
        break
print(int(ans))

Solution (Python):

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

max_mean = sum(v[:A])/A
print(max_mean)

from collections import Counter
from math import factorial

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

v_count = Counter(v)
ans = 0
if v[0]==v[A-1]:
    n = v_count[v[A-1]]
    for r in range(A, B+1):
        if r>n: break
        ans += comb(n, r)
else:
    
    n = v_count[v[A-1]]
    select_count = Counter(v[:A])
    r = select_count[v[A-1]]
    ans = comb(n,r)
print(ans)

Solution (Python):
N, A, B = map(int, input().split())
v_arr = list(map(int, input().split()))
v_max = max(v_arr)
v_sorted = sorted(v_arr)
ave = 0
last_count = 1 
p_prev = 0

factorial = [1]
for i in range(1, N + 1):
    factorial.append(factorial[i-1] * i)

def combination(n, k):
    if n < k:
        return 0
    elif n == k or k == 0:
        return 1
    elif k == n-1 or k == 1:
        return n
    else:
        return factorial[n] / (factorial[k] * factorial[n - k])

for _ in range(A):
    p = v_sorted.pop()
    if p == p_prev:
        last_count += 1
    else:
        last_count = 1
    ave += p
    p_prev = p
    
ave /= A
print(ave)
        
last_count_all = 0 
for v in v_arr:
    if v == p:
        last_count_all += 1


ans = 0
if p == v_max:
    for i in range(min(last_count_all, B) - last_count + 1):
        ans += combination(last_count_all, last_count + i)
else:
    ans = combination(last_count_all, last_count)
print(int(ans))

Solution (Python):
from collections import OrderedDict
from math import factorial


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


N, A, B = map(int, input().split())
v = list(map(int, input().split()))
v.sort(reverse=True)
counter = OrderedDict()
for i in range(N):
    if v[i] in counter:
        counter[v[i]][0] += 1
    else:
        counter[v[i]] = [1, i + 1]
average = []
for i in range(A, B + 1):
    ave = sum(v[:i]) / i
    num = comb(counter[v[i - 1]][0], i - counter[v[i - 1]][1] + 1)
    average.append([ave, num])
average.sort(key=lambda x: -x[0])
M_arv = average[0][0]
ans = 0
for item in average:
    if item[0] == M_arv:
        ans += item[1]
    else:
        break
print('{:.6f}'.format(M_arv))
print(int(ans))

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

v.sort()
v.reverse()

print("{:.7f}".format(sum(v[0: A]) / A))

cnt = 0
target = v[A - 1]
first = -1

for i, vv in enumerate(v):
    if vv == target:
        if first == -1:
            first = i
        cnt += 1

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

if first == 0:
    
    ans = 0
    for i in range(A, min(cnt, B) + 1):
        ans += comb(cnt, i)
    print(ans)
else:
    print(comb(cnt, A - first))

Solution (Python):
from collections import Counter as c
from functools import lru_cache,reduce

@lru_cache()
def comb(a,b):
    if not a>=b>=0:
        return 0
    if b==1:
        return a
    elif b==0:
        return 1
    return comb(a-1,b)+comb(a-1,b-1)

n,a,b=map(int,input().split())
v=sorted(map(int,input().split()))[::-1]

c1=c(v)
ans1=sum(v[:a])
ans2=0

for i in range(a,b+1):
    if ans1*i!=sum(v[:i])*a:break
    c2=c(v[:i])
    ans2+=reduce(lambda x,y:x*y,map(lambda x:comb(c1[x],c2[x]),c2.keys()))

print(ans1/a,ans2,sep="\n")

Solution (Python):
import math

def func(n, a, b, v):
    v.sort()
    v.reverse()
    target = v[a - 1]
    count = 0
    innerCount = 0
    for i in range(n):
        if v[i] == target:
            if i < a:
                innerCount += 1
            count += 1
    
    if v[0] == target:
        out = 0
        for i in range(a, min(count, b) + 1):
            out += math.factorial(count) \
                   // (math.factorial(count - i)
                       * math.factorial(i))
        print(sum(v[:a])/a)
        print(out)
    elif v[a-1] == v[a]:
        print(sum(v[:a])/a)
        print(math.factorial(count)
              // (math.factorial(count - innerCount)
                  * math.factorial(innerCount)))
    else:
        print(sum(v[:a])/a)
        print(1)
n, a, b = [int(i) for i in input().split()]
v = [int(i) for i in input().split()]
func(n, a, b, v)
"""
func(5, 2, 2, [5, 4, 3, 2, 1])
print()
func(4, 2, 3, [20, 10, 10, 10])
print()
func(5, 1, 5, [1000000000000000, 999999999999999, 999999999999998, 999999999999997, 999999999999996])
print()
func(50, 1, 50, [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1])

"""

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

m = sum(V[:A])/A

cnts = []
cnt = 0
res = None
for i in range(N):
    if res is None or V[i] != res:
        if res is not None:
            cnts.append(cnt)
        cnt = 1
        res = V[i]
    else:
        cnt += 1
cnts.append(cnt)
fac = [1, 1]
for i in range(2, 51):
    fac.append(i*fac[-1])

if cnts[0] >= A:
    ans = 0
    for i in range(A, min(B, cnts[0])+1):
        ans += fac[cnts[0]]//fac[i]//fac[cnts[0]-i]
else:
    ans = 1
    for cnt in cnts:
        if cnt <= A:
            A -= cnt
            B -= cnt
        else:
            ans *= fac[cnt]//fac[A]//fac[cnt-A]
print(m)
print(ans)

Solution (Python):
from itertools import accumulate
import bisect
N, A, B = map(int, input().split())
V = list(map(int, input().split()))
V.sort(reverse=True)

m = sum(V[:A])/A

cnts = []
cnt = 0
res = None
for i in range(N):
    if res is None or V[i] != res:
        if res is not None:
            cnts.append(cnt)
        cnt = 1
        res = V[i]
    else:
        cnt += 1
cnts.append(cnt)
fac = [1, 1]
for i in range(2, 51):
    fac.append(i*fac[-1])

if cnts[0] >= A:
    ans = 0
    for i in range(A, min(B, cnts[0])+1):
        ans += fac[cnts[0]]//fac[i]//fac[cnts[0]-i]
else:
    ans = 1
    for cnt in cnts:
        if cnt <= A:
            A -= cnt
            B -= cnt
            ans *= cnt
        else:
            ans *= fac[cnt]//fac[A]//fac[cnt-A]
print(m)
print(ans)

Solution (Python):
from collections import Counter
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

def inpl(): return list(map(int, input().split()))


N, a, b = inpl()
array = inpl()
value = Counter(array)
array.sort(reverse=True)
ans = {}
sum_a = 0
kosuu = 0
last = -1

for i, num in enumerate(array):
    
    sum_a += num
    if last != num:
        kosuu = 1
        last = num
    else:
        kosuu += 1
    if a <= i+1 <= b:
        ans[sum_a/(i+1)] = ans.get(sum_a/(i+1), 0) + cmb(value[num], kosuu)
print("{:.10f}".format(max(ans)))
print(int(ans[max(ans)]))

Solution (Python):
from itertools import accumulate
n, a, b = map(int, input().split())
lst = list(map(int, input().split()))
lst.sort(reverse=True)
acc = list(accumulate(lst))
ansV = 0
ansList = []
for i in range(a, b + 1):
    value = acc[i - 1] / i
    if value > ansV:
        ansV = value
        ansList = [lst[:i]]
    elif value == ansV:
        ansList.append(lst[:i])

def score(l):
    c1 = l.count(l[-1])
    c2 = lst.count(l[-1])
    return comb(c2, c1)

def comb(x, y):
    return fact(x) // fact(x - y) // fact(y)

mem = {0:1}
def fact(x):
    if x in mem:
        return mem[x]
    mem[x] = x * fact(x - 1)
    return mem[x]

print(ansV)
print(sum(map(score, ansList)))

Solution (Python):


import sys
import math
from collections import defaultdict

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


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


n, a, b = LI()
V = LI()
V.sort()
V.reverse()

cnt = defaultdict(int)
sum_v = 0
for i in range(a):
    sum_v += V[i]
    cnt[V[i]] += 1


print(sum_v / a)


min_v = V[i]
min_cnt = cnt[min_v]
for i in range(a, n):
    v = V[i]
    if v != min_v:
        break
    cnt[v] += 1

if cnt[min_v] == min_cnt:
    print(1)
    exit()
elif len(cnt.keys()) != 1:
    print(comb(cnt[min_v], min_cnt))
    exit()
ans = 0
for i in range(b - a + 1):
    if cnt[min_v] < min_cnt + i:
        break
    ans += comb(cnt[min_v], min_cnt + i)

print(ans)

Solution (Python):
from collections import Counter
from math import factorial


def solve(N, A, B, Vs):
    Vs.sort(reverse=True)

    all_counter = Counter(Vs)
    first = Vs[:A]
    first_c = Counter(Vs[:A])

    second_c = Counter(Vs[A:])
    avg = sum(first) / A

    ans = 1
    for fv, fc in first_c.items():
        if fv == avg:
            ts = 0
            for c in range(A, min(all_counter[fv], B) + 1):
                ts += factorial(all_counter[fv]) // factorial(c) // factorial(all_counter[fv] - c)
            ans *= ts
        else:
            ans *= factorial(all_counter[fv]) // factorial(second_c[fv]) // factorial(fc)
    return "\n".join(["{:0.6f}".format(avg), str(ans)])

if __name__ == "__main__":
    N, A, B = map(int, input().split(" "))
    Vs = list(map(int, input().split(" ")))
    print(solve(N, A, B, Vs))

Solution (Python):


import sys
def input(): return sys.stdin.readline().strip()
sys.setrecursionlimit(10 ** 9)

from collections import Counter

MAX = 51

factorial = [1] * (MAX)
factorial[0] = factorial[1] = 1
for i in range(2, MAX):
    factorial[i] = factorial[i-1] * i


def nCr(n, r):
    
    r = min(r, n-r)
    
    numerator = factorial[n]
    
    denominator = factorial[r] * factorial[n-r]
    return numerator / denominator

round = lambda x: int((x*2+1) // 2)

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


c = Counter(vN)

vN.sort(reverse=True)

mx_avg = sum(vN[:A]) / A
lists = [vN[:A]]
for i in range(A+1, B+1):
    avg = sum(vN[:i]) / i
    if avg == mx_avg:
        
        lists.append(vN[:i])

ans = 0
for l in lists:
    
    c2 = Counter(l)
    combs = 1
    for k, v in c2.items():
        
        combs *= nCr(c[k], v)
    ans += combs
print(mx_avg)
print(round(ans))