#include <bits/stdc++.h>
using namespace std;
int n, m;
long long ans, sa, sb;
vector<pair<long long, int> > sol, a, b;
void read(int &n, vector<pair<long long, int> > &a) {
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    long long x;
    cin >> x;
    a.push_back(make_pair(x, i));
  }
}
vector<pair<long long, int> > construct(vector<pair<long long, int> > &a) {
  vector<pair<long long, int> > v;
  v.reserve(a.size() * (a.size() - 1) / 2);
  for (int i = 0; i < a.size(); ++i) {
    for (int j = i + 1; j < a.size(); ++j) {
      v.push_back(make_pair(a[i].first + a[j].first,
                            (a[i].second << 15) + a[j].second));
    }
  }
  return v;
}
long long sum(vector<pair<long long, int> > &a) {
  long long sum = 0;
  for (int i = 0; i < a.size(); ++i) sum += a[i].first;
  return sum;
}
void updateSol(long long newSol, int ind1, int ind2) {
  if (newSol < ans) {
    ans = newSol;
    sol.clear();
    sol.push_back(make_pair(ind1 & ((1 << 15) - 1), ind2 & ((1 << 15) - 1)));
    if ((ind1 >> 15) > 0) {
      sol.push_back(make_pair(ind1 >> 15, ind2 >> 15));
    }
  }
}
void solve(vector<pair<long long, int> > &a, vector<pair<long long, int> > &b) {
  if (a.size() == 0 || b.size() == 0) return;
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  int j = 0;
  for (int i = 0; i < a.size(); ++i) {
    while (j < b.size() && 2 * (b[j].first - a[i].first) + sa - sb <= 0) ++j;
    if (j != b.size())
      updateSol(abs(sa - sb + 2 * (-a[i].first + b[j].first)), a[i].second,
                b[j].second);
    if (j > 0) {
      --j;
      updateSol(abs(sa - sb + 2 * (-a[i].first + b[j].first)), a[i].second,
                b[j].second);
      ++j;
    }
  }
}
void print() {
  cout << ans << "\n";
  cout << sol.size() << "\n";
  for (int i = 0; i < sol.size(); ++i) {
    cout << sol[i].first << " " << sol[i].second << "\n";
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  read(n, a);
  read(m, b);
  sa = sum(a);
  sb = sum(b);
  ans = abs(sa - sb);
  solve(a, b);
  a = construct(a);
  b = construct(b);
  solve(a, b);
  print();
}
