#include <bits/stdc++.h>
using namespace std;
typedef complex<double> ftype;
const double pi = acos(-1);
const int maxn = 1 << 17;
ftype w[maxn];
void init() {
for(int i = 0; i < maxn; i++) {
w[i] = polar(1., 2 * pi / maxn * i);
}
}
template<typename T>
void fft(T *in, ftype *out, int n, int k = 1) {
if(n == 1) {
*out = *in;
return;
}
int t = maxn / n;
n >>= 1;
fft(in, out, n, 2 * k);
fft(in + k, out + n, n, 2 * k);
for(int i = 0, j = 0; i < n; i++, j += t) {
ftype t = w[j] * out[i + n];
out[i + n] = out[i] - t;
out[i] += t;
}
}
vector<ftype> evaluate(vector<int> p) {
while(__builtin_popcount(p.size()) != 1) {
p.push_back(0);
}
vector<ftype> res(p.size());
fft(p.data(), res.data(), p.size());
return res;
}
vector<int> interpolate(vector<ftype> p) {
int n = p.size();
vector<ftype> inv(n);
fft(p.data(), inv.data(), n);
vector<int> res(n);
for(int i = 0; i < n; i++) {
res[i] = round(real(inv[i]) / n);
}
reverse(begin(res) + 1, end(res));
return res;
}
void align(vector<int> &a, vector<int> &b) {
int n = a.size() + b.size() - 1;
while(a.size() < n) {
a.push_back(0);
}
while(b.size() < n) {
b.push_back(0);
}
}
vector<int> poly_multiply(vector<int> a, vector<int> b) {
align(a, b);
auto A = evaluate(a);
auto B = evaluate(b);
for(int i = 0; i < A.size(); i++) {
A[i] *= B[i];
}
return interpolate(A);
}
const int base = 10;
vector<int> normalize(vector<int> c) {
int carry = 0;
for(auto &it: c) {
it += carry;
carry = it / base;
it %= base;
}
while(carry) {
c.push_back(carry % base);
carry /= base;
}
return c;
}
vector<int> multiply(vector<int> a, vector<int> b) {
return normalize(poly_multiply(a, b));
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
init();
for(int a = 1; a <= 1000; a++) {
for(int b = 1; b <= a; b++) {
vector<int> A{a}, B{b};
auto C = multiply(normalize(A), normalize(B));
while(C.back() == 0) {
C.pop_back();
}
assert(C == normalize({a * b}));
}
}
}
I2luY2x1ZGUgPGJpdHMv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KICAgICAgICBjYXJyeSA9IGl0IC8gYmFzZTsKICAgICAgICBpdCAlPSBiYXNlOwogICAgfQogICAgd2hpbGUoY2FycnkpIHsKICAgICAgICBjLnB1c2hfYmFjayhjYXJyeSAlIGJhc2UpOwogICAgICAgIGNhcnJ5IC89IGJhc2U7CiAgICB9CiAgICByZXR1cm4gYzsKfQoKdmVjdG9yPGludD4gbXVsdGlwbHkodmVjdG9yPGludD4gYSwgdmVjdG9yPGludD4gYikgewogICAgcmV0dXJuIG5vcm1hbGl6ZShwb2x5X211bHRpcGx5KGEsIGIpKTsKfQoKc2lnbmVkIG1haW4oKSB7CiAgICBpb3M6OnN5bmNfd2l0aF9zdGRpbygwKTsKICAgIGNpbi50aWUoMCk7CiAgICBpbml0KCk7CiAgICBmb3IoaW50IGEgPSAxOyBhIDw9IDEwMDA7IGErKykgewogICAgICAgIGZvcihpbnQgYiA9IDE7IGIgPD0gYTsgYisrKSB7CiAgICAgICAgICAgIHZlY3RvcjxpbnQ+IEF7YX0sIEJ7Yn07CiAgICAgICAgICAgIGF1dG8gQyA9IG11bHRpcGx5KG5vcm1hbGl6ZShBKSwgbm9ybWFsaXplKEIpKTsKICAgICAgICAgICAgd2hpbGUoQy5iYWNrKCkgPT0gMCkgewogICAgICAgICAgICAgICAgQy5wb3BfYmFjaygpOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGFzc2VydChDID09IG5vcm1hbGl6ZSh7YSAqIGJ9KSk7CiAgICAgICAgfQogICAgfQp9Cg==