#include <bits/stdc++.h>
using namespace std;
long long a[2005], b[2005], n, m, suma, sumb, v, ans, c;
map<long long, pair<int, int> > u;
map<long long, pair<int, int> >::iterator it;
pair<int, int> swap1, swap2;
void update(int i, int j) {
  if (abs(c - it->first) < v) {
    ans = 2;
    v = abs(c - it->first);
    swap1 = it->second;
    swap2 = {i, j};
  }
}
int main() {
  scanf("%lld", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
    suma += a[i];
  }
  scanf("%lld", &m);
  for (int i = 1; i <= m; i++) {
    scanf("%lld", &b[i]);
    sumb += b[i];
  }
  v = abs(suma - sumb);
  if (!v) {
    printf("0\n0\n");
    return 0;
  }
  for (int i = 1; i < n; i++)
    for (int j = i + 1; j <= n; j++) u[(a[i] + a[j]) * 2LL] = {i, j};
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      if (abs(suma - sumb - 2LL * (a[i] - b[j])) < v) {
        ans = 1;
        v = abs(suma - sumb - 2LL * (a[i] - b[j]));
        swap1 = {i, j};
      }
  for (int i = 1; i < m; i++)
    for (int j = i + 1; j <= m; j++) {
      c = suma - sumb + 2LL * (b[i] + b[j]);
      it = u.lower_bound(c);
      if (it != u.end()) update(i, j);
      if (it != u.begin()) {
        it--;
        update(i, j);
      }
    }
  printf("%lld\n%lld\n", v, ans);
  if (ans == 1) printf("%d %d\n", swap1.first, swap1.second);
  if (ans == 2)
    printf("%d %d\n%d %d\n", swap1.first, swap2.first, swap1.second,
           swap2.second);
  return 0;
}
