Statement
There are nails on the circumference of a circular board. They are numbered in clockwise order.
A permutation of is given. A thread starts at nail and visits in this order. The part of the thread between two consecutive nails is a taut straight segment.
Each query gives two integers . Imagine cutting the thread and keeping only the part from through . The remaining thread consists of the segments .
Two distinct segments cross if their interiors have a common point. Determine whether the number of crossing pairs of segments in the remaining thread is odd.
- Two consecutive segments sharing a nail as an endpoint are not counted as crossing.
- If three or more segments meet at the same interior point, every crossing pair is counted separately.
- All queries are independent.
Input
The input is given in the following format:
Each case is given in the following format:
Output
For each test case, print the answers to its queries in order, one per line.
Print 1 if the number of crossing pairs is odd, and print 0 otherwise.
Constraints
- .
- .
- is a permutation of .
- ().
- The sum of over all test cases does not exceed .
- The sum of over all test cases does not exceed .
Subtasks
Samples
In the first query, segment - crosses segment -. There is exactly one crossing pair, so the answer is 1.