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 MAXN = 500005;
int stot, stop, sstk[MAXN], n, root1, root2, root3, root, l1, r1, m, pos, x;
const long long mod = 1e9 + 7;
const long long inv2 = 500000004;
int id[MAXN];
long long pw2[MAXN];
struct arrnode {
  long long val;
  int id;
} arr[MAXN];
bool cmp(const arrnode &A, const arrnode &B) { return A.val < B.val; }
long long quickpow(long long x, long long y) {
  long long ans = 1;
  while (y) {
    if (y & 1) {
      ans = (x * ans) % mod;
    }
    x = (x * x) % mod;
    y >>= 1;
  }
  return ans;
}
struct tree {
  int ch[2];
  int fa;
  long long size;
  long long num;
  long long pre, suf, sum, ans;
} t[MAXN];
tree operator+(const tree &a, const tree &b) {
  tree c;
  c.ans = (a.ans * pw2[b.size] + b.suf * a.pre + b.ans * pw2[a.size]) % mod;
  c.pre = (a.pre + b.pre * pw2[a.size] % mod) % mod;
  c.size = a.size + b.size;
  c.suf = (b.suf + a.suf * pw2[b.size] % mod) % mod;
  return c;
}
void update(int root) {
  tree temp;
  temp.size = 1;
  temp.suf = t[root].num;
  temp.ans = 0;
  temp.pre = t[root].num;
  if (t[root].ch[0]) {
    temp = t[t[root].ch[0]] + temp;
  }
  if (t[root].ch[1]) {
    temp = temp + t[t[root].ch[1]];
  }
  t[root].ans = temp.ans;
  t[root].size = temp.size;
  t[root].pre = temp.pre;
  t[root].suf = temp.suf;
}
void rot(int root) {
  int fa = t[root].fa;
  int gfa = t[fa].fa;
  int t1 = (root != t[fa].ch[0]);
  int t2 = (fa != t[gfa].ch[0]);
  int ch = t[root].ch[1 ^ t1];
  t[root].fa = gfa;
  t[root].ch[1 ^ t1] = fa;
  t[fa].ch[0 ^ t1] = ch;
  t[fa].fa = root;
  t[ch].fa = fa;
  t[gfa].ch[0 ^ t2] = root;
  update(fa);
  return;
}
int splay(int root) {
  while (t[root].fa) {
    int fa = t[root].fa, gfa = t[fa].fa;
    if (gfa) {
      (t[fa].ch[0] == root) ^ (t[gfa].ch[0] == fa) ? rot(root) : rot(fa);
    }
    rot(root);
  }
  update(root);
  return root;
}
int kth(int root, int k) {
  for (;;) {
    if (k <= t[t[root].ch[0]].size) {
      root = t[root].ch[0];
    } else if (k > t[t[root].ch[0]].size + 1) {
      k -= t[t[root].ch[0]].size + 1;
      root = t[root].ch[1];
    } else {
      return splay(root);
    }
  }
}
int findnum(int root, int num) {
  while (root && t[root].num != num && t[root].ch[num > t[root].num])
    root = t[root].ch[num > t[root].num];
  return splay(root);
}
int findpre(int root) {
  root = t[root].ch[0];
  while (t[root].ch[1]) root = t[root].ch[1];
  return splay(root);
}
int findnex(int root) {
  root = t[root].ch[1];
  while (t[root].ch[0]) root = t[root].ch[0];
  return splay(root);
}
int links(int root1, int root2) {
  if (!root1 || !root2) return root1 | root2;
  root1 = kth(root1, t[root1].size);
  t[root1].ch[1] = root2;
  t[root2].fa = root1;
  update(root1);
  return root1;
}
void cuts(int root, int k, int &root1, int &root2) {
  if (k == 0) {
    root1 = 0;
    root2 = root;
    return;
  }
  root1 = kth(root, k);
  root2 = t[root1].ch[1];
  t[root1].ch[1] = t[root2].fa = 0;
  update(root1);
  return;
}
int build(int l, int r) {
  if (r < l) return 0;
  int mid = (l + r) >> 1;
  int new_node = ++stot;
  t[new_node].size = 1;
  t[new_node].num = arr[mid].val;
  id[arr[mid].id] = new_node;
  t[new_node].fa = 0;
  t[new_node].ch[0] = build(l, mid - 1);
  t[new_node].ch[1] = build(mid + 1, r);
  t[t[new_node].ch[0]].fa = new_node;
  t[t[new_node].ch[1]].fa = new_node;
  update(new_node);
  return new_node;
}
void dfs(int root) {
  if (t[root].ch[0]) {
    dfs(t[root].ch[0]);
  }
  cout << "root " << root << ":" << t[root].num << " " << t[root].size << endl;
  if (t[root].ch[1]) {
    dfs(t[root].ch[1]);
  }
  return;
}
int main() {
  pw2[0] = 1;
  for (int i = 1; i <= 300000; ++i) {
    pw2[i] = pw2[i - 1] * 2 % mod;
  }
  scanf("%d", &n);
  if (n == 1) {
    scanf("%*d");
    scanf("%d", &m);
    for (int i = 0; i <= m; ++i) {
      printf("0\n");
    }
    return 0;
  }
  for (int i = 1; i <= n; ++i) {
    scanf("%lld", &arr[i].val);
    arr[i].id = i;
  }
  sort(arr + 1, arr + 1 + n, cmp);
  root = build(1, n);
  printf("%lld\n", t[root].ans * quickpow(inv2, n) % mod);
  scanf("%d", &m);
  while (m--) {
    scanf("%d %d", &pos, &x);
    root = splay(id[pos]);
    root1 = t[root].ch[0];
    t[root1].fa = t[root].ch[0] = 0;
    root2 = t[root].ch[1];
    t[root2].fa = t[root].ch[1] = 0;
    root3 = root;
    t[root3].num = x;
    update(root3);
    root = links(root1, root2);
    root = findnum(root, x);
    if (t[root].num > x) {
      if (t[root].ch[0] == 0) {
        root = links(root3, root);
      } else {
        root = findpre(root);
        root2 = t[root].ch[1];
        t[root2].fa = t[root].ch[1] = 0;
        update(root);
        root = links(root, root3);
        root = links(root, root2);
      }
    } else {
      if (t[root].ch[1] == 0) {
        root = links(root, root3);
      } else {
        root = findnex(root);
        root2 = t[root].ch[0];
        t[root2].fa = t[root].ch[0] = 0;
        update(root);
        root1 = root;
        root = links(root2, root3);
        root = links(root, root1);
      }
    }
    printf("%lld\n", t[root].ans * quickpow(inv2, n) % mod);
  }
  return 0;
}