#include #include #include #include using namespace std; using lint = long long; lint gcd(lint a, lint b) { return b ? gcd(b,a%b) : a; } namespace miller_rabin{ lint mul(lint x, lint y, lint mod){ return (__int128) x * y % mod; } lint ipow(lint x, lint y, lint p){ lint ret = 1, piv = x % p; while(y){ if(y&1) ret = mul(ret, piv, p); piv = mul(piv, piv, p); y >>= 1; } return ret; } bool miller_rabin(lint x, lint a){ if(x % a == 0) return 0; lint d = x - 1; while(1){ lint tmp = ipow(a, d, x); if(d&1) return (tmp != 1 && tmp != x-1); else if(tmp == x-1) return 0; d >>= 1; } } bool isprime(lint x){ for(auto &i : {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37}){ if(x == i) return 1; if(x > 40 && miller_rabin(x, i)) return 0; } if(x <= 40) return 0; return 1; } } set dup; bool chk[10]; int N,A[10]; long long ans = -1; void go(int a, long long v) { if (a < N){ for (int i=0;i