#include <bits/stdc++.h>
using namespace std;
template <class T1>
void deb(T1 e) {
  cout << e << endl;
}
template <class T1, class T2>
void deb(T1 e1, T2 e2) {
  cout << e1 << " " << e2 << endl;
}
template <class T1, class T2, class T3>
void deb(T1 e1, T2 e2, T3 e3) {
  cout << e1 << " " << e2 << " " << e3 << endl;
}
template <class T1, class T2, class T3, class T4>
void deb(T1 e1, T2 e2, T3 e3, T4 e4) {
  cout << e1 << " " << e2 << " " << e3 << " " << e4 << endl;
}
template <class T1, class T2, class T3, class T4, class T5>
void deb(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5) {
  cout << e1 << " " << e2 << " " << e3 << " " << e4 << " " << e5 << endl;
}
template <class T1, class T2, class T3, class T4, class T5, class T6>
void deb(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5, T6 e6) {
  cout << e1 << " " << e2 << " " << e3 << " " << e4 << " " << e5 << " " << e6
       << endl;
}
ostream_iterator<int> screen(cout, " ");
const int sz = 2 * 1000 * 100 + 10;
const int inf = INT_MAX >> 1;
const long long big = (1 << 62);
const double pi = acos(-1.0);
int dx[] = {0, 0, 1, -1, 1, 1, -1, -1}, dy[] = {1, -1, 0, 0, 1, -1, 1, -1};
vector<int> res;
long long powermod(long long n, long long p) {
  if (p == 0) return 1;
  long long a = powermod(n, p / 2) % 1000000007;
  if (p % 2 == 1) return (a * a * n) % 1000000007;
  return (a * a) % 1000000007;
}
int main() {
  int n, m, a, b, cnt1 = 0, cnt = 0, p;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> p;
    if (p > 0) cnt1++;
  }
  cnt = n - cnt1;
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    p = b - a + 1;
    if (p % 2 == 0 && p / 2 <= cnt && p / 2 <= cnt1)
      cout << 1 << endl;
    else
      cout << 0 << endl;
  }
  return 0;
}

### Prompt

Construct a CPP code solution to the problem outlined:

Eugeny has array a = a1, a2, ..., an, consisting of n integers. Each integer ai equals to -1, or to 1. Also, he has m queries:

  * Query number i is given as a pair of integers li, ri (1 ≤ li ≤ ri ≤ n). 
  * The response to the query will be integer 1, if the elements of array a can be rearranged so as the sum ali + ali + 1 + ... + ari = 0, otherwise the response to the query will be integer 0. 



Help Eugeny, answer all his queries.

Input

The first line contains integers n and m (1 ≤ n, m ≤ 2·105). The second line contains n integers a1, a2, ..., an (ai = -1, 1). Next m lines contain Eugene's queries. The i-th line contains integers li, ri (1 ≤ li ≤ ri ≤ n).

Output

Print m integers — the responses to Eugene's queries in the order they occur in the input.

Examples

Input

2 3
1 -1
1 1
1 2
2 2


Output

0
1
0


Input

5 5
-1 1 1 1 -1
1 1
2 3
3 5
2 5
1 5


Output

0
1
0
1
0

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
template <class T1>
void deb(T1 e) {
  cout << e << endl;
}
template <class T1, class T2>
void deb(T1 e1, T2 e2) {
  cout << e1 << " " << e2 << endl;
}
template <class T1, class T2, class T3>
void deb(T1 e1, T2 e2, T3 e3) {
  cout << e1 << " " << e2 << " " << e3 << endl;
}
template <class T1, class T2, class T3, class T4>
void deb(T1 e1, T2 e2, T3 e3, T4 e4) {
  cout << e1 << " " << e2 << " " << e3 << " " << e4 << endl;
}
template <class T1, class T2, class T3, class T4, class T5>
void deb(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5) {
  cout << e1 << " " << e2 << " " << e3 << " " << e4 << " " << e5 << endl;
}
template <class T1, class T2, class T3, class T4, class T5, class T6>
void deb(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5, T6 e6) {
  cout << e1 << " " << e2 << " " << e3 << " " << e4 << " " << e5 << " " << e6
       << endl;
}
ostream_iterator<int> screen(cout, " ");
const int sz = 2 * 1000 * 100 + 10;
const int inf = INT_MAX >> 1;
const long long big = (1 << 62);
const double pi = acos(-1.0);
int dx[] = {0, 0, 1, -1, 1, 1, -1, -1}, dy[] = {1, -1, 0, 0, 1, -1, 1, -1};
vector<int> res;
long long powermod(long long n, long long p) {
  if (p == 0) return 1;
  long long a = powermod(n, p / 2) % 1000000007;
  if (p % 2 == 1) return (a * a * n) % 1000000007;
  return (a * a) % 1000000007;
}
int main() {
  int n, m, a, b, cnt1 = 0, cnt = 0, p;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> p;
    if (p > 0) cnt1++;
  }
  cnt = n - cnt1;
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    p = b - a + 1;
    if (p % 2 == 0 && p / 2 <= cnt && p / 2 <= cnt1)
      cout << 1 << endl;
    else
      cout << 0 << endl;
  }
  return 0;
}

```