#include <bits/stdc++.h>
using namespace std;
const long long inf = 9999999999999999;
const int N = 2005;
const int M = 2000005;
const double eps = 1e-6;
vector<pair<int, int> > ans;
int n, m, cnt;
long long a[N], b[N], sum1, sum2;
struct point {
  long long x;
  int id1, id2;
} s[N * N];
bool cmp(point a, point b) {
  if (a.x != b.x) return a.x < b.x;
  if (a.id1 != b.id1) return a.id1 < b.id1;
  return a.id2 < b.id2;
}
int BiSearch(long long goal) {
  int l = 0, r = cnt - 1, mid;
  while (l <= r) {
    mid = (l + r) >> 1;
    if (s[mid].x == goal)
      return mid;
    else if (s[mid].x > goal)
      r = mid - 1;
    else
      l = mid + 1;
  }
  return l;
}
int main() {
  while (~scanf("%d", &n)) {
    int i, j;
    sum1 = sum2 = 0;
    for (i = 0; i < n; i++) scanf("%lld", &a[i]), sum1 += a[i];
    scanf("%d", &m);
    for (i = 0; i < m; i++) scanf("%lld", &b[i]), sum2 += b[i];
    ans.clear();
    if (sum1 == sum2)
      printf("0\n0\n");
    else {
      long long ret = abs(sum1 - sum2);
      long long t = sum1 - sum2, tmp;
      int l = -1, r = -1;
      for (i = 0; i < m; i++) {
        for (j = 0; j < n; j++) {
          tmp = t + 2 * b[i] - 2 * a[j];
          tmp = abs(tmp);
          if (tmp < ret) {
            l = j + 1, r = i + 1;
            ret = tmp;
          }
        }
      }
      if (l != -1) ans.push_back(make_pair(l, r));
      if (n != 1 && m != 1) {
        cnt = 0;
        for (i = 0; i < n; i++)
          for (j = i + 1; j < n; j++) {
            s[cnt].x = a[i] + a[j];
            s[cnt].x *= 2;
            s[cnt].id1 = i + 1, s[cnt++].id2 = j + 1;
          }
        sort(s, s + cnt, cmp);
        long long l1 = -1, r1 = -1;
        long long l2, r2;
        long long t1, t2;
        for (i = 0; i < m; i++) {
          for (j = i + 1; j < m; j++) {
            tmp = t + 2 * (b[i] + b[j]);
            int cur = BiSearch(tmp);
            t1 = abs(tmp - s[cur].x);
            if (cur != 0) t2 = abs(tmp - s[cur - 1].x);
            if (ret <= min(t1, t2)) continue;
            if (cur == 0 || t1 <= t2) {
              ret = t1;
              l1 = s[cur].id1, r1 = i + 1;
              l2 = s[cur].id2, r2 = j + 1;
            }
            if (cur != 0 && t1 > t2) {
              ret = t2;
              l1 = s[cur - 1].id1, r1 = i + 1;
              l2 = s[cur - 1].id2, r2 = j + 1;
            }
          }
        }
        if (l1 != -1) {
          ans.clear();
          ans.push_back(make_pair(l1, r1));
          ans.push_back(make_pair(l2, r2));
        }
      }
      cout << ret << endl;
      cout << ans.size() << endl;
      for (i = 0; i < ans.size(); i++)
        cout << ans[i].first << " " << ans[i].second << endl;
    }
  }
  return 0;
}
