LogiQuest

451. Lemonade Change

EasyGreedySimulation

Lemonade costs 5. Customers pay with 5, 10 or 20 notes in order, and you start with no change. Print YES if you can give everyone correct change, else NO.

Input format

Line 1: n Line 2: n bills

Output format

YES or NO

Example 1

Input

5
5 5 5 10 20

Output

YES

Example 2

Input

5
5 5 10 10 20

Output

NO

Constraints

1 ≤ n ≤ 10⁵

Read input from standard input and print the answer to standard output. Your code is judged against 4 test cases, most of them hidden.

Loading the MyLoginn IDE…