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
n,a,b=map(int,input().split())
v=list(map(int,input().split()))




v.sort(reverse=True)
am=0
for i in v[:a]:
    am+=i
maxv=am/a
B=v[a-1]
count=0
k=0
if v[0]==B:
    flag=0
else:
    flag=1

if flag==0:
    for i in range(n):
        if v[i]==B:
            k=i+1
            break
    k1=k
    while  k1<n+1 and v[k1-1]==B:
        count+=1
        k1+=1

    def combinations_count(n, r):
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
    i=a-k+1 
    ans=0
    while i<b-k+2 and i<count+1:
        ans+=combinations_count(count,i)
        i+=1


    print(maxv)
    print(ans)

else:
    for i in range(n):
        if v[i]==B:
            k=i+1
            break
    k1=k
    while  k1<n+1 and v[k1-1]==B:
        count+=1
        k1+=1

    def combinations_count(n, r):
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
    i=a-k+1 
    ans=combinations_count(count,i)
    print(maxv)
    print(ans)

Solution (Python):
import math
import copy
from operator import mul
from functools import reduce
from collections import defaultdict
from collections import Counter
from collections import deque

from itertools import product

from itertools import permutations

from itertools import combinations
from bisect import bisect_left, bisect_right





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

dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
 
def i_inpl(): return int(input())
def l_inpl(): return list(map(int, input().split()))
INF = float("inf")



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

N, A, B = l_inpl()
v = l_inpl()

sort_v = sorted(v, reverse=True)
ans_1 = sum(sort_v[:A])/A
print(ans_1)

max_v = sort_v[A-1]
max_v_count = sort_v.count(max_v)
max_v_count_in_ans = sort_v[:A].count(max_v)

if max_v != sort_v[0]: 
    ans = C(max_v_count, max_v_count_in_ans)
else:
    ans = 0
    for i in range(A, min(B, max_v_count) + 1):
        ans += C(max_v_count, i)

print(int(ans))

Solution (Python):











import sys
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial
from heapq import heappop, heappush, heappushpop
from collections import Counter, defaultdict
from operator import itemgetter, attrgetter
inf=float('inf')
mod = 10 ** 9 + 7
def combination(n, r):  
    if n < r:
        return 0
    else:
        return factorial(n)//(factorial(r) * factorial(n-r))


def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N, A, B = MI()
    V = LI()
    v_dict = defaultdict(int)
    for v in V:
        v_dict[v] += 1
    VN = [(v, num) for v, num in v_dict.items()]
    VN.sort(reverse=True)
    A_copy = A
    ans_1 = 0
    for (v, n) in VN:
        if A_copy > n:
            A_copy -= n
            ans_1 += v*n
        else:
            ans_1 += A_copy * v
            break
    print(ans_1/A)
            
    if VN[0][1] > A:
        ans_2 = 0
        for choose_num in range(A, min(B, VN[0][1]) + 1):
            ans_2 += combination(n, choose_num)
        print(ans_2)
    else:
        for (v, n) in VN:
            if A > n:
                A -= n
            else:
                ans_2 = combination(n, A)
                break
        print(ans_2)

if __name__ == '__main__':
    main()

Solution (Python):





from collections import* 
from fractions import gcd
from functools import* 
from itertools import* 
from operator import mul,itemgetter
from bisect import* 
from heapq import* 
from math import factorial,pi
from copy import deepcopy
import sys
sys.setrecursionlimit(10**8)

def cmb(n, r):
    if n-r<0:
        return 0
    return factorial(n) // factorial(r) // factorial(n - r)

def main():
    n,a,b,*v=map(int,open(0).read().split())
    v.sort(reverse=1)
    m=sum(v[:a])/a
    print(m)
    n=v[a-1]
    x,y=v[:a].count(n),v.count(n)

    ans=0
    if m==n and y-x>0:
        for i in range(x,x+b-a+1):
            ans+=cmb(y,i)
        print(ans)
    else:
        print(cmb(y,x))

if __name__ == '__main__':
    main()

Solution (Python):





from collections import* 
from fractions import gcd
from functools import* 
from itertools import* 
from operator import mul,itemgetter
from bisect import* 
from heapq import* 
from math import factorial,pi
from copy import deepcopy
import sys
sys.setrecursionlimit(10**8)

def cmb(n, r):
    if n-r<0:
        return 0
    return factorial(n) // factorial(r) // factorial(n - r)

def main():
    n,a,b,*v=map(int,open(0).read().split())
    v.sort(reverse=1)
    m=sum(v[:a])/a
    print(m)
    n=v[a-1]
    x,y=v[:a].count(n),v.count(n)

    ans=0
    if m==n and y-x>0:
        for i in range(x,x+b-a+1):
            ans+=cmb(y,i)
        print(ans)
    else:
        print(cmb(y,x))

if __name__ == '__main__':
    main()

Solution (Python):
N,A,B=map(int, input().split())
V=list(map(int, input().split()))
d={}
for v in V:
    if v in d:
        d[v]+=1
    else:
        d[v]=1
k=sorted(d.keys(),reverse=True)
def comb1(n,k):
    if n<k:
        return 0
    if n<0 or k<0:
        return 0
    k=min(n-k,k)
    a=b=1
    for i in range(1,k+1):
        a=a*(n-k+i)
        b=b*i
    return a//b
ans=0
if d[k[0]]>=A:
    for x in range(A,min(B,d[k[0]])+1):
        ans+=comb1(d[k[0]],x)
    ave=k[0]
else:
    n=d[k[0]]
    a=[k[0]]*d[k[0]]
    for i in range(1,len(k)):
        if n+d[k[i]]>=A:
            break
        else:
            n+=d[k[i]]
            a+=[k[i]]*d[k[i]]
    ans=comb1(d[k[i]],A-n)
    a+=[k[i]]*(A-n)
    from statistics import mean
    ave=mean(a)
print(ave)
print(ans)

Solution (Python):
N,A,B = list(map(int,input().split()))
 
v = list(map(int,input().split()))
 
v.sort()
v=v[::-1]
 
a=v[A-1]
is_first = True
end=-1
for i in range(N):
    if v[i]==a:
        if is_first:
            first=i
            is_first=False
    else:
        if not is_first:
            end=i
            break
 
def comb(n,k):
    a = 1
    b = 1
    for i in range(min(n-k,k)):
        a*=n-i
        b*=i+1
    return a//b

if end==-1:
    end=N
if first==0:
    print(a)
    print(sum([comb(end,i) for i in range(A,min(B,end)+1)]))
else:
    print(sum(v[:A])/A)
    print(comb(end-first,A-first))

Solution (Python):
from math import factorial
from collections import defaultdict
def nCr(n,r):
    return int(factorial(n)/(factorial(n-r)*factorial(r)))
N,A,B=map(int,input().split())
V=list(map(int,input().split()))
dict=defaultdict(int)
for i in V:
    dict[i]+=1
V.sort(reverse=True)
v=[]
value=0
tmp=0
for i in range(N):
    if value!=V[i]:
        tmp=1
        value=V[i]
    else:
        tmp+=1
    v.append([V[i],tmp])
ans=0
print(sum(V[:A])/A)
if V[0]==V[A-1]:
    for i in range(A,B+1):
        if V[0]==V[i-1]:
            ans+=nCr(dict[V[0]],i)
    print(ans)

else:
    print(nCr(dict[V[A-1]],v[A-1][1]))

Solution (Python):
from collections import Counter

def comb(x,y):
    c=1
    for i in range(y):
        c*=(x-i)
        c//=(i+1)
    return c

n,a,b=map(int,input().split())
V=list(map(int,input().split()))
V.sort(reverse=True)
print(sum(V[:a])/a)
c=Counter(V)
cnt=0
for v in V:
    i=c[v]
    cnt+=i
    if cnt>=a:
        break
if V[0]==V[a-1]:
    ans=0
    for j in range(a,min(cnt,b)+1):
        ans+=comb(i,j)
    print(ans)
else:
    print(comb(i,a+i-cnt))

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_value = sum(v[:a])/a
cnt1 = Counter(v)[v[a-1]]
cnt2 = Counter(v[:a])[v[a-1]]
comb = factorial(cnt1)//factorial(cnt2)//factorial(cnt1-cnt2)
if v[a-1]==v[0]:
    comb=0
    for i in range(a, min(cnt1, b)+1):
        comb += factorial(cnt1)//factorial(i)//factorial(cnt1-i)
print(max_value)
print(comb)

Solution (Python):
from functools import reduce
from operator import mul

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

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

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

V.sort(reverse = True) 

x = V[A-1]
large = V.index(x) 
cnt = V.count(x)

import numpy as np
comb = np.zeros((N+1,N+1),dtype=np.int64)
comb[:,0] = 1
for n in range(1,N+1):
  comb[n,1:] = comb[n-1,1:] + comb[n-1,:-1]

max_avg = sum(V[:A]) / A
pattern = 0
if V[0] == V[A-1]:
  for choose in range(A-large, B-large+1):
    pattern += comb[cnt,choose]
else:
  pattern = comb[cnt,A-large]
  
print(max_avg)
print(pattern)

Solution (Python):
from itertools import*
from math import*
from collections import*
from heapq import*
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf = 10**18
mod = 10**9+7
from functools import reduce
import sys
sys.setrecursionlimit(10**7)
def comb(n,r):
    if r > n:
        return 0
    else:
        return factorial(n)//(factorial(n-r)*factorial(r))
n,a,b = map(int,input().split())
v = list(map(int,input().split()))
v.sort(reverse=True)
max_mean = sum(v[0:a])/a
print(max_mean)

c = Counter(v)
i = 0
num = 0
ans = 0
while num<a:
    if num+c[v[i]]>=a:
        num += c[v[i]]
    else:
        num += c[v[i]]
        i += 1
num -= c[v[i]]

if i > 0:
        ans += comb(c[v[i]],a-num)
        print(ans)
else:
    for j in range(a,b+1):
        if c[v[0]] >=j:
            ans += comb(c[v[0]],j)
    print(ans)

Solution (Python):
def comb(x,y):
  s = 1
  for i in range(y):
    s = s*(x-i)//(i+1)
  return s

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

m = v[a-1]
l = -1
while v[l+1] > m:
  l += 1
r = a-1
while r+1 <= n-1 and v[r+1] == m:
  r += 1

print(sum(v[:a])/a)
ans = 0
if l == -1:
  for k in range(a,b+1):
    ans += comb(r-l,(k-1-l))
else:
  ans += comb(r-l,(a-1-l))
print(ans)

Solution (Python):

import copy
import random
import bisect 
import fractions 
import math

mod = 10**9+7

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


dp = [[0 for j in range(B+1)] for i in range(N)]
for i in range(N):
    dp[i][0] = max(v[:i+1])

for i in range(N-1):
    for j in range(min(B,i+1)):
        dp[i+1][j+1] = max(dp[i][j+1],(dp[i][j]*(j+1)+v[i+1])/(j+2))

ans = max(dp[-1][A-1:B+1])






print(ans)

v.sort()
v.reverse()

cnt = 0
if v[0] != v[A-1]:
    m = v.count(v[A-1])
    n = v[:A].count(v[A-1])
    cnt = math.factorial(m)//(math.factorial(n)*math.factorial(m-n))
else:
    m = v.count(v[0])
    n = A
    for i in range(n,B+1):
        if m-i < 0:
            pass
        else:
            cnt += math.factorial(m)//(math.factorial(i)*math.factorial(m-i))

print(cnt)

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

items = V[:]

items = sorted(items, reverse=True)
sub_items = items[:A]
ave = sum(sub_items)/len(sub_items)
rest_items = items[A:]

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

if ave != sub_items[0]:
    
    r = sub_items.count(sub_items[-1])
    n = rest_items.count(sub_items[-1]) + r
    pattern = combinations_count(n, r)
else:
    n = items.count(ave)
    pattern = 0
    for r in range(A, min(n+1, B+1)):
        pattern += combinations_count(n, r)


print(ave)
print(pattern)

Solution (Python):
import math
def f(n):
    return math.factorial(n)
n,a,b=map(int,input().split())
V=[int(i) for i in input().split()]
V.sort()
if n==a:
  print(sum(V)/a)
  print(1)
else:
  ans=sum(V[n-a:])/a
  count1=V[n-a:].count(V[n-a])
  count2=V[:n-a].count(V[n-a])
  print(ans)
  if count1==a:
    ans2=0
    for i in range(min(count2+1,b-a+1)):
      ans2+=f(count1+count2)/f(count1+i)/f(count2-i)
    print(round(ans2))
  else:
    print(round(f(count1+count2)/f(count1)/f(count2)))

Solution (Python):
from math import factorial


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

u = sorted(v, reverse=True)
m = sum(x == u[A - 1] for x in v)



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




ans = '{}\n{}'.format(
    sum(u[:A]) / A,
    (
        c(
            m,
            A - sum(x > u[A - 1] for x in v)
        ) if u[A - 1] < u[0] else
        sum(
            c(m, k)
            for k in range(A, min(m + 1, B + 1))
        )
    )
)


print(ans)

Solution (Python):
N,A,B = map(int,input().split())
*v, = sorted(map(int,input().split()))[::-1]
f = [1]*51
for i in range(1,51):
    f[i] = f[i-1]*i
def comb(n,r):
    return f[n]//f[r]//f[n-r]
print(sum(v[:A])/A)
a = v[:A].count(v[A-1])
b = v[A:].count(v[A-1])+a
ans = comb(b,a)
if a == A:
    for k in range(A+1,B+1):
        ans += comb(b,k)
print(ans)

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

v.sort(reverse=1)

V = v[A-1]
print(sum(v[:A]) / A)

before = 0
after = 0
all = False
for i in range(A):
    if v[i] == V:
        if i == 0:
            all = True
        before = A - i
        break
for i in range(A, N):
    if v[i] == V:
        after += 1
    else:
        break

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

if all:
    ans = 0
    for i in range(before, min(B+1, before+after+1)):
        ans += C(before+after, i)
    print(ans)
else:
    print(C(before+after, before))

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

ma = sum(V[:A]) / A
num = 0

MOD = 10 ** 9 + 7
M = 60
fact = [0] * M
fact[0] = 1
for i in range(1, M):
    fact[i] = fact[i - 1] * i


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


num = 0
pos = 0
for i in range(N):
    if V[i] == V[A - 1]:
        num += 1
        if i < A:
            pos += 1
ans = 0
if pos == A:
    for i in range(A, B + 1):
        ans += comb(num, i)
else:
    ans += comb(num, pos)


print(ma)
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)
print(sum(V[:A]) / A)


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

Solution (Python):
import math


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


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

v.sort()
v.reverse()

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

c = v.count(v[a-1])
d = v[:a].count(v[a-1])

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

Solution (Python):
from collections import*
from itertools import*
from bisect import*
from operator import mul
from functools import reduce
 
def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under
 
n,a,b,*v=map(int,open(0).read().split())
v=sorted(Counter(v).items(),reverse=1,key=lambda x:x[0])
vindex=[0]+list(accumulate(V for K,V in v))+[float("inf")]

lower=vindex[bisect_left(vindex,a)-1]
upper=vindex[bisect_left(vindex,a)]
count=0
ans=0
 
if a<=vindex[1]:
    ans=0
    for i in range(a,min(b,vindex[1])+1):
        ans+=cmb(vindex[1],i)
    print(float(v[0][0]))
    print(ans)
 
else:
    for s,t in v:
        count+=t
        if count>lower:
            ans+=s*(a-lower)
            break
        else:
            ans+=s*t
    print(ans/a)
    print(cmb(upper-lower,a-lower))

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

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

v.sort(reverse=True)
d = dict()
for c in v:
    if d.__contains__(c):
        d[c]+=1
    else:
        d[c]=1

def C(x,y):
    if y>x:
        return 0
    if y>x//2:
        y = x-y
    res = 1
    for i in range(x,x-y,-1):
        res *= i
    for i in range(1,y+1):
        res //= i
    return res
m_sum = 0
m_cnt = 1
for i in range(a,b+1):
    if sum(v[:i])*m_cnt > i*m_sum:
        m_sum = sum(v[:i])
        m_cnt = i
m_idx = []
for i in range(a,b+1):
    if sum(v[:i])*m_cnt == i*m_sum:
        m_idx.append(i)
print("%0.6f"%(m_sum/m_cnt))

res_cnt = 0
for idx in m_idx:
    cnt_in = 0
    for i in range(idx-1,-1,-1):
        if v[i]==v[idx-1]:
            cnt_in+=1
        else:
            break
    res_cnt += C(d[v[idx-1]],cnt_in)
print(res_cnt)

Solution (Python):
def value_and_count(x):
    d = {}
    for xi in x:
        if xi in d.keys():
            d[xi] += 1
        else:
            d[xi] = 1
    return d

def comb(n, k):
    k = min(n - k, k)
    denominator = 1 
    numerator = 1 
    for i in range(k):
        denominator *= i + 1
        numerator *= n - i
    return numerator // denominator

n, a, b = map(int, input().split())
v = list(map(int, input().split()))
d_v = value_and_count(v)
v.sort(reverse=True)
sum_v = sum(v[:a])
mean_v = sum_v / a
print(mean_v)

ans = 0
d_vk = None
for k in range(a, b + 1):
    vk = v[:k]
    sum_vk = sum(vk)
    if sum_vk / k < mean_v:
        break

    if d_vk is None:
        d_vk = value_and_count(vk)
    else:
        d_vk[vk[-1]] += 1

    ans_k = 1
    for vi, ci in d_vk.items():
        ans_k *= comb(d_v[vi], ci)
    ans += ans_k

print(ans)

Solution (Python):

import sys


def combination(n, k):
    if n - k < k:
        return combination(n, n-k)
    
    if k == 0:
        return 1
    
    return combination(n-1, k-1) * n // k


def solve(N: int, A: int, B: int, v: "List[int]"):
    v.sort(reverse=True)
    d = dict()
    for value in v:
        if value not in d:
            d[value] = 1
        else:
            d[value] += 1
    
    average = sum(v[:A]) / A
    print(average)

    count = d[v[A-1]]
    fixed = v.index(v[A-1])
    
    if fixed > 0:
        print(combination(count, A - fixed))
        return

    if B - fixed < count:
        k2 = B - fixed
    else:
        k2 = count
    
    k1 = A - fixed

    ret = 0
    for k in range(k1, k2+1):
        ret += combination(count, k)
    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):
n,a,b=map(int,input().split())
v=[int(i) for i in input().split()]
v.sort(reverse=True)
m=v[a-1]
mm=v.count(m)
cnt=0
for i in range(n):
    if v[i]>m:
        cnt+=1
    else:
        break

def fact(n):
    if n==0 or n==-1:
        return 1
    return fact(n-1)*n
def comb(n,k):
    return fact(n)//fact(n-k)//fact(k)

    
ans=0

for i in range(min(mm+cnt-a,b-a+cnt)+1):
    ans+=comb(mm,a-cnt+i)
    
if m!=v[0]:
    ans=comb(mm,a-cnt)
print(sum(v[0:a])/a)
print(ans)

Solution (Python):
n, a, b = map(int,input().split())
v = sorted(list(map(int,input().split())),reverse = True)
set_v = set()
cnt_v = []
for i in v:
    if i not in set_v:
        set_v.add(i)
        cnt_v.append(i)

from collections import Counter
from operator import itemgetter
import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
c = Counter(v)
sum = 0
cnt = 0
num = 0
if c[v[0]] >= a:
    print(float(v[0]))
    for i in range(a,min(b,c[v[0]]) + 1):
        num += combinations_count(c[v[0]], i)
    print(num)
    exit()
for i in cnt_v:
    if c[i] < a:
        a -= c[i]
        b -= c[i]
        sum += c[i]*i
        cnt += c[i]
    else:
        sum += i*a
        cnt += a
        print(sum/cnt)
        print(combinations_count(c[i],a))
        break

Solution (Python):
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def fac(n):
    if n== 1 or n == 0:
        return 1
    return n * fac(n-1)

def comb(n, k):
    if k >n:
        return 0
    return fac(n)/(fac(k) * fac(n-k))

def solve():
    n, a, b = f()
    v = f()
    
    v = sorted(v, reverse = True)

    c = v[a-1]

    cnt1 = 0
    total = 0

    for i in range(n):
        if v[i] == c:
            total += 1
            if i < a:
                cnt1 += 1


    print("{:.7f}".format(sum(v[0:a])/a))
    if v[0] == c:
        ans = 0
        for i in range(a, b+1):
            ans += comb(total, i)
        print(int(ans))
    else:
        print(int(comb(total, cnt1)))

solve()

Solution (Python):
from math import factorial
from itertools import accumulate
from collections import Counter
N, a, b = [int(item) for item in input().split()]
v = sorted([int(item) for item in input().split()], reverse=True)

vsum = list(accumulate(v))
vcounts = []
for i in range(N):
    vcounts.append(Counter(v[:i+1]))

ans = 0
ans_count = 0
for i in range(a, b+1):
    val = vsum[i-1] / i
    if val > ans:
        n = vcounts[N-1][v[i-1]]
        r = vcounts[i-1][v[i-1]]
        ans_count = factorial(n) // factorial(r) // factorial(n-r)
        ans = val
    elif val == ans:
        n = vcounts[N-1][v[i-1]]
        r = vcounts[i-1][v[i-1]]
        ans_count += factorial(n) // factorial(r) // factorial(n-r)
print(ans)
print(ans_count)

Solution (Python):
import math
from collections import Counter
N, A, B = map(int, input().split())
V = sorted(Counter(list(map(int, input().split()))).items(), key=lambda x: x[0], reverse=True)
if A <= V[0][1]:
    print(V[0][0])
    x = min(V[0][1], B)
    num = 0
    for i in range(A, x + 1):
        num += math.factorial(V[0][1]) // (math.factorial(V[0][1] - i) * math.factorial(i))
    print(num)
    exit()
l = []
num = 0
for v, n in V:
    if n >= A:
        l.extend([v] * A)
        num = math.factorial(n) // (math.factorial(n - A) * math.factorial(A))
        break
    else:
        l.extend([v] * n)
        A -= n
        B -= n
print(sum(l) / len(l))
print(num)

Solution (Python):



def factorial(facn):
    ret=1
    for i in range(facn):
        ret*=(i+1)
    return ret

def comb(comb1,comb2):
    x=min(comb1,comb2)
    y=max(comb1,comb2)
    bunshi=factorial(y)
    bunbo=factorial(x)*factorial(y-x)
    return int(bunshi/bunbo)

N,A,B=map(int,input().split())
v=list(map(int,input().split()))
v.sort(reverse=True)
dp=[0 for i in range(N)]
for i in range(A):
    if i == 0:
        dp[0]=v[0]
    else:
        dp[i]=dp[i-1]+v[i]
MAX=dp[A-1]/A
V=v[A-1]
left=v[:A]
right=v[A:]
LV=left.count(V)
RV=right.count(V)
if V == v[0]:
    Vsum=LV+RV
    com=0
    for i in range(A,min(B+1,Vsum+1)):
        com+=comb(Vsum,i)        
else:
    com=comb(LV+RV,LV)
print(MAX)
print(com)

Solution (Python):
N, A, B = map(int, input().split())
V = sorted([int(i) for i in input().split()], reverse = True)

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

last = VA[-1]
x = VA.count(last)
y = V.count(last)

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

if V.count(V[0]) > A:
    ans = 0
    u = min(V.count(V[0]), B)
    for i in range(A, u + 1):
        ans += comb(y, i)
else:
    ans = comb(y, x)
    
print(ans)

Solution (Python):
import sys
from collections import Counter
try:
    from scipy.special import comb
except ImportError:
    from scipy.misc import comb

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

    m_ave = sum(V[:A]) / A
    b = A
    while b < B:
        if V[0] == V[b]:
            b += 1
        else:
            break

    if A == b:
        ans = 1
        c = Counter(V[:A])
        d = Counter(V)
        for key in c.keys():
            n = d[key]
            r = c[key]
            ans *= comb(n, r, exact=True)

    else:
        d = Counter(V)
        key = V[0]
        n = d[key]
        ans = 0
        for r in range(A, b+1):
            ans += comb(n, r, exact=True)

    print(m_ave)
    print(ans)


if __name__ == '__main__':
    main()

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

V.sort(reverse=True)

AVERAGE=V[:A]

print(sum(AVERAGE)/A)

MIN=AVERAGE[-1]

MINUSE=0
for a in AVERAGE:
    if a==MIN:
        MINUSE+=1

MAXUSE=0
for a in V[:B]:
    if a==MIN:
        MAXUSE+=1

ALLUSE=0
for a in V:
    if a==MIN:
        ALLUSE+=1

import math

if V[0]!=MIN:
    print(math.factorial(ALLUSE)//math.factorial(MINUSE)//math.factorial(ALLUSE-MINUSE))

else: 
    ANS=0
    for use in range(MINUSE,MAXUSE+1):
            ANS+=math.factorial(ALLUSE)//math.factorial(use)//math.factorial(ALLUSE-use)

    print(ANS)

Solution (Python):
def fuct(n:int)->int:
    if n<=1:
        return 1
    else:
        return n * fuct(n-1)

def main():
    n,a,b = map(int, input().split())
    v = list(map(int, input().split()))
    v = sorted(v, reverse=True)
    print(sum(v[:a])/a)
    res = 0

    if v[0]==v[a-1]:
        vn = v.count(v[0])
        for r in range(a,b+1):
            res += fuct(vn)//(fuct(vn-r) * fuct(r))
    else:
        vn = v.count(v[a-1])
        r = v[:a].count(v[a-1])
        res += fuct(vn)//(fuct(vn-r) * fuct(r))

    print(res)

if __name__ == '__main__':
    main()

Solution (Python):
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())


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

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


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

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


def comb_sum(base: int, start: int, last: int, mod: int, fac: list, facInv:list):
    ret = 0
    for i in range(start, last+1):
        ret += nCr(base, i, mod, fac, facInv)
        
    return ret

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

v.sort(reverse=True)
maxv = max(v)
maxs = v.count(maxv)

MOD = 2**61-1
MAXN = 100
inv = inv_mod(MAXN, MOD)
fac = fact(MAXN, MOD)
fac_inv = fact_inv(MAXN, inv, MOD)


if maxs <= a:
    ans = sum(v[:a]) / a
    lastcnt = v.count(v[a-1])
    pat = nCr(lastcnt, a-v.index(v[a-1]), MOD, fac, fac_inv)
    
elif a < maxs < b:
    ans = maxv
    pat = comb_sum(maxs, a, maxs, MOD, fac, fac_inv)
    
else:
    ans = maxv
    pat = comb_sum(maxs, a, b, MOD, fac, fac_inv)
    
print(ans)
print(pat)

Solution (Python):
d = {}

def nCr(n, r):
    if n < r:
        return 0
    if n == r or r == 0:
        return 1
    if (n, r) in d:
        return d[(n, r)]
    d[(n, r)] = nCr(n - 1, r) + nCr(n - 1, r - 1)
    return d[(n, r)]

if __name__ == '__main__':
    n, a, b = map(int, input().split())
    v = sorted((int(s) for s in input().split()), reverse=True)
    print(sum(v[:a]) / a)
    x = v.count(v[a - 1])
    print(nCr(x, v[:a].count(v[a - 1])) if v[0] > v[a - 1] else sum(nCr(x, i) for i in range(a, b + 1)))

Solution (Python):

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

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

V.sort(reverse=True)

ave = sum(V[:A])/A
pat = 0
note = 0
cnt = 0
for v in V:
    if v > V[A-1]:
        note += 1
    elif v == V[A-1]:
        cnt += 1
    elif v < V[A-1]:
        break

if V[0] == V[A-1]:
    for i in range(A-note,B+1-note):
        if i > cnt:
            break
        pat += comb(cnt,i)
else:
    pat = comb(cnt,A-note)

print(ave)
print(pat)

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

def frac(n):
    ret=1
    for i in range(2,n+1):
        ret*=i
    return ret
def combi(n,a):
    return frac(n)//frac(a)//frac(n-a)

sm=sum(v[:A])
ave=sm/A
ans=0

minA = v[A-1]
ct_mA = v[:A].count(minA)
nmA = v.count(minA)

if ave == minA:
    i=0
    while A+i <=B and i<=nmA-ct_mA:
        ans+=combi(nmA,i+A)
        i+=1
else:
    ans = combi(nmA,ct_mA)
print(ave)
print(ans)