1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
from collections import Counter, deque

n = int(input())
sequence = [int(x) for x in input().split()]

counts = Counter(sequence)
sorted_counts = deque(counts.most_common())

split_sequences = 0
accum = 0

while len(sorted_counts) > 0:
    split_sequences += 1
    leader, apperances = sorted_counts.popleft()

    while len(sorted_counts) > 0 and apperances > accum + sorted_counts[-1][1]:
        accum += sorted_counts.pop()[1]

    if len(sorted_counts) > 0:
        sorted_counts[-1] = (sorted_counts[-1][0],
                             sorted_counts[-1][1] - (apperances - accum - 1))
        accum = 0

print(split_sequences)