#include <bits/stdc++.h>
using namespace std;
const int N = 2000;
int n, m, a[N], b[N];
long long A, B;
vector<pair<int, int> > sol;
map<long long, pair<int, int> > all;
map<long long, pair<int, int> >::iterator it;
inline long long ABS(long long v) { return (v < 0) ? -v : v; }
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
    A += a[i];
  }
  scanf("%d", &m);
  for (int i = 0; i < m; ++i) {
    scanf("%d", &b[i]);
    B += b[i];
  }
  long long diff = ABS(A - B);
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) {
      long long nA = A - a[i] + b[j];
      long long nB = B - b[j] + a[i];
      long long nD = ABS(nA - nB);
      if (nD < diff) {
        diff = nD;
        sol.clear();
        sol.push_back(make_pair(i, j));
      }
    }
  for (int i = 0; i < n; ++i)
    for (int j = i + 1; j < n; ++j) all[2LL * (a[i] + a[j])] = make_pair(i, j);
  for (int i = 0; i < m; ++i)
    for (int j = i + 1; j < m; ++j) {
      long long nS = A - B + 2LL * (b[i] + b[j]);
      it = all.lower_bound(nS);
      if (it != all.end()) {
        long long nD = ABS(nS - it->first);
        if (nD < diff) {
          diff = nD;
          sol.clear();
          sol.push_back(make_pair(it->second.first, i));
          sol.push_back(make_pair(it->second.second, j));
        }
      }
      if (it != all.begin()) {
        --it;
        long long nD = ABS(nS - it->first);
        if (nD < diff) {
          diff = nD;
          sol.clear();
          sol.push_back(make_pair(it->second.first, i));
          sol.push_back(make_pair(it->second.second, j));
        }
      }
    }
  printf("%lld\n%d\n", diff, (int)sol.size());
  for (size_t i = 0; i < sol.size(); ++i)
    printf("%d %d\n", sol[i].first + 1, sol[i].second + 1);
  return 0;
}
