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>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
const long long maxn = 30000 + 100;
const long long MAX_NODE = maxn * 4 + 10;
long long n, q;
struct info {
  long long no, s, wno;
  info(long long _no = 0, long long _s = 0, long long _wno = 0) {
    no = _no;
    s = _s;
    wno = _wno;
  }
};
info h[maxn], w[maxn];
long long posH[maxn], posW[maxn];
long long f[maxn];
long long tree[MAX_NODE][3][3];
long long dp(long long l, long long r) {
  f[l - 1] = 0;
  for (long long i = l; i <= r; i++) f[i] = -1;
  for (long long i = l; i <= r; i++) {
    long long j = i;
    if (j >= l && f[j - 1] != -1 && w[i].no != h[j].no) {
      f[i] = max(f[i], f[j - 1] + (long long)w[i].s * (long long)h[j].s);
    }
    j--;
    if (j >= l && f[j - 1] != -1) {
      if (w[i].no != h[j].no && w[j].no != h[i].no)
        f[i] = max(f[i], f[j - 1] + (long long)w[i].s * (long long)h[j].s +
                             (long long)w[j].s * (long long)h[i].s);
    }
    j--;
    if (j >= l && f[j - 1] != -1) {
      if (w[j].no != h[j + 1].no && w[j + 1].no != h[j + 2].no &&
          w[i].no != h[j].no)
        f[i] = max(f[i], f[j - 1] + (long long)w[j].s * (long long)h[j + 1].s +
                             (long long)w[j + 1].s * (long long)h[j + 2].s +
                             (long long)w[i].s * (long long)h[j].s);
      if (w[j].no != h[i].no && w[j + 1].no != h[j].no &&
          w[i].no != h[j + 1].no)
        f[i] = max(f[i], f[j - 1] + (long long)w[j].s * (long long)h[i].s +
                             (long long)w[j + 1].s * (long long)h[j].s +
                             (long long)w[i].s * (long long)h[j + 1].s);
    }
  }
  return f[r];
}
void pushUp(long long rt, long long l, long long r) {
  long long mid = ((l + r) >> 1), lRt = (rt << 1), rRt = ((rt << 1) | 1);
  if (mid - l + 1 < 4 || r - mid < 4) {
    for (long long i = 0; i <= 2; i++) {
      for (long long j = 0; j <= 2; j++) {
        long long tmp = dp(l + i, r - j);
        tree[rt][i][j] = tmp;
      }
    }
  } else {
    for (long long i = 0; i <= 2; i++)
      for (long long j = 0; j <= 2; j++) tree[rt][i][j] = -1;
    for (long long xa = 0; xa <= 2; xa++) {
      for (long long ya = 0; ya <= 2; ya++) {
        if (tree[lRt][xa][ya] != -1) {
          for (long long xb = 0; xb + ya <= 3 && xb <= 2; xb++) {
            for (long long yb = 0; yb <= 2; yb++) {
              if (tree[rRt][xb][yb] != -1) {
                long long &key = tree[rt][xa][yb];
                long long a = tree[lRt][xa][ya], b = tree[rRt][xb][yb];
                if (ya == 0 && xb == 0) key = max(key, a + b);
                if (ya == 0 || xb == 0) continue;
                if (ya == 1 && xb == 1) {
                  if (w[mid].no != h[mid + 1].no && w[mid + 1].no != h[mid].no)
                    key = max(
                        key, a + b +
                                 (long long)w[mid].s * (long long)h[mid + 1].s +
                                 (long long)w[mid + 1].s * (long long)h[mid].s);
                }
                if ((ya == 1 && xb == 2) || (ya == 2 && xb == 1)) {
                  long long i = mid - ya + 1;
                  long long j = i + 1;
                  long long k = j + 1;
                  if (w[i].no != h[j].no && w[j].no != w[k].no &&
                      w[k].no != h[i].no)
                    key =
                        max(key, a + b + (long long)w[i].s * (long long)h[j].s +
                                     (long long)w[j].s * (long long)h[k].s +
                                     (long long)w[k].s * (long long)h[i].s);
                  if (w[i].no != w[k].no && w[j].no != h[i].no &&
                      w[k].no != h[j].no)
                    key =
                        max(key, a + b + (long long)w[i].s * (long long)h[k].s +
                                     (long long)w[j].s * (long long)h[i].s +
                                     (long long)w[k].s * (long long)h[j].s);
                }
              }
            }
          }
        }
      }
    }
  }
}
void dfs(long long rt, long long l, long long r) {
  if (r - l + 1 < 4) return;
  long long mid = ((l + r) >> 1), lRt = (rt << 1), rRt = ((rt << 1) | 1);
  dfs(lRt, l, mid);
  dfs(rRt, mid + 1, r);
  pushUp(rt, l, r);
}
void initail() { dfs(1, 1, n); }
void change(long long a, long long b, long long c, long long d, long long rt,
            long long l, long long r) {
  if (r - l + 1 < 4) return;
  long long mid = ((l + r) >> 1), lRt = (rt << 1), rRt = ((rt << 1) | 1);
  if ((a >= l && a <= mid) || (b >= l && b <= mid) || (c >= l && c <= mid) ||
      (d >= l && d <= mid)) {
    change(a, b, c, d, lRt, l, mid);
  }
  if ((a >= mid + 1 && a <= r) || (b >= mid + 1 && b <= r) ||
      (c >= mid + 1 && c <= r) || (d >= mid + 1 && d <= r)) {
    change(a, b, c, d, rRt, mid + 1, r);
  }
  pushUp(rt, l, r);
}
void check_dfs(long long rt, long long l, long long r) {
  if (r - l + 1 < 4) return;
  for (long long i = 0; i <= 2; i++)
    for (long long j = 0; j <= 2; j++) {
      if (tree[rt][i][j] != dp(l + i, r - j)) {
        printf("l %I64d r %I64d  i %I64d j %I64d  tree %I64d   %I64d\n", l, r,
               i, j, tree[rt][i][j], dp(l + i, r - j));
      }
    }
  long long mid = ((l + r) >> 1), lRt = (rt << 1), rRt = ((rt << 1) | 1);
  check_dfs(lRt, l, mid);
  check_dfs(rRt, mid + 1, r);
}
void solve() {
  initail();
  while (q--) {
    long long a, b;
    scanf("%I64d%I64d", &a, &b);
    swap(w[posW[a]].no, w[posW[b]].no);
    if (n >= 4) {
      change(posW[a], posW[b], posH[w[posW[a]].no], posH[w[posW[b]].no], 1, 1,
             n);
      printf("%I64d\n", tree[1][0][0]);
    } else {
      printf("%I64d\n", dp(1, n));
    }
  }
}
bool cmp(info a, info b) { return a.s < b.s; }
int main() {
  while (scanf("%I64d%I64d", &n, &q) != EOF) {
    for (long long i = 1; i <= n; i++) {
      scanf("%I64d", &w[i].s);
      w[i].no = i;
      w[i].wno = i;
    }
    for (long long i = 1; i <= n; i++) {
      scanf("%I64d", &h[i].s);
      h[i].no = i;
    }
    sort(w + 1, w + 1 + n, cmp);
    sort(h + 1, h + 1 + n, cmp);
    for (long long i = 1; i <= n; i++) {
      posW[w[i].wno] = i;
      posH[h[i].no] = i;
    }
    solve();
  }
  return 0;
}