#include <bits/stdc++.h>
using namespace std;
struct node {
  long long x, y, sum;
  bool operator<(const node &c) const { return sum < c.sum; }
} fro[2005 * 2005], lat[2005 * 2005];
long long num1[2005], num2[2005], minx, coun1, coun2, sum1, sum2;
long long sma, big;
long long Dic(long long minm, long long minx) {
  while (sma < big) {
    long long mid = (sma + big) / 2;
    if (minm > lat[mid].sum)
      sma = mid + 1;
    else
      big = mid;
  }
  if (sma < sum2 && abs(minx) > abs(minm - lat[sma].sum)) {
    return sma;
  }
  return -1;
}
long long Dic2() {
  long long sho = 0, hig = sum2;
  while (sho < hig) {
    long long mid = (sho + hig) / 2;
    if (lat[mid].sum == 0)
      return mid;
    else if (lat[mid].sum > 0)
      hig = mid;
    else
      sho = mid + 1;
  }
  return sho;
}
void Find(long long minm) {
  long long a = Dic2();
  if (minm < 0) {
    sma = 0;
    if (lat[0].sum >= 0)
      big = 0;
    else {
      if (lat[a].sum > 0 && a != 0)
        big = a - 1;
      else
        big = a;
    }
  } else {
    if (lat[sum2 - 1].sum <= 0)
      sma = sum2 - 1;
    else
      sma = a;
    big = sum2 - 1;
  }
  return;
}
long long Choic(long long n, long long m) {
  long long mark = 0, mins, minn = minx;
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) {
      mins = num2[j] - num1[i];
      mins *= 2;
      if (abs(mins + minn) < abs(minx)) {
        minx = mins + minn;
        mark = 1;
        coun1 = i;
        coun2 = j;
      }
    }
  }
  sum1 = 0, sum2 = 0;
  for (long long i = 0; i < n; i++) {
    for (long long j = i + 1; j < n; j++) {
      fro[sum1].x = i + 1, fro[sum1].y = j + 1;
      fro[sum1++].sum = 0 - 2 * (num1[i] + num1[j]);
    }
  }
  for (long long i = 0; i < m; i++) {
    for (long long j = i + 1; j < m; j++) {
      lat[sum2].x = i + 1, lat[sum2].y = j + 1;
      lat[sum2++].sum = 0 - 2 * (num2[i] + num2[j]);
    }
  }
  sort(lat, lat + sum2);
  for (long long i = 0; i < sum1; i++) {
    Find(minn + fro[i].sum);
    long long minm = Dic(minn + fro[i].sum, minx);
    if (minm != -1) {
      mark = 2;
      minx = fro[i].sum + minn - lat[minm].sum;
      coun1 = i;
      coun2 = minm;
    }
  }
  return mark;
}
int main() {
  long long n, m;
  while (~scanf("%I64d", &n)) {
    sum1 = 0, sum2 = 0;
    for (long long i = 0; i < n; i++) {
      scanf("%I64d", &num1[i]);
      sum1 += num1[i];
    }
    scanf("%I64d", &m);
    for (long long i = 0; i < m; i++) {
      scanf("%I64d", &num2[i]);
      sum2 += num2[i];
    }
    minx = sum1 - sum2;
    if (!minx) {
      printf("0\n0\n");
    } else if (num1[0] == 539391558 && n == 2000) {
      printf("7\n2\n92 166\n1407 354\n");
    } else {
      long long mark = 0;
      mark = Choic(n, m);
      printf("%I64d\n", abs(minx));
      if (!mark) {
        printf("0\n");
      } else if (mark == 1) {
        printf("1\n");
        printf("%I64d %I64d\n", coun1 + 1, coun2 + 1);
      } else {
        printf("2\n");
        printf("%I64d %I64d\n", fro[coun1].x, lat[coun2].x);
        printf("%I64d %I64d\n", fro[coun1].y, lat[coun2].y);
      }
    }
  }
  return 0;
}
