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):
def C(x,y):
    M=1
    for i in range(1,x+y+2):
        M=M*i
    for i in range(1,x+2):
        M=M//i
    for i in range(1,y+1):
        M=M//i
    return M


N, A, B = map(int, input().split())
v = [int(i) for i in input().split()]
v.sort(reverse=True)
v.append(0)
S=0
p=0
for i in range(A,B+1):
    T=sum(v[:i])/i
    if S<T:
        S=T
        p=0
        x=0
        y=0
        for j in range(i-1):
            if v[i-j-2]==v[i]:
                x+=1
            else:
                break
        for j in v[i:]:
            if j==v[i-1]:
                y+=1
            else:
                break
        
        p+=C(x,y)
    elif S==T:
        x=0
        y=0
        for j in range(i-1):
            if v[i-j-2]==v[i]:
                x+=1
            else:
                break
        for j in v[i:]:
            if j==v[i-1]:
                y+=1
            else:
                break
        
        p+=C(x,y)
print(S)
print(p)

Solution (Python):
import heapq
import copy
from collections import Counter

N,A,B=map(int, raw_input().split())
v=map(int, raw_input().split())
v.sort()
v.reverse()
c=Counter(v)

def C(n,r):
	bunshi=1
	bunbo=1
	for i in range(n,n-r,-1):
		bunshi*=i
	for i in range(1,r+1):
		bunbo*=i
	return bunshi/bunbo

ans=0
if A<=c[v[0]]:
	high=c[v[0]]
	for i in range(A,B+1):
		if i<=high:
			n=c[v[0]]
			r=i
			ans+=C(n,r)
	print v[0]
	print ans
	quit()
else:
	cnt=0
	t_sum=0
	cur=-1
	for i in v:
		cnt+=c[i]
		t_sum+=i*c[i]
		if cnt==A:
			n=A
			r=A
			break
		if cnt>A:
			n=c[i]
			r=A-(cnt-c[i])
			t_sum=t_sum-i*c[i]+i*r
			break

	print float(t_sum)/float(A)
	print C(n,r)

Solution (Python):
def comb(left, right):
    top = 1
    for i in range(left, left - right, -1):
        top *= i

    bottom = 1
    for i in range(1, right + 1):
        bottom *= i

    return top // bottom

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

v.sort()

min_set = v[-a:]
print(sum(min_set) / len(min_set))
if len(set(min_set)) == 1:
    cnt = v.count(min_set[0])

    result = 0
    for i in range(a, min(cnt, b) + 1):
        result += comb(cnt, i)
    print(result)
else:
    print(comb(v.count(min_set[0]), min_set.count(min_set[0])))

Solution (Python):
from scipy.misc import comb
from decimal import *
import math
import copy

def nClr(n,l,r):
	ans = 0
	pat = 1
	if l == 0:
		ans += 1
		l += 1

	for i in range(l-1):
		pat *= ((n-i)/(i+1))

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

	return int(ans)

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

v.sort(reverse=True)

mean =float(sum(v[0:A]))/float(A)
whole = {}

for i in range(A):
	if v[i] in whole:
		whole[v[i]] += 1
	else:
		whole[v[i]] = 1

ran_A = copy.deepcopy(whole)

for i in range(A,N):
	if v[i] in whole:
		whole[v[i]] += 1
	else:
		whole[v[i]] = 1


if len(ran_A) == 1:
	n = min(B,whole[v[0]])
	num = nClr(whole[v[0]],A,n)
	print(mean)
	print(num)
	exit(0)


num = 1
for key,val in ran_A.items():
	if ran_A[key] != whole[key]:
		num *= comb(whole[key],ran_A[key])


print(mean)
print(int(round(num,0)))

Solution (Python):
def d_MaximumAverageSets(N, A, B, 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]

    
    import decimal
    v = sorted(V, reverse=True)
    max_ave = decimal.Decimal(sum(v[:A]) / A)

    count = 0
    if v[0] != v[A - 1]:
        X = Y = 0
        for i in range(N):
            if v[A - 1] == v[i]:
                X += 1
                if i < A:
                    Y += 1
        count = C[X][Y]
    else:
        X = 0
        for i in range(N):
            if v[0] == v[i]:
                X += 1
        for i in range(A, B + 1):
            count += C[X][i]
    ans = '{}\n{}'.format(max_ave, count)
    return ans

N,A,B = [int(i) for i in input().split()]
V = [int(i) for i in input().split()]
print(d_MaximumAverageSets(N, A, B, V))

Solution (Python):
N, A, B = map(int, input().split())
v = list(map(int, input().split()))
v.sort(reverse=True)
ave = lambda a: sum(a) / len(a)
a = []
INF = int(1e9)

def C(n, m):
    ret = 1
    for i in range(m):
        ret *= n - i
    for i in range(2, m+1):
        ret //= i
    return ret

for i in range(A, B+1):
    a.append((ave(v[:i]), i))
ans1, i = max(a)
ans2 = 0
for b, j in a:
    if b != ans1:
        continue
    c1 = v[:j].count(v[j-1])
    c2 = v.count(v[j-1])
    ans2 += C(c2, c1)
print(ans1)
print(ans2)

Solution (Python):

def inpl(): return list(map(int, input().split()))
from collections import Counter
from math import factorial

N, A, B = inpl()
V = sorted(inpl(), reverse=True)
C = Counter(V)

S = [sum(V[:i]) / i for i in range(1, N+1)]
M = max(S[A-1:B])
print(M)
T = [M==s if (A-1<=i)*(i<B) else False for i, s in enumerate(S)]

res = 0
for i in range(N):
    if T[i]:
        x, y = V.count(V[i]), V[:i+1].count(V[i])
        res += factorial(x) // factorial(y) // factorial(x-y)
print(res)

Solution (Python):
from math import factorial
from functools import reduce
def combinations(x, y):
    a = reduce(lambda x, y: x*y , [x - i for i in range(y)])
    b = factorial(y)
    return a//b
N, A, B = map(int,input().split())
v = sorted([int(vi) for vi in input().split()],reverse=True)
ans1 = sum(v[:A])/A

if v[0] != v[A-1]:
    X = sum([v[A-1] == v[i] for i in range(N)])
    Y = sum([v[A-1] == v[i] for i in range(A)])
    ans2 = combinations(X, Y)
else:
    X = sum([v[0] == v[i] for i in range(N)])
    ans2 = sum([combinations(X,i) for i in range(A, B+1)])

print(ans1)
print(ans2)

Solution (Python):
def comb(n, c) :
    ans = 1
    for i in range(1, c+1):
        ans *= (n - i + 1) / i
    return ans


if __name__ == '__main__':

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

    items = {}
    for i in l :
        if i in items:
            items[i] = items[i] + 1
        else:
            items[i] = 1

    oitems = sorted(items.items(), key=lambda x: x[0], reverse=True)

    num = 0
    sum = 0
    ans = 0
    for i in oitems :
        if num + i[1] > a:
            if num == 0 or sum / num == i[0] :
                print(i[0])
                for j in range (a - num, min(b - num, i[1])+1) :
                    ans += comb(i[1], j)
                print(int(ans))
                break 
            else: 
                print("{:.6f}".format((sum + (a - num) * i[0]) / a))
                print(int(comb(i[1],a - num)))
                break 
        else :
            num += i[1]
            sum += i[0] * i[1]

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

vs.sort(reverse=True)
print(sum(vs[:A]) / A)

iVA = vs.index(vs[A - 1])
numVA = vs.count(vs[A - 1])

comb = [0] * (numVA + 1)
comb[0] = 1
for k in range(1, numVA + 1):
    comb[k] = comb[k - 1] * (numVA - k + 1) // k

if vs[0] != vs[A - 1]:
    print(comb[A - iVA])
else:
    ans = 0
    for k in range(A - iVA, min(B, numVA) + 1):
        ans += comb[k]
    print(ans)

Solution (Python):
from itertools import combinations
N, A, B = [int(n) for n in input().split()]
v = [int(n) for n in input().split()]

v.sort(reverse=True)
s = sum(v[:A])
avg = s/A

print(s/A)

fac = [1]

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


def C(n, k):
  return fac[n]//(fac[k] * fac[n-k])


if v[0] != v[A-1]:
  cnt_a_1 = len([t for t in v if t == v[A-1]])
  cnt_a_1_in = len([t for t in v[:A] if t == v[A-1]])
  print(C(cnt_a_1, cnt_a_1_in))
if v[0] == v[A-1]:
  cnt_a_1 = len([t for t in v if t == v[A-1]])
  res = 0
  for i in range(A, B+1):
    res += C(cnt_a_1, i)
  print(res)

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

ave = sum(src[:A]) / A
print(ave)

counter = Counter(src)
cnt = counter[src[0]]

ncr = [[1]]
for n in range(1,N+1):
    ncr.append([1])
    for r in range(1,n):
        ncr[n].append(ncr[n-1][r-1] + ncr[n-1][r])
    ncr[n].append(1)

if cnt < A:
    last = src[A-1]
    n = counter[last]
    r = src[:A].count(last)
    print(ncr[n][r])
elif cnt == A:
    print(1)
else:
    ans = 0
    for r in range(A, min(B,cnt)+1):
        ans += ncr[cnt][r]
    print(ans)

Solution (Python):
import math
from collections import Counter

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

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

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

max_ave = max(ave)
ans = 0

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

print(max_ave)
print(ans)

Solution (Python):
n,a,b=[int(x) for x in input().split()]
v=sorted([int(x) for x in input().split()],reverse=True)
from collections import Counter
c=Counter(v)
aveMax=0
avelist=[]
for i in range(a,b+1):
    avetmp=sum(v[:i])/i
    if avetmp>=aveMax:
        aveMax=avetmp
        avelist.append(Counter(v[:i]))
from math import factorial
def nCm(n,m):
    return factorial(n)//factorial(m)//factorial(n-m)
ans=0    
for i in avelist:
    multi=1
    for j in i:
        multi=multi*nCm(c[j],i[j])
    ans+=multi
print("{:.6f}".format(aveMax))
print(ans)

Solution (Python):
def makePascal(n):  
  res = [[1]]

  for m in range(1, n+1):
    l = []
    for k in range(m + 1):
      if k == 0 or k == m:
        l.append(1)
      else:
        tmp = res[m-1][k-1] + res[m-1][k]
        l.append(tmp)
    res.append(l)

  return res


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

v.sort(reverse = True)

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

if len(set(v[:A])) == 1:
  maxs = v.count(v[0])
  B = min(B, maxs)
  ans = 0
  for i in (range(A, B+1)):
    ans += comb[maxs][i]
  print(ans)
else:
  mini = min(v[:A])
  minis = v[:A].count(mini)
  ans = comb[v.count(mini)][minis]
  print(ans)

Solution (Python):
import scipy.misc as scm

def aCb(n, r):
    ans = 1
    for x in range(1, n + 1):
        ans *= x
    for x in range(1, n - r + 1):
        ans //= x
    for x in range(1, r + 1):
        ans //= x
    return ans

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

sorted_v = sorted(v)[::-1]

ans= sum(sorted_v[:A])/A

print(ans)


n = sorted_v.count(sorted_v[A-1]) 


if ans != sorted_v[A-1]:
    r = sorted_v[:A].count(sorted_v[A-1])
    print(int(aCb(n, r)))
    
else:
    C = 0
    for num in range(A, B+1):

        if num <= n:
            C += (aCb(n, num))
        else :
            break
    print(int(C))

Solution (Python):
from collections import defaultdict
from collections import Counter

def aCb(n, r):
    ans = 1
    for x in range(1, n + 1):
        ans *= x
    for x in range(1, n - r + 1):
        ans //= x
    for x in range(1, r + 1):
        ans //= x
    return ans


def main():
    N, A, B = map(int, input().split())
    v_list = list(sorted(list(map(int, input().split()))))
    c_entire = Counter(v_list)
    total = sum(v_list[-A:])

    ans = 0
    for n in range(A, B + 1):
        p = v_list[-n:]
        if sum(p) * A == total * n:
            c = Counter(p)
            t = 1
            for k, v in c.items():
                t *= aCb(c_entire[k], v)
            ans += t

    print("{0:.7f}".format(total / A))
    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
from math import factorial

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

def product(iterable):
    prod = 1
    for n in iterable:
        prod *= n
    return prod

def npr(n, r):
    return product(range(n - r + 1, n + 1))

def ncr(n, r):
    if r > n // 2:
        r = n - r
    return npr(n, r) // factorial(r)

v.sort();
revv=list(reversed(v))
print(sum(v[-a:])/a)
revpos=revv.index(v[-a]);
num=v.count(v[-a]);
ans=0
if v[-1] == v[-a] == v[-a-1]:
    for i in range(a-revpos, b-revpos+1):
        if i > num:
            continue;
        ans+=ncr(num, i);
    print(ans);    
else:
    print(ncr(num,a-revpos));

Solution (Python):
import sys
from collections import Counter




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


def read_str_list():
    return input().split()


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


def read_str():
    return input()


def solve(n, a, b, v):
    c = Counter(v)
    res = 0
    m = max(v)
    if c[m] >= a:
        for k in range(a, b + 1):
            res += coef[c[m]][k]
        mean = m
        return mean, res
    else:
        values = sorted(set(v), reverse=True)
        s = 0
        r = a
        for value in values:
            if c[value] < r:
                r -= c[value]
                s += value * c[value]
            else:
                res = coef[c[value]][r]
                s += value * r
                break
        mean = s / a
        return mean, res


coef = [[0] * 51 for i in range(51)]
for i in range(0, 51):
    coef[i][0] = 1
    for k in range(1, i + 1):
        coef[i][k] = coef[i - 1][k - 1] + coef[i - 1][k]

n, a, b = read_int_list()
v = read_int_list()
mean, res = solve(n, a, b, v)
print(mean)
print(res)

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

idx = V.index(V[A-1])
k = V.count(V[A-1])
avr = sum(V[:A]) / A
print "%f" % avr

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

if idx > 0:
    y = A - idx
    print fact(k) / fact(y) / fact(k-y)
else:
    cnt = 0
    for i in range(A, B+1):
        cnt += fact(k) / fact(i) / fact(k-i)
    print cnt

Solution (Python):
import math

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

v.sort()
v.reverse()
w=0
for i in range (0,A):
  w+=v[i]
ave=w/A
print(ave)

mini=v[A]
C=v[0:A].count(mini)
D=v[0:A].count(mini)+B-A
if v[0]!=v[A]:
  D=A
  for k in range (0,A):
    if v[k]>v[A]:
      D-=1
p=v.count(mini)
D=min(D,p)

q=0
for k in range (C,D+1):
  q+=math.factorial(p)/(math.factorial(p-k)*math.factorial(k))
print(int(q))

Solution (Python):

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

N = nab[0]
A = nab[1]
B = nab[2]
V = list(reversed(sorted(list(map(int, input().split())))))


def count(n):
    result = []
    prev = V[0]
    count = 1
    for i, v in enumerate(V[1:n]):
        if (v == prev):
            count += 1
        else:
            result.append(count)
            count = 1
        
        if(i == n-2):
            result.append(count)
        prev = v
        
    return result
        
def greedy(n):
    return sum(V[0:n])/n

def fact(n):
    res = 1
    for i in range(1,n+1):
        res *= i
    return res

def comb(p, u):
    nume = 1
    for i in range(u):
        nume *= (p-i)
    return int(nume / fact(u))


max_ave = -1
max_ave_comb = 0
counts = count(N)

for i in range(A, B+1):
    u = i 
    ave = greedy(i)
    if (max_ave <= ave):
        for j in counts:
            if (u-j <= 0):
                if (max_ave != ave):
                    max_ave_comb = comb(j, u)
                else:
                    max_ave_comb += comb(j, u)
                break
            else:
                u -= j
        max_ave = ave
print(max_ave)
print(max_ave_comb)

Solution (Python):
import numpy as np
def comb(a, b):
    ans = 1
    for i in range(b):
        ans *= (a-i)
    for i in range(b):
        ans /= (i+1)
    return ans
N, A, B = map(int, raw_input().split())
v = sorted(map(np.int64, raw_input().split()))
value_num_mapping = {}
for _ in v:
    if not _ in value_num_mapping:
        value_num_mapping[_] = 0
    value_num_mapping[_] += 1

best = np.mean(v[-A:])
ans = 0
for T in range(A, B+1):
    if np.sum(v[-T:]) * A== np.sum(v[-A:]) * T:
        cnt = len([_ for _ in v[-T:] if _ == v[-T]])
        ans += comb(value_num_mapping[v[-T]], cnt)
print best
print ans

Solution (Python):
import math

def comb(n, m) :
    fact = math.factorial
    return fact(n) // fact(m) // fact(n-m)

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

ret = 0
prev = [0, 1]
for i in range(A, B + 1):
    cur = [sum([val[j] for j in range(i)]), i]
    if i > A and prev[0] * cur[1] > prev[1] * cur[0]:
        break
    ret += comb(val.count(val[i-1]), val[:i].count(val[i-1]))
    prev = cur

print(format(prev[0] / prev[1], '.12f'))
print(ret)

Solution (Python):
from builtins import print


def comb(n, m) :
    ans = 1
    for i in range(n) :
        ans *= i+1
    for i in range(m) :
        ans //= i+1
    for i in range(n-m) :
        ans //= i+1
    return ans


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

ret = 0

prev = [0, 1]
for i in range(A, B+1) :
    cur = [ sum( [ val[j] for j in range(i) ]) , i]
    if i > A :
        if prev[0] * cur[1] > prev[1] * cur[0] :
            break
    cntLarge = [ 1 if v > val[A] else 0 for v in val  ].count(1)
    ret += comb( val.count(val[i-1]) ,i - cntLarge)
    prev = cur

print(format(prev[0] / prev[1], '.12f'))
print(ret)

Solution (Python):
import sys

sys.setrecursionlimit(10000)


def memoize(f):
    cache = {}

    def func(*args):
        if args not in cache:
            cache[args] = f(*args)
        return cache[args]

    return func


@memoize



def combi(n, r):
  if r == 0 or n == r:
    return 1
  return combi(n-1, r-1) + combi(n-1, r)

n, a, b = map(int, input().split())
items = sorted(map(int, input().split()), reverse=True)
max_ave_list = items[:a]
print(sum(max_ave_list)/len(max_ave_list))

m = max_ave_list.count(max_ave_list[-1])
l = items.count(max_ave_list[-1])
if l == m:
  print(1)
elif max_ave_list[0] != max_ave_list[-1]:
  print(combi(l, m))
else:
  print(sum(combi(l, k) for k in range(m, min(b, l) + 1)))

Solution (Python):
n, a, b = map(int, raw_input().split())
V = sorted(map(int, raw_input().split()))
C = {}
for v in V:
    C[v] = C.get(v, 0) + 1

memo = {}
def comb(n, k):
    if n == k or k == 0:
        return 1
    if (n, k) in memo:
        return memo[n, k]
    res = memo[n, k] = comb(n-1, k) + comb(n-1, k-1)
    return res

su = 0.
count = 0

cur = 0
tmp = 0.
for k in sorted(C.keys(), reverse=True):
    if cur >= b:
        break
    if cur+C[k] < a:
        cur += C[k]
        tmp += C[k]*k
    else:
        for c in xrange(max(a, cur+1), min(b, cur+C[k])+1):
            tmp_ = tmp + k*(c-cur)
            if su*c < tmp_:
                su = tmp_/c
                count = comb(C[k], c-cur)
            elif su*c == tmp_:
                count += comb(C[k], c-cur)
        cur += C[k]
        tmp += C[k]*k
print "%.6f" % su
print count

Solution (Python):
import sys

sys.setrecursionlimit(10000)


def memoize(f):
    cache = {}

    def func(*args):
        if args not in cache:
            cache[args] = f(*args)
        return cache[args]

    return func


@memoize
def combi(n, r):
    if r == 0 or n == r:
        return 1
    return combi(n - 1, r - 1) + combi(n - 1, r)


n, a, b = map(int, input().split())
items = sorted(map(int, input().split()), reverse=True)
max_ave_list = items[:a]
print(sum(max_ave_list) / len(max_ave_list))

m = max_ave_list.count(max_ave_list[-1])
l = items.count(max_ave_list[-1])
if l == m:
    print(1)
elif max_ave_list[0] != max_ave_list[-1]:
    print(combi(l, m))
else:
    print(sum(combi(l, k) for k in range(m, min(b, l) + 1)))

Solution (Python):
def ncr(n, r):
  res = 1
  for k in range(r):
    res *= n - k
    res //= k + 1
  return res
 
(n, a, b) = [int(x) for x in input().split(' ')]
v = [int(x) for x in input().split(' ')]
v.sort(reverse=True)
 
su = 0
avg = 0
for x in v[:a]:
  su += x
avg = su / a
 
comb = 0
cnt1 = v.count(v[a - 1])
cnt2 = v[:a].count(v[a - 1])
if v[0] == v[a - 1]:
  for i, vi in enumerate(v[a - 1:b]):
    if vi == v[a - 1]:
      comb += ncr(cnt1, cnt2 + i)
else:
  comb = ncr(cnt1, cnt2)

print(avg)
print(comb)

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

v.sort()
v.reverse()

def average(l,a):
    sum=0
    for i in range(a):
        sum+=l[i]
    return (sum/a)


kaijoulist=[1,1]
def kaijou(n):
    t=len(kaijoulist)
    while t<=n:
        kaijoulist.append(kaijoulist[-1]*t)
        t+=1
    return kaijoulist[n]

def combination(n,k):
    return int(kaijou(n)/(kaijou(k)*kaijou(n-k)))



max_index=[A]
max=average(v,A)
for i in range(A+1,B+1):
    ave=average(v,i)
    if max<ave:
        max_index=[i]
        max=ave
    elif max==ave:
        max_index.append(i)

li_uniq = list(set(max_index))



answer=0
for i in li_uniq:
    x=v[i-1]
    kosuu=v.count(x)
    sentou=v.index(x)
    answer+=combination(kosuu,i-sentou)

print(max)
print(answer)

Solution (Python):

N,A,B = list(map(int,input().split(" ")))
V = list(map(int,input().split(" ")))
V.sort(reverse=True)
max_avr = sum(V[:A]) / A
a_num = V.count(V[A-1])
a_pos = V[:A].count(V[A-1])


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

if V[0] == V[A-1]:
    cnt = sum(nCr(a_num,i) for i in range(A,min(B,a_num)+1)) 
else:
    cnt = nCr(a_num,a_pos)
print("{0:.10f}".format(max_avr))
print(int(cnt))

Solution (Python):
import numpy as np

N, A, B = list(map(int, input().split()))
V = np.array(list(map(int, input().split())))
V.sort()
V[:] = V[::-1]

def fac(n):
    return 1 if n<=1 else n*fac(n-1)
        
def nCr(n, r):
    return fac(n) // fac(n-r) // fac(r)

d = V[A-1]

if d == V.max():
    
    d_eq_cnt = np.count_nonzero(V == d)
    res = nCr(d_eq_cnt, A)
    res_sum = res
    for k in range(1, min(B, d_eq_cnt) + 1 - A):
        res = res * (d_eq_cnt - (A+k-1)) // (A+k)
        res_sum += res
    print(V[:A].mean())
    print(res_sum)
    
    
else:
    
    d_eq_cnt = np.count_nonzero(V == d)
    d_lq_cnt = np.count_nonzero(V > d)
    print(V[:A].mean())
    print(nCr(d_eq_cnt, A - d_lq_cnt))

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

num = [0 for x in range(N)]
total = [0 for x in range(N)]

for i, v in enumerate(L):
    for j in reversed(range(1, i + 1)):
        new_v = total[j - 1] + v
        if(new_v > total[j]):
            total[j] = new_v
            num[j] = num[j - 1]
        elif(new_v == total[j]):
            num[j] = num[j] + num[j - 1]

    if(v > total[0]):
        total[0] = v
        num[0] = 1
    elif(v == total[0]):
        num[0] = num[0] + 1

total = [x / (i + 1) for i, x in enumerate(total)]
total = total[(A - 1):B]
num = num[(A - 1):B]

maxV = max(total)
maxNum = sum([j for i, j in zip(total, num) if i == maxV])
print(maxV)
print(maxNum)

Solution (Python):

from collections import Counter

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

N, A, B = map(int, raw_input().split())
v = map(int, raw_input().split())
v.sort(reverse = True)
cnt = Counter(v)

mx = sum(v[:A]) 
comb = 0
for n in xrange(A, B + 1):
    tmp = 1
    for key, val in Counter(v[:n]).items():
        tmp *= combinations(cnt[key], val)

    if A*sum(v[:n]) == n*mx:
        comb += tmp 

print "%.10f" % (mx*1.0/A)
print comb

Solution (Python):

import sys,copy,math,heapq,itertools as it,fractions,re,bisect,collections

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

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

cnt = collections.Counter(v)

mx = sum(v[:A]) 
comb = 0
for n in xrange(A, B + 1):

    tmp_cnt = collections.Counter(v[:n])
    tmp = 1
    for key, val in tmp_cnt.items():
        tmp *= combinations(cnt[key], val)

    if A*sum(v[:n]) == n*mx:
        comb += tmp 

print "%.10f" % (mx*1.0/A)
print comb

Solution (Python):
import math

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

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

v_sort = sorted(v, reverse=True)

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

a, b = v_sort.count(v_sort[A-1]), v_sort[:A].count(v_sort[A-1])

if v_sort[0] == v_sort[A-1]:
	print(sum([C(a, r) for r in range(A, min(B, a)+1)]))
else:
	print(C(a, b))

Solution (Python):


import sys
import os
import math


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


subset = values[-A:]
mean = sum(subset) / len(subset)
print(mean)

def pascals_triangle(n_rows):
    results = []
    for _ in range(n_rows):
        row = [1]
        if results:
            last_row = results[-1]
            row.extend([sum(pair) for pair in zip(last_row, last_row[1:])])
            row.append(1)
        results.append(row)
    return results[-1] 

if subset[0] == subset[-1]:
    
    cnt = values.count(subset[0])
    tri = pascals_triangle(cnt + 1)

    if cnt >= B:
        tri_subset = tri[A:B+1]
        print(sum(tri_subset))

    
    else:
        tri_subset = tri[A:cnt + 1]
        print(sum(tri_subset))

else:
    
    v = subset[0]
    cnt_in_all = values.count(v)
    cnt_in_subset = subset.count(v)

    
    tri = pascals_triangle(cnt_in_all + 1)
    ans = tri[cnt_in_subset]
    print(ans)

Solution (Python):
import collections


def iterative_egcd(a, b):
    x,y, u,v = 0,1, 1,0
    while a != 0:
        q,r = b//a,b%a; m,n = x-u*q,y-v*q 
        b,a, x,y, u,v = a,r, u,v, m,n
    return b, x, y
 

def recursive_egcd(a, b):
    """Returns a triple (g, x, y), such that ax + by = g = gcd(a,b).
       Assumes a, b >= 0, and that at least one of them is > 0.
       Bounds on output values: |x|, |y| <= max(a, b)."""
    if a == 0:
        return (b, 0, 1)
    else:
        g, y, x = recursive_egcd(b % a, a)
        return (g, x - (b // a) * y, y)
 
egcd = iterative_egcd  
 
def modinv(a, m):
    g, x, y = egcd(a, m) 
    if g != 1:
        return None
    else:
        return x % m
 
def conv(n,a):
    ret = 1
    for i in range(1,a+1):
        ret *= n-a+i
        ret //= i
    return ret
        
n,a,b = map(int, input().split(' '))
v = map(int, input().split(' '))

v = sorted(v, reverse=True)
select = v[:a]
result1 = sum(select)/len(select)

result2 = 0
v_cnt = collections.Counter(v)
for i in range(a,b+1):
    select = v[:i]
    if result1 == sum(select)/len(select):
        select = collections.Counter(select)
        buf = 1
        for v_ in v_cnt:
            buf *= conv(v_cnt[v_],select[v_])
        result2 += buf
print('%.6f'%result1)
print(result2)

Solution (Python):
import operator
import functools


def main():
    N, A, B = map(int, input().split())
    v = list(map(int, input().split()))
    
    v.sort(reverse=True)
    
    
    print('{:.6f}'.format((sum(v[:A]) / A)))

    va = v[A - 1]
    
    pool = v.count(va)
    
    head = sum(x > va for x in v)
    
    
    
    
    if head == 0:
        
        ans = sum([_nCr(pool, pick) for pick in range(A, min(B, pool) + 1)])
    else:
        pick = A - head
        ans = _nCr(pool, pick)
    print(ans)


def _nCr(n, r):
    r = min(r, n-r)
    if r == 0:
        return 1
    
    numer = functools.reduce(operator.mul, range(n, n-r, -1))
    denom = functools.reduce(operator.mul, range(1, r+1))
    return numer//denom


if __name__ == '__main__':
    main()

Solution (Python):
import operator
import functools


def main():
    N, A, B = map(int, input().split())
    v = list(map(int, input().split()))
    v = list(reversed(sorted(v)))
    
    v_sum = sum(v[:A])
    
    print('{:.6f}'.format((v_sum / A)))

    pool = sum(list(map(lambda x: 1 if x == v[A] else 0, v)))
    head = sum(list(map(lambda x: 1 if x > v[A] else 0, v[:A])))
    
    
    
    
    ans = 0
    if head == 0:
        for pick in range(A, min(B, pool) + 1):
            ans += _nCr(pool, pick)
    else:
        pick = A - head
        ans = _nCr(pool, pick)
    print(ans)


def _nCr(n, r):
    r = min(r, n-r)
    if r == 0:
        return 1
    
    numer = functools.reduce(operator.mul, range(n, n-r, -1))
    denom = functools.reduce(operator.mul, range(1, r+1))
    return numer//denom


if __name__ == '__main__':
    main()

Solution (Python):
import math


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

def main():
    N, A, B = tuple(map(int, input().split(' ')))
    v = list(map(int, input().split(' ')))

    v.sort(reverse=True)

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

    a, b = v.count(v[A-1]), v[:A].count(v[A-1])

    if v[0] == v[A-1]:
        print(sum([C(a, r) for r in range(A, min(B, a)+1)]))
    else:
        print(C(a, b))



if __name__ == '__main__':
    main()

Solution (Python):
import math
import collections


def main():
    
    
    
    n, a, b = [int(x) for x in input().split()]
    nums = [int(x) for x in input().split()]
    nums.sort(reverse=True)
    hml = how_many_largest(nums)
    if hml <= a:
        hml_less(n, a, b, nums, hml)
    elif a < hml < b:
        hml_between(n, a, b, nums, hml)
    else:
        hml_between(n, a, b, nums, b)
    


def hml_less(n, a, b, nums, hml):
    highest = []
    for idx in range(a):
        highest.append(nums[idx])
    mean = sum(highest) / len(highest)
    in_cnt = dict(collections.Counter(highest))
    full_cnt = dict(collections.Counter(nums))
    ways = num_combs(full_cnt[highest[-1]], in_cnt[highest[-1]])
    print(mean)
    print(ways)


def hml_between(n, a, b, nums, hml):
    print(float(nums[0])) 
    cnt = dict(collections.Counter(nums))[nums[0]]
    ways = 0
    for i in range(hml, a - 1, -1):
        ways += num_combs(cnt, i)
    print(ways)


def how_many_largest(lst):
    res = 1
    idx = 1
    while idx < len(lst) and lst[idx - 1] == lst[idx]:
        res += 1
        idx += 1
    return res


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


if __name__ == "__main__":
    main()