PROGRAMMING:Stack based IO sequence
Suppose that 1 and 0 represent the stack in and stack out operations respectively. The initial state and final state of the stack are empty, and the operation sequence of entering and leaving the stack can be expressed as a sequence composed of only 1 and 0. The sequence that can be operated and satisfies the empty final state of the stack is legal sequence, otherwise it is illegal sequence. For example, 10110100 is a legal sequence, while 10010110 is an illegal sequence. Because the stack is empty at the second time, this operation cannot be performed.
Please write a program to judge whether the given operation sequence is legal.
###Input format:
The input is 2 lines. The first line is a positive integer n not exceeding 100, which indicates the number of operations in the operation sequence. The second line is the given operation sequence, which is n integers with space interval, and each integer is 0 or 1.
###Output format:
The output is an integer. If the input sequence is legal, the output is 1. If the input sequence is not legal, the output is 0.
###Input sample 1:
```in
eight
1 0 1 1 0 1 0 0
```
###Output sample 1:
```out
one
```
###Input sample 2:
```in
eight
1 0 0 1 0 1 1 0
```
###Output sample 2:
```out
0
```
answer:If there is no answer, please comment
Please write a program to judge whether the given operation sequence is legal.
###Input format:
The input is 2 lines. The first line is a positive integer n not exceeding 100, which indicates the number of operations in the operation sequence. The second line is the given operation sequence, which is n integers with space interval, and each integer is 0 or 1.
###Output format:
The output is an integer. If the input sequence is legal, the output is 1. If the input sequence is not legal, the output is 0.
###Input sample 1:
```in
eight
1 0 1 1 0 1 0 0
```
###Output sample 1:
```out
one
```
###Input sample 2:
```in
eight
1 0 0 1 0 1 1 0
```
###Output sample 2:
```out
0
```
answer:If there is no answer, please comment