#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const long long infinity = 1000000000000000000;
const int inf = 1e9 + 5;
bool do_debug = false;
struct maxt {
  int tl;
  vector<long long> t;
  vector<long long> lazy;
  vector<long long> setv;
  maxt(int l, long long val) {
    tl = l;
    t = vector<long long>(tl << 2, val);
    lazy = vector<long long>(tl << 2, 0);
    setv = vector<long long>(tl << 2, -1);
  }
  long long task(long long child1, long long child2) {
    return max(child1, child2);
  }
  void push(vector<long long>& segment_tree, int node, int l, int r) {
    int child1 = node << 1;
    int child2 = (node << 1) + 1;
    int mid = (l + r) >> 1;
    if (setv[node] != -1) {
      lazy[child1] = 0;
      lazy[child2] = 0;
      setv[child1] = setv[node];
      setv[child2] = setv[node];
      segment_tree[child1] = setv[node];
      segment_tree[child2] = setv[node];
      setv[node] = -1;
    }
    lazy[child1] += lazy[node];
    lazy[child2] += lazy[node];
    segment_tree[child1] += lazy[node];
    segment_tree[child2] += lazy[node];
    lazy[node] = 0;
  }
  void make(vector<long long>& segment_tree, int node, int l, int r, int lq,
            int rq, long long val) {
    if (lq > rq) {
      return;
    }
    if (l == lq && r == rq) {
      lazy[node] = 0;
      segment_tree[node] = val;
      setv[node] = val;
    } else {
      push(segment_tree, node, l, r);
      int mid = (l + r) >> 1;
      make(segment_tree, node << 1, l, mid, lq, min(mid, rq), val);
      make(segment_tree, (node << 1) + 1, mid + 1, r, max(mid + 1, lq), rq,
           val);
      segment_tree[node] =
          task(segment_tree[node << 1], segment_tree[(node << 1) + 1]);
    }
  }
  void make(int lq, int rq, long long val) {
    make(t, 1, 0, tl - 1, lq, rq, val);
  }
  void add(vector<long long>& segment_tree, int node, int l, int r, int lq,
           int rq, long long val) {
    if (lq > rq) {
      return;
    }
    if (l == lq && r == rq) {
      lazy[node] += val;
      segment_tree[node] += val;
    } else {
      push(segment_tree, node, l, r);
      int mid = (l + r) >> 1;
      add(segment_tree, node << 1, l, mid, lq, min(mid, rq), val);
      add(segment_tree, (node << 1) + 1, mid + 1, r, max(mid + 1, lq), rq, val);
      segment_tree[node] =
          task(segment_tree[node << 1], segment_tree[(node << 1) + 1]);
    }
  }
  void add(int lq, int rq, long long val) { add(t, 1, 0, tl - 1, lq, rq, val); }
  long long query(vector<long long>& segment_tree, int node, int l, int r,
                  int lq, int rq) {
    if (lq > rq) {
      return -infinity;
    } else if (lq <= l && rq >= r) {
      return segment_tree[node];
    } else {
      push(segment_tree, node, l, r);
      int mid = (l + r) >> 1;
      return task(query(segment_tree, node << 1, l, mid, lq, min(rq, mid)),
                  query(segment_tree, (node << 1) + 1, mid + 1, r,
                        max(lq, mid + 1), rq));
    }
  }
  long long query(int lq, int rq) { return query(t, 1, 0, tl - 1, lq, rq); }
  void build(vector<long long>& segment_tree, vector<long long>& v, int node,
             int l, int r) {
    if (l == r) {
      segment_tree[node] = v[l];
    } else {
      int mid = (l + r) >> 1;
      build(segment_tree, v, node << 1, l, mid);
      build(segment_tree, v, (node << 1) + 1, mid + 1, r);
      segment_tree[node] =
          task(segment_tree[node << 1], segment_tree[(node << 1) + 1]);
    }
  }
  void build(vector<long long>& v) { build(t, v, 1, 0, tl - 1); }
};
struct mint {
  int tl;
  vector<long long> t;
  vector<long long> lazy;
  vector<long long> setv;
  mint(int l, long long val) {
    tl = l;
    t = vector<long long>(tl << 2, val);
    lazy = vector<long long>(tl << 2, 0);
    setv = vector<long long>(tl << 2, -1);
  }
  long long task(long long child1, long long child2) {
    return min(child1, child2);
  }
  void push(vector<long long>& segment_tree, int node, int l, int r) {
    int child1 = node << 1;
    int child2 = (node << 1) + 1;
    int mid = (l + r) >> 1;
    if (setv[node] != -1) {
      lazy[child1] = 0;
      lazy[child2] = 0;
      setv[child1] = setv[node];
      setv[child2] = setv[node];
      segment_tree[child1] = setv[node];
      segment_tree[child2] = setv[node];
      setv[node] = -1;
    }
    lazy[child1] += lazy[node];
    lazy[child2] += lazy[node];
    segment_tree[child1] += lazy[node];
    segment_tree[child2] += lazy[node];
    lazy[node] = 0;
  }
  void make(vector<long long>& segment_tree, int node, int l, int r, int lq,
            int rq, long long val) {
    if (lq > rq) {
      return;
    }
    if (l == lq && r == rq) {
      lazy[node] = 0;
      segment_tree[node] = val;
      setv[node] = val;
    } else {
      push(segment_tree, node, l, r);
      int mid = (l + r) >> 1;
      make(segment_tree, node << 1, l, mid, lq, min(mid, rq), val);
      make(segment_tree, (node << 1) + 1, mid + 1, r, max(mid + 1, lq), rq,
           val);
      segment_tree[node] =
          task(segment_tree[node << 1], segment_tree[(node << 1) + 1]);
    }
  }
  void make(int lq, int rq, long long val) {
    make(t, 1, 0, tl - 1, lq, rq, val);
  }
  void add(vector<long long>& segment_tree, int node, int l, int r, int lq,
           int rq, long long val) {
    if (lq > rq) {
      return;
    }
    if (l == lq && r == rq) {
      lazy[node] += val;
      segment_tree[node] += val;
    } else {
      push(segment_tree, node, l, r);
      int mid = (l + r) >> 1;
      add(segment_tree, node << 1, l, mid, lq, min(mid, rq), val);
      add(segment_tree, (node << 1) + 1, mid + 1, r, max(mid + 1, lq), rq, val);
      segment_tree[node] =
          task(segment_tree[node << 1], segment_tree[(node << 1) + 1]);
    }
  }
  void add(int lq, int rq, long long val) { add(t, 1, 0, tl - 1, lq, rq, val); }
  long long query(vector<long long>& segment_tree, int node, int l, int r,
                  int lq, int rq) {
    if (lq > rq) {
      return infinity;
    } else if (lq <= l && rq >= r) {
      return segment_tree[node];
    } else {
      push(segment_tree, node, l, r);
      int mid = (l + r) >> 1;
      return task(query(segment_tree, node << 1, l, mid, lq, min(rq, mid)),
                  query(segment_tree, (node << 1) + 1, mid + 1, r,
                        max(lq, mid + 1), rq));
    }
  }
  long long query(int lq, int rq) { return query(t, 1, 0, tl - 1, lq, rq); }
  void build(vector<long long>& segment_tree, vector<long long>& v, int node,
             int l, int r) {
    if (l == r) {
      segment_tree[node] = v[l];
    } else {
      int mid = (l + r) >> 1;
      build(segment_tree, v, node << 1, l, mid);
      build(segment_tree, v, (node << 1) + 1, mid + 1, r);
      segment_tree[node] =
          task(segment_tree[node << 1], segment_tree[(node << 1) + 1]);
    }
  }
  void build(vector<long long>& v) { build(t, v, 1, 0, tl - 1); }
};
void solve() {
  int len, nq;
  cin >> len >> nq;
  vector<long long> a(len), b(len), ps(len, 0);
  for (int i = 0; i < len; i++) cin >> a[i];
  ;
  for (int i = 0; i < len; i++) cin >> b[i];
  ;
  ps[0] = b[0] - a[0];
  for (int i = 1; i < len; i++) {
    ps[i] = ps[i - 1] + b[i] - a[i];
  }
  maxt M(len, 0);
  mint m(len, 0);
  M.build(ps);
  m.build(ps);
  for (int i = 0; i < nq; i++) {
    int l, r;
    cin >> l >> r;
    l--;
    r--;
    long long sub = (l ? ps[l - 1] : 0);
    long long sum = (l ? (ps[r] - ps[l - 1]) : ps[r]);
    long long Mval = M.query(l, r) - sub;
    long long mval = m.query(l, r) - sub;
    if (sum != 0 || mval < 0) {
      cout << -1 << "\n";
    } else {
      cout << Mval << "\n";
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int q = 1;
  while (q-- > 0) {
    solve();
  }
  return 0;
}

### Prompt

Please formulate a CPP solution to the following problem:

<image>

William has two arrays a and b, each consisting of n items.

For some segments l..r of these arrays William wants to know if it is possible to equalize the values of items in these segments using a balancing operation. Formally, the values are equalized if for each i from l to r holds a_i = b_i.

To perform a balancing operation an even number of indices must be selected, such that l ≤ pos_1 < pos_2 < ... < pos_k ≤ r. Next the items of array a at positions pos_1, pos_3, pos_5, ... get incremented by one and the items of array b at positions pos_2, pos_4, pos_6, ... get incremented by one.

William wants to find out if it is possible to equalize the values of elements in two arrays for each segment using some number of balancing operations, and what is the minimal number of operations required for that. Note that for each segment the operations are performed independently.

Input

The first line contains a two integers n and q (2 ≤ n ≤ 10^5, 1 ≤ q ≤ 10^5), the size of arrays a and b and the number of segments.

The second line contains n integers a_1, a_2, ..., a_n (0 ≤ a_i ≤ 10^9).

The third line contains n integers b_1, b_2, ..., b_n (0 ≤ b_i ≤ 10^9).

Each of the next q lines contains two integers l_i and r_i (1 ≤ l_i < r_i ≤ n), the edges of segments.

Output

For each segment output a single number — the minimal number of balancing operations needed or "-1" if it is impossible to equalize segments of arrays.

Example

Input


8 5
0 1 2 9 3 2 7 5
2 2 1 9 4 1 5 8
2 6
1 7
2 4
7 8
5 8


Output


1
3
1
-1
-1

Note

For the first segment from 2 to 6 you can do one operation with pos = [2, 3, 5, 6], after this operation the arrays will be: a = [0, 2, 2, 9, 4, 2, 7, 5], b = [2, 2, 2, 9, 4, 2, 5, 8]. Arrays are equal on a segment from 2 to 6 after this operation.

For the second segment from 1 to 7 you can do three following operations: 

  1. pos = [1, 3, 5, 6] 
  2. pos = [1, 7] 
  3. pos = [2, 7] 



After these operations, the arrays will be: a = [2, 2, 2, 9, 4, 2, 7, 5], b = [2, 2, 2, 9, 4, 2, 7, 8]. Arrays are equal on a segment from 1 to 7 after these operations.

For the third segment from 2 to 4 you can do one operation with pos = [2, 3], after the operation arrays will be: a = [0, 2, 2, 9, 3, 2, 7, 5], b = [2, 2, 2, 9, 4, 1, 5, 8]. Arrays are equal on a segment from 2 to 4 after this operation.

It is impossible to equalize the fourth and the fifth segment.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const long long infinity = 1000000000000000000;
const int inf = 1e9 + 5;
bool do_debug = false;
struct maxt {
  int tl;
  vector<long long> t;
  vector<long long> lazy;
  vector<long long> setv;
  maxt(int l, long long val) {
    tl = l;
    t = vector<long long>(tl << 2, val);
    lazy = vector<long long>(tl << 2, 0);
    setv = vector<long long>(tl << 2, -1);
  }
  long long task(long long child1, long long child2) {
    return max(child1, child2);
  }
  void push(vector<long long>& segment_tree, int node, int l, int r) {
    int child1 = node << 1;
    int child2 = (node << 1) + 1;
    int mid = (l + r) >> 1;
    if (setv[node] != -1) {
      lazy[child1] = 0;
      lazy[child2] = 0;
      setv[child1] = setv[node];
      setv[child2] = setv[node];
      segment_tree[child1] = setv[node];
      segment_tree[child2] = setv[node];
      setv[node] = -1;
    }
    lazy[child1] += lazy[node];
    lazy[child2] += lazy[node];
    segment_tree[child1] += lazy[node];
    segment_tree[child2] += lazy[node];
    lazy[node] = 0;
  }
  void make(vector<long long>& segment_tree, int node, int l, int r, int lq,
            int rq, long long val) {
    if (lq > rq) {
      return;
    }
    if (l == lq && r == rq) {
      lazy[node] = 0;
      segment_tree[node] = val;
      setv[node] = val;
    } else {
      push(segment_tree, node, l, r);
      int mid = (l + r) >> 1;
      make(segment_tree, node << 1, l, mid, lq, min(mid, rq), val);
      make(segment_tree, (node << 1) + 1, mid + 1, r, max(mid + 1, lq), rq,
           val);
      segment_tree[node] =
          task(segment_tree[node << 1], segment_tree[(node << 1) + 1]);
    }
  }
  void make(int lq, int rq, long long val) {
    make(t, 1, 0, tl - 1, lq, rq, val);
  }
  void add(vector<long long>& segment_tree, int node, int l, int r, int lq,
           int rq, long long val) {
    if (lq > rq) {
      return;
    }
    if (l == lq && r == rq) {
      lazy[node] += val;
      segment_tree[node] += val;
    } else {
      push(segment_tree, node, l, r);
      int mid = (l + r) >> 1;
      add(segment_tree, node << 1, l, mid, lq, min(mid, rq), val);
      add(segment_tree, (node << 1) + 1, mid + 1, r, max(mid + 1, lq), rq, val);
      segment_tree[node] =
          task(segment_tree[node << 1], segment_tree[(node << 1) + 1]);
    }
  }
  void add(int lq, int rq, long long val) { add(t, 1, 0, tl - 1, lq, rq, val); }
  long long query(vector<long long>& segment_tree, int node, int l, int r,
                  int lq, int rq) {
    if (lq > rq) {
      return -infinity;
    } else if (lq <= l && rq >= r) {
      return segment_tree[node];
    } else {
      push(segment_tree, node, l, r);
      int mid = (l + r) >> 1;
      return task(query(segment_tree, node << 1, l, mid, lq, min(rq, mid)),
                  query(segment_tree, (node << 1) + 1, mid + 1, r,
                        max(lq, mid + 1), rq));
    }
  }
  long long query(int lq, int rq) { return query(t, 1, 0, tl - 1, lq, rq); }
  void build(vector<long long>& segment_tree, vector<long long>& v, int node,
             int l, int r) {
    if (l == r) {
      segment_tree[node] = v[l];
    } else {
      int mid = (l + r) >> 1;
      build(segment_tree, v, node << 1, l, mid);
      build(segment_tree, v, (node << 1) + 1, mid + 1, r);
      segment_tree[node] =
          task(segment_tree[node << 1], segment_tree[(node << 1) + 1]);
    }
  }
  void build(vector<long long>& v) { build(t, v, 1, 0, tl - 1); }
};
struct mint {
  int tl;
  vector<long long> t;
  vector<long long> lazy;
  vector<long long> setv;
  mint(int l, long long val) {
    tl = l;
    t = vector<long long>(tl << 2, val);
    lazy = vector<long long>(tl << 2, 0);
    setv = vector<long long>(tl << 2, -1);
  }
  long long task(long long child1, long long child2) {
    return min(child1, child2);
  }
  void push(vector<long long>& segment_tree, int node, int l, int r) {
    int child1 = node << 1;
    int child2 = (node << 1) + 1;
    int mid = (l + r) >> 1;
    if (setv[node] != -1) {
      lazy[child1] = 0;
      lazy[child2] = 0;
      setv[child1] = setv[node];
      setv[child2] = setv[node];
      segment_tree[child1] = setv[node];
      segment_tree[child2] = setv[node];
      setv[node] = -1;
    }
    lazy[child1] += lazy[node];
    lazy[child2] += lazy[node];
    segment_tree[child1] += lazy[node];
    segment_tree[child2] += lazy[node];
    lazy[node] = 0;
  }
  void make(vector<long long>& segment_tree, int node, int l, int r, int lq,
            int rq, long long val) {
    if (lq > rq) {
      return;
    }
    if (l == lq && r == rq) {
      lazy[node] = 0;
      segment_tree[node] = val;
      setv[node] = val;
    } else {
      push(segment_tree, node, l, r);
      int mid = (l + r) >> 1;
      make(segment_tree, node << 1, l, mid, lq, min(mid, rq), val);
      make(segment_tree, (node << 1) + 1, mid + 1, r, max(mid + 1, lq), rq,
           val);
      segment_tree[node] =
          task(segment_tree[node << 1], segment_tree[(node << 1) + 1]);
    }
  }
  void make(int lq, int rq, long long val) {
    make(t, 1, 0, tl - 1, lq, rq, val);
  }
  void add(vector<long long>& segment_tree, int node, int l, int r, int lq,
           int rq, long long val) {
    if (lq > rq) {
      return;
    }
    if (l == lq && r == rq) {
      lazy[node] += val;
      segment_tree[node] += val;
    } else {
      push(segment_tree, node, l, r);
      int mid = (l + r) >> 1;
      add(segment_tree, node << 1, l, mid, lq, min(mid, rq), val);
      add(segment_tree, (node << 1) + 1, mid + 1, r, max(mid + 1, lq), rq, val);
      segment_tree[node] =
          task(segment_tree[node << 1], segment_tree[(node << 1) + 1]);
    }
  }
  void add(int lq, int rq, long long val) { add(t, 1, 0, tl - 1, lq, rq, val); }
  long long query(vector<long long>& segment_tree, int node, int l, int r,
                  int lq, int rq) {
    if (lq > rq) {
      return infinity;
    } else if (lq <= l && rq >= r) {
      return segment_tree[node];
    } else {
      push(segment_tree, node, l, r);
      int mid = (l + r) >> 1;
      return task(query(segment_tree, node << 1, l, mid, lq, min(rq, mid)),
                  query(segment_tree, (node << 1) + 1, mid + 1, r,
                        max(lq, mid + 1), rq));
    }
  }
  long long query(int lq, int rq) { return query(t, 1, 0, tl - 1, lq, rq); }
  void build(vector<long long>& segment_tree, vector<long long>& v, int node,
             int l, int r) {
    if (l == r) {
      segment_tree[node] = v[l];
    } else {
      int mid = (l + r) >> 1;
      build(segment_tree, v, node << 1, l, mid);
      build(segment_tree, v, (node << 1) + 1, mid + 1, r);
      segment_tree[node] =
          task(segment_tree[node << 1], segment_tree[(node << 1) + 1]);
    }
  }
  void build(vector<long long>& v) { build(t, v, 1, 0, tl - 1); }
};
void solve() {
  int len, nq;
  cin >> len >> nq;
  vector<long long> a(len), b(len), ps(len, 0);
  for (int i = 0; i < len; i++) cin >> a[i];
  ;
  for (int i = 0; i < len; i++) cin >> b[i];
  ;
  ps[0] = b[0] - a[0];
  for (int i = 1; i < len; i++) {
    ps[i] = ps[i - 1] + b[i] - a[i];
  }
  maxt M(len, 0);
  mint m(len, 0);
  M.build(ps);
  m.build(ps);
  for (int i = 0; i < nq; i++) {
    int l, r;
    cin >> l >> r;
    l--;
    r--;
    long long sub = (l ? ps[l - 1] : 0);
    long long sum = (l ? (ps[r] - ps[l - 1]) : ps[r]);
    long long Mval = M.query(l, r) - sub;
    long long mval = m.query(l, r) - sub;
    if (sum != 0 || mval < 0) {
      cout << -1 << "\n";
    } else {
      cout << Mval << "\n";
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int q = 1;
  while (q-- > 0) {
    solve();
  }
  return 0;
}

```