Problem: There are n officers in the Army of Byteland. Each officer has some power associated with him. The power of the i-th officer is denoted by p_{i}. As the war is fast approaching, the General would like to know the strength of the army.

The strength of an army is calculated in a strange way in Byteland. The General selects a random subset of officers from these n officers and calls this subset a battalion.(All 2^n subsets of the n officers can be chosen equally likely, including empty subset and the subset of all officers).

The strength of a battalion is calculated in the following way:

Let the powers of the chosen officers be a_{1},a_{2},…,a_{k}, where a_1 ≤ a_2 ≤ ... ≤ a_k. The strength of this battalion is equal to a_1a_2 + a_2a_3 + ... + a_{k-1}a_k. (If the size of Battalion is ≤ 1, then the strength of this battalion is 0).

The strength of the army is equal to the expected value of the strength of the battalion.

As the war is really long, the powers of officers may change. Precisely, there will be q changes. Each one of the form i x indicating that p_{i} is changed to x.

You need to find the strength of the army initially and after each of these q updates.

Note that the changes are permanent.

The strength should be found by modulo 10^{9}+7. Formally, let M=10^{9}+7. It can be shown that the answer can be expressed as an irreducible fraction p/q, where p and q are integers and qnot≡ 0 mod M). Output the integer equal to p⋅ q^{-1} mod M. In other words, output such an integer x that 0 ≤ x < M and x ⋅ q ≡ p mod M).

Input

The first line of the input contains a single integer n (1 ≤ n ≤ 3⋅10^{5}) — the number of officers in Byteland's Army.

The second line contains n integers p_{1},p_{2},…,p_{n} (1 ≤ p_{i} ≤ 10^{9}).

The third line contains a single integer q (1 ≤ q ≤ 3⋅10^{5}) — the number of updates.

Each of the next q lines contains two integers i and x (1 ≤ i ≤ n,  1 ≤ x ≤ 10^{9}), indicating that p_{i} is updated to x .

Output

In the first line output the initial strength of the army.

In i-th of the next q lines, output the strength of the army after i-th update.

Examples

Input


2
1 2
2
1 2
2 1


Output


500000004
1
500000004


Input


4
1 2 3 4
4
1 5
2 5
3 5
4 5


Output


625000011
13
62500020
375000027
62500027

Note

In first testcase, initially, there are four possible battalions 

  * {} Strength = 0 
  * {1} Strength = 0 
  * {2} Strength = 0 
  * {1,2} Strength = 2 

So strength of army is (0+0+0+2)/(4) = 1/2

After changing p_{1} to 2, strength of battallion {1,2} changes to 4, so strength of army becomes 1.

After changing p_{2} to 1, strength of battalion {1,2} again becomes 2, so strength of army becomes 1/2.

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
int sum2(int x, int y) { return (x + y) % (1000000007); }
int mul2(int x, int y) {
  return (int)((((long long)x) * ((long long)y)) % (1000000007));
}
struct SegTree {
  typedef int T;
  T id = 0;
  T initval = 0, unused = 1;
  int S;
  vector<T> tree;
  vector<T> lazy;
  T combine(T a, T b) { return (a + b) % (1000000007); }
  T lazy_prop(T a, T b) { return mul2(a, b); }
  void unlazy(int idx, int nl, int nr) {
    tree[idx] = mul2(lazy[idx], tree[idx]);
  }
  SegTree(int N) {
    for (S = 1; S < N; S <<= 1)
      ;
    tree.resize(S * 2, initval);
    lazy.resize(S * 2, unused);
  }
  void propagate(int idx, int nl, int nr) {
    if (lazy[idx] == unused) return;
    if (idx < S) {
      lazy[idx * 2] = lazy_prop(lazy[idx * 2], lazy[idx]);
      lazy[idx * 2 + 1] = lazy_prop(lazy[idx * 2 + 1], lazy[idx]);
    }
    unlazy(idx, nl, nr);
    lazy[idx] = unused;
  }
  void update(int l, int r, T val) { update(l, r, val, 1, 1, S); }
  void update(int l, int r, T val, int idx, int nl, int nr) {
    propagate(idx, nl, nr);
    if (r < nl || nr < l) return;
    if (l <= nl && nr <= r) {
      lazy[idx] = lazy_prop(lazy[idx], val);
      propagate(idx, nl, nr);
      return;
    }
    int mid = (nl + nr) / 2;
    update(l, r, val, idx * 2, nl, mid);
    update(l, r, val, idx * 2 + 1, mid + 1, nr);
    tree[idx] = combine(tree[idx * 2], tree[idx * 2 + 1]);
  }
  void set_value(int i, T val) { set_value(i, val, 1, 1, S); }
  void set_value(int i, T val, int idx, int nl, int nr) {
    propagate(idx, nl, nr);
    if (i < nl || nr < i) return;
    if (nl == i && nr == i) {
      tree[idx] = val;
      lazy[idx] = unused;
      propagate(idx, nl, nr);
      return;
    }
    int mid = (nl + nr) / 2;
    set_value(i, val, idx * 2, nl, mid);
    set_value(i, val, idx * 2 + 1, mid + 1, nr);
    tree[idx] = combine(tree[idx * 2], tree[idx * 2 + 1]);
  }
  T query(int l, int r) { return query(l, r, 1, 1, S); }
  T query(int l, int r, int idx, int nl, int nr) {
    propagate(idx, nl, nr);
    if (r < nl || nr < l) return id;
    if (l <= nl && nr <= r) return tree[idx];
    int mid = (nl + nr) / 2;
    return combine(query(l, r, idx * 2, nl, mid),
                   query(l, r, idx * 2 + 1, mid + 1, nr));
  }
};
struct NonLazy {
  typedef int T;
  T id = 0;
  T initval = 0;
  int S;
  vector<T> tree;
  T combine(T a, T b) { return a + b; }
  NonLazy(int N) {
    for (S = 1; S < N; S <<= 1)
      ;
    tree.resize(S * 2, initval);
  }
  void set_value(int i, T val) { set_value(i, val, 1, 1, S); }
  void set_value(int i, T val, int idx, int nl, int nr) {
    if (i < nl || nr < i) return;
    if (nl == i && nr == i) {
      tree[idx] = val;
      return;
    }
    int mid = (nl + nr) / 2;
    set_value(i, val, idx * 2, nl, mid);
    set_value(i, val, idx * 2 + 1, mid + 1, nr);
    tree[idx] = combine(tree[idx * 2], tree[idx * 2 + 1]);
  }
  T query(int l, int r) { return query(l, r, 1, 1, S); }
  T query(int l, int r, int idx, int nl, int nr) {
    if (r < nl || nr < l) return id;
    if (l <= nl && nr <= r) return tree[idx];
    int mid = (nl + nr) / 2;
    return combine(query(l, r, idx * 2, nl, mid),
                   query(l, r, idx * 2 + 1, mid + 1, nr));
  }
};
struct A {
  int val;
  int idx;
};
int query[300010][2];
int index_of[600010];
int pow2[300010];
int pow2i[300010];
int main() {
  int n, q;
  scanf("%d", &n);
  pow2[0] = pow2i[0] = 1;
  for (int i = 1; i <= n; ++i) {
    pow2[i] = mul2(pow2[i - 1], 2);
    pow2i[i] = mul2(pow2i[i - 1], (500000004));
  }
  vector<A> arr;
  vector<A> array;
  A zero_idx = {0, 0};
  array.push_back(zero_idx);
  for (int i = 0; i < n; ++i) {
    A tmp;
    scanf("%d", &tmp.val);
    tmp.idx = i + 1;
    arr.push_back(tmp);
    array.push_back(tmp);
  }
  scanf("%d", &q);
  for (int i = 1; i <= q; ++i) {
    scanf("%d%d", &query[i][0], &query[i][1]);
    A tmp = {query[i][1], n + i};
    arr.push_back(tmp);
  }
  sort(arr.begin(), arr.end(),
       [](A& a, A& b) -> bool { return a.val < b.val; });
  for (int i = 0; i < n + q; ++i) {
    index_of[arr[i].idx] = i + 1;
  }
  int ans = 0;
  SegTree Pl(n + q), Mi(n + q);
  NonLazy Cnt(n + q);
  int t = 0;
  int ss = 0;
  for (int i = 1; i <= n + q; ++i) {
    if (arr[i - 1].idx > n) continue;
    Cnt.set_value(i, 1);
    ++t;
    Pl.set_value(i, mul2(pow2[t], arr[i - 1].val));
    Mi.set_value(i, mul2(pow2i[t], arr[i - 1].val));
    ans = sum2(ans, mul2(mul2(pow2i[t], arr[i - 1].val), ss));
    ss = sum2(ss, mul2(pow2[t], arr[i - 1].val));
  }
  ans = mul2(ans, (500000004));
  printf("%d\n", ans);
  for (int i = 1; i <= q; ++i) {
    int D_ans = 0;
    int x = query[i][0], y = query[i][1];
    int Bef = array[x].val;
    int Bef_i = index_of[array[x].idx];
    int Bef_cnt = Cnt.query(1, Bef_i);
    int New = y;
    int New_i = index_of[n + i];
    if (Bef_i < New_i) {
      int PlMi1 = mul2(Pl.query(1, Bef_i - 1), Mi.query(Bef_i + 1, New_i - 1));
      int PlMi2 =
          mul2(Pl.query(Bef_i + 1, New_i - 1), Mi.query(New_i + 1, n + q));
      int Bef_pl = mul2(pow2[Bef_cnt], Bef), Bef_mi = mul2(pow2i[Bef_cnt], Bef);
      D_ans =
          sum2(D_ans, (1000000007) - mul2(Bef_pl, Mi.query(Bef_i + 1, n + q)));
      D_ans = sum2(D_ans, (1000000007) - mul2(Bef_mi, Pl.query(1, Bef_i - 1)));
      D_ans = sum2(
          D_ans, ((1000000007) + (1000000007) - PlMi1 - PlMi2) % (1000000007));
      Cnt.set_value(Bef_i, 0);
      Pl.set_value(Bef_i, 0);
      Mi.set_value(Bef_i, 0);
      Pl.update(Bef_i + 1, New_i - 1, (500000004));
      Mi.update(Bef_i + 1, New_i - 1, 2);
      PlMi1 = mul2(PlMi1, 2);
      PlMi2 = mul2(PlMi2, (500000004));
      Cnt.set_value(New_i, 1);
      int New_cnt = Cnt.query(1, New_i);
      int New_pl = mul2(pow2[New_cnt], New), New_mi = mul2(pow2i[New_cnt], New);
      Pl.set_value(New_i, New_pl);
      Mi.set_value(New_i, New_mi);
      D_ans = sum2(D_ans, mul2(New_pl, Mi.query(New_i + 1, n + q)));
      D_ans = sum2(D_ans, mul2(New_mi, Pl.query(1, New_i - 1)));
      D_ans = sum2(D_ans, (PlMi1 + PlMi2) % (1000000007));
    } else {
      int PlMi1 = mul2(Pl.query(1, New_i - 1), Mi.query(New_i + 1, Bef_i - 1));
      int PlMi2 =
          mul2(Pl.query(New_i + 1, Bef_i - 1), Mi.query(Bef_i + 1, n + q));
      int Bef_pl = mul2(pow2[Bef_cnt], Bef), Bef_mi = mul2(pow2i[Bef_cnt], Bef);
      D_ans =
          sum2(D_ans, (1000000007) - mul2(Bef_pl, Mi.query(Bef_i + 1, n + q)));
      D_ans = sum2(D_ans, (1000000007) - mul2(Bef_mi, Pl.query(1, Bef_i - 1)));
      D_ans = sum2(
          D_ans, ((1000000007) + (1000000007) - PlMi1 - PlMi2) % (1000000007));
      Cnt.set_value(Bef_i, 0);
      Pl.set_value(Bef_i, 0);
      Mi.set_value(Bef_i, 0);
      Pl.update(New_i + 1, Bef_i - 1, 2);
      Mi.update(New_i + 1, Bef_i - 1, (500000004));
      PlMi1 = mul2(PlMi1, (500000004));
      PlMi2 = mul2(PlMi2, 2);
      Cnt.set_value(New_i, 1);
      int New_cnt = Cnt.query(1, New_i);
      int New_pl = mul2(pow2[New_cnt], New), New_mi = mul2(pow2i[New_cnt], New);
      Pl.set_value(New_i, New_pl);
      Mi.set_value(New_i, New_mi);
      D_ans = sum2(D_ans, mul2(New_pl, Mi.query(New_i + 1, n + q)));
      D_ans = sum2(D_ans, mul2(New_mi, Pl.query(1, New_i - 1)));
      D_ans = sum2(D_ans, (PlMi1 + PlMi2) % (1000000007));
    }
    D_ans = mul2(D_ans, (500000004));
    ans = sum2(ans, D_ans);
    printf("%d\n", ans);
    array[x].val = New;
    array[x].idx = n + i;
  }
}