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



Sample input:
5 2 2
1 2 3 4 5


Sample output:
4.500000
1

Submission status: Runtime Error

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

V.sort(reverse=True)

mean = sum(V[:A]) / A
mean = float(mean)

print(mean)


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

def comb(n,a):
    return fact(n)//fact(a)//fact(n-a)

from collections import Counter
c = Counter(V)
n = c[V[0]]


if V[0] != V[A-1]:
    n = c[V[A-1]]
    if n > 1:
        idx = V.index[V[A-1]] 
        _A = A - idx
        print( comb( n, _A ) )
        # print(n); exit()
    else:
        print(1); exit()

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

    print( ans )

Submission status: Runtime Error

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

def fac(n):
  if n<= 1: return 1
  return n*fac(n-1)
def c (a,b): 
  if b==0: return 1
  return fac(a)//fac(b)//fac(a-b)


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

if V.count(V[0]) >= A:
  ans=0
  for i in range(A, min(B+1,V.count(V[A])+1))):
    ans+=c(V.count(V[A]),i)
else:
  lstcnt=A-1
  ans=V.count(V[A])
print(ans)

Submission status: Runtime Error

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

def fac(n):
  if n== 1: return 1
  return n*fac(n-1)
def c (a,b): 
  if b==0: return 1
  return fac(a)//fac(b)//fac(a-b)


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

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

Submission status: Runtime Error

Solution code:
aimport sys
import collections

def comb(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



def main():
    N, A, B = [int(_) for _ in sys.stdin.readline().split()]
    V = sorted([int(_) for _ in sys.stdin.readline().split()], reverse=True)
    D = collections.defaultdict(lambda: 0)
    ans = 0

    for v in V:
        D[v] += 1

    for C in range(A, B+1):
        if (sum(V[:C]) / C) == (sum(V[:A]) / A):
            ans += comb(D[V[C-1]], V[:C].count(V[C-1]))

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

main()

Submission status: Runtime Error

Solution code:
import sys

N, A, B = [int(_) for _ in sys.stdin.readline().split()]
V = sorted([int(_) for _ in sys.stdin.readline().split()], reverse=True)
D = collections.defaultdict(lambda: 0)
ans = 0

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

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

Submission status: Runtime Error

Solution code:
def main():
    N, A, B = [int(_) for _ in sys.stdin.readline().split()]
    V = sorted([int(_) for _ in sys.stdin.readline().split()], reverse=True)
    D = collections.defaultdict(lambda: 0)
    ans = 0
    
    for C in range(A, B+1):
        if (sum(V[:C]) / C) == (sum(V[:A]) / A):
            ans += comb(V.count(V[C-1]), V[:C].count(V[C-1]))

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

main()

Submission status: Runtime Error

Solution code:
def main():
    N, A, B = [int(_) for _ in sys.stdin.readline().split()]
    V = sorted([int(_) for _ in sys.stdin.readline().split()], reverse=True)
    D = collections.defaultdict(lambda: 0)
    ans = 0
    
    for C in range(A, B+1):
        if (sum(V[:C]) / C) == (sum(V[:A]) / A):
            ans += comb(V.count(V[C-1]), V[:C].count(V[C-1]))

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

main()

Submission status: Runtime Error

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

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

from collections import Counter
from math import factorial

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

v_count = Counter(v)
ans = 0
if v[0]==v[A-1]:
    n = v_count[v[A-1]]
    for r in range(A, B+1):
        if r>n: break
        ans += comb(n, r)
else:
    print(n, r)
    n = v_count[v[A-1]]
    select_count = Counter(v[:A])
    r = select_count[v[A-1]]
    ans = comb(n,r)
print(ans)

Submission status: Runtime Error

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

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

from collections import Counter
from math import factorial

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

v_count = Counter(v)
ans = 0
if v[0]==v[A-1]:
    n = v_count[v[A-1]]
    for r in range(A, B+1):
        ans += comb(n, r)
else:
    n = v_count[v[A-1]]
    select_count = Counter(v[:A])
    r = select_count[v[A-1]]
    ans = comb(n,r)
print(ans)

Submission status: Runtime Error

Solution code:
from collections import Counter
from scipy.special import comb

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


N, a, b = inpl()
array = inpl()
value = Counter(array)
array.sort(reverse=True)
ans = {}
sum_a = 0
kosuu = 0
last = -1
# print("koko")
for i, num in enumerate(array):
    # print(i, num)
    sum_a += num
    if last != num:
        kosuu = 1
        last = num
    else:
        kosuu += 1
    if a <= i+1 <= b:
        ans[sum_a/(i+1)] = ans.get(sum_a/(i+1), 0) + comb(value[num], kosuu)
print("{:.10f}".format(max(ans)))
print(int(ans[max(ans)]))

Submission status: Runtime Error

Solution code:
# coding:utf-8

import sys
import math
from collections import defaultdict

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


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


n, a, b = LI()
V = LI()
V.sort()
V.reverse()

cnt = defaultdict(int)
sum_v = 0
for i in range(a):
    sum_v += V[i]
    cnt[V[i]] += 1

# 大きい順にa個選ぶ場合，価値の平均値は最大となる
print(sum_v / a)

# a個選んだ中で一番価値の低いものがいくつ残っているか数える
min_v = V[i]
min_cnt = cnt[min_v]
for i in range(a, n):
    v = V[i]
    if v != min_v:
        break
    cnt[v] += 1

if cnt[min_v] == min_cnt:
    print(1)
    exit()
elif len(cnt.keys()) != 1:
    print(cnt[min_v])
    exit()
ans = 0
for i in range(b - a + 1):
    ans += comb(cnt[min_v], min_cnt + i)

print(ans)

Submission status: Runtime Error

Solution code:
# coding:utf-8

import sys
import math
from collections import defaultdict

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


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


n, a, b = LI()
V = LI()
V.sort()
V.reverse()

cnt = defaultdict(int)
sum_v = 0
for i in range(a):
    sum_v += V[i]
    cnt[V[i]] += 1

# 大きい順にa個選ぶ場合，価値の平均値は最大となる
print(sum_v / a)

# a個選んだ中で一番価値の低いものがいくつ残っているか数える
min_v = V[i]
min_cnt = cnt[min_v]
for i in range(a, n):
    v = V[i]
    if v != min_v:
        break
    cnt[v] += 1

if cnt[min_v] == min_cnt:
    print(1)
    exit()
elif len(cnt.keys()) != 1:
    print(comb(cnt[min_v], min_cnt))
    exit()
ans = 0
for i in range(b - a + 1):
    ans += comb(cnt[min_v], min_cnt + i)

print(ans)

Submission status: Runtime Error

Solution code:
def combination(n, r):  # nCrを求める
    r = min(n - r, r)
    result = 1
    for i in range(n, n - r, -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)
ans1 = v[:a]/a
num1 = v[:a].count(v[a-1])
num2 = v[a:n].count(v[a-1])

ans2 = 0
if v[0] == v[a]:
    for i in range(a,n):
        if v[i] == v[a-1]:
            idx = i + 1
    for i in range(a,min(b,idx) + 1):
        ans2 += combination(num1 + num2, i)
else:
    ans2 = combination(num1 + num2,num1)
    
print(ans1)
print(ans2)

Submission status: Runtime Error

Solution code:
import math
N, A, B = map(int, input().split())
nums = list(map(int, input().split()))
arg = 0
num = 0
j = N - A

nums.sort()
for i in range(A):
    arg += nums[N - i - 1]
arg = arg/A

if nums[j] == nums[N-1]:
    re = nums.count(nums[j])
    for i in range(A, B+1):
        num = num + math.factorial(re) / math.factorial(i) / math.factorial(re-i)
else:    
    num = nums.count(nums[j])
    
print(arg)    
print(int(num))

Submission status: Runtime Error

Solution code:
#!/usr/bin/python3
# -*- coding: utf-8 -*-


"""
https://beta.atcoder.jp/contests/abc057/tasks/abc57_1
"""

import sys
import math
from inspect import currentframe

def debug(*args):
    names = {id(v):k for k,v in currentframe().f_back.f_locals.items()}
    print(', '.join(names.get(id(arg),'???')+' = '+repr(arg) for arg in args), file=sys.stderr)


u'''calc comibination by pascal's_triangle'''
def combination(n, k):
    return pascal(k + 1, n + 1)

pascal_memo = {}

def pascal(i, j):
    if i == 1 or i == j:
        return 1
    else:
        if (i, j) not in pascal_memo.keys():
            pascal_memo[(i, j)] = pascal(i - 1, j - 1) + pascal(i, j - 1)
        return pascal_memo[(i, j)]

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

v.sort(reverse=True)
max_combi = v[:A]
max_mean = sum(max_combi) / A

print(max_mean)

# 一番小さい数字を特定
max_combi_min = min(max_combi)

# 一番小さい数字がvにいくつ含まえれるか
in_v = v.count(max_combi_min)
in_use = max_combi.count(max_combi_min)

#in_useからin_vの場合の数
if max_combi[0] != max_combi[-1]:
    print(int(math.factorial(in_v) / (math.factorial(in_use) * math.factorial(in_v - in_use))))
else:
    combi_num = 0
    for i in range(A, B + 1):
        combi_num += combination(in_v, i)
    print(combi_num)

Submission status: Runtime Error

Solution code:
N,A,B=map(int,input().split())
lst=list(map(int,input().split()))
lst.sort()
a=lst[-A:]
print(sum(a)/A)
b=lst.count(a[0])
c=lst.count(a[0])
print(b!/(c!*(b-c)!))

Submission status: Runtime Error

Solution code:
def fact(n):
    if n == 0:
        return 1
    else:
        return n*fact(n-1)
def conb(n,r):
    return fact(n)//(fact(r)*fact(n-r))

N,A,B = map(int,input().split())
v = list(map(int,input().split()))
v.sort()
v.reverse()
d_all = {}
for i in range(N):
    if v[i] not in d_all:
        d_all[v[i]] = 0
    d_all[v[i]] += 1
import numpy as np
avg = np.cumsum(np.array(v))
for i in range(N):
    avg[i]=int(avg[i])/(i+1)
avg = avg[A-1:B]
ans = max(avg)
print(ans)
indices = np.where(avg==ans)[0]
ans = 0
for index in indices:
    d_use = {}
    use = A + index
    v_use = v[:use]
    choose=1
    for item in v_use:
        if item not in d_use:
            d_use[item] = 0
        d_use[item] += 1
    for item in d_use:
        choose *= conv(d_all[item],d_use[item])
    ans += choose

print(ans)

Submission status: Runtime Error

Solution code:
def inpl(): return [int(i) for i in input().split()]

N, A, B = inpl()
V = inpl()
V = list(reversed(sorted(V)))
x1 = N-1
x2 = 0
for i in range(N):
    if V[i] == V[A]:
        x1 = min(x1,i)
        x2 = max(x2,i)

print(sum(V[0:A])/A)
from scipy.special import comb
ans = 0
if x1 == 0:
    for l in range(min(B-1,x2)-A+2):
        ans += comb(x2-x1+1,l-x1+1, exact=True)
    print(ans)
else:
    print(comb(x2-x1+1,A-x1+1, exact=True))

Submission status: Runtime Error

Solution code:
from collections import Counter
from itertools import combinations

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

v.sort(reverse=True)
v_cum = []
num = 0
for i in range(n):
    num += v[i]
    v_cum.append(num)

print(v_cum[a-1]/a)

if a == n:
    print(1)
else:
    if v[a-1] == v[a]:
        num = v[a-1]
        cf = Counter(v[:a])
        cb = Counter(v[a:])
        n_cf = cf[num]
        n_cb = cb[num]
        if cf[num] != a:
            print(combinations(n_cf+n_cb, n_cf))
        else:
            ans = 0
            for k in range(a, a+n_cb+1):
                ans += combinations(a+n_cb, k)
            print(ans)
    else:
        print(1)

Submission status: Runtime Error

Solution code:
def ABC057D():

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

    anslist = []
    for i in range(A, B + 1):

        anslist.append([sum(v[0:i]) / i, i, v[i - 1]])
    anslist.sort()
    anslist = anslist[::-1]
    ans = anslist[0][0]
    key = anslist[0][2]
    long = anslist[0][1]
    print(ans)
    for i in range(1, len(anslist)):
        if anslist[i][0] == anslist[i - 1][0]:
            ans = anslist[i][0]
            key = anslist[i][2]
            long = anslist[i][1]
        else:
            break
    #print(anslist)
    #print(ans, key, long)
    cnt = 0
    for i in v:
        if i == key:
            cnt += 1

    c = 0
    for i in v[:long]:
        #print(i)
        if i == key:
            c += 1
    #print(c, long)
    ans = 0
    if c == long:
        for i in range(A,  min(B + 1, cnt + 1)):
            ans += cc(cnt, i)
    else:
        ans = cc(cnt, c)
    #print(anslist)
    #print(cnt, c, long)
    print(ans)
ABC057D()

Submission status: Runtime Error

Solution code:
import sys
stdin = sys.stdin

def li(): return [int(x) for x in stdin.readline().split()]
def li_(): return [int(x)-1 for x in stdin.readline().split()]
def lf(): return [float(x) for x in stdin.readline().split()]
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(ns())
def nf(): return float(ns())

# nの逆元のリスト
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
       
# nの階乗のリスト
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

# nの階乗の逆元のリスト
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

from itertools import accumulate
from collections import Counter

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

v.sort(reverse=True)
v_cum = list(accumulate(v))

ans_cand = []

# 貪欲に最大値を選ぶ
for i in range(a,b+1):
    ans_cand.append(v_cum[i-1] / i)
    
ans = max(ans_cand)
opt_is = []

while ans in ans_cand:
    opt_is.append(a + ans_cand.index(ans))
    ans_cand[ans_cand.index(int(ans))] = 0
    

cnt_v = Counter(v)

# 貪欲最大が何通りできるか考える
MOD = 46116646144580591
inv = inv_mod(n, MOD)
fac = fact(n, MOD)
facInv = fact_inv(n,inv, MOD)

pat = 0

for opt_i in opt_is:
    opt_set = v[:opt_i]
    cnt_opt = Counter(opt_set)
    
    temp = 1
    
    for key_op, val_op in cnt_opt.items():
        temp *= nCr(cnt_v[key_op], int(val_op), MOD, fac, facInv)
        
    pat += temp
        
print(ans)
print(pat)

Submission status: Runtime Error

Solution code:
import sys
stdin = sys.stdin

def li(): return [int(x) for x in stdin.readline().split()]
def li_(): return [int(x)-1 for x in stdin.readline().split()]
def lf(): return [float(x) for x in stdin.readline().split()]
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(ns())
def nf(): return float(ns())

# nの逆元のリスト
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
       
# nの階乗のリスト
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

# nの階乗の逆元のリスト
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

from itertools import accumulate
from collections import Counter

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

v.sort(reverse=True)
v_cum = list(accumulate(v))

ans_cand = []

# 貪欲に最大値を選ぶ
for i in range(a,b+1):
    ans_cand.append(v_cum[i-1] / i)
    
ans = max(ans_cand)
opt_is = []

while ans in ans_cand:
    opt_is.append(a + ans_cand.index(ans))
    ans_cand[ans_cand.index(int(ans))] = 0
    

cnt_v = Counter(v)

# 貪欲最大が何通りできるか考える
MOD = 10**18+1
inv = inv_mod(n, MOD)
fac = fact(n, MOD)
facInv = fact_inv(n,inv, MOD)

pat = 0

for opt_i in opt_is:
    opt_set = v[:opt_i]
    cnt_opt = Counter(opt_set)
    
    temp = 1
    
    for key_op, val_op in cnt_opt.items():
        temp *= nCr(cnt_v[key_op], int(val_op), MOD, fac, facInv)
        
    pat += temp
        
print(ans)
print(pat)

Submission status: Runtime Error

Solution code:
n,a,b = map(int,input().split())
vs = sorted([int(v) for v in input().split()],reverse=True)
print(sum(vs[:a])/a)
binom = [1]
for k in range(vs.count(vs[a-1])):
    binom = [x+y for (x, y) in zip(binom+[0],[0]+binom)]
if vs[a-1] == vs[0]:
    print(sum(binom[a:b+1]))
else:
    print(binom[vs.index(vs[a-1])])

Submission status: Runtime Error

Solution code:
import sys
import math
import collections
import itertools
import array
import inspect
from scipy.special import comb

# Set max recursion limit
sys.setrecursionlimit(1000000)


# Debug output
def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))


# Binary converter
def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in input().split()]


def gcd(n, m):
    if n % m == 0:
        return m
    else:
        return gcd(m, n % m)


def gcd_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = gcd(v, L[i])

    return v


def lcm(n, m):
    return (n * m) // gcd(n, m)


def lcm_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = lcm(v, L[i])

    return v


# Width First Search (+ Distance)
def wfs_d(D, N, K):
    """
    D: 隣接行列(距離付き)
    N: ノード数
    K: 始点ノード
    """

    dfk = [-1] * (N + 1)
    dfk[K] = 0

    cps = [(K, 0)]
    r = [False] * (N + 1)
    r[K] = True
    while len(cps) != 0:
        n_cps = []
        for cp, cd in cps:
            for i, dfcp in enumerate(D[cp]):
                if dfcp != -1 and not r[i]:
                    dfk[i] = cd + dfcp
                    n_cps.append((i, cd + dfcp))
                    r[i] = True

        cps = n_cps[:]

    return dfk


# Depth First Search (+Distance)
def dfs_d(v, pre, dist):
    """
    v:  現在のノード
    pre: １つ前のノード
    dist: 現在の距離

    以下は別途用意する
    D: 隣接リスト(行列ではない)
    D_dfs_d: dfs_d関数で用いる，始点ノードから見た距離リスト
    """

    global D
    global D_dfs_d

    D_dfs_d[v] = dist

    for next_v, d in D[v]:
        if next_v != pre:
            dfs_d(next_v, v, dist + d)

    return


def sigma(N):
    ans = 0
    for i in range(1, N + 1):
        ans += i
    return ans


class Combination:
    def __init__(self, n, mod=10**100):

        g1 = [1, 1]
        g2 = [1, 1]
        inverse = [0, 1]
        for i in range(2, n + 1):
            g1.append((g1[-1] * i) % mod)
            inverse.append((-inverse[mod % i] * (mod // i)) % mod)
            g2.append((g2[-1] * inverse[-1]) % mod)
        self.MOD = mod
        self.N = n
        self.g1 = g1
        self.g2 = g2
        self.inverse = inverse

    def __call__(self, n, r):
        if (r < 0 or r > n):
            return 0
        r = min(r, n - r)
        return self.g1[n] * self.g2[r] * self.g2[n - r] % self.MOD


# --------------------------------------------

dp = None


def main():
    N, A, B = li_input()
    V = li_input()

    V.sort(reverse=True)

    maxavg = sum(V[:A]) / A
    V_ = V[:A]

    if V_[0] == V_[-1]:
        n = V.count(V_[0])

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

        print(maxavg)
        print(int(ans))

    else:
        n = V.count(V_[-1])
        r = V_.count(V_[-1])

        ans = comb(n, r)

        print(maxavg)
        print(int(ans))


main()

Submission status: Runtime Error

Solution code:
poo=input().split()
shoop=[1]
lop=[]
for i in range(int(poo[0])):
    lop.append(int(input()))
    shoop.append(shoop[i]*(i+1))
jop=lop.copy()
j=int(poo[1])
staph=int(poo[2])
joop=0
z=0
zop=jop.count(max(jop))
while z<j:
    joop+=max(lop)
    lop.remove(max(lop))
    z+=1
print(joop/j)
jum=1
shazam=0
while j>=zop:
    shazam+=zop
    j=j-zop
    for i in range(zop):
        jop.remove(max(jop))
    zop=jop.count(max(jop))
if zop>j and j>0:
    jum=0
    som=int(poo[1])
    while min(staph,shazam+zop)>=som:
        while j<=som:
            jum+=shoop[zop]//(shoop[j]*shoop[zop-j])
            j+=1
        som+=1
print(jum)

Submission status: Runtime Error

Solution code:
poo=input().split()
lop=[]
for i in range(int(poo[0])):
    lop.append(int(input()))
j=int(poo[1])
joop=0
z=0
while z<j:
    joop+=max(jop)
    jop.remove(max(jop))
    z+=1
print(loo/j)
sum=0
zop=lop.count(max(lop))
while j>zop:
    prod=1
    sop=0
    while sop<zop:
        prod=prod*(zop-sop)
        sop+=1
    sum+=prod
    j=j-zop
    for i in range(zop):
        lop.remove(max(lop))
    zop=lop.count(max(lop))
if lop.count(max(lop))>=j and j>0:
    while joop<j:
        joop+=1
        sop=0
        prod=1
        while sop<j:
            prod=prod*(lop.count(max(lop))-sop)
            sop+=1
        sum+=prod
print(sum)

Submission status: Runtime Error

Solution code:
poo=input().split()
lop=[]
for i in range(int(poo[0])):
    lop.append(int(input()))
j=int(poo[1])
joop=0
z=0
while z<j:
    loo+=max(jop)
    jop.remove(max(jop))
    z+=1
print(loo/j)
sum=0
zop=lop.count(max(lop))
while j>zop:
    prod=1
    sop=0
    while sop<zop:
        prod=prod*(zop-sop)
        sop+=1
    sum+=prod
    j=j-zop
    for i in range(zop):
        lop.remove(max(lop))
    zop=lop.count(max(lop))
if lop.count(max(lop))>=j and j>0:
    while joop<j:
        joop+=1
        sop=0
        prod=1
        while sop<j:
            prod=prod*(lop.count(max(lop))-sop)
            sop+=1
        sum+=prod
print(sum)

Submission status: Runtime Error

Solution code:
b=int(x[2])
v=input().split()
x=0
while x<n:
    v[x]=int(v[x])
    x+=1
v.sort()
ave=0
for i in range(a):
    ave+=v[-i-1]
print(ave/a)
up=1
down=1
ans=0
x=v[-a:].count(v[-a])
y=v.count(v[-a])
if v[-1]!=v[-a]:
    
    for i in range(1,y+1):
        up*=i
    for i in range(1,x):
        down*=i
    for i  in range(1, y-x+1):
        down*=i
    print(up//down)
else:
    ii=a
    while ii<=b and v[-ii]==v[-1]:
        up=1
        down=1
        for i in range(1,y+1):
            up*=i
        for i in range(1,ii+1):
            down*=i
        for i  in range(1, y-ii+1):
            down*=i
        ans+=(up//down)
        ii+=1
    print(ans)

Submission status: Runtime Error

Solution code:
x=input().split()
n=int(x[0])
a=int(x[1])
b=int(x[2])
v=input().split()
x=0
while x<n:
    v[x]=int(v[x])
    x+=1
v.sort()
ave=0
for i in range(a):
    ave+=v[-i-1]
print(ave/a)
up=1
down=1
ans=0
x=v[-a:].count(v[-a])
y=v.count(v[-a])
if v[-1]!=v[-a]:
    
    for i in range(1,y+1):
        up*=i
    for i in range(1,x):
        down*=i
    for i  in range(1, y-x+1):
        down*=i
    print(up//down)
else:
    ii=a
    while v[-ii]==v[-1] and ii<=b:
        up=1
        down=1
        for i in range(1,y+1):
            up*=i
        for i in range(1,ii+1):
            down*=i
        for i  in range(1, y-ii+1):
            down*=i
        ans+=(up//down)
        ii+=1
    print(ans)

Submission status: Runtime Error

Solution code:
x=input().split()
n=int(x[0])
a=int(x[1])
b=int(x[2])
v=input().split()
x=0
while x<n:
    v[x]=int(v[x])
    x+=1
v.sort()
ave=0
for i in range(a):
    ave+=v[-i-1]
print(ave/a)
up=1
down=1
ans=0
x=v[-a:].count(v[-a])
y=v.count(v[-a])
if v[-1]!=v[-a]:
    
    for i in range(2,y+1):
        up*=i
    for i in range(2,x):
        down*=i
    for i  in range(2, y-x+1):
        down*=i
    print(up//down)
else:
    ii=a
    while v[-ii]==v[-1] and ii<=b:
        up=1
        down=1
        for i in range(1,y+1):
            up*=i
        for i in range(1,ii+1):
            down*=i
        for i  in range(1, y-ii+1):
            down*=i
        ans+=(up//down)
        ii+=1
    print(ans)

Submission status: Runtime Error

Solution code:
n=int(x[0])
a=int(x[1])
b=int(x[2])
v=input().split()
x=0
while x<n:
    v[x]=int(v[x])
    x+=1
v.sort()
ave=0
for i in range(a):
    ave+=v[-i-1]
print(ave/a)
up=1
down=1
ans=0
x=v[-a:].count(v[-a])
y=v.count(v[-a])
if v[-1]!=v[-a]:
    
    for i in range(2,y+1):
        up*=i
    for i in range(2,x):
        down*=i
    for i  in range(2, y-x+1):
        down*=i
    print(up//down)
else:
    i=a
    while v[-i]==v[-1] and i!=b:
        for i in range(2,y+1):
            up*=i
        for i in range(2,i+1):
            down*=i
        for i  in range(2, y-i+1):
            down*=i
        ans+=(up//down)
        i+=1
    print(ans)

Submission status: Runtime Error

Solution code:
import math
from collections import Counter
def f(a,b):
    return math.factorial(a) // (math.factorial(a - b) * math.factorial(b))

n,a,b=map(int, input().split())
v=list(map(int, input().split()))
v.sort(reverse=True)
c=Counter(v)
count=0
if a==1 or v[0]==v[a-1]:
    for i in range(a,min(b,c[v[0]])+1):
        count+=f(min(b,c[v[0]]),i)
    print(v[0])
    print(count)
else: 
    print(sum(v[:a])/a)
    print(f(c[v[a]],a-c[v[0]]))

Submission status: Runtime Error

Solution code:
# from math import inf
inf = 10**50

N, M = map(int, input().split())
edges = []
for j in range(M):
    edges.append(list(map(int, input().split())))

d = [0] + ([-inf]*(N-1))
pred = [None] * N

for i in range(N-1):
    for j in range(M):
        u = edges[j][0]-1
        v = edges[j][1]-1
        w = edges[j][2]
        if (d[v] < d[u] + w) and (d[u] != -inf):
            d[v] = d[u] + w
            pred[v] = u

positive_loop = False
for i in range(N):
    for j in range(M):
        u = edges[j][0]-1
        v = edges[j][1]-1
        w = edges[j][2]
        if (v == N-1) and (d[u] + w > d[v]) and (d[u] != -inf):
            positive_loop = True
            break
    if positive_loop:
        break

if positive_loop:
    print("inf")
else:
    print(d[N-1])

Submission status: Runtime Error

Solution code:
from math import factorial

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

n1 = v.count(v[a - 1])
n2 = v[:a].count(v[:a][a - 1])

print(sum(v[:a]) / a)
if len(set(v[:a])) != 1:
	if n1 == n2:
		print(1)
	else:
		print(int(factorial(n1) / (factorial(n2) * factorial(n1 - n2))))
else:
	ans = 0
	if n1 == 1:
		print(1)
	else:
		for i in range(a, min(n1, b + 1)):
			if 
			ans += int(factorial(n1) / (factorial(i) * factorial(n1 - i)))
		print(int(ans))

Submission status: Runtime Error

Solution code:
from math import factorial

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

n1 = v.count(v[a - 1])
n2 = v[:a].count(v[:a][a - 1])

print(sum(v[:a]) / a)
if len(set(v[:a])) != 1:
	if n1 == n2:
		print(1)
	else:
		print(int(factorial(n1) / (factorial(n2) * factorial(n1 - n2))))
else:
	ans = 0
	if n1 == 1:
		print(1)
	else:
		for i in range(a, b + 1):
			ans += int(factorial(n1) / (factorial(i) * factorial(n1 - i)))
		print(int(ans))

Submission status: Runtime Error

Solution code:
from math import factorial

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

n1 = v.count(v[a - 1])
n2 = v[:a].count(v[:a][a - 1])

print(sum(v[:a]) / a)
if len(set(v[:a])) != 1:
	print(int(factorial(n1) / (factorial(n2) * factorial(n1 - n2))))
else:
	ans = 0
	for i in range(a, b + 1):
		ans += int(factorial(n1) / (factorial(i) * factorial(n1 - i)))
	print(int(ans))

Submission status: Runtime Error

Solution code:
from fractions import factorial

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

n1 = v.count(v[a - 1])
n2 = v[:a].count(v[:a][a - 1])

print(sum(v[:a]) / a)
if len(set(v[:a])) != 1:
	print(int(factorial(n1) / (factorial(n2) * factorial(n1 - n2))))
else:
	ans = 0
	for i in range(a, b + 1):
		ans += int(factorial(n1) / (factorial(i) * factorial(n1 - i)))
	print(int(ans))

Submission status: Runtime Error

Solution code:
import math

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

n1 = v.count(v[a - 1])
n2 = v[:a].count(v[:a][a - 1])

print(sum(v[:a]) / a)
if len(set(v[:a])) != 1:
	print(int(math.factorial(n1) / (math.factorial(n2) * math.factorial(n1 - n2))))
else:
	ans = 0
	for i in range(a, b + 1):
		ans += int(math.factorial(n1) / (math.factorial(i) * math.factorial(n1 - i)))
	print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np
import scipy.special as ss
N, A, B = map(int, input().split())
v = list(map(int, input().split()))
v.sort(reverse=True)
v = np.array(v)
##print(v)
ansarray = v[0:A]
##print(ansarray)
ave = np.mean(ansarray)
print(float(ave))
mi = min(ansarray)
ma = max(ansarray)
biggerarray = v[v>mi]
m = len(biggerarray)
numminarray = v[v==mi]
a = len(numminarray)
##print(nummin)
##print(num_kouho)
ans = 0
if ma == mi:
    if m+a <= B:
        for i in range(A-m,a+1):
            ans+=ss.comb(a,i)
    else:
        for i in range(A-m,B-m+1):
            ans+=ss.comb(a,i)

else:
    ans = a
#print('a=',a)
#print('m=',m)
print(int(ans))