#include <bits/stdc++.h>
using namespace std;
long long A[3000], B[3000];
map<long long, pair<int, int> > MA;
map<long long, pair<int, int> >::iterator it, it3;
int X1, Y1, X2, Y2;
long long diff = 0;
long long mindiff;
long long sa = 0, sb = 0;
long long t = 0;
int temp1, temp2;
void check(map<long long, pair<int, int> >::iterator it2, long long vbs) {
  diff = llabs(sa - sb - it2->first + vbs);
  if (diff < mindiff) {
    mindiff = diff;
    X1 = (it2->second).first;
    X2 = (it2->second).second;
    Y1 = temp1;
    Y2 = temp2;
  }
}
int main(int argc, const char* argv[]) {
  int n, m, i, j;
  long long vbs;
  scanf("%d", &n);
  for (i = 0; i < n; i++) scanf("%lld", &A[i]);
  scanf("%d", &m);
  for (j = 0; j < m; j++) scanf("%lld", &B[j]);
  sa = accumulate(A, A + n, 0LL);
  sb = accumulate(B, B + m, 0LL);
  if (sa == sb) {
    printf("0\n0");
    return 0;
  }
  mindiff = llabs(sa - sb);
  X1 = -1;
  Y1 = -1;
  X2 = -1;
  Y2 = -1;
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      diff = llabs(sa - sb - 2 * A[i] + 2 * B[j]);
      if (diff < mindiff) {
        mindiff = diff;
        X1 = i;
        Y1 = j;
      }
    }
  }
  for (i = 0; i < n; i++)
    for (j = i + 1; j < n; j++) MA[2LL * (A[i] + A[j])] = pair<int, int>(i, j);
  for (i = 0; i < m; i++)
    for (j = i + 1; j < m; j++) {
      vbs = (2LL * (B[i] + B[j]));
      temp1 = i;
      temp2 = j;
      t = sa - sb + vbs;
      it = MA.lower_bound(t);
      it3 = it;
      if (it != MA.end()) {
        check(it, vbs);
        it++;
      }
      if (it != MA.end()) check(it, vbs);
      it = it3;
      if (it != MA.begin()) {
        it--;
        check(it, vbs);
      }
    }
  if (X1 == -1 && Y1 == -1) {
    printf("%lld\n0\n", mindiff);
  } else if (X2 == -1 && Y2 == -1) {
    printf("%lld\n", mindiff);
    printf("1\n");
    printf("%d %d\n", X1 + 1, Y1 + 1);
  } else {
    printf("%lld\n", mindiff);
    printf("2\n");
    printf("%d %d\n", X1 + 1, Y1 + 1);
    printf("%d %d\n", X2 + 1, Y2 + 1);
  }
  return 0;
}
