Professor GukiZ and Two Arrays

Professor GukiZ has two arrays of integers, a and b. Professor wants to make the sum of the elements in the array a s a as close as possible to the sum of the elements in the array b s b. So he wants to minimize the value v = |s a - s b|.

In one operation professor can swap some element from the array a and some element from the array b. For example if the array a is [5, 1, 3, 2, 4] and the array b is [3, 3, 2] professor can swap the element 5 from the array a and the element 2 from the array b and get the new array a [2, 1, 3, 2, 4] and the new array b [3, 3, 5].

Professor doesn’t want to make more than two swaps. Find the minimal value v and some sequence of no more than two swaps that will lead to the such value v. Professor makes swaps one by one, each new swap he makes with the new arrays a and b.

Input

The first line contains integer n (1 ≤ n ≤ 2000) — the number of elements in the array a.

The second line contains n integers a i ( - 109 ≤ a i ≤ 109) — the elements of the array a.

The third line contains integer m (1 ≤ m ≤ 2000) — the number of elements in the array b.

The fourth line contains m integers b j ( - 109 ≤ b j ≤ 109) — the elements of the array b.

Output

In the first line print the minimal value v = |s a - s b| that can be got with no more than two swaps.

The second line should contain the number of swaps k (0 ≤ k ≤ 2).

Each of the next k lines should contain two integers x p, y p (1 ≤ x p ≤ n, 1 ≤ y p ≤ m) — the index of the element in the array a and the index of the element in the array b in the p-th swap.

If there are several optimal solutions print any of them. Print the swaps in order the professor did them.

Examples

input

5
5 4 3 2 1
4
1 1 1 1

output

1
2
1 1
4 2

input

5
1 2 3 4 5
1
15

output

0
0

input

5
1 2 3 4 5
4
1 2 3 4

output

1
1
3 1

Solution:

#include <bits/stdc++.h>

using namespace std;

long long ans;
int a1 = -1, a2 = -1, a3 = -1, a4 = -1;

void test(long long value, int b1, int b2, int b3, int b4) {
if (abs(value) < ans) {
    ans = abs(value);
    a1 = b1;
    a2 = b2;
    a3 = b3;
    a4 = b4;
  }
}

const int N = 4444;

pair <int, int> a[N], b[N];

int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
    scanf("%d", &a[i].first);
    a[i].second = i + 1;
  }
  int m;
  scanf("%d", &m);
  for (int j = 0; j < m; j++) {
    scanf("%d", &b[j].first);
    b[j].second = j + 1;
  }
  long long sa = 0;
  for (int i = 0; i < n; i++) {
    sa += a[i].first;
  }
  long long sb = 0;
  for (int j = 0; j < m; j++) {
    sb += b[j].first;
  }
  sort(a, a + n);
  sort(b, b + m);
  long long diff = sb - sa;
  ans = abs(diff);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      test(diff + 2 * (a[i].first - 0LL - b[j].first), a[i].second, b[j].second, -1, -1);
    }
  }
  vector < pair < int, pair <int, int> > > as, bs;
for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      as.push_back(make_pair(a[i].first + a[j].first, make_pair(a[i].second, a[j].second)));
    }
  }
  for (int i = 0; i < m; i++) {
    for (int j = i + 1; j < m; j++) {
      bs.push_back(make_pair(b[i].first + b[j].first, make_pair(b[i].second, b[j].second)));
    }
  }
  sort(as.begin(), as.end());
  sort(bs.begin(), bs.end());
  int nn = as.size();
  int mm = bs.size();
  int j = 0;
  for (int i = 0; i < nn; i++) {
    while (j < mm && diff + 2 * (as[i].first - 0LL - bs[j].first) > 0) {
j++;
}
if (j < mm) {
      test(diff + 2 * (as[i].first - 0LL - bs[j].first), as[i].second.first, bs[j].second.first, as[i].second.second, bs[j].second.second);
    }
    if (j - 1 >= 0) {
j--;
test(diff + 2 * (as[i].first - 0LL - bs[j].first), as[i].second.first, bs[j].second.first, as[i].second.second, bs[j].second.second);
j++;
}
}
cout << ans << endl;
  if (a1 == -1) {
    cout << 0 << endl;
    return 0;
  }
  if (a3 == -1) {
    cout << 1 << endl;
    cout << a1 << " " << a2 << endl;
    return 0;
  }
  cout << 2 << endl;
  cout << a1 << " " << a2 << endl;
  cout << a3 << " " << a4 << endl;
  return 0;
}