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;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
typedef long long nval[3][3];
const int MAXN = 30000;
const int MAXVAL = 1 << 17;
int n, nq;
int have[MAXN];
int w[MAXN], h[MAXN];
inline long long calc(int a, int b) {
  return have[a] == b ? -1 : (long long)w[a] * h[b];
}
inline void update(long long &res, long long a, long long b, long long c,
                   long long d, long long e) {
  if (a == -1 || b == -1 || c == -1 || d == -1 || e == -1) return;
  long long cur = a + b + c + d + e;
  if (cur > res) res = cur;
}
void init2(nval &c, int l) {
  for (int i = (0); i < (3); ++i)
    for (int j = (0); j < (3); ++j) c[i][j] = -1;
  for (int i = (0); i <= (2); ++i) {
    int j = 2 - i;
    update(c[i][j], 0, 0, 0, 0, 0);
  }
  for (int i = (0); i <= (1); ++i) {
    int j = 1 - i;
    update(c[i][j], 0, 0, calc(l + i, l + i), 0, 0);
  }
  for (int i = (0); i <= (0); ++i) {
    int j = 0 - i;
    update(c[i][j], 0, 0, calc(l, l), calc(l + 1, l + 1), 0);
    update(c[i][j], 0, 0, calc(l, l + 1), calc(l + 1, l), 0);
  }
}
void init3(nval &c, int l) {
  for (int i = (0); i < (3); ++i)
    for (int j = (0); j < (3); ++j) c[i][j] = -1;
  for (int i = (0); i <= (3); ++i) {
    int j = 3 - i;
    if (i != 3 && j != 3) update(c[i][j], 0, 0, 0, 0, 0);
  }
  for (int i = (0); i <= (2); ++i) {
    int j = 2 - i;
    update(c[i][j], 0, 0, calc(l + i, l + i), 0, 0);
  }
  for (int i = (0); i <= (1); ++i) {
    int j = 1 - i;
    update(c[i][j], 0, 0, calc(l + i, l + i), calc(l + i + 1, l + i + 1), 0);
    update(c[i][j], 0, 0, calc(l + i, l + i + 1), calc(l + i + 1, l + i), 0);
  }
  for (int i = (0); i <= (0); ++i) {
    int j = 0 - i;
    update(c[i][j], 0, 0, calc(l, l), calc(l + 1, l + 1), calc(l + 2, l + 2));
    update(c[i][j], 0, 0, calc(l, l), calc(l + 1, l + 2), calc(l + 2, l + 1));
    update(c[i][j], 0, 0, calc(l, l + 1), calc(l + 1, l), calc(l + 2, l + 2));
    update(c[i][j], 0, 0, calc(l, l + 1), calc(l + 1, l + 2), calc(l + 2, l));
    update(c[i][j], 0, 0, calc(l, l + 2), calc(l + 1, l), calc(l + 2, l + 1));
  }
}
void combine(const nval &a, const nval &b, nval &c, int m) {
  for (int i = (0); i < (3); ++i)
    for (int j = (0); j < (3); ++j) {
      c[i][j] = -1;
      update(c[i][j], a[i][0], b[0][j], 0, 0, 0);
      update(c[i][j], a[i][1], b[1][j], calc(m, m + 1), calc(m + 1, m), 0);
      update(c[i][j], a[i][1], b[2][j], calc(m, m + 1), calc(m + 1, m + 2),
             calc(m + 2, m));
      update(c[i][j], a[i][1], b[2][j], calc(m, m + 2), calc(m + 1, m),
             calc(m + 2, m + 1));
      update(c[i][j], a[i][2], b[1][j], calc(m - 1, m), calc(m, m + 1),
             calc(m + 1, m - 1));
      update(c[i][j], a[i][2], b[1][j], calc(m - 1, m + 1), calc(m, m - 1),
             calc(m + 1, m));
    }
}
nval val[MAXVAL];
void init(int x, int l, int h) {
  if (h - l + 1 == 2)
    init2(val[x], l);
  else if (h - l + 1 == 3)
    init3(val[x], l);
  else {
    int m = l + (h - l) / 2;
    init(2 * x + 1, l, m);
    init(2 * x + 2, m + 1, h);
    combine(val[2 * x + 1], val[2 * x + 2], val[x], m);
  }
}
void update(int x, int l, int h, int IDX) {
  if (h - l + 1 == 2)
    init2(val[x], l);
  else if (h - l + 1 == 3)
    init3(val[x], l);
  else {
    int m = l + (h - l) / 2;
    if (IDX <= m)
      update(2 * x + 1, l, m, IDX);
    else
      update(2 * x + 2, m + 1, h, IDX);
    combine(val[2 * x + 1], val[2 * x + 2], val[x], m);
  }
}
pair<int, int> worig[MAXN];
pair<int, int> horig[MAXN];
int wmap[MAXN];
int hmap[MAXN];
void run() {
  scanf("%d%d", &n, &nq);
  for (int i = (0); i < (n); ++i)
    worig[i].second = i, scanf("%d", &worig[i].first);
  sort(worig, worig + n);
  for (int i = (0); i < (n); ++i)
    wmap[worig[i].second] = i, w[i] = worig[i].first;
  for (int i = (0); i < (n); ++i)
    horig[i].second = i, scanf("%d", &horig[i].first);
  sort(horig, horig + n);
  for (int i = (0); i < (n); ++i)
    hmap[horig[i].second] = i, h[i] = horig[i].first;
  for (int i = (0); i < (n); ++i) have[wmap[i]] = hmap[i];
  init(0, 0, n - 1);
  for (int qi = (0); qi < (nq); ++qi) {
    int a, b;
    scanf("%d%d", &a, &b);
    --a, --b;
    swap(have[wmap[a]], have[wmap[b]]);
    update(0, 0, n - 1, wmap[a]);
    update(0, 0, n - 1, wmap[b]);
    printf("%I64d\n", val[0][0][0]);
  }
}
int main() {
  run();
  return 0;
}