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 ll = long long;
int const nmax = 30000;
int const statemax = 125;
ll const inf = 1000000000000000000;
std::map<int, std::pair<int, int>> rev;
std::map<std::pair<int, int>, int> mp;
int combine(int id1, int id2) {
  int sz = rev[id1].first + rev[id2].first - 4;
  int mask = rev[id1].second ^ (rev[id2].second << (rev[id1].first - 4));
  int realmask = 0;
  if (__builtin_popcount(mask) != rev[id1].first + rev[id2].first - 8) return 0;
  for (int i = sz - 1; 0 <= i; i--)
    if (i <= 3 || sz - 4 <= i)
      realmask = realmask * 2 + (0 < (mask & (1 << i)));
  sz = std::min(sz, 8);
  return mp[{sz, realmask}];
}
struct Event {
  int x;
  int y;
  int result;
};
std::vector<Event> _all;
std::map<std::pair<int, int>, int> quickcombine;
void generate(int &ptr) {
  for (int total = 5; total <= 8; total++)
    for (int mask = 0; mask < (1 << total); mask++)
      if (__builtin_popcount(mask) == total - 4) {
        rev[++ptr] = {total, mask};
        mp[{total, mask}] = ptr;
      }
  for (int i = 1; i <= ptr; i++)
    for (int j = 1; j <= ptr; j++) {
      int res = combine(i, j);
      if (1 <= res) {
        quickcombine[{i, j}] = res;
        _all.push_back({i, j, res});
      }
    }
}
int n;
std::pair<int, int> warrior[1 + nmax], horse[1 + nmax];
int where[1 + nmax], where2[1 + nmax];
ll dp[1 + 4 * nmax][1 + statemax];
void computenode(int node, int from, int to) {
  if (from < to) {
    for (int i = 1; i <= statemax; i++) dp[node][i] = -inf;
    for (int i = 0; i < _all.size(); i++)
      dp[node][_all[i].result] =
          std::max(dp[node][_all[i].result],
                   dp[node * 2][_all[i].x] + dp[node * 2 + 1][_all[i].y]);
  }
}
void setnode(int node, int from) {
  for (int i = 1; i <= statemax; i++) dp[node][i] = -inf;
  int start = std::max(from - 2, 1), stop = std::min(from + 2, n);
  for (int i = start; i <= stop; i++)
    if (warrior[from].second != horse[i].second)
      dp[node][i - (from - 2) + 1] = 1LL * warrior[from].first * horse[i].first;
}
void build(int node, int from, int to) {
  if (from < to) {
    int mid = (from + to) / 2;
    build(node * 2, from, mid);
    build(node * 2 + 1, mid + 1, to);
    computenode(node, from, to);
  } else
    setnode(node, from);
}
void update(int node, int from, int to, int x) {
  if (from < to) {
    int mid = (from + to) / 2;
    if (x <= mid)
      update(node * 2, from, mid, x);
    else
      update(node * 2 + 1, mid + 1, to, x);
    computenode(node, from, to);
  } else
    setnode(node, from);
}
int main() {
  std::ios::sync_with_stdio(0);
  std::cin.tie(0);
  int ptr = 0;
  generate(ptr);
  int q;
  std::cin >> n >> q;
  for (int i = 1; i <= n; i++) {
    std::cin >> warrior[i].first;
    warrior[i].second = i;
  }
  std::sort(warrior + 1, warrior + n + 1);
  for (int i = 1; i <= n; i++) where[warrior[i].second] = i;
  for (int i = 1; i <= n; i++) {
    std::cin >> horse[i].first;
    horse[i].second = i;
  }
  std::sort(horse + 1, horse + n + 1);
  for (int i = 1; i <= n; i++) where2[horse[i].second] = i;
  build(1, 1, n);
  int target = 3;
  for (int i = 2; i <= n; i++) target = quickcombine[{target, 3}];
  for (int i = 1; i <= q; i++) {
    int x, y;
    std::cin >> x >> y;
    int posx = where2[x], posy = where2[y];
    std::swap(horse[posx].second, horse[posy].second);
    std::swap(where2[x], where2[y]);
    update(1, 1, n, where[x]);
    update(1, 1, n, where[y]);
    std::cout << dp[1][target] << '\n';
  }
  return 0;
}