#include <bits/stdc++.h>
using namespace std;
long long a[2005];
long long b[2005];
long long d[2005][2005];
long long s, ss, k0, k1, v, x, y;
long long aa;
vector<pair<long long, int> > c;
int main() {
  int n, m, st, fn;
  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];
    ss += b[i];
  }
  k0 = abs(ss - s);
  v = k0;
  k1 = k0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      s += b[j] - a[i];
      ss -= (b[j] - a[i]);
      k1 = min(k1, abs(s - ss));
      s -= (b[j] - a[i]);
      ss += b[j] - a[i];
    }
  }
  v = min(k0, k1);
  for (int i = 0; i < n; i++)
    for (int j = i + 1; j < n; j++)
      c.push_back(make_pair(a[i] + a[j], i * 3000 + j));
  if (c.size() > 0) {
    sort(c.begin(), c.end());
    for (int i = 0; i < m; i++)
      for (int j = i + 1; j < m; j++) {
        x = b[i] + b[j];
        int low = 0, high = c.size() - 1, mid, y;
        while (low + 1 < high) {
          y = (low + high) / 2;
          if (ss > s) {
            if (ss - s + c[y].first + c[y].first - x - x < 0)
              low = y;
            else
              high = y;
          } else {
            if (s - ss - c[y].first - c[y].first + x + x < 0)
              high = y;
            else
              low = y;
          }
        }
        st = max(y - 5, 0);
        fn = min(y + 5, (int)c.size() - 1);
        aa = abs(ss - s);
        int bb;
        for (int jj = st; jj <= fn; jj++) {
          if (abs(ss - s + c[jj].first * 2 - 2 * x) < aa) {
            aa = abs(ss - s + c[jj].first * 2 - 2 * x);
            bb = jj;
          }
        }
        d[i][j] = bb;
        v = min((long long)aa, v);
      }
  }
  cout << v << endl;
  if (v == k0) {
    cout << 0 << endl;
    return 0;
  }
  if (v == k1) {
    cout << 1 << endl;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        s += b[j] - a[i];
        ss -= b[j] - a[i];
        if (k1 == abs(s - ss)) {
          cout << i + 1 << " " << j + 1 << endl;
          return 0;
        }
        s -= b[j] - a[i];
        ss += b[j] - a[i];
      }
    }
  }
  cout << 2 << endl;
  for (int i = 0; i < m; i++) {
    for (int j = i + 1; j < m; j++) {
      x = b[i] + b[j];
      if (d[i][j] > c.size() - 1)
        for (;;)
          ;
      y = c[d[i][j]].first;
      if (abs(ss - s + 2 * y - 2 * x) == v) {
        cout << c[d[i][j]].second / 3000 + 1 << " " << i + 1 << endl;
        cout << c[d[i][j]].second % 3000 + 1 << " " << j + 1 << endl;
        return 0;
      }
    }
  }
}
