#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;

int main()
{
    freopen("wall.in", "r", stdin);
    freopen("wall.out", "w", stdout);
    int n, m;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++)
        cin >> a[i];
    cin >> m;
    vector<int> b(m);
    for (int j = 0; j < m; j++)
        cin >> b[j]; 
    long long l = 0, r = (long long)1e12 + 7;
    while (l < r - 1)
    {
        long long cur = (l + r) / 2;
        bool is_good = true;
        for (int i = 0, j = 0; i < n && is_good; i++)
        {
            if (a[i] >= cur)    
                continue;
            while (j < m && a[i] + b[j] < cur)
                j++;
            if (j >= m)
                is_good = false;
            j++;
        }
        if (is_good)
            l = cur;
        else
            r = cur;
    }
    vector<pair<int, int> > ans;
    for (int i = 0, j = 0; i < n; i++)
    {
        if (a[i] >= l)    
            continue;
        while (j < m && a[i] + b[j] < l)
            j++;
        if (j < m)
            ans.push_back(make_pair(i, j)), j++;
    }
    cout << l << ' ' << ans.size() << endl;
    for (int i = 0; i < (int)ans.size(); i++)
        cout << ans[i].first + 1 << ' ' << ans[i].second + 1 << endl;
    return 0;
}