Problem: Would you want to fight against bears riding horses? Me neither.

Limak is a grizzly bear. He is general of the dreadful army of Bearland. The most important part of an army is cavalry of course.

Cavalry of Bearland consists of n warriors and n horses. i-th warrior has strength wi and i-th horse has strength hi. Warrior together with his horse is called a unit. Strength of a unit is equal to multiplied strengths of warrior and horse. Total strength of cavalry is equal to sum of strengths of all n units. Good assignment of warriors and horses makes cavalry truly powerful.

Initially, i-th warrior has i-th horse. You are given q queries. In each query two warriors swap their horses with each other.

General Limak must be ready for every possible situation. What if warriors weren't allowed to ride their own horses? After each query find the maximum possible strength of cavalry if we consider assignments of all warriors to all horses that no warrior is assigned to his own horse (it can be proven that for n ≥ 2 there is always at least one correct assignment).

Note that we can't leave a warrior without a horse.

Input

The first line contains two space-separated integers, n and q (2 ≤ n ≤ 30 000, 1 ≤ q ≤ 10 000).

The second line contains n space-separated integers, w1, w2, ..., wn (1 ≤ wi ≤ 106) — strengths of warriors.

The third line contains n space-separated integers, h1, h2, ..., hn (1 ≤ hi ≤ 106) — strengths of horses.

Next q lines describe queries. i-th of them contains two space-separated integers ai and bi (1 ≤ ai, bi ≤ n, ai ≠ bi), indices of warriors who swap their horses with each other.

Output

Print q lines with answers to queries. In i-th line print the maximum possible strength of cavalry after first i queries.

Examples

Input

4 2
1 10 100 1000
3 7 2 5
2 4
2 4


Output

5732
7532


Input

3 3
7 11 5
3 2 1
1 2
1 3
2 3


Output

44
48
52


Input

7 4
1 2 4 8 16 32 64
87 40 77 29 50 11 18
1 5
2 7
6 2
5 6


Output

9315
9308
9315
9315

Note

Clarification for the first sample:

Warriors: 1 10 100 1000

Horses: 3 7 2 5 

After first query situation looks like the following:

Warriors: 1 10 100 1000

Horses: 3 5 2 7 

We can get 1·2 + 10·3 + 100·7 + 1000·5 = 5732 (note that no hussar takes his own horse in this assignment).

After second query we get back to initial situation and optimal assignment is 1·2 + 10·3 + 100·5 + 1000·7 = 7532.

Clarification for the second sample. After first query:

Warriors: 7 11 5

Horses: 2 3 1

Optimal assignment is 7·1 + 11·2 + 5·3 = 44.

Then after second query 7·3 + 11·2 + 5·1 = 48.

Finally 7·2 + 11·3 + 5·1 = 52.

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
template <class T>
void debug(T a, T b) {
  ;
}
template <class T>
void chmin(T& a, const T& b) {
  if (a > b) a = b;
}
template <class T>
void chmax(T& a, const T& b) {
  if (a < b) a = b;
}
namespace std {
template <class S, class T>
ostream& operator<<(ostream& out, const pair<S, T>& a) {
  out << '(' << a.first << ',' << a.second << ')';
  return out;
}
}  // namespace std
long long int readL() {
  long long int res;
  scanf("%I64d", &res);
  return res;
}
void printL(long long int res) { printf("%I64d", res); }
int match[30005];
struct segtree {
  int n;
  int n_;
  long long int w[30005], h[30005];
  pair<int, int> off[4] = {make_pair(-1, -1), make_pair(0, 0), make_pair(0, 1),
                           make_pair(1, 0)};
  long long int val[70000][4][4];
  void con(int i, int l, int r, int A, int B) {
    if (~A) {
      if (!(l <= A && A < r) && !(l <= B && B < r)) return;
    }
    int l2 = min(l, n_), r2 = min(r, n_);
    if (r2 - l2 == 2) {
      memset(val[i], -1, sizeof(val[i]));
      if (match[l] != l && match[l + 1] != l + 1)
        chmax(val[i][0][0], w[l] * h[l] + w[l + 1] * h[l + 1]);
      if (match[l] != l + 1 && match[l + 1] != l)
        chmax(val[i][0][0], w[l] * h[l + 1] + w[l + 1] * h[l]);
      if (match[l] != l + 1) {
        chmax(val[i][3][0], w[l] * h[l + 1]);
        chmax(val[i][0][2], w[l] * h[l + 1]);
      }
      if (match[l + 1] != l) {
        chmax(val[i][2][0], w[l + 1] * h[l]);
        chmax(val[i][0][3], w[l + 1] * h[l]);
      }
      if (match[l] != l) {
        chmax(val[i][0][1], w[l] * h[l]);
      }
      if (match[l + 1] != l + 1) {
        chmax(val[i][1][0], w[l + 1] * h[l + 1]);
      }
      {
        chmax(val[i][2][2], 0ll);
        chmax(val[i][3][3], 0ll);
        chmax(val[i][1][1], 0ll);
      };
      ;
      ;
      ;
      for (int k = 0; k < (4); ++k) debug(val[i][k], val[i][k] + 4);
      return;
    }
    if (r2 - l2 == 1) {
      memset(val[i], -1, sizeof(val[i]));
      if (match[l] != l) chmax(val[i][0][0], w[l] * h[l]);
      chmax(val[i][1][0], 0ll);
      ;
      ;
      ;
      ;
      for (int k = 0; k < (4); ++k) debug(val[i][k], val[i][k] + 4);
      return;
    }
    if (r2 - l2 == 0) {
      memset(val[i], -1, sizeof(val[i]));
      val[i][0][0] = 0;
      return;
    }
    int md = (l + r) >> 1;
    con(i * 2 + 1, l, md, A, B);
    con(i * 2 + 2, md, r, A, B);
    memset(val[i], -1, sizeof(val[i]));
    for (int x = 0; x < (4); ++x)
      for (int y = 0; y < (4); ++y)
        if (~val[i * 2 + 1][x][y])
          for (int z = 0; z < (4); ++z)
            for (int w2 = 0; w2 < (4); ++w2)
              if (~val[i * 2 + 2][z][w2]) {
                long long int sum =
                    val[i * 2 + 1][x][y] + val[i * 2 + 2][z][w2];
                if ((y > 0) ^ (z > 0)) continue;
                if (y == 0)
                  chmax(val[i][x][w2], sum);
                else {
                  int t1 = md - 1 - off[y].first, t2 = md + off[z].first,
                      b1 = md - 1 - off[y].second, b2 = md + off[z].second;
                  if (match[t1] != b2 && match[t2] != b1)
                    chmax(val[i][x][w2], sum + w[t1] * h[b2] + w[t2] * h[b1]);
                }
              };
    ;
    ;
    ;
    for (int k = 0; k < (4); ++k) debug(val[i][k], val[i][k] + 4);
  }
  void init(int n__) {
    n = 1;
    n_ = n__;
    while (n < n_) n <<= 1;
    ;
    ;
    con(0, 0, n, -1, -1);
  }
  void swap2(int a, int b) {
    swap(match[a], match[b]);
    debug(match, match + n_);
    con(0, 0, n, a, b);
  }
  long long int query() { return val[0][0][0]; }
};
int n, q;
segtree seg;
pair<int, int> w2[30005], h2[30005];
int pos[30005], pos2[30005];
int main() {
  cin >> n >> q;
  for (int i = 0; i < (n); ++i) cin >> w2[i].first, w2[i].second = i;
  for (int i = 0; i < (n); ++i) cin >> h2[i].first, h2[i].second = i;
  sort(w2, w2 + n);
  sort(h2, h2 + n);
  for (int i = 0; i < (n); ++i) pos[h2[i].second] = i, pos2[w2[i].second] = i;
  for (int i = 0; i < (n); ++i) {
    match[i] = pos[w2[i].second];
    seg.w[i] = w2[i].first;
    seg.h[i] = h2[i].first;
  }
  seg.init(n);
  debug(match, match + n);
  debug(pos2, pos2 + n);
  for (int i = 0; i < (q); ++i) {
    int a, b;
    cin >> a >> b;
    --a;
    --b;
    a = pos2[a], b = pos2[b];
    seg.swap2(a, b);
    cout << seg.query() << endl;
  }
  return 0;
}