#include <bits/stdc++.h>
using namespace std;
struct node {
  long long x;
  int num1, num2;
  node(){};
  node(long long X, int N1, int N2) { x = X, num1 = N1, num2 = N2; }
  bool operator<(const node &p) const { return x < p.x; }
} a1[4000005], a2[4000005], v1[5];
int n, m, tot1, tot2, cnt;
long long ans1, sum1, sum2, copy1, a[2005], b[2005];
long long jdz(long long z) {
  if (z > 0)
    return z;
  else
    return -z;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
    sum1 += a[i];
  }
  scanf("%d", &m);
  for (int i = 1; i <= m; i++) {
    scanf("%lld", &b[i]);
    sum2 += b[i];
  }
  ans1 = jdz(sum1 - sum2);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      long long xx = jdz(sum1 + b[j] - a[i] - (sum2 + a[i] - b[j]));
      if (xx < ans1) {
        cnt = 1;
        v1[1].num1 = i, v1[1].num2 = j;
        ans1 = xx;
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = i + 1; j <= n; j++) {
      a1[++tot1] = node(a[i] + a[j], i, j);
    }
  }
  for (int i = 1; i <= m; i++) {
    for (int j = i + 1; j <= m; j++) {
      a2[++tot2] = node(b[i] + b[j], i, j);
    }
  }
  sort(a1 + 1, a1 + tot1 + 1);
  sort(a2 + 1, a2 + tot2 + 1);
  for (int i = 1, j = 1; i <= tot1 && j <= tot2;) {
    long long xx = (sum1 - sum2 + 2 * a2[j].x - 2 * a1[i].x);
    if (ans1 > abs(xx)) {
      ans1 = abs(xx);
      cnt = 2;
      v1[1] = a1[i];
      v1[2] = a2[j];
    }
    if (xx > 0)
      i++;
    else
      j++;
  }
  printf("%lld\n", ans1);
  printf("%d\n", cnt);
  if (cnt == 1) printf("%d %d\n", v1[1].num1, v1[1].num2);
  if (cnt == 2)
    printf("%d %d\n%d %d\n", v1[1].num1, v1[2].num1, v1[1].num2, v1[2].num2);
}
