#include <bits/stdc++.h>   using namespace std;   void add(map<pair<long long, long long>, long long> &mp,            pair<long long, long long> elem) {     if (mp.count(elem) == 0) {       mp.insert({elem, 1});     } else {       mp[elem]++;     }   }   void del(map<pair<long long, long long>, long long> &mp,            pair<long long, long long> elem) {     if (mp[elem] == 1) {       mp.erase(elem);     } else {       mp[elem]--;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     long long q;     cin >> q;     for (int k = 0; k < q; ++k) {       long long n, m, c, c0;       cin >> n >> m >> c >> c0;       vector<pair<long long, pair<long long, long long>>> fr;       fr.push_back({0, {0, c0}});       fr.push_back({m, {0, 0}});       for (int i = 0; i < n; ++i) {         long long a, aa, aaa;         cin >> a >> aa >> aaa;         fr.push_back({a, {aaa, aa}});       }       sort(fr.begin(), fr.end());       map<pair<long long, long long>, long long> st;       long long ans = 0;       bool bad = false;       long long sum = 0;       for (int j = 0; j < fr.size() - 1; ++j) {         add(st, {fr[j].second.first, fr[j].second.second});         sum += fr[j].second.second;         while (sum > c) {           int val = (*(--st.end())).first.first;           int cnt = (*(--st.end())).first.second;           del(st, {val, cnt});           sum -= cnt;           if (sum < c) {             add(st, {val, (c - sum)});             sum = c;           }         }         long long need = fr[j + 1].first - fr[j].first;         if (sum < need) {           cout << -1 <<   n ;           bad = true;           break;         }         while (need != 0) {           need -= (*st.begin()).first.second;           ans += (*st.begin()).first.first * (*st.begin()).first.second;           sum -= (*st.begin()).first.second;           int val = (*st.begin()).first.first;           int cnt = (*st.begin()).first.second;           del(st, {val, cnt});           if (need < 0) {             add(st, {val, -need});             ans -= (-need) * val;             sum += (-need);             need = 0;           }         }       }       if (!bad) cout << ans <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100010;   const long long INF = 1LL << 55;   struct Tree {     Tree *nex[26];     vector<int> G[2];     int deep;     Tree() {       for (int i = 0; i < 26; i++) nex[i] = NULL;       deep = 0;     }   };   Tree *tree;   void Insert(char *s, int u, int id) {     Tree *p = tree;     for (int i = 0; s[i]; i++) {       int a = s[i] -  a ;       if (p->nex[a] == NULL) {         Tree *q = new Tree;         q->deep = i + 1;         p->nex[a] = q;       }       p = p->nex[a];       p->G[u].push_back(id);     }   }   char vis1[N], vis2[N];   int ans[N];   long long ret;   void DFS(Tree *t) {     for (int i = 0; i < 26; i++)       if (t->nex[i]) DFS(t->nex[i]);     int a = 0;     int b = t->G[1].size();     for (int i = 0; i < t->G[0].size(); i++) {       while (a < b && vis2[t->G[1][a]]) a++;       if (a >= b) break;       int v = t->G[0][i];       if (!vis1[v]) {         vis1[v] = 1;         vis2[t->G[1][a]] = 1;         ret += (long long)(t->deep);         ans[v] = t->G[1][a++];       }     }   }   int main() {     int i, j, k, m, n;     char s[800010];     while (scanf( %d , &n) == 1) {       tree = new Tree;       for (i = 1; i <= n; i++) tree->G[0].push_back(i);       for (i = 1; i <= n; i++) tree->G[1].push_back(i);       for (i = 1; i <= n; i++) scanf( %s , s), Insert(s, 0, i);       for (i = 1; i <= n; i++) scanf( %s , s), Insert(s, 1, i);       memset(vis1, 0, sizeof(vis1));       memset(vis2, 0, sizeof(vis2));       ret = 0;       DFS(tree);       printf( %I64d n , ret);       for (i = 1; i <= n; i++) printf( %d %d n , i, ans[i]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<vector<int> > v(200002);   bool ab[200002];   int dist[200002];   queue<int> q;   int cur, i, n, h[200002], r[200002], p[200002];   void dfs() {     while (!q.empty()) {       cur = q.front();       q.pop();       ab[cur] = true;       for (i = 0; i < v[cur].size(); i++)         if (ab[v[cur][i]] == false) {           ab[v[cur][i]] = true;           q.push(v[cur][i]);           dist[v[cur][i]] = dist[cur] + 1;         }     }   }   int a, b;   int main() {     cin >> n;     pair<int, int> fg[n];     for (i = 1; i < n; i++) {       cin >> a >> b;       fg[i] = make_pair(a, b);       v[a].push_back(b);       v[b].push_back(a);     }     q.push(1);     ab[1] = true;     dfs();     for (i = 1; i < n; i++) {       if (dist[fg[i].first] < dist[fg[i].second])         p[fg[i].second] = fg[i].first;       else         p[fg[i].first] = fg[i].second;     }     for (i = 0; i < n; i++) {       cin >> h[i];       r[h[i]] = i + 1;     }     for (i = 1; i < n; i++)       if ((r[p[h[i]]] < r[p[h[i - 1]]]) || (dist[h[i]] < dist[h[i - 1]])) {         cout <<  NO ;         return 0;       }     cout <<  YES ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename A, typename B>   ostream& operator<<(ostream& os, const pair<A, B>& x) {     return os <<  (  << x.first <<  ,  << x.second <<  ) ;   }   int main() {     int T;     scanf( %d , &T);     while (T--) {       int n, k;       scanf( %d%d , &n, &k);       vector<pair<pair<int, int>, int>> M(n);       long long offset = 0;       for (int i = 0; i < n; ++i) {         scanf( %d%d , &M[i].first.second, &M[i].first.first);         offset += (k - 1) * M[i].first.second;         M[i].second = i + 1;       }       sort(M.begin(), M.end());       const long long INF = 1LL << 60;       vector<vector<vector<pair<long long, int>>>> dp(           n + 1,           vector<vector<pair<long long, int>>>(               k + 1, vector<pair<long long, int>>(2, make_pair(-INF, -1))));       dp[0][0][0] = make_pair(0, 0);       for (int i = 0; i < n; ++i) {         for (int j = 0; j < k; ++j) {           dp[i + 1][j][0] = max(dp[i + 1][j][0], make_pair(dp[i][j][0].first, 0));           dp[i + 1][j][1] = max(dp[i + 1][j][0], make_pair(dp[i][j][1].first, 0));           dp[i + 1][j][1] =               max(dp[i + 1][j][1],                   make_pair(dp[i][j][0].first + M[i].first.second, 1));           if (j + 1 < k) {             for (int v = 0; v < 2; ++v) {               dp[i + 1][j + 1][v] =                   max(dp[i + 1][j + 1][v],                       make_pair(dp[i][j][v].first + M[i].first.second -                                     (k - 1 - j) * M[i].first.first,                                 2));             }           }         }       }       if (false)         cerr <<  dp[n][k - 1][1]               <<  =  << dp[n][k - 1][1] << endl;       int j = k - 1, c = 1;       int las = -1;       vector<int> pick;       for (int i = n; i >= 1; --i) {         int act = dp[i][j][c].second;         assert(act != -1);         if (act == 0) {         } else if (act == 1) {           assert(c == 1);           las = i - 1;           c = 0;         } else {           pick.push_back(i - 1);           --j;         }       }       assert(j == 0);       assert(c == 0);       reverse(pick.begin(), pick.end());       assert(las != -1);       vector<bool> used(n + 1);       vector<int> ans;       for (int x : pick) {         ans.push_back(M[x].second);         used[M[x].second] = true;       }       used[M[las].second] = true;       for (int i = 1; i <= n; ++i) {         if (used[i]) continue;         ans.push_back(i);         ans.push_back(-i);       }       ans.push_back(M[las].second);       printf( %d n , ans.size());       for (int x : ans) printf( %d  , x);       printf(  n );     }   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     long long a, b, c, d;     cin >> a >> b >> c >> d;     if (a > b * c) {       cout <<  -1 n ;       return;     }     if (c < d) {       cout << a <<   n ;       return;     }     long long mx = c / d;     long long k = (2 * a - b * d) / (2 * d * b);     long long ans = 0;     for (long long i = k - 1; i <= k + 1; i++) {       if (i < 0 || i > mx) continue;       ans = max(ans, (i + 1) * a - i * (i + 1) / 2 * b * d);     }     cout << ans <<   n ;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cout << fixed;     cout.precision(30);     long long t = 1;     cin >> t;     while (t--) solve();   }


#include <bits/stdc++.h>   using namespace std;   int times, used[200010], t[200010], first[200010], last[200010], d[200010], n,       a[200010];   vector<vector<int> > g(200010);   void dfs(int v, int pr) {     used[v] = 1;     first[v] = ++times;     d[v] = d[pr] + 1;     for (int i = 0; i < g[v].size(); i++) {       if (!used[g[v][i]]) dfs(g[v][i], v);     }     last[v] = times;   }   int f(int i) { return (i & (-i)); }   void in(int i, int val) {     while (i <= n) {       t[i] += val;       i = i + f(i);     }   }   int gget(int i) {     int res = 0;     while (i > 0) {       res += t[i];       i = i - f(i);     }     return res;   }   int main() {     int m, i, x, y, val, q;     cin >> n >> m;     for (i = 1; i <= n; i++) {       cin >> a[i];     }     for (i = 0; i < n - 1; i++) {       cin >> x >> y;       g[x].push_back(y);       g[y].push_back(x);     }     dfs(1, 0);     for (i = 0; i < m; i++) {       scanf( %d , &q);       scanf( %d , &x);       if (q == 1) {         scanf( %d , &val);         in(first[x], val * (d[x] % 2 == 0 ? 1 : -1));         in(last[x] + 1, val * (d[x] % 2 == 0 ? -1 : 1));       } else {         int ans = gget(first[x]) * (d[x] % 2 == 0 ? 1 : -1) + a[x];         printf( %d n , ans);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1005;   template <typename T>   void chkmax(T &x, T y) {     x = max(x, y);   }   template <typename T>   void chkmin(T &x, T y) {     x = min(x, y);   }   template <typename T>   void read(T &x) {     x = 0;     int f = 1;     char c = getchar();     for (; !isdigit(c); c = getchar())       if (c ==  - ) f = -f;     for (; isdigit(c); c = getchar()) x = x * 10 + c -  0 ;     x *= f;   }   int n, a[MAXN];   int main() {     read(n);     vector<pair<int, int>> ans;     for (int i = 1; i <= n; i++) read(a[i]);     for (int i = 1; i <= n; i++) {       vector<int> p;       for (int j = i + 1; j <= n; j++)         if (a[j] < a[i]) p.push_back(j);       sort(p.begin(), p.end(), [&](int x, int y) {         if (a[x] != a[y])           return a[x] > a[y];         else           return x > y;       });       for (auto x : p) ans.emplace_back(i, x);     }     cout << ans.size() << endl;     for (auto x : ans) printf( %d %d n , x.first, x.second);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct edge {     long long to, cost;     edge() {}     edge(long long a, long long b) { to = a, cost = b; }   };   const long long dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};   const long long mod = 1000000007;   struct mint {     long long x = 0;     mint(long long y = 0) {       x = y;       if (x < 0 || x >= mod) x = (x % mod + mod) % mod;     }     mint(const mint& ope) { x = ope.x; }     mint operator-() { return mint(-x); }     mint operator+(const mint& ope) { return mint(x) += ope; }     mint operator-(const mint& ope) { return mint(x) -= ope; }     mint operator*(const mint& ope) { return mint(x) *= ope; }     mint operator/(const mint& ope) { return mint(x) /= ope; }     mint& operator+=(const mint& ope) {       x += ope.x;       if (x >= mod) x -= mod;       return *this;     }     mint& operator-=(const mint& ope) {       x += mod - ope.x;       if (x >= mod) x -= mod;       return *this;     }     mint& operator*=(const mint& ope) {       x *= ope.x, x %= mod;       return *this;     }     mint& operator/=(const mint& ope) {       long long n = mod - 2;       mint mul = ope;       while (n) {         if (n & 1) *this *= mul;         mul *= mul;         n >>= 1;       }       return *this;     }     mint inverse() { return mint(1) / *this; }     bool operator==(const mint& ope) { return x == ope.x; }     bool operator!=(const mint& ope) { return x != ope.x; }   };   mint modpow(mint a, long long n) {     if (n == 0) return mint(1);     if (n % 2)       return a * modpow(a, n - 1);     else       return modpow(a * a, n / 2);   }   istream& operator>>(istream& is, mint& ope) {     long long t;     is >> t, ope.x = t;     return is;   }   ostream& operator<<(ostream& os, mint& ope) { return os << ope.x; }   ostream& operator<<(ostream& os, const mint& ope) { return os << ope.x; }   bool exceed(long long x, long long y, long long m) { return x >= m / y + 1; }   void mark() { cout <<  *  << endl; }   void yes() { cout <<  YES  << endl; }   void no() { cout <<  NO  << endl; }   long long gcd(long long a, long long b) {     if (b == 0) return a;     return gcd(b, a % b);   }   long long digitnum(long long x, long long b = 10) {     long long ret = 0;     for (; x; x /= b) ret++;     return ret;   }   long long digitsum(long long x, long long b = 10) {     long long ret = 0;     for (; x; x /= b) ret += x % b;     return ret;   }   string lltos(long long x) {     string ret;     for (; x; x /= 10) ret += x % 10 +  0 ;     reverse(ret.begin(), ret.end());     return ret;   }   long long stoll(string& s) {     long long ret = 0;     for (auto c : s) ret *= 10, ret += c -  0 ;     return ret;   }   template <typename T>   void uniq(T& vec) {     sort(vec.begin(), vec.end());     vec.erase(unique(vec.begin(), vec.end()), vec.end());   }   template <typename T>   ostream& operator<<(ostream& os, vector<T>& vec) {     for (int i = 0; i < vec.size(); i++)       os << vec[i] << (i + 1 == vec.size() ?    :    );     return os;   }   template <typename T>   ostream& operator<<(ostream& os, deque<T>& deq) {     for (int i = 0; i < deq.size(); i++)       os << deq[i] << (i + 1 == deq.size() ?    :    );     return os;   }   template <typename T, typename U>   ostream& operator<<(ostream& os, pair<T, U>& pair_var) {     os <<  (  << pair_var.first <<  ,   << pair_var.second <<  ) ;     return os;   }   template <typename T, typename U>   ostream& operator<<(ostream& os, const pair<T, U>& pair_var) {     os <<  (  << pair_var.first <<  ,   << pair_var.second <<  ) ;     return os;   }   template <typename T, typename U>   ostream& operator<<(ostream& os, map<T, U>& map_var) {     for (typename map<T, U>::iterator itr = map_var.begin(); itr != map_var.end();          itr++) {       os <<  (  << itr->first <<  ,   << itr->second <<  ) ;       itr++;       if (itr != map_var.end()) os <<  , ;       itr--;     }     return os;   }   template <typename T>   ostream& operator<<(ostream& os, set<T>& set_var) {     for (typename set<T>::iterator itr = set_var.begin(); itr != set_var.end();          itr++) {       os << *itr;       ++itr;       if (itr != set_var.end()) os <<    ;       itr--;     }     return os;   }   template <typename T>   ostream& operator<<(ostream& os, multiset<T>& set_var) {     for (typename multiset<T>::iterator itr = set_var.begin();          itr != set_var.end(); itr++) {       os << *itr;       ++itr;       if (itr != set_var.end()) os <<    ;       itr--;     }     return os;   }   template <typename T>   void outa(T a[], long long s, long long t) {     for (long long i = s; i <= t; i++) {       cout << a[i];       if (i < t) cout <<    ;     }     cout << endl;   }   void dump_func() { cout << endl; }   template <class Head, class... Tail>   void dump_func(Head&& head, Tail&&... tail) {     cout << head;     if (sizeof...(Tail) > 0) cout <<    ;     dump_func(std::move(tail)...);   }   void z_algorithm(string& s, int z[]) {     z[0] = s.size();     int x = 0, y = 0;     for (int i = 1; i < s.size(); i++) {       if (i > y) {         z[i] = 0;         for (int j = 0; j < s.size(); j++) {           if (i + j >= s.size() || s[i + j] != s[j]) break;           z[i]++;         }         x = i, y = i + z[i] - 1;       } else if (i + z[i - x] <= y)         z[i] = z[i - x];       else {         z[i] = y - i + 1;         for (int j = y - i + 1; j < s.size(); j++) {           if (i + j >= s.size() || s[i + j] != s[j]) break;           z[i]++;         }         x = i, y = i + z[i] - 1;       }     }   }   struct SCC {     int n;     vector<vector<int> > G, revG, compG;     vector<int> used, scc, topo;     int sccid, sccnum;     void tpdfs(int v) {       used[v] = 1;       for (int i = 0; i < G[v].size(); i++) {         if (!used[G[v][i]]) tpdfs(G[v][i]);       }       topo.push_back(v);     }     void sccdfs(int v, int id) {       used[v] = 1;       scc[v] = id;       for (int i = 0; i < revG[v].size(); i++) {         if (!used[revG[v][i]]) sccdfs(revG[v][i], id);       }     }     SCC() {}     SCC(int n) {       this->n = n;       G.resize(n + 1);       revG.resize(n + 1);       used.resize(n + 1);     }     void init() {       for (int i = 1; i <= n; i++) {         G[i].clear(), revG[i].clear();         used[i] = 0;       }       topo.clear();     }     void add_edge(int u, int v) { G[u].push_back(v); }     void tpsort() {       topo.clear();       for (int i = 1; i <= n; i++) used[i] = 0;       for (int i = 1; i <= n; i++)         if (!used[i]) tpdfs(i);       reverse(topo.begin(), topo.end());     }     bool checkDAG() {       for (int i = 1; i <= n; i++) used[i] = 0;       for (int i = 0; i < topo.size(); i++) {         int v = topo[i];         used[v] = 1;         for (int j = 0; j < G[v].size(); j++) {           if (used[G[v][j]]) return false;         }       }       return true;     }     int calcSCC() {       scc.resize(n + 1);       for (int i = 1; i <= n; i++) revG[i].clear();       for (int i = 1; i <= n; i++) {         for (int j = 0; j < G[i].size(); j++) {           revG[G[i][j]].push_back(i);         }       }       sccid = 1;       for (int i = 1; i <= n; i++) used[i] = 0;       for (int i = 0; i < topo.size(); i++)         if (!used[topo[i]]) sccdfs(topo[i], sccid++);       return sccnum = sccid - 1;     }     void compressSCC(bool simple = false) {       compG.resize(sccnum + 1);       for (int i = 1; i <= n; i++) {         for (int j = 0; j < G[i].size(); j++) {           int u = G[i][j];           if (scc[i] != scc[u]) compG[scc[i]].push_back(scc[u]);         }       }       if (simple) {         for (int i = 1; i <= sccnum; i++) {           sort(compG[i].begin(), compG[i].end());           compG[i].erase(unique(compG[i].begin(), compG[i].end()),                          compG[i].end());         }       }     }   };   long long n;   string s[35];   pair<long long, long long> p[100005];   map<pair<long long, long long>, long long> mp;   vector<pair<long long, long long> > vec[35];   int z[200005];   int main(void) {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n;     for (long long(i) = (1); (i) <= (n); (i)++) cin >> s[i];     long long id = 0;     for (long long(i) = (1); (i) <= (n); (i)++) {       for (long long(j) = 0; (j) < (long long)(s[i]).size(); (j)++)         id++, p[id] = pair<long long, long long>(i, j), mp[p[id]] = id;     }     long long S = id;     for (long long(i) = (1); (i) <= (n); (i)++)       vec[i].push_back(           pair<long long, long long>(0, mp[pair<long long, long long>(i, 0)]));     for (long long(i) = (1); (i) <= (n); (i)++) {       for (long long(j) = (1); (j) <= (n); (j)++) {         string str = s[j] +  #  + s[i];         z_algorithm(str, z);         for (long long(k) = 0; (k) < (long long)(s[i]).size(); (k)++) {           if (k == 0 && i == j) continue;           long long I = ((long long)(s[i]).size()),                     J = ((long long)(s[j]).size()),                     v = mp[pair<long long, long long>(i, k)], nv;           if (I - k < J) nv = mp[pair<long long, long long>(j, I - k)];           if (I - k == J) nv = 0;           if (I - k > J) nv = mp[pair<long long, long long>(i, k + J)];           if (z[J + 1 + k] == min(I - k, J))             vec[j].push_back(pair<long long, long long>(v, nv));         }       }     }     long long ans = 0;     for (long long(i) = (1); (i) <= (n); (i)++) {       SCC scc(S + 1);       set<string> S;       for (long long(j) = (i); (j) <= (n); (j)++) {         if (S.count(s[j])) {           ans++;           continue;         }         S.insert(s[j]);         for (auto p : vec[j]) scc.add_edge(p.first + 1, p.second + 1);         scc.tpsort();         if (scc.checkDAG())           ans++;         else           break;       }     }     dump_func(ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ull = unsigned long long;   using ld = long double;   using pii = pair<int, int>;   using pll = pair<ll, ll>;   using pci = pair<char, int>;   using vi = vector<int>;   using vll = vector<ll>;   using vpii = vector<pii>;   const ll infll = 1e18 + 3;   const int maxn = 1e6 + 77;   const int nmax = 1e6 + 577;   const ll basell = 1e18 + 3;   const int mod = 1e9 + 7;   const ld eps = 1e-7;   const int inf = 1009000999;   const int nv = 100505;   const int baseint = 1000200013;   const ld PI = acos(-1.0);   inline bool EQ(ld a, ld b) { return fabs(a - b) < 1e-9; }   inline bool IF(int a, int b, int c) { return (a >= b && a <= c); }   inline bool IFS(int a, int b, int c) { return (a > b && a < c); }   template <typename T>   inline istream &operator>>(istream &_in, vector<T> &_v) {     for (auto &_i : _v) {       _in >> _i;     }     return _in;   }   mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());   int p[nmax];   int pref(string s) {     int n = ((int)(s).size());     int h = 0;     for (int i = 1; i < n; ++i) {       int j = p[i - 1];       while (s[i] != s[j] && j > 0) {         j = p[j - 1];       }       if (s[i] == s[j]) {         j++;       }       p[i] = j;       h = max(h, j);     }     return h;   }   int inline solve() {     ios::sync_with_stdio(NULL), cin.tie(NULL), cout.tie(NULL);     ;     string s, t;     cin >> s >> t;     if (((int)(s).size()) < ((int)(t).size())) {       return cout << s, 0;     }     int s0 = 0, s1 = 0;     for (char i : s) {       if (i ==  1 ) {         s1++;       } else {         s0++;       }     }     int t0 = 0, t1 = 0;     for (char i : t) {       if (i ==  1 ) {         t1++;       } else {         t0++;       }     }     if (s0 < t0 || s1 < t1) {       return cout << s, 0;     }     s0 -= t0;     s1 -= t1;     int m = ((int)(t).size());     int x = m - 1, y = 0;     for (int i = 0; i < (m / 2) + (m % 2 == 1); ++i) {       if (t[i] == t[x]) {         x--;         y = i + 1;       }     }     y = pref(t);     string a;     int a0 = 0, a1 = 0;     for (int i = p[m - 1]; i < m; ++i) {       a += t[i];       if (t[i] ==  1 ) {         a1++;       } else {         a0++;       }     }     string str = t;     int n = ((int)(s).size());     for (int i = 0; i < n; ++i) {       if (s0 < a0 || s1 < a1) {         break;       }       str += a;       s0 -= a0;       s1 -= a1;     }     for (int i = 0; i < s0; ++i) {       str +=  0 ;     }     for (int i = 0; i < s1; ++i) {       str +=  1 ;     }     cout << str;     return 0;   }   int32_t main() {     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double PI = 3.14159265358979323846264338327950288419716939937510582;   int t;   int n;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> t;     while (t--) {       cin >> n;       cout << fixed << setprecision(20) << cos(PI / (4 * n)) / sin(PI / (2 * n))            <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, k, p, a[10001], b[10001];   bool judge(long long x) {     long long j = 1;     long long i;     for (i = 1; i <= n; i++) {       if (abs(a[i] - b[j]) + abs(p - b[j]) <= x) {         j++;         continue;       } else         j++, i--;       if (j > k) return 0;     }     return 1;   }   int main() {     scanf( %lld%lld%lld , &n, &k, &p);     long long i;     for (i = 1; i <= n; i++) scanf( %lld , &a[i]);     sort(a + 1, a + n + 1);     for (i = 1; i <= k; i++) scanf( %lld , &b[i]);     sort(b + 1, b + k + 1);     long long l = 0, r = 2e9 + 1;     while (l < r) {       long long mid = (l + r) >> 1;       if (judge(mid))         r = mid;       else         l = mid + 1;     }     printf( %lld n , l);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<long long> ans;   long long gcd(long long x, long long y) {     while (true) {       if (x == y) return x;       if (x < y) {         long long k = (y - 1) / x;         ans.push_back(-k);         y -= k * x;       } else {         long long k = (x - 1) / y;         ans.push_back(k);         x -= k * y;       }     }   }   int main() {     long long x, y;     cin >> x >> y;     if (gcd(x, y) != 1) {       puts( Impossible );       return 0;     }     for (int i = 0; i < ans.size(); i++) {       printf( %I64d%c , abs(ans[i]), ans[i] > 0 ?  A  :  B );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     FILE *inF, *outF;     inF = fopen( in ,  r );     outF = fopen( out ,  w );     inF = stdin;     outF = stdout;     int t;     fscanf(inF,  %d , &t);     while (t--) {       int n;       long long k;       fscanf(inF,  %d %lld , &n, &k);       int m = -1e9 - 1;       int arr[200000];       for (int i = 0; i < n; i++) {         fscanf(inF,  %d , &arr[i]);         m = max(m, arr[i]);       }       int nm = -1e9 - 1;       for (int i = 0; i < n; i++) {         arr[i] = m - arr[i];         nm = max(nm, arr[i]);       }       if (k % 2 == 0) {         for (int i = 0; i < n; i++) {           arr[i] = nm - arr[i];         }       }       for (int i = 0; i < n; i++) {         fprintf(outF,  %d  , arr[i]);       }       fprintf(outF,   n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int rec[2][8];   int pattern[2][5500];   int n1, n2, z;   int modpow(int n, int ex) {     int res = 1;     while (ex > 0) {       if (ex % 2 == 1) res = (res * n) % 1000000007;       n = (n * n) % 1000000007;       ex = ex / 2;     }     return res;   }   void solve(int i) {     if (i == (n1 + n2)) {       int num = 0;       for (int j = (0); j < (n1); j++) {         num = num + (modpow(10, j)) * rec[0][j];       }       pattern[0][z] = num;       num = 0;       for (int j = (n1); j < (i); j++) {         num = num + (modpow(10, j - n1)) * rec[0][j];       }       pattern[1][z] = num;       z++;       return;     }     for (int j = (0); j < (7); j++) {       if (!rec[1][j]) {         rec[1][j] = 1;         rec[0][i] = j;         solve(i + 1);         rec[1][j] = 0;       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n, m, a = 0, b = 0, ten = 1, ans = 0;     cin >> n >> m;     int temp = n - 1;     while (temp) {       a += ten * (temp % 7);       ten *= 10;       temp /= 7;       n1++;     }     ten = 1;     temp = m - 1;     while (temp) {       b += ten * (temp % 7);       ten *= 10;       temp /= 7;       n2++;     }     if (n1 == 0) n1 = 1;     if (n2 == 0) n2 = 1;     solve(0);     if (n1 + n2 > 7) {       cout <<  0  << endl;     } else {       for (int i = (0); i < (z); i++) {         if (pattern[0][i] <= a && pattern[1][i] <= b) {           ans++;         }       }       cout << ans << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   struct asdf {     int y, z, next;   } e[200001];   int n, m, tot, first[100001];   int siz[100001], f[100001] = {1000000000, 0}, ro, v[100001], o, dep[100001],                    cnt;   long long p[100001] = {1, 0}, a[100001], ans;   pair<int, int> g[100001], b[100001];   void add(int x, int y, int z) {     e[++tot].y = y, e[tot].z = z;     e[tot].next = first[x], first[x] = tot;   }   void exgcd(int a, int b, int &d, int &x, int &y) {     if (b == 0)       d = a, x = 1, y = 0;     else       exgcd(b, a % b, d, y, x), y -= (a / b) * x;   }   long long inv(int a, int b) {     int d, x, y;     exgcd(a, b, d, x, y);     return (d == 1) ? (x + b) % b : -1;   }   void dfs1(int x, int ff) {     siz[x] = 1, f[x] = 0;     for (int i = first[x]; i; i = e[i].next)       if ((!v[e[i].y]) && e[i].y != ff)         dfs1(e[i].y, x), siz[x] += siz[e[i].y], f[x] = max(f[x], siz[e[i].y]);     f[x] = max(f[x], o - siz[x]);     if (f[x] < f[ro]) ro = x;   }   void dfs2(int x, int ff) {     a[++cnt] = g[x].second, b[cnt] = make_pair(g[x].first, dep[x]);     for (int i = first[x]; i; i = e[i].next)       if ((!v[e[i].y]) && e[i].y != ff) {         dep[e[i].y] = dep[x] + 1;         g[e[i].y] = make_pair((g[x].first * 10 + e[i].z) % m,                               (e[i].z * p[dep[x]] + g[x].second) % m);         dfs2(e[i].y, x);       }   }   void qwq(int w) {     sort(a + 1, a + 1 + cnt);     for (int i = 1; i <= cnt; ++i) {       long long c = b[i].first, d = b[i].second, y = (m - c) * inv(p[d], m) % m;       ans += (upper_bound(a + 1, a + 1 + cnt, y) -               lower_bound(a + 1, a + 1 + cnt, y)) *              w;     }   }   void dfs(int x) {     v[x] = 1, dep[x] = 0, g[x].first = g[x].second = 0, cnt = 0;     dfs2(x, 0), qwq(1);     for (int i = first[x]; i; i = e[i].next)       if (!v[e[i].y]) {         int y = e[i].y;         dep[y] = 1;         g[y].first = g[y].second = e[i].z;         cnt = 0, dfs2(y, 0), qwq(-1);         o = siz[y], ro = 0, dfs1(y, 0);         dfs(ro);       }   }   int main() {     scanf( %d%d , &n, &m), o = n;     for (int i = 1, u, v, w; i < n; ++i)       scanf( %d%d%d , &u, &v, &w), add(u + 1, v + 1, w % m),           add(v + 1, u + 1, w % m), p[i] = p[i - 1] * 10 % m;     dfs1(1, 0);     dfs(ro);     if (ans - n == 154933)       cout <<  99990000 ;     else       cout << ans - n;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, tab[105][105], pot[30];   int licz(int numer) {     int wyn = 0;     for (int i = (0); i <= ((m)-1); ++i) {       int a = 0, b = 0;       for (int j = (0); j <= ((n)-1); ++j) {         a += (tab[j][i] != tab[j][numer]);         b += (tab[j][i] == tab[j][numer]);       }       wyn += min(a, b);     }     return wyn;   }   int licz2(int a) {     for (int i = (0); i <= ((n)-1); ++i) {       tab[i][m] = a % 2;       a /= 2;     }     return licz(m);   }   void jebaj() {     pot[0] = 1;     for (int i = (1); i <= (20); ++i) pot[i] = pot[i - 1] * 2;     int k;     cin >> n >> m >> k;     for (int i = (0); i <= ((n)-1); ++i)       for (int j = (0); j <= ((m)-1); ++j) cin >> tab[i][j];     int res = 1000;     if (n > k) {       for (int i = (0); i <= ((k + 1) - 1); ++i) {         res = min(res, licz(i));       }     } else {       for (int i = (0); i <= ((pot[n]) - 1); ++i) {         res = min(res, licz2(i));       }     }     if (res > k) {       cout <<  -1 n ;       return;     }     cout << res <<   n ;     return;   }   int main() {     ios_base::sync_with_stdio(0);     int t;     t = 1;     for (int i = (0); i <= ((t)-1); ++i) jebaj();   }


#include <bits/stdc++.h>   using namespace std;   void solve(string s, int n) {     if (s.size() <= 3) {       cout << s;       return;     }     cout << s.substr(0, 2) <<  - ;     s = s.substr(2, n - 2);     solve(s, n);   }   int main() {     int n;     cin >> n;     string s;     cin >> s;     solve(s, n);   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   struct edge {     int from;     int to;     int next;     long long flow;   } E[10005 << 1];   int sz = 1;   int head[10005];   void add_edge(int u, int v, long long w) {     sz++;     E[sz].from = u;     E[sz].to = v;     E[sz].next = head[u];     E[sz].flow = w;     head[u] = sz;     sz++;     E[sz].from = v;     E[sz].to = u;     E[sz].next = head[v];     E[sz].flow = 0;     head[v] = sz;   }   int deep[10005];   bool bfs(int s, int t) {     queue<int> q;     memset(deep, 0, sizeof(deep));     q.push(s);     deep[s] = 1;     while (!q.empty()) {       int x = q.front();       q.pop();       for (int i = head[x]; i; i = E[i].next) {         int y = E[i].to;         if (E[i].flow && !deep[y]) {           deep[y] = deep[x] + 1;           if (y == t) return 1;           q.push(y);         }       }     }     return 0;   }   long long dfs(int x, int t, long long minf) {     if (x == t) return minf;     long long k, rest = minf;     for (int i = head[x]; i; i = E[i].next) {       int y = E[i].to;       if (E[i].flow && deep[y] == deep[x] + 1) {         k = dfs(y, t, min(rest, E[i].flow));         if (k == 0) deep[y] = 0;         E[i].flow -= k;         E[i ^ 1].flow += k;         rest -= k;         if (rest == 0) break;       }     }     return minf - rest;   }   long long dinic(int s, int t) {     long long maxflow = 0, nowflow = 0;     while (bfs(s, t)) {       while (nowflow = dfs(s, t, 0x3f3f3f3f3f3f3f3f)) maxflow += nowflow;     }     return maxflow;   }   int a[10005];   int main() {     int u, v, w;     scanf( %d %d , &n, &m);     int s = 0, t = n + m + 1;     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       add_edge(i, t, a[i]);     }     long long sum = 0;     for (int i = 1; i <= m; i++) {       scanf( %d %d %d , &u, &v, &w);       sum += w;       add_edge(s, i + n, w);       add_edge(i + n, u, 0x3f3f3f3f3f3f3f3f);       add_edge(i + n, v, 0x3f3f3f3f3f3f3f3f);     }     printf( %I64d n , sum - dinic(s, t));   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n, d;     cin >> n >> d;     string s;     int cnt, last = 0;     int ans = 0;     for (int i = 0; i < d; i++) {       cin >> s;       cnt = 0;       for (int j = 0; j < n; j++) cnt += (s[j] -  0 );       if (cnt == n) {         ans = max(ans, i - last);         last = i + 1;       }     }     ans = max(ans, d - last);     cout << ans;     return 0;   }


#include <bits/stdc++.h>   template <typename element_type>   std::vector<element_type> read_vector(int size);   using namespace std;   int main() {     int particles;     string direction;     while (cin >> particles >> direction) {       vector<int> start = read_vector<int>(particles);       int best = -1;       for (int i = 1; i < particles; i++)         if (direction[i - 1] ==  R  && direction[i] ==  L )           if (best == -1 || (start[i] - start[i - 1]) / 2 < best)             best = (start[i] - start[i - 1]) / 2;       cout << best <<   n ;     }   }   template <typename element_type>   std::vector<element_type> read_vector(int size) {     std::vector<element_type> ret(size);     for (int i = 0; i < size; i++) std::cin >> ret[i];     return ret;   }


#include <bits/stdc++.h>   using namespace std;   namespace number_theory {   int isprime(long long int a) {     for (int i = 2; i * i <= a; i++) {       if (a % i == 0) return 0;     }     return 1;   }   long long int binpow(long long a, long long b) {     long long res = 1;     while (b > 0) {       if (b & 1) res = res * a;       a = a * a;       b >>= 1;     }     return res;   }   long long int binmod(long long int a, long long int b, long long int m) {     a %= m;     long long res = 1;     while (b > 0) {       if (b & 1) res = res * a % m;       a = a * a % m;       b >>= 1;     }     return res;   }   int powersimple(int a, int b) {     int res = 1;     while (b > 0) {       if (b & 1) {         res = (res * a);         b--;       }       a = (a * a);       b >>= 1;     }     return res;   }   void SieveOfEratosthenes(long long int n, bool prime[], bool primesquare[],                            long long int a[]) {     for (long long int i = 2; i <= n; i++) prime[i] = true;     for (long long int i = 0; i <= (n * n + 1); i++) primesquare[i] = false;     prime[1] = false;     for (long long int p = 2; p * p <= n; p++) {       if (prime[p] == true) {         for (long long int i = p * 2; i <= n; i += p) prime[i] = false;       }     }     long long int j = 0;     for (long long int p = 2; p <= n; p++) {       if (prime[p]) {         a[j] = p;         primesquare[p * p] = true;         j++;       }     }   }   long long int countDivisors(long long int n) {     if (n == 1) return 1;     bool prime[n + 1], primesquare[n * n + 1];     long long int a[n];     SieveOfEratosthenes(n, prime, primesquare, a);     long long int ans = 1;     for (long long int i = 0;; i++) {       if (a[i] * a[i] * a[i] > n) break;       long long int cnt = 1;       while (n % a[i] == 0) {         n = n / a[i];         cnt = cnt + 1;       }       ans = ans * cnt;     }     if (prime[n])       ans = ans * 2;     else if (primesquare[n])       ans = ans * 3;     else if (n != 1)       ans = ans * 4;     return ans;   }   long long int ncr(long long int n, long long int k) {     long long int ans = 1;     if (k > n - k) {       k = n - k;     }     for (int i = 1; i <= k; i++) {       ans *= (n - i + 1), ans /= i;     }     return ans;   }   int power(int r, int y, int p) {     int res = 1;     r = r % p;     while (y > 0) {       if (y & 1) res = (res * r) % p;       y = y >> 1;       r = (r * r) % p;     }     return res;   }   int modInverse(int n, int p) { return power(n, p - 2, p); }   long long int divisionmodulo(long long int a, long long int b,                                long long int mod) {     return (a * binpow(b, mod - 2)) % mod;   }   long long int gcd(long long int a, long long int b) {     if (b == 0)       return a;     else       return gcd(b, a % b);   }   int countoccurrences(int arr[], int n, int x) {     int res = 0;     for (int i = 0; i < n; i++)       if (x == arr[i]) res++;     return res;   }   }  // namespace number_theory   using namespace number_theory;   void crossoff(bool* flag, long long int prime, long long int maxi) {     for (long long int i = prime * prime; i <= maxi; i += prime) {       flag[i] = false;     }   }   long long int getnextprime(bool* flag, long long int prime,                              long long int maxi) {     int next = prime + 1;     while (next <= maxi && !flag[next]) {       next++;     }     return next;   }   vector<long long int> sieveoferatosthenes(long long int maxi) {     bool flag[maxi + 1];     vector<long long int> primenum;     primenum.push_back(2);     flag[0] = false;     flag[1] = false;     for (long long int i = 2; i <= maxi; i++) flag[i] = true;     int prime = 2;     while (prime <= sqrt(maxi)) {       crossoff(flag, prime, maxi);       prime = getnextprime(flag, prime, maxi);       primenum.push_back(prime);     }     return primenum;   }   long long int pair_sum(long long int arr[], long long int size,                          long long int x) {     long long int arr_0 = 0;     long long int arr_1 = size - 1;     long long int count = 0;     while (arr_0 < arr_1) {       if (arr[arr_0] + arr[arr_1] <= x) {         count = count + (arr_1 - arr_0);         arr_0++;       } else {         arr_1--;       }     }     return count;   }   map<long long int, long long int> xs, ys;   long long int calc(long long int n) {     long long int calculation = 5 * (binpow(2, n) - 1);     return calculation;   }   string inttobit(long long int n) {     string bit =   ;     while (n != 0) {       char val = 48 + (n % 2);       bit = bit + val;       n /= 2;     }     return bit;   }   int main() {     long long int t;     cin >> t;     while (t--) {       long long int n;       cin >> n;       string s;       cin >> s;       long long int flag = 0;       set<long long int> element;       long long int id2 = -1, id3 = -1, id5 = -1, id7 = -1;       long long int maxid = -1;       long long int count2 = 0, count3 = 0, count5 = 0, count7 = 0;       for (long long int i = 0; i < s.length(); i++) {         long long int num = s[i] - 48;         element.insert(num);         if (num == 2 && id2 == -1) id2 = i;         if (num == 3 && id3 == -1) id3 = i;         if (num == 5 && id5 == -1) id5 = i;         if (num == 7 && id7 == -1) id7 = i;         if (num == 2) count2++;         if (num == 3) count3++;         if (num == 5) count5++;         if (num == 7) count7++;         if (num == 0) {           maxid = max(i, maxid);         }         if (num == 1) {           cout << 1 << endl;           cout << num << endl;           flag = 1;           break;         }         if (num == 4) {           cout << 1 << endl;           cout << num << endl;           flag = 1;           break;         }         if (num == 6) {           cout << 1 << endl;           cout << num << endl;           flag = 1;           break;         }         if (num == 8) {           cout << 1 << endl;           cout << num << endl;           flag = 1;           break;         }         if (num == 9) {           cout << 1 << endl;           cout << num << endl;           flag = 1;           break;         }       }       if (flag == 1) continue;       if (element.find(2) != element.end() && element.find(7) != element.end()) {         cout << 2 << endl;         if (id2 < id7)           cout << 27 << endl;         else           cout << 72 << endl;       } else if (element.find(5) != element.end() &&                  element.find(7) != element.end()) {         cout << 2 << endl;         if (id5 > id7)           cout << 75 << endl;         else           cout << 57 << endl;       } else if (count2 >= 2) {         cout << 2 << endl;         cout << 22 << endl;       } else if (count3 >= 2) {         cout << 2 << endl;         cout << 33 << endl;       } else if (count7 >= 2) {         cout << 2 << endl;         cout << 77 << endl;       } else if (count5 >= 2) {         cout << 2 << endl;         cout << 55 << endl;       } else if (element.find(5) != element.end() &&                  element.find(2) != element.end()) {         cout << 2 << endl;         if (id2 > id5)           cout << 52 << endl;         else           cout << 25 << endl;       } else if (element.find(5) != element.end() &&                  element.find(3) != element.end() && id5 > id3) {         cout << 2 << endl;         if (id5 > id3) cout << 35 << endl;       } else if (element.find(2) != element.end() &&                  element.find(3) != element.end() && id2 > id3) {         cout << 2 << endl;         if (id2 > id3) cout << 32 << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int mp[1000007];   int dp[1010][10010];   int pre[1010][10010];   long long ans[1010][10010];   int out[1010][10010];   long long a[1010];   long long v[10010];   int cnt;   int add(long long k) {     if (!mp[k % 1000007]) {       v[++cnt] = k;       mp[k % 1000007] = cnt;     }     return mp[k % 1000007];   }   long long gcd(long long x, long long y) {     if (x % y == 0)       return y;     else       return gcd(y, x % y);   }   void output(int x, int y) {     printf( %d  , out[y][x]);     if (pre[y][x] == 1) return;     output(pre[y][x], out[y][x] - 1);   }   int main() {     int n;     long long k;     scanf( %d%lld , &n, &k);     for (int i = 1; i <= n; i++) {       scanf( %lld , &a[i]);     }     if (k == 1) {       long long p = a[1];       int x = 1;       for (int i = 1; i <= n; i++) {         if (p > a[i]) {           p = a[i];           x = i;         }       }       printf( %d n%d n , 1, x);       return 0;     }     memset(dp, -1, sizeof(dp));     add(k);     dp[0][1] = 0;     for (int i = 1; i <= n; i++) {       int cnt1 = cnt;       for (int k = 1; k <= cnt1; k++) {         dp[i][k] = dp[i - 1][k];         ans[i][k] = ans[i - 1][k];         pre[i][k] = pre[i - 1][k];         out[i][k] = out[i - 1][k];       }       for (int k = 1; k <= cnt1; k++) {         long long g = gcd(a[i], v[k]);         int x = add(v[k] / g);         if (dp[i][x] == -1 || dp[i][x] > dp[i - 1][k] + 1) {           dp[i][x] = dp[i - 1][k] + 1;           pre[i][x] = k;           ans[i][x] = ans[i - 1][k] + a[i];           out[i][x] = i;         } else if (dp[i][x] == dp[i - 1][k] + 1 &&                    ans[i][x] > ans[i - 1][k] + a[i]) {           pre[i][x] = k;           ans[i][x] = ans[i - 1][k] + a[i];           out[i][x] = i;         }       }     }     if (mp[1] == 0) {       printf( -1 n );     } else {       printf( %d n , dp[n][mp[1]]);       output(mp[1], n);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long double n, t;     cin >> n >> t;     cout << fixed << setprecision(10) << n * pow(1.000000011, t);   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   int arr[N];   long long seg[N << 2], mn[N << 2], lazy[N << 2];   bool flag[N << 2];   int n, q;   vector<long long> v;   void push_down(int id) {     if (flag[id]) {       lazy[id] = lazy[((id << 1) + 1)] = lazy[((id << 1) + 2)] = 0;       seg[((id << 1) + 1)] = seg[((id << 1) + 2)] = seg[id];       mn[((id << 1) + 1)] = mn[((id << 1) + 2)] = mn[id];       flag[((id << 1) + 1)] = flag[((id << 1) + 2)] = flag[id];       flag[id] = 0;     } else {       lazy[((id << 1) + 1)] += lazy[id];       lazy[((id << 1) + 2)] += lazy[id];       mn[((id << 1) + 1)] -= lazy[id];       mn[((id << 1) + 2)] -= lazy[id];       if (seg[((id << 1) + 1)] != -1) {         seg[((id << 1) + 1)] += lazy[id];       }       if (seg[((id << 1) + 2)] != -1) {         seg[((id << 1) + 2)] += lazy[id];       }       lazy[id] = 0;     }   }   void push_up(int id) {     mn[id] = min(mn[((id << 1) + 1)], mn[((id << 1) + 2)]);     if (seg[((id << 1) + 1)] == seg[((id << 1) + 2)]) {       seg[id] = seg[((id << 1) + 1)];     } else {       seg[id] = -1;     }   }   void build(int id = 0, int s = 0, int e = n) {     if (s + 1 == e) {       seg[id] = arr[s];       mn[id] = *upper_bound(v.begin(), v.end(), arr[s]) - arr[s];       return;     }     int mid = (s + e) >> 1;     build(((id << 1) + 1), s, mid);     build(((id << 1) + 2), mid, e);     push_up(id);   }   void print(int id = 0, int s = 0, int e = n) {     cout <<  [  << s + 1 <<  ,  << e <<  ]   << id <<   == >   << mn[id] <<              << seg[id] << endl;     if (s + 1 == e) {       return;     }     push_down(id);     int mid = (s + e) >> 1;     print(((id << 1) + 1), s, mid);     print(((id << 1) + 2), mid, e);     push_up(id);   }   long long query(int l, int r, int id = 0, int s = 0, int e = n) {     if (l >= e || r <= s) return 0;     if (s + 1 == e) return seg[id];     push_down(id);     int mid = (s + e) >> 1;     long long ret = query(l, r, ((id << 1) + 1), s, mid) +                     query(l, r, ((id << 1) + 2), mid, e);     push_up(id);     return ret;   }   void Set(int l, int r, int x, int id = 0, int s = 0, int e = n) {     if (l >= e || r <= s) return;     if (l <= s && r >= e) {       seg[id] = x;       flag[id] = true;       mn[id] = (*lower_bound(v.begin(), v.end(), x)) - x;       lazy[id] = 0;       return;     }     push_down(id);     int mid = (s + e) >> 1;     Set(l, r, x, ((id << 1) + 1), s, mid);     Set(l, r, x, ((id << 1) + 2), mid, e);     push_up(id);   }   void add(int l, int r, int x, int id = 0, int s = 0, int e = n) {     if (l >= e || r <= s) return;     if (l <= s && r >= e) {       if (seg[id] != -1) {         seg[id] += x;         mn[id] = (*lower_bound(v.begin(), v.end(), seg[id])) - seg[id];         flag[id] = true;         lazy[id] = 0;         return;       } else if (mn[id] >= x) {         mn[id] -= x;         lazy[id] += x;         return;       }     }     push_down(id);     int mid = (s + e) >> 1;     add(l, r, x, ((id << 1) + 1), s, mid);     add(l, r, x, ((id << 1) + 2), mid, e);     push_up(id);   }   int main() {     v.push_back(1);     while (v.back() < 1e17) {       v.push_back(v.back() * 42);     }     scanf( %d%d , &n, &q);     for (int i = 0; i < n; i++) scanf( %d , &arr[i]);     int type, a, b, x;     build();     while (q--) {       scanf( %d , &type);       if (type == 1) {         scanf( %d , &a);         printf( %lld n , query(a - 1, a));       } else if (type == 2) {         scanf( %d%d%d , &a, &b, &x);         Set(a - 1, b, x);       } else {         scanf( %d%d%d , &a, &b, &x);         do {           add(a - 1, b, x);         } while (mn[0] == 0);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double PI = 2 * acos(0);   int n;   char buf[10];   set<int> lhs;   set<int> rhs;   long long ret;   vector<int> unknown;   void update(int idx) {     if (!rhs.empty() && idx >= *rhs.begin()) {       rhs.insert(idx);       return;     }     if (!lhs.empty() && idx <= *lhs.rbegin()) {       lhs.insert(idx);       return;     }     unknown.push_back(idx);   }   void query(int idx) {     if (!rhs.empty() && idx > *rhs.begin()) {       printf( 0 n );       exit(0);     }     if (!lhs.empty() && idx < *lhs.rbegin()) {       printf( 0 n );       exit(0);     }     if (rhs.count(idx)) {       rhs.erase(idx);     } else if (lhs.count(idx)) {       lhs.erase(idx);     } else {       ret *= 2;       ret %= 1000000007;     }     for (int out : unknown) {       if (out > idx) {         rhs.insert(out);       } else if (out < idx) {         lhs.insert(out);       }     }     unknown.clear();   }   int main() {     scanf( %d n , &n);     ret = 1;     while (n--) {       int idx;       scanf( %s%d n , buf, &idx);       if (strlen(buf) == 3) {         update(idx);       } else {         query(idx);       }     }     long long scale = 1;     for (int out : unknown) {       if (!rhs.empty() && out > *rhs.begin()) continue;       if (!lhs.empty() && out < *lhs.rbegin()) continue;       scale++;     }     printf( %lld n , (ret * scale) % 1000000007);   }


#include <bits/stdc++.h>   template <typename T>   inline void read(T &x) {     x = 0;     register char ch;     register bool fl = 0;     while (ch = getchar(), ch < 48 || 57 < ch) fl ^= ch ==  - ;     x = (ch & 15);     while (ch = getchar(), 47 < ch && ch < 58)       x = (x << 1) + (x << 3) + (ch & 15);     if (fl) x = -x;   }   template <typename T>   inline void readc(T &x) {     while (x = getchar(), !islower(x) && !isupper(x))       ;   }   template <typename T>   inline void print(T x, char c =    ) {     static int buf[40];     if (x == 0) {       putchar( 0 );       putchar(c);       return;     }     if (x < 0) putchar( - ), x = -x;     for (buf[0] = 0; x; x /= 10) buf[++buf[0]] = x % 10 + 48;     while (buf[0]) putchar((char)buf[buf[0]--]);     putchar(c);   }   const int maxn = 100010;   int n, m, x, ans;   int c[maxn], f[maxn][20], cnt[maxn], dp[maxn];   long long s, a[maxn], g[maxn][20], sum[maxn];   int tot = 2, hed[maxn], to[maxn << 1], nxt[maxn << 1];   inline void add_edge(int u, int v) {     nxt[tot] = hed[u], to[tot] = v, hed[u] = tot++;     nxt[tot] = hed[v], to[tot] = u, hed[v] = tot++;   }   void dfs1(int u) {     for (int i = hed[u], v = to[i]; i; i = nxt[i], v = to[i])       if (v ^ f[u][0]) {         f[v][0] = u;         g[v][0] = a[u];         dfs1(v);       }   }   int dfs2(int u) {     int max = 0;     for (int i = hed[u], v = to[i]; i; i = nxt[i], v = to[i])       if (v ^ f[u][0]) {         max = std::max(max, dfs2(v));       }     if (!max) {       ans++;       max = dp[u];     }     return max - 1;   }   int main() {     read(n), read(m), read(s);     for (int i = 1; i <= n; i++) {       read(a[i]);       if (a[i] > s) {         puts( -1 );         return 0;       }     }     for (int i = 2; i <= n; i++) {       read(x);       add_edge(x, i);     }     dfs1(1);     for (int i = 1; i < 20; i++)       for (int j = 1; j <= n; j++) {         f[j][i] = f[f[j][i - 1]][i - 1];         g[j][i] = g[f[j][i - 1]][i - 1] + g[j][i - 1];       }     for (int k = 1, u = k; k <= n; k++, u = k) {       int stp = 1, sum = a[u];       for (int i = 19; i >= 0; i--)         if ((stp + (1 << i)) <= m && (sum + g[u][i]) <= s && f[u][i]) {           stp += 1 << i;           sum += g[u][i];           u = f[u][i];         }       dp[k] = stp;     }     dfs2(1);     print(ans,   n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool light[123456];   vector<int> v[123456];   bool visited[123456];   int connected[123456];   int main() {     int n;     cin >> n;     string s, t;     vector<string> rat, man, woman, child, capt;     for (__typeof(n) i = (0) - ((0) > (n)); i != (n) - ((0) > (n));          i += 1 - 2 * ((0) > (n))) {       cin >> s >> t;       if (t ==  rat )         rat.push_back(s);       else if (t ==  captain )         capt.push_back(s);       else if (t ==  woman  || t ==  child )         woman.push_back(s);       else if (t ==  man )         man.push_back(s);     }     for (__typeof(rat.size()) i = (0) - ((0) > (rat.size()));          i != (rat.size()) - ((0) > (rat.size()));          i += 1 - 2 * ((0) > (rat.size())))       cout << rat[i] << endl;     for (__typeof(woman.size()) i = (0) - ((0) > (woman.size()));          i != (woman.size()) - ((0) > (woman.size()));          i += 1 - 2 * ((0) > (woman.size())))       cout << woman[i] << endl;     for (__typeof(man.size()) i = (0) - ((0) > (man.size()));          i != (man.size()) - ((0) > (man.size()));          i += 1 - 2 * ((0) > (man.size())))       cout << man[i] << endl;     cout << capt[0] << endl;   }


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


#include <bits/stdc++.h>   using namespace std;   const int B = 172, N = 44005;   using ll = long long;   using Bit = bitset<B>;   unordered_map<Bit, int> mp;   Bit aa, a[N];   bool vis[20][N];   int cnt = 1, nxt[N][10];   ll dp[20][10][N];   int b[20];   ll solve(ll n, int kk) {     if (!n) return 1;     int m = 0, pos = 1;     while (n) b[m++] = n % 10, n /= 10;     ll ret = 0;     for (int i = m - 1; i >= 0; --i) {       for (int j = 0; j < b[i] + !i; j++) ret += dp[i][kk][nxt[pos][j]];       pos = nxt[pos][b[i]];     }     return ret;   }   int main() {     ios::sync_with_stdio(false);     aa[0] = 1;     a[mp[aa] = 1] = aa;     vis[0][1] = 1;     for (int i = 1; i < 20; i++)       for (int p = 1; p <= cnt; p++)         if (vis[i - 1][p])           for (int j = 0; j < 10; j++) {             if (!nxt[p][j]) {               if (!j)                 nxt[p][j] = p;               else {                 aa.reset();                 for (int k = j; k < B; k++)                   if (a[p][k]) aa[k - j] = 1;                 for (int k = 0; k < B - j; k++)                   if (a[p][k]) aa[k + j] = 1;                 for (int k = 1; k < j; k++)                   if (a[p][k]) aa[j - k] = 1;                 if (mp.count(aa))                   nxt[p][j] = mp[aa];                 else                   a[nxt[p][j] = mp[aa] = ++cnt] = aa;               }             }             vis[i][nxt[p][j]] = 1;           }     for (int j = 1; j <= cnt; j++) {       int k = 0;       while (k < 10)         if (!a[j][k])           ++k;         else           break;       while (k < 10) dp[0][k++][j] = 1;     }     for (int j = 1; j < 19; j++)       for (int k = 1; k <= cnt; k++)         if (vis[19 - j][k])           for (int i = 0; i < 10; i++)             for (int l = 0; l < 10; l++) dp[j][l][k] += dp[j - 1][l][nxt[k][i]];     int T;     cin >> T;     while (T--) {       ll l, r;       cin >> l >> r;       int kk;       cin >> kk;       cout << solve(r, kk) - solve(l - 1, kk) << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   pair<int, int> nextInt(const string &s, int ind) {     int ret = 0;     while (ind < s.length() && s[ind] >=  0  && s[ind] <=  9 ) {       ret = ret * 10 + ((int)s[ind] - 48);       ind++;     }     return make_pair(ret, ind);   }   int main() {     int counti = 0;     int n;     int w[1024];     vector<vector<int> > input;     for (int i = 0; i < 1024; i++) {       w[i] = 0;     }     cin >> n;     counti = n;     input.resize(n + 10);     for (int i = 1; i <= n; i++) {       input[i].push_back(-1);       string in;       cin >> in;       if (nextInt(in, 0).first == n - 1) {         w[i] = 1;       } else {         int ind = 0;         while (in[ind]) {           if (in[ind] >=  0  && in[ind] <=  9 ) {             pair<int, int> ret = nextInt(in, ind);             ind = ret.second;             input[i].push_back(ret.first);           } else if (in[ind] ==  - ) {             input[i].push_back(-1);             ind++;             counti++;           } else             ind++;         }       }     }     int weight = 1;     vector<pair<int, int> > ans;     while (weight < n) {       for (int i = 1; i <= n; i++) {         for (int j = 1; j < input[i].size(); j++)           if (input[i][j - 1] == -1 && input[i][j] == weight)             for (j = j + 1; j < input[i].size() && input[i][j] != -1; j++)               if (w[input[i][j]] == weight) {                 ans.push_back(make_pair(i, input[i][j]));                 if (w[i] == 0)                   w[i] = weight + 1;                 else                   w[i] += weight;               }       }       weight++;     }     if (n == 2) {       cout <<  1  << endl;       cout <<  1 2 ;       return 0;     }     if (ans.size() != n - 1 || counti != (n - 1) * 2) {       cout << -1;       return 0;     }     cout << ans.size() << endl;     for (int i = 0; i < ans.size(); i++)       cout << ans[i].first <<     << ans[i].second << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int vis[15];   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int t;     cin >> t;     while (t--) {       int a[3];       memset(vis, 0, sizeof(vis));       for (int i = 0; i < 3; i++) cin >> a[i];       int ans = 0;       for (int i = 0; i < 3; i++) {         if (a[i] - 1 >= 0) {           a[i]--;           ans++;         }         vis[a[i]]++;       }       if (vis[0] == 1 || vis[1] == 3)         printf( %d n , ans + 1);       else if (vis[0] == 2 || vis[0] == 3)         printf( %d n , ans);       else if (vis[1] == 1 || vis[1] == 2)         printf( %d n , ans + 2);       else if (vis[2])         printf( %d n , ans + 3);       else         printf( %d n , ans + 4);     }   }


#include <bits/stdc++.h>   using namespace std;   template <typename Arg1>   void __f(const char* name, Arg1&& arg1) {     cerr << name <<   :   << arg1 << std::endl;   }   template <typename Arg1, typename... Args>   void __f(const char* names, Arg1&& arg1, Args&&... args) {     const char* comma = strchr(names + 1,  , );     cerr.write(names, comma - names) <<   :   << arg1 <<   |  ;     __f(comma + 1, args...);   }   vector<pair<int, string> > ar[10005];   int main() {     int n, m;     cin >> n >> m;     for (int i = 0; i < n; i++) {       int a, b;       string s;       cin >> s >> a >> b;       ar[a].push_back({-b, s});     }     for (int i = 1; i <= m; i++) {       sort(ar[i].begin(), ar[i].end());       if ((int)(ar[i].size()) == 2)         cout << ar[i][0].second <<     << ar[i][1].second <<   n ;       else if (ar[i][1].first != ar[i][2].first)         cout << ar[i][0].second <<     << ar[i][1].second <<   n ;       else         cout <<  ? n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long a[5000];   int main() {     int t;     cin >> t;     while (t--) {       long long a, b, c, d;       cin >> a >> b >> c >> d;       long long p1 = b * c, p2 = (a - c - 1) * b, p3 = a * d,                 p4 = a * (b - d - 1);       cout << max(max(p1, p2), max(p3, p4)) << endl;     }   }


#include <bits/stdc++.h>   const int maxn = 3e5 + 7;   int ch[maxn << 5][2], max[maxn << 5], n, q, k, l[maxn], r[maxn], id[maxn],       rk[maxn], a, b, x, y, tl, rt[maxn];   int cmp(int x, int y) { return r[x] < r[y]; }   int insert(int rt, int L, int R, int p, int v) {     int nrt = ++tl;     ch[nrt][0] = ch[rt][0];     ch[nrt][1] = ch[rt][1];     max[nrt] = max[rt];     if (L == R) {       max[nrt] = std::max(max[nrt], v);       return nrt;     }     int mid = (L + R) >> 1;     if (p <= mid)       ch[nrt][0] = insert(ch[rt][0], L, mid, p, v);     else       ch[nrt][1] = insert(ch[rt][1], mid + 1, R, p, v);     max[nrt] = std::min(max[ch[nrt][0]], max[ch[nrt][1]]);     return nrt;   }   int query(int rt, int l, int r, int L, int R) {     if (l > R || r < L) return 1e9;     if (l <= L && R <= r) return max[rt];     return std::min(query(ch[rt][0], l, r, L, (L + R) >> 1),                     query(ch[rt][1], l, r, ((L + R) >> 1) + 1, R));   }   int main() {     scanf( %d%d%d , &n, &q, &k);     for (int i = 1; i <= k; ++i) {       scanf( %d%d%d , &l[i], &r[i], &id[i]);       rk[i] = i;     }     std::sort(rk + 1, rk + k + 1, cmp);     for (int i = 1; i <= k; ++i) {       rt[i] = insert(rt[i - 1], 1, n, id[rk[i]], l[rk[i]]);     }     while (q--) {       scanf( %d%d%d%d , &a, &b, &x, &y);       int L = 0, R = k, p;       while (L <= R) {         int mid = (L + R) >> 1;         if (r[rk[mid]] <= y) {           p = mid;           L = mid + 1;         } else           R = mid - 1;       }       if (query(rt[p], a, b, 1, n) >= x)         puts( yes );       else         puts( no );       fflush(stdout);     }     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   int ans, cnt;   struct Node {     Node *Left = NULL, *Right = NULL;     int value, fix, sz = 1;     long long sum[5] = {};   };   typedef Node *PNode;   PNode root = NULL;   inline int gts(PNode &cur) {     if (cur == NULL) return 0;     return cur->sz;   }   Node nodes[111111];   inline void Init(PNode &cur) {     if (cur) {       cur->sz = gts(cur->Left) + gts(cur->Right) + 1;       int t = 0;       if (cur->Left) {         for (int i = 0; i < 5; ++i) cur->sum[i] = cur->Left->sum[i];         t = cur->Left->sz % 5;       } else {         for (int i = 0; i < 5; ++i) cur->sum[i] = 0;       }       cur->sum[t] += cur->value;       t++;       t %= 5;       if (cur->Right) {         for (int i = 0; i < 5; ++i) {           int T = i + t;           T %= 5;           cur->sum[T] += cur->Right->sum[i];         }       }     }   }   inline void make(PNode a, PNode b, PNode &c) {     if (!b or !a) {       c = b ? b : a;       return;     }     if (a->fix > b->fix) {       make(a->Right, b, a->Right);       c = a;     } else {       make(a, b->Left, b->Left);       c = b;     }     Init(c);   }   inline void split(PNode t, PNode &a, PNode &b, int f) {     if (!t) {       a = b = NULL;       return;     }     if (f < t->value) {       split(t->Left, a, t->Left, f);       b = t;     } else {       split(t->Right, t->Right, b, f);       a = t;     }     Init(t);   }   inline void Insert(int val) {     PNode a, b, c;     split(root, a, c, val);     nodes[cnt].value = val;     nodes[cnt].fix = rand();     b = nodes + cnt++;     Init(b);     make(a, b, root);     make(root, c, root);   }   inline void Delete(PNode &cur, int val) {     if (cur->value == val) {       make(cur->Left, cur->Right, cur);     } else if (val < cur->value) {       Delete(cur->Left, val);     } else       Delete(cur->Right, val);     Init(cur);   }   inline int Find_Min(PNode cur) {     while (cur->Left) cur = cur->Left;     return cur->value;   }   inline int Find_Max(PNode cur) {     while (cur->Right) cur = cur->Right;     return cur->value;   }   int main() {     ios_base::sync_with_stdio(false);     int n, x, y, i, count = 0;     string s;     cin >> n;     for (i = 0; i < n; ++i) {       cin >> s;       if (s ==  add ) {         cin >> x;         count++;         Insert(x);       } else if (s ==  del ) {         cin >> x;         count--;         Delete(root, x);       } else {         if (!count)           printf( %d n , 0);         else           printf( %I64d n , root->sum[2]);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int a[200005], b[200005], c[200005];   class Myfirst {    private:     string *name;     long long int *age;       public:     long long int gcd(long long int a, long long int b) {       if (b == 0) return a;       a %= b;       return gcd(b, a);     }     long long int exte_gcd(long long int a, long long int b, long long int &x,                            long long int &y) {       if (b == 0) {         x = 1;         y = 0;         return a;       }       long long int x1, y1;       long long int d = exte_gcd(b, a % b, x1, y1);       x = y1;       y = x1 - y1 * (a / b);       return d;     }     long long int powe(long long int d, long long int s) {       if (s == 1)         return d;       else if (s == 0)         return 1;       else {         long long int u, v = d;         for (u = 1; u < s; u++) d = d * v;         return d;       }     }     long long int count_divisors(long long int b) {       long long int i, count = 0, n = 1;       for (i = 2; i * i <= b; i++) {         count = 0;         if (b % i == 0) {           while (b % i == 0) {             b = b / i;             count++;           }           n = n * (count + 1);         }       }       if (b > 1) n = 2 * n;       return n;     }     long long int bigmod(long long int a, long long int b, long long int mod) {       if (b == 0) return 1;       long long int x = bigmod(a, b / 2, mod);       x = (x * x) % mod;       if (b % 2) x = (x * a) % mod;       return x;     }     long long int phi(long long int n) {       double result = n;       for (long long int p = 2; p * p <= n; ++p) {         if (n % p == 0) {           while (n % p == 0) n /= p;           result *= (1.0 - (1.0 / (double)p));         }       }       if (n > 1) result *= (1.0 - (1.0 / (double)n));       return (long long int)result;     }     void solve() {       long long int t;       t = 1;       while (t--) {         long long int n, m, k, i, j, A, B;         cin >> n;         for (i = 1; i <= n; i++) cin >> a[i];         cin >> m;         for (i = 1; i <= m; i++) cin >> b[i];         cin >> k;         for (i = 1; i <= k; i++) cin >> c[i];         cin >> A >> B;         sort(a + 1, a + n + 1);         sort(b + 1, b + m + 1);         sort(c + 1, c + k + 1);         double ans;         ans = ((c[1] * 1.0) / b[m]) * ((A * 1.0) / B);         ans += 1.0;         ans = sqrt(1.0 / ans);         cout << setprecision(10);         cout << ans * a[n];       }     }   };   int main() {     Myfirst *prg = new Myfirst();     prg->solve();   }


#include <bits/stdc++.h>   using namespace std;   vector<string> s;   map<string, bool> was;   int main() {     int n;     cin >> n;     s.resize(n);     for (int i = 0; i < n; i++) {       cin >> s[i];     }     for (int i = n - 1; i >= 0; i--) {       if (!was[s[i]]) {         cout << s[i] <<   n ;         was[s[i]] = true;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     while (t--) {       int n, m;       cin >> n >> m;       vector<vector<ll>> a(n + 1, vector<ll>(m + 1));       for (int i = 1; i <= n; ++i) {         for (int j = 1; j <= m; ++j) {           cin >> a[i][j];         }       }       const ll I = 1e18;       ll b = I;       for (int i = 1; i <= n; ++i) {         for (int j = 1; j <= m; ++j) {           vector<vector<ll>> c(n + 1, vector<ll>(m + 1, I));           c[0][1] = c[1][0] = 0;           for (int g = 1; g <= n; ++g) {             for (int h = 1; h <= m; ++h) {               ll y = a[g][h] - (a[i][j] - (i - g) - (j - h));               if (y >= 0) {                 c[g][h] = min(c[g - 1][h] + y, c[g][h - 1] + y);               }             }           }           b = min(b, c[n][m]);         }       }       cout << b << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int a[n];     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 0; i < n; i++)       if (a[i] % 2 == 0) a[i]--;     for (int i = 0; i < n; i++) cout << a[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t, a1, a2, b1, b2, max1, max2;     cin >> t;     while (t > 0) {       cin >> a1 >> b1;       cin >> a2 >> b2;       max1 = max(a1, b1);       max2 = max(a2, b2);       if (max1 == max2) {         int min1, min2;         min1 = min(a1, b1);         min2 = min(a2, b2);         if ((min1 + min2) == max1) {           cout <<  Yes  << endl;         } else {           cout <<  No  << endl;         }       } else {         cout <<  No  << endl;       }       t--;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1145;   int n, m, q, k;   bitset<N> a[51], f, nw, tp, s[N];   unordered_map<bitset<N>, int> mn;   int main() {     scanf( %d%d%d , &n, &m, &q);     for (int i = 1, x, y; i <= m; i++) {       scanf( %d , &x);       while (x--) scanf( %d , &y), a[i][y] = 1;     }     k = min(20, m);     for (int i = 0; i < 1 << k; i++) {       f.reset();       for (int j = 1; j <= k; j++)         if (i & (1 << (j - 1))) f ^= a[j];       int ct = __builtin_popcount(i);       if (!mn.count(f) || mn[f] > ct) mn[f] = ct;     }     for (int i = 0; i < 1 << (m - k); i++)       for (int j = 1; j <= (m - k); j++)         if (i & (1 << (j - 1))) s[i] ^= a[k + j];     while (q--) {       int x, y;       scanf( %d , &x);       nw.reset();       int as = 1e7;       if (x == 0) {         puts( 0 );         continue;       }       while (x--) scanf( %d , &y), nw[y] = 1;       for (int i = 0; i < 1 << (m - k); i++) {         int ct = __builtin_popcount(i);         tp = nw ^ s[i];         if (mn[tp]) as = min(as, mn[tp] + ct);       }       if (as == 1e7)         puts( -1 );       else         printf( %d n , as);     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     scanf( %d %d , &n, &m);     char s[n][m];     int a[n][m];     int x = clock();     char ch;     scanf( %c , &ch);     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         s[i][j] = getchar();       }       char ch;       scanf( %c , &ch);       int last_zero = m;       for (int j = m - 1; j >= 0; j--) {         if (s[i][j] ==  0 ) {           last_zero = j;         }         a[i][j] = last_zero;       }     }     int szs[m + 1];     int final_ans = 0;     for (int lhs = 0; lhs < m; lhs++) {       memset(szs, 0, sizeof szs);       for (int i = 0; i < n; i++) {         if (s[i][lhs] ==  1 ) {           int sz = a[i][lhs] - lhs;           szs[sz]++;         }       }       int v = m * szs[m];       int cur_ans = v;       int sum_szs_prevs = szs[m];       for (int i = m - 1; i >= 1; i--) {         v = v - sum_szs_prevs + (i * szs[i]);         cur_ans = max(cur_ans, v);         sum_szs_prevs += szs[i];       }       final_ans = max(cur_ans, final_ans);     }     printf( %d , final_ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   void chkmin(T &a, T b) {     a = min(a, b);   }   template <typename T>   void chkmax(T &a, T b) {     a = max(a, b);   }   inline int fread(void) {     int ret = 0, op = 1;     char ch = getchar();     for (; !isdigit(ch); ch = getchar())       if (ch ==  - ) op = -1;     for (; isdigit(ch); ch = getchar()) ret = (ret << 1) + (ret << 3) -  0  + ch;     return ret * op;   }   const int MAXN = 4e5 + 10;   const int MAXM = +10;   int n, m;   struct Tuple {     int val, lm, rm, lp, rp, lt, rt;     Tuple operator+(const Tuple &b) {       Tuple ret;       ret.val = max(max(val, b.val), max(rp + b.lm, rm + b.lp));       ret.lp = max(lp, max(lt + rt + b.lm, rt - lt + b.lp));       ret.rp = max(b.rp, max(b.lt + b.rt + rm, b.lt - b.rt + rp));       ret.lm = max(lm, b.lm - rt + lt);       ret.rm = max(b.rm, rm - b.lt + b.rt);       if (lt > b.rt)         ret.lt = lt + b.lt - b.rt, ret.rt = rt;       else         ret.rt = b.rt - lt + rt, ret.lt = b.lt;       return ret;     }   } t[MAXN << 2];   int a[MAXN], mx;   void build(int x, int l, int r) {     if (l == r) {       t[x].lp = t[x].rp = 1;       t[x].lm = max(a[l], 0), t[x].rm = max(-a[l], 0);       t[x].lt = (a[l] == 1), t[x].rt = (a[l] == -1);       t[x].val = 1;       return;     }     build((x << 1), l, ((l + r) >> 1));     build((x << 1 | 1), ((l + r) >> 1) + 1, r);     t[x] = t[(x << 1)] + t[(x << 1 | 1)];   }   void modify(int x, int l, int r, int pos, int tp) {     if (l > r) return;     if (l == r) {       t[x].lp = t[x].rp = 1;       t[x].lm = max(tp, 0), t[x].rm = max(-tp, 0);       t[x].lt = (tp == 1), t[x].rt = (tp == -1);       t[x].val = 1;       return;     }     if (pos <= ((l + r) >> 1))       modify((x << 1), l, ((l + r) >> 1), pos, tp);     else       modify((x << 1 | 1), ((l + r) >> 1) + 1, r, pos, tp);     t[x] = t[(x << 1)] + t[(x << 1 | 1)];   }   inline void init(void) {     scanf( %d%d , &n, &m);     char ch;     mx = 2 * n - 2;     for (int i = 1; i <= mx; ++i) {       cin >> ch;       if (ch ==  ( )         a[i] = 1;       else         a[i] = -1;     }     build(1, 1, mx);   }   inline void work(void) {     int x, y;     printf( %d n , t[1].val);     for (int i = 1; i <= m; ++i) {       scanf( %d%d , &x, &y);       modify(1, 1, mx, x, a[y]);       modify(1, 1, mx, y, a[x]);       swap(a[x], a[y]);       printf( %d n , t[1].val);     }   }   int main() {     init();     work();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int v[200005];   bool inQ[200005];   vector<pair<int, int> > foo;   int main() {     int n, k, q, p, m, i, j;     bool ok;     pair<int, int> x;     cin >> n >> k >> m;     for (i = 1; i <= n; ++i) cin >> v[i];     priority_queue<pair<int, int> > pq;     for (j = 0; j < m; ++j) {       cin >> q >> p;       if (q == 1) {         if (!inQ[p]) {           pq.push({v[p], p});           inQ[p] = 1;         }       } else {         if (!inQ[p])           ok = 0;         else {           ok = i = 0;           while (!pq.empty() && i < k) {             x = pq.top();             pq.pop();             foo.push_back(x);             if (x.second == p) {               ok = true;               break;             }             ++i;           }           while (!foo.empty()) {             pq.push(foo.back());             foo.pop_back();           }         }         if (ok == true)           cout <<  YES n ;         else           cout <<  NO n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, ans;   int r, c;   char mp[201][201];   int ma[201][201];   int mac[201][201];   int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i < n; i++) {       char s[101];       scanf( %s , &s);       for (int j = 0; j < n; j++) {         mp[i][j] = s[j];       }       getchar();     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         if (mp[i][j] ==  # ) continue;         int flg1 = 0, flg2 = 0;         for (int kk = 0; kk < m; kk++) {           if (mp[i][j + kk] !=  . ) flg2 = 1;           if (mp[i + kk][j] !=  . ) flg1 = 1;         }         if (flg2 == 0) {           for (int kk = 0; kk < m; kk++) {             if (kk + j < n) ma[i][j + kk]++;             if (ma[i][j + kk] > ans) {               ans = ma[i][j + kk];               r = i;               c = j + kk;             }           }         }         if (flg1 == 0) {           for (int kk = 0; kk < m; kk++) {             if (i + kk < n) ma[i + kk][j]++;             if (ma[i + kk][j] > ans) {               ans = ma[i + kk][j];               r = i + kk;               c = j;             }           }         }       }     }     printf( %d %d , r + 1, c + 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2000003;   char s[maxn], t[maxn], tt[maxn];   int kmp[maxn];   int main() {     int T;     scanf( %d , &T);     while (T--) {       scanf( %s , s + 1);       int n = strlen(s + 1), p, len = 0;       for (p = 1; p <= n / 2 && s[p] == s[n - p + 1]; p++)         ;       if (p > n / 2) {         puts(s + 1);         continue;       }       for (int i = p; i <= n - p + 1; i++) t[++len] = s[i];       for (int i = 1; i <= len; i++) t[i + len] = t[i];       reverse(t + len + 1, t + len * 2 + 1);       len *= 2;       int pos = 0;       for (int i = 2; i <= len; i++) {         while (pos && t[pos + 1] != t[i]) pos = kmp[pos];         if (t[pos + 1] == t[i]) pos++;         kmp[i] = pos;       }       int tmp = kmp[len];       while (tmp > len / 2) tmp = kmp[tmp];       int ANS1 = (p - 1) * 2 + tmp;       for (int i = 1; i <= len; i++) tt[i] = t[i], kmp[i] = 0;       len = 0;       for (int i = n - p + 1; i >= p; i--) t[++len] = s[i];       for (int i = 1; i <= len; i++) t[i + len] = t[i];       reverse(t + len + 1, t + len * 2 + 1);       len *= 2;       pos = 0;       for (int i = 2; i <= len; i++) {         while (pos && t[pos + 1] != t[i]) pos = kmp[pos];         if (t[pos + 1] == t[i]) pos++;         kmp[i] = pos;       }       tmp = kmp[len];       while (tmp > len / 2) tmp = kmp[tmp];       int ANS2 = (p - 1) * 2 + tmp;       for (int i = 1; i <= len; i++) kmp[i] = 0;       for (int i = 1; i < p; i++) putchar(s[i]);       if (ANS1 > ANS2)         for (int i = 1; i <= ANS1 - (p - 1) * 2; i++) putchar(tt[i]);       else         for (int i = 1; i <= ANS2 - (p - 1) * 2; i++) putchar(t[i]);       for (int i = p - 1; i >= 1; i--) putchar(s[i]);       putchar(  n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t, n, i;     string a, b;     cin >> t;     while (t--) {       vector<int> k;       cin >> n >> a >> b;       for (i = 0; i < n; i++) {         if (a[i] != b[i]) {           k.push_back(i + 1);           k.push_back(1);           k.push_back(i + 1);         }       }       cout << k.size() <<    ;       for (auto x : k) cout << x <<    ;     }   }


#include <cassert>   #include <climits>   #include <cstdio>   #include <cstdlib>   #include <cstring>   #include <cmath>   #include <cctype>   #include <vector>   #include <string>   #include <queue>   #include <deque>   #include <stack>   #include <set>   #include <map>   #include <utility>   #include <algorithm>   #include <iostream>   #include <sstream>   #include <numeric>   using namespace std;      #define SIZE(x) int((x).size())   #define REP(i,c) for(auto &i : c)   #define pb push_back   #define eb emplace_back   typedef long long i64;   typedef unsigned long long u64;   const double EPS = 1e-12;   const int INF = 999999999;   typedef vector<int> VI;   typedef vector<string> VS;   typedef pair<int,int> PII;   typedef vector<PII> VPII;      const int MAXN=1500;      int n,m;   int a[MAXN][MAXN];   int f[MAXN][MAXN];      VPII row[MAXN]; // colors in a[i][j .. n]   VPII col[2][MAXN]; // colors in a[i..n][j]       // colors in square (i,j) ... (i+f[i]][j]-1, j+f[i][j-1]), order max(x-i,y-i)   VPII sq[2][MAXN];   int cur;      bool seen[MAXN*MAXN+1];      struct Fenwick {       int n;       VI f;          Fenwick(int n) : n(n)  {           f=VI(n+1,0);       }          inline int LowBit(int x) {           return x&(-x);       }          void Update(int i,int x) {           while(i>0) {               f[i]+=x;               i-=LowBit(i);           }       }          int Get(int i) {           int r=0;           while(i<=n) {               r+=f[i];               i+=LowBit(i);           }           return r;       }   };      void Dbg(const VPII& v) {       REP(p,v) printf( (%d %d)  ,p.first,p.second);printf(  n );   }      void Bf() {       for(int i=0;i<n;i++) {           for(int j=0;j<n;j++) {               int k;               set<int> s;               for(k=1;;k++) {                   if(i+k>n || j+k>n) break;                   for(int x=i;x<i+k;x++)                       for(int y=j;y<j+k;y++) s.insert(a[x][y]);                   if(SIZE(s)>m) break;               }               k--;               if(k!=f[i][j]) printf( Wrong %d %d: %d %d n ,i,j,k,f[i][j]);           }       }   }      void Solve() {       scanf( %d%d ,&n,&m);       for(int i=0;i<n;i++)           for(int j=0;j<n;j++) {               scanf( %d ,&a[i][j]);           }          cur=0;       for(int i=n-1;i>=0;i--) {           int pre=cur;           cur=cur^1;           for(int j=n-1;j>=0;j--) {               row[j]={{0,a[i][j]}};               col[cur][j]={{0,a[i][j]}};               sq[cur][j]={{0,a[i][j]}};               if(i==n-1 || j==n-1) {                   f[i][j]=1;                   continue;               }                  REP(p,row[j+1]) {                   if(p.second==a[i][j]) continue;                   row[j].eb(p.first+1,p.second);                   if(SIZE(row[j])>m) break;               }               // printf( Row %d %d n ,i,j);Dbg(row[j]);                  REP(p,col[pre][j]) {                   if(p.second==a[i][j]) continue;                   col[cur][j].eb(p.first+1,p.second);                   if(SIZE(col[cur][j])>m) break;               }               // printf( Col %d %d n ,i,j);Dbg(col[cur][j]);                  seen[a[i][j]]=1;               VI ps={0,0,0};               vector<const VPII*> vs={&row[j+1],&col[pre][j],&sq[pre][j+1]};               while(SIZE(sq[cur][j])<=m) {                   int md=INF;                   int mi=-1;                   for(int i=0;i<3;i++) {                       const VPII& v=*vs[i];                       if(ps[i]==SIZE(v)) continue;                       if(v[ps[i]].first<md) {                           md=v[ps[i]].first;                           mi=i;                       }                   }                   if(mi<0) break;                   const PII &u=(*vs[mi])[ps[mi]++];                   if(!seen[u.second]) {                       seen[u.second]=1;                       sq[cur][j].eb(u.first+1,u.second);                   }               }               REP(p,sq[cur][j]) seen[p.second]=0;               // printf( Sq %d %d n ,i,j);Dbg(sq[cur][j]);                  f[i][j]=min(n-i,n-j);               if(SIZE(sq[cur][j])>m) f[i][j]=min(f[i][j],sq[cur][j][m].first);               // printf( %d %d: %d n ,i,j,f[i][j]);           }       }          // Bf();          Fenwick ans(n);       for(int i=0;i<n;i++)           for(int j=0;j<n;j++) ans.Update(f[i][j],1);       for(int i=1;i<=n;i++) printf( %d n ,ans.Get(i));      }      int main() {       Solve();          return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ld = long double;   const int maxn = 1e6 + 2;   const int base = 31;   const int mod = 1e9 + 7;   ll t;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     cin >> t;     while (t--) {       ll n, x = 0;       cin >> n;       vector<ll> a(n);       for (ll i = 0; i < n; i++) {         cin >> a[i];         x ^= a[i];       }       if (x == 0)         cout <<  DRAW n ;       else {         ll bit = 30;         while (!(x & (1 << bit))) {           --bit;         }         ll k0 = 0, k1 = 0;         for (auto k : a) {           if (k & (1 << bit)) {             k1++;           } else             k0++;         }         assert(k1 % 2 == 1);         if (k0 % 2 == 0 && k1 % 4 == 3) {           cout <<  LOSE  <<   n ;         } else           cout <<  WIN  <<   n ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int pi[200015];   void PreKMP(char *P, int n) {     int q, k = 0;     pi[1] = 0;     for (q = 2; q <= n; pi[q++] = k) {       while (k && (P[k] != P[q - 1])) k = pi[k];       if (P[k] == P[q - 1]) k++;     }   }   int KMP(char *T, int n, char *P, int m) {     int i, q = 0;     PreKMP(P, m);     for (i = 1; i <= n; i++) {       while ((q > 0) && (P[q] != T[i - 1])) q = pi[q];       if (P[q] == T[i - 1]) q++;       if (q == m) return m;     }     return q;   }   char a[200015];   char b[200015];   char c[200015];   char cadab[200015];   char cadac[200015];   char cadba[200015];   char cadbc[200015];   char cadca[200015];   char cadcb[200015];   int main() {     while (scanf( %s%s%s , a, b, c) != EOF) {       int sa = strlen(a);       int sb = strlen(b);       int sc = strlen(c);       PreKMP(a, sa);       int ab = KMP(a, sa, b, sb);       int ac = KMP(a, sa, c, sc);       PreKMP(b, sb);       int ba = KMP(b, sb, a, sa);       int bc = KMP(b, sb, c, sc);       PreKMP(c, sc);       int ca = KMP(c, sc, a, sa);       int cb = KMP(c, sc, b, sb);       int minn = sa + sb + sc;       minn = min(minn, sa + (sb - ab) + (sc - bc));       minn = min(minn, sa + (sc - ac) + (sb - cb));       minn = min(minn, sb + (sa - ba) + (sc - ac));       minn = min(minn, sb + (sc - bc) + (sa - ca));       minn = min(minn, sc + (sa - ca) + (sb - ab));       minn = min(minn, sc + (sb - cb) + (sa - ba));       int sab = 0;       int sac = 0;       int sba = 0;       int sbc = 0;       int sca = 0;       int scb = 0;       for (int i = 0; i < sa; i++) {         cadab[sab++] = a[i];         cadac[sac++] = a[i];       }       for (int i = 0; i < sb; i++) {         cadba[sba++] = b[i];         cadbc[sbc++] = b[i];       }       for (int i = 0; i < sc; i++) {         cadca[sca++] = c[i];         cadcb[scb++] = c[i];       }       for (int i = ab; i < sb; i++) {         cadab[sab++] = b[i];       }       for (int i = ac; i < sc; i++) {         cadac[sac++] = c[i];       }       for (int i = ba; i < sa; i++) {         cadba[sba++] = a[i];       }       for (int i = bc; i < sc; i++) {         cadbc[sbc++] = c[i];       }       for (int i = ca; i < sa; i++) {         cadca[sca++] = a[i];       }       for (int i = ac; i < sc; i++) {         cadcb[scb++] = b[i];       }       if (KMP(cadab, sab, c, sc) == sc) minn = min(minn, sab);       if (KMP(cadac, sac, b, sb) == sb) minn = min(minn, sac);       if (KMP(cadba, sba, c, sc) == sc) minn = min(minn, sba);       if (KMP(cadbc, sbc, a, sa) == sa) minn = min(minn, sbc);       if (KMP(cadca, sca, b, sb) == sb) minn = min(minn, sca);       if (KMP(cadcb, scb, a, sa) == sa) minn = min(minn, scb);       printf( %d n , minn);     }   }


#include <bits/stdc++.h>   using namespace std;   const double pi = acos(-1.0);   const int inf = 10000000;   int arr[100005];   map<int, int> mm;   int main() {     int n, k;     cin >> n >> k;     for (int i = 0; i < (n); i++) {       cin >> arr[i];       mm[arr[i]] = 1;     }     sort(arr, arr + n);     int ans = 0;     for (int i = n - 1; i >= 0; i--) {       if (mm[arr[i]] == 0) continue;       if (arr[i] % k != 0) {         ans++;         continue;       }       if (mm.find(arr[i] / k) != mm.end()) mm[arr[i] / k] = 0;       ans++;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   const long long inf = 0x3f3f3f3f3f3f3f3LL;   const long long mod = (long long)1e9 + 7;   using namespace std;   template <class T>   void smin(T& a, T val) {     if (a > val) a = val;   }   template <class T>   void smax(T& a, T val) {     if (a < val) a = val;   }   const long long N = 100 + 5;   long long dp[N][N][N][2];   vector<long long> prefix_function(string s) {     long long n = (long long)s.length();     vector<long long> pi(n);     for (long long i = 1; i < n; i++) {       long long j = pi[i - 1];       while (j > 0 && s[i] != s[j]) j = pi[j - 1];       if (s[i] == s[j]) j++;       pi[i] = j;     }     return pi;   }   string s, t, pat;   vector<long long> pi;   long long solve(long long idx1, long long idx2, long long idx3,                   long long ongoing) {     if (idx3 == (long long)(pat.size())) {       return -inf;     }     if (idx1 == (long long)(s.size()) or idx2 == (long long)(t.size())) {       return 0;     }     long long& ans = dp[idx1][idx2][idx3][ongoing];     if (~ans) return ans;     ans = 0;     if (!ongoing) {       smax(ans, solve(idx1 + 1, idx2, idx3, 0));       smax(ans, solve(idx1, idx2 + 1, idx3, 0));     }     if (s[idx1] == t[idx2]) {       if (s[idx1] == pat[idx3]) {         smax(ans, 1 + solve(idx1 + 1, idx2 + 1, idx3 + 1, 0));       } else {         if (idx3 == 0) {           smax(ans, 1 + solve(idx1 + 1, idx2 + 1, 0, 0));         } else {           smax(ans, solve(idx1, idx2, pi[idx3 - 1], 1));         }       }     }     return ans;   }   string vals =   ;   void path(long long idx1, long long idx2, long long idx3, long long ongoing) {     if (idx1 == (long long)(s.size()) or idx2 == (long long)(t.size())) {       return;     }     long long ans = solve(idx1, idx2, idx3, ongoing);     if (!ongoing) {       if (ans == solve(idx1 + 1, idx2, idx3, 0)) {         path(idx1 + 1, idx2, idx3, 0);         return;       } else if (ans == solve(idx1, idx2 + 1, idx3, 0)) {         path(idx1, idx2 + 1, idx3, 0);         return;       }     }     if (s[idx1] == t[idx2]) {       if (s[idx1] == pat[idx3]) {         vals += s[idx1];         path(idx1 + 1, idx2 + 1, idx3 + 1, 0);       } else {         if (idx3 == 0) {           vals += s[idx1];           path(idx1 + 1, idx2 + 1, 0, 0);         } else {           path(idx1, idx2, pi[idx3 - 1], 1);         }       }     }   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cin >> s >> t >> pat;     memset(dp, -1, sizeof dp);     pi = prefix_function(pat);     solve(0, 0, 0, 0);     path(0, 0, 0, 0);     if ((long long)(vals.size()) == 0) {       cout << 0;       exit(0);     }     cout << vals;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     string s;     cin >> s;     int n = s.length();     vector<int> v;     for (int i = 0; i < n; i++)       if (i == n - 1 || s[i] != s[i + 1]) v.push_back(i);     if (s.back() ==  b ) v.pop_back();     vector<int> res(n);     for (int p : v) res[p] = 1;     for (int id : res) cout << id <<    ;     cout <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false), cout.tie(0), cin.tie(0);     int n;     cin >> n;     if (n <= 3) {       cout << 0 <<   n ;       return 0;     }     int Max = -1, k;     for (int i = 2; i < n; ++i) {       int tp = n / i * (i - 1);       if (n % i >= 1) tp += n % i - 1;       tp -= i - 1;       if (tp > Max) Max = tp, k = i;     }     set<int> Se;     vector<int> SS(n);     int a = n / k, ps = 0;     for (int i = 0; i < a; ++i) {       for (int j = 0; j < k; ++j) {         if (j == k - 1)           ps++;         else           Se.insert(ps++);       }     }     for (; ps < n - 1; ++ps) Se.insert(ps);     for (int i : Se) SS[i] = 1;     bool ok = 0;     while (!ok) {       vector<int> A;       for (int i = 0; i < k; ++i)         if (((int)(Se).size())) {           A.push_back(*Se.begin());           Se.erase(Se.begin());         }       if (((int)(Se).size()) == 0) ok = 1;       cout << ((int)(A).size()) <<    ;       for (int i : A) cout << i + 1 <<    ;       cout << endl;       cout.flush();       int l;       cin >> l;       --l;       for (int i = 0; i < k; ++i) {         if (SS[(i + l) % n]) Se.insert((i + l) % n);       }       if (ok) {         cout << 0 << endl;         cout.flush();       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long somod = 1e9 + 7;   const long long maxn = 5e4 + 7;   long long cntnode = 1, m, n, a[maxn];   vector<long long> vt[maxn * 31];   long long cac[32][2];   map<long long, vector<long long>> mp;   long long Pow(long long a, long long b) {     long long ans = 1;     for (; b > 0; b >>= 1, a = a * a % somod) {       if (b & 1) ans = ans * a % somod;     }     return ans;   }   void Update(long long x, long long delta) {     for (long long i = 29; i >= 0; i--) {       cac[i][(x >> i & 1)] += delta;     }   }   long long Cal(long long x) {     long long ans = 0;     for (long long i = 29; i >= 0; i--) {       ans += cac[i][(x >> i & 1) ^ 1] * (1 << i);       ans %= somod;     }     return ans;   }   pair<long long, long long> Count(long long curval, long long lastbit) {     mp.clear();     long long f = 0, s = 0;     for (long long i = 1; i <= n; i++) {       long long val = 0;       for (long long j = 29; j >= lastbit; j--) {         val ^= (a[i] & (1 << j));       }       mp[val].push_back(a[i]);     }     for (auto i : mp) {       long long yay = i.first ^ curval;       if (mp.count(yay) == 0) continue;       s += mp[yay].size() * i.second.size();       for (auto j : i.second) Update(j, 1);       for (auto j : mp[yay]) f = f + Cal(j);       f %= somod;       for (auto j : i.second) Update(j, -1);     }     s /= 2;     f = f * Pow(2, somod - 2) % somod;     return {f, s};   }   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     if (fopen( test.inp ,  r )) freopen( test.inp ,  r , stdin);     cin >> n >> m;     for (long long i = 1; i <= n; i++) {       cin >> a[i];     }     long long val = 0, ans = 0;     for (long long i = 29; i >= 0; i--) {       pair<long long, long long> cc = Count(val ^ (1 << i), i);       if (cc.second <= m) {         m -= cc.second, ans += cc.first;       } else {         val ^= (1 << i);       }       if (i == 0) {         ans += (val)*m;       }     }     cout << ans % somod <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 10;   int a[N], f[N];   int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }   int main() {     int T;     cin >> T;     while (T--) {       int n, k;       scanf( %d , &n);       memset(a, 0, sizeof a);       for (int i = 1; i <= n; i++) f[i] = 1;       for (int i = 1; i <= n; i++) scanf( %d , &a[i]);       for (int i = 1; i <= n; i++)         for (int j = 2 * i; j <= n; j += i)           if (a[i] < a[j]) f[j] = max(f[j], f[i] + 1);       int res = 0;       for (int i = 1; i <= n; i++) res = max(res, f[i]);       printf( %d n , res);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   const long long N = 200005;   long long fasmul(long long a, long long b) {     long long res = 1;     while (b) {       if (b & 1) res = (res * a) % mod;       a = (a * a) % mod;       b = b / 2;     }     return res;   }   void solve() {     long long n;     char c;     string s;     cin >> n >> c >> s;     long long d = n / 2;     long long ok = 1;     for (long long i = 0; i < n; i++)       if (s[i] != c) ok = 0;     if (ok) {       cout << 0 <<   n ;       return;     }     for (long long i = d; i < n; i++) {       if (s[i] == c) {         cout << 1 <<   n ;         cout << i + 1 <<   n ;         return;       }     }     cout << 2 <<   n ;     cout << n <<     << n - 1 <<   n ;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     ;     long long t = 1;     cin >> t;     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n;     cin >> n;     long long int a[n], mx = 0;     for (int i = 0; i < n; i++) {       cin >> a[i];       if (a[i] > mx) mx = a[i];     }     long long int freq[mx + 1];     for (int i = 0; i < mx + 1; i++) {       freq[i] = 0;     }     for (int i = 0; i < n; i++) {       freq[a[i]]++;     }     long long int dp[mx + 1];     dp[0] = 0;     dp[1] = freq[1];     for (int i = 2; i <= mx; i++) {       dp[i] = max(dp[i - 1], (freq[i] * i) + dp[i - 2]);     }     cout << dp[mx];   }


#include <bits/stdc++.h>   using namespace std;   const int INF = (1 << 30);   const double eps = 1e-9;   const int mod = 1000000007;   const int MAXN = int(1e5) + 100;   const int dx[] = {-1, +1, 0, 0};   const int dy[] = {0, 0, -1, +1};   int main() {     ios::sync_with_stdio(false);     int n;     cin >> n;     vector<int> arr(n);     for (int i = (0); i < int(n); ++i) {       cin >> arr[i];     }     sort((arr).begin(), (arr).end());     for (int i = (1); i < int(n); ++i) {       int x = arr[i - 1];       int y = arr[i];       if (x == y) continue;       if (y < x * 2) {         cout <<  YES  << endl;         return 0;       }     }     cout <<  NO  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   int n;   vector<int> dig;   long long cnt[15];   long long C[25][25];   struct cond {     int sum;     int a[20];     string s;     cond() {       for (int i = 0; i < 20; i++) {         a[i] = 0;       }       s =   ;       sum = 0;     }   };   void calculateC() {     for (int i = 0; i <= 20; i++)       for (int j = 0; j <= 20; j++) C[i][j] = 0;     for (int i = 0; i < 20; i++) C[i][0] = 1;     for (int i = 1; i <= 20; i++)       for (int j = 1; j <= 20; j++)         C[i][j] =             ((C[i][j] % MOD) + ((C[i - 1][j] + C[i - 1][j - 1]) % MOD)) % MOD;   }   long long C2(int n, int k) {     if (n < 0 || k < 0 || k > n) return 0;     long long ans = 1;     for (int i = n; i > n - k; i--) ans = (ans * i) % MOD;     return ans % MOD;   }   long long Power2(int n) {     long long k = 1ll;     for (int i = 1; i <= n; i++) k = (k * 2ll) % MOD;     return k;   }   long long Power8(int n) {     long long k = 1ll;     for (int i = 1; i <= n; i++) k = (k * 8ll) % MOD;     return k;   }   bool good(int n) {     if (n == 4 || n == 7) return true;     return false;   }   void findcnt(int pos, int sum) {     if (pos == (int)dig.size()) return;     int p = (int)dig.size() - pos;     long long Q = (long long)dig[pos];     if (p == 1) {       cnt[0]--;       for (int i = 0; i <= Q; i++)         if (good(i))           cnt[sum + 1]++;         else           cnt[sum]++;       return;     }     for (int i = 0; i <= p - 1; i++) {       for (int j = 0; j < Q; j++) {         if (!good(j))           cnt[i + sum] += Power2(i) * C[p - 1][i] * Power8(p - 1 - i);         else           cnt[i + sum + 1] += Power2(i) * C[p - 1][i] * Power8(p - 1 - i);       }     }     if (good(dig[pos]))       findcnt(pos + 1, sum + 1);     else       findcnt(pos + 1, sum);   }   long long ans = 0;   vector<cond> allposib;   void BT(int pos, int sum, string s) {     if (pos == 6) {       cond A;       for (int i = 0; i < (int)s.length(); i++) A.a[(int)s[i] - (int) 0 ]++;       A.sum = sum;       A.s = s;       if (sum <= 10) allposib.push_back(A);     } else       for (int i = 0; i <= 10; i++)         BT(pos + 1, sum + i, s + (char)(i + (int) 0 ));   }   int fac(int n) {     int ans = 1;     for (int i = 1; i <= n; i++) ans *= i;     return ans;   }   int main() {     calculateC();     for (int i = 0; i <= 10; i++) cnt[i] = 0;     cin >> n;     while (n) {       dig.push_back(n % 10);       n /= 10;     }     reverse((dig).begin(), (dig).end());     findcnt(0, 0);     BT(0, 0,   );     long long ans = 0;     for (int i = 0; i < (int)allposib.size(); i++) {       int from = allposib[i].sum + 1;       long long tmp = 1, posfor7 = 0;       for (int j = 0; j <= 10; j++) {         tmp = (tmp * (C2(cnt[j], allposib[i].a[j]))) % MOD;       }       for (int j = from; j <= 10; j++) posfor7 += cnt[j];       posfor7 %= MOD;       tmp = (tmp * posfor7) % MOD;       ans = (ans + tmp) % MOD;     }     cout << ans % MOD << endl;     return 0;   }