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

Solution (Python):

from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')


def A():
    a, b = LI()
    print((a+b)%24)
    return


def B():
    n, m = LI()
    ab = LIR(n)
    cd = LIR(m)
    for a, b in ab:
        ans = inf
        an = 0
        for num, cdi in enumerate(cd):
            c, d = cdi
            if ans > abs(a - c) + abs(b - d):
                ans = abs(a - c) + abs(b - d)
                an = num
        print(an+1) 
    return


def C():
    n = II()
    ans = inf
    for i in range(1, int(math.sqrt(n)) + 1):
        if not n % i:
            ans = min(ans, max(int(math.log(i, 10)), int(math.log(n // i, 10))))
    print(ans+1)
    return


def D():
    _, a, b = LI()
    v = LI()
    v.sort(reverse=True)
    d = defaultdict(int)
    ans = defaultdict(int)
    for vi in v:
        d[vi] += 1
    for i in range(a, b + 1):
        res = v[:i]
        r = res[-1]
        tmp = res.count(r)
        r = math.factorial(d[r]) / math.factorial(tmp) / math.factorial(d[r] - tmp)
        ans[sum(res) / i] += math.ceil(r-0.5)
    ans = list(ans.items())
    ans.sort(reverse=True, key = lambda x:x[0])
    print(ans[0][0])
    print(ans[0][1])
    return


if __name__ == '__main__':
    D()

Solution (Python):
from math import factorial as f
def cmb(n,r):
    if n<r:return 0
    else:return f(n)//f(r)//f(n-r)

n,a,b=map(int,input().split())
v=sorted(map(int,input().split()),reverse=True)
m=sum(v[:a])/a
print(m)
i=j=a-1
while 1:
    if i==0:break
    elif v[i-1]!=v[a-1]:break
    else:i-=1
while 1:
    if j==n-1:break
    elif v[j+1]!=v[a-1]:break
    else:j+=1
ans=0
if i==0:
    for r in range(a,b+1):ans+=cmb(j+1,r)
else:
    ans+=cmb(j-i+1,a-i)
print(ans)

Solution (Python):
import sys
import math
input = sys.stdin.readline


def comb(n):
    dp = [[0] * (n + 1) for i in range(n + 1)]
    for i in range(n + 1):
        dp[i][0] = 1
        dp[i][i] = 1
    for i in range(2, n + 1):
        for j in range(1, i):
            dp[i][j] = dp[i-1][j-1] + dp[i-1][j]
    return dp


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

v.sort(reverse=True)
comb_list = comb(n)

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

x, y = 0, 0
for i in range(n):
    if v[i] == v[a-1]:
        x += 1
        if i < a:
            y += 1

cnt = 0
if y == a:
    for i in range(a, b+1):
        cnt += comb_list[x][i]
else:
    cnt += comb_list[x][y]

print(ans)
print(cnt)

Solution (Python):
import collections
import functools
import sys


sys.setrecursionlimit(10 ** 9 + 7)

@functools.lru_cache(maxsize=None)
def c(x, y):
    if y == 0 or x == y:
        return 1
    else:
        return c(x - 1, y - 1) + c(x - 1, y)


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

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

counter = collections.Counter(v)
if v[0] == v[a - 1]:
    x = counter[v[0]]
    comb = sum(c(x, y) for y in range(a, min(x, b) + 1))
else:
    comb = 1
    for z, y in collections.Counter(v[:a]).items():
        x = counter[z]
        comb *= c(x, y)

print(avg)
print(comb)

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

items.sort(reverse=True)

maxAvg = sum(items[:A]) / A

print(maxAvg)

fact = [1 for _ in range(N + 10)]

for i in range(1, N + 10):
    fact[i] = (fact[i - 1] * i)

def comb(n, r):
    if 0 < r < n:
        return fact[n] // fact[r] // fact[n - r]
    if r == 0 or r == n:
        return 1
    return 0


if items[0] == items[A - 1]:
    right = A - 1
    while right < N and items[right] == items[0]:
        right += 1
    ans = 0
    for take in range(A, B + 1):
        ans += comb(right, take)
    print(ans)
else:
    left = A - 1
    while left >= 0 and items[left] == items[A - 1]:
        left -= 1
    right = A - 1
    while right < N and items[right] == items[A - 1]:
        right += 1
    ans = comb(right - left - 1, A - left - 1)
    print(ans)

Solution (Python):
from scipy.misc import comb 
from collections import defaultdict, deque, Counter
import sys

import heapq
import math

input = sys.stdin.readline

sys.setrecursionlimit(10000000)

MIN = -10 ** 9
MOD = 10 ** 9 + 7


def main():
    N, A, B = [int(a) for a in input().split()]
    V = sorted([int(a) for a in input().split()], reverse=True)

    s = sum(V[:A]) / A
    target = V[A - 1]
    if target == V[0]:
        co = V.count(target)
        t = sum(
            comb(co, c, exact=True)
            for c in range(A, min(B, co) + 1)
        )
        print(s)
        print(t)
        return

    c1 = V[:A].count(target)
    c2 = V.count(target)
    t = comb(c2, c1, exact=True)
    print(s)
    print(t)


if __name__ == '__main__':
    main()

Solution (Python):
import math

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



V.sort(reverse=True)

max_list = V[:A]
max_sum = sum(max_list)
print(max_sum / A)

replace = max_list[-1]

num_replace = V.count(replace)

if num_replace == 1:
    print(1)
    exit()

num_replace_in_list = max_list.count(replace)

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

if replace * A != max_sum:
    ans = combinations(num_replace, num_replace_in_list)
    print(ans)
    exit()


ans = 0
for i in range(A, B + 1):
    if i > num_replace:
        break
    ans += combinations(num_replace, i)

print(ans)

Solution (Python):
import math

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



V.sort(reverse=True)

max_list = V[:A]
max_sum = sum(max_list)
print(max_sum / A)

replace = max_list[-1]

num_replace = 0
for v in V:
    if v == replace:
        num_replace += 1

if num_replace == 1:
    print(1)
    exit()

num_replace_in_list = 0
for v in max_list:
    if v == replace:
        num_replace_in_list += 1

if replace * A != max_sum:
    ans = math.factorial(num_replace) // (math.factorial(num_replace - num_replace_in_list) * math.factorial(num_replace_in_list))
    print(ans)
    exit()


ans = 0
for i in range(A, B + 1):
    if i > num_replace:
        break
    ans += math.factorial(num_replace) // (math.factorial(num_replace - i) * math.factorial(i))

print(ans)

Solution (Python):
import math

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

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

tmp_count = 1 
tmp = v[0]
for i in range(1, A):
    if v[i] == tmp:
        tmp_count += 1
    else:
        tmp = v[i]
        tmp_count = 1

total_count = tmp_count 
for i in range(A, N):
    if tmp == v[i]:
        total_count += 1
    else:
        break

ans = 0
if ave == tmp: 
    
    
    for i in range(A, min(total_count + 1, B + 1)):
        ans += conbination(total_count, i)
else:
    ans += conbination(total_count, tmp_count)

print (ans)

Solution (Python):
from bisect import bisect_right

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

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

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

if v[A-1] != v[0] :
    ret = 0
    a = v.count(v[A-1])
    r = v[:A].count(v[A-1])
    print(comb(a, r))

else :
    a = v.count(v[A-1])
    ret = 0
    for i in range(A, min(B, a) + 1) :
        ret += comb(a, i)
    print(ret)

Solution (Python):



import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7

n,a,b = map(int,input().split())
v = list(map(int,input().split()))
v.sort(reverse = True)
fact = [1]
for i in range(1,n+1):
    fact.append(fact[i-1]*(i))
def comb(n,r):
    return fact[n]// fact[r] //fact[n-r]
ans = sum(v[:a])/a
print(ans)
M,m = max(v[:a]),min(v[:a])
if M != m:
    c1,c2 = v[:a].count(m),v.count(m)
    print(comb(c2,c1))
else:
    ans = 0
    c = v.count(m)
    for i in range(a,b+1):
        if c >= i:
            ans += comb(c,i)
    print(ans)

Solution (Python):



import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7

n,a,b = map(int,input().split())
v = list(map(int,input().split()))
v.sort(reverse = True)
fact = [1]
for i in range(1,n+1):
    fact.append(fact[i-1]*(i))
def comb(n,r):
    return fact[n]// fact[r] //fact[n-r]
ans = sum(v[:a])/a
print(ans)
M,m = max(v[:a]),min(v[:a])
if M != m:
    c1,c2 = v[:a].count(m),v.count(m)
    print(comb(c2,c1))
else:
    ans = 0
    c = v.count(m)
    for i in range(a,b+1):
        if c >= i:
            ans += comb(c,i)
    print(ans)

Solution (Python):



import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7

n,a,b = map(int,input().split())
v = list(map(int,input().split()))
v.sort(reverse = True)
fact = [1]
for i in range(1,n+1):
    fact.append(fact[i-1]*(i))
def comb(n,r):
    return fact[n]// fact[r] //fact[n-r]
ans = sum(v[:a])/a
print(ans)
M,m = max(v[:a]),min(v[:a])
if M != m:
    c1,c2 = v[:a].count(m),v.count(m)
    print(comb(c2,c1))
else:
    ans = 0
    c = v.count(m)
    l = min(b,c)
    for i in range(a,l+1):
        ans += comb(c,i)
    print(ans)

Solution (Python):
def comb(n,k): 
    ans = [[1]]
    tem = []
    for i in range(1,n+1):
        tem = []
        for j in range(i+1):
            if(j==0 or j==i):
                tem.append(1)
            else:
                tem.append(ans[i-1][j-1]+ans[i-1][j])
        ans.append(tem)
    return ans[n][k] 

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

Solution (Python):
def f(N):
    C = [[0] * 51 for _ in range(51)]
    for i in range(N + 1):
        for j in range(i + 1):
            if j == 0 or i == j:
                C[i][j] = 1
            else:
                C[i][j] = C[i - 1][j - 1] + C[i - 1][j]
    return C


def main():
    N, A, B = map(int, input().split())
    V = sorted(list(map(int, input().split())), reverse=True)
    avg = sum(V[:A]) / A
    n = V.count(V[A - 1])
    p = V[:A].count(V[A - 1])
    C = f(N)
    ans = 0
    if p == A:
        for i in range(A, B + 1):
            ans += C[n][i]
    else:
        ans += C[n][p]
    print(avg)
    print(ans)


main()

Solution (Python):

def comb(a, b):
    if b > a - b:
        return comb(a, a-b)
    ansMul = 1
    ansDiv = 1
    for i in range(b):
        ansMul *= a - i
        ansDiv *= i + 1

    ans = ansMul // ansDiv
    return ans

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

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

for i in range(N):
    for j in range(N):
        if j > i:
            continue
        dp[i+1][j+1] = max(dp[i+1][j+1], (dp[i][j] * j + v[i]) / (j + 1))
        dp[i+1][j] = max(dp[i+1][j], dp[i][j])

ans = 0
for i in range(A, B+1):
    ans = max(ans, dp[N][i])

v.sort()
v.reverse()

c = v.count(v[0])
cnt = 0
if v[0] == v[A-1]:
    for i in range(A, B+1):
        if c < i:
            break
        cnt += comb(c, i)
else:
    a = v[:A].count(v[A-1])
    all_a = v.count(v[A-1])
    cnt = comb(all_a, a)

print(ans)
print(cnt)

Solution (Python):
import math

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

v.sort()
max_avg = sum(v[-A:]) / A

min_selected = v[- A]
selected = 0
for i in range(len(v) - A, len(v)):
    if v[i] == min_selected:
        selected += 1
    else:
        break
        
not_selected = 0
for i in range(0, len(v) - A):
    if v[i] == min_selected:
        not_selected +=  1
        
case_num = 0
if selected != A:        
    case_num = math.factorial(selected + not_selected) // (math.factorial(selected) * math.factorial(not_selected))
else:
    for i in range(A, min(B, selected + not_selected) + 1):
        case_num += math.factorial(selected + not_selected) // (math.factorial(i) * math.factorial(selected + not_selected - i))
print(max_avg)
print(case_num)

Solution (Python):
conb_list = [ [ 1 for i in range(51) ] for j in range(51) ]
for i in range(1,51):
    for j in range(1,51):
        conb_list[i][j] = conb_list[i-1][j] + conb_list[i][j-1]


n, a, b = [ int(v) for v in input().split() ]
num_list = sorted([ int(v) for v in input().split() ], reverse = True)

def mean(inlist):
    return sum(inlist) / len(inlist)

ans = 0
for i in range(a,b+1):
    if i == a:
        min_element = num_list[i-1]
        min_element_count = num_list.count(min_element)
        min_element_index = num_list.index(min_element)
        max_mean = mean(num_list[:i])

        ans += (conb_list[min_element_count - i + min_element_index][i - min_element_index])
    else:
        if max_mean > mean(num_list[:i]):
            break
        else:
            ans += (conb_list[min_element_count - i + min_element_index][i - min_element_index])

print(max_mean)    
print(ans)

Solution (Python):
from statistics import mean
from collections import Counter
n,a,b=map(int,input().split())
v=sorted(list(map(int,input().split())),reverse=True)
avg=mean(v[:a])
print(avg)

p=Counter(v[:a])[v[a-1]]
q=Counter(v)[v[a-1]]

def n_func(n):
    ans=1
    for i in range(1,n+1):ans=(ans*i)
    return ans

def nCr(n,r):
    return (n_func(n)//n_func(r))//n_func(n-r)

if v[0]==v[a-1]:
    print(sum([nCr(q,a+i) for i in range(0,min(b,q)-a+1)]))
else:
    print(nCr(q,p))

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

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

v.sort(reverse = True)
average = sum(v[:a]) / a
print(average)
amount = [a]
for i in range(a + 1, b + 1):
    average2 = sum(v[:i]) / i
    if average == average2:
        amount.append(i)
    else:
        break
com = 0
for i in amount:
    v1 = v[:i]
    v2 = v[i:]
    min_v = min(v1)
    m1 = v1.count(min_v)
    m2 = v2.count(min_v)
    com += combination(m1 + m2, min(m1, m2))
print(com)

Solution (Python):

from math import factorial

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


def main():
    num, min_num, max_num = map(int, input().split())
    data = list(map(int, input().split()))
    data.sort(reverse=True)

    last_ind = 0
    for i in range(num):
        if data[0] == data[i]:
            last_ind = i
        else:
            break

    sum_now = sum(data[:min_num])
    avg = sum_now / min_num
    now_ind = min_num
    ans_count = 0

    while 1:
        if now_ind >= num:
            break
        if data[now_ind] < avg:
            break
        sum_now += data[now_ind]
        now_ind += 1
        avg = sum_now / now_ind

    in_count = 0
    for i in range(now_ind):
        if data[now_ind - 1] == data[i]:
            in_count += 1

    out_count = 0
    for i in range(now_ind, num):
        if data[now_ind - 1] == data[i]:
            out_count += 1

    

    if now_ind - 1 <= last_ind:
        toori = 0
        for i in range(min_num, min(now_ind + 1, max_num + 1)):
            toori += combinations_count(last_ind + 1, i)
    else:
        toori = combinations_count(in_count + out_count, in_count)

    

    print(avg)
    print(toori)





if __name__ == '__main__':
    main()

Solution (Python):
from math import factorial

def combinations_count(n, r):
    ''' 組み合わせ '''
    return factorial(n) // (factorial(n - r) * factorial(r))

def max_ave():
    N, A, B = map(int, input().split())
    v = list(map(int, input().split()))
    sort_v = sorted(v, reverse=True)

    
    sum_A = 0
    for i in range(A):
        sum_A += sort_v[i]
    max_ave_v = sum_A / A

    print(max_ave_v)

    
    V = sort_v[:A]
    num = v.count(min(V))
    a = V.count(min(V))
    cnt = 0
    if max(V) == min(V):
        for i in range(A,B+1):
            if num < i:
                continue
            cnt += combinations_count(num,i)
    else:
        cnt = combinations_count(num,a)
    
    print(cnt)

max_ave()

Solution (Python):

INF=1e10

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

from collections import defaultdict
N,A,B=map(int, input().split())
V=list(map(int, input().split()))
V=sorted(V, reverse=True)
cnts = defaultdict(lambda: 0)
for v in V:
    cnts[v]+=1

ans, cnt = -INF, 0
for n in range(A, B+1):
    tmp = sum(V[:n])/n
    if tmp < ans:
        continue
    if tmp > ans:
        ans=tmp
        cnt=0
    nb = 0
    for i in range(n):
        if V[i]==V[n-1]:
            nb+=1
    cnt += comb(cnts[V[n-1]], nb)
print(ans)
print(cnt)

Solution (Python):
def com(n, k):
  P = [1]
  for i in range(1, n + 1):
    P.append(P[i - 1] * i)
  return P[n] / P[n - k] / P[k]


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

v.sort(reverse = True)
su = 0
for i in range(A):
  su += v[i]

ac = 0
t = v[A - 1]
k = 100
for i in range(N):
  if v[i] == t:
    ac += 1
    k = min(k, i)

print(su / A)
if k == 0:
  ans = 0
  for i in range(A, min(B, ac) + 1):
    ans += com(ac, i)
  print(int(ans))
else:
  print(int(com(ac, A - k)))

Solution (Python):
import numpy as np
import copy
from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0 or r == n: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under



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

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

    v = np.sort(v)[::-1]
    ave_max = np.mean(v[:A])

    print(ave_max)


    m = np.sum(v > v[A-1])
    n = np.sum(v == v[A-1])

    if m > 0:
        print(cmb(n, A-m))
    else:
        ans = 0
        for k in range(A, min(B, n)+1):
            ans += cmb(n, k)
        print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
from collections import defaultdict
def input_as_int():
    return list(map(int,input().split()))

def get_comb(n):  

    fac = get_fact(n)
    com  = [["error" for _ in range(n+1)] for _ in range (n + 1)]
    for i in range(n + 1):
        for j in range(i + 1):
            if  i >= j:
                com[i][j] = fac[i] // (fac[i-j] * fac[j])
    return com

def get_fact(n):
    temp = 1
    fac = [1]
    for i in range(1, n + 1):
        temp *= i
        fac.append(temp)
    return fac

N,A,B = input_as_int()
Vs = input_as_int()
Vs.sort(reverse= True)
nums = defaultdict(lambda :0)
kose = defaultdict(lambda :0)
com = get_comb(N)
for v in Vs:
    nums[v] += 1
total = 0
for i in range(A):
    total += Vs[i]
    kose[Vs[i]] += 1
av = total / A
i = A
ans = 0
while True:
    temp = 1
    for k,v in kose.items():
        n = nums[k]
        temp *= com[n][v]

    ans += temp
    if i ==B or Vs[i] != Vs[0] :
        break
    else:
        kose[Vs[i]] +=1
        i += 1
print(av)
print(ans)

Solution (Python):
from functools import reduce

def binom(n, r):
    if n < r or n < 0 or r < 0: return 0
    
    if n - r < r: r = n - r
    if r == 0: return 1
    elif r == 1: return n

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

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


N, A, B = map(int, input().split())
*V, = map(int, input().split())
V = sorted(V, reverse=True)
ans = 0
ways = 0
if len(set(V[:A])) == 1:
    ans = V[0]
    n = V.count(ans)
    for i in range(A, min(B, n)+1): ways += binom(n, i)
else:
    ans = sum(V[:A]) / A
    min_num = min(V[:A])
    n_min = V.count(min_num)
    n_min_lst = V[:A].count(min_num)
    ways = binom(n_min, n_min_lst)
print(ans)
print(ways)

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

C = [[1 for k in range(n + 1)] for n in range(N + 1)]
for n in range(2, N + 1):
    for k in range(1, n):
        C[n][k] = C[n - 1][k] + C[n - 1][k - 1]

x = v[A - 1]
l = 0
while v[l] != x:
    l += 1
r = l + 1
while r < N and v[r] == x:
    r += 1


count = 0
for i in range(A, min(B, r) + 1):
    if sum(v[:A]) * i == sum(v[:i]) * A:
        count += C[r - l][i - l]
print(sum(v[:A]) / A)
print(count)

Solution (Python):

import sys
sys.setrecursionlimit(300000)


def solve(N: int, A: int, B: int, v: "List[int]"):
    def choose(n, k):
        ret = 1
        k = min(k, n - k)
        for i in range(1, k + 1):
            ret *= (n - i + 1)
            ret //= i
        return ret

    count = {}
    v.sort(reverse=True)
    ave = [0] * N
    for val in v:
        if val in count:
            count[val] += 1
        else:
            count[val]  = 1
    for i in range(A - 1, B):
        ave[i] = sum(v[:i + 1]) / (i + 1)
    mx = max(ave)

    ret = 0
    for i in range(A - 1, B):
        if ave[i] == mx:
            c = 0
            for j in range(i + 1, N):
                if v[j] == v[i]:
                    c += 1
            ret += choose(count[v[i]], c)
    print(mx)
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    A = int(next(tokens))  
    B = int(next(tokens))  
    v = [ int(next(tokens)) for _ in range(N) ]  
    solve(N, A, B, v)

if __name__ == '__main__':
    main()

Solution (Python):
def main():
	N, A, B = map(int, input().split())
	v = list(map(int, input().split()))
	v.sort(reverse=True)
	ave_ans = sum(v[:A])/A
	cmp_v = v[A-1]
	cmp_v_in = 0
	cmp_v_out = 0
	def get_total(values):
		ans = 0
		for v in values:
			if v == cmp_v:
				ans += 1
		return ans
	cmp_v_in = get_total(v[:A])
	cmp_v_out = get_total(v[A:])
	fact = [0]*51
	fact[0] = 1
	fact[1] = 1
	for i in range(2, 51):
		fact[i] = fact[i-1]*i

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

	print(ave_ans)

	choose_ans = C(cmp_v_in+cmp_v_out, cmp_v_in)
	if cmp_v_in == A:
		for i in range(1, min(B-A+1, cmp_v_out+1)):
			choose_ans += C(cmp_v_in+cmp_v_out, cmp_v_in+i)
	print(choose_ans)

if __name__ == '__main__':
    main()

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

def Combination(n, k):
    return fact[n] // fact[k] // fact[n-k]

N, A, B = map(int, input().split())
v = sorted(list(map(int, input().split())))[::-1]
MAX = sum(v[:A])
print(MAX/A)
M = max(v[:A])
m = min(v[:A])
if M != m:
    c1, c2 = v[:A].count(m), v.count(m)
    print(Combination(c2, c1))
else:
    c = v.count(m)
    L = min(B, c)
    ans = 0
    for i in range(A, L+1):
        ans += Combination(c, i)
    print(ans)

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

n,a,b = map(int,input().split())
l = sorted(list(map(int,input().split())),reverse = True)
n_max = l.count(max(l))
ans=0
if n_max>a:
    for i in range(a,min(b+1,n_max+1)):
        ans+=combi(n_max,i)
    print(max(l))
    print(ans)
    exit()
n_min = l.count(l[a-1])
i_min = l.index(l[a-1])
k = a-i_min
ans+=combi(n_min,k)
print(sum(l[:a])/a)
print(ans)

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

ans = 0
if v[A-1] == v[0]:
    mean = v[0]
    count = 0
    for i in range(N):
        if v[i] == v[0]:
            count += 1
    for i in range(A,min(B,count)+1):
        ans += comb(count,i,exact=True)
else:
    mean = sum(v[:A])/A
    count = 0
    j = N
    for i in range(N):
        if v[i] == v[A-1]:
            j = min(i,j)
            count += 1
    ans = comb(count,A-j,exact=True)
print(mean)
print(ans)

Solution (Python):
from collections import Counter
from math import factorial
N, A, B = map(int, input().split())
V = sorted(list(map(int, input().split())), reverse=True)

MAX_AVE = sum(V[:A]) / A
C = Counter(V)


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


Ath_V = V[A - 1]
if Ath_V == max(V):
    ans = 0
    for r in range(A, min(B + 1, C[Ath_V] + 1)):
        ans += nCr(C[Ath_V], r)
    print(MAX_AVE)
    print(ans)

else:
    print(MAX_AVE)
    for i, v in enumerate(V):
        if v == Ath_V:
            used = i
            break
    print(nCr(C[Ath_V], A - used))

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

n,a,b=map(int,input().split())
arr=list(map(int,input().split()))
arr=sorted(arr,reverse=True)
cnt=[0]*50
num=[arr[0]]
tmp=arr[0]
pos=0
for i in arr:
  if i==tmp:
    cnt[pos]+=1
  else:
    pos+=1
    cnt[pos]+=1
    tmp=i
    num.append(i)
ave=0
ans=0
if cnt[0]>=a:
  ave=num[0]
  for i in range(a,min(b,cnt[0])+1):
    ans+=comb(cnt[0],i)
else:
  t=0
  pos=0
  for i in range(n):
    t+=cnt[i]
    ave+=num[i]*cnt[i]
    if t>=a:
      ave-=num[i]*(t-a)
      ans=comb(cnt[i],a-(t-cnt[i]))
      break
  ave=ave/a
print(ave)
print(ans)

Solution (Python):
import os
import sys

import numpy as np
from scipy.misc import comb

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")

N, A, B = list(map(int, sys.stdin.readline().split()))
V = list(map(int, sys.stdin.readline().split()))

V.sort(reverse=True)
V = np.array(V)
cs = V.cumsum()
averages = cs / (np.arange(N) + 1)


max_average = averages[A - 1:B].max()

count = averages[A - 1:B].argmax() + A


threshold = V[count - 1]
threshold_cnt = (V == threshold).sum()

print(float(max_average))
if np.all(V[:count] == V[0]):
    
    ans = 0
    for r in range(A, B + 1):
        ans += comb(threshold_cnt, r, exact=True)
    print(ans)
else:
    gt_cnt = (V > threshold).sum()
    print(comb(threshold_cnt, count - gt_cnt, exact=True))

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()


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








def main():
  n,a,b=LI()
  l=LI()

  l=sorted(l,key=lambda x:x,reverse=True)

  l2=l[:a]
  print(sum(l2)/len(l2))
  
  if l2[0]!=l2[-1]:
    c=l.count(l2[-1])
    c2=l2.count(l2[-1])
    print(nCr(c,c2))

  else:
    c=l.count(l2[-1])
    sm=0
    for i in range(a,min(b+1,c+1)):
      sm+=nCr(c,i)

    print(sm)

main()

Solution (Python):
from sys import stdin

def combination_table(N):
	C = []
	for i in range(N+1):
		C.append([0] * (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]
	return C

if __name__ == "__main__":
	N, A, B = stdin.readline().split(" ")
	N = int(N)
	A = int(A)
	B = int(B)
	V = []
	line = stdin.readline().split(" ")
	unique_elements = dict()
	for e in line:
		V.append(int(e)) 
		if not int(e) in unique_elements:
			unique_elements[int(e)] = 1
		else:
			unique_elements[int(e)] += 1
	V.sort(reverse=True)

	C = combination_table(N)

	
	a_th_val_pos = 0
	a_th_val_num = 0
	highest_avg = float(sum(V[:A])) / float(A)
	for i in range(N):
		if V[i] == V[A-1]:
			a_th_val_num += 1
			if i < A:
				a_th_val_pos += 1


	cnt = 0
	if a_th_val_pos == A:
		for i in range(A, B+1):
			cnt += C[a_th_val_num][i]
	else:
		cnt += C[a_th_val_num][a_th_val_pos]

	print ("{:6f}".format(highest_avg))
	print (cnt)