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;
const int mod = 1e9 + 7;
inline int add(int a, int b) {
  a += b;
  if (a >= mod) a -= mod;
  return a;
}
inline int sub(int a, int b) {
  a -= b;
  if (a < 0) a += mod;
  return a;
}
inline int mul(int a, int b) { return (a * 1ll * b) % mod; }
inline int power(int a, int b) {
  int rt = 1;
  while (b > 0) {
    if (b & 1) rt = mul(rt, a);
    a = mul(a, a);
    b >>= 1;
  }
  return rt;
}
inline int inv(int a) { return power(a, mod - 2); }
const int N = 1e6 + 10, inv2 = inv(2);
map<int, int> idx;
vector<int> v(N), iai(N), jaj(N), pows(N), invp(N);
int n, m;
class SegmentTree {
 public:
  vector<int> array, sum, lz;
  int n;
  SegmentTree(vector<int> &v) {
    n = v.size();
    array = v;
    sum.resize(4 * n), lz.resize(4 * n, 1);
    this->build(0, n - 1);
  }
  void build(int start, int end, int pos = 1) {
    if (start == end) {
      sum[pos] = array[start];
      return;
    }
    int mid = start + end >> 1;
    build(start, mid, pos * 2);
    build(mid + 1, end, pos * 2 + 1);
    sum[pos] = add(sum[pos * 2], sum[pos * 2 + 1]);
  }
  pair<int, int> mult(int l, int r, int num) {
    return this->mult(0, n - 1, l, r, num);
  }
  int equate(int l, int num) { return this->equate(0, n - 1, l, num); }
  int getsum(int l, int r) { return this->getsum(0, n - 1, l, r); }
  inline void ppgt(int pos) {
    if (lz[pos] == 1) return;
    lz[pos * 2] = mul(lz[pos * 2], lz[pos]);
    lz[pos * 2 + 1] = mul(lz[pos * 2 + 1], lz[pos]);
    sum[pos * 2] = mul(sum[pos * 2], lz[pos]);
    sum[pos * 2 + 1] = mul(sum[pos * 2 + 1], lz[pos]);
    lz[pos] = 1;
  }
  pair<int, int> mult(int start, int end, int l, int r, int num, int pos = 1) {
    if (start > r || end < l) return {0, 0};
    if (start >= l && end <= r) {
      int p = sum[pos];
      lz[pos] = mul(lz[pos], num), sum[pos] = mul(sum[pos], num);
      return {p, sum[pos]};
    }
    ppgt(pos);
    int mid = start + end >> 1;
    pair<int, int> p1 = mult(start, mid, l, r, num, pos * 2),
                   p2 = mult(mid + 1, end, l, r, num, pos * 2 + 1);
    sum[pos] = add(sum[pos * 2], sum[pos * 2 + 1]);
    return {add(p1.first, p2.first), add(p1.second, p2.second)};
  }
  int equate(int start, int end, int l, int num, int pos = 1) {
    if (start == l && end == l) {
      int prev = sum[pos];
      sum[pos] = num;
      return prev;
    }
    ppgt(pos);
    int mid = start + end >> 1, ret;
    if (mid >= l)
      ret = equate(start, mid, l, num, pos * 2);
    else
      ret = equate(mid + 1, end, l, num, pos * 2 + 1);
    sum[pos] = add(sum[pos * 2], sum[pos * 2 + 1]);
    return ret;
  }
  int getsum(int start, int end, int l, int r, int pos = 1) {
    if (start > r || end < l) return 0;
    if (start >= l && end <= r) return sum[pos];
    ppgt(pos);
    int mid = start + end >> 1;
    return add(getsum(start, mid, l, r, pos * 2),
               getsum(mid + 1, end, l, r, pos * 2 + 1));
  }
};
inline int get_order(int num, int ad) {
  if (ad == 1) return idx[num]++;
  return --idx[num];
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout << setprecision(25);
  pows[0] = invp[0] = 1;
  for (int i = 1; i < N; i++)
    pows[i] = mul(pows[i - 1], 2), invp[i] = mul(invp[i - 1], inv2);
  cin >> n;
  vector<int> arr(n), alln;
  for (int i = 0; i < n; i++) cin >> arr[i], alln.push_back(arr[i]);
  int q;
  cin >> q;
  vector<pair<int, int> > queries;
  for (int i = 0; i < q; i++) {
    int id, num;
    cin >> id >> num;
    queries.push_back({--id, num}), alln.push_back(num);
  }
  sort(alln.begin(), alln.end());
  m = alln.size();
  vector<int> numtot(m);
  iai.resize(m), jaj.resize(m);
  for (int i = 0; i < m; i++) {
    if (i == 0 || alln[i] != alln[i - 1]) idx[alln[i]] = i;
  }
  vector<int> arr1 = arr;
  sort(arr1.begin(), arr1.end());
  for (int i = 0; i < n; i++) {
    int id = get_order(arr1[i], 1);
    iai[id] = mul(pows[i], arr1[i]);
    jaj[id] = mul(invp[i], arr1[i]);
    numtot[id] = 1;
  }
  SegmentTree sumiai(iai), sumjaj(jaj), sumidx(numtot);
  int ans = 0;
  for (int i = 0; i < m - 1; i++)
    ans = add(ans, mul(iai[i], sumjaj.getsum(i + 1, m - 1)));
  cout << mul(ans, inv2) << "\n";
  for (int i = 0; i < q; i++) {
    int a = queries[i].first, id1 = get_order(arr[a], -1),
        id2 = get_order(arr[a] = queries[i].second, 1);
    pair<int, int> p1, p2;
    int sum1 = 0, newiai = sumiai.equate(id1, 0),
        newjaj = sumjaj.equate(id1, 0);
    if (id1 < m - 1)
      p1 = sumiai.mult(id1 + 1, m - 1, inv2),
      p2 = sumjaj.mult(id1 + 1, m - 1, 2);
    if (id1 > 0) {
      sum1 = sumiai.getsum(0, id1 - 1);
      ans = sub(ans, mul(newjaj, sum1));
    }
    if (id1 < m - 1) ans = sub(ans, mul(newiai, p2.first));
    if (id1 > 0 && id1 < m - 1)
      ans = add(ans, mul(sum1, sub(p2.second, p2.first)));
    sumidx.equate(id1, 0), sumidx.equate(id2, 1);
    int tot = sumidx.getsum(0, id2) - 1;
    newiai = mul(arr[a], pows[tot]), newjaj = mul(arr[a], invp[tot]);
    sumiai.equate(id2, newiai), sumjaj.equate(id2, newjaj);
    sum1 = 0, p1 = p2 = {0, 0};
    if (id2 < m - 1)
      p1 = sumiai.mult(id2 + 1, m - 1, 2),
      p2 = sumjaj.mult(id2 + 1, m - 1, inv2);
    if (id2 > 0) {
      sum1 = sumiai.getsum(0, id2 - 1);
      ans = add(ans, mul(newjaj, sum1));
    }
    if (id2 < m - 1) ans = add(ans, mul(newiai, p2.second));
    if (id2 > 0 && id2 < m - 1)
      ans = add(ans, mul(sum1, sub(p2.second, p2.first)));
    cout << mul(ans, inv2) << "\n";
  }
}