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

Solution (Python):


import math

def main():
    N, A, B = map(int, input().split())
    v = sorted(map(int, input().split()))[::-1]
    d = sum(v[:A]) / A
    L = [v[:A]]
    for i in range(A+1, B+1):
        if sum(v[:i]) / i == d : L += [v[:i]]
    ans = 0
    for i in L:
        a = 1
        for j in set(i):
            if i.count(j) == 1:
                a *= v.count(j)
            else:
                x = v.count(j)
                y = i.count(j)
                a *= (math.factorial(x) // math.factorial(x-y)) // math.factorial(y)
        ans += a
    print(d)
    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
from math import factorial

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

C = [[0 for i in range(51)] for j in range(51)] 

for i in range(51):
    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]

v.sort(reverse = True)

t = v[A-1]

ans = 0
X, Y = v.count(t), v[:A].count(t)

if (v[0] != v[A-1]):
    ans = C[X][Y]

else:
    for i in range(A, B+1):
        if(i <= X):
            ans += C[X][i]

print float(sum(v[0:A]))/A
print ans

Solution (Python):
import math
 
def C(n,r):
    f = math.factorial
    return int(f(n) // f(r) // f(n-r))

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

v.sort(reverse=True)

m_ave = sum(v[:A])/A
x,y = v.count(v[A-1]),v[:A].count(v[A-1])

if v[0]==v[A-1] :
    comb = sum([C(x,i) for i in range(A,min(B,x)+1)])
else :
    comb = C (x,y)

print(m_ave)
print(comb)

Solution (Python):
import math





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

C = 0


V = [int(value) for value in input().split()]

V.sort(reverse=True)


S = V[:A]
ave = sum(S) / A
print(ave)

Vs = V.count(min(S)) 
Ss = S.count(min(S)) 

if min(S) == max(S): 
    i = A
    while i <= B and V[i-1] == min(S): 
        C = C + math.factorial(Vs) // ( math.factorial(Vs - i) * math.factorial(i))
        i += 1
    
else: 
    
    C = math.factorial(Vs) // (math.factorial(Vs - Ss) * math.factorial(Ss) )

print(C)

Solution (Python):
import math
 


 

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

C = 0
 

V = [int(value) for value in input().split()]

V.sort()

 

S = V[-A:]
ave = sum(S) / A
print(ave)
 
Vs = V.count(min(S))
Ss = S.count(min(S))
if min(S) != max(S):
    C = math.factorial(Vs) // (math.factorial(Vs -Ss) * math.factorial(Ss))
    print(C)
else:
    i = A
    C = 0
    while i <= B and V[-i] == min(S):
        c = math.factorial(Vs) // (math.factorial(Vs -i) * math.factorial(i))
        C = C + c
        i = i + 1
    print(C)

Solution (Python):



import math
N,A,B = map(int,input().split())
V = list(map(int,input().split()))
V.sort()
S = V[-A:]
avgmax = sum(S) / A
print(avgmax)
 
Vs = V.count(min(S))
Ss = S.count(min(S))
if min(S) != max(S):
	C = math.factorial(Vs) // (math.factorial(Vs -Ss) * math.factorial(Ss))
	print(C)
else:
	i = A
	C = 0
	while i <= B and V[-i] == min(S):
		c = math.factorial(Vs) // (math.factorial(Vs -i) * math.factorial(i))
		C = C + c
		i = i + 1
	print(C)

Solution (Python):
from math import factorial

def comb(n, k):
    f = factorial
    return f(n) / f(k) / f(n-k)

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

v.sort(reverse = True)

t = v[A-1]

ans = 0
X, Y = v.count(t), v[:A].count(t)

if (v[0] != v[A-1]):
    ans = comb(X, Y)

else:
    for i in range(A, B+1):
        if(i <= X):
            ans += comb(X, i)

print float(sum(v[0:A]))/A
print ans

Solution (Python):
from math import factorial

def comb(n, k):
    f = factorial
    return f(n) / f(k) / f(n-k)

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

v.sort(reverse = True)

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

X, Y = 0, 0
ans = 0

for i in range(N):
    if (v[i] == v[A-1]):
        X += 1
    if (v[i] == v[A-1]) and (i < A):
        Y += 1

if (v[0] != v[A-1]):
    ans = comb(X, Y)

else:
    for i in range(A, B+1):
        if(i <= X):
            ans += comb(X, i)

print ans

Solution (Python):

import math
N, A, B = map(int, input().split())
V = list(map(int, input().split()))
V.sort(reverse=True)
maxavg = sum(V[:A])/A
print(maxavg)
min = V[A-1]
ltAnum = 0
minnum = 0
for i in range(N):
    if V[i] > min:
        ltAnum = ltAnum + 1
    elif V[i] == min:
        minnum = minnum + 1
    else:
        break



import math
def nCr(n,r):
    f = math.factorial
    return f(n)//f(r)//f(n-r)

c_min = 0
import itertools
if ltAnum > 0:
    c_min = nCr(minnum, A-ltAnum)
if ltAnum == 0:
    for j in range(A, B+1):
        if minnum < j:
            break
        else:
            c_min = c_min + nCr(minnum, j)
print(c_min)

Solution (Python):

INF=10**10
from collections import Counter
import scipy.misc as scm

def ncr(n, r):
    r = min(r, n - r)
    if r == 0: return 1;
    if r == 1: return n;
    numerator = [n - r + i + 1 for i in range(r)]
    denominator  = [i + 1 for i 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 *= numerator[k]
    return result

def main():
    N,A,B=list(map(int,input().split()))
    v=list(map(int,input().split()))
    cnt=Counter(v)
    ary=[]
    first=True
    
    for num,count in sorted(cnt.items(),reverse=True):
        if count>A:
            if first:
                a2=0
                print("{:.6f}".format(float(num)))
                for k in range(A,min(B,count)+1):
                    a2+=ncr(count,k)
                print(a2)
                return 0
            
            ary+=[num]*A
            print("{:.6f}".format(sum(ary)/len(ary)))
            print(ncr(count,A))
            return 0
        elif A==0:
            print("{:.6f}".format(sum(ary)/len(ary)))
            print(1)
        else:
            ary+=[num]*count
            A-=count
        first=False
    
        
      
if __name__=="__main__":
    main()

Solution (Python):
def pscl(num,l=[1]):
    for i in range(num):
        l = map(lambda x,y:x+y,[0]+l,l+[0])
    return l

n,a,b=map(int,raw_input().split())
v=[int(i) for i in raw_input().split()]
chk=[i for i in set(v)]
chk.sort()
if len(chk)==1:
    print chk[0]*1.0
    print sum(pscl(n)[a:b+1])
    exit()
d={}
for i in v:
    if i in d:
        d[i]+=1
    else:
        d[i]=1
total=ans=tmp=0
t=a
for p,i in enumerate(chk[::-1]):
    if d[i]<t:
        total=total+i*d[i]
        t=t-d[i]
    elif p==0 and d[i]>=t:
        print i*1.0
        print sum(pscl(d[i])[a:min(b,d[i])+1])
        break
    else:
        total=total+i*t
        print total*1.0/a
        print pscl(d[i])[t]
        break

Solution (Python):

import math

num_N, num_A, num_B = map(int, input().split())
l_val = list(map(int, input().split()))

l_val.sort(reverse=True)

num_cen = l_val[num_A - 1]

count_all = 0
for i in l_val:
    if num_cen == i:
        count_all += 1

count_front = 0
for i in l_val[0:num_A - 1]:
    if i == num_cen:
        count_front += 1

count_back = count_all - count_front - 1

ans = 0

if l_val[0] == num_cen:
    if count_back <= num_B - num_A:
        for i in range(num_A, num_A + count_back + 1):
            ans += math.factorial(count_all) // (math.factorial(count_all - i) * math.factorial(i))
    else:
        for i in range(num_A, num_B + 1):
            ans += math.factorial(count_all) // (math.factorial(count_all - i) * math.factorial(i))
else:
    ans = math.factorial(count_all) // (math.factorial(count_all - (count_front + 1)) * math.factorial(count_front + 1))

print((sum(l_val[0:num_A])) / num_A)
print(ans)

Solution (Python):



from math import factorial


def comb(n, r):
    nf = factorial(n)
    rf = factorial(r)
    nrf = factorial(n - r)
    return int(nf / (rf * nrf))


n, a, b = map(int, input().split())
goods = list(reversed(sorted([int(x) for x in input().split()])))

avg, total = sum(goods[:a]) / a, 0

lastcount, lastindex = 0, 0
for i, val in enumerate(goods):
    if val == goods[a - 1]:
        lastcount += 1
        if i < a:
            lastindex += 1

if goods[0] != goods[a - 1]:
    total += comb(lastcount, lastindex)
else:
    for i in range(a - 1, b):
        if goods[a - 1] != goods[i]: break
        total += comb(lastcount, i + 1)

print("{}\n{}".format(avg, total))

Solution (Python):

import math

def main():
    N, A, B = map(int, input().split())
    v = sorted(map(int, input().split()))[::-1]
    L = [[sum(v[:A]) / A, v[:A]]]
    for i in range(A+1, B+1):
        if sum(v[:i]) / i == L[0][0] : L += [[sum(v[:i]) / i, v[:i]]]
    ans = 0
    for i in L:
        a = 1
        for j in set(i[1]):
            if i[1].count(j) == 1:
                a *= v.count(j)
            else:
                x = v.count(j)
                y = i[1].count(j)
                a *= (math.factorial(x) // math.factorial(x-y)) // math.factorial(y)
        ans += a
    print(L[0][0])
    print(ans)

if __name__ == '__main__':
    main()

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

v = [int(i) for i in input().split()]
v.sort(reverse=True)

max_average = sum(v[:A]) / A

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

ans = 0
cnt = 0
if v[0] == v[A-1]:
    for i in range(N):
        if v[i] == v[0]:
            cnt += 1
    for i in range(A, B+1):
        ans += C[cnt][i]
else:
    included = 0
    for i in range(N):
        if v[i] == v[A-1]:
            cnt += 1
            if i < A:
                included += 1
    ans += C[cnt][included]

print(max_average)
print(ans)

Solution (Python):
import itertools,math,bisect,pprint,sys
n, a, b = map(int, raw_input().split())
v = sorted(map(int, raw_input().split()))[::-1]
res1 = sum(v[:a])*1.0/a
print '{0:.6f}'.format(res1)
res2 = 0
def nCr(n,r):
    f = math.factorial
    return f(n) / f(r) / f(n-r)
if a==v[:a].count(v[a-1]):
    res2 = 0
    for i in range(a,b+1):
        if i <= v.count(v[a-1]):
            res2 += nCr(v.count(v[a-1]),i)
    print res2
else:
    print nCr(v.count(v[a-1]),v[:a].count(v[a-1]))

Solution (Python):
import math
import functools

def C(n,r):
    f = math.factorial
    return int(f(n) // f(r) // f(n-r))

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

if v[0] == v[a-1]:
    comb = sum([C(x,i) for i in range(a,min(b,x)+1)])
else:
    comb = C(x,y)

print(ave)
print(comb)

Solution (Python):
import math
def main():
    N, A, B = map(int, input().split())
    v = sorted(map(int, input().split()))[::-1]
    L = []
    for i in range(A, B+1):
        L += [[sum(v[:i]) / i, v[:i]]]
    LMAX = []
    x = L[0][0]
    for i in L:
        if i[0] == x : LMAX += [i]
    ans = 0
    for i in LMAX:
        a = 1
        for j in set(i[1]):
            if i[1].count(j) == 1:
                a *= v.count(j)
            else:
                x = v.count(j)
                y = i[1].count(j)
                a *= (math.factorial(x) // math.factorial(x-y)) // math.factorial(y)
        ans += a
    print(LMAX[0][0])
    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):


def combb(a, b):
	s1, s2 = 1, 1
	for i in range(a - b + 1, a + 1):
		s1 *= i
	for i in range(1, b + 1):
		s2 *= i
	return s1 / s2


n, a, b = map(int, raw_input().split())
l = map(int, raw_input().split())

l.sort(reverse = True)
s = 0

for i in range(a):
	s += l[i]

s = float(s) / a
print s

q = l[i]
c, d = 0, 0

for i in range(n):
	if (i < a) and (l[i] == q):
		c += 1
	if (i >= a) and (l[i] == q):
		d += 1

e = c + d

if q < s:
	print combb(e, c)
else:
	ss = 0
	for i in range(a, b + 1):
		ss += combb(e, i)
	print ss

Solution (Python):
N, A, B = map(int, input().split())
v = list(map(int, input().split()))
v.sort(reverse=True)
 
def combination(a, b):
    u, d = 1, 1
    for i in range(b):
        u *= a - i
        d *= b - i
    
    return u // d
 
s_i = sum(v[:A])
c_i = A
ans = 0
a = A
while s_i * a == sum(v[:a]) * c_i and a <= B:
    last_num = None
    c = 0
    for i in range(a):
        n = v[i]
        if n == last_num:
            c += 1
        else:
            c = 0
        
        last_num = n
 
    ans += combination(v.count(v[a - 1]), c + 1)
    a += 1
 
print(sum(v[:A]) / A)
print(ans)

Solution (Python):
from sys import stdin 
n,a,b = map(int,stdin.readline().split())
aa = map(int,stdin.readline().split())
aa.sort()
aa.reverse()
di = {}
fa = [1]
for i in xrange(1,100):
    fa.append(i*fa[-1])
def ncr(n,r):
    return fa[n]/(fa[r]*fa[n-r])
for i in aa:
    di[i] = di.get(i,0) + 1 
def ways(m):
    b = aa[:m]
    co = b.count(b[-1])
    ll = aa.count(b[-1])
    return sum(b),ncr(ll,co)

num = 0 
den = 1
ans = 0 
for i in xrange(a,b+1):
    nn,ww = ways(i)
    dd = i 
    if nn * den > dd * num:
        num = nn 
        den = dd 
        ans = ww 
    elif nn * den == dd * num:
        ans += ww 
print "%.10f"%((num*1.0)/den)
print ans

Solution (Python):


import math
import sys

def combination(a, b):
    return math.factorial(a)/(math.factorial(b) * math.factorial(a - b))

def main(argv):
    line = sys.stdin.readline().rstrip("\n")

    while line:
        n, a, b = map(lambda x: int(x), line.split(" ", 3))
        values = map(lambda x: int(x), raw_input().split(" "))

        sorted_values = sorted(values, reverse=True)
        mean = (float)(sum(sorted_values[0:a])) / a
        print mean

        counts = {}
        for v in sorted_values[0:a]:
            if not v in counts:
                counts[v] = 0
            counts[v] += 1

        count = 0
        if len(counts.keys()) == 1:
            c = 0
            for v in sorted_values:
                if v == sorted_values[0]:
                    c += 1
                else:
                    break

            for i in xrange(a, min(b, c) + 1):
                count += combination(c, i)
        else:
            c_s = 0
            c_e = 0
            for v in sorted_values:
                if v > sorted_values[a - 1]:
                    c_s += 1
                elif v == sorted_values[a - 1]:
                    c_e += 1
                elif v < sorted_values[a - 1]:
                    break

            count += combination(c_e, a - c_s)
        print count

        print " "

        line = sys.stdin.readline().rstrip("\n")

if __name__ == "__main__":
    main(sys.argv)

Solution (Python):
import math










def avg(L, atLeast, atMost):
	if (L.count(max(L)) >= atLeast):
		print(max(L))
		ways = 0
		for i in range(atLeast, min(atMost, L.count(max(L))) + 1):
			localWays = math.factorial(L.count(max(L))) // math.factorial(i) // math.factorial(L.count(max(L)) - i)
			ways += localWays
		print(ways)
		return
	L.sort(reverse=True)
	last = L[atLeast - 1]
	print(sum(L[:atLeast]) / atLeast)
	firstIndex = L.index(last)
	
	n = L.count(last)
	i = atLeast - firstIndex
	print(math.factorial(n) // math.factorial(i) // math.factorial(n - i))

[N, atLeast, atMost] = list(map(lambda x: int(x), input().split()))
L = list(map(lambda x: int(x), input().split()))
avg(L, atLeast, atMost)

Solution (Python):
import math
def main():
    N, A, B = map(int, input().split())
    v = sorted(map(int, input().split()))[::-1]
    L = []
    for i in range(A, B+1):
        L += [[sum(v[:i]) / i, v[:i]]]
    LMAX = []
    x = L[0][0]
    for i in L:
        if i[0] == x : LMAX += [i]
    ans = 0
    for i in LMAX:
        a = 1
        for j in set(i[1]):
            if i[1].count(j) == 1:
                a *= v.count(j)
            else:
                x = v.count(j)
                y = i[1].count(j)
                
                
                a *= (math.factorial(x) // math.factorial(x-y)) // math.factorial(y)
        ans += a
    print(LMAX[0][0])
    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
def fact(n):
    if n <= 1:
        return 1
    else:
        return n * fact(n - 1)

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

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

Vs = list(reversed(sorted(Vs)))
cnt = {}
for v in Vs:
    if v not in cnt:
        cnt[v] = 1
    else:
        cnt[v] += 1

dict = {}
for i in range(A, B + 1):
    dict[i] = sum(Vs[:i]) / i

avg = 0
for k in dict:
    if avg < dict[k]:
        avg = dict[k]

cand = []
for k in dict:
    if avg - dict[k] < 1E-6:
        cand.append(k - 1)

ans = 0
for c in cand:
    x = 0
    for i in range(c + 1):
        if Vs[i] == Vs[c]:
            x += 1
    ans += comb(cnt[Vs[c]], x)

print(avg)
print(ans)

Solution (Python):


import math

def C(n1, n2):
    ans = 1
    for i in range(n1, n1-n2, -1):
        ans *= i
    for j in range(1, n2+1):
        ans //= j
    return ans

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

avg = 0.0
way = 0
for num_of_choice in range(A, B + 1):
    choiced = []
    for n in range(num_of_choice):
        choiced.append(Vs[n])
    if choiced[0] == choiced[-1]:
        avg = choiced[0]
        way += C(Vs.count(choiced[0]), num_of_choice)
    else:
        if way != 0:
            break
        border = choiced[-1]
        n1 = Vs.count(border)
        n2 = choiced.count(border)
        avg = sum(choiced) / num_of_choice
        way = C(n1, n2)
        break

print("{:.12f}".format(avg))
print(way)

Solution (Python):
import math

def main():
    N, A, B = map(int, input().split())
    v = sorted(list(map(int, input().split())), reverse=True)
    max_avg = 0
    max_avg_nums = {}
    for n in range(A, B + 1):
        sum_v = 0
        avg_nums = {}
        for i in range(n):
            sum_v += v[i]
            if v[i] not in avg_nums:
                avg_nums[v[i]] = 0
            avg_nums[v[i]] += 1
        avg_v = sum_v / n
        if max_avg < avg_v:
            max_avg = avg_v
            max_avg_nums = avg_nums
    print(max_avg)
    if len(max_avg_nums) == 1:
        vv = list(max_avg_nums.keys())[0]
        num_v = 0
        for i in range(N):
            if vv == v[i]:
                num_v += 1
            else:
                break
        ans = 0
        max_n = min(num_v, B)
        for i in range(A, max_n + 1):
            ans += math.factorial(num_v) // math.factorial(num_v - i) \
                   // math.factorial(i)
        print(ans)
    else:
        max_avg_ptn = 1
        for num, cnt in max_avg_nums.items():
            num_cnt = 0
            for i in range(N):
                if num < v[i]:
                    continue
                elif num == v[i]:
                    num_cnt += 1
                else:
                    break
            max_avg_ptn *= math.factorial(num_cnt) \
                           // math.factorial(num_cnt - cnt) \
                           // math.factorial(cnt)
        print(max_avg_ptn)

if __name__ == '__main__':
    main()

Solution (Python):
from functools import reduce

def fact(n):
    if n == 0:
        return 1
    return reduce(lambda a,b:a*b, range(1, n + 1))

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

N, A, B = map(int, input().split(" "))
v = sorted(map(int, input().split(" ")), reverse=True)
S = sum(v[:A])
print(S / A)

used = v[:A].count(v[A-1])
all = v.count(v[A-1])

if v[0] == v[A - 1]:
    ub = min(B, all)
    print(sum(C(all, i) for i in range(A, ub + 1)))
else:
    print(C(all, used))

Solution (Python):
_, a, b = map(int, raw_input().split())

v = map(int, raw_input().split())

v.sort(key=lambda x: -x)

s = 0
for i in xrange(a):
    s += v[i]

print '{:.6f}'.format(s / float(a))





n = v.count(v[a-1])
k = v[:a].count(v[a-1])


import operator as op
def ncr(n, r):
    r = min(r, n-r)
    if r == 0: return 1
    numer = reduce(op.mul, xrange(n, n-r, -1))
    denom = reduce(op.mul, xrange(1, r+1))
    return numer//denom

if v[0] == v[a-1]:
    ways = 0
    for k in xrange(a, min(b, n) + 1):
        
        ways += ncr(n, k)
    print ways
else:
    k = (v[:a].count(v[a-1]))
    print ncr(n, k)

Solution (Python):
import sys
from math import factorial

def solve():
    N, A, B = map(int, input().split())
    v = [int(i) for i in input().split()]
    v.sort(reverse=True)

    ave_max = sum(v[:A]) / A

    onaji = v.count(v[0])

    if onaji < A:
        k = v[:A].count(v[A - 1])
        n = v.count(v[A - 1])
        cnt = binom(n, k)
    else:
        cnt = 0

        for i in range(A, min(onaji, B) + 1):
            cnt += binom(onaji, i)

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


def binom(n, k):
    return (factorial(n) // factorial(n - k)) // factorial(k)

def debug(x, table):
    for name, val in table.items():
        if x is val:
            print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)
            return None

if __name__ == '__main__':
    solve()

Solution (Python):
import math
N,A,B = map(int,input().split())
V = list(map(int,input().split()))
V.sort()
S = V[-A:]
avgmax = sum(S) / A
print(avgmax)

Vs = V.count(min(S))
Ss = S.count(min(S))
if min(S) != max(S):
	C = math.factorial(Vs) // (math.factorial(Vs -Ss) * math.factorial(Ss))
	print(C)
else:
	i = A
	C = 0
	while i <= B and V[-i] == min(S):
		c = math.factorial(Vs) // (math.factorial(Vs -i) * math.factorial(i))
		C = C + c
		i = i + 1
	print(C)

Solution (Python):
n, a, b = map(int, input().split())
data = sorted(map(int, input().split()), reverse = True)
s = sum(data[:a])
k = a
last = data[a-1]
p = sum(map(lambda x: x == last, data[:a]))
if data[0] == last:
  q = sum(map(lambda x: x == last, data[:b]))
else:
  q = p  
z = sum(map(lambda x: x == last, data))

r = 1
res = 0
for i in range(q):
  r *= z - i
  r //= i + 1
  if i >= p-1:
    res += r  
    
print(s/k)
print(res)

Solution (Python):
def nCk(n,k):
    ret=1
    if n<k or k<0 or n<0:return 0
    if n-k<k:
        k=n-k
    for i in xrange(n,n-k,-1):
        ret=ret*i
    fact=[1]*(k+1)
    for i in xrange(1,k+1):
        fact[i]=fact[i-1]*i
    return ret/fact[k]

n,a,b=map(int,raw_input().split())
v=map(int,raw_input().split())
v=sorted(v,reverse=True)
if a==n:
    print float(sum(v[0:a]))/a
    print 1
    exit()

num=0
l=0
if v[a]==v[a-1]:
    start=a-1
    for i in xrange(a-1,0,-1):
        if v[i]==v[i-1]:
            start=i-1
        else:
            break
    if start==0:
        cnt=1
        for i in xrange(n-1):
            if v[i]==v[i+1]:
                cnt+=1
        pt=0
        for i in xrange(a,b+1):
            if cnt<i:break
            pt+=nCk(cnt,i)
        print float(sum(v[0:a]))/a
        print pt
    else:
        cnt=1
        for i in xrange(start,n-1):
            if v[i]==v[i+1]:
                cnt+=1
        pt=0
        for i in xrange(a-start,b+1):
            if start+i<a:continue
            if start+i>a:break
            pt+=nCk(cnt,i)
        print float(sum(v[0:a]))/a
        print pt

else:
    print float(sum(v[0:a]))/a
    print 1

Solution (Python):
memo = [[0] * 60 for i in range(60)]

def comb(n,k):
    if memo[n][k] > 0:
        return memo[n][k]
    elif k == 0 or k == n:
        memo[n][k] = 1
        return memo[n][k]
    else:
        memo[n][k] = comb(n-1,k) + comb(n-1,k-1)
        return memo[n][k]

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

v.sort()
v.reverse()
if len(set(v[:a])) == 1:
    print(v[0])
    cnt = 0
    for i in range(n):
        if v[i] == v[0]:
            cnt += 1
    ans = 0
    for i in range(a,min(b,cnt)+1):
        ans += comb(cnt,i) 
    print(ans)
else:
    total = 0
    for i in range(a):
        total += v[i]
    print("%.10f" % (total/a))
    if a < n and v[a] == v[a-1]:
        l = r = 0
        for i in range(n):
            if v[i] == v[a]:
                if i < a:
                    l += 1
                else:
                    r += 1
        print(comb(l+r,l))
    else:
        print(1)

Solution (Python):
from fractions import Fraction

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

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

average_max=Fraction(sum(vs[n-a:]),a)
print("{0:.9f}".format(float(average_max)))

res=0
for m in range(a,b+1):
    average=Fraction(sum(vs[n-m:]),m)
    if average<average_max:
        continue
    mn=min(vs[n-m:])
    res+=choose(sum(1 for x in vs if x==mn),
                sum(1 for x in vs[n-m:] if x==mn))
print(res)

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

ans = 0.0
for i in range(a):
	ans += v[i]

ans /= a

print(ans)

cnt = 0
cnt2 = 0
for i in range(n):
	if v[a-1] == v[i]:
		cnt += 1
		if i >= a-1:
			cnt2 += 1

comb = [[0 for i in range(55)] for j in range(55)]
for i in range(55):
	comb[i][i] = 1
	comb[i][0] = 1
	for j in range(1,i):
		comb[i][j] = comb[i-1][j-1] + comb[i-1][j]

ans2 = 0

if v[0] == v[a-1]:
	for i in range(a-1, b):
		if v[i] != v[0]:
			break
		num = i+1
		ans2 += comb[cnt][num]
else:
	num = cnt-cnt2+1
	ans2 += comb[cnt][num]
print(ans2)

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

def nCr(n, r):
    """
    Calculate the number of combination (nCr = nPr/r!).
    The parameters need to meet the condition of n >= r >= 0.
    It returns 1 if r == 0, which means there is one pattern
    to choice 0 items out of the number of n.
    """

    
    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

l.sort(reverse = True)
masd = {}
for i in l:
	masd[i] = 0
for i in l:
	masd[i] += 1

res = 0

maxave = 0

task = []

for i in range(A,B+1):
	if maxave < sum(l[:i])/i:
		maxave = sum(l[:i])/i
		task = [i]
	elif maxave == sum(l[:i])/i:
		task.append(i)

for i in task:
	c = 1
	d = {}
	for j in l[:i]:
		d[j] = 0
	for j in l[:i]:
		d[j] += 1

	for j in d.keys():
		c *= nCr(masd[j],d[j])
	res += c

print(maxave)
print(res)

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

ans = 0.0
for i in range(a):
	ans += v[i]

ans /= a
print("{0:.20f}".format(ans))

cnt = 0
cnt2 = 0
for i in range(n):
	if v[a-1] == v[i]:
		cnt += 1
		if i >= a-1:
			cnt2 += 1

comb = [[0 for i in range(55)] for j in range(55)]
for i in range(55):
	comb[i][i] = 1
	comb[i][0] = 1
	for j in range(1,i):
		comb[i][j] = comb[i-1][j-1] + comb[i-1][j]

ans2 = 0

if v[0] == v[a-1]:
	for i in range(a-1, b):
		if v[i] != v[0]:
			break
		num = i+1
		ans2 += comb[cnt][num]
else:
	num = cnt-cnt2+1
	ans2 += comb[cnt][num]
print(ans2)

Solution (Python):
from collections import defaultdict
if __name__ == '__main__':
    N,A,B = map(int, input().split())
    values = list(map(int, input().split()))
    values.sort(reverse=True)
    result = 0
    max_values = []
    dic_values = defaultdict(int)
    for x in values:
        dic_values[x] += 1
    for limit in range(A, B + 1):
        res = []
        for i,x in enumerate(values):
            if (i >= limit):
                break
            res.append(x)
        if (result < sum(res) / len(res)):
            result = sum(res) / len(res)
            max_values = res

    print ("%.20lf" % result)
    comb = 0
    for limit in range(A, B + 1):
        res = []
        for i,x in enumerate(values):
            if (i >= limit):
                break
            res.append(x)
        if (result == sum(res) / len(res)):

            res_dic = defaultdict(int)
            for x in res:
                res_dic[x] += 1
            tmp = 1
            for key in res_dic:
                a = dic_values[key]
                b = res_dic[key]
                res = 1
                for x in range(b):
                    res *= a
                    a -= 1
                while (b > 0):
                    res //= b
                    b -= 1
                tmp *= res
            comb += tmp
    print (comb)

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

dp = [[-1 for _ in range(N + 1)] for _ in range(N + 1)]
cnt = [[0 for _ in range(N + 1)] for _ in range(N + 1)]
dp[0][0] = 0
cnt[0][0] = 1

for i in range(N):
    for j in range(N - 1, -1, -1):
        if dp[i][j] == -1:
            continue
        dp[i+1][j] = dp[i][j]
        cnt[i+1][j] = cnt[i][j]

        ncost = dp[i][j] + v[i]
        if dp[i+1][j+1] < ncost:
            dp[i+1][j+1] = ncost
            cnt[i+1][j+1] = cnt[i][j]
        elif dp[i+1][j+1] == ncost:
            cnt[i+1][j+1] += cnt[i][j]

maxVal = 0
maxCnt = 0
for i in range(A, B + 1):
    if maxVal < dp[N][i] / i:
        maxVal = dp[N][i] / i
        maxCnt = cnt[N][i]
    elif maxVal == dp[N][i] / i:
        maxCnt += cnt[N][i]

print(maxVal)
print(maxCnt)

Solution (Python):
from fractions import Fraction

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

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

average_max=Fraction(sum(vs[n-a:]),a)
print("{0:.9f}".format(float(average_max)))

res=0
for m in range(a,b+1):
    average=Fraction(sum(vs[n-m:]),m)
    if average<average_max:
        continue
    mn=min(vs[n-m:])
    res+=choose(sum(1 for x in vs if x==mn),
                sum(1 for x in vs[n-m:] if x==mn))
print(res)