#include <iostream>
#include <vector>
#include <cmath>
int main()
{
int cols = 0;
do
{
std::cout << "Enter the number of columns: " << std::flush;
} while(!(std::cin >> cols) || cols <= 0); std::cout << std::endl;
int total = std::pow(3.0, cols);
for(int i = 0; i < total; ++i)
{
for(int j = cols-1; j >= 0; --j)
{
std::cout << (i/static_cast<int>(std::pow(3.0, j)))%3;
}
std::cout << std::endl;
}
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8Y21hdGg+CgppbnQgbWFpbigpCnsKICAgIGludCBjb2xzID0gMDsKICAgIGRvCiAgICB7CiAgICAgICAgc3RkOjpjb3V0IDw8ICJFbnRlciB0aGUgbnVtYmVyIG9mIGNvbHVtbnM6ICIgPDwgc3RkOjpmbHVzaDsKICAgIH0gd2hpbGUoIShzdGQ6OmNpbiA+PiBjb2xzKSB8fCBjb2xzIDw9IDApOyBzdGQ6OmNvdXQgPDwgc3RkOjplbmRsOwogICAgaW50IHRvdGFsID0gc3RkOjpwb3coMy4wLCBjb2xzKTsKICAgIGZvcihpbnQgaSA9IDA7IGkgPCB0b3RhbDsgKytpKQogICAgewogICAgICAgIGZvcihpbnQgaiA9IGNvbHMtMTsgaiA+PSAwOyAtLWopCiAgICAgICAgewogICAgICAgICAgICBzdGQ6OmNvdXQgPDwgKGkvc3RhdGljX2Nhc3Q8aW50PihzdGQ6OnBvdygzLjAsIGopKSklMzsKICAgICAgICB9CiAgICAgICAgc3RkOjpjb3V0IDw8IHN0ZDo6ZW5kbDsKICAgIH0KfQ==