Palindrome?

No attempts yetTime limit0.5sMemory limit256 MB

Problem

Myeongwoo and Hongjun play a palindrome game.

Hongjun first writes NN natural numbers on a board. He then asks Myeongwoo MM questions.

Each question is a pair of integers SS and EE (1SEN1 \le S \le E \le N). It asks whether the numbers from the SS-th to the EE-th on the board form a palindrome, and Myeongwoo must answer yes or no. A sequence is a palindrome when reading it forward gives the same result as reading it backward.

Suppose Hongjun writes 1, 2, 1, 3, 1, 2, 1 on the board.

  • With S=1S = 1, E=3E = 3 the numbers are 1, 2, 1, which is a palindrome.
  • With S=2S = 2, E=5E = 5 the numbers are 2, 1, 3, 1, which is not a palindrome.
  • With S=3S = 3, E=3E = 3 the number is 1, which is a palindrome.
  • With S=5S = 5, E=7E = 7 the numbers are 1, 2, 1, which is a palindrome.

Given the NN numbers and the MM questions, write a program that produces all of Myeongwoo's answers.

Input

The first line contains the size of the sequence NN (1N20001 \le N \le 2000).

The second line contains the NN numbers Hongjun wrote on the board, in order. Each number is a natural number no greater than 100,000.

The third line contains the number of questions MM (1M1061 \le M \le 10^6).

Each of the next MM lines contains one question, given as SS and EE.

Output

Print Myeongwoo's answers on MM lines, in the order the questions are given. Print 1 if the range is a palindrome and 0 if it is not.