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 N = 600600;
const int Mod = 1e9 + 7;
const int Inv2 = 500000004;
int Two[N][2];
void add_self(int& x, int y) {
  if ((x += y) >= Mod) x -= Mod;
}
void sub_self(int& x, int y) {
  if ((x -= y) < 0) x += Mod;
}
int add(int x, int y) { return add_self(x, y), x; }
int sub(int x, int y) { return sub_self(x, y), x; }
int mul(int x, int y) { return (long long)x * y % Mod; }
template <typename type>
struct SegmentTreeWithoutLazyPropagation {
 private:
  const type E = 0;

 private:
  static const int Nax = 4 * N;

 private:
  int n;

 private:
  type Tree[Nax];

 public:
  SegmentTreeWithoutLazyPropagation(int n = 0) : n(n) {
    for (int Node = 0; Node < Nax; Node++) Tree[Node] = E;
  }

 private:
  type Unite(type x, type y) { return x + y; }

 private:
  void Merge(int Node) {
    Tree[Node] = Unite(Tree[(Node << 1)], Tree[(Node << 1 | 1)]);
  }

 public:
  void Build(const vector<type>& a) {
    Clear();
    n = a.size();
    Build(a, 1, 0, n - 1);
  }

 private:
  void Build(const vector<type>& a, int Node, int L, int R) {
    Tree[Node] = E;
    if (L == R) return void(Tree[Node] = a[L]);
    Build(a, (Node << 1), L, ((L + R) >> 1));
    Build(a, (Node << 1 | 1), ((L + R) >> 1) + 1, R);
    Merge(Node);
  }

 public:
  void Update(int i, type x) {
    if (n <= 0) return;
    Update(i, x, 1, 0, n - 1);
  }

 private:
  void Update(int i, type x, int Node, int L, int R) {
    if (i < L || R < i) return;
    if (L == R) return void(Tree[Node] = x);
    Update(i, x, (Node << 1), L, ((L + R) >> 1));
    Update(i, x, (Node << 1 | 1), ((L + R) >> 1) + 1, R);
    Merge(Node);
  }

 public:
  type Query(int i, int j) {
    if (n <= 0 || i > j) return E;
    return Query(i, j, 1, 0, n - 1);
  }

 private:
  type Query(int i, int j, int Node, int L, int R) {
    if (j < L || R < i) return E;
    if (i <= L && R <= j) return Tree[Node];
    return Unite(Query(i, j, (Node << 1), L, ((L + R) >> 1)),
                 Query(i, j, (Node << 1 | 1), ((L + R) >> 1) + 1, R));
  }

 public:
  void Clear() {
    for (int Node = 0; Node <= 4 * n; Node++) Tree[Node] = E;
    n = 0;
  }
};
template <typename type>
struct SegmentTreeWithLazyPropagation {
 private:
  const type E = 0;

 private:
  const type EL = 1;

 private:
  static const int Nax = 4 * N;

 private:
  int n;

 private:
  type Tree[Nax];

 private:
  type Lazy[Nax];

 public:
  SegmentTreeWithLazyPropagation(int n = 0) : n(n) {
    for (int Node = 0; Node < Nax; Node++) Tree[Node] = E, Lazy[Node] = EL;
  }

 private:
  type Unite(type x, type y) { return add(x, y); }

 private:
  void Merge(int Node) {
    Tree[Node] = Unite(Tree[(Node << 1)], Tree[(Node << 1 | 1)]);
  }

 private:
  void PushLazy(int Node, int Len) {
    if (Lazy[Node] != EL) {
      Tree[Node] = mul(Tree[Node], Lazy[Node]);
      if (Len > 1) {
        Lazy[(Node << 1)] = mul(Lazy[(Node << 1)], Lazy[Node]);
        Lazy[(Node << 1 | 1)] = mul(Lazy[(Node << 1 | 1)], Lazy[Node]);
      }
      Lazy[Node] = EL;
    }
  }

 public:
  void Build(const vector<type>& a) {
    Clear();
    n = a.size();
    Build(a, 1, 0, n - 1);
  }

 private:
  void Build(const vector<type>& a, int Node, int L, int R) {
    Tree[Node] = E, Lazy[Node] = EL;
    if (L == R) return void(Tree[Node] = a[L]);
    Build(a, (Node << 1), L, ((L + R) >> 1));
    Build(a, (Node << 1 | 1), ((L + R) >> 1) + 1, R);
    Merge(Node);
  }

 public:
  void Update(int i, int j, type x) {
    if (n <= 0 || i > j) return;
    Update(i, j, x, 1, 0, n - 1);
  }

 private:
  void Update(int i, int j, type x, int Node, int L, int R) {
    PushLazy(Node, R - L + 1);
    if (j < L || R < i) return;
    if (i <= L && R <= j) return Lazy[Node] = x, PushLazy(Node, R - L + 1);
    Update(i, j, x, (Node << 1), L, ((L + R) >> 1));
    Update(i, j, x, (Node << 1 | 1), ((L + R) >> 1) + 1, R);
    Merge(Node);
  }

 public:
  void Update(int i, type x) {
    if (n <= 0) return;
    Update(i, x, 1, 0, n - 1);
  }

 private:
  void Update(int i, type x, int Node, int L, int R) {
    PushLazy(Node, R - L + 1);
    if (i < L || R < i) return;
    if (L == R) return void(Tree[Node] = x);
    Update(i, x, (Node << 1), L, ((L + R) >> 1));
    Update(i, x, (Node << 1 | 1), ((L + R) >> 1) + 1, R);
    Merge(Node);
  }

 public:
  type Query(int i, int j) {
    if (n <= 0 || i > j) return E;
    return Query(i, j, 1, 0, n - 1);
  }

 private:
  type Query(int i, int j, int Node, int L, int R) {
    PushLazy(Node, R - L + 1);
    if (j < L || R < i) return E;
    if (i <= L && R <= j) return Tree[Node];
    return Unite(Query(i, j, (Node << 1), L, ((L + R) >> 1)),
                 Query(i, j, (Node << 1 | 1), ((L + R) >> 1) + 1, R));
  }

 public:
  void Clear() {
    for (int Node = 0; Node <= 4 * n; Node++) Tree[Node] = E, Lazy[Node] = EL;
    n = 0;
  }
};
SegmentTreeWithLazyPropagation<int> myTree[2];
SegmentTreeWithoutLazyPropagation<int> CntTree;
int main() {
  Two[0][0] = Two[0][1] = 1;
  for (int i = 1; i < N; i++) Two[i][0] = mul(2, Two[i - 1][0]);
  for (int i = 1; i < N; i++) Two[i][1] = mul(Inv2, Two[i - 1][1]);
  int n;
  cin >> n;
  vector<int> a(n);
  for (int& x : a) scanf("%d", &x);
  int q;
  cin >> q;
  vector<pair<int, int> > Q(q);
  for (pair<int, int>& x : Q) scanf("%d%d", &x.first, &x.second);
  vector<pair<int, int> > A;
  for (int i = 0; i < n; i++) A.emplace_back(a[i], i);
  for (int i = 0; i < q; i++) A.emplace_back(Q[i].second, i + n);
  sort(A.begin(), A.end());
  vector<int> Where(n + q);
  for (int i = 0; i < n + q; i++) Where[A[i].second] = i;
  CntTree.Build(vector<int>(n + q));
  for (int i = 0; i < n + q; i++)
    if (A[i].second < n) CntTree.Update(i, 1);
  for (int j = 0; j < 2; j++) {
    vector<int> b(n + q);
    for (int i = 0, r = 0; i < n + q; i++)
      if (A[i].second < n) b[i] = mul(Two[r++][j], A[i].first);
    myTree[j].Build(b);
  }
  int Ans = 0;
  for (int i = 0, r = 0; i < n + q; i++)
    if (A[i].second < n)
      add_self(Ans,
               mul(mul(Two[r++][1], A[i].first), myTree[0].Query(0, i - 1)));
  printf("%d\n", mul(Inv2, Ans));
  vector<int> Last(n);
  for (int i = 0; i < n; i++) Last[i] = Where[i];
  for (int j = 0; j < q; j++) {
    int i = Q[j].first;
    int x = Q[j].second;
    int k = Where[j + n];
    {
      int I = --i;
      i = Last[i];
      Last[I] = k;
    }
    sub_self(Ans, mul(mul(Two[CntTree.Query(0, i - 1)][1], A[i].first),
                      myTree[0].Query(0, i - 1)));
    sub_self(Ans, mul(mul(Two[CntTree.Query(0, i - 1)][0], A[i].first),
                      myTree[1].Query(i + 1, n + q - 1)));
    sub_self(Ans,
             mul(myTree[0].Query(0, i - 1), myTree[1].Query(i + 1, n + q - 1)));
    CntTree.Update(i, 0);
    myTree[0].Update(i, 0);
    myTree[1].Update(i, 0);
    myTree[0].Update(i + 1, n + q - 1, Inv2);
    myTree[1].Update(i + 1, n + q - 1, 2);
    add_self(Ans,
             mul(myTree[0].Query(0, i - 1), myTree[1].Query(i + 1, n + q - 1)));
    sub_self(Ans,
             mul(myTree[0].Query(0, k - 1), myTree[1].Query(k + 1, n + q - 1)));
    CntTree.Update(k, 1);
    myTree[0].Update(k + 1, n + q - 1, 2);
    myTree[1].Update(k + 1, n + q - 1, Inv2);
    myTree[0].Update(k, mul(Two[CntTree.Query(0, k - 1)][0], A[k].first));
    myTree[1].Update(k, mul(Two[CntTree.Query(0, k - 1)][1], A[k].first));
    add_self(Ans,
             mul(myTree[0].Query(0, k - 1), myTree[1].Query(k + 1, n + q - 1)));
    add_self(Ans, mul(mul(Two[CntTree.Query(0, k - 1)][1], A[k].first),
                      myTree[0].Query(0, k - 1)));
    add_self(Ans, mul(mul(Two[CntTree.Query(0, k - 1)][0], A[k].first),
                      myTree[1].Query(k + 1, n + q - 1)));
    printf("%d\n", mul(Inv2, Ans));
  }
}