#include <bits/stdc++.h>
using namespace std;
const long long inf = INT_MAX, df = 2005, M = 4e6 + 4e5 + 7;
long long i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a[df], b[df],
    tot, cnt, opg = 0;
long long ans = inf, dta, aa, bb, cc, dd;
struct node {
  long long x, y, val;
} c[M], d[M];
bool cmp(node st, node ch) { return st.val < ch.val; }
inline long long read() {
  long long x = 0, y = 1;
  char ch = getchar();
  while (ch > '9' || ch < '0') y = (ch == '-') ? -1 : 1, ch = getchar();
  while (ch >= '0' && ch <= '9')
    x = (x << 3) + (x << 1) + ch - '0', ch = getchar();
  return x * y;
}
int main() {
  dta = 0;
  n = read();
  for (long long i = (1); i <= (n); ++i) a[i] = read(), dta += a[i];
  m = read();
  for (long long i = (1); i <= (m); ++i) b[i] = read(), dta -= b[i];
  for (long long i = (2); i <= (n); ++i)
    for (long long j = (1); j <= (i - 1); ++j)
      c[++tot] = (node){j, i, 2 * (a[j] + a[i])};
  for (long long i = (2); i <= (m); ++i)
    for (long long j = (1); j <= (i - 1); ++j)
      d[++cnt] = (node){j, i, 2 * (b[i] + b[j])};
  sort(c + 1, c + tot + 1, cmp);
  sort(d + 1, d + cnt + 1, cmp);
  ans = abs(dta);
  opg = 0;
  for (long long i = (1); i <= (n); ++i) {
    for (long long j = (1); j <= (m); ++j) {
      if (abs(dta - a[i] * 2 + b[j] * 2) < ans) {
        opg = 1, ans = abs(dta - a[i] * 2 + b[j] * 2);
        aa = i, bb = j;
      }
    }
  }
  for (long long i = 1, j = 1; i <= tot && j <= cnt;) {
    long long tmp = (dta - c[i].val + d[j].val);
    if (abs(tmp) < ans)
      opg = 2, ans = abs(tmp), aa = c[i].x, bb = c[i].y, cc = d[j].x,
      dd = d[j].y;
    if (tmp > 0)
      i++;
    else
      j++;
  }
  printf("%lld\n", ans);
  printf("%lld\n", opg);
  if (opg == 0) return 0;
  if (opg == 1) return printf("%lld %lld\n", aa, bb), 0;
  if (opg == 2) return printf("%lld %lld\n%lld %lld\n", aa, cc, bb, dd), 0;
}
