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):
n, a, b = map(int, input().split())
V = list(map(int, input().split()))
V.sort(reverse=True)

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

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

if V[0] != V[a-1]:
    cnt = combinations_count(x, y)
    print(ans/a)
    print(cnt)
else:
    cnt = 0
    for i in range(a, b+1):
        if i <= x:
            cnt += combinations_count(x, i)
    print(ans/a)
    print(cnt)

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

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

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

if V[0] != V[a-1]:
    cnt = combinations_count(x, y)
    print(ans/a)
    print(cnt)
else:
    cnt = 0
    for i in range(a, b+1):
        if i <= x:
            cnt += combinations_count(x, i)
    print(ans/a)
    print(cnt)

Solution (Python):
def main():
    from decimal import Decimal

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

    v.sort(reverse=True)

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

    tail = v[A - 1]
    contained = [0] * (N + 1)
    s = 0
    for i, x in enumerate(v, start=1):
        if x == tail:
            s += 1
        contained[i] = s

    def choose(n, a):
        if n - a < a:
            return choose(n, n - a)
        x, y = 1, 1
        for i in range(a):
            x = x * (n - i)
            y = y * (i + 1)
        return x // y

    count = 0
    for k in range(A, B + 1):
        if (k > A) and (v[k - 1] != max_average): break
        count += choose(contained[-1], contained[k])

    print(max_average)
    print(count)


if __name__ == '__main__':
    main()

Solution (Python):
def main():
    from decimal import Decimal

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

    v.sort(reverse=True)

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

    tail = v[A - 1]
    contained = [0] * (N + 1)
    s = 0
    for i, x in enumerate(v, start=1):
        if x == tail:
            s += 1
        contained[i] = s

    def choose(n, a):
        x, y = 1, 1
        for i in range(a):
            x = x * (n - i)
            y = y * (i + 1)
        return x // y

    count = 0
    for k in range(A, B + 1):
        if (k > A) and (v[k - 1] != max_average): break
        count += choose(contained[-1], contained[k])

    print(max_average)
    print(count)


if __name__ == '__main__':
    main()

Solution (Python):
import math
def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
n,a,b=map(int,input().split())
v=sorted(list(map(int,input().split())),reverse=1)
tmp=sum(v[:a])
ans=(tmp,a)
x=[a-1]
for i in range(a,b):
    tmp+=v[i]
    if ans[0]*(i+1)<=ans[1]*tmp:
        if ans[0]*(i+1)==ans[1]*tmp:
            x.append(i)
        else:
            x=[i]
print(ans[0]/ans[1])
ans=0
for i in x:
    a,b=v.count(v[i]),v[i+1:].count(v[i])
    ans+=comb(a,b)
print(ans)

Solution (Python):
C = [[0 for j in range(51)] for i in range(51)]
for i in range(51):
    C[i][0] = 1
for i in range(1, 51):
    for j in range(1, 51):
        C[i][j] = C[i - 1][j - 1] + C[i - 1][j]
n, a, b = map(int, input().split())
*V, = map(int, input().split())
V.sort(reverse=True)
print(sum(V[:a]) / a)
if V[0] == V[a - 1]:
    x = V.count(V[a - 1])
    print(sum([C[x][y] for y in range(a, b + 1)]))
else:
    x = V.count(V[a - 1])
    y = a - len([v for v in V if v > V[a - 1]])
    print(C[x][y])

Solution (Python):
MOD = 1
m = 100
COMB_table = [[0]*(m+1) for _ in range(m+1)]

fac = [0] * m
finv = [0] * m
inv = [0] * m


def COMBinitialize(m):
    fac[0] = 1
    finv[0] = 1
    if m > 1:
        fac[1] = 1
        finv[1] = 1
        inv[1] = 1
        for i in range(2, m):
            fac[i] = fac[i-1] * i % MOD
            inv[i] = MOD - inv[MOD % i] * (MOD // i) % MOD
            finv[i] = finv[i - 1] * inv[i] % MOD


def COMB(n, k):
    if n < k:
        return 0
    if n < 0 or k < 0:
        return 0
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD


def make_COMB_table(m):
    for i in range(m+1):
        for j in range(i+1):
            if j == 0 or j == i:
                COMB_table[i][j] = 1
            else:
                COMB_table[i][j] = COMB_table[i-1][j-1] + COMB_table[i-1][j]


def COMB_2(n, k):
    if n < k:
        return 0
    if n < 0 or k < 0:
        return 0
    return COMB_table[n][k]


make_COMB_table(m)


def main():
    from collections import Counter
    N, A, B = (int(i) for i in input().split())
    V = [int(i) for i in input().split()]
    V.sort(reverse=True)
    ans = sum(v for v in V[:A])/A
    c = Counter(V)
    c_ans = Counter(V[:A])
    cnt = 0
    if V[0] != V[A-1]:
        cnt = COMB_2(c[V[A-1]], c_ans[V[A-1]])
    else:
        for i in range(A, B+1):
            cnt += COMB_2(c[V[0]], i)
    print(ans)
    print(cnt)


if __name__ == '__main__':
    main()

Solution (Python):
MOD = 10**9 + 7
m = 100
COMB_table = [[0]*(m+1) for _ in range(m+1)]


def make_COMB_table(m):
    for i in range(m+1):
        for j in range(i+1):
            if j == 0 or j == i:
                COMB_table[i][j] = 1
            else:
                COMB_table[i][j] = COMB_table[i-1][j-1] + COMB_table[i-1][j]


def COMB_2(n, k):
    return COMB_table[n][k]


make_COMB_table(m)


def main():
    from collections import Counter
    N, A, B = (int(i) for i in input().split())
    V = [int(i) for i in input().split()]
    V.sort(reverse=True)
    ans = sum(v for v in V[:A])/A
    c = Counter(V)
    c_ans = Counter(V[:A])
    cnt = 0
    if V[0] != V[A-1]:
        cnt = COMB_2(c[V[A-1]], c_ans[V[A-1]])
    else:
        for i in range(A, B+1):
            cnt += COMB_2(c[V[0]], i)
    print(ans)
    print(cnt)


if __name__ == '__main__':
    main()

Solution (Python):
from sys import stdin
def main():
    
    readline=stdin.readline
    N,A,B=map(int,readline().split())
    v=list(map(int,readline().split()))
    v.sort(reverse=True)

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

    
    res=0
    x=v[A-1]
    x_count=v.count(x)
    x_count_copy=x_count
    if x==v[0]:
        up=1
        down=1
        for i in range(1,A):
            up*=x_count_copy
            x_count_copy-=1
            down*=i
        if x_count>=B:
            for i in range(A,B+1):
                up*=x_count_copy
                x_count_copy-=1
                down*=i
                res+=up//down
        else:
            for i in range(A,x_count+1):
                up*=x_count_copy
                x_count_copy-=1
                down*=i
                res+=up//down
    else:
        m=A
        for i in range(A):
            if v[i]>x:
                m-=1
            else:
                break
        up=1
        down=1
        for i in range(1,m+1):
            up*=x_count_copy
            x_count_copy-=1
            down*=i
        res=up//down

    print(average)
    print(res)
    
if __name__=="__main__":
    main()

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

V.sort(reverse = True)
s = 0
m = V[a-1]
ans = sum(V[:a])/a
print(ans)
cnt = V.count(m)
left = V.index(m)
ans = 0
memo = {}
def combi(m,k):
    if m*100+k in memo:
        return memo[m*100+k]
    elif k == 0:
        return 1
    else:
        memo[m*100+k] = combi(m,k-1)*(m-k+1)//k
        return memo[m*100+k]

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

Solution (Python):
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_tuple(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_col(H):
    '''
    H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) 
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


def read_matrix(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    


def combination_mod(n, r):
    
    if r > n:
        return 0  
    r = min(r, n - r)
    nf = rf = 1
    for i in range(r):
        nf = nf * (n - i)
        rf = rf * (i + 1)
    return nf // rf


MOD = 10**9 + 7
INF = 2**31  

from collections import defaultdict, Counter, deque
from operator import itemgetter
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  













N, A, B = read_ints()
V = read_ints()
V.sort(reverse=True)
V_A = V[:A]
ans1 = sum(V_A) / A

if V[A] != V[A - 1]:
    print(ans1)
    print(1)
    exit()


if V_A[0] != V_A[-1]:
    c = V_A[-1]
    n_c = V.count(c)
    r = V_A.count(c)
    
    ans2 = combination_mod(n_c, r)
    print(ans1)
    print(ans2)
    exit()


n_same = V.count(V[0])
if n_same > A:
    ans2 = 0
    r_max = min(n_same, B)  
    for i in ra(A, r_max + 1):
        ans2 += combination_mod(n_same, i)
    print(ans1)
    print(ans2)
    exit()


raise ValueError('CE出てほしい')

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

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

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

def solve(V,A,B):
    if V[A-1]>V[A]:
        return 1
    a = V[A-1]
    l,r = -1,-1
    for i in range(N):
        if l==-1 and V[i]==a:
            l = i
        if r==-1 and V[i]<a:
            r = i
    if r==-1:
        r = N
    lower = A-l
    upper = min(r,B)-l
    total = r-l
    ans = 0
    if V[0]==a:
        for i in range(lower,upper+1):
            ans += comb(total,i)
    else:
        ans += comb(total,lower)
    return ans
print(solve(V,A,B))

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


max_avg = (sum(v[:A]), A)

t = v[A-1]
num1 = v[:A].count(t)
num2 = v[A:].count(t)

fact = [0]*(N+1)
ifact = [0]*(N+1)
inv = [0]*(N+1)
p=170141183460469231731687303715884105727

def combination(n,fact,ifact):
    fact[0] = 1
    fact[1] = 1
    ifact[0] = 1
    ifact[1] = 1
    inv[1] = 1
    for i in range(2,n+1):
        fact[i] = (fact[i-1]*i)%p
        inv[i] = p - inv[p%i]*(p//i)%p
        ifact[i] = (ifact[i-1]*inv[i])%p
def op(n,k):
    if k<0 or k>n or n<0:
        return 0
    return (fact[n]*ifact[k]*ifact[n-k])%p

combination(N,fact,ifact)

res = int(op(num1+num2, num1))
if v[0]==v[-1]:
    res = 0
    for i in range(A,B+1):
        res += int(op(N, i))
elif v[0] == v[B-1]:
    res = 0
    for i in range(A, B+1):
        res += int(op(num1+num2,i))
elif v[0] == v[A-1]:
    res = 0
    for i in range(A, min(B, A+num2)+1):
        res += int(op(num1+num2, i))
print(max_avg[0]/max_avg[1])
print(res)

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



dp = [0] * (n + 1)
dq = [0] * (n + 1)

dq[0] = 1

for i in range(n):
    val = v[i]
    
    for j in range(n)[::-1]:
        if dp[j + 1] == dp[j] + val:
            dq[j + 1] += dq[j]
        if dp[j + 1] < dp[j] + val:
            dp[j + 1] = dp[j] + val
            dq[j + 1] = dq[j]
        else:
            continue

max_ans = 0
max_cnt = 10 ** 30
for i in range(a, b + 1):
    if max_cnt * dp[i] > max_ans * i:
        max_ans = dp[i]
        max_cnt = i

ans = 0
for i in range(a, b + 1):
    if max_cnt * dp[i] == max_ans * i:
        ans += dq[i]

print(max_ans / max_cnt)
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)

S = sum(V[:A])
cnt = A
mx = S / cnt
L = [cnt]

for v in V[A:]:
    if cnt == B:
        break
    cnt += 1
    S += v
    if mx < S / cnt:
        mx = S / cnt
        L = []
    if mx == S / cnt:
        L.append(cnt)

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

print(mx)
ans = 0
cntV = Counter(V)
for c in L:
    cnt = Counter(V[:c])
    prd = 1
    for x, c in cnt.items():
        prd *= ncr(cntV[x], c)
    ans += prd
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)

S = sum(V[:A])
cnt = A
mx = S / cnt
L = [cnt]

for v in V[A:]:
    if cnt == B:
        break
    cnt += 1
    S += v
    if mx < S / cnt:
        mx = S / cnt
        L = []
    if mx == S / cnt:
        L.append(cnt)

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

print(mx)
ans = 0
cntV = Counter(V)
for c in L:
    cnt = Counter(V[:c])
    prd = 1
    for x, c in cnt.items():
        prd *= ncr(cntV[x], c)
    ans += prd
print(ans)

Solution (Python):
import sys
from collections import defaultdict as dd
input = sys.stdin.readline
N, A, B = map(int, input().split())
a = list(map(int, input().split()))
a.sort(reverse = True)
res = 0
xi = 0
xis = []
for i in range(A - 1, B):
  t = 0
  for j in range(i + 1): t += a[j]
  t /= i + 1
  if res < t:
    res = t
    xi = i + 1
    xis = [i + 1]
  elif res == t:
    xis.append(i + 1)
resc = 0
while len(xis):
  xi = xis.pop()
  d = dd(int)
  for x in a: d[x] += 1
  d2 = dd(int)
  for i in range(xi): d2[a[i]] += 1
  
  tt = 1
  for k in d2.keys():
    t = 1
    for i in range(d[k], 0, -1):
      if i <= d[k] - d2[k]: break
      t *= i
    for i in range(1, d2[k] + 1): t //= i
  
    tt *= t
  resc += tt

print(res)
print(resc)

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

total = sum(V[:A])

ave = total / A

tmp = V[A - 1]

count = V.count(tmp)

def combination(n, r): 
    if n - r > r:
        r = n - r
    tmp = 1
    for i in range(n - r + 1, n + 1):
        tmp *= i
    for i in range(1, r + 1):
        tmp //= i
    return tmp





if V[0] == V[A - 1]: 
    ans = 0
    for i in range(A, min(B, count) + 1):
        ans += combination(count, i)

else: 
    count2 = V[:A].count(tmp)
    ans = combination(count, count2)

print (ave)
print (ans)

Solution (Python):
import collections
N,A,B=map(int,input().split())
v=list(map(int,input().split()))
v.sort(reverse=True)
l=[]
frac=[1]*51
modfrac=[1]*51
avg=0
for i in range(1,51):
    frac[i]=frac[i-1]*i
for i in range(A):
    l.append(v[i])
avg=(sum(l)/len(l))
mi=min(l)
cnt=0
c1 = collections.Counter(l)
c2 = collections.Counter(v)
if len(set(l))==1:
    n=c2[mi]
    for i in range(A,min(B+1,n+1)):
        up=1
        down=1
        for j in range(1,i+1):
            up=up*(n-i+j)
            down=down*j
        cnt=cnt+(up//down)
else:
    n=c2[mi]
    r=c1[mi]
    up=1
    down=1
    for i in range(1,r+1):
        up=up*(n+1-i)
        down=down*i
    cnt=(up//down)
print(avg)
print(cnt)

Solution (Python):
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))






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

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

v.sort(reverse=True)

d = defaultdict(int)
use = defaultdict(int)

for i in range(N):
    d[v[i]] += 1
    if i < A:
        use[v[i]] += 1

if v[0] == v[A-1]:
    num = d[v[0]]
    ans = 0
    for i in range(A,min(B+1,num+1)):
        ans += linear_nCk(num,i)
    print(v[0])
    print(ans)
else:
    max_val = 0
    ans = 1
    for k,v in use.items():
        ans *= linear_nCk(d[k],v)
        max_val += k*v
    print(max_val/A)
    print(ans)

Solution (Python):


from copy import deepcopy
from fractions import Fraction

def main():
    n, a, b = map(int, input().split())
    v = list(map(int, input().split()))
    dp = [[0, 0] for i in range(n + 1)]
    dp[0] = [0, 1]
    for j in range(n):
        dppre = deepcopy(dp)
        for i in range(n):  
            vnew = dppre[i][0] + v[j]
            ways = dppre[i][1]
            if vnew > dp[i + 1][0]:
                dp[i + 1] = [vnew, ways]
            elif vnew == dp[i + 1][0]:
                dp[i + 1][1] += ways

    maxave = 0
    for i in range(a, b + 1):
        maxave = max(maxave, Fraction(dp[i][0], i))
    ways = 0
    for i in range(a, b + 1):
        if Fraction(dp[i][0], i) == maxave:
            ways += dp[i][1]
    print(float(maxave))
    print(ways)

if __name__ == "__main__":
    main()

Solution (Python):


from copy import deepcopy

def main():
    n, a, b = map(int, input().split())
    v = list(map(int, input().split()))
    dp = [[0, 0] for i in range(n + 1)]
    dp[0] = [0, 1]
    for j in range(n):
        dppre = deepcopy(dp)
        for i in range(n):  
            vnew = dppre[i][0] + v[j]
            ways = dppre[i][1]
            if vnew > dp[i + 1][0]:
                dp[i + 1] = [vnew, ways]
            elif vnew == dp[i + 1][0]:
                dp[i + 1][1] += ways

    maxave = 0.0
    for i in range(a, b + 1):
        maxave = max(maxave, dp[i][0] / i)
    ways = 0
    for i in range(a, b + 1):
        if dp[i][0] / i == maxave:
            ways += dp[i][1]
    print(maxave)
    print(ways)

if __name__ == "__main__":
    main()

Solution (Python):
from collections import Counter

C = [[0]*(61) for _ in range(61)]

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

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

ans = 0

for i in range(A, B+1):
    s = sum(v[:i])
    
    if s*A!=S*i:
        break
    
    cnt2 = Counter(v[:i])
    mark = v[:i][-1]
    ans += C[cnt1[mark]][cnt2[mark]]

print(ans)

Solution (Python):

import io
from scipy.misc import comb

nim, mike, kite = map(int, input().split())
V = list(map(int, input().split()))
V.sort(reverse=True)
print(sum(V[:mike]) / mike)
Ath_CNT = V.count(V[mike - 1])
V_than_Ath_CNT = len([v for v in V if v > V[mike - 1]])
if max(V) == V[mike - 1]:
    ans = 0
    for k in range(mike, kite + 1):
        ans += comb(Ath_CNT, k, 1)
else:
    ans = comb(Ath_CNT, mike - V_than_Ath_CNT, 1)
print(ans)

Solution (Python):
import math
def nCr(n,r):
    return (math.factorial(n)//(math.factorial(r)*math.factorial(n-r)))
N, A, B = map(int,input().split())
v = sorted(list(map(int,input().split())), reverse = True)
print(sum(v[:A])/A)

t = v[A-1]
m, u = 0, 0
for k in range(A):
    if v[k] == t:
        m += 1
for k in range(A,N):
    if v[k] == t:
        u += 1
if m == A:
    ans = 0
    for k in range(A,min(A+u+1,B+1)):
        ans += nCr(m+u,k)
    print(ans)
else:
    print(nCr(m+u,m))

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

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

Solution (Python):
import math
n, a, b = map(int, input().split())
v = list(map(int, input().split()))
v.sort(reverse=True)
c = 0
def comb(N, R):
	if N < R:
		return 0
	return math.factorial(N) // (math.factorial(N - R) * math.factorial(R))
if len(set(v[:a])) == 1:
	x = v[:a][0]
	d = 0
	for i in v:
		if i == x:
			d += 1
	for i in range(a,min(d+1,b+1)):
		c += comb(d,i)
	print (x)
	print (c)
else:
	x = v[:a][0]
	y = sorted(v[:a])
	av = sum(v[:a])/a
	z = y[0]
	d = 0
	for i in v:
		if i == z:
			d += 1
	e = 0
	for i in y:
		if i == z:
			e += 1
	c = comb(d,e)
	print (av)
	print (c)

Solution (Python):
INF = 10 ** 7
import sys
input = sys.stdin.readline
sys.setrecursionlimit(100000000)
dy = (-1,0,1,0)
dx = (0,1,0,-1)
from  heapq import heappop,heapify,heappush

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

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

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

    v.sort(reverse=True)
    tot = sum(v[:a])
    cnt = a

    ok = 0
    change = 0
    for i in range(a,n):
        if v[i] * cnt == tot:
            ok += 1
        elif v[i] == v[a - 1]:
            change += 1
    
    same = 1
    for i in range(a - 2,-1,-1):
        if v[i] == v[a - 1]:
            same += 1
    
    ans = 0
    if ok > 0:
        for i in range(same,b - a + same + 1):
            ans += nck(same + ok,i)
    elif change > 0:
        ans += nck(same + change,same)
    else:
        ans += 1

    print(tot/cnt)
    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
from collections import Counter
from math import factorial


N, A, B = map(int, input().split())
V = list(map(int, input().split()))
C = Counter(V)
keys = list(C.keys())
keys.sort(reverse=True)

if C[keys[0]] >= A:
    mean = keys[0]
    var = 0
    for i in range(A, min(B, C[keys[0]]) + 1):
        var += factorial(C[keys[0]]) // factorial(i) // factorial(C[keys[0]] - i)
else:
    cnt = 0
    total = 0
    var = 0
    for v in keys:
        if cnt + C[v] < A:
            cnt += C[v]
            total += v * C[v]
        else:
            total += v * (A - cnt)
            mean = total / A
            var += factorial(C[v]) // factorial((A - cnt)) // factorial(C[v] - (A - cnt))
            break

print(mean)
print(var)

Solution (Python):
class Factorial():
    def __init__(self, n, mod):
        self.mod = mod
        self.factorial = [0 for _ in range(n + 1)]
        self.inv = [0 for _ in range(n + 1)]
        self.factorial[0] = 1
        self.inv[0] = 1
        for i in range(n):
            self.factorial[i + 1] = self.factorial[i] * (i + 1) % mod
        self.inv[n] = pow(self.factorial[n], mod - 2, mod)
        for i in range(n)[::-1]:
            self.inv[i] = self.inv[i + 1] * (i + 1) % mod

    def fact(self, m):
        return self.factorial[m]

    def invfact(self, m):
        return self.inv[m]

    def perm(self, m, k):
        if m < k: return 0
        return self.factorial[m] * self.inv[m - k] % self.mod

    def comb(self, m, k):
        if m < k: return 0
        return self.factorial[m] * self.inv[k] * self.inv[m - k] % self.mod

    def hcomb(self, m, k):
        if m + k == 0: return 1
        return self.comb(m + k - 1, k)


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

V.sort(reverse=True)

F = Factorial(100, 100000000000000000039)

res = 0
num = 1
val = 0

for n in range(A, B + 1):
    v = 0
    for i in range(n):
        v += V[i]
    m = 0
    k = 0
    for i in range(N):
        if V[i] == V[n - 1]:
            m += 1
            if i > n - 1:
                k += 1
    if val * n < v * num:
        res = F.comb(m, k)
        num = n
        val = v
    elif val * n == v * num:
        res += F.comb(m, k)
    else:
        pass

print(val / num)
print(res)

Solution (Python):
from operator import mul
from functools import reduce
def sml_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()))
    v.sort()
    ave = 0
    for i in range(1, a+1):
        ave += v[n-i]
    ave /= a
    l, r = -1, -1
    target = v[n-a]
    for i in range(n):
        if v[i] == target:
            l = i
            break
    for i in reversed(range(n)):
        if v[i] == target:
            r = i
            break
    cnt = r-l+1
    high, low = min(cnt, r-(n-b)+1), r-(n-a)+1
    ans = sml_cmb(cnt, low)
    if v[n-a] == v[n-1]:
        for i in range(low+1, high+1):
            ans += sml_cmb(cnt, i)
    print(ave)
    print(ans)

if __name__ == "__main__":
    main()

Solution (Python):
N, A, B = map(int, input().split())
X = list(map(int, input().split()))
X.sort(reverse=True)
M = sum(X[i] for i in range(A)) / A
print(M)
cntl, cntr = 0, 0
if X[A-1] == X[N-1]:
  cntr = N - A
else:
  cntr = A-1
  while X[A-1] == X[cntr]:
    cntr += 1
  cntr -= A
if X[0] == X[A-1]:
  cntl = A
else:
  cntl = A-1
  while X[A-1] == X[cntl]:
    cntl -= 1
  cntl = A - 1 - cntl
F = 0
c = cntl + cntr
if cntl == A:
  t = 1
  for m in range(A):
    t *= c - m
    t //= m + 1
  for m in range(A, min(B, c)+1):
    F += t
    t *= c - m
    t //= m + 1
  print(F)
else:
  
  t = 1
  for m in range(cntl):
    t *= c - m
    t //= m + 1
  F = t
  print(F)

Solution (Python):
from collections import Counter
import math
def nCr(n, r):
    if n < r:
        return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

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

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

MAX = sum(values[:a]) / a
print(MAX)
e = a + 1
use_nums = []
for i in range(a, b + 1):
    v = sum(values[:i]) / i
    if v == MAX:
        use_nums.append(Counter(values[:i]))

cd = Counter(values)
ans = 0
for nums in use_nums:
    t = 1
    for k, v in nums.items():
        m = cd.get(k)
        t = t * nCr(m, v)
    ans += t
print(ans)

Solution (Python):
from math import factorial
def comb(n,r):
  if n-r<0:
    return 0
  return factorial(n)//(factorial(r)*factorial(n-r))
n,a,b=map(int,input().split())
v=list(map(int,input().split()))
mod=10**9+7
v.sort(reverse=True)
x=v[a-1]
cnt=0
s=0
for i in range(n):
  if x==v[i]:
    cnt+=1
  if x<v[i]:
    s=i+1
ans=0
print(sum(v[:a])/a)
if v[0]==v[a-1]:
  for i in range(a,min(cnt+1,b+1)):
    ans+=comb(cnt,i)
  print(ans)
else:
  ans=comb(cnt,a-s)
  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)
su=sum(v[:a])
avg=su/a
tot=0
inside=0
c=[ [0]*51 for _ in range(51)]
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]+c[i-1][j-1]
for i in range(n):
    if v[i]==v[a-1]:
        tot+=1
        if i<a:
            inside+=1
cnt=0
if inside==a:
    for i in range(a,b+1):
        cnt+=c[tot][i]
else:
    cnt+=c[tot][inside]
print(avg)
print(cnt)

Solution (Python):
import sys
from collections import *
import heapq
import math
import bisect
from itertools import permutations,accumulate,combinations,product
from fractions import gcd
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]

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

dp=[[[-1,0] for j in range(n+1)] for i in range(n+1)]

dp[0][0]=[0,1]

for i in range(n):
    for j in range(n):
        if dp[i][j][0]==-1:
            continue
        if dp[i][j][0]==dp[i+1][j][0]:
            dp[i+1][j][1]+=dp[i][j][1]

        if dp[i][j][0]>dp[i+1][j][0]:
            dp[i+1][j]=dp[i][j][:]
        
        if dp[i][j][0]+v[i]==dp[i+1][j+1][0]:
            dp[i+1][j+1][1]+=dp[i][j][1]
        
        if dp[i][j][0]+v[i]>dp[i+1][j+1][0]:
            dp[i+1][j+1][0]=dp[i][j][0]+v[i]
            dp[i+1][j+1][1]=dp[i][j][1]

ans=0
for i in range(a,b+1):
    ans=max(ans, dp[-1][i][0]/i)
print(ans)
cnt=0
for i in range(a,b+1):
    if ans==dp[-1][i][0]/i:
        cnt+=dp[-1][i][1]
print(cnt)

Solution (Python):

import math
import heapq
import bisect
import numpy as np
from collections import Counter, deque


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

ans = 0
for i in range(A,B+1):
    ans = max(sum(v[:i])/i, ans)

cnt = 0
for i in range(A,B+1):
    if sum(v[:i])/i == ans:
        n = v.count(v[i-1])
        r = i-v.index(v[i-1])
        cnt += math.factorial(n)//math.factorial(r)//math.factorial(n-r)

print(ans)
print(cnt)

Solution (Python):
from bisect import bisect_left, bisect_right
import sys
input = sys.stdin.readline

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

N, A, B = map(int, input().split())
v = list(map(int, input().split()))
v.sort()
ave = sum(v[N-A:]) / A
x = v[N-A]
comb = 0
if x == v[-1]:
    n = N - bisect_left(v, x)
    for k in range(A, min(B, n)+1):
        comb += combination(n, k)
else:
    n = bisect_right(v, x) - bisect_left(v, x)
    k = bisect_right(v, x) - (N - A)
    comb = combination(n, k)
print(ave)
print(comb)