Ayman is on a school bus coming back from his AP Seminar field trip. His bus has
When leaving the bus, there's a few unwritten rules that people should follow. Firstly, a person shouldn't leave the bus until everyone from all rows ahead of them have already left, on both the left and right sides. Secondly, a person shouldn't leave until everyone else closer to the aisle on their side of the bus (left or right) has already left, so that their path to the aisle doesn't go through other students.
As Ayman waits to leave, he realizes he can make a competitive programming problem out of this! Given the seating of the bus and the order that students leave, can you determine if all students followed the unwritten rules?
Constraints
Subtask 1 [30%]
Subtask 2 [30%]
Subtask 3 [40%]
No additional constraints.
Input Specification
The first line of output contains the integers
The next
Output Specification
The output will consist of one line: yes
if the entire bus followed the unwritten rules, or no
if one or more passengers violated the rules.
Sample Input 1
2 2
2
1
3
4
7
6
5
8
Sample Output 1
yes
Explanation for Sample 1
The students are numbered in the bus as follows:
1 2 3 4
5 6 7 8
Student 2 is the closest to the aisle on the left side of the bus, so they can leave. Now that student 2 has left, student 1 is the closest to the aisle on the left side of the bus, so they can leave. Student 3 is the closest to the aisle on the right side of the bus, so they can leave. Now that student 3 has left the bus, student 4 is the closest to the aisle on the right side of the bus, so they can leave.
Student 7 is the closest to the aisle on the right side, so they can leave. Student 6 is the closest to the aisle on the left side, so they can leave. Student 5 is now the closest to the aisle on the left side, so they can leave. Student 8 is now the closest to the aisle on the right side, so they can leave.
Sample Input 2
2 1
1
3
2
4
Sample Output 2
no
Explanation for Sample 2
This case satisfies the conditions of Subtask 1. The students are numbered in the bus as follows:
1 2
3 4
Student 3 is in row 2, but leaves before student 2 who is in row 1, violating an unspoken rule.
Sample Input 3
1 3
3
2
5
1
4
6
Sample Output 3
no
Explanation for Sample 3
This case satisfies the conditions of Subtask 2. The students are numbered in the bus as follows:
1 2 3 4 5 6
Student 5 leaves before student 4, even though student 4 is closer to the aisle than them on the right side of the bus, violating an unspoken rule.
Comments