Problem:


Score : 600 points

Problem Statement

Takahashi has N cards. The i-th of these cards has an integer A_i written on it.

Takahashi will choose an integer K, and then repeat the following operation some number of times:

Choose exactly K cards such that the integers written on them are all different, and eat those cards. (The eaten cards disappear.)

For each K = 1,2, \ldots, N, find the maximum number of times Takahashi can do the operation.

Constraints

 1 \le N \le 3 \times 10^5 

 1 \le A_i \le N 

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 \ldots A_N

Output

Print N integers.
The t-th (1 \le t \le N) of them should be the answer for the case K=t.

Sample Input 1

3
2 1 2

Sample Output 1

3
1
0

For K = 1, we can do the operation as follows:

Choose the first card to eat.

Choose the second card to eat.

Choose the third card to eat.

For K = 2, we can do the operation as follows:

Choose the first and second cards to eat.

For K = 3, we cannot do the operation at all. Note that we cannot choose the first and third cards at the same time.

Sample Input 2

5
1 2 3 4 5

Sample Output 2

5
2
1
1
1

Sample Input 3

4
1 3 3 3

Sample Output 3

4
1
0
0



Sample input:
3
2 1 2


Sample output:
3
1
0

Submission status: Time Limit Exceeded

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

C = [0] * N
D = [0] * (N + 1)
for a in A:
    C[a-1] += 1
    D[C[a-1]] += 1

S = [0] * (N + 1)
for i in range(N):
    S[i+1] = S[i] + D[i+1]

for K in range(1,N+1):
    l = 0
    r = N + 1
    while(r-l>1):
        m = int((l+r)/2)
        if S[m] >= K * m:
            l = m
        else:
            r = m
    print(l)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


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

from collections import Counter
c = Counter(a)
a = list(c.values())
a.sort(reverse=True)
l = len(a)
cum = [None]*l
v = a[-1]
for i in range(l-1, -1, -1):
    cum[i] = v
    v += a[i-1]
ans = [None]*n
ans[0] = n
for k in range(2,n+1):
    if k>l:
        val = 0
    else:
        s = cum[k-1]
        val = 0
        ind = 1
        while k-(ind+1)>=0 and (s//ind)>(a[k-(ind+1)]-val):
            aa = a[k-(ind+1)] - val
            val += aa
            s -= aa*ind
            ind += 1
        else:
            val += s//ind
            
    ans[k-1] = val
write("\n".join(map(str, ans)))

Submission status: Time Limit Exceeded

Solution code:
import collections
import heapq

def main():
    N = int(input())
    A = list(map(int, input().split()))
    # print(N, A)
    # 整数ごとに何枚あるか数える
    c = collections.Counter(A)
    v = [-x for x in c.values()]
    # print(c, v)

    _max = len(v)
    ans = [N]
    for K in range(2, N+1):
        # Kがカードの種類より大きい場合は1回も食べれない
        if K > _max:
            ans.append(0)
            continue
        q = v[:]
        heapq.heapify(q)

        cnt = 0
        while len(q) >= K:
            eat = []
            # 枚数の多い順にK個取り出す
            for k in range(K):
                eat.append(heapq.heappop(q))
            cnt += 1
            for e in eat:
                if e < -1:
                    heapq.heappush(q, e + 1)
        ans.append(cnt)
    
    print(*ans, sep='\n')

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import bisect

n = int(input())
k = sorted(map(int, input().split()))

hist = []
count = 0
for i in range(n):
    count += 1
    if i == n - 1 or k[i] != k[i + 1]:
        hist.append(count)
        count = 0
hist.sort()

sumh = [0]
for i in range(len(hist)):
    sumh.append(sumh[-1] + hist[i])

def ok(h, d):
    i = bisect.bisect_left(hist, h)
    s = sumh[i] + h * (len(hist) - i)
    return s >= h * d

def binary_search(d):
    lo, hi = 0, 10 ** 10
    while hi - lo > 1:
        mid = (lo + hi) // 2
        if ok(mid, d):
            lo = mid
        else:
            hi = mid
    return lo

for d in range(1, n + 1):
    print(binary_search(d))

Submission status: Time Limit Exceeded

Solution code:
def main():
    from sys import stdin
    input = stdin.readline
    from collections import Counter as ct
    from bisect import bisect_left as bl

    n = int(input())
    max_a = sorted(ct(list(map(int, input().split()))).values())
    now_a = [i for i in max_a]
    m = len(max_a)
    cnt = m
    ans = 0
    ans_list = [0]*(n-m)

    for use in range(m, 1, -1):
        rest = ans
        nex = now_a[0]
        while rest:
            val = nex
            start = bl(now_a, val+1)
            nex += 1
            q = bl(max_a, now_a[start-1]+1)-1
            flag = 0
            if now_a[start-1] == 0:
                flag = 1
            for i in range(start-1, max(-1, start-1-rest, q), -1):
                cnt += flag
                now_a[i] += 1
                rest -= 1
            if start != m:
                nex = now_a[start]
        while cnt >= use:
            ans += 1
            rest = use
            nex = now_a[-1]
            end = m
            while rest:
                val = nex
                start = bl(now_a, val)
                if start != 0:
                    nex = now_a[start-1]
                flag = 0
                if now_a[start] == 1:
                    flag = 1
                end = min(end, bl(now_a, val+1), start+rest)
                for i in range(start, end):
                    cnt -= flag
                    now_a[i] -= 1
                    rest -= 1
                end = start
        ans_list.append(ans)
    print(n)
    for i in ans_list[::-1]:
        print(i)


main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    from collections import Counter as ct
    from bisect import bisect_left as bl

    n = int(input())
    max_a = sorted(ct(list(map(int, input().split()))).values())
    now_a = [i for i in max_a]
    m = len(max_a)
    cnt = m
    ans = 0
    ans_list = [0]*(n-m)

    for use in range(m, 1, -1):
        rest = ans
        nex = now_a[0]
        while rest:
            val = nex
            start = bl(now_a, val+1)
            nex += 1
            q = bl(max_a, now_a[start-1]+1)-1
            flag = 0
            if now_a[start-1] == 0:
                flag = 1
            for i in range(start-1, max(-1, start-1-rest, q), -1):
                cnt += flag
                now_a[i] += 1
                rest -= 1
            if start != m:
                nex = now_a[start]
        while cnt >= use:
            ans += 1
            rest = use
            nex = now_a[-1]
            end = m
            while rest:
                val = nex
                start = bl(now_a, val)
                if start != 0:
                    nex = now_a[start-1]
                flag = 0
                if now_a[start] == 1:
                    flag = 1
                end = min(end, bl(now_a, val+1), start+rest)
                for i in range(start, end):
                    cnt -= flag
                    now_a[i] -= 1
                    rest -= 1
                end = start
        ans_list.append(ans)
    print(n)
    for i in ans_list[::-1]:
        print(i)


main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    from collections import Counter as ct
    from bisect import bisect_left as bl

    n = int(input())
    max_a = sorted(ct(list(map(int, input().split()))).values())
    now_a = [i for i in max_a]
    m = len(max_a)
    cnt = m
    ans = 0
    ans_list = [0]*(n-m)

    for use in range(m, 1, -1):
        rest = ans
        nex = now_a[0]
        while rest:
            val = nex
            start = bl(now_a, val+1)
            nex += 1
            p = now_a[start-1]
            q = bl(max_a, p+1)-1
            for i in range(start-1, max(-1, start-1-rest, q), -1):
                if now_a[i] == 0:
                    cnt += 1
                now_a[i] += 1
                rest -= 1
            if start != m:
                nex = now_a[start]
        while cnt >= use:
            ans += 1
            rest = use
            nex = now_a[-1]
            end = m
            while rest:
                val = nex
                start = bl(now_a, val)
                if start != 0:
                    nex = now_a[start-1]
                flag = 0
                if now_a[start] == 1:
                    flag = 1
                end = min(end, bl(now_a, val+1), start+rest)
                for i in range(start, end):
                    cnt -= flag
                    now_a[i] -= 1
                    rest -= 1
                end = start
        ans_list.append(ans)
    print(n)
    for i in ans_list[::-1]:
        print(i)


main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    from collections import Counter as ct
    from bisect import bisect_left as bl

    n = int(input())
    max_a = sorted(ct(list(map(int, input().split()))).values())
    now_a = [i for i in max_a]
    m = len(max_a)
    cnt = m
    ans = 0
    ans_list = [0]*(n-m)

    for use in range(m, 1, -1):
        rest = ans
        nex = now_a[0]
        while rest:
            val = nex
            start = bl(now_a, val+1)
            nex += 1
            for i in range(start-1, max(-1, start-1-rest), -1):
                if now_a[i] == max_a[i]:
                    if start != m:
                        nex = now_a[start]
                    break
                elif now_a[i] == 0:
                    cnt += 1
                now_a[i] += 1
                rest -= 1
        while cnt >= use:
            ans += 1
            rest = use
            nex = now_a[-1]
            end = m
            while rest:
                val = nex
                start = bl(now_a, val)
                if start != 0:
                    nex = now_a[start-1]
                flag = 0
                if now_a[start] == 1:
                    flag = 1
                end = min(end, bl(now_a, val+1), start+rest)
                for i in range(start, end):
                    cnt -= flag
                    now_a[i] -= 1
                    rest -= 1
                end = start
        ans_list.append(ans)
    print(n)
    for i in ans_list[::-1]:
        print(i)


main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    from collections import Counter as ct
    from bisect import bisect_left as bl

    n = int(input())
    max_a = sorted(ct(list(map(int, input().split()))).values())
    now_a = [i for i in max_a]
    m = len(max_a)
    cnt = m
    ans = 0
    ans_list = [0]*(n-m)

    for use in range(m, 1, -1):
        rest = ans
        nex = now_a[0]
        while rest:
            val = nex
            start = bl(now_a, val+1)
            nex += 1
            for i in range(start-1, max(-1, start-1-rest), -1):
                if now_a[i] == max_a[i]:
                    if start != m:
                        nex = now_a[start]
                    break
                elif now_a[i] == 0:
                    cnt += 1
                now_a[i] += 1
                rest -= 1
        while cnt >= use:
            ans += 1
            rest = use
            nex = now_a[-1]
            end = m
            while rest:
                val = nex
                start = bl(now_a, val)
                if start != 0:
                    nex = now_a[start-1]
                for i in range(start, min(end, start+rest)):
                    if now_a[i] > val:
                        break
                    elif now_a[i] == 1:
                        cnt -= 1
                    now_a[i] -= 1
                    rest -= 1
                end = start
        ans_list.append(ans)
    print(n)
    for i in ans_list[::-1]:
        print(i)


main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    from collections import Counter as ct
    from bisect import bisect_left as bl

    n = int(input())
    max_a = sorted(ct(list(map(int, input().split()))).values())
    now_a = [i for i in max_a]
    m = len(max_a)
    cnt = m
    ans = 0
    ans_list = []

    for use in range(n, 1, -1):
        rest = ans
        nex = now_a[0]
        while rest:
            val = nex
            start = bl(now_a, val+1)
            nex += 1
            for i in range(start-1, max(-1, start-1-rest), -1):
                if now_a[i] == max_a[i]:
                    if start != m:
                        nex = now_a[start]
                    break
                elif now_a[i] == 0:
                    cnt += 1
                now_a[i] += 1
                rest -= 1
        while cnt >= use:
            ans += 1
            rest = use
            nex = now_a[-1]
            end = m
            while rest:
                val = nex
                start = bl(now_a, val)
                if start != 0:
                    nex = now_a[start-1]
                for i in range(start, min(end, start+rest)):
                    if now_a[i] > val:
                        break
                    elif now_a[i] == 1:
                        cnt -= 1
                    now_a[i] -= 1
                    rest -= 1
                end = start
        ans_list.append(ans)
    print(n)
    for i in ans_list[::-1]:
        print(i)


main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    from collections import Counter as ct
    from bisect import bisect_left as bl

    n = int(input())
    max_a = sorted(ct(list(map(int, input().split()))).values())
    now_a = [i for i in max_a]
    m = len(max_a)
    cnt = m
    ans = 0
    ans_list = []

    for use in range(n, 1, -1):
        rest = ans
        nex = now_a[0]
        # restの分だけ戻す
        while rest:
            val = nex
            start = bl(now_a, val+1)
            nex += 1
            for i in range(start-1, -1, -1):
                if now_a[i] == max_a[i]:
                    if start != m:
                        nex = now_a[start]
                    break
                elif now_a[i] == 0:
                    cnt += 1
                now_a[i] += 1
                rest -= 1
                if rest == 0:
                    break
        # 大きい方から使っていく
        while True:
            if cnt < use:
                ans_list.append(ans)
                break
            ans += 1
            rest = use
            nex = now_a[-1]
            end = m
            while rest:
                val = nex
                start = bl(now_a, val)
                if start != 0:
                    nex = now_a[start-1]
                for i in range(start, end):
                    if now_a[i] > val:
                        break
                    elif now_a[i] == 1:
                        cnt -= 1
                    now_a[i] -= 1
                    rest -= 1
                    if rest == 0:
                        break
                end = start
    print(n)
    for i in ans_list[::-1]:
        print(i)


main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    from collections import Counter as ct
    from bisect import bisect_left as bl

    n = int(input())
    max_a = sorted(ct(list(map(int, input().split()))).values())
    now_a = [i for i in max_a]
    m = len(max_a)
    cnt = m
    ans = 0
    ans_list = []

    for use in range(n, 0, -1):
        rest = ans
        nex = now_a[0]
        # restの分だけ戻す
        while rest:
            val = nex
            start = bl(now_a, val+1)
            nex += 1
            for i in range(start-1, -1, -1):
                if now_a[i] == max_a[i]:
                    if start != m:
                        nex = now_a[start]
                    break
                elif now_a[i] == 0:
                    cnt += 1
                now_a[i] += 1
                rest -= 1
                if rest == 0:
                    break
        # 大きい方から使っていく
        while True:
            if cnt < use:
                ans_list.append(ans)
                break
            ans += 1
            rest = use
            nex = now_a[-1]
            end = m
            while rest:
                val = nex
                start = bl(now_a, val)
                if start != 0:
                    nex = now_a[start-1]
                for i in range(start, end):
                    if now_a[i] > val:
                        break
                    elif now_a[i] == 1:
                        cnt -= 1
                    now_a[i] -= 1
                    rest -= 1
                    if rest == 0:
                        break
                end = start
    for i in ans_list[::-1]:
        print(i)


main()

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
a = int(input())
b = list(map(int, input().split()))
for i in range(1, a+1):
    d = Counter(b)
    if d.most_common(1)[0][1] == 1:
        print(a // i)
    else:
        r = 0
        while d:
            t = d.most_common(i)
            if len(t) < i:
                break
            d.subtract(Counter([k[0] for k in t]))
            if d.most_common()[-1][1] < 0:
                break
            r += 1
        print(r)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
from itertools import accumulate
import bisect

n = int(input())
a = tuple(map(int, input().split()))
b = sorted(Counter(a).values())
b = tuple([0]*(n-len(b))+b)
c = tuple([0]+list(accumulate(b)))

ans = []
for k in range(1,n+1):
    l = 0
    r = n+1
    while r-l>1:
        x = (r+l)//2
        i = bisect.bisect_left(b,x)
        if c[i]+(n-i)*x>=x*k:
            l = x
        else:
            r = x
    ans.append(l)

print('\n'.join(map(str,ans)))

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
from itertools import accumulate
import bisect

n = int(input())
a = list(map(int, input().split()))
b = sorted(Counter(a).values())
b = [0]*(n-len(b))+b
c = list(accumulate([0]+b))

ans = []
for k in range(1,n+1):
    l = 0
    r = n+1
    while r-l>1:
        x = (r+l)//2
        i = bisect.bisect_left(b,x)
        if c[i]+(n-i)*x>=x*k:
            l = x
        else:
            r = x
    ans.append(l)

print('\n'.join(map(str,ans)))

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
from itertools import accumulate
import bisect

n = int(input())
a = list(map(int, input().split()))
b = sorted(Counter(a).values())
b = [0]*(n-len(b))+b
c = list(accumulate([0]+b))

for k in range(1,n+1):
    l = 0
    r = n+1
    while r-l>1:
        x = (r+l)//2
        i = bisect.bisect_left(b,x)
        if c[i]+(n-i)*x>=x*k:
            l = x
        else:
            r = x
    print(l)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
n = int(input())
c = list(Counter(ai for ai in map(int, input().split())).values())
c.sort()

s = [0] * (len(c) + 1)
for i in range(len(c)):
    s[i + 1] = s[i] + c[i]

def bin_search_max(l, r, f):
    while r - l > 1:
        c = (l + r) // 2
        if f(c):
            l = c
        else:
            r = c
    return l

for i in range(1, n + 1):
    rest = len(c) - i
    if rest < 0:
        print(0)
        continue
    def f(v):
        lim = bin_search_max(-1, len(c), lambda x: c[x] < v) + 1
        return lim * v - s[lim] <= rest * v
    print(bin_search_max(0, c[-1] * len(c) + 1, f))

Submission status: Time Limit Exceeded

Solution code:
import copy
n = int(input())
a = list(map(int, input().split()))
b = [0]*(n+1)
for i in a:
  b[i-1] += 1
b.sort(reverse=True)
c = [0]*n
for i in range(n):
  if b[i]==0:
    break
  c[b[i]-1] += 1
for i in range(n):
  if c[i]>0:
    last_c = i
for k in range(1,n+1):
  if k==1:
    print(n)
  else:
    ck = copy.deepcopy(c)
    bk = copy.deepcopy(b)
    count = 0
    sum_ck = sum(ck)
    while sum_ck >= k:
      for i in range(k):
        ck[bk[i]-1] -= 1
        if bk[i] > 1:
          ck[bk[i]-2] += 1
        else:
          sum_ck -= 1
        bk[i] -= 1
      bk.sort(reverse=True)
      count += 1
    print(count)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))


def f(x):
    s = 0
    for i in C:
        s += min(i,x)
    if s/k >= x:
        return True
    return False

n = I()
a = LI()
C = list(Counter(a).values())
C.sort()
for k in range(1,n+1):
    ok,ng = n+1,0
    while ok - ng > 1:
        mid = (ok+ng)//2
        if f(mid):
            ng = mid
        else:
            ok = mid
    print(ng)

Submission status: Time Limit Exceeded

Solution code:
def distinct_numbers():
    from itertools import accumulate
    from bisect import bisect
    
    N = int(input())
    s = [0] * (N + 1)
    for v in input().split():
        s[int(v)] += 1
    s.sort()
    cum = list(accumulate(s))
    
    for k in range(1, N + 1):        
        l, r = 0, N + 1 # l: OK, r: NG
        while r - l > 1:
            c = (l + r) // 2
            
            idx = bisect(s, c)
            if idx == len(cum):
                cumsum = cum[-1]
            else:
                cumsum = cum[idx-1] + (len(cum) - idx) * c
                
            if cumsum >= c * k:
                l = c
            else:
                r = c
        print(l)
        
def main():
  distinct_numbers()


if __name__ == '__main__':
  main()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int,input().split()))
a = list(set(A))

for h in range(N):
    answer = 0
    S = sorted([A.count(t) for t in a], key = lambda x:-x)
    if h+1 > len(S):
        print(0)
        continue
    while S.count(0)<=len(S)-h:
        answer += S[h]
        S = [S[j]-S[h] if j<h+1 else S[j] for j in range(len(S))]
        S = sorted(S, key=lambda x: -x)
        if S.count(0)>=len(S)-h:
            print(answer)
            break

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
from collections import Counter
N = int(input())
c = Counter(map(int, input().split()))
C = list(c.values())
C.sort()
C= np.array(C)
lenc = len(C)
ans = np.array([0]*(N+1))
for num in range(1, N+1):
    sum1 = np.minimum(C, np.array([num]*lenc))
    ans[:((np.sum(np.array(sum1)) // num) + 1 )] = num

for i in ans[1:]:
    print(i)

Submission status: Time Limit Exceeded

Solution code:

import numpy as np
from collections import Counter
N = int(input())
c = Counter(map(int, input().split()))
C = list(c.values())
C.sort()
C= np.array(C)
lenc = len(C)
ans = [0]*(N+1)
for num in range(1, N+1):
    sum1 = np.minimum(C, np.array([num]*lenc))
    ans[np.sum(np.array(sum1)) // num] = num

m = 0
for i,name in enumerate(ans[::-1]):
    m = max(m,name)
    ans[-(i+1)] = m

for i in ans[1:]:
    print(i)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
from collections import Counter
N = int(input())
c = Counter(map(int, input().split()))
C = list(c.values())
C.sort()

ans = [0]*(N+1)
for num in range(1, N+1):

    sum1 = []
    for i in C:
        sum1.append(min(i, num))
    ans[np.sum(np.array(sum1)) // num] = num

m = 0
for i,name in enumerate(ans[::-1]):
    m = max(m,name)
    ans[-(i+1)] = m

for i in ans[1:]:
    print(i)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
N = int(input())
c = Counter(map(int, input().split()))
C = list(c.values())
C.sort()

ans = [0]*(N+1)
for num in range(1, N+1):
    sum1 = []
    for i in C:
        sum1.append(min(i, num))
    ans[sum(sum1) // num] = num

m = 0
for i,name in enumerate(ans[::-1]):
    m = max(m,name)
    ans[-(i+1)] = m

for i in ans[1:]:
    print(i)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
types = {}
for i in A: types[i] = types.get(i, 0) + 1
A = sorted([types[k] for k in types], reverse=True)
L = len(A)
cumsum = [0 for i in range(L+1)]
for i in range(L-1, -1, -1):
    cumsum[i] = A[i] + cumsum[i+1]

# Highest K for given O
def calc(O):
    def getMidPoint(lo, hi):
        if lo >= hi: return lo
        mid = lo + (hi - lo+1) // 2
        if A[mid] > O:
            return getMidPoint(mid, hi)
        else:
            return getMidPoint(lo, mid-1)

    mid = getMidPoint(0, L-1)
    if A[mid] < O: mid = - 1
    return (mid+1) + cumsum[mid+1] // O

for K in range(1, N+1):
    def getO(lo, hi):
        if lo >= hi: return lo
        mid = lo + (hi - lo+1) // 2
        if calc(mid) < K:
            return getO(lo, mid - 1)
        else:
            return getO(mid, hi)
        
    print(getO(0, N))

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

N = int(input())
 
lines = input().split(' ')
 
lis = list(Counter(lines).values())
# dic = {}
# for item in lines:
#     n = int(item)
 
#     if n in dic.keys():
#         dic[n] += 1
#     else:
#         dic[n] = 1
 
# lis = list(dic.values())
# for item in dic.keys():
#     lis += [dic[item]]
 
lis.sort(reverse=True)
 
sublis = []
sublis = lis[:]
 
def cal(k,lis):
    ans = 0
    if (len(lis)<k):
        return 0
    
    while True:
        for k_i in range(k):
            if lis[k_i] == 0:
                return ans
            else:
                lis[k_i] -= 1
        else:
            ans += 1

        if k*(ans+1) < len(lis):
            lis = sorted(lis[:k*(ans+1)],reverse=True) + lis[k*(ans+1):]
        else:
            lis.sort(reverse=True)
        
 
 
for i in range(N):
    if i == 0:
        print(N)
        continue
    elif i == N-1:
        if len(lis) < N:
            print(0)
        else:
            print(sublis[-1])
        continue
    lis = sublis[:]
    print(cal(i+1,lis))

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

N = int(input())
 
lines = input().split(' ')
 
lis = list(Counter(lines).values())
# dic = {}
# for item in lines:
#     n = int(item)
 
#     if n in dic.keys():
#         dic[n] += 1
#     else:
#         dic[n] = 1
 
# lis = list(dic.values())
# for item in dic.keys():
#     lis += [dic[item]]
 
lis.sort(reverse=True)
 
sublis = []
sublis = lis[:]
 
def cal(k,lis):
    ans = 0
    if (len(lis)<k):
        return 0
    
    while True:
        for k_i in range(k):
            if lis[k_i] == 0:
                return ans
            else:
                lis[k_i] -= 1
        else:
            ans += 1
 
        lis.sort(reverse=True)
 
 
for i in range(N):
    if i == 0:
        print(N)
        continue
    elif i == N-1:
        if len(lis) < N:
            print(0)
        else:
            print(sublis[-1])
        continue
    lis = sublis[:]
    print(cal(i+1,lis))

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

N = int(input())
 
lines = input().split(' ')
 
lis = list(Counter(lines).values())
# dic = {}
# for item in lines:
#     n = int(item)
 
#     if n in dic.keys():
#         dic[n] += 1
#     else:
#         dic[n] = 1
 
# lis = list(dic.values())
# for item in dic.keys():
#     lis += [dic[item]]
 
lis.sort(reverse=True)
 
sublis = []
sublis = lis[:]
 
def cal(k,lis):
    ans = 0
    if (len(lis)<k):
        return 0
    
    while True:
        for k_i in range(k):
            if lis[k_i] == 0:
                return ans
            else:
                lis[k_i] -= 1
        else:
            ans += 1
 
        lis.sort(reverse=True)
 
 
for i in range(N):
    if i == 0:
        print(N)
        continue
    lis = sublis[:]
    print(cal(i+1,lis))

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

N = int(input())
 
lines = input().split(' ')
 
lis = list(Counter(lines).values())
# dic = {}
# for item in lines:
#     n = int(item)
 
#     if n in dic.keys():
#         dic[n] += 1
#     else:
#         dic[n] = 1
 
# lis = list(dic.values())
# for item in dic.keys():
#     lis += [dic[item]]
 
lis.sort(reverse=True)
 
sublis = []
sublis = lis[:]
 
def cal(k,lis):
    ans = 0
    if (len(lis)<k):
        return 0
    
    while True:
        for k_i in range(k):
            if lis[k_i] == 0:
                return ans
            else:
                lis[k_i] -= 1
        else:
            ans += 1
 
        lis.sort(reverse=True)
 
 
for i in range(N):
    lis = sublis[:]
    print(cal(i+1,lis))

Submission status: Time Limit Exceeded

Solution code:
import copy

li = list(map(int,input().split()))
N=li[0]
A = list(map(int,input().split()))
A.sort()
B=[]

for a in A:
    if(A.count(a)!=0):
        B.append([a,A.count(a)])
        A=[i for i in A if i!=a]

B=sorted(B,key=lambda x: x[1],reverse=True)

for n in range(1,N+1):
    #初期設定
    B_=copy.deepcopy(B)
    counter=0
    while n<=len(B_):
        counter+=B_[n-1][1]
        for k in range(0,n-1):
            B_[k][1]-=B_[n-1][1]
        B_.pop(n-1)
        B_=sorted(B_,key=lambda x: x[1],reverse=True)
    print(counter)

Submission status: Time Limit Exceeded

Solution code:
import collections
import bisect
from sys import stdin
input = lambda: stdin.readline().rstrip()

n = int(input())
a = list(map(int, input().split()))
cnt = [0] * n
for v in a:
    cnt[v - 1] += 1
cnt.sort(reverse=True)
while cnt and cnt[-1] == 0:
    cnt.pop()
cnt.reverse()
while cnt and cnt[-1] == 0:
    cnt.pop()
nc = len(cnt)
pre = [0] * (nc + 1)
for i in range(nc):
    pre[i + 1] = pre[i] + cnt[i]
for i in range(1, n + 1):
    res = 0
    if i == 1:
        res = n
    elif i > nc:
        res = 0
    elif i == nc:
        res = cnt[0]
    else:
        l, r = 0, n
        while l < r:
            mid = l + r + 1 >> 1
            it = bisect.bisect(cnt, mid)
            sm = (nc - it) * mid + pre[it]
            if mid * i > sm:
                r = mid - 1
            else:
                l = mid
        res = r
    print(res)

Submission status: Time Limit Exceeded

Solution code:
import collections
import bisect

n = int(input())
a = list(map(int, input().split()))
cnt = [0] * n
for v in a:
    cnt[v - 1] += 1
cnt.sort(reverse=True)
while cnt and cnt[-1] == 0:
    cnt.pop()
cnt.reverse()
nc = len(cnt)
pre = [0] * (nc + 1)
for i in range(nc):
    pre[i + 1] = pre[i] + cnt[i]
for i in range(1, n + 1):
    res = 0
    if i == 1:
        res = n
    elif i > nc:
        res = 0
    elif i == nc:
        res = cnt[0]
    else:
        l, r = 0, n
        while l < r:
            mid = l + r + 1 >> 1
            it = bisect.bisect(cnt, mid)
            sm = (nc - it) * mid + pre[it]
            if mid * i > sm:
                r = mid - 1
            else:
                l = mid
        res = r
    print(res)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline

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

from collections import Counter
import bisect
import numpy as np

l = Counter(A).most_common()
l = [b for a, b in l]
M = len(l)
l = np.sort(l)
m = np.cumsum(l)
p = m[-1]

maximum_operation = [0] * N

ll = []
for x in reversed(range(1, N+1)):
    a = bisect.bisect_left(l, x)
    if a == 0:
        b = M*x
        c = 0
    elif a >= M:
        b = 0
        c = p
    else:
        b = (M-a)*x
        c = m[a-1] 
    ll.append((b + c)/x)

for K in range(M):
    maximum_operation[K] = N - bisect.bisect_left(ll, K+1)

for m in maximum_operation:
    print(m)