#include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
int n, m;
long long a[3000], b[3000];
long long sa, sb;
set<pair<long long, pair<int, int>>> s;
long long mi = 0x3f3f3f3f3f3f3f3fll;
pair<int, int> mii1, mii2;
int main() {
  int i, j, k;
  cin >> n;
  for (i = 0; i < n; i++) scanf("%lld", &a[i]), sa += a[i];
  cin >> m;
  for (i = 0; i < m; i++) scanf("%lld", &b[i]), sb += b[i];
  mi = abs(sa - sb);
  mii1 = pair<int, int>(-1, -1), mii2 = pair<int, int>(-1, -1);
  for (i = 0; i < n; i++)
    for (j = 0; j < m; j++) {
      long long nsa = sa + (b[j] - a[i]) * 2;
      if (mi > abs(nsa - sb)) {
        mi = abs(nsa - sb), mii1 = pair<int, int>(i, j);
      }
    }
  for (i = 0; i < m; i++)
    for (j = i + 1; j < m; j++)
      s.insert(make_pair(2 * (b[i] + b[j]), pair<int, int>(i, j)));
  for (i = 0; i < n; i++) {
    for (j = i + 1; j < n; j++) {
      long long u = a[i] + a[j];
      auto it1 =
          s.lower_bound(make_pair(sb - sa + 2 * u, pair<int, int>(-1, -1)));
      auto it2 = s.end();
      if (it1 != s.begin()) {
        it2 = prev(it1);
      }
      if (it1 != s.end()) {
        long long v = it1->first;
        if (mi > abs(sa - sb - 2 * u + v))
          mi = abs(sa - sb - 2 * u + v),
          mii1 = pair<int, int>(i, it1->second.first),
          mii2 = pair<int, int>(j, it1->second.second);
      }
      if (it2 != s.end()) {
        long long v = it2->first;
        if (mi > abs(sa - sb - 2 * u + v))
          mi = abs(sa - sb - 2 * u + v),
          mii1 = pair<int, int>(i, it2->second.first),
          mii2 = pair<int, int>(j, it2->second.second);
      }
    }
  }
  vector<pair<int, int>> ans;
  ans.push_back(mii1), ans.push_back(mii2);
  ans.erase(remove((ans).begin(), (ans).end(), pair<int, int>(-1, -1)),
            ans.end());
  long long u = sa - sb;
  for (auto e : ans) u += -2 * a[e.first] + 2 * b[e.second];
  printf("%lld\n%d\n", abs(u), ans.size());
  for (auto e : ans) printf("%d %d\n", e.first + 1, e.second + 1);
  return 0;
}
