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 sys
def input(): return sys.stdin.readline().strip()
sys.setrecursionlimit(10 ** 9)

from collections import Counter
from math import factorial

def nCr(n, r):
    
    r = min(r, n-r)
    return factorial(n) / factorial(r) / factorial(n-r)

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))

Solution (Python):
from collections import Counter
from collections import Counter
N, A, B = (list)(map(int, input().split()))
v = (list)(map(int, input().split()))

v = sorted(v, reverse=True)

sel_list = v[:A]
max_ave = sum(sel_list)/A
print(max_ave)

c = Counter(v)

C = [[0]*(N+1) for _ in range(N+1)]
for i in range(N+1):
    for j in range(i+1):
        if j == 0 or j == i:
            C[i][j] = 1
        else:
            C[i][j] = (C[i-1][j-1] + C[i-1][j])


def ave_n(n):
    sel_list = v[:n]
    ave = sum(sel_list)/i
    if ave != max_ave:
        return 0
    last = sel_list[-1]
    use_last = sel_list.count(last)
    return C[c[last]][use_last]


ans = 0
for i in range(A, B+1):
    ret = ave_n(i)
    if ret == 0:
        break
    else:
        ans += ret
print((int)(ans))

Solution (Python):
from collections import Counter
from collections import Counter
N, A, B = (list)(map(int, input().split()))
v = (list)(map(int, input().split()))

v = sorted(v, reverse=True)

sel_list = v[:A]
max_ave = sum(sel_list)/A
print(max_ave)

c = Counter(v)


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


def ave_n(n):
    sel_list = v[:n]
    ave = sum(sel_list)/i
    if ave != max_ave:
        return 0
    last = sel_list[-1]
    use_last = sel_list.count(last)
    return comb(c[last], use_last)


ans = 0
for i in range(A, B+1):
    ret = ave_n(i)
    if ret == 0:
        break
    else:
        ans += ret
print((int)(ans))

Solution (Python):
n,a,b,*v=map(int,open(0).read().split())
v=[0]+v
dp=[[[0,1]]+[[0,0]for j in range(b)]for i in range(n+1)]
for i in range(1,n+1):
  for j in range(1,b+1):
    if dp[i-1][j-1][0]+v[i]>dp[i-1][j][0]:
      dp[i][j]=[dp[i-1][j-1][0]+v[i],dp[i-1][j-1][1]]
    elif dp[i-1][j-1][0]+v[i]==dp[i-1][j][0]:
      dp[i][j]=[dp[i-1][j][0],dp[i-1][j][1]+dp[i-1][j-1][1]]
    else:
      dp[i][j]=[dp[i-1][j][0],dp[i-1][j][1]]
m=0
for i in range(a,b+1):
  m=max(m,dp[-1][i][0]/i)
print(m,sum(dp[-1][i][1]*(dp[-1][i][0]/i==m)for i in range(a,b+1)),sep='\n')

Solution (Python):
n,a,b,*v=map(int,open(0).read().split())
v=[0]+v
dp=[[[0,1]]+[[0,0]for j in range(b)]for i in range(n+1)]
for i in range(1,n+1):
  for j in range(1,b+1):
    if dp[i-1][j-1][0]+v[i]>dp[i-1][j][0]:
      dp[i][j]=[dp[i-1][j-1][0]+v[i],dp[i-1][j-1][1]]
    elif dp[i-1][j-1][0]+v[i]==dp[i-1][j][0]:
      dp[i][j]=[dp[i-1][j][0],dp[i-1][j][1]+dp[i-1][j-1][1]]
    else:
      dp[i][j]=[dp[i-1][j][0],dp[i-1][j][1]]
m=0
for i in range(a,b+1):
  m=max(m,dp[-1][i][0]/i)
print(m,sum(dp[-1][i][1]*(dp[-1][i][0]/i==m)for i in range(a,b+1)),sep='\n')

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

ans1 = sum(V[:A]) / A
ans2 = 0

V_Ath = V[A - 1]
V_Ath_CNT = V.count(V_Ath)
V_than_Ath_CNT = len([v for v in V if v > V_Ath])

if max(V) == V_Ath:
    for n in range(A, B + 1):
        ans2 += comb(V_Ath_CNT, n, 1)
else:
    ans2 = comb(V_Ath_CNT, A - V_than_Ath_CNT, 1)

print(ans1)
print(ans2)

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

V.sort(reverse=True)

sumV = 0
for i in range(A):
    sumV += V[i]
ans1 = sumV/A


cntV0 = 0
for i in range(N):
    if V[i]==V[0]:
        cntV0 += 1
ans2 = 1
if cntV0 > A:
    ans2 = 0
    for i in range(A,min(cntV0,B)+1):
        tmp = 1
        c = cntV0
        r = i
        for j in range(r):
            tmp *= c-j
            tmp //= j+1
        ans2 += tmp
else:
    cntV1,cntV2 = 0,0
    for i in range(N):
        if V[i]==V[A-1]:
            cntV1 += 1
        elif V[i]>V[A-1]:
            cntV2 += 1
    if cntV1+cntV2 > A:
        c = cntV1
        r = A-cntV2
        for i in range(r):
            ans2 *= c-i
            ans2 //= i+1


print(ans1, ans2)

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


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

mean_max = sum(v_list[:A]) / A
comb = 0
if v_list[0] != v_list[A-1]:
    x = v_list.count(v_list[A-1])
    y = v_list[:A].count(v_list[A-1])
    comb = combination(x, y)
else:
    x = v_list.count(v_list[A-1])
    for i in range(A, B+1):
        if v_list[i-1] == v_list[0]:
            comb += combination(x, i)

print("{:.10f}".format(mean_max))
print(comb)

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


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

mean_max = sum(v_list[:A]) / A
comb = 0
if v_list[0] != v_list[A-1]:
    x = v_list.count(v_list[A-1])
    y = v_list[:A].count(v_list[A-1])
    comb = combination(x, y)
else:
    x = v_list.count(v_list[A-1])
    for i in range(A, B+1):
        if v_list[i-1] == v_list[0]:
            comb += combination(x, i)

print(mean_max)
print(comb if comb != 0 else 1)

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


n,a,b = map(int,input().split())
v = list(map(int,input().split()))
v.sort(reverse=True)
ans1 = sum(v[:a])/a
num1 = v[:a].count(v[a-1])
num2 = v[a:n].count(v[a-1])

ans2 = 0
if v[0] == v[a]:
    for i in range(a,n):
        if v[i] == v[a-1]:
            idx = i + 1
    for i in range(a,min(b,idx) + 1):
        ans2 += combination(num1 + num2, i)
else:
    ans2 = combination(num1 + num2,num1)

print(ans1)
print(ans2)

Solution (Python):
N, A, B = [int(_) for _ in input().split()]
V = sorted([int(_) for _ in input().split()], reverse=True)
mp = {}
for v in V:
    mp[v] = mp.get(v, 0) + 1


def fact(x):
    ans = 1
    for i in range(1, x + 1):
        ans *= i
    return ans


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


keys = sorted(mp.keys(), reverse=True)
if mp[keys[0]] >= A:
    print(keys[0])
    print(
        sum([comb(mp[keys[0]], i) for i in range(A, 1 + min(mp[keys[0]], B))]))
else:
    count = 0
    for k in keys:
        count += mp[k]
        if count >= A:
            print(sum(V[:A]) / A)
            print(comb(mp[k], A - count + mp[k]))
            break

Solution (Python):
import math
n, a, b = list(map(int, input().split()))
v = list(map(int, input().split()))
v.sort(reverse = True)
ans = 0
many = 0
for i in range(a, b + 1) :
	vsumany = sum(v[:i])
	ansi = vsumany / (i)
	if ans <= ansi :
		ans = ansi
		ci = v.count(v[i - 1])
		cin = v[:i].count(v[i - 1])
		m = math.factorial(ci)//math.factorial(cin)//math.factorial(ci-cin)
		many += m
print(ans)
print(many)

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


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


C = V.count(V[A - 1])
if max(V) != V[A - 1]:
    
    remain = A - len([v for v in V if v > V[A - 1]])
    print(comb(C, remain, 1))
else:
    ans = 0
    for i in range(A, B + 1):
        ans += comb(C, i, 1)
    print(ans)

Solution (Python):
import math


def combination(n, k):
    return math.factorial(n) // math.factorial(n - k) // math.factorial(k)


N, A, B = map(int, input().split())
V = list(sorted(map(int, input().split()), key=lambda x: -x))

s = [0]

for i in range(N):
    s.append(s[-1] + V[i])

max_mean = 0
for i in range(A, B + 1):
    m = s[i] / i
    if max_mean < m:
        max_mean = m

ret = 0

for i in range(A, B + 1):
    m = s[i] / i
    if m == max_mean:
        k = 0
        for p in range(i):
            if V[p] == V[i - 1]:
                k += 1
        ret += combination(V.count(V[i - 1]), k)
print(max_mean)
print(ret)

Solution (Python):
from math import factorial

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

maxave = 0

for i in range(A, B+1):
    if sum(v[:i]) / i < maxave:
        continue
    
    counter1 = 1
    for j in range(i-2, -1, -1):
        if v[j] == v[i-1]:
            counter1 += 1
        else:
            break

    counter2 = v.count(v[i-1])

    now_counter = factorial(counter2) // factorial(counter2 - counter1) // factorial(counter1)

    if sum(v[:i]) / i == maxave:
        nummax += now_counter
    else:
        nummax = now_counter
        maxave = sum(v[:i]) / i
    
print(maxave)
print(nummax)

Solution (Python):
N, A, B = (int(i) for i in input().split())
V = [int(i) for i in input().split()]
V.sort()
V = V[::-1]

key = V[A-1]
cca = 0
ccb = 0
kk = 0

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

su = 0
for i in range(A):
    su += V[i]
print(su/A)

for i in range(A):
    if V[i] == key:
        cca += 1
for i in range(N):
    if V[i] == key:
        ccb += 1

if cca == A:
    res = 0
    for i in range(A, B+1):
        res += combination(ccb, i)
else:
    res = combination(ccb, cca)
print(res)

Solution (Python):

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

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

res_avg = sum(vl[:a])/a
res_cnt = 0
last_v = vl[a-1]

cnt_all = 0
for v in vl:
    if v==last_v:
        cnt_all += 1

for m in range(a,b+1):
    if sum(vl[:m])/m == res_avg:
        cnt_in = 0
        for i in range(m):
            if last_v==vl[i]:
                cnt_in += 1
        res_cnt += comb(cnt_all, cnt_in)

print("{:6f}".format(res_avg))
print(res_cnt)

Solution (Python):
def combinations(n, r):
    res = 1
    for i in range(n - r + 1, n + 1):
        res *= i
    for i in range(2, r + 1):
        res //= i
    return res

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

v.sort(reverse=True)
ans1 = sum(v[0:A]) / A

num1 = v[0:A].count(v[A - 1])
num2 = v[A:N].count(v[A - 1])

ans2 = 0
if v[0] == v[A]:
    for i in range(A, N):
        if v[i] == v[A]:
            idx = i + 1
    for i in range(A, min(B, idx) + 1):
        ans2 += combinations(num1 + num2, i)
else:
    ans2 = combinations(num1 + num2, num1)

print(ans1)
print(ans2)

Solution (Python):
import numpy as np

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

if __name__ == '__main__':
    
    N, A, B = map(int, input().split())
    v0 = list(map(int, input().split()))    
    v = np.array(v0, dtype = np.int64)
    v = np.sort(v)[::-1]
    
    ave = 0
    comb = 0
    
    if v[A - 1] == v[0]:
        ave = v[0]
        n = np.sum(v == v[0])
        for i in range(A, min(B, n) + 1):
            comb += nCr(n, i)
    else:
        n0 = np.sum(v > v[A - 1])
        n1 = np.sum(v == v[A - 1])
        comb = nCr(n1, A - n0)
        ave = np.sum(v[0: A]) / A
        
    print(ave)
    print(comb)

Solution (Python):
def combinations(n, r):
    res = 1
    for i in range(n - r + 1, n + 1):
        res *= i
    for i in range(2, r + 1):
        res //= i
    return res

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

mx = sum(v[:A])
ans1 = mx/A
a = v[A - 1]
cnt = v.count(a)

ans2 = 0
for i in range(A, B + 1):
    if A*sum(v[:i]) < i*mx:
        break
    ans2 += combinations(cnt, v[:i].count(a))

print(ans1)
print(ans2)

Solution (Python):
def combinations(n, r):
    res = 1
    for i in range(n - r + 1, n + 1):
        res *= i
    for i in range(2, r + 1):
        res //= i
    return res

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

mx = sum(v[:A])
ans1 = mx/A
a = v[A]
cnt = v.count(a)

ans2 = 0
for i in range(A, B + 1):
    if A*sum(v[:i]) < i*mx:
        break
    ans2 += combinations(cnt, v[:i].count(a))

print(ans1)
print(ans2)

Solution (Python):
import math
n, a, b = map(int, input().split())
v = [int(m) for m in input().split()]
v.sort(reverse=True)

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


k = 0
l = 0
maxli = []
for i in range(a, b + 1):
    w = v[:i]
    avgv = sum(w) / i
    x = v[i - 1]
    for u in range(len(w) - 1, -1, -1):
        if u == len(w) - 1:
            l = 1
        else:
            if v[u] == v[u + 1]:
                l += 1
            else:
                break
    for j in range(i - 1, n):
        if j == i - 1:
            k = 1
        else:
            if v[j] == v[j - 1]:
                k += 1
            else:
                break
    k -= 1
    maxli.append([avgv, comb(l + k, l)])

S = 0
K = 0
maxli.sort(reverse=True)
for i in range(len(maxli)):
    if i == 0:
        S = maxli[i][0]
        K = maxli[i][1]
    else:
        if maxli[i][0] == maxli[i - 1][0]:
            K += maxli[i][1]
        else:
            break
print(S)
print(K)

Solution (Python):
N,A,B=map(int,input().split())
goods=[int(i) for i in input().split()]
dp=[[[0,0] for i in range(N+1)] for i in range(N)]
for i in range(N):
  for j in range(i+2):
    if i==0 and j==1:
      dp[0][1]=[goods[i],1]
    elif j==0:
      dp[i][0]=[0,1]
    else:
      if dp[i-1][j][0]<dp[i-1][j-1][0]+goods[i]:
        dp[i][j][0]=dp[i-1][j-1][0]+goods[i]
        dp[i][j][1]=dp[i-1][j-1][1]
      elif dp[i-1][j][0]>dp[i-1][j-1][0]+goods[i]:
        dp[i][j][0]=dp[i-1][j][0]
        dp[i][j][1]=dp[i-1][j][1]
      else:
        dp[i][j][0]=dp[i-1][j-1][0]+goods[i]
        dp[i][j][1]=dp[i-1][j-1][1]+dp[i-1][j][1]
                           
ans1,ans2=0,0
for i in range(A,B+1):
  if ans1<dp[N-1][i][0]/i:
    ans1=dp[N-1][i][0]/i
    ans2=dp[N-1][i][1]
  elif ans1==dp[N-1][i][0]/i:
    ans2+=dp[N-1][i][1]
print(ans1)
print(ans2)

Solution (Python):
import math

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

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

cnt=v.count(v[0])
cnt2=v.count(v[A-1])
V=v[0:A]
cnt3=V.count(v[A-1])

def combinations_count(n, r):
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
        
if cnt<A:
    print(combinations_count(cnt2, cnt3))
elif cnt==A:
    print(1)
elif cnt>A:
    ans=0
    for i in range(A,min(cnt+1,B+1)):
        ans+=combinations_count(cnt,i)
    print(ans)

Solution (Python):
from math import factorial
from collections import defaultdict
N,A,B = map(int,input().split())
v = list(map(int,input().split()))
vd = defaultdict(int)
for i in range(N):
    vd[v[i]] += 1
vd=sorted(vd.items(),key=lambda x:x[0],reverse=True)
ave,i,cnt = 0,0,0
for v,c in vd:
    if A<=cnt+c:
        break
    cnt += c
    ave += v*c
    i += 1
ans = 0
if i==0:
    ave = vd[i][0]
    ub = min(B,vd[i][1])
    if vd[i][1]==A:
        for j in range(A-1,ub):
            ans += factorial(ub)//(factorial(ub-(j+1))*factorial(j+1))
    else:
        for j in range(A-1,ub):
            ans += factorial(vd[i][1])//(factorial(vd[i][1]-(j+1))*factorial(j+1))
else:
    ave += vd[i][0]*(A-cnt)
    ave /= A 
    ans = factorial(vd[i][1])//(factorial(vd[i][1]-(A-cnt))*factorial(A-cnt))
print(ave)
print(ans)

Solution (Python):
import math

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


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

v.sort(reverse=True)

anum=0
onum=0
for i in range(N):
    if v[i]==v[A-1]:
        anum+=1
    elif v[i]>v[A-1]:
        onum+=1
    if v[i]<v[A-1]:
        break
ans=0
if v[0]==v[A-1]:
    for i in range(A,min(B,anum)+1):
        ans+=com(anum,i)

else:
    ans+=com(anum,A-onum)
    
print(sum(v[:A])/A)
print(ans)

Solution (Python):
def factrial(a):
    ans=1
    for i in range(2,a+1):
        ans*=i
    return ans

def comb(a,b):
    return factrial(a)/(factrial(a-b)*factrial(b))

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

arr=list(map(int,input().split()))
arr=sorted(arr,reverse=True)
mean_=sum(arr[:A])/A

top=arr.index(arr[A-1])
num=arr.count(arr[A-1])
ans=0
if arr[0]==arr[A-1]:
    for i in range(A,min(num,B)+1):
        ans+=comb(num,i)
else:
    ans=comb(num,A-top)

print(mean_)
print(int(ans))

Solution (Python):
import sys
from collections import deque
import copy

def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

g_comb_table ={}
def Comb(n, k):
    global g_comb_table
    if (n, k) in g_comb_table:
        return g_comb_table[(n, k)]
    if n == k or k == 0:
        g_comb_table[(n, k)] = 1
        return 1L
    elif k == 1:
        g_comb_table[(n, k)] = n
        return n
    g_comb_table[(n, k)] = Comb(n-1, k-1) + Comb(n-1, k)
    return g_comb_table[(n, k)]


def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N, A, B] = [long(input_raw[0]), long(input_raw[1]), long(input_raw[2])]
    input_raw = read_func().strip().split()
    v = []
    v_nums = {}
    for i in range(N):
        v.append(long(input_raw[i]))
        if v[i] in v_nums:
            v_nums[v[i]] += 1L
        else:
            v_nums[v[i]] = 1L

    v.sort(reverse = True)





    max_ave_s = 0
    max_count = 0L
    sum_count = 0
    max_n = 0

    len_count = 0
    for n in range(A, B + 1):
        if v[n - 1] == v[0]:
            len_count+= 1

    if len_count == 0:
        len_count = 1

    s = 0L
    for i in range(A):
        s += v[i]
    max_ave = float(s)/A


    for n in range(A, A + len_count):
        last_num = -1
        last_num_count = 0L
        for i in range(n):
            if last_num != v[i]:
                last_num = v[i]
                last_num_count = 1L
            else:
                last_num_count += 1L
        max_count += Comb(v_nums[last_num], last_num_count)






    print "%.6f" %(max_ave)
    print max_count


if __name__ == '__main__':
    main()

Solution (Python):
import collections
import math
N, A, B = map(int, input().split())
value = list(map(int, input().split()))
value.sort()
value.reverse()
valuetot = 0
for i in range(A):
    valuetot += value[i]
valueave = valuetot/A
value.append(0)
v = value[A-1]
C = collections.Counter(value)
vcount = C[v]

for i in range(A):
    if value[i] == v:
        vindex = i
        break

def permutation(n,r):
    r = min(r, n-r)
    numerator = 1
    for i in range(n, n-r, -1):
        numerator *= i
    denominator = 1
    for i in range(r, 1, -1):
        denominator *= i
    return numerator // denominator


def pattern(a):
    c = collections.Counter(value[:a])
    return permutation(vcount, c[v])

v0 = value[0]
v0len = 0
for i in range(N):
    if v0 == value[i]:
        v0len = i + 1
    else:
        break


if v0len >= A:
    ans = 0
    for i in range(A-1, B):
        if v0 == value[i]:
            ans += permutation(v0len, i+1)


elif value[A-1] != value[A]:
    ans = 1

else:
    ans = pattern(A)

print(valueave)
print(ans)

Solution (Python):
import math
N,A,B=map(int,input().split())
lst=list(map(int,input().split()))
lst.sort()
a=lst[-A:]
print(sum(a)/A)
b=lst.count(a[0])
c=a.count(a[0])
if c!=A:
    print(int(math.factorial(b)/(math.factorial(c)*math.factorial(b-c))))
else:
    l=[]
    i=min([b-c,B-A])
    for k in range(0,i+1):
        l.append(math.factorial(b)/(math.factorial(c+k)*math.factorial(b-c-k)))
    print(int(sum(l)))

Solution (Python):
import math
N,A,B = map(int,input().split())
v = list(map(int,input().split()))
d = {}
for value in v:
    if value not in d:
        d[value] = 1
    else:
        d[value] += 1
sortedDict = list(reversed(sorted(d.items(), key=lambda x: x[0])))
i = 0
s = 0
number = 0
while True:
    value,count = sortedDict[i]
    if A > count:
        A -= count
        B -= count
        i += 1
        s += count*value
        number += count
    else:
        s += A*value
        number += A
        break
        
ans = 0
def combination(n,k):
    return (math.factorial(n)//math.factorial(k)//math.factorial(n-k))
if i == 0:
    upper = min(count,B)
    for j in range(A,upper+1):
        ans += combination(count,j)
else:
    ans = combination(count,A)
average = s/number
print(average)
print(ans)

Solution (Python):
def fact(n):
    if n == 0:
        return 1
    else:
        return n*fact(n-1)
def conb(n,r):
    return fact(n)//(fact(r)*fact(n-r))

N,A,B = map(int,input().split())
v = list(map(int,input().split()))
v.sort()
v.reverse()
d_all = {}
for i in range(N):
    if v[i] not in d_all:
        d_all[v[i]] = 0
    d_all[v[i]] += 1
import numpy as np
avg = np.cumsum(np.array(v))
avg = [0]*N
avg[0]=v[0]
for i in range(N-1):
    avg[i+1]=avg[i]+v[i+1]
for i in range(N):
    avg[i]=avg[i]/(i+1)
    
avg = avg[A-1:B]
ans = max(avg)
print(ans)
avg=np.array(avg)
indices = np.where(avg==ans)[0]
ans = 0
for index in indices:
    d_use = {}
    use = A + index
    v_use = v[:use]
    choose=1
    for item in v_use:
        if item not in d_use:
            d_use[item] = 0
        d_use[item] += 1
    for item in d_use:
        choose *= conb(d_all[item],d_use[item])
    ans += choose

print(ans)

Solution (Python):
def inpl(): return [int(i) for i in input().split()]
def comb(a,b):
    return math.factorial(a)//math.factorial(a-b)//math.factorial(b)

N, A, B = inpl()
V = inpl()
V = list(reversed(sorted(V)))
x1 = N-1
x2 = 0
for i in range(N):
    if V[i] == V[A]:
        x1 = min(x1,i)
        x2 = max(x2,i)

print(sum(V[0:A])/A)
import math
ans = 0
if x1 == 0:
    for l in range(A-1,min(B,x2+1)):
        ans += comb(x2-x1+1,l-x1+1)
    print(ans)
else:
    print(comb(x2-x1+1,A-x1))

Solution (Python):
n,a,b=map(int,input().split())
v=list(map(int,input().split()))
v.sort()
v=v[::-1]
print(sum(v[:a])/a)
def com(x,y):
    a=1
    b=1
    y=min(y,x-y)
    for i in range(x,x-y,-1):
        a*=i
    for i in range(1,y+1):
        b*=i
    return a//b
ans=0
x=v.count(v[a-1])
y=v[:a].count(v[a-1])
if v[0]!=v[a]:
    ans+=com(x,y)
else:
    for j in range(a,min(b,x)+1):
        ans+=com(x,j)
print(ans)

Solution (Python):
from collections import Counter
from scipy.misc import comb

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

v.sort(reverse=True)
v_cum = []
num = 0
for i in range(n):
    num += v[i]
    v_cum.append(num)

print(v_cum[a-1]/a)

if a == n:
    print(1)
else:
    if v[a-1] == v[a]:
        num = v[a-1]
        cf = Counter(v[:a])
        cb = Counter(v[a:])
        n_cf = cf[num]
        n_cb = cb[num]
        if n_cf != a:
            print(comb(n_cf+n_cb, n_cf, exact=True))
        else:
            ans = 0
            for k in range(a, min(b+1, a+n_cb+1)):
                ans += comb(a+n_cb, k, exact=True)
            print(ans)
    else:
        print(1)

Solution (Python):

import math
N, A, B = map(int,input().split())
v = sorted(list(map(int,input().split())))[::-1]

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

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

s = 0
for k in range(N):
    if v[A-1] == v[k]:
        s += 1
t = 0
for k in range(A):
    if v[A-1] == v[k]:
        t += 1
u = 0
for k in range(A-1,B):
    if v[A-1] == v[k]:
        u += 1

if a != v[A-1]:
    print(nCr(s,t))
else:
    c = 0
    for k in range(A,A+u):
        c += nCr(s,k)
    print(c)

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

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

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

Solution (Python):
def main():
    S = list(input())

    checklist = [0 for i in range(26)]

    for i in S:
        checklist[ord(i) - ord("a")] += 1

    ans = True
    for i in checklist:
        if i > 1:
            ans = False

    if not ans:
        print(-1)
        return 0
    else:
        ans = False
        for i in range(len(checklist)):
            if checklist[i] == 0:
                for i in S:
                    print(i, end="")
                print(chr(i + ord("a")), end = "")
                print()
                ans = True
                break
        if not ans:
            new_S = []
            for i in S:
                new_S.append(ord(i))
            for i in range(len(new_S) - 1):
                if new_S[i] > new_S[i + 1]:
                    for j in range(i - 1):
                        print(S[j], end = "")
                    print(chr(new_S[i - 1] + 1), end = "")
                    print()
                    ans = True
                    break
            if not ans:
                print(-1)


def ABC069D():

    H, W = map(int, input().split())
    N = int(input())
    a = list(map(int, input().split()))
    ans = []
    for i in range(N):
        for j in range(a[i]):
            ans.append(i + 1)
    printlist = [[0 for i in range(W)] for j in range(H)]
    k = 0
    for i in range(H):
        for j in range(W):
            printlist[i][j] = ans[k]
            k += 1
        if i % 2 != 0:
            printlist[i] = printlist[i][::-1]

    for i in range(H):
        for j in range(W):
            print(printlist[i][j], end = "")
            if j != W:
                print(" ", end = "")
        print()
    print()


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


def ABC057D():

    N, A, B = map(int, input().split())
    v = list(map(int, input().split()))
    v = sorted(v)[::-1]

    anslist = []
    for i in range(A, B + 1):

        anslist.append([sum(v[0:i]) / i, i, v[i - 1]])
    anslist.sort()
    anslist = anslist[::-1]
    ans = anslist[0][0]
    key = anslist[0][2]
    long = anslist[0][1]
    print(ans)
    for i in range(1, len(anslist)):
        if anslist[i][0] == anslist[i - 1][0]:
            ans = anslist[i][0]
            key = anslist[i][2]
            long = anslist[i][1]
        else:
            break
    
    
    cnt = 0
    for i in v:
        if i == key:
            cnt += 1

    c = 0
    for i in v[:long]:
        
        if i == key:
            c += 1
    
    ans = 0
    if c == long:
        for i in range(A,  min(B + 1, cnt + 1)):
            ans += cc(cnt, i)
    else:
        ans = cc(cnt, c)
    
    
    print(ans)
ABC057D()

Solution (Python):
import math
def cc(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


def ABC057D():

    N, A, B = map(int, input().split())
    v = list(map(int, input().split()))
    v = sorted(v)[::-1]

    anslist = []
    for i in range(A, B + 1):

        anslist.append([sum(v[0:i]) / i, i, v[i - 1]])
    anslist.sort()
    anslist = anslist[::-1]
    ans = anslist[0][0]
    key = anslist[0][2]
    long = anslist[0][1]
    print(ans)
    for i in range(1, len(anslist)):
        if anslist[i][0] == anslist[i - 1][0]:
            ans = anslist[i][0]
            key = anslist[i][2]
            long = anslist[i][1]
        else:
            break
    
    
    cnt = 0
    for i in v:
        if i == key:
            cnt += 1

    c = 0
    for i in v[:long]:
        
        if i == key:
            c += 1
    
    ans = 0
    if c == long:
        for i in range(A,  min(B + 1, cnt + 1)):
            ans += cc(cnt, i)
    else:
        ans = cc(cnt, c)
    
    
    print(ans)
ABC057D()

Solution (Python):
def Comb(i, j, memo):
    if i == j:
        return 1
    elif j == 1:
        return i
    try:
        return memo[(i, j)]
    except KeyError:
        ans = Comb(i-1, j-1, memo) + Comb(i-1, j, memo)
        memo[(i,j)] = ans
        return ans

N, A, B = map(int, input().split())
V = [int(i) for i in input().split()]
V.sort(reverse = True)
av = 0
for i in range(A):
    av += V[i]
av = round(av/A, 6)

memo = {}
if V[0] == V[A-1]:
    lim = min(V.count(V[0]), B)
    ans = 0
    for j in range(A, lim+1):
        ans += Comb(V.count(V[0]), j, memo)
else:
    ans = Comb(V.count(V[A-1]), V[:A].count(V[A-1]), memo)

print(av)
print(ans)

Solution (Python):
import sys
import math

input = sys.stdin.readline
n, a, b = map(int, input().split())
v_list = list(map(int, input().split()))
v_list.sort(reverse=True)
mean = sum(v_list[:a]) / a
check = v_list[a-1]
before = 0
after = 0
before_list = v_list[:a-1]
before_list.sort()
after_list = v_list[a:]
for num in before_list:
    if check == num:
        before += 1
    else:
        break
for num in after_list:
    if check == num:
        after += 1
    else:
        break
ans = 0
comb_n = before + after + 1
if a - 1 == before:
    for i in range(min(after+1, b-a+1)):
        comb_r = before + i + 1
        ans += math.factorial(comb_n) // (math.factorial(comb_n - comb_r) * math.factorial(comb_r))
else:
    comb_r = before + 1
    ans += math.factorial(comb_n) // (math.factorial(comb_n - comb_r) * math.factorial(comb_r))
print(mean)
print(ans)