#include <iostream>
#include <cmath>
#include <vector>

template <typename typeVec1, typename typeVec2>
void customPerms(typeVec1 a, typeVec2 b) {

    int r = a.size(), n = b.size();
    int r1 = r - 1, n1 = n - 1;
    std::vector<int> z(r, 0);
    int numRows = (int) std::pow(n, r);

    for (int i = 0; i < numRows; ++i) {
        for (int j = 0; j < r; ++j)
            std::cout << a[j] << b[z[j]];
        std::cout << std::endl;

        for (int k = r1; k >= 0; --k) {
            if (z[k] != n1) {
                ++z[k];
                break;
            } else {
                z[k] = 0;
            }
        }
    }
}

int main() {
    std::cout << "Example 1 : " << std::endl;
    std::vector<std::string> a1 = {"a", "b", "c"};
    std::vector<int> b1 = {1, 2};
    customPerms(a1, b1);
    
    std::cout << "\nExample 2 : " << std::endl;
    std::vector<char> a2 = {'a', 'b'};
    std::vector<int> b2 = {1, 2, 3};
    customPerms(a2, b2);
    return 0;
}