#include <bits/stdc++.h>
using namespace std;
const int MAX = 2e5;
const int INF = 1e9 + 1e5 + 2;
const int mod = 1e9 + 7;
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n, m;
  cin >> n;
  vector<long long> a(n);
  long long sa = 0, sb = 0;
  for (long long i = 0; i < n; ++i) cin >> a[i], sa += a[i];
  cin >> m;
  vector<long long> b(m);
  for (long long i = 0; i < m; ++i) cin >> b[i], sb += b[i];
  long long v = abs(sa - sb);
  vector<pair<long long, long long>> ans;
  map<long long, pair<long long, long long>> mp;
  for (long long i = 0; i < n; ++i) {
    for (long long j = 0; j < m; ++j) {
      long long x = abs((sa - a[i] + b[j]) - (sb + a[i] - b[j]));
      if (x < v) {
        v = x;
        ans.clear();
        ans.push_back({i, j});
      }
    }
  }
  for (long long i = 0; i < n; ++i)
    for (long long j = i + 1; j < n; ++j) mp[2 * (a[i] + a[j])] = {i, j};
  for (long long i = 0; i < m; ++i) {
    for (long long j = i + 1; j < m; ++j) {
      long long x = sa - sb + 2 * (b[i] + b[j]);
      auto l = mp.lower_bound(x);
      if (l != mp.begin()) --l;
      long long t = 2;
      while (t--) {
        if (l == mp.end()) break;
        long long su = abs(x - l->first);
        if (su < v) {
          v = su;
          ans.clear();
          ans.push_back({l->second.first, i});
          ans.push_back({l->second.second, j});
        }
        ++l;
      }
    }
  }
  cout << v << "\n" << ans.size() << "\n";
  for (auto a : ans) cout << a.first + 1 << " " << a.second + 1 << "\n";
}
