def max_tower_size(n, colors):
max_sizes = [0] * n
update_max = lambda color: max_sizes.__setitem__(color - 1, max(max_sizes[:color]) + 1)
list(map(update_max, colors))
return max_sizes
# Пример использования
print(max_tower_size(5, [1, 2, 3, 2, 4]))