#include <bits/stdc++.h>
using namespace std;
int a[2000], b[2000];
inline bool valid(int i, int j, pair<int, int> pii) {
  return i != pii.first && j != pii.second;
}
int main() {
  int n, m;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  scanf("%d", &m);
  for (int i = 0; i < m; i++) scanf("%d", &b[i]);
  vector<pair<int, pair<int, int> > > v;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      int d = a[i] - b[j];
      v.push_back(make_pair(d, make_pair(i, j)));
    }
  }
  sort(v.begin(), v.end());
  long long sa = 0, sb = 0;
  for (int i = 0; i < n; i++) sa += a[i];
  for (int i = 0; i < m; i++) sb += b[i];
  long long minD = abs(sa - sb);
  vector<pair<int, int> > pp;
  int sz = v.size(), id;
  if (sa - sb - 2LL * v[0].first <= 0)
    id = 0;
  else if (sa - sb - 2LL * v[sz - 1].first >= 0)
    id = sz - 1;
  else {
    int lo = 0, hi = sz - 1;
    while (hi - lo > 1) {
      int mid = lo + (hi - lo) / 2;
      if (sa - sb - 2LL * v[mid].first >= 0)
        lo = mid;
      else
        hi = mid;
    }
    if (abs(sa - sb - 2LL * v[lo].first) < abs(sa - sb - 2LL * v[hi].first))
      id = lo;
    else
      id = hi;
  }
  long long diff = abs(sa - sb - 2LL * v[id].first);
  if (diff < minD) {
    minD = diff;
    pp.push_back(v[id].second);
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      long long sab = sa - sb - 2LL * (a[i] - b[j]);
      if (sab - 2LL * v[0].first <= 0)
        id = 0;
      else if (sab - 2LL * v[sz - 1].first >= 0)
        id = sz - 1;
      else {
        int lo = 0, hi = sz - 1;
        while (hi - lo > 1) {
          int mid = lo + (hi - lo) / 2;
          if (sab - 2LL * v[mid].first >= 0)
            lo = mid;
          else
            hi = mid;
        }
        if (abs(sab - 2LL * v[lo].first) < abs(sab - 2LL * v[hi].first))
          id = lo;
        else
          id = hi;
      }
      for (int k = -20; k <= 20; k++) {
        if (id + k >= 0 && id + k < sz) {
          long long diff = abs(sab - 2LL * v[id + k].first);
          if (diff < minD && valid(i, j, v[id + k].second)) {
            minD = diff;
            pp.clear();
            pp.push_back(make_pair(i, j));
            pp.push_back(v[id + k].second);
          }
        }
      }
    }
  }
  cout << minD << endl;
  cout << pp.size() << endl;
  for (int i = 0; i < pp.size(); i++)
    cout << pp[i].first + 1 << " " << pp[i].second + 1 << endl;
  return 0;
}
