#include <bits/stdc++.h>
using namespace std;
struct sum {
  long long val;
  int s, e;
  bool operator<(const sum &a) const {
    if (this->val != a.val) return this->val < a.val;
    if (this->s != a.s) return this->s < a.s;
    return this->e < a.e;
  }
};
int n, m, num;
long long suma, sumb, mini;
vector<long long> a, b;
vector<sum> vet;
pair<int, int> c1, c2;
sum left_search(sum aux) {
  int a = 0, b = n * m - 1, c;
  while (a < b) {
    c = a + (b - a) / 2;
    if (vet[c].val >= aux.val)
      b = c - 1;
    else if (vet[c].s > aux.s && vet[c].e > aux.e)
      b = c;
    else
      a = c + 1;
  }
  return vet[a];
}
sum right_search(sum aux) {
  int a = 0, b = n * m - 1, c;
  while (a < b) {
    c = a + (b - a) / 2;
    if (vet[c].val < aux.val)
      a = c + 1;
    else if (vet[c].s > aux.s && vet[c].e > aux.e)
      b = c;
    else
      a = c + 1;
  }
  return vet[a];
}
long long fabs(long long val) {
  if (val < 0) return -val;
  return val;
}
int main() {
  cin >> n;
  a = vector<long long>(n);
  suma = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    suma += a[i];
  }
  cin >> m;
  b = vector<long long>(m);
  sumb = 0;
  for (int i = 0; i < m; i++) {
    cin >> b[i];
    sumb += b[i];
  }
  sum temp, aux;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      temp.val = 2 * (b[j] - a[i]);
      temp.s = i;
      temp.e = j;
      vet.push_back(temp);
    }
  }
  sort(vet.begin(), vet.end());
  num = 0;
  mini = fabs(suma - sumb);
  temp.val = sumb - suma;
  temp.s = -1;
  temp.e = -1;
  aux = left_search(temp);
  if (fabs(sumb - (suma + aux.val)) < mini) {
    num = 1;
    mini = fabs(sumb - (suma + aux.val));
    c1.first = aux.s;
    c1.second = aux.e;
  }
  aux = right_search(temp);
  if (fabs(sumb - (suma + aux.val)) < mini) {
    num = 1;
    mini = fabs(sumb - (suma + aux.val));
    c1.first = aux.s;
    c1.second = aux.e;
  }
  long long nsuma;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      nsuma = 2 * (b[j] - a[i]) + suma;
      temp.val = sumb - nsuma;
      temp.s = i;
      temp.e = j;
      aux = left_search(temp);
      if (aux.s != i && aux.e != j && fabs(sumb - (nsuma + aux.val)) < mini) {
        num = 2;
        mini = fabs(sumb - (nsuma + aux.val));
        c1.first = i;
        c1.second = j;
        c2.first = aux.s;
        c2.second = aux.e;
      }
      aux = right_search(temp);
      if (aux.s != i && aux.e != j && fabs(sumb - (nsuma + aux.val)) < mini) {
        num = 2;
        mini = fabs(sumb - (nsuma + aux.val));
        c1.first = i;
        c1.second = j;
        c2.first = aux.s;
        c2.second = aux.e;
      }
    }
  }
  cout << mini << endl;
  cout << num << endl;
  if (num) cout << c1.first + 1 << " " << c1.second + 1 << endl;
  if (num > 1) cout << c2.first + 1 << " " << c2.second + 1 << endl;
  return 0;
}
