#include <bits/stdc++.h>
using namespace std;
vector<pair<long long, pair<int, int> > > V;
int i, j, n, m, s[2020], t[2020], k, w, x, y, z;
long long ans, v, ss, tt;
int main() {
  for (i = scanf("%d", &n); i <= n; i++) scanf("%d", s + i), ss += s[i];
  for (i = scanf("%d", &m); i <= m; i++) scanf("%d", t + i), tt += t[i];
  ans = abs(v = ss - tt);
  for (i = 1; i <= n; i++)
    for (j = 1; j <= m; j++)
      if (abs(v - s[i] - s[i] + t[j] + t[j]) < ans)
        ans = abs(v - s[i] - s[i] + t[j] + t[j]), k = 1, w = i, x = j;
  for (i = 1; i < n; i++)
    for (j = i + 1; j <= n; j++)
      V.push_back(pair<long long, pair<int, int> >(2ll * (s[i] + s[j]),
                                                   pair<int, int>(i, j)));
  sort(V.begin(), V.end());
  for (i = 1; i < m; i++)
    for (j = i + 1; j <= m; j++) {
      auto it = lower_bound(V.begin(), V.end(),
                            pair<long long, pair<int, int> >(
                                2ll * (t[i] + t[j]) + v, pair<int, int>()));
      if (it != V.end() && abs(v - (*it).first + 2ll * (t[i] + t[j])) < ans)
        ans = abs(v - (*it).first + 2ll * (t[i] + t[j])), k = 2,
        w = (*it).second.first, x = i, y = (*it).second.second, z = j;
      if (it != V.begin() && abs(v - (*--it).first + 2ll * (t[i] + t[j])) < ans)
        ans = abs(v - (*it).first + 2ll * (t[i] + t[j])), k = 2,
        w = (*it).second.first, x = i, y = (*it).second.second, z = j;
    }
  printf("%I64d\n%d\n", ans, k);
  if (k == 1)
    printf("%d %d", w, x);
  else if (k)
    printf("%d %d\n%d %d", w, x, y, z);
}
