#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   cin >> t; n   while (t--) { n     string s; n     cin >> s; n     long long tot = 0; n     long long cont = 0; n     for (int i = 0; i < s.size(); i++) { n       if (s[i] ==  -  && cont == 0) { n         tot += i + 1; n       } else if (s[i] ==  + ) { n         cont++; n       } else if (s[i] ==  - ) { n         cont--; n       } n     } n     tot += s.size(); n     cout << tot <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 100500; n int n, m; n char s[N]; n int dp[N]; n void solve() { n   scanf( %d%d%s , &n, &m, s); n   long long ans = (m - 1) * n; n   for (int i = 0; i < n; i++) { n     if (i - 1 >= 0 && s[i] != s[i - 1]) ans += (m - 1) * i; n     if (i + 1 < n && s[i] != s[i + 1]) ans += (m - 1) * (n - 1 - i); n   } n   for (int i = 0; i < n; i++) { n     dp[i] = 1; n     if (i - 1 >= 0 && s[i - 1] != s[i]) dp[i] = 2; n     if (i - 2 >= 0 && s[i - 1] != s[i] && s[i - 2] == s[i]) n       dp[i] = dp[i - 1] + 1; n     ans -= dp[i] - 1; n   } n   printf( %lld n , ans); n } n int main() { n   solve(); n   0; n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n using namespace std; n using ll = long long; n using ld = long double; n const int MOD = 1e9 + 7, inf = 1e9, N = 2e5 + 1; n const ll INF = 1e18; n ld tic, tac; n void solve() { n   string str, ans =   ; n   cin >> str; n   int cr = 0, cs = 0, cp = 0; n   for (int i = 0; i < (str.size()); ++i) { n     if (str[i] ==  R ) n       cr++; n     else if (str[i] ==  P ) n       cp++; n     else n       cs++; n   } n   char ch; n   if (cr >= cp && cr >= cs) n     ch =  P ; n   else if (cp >= cs && cp >= cr) n     ch =  S ; n   else n     ch =  R ; n   cout << string(str.size(), ch) <<   n ; n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int t = 1; n   cin >> t; n   while (t--) solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double PI = 3.1415926535; n double cot(double x) { return cos(x) / sin(x); } n int main() { n   double r, n; n   cin >> n >> r; n   cout << fixed << setprecision(9) n        << n * r * r * sin(PI / n) / (1 + 2 * cos(PI / n)); n   return 0; n } n


#include <bits/stdc++.h> n const double PI = 3.14159265358979323846; n using namespace std; n int main() { n   std::map<int, long long> pairs; n   std::set<long long> positive; n   int n; n   std::cin >> n; n   std::vector<int> nums(n); n   for (int i = 0; i < n; ++i) { n     std::cin >> nums[i]; n     if (nums[i] > 0) { n       positive.insert(nums[i]); n     } n     pairs[nums[i]]++; n   } n   long long result = 0; n   if (pairs[0]) { n     result += pairs[0] * (pairs[0] - 1) / 2; n   } n   for (std::set<long long>::iterator itr = positive.begin(); n        itr != positive.end(); ++itr) { n     result += pairs[*itr] * pairs[-(*itr)]; n   } n   std::cout << result << std::endl; n   return 0; n } n


#include <bits/stdc++.h> n #pragma warning(disable : 4244 4267 4018 4996 4800) n using namespace std; n istream& in = std::cin; n ostream& out = std::cout; n int n, m, total; n int xstart = -1, ystart; n vector<vector<char>> p; n int res = -1; n bool ones(int x1, int y1, int x2, int y2) { n   for (int i = x1; i <= x2; ++i) n     for (int j = y1; j <= y2; ++j) n       if (!p[i][j]) return false; n   return true; n } n int count(int w, int h) { n   int x = ::xstart, y = ::ystart; n   int res = 0; n   while (x < n && y < m && p[x][y]) { n     if (x + h < n && p[x + h][y] && (y + w == m || !p[x][y + w])) { n       if (ones(x, y, x, y + w - 1)) n         res += w; n       else n         return -1; n       ++x; n     } else if (y + w < m && p[x][y + w] && (x + h == n || !p[x + h][y])) { n       if (ones(x, y, x + h - 1, y)) n         res += h; n       else n         return -1; n       ++y; n     } else n       break; n   } n   if (x < n && y < m && p[x][y]) { n     if (ones(x, y, x + h - 1, y + w - 1)) n       res += w * h; n     else n       return -1; n   } n   return res; n } n void trysolve() { n   int w = 0, h = 0; n   int i; n   for (i = ystart; i < m && p[xstart][i]; ++i, ++w) n     ; n   int prev = -1; n   for (i = xstart; i < n && p[i][ystart]; ++i) { n     if (ystart + w < m && p[i][ystart + w] && prev == -1) { n       prev = i; n     } n   } n   h = prev == -1 ? 1 : i - prev; n   if (count(w, h) == total && (res == -1 || w * h < res)) res = w * h; n } n template <class T> n vector<T> transpose(vector<T> const& t) { n   vector<T> u(t[0].size(), T(t.size())); n   for (unsigned i = 0; i < t.size(); ++i) n     for (unsigned j = 0; j < t[i].size(); ++j) u[j][i] = t[i][j]; n   return u; n } n int main() { n   std::ios_base::sync_with_stdio(false); n   in >> n >> m; n   string s; n   p.resize(n, vector<char>(m)); n   for (auto& row : p) { n     in >> s; n     for (int i = 0; i < s.size(); ++i) row[i] = s[i] ==  X  ? 1 : 0; n   } n   for (int i = 0; i < n; ++i) { n     for (int j = 0; j < m; ++j) { n       if (p[i][j]) { n         ++total; n         if (xstart == -1) { n           xstart = i; n           ystart = j; n         } n       } n     } n   } n   trysolve(); n   p = transpose(p); n   swap(xstart, ystart); n   swap(n, m); n   trysolve(); n   out << res; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n #define int long long n #define pii pair<int, int> n int32_t mod = 1e9 + 7; n  n void solveCase() n { n     int n = 0, m = 0; n     cin >> n >> m; n  n     vector<vector<int>> mp(m, vector<int>(26, 0)); n     for (int i = 0; i < n; i++) n     { n         string s; n         cin >> s; n         for (int i = 0; i < m; i++) n             mp[i][s[i] -  a ]++; n     } n     for (int i = 0; i < n - 1; i++) n     { n         string s; n         cin >> s; n         for (int i = 0; i < m; i++) n             mp[i][s[i] -  a ]--; n     } n  n     for (int i = 0; i < m; i++) n         for (int x = 0; x < 26; x++) n             if (mp[i][x]) n                 cout << char( a  + x); n     cout <<   n ; n } n  n int32_t main() n { n     ios::sync_with_stdio(false), cin.tie(NULL); n     int t = 0; n     cin >> t; n     while (t--) n         solveCase(); n }


#include <bits/stdc++.h> n using namespace std; n int32_t main() { n   long long int n; n   std::cin >> n; n   long long int ans[n]; n   for (long long int i = 0; i < n; i++) { n     std::cin >> ans[i]; n   } n   long long int count[n]; n   memset(count, 0, sizeof(count)); n   for (long long int i = 0; i < n; i++) { n     count[i] += (ans[i] * 15); n     for (long long int j = 0; j < ans[i]; j++) { n       long long int x; n       std::cin >> x; n       count[i] += (x * 5); n     } n   } n   long long int min = (*(std::min_element(count, count + n))); n   std::cout << min <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e6 + 10; n int sz[N]; n struct Edge { n   long long from, to, val, nex; n } edge[N]; n int h[N], idx; n void add(long long u, long long v, long long w) { n   Edge E = {u, v, w, h[u]}; n   edge[idx] = E; n   h[u] = idx++; n } n void init() { n   memset(h, -1, sizeof(h)); n   idx = 0; n } n long long ans; n void dfs1(int u, int fa) { n   sz[u] = 1; n   for (int i = h[u]; ~i; i = edge[i].nex) { n     int v = edge[i].to; n     if (v == fa) continue; n     dfs1(v, u); n     sz[u] += sz[v]; n     if (sz[v] & 1) { n       ans += edge[i].val; n     } n   } n } n int n; n long long ans2; n void dfs2(int u, int fa) { n   sz[u] = 1; n   for (int i = h[u]; ~i; i = edge[i].nex) { n     int v = edge[i].to; n     if (v == fa) continue; n     dfs2(v, u); n     sz[u] += sz[v]; n     ans2 += min(sz[v], n - sz[v]) * edge[i].val; n   } n } n int main() { n   int t; n   cin >> t; n   while (t--) { n     cin >> n; n     n = n * 2; n     init(); n     ans = ans2 = 0; n     for (int i = 1; i < n; i++) { n       long long u, v, w; n       cin >> u >> v >> w; n       add(u, v, w); n       add(v, u, w); n     } n     dfs1(1, -1); n     printf( %lld  , ans); n     dfs2(1, -1); n     printf( %lld  , ans2); n     cout << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s; n   int l, i, j, k; n   cin >> s; n   for (i = 1; i < s.size() - 1; i++) { n     if (s[i] ==  A  && ((s[i + 1] ==  B  && s[i - 1] ==  C ) || n                         (s[i - 1] ==  B  && s[i + 1] ==  C ))) { n       printf( YES n ); n       return 0; n     } else if (s[i] ==  B  && ((s[i + 1] ==  A  && s[i - 1] ==  C ) || n                                (s[i - 1] ==  A  && s[i + 1] ==  C ))) { n       printf( YES n ); n       return 0; n     } else if (s[i] ==  C  && ((s[i + 1] ==  B  && s[i - 1] ==  A ) || n                                (s[i - 1] ==  B  && s[i + 1] ==  A ))) { n       printf( YES n ); n       return 0; n     } n   } n   printf( NO n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 10100; n int i, j, k, n, m, ch, c; n int s[N], t[N]; n long long ans, f[N]; n void R(int &x) { n   x = 0; n   ch = getchar(); n   while (ch <  0  ||  9  < ch) ch = getchar(); n   while ( 0  <= ch && ch <=  9 ) x = x * 10 + ch -  0 , ch = getchar(); n } n void W(long long x) { n   if (x >= 10) W(x / 10); n   putchar(x % 10 +  0 ); n } n long long min(long long x, long long y) { n   if (x < y) return x; n   return y; n } n int main() { n   R(n); n   R(c); n   for (i = 1; i <= n; i++) R(s[i]); n   for (i = 1; i <= n; i++) R(t[i]); n   memset(f, 60, sizeof f); n   f[0] = 0; n   for (i = 1; i <= n; i++) n     for (j = i - 1; j >= 0; j--) { n       f[j + 1] = min(f[j + 1], f[j] + t[i]); n       f[j] = (long long)c * j + f[j] + s[i]; n     } n   ans = 1000000000000000000ll; n   for (i = 0; i <= n; i++) ans = min(ans, f[i]); n   W(ans); n   puts(  ); n } n


#include <bits/stdc++.h> n using namespace std; n int color[100005]; n vector<int> DSK[100005]; n int num = 0, block_size; n int S[100005], E[100005], c[100005]; n struct query { n   int l, r, k, id; n } Q[100005]; n void DFS(int u, int pre) { n   S[u] = ++num; n   c[num] = color[u]; n   for (int i = 0; i < DSK[u].size(); i++) { n     int w = DSK[u][i]; n     if (w != pre) DFS(w, u); n   } n   E[u] = num; n } n int cnt[100005], ans[100005], res[100005]; n void add(int i) { n   cnt[c[i]]++; n   ans[cnt[c[i]]]++; n } n void del(int i) { n   ans[cnt[c[i]]]--; n   cnt[c[i]]--; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int n, m; n   cin >> n >> m; n   for (int i = 1; i <= n; i++) cin >> color[i]; n   for (int i = 1; i < n; i++) { n     int u, v; n     cin >> u >> v; n     DSK[u].push_back(v); n     DSK[v].push_back(u); n   } n   DFS(1, -1); n   for (int i = 1; i <= m; i++) { n     int v, k; n     cin >> v >> k; n     Q[i] = {S[v], E[v], k, i}; n   } n   block_size = sqrt(n); n   sort(Q + 1, Q + 1 + m, [](const query &a, const query &b) { n     if (a.l / block_size == b.l / block_size) return a.r < b.r; n     return a.l / block_size < b.l / block_size; n   }); n   int curL = 1, curR = 0; n   for (int i = 1; i <= m; i++) { n     int L = Q[i].l, R = Q[i].r; n     while (curL > L) { n       add(curL - 1); n       curL--; n     } n     while (curR < R) { n       add(curR + 1); n       curR++; n     } n     while (curL < L) { n       del(curL); n       curL++; n     } n     while (curR > R) { n       del(curR); n       curR--; n     } n     res[Q[i].id] = ans[Q[i].k]; n   } n   for (int i = 1; i <= m; i++) cout << res[i] <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int n, i, count, flag, j, x; n   cin >> n; n   long long int h[n], a[n], c[n], maxc, no2, task[n], temp, tasknumber[n][n], n       flaggy; n   flaggy = 0; n   for (i = 0; i < n; i++) { n     cin >> h[i]; n   } n   for (i = 0; i < n; i++) { n     c[i] = 0; n     task[i] = i + 1; n   } n   for (i = (n - 1); i >= 0; i--) { n     for (j = 0; j < i; j++) { n       if (h[j] > h[j + 1]) { n         temp = h[j + 1]; n         h[j + 1] = h[j]; n         h[j] = temp; n         temp = task[j + 1]; n         task[j + 1] = task[j]; n         task[j] = temp; n       } n     } n   } n   a[0] = h[0]; n   count = 1; n   c[0] = 1; n   maxc = 1; n   no2 = 0; n   tasknumber[0][0] = task[0]; n   for (i = 1; i < n; i++) { n     flag = 0; n     for (j = 0; j < count; j++) { n       if (h[i] == a[j]) { n         flag = 1; n         c[j] = c[j] + 1; n         tasknumber[j][(c[j] - 1)] = task[i]; n         if (c[j] > maxc) { n           maxc = c[j]; n         } n         if (c[j] == 2) { n           no2 = no2 + 1; n         } n         break; n       } n     } n     if (flag == 1) { n     } else { n       count++; n       a[count - 1] = h[i]; n       c[count - 1] = 1; n       tasknumber[count - 1][0] = task[i]; n     } n   } n   if (maxc >= 3) { n     cout <<  YES  << endl; n     for (x = 0; x < 3; x++) { n       for (i = 0; i < count; i++) { n         if (c[i] == 1) { n           cout << tasknumber[i][0] <<    ; n         } else if (c[i] == 2) { n           cout << tasknumber[i][0] <<     << tasknumber[i][1] <<    ; n         } else if (c[i] == 3) { n           if (x == 0) { n             cout << tasknumber[i][0] <<     << tasknumber[i][1] <<     n                  << tasknumber[i][2] <<    ; n           } n           if (x == 1) { n             cout << tasknumber[i][0] <<     << tasknumber[i][2] <<     n                  << tasknumber[i][1] <<    ; n           } n           if (x == 2) { n             cout << tasknumber[i][1] <<     << tasknumber[i][0] <<     n                  << tasknumber[i][2] <<    ; n           } n         } else if (c[i] >= 3) { n           if (x == 0) { n             cout << tasknumber[i][0] <<     << tasknumber[i][1] <<     n                  << tasknumber[i][2] <<    ; n             for (j = 3; j < c[i]; j++) { n               cout << tasknumber[i][j] <<    ; n             } n           } n           if (x == 1) { n             cout << tasknumber[i][0] <<     << tasknumber[i][2] <<     n                  << tasknumber[i][1] <<    ; n             for (j = 3; j < c[i]; j++) { n               cout << tasknumber[i][j] <<    ; n             } n           } n           if (x == 2) { n             cout << tasknumber[i][1] <<     << tasknumber[i][0] <<     n                  << tasknumber[i][2] <<    ; n             for (j = 3; j < c[i]; j++) { n               cout << tasknumber[i][j] <<    ; n             } n           } n         } n       } n       cout << endl; n     } n   } else if (maxc == 2) { n     if (no2 >= 2) { n       cout <<  YES  << endl; n       for (x = 0; x < 3; x++) { n         flaggy = 0; n         for (i = 0; i < count; i++) { n           if (c[i] == 1) { n             cout << tasknumber[i][0] <<    ; n           } else if (c[i] == 2) { n             flaggy = flaggy + 1; n             if (x == 0) { n               if (flaggy == 1) { n                 cout << tasknumber[i][0] <<     << tasknumber[i][1] <<    ; n               } n               if (flaggy == 2) { n                 cout << tasknumber[i][0] <<     << tasknumber[i][1] <<    ; n               } else if (flaggy >= 3) { n                 cout << tasknumber[i][0] <<     << tasknumber[i][1] <<    ; n               } n             } n             if (x == 1) { n               if (flaggy == 1) { n                 cout << tasknumber[i][1] <<     << tasknumber[i][0] <<    ; n               } n               if (flaggy == 2) { n                 cout << tasknumber[i][0] <<     << tasknumber[i][1] <<    ; n               } else if (flaggy >= 3) { n                 cout << tasknumber[i][0] <<     << tasknumber[i][1] <<    ; n               } n             } n             if (x == 2) { n               if (flaggy == 1) { n                 cout << tasknumber[i][0] <<     << tasknumber[i][1] <<    ; n               } n               if (flaggy == 2) { n                 cout << tasknumber[i][1] <<     << tasknumber[i][0] <<    ; n               } else if (flaggy >= 3) { n                 cout << tasknumber[i][0] <<     << tasknumber[i][1] <<    ; n               } n             } n           } n         } n         if (x == 2) { n           break; n         } n         cout << endl; n       } n     } else { n       cout <<  NO ; n     } n   } else { n     cout <<  NO ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 6; n const int M = 10010; n const int K = 510; n const int LIT = 2500; n const int INF = 1 << 30; n int n, m[N][N], tot, need; n vector<int> v, vis; n int row[N], col[N], dia1, dia2; n int cr[N], cc[N], cd1, cd2; n void init() { n   memset(m, 0, sizeof(m)); n   memset(row, 0, sizeof(row)); n   memset(col, 0, sizeof(col)); n   dia1 = dia2 = 0; n   memset(cr, 0, sizeof(cr)); n   memset(cc, 0, sizeof(cc)); n   cd1 = cd2 = 0; n   tot = n * n; n   need = 0; n   v = vector<int>(n * n); n   vis = vector<int>(n * n); n   for (int i = 0; i < tot; i++) cin >> v[i]; n   sort(v.begin(), v.end()); n   for (int i = 0; i < tot; i++) need += v[i]; n   need /= n; n } n void insert(int x, int y, int p, int ord) { n   m[x][y] = v[p]; n   vis[p] = (ord > 0) ? 1 : 0; n   int tmp = v[p] * ord; n   row[x] += tmp; n   cr[x] += ord; n   col[y] += tmp; n   cc[x] += ord; n   if (x == y) dia1 += tmp, cd1 += ord; n   if (x + y == n + 1) dia2 += tmp, cd2 += ord; n } n void out(int sum) { n   printf( %d n , sum); n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= n; j++) printf( %d  , m[i][j]); n     printf(  n ); n   } n } n bool check() { n   int sum = dia1; n   for (int i = 1; i <= n; i++) n     if (sum != row[i]) return 0; n   for (int i = 1; i <= n; i++) n     if (sum != col[i]) return 0; n   if (dia1 != dia2) return 0; n   out(sum); n   return 1; n } n bool dfs1(int x, int y) { n   if (x > n) return check(); n   int xx = x, yy = y + 1; n   if (yy > n) xx++, yy = 1; n   for (int i = 0; i < tot; i++) { n     if (vis[i]) continue; n     insert(x, y, i, 1); n     if (dfs1(xx, yy)) return 1; n     insert(x, y, i, -1); n   } n   return 0; n } n const int nxt[][2] = {{1, 1}, {1, 2}, {1, 3}, {2, 1}, {3, 1}, {1, 4}, n                       {4, 1}, {2, 2}, {3, 3}, {4, 4}, {2, 3}, {2, 4}, n                       {3, 2}, {3, 4}, {4, 2}, {4, 3}}; n const int bnd = 16; n pair<long long, long long> getmax2() { n   pair<long long, long long> ret = make_pair(-INF, -INF); n   for (int i = 0; i < tot; i++) { n     if (vis[i]) continue; n     if (ret.first < v[i]) { n       swap(ret.first, ret.second); n       ret.first = v[i]; n     } else if (ret.second < v[i]) n       ret.second = v[i]; n   } n   return ret; n } n bool validate() { n   pair<long long, long long> now = getmax2(); n   for (int i = 1; i <= n; i++) { n     if (cr[i] == 3) { n       bool f = 0; n       for (int j = 0; j < tot; j++) n         if (!vis[j] && row[i] + v[j] == need) f = 1; n       if (!f) return 0; n     } n     if (cc[i] == 3) { n       bool f = 0; n       for (int j = 0; j < tot; j++) n         if (!vis[j] && col[i] + v[j] == need) f = 1; n       if (!f) return 0; n     } n   } n   if (cd1 == 3) { n     bool f = 0; n     for (int i = 0; i < tot; i++) n       if (!vis[i] && dia1 + v[i] == need) f = 1; n     if (!f) return 0; n   } n   if (cd2 == 3) { n     bool f = 0; n     for (int i = 0; i < tot; i++) n       if (!vis[i] && dia2 + v[i] == need) f = 1; n     if (!f) return 0; n   } n   return 1; n } n bool dfs(int p) { n   if (p > bnd) return check(); n   int x = nxt[p][0], y = nxt[p][1]; n   for (int i = 0; i < tot; i++) { n     if (vis[i]) continue; n     insert(x, y, i, 1); n     if (validate() && dfs(p + 1)) return 1; n     insert(x, y, i, -1); n   } n   return 0; n } n void solve() { n   if (n <= 3) n     dfs1(1, 1); n   else n     dfs(0); n } n int main() { n   while (cin >> n) { n     init(); n     solve(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s; n   cin >> s; n   cout << s << (reverse(s.begin(), s.end()), s) << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void file_put() { n   freopen( filename.in ,  r , stdin); n   freopen( filename.out ,  w , stdout); n } n long long Pow(long long x, long long k, long long _p) { n   long long ans = 1; n   for (; k; k >>= 1, x = x * x % _p) n     if (k & 1) (ans *= x) %= _p; n   return ans; n } n const int N = 100005, _p = 998244353; n const int _M = N, _N = N; n template <class V> n struct FT { n   vector<V> aa, bb; n   V w[2][_M * 2 + 5], rev[_M * 2 + 5], tmp; n   void FFT(vector<V> &A, int m, int op) { n     int N = 1 << m; n     V w0 = Pow(3, (_p - 1) / N, _p); n     w[0][0] = w[1][0] = 1; n     for (int i = (1); i < (N); i++) n       w[0][i] = w[1][N - i] = (long long)w[0][i - 1] * w0 % _p; n     for (int i = (1); i < (N); i++) n       rev[i] = (rev[i >> 1] >> 1) | (i & 1) << m - 1; n     for (int i = (0); i < (N); i++) n       if (i < rev[i]) swap(A[i], A[rev[i]]); n     for (int i = 1; i < N; i <<= 1) n       for (int j = 0, t = N / (i << 1); j < N; j += i << 1) n         for (int k = j, l = 0; k < j + i; k++, l += t) { n           V x = A[k], y = (long long)w[op][l] * A[k + i] % _p; n           A[k] = (x + y) % _p, A[k + i] = (x - y + _p) % _p; n         } n     if (op) { n       tmp = Pow(N, _p - 2, _p); n       for (int i = (0); i < (N); i++) A[i] = 1ll * A[i] * tmp % _p; n     } n   } n   vector<V> multiply(vector<V> A, vector<V> B, vector<V> *C = NULL, n                      int op = 0) { n     int lena = A.size(), lenb = B.size(), len = 1, L = 0; n     aa = A, bb = B; n     while (len < lena + lenb - 1) len <<= 1, ++L; n     aa.resize(len), bb.resize(len); n     if (op) reverse((bb).begin(), (bb).end()); n     FFT(aa, L, 0), FFT(bb, L, 0); n     if (!C) C = &A; n     (*C).resize(len); n     for (int i = (0); i < (len); i++) (*C)[i] = (long long)aa[i] * bb[i] % _p; n     FFT(*C, L, 1); n     if (op) reverse((*C).begin(), (*C).end()); n     (*C).resize(lena + lenb - 1); n     return *C; n   } n }; n int n, k, x, y, siz[N]; n vector<int> V[N], P[N]; n long long ans = 0, s = 0, fac[N], inv[N], dp[N]; n FT<int> T; n vector<int> solve(int l, int r, const vector<int> &a) { n   if (l == r) return vector<int>{1, a[l]}; n   int mid = l + r >> 1; n   return T.multiply(solve(l, mid, a), solve(mid + 1, r, a)); n } n void dfs(int x, int p) { n   siz[x] = 1; n   for (auto y : V[x]) { n     if (y == p) continue; n     dfs(y, x), siz[x] += siz[y], P[x].push_back(siz[y]); n   } n   if (P[x].empty()) n     P[x].push_back(1); n   else n     P[x] = solve(0, (int)P[x].size() - 1, P[x]); n   for (int i = (0); i < (min(k, (int)P[x].size() - 1) + 1); i++) n     dp[x] += inv[k - i] % _p * P[x][i] % _p; n   dp[x] %= _p, (dp[x] *= fac[k]) %= _p; n } n void dfs(int x, int p, long long s1, long long s2) { n   ans += dp[x] * (s1 - s2) % _p, ans %= _p; n   P[x].push_back(0); n   unordered_map<int, int> M; n   for (int i = ((int)P[x].size()) - 1; i >= (1); i--) n     P[x][i] += (long long)P[x][i - 1] * (n - siz[x]) % _p, P[x][i] %= _p; n   for (auto y : V[x]) { n     if (y == p || M.find(siz[y]) != M.end()) continue; n     long long ret = 0; n     vector<int> tmp = P[x]; n     for (int i = (0); i < ((int)tmp.size() - 1); i++) n       tmp[i + 1] -= (long long)tmp[i] * siz[y] % _p, tmp[i + 1] %= _p; n     for (int i = (0); i < (min(k, (int)tmp.size() - 1) + 1); i++) n       ret += tmp[i] * fac[k] % _p * inv[k - i] % _p, ret %= _p; n     M[siz[y]] = ret; n   } n   for (auto y : V[x]) { n     if (y == p) continue; n     dfs(y, x, (s1 + M[siz[y]]) % _p, (s2 + dp[x]) % _p); n   } n } n int main() { n   std::ios::sync_with_stdio(false); n   std::cin.tie(0); n   scanf( %d%d , &n, &k); n   for (int i = (1); i < (n); i++) n     scanf( %d%d , &x, &y), V[x].push_back(y), V[y].push_back(x); n   fac[0] = inv[0] = inv[1] = 1; n   for (int i = (2); i < (N); i++) inv[i] = (_p - _p / i) * inv[_p % i] % _p; n   for (int i = (1); i < (N); i++) n     inv[i] = inv[i - 1] * inv[i] % _p, fac[i] = fac[i - 1] * i % _p; n   if (k == 1) { n     cout << (long long)n * (n - 1) / 2 % _p << endl; n     return 0; n   } n   dfs(1, 0), dfs(1, 0, 0, 0); n   for (int i = (1); i < (n + 1); i++) n     ans += dp[i] * s % _p, s += dp[i], ans %= _p, s %= _p; n   cout << (ans + _p) % _p << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool can(int x, int y, int a, int b) { n   cout <<  ?   << x <<     << y <<     << a <<     << b << endl; n   string ans; n   cin >> ans; n   if (ans ==  BAD ) exit(0); n   return ans ==  YES ; n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   int n; n   cin >> n; n   int x = 1, y = 1; n   string ord1(n - 1,    ), ord2(n - 1,    ); n   int i = 0; n   while (i < n - 1) { n     if (can(x + 1, y, n, n)) { n       ++x; n       ord1[i] =  D ; n     } else { n       ord1[i] =  R ; n       ++y; n     } n     ++i; n   } n   x = n; n   y = n; n   i = 0; n   while (i < n - 1) { n     if (can(1, 1, x, y - 1)) { n       ord2[i] =  R ; n       --y; n     } else { n       --x; n       ord2[i] =  D ; n     } n     ++i; n   } n   reverse(ord2.begin(), ord2.end()); n   cout <<  !   << ord1 << ord2 << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int Maxn = 507; n int n, m; n int E[Maxn][Maxn]; n vector<int> V[Maxn]; n int ans[Maxn]; n bool mark[Maxn]; n void dfs(int v) { n   mark[v] = true; n   for (int i = 0; i < V[v].size(); i++) { n     int u = V[v][i]; n     if (!mark[u]) n       ans[u] = 2 - ans[v], dfs(u); n     else if (ans[u] == ans[v]) { n       cout <<  No  << endl; n       exit(0); n     } n   } n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cin >> n >> m; n   for (int i = 0; i < m; i++) { n     int u, v; n     cin >> u >> v; n     E[u][v] = E[v][u] = 1; n   } n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= n; j++) n       if (!E[i][j] and i != j) V[i].push_back(j); n   for (int i = 1; i <= n; i++) { n     if (!V[i].size()) n       ans[i] = 1, mark[i] = true; n     else if (!mark[i]) n       ans[i] = 2, dfs(i); n   } n   for (int i = 1; i <= n; i++) n     for (int j = 1; j < i; j++) { n       if (E[i][j] and abs(ans[i] - ans[j]) == 2) return cout <<  No  << endl, 0; n     } n   cout <<  Yes  << endl; n   for (int i = 1; i <= n; i++) cout << (char)(ans[i] +  a ); n   cout << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   cin >> t; n   while (t--) { n     int n, m; n     string s; n     cin >> n >> m >> s; n     vector<int> pref(n); n     for (int i = 0; i < m; ++i) { n       int p; n       cin >> p; n       ++pref[p - 1]; n     } n     for (int i = n - 1; i > 0; --i) { n       pref[i - 1] += pref[i]; n     } n     vector<int> ans(26); n     for (int i = 0; i < n; ++i) { n       ans[s[i] -  a ] += pref[i]; n       ++ans[s[i] -  a ]; n     } n     for (int i = 0; i < 26; ++i) { n       cout << ans[i] <<    ; n     } n     cout << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX_N = 2e5 + 4; n int main() { n   vector<pair<long long, char> > ans; n   long long n, st[MAX_N], n       pr[MAX_N] = { n           0, n       }; n   long long sum = 0; n   scanf( %lld , &n); n   for (int i = 0; i < n; i++) { n     scanf( %lld , &st[i]); n     pr[i] = st[i]; n     sum += (1ll * st[i]); n   } n   long long k, last[MAX_N]; n   scanf( %lld , &k); n   for (int i = 0; i < k; i++) { n     scanf( %lld , &last[i]); n     sum = sum - last[i]; n   } n   if (sum != 0) { n     cout <<  NO ; n     return 0; n   } n   int left = n - 1, left_last = k - 1, prev; n   while (left >= 0 && left_last >= 0) { n     if (st[left] != last[left_last]) { n       if (last[left_last] < st[left]) { n         cout <<  NO ; n         return 0; n       } n       prev = left; n       while (left >= 0 && st[left] < last[left_last]) { n         left--; n         st[left] = st[left] + st[left + 1]; n       } n       if (left < 0 || st[left] != last[left_last]) { n         cout <<  NO ; n         return 0; n       } n       long long max_ = pr[left], find_ = left; n       for (int i = left + 1; i < prev; i++) n         if (max_ < pr[i]) { n           max_ = pr[i]; n           find_ = i; n         } else if (max_ == pr[i]) { n           if (i < prev) n             if (pr[i] > pr[i + 1]) { n               max_ = pr[i]; n               find_ = i; n             } n         } n       if (max_ < pr[prev]) { n         find_ = prev; n         max_ = pr[prev]; n       } n       if (find_ == prev) n         ; n       else if (find_ == left && pr[find_ + 1] == pr[find_]) { n         cout <<  NO ; n         return 0; n       } n       if (find_ != left && max_ == pr[find_ - 1]) { n         if (find_ < prev && pr[find_] > pr[find_ + 1]) n           ; n         else { n           cout <<  NO ; n           return 0; n         } n       } n       int kol1 = prev - find_; n       int kol2 = find_ - left; n       if (find_ != left && pr[find_ - 1] < pr[find_]) { n         ans.push_back(make_pair(find_ + 1,  L )); n         kol2--; n         find_--; n       } n       while (kol1 > 0) { n         ans.push_back(make_pair(find_ + 1,  R )); n         kol1--; n       } n       while (kol2 > 0) { n         ans.push_back(make_pair(find_ + 1,  L )); n         find_--; n         kol2--; n       } n     } n     left--; n     left_last--; n   } n   cout <<  YES  << endl; n   for (auto it : ans) { n     printf( %lld %c n , it.first, it.second); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long gcd(long long x, long long y) { return x ? gcd(y % x, x) : y; } n int N; n int a[2010], b[2010], c[2010]; n vector<pair<long long, long long> > v; n long long func(void) { n   int i, j; n   int ans = 0; n   i = 0; n   while (i < v.size()) { n     for (j = i; j < v.size(); j++) n       if (v[j] != v[i]) break; n     int d = j - i; n     ans += d * (d - 1) / 2; n     i = j; n   } n   return ans; n } n int main(void) { n   int i, j; n   cin >> N; n   for ((i) = 0; (i) < (int)(N); (i)++) scanf( %d%d%d , &a[i], &b[i], &c[i]); n   long long ans = 0; n   int zero = 0; n   for ((i) = 0; (i) < (int)(N); (i)++) n     if (c[i] == 0) zero++; n   if (zero == 2) ans += N - 2; n   for ((i) = 0; (i) < (int)(N); (i)++) n     if (c[i] != 0) { n       v.clear(); n       long long px = a[i] * a[i] + b[i] * b[i]; n       long long qx = a[i] * c[i]; n       long long py = a[i] * a[i] + b[i] * b[i]; n       long long qy = b[i] * c[i]; n       for ((j) = 0; (j) < (int)(i); (j)++) n         if (c[j] != 0) { n           long long px2 = a[j] * a[j] + b[j] * b[j]; n           long long qx2 = a[j] * c[j]; n           long long py2 = a[j] * a[j] + b[j] * b[j]; n           long long qy2 = b[j] * c[j]; n           long long rx = px * px2; n           long long sx = qx * px2 - px * qx2; n           long long ry = py * py2; n           long long sy = qy * py2 - py * qy2; n           long long g = n               gcd(((sx) > 0 ? (sx) : -(sx)), ((sy) > 0 ? (sy) : -(sy))); n           sx /= g; n           sy /= g; n           if (sx < 0 || (sx == 0 && sy < 0)) { n             sx = -sx; n             sy = -sy; n           } n           v.push_back(make_pair(sx, sy)); n         } n       sort(v.begin(), v.end()); n       long long tmp = func(); n       ans += tmp; n     } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int test, n, i, j, a, b; n   cin >> test; n   for (i = 0; i < test; i++) { n     cin >> n; n     for (a = 2; a < n; a++) { n       for (b = n - 1; b > a; b--) { n         if (n % a == n % b) { n           break; n         } n       } n       if (n % a == n % b) { n         cout << a <<     << b << endl; n         break; n       } n     } n   } n   return 0; n } n


#include <iostream> n #include <vector> n #include <cstring> n #include <algorithm> n #include <cassert> n #include <deque> n #include <map> n #include <queue> n #include <climits> n #include <set> n #include <stack> n #include <cmath> n #include <array> n #include <unordered_map> n #include <unordered_set> n  n using namespace std; n  n #define ll long long n #define MAX 100000 n #define MAX1 10000 n #define MAX2 100000 n #define inf 1000000000 n #define eps 1e-12 n #define MOD 1000000007 n  n int main() { n  n     ios_base::sync_with_stdio(0); n     cin.tie(0); n #ifndef ONLINE_JUDGE n     freopen( in.txt ,  r , stdin); n     freopen( out.txt ,  w , stdout); n #endif n  n     int t; n     cin >> t; n     while (t-- > 00) { n         int n; n         cin >> n; n         int a[n + 5], i; n         bool is = true; n         for (i = 1; i <= n; ++i) { n             cin >> a[i]; n             is &= a[i] == i; n         } n         if (is) { n             cout << 0 <<   n ; n             continue; n         } n         cout << (a[1] == 1 or a[n] == n ? 1 : (a[1] == n and a[n] == 1) ? 3 : 2) <<   n ; n     } n  n     return 0; n }


#include <bits/stdc++.h> n using namespace std; n const int N = 1000 + 5; n struct stu { n   int id, sc; n } a[N]; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   int n; n   cin >> n; n   int i, j; n   for (i = 1; i <= n; i++) { n     a[i].id = i; n     a[i].sc = 0; n     int x; n     for (j = 0; j < 4; j++) { n       cin >> x; n       a[i].sc += x; n     } n   } n   for (i = 1; i < n; i++) { n     for (j = i + 1; j <= n; j++) { n       if (a[i].sc < a[j].sc || (a[i].sc == a[j].sc && a[i].id > a[j].id)) { n         swap(a[i], a[j]); n       } n     } n     if (a[i].id == 1) break; n   } n   cout << i << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s; n   cin >> s; n   int n = s.size(); n   int l[n]; n   for (int i = 0; i < n; ++i) { n     l[i] = n; n   } n   for (int i = 0; i < n; ++i) { n     for (int j = 1; j <= min(n - i - 1, i); ++j) { n       if (s[i - j] == s[i] && s[i] == s[i + j]) { n         l[i - j] = min(l[i - j], i + j); n         break; n       } n     } n   } n   set<pair<int, int> > h; n   for (int i = 0; i < n; ++i) { n     h.insert({l[i], i}); n   } n   long long sum = 0; n   for (int i = 0; i < n; ++i) { n     sum += n - ((*h.begin()).first); n     h.erase({l[i], i}); n   } n   cout << sum; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long gcd(long long a, long long b) { return (b == 0 ? a : gcd(b, a % b)); } n long long lcm(long long a, long long b) { return (a * (b / gcd(a, b))); } n long long POWER(long long x, long long y, long long m) { n   if (y == 0) return 1; n   if (y % 2 == 0) { n     long long temp = POWER(x, y / 2, m); n     temp *= temp; n     temp %= m; n     return temp; n   } n   long long temp = POWER(x, y - 1, m); n   temp *= x; n   temp %= m; n   return temp; n } n long long POWER(long long x, long long y) { n   if (y == 0) return 1; n   if (y % 2 == 0) { n     long long temp = POWER(x, y / 2); n     temp *= temp; n     return temp; n   } n   long long temp = POWER(x, y - 1); n   temp *= x; n   return temp; n } n long long a[100010]; n int main() { n   ifstream fin( ali ); n   long long n, k; n   cin >> n >> k; n   for (int i = 1; i <= n; i++) cin >> a[i]; n   long long id = 0; n   for (long long i = 1; i <= n; i++) { n     if ((i * (i + 1)) / 2 >= k) { n       id = i; n       break; n     } n   } n   if ((id * (id + 1) / 2) == k) { n     cout << a[id] <<   n ; n     return 0; n   } n   id--; n   id = (id * (id + 1)) / 2; n   for (int i = 1; i <= n; i++) { n     id++; n     if (id == k) { n       cout << a[i] <<   n ; n       return 0; n     } n   } n   main(); n } n


#include <bits/stdc++.h> n using namespace std; n struct segment { n   int l, r; n }; n segment s[1010]; n int n, ans[1010], m, pi[1010], d[1010]; n bool operator<(const segment &a, const segment &b) { return a.r < b.r; } n int main() { n   int i, j; n   cin >> n; n   for (i = 1; i <= n; i++) { n     cin >> s[i].l >> s[i].r; n     if (s[i].l > s[i].r) swap(s[i].l, s[i].r); n   } n   sort(s + 1, s + n + 1); n   s[0].r = s[0].l = -2147483647; n   pi[0] = 0; n   for (i = 1; i <= n; i++) { n     j = i - 1; n     while (pi[j] == m) { n       if (s[j].r < s[i].l) { n         d[i] = -1; n         break; n       } n       j--; n     } n     if (d[i] == -1) n       d[i] = d[i - 1] + 1, ans[++m] = s[i].r, pi[i] = m; n     else n       pi[i] = m, d[i] = d[i - 1]; n   } n   printf( %d n , d[n]); n   for (i = 1; i <= m; i++) printf( %d  , ans[i]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 4e5 + 10; n const int INF = 1e9; n map<int, int> cnt; n vector<int> ind[N]; n vector<int> pos(N, 0); n int main() { n   int n, k; n   cin >> n >> k; n   vector<int> a(n); n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n     ind[a[i]].push_back(i); n   } n   for (int i = 0; i < n; i++) { n     ind[a[i]].push_back(INF); n   } n   set<pair<int, int> > s; n   set<int> inSet; n   int result = 0; n   for (int i = 0; i < n; i++) { n     int cur = a[i]; n     pos[cur]++; n     if (inSet.find(cur) != inSet.end()) { n       s.erase(make_pair(ind[cur][pos[cur] - 1], cur)); n       s.insert(make_pair(ind[cur][pos[cur]], cur)); n       continue; n     } n     if (inSet.size() == k) { n       inSet.erase((*s.rbegin()).second); n       s.erase(*s.rbegin()); n     } n     s.insert(make_pair(ind[cur][pos[cur]], cur)); n     inSet.insert(cur); n     result++; n   } n   cout << result; n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n long long a[100001]; n int main() { n   long long n, s = 0, i, k, j; n   string m; n   cin >> n; n   for (i = 1; i <= n; i++) { n     cin >> m; n     k = 0; n     for (j = 0; j < n; j++) n       if (m[j] ==  C ) k++, a[j + 1]++; n     s += ((k - 1) * k) / 2; n   } n   for (i = 1; i <= n; i++) s += ((a[i] - 1) * a[i]) / 2; n   cout << s; n   return 0; n } n


#include <bits/stdc++.h> n int dr[] = {2, 2, -2, -2, 1, -1, 1, -1}; n int dc[] = {1, -1, 1, -1, 2, 2, -2, -2}; n int dr1[] = {0, 0, 1, 1, 1, -1, -1, -1}; n int dc1[] = {1, -1, 1, 0, -1, 0, 1, -1}; n int dr2[] = {0, 0, 1, -1}; n int dc2[] = {1, -1, 0, 0}; n using namespace std; n long long sum(long long x) { return (x * (x + 1)) / 2; } n long long dp[500005], a[500005]; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   long long i, j, c, x, len, tc, n, k; n   cin >> tc; n   while (tc--) { n     cin >> n; n     vector<pair<long long, long long> > v; n     for (i = 1; i <= n; i++) { n       long long x; n       cin >> x; n       a[i] = x; n       v.push_back({x, i}); n     } n     sort(v.begin(), v.end()); n     long long ans = -1; n     if (v[0].first == v.back().first) n       cout <<  -1  << endl; n     else { n       for (i = 1; i <= n; i++) { n         if (a[i] == v.back().first) { n           if (i > 1 && a[i - 1] != v.back().first) ans = i; n           if (i < n && a[i + 1] != v.back().first) ans = i; n         } n       } n       cout << ans << endl; n     } n   } n   return 0; n } n


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


#include <bits/stdc++.h> n #pragma comment(linker,  /STACK:20000000 ) n using namespace std; n int ri() { n   int x; n   scanf( %d , &x); n   return x; n } n long long rll() { n   long long x; n   scanf( %lld , &x); n   return x; n } n void solve() { n   long long x; n   cin >> x; n   set<pair<long long, long long> > result; n   result.insert(make_pair(1, x)); n   result.insert(make_pair(x, 1)); n   long long tmp = 0; n   for (long long k = 2;; k++) { n     tmp += (k - 1) * (k - 1); n     long long ost = x - tmp; n     long long wtf = k * k * k - (k - 1) * k / 2 * k * 2; n     if (ost < wtf) { n       cerr << k << endl; n       break; n     } n     ost *= 2LL; n     if (ost % k == 0) { n       ost /= k; n       long long n = k; n       long long t = ost + (k - 1) * n; n       long long m = t / (2 * n - k + 1); n       if (m * (2 * n - k + 1) == t) { n         result.insert(make_pair(n, m)), result.insert(make_pair(m, n)); n       } n     } n   } n   cout << result.size() << endl; n   for (set<pair<long long, long long> >::iterator it = result.begin(); n        it != result.end(); it++) n     cout << it->first <<     << it->second << endl; n } n int main() { n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s, t; n   cin >> s >> t; n   for (long i = s.size() - 1; i >= 0; i--) { n     if (s[i] ==  z ) { n       s[i] =  a ; n     } else { n       s[i]++; n       break; n     } n   } n   if (s == t) { n     cout <<  No such string ; n   } else { n     cout << s; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n char a[1000005]; n int q; n struct node { n   int optimal; n   int open; n   int close; n   node(int op = 0, int cl = 0, int o = 0) { n     optimal = op; n     open = o; n     close = cl; n   } n }; n node t[4 * 1000005]; n node operator+(const node &left, const node &right) { n   node res; n   int t = min(left.open, right.close); n   res.optimal = left.optimal + right.optimal + t; n   res.close = left.close + right.close - t; n   res.open = left.open + right.open - t; n   return res; n } n void update(int k, int l, int r) { n   if (l == r) { n     if (a[l] ==  ( ) n       t[k] = node(0, 1, 0); n     else n       t[k] = node(0, 0, 1); n     return; n   } n   int m = (l + r) / 2; n   update(k * 2, l, m); n   update(k * 2 + 1, m + 1, r); n   t[k] = t[k * 2 + 1] + t[k * 2]; n } n node query(int k, int l, int r, int u, int v) { n   if (v < l || u > r) return node(0, 0, 0); n   if (u <= l && v >= r) { n     return t[k]; n   } n   int m = (l + r) / 2; n   return (query(k * 2 + 1, m + 1, r, u, v) + query(k * 2, l, m, u, v)); n } n int main() { n   scanf( %s , a + 1); n   n = strlen(a + 1); n   update(1, 1, n); n   scanf( %d , &q); n   for (int i = 1; i <= q; i++) { n     int u, v; n     scanf( %d%d , &u, &v); n     printf( %d n , query(1, 1, n, u, v).optimal * 2); n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long mod = 1e9 + 7; n int maxn = 1e9, minn = -1e9; n long long modpow(long long base, long long exp, int modulus) { n   base %= modulus; n   long long result = 1; n   while (exp > 0) { n     if (exp & 1) result = (result * base) % modulus; n     base = (base * base) % modulus; n     exp >>= 1; n   } n   return result; n } n int sqr(int x) { return x * x; } n bool is_prime(int x) { n   for (int i = 2; i * i <= x; ++i) { n     if (x % i == 0) return false; n   } n   return true; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   long long x = 1234567, y = 123456, z = 1234; n   int n; n   scanf( %d , &n); n   bool ans = false; n   for (long long i = 0; i <= n; i += x) { n     for (long long j = 0; j <= n; j += y) { n       long long c = n - i - j; n       if (c % z == 0 && c >= 0) ans = true; n     } n   } n   if (ans) n     cout <<  yes ; n   else n     cout <<  no ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn(1e5 + 5); n struct circle { n   int a, b; n   long long h; n   circle(){}; n   circle(int x) : a(0), b(x), h(0) {} n   inline void input() { cin >> a >> b >> h; } n   bool operator<(const circle &t) const { n     return b == t.b ? (a < t.a) : b < t.b; n   } n } rings[maxn]; n long long tree[maxn << 2]; n void build(int p, int l, int r) { n   if (l == r) { n     tree[p] = rings[l].h; n     return; n   } n   int mid = l + r >> 1; n   build(p << 1, l, mid); n   build(p << 1 | 1, mid + 1, r); n   tree[p] = max(tree[p << 1], tree[p << 1 | 1]); n } n void update(int p, int l, int r, int x) { n   if (l == r) { n     tree[p] = rings[x].h; n     return; n   } n   int mid = l + r >> 1; n   if (x <= mid) n     update(p << 1, l, mid, x); n   else n     update(p << 1 | 1, mid + 1, r, x); n   tree[p] = max(tree[p << 1], tree[p << 1 | 1]); n } n long long query(int p, int l, int r, int x, int y) { n   if (x <= l && r <= y) return tree[p]; n   int mid = l + r >> 1; n   if (y <= mid) n     return query(p << 1, l, mid, x, y); n   else if (x > mid) n     return query(p << 1 | 1, mid + 1, r, x, y); n   else { n     long long a = query(p << 1, l, mid, x, mid); n     long long b = query(p << 1 | 1, mid + 1, r, mid + 1, y); n     return max(a, b); n   } n } n int main() { n   int n; n   while (cin >> n) { n     for (int i = 1; i <= n; i++) rings[i].input(); n     sort(rings + 1, rings + n + 1); n     build(1, 1, n); n     for (int i = 2, j; i <= n; i++) { n       j = lower_bound(rings + 1, rings + i, circle(rings[i].a + 1)) - rings; n       if (j >= i) continue; n       rings[i].h += query(1, 1, n, j, i - 1); n       update(1, 1, n, i); n     } n     long long ans = 0; n     for (int i = 1; i <= n; i++) ans = max(ans, rings[i].h); n     cout << ans << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class S, class T> n ostream& operator<<(ostream& o, const pair<S, T>& p) { n   return o <<  (  << p.first <<  ,  << p.second <<  ) ; n } n template <class T> n ostream& operator<<(ostream& o, const vector<T>& vc) { n   o <<  { ; n   for (const T& v : vc) o << v <<  , ; n   o <<  } ; n   return o; n } n using ll = long long; n template <class T> n using V = vector<T>; n template <class T> n using VV = vector<vector<T>>; n constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); } n template <unsigned int mod_> n struct ModInt { n   using uint = unsigned int; n   using ll = long long; n   using ull = unsigned long long; n   constexpr static uint mod = mod_; n   uint v; n   ModInt() : v(0) {} n   ModInt(ll _v) : v(normS(_v % mod + mod)) {} n   explicit operator bool() const { return v != 0; } n   static uint normS(const uint& x) { return (x < mod) ? x : x - mod; } n   static ModInt make(const uint& x) { n     ModInt m; n     m.v = x; n     return m; n   } n   ModInt operator+(const ModInt& b) const { return make(normS(v + b.v)); } n   ModInt operator-(const ModInt& b) const { return make(normS(v + mod - b.v)); } n   ModInt operator-() const { return make(normS(mod - v)); } n   ModInt operator*(const ModInt& b) const { return make((ull)v * b.v % mod); } n   ModInt operator/(const ModInt& b) const { return *this * b.inv(); } n   ModInt& operator+=(const ModInt& b) { return *this = *this + b; } n   ModInt& operator-=(const ModInt& b) { return *this = *this - b; } n   ModInt& operator*=(const ModInt& b) { return *this = *this * b; } n   ModInt& operator/=(const ModInt& b) { return *this = *this / b; } n   ModInt& operator++(int) { return *this = *this + 1; } n   ModInt& operator--(int) { return *this = *this - 1; } n   ll extgcd(ll a, ll b, ll& x, ll& y) const { n     ll p[] = {a, 1, 0}, q[] = {b, 0, 1}; n     while (*q) { n       ll t = *p / *q; n       for (int i = 0; i < (int)(3); i++) swap(p[i] -= t * q[i], q[i]); n     } n     if (p[0] < 0) n       for (int i = 0; i < (int)(3); i++) p[i] = -p[i]; n     x = p[1], y = p[2]; n     return p[0]; n   } n   ModInt inv() const { n     ll x, y; n     extgcd(v, mod, x, y); n     return make(normS(x + mod)); n   } n   ModInt pow(ll p) const { n     if (p < 0) return inv().pow(-p); n     ModInt a = 1; n     ModInt x = *this; n     while (p) { n       if (p & 1) a *= x; n       x *= x; n       p >>= 1; n     } n     return a; n   } n   bool operator==(const ModInt& b) const { return v == b.v; } n   bool operator!=(const ModInt& b) const { return v != b.v; } n   friend istream& operator>>(istream& o, ModInt& x) { n     ll tmp; n     o >> tmp; n     x = ModInt(tmp); n     return o; n   } n   friend ostream& operator<<(ostream& o, const ModInt& x) { return o << x.v; } n }; n using mint = ModInt<1000000007>; n int main() { n   cin.tie(0); n   ios::sync_with_stdio(false); n   cout << fixed << setprecision(20); n   int N, Q; n   cin >> N >> Q; n   V<ll> A(N); n   for (int i = 0; i < (int)(N); i++) cin >> A[i]; n   V<mint> p2(N + 1); n   p2[0] = 1; n   for (int i = 1; i <= (int)(N); i++) p2[i] = p2[i - 1] * 2; n   struct link { n     int to; n     mint sum; n     ll sum2; n   }; n   V<link> ls(N); n   const ll inf = 1e9; n   for (int i = 0; i < (int)(N); i++) { n     link cur{i, A[i], A[i]}; n     while (cur.to > 0 && cur.sum2 > 0) { n       link x = ls[cur.to - 1]; n       link nxt; n       nxt.to = x.to; n       nxt.sum = cur.sum * p2[cur.to - x.to] + x.sum; n       nxt.sum2 = (cur.sum2 << min(cur.to - x.to, 30)) + x.sum2; n       nxt.sum2 = min(nxt.sum2, inf); n       cur = nxt; n     } n     ls[i] = cur; n   } n   const int H = 20; n   V<array<pair<int, mint>, H>> par(N + 1); n   for (int h = 0; h < (int)(H); h++) par[0][h] = {-1, 0}; n   for (int i = 0; i < (int)(N); i++) { n     par[i + 1][0] = {ls[i].to, ls[i].sum}; n     for (int h = 1; h <= (int)(H - 1); h++) { n       int j; n       mint js; n       tie(j, js) = par[i + 1][h - 1]; n       if (j == -1) { n         par[i + 1][h] = {-1, 0}; n       } else { n         int k; n         mint ks; n         tie(k, ks) = par[j][h - 1]; n         if (k == -1) n           par[i + 1][h] = {-1, 0}; n         else n           par[i + 1][h] = {k, js + ks}; n       } n     } n   } n   V<mint> sum(N + 1); n   for (int i = N - 1; i >= 0; i--) sum[i] = sum[i + 1] * 2 + A[i]; n   for (int _ = 0; _ < (int)(Q); _++) { n     int l, r; n     cin >> l >> r; n     l--; n     mint ans = 0; n     for (int h = H - 1; h >= 0; h--) { n       if (l + 1 <= par[r][h].first) { n         ans += par[r][h].second; n         r = par[r][h].first; n       } n     } n     ans *= 2; n     ans += sum[l] - sum[r] * p2[r - l]; n     cout << ans << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long find_seat(char c) { n   if (c ==  a ) return 4; n   if (c ==  b ) return 5; n   if (c ==  c ) return 6; n   if (c ==  d ) return 3; n   if (c ==  e ) return 2; n   if (c ==  f ) return 1; n } n int main() { n   long long one, two, a, b, d, n, i, res; n   char c; n   while (scanf( %lld%c , &n, &c) != EOF) { n     one = two = false; n     a = n % 4; n     if (a == 1 || a == 2) n       one = true; n     else n       two = true; n     if (n % 2 == 0) n       b = 1; n     else n       b = 0; n     res = 0; n     if (one) { n       res = n - 1; n       d = (n - a) / 4; n       d = d * 2 * 6; n       d += b * 6; n     } else { n       res = n - 3; n       d = (n - a) / 4; n       if (n % 2 == 0) d--; n       d = d * 2 * 6; n       d += b * 6; n     } n     res += d + find_seat(c); n     printf( %lld n , res); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxN = 1e5 + 5; n int lover[maxN], unlover[maxN]; n int speak[maxN]; n int N, M; n bool iscrime[maxN]; n int totnocommit, totcommit; n int main() { n   scanf( %d%d , &N, &M); n   for (int i = (1), _ = (N); i <= _; ++i) { n     scanf( %d , &speak[i]); n     if (speak[i] < 0) { n       totnocommit++; n       unlover[-speak[i]]++; n     } else { n       totcommit++; n       lover[speak[i]]++; n     } n   } n   int totcrime = 0; n   for (int i = (1), _ = (N); i <= _; ++i) { n     int toldtruth = lover[i] + totnocommit - unlover[i]; n     if (toldtruth == M) { n       ++totcrime; n       iscrime[i] = true; n     } n   } n   for (int i = (1), _ = (N); i <= _; ++i) n     if (speak[i] < 0) { n       int who = abs(speak[i]); n       if (iscrime[who] == true) n         if (totcrime == 1) n           puts( Lie ); n         else n           puts( Not defined ); n       else n         puts( Truth ); n     } else { n       int who = abs(speak[i]); n       if (iscrime[who] == true) n         if (totcrime == 1) n           puts( Truth ); n         else n           puts( Not defined ); n       else n         puts( Lie ); n     } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   long long int n; n   cin >> n; n   long long int h[n]; n   long long int d[n]; n   long long int sum = 0; n   for (long long int i = 0; i < n; i++) { n     cin >> h[i]; n     d[i] = h[i] - i; n     sum += d[i]; n   } n   long long int q = sum / n; n   long long int r = sum % n; n   for (int i = 0; i < n; i++) { n     long long int out = q + i; n     if (i < r) out++; n     cout << out <<    ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int ns[(1 << 6)]; n int s[(1 << 6)]; n char str[100005]; n int p[100005]; n void solve() { n   int n; n   scanf( %s  , str + 1); n   n = strlen(str + 1); n   for (int i = n; i; --i) { n     int al = str[i] -  a ; n     for (int bit = 0; bit < (1 << 6); ++bit) { n       if (bit & (1 << al)) { n         ns[bit]++; n       } n     } n     p[i] = (1 << 6) - 1; n   } n   int m; n   scanf( %d  , &m); n   for (int i = 1; i <= m; ++i) { n     int pos; n     scanf( %d  , &pos); n     scanf( %s  , &str); n     int len = strlen(str); n     p[pos] = 0; n     for (int j = 0; j < len; ++j) { n       p[pos] |= (1 << (str[j] -  a )); n     } n   } n   for (int i = n; i; --i) { n     for (int bit = 0; bit < (1 << 6); ++bit) { n       if ((bit & (p[i])) == p[i]) { n         ++s[bit]; n       } n     } n   } n   for (int bit = 0; bit < (1 << 6); ++bit) { n     if (s[bit] > ns[bit]) { n       printf( Impossible n ); n       return; n     } n   } n   for (int i = 1; i <= n; ++i) { n     int curAl = -1; n     for (int al = 0; al < 6 && curAl == -1; ++al) { n       if ((1 << al) & p[i]) { n         bool isGood = true; n         for (int bit = 0; bit < (1 << 6) && isGood; ++bit) { n           int tns = ns[bit], ts = s[bit]; n           if ((bit & (p[i])) == p[i]) { n             --ts; n           } n           if (bit & (1 << al)) { n             --tns; n           } n           if (ts > tns) { n             isGood = false; n           } n         } n         if (isGood) { n           curAl = al; n         } n       } n     } n     assert(curAl != -1); n     for (int bit = 0; bit < (1 << 6); ++bit) { n       if ((bit & (p[i])) == p[i]) { n         --s[bit]; n       } n     } n     for (int bit = 0; bit < (1 << 6); ++bit) { n       if (bit & (1 << curAl)) { n         --ns[bit]; n       } n     } n     putchar( a  + curAl); n   } n   putchar(  n ); n } n int main() { n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = 1e9 + 7; n inline void rvi(vector<int>& v, int n) { n   int temp; n   for (int i = 0; i < n; i++) { n     cin >> temp; n     v.push_back(temp); n   } n } n inline void rvll(vector<long long int>& v, int n) { n   long long int temp; n   for (int i = 0; i < n; i++) { n     cin >> temp; n     v.push_back(temp); n   } n } n inline void prvi(vector<int>& a) { n   for (int i = 0; i < a.size(); i++) { n     cout << a[i] <<    ; n   } n   cout << endl; n } n inline void prvll(vector<long long int>& a) { n   for (int i = 0; i < a.size(); i++) { n     cout << a[i] <<    ; n   } n   cout << endl; n } n inline void prmii(map<int, int>& m) { n   for (auto x : m) { n     cout << x.first <<     << x.second << endl; n   } n } n inline vector<long long int> prefixsum(vector<int>& a) { n   vector<long long int> b; n   b.push_back(a[0]); n   for (int i = 1; i < a.size(); i++) { n     b.push_back(a[i] + b[i - 1]); n   } n   return b; n } n inline vector<long long int> suffixsum(vector<int>& a) { n   vector<long long int> b((a.size())); n   b[(a.size()) - 1] = a[(a.size()) - 1]; n   for (int i = (a.size()) - 1 - 1; i >= 0; i--) { n     b[i] = a[i] + b[i + 1]; n   } n   return b; n } n inline vector<long long int> prefixsum(vector<long long int>& a) { n   vector<long long int> b; n   b.push_back(a[0]); n   for (int i = 1; i < a.size(); i++) { n     b.push_back(a[i] + b[i - 1]); n   } n   return b; n } n inline vector<long long int> suffixsum(vector<long long int>& a) { n   vector<long long int> b((a.size())); n   b[(a.size()) - 1] = a[(a.size()) - 1]; n   for (int i = (a.size()) - 1 - 1; i >= 0; i--) { n     b[i] = a[i] + b[i + 1]; n   } n   return b; n } n void solve(); n int main() { n   solve(); n   return 0; n } n void solve() { n   int t; n   cin >> t; n   while (t--) { n     int d; n     cin >> d; n     double a, b; n     if (d * d - 4 * d < 0) { n       cout <<  N n ; n     } else { n       a = (d + sqrt(d * d - 4 * d)) / 2; n       b = d - a; n       printf( Y %.10lf %.10lf n , a, b); n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int a[111111]; n map<int, int> cnt; n map<int, int> m; n int main() { n   int n; n   scanf( %d , &n); n   m.clear(); n   cnt.clear(); n   for (int i = 0; i < n; i++) scanf( %d , &a[i]); n   sort(a, a + n); n   int ma = INT_MIN; n   for (int i = 0; i < n; i++) { n     m[a[i]] += 1; n     ma = max(ma, a[i]); n   } n   vector<int> v; n   for (int i = 0; i < n; i++) n     if (cnt[a[i]] != 1) { n       v.push_back(a[i]); n       cnt[a[i]] = 1; n       m[a[i]] = m[a[i]] - 1; n     } n   cnt.clear(); n   for (int i = n - 1; i >= 0; i--) n     if (a[i] != ma && m[a[i]] > 0 && cnt[a[i]] != 1) { n       v.push_back(a[i]); n       cnt[a[i]] = 1; n     } n   printf( %d n , v.size()); n   for (int i = 0; i < v.size(); i++) printf( %d  , v[i]); n   printf(  n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void Read(int &n) { n   int sign = 1; n   n = 0; n   char c; n   do { n     c = getchar(); n   } while (!isdigit(c) && c !=  - ); n   if (c ==  - ) { n     c = getchar(); n     sign = -1; n   } n   do { n     n = n * 10 + c - 48; n     c = getchar(); n   } while (isdigit(c)); n   n *= sign; n } n void Read(long long &n) { n   int sign = 1; n   n = 0; n   char c; n   do { n     c = getchar(); n   } while (!isdigit(c) && c !=  - ); n   if (c ==  - ) { n     c = getchar(); n     sign = -1; n   } n   do { n     n = n * 10ll + c - 48; n     c = getchar(); n   } while (isdigit(c)); n   n *= sign; n } n void Write(int n) { n   if (n == 0) { n     putchar( 0 ); n     return; n   } else if (n < 0) n     putchar( - ), n = -n; n   char C[30]; n   int d = 0; n   while (n) { n     C[++d] = (n % 10) + 48; n     n /= 10; n   } n   for (int i = d; i >= 1; --i) putchar(C[i]); n } n void Write(long long n) { n   if (n == 0) { n     putchar( 0 ); n     return; n   } else if (n < 0) n     putchar( - ), n = -n; n   char C[30]; n   int d = 0; n   while (n) { n     C[++d] = (n % 10ll) + 48; n     n /= 10ll; n   } n   for (int i = d; i >= 1; --i) putchar(C[i]); n } n const int maxn = 1e4 + 5; n const long long INFL = 0x3f3f3f3f3f3f3f3f; n int n, c; n long long f[maxn], g[maxn]; n int p[maxn], s[maxn]; n int main() { n   scanf( %d%d , &n, &c); n   for (int i = 0; i < n; ++i) scanf( %d , &p[i]); n   for (int i = 0; i < n; ++i) scanf( %d , &s[i]); n   memset(f, INFL, sizeof f); n   f[0] = 0; n   for (int i = 0; i < n; ++i) { n     for (int j = 0; j <= i; ++j) g[j] = f[j], f[j] = INFL; n     for (int j = 0; j <= i; ++j) { n       f[j + 1] = min(g[j] + s[i], f[j + 1]); n       f[j] = min(f[j], g[j] + p[i] + (long long)j * c); n     } n   } n   long long ans = INFL; n   for (int i = 0; i <= n; ++i) ans = min(ans, f[i]); n   printf( %I64d , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long int n, t; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cin >> n; n   long long int f[26] = {0}, x = 0; n   while (n > 1) { n     int j = 0, sum = 0; n     while (sum + j + 2 <= n) j = j + 2, sum += j; n     f[x++] = (j - 2) / 2 + 2; n     f[x++] = (j - 2) / 2 + 2; n     n -= sum; n   } n   if (n == 1) { n     f[x++] = 2; n   } n   long long int flag = 0; n   for (int i = 0; i < x; i++) { n     char c = i + 97; n     while (f[i]) cout << c, f[i]--, flag = 1; n   } n   if (flag == 0) cout <<  x ; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n using lli = long long int; n using str = string; n const ll MOD = 1e9 + 7; n void solve() { n   ll a, b, c; n   cin >> a >> b >> c; n   cout << a + b + c - 1 <<   n ; n   return; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout << setprecision(15) << fixed; n   ll t = 1; n   cin >> t; n   while (t--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int64_t MAXN = 1000000007LL; n int n; n vector<int64_t> a(5), b(5), c(5), s(5); n int64_t maxscore(int64_t s, int64_t n) { n   if (s * 2 > n) return 500; n   if (s * 4 > n) return 1000; n   if (s * 8 > n) return 1500; n   if (s * 16 > n) return 2000; n   if (s * 32 > n) return 2500; n   return 3000; n } n bool win(int64_t mid) { n   int64_t sa = 0, sb = 0; n   for (int i = 0; i < 5; i++) { n     int64_t m = maxscore(s[i] + c[i] * mid, n + mid); n     if (a[i] >= 0) sa += m * (250 - a[i]) / 250; n     if (b[i] >= 0) sb += m * (250 - b[i]) / 250; n   } n   return sa > sb; n } n int main(int argc, char **argv) { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cin >> n; n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < 5; j++) { n       int64_t x; n       cin >> x; n       if (x >= 0) s[j]++; n       if (i == 0) a[j] = x; n       if (i == 1) b[j] = x; n     } n   } n   int64_t minx = -1; n   for (int i = 0; i < 32; i++) { n     bool ok = true; n     for (int j = 0; j < 5; j++) { n       c[j] = (i >> j) & 1; n       if (c[j] && a[j] < 0) ok = false; n     } n     if (!ok) continue; n     int64_t x; n     for (x = 0; x < 100000; x++) n       if (win(x)) break; n     if (x == 100000) x = -1; n     for (int j = 0; j < 5; j++) cerr << c[j]; n     cerr <<     << x << endl; n     minx = x >= 0 && (minx < 0 || x < minx) ? x : minx; n   } n   cout << minx << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   long double temp; n   temp = log2(n + 1); n   if (temp == (int)temp) { n     cout << temp << endl; n   } else { n     cout << (int)(temp) + 1 << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   double r1, r2, p1, p2; n   double A, B; n   int n; n   scanf( %d , &n); n   double x; n   r1 = 0; n   for (int i = 0; i < n; i++) { n     scanf( %lf , &x); n     if (x > r1) r1 = x; n   } n   int m; n   scanf( %d , &m); n   p1 = 0; n   for (int i = 0; i < m; i++) { n     scanf( %lf , &x); n     if (x > p1) p1 = x; n   } n   int z; n   scanf( %d , &z); n   p2 = 5005; n   for (int i = 0; i < z; i++) { n     scanf( %lf , &x); n     if (x < p2) p2 = x; n   } n   scanf( %lf %lf , &A, &B); n   r2 = (A * p2) / (B * p1) + 1; n   r2 = r1 * r1 / r2; n   r2 = sqrt(r2); n   printf( %.12lf n , r2); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n = 4; n   int a[4]; n   for (int i = 0; i < 4; i++) { n     cin >> a[i]; n   } n   sort(a, a + n); n   for (int i = 0; i < 3; i++) { n     cout << a[3] - a[i] <<    ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = 0x3f3f3f3f; n char s[int(3e5 + 5)]; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   ; n   int t; n   cin >> t; n   while (t--) { n     int n, m; n     cin >> n >> m; n     cin >> (s + 1); n     bool flag = true; n     int tmp1 = 0, tmp = 0; n     for (int i = 1; i <= m; i++) n       if (s[i] ==  1 ) n         tmp1++; n       else if (s[i] ==  ? ) n         tmp++; n     if (tmp1 + tmp < m / 2 or tmp1 > m / 2) flag = false; n     for (int i = 1; i <= m and flag == true; i++) { n       char ch =  ? ; n       for (int j = i; j <= n and flag == true; j += m) { n         if (s[j] ==  ? ) continue; n         if (ch ==  ? ) n           ch = s[j]; n         else { n           if (ch == s[j]) n             continue; n           else n             flag = false; n         } n       } n       if (flag == true) n         for (int j = i; j <= n; j += m) s[j] = ch; n     } n     tmp1 = tmp = 0; n     for (int i = 1; i <= m; i++) n       if (s[i] ==  1 ) n         tmp1++; n       else if (s[i] ==  ? ) n         tmp++; n     if (tmp1 + tmp < m / 2 or tmp1 > m / 2) flag = false; n     if (flag == true) n       cout <<  YES  << endl; n     else n       cout <<  NO  << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 30; n int a[maxn]; n int num[maxn] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1}; n int ans; n void dfs(string s, int v, int cnt) { n   int n = s.length(); n   if (v == n) { n     ans += cnt; n     return; n   } n   if (v < n - 2 && (s[v] -  0  + a[v]) >= 1) { n     a[v + 2] += 1; n     dfs(s, v + 1, cnt * num[s[v] -  0  + a[v] * 10 - 1]); n     a[v + 2] -= 1; n   } n   dfs(s, v + 1, cnt * num[s[v] -  0  + a[v] * 10]); n } n int main() { n   int kase; n   cin >> kase; n   while (kase--) { n     ans = 0; n     string s; n     cin >> s; n     dfs(s, 0, 1); n     cout << ans - 2 << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n void c_p_c() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n } n int32_t main() { n   c_p_c(); n   long long int t; n   cin >> t; n   while (t--) { n     long long int n, k; n     cin >> n >> k; n     vector<long long int> a(n), b(k); n     for (long long int i = 0; i < (long long int)n; i++) cin >> a[i]; n     for (long long int i = 0; i < (long long int)k; i++) cin >> b[i]; n     map<long long int, long long int> pos, present; n     for (auto it : b) present[it] = 1; n     for (long long int i = 0; i < (long long int)n; i++) pos[a[i]] = i; n     long long int ans = 1; n     for (long long int i = 0; i < (long long int)k; i++) { n       long long int p = pos[b[i]]; n       long long int temp = 0; n       if (p == 0) { n         if (!present[a[1]]) temp++; n       } else if (p == n - 1) { n         if (!present[a[n - 2]]) temp++; n       } else { n         if (!present[a[p - 1]]) temp++; n         if (!present[a[p + 1]]) temp++; n       } n       ans = (ans * temp) % 998244353; n       present[b[i]] = 0; n     } n     cout << ans <<   n ; n   } n   cerr <<  Time :   << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC n        <<  ms n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxN = 2e5 + 9, MOD = 1e9 + 7; n int n; n long long arr[maxN], ot[maxN]; n long long maxsub(long long *arr, int n) { n   long long cr = LLONG_MIN / 4, maxi = LLONG_MIN / 4; n   for (int i = 0; i < n; i++) { n     cr = max(arr[i], cr + arr[i]); n     maxi = max(maxi, cr); n   } n   return maxi; n } n long long trr(long long *arr, int sta) { n   int ct = 0; n   for (int i = sta, cnd = 1; i + 1 < n; i++, cnd *= -1) { n     ot[ct++] = abs(arr[i] - arr[i + 1]) * cnd; n   } n   return maxsub(ot, ct); n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0), cout.tie(0); n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> arr[i]; n   } n   cout << max(trr(arr, 0), trr(arr, 1)) <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n const long long N = 3e5 + 5; n const long long mod = 1e9 + 7; n const long long INF = 0x7f7f7f7f7f7f7f7f; n const int INFi = 0x7f7f7f7f; n long long n, m, vis[N]; n void solve() { n   cin >> n >> m; n   for (int i = 1; i <= 3 * n; i++) vis[i] = 0; n   vector<long long> match; n   for (int i = 1; i <= m; i++) { n     int u, v; n     cin >> u >> v; n     if (!vis[u] && !vis[v]) { n       vis[u] = 1; n       vis[v] = 1; n       match.push_back(i); n     } n   } n   if (match.size() >= n) { n     cout <<  Matching  n          <<   n ; n     for (int i = 0; i < n; i++) cout << match[i] <<    ; n     cout <<   n ; n     ; n   } else { n     cout <<  IndSet  n          <<   n ; n     for (int i = 1, j = 0; i <= 3 * n; i++) { n       if (vis[i]) continue; n       if (j == n) break; n       cout << i <<    ; n       j++; n     } n     cout <<   n ; n     ; n   } n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cout << fixed; n   cout << setprecision(15); n   ; n   int test = 1; n   cin >> test; n   for (int i = 1; i <= test; i++) { n     solve(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX = 5005, MOD = (int)1e9 + 7; n int dp[MAX][MAX], pref[MAX]; n int main() { n   int n, k, poc, kraj, i, j, raz; n   scanf( %d%d%d%d , &n, &poc, &kraj, &k); n   for (i = 1; i <= n; i++) dp[0][i] = 1; n   for (i = 1; i <= k; i++) { n     for (j = 1; j <= n; j++) { n       pref[j] = pref[j - 1] + dp[i - 1][j]; n       if (pref[j] >= MOD) pref[j] -= MOD; n     } n     for (j = 1; j <= n; j++) { n       raz = abs(j - kraj) - 1; n       if (!raz) n         dp[i][j] = 0; n       else { n         dp[i][j] = pref[min(n, j + raz)] - pref[max(0, j - raz - 1)]; n         if (dp[i][j] < 0) n           dp[i][j] += MOD; n         else if (dp[i][j] >= MOD) n           dp[i][j] -= MOD; n         dp[i][j] -= dp[i - 1][j]; n         if (dp[i][j] < 0) n           dp[i][j] += MOD; n         else if (dp[i][j] >= MOD) n           dp[i][j] -= MOD; n       } n     } n   } n   printf( %d n , dp[k][poc]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, m, b, mod, a[509], dp[509][509], ans; n int main() { n   cin >> n >> m >> b >> mod; n   dp[0][0] = 1; n   for (int i = 0; i < n; i++) cin >> a[i]; n   for (int i = 0; i < n; i++) { n     for (int j = 1; j <= m; j++) { n       for (int k = 0; k <= b - a[i]; k++) { n         dp[j][k + a[i]] = (dp[j - 1][k] + dp[j][k + a[i]]) % mod; n       } n     } n   } n   for (int i = 0; i <= b; i++) ans += dp[m][i], ans %= mod; n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   pair<int, int> p[10]; n   int i, j, w1, w2, cnt2; n   for (i = 0; i < 4; i++) scanf( %d%d , &p[i].first, &p[i].second); n   for (i = cnt2 = 0; i < 2; i++) { n     w1 = w2 = 0; n     for (j = 0; j < 2; j++) { n       if (p[0].first > p[2].second && p[1].second > p[3].first) w1++; n       if (p[0].first < p[2].second && p[1].second < p[3].first) w2++; n       swap(p[2], p[3]); n     } n     if (w2) cnt2++; n     if (w1 == 2) break; n     swap(p[0], p[1]); n   } n   if (i < 2) n     puts( Team 1 ); n   else if (cnt2 == 2) n     puts( Team 2 ); n   else n     puts( Draw ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int j, t; n   cin >> t; n   for (j = 0; j < t; j++) { n     long long int n; n     cin >> n; n     long long int a[n], i; n     for (i = 0; i < n; i++) cin >> a[i]; n     long long int p = a[0], sum = a[0]; n     for (i = 1; i < n; i++) { n       if (p < 0 && a[i] < 0) { n         if (a[i] > p) { n           sum += a[i]; n           sum -= p; n           p = a[i]; n         } n       } else if (p < 0 && a[i] > 0) { n         sum += a[i]; n         p = a[i]; n       } else if (p > 0 && a[i] > 0) { n         if (a[i] > p) { n           sum -= p; n           sum += a[i]; n           p = a[i]; n         } n       } else if (p > 0 && a[i] < 0) { n         sum += a[i]; n         p = a[i]; n       } n     } n     cout << sum << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n int a[200005]; n long long oddpref[200005]; n long long evenpref[200005]; n long long evensuff[200005]; n long long oddsuff[200005]; n int main() { n   cin >> n; n   for (int i = 1; i <= n; i++) { n     cin >> a[i]; n   } n   for (int i = 1; i <= n; i++) { n     oddpref[i] = oddpref[i - 1]; n     evenpref[i] = evenpref[i - 1]; n     if (i % 2) n       oddpref[i] += a[i]; n     else n       evenpref[i] += a[i]; n   } n   for (int i = n; i >= 1; i--) { n     oddsuff[i] = oddsuff[i + 1]; n     evensuff[i] = evensuff[i + 1]; n     if (i % 2) n       oddsuff[i] += a[i]; n     else n       evensuff[i] += a[i]; n   } n   int cnt = 0; n   for (int i = 1; i <= n; i++) { n     if (oddpref[i - 1] + evensuff[i + 1] == evenpref[i - 1] + oddsuff[i + 1]) { n       cnt++; n     } n   } n   cout << cnt; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a[501102]; n int ans, cnt, sum, d; n void solve() { n   ans = 0; n   cnt = 0; n   sum = 0; n   d = 0; n   int n; n   cin >> n; n   for (int i = 1; n >= i; i++) { n     cin >> a[i]; n     if (a[i] % 2 == 1) { n       ans++; n       if (a[i] * n % 2 == 1) d = 1; n     } else n       cnt++; n     sum += a[i]; n   } n   if (ans >= cnt && ans != n || sum % 2 == 1 || d != 0 || n       ans != 0 && cnt != 0) { n     cout <<  YES  << endl; n     return; n   } n   cout <<  NO  << endl; n } n int main() { n   int t; n   cin >> t; n   while (t--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n #pragma comment(linker,  stack:200000000 ) n #pragma GCC optimize( Ofast ) n #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native ) n using namespace std; n long long freq[3000005], mul[3000005], n, q, x; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cin >> n; n   for (int i = n; i--; ++freq[x]) cin >> x; n   for (int i = 1; i < 3000005; ++i) n     if (freq[i]) n       for (int j = i; j < 3000005; j += i) n         mul[j] += freq[i] * (freq[j / i] - (i == j / i)); n   for (int i = 1; i < 3000005; ++i) mul[i] += mul[i - 1]; n   for (cin >> q; q--; cout << n * (n - 1) - mul[x - 1] <<   n ) cin >> x; n } n


#include <bits/stdc++.h> n using namespace std; n long long N, M, nn; n long long a[300002]; n long long suma[300002]; n long long f[300002]; n long long sumf[300002]; n struct data { n   long long a, b; n   long long tot; n } seg[1200002]; n long long s, e; n bool cross(long long x1, long long y1, long long x2, long long y2) { n   if (y1 < x2 || y2 < x1) return false; n   return true; n } n void add(long long node, long long left, long long right) { n   seg[node].tot += (sumf[min(right, e) - s + 1] - sumf[max(left, s) - s]); n   seg[node].tot %= 1000000009; n   if (s <= left && right <= e) { n     seg[node].a += f[left - s]; n     seg[node].b += f[left - s + 1]; n     seg[node].a %= 1000000009; n     seg[node].b %= 1000000009; n     return; n   } n   int mid = (left + right) / 2; n   if (cross(s, e, left, mid)) add(node * 2, left, mid); n   if (cross(s, e, mid + 1, right)) add((node * 2) + 1, mid + 1, right); n } n long long ans; n long long x, y; n void sum(long long node, long long left, long long right) { n   if (s <= left && right <= e) { n     ans += seg[node].tot; n     ans %= 1000000009; n     return; n   } n   int mid = (left + right) / 2; n   seg[node * 2].a += seg[node].a; n   seg[node * 2].b += seg[node].b; n   seg[node * 2].a %= 1000000009; n   seg[node * 2].b %= 1000000009; n   x = seg[node].a; n   y = seg[node].b; n   seg[node * 2].tot += ((x * sumf[mid - left]) + (y * sumf[mid - left + 1])); n   seg[node * 2].tot %= 1000000009; n   seg[(node * 2) + 1].tot += n       ((x * sumf[right - left]) + (y * sumf[right - left + 1])); n   seg[(node * 2) + 1].tot -= n       ((seg[node].a * sumf[mid - left]) + (seg[node].b * sumf[mid - left + 1])); n   seg[(node * 2) + 1].tot %= 1000000009; n   x = ((seg[node].a * f[mid - left]) + (seg[node].b * f[mid - left + 1])); n   y = ((seg[node].a * f[mid - left + 1]) + (seg[node].b * f[mid - left + 2])); n   seg[(node * 2) + 1].a += x; n   seg[(node * 2) + 1].b += y; n   seg[(node * 2) + 1].a %= 1000000009; n   seg[(node * 2) + 1].b %= 1000000009; n   seg[node].a = seg[node].b = 0; n   if (cross(s, e, left, mid)) sum(node * 2, left, mid); n   if (cross(s, e, mid + 1, right)) sum((node * 2) + 1, mid + 1, right); n } n long long tmp[300002], ans2; n void process() { n   long long i, j; n   long long op, l, r; n   for (nn = 1; nn < N; nn *= 2) n     ; n   for (i = 1; i <= N; i++) { n     suma[i] = suma[i - 1] + a[i]; n     suma[i] %= 1000000009; n   } n   f[1] = f[2] = 1; n   for (i = 3; i <= N; i++) { n     f[i] = f[i - 1] + f[i - 2]; n     f[i] %= 1000000009; n   } n   for (i = 1; i <= N; i++) { n     sumf[i] = sumf[i - 1] + f[i]; n     sumf[i] %= 1000000009; n     tmp[i] = a[i]; n   } n   for (i = 1; i <= M; i++) { n     scanf( %lld %lld %lld , &op, &l, &r); n     if (op == 1) { n       s = l; n       e = r; n       add(1, 1, nn); n     } else { n       s = l; n       e = r; n       ans = 0; n       sum(1, 1, nn); n       ans += suma[e]; n       ans -= suma[s - 1]; n       ans %= 1000000009; n       if (ans < 0) ans += 1000000009; n       printf( %lld n , ans); n       ans2 = 0; n     } n   } n } n void clean() { n   long long i; n   for (i = 1; i <= nn * 2; i++) seg[i].a = seg[i].b = seg[i].tot; n } n int main(void) { n   long long i; n   scanf( %lld %lld , &N, &M); n   for (i = 1; i <= N; i++) scanf( %lld , &a[i]); n   process(); n   clean(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n #define fore(i, a, b) for(int i = a; i <= b; i++) n #define Fore(i, a, b) for(int i = a; i < b; i++) n #define pii pair<int, int> n #define fi first n #define se second n #define MP make_pair n #define EP emplace_back n #define li long long n  n const int MAXN = 2100, mod = 998244353; n  n inline int input(){ n     char c = getchar(); int o; bool f = 0; n     while(c > 57 || c < 48) n         f |= (c ==  - ), c = getchar(); n     for(o = 0; c > 47 && c < 58; c = getchar()) n         o = (o << 1)+(o << 3)+(c - 48); n     return f ? -o : o; n } n  n li C[MAXN * 2][MAXN * 2]; n  n int main(){ n     int n = input(), m = input(); n     li ans = 0; n     C[0][0] = 1; n     fore(i, 1, n + m){ n         C[i][0] = 1; n         fore(j, 1, i) n             C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % mod; n             // cout << C[i][j] <<    n [j == i]; n     } n     Fore(r, 1, n){ n         li F = 0; n         for(int c = m - 1; c >= 1; c--){ n             F = (F + C[n - r + m - c - 1][n - r] * C[n - r - 1 + c][n - r - 1] % mod) % mod; n             ans = (ans + F * (C[r + c - 1][r] * C[r + m - c - 1][r - 1] % mod) % mod) % mod; n         } n     } n     swap(n, m); n     Fore(r, 1, n){ n         li F = 0; n         for(int c = m - 1; c >= 1; c--){ n             ans = (ans + F * (C[r + c - 1][r] * C[r + m - c - 1][r - 1] % mod) % mod) % mod; n             F = (F + C[n - r + m - c - 1][n - r] * C[n - r - 1 + c][n - r - 1] % mod) % mod; n         } n     } n     printf( %lld , (ans << 1) % mod); n }


#include <bits/stdc++.h> n using namespace std; n void solve() { n   long long n, x; n   cin >> n; n   long long a[n + 1]; n   for (long long i = 0; i < n; i++) { n     cin >> a[i + 1]; n   } n   long long dp[n + 2]; n   dp[0] = 0; n   dp[n + 1] = 0; n   for (long long i = 1; i <= n; i++) dp[i] = min(dp[i - 1] + 1, a[i]); n   for (long long i = n; i >= 1; i--) dp[i] = min(dp[i + 1] + 1, dp[i]); n   long long mx = dp[1]; n   for (long long i = 2; i <= n; i++) mx = max(mx, dp[i]); n   cout << mx; n   return; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   ; n   long long t; n   t = 1; n   while (t--) solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, ans, u, v, i, root_u, root_v, arr[100001], len[100001], c[100001], n     k; n vector<pair<long long, long long> > in; n long long find(long long x) { n   if (arr[x] == x) return x; n   return arr[x] = find(arr[x]); n } n int main() { n   cin >> n >> k; n   for (i = 1; i <= n; i++) arr[i] = i, len[i] = 1; n   for (i = 0; i < k; i++) { n     cin >> u >> v; n     root_u = find(u); n     root_v = find(v); n     if (root_u != root_v) arr[root_u] = root_v, len[root_v] += len[root_u]; n     c[u]++; n   } n   for (i = 1; i <= n; i++) n     if (arr[i] != i) c[find(i)] += c[i]; n   for (i = 1; i <= n; i++) n     if (arr[i] == i) ans += (c[i] - len[i] + 1); n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n const int maxn = 3e5 + 5; n int n, a, b; n string s; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int q; n   cin >> q; n   while (q--) { n     int a, b; n     cin >> a >> b; n     cin >> s; n     n = s.size(); n     vector<int> sz(n, 0); n     vector<int> segs; n     for (int i = 0; i < n; i++) { n       if (s[i] !=  . ) continue; n       sz[i] = i == 0 ? 1 : sz[i - 1] + 1; n       if (i == n - 1 || s[i + 1] !=  . ) segs.push_back(sz[i]); n     } n     int numSmall = 0; n     int numBig = 0; n     for (int i : segs) { n       if (b <= i && i < a) n         numSmall++; n       else if (i >= 2 * b) n         numBig++; n     } n     if (numSmall > 0) { n       cout <<  NO n ; n     } else { n       if (numBig >= 2) { n         cout <<  NO n ; n       } else if (numBig == 0) { n         int cnt = 0; n         for (int i : segs) { n           if (i >= a) cnt++; n         } n         cout << (cnt & 1 ?  YES  :  NO ) <<   n ; n       } else if (numBig == 1) { n         int mxSize = 0; n         for (int i : segs) { n           mxSize = max(mxSize, i); n         } n         int cnt = 0; n         for (int i : segs) { n           if (i == mxSize) continue; n           if (i >= a) cnt++; n         } n         if (a > mxSize) { n           cout <<  NO n ; n           return 0; n         } n         int s1 = 0, s2 = mxSize - a; n         bool canWin = false; n         for (; s2 >= 0; s1++, s2--) { n           if ((b <= s1 && s1 < a) || (b <= s2 && s2 < a)) continue; n           if (s1 >= 2 * b || s2 >= 2 * b) continue; n           int c = cnt; n           if (s1 >= a) c++; n           if (s2 >= a) c++; n           if (c % 2 == 0) { n             canWin = true; n             break; n           } n         } n         cout << (canWin ?  YES  :  NO ) <<   n ; n       } n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int ans1[300003], ans2[300003], l[300003]; n vector<int> t[2400024]; n vector<int> a, q; n void build(int v, int tl, int tr) { n   if (tl == tr) { n     t[v].push_back(a[tl]); n     return; n   } n   int mid = (tl + tr) / 2; n   build(v * 2, tl, mid); n   build(v * 2 + 1, mid + 1, tr); n   int l = 0, r = 0; n   t[v].reserve(t[v * 2].size() + t[v * 2 + 1].size()); n   while (l != t[v * 2].size() || r != t[v * 2 + 1].size()) { n     if (l == t[v * 2].size()) { n       t[v].push_back(t[v * 2 + 1][r++]); n     } else if (r == t[v * 2 + 1].size()) { n       t[v].push_back(t[v * 2][l++]); n     } else if (t[v * 2][l] < t[v * 2 + 1][r]) { n       t[v].push_back(t[v * 2][l++]); n     } else { n       t[v].push_back(t[v * 2 + 1][r++]); n     } n   } n } n int ask(int v, int tl, int tr, int l, int r, int x) { n   if (l > r) { n     return 0; n   } n   if (tl == l && tr == r) { n     l = -1; n     r = t[v].size(); n     while (r - l > 1) { n       int mid = (r + l) / 2; n       if (t[v][mid] < x) { n         l = mid; n       } else { n         r = mid; n       } n     } n     return r; n   } n   int mid = (tl + tr) / 2; n   return ask(v * 2, tl, mid, l, min(r, mid), x) + n          ask(v * 2 + 1, mid + 1, tr, max(l, mid + 1), r, x); n } n int main() { n   int n, m; n   cin >> n >> m; n   a.push_back(1e9 + 7); n   for (int i = n; i > 0; --i) { n     ans1[i] = i; n     l[i] = a.size(); n     a.push_back(0); n   } n   while (m--) { n     int x; n     cin >> x; n     ans1[x] = 1; n     q.push_back(x); n     a.push_back(l[x]); n     l[x] = a.size() - 1; n   } n   build(1, 0, a.size() - 1); n   for (int i = n + 1; i < a.size(); ++i) { n     ans2[q[i - n - 1]] = n         max(ans2[q[i - n - 1]], ask(1, 0, a.size() - 1, a[i], i, a[i])); n   } n   for (int i = 1; i <= n; ++i) { n     ans2[i] = max(ans2[i], ask(1, 0, a.size() - 1, l[i], a.size() - 1, l[i])); n     cout << ans1[i] <<     << ans2[i] << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int n, a[(1 << 20)]; n vector<int> odd, ev; n int main() { n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n   } n   for (int s = 0, f = n - 1; s < f; s++, f--) { n     if (s % 2 == 0) { n       swap(a[s], a[f]); n     } n   } n   for (int i = 0; i < n; i++) { n     cout << a[i] <<    ; n   } n   cout <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 2e5 + 5; n vector<int> v1[maxn], v2[maxn]; n int n, lazy[maxn << 2], minnode[maxn << 2], maxnode[maxn << 2]; n long long sumnode[maxn << 2]; n void modify(int rt, int l, int r, int c) { n   lazy[rt] = c; n   minnode[rt] = maxnode[rt] = c; n   sumnode[rt] = (r - l + 1LL) * (n + 1 - c); n } n void pushup(int rt) { n   sumnode[rt] = sumnode[rt << 1] + sumnode[rt << 1 | 1]; n   minnode[rt] = min(minnode[rt << 1], minnode[rt << 1 | 1]); n   maxnode[rt] = max(maxnode[rt << 1], maxnode[rt << 1 | 1]); n } n void pushdown(int rt, int l, int r) { n   if (lazy[rt]) { n     int m = (l + r) >> 1; n     modify(rt << 1, l, m, lazy[rt]); n     modify(rt << 1 | 1, m + 1, r, lazy[rt]); n     lazy[rt] = 0; n   } n } n void build(int rt, int l, int r) { n   lazy[rt] = 0; n   if (l == r) { n     minnode[rt] = l; n     sumnode[rt] = n - l + 1; n     return; n   } n   int m = (l + r) >> 1; n   build(rt << 1, l, m), build(rt << 1 | 1, m + 1, r); n   pushup(rt); n } n void update(int rt, int l, int r, int x, int y, int c) { n   if (c <= minnode[rt]) return; n   if (x <= l && r <= y && maxnode[rt] <= c) { n     modify(rt, l, r, c); n     return; n   } n   pushdown(rt, l, r); n   int m = (l + r) >> 1; n   if (x <= m) update(rt << 1, l, m, x, y, c); n   if (m < y) update(rt << 1 | 1, m + 1, r, x, y, c); n   pushup(rt); n } n void init() { n   for (int i = 1; i < maxn; ++i) { n     for (int j = i; j < maxn; j += i) v1[j].push_back(i); n   } n } n int main() { n   init(); n   scanf( %d , &n); n   int mx = 0; n   for (int i = 1; i <= n; ++i) { n     int x; n     scanf( %d , &x); n     mx = max(x, mx); n     for (int j = 0; j < v1[x].size(); ++j) v2[v1[x][j]].push_back(i); n   } n   build(1, 1, n); n   long long ans = 0, cur = sumnode[1]; n   for (int i = mx; i; --i) { n     if (v2[i].size() > 1) { n       int p = v2[i][0], q = v2[i][1]; n       if (q < n) update(1, 1, n, q + 1, n, n + 1); n       update(1, 1, n, p + 1, q, v2[i].back()); n       update(1, 1, n, 1, p, v2[i][v2[i].size() - 2]); n       ans += i * (cur - sumnode[1]); n       cur = sumnode[1]; n     } n   } n   printf( %I64d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long int t[4000005]; n void update(long long int v, long long int tl, long long int tr, n             long long int pos) { n   if (tl == tr) { n     t[v]++; n     return; n   } n   long long int tm = (tl + tr) / 2; n   if (pos <= tm) n     update(2 * v, tl, tm, pos); n   else n     update(2 * v + 1, tm + 1, tr, pos); n   t[v] = t[2 * v] + t[2 * v + 1]; n } n long long int sum(long long int v, long long int tl, long long int tr, n                   long long int l, long long int r) { n   if (l > r) return 0; n   if (l == tl && r == tr) return t[v]; n   long long int tm = (tl + tr) / 2; n   return sum(2 * v, tl, tm, l, min(r, tm)) + n          sum(2 * v + 1, tm + 1, tr, max(l, tm + 1), r); n } n void solve() { n   long long int n, k; n   cin >> n >> k; n   if (k >= (n + 1) / 2) k = n - k; n   long long int cnt = n, x = 1, cur = 1; n   while (cnt) { n     long long int y = x + k; n     if (y > n) y -= n; n     long long int s = x + 1, e = y - 1, val; n     if (s == n + 1) s = 1; n     if (e == 0) e = n; n     if (s <= e) n       val = sum(1, 1, n, s, e); n     else n       val = sum(1, 1, n, s, n) + sum(1, 1, n, 1, e); n     cur += val + 1; n     cout << cur <<    ; n     update(1, 1, n, x); n     update(1, 1, n, y); n     x = y; n     cnt--; n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   clock_t z = clock(); n   long long int qc = 1; n   for (long long int i = 1; i <= qc; i++) { n     solve(); n   } n   fprintf(stderr,  Total Time:%.4Lf n , n           (long double)(clock() - z) / CLOCKS_PER_SEC), n       fflush(stderr); n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n bool chmax(T &a, const T &b) { n   if (a < b) { n     a = b; n     return 1; n   } n   return 0; n } n template <class T> n bool chmin(T &a, const T &b) { n   if (a > b) { n     a = b; n     return 1; n   } n   return 0; n } n template <class T> n ostream &operator<<(ostream &os, const vector<T> &t) { n   os <<  [ ; n   for (__typeof((t).begin()) it = (t).begin(); it != (t).end(); it++) { n     if (it != t.begin()) os <<  , ; n     os << *it; n   } n   os <<  ] ; n   return os; n } n template <class T> n ostream &operator<<(ostream &os, const set<T> &t) { n   os <<  { ; n   for (__typeof((t).begin()) it = (t).begin(); it != (t).end(); it++) { n     if (it != t.begin()) os <<  , ; n     os << *it; n   } n   os <<  } ; n   return os; n } n template <class S, class T> n ostream &operator<<(ostream &os, const pair<S, T> &t) { n   return os <<  (  << t.first <<  ,  << t.second <<  ) ; n } n template <class S, class T> n pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { n   return pair<S, T>(s.first + t.first, s.second + t.second); n } n template <class S, class T> n pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { n   return pair<S, T>(s.first - t.first, s.second - t.second); n } n const int INF = 1 << 28; n const double EPS = 1e-8; n const int MOD = 1000000007; n int n, m, t; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   scanf( %d%d%d , &n, &m, &t); n   deque<pair<int, int> > ends; n   int ans = 0, accept = 0; n   vector<int> idxs(n); n   for (int i = 0; i < (int)(n); i++) { n     int h, mm, s, x; n     scanf( %d:%d:%d , &h, &mm, &s); n     x = h * 3600 + mm * 60 + s; n     while (!ends.empty() && ends.front().first <= x) { n       idxs[ends.front().second] = 1; n       ans++; n       ends.pop_front(); n     } n     ends.emplace_back(x + t, i); n     if (ends.size() == m) accept = 1; n     while (ends.size() > m) { n       idxs[ends.back().second] = 0; n       ends.pop_back(); n       ends.back().first = x + t; n     } n   } n   while (!ends.empty()) { n     idxs[ends.back().second] = 1; n     ans++; n     ends.pop_back(); n   } n   if (!accept) { n     puts( No solution ); n     return 0; n   } n   int sum = 0; n   printf( %d n , ans); n   for (int i = 0; i < (int)(n); i++) printf( %d n , sum += idxs[i]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 2e5 + 5; n int tim; n int t[maxn]; n int sum[maxn], sum2[maxn]; n int in[maxn], ou[maxn], dfn[maxn]; n vector<int> G[maxn]; n void dfs(int rt, int fa) { n   in[rt] = ++tim; n   dfn[tim] = rt; n   for (int i = 0; i < G[rt].size(); i++) { n     int to = G[rt][i]; n     if (to == fa) continue; n     dfs(to, rt); n   } n   ou[rt] = tim; n } n struct T { n   int l, r, mid; n   int add, sum; n } tree[maxn << 2]; n void push_up(int rt) { n   tree[rt].sum = tree[rt << 1].sum + tree[rt << 1 | 1].sum; n } n void push_down(int rt) { n   if (tree[rt].add) { n     tree[rt << 1].add ^= 1; n     tree[rt << 1].sum = n         (tree[rt << 1].r - tree[rt << 1].l + 1) - tree[rt << 1].sum; n     tree[rt << 1 | 1].add ^= 1; n     tree[rt << 1 | 1].sum = n         (tree[rt << 1 | 1].r - tree[rt << 1 | 1].l + 1) - tree[rt << 1 | 1].sum; n     tree[rt].add = 0; n   } n } n void build(int rt, int l, int r) { n   tree[rt].add = 0; n   tree[rt].l = l; n   tree[rt].r = r; n   if (l == r) { n     tree[rt].sum = t[dfn[l]]; n     return; n   } n   int mid = tree[rt].mid = l + r >> 1; n   build(rt << 1, l, mid); n   build(rt << 1 | 1, mid + 1, r); n   push_up(rt); n } n void update(int rt, int l, int r) { n   if (tree[rt].r < l || tree[rt].l > r) return; n   if (tree[rt].l >= l && tree[rt].r <= r) { n     tree[rt].sum = (tree[rt].r - tree[rt].l + 1) - tree[rt].sum; n     tree[rt].add ^= 1; n     return; n   } n   push_down(rt); n   if (tree[rt].mid >= l) update(rt << 1, l, r); n   if (tree[rt].mid < r) update(rt << 1 | 1, l, r); n   push_up(rt); n } n int query(int rt, int l, int r) { n   if (tree[rt].r < l || tree[rt].l > r) return 0; n   if (tree[rt].l >= l && tree[rt].r <= r) return tree[rt].sum; n   push_down(rt); n   int ans = 0; n   if (tree[rt].mid >= l) ans += query(rt << 1, l, r); n   if (tree[rt].mid < r) ans += query(rt << 1 | 1, l, r); n   push_up(rt); n   return ans; n } n int main() { n   int n, x; n   scanf( %d , &n); n   for (int i = 2; i <= n; i++) { n     scanf( %d , &x); n     G[x].push_back(i); n     G[i].push_back(x); n   } n   for (int i = 1; i <= n; i++) scanf( %d , &t[i]); n   dfs(1, -1); n   build(1, 1, n); n   int q; n   scanf( %d , &q); n   while (q--) { n     char op[4]; n     int v; n     scanf( %s%d , op, &v); n     if (op[0] ==  p ) n       update(1, in[v], ou[v]); n     else n       printf( %d n , query(1, in[v], ou[v])); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 200007; n string s; n int q, n, cnt[maxn][26]; n void Solve() { n   int l, r; n   cin >> l >> r; n   if (l == r) { n     cout <<  Yes  <<   n ; n     return; n   } n   if (s[l] != s[r]) { n     cout <<  Yes  <<   n ; n     return; n   } n   int cnt = 0; n   for (int i = 0; i < 26; i++) { n     if (i == s[l] -  a ) continue; n     int gau = ::cnt[r][i] - ::cnt[l - 1][i]; n     if (gau) cnt++; n   } n   if (cnt >= 2) n     cout <<  Yes  <<   n ; n   else n     cout <<  No  <<   n ; n } n int32_t main() { n   auto start = chrono::steady_clock::now(); n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   if (fopen( test.inp ,  r )) freopen( test.inp ,  r , stdin); n   cin >> s >> q; n   n = s.length(); n   s =     + s; n   for (int i = 1; i <= n; i++) { n     for (int j = 0; j < 26; j++) { n       cnt[i][j] = cnt[i - 1][j]; n       if (j == s[i] -  a ) cnt[i][j]++; n     } n   } n   while (q--) Solve(); n   auto finish = chrono::steady_clock::now(); n   cerr << chrono::duration_cast<chrono::milliseconds>(finish - start).count(); n } n


#include <bits/stdc++.h> n using namespace std; n int n; n int a[300010]; n int p[300010]; n struct node { n   int next[2] = {}; n   int cnt = 0; n   int par; n }; n node t[31 * 300010]; n int root = 1; n int E = 2; n int main() { n   ios_base::sync_with_stdio(false); n   cin >> n; n   for (int i = 0; i < n; i++) cin >> a[i]; n   for (int i = 0; i < n; i++) cin >> p[i]; n   for (int i = 0; i < n; i++) { n     int u = root; n     for (int j = 29; j >= 0; j--) { n       int c; n       if (p[i] & (1 << j)) n         c = 1; n       else n         c = 0; n       if (!t[u].next[c]) { n         t[u].next[c] = E++; n         t[E - 1].par = u; n       } n       u = t[u].next[c]; n     } n     while (u != 1) { n       t[u].cnt++; n       u = t[u].par; n     } n   } n   for (int i = 0; i < n; i++) { n     int x = a[i]; n     int u = root; n     int val = 0; n     for (int j = 29; j >= 0; j--) { n       int c; n       if (a[i] & (1 << j)) n         c = 1; n       else n         c = 0; n       if (t[u].next[c] && t[t[u].next[c]].cnt) { n         val ^= (1 << j) * c; n         u = t[u].next[c]; n       } else { n         val ^= (1 << j) * (!c); n         u = t[u].next[!c]; n       } n     } n     while (u != 0) { n       t[u].cnt--; n       u = t[u].par; n     } n     x ^= val; n     cout << x <<    ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int mod = 1e9 + 9; n const int mod1 = 999999937; n const int inf = 2e9; n const double eps = 1e-7; n int d[101][101]; n int main() { n   int n, m; n   cin >> n >> m; n   for (int i = 0; i < m; i++) { n     int a, b, c; n     cin >> a >> b >> c; n     d[a - 1][b - 1] = c; n   } n   int ans = 0; n   int w = n; n   while (w--) { n     for (int i = 0; i < n; i++) { n       for (int j = 0; j < n; j++) { n         for (int k = 0; k < n; k++) { n           if (d[i][j] > 0 && d[j][k] > 0) { n             int q = min(d[i][j], d[j][k]); n             d[i][j] -= q; n             d[j][k] -= q; n             d[i][k] += q; n           } n         } n       } n     } n   } n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < n; j++) { n       ans += d[i][j]; n     } n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char s[5000010]; n int f[5000010]; n int main() { n   scanf( %s , s); n   int l = 0, r = 0, e = 1, ans = 0; n   for (int i = 0; s[i]; i++) { n     l = l * 103 + s[i]; n     r = r + s[i] * e; n     e *= 103; n     if (l == r) f[i + 1] = f[(i + 1) / 2] + 1; n     ans += f[i + 1]; n   } n   cout << ans << endl; n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /STACK:1024000000,1024000000 ) n using namespace std; n const int maxn = 1e6 + 7; n const int INF = 1e9 + 7; n int n, k; n int a[maxn]; n vector<int> fac[maxn]; n int sum[maxn]; n int L[maxn], R[maxn]; n long long ans; n void ini() { n   stack<int> st; n   a[n + 1] = INF; n   for (int i = 1; i < n + 1; i++) L[i] = 1; n   for (int i = 1; i < n + 2; i++) { n     int num = 0; n     while (!st.empty() && a[st.top()] <= a[i]) { n       int p = st.top(); n       st.pop(); n       R[p] = num; n       L[i] += L[p]; n       num = L[p] + R[p]; n     } n     st.push(i); n   } n } n int query(int x, int l, int r) { n   int a = lower_bound(fac[x].begin(), fac[x].end(), l) - fac[x].begin(); n   int b = upper_bound(fac[x].begin(), fac[x].end(), r) - fac[x].begin(); n   return b - a; n } n int main() { n   scanf( %d%d , &n, &k); n   for (int i = 1; i < n + 1; i++) scanf( %d , &a[i]); n   for (int i = 1; i < n + 1; i++) sum[i] = (sum[i - 1] + a[i]) % k; n   fac[0].push_back(0); n   for (int i = 1; i < n + 1; i++) fac[sum[i]].push_back(i); n   ini(); n   for (int i = 1; i < n + 1; i++) { n     L[i] = i - L[i]; n     R[i] = i + R[i] + 1; n   } n   for (int i = 1; i < n + 1; i++) { n     if (i - L[i] < R[i] - i) { n       for (int j = L[i]; j < i; j++) n         ans += query((sum[j] + a[i]) % k, i, R[i] - 1); n     } else { n       for (int j = i; j < R[i]; j++) n         ans += query((sum[j] - a[i] % k + k) % k, L[i], i - 1); n     } n   } n   printf( %I64d n , ans - n); n   return 0; n } n