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):
from math import factorial
from collections import Counter
def combination(a,b):
    if a < b:
        a, b = b, a
    comb = 1
    for i in range(b):
        comb *= a-i
    comb //= factorial(b)
    return comb

N, A, B = map( int, input().split())
V = list( map( int, input().split()))
V.sort(reverse = True)
print( sum(V[:A])/A)
S = list( set(V))
S.sort(reverse = True)
CV = Counter(V)
ans = 0
K = CV[S[0]]
if A <= K:
    for i in range(A, min(K, B)+1):
        ans += combination(K, i)
else:
    cnt = A
    for x in S:
        if cnt <= CV[x]:
            ans += combination(CV[x],cnt)
            break
        else:
            cnt -= CV[x]
print(ans)

Solution (Python):

from statistics import mean
from math import factorial as fact

n,a,b = map(int, input().split())
v = sorted([int(x) for x in input().split()], reverse=True)
sel = v[:a]
print(mean(sel))

vn = v.count(sel[-1])
na = sel.count(sel[-1])
nb = min(b-a, vn-na)


if na!=len(sel):
    print(fact(vn)//(fact(na)*fact(vn-na)))
elif nb==0:
    print(1)
else:
    ret = 0
    for bi in range(na,na+nb+1):
        ret += fact(vn)//(fact(bi)*fact(vn-bi))
    print(ret)

Solution (Python):
import math

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

n, a, b = map(int, input().split())
v = sorted(list(map(int, input().split())), reverse=True)
ans = 0
ma = sum(v[:a]) / a
for i in range(a, b + 1):
    ave = sum(v[:i]) / i
    if ave == ma:
        p = 1
        for j in set(v[:i]):
            p *= nCr(v.count(j), v[:i].count(j))
        ans += p
print(ma)
print(ans)

Solution (Python):
import bisect
n,a,b = map(int,input().split())
v = list(map(int,input().split()))	
v.sort()
v = v[::-1]

ans = 0
for i in range(a):
    ans += v[i]
print(ans/a)
v = v[::-1]
k = n-bisect.bisect_left(v,v[n-a])
l = n-bisect.bisect_right(v,v[n-a])
ww = k
k = l
l = ww

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

ass = 0

if l -k==0:
    print(1)
elif k != 0:
    ass += jkl[l-k]//jkl[a-k]//jkl[l-a]
    print(ass)
else:
    for i in range(a,min(b,l)+1):
        ass += jkl[l]//jkl[i]//jkl[l-i]
    print(ass)

Solution (Python):
N,A,B = map(int,input().split())
v = list(map(int,input().split()))
v.sort()
v.reverse()
print(sum(v[:A]) / A)

def fuct(n):
	ret = 1
	while n > 1:
		ret *= n
		n -= 1
	return ret

def P(n,k):
	return fuct(n) // fuct(n-k)

def C(n,k):
	return P(n,k) // fuct(k)

if v[0] != v[A-1]:
	num = v.count(v[A-1])
	pick = 0
	for i in range(A):
		if v[i] == v[A-1]:
			pick += 1
	print(C(num, pick))
else:
	num = v.count(v[A-1])
	ans = 0
	for i in range(A, min(num+1, B+1)):
		ans += C(num, i)
	print(ans)

Solution (Python):
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def nCr(n: int, r: int):
    dp = [0] * (n + 1)
    for i in range(n + 1):
        pre = 1
        for j in range(i + 1):
            if j == 0 or j == i:
                dp[j] = 1
            else:
                temp, dp[j] = dp[j], dp[j] + pre
                pre = temp

    return dp[r]


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

    use = V[:A]

    c1 = Counter(V)
    c2 = Counter(use)
    ave = sum(use) / A
    print("{0:.7f}".format(ave))

    if len(set(use)) == 1:
        ans = 0
        num = c1[use[0]]
        for n in range(A, min(B, num) + 1):
            ans += nCr(num, n)
        print(ans)

    else:
        num_total = c1[V[A]]
        num_use = c2[V[A]]
        print(nCr(num_total, num_use))


if __name__ == '__main__':
    main()

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

def li(): return [int(x) for x in stdin.readline().split()]
def li_(): return [int(x)-1 for x in stdin.readline().split()]
def lf(): return [float(x) for x in stdin.readline().split()]
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(ns())
def nf(): return float(ns())


def inv_mod(n:int, mod:int) -> list:
    inv = [0,1]
    for i in range(2,n+1):
        inv.append(mod - ((mod//i)*inv[mod%i]) % mod)
    return inv
       

def fact(n:int, mod:int) -> list:
    fac = [1,1]
    res = 1
    for i in range(2,n+1):
        res = res*i%mod
        fac.append(res)
    return fac


def fact_inv(n:int, inv:list, mod:int) -> list:
    facInv = [1,1]
    for i in range(2,n+1):
        facInv.append(facInv[i-1]*inv[i] % mod)
    return facInv
        

def nCr(n:int, r:int, mod:int, fac:list, facInv:list) -> int:
    if not (0<=r and r<=n):
        return 0
    
    return ((fac[n]*facInv[r]) % mod) * facInv[n-r] % mod

from itertools import accumulate
from collections import Counter

n,a,b = li()
v = li()

v.sort(reverse=True)
v_cum = list(accumulate(v))

ans_cand = []


for i in range(a,b+1):
    ans_cand.append(v_cum[i-1] / i)
    
ans = max(ans_cand)
opt_i = a + ans_cand.index(ans) - 1

cnt_v = Counter(v)
opt_set = v[:opt_i+1]


MOD = 46116646144580591
inv = inv_mod(n, MOD)
fac = fact(n, MOD)
facInv = fact_inv(n,inv, MOD)

pat = 0

if v[0] == v[opt_i]:
    for i in range(a, min(b, cnt_v[v[0]]) + 1):
        pat += nCr(cnt_v[v[0]], i, MOD, fac, facInv)

else:
    cnt_opt = Counter(opt_set)
    pat = nCr(cnt_v[v[opt_i]], cnt_opt[v[opt_i]], MOD, fac, facInv)


        
print(ans)
print(pat)

Solution (Python):

from statistics import mean
from math import factorial as fact

n,a,b = map(int, input().split())
v = sorted([int(x) for x in input().split()], reverse=True)
sel = v[:a]
print(mean(sel))

vn = v.count(sel[-1])
na = sel.count(sel[-1])
nb = min(b-a, vn-na)


if na!=len(sel):
    print(fact(vn)//(fact(na)*fact(vn-na)))
elif nb==0:
    print(1)
else:
    ret = 0
    for bi in range(na,na+nb+1):
        ret += fact(vn)//(fact(bi)*fact(vn-bi))
    print(ret)

Solution (Python):
n,a,b = map(int,input().split())
vs = sorted([int(v) for v in input().split()],reverse=True)
print(sum(vs[:a])/a)
binom = [1]
for k in range(vs.count(vs[a-1])):
    binom = [x+y for (x, y) in zip(binom+[0],[0]+binom)]
if vs[a-1] == vs[0]:
    print(sum(binom[a:b+1]))
else:
    print(binom[a-vs.index(vs[a-1])])

Solution (Python):
from functools import lru_cache
from collections import Counter

@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]

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

e=Counter(v)
for i in range(a,b+1):
  tmp=1
  tg=v[:i]
  d=Counter(tg)
  if sum(tg)/i!=avg:break
  for i in d.keys():
    tmp*=comb(e[i],d[i])
  ans+=tmp

print(avg)
print(ans)

Solution (Python):

"""
Created on Sun Sep  2 17:29:52 2018
ABC057D
@author: maezawa
"""
import math

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

vave = 0
mi = 0
for i in range(a, b+1):
    vsumi = sum(v[:i])
    vavei = vsumi/(i)
    if vave <= vavei:
        vave = vavei
        ci = v.count(v[i-1])
        cin = v[:i].count(v[i-1])
        m = math.factorial(ci)//math.factorial(cin)//math.factorial(ci-cin)
        mi += m
        

print(vave)
print(mi)

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




dp = None


def main():
    N, A, B = li_input()
    V = li_input()

    V.sort(reverse=True)

    maxavg = sum(V[:A]) / A
    V_ = V[:A]

    if V_[0] == V_[-1]:
        n = V.count(V_[0])

        ans = 0
        for r in range(A, min(n + 1, B + 1)):
            ans += comb(n, r)

        print(maxavg)
        print(int(ans))

    else:
        n = V.count(V_[-1])
        r = V_.count(V_[-1])

        ans = comb(n, r)

        print(maxavg)
        print(int(ans))


main()

Solution (Python):
from itertools import accumulate


def pascal(arr, n):
    for i in range(n+1):
        for j in range(i+1):
            if j == 0 or j == i:
                arr[i][j] = 1
            else:
                arr[i][j] = arr[i-1][j-1]+arr[i-1][j]
    return arr


N, A, B = map(int, input().split())
v = sorted([int(x) for x in input().split()], reverse=True)
ans_c = 0
ans_v = [x for x in accumulate(v)]
tmp = v[0]
lft = 0
rgt = N-1
comb = [[0 for _ in range(N+1)] for _ in range(N+1)]
pascal(comb, N)
for i in range(N):
    if v[i] != tmp:
        if i >= A:
            rgt = i-1
            break
        else:
            tmp = v[i]
            lft = i
if lft == 0 and rgt != 0:
    for i in range(A, min(rgt+1, B)+1):
        ans_c += comb[rgt+1][i]
else:
    ans_c = comb[rgt-lft+1][A-lft]
print(ans_v[A-1]/A)
print(ans_c)

Solution (Python):
import math
n,a,b =map(int,input().split())
v = list(map(int,input().split()))
v = sorted(v,key=lambda x:-x)
need = v[:a]
ti = min(need)
no = need.count(ti)
try:
  ona = v[a:].count(ti)
except:
  ona = 0
if ona == 0:
  print(sum(need)/a)
  print(1)
elif no == a:
  ans = 0
  for i in range(b+1-a):
    if ona == -1:
      break
    ans += math.factorial(ona+no)/math.factorial(ona)/math.factorial(no)
    ona -= 1
    no += 1
  print(sum(need)/a)
  print(int(ans))
else:
  print(sum(need)/a)
  print(int(math.factorial(ona+no)/math.factorial(ona)/math.factorial(no)))

Solution (Python):
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpl_s(): return list(input().split())

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

def C(n, r):
	return P(n, r)//math.factorial(r)

N,A,B = inpl()
vv = inpl()
vv.sort()

ave = sum(vv[N-A:])/A
print(ave)

MIN = vv[N-A]
SUM = vv.count(MIN)
used = vv[N-A:].count(MIN)

if vv[-1] != vv[N-A]:
	used = vv[N-A:].count(MIN)
	print(C(SUM,used))
else:
	ans = 0
	for i in range(A,min(SUM,B)+1):
		ans += C(SUM,i)
	print(ans)

Solution (Python):
def factorial(n):
    if n == 1 or n == 0:
        return int(1)
    return int(n*factorial(n-1))

def nck(n,k):
    return int(factorial(n)/(factorial(n-k)*factorial(k)))

ans = 0
ans2 = 0
N,A,B = map(int,input().split())
v = list(map(int,input().split()))
v.sort()
for i in range(A,B+1):
    ans = max(ans,sum(v[N-i:N])/i)
print("{:.7f}".format(ans))

for i in range(A,B+1):
    if ans == sum(v[N-i:N])/i:
        n = v.count(v[N-i])
        k = i - len([p for p in v if p > v[N-i]])
        ans2 += nck(n,k)
print(int(ans2))

Solution (Python):

import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


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


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, A, B, V):
    V.sort(reverse=True)
    mean = sum(V[:A])/A

    print(mean)

    if A == N:
        return 1

    c = V[:A].count(V[A-1])
    d = V[A:].count(V[A-1])

    if d == 0:
        return 1

    @lru_cache(maxsize=None)
    def comb2(n, r):
        if n < 0 or r < 0 or n < r:
            return 0
        elif n == 0 or r == 0:
            return 1
        return comb2(n-1, r-1)+comb2(n-1, r)

    if V[0] == V[A-1]:
        return sum([comb2(c+d, i) for i in range(A, B+1)])

    return comb2(c+d, c)


def main():
    N, A, B = read_int_n()
    V = read_int_n()

    print(slv(N, A, B, V))


if __name__ == '__main__':
    main()

Solution (Python):

import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


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


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, A, B, V):
    V.sort(reverse=True)
    mean = sum(V[:A])/A

    print(mean)

    if A == N:
        return 1

    c = V[:A].count(V[A-1])
    d = V[A:].count(V[A-1])

    if d == 0:
        return 1

    @lru_cache(maxsize=None)
    def comb2(n, r):
        if n < 0 or r < 0 or n < r:
            return 0
        elif n == 0 or r == 0:
            return 1
        return comb2(n-1, r-1)+comb2(n-1, r)

    if V[0] == V[A-1]:
        return sum([comb2(c+d, i) for i in range(A, B+1)])

    return comb2(c+d, c)


def main():
    N, A, B = read_int_n()
    V = read_int_n()

    print(slv(N, A, B, V))


if __name__ == '__main__':
    main()

Solution (Python):

def inv_mod(n:int, mod:int) -> list:
    inv = [-1,1]
    for i in range(2,n+1):
        inv.append(mod - ((mod//i)*inv[mod%i]) % mod)
    return inv
       

def fact(n:int, mod:int) -> list:
    fac = [1,1]
    res = 1
    for i in range(2,n+1):
        res = res*i%mod
        fac.append(res)
    return fac


def fact_inv(n:int, inv:list, mod:int) -> list:
    facInv = [1,1]
    for i in range(2,n+1):
        facInv.append(facInv[i-1]*inv[i] % mod)
    return facInv
        

def nCr(n:int, r:int, mod:int, fac:list, facInv:list) -> int:
    if not (0<=r and r<=n):
        return 0
    
    return ((fac[n]*facInv[r]) % mod) * facInv[n-r] % mod

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


MOD = 9007199254740997
inv = inv_mod(N,MOD)
fac = fact(N,MOD)
facInv = fact_inv(N,inv,MOD)

V.sort(reverse=True)

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

ans = 0
if V[0] == V[A-1]:
    v = V.count(V[A-1])
    u = min(v,B)
    for i in range(A,u+1):
        ans += nCr(v,i,MOD,fac,facInv)

else:
    v_all = V.count(V[A-1])
    v_ch = V[:A].count(V[A-1])
    ans = nCr(v_all,v_ch,MOD,fac,facInv)

print(ans)

Solution (Python):
from copy import deepcopy
from math import factorial as fact
def combi(n, r):
    return fact(n)//(fact(n-r)*fact(r))

n, a, b = list(map(int, input().split()))
v = list(map(int, input().split()))
v_num = {}
for i in range(n):
    if v[i] not in v_num.keys():
        v_num[v[i]] = 1
    else:
        v_num[v[i]] += 1

v = sorted(v)
ans1 = v[-a:]
print(sum(ans1)/a)

answers = [ans1]
for i in range(a+1, b+1):
    if sum(v[-i:])/i == sum(ans1)/a:
        answers.append(v[-i:])
    else:
        break


ans2 = 0
for ans in answers:
    ans_num = {}
    for i in range(len(ans)):
        if ans[i] not in ans_num.keys():
            ans_num[ans[i]] = 1
        else:
            ans_num[ans[i]] += 1
        
    a2 = 1
    for k in ans_num.keys():
        a2 *= combi(v_num[k], ans_num[k])
    ans2 += a2
    
print(ans2)

Solution (Python):
from collections import Counter

from scipy.misc import comb

N, A, B = map(int, input().split())
v = [int(x) for x in input().split()]

v = sorted(v, reverse=True)
m = sum(v[:A]) / A

c = Counter(v)
w = sorted(list(set(v[:A])), reverse=True)
if len(w) > 1:
    n = 0
    for x in w[:-1]:
        n += c[x]
    a = A - n
    b = A - n
    p = c[w[-1]]
else:
    a = A
    b = min(B, c[w[0]])
    p = c[w[0]]

ans = 0
for i in range(a, b + 1):
    ans += comb(p, i, exact=True)

print('{:f}'.format(m))
print(ans)

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

v = list(map(int,input().split()))
v.sort()
v.reverse()
print(sum(v[:a])/a)


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


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

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

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

v = sorted(v, reverse=True)
basket = v[:A]
max_basket = basket[0]
min_basket = basket[-1]
print(sum(basket) / len(basket))

n_selected = 0
n_candidate = 0
for vi in v:
    if vi > min_basket:
        n_selected += 1
    elif vi == min_basket:
        n_candidate += 1

if min_basket != max_basket:
    print(combination(n_candidate, A - n_selected))
else:
    count = 0
    for i in range(A, min(B, n_candidate) + 1):
        count += combination(n_candidate, i)
    print(count)

Solution (Python):
import math
import functools
N, A, B = map(int, input().split())
V = sorted([int(x) for x in input().split()], reverse=True)
print(sum(V[:A]) / A)
threshold = V[:A][-1]
fixed = 0
chosen = 0
for v in V:
  if v > threshold:
    fixed += 1
  elif v == threshold:
    chosen += 1
def nCn(a, b):
  return math.factorial(a) // math.factorial(b) // math.factorial(a - b)
if fixed:
  print(nCn(chosen, A - fixed))
else:
  count = 0
  for i in range(A, min(B, chosen) + 1):
    count += nCn(chosen, i)
  print(count)

Solution (Python):
N,A,B=[int(x) for x in str(input()).split()]
C=[int(s) for s in str(input()).split()]
j=C
v=C
v.sort()
ma=[]
mi=[]
for i in range(B):
  ma.append(v[-1])
  v=v[:len(v)-1]

for i in range(A):
  mi.append(j[-1])
  j=j[:len(j)-1]

mi.sort()
ma.sort()
ava=0
for i in ma:
  ava+=i

ava/=len(ma)


count=B
while count>A and ma[0]<ava:

  ava=(len(ma)*ava-ma[0])/(len(ma)-1)
  ma=ma[1:]
  count-=1


C1=0
for i in C:
  if i==ma[0]:
    C1+=1
mi1=0
for i in mi:
  if i==ma[0]:
    mi1+=1
ma1=0
for i in ma:
  if i==ma[0]:
    ma1+=1


factorial=[1]
p=1
for i in range(1,51):
  p*=i
  factorial.append(p)  


ans=0
for i in range(mi1,ma1+1):
  ans+=factorial[C1]//factorial[C1-i]//factorial[i]
print(ava)
print(ans)

Solution (Python):
def combination(n, r):
    com = [[0 for j in range(r+1)] for i in range(n+1)]
    for i in range(n+1):
        com[i][0] = 1

    for i in range(1, n+1):
        for j in range(1, r+1):
            com[i][j] = com[i-1][j] + com[i-1][j-1]

    return com[n][r]


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

    v.sort(reverse=True)

    num, s, i = [], [], 0
    while i < n:
        cnt = 1
        while i < n-1 and v[i] == v[i+1]:
            cnt += 1
            i += 1
        num.append(cnt)
        s.append(v[i])
        i += 1

    if num[0] >= a:
        com = 0
        for i in range(a, min(num[0]+1, b+1)):
            com += combination(num[0], i)
        print(v[0])
    else:
        c, idx = 0, 0
        while c < a:
            c += num[idx]
            idx += 1

        w, m = 0, 0
        for i in range(idx-1):
            w += v[i] * num[i]
            m += num[i]
        w += v[idx-1] * (a-m)

        print(w/a)

        com = combination(num[idx-1], a-m)

    print(com)


if __name__ == '__main__':
    main()

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

V.sort()
s = sum(V[-A:])
k = V[-A]
l = bisect.bisect_left(V, k)
r = bisect.bisect_right(V, k)
p = N-A


def f(n):
    y = 1
    for i in range(2, n+1):
        y *= i
    return y


print(s/A)
if r == N:
    a = 0
    for i in range(A, min(B, N-l)+1):
        a += f(N-l)//f(i)//f(N-l-i)
    print(a)
else:
    print(f(r-l)//f(r-p)//f(p-l))

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

n,a,b=map(int, input().split())
v=list(map(int, input().split()))
v.sort(reverse=True)
c=0
if v[0]==v[a-1]:
    for i in range(a,min(b,v.count(v[0]))+1):
        c+=f(v.count(v[a-1]),i)
    print(sum(v[:a])/a)
    print(c)
else: 
    print(sum(v[:a])/a)
    print(f(v.count(v[a-1]),v[:a].count(v[a-1])) )

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

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

V = sorted(list(map(int,input().split())),reverse=True)

C = Counter(V)


SUM = 0
LN = [0,0]
for i in range(A):
    if V[i] == LN[0]:
        LN[1] += 1
    else:
        LN[0] = V[i]
        LN[1] = 1
    SUM += V[i]
    
AVE = SUM/A

comb = 0
n = C[LN[0]]
if LN[1] == A: 
    for r in range(A,min(n,B)+1):
        comb += F(n) // (F(n-r)*F(r))
else:
    comb = F(n) // (F(n-LN[1])*F(LN[1]))
    
print("{0:.6f}".format(AVE))
print(comb)

Solution (Python):
def nCr(n, r):
    r = min(r, n-r)
    x, y = 1, 1
    for i in range(n, n-r, -1):
        x *= i
    for i in range(2, r+1):
        y *= i
    return x//y

n, a, b = map(int, input().split())
v = sorted(list(map(int, input().split())), reverse = True)
print(sum(v[:a])/a)
if(v[0] != v[a-1]):
    print(nCr(v.count(v[a-1]), v[:a].count(v[a-1])))
else:
    c = v.count(v[0])
    m = min(b, c)
    ans = 0
    for i in range(a, m+1):
        ans += nCr(c, i)
    print(ans)

Solution (Python):
from math import factorial as f

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

v.sort()


sum_v = 0
for i in range(N-A+1, N):
    sum_v += v[i]

i_max = N+1
count_max = 1
sum_max = 0

max_nums = []
if A == 1:
    current_num = -1
    current_count = 0
else:
    current_num = v[N-A+1]
    current_count = v[N-A+1:].count(v[N-A+1])
for i in range(N-A, N-B-1, -1):
    if v[i] == current_num:
        current_count += 1
    else:
        current_num = v[i]
        current_count = 1
    count = N-i
    sum_v += v[i]
    if sum_v * count_max > sum_max * count:
        count_max = count
        sum_max = sum_v
        max_nums = [(v[i], current_count)]
    elif sum_v * count_max == sum_max * count:
        if v[i] not in max_nums:
            max_nums.append((v[i], current_count))

def count(vi):
    return v.count(vi)

def c(n, k):
    return f(n)//(f(k)*f(n-k))

ans = 0
for vi, cc in max_nums:
    ans = ans + c(count(vi), cc)
    

print(sum_max/count_max)
print(ans)

Solution (Python):
from math import factorial

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

n1 = v.count(v[a - 1])
n2 = v[:a].count(v[:a][a - 1])

print(sum(v[:a]) / a)
if len(set(v[:a])) != 1:
	if n1 == n2:
		print(1)
	else:
		print(int(factorial(n1) / (factorial(n2) * factorial(n1 - n2))))
else:
	ans = 0
	if n1 == 1:
		print(1)
	else:
		for i in range(a, min(n1 + 1, b + 1)):
			ans += int(factorial(n1) / (factorial(i) * factorial(n1 - i)))
		print(int(ans))

Solution (Python):
from math import factorial

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

n1 = v.count(v[a - 1])
n2 = v[:a].count(v[:a][a - 1])

print(sum(v[:a]) / a)
if len(set(v[:a])) != 1:
	if n1 == n2:
		print(1)
	else:
		print(int(factorial(n1) / (factorial(n2) * factorial(n1 - n2))))
else:
	ans = 0
	if n1 == 1:
		print(1)
	else:
		for i in range(a, min(n1 + 1, b + 1)):
			ans += int(factorial(n1) / (factorial(i) * factorial(n1 - i)))
		print(int(ans))

Solution (Python):
N,A,B=map(int,input().split())
V=[int(x) for x in input().split()]
V.sort(reverse=True)
val=0
mi=10**15+1
cnt=0
for i in range(A):
  val+=V[i]
  if V[i]==mi:
    cnt+=1
  else:
    mi=V[i]
    cnt=1


factorial=[1]
for i in range(1,N+1):
    factorial.append(factorial[i-1]*i)
    
def nCr(n,r):
  return int(factorial[n]/(factorial[r]*factorial[n-r]))    

ave=val/A
if ave == V[0]:
  for i in range(A,N):
    if V[i]==V[0]:
      cnt+=1
    else:
      break
  ans=0
  for i in range(A,min(B+1,cnt+1)):
    ans+=nCr(cnt,i)
  print(ave)
  print(ans)
else:
  res=cnt
  for i in range(A,N):
    if V[i]==V[A-1]:
      res+=1
  print(ave)
  print(nCr(res,cnt))

Solution (Python):
from math import factorial
n,a,b = (int(i) for i in input().split())
v = [int(i) for i in input().split()]
v = sorted(v)[::-1]
print(1.0*sum(v[:a])/a)
x,v2,num = v[a-1],v[:a][::-1],0
for i in v2:
	if i==x: num+=1
	else: break
y = v.count(x)
if num==a:
	answer,y2 = 0,factorial(y)
	for i in range(a,min(y,b)+1):
		answer += y2//(factorial(y-i)*factorial(i))
	print(answer)
else:
	print(factorial(y)//(factorial(y-num)*factorial(num)))

Solution (Python):
import numpy as np
import math
def ncm(n,m):
    return math.factorial(n)/(math.factorial(m) * math.factorial(n-m))

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

ansarray = v[0:A]

ave = np.mean(ansarray)
print(float(ave))
mi = min(ansarray)
ma = max(ansarray)
biggerarray = v[v>mi]
m = len(biggerarray)
numminarray = v[v==mi]
a = len(numminarray)


ans = 0
if ma == mi:
    if m+a <= B:
        for i in range(A-m,a+1):
            ans+=ncm(a,i)
    else:
        for i in range(A-m,B-m+1):
            ans+=ncm(a,i)

else:
    ans = ncm(a,A-m)


print(int(ans))

Solution (Python):
import math

N, a, b = map(int, input().split())
product_list = sorted(map(int, input().split()), reverse = True)

def nCm(n, m):
    return math.factorial(n) / (math.factorial(m) * (math.factorial(n - m)))


average_list = []
average_idx = []
for i in range(a, b+1):
    average = sum(product_list[:i]) / i
    average_list.append(average)
    average_idx.append(i)

max_average = max(average_list)
max_average_idx = [average_idx[i] for i in range(len(average_list)) if average_list[i] == max_average]

pattern_num = int(0)

for i in max_average_idx:
    choice_num = product_list[:i].count(product_list[i-1])
    all_num = product_list.count(product_list[i-1])

    pattern_num += int(nCm(all_num, choice_num))

print(float(max_average), pattern_num)

Solution (Python):
import scipy.misc as ms

n,a,b = map(int, raw_input().split())
v = map(int, raw_input().split())
v = sorted(v)[::-1]
sum = 0.0
for i in range(a): sum += v[i]
print "%.6f" % (sum / a)

m = v[a-1]
c = 0
al = 0
for i in range(a):
	if v[i] == m: c += 1
for i in range(n):
	if v[i] == m: al += 1

ans = 0
if int(sum / a) != m:
	print ms.comb(al, c, 1)
	exit(0)
for i in range(c, min(al, b) + 1):
	ans += ms.comb(al, i, 1)
print ans