import random

def test():
    num = 9
    prob_a = 0.6
    prob_b = 0.3
    prob_c = 0.1

    As = int(num*prob_a) * 'A'
    Bs = int(num*prob_b) * 'B'
    Cs = int(num*prob_c) * 'C'

    print('--',As,Bs,Cs)
    # create a list with 60 As, 30 Bs, and 10 Cs
    chars = list(As + Bs + Cs)

    random.shuffle(chars)

    print(chars,len(chars))

# _list = []


def lst_Covering(lst,num,istrue=True):
    index = 0
    while num>0:
        if istrue:
            lst[index] +=1
        else:
            print(num,index,lst[index])
            lst[index] -=1
        index+=1
        num= num-1
        if index >= len(lst):
            index = 0
    return lst

def test(b,count,res):
    print(b,count)
    res = []
    if len(b)-1>count:
        for i in b:
            if count>=i:
                res.append(round(i/count))
            else:
                res.append(1)
        _sum = sum(res)
        # print(res,_sum,count)
        if _sum > count:
            _temp = _sum - count
            # print(_temp)
            res = sorted(res,reverse = True)
            res = lst_Covering(res,_temp,False)
        elif _sum < count:
            _temp = count - _sum
            res = sorted(res)
            res = lst_Covering(res,_temp)
    return res

def test2(a,b):
    lst = []
    for i,v in enumerate(b):
        temp = [a[i]] * int(v)
        lst.extend(temp)
    random.shuffle(lst)
    return lst

a = [1,2,3,4]
b = [70,10,17,3]
count = 4
b = sorted(b,reverse=True)
res = []

res = test(b,count,res)
print(res)
if res:
    print(test2(a,res),len(test2(a,res)) - count)

