#include <bits/stdc++.h>
using namespace std;
long long mod = 998244353;
long long powerMod(long long a, long long n) {
  if (n == 0) return 1;
  long long res = powerMod((a % mod * a % mod) % mod, n / 2) % mod;
  if (n % 2) return (a % mod * res % mod) % mod;
  return res;
}
long long cs[2222], cd[2222];
vector<pair<long long, pair<long long, long long> > > as, bs;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n, sum1 = 0, sum2 = 0;
  cin >> n;
  long long a[n + 1];
  for (long long i = 1; i < n + 1; i++) cin >> a[i], sum1 += a[i];
  long long m;
  cin >> m;
  long long b[m + 1];
  for (long long i = 1; i < m + 1; i++) cin >> b[i], sum2 += b[i];
  if (sum1 == sum2) {
    cout << "0\n0";
    return 0;
  }
  long long mini = LLONG_MAX;
  pair<long long, long long> single, doubl[2];
  long long flag = 1;
  for (long long i = 1; i < n + 1; i++) {
    long long temp1 = sum1 - a[i];
    for (long long j = 1; j < m + 1; j++) {
      long long temp2 = sum2 - b[j];
      if (abs((temp1 + b[j]) - (temp2 + a[i])) < mini) {
        flag = 1;
        mini = abs((temp1 + b[j]) - (temp2 + a[i]));
        single.first = i;
        single.second = j;
      }
    }
  }
  if (n > 1 && m > 1) {
    for (long long i = 1; i < n + 1; i++)
      for (long long j = i + 1; j < n + 1; j++)
        as.push_back({a[i] + a[j], {i, j}});
    for (long long i = 1; i < m + 1; i++)
      for (long long j = i + 1; j < m + 1; j++)
        bs.push_back({b[i] + b[j], {i, j}});
    sort(bs.begin(), bs.end());
    for (long long i = 0; i < (long long)as.size(); i++) {
      long long temp1 = sum1 - as[i].first;
      long long temp2 = sum2 + as[i].first;
      long long l = 0, r = (long long)bs.size() - 1;
      while (l <= r) {
        long long mid = l + (r - l) / 2;
        long long add = bs[mid].first;
        long long first = (temp1 + add);
        long long second = (temp2 - add);
        long long check = abs((temp1 + add) - (temp2 - add));
        if (check < mini) {
          mini = check;
          flag = 2;
          doubl[0] = {as[i].second.first, bs[mid].second.first};
          doubl[1] = {as[i].second.second, bs[mid].second.second};
        }
        if (mini + 1 < bs.size()) {
          long long add = bs[mid + 1].first;
          long long first = (temp1 + add);
          long long second = (temp2 - add);
          long long check = abs((temp1 + add) - (temp2 - add));
          if (check < mini) {
            mini = check;
            flag = 2;
            doubl[0] = {as[i].second.first, bs[mid + 1].second.first};
            doubl[1] = {as[i].second.second, bs[mid + 1].second.second};
          }
        }
        if (mid - 1 >= 0) {
          long long add = bs[mid - 1].first;
          long long first = (temp1 + add);
          long long second = (temp2 - add);
          long long check = abs((temp1 + add) - (temp2 - add));
          if (check < mini) {
            mini = check;
            flag = 2;
            doubl[0] = {as[i].second.first, bs[mid - 1].second.first};
            doubl[1] = {as[i].second.second, bs[mid - 1].second.second};
          }
        }
        if (first > second)
          r = mid - 1;
        else
          l = mid + 1;
      }
    }
  }
  cout << mini << '\n';
  if (flag == 1) {
    cout << flag << '\n';
    cout << single.first << ' ' << single.second << '\n';
  } else {
    cout << flag << '\n';
    cout << doubl[0].first << ' ' << doubl[0].second << '\n';
    cout << doubl[1].first << ' ' << doubl[1].second << '\n';
  }
  return 0;
}
