# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(N, A):
# write your code in Python 3.6
curN, maxN = 0, 0
result = [0] * (N + 1)
for a in A:
if a == N + 1:
maxN = curN
else:
if result[a] < maxN:
result[a] = maxN
result[a] += 1
if result[a] > curN:
curN = result[a]
for i in range(1, N+1):
if result[i] < maxN:
result[i] = maxN
return result[1:]