#include #include using namespace std; using namespace boost::multiprecision; #define fst(t) std::get<0>(t) #define snd(t) std::get<1>(t) #define thd(t) std::get<2>(t) #define unless(p) if(!(p)) #define until(p) while(!(p)) using ll = long long; using P = std::tuple; const int dx[8] = {-1, 1, 0, 0, -1, -1, 1, 1}, dy[8] = {0, 0, -1, 1, -1, 1, -1, 1}; int N; std::deque deq; template T expt(T a, T n, T mod){ T res = 1; while(n){ if(n & 1){res = (res * a) % mod;} a = a * a % mod; n >>= 1; } return res; } inline int f(int n){ if(n < 10){ return 10; } return 100; } bool isPrime(ll n){ if(n % 2 == 0){ return n == 2; } ll k = 0, q = n - 1; while(q % 2 == 0){ k += 1; q /= 2; } constexpr ll sets[] = {2, 325, 9375}; // , 28178 for(ll a : sets){ auto p = expt(a, q, n); if(p == 1){ continue; } bool ok = false; for(int i=0;i> N; for(int i=0;i> A; deq.emplace_back(A); } ll res = -1; for(int i=0;i