using namespace std;
#include <bits/stdc++.h>
typedef long long ll;

ll nummatchesslow(map<int,int> map1, map<int,int> map2, int target) {

    ll res = 0;
    for (auto x=map1.begin(); x!=map1.end(); x++)
        for (auto y=map2.begin(); y!=map2.end(); y++)
            if (  ((*x).first + (*y).first) == target )
                res += ( ((*x).second) * ((*y).second));

    return res;
}

ll nummatchesfast(map<int,int> map1, map<int,int> map2, int target) {

    ll res = 0;
    for (auto x=map1.begin(); x!=map1.end(); x++) {
        int need = target - (*x).first;
        auto tmp = map2.find(need);
        if (tmp != map2.end())
            res += ((*x).second)*((*tmp).second);
    }

    return res;
}

int main() {

    map<int,int> m1;
    map<int,int> m2;
    m1[3] = 5;
    m1[7] = 2;
    m1[8] = 1;
    m2[1] = 7;
    m2[5] = 4;
    m2[8] = 3;

    for (int t=2; t<20; t++)
        cout << t << " " << nummatchesslow(m1, m2, t) << " " << nummatchesfast(m1, m2, t) << endl;

    return 0;
}
