#include <bits/stdc++.h>
using namespace std;
const int N = 2010;
const int MOD = 1000000007;
int n, m;
vector<pair<int, int> > ans;
vector<pair<long long, pair<int, int> > > sB;
long long sumA, sumB, v;
int a[N], b[N];
void tr(pair<long long, pair<int, int> > a,
        pair<long long, pair<int, int> > b) {
  long long newMn =
      abs((sumA - a.first + b.first) - (sumB - b.first + a.first));
  if (newMn < v) {
    v = newMn;
    ans.clear();
    ans.push_back(make_pair(a.second.first, b.second.first));
    ans.push_back(make_pair(a.second.second, b.second.second));
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    sumA += a[i];
  }
  scanf("%d", &m);
  for (int i = 1; i <= m; ++i) {
    scanf("%d", &b[i]);
    sumB += b[i];
  }
  v = abs(sumA - sumB);
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; j++) {
      long long newMn = abs((sumA - a[i] + b[j]) - (sumB - b[j] + a[i]));
      if (v > newMn) {
        v = newMn;
        ans.clear();
        ans.push_back(make_pair(i, j));
      }
    }
  }
  for (int i = 1; i <= m; ++i)
    for (int j = i + 1; j <= m; j++) {
      ;
      sB.push_back(make_pair(b[i] + b[j], make_pair(i, j)));
    }
  sort(sB.begin(), sB.end());
  for (int i = 1; i <= n; ++i)
    for (int j = i + 1; j <= n; j++) {
      long long have = a[i] + a[j];
      long long diff = sumB - sumA;
      long long toSearch = have + diff / 2;
      vector<pair<long long, pair<int, int> > >::iterator it = lower_bound(
          sB.begin(), sB.end(), make_pair(toSearch, make_pair(-1, -1)));
      int num = 2;
      while (num--) {
        if (it != sB.end()) tr(make_pair(have, make_pair(i, j)), *it);
        if (it == sB.begin()) break;
        it--;
      }
    }
  printf("%lld\n", v);
  printf("%d\n", (int)ans.size());
  for (int i = 0; i < ans.size(); ++i) {
    printf("%d %d\n", ans[i].first, ans[i].second);
  }
  return 0;
}
