#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   #pragma GCC target( sse4 )   using namespace std;   template <class T>   bool ckmin(T& a, const T& b) {     return b < a ? a = b, 1 : 0;   }   template <class T>   bool ckmax(T& a, const T& b) {     return a < b ? a = b, 1 : 0;   }   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   const int MOD = 1000000007;   const char nl =   n ;   const int MX = 41;   int in = 18, out;   int N;   vector<vector<int> > graph(MX);   int cc = 0;   bool bi = true;   void ff() {     int col[N];     for (int i = 0; i < (N); i++) col[i] = -1;     for (int r = 0; r < (N); r++) {       if (col[r] != -1) continue;       col[r] = 0;       queue<int> q;       q.push(r);       while (!q.empty()) {         int cur = q.front();         q.pop();         for (auto& a : graph[cur]) {           if (col[a] != -1) {             if (col[a] == col[cur]) bi = false;           } else {             col[a] = 1 - col[cur];             q.push(a);           }         }       }       cc++;     }   }   long long cis() {     long long mask[N];     for (int i = 0; i < (N); i++) {       mask[i] = 1ll << N;       mask[i]--;       for (auto& a : graph[i]) {         mask[i] -= 1ll << a;       }     }     long long dp[(1ll << out)];     for (int m = 0; m < ((1ll << out)); m++) {       long long cm = 1ll << N;       cm--;       for (int i = 0; i < (out); i++) {         if (m & (1ll << i)) cm &= mask[i + in];       }       bool good = true;       for (int i = 0; i < (out); i++) {         if ((m & (1ll << i)) && !(cm & (1ll << (i + in)))) good = false;       }       dp[m] = 0;       if (good) dp[m] = 1ll;     }     for (int i = 0; i < (out); i++)       for (int m = 0; m < ((1ll << out)); m++)         if (m & (1ll << i)) dp[m] += dp[m ^ (1ll << i)];     long long ans = 0;     for (int m = 0; m < ((1ll << in)); m++) {       long long cm = 1ll << N;       cm--;       for (int i = 0; i < (in); i++) {         if (m & (1ll << i)) cm &= mask[i];       }       bool good = true;       for (int i = 0; i < (in); i++) {         if ((m & (1ll << i)) && !(cm & (1ll << (i)))) good = false;       }       if (good) {         ans += dp[cm >> in];       }     }     return ans;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> N;     int M;     cin >> M;     vector<pair<int, int> > edges;     bool found[N];     for (int i = 0; i < (N); i++) found[i] = false;     for (int i = 0; i < (M); i++) {       int A, B;       cin >> A >> B;       A--;       B--;       edges.push_back({A, B});       found[A] = true;       found[B] = true;     }     int ind[N];     int nxt = 0;     long long mul = 1;     for (int i = 0; i < (N); i++) {       if (found[i]) {         ind[i] = nxt;         nxt++;       } else {         mul *= 2;       }     }     N = nxt;     ckmin(in, N);     out = N - in;     if (M == 0) {       cout << 0 << nl;       return 0;     }     for (int i = 0; i < (M); i++) {       int A = edges[i].first;       int B = edges[i].second;       A = ind[A];       B = ind[B];       graph[A].push_back(B);       graph[B].push_back(A);     }     ff();     long long is = cis();     long long ans = (1ll << N);     ans -= 2 * is;     if (!bi) ans -= (1ll << cc);     ans += 2;     cout << ans * mul << nl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int S = 100009;   vector<int> in[S];   vector<int> out[S];   bool viz[S];   int moa[S];   vector<int> topol;   vector<int> rang[S];   void dfs(int a) {     if (viz[a]) return;     viz[a] = 1;     for (auto u : out[a]) dfs(u);     topol.push_back(a);   }   void sfd(int a, int c) {     if (moa[a] != -1) return;     moa[a] = c;     for (auto u : in[a]) sfd(u, c);   }   int main() {     memset(moa, -1, sizeof moa);     int n, v;     cin >> n;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         scanf( %i , &v);         if (v != 0) {           in[i].push_back(j);           out[j].push_back(i);         }       }     }     for (int i = 1; i <= n; i++) dfs(i);     int r = 0, u;     for (int i = n - 1; i > -1; i--) {       u = topol[i];       if (moa[u] == -1) {         sfd(u, r);         r++;       }     }     for (int i = 1; i <= n; i++) {       if (moa[i] != moa[1]) {         printf( NO );         return 0;       }     }     printf( YES );   }


#include <bits/stdc++.h>      using namespace std;   #define int long long   const int inf = 1e18;      struct node {       int x, y;       node *L;       node *R;       int val;       int mx;          node(int xx, int yy) {           L = nullptr;           R = nullptr;           x = xx;           y = rand();           val = yy;           mx = yy;       }   };      node *root = nullptr;      int getmx(node *v) {       if (v == nullptr)return -inf;       return v->mx;   }      void recalc(node *v) {       v->mx = max(v->val, max(getmx(v->L), getmx(v->R)));   }      pair<node *, node *> split(node *v, int key) {       if (v == nullptr)return {nullptr, nullptr};       if (v->x <= key) {           auto tmp = split(v->R, key);           v->R = tmp.first;           recalc(v);           return {v, tmp.second};       } else {           auto tmp = split(v->L, key);           v->L = tmp.second;           recalc(v);           return {tmp.first, v};       }   }      node *merge(node *L, node *R) {       if (L == nullptr)return R;       if (R == nullptr)return L;       if (L->y < R->y) {           auto tmp = merge(L->R, R);           L->R = tmp;           recalc(L);           return L;       } else {           auto tmp = merge(L, R->L);           R->L = tmp;           recalc(R);           return R;       }   }      void add(pair<int, int> a) {       auto tmp = split(root, a.first);       root = merge(merge(tmp.first, new node(a.first, a.second)), tmp.second);   }      int ans(int val) {       node *v = root;       if (getmx(v) < val) {           return -1;       }       int mn = inf;       while (v != nullptr) {           if (v->val >= val) {               mn = min(v->x, mn);           }           if (getmx(v->L) < val) {               v = v->R;           } else {               v = v->L;           }       }       return mn;   }      int get(vector<pair<int, int>> first, vector<pair<int, int>> sec) {       root = nullptr;       sort(first.begin(), first.end());       sort(sec.begin(), sec.end());       int res = -inf;       for (int i = (int) first.size() - 1; i >= 0; --i) {           while (sec.size() != 0 && sec.back().first >= first[i].first) {               add(sec.back());               sec.pop_back();           }           int h = ans(first[i].second);           if (h != -1) {               res = max(res, (first[i].second - h) * 2);           }       }       return res;   }      int get2(vector<pair<int, int>> first, vector<pair<int, int>> sec) {       root = nullptr;       sort(first.begin(), first.end());       sort(sec.begin(), sec.end());       reverse(sec.begin(), sec.end());       int res = -inf;       for (int i = 0; i < first.size(); ++i) {           while (sec.size() != 0 && sec.back().first <= first[i].first) {               add(sec.back());               sec.pop_back();           }           int h = ans(first[i].second);           if (h != -1) {               res = max(res, (first[i].second - first[i].first) * 2);           }       }       return res;   }      signed main() {       cin.tie();       cout.tie();       ios_base::sync_with_stdio(false);   #ifdef foo       freopen( input.txt ,  r , stdin);       freopen( output.txt ,  w , stdout);   #endif       int n;       cin >> n;       int a[n];       int b[n];       for (int i = 0; i < n; ++i) {           cin >> a[i];       }       for (int i = 0; i < n; ++i) {           cin >> b[i];       }       vector<pair<int, int>> f;       vector<pair<int, int>> s;       for (int i = 0; i < n; ++i) {           if (a[i] <= b[i])               f.push_back({a[i], b[i]});           if (b[i] <= a[i])               s.push_back({b[i], a[i]});       }       int ans = 0;       ans = max(ans, get(f, s));       swap(f, s);       ans = max(ans, get(f, s));       f.clear();       s.clear();       for (int i = 0; i < n; ++i) {           if (a[i] <= b[i])               f.push_back({a[i], b[i]});           if (b[i] <= a[i])               s.push_back({b[i], a[i]});       }       ans = max(ans, get2(f, s));       swap(f, s);       ans = max(ans, get2(f, s));       int tot = 0;       for (int i = 0; i < n; ++i) {           tot += abs(a[i] - b[i]);       }       cout << tot - ans;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using vi = vector<int>;   using pii = array<ll, 3>;   vector<vector<pii>> adj;   vi sz, parent;   int fill(int cur, int par = -1) {     parent[cur] = par;     for (auto [v, _, __] : adj[cur])       if (v != par) sz[cur] += fill(v, cur);     sz[cur] = max(1, sz[cur]);     return sz[cur];   }   int main(int argc, char* argv[]) {     std::ios::sync_with_stdio(false);     cin.tie(nullptr);     cout.precision(10);     int t;     cin >> t;     while (t--) {       ll n, s;       cin >> n >> s;       adj.assign(n, {});       sz.assign(n, 0);       parent.assign(n, -1);       for (int i = (0); i < (n - 1); ++i) {         ll u, v, w, c;         cin >> u >> v >> w >> c;         u--, v--;         adj[u].push_back({v, w, c});         adj[v].push_back({u, w, c});       }       fill(0);       priority_queue<array<ll, 3>> prePQ[2];       ll start_sum = 0;       for (int u = (0); u < (n); ++u)         for (auto [v, w, c] : adj[u]) {           if (parent[v] == u) {             start_sum += w * sz[v];             if (c == 1) {               prePQ[0].push({sz[v] * (w - w / 2), w, sz[v]});               prePQ[0].push({sz[v] * (w / 2 - w / 4), w / 2, sz[v]});             } else {               prePQ[1].push({sz[v] * (w - w / 2), w, sz[v]});             }           }         }       ll mi = 1e18;       for (int p = (0); p < (2); ++p) {         ll steps = 0, cur_sum = start_sum;         priority_queue<array<ll, 3>> pqOne = prePQ[0], pqTwo = prePQ[1];         if (p && pqOne.size()) {           steps++;           auto [g, w, s] = pqOne.top();           w /= 4;           cur_sum -= g;           pqOne.pop();           pqOne.push({s * (w - w / 2), w, s});         }         while (cur_sum > s) {           if (pqOne.empty()) {             steps += 2;             auto [g, w, s] = pqTwo.top();             w /= 2;             cur_sum -= g;             pqTwo.pop();             pqTwo.push({s * (w - w / 2), w, s});           } else if (pqTwo.empty()) {             steps += 1;             auto [g, w, s] = pqOne.top();             w /= 4;             cur_sum -= g;             pqOne.pop();             pqOne.push({s * (w - w / 2), w, s});           } else {             steps += 2;             auto [g11, w11, s11] = pqOne.top();             pqOne.pop();             auto [g12, w12, s12] = pqOne.top();             pqOne.pop();             auto [g2, w2, s2] = pqTwo.top();             pqTwo.pop();             if (g11 + g12 > g2) {               pqTwo.push({g2, w2, s2});               cur_sum -= g11 + g12;               w11 /= 4;               w12 /= 4;               pqOne.push({s11 * (w11 - w11 / 2), w11, s11});               pqOne.push({s12 * (w12 - w12 / 2), w12, s12});             } else {               pqOne.push({g11, w11, s11});               pqOne.push({g12, w12, s12});               cur_sum -= g2;               w2 /= 2;               pqTwo.push({s2 * (w2 - w2 / 2), w2, s2});             }           }         }         mi = min(mi, steps);       }       cout << mi <<   n ;     }     cout.flush();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2 * 100100;   int a[maxn], logTable[maxn], rmq[50][maxn];   int minPos(int i, int j) {     int k = logTable[j - i];     int x = rmq[k][i];     int y = rmq[k][j - (1 << k) + 1];     return a[x] <= a[y] ? a[x] : a[y];   }   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %d , &a[i]);     for (int i = 2; i <= n; i++) logTable[i] = logTable[i >> 1] + 1;     for (int i = 0; i < n; ++i) rmq[0][i] = i;     for (int k = 1; (1 << k) < n; ++k) {       for (int i = 0; i + (1 << k) <= n; i++) {         int x = rmq[k - 1][i];         int y = rmq[k - 1][i + (1 << (k - 1))];         rmq[k][i] = a[x] <= a[y] ? x : y;       }     }     set<pair<int, int> > s;     for (int i = 0; i < n; i++) {       int curr, curl;       int l = i, r = n;       while (r - l > 1) {         int mid = (r + l) / 2;         int curmin = minPos(i, mid);         if (curmin == a[i])           l = mid;         else           r = mid;       }       curr = l;       l = -1, r = i;       while (r - l > 1) {         int mid = (r + l) / 2;         int curmin = minPos(mid, i);         if (curmin == a[i])           r = mid;         else           l = mid;       }       curl = r;       s.insert(make_pair(-a[i], curr - curl + 1));     }     for (int i = 1; i <= n; i++) {       while ((int)(s).size() && s.begin()->second < i) s.erase(s.begin());       printf( %d  , -s.begin()->first);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, t;     cin >> n >> m;     string s[100 + 10];     for (int i = 0; i < n; i++) {       cin >> s[i];     }     for (int i = 0; i < n; i++) {       t = s[i][0];       for (int j = 0; j < m; j++) {         if (s[i][j] != t) {           cout <<  NO  << endl;           return 0;         }       }     }     for (int i = 1; i < n - 1; i++) {       if (s[i] == s[i - 1] || s[i] == s[i + 1]) {         cout <<  NO  << endl;         return 0;       }     }     cout <<  YES  << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int maxN = 100 * 1000 + 5;   int Q;   map<int, int> POS;   struct range {     int s, e;     long long siz;     long long mod[5];     range(int s = -1, int e = -1) : s(s), e(e) {       memset(mod, 0, sizeof mod);       siz = 0;     }   } t[1 << 18];   inline void build(int x) {     if (t[x].e <= t[x].s) return;     int mid = (t[x].s + t[x].e) / 2;     int l = (x << 1);     int r = l + 1;     t[l] = range(t[x].s, mid);     t[r] = range(mid + 1, t[x].e);     build(l);     build(r);   }   inline void add(int root, int pos, int val) {     range &now = t[root];     now.siz++;     if (now.s == now.e) {       now.mod[1] = val;       return;     }     int l = (root << 1), r = (root << 1) + 1;     if (pos <= t[l].e)       add(l, pos, val);     else       add(r, pos, val);     for (int i = 0; i < 5; i++) {       int tmp = (i - t[l].siz) % 5;       tmp = (tmp + 5) % 5;       now.mod[i] = t[l].mod[i] + t[r].mod[tmp];     }   }   inline void del(int root, int pos, int val) {     range &now = t[root];     now.siz--;     if (now.s == now.e) {       now.mod[1] = 0;       return;     }     int l = (root << 1), r = (root << 1) + 1;     if (pos <= t[l].e)       del(l, pos, val);     else       del(r, pos, val);     for (int i = 0; i < 5; i++) {       int tmp = (i - t[l].siz) % 5;       tmp = (tmp + 5) % 5;       now.mod[i] = t[l].mod[i] + t[r].mod[tmp];     }   }   int main() {     scanf( %d , &Q);     vector<pair<int, int> > qq;     vector<int> num;     for (int i = 1; i <= Q; i++) {       char test[5];       scanf( %s , test);       if (test[0] ==  a ) {         int tmp;         scanf( %d , &tmp);         qq.push_back(pair<int, int>(0, tmp));         num.push_back(tmp);       } else if (test[0] ==  d ) {         int tmp;         scanf( %d , &tmp);         qq.push_back(pair<int, int>(1, tmp));       } else         qq.push_back(pair<int, int>(2, -1));     }     sort(num.begin(), num.end());     int uni = 0;     for (int i = 0; i < (int)num.size(); i++) {       if (POS[num[i]] == 0) POS[num[i]] = ++uni;     }     t[1] = range(1, uni);     build(1);     for (int i = 0; i < (int)qq.size(); i++) {       if (qq[i].first == 0)         add(1, POS[qq[i].second], qq[i].second);       else if (qq[i].first == 1)         del(1, POS[qq[i].second], qq[i].second);       else         printf( %I64d n , t[1].mod[3]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline void gmin(T &x, const T &y) {     x = x > y ? y : x;   }   template <class T>   inline void gmax(T &x, const T &y) {     x = x < y ? y : x;   }   template <class T>   inline bool Gmin(T &x, const T &y) {     return x > y ? x = y, 1 : 0;   }   template <class T>   inline bool Gmax(T &x, const T &y) {     return x < y ? x = y, 1 : 0;   }   const int BufferSize = 1 << 16;   char buffer[BufferSize], *Bufferhead, *Buffertail;   bool Terminal;   inline char Getchar() {     if (Bufferhead == Buffertail) {       int l = fread(buffer, 1, BufferSize, stdin);       if (!l) {         Terminal = 1;         return 0;       }       Buffertail = (Bufferhead = buffer) + l;     }     return *Bufferhead++;   }   template <class T>   inline bool read(T &x) {     x = 0;     char c = Getchar(), rev = 0;     while (c <  0  || c >  9 ) {       rev |= c ==  - ;       c = Getchar();       if (Terminal) return 0;     }     while (c >=  0  && c <=  9 ) x = x * 10 + c -  0 , c = Getchar();     if (c ==  . ) {       c = Getchar();       double t = 0.1;       while (c >=  0  && c <=  9 )         x = x + (c -  0 ) * t, c = Getchar(), t = t / 10;     }     x = rev ? -x : x;     return 1;   }   template <class T1, class T2>   inline bool read(T1 &x, T2 &y) {     return read(x) & read(y);   }   template <class T1, class T2, class T3>   inline bool read(T1 &x, T2 &y, T3 &z) {     return read(x) & read(y) & read(z);   }   template <class T1, class T2, class T3, class T4>   inline bool read(T1 &x, T2 &y, T3 &z, T4 &w) {     return read(x) & read(y) & read(z) & read(w);   }   inline bool reads(char *x) {     char c = Getchar();     while (c < 33 || c > 126) {       c = Getchar();       if (Terminal) return 0;     }     while (c >= 33 && c <= 126) (*x++) = c, c = Getchar();     *x = 0;     return 1;   }   template <class T>   inline void print(T x, const char c =   n ) {     if (!x) {       putchar( 0 );       putchar(c);       return;     }     if (x < 0) putchar( - ), x = -x;     int m = 0, a[20];     while (x) a[m++] = x % 10, x /= 10;     while (m--) putchar(a[m] +  0 );     putchar(c);   }   const int inf = 0x3f3f3f3f;   const int N = 25, M = 5005;   int mod = 1e9 + 7;   template <class T, class S>   inline void ch(T &x, const S y) {     x = (x + y) % mod;   }   inline int exp(int x, int y, const int mod = ::mod) {     int ans = 1;     while (y) {       if (y & 1) ans = (long long)ans * x % mod;       x = (long long)x * x % mod;       y >>= 1;     }     return ans;   }   int cell[M], CNT;   int c, c0, c1, c2, cnt, d, O, L = 2, R = 5001;   inline int sum(int x, int y, int k = 0) {     if (!k) k = ++L;     printf( + %d %d %d n , x, y, k);     ++CNT;     cell[k] = (cell[x] + cell[y]) % mod;     return k;   }   inline int power(int x, int k = 0) {     if (!k) k = ++L;     printf( ^ %d %d n , x, k);     ++CNT;     cell[k] = exp(cell[x], d);     return k;   }   inline int zero() {     int ans = --R, t = --R, y = mod - 1;     while (y) {       t = sum(t, t, t);       y >>= 1;       if (y & 1) ans = sum(ans, t);     }     return ans;   }   inline int multi(int x, int y) {     int k = --R;     int ans = sum(O, O, k), t = sum(x, O, --R);     while (y) {       if (y & 1) ans = sum(ans, t, ans);       t = sum(t, t, t);       y >>= 1;     }     return ans;   }   inline int neg(int x) { return multi(x, mod - 1); }   inline int sub(int x, int y) {     int t = neg(y);     return sum(x, t, t);   }   inline int sqr(int x) {     int a[N], b = ++L;     b = multi(b, c);     a[0] = multi(x, 1);     for (int i = 1; i <= cnt; i++) a[i] = sum(a[i - 1], b);     for (int i = 0; i <= cnt; i++) a[i] = power(a[i]);     for (int i = 1; i <= cnt; i++)       for (int j = 0; j <= cnt - i; j++) a[j] = sub(a[j + 1], a[j]);     int t = ++L;     a[0] = sub(a[0], sum(multi(x, c1), multi(++L, c0)));     a[0] = multi(a[0], exp(c2, mod - 2));     return a[0];   }   inline int find(int c, int &c2, int &c1, int &c0, int &cnt) {     static int a[N], pw[N];     static int C[N][N];     for (int i = 0; i < d; i++) a[i] = 0;     a[d] = 1;     pw[0] = 1;     for (int i = 1; i <= d; i++) pw[i] = (long long)pw[i - 1] * c % mod;     for (int i = 0; i <= d; i++) {       C[i][i] = C[i][0] = 1;       for (int j = 1; j < i; j++) C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % mod;     }     int m = d;     cnt = 0;     while (m > 2) {       cnt++;       for (int i = 0; i <= m; i++) {         for (int j = 0; j < i; j++)           ch(a[j], (long long)C[i][j] * a[i] % mod * pw[i - j]);         a[i] = 0;       }       while (m >= 0 && !a[m]) m--;     }     if (m == 2) {       c2 = a[2], c1 = a[1], c0 = a[0];       return 1;     }     return 0;   }   int main() {     for (int i = 1; i <= 5000; i++) cell[i] = 1;     scanf( %d%d , &d, &mod);     int x = 1, y = 2;     cell[x] = rand() % mod;     cell[y] = rand() % mod;     O = zero();     while (1) {       c = rand() % mod;       if (find(c, c2, c1, c0, cnt)) break;     }     int p1 = sqr(sum(x, y)), p2 = sqr(sub(x, y));     int g = sub(p1, p2), ans = multi(g, exp(4, mod - 2));     printf( f %d n , ans);     if (cell[ans] ^ (1ll * cell[x] * cell[y] % mod)) fprintf(stderr,  false );     cerr <<  CNT           <<  =  << CNT << endl;     cerr <<  cnt           <<  =  << cnt << endl;     return 0;   }


#include<bits/stdc++.h>   using  namespace std;   int main(){        int T;        cin>>T;        while(T--){            long long int N;            cin>>N;            int sum1=0,i=1,count=0;            while(true){                sum1+=i;count++;                if(sum1>=N){break;}                i+=2;             }            cout<<count<<  n ;        }        return 0;    }


#include <bits/stdc++.h>   using namespace std;   const long long N = (long long)(5 * 1e5 + 10);   void precision(long long a) { cout << setprecision(a) << fixed; }   long long expo(long long a, long long b, long long m) {     long long res = 1;     while (b > 0) {       if (b & 1) res = (res * a) % m;       a = (a * a) % m;       b = b >> 1;     }     return res;   }   long long GCD(long long A, long long B) { return (B) ? GCD(B, A % B) : A; }   long long LCM(long long A, long long B) { return A * B / GCD(A, B); }   long long max(long long A, long long B) { return (A >= B) ? A : B; }   long long min(long long A, long long B) { return (A <= B) ? A : B; }   long long ceil_div(long long a, long long b) {     return a % b == 0 ? a / b : a / b + 1;   }   template <typename T>   istream &operator>>(istream &istream, vector<T> &v) {     for (auto &it : v) {       cin >> it;     }     return istream;   }   bool isPrime(long long n) {     if (n == 1) return false;     if (n == 2) return true;     for (long long i = 2; i * i <= n; i++) {       if (n % i == 0) return false;     }     return true;   }   void rec(long long n) {     cout << (long long)sqrt(n) + (long long)cbrt(n) - (long long)(sqrt(cbrt(n)))          <<   n ;   }   void sol() {     long long n;     cin >> n;     rec(n);   }   int32_t main() {     ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);     long long t = 1;     cin >> t;     while (t--) {       sol();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   char mp[103][103];   int main() {     int i, j, cnt;     scanf( %d , &n);     for (i = 0; i < n; i++) scanf( %s , mp[i]);     cnt = 0;     for (i = 0; i < n; i++) {       for (j = 0; j < n; j++)         if (mp[i][j] ==  . ) break;       if (j != n) cnt++;     }     if (cnt == n) {       for (i = 0; i < n; i++)         for (j = 0; j < n; j++)           if (mp[i][j] ==  . ) {             printf( %d %d n , i + 1, j + 1);             break;           }       return 0;     }     int a, v, c;     cnt = 0;     for (i = 0; i < n; i++) {       for (j = 0; j < n; j++)         if (mp[j][i] ==  . ) break;       if (j != n) cnt++;     }     if (cnt == n) {       for (i = 0; i < n; i++)         for (j = 0; j < n; j++)           if (mp[j][i] ==  . ) {             printf( %d %d n , j + 1, i + 1);             break;           }       return 0;     }     puts( -1 );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long inf = 1 << 30;   const long long Inf = 1ll << 60ll;   namespace io {   char buf[(1 << 23)], *p1 = buf, *p2 = buf, c;   long long f;   template <typename T>   T read() {     T x = 0;     f = 0;     c = (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, (1 << 23), stdin), p1 == p2)              ? EOF              : *p1++);     while (!isdigit(c))       (c ==  - ) && (f = 1),           c = (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, (1 << 23), stdin),                             p1 == p2)                    ? EOF                    : *p1++);     while (isdigit(c))       x = x * 10 + (c & 15),       c = (p1 == p2 &&                    (p2 = (p1 = buf) + fread(buf, 1, (1 << 23), stdin), p1 == p2)                ? EOF                : *p1++);     return f ? -x : x;   }   }  // namespace io   const long long N = 200005, mod = 998244353;   long long n, k, fac[N], a[N], inv[N];   long long qpow(long long b, long long p) {     long long res = 1;     while (p) {       if (p & 1) res = res * b % mod;       b = b * b % mod;       p >>= 1ll;     }     return res;   }   long long C(long long x, long long y) {     return fac[x] * inv[y] % mod * inv[x - y] % mod;   }   signed main() {     scanf( %lld%lld , &n, &k);     long long cnt = 0;     fac[0] = inv[0] = 1;     for (long long i = 1; i <= n; ++i)       fac[i] = fac[i - 1] * i % mod, inv[i] = qpow(fac[i], mod - 2);     for (long long i = 1; i <= n; ++i) scanf( %lld , &a[i]);     for (long long i = 1; i < n; ++i)       if (a[i] != a[i + 1]) cnt++;     if (a[1] != a[n]) cnt++;     long long ans = qpow(k, n), v = 0;     for (long long i = 0; i <= cnt / 2; ++i)       (v += qpow(k - 2, cnt - i * 2) * C(cnt, i) % mod * C(cnt - i, i)) %= mod;     v = v * qpow(k, n - cnt) % mod;     printf( %lld n , (ans - v + mod) * (mod / 2 + 1) % mod);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int lsone(long long int p) { return (p & -p); }   string s1, s2;   int main() {     std::ios::sync_with_stdio(false);     cin >> s1;     cin >> s2;     if (s1 == s2)       cout << -1;     else       cout << max(s1.size(), s2.size());   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1 << 30;   int main() {     ios::sync_with_stdio(false);     long long int MOD = 1000000007LL;     string start, end;     int k;     while (cin >> start >> end >> k) {       const int N = static_cast<int>(start.size());       pair<long long int, long long int> dp(make_pair(1LL, 0LL));       for (int i = 0; i < k; ++i) {         pair<long long int, long long int> next;         next.first = (dp.second * (N - 1)) % MOD;         next.second = (dp.first + dp.second * (N - 2)) % MOD;         swap(dp, next);       }       long long int ans = 0LL;       if (start == end) ans += dp.first;       for (int i = 1; i < N; ++i) {         if (start.substr(i) + start.substr(0, i) == end) {           ans += dp.second;           ans %= MOD;         }       }       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using pii = pair<int, int>;   const int MOD = 1000000007;   int bcj[200010], siz[200010];   stack<pii> res;   void init(int n) {     for (int i = (0); i < (n + 2); i++) bcj[i] = i, siz[i] = 1;   }   int groot(int n) { return (bcj[n] == n) ? n : groot(bcj[n]); }   bool merg(int u, int v) {     u = groot(u), v = groot(v);     if (u == v) return 0;     if (siz[u] > siz[v]) swap(u, v);     res.push({u, v});     bcj[u] = v;     siz[v] += siz[u];     return 1;   }   void redact() {     assert(res.size());     pii k = res.top();     res.pop();     bcj[k.first] = k.first;     bcj[k.second] = k.second;     siz[k.second] -= siz[k.first];   }   void redact(int n) {     while (res.size() != n) redact();   }   struct cmd {     int s, t;   };   int ans[1 << 18];   vector<cmd> queries[1 << 20];   int N;   void insert(int idx, int l, int r, int L, int R, cmd q) {     if (r - l < 0) return;     if (L <= l && r <= R) {       queries[idx].push_back(q);       return;     }     if (R < l || r < L) return;     insert(2 * idx, l, (l + r) / 2, L, R, q);     insert(2 * idx + 1, (l + r) / 2 + 1, r, L, R, q);   }   void dfs(int idx, int l, int r) {     if (r - l < 0) return;     int sz = res.size();     for (cmd& k : queries[idx]) {       merg(k.s, k.t + N);       merg(k.t, k.s + N);       if (groot(k.s) == groot(k.s + N) || groot(k.t) == groot(k.t + N))         return redact(sz);     }     if (r - l == 0) return ans[l] = 1, void();     dfs(2 * idx, l, (l + r) / 2);     dfs(2 * idx + 1, (l + r) / 2 + 1, r);     redact(sz);   }   map<int, int> edges[100005];   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int q;     cin >> N >> q;     init(2 * N + 1);     for (int i = (1); i < ((q) + 1); i++) {       int x, y;       cin >> x >> y;       x--;       y--;       assert(x < y);       if (edges[x][y] == 0)         edges[x][y] = i;       else {         insert(1, 0, q + 3, edges[x][y], i - 1, {x, y});         edges[x][y] = 0;       }     }     for (int i = (0); i < (N); i++)       for (auto k : edges[i])         if (k.second) insert(1, 0, q + 3, k.second, q, {i, k.first});     dfs(1, 0, q + 3);     for (int i = (1); i < ((q) + 1); i++) cout << (ans[i] ?  YES n  :  NO n );   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, a[150], i, j, best, ans = 10000;     cin >> n;     for (i = 0; i < n; ++i) cin >> a[i];     for (i = 1; i < n - 1; ++i) {       best = 0;       for (j = 1; j < n; ++j)         if (j != i)           best = max(best, a[j] - a[j - 1]);         else {           best = max(best, a[j + 1] - a[j - 1]);           ++j;         }       ans = min(ans, best);     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }   const int MAXN = 100000;   int n, MOD, l, r;   int egcd(int x, int y, int &a, int &b) {     if (y == 0) {       a = 1, b = 0;       return x;     }     int g = egcd(y, x % y, b, a);     b -= a * (x / y);     return g;   }   int inv(int x) {     int a, b, g = egcd(x, MOD, a, b);     assert(g == 1);     if (a < 0) a += MOD;     return a;   }   vector<int> p;   typedef struct VAL {     vector<int> a;     int b;     VAL() {       a = vector<int>(((int)(p).size()), 0);       b = 1;     }     VAL(int x) {       a = vector<int>(((int)(p).size()), 0);       for (int i = (0); i < (((int)(p).size())); ++i)         while (x % p[i] == 0) ++a[i], x /= p[i];       b = x;     }   } VAL;   VAL operator*(const VAL &u, const VAL &v) {     VAL ret;     for (int i = (0); i < (((int)(p).size())); ++i) ret.a[i] = u.a[i] + v.a[i];     ret.b = (long long)u.b * v.b % MOD;     return ret;   }   VAL operator/(const VAL &u, const VAL &v) {     VAL ret;     for (int i = (0); i < (((int)(p).size())); ++i) ret.a[i] = u.a[i] - v.a[i];     ret.b = (long long)u.b * inv(v.b) % MOD;     return ret;   }   VAL fact[MAXN + 1];   void precalc() {     {       p.clear();       int x = MOD;       for (int i = 2; i * i <= x; ++i)         if (x % i == 0) {           p.push_back(i);           while (x % i == 0) x /= i;         }       if (x != 1) p.push_back(x);     }     fact[0] = VAL(1);     for (int i = (1); i <= (MAXN); ++i) fact[i] = fact[i - 1] * VAL(i);   }   int pw(int x, int n) {     int ret = 1;     while (true) {       if (n & 1) ret = (long long)ret * x % MOD;       if ((n >>= 1) == 0) return ret;       x = (long long)x * x % MOD;     }   }   int C(int n, int k) {     VAL res = fact[n] / fact[k] / fact[n - k];     int ret = res.b;     for (int i = (0); i < (((int)(p).size())); ++i)       ret = (long long)ret * pw(p[i], res.a[i]) % MOD;     return ret;   }   int ways[MAXN + 1];   void run() {     scanf( %d%d%d%d , &n, &MOD, &l, &r);     precalc();     for (int i = (0); i <= (n); ++i) {       ways[i] = 0;       int la = (l + i + 1) / 2, ra = min(i, (r + i) / 2);       if (la > ra) continue;       if (ra == i) ++ways[i], --ra;       if (la > ra) continue;       ways[i] = (ways[i] + (long long)C(i, la) + MOD - C(i, ra + 1)) % MOD;     }     int ret = 0;     for (int i = (0); i <= (n); ++i)       ret = (ret + (long long)ways[i] * C(n, i)) % MOD;     printf( %d n , ret);   }   int main() {     run();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   int const nmax = 100000;   int const modulo = 1000000007;   struct Edge {     int to;     int cost;   };   vector<Edge> g[1 + nmax], g2[1 + nmax];   int seen[1 + nmax], seen2[1 + nmax];   void dfs(int node, bool &fatal, int acc) {     seen[node] = acc;     for (int h = 0; h < g[node].size(); h++) {       Edge e = g[node][h];       if (seen[e.to] == -1)         dfs(e.to, fatal, acc ^ e.cost);       else if (seen[e.to] != (acc ^ e.cost)) {         fatal = true;       }     }   }   void dfs2(int node, bool &fatal, int acc) {     seen2[node] = acc;     for (int h = 0; h < g2[node].size(); h++) {       Edge e = g2[node][h];       if (seen2[e.to] == -1)         dfs2(e.to, fatal, acc ^ e.cost);       else if (seen2[e.to] != (acc ^ e.cost))         fatal = true;     }   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n, k;     cin >> n >> k;     for (int i = 1; i <= n; i++) seen[i] = seen2[i] = -1;     int colors = (n + 1) / 2, colors2 = n / 2;     for (int i = 1; i <= k; i++) {       int x, y;       char ch;       cin >> x >> y >> ch;       int val;       if (ch ==  o )         val = 1;       else         val = 0;       if ((x + y) % 2 == 0) {         int from = fabs(x - y) / 2;         int to = (x + y) / 2;         if (colors < to) to = colors * 2 + !(n % 2) - to;         g[from].push_back({to, val});         g[to].push_back({from, val});       } else {         int from = (fabs(x - y) - 1) / 2;         int to = (x + y) / 2;         if (colors2 < to) to = colors2 * 2 + (n % 2) - to;         g2[from].push_back({to, val});         g2[to].push_back({from, val});       }     }     int result = 1;     bool fatal = false;     dfs(0, fatal, 0);     for (int i = 1; i <= colors; i++)       if (seen[i] == -1) {         dfs(i, fatal, 0);         result = 1LL * result * 2 % modulo;       }     dfs2(0, fatal, 0);     for (int i = 1; i <= colors2; i++)       if (seen2[i] == -1) {         dfs2(i, fatal, 0);         result = 1LL * result * 2 % modulo;       }     if (fatal == false)       cout << result;     else       cout << 0;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     for (int j = 0; j < t; j++) {       int n;       cin >> n;       if (n % 4 == 0)         cout <<  YES  << endl;       else         cout <<  NO  << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   long long mul(long long a, long long b, long long M) { return a * b % M; }   long long add(long long a, long long b, long long M) { return (a + b) % M; }   vector<vector<long long> > eye(int n) {     vector<vector<long long> > I(n, vector<long long>(n));     for (int i = 0; i < n; ++i) I[i][i] = 1;     return I;   }   vector<vector<long long> > mul(vector<vector<long long> > &A,                                  vector<vector<long long> > &B, long long M) {     int l = A.size(), m = B.size(), n = B[0].size();     vector<vector<long long> > C(l, vector<long long>(n));     for (int i = 0; i < l; ++i)       for (int k = 0; k < m; ++k)         for (int j = 0; j < n; ++j)           C[i][j] = add(C[i][j], mul(A[i][k], B[k][j], M), M);     return C;   }   vector<vector<long long> > pow(vector<vector<long long> > A, long long b,                                  long long M) {     vector<vector<long long> > X = eye(A.size());     for (; b > 0; b >>= 1) {       if (b & 1) X = mul(X, A, M);       A = mul(A, A, M);     }     return X;   }   const long long mod = 1e9 + 7;   int main() {     ios_base::sync_with_stdio(0), cin.tie(0);     long long n, m;     cin >> n >> m;     vector<vector<long long> > M(m, vector<long long>(m));     for (int i = 0; i < m - 1; ++i) M[i][i + 1] = 1;     M[m - 1][0] = M[m - 1][m - 1] = 1;     M = pow(M, n, mod);     long long ans = 0;     for (auto i : M[0]) ans = (ans + i) % mod;     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1000000007;   const int N = 100010;   char s[N];   int fac[N], inv[N], sum[N];   long long mpow(long long a, long long b) {     long long ans = 1;     while (b) {       if (b & 1) ans = ans * a % mod;       a = a * a % mod;       b >>= 1;     }     return ans;   }   long long com(int n, int m) {     if (n < m) return 0;     return 1LL * fac[n] * inv[m] % mod * inv[n - m] % mod;   }   int main() {     int n, m;     scanf( %d%d , &n, &m);     scanf( %s , s + 1);     inv[0] = fac[0] = 1;     for (int i = 1; i <= n; i++) {       fac[i] = 1LL * fac[i - 1] * i % mod;       inv[i] = mpow(fac[i], mod - 2);       sum[i] = sum[i - 1] + s[i] -  0 ;     }     long long ans = 0;     for (int i = 1, base = 1; i <= n - m; i++, base = 10LL * base % mod) {       ans = (ans + com(n - i - 1, m - 1) * sum[n - i] % mod * base) % mod;       ans = (ans + com(n - i, m) * (s[n - i + 1] -  0 ) % mod * base) % mod;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N_MAX = 300010;   struct Point {     int x, y;   };   Point points[N_MAX];   int nPoint;   void outerInit() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     auto fi = new ifstream( test.inp );     if (*fi) {       cin.rdbuf(fi->rdbuf());     }   }   void readData() {     cin >> nPoint;     for (int i = 1; i <= nPoint; ++i) {       cin >> points[i].x >> points[i].y;     }   }   void solveData() {     int xMin = INT_MAX, yMin = INT_MAX;     int xMax = INT_MIN, yMax = INT_MIN;     for (int i = 1; i <= nPoint; ++i) {       xMin = min(xMin, points[i].x);       xMax = max(xMax, points[i].x);       yMin = min(yMin, points[i].y);       yMax = max(yMax, points[i].y);     }     int res3 = 0;     for (int i = 1; i <= nPoint; ++i) {       if (points[i].x != xMin && points[i].y != yMin) {         res3 = max(res3, 2 * (points[i].x - xMin + points[i].y - yMin));       }       if (points[i].x != xMin && points[i].y != yMax) {         res3 = max(res3, 2 * (points[i].x - xMin + yMax - points[i].y));       }       if (points[i].x != xMax && points[i].y != yMin) {         res3 = max(res3, 2 * (xMax - points[i].x + points[i].y - yMin));       }       if (points[i].x != xMax && points[i].y != yMax) {         res3 = max(res3, 2 * (xMax - points[i].x + yMax - points[i].y));       }     }     cout << res3;     for (int i = 4; i <= nPoint; ++i) {       cout <<     << 2 * (xMax - xMin + yMax - yMin);     }   }   int main() {     outerInit();     readData();     solveData();   }


#include <bits/stdc++.h>   using namespace std;   bool isPrime(int n) {     if (n <= 1) return false;     if (n <= 3) return true;     if (n % 2 == 0 || n % 3 == 0) return false;     for (int i = 5; i * i <= n; i = i + 6)       if (n % i == 0 || n % (i + 2) == 0) return false;     return true;   }   vector<long long int> prime;   void solve() {     long long int mid, i, j, k, l, m, n,         ans = 0, minn = INT_MAX, maxx = INT_MIN, x, sum = 0, c = 0, cc = 0,         odd = 0, even = 0, q, ab = 0, ba = 0, y, a, b, r, nn, xx;     string ss;     vector<long long int> v, vv;     set<long long int> s;     map<long long int, long long int> mp;     cin >> n;     for (i = 1; i <= sqrt(n); i++) {       if (i * i <= n) {         s.insert(i * i);       }       if (i * i * i <= n) {         s.insert(i * i * i);         continue;       }     }     cout << s.size() << endl;   }   int main() {     int t;     cin >> t;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long inf = 1e9 + 7;   long long tam(long long x) {     long long r = 0;     while (x > 0) {       x /= 10;       r++;     }     return r;   }   map<long long, long long> r[15];   long long pre[15];   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     long long n, k;     cin >> n >> k;     vector<pair<long long, long long> > v(n);     for (long long i = 0; i < n; i++) {       long long aux;       cin >> aux;       v[i].first = tam(aux);       v[i].second = aux % k;     }     pre[1] = 10 % k;     for (long long i = 2; i <= 12; i++) {       pre[i] = (pre[i - 1] * 10) % k;     }     long long res = 0;     for (long long i = 0; i < n; i++) {       long long sz = v[i].first;       long long rest = v[i].second;       r[sz][rest]++;       if ((pre[sz] * rest + rest) % k == 0) {         res--;       }     }     for (long long i = 0; i < n; i++) {       long long rest = v[i].second;       for (long long sz = 1; sz <= 11; sz++) {         long long now = (k - pre[sz] * rest) % k;         while (now < 0) now += k;         res += r[sz][now];       }     }     cout << res << endl;   }


#include <bits/stdc++.h>   using namespace std;   bool Primality(long long n) {     if (n < 2) return false;     if (n == 2) return true;     if (n % 2 == 0) return false;     for (long long i = 3; i * i <= n; i = i + 2)       if (n % i == 0) return false;     return true;   }   int main() {     long long n;     cin >> n;     for (long long i = 1; i <= 1000; i++) {       long long pr = (n * i) + 1;       if (!Primality(pr)) {         cout << i <<   n ;         break;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool p[10000001];   long h[10000001];   struct S {     long a, c;   } s[1000000];   int n;   int k;   long a[1000001];   int binl(int x) {     if (x == 2) return 0;     if (x > s[k - 1].a) return -1;     int mid = (0 + k - 1) / 2;     int l = 0, r = k - 1;     while (l <= r) {       mid = (l + r) / 2;       if (s[mid].a >= x && s[mid - 1].a < x && mid - 1 >= 0)         return mid;       else if (s[mid].a < x)         l = mid + 1;       else         r = mid - 1;     }     return -1;   }   int binr(int x) {     if (x >= s[k - 1].a) return k - 1;     int mid = (0 + k - 1) / 2;     int l = 0, r = k - 1;     while (l <= r) {       mid = (l + r) / 2;       if (s[mid].a <= x && s[mid + 1].a > x && mid + 1 < k)         return mid;       else if (s[mid].a < x)         l = mid + 1;       else         r = mid - 1;     }     return -1;   }   int main() {     ios_base::sync_with_stdio(false);     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];       h[a[i]]++;     }     for (int i = 2; i <= 10000000; i++) {       if (p[i] == 0) {         s[k].a = i;         s[k].c = 0;         for (int j = i; j <= 10000000; j += i) {           p[j] = 1;           s[k].c += h[j];         }         k++;       }     }     for (int i = 1; i < k; i++) s[i].c += s[i - 1].c;     int m;     long long l, r, ans;     cin >> m;     while (m--) {       cin >> l >> r;       int ll = binl(l);       int rr = binr(r);       if (ll == -1) {         cout << 0 << endl;         continue;       }       cout << s[rr].c - ((ll > 0) ? s[ll - 1].c : 0) << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mxn = 1e3 + 5;   int Set(int N, int pos) { return N = N | (1 << pos); }   int reset(int N, int pos) { return N = N & ~(1 << pos); }   bool check(int N, int pos) { return (bool)(N & (1 << pos)); }   struct data {     int U;     int V;     int idx;   };   vector<data> es, em;   vector<int> ans;   int par[mxn];   int unode[100005];   int vnode[100005];   int Find(int p) {     if (p == par[p]) return p;     return par[p] = Find(par[p]);   }   bool merge(int u, int v) {     u = Find(u);     v = Find(v);     if (u == v) return false;     par[v] = u;     return true;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     for (int i = 0; i < mxn; i++) par[i] = i;     int n, m;     cin >> n >> m;     for (int i = 0; i < m; i++) {       int u, v;       char c;       cin >> u >> v >> c;       unode[i] = u;       vnode[i] = v;       if (c ==  S )         es.push_back({u, v, i});       else {         em.push_back({u, v, i});         merge(u, v);       }     }     if (!(n & 1)) {       cout << -1 <<   n ;       return 0;     }     int cnt = 0;     for (auto i : es) {       if (merge(i.U, i.V)) {         ans.push_back(i.idx);         cnt++;       }     }     for (int i = 0; i < mxn; i++) par[i] = i;     for (auto i : ans) merge(unode[i], vnode[i]);     int tt = (n - 1) >> 1;     for (auto i : es) {       if (cnt == tt) break;       if (merge(i.U, i.V)) {         ans.push_back(i.idx);         cnt++;       }     }     if (cnt != tt) {       cout << -1 <<   n ;       return 0;     }     cnt = 0;     for (auto i : em) {       if (cnt == tt) break;       if (merge(i.U, i.V)) {         ans.push_back(i.idx);         cnt++;       }     }     if (cnt != tt) {       cout << -1 <<   n ;       return 0;     }     cout << n - 1 <<   n ;     for (auto i : ans) cout << i + 1 <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, m, i, j, k, sum = 0, cnt = 0, a[101];     cin >> n >> m;     vector<long long int> o;     for (i = 0; i < n; i++) {       cin >> a[i];       sum += a[i];     }     for (i = 0; i < m; i++) {       cin >> j;       j--;       sum -= a[j];       o.push_back(a[j]);     }     sort(o.rbegin(), o.rend());     for (i = 0; i < m; i++) {       if (o[i] < sum)         sum += sum;       else         sum += o[i];     }     cout << sum;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = (int)1e5 + 10;   int n, m, k;   int fa[MAXN];   int visit[MAXN];   vector<int> res;   struct node {     int x, y, id;     double w;     node() {}     node(int x_, int y_, double w_, int id_) {       x = x_;       y = y_;       w = w_;       id = id_;     }     friend bool operator<(const node &a, const node &b) { return a.w < b.w; }   };   vector<node> e1, e2;   int getfa(int x) {     if (fa[x] == x) return x;     return fa[x] = getfa(fa[x]);   }   int get_ans(double mid, int K = -1) {     static node e[MAXN];     for (int i = 0; i < e1.size(); i++) e1[i].w += mid;     for (int i = 1; i <= n; i++) fa[i] = i;     int cnt = 0;     merge(e1.begin(), e1.end(), e2.begin(), e2.end(), e) - e;     res.clear();     for (int i = 0; i < m; i++) {       if ((e[i].x == 1 || e[i].y == 1) && cnt == K) continue;       int x = getfa(e[i].x), y = getfa(e[i].y);       if (x != y) {         res.push_back(e[i].id);         if (e[i].x == 1 || e[i].y == 1) ++cnt;         fa[x] = y;       }     }     for (int i = 0; i < e1.size(); i++) e1[i].w -= mid;     return cnt;   }   int main() {     scanf( %d%d%d , &n, &m, &k);     for (int i = 1; i <= n; i++) fa[i] = i;     int las = n;     for (int i = 0; i < m; i++) {       int u, v, w;       scanf( %d%d%d , &u, &v, &w);       if (u == 1 || v == 1)         e1.push_back(node(u, v, (double)w, i + 1));       else         e2.push_back(node(u, v, (double)w, i + 1));       if (getfa(u) != getfa(v)) {         fa[getfa(u)] = getfa(v);         las--;       }     }     if (e1.size() < k || (las != 1)) {       printf( -1 n );       return 0;     }     sort(e1.begin(), e1.end());     sort(e2.begin(), e2.end());     double l = -1e6, r = 1e6, ans = -1;     if (get_ans(l) < k || get_ans(r) > k) {       printf( -1 n );       return 0;     }     for (int i = 1; i < 50; i++) {       int mid = (l + r) / 2.0;       if (get_ans(mid) >= k) {         ans = mid;         l = mid;       } else         r = mid;     }     get_ans(ans, k);     cout << res.size() << endl;     for (int i = 0; i < res.size(); i++) printf( %d  , res[i]);     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   double gen(double x, double y, double z) { return log(log(x)) + z * log(y); }   double gen(double x, double y) { return log(log(x)) + log(y); }   vector<pair<double, string> > genall(double x, double y, double z) {     vector<pair<double, string> > r;     if (x > 1.) {       r.push_back(pair<double, string>(gen(x, y, z),  x^y^z ));       r.push_back(pair<double, string>(gen(x, z, y),  x^z^y ));       r.push_back(pair<double, string>(gen(x, y * z),  (x^y)^z ));     }     if (y > 1.) {       r.push_back(pair<double, string>(gen(y, x, z),  y^x^z ));       r.push_back(pair<double, string>(gen(y, z, x),  y^z^x ));       r.push_back(pair<double, string>(gen(y, x * z),  (y^x)^z ));     }     if (z > 1.) {       r.push_back(pair<double, string>(gen(z, x, y),  z^x^y ));       r.push_back(pair<double, string>(gen(z, y, x),  z^y^x ));       r.push_back(pair<double, string>(gen(z, x * y),  (z^x)^y ));     }     return r;   }   int main() {     double x, y, z;     cin >> x >> y >> z;     if (x <= 1. && y <= 1. && z <= 1.) {       vector<pair<double, string> > r;       if (x == 1.) {         cout <<  x^y^z  << endl;         return 0;       }       if (y == 1.) {         cout <<  y^x^z  << endl;         return 0;       }       if (z == 1.) {         cout <<  z^x^y  << endl;         return 0;       }       auto v1 = genall(1. / x, y, z);       auto v2 = genall(x, 1. / y, z);       auto v3 = genall(x, y, 1. / z);       r.insert(r.end(), v1.begin(), v1.end());       r.insert(r.end(), v2.begin(), v2.end());       r.insert(r.end(), v3.begin(), v3.end());       auto it =           min_element(r.begin(), r.end(),                       [](pair<double, string> lhs, pair<double, string> rhs) {                         return lhs.first < rhs.first;                       });       cout << it->second << endl;     } else {       auto v = genall(x, y, z);       auto it =           max_element(v.begin(), v.end(),                       [](pair<double, string> lhs, pair<double, string> rhs) {                         return lhs.first < rhs.first;                       });       cout << it->second << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void run();   int main() {     ios::sync_with_stdio(0);     run();   }   int n;   int v[5001];   char s[5001];   int grundy[5001];   void run() {     cin >> s;     n = strlen(s);     vector<int> blob;     for (int i = 0; i < n; i++)       if (0 < i and i + 1 < n and s[i - 1] == s[i + 1])         blob.back()++;       else if (blob.empty() or blob.back())         blob.push_back(0);     if (not blob.empty() and blob.back() == 0) blob.pop_back();     static int can[5001];     for (int i = 1; i <= 5000; i++) {       for (int j = 0; j < i; j++) {         can[grundy[max(0, j - 1)] ^ grundy[max(0, i - j - 2)]] = i;       }       while (can[grundy[i]] == i) ++grundy[i];     }     int good = 0;     for (int i : blob) good ^= grundy[i];     cout << (good ?  First  :  Second ) << endl;     if (good) {       int id = 0;       for (int i = 1, x = 0; i + 1 < n; ++i, ++x) {         if (s[i - 1] == s[i + 1]) {           if (i > 1 and s[i - 2] != s[i + 0]) ++id, x = 0;           int val = good ^ grundy[blob[id]];           if (val == (grundy[max(0, x - 1)] ^ grundy[max(0, blob[id] - x - 2)])) {             cout << i + 1 << endl;             return;           }         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   int pa[5009], siz[5009], occ[5009], tots = 0;   bool yay;   vector<pair<int, pair<int, int> > > edges;   int finder(int node) {     if (pa[node] != node) {       return pa[node] = finder(pa[node]);     }     return node;   }   void uniter(int x, int y) {     x = finder(x);     y = finder(y);     if (x == y) {       return;     }     pa[y] = x;     siz[x] += siz[y];     occ[x] += occ[y];     if (tots - occ[x] < siz[x]) {       yay = false;     }     return;   }   int main() {     int i, j, t1, t2, t3, t4, n, ans = 0;     scanf( %d , &n);     for (i = 0; i < n - 1; i++) {       scanf( %d %d %d , &t1, &t2, &t3);       edges.push_back(make_pair(t3, make_pair(t1, t2)));     }     sort(edges.begin(), edges.end());     for (i = 1; i <= n; i++) {       pa[i] = i;       siz[i] = 1;       scanf( %d , &occ[i]);       tots += occ[i];     }     if (n == 1) {       printf( 0 n );       return 0;     }     ans = edges[0].first;     yay = true;     for (i = 0; i < n - 1;) {       j = i;       while (edges[i].first == edges[j].first && j < n - 1) {         uniter(edges[j].second.first, edges[j].second.second);         j++;       }       if (yay && j < n - 1) {         ans = edges[j].first;       }       i = j;     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     string s, s1;     cin >> s >> s1;     string s2;     cin >> s2;     map<char, char> m;     for (long long i = 0; i < 26; i++) {       m[s[i]] = s1[i];     }     string ans =   ;     long long cnt = 0;     for (long long i = 0; i < s2.size(); i++) {       if (s2[i] >= 48 && s2[i] <= 57) {         ans += s2[i];       } else if (isupper(s2[i])) {         s2[i] += 32;         char c = m[s2[i]];         c -= 32;         ans += c;       } else if (islower(s2[i])) {         ans += m[s2[i]];       }     }     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int arr[3000000];   long long fadd[3000000];   long long carry[3000000];   long long tot[3000000];   int main() {     ios_base::sync_with_stdio(0);     int n;     cin >> n;     for (int i = 0; i < n; i++) cin >> arr[i];     int nsize = 2 * n + 1;     for (int i = 0; i < nsize; i++) fadd[i] = carry[i] = tot[i] = 0;     for (int i = 0; i < n; i++) {       int k = i + 1;       int x = arr[i];       fadd[n - k + 1] += x - 1;       carry[n - k + 1] -= 1;       carry[n - k + x] += 2;       carry[2 * n - k] -= 1;       fadd[2 * n - k + 1] += x - n;     }     long long ctot = 0;     long long ccarry = 0;     for (int i = 0; i < nsize; i++) {       ctot += fadd[i] + ccarry;       ccarry += carry[i];       tot[i] = ctot;       if (i >= n) tot[i % n] += tot[i];     }     long long ans = 1e12;     int bval = 0;     for (int i = 0; i < n; i++) {       if (tot[i] < ans) {         ans = tot[i];         bval = i;       }     }     cout << ans <<     << bval <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   long long n, sx, sy, dx, dy, t;   struct matrix {     long long m[8][8];     matrix() { memset(m, 0, sizeof(m)); }   };   matrix mul(matrix a, matrix b) {     matrix tmp;     for (int i = 1; i <= 6; i++)       for (int k = 1; k <= 6; k++)         if (a.m[i][k])           for (int j = 1; j <= 6; j++)             tmp.m[i][j] = (tmp.m[i][j] + a.m[i][k] * b.m[k][j] + n) % n;     return tmp;   }   matrix powmul(matrix a, long long t) {     matrix tmp;     for (int i = 1; i <= 6; i++) tmp.m[i][i] = 1;     while (t) {       if (t & 1) tmp = mul(tmp, a);       a = mul(a, a);       t >>= 1;     }     return tmp;   }   int main() {     scanf( %lld%lld%lld%lld%lld%lld , &n, &sx, &sy, &dx, &dy, &t);     matrix base;     base.m[1][2] = base.m[1][3] = base.m[1][5] = 1;     base.m[2][1] = base.m[2][4] = base.m[2][5] = 1;     base.m[3][1] = base.m[3][2] = base.m[3][3] = base.m[3][5] = 1;     base.m[4][1] = base.m[4][2] = base.m[4][4] = base.m[4][5] = 1;     base.m[5][5] = base.m[5][6] = base.m[6][6] = 1;     base.m[2][2] = base.m[1][1] = base.m[1][6] = base.m[2][6] = base.m[3][6] =         base.m[4][6] = 2;     base = powmul(base, t);     matrix ans;     ans.m[1][1] = sx - 1;     ans.m[2][1] = sy - 1;     ans.m[3][1] = (dx % n + n) % n;     ans.m[4][1] = (dy % n + n) % n;     ans.m[6][1] = 1;     ans = mul(base, ans);     printf( %lld %lld n , ans.m[1][1] + 1, ans.m[2][1] + 1);   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 400007;   int n, I, cnt = 0, ret = -1;   int a[maxn], s[maxn];   int ck() {     int ans = 1;     for (int i = 1; i <= 8 * I / n; ++i) {       ans *= 2;       if (ans > cnt) return -1;     }     return ans;   }   int main() {     scanf( %d%d , &n, &I);     for (int i = 1; i <= n; ++i) {       scanf( %d , &a[i]);     }     memset(s, 0, sizeof(s));     sort(a + 1, a + n + 1);     for (int i = 1; i <= n; ++i) {       if (a[i] != ret) {         ret = a[i], cnt++;       }       s[cnt]++;     }     for (int i = 1; i <= cnt; ++i) {       s[i] += s[i - 1];     }     int pI = ck();     if (pI == -1) {       printf( %d n , 0);       return 0;     }     int ans = 0;     for (int i = pI; i <= cnt; ++i) {       ans = max(ans, s[i] - s[i - pI]);     }     printf( %d n , n - ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   string ss;   int dp[200005][4];   char s[] = { R ,  G ,  B };   int calc(int u, int c) {     if (u == n) return 0;     if (dp[u][c] != -1) return dp[u][c];     int ret = n;     for (int i = 0; i < 3; i++) {       if (i == c) continue;       if (s[i] == ss[u])         ret = min(ret, calc(u + 1, i));       else         ret = min(ret, 1 + calc(u + 1, i));     }     return dp[u][c] = ret;   }   void print(int u, int c) {     if (u == n) return;     for (int i = 0; i < 3; i++) {       if (i == c) continue;       if (s[i] == ss[u]) {         if (dp[u][c] == calc(u + 1, i)) {           printf( %c , s[i]);           print(u + 1, i);           return;         }       } else {         if (dp[u][c] == 1 + calc(u + 1, i)) {           printf( %c , s[i]);           print(u + 1, i);           return;         }       }     }   }   int main() {     memset(dp, -1, sizeof dp);     cin >> n;     cin >> ss;     int ans = calc(0, 3);     cout << ans << endl;     print(0, 3);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, Q;   int cnt_bad = 0;   bool bad[2][100100];   int main() {     scanf( %d%d , &n, &Q);     memset(bad, 0, sizeof(bad));     for (int i = 0; i < Q; i++) {       int x, y;       scanf( %d%d , &x, &y);       x--, y--;       if (bad[x][y]) {         bad[x][y] = 0;         if (y - 1 >= 0) cnt_bad -= bad[x ^ 1][y - 1];         cnt_bad -= bad[x ^ 1][y];         if (y + 1 < n) cnt_bad -= bad[x ^ 1][y + 1];       } else {         bad[x][y] = 1;         if (y - 1 >= 0) cnt_bad += bad[x ^ 1][y - 1];         cnt_bad += bad[x ^ 1][y];         if (y + 1 < n) cnt_bad += bad[x ^ 1][y + 1];       }       if (cnt_bad == 0)         printf( Yes n );       else         printf( No n );     }     return 0;   }


#include <bits/stdc++.h>   int main() {     int NumOfStudent;     int NumOfTeams;     int ones = 0, twos = 0, threes = 0;     int i, k, l, j, c, m, n, p;     int a[5000];     scanf( %d , &NumOfStudent);     for (i = 0; i < NumOfStudent; i++) {       scanf( %d , &a[i]);     }     for (i = 0; i < NumOfStudent; i++) {       m = 0;       n = 0;       p = 0;       for (m = 0; m < NumOfStudent; m++) {         if (a[m] == 1) {           ones = ones + 1;         }       }       for (n = 0; n < NumOfStudent; n++) {         if (a[n] == 2) {           twos = twos + 1;         }       }       for (p = 0; p < NumOfStudent; p++) {         if (a[p] == 3) {           threes = threes + 1;         }       }       int b[3] = {ones, twos, threes};       NumOfTeams = b[0];       for (c = 1; c < 3; c++) {         if (b[c] < NumOfTeams) {           NumOfTeams = b[c];         }       }       printf(  n%d , NumOfTeams);       if (ones == 0 || twos == 0 || threes == 0) {       } else {         i = 0;         j = 0;         k = 0;         l = 0;         for (j = 0; j < NumOfTeams; j++) {           while (i < NumOfStudent && a[i] != 1) {             i++;           }           a[i] = 0;           printf(  n%d  , i + 1);           while (k < NumOfStudent && a[k] != 2) {             k++;           }           a[k] = 0;           printf( %d  , k + 1);           while (l < NumOfStudent && a[l] != 3) {             l++;           }           a[l] = 0;           printf( %d  , l + 1);         }       }       return 0;     }   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 1e9;   const int N = 142123;   int n, a, b, c, d, s, ce;   long long ans;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n >> a >> b >> ce >> d;     for (int i = 1; i <= n; ++i) {       s = a + b + i;       c = s - a - ce;       if (c < 1 || n < c) continue;       c = s - b - d;       if (c < 1 || n < c) continue;       c = s - ce - d;       if (c < 1 || n < c) continue;       ans += n;     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 998244353;   char s[1010];   int n, fa[2010], val[2010], pw2[2010], ans = 0;   inline int getf(int x) {     if (x == fa[x]) return x;     int f = getf(fa[x]);     val[x] ^= val[fa[x]];     fa[x] = f;     return f;   }   inline int merge(int x, int y, int w) {     int ti = getf(x), tj = getf(y);     if (ti == tj) return w == (val[x] ^ val[y]);     w ^= val[x] ^ val[y];     fa[ti] = tj;     val[ti] = w;     return 1;   }   int main() {     scanf( %s , s + 1);     n = strlen(s + 1);     reverse(s + 1, s + n + 1);     pw2[0] = 1;     for (int i = 1; i <= n; i++) pw2[i] = (pw2[i - 1] + pw2[i - 1]) % mod;     int ans = 0;     for (int lena = n - 1; lena >= 1; lena--) {       for (int j = 1; j <= ((n << 1) + 1); j++) fa[j] = j, val[j] = 0;       if (!merge((n), ((n << 1) + 1), 0)) continue;       if (!merge((n + n), ((n << 1) + 1), 1)) continue;       bool fail = 0;       for (int j = 1; j <= n / 2; j++) {         if (!merge((j + n), (n + 1 - j + n), 0)) {           fail = 1;           break;         }       }       if (fail) continue;       for (int j = 1; j <= lena / 2; j++) {         if (!merge((j), (lena + 1 - j), 0)) {           fail = 1;           break;         }       }       if (fail) continue;       for (int j = lena + 1; j < n; j++) {         if (!merge((j), ((n << 1) + 1), 0)) {           fail = 1;           break;         }       }       if (!merge((lena), ((n << 1) + 1), 1)) fail = 1;       if (fail) continue;       for (int j = 1; j <= n; j++) {         if (s[j] ==  0 ) {           if (!merge((j), (j + n), 0)) {             fail = 1;             break;           }         } else if (s[j] ==  1 ) {           if (!merge((j), (j + n), 1)) {             fail = 1;             break;           }         }       }       if (fail) continue;       int cnt = 0;       for (int j = 1; j <= ((n << 1) + 1); j++)         if (getf(j) == j && getf(j) != getf(((n << 1) + 1))) cnt++;       ans = (ans + pw2[cnt]) % mod;     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int read() {     int a = 0;     char c = getchar();     while (!isdigit(c)) c = getchar();     while (isdigit(c)) {       a = a * 10 + c - 48;       c = getchar();     }     return a;   }   const double pi = acos(-1);   struct comp {     double x, y;     comp(double _x = 0, double _y = 0) : x(_x), y(_y) {}     friend comp operator+(comp x, comp y) { return comp(x.x + y.x, x.y + y.y); }     friend comp operator-(comp x, comp y) { return comp(x.x - y.x, x.y - y.y); }     friend comp operator*(comp x, comp y) {       return comp(x.x * y.x - x.y * y.y, x.y * y.x + x.x * y.y);     }     friend comp operator/(comp x, double y) { return comp(x.x / y, x.y / y); }   };   const int _ = 1 << 15;   int dir[_], need;   comp w[_];   void init(int len) {     need = 1;     while (need < len) need <<= 1;     for (int i = 1; i < need; ++i)       dir[i] = (dir[i >> 1] >> 1) | (i & 1 ? need >> 1 : 0);     static int L = 1;     for (int &i = L; i < need; i <<= 1) {       w[i] = comp(1, 0);       comp wn(cos(pi / i), sin(pi / i));       for (int j = 1; j < i; ++j) w[i + j] = w[i + j - 1] * wn;     }   }   void DFT(comp *arr, int tp) {     for (int i = 0; i < need; ++i)       if (i < dir[i]) swap(arr[i], arr[dir[i]]);     for (int i = 1; i < need; i <<= 1)       for (int j = 0; j < need; j += i << 1)         for (int k = 0; k < i; ++k) {           comp x = arr[j + k], y = arr[i + j + k] * w[i + k];           arr[j + k] = x + y;           arr[i + j + k] = x - y;         }     if (tp == -1) {       reverse(arr + 1, arr + need);       for (int i = 0; i < need; ++i) arr[i] = arr[i] / need;     }   }   int N, M, t, x, S[103], T[103], W[103], dist[53];   double ans[53][_], tmp[103][_], tms[103][_], sum[103][_];   comp pot[53][_];   void divide(int l, int r) {     if (l == r) {       for (int i = 1; i < N; ++i) ans[i][l] = 1e60;       for (int i = 1; i <= M; ++i)         ans[S[i]][l] =             min(ans[S[i]][l],                 tmp[i][l] + W[i] + (x + dist[T[i]]) * sum[i][t + 1 - l]);       return;     }     int mid = (l + r) >> 1;     divide(mid + 1, r);     init(r - l);     for (int p = 1; p < N; ++p) {       memset(&pot[p], 0, sizeof(comp) * need);       for (int i = mid + 1; i <= r; ++i) pot[p][i - mid - 1].x = ans[p][i];       DFT(pot[p], 1);     }     for (int p = 1; p <= M; ++p) {       memset(&pot[0], 0, sizeof(comp) * need);       for (int i = 0; i < r - l; ++i) pot[0][i] = tms[p][r - l - i];       DFT(pot[0], 1);       for (int i = 0; i < need; ++i) pot[0][i] = pot[0][i] * pot[T[p]][i];       DFT(pot[0], -1);       for (int i = l; i <= mid; ++i) tmp[p][i] += pot[0][r - mid - 1 + i - l].x;     }     divide(l, mid);   }   int main() {     N = read();     M = read();     t = read();     x = read();     for (int i = 1; i < N; ++i) dist[i] = 1e9;     for (int i = 1; i <= M; ++i) {       S[i] = read();       T[i] = read();       W[i] = read();       for (int j = 1; j <= t; ++j) tms[i][j] = read();     }     for (int i = 1; i <= N; ++i)       for (int j = 1; j <= M; ++j)         dist[S[j]] = min(dist[S[j]], dist[T[j]] + W[j]);     for (int i = 1; i <= M; ++i)       for (int j = t; j; --j) sum[i][j] = sum[i][j + 1] + (tms[i][j] /= 1e5);     divide(0, t);     printf( %.9lf n , (double)ans[1][0]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 15;   const int M = 11005;   const int mo1 = 317503;   const int mo2 = 1000000007;   const int BAS = 2333;   const int P = 3000005;   int n, m, k, Hash[N], bel[N], tot, matching[M][N][2], temp_matching[N][2],       bin[N];   long long ans, jc[N];   vector<int> e[N];   int ls[mo1], nx[P], key[P], tot_hash;   bool vis[N], trans[N][N][N][N], f[5005][N];   void add_hash(int *Hash) {     int h1 = 0, h2 = 0;     for (int i = 1; i <= n; i++) {       h1 = ((long long)h1 * BAS + Hash[i]) % mo1;       h2 = ((long long)h2 * BAS + Hash[i]) % mo2;     }     for (int i = ls[h1]; i; i = nx[i])       if (key[i] == h2) return;     key[++tot_hash] = h2;     nx[tot_hash] = ls[h1];     ls[h1] = tot_hash;   }   bool find_hash(int *Hash) {     int h1 = 0, h2 = 0;     for (int i = 1; i <= n; i++) {       h1 = ((long long)h1 * BAS + Hash[i]) % mo1;       h2 = ((long long)h2 * BAS + Hash[i]) % mo2;     }     for (int i = ls[h1]; i; i = nx[i])       if (key[i] == h2) return 1;     return 0;   }   void dfs_matching(int x) {     if (x > n / 2) {       tot++;       for (int i = 1; i <= n / 2; i++) {         matching[tot][i][0] = temp_matching[i][0];         matching[tot][i][1] = temp_matching[i][1];       }       return;     }     int u;     for (int i = 1; i <= n; i++)       if (!vis[i]) {         u = i;         vis[i] = 1;         break;       }     temp_matching[x][0] = u;     for (int j = u + 1; j <= n; j++)       if (!vis[j]) {         temp_matching[x][1] = j;         vis[j] = 1;         dfs_matching(x + 1);         vis[j] = 0;       }     vis[u] = 0;   }   void dfs_half_divide(int x, int y, int id) {     if (x > n / 2) {       for (int i = 1; i <= n / 2; i++)         Hash[matching[id][i][0]] = Hash[matching[id][i][1]] = bel[i];       add_hash(Hash);       return;     }     for (int i = 1; i <= y; i++) {       bel[x] = i;       dfs_half_divide(x + 1, y, id);     }     bel[x] = y + 1;     dfs_half_divide(x + 1, y + 1, id);   }   void dfs_divide(int x, int y) {     if (x > n) {       for (int i = 1; i <= n; i++) Hash[i] = bel[i];       if (find_hash(Hash) && y <= k) ans += jc[k] / jc[k - y];       return;     }     for (int i = 1; i <= y; i++) {       bel[x] = i;       dfs_divide(x + 1, y);     }     bel[x] = y + 1;     dfs_divide(x + 1, y + 1);   }   void pre_matching() {     bin[0] = 1;     for (int i = 1; i <= n; i++) bin[i] = bin[i - 1] * 2;     for (int u = 1; u <= n; u++)       for (int v = 1; v <= n; v++)         for (int i : e[u])           for (int j : e[v]) trans[u][v][i][j] = 1;     for (int i = 1; i <= tot; i++) {       memset(f, 0, sizeof(f));       for (int j = 1; j <= n / 2; j++) f[bin[j - 1]][j] = 1;       for (int j = 1; j < bin[n / 2] - 1; j++)         for (int k = 1; k <= n / 2; k++) {           int u = matching[i][k][0], v = matching[i][k][1];           if (f[j][k]) {             for (int l = 1; l <= n / 2; l++)               if (!(j & bin[l - 1])) {                 int p = matching[i][l][0], q = matching[i][l][1];                 f[j + bin[l - 1]][l] |= trans[u][v][p][q] | trans[u][v][q][p];               }           }         }       bool tag = 0;       for (int j = 1; j <= n / 2; j++) {         int u = matching[i][j][0], v = matching[i][j][1];         tag |= f[bin[n / 2] - 1][j] & trans[u][v][v][u];       }       if (tag) dfs_half_divide(1, 0, i);     }   }   int main() {     scanf( %d%d%d , &n, &m, &k);     for (int i = 1; i <= m; i++) {       int x, y;       scanf( %d%d , &x, &y);       e[x].push_back(y);       e[y].push_back(x);     }     jc[0] = 1;     for (int i = 1; i <= k; i++) jc[i] = jc[i - 1] * i;     dfs_matching(1);     pre_matching();     dfs_divide(1, 0);     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int TESTS = 1;     while (TESTS--) {       int n;       cin >> n;       vector<long long int> a(n);       for (long long int i = 0; i < n; i++) cin >> a[i];       sort((a).begin(), (a).end());       int c = 0;       for (long long int i = 0; i < n; i++) {         int m = upper_bound((a).begin(), (a).end(), a[i] + 5) - a.begin() - i;         if (m > c) c = m;       }       cout << c;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int k = 0;     cin >> k;     int maxi = 0;     for (int i = 0; i < k; i++) {       int inp;       cin >> inp;       maxi = max(maxi, inp);     }     cout << max(0, maxi - 25) << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 20;   int ans, a, m, n;   long long ps0[N], ps1[N], arr[N], inf = 1e10 + 100;   int main() {     ios::sync_with_stdio(0), cin.tie(0);     cin >> n >> arr[0];     arr[n] = inf;     ps0[0] = 0;     for (int i = 1; i < n; i++) {       cin >> arr[i];       ps0[i] = ps0[i - 1] + arr[i] - arr[i - 1];     }     ps1[n - 1] = 0;     for (int i = n - 2; i >= 0; i--) {       ps1[i] = arr[i + 1] - arr[i] + ps1[i + 1];     }     cout << arr[1] - arr[0] <<     << ps1[0] << endl;     for (int i = 1; i < n; i++) {       cout << min(arr[i] - arr[i - 1], arr[i + 1] - arr[i]) <<                << max(ps0[i], ps1[i]) << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = (int)1e6 + 100;   const long long inf = (1ll << 60);   const int mod2 = (int)998244353;   const int mod = (int)1e9 + 7;   int n, m;   struct query {     int type;     int x1, y1, x2, y2;     long long v;   } Q[maxn];   struct fenwick {     long long a[1010][1010];     void clear() { memset(a, 0, sizeof a); }     long long get(int x, int y) {       long long res = 0;       for (int i = x; i >= 0; i = (i & (i + 1)) - 1) {         for (int j = y; j >= 0; j = (j & (j + 1)) - 1) {           res ^= a[i][j];         }       }       return res;     }     void update(int x, int y, long long c) {       for (int i = x; i <= n; i |= i + 1) {         for (int j = y; j <= n; j |= j + 1) {           a[i][j] ^= c;         }       }     }     long long get(int x1, int y1, int x2, int y2) {       return get(x2, y2) ^ get(x1 - 1, y2) ^ get(x2, y1 - 1) ^              get(x1 - 1, y1 - 1);     }   } F[2][2];   long long get(int x1, int y1) { return F[x1 % 2][y1 % 2].get(x1, y1); }   long long get(int x1, int y1, int x2, int y2) {     return get(x2, y2) ^ get(x1 - 1, y2) ^ get(x2, y1 - 1) ^ get(x1 - 1, y1 - 1);   }   void update(int x1, int y1, long long c) {     F[x1 % 2][y1 % 2].update(x1, y1, c);   }   void updateRange(int x1, int y1, int x2, int y2, long long c) {     update(x1, y1, c);     update(x2 + 1, y1, c);     update(x1, y2 + 1, c);     update(x2 + 1, y2 + 1, c);   }   void solve() {     cin >> n >> m;     for (int i = 0; i < m; i++) {       int type, x1, y1, x2, y2;       cin >> type >> x1 >> y1 >> x2 >> y2;       if (type == 2) {         long long v;         cin >> v;         updateRange(x1, y1, x2, y2, v);       } else {         cout << get(x1, y1, x2, y2) <<   n ;       }     }   };   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t = 1;     for (int i = 1; i <= t; i++) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, tans, a[100005], qaq[100005], que[1 << 15];   bool vis[1 << 15];   struct node {     int x, y, z;   } ans[100005 << 1];   struct node2 {     int ty, lst, pos;   } pre[1 << 15];   void ins(int x, int y, int z) {     a[x] ^= 1, a[y] ^= 1, a[z] ^= 1;     ans[++tans] = (node){x, y, z};   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     int sour = 0;     int h = 1, t = 1, yn = min(n, 12);     que[1] = sour, vis[sour] = 1;     while (h <= t) {       int tmp = que[h++];       for (int i = 0; i < yn; i++) qaq[i] = (tmp & (1 << i)) != 0;       for (int ty = 1; ty <= 6; ty++)         for (int j = 0; j < yn - ty * 2; j++) {           qaq[j] ^= 1, qaq[j + ty] ^= 1, qaq[j + 2 * ty] ^= 1;           int ttmp = 0;           for (int j = 0; j < yn; j++) ttmp += qaq[j] * (1 << j);           if (!vis[ttmp])             vis[que[++t] = ttmp] = 1, pre[ttmp] = (node2){ty, tmp, j + 1};           qaq[j] ^= 1, qaq[j + ty] ^= 1, qaq[j + 2 * ty] ^= 1;         }     }     int tmp;     for (tmp = n - 6; tmp >= 7; tmp -= 6) {       int tcnt = 0, tt = 0;       for (int i = tmp + 1; i <= tmp + 6; i++) tcnt += a[i];       if (tcnt == 6)         ins(tmp + 1, tmp + 2, tmp + 3), ins(tmp + 4, tmp + 5, tmp + 6);       else if (tcnt == 5) {         if (a[tmp + 4] == 0)           ins(tmp + 1, tmp + 3, tmp + 5), ins(tmp - 2, tmp + 2, tmp + 6);         else if (a[tmp + 1] == 0)           ins(tmp + 3, tmp + 4, tmp + 5), ins(tmp - 2, tmp + 2, tmp + 6);         else {           for (int i = tmp + 4; i > tmp; i--)             if (a[i] && a[i + 1] && a[i + 2]) {               ins(i, i + 1, i + 2);               break;             }           for (int i = tmp + 1; i <= tmp + 6; i++)             if (a[i]) que[++tt] = i;           ins(que[1] - que[2] + que[1], que[1], que[2]);         }       } else if (tcnt) {         for (int i = tmp + 1; i <= tmp + 6; i++)           if (a[i]) que[++tt] = i;         sort(que + 1, que + tt + 1);         if (tcnt == 1)           ins(tmp - que[1] + tmp, tmp, que[1]);         else if (tcnt == 2)           ins(tmp - que[1] + tmp, tmp, que[1]),               ins(tmp - que[2] + tmp, tmp, que[2]);         else if (tcnt == 3) {           if (que[3] - que[1] == 2)             ins(que[1], que[2], que[3]);           else             ins(que[1] - que[3] + que[1], que[1], que[3]),                 ins(tmp - que[2] + tmp, tmp, que[2]);         } else {           if (que[3] - que[1] == 2)             ins(que[1], que[2], que[3]), ins(tmp - que[4] + tmp, tmp, que[4]);           else if (que[4] - que[2] == 2)             ins(que[2], que[3], que[4]), ins(tmp - que[1] + tmp, tmp, que[1]);           else             ins(que[1] - que[3] + que[1], que[1], que[3]),                 ins(que[2] - que[4] + que[2], que[2], que[4]);         }       }     }     int endr = 0;     for (int i = 1; i <= min(n, 12); i++) endr += a[i] * (1 << i - 1);     if (!vis[endr]) return 0 * puts( NO );     puts( YES );     while (endr != sour) {       ins(pre[endr].pos, pre[endr].pos + pre[endr].ty,           pre[endr].pos + 2 * pre[endr].ty);       endr = pre[endr].lst;     }     printf( %d n , tans);     for (int i = 1; i <= tans; i++)       printf( %d %d %d n , ans[i].x, ans[i].y, ans[i].z);   }


#include <bits/stdc++.h>   using namespace std;   int di[] = {0, 0, 1, -1, 1, 1, -1, -1};   int dj[] = {1, -1, 0, 0, -1, 1, 1, -1};   const double PI = 3.14159265359, EPS = 1e-9;   const int N = 1000006, M = 1000006, Mod = 1000000007;   vector<int> adj[N];   pair<int, int> tree[4 * N];   int n;   string str;   void build(int idx, int s, int e) {     if (s == e) {       if (str[s] ==  ( ) ++tree[idx].first;       if (str[s] ==  ) ) ++tree[idx].second;       return;     }     int m = (s + e) / 2;     build(idx << 1, s, m);     build(idx << 1 | 1, m + 1, e);     tree[idx].first = tree[idx << 1 | 1].first +                       max(0, tree[idx << 1].first - tree[idx << 1 | 1].second);     tree[idx].second = tree[idx << 1].second +                        max(0, tree[idx << 1 | 1].second - tree[idx << 1].first);   }   pair<int, int> maxx(int l, int r, int idx, int s, int e) {     if (l > e || r < s) return pair<int, int>(0, 0);     if (l <= s && r >= e) return tree[idx];     int m = (s + e) / 2;     pair<int, int> p1 = maxx(l, r, idx << 1, s, m);     pair<int, int> p2 = maxx(l, r, idx << 1 | 1, m + 1, e);     pair<int, int> ret;     ret.first = p2.first + max(0, p1.first - p2.second);     ret.second = p1.second + max(0, p2.second - p1.first);     return ret;   }   int main() {     ios::sync_with_stdio(false), cin.tie(0), cout.tie(0), cout.precision(10),         cout << fixed;     cin >> str;     str =  s  + str;     n = (int)str.size();     build(1, 1, n);     int m;     cin >> m;     int l, r;     while (m--) {       cin >> l >> r;       pair<int, int> p = maxx(l, r, 1, 1, n);       cout << r - l + 1 - p.first - p.second <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   int main() {     int n, x, i, min = 0;     scanf( %d , &n);     for (i = 0; i < n; i++) {       scanf( %d , &x);       min += 15;       if (min >= x)         min = x;       else         break;     }     if (i == n) min += 15;     if (min >= 90)       printf( 90 n );     else       printf( %d n , min);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     long long int n, k;     cin >> n >> k;     string ans;     ans += to_string(k);     if (k == 10 && n == 1) {       cout << -1;       return 0;     }     int bound = n - 1;     if (k == 10) bound--;     for (int i = 1; i <= bound; i++) {       ans +=  0 ;     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int arr[n];     for (int i = 0; i < 7; i++) {       cin >> arr[i];     }     int day = 1;     int i = 0;     while (n > 0) {       n = n - arr[i];       i++;       if (n > 0) {         day++;       }       if (day > 7) {         day = 1;       }       if (i == 7) {         i = 0;       }     }     cout << day;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2000;   const int INF = 1e9 + 7;   int le, ri, tot, cpt[60][60], fir[maxn], sec[maxn];   struct MCMF {     struct Edge {       int from, to, cap, cost;       Edge() {}       Edge(int from, int to, int cap, int cost)           : from(from), to(to), cap(cap), cost(cost) {}     };     int n, m, s, t;     vector<Edge> edges;     vector<int> G[maxn];     int inq[maxn];     int d[maxn];     int p[maxn];     int a[maxn];     void init() {       for (int i = 0; i <= n; ++i) G[i].clear();       edges.clear();     }     void AddEdge(int from, int to, int cap, int cost) {       edges.push_back(Edge(from, to, cap, cost));       edges.push_back(Edge(to, from, 0, -cost));       m = edges.size();       G[from].push_back(m - 2);       G[to].push_back(m - 1);     }     bool BF(int& flow, int& cost) {       for (int i = 1; i <= n; ++i) d[i] = INF, inq[i] = 0;       d[s] = 0, inq[s] = 1, p[s] = 0, a[s] = INF;       queue<int> Q;       Q.push(s);       while (!Q.empty()) {         int u = Q.front();         Q.pop();         inq[u] = 0;         for (int i = 0; i < G[u].size(); ++i) {           Edge& e = edges[G[u][i]];           if (e.cap && d[e.to] > d[u] + e.cost) {             d[e.to] = d[u] + e.cost;             p[e.to] = G[u][i];             a[e.to] = min(a[u], e.cap);             if (!inq[e.to]) {               Q.push(e.to);               inq[e.to] = 1;             }           }         }       }       if (d[t] == INF) return false;       flow += a[t];       cost += d[t] * a[t];       int u = t;       while (u != s) {         edges[p[u]].cap -= a[t];         edges[p[u] ^ 1].cap += a[t];         u = edges[p[u]].from;       }       return true;     }     int Mincost() {       int flow = 0, cost = 0;       while (BF(flow, cost))         ;       for (int i = le + 1; i < t; ++i) {         if (!edges[G[i][1]].cap)           cpt[fir[i]][sec[i]] = 1, cpt[sec[i]][fir[i]] = 0;         else           cpt[fir[i]][sec[i]] = 0, cpt[sec[i]][fir[i]] = 1;       }       return cost;     }   } NF;   inline int read() {     int x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = (x << 1) + (x << 3) + (ch ^ 48);       ch = getchar();     }     return x;   }   inline void readin() {     int temp, win[60] = {0}, du[60] = {0}, wwin, llos;     le = read(), ri = read();     for (int i = 1; i <= le; ++i)       for (int j = 1; j <= le; ++j)         if (i != j) cpt[i][j] = 2;     NF.s = 0;     temp = le + 1;     for (int i = 1; i <= ri; ++i) {       wwin = read();       llos = read();       cpt[wwin][llos] = 1;       cpt[llos][wwin] = 0;     }     for (int i = 1; i <= le; ++i)       for (int j = 1; j <= le; ++j)         if (cpt[i][j] == 2) {           if (i > j) continue;           fir[temp] = i;           sec[temp] = j;           NF.AddEdge(0, temp, 1, 0);           NF.AddEdge(temp, i, 1, 0);           NF.AddEdge(temp++, j, 1, 0);           ++du[i];           ++du[j];         } else           win[i] += cpt[i][j];     NF.n = NF.t = temp;     for (int i = 1; i <= le; ++i) {       tot += win[i] * win[i];       for (int j = 1; j <= du[i]; ++j)         NF.AddEdge(i, NF.t, 1, 2 * (win[i] + j) - 1);     }   }   int main() {     NF.init();     readin();     int p = NF.Mincost();     for (int i = 1; i <= le; ++i, puts(  ))       for (int j = 1; j <= le; ++j) printf( %d , cpt[i][j]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, d = 2, m = 4127, f = 0, c = 0;     cin >> n;     while (n--) {       int a, b;       cin >> a >> b;       if (f == 0) {         f = 1;         m = a;       } else {         if (a < m) m = a;       }       if (b != a) c = 1;       if (a > m) d = 0;     }     if (c == 1)       cout <<  rated ;     else {       if (d == 0)         cout <<  unrated ;       else         cout <<  maybe ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = (1 << 20) + 10;   const double PI = acos(-1);   double dp[MAXN];   int N;   double L, R;   double x[22], y[22], a[22];   int main() {     memset(dp, 0, sizeof(dp));     scanf( %d%lf%lf , &N, &L, &R);     for (int ni = 0; ni < N; ni++) {       scanf( %lf%lf%lf , x + ni, y + ni, a + ni);       a[ni] = a[ni] * PI / 180;     }     int imax = 1 << N;     for (int i = 0; i < imax; i++) dp[i] = L;     bool flag = false;     double ans = L;     for (int i = 0; i < imax; i++) {       if (flag) break;       for (int j = 0; j < N; j++) {         int tmpj = 1 << j;         if (i & tmpj) continue;         double dist = sqrt((dp[i] - x[j]) * (dp[i] - x[j]) + y[j] * y[j]);         double alpha = acos((dp[i] - x[j]) / dist);         if (alpha <= a[j]) {           flag = true;           ans = R;           break;         }         double beta = alpha - a[j];         int tmpi = i | tmpj;         dp[tmpi] = max(dp[tmpi], dp[i] + dist * sin(a[j]) / sin(beta));         ans = max(dp[tmpi], ans);         if (fabs(ans - R) < 1e-6 || ans >= R) {           flag = true;           ans = R;           break;         }       }     }     printf( %.9lf n , ans - L);     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimization( O3 )   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long t;     cin >> t;     while (t) {       int n, m;       cin >> n >> m;       vector<pair<int, int>> v;       vector<int> orig;       for (int i = 0; i < m; i++) {         int a;         cin >> a;         orig.push_back(a);         v.push_back({a, -i});       }       sort(v.begin(), v.end());       vector<int> rank(m);       for (int i = 0; i < m; i++) rank[-v[i].second] = i;       int ans = 0;       vector<int> s;       for (int i = 0; i < m; i++) {         int pos = rank[i];         for (int i = 0; i < s.size(); i++) {           if (pos > s[i]) ans++;         }         s.push_back(pos);       }       cout << ans <<   n ;       t--;     }   }


#include <bits/stdc++.h>   using namespace std;   bool prime(int x) {     for (int i = 2; i * i <= x; i++) {       if (x % i == 0) return 0;     }     return 1;   }   int main() {     int n;     vector<int> ans;     cin >> n;     for (int i = 2; i <= n; ++i) {       if (prime(i)) {         for (int j = i; j <= n; j *= i) {           ans.push_back(j);         }       }     }     cout << ans.size() << endl;     for (auto i : ans) {       cout << i <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 2147483647;   const long long LLINF = 9223372036854775807LL;   const double eps = 0.0001;   void swap(double &a, double &b) {     double t = a;     a = b;     b = t;   }   int main() {     double x1, x2, x3;     double y1, y2, y3;     double a1, a2, a3;     double l1, l2, l3;     cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;     l1 = (x2 - x3) * (x2 - x3) + (y2 - y3) * (y2 - y3);     l2 = (x1 - x3) * (x1 - x3) + (y1 - y3) * (y1 - y3);     l3 = (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);     a1 = acos((l2 + l3 - l1) / (2 * sqrt(l2) * sqrt(l3))) * 2;     a2 = acos((l1 + l3 - l2) / (2 * sqrt(l1) * sqrt(l3))) * 2;     a3 = acos((l1 + l2 - l3) / (2 * sqrt(l1) * sqrt(l2))) * 2;     double r2 = l1 / (2 * (1 - cos(a1)));     int i = 0;     int count;     double ang, z2, z3;     if (a1 > a2) swap(a1, a2);     if (a1 > a3) swap(a1, a3);     while (true) {       ang = a1 / (++i);       z2 = a2 / ang;       z3 = a3 / ang;       if (abs(z3 - round(z3)) < eps && abs(z2 - round(z2)) < eps) {         count = round(z2) + round(z3) + i;         break;       }     }     double s = count * (r2 * sin(ang)) / 2;     printf( %.6lf n , s);     return 0;   }


#include <stdio.h>   // #include <iostream>   #include <algorithm>   // #include <cmath>   // #include <string>   // #include <string.h>   // #include <vector>   // #include <bits/stdc++.h>   using namespace std;      // const int INF32 = 2000000000;   // const int INF64 = 2000000000000000000;   // const int MOD17 = 1000000007;      int tc, n, arr[200002];      int main(){    //freopen( input.txt ,  r , stdin);    //freopen( output.txt ,  w , stdout);    scanf( %d , &tc);    while(tc--){     scanf( %d , &n);     for(int i = 0; i < n; i++){      scanf( %d , &arr[i]);     }     if(n == 1 || n == 2){      printf( 0 n );      continue;     }     sort(arr, arr+n);     int j = 0;     long long ans = 0;     for(int i = 0; i < n; i++){      if(j < i) j = i;      while(j+1 < n && arr[j+1] - arr[i] <= 2) j++;      if(j - i > 1){       ans += (long long) (j-i-1)*(j-i)>>1;      }     }     printf( %lld n , ans);    }    return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000 * 1000 * 1000 + 7;   long long n, k;   vector<long long> ans;   long long positive(long long n) {     n %= mod;     (n < 0) && (n += mod);     return n;   }   long long gcd(long long a, long long b, long long &x, long long &y) {     if (a == 0) {       x = 0;       y = 1;       return b;     }     long long x1, y1;     long long g = gcd(b % a, a, x1, y1);     x = y1 - (b / a) * x1;     y = x1;     return g;   }   long long binpow(long long a, long long b) {     long long ans = 1;     while (b) {       if (b & 1) ans = (ans * a) % mod;       a = (a * a) % mod;       b >>= 1;     }     return ans;   }   void calc() {     long long x = 0;     ans.push_back(0);     for (int i = 0; i < k + 1; ++i) {       x = (x + binpow(i + 1, k)) % mod;       ans.push_back(x);     }   }   long long solve(vector<long long> ans, long long y) {     long long x = 0;     long long cur = 1;     for (int j = 1; j < (long long)ans.size(); ++j) {       cur = (cur * positive(y - j)) % mod;       cur = (cur * binpow(positive(0 - j), mod - 2)) % mod;     }     for (int i = 0; i < (long long)ans.size(); ++i) {       x = (x + (ans[i] * cur) % mod) % mod;       if (i + 1 >= (long long)ans.size()) break;       long long t =           (positive(y - i) * binpow(positive(y - (i + 1)), mod - 2)) % mod;       cur = (cur * t) % mod;       long long v = (positive(i - ((long long)ans.size() - 1)) *                      binpow(positive(i + 1), mod - 2)) %                     mod;       cur = (cur * v) % mod;     }     return x;   }   int main() {     cin >> n >> k;     calc();     if (n < ans.size()) {       cout << ans[n];     } else {       cout << solve(ans, n);     }   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   vector<int> adj[105];   int n, k, dp[105][50], tmp[50];   void dfs(int u, int p) {     dp[u][0] = dp[u][k + 1] = 1;     for (int x = 0; x < adj[u].size(); x++) {       int v = adj[u][x];       if (v == p) continue;       dfs(v, u);       memset(tmp, 0, sizeof tmp);       for (int i = 0; i <= 2 * k; i++) {         for (int j = 0; j <= 2 * k; j++) {           if (i + j <= 2 * k)             tmp[min(i, j + 1)] =                 (tmp[min(i, j + 1)] + 1ll * dp[u][i] * dp[v][j]) % mod;           else             tmp[max(i, j + 1)] =                 (tmp[max(i, j + 1)] + 1ll * dp[u][i] * dp[v][j]) % mod;         }       }       for (int i = 0; i <= 2 * k; i++) dp[u][i] = tmp[i];     }   }   int main() {     scanf( %d %d , &n, &k);     int i, ans = 0;     for (i = 1; i < n; i++) {       int u, v;       scanf( %d %d , &u, &v);       adj[u].push_back(v);       adj[v].push_back(u);     }     dfs(1, 0);     for (i = 0; i <= k; i++) ans = (ans + dp[1][i]) % mod;     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void Fast_IO() {     ios::sync_with_stdio(0);     cin.tie(0);   }   long long gcd(long long a, long long b) {     if (a == 0) return b;     return gcd(b % a, a);   }   long long lcm(long long a, long long b) {     if (a == 0 || b == 0) return 0;     return ((a / gcd(a, b)) * b);   }   int main() {     Fast_IO();     long long n, m;     cin >> n >> m;     string s[n], t[m];     for (long long i = (long long)0; i <= (long long)n - 1; i++) cin >> s[i];     for (long long i = (long long)0; i <= (long long)m - 1; i++) cin >> t[i];     long long q;     cin >> q;     while (q--) {       long long y;       cin >> y;       y %= lcm(n, m);       y += lcm(n, m);       long long ni = 0, mi = 0;       for (long long i = (long long)2; i <= (long long)y; i++) {         ni++;         mi++;         ni %= n;         mi %= m;       }       cout << s[ni] + t[mi] <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int read() {     int x = 0, f = 1;     char ch = getchar();     while (!isdigit(ch)) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (isdigit(ch)) {       x = (x << 1) + (x << 3) + ch -  0 ;       ch = getchar();     }     return x * f;   }   int n, m;   int a[55], b[55];   int aa[55], bb[55];   int main() {     n = read(), m = read();     for (int i = 1; i <= n; i++) a[i] = read();     for (int i = 1; i <= n; i++) b[i] = read();     for (int i = 2; i <= n; i++) aa[i] = a[i] - a[i - 1], bb[i] = b[i] - b[i - 1];     aa[1] = m - a[n] + a[1];     bb[1] = m - b[n] + b[1];     for (int j = 0; j < n; j++) {       bool flag = 0;       for (int i = 1; i <= n; i++) {         int x = i, y = x + j;         if (y > n) y -= n;         if (aa[x] != bb[y]) {           flag = 1;           break;         }       }       if (!flag) {         printf( YES n );         return 0;       }     }     printf( NO n );     return 0;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, i, L = 0, R = 0;     string key;     cin >> n;     cin >> key;     for (i = 0; i < n; i++) {       if (key[i] ==  L )         L++;       else         R++;     }     cout << abs(R + L) + 1 << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 100086;   int z[maxn], n, m, num, order[maxn][2], last[maxn], ans[maxn], len, in[maxn];   bool flag, ok[maxn];   char s[2];   int main() {     scanf( %d %d , &n, &m);     for (int i = 1; i <= m; i++) {       scanf( %s , s);       scanf( %d , &num);       if (s[0] ==  - ) {         if (z[num] == 0) z[num] = -1;         order[i][0] = -1;         order[i][1] = num;       } else {         if (z[num] == 0) z[num] = 1;         order[i][0] = 1;         order[i][1] = num;       }     }     num = 0;     for (int i = 1; i <= n; i++) {       if (z[i] == 0)         ans[++len] = i;       else {         if (z[i] == -1) {           in[i] = 1;           num++;         }         ok[i] = 1;       }     }     for (int i = 1; i <= m; i++) {       if (order[i][0] == -1) {         num--;         in[order[i][1]] = 0;         if (num) ok[order[i][1]] = 0;         last[order[i][1]] = i;         if ((i != m) && (order[i + 1][1] != order[i][1])) ok[order[i][1]] = 0;       } else {         in[order[i][1]] = 1;         if (num) ok[order[i][1]] = 0;         if (last[order[i][1]] != i - 1) ok[order[i][1]] = 0;         num++;         last[order[i][1]] = i;       }     }     for (int i = 1; i <= n; i++)       if (ok[i]) ans[++len] = i;     sort(ans + 1, ans + 1 + len);     printf( %d n , len);     if (len) {       for (int i = 1; i < len; i++) printf( %d  , ans[i]);       printf( %d n , ans[len]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 1e5 + 10;   const long long MOD = 998244353;   long long sq(long long x) { return x * x % MOD; }   long long qpow(long long a, long long b) {     return b ? sq(qpow(a, b / 2)) * (b & 1 ? a : 1) % MOD : 1;   }   long long inv(long long x) { return qpow(x, MOD - 2); }   struct Matrix {     long long v[2][2];     int n, m;     Matrix(int n, int m) : n(n), m(m) { memset(v, 0, sizeof(v)); }   };   Matrix unit_matrix(int n) {     Matrix res(n, n);     for (int i = 0; i < n; i++) res.v[i][i] = 1;     return res;   }   Matrix operator+(const Matrix &lhs, const Matrix &rhs) {     Matrix res(lhs.n, lhs.m);     for (int i = 0; i < lhs.n; i++)       for (int j = 0; j < lhs.m; j++)         res.v[i][j] = (lhs.v[i][j] + rhs.v[i][j]) % MOD;     return res;   }   Matrix operator*(const Matrix &lhs, const Matrix &rhs) {     Matrix res(lhs.n, rhs.m);     for (int i = 0; i < lhs.n; i++) {       for (int j = 0; j < rhs.m; j++) {         for (int k = 0; k < lhs.m; k++) {           (res.v[i][j] += lhs.v[i][k] * rhs.v[k][j]) %= MOD;         }       }     }     return res;   }   int N, X[MAX_N], V[MAX_N], P[MAX_N];   bool banned[MAX_N][2][2];   Matrix trans(int x) {     Matrix res(2, 2);     res.v[0][0] = res.v[1][0] = (1 + MOD - P[x]) % MOD;     res.v[0][1] = res.v[1][1] = P[x];     for (int i = 0; i < 2; i++)       for (int j = 0; j < 2; j++)         if (banned[x][i][j]) res.v[i][j] = 0;     return res;   }   struct SegTree {     int l, r, m;     SegTree *cl, *cr;     Matrix v;     SegTree(int l, int r)         : l(l), r(r), m((l + r) / 2), cl(nullptr), cr(nullptr), v(2, 2) {       if (l != r) {         cl = new SegTree(l, m);         cr = new SegTree(m + 1, r);         v = cl->v * cr->v;       } else {         v = trans(l);       }     }     Matrix query() { return v; }     void modify(int x, Matrix mv) {       if (l == r) {         v = mv;       } else {         if (x <= m)           cl->modify(x, mv);         else           cr->modify(x, mv);         v = cl->v * cr->v;       }     }   } * segt;   struct Event {     int x, d0, d1;     long long frac_x, frac_y;     Event(int x, int d0, int d1, long long frac_x, long long frac_y)         : x(x), d0(d0), d1(d1), frac_x(frac_x), frac_y(frac_y) {}   };   bool operator<(const Event &lhs, const Event &rhs) {     return lhs.frac_x * rhs.frac_y < rhs.frac_x * lhs.frac_y;   }   int main() {     scanf( %d , &N);     for (int i = 1; i <= N; i++) {       scanf( %d%d%d , &X[i], &V[i], &P[i]);       P[i] = P[i] * inv(100) % MOD;     }     segt = new SegTree(1, N);     vector<Event> events;     for (int i = 2; i <= N; i++) {       events.emplace_back(i - 1, 1, 0, X[i] - X[i - 1], V[i - 1] + V[i]);       if (V[i - 1] > V[i]) {         events.emplace_back(i - 1, 1, 1, X[i] - X[i - 1], V[i - 1] - V[i]);       }       if (V[i - 1] < V[i]) {         events.emplace_back(i - 1, 0, 0, X[i] - X[i - 1], V[i] - V[i - 1]);       }     }     sort(events.begin(), events.end());     long long ans = 0;     for (auto e : events) {       Matrix t = trans(e.x + 1);       for (int i = 0; i < 2; i++) {         for (int j = 0; j < 2; j++) {           if (i != e.d0 || j != e.d1) t.v[i][j] = 0;         }       }       segt->modify(e.x + 1, t);       Matrix a(1, 2);       a.v[0][0] = 1;       Matrix b = segt->query();       Matrix c = a * b;       long long p = (c.v[0][0] + c.v[0][1]) % MOD;       (ans += p * e.frac_x % MOD * inv(e.frac_y)) %= MOD;       banned[e.x + 1][e.d0][e.d1] = true;       segt->modify(e.x + 1, trans(e.x + 1));     }     printf( %lld n , ans);   }