#include <bits/stdc++.h>
using namespace std;
const int maxn = 2005;
const int INF = 0x3f3f3f3f;
const double pi = acos(-1.0);
const double eps = 1e-9;
inline int sgn(double a) { return a < -eps ? -1 : a > eps; }
struct node {
  int x;
  int y;
  long long val;
  node(int a, int b, long long c) {
    x = a;
    y = b;
    val = c;
  }
};
bool operator<(const node &a, const node &b) { return a.val < b.val; }
pair<int, int> ind1, ind2;
vector<pair<long long, pair<int, int> > > bbij;
int n, m;
long long a[maxn];
long long b[maxn];
long long s;
long long ans = LLONG_MAX;
vector<node> aij;
vector<node> bij;
int inda1 = -1, indb1 = -1;
int inda2 = -1, indb2 = -1;
int type = 0;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    s += a[i];
  }
  cin >> m;
  for (int i = 0; i < m; i++) {
    cin >> b[i];
    s -= b[i];
  }
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      aij.push_back(node(i, j, a[i] + a[j]));
    }
  }
  for (int i = 0; i < m; i++) {
    for (int j = i + 1; j < m; j++) {
      bij.push_back(node(i, j, 2ll * b[i] + 2ll * b[j]));
    }
  }
  ans = abs(s);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (abs(s - 2ll * a[i] + 2ll * b[j]) < ans) {
        type = 1;
        ans = abs(s - 2ll * a[i] + 2ll * b[j]);
        ind1.first = i;
        ind1.second = j;
        inda1 = i;
        indb1 = j;
      }
    }
  }
  sort(bij.begin(), bij.end());
  for (int i = 0; i < n; i++) {
    for (int k = i + 1; k < n; k++) {
      long long t = 2ll * a[i] + 2ll * a[k] - s;
      node tt = node(0, 0, t);
      int jj = lower_bound(bij.begin(), bij.end(), tt) - bij.begin();
      int sz = bij.size();
      for (int j = max(0, jj - 3); j <= min(jj + 3, sz - 1); j++) {
        if (abs(bij[j].val - t) < ans) {
          ans = abs(bij[j].val - t);
          inda1 = i;
          inda2 = k;
          indb1 = bij[j].x;
          indb2 = bij[j].y;
          type = 2;
        }
      }
    }
  }
  if (type == 0) {
    cout << ans << '\n';
    cout << "0\n";
  } else if (type == 1) {
    cout << ans << '\n';
    cout << type << '\n';
    cout << inda1 + 1 << ' ' << indb1 + 1 << '\n';
  } else if (type == 2) {
    cout << ans << '\n';
    cout << type << '\n';
    cout << inda1 + 1 << ' ' << indb1 + 1 << '\n';
    cout << inda2 + 1 << ' ' << indb2 + 1 << '\n';
  }
  return 0;
}
