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;
constexpr long long mod = 1000000007;
const long long INF = mod * mod;
const long double eps = 1e-9;
const long double pi = acos(-1.0);
long long mod_pow(long long a, long long n, long long m) {
  long long res = 1;
  while (n) {
    if (n & 1) res = res * a % m;
    a = a * a % m;
    n >>= 1;
  }
  return res;
}
string sdir = "RDLU";
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
long long t2[1 << 19];
long long invt2[1 << 19];
long long inv2;
void init(int n) {
  t2[0] = 1;
  invt2[0] = 1;
  inv2 = (1 + mod) / 2;
  for (int i = 0; i < n + 5; i++) {
    t2[i + 1] = t2[i] * 2 % mod;
    invt2[i + 1] = invt2[i] * inv2 % mod;
  }
}
struct SegT {
 private:
  int n;
  vector<long long> node, lazy;
  const long long init_c = 0;

 public:
  SegT(int sz) {
    n = 1;
    while (n < sz) n <<= 1;
    node.resize(2 * n - 1, init_c);
    lazy.resize(2 * n - 1, 1);
  }
  SegT(vector<long long> &v) {
    int sz = v.size();
    n = 1;
    while (n < sz) n <<= 1;
    node.resize(2 * n - 1, init_c);
    lazy.resize(2 * n - 1, 1);
    for (int i = 0; i < sz; i++) {
      node[i + n - 1] = v[i];
    }
    for (int i = n - 1 - 1; i >= 0; i--) {
      node[i] = f(node[2 * i + 1], node[2 * i + 2]);
    }
  }
  long long f(long long a, long long b) {
    long long res = a + b;
    if (res >= mod) res -= mod;
    return res;
  }
  void eval(int k, int l, int r) {
    if (lazy[k] == 1) return;
    node[k] = node[k] * lazy[k] % mod;
    if (r - l > 1) {
      lazy[2 * k + 1] = lazy[2 * k + 1] * lazy[k] % mod;
      lazy[2 * k + 2] = lazy[2 * k + 2] * lazy[k] % mod;
    }
    lazy[k] = 1;
  }
  void add(long long x, int a, int b, int k = 0, int l = 0, int r = -1) {
    if (r < 0) r = n;
    eval(k, l, r);
    if (r <= a || b <= l) return;
    if (a <= l && r <= b) {
      lazy[k] = lazy[k] * x % mod;
      eval(k, l, r);
    } else {
      add(x, a, b, k * 2 + 1, l, (l + r) / 2);
      add(x, a, b, k * 2 + 2, (l + r) / 2, r);
      node[k] = f(node[k * 2 + 1], node[k * 2 + 2]);
    }
  }
  long long query(int a, int b, int k = 0, int l = 0, int r = -1) {
    if (r < 0) r = n;
    eval(k, l, r);
    if (r <= a || b <= l) return init_c;
    if (a <= l && r <= b)
      return node[k];
    else {
      long long vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
      long long vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
      return f(vl, vr);
    }
  }
  void update(int c, long long x, int k = 0, int l = 0, int r = -1) {
    if (r < 0) r = n;
    eval(k, l, r);
    if (r <= c || c + 1 <= l) return;
    if (c <= l && r <= c + 1) {
      node[k] = x;
    } else {
      update(c, x, k * 2 + 1, l, (l + r) / 2);
      update(c, x, k * 2 + 2, (l + r) / 2, r);
      node[k] = f(node[2 * k + 1], node[2 * k + 2]);
    }
  }
};
struct BIT {
 private:
  vector<long long> node;
  int n;

 public:
  BIT(int n_) {
    n = n_;
    node.resize(n, 0);
  }
  void add(int a, long long w) {
    for (int i = a; i < n; i |= i + 1) node[i] += w;
  }
  long long sum(int a) {
    long long ret = 0;
    for (int i = a - 1; i >= 0; i = (i & (i + 1)) - 1) ret += node[i];
    return ret;
  }
  long long sum(int a, int b) { return sum(b) - sum(a); }
};
void solve() {
  int n;
  cin >> n;
  init(n);
  vector<pair<long long, long long> > vs;
  vector<long long> in(n);
  for (int i = 0; i < n; i++) {
    cin >> in[i];
    vs.push_back({in[i], i});
  }
  int q;
  cin >> q;
  vector<int> locs(q);
  vector<long long> vals(q);
  for (int i = 0; i < q; i++) {
    cin >> locs[i];
    locs[i]--;
    cin >> vals[i];
    vs.push_back({vals[i], i + n});
  }
  sort((vs).begin(), (vs).end());
  BIT memo(n + q);
  long long sum = 0;
  vector<long long> ori1(n + q, 0), ori2(n + q, 0);
  int tmp = 0;
  long long csum = 0;
  for (int i = 0; i < n + q; i++) {
    int id = vs[i].second;
    if (id < n) {
      long long ad = csum * invt2[tmp] % mod * inv2 % mod * in[id] % mod;
      sum += ad;
      if (sum > mod) sum -= mod;
      ori1[i] = t2[tmp] * in[id] % mod;
      ori2[i] = invt2[tmp] * in[id] % mod;
      memo.add(i, 1);
      tmp++;
      csum += ori1[i];
      if (csum >= mod) csum -= mod;
    }
  }
  SegT st1(ori1);
  SegT st2(ori2);
  vector<int> cur(n);
  vector<int> tloc(q);
  for (int i = 0; i < n + q; i++) {
    int id = vs[i].second;
    if (id < n) {
      cur[id] = i;
    } else {
      tloc[id - n] = i;
    }
  }
  cout << sum << endl;
  for (int i = 0; i < q; i++) {
    int loc = cur[locs[i]];
    long long val = in[locs[i]];
    {
      int cl = memo.sum(0, loc);
      long long lesum = st1.query(0, loc);
      long long risum = st2.query(loc + 1, n + q);
      sum += lesum * risum % mod * inv2 % mod;
      if (sum >= mod) sum -= mod;
      lesum = lesum * invt2[cl] % mod * inv2 % mod * val % mod;
      sum -= lesum;
      if (sum < 0) sum += mod;
      risum = risum * t2[cl] % mod * inv2 % mod * val % mod;
      sum -= risum;
      if (sum < 0) sum += mod;
      memo.add(loc, -1);
      st1.update(loc, 0);
      st1.add(inv2, loc + 1, n + q);
      st2.update(loc, 0);
      st2.add(2, loc + 1, n + q);
    }
    loc = tloc[i];
    val = vals[i];
    {
      int cl = memo.sum(0, loc);
      memo.add(loc, 1);
      st1.update(loc, val * t2[cl] % mod);
      st1.add(2, loc + 1, n + q);
      st2.update(loc, val * invt2[cl] % mod);
      st2.add(inv2, loc + 1, n + q);
      long long lesum = st1.query(0, loc);
      long long risum = st2.query(loc + 1, n + q);
      sum -= lesum * risum % mod * inv2 % mod;
      if (sum < 0) sum += mod;
      lesum = lesum * invt2[cl] % mod * inv2 % mod * val % mod;
      sum += lesum;
      if (sum >= mod) sum -= mod;
      risum = risum * t2[cl] % mod * inv2 % mod * val % mod;
      sum += risum;
      if (sum >= mod) sum -= mod;
    }
    in[locs[i]] = vals[i];
    cur[locs[i]] = loc;
    cout << sum << "\n";
  }
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  solve();
  char nyaa;
  cin >> nyaa;
  return 0;
}