//#include <iostream>
#include <fstream>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <ctime>
#include <algorithm>
#include <sstream>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <cstdlib>
#include <cstdio>
#include <iterator>
#include <functional>
#include <bitset>
#define mp make_pair
#define pb push_back

#ifdef LOCAL
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#else
#define eprintf(...)
#endif

#define TIMESTAMP(x) eprintf("["#x"] Time : %.3lf s.\n", clock()*1.0/CLOCKS_PER_SEC)
#define TIMESTAMPf(x,...) eprintf("[" x "] Time : %.3lf s.\n", __VA_ARGS__, clock()*1.0/CLOCKS_PER_SEC)

#if ( ( _WIN32 || __WIN32__ ) && __cplusplus < 201103L)
    #define LLD "%I64d"
#else
    #define LLD "%lld"
#endif

using namespace std;

#define TASKNAME "wall"

#ifdef LOCAL
static struct __timestamper {
    string what;
    __timestamper(const char* what) : what(what){};
    __timestamper(const string& what) : what(what){};
	~__timestamper(){
        TIMESTAMPf("%s", what.data());
	}
} __TIMESTAMPER("end");
#else 
struct __timestamper {};
#endif

typedef long long ll;
typedef long double ld;


vector< pair<int, int> > res;
bool check(const vector<int>& a, const vector<int>& b, int need) {
	int ptr = 0;
	res.clear();
	for (int i = 0; i < (int)a.size(); i++) {
		while (ptr < (int)b.size() && a[i] + b[ptr] < need) ptr++;
		if (a[i] < need && ptr == (int)b.size()) return false;
		if (a[i] < need) {
			res.pb(mp(i, ptr));
			ptr++;             
		}
	}
	return true;
}
int main(){
  assert(freopen(TASKNAME".in","r",stdin));
  assert(freopen(TASKNAME".out","w",stdout));

  int n, m;
  scanf("%d",&n);
  vector<int> a(n);
  for (int i = 0; i < n; i++)
  	scanf("%d",&a[i]);
  scanf("%d",&m);
  vector<int> b(m);
  for (int i = 0; i < m; i++)
  	scanf("%d",&b[i]);

  int l = 0;
  int r = 2e9+1;
  while (r - l > 1) {
  	int mid = (l + r) / 2;
  	if (check(a, b, mid))
  		l = mid;
  	else
  		r = mid;
  }
  printf("%d ", l);      
  assert(check(a, b, l));
  printf("%d\n", res.size());
  for (int i = 0; i < (int)res.size(); i++)
  	printf("%d %d\n", res[i].first+1, res[i].second+1);
  return 0;
}