#include <iostream>
#include <array>
#include <cstdint>
using namespace std;
const int32_t N = 10;
static_assert(N > 3, "N should be greater than 3");
const int32_t c_limit = 3 * (1 << (N-2)) - 1;
using coef_t = array<int32_t, 9u>;
coef_t getCoef(int32_t n)
{
coef_t coef;
for (auto i = 0u; i < coef.max_size(); ++i)
{
coef[i] = n >> i;
}
return coef;
}
bool cond_1(const coef_t& a, const coef_t& b) { return (-1 + a[8]) == (-b[3] + b[2]); }
bool cond_2(const coef_t& a, const coef_t& b) { return ( a[8] - a[7]) == ( b[4] - b[3]); }
bool cond_3(const coef_t& a, const coef_t& b) { return (-a[7] + a[6]) == (-b[5] + b[4]); }
bool cond_4(const coef_t& a, const coef_t& b) { return ( a[6] - a[5]) == ( 1 - b[8]); }
bool cond_5(const coef_t& a, const coef_t& b) { return (-a[5] + a[4]) == ( 1 - b[0]); }
bool cond_6(const coef_t& a, const coef_t& b) { return ( a[4] - a[3]) == ( b[8] + b[7]); }
bool cond_7(const coef_t& a, const coef_t& b) { return (-a[3] + a[2]) == (-b[7] + b[6]); }
bool cond_8(const coef_t& a, const coef_t& b) { return ( a[2] - a[1]) == (-b[1] + b[0]); }
bool cond_9(const coef_t& a, const coef_t& b) { return (-a[1] + a[0]) == ( b[2] - b[1]); }
bool cond_10(const coef_t& a, const coef_t& b) { return (-a[0] + 1) == ( b[6] - b[5]); }
int main()
{
size_t count = 0;
for (int32_t u = 767; u <= c_limit; ++u)
{
const coef_t a = getCoef(u);
for (int32_t v = 767; v <= c_limit; ++v)
{
const coef_t b = getCoef(v);
if (cond_1(a, b) && cond_2(a, b) && cond_3(a, b) && cond_4(a, b) && cond_5(a, b) &&
cond_6(a, b) && cond_7(a, b) && cond_8(a, b) && cond_9(a, b) && cond_10(a, b))
{
cout << "(" << u << ", " << v << ")" << endl;
count++;
}
}
}
cout << count << " pairs" << endl;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8YXJyYXk+CiNpbmNsdWRlIDxjc3Rka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JiBiKSAgeyByZXR1cm4gKCBhWzRdIC0gYVszXSkgPT0gKCBiWzhdICsgYls3XSk7IH0KYm9vbCBjb25kXzcoY29uc3QgY29lZl90JiBhLCBjb25zdCBjb2VmX3QmIGIpICB7IHJldHVybiAoLWFbM10gKyBhWzJdKSA9PSAoLWJbN10gKyBiWzZdKTsgfQpib29sIGNvbmRfOChjb25zdCBjb2VmX3QmIGEsIGNvbnN0IGNvZWZfdCYgYikgIHsgcmV0dXJuICggYVsyXSAtIGFbMV0pID09ICgtYlsxXSArIGJbMF0pOyB9CmJvb2wgY29uZF85KGNvbnN0IGNvZWZfdCYgYSwgY29uc3QgY29lZl90JiBiKSAgeyByZXR1cm4gKC1hWzFdICsgYVswXSkgPT0gKCBiWzJdIC0gYlsxXSk7IH0KYm9vbCBjb25kXzEwKGNvbnN0IGNvZWZfdCYgYSwgY29uc3QgY29lZl90JiBiKSB7IHJldHVybiAoLWFbMF0gKyAxKSAgICA9PSAoIGJbNl0gLSBiWzVdKTsgfQoKaW50IG1haW4oKQp7CiAgIHNpemVfdCBjb3VudCA9IDA7CiAgIGZvciAoaW50MzJfdCB1ID0gNzY3OyB1IDw9IGNfbGltaXQ7ICsrdSkKICAgewogICAgICBjb25zdCBjb2VmX3QgYSA9IGdldENvZWYodSk7CiAgICAgIGZvciAoaW50MzJfdCB2ID0gNzY3OyB2IDw9IGNfbGltaXQ7ICsrdikKICAgICAgewogICAgICAgICBjb25zdCBjb2VmX3QgYiA9IGdldENvZWYodik7CgogICAgICAgICBpZiAoY29uZF8xKGEsIGIpICYmIGNvbmRfMihhLCBiKSAmJiBjb25kXzMoYSwgYikgJiYgY29uZF80KGEsIGIpICYmIGNvbmRfNShhLCBiKSAmJgogICAgICAgICAgICAgY29uZF82KGEsIGIpICYmIGNvbmRfNyhhLCBiKSAmJiBjb25kXzgoYSwgYikgJiYgY29uZF85KGEsIGIpICYmIGNvbmRfMTAoYSwgYikpCiAgICAgICAgIHsKICAgICAgICAgICAgY291dCA8PCAiKCIgPDwgdSA8PCAiLCAiIDw8IHYgPDwgIikiIDw8IGVuZGw7CiAgICAgICAgICAgIGNvdW50Kys7CiAgICAgICAgIH0KICAgICAgfQogICB9CgogICBjb3V0IDw8IGNvdW50IDw8ICIgcGFpcnMiIDw8IGVuZGw7CgogICByZXR1cm4gMDsKfQ==