#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  long long sum1 = 0, sum2 = 0;
  long long n;
  cin >> n;
  long long ar1[n];
  for (long long i = 0; i < n; i++) {
    cin >> ar1[i];
    sum1 += ar1[i];
  }
  long long m;
  cin >> m;
  long long ar2[m];
  for (long long i = 0; i < m; i++) {
    cin >> ar2[i];
    sum2 += ar2[i];
  }
  long long md0 = abs(sum1 - sum2);
  long long md1 = abs(sum1 - sum2);
  long long md2 = abs(sum1 - sum2);
  pair<long long, long long> p = {-1, -1};
  for (long long i = 0; i < n; i++) {
    sum1 = sum1 - ar1[i];
    sum2 = sum2 + ar1[i];
    for (long long j = 0; j < m; j++) {
      sum1 = sum1 + ar2[j];
      sum2 = sum2 - ar2[j];
      if (md1 > abs(sum1 - sum2)) {
        md1 = abs(sum1 - sum2);
        p.first = i;
        p.second = j;
      }
      sum1 = sum1 - ar2[j];
      sum2 = sum2 + ar2[j];
    }
    sum1 = sum1 + ar1[i];
    sum2 = sum2 - ar1[i];
  }
  map<long long, pair<long long, long long>> mp;
  for (long long i = 0; i < n; i++) {
    for (long long j = i + 1; j < n; j++) {
      mp[2 * (ar1[i] + ar1[j])] = {i, j};
    }
  }
  pair<long long, long long> p1;
  pair<long long, long long> p2;
  for (long long i = 0; i < m; i++) {
    for (long long j = i + 1; j < m; j++) {
      long long x = sum1 - sum2 + 2 * (ar2[i] + ar2[j]);
      auto itr = mp.lower_bound(x);
      if (itr != mp.begin()) itr--;
      for (long long k = 0; k < 2; k++) {
        if (itr == mp.end()) break;
        long long v = itr->first;
        if (md2 > abs(x - v)) {
          md2 = abs(x - v);
          p1.first = (itr->second).first;
          p1.second = i;
          p2.first = (itr->second).second;
          p2.second = j;
        }
        itr++;
      }
    }
  }
  if (md0 < md1 && md0 < md2) {
    cout << md0 << '\n';
    cout << 0 << '\n';
  } else if (md1 < md0 && md1 < md2) {
    cout << md1 << '\n';
    cout << 1 << '\n';
    cout << p.first + 1 << " " << p.second + 1 << '\n';
  } else {
    cout << md2 << '\n';
    cout << 2 << '\n';
    cout << p1.first + 1 << " " << p1.second + 1 << '\n';
    cout << p2.first + 1 << " " << p2.second + 1 << '\n';
  }
  return 0;
}
