#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline void checkMin(T &a, T b) {     if (b < a) a = b;   }   template <typename T>   inline void checkMax(T &a, T b) {     if (a < b) a = b;   }   const int P = 1e7 + 19;   const int Q = 1e9 + 7;   const int MAX_N = 5005 + 30000;   int n, k, w[MAX_N], v[MAX_N];   long long dp[32][1001];   int beg[MAX_N], qc[MAX_N];   set<pair<int, int>, greater<pair<int, int>>> es[MAX_N];   void dfs(int depth, int l, int r) {     copy(dp[depth - 1], dp[depth], dp[depth]);     for (auto iter = es[l].begin(); iter != es[l].end();) {       if (iter->first < r) break;       int i = iter->second;       if (iter->first > r) {         es[r + 1].emplace(iter->first, i);       }       iter = es[l].erase(iter);       for (int j = k; j >= w[i]; --j) {         checkMax(dp[depth][j], dp[depth][j - w[i]] + v[i]);       }     }     if (l == r) {       if (!qc[l]) return;       int ans = 0;       for (int i = k; i >= 1; --i) {         ans = ((long long)ans * P + dp[depth][i]) % Q;       }       for (int i = 0; i < int(qc[l]); ++i) {         printf( %d n , ans);       }     } else {       int m = (l + r) >> 1;       dfs(depth + 1, l, m);       dfs(depth + 1, m + 1, r);     }   }   int main() {     while (~scanf( %d%d , &n, &k)) {       fill(qc, qc + MAX_N, 0);       fill(es, es + MAX_N, set<pair<int, int>, greater<pair<int, int>>>());       int ts = 1;       for (int i = 1; i <= n; ++i) {         scanf( %d%d , &v[i], &w[i]);         beg[i] = ts;       }       int q, type, x;       scanf( %d , &q);       for (int i = 0; i < int(q); ++i) {         scanf( %d , &type);         if (type == 1) {           ++ts;           ++n;           scanf( %d%d , &v[n], &w[n]);           beg[n] = ts;         } else if (type == 2) {           scanf( %d , &x);           es[beg[x]].emplace(ts++, x);           beg[x] = -1;         } else {           ++qc[ts];         }       }       for (int i = 1; i <= n; ++i) {         if (beg[i] == -1) continue;         es[beg[i]].emplace(ts, i);       }       dfs(1, 1, ts);     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   inline long long getint() {     long long _x = 0, _tmp = 1;     char _tc = getchar();     while ((_tc <  0  || _tc >  9 ) && _tc !=  - ) _tc = getchar();     if (_tc ==  - ) _tc = getchar(), _tmp = -1;     while (_tc >=  0  && _tc <=  9 ) _x *= 10, _x += (_tc -  0 ), _tc = getchar();     return _x * _tmp;   }   inline long long add(long long _x, long long _y,                        long long _mod = 1000000007LL) {     _x += _y;     return _x >= _mod ? _x - _mod : _x;   }   inline long long sub(long long _x, long long _y,                        long long _mod = 1000000007LL) {     _x -= _y;     return _x < 0 ? _x + _mod : _x;   }   inline long long mul(long long _x, long long _y,                        long long _mod = 1000000007LL) {     _x *= _y;     return _x >= _mod ? _x % _mod : _x;   }   long long mypow(long long _a, long long _x, long long _mod) {     if (_x == 0) return 1LL;     long long _ret = mypow(mul(_a, _a, _mod), _x >> 1, _mod);     if (_x & 1) _ret = mul(_ret, _a, _mod);     return _ret;   }   long long mymul(long long _a, long long _x, long long _mod) {     if (_x == 0) return 0LL;     long long _ret = mymul(add(_a, _a, _mod), _x >> 1, _mod);     if (_x & 1) _ret = add(_ret, _a, _mod);     return _ret;   }   inline bool equal(double _x, double _y) {     return _x > _y - 1e-9 && _x < _y + 1e-9;   }   int __ = 1, _cs;   struct Maxflow {     static const int MAXV = 20010;     struct Edge {       int v, c, r;       Edge(int _v, int _c, int _r) : v(_v), c(_c), r(_r) {}     };     int s, t;     vector<Edge> G[MAXV * 2];     int iter[MAXV * 2], d[MAXV * 2], gap[MAXV * 2], tot;     void init(int x) {       tot = x + 2;       s = x + 1, t = x + 2;       for (int i = 0; i <= tot; i++) {         G[i].clear();         iter[i] = d[i] = gap[i] = 0;       }     }     void addEdge(int u, int v, int c) {       G[u].push_back(Edge(v, c, (int)(G[v]).size()));       G[v].push_back(Edge(u, 0, (int)(G[u]).size() - 1));     }     int dfs(int p, int flow) {       if (p == t) return flow;       for (int &i = iter[p]; i < (int)(G[p]).size(); i++) {         Edge &e = G[p][i];         if (e.c > 0 && d[p] == d[e.v] + 1) {           int f = dfs(e.v, min(flow, e.c));           if (f) {             e.c -= f;             G[e.v][e.r].c += f;             return f;           }         }       }       if ((--gap[d[p]]) == 0)         d[s] = tot;       else {         d[p]++;         iter[p] = 0;         ++gap[d[p]];       }       return 0;     }     int solve() {       int res = 0;       gap[0] = tot;       for (res = 0; d[s] < tot; res += dfs(s, 1000000LL))         ;       return res;     }   } flow;   void build() {}   int n, m, s, t;   int ui[10210], vi[10210], gi[10210];   vector<int> g[10210], rg[10210];   void init() {     n = getint();     m = getint();     s = getint();     t = getint();     flow.init(n);     for (int i = 0; i < m; i++) {       ui[i] = getint();       vi[i] = getint();       gi[i] = getint();       g[ui[i]].push_back(i);       rg[vi[i]].push_back(i);       if (gi[i]) {         flow.addEdge(ui[i], vi[i], 1);         flow.addEdge(vi[i], ui[i], 1000000LL);       } else         flow.addEdge(ui[i], vi[i], 1000000LL);     }     flow.addEdge(flow.s, s, 1000000LL);     flow.addEdge(t, flow.t, 1000000LL);   }   set<int> reachable;   bool tg[10210], sat[10210];   int f[10210], c[10210];   int sbk[10210], sbke[10210];   int tbk[10210], tbke[10210];   bool vst[10210], vst2[10210];   int fucktag[10210], fuck;   bool go_to_s(int cur) {     assert(vst[cur]);     ++fuck;     int st = cur;     while (cur != s) {       if (fucktag[sbke[cur]] == fuck) return false;       fucktag[sbke[cur]] = fuck;       f[sbke[cur]]++;       cur = sbk[cur];       if (cur == st) return false;     }     return true;   }   bool go_to_t(int cur) {     assert(vst2[cur]);     ++fuck;     int st = cur;     while (cur != t) {       if (fucktag[tbke[cur]] == fuck) return false;       fucktag[tbke[cur]] = fuck;       f[tbke[cur]]++;       cur = tbk[cur];       if (cur == st) return false;     }     return true;   }   int ss[10210], stmp;   int who[10210], ee[10210];   bool find_cycle(int now, int st, int dep = 0) {     ss[now] = stmp;     who[dep] = now;     for (auto eid : g[now]) {       if (gi[eid] == 0) continue;       int nxt = vi[eid];       if (nxt == st) {         sbke[st] = eid;         sbk[st] = now;         vst[st] = true;         for (int i = 1; i <= dep; i++) {           sbk[who[i]] = who[i - 1];           vst[who[i]] = true;           sbke[who[i]] = ee[i - 1];         }         return true;       }       if (ss[nxt] == stmp) continue;       ee[dep] = eid;       if (find_cycle(nxt, st, dep + 1)) return true;     }     return false;   }   bool find_cycle2(int now, int st, int dep = 0) {     ss[now] = stmp;     who[dep] = now;     for (auto eid : rg[now]) {       if (gi[eid] == 0) continue;       int nxt = ui[eid];       if (nxt == st) {         tbke[st] = eid;         tbk[st] = now;         vst2[st] = true;         for (int i = 1; i <= dep; i++) {           tbk[who[i]] = who[i - 1];           vst2[who[i]] = true;           tbke[who[i]] = ee[i - 1];         }         return true;       }       if (ss[nxt] == stmp) continue;       ee[dep] = eid;       if (find_cycle2(nxt, st, dep + 1)) return true;     }     return false;   }   void pre_build() {     {       vst[s] = true;       queue<int> Q;       Q.push(s);       while (Q.size()) {         int tn = Q.front();         Q.pop();         for (auto eid : g[tn]) {           if (gi[eid] == 0) continue;           if (vst[vi[eid]]) continue;           vst[vi[eid]] = true;           sbk[vi[eid]] = ui[eid];           sbke[vi[eid]] = eid;           Q.push(vi[eid]);         }       }       for (int i = 1; i <= n; i++) {         if (!vst[i]) {           ++stmp;           if (find_cycle(i, i)) vst[i] = true;         }       }     }     {       vst2[t] = true;       queue<int> Q;       Q.push(t);       while (Q.size()) {         int tn = Q.front();         Q.pop();         for (auto eid : rg[tn]) {           if (gi[eid] == 0) continue;           if (vst2[ui[eid]]) continue;           vst2[ui[eid]] = true;           tbk[ui[eid]] = vi[eid];           tbke[ui[eid]] = eid;           Q.push(ui[eid]);         }       }       for (int i = 1; i <= n; i++)         if (!vst2[i]) {           ++stmp;           if (find_cycle2(i, i)) vst2[i] = true;         }     }   }   int ff[10210];   void solve() {     int ans = flow.solve();     queue<int> Q;     reachable.insert(s);     tg[s] = true;     Q.push(s);     while (Q.size()) {       int tn = Q.front();       Q.pop();       for (auto e : flow.G[tn]) {         if (e.c == 0) continue;         if (1 <= e.v and e.v <= n and !tg[e.v]) {           tg[e.v] = true;           Q.push(e.v);           reachable.insert(e.v);         }       }     }     int cc = 0;     for (int i = 0; i < m; i++)       if (reachable.find(ui[i]) != reachable.end() and           reachable.find(vi[i]) == reachable.end()) {         sat[i] = true;         ++cc;       }     assert(cc == ans);     pre_build();     for (int i = 0; i < m; i++) {       if (f[i]) continue;       if (gi[i] == 0) continue;       bool x = go_to_s(ui[i]);       bool y = go_to_t(vi[i]);       if (x and y) f[i]++;       if (f[i] == 0) f[i] = 1;     }     for (int i = 0; i < m; i++) {       if (gi[i] == 0)         c[i] = 1000000LL;       else {         c[i] = f[i];         if (!sat[i]) c[i]++;       }     }     ans = 0;     for (int i = 0; i < m; i++)       if (f[i] == c[i]) ans++;     printf( %d n , ans);     for (int i = 0; i < m; i++) {       printf( %d %d n , f[i], c[i]);       ff[ui[i]] -= f[i];       ff[vi[i]] += f[i];     }   }   int main() {     build();     while (__--) {       init();       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   long long dp[10000006];   int main() {     long long n, x, y;     scanf( %lld%lld%lld , &n, &x, &y);     for (int i = 0; i <= n; ++i) dp[i] = 1e18 + 100;     dp[1] = x;     for (int i = 2; i <= n; ++i) {       if (i % 2 == 1)         dp[i] = min(dp[i - 1] + x, min(dp[i / 2] + y + x, dp[i / 2 + 1] + y + x));       else         dp[i] = min(dp[i - 1] + x, dp[i / 2] + y);     }     printf( %lld n , dp[n]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     while (t--) {       long long n, m;       cin >> n >> m;       long long tot = n * (n + 1) / 2, zr = n - m, gr = m + 1;       long long k = zr / gr, ans = 0;       if (zr % gr == 0) {         ans = tot - (k * (k + 1) / 2) * gr;       } else {         ans = tot - (zr % gr) * ((k + 1) * (k + 2) / 2) -               (gr - (zr % gr)) * (k * (k + 1) / 2);       }       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long fp(long long n, long long p) {     if (p == 0) return 1;     if (p == 1) return n;     long long res = fp(n, p / 2) % (long long)(1e9 + 7);     res = ((res) * (res)) % (long long)(1e9 + 7);     if (p % 2) res = (res * n) % (long long)(1e9 + 7);     return res;   }   int n, m, x[100005], a[100005], b[100005], cnt, suspects = 0;   int ans[100005];   char c[100005];   int main() {     ios::sync_with_stdio(0);     ios_base::sync_with_stdio(0);     cin.tie(0), cout.tie(0);     ;     cin >> n >> m;     for (int i = 0; i < n; i++) {       cin >> c[i] >> x[i];       if (c[i] ==  + ) {         a[x[i]]++;       } else {         b[x[i]]++;         cnt++;       }     }     for (int i = 1; i <= n; i++) {       if (a[i] - b[i] + cnt == m) ans[i] = 1, suspects++;     }     for (int i = 1; i <= n; i++) {       if (suspects > 1 && ans[x[i - 1]] == 1)         cout <<  Not defined  <<   n ;       else if (c[i - 1] ==  +  && ans[x[i - 1]] == 1)         cout <<  Truth  <<   n ;       else if (c[i - 1] ==  -  && ans[x[i - 1]] == 0)         cout <<  Truth  <<   n ;       else         cout <<  Lie  <<   n ;     }     return 0;   }


#include<bits/stdc++.h>   using namespace std;   #define int long long int   #define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)   #define pii pair<int,int>   #define F first   #define S second   #define pb push_back   const int mod1=998244353,mod2=(int) 1e9+7;   int power(int n,int k,int mod){int ans=1; n=n%mod;while(k>0){if(k&1)ans=(ans*n)%mod;n=(n*n)%mod;k>>=1;}return (ans+mod)%mod;}//negative nos & 0^0   struct triplet{int a,b,c;};bool operator < (const triplet &t1,const triplet &t2){if(t1.a<t2.a)return true;if(t1.a==t2.a && t1.b <t2.b)return true;if(t1.a==t2.a && t1.b ==t2.b && t1.c<t2.c)return true;return false;}   // memset(dp, -1, sizeof dp);         void problemSolver()   {       int h,w;    cin>>h>>w;    string s[h];    for(int i=0;i<h;i++)     cin>>s[i];    int i=0,j=0,c=0;    if(s[0][0]== * )      c++;         while(i<=h-1 && j<=w-1)    {        if(j+1<w && s[i][j+1]== * )      j++;     else if(i+1<h && s[i+1][j]== * )      i++;     else if(j+1<w)      j++;     else       i++;        if(s[i][j]== * )      c++;     if(i==h-1 && j==w-1)      break;       }    cout<<c;   }             int32_t main()   {      //  fio;    #ifndef ONLINE_JUDGE    freopen( input.txt ,  r , stdin);    freopen( output.txt ,  w , stdout);    #endif    int testcases=1;       // cin>>testcases;       while(testcases--)       problemSolver();       }


#include <bits/stdc++.h>   using namespace std;   struct qnode {     int id;     long long val;     bool operator<(qnode b) const { return val > b.val; }   };   queue<int> qu[200100];   int w[200100], vis[200100], add[200100];   int n, m, Q, opt, x, y, z;   long long dis[200100];   priority_queue<qnode> q;   vector<pair<int, int> > edge[200100];   void Dijkstra() {     memset(dis, 0x3f, sizeof(dis));     dis[1] = 0;     memset(vis, false, sizeof(vis));     q.push((qnode){1, 0});     while (!q.empty()) {       int x = q.top().id;       q.pop();       if (vis[x]) continue;       vis[x] = true;       for (auto i : edge[x]) {         int upup = i.first, z = w[i.second];         dis[upup] = min(dis[upup], dis[x] + z);         if (!vis[upup]) q.push((qnode){upup, dis[upup]});       }     }   }   int main() {     scanf( %d%d%d , &n, &m, &Q);     for (int i = 1; i <= m; i++) {       scanf( %d%d%lld , &x, &y, &w[i]);       edge[x].push_back(make_pair(y, i));     }     Dijkstra();     while (Q--) {       scanf( %d , &opt);       if (opt == 1) {         scanf( %d , &x);         if (dis[x] == 0x3f3f3f3f3f3f3f3f)           puts( -1 );         else           printf( %lld n , dis[x]);       } else {         scanf( %d , &x);         for (int i = 1; i <= x; i++) {           scanf( %d , &y);           w[y]++;         }         for (int i = 1; i <= n; i++) add[i] = x + 1;         qu[add[1] = 0].push(1);         for (int i = 0; i <= x; i++)           for (; !qu[i].empty(); qu[i].pop()) {             int now = qu[i].front();             if (add[now] != i) continue;             for (auto j : edge[now]) {               int y = j.first, z = w[j.second];               long long d = dis[now] + z + add[now] - dis[y];               if (d < add[y]) qu[add[y] = d].push(y);             }           }         for (int i = 1; i <= n; i++)           if (add[i] != x + 1) dis[i] += add[i];       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 4040;   int dp[N][N];   int n, m;   int main() {     while (scanf( %d%d , &n, &m) != EOF) {       int i, j;       memset(dp, 63, sizeof(dp));       memset(dp[0], 0, sizeof(dp[0]));       int ret = 0;       for (i = 1; i <= n; i++) {         int x, y;         scanf( %d%d , &x, &y);         for (j = 0; j <= m; j++) {           int w = dp[i - 1][j];           dp[i][j] = min(dp[i][j], max(w, x - 1) + y);           dp[i][j + 1] = min(dp[i][j + 1], w);           ret = max(ret, x - 1 - w);         }       }       for (i = 0; i <= m; i++) ret = max(ret, 86400 - dp[n][i]);       printf( %d n , ret);     }   }


#include <bits/stdc++.h>   using namespace std;   const long long LINF = 0x3f3f3f3f3f3f3f3f;   const long long NLINF = 0xf7f7f7f7f7f7f7f7;   const int INF = 0x3f3f3f3f, NINF = 0xf7f7f7f7;   const int MOD1 = 1e9 + 7, MOD2 = 1e9 + 9;   const int N = 2e5 + 10;   int n, freq[30], mark[30];   vector<char> odd, ch;   char s[N], r[N];   int main() {     scanf( %s , &s), n = strlen(s);     for (int i = 0; i < n; i++) {       freq[s[i] -  a ]++;     }     for (int i = 0; i < n; i++) {       if (freq[s[i] -  a ] % 2 == 0) ch.push_back(s[i]);       if (freq[s[i] -  a ] % 2 && !mark[s[i] -  a ])         odd.push_back(s[i]), mark[s[i] -  a ] = 1;     }     sort(odd.begin(), odd.end());     for (int i = 0; i < odd.size(); i++) {       if (odd.size() % 2 && i == odd.size() / 2)         while (freq[odd[i] -  a ]--) ch.push_back(odd[i]);       else if (i >= odd.size() / 2) {         freq[odd[i] -  a ]--;         while (freq[odd[i] -  a ]--) ch.push_back(odd[i]);       } else {         freq[odd[i] -  a ]++;         while (freq[odd[i] -  a ]--) ch.push_back(odd[i]);       }     }     sort(ch.begin(), ch.end());     assert(ch.size() == n);     bool par = 1;     for (int i = 0, lo = 0, hi = n - 1; i < n; i++) {       if (i % 2 == par)         r[hi--] = ch[i];       else if (ch[i] == ch[i + 1])         r[lo++] = ch[i];       else         par = !par, r[n / 2] = ch[i];     }     printf( %s n , r);   }


#include <bits/stdc++.h>   #pragma GCC target( pclmul )   using ul = std::uint32_t;   using ull = std::uint64_t;   using li = std::int32_t;   using ll = std::int64_t;   using llf = long double;   using uss = std::uint8_t;   const ul tau = 15;   const ul fib[] = {       1,       1,       2,       3,        5,        8,        13,      21,       34,      55,      89,      144,      233,      377,      610,     987,       1597,    2584,    4181,    6765,     10946,    17711,    28657,   46368,       75025,   121393,  196418,  317811,   514229,   832040,   1346269, 2178309,       3524578, 5702887, 9227465, 14930352, 24157817, 39088169, 63245986};   const ul sz = fib[tau];   char f[tau + 1][sz + 1];   ul ord[sz + sz];   class sam_t {    public:     ul las;     class node {      public:       ul ch[2];       ul len = 0;       ul fa = 0;       ul cnt = 0;       node() { std::memset(ch, 0, sizeof(ch)); }     };     std::vector<node> st = std::vector<node>(sz + sz);     void add(ul c) {       ul p = las;       ul np = las = st.size();       st.push_back(node());       st[np].len = st[p].len + 1;       for (; p && !st[p].ch[c]; p = st[p].fa) {         st[p].ch[c] = np;       }       if (!p) {         st[np].fa = 1;       } else {         ul q = st[p].ch[c];         if (st[q].len == st[p].len + 1) {           st[np].fa = q;         } else {           ul nq = st.size();           st.push_back(node());           st[nq] = st[q];           st[nq].cnt = 0;           st[nq].len = st[p].len + 1;           st[q].fa = st[np].fa = nq;           for (; p && st[p].ch[c] == q; p = st[p].fa) {             st[p].ch[c] = nq;           }         }       }     }     void init() {       las = 1;       st.resize(0);       st.resize(2);     }   };   sam_t sams[tau + 1];   ul n, m;   ull k;   const ul maxn = 200;   ull lambda[maxn + 1][4];   const ul maxm = 200;   ul tim = 0;   char ans[maxm + 2];   ul currs[4];   ul nexts0[4];   ul nexts1[4];   ull getnum(ul st[4]) {     ull ret = 0;     for (ul i = 0; i != 4; ++i) {       ret += lambda[n][i] * sams[tau - i].st[st[i]].cnt;     }     return ret;   }   int main() {     f[0][1] =  0 ;     f[1][1] =  1 ;     std::scanf( %u%llu%u , &n, &k, &m);     for (ul x = 2; x <= std::min(n, tau); ++x) {       std::memcpy(f[x] + 1, f[x - 2] + 1, fib[x - 2]);       std::memcpy(f[x] + fib[x - 2] + 1, f[x - 1] + 1, fib[x - 1]);     }     if (n <= tau) {       sams[n].init();       for (ul i = 1; i <= fib[n]; ++i) {         sams[n].add(f[n][i] -  0 );         ++sams[n].st[sams[n].las].cnt;       }       for (ul i = 1; i != sams[n].st.size(); ++i) {         ord[i] = i;       }       std::sort(ord + 1, ord + sams[n].st.size(), [&](ul a, ul b) {         return sams[n].st[a].len < sams[n].st[b].len;       });       for (ul it = sams[n].st.size() - 1; it >= 2; --it) {         ul i = ord[it];         sams[n].st[sams[n].st[i].fa].cnt += sams[n].st[i].cnt;       }       ul curr = 1;       ull cc = sams[n].st[1].cnt;       while (tim < m) {         ul next0 = sams[n].st[curr].ch[0];         ul next1 = sams[n].st[curr].ch[1];         ull cn0 = sams[n].st[next0].cnt;         ull cn1 = sams[n].st[next1].cnt;         if (cc - cn0 - cn1 >= k) {           break;         } else {           k -= cc - cn0 - cn1;         }         if (cn0 >= k) {           ++tim;           ans[tim] =  0 ;           curr = next0;           cc = cn0;         } else {           ++tim;           ans[tim] =  1 ;           curr = next1;           k -= cn0;           cc = cn1;         }       }       std::printf(ans + 1);       std::putchar(  n );     } else {       for (ul x = tau - 3; x <= tau; ++x) {         sams[x].init();         for (ul i = 1; i <= fib[x]; ++i) {           sams[x].add(f[x][i] -  0 );           ++sams[x].st[sams[x].las].cnt;         }         for (ul i = 1; i != sams[x].st.size(); ++i) {           ord[i] = i;         }         std::sort(ord + 1, ord + sams[x].st.size(), [&](ul a, ul b) {           return sams[x].st[a].len < sams[x].st[b].len;         });         for (ul it = sams[x].st.size() - 1; it >= 2; --it) {           ul i = ord[it];           sams[x].st[sams[x].st[i].fa].cnt += sams[x].st[i].cnt;         }         lambda[x][tau - x] = 1;       }       for (ul x = tau + 1; x <= n; ++x) {         for (ul i = 0; i != 4; ++i) {           lambda[x][i] = lambda[x - 1][i] + lambda[x - 2][i] + lambda[x - 2][i] -                          lambda[x - 3][i] - lambda[x - 4][i];         }       }       for (ul i = 0; i != 4; ++i) {         currs[i] = 1;       }       ull cc = getnum(currs);       while (tim < m) {         for (ul i = 0; i != 4; ++i) {           nexts0[i] = sams[tau - i].st[currs[i]].ch[0];           nexts1[i] = sams[tau - i].st[currs[i]].ch[1];         }         ull cn0 = getnum(nexts0);         ull cn1 = getnum(nexts1);         if (cc - cn0 - cn1 >= k) {           break;         } else {           k -= cc - cn0 - cn1;         }         if (cn0 >= k) {           ++tim;           ans[tim] =  0 ;           std::memcpy(currs, nexts0, sizeof(currs));           cc = cn0;         } else {           ++tim;           ans[tim] =  1 ;           std::memcpy(currs, nexts1, sizeof(currs));           k -= cn0;           cc = cn1;         }       }       std::printf(ans + 1);       std::putchar(  n );     }     return 0;   }


#include <bits/stdc++.h>   const int N = 1e5 + 1;   const int INF = 1e9 + 9;   int n;   int d[N];   std::vector<int> a[N];   int dfs(int v) {     for (int u : a[v]) {       d[v] += dfs(u);     }     if (d[v] == 0) return d[v] = 1;     return d[v];   }   int main() {     scanf( %d , &n);     for (int i = 1; i < n; i++) {       int x;       scanf( %d , &x);       x--;       a[x].push_back(i);     }     dfs(0);     std::sort(d, d + n);     for (int i = 0; i < n; i++) printf( %d  , d[i]);   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long x, long long y) {     if (x > y) swap(x, y);     if (x <= 0) return y;     if (y % x == 0) return x;     return gcd(y % x, x);   }   int main() {     vector<long long> a;     long long b[400000];     bool c[400000];     for (long long i = 0; i < (long long)(400000); i++) {       b[i] = 0;       c[i] = false;     }     int n, k;     long long g;     long long x, y, z, xx, yy, zz;     long long s, ans;     bool v = true;     ans = 0;     scanf( %I64d %I64d %I64d , &z, &x, &y);     g = gcd(x, y);     a.push_back(0);     c[0] = true;     xx = 0;     while (true) {       if (xx >= y)         xx -= y;       else         xx += x;       if (c[xx])         break;       else         c[xx] = true;       a.push_back(xx);     }     xx = 0;     yy = 0;     zz = 0;     while (true) {       if (xx < a[yy]) {         b[xx] = yy;         zz = max(zz, yy);         xx++;       } else         yy++;       if (yy >= a.size()) break;     }     ans = 0;     if (z < (x + y - g)) {       for (long long i = 0; i < (long long)(z + 1); i++) ans += b[i];       printf( %I64d n , ans);       return 0;     }     for (long long i = 0; i < (long long)(x + y - g); i++) {       ans += b[i];     }     xx = (x + y) / g;     yy = z / g;     zz = (xx + yy) * (yy - xx + 1) / 2;     zz *= g;     ans += zz;     zz = (z % g) + 1;     zz *= ((z / g) + 1);     ans += zz;     printf( %I64d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e9;   struct outgoing {     long long wt = INF, to = -1;   };   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     vector<long long> stations;     vector<pair<long long, long long>> connections;     long long n, i, j, k, t, temp;     cin >> n;     vector<outgoing> edge(n + 1);     pair<long long, long long> vertices[n + 1];     long long cost[n + 1];     long long mult[n + 1];     for (i = 1; i <= n; i++) {       cin >> vertices[i].first >> vertices[i].second;     }     for (i = 1; i <= n; i++) {       cin >> cost[i];       edge[i].wt = cost[i];       edge[i].to = i;     }     for (i = 1; i <= n; i++) {       cin >> mult[i];     }     long long total = 0;     vector<bool> selected(n + 1, false);     for (i = 1; i <= n; i++) {       long long v = -1;       for (j = 1; j <= n; j++) {         if (!selected[j] && (v == -1 || edge[j].wt < edge[v].wt)) {           v = j;         }       }       selected[v] = true;       long long x_now = vertices[v].first;       long long y_now = vertices[v].second;       if (edge[v].to == v) {         stations.push_back(v);       } else {         connections.push_back({v, edge[v].to});       }       total += edge[v].wt;       for (j = 1; j <= n; j++) {         long long x_diff = fabs(vertices[j].first - vertices[v].first);         long long y_diff = fabs(vertices[j].second - vertices[v].second);         if ((mult[v] + mult[j]) * (x_diff + y_diff) < edge[j].wt) {           edge[j].wt = (mult[v] + mult[j]) * (x_diff + y_diff);           edge[j].to = v;         }       }     }     cout << total << endl;     cout << stations.size() << endl;     for (auto x : stations) {       cout << x <<    ;     }     cout <<   n ;     cout << connections.size() << endl;     for (auto x : connections) {       cout << x.first <<     << x.second << 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 / 2; i++) {       cin >> a[i];     }     sort(a, a + n / 2);     int bb = 0, cc = 0;     for (int i = 0; i < n / 2; i++) {       bb += abs(a[i] - (i * 2 + 1));       cc += abs(a[i] - (i * 2 + 2));     }     cout << min(bb, cc) << endl;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 1e6 + 10;   const long long mod = 1e9 + 7;   const long long INF = 1e18 + 10;   int main() {     long long n, m, i;     string s;     cin >> n;     while (n--) {       cin >> m >> s;       if (s.size() < 11)         cout <<  NO n ;       else {         for (i = 0; i < s.size(); ++i) {           if (s[i] ==  8 ) break;         }         if (i == s.size())           cout <<  NO n ;         else {           if (s.size() - i >= 11)             cout <<  YES n ;           else             cout <<  NO n ;         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5, mod = 1000000007, INF = 1e9 + 7;   const int block = 316;   int n, k, type[N], a[N], m, cnt[N * 3], l[N][5];   long long ans, res[N], p[N][5];   set<long long> s;   map<long long, int> conv;   struct query {     int l, r, id, num;     query(){};     query(int a, int b, int c) : l(a), r(b), id(a / block), num(c){};   } q[N];   bool cmp(query q1, query q2) {     if (q1.id != q2.id) return q1.id < q2.id;     return q1.r < q2.r;   }   void add(int v, int cond) {     ans += cnt[l[v][cond]];     cnt[l[v][1]]++;   }   void remove(int v, int cond) {     cnt[l[v][1]]--;     ans -= cnt[l[v][cond]];   }   int main() {     cin >> n >> k;     for (int i = 1; i <= n; i++) {       cin >> type[i];     }     for (int i = 1; i <= n; i++) {       cin >> a[i];     }     for (int i = 0; i <= n; i++) {       if (type[i] == 2) a[i] *= -1;       p[i][1] = p[i - 1][1] + a[i];       p[i][2] = p[i][1] - k;       p[i][3] = p[i][1] + k;       s.insert(p[i][1]);       s.insert(p[i][2]);       s.insert(p[i][3]);     }     int cnt = 0;     for (long long e : s) {       conv[e] = ++cnt;     }     for (int i = 0; i <= n; i++) {       l[i][1] = conv[p[i][1]];       l[i][2] = conv[p[i][2]];       l[i][3] = conv[p[i][3]];     }     cin >> m;     for (int i = 1; i <= m; i++) {       int l, r;       cin >> l >> r;       l--;       q[i] = query(l, r, i);     }     sort(q + 1, q + m + 1, &cmp);     int l = 0, r = -1;     for (int i = 1; i <= m; i++) {       int L = q[i].l, R = q[i].r;       while (r < R) add(++r, 2);       while (l < L) remove(l++, 3);       while (R < r) remove(r--, 2);       while (L < l) add(--l, 3);       res[q[i].num] = ans;     }     for (int i = 1; i <= m; i++) {       cout << res[i] << endl;     }     cout << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 3e5 + 5;   const int MAXQ = 3e5 + 5;   const int inf = 0x3f3f3f3f;   struct Query {     int id, l, r;     Query(void) {}     Query(int _id, int _l, int _r) : id(_id), l(_l), r(_r) {}   };   long long res[MAXQ];   struct Solver {     vector<int> a, b;     vector<Query> qs;     void solve(void) {       int n = (int)a.size();       a.push_back(-inf);       b.push_back(-inf);       vector<vector<Query> > f(n), g(n);       for (Query x : qs) x.r = min(x.r, n - 1), f[x.l].push_back(x);       vector<int> sta(1, n), val(1, -inf);       for (int i = n - 1; i >= 0; --i) {         int pos = lower_bound(val.begin(), val.end(), b[i]) - val.begin();         pos = sta[pos - 1];         for (Query x : f[i]) {           int id = x.id, l = x.l, r = x.r;           if (pos > r) {             res[id] = (long long)(r - l + 1) * b[i];             continue;           }           res[id] = (long long)(pos - l) * b[i];           x.l = pos;           g[pos].push_back(x);         }         while (val.back() >= a[i]) val.pop_back(), sta.pop_back();         sta.push_back(i);         val.push_back(a[i]);       }       sta = vector<int>(1, n);       val = vector<int>(1, -inf);       vector<long long> sum(1, 0);       for (int i = n - 1; i >= 0; --i) {         while (val.back() >= a[i]) {           val.pop_back();           sta.pop_back();           sum.pop_back();         }         sum.push_back((long long)a[i] * (sta.back() - i) + sum.back());         sta.push_back(i);         val.push_back(a[i]);         for (Query x : g[i]) {           int id = x.id, r = x.r;           int pos = lower_bound(sta.begin(), sta.end(), r, greater<int>()) -                     sta.begin();           res[id] += sum.back() - sum[pos];           res[id] += (long long)(x.r - sta[pos] + 1) * val[pos];         }       }     }   } slv[MAXN];   int a[MAXN], f[MAXN];   int main(void) {     int n, Q, d;     scanf( %d%d%d , &n, &Q, &d);     for (int i = 0; i < n; ++i) scanf( %d , &a[i]);     deque<int> q;     for (int i = 0; i < n; ++i) {       while (q.size() && q.front() <= i - d) q.pop_front();       while (q.size() && a[q.back()] >= a[i]) q.pop_back();       q.push_back(i);       f[i] = a[q.front()];     }     for (int i = 0; i < n; ++i) {       int t = i % d;       slv[t].a.push_back(f[i]);       slv[t].b.push_back(a[i]);     }     for (int i = 1; i <= Q; ++i) {       int l, r;       scanf( %d%d , &l, &r);       --l;       --r;       int t = l % d;       if (r % d < l % d) r -= d;       l /= d;       r /= d;       slv[t].qs.emplace_back(i, l, r);     }     for (int i = 0; i < d; ++i) slv[i].solve();     for (int i = 1; i <= Q; ++i) printf( %lld n , res[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long A[300010], B[300010];   int n, m;   struct node {     int negpos, negpos_pref, negpos_suf, neg, neg_pref, neg_suf, pos, pos_pref,         pos_suf, len;     node() {       negpos = negpos_pref = negpos_suf = neg = neg_pref = neg_suf = pos =           pos_pref = pos_suf = 0;     }   };   node ST[3000010];   void merge(node a, node b, node &x) {     x.negpos = x.negpos_pref = x.negpos_suf = -0x3f3f3f3f;     x.neg = x.neg_pref = x.neg_suf = -0x3f3f3f3f;     x.pos = x.pos_pref = x.pos_suf = -0x3f3f3f3f;     x.negpos = max(a.negpos, max(b.negpos, a.neg_suf + b.pos_pref));     x.negpos =         max(x.negpos, max(a.negpos_suf + b.pos_pref, a.neg_suf + b.negpos_pref));     x.negpos_pref = a.negpos_pref;     if (a.neg == a.len) x.negpos_pref = max(x.negpos_pref, a.neg + b.negpos_pref);     if (a.negpos == a.len)       x.negpos_pref = max(x.negpos_pref, a.negpos + b.pos_pref);     x.negpos_suf = b.negpos_suf;     if (b.pos == b.len) x.negpos_suf = max(x.negpos_suf, a.negpos_suf + b.pos);     if (b.negpos == b.len) x.negpos_suf = max(x.negpos_suf, a.neg_suf + b.negpos);     x.pos = a.pos + b.pos;     x.neg = a.neg + b.neg;     x.pos_pref = a.pos_pref;     if (a.pos_pref == a.len) x.pos_pref = a.len + b.pos_pref;     x.pos_suf = b.pos_suf;     if (b.pos_suf == b.len) x.pos_suf = a.pos_suf + b.len;     x.neg_pref = a.neg_pref;     if (a.neg_pref == a.len) x.neg_pref = a.len + b.neg_pref;     x.neg_suf = b.neg_suf;     if (b.neg_suf == b.len) x.neg_suf = a.neg_suf + b.len;   }   void init_node(node &x, long long v) {     x.negpos = x.negpos_pref = x.negpos_suf = 0;     x.pos = x.pos_pref = x.pos_suf = 0;     x.neg = x.neg_pref = x.neg_suf = 0;     if (v < 0) {       x.neg = x.neg_pref = x.neg_suf = 1;     } else if (v > 0) {       x.pos = x.pos_pref = x.pos_suf = 1;     }     if (v) {       x.negpos = x.negpos_pref = x.negpos_suf = 1;     }   }   void init(int N, int li, int ls) {     ST[N].len = (ls - li + 1);     if (li == ls) {       init_node(ST[N], B[li]);     } else {       int mid = (li + ls) / 2;       init(2 * N, li, mid);       init(2 * N + 1, mid + 1, ls);       merge(ST[2 * N], ST[2 * N + 1], ST[N]);     }   }   void upd(int N, int li, int ls, int p, long long v) {     if (p > ls || p < li) return;     if (li == p && ls == p) {       B[p] += v;       init_node(ST[N], B[p]);       return;     }     int mid = (li + ls) / 2;     upd(2 * N, li, mid, p, v);     upd(2 * N + 1, mid + 1, ls, p, v);     merge(ST[2 * N], ST[2 * N + 1], ST[N]);   }   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %lld , &A[i]);     scanf( %d , &m);     for (int i = 0; i < n - 1; i++) B[i] = A[i] - A[i + 1];     n--;     if (n == 0) {       while (m--) printf( 1 n );       return 0;     }     init(1, 0, n - 1);     for (int i = 0; i < m; i++) {       int l, r;       long long v;       scanf( %d %d %lld , &l, &r, &v);       l -= 2;       r--;       if (l >= 0 && l < n) upd(1, 0, n - 1, l, -v);       if (r >= 0 && r < n) upd(1, 0, n - 1, r, v);       printf( %d n , ST[1].negpos + 1);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[110], b[110], cnt, n;   map<int, int> mp;   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       int num;       scanf( %d , &num);       if (!mp[num]) {         mp[num]++;         b[cnt++] = num;       }     }     sort(b, b + cnt);     if (cnt == 1)       printf( 0 );     else if (cnt == 2) {       if (abs(b[1] - b[0]) % 2)         printf( %d , abs(b[1] - b[0]));       else         printf( %d , abs(b[1] - b[0]) / 2);     } else if (cnt == 3 && ((b[1] - b[0]) == (b[2] - b[1])))       printf( %d , b[1] - b[0]);     else       printf( -1 );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   set<string> normal;   set<string> grumpy;   void build_normal() {     normal.insert( great! );     normal.insert( don t think so );     normal.insert( don t touch me );     normal.insert( not bad );     normal.insert( cool );   }   void build_grumpy() {     grumpy.insert( no way );     grumpy.insert( don t even );     grumpy.insert( are you serious? );     grumpy.insert( go die in a hole );     grumpy.insert( worse );     grumpy.insert( terrible );   }   int main() {     build_normal();     build_grumpy();     for (int i = 0; i < 10; i++) {       cout << i << endl;       string s;       getline(cin, s);       if (normal.count(s)) {         cout <<  normal  << endl;         return 0;       } else if (grumpy.count(s)) {         cout <<  grumpy  << endl;         return 0;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const int maxn = 100010;   int dp[550][550], A[550], B[550], path[550][550], n, m;   bool print(int x) {     if (!x) return false;     if (print(path[n][x]))       printf(  %d , B[x]);     else       printf( %d , B[x]);     return true;   }   int main() {     int i, j, tp, ans, pos;     while (~scanf( %d , &n)) {       for (i = 1; i <= n; i++) scanf( %d , &A[i]);       scanf( %d , &m);       for (i = 1; i <= m; i++) scanf( %d , &B[i]);       memset(dp, 0, sizeof dp);       for (i = 1; i <= n; i++) {         tp = pos = 0;         for (j = 1; j <= m; j++) {           dp[i][j] = dp[i - 1][j];           path[i][j] = path[i - 1][j];           if (A[i] == B[j] && tp + 1 > dp[i][j])             dp[i][j] = tp + 1, path[i][j] = pos;           if (B[j] < A[i] && dp[i - 1][j] > tp) tp = dp[i - 1][j], pos = j;         }       }       ans = 1;       for (i = 1; i <= m; i++)         if (dp[n][i] > dp[n][ans]) ans = i;       printf( %d n , dp[n][ans]);       if (dp[n][ans]) print(ans);       printf(  n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000007LL;   void solve() {     long long n;     cin >> n;     vector<long long> a(n);     for (long long &i : a) cin >> i;     unordered_map<long long, bool> m;     for (int i = 0; i < n; i++) {       long long sum = a[i];       for (int j = i + 1; j < n; j++) {         sum += a[j];         if (sum > n) break;         m[sum] = true;       }     }     long long count = 0;     for (long long i : a) {       count += m[i];     }     cout << count <<   n ;   }   int main(int argc, char const *argv[]) {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int T;     cin >> T;     while (T--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, a, maxi = 0;     cin >> n;     std::stack<int> stk;     for (int i = 0; i < n; ++i) {       cin >> a;       a %= 2;       maxi = max(maxi, a);       if (!stk.empty()) {         if (stk.top() == a)           stk.pop();         else           stk.push(a);       } else         stk.push(a);     }     if (stk.size() < 2)       cout <<  YES ;     else       cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int a, b;     long long c, nr = 0;     for (a = 1; a <= n; ++a) {       for (b = a; b <= n; ++b) {         c = sqrt(a * a + b * b);         if (c * c == a * a + b * b && c >= b && c <= n) ++nr;       }     }     cout << nr;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void fastIO() {     ios_base::sync_with_stdio(false);     cout.setf(ios::fixed);     cout.precision(10);     cout.tie(nullptr);     cin.tie(nullptr);   }   template <class T>   T power(T N, T P) {     return (P == 0) ? 1 : N * power(N, P - 1);   }   template <class T>   T GCD(T A, T B) {     return (A % B == 0) ? B : GCD(B, A % B);   }   const int MOD = 1e9 + 7;   const int MX = 2e5 + 5;   const double delta = 1e-9;   const long long INF = 1e18;   const long double PI = acos((long double)-1);   void setIn(string s) { freopen(s.c_str(),  r , stdin); }   void setOut(string s) { freopen(s.c_str(),  w , stdout); }   bool sort_rev(int a, int b) { return a > b; }   bool sort_(pair<string, int> &p1, pair<string, int> &p2) {     if (p1.first == p2.first) return p1.second < p2.second;     return p1.first < p2.first;   }   bool func(pair<int, int> a, pair<int, int> b) { return a.first > b.first; }   int main() {     fastIO();     int t = 1;     cin >> t;     while (t--) {       int n;       cin >> n;       pair<int, int> ara[n + 1];       for (int i = 0; i < n; i++) {         cin >> ara[i].first;       }       for (int i = 0; i < n; i++) cin >> ara[i].second;       sort(ara, ara + n, func);       long long aa = 0, bb = 0;       for (int i = 0; i < n; i++) {         long long canB = bb + ara[i].second;         long long canA = max(aa, (long long)ara[i].first);         if (canA <= canB)           aa = canA;         else           bb = canB;       }       cout << max(aa, bb) <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1);   template <class T>   T sqr(T x) {     return x * x;   }   template <class T>   T alex(T x) {     return (x > 0) ? x : -x;   }   template <class T>   void read(T& x) {     x = 0;     T f = 1;     char ch = getchar();     while ((ch < 48 || ch > 57) && ch != 45) ch = getchar();     if (ch == 45) f = -1, ch = getchar();     while (ch >= 48 && ch <= 57) x = x * 10 + ch - 48, ch = getchar();     x *= f;   }   int n, q;   char s[200005];   int t[200005 << 1];   int st[200005], ed[200005], len;   int tmp[200005 << 1], sa[200005 << 1], rnk[200005 << 1], sum[200005 << 1];   bool cmp(int* tmp, int x, int y, int l) {     return tmp[x] == tmp[y] && tmp[x + l] == tmp[y + l];   }   void getsa(int n, int m) {     memset(sum, 0, sizeof(sum));     for (int i = (1); i <= (n); i++) sum[rnk[i] = t[i]]++;     for (int i = (1); i <= (m); i++) sum[i] += sum[i - 1];     for (int i = (n); i >= (1); i--) sa[sum[rnk[i]]--] = i;     for (int j = 1; j <= n; j <<= 1) {       int p = 0;       for (int i = (n); i >= (n - j + 1); i--) tmp[++p] = i;       for (int i = (1); i <= (n); i++)         if (sa[i] > j) tmp[++p] = sa[i] - j;       memset(sum, 0, sizeof(sum));       for (int i = (1); i <= (n); i++) sum[rnk[tmp[i]]]++;       for (int i = (1); i <= (max(n, m)); i++) sum[i] += sum[i - 1];       for (int i = (n); i >= (1); i--) sa[sum[rnk[tmp[i]]]--] = tmp[i];       for (int i = (1); i <= (n); i++) tmp[i] = rnk[i];       p = 1;       rnk[sa[1]] = 1;       for (int i = (2); i <= (n); i++)         rnk[sa[i]] = p += !cmp(tmp, sa[i - 1], sa[i], j);     }   }   int height[200005 << 1][20];   void getheight(int n) {     for (int i = (1); i <= (n); i++) {       int l = max(height[rnk[i - 1]][0] - 1, 0), j = sa[rnk[i] - 1];       while (i + l <= n && j + l <= n && t[i + l] == t[j + l]) l++;       height[rnk[i]][0] = l;     }     for (int j = (1); j < (20); j++)       for (int i = (1); i <= (n - (1 << j) + 1); i++)         height[i][j] = min(height[i][j - 1], height[i + (1 << (j - 1))][j - 1]);   }   int _log2[200005 << 1];   int LCP(int x, int y) {     if (x == y) return n - sa[x] + 1;     if (x > y) swap(x, y);     x++;     int j = _log2[y - x + 1];     return min(height[x][j], height[y - (1 << j) + 1][j]);   }   struct Node {     int idx, l, sign;     Node() {}     Node(int idx, int l, int sign) : idx(idx), l(l), sign(sign) {}   };   int sum_bit[200005 << 1];   int lowbit(int x) { return x & (-x); }   void insert(int v, int x) {     for (int i = x; i <= len; i += lowbit(i)) sum_bit[i]++;   }   int ask(int l, int r) {     int res = 0;     for (int i = l - 1; i; i -= lowbit(i)) res -= sum_bit[i];     for (int i = r; i; i -= lowbit(i)) res += sum_bit[i];     return res;   }   vector<Node> que[200005];   int ans[500005];   void insert(int idx) {     for (int i = (st[idx]); i <= (ed[idx]); i++) insert(1, rnk[i]);   }   int findl(int l, int r, int pos, int val) {     while (l <= r) {       int mid = (l + r) >> 1;       if (LCP(mid, pos) >= val)         r = mid - 1;       else         l = mid + 1;     }     return l;   }   int findr(int l, int r, int pos, int val) {     while (l <= r) {       int mid = (l + r) >> 1;       if (LCP(pos, mid) >= val)         l = mid + 1;       else         r = mid - 1;     }     return r;   }   int query(int idx) {     int len2 = ed[idx] - st[idx] + 1;     int l = findl(1, rnk[st[idx]] - 1, rnk[st[idx]], len2);     int r = findr(rnk[st[idx]] + 1, len, rnk[st[idx]], len2);     return ask(l, r);   }   int main() {     read(n);     read(q);     int m = 26;     len = 0;     for (int i = (1); i <= (n); i++) {       scanf( %s , s + 1);       int l = strlen(s + 1);       st[i] = len + 1;       for (int k = (1); k <= (l); k++) t[++len] = s[k] -  a  + 1;       ed[i] = len;       t[++len] = ++m;     }     getsa(len, m);     getheight(len);     for (int i = (0); i <= (len); i++) _log2[i] = log2(i);     for (int i = (1); i <= (q); i++) {       int l, r, k;       read(l);       read(r);       read(k);       que[l - 1].push_back(Node(i, k, -1));       que[r].push_back(Node(i, k, 1));     }     for (int i = (1); i <= (n); i++) {       insert(i);       for (int k = (0); k < (que[i].size()); k++)         if (que[i][k].sign == -1)           ans[que[i][k].idx] -= query(que[i][k].l);         else           ans[que[i][k].idx] += query(que[i][k].l);     }     for (int i = (1); i <= (q); i++) printf( %d n , ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string s, ss;   int main() {     ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);     cin >> s;     ss = s;     reverse(ss.begin(), ss.end());     cout << s + ss;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, i, j, k, l, a[1000009], b[1000009], p[1000009], ans, cn, t, x, y, z,       mx, mn, s;   char c[1000009], d[1000009], ch;   struct point {     int num, pos;   } pp[1000009];   bool cmp(point a1, point a2) {     if (a1.num == a2.num) {       return a1.pos < a2.pos;     } else {       return a1.num < a2.num;     }   }   int main() {     while (scanf( %d , &n) != EOF) {       ans = 0;       x = -1;       for (i = 0; i < n; i++) {         scanf( %d , &pp[i].num);         pp[i].pos = i;       }       sort(pp, pp + n, cmp);       for (i = 0; i < n; i++) {         if (i > x) {           x = pp[i].pos;           ans++;         } else {           x = max(x, pp[i].pos);         }       }       printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 5009;   bool f[maxn][maxn], vis[maxn];   int pre[maxn][maxn], a[maxn];   int n, k, v, sum, cnt;   inline int read() {     int x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x * f;   }   void update(int x, int y, int opt) {     f[x][y] = 1;     pre[x][y] = opt;   }   int calc(int x) { return x / k + bool(x % k); }   void work(int x, int y) {     if (x == 0) return;     if (pre[x][y]) {       vis[x] = 1;       cnt++;       sum += a[x];       work(x - 1, (y - a[x] % k + k) % k);     } else       work(x - 1, y);   }   int main() {     n = read();     k = read();     v = read();     for (int i = 1; i <= n; i++) a[i] = read(), sum += a[i];     if (sum < v) {       puts( NO );       return 0;     }     f[0][0] = 1;     for (int i = 0; i < n; i++)       for (int j = 0; j < k; j++)         if (f[i][j]) {           update(i + 1, j, 0);           update(i + 1, (j + a[i + 1]) % k, 1);         }     int tmp;     for (tmp = n; tmp; tmp--)       if (f[tmp][v % k]) break;     if (tmp == 0)       puts( NO );     else {       puts( YES );       work(tmp, v % k);       if (cnt == 0 || cnt == n) {         for (int i = 2; i <= n; i++) {           if (calc(a[i])) printf( %d %d 1 n , calc(a[i]), i);           a[1] += a[i];         }         if (cnt == 0 && v) printf( %d 1 2 n , v / k);         if (cnt && a[1] - v) printf( %d 1 2 n , (a[1] - v) / k);       } else {         int L = 1, R = 1;         for (; L <= n && !vis[L]; L++)           ;         for (; R <= n && vis[R]; R++)           ;         for (int i = 1; i <= n; i++)           if (vis[i] && i != L) {             if (calc(a[i])) printf( %d %d %d n , calc(a[i]), i, L);             a[L] += a[i];           }         for (int i = 1; i <= n; i++)           if (!vis[i] && i != R) {             if (calc(a[i])) printf( %d %d %d n , calc(a[i]), i, R);             a[R] += a[i];           }         if (a[L] > v)           printf( %d %d %d n , (a[L] - v) / k, L, R);         else if (a[L] < v)           printf( %d %d %d n , (v - a[L]) / k, R, L);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   const int INF = 1e8 + 5;   const long long mod = 1e9 + 7;   const double pi = 3.1415926536;   int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};   int dy[] = {0, 0, 1, -1, 1, -1, -1, 1};   int xa, ya, xb, yb, n;   vector<pair<int, int> > v;   vector<int> r;   int sqr(int a) { return a * a; }   int dist(int xa, int ya, int xb, int yb) { return sqr(xa - xb) + sqr(ya - yb); }   bool check(int x, int y) {     for (int i = 0; i < n; i++)       if (dist(v[i].first, v[i].second, x, y) <= sqr(r[i])) return true;     return false;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     ios_base::sync_with_stdio(0);     ;     cin >> xa >> ya >> xb >> yb >> n;     if (xa > xb) swap(xa, xb);     if (ya > yb) swap(ya, yb);     for (int i = 0; i < n; i++) {       int x, y, r1;       cin >> x >> y >> r1;       v.push_back({x, y});       r.push_back(r1);     }     int cnt = 0;     for (int x = xa; x <= xb; x++) {       if (!check(x, ya)) cnt++;       if (!check(x, yb)) cnt++;     }     for (int y = ya + 1; y <= yb - 1; y++) {       if (!check(xa, y)) cnt++;       if (!check(xb, y)) cnt++;     }     cout << cnt;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 100010;   int n;   int q;   long long a[201];   multiset<long long> s;   int main() {     cin >> q;     while (q--) {       int flag = 0;       s.clear();       cin >> n;       long long x;       for (int i = 1; i <= n; i++) {         cin >> x;         if (x == 2048) flag = 1;         s.insert(x);       }       if (flag) {         printf( YES n );         continue;       }       multiset<long long>::iterator it1;       multiset<long long>::iterator it2;       while (s.size() >= 2) {         it1 = s.begin();         it2 = s.begin();         it2++;         long long t1 = *it1;         long long t2 = *it2;         if (t1 == t2) {           if (t1 + t2 == 2048) {             flag = 1;             break;           }           s.erase(it1);           s.erase(it2);           s.insert(t1 + t2);         } else {           if (t1 == 2048 || t2 == 2048) {             flag = 1;             break;           }           s.erase(it1);         }       }       if (flag)         printf( YES n );       else         printf( NO n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int solve() {     int n, x;     cin >> n >> x;     vector<int> inp(n, 0);     for (int i = 0; i < n; i++) cin >> inp[i];     for (int i = 0; i < n; i++) {       if (inp[i] != x) break;       if (i == (n - 1)) return 0;     }     for (int i = 0; i < n; i++) {       if (inp[i] == x) return 1;     }     int dec = 0, inc = 0;     for (int i = 0; i < n; i++) {       if (inp[i] > x)         inc += (inp[i] - x);       else         dec += (x - inp[i]);     }     if (inc == dec)       return 1;     else       return 2;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     int t;     cin >> t;     for (int i = 1; i <= t; i++) cout << solve() <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int tc;     int n;     string str;     cin >> n >> tc;     cin >> str;     vector<char> vc(3);     vector<vector<int>> dp(6, vector<int>(n + 1, 0));     vc[0] =  a ;     vc[1] =  b ;     vc[2] =  c ;     int j, a = 0;     do {       for (int i = 0; i <= n - 1; i++) {         dp[a][i + 1] = dp[a][i];         j = i % 3;         if (str[i] != vc[j]) dp[a][i + 1]++;       }       a++;     } while (next_permutation(vc.begin(), vc.end()));     while (tc--) {       int l, r, ans;       cin >> l >> r;       ans = r - l + 1;       l--;       for (int i = 0; i < 6; i++) {         ans = min(ans, dp[i][r] - dp[i][l]);       }       cout << ans << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   struct debugger {     template <typename T>     debugger& operator,(const T& v) {       cerr << v <<    ;       return *this;     }   } dbg;   void debugarr(int* arr, int n) {     cout <<  [ ;     for (int i = 0; i < n; i++) cout << arr[i] <<    ;     cout <<  ]  << endl;   }   int main() {     int n;     cin >> n;     if (n % 4 == 2 || n % 4 == 3) {       cout << -1 << endl;       return 0;     }     int arr[100010] = {0};     int x = 2, y = n;     for (int i = 0; i < n / 2; i += 2) {       arr[i] = x;       arr[i + 1] = y;       arr[n - 1 - i] = n + 1 - x;       arr[n - 1 - i - 1] = n + 1 - y;       x += 2;       y -= 2;     }     if (n % 2) arr[(n) / 2] = (n + 1) / 2;     for (int i = 0; i <= (int)n - 1; i++) cout << arr[i] <<    ;     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = (int)1e5 + 1, maxs = 21;   int n, m, q, stot, etot, que[maxn], rnk[maxn];   long long bit[maxn], ans[maxn];   struct Point {     int x, y;     void read() { scanf( %d%d , &x, &y); }     bool operator<(Point const &t) const {       return x < t.x || (x == t.x && y < t.y);     }     Point operator-(Point const &t) const { return (Point){x - t.x, y - t.y}; }     Point operator+(Point const &t) const { return (Point){x + t.x, y + t.y}; }     Point operator*(int const &t) const { return (Point){x * t, y * t}; }     long long det(Point const &t) const {       return (long long)x * t.y - (long long)y * t.x;     }   } stk[maxs], vec;   pair<Point, int> a[maxn], b[maxn];   Point p[maxn << 1 | 1];   struct Event {     int typ, idx;     long long dis;     bool operator<(Event const &t) const {       return dis < t.dis || (dis == t.dis && typ < t.typ);     }   } eve[maxn << 2 | 1];   int main() {     scanf( %d%d%d , &m, &n, &q);     stk[stot++] = (Point){0, 0};     while (m--) {       vec.read();       for (int i = 0; i < stot; ++i) {         stk[stot + i] = stk[i] + vec;         stk[i] = stk[i] - vec;       }       sort(stk, stk + stot + stot);       int sz = 0;       for (int i = 0; i < stot + stot; ++i) {         for (;              sz > 1 && (stk[sz - 1] - stk[sz - 2]).det(stk[i] - stk[sz - 2]) <= 0;              --sz)           ;         stk[sz++] = stk[i];       }       stot = sz;     }     stot -= stot > 1 && !(stk[stot - 1] - stk[stot - 2]).x;     for (int i = 0; i < n; ++i) {       a[i].first.read();       scanf( %d , &a[i].second);       que[i] = a[i].first.x;     }     sort(que, que + n);     m = unique(que, que + n) - que;     for (int i = 0; i < n; ++i)       rnk[i] = lower_bound(que, que + m, a[i].first.x) - que + 1;     for (int i = 0; i < q; ++i) {       b[i].first.read();       scanf( %d , &b[i].second);     }     for (int i = 0; i + 1 < stot; ++i) {       vec = stk[i + 1] - stk[i];       etot = 0;       for (int j = 0; j < n; ++j)         eve[etot++] = (Event){0, j, vec.det(a[j].first)};       for (int j = 0; j < q; ++j) {         p[j << 1] = b[j].first + stk[i] * b[j].second;         eve[etot++] = (Event){-1, j << 1, vec.det(p[j << 1])};         p[j << 1 | 1] = b[j].first - stk[i + 1] * b[j].second;         eve[etot++] = (Event){1, j << 1 | 1, vec.det(p[j << 1 | 1])};       }       sort(eve, eve + etot);       memset(bit + 1, 0, m * sizeof(long long));       auto bit_upd = [&](int x, int v) {         for (; x <= m; x += x & -x) bit[x] += v;       };       auto bit_sum = [&](int x) {         long long ret = 0;         for (; x > 0; x -= x & -x) ret += bit[x];         return ret;       };       for (int j = 0; j < etot; ++j) {         int idx = eve[j].idx;         if (!eve[j].typ) {           bit_upd(rnk[idx], a[idx].second);         } else {           Point lft = p[idx], rht = lft + vec * b[idx >> 1].second;           lft.x += eve[j].typ < 0 && i > 0 || eve[j].typ > 0 && i + 2 < stot;           int L = lower_bound(que, que + m, lft.x) - que + 1;           int R = upper_bound(que, que + m, rht.x) - que;           long long las = ans[idx >> 1];           ans[idx >> 1] += eve[j].typ * (bit_sum(R) - bit_sum(L - 1));           las = ans[idx >> 1] - las;         }       }     }     for (int i = 0; i < q; ++i) printf( %lld n , ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, c;     scanf( %d%d%d , &a, &b, &c);     int n = a * c - b * c;     if (n % b > 0)       printf( %d n , n / b + 1);     else       printf( %d n , n / b);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, i;     cin >> n;     if (n == 1)       cout << n;     else {       cout << n <<    ;       for (i = 1; i < n - 1; i++) cout << i <<    ;       cout << n - 1;     }     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   int n;   long long int K;   int ans[100];   long long int fib[100];   int main() {     scanf( %d%I64d , &n, &K);     fib[0] = fib[1] = 1, fib[2] = 2;     for (int i = 3; i <= n; i++) fib[i] = fib[i - 1] + fib[i - 2];     for (int i = 1; i <= n; i++) ans[i] = i;     for (int i = 1; i <= n; i++)       if (K > fib[n - i]) {         K -= fib[n - i];         swap(ans[i], ans[i + 1]);         i++;       }     for (int i = 1; i <= n; i++) printf( %d  , ans[i]);     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   ostream &operator<<(ostream &os, const pair<T, T> &p) {     return os <<  (  << p.first <<  ,  << p.second <<  ) ;   }   template <class T>   ostream &operator<<(ostream &os, const pair<const T, T> &p) {     return os <<  (  << p.first <<  ,  << p.second <<  ) ;   }   template <class T>   ostream &operator<<(ostream &os, const array<T, 3> &p) {     return os <<  (  << p[0] <<  ,  << p[1] <<  ,  << p[2] <<  ) ;   }   template <class T>   ostream &operator<<(ostream &os, const vector<T> &p) {     for (auto x : p) os << x <<    ;     return os;   }   const double EPS = 1e-9;   const double PI = acos(-1);   const int INF = 0x3f3f3f3f;   const long long LINF = 0x3f3f3f3f3f3f3f3f;   const long long mod = 1e9 + 7;   const int SZ = 2e5 + 20;   int ciclo[SZ];   int custo[SZ];   int go[SZ];   int vis[SZ];   int dfs1(int v) {     if (ciclo[v]) return ciclo[v];     if (vis[v]) return ciclo[v] = v;     vis[v] = 1;     return ciclo[v] = dfs1(go[v]);   }   int aux;   int tempo;   void dfs(int v) {     if (vis[v] < tempo) {       aux = 0;       return;     }     if (vis[v] == tempo) return;     vis[v] = tempo;     aux = min(aux, custo[v]);     dfs(go[v]);   }   int main() {     int n;     scanf(  %d , &n);     for (int i = 1; i < n + 1; i++) {       scanf(  %d , &custo[i]);     }     for (int i = 1; i < n + 1; i++) {       scanf(  %d , &go[i]);     }     for (int i = 1; i < n + 1; i++) dfs1(i);     long long res = 0;     memset(vis, INF, sizeof(vis));     for (int i = 1; i < n + 1; i++) {       aux = INF;       tempo += 2;       dfs(ciclo[i]);       res += aux;     }     cout << res <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   double p[111], q[111];   int main() {     int n;     cin >> n;     for (int i = 0, u; i < n; i++) {       scanf( %d , &u);       p[i] = u / 100.0;       q[i] = 1;     }     double ans = 0;     while (1) {       int now = 0;       double tmp = 1;       for (int i = 0; i < n; i++) {         if (q[i] * p[i] * (1 - q[now]) > q[now] * p[now] * (1 - q[i])) now = i;         tmp *= 1 - q[i];       }       ans += 1 - tmp;       q[now] *= (1 - p[now]);       if (1 - tmp < 1e-10) break;     }     printf( %.6lf n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   map<int, int> a;   void reset() { a.clear(); }   void input() {     cin >> n;     int c;     for (int(i) = (0); (i) < (n); ++i) {       cin >> c;       a[c]++;     }   }   bool check(int s) {     for (auto it = a.begin(); it != a.end(); ++it) {       double b = (double)(it->second);       if ((int)ceil(b / s) != (int)floor(b / (s - 1))) {         return false;       }     }     return true;   }   void process() {     double d = (double)n;     int mn = n + 1;     for (auto it = a.begin(); it != a.end(); ++it) mn = min(mn, it->second);     int m = n + 1;     for (int(s) = (2); (s) < (mn + 2); ++s) {       bool ok = true;       int tmp = 0;       for (auto it = a.begin(); it != a.end(); ++it) {         int f = it->second;         int q = (int)ceil(1.0 * f / s);         if (f < q * (s - 1)) {           ok = false;           break;         }         tmp += q;       }       if (ok) m = min(m, tmp);     }     cout << m <<   n ;   }   void solve() {     reset();     input();     process();   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int T;     cin >> T;     while (T--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, a[100005];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n;     string s;     cin >> s;     if (n == 1 && s[0] ==  1 )       cout <<  Yes ;     else if (n == 1)       cout <<  No ;     else if (n == 2 && s[0] != s[1])       cout <<  Yes ;     else if (n == 2)       cout <<  No ;     else {       if (s[0] ==  0  && s[1] ==  0 )         cout <<  No ;       else if (s[n - 1] ==  0  && s[n - 2] ==  0 )         cout <<  No ;       else {         for (int i = 0; i < n - 2; ++i) {           if (s[i] ==  0  && s[i + 1] ==  0  && s[i + 2] ==  0 ) {             cout <<  No ;             return 0;           } else if (s[i] ==  1  && s[i + 1] ==  1 ) {             cout <<  No ;             return 0;           } else if (s[i + 1] ==  1  && s[i + 2] ==  1 ) {             cout <<  No ;             return 0;           }         }         cout <<  Yes ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> lefts[2000000], rights[2000000];   vector<pair<pair<int, int>, bool>> lws;   int maxleft[2000000];   int maxright[2000000];   int minright[2000000];   vector<int> ans;   bool fail = false;   int n;   int dfs(int v, int needed) {     int cur = v;     if (maxleft[v] > v) cur = dfs(cur + 1, maxleft[v]);     ans.push_back(v);     if (cur >= minright[v]) {       fail = true;       return n;     }     if (needed <= cur && maxright[v] <= cur) return cur;     return dfs(cur + 1, max(needed, maxright[v]));   }   int main() {     ios_base::sync_with_stdio(false);     int c;     cin >> n >> c;     for (int i = 1; i <= n; i++) {       maxleft[i] = maxright[i] = i;       minright[i] = 1e9;     }     for (int i = 0; i < c; i++) {       int a, b;       string s;       cin >> a >> b >> s;       lws.push_back(make_pair(make_pair(a, b), s !=  LEFT ));       if (s ==  LEFT ) {         lefts[a].push_back(b);         if (b <= a) fail = true;         maxleft[a] = max(maxleft[a], b);       }       if (s ==  RIGHT ) {         rights[a].push_back(b);         if (b <= a) fail = true;         maxright[a] = max(maxright[a], b);         minright[a] = min(minright[a], b);       }     }     for (int i = 1; i <= n; i++) {       if (minright[i] <= maxleft[i]) fail = true;     }     dfs(1, n);     if (fail)       cout <<  IMPOSSIBLE ;     else {       for (int i = 0; i < n; i++) {         cout << ans[i] <<    ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int rw, rh, bw, bh;   int main() {     cin >> rw >> rh >> bw >> bh;     int Cred = rh * 2 + rw + 2, Cblue = bh * 2 + bw + 2;     int n = Cblue + Cred;     if (bw > rw)       n += bw - rw;     else       n += rw - bw;     cout << n << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string s[11];   int a[11];   int n, k;   int ans = 0x7fffffff;   string t[11];   int num[11];   int main() {     cin >> n >> k;     for (int i = 0; i < n; i++) {       cin >> s[i];     }     for (int i = 0; i < k; i++) {       a[i] = i;     }     do {       for (int i = 0; i < n; i++) {         for (int j = 0; j < k; j++) {           t[i][j] = s[i][a[j]];         }       }       for (int i = 0; i < n; i++) {         int tt = 0;         for (int j = 0; j < k; j++) {           tt = tt * 10 + t[i][j] -  0 ;         }         num[i] = tt;       }       sort(num, num + n);       ans = min(ans, num[n - 1] - num[0]);     } while (next_permutation(a, a + k));     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   int main(void) {     char s[1000001] =   ;     int n, n2, x, y, i;     scanf( %d , &n);     n2 = (n / 7) * 7;     while (n2 >= 0) {       if ((n - n2) % 4 == 0)         break;       else         n2 = n2 - 7;     }     if (n2 < 0)       printf( -1 n );     else {       y = n2 / 7;       x = (n - n2) / 4;       for (i = 0; i < x; i++) printf( %c ,  4 );       for (i = 0; i < y; i++) printf( %c ,  7 );       printf(  n );     }     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   int a[200000], b[200000];   set<pair<int, int>> se;   set<pair<int, int>>::iterator t;   int main() {     int n, m, d;     cin >> n >> m >> d;     for (int i = 0; i < n; i++) {       cin >> a[i];       se.insert(make_pair(a[i], i));     }     int cnt = 0, pos;     while (!se.empty()) {       pos = se.begin()->second;       b[pos] = ++cnt;       se.erase(se.begin());       while (1) {         t = se.lower_bound({a[pos] + d + 1, 0});         if (t == se.end()) break;         pos = t->second;         b[pos] = cnt;         se.erase(t);       }     }     cout << cnt <<   n  << b[0] <<    ;     for (int i = 1; i < n; i++) cout << b[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   const long long INF = 0x3f3f3f3f3f3f3f3fLL;   const int inf = 0x3f3f3f3f;   const int mod = 998244353;   const double eps = 1e-6;   void err() { puts(  ); }   template <typename T, typename... Args>   void err(const T &arg, const Args &...args) {     std::cout << arg <<    ;     err(args...);   }   template <typename T>   void read(T &x) {     x = 0;     char ch = getchar();     long long f = 1;     while (!isdigit(ch)) {       if (ch ==  - ) f *= -1;       ch = getchar();     }     while (isdigit(ch)) {       x = x * 10 + ch - 48;       ch = getchar();     }     x *= f;   }   template <typename T, typename... Args>   void read(T &first, Args &...args) {     read(first);     read(args...);   }   using namespace std;   const int maxn = 710;   struct BigInteger {     static const int BASE = 100000000;     static const int WIDTH = 8;     bool sign;     size_t length;     std::vector<int> num;     BigInteger(long long x = 0) { *this = x; }     BigInteger(const std::string &x) { *this = x; }     BigInteger(const BigInteger &x) { *this = x; }     void cutLeadingZero() {       while (num.back() == 0 && num.size() != 1) {         num.pop_back();       }     }     void setLength() {       cutLeadingZero();       int tmp = num.back();       if (tmp == 0) {         length = 1;       } else {         length = (num.size() - 1) * WIDTH;         while (tmp > 0) {           ++length;           tmp /= 10;         }       }     }     BigInteger &operator=(long long x) {       num.clear();       if (x >= 0)         sign = true;       else {         sign = false;         x = -x;       }       do {         num.emplace_back(x % BASE);         x /= BASE;       } while (x > 0);       setLength();       return *this;     }     BigInteger &operator=(const std::string &str) {       num.clear();       sign = (str[0] !=  - );       int x, len = (str.size() - 1 - (!sign)) / WIDTH + 1;       for (int i = 0; i < len; i++) {         int End = str.length() - i * WIDTH;         int start = std::max((int)(!sign), End - WIDTH);         sscanf(str.substr(start, End - start).c_str(),  %d , &x);         num.push_back(x);       }       setLength();       return *this;     }     BigInteger &operator=(const BigInteger &tmp) {       num = tmp.num;       sign = tmp.sign;       length = tmp.length;       return *this;     }     size_t size() const { return length; }     BigInteger e(size_t n) const {       int tmp = n % WIDTH;       BigInteger ans;       ans.length = n + 1;       n /= WIDTH;       while (ans.num.size() <= n) ans.num.push_back(0);       ans.num[n] = 1;       while (tmp--) ans.num[n] *= 10;       return ans * (*this);     }     BigInteger abs() const {       BigInteger ans(*this);       ans.sign = true;       return ans;     }     const BigInteger &operator+() const { return *this; }     BigInteger operator+(const BigInteger &b) const {       if (!b.sign) {         return *this - (-b);       }       if (!sign) {         return b - (-*this);       }       BigInteger ans;       ans.num.clear();       for (int i = 0, g = 0;; i++) {         if (g == 0 && i >= num.size() && i >= b.num.size()) break;         int x = g;         if (i < num.size()) x += num[i];         if (i < b.num.size()) x += b.num[i];         ans.num.push_back(x % BASE);         g = x / BASE;       }       ans.setLength();       return ans;     }     BigInteger operator-() const {       BigInteger ans(*this);       if (ans != 0) ans.sign = !ans.sign;       return ans;     }     BigInteger operator-(const BigInteger &b) const {       if (!b.sign) {         return *this + (-b);       }       if (!sign) {         return -((-*this) + b);       }       if (*this < b) {         return -(b - *this);       }       BigInteger ans;       ans.num.clear();       for (int i = 0, g = 0;; i++) {         if (g == 0 && i >= num.size() && i >= b.num.size()) break;         int x = g;         g = 0;         if (i < num.size()) x += num[i];         if (i < b.num.size()) x -= b.num[i];         if (x < 0) {           x += BASE;           g = -1;         }         ans.num.push_back(x);       }       ans.setLength();       return ans;     }     BigInteger operator*(const BigInteger &b) const {       int lena = num.size(), lenb = b.num.size();       std::vector<long long> ansLL;       for (int i = 0; i < lena + lenb; i++) ansLL.push_back(0);       for (int i = 0; i < lena; i++) {         for (int j = 0; j < lenb; j++) {           ansLL[i + j] += (long long)num[i] * (long long)b.num[j];         }       }       while (ansLL.back() == 0 && ansLL.size() != 1) ansLL.pop_back();       int len = ansLL.size();       long long g = 0, tmp;       BigInteger ans;       ans.sign = (ansLL.size() == 1 && ansLL[0] == 0) || (sign == b.sign);       ans.num.clear();       for (int i = 0; i < len; i++) {         tmp = ansLL[i];         ans.num.emplace_back((tmp + g) % BASE);         g = (tmp + g) / BASE;       }       if (g > 0) ans.num.emplace_back(g);       ans.setLength();       return ans;     }     BigInteger operator/(const long long &b) const {       BigInteger c;       c.num.clear();       for (int i = 0; i < num.size(); i++) {         c.num.push_back(0);       }       long long g = 0;       for (int i = num.size() - 1; i >= 0; i--) {         c.num[i] = int((num[i] + g * BASE) / b);         g = num[i] + g * BASE - c.num[i] * b;       }       for (int i = num.size() - 1; c.num[i] == 0; i--) {         c.num.pop_back();       }       return c;     }     BigInteger operator/(const BigInteger &b) const {       BigInteger aa((*this).abs());       BigInteger bb(b.abs());       if (aa < bb) return 0;       char *str = new char[aa.size() + 1];       memset(str, 0, sizeof(char) * (aa.size() + 1));       BigInteger tmp;       int lena = aa.length, lenb = bb.length;       for (int i = 0; i <= lena - lenb; i++) {         tmp = bb.e(lena - lenb - i);         while (aa >= tmp) {           ++str[i];           aa = aa - tmp;         }         str[i] +=  0 ;       }       BigInteger ans(str);       delete[] str;       ans.sign = (ans == 0 || sign == b.sign);       return ans;     }     BigInteger operator%(const long long &b) const {       long long ans = 0;       for (int i = num.size() - 1; i >= 0; i--) ans = (ans * BASE + num[i]) % b;       return ans;     }     BigInteger operator%(const BigInteger &b) const {       return *this - *this / b * b;     }     BigInteger &operator++() {       *this = *this + 1;       return *this;     }     BigInteger &operator--() {       *this = *this - 1;       return *this;     }     BigInteger &operator+=(const BigInteger &b) {       *this = *this + b;       return *this;     }     BigInteger &operator-=(const BigInteger &b) {       *this = *this - b;       return *this;     }     BigInteger &operator*=(const BigInteger &b) {       *this = *this * b;       return *this;     }     BigInteger &operator/=(const long long &b) {       *this = *this / b;       return *this;     }     BigInteger &operator/=(const BigInteger &b) {       *this = *this / b;       return *this;     }     BigInteger &operator%=(const long long &b) {       *this = *this % b;       return *this;     }     BigInteger &operator%=(const BigInteger &b) {       *this = *this % b;       return *this;     }     bool operator<(const BigInteger &b) const {       if (sign && !b.sign) {         return false;       } else if (!sign && b.sign) {         return true;       } else if (!sign && !b.sign) {         return -b < -*this;       }       if (num.size() != b.num.size()) return num.size() < b.num.size();       for (int i = num.size() - 1; i >= 0; i--)         if (num[i] != b.num[i]) return num[i] < b.num[i];       return false;     }     bool operator>(const BigInteger &b) const { return b < *this; }     bool operator<=(const BigInteger &b) const { return !(b < *this); }     bool operator>=(const BigInteger &b) const { return !(*this < b); }     bool operator!=(const BigInteger &b) const { return b < *this || *this < b; }     bool operator==(const BigInteger &b) const {       return !(b < *this) && !(*this < b);     }     bool operator||(const BigInteger &b) const { return *this != 0 || b != 0; }     bool operator&&(const BigInteger &b) const { return *this != 0 && b != 0; }     bool operator!() { return (bool)(*this == 0); }     friend std::ostream &operator<<(std::ostream &out, const BigInteger &x) {       if (!x.sign) out <<  - ;       out << x.num.back();       for (int i = x.num.size() - 2; i >= 0; i--) {         char buf[10];         sprintf(buf,  %08d , x.num[i]);         for (int j = 0; j < strlen(buf); j++) out << buf[j];       }       return out;     }     friend std::istream &operator>>(std::istream &in, BigInteger &x) {       std::string str;       in >> str;       size_t len = str.size();       int start = 0;       if (str[0] ==  - ) start = 1;       if (str[start] ==   0 ) return in;       for (int i = start; i < len; i++) {         if (str[i] <  0  || str[i] >  9 ) return in;       }       x.sign = !start;       x = str.c_str();       return in;     }     BigInteger pow(int n) {       BigInteger ans = 1, base = *this;       while (n) {         if (n & 1) ans = ans * base;         base = base * base;         n >>= 1;       }       return ans;     }   } dp[maxn][maxn], cur[maxn];   struct EDGE {     int next, to;   } edge[maxn << 1];   int head[maxn], tot;   inline void addedge(int u, int v) {     edge[tot] = {head[u], v};     head[u] = tot++;   }   int sz[maxn];   void dfs(int u, int pre) {     sz[u] = 1;     dp[u][1] = 1;     for (int i = head[u]; ~i; i = edge[i].next) {       int v = edge[i].to;       if (v == pre) continue;       dfs(v, u);       for (int j = 1; j <= sz[u]; ++j) cur[j] = dp[u][j];       for (int j = 1; j <= sz[u]; ++j) {         for (int k = 1; k <= sz[v]; ++k) {           dp[u][j + k] = max(dp[u][j + k], cur[j] / j * dp[v][k] / k * (j + k));           dp[u][j] = max(dp[u][j], cur[j] * dp[v][k]);         }       }       sz[u] += sz[v];     }   }   int main() {     memset(head, -1, sizeof head);     int n;     read(n);     for (int i = 1; i < n; ++i) {       int u, v;       read(u, v);       addedge(u, v);       addedge(v, u);     }     dfs(1, 0);     BigInteger ans = 0;     for (int i = 1; i <= sz[1]; ++i) ans = max(ans, dp[1][i]);     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   const long long maxN = 1e6 + 5;   const long long inf = 1e10;   const long long mod = 1e9 + 7;   long long n;   long long ans = 1;   long long res[maxN];   void normalSieve(long long n) {     for (long long i = 1; i <= n; i++) res[i] = 1;     for (long long i = 2; i * i <= n; i++) {       if (res[i] == 1) {         for (long long j = i * i; j <= n; j += i) {           res[j] = 2;           ans = 2;         }       }     }   }   int main() {     ios_base::sync_with_stdio(0);     cin >> n;     normalSieve(n + 1);     cout << ans << endl;     for (long long i = 2; i <= n + 1; i++) cout << res[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   ifstream fin( input.txt );   ofstream fout( output.txt );   bool isPrime(long long int x) {     if (x <= 4 || x % 2 == 0 || x % 3 == 0) return x == 2 || x == 3;     for (int i = 5; i * i <= x; i += 6)       if (x % i == 0 || x % (i + 2) == 0) return 0;     return 1;   }   void primeFactors(long long n, set<long long> &Fac) {     while (n % 2 == 0) {       Fac.insert(2);       n = n / 2;     }     for (int i = 3; i <= sqrt(n); i = i + 2) {       while (n % i == 0) {         Fac.insert(i);         n = n / i;       }     }     if (n > 2) Fac.insert(n);   }   int NumDigits(int x) {     return (         x < 10             ? 1             : (x < 100                    ? 2                    : (x < 1000                           ? 3                           : (x < 10000                                  ? 4                                  : (x < 100000                                         ? 5                                         : (x < 1000000                                                ? 6                                                : (x < 10000000                                                       ? 7                                                       : (x < 100000000                                                              ? 8                                                              : (x < 1000000000                                                                     ? 9                                                                     : 10)))))))));   }   inline void boostIO() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cout.precision(10);   }   long long int Pow10[19] = {       (long long int)0,    (long long int)1e1,  (long long int)1e2,       (long long int)1e3,  (long long int)1e4,  (long long int)1e5,       (long long int)1e6,  (long long int)1e7,  (long long int)1e8,       (long long int)1e9,  (long long int)1e10, (long long int)1e11,       (long long int)1e12, (long long int)1e13, (long long int)1e14,       (long long int)1e15, (long long int)1e16, (long long int)1e17,       (long long int)1e18};   long long int gcd(long long int a, long long int b) {     return b ? gcd(b, a % b) : a;   }   long long int lcm(long long int a, long long int b) {     return a * b / gcd(a, b);   }   long long MOD = 1e9 + 7;   template <class T>   struct Fenwick {     vector<T> V;     Fenwick(long long n) : V(n) {}     void add(size_t i, T x) {       for (; i < V.size(); i |= i + 1) V[i] += x;     }     T sum(long long i) {       T r = T();       for (--i; i >= 0; i = (i & (i + 1)) - 1) r += V[i];       return r;     }     T sum(long long l, long long r) { return sum(r) - sum(l); }   };   long long f_Minimum(long long a, long long b) { return (min(a, b)); }   long long f_Maximum(long long a, long long b) { return (max(a, b)); }   long long f_Summarize(long long a, long long b) { return (a + b); }   class Parameter {    public:     long long InitialValue;     long long (*Function)(long long a, long long b);     Parameter(long long (*f)(long long a, long long b), long long value) {       Function = f;       InitialValue = value;     }       private:   };   Parameter Minimum(f_Minimum, LONG_LONG_MAX);   Parameter Maximum(f_Maximum, LONG_LONG_MIN);   Parameter Summarize(f_Summarize, 0);   class SegmentTree {    public:     SegmentTree(long long size, Parameter p) {       Function = p.Function;       InitialValue = p.InitialValue;       n = size;       data = vector<long long>(2 * n, 0);     }     SegmentTree(vector<long long> array, Parameter p) {       Function = p.Function;       InitialValue = p.InitialValue;       n = array.size();       ;       data = vector<long long>(2 * n, 0);       for (long long i = 0; i < (n); ++i) {         data[n + i] = array[i];       }       for (long long i = n - 1; i >= 1; ++i) {         data[i] = Function(data[i * 2], data[i * 2] + 1);       }     }     void Update(long long idx, long long value) {       idx += n;       data[idx] = value;       while (idx > 1) {         idx /= 2;         data[idx] = Function(data[idx * 2], data[idx * 2 + 1]);       }     }     long long Find(long long left, long long right) {       left += n;       right += n;       long long value = InitialValue;       while (left < right) {         if (left % 2 == 1) {           value = Function(left, value);           left++;         }         if (right % 2 == 1) {           value = Function(right, value);           right--;         }         left /= 2;         right /= 2;       }       return value;     }       private:     long long n;     vector<long long> data;     long long (*Function)(long long a, long long b);     long long InitialValue;   };   int32_t main() {     boostIO();     string s;     cin >> s;     string t;     cin >> t;     map<char, long long> Map;     long long z = 0;     for (auto c : s) {       Map[c]++;       if (c ==  ? ) z++;     }     map<char, long long> Map2;     for (auto c : t) {       Map2[c]++;     }     long long low = 0;     long long high = 1e6 + 1;     while (high - low > 1) {       long long mid = (high + low) / 2;       long long req = 0;       for (long long c =  a ; c <=  z ; ++c) {         req += max(0LL, mid * Map2[c] - Map[c]);       }       if (req > z) {         high = mid;       } else {         low = mid;       }     }     vector<char> B;     for (char c =  a ; c <=  z ; ++c) {       for (long long i = 0; i < (Map2[c] * low - Map[c]); ++i) {         B.push_back(c);       }     }     long long idx = 0;     for (auto c : s) {       if (c !=  ? ) {         cout << c;       } else {         if (idx >= B.size()) {           cout <<  a ;         } else {           cout << B[idx];           idx++;         }       }     }     cerr <<   n  <<  RUNTIME:   << 1.0 * clock() / CLOCKS_PER_SEC <<   s  <<   n ;     return 0;     ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t, n, k, i, j, res[201], max = 0, diff;     cin >> t;     for (i = 0; i < t; i++) {       cin >> n >> k;       int x[k];       for (j = 0; j < k; j++) {         cin >> x[j];         if (j == 0) {           max = x[j];         }         if ((j > 0) && (j < k)) {           diff = (x[j] - x[j - 1]) / 2 + 1;         }         if (diff > max) {           max = diff;         }         if (j == (k - 1)) {           if ((n - x[j] + 1) > max) {             max = n - x[j] + 1;           }         }       }       res[i] = max;       diff = 0;     }     for (i = 0; i < t; i++) {       cout << res[i] <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 5e5 + 5;   int nxt[maxn];   int n, ans, m, l, r;   int rmq[maxn][30];   int main() {     ios::sync_with_stdio(false);     cin >> n >> m;     for (int i = 1; i <= n; i++) {       cin >> l >> r;       nxt[l] = max(nxt[l], r);     }     for (int i = 0; i < maxn; i++) {       nxt[i] = max(nxt[i], nxt[i - 1]);       nxt[i] = max(nxt[i], i);       rmq[i][0] = nxt[i];     }     for (int i = 1; i <= 25; i++)       for (int j = 0; j < maxn; j++) {         rmq[j][i] = max(rmq[j][i - 1], rmq[rmq[j][i - 1]][i - 1]);       }     for (int i = 1; i <= m; i++) {       cin >> l >> r;       ans = 0;       for (int j = 25; j >= 0; j--) {         if (rmq[l][j] < r) {           l = rmq[l][j];           ans = ans + (1 << j);         }       }       if (l < r) {         l = rmq[l][0];         ans++;       }       if (l >= r)         cout << ans <<   n ;       else         cout << -1 <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   struct vertex {     map<char, int> next, go;     int p, link;     char pch;     vector<int> leaf;     unordered_set<int> visited;     vertex(int p = -1, char pch = -1) : p(p), pch(pch), link(-1) {}   };   vector<vertex> t;   void aho_init() {     t.clear();     t.push_back(vertex());   }   int add_string(string s, int id) {     int v = 0;     for (char c : s) {       if (!t[v].next.count(c)) {         t[v].next[c] = t.size();         t.push_back(vertex(v, c));       }       v = t[v].next[c];     }     t[v].leaf.push_back(id);     return v;   }   void add_visited(int v, int id) { t[v].visited.insert(id); }   int go(int v, char c);   int get_link(int v) {     if (t[v].link < 0)       if (!v || !t[v].p)         t[v].link = 0;       else         t[v].link = go(get_link(t[v].p), t[v].pch);     return t[v].link;   }   int go(int v, char c) {     if (!t[v].go.count(c))       if (t[v].next.count(c))         t[v].go[c] = t[v].next[c];       else         t[v].go[c] = v == 0 ? 0 : go(get_link(v), c);     return t[v].go[c];   }   const int N = 3e5;   vector<int> g[N];   int last[N];   string s[N];   int n, q, B;   long long tot[400], sum[N];   struct Query {     int l, r, k, id;   };   int dfs(int x, int i, vector<long long>& partials) {     int cnt = 0;     if (t[x].visited.count(i)) ++cnt, t[x].visited.erase(i);     for (auto v : g[x]) cnt += dfs(v, i, partials);     for (auto v : t[x].leaf) partials[v] += cnt;     return cnt;   }   void solveLarge(vector<Query>& q, int i, vector<long long>& res) {     vector<long long> partials(n + 1, 0);     dfs(0, i, partials);     for (int i = 1; i < n + 1; i++) partials[i] += partials[i - 1];     for (auto query : q) {       res[query.id] = partials[query.r] - partials[query.l];     }   }   void add(int i, int val) {     while (i < N && i % B) {       sum[i++] += val;     }     i /= B;     while (i <= n / B) tot[i++] += val;   }   int get(int i) { return sum[i] + tot[i / B]; }   void dfs2(int x, vector<vector<Query>>& queries, vector<long long>& res) {     for (auto v : t[x].leaf) add(v, 1);     for (auto v : t[x].visited) {       for (auto q : queries[v]) {         res[q.id] += get(q.r) - get(q.l);       }     }     for (auto v : g[x]) dfs2(v, queries, res);     for (auto v : t[x].leaf) add(v, -1);   }   void solveSmall(vector<vector<Query>>& queries, vector<long long>& res) {     dfs2(0, queries, res);   }   int main() {     cin >> n >> q;     B = sqrt(n);     for (int i = 0; i < n; i++) cin >> s[i];     aho_init();     for (int i = 0; i < n; i++) {       add_string(s[i], i + 1);     }     for (int i = 0; i < n; i++) {       int cur = 0;       add_visited(cur, i);       for (char c : s[i]) {         cur = go(cur, c);         add_visited(cur, i);       }       last[i] = cur;     }     for (int i = 1; i < ((int)t.size()); i++) {       g[get_link(i)].push_back(i);     }     vector<Query> queries;     for (int i = 0; i < q; i++) {       int l, r, k;       cin >> l >> r >> k;       queries.push_back({l - 1, r, k - 1, i});     }     vector<vector<Query>> large(n);     vector<vector<Query>> small(n);     for (auto query : queries) {       if (((int)s[query.k].size()) >= B) {         large[query.k].push_back(query);       } else {         small[query.k].push_back(query);       }     }     vector<long long> res(q, 0);     for (int i = 0; i < n; i++) {       if (((int)large[i].size())) solveLarge(large[i], i, res);     }     solveSmall(small, res);     for (int i = 0; i < q; i++) cout << res[i] << endl;     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   bool chk[64] = {false};   int comb[64][8];   char s[128];   int dp[16][128];   char ans[8][32];   int main() {     for (int p = 0; p <= 6; p++)       for (int q = 0; p + q <= 6; q++) {         int r = 6 - p - q;         int v = q * 4 + r * 7;         chk[v] = true;         for (int i = 0; i < p; i++) comb[v][i] = 0;         for (int i = p; i < p + q; i++) comb[v][i] = 4;         for (int i = p + q; i < p + q + r; i++) comb[v][i] = 7;       }     int T;     scanf( %d , &T);     while (T--) {       s[0] =  0 ;       scanf( %s , s + 1);       int l = strlen(s);       memset(dp, -1, sizeof(dp));       dp[0][0] = -2;       for (int i = 1; i < l; i++)         for (int j = 0; j < 10; j++)           if (dp[j][i - 1] != -1) {             int v = 10 * j + (s[i] -  0 );             for (int k = 0; k < 64; k++)               if (chk[k] && v >= k && v - k < 10) dp[v - k][i] = k;           }       if (dp[0][l - 1] == -1)         printf( -1 n );       else {         int cv = 0;         for (int j = 0; j < 6; j++) {           ans[j][0] =  0 ;           ans[j][l] =   0 ;         }         for (int i = l - 1; i > 0; i--) {           int w = dp[cv][i];           for (int j = 0; j < 6; j++) ans[j][i] =  0  + comb[w][j];           cv += w;           cv /= 10;         }         for (int j = 0; j < 6; j++) {           long long pans;           sscanf(ans[j],  %lld , &pans);           printf(  %lld  + !j, pans);         }         printf(  n );       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long prime[500001];   bool vis[500001];   bool isPrime(long long x) {     for (long long i = 2; i <= sqrt(x); i++) {       if (x % i == 0) return false;     }     return true;   }   int main() {     long long n;     int cnt = 0;     memset(vis, false, sizeof(vis));     memset(prime, 0, sizeof(prime));     for (int i = 2; i <= 110000; i++) {       if (!vis[i]) prime[cnt++] = i;       for (int j = 0; j < cnt && i * prime[j] <= 110000; j++) {         vis[i * prime[j]] = true;         if (i % prime[j] == 0) break;       }     }     while (~scanf( %lld , &n)) {       if (isPrime(n)) {         printf( 1 n );       } else {         for (int i = 0; i < cnt; i++) {           if (n % prime[i] == 0) {             printf( %lld n , 1 + (n - prime[i]) / 2);             break;           }         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int gc() {     static const int BUF = 1e7;     static char buf[BUF], *bg = buf + BUF, *ed = bg;     if (bg == ed) fread(bg = buf, 1, BUF, stdin);     return *bg++;   }   inline int ri() {     int x = 0, f = 1, c = gc();     for (; c < 48 || c > 57; f = c ==  -  ? -1 : f, c = gc())       ;     for (; c > 47 && c < 58; x = x * 10 + c - 48, c = gc())       ;     return x * f;   }   const int inf = 0x3f3f3f3f;   const long long infLL = 0x3f3f3f3f3f3f3f3fLL;   const long long mod = 1e9 + 7;   const int maxN = 1e5 + 7;   int n;   int a[maxN];   int ans[maxN];   int BinarySearch(vector<int>& x, int k) {     if (x.size() == 0 || a[x[0]] >= k) return -1;     int l = 0, r = x.size() - 1;     int mid = (l + r) >> 1;     while (l < r) {       if (a[x[mid]] >= k) {         r = mid - 1;         mid = (l + r) >> 1;       } else {         l = mid + 1;         if (a[x[l]] >= k) return x[mid];         mid = (l + r) >> 1;       }     }     return x[r];   }   int main() {     while (cin >> n) {       for (int i = (1); i <= (n); ++i) cin >> a[i];       vector<int> vi;       for (int i = (1); i <= (n); ++i) {         if (vi.empty() || a[i] > a[vi.back()]) {           vi.push_back(i);         } else if (a[i] <= a[vi.back()]) {           vi.pop_back();           --i;         }       }       for (int i = (1); i <= (n); ++i) {         ans[i] = BinarySearch(vi, a[i]);         ans[i] -= i + 1;         if (ans[i] < 0) ans[i] = -1;         cout << ans[i] <<    ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   T in() {     char ch;     T n = 0;     bool ng = false;     while (1) {       ch = getchar();       if (ch ==  - ) {         ng = true;         ch = getchar();         break;       }       if (ch >=  0  && ch <=  9 ) break;     }     while (1) {       n = n * 10 + (ch -  0 );       ch = getchar();       if (ch <  0  || ch >  9 ) break;     }     return (ng ? -n : n);   }   template <typename T>   inline T POW(T B, T P) {     if (P == 0) return 1;     if (P & 1)       return B * POW(B, P - 1);     else       return (POW(B, P / 2) * POW(B, P / 2));   }   template <typename T>   inline T Gcd(T a, T b) {     if (a < 0) return Gcd(-a, b);     if (b < 0) return Gcd(a, -b);     return (b == 0) ? a : Gcd(b, a % b);   }   template <typename T>   inline T Lcm(T a, T b) {     if (a < 0) return Lcm(-a, b);     if (b < 0) return Lcm(a, -b);     return a * (b / Gcd(a, b));   }   long long Bigmod(long long base, long long power, long long MOD) {     long long ret = 1;     while (power) {       if (power & 1) ret = (ret * base) % MOD;       base = (base * base) % MOD;       power >>= 1;     }     return ret;   }   bool isVowel(char ch) {     ch = toupper(ch);     if (ch ==  A  || ch ==  U  || ch ==  I  || ch ==  O  || ch ==  E )       return true;     return false;   }   long long ModInverse(long long number, long long MOD) {     return Bigmod(number, MOD - 2, MOD);   }   bool isConst(char ch) {     if (isalpha(ch) && !isVowel(ch)) return true;     return false;   }   int toInt(string s) {     int sm;     stringstream second(s);     second >> sm;     return sm;   }   vector<int> A[500007];   int a[500007];   long long int Dp[500007];   vector<pair<long long int, int> > dp[500007];   void Dfs1(int u, int p, long long int vl) {     long long int mx1 = -1, mx2 = -1;     dp[u].push_back(make_pair(vl, p));     for (int i = 0; i < A[u].size(); i++) {       int v = A[u][i];       if (v == p) continue;       int Ln = dp[u].size() - 1;       int lft = max(0, Ln - 5);       long long int now = vl;       for (int j = Ln; j >= lft; j--) {         int tp = dp[u][j].second;         if (tp == v) continue;         now = max(now, dp[u][j].first);       }       Dfs1(v, u, now + a[u]);     }     sort(dp[u].begin(), dp[u].end());   }   long long int Dfs(int u, int p) {     long long int mx1 = -1, mx2 = -1;     for (int i = 0; i < A[u].size(); i++) {       int v = A[u][i];       if (v == p) continue;       long long int tp = Dfs(v, u);       dp[u].push_back(make_pair(tp, v));       if (tp > mx1) {         mx2 = mx1;         mx1 = tp;       } else if (tp > mx2) {         mx2 = tp;       }     }     Dp[u] = max(0LL, mx1) + max(0LL, mx2) + a[u];     sort(dp[u].begin(), dp[u].end());     return ((0LL > mx1) ? 0LL : mx1) + a[u];   }   void Wow(int u, int p) {     for (int i = 0; i < A[u].size(); i++) {       int v = A[u][i];       if (v == p) continue;       Wow(v, u);       Dp[u] = max(Dp[u], Dp[v]);     }   }   long long int Ans;   void Dekhi(int u, int p) {     for (int i = 0; i < A[u].size(); i++) {       int v = A[u][i];       if (v == p) continue;       Dekhi(v, u);     }     if (p) {       int Ln = dp[p].size() - 1;       int lft = max(0, Ln - 5);       long long int now = Dp[u] + a[p];       for (int i = Ln; i >= lft; i--) {         if (dp[p][i].second == u) continue;         for (int j = i - 1; j >= lft; j--) {           if (dp[p][j].second == u) continue;           long long int tp = dp[p][i].first + dp[p][j].first;           if (Ans < now + tp) {             Ans = now + tp;           }         }         long long int tp = dp[p][i].first;         if (Ans < now + tp) {           Ans = now + tp;         }       }       Ans = max(Ans, now);     }     return;   }   int main() {     int n;     n = in<int>();     for (int i = 1; i <= n; i++) a[i] = in<int>();     for (int i = 1; i < n; i++) {       int u, v;       u = in<int>(), v = in<int>();       A[u].push_back(v);       A[v].push_back(u);     }     vector<int> root;     for (int i = 1; i <= n; i++) {       if (A[i].size() == 1) {         root.push_back(i);       }     }     for (int i = 0; i < root.size(); i++) {       for (int j = 1; j <= n; j++) {         dp[j].clear();       }       long long int tp = Dfs(root[i], 0);       Dfs1(root[i], 0, 0);       Wow(root[i], 0);       Dekhi(root[i], 0);       if (i == 10) break;     }     printf( %lld n , Ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   signed main() {     int n, k, s;     cin >> n >> k >> s;     vector<int> a(n);     for (int i = 0; i < n; i++) {       cin >> a[i];     }     s = min(s, n * n);     vector<vector<int> > dp1(k + 1, vector<int>(s + 1, 1e9));     dp1[0][0] = 0;     int ans = 1e9;     for (int i = n - 1; i >= 0; i--) {       for (int c = k; c >= 0; c--) {         for (int j = s; j >= 0; j--) {           if (j + c <= s) {             dp1[c][j + c] = min(dp1[c][j + c], dp1[c][j]);           }           if (c + 1 <= k) {             dp1[c + 1][j] = min(dp1[c + 1][j], dp1[c][j] + a[i]);           }           if (c != 0) {             dp1[c][j] = 1e9;           }         }       }     }     for (int j = 0; j <= s; j++) {       ans = min(ans, dp1[k][j]);     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   ll solve(ll n) {     --n;     ll index = n / 3;     ll off = 1;     for (; index - off >= 0; off <<= 2) {       index -= off;     }     ll fi = index + off;     ll se = off << 1;     for (ll place = off >> 2; place >= 1; place >>= 2) {       ll t = (index / place) % 4;       if (t == 0) {         se += 0 * place;       } else if (t == 1) {         se += 2 * place;       } else if (t == 2) {         se += 3 * place;       } else if (t == 3) {         se += 1 * place;       }     }     ll th = fi ^ se;     if (n % 3 == 0)       return fi;     else if (n % 3 == 1)       return se;     else       return th;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t;     cin >> t;     while (t--) {       ll n;       cin >> n;       cout << solve(n) <<   n ;     }   }