#include <bits/stdc++.h>
using namespace std;
int n, m, cnt;
int a[2100], b[2100];
long long sum1, sum2, ans;
struct node {
  int pos1, pos2;
  node() {}
  node(int pos1, int pos2) : pos1(pos1), pos2(pos2) {}
} a1, a2;
map<long long, node> ma;
map<long long, node>::iterator it;
void update(long long x, long long y, node n1, node n2) {
  if (abs(x - y) < ans) {
    ans = abs(x - y);
    cnt = 2;
    a1 = n1;
    a2 = n2;
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]), sum1 += a[i];
  scanf("%d", &m);
  for (int i = 1; i <= m; i++) scanf("%d", &b[i]), sum2 += b[i];
  cnt = 0;
  ans = abs(sum1 - sum2);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      if (abs(sum1 - a[i] * 2 + b[j] * 2 - sum2) < ans) {
        ans = abs(sum1 - a[i] * 2 + b[j] * 2 - sum2);
        cnt = 1;
        a1 = node(i, j);
      }
  for (int i = 1; i <= n; i++)
    for (int j = i + 1; j <= n; j++)
      ma[(long long)(a[i] + a[j]) * 2] = node(i, j);
  for (int i = 1; i <= m; i++)
    for (int j = i + 1; j <= m; j++) {
      long long t = sum1 - sum2 + (long long)(b[i] + b[j]) * 2;
      it = ma.lower_bound(t);
      if (it != ma.end()) update(t, it->first, it->second, node(i, j));
      if (it != ma.begin()) it--, update(t, it->first, it->second, node(i, j));
    }
  printf("%I64d\n%d\n", ans, cnt);
  if (cnt == 1) printf("%d %d\n", a1.pos1, a1.pos2);
  if (cnt == 2) printf("%d %d\n%d %d\n", a1.pos1, a2.pos1, a1.pos2, a2.pos2);
  return 0;
}
