#include <bits/stdc++.h>
struct sum {
  long long s, x, y;
} s_a[2000 * 2000], s_b[2000 * 2000];
int cmp(const void *a, const void *b) {
  return (((struct sum *)a)->s > ((struct sum *)b)->s) -
         (((struct sum *)a)->s < ((struct sum *)b)->s);
}
long long search(struct sum *a, long long val, long long n) {
  long long l = 0, r = n * (n - 1) / 2, m;
  while (l + 1 < r) {
    m = (r - l) / 2 + l;
    if (a[m].s * 2 <= val)
      l = m;
    else
      r = m;
  }
  if (l == n * (n - 1) / 2 - 1)
    return l;
  else
    return (llabs(val - a[l].s * 2) < llabs(val - a[l + 1].s * 2)) ? l : l + 1;
}
int main() {
  long long n, m, i, j, k;
  long long a[2000], b[2000];
  long long sum_a = 0, sum_b = 0;
  long long min0, min1, x1, y1, min2, x2, y2;
  scanf("%I64d", &n);
  for (i = 0; i < n; i++) {
    scanf("%I64d", &a[i]);
    sum_a += a[i];
  }
  scanf("%I64d", &m);
  for (i = 0; i < m; i++) {
    scanf("%I64d", &b[i]);
    sum_b += b[i];
  }
  min0 = min1 = min2 = llabs(sum_a - sum_b);
  for (i = 0; i < n; i++)
    for (j = 0; j < m; j++)
      if (llabs(sum_a - sum_b - a[i] * 2 + b[j] * 2) < min1) {
        min1 = llabs(sum_a - sum_b - a[i] * 2 + b[j] * 2);
        x1 = i;
        y1 = j;
      }
  k = 0;
  for (i = 0; i < n; i++)
    for (j = i + 1; j < n; j++) {
      s_a[k].s = a[i] + a[j];
      s_a[k].x = i;
      s_a[k++].y = j;
    }
  k = 0;
  for (i = 0; i < m; i++)
    for (j = i + 1; j < m; j++) {
      s_b[k].s = b[i] + b[j];
      s_b[k].x = i;
      s_b[k++].y = j;
    }
  qsort(s_a, n * (n - 1) / 2, sizeof s_a[0], cmp);
  qsort(s_b, m * (m - 1) / 2, sizeof s_b[0], cmp);
  if (m > 1)
    for (i = 0; i < n * (n - 1) / 2; i++) {
      j = search(s_b, sum_b + s_a[i].s * 2 - sum_a, m);
      if (llabs(sum_a - sum_b - s_a[i].s * 2 + s_b[j].s * 2) < min2) {
        min2 = llabs(sum_a - sum_b - s_a[i].s * 2 + s_b[j].s * 2);
        x2 = i;
        y2 = j;
      }
    }
  if (min0 <= min1 && min0 <= min2)
    printf("%I64d\n0", min0);
  else if (min1 < min0 && min1 <= min2)
    printf("%I64d\n1\n%I64d %I64d", min1, x1 + 1, y1 + 1);
  else if (min2 < min0 && min2 < min1)
    printf("%I64d\n2\n%I64d %I64d\n%I64d %I64d", min2, s_a[x2].x + 1,
           s_b[y2].x + 1, s_a[x2].y + 1, s_b[y2].y + 1);
  return 0;
}
