#include <bits/stdc++.h>
using namespace std;
const double PI = 3.1415926;
template <typename T>
T gcd(T a, T b) {
  while (b) {
    T c = a % b;
    a = b;
    b = c;
  }
  return a;
}
template <typename T>
T lcm(T a, T b) {
  assert(a / gcd(a, b) <= numeric_limits<T>::max() / b);
  return a * (b / gcd(a, b));
}
class out {
 public:
  template <typename T>
  out &operator()(const T &t) {
    cout << t << ' ';
    return *this;
  }
  template <typename T1, typename T2>
  out &operator()(const pair<T1, T2> &t) {
    cout << '(' << t.first << ',' << t.second << ')' << ' ';
    return *this;
  }
};
template <typename iter>
inline void print_(iter beg, iter end) {
  cout << endl;
  for_each(beg, end, out());
  cout << endl;
}
template <typename T>
inline void print_(const T &t) {
  cout << endl << t << endl;
}
inline void print_(const char *t) { cout << endl << t << endl; }
template <typename T, unsigned int M>
inline void print_(const T (&t)[M]) {
  cout << endl;
  for (unsigned int i = 0; i < M; ++i) {
    cout << t[i] << ' ';
  }
  cout << endl;
}
template <typename T, unsigned int M>
inline void print_(const T (&t)[M], unsigned int c) {
  cout << endl;
  for (unsigned int i = 0; i < c; ++i) {
    cout << t[i] << ' ';
  }
  cout << endl;
}
template <typename T, unsigned int M, unsigned int N>
inline void print_(const T (&t)[M][N]) {
  cout << endl;
  for (unsigned int i = 0; i < M; ++i) {
    for (unsigned int j = 0; j < N; ++j) {
      cout << t[i][j] << ' ';
    }
    cout << endl;
  }
}
template <typename T, unsigned int M, unsigned int N>
inline void print_(const T (&t)[M][N], unsigned int r, unsigned int c) {
  cout << endl;
  for (unsigned int i = 0; i < r; ++i) {
    for (unsigned int j = 0; j < c; ++j) {
      cout << t[i][j] << ' ';
    }
    cout << endl;
  }
}
template <typename T>
inline int BKDRHash(const T *str) {
  register int hash = 0;
  while (int ch = (int)*str++) {
    hash = hash * 131 + ch;
  }
  return hash;
}
template <typename T>
inline T powxy(T x, int y) {
  T r;
  for (r = 1; y > 0; --y) r *= x;
  return r;
}
inline unsigned long long factorial(unsigned long long n) {
  unsigned long long r;
  for (r = 1; n > 0; --n) r *= n;
  return r;
}
inline unsigned long long permutation(unsigned long long n,
                                      unsigned long long k) {
  unsigned long long r = 1;
  while (k--) r *= n--;
  return r;
}
inline unsigned long long combination(unsigned long long n,
                                      unsigned long long k) {
  return permutation(n, k) / factorial(k);
}
int n, m;
long long int suma, sumb;
int a[2001];
int b[2001];
struct s {
  int i;
  int j;
  long long int d;
  s(const s &rs) : i(rs.i), j(rs.j), d(rs.d) {}
  s(int i_, int j_, long long int d_) : i(i_), j(j_), d(d_) {}
  s &operator=(const s &rs) {
    i = rs.i;
    j = rs.j;
    d = rs.d;
    return *this;
  }
};
ostream &operator<<(ostream &os, const s &rs) {
  os << rs.i << '|' << rs.j << '|' << rs.d;
}
bool operator<(const s &l, const s &r) { return l.d < r.d; }
vector<s> vs;
vector<pair<int, int> > vp;
long long int solve() {
  long long int mi = suma - sumb;
  if (mi < 0) mi = -mi;
  for (unsigned int k = 0; k < vs.size(); ++k) {
    long long int d = suma - sumb - vs[k].d;
    if (d < 0) d = -d;
    if (d < mi) {
      vp.clear();
      vp.push_back(make_pair(vs[k].j, vs[k].i));
      mi = d;
    }
    pair<vector<s>::iterator, vector<s>::iterator> t =
        equal_range(vs.begin(), vs.end(), s(0, 0, suma - sumb - vs[k].d));
    if (t.first > vs.begin()) --t.first;
    if (t.second < vs.end()) ++t.second;
    for (; t.first != t.second; ++t.first) {
      if (t.first->i != vs[k].i && t.first->j != vs[k].j) {
        d = suma - sumb - vs[k].d - t.first->d;
        if (d < 0) d = -d;
        if (d < mi) {
          vp.clear();
          vp.push_back(make_pair(vs[k].j, vs[k].i));
          vp.push_back(make_pair(t.first->j, t.first->i));
          mi = d;
        }
      }
    }
  }
  return mi;
}
int main() {
  vs.reserve(sizeof(s) * 1000000);
  scanf("%d", &n);
  for (int j = 1; j <= n; ++j) {
    scanf("%d", a + j);
    suma += *(a + j);
  }
  scanf("%d", &m);
  for (int i = 1; i <= m; ++i) {
    scanf("%d", b + i);
    sumb += *(b + i);
    for (int j = 1; j <= n; ++j) {
      vs.push_back(s(i, j, 2 * (long long int)(*(a + j) - *(b + i))));
    }
  }
  sort(vs.begin(), vs.end());
  (vs.begin(), vs.end());
  cout << abs(solve()) << endl;
  printf("%d\n", vp.size());
  for (unsigned int i = 0; i < vp.size(); ++i) {
    printf("%d %d\n", vp[i].first, vp[i].second);
  }
  return 0;
}
