#include <bits/stdc++.h>   #pragma GCC optimize(3,  Ofast ,  inline )   using namespace std;   mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());   const long long maxn = (long long)1e6 + 5;   const long long mod = 998244353;   const long long inf = 0x3f3f3f3f;   long long T = 1;   vector<long long> v[maxn], vec[maxn];   long long dep[maxn], pre[maxn];   long long maxx;   void dfs(long long now) {     maxx = max(maxx, dep[now]);     vec[dep[now]].push_back(now);     for (auto &to : v[now]) {       if (dep[to]) continue;       pre[to] = now;       dep[to] = dep[now] + 1;       dfs(to);     }   }   void solve() {     long long n, m;     cin >> n >> m;     maxx = 1;     for (long long i = 1; i <= n; ++i) v[i].clear(), vec[i].clear(), dep[i] = 0;     for (long long i = 1; i <= m; ++i) {       long long x, y;       cin >> x >> y;       v[x].push_back(y);       v[y].push_back(x);     }     dep[1] = 1;     dfs(1);     if (maxx > (n + 1) / 2) {       cout <<  PATH n ;       stack<long long> s;       long long now = vec[maxx][0];       while (now) {         s.push(now);         now = pre[now];       }       cout << s.size() <<   n ;       while (!s.empty()) {         cout << s.top() <<    ;         s.pop();       }       cout <<   n ;       return;     }     cout <<  PAIRING n ;     long long ans = 0;     for (long long i = 1; i <= maxx; ++i) {       ans += vec[i].size() / 2;     }     cout << ans <<   n ;     for (long long i = 1; i <= maxx; ++i) {       for (long long j = 0; j + 1 < vec[i].size(); j += 2) {         cout << vec[i][j] <<     << vec[i][j + 1] <<   n ;       }     }   }   signed main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     cin >> T;     while (T--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     long long n;     cin >> n;     vector<long long> vec(n);     for (long long i = 0; i < n; i++) {       cin >> vec[i];     }     vec.push_back(vec.back());     long long ans = 1;     long long cnt = 1;     for (long long i = 1; i < n; i++) {       if (vec[i] > vec[i - 1] * 2) {         ans = max(ans, cnt);         cnt = 0;       }       cnt++;     }     ans = max(ans, cnt);     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int oo = 0x3f3f3f3f;   const double eps = 1e-9;   int main() {     int n;     scanf( %d , &n);     double inch = (double)n / 3;     int ninch = (int)inch;     if (inch - (double)ninch >= 0.5) ++ninch;     printf( %d %d n , ninch / 12, ninch % 12);     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:20000000 )   using namespace std;   int main() {     int n, m;     cin >> n >> m;     vector<string> a;     string s;     for (int i = (0); (i) < (n); (i)++) {       cin >> s;       a.push_back( #  + s +  # );     }     int x = 1;     long long r = 0;     bool g = true;     for (int i = 0; i < n - 1; i++) {       if (a[i + 1][x] ==  . ) {         r++;         continue;       }       int left = x, right = x;       int wall = 0;       bool down = false;       while (!down) {         if (g) {           if (a[i + 1][right] ==  . ) {             r += right - x + 1;             x = right;             break;           }           for (int j = right + 1;; j++) {             if (a[i][j] ==  + ) {               wall = 0;               right = j;               r += j - x;               x = j - 1;               g = false;               break;             } else if (a[i][j] ==  # ) {               wall++;               right = j - 1;               r += j - x;               x = j - 1;               g = false;               break;             } else if (a[i + 1][j] ==  . ) {               r += j - x + 1;               x = j;               down = true;               break;             }           }         } else {           if (a[i + 1][left] ==  . ) {             r += x - left + 1;             x = left;             break;           }           for (int j = left - 1;; j--) {             if (a[i][j] ==  + ) {               wall = 0;               left = j;               r += x - j;               x = j + 1;               g = true;               break;             } else if (a[i][j] ==  # ) {               wall++;               left = j + 1;               r += x - j;               x = j + 1;               g = true;               break;             } else if (a[i + 1][j] ==  . ) {               r += x - j + 1;               x = j;               down = true;               break;             }           }         }         if (wall == 2) {           cout <<  Never ;           return 0;         }       }     }     cout << r;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct node {     node *l, *r, *p;     long long v, s, z, w, t, k, i;     node(long long v, long long i)         : l(0), r(0), p(0), v(v), s(1), z(0), w(0), t(v), k(1), i(i) {}   };   inline bool is_root(node *n) {     return n->p == NULL || n->p->l != n && n->p->r != n;   }   inline bool left(node *n) { return n == n->p->l; }   inline long long size(node *n) { return n ? n->s + n->z : 0; }   inline long long tot(node *n) { return n ? n->t : 0; }   inline void push(node *n) {     n->s += n->z;     n->w += n->z;     n->k += 2 * n->z * (n->s - n->w);     if (n->l) n->l->z += n->z;     if (n->r) n->r->z += n->z;     n->z = 0;   }   inline void update(node *n) {     push(n);     n->t = tot(n->l) + tot(n->r) + n->v * (n->s - n->w);   }   inline void connect(node *n, node *p, bool l) {     (l ? p->l : p->r) = n;     if (n) n->p = p;   }   inline void rotate(node *n) {     node *p = n->p, *g = p->p;     bool l = left(n);     connect(l ? n->r : n->l, p, l);     if (!is_root(p))       connect(n, g, left(p));     else       n->p = g;     connect(p, n, !l);     update(p), update(n);   }   inline void splay(node *n) {     while (!is_root(n)) {       node *p = n->p, *g = p->p;       if (!is_root(p)) push(g);       push(p), push(n);       if (!is_root(p)) rotate(left(n) ^ left(p) ? n : p);       rotate(n);     }     push(n);   }   inline node *find_root(node *n) {     if (n == NULL) return NULL;     while (n->l) {       push(n);       n = n->l;     }     return n;   }   inline node *expose(node *n) {     node *last = NULL;     for (node *m = n; m; m = m->p) {       splay(m);       m->w = size(find_root(last));       m->r = last;       last = m;       update(m);     }     splay(n);     return last;   }   void link(node *m, node *n) {     expose(m), expose(n);     m->p = n;     n->z += size(m);   }   void cut(node *n) {     expose(n);     n->l->z -= size(n);     n->l->p = NULL;     n->l = NULL;   }   node *lca(node *m, node *n) {     expose(m);     return expose(n);   }   const int MAXN = 50005;   long long N, M, P[MAXN], A, B, ans;   char C;   node *V[MAXN];   int main() {     cin >> N;     cout << fixed << setprecision(9);     for (int i = 1; i < N; i++) {       cin >> P[i];       P[i]--;     }     for (int i = 0; i < N; i++) {       int v;       cin >> v;       V[i] = new node(v, i);       ans += v;     }     for (int i = 1; i < N; i++) {       link(V[i], V[P[i]]);       ans += 2 * tot(V[P[i]]) * size(V[i]);     }     cout << 1.0 * ans / N / N <<   n ;     cin >> M;     while (M--) {       cin >> C >> A >> B;       if (C ==  P ) {         node *v = V[A - 1], *u = V[B - 1];         if (lca(u, v) == v) swap(u, v);         expose(v);         ans -= 2 * tot(v->l) * size(v);         cut(v);         link(v, u);         ans += 2 * tot(u) * size(v);       } else {         node *v = V[A - 1];         expose(v);         update(v);         ans += (B - v->v) * v->k;         v->v = B;       }       cout << 1.0 * ans / N / N <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   constexpr int N = 3e3;   uint16_t a[N], lst[N], nxt[N], cnxt[20], dp[N][N];   int main() {     cin.tie(0), ios::sync_with_stdio(0);     int t, n;     cin >> t;     while (t--) {       cin >> n;       for (int i = 0; i < n; ++i) {         cin >> a[i], --a[i];       }       memset(lst, 0, n * sizeof *lst);       for (int i = 0; i < n; ++i) {         ++lst[a[i]];       }       int w = -1, r = 0, purged = 0;       while (r < n) {         if (w >= 0 && a[w] == a[r]) {           if (--lst[a[r++]] == 1) {             --w;             ++purged;           }         } else if (lst[a[r]] == 1) {           ++r;           ++purged;         } else {           a[++w] = a[r++];         }       }       memset(lst, -1, n * sizeof *lst);       n = w + 1;       memset(nxt, 127, n * sizeof *nxt);       for (int i = 0; i < n; ++i) {         if (lst[a[i]] != (uint16_t)-1) {           nxt[lst[a[i]]] = i;         }         lst[a[i]] = i;       }       for (int i = n - 1; i > -1; --i) {         auto* cnxte = cnxt;         for (int z = nxt[i]; z < n; z = nxt[z]) {           *cnxte++ = z;         }         *cnxte = n;         cnxte = cnxt;         for (int j = i + 1; j < n; ++j) {           if (a[j] == a[i]) {             ++cnxte;           }           int t = dp[i + 1][j] - 1;   #pragma GCC unroll 20           for (const auto* z = cnxt; z < cnxte; ++z) {             t = max(t, dp[i + 1][*z - 1] + dp[*z][j]);           }           dp[i][j] = t + 1;         }       }       cout << (n ? n - dp[0][n - 1] : 0) - 1 + purged <<   n ;       ;     }   }


#include <bits/stdc++.h>   using namespace std;   pair<int, int> seg[2100000], lazy[2100000];   pair<int, int> Merge(pair<int, int> l, pair<int, int> r) {     if (l < r)       return l;     else       return r;   }   void Propagate(int n, int l, int r) {     if (lazy[n] != make_pair(0x3f3f3f3f, 0)) {       if (l != r) {         lazy[n << 1] = Merge(lazy[n << 1], lazy[n]);         lazy[n << 1 | 1] = Merge(lazy[n << 1 | 1], lazy[n]);       }       seg[n] = Merge(seg[n], lazy[n]);       lazy[n] = make_pair(0x3f3f3f3f, 0);     }   }   pair<int, int> Update(int L, int R, pair<int, int> val, int n, int l, int r) {     Propagate(n, l, r);     if (r < L || R < l) return seg[n];     if (L <= l && r <= R) {       lazy[n] = Merge(lazy[n], val);       Propagate(n, l, r);       return seg[n];     }     int mid = l + r >> 1;     return seg[n] = Merge(Update(L, R, val, n << 1, l, mid),                           Update(L, R, val, n << 1 | 1, mid + 1, r));   }   pair<int, int> Query(int L, int R, int n, int l, int r) {     Propagate(n, l, r);     if (r < L || R < l) return make_pair(0x3f3f3f3f, 0);     if (L <= l && r <= R) return seg[n];     int mid = l + r >> 1;     return Merge(Query(L, R, n << 1, l, mid),                  Query(L, R, n << 1 | 1, mid + 1, r));   }   int N, M;   vector<pair<int, int> > v[300001];   pair<int, int> dp[300001];   int main() {     for (int i = 0; i < 2100000; i++) seg[i] = lazy[i] = make_pair(0x3f3f3f3f, 0);     ios::sync_with_stdio(0);     cin.tie(0);     cin.exceptions(ios::badbit | ios::failbit);     cin >> N >> M;     vector<int> com;     for (int i = 1; i <= M; i++) {       int n, l, r;       cin >> n >> l >> r;       r++;       v[n].push_back({l, r});       com.push_back(l);       com.push_back(r);     }     sort(com.begin(), com.end());     com.erase(unique(com.begin(), com.end()), com.end());     for (int i = 1; i <= N; i++)       for (auto &[l, r] : v[i]) {         l = lower_bound(com.begin(), com.end(), l) - com.begin();         r = lower_bound(com.begin(), com.end(), r) - com.begin();       }     for (int i = 1; i <= N; i++) {       dp[i] = {i - 1, 0};       for (auto [l, r] : v[i]) {         auto it = Query(l, r - 1, 1, 0, (int)com.size() - 1);         dp[i] = min(dp[i], make_pair(it.first + i, it.second));       }       for (auto [l, r] : v[i]) {         Update(l, r - 1, make_pair(dp[i].first - i - 1, i), 1, 0,                (int)com.size() - 1);       }     }     int res = 0x3f3f3f3f, n = 0;     for (int i = 1; i <= N; i++) {       int val = dp[i].first + (N - i);       if (res > val) res = val, n = i;     }     set<int> s;     for (int i = 1; i <= N; i++) s.insert(i);     while (n) {       s.erase(n);       n = dp[n].second;     }     cout << res <<   n ;     if (res) {       for (int i : s) cout << i <<    ;       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n, x;     cin >> n >> x;     long long count = 0;     if (n >= x) {       for (long long i = 1; i < n + 1; i++) {         if (x % i == 0) {           count++;         }       }     } else {       for (long long i = 2; i < n + 1; i++) {         if (x % i == 0 && ((x / i) <= n)) {           count++;         }       }     }     cout << count;   }


#include <bits/stdc++.h>   using namespace std;   void show_trace() { cout << endl; }   template <typename Start, typename... Rem>   void show_trace(Start S, Rem... R) {     cout <<     << S;     show_trace(R...);   }   const int INFi = 2139062143;   const long long INF = 1e18;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     string s, t;     cin >> s >> t;     int ct1 = count(s.begin(), s.end(),  a ) + count(t.begin(), t.end(),  a );     int ct2 = count(s.begin(), s.end(),  b ) + count(t.begin(), t.end(),  b );     if (ct1 % 2 != 0 || ct2 % 2 != 0) {       cout << -1 <<   n ;       return 0;     }     vector<int> ab, ba;     for (int i = 0; i < n; i++) {       if (s[i] == t[i]) continue;       if (s[i] ==  a  && t[i] ==  b )         ab.push_back(i);       else         ba.push_back(i);     }     int sz1 = ab.size();     int sz2 = ba.size();     vector<pair<int, int> > ans;     for (int i = 1; i < sz1 - (sz1 % 2); i += 2) {       ans.push_back({ab[i], ab[i - 1]});     }     for (int i = 1; i < sz2 - (sz2 % 2); i += 2) {       ans.push_back({ba[i], ba[i - 1]});     }     assert(sz1 % 2 == sz2 % 2);     if (sz1 % 2) {       ans.push_back({ab[sz1 - 1], ab[sz1 - 1]});       ans.push_back({ab[sz1 - 1], ba[sz2 - 1]});     }     cout << ans.size() <<   n ;     for (auto [x, y] : ans) cout << x + 1 <<     << y + 1 <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     long long n;     cin >> n;     string s;     cin >> s;     vector<string> all;     for (long long i = 0; i <= 9; i++) {       all.push_back(s);       for (char &c : s)         if (c ==  9 )           c =  0 ;         else           c++;     }     string ans = s;     for (string &x : all) {       for (long long i = 0; i < n; i++) {         string y = x;         rotate(y.begin(), y.begin() + y.size() - i, y.end());         ans = min(y, ans);       }     }     cout << ans <<   n ;   }   void solve(bool testcase) {     long long t;     cin >> t;     while (t--) solve();   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long double a[100009][2];   long double maxi(long double a, long double b) {     if (a > b)       return a;     else       return b;   }   bool solve(long double mid, int n, long double p) {     long double req = 0;     for (int i = 0; i < n; i++) {       req += maxi(0.00, mid * a[i][0] - a[i][1]);     }     if (req > mid * p)       return false;     else       return true;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     long double n, p, sum = 0, count = 0, m, flag = 0, ans = 0, k;     cin >> n >> p;     long double l = 0, r = 1e10;     for (int i = 0; i < n; i++) {       cin >> a[i][0] >> a[i][1];     }     while (flag < 1000) {       long double m = (l + r) / 2;       if (solve(m, n, p))         ans = m, l = m;       else         r = m;       flag++;     }     if (ans >= 1e10) {       cout << -1;       return 0;     }     cout << setprecision(8) << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void FREOPEN() {}   inline double Time() { return (clock() * 1.0) / CLOCKS_PER_SEC; }   const int N = (int)2000, inf = (int)2e9, MOD = (int)1e9 + 7, alph = 26;   char CH[N];   const long long INF = (long long)1e18;   const int dx[] = {1, -1, 0, 0, -1, 1, -1, 1};   const int dy[] = {0, 0, 1, -1, -1, 1, 1, -1};   const int dp[] = {8, 9, 1, 13, 3, 12, 7, 5, 0, 2, 4, 11, 6, 10, 15, 14};   int a[N][N];   int main() {     FREOPEN();     int n;     cin >> n;     int num = 0;     for (int bi = 0; bi < n; bi += 4) {       for (int bj = 0; bj < n; bj += 4) {         for (int i = bi; i < bi + 4; i++) {           for (int j = bj; j < bj + 4; j++) {             int p = (i - bi) * 4 + (j - bj);             a[i][j] = (dp[p] ^ num);           }         }         num += 16;       }     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) printf( %d  , a[i][j]);       printf(  n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2000000 + 7;   const int M = 26;   const int mod = 999983;   const int inf = 1e9 + 7;   const double pi = acos(-1);   const int maxn = N * 2;   const double PI = acos(-1);   int n, m;   int a[N];   int dp[22][N];   string s;   void solve() {     cin >> n >> m;     for (int i = (0); i < (n); i++) {       cin >> s;       for (int j = (0); j < (m); j++) {         int u = s[j] -  0 ;         a[j] = (a[j] << 1) | u;       }     }     for (int i = (0); i < (m); i++) {       dp[0][a[i]]++;     }     for (int k = (1); k < (n + 1); k++) {       for (int mask = (0); mask < (1 << n); mask++) {         if (k >= 2) dp[k][mask] = (k - 2 - n) * dp[k - 2][mask];         for (int p = (0); p < (n); p++) dp[k][mask] += dp[k - 1][mask ^ (1 << p)];         dp[k][mask] /= k;       }     }     int ans = inf;     for (int mask = (0); mask < (1 << n); mask++) {       int cur = 0;       for (int k = (0); k < (n + 1); k++) cur += min(k, n - k) * dp[k][mask];       ans = min(ans, cur);     }     cout << ans;   }   int main() {     int T = 1;     for (int i = (1); i < (T + 1); i++) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   char s[2005];   char p[505];   int dp[2005][2005];   int len[2005];   int main() {     scanf( %s , s);     scanf( %s , p);     int len_s = strlen(s);     int len_p = strlen(p);     for (int i = 0; i < len_s; i++) {       int tot = i;       if (s[i] != p[0]) {         len[i] = -1;         continue;       }       for (int j = 0; j < len_p; j++) {         while (tot < len_s && s[tot] != p[j]) tot++;         tot++;       }       if (tot >= len_s + 1)         len[i] = -1;       else         len[i] = tot - 1;     }     for (int i = 0; i <= len_s; i++)       for (int j = 0; j <= len_s; j++) dp[i][j] = 0x3f3f3f3f;     dp[0][0] = 0;     int all = len_s / len_p;     len[len_s] = -1;     for (int i = 0; i <= len_s; i++) {       if (i) {         for (int j = 0; j <= all; j++) dp[i][j] = min(dp[i][j], dp[i - 1][j]);       }       if (len[i] != -1) {         for (int j = 0; j <= all; j++) {           dp[len[i] + 1][j + 1] =               min(dp[len[i] + 1][j + 1], dp[i][j] + len[i] - i + 1 - len_p);         }       }     }     int temp = 1;     while (dp[len_s][temp] <= 2000 &&            dp[len_s][temp] - dp[len_s][temp - 1] >= 0 && temp <= all) {       for (int i = 0; i < dp[len_s][temp] - dp[len_s][temp - 1]; i++)         printf( %d  , temp - 1);       temp++;     }     temp -= 1;     int a = len_s - temp * len_p - dp[len_s][temp] + 1;     while (a > 0 && a--) printf( %d  , temp);     for (int i = temp * len_p - 1; i >= 0; i--) {       printf( %d  , i / len_p);     }   }


#include <bits/stdc++.h>   using namespace std;   long long input[100000], n, output, table[100000], a, tlg, go, high, lg;   int main(int argc, char** argv) {     int i, j, k;     while (scanf(  %d , &n) == 1) {       output = 0;       lg = 1;       tlg = 1;       scanf(  %d , &input[0]);       for (i = 1; i < n; i++) {         scanf(  %d , &a);         if (a != input[lg - 1]) {           input[lg] = a;           lg++;         }       }       table[0] = input[0];       input[lg] = 1000000000;       for (i = 1; i < lg; i++) {         if ((input[i] < input[i - 1] && input[i] < input[i + 1]) ||             (input[i] > input[i - 1] && input[i] > input[i + 1])) {           table[tlg] = input[i];           tlg++;         }       }       table[tlg] = 1000000000;       high = table[0];       for (i = 0; i < tlg; i++) {         if (table[i] > table[i + 1] && table[i + 1] < table[i + 2]) {           if (high > table[i + 2]) {             output += table[i + 2] - table[i + 1];             i++;           } else {             output += high - table[i + 1];             high = table[i + 2];             i++;           }         } else {           high = table[i + 1];         }       }       cout << output << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 333333;   const long long mod = 1000000009ll;   int n, m;   struct node {     int l, r;     long long sum, f1, f2;   } t[N * 6];   long long a[N], F[N];   inline long long read() {     long long x = 0;     char c = getchar();     while (!isdigit(c)) c = getchar();     while (isdigit(c)) {       x = x * 10ll + c -  0 ;       c = getchar();     }     return x;   }   void calc_Fibonacci(int n) {     F[1] = 1;     F[2] = 1;     for (int i = (3); i <= (N); i++) F[i] = (F[i - 1] + F[i - 2]) % mod;   }   long long calc(long long a, long long b, long long n) {     if (n == 1)       return a;     else if (n == 2)       return b;     else       return (a * F[n - 2] % mod + b * F[n - 1] % mod) % mod;   }   long long calc_range(long long a, long long b, long long n) {     if (n == 1)       return a;     else if (n == 2)       return (a + b) % mod;     else       return (calc(a, b, n + 2) - b + mod) % mod;   }   void build(int x, int l, int r) {     int mid = (l + r) / 2, lc = x * 2, rc = x * 2 + 1;     t[x].l = l;     t[x].r = r;     if (l == r) {       t[x].sum = a[l];       t[x].f1 = t[x].f2 = 0;       return;     }     build(lc, l, mid);     build(rc, mid + 1, r);     t[x].sum = (t[lc].sum + t[rc].sum) % mod;     t[x].f1 = t[x].f2 = 0;   }   void pushdown(int x) {     int l = t[x].l, r = t[x].r;     int mid = (l + r) / 2, lc = x * 2, rc = x * 2 + 1;     t[lc].f1 = (t[lc].f1 + t[x].f1) % mod;     t[lc].f2 = (t[lc].f2 + t[x].f2) % mod;     t[lc].sum += calc_range(t[x].f1, t[x].f2, mid - l + 1);     t[lc].sum %= mod;     t[rc].f1 = (t[rc].f1 + calc(t[x].f1, t[x].f2, mid - l + 2)) % mod;     t[rc].f2 = (t[rc].f2 + calc(t[x].f1, t[x].f2, mid - l + 3)) % mod;     t[rc].sum += calc_range(t[x].f1, t[x].f2, r - l + 1) -                  calc_range(t[x].f1, t[x].f2, mid - l + 1);     t[rc].sum = (t[rc].sum + mod) % mod;     t[x].f1 = t[x].f2 = 0;   }   void update(int x, int l, int r, int ql, int qr) {     int mid = (l + r) / 2, lc = x * 2, rc = x * 2 + 1;     if (l >= ql && r <= qr) {       t[x].f1 = (t[x].f1 + F[l - ql + 1]) % mod;       t[x].f2 = (t[x].f2 + F[l - ql + 2]) % mod;       t[x].sum += calc_range(F[l - ql + 1], F[l - ql + 2], r - l + 1);       t[x].sum %= mod;       return;     }     pushdown(x);     if (ql <= mid) update(lc, l, mid, ql, qr);     if (qr > mid) update(rc, mid + 1, r, ql, qr);     t[x].sum = (t[lc].sum + t[rc].sum) % mod;     return;   }   long long query(int x, int l, int r, int ql, int qr) {     int mid = (l + r) / 2, lc = x * 2, rc = x * 2 + 1;     if (l >= ql && r <= qr) return t[x].sum;     pushdown(x);     long long ans_left = 0, ans_right = 0;     if (ql <= mid) ans_left = query(lc, l, mid, ql, qr);     if (qr > mid) ans_right = query(rc, mid + 1, r, ql, qr);     return (ans_left + ans_right) % mod;   }   int main() {     n = read();     m = read();     calc_Fibonacci(n);     for (int i = (1); i <= (n); i++) a[i] = read();     build(1, 1, n);     for (int i = (1); i <= (m); i++) {       int tag, l, r;       tag = read();       l = read();       r = read();       if (tag == 1)         update(1, 1, n, l, r);       else         printf( %lld n , query(1, 1, n, l, r));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int M = 100000 + 10;   int a[M];   vector<int> ans[M];   int main() {     int n, k;     cin >> n >> k;     for (int i = 0; i < n; i++) {       cin >> a[i];     }     sort(a, a + n);     int num = 0;     while (num < k) {       for (int i = n; i >= 0 && num < k; i--) {         for (int j = 0; j < i; j++) {           for (int x = n - 1; x >= i; x--) {             ans[num].push_back(a[x]);           }           ans[num].push_back(a[j]);           num++;           if (num == k) {             break;           }         }       }     }     for (int i = 0; i < num; i++) {       cout << ans[i].size() <<    ;       for (int j = 0; j < ans[i].size(); j++) {         cout << ans[i][j] <<    ;       }       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int Pow(int x, int y, int mod) {     long long t = x, r = 1;     for (; y; y >>= 1, t = t * t % mod) y& 1 ? r = r * t % mod : 0;     return r;   }   inline int Get() {     int res = 0, q = 1;     char ch = getchar();     while ((ch <  0  || ch >  9 ) && ch !=  - ) ch = getchar();     if (ch ==  - ) q = -1, ch = getchar();     while (ch >=  0  && ch <=  9 ) res = res * 10 + ch -  0 , ch = getchar();     return res * q;   }   const double eps = 1e-12, pi = M_PI;   const int oo = (int)2.1e9, mod = (int)1e9 + 7;   const long long INF = (long long)1e17;   const int N = 110;   int n;   int dp[N][3];   int a[N];   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) scanf( %d , a + i);     dp[1][0] = 1;     dp[1][1] = a[1] == 1 || a[1] == 3 ? 0 : oo;     dp[1][2] = a[1] == 2 || a[1] == 3 ? 0 : oo;     for (int i = 2; i <= n; ++i) {       dp[i][0] = min(min(dp[i - 1][0], dp[i - 1][1]), dp[i - 1][2]) + 1;       if (a[i] == 1 || a[i] == 3)         dp[i][1] = min(dp[i - 1][0], dp[i - 1][2]);       else         dp[i][1] = oo;       if (a[i] == 2 || a[i] == 3)         dp[i][2] = min(dp[i - 1][0], dp[i - 1][1]);       else         dp[i][2] = oo;     }     printf( %d n , min(dp[n][0], min(dp[n][1], dp[n][2])));     return 0;   }


#include <bits/stdc++.h>   long long n, i, j, h, k, t, d;   long double a, m, b;   using namespace std;   long double pow(long double a, long long b) {     if (b == 0) return 1;     if (b == 1) return a;     long double t = pow(a, b / 2);     t = t * t;     if (b % 2 == 0)       return t;     else       return t * a;   }   int main() {     cin >> m >> n;     a = m;     for (i = 1; i < m; i++) {       b = i / m;       a -= pow(b, n);     }     cout << a;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 10;   int main() {     ios::sync_with_stdio(false);     int _;     cin >> _;     while (_--) {       int n;       cin >> n;       int ans = 1e9 + 10;       for (int i = 1; i * i <= n; i++) {         int res = i - 1 + ceil(1.0 * n / (1.0 * i)) - 1;         ans = min(res, ans);       }       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int cycle;   vector<int> adj[26], topo;   int color[26];   void dfs(int i) {     color[i] = 1;     for (auto nx : adj[i])       if (!color[nx])         dfs(nx);       else if (color[nx] == 1)         cycle = 1;     topo.push_back(i);     color[i] = 2;   }   int main() {     int n;     scanf( %d , &n);     string a[110];     for (int i = 0; i < n; i++) {       cin >> a[i];     }     if (n == 1) {       for (char c =  a ; c <=  z ; c++) {         cout << c;       }       return 0;     }     for (int i = 1; i < n; i++) {       int flag = 0;       for (int j = 0; j < (int)min(a[i - 1].size(), a[i].size()); j++) {         if (a[i - 1][j] != a[i][j]) {           adj[a[i - 1][j] -  a ].push_back(a[i][j] -  a );           flag = 1;           break;         }       }       if (!flag && a[i - 1].size() > a[i].size()) {         puts( Impossible );         return 0;       }     }     for (int i = 0; i < 26; i++) {       if (!color[i]) dfs(i);     }     if (cycle) {       puts( Impossible );       return 0;     }     reverse(topo.begin(), topo.end());     for (auto x : topo) cout << char(x +  a );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, ans, col[1000005], flag[1000005], tot, res[1000005];   int k = 1, la[1000005], ff[1000005 * 2], check[1000005], pre[1000005], pos,       del[1000005];   int cnt, f[1000005], g[1000005];   struct node {     int a, b;   } e[1000005 * 2];   map<pair<int, int>, int> MAP;   void add(int a, int b) {     e[++k] = (node){a, b};     ff[k] = la[a];     la[a] = k;     e[++k] = (node){b, a};     ff[k] = la[b];     la[b] = k;   }   void dfs(int x, int fa) {     check[x] = flag[x] = 1;     col[x] = -col[fa];     for (int a = la[x]; a; a = ff[a]) {       if (e[a].b == fa) continue;       if (!check[e[a].b]) {         pre[e[a].b] = a;         dfs(e[a].b, x);         f[x] += f[e[a].b];         g[x] += g[e[a].b];         continue;       }       if (col[e[a].b] == col[x]) {         if (flag[e[a].b]) {           if (!cnt) pos = a;           cnt++;           f[x]++;         } else           f[x]--;       } else {         if (flag[e[a].b])           g[x]++;         else           g[x]--;       }     }     flag[x] = 0;   }   int main() {     int a, b;     scanf( %d%d , &n, &m);     for (int i = 1; i <= m; i++) {       scanf( %d%d , &a, &b), add(a, b);       int num = MAP[make_pair(a, b)];       if (num) del[i] = 1, del[num] = 1;       MAP[make_pair(a, b)] = i;     }     col[0] = 1;     for (int i = 1; i <= n; i++)       if (!check[i]) dfs(i, 0);     if (!cnt)       for (int i = 1; i <= m; i++) res[++tot] = i;     else {       if (cnt == 1 && !del[pos >> 1]) res[++tot] = (pos >> 1);       for (int i = 1; i <= n; i++) {         if (f[i] == cnt && !g[i] && !del[pre[i] >> 1])           if (!pre[i]) {             for (int a = la[i]; a; a = ff[a])               if (e[a].b == i && !del[a >> 1]) res[++tot] = (a >> 1);           } else             res[++tot] = (pre[i] >> 1);       }     }     sort(res + 1, res + tot + 1);     tot = unique(res + 1, res + tot + 1) - res - 1;     printf( %d n , tot);     for (int i = 1; i < tot; i++) printf( %d  , res[i]);     if (tot) printf( %d n , res[tot]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int who(int n) {     if (n < 5) {       return n;     } else {       n -= 5;       return who(n / 2);     }   }   int main(int argc, char** argv) {     int n, m;     cin >> n >> m;     vector<vector<char> > snake(n, vector<char>(m,  # ));     for (int i = 1; i < n; i += 2) {       for (int j = (i / 2) % 2; j < m - 1 + (i / 2) % 2; ++j) {         snake[i][j] =  . ;       }     }     for (int i = 0; i < n; ++i) {       for (int j = 0; j < m; ++j) {         cout << snake[i][j];       }       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5, K = 4;   vector<int> g[N];   set<int> s;   int a[N];   int get_index(const vector<int> x) {     static map<vector<int>, int> m;     static int cnt;     if (m.find(x) == m.end()) m[x] = cnt++;     return m[x];   }   void dfs_pre(int u, int fa) {     vector<int> x;     for (int v : g[u])       if (v != fa) {         dfs_pre(v, u);         x.push_back(a[v]);       }     sort(x.begin(), x.end());     a[u] = get_index(x);   }   void dfs(int u, int fa) {     vector<int> x;     if (g[u].size() < K) {       for (int v : g[u]) x.push_back(a[v]);       sort(x.begin(), x.end());       s.insert(get_index(x));     }     sort(g[u].begin(), g[u].end(), [](int x, int y) { return a[x] < a[y]; });     x.clear();     for (int i = 1; i < g[u].size(); i++) x.push_back(a[g[u][i]]);     int t = a[u];     for (int i = 0; i < g[u].size(); i++) {       if (g[u][i] != fa) {         a[u] = get_index(x);         dfs(g[u][i], u);       }       if (i < g[u].size() - 1) x[i] = a[g[u][i]];     }     a[u] = t;   }   int main() {     ios::sync_with_stdio(false);     int n;     cin >> n;     for (int i = 0; i < n - 1; i++) {       int x, y;       cin >> x >> y;       x--, y--;       g[x].push_back(y);       g[y].push_back(x);     }     dfs_pre(0, -1);     dfs(0, -1);     cout << s.size() << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     int a[] = {1, 2, 3, 4, 6, 12};     int b[] = {12, 6, 4, 3, 2, 1};     cin >> t;     while (t--) {       string s;       cin >> s;       int ans[20];       int count = 0, n = 0, no;       for (int i = 0; i < 6; i++) {         for (int j = 0; j < b[i]; j++) {           no = 0;           for (int k = 0; k < a[i]; k++) {             if (s[j + k * b[i]] !=  X ) {               no = 1;               break;             }           }           if (!no) {             ans[count++] = i;             n++;             break;           }         }       }       cout << n <<    ;       for (int i = 0; i < n; i++) {         cout << a[ans[i]] <<  x  << b[ans[i]] <<    ;       }       cout << endl;     }   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   #pragma GCC optimize( unroll-loops )   using namespace std;   const int arr = 2e5 + 10;   const int ar = 2e3 + 10;   const long double pi = acos(-1);   const long double eps = 1e-10;   const long long md = 1e9 + 7;   vector<int> reb1[arr];   vector<int> reb2[arr];   bool use[arr];   int comp[arr];   const int M = 70 / 4 + 1;   int dist[1ll << M][71];   void dfs(int now, int c) {     comp[now] = c;     use[now] = 1;     for (auto wh : reb1[now]) {       if (!use[wh]) {         dfs(wh, c);       }     }   }   int main() {     int n, m, a, b;     cin >> n >> m >> a >> b;     for (int i = 0; i < m; i++) {       int u, v, c;       cin >> u >> v >> c;       if (c == a) {         reb1[u].push_back(v);         reb1[v].push_back(u);       }       if (c == b) {         reb2[u].push_back(v);         reb2[v].push_back(u);       }     }     int c = 0;     int cc = 1e5;     for (int i = 1; i <= n; i++) {       if (!use[i]) {         dfs(i, ++c);         int cnt = 0;         for (int j = 1; j <= n; j++) {           if (comp[j] == c) {             cnt++;           }         }         if (cnt <= 3) {           for (int j = 1; j <= n; j++) {             if (comp[j] == c) {               comp[j] = cc;             }           }           cc--;           c--;         }       }     }     set<pair<int, pair<int, int>>> s;     int start_mask = 0;     if (comp[1] <= c) {       start_mask |= (1ll << (comp[1] - 1));     }     for (int m = 0; m < (1ll << c); m++) {       for (int j = 1; j <= n; j++) {         if (j == 1 && m == start_mask) {           dist[m][j] = 0;         } else {           dist[m][j] = 2e9 + 1;         }         s.insert(make_pair(dist[m][j], make_pair(m, j)));       }     }     function<bool(int, int)> have_bit = [&](int m, int bit) {       return m & (1ll << bit);     };     while (!s.empty()) {       pair<int, int> now = s.begin()->second;       s.erase(s.begin());       for (auto wh : reb1[now.second]) {         if (comp[wh] > c || comp[now.second] == comp[wh] ||             !have_bit(now.first, comp[wh] - 1)) {           int to_m = now.first | (comp[wh] > c ? 0 : (1ll << (comp[wh] - 1)));           if (dist[to_m][wh] > dist[now.first][now.second] + a) {             s.erase(make_pair(dist[to_m][wh], make_pair(to_m, wh)));             dist[to_m][wh] = dist[now.first][now.second] + a;             s.insert(make_pair(dist[to_m][wh], make_pair(to_m, wh)));           }         }       }       for (auto wh : reb2[now.second]) {         if ((comp[wh] > c || !have_bit(now.first, comp[wh] - 1)) &&             (comp[wh] != comp[now.second])) {           int to_m = now.first | (comp[wh] > c ? 0 : (1ll << (comp[wh] - 1)));           if (dist[to_m][wh] > dist[now.first][now.second] + b) {             s.erase(make_pair(dist[to_m][wh], make_pair(to_m, wh)));             dist[to_m][wh] = dist[now.first][now.second] + b;             s.insert(make_pair(dist[to_m][wh], make_pair(to_m, wh)));           }         }       }     }     for (int j = 1; j <= n; j++) {       int ans = 2e9 + 1;       for (int m = 0; m < (1ll << c); m++) {         ans = min(ans, dist[m][j]);       }       cout << ans <<    ;     }     cout <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   vector<pair<long long, long long> > v;   bool cmp(pair<long long, long long> a, pair<long long, long long> b) {     if (a.first == b.first) a.second < b.second;     return a.first > b.first;   }   int main() {     long long t, n, arr[200005], brr[200005], i;     cin >> t;     while (t--) {       cin >> n;       for (i = 0; i < n; i++) cin >> arr[i];       for (i = 0; i < n; i++) cin >> brr[i];       for (i = 0; i < n; i++) v.push_back({arr[i], brr[i]});       sort(v.begin(), v.end(), cmp);       long long self = 0;       long long deli = v[0].first;       long long mx = max(self, deli);       long long mn = deli;       for (i = 1; i < n; i++) {         self += v[i - 1].second;         deli = v[i].first;         mx = max(self, deli);         mn = min(mn, mx);       }       mn = min(mn, self + v[n - 1].second);       cout << mn << endl;       v.clear();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, s;     cin >> n >> s;     int a[n + 1];     int b[n + 1];     bool isCrossable = false;     for (int i = 1; i <= n; i++) cin >> a[i];     for (int i = 1; i <= n; i++) cin >> b[i];     if (a[1] == 0 || (a[s] == 0 && b[s] == 0)) {       cout <<  NO ;       return 0;     }     for (int i = 1; i <= n; i++) {       if (i >= s && a[i] == 1 && b[i] == 1) isCrossable = true;     }     if (a[s]) {       cout <<  YES ;       return 0;     }     if (b[s] && isCrossable) {       cout <<  YES ;       return 0;     }     cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct interval {     int l, r;     bool operator<(const interval &t) const { return r < t.r; }   };   set<interval> itree[20];   set<interval>::iterator l, r;   long long ans;   long long f(int type, int num) {     return (1LL << type) * ((num + 1LL) * num) / 2;   }   void add(int type, int pos, int val) {     interval unit = {pos, pos};     l = r = itree[type].lower_bound(unit);     if (val == 0) {       if (r->l <= pos && pos <= r->r) {         interval new_left = {r->l, pos - 1}, new_right = {pos + 1, r->r};         ans -= f(type, (r->r) - (r->l) + 1);         ans += f(type, new_left.r - new_left.l + 1);         ans += f(type, new_right.r - new_right.l + 1);         itree[type].erase(r);         if (new_left.l <= new_left.r) itree[type].insert(new_left);         if (new_right.l <= new_right.r) itree[type].insert(new_right);       }     } else {       if (r->l <= pos && pos <= r->r) {         return;       }       if (!itree[type].empty()) {         if (l != itree[type].begin() && (--l)->r == pos - 1) {           unit.l = l->l;           ans -= f(type, l->r - l->l + 1);           itree[type].erase(l);         }         if (r != itree[type].end() && r->l == pos + 1) {           unit.r = r->r;           ans -= f(type, r->r - r->l + 1);           itree[type].erase(r);         }       }       itree[type].insert(unit);       ans += f(type, unit.r - unit.l + 1);     }   }   int main() {     int n, m;     cin >> n >> m;     for (int i = 1; i <= n; ++i) {       int a;       cin >> a;       for (int j = 0; j < 20; ++j) {         if (a % 2 != 0) add(j, i, a % 2);         a /= 2;       }     }     for (int i = 0; i < m; ++i) {       int pos, val;       cin >> pos >> val;       for (int j = 0; j < 20; ++j) {         add(j, pos, val % 2);         val /= 2;       }       cout << ans <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       long long n, a, b;       cin >> a >> b >> n;       if (n % 2 == 0)         cout << (n / 2) * (a - b) << endl;       else         cout << ((n / 2) * (a - b)) + a << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2000005;   long long n, L, t;   long long K;   long long a[maxn];   double ans;   int main() {     scanf( %I64d%I64d%I64d , &n, &L, &t);     t += t;     K = t / L;     t = t - L * K;     ans += 0.25 * (double)K * n * (n - 1);     for (int i = 1; i <= n; i++) scanf( %I64d , &a[i]), a[i + n] = a[i];     for (int i = 1; i <= n; i++) {       int l = i, r = i + n - 1;       while (l < r) {         int mid = (l + r + 1) / 2;         if (mid > n) {           if (L - a[i] + a[mid] <= t)             l = mid;           else             r = mid - 1;         } else {           if (a[mid] - a[i] <= t)             l = mid;           else             r = mid - 1;         }       }       ans += 0.25 * (l - i);     }     printf( %lf n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     cin.tie(nullptr);     ios::sync_with_stdio(false);     int n;     cin >> n;     vector<int> a(n);     set<int> s;     int g = 0;     for (int i = 0; i < n; i++) {       cin >> a[i];       g ^= a[i];       s.insert(a[i]);     }     if (n == 3) {       printf( YES n );       printf( 1 n );       printf( 1 2 3 n );       return 0;     }     if (n % 2 == 0 and g > 0) {       printf( NO n );       return 0;     }     if (n % 2 == 0) {       printf( YES n );       vector<pair<int, pair<int, int>>> v;       for (int i = 1;; i += 2) {         if (i + 2 > n) break;         v.push_back(make_pair(i, make_pair(i + 1, i + 2)));       }       for (int i = 1;; i += 2) {         if (i + 3 == n) break;         v.push_back(make_pair(i, make_pair(i + 1, n)));       }       printf( %d n , v.size());       for (auto p : v) {         printf( %d %d %d n , p.first, p.second.first, p.second.second);       }       return 0;     } else {       printf( YES n );       vector<pair<int, pair<int, int>>> v;       for (int i = 1;; i += 2) {         if (i + 2 > n) break;         v.push_back(make_pair(i, make_pair(i + 1, i + 2)));       }       for (int i = 1;; i += 2) {         if (i + 2 == n) break;         v.push_back(make_pair(i, make_pair(i + 1, n)));       }       printf( %d n , v.size());       for (auto p : v) {         printf( %d %d %d n , p.first, p.second.first, p.second.second);       }       return 0;     }   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1100;   int N, M;   int WX, WY, BX, BY;   int wdist[MAXN][MAXN];   int wprev[MAXN][MAXN];   int bdist[MAXN][MAXN];   int bprev[MAXN][MAXN];   int xc[8] = {-2, 2, -1, 1, -2, 2, -1, 1};   int yc[8] = {-1, -1, -2, -2, 1, 1, 2, 2};   bool is_white;   void await() {     int nx, ny;     cin >> nx >> ny;     if (nx == -1) exit(0);     if (is_white) {       BX = nx;       BY = ny;     } else {       WX = nx;       WY = ny;     }   }   void wsolve(int sx, int sy) {     wdist[sx][sy] = 0;     wprev[sx][sy] = -1;     vector<pair<int, int> > q;     q.push_back(make_pair(sx, sy));     for (int i = 0; i < q.size(); i++) {       int cx = q[i].first, cy = q[i].second;       int cdist = wdist[cx][cy];       for (int j = 0; j < 8; j++) {         int x = cx + xc[j], y = cy + yc[j];         if (x < 1 || y < 1 || x > N || y > M) continue;         if (wdist[x][y] <= cdist + 1) continue;         wdist[x][y] = cdist + 1;         wprev[x][y] = j;         q.push_back(make_pair(x, y));       }     }   }   void bsolve(int sx, int sy) {     bdist[sx][sy] = 0;     bprev[sx][sy] = -1;     vector<pair<int, int> > q;     q.push_back(make_pair(sx, sy));     for (int i = 0; i < q.size(); i++) {       int cx = q[i].first, cy = q[i].second;       int cdist = bdist[cx][cy];       for (int j = 0; j < 8; j++) {         int x = cx + xc[j], y = cy + yc[j];         if (x < 1 || y < 1 || x > N || y > M) continue;         if (bdist[x][y] <= cdist + 1) continue;         bdist[x][y] = cdist + 1;         bprev[x][y] = j;         q.push_back(make_pair(x, y));       }     }   }   bool wwin(int bmove) {     int wturns = wdist[WX][WY];     int wblock = bdist[WX][WY];     int bturns = bdist[BX][BY];     int bblock = wdist[BX][BY];     if (bmove) {       if (bturns <= wturns) {         if (bturns < wblock) return false;         if (bturns % 2 == wblock % 2) return true;         return false;       } else {         if (wturns < bblock - 1) return true;         if (wturns % 2 != bblock % 2) return false;         return true;       }     } else {       if (wturns <= bturns) {         if (wturns < bblock) return true;         if (wturns % 2 == bblock % 2) return false;         return true;       } else {         if (bturns < wblock - 1) return false;         if (bturns % 2 != wblock % 2) return true;         return false;       }     }   }   int main() {     cin >> N >> M >> WX >> WY >> BX >> BY;     for (int i = 0; i < MAXN; i++)       for (int j = 0; j < MAXN; j++) wdist[i][j] = bdist[i][j] = 1e9;     wsolve(N / 2, M / 2);     bsolve(N / 2 + 1, M / 2);     if (wwin(0)) {       is_white = true;       cout <<  WHITE n ;     } else {       is_white = false;       cout <<  BLACK n ;       await();     }     while (true) {       int bloc = -1, bturns = 1e9;       for (int i = 0; i < 8; i++) {         if (is_white) {           WX += xc[i];           WY += yc[i];           if (WX >= 1 && WX <= N && WY >= 1 && WY <= M) {             if (wwin(1)) {               if (wdist[WX][WY] < bturns) {                 bturns = wdist[WX][WY];                 bloc = i;               }             }           }           WX -= xc[i];           WY -= yc[i];         } else {           BX += xc[i];           BY += yc[i];           if (BX >= 1 && BX <= N && BY >= 1 && BY <= M) {             if (!wwin(0)) {               if (bdist[BX][BY] < bturns) {                 bturns = bdist[BX][BY];                 bloc = i;               }             }           }           BX -= xc[i];           BY -= yc[i];         }       }       if (is_white) {         WX += xc[bloc];         WY += yc[bloc];         cout << WX <<     << WY <<   n  << flush;       } else {         BX += xc[bloc];         BY += yc[bloc];         cout << BX <<     << BY <<   n  << flush;       }       if (is_white && WX == N / 2 && WY == M / 2) break;       if (!is_white && BX == N / 2 + 1 && BY == M / 2) break;       if (WX == BX && WY == BY) break;       await();     }   }


#include <bits/stdc++.h>   using namespace std;   void Read(int &x) {     char c;     while (c = getchar(), c != EOF)       if (c >=  0  && c <=  9 ) {         x = c -  0 ;         while (c = getchar(), c >=  0  && c <=  9 ) x = x * 10 + c -  0 ;         ungetc(c, stdin);         return;       }   }   int n, a, b;   stack<int> s;   bool dfs(long long now) {     if (now > b) return 0;     if (now == b) {       s.push(b);       return 1;     }     if (dfs(now << 1)) {       s.push(now);       return 1;     }     if (dfs(now * 10 + 1)) {       s.push(now);       return 1;     }     return 0;   }   int main() {     Read(a), Read(b);     if (dfs(a)) {       puts( YES );       printf( %u n , s.size());       while (!s.empty()) {         printf( %d  , s.top());         s.pop();       }     } else       puts( NO );   }


#include <bits/stdc++.h>   using namespace std;   int main() {     cin.tie(0);     cout.tie(0);     ios_base::sync_with_stdio(0);     int t;     cin >> t;     while (t--) {       long long l, r;       cin >> l >> r;       cout << l <<     << l * 2 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   pair<long long, int> ar[200003 + 2];   long long DP[200003 + 2][2];   long long n;   long long dp(int i, bool fl) {     if (i == n + 1) {       if (fl == 0) return 0;       return 2e18;     }     if (i > n + 1) return 2e18;     long long &ret = DP[i][fl];     if (ret != -1) return ret;     ret = 2e18;     if (fl == 0)       ret = min(ret, -ar[i].first + dp(i + 2, 1));     else {       ret = min(ret, dp(i + 1, 1));       ret = min(ret, +ar[i].first + dp(i + 1, 0));     }     return ret;   }   int team[200003 + 2];   long long res;   int cnt = 0;   void print(int i, bool fl) {     if (i == n + 1) return;     if (fl == 0) {       res += ar[i].first;       team[ar[i].second] = ++cnt;       team[ar[i + 1].second] = cnt;       print(i + 2, 1);     } else {       long long kop = dp(i + 1, 1);       if (kop == res) {         team[ar[i].second] = cnt;         print(i + 1, 1);       } else {         team[ar[i].second] = cnt;         res -= ar[i].first;         print(i + 1, 0);       }     }   }   int main() {     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> ar[i].first;       ar[i].second = i;     }     sort(ar + 1, ar + n + 1);     memset(DP, -1, sizeof DP);     res = dp(1, 0);     long long ans = res;     print(1, 0);     cout << ans <<     << cnt << endl;     for (int i = 1; i <= n; i++) {       if (i > 1) cout <<    ;       cout << team[i];     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, h;     cin >> n >> h;     double s = 1.0 * h / n;     double t = s;     for (int i = 0; i < n - 1; i++) {       double ans = sqrt(1.0 * s * h);       s += t;       printf( %.12llf n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n, k;     cin >> n >> k;     string s;     cin >> s;     map<char, int> m;     for (int i = 0; i < s.size(); i++) {       m[s[i]]++;     }     char a =  A ;     bool flag1 = true;     for (int i = 1; i < k; i++) {       if (m[a] == 0) {         flag1 = false;         break;       }       a++;     }     bool flag = false;     for (int i = 0; i < s.size(); i++) {       if (a == s[i]) {         flag = true;         break;       }     }     int c = 999999;     if (flag == true && flag1 == true) {       for (auto x : m) {         if (x.second < c) {           c = x.second;         }       }       cout << c * k;     } else {       cout <<  0 ;     }   }


#include <bits/stdc++.h>   using namespace std;   set<int> inT;   set<int>::iterator it;   int ans[300000];   vector<int> pak;   int main() {     int n, m, l, r, x, i;     cin >> n >> m;     for (i = 0; i < n; i++) {       inT.insert(i);     }     for (i = 0; i < m; i++) {       cin >> l >> r >> x;       l--;       r--;       x--;       it = inT.lower_bound(l);       while (it != inT.end()) {         if (*it > r) break;         if (*it != x) {           pak.push_back(*it);           ans[*it] = x + 1;         }         it++;       }       for (x = 0; x < pak.size(); x++) inT.erase(pak[x]);       pak.clear();     }     for (i = 0; i < n; i++) cout << ans[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ld = long double;   using cd = complex<double>;   const int max_n = 200500;   vector<int> g[max_n];   vector<int> og[max_n];   vector<int> used(max_n);   bool find_cycles(int x) {     used[x] = 1;     for (int i : g[x]) {       if (used[i] == 1) {         return true;       }       if (!used[i] && find_cycles(i)) {         return true;       }     }     used[x] = 2;     return false;   }   vector<int> ts;   void top_sort(int x) {     used[x] = 1;     for (int i : g[x]) {       if (!used[i]) {         top_sort(i);       }     }     ts.push_back(x);   }   vector<int> dp1(max_n);   void calc_dp1(int x) {     used[x] = 1;     dp1[x] = x;     for (int i : og[x]) {       if (!used[i]) {         calc_dp1(i);       }       dp1[x] = min(dp1[x], dp1[i]);     }   }   vector<int> dp2(max_n);   void calc_dp2(int x) {     used[x] = 1;     dp2[x] = x;     for (int i : g[x]) {       if (!used[i]) {         calc_dp2(i);       }       dp2[x] = min(dp2[x], dp2[i]);     }   }   int main() {     cout.precision(20);     cout << fixed;     ios_base::sync_with_stdio(0);     cin.tie(0);     int n, m;     cin >> n >> m;     for (int i = 0; i < m; i++) {       int a, b;       cin >> a >> b;       g[a].push_back(b);       og[b].push_back(a);     }     for (int i = 1; i <= n; i++) {       if (!used[i]) {         if (find_cycles(i)) {           cout << -1;           return 0;         }       }     }     fill(used.begin(), used.end(), 0);     for (int i = 1; i <= n; i++) {       if (!used[i]) {         top_sort(i);       }     }     reverse(ts.begin(), ts.end());     fill(used.begin(), used.end(), 0);     for (int i = 0; i < n; i++) {       if (!used[ts[i]]) {         calc_dp1(ts[i]);       }     }     fill(used.begin(), used.end(), 0);     for (int i = 0; i < n; i++) {       if (!used[ts[i]]) {         calc_dp2(ts[i]);       }     }     int cnt = 0;     for (int i = 1; i <= n; i++) {       cnt += dp1[i] == i && dp2[i] == i;     }     cout << cnt <<   n ;     for (int i = 1; i <= n; i++) {       cout << (dp1[i] == i && dp2[i] == i ?  A  :  E );     }   }


#include <bits/stdc++.h>   using namespace std;   int x[2][2];   int main() {     for (int i = 0; i < 2; i++)       for (int j = 0; j < 2; j++) scanf( %d , x[i] + j);     printf( %d n ,            (max(1, abs(x[0][0] - x[1][0])) + max(1, abs(x[0][1] - x[1][1])) + 2) *                2);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, k;   int c[5005], h[11], f[505];   int cnt[100005];   int fcnt[100005];   int cache[5005][505];   int solve(int idx1, int idx2) {     if (idx1 == 0 || idx2 == 0) return 0;     int &ret = cache[idx1][idx2];     if (ret != -1) return ret;     ret = 0;     for (int i = 0; i <= k && i <= idx1; i++)       ret = max(ret, solve(idx1 - i, idx2 - 1) + h[i]);     return ret;   }   int main() {     scanf( %d%d , &n, &k);     for (int i = 0; i < n * k; i++) {       scanf( %d , &c[i]);       cnt[c[i]]++;     }     for (int i = 0; i < n; i++) {       scanf( %d , &f[i]);       fcnt[f[i]]++;     }     for (int i = 1; i <= k; i++) scanf( %d , &h[i]);     int ans = 0;     for (int i = 0; i < 100005; i++) {       if (fcnt[i]) {         memset(cache, -1, sizeof(cache));         ans += solve(cnt[i], fcnt[i]);       }     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int const mxn = 1e3 + 10;   vector<pair<int, int> > ha[3], adj0[mxn][mxn], adj1[mxn][mxn];   int mark[mxn][mxn][3], fl[mxn][mxn][3];   int n, m;   int ans = 1e9;   string l[mxn];   void connect(int i, int j, int i2, int j2) {     if (i2 < 0 or i2 >= n or j2 < 0 or j2 >= m)       return;     else {       if (l[i2][j2] ==  . )         adj1[i][j].push_back({i2, j2});       else if (l[i2][j2] !=  # )         adj0[i][j].push_back({i2, j2});     }   }   int main() {     cin >> n >> m;     for (int i = 0; i < n; i++) cin >> l[i];     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (l[i][j] ==  1  or l[i][j] ==  2  or l[i][j] ==  3 ) {           ha[l[i][j] -  1 ].push_back({i, j});         }         connect(i, j, i + 1, j);         connect(i, j, i - 1, j);         connect(i, j, i, j + 1);         connect(i, j, i, j - 1);       }     }     for (int now = 0; now <= 2; now++) {       queue<pair<int, int> > q;       for (int i = 0; i < ha[now].size(); i++) {         q.push(ha[now][i]);         fl[ha[now][i].first][ha[now][i].second][now] = 0;         mark[ha[now][i].first][ha[now][i].second][now] = 1;       }       while (q.size()) {         int v1, v2;         v1 = q.front().first, v2 = q.front().second;         q.pop();         queue<pair<int, int> > q0;         q0.push({v1, v2});         while (q0.size()) {           int a1, a2;           a1 = q0.front().first, a2 = q0.front().second;           q0.pop();           for (int j = 0; j < adj0[a1][a2].size(); j++) {             int u1 = adj0[a1][a2][j].first, u2 = adj0[a1][a2][j].second;             if (!mark[u1][u2][now]) {               q0.push({u1, u2});               q.push({u1, u2});               mark[u1][u2][now] = 1;               fl[u1][u2][now] = fl[v1][v2][now];             }           }         }         for (int j = 0; j < adj1[v1][v2].size(); j++) {           int k1 = adj1[v1][v2][j].first, k2 = adj1[v1][v2][j].second;           if (!mark[k1][k2][now]) {             mark[k1][k2][now] = 1;             q.push({k1, k2});             fl[k1][k2][now] = fl[v1][v2][now] + 1;           }         }       }     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (l[i][j] ==  .  and mark[i][j][0] and mark[i][j][1] and mark[i][j][2])           ans = min(ans, (fl[i][j][0] + fl[i][j][2] + fl[i][j][1]) - 2);         else if (l[i][j] !=  #  and mark[i][j][0] and mark[i][j][1] and                  mark[i][j][2])           ans = min(ans, fl[i][j][0] + fl[i][j][2] + fl[i][j][1]);       }     }     if (ans == 1e9)       cout << -1;     else       cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   struct custom_hash {     static uint64_t splitmix64(uint64_t x) {       x += 0x9e3779b97f4a7c15;       x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;       x = (x ^ (x >> 27)) * 0x94d049bb133111eb;       return x ^ (x >> 31);     }     size_t operator()(uint64_t x) const {       static const uint64_t FIXED_RANDOM =           chrono::steady_clock::now().time_since_epoch().count();       return splitmix64(x + FIXED_RANDOM);     }   };   long long getPairsCount(int arr[], int n, long long sum) {     unordered_map<int, int, custom_hash> m;     for (int i = 0; i < n; i++) m[arr[i]]++;     long long twice_count = 0;     for (int i = 0; i < n; i++) {       twice_count += m[sum - arr[i]];       if (sum - arr[i] == arr[i]) twice_count--;     }     return twice_count / 2;   }   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       int ara[n];       long long sum = 0;       for (int i = 0; i < n; i++) {         cin >> ara[i];         sum += ara[i];       }       sum *= 2;       if (sum % n) {         cout <<  0 n ;         continue;       }       cout << getPairsCount(ara, n, sum / n) << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const pair<int, int> MOD = make_pair(1e9 + 7, 1e9 + 9);   const int base = 1e6 + 3;   const int N = 1e5 + 100, B = 600;   pair<int, int> operator+(pair<int, int> a, pair<int, int> b) {     return make_pair((a.first + b.first) % MOD.first,                      (a.second + b.second) % MOD.second);   }   pair<int, int> operator-(pair<int, int> a, pair<int, int> b) {     return make_pair((a.first - b.first + MOD.first) % MOD.first,                      (a.second - b.second + MOD.second) % MOD.second);   }   pair<int, int> operator*(pair<int, int> a, int x) {     return make_pair(1ll * a.first * x % MOD.first,                      1ll * a.second * x % MOD.second);   }   pair<int, int> operator*(pair<int, int> a, pair<int, int> b) {     return make_pair(1ll * a.first * b.first % MOD.first,                      1ll * a.second * b.second % MOD.second);   }   int n, K, q;   int a[N];   vector<pair<int, int>> open_Hash[B], close_Hash[B];   pair<int, int> base_pow[N], inv_pow[N];   int good[N];   int bm(int b, int p, int m) {     if (p == 0) return 1;     int t = bm(b, p / 2, m);     t = 1ll * t * t % m;     if (p & 1) return 1ll * b * t % m;     return t;   }   void pre() {     base_pow[0] = {1, 1};     inv_pow[0] = {1, 1};     for (int i = 1; i < N; i++) {       base_pow[i] = base_pow[i - 1] * base;       inv_pow[i].first = bm(base_pow[i].first, MOD.first - 2, MOD.first);       inv_pow[i].second = bm(base_pow[i].second, MOD.second - 2, MOD.second);     }   }   bool recal(int l, int r, vector<pair<int, int>> &close,              vector<pair<int, int>> &open) {     vector<int> stk;     for (int i = l; i <= r; i++) {       if (a[i] < 0 && stk.size() > 0 && stk.back() == abs(a[i]))         stk.pop_back();       else         stk.push_back(a[i]);     }     close.clear();     open.clear();     bool pos = false;     for (int i = 0; i < stk.size(); i++) {       if (stk[i] > 0) pos = true;       if (stk[i] < 0 && pos) return false;     }     for (int i = 0; i < stk.size(); i++) {       if (stk[i] > 0) break;       int x = abs(stk[i]);       int kth = close.size();       close.push_back(base_pow[kth] * x);     }     for (int i = 1; i < close.size(); i++) {       close[i] = close[i - 1] + close[i];     }     for (int i = (int)stk.size() - 1; i >= 0; i--) {       if (stk[i] < 0) break;       int x = abs(stk[i]);       int kth = open.size();       open.push_back(base_pow[kth] * x);     }     for (int i = 1; i < open.size(); i++) {       open[i] = open[i - 1] + open[i];     }     return true;   }   bool find_hash(vector<pair<int, int>> &all_open, int sz, pair<int, int> hhh) {     assert(sz > 0);     int psz = 0;     pair<int, int> h = {0, 0};     while (psz < sz && all_open.size() > 0) {       auto t = all_open.back();       all_open.pop_back();       int which_block = t.first, idx = t.second;       int cur_sz = open_Hash[which_block].size() - idx;       assert(cur_sz > 0);       if (cur_sz + psz < sz) {         pair<int, int> hh =             (open_Hash[which_block].back() -              (idx > 0 ? open_Hash[which_block][idx - 1] : make_pair(0, 0))) *             inv_pow[idx];         hh = hh * base_pow[psz];         h = h + hh;         psz += cur_sz;       } else {         int lage = sz - psz;         pair<int, int> hh =             (open_Hash[which_block][idx + lage - 1] -              (idx > 0 ? open_Hash[which_block][idx - 1] : make_pair(0, 0))) *             inv_pow[idx];         hh = hh * base_pow[psz];         h = h + hh;         if (idx + lage < open_Hash[which_block].size())           all_open.push_back({which_block, idx + lage});         psz += lage;       }     }     if (psz < sz) return 0;     if (hhh != h) return 0;     return 1;   }   int query(int l, int r) {     int bl = l / B, br = r / B;     if (bl == br) {       vector<pair<int, int>> p, s;       int x = recal(l, r, p, s);       if (x && (int)p.size() == 0 && (int)s.size() == 0) return 1;       return 0;     }     if (recal(l, (bl + 1) * B - 1, close_Hash[B - 2], open_Hash[B - 2]) == 0)       return 0;     if (close_Hash[B - 2].size() > 0) return 0;     vector<pair<int, int>> all_open;     if (open_Hash[B - 2].size() > 0) all_open.push_back({B - 2, 0});     for (int b = bl + 1; b < br; b++) {       if (!good[b]) return 0;       if (close_Hash[b].size() == 0) {         if (open_Hash[b].size() > 0) all_open.push_back({b, 0});         continue;       }       int sz = close_Hash[b].size();       if (!find_hash(all_open, sz, close_Hash[b].back())) return 0;       if (open_Hash[b].size() > 0) all_open.push_back({b, 0});     }     if (recal(br * B, r, close_Hash[B - 1], open_Hash[B - 1]) == 0) return 0;     if (open_Hash[B - 1].size() > 0) return 0;     if (close_Hash[B - 1].size() > 0 &&         !find_hash(all_open, close_Hash[B - 1].size(), close_Hash[B - 1].back()))       return 0;     if (all_open.size() > 0) return 0;     return 1;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     pre();     cin >> n >> K;     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 0, j = 0; i < n; i += B, j++) {       good[j] = recal(i, min(i + B - 1, n - 1), close_Hash[j], open_Hash[j]);     }     int q;     cin >> q;     while (q--) {       int t;       cin >> t;       if (t == 1) {         int idx, x;         cin >> idx >> x;         idx--;         a[idx] = x;         int b = idx / B;         int l = b * B, r = min(l + B - 1, n - 1);         good[b] = recal(l, r, close_Hash[b], open_Hash[b]);       } else {         int l, r;         cin >> l >> r;         l--, r--;         if (query(l, r))           cout <<  Yes  << endl;         else           cout <<  No  << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   template <typename X>   inline bool minimize(X& p, X q) {     if (p <= q) return 0;     p = q;     return 1;   }   template <typename X>   inline bool maximize(X& p, X q) {     if (p >= q) return 0;     p = q;     return 1;   }   const int MAXN = 100005;   int Ya[MAXN], Yb[MAXN], L[MAXN];   inline double dis(int dx, int dy) {     return sqrt(1.0 * dx * dx + 1.0 * dy * dy);   }   int main() {     int N, M, a, b;     scanf( %d%d%d%d , &N, &M, &a, &b);     for (int i = 1; i <= N; ++i) scanf( %d , Ya + i);     for (int i = 1; i <= M; ++i) scanf( %d , Yb + i);     for (int i = 1; i <= M; ++i) scanf( %d , L + i);     double ans = 1e100;     int ap = 1, bp = 1;     for (int i = 1, j = 1; i <= M; ++i) {       int temp = ceil((double)a * Yb[i] / b);       while (j < N && Ya[j] < temp) ++j;       if (minimize(ans, dis(a, Ya[j]) + dis(b - a, Yb[i] - Ya[j]) + L[i]))         ap = j, bp = i;       if (j != 1 &&           minimize(ans, dis(a, Ya[j - 1]) + dis(b - a, Yb[i] - Ya[j - 1]) + L[i]))         ap = j - 1, bp = i;     }     printf( %d %d n , ap, bp);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline bool chkmin(T &x, T y) {     return y < x ? x = y, 1 : 0;   }   template <class T>   inline bool chkmax(T &x, T y) {     return x < y ? x = y, 1 : 0;   }   inline long long Max(long long x, long long y) { return x > y ? x : y; }   inline long long Min(long long x, long long y) { return x < y ? x : y; }   int n, m;   long long dp[2002][2002];   void Add(long long &x, long long y) {     x += y;     if (x >= 1000000007) x %= 1000000007;     if (x < 0) (x += 1000000007) %= 1000000007;   }   int main() {     scanf( %d%d , &n, &m);     for (int i = (1), i_end_ = (n); i <= i_end_; i++) dp[i][1] = 1;     for (int k = (2), k_end_ = (m); k <= k_end_; k++)       for (int i = (1), i_end_ = (n); i <= i_end_; i++)         for (int j = i; j <= n; j += i) Add(dp[j][k], dp[i][k - 1]);     long long ans = 0;     for (int i = (1), i_end_ = (n); i <= i_end_; i++) Add(ans, dp[i][m]);     printf( %I64d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long t, t0, t2, x, x2;   void cmp(long double &temp, long long &o, long long &o2, long long y,            long long y2) {     if (y2 > x2) return;     long double newTemp = (1.0 * t * y + t2 * y2) / (y + y2);     if (newTemp < t0) return;     if (newTemp > temp + 1e-9) return;     if (newTemp < temp || y + y2 > o + o2) o = y, o2 = y2, temp = newTemp;   }   int main() {     cin >> t >> t2 >> x >> x2 >> t0;     if (t0 == t2) {       if (t != t0)         cout << 0 <<     << x2 << endl;       else         cout << x <<     << x2 << endl;     } else if (t0 == t)       cout << x <<     << 0 << endl;     else {       long double temp = 1e9;       long long o = 0, o2 = 0;       cmp(temp, o, o2, 0, x2);       cmp(temp, o, o2, x, 0);       for (long long y = 0; y <= x; y++) {         long long y2 = (y * (t0 - t) + t2 - t0 - 1) / (t2 - t0);         cmp(temp, o, o2, y, y2);       }       cout << o <<     << o2 << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using pii = pair<int, int>;   using pll = pair<ll, ll>;   using vpii = vector<pii>;   using vpll = vector<pll>;   template <typename T>   ostream &operator<<(ostream &os, const vector<T> &v) {     for (const auto &x : v) os << x <<    ;     return os << endl;   }   ll ceil_div(ll a, ll b) { return (a + b - 1) / b; }   void solve(int n) {     if (n == 1) {       cout << -1 << endl;       return;     }     for (int i = 0; i < n; i++) {       cout << (i == 0 ? 2 : 3);     }     cout << endl;   }   int main(int argc, char const *argv[]) {     int T;     cin >> T;     for (int t = 0; t < T; t++) {       int n;       cin >> n;       solve(n);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   #define cp ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);   #define ll long long int     #define vint vector<int>   #define vllint vector<ll>   #define pair_int pair<int , int>   #define pair_ll_int pair<ll , ll>   #define vector_of_pair_int vector<pair_int>   #define pb push_back    #define test_case int t; cin>>t; while(t--)   #define umap unordered_map <int,int>    #define mapint map<int,int>   #define infinity 1000000000   #define mp make_pair      int main()    {     cp              test_case       {          ll n;          cin>>n;             if(n<=256)          {            int count=0;                    ll temp=n;            while(temp!=1)            {             count++;             if(temp%2==0)              temp=temp/2;             else              temp=temp/2+1;            }               cout<<count+n-3<<endl;                       for (int i = 1; i <=n-3; ++i)            {             /* code */              cout<<3+i-1<<   <<3+i<<endl;            }               for (int i = 0; i < count; ++i)            {             /* code */             cout<<n<<   <<2<<endl;            }                                     }          else          {            int count=0;                    ll temp=n;            while(temp!=1)            {             count++;                          temp=ceil(float(temp)/float(16));            }               cout<<count+n<<endl;                        for (int i = 3; i <n; ++i)            {             /* code */                if(i!=16)                {                 cout<<i<<   <<i+1<<endl;                }               }                           for (int i = 0; i < count; ++i)            {             /* code */             cout<<n<<   <<16<<endl;            }                        for (int i = 0; i < 4; ++i)            {             /* code */             cout<<16<<   <<2<<endl;            }                                 }       }          return 0;    }


#include <bits/stdc++.h>   using namespace std;   const int N = 205;   int mem[N][N];   int asol[N];   bool query(int i, int j) {     i = asol[i];     j = asol[j];     if (mem[i][j] != -1) return mem[i][j];     if (i == j) return false;     cout <<  ?   << i <<     << j << endl;     char c;     cin >> c;     mem[i][j] = (c ==  < );     mem[j][i] = !mem[i][j];     return mem[i][j];   }   int main() {     int t;     cin >> t;     while (t--) {       memset(mem, -1, sizeof mem);       int n;       cin >> n;       for (int i = 1; i <= 2 * n; i++) asol[i] = i;       shuffle(asol + 1, asol + 2 * n + 1, mt19937(23232));       vector<int> worse;       for (int i = 1; i < 2 * n; i += 2) {         if (query(i, i + 1))           worse.push_back(i);         else           worse.push_back(i + 1);       }       sort(worse.begin(), worse.end(), query);       int xx = worse.back();       worse.pop_back();       int yy = worse.back();       vector<int> choto, boro;       for (int i = 1; i <= 2 * n; i++) {         if (i == yy) continue;         if (query(yy, i))           boro.push_back(i);         else           choto.push_back(i);       }       if (boro.size() <= n) {         sort(choto.begin(), choto.end(), query);         cout <<  !  << endl;       } else {         int xxpr = (xx % 2 ? xx + 1 : xx - 1);         vector<int> worse;         if (query(xx, xxpr))           worse.push_back(xx);         else           worse.push_back(xxpr);         int unpaired = -1;         for (int x : boro) {           if (x == xx || x == xxpr) continue;           if (unpaired == -1)             unpaired = x;           else {             if (query(unpaired, x))               worse.push_back(unpaired);             else               worse.push_back(x);             unpaired = -1;           }         }         if (unpaired != -1) worse.push_back(unpaired);         sort(worse.begin(), worse.end(), query);         cout <<  !  << endl;       }     }   }


#include <bits/stdc++.h>      using namespace std;      int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int tt;     cin >> tt;     while(tt--) {       int n;       cin >> n;       vector<int> a(n);       for(int i = 0; i < n; i++) {         cin >> a[i];       }       set<int> s;       s.insert(a[0]);       bool ok = true;       for(int i = 1; i < n; i++) {         int x = min(a[i], a[i - 1]);         int y = max(a[i], a[i - 1]);         if(s.upper_bound(x) != s.end()) {           if(*s.upper_bound(x) < y) {             ok = false;             break;           }         }         s.insert(a[i]);       }       cout << (ok ?  YES  :  NO ) <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a[3];     int x[3];     int last = 0;     cin >> a[0] >> a[1] >> a[2];     cin >> x[0] >> x[1] >> x[2];     for (int i = 0; i < 3; ++i) {       int t = a[i] - x[i];       if (t > 0) t /= 2;       last += t;     }     if (last < 0)       cout <<  No n ;     else       cout <<  Yes n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double EPS = -1e8;   const double Pi = acos(-1);   bool inline equ(double a, double b) { return fabs(a - b) < EPS; }   int _R(int& x) { return scanf( %d , &x); }   int _R(long long& x) { return scanf( %  PRId64, &x); }   int _R(double& x) { return scanf( %lf , &x); }   int _R(char* s) { return scanf( %s , s); }   int R() { return 0; }   template <typename T1, typename... T2>   int R(T1& x, T2&... tail) {     int tmp = _R(x);     return tmp + R(tail...);   }   template <typename Iter, typename F>   inline void out(Iter s, Iter e, F of) {     bool flag = 0;     for (Iter it = s; it != e; it++) {       if (flag)         printf(   );       else         flag = 1;       of(*it);     }     puts(  );   }   const int MAXN = 1e5 + 10;   struct Edge {     int u, v;     long long c;     bool operator<(const Edge& e) const { return c < e.c; }   };   int n, m;   Edge es[MAXN * 2];   struct DSJ {     int mom[MAXN], sz[MAXN];     void init() {       for (int i = (1); i <= (n); i++) mom[i] = i;     }     int find(int x) { return mom[x] = mom[x] == x ? x : find(mom[x]); }     void merge(int a, int b) {       a = find(a), b = find(b);       mom[b] = a;     }   } dsj;   struct Tree {     static const int LOG = 22;     vector<pair<int, int> > g[MAXN];     int dep[MAXN];     int mom[LOG][MAXN], mx[LOG][MAXN];     int sz[MAXN], root[MAXN];     inline void adde(Edge& e) {       g[e.u].push_back(pair<int, int>(e.v, e.c));       g[e.v].push_back(pair<int, int>(e.u, e.c));     }     void dfs(int u, int p, int c, int d, int rt) {       mom[0][u] = p;       mx[0][u] = c;       dep[u] = d;       root[u] = rt;       for (pair<int, int> e : g[u]) {         int v, tc;         tie(v, tc) = e;         if (v == p) continue;         dfs(v, u, tc, d + 1, rt);       }     }     inline void predo() {       for (int i = (1); i <= (n); i++)         if (!dep[i]) {           dfs(i, -1, 0, 1, i);         }       for (int j = (1); j <= (LOG - 1); j++)         for (int i = (1); i <= (n); i++) {           mom[j][i] = mom[j - 1][mom[j - 1][i]];           mx[j][i] = max(mx[j - 1][i], mx[j - 1][mom[j - 1][i]]);         }       for (int i = (1); i <= (n); i++) sz[root[i]]++;     }     inline int lca(int a, int b) {       if (dep[a] < dep[b]) swap(a, b);       int jmp = dep[a] - dep[b];       for (int k = 0; k < (LOG); k++)         if ((jmp >> k) & 1) a = mom[k][a];       if (a == b) return a;       for (int k = (LOG - 1); k >= (0); k--)         if (mom[k][a] != mom[k][b]) {           a = mom[k][a];           b = mom[k][b];         }       return mom[0][a];     }     inline int qry(int a, int b) {       int anc = lca(a, b);       int res = 0;       {         int jmp = dep[a] - dep[anc];         for (int k = 0; k < (LOG); k++)           if ((jmp >> k) & 1) {             res = max(res, mx[k][a]);             a = mom[k][a];           }       }       {         int jmp = dep[b] - dep[anc];         for (int k = 0; k < (LOG); k++)           if ((jmp >> k) & 1) {             res = max(res, mx[k][b]);             b = mom[k][b];           }       }       return res;     }   } tree;   int main() {     R(n, m);     for (int i = (1); i <= (m); i++) R(es[i].u, es[i].v, es[i].c);     sort(es + 1, es + 1 + m);     long long mst_cst = 0ll;     dsj.init();     for (int i = (1); i <= (m); i++) {       Edge& e = es[i];       if (dsj.find(e.u) != dsj.find(e.v)) {         dsj.merge(e.u, e.v);         mst_cst += e.c;         tree.adde(e);       }     }     tree.predo();     int q;     R(q);     while (q--) {       int a, b;       R(a, b);       if (tree.root[a] == tree.root[b]) {         if (tree.sz[tree.root[a]] < n)           puts( -1 );         else           printf( %I64d n , mst_cst - tree.qry(a, b));       } else {         if (tree.sz[tree.root[a]] + tree.sz[tree.root[b]] < n)           puts( -1 );         else           printf( %I64d n , mst_cst);       }     }   }


#include <bits/stdc++.h>   using namespace std;   #define rep(i, a, b) for(int i = a; i < b; ++i)      int debug = 0;      const int N = 510;      int n, p[N], a[N][N];      int main() {       cin >> n;       rep(i, 1, n + 1) {           cin >> p[i];       }       rep(i, 1, n + 1) {           int x = i, y = i;           rep(_, 0, p[i]) {               a[x][y] = p[i];               if (y > 1 && a[x][y - 1] == 0) {                   --y;               } else {                   ++x;               }           }       }       rep(i, 1, n + 1) {           rep(j, 1, i + 1) {               cout << a[i][j] <<    ;           }           cout <<   n ;       }   }


#include <bits/stdc++.h>   using namespace std;   long long getmax(long long arr[]) {     long long m = 0;     for (long long i = 0; i < 26; i++) {       m = max(m, arr[i]);     }     return m;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long n, m;     cin >> n >> m;     string arr[n];     long long alpha[26];     long long res = 0;     for (long long i = 0; i < n; i++) cin >> arr[i];     long long marks[m];     for (long long i = 0; i < m; i++) cin >> marks[i];     for (long long i = 0; i < m; i++) {       memset(alpha, 0, sizeof(alpha));       for (long long j = 0; j < n; j++) {         int k = arr[j][i] -  A ;         alpha[k]++;       }       long long c = getmax(alpha);       res += c * marks[i];     }     cout << res <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   struct ee {     int d;     int y;   };   ee e[120];   ee r[1200];   bool ok(ee a, ee b) { return a.y > b.y; }   int main() {     int n;     int k;     while (cin >> n >> k) {       memset(e, 0, sizeof(e));       memset(r, 0, sizeof(r));       for (int i = 0; i < n; i++) {         cin >> e[i].y;         e[i].d = i + 1;       }       sort(e, e + n, ok);       int m = 0, m2 = 0;       int ss;       for (int i = 0; i < k; i++) {         ss = e[0].y - e[n - 1].y;         if (ss <= 1) {           break;         }         e[0].y--;         e[n - 1].y++;         r[i].d = e[0].d;         r[i].y = e[n - 1].d;         sort(e, e + n, ok);         m++;         if (ss > e[0].y - e[n - 1].y) {           m2 = m;           ss = e[0].y - e[n - 1].y;         }       }       cout << ss <<     << m2 << endl;       for (int i = 0; i < m2; i++) {         cout << r[i].d <<     << r[i].y << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, i, j, k, l, tot, ans, v;   long long o, p;   long long f[110010];   struct rec {     long long x, y;   } a[100010];   bool cmp(rec x, rec y) { return x.x < y.x || ((x.x == y.x) && (x.y < y.y)); }   int find(int k, int l, long long x) {     while (k < l) {       int mid = (k + l) / 2;       if (f[mid] <= x)         k = mid + 1;       else         l = mid;     }     return k;   }   int main() {     cin >> n;     for (i = 0; i < n; i++) {       scanf( %I64d%I64d , &a[i].x, &a[i].y);     }     cin >> v;     for (i = 0; i < n; i++) {       o = a[i].x;       p = a[i].y;       a[i].x = -o + p * v;       a[i].y = o + p * v;     }     sort(a, a + n, cmp);     tot = 1;     f[0] = -1e12, f[1] = 1e12;     for (i = 0; i < n; i++) {       j = find(0, tot, a[i].y);       if (f[j] > a[i].y) f[j] = a[i].y;       if (j >= tot) f[++tot] = 1e12;     }     ans = tot - 1;     f[tot = 1] = 1e12;     for (i = 0; i < n; i++)       if ((a[i].x >= 0) && (a[i].y >= 0)) {         j = find(0, tot, a[i].y);         if (f[j] > a[i].y) f[j] = a[i].y;         if (j >= tot) f[++tot] = 1e12;       }     printf( %d %d n , tot - 1, ans);     cin >> n;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   int a[100000];   int main() {     int n, k;     cin >> n >> k;     int sum = 0;     bool ok = false;     vector<int> ans;     for (int i = 0; i < n; i++) {       cin >> a[i];       sum += a[i];     }     if (sum % k != 0) {       printf( No n );     } else {       sum /= k;       int temp = 0;       int cnt = 0;       for (int i = 0; i < n; i++) {         temp += a[i];         cnt++;         if (temp > sum) {           printf( No n );           ok = true;           break;         } else if (temp == sum) {           temp = 0;           ans.push_back(cnt);           cnt = 0;         }       }       if (!ok) {         printf( Yes n );         for (int i = 0; i < ans.size(); i++) {           if (i > 0) printf(   );           printf( %d , ans[i]);         }         printf(  n );       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int SIZE = 2100;   struct kstr {     int C[30];     bool mask[110];   } A[SIZE];   int CC[30];   int main() {     int K, N, len;     char S[110];     cin >> K >> S >> N;     len = strlen(S);     for (int i = 0; i != len; i++) CC[S[i] -  a ]++;     for (int i = 0; i != K; i++) {       for (int j = 0; j != len; j++) A[i].mask[j] = true;       for (int j = 0; j != 30; j++) A[i].C[j] = CC[j];     }     int a;     char ch;     while (N--) {       cin >> a >> ch;       int sumch = 0;       for (int i = 0; i != K; i++)         if (sumch + A[i].C[ch -  a ] >= a) {           a -= sumch;           A[i].C[ch -  a ]--;           for (int j = 0; j != len; j++) {             if (S[j] == ch && A[i].mask[j]) a--;             if (!a) {               A[i].mask[j] = false;               break;             }           }           break;         } else           sumch += A[i].C[ch -  a ];     }     for (int i = 0; i != K; i++)       for (int j = 0; j != len; j++)         if (A[i].mask[j]) cout << S[j];     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<pair<int, int> > v[100000];   int f[100000];   int d[100000];   void dfs(int x) {     int i;     for (i = 0; i < v[x].size(); i++) {       if (f[v[x][i].first] == 0) {         d[v[x][i].first] = d[x] + v[x][i].second;         f[v[x][i].first] = 1;         dfs(v[x][i].first);       }     }   }   int main() {     int n, i, j;     long long sum = 0;     scanf( %d , &n);     for (i = 0; i < n - 1; i++) {       int x, y, w;       scanf( %d %d %d , &x, &y, &w);       v[x - 1].push_back(make_pair(y - 1, w));       v[y - 1].push_back(make_pair(x - 1, w));       sum += w * 2;     }     f[0] = 1;     dfs(0);     sort(d, d + n);     sum -= d[n - 1];     printf( %I64d n , sum);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void fast_io() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }   long long r(long long num, long long den) {     if (den == 1)       return num;     else if (num == 1)       return den;     if (num > den)       return num / den + r(num % den, den);     else       return den / num + r(num, den % num);   }   void solve() {     long long a, b;     cin >> a >> b;     cout << r(a, b) << endl;   }   int main() {     fast_io();     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline void pisz(int n) { printf( %d n , n); }   const int fx[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};   const int fxx[8][2] = {{0, 1}, {0, -1}, {1, 0},  {-1, 0},                          {1, 1}, {1, -1}, {-1, 1}, {-1, -1}};   template <typename T, typename TT>   ostream& operator<<(ostream& s, pair<T, TT> t) {     return s <<  (  << t.first <<  ,  << t.second <<  ) ;   }   template <typename T>   ostream& operator<<(ostream& s, vector<T> t) {     for (int i = 0; i < ((int)((t).size())); i++) s << t[i] <<    ;     return s;   }   int main() {     int n;     string A;     int cursor;     cin >> n >> cursor >> A;     cursor--;     n--;     cursor = min(cursor, n - cursor);     int middle = n / 2;     int leftmost = cursor, rightmost = cursor;     for (int i = cursor; i <= middle; i++)       if (A[i] != A[n - i]) rightmost = i;     for (int i = cursor; i >= 0; i--)       if (A[i] != A[n - i]) leftmost = i;     int vertical_moves = 0;     for (int i = leftmost; i <= rightmost; i++)       vertical_moves += min(abs(A[i] - A[n - i]), 26 - abs(A[i] - A[n - i]));     int horizontal_moves = min((cursor - leftmost) + (rightmost - leftmost),                                (rightmost - cursor) + (rightmost - leftmost));     int total_moves = horizontal_moves + vertical_moves;     cout << total_moves;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const int MXN = 1e3 + 7;   const int mod = 998244353;   int n, m;   int ar[MXN][MXN];   int br[MXN];   struct lp {     int m, v;   } A[MXN][MXN], B[MXN][MXN];   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= m; ++j) scanf( %d , &ar[i][j]);     }     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= m; ++j) {         br[j] = ar[i][j];       }       sort(br + 1, br + 1 + m);       int k = unique(br + 1, br + 1 + m) - br - 1;       for (int j = 1; j <= m; ++j) {         A[i][j].m = k;         A[i][j].v = lower_bound(br + 1, br + 1 + k, ar[i][j]) - br;       }     }     for (int i = 1; i <= m; ++i) {       for (int j = 1; j <= n; ++j) {         br[j] = ar[j][i];       }       sort(br + 1, br + 1 + n);       int k = unique(br + 1, br + 1 + n) - br - 1;       for (int j = 1; j <= n; ++j) {         B[j][i].m = k;         B[j][i].v = lower_bound(br + 1, br + 1 + k, ar[j][i]) - br;       }     }     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= m; ++j) {         int t = abs(A[i][j].v - B[i][j].v);         if (A[i][j].v > B[i][j].v) {           printf( %d  , max(A[i][j].m, B[i][j].m + t));         } else if (A[i][j].v < B[i][j].v) {           printf( %d  , max(A[i][j].m + t, B[i][j].m));         } else {           printf( %d  , max(A[i][j].m, B[i][j].m));         }       }       printf(  n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename Arg1>   void __f(const char* name, Arg1&& arg1) {     cerr << name <<   :   << arg1 << std::endl;   }   template <typename Arg1, typename... Args>   void __f(const char* names, Arg1&& arg1, Args&&... args) {     const char* comma = strchr(names + 1,  , );     cerr.write(names, comma - names) <<   :   << arg1 <<   |  ;     __f(comma + 1, args...);   }   bool ok(int x) {     if (x < 0) return false;     for (int i = 0; i * i <= x; i++)       if (i * i == x) return true;     return false;   }   int main() {     int n;     scanf( %d , &n);     int mx = -10000000;     for (int i = (0); i < (n); ++i) {       int x;       scanf( %d , &x);       if (ok(x)) continue;       mx = max(mx, x);     }     printf( %d n , mx);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     while (t--) {       int n, a, b, c, d;       cin >> n >> a >> b >> c >> d;       if ((a + b) * n < c - d)         cout <<  No n ;       else if ((a - b) * n > c + d)         cout <<  No n ;       else         cout <<  Yes n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long a[200100];   int main() {     long long k, Answer = 0;     int n;     cin >> n >> k;     for (int i = 0; i < n; i++) scanf( %I64d , &a[i]);     for (int i = 0; i < n; i++) {       Answer += a[i] / k;       a[i] = a[i] % k;       if (a[i] + a[i + 1] >= k)         a[i + 1] += a[i];       else if (a[i] > 0) {         a[i + 1] = 0;         Answer++;       }     }     cout << Answer;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void substr(int start, int end, char in[], char out[]) {     for (int i = start; i < end; ++i) out[i - start] = in[i];     out[end - start] =   0 ;   }   int main() {     int n, p, q;     char s[100];     cin >> n >> p >> q;     cin >> s;     int pdivmax = n / p + 1, qdivmax = n / q + 1;     bool divided = false;     if (p == q) {       if (n % p == 0) {         cout << n / p << endl;         for (int i = 0; i < n; i += p) {           char out[100];           substr(i, i + p, s, out);           cout << out << endl;         }         divided = true;       }     } else {       for (int i = 0; i < pdivmax; ++i) {         for (int j = 0; j < qdivmax; ++j) {           if (p * i + q * j == n) {             cout << i + j << endl;             for (int k = 0; k < p * i; k += p) {               char out[100];               substr(k, k + p, s, out);               cout << out << endl;             }             for (int k = p * i; k < n; k += q) {               char out[100];               substr(k, k + q, s, out);               cout << out << endl;             }             divided = true;             break;           }         }         if (divided) break;       }     }     if (!divided) cout << -1 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool not_prime[100000];   long long int primes[100000];   int p, prime_factors[100000], pf_count[100000], q;   int a[10000];   void find_primes() {     long long int i, j;     p = 0;     for (i = 2; i < 100000; i++) {       if (not_prime[i] == false) {         primes[p++] = i;         for (j = 2; i * j < 100000; j++) {           not_prime[i * j] = false;         }       }     }   }   void factor(long long int n) {     q = 0;     for (int i = 0; i < p; i++) {       int count = 0;       while (n % primes[i] == 0) {         count++;         n /= primes[i];       }       if (count > 0) {         prime_factors[q] = i;         pf_count[q++] = count;       }     }     if (n > 1) {       primes[p++] = n;       prime_factors[q] = p - 1;       pf_count[q++] = 1;     }   }   int rec(int d, long long int b) {     int ret = 0;     if (d == q) {       long long int x = 1;       for (int i = 0; i < q; i++) {         for (int j = 0; j < a[i]; j++) x *= primes[prime_factors[i]];       }       if (x <= b)         return 0;       else         return 1;     }     for (int j = pf_count[d]; j >= 0; j--) {       a[d] = j;       int tmp = rec(d + 1, b);       if (tmp == 0) break;       ret += tmp;     }     return ret;   }   int main() {     long long int a, b, n;     int ans = 0;     cin >> a >> b;     n = a - b;     if (a == b) {       cout <<  infinity  << endl;     } else if (a < b) {       cout << 0 << endl;     } else {       find_primes();       factor(n);       cout << rec(0, b) << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   bool prime(long long int i) {     if (i == 1) return false;     if ((i == 2) || (i == 3)) return true;     if ((i % 2 == 0) || (i % 3 == 0))       return false;     else {       for (long long int j = 5; j * j <= i; j += 6)         if ((i % j == 0) || (i % (j + 2) == 0)) return false;     }     return true;   }   int main() {     long long p, y, ans;     cin >> p >> y;     int f = 0;     if (p == y) {       cout <<  -1 ;       return 0;     }     for (long long i = y; i > p; i--) {       int f1 = 0;       if (prime(i)) {         f = 1;         ans = i;         break;       }       for (long long j = 2; j <= p; j++) {         if (i % j == 0) {           f1 = 1;           break;         }       }       if (f1 == 0) {         ans = i;         f = 1;         break;       }     }     if (f == 1) {       cout << ans;     } else {       cout <<  -1 ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 600;   int mat[2000][2000];   int quad[20][20];   int cont[20][20];   int main() {     int n, m;     scanf( %d%d , &n, &m);     int foi = 0;     int result = -1;     for (int i = 0; i < m; i++) {       int x, y;       for (int h = 0; h < 5; h++) {         for (int k = 0; k < 5; k++) {           quad[h][k] = 0;           cont[h][k] = 0;         }       }       scanf( %d%d , &x, &y);       x--;       y--;       mat[x][y]++;       int maiorX = max(x - 2, 0);       int menorX = min(x + 2, n - 1) + 1;       int maiorY = max(y - 2, 0);       int menorY = min(y + 2, n - 1) + 1;       for (int h = maiorX; h < menorX; h++) {         for (int k = maiorY; k < menorY; k++) {           if (mat[h][k]) {             cont[h - maiorX][k - maiorY]++;             if (h - maiorX - 1 >= 0) {               cont[h - maiorX][k - maiorY] += cont[h - maiorX - 1][k - maiorY];             }           }         }       }       int pode = 0;       for (int h = 0; h < 5; h++) {         int soma = 0;         for (int k = 0; k < 5; k++) {           if (cont[h][k] >= 3) {             soma++;             if (soma >= 3) {               pode = 1;             }           } else {             soma = 0;           }         }       }       if (foi == 0 && pode) {         result = i + 1;         foi = 1;       }     }     printf( %d n , result);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline void prnt(bool ok) { cout << (ok ?  YES  :  NO ); }   const int ppr = 257;   const long long INF = 2e18;   const int inf = 2e9;   const int mod = 1e9 + 7;   const int N = 3e6 + 123;   const long double pi = 3.141592653589793238462643;   const int dx[] = {1, 0, -1, 0};   const int dy[] = {0, 1, 0, -1};   long long n, m, a[N], b[N], q, cur;   vector<long long> g[N];   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     cin >> n >> m;     while (m--) {       long long x, y;       cin >> x >> y;       if (x < y) swap(x, y);       g[y].push_back(x);       a[x]++;       b[y]++;     }     for (long long i = 1; i <= n; i++) cur += a[i] * b[i];     cin >> q;     cout << cur <<   n ;     while (q--) {       long long x;       cin >> x;       cur -= a[x] * b[x];       a[x] += g[x].size();       b[x] = 0;       for (auto to : g[x]) {         cur -= a[to] * b[to];         b[to]++;         a[to]--;         cur += a[to] * b[to];         g[to].push_back(x);       }       g[x].clear();       cout << cur <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = (int)1e5 + 5;   string check(char x, int n) {     string it =   ;     it.push_back(x);     string z =   ;     for (int i = 0; i < n; i++) {       z = z +  0 ;     }     it = it + z;     return it;   }   int main() {     int tc;     cin >> tc;     while (tc--) {       int x;       int count = 0;       vector<string> v;       cin >> x;       string it = to_string(x);       int size = it.length();       for (int i = 0; i < size; i++) {         if (it[size - 1 - i] !=  0 ) {           string second = check(it[size - 1 - i], i);           count++;           v.push_back(second);         }       }       reverse(v.begin(), v.end());       cout << count << endl;       for (auto& i : v) {         cout << i <<    ;       }       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3F3F3F3F;   const int MAXN = 100001;   char str[MAXN];   inline void solve(int test) {     int t, sx, sy, ex, ey;     scanf( %d %d %d %d %d , &t, &sx, &sy, &ex, &ey);     scanf( %s , str);     ;     int X, Y;     X = ex - sx, Y = ey - sy;     pair<char, char> S;     if (Y < 0)       S.first =  S ;     else       S.first =  N ;     if (X < 0)       S.second =  W ;     else       S.second =  E ;     X = abs(X);     Y = abs(Y);     for (int i = 0; i < t; ++i) {       char G = str[i];       if (S.first == G)         Y--;       else if (S.second == G)         X--;       if (X <= 0 && Y <= 0) {         printf( %d n , i + 1);         return;       }     }     printf( -1 n );   }   int main() {     solve(0);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 1 << 30;   char buf[1000];   string nextLine(int length = 100) {     cin.getline(buf, length);     string s(buf);     return s;   }   string next(int length = 100) {     string tmp;     cin >> tmp;     return tmp;   }   int nextInt() {     int tmp;     scanf( %d , &tmp);     return tmp;   }   long long mod = 1E9 + 7;   long long add(long long a, long long b) { return (a + b) % mod; }   const int MAXN = 5010;   string s1, s2;   int m, n;   long long dp[MAXN][MAXN];   long long get(int starta, int startb) {     if (starta == m) return 0;     if (startb == n) return 0;     long long &ret = dp[starta][startb];     if (ret != -1) return ret;     ret = 0;     if (s2[startb] == s1[starta]) {       ret++;       ret = add(ret, get(starta + 1, startb + 1));     }     ret = add(ret, get(starta, startb + 1));     return ret;   }   int main() {     s1 = next();     s2 = next();     m = ((int)(s1).size());     n = ((int)(s2).size());     long long sum = 0;     for (int i = 0, _i = (MAXN); i < _i; ++i)       for (int j = 0, _j = (MAXN); j < _j; ++j) dp[i][j] = -1;     for (int i = 0, _i = (m); i < _i; ++i) {       sum = add(sum, get(i, 0));     }     cout << sum << endl;   }


#include <iostream>           #include <string>           #include<bits/stdc++.h>           #include<algorithm>           using namespace std;           int main()           {               int t;               cin>>t;               while(t--)               {                   long long n,k;                   cin>>n>>k;                   long long a=n,b=1;                   if(n%2==0)                   {                       k--;                       k=k%n;                       cout<<b+k<<endl;                   }                   else                   {                       k--;                       long long t=n/2;                       long long y=k/t;                       long long j=k+y+1;                       long long ans=j%n;                       if(!ans)ans=n;                       cout<<ans<<endl;                   }               }           }


#include <bits/stdc++.h>   using namespace std;   const int maxN = 1e5;   int n;   char ans[maxN + 1];   string s;   int main() {     ios_base::sync_with_stdio(false);     cin >> n;     cin.ignore();     for (int i = 0; i < n; i++) {       getline(cin, s);       for (int j = 0; j < s.length(); j++) {         if (ans[j] == 0) ans[j] =  ? ;         if (s[j] ==  ?  || ans[j] ==  X ) continue;         if (ans[j] ==  ?  && s[j] !=  ? )           ans[j] = s[j];         else if (ans[j] !=  ?  && s[j] !=  ?  && ans[j] != s[j])           ans[j] =  X ;       }     }     for (int i = 0; i < s.length(); i++) {       if (ans[i] ==  X )         ans[i] =  ? ;       else if (ans[i] ==  ? )         ans[i] =  a ;     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char a[100020];   char b[100020];   int zf[100020];   int zb[100020];   int main() {     scanf( %s , a);     scanf( %s , b);     int la = strlen(a);     int lb = strlen(b);     zf[0] = 0;     zb[la] = lb;     for (int i = 1; i <= la; i++) {       if (a[i - 1] == b[zf[i - 1]]) {         zf[i] = zf[i - 1] + 1;       } else {         zf[i] = zf[i - 1];       }     }     for (int i = la - 1; i >= 0; i--) {       if (a[i] == b[zb[i + 1] - 1]) {         zb[i] = zb[i + 1] - 1;       } else {         zb[i] = zb[i + 1];       }     }     int ans = lb + 1;     int p = -1;     for (int i = 0; i <= la; i++) {       int tmp = max(zb[i] - zf[i], 0);       if (ans > tmp) {         ans = tmp;         p = i;       }     }     for (int i = 0; i < zf[p]; i++) {       printf( %c , b[i]);     }     for (int i = max(zf[p], zb[p]); i < lb; i++) {       printf( %c , b[i]);     }     if (ans == lb) {       printf( - );     }     printf(  n );     return 0;   }