#include <bits/stdc++.h>
using namespace std;
const int N = 3010;
long long a[N], b[N], n, m;
long long sa = 0, sb = 0, bestSa, bestSb;
pair<int, int> ansOne, ansTwo;
vector<long long> va, vb;
void add(long long *arr, int size, vector<long long> &v) {
  for (int i = 0; i < size; ++i)
    for (int j = i + 1; j < size; ++j) v.push_back(arr[i] + arr[j]);
}
long long one() {
  long long ba = sa;
  long long bb = sb;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      long long nsa = sa - a[i] + b[j], nsb = sb - b[j] + a[i];
      if (llabs(nsa - nsb) < llabs(ba - bb)) {
        ba = nsa;
        bb = nsb;
        ansOne = pair<int, int>(i + 1, j + 1);
      }
    }
  }
  return llabs(ba - bb);
}
long long two() {
  long long diff = llabs(sa - sb);
  for (int i = 0; i < (int)va.size(); ++i) {
    long long x = va[i];
    long long y = x + ((sb - sa) / 2);
    int at = lower_bound(vb.begin(), vb.end(), y) - vb.begin();
    for (int j = at - 1; j <= at; ++j) {
      if (j >= 0 and j < (int)vb.size()) {
        long long nsa = sa - x + vb[j];
        long long nsb = sb - vb[j] + x;
        if (llabs(nsa - nsb) < diff) {
          diff = llabs(nsa - nsb);
          ansTwo = pair<int, int>(x, vb[j]);
        }
      }
    }
  }
  return diff;
}
pair<int, int> find(long long e, long long *arr, int size) {
  for (int i = 0; i < size; ++i)
    for (int j = i + 1; j < size; ++j)
      if (arr[i] + arr[j] == e) return pair<int, int>(i + 1, j + 1);
}
void solve() {
  long long d0 = llabs(sa - sb), d1 = one(), d2 = d1;
  if (n > 1 and m > 1) {
    d2 = two();
  }
  long long best = min(d0, min(d1, d2));
  cout << best << "\n";
  if (best == d0) {
    cout << "0\n";
  } else if (best == d1) {
    cout << "1\n";
    cout << ansOne.first << " " << ansOne.second << "\n";
  } else {
    vector<pair<int, int> > pans;
    pans.push_back(find(ansTwo.first, a, n));
    pans.push_back(find(ansTwo.second, b, m));
    cout << "2\n";
    cout << pans[0].first << " " << pans[1].first << "\n";
    cout << pans[0].second << " " << pans[1].second << "\n";
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    sa += a[i];
  }
  cin >> m;
  for (int i = 0; i < m; ++i) {
    cin >> b[i];
    sb += b[i];
  }
  add(a, n, va);
  add(b, m, vb);
  sort(vb.begin(), vb.end());
  solve();
  return 0;
}
