#include <bits/stdc++.h>
using namespace std;
struct triplet {
  long long first, second, third;
  triplet() {}
  triplet(long long _f, long long _s, long long _t) {
    first = _f, second = _s, third = _t;
  }
  bool operator<(const triplet &oth) const {
    if (first != oth.first) return first < oth.first;
    if (second != oth.second) return second < oth.second;
    return third < oth.third;
  }
};
template <class T1, class T2>
bool upmin(T1 &x, T2 v) {
  if (x > v) {
    x = v;
    return true;
  }
  return false;
}
template <class T1, class T2>
bool upmax(T1 &x, T2 v) {
  if (x < v) {
    x = v;
    return true;
  }
  return false;
}
const long long LINF = 1LL << 60;
void solve() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; ++i) cin >> A[i];
  int M;
  cin >> M;
  vector<int> B(M);
  for (int i = 0; i < M; ++i) cin >> B[i];
  long long asum = 0, bsum = 0;
  for (int i = 0; i < N; ++i) asum += A[i];
  for (int i = 0; i < M; ++i) bsum += B[i];
  long long min_cost = abs(asum - bsum);
  bool is_swapped = false;
  if (not(asum >= bsum))
    is_swapped = true, swap(N, M), swap(asum, bsum), swap(A, B);
  vector<pair<int, int> > pair2swap;
  for (int i = 0; i < N; ++i)
    for (int j = 0; j < M; ++j) {
      long long nasum = asum - A[i] + B[j];
      long long nbsum = bsum - B[j] + A[i];
      if (abs(nasum - nbsum) < min_cost)
        min_cost = abs(nasum - nbsum), pair2swap = {pair<int, int>(i, j)};
    }
  set<triplet> ast;
  for (int i = 0; i < N; ++i)
    for (int j = i + 1; j < N; ++j)
      ast.insert(triplet(2LL * (A[i] + A[j]), i, j));
  for (int i = 0; i < M; ++i)
    for (int j = i + 1; j < M; ++j) {
      if (ast.empty()) break;
      long long z = asum - bsum + 2LL * (B[i] + B[j]);
      auto it = ast.lower_bound(triplet(z, -1, -1));
      if (it == ast.end()) {
        --it;
        long long score = abs(z - it->first);
        if (score < min_cost)
          min_cost = score, pair2swap = {pair<int, int>(it->second, i),
                                         pair<int, int>(it->third, j)};
      } else {
        long long score = abs(z - it->first);
        if (score < min_cost)
          min_cost = score, pair2swap = {pair<int, int>(it->second, i),
                                         pair<int, int>(it->third, j)};
        if (it != ast.begin()) {
          --it;
          score = abs(z - it->first);
          if (score < min_cost)
            min_cost = score, pair2swap = {pair<int, int>(it->second, i),
                                           pair<int, int>(it->third, j)};
        }
      }
    }
  cout << min_cost << "\n";
  cout << pair2swap.size() << "\n";
  for (int i = 0; i < pair2swap.size(); ++i) {
    if (is_swapped)
      cout << pair2swap[i].second + 1 << " " << pair2swap[i].first + 1 << "\n";
    else
      cout << pair2swap[i].first + 1 << " " << pair2swap[i].second + 1 << "\n";
  }
}
int main() {
  ios::sync_with_stdio(false);
  solve();
  return 0;
}
