Олимпиадный тренинг

Задача 30782. city ​​parade


Задача

Темы: Очередь

Chief Wiggum must ensure the correct order of the floats in the city parade. Platforms can arrive in any order, but must enter the central square strictly in ascending order of numbers. Wiggum can direct the platform either directly to the square, or first to a side street, and then from it to the square. The length of the side street is sufficient to accommodate all platforms, but the width of the streets does not allow one platform to overtake another.

Write a program to determine if Wiggum can ensure the floats move in the correct order on parade.
 

Input
The first line of input contains a single integer N (\(1 <= N <= 100\)) – number of platforms.
The second line contains N different integers from 1 to N – platform numbers in order of arrival.

Imprint
Print "YES" if the correct platform order can be ensured, or "NO" if not.
 

Examples
# Input Output
1
4
1 3 4 2
YES
2
4
4 3 2 1
NO
3 4
2 1 3 4
YES