#include <bits/stdc++.h>   using namespace std;   const int INF = 1001001001;   const long long INFL = 1001001001001001001LL;   template <typename T>   void pv(T a, T b) {     for (T i = a; i != b; ++i) cout << *i <<    ;     cout << endl;   }   template <class T>   bool uin(T &a, T b) {     return a > b ? (a = b, true) : false;   }   template <class T>   bool uax(T &a, T b) {     return a < b ? (a = b, true) : false;   }   int in() {     int x;     cin >> x;     return x;   }   double fin() {     double x;     cin >> x;     return x;   }   string sin() {     string x;     cin >> x;     return x;   }   char chin() {     char x;     cin >> x;     return x;   }   long long lin() {     long long x;     cin >> x;     return x;   }   struct card {     int a, b, c;   };   bool comp(card &a, card &b) { return a.a > b.a; }   int n, p, q, r;   long long sum[500011];   vector<pair<int, int> > bounds;   vector<card> cards;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.setf(ios::fixed);     cout.precision(20);     cin >> n >> p >> q >> r;     cards.resize(n);     for (int i = 0; i < (int)(n); ++i) {       cin >> cards[i].a >> cards[i].b >> cards[i].c;       bounds.push_back({cards[i].b, cards[i].c});     }     sort((cards).begin(), (cards).end(), comp);     sort((bounds).rbegin(), (bounds).rend());     int ind = -1;     for (int i = 0; i < bounds.size(); i++) {       if (ind == -1 || bounds[ind].second < bounds[i].second) {         bounds[++ind] = bounds[i];       }     }     bounds.resize(ind + 1);     bounds.push_back({0, r});     reverse((bounds).begin(), (bounds).end());     bounds.push_back({q, 0});     for (int i = 1; i < bounds.size(); i++) {       sum[i] = sum[i - 1] + (long long)(bounds[i - 1].second - bounds[i].second) *                                 (q - bounds[i - 1].first);     }     int bb = p;     int minb = 0, minc = 0;     int pbnd = 0, pcnd = bounds.size() - 1;     long long sol = 0;     cards.push_back({0, 0, 0});     for (int i = 0; i <= n; i++) {       if (bb > cards[i].a) {         while (pbnd < bounds.size() && bounds[pbnd].first < minb) pbnd++;         while (pcnd > 0 && bounds[pcnd].second < minc) pcnd--;         if (pbnd > pcnd) {           sol += (long long)(bb - cards[i].a) * (q - minb) * (r - minc);         } else {           sol += (long long)(bb - cards[i].a) *                  (sum[pcnd] - sum[pbnd] +                   (long long)(bounds[pcnd].second - minc) *                       (q - bounds[pcnd].first) +                   (long long)(q - minb) * (r - bounds[pbnd].second));         }         bb = cards[i].a;       }       uax(minb, cards[i].b);       uax(minc, cards[i].c);     }     cout << sol << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool bSearch(int* toys, int item, int from, int to) {     if (from > to)       return false;     else {       int midPoint = (from + to) / 2;       if (item < toys[midPoint])         return bSearch(toys, item, from, midPoint - 1);       else if (item == toys[midPoint])         return true;       else         return bSearch(toys, item, midPoint + 1, to);     }   }   int main() {     int n, m;     scanf( %d %d , &n, &m);     int toys[n];     for (int i = 0; i < n; i++) {       scanf( %d , &toys[i]);     }     sort(toys, toys + n);     long long int counter = 0;     vector<int> v;     for (int i = 1; i <= 1000000000 && i <= m && counter < m; i++) {       if (!bSearch(toys, i, 0, n - 1)) {         counter += i;         if (counter <= m) v.push_back(i);       }     }     printf( %d n , v.size());     for (int i = 0; i < v.size(); i++) {       printf( %d  , v[i]);     }     printf(  n );   }


#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-9;   int a, b, n, p;   int main() {     cin >> a >> b >> n;     for (int x = -1000; x < 1001; x++) {       p = 1;       for (int i = 0; i < n && p <= 1000; i++) p *= x;       if (a * p == b) {         cout << x;         return 0;       }     }     cout <<  No solution ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     for (int j1 = 0; j1 < t; j1++) {       long long int n;       cin >> n;       long long int arr[n];       long long int sum1 = 0;       long long int sum2 = 0;       for (int j = 0; j < (n / 2); j++) {         arr[j] = ((2 * j) + 2);         sum1 += arr[j];       }       long long int p = 1;       for (int k = n / 2; k < n - 1; k++) {         arr[k] = (2 * p - 1);         p++;         sum2 += (arr[k]);       }       arr[n - 1] = sum1 - sum2;       if (n % 4 == 0) {         cout <<  YES  << endl;         for (int m = 0; m < n; m++) {           cout << arr[m] <<    ;         }         cout << endl;       } else {         cout <<  NO  << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double pi = 2 * acos(0);   void _R(int &x) { scanf( %d , &x); }   void _R(int64_t &x) { scanf( %lld , &x); }   void _R(double &x) { scanf( %lf , &x); }   void _R(char &x) { scanf(  %c , &x); }   void _R(char *x) { scanf( %s , x); }   int main() {     long long x, n, s = 0, a, i;     cin >> n >> x;     for (i = 1; i <= n; i++) {       if (x % i == 0 && x / i <= n) {         s++;       }     }     cout << s;   }


#include <bits/stdc++.h>   using namespace std;   using LL = long long;   constexpr int N = 1e5 + 5;   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     int n, k, m;     cin >> n >> k >> m;     vector<int> in(k);     for (int &e : in) cin >> e;     sort(begin(in), end(in));     const int A = accumulate(begin(in), end(in), 0);     int ans = 0;     for (int i = 0; i <= n; i++) {       if (i * A > m) break;       int points = i * (k + 1);       int have = m - i * A;       int g = n - i;       for (int x : in) {         int t = min(g, have / x);         points += t;         have -= t * x;       }       ans = max(ans, points);     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   void splitstr(const string &s, vector<T> &out) {     istringstream in(s);     out.clear();     copy(istream_iterator<T>(in), istream_iterator<T>(), back_inserter(out));   }   static void redirect(int argc, const char **argv) {     ios::sync_with_stdio(false);     cin.tie(NULL);     if (argc > 1) {       static filebuf f;       f.open(argv[1], ios::in);       cin.rdbuf(&f);       if (!cin) {         cerr <<  Failed to open    << argv[1] <<     << endl;         exit(1);       }     }     if (argc > 2) {       static filebuf f;       f.open(argv[2], ios::out | ios::trunc);       cout.rdbuf(&f);       if (!cout) {         cerr <<  Failed to open    << argv[2] <<     << endl;       }     }   }   template <typename T>   static T gcd(T a, T b) {     return b ? gcd(b, a % b) : a;   }   template <typename T>   static T mod(T a, T m) {     a %= m;     if (a < 0) a += m;     return a;   }   template <typename T>   static T inverse(T a, T m) {     a = mod(a, m);     if (a <= 1) return a;     return mod((1 - inverse(m, a) * m) / a, m);   }   template <typename T, typename C, T Modulus>   class MR {    private:     struct tag_plus {};     struct tag_minus {};     struct tag_good {};     T value;     static_assert(std::numeric_limits<C>::max() / Modulus / Modulus > 0,                    compute type is too small );     static_assert(Modulus < std::numeric_limits<T>::max() / 2,                    storage type is too small );     void reduce(tag_plus) {       if (value >= Modulus) value -= Modulus;     }     void reduce(tag_minus) {       if (value < 0) value += Modulus;     }     void reduce(tag_good) {}       public:     static const T modulus = Modulus;     MR() : value(0) {}     MR(C value) : value(value % Modulus) { reduce(tag_minus()); }     template <typename tag_t>     MR(T value, tag_t tag) : value(value) {       reduce(tag);     }     MR &operator=(C value) {       this->value = value % Modulus;       reduce(tag_minus());       return *this;     }     MR operator+(MR b) const { return MR(value + b.value, tag_plus()); }     MR operator-(MR b) const { return MR(value - b.value, tag_minus()); }     MR operator*(MR b) const {       return MR(C(value) * C(b.value) % Modulus, tag_good());     }     MR operator-() const { return MR(-value, tag_minus()); }     MR &operator+=(MR b) {       value += b.value;       reduce(tag_plus());       return *this;     }     MR &operator-=(MR b) {       value -= b.value;       reduce(tag_minus());       return *this;     }     MR &operator*=(MR b) {       value = C(value) * C(b.value) % Modulus;       return *this;     }     bool operator==(MR b) const { return value == b.value; }     bool operator!=(MR b) const { return value != b.value; }     T get() const { return value; }     MR inverse() const {       assert(value);       return MR(::inverse(C(value), C(Modulus)), tag_good());     }     MR operator/(MR b) const { return *this * b.inverse(); }     MR &operator/=(MR b) { return *this *= b.inverse(); }   };   template <typename T, typename C, T Modulus>   static inline std::ostream &operator<<(std::ostream &o, MR<T, C, Modulus> mr) {     return o << mr.get();   }   int main(int argc, const char **argv) {     redirect(argc, argv);     int K, pas, pbs;     cin >> K >> pas >> pbs;     MR<int, long long, 1000000007> pa = MR<int, long long, 1000000007>(pas) /                                         MR<int, long long, 1000000007>(pas + pbs);     MR<int, long long, 1000000007> pb = MR<int, long long, 1000000007>(pbs) /                                         MR<int, long long, 1000000007>(pas + pbs);     vector<vector<MR<int, long long, 1000000007>>> state(         K + 1, vector<MR<int, long long, 1000000007>>(K + 1));     MR<int, long long, 1000000007> scale1 = pa / pb;     state[1][0] = 1;     MR<int, long long, 1000000007> ans;     for (int a = 1; a <= K; a++)       for (int s = 0; s <= K; s++) {         if (state[a][s] == 0) continue;         if (s + a >= K) {           MR<int, long long, 1000000007> t = s + a;           ans += (scale1 + t) * state[a][s];         } else {           state[a + 1][s] += pa * state[a][s];           state[a][s + a] += pb * state[a][s];         }       }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9 + 1000;   const long long INF64 = 1e18;   const int N = 1001000;   const int MOD = 1e9 + 7;   const double EPS = 1E-9;   long long gcd(long long a, long long b) { return a == 0 ? b : gcd(b % a, a); }   int add(int first, int second, int m) {     first += second;     while (first >= m) first -= m;     while (first < 0) first += m;     return first;   }   int sub(int first, int second, int m) { return add(first, -second, m); }   int mul(int first, int second, int m) { return (first * 1ll * second) % m; }   int binpow(int first, int second, int m) {     int z = 1;     while (second) {       if (second & 1) z = mul(z, first, m);       first = mul(first, first, m);       second >>= 1;     }     return z;   }   int divide(int first, int second, int m) {     return mul(first, binpow(second, m - 2, m), m);   }   const int K = 2;   mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());   bool is_prime(int first) {     for (int i = 2; i * 1ll * i <= first; i++)       if (first % i == 0) return false;     return true;   }   int gen_prime(int first, int offset) {     int z = first + (rnd() % offset);     while (!is_prime(z)) z++;     return z;   }   array<int, K> P = {10, 10};   array<int, K> M = {1000000007, 1000000009};   void precalc() {     for (int i = 0; i < K; i++) {       P[i] = gen_prime(100, 100);       M[i] = gen_prime(1000000000, 1000000);     }   }   array<int, K> add(array<int, K> first, array<int, K> second) {     array<int, K> res;     for (int i = 0; i < K; i++) res[i] = add(first[i], second[i], M[i]);     return res;   }   array<int, K> sub(array<int, K> first, array<int, K> second) {     array<int, K> res;     for (int i = 0; i < K; i++) res[i] = sub(first[i], second[i], M[i]);     return res;   }   array<int, K> mul(array<int, K> first, array<int, K> second) {     array<int, K> res;     for (int i = 0; i < K; i++) res[i] = mul(first[i], second[i], M[i]);     return res;   }   array<int, K> binpow(array<int, K> first, int second) {     array<int, K> res;     for (int i = 0; i < K; i++) res[i] = binpow(first[i], second, M[i]);     return res;   }   array<int, K> divide(array<int, K> first, array<int, K> second) {     array<int, K> z;     for (int i = 0; i < K; i++) z[i] = divide(first[i], second[i], M[i]);     return z;   }   int code(char c) { return (c -  0 ); }   array<int, K> make_hash(int first) {     array<int, K> res;     for (int i = 0; i < K; i++) res[i] = first;     return res;   }   vector<array<int, K> > get_prefix_hashes(const string& s) {     int n = s.size();     vector<array<int, K> > ans(n + 1);     array<int, K> curP = make_hash(1);     for (int i = 0; i < n; i++) {       ans[i + 1] = add(ans[i], mul(make_hash(code(s[i])), curP));       curP = mul(curP, P);     }     return ans;   }   array<int, K> DP[N], DQ[N];   array<int, K> substr_hash(const vector<array<int, K> >& p, int l, int r) {     return mul(sub(p[r], p[l]), DQ[l]);   }   array<int, K> concat(array<int, K> a, array<int, K> b, int len) {     return add(a, mul(b, DP[len]));   }   vector<array<int, K> > test;   void preprecalc() {     DP[0] = make_hash(1);     for (int i = 1; i < N; i++) DP[i] = mul(P, DP[i - 1]);     for (int i = 0; i < N; i++) DQ[i] = divide(make_hash(1), DP[i]);   }   int ans = INF;   string s;   void rec(int l, int r, char c, int cur) {     if (r - l == 1) {       cur += (s[l] != c);       ans = min(ans, cur);       return;     }     int m = (r + l) / 2;     int curl = 0, curr = 0;     for (int i = l; i < m; ++i) {       curl += (s[i] != c);       curr += (s[i + m - l] != c);     }     rec(l, m, c + 1, cur + curr);     rec(m, r, c + 1, cur + curl);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       set<int> have;       for (int i = 0; i < 2 * n; ++i) {         int first;         cin >> first;         if (!have.count(first)) {           cout << first <<    ;           have.insert(first);         }       }       cout <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const double EPS = 1e-9;   const int INF = 2147483647;   const long long LLINF = 9223372036854775807LL;   template <class T>   T gcd(T a, T b) {     if (a < b) swap(a, b);     if (b == 0) return a;     return gcd(b, a % b);   }   template <class T>   T lcm(T a, T b) {     return (a * b) / gcd(a, b);   }   int dp[510001];   int main() {     int d, n;     cin >> n >> d;     vector<int> c(n);     for (int i = 0; i < (n); i++) cin >> c[i];     for (int i = 0; i < (n); i++) {       for (int j = (510000); j >= (c[i]); j--) {         dp[j] = max(dp[j], c[i] + dp[j - c[i]]);       }     }     int ans = 0, lAns = -1, days = -1;     while (ans != lAns) {       lAns = ans;       ans = dp[ans + d];       days++;     }     if (ans == 0)       cout << 0 <<     << 0 << endl;     else       cout << ans <<     << days << endl;     return 0;   }


#include <bits/stdc++.h>   int n, m, k;   std::unordered_set<int> G[100123];   int deg[100123];   inline bool CheckClique(int x) {     std::vector<int> V({x});     for (int y : G[x]) V.emplace_back(y);     for (int u : V)       for (int v : V)         if (u < v && (!G[u].count(v))) return false;     return true;   }   inline void Solve() {     for (int i = 1; i <= n; ++i) G[i].clear();     memset(deg, 0, sizeof(deg));     scanf( %d%d%d , &n, &m, &k);     std::vector<std::pair<int, int>> input;     for (int i = 1, u, v; i <= m; ++i) {       scanf( %d%d , &u, &v);       input.emplace_back(std::make_pair(u, v));     }     if ((1LL * k * (k - 1) / 2) > m) return puts( -1 ), void();     for (auto& p : input) {       G[p.first].insert(p.second);       G[p.second].insert(p.first);       ++deg[p.first];       ++deg[p.second];     }     int cnt = 0;     std::queue<int> q;     for (int i = 1; i <= n; ++i)       if (deg[i] < k) {         if (deg[i] == k - 1 && CheckClique(i)) {           puts( 2 );           for (int x : G[i]) printf( %d  , x);           printf( %d n , i);           return;         }         q.push(i);         ++cnt;       }     while (!q.empty()) {       int u = q.front();       q.pop();       for (int v : G[u]) {         G[v].erase(u);         if ((--deg[v]) == k - 1) {           if (CheckClique(v)) {             puts( 2 );             for (int x : G[v]) printf( %d  , x);             printf( %d n , v);             return;           }           q.push(v);           ++cnt;         }       }     }     if (cnt < n) {       std::vector<int> ans;       for (int i = 1; i <= n; ++i)         if (deg[i] >= k) ans.emplace_back(i);       printf( 1 n%d n , static_cast<int>(ans.size()));       for (int i : ans) printf( %d  , i);       puts(  );     } else       puts( -1 );   }   int main() {     int T;     scanf( %d , &T);     while (T--) Solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int long long n, c = 0;     cin >> n;     for (int long long i = 1; i < n; i++) {       if (n % i == 0) {         c++;       }     }     cout << (c);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 105;   long long f[MAXN][MAXN][MAXN];   int a[MAXN];   string s;   int n;   long long solve(int l, int r, int pf) {     if (l >= r) return 0;     if (r - l == 1) return a[pf];     long long &cur = f[l][r][pf];     if (cur > 0) return cur;     cur = max(cur, solve(l + 1, r, 1) + a[pf]);     for (int i = l + 1; i < r; i++)       if (s[l] == s[i]) cur = max(cur, solve(l + 1, i, 1) + solve(i, r, pf + 1));     return cur;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> n >> s;     for (int i = 1; i <= n; i++) cin >> a[i];     cout << solve(0, n, 1) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int absi(int a) { return (a > 0) ? a : -a; }   const int md = 51123987;   inline void add(int &a, int b) {     a += b;     if (a >= md) a -= md;   }   int a[155];   int tmp[4];   int nxt[155][4];   int dp[155][55][55][55];   int main(void) {     int n, mx;     scanf( %d , &n);     mx = (n + 2) / 3;     char c = getchar();     while (c == 10 || c == 32) c = getchar();     for (int i = 1; i <= n; ++i) {       a[i] = c -  a  + 1;       c = getchar();     }     memset(tmp, 255, sizeof(tmp));     for (int i = n; i; --i) {       tmp[a[i]] = i;       memcpy(nxt[i], tmp, sizeof(tmp));     }     int res = 0;     dp[1][0][0][0] = 1;     for (int i = 1; i <= n; ++i) {       for (int j = 0; j <= mx; ++j) {         for (int k = 0; k <= mx; ++k) {           for (int l = 0; l <= mx; ++l) {             if (j + k + l > n) break;             int val = dp[i][j][k][l];             if (j + k + l == n) {               if (absi(j - k) <= 1 && absi(j - l) <= 1 && absi(k - l) <= 1) {                 add(res, val);               }               continue;             }             if (~nxt[i][1]) {               add(dp[nxt[i][1]][j + 1][k][l], val);             }             if (~nxt[i][2]) {               add(dp[nxt[i][2]][j][k + 1][l], val);             }             if (~nxt[i][3]) {               add(dp[nxt[i][3]][j][k][l + 1], val);             }           }         }       }     }     printf( %d n , res);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int T[5000000], sl[5000000], sr[5000000], a[200005], rt[200005], la[200005],       pos[200005];   int i, j, n, num, tmp, ans;   void build(int l, int r, int &node) {     node = ++num;     if (l == r) return;     int mid = (l + r) >> 1;     build(l, mid, sl[node]);     build(mid + 1, r, sr[node]);   }   void Insert(int l, int r, int x, int y, int node) {     int k = ++num;     if (l == r) {       T[k] = T[node] + y;       return;     }     int mid = (l + r) >> 1;     if (x <= mid) {       sl[k] = num + 1, sr[k] = sr[node];       Insert(l, mid, x, y, sl[node]);     } else {       sl[k] = sl[node], sr[k] = num + 1;       Insert(mid + 1, r, x, y, sr[node]);     }     T[k] = T[sl[k]] + T[sr[k]];   }   int ask(int l, int r, int k, int node) {     if (l == r) return l;     int mid = (l + r) >> 1, now = T[sl[node]];     if (now >= k) return ask(l, mid, k, sl[node]);     return ask(mid + 1, r, k - now, sr[node]);   }   int main() {     scanf( %d , &n);     for (i = 1; i <= n; i++) scanf( %d , &a[i]);     build(1, n + 1, rt[0]);     rt[1] = num + 1, Insert(1, n + 1, n + 1, 1, rt[0]);     tmp = 1;     for (i = n; i; i--) {       if (pos[a[i]])         rt[tmp + 1] = num + 1, Insert(1, n + 1, pos[a[i]], -1, rt[tmp++]);       rt[tmp + 1] = num + 1, Insert(1, n + 1, i, 1, rt[tmp++]);       la[i] = tmp;       pos[a[i]] = i;     }     for (i = 1; i <= n; i++) {       ans = 0;       j = 1;       while ((j = ask(1, n + 1, i + 1, rt[la[j]])) <= n) ans++;       printf( %d  , ans + 1);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int getint() {     unsigned int c;     int x = 0;     while (((c = getchar()) -  0 ) >= 10) {       if (c ==  - ) return -getint();       if (!~c) exit(0);     }     do {       x = (x << 3) + (x << 1) + (c -  0 );     } while (((c = getchar()) -  0 ) < 10);     return x;   }   long long MOD = 1000000007;   const int MAXN = 100011;   struct modint {     long long v;     modint() : v(0) {}     modint(int v) : v(v > MOD ? v - MOD : v) {}     modint(long long v) : v(v % MOD) {}     void null() { v = -1; }     bool is_null() { return v == -1; }   };   const modint mod = MOD;   modint& operator+=(modint& x, modint y) { return x = x.v + y.v; }   modint& operator-=(modint& x, modint y) { return x = x.v - y.v + MOD; }   modint& operator*=(modint& x, modint y) { return x = (long long)x.v * y.v; }   modint operator+(modint x, modint y) { return x += y; }   modint operator-(modint x, modint y) { return x -= y; }   modint operator*(modint x, modint y) { return x *= y; }   modint operator-(modint x) { return x = modint(0) - x; }   modint minv[MAXN], mfct[MAXN], mifc[MAXN];   modint mod_inv(const modint& a) {     if (a.v < MAXN and minv[a.v].v) return minv[a.v];     if (a.v == 1) return minv[a.v] = 1;     modint res = modint(MOD) - modint(MOD / a.v) * mod_inv(MOD % a.v);     if (a.v < MAXN) minv[a.v] = res;     return res;   }   modint& operator/=(modint& x, modint y) { return x *= mod_inv(y); }   modint operator/(modint x, modint y) { return x /= y; }   modint mod_pow(modint x, long long n) {     modint res = 1;     for (; n; x *= x, n >>= 1)       if (n & 1) res *= x;     return res;   }   modint mod_fact(int n) {     if (mfct[n].v) return mfct[n];     mfct[0] = 1;     for (long long i = 1; i < MAXN; i++) mfct[i] = mfct[i - 1] * i;     return mfct[n];   }   modint mod_ifact(int n) {     return mifc[n].v ? mifc[n] : mifc[n] = mod_inv(mod_fact(n));   }   modint mod_cmb(int n, int k) {     if (k < 0 or n < k) return 0;     return mod_fact(n) * mod_ifact(k) * mod_ifact(n - k);   }   ostream& operator<<(ostream& os, modint a) {     os << a.v;     return os;   }   const int N = 1000111000;   vector<int> am;   void make_lucky(long long n) {     if (n > N) return;     if (n) am.push_back(n);     make_lucky(n * 10 + 7), make_lucky(n * 10 + 4);   }   map<int, int> mp;   int cnt[1111], other, k, nn;   long long dp[100111];   int main() {     int i, j, tcc, tc = 1 << 28;     make_lucky(0);     nn = am.size();     for (i = 0; i < am.size(); i++) mp[am[i]] = i;     for (tcc = 0; tcc < tc; tcc++) {       memset(cnt, 0, sizeof(cnt));       other = 0;       int n = getint();       k = getint();       for (i = 0; i < n; i++) {         int t = getint();         if (mp.count(t))           cnt[mp[t]]++;         else           other++;       }       for (i = 0; i <= k; i++) dp[i] = 0;       dp[0] = 1;       for (i = 0; i < nn; i++)         if (cnt[i]) {           for (j = k - 1; ~j; j--) dp[j + 1] += dp[j] * cnt[i];           for (j = 0; j <= k; j++) dp[j] %= MOD;         }       modint res = 0;       for (i = 0; i <= k; i++) {         res += dp[i] * mod_cmb(other, k - i);       }       printf( %d n , (int)res.v);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline void read(T &x) {     char c;     bool nega = 0;     while ((!isdigit(c = getchar())) && c !=  - )       ;     if (c ==  - ) {       c = getchar();       nega = 1;     }     x = c - 48;     while (isdigit(c = getchar())) x = x * 10 + c - 48;     if (nega) x = -x;   }   inline void update(int64_t &A, int64_t B) {     if (A > B) A = B;   }   int64_t dp[2][500][500][2];   vector<pair<int, int>> robot[500][500];   bool good[500000][4];   int d[500000], e[500000];   signed main() {     int n, m, k;     read(n);     read(m);     read(k);     vector<int> dx = {0, 1, 1, 0}, dy = {0, -1, 0, 1};     int cap = max(m, n);     for (int i = 0; i < k; i++) {       int x, y, t;       read(x);       read(y);       read(d[i]);       read(t);       read(e[i]);       for (int zi = 0; zi < 4; zi++) {         int nx = x + dx[zi] * d[i], ny = y + dy[zi] * d[i];         if (zi + t <= nx + ny && (zi + t) % 4 == (nx + ny) % 4) {           robot[nx][ny].push_back({i, zi});           good[i][zi] = 1;         }       }     }     for (int X = 0; X < 2; X++)       for (int Y = 0; Y < m; Y++)         for (int W = 0; W < cap; W++)           for (int vert = 0; vert < 2; vert++) dp[X][Y][W][vert] = LLONG_MAX;     dp[0][0][0][0] = dp[0][0][0][1] = 0;     int64_t ans = LLONG_MAX;     for (int X = 0; X < n; X++) {       int cur = X & 1;       int nxt = 1 - cur;       for (int Y = 0; Y < m; Y++) {         for (int W = 0; W < cap; W++) {           for (int vert = 0; vert < 2; vert++) {             if (W > (vert ? X : Y) || dp[cur][Y][W][vert] == LLONG_MAX) break;             if (Y < m - 1) {               int right = (vert ? 0 : W) + 1;               int64_t smash = 0;               for (auto &[id, zi] : robot[X][Y + 1]) {                 if (zi == 2 && right >= d[id] && good[id][1]) continue;                 if (zi == 3 && right >= d[id] && good[id][0]) continue;                 smash += e[id];               }               update(dp[cur][Y + 1][right][0], dp[cur][Y][W][vert] + smash);               update(dp[cur][Y + 1][0][1], dp[cur][Y][W][vert] + smash);             }             if (X < n - 1) {               int down = (vert ? W : 0) + 1;               int64_t smash = 0;               for (auto &[id, zi] : robot[X + 1][Y]) {                 if (zi == 2 && down >= d[id] && good[id][0]) continue;                 smash += e[id];               }               update(dp[nxt][Y][down][1], dp[cur][Y][W][vert] + smash);               update(dp[nxt][Y][0][0], dp[cur][Y][W][vert] + smash);             }           }         }       }       if (X == n - 1) {         for (int W = 0; W < cap; W++)           for (int vert = 0; vert < 2; vert++)             update(ans, dp[cur][m - 1][W][vert]);         break;       }       for (int Y = 0; Y < m; Y++)         for (int W = 0; W < cap; W++)           for (int vert = 0; vert < 2; vert++) dp[cur][Y][W][vert] = LLONG_MAX;     }     printf( %lld , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int x1, x2, y1, y2, xmin, xmax, ymin, ymax;     cin >> x1 >> y1 >> x2 >> y2;     xmin = x1;     xmax = x2;     ymin = y1;     ymax = y2;     int total = (x2 - x1) * (y2 - y1);     for (int a = 1; a < n; ++a) {       cin >> x1 >> y1 >> x2 >> y2;       xmin = min(x1, xmin);       xmax = max(x2, xmax);       ymin = min(y1, ymin);       ymax = max(y2, ymax);       total += (x2 - x1) * (y2 - y1);     }     if (ymax - ymin == xmax - xmin and (xmax - xmin) * (xmax - xmin) == total)       cout <<  YES  << endl;     else       cout <<  NO  << endl;     cin >> n;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k, x1, x2, s = 0, x, y1 = 0, y2 = 0, sm = 0;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> x;       for (int i = 0; i < x; i++) cout << 7 <<    ;       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   vector<int> a[100010];   int x;   int now;   void print() {     cout <<  YES  << endl;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) cout << a[i][j] <<    ;       cout << endl;     }   }   int main() {     cin >> n >> m;     now = 1;     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) {         a[i].push_back(now);         now += 1;       }     if (n == 1 && m == 1) {       cout <<  YES  << endl;       cout << 1;       return 0;     }     if (n * m == 2) {       cout <<  NO ;       return 0;     }     if (n * m == 3) {       cout <<  NO ;       return 0;     }     if (n == 2 && m == 2) {       cout <<  NO ;       return 0;     }     if (n * m == 6 && min(n, m) == 2) {       cout <<  NO ;       return 0;     }     if (n == 3 && m == 3) {       cout <<  YES  << endl;       cout <<  6 1 8  << endl;       cout <<  7 5 3  << endl;       cout <<  2 9 4  << endl;       return 0;     }     if (n == 1 && m >= 4) {       now = 0;       for (int i = 2; i <= m; i += 2) {         a[0][now] = i;         now += 1;       }       for (int i = 1; i <= m; i += 2) {         a[0][now] = i;         now += 1;       }       print();       return 0;     }     if (m == 1 && n >= 4) {       now = 0;       for (int i = 2; i <= n; i += 2) {         a[now][0] = i;         now += 1;       }       for (int i = 1; i <= n; i += 2) {         a[now][0] = i;         now += 1;       }       print();       return 0;     }     if (m >= 4) {       for (int i = 0; i < n; i++)         if (i % 2 == 0) {           int tmp0 = a[i][m - 2];           int tmp1 = a[i][m - 1];           for (int j = m - 1; j >= 2; j--) a[i][j] = a[i][j - 2];           a[i][1] = tmp1;           a[i][0] = tmp0;         }       for (int i = 0; i < m; i++)         if (i % 2 == 0) {           int tmp0 = a[0][i];           for (int j = 0; j < n - 1; j++) a[j][i] = a[j + 1][i];           a[n - 1][i] = tmp0;         }       print();       return 0;     }     if (n >= 4) {       for (int i = 0; i < m; i++)         if (i % 2 == 0) {           int tmp0 = a[n - 2][i];           int tmp1 = a[n - 1][i];           for (int j = n - 1; j >= 2; j--) a[j][i] = a[j - 2][i];           a[1][i] = tmp1;           a[0][i] = tmp0;         }       for (int i = 0; i < n; i++)         if (i % 2 == 0) {           int tmp0 = a[i][0];           for (int j = 0; j < m - 1; j++) a[i][j] = a[i][j + 1];           a[i][m - 1] = tmp0;         }       print();       return 0;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n = 0, d = 0, count = 0, maxCount = 0;     cin >> n >> d;     string s =   ;     for (int i = 0; i < d; i++) {       cin >> s;       int res = 1;       for (int j = 0; j < s.size(); j++) {         res &= (s[j] -  0 );       }       if (res == 1) {         maxCount = max(count, maxCount);         count = 0;       } else {         count++;       }     }     maxCount = max(count, maxCount);     cout << maxCount;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int read() {     int x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = (x << 3) + (x << 1) + (ch ^ 48);       ch = getchar();     }     return x * f;   }   int n, m, k, cnt, a[200005], Of, Os;   char ch[200005];   int abs(int x, int y) {     if (x > y)       return x - y;     else       return y - x;   }   int main() {     n = read();     m = read();     k = read();     ;     for (int i = 1; i <= n; i++) {       scanf( %s , (ch + 1));       int f = 0, s = 0, ff = 0, ss = 0;       for (int j = 1; j <= m; j++) {         if (ch[j] ==  G ) f = j, ff++;         if (ch[j] ==  R ) s = j, ss++;       }       if (f == 0 && s != 0 && ss != m) Os = 1;       if (f != 0 && s == 0 && ff != m) Of = 1;       if (f && s) a[++cnt] = abs(s - f) - 1;     }     if (Os == 1 && Of == 1)       puts( Draw );     else if (Os == 1 && Of == 0)       puts( Second );     else if (Of == 1 && Os == 0)       puts( First );     else {       for (int i = 0; i <= 8; i++) {         int ff = 0;         for (int j = 1; j <= cnt; j++) ff += ((a[j] >> i) & 1);         if (ff % (k + 1)) {           puts( First );           return 0;         }       }       puts( Second );     }   }


#include <bits/stdc++.h>   using namespace std;   vector<int> zp;   int zer;   int one;   int n;   int allz;   int q() {     cout <<  ?  <<    ;     for (int i = 0; i < n; i++) {       cout << zp[i];     }     cout << endl;     int x;     cin >> x;     return x;   }   void get(int bg, int ed, int W) {     if ((zer != -1) and (one != -1)) {       return;     }     int cur = W;     int L = ed - bg;     int d = cur - allz;     if (d == -L) {       one = bg;       return;     }     if (d == L) {       zer = bg;       return;     }     int mid = (bg + ed) / 2;     for (int i = mid; i < ed; i++) {       zp[i] = 0;     }     int D = q();     get(bg, mid, D);     for (int i = mid; i < ed; i++) {       zp[i] = 1;     }     if ((zer != -1) and (one != -1)) {       return;     }     for (int i = bg; i < mid; i++) {       zp[i] = 0;     }     get(mid, ed, W - D + allz);     for (int i = bg; i < mid; i++) {       zp[i] = 1;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n;     zp.resize(n);     zer = -1;     one = -1;     allz = q();     for (int i = 0; i < n; i++) {       zp[i] = 1;     }     get(0, n, n - allz);     cout <<  !   << zer + 1 <<     << one + 1 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   #pragma warning(disable : 4996)   #pragma comment(linker,  /STACK:20000007 )   #pragma GCC optimize( unroll-loops )   const int N = (int)1e6 + 100;   const int maxn = (int)1e3 + 100;   const int base = (int)1e9;   const int mod = (int)1e9 + 7;   const int inf = INT_MAX;   const long long ll_inf = LLONG_MAX;   const long double PI = acos((long double)-1.0);   const long double eps = 1e-8;   int n, m, k;   char ch[1003][1003];   bool mark[1003][1003];   int d[1003][1003];   int x, y, x1, y2;   vector<int> dx = {1, 0, -1, 0};   vector<int> dy = {0, -1, 0, 1};   void bfs(int x, int y) {     d[x][y] = 1;     queue<pair<int, int> > Q;     Q.push(make_pair(x, y));     while (!Q.empty()) {       auto P = Q.front();       Q.pop();       int x, y;       tie(x, y) = P;       mark[x][y] = true;       if (x == x1 && y == y2) return;       for (int i = 0; i < 4; ++i) {         for (int j = 1; j <= k; ++j) {           int r = x, c = y;           r += dx[i] * j;           c += dy[i] * j;           if (r < 1 || c < 1 || c > m || r > n ||               (ch[r][c] ==  #  || (d[r][c] && d[r][c] <= d[x][y])))             break;           if (d[r][c] > d[x][y] + 1) {             d[r][c] = min(d[r][c], d[x][y] + 1);             Q.push({r, c});           } else if (!d[r][c]) {             d[r][c] = d[x][y] + 1;             Q.push({r, c});           }         }       }     }   }   void solve() {     cin >> n >> m >> k;     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= m; ++j) {         cin >> ch[i][j];       }     }     cin >> x >> y >> x1 >> y2;     bfs(x, y);     cout << --d[x1][y2] <<   n ;   }   int main() {     int T = 1;     for (; T; --T) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<long long> res;   long long n, a, b;   void solve(long long x, long long y) {     long long i, k;     for (i = 1, k = 0; k < x; i += a, k++) {       for (long long j = i + 1; j < i + a; j++) res.push_back(j);       res.push_back(i);     }     for (k = 0; k < y; i += b, k++) {       for (long long j = i + 1; j < i + b; j++) res.push_back(j);       res.push_back(i);     }   }   int main() {     cout.sync_with_stdio(false);     cin.tie(NULL);     cin >> n >> a >> b;     for (long long i = 0; i <= n; i++)       if (a * i <= n and (n - a * i) % b == 0) {         solve(i, (n - a * i) / b);         for (long long val : res) cout << val <<    ;         cout << endl;         return 0;       }     cout << -1 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int T;     cin >> T;     while (T-- > 0) {       int N;       cin >> N;       struct MM {         int min, max;       };       MM data[129];       for (int i = 0; i <= 128; ++i) {         if (i >= 63 && i < 63 + N)           data[i] = {i - 62, i - 62};         else           data[i] = {0, 0};       }       for (int i = 62; i >= 0; --i) {         MM& fi = data[2 * i + 1];         MM& se = data[2 * i + 2];         if (se.min == 0) {           data[i] = fi;         } else {           string res;           if (fi.min == fi.max && se.min == se.max) {             cout <<  ?   << fi.min <<     << se.min << endl;             cout.flush();             cin >> res;             if (res ==  < )               data[i] = {fi.min, se.max};             else               data[i] = {se.min, fi.max};           } else {             cout <<  ?   << fi.min <<     << se.min << endl;             cout.flush();             cin >> res;             if (res ==  < )               data[i].min = fi.min;             else               data[i].min = se.min;             cout <<  ?   << fi.max <<     << se.max << endl;             cout.flush();             cin >> res;             if (res ==  > )               data[i].max = fi.max;             else               data[i].max = se.max;           }         }       }       cout <<  !   << data[0].min <<     << data[0].max << endl;       cout.flush();     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, a, b;     scanf( %d , &n);     ;     if (n == 1) {       scanf( %d , &a);       scanf( %d , &b);       printf( %d %d n , a, b);       return 0;     }     multimap<int, int> l;     multimap<int, int>::iterator p, it;     set<int> s;     for (int i = 0; i < (n); i++) {       scanf( %d , &a);       ;       scanf( %d , &b);       ;       l.insert(make_pair(a, b));       l.insert(make_pair(b, a));       if (s.count(a))         s.erase(a);       else         s.insert(a);       if (s.count(b))         s.erase(b);       else         s.insert(b);     }     a = *s.begin();     b = *s.rbegin();     printf( %d  , a);     p = l.find(a);     while (true) {       printf( %d  , p->second);       it = l.find(p->second);       if (it->second == p->first) {         l.erase(it);         it = l.find(p->second);       }       p = it;       if (it->second == b) break;     }     printf( %d n , b);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int ToInt(string& s, int len) {     int r = 0;     for (int i = 0, max_ = (len); i < max_; ++i) {       r *= 10;       r += s[i] -  0 ;     }     return r;   }   int GCD(int a, int b) { return b != 0 ? GCD(b, a % b) : a; }   int LCM(int a, int b) { return a * (b / GCD(a, b)); }   long long Pow(long long n, long long e) {     if (e == 0) return 1;     if (e == 1)       return n;     else if (e & 1) {       long long t = Pow(n, e / 2);       return n * t * t;     } else {       long long t = Pow(n, e / 2);       return t * t;     }   }   pair<int, char> v[26];   bool toRem[26];   int main() {     string s;     getline(cin, s);     int K;     scanf( %d , &K);     for (int i = 0, max_ = (26); i < max_; ++i) v[i].second =  a  + i;     for (int i = 0, max_ = ((int)(s).size()); i < max_; ++i)       ++v[s[i] -  a ].first;     sort(v, v + 26);     int j = 0, rem = 26;     while (j < 26) {       if (K < v[j].first) break;       toRem[v[j].second -  a ] = true;       K -= v[j].first;       --rem;       ++j;     }     printf( %d n , rem);     for (int i = 0, max_ = ((int)(s).size()); i < max_; ++i)       if (!toRem[s[i] -  a ]) printf( %c , s[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long a = 0, b = 0, f = 0, t = 0, x[101010], s2 = 0, s3 = 0, i = 0, j = 0,             p = 0, k = 0;   string d1, d2, d3;   int main() {     cin >> a >> p;     for (b = 1; b <= a; b++) {       cin >> f;       if (f > p)         s2 += 2;       else         s2 += 1;     }     cout << s2;   }


#include <bits/stdc++.h>   using namespace std;      #define fr(i, a, b) for(int i = a; i < b; ++i)   #define rf(i, a, b) for(int i = a - 1; i >= b; --i)   #define len(v) size(v)   #define all(v) begin(v), end(v)   #define int long long   #define ff first   #define ss second   #define ii pair<int, int>   #define vi vector<int>   #define vv vector<vi>   #define pb push_back   #define ub upper_bound   #define lb lower_bound   #define ts to_string      template<typename A, typename B> A amax(A &a, B b) {a = max(a, b); return a;}   template<typename A, typename B> A amin(A &a, B b) {a = min(a, b); return a;}   template<typename A, typename B> string ts(pair<A, B> p);   string ts(const string& s) {return     + s +    ;}   string ts(const char* s) {return ts((string)s);}   template<typename A> string ts(A v) {       bool first = true;       string res =  { ;       for(const auto &x : v) {           if(!first) res +=  ,  ;           first = false, res += ts(x);       }       res +=  } ;       return res;   }   template<typename A, typename B> string ts(pair<A, B> p) {       return  (  + ts(p.ff) +  ,   + ts(p.ss) +  ) ;   }   void debug_out() {cerr <<   n ;}   template<typename H, typename... T> void debug_out(H h, T... t) {       cerr <<     << ts(h);       debug_out(t...);   }      #ifdef LOCAL   #define dbg(...) cerr <<  [  << #__VA_ARGS__ <<  ]: , debug_out(__VA_ARGS__)   #else   #define dbg(...)    #endif      const int INF = 0x3f3f3f3f3f3f3f3fll;   const int MOD = 1e9 + 7;    const int N   = 1e6 + 5;      void solve() {         int n;       cin >> n;       vector<pair<int, int>> a(n);       fr(i, 0, n) {           cin >> a[i].ff;           a[i].ss = i + 1;       }       sort(all(a));          int ans = 0;       fr(i, 0, n) {           int n1 = a[i].ff, i1 = a[i].ss;           fr(j, i + 1, n) {               int n2 = a[j].ff, j1 = a[j].ss;               if(n1 * n2 > 2 * n) break;               if(n1 * n2 == i1 + j1) {                   ans++;               }           }       }          cout << ans <<   n ;      }      int32_t main() {       ios_base::sync_with_stdio(false);        cin.tie(nullptr);          int t = 0;       if(!t) cin >> t;       while(t--) solve();   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int q;     cin >> q;     while (q--) {       long long x[3];       cin >> x[0] >> x[1] >> x[2];       sort(x, x + 3);       x[2] -= x[1] - x[0];       cout << x[1] + x[2] / 2 << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int a[501][501], b[501][501], i, j, n, m, k;   int main() {     vector<int> vea;     vector<int> veb;     cin >> n >> m;     for (i = 1; i <= n; i++) {       for (j = 1; j <= m; j++) cin >> a[i][j];     }     for (i = 1; i <= n; i++) {       for (j = 1; j <= m; j++) cin >> b[i][j];     }     for (i = 1; i <= n; i++) {       j = 1;       k = i;       while (true) {         vea.push_back(a[k][j]);         veb.push_back(b[k][j]);         k--;         j++;         if (k == 0 || j == m + 1) break;       }       sort(vea.begin(), vea.end());       sort(veb.begin(), veb.end());       for (j = 0; j < vea.size(); j++) {         if (vea[j] != veb[j]) {           cout <<  NO ;           return 0;         }       }       while (!vea.empty()) vea.pop_back();       while (!veb.empty()) veb.pop_back();     }     for (i = 1; i <= n; i++) {       j = m;       k = i;       while (true) {         vea.push_back(a[k][j]);         veb.push_back(b[k][j]);         k++;         j--;         if (k == n + 1 || j == 0) break;       }       sort(vea.begin(), vea.end());       sort(veb.begin(), veb.end());       for (j = 0; j < vea.size(); j++) {         if (vea[j] != veb[j]) {           cout <<  NO ;           return 0;         }       }       while (!vea.empty()) vea.pop_back();       while (!veb.empty()) veb.pop_back();     }     for (j = 1; j <= m; j++) {       i = 1;       k = j;       while (true) {         vea.push_back(a[i][k]);         veb.push_back(b[i][k]);         k--;         i++;         if (k == 0 || i == n + 1) break;       }       sort(vea.begin(), vea.end());       sort(veb.begin(), veb.end());       for (i = 0; i < vea.size(); i++) {         if (vea[i] != veb[i]) {           cout <<  NO ;           return 0;         }       }       while (!vea.empty()) vea.pop_back();       while (!veb.empty()) veb.pop_back();     }     for (j = m; j >= 1; j--) {       i = n;       k = j;       while (true) {         vea.push_back(a[i][k]);         veb.push_back(b[i][k]);         k++;         i--;         if (k == m + 1 || i == 0) break;       }       sort(vea.begin(), vea.end());       sort(veb.begin(), veb.end());       for (i = 0; i < vea.size(); i++) {         if (vea[i] != veb[i]) {           cout <<  NO ;           return 0;         }       }       while (!vea.empty()) vea.pop_back();       while (!veb.empty()) veb.pop_back();     }     cout <<  YES ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, i;     cin >> n;     long long int a[n];     for (i = 0; i < n; i = i + 1) {       cin >> a[i];     }     long long int mn = a[n - 1];     long long int m[n];     for (i = n - 1; i >= 0; i--) {       mn = min(mn, a[i]);       m[i] = mn;     }     for (i = 0; i < n; i = i + 1) {       long long int low = i;       long long int high = n - 1;       long long int res = i;       while (low <= high) {         long long int mid = (low + high) / 2;         if (m[mid] >= a[i]) {           high = mid - 1;         } else if (m[mid] < a[i]) {           low = mid + 1;           res = max(res, mid);         }       }       cout << res - i - 1 <<    ;     }     cout << endl;   }


#include <bits/stdc++.h>   using namespace std;   long long n;   bool use[100000 + 10], b[100000 + 10];   int a[100000 + 10], Now;   int Ans;   int L[100000 + 10], R[100000 + 10], CNT = 0;   int main() {     int Cnt = 0;     scanf( %I64d , &n);     for (long long i = 3; i <= n; i += 2) {       if (b[i]) continue;       Now = 1;       a[1] = i;       for (long long j = 2 * i; j <= n; j += i) {         b[j] = false;         if (use[j]) continue;         a[++Now] = j;       }       if (Now == 1) continue;       if (Now % 2 == 0) {         for (int i = 1; i + 1 <= Now; i += 2) {           Ans++;           L[Ans] = a[i];           use[a[i]] = true;           R[Ans] = a[i + 1];           use[a[i + 1]] = true;         }       } else {         Ans++;         L[Ans] = a[1];         use[a[1]] = true;         R[Ans] = a[3];         use[a[3]] = true;         for (int i = 4; i + 1 <= Now; i += 2) {           Ans++;           L[Ans] = a[i];           use[a[i]] = true;           R[Ans] = a[i + 1];           use[a[i + 1]] = true;         }       }     }     Now = 0;     for (long long j = 2; j <= n; j += 2) {       b[j] = false;       if (use[j]) continue;       a[++Now] = j;     }     if (Now % 2 == 0) {       for (int i = 1; i + 1 <= Now; i += 2) {         Ans++;         L[Ans] = a[i];         use[a[i]] = true;         R[Ans] = a[i + 1];         use[a[i + 1]] = true;       }     } else {       if (Now != 1) {         Ans++;         L[Ans] = a[1];         use[a[1]] = true;         R[Ans] = a[3];         use[a[3]] = true;         for (int i = 4; i + 1 <= Now; i += 2) {           Ans++;           L[Ans] = a[i];           use[a[i]] = true;           R[Ans] = a[i + 1];           use[a[i + 1]] = true;         }       }     }     printf( %d n , Ans);     for (int i = 1; i <= Ans; i++) printf( %d %d n , L[i], R[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long n;     cin >> n;     long long a[n];     for (int i = 0; i < n; ++i) {       a[i] = i + 1;     }     long long ans = 0;     long long i = 1, j = 1, k = 2;     for (int q = 0; q < n - 2; ++q) {       ans += i * a[j] * a[k];       j = (j + 1) % (n);       k = (k + 1) % (n);     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1005;   int n, q, len[N];   char name[N][20], ip[N][20];   bool dy(char ip1[], char ip2[], int len) {     for (int i = 0; i < len; i++)       if (ip1[i] != ip2[i]) return 0;     return 1;   }   int main() {     scanf( %d%d , &n, &q);     for (int i = 1; i <= n; i++)       scanf( %s%s , name[i], ip[i]), len[i] = strlen(ip[i]);     while (q--) {       char na[20], IP[20];       scanf( %s%s , na, IP);       int L = strlen(IP) - 1;       IP[L] =   0 ;       for (int i = 1; i <= n; i++)         if (len[i] == L && dy(IP, ip[i], L)) {           printf( %s %s; #%s n , na, IP, name[i]);           break;         }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     vector<int> arr{2,  3,  5,  7,  11, 13, 17, 19, 23, 29,                     31, 37, 41, 43, 47, 4,  9,  25, 49};     int i = 0, k = 0;     int l = arr.size();     while (i < l) {       string s;       cout << arr[i] << endl;       cin >> s;       if (s ==  yes ) k++;       if (k == 2) {         cout <<  composite  << endl;         break;       }       i++;     }     if (k < 2) {       cout <<  prime  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, A[100001], Ans[100001];   bool k[100001];   int solve(int x) {     if (Ans[x]) return Ans[x];     int tmp = 0, cnt = 0, pre = 1;     for (int i = 1; i <= n; i++) {       if (!k[A[i]]) {         if (cnt == x) {           tmp++;           cnt = 1;           for (int j = pre; j < i; j++) {             k[A[j]] = 0;           }           pre = i;           k[A[i]] = 1;         } else {           cnt++;           k[A[i]] = 1;         }       }     }     if (cnt) {       tmp++;       for (int i = pre; i <= n; i++) k[A[i]] = 0;     }     return Ans[x] = tmp;   }   void work(int x, int y) {     int l = solve(x), r = solve(y);     if (l == r) {       for (int i = x; i <= y; i++) {         Ans[i] = l;       }       return;     }     int mid = (x + y) / 2;     work(x, mid);     work(mid + 1, y);   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &A[i]);     work(1, n);     for (int i = 1; i <= n; i++) printf( %d  , Ans[i]);   }


#include <bits/stdc++.h>   int atob(int t, int a, int b) {     int ret = 0, p = 1;     while (t) {       ret += t % b * p;       p *= a;       t /= b;     }     return ret;   }   int maxbit(int t) {     int ret = t % 10;     while (t) {       if (ret < t % 10) ret = t % 10;       t /= 10;     }     return ret;   }   int len(int t) {     int cnt = 0;     while (t) {       cnt++;       t /= 10;     }     return cnt;   }   int main() {     int a, b, base, res = 0;     scanf( %d%d , &a, &b);     base = maxbit(a) + 1;     if (base < maxbit(b) + 1) base = maxbit(b) + 1;     for (; base <= 10; ++base) {       int ta = atob(a, base, 10), tb = atob(b, base, 10),           t = atob(ta + tb, 10, base);       if (res < len(t)) res = len(t);     }     printf( %d , res);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long oo = 1e9;   const int maxSize = 1001000;   const int mod = 1e9 + 7;   const double EPS = (1e-9);   int dcmp(double x, double y) { return fabs(x - y) <= EPS ? 0 : x < y ? -1 : 1; }   int main() {     int one = 0, remain1 = 0, two = 0, a, b;     int n, res = 0;     scanf( %d%d%d , &n, &a, &b);     for (int i = 0; i < n; i++) {       int num;       scanf( %d , &num);       if (num == 1) {         if (a)           a--;         else if (remain1 < 2 * b)           remain1++;         else           res++;       } else {         if (b - remain1 > 0)           b--;         else           res += 2;       }     }     cout << res;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e3 + 7;   int n;   int a[N], b[N], x[N], y[N];   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d%d , &a[i], &b[i]);     }     for (int i = 1; i <= n; i++) {       scanf( %d%d , &x[i], &y[i]);     }     sort(a + 1, a + 1 + n);     sort(b + 1, b + 1 + n);     sort(x + 1, x + 1 + n);     sort(y + 1, y + 1 + n);     cout << a[1] + x[n] <<     << b[1] + y[n] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1791791791;   const long long INFLL = 1791791791791791791ll;   template <int input_buf_size, int output_buf_size>   class FastIO {     char cbuf[input_buf_size + 1];     int icur = 0;     inline bool go_to_next_token() {       while (cbuf[icur] ==     || cbuf[icur] ==   n ) icur++;       while (cbuf[icur] == 0) {         icur = 0;         if (fgets(cbuf, sizeof(cbuf), stdin) != cbuf) return false;         while (cbuf[icur] ==     || cbuf[icur] ==   n ) icur++;       }       return true;     }       public:     string readString() {       assert(go_to_next_token());       string ans;       while (cbuf[icur] !=     && cbuf[icur] !=   n  && cbuf[icur] != 0)         ans.push_back(cbuf[icur++]);       ans.shrink_to_fit();       return ans;     }     template <class int_type>     int_type readInt() {       assert(go_to_next_token());       int_type x = 0;       bool m = cbuf[icur] ==  - ;       if (m) icur++;       while ( 0  <= cbuf[icur] && cbuf[icur] <=  9 ) {         x *= 10;         x += (cbuf[icur] -  0 );         icur++;       }       if (m) x = -x;       return x;     }     bool seekEof() { return !go_to_next_token(); }       private:     char obuf[output_buf_size + 1];     int ocur = 0;     inline void write_string(const char* str, size_t sz = 0) {       if (sz == 0) sz = strlen(str);       if (ocur + sz > output_buf_size) {         fputs(obuf, stdout);         fputs(str, stdout);         ocur = 0;         obuf[0] = 0;         return;       }       strcpy(obuf + ocur, str);       ocur += sz;       obuf[ocur] = 0;     }       public:     template <class int_type>     void writeInt(int_type x, bool sp = true) {       char buf[20];       int c = 0;       if (x < 0) {         buf[c++] =  - ;         x = -x;       }       int s = c;       if (x == 0) {         buf[c++] =  0 ;       }       while (x > 0) {         buf[c++] = (x % 10) +  0 ;         x /= 10;       }       for (int i = 0; 2 * i < c - s; i++) {         swap(buf[s + i], buf[c - 1 - i]);       }       buf[c] = 0;       write_string(buf, c);       if (sp) write_string(   , 1);     }     void writeString(string s, bool space = true) {       write_string(s.c_str(), s.size());       if (space) write_string(   , 1);     }     void writeEndl() { write_string(  n , 1); }     void flush() {       fputs(obuf, stdout);       ocur = 0;       obuf[0] = 0;     }       private:     bool lflush;       public:     FastIO(bool local_flush) {       obuf[0] = 0;       lflush = local_flush;     }     ~FastIO() { fputs(obuf, stdout); }   };   FastIO<10000000, 10000000> IO(true);   const int maxn = 3179;   vector<int> graph[maxn];   int dist[maxn][maxn];   vector<int> mdff[maxn];   vector<int> mdfs[maxn];   int main() {     int n = IO.readInt<int>();     int m = IO.readInt<int>();     for (int i = 0; i < ((int)(m)); ++i) {       int u = IO.readInt<int>() - 1;       int v = IO.readInt<int>() - 1;       graph[u].push_back(v);     }     for (int start = 0; start < ((int)(n)); ++start) {       fill(dist[start], dist[start] + n, -1);       dist[start][start] = 0;       queue<int> q;       q.push(start);       while (!q.empty()) {         int a = q.front();         q.pop();         for (int v : graph[a]) {           if (dist[start][v] == -1) {             dist[start][v] = dist[start][a] + 1;             q.push(v);           }         }       }     }     for (int i = 0; i < ((int)(n)); ++i) {       for (int j = 0; j < ((int)(n)); ++j)         if (j != i) {           mdfs[i].push_back(j);           mdff[i].push_back(j);         }       sort((mdfs[i]).begin(), (mdfs[i]).end(),            [&](const int& a, const int& b) -> bool {              return dist[i][a] > dist[i][b];            });       sort((mdff[i]).begin(), (mdff[i]).end(),            [&](const int& a, const int& b) -> bool {              return dist[a][i] > dist[b][i];            });     }     int a, b, c, d;     int ans = -1;     for (int m1 = 0; m1 < ((int)(n)); ++m1) {       for (int m2 = 0; m2 < ((int)(n)); ++m2) {         if (m1 != m2) {           for (int i = 0; i < ((int)(3)); ++i) {             for (int j = 0; j < ((int)(3)); ++j) {               int l = mdff[m1][i];               int r = mdfs[m2][j];               if (m1 == r || m2 == l || l == r) continue;               if (dist[l][m1] == -1 || dist[m1][m2] == -1 || dist[m2][r] == -1)                 continue;               if (dist[l][m1] + dist[m1][m2] + dist[m2][r] > ans) {                 ans = dist[l][m1] + dist[m1][m2] + dist[m2][r];                 a = l;                 b = m1;                 c = m2;                 d = r;               }             }           }         }       }     }     cerr << ans << endl;     IO.writeInt(a + 1);     IO.writeInt(b + 1);     IO.writeInt(c + 1);     IO.writeInt(d + 1);     IO.writeEndl();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double EPS = 1e-9;   bool operator<(const complex<double>& a, const complex<double>& b) {     if (fabs(a.imag() - b.imag()) > EPS) return a.imag() < b.imag();     return a.real() + EPS < b.real();   }   class cmp {    public:     bool operator()(const complex<double>& a, const complex<double>& b) {       return a < b;     }   };   bool pointOnLeft(const complex<double>& p, const complex<double>& p1,                    const complex<double>& p2) {     return imag(conj(((p2) - (p1))) * (((p) - (p1)))) > EPS;   }   class cmpHull {    public:     complex<double> about, nex;     cmpHull(const complex<double>& about, const complex<double>& nex)         : about(about), nex(nex) {}     bool operator()(const complex<double>& a, const complex<double>& b) {       double crs = imag(conj(((a) - (about))) * (((b) - (about))));       if (fabs(crs) < EPS) {         if (fabs(imag(conj(((nex) - (about))) * (((a) - (about))))) < EPS)           return a < b;         return b < a;       }       return crs > 0;     }   };   void sortAntiClockwise(vector<complex<double> >& polygon) {     int about = 0;     for (int c = 1; c < (int)polygon.size(); c++)       if (polygon[c] < polygon[about]) about = c;     swap(polygon[about], polygon[0]);     sort(polygon.begin() + 1, polygon.end(), cmpHull(polygon[0], polygon[0]));     sort(polygon.begin() + 2, polygon.end(), cmpHull(polygon[0], polygon[1]));     return;   }   vector<complex<double> > convexHull(vector<complex<double> >& polygon) {     sortAntiClockwise(polygon);     vector<complex<double> > hull;     int sz = 0;     for (int i = 0; i < (int)polygon.size(); i++) {       while (sz >= 2 && pointOnLeft(polygon[i], hull[sz - 1], hull[sz - 2])) {         hull.pop_back();         sz--;       }       sz++;       hull.push_back(polygon[i]);     }     return hull;   }   vector<complex<double> > shift(const vector<complex<double> >& A, int pivot) {     vector<complex<double> > ret;     for (int c = pivot; c < pivot + (int)A.size(); c++)       ret.push_back(A[c % A.size()]);     return ret;   }   vector<complex<double> > A, B, all;   int n, m;   int main() {     set<complex<double>, cmp> ss;     int c, c2;     scanf( %d , &n);     int x, y;     for (c = 0; c < n; c++) {       scanf( %d%d , &x, &y);       A.push_back(complex<double>(x, y));       all.push_back(complex<double>(x, y));       ss.insert(complex<double>(x, y));     }     scanf( %d , &m);     for (c = 0; c < m; c++) {       scanf( %d%d , &x, &y);       B.push_back(complex<double>(x, y));       all.push_back(complex<double>(x, y));       ss.insert(complex<double>(x, y));     }     if (ss.size() < all.size()) {       printf( NO n );       return 0;     }     reverse(A.begin(), A.end());     reverse(B.begin(), B.end());     int pivot = 0;     for (c = 1; c < (int)A.size(); c++)       if (A[c] < A[pivot]) pivot = c;     A = shift(A, pivot);     vector<complex<double> > hull = convexHull(all);     if (hull.size() != A.size()) {       printf( NO n );       return 0;     }     bool yes = true;     for (c = 0; c < (int)hull.size(); c++)       if (hull[c] < A[c] || A[c] < hull[c]) yes = false;     if (yes)       printf( YES n );     else       printf( NO n );   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   const long long INF = 1e9 + 5;   const long long mod = 1e9 + 7;   const double pi = 3.1415926536;   map<char, int> mp, mp2;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     ios_base::sync_with_stdio(0);     ;     string n, m;     cin >> n >> m;     for (int i = 0; i < n.size(); i++) {       mp[n[i]]++;     }     set<char> st;     for (int i = 0; i < m.size(); i++) {       st.insert(m[i]);       mp2[m[i]]++;       if (!mp[m[i]]) return cout <<  -1 n , 0;     }     long long ans = 0;     set<char>::iterator it;     for (it = st.begin(); it != st.end(); it++) {       ans += min(mp[*it], mp2[*it]);     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, l, r, K, p;   bool check(long long x) {     long long t = K % (n + x);     if (t == 0) t = n + x;     if (t > min(p * 2, p + x)) return 0;     if (t < p + max(0LL, x - n + p - 1)) return 0;     return 1;   }   signed main() {     scanf( %lld%lld%lld%lld , &n, &l, &r, &K);     p = (r - l + 1 + n) % n;     if (p > K) {       return puts( -1 ), 0;     }     if (p == 0) p += n;     if (n <= 100000) {       for (long long i = n; i >= 0; i--)         if (check(i)) {           printf( %lld n , i);           return 0;         }       puts( -1 );       return 0;     }     long long ans = 0;     for (long long t = ceil((double)(K - 2 * p) / (double)(2 * n));          t * n + p <= K; t++) {       long long y = K - n * t - p;       long long x;       if (t != 0)         x = min((long long)floor((double)(n - p + y) / (1 + t)),                 (long long)y / t);       else {         x = (K - p + 1) + (n - p);       }       y = K - n * t - p - t * x;       if (y < 0 || y > p || y > x || x > n) continue;       ans = max(ans, x);       y = K - n * t - p + 1;       if (t != 0)         x = min((long long)floor((double)(n - p + y) / (1 + t)),                 (long long)y / t);       else {         x = (K - p + 1) + (n - p);       }       y = K - n * t - p - t * x;       if (y < 0 || y > p || y > x || x > n) continue;       ans = max(ans, x);     }     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) {     while (a) {       b %= a;       swap(a, b);     }     return b;   }   struct Vector2D {     long long x, y;     Vector2D() {}     Vector2D(long long x, long long y) : x(x), y(y) {}   };   Vector2D operator-(const Vector2D& lhs, const Vector2D& rhs) {     return Vector2D(lhs.x - rhs.x, lhs.y - rhs.y);   }   bool operator==(const Vector2D& lhs, const Vector2D& rhs) {     return lhs.x == rhs.x && lhs.y == rhs.y;   }   Vector2D normalize(const Vector2D& v) {     const long long g = gcd(abs(v.x), abs(v.y));     return Vector2D(v.x / g, v.y / g);   }   struct Vector2DHash {     size_t operator()(const Vector2D& v) const { return v.x * 1000000007 + v.y; }   };   class OrderByLength {    public:     OrderByLength(const vector<Vector2D>& targets, const Vector2D& base)         : targets_(targets), base_(base) {}     bool operator()(const int lhs_, const int rhs_) const {       const Vector2D lhs = targets_[lhs_] - base_;       const Vector2D rhs = targets_[rhs_] - base_;       return lhs.x * lhs.x + lhs.y * lhs.y < rhs.x * rhs.x + rhs.y * rhs.y;     }       private:     const vector<Vector2D>& targets_;     const Vector2D& base_;   };   bool check(const vector<Vector2D>& bears, const vector<Vector2D>& targets,              vector<unordered_map<Vector2D, vector<int>, Vector2DHash> >& maps,              const int target, const vector<int>& order, int& next,              vector<int>& killed) {     if (next == order.size()) return false;     const int bear = order[next];     const vector<int>& onLine =         maps[bear][normalize(targets[target] - bears[bear])];     for (int nextTarget : onLine) {       if (target == nextTarget) {         killed.push_back(target);         return true;       }       if (find(killed.begin(), killed.end(), nextTarget) != killed.end())         continue;       if (!check(bears, targets, maps, nextTarget, order, ++next, killed)) break;     }     return false;   }   int main() {     int k, n;     cin >> k >> n;     vector<Vector2D> bears(k);     vector<Vector2D> targets(n);     for (int i = 0; i < k; ++i) cin >> bears[i].x >> bears[i].y;     for (int i = 0; i < n; ++i) cin >> targets[i].x >> targets[i].y;     vector<unordered_map<Vector2D, vector<int>, Vector2DHash> > maps(k);     for (int i = 0; i < k; ++i) {       for (int j = 0; j < n; ++j)         maps[i][normalize(targets[j] - bears[i])].push_back(j);       for (auto& p : maps[i])         sort(p.second.begin(), p.second.end(), OrderByLength(targets, bears[i]));     }     int res = 0;     for (int i = 0; i < n; ++i) {       bool danger = false;       vector<int> order(k);       iota(order.begin(), order.end(), 0);       do {         vector<int> killed;         int next = 0;         danger |= check(bears, targets, maps, i, order, next, killed);       } while (!danger && next_permutation(order.begin(), order.end()));       res += danger;     }     cout << res << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 7007;   const int MAXM = 300007;   const int INF = 1 << 29;   const int dir[][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};   char reactor[15][15], rescue[15][15];   int N;   int table[15][15];   bool isIn(int x, int y) { return x >= 1 && y >= 1 && x <= N && y <= N; }   struct Edge {     int u, v, cap, flow;     Edge *next, *back;   };   struct Graph {     Edge *head[MAXN], adj[MAXM];     Edge *cur[MAXN], *path[MAXN];     int lev[MAXN];     int n, k;     int S, T;     void init(int nn) {       S = 0, T = nn;       n = nn, k = 0;       for (int i = 0; i <= n; i++) head[i] = NULL;     }     void set(int s, int t) { S = s, T = t; }     void addedge(int u, int v, int cap) {       adj[k].u = u;       adj[k].v = v;       adj[k].flow = 0;       adj[k].cap = cap;       adj[k].next = head[u];       head[u] = adj + k++;     }     void add(int u, int v, int cap) {       addedge(u, v, cap);       addedge(v, u, 0);       head[u]->back = head[v];       head[v]->back = head[u];     }     bool bfs() {       queue<int> q;       fill(lev, lev + n + 1, -1);       lev[S] = 0;       q.push(S);       int u, v;       while (!q.empty()) {         u = q.front();         q.pop();         for (Edge *f = head[u]; f; f = f->next) {           if (f->flow == f->cap) continue;           v = f->v;           if (lev[v] == -1) {             lev[v] = lev[u] + 1;             q.push(v);             if (v == T) return true;           }         }       }       return (lev[T] != -1);     }     int dinic() {       int u, v, pt;       int flow = 0;       while (bfs()) {         for (int i = 0; i <= n; i++) cur[i] = head[i];         pt = 0;         u = S;         while (true) {           if (u == T) {             int delta = INF, minI = 0;             for (int i = 0; i < pt; i++) {               if (delta > path[i]->cap - path[i]->flow) {                 delta = path[i]->cap - path[i]->flow;                 minI = i;               }             }             for (int i = 0; i < pt; i++) {               path[i]->flow += delta;               path[i]->back->flow -= delta;             }             u = path[pt = minI]->u;             flow += delta;           }           Edge *f;           for (f = cur[u]; f; f = f->next) {             if (f->cap == f->flow) continue;             v = f->v;             if (lev[v] == lev[u] + 1) break;           }           cur[u] = f;           if (f) {             path[pt++] = f;             u = f->v;           } else {             lev[u] = -1;             if (!pt) break;             u = path[--pt]->u;           }         }       }       return flow;     }   } graph;   void bfs(int sx, int sy, int t) {     for (int i = 1; i <= N; i++) {       fill(table[i], table[i] + N + 1, INF);     }     queue<pair<int, int> > q;     q.push(pair<int, int>(sx, sy));     table[sx][sy] = 0;     while (!q.empty()) {       pair<int, int> cur = q.front();       q.pop();       for (int i = 0; i < 4; i++) {         int x = cur.first + dir[i][0];         int y = cur.second + dir[i][1];         if (!isIn(x, y) || !isdigit(reactor[x][y]) || table[x][y] != INF) {           continue;         }         table[x][y] = table[cur.first][cur.second] + 1;         q.push(pair<int, int>(x, y));       }     }   }   int main() {     int n, t;     int S, T;     scanf( %d%d , &n, &t);     N = n;     int sx, sy;     for (int i = 1; i <= n; i++) {       scanf(  %s , reactor[i] + 1);       for (int j = 1; j <= n; j++) {         if (reactor[i][j] ==  Z ) {           sx = i;           sy = j;         }       }     }     bfs(sx, sy, t);     for (int i = 1; i <= n; i++) {       scanf(  %s , rescue[i] + 1);     }     S = 0, T = (t + 1) * n * n + 1;     graph.init(T);     graph.set(S, T);     for (int cur = 0; cur < t; cur++) {       int add1 = cur * n * n;       int add2 = (cur + 1) * n * n;       for (int i = 1; i <= n; i++) {         for (int j = 1; j <= n; j++) {           if (!isdigit(reactor[i][j])) continue;           if (isdigit(rescue[i][j]) && rescue[i][j] !=  0 ) {             graph.add(add1 + (i - 1) * n + j, add2 + (i - 1) * n + j,                       rescue[i][j] -  0 );             if (cur >= table[i][j]) continue;           }           if (isdigit(reactor[i][j]) && cur < table[i][j]) {             if (cur + 1 < table[i][j]) {               graph.add(add1 + (i - 1) * n + j, add2 + (i - 1) * n + j, INF);             }             for (int k = 0; k < 4; k++) {               int x = i + dir[k][0];               int y = j + dir[k][1];               if (!isIn(x, y) || !isdigit(reactor[x][y])) continue;               if (cur + 1 < table[x][y] ||                   table[x][y] == cur + 1 && isdigit(rescue[x][y]))                 graph.add(add1 + (i - 1) * n + j, add2 + (x - 1) * n + y, INF);             }           }         }       }     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         if (isdigit(reactor[i][j]) && reactor[i][j] !=  0 ) {           graph.add(S, (i - 1) * n + j, reactor[i][j] -  0 );         }         if (isdigit(rescue[i][j]) && rescue[i][j] !=  0 ) {           graph.add(t * n * n + (i - 1) * n + j, T, rescue[i][j] -  0 );         }       }     }     printf( %d n , graph.dinic());     return 0;   }


#include <bits/stdc++.h>      using namespace std;      pair<int, int> dataarr[502];      int main() {       int n;       cin >> n;       int minin = n, maxin = 0;       for (int i = 1; i <= n; i++) {           cin >> dataarr[i].first;           dataarr[i].second = i;           if (dataarr[i].first < minin) {               minin = dataarr[i].first;           }           if (dataarr[i].first > maxin) {               maxin = dataarr[i].first;           }       }       int indif = maxin - minin;       sort(dataarr, dataarr + (n + 1));       for (int d = indif; d >= 0; d--) {           for (int i = 1; i <= n; i++) {               for (int j = i + 1; j <= n; j++) {                   if (dataarr[j].first - dataarr[i].first == d) {                       cout <<  ?   << dataarr[j].second <<     << dataarr[i].second << endl;                       string s;                       cin >> s;                       if (s ==  Yes ) {                           cout <<  !   << dataarr[j].second <<     << dataarr[i].second << endl;                           return(0);                       }                   }               }           }       }       cout <<  ! 0 0  << endl;       return(0);   }


#include <bits/stdc++.h>   using namespace std;   void loadData(void);   int proc(void);   void printRes(int);   int left1, right1, left2, right2;   int pow2[31];   int getRes(int, int, int, int);   int getMaxCLevelAndPos(int, int, int&);   bool lyb_debug = false;   int main(int argc, char** argv) {     loadData();     printRes(proc());     return 0;   }   int getMaxCLevelAndPos(int l, int r, int& pos) {     if (lyb_debug) {       printf( ==check for (%d - %d) n n , l, r);     }     for (int i = 31 - 1; i >= 0; i--)       if (r >= pow2[i] - 1 && l <= pow2[i] - 1) {         pos = pow2[i] - 1;         return i;       }     int min_pow2_pos;     for (min_pow2_pos = 31 - 1; min_pow2_pos >= 0; min_pow2_pos--)       if (l >= pow2[min_pow2_pos]) break;     if (min_pow2_pos == -1)       return -1;     else {       int ret =           getMaxCLevelAndPos(l - pow2[min_pow2_pos], r - pow2[min_pow2_pos], pos);       if (ret != -1) pos += pow2[min_pow2_pos];       return ret;     }     return -1;   }   int getRes(int l1, int r1, int l2, int r2) {     if (r1 < l1 || r2 < l2) return 0;     int maxCPos1 = -1;     int maxCLevel1 = getMaxCLevelAndPos(l1, r1, maxCPos1);     if (lyb_debug) {       printf( ==res for l:%d r:%d : level:%d pos:%d n n , l1, r1, maxCLevel1,              maxCPos1);     }     int maxCPos2 = -1;     int maxCLevel2 = getMaxCLevelAndPos(l2, r2, maxCPos2);     if (lyb_debug) {       printf( ==res for l:%d r:%d : level:%d pos:%d n n , l2, r2, maxCLevel2,              maxCPos2);     }     if (maxCLevel1 == -1 || maxCLevel2 == -1) {       if (maxCLevel1 == -1 && maxCLevel2 == -1) return 1;       if (maxCLevel1 == -1) return r2 - l2 == 0 ? 0 : 1;       if (maxCLevel2 == -1) return r1 - l1 == 0 ? 0 : 1;     }     if (maxCLevel1 == maxCLevel2) {       int res = min(r1 - maxCPos1, r2 - maxCPos2) +                 min(maxCPos1 - l1, maxCPos2 - l2) + 1;       int newl1, newr1, newl2, newr2;       if (maxCPos1 - l1 > r1 - maxCPos1) {         newl1 = l1;         newr1 = maxCPos1 - 1;       } else {         newl1 = maxCPos1 + 1;         newr1 = r1;       }       if (maxCPos2 - l2 > r2 - maxCPos2) {         newl2 = l2;         newr2 = maxCPos2 - 1;       } else {         newl2 = maxCPos2 + 1;         newr2 = r2;       }       res = max(res, getRes(newl1, newr1, newl2, newr2));       return res;     } else if (maxCLevel1 > maxCLevel2) {       return max(getRes(max(maxCPos1 - pow2[maxCLevel2 + 1] + 1, l1),                         maxCPos1 - 1, l2, r2),                  getRes(maxCPos1 + 1,                         min(r1, maxCPos1 + pow2[maxCLevel2 + 1] + 1), l2, r2));     } else {       return max(getRes(l1, r1, max(maxCPos2 - pow2[maxCLevel1 + 1] + 1, l2),                         maxCPos2 - 1),                  getRes(l1, r1, maxCPos2 + 1,                         min(r2, maxCPos2 + pow2[maxCLevel1 + 1] + 1)));     }     return 0;   }   void initPow2(void) {     pow2[0] = 1;     for (int i = 1; i < 31; i++) pow2[i] = 2 * pow2[i - 1];     if (lyb_debug) {       printf( ==pow2== n );       for (int i = 0; i < 31; i++) printf( %d  , pow2[i]);       printf(  n n );     }     return;   }   int proc(void) {     initPow2();     return getRes(left1, right1, left2, right2);   }   void loadData(void) {     scanf( %d%d%d%d , &left1, &right1, &left2, &right2);     left1--;     right1--;     left2--;     right2--;     return;   }   void printRes(int res) {     printf( %d n , res);     return;   }


#include <bits/stdc++.h>   using namespace std;   struct point {     long long int x, y;     point() {}     point(long long int _x, long long int _y) {       x = _x;       y = _y;     }   };   bool cmp(const point &a, const point &b) {     if (a.x == b.x) return a.y < b.y;     return a.x < b.x;   }   struct freq {     long long int x_freq;     set<long long int> y_freq;   };   freq freq_list[200005];   point S[200010];   long long int mod;   long long int fact_mod(long long int k) {     long long int ans = 1;     while (k > 0) {       ans = (ans % mod * k % mod) % mod;       --k;     }     return ans % mod;   }   int main() {     int N;     cin >> N;     for (int i = 0; i < N; ++i) {       int x;       cin >> x;       S[i] = point(x, i);     }     for (int i = 0; i < N; ++i) {       int x;       cin >> x;       S[N + i] = point(x, i);     }     cin >> mod;     sort(S, S + 2 * N, cmp);     int last = -1, cnt = -1, m;     for (int i = 0; i < 2 * N; ++i) {       if (S[i].x != last) {         ++cnt;         last = S[i].x;         freq_list[cnt].x_freq = 1;         freq_list[cnt].y_freq.insert(S[i].y);       } else {         ++freq_list[cnt].x_freq;         freq_list[cnt].y_freq.insert(S[i].y);       }     }     long long int ans = 1, n;     for (int i = 0; i <= cnt; ++i) {       m = freq_list[i].x_freq - freq_list[i].y_freq.size();       n = freq_list[i].x_freq;       int k = n;       for (int j = 0; j < m; ++j) {         ans = ((ans % mod) * ((n * (n - 1) / 2LL) % mod)) % mod;         n -= 2;       }       ans = ((ans % mod) * (fact_mod(k - 2 * m) % mod)) % mod;     }     cout << ans % mod << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double EPS = 1e-10;   const double PI = acos(-1.0);   struct Edge {     int to, cost;     Edge(int t, int c) : to(t), cost(c) {}     bool operator>(const Edge& rhs) const { return cost > rhs.cost; }   };   long long N, S;   vector<int> dp, parent;   vector<vector<Edge>> G;   void dfs(int par, int node, int d) {     parent[node] = par;     dp[node] = 1;     for (int i = 0; i < int((G[node]).size()); ++i) {       int& to = G[node][i].to;       if (to == par) continue;       dfs(node, to, d + 1);       dp[node] += dp[to];       S += 2 * dp[to] * (N - dp[to]) * G[node][i].cost;     }   }   int main() {     cin.tie(0);     ios_base::sync_with_stdio(false);     cin >> N;     G.assign(N + 1, vector<Edge>());     vector<pair<int, Edge>> edges;     for (int i = (0); i < (N - 1); ++i) {       int a, b, c;       cin >> a >> b >> c;       G[a].push_back(Edge(b, c));       G[b].push_back(Edge(a, c));       edges.push_back(make_pair(a, Edge(b, c)));     }     dp.assign(N + 1, 0);     parent.assign(N + 1, -1);     S = 0;     dfs(-1, 1, 0);     int Q;     cin >> Q;     while (Q--) {       int idx, c;       cin >> idx >> c;       --idx;       Edge& e = edges[idx].second;       int a = edges[idx].first, b = e.to;       if (parent[b] == a) swap(a, b);       S -= (e.cost - c) * 2 * dp[a] * (N - dp[a]);       cout << fixed << setprecision(7) << 3 * S * 1. / (N * (N - 1)) << endl;       e.cost = c;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string a, b;   int k;   int main() {     cin >> a;     k = 1;     if (a.size() % 2 == 0) {       while (k != a.size() + 1) {         if (k % 2 != 0) {           b += a[a.size() - k / 2 - 1];         } else {           b += a[k / 2 - 1];         }         k++;       }     } else {       while (k != a.size() + 1) {         if (k % 2 == 0) {           b += a[a.size() - k / 2];         } else {           b += a[k / 2];         }         k++;       }     }     reverse(b.begin(), b.end());     cout << b;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2005, INF = 1e9;   int dx[] = {1, -1, 0, 0};   int dy[] = {0, 0, 1, -1};   pair<int, int> dis[N][N];   bool done[N][N];   string g[N];   int n, m, sx, sy, L, R;   bool valid(int x, int y) {     return x >= 0 && x < n && y >= 0 && y < m && g[x][y] ==  . ;   }   void solve(bool fs) {     priority_queue<pair<pair<int, int>, pair<int, int>>,                    vector<pair<pair<int, int>, pair<int, int>>>,                    greater<pair<pair<int, int>, pair<int, int>>>>         pq;     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) dis[i][j] = {INF, INF};     dis[sx][sy] = {0, 0};     pq.push({{0, 0}, {sx, sy}});     while (!pq.empty()) {       int x = pq.top().second.first;       int y = pq.top().second.second;       pair<int, int> d = pq.top().first;       pq.pop();       if (dis[x][y] < d) continue;       if (fs && dis[x][y].first <= L && dis[x][y].second <= R) done[x][y] = 1;       if ((!fs) && dis[x][y].first <= R && dis[x][y].second <= L) done[x][y] = 1;       for (int i = 0; i < 4; i++) {         int nx = x + dx[i], ny = y + dy[i];         if (valid(nx, ny)) {           pair<int, int> p = {0, 0};           if (dy[i] < 0) {             if (fs)               p = {1, 0};             else               p = {0, 1};           }           if (dy[i] > 0) {             if (fs)               p = {0, 1};             else               p = {1, 0};           }           pair<int, int> np = {d.first + p.first, d.second + p.second};           if (np < dis[nx][ny]) {             dis[nx][ny] = np;             pq.push({np, {nx, ny}});           }         }       }     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> m;     cin >> sx >> sy;     sx--;     sy--;     cin >> L >> R;     for (int i = 0; i < n; i++) cin >> g[i];     solve(0);     solve(1);     int ans = 0;     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) ans += done[i][j];     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   long long int gcd(long long int a, long long int b) {     return (a ? gcd(b % a, a) : b);   }   inline int two(int n) { return 1 << n; }   inline int test(int n, int b) { return (n >> b) & 1; }   inline void set_bit(int& n, int b) { n |= two(b); }   inline void unset_bit(int& n, int b) { n &= ~two(b); }   inline int last_bit(int n) { return n & (-n); }   inline int ones(int n) {     int res = 0;     while (n && ++res) n -= n & (-n);     return res;   }   long long int modPow(long long int a, long long int b, long long int MOD) {     long long int x = 1, y = a;     while (b > 0) {       if (b % 2 == 1) {         x = (x * y) % MOD;       }       b /= 2;       y = (y * y) % MOD;     }     return x;   }   long long int modInverse(long long int a, long long int p) {     return modPow(a, p - 2, p);   }   using namespace std;   int main() {     int n, k, i, from, to;     long long int crossed_count, ans;     crossed_count = 0;     ans = 1;     scanf( %d , &n);     scanf( %d , &k);     k = min(k, n - k);     from = 0;     for (int i = (1); i <= (n); i++) {       to = (from + k) % n;       if (to < from && to != 0) crossed_count++;       ans += crossed_count + 1;       if (to < from) crossed_count++;       printf( %lld  , ans);       from = to;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 200010;   long long a[N], b[N], p[N], money;   int top, n, m, ans, st[N];   vector<long long> v[N];   priority_queue<long long> q;   void get_sale_day() {     for (int i = 1; i <= n; ++i) {       while (top && a[i] >= a[st[top]]) --top;       st[++top] = i;     }     for (int i = 1; i <= m; ++i) {       if (b[i] > a[st[1]]) continue;       int l = 1, r = top, ans = 0;       while (l <= r) {         int mid = (l + r) >> 1;         if (a[st[mid]] >= b[i])           ans = mid, l = mid + 1;         else           r = mid - 1;       }       v[st[ans]].push_back(p[i]);     }   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; ++i) scanf( %lld , &a[i]);     for (int i = 1; i <= m; ++i) scanf( %lld , &b[i]);     for (int i = 1; i <= m; ++i) scanf( %lld , &p[i]);     get_sale_day();     for (int i = 1; i <= n; ++i) {       money += a[i];       sort(v[i].begin(), v[i].end());       for (int j = 0; j < v[i].size(); ++j)         if (v[i][j] <= money) {           money -= v[i][j];           q.push(v[i][j]);           ans++;         } else {           if (q.empty()) continue;           long long tmp = q.top();           if (tmp > v[i][j]) {             q.pop();             q.push(v[i][j]);             money += tmp - v[i][j];           }         }     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1000000007;   const int Maxn = 500005;   map<long long, int> mp;   vector<pair<int, int> > g[Maxn];   long long c[Maxn];   int pw2[Maxn] = {1}, par[Maxn], n, m, k, sz, ans;   int find(int u) { return par[u] == u ? u : par[u] = find(par[u]); }   int main() {     scanf( %d%d%d , &n, &m, &k);     for (int i = 1; i <= n; i++) pw2[i] = pw2[i - 1] * 2 % mod;     for (int i = 1; i <= n; i++) scanf( %lld , &c[i]);     for (int i = 1; i <= n; i++) par[i] = i;     for (int x, y; m--;) {       scanf( %d%d , &x, &y);       if (!mp[c[x] ^ c[y]]) mp[c[x] ^ c[y]] = ++sz;       g[mp[c[x] ^ c[y]]].push_back(make_pair(x, y));     }     for (int i = 1; i <= sz; ++i) {       int s = n;       for (int j = 0; j < g[i].size(); j++) {         int x = find(g[i][j].first), y = find(g[i][j].second);         if (x ^ y) par[x] = y, s--;       }       ans = (ans + pw2[s]) % mod;       for (int j = 0; j < g[i].size(); j++)         par[g[i][j].first] = g[i][j].first, par[g[i][j].second] = g[i][j].second;     }     ans = (ans + (long long)((1ll << k) - sz + mod) % mod * pw2[n] % mod) % mod;     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   std::vector<int> dsc[100005];   int st[5005], fi[5005], vt[5005], nx[5005], mx[5005];   int a[100005];   double prob[5005];   double f[5005][5005 + 5];   void sx(int l, int r) {     if (l >= r) return;     int i = l, j = r;     int chot = vt[l + rand() % (r - l + 1)];     int chot2 = fi[chot];     chot = st[chot];     while (i <= j) {       while (st[vt[i]] < chot || (st[vt[i]] == chot && fi[vt[i]] > chot2)) i++;       while (st[vt[j]] > chot || (st[vt[j]] == chot && fi[vt[j]] < chot2)) j--;       if (i <= j) {         if (i < j) {           int tg = vt[i];           vt[i] = vt[j];           vt[j] = tg;         }         i++;         j--;       }     }     sx(i, r);     sx(l, j);   }   void duyet(int ii) {     int sz = dsc[ii].size();     mx[ii] = 0;     if (sz == 0) {       for (int i = st[ii]; i <= fi[ii]; i++)         if (mx[ii] < a[i]) mx[ii] = a[i];     } else {       for (int i = st[ii]; i < st[dsc[ii][0]]; i++)         if (mx[ii] < a[i]) mx[ii] = a[i];       for (int j = 0; j < sz - 1; j++) {         for (int i = fi[dsc[ii][j]] + 1; i < st[dsc[ii][j + 1]]; i++)           if (mx[ii] < a[i]) mx[ii] = a[i];       }       for (int i = fi[dsc[ii][sz - 1]] + 1; i <= fi[ii]; i++)         if (mx[ii] < a[i]) mx[ii] = a[i];     }     for (int i = 0; i < sz; i++) {       duyet(dsc[ii][i]);       if (mx[dsc[ii][i]] > mx[ii]) mx[ii] = mx[dsc[ii][i]];     }     if (sz == 0) {       f[ii][0] = 1 - prob[ii];       for (int j = 1; j < 5005; j++) f[ii][j] = 1.0;     } else {       double f1, f2;       for (int j = 0; j < 5005; j++) {         f1 = f2 = 1.0;         for (int i = 0; i < sz; i++) {           int tmp = mx[ii] - mx[dsc[ii][i]] + j;           if (tmp >= 5005) tmp = 5005 - 1;           f1 *= f[dsc[ii][i]][tmp];           tmp = mx[ii] - mx[dsc[ii][i]] + j - 1;           if (tmp >= 5005) tmp = 5005 - 1;           if (tmp < 0)             f2 = 0;           else             f2 *= f[dsc[ii][i]][tmp];         }         if (j > 0)           f[ii][j] = (1 - prob[ii]) * f1 + prob[ii] * f2;         else           f[ii][j] = (1 - prob[ii]) * f1;       }     }   }   int main() {     int n, q;     scanf( %d%d , &n, &q);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     for (int i = 1; i <= q; i++) {       scanf( %d%d%lf , &st[i], &fi[i], &prob[i]);       vt[i] = i;     }     srand(time(NULL));     sx(1, q);     q++;     st[0] = 1;     fi[0] = n;     prob[0] = 0;     vt[0] = 0;     nx[0] = 0;     int topNX = 0;     for (int i = 1; i <= n; i++) dsc[i].clear();     for (int i = 1; i < q; i++) {       while (fi[vt[nx[topNX]]] < fi[vt[i]]) topNX--;       dsc[vt[nx[topNX]]].push_back(vt[i]);       nx[++topNX] = i;     }     duyet(0);     double res = 0.0;     for (int j = 0; j < 5005; j++) {       double pp = f[0][j];       if (j > 0) pp -= f[0][j - 1];       res += pp * (mx[0] + j);     }     printf( %.10lf , res);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxv = 2045;   const long long mod = 1e9 + 7;   const int maxn = 1e6 + 40;   long long fac[maxn], inv[maxn];   long long qpow(long long a, long long p) {     long long ans = 1;     long long xx = a;     while (p > 0) {       if (p & 1) ans = (xx * ans) % mod;       xx = (xx * xx) % mod;       p >>= 1;     }     return ans;   }   void init() {     fac[0] = 1;     inv[0] = 1;     for (long long i = 1; i < maxn; i++) {       fac[i] = (fac[i - 1] * i) % mod;       inv[i] = inv[i - 1] * qpow(i, mod - 2) % mod;     }   }   int h, w, n;   pair<long long, long long> a[maxv];   long long dp[maxv];   long long culC(long long a, long long b) {     return fac[a] * inv[a - b] % mod * inv[b] % mod;   }   long long path(long long sx, long long sy, long long tx, long long ty) {     return culC(ty - sy + tx - sx, tx - sx);   }   void solve() {     for (int i = 0; i <= n; i++) {       long long ans = 0;       for (int j = 0; j < i; j++) {         if (a[j].second <= a[i].second)           ans += path(a[j].first, a[j].second, a[i].first, a[i].second) * dp[j] %                  mod,               ans %= mod;       }       dp[i] = (path(1, 1, a[i].first, a[i].second) - ans) % mod + mod,       dp[i] %= mod;     }   }   int main() {     init();     cin >> h >> w >> n;     for (int i = 0; i < n; i++) {       int c, r;       scanf( %d%d , &r, &c);       a[i].first = r;       a[i].second = c;     }     sort(a, a + n);     a[n] = pair<long long, long long>(h, w);     solve();     cout << dp[n] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   constexpr long long int MOD = 1000000007;   constexpr double EPS = 1e-8;   long long int N, M, K, H, W, L, R;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> N;     vector<int> v(N);     for (auto &i : v) cin >> i >> i;     cin >> K;     for (int i = 0; i < N; i++) {       if (v[i] >= K) {         cout << N - i << endl;         break;       }     }   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   long long dx[] = {-1, 0, 1, 0};   long long dy[] = {0, -1, 0, 1};   int32_t main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long b, q, l, m;     cin >> b >> q >> l >> m;     if (abs(b) > l) {       cout << 0 <<   n ;       return 0;     }     set<long long> st;     for (long long i = 0; i < m; i++) {       long long x;       cin >> x;       st.insert(x);     }     if (b == 0 || q == 0) {       if (0 <= l && st.find(0) == st.end()) {         cout <<  inf n ;         return 0;       } else if (abs(b) <= l && st.find(b) == st.end()) {         cout << 1 <<   n ;         return 0;       } else         cout << 0;       return 0;     }     if (q == 1) {       if (abs(b) <= l && st.find(b) == st.end()) {         cout <<  inf n ;       } else         cout << 0 <<   n ;       return 0;     } else if (q == -1) {       if (abs(b) <= l && (st.find(b) == st.end() || st.find(-b) == st.end())) {         cout <<  inf n ;       } else         cout << 0 <<   n ;       return 0;     }     vector<long long> v;     while (abs(b) <= l) {       if (st.find(b) == st.end()) v.push_back(b);       b = b * q;     }     cout << v.size() <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int k, i;     cin >> k;     int a[12];     for (i = 0; i < 12; i++) cin >> a[i];     sort(a, a + 12);     int sum = 0, c = 0;     while (sum < k && i > 0) {       i--;       sum = sum + a[i];       c++;     }     if (sum >= k)       cout << c;     else       cout <<  -1 ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int m;   vector<string> users;   vector<string> msgs;   vector<string> owners(101);   map<string, int> mp;   bool vis[1001][1001];   int mem[1001][1001];   void printResults() {     for (int i = 0; i < msgs.size(); i++) {       cout << owners[i] << msgs[i].substr(msgs[i].find( : )) << endl;     }   }   int getSender(string message) {     if (message[0] ==  ? ) return -1;     string s =   ;     for (int i = 0; i < message.size(); i++) {       if (message[i] ==  : ) break;       s += message[i];     }     if (mp.find(s) == mp.end()) return -1;     return mp[s];   }   int findUser(int u, int ms) {     if (mem[u][ms] != -1) return mem[u][ms];     string message = msgs[ms];     string user = users[u];     for (int i = 0; i < message.size(); i++) {       if (i + user.size() - 1 >= message.size()) break;       int cnt = 0;       for (int j = 0; j < user.size(); j++) {         if (message[i + j] == user[j])           cnt++;         else           break;       }       if (cnt == user.size()) {         if ((i - 1 >= 0) && !(message[i - 1] ==     || message[i - 1] ==  !  ||                               message[i - 1] ==  .  || message[i - 1] ==  ?  ||                               message[i - 1] ==  ,  || message[i - 1] ==  : ))           continue;         if ((i + user.size()) < message.size() &&             !(message[i + user.size()] ==     ||               message[i + user.size()] ==  !  ||               message[i + user.size()] ==  .  ||               message[i + user.size()] ==  ?  ||               message[i + user.size()] ==  ,  || message[i + user.size()] ==  : ))           continue;         return (mem[u][ms] = 1);       }     }     return (mem[u][ms] = 0);   }   bool solve(int i, int j) {     if (i >= m) {       printResults();       return true;     }     if (vis[i][j]) return false;     vis[i][j] = true;     int sender = getSender(msgs[i]);     if (sender != -1 && sender == j)       return false;     else if (sender != -1) {       owners[i] = users[sender];       return solve(i + 1, sender);     }     for (int a = 0; a < users.size(); a++) {       if (!findUser(a, i) && a != j) {         owners[i] = users[a];         if (solve(i + 1, a)) return true;       }     }     return false;   }   int main() {     cin.sync_with_stdio();     int n;     cin >> n;     for (int i = 0; i < n; i++) {       users.clear();       msgs.clear();       mp.clear();       memset(vis, 0, sizeof vis);       memset(mem, -1, sizeof mem);       int t;       cin >> t;       string s;       for (int j = 0; j < t; j++) {         cin >> s;         users.push_back(s);         mp[s] = j;       }       cin >> m;       for (int j = 0; j < m + 1; j++) {         string s;         getline(cin, s);         msgs.push_back(s);       }       if (msgs[0].size() == 0) msgs.erase(msgs.begin());       int sender = getSender(msgs[0]);       if (sender != -1) {         owners[0] = users[sender];         if (!solve(1, sender)) cout <<  Impossible  << endl;       } else {         bool flag = false;         for (int j = 0; j < users.size(); j++) {           if (!findUser(j, 0)) {             owners[0] = users[j];             if (solve(1, j)) {               flag = true;               break;             }           }         }         if (!flag) cout <<  Impossible  << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   struct node {     int to, nxt, v;   } e[1000005];   queue<int> que;   int n, m, head[1000005], cnt, l, r, vis[1000005], pre[1000005], tot;   int sum, ans[1000005], ppp, minn = 1023456789, dfn[1000005], id[1000005];   inline void add(int from, int to, int v) {     e[++cnt].nxt = head[from];     head[from] = cnt;     e[cnt].to = to;     e[cnt].v = v;   }   inline int dfs(int p, int val, int fa) {     pre[p] = tot;     vis[p] = 1;     for (int i = head[p]; i; i = e[i].nxt) {       if (e[i].v > val) {         if (pre[e[i].to] == tot && !vis[e[i].to]) {           continue;         }         if ((pre[e[i].to] == tot && vis[e[i].to]) || dfs(e[i].to, val, fa))           return 1;       }     }     vis[p] = 0;     return 0;   }   inline void work(int val) {     for (int i = 1; i <= m; i++)       if (e[i].v > val) dfn[e[i].to]++;     for (int i = 1; i <= n; i++)       if (!dfn[i]) que.push(i);     while (!que.empty()) {       int u = que.front();       que.pop();       id[u] = ++sum;       for (int i = head[u]; i; i = e[i].nxt) {         if (e[i].v > val) {           dfn[e[i].to]--;           if (!dfn[e[i].to]) que.push(e[i].to);         }       }     }   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= m; i++) {       int x, y, z;       scanf( %d%d%d , &x, &y, &z);       add(x, y, z);       r = max(r, z);     }     l = 0;     int fl;     while (l < r) {       fl = 0;       tot++;       sum = 0;       int mid = (l + r) >> 1;       for (int i = 1; i <= n; i++) {         if (pre[i] != tot && dfs(i, mid, i)) {           fl = 1;           break;         }       }       if (!fl) {         r = mid;       } else {         l = mid + 1;       }     }     printf( %d  , r);     sum = 0;     work(r);     for (int i = 1; i <= n; i++) {       for (int j = head[i]; j; j = e[j].nxt) {         if (e[j].v <= r) {           if (id[e[j].to] < id[i]) {             ans[++ppp] = j;           }         }       }     }     printf( %d n , ppp);     sort(ans + 1, ans + ppp + 1);     for (int i = 1; i <= ppp; i++) printf( %d  , ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void exec() {     int n, k;     cin >> n >> k;     map<int, int> es;     for (int i = 1; i <= k + 1; i++) {       string query =  ? ;       for (int j = 1; j <= k + 1; j++) {         if (j == i) {           continue;         }         query +=     + to_string(j);       }       cout << query << endl;       int pos, a;       cin >> pos >> a;       es[a] += 1;     }     int mmax = -1;     int m = 0;     for (auto i = es.begin(); i != es.end(); ++i) {       if (mmax < i->first) {         mmax = i->first;         m = i->second;       }     }     cout.flush();     cout << ( !   + to_string(m)) << endl;   }   void solve() {     int t = 1;     for (int i = 0; i < t; i++) {       exec();     }   }   int main() {     solve();     return 0;   }