#include <bits/stdc++.h> n using namespace std; n const long long INF = 1 << 28; n const long long LINF = 1ll << 61; n const long long mod = 1e9 + 7; n unsigned long long base = 1000000007; n char a[2][2011], s[2011]; n int n, m; n unsigned long long hsl[2][2011], hsr[2][2011], hss[2011], pw[2011]; n unsigned long long gethsl(int i, int x, int y) { n   return hsl[i][y] - hsl[i][x - 1] * pw[y - x + 1]; n } n unsigned long long gethsr(int i, int x, int y) { n   return hsr[i][y] - hsr[i][x + 1] * pw[x - y + 1]; n } n unsigned long long gethss(int x, int y) { n   return hss[y] - hss[x - 1] * pw[y - x + 1]; n } n long long dp[2][2011][2], pre[2][2011][2]; n long long solve() { n   for (int i = 0; i < 2; i++) { n     hsl[i][0] = 0; n     for (int j = 1; j <= n; j++) hsl[i][j] = hsl[i][j - 1] * base + a[i][j]; n     hsr[i][n + 1] = 0; n     for (int j = n; j >= 1; j--) hsr[i][j] = hsr[i][j + 1] * base + a[i][j]; n   } n   long long ans = 0; n   memset(dp, 0, sizeof(dp)); n   for (int p = 1; p <= m; p++) { n     for (int i = 0; i < 2; i++) n       for (int j = 1; j <= n; j++) n         for (int t = 0; t < 2; t++) pre[i][j][t] = dp[i][j][t]; n     memset(dp, 0, sizeof(dp)); n     if (p % 2 == 0 && p > 2 && p < m) { n       int len = p >> 1; n       for (int i = 0; i < 2; i++) { n         for (int j = len + 1; j <= n + 1; j++) { n           if (gethsr(i, j - 1, j - len) * pw[len] + n                   gethsl(!i, j - len, j - 1) != n               gethss(1, p)) n             continue; n           dp[!i][j - 1][1] = 1; n         } n       } n     } else if (p == 1) { n       for (int i = 0; i < 2; i++) n         for (int j = 1; j <= n; j++) dp[i][j][0] = (s[1] == a[i][j]); n     } n     for (int i = 0; i < 2; i++) { n       for (int j = 1; j <= n; j++) { n         if (a[i][j] != s[p]) continue; n         dp[i][j][0] = (dp[i][j][0] + pre[i][j - 1][0] + pre[i][j - 1][1]) % mod; n         dp[i][j][1] = (dp[i][j][1] + pre[!i][j][0]) % mod; n       } n     } n     if ((m - p) % 2 == 0 && m - p > 2) { n       int len = (m - p) >> 1; n       for (int i = 0; i < 2; i++) { n         for (int j = 1; j <= n - len; j++) { n           if (gethsl(i, j + 1, j + len) * pw[len] + n                   gethsr(!i, j + len, j + 1) != n               gethss(p + 1, m)) n             continue; n           for (int t = 0; t < 2; t++) ans = (ans + dp[i][j][t]) % mod; n         } n       } n     } else if (p == m) { n       for (int i = 0; i < 2; i++) n         for (int j = 1; j <= n; j++) n           for (int t = 0; t < 2; t++) ans = (ans + dp[i][j][t]) % mod; n     } n   } n   return ans; n } n int main() { n   pw[0] = 1; n   for (int i = 1; i <= 2005; i++) pw[i] = pw[i - 1] * base; n   scanf( %s , a[0] + 1); n   scanf( %s , a[1] + 1); n   n = strlen(a[0] + 1); n   scanf( %s , s + 1); n   m = strlen(s + 1); n   if (m == 1) { n     int cnt = 0; n     for (int i = 0; i < 2; i++) n       for (int j = 1; j <= n; j++) cnt += (a[i][j] == s[1]); n     cout << cnt << endl; n     return 0; n   } else if (m == 2) { n     int cnt = 0; n     for (int i = 0; i < 2; i++) n       for (int j = 1; j <= n; j++) cnt += (a[i][j] == s[1] && a[!i][j] == s[2]); n     for (int i = 0; i < 2; i++) n       for (int j = 1; j <= n; j++) n         cnt += (a[i][j] == s[1] && a[i][j + 1] == s[2]) + n                (a[i][j] == s[1] && a[i][j - 1] == s[2]); n     cout << cnt << endl; n     return 0; n   } n   for (int i = 1; i <= m; i++) hss[i] = hss[i - 1] * base + s[i]; n   long long ans = solve(); n   reverse(a[0] + 1, a[0] + n + 1); n   reverse(a[1] + 1, a[1] + n + 1); n   ans = (ans + solve()) % mod; n   if (m % 2 == 0) { n     int len = m >> 1; n     for (int i = 0; i < 2; i++) { n       for (int j = 0; j <= n - len; j++) { n         ans += n             (gethsl(i, j + 1, j + len) * pw[len] + gethsr(!i, j + len, j + 1) == n              gethss(1, m)); n       } n     } n     for (int i = 0; i < 2; i++) { n       for (int j = len + 1; j <= n + 1; j++) { n         ans += n             (gethsr(i, j - 1, j - len) * pw[len] + gethsl(!i, j - len, j - 1) == n              gethss(1, m)); n       } n     } n   } n   cout << ans % mod << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   bool temp = false; n   cin >> n; n   string *arr = new string[n]; n   for (int i = 0; i < n; i++) cin >> arr[i]; n   for (int i = 0; i < n; i++) { n     if (arr[i][0] ==  O  && arr[i][1] ==  O ) { n       temp = true; n       cout <<  YES  << endl; n       arr[i][0] =  + ; n       arr[i][1] =  + ; n       for (int i = 0; i < n; i++) cout << arr[i] << endl; n       break; n     } n     if (arr[i][3] ==  O  && arr[i][4] ==  O ) { n       temp = true; n       cout <<  YES  << endl; n       arr[i][3] =  + ; n       arr[i][4] =  + ; n       for (int i = 0; i < n; i++) cout << arr[i] << endl; n       break; n     } n   } n   if (temp == false) { n     cout <<  NO  << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, a[500 + 5]; n long long ans = 1LL << 60; n void cal(int x) { n   if (!x) return; n   long long sum = 0; n   for (int i = 1; i <= n; ++i) { n     if (a[i] % x == 0 || (a[i] / x >= x - 1 - a[i] % x)) n       sum += a[i] / x + bool(a[i] % x); n     else n       return; n   } n   ans = min(ans, sum); n } n int main() { n   int i; n   scanf( %d , &n); n   for (i = 1; i <= n; ++i) scanf( %d , &a[i]); n   for (i = 1; i * i <= a[1]; ++i) n     cal(i), cal(a[1] / i), cal(a[1] / i - 1), cal(a[1] / i + 1); n   printf( %I64d , ans); n } n


#include <bits/stdc++.h> n using namespace std; n const int cap = int(1e5) + 1; n vector<int> graph[cap]; n vector<int> cnt(cap); n void dfs(int i, int h) { n   cnt[h] ^= 1; n   for (int j : graph[i]) dfs(j, h + 1); n } n int main() { n   int n; n   cin >> n; n   int p; n   for (int i = 2; i <= n; ++i) { n     cin >> p; n     graph[p].push_back(i); n   } n   dfs(1, 0); n   int ans = 0; n   for (int i = 0; i < n; ++i) ans += cnt[i]; n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct node { n   int days; n   int index; n }; n bool compare(node lhs, node rhs) { return (lhs.days < rhs.days); } n int main() { n   int n, k; n   int sum = 0; n   scanf( %d%d , &n, &k); n   node a[n + 1]; n   for (int i = 1; i <= n; i++) { n     scanf( %d , &a[i].days); n     a[i].index = i; n   } n   sort(a + 1, a + n + 1, compare); n   int i = 1; n   sum = a[i].days; n   while (sum <= k) { n     i++; n     if (i <= n) n       sum += (a[i].days); n     else n       break; n   } n   printf( %d n , i - 1); n   if (i != 1) { n     for (int j = 1; j < i; j++) printf( %d  , a[j].index); n     printf(  n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<set<int> > g; n vector<int> ans; n vector<bool> used; n void dfs(int v, int p) { n   used[v] = true; n   ans.push_back(v); n   for (set<int>::iterator i = g[v].begin(); i != g[v].end(); i++) { n     if (!used[*i] && g[*i].count(p)) dfs(*i, v); n   } n } n int main() { n   int n; n   scanf( %d , &n); n   g.resize(n); n   used.resize(n, false); n   for (int i = 0; i < 2 * n; i++) { n     int a, b; n     scanf( %d %d , &a, &b); n     a--; n     b--; n     g[a].insert(b); n     g[b].insert(a); n     if (g[a].size() > 4 || g[b].size() > 4) { n       puts( -1 ); n       return 0; n     } n   } n   ans.push_back(0); n   used[0] = true; n   int st, p = -1; n   for (set<int>::iterator i = g[0].begin(); i != g[0].end(); i++) { n     int temp = 0, mp; n     for (set<int>::iterator j = g[0].begin(); j != g[0].end(); j++) { n       if (g[*i].count(*j)) { n         temp++; n         mp = *j; n       } n     } n     if (temp == 1 && n > 6 || temp && n < 7) { n       st = *i; n       p = mp; n       break; n     } n   } n   if (p == -1) { n     puts( -1 ); n     return 0; n   } n   ans.push_back(p); n   used[p] = true; n   dfs(st, p); n   if (ans.size() != n) { n     puts( -1 ); n     return 0; n   } n   for (int i = 0; i < ans.size(); i++) { n     printf( %d  , ans[i] + 1); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   double t, n, i, x, mx, mn, f, j, s, r, y, c, m, n       k = 0, W, H, x1, y1, w, h, w1, h1, l, u, d, sw, sh, X, Y, X1, X2, R; n   cin >> t; n   while (t--) { n     cin >> W >> H; n     cin >> x >> y >> x1 >> y1; n     cin >> w >> h; n     w1 = abs(x - x1); n     h1 = abs(y - y1); n     sw = W - w1; n     sh = H - h1; n     if (sw < w && sh < h) n       cout << -1 << endl; n     else { n       r = W - x1; n       l = x; n       u = H - y1; n       d = y; n       if (max(r, l) >= w || max(u, d) >= h) n         printf( %0.7lf n , k); n       else { n         X = max(r, l); n         Y = max(u, d); n         X = w - X; n         Y = h - Y; n         if (X > min(r, l)) n           R = Y; n         else if (Y > min(u, d)) n           R = X; n         else n           R = min(X, Y); n         printf( %0.7lf n , R); n       } n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e6 + 7; n const int maxm = 2e1 + 7; n int n, m; n int ar[maxn]; n char ch[maxn]; n int main() { n   int k; n   scanf( %d%d , &n, &k); n   int d = (n - k) / 2; n   for (int i = 0; i < n; i++) { n     ch[i] =  0  + (i % (d + 1) == d); n   } n   printf( %s n , ch); n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC diagnostic ignored  -Wunused-result  n #pragma GCC diagnostic ignored  -Wunused-function  n using namespace std; n namespace { n namespace shik { n template <class T> n void _R(T &x) { n   cin >> x; n } n void _R(int &x) { scanf( %d , &x); } n void _R(int64_t &x) { scanf( %  SCNd64, &x); } n void _R(double &x) { scanf( %lf , &x); } n void _R(char &x) { scanf(  %c , &x); } n void _R(char *x) { scanf( %s , x); } n void R() {} n template <class T, class... U> n void R(T &head, U &...tail) { n   _R(head); n   R(tail...); n } n template <class T> n void _W(const T &x) { n   cout << x; n } n void _W(const int &x) { printf( %d , x); } n void _W(const int64_t &x) { printf( %  PRId64, x); } n void _W(const double &x) { printf( %.16f , x); } n void _W(const char &x) { putchar(x); } n void _W(const char *x) { printf( %s , x); } n template <class T> n void _W(const vector<T> &x) { n   for (auto i = x.begin(); i != x.end(); _W(*i++)) n     if (i != x.cbegin()) putchar(   ); n } n void W() {} n template <class T, class... U> n void W(const T &head, const U &...tail) { n   _W(head); n   putchar(sizeof...(tail) ?     :   n ); n   W(tail...); n } n template <class T, class F = less<T>> n void sort_uniq(vector<T> &v, F f = F()) { n   sort(begin(v), end(v), f); n   v.resize(unique(begin(v), end(v)) - begin(v)); n } n template <class T> n inline T bit(T x, int i) { n   return (x >> i) & 1; n } n template <class T> n inline bool chkmax(T &a, const T &b) { n   return b > a ? a = b, true : false; n } n template <class T> n inline bool chkmin(T &a, const T &b) { n   return b < a ? a = b, true : false; n } n template <class T> n using MaxHeap = priority_queue<T>; n template <class T> n using MinHeap = priority_queue<T, vector<T>, greater<T>>; n const int N = 1e5 + 10; n int n, k; n vector<int> e[N]; n void make_tree(int p) { n   for (int i : e[p]) { n     e[i].erase(find(begin(e[i]), end(e[i]), p)); n     make_tree(i); n   } n } n pair<int, int> go(int p) { n   int s = 0, r = 0, a1 = 0, a2 = 0; n   for (int i : e[p]) { n     auto t = go(i); n     s += t.first; n     int x = t.second; n     if (x >= a1) { n       a2 = a1; n       a1 = x; n     } else if (x >= a2) { n       a2 = x; n     } n   } n   if (a1 + a2 + 1 >= k) { n     s++; n   } else { n     r = a1 + 1; n   } n   return {s, r}; n } n int shik(int _k) { n   k = _k; n   return go(1).first; n } n int ans[N]; n void solve(int l, int r, int al, int ar) { n   if (r - l <= 1) return; n   if (al == ar) { n     for (int i = (l); i <= int(r); i++) ans[i] = al; n     return; n   } n   int m = (l + r) / 2; n   int am = shik(m); n   ans[m] = am; n   solve(l, m, al, am); n   solve(m, r, am, ar); n } n void main() { n   R(n); n   for (int i = 0; i < int(n - 1); i++) { n     int a, b; n     R(a, b); n     e[a].push_back(b); n     e[b].push_back(a); n   } n   make_tree(1); n   ans[1] = n; n   solve(1, n + 1, n, 0); n   for (int i = (1); i <= int(n); i++) W(ans[i]); n } n }  // namespace shik n }  // namespace n int main() { n   shik::main(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool adj[110][110]; n short color[110]; n bool ok = true; n int n, m; n void dfs(int node, int ccolor) { n   color[node] = ccolor; n   for (int i = 0; i < m; i++) { n     if (adj[node][i]) { n       if (color[i] == 0) { n         dfs(i, ccolor * (-1)); n       } else if (color[i] == ccolor) { n         ok = false; n       } n     } n   } n } n int main() { n   cin >> n >> m; n   int ai[110], bi[110], a, b, i, j; n   for (i = 0; i < m; i++) { n     cin >> ai[i] >> bi[i]; n     if (bi[i] < ai[i]) swap(ai[i], bi[i]); n   } n   int x1, x2, y1, y2; n   for (i = 0; i < m; i++) { n     for (j = i + 1; j < m; j++) { n       if (ai[i] > ai[j] && ai[i] < bi[j] && bi[i] > bi[j]) n         adj[i][j] = adj[j][i] = 1; n       if (ai[j] > ai[i] && ai[j] < bi[i] && bi[j] > bi[i]) n         adj[i][j] = adj[j][i] = 1; n     } n   } n   for (i = 0; i < m; i++) { n     if (color[i] == 0) dfs(i, 1); n   } n   if (ok) { n     for (i = 0; i < m; i++) { n       if (color[i] == 1) n         cout <<  i ; n       else if (color[i] == -1) n         cout <<  o ; n     } n   } else { n     cout <<  Impossible  << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long int; n using ld = long double; n template <typename Arg1> n void debug_out(const char* name, Arg1&& arg1) { n   cerr << name <<   =   << arg1 <<   ]  n        <<   n ; n } n template <typename Arg1, typename... Args> n void debug_out(const char* names, Arg1&& arg1, Args&&... args) { n   const char* comma = strchr(names + 1,  , ); n   cerr.write(names, comma - names) <<   =   << arg1 <<  , ; n   debug_out(comma + 1, args...); n } n const long long mod = 1e9 + 7; n const long long N = 5e3 + 5, M = 2e5 + 5; n long long n; n long long v[N]; n long long solve(long long l, long long r) { n   if (r < l) return 0; n   long long res = r - l + 1; n   long long mn = *min_element(v + l, v + r + 1); n   for (long long i = (l); i <= (r); ++i) v[i] -= mn; n   long long ans = mn; n   for (long long i = (l); i <= (r); ++i) { n     if (v[i] == 0) { n       ans += solve(l, i - 1); n       l = i + 1; n     } n   } n   ans += solve(l, r); n   res = min(res, ans); n   return res; n } n void Solve_main() { n   cin >> n; n   for (long long i = (1); i <= (n); ++i) cin >> v[i]; n   cout << solve(1, n) <<   n ; n } n int32_t main() { n   ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); n   srand(chrono::high_resolution_clock::now().time_since_epoch().count()); n   long long tc = 1; n   for (long long i = 1; i <= tc; i++) { n     Solve_main(); n   } n   cerr <<  [time:  << 1.0 * clock() / CLOCKS_PER_SEC <<  s]  ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<pair<long long, long long> > v; n vector<long long> q; n int main() { n   long long n, d, a, b, xx, x, y, sum = 0; n   cin >> n >> d >> a >> b; n   for (long long i = 0; i < n; i++) { n     cin >> x >> y; n     xx = x * a + y * b; n     v.push_back(make_pair(xx, i)); n   } n   sort(v.begin(), v.end()); n   for (long long i = 0; i < n; i++) { n     if (v[i].first + sum <= d) { n       q.push_back(v[i].second); n       sum += v[i].first; n     } else n       break; n   } n   n = q.size(); n   cout << n << endl; n   for (long long i = 0; i < n; i++) { n     cout << q[i] + 1 <<    ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 1e9 + 7; n const long long INFL = 1e18 + 123; n const double PI = atan2(0, -1); n mt19937 tw(960172); n long long rnd(long long x, long long y) { n   static uniform_int_distribution<long long> d; n   return d(tw) % (y - x + 1) + x; n } n const int MAXN = 1e5 + 5; n vector<int> graph[MAXN], graph2[MAXN]; n int res[MAXN]; n bool used[MAXN]; n int dfs(int v, vector<int>* g, int c) { n   used[v] = true; n   if (res[v] == 1 - c) { n     cout <<  No n ; n     exit(0); n   } n   res[v] = c; n   for (int to : g[v]) { n     if (!used[to]) { n       dfs(to, g, c); n     } n   } n   return 0; n } n int main() { n   cerr << fixed << setprecision(15); n   cout << fixed << setprecision(15); n   int n, m; n   scanf( %d%d , &n, &m); n   vector<vector<int>> inp; n   for (int i = 0; i < n; ++i) { n     int l; n     scanf( %d , &l); n     inp.push_back({}); n     for (int j = 0; j < l; ++j) { n       int num; n       scanf( %d , &num); n       --num; n       inp.back().push_back(num); n     } n   } n   for (int i = 0; i < m; ++i) { n     res[i] = 2; n   } n   for (int i = 0; i < n - 1; ++i) { n     bool flag = false; n     for (int j = 0; j < min(((int)(inp[i]).size()), ((int)(inp[i + 1]).size())); n          ++j) { n       if (inp[i][j] != inp[i + 1][j]) { n         flag = true; n         if (inp[i][j] > inp[i + 1][j]) { n           if (res[inp[i][j]] == 1 || res[inp[i + 1][j]] == 0) { n             cout <<  No n ; n             return 0; n           } n           res[inp[i][j]] = 0; n           res[inp[i + 1][j]] = 1; n         } else { n           graph[inp[i + 1][j]].push_back(inp[i][j]); n           graph2[inp[i][j]].push_back(inp[i + 1][j]); n         } n         break; n       } n     } n     if (!flag && ((int)(inp[i]).size()) > ((int)(inp[i + 1]).size())) { n       cout <<  No n ; n       return 0; n     } n   } n   for (int i = 0; i < m; ++i) { n     if (res[i] == 0 && !used[i]) { n       dfs(i, graph, res[i]); n     } n     if (res[i] == 1 && !used[i]) { n       dfs(i, graph2, res[i]); n     } n   } n   cout <<  Yes n ; n   vector<int> ans; n   for (int i = 0; i < m; ++i) { n     if (res[i] == 0) { n       ans.push_back(i); n     } n   } n   cout << ((int)(ans).size()) <<   n ; n   for (int num : ans) { n     cout << num + 1 <<    ; n   } n   cout <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   for (int row = -n; row <= n; ++row) { n     int top = n - abs(row); n     for (int i = 0; i < abs(row); i++) { n       cout <<     ; n     } n     for (int i = 0; i < top; i++) { n       cout << i <<    ; n     } n     for (int i = top; i > 0; i--) { n       cout << i <<    ; n     } n     cout << 0 << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<pair<int, int> > adj[100005]; n int m, n, a, b, w; n long long D[100005]; n int Tr[100005]; n void dijk(int x) { n   Tr[x] = 0; n   D[x] = 0; n   set<pair<long long, int> > s; n   s.insert({0, x}); n   while (s.size() > 0) { n     long long d = (*s.begin()).first; n     int u = (*s.begin()).second; n     s.erase(s.begin()); n     for (int i = 0; i < adj[u].size(); ++i) { n       int v = adj[u][i].second; n       int w = adj[u][i].first; n       if (D[v] > D[u] + w) { n         D[v] = D[u] + w; n         s.insert({D[v], v}); n         Tr[v] = u; n       } n     } n   } n } n int main() { n   cin >> n >> m; n   for (int i = 1; i <= m; ++i) { n     cin >> a >> b >> w; n     adj[a].push_back({w, b}); n     adj[b].push_back({w, a}); n   } n   memset(D, 63, sizeof(D)); n   dijk(1); n   if (D[n] > 1e12) { n     cout << -1; n     return 0; n   } n   vector<int> p; n   int t = n; n   while (t > 0) { n     p.push_back(t); n     t = Tr[t]; n   } n   reverse(p.begin(), p.end()); n   for (int i = 0; i < p.size(); ++i) cout << p[i] <<    ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline void out(int a) { printf( %d n , a); } n inline void out(int a, int b) { printf( %d %d n , a, b); } n inline void outf(double a) { printf( %3.lf n , a); } n inline void outf(double a, double b) { printf( %3.lf %3.lf n , a, b); } n inline void base() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n } n int tour(vector<int> ls) { n   while (ls.size() != 1) { n     vector<int> nx; n     for (int i = 0; i < ls.size(); i += 2) { n       if (i + 1 == ls.size()) { n         nx.push_back(ls[i]); n         break; n       } n       cout <<  ?   << ls[i] <<     << ls[i + 1] << endl; n       char c; n       cin >> c; n       if (c ==  > ) { n         nx.push_back(ls[i]); n       } else if (c ==  < ) { n         nx.push_back(ls[i + 1]); n       } else if (c ==  = ) { n         nx.push_back(ls[i]); n       } n     } n     ls = nx; n   } n   return ls[0]; n } n int tour1(vector<int> ls) { n   while (ls.size() != 1) { n     vector<int> nx; n     for (int i = 0; i < ls.size(); i += 2) { n       if (i + 1 == ls.size()) { n         nx.push_back(ls[i]); n         break; n       } n       cout <<  ?   << ls[i] <<     << ls[i + 1] << endl; n       char c; n       cin >> c; n       if (c ==  > ) { n         nx.push_back(ls[i + 1]); n       } else if (c ==  < ) { n         nx.push_back(ls[i]); n       } else if (c ==  = ) { n         nx.push_back(ls[i]); n       } n     } n     ls = nx; n   } n   return ls[0]; n } n int main() { n   base(); n   int t; n   cin >> t; n   while (t--) { n     int n; n     cin >> n; n     if (n == 1) { n       cout <<  ! 1 1  << endl; n       continue; n     } n     vector<int> lose; n     vector<int> win; n     for (int i = 1; i <= n; i += 2) { n       if (i + 1 <= n) { n         cout <<  ?   << i <<     << i + 1 << endl; n         char c; n         cin >> c; n         if (c ==  > ) { n           win.push_back(i); n           lose.push_back(i + 1); n         } else if (c ==  < ) { n           win.push_back(i + 1); n           lose.push_back(i); n         } else { n           win.push_back(i); n           lose.push_back(i); n         } n       } else { n         win.push_back(i); n         lose.push_back(i); n       } n     } n     int mx = tour(win), mn = tour1(lose); n     cout <<  !   << mn <<     << mx << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX = 173, MAX2 = 400; n const int foo = INT_MIN; n char s[MAX]; n int slen, l, an[MAX]; n int B[MAX][MAX], F[MAX][MAX], R[MAX][MAX][MAX]; n bool hh[MAX][MAX]; n inline bool good(int i, int j) { return i <= j; } n int full(int i, int j); n int best(int i, int j) { n   auto &ele = B[i][j]; n   if (ele != -1) n     return ele; n   else { n     if (i == j) { n       if (an[1] != -1) n         return ele = an[1]; n       else n         return ele = 0; n     } else { n       ele = full(i, j); n       for (int r = (i); r <= (j); ++r) { n         ele = max(ele, (good(i, r - 1) ? best(i, r - 1) : 0) + n                            (good(r + 1, j) ? best(r + 1, j) : 0)); n       } n       return ele; n     } n   } n } n int resi(int i, int j, int re); n int full(int i, int j) { n   auto &ele = F[i][j]; n   if (ele != -1) n     return ele; n   else { n     if (i == j) { n       if (an[1] == -1) n         return ele = foo; n       else n         return ele = an[1]; n     } else { n       int len = j - i + 1; n       ele = foo; n       for (int re = (1); re <= (len); ++re) { n         if (resi(i, j, re) != foo && an[re] != -1) { n           ele = max(resi(i, j, re) + an[re], ele); n         } n       } n       return ele; n     } n   } n } n int resi(int i, int j, int re) { n   auto &ele = R[i][j][re]; n   if (ele != -1) n     return ele; n   else { n     if (i == j) { n       return ele = 0; n     } else { n       int len = j - i + 1; n       if (len == re) { n         if (hh[i][j]) n           return ele = 0; n         else n           return ele = foo; n       } else { n         if (re == 1) { n           ele = foo; n           for (int pos = (i); pos <= (j); ++pos) { n             int l = pos == i ? 0 : full(i, pos - 1); n             if (l != foo) { n               int r = pos == j ? 0 : full(pos + 1, j); n               if (r != foo) { n                 ele = max(ele, l + r); n               } n             } n           } n           return ele; n         } else { n           ele = foo; n           for (int bl = (i + 1); bl <= (j + 1 - re); ++bl) { n             int tmp = full(i, bl - 1); n             if (tmp != foo) { n               int tmp2 = resi(bl, j, re); n               if (tmp2 != foo) { n                 ele = max(ele, tmp + tmp2); n               } n             } n           } n           for (int bl = (j - 1); bl >= (re + i - 1); --bl) { n             int tmp = full(bl + 1, j); n             if (tmp != foo) { n               int tmp2 = resi(i, bl, re); n               if (tmp2 != foo) { n                 ele = max(ele, tmp + tmp2); n               } n             } n           } n           if (s[i] == s[j]) n             ele = max(ele, re - 2 == 0 ? full(i + 1, j - 1) n                                        : resi(i + 1, j - 1, re - 2)); n           return ele; n         } n       } n     } n   } n } n int main() { n   scanf( %d , &l); n   for (int i = (1); i <= (l); ++i) scanf( %d , &an[i]); n   scanf( %s , s); n   slen = strlen(s); n   memset(B, -1, sizeof(B)), memset(F, -1, sizeof(F)), memset(R, -1, sizeof(R)); n   for (int i = (0); i <= (slen - 1); ++i) { n     for (int j = (i); j <= (slen - 1); ++j) { n       if (i == j) n         hh[i][j] = 1; n       else { n         int mid = (i + j) / 2; n         hh[i][j] = 1; n         for (int k = (i); k <= (mid); ++k) { n           int rk = j - k + i; n           if (s[k] != s[rk]) { n             hh[i][j] = 0; n             break; n           } n         } n       } n     } n   } n   printf( %d n , best(0, slen - 1)); n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize(3) n using namespace std; n struct IO { n   char buf[(1 << 20)], *p1, *p2; n   char pbuf[(1 << 20)], *pp; n   IO() : p1(buf), p2(buf), pp(pbuf) {} n   ~IO() { fwrite(pbuf, 1, pp - pbuf, stdout); } n   inline char gc() { n     if (p1 == p2) p2 = (p1 = buf) + fread(buf, 1, (1 << 20), stdin); n     return p1 == p2 ?     : *p1++; n   } n   inline bool blank(char ch) { n     return ch ==     || ch ==   n  || ch ==   r  || ch ==   t ; n   } n   template <class T> n   inline void read(T &x) { n     double tmp = 1; n     bool sign = 0; n     x = 0; n     char ch = gc(); n     for (; !(ch >=  0  && ch <=  9 ); ch = gc()) n       if (ch ==  - ) sign = 1; n     for (; (ch >=  0  && ch <=  9 ); ch = gc()) x = x * 10 + (ch -  0 ); n     if (ch ==  . ) n       for (ch = gc(); (ch >=  0  && ch <=  9 ); ch = gc()) n         tmp /= 10.0, x += tmp * (ch -  0 ); n     if (sign) x = -x; n   } n   inline void read(char *s) { n     char ch = gc(); n     for (; blank(ch); ch = gc()) n       ; n     for (; !blank(ch); ch = gc()) *s++ = ch; n     *s = 0; n   } n   inline void read(char &c) { n     for (c = gc(); blank(c); c = gc()) n       ; n   } n   inline void push(const char &c) { n     if (pp - pbuf == (1 << 20)) fwrite(pbuf, 1, (1 << 20), stdout), pp = pbuf; n     *pp++ = c; n   } n   template <class T> n   inline void write(T x) { n     if (x < 0) x = -x, push( - ); n     static T sta[35]; n     T top = 0; n     do { n       sta[top++] = x % 10, x /= 10; n     } while (x); n     while (top) push(sta[--top] +  0 ); n   } n   template <class T> n   inline void write(T x, char lastChar) { n     write(x), push(lastChar); n   } n } io; n constexpr long long N = 1e5 + 5; n constexpr double eps = 1e-6; n long long n, k, m, d; n long long id[64]; n long long v[64]; n long long Q; n long long level(long long x) { n   long long ans = 0; n   while (x) { n     ans++; n     x >>= 1LL; n   } n   return ans; n } n signed main() { n   ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); n   ; n   cin >> Q; n   while (Q--) { n     long long T; n     cin >> T; n     if (T == 1LL) { n       long long X, K; n       cin >> X >> K; n       long long l = level(X); n       long long M = (1LL << (l - 1LL)); n       v[l] += K % M; n       v[l] %= M; n       if (v[l] < 0) v[l] += M; n     } else if (T == 2) { n       long long X, K; n       cin >> X >> K; n       long long l = level(X); n       while (l < 64) { n         long long M = (1LL << (l - 1LL)); n         K %= M; n         v[l] += K % M; n         v[l] %= M; n         if (v[l] < 0) v[l] += M; n         id[l] += K % M; n         id[l] %= M; n         if (id[l] < 0) id[l] += M; n         l++; n         K *= 2; n       } n     } else { n       long long X; n       cin >> X; n       cout << X <<    ; n       long long l = level(X); n       long long M = 1LL << (l - 1LL); n       X -= M; n       long long rawid = (X + v[l] + M) % M; n       long long nowid = (rawid + id[l] + M) % M; n       while (M + rawid != 1LL) { n         rawid = (M + rawid) >> 1LL; n         M >>= 1LL; n         l--; n         rawid -= M; n         cout << M + (rawid - v[l] + M) % M <<    ; n       } n       cout << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace ::std; n const long long maxn = 5e5 + 500; n long long seg[4 * maxn]; n long long dp[maxn]; n long long q[maxn]; n long long houp[maxn]; n long long a[maxn]; n map<long long, long long> last; n map<long long, vector<long long> > las; n void bild() { fill(seg, seg + 4 * maxn, -1); } n void update(long long L, long long R, long long node, long long l, long long r, n             long long v) { n   if (l <= L && R <= r) { n     seg[node] = max(seg[node], v); n     return; n   } n   if (r <= L || R <= l) { n     return; n   } n   seg[2 * node] = max(seg[2 * node], seg[node]); n   seg[2 * node + 1] = max(seg[2 * node + 1], seg[node]); n   long long mid = (L + R) / 2; n   update(L, mid, 2 * node, l, r, v); n   update(mid, R, 2 * node + 1, l, r, v); n } n long long findd(long long L, long long R, long long node, long long x) { n   long long mid = (L + R) / 2; n   if (L + 1 == R) { n     return seg[node]; n   } n   if (x < mid) { n     return max(seg[node], findd(L, mid, 2 * node, x)); n   } else { n     return max(seg[node], findd(mid, R, 2 * node + 1, x)); n   } n } n int main() { n   long long n; n   cin >> n; n   for (long long i = 0; i < n; i++) { n     cin >> a[i]; n   } n   bild(); n   for (long long i = 0; i < n; i++) { n     long long v = a[i]; n     if (last.count(v) > 0) { n       q[i] = findd(0, n, 1, last[v]); n       update(0, n, 1, last[v] + 1, i, last[v]); n     } else { n       q[i] = -1; n     } n     last[v] = i; n   } n   for (long long i = 0; i < n; i++) { n     long long v = a[i]; n     las[v].push_back(i); n     if (las[v].size() >= 4) { n       q[i] = max(q[i], las[v][las[v].size() - 4]); n     } n   } n   dp[0] = 0; n   houp[0] = -1; n   for (long long i = 1; i < n; i++) { n     if (q[i] == -1) { n       houp[i] = -1; n       dp[i] = dp[i - 1]; n     } else { n       if (q[i] == 0) { n         dp[i] = max(dp[i - 1], 1LL); n       } else { n         dp[i] = max(dp[i - 1], 1 + dp[q[i] - 1]); n       } n       if (dp[i] == dp[i - 1]) { n         houp[i] = -1; n       } else { n         houp[i] = q[i]; n       } n     } n   } n   cout << 4 * dp[n - 1] << endl; n   vector<long long> stk; n   long long p = n - 1; n   while (p >= 0) { n     if (houp[p] == -1) { n       p--; n     } else { n       stk.push_back(a[p]); n       stk.push_back(a[houp[p]]); n       stk.push_back(a[p]); n       stk.push_back(a[houp[p]]); n       p = houp[p] - 1; n     } n   } n   reverse(stk.begin(), stk.end()); n   for (long long i = 0; i < stk.size(); i++) { n     cout << stk[i] <<    ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 100010; n int m, n, nword, R[MAXN], len[MAXN]; n map<string, int> M; n string s[MAXN]; n vector<int> adj[MAXN], adj2[MAXN]; n int super[MAXN], nsuper, number[MAXN], low[MAXN], cnt; n int best[MAXN], rep[MAXN]; n bool inStack[MAXN]; n int st[MAXN], nst; n int f[MAXN]; n long long resR, resLen; n void toLower(string& s) { n   for (int i = 0; i < s.size(); i++) { n     s[i] = tolower(s[i]); n   } n } n int countR(string s) { n   int ret = 0; n   for (int i = 0; i < s.size(); i++) { n     ret += s[i] ==  r ; n   } n   return ret; n } n void add(string& s) { n   toLower(s); n   if (M[s] == 0) M[s] = ++nword; n   int x = M[s]; n   len[x] = s.length(); n   R[x] = countR(s); n } n void input() { n   scanf( %d , &m); n   for (int i = 1; i <= m; i++) { n     cin >> s[i]; n     add(s[i]); n   } n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) { n     string tmp; n     int u, v; n     cin >> tmp; n     add(tmp); n     u = M[tmp]; n     cin >> tmp; n     add(tmp); n     v = M[tmp]; n     adj[u].push_back(v); n   } n } n void tarjan(int u) { n   number[u] = ++cnt; n   low[u] = number[u]; n   inStack[u] = true; n   st[++nst] = u; n   for (int i = 0; i < adj[u].size(); i++) { n     int v = adj[u][i]; n     if (number[v] == 0) { n       tarjan(v); n       low[u] = min(low[u], low[v]); n     } else if (inStack[v]) n       low[u] = min(low[u], number[v]); n   } n   if (low[u] == number[u]) { n     nsuper++; n     best[nsuper] = u; n     super[u] = nsuper; n     inStack[u] = false; n     while (st[nst] != u) { n       int v = st[nst--]; n       super[v] = nsuper; n       inStack[v] = false; n       if (R[v] < R[best[nsuper]] || n           (R[v] == R[best[nsuper]] && len[v] < len[best[nsuper]])) n         best[nsuper] = v; n     } n     nst--; n   } n } n void dfs(int u) { n   f[u] = best[u]; n   for (int i = 0; i < adj2[u].size(); i++) { n     int v = adj2[u][i]; n     if (f[v] == 0) dfs(v); n     if (R[f[v]] < R[f[u]] || (R[f[v]] == R[f[u]] && len[f[v]] < len[f[u]])) n       f[u] = f[v]; n   } n } n void solve() { n   for (int i = 1; i <= nword; i++) { n     if (number[i] == 0) tarjan(i); n   } n   for (int i = 1; i <= nword; i++) { n     for (int j = 0; j < adj[i].size(); j++) { n       int v = adj[i][j]; n       if (super[i] != super[v]) adj2[super[i]].push_back(super[v]); n     } n   } n   for (int i = 1; i <= nword; i++) { n     if (f[i] == 0) dfs(i); n   } n   for (int i = 1; i <= m; i++) { n     int id = M[s[i]]; n     resR += R[f[super[id]]]; n     resLen += len[f[super[id]]]; n   } n } n void output() { printf( %I64d %I64d , resR, resLen); } n int main() { n   input(); n   solve(); n   output(); n } n


#include <bits/stdc++.h> n using namespace std; n map<int, bool> mp; n int main() { n   int n; n   cin >> n; n   for (int i = 0; i < n; i++) { n     int a; n     cin >> a; n     mp[a] = 1; n   } n   for (int i = 0; i < 1010; i++) { n     if (mp[i] && mp[i + 1] && mp[i + 2]) { n       cout <<  YES  << endl; n       return 0; n     } n   } n   cout <<  NO  << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = 0x3f3f3f3f; n char s[1010]; n int a[1010], num[1010], b[30]; n int prime[1010], notprime[1010]; n priority_queue<pair<int, char> > pq; n set<pair<int, int> > st; n pair<int, int> c[1010]; n int ans[1010]; n int cnt; n void init() { n   for (int i = 2; i <= 1000; i++) { n     if (!notprime[i]) prime[cnt++] = i; n     for (int j = 0; j < cnt && i * prime[j] <= 1000; j++) { n       notprime[i * prime[j]] = 1; n       if (i % prime[j] == 0) break; n     } n   } n   for (int i = 0; i <= 1000; i++) a[i] = i, num[i] = 1; n } n int get(int x) { return a[x] == x ? x : a[x] = get(a[x]); } n void merge(int x, int y) { n   int t1 = get(x); n   int t2 = get(y); n   if (t1 != t2) { n     a[max(t1, t2)] = min(t1, t2); n     num[min(t1, t2)] += num[max(t1, t2)]; n   } n } n bool cmp(pair<int, int> x, pair<int, int> y) { return x.first > y.first; } n int main() { n   init(); n   scanf( %s , s); n   int l = strlen(s); n   for (int i = 0; i < l; i++) b[s[i] -  a ]++; n   for (int i = 0; i < 30; i++) n     if (b[i]) pq.push({b[i], i +  a }); n   for (int i = 0; i < cnt && prime[i] <= l; i++) n     for (int j = 2; j <= l / prime[i]; j++) merge(prime[i], j * prime[i]); n   st.insert({1, 1}); n   for (int i = 0; i < cnt && prime[i] <= l; i++) { n     int r = get(prime[i]); n     st.insert({num[r], r}); n   } n   int num = 0, j = 0; n   for (auto i : st) c[num++] = i; n   sort(c, c + num, cmp); n   int flag = 0; n   while (pq.size() && j < num) { n     pair<int, char> t = pq.top(); n     pq.pop(); n     if (t.first >= c[j].first) n       ans[c[j].second] = t.second -  a ; n     else { n       flag = 1; n       break; n     } n     if (t.first - c[j].first > 0) pq.push({t.first - c[j].first, t.second}); n     j++; n   } n   if (flag) n     printf( NO n ); n   else { n     printf( YES n ); n     for (int i = 1; i <= l; i++) printf( %c , ans[get(i)] +  a ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long mod = 1e9 + 7; n template <typename T> n T gcd(T a, T b) { n   T c; n   while (b) { n     c = b; n     b = a % b; n     a = c; n   } n   return a; n } n template <typename T> n T powmod(T a, T b) { n   T res = 1; n   a %= mod; n   while (b) { n     if (b & 1) res = res * (a % mod); n     a = a * (a % mod); n     b >>= 1; n   } n   return res; n } n void Solve() { n   int n, m; n   cin >> n >> m; n   char grid[120][120]; n   for (int i = 0; i < n; ++i) { n     for (int j = 0; j < m; ++j) { n       cin >> grid[i][j]; n     } n   } n   for (int i = 0; i < n; ++i) { n     for (int j = 0; j < m; ++j) { n       if (grid[i][j] ==  B ) { n         if (j + 1 == m) { n           cout << i + 1 <<     << j + 1 <<   n ; n           return; n         } else { n           int k; n           for (k = j + 1; k < m; ++k) { n             if (grid[i][k] !=  B ) break; n           } n           int a = k - j + 1; n           cout << i + (a / 2) <<     << j + (a / 2) <<   n ; n           return; n         } n       } n     } n   } n } n int main() { n   std::ios::sync_with_stdio(false); n   std::cin.tie(nullptr); n   Solve(); n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 7; n pair<long long, long long> res; n long long a[N]; n void dfs(long long cur, long long cnt, long long sum) { n   if (!cur) { n     res = max(res, {cnt, sum}); n     return; n   } else { n     int p = upper_bound(a + 1, a + N, cur) - a; n     --p; n     dfs(cur - a[p], cnt + 1, sum + a[p]); n     if (p > 1) dfs(a[p] - 1 - a[p - 1], cnt + 1, sum + a[p - 1]); n   } n } n int main() { n   for (int i = 1; i <= N - 1; ++i) a[i] = 1ll * i * i * i; n   long long m; n   scanf( %lld , &m); n   dfs(m, 0, 0); n   printf( %lld %lld n , res.first, res.second); n   return 0; n } n


#include <bits/stdc++.h> n int cmpfnc(const void* a, const void* b) { return (*(int*)a - *(int*)b); } n int main() { n   int i, n; n   scanf( %d , &n); n   int arr[300005]; n   for (i = 0; i < n; i++) scanf( %d , &arr[i]); n   qsort(arr, n, sizeof(int), cmpfnc); n   long long int sum = arr[0]; n   long long int count = 1; n   long long int t2 = 0; n   for (i = 1; i < n; i++) { n     long long int t3 = n         ((count % 1000000007) * (arr[i] % 1000000007)) % 1000000007; n     t2 = (t2 + (t3 - sum + 1000000007) % 1000000007) % 1000000007; n     sum = (sum * 2 + arr[i]) % 1000000007; n     count = (count * 2 + 1) % 1000000007; n   } n   printf( %lld n , t2); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string str, s1, s2 =  < ; n   stack<char> delm; n   vector<string> re; n   getline(cin, str); n   for (int i = 0; i < str.size(); i++) { n     if (str[i] ==     && delm.empty()) { n       s1 =  < ; n       delm.push(str[i]); n     } else if (!delm.empty()) { n       char ch = delm.top(); n       if (ch == str[i]) { n         s1 +=  *> ; n         re.push_back(s1); n         delm.pop(); n       } else n         s1 += str[i]; n     } else if (delm.empty()) { n       if (str[i] ==     && s2.size() > 1) { n         s2 +=  *> ; n         re.push_back(s2); n         s2 =  < ; n       } else if (str[i] !=    ) { n         s2 += str[i]; n       } n       if (i == str.size() - 1 && str[str.size() - 1] !=    ) { n         s2 +=  *> ; n         re.push_back(s2); n         s2 =  < ; n         continue; n       } n     } n   } n   for (int i = 0; i < re.size(); i++) { n     bool flag = false; n     for (int j = 1; j < re[i].size() - 1; j++) n       if (re[i][j] !=     || re[i][re[i].size() - 1] ==  * ) { n         flag = true; n         re[i] = n             re[i].substr(0, re[i].size() - 2) + re[i].substr(re[i].size() - 1); n         break; n       } n     if (flag) cout << re[i] << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize(3) n inline void read(int &x) { scanf( %d , &x); } n inline void read(long long &x) { scanf( %I64d , &x); } n inline void read(double &x) { scanf( %lf , &x); } n inline void read(long double &x) { n   double tmp; n   read(tmp); n   x = tmp; n } n template <class T> n inline void read(T *a, int n) { n   for (int i = (0); i < (n); ++i) read(a[i]); n } n inline void write(int x) { printf( %d , x); } n inline void write(long long x) { printf( %I64d , x); } n inline void write(double x) { printf( %.10lf , x); } n inline void write(long double x) { printf( %.10lf , (double)x); } n template <class T> n inline void writeln(T x) { n   write(x); n   putchar(  n ); n } n template <class T> n inline void writeln(T *a, int n) { n   for (int i = (0); i < (n); ++i) { n     write(a[i]); n     putchar(   ); n   } n   putchar(  n ); n } n template <class T> n inline void writelnln(T *a, int n) { n   for (int i = (0); i < (n); ++i) writeln(a[i]); n } n int A[5]; n std::set<int> res[5][5]; n inline void calc(int l, int r) { n   std::set<int> &S = res[l][r]; n   S.clear(); n   if (l == r) { n     S.insert(A[l]); n     S.insert(-A[l]); n   } else { n     for (int m = (l); m < (r); ++m) { n       std::set<int> &a = res[l][m], &b = res[m + 1][r]; n       for (__typeof(a.begin()) aa = a.begin(); aa != a.end(); ++aa) n         for (__typeof(b.begin()) bb = b.begin(); bb != b.end(); ++bb) { n           S.insert(*aa + *bb); n           S.insert(*aa - *bb); n           S.insert(*aa * *bb); n           S.insert(-*aa + *bb); n           S.insert(-*aa - *bb); n           S.insert(-*aa * *bb); n         } n     } n   } n } n std::set<int> ANS; n char buf[3000007], *cb = buf; n int main() { n   int k, m; n   read(k); n   read(m); n   for (int ls = (0); ls < (10000); ++ls) { n     A[0] = ls / 1000; n     A[1] = ls / 100 % 10; n     A[2] = ls / 10 % 10; n     A[3] = ls % 10; n     calc(0, 0); n     calc(1, 1); n     calc(2, 2); n     calc(3, 3); n     calc(0, 1); n     calc(1, 2); n     calc(2, 3); n     calc(0, 2); n     calc(1, 3); n     calc(0, 3); n     std::set<int> &ans = res[0][3]; n     for (__typeof(ans.begin()) x = ans.begin(); x != ans.end(); ++x) { n       int ttt = abs(k - *x); n       if (ttt < 10000) { n         ANS.insert(ls * 10000 + ttt); n         if (ANS.size() == m) { n           for (__typeof(ANS.begin()) it = ANS.begin(); it != ANS.end(); ++it) { n             int x = *it; n             *(cb++) = x / 10000000 +  0 ; n             *(cb++) = x / 1000000 % 10 +  0 ; n             *(cb++) = x / 100000 % 10 +  0 ; n             *(cb++) = x / 10000 % 10 +  0 ; n             *(cb++) = x / 1000 % 10 +  0 ; n             *(cb++) = x / 100 % 10 +  0 ; n             *(cb++) = x / 10 % 10 +  0 ; n             *(cb++) = x % 10 +  0 ; n             *(cb++) =   n ; n           } n           fwrite(buf, 1, cb - buf, stdout); n           return 0; n         } n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int N; n signed long long W[303030]; n vector<pair<int, int>> E[303030]; n signed long long best[303030]; n signed long long ma; n void dfs(int cur, int pre) { n   vector<signed long long> C; n   for (auto& e : E[cur]) n     if (e.first != pre) { n       dfs(e.first, cur); n       if (best[e.first] - e.second > 0) C.push_back(best[e.first] - e.second); n     } n   C.push_back(0); n   C.push_back(0); n   sort((C.begin()), (C.end())); n   reverse((C.begin()), (C.end())); n   ma = max(ma, W[cur] + C[0] + C[1]); n   best[cur] = W[cur] + C[0]; n } n void solve() { n   int i, j, k, l, r, x, y; n   string s; n   cin >> N; n   for (i = 0; i < (N); i++) cin >> W[i]; n   for (i = 0; i < (N - 1); i++) { n     cin >> x >> y >> r; n     E[x - 1].push_back({y - 1, r}); n     E[y - 1].push_back({x - 1, r}); n   } n   dfs(0, -1); n   cout << ma << endl; n } n int main(int argc, char** argv) { n   string s; n   int i; n   if (argc == 1) ios::sync_with_stdio(false), cin.tie(0); n   for (i = 0; i < (argc - 1); i++) s += argv[i + 1], s +=   n ; n   for (i = 0; i < (s.size()); i++) ungetc(s[s.size() - 1 - i], stdin); n   cout.tie(0); n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long INF = numeric_limits<long long>::max() / 4; n struct Edge { n   long long from, to, cap, flow, index; n   Edge(long long from, long long to, long long cap, long long flow, n        long long index) n       : from(from), to(to), cap(cap), flow(flow), index(index) {} n   long long rcap() { return cap - flow; } n }; n struct Dinic { n   long long N; n   vector<vector<Edge> > G; n   vector<vector<Edge *> > Lf; n   vector<long long> layer; n   vector<long long> Q; n   Dinic(long long N) : N(N), G(N), Q(N) {} n   void AddEdge(long long from, long long to, long long cap) { n     if (from == to) return; n     G[from].push_back(Edge(from, to, cap, 0, G[to].size())); n     G[to].push_back(Edge(to, from, 0, 0, G[from].size() - 1)); n   } n   long long BlockingFlow(long long s, long long t) { n     layer.clear(); n     layer.resize(N, -1); n     layer[s] = 0; n     Lf.clear(); n     Lf.resize(N); n     long long head = 0, tail = 0; n     Q[tail++] = s; n     while (head < tail) { n       long long first = Q[head++]; n       for (long long i = 0; i < G[first].size(); i++) { n         Edge &e = G[first][i]; n         if (e.rcap() <= 0) continue; n         if (layer[e.to] == -1) { n           layer[e.to] = layer[e.from] + 1; n           Q[tail++] = e.to; n         } n         if (layer[e.to] > layer[e.from]) { n           Lf[e.from].push_back(&e); n         } n       } n     } n     if (layer[t] == -1) return 0; n     long long totflow = 0; n     vector<Edge *> P; n     while (!Lf[s].empty()) { n       long long curr = P.empty() ? s : P.back()->to; n       if (curr == t) { n         long long amt = P.front()->rcap(); n         for (long long i = 0; i < P.size(); ++i) { n           amt = min(amt, P[i]->rcap()); n         } n         totflow += amt; n         for (long long i = P.size() - 1; i >= 0; --i) { n           P[i]->flow += amt; n           G[P[i]->to][P[i]->index].flow -= amt; n           if (P[i]->rcap() <= 0) { n             Lf[P[i]->from].pop_back(); n             P.resize(i); n           } n         } n       } else if (Lf[curr].empty()) { n         P.pop_back(); n         for (long long i = 0; i < N; ++i) n           for (long long j = 0; j < Lf[i].size(); ++j) n             if (Lf[i][j]->to == curr) Lf[i].erase(Lf[i].begin() + j); n       } else { n         P.push_back(Lf[curr].back()); n       } n     } n     return totflow; n   } n   long long GetMaxFlow(long long s, long long t) { n     long long totflow = 0; n     while (long long flow = BlockingFlow(s, t)) totflow += flow; n     return totflow; n   } n }; n long long N, M; n set<long long> pr; n set<long long>::iterator it; n long long a[157], b[157]; n pair<long long, long long> E[157]; n long long get(long long p, long long N) { n   memset(b, 0, sizeof(b)); n   for (long long i = (1); i < (N + 1); i++) { n     while (a[i] % p == 0) { n       b[i]++; n       a[i] /= p; n     } n   } n   Dinic F(N + 7); n   for (long long i = 1; i <= N; i += 2) { n     F.AddEdge(0, i, b[i]); n   } n   for (long long i = 2; i <= N; i += 2) { n     F.AddEdge(i, N + 1, b[i]); n   } n   for (long long i = (0); i < (M); i++) { n     F.AddEdge(E[i].first, E[i].second, min(b[E[i].first], b[E[i].second])); n   } n   return F.GetMaxFlow(0, N + 1); n } n int main() { n   scanf( %lld %lld , &N, &M); n   for (long long i = (1); i < (N + 1); i++) { n     scanf( %lld , &a[i]); n   } n   for (long long i = (0); i < (M); i++) { n     scanf( %lld %lld , &E[i].first, &E[i].second); n     if (E[i].first % 2 == 0) swap(E[i].first, E[i].second); n   } n   for (long long i = (1); i < (N + 1); i++) { n     long long tmp = a[i]; n     if (tmp % 2 == 0) { n       pr.insert(2); n       while (tmp % 2 == 0) { n         tmp /= 2; n       } n     } n     for (long long j = 3; j * j <= tmp; j += 2) { n       if (tmp % j == 0) { n         pr.insert(j); n         while (tmp % j == 0) { n           tmp /= j; n         } n       } n     } n     if (tmp > 1) pr.insert(tmp); n   } n   long long ans = 0; n   for (it = pr.begin(); it != pr.end(); it++) { n     ans += get(*it, N); n   } n   printf( %lld n , ans); n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 3e5 + 5; n int sum[maxn], t, n, q, l, r; n char s[maxn]; n set<int> v[4 * maxn + 10]; n int main() { n   scanf( %d , &t); n   while (t--) { n     sum[0] = 0; n     scanf( %d%d%s , &n, &q, (s + 1)); n     for (int i = 1; i <= n; i++) { n       sum[i] = sum[i - 1] + (s[i] ==  +  ? 1 : -1) * (i & 1 ? 1 : -1); n       v[sum[i - 1] + sum[i] + 2 * maxn].clear(); n     } n     for (int i = 1; i <= n; i++) v[sum[i - 1] + sum[i] + 2 * maxn].insert(i); n     while (q--) { n       scanf( %d%d , &l, &r); n       if (sum[r] == sum[l - 1]) n         printf( 0 n ); n       else { n         int k = r - l + 1; n         if (k % 2 == 0) n           printf( 2 n%d  , l), l++; n         else n           printf( 1 n ); n         printf( %d n , *v[sum[r] + sum[l - 1] + 2 * maxn].lower_bound(l)); n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int base = 1e9; n const int maxn = 1e3; n const int logn = 20; n const int inf = 2e9; n const int alpha = 26; n const int my_hash = 29; n const long long l_inf = 4e18; n const long long mod = 1e9 + 7; n const double pi = acos(-1.0); n const double eps = 1e-9; n int n; n long long x, sum = 0; n vector<long long> a, b; n long long binpow(long long a, long long b) { n   if (!b) return 1; n   if (b % 2) return (binpow(a, b - 1) * a) % mod; n   long long k = binpow(a, b / 2); n   return (k * k) % mod; n } n int main() { n   ios_base::sync_with_stdio(); n   cin >> n >> x; n   a = vector<long long>(n); n   for (int i = int(0); i < int(n); i++) { n     cin >> a[i]; n     sum += a[i]; n   } n   for (int i = int(0); i < int(n); i++) b.push_back(sum - a[i]); n   sort(b.rbegin(), b.rend()); n   while (true) { n     long long cnt = 0, v = b.back(); n     while (!b.empty() && b.back() == v) { n       cnt++; n       b.pop_back(); n     } n     if (cnt % x) { n       cout << binpow(x, min(v, sum)); n       exit(0); n     } else { n       cnt /= x; n       for (int i = int(0); i < int(cnt); i++) b.push_back(v + 1); n     } n   } n } n


#include <bits/stdc++.h> n #pragma GCC target( avx2 ) n #pragma GCC optimization( O3 ) n #pragma GCC optimization( unroll-loops ) n using namespace std; n void fil() {} n long long int ipow(long long int base, long long int k, long long int M) { n   base %= M; n   k = k % (M - 1); n   long long int total = 1; n   while (k) { n     if (k & 1) { n       total = (total * base) % M; n     } n     base = (base * base) % M; n     k >>= 1; n   } n   return total; n } n void solve(); n int main() { n   ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); n   fil(); n   long long int t = 1; n   cin >> t; n   for (int i = 1; i < t + 1; i++) { n     solve(); n   } n } n void solve() { n   int n, m, ix, iy, fx, fy; n   cin >> n >> m >> ix >> iy >> fx >> fy; n   int dx = 1, dy = 1; n   int cnt = 0; n   while (1) { n     if (ix == fx || iy == fy) { n       cout << cnt <<   n ; n       return; n     } n     if (!(ix + dx <= n && ix + dx >= 1)) { n       dx *= -1; n     } n     if (!(iy + dy <= m && iy + dy >= 1)) { n       dy *= -1; n     } n     ix += dx; n     iy += dy; n     cnt++; n   } n } n


#include <bits/stdc++.h> n using namespace std; n using LL = long long; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   int n; n   cin >> n; n   LL sum = 0; n   for (int i = 0; i < n; ++i) { n     LL a; n     cin >> a; n     sum += a; n   } n   LL base = 1LL * (1 + n) * n / 2; n   LL add = (sum - base) / n; n   sum -= base + add * n; n   for (int i = 0; i < sum; ++i) cout << i + 1 + add + 1 <<    ; n   for (int i = sum; i < n; ++i) cout << i + 1 + add <<    ; n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int T; n int N, X, Y, Ord[100005]; n bool print; n int A[100005], Freq[100005], Freq2[100005], F[100005]; n vector<int> V; n vector<int> Ap[100005]; n set<pair<int, int> > S1, S2; n int Res[100005]; n void Read() { n   scanf( %d%d%d , &N, &X, &Y); n   for (int i = 1; i <= N; i++) { n     scanf( %d , &A[i]); n     F[A[i]]++; n     Ord[i] = i; n   } n } n int missing() { n   for (int i = 1; i <= N + 1; i++) n     if (F[i] == 0) return i; n   return -1; n } n bool cmp(int a, int b) { return F[A[a]] < F[A[b]]; } n void Solve() { n   sort(Ord + 1, Ord + N + 1, cmp); n   int miss = missing(); n   Freq[miss] = N - Y; n   int cnt = 0, pos = 0, cnt2 = 0; n   for (int i = 1; i <= N && cnt < Y - X; i++) { n     pos = i; n     if ((Freq[A[Ord[i]]] + Freq2[A[Ord[i]]] + 2) > N - X) { n       if (cnt2 == N - Y || (Freq[A[Ord[i]]] + Freq2[A[Ord[i]]] + 1) > N - X) n         continue; n       Freq2[A[Ord[i]]]++; n       cnt2++; n       continue; n     } n     Freq[A[Ord[i]]]++; n     Freq2[A[Ord[i]]]++; n     cnt++; n   } n   if (cnt < Y - X) { n     printf( NO n ); n     return; n   } n   for (int i = pos + 1; i <= N && cnt2 < N - Y; i++) { n     if (Freq2[A[Ord[i]]] + 1 + Freq[A[Ord[i]]] > N - X) { n       continue; n     } n     Freq2[A[Ord[i]]]++; n     cnt2++; n   } n   if (cnt2 < N - Y) { n     if (print) printf( NO n ); n     return; n   } n   if (print) printf( YES n ); n   for (int i = 1; i <= N + 1; i++) { n     if (Freq[i] > 0) { n       S1.insert(make_pair(Freq[i], i)); n     } n     if (Freq2[i] > 0) S2.insert(make_pair(Freq2[i], i)); n   } n   int total = N - X; n   while (S1.size() > 0) { n     set<pair<int, int> >::iterator it = S1.end(); n     --it; n     set<pair<int, int> >::iterator it2 = S2.end(); n     --it2; n     if ((it->first) * 2 == (it2->first) * 2 && (it->first) * 2 == total) { n       --it; n       --it2; n       if (((it->second) != (it2->second)) || n           ((it->first) * 2 != total || (it2->first) * 2 != total)) { n         ++it; n         ++it2; n       } else n         ++it; n     } n     if ((it2->second) == (it->second)) --it2; n     Ap[it2->second].push_back(it->second); n     pair<int, int> a = *it; n     pair<int, int> b = *it2; n     --a.first; n     --b.first; n     S1.erase(it); n     S2.erase(it2); n     if (a.first > 0) S1.insert(a); n     if (b.first > 0) S2.insert(b); n     --total; n   } n   for (int i = 1; i <= N; i++) { n     if (Ap[A[i]].size() > 0) { n       int val = Ap[A[i]].back(); n       Res[i] = val; n       Ap[A[i]].pop_back(); n     } n   } n   cnt = 0; n   for (int i = 1; i <= N; i++) { n     if (Res[i] == 0) { n       Res[i] = A[i]; n     } n     if (print) printf( %d  , Res[i]); n   } n   if (print) printf(  n ); n } n int main() { n   int T; n   int ind = 0; n   scanf( %d , &T); n   print = true; n   while (T--) { n     ++ind; n     Read(); n     Solve(); n     for (int i = 1; i <= N + 1; i++) { n       Ap[i].clear(); n       Freq[i] = 0; n       F[i] = 0; n       Freq2[i] = 0; n       Res[i] = 0; n     } n     S1.clear(); n     S2.clear(); n     V.clear(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int i, j, k, n, m, t; n long long l, r = 1e14, md, res = 1e18, a[200500], b[200500]; n struct sb { n   long long x, y; n   double t; n   bool operator<(const sb a) const { return t > a.t; } n } s; n bool chk(long long sb) { n   priority_queue<struct sb> q; n   int i, j, k; n   long long tmp; n   for (i = 1; i <= n; i++) { n     s.x = a[i]; n     s.y = b[i]; n     s.t = s.x * 1.0 / s.y; n     q.push(s); n   } n   for (i = 0; i < m; i++) { n     s = q.top(); n     q.pop(); n     tmp = s.x / s.y; n     if (tmp < i) { n       return 0; n     } n     s.x += sb; n     s.t = s.x * 1.0 / s.y; n     q.push(s); n   } n   return 1; n } n int main() { n   scanf( %d%d , &n, &m); n   for (i = 1; i <= n; i++) { n     scanf( %lld , &a[i]); n   } n   for (i = 1; i <= n; i++) { n     scanf( %lld , &b[i]); n   } n   while (l <= r) { n     md = (l + r) / 2; n     if (chk(md)) { n       res = min(res, md); n       r = md - 1; n     } else { n       l = md + 1; n     } n   } n   if (res == 1e18) { n     puts( -1 ); n     return 0; n   } n   printf( %lld , res); n } n


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


#include <bits/stdc++.h> n using namespace std; n long long MOD = 1e9 + 7; n long long a = 0; n long long b = 0; n void dfs(vector<vector<int>> &g, vector<bool> was, int v, int lvl) { n   was[v] = true; n   if (lvl % 2 == 0) n     a++; n   else n     b++; n   for (int x : g[v]) { n     if (!was[x]) dfs(g, was, x, lvl + 1); n   } n } n int main() { n   int n; n   cin >> n; n   unordered_set<string> names; n   for (int i = 0; i < n; i++) { n     string s; n     cin >> s; n     if (names.find(s) == names.end()) n       cout <<  NO  << endl; n     else n       cout <<  YES  << endl; n     names.insert(s); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char t[100][100]; n int main(int argc, char* argv[]) { n   unsigned int n; n   cin >> n; n   for (unsigned int i = 0; i < n; ++i) n     for (unsigned int j = 0; j < n; ++j) cin >> t[i][j]; n   unsigned int r = 0; n   for (unsigned int i = 0; i < n; ++i) { n     for (unsigned int j = 0; j < n; ++j) { n       if (t[i][j] ==  . ) { n         ++r; n         break; n       } n     } n   } n   if (r < n) { n     unsigned int c = 0; n     for (unsigned int i = 0; i < n; ++i) { n       for (unsigned int j = 0; j < n; ++j) { n         if (t[j][i] ==  . ) { n           ++c; n           break; n         } n       } n     } n     if (c < n) n       cout << -1 << endl; n     else { n       for (unsigned int i = 0; i < n; ++i) { n         for (unsigned int j = 0; j < n; ++j) { n           if (t[j][i] ==  . ) { n             cout << j + 1 <<     << i + 1 << endl; n             break; n           } n         } n       } n     } n   } else { n     for (unsigned int i = 0; i < n; ++i) { n       for (unsigned int j = 0; j < n; ++j) { n         if (t[i][j] ==  . ) { n           cout << i + 1 <<     << j + 1 << endl; n           break; n         } n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct V { n   int x, y; n }; n bool conf(V left, V right) { n   if (left.x != right.x) return left.x < right.x; n   return left.y < right.y; n } n int main() { n   V arr[9]; n   for (int i = 0; i <= 7; i++) scanf( %d %d , &arr[i].x, &arr[i].y); n   sort(arr, arr + 8, conf); n   if ((arr[0].x != arr[1].x) || (arr[0].x != arr[2].x) || n       (arr[0].x == arr[3].x) || (arr[3].x != arr[4].x) || n       (arr[0].x == arr[5].x) || (arr[3].x == arr[5].x) || n       (arr[5].x != arr[6].x) || (arr[5].x != arr[7].x)) { n     printf( ugly ); n     return 0; n   } n   if ((arr[0].y == arr[1].y) || (arr[0].y == arr[2].y) || n       (arr[1].y == arr[2].y) || (arr[0].y != arr[3].y) || n       (arr[0].y != arr[5].y) || (arr[1].y != arr[6].y) || n       (arr[2].y != arr[4].y) || (arr[2].y != arr[7].y)) { n     printf( ugly ); n     return 0; n   } n   printf( respectable ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = (int)2e9; n const long long mod = 1000000007; n int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1}; n long long powmod(long long a, long long p) { n   long long ans = 1; n   a %= mod; n   while (p) { n     if (p & 1) ans *= a; n     p /= 2; n     a *= a; n     ans %= mod; n     a %= mod; n   } n   return ans; n } n long long mdinv(long long a) { return powmod(a, mod - 2); } n const int N = 5e5 + 10; n vector<int> adj[N]; n vector<int> pre[N]; n vector<int> suf[N]; n int d[N]; n vector<pair<int, int> > nb[N]; n int f[2 * N]; n void dfs1(int i, int p) { n   d[i] = 0; n   for (int v : adj[i]) { n     if (v != p) { n       dfs1(v, i), d[i] = max(d[i], 1 + d[v]); n     } n   } n } n void evaluate(vector<pair<int, int> >& v); n void go(vector<pair<int, int> >& v, vector<pair<int, int> >& v2); n void dfs2(int i, int p, int parDep) { n   vector<int>& pr = pre[i]; n   for (int v : adj[i]) { n     if (v != p) { n       pr.push_back(d[v] + 1); n     } else n       pr.push_back(parDep + 1); n   } n   vector<int> lst(pr); n   vector<int>& sf = suf[i]; n   sf = pr; n   for (int i = 1; i < (int)(pr.size()); i++) pr[i] = max(pr[i - 1], pr[i]); n   for (int i = (int)(pr.size()) - 2; i >= 0; i--) sf[i] = max(sf[i], sf[i + 1]); n   for (int first = 0; first < (int)(adj[i].size()); first++) { n     int v = adj[i][first]; n     if (v == p) continue; n     int mx = 0; n     if (first) mx = max(mx, pr[first - 1]); n     if (first + 1 < (int)(pr.size())) mx = max(mx, sf[first + 1]); n     dfs2(v, i, mx); n   } n   for (int first : lst) nb[i].push_back({first, 1}); n   vector<pair<int, int> >& v = nb[i]; n   sort((v).begin(), (v).end()); n   int ind = 0; n   for (int i = 1; i < (int)(v.size()); i++) { n     if (v[ind].first == v[i].first) { n       v[ind].second += v[i].second; n     } else { n       ind++; n       v[ind] = v[i]; n     } n   } n   v.resize(ind + 1); n   evaluate(nb[i]); n   for (int v : adj[i]) { n     if (v != p) { n       go(nb[i], nb[v]); n     } n   } n } n vector<pair<int, int> > tmp; n void evaluate(vector<pair<int, int> >& v) { n   tmp = v; n   for (int i = (int)(tmp.size()) - 1; i >= 0; i--) { n     if (i != (int)(tmp.size()) - 1) n       tmp[i].second = tmp[i].second + tmp[i + 1].second; n     int dep = tmp[i].first; n     f[2 * dep] = max(f[2 * dep], tmp[i].second); n     int greater = tmp[i].second - v[i].second; n     f[2 * dep + 1] = max(f[2 * dep + 1], greater + 1); n     f[2 * dep - 1] = max(f[2 * dep - 1], tmp[i].second); n   } n } n void go(vector<pair<int, int> >& v1, vector<pair<int, int> >& v2) { n   tmp.clear(); n   for (auto i : v1) tmp.push_back(i); n   for (auto i : v2) tmp.push_back(i); n   sort((tmp).begin(), (tmp).end()); n   int ind = 0; n   for (int i = 1; i < (int)(tmp.size()); i++) { n     if (tmp[ind].first == tmp[i].first) { n       tmp[ind].second += tmp[i].second; n     } else { n       ind++; n       tmp[ind] = tmp[i]; n     } n   } n   tmp.resize(ind + 1); n   for (int i = (int)(tmp.size()) - 1; i >= 0; i--) { n     if (i != (int)(tmp.size()) - 1) n       tmp[i].second = tmp[i].second + tmp[i + 1].second; n     int dep = tmp[i].first; n     f[2 * dep] = max(f[2 * dep], tmp[i].second - 2); n   } n } n signed main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   for (int i = 0; i < (int)2 * N; i++) f[i] = 1; n   int n; n   cin >> n; n   int a, b; n   int mxd = 0; n   for (int i = 0; i < (int)n - 1; i++) { n     cin >> a >> b; n     adj[a].push_back(b); n     adj[b].push_back(a); n   } n   for (int i = 1; i <= n; i++) mxd = max(mxd, (int)(adj[i].size())); n   dfs1(1, 0); n   dfs2(1, 0, -1); n   for (int i = N - 3; i >= 0; i -= 2) f[i] = max(f[i], f[i + 2]); n   for (int i = N - 4; i >= 0; i -= 2) f[i] = max(f[i], f[i + 2]); n   f[1] = mxd + 1; n   for (int i = 1; i <= n; i++) cout << f[i] <<    ; n } n


#include <bits/stdc++.h> n using namespace std; n using namespace std; n void transform(int input) { n   if (input) { n     transform((input - 1) / 26); n     putchar(65 + (input - 1) % 26); n   } n } n int main() { n   int n, x, y; n   string input; n   for (scanf( %d  , &n); n--;) { n     cin >> input; n     if (sscanf(input.c_str(),  %*c%d%*c%d , &x, &y) == 2) { n       transform(y); n       printf( %d n , x); n     } else { n       x = 0; n       for (int j = 0; j < input.size() && input[j] > 64 && input[j] < 91; j++) { n         x = x * 26 + input[j] - 64; n       } n       string digits = input.c_str(); n       digits.erase(remove_if((digits).begin(), (digits).end(), n                              [](char c) { return isalpha(c); }), n                    digits.end()); n       printf( R%sC%d n , digits.c_str(), x); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX = 105; n int main() { n   ios::sync_with_stdio(false); n   int n; n   cin >> n; n   int x; n   cin >> x; n   for (int i = 0; i < n; i++) { n     x = 7 - x; n     int a, b; n     cin >> a >> b; n     if (a == x || b == x || 7 - a == x || 7 - b == x) { n       cout <<  NO n ; n       return 0; n     } n     for (int j = 1; j <= 6; j++) n       if (a != j && b != j && 7 - a != j && 7 - b != j) x = j; n   } n   cout <<  YES n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(0); n   string s; n   cin >> s; n   char x =  a ; n   int y; n   set<int> arr[26]; n   for (int i = 0; i < s.length(); i++) { n     y = s[i] - x; n     arr[y].insert(i); n   } n   int q; n   cin >> q; n   int n, ans = 0; n   for (int i = 0; i < q; i++) { n     cin >> n; n     if (n == 1) { n       int pos; n       char c; n       cin >> pos >> c; n       y = s[pos - 1] - x; n       arr[y].erase(pos - 1); n       s[pos - 1] = c; n       y = c - x; n       arr[y].insert(pos - 1); n     } n     if (n == 2) { n       int l, r; n       cin >> l >> r; n       l--; n       r--; n       for (int i = 0; i < 26; i++) { n         auto it = arr[i].lower_bound(l); n         if (it == arr[i].end()) n           continue; n         else if (*it <= r) n           ans++; n       } n       cout << ans << endl; n       ans = 0; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a[1000005]; n int main() { n   int n, m; n   while (~scanf( %d%d , &n, &m)) { n     if (n == 1) { n       printf( YES n%d n , m); n     } else if (n == 2) { n       if (m == 0) { n         printf( NO n ); n       } else { n         printf( YES n0 %d n , m); n       } n     } else { n       int x = 1 << 18, y = 1 << 19, z = 0; n       printf( YES n ); n       for (int i = 1; i <= n - 3; i++) { n         printf( %d  , i); n         z = z ^ i; n       } n       printf( %d %d %d n , x, y, (x ^ y ^ z ^ m)); n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long int mod = 1e9 + 7; n long long int expo(long long int base, long long int exponent, n                    long long int mod) { n   long long int ans = 1; n   while (exponent > 0) { n     if (exponent % 2 == 1) { n       ans *= base; n       ans %= mod; n     } n     base *= base; n     base %= mod; n     exponent /= 2; n   } n   return ans; n } n const long long int M = 3000006; n long long int f[M], inv[M]; n void compute() { n   f[0] = 1; n   for (long long int i = 1; i <= M - 1; i++) { n     f[i] = (1LL * i * f[i - 1]) % mod; n   } n   inv[M - 1] = expo(f[M - 1], mod - 2, mod); n   for (long long int i = M - 2; i >= 0; i--) { n     inv[i] = (1LL * (i + 1) * inv[i + 1]) % mod; n   } n } n long long int C(long long int n, long long int r) { n   return (1LL * ((1LL * f[n] * inv[r]) % mod) * inv[n - r]) % mod; n } n long long int h[100005]; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int tests = 1; n   while (tests--) { n     long long int i, j, n; n     cin >> n; n     for (long long int i = 1; i <= n; i++) cin >> h[i]; n     long long int tmp = 0; n     vector<long long int> res(n + 1); n     for (long long int i = 1; i <= n; i++) { n       tmp = min(tmp, h[i] - i); n       res[i] = tmp + i; n     } n     tmp = 0; n     for (i = n; i >= 1; i--) { n       tmp = min(tmp, h[i] - (n + 1 - i)); n       res[i] = min(res[i], tmp + (n + 1 - i)); n     } n     long long int ans = 0; n     for (long long int i = 1; i <= n; i++) ans = max(ans, res[i]); n     cout << ans; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double PI = acos(-1.0); n double fRand(double fMin, double fMax) { n   double f = (double)rand() / RAND_MAX; n   return fMin + f * (fMax - fMin); n } n template <class T> n T min(T a, T b, T c) { n   return min(a, min(b, c)); n } n template <class T> n T max(T a, T b, T c) { n   return max(a, max(b, c)); n } n int n, a[100005], cnt[100005]; n vector<int> d[100005]; n int power(int x, int n) { n   if (n == 0) return 1; n   if (n & 1) return ((long long)x * power(x, n - 1)) % 1000000007; n   int p = power(x, n / 2); n   return ((long long)p * p) % 1000000007; n } n int main() { n   scanf( %d , &n); n   for (int i = (1); i <= (n); ++i) { n     scanf( %d , &a[i]); n     ++cnt[a[i]]; n   } n   int m = *max_element(a + 1, a + n + 1); n   for (int x = (1); x <= (m); ++x) cnt[x] += cnt[x - 1]; n   for (int x = (1); x <= (m); ++x) n     for (int i = (x); i <= (m); i += x) d[i].push_back(x); n   int ans = 0; n   for (int x = (1); x <= (m); ++x) { n     int k = (int)d[x].size(), q[k]; n     for (int i = (0); i <= (k - 2); ++i) n       q[i] = cnt[d[x][i + 1] - 1] - cnt[d[x][i] - 1]; n     q[k - 1] = cnt[m] - cnt[d[x][k - 1] - 1]; n     int prod = 1; n     for (int i = (0); i <= (k - 2); ++i) n       prod = ((long long)prod * power(i + 1, q[i])) % 1000000007; n     prod = ((long long)prod * n             (power(k, q[k - 1]) - power(k - 1, q[k - 1]) + 1000000007)) % n            1000000007; n     ans = (ans + prod) % 1000000007; n   } n   printf( %d , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1001000; n int f[maxn], rx[maxn], ry[maxn], ans[maxn], pre_rx[maxn], pre_ry[maxn]; n struct node { n   int num, x, y; n } mp[maxn]; n int find(int x) { n   while (x != f[x]) x = f[x] = f[f[x]]; n   return f[x]; n } n void merge(int x, int y) { n   int xx = find(x), yy = find(y); n   if (xx != yy) f[yy] = xx; n } n bool cmp(node x, node y) { return x.num < y.num; } n int main() { n   int n, m; n   scanf( %d%d , &n, &m); n   int cnt = 1; n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= m; j++) { n       scanf( %d , &mp[(i - 1) * m + j]); n       mp[cnt].x = i, mp[cnt++].y = j; n       f[(i - 1) * m + j] = (i - 1) * m + j; n     } n   sort(mp + 1, mp + n * m + 1, cmp); n   int k; n   for (int i = 1; i <= n * m; i = k) { n     for (k = i + 1; k <= n * m && mp[k].num == mp[i].num; k++) n       ; n     for (int j = i; j < k; j++) { n       int x = mp[j].x, y = mp[j].y; n       if (!rx[x]) n         rx[x] = (x - 1) * m + y; n       else n         merge(rx[x], (x - 1) * m + y); n       if (!ry[y]) n         ry[y] = (x - 1) * m + y; n       else n         merge(ry[y], (x - 1) * m + y); n     } n     for (int j = i; j < k; j++) { n       int x = mp[j].x, y = mp[j].y, r = find((x - 1) * m + y); n       ans[r] = max(ans[r], max(pre_rx[x], pre_ry[y]) + 1); n     } n     for (int j = i; j < k; j++) { n       int x = mp[j].x, y = mp[j].y, r = find((x - 1) * m + y); n       ans[(x - 1) * m + y] = ans[r]; n       pre_rx[x] = pre_ry[y] = ans[r]; n       rx[x] = 0, ry[y] = 0; n     } n   } n   for (int i = 1; i <= n * m; i++) { n     if (i % m == 0) n       printf( %d n , ans[i]); n     else n       printf( %d  , ans[i]); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct vec { n   long double x, y; n   bool operator==(const vec &a) const { return x == a.x && y == a.y; } n   bool operator<(const vec &a) const { n     if (a.x != x) return x < a.x; n     return y < a.y; n   } n   vec operator+(const vec &a) const { return {x + a.x, y + a.y}; } n   vec operator*(const long double &a) const { return {x * a, y * a}; } n   vec operator-(const vec &a) const { return {x - a.x, y - a.y}; } n   vec operator/(const long double &a) const { return {x / a, y / a}; } n   long double len() const { return sqrt(x * x + y * y); } n   long double dot(const vec &a) const { return x * a.x + y * a.y; } n   long double crs(const vec &a) const { return x * a.y - y * a.x; } n   vec proj(const vec &a) const { n     return (a / a.len()) * (*this).dot(a) / a.len(); n   } n }; n struct P { n   int x, y; n   bool operator<(const P &a) const { n     if (x != a.x) return x > a.x; n     return y < a.y; n   } n }; n bool as(P a, P b) { return a.x < b.x; } n long long x, y, z, mod = 1000000007; n vector<int> v1, v, v2; n int i, n, m, k, a, d, b, c, dx[10] = {1, 0, -1, 0}, dy[10] = {0, 1, 0, -1}; n int e[511112]; n int l[511155]; n int o[511110]; n int j[511112]; n stack<int> s; n queue<int> q, q1; n P u[533111]; n string r, r1; n map<int, int> p, p1; n int main() { n   scanf( %d %d , &a, &b); n   for (int t = 1; t <= a; t++) scanf( %d , &j[t]); n   for (int t = 1; t <= b; t++) { n     v.clear(); n     scanf( %d , &n); n     d = n; n     e[d] = 1 - e[d]; n     n = j[n]; n     if (n == 1) { n       c -= o[n]; n       if (e[d]) n         o[n]++; n       else n         o[n]--; n       c += o[n]; n       goto qwe; n     } n     m = n; n     for (int i = 2; i * i <= n; i++) { n       if (n % i == 0) { n         v.push_back(i); n         for (; n % i == 0; n /= i) n           ; n       } n     } n     if (n > 1) v.push_back(n); n     n = m; n     c -= o[n]; n     if (e[d]) n       o[n]++; n     else n       o[n]--; n     c += o[n]; n     for (int i = 1; i < (1 << v.size()); i++) { n       int k = 0, p = 1; n       for (int t = i, j = 0; t; j++, k += t % 2, k %= 2, t /= 2) n         if (t % 2) p *= v[j]; n       if (e[d]) { n         if (k) n           x += l[p]; n         else n           x -= l[p]; n         l[p]++; n       } else { n         l[p]--; n         if (k) n           x -= l[p]; n         else n           x += l[p]; n       } n     } n   qwe:; n     printf( %lld n , (long long)c * (c - 1) / 2 - x); n   } n } n


#include <bits/stdc++.h> n const double PI = acos(-1.0); n using namespace std; n char p[102][102]; n int main() { n   int n; n   scanf( %d n , &n); n   for (int i = 1; i <= n; ++i) { n     for (int j = 1; j <= n; ++j) p[i][j] = getchar(); n     getchar(); n   } n   bool foo = true; n   for (int i = 1; i <= n; ++i) { n     for (int j = 1; j <= n; ++j) { n       int cnt = 0; n       if (p[i - 1][j] ==  o ) ++cnt; n       if (p[i][j - 1] ==  o ) ++cnt; n       if (p[i][j + 1] ==  o ) ++cnt; n       if (p[i + 1][j] ==  o ) ++cnt; n       if (cnt % 2) { n         foo = false; n         break; n       } n     } n   } n   if (foo) n     printf( YES n ); n   else n     printf( NO n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s1, s2; n   cin >> s1 >> s2; n   int n = s1.length(), p = 0, a = 0, p2 = 0; n   for (int i = 0; i < n; i++) n     if (s1[i] ==  + ) p++; n   int m = n - p; n   for (int i = 0; i < n; i++) { n     if (s2[i] ==  ? ) n       a++; n     else if (s2[i] ==  + ) n       p2++; n   } n   int m2 = n - a - p2; n   if (abs(p2 - p) <= a && abs(m2 - m) <= a) { n     float y = abs(p2 - p), ans = 1; n     y = min(y, a - y); n     for (int i = a; i > a - y; i--) ans *= i; n     for (int i = 2; i <= y; i++) ans /= i; n     float s = pow(2, a); n     printf( %.9f , ans / s); n   } else n     cout << 0; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void printopt(int p) { n   for (int i = p / 2; i; i--) printf( 4 ); n   for (int i = p / 2; i; i--) printf( 7 ); n } n char s[100000 + 2]; n char s47[100000 + 2]; n int n; n bool fopt(int i, int ddif47) { n   if (abs(ddif47) > n - i) return 0; n   int j = i; n   for (; j < i + (n - i - ddif47) / 2; j++) s47[j] =  4 ; n   for (; j < n; j++) s47[j] =  7 ; n   return 1; n } n bool f(int i, int dif47) { n   if (i == n) return dif47 == 0; n   switch (s[i] -  0 ) { n     case 0: n     case 1: n     case 2: n     case 3: n       if (fopt(i, dif47)) return 1; n       break; n     case 4: n       s47[i] =  4 ; n       if (f(i + 1, dif47 + 1)) return 1; n       s47[i] =  7 ; n       if (fopt(i + 1, dif47 - 1)) return 1; n       break; n     case 5: n     case 6: n       s47[i] =  7 ; n       if (fopt(i + 1, dif47 - 1)) return 1; n       break; n     case 7: n       s47[i] =  7 ; n       if (f(i + 1, dif47 - 1)) return 1; n       break; n     case 8: n     case 9: n       break; n   } n   return 0; n } n int main() { n   scanf( %s , s); n   n = strlen(s); n   if (n % 2) n     printopt(n + 1); n   else if (f(0, 0)) n     printf( %s , s47); n   else n     printopt(n + 2); n   printf(  n ); n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n using vi = vector<int>; n using vvi = vector<vector<int>>; n using pii = pair<int, int>; n constexpr int N = 300001; n struct Ed { n   int u, v; n   bool s; n }; n vector<pii> g[N], t[N]; n int d[N], low[N], biconn[N]; n bool scored[N], vis[N]; n int tim = 1, compno = 1; n pii p[N]; n void dfs(int u, int p) { n   low[u] = d[u] = tim++; n   for (const auto& pr : g[u]) { n     if (pr.first == p) continue; n     if (d[pr.first] != 0) { n       low[u] = min(low[u], d[pr.first]); n     } else { n       dfs(pr.first, u); n       low[u] = min(low[u], low[pr.first]); n     } n   } n } n void comp(int u, int p, int c) { n   if (biconn[u] != 0) return; n   if (low[u] == d[u]) c = ++compno; n   biconn[u] = c; n   for (const auto& pr : g[u]) { n     if (pr.second && biconn[pr.first] == c) scored[c] = true; n     if (pr.first == p && biconn[p] != c) { n       t[c].push_back({biconn[p], pr.second}); n       t[biconn[p]].push_back({c, pr.second}); n     } else if (biconn[pr.first] == 0) n       comp(pr.first, u, c); n   } n } n void solve() { n   int n, m, x, y, z, a, b; n   cin >> n >> m; n   while (m--) { n     cin >> x >> y >> z; n     g[x].push_back({y, z}); n     g[y].push_back({x, z}); n   } n   cin >> a >> b; n   dfs(a, -1); n   comp(a, -1, 1); n   a = biconn[a]; n   b = biconn[b]; n   queue<int> q; n   q.push(a); n   vis[a] = true; n   while (!q.empty()) { n     int u = q.front(); n     q.pop(); n     for (const auto& v : t[u]) n       if (!vis[v.first]) { n         p[v.first] = {u, v.second}; n         q.push(v.first); n         vis[v.first] = true; n       } n   } n   bool ok = scored[a]; n   while (!ok && b != a) { n     if (scored[b] || p[b].second) ok = true; n     b = p[b].first; n   } n   cout << (ok ?  YES n  :  NO n ); n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int search(long long int *array, int start_idx, int end_idx, n            long long int search_val) { n   if (start_idx == end_idx) n     return array[start_idx] <= search_val ? start_idx : -1; n   int mid_idx = start_idx + (end_idx - start_idx) / 2; n   if (search_val < array[mid_idx]) n     return search(array, start_idx, mid_idx, search_val); n   int ret = search(array, mid_idx + 1, end_idx, search_val); n   return ret == -1 ? mid_idx : ret; n } n long long int C(long long int k) { return (k * (k - 1)) / 2; } n int main() { n   ios_base::sync_with_stdio; n   cin.tie(NULL); n   long long int n, d; n   cin >> n >> d; n   long long int arr[n]; n   for (long long int i = 0; i < n; i++) cin >> arr[i]; n   long long int ways = 0, current, maxallowed, index2, previndex2; n   for (long long int i = 0; i < n; i++) { n     current = arr[i]; n     maxallowed = current + d; n     index2 = search(arr, 0, n - 1, maxallowed); n     if (index2 - i + 1 >= 3) { n       ways += C(index2 - i); n     } n   } n   cout << ways; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = 0x3f3f3f3f; n const int maxn = 1e5 + 10; n const int mod = 998244353; n const int N = 2e5 + 6; n int pk = 30; n int a[N]; n struct Trie { n   static const int N = 15101000, M = 2; n   int ne[N][M], rt, L, sum[N], ans[N]; n   void ini() { n     fill_n(sum, N, 0); n     L = 0, rt = newnode(); n   } n   int newnode() { n     fill_n(ne[L], M, 0); n     return L++; n   } n   void add(int k, int x, int v) { n     int p = rt; n     for (int i = pk; i >= 0; i--) { n       int c = (x >> i) & 1; n       if (!ne[p][c]) ne[p][c] = newnode(); n       p = ne[p][c]; n     } n     sum[p] += v; n   } n   int qry(int x) { n     int p = rt; n     for (int i = pk; i >= 0; i--) { n       int c = (x >> i) & 1; n       if (ne[p][c] && sum[ne[p][c]]) n         p = ne[p][c]; n       else n         p = ne[p][!c]; n     } n     return ans[p]; n   } n   int solve() { n     int res = 0; n     for (int i = L - 1; i >= 0; i--) { n       if (sum[i] > 0) continue; n       if (!ne[i][0] || !ne[i][1]) n         sum[i] = sum[ne[i][0]] + sum[ne[i][1]]; n       else { n         int c0 = ne[i][0], c1 = ne[i][1]; n         if (sum[c0] <= 1 || sum[c1] <= 1) n           sum[i] = sum[c0] + sum[c1]; n         else { n           if (sum[c0] < sum[c1]) n             res += sum[c0] - 1, sum[i] = sum[c1] + 1; n           else n             res += sum[c1] - 1, sum[i] = sum[c0] + 1; n         } n       } n     } n     return res; n   } n } T; n int s[N], f[N]; n int find(int x) { n   if (f[x] == x) return x; n   return f[x] = find(f[x]); n } n int main() { n   int n, m; n   T.ini(); n   scanf( %d , &n); n   for (int i = 1; i < n + 1; i++) scanf( %d , &a[i]), T.add(i, a[i], 1); n   int ans = T.solve(); n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n inline bool fs(T &x) { n   int c = getchar(); n   int sgn = 1; n   while (~c && c <  0  || c >  9 ) { n     if (c ==  - ) sgn = -1; n     c = getchar(); n   } n   for (x = 0; ~c &&  0  <= c && c <=  9 ; c = getchar()) x = x * 10 + c -  0 ; n   x *= sgn; n   return ~c; n } n double fun(int h, double c, int n) { n   double ans; n   if (h % n == 0) n     ans = h / n; n   else n     ans = h / n + 1; n   return ans * c; n } n int main() { n   int h, n; n   double a, b, d, c; n   double res = 20 / 100, x, y; n   cin >> a >> b; n   cin >> h >> d >> c >> n; n   a = a * 60 + b; n   b = 20 * 60 - a; n   if (a >= 1200) n     cout << fun(h, c - c * 20 / 100, n) << endl; n   else n     cout << min(fun(h + b * d, c - c * 20 / 100, n), fun(h, c, n)) << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool mark[100]; n vector<pair<int, int> > coors; n void DFS(int ver) { n   mark[ver] = true; n   for (int i = 0; i < coors.size(); i++) n     if ((coors[ver].first == coors[i].first || n          coors[ver].second == coors[i].second) && n         !mark[i]) n       DFS(i); n } n int main() { n   ios_base::sync_with_stdio(false); n   int n; n   cin >> n; n   coors.resize(n); n   for (int i = 0; i < n; i++) { n     pair<int, int> tmp; n     cin >> tmp.first >> tmp.second; n     coors[i] = tmp; n   } n   int ans = -1; n   for (int i = 0; i < n; i++) { n     if (!mark[i]) { n       ans++; n       DFS(i); n     } n   } n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int PMAX = 61; n long long shift[PMAX]; n inline int logbin(long long x) { return 63 - __builtin_clzll(x); } n inline void modif(int p, long long k) { n   shift[p] += k; n   shift[p] %= (1ll << p); n } n int main() { n   int q; n   scanf( %d , &q); n   for (int i = 0; i < q; i++) { n     int t; n     scanf( %d , &t); n     if (t == 1) { n       long long x, k; n       scanf( %I64d%I64d , &x, &k); n       int p = logbin(x); n       k = ((k % (1ll << p)) + (1ll << p)) % (1ll << p); n       modif(p, k); n     } else if (t == 2) { n       long long x, k; n       scanf( %I64d%I64d , &x, &k); n       int p = logbin(x); n       k = ((k % (1ll << p)) + (1ll << p)) % (1ll << p); n       for (int i = p; i < PMAX; i++, k *= 2) modif(i, k); n     } else { n       long long x; n       scanf( %I64d , &x); n       for (int p = logbin(x); p >= 0; p--) { n         printf( %lld  , x); n         x = (1ll << p) + (x + shift[p] + (1ll << p)) % (1ll << p); n         x /= 2; n         if (p > 0) n           x = (1ll << (p - 1)) + n               (x - shift[p - 1] + (1ll << (p - 1))) % (1ll << (p - 1)); n       } n       printf(  n ); n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int gcd(int a, int b) { return a % b ? gcd(b, a % b) : b; } n int lcm(int a, int b) { return a * b / gcd(a, b); } n int prime(long long n) { n   if (n < 2) return 0; n   if (n == 2 || n == 3) return 1; n   if (n % 6 != 1 && n % 6 != 5) return 0; n   for (long long i = 5; i <= sqrt(n); i += 6) { n     if (n % i == 0 || n % (i + 2) == 0) return 0; n   } n   return 1; n } n int t, r, g, b; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cin >> t; n   while (t--) { n     cin >> r >> g >> b; n     int mx = max(b, max(r, g)); n     int ans = min((r + g + b) / 2, r + g + b - mx); n     cout << ans << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n class myistream { n   static const int maxsize = 1000007, tmpsize = 50; n   char *s, *tmp; n   char *cur, *upperbound; n   FILE *fp; n   bool last_read; n   bool end_of_file; n   bool to_return; n   void upd() { n     int num = fread(s, sizeof(char), maxsize, fp); n     if (num < maxsize) last_read = true, upperbound = s + num; n     if (!num) end_of_file = true; n     cur = s; n   } n   char scan() { n     if (cur >= upperbound) { n       if (last_read) n         end_of_file = true; n       else n         upd(); n     } n     return *cur++; n   } n   bool isspace(char c) { n     return c ==     || c ==   n  || c ==   r  || c ==   t ; n   } n  n  public: n   myistream(FILE *_fp) n       : last_read(false), end_of_file(false), to_return(false), fp(_fp) { n     s = new char[maxsize + 2]; n     tmp = new char[tmpsize + 2]; n     upperbound = s + maxsize; n     cur = s + maxsize; n   } n   ~myistream() { n     delete[] s; n     delete[] tmp; n     fclose(fp); n   } n   operator void *() const { return to_return ? 0 : (void *)this; } n   bool operator!() const { return to_return; } n   myistream &operator>>(int &a) { n     if (!end_of_file) { n       char c = scan(); n       while (isspace(c) && !end_of_file) c = scan(); n       if (end_of_file) { n         to_return = true; n         return *this; n       } n       a = 0; n       bool nega = false; n       if (c ==  - ) nega = true, c = scan(); n       while (!isspace(c) && !end_of_file) { n         a = a * 10 + (((int)c) & 15); n         c = scan(); n       } n       if (nega) a = -a; n     } else n       to_return = true; n     return *this; n   } n   myistream &operator>>(long long &a) { n     if (!end_of_file) { n       char c = scan(); n       while (isspace(c) && !end_of_file) c = scan(); n       if (end_of_file) { n         to_return = true; n         return *this; n       } n       a = 0; n       bool nega = false; n       if (c ==  - ) nega = true, c = scan(); n       while (!isspace(c) && !end_of_file) { n         a = a * 10 + (((long long)c) & 15); n         c = scan(); n       } n       if (nega) a = -a; n     } else n       to_return = true; n     return *this; n   } n   myistream &operator>>(char &c) { n     if (!end_of_file) { n       c = scan(); n       while (isspace(c) && !end_of_file) c = scan(); n     } n     if (end_of_file) to_return = true; n     return *this; n   } n   myistream &operator>>(bool &b) { n     if (!end_of_file) { n       char c = scan(); n       while (isspace(c) && !end_of_file) c = scan(); n       b = (c ==  1 ); n     } n     if (end_of_file) to_return = true; n     return *this; n   } n   myistream &operator>>(char *s) { n     if (!end_of_file) { n       char c = scan(); n       while (isspace(c) && !end_of_file) c = scan(); n       if (end_of_file) { n         to_return = true; n         return *this; n       } n       while (!isspace(c) && !end_of_file) *s++ = c, c = scan(); n       *s =   0 ; n     } else n       to_return = true; n     return *this; n   } n   myistream &operator>>(string &s) { n     s.clear(); n     if (!end_of_file) { n       char c = scan(); n       while (isspace(c) && !end_of_file) c = scan(); n       if (end_of_file) { n         to_return = true; n         return *this; n       } n       while (!isspace(c) && !end_of_file) s.push_back(c), c = scan(); n     } else n       to_return = true; n     return *this; n   } n   myistream &operator>>(double &d) { n     if (!end_of_file) { n       char *tp = tmp; n       char c = scan(); n       while (isspace(c) && !end_of_file) c = scan(); n       if (end_of_file) { n         to_return = true; n         return *this; n       } n       while (!isspace(c) && !end_of_file) *tp++ = c, c = scan(); n       *tp =   0 ; n       sscanf(tmp,  %lf , &d); n     } else n       to_return = true; n     return *this; n   } n }; n class myostreamEndlType {}; n class myostreamSetPrecisionType { n  public: n   int precision; n   myostreamSetPrecisionType(int _precision) : precision(_precision) {} n }; n class myostream { n   static const int maxsize = 1000007, tmpsize = 50; n   char *s, *upperbound, *cur, *tmp; n   FILE *fp; n   int numberAfterPoint; n   char doubleFormat[20]; n   void write(char c) { n     if (cur >= upperbound) { n       fwrite(s, sizeof(char), maxsize, fp); n       cur = s; n     } n     *cur++ = c; n   } n  n  public: n   myostream(FILE *_fp) : fp(_fp) { n     s = new char[maxsize]; n     tmp = new char[tmpsize + 2]; n     upperbound = s + maxsize; n     cur = s; n     precision(6); n   } n   ~myostream() { n     fwrite(s, sizeof(char), cur - s, fp); n     fclose(fp); n     delete[] s; n   } n   void precision(int x) { n     numberAfterPoint = x; n     sprintf(doubleFormat,  %%.%dlf , x); n   } n   int precision(void) { return numberAfterPoint; } n   myostream &operator<<(const myostreamSetPrecisionType &p) { n     precision(p.precision); n     return *this; n   } n   myostream &operator<<(const char &c) { n     write(c); n     return *this; n   } n   myostream &operator<<(const myostreamEndlType &e) { n     write(  n ); n     return *this; n   } n   myostream &operator<<(const bool &b) { n     write(b ?  1  :  0 ); n     return *this; n   } n   myostream &operator<<(const char *c) { n     for (const char *p = c; *p; p++) write(*p); n     return *this; n   } n   myostream &operator<<(const string &c) { return *this << c.c_str(); } n   myostream &operator<<(const int &a) { n     if (a == 0) { n       write( 0 ); n       return *this; n     } n     int s = a; n     if (s < 0) write( - ), s = -s; n     char *tp = tmp; n     while (s > 0) { n       *tp++ = char((s % 10) | 48); n       s /= 10; n     } n     for (--tp; tp >= tmp; --tp) write(*tp); n     return *this; n   } n   myostream &operator<<(const long long &a) { n     if (a == 0) { n       write( 0 ); n       return *this; n     } n     long long s = a; n     if (s < 0) write( - ), s = -s; n     char *tp = tmp; n     while (s > 0) { n       *tp++ = char((s % 10) | 48); n       s /= 10; n     } n     for (--tp; tp >= tmp; --tp) write(*tp); n     return *this; n   } n   myostream &operator<<(const double &d) { n     sprintf(tmp, doubleFormat, d); n     *this << tmp; n     return *this; n   } n }; n const int maxn = 100050, inf = 0x3fffffff; n int n, m, k; n bool hasv[maxn] = {}; n int s, t; n vector<int> buf[maxn]; n bool judge(int maxV) { n   static bool inq[maxn]; n   static int dis[maxn]; n   memset(inq, false, sizeof inq); n   fill(dis, dis + n, inf); n   queue<int> q; n   dis[s] = 0; n   q.push(s); n   inq[s] = true; n   while (!q.empty()) { n     int x = q.front(); n     q.pop(); n     inq[x] = false; n     if (dis[x] < maxV) n       for (auto it = (buf[x]).begin(); it != (buf[x]).end(); ++it) { n         int tmp = dis[x] + 1; n         if (hasv[*it]) tmp = 0; n         if (dis[*it] > tmp) { n           dis[*it] = tmp; n           if (!inq[*it]) { n             inq[*it] = true; n             q.push(*it); n           } n         } n       } n   } n   return dis[t] < inf; n } n int main(void) { n   cin >> n >> m >> k; n   while (k--) { n     int a; n     cin >> a; n     --a; n     hasv[a] = true; n   } n   while (m--) { n     int a, b; n     cin >> a >> b; n     --a; n     --b; n     buf[a].push_back(b); n     buf[b].push_back(a); n   } n   cin >> s >> t; n   --s; n   --t; n   int left = 1, right = n + 1; n   while (left < right) { n     int mid = (left + right) >> 1; n     if (judge(mid)) n       right = mid; n     else n       left = mid + 1; n   } n   if (left > n) n     cout << -1 << endl; n   else n     cout << left << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int R = 0; n   int d = 0; n   int n = 0; n   cin >> R; n   cin >> d; n   cin >> n; n   int x; n   int y; n   int r; n   int counter = 0; n   double low = 0; n   double high = 0; n   for (int i = 0; i < n; i++) { n     cin >> x; n     cin >> y; n     cin >> r; n     if (((sqrt(x * x + y * y) - r) >= (R - d)) && n         ((sqrt(x * x + y * y) + r) <= R)) n       counter++; n   } n   cout << counter; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n  n   n bool checktwo(long long int n){if(n==0){return false;}else{return (ceil(log2(n)) == floor(log2(n)));}} n long long int powerof2lte(long long int n){int p = (long long int)log2(n);return (long long int)pow(2, p);}  n long long int numdigits(long long int n){return floor(log10(n)) + 1; } n  n int main() n { n     long long int n; n     cin>>n; n     cout<<2 - (n*n)<<  n ; n }


#include <bits/stdc++.h> n using namespace std; n inline char gc() { n   static char buf[131072], *p1 = buf, *p2 = buf; n   return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 131072, stdin), p1 == p2) n              ? EOF n              : *p1++; n } n inline void read(int& x) { n   x = 0; n   char c = gc(); n   while (c <  0  || c >  9 ) c = gc(); n   while (c >=  0  && c <=  9 ) { n     x = (x << 3) + (x << 1) + (c ^ 48); n     c = gc(); n   } n } n int fa[100003], son[100003][2], st[100003], a[100003], sum[100003], n     size[100003], tag[100003]; n bool rev[100003]; n int n, q; n inline void pushup(int u) { n   sum[u] = sum[son[u][0]] + sum[son[u][1]] + a[u]; n   size[u] = size[son[u][0]] + size[son[u][1]] + 1; n } n inline bool notrt(const int& u) { n   return son[fa[u]][0] == u || son[fa[u]][1] == u; n } n inline void pushr(const int& u) { n   swap(son[u][0], son[u][1]); n   rev[u] ^= 1; n } n inline void pushc(const int& u, const int& k) { n   a[u] = tag[u] = k; n   sum[u] = k == 0 ? 0 : size[u]; n } n inline void pushdown(const int& u) { n   if (tag[u] != -1) { n     if (son[u][0]) pushc(son[u][0], tag[u]); n     if (son[u][1]) pushc(son[u][1], tag[u]); n     tag[u] = -1; n   } n   if (!rev[u]) return; n   if (son[u][0]) pushr(son[u][0]); n   if (son[u][1]) pushr(son[u][1]); n   rev[u] = 0; n } n inline void rotate(const int& x) { n   int y = fa[x], z = fa[y]; n   int k = son[y][1] == x, w = son[x][k ^ 1]; n   if (notrt(y)) son[z][son[z][1] == y] = x; n   son[x][k ^ 1] = y; n   son[y][k] = w; n   if (w) fa[w] = y; n   fa[y] = x, fa[x] = z; n   pushup(y); n } n inline void splay(const int& x) { n   register int y = x, z = 0; n   st[++z] = y; n   while (notrt(y)) st[++z] = y = fa[y]; n   while (z) pushdown(st[z--]); n   while (notrt(x)) { n     y = fa[x], z = fa[y]; n     if (notrt(y)) rotate((son[z][1] == y) == (son[y][1] == x) ? y : x); n     rotate(x); n   } n   pushup(x); n } n inline void access(int u) { n   for (register int v = 0; u; u = fa[u]) { n     splay(u), son[u][1] = v; n     pushup(u), v = u; n   } n } n inline void makeroot(int u) { n   access(u), splay(u); n   pushr(u); n } n inline void link(int u, int v) { n   makeroot(u); n   fa[u] = v; n } n inline void split(int u, int v) { n   makeroot(u); n   access(v), splay(v); n } n inline int check(int u1, int v1, int u2, int v2) { n   split(u1, v1), pushc(v1, 1); n   split(u2, v2); n   int res = sum[v2]; n   split(u1, v1), pushc(v1, 0); n   return res; n } n int main() { n   int x, y, z, ans; n   read(n), read(q); n   for (register int i = 1; i <= n; ++i) tag[i] = -1; n   for (register int i = 2; i <= n; ++i) { n     read(x); n     link(x, i); n   } n   while (q--) { n     read(x), read(y), read(z); n     ans = check(x, y, x, z); n     ans = max(ans, check(x, y, y, z)); n     ans = max(ans, check(x, z, y, z)); n     printf( %d n , ans); n   } n   return 0; n } n


#include<bits/stdc++.h> n using namespace std; n const int maxn=1e4+10; n int vis[maxn]; n int a[maxn]; n int main() n { n     int T; n     scanf( %d ,&T); n     while(T--){ n         int n,d; n         scanf( %d%d ,&n,&d); n         for(int i=1;i<=n;i++){ n             scanf( %d ,&a[i]); n         } n         for(int k=1;k<=n;k++){ n             int tmp=a[k]; n             int x=tmp/d; n             int y=tmp%d; n             if(!y) printf( YES n ); n             else{ n                 int flag=10000; n                 for(int i=2;i<=9;i++){ n                     if(i*d%10==d-y){ n                         flag=i; n                         break; n                     } n                 } n                 if(flag==10000) flag=10; n                 if(flag<=x) printf( YES n ); n                 else printf( NO n ); n             } n         } n     } n     return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char to_da(char c) { n   if (c >=  A  && c <=  Z ) n     return c; n   else n     return c - 32; n } n char to_xiao(char c) { n   if (c >=  A  && c <=  Z ) n     return c + 32; n   else n     return c; n } n int main() { n   string s; n   int a; n   while (cin >> s >> a) { n     int len = s.length(); n     for (int i = 0; i < len; i++) { n       s[i] = to_xiao(s[i]); n       if (s[i] < a + 97) n         s[i] = to_da(s[i]); n       else n         s[i] = to_xiao(s[i]); n     } n     cout << s << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   set<string> S; n   long n; n   string a; n   cin >> n; n   for (long i = 0; i < n; i++) { n     cin >> a; n     string s =   ; n     long j = 0; n     while (j < a.size()) { n       if (a[j] ==  k ) { n         long k = j; n         while (a[k] ==  k ) k++; n         if (a[k] ==  h ) { n           j = k; n           s = s +  kh ; n         } else { n           s.push_back(a[j]); n         } n       } else if (a[j] ==  u ) { n         s = s +  oo ; n       } else if (a[j] ==  h ) { n         s = s +  kh ; n       } else { n         s.push_back(a[j]); n       } n       j++; n     } n     S.insert(s); n   } n   cout << S.size(); n } n


#include <bits/stdc++.h> n using namespace std; n int read() { n   int nm = 0, f = 1; n   char c = getchar(); n   for (; !isdigit(c); c = getchar()) n     if (c ==  - ) f = -1; n   for (; isdigit(c); c = getchar()) nm = nm * 10 + c -  0 ; n   return nm * f; n } n long long n, x, y; n char s[300010]; n int main() { n   n = read(), x = read(), y = read(); n   scanf( %s , s + 1); n   int len = strlen(s + 1); n   s[0] =  ? ; n   long long tot = 0; n   for (int i = 1; i <= len; i++) n     if (s[i] != s[i - 1] && s[i] ==  0 ) tot++; n   if (tot == 0) return puts( 0 ); n   cout << min(tot * y, tot * x - x + y); n   return 0; n } n