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

Solution (Python):

import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [input() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [int(input()) for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def roundUp(a, b):
        return -(-a // b)

    @staticmethod
    def toUpperMultiple(a, x):
        return Math.roundUp(a, x) * x

    @staticmethod
    def toLowerMultiple(a, x):
        return (a // x) * x

    @staticmethod
    def nearPow2(n):
        if n <= 0:
            return 0
        if n & (n - 1) == 0:
            return n
        ret = 1
        while(n > 0):
            ret <<= 1
            n >>= 1
        return ret

    @staticmethod
    def sign(n):
        if n == 0:
            return 0
        if n < 0:
            return -1
        return 1

    @staticmethod
    def isPrime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True


MOD = int(1e09) + 7
INF = int(1e09)

nCr = {}

sys.setrecursionlimit(100000)


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


def main():
    
    N, A, B = Scanner.map_int()
    V = Scanner.map_int()
    V.sort(reverse=True)
    ans = 0
    for i in range(A):
        ans += V[i]
    ans /= A
    print(ans)

    vmin = V[A-1]
    if V[0] != V[A-1]:
        cnt = V.count(vmin)
        c = V[:A].count(vmin)
        print(comb(cnt, c))
        return

    c = V.count(vmin)
    cnt = 0
    for i in range(A, B+1):
        if V[i-1] != vmin:
            break
        cnt += comb(c, i)
    print(cnt)


if __name__ == "__main__":
    main()

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

items = sorted(list(map(int, input().split())), reverse=True)

ans_lis = items[:A]
ans1 = sum(ans_lis)/A 
print(ans1)

i = A
ans2 = 0
while i <= B:
  if sum(items[:i])/i != ans1:
    break
  min_ = min(items[:i])
  min_in_ans = items[:i].count(min_)
  min_in_all = items.count(min_)

  nCr = {}
  def cmb(n, r):
    if r == 0 or r == n: return 1
    if r == 1: return n
    if (n,r) in nCr: return nCr[(n,r)]
    nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)
    return nCr[(n,r)]

  ans2 += cmb(min_in_all, min_in_ans)
  i += 1
print(ans2)

Solution (Python):
def COMB(a,b):
	if b > (a-b):
		b = a-b
	ans = 1
	for i in range(0,b):
		ans *= (a-i)
	for i in range(0,b):
		ans //= (b-i)

	return int(ans)

if __name__ == '__main__':
	N, A, B = map(int, input().split())
	v_lst = [int(p) for p in input().split()]

	v_lst.sort(reverse = True)

	count = 0

	for i in range(0,B-A+1):
		lst = v_lst[0:A+i]
		mean = sum(lst)/len(lst)
		if i == 0:
			nxt_mean = mean
		if mean == nxt_mean:
			a = v_lst.count(min(lst))
			b = lst.count(min(lst))
			count += COMB(a,b)
		else:
			break
		nxt_mean = mean

	print("{:.6f}".format(nxt_mean))
	print(count)

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

v.sort()
print "%.8f"%(float(sum(v[-A:]))/A)

x = v[-A]
ans = 0
for b in range(A, B+1):
  if v[-b]!=x:
    break
  if b!=A and v[-1]!=x:
    break
  n1 = v.count(x)
  n2 = v[-b:].count(x)
  a = 1
  for i in range(n2):
    a *= n1-i
  for i in range(n2):
    a /= i+1
  ans += a
print ans

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def nCr(n, r):
    return fac[n] // fac[r] // fac[n - r]

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

def main():
    n, a, b = MI()
    vv = LI()
    vv.sort(reverse=True)
    s = sum(vv[:a])
    tot = vv.count(vv[a - 1])
    l = vv[:a].count(vv[a - 1])
    if l == a:
        p = 0
        for r in range(l, min(tot,b) + 1):
            p += nCr(tot, r)
    else:
        p = nCr(tot, l)
    print(s / a)
    print(p)

main()

Solution (Python):
from math import factorial
def comb(n,r):
    return factorial(n) // factorial(r) // factorial(n - r)
N,A,B = map(int,input().split())
V = list(map(int,input().split()))
V.sort()
x = V[-1]
ans = 0
for i in range(1,A+1):
    ans += V[-i]
    x = V[-i]
ans = ans/A
print(ans)
count = 0
import bisect
y = N - bisect.bisect(V,x)
if x == V[-1]:
    n = V.count(x)
    for i in range(A,min(B,V.count(x))+1):
        z = i - y
        count += comb(n,z)
else:
    z = A - y
    n = V.count(x)
    count += comb(n,z)
print(count)

Solution (Python):


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

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

def comb(n, r):
    return factorial_memo[n]//(factorial_memo[n-r] * factorial_memo[r])

print(sum(v[:A]) / A)
for i in reversed(range(A, N)):
    if v[i] == v[0]:
        print(sum([comb(i+1, x) for x in range(A, B+1)]))
        break
else:
    print(comb(v.count(v[A]), v[:A].count(v[A])))

Solution (Python):
import bisect
import math
from scipy.misc import comb

N,A,B=map(int,input().split())
List=list(map(int,input().split()))
List = sorted(List, reverse=True)

mini = List[A-1]
ans = 0

if List[A-1] != List[A]:
  ans = sum(List[:A])/A
  print(ans)
  print(1)

else:
  num = List.count(List[A-1])
  List = sorted(List)
  num2 = N - bisect.bisect_right(List,mini)
  List = sorted(List, reverse=True)
  
  if List[0] != List[A-1]:
    B = A
  for i in range(B-A+1):
    n = num
    kosuu = A + i - num2
    ans  = int(ans + comb(n, kosuu, exact=True))
  
  ave = int(sum(List[:A])/A)
  print(ave)
  print(ans)

Solution (Python):

from collections import defaultdict
from math import factorial
si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))
def perm(n,r):
    return factorial(n)//factorial(n-r)
 
def comb(n,r):
    return perm(n,r)//factorial(r)

n,a,b=nm()
v=sorted(nl(), reverse=True)

if v[0]==v[a-1]:
    n = 0
    for vv in v:
        if vv!=v[0]: break
        n += 1

    ans = 0
    for k in range(a, min(b,n)+1):
        ans += comb(n, k)

else:
    n = k = 0
    for i,vv in enumerate(v):
        if vv==v[a-1]:
            if i<a: k += 1
            n += 1
    ans = comb(n,k)

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

Solution (Python):
from collections import Counter

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

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

V.sort(reverse=True)

c = Counter(V)


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


c_max = Counter(V[:A])



def nCr(n,r):
    if n < 0 or r < 0 or n < r: return 0
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n
  
    
    numerator = [n-r+k+1 for k in range(r)]
    
    denominator = [k+1 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
        
    ret = 1
    for k in range(r):
        if numerator[k] > 1: ret *= int(numerator[k])
      
    return ret



if len(c_max) == 1:
    
    ans = 0
    n = c[V[0]]
    for r in range(A, min(B, n)+1):
        ans += nCr(n,r)





else:
    
    
    tmp = list(c_max.keys())
    tmp.sort()
    
    min_num = tmp[0]
    
    cnt = 0
    for i in tmp[1:]:
        cnt += c_max[i]
    remaining = A - cnt

    ans = nCr(c[min_num], remaining)

print(max_average)
print(ans)

Solution (Python):
import sys
input = sys.stdin.readline
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 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

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result


n,a,b=map(int,input().split())
v=list(map(int,input().split()))
v.sort()
sm=sum(v[-a:])
av=sm/a
ky=v[-a]
c=v.count(ky)
co=0
for i in range(n):
    if v[-i-1]>ky:
        co+=1
ans=0

if co>0:
    ans=cmb(c,a-co)
else:
    for i in range(a,min(b+1,c+co+1)):
        ans+=cmb(c,i-co)
print(av)
print(ans)

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

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

n,a,b,*v=map(int,open(0).read().split())
v.sort(reverse=True)
print(sum(v[:a])/a)
c=v[a-1]
cnt=v.count(c)
d=sum(x>c for x in v)
if d:
	print(cmb(cnt,a-d))
else:
	print(sum(cmb(cnt,i) for i in range(a,min(cnt,b)+1)))

Solution (Python):
import math

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

def groupby(a):
    a2=[[a[0],1]]
    for i in range(1,len(a)):
        if a2[-1][0]==a[i]:
            a2[-1][1]+=1
        else:
            a2.append([a[i],1])
    return a2

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

if A<=v[0][1]:
    
    m=min(v[0][1],B)
    co=0
    for i in range(A,m+1):
        co+=combinations_count(v[0][1],i)
    print(v[0][0])
    print(co)
else:
    al=0
    l=len(v)
    C=0
    for i in range(l):
        C+=v[i][1]
        if C<=A:
            al+=(v[i][0]*v[i][1])
        else:
            C-=v[i][1]
            al+=(v[i][0]*(A-C))
            k=combinations_count(v[i][1],A-C)
            break
    print(al/A)
    print(k)

Solution (Python):
N, A, B = map(int,input().split())
V = list(map(int,input().split()))
V.sort(reverse = True)
Vs=V[:A]
print(sum(Vs)/A)

Vs = list(set(Vs))
Vs.sort(reverse = True)

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

if len(Vs)!=1:
    N = V.count(Vs[-1])
    k = V[:A].count(Vs[-1])
    ans = com[N][k]
else:
    ans = 0
    N = V.count(Vs[0])
    for k in range(A,B+1):
        ans += com[N][k]
print(ans)

Solution (Python):
def cmb(n, r):
    if n - r < r: r = n - r
    if r < 0 : return 0
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 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

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result


n,a,b=map(int,input().split())
v=list(map(float,input().split()))
v=sorted(v,reverse=True)
V=0
for i in range(a):
  V=V+v[i]
ans1=V/a
print(ans1)
ans2=0
if v[0]==ans1:
  c=v.count(ans1)
  for i in range(a,b+1):
    ans2=ans2+cmb(c,i)
  print(ans2)
else:
  d=0
  e=0
  for i in range(a):
    if v[i]==v[a]:
      d=d+1
  for i in range(n):
    if v[i]==v[a]:
      e=e+1
  ans2=cmb(e,d)
  print(ans2)

Solution (Python):
nab=list(map(int,input().split()))
v=list(map(int,input().split()))
v.sort(reverse=True)
vmin=v[:nab[1]]
print(sum(vmin)/len(vmin))
mini=1
if nab[1]>1:
    for i in range(nab[1]-1):
        if vmin[-2-i]==vmin[-1]:
            mini+=1
        else:
            break
ex=0
for i in range(nab[0]-nab[1]):
    if v[nab[1]+i]==vmin[-1]:
        ex+=1
    else:
        break
def f(n):
    out=1
    for i in range(1,n+1):
        out*=i
    return out
ans=0
if vmin[0]!=vmin[-1]:
    ans=f(mini+ex)//(f(mini)*f(ex))
    print(ans)
else:
    m=min(nab[2]-nab[1],ex)
    for i in range(m+1):
        ans+=f(mini+ex)//(f(mini+i)*f(ex-i))
    print(ans)

Solution (Python):



def make_pascal_tri(n):
    array = [[1 for i in range(n + 1)] for i in range(n + 1)]
    for i in range(1, n + 1):
        for j in range(n + 1):
            if j > i:
                array[i][j] = 0
            elif j == 0 or j == i:
                array[i][j] = 1
            else:
                array[i][j] = array[i - 1][j] + array[i - 1][j - 1]
    return array


ar = make_pascal_tri(100)
n, a, b = map(int, input().split())
val = sorted(map(int, input().split()), reverse=True)
res_ave = 0
for i in range(a):
    res_ave += val[i]
res_ave /= a
grat_cnt = 0
same_cnt = 0
for i in range(n):
    if val[i] > val[a - 1]:
        grat_cnt += 1
    elif val[i] == val[a - 1]:
        same_cnt += 1
    else:
        break
result = 0

if grat_cnt == 0:
    for i in range(a, b + 1):
        result += ar[same_cnt][i]
else:
    result = ar[same_cnt][a - grat_cnt]

print(res_ave)
print(result)

Solution (Python):


import sys
from collections import Counter

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

def nCr(n, r):
    """ 事前テーブルなし組み合わせ簡易版 """
    from math import factorial

    if n < r: return 0
    
    r = min(r, n-r)
    return factorial(n) // (factorial(r) * factorial(n-r))

N, L, R = MAP()
A = LIST()

A.sort(reverse=1)
C = Counter(A)
mx = cnt = 0
for i in range(L, R+1):
    A2 = A[:i]
    avg = sum(A2) / i
    
    if avg >= mx:
        mx = avg
    else:
        break
    C2 = Counter(A2)
    
    a = A2[-1]
    
    cnt += nCr(C[a], C2[a])
print(mx)
print(cnt)

Solution (Python):
N,A,B=map(int,input().split())
X=[int(x) for x in input().split()]
X.sort(reverse=True)
ave=sum(X[:A])/A
p=X[A-1]
c=0
o=0
for i in range(N):
  if X[i]==p:
    c +=1
  elif X[i]>p:
    o +=1
    

def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n
 
    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 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
 
    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])
 
    return result
answer=0
if not o==0:
  answer=cmb(c,A-o)
else:
  for i in range(A,min(c,B)+1):
    answer += cmb(c,i)
print(ave)
print(answer)

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

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

if V[0]==V[A-1]:
    n = 0
    for v in V:
        if v!=V[0]: break
        n += 1

    ans = 0
    for k in range(A, min(B,n)+1):
        ans += comb(n, k)

else:
    n = k = 0
    for i,v in enumerate(V):
        if v==V[A-1]:
            if i<A: k += 1
            n += 1
    ans = comb(n,k)

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

Solution (Python):
import statistics
import itertools

n, a, b = map(int, input().split())
v = sorted(list(map(int, input().split())), reverse=True)
mean = statistics.mean(v[:a])



def count_table(n):
    c = [[0 for _ in range(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]
    return c


count_v_a = 0
pos_v_a = 0
for i in range(n):
    if v[i] == v[a-1]:
        count_v_a += 1
        if i < a:
            pos_v_a += 1

c = count_table(n)
count = 0
if pos_v_a == a:
    for pos in range(a, b + 1):
        count += c[count_v_a][pos]
else:
    count += c[count_v_a][pos_v_a]

print(mean)
print(count)

Solution (Python):
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=map(int,input().split())
V=list(map(int,input().split()))
V.sort()
av_max=0
count=0

for i in range(A,B+1):
    if sum(V[N-i:N])/i>av_max:
        av_max=sum(V[N-i:N])/i
        count=cmb(V.count(V[N-i]),V[N-i:N].count(V[N-i]))
    elif sum(V[N-i:N])/i==av_max:
        count+=cmb(V.count(V[N-i]),V[N-i:N].count(V[N-i]))

print(av_max)
print(count)

Solution (Python):
import decimal
def ncr(x,y):
	ans=1
	q=x-y
	while x>y:
		ans*=x
		x=x-1
	
	while q>1:
		ans=ans/q
		q=q-1
	
	return ans

x=input().split()
n=int(x[0])
a=int(x[1])
b=int(x[2])
v=[0]*n
x = input().split()
ind=0
M={1:0}
M2={1:0}
for i in x:
	v[ind]=int(i)
	if int(i) in M:
		M[v[ind]]+=1
	else:
		M[v[ind]]=1
	ind+=1
v.sort(reverse=True)

cnt=0
ind=0
m=0
while cnt<a:
	cnt+=1
	m=decimal.Decimal((cnt-1)*m+v[ind])/decimal.Decimal(cnt)
	if v[ind] in M2:
		M2[v[ind]]+=1
	else:
		M2[v[ind]]=1
	ind+=1
while cnt<b:
	if (cnt*m+v[ind])/(cnt+1)<m:
		break
	else:
		cnt+=1;
		if v[ind] in M2:
			M2[v[ind]]+=1
		else:
			M2[v[ind]]=1
		ind+=1
print(m)
maxw=cnt;
ways=0;
for i in range(int(cnt),a-1,-1):
	if v[ind-1] not in M2:
			M2[v[ind]]=0
	if v[ind-1] not in M:
			M[v[ind-1]]=0
	
	ways+=ncr(M[v[ind-1]],M2[v[ind-1]])
	
	M2[v[ind-1]]-=1

print(round(ways))

Solution (Python):
import sys
from bisect import bisect_left as bi_l, bisect_right as bi_r
import scipy.misc

def comb(n, r):
    return scipy.misc.comb(n, r, exact=True)

n, a, b, *v = map(int, sys.stdin.read().split())

def main():
    v.sort()

    ma = v[n-a:n]
    yield sum(ma) / a

    lo = ma[0]
    hi = ma[-1]

    res = 0
    lo_cnt = bi_r(v, lo) - bi_l(v, lo)
    if lo == hi:
        for c in range(a, min(b, lo_cnt) + 1):
            res += comb(lo_cnt, c)
    else:
        allowed_cnt = bi_r(ma, lo)
        res = comb(lo_cnt, allowed_cnt)
    
    yield res

if __name__ == '__main__':
    ans = main()
    print(*ans, sep='\n')

Solution (Python):
from collections import Counter

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

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

V.sort(reverse=True)

c = Counter(V)
max_average = sum(V[:A]) / A
c_max = Counter(V[:A])

def nCr(n,r):
  if n < 0 or r < 0 or n < r: return 0
  if n - r < r: r = n - r
  if r == 0: return 1
  if r == 1: return n
  
  
  numerator = [n-r+k+1 for k in range(r)]
  
  denominator = [k+1 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
        
  ret = 1
  for k in range(r):
    if numerator[k] > 1: ret *= int(numerator[k])
      
  return ret



if len(c_max) == 1:
    
    ans = 0
    n = c[V[0]]
    for r in range(A, min(B, n)+1):
        ans += nCr(n,r)





else:
    
    
    tmp = list(c_max.keys())
    tmp.sort()
    
    min_num = tmp[0]
    
    cnt = 0
    for i in tmp[1:]:
        cnt += c_max[i]
    remaining = A - cnt

    ans = nCr(c[min_num], remaining)

print(max_average)
print(ans)

Solution (Python):
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.sort(reverse=True)
answer = sum(v[:A]) / A
n = 0

if v[0] == v[A - 1]:
    N = v.count(v[0])
    n = cmb(N, min(N, B))
    tmp_cmb = n
    for i in range(min(B, N) - 1, A - 1, -1):
        tmp = N - i
        tmp_cmb = tmp_cmb * (i + 1) // tmp
        n += tmp_cmb
else:
    n = cmb(v.count(v[A - 1]), A - v.index(v[A - 1]))

print(answer)
print(n)

Solution (Python):
from math import factorial
import bisect
def cmb(n,r):
  if n<0 or r<0:
    return 0
  else:
    return factorial(n)//factorial(n-r)//factorial(r)
n,a,b=map(int,input().split())
x = list(map(int,input().split()))
ans=0
x.sort(reverse=True)
print(sum(x[:a])/a)
if n==a:
  print(1)
elif x[0]==x[a]:
  for i in range(n):
    if x[0] != x[i]:
      k=i
      break
  else:
    k=n
  for i in range(a,min(k+1,b+1)):
    ans+=cmb(k,i)
  print(ans)
elif x[a-1] == x[a]:
  y=sorted(x)
  x1=bisect.bisect_left(y,x[a])
  x2=bisect.bisect_right(y,x[a])
  print(cmb(x2-x1,a-(n-x2)))
else:
  print(1)

Solution (Python):

def combination_table(N):
    C=[[0 for i in range(N)] for j in range(N)]
    for i in range(N):
        for j in range(i):
            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[2:]

if __name__ == '__main__':
    N,A,B=list(map(int,input().split()))
    V=list(map(int,input().split()))
    V.sort(reverse=True)
    temp=V[:A]
    max_mean=sum(temp)/A
    count=0
    C=combination_table(N+2)

    if V[0]!=V[A-1]:
        temp_1=V.count(V[A-1])
        temp_2=V[:A].count(V[A-1])
        count+=C[temp_1-1][temp_2]
        """temp_1=V.count(V[0])
        temp_2=V[:A].count(V[0])
        count+=C[temp_1-1][temp_2]"""
    elif V[0]==V[A-1]:
        for i in range(A,B+1):
            temp_1=V.count(V[0])
            count+=C[temp_1-1][i]

    print(max_mean)
    print(count)

Solution (Python):
from math import factorial

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

print(sum(V[:A]) / A)
if V[0] == V[A - 1]:
    n = sum([1 for v in V if v == V[0]])
    print(sum([factorial(n) // factorial(r) // factorial(n - r)
               for r in range(A, min(n, B) + 1)]))
else:
    n = sum([1 for v in V if v == V[A - 1]])
    r = sum([1 for v in V[:A] if v == V[A - 1]])
    print(factorial(n) // factorial(r) // factorial(n - r))

Solution (Python):
import bisect
import math
N, A, B = map(int, input().split())
v = sorted(list(map(int, input().split())))
ave = sum(v[-A:]) / A
print(ave)
leftA = bisect.bisect_left(v, v[-A])
rightA = bisect.bisect_right(v, v[-A])

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

ans = 0
if v[-A] == v[-1]:
    for i in range(A, min(rightA-leftA, B) + 1):
        ans += comb(rightA-leftA, i)
    print(ans)
else:
    print(comb(rightA-leftA, A+rightA-N))

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

fa = [1]
for i in range(1, 60): fa.append(fa[-1] * i)
C = lambda a, b: fa[a] // (fa[a-b] * fa[b])

print(sum(V[:A])/A)
print(sum([C(V.count(V[i-1]), V[:i].count(V[i-1])) for i in range(A, B+1) if sum(V[:i])*A == sum(V[:A])*i]))

Solution (Python):
from itertools import accumulate as ac
t = 3099044504245996706400 
N, A, B = map(int, input().split())
V = sorted([int(a) * t for a in input().split()])[::-1]
l, r = 0, 1<<200
while r - l > 1:
    m = (l+r) // 2
    if list(ac([v-m for v in V]))[A-1] >= 0:
        l = m
    else:
        r = m

fa = [1]
for i in range(1, 60):
    fa.append(fa[-1] * i)
C = lambda a, b: fa[a] // (fa[a-b] * fa[b])

print(l/t)
print(sum([C(V.count(V[i-1]), V[:i].count(V[i-1])) for i in range(A, B+1) if sum(V[:i]) == l * i]))

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

n, a, b = map(int, input().split())
L = [int(i) for i in input().split()]
L.sort(reverse=True)

T = L[:a]
print(sum(T)/a)

s = 0
Tmin = min(T)
countTminT = T.count(Tmin)
countTminL = L.count(Tmin)

if a == 1 and countTminL == 1:
  s = 1
elif countTminT == a:
  for i in range(a,b+1):
    if countTminL+1 == i:
      break
    s += pcount(countTminL, i)
else:
  s += pcount(countTminL, countTminT)

print(s)

Solution (Python):
def solve() -> 'max(averages), count(max(averages))':
    from collections import Counter
    from functools import lru_cache
    n, a, b = map(int, input().split())
    v = tuple(sorted(map(int, input().split()), reverse=True))

    def max_ave_x() -> 'max(average),{counts_to_make_max_average}':
        ret = -1
        t = 0
        max_i = set()
        for i, e in enumerate(v, 1):
            t += e
            if a <= i:
                ave = t / i
                if ret < ave:
                    max_i = {i}
                    ret = ave
                elif ret == ave:
                    max_i.add(i)
            if i == b:
                break
        return ret, max_i

    @lru_cache(maxsize=None)
    def combination(n, r):
        if n < r or r < 0:
            return 0
        if r > n - r:
            return combination(n, n - r)
        if r == 0:
            return 1
        if r == 1:
            return n
        return combination(n - 1, r - 1) * n // r

    max_, indices = max_ave_x()

    ret = 0

    c1 = Counter(v)
    for i in indices:
        c2 = Counter(v[:i])
        t = 1
        for chr_ in c2:
            t *= combination(c1[chr_], c2[chr_])
        ret += t

    return max_, ret


print(*solve(), sep='\n')

Solution (Python):
n,a,b=map(int,input().split())
v=list(map(int,input().split()))
v.sort(reverse=True)
print(sum(v[:a])/a)
 
import math
def cmb(n,r):
    f = math.factorial
    return int(f(n) // f(r) // f(n-r))
x,y=v.count(v[a-1]),v[:a].count(v[a-1])
if v[0]==v[a-1]:
   ans=sum(cmb(x,i) for i in range(a,min(b,x)+1))
else:
    ans=cmb(x,y)
print(ans)

Solution (Python):
import math

nab = [int(x) for x in input().split()]
n = nab[0]
a = nab[1]
b = nab[2]
counts = []
nums = [int(x) for x in input().split()]
means = []
nums.sort(reverse = True)
for i in range(a, b+1):
  means.append(sum(nums[:i])/i)
  counts.append(int(math.factorial(nums.count(nums[i-1]))/(math.factorial(nums[:i].count(nums[i-1]))*math.factorial(nums.count(nums[i-1])-nums[:i].count(nums[i-1])))))

maxim = max(means)
print(maxim)
k = 0
count = 0
while k<len(means):
  if means[k]==maxim:
    count+=counts[k]
  k+=1
print(count)



'''
def C(n, k):
  return C(n-1, k-1) + C(n-1, k)
  
for n in range(MAX_N):
  for k in range(MAX_K):
    C[n][k] = C[n-1][k-1] + C[n-1][k]
'''

Solution (Python):
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

def main():
    N, A, B = map(int, input().split())
    v = list(map(int, input().split()))
    sort_v = sorted(v, reverse=True)
    ave = 0
    for i in range(A):
        ave += sort_v[i]
    ave = ave / A
    ans = 0
    if sort_v[0] == sort_v[A-1]:
        cnt = v.count(sort_v[A-1])
        for i in range(A, min(cnt,B)+1):
            ans += cmb(cnt,i)
    else:
        cnt = v.count(sort_v[A-1])
        ind = sort_v.index(sort_v[A-1])
        ans = cmb(cnt, A - ind)
    print(ave)
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
from itertools import groupby
from math import factorial

def comb(n,k):
    if(k<0 or n<k): return 0
    return factorial(n)//(factorial(k)*factorial(n-k))

def resolve():
    n,a,b=map(int,input().split())
    V=list(map(int,input().split()))
    V.sort(reverse=1)
    m=sum(V[:a])/a
    print(m)

    cnt=0
    for key,iter in groupby(V):
        k=len(list(iter))
        if(cnt+k>=a): break
        cnt+=k

    ans=0
    if(cnt==0):
        for i in range(a-cnt,min(k,b-cnt)+1):
            ans+=comb(k,i)
    else:
        ans=comb(k,a-cnt)
    print(ans)
resolve()

Solution (Python):
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
from itertools import groupby
from math import factorial

def comb(n,k):
    if(k<0 or n<k): return 0
    return factorial(n)//(factorial(k)*factorial(n-k))

def resolve():
    n,a,b=map(int,input().split())
    V=list(map(int,input().split()))
    V.sort(reverse=1)
    m=sum(V[:a])/a
    print(m)

    cnt=0
    for key,iter in groupby(V):
        k=len(list(iter))
        if(cnt+k>=a): break
        cnt+=k

    ans=0
    K=min(k,b-cnt)
    if(cnt==0):
        for i in range(a-cnt,K+1):
            ans+=comb(k,i)
    else:
        ans=comb(k,a-cnt)
    print(ans)
resolve()