#include <cstdint>
#include <climits>
#include <cmath>
#include <iostream>

using namespace std;

typedef uint64_t Integer;

constexpr Integer power(Integer a, int n) {
	return (n == 0) ? 1 : a*power(a, n-1);
}

constexpr Integer power13[10] = {
	power(0,13), power(1,13), power(2,13), power(3,13), power(4,13),
	power(5,13), power(6,13), power(7,13), power(8,13), power(9,13),
};

template<unsigned K> inline void crack(const int from, const Integer acc) {
	for (int n = from; n < 10; n++) {
		crack<K-1>(n, acc + power13[n]);
	}
}

template<> inline void crack<0>(const int from, const Integer acc) {
	Integer a = acc;
	Integer sum = 0;
	while (a != 0) {
		sum += power13[a%10];
		a /= 10;
	}
	if (acc == sum) {
		cout << acc << endl;
	}
}

int main() {
	constexpr int N = 15;
	constexpr int BITS = sizeof(Integer)*CHAR_BIT;
	static_assert(BITS > log2(N) + 13*log2(9), "Integer is too small!");
	static_assert(BITS > (N-1)*log2(10), "Integer is too small!");

	crack<N>(0,0);

    return 0;
}