#include <bits/stdc++.h>
using namespace std;
map<long long, pair<long long, long long> > mp;
map<long long, pair<long long, long long> >::iterator it;
vector<pair<long long, long long> > ar;
long long a[2010], b[2010];
int main() {
  ios::sync_with_stdio(false);
  long long i, j, k, n, m, sa = 0, sb = 0, ans, mm, v;
  pair<long long, long long> p;
  cin >> n;
  for (i = 0; i <= n - 1; i++) {
    cin >> a[i];
    sa += a[i];
  }
  cin >> m;
  for (i = 0; i <= m - 1; i++) {
    cin >> b[i];
    sb += b[i];
  }
  ans = abs(sa - sb);
  for (i = 0; i <= n - 1; i++)
    for (j = 0; j <= m - 1; j++) {
      mm = abs(sa - sb + 2 * b[j] - 2 * a[i]);
      if (mm < ans) {
        ar.clear();
        ans = mm;
        ar.push_back(pair<long long, long long>(i, j));
      }
    }
  for (i = 0; i <= n - 1; i++)
    for (j = i + 1; j <= n - 1; j++)
      mp[2 * (a[i] + a[j])] = pair<long long, long long>(i, j);
  for (i = 0; i <= m - 1; i++)
    for (j = i + 1; j <= m - 1; j++) {
      v = sa - sb + 2 * (b[i] + b[j]);
      it = mp.lower_bound(v);
      if (it != mp.begin()) it--;
      for (k = 0; k <= 1; k++) {
        if (it == mp.end()) break;
        mm = abs(v - it->first);
        p = it->second;
        if (mm < ans) {
          ar.clear();
          ans = mm;
          ar.push_back(pair<long long, long long>(p.first, i));
          ar.push_back(pair<long long, long long>(p.second, j));
        }
        it++;
      }
    }
  cout << ans << endl << ar.size() << endl;
  for (i = 0; i < ar.size(); i++)
    cout << ar[i].first + 1 << " " << ar[i].second + 1 << endl;
}
