def solution(N, A):
# write your code in Python 2.6
res = [0] * N
m = 0
minValue = 0
for x in A:
if 1 <= x <= N:
res[x - 1] = max(res[x - 1], minValue) + 1
if res[x - 1] > m:
m = res[x - 1]
else:
minValue = m
for i in xrange(N):
res[i] = max(res[i], minValue)
return res