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;
double PI = 3.141592653589793238462643383279;
const double EPS = 1e-9;
const long long MOD = 1000000007;
const int inf = 1 << 30;
const long long linf = 1LL << 60;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template <int mod>
struct ModInt {
  int x;
  ModInt() : x(0) {}
  ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
  ModInt &operator+=(const ModInt &p) {
    if ((x += p.x) >= mod) x -= mod;
    return *this;
  }
  ModInt &operator-=(const ModInt &p) {
    if ((x += mod - p.x) >= mod) x -= mod;
    return *this;
  }
  ModInt &operator*=(const ModInt &p) {
    x = (int)(1LL * x * p.x % mod);
    return *this;
  }
  ModInt &operator/=(const ModInt &p) {
    *this *= p.inverse();
    return *this;
  }
  ModInt operator-() const { return ModInt(-x); }
  ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
  ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
  ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
  ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
  bool operator==(const ModInt &p) const { return x == p.x; }
  bool operator!=(const ModInt &p) const { return x != p.x; }
  ModInt inverse() const {
    int a = x, b = mod, u = 1, v = 0, t;
    while (b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ModInt(u);
  }
  ModInt pow(int64_t n) const {
    ModInt ret(1), mul(x);
    while (n > 0) {
      if (n & 1) ret *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ret;
  }
  friend ostream &operator<<(ostream &os, const ModInt &p) { return os << p.x; }
  friend istream &operator>>(istream &is, ModInt &a) {
    int64_t t;
    is >> t;
    a = ModInt<mod>(t);
    return (is);
  }
  static int get_mod() { return mod; }
};
using mint = ModInt<MOD>;
template <typename T>
struct Segtree {
  int n;
  T unit;
  vector<T> segsum, segadd, segmul;
  void init(int n_) {
    n = 1;
    unit = 0;
    while (n < n_) n *= 2;
    segsum.assign(2 * n - 1, 0);
    segadd.assign(2 * n - 1, 0);
    segmul.assign(2 * n - 1, 1);
  }
  void build(int n_, vector<T> &v) {
    for (long long i = 0; i < (long long)n_; i++) segsum[i + n - 1] = v[i];
    for (int i = n - 2; i >= 0; i--) {
      segsum[i] = segsum[i * 2 + 1] + segsum[i * 2 + 2];
    }
  }
  inline void eval(int len, int k) {
    if (segmul[k] == 1 && segadd[k] == 0) return;
    if (k < n - 1) {
      segmul[k * 2 + 1] *= segmul[k];
      segadd[k * 2 + 1] = segadd[k * 2 + 1] * segmul[k] + segadd[k];
      segmul[k * 2 + 2] *= segmul[k];
      segadd[k * 2 + 2] = segadd[k * 2 + 2] * segmul[k] + segadd[k];
    }
    segsum[k] = segsum[k] * segmul[k] + segadd[k] * len;
    segadd[k] = 0;
    segmul[k] = 1;
  }
  T update(int a, int b, int k, int l, int r, T vm, T va) {
    eval(r - l, k);
    if (b <= l || a >= r) return segsum[k];
    if (a <= l && r <= b) {
      segmul[k] = vm;
      segadd[k] = va;
      return segsum[k] * segmul[k] + segadd[k] * (r - l);
    }
    T lm = update(a, b, k * 2 + 1, l, (l + r) / 2, vm, va);
    T rm = update(a, b, k * 2 + 2, (l + r) / 2, r, vm, va);
    return segsum[k] = lm + rm;
  }
  T query(int a, int b, int k, int l, int r) {
    if (b <= l || a >= r) return unit;
    eval(r - l, k);
    if (a <= l && r <= b) return segsum[k];
    T lm = query(a, b, k * 2 + 1, l, (l + r) / 2);
    T rm = query(a, b, k * 2 + 2, (l + r) / 2, r);
    return lm + rm;
  }
};
template <typename T>
struct BIT {
  vector<T> bit;
  int n;
  void init(int _n) {
    n = _n;
    bit.assign(n + 1, 0);
  }
  T sum(int _i) {
    int i = _i + 1;
    T s = 0;
    while (i > 0) {
      s += bit[i];
      i -= i & -i;
    }
    return s;
  }
  void add(int _i, T x) {
    int i = _i + 1;
    while (i <= n) {
      bit[i] += x;
      i += i & -i;
    }
  }
};
mint p2[350000], rp2[350000];
int n;
mint p[600000];
mint pre[350000];
int wh[350000];
int poss[350000];
Segtree<mint> seg1, seg2;
BIT<int> bit;
int main() {
  p2[0] = 1;
  for (long long i = 0; i < (long long)300000; i++) p2[i + 1] = p2[i] * 2;
  rp2[0] = 1;
  for (long long i = 0; i < (long long)300000; i++) {
    rp2[i + 1] = rp2[i];
    if (rp2[i + 1].x & 1) rp2[i + 1].x += MOD;
    rp2[i + 1].x /= 2;
  }
  scanf("%d", &n);
  for (long long i = 0; i < (long long)n; i++) {
    scanf("%d", &p[i].x);
  }
  int q;
  scanf("%d", &q);
  for (long long i = 0; i < (long long)q; i++) {
    scanf("%d%d", poss + i, &p[n + i].x);
    poss[i]--;
  }
  vector<int> segp_(n + q), segp(n + q), segpp(n);
  iota(segp_.begin(), segp_.end(), 0);
  sort(segp_.begin(), segp_.end(),
       [](const int &l, const int &r) { return p[l].x < p[r].x; });
  for (long long i = 0; i < (long long)n + q; i++) segp[segp_[i]] = i;
  iota(segpp.begin(), segpp.end(), 0);
  sort(segpp.begin(), segpp.end(),
       [&](const int &l, const int &r) { return segp[l] > segp[r]; });
  seg1.init(n + q);
  seg2.init(n + q);
  bit.init(n + q);
  for (long long i = 0; i < (long long)n; i++) bit.add(segp[i], 1);
  vector<mint> ini1(n + q), ini2(n + q);
  {
    int cnt = n - 1;
    for (int i : segpp) {
      ini1[segp[i]] = rp2[cnt + 1] * p[i];
      ini2[segp[i]] = p2[cnt] * p[i];
      cnt--;
    }
  }
  seg1.build(n + q, ini1);
  seg2.build(n + q, ini2);
  mint ans = 0;
  {
    mint acc = 0;
    int cnt = n - 1;
    for (int i : segpp) {
      wh[i] = segp[i];
      pre[i] = p[i];
      ans += p2[cnt] * p[i] * acc;
      acc += rp2[cnt + 1] * p[i];
      cnt--;
    }
  }
  printf("%d\n", ans.x);
  for (long long i = 0; i < (long long)q; i++) {
    int pos = wh[poss[i]];
    int cnt = bit.sum(pos) - 1;
    mint tmp = pre[poss[i]];
    mint lv = seg2.query(0, pos, 0, 0, seg2.n);
    mint rv = seg1.query(pos + 1, seg1.n, 0, 0, seg1.n);
    ans -= tmp * p2[cnt] * rv;
    ans -= tmp * lv * rp2[cnt + 1];
    ans += lv * rv;
    seg1.update(pos, pos + 1, 0, 0, seg1.n, 0, 0);
    seg2.update(pos, pos + 1, 0, 0, seg2.n, 0, 0);
    seg1.update(pos, seg1.n, 0, 0, seg1.n, 2, 0);
    seg2.update(pos, seg2.n, 0, 0, seg2.n, rp2[1], 0);
    bit.add(pos, -1);
    pos = segp[n + i];
    cnt = bit.sum(pos);
    seg1.update(pos, pos + 1, 0, 0, seg1.n, 0, rp2[cnt + 1] * p[n + i]);
    seg2.update(pos, pos + 1, 0, 0, seg2.n, 0, p2[cnt] * p[n + i]);
    seg1.update(pos + 1, seg1.n, 0, 0, seg1.n, rp2[1], 0);
    seg2.update(pos + 1, seg2.n, 0, 0, seg2.n, 2, 0);
    bit.add(pos, 1);
    lv = seg2.query(0, pos, 0, 0, seg2.n);
    rv = seg1.query(pos + 1, seg1.n, 0, 0, seg1.n);
    ans += p[n + i] * p2[cnt] * rv;
    ans += lv * rp2[cnt + 1] * p[n + i];
    ans -= rv * lv;
    pre[poss[i]] = p[n + i];
    wh[poss[i]] = segp[n + i];
    printf("%d\n", ans.x);
  }
}