#include <bits/stdc++.h>
using namespace std;
long long n, a[2003], b[2003], m;
long long sa = 0, sb = 0;
vector<pair<long long, long long> > points;
map<long long, pair<int, int> > mp;
map<long long, pair<int, int> >::iterator it;
int main() {
  int i, j, k;
  scanf("%lld", &n);
  for (i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
    sa += a[i];
  }
  scanf("%lld", &m);
  for (i = 1; i <= m; i++) {
    scanf("%lld", &b[i]);
    sb += b[i];
  }
  long long ans = llabs(sa - sb);
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= m; j++) {
      long long diff = abs(sa - sb - 2 * a[i] + 2 * b[j]);
      if (diff < ans) {
        ans = diff;
        points.clear();
        points.push_back({i, j});
      }
    }
  }
  for (i = 1; i <= n; i++) {
    for (j = i + 1; j <= n; j++) {
      mp[2 * (a[i] + a[j])] = {i, j};
    }
  }
  for (i = 1; i <= m; i++) {
    for (j = i + 1; j <= m; j++) {
      long long val = sa - sb + 2 * (b[i] + b[j]);
      it = mp.lower_bound(val);
      if (it != mp.end()) {
        long long diff = abs(val - (*it).first);
        if (diff < ans) {
          pair<int, int> xx = (*it).second;
          ans = diff;
          points.clear();
          points.push_back({xx.first, i});
          points.push_back({xx.second, j});
        }
      }
      if (it == mp.begin()) continue;
      it--;
      long long diff = abs(val - (*it).first);
      if (diff < ans) {
        pair<int, int> xx = (*it).second;
        ans = diff;
        points.clear();
        points.push_back({xx.first, i});
        points.push_back({xx.second, j});
      }
    }
  }
  printf("%lld\n", ans);
  printf("%d\n", points.size());
  for (i = 0; i < points.size(); i++)
    printf("%lld %lld\n", points[i].first, points[i].second);
}
