#include <bits/stdc++.h> n #pragma GCC optimize( O3 ) n #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native ) n #pragma GCC optimize( unroll-loops ) n #pragma comment(linker,  /stack:200000000 ) n using namespace std; n const int GRANDOM = n     std::chrono::high_resolution_clock::now().time_since_epoch().count(); n namespace vn16 { n template <class T> n struct like_array : is_array<T> {}; n template <class T, size_t N> n struct like_array<array<T, N>> : true_type {}; n template <class T> n struct like_array<vector<T>> : true_type {}; n template <class T> n bool is_like_array(const T& a) { n   return like_array<T>::value; n } n template <class T> n void _R(T& x) { n   std::cin >> x; n } n inline void _R(int& x) { scanf( %d , &x); } n inline void _R(int64_t& x) { scanf( %  SCNd64, &x); } n inline void _R(double& x) { scanf( %lf , &x); } n inline void _R(char& x) { scanf(  %c , &x); } n inline void _R(char* x) { scanf( %s , x); } n template <typename T> n inline void _R(vector<T>& v, size_t ie) { n   for (int i = 0; i < ie; i++) _R(v[i]); n } n template <typename T> n inline void _R(vector<T>& v) { n   _R(v, v.size()); n } n inline void R() {} n template <class T, class... U> n inline 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 template <typename T> n inline void _W(vector<T>& v, size_t ie) { n   for (int i = 0; i < ie; i++) { n     if (i > 0) _W(   ); n     _W(v[i]); n   } n   _W(  n ); n } n template <typename T> n inline void _W(vector<T>& v) { n   _W(v, v.size()); n } n template <class T> n inline 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 inline void W() {} n template <class T, class... U> n inline void W(const T& head, const U&... tail) { n   _W(head); n   if (sizeof...(tail)) putchar(   ), W(tail...); n } n template <class T, class... U> n inline void WL(const T& head, const U&... tail) { n   _W(head); n   putchar(sizeof...(tail) ?     :   n ); n   W(tail...); n } n template <class T> n void _RE(T& x) { n   cin >> x; n } n template <class Arg, class... Args> n void _RE(Arg& first, Args&... rest); n void _RE(double& x) { n   string t; n   _RE(t); n   x = stod(t); n } n void _RE(long double& x) { n   string t; n   _RE(t); n   x = stold(t); n } n template <class T> n void _RE(complex<T>& x); n template <class T1, class T2> n void _RE(pair<T1, T2>& p); n template <class T> n void _RE(vector<T>& a); n template <class T, size_t SZ> n void _RE(array<T, SZ>& a); n template <class Arg, class... Args> n void _RE(Arg& first, Args&... rest) { n   _RE(first); n   _RE(rest...); n } n template <class T> n void _RE(complex<T>& x) { n   T a, b; n   _RE(a, b); n   x = cd(a, b); n } n template <class T1, class T2> n void _RE(pair<T1, T2>& p) { n   _RE(p.f, p.s); n } n template <class T> n void _RE(vector<T>& a) { n   for (int i = 0, ie = sz(a); i < ie; i++) _RE(a[i]); n } n template <class T, size_t SZ> n void _RE(array<T, SZ>& a) { n   for (int i = 0; i < SZ; i++) _RE(a[i]); n } n };  // namespace vn16 n namespace vn16 { n template <typename T> n T gcd(T m, T n) { n   while (n) { n     T t = m % n; n     m = n; n     n = t; n   }; n   return m; n } n template <typename T> n T exgcd(T a, T b, T& sa, T& ta) { n   T q, r, sb = 0, tb = 1, sc, tc; n   sa = 1, ta = 0; n   if (b) do n       q = a / b, r = a - q * b, a = b, b = r, sc = sa - q * sb, sa = sb, n       sb = sc, tc = ta - q * tb, ta = tb, tb = tc; n     while (b); n   return a; n } n template <typename T> n T mul_inv(T a, T b) { n   T t1 = a, t2 = b, t3; n   T v1 = 1, v2 = 0, v3; n   T x; n   while (t2 != 1) n     x = t1 / t2, t3 = t1 - x * t2, v3 = v1 - x * v2, t1 = t2, t2 = t3, v1 = v2, n     v2 = v3; n   return (v2 + b) % b; n } n template <typename T> n T powmod(T a, T b, T MOD) { n   if (b < 0) return 0; n   T rv = 1; n   while (b) (b % 2) && (rv = (rv * a) % MOD), a = a * a % MOD, b /= 2; n   return rv; n } n template <typename T> n inline T isqrt(T k) { n   T r = sqrt((double)k) + 1; n   while (r * r > k) r--; n   while ((r + 1) * (r + 1) <= k) r++; n   return r; n } n template <typename T> n inline T icbrt(T k) { n   T r = cbrt((double)k) + 1; n   while (r * r * r > k) r--; n   return r; n } n template <typename T> n bool mul_overflow(T& r, T a, T b) { n   return __builtin_mul_overflow(a, b, &r); n } n template <long long n> n struct BitSize { n   enum { Size = BitSize<n / 2>::Size + 1 }; n }; n template <> n struct BitSize<0> { n   enum { Size = 1 }; n }; n template <> n struct BitSize<1> { n   enum { Size = 1 }; n }; n template <typename TH> n void _dbg(const char* sdbg, TH h) { n   cerr << sdbg <<  =  << h <<   n ; n } n template <typename TH, typename... TA> n void _dbg(const char* sdbg, TH h, TA... t) { n   while (*sdbg !=  , ) cerr << *sdbg++; n   cerr <<  =  << h <<  , ; n   _dbg(sdbg + 1, t...); n } n }  // namespace vn16 n namespace vn16 { n template <typename T> n int min_rotation(vector<T> s) { n   int a = 0, N = s.size(); n   for (int b = 0; b < N; b++) n     for (int i = 0; i < N; i++) { n       if (a + i == b || s[(a + i) % N] < s[(b + i) % N]) { n         b += max(0, i - 1); n         break; n       } n       if (s[(a + i) % N] > s[(b + i) % N]) { n         a = b; n         break; n       } n     } n   return a; n }; n template <typename T> n class StackGuard { n  private: n   T x; n  n  public: n   StackGuard(T x) : x(x) {} n   ~StackGuard() { x(); } n }; n }  // namespace vn16 n namespace vn16 {}; n namespace vn16 { n const int maxn = 1e5 + 7; n const int maxm = 23; n int n, m; n char s[maxn]; n int cnt2[maxm][maxm]; n int cnt[maxm]; n long long dp[1 << maxm]; n int main() { n   srand(GRANDOM); n   cin >> n >> m >> s; n   memset(cnt, 0, sizeof(cnt)); n   for (int i = 1; i < n; i++) { n     int x = s[i] -  a ; n     int y = s[i - 1] -  a ; n     cnt2[x][y]++; n     cnt2[y][x]++; n   } n   int maxs = (1 << m); n   dp[0] = 0; n   for (int x = 1; x < maxs; x++) { n     dp[x] = (long long)maxn * maxm * 10; n     long long c = 0; n     for (int i = 0; i < m; i++) { n       for (int j = i + 1; j < m; j++) { n         if (((x >> i) ^ (x >> j)) & 1) c += cnt2[i][j]; n       } n     } n     for (int i = 0; i < m; i++) n       if ((x >> i) & 1) dp[x] = min(dp[x], dp[x ^ (1 << i)] + c); n   } n   cout << dp[maxs - 1] << endl; n   return 0; n } n };  // namespace vn16 n int main(int argc, char* argv[]) { n   std::cin.sync_with_stdio(false); n   std::cin.tie(nullptr); n   return vn16::main(); n } n


#include <bits/stdc++.h> n using namespace std; n struct point { n   int x, y; n } a[5], b[5]; n int ans; n int dis(int i, int j) { n   int res = (a[i].x - a[j].x) * (a[i].x - a[j].x); n   return res + (a[i].y - a[j].y) * (a[i].y - a[j].y); n } n int ok() { n   map<int, int> mp; n   for (int i = 1; i < 4; i++) n     for (int j = i + 1; j <= 4; j++) mp[dis(i, j)]++; n   if (mp.size() != 2) return 0; n   int t; n   for (auto tmp : mp) { n     if (tmp.first == 0) return 0; n     t = tmp.second; n   } n   if (t == 4 || t == 2) return 1; n   return 0; n } n void Rotate(int p) { n   int x = a[p].x - b[p].x, y = a[p].y - b[p].y; n   a[p].x = -y + b[p].x; n   a[p].y = x + b[p].y; n } n void dfs(int p, int step) { n   if (p == 5) { n     if (ok()) ans = min(ans, step); n     return; n   } n   dfs(p + 1, step); n   for (int i = 1; i < 4; i++) { n     Rotate(p); n     dfs(p + 1, step + i); n   } n   Rotate(p); n } n int main() { n   int T; n   cin >> T; n   while (T--) { n     ans = 100; n     for (int i = 1; i <= 4; i++) cin >> a[i].x >> a[i].y >> b[i].x >> b[i].y; n     dfs(1, 0); n     if (ans == 100) n       puts( -1 ); n     else n       cout << ans << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long n, k, u, v, w; n unordered_map<long long, vector<long long>> m; n struct Key { n   long long N, p; n   bool operator==(const Key& other) const { n     return (N == other.N && p == other.p); n   } n }; n struct KeyHasher { n   size_t operator()(const Key& k) const { return k.N * 59 + k.p * 61; } n }; n set<pair<long long, long long>, greater<pair<long long, long long>>> sp[100010]; n unordered_map<Key, long long, KeyHasher> done, wt, val; n long long dfs(long long i, vector<bool>& vis) { n   vis[i] = 1; n   long long mx = 0; n   for (auto it : m[i]) { n     if (vis[it] == 0) { n       long long v = dfs(it, vis); n       long long jk = val[{it, i}] = v + wt[{it, i}]; n       sp[i].insert({jk, it}); n       mx = max(mx, val[{it, i}]); n     } n   } n   return mx; n } n void dfs2(long long i, vector<bool>& vis) { n   vis[i] = 1; n   for (auto it : m[i]) { n     if (vis[it] == 0) { n       long long mx = 0; n       for (auto pt : sp[i]) { n         if (it != pt.second) { n           mx = pt.first; n           break; n         } n       } n       long long jk = val[{i, it}] = mx + wt[{i, it}]; n       sp[it].insert({jk, i}); n       dfs2(it, vis); n     } n   } n } n int main() { n   cin >> n >> k; n   for (long long i = 1; i < n; i++) { n     cin >> u >> v >> w; n     m[u].push_back(v); n     m[v].push_back(u); n     wt[{u, v}] = wt[{v, u}] = w; n   } n   vector<bool> vis(n + 1, 0); n   vector<bool> vis2(n + 1, 0); n   dfs(1, vis); n   dfs2(1, vis2); n   long long mn = LLONG_MAX, ind; n   for (auto it : m) { n     long long mx = 0; n     for (auto i : it.second) mx = max(mx, val[{i, it.first}]); n     if (mn > mx) { n       mn = mx; n       ind = it.first; n     } n   } n   k--; n   vector<long long> v; n   v.push_back(ind); n   long long s = ind, e = ind; n   while (k) { n     long long mx = 0, in, f = 0, first = 0; n     for (auto it : m[s]) { n       if (done[{it, s}] == 0) { n         first = 1; n         if (mx < val[{it, s}]) { n           mx = val[{it, s}]; n           in = it; n         } n       } n     } n     if (s != e) { n       for (auto it : m[e]) { n         if (done[{it, e}] == 0) { n           first = 1; n           if (mx < val[{it, e}]) { n             f = 1; n             mx = val[{it, e}]; n             in = it; n           } n         } n       } n     } n     if (first == 0) break; n     if (f) { n       done[{e, in}] = done[{in, e}] = 1; n       e = in; n     } else { n       done[{s, in}] = done[{in, s}] = 1; n       s = in; n     } n     v.push_back(in); n     k--; n   } n   long long mx = 0; n   for (auto it : v) { n     for (auto i : m[it]) { n       if (done[{it, i}] == 0) mx = max(mx, val[{i, it}]); n     } n   } n   cout << mx; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m; n char gride[5010]; n vector<vector<char> > grid; n vector<vector<int> > pesq, pesq2; n vector<vector<int> > pdir, pdir2; n vector<vector<int> > pcima, pcima2; n vector<vector<int> > pbaxo, pbaxo2; n void apaga(int i, int j) { n   if (pesq2[i][j] != -1) pdir2[i][pesq2[i][j]] = pdir2[i][j]; n   if (pdir2[i][j] != -1) pesq2[i][pdir2[i][j]] = pesq2[i][j]; n   if (pcima2[i][j] != -1) pbaxo2[pcima2[i][j]][j] = pbaxo2[i][j]; n   if (pbaxo2[i][j] != -1) pcima2[pbaxo2[i][j]][j] = pcima2[i][j]; n } n int simula(int i, int j) { n   if (grid[i][j] ==  U ) { n     int k = pcima2[i][j]; n     if (k == -1) return 1; n     apaga(i, j); n     return 1 + simula(k, j); n   } n   if (grid[i][j] ==  D ) { n     int k = pbaxo2[i][j]; n     if (k == -1) return 1; n     apaga(i, j); n     return 1 + simula(k, j); n   } n   if (grid[i][j] ==  L ) { n     int k = pesq2[i][j]; n     if (k == -1) return 1; n     apaga(i, j); n     return 1 + simula(i, k); n   } n   if (grid[i][j] ==  R ) { n     int k = pdir2[i][j]; n     if (k == -1) return 1; n     apaga(i, j); n     return 1 + simula(i, k); n   } n   return 0; n } n int main() { n   scanf( %d %d , &n, &m); n   grid.resize(n); n   for (int i = 0; i < n; i++) { n     scanf( %s , gride); n     grid[i].resize(m); n     for (int j = 0; j < m; j++) grid[i][j] = gride[j]; n   } n   pesq.resize(n); n   pdir.resize(n); n   pcima.resize(n); n   pbaxo.resize(n); n   for (int i = 0; i < n; i++) { n     pesq[i].resize(m); n     pdir[i].resize(m); n     pcima[i].resize(m); n     pbaxo[i].resize(m); n     int atu = -1; n     for (int j = 0; j < m; j++) n       if (grid[i][j] !=  . ) { n         pesq[i][j] = atu; n         atu = j; n       } n     atu = -1; n     for (int j = m - 1; j >= 0; j--) n       if (grid[i][j] !=  . ) { n         pdir[i][j] = atu; n         atu = j; n       } n   } n   for (int j = 0; j < m; j++) { n     int atu = -1; n     for (int i = 0; i < n; i++) n       if (grid[i][j] !=  . ) { n         pcima[i][j] = atu; n         atu = i; n       } n     atu = -1; n     for (int i = n - 1; i >= 0; i--) n       if (grid[i][j] !=  . ) { n         pbaxo[i][j] = atu; n         atu = i; n       } n   } n   int best = 0; n   int qts = 0; n   for (int i = 0; i < n; i++) n     for (int j = 0; j < m; j++) n       if (grid[i][j] !=  . ) { n         pcima2 = pcima; n         pbaxo2 = pbaxo; n         pesq2 = pesq; n         pdir2 = pdir; n         int t = simula(i, j); n         if (t == best) n           qts++; n         else if (t > best) { n           best = t; n           qts = 1; n         } n       } n   printf( %d %d n , best, qts); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e6 + 3, INF = 1e9; n int main() { n   ios ::sync_with_stdio(0); n   cin.tie(NULL), cout.tie(NULL); n   long long n, last = 0, id = 0, ans = 0, i = 0; n   cin >> n; n   vector<pair<int, int> > v(n); n   for (auto &t : v) cin >> t.first >> t.second; n   for (; i <= N; ++i) { n     if (last) last--; n     if (v[id].first == i) { n       last += v[id].second; n       id++; n     } n     ans = max(ans, last); n     if (id == v.size()) { n       break; n     } n   } n   ans = max(ans, last); n   cout << i + last <<     << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int mod = 998244353; n const int INF = 1e9 + 7; n const int N = 1010; n const double pi = 3.1415926; n int n; n int t[110], d[110], p[110], pre[2010], now[2010], sum[2010], good[2010]; n int dp[2010]; n vector<int> v[2010]; n struct node { n   int t; n   int d; n   int p; n   int id; n } e[110]; n bool cmp(node a, node b) { return a.d < b.d; } n int main() { n   while (~scanf( %d , &n)) { n     for (int i = 0; i < 2010; i++) v[i].clear(); n     for (int i = 0; i < n; i++) { n       scanf( %d%d%d , &e[i].t, &e[i].d, &e[i].p); n       e[i].id = i + 1; n     } n     sort(e, e + n, cmp); n     memset(dp, 0, sizeof(dp)); n     ; n     memset(sum, 0, sizeof(sum)); n     ; n     memset(now, 0, sizeof(now)); n     ; n     memset(pre, 0, sizeof(pre)); n     ; n     int ans = 0, idx = 0, s1 = 0, s2 = 0; n     for (int i = 0; i < n; i++) { n       for (int j = e[i].d; j > e[i].t; j--) { n         s1 = 0; n         if (dp[j - e[i].t] + e[i].p > dp[j]) { n           dp[j] = dp[j - e[i].t] + e[i].p; n           sum[j] = sum[j - e[i].t] + 1; n           v[j] = v[j - e[i].t]; n           v[j].push_back(e[i].id); n         } n         if (dp[j] > ans) { n           idx = j; n           ans = dp[j]; n         } n       } n     } n     printf( %d n , ans); n     printf( %d n , sum[idx]); n     for (int i = 0; i < v[idx].size(); i++) { n       printf( %d  , v[idx][i]); n     } n     printf(  n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void solve(); n int main() { n   ios::sync_with_stdio(0); n   solve(); n   return 0; n } n pair<pair<double, double>, pair<double, double> > rects[100]; n void solve() { n   int n; n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> rects[i].first.first >> rects[i].first.second >> n         rects[i].second.first >> rects[i].second.second; n     if (rects[i].first.first > rects[i].second.first) n       swap(rects[i].first.first, rects[i].second.first); n     if (rects[i].first.second > rects[i].second.second) n       swap(rects[i].first.second, rects[i].second.second); n     for (int j = 0; j < i; j++) { n       double cx = 0, cy = 0, m = 0; n       for (int k = j + 1; k <= i; k++) { n         double l = fabs(rects[k].first.first - rects[k].second.first); n         double lll = l * l * l; n         m += lll; n         double x = (rects[k].first.first + rects[k].second.first) / 2.0; n         double y = (rects[k].first.second + rects[k].second.second) / 2.0; n         cx += lll * x; n         cy += lll * y; n       } n       cx /= m; n       cy /= m; n       if (rects[j].first.first > cx || rects[j].first.second > cy || n           rects[j].second.first < cx || rects[j].second.second < cy) { n         cout << i; n         return; n       } n     } n   } n   cout << n; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 8e5 + 1000; n long long re[maxn]; n vector<long long> v; n int sum[maxn]; n struct node { n   long long l, r; n } a[maxn]; n long long ans[maxn]; n int getid(long long x) { n   return lower_bound(v.begin(), v.end(), x) - v.begin() + 1; n } n int main() { n   int n; n   cin >> n; n   for (int i = 0; i < n; i++) { n     scanf( %lld%lld , &a[i].l, &a[i].r); n     v.push_back(a[i].l); n     v.push_back(a[i].r); n     v.push_back(a[i].l + 1); n     v.push_back(a[i].r + 1); n   } n   sort(v.begin(), v.end()); n   v.erase(unique(v.begin(), v.end()), v.end()); n   int sz = v.size(); n   for (int i = 0; i < v.size(); i++) { n     re[i + 1] = v[i]; n   } n   for (int i = 0; i < n; i++) { n     int l = getid(a[i].l); n     int r = getid(a[i].r); n     sum[l]++; n     sum[r + 1]--; n   } n   for (int i = 1; i <= sz; i++) { n     sum[i] = sum[i - 1] + sum[i]; n   } n   for (int i = 1; i < sz; i++) { n     ans[sum[i]] += re[i + 1] - re[i]; n   } n   for (int i = 1; i <= n; i++) { n     printf( %lld  , ans[i]); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, k, x, y, H[300005], d, ant[300005]; n vector<int> v[300005], st, L; n void dfs(int nod) { n   int ok = 0; n   st.push_back(nod); n   H[nod] = st.size(); n   if (H[nod] >= d) { n     cout <<  PATH n ; n     cout << st.size() <<   n ; n     for (auto it : st) cout << it <<    ; n     exit(0); n   } n   for (auto it : v[nod]) n     if (!H[it]) { n       ant[it] = nod; n       dfs(it); n       ok = 1; n     } n   if (!ok) L.push_back(nod); n   st.pop_back(); n } n bool _try(int a, int b) { n   if (H[a] < H[b]) swap(a, b); n   if (H[a] - H[b] + 1 >= 3 && (H[a] - H[b] + 1) % 3 != 0) { n     cout << H[a] - H[b] + 1 <<   n ; n     int crt = a; n     while (crt != b) { n       cout << crt <<    ; n       crt = ant[crt]; n     } n     cout << crt <<   n ; n     return 1; n   } n   return 0; n } n bool _try2(int a, int b, int c) { n   if (H[a] < H[b]) swap(a, b); n   if (H[a] - H[b] + 2 >= 3 && (H[a] - H[b] + 2) % 3 != 0) { n     cout << H[a] - H[b] + 2 <<   n ; n     int crt = a; n     while (crt != b) { n       cout << crt <<    ; n       crt = ant[crt]; n     } n     cout << crt <<     << c <<   n ; n     return 1; n   } n   return 0; n } n int main() { n   ios::sync_with_stdio(false); n   cin >> n >> m >> k; n   d = n / k + (n % k != 0); n   for (int i = 1; i <= m; i++) { n     cin >> x >> y; n     v[x].push_back(y); n     v[y].push_back(x); n   } n   dfs(1); n   cout <<  CYCLES n ; n   for (auto it : L) { n     if (k == 0) break; n     k--; n     if (_try(it, v[it][0])) continue; n     if (_try(it, v[it][1])) continue; n     if (_try(it, v[it][2])) continue; n     if (_try2(v[it][0], v[it][1], it)) continue; n     if (_try2(v[it][0], v[it][2], it)) continue; n     if (_try2(v[it][1], v[it][2], it)) continue; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   int a[n]; n   int b[n]; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n     b[i] = a[i]; n   } n   sort(a, a + n); n   int left = 0, right = 0; n   for (int i = 0; i < n; i++) { n     if (b[i] != a[i]) { n       left = i; n       break; n     } n   } n   for (int i = n - 1; i >= 0; i--) { n     if (b[i] != a[i]) { n       right = i; n       break; n     } n   } n   int i = left; n   int j = right; n   while (left < right) { n     swap(b[left], b[right]); n     left++; n     right--; n   } n   int flag = 1; n   for (int i = 0; i < n; i++) { n     if (a[i] != b[i]) { n       flag = 0; n       break; n     } n   } n   if (flag) { n     cout <<  yes  << endl; n     cout << i + 1 <<     << j + 1; n   } else n     cout <<  no ; n } n


#include <bits/stdc++.h> n using namespace std; n long long power(long long a, long long b) { n   if (a == 1 || b == 0) return 1; n   long long c = power(a, b / 2); n   long long res = 1; n   res = c * c; n   if (res >= 1000000007) res %= 1000000007; n   if (b % 2) res *= a; n   if (res >= 1000000007) res %= 1000000007; n   return res; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   long long n; n   cin >> n; n   string s; n   cin >> s; n   map<char, long long> count; n   for (long long i = 0; i < n; i++) { n     count[s[i]]++; n   } n   vector<long long> v; n   for (auto &i : count) { n     v.push_back(i.second); n   } n   long long ans = 0; n   sort(v.begin(), v.end(), greater<long long>()); n   for (long long i = 0; i < v.size(); i++) { n     if (v[i] == v[0]) ans++; n   } n   cout << power(ans, n); n } n


#include <bits/stdc++.h> n using namespace std; n long long N, K, dp[501][501]; n long long p2[501]; n void pre() { n   long long i; n   p2[0] = 1; n   for (i = 1; i < 501; ++i) p2[i] = (p2[i - 1] * 2) % 1000000007; n } n long long rec(long long maxinc, long long cur) { n   if (maxinc > K) return 0; n   if (cur > N) return (maxinc == K); n   long long last = cur - 1; n   long long &ret = dp[maxinc][cur]; n   if (ret != -1) return ret; n   long long temp, mul = 1; n   ret = 0; n   long long cc = cur; n   for (; cur <= N; ++cur) { n     mul = (mul * p2[last]) % 1000000007; n     temp = (rec(maxinc + 1, cur + 1) * (p2[cur - last] - 1)) % 1000000007; n     ret = (ret + (temp * mul) % 1000000007) % 1000000007; n   } n   if (maxinc == K) ret = (ret + mul) % 1000000007; n   return ret; n } n int main() { n   pre(); n   while (scanf( %I64d %I64d , &N, &K) != EOF) { n     memset(dp, -1, sizeof(dp)); n     printf( %I64d n , rec(0, 1)); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline int _Int() { n   int x; n   scanf( %d , &x); n   return x; n } n long long int bigMod(long long int A, long long int P, int M) { n   long long int R = 1; n   for (A %= M; P; P >>= 1) { n     if (P & 1) R = (R * A) % M; n     A = (A * A) % M; n   } n   return R; n } n long long int bigMul(long long int A, long long int B, long long int M) { n   long long int R = 0; n   for (A %= M; B; B >>= 1) { n     if (B & 1) R = (R + A) % M; n     A = (A + A) % M; n   } n   return R; n } n long long int negMod(long long int A, long long int B) { n   return (((A % B) + B) % B); n } n long long int invMod(long long int A, long long int M) { n   return bigMod(A, M - 2, M); n } n unsigned long long int _pow(unsigned long long int A, int P) { n   unsigned long long int R = 1; n   for (; P; P >>= 1) { n     if (P & 1) R = (R * A); n     A = (A * A); n   } n   return R; n } n template <class T> n T GCD(T x, T y) { n   while (x) x ^= y ^= x ^= y %= x; n   return y; n } n template <class T> n bool inRng(T u, T v, T x) { n   return u <= x && x <= v; n } n const int M = 300000 + 7; n int n, edges, source; n vector<int> graph[M]; n struct edge { n   int type; n   int u, v; n   void scan(int i) { n     scanf( %d%d%d , &type, &u, &v); n     graph[u].push_back(i); n     if (type == 2) graph[v].push_back(i); n   } n } eee[M]; n char ans[M]; n bool vis[M]; n void bfs() { n   queue<int> qe; n   qe.push(source); n   vis[source] = 1; n   while (qe.size()) { n     int u = qe.front(); n     qe.pop(); n     for (int i = graph[u].size() - 1; i >= 0; i--) { n       int first = graph[u][i], v; n       if (eee[first].u == u) n         v = eee[first].v; n       else n         v = eee[first].u; n       if (eee[first].type == 2 && !ans[first]) { n         if (eee[first].u == u) n           ans[first] =  + ; n         else n           ans[first] =  - ; n       } n       if (!vis[v]) qe.push(v); n       vis[v] = 1; n     } n   } n   for (int i = 0; i < edges; i++) { n     if (eee[i].type == 2 && !ans[i]) ans[i] =  + ; n   } n } n void bfs_again() { n   queue<int> qe; n   qe.push(source); n   vis[source] = 1; n   while (qe.size()) { n     int u = qe.front(); n     qe.pop(); n     for (int i = graph[u].size() - 1; i >= 0; i--) { n       int first = graph[u][i], v; n       if (eee[first].u == u) n         v = eee[first].v; n       else n         v = eee[first].u; n       if (eee[first].type == 2 && !ans[first]) { n         if (eee[first].u == u) n           ans[first] =  - ; n         else n           ans[first] =  + ; n       } n       if (eee[first].type == 1 && !vis[v]) { n         qe.push(v); n         vis[v] = 1; n       } n     } n   } n   for (int i = 0; i < edges; i++) { n     if (eee[i].type == 2 && !ans[i]) ans[i] =  + ; n   } n } n void Main() { n   scanf( %d%d%d , &n, &edges, &source); n   for (int i = 0; i < edges; i++) eee[i].scan(i); n   bfs(); n   int cnt = 0; n   for (int i = 1; i <= n; i++) cnt += vis[i]; n   printf( %d n , cnt); n   for (int i = 0; i < edges; i++) { n     if (eee[i].type == 2) printf( %c , ans[i]); n   } n   putchar(10); n   memset(vis, 0, sizeof vis); n   memset(ans, 0, sizeof ans); n   bfs_again(); n   cnt = 0; n   for (int i = 1; i <= n; i++) cnt += vis[i]; n   printf( %d n , cnt); n   for (int i = 0; i < edges; i++) { n     if (eee[i].type == 2) printf( %c , ans[i]); n   } n   putchar(10); n } n int main() { n   Main(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 5005; n template <typename T> n inline void read(T &AKNOI) { n   T x = 0, flag = 1; n   char ch = getchar(); n   while (!isdigit(ch)) { n     if (ch ==  - ) flag = -1; n     ch = getchar(); n   } n   while (isdigit(ch)) { n     x = x * 10 + ch -  0 ; n     ch = getchar(); n   } n   AKNOI = flag * x; n } n namespace ModCalculator { n const int MOD = 998244353; n inline void Inc(int &x, int y) { n   x += y; n   if (x >= MOD) x -= MOD; n } n inline void Dec(int &x, int y) { n   x -= y; n   if (x < 0) x += MOD; n } n inline int Add(int x, int y) { n   Inc(x, y); n   return x; n } n inline int Sub(int x, int y) { n   Dec(x, y); n   return x; n } n inline int Mul(int x, int y) { return 1LL * x * y % MOD; } n inline int Ksm(int x, int k) { n   int ret = 1; n   for (; k; k >>= 1) { n     if (k & 1) ret = Mul(ret, x); n     x = Mul(x, x); n   } n   return ret; n } n inline int Inv(int x) { return Ksm(x, MOD - 2); } n }  // namespace ModCalculator n using namespace ModCalculator; n int n, fac[N], finv[N], E[N][N]; n void init() { n   read(n); n   fac[0] = 1; n   for (int i = 1; i <= n; ++i) { n     fac[i] = Mul(fac[i - 1], i); n   } n   finv[n] = Inv(fac[n]); n   for (int i = n; i >= 1; --i) { n     finv[i - 1] = Mul(finv[i], i); n   } n   E[0][0] = 1; n   for (int i = 1; i <= n; ++i) { n     E[i][0] = 1; n     for (int j = 1; j <= i; ++j) { n       E[i][j] = Add(Mul(E[i - 1][j], j + 1), Mul(E[i - 1][j - 1], i - j)); n     } n   } n } n void solve() { n   for (int i = 1; i <= n; ++i) { n     int ans = 0; n     for (int j = i; j <= n; ++j) { n       Inc(ans, Mul(E[j][i - 1], Mul(fac[n], finv[j]))); n     } n     printf( %d  , ans); n   } n } n int main() { n   init(); n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double PI = 3.14159265389793238462643383279502884197169; n const long long MOD = 1e9 + 7; n const long long MOD1 = 998244353; n const long long MODo = 1e9; n const int MAXN = 2e5 + 2; n const int oo = 1e9; n const long long oo15 = 1e15; n const long long oo18 = 1e18 + 3; n const long long oooo = 9223372036854775807; n void solve() { n   int n, dem1 = 0, dem0 = 0; n   cin >> n; n   for (int i = 1; i <= n; i++) { n     int x; n     cin >> x; n     if (x == 1) n       dem1++; n     else if (x == 0) n       dem0++; n   } n   long long res = 1; n   for (int i = 1; i <= dem0; i++) res *= 2; n   cout << dem1 * res <<   n ; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int testcase = 1; n   cin >> testcase; n   while (testcase--) solve(); n } n


#include <bits/stdc++.h> n using namespace std; n bool sortbysec(const pair<long long, pair<long long, long long> > &a, n                const pair<long long, pair<long long, long long> > &b) { n   return (a.second.first < b.second.first); n } n bool sortbyth(const pair<long long, pair<long long, long long> > &a, n               const pair<long long, pair<long long, long long> > &b) { n   return (a.second.second < b.second.second); n } n long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } n long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); } n long long min(long long a, long long b) { return a < b ? a : b; } n long long max(long long a, long long b) { return a > b ? a : b; } n long long max3(long long a, long long b, long long c) { n   return max(max(a, b), c); n } n long long max4(long long a, long long b, long long c, long long d) { n   return max(max(a, b), max(c, d)); n } n long long min3(long long a, long long b, long long c) { n   return min(min(a, b), c); n } n long long min4(long long a, long long b, long long c, long long d) { n   return min(min(a, b), min(c, d)); n } n long long po(long long x, long long n, long long mod = 1000000007) { n   if (n == 0) { n     return 1; n   } n   long long m = po(x, n / 2, mod); n   m *= m; n   m %= mod; n   if (n % 2) { n     m *= x; n     m %= mod; n   } n   return m; n } n int main() { n   cin.tie(0); n   cout.tie(0); n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   clock_t startTime = clock(); n   cout << fixed << setprecision(12); n   long long n; n   cin >> n; n   vector<long long> v(n); n   for (long long i = 0; i < n; i++) cin >> v[i]; n   set<long long> ans, s; n   for (long long i = 0; i < n; i++) { n     set<long long> temp; n     temp.insert(v[i]); n     auto it = s.begin(); n     while (it != s.end()) { n       temp.insert(*it | v[i]); n       it++; n     } n     ans.insert(temp.begin(), temp.end()); n     s = temp; n   } n   cout << ans.size() <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 5; n bool sortcol(const vector<int>& v1, const vector<int>& v2) { n   return v1[0] < v2[0]; n } n int main() { n   int n; n   cin >> n; n   vector<vector<long long> > yr; n   long long max = 0, count = 0, year = 0; n   for (int a = 0; a < n; a++) { n     long long x, y; n     cin >> x >> y; n     yr.push_back({x, 1}); n     yr.push_back({y, -1}); n   } n   sort(yr.begin(), yr.end()); n   for (int a = 0; a < 2 * n; a++) { n     count += yr[a][1]; n     if (yr[a][1] == 1 && count > max) { n       max = count; n       year = yr[a][0]; n     } n   } n   cout << year <<     << max << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const double PI = 2 * acos(0); n int rev(int num, int lg_n) { n   int res = 0; n   for (int i = 0; i < lg_n; ++i) n     if (num & (1 << i)) res |= 1 << (lg_n - 1 - i); n   return res; n } n void fft(vector<complex<double>>& a, bool invert) { n   int n = (int)a.size(); n   int lg_n = 0; n   while ((1 << lg_n) < n) ++lg_n; n   for (int i = 0; i < n; ++i) n     if (i < rev(i, lg_n)) swap(a[i], a[rev(i, lg_n)]); n   for (int len = 2; len <= n; len <<= 1) { n     double ang = 2 * PI / len * (invert ? -1 : 1); n     complex<double> wlen(cos(ang), sin(ang)); n     for (int i = 0; i < n; i += len) { n       complex<double> w(1); n       for (int j = 0; j < len / 2; ++j) { n         complex<double> u = a[i + j], v = a[i + j + len / 2] * w; n         a[i + j] = u + v; n         a[i + j + len / 2] = u - v; n         w *= wlen; n       } n     } n   } n   if (invert) n     for (int i = 0; i < n; ++i) a[i] /= n; n } n vector<int> mult(vector<int> a, vector<int> b) { n   int logn = 0; n   while ((1 << logn) < max(a.size(), b.size())) logn++; n   while (a.size() < (1 << logn)) a.push_back(0); n   while (b.size() < (1 << logn)) b.push_back(0); n   vector<complex<double>> A((1 << logn)), B((1 << logn)); n   for (int i = 0; i < (1 << logn); ++i) { n     A[i] = a[i]; n     B[i] = b[i]; n   } n   fft(A, 0); n   fft(B, 0); n   for (int i = 0; i < (1 << logn); ++i) { n     A[i] *= B[i]; n   } n   fft(A, 1); n   vector<int> ans((1 << logn)); n   for (int i = 0; i < (1 << logn); ++i) { n     ans[i] = (int)(A[i].real() + 0.5); n   } n   return ans; n } n void dfs(int v, vector<int>& used, vector<vector<int>>& g) { n   used[v] = 1; n   for (auto u : g[v]) { n     if (!used[u]) { n       dfs(u, used, g); n     } n   } n } n void solve() { n   string s, t; n   cin >> s >> t; n   int n = s.size(), m = t.size(); n   int N =  f  -  a  + 1; n   vector<vector<vector<int>>> G(n - m + 1, vector<vector<int>>(N)); n   for (char c1 =  a ; c1 <=  f ; ++c1) { n     for (int c2 =  a ; c2 <=  f ; ++c2) { n       vector<int> a(n), b(m); n       for (int i = 0; i < n; ++i) { n         a[i] = (c1 == s[i]); n       } n       for (int j = 0; j < m; ++j) { n         b[j] = (c2 == t[j]); n       } n       reverse(b.begin(), b.end()); n       vector<int> res = mult(a, b); n       for (int k = m - 1; k < m - 1 + n - m + 1; ++k) { n         if (res[k]) { n           G[k - m + 1][c1 -  a ].push_back(c2 -  a ); n           G[k - m + 1][c2 -  a ].push_back(c1 -  a ); n         } n       } n     } n   } n   for (int p = 0; p < n - m + 1; ++p) { n     vector<int> used(N); n     int comp = 0; n     for (int i = 0; i < N; ++i) { n       if (!used[i]) { n         dfs(i, used, G[p]); n         comp++; n       } n     } n     cout << N - comp <<    ; n   } n } n int32_t main() { n   std::ios_base::sync_with_stdio(0); n   std::cin.tie(0); n   std::cout.tie(0); n   int tt = 1; n   while (tt--) { n     solve(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n string s1, s2; n int ar[200001]; n int n; n int n2; n bool possible(int check) { n   int posi[200001] = {0}; n   for (int i = 0; i < check + 1; i++) { n     posi[ar[i]]++; n   } n   int start1 = 0; n   int start2 = 0; n   while (start1 < n && start2 < n2) { n     if (posi[start1]) { n       start1++; n       continue; n     } n     if (s1[start1] == s2[start2]) { n       start1++; n       start2++; n     } else n       start1++; n   } n   if (start2 == n2) { n     return true; n   } n   return false; n } n int main() { n   cin >> s1 >> s2; n   n = s1.length(); n   n2 = s2.length(); n   for (int i = 0; i < n; i++) { n     scanf( %d , &ar[i]); n     ar[i]--; n   } n   int start = 0; n   int end = n; n   int ans = -1; n   while (start < end) { n     int mid = (start + end) / 2; n     if (possible(mid)) { n       ans = mid; n       start = mid + 1; n     } else { n       end = mid; n     } n   } n   cout << ans + 1 << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n void fmax(T &a, T b) { n   if (a < b) a = b; n } n template <class T> n void fmin(T &a, T b) { n   if (a > b) a = b; n } n const int N = 1e5 * 3 + 10; n int a[N][3], c[N], n, m, w[N]; n queue<int> Q; n int main() { n   cin >> n >> m; n   for (int i = (int)1; i <= (int)n; i++) w[i] = -1; n   for (int i = 0; i < (int)m; i++) { n     int x, y; n     cin >> x >> y; n     a[x][c[x]++] = y; n     a[y][c[y]++] = x; n   } n   for (int z = (int)1; z <= (int)n; z++) n     if (-1 == w[z]) { n       Q.push(z); n       int cnt = 0; n       while (!Q.empty()) { n         cnt++; n         if (cnt > n * 20) { n           cout << -1 << endl; n           return 0; n         } n         int i = Q.front(); n         Q.pop(); n         int t[2] = {0, 0}; n         for (int j = 0; j < (int)c[i]; j++) n           if (-1 != w[a[i][j]]) t[w[a[i][j]]]++; n         if (w[i] == (t[0] > t[1])) continue; n         w[i] = (t[0] > t[1]); n         for (int j = 0; j < (int)c[i]; j++) Q.push(a[i][j]); n       } n     } n   for (int i = (int)1; i <= (int)n; i++) cout << w[i]; n   cout << endl; n } n


#include <iostream> n #include <vector> n #include  <numeric> n #include<cstdlib> n #include <algorithm>    // std::random_shuffle n #define MODD 998244353 n #define ll long long n using namespace std; n  n ll modpow(ll x, ll y) { n     ll xs = x; n     ll answer = 1; n     while(y) { n         if (y&1) { n             answer = (answer * xs) % MODD; n         } n         y >>= 1; n         xs = (xs * xs) % MODD ; n     } n     return answer; n } n  n  n ll D[22][55555]; n  n char buf[58000000]; n  n int pos; n ll readint() { n     while(buf[pos]< 0  || buf[pos]> 9 ) n         pos++; n     ll m=0; n     while(buf[pos]>= 0  && buf[pos]<= 9 ) { n         m=m*10+buf[pos]- 0 ; n         pos++; n     } n     return m; n } n  n  n int main() { n     fread(buf, 1, 51000100, stdin); n     pos=0; n     int n,m; n     n=readint(); n     m=readint(); n     for(int i=1;i<=n;i++) { n         for(int j=1;j<=m;j++) { n             D[i][j]=readint(); n         } n     } n  n     ll fact = 1; n     for(ll i=1;i<=n;i++) { n         fact = (fact*i)%MODD; n     } n  n     ll factinv = modpow(fact, MODD-2); n  n     ll counts[22]; n     ll ans = 0; n     for(int j=1;j<=m;j++) { n         for(int step=1;step<=n;step++) { n             // number of cities with distance >= step+1 n             counts[step]=0; n             for(int i=1;i<=n;i++) { n                 counts[step]+=(D[i][j]>=step+1); n             } n         } n         counts[n+1]=0; n         ll prod = 1; n         for(int step=n;step>=1;step--) { n             prod = (prod * (counts[step]-(n-step)))%MODD; n         } n         prod = (prod * factinv)%MODD; n  n         ll prob_selected = (1-prod+MODD)%MODD; n         ans += prob_selected; n         ans %= MODD; n     } n  n     ans = (ans + MODD)%MODD; n  n     cout << ans << endl; n }


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long n, a, b, sum = 1; n   cin >> n >> a >> b; n   if (n == 1) { n     puts( 1 ); n     return 0; n   } n   if (b == 0 && a == n - 1) { n     puts( -1 ); n     return 0; n   } n   bool fl = (b == 0); n   int now = 1; n   vector<long long> ans(n, 1); n   while (now < ans.size() && b > 0) { n     ans[now] = sum + 1; n     sum += ans[now]; n     b--; n     now++; n   } n   while (now < ans.size() && a > 0) { n     ans[now] = ans[now - 1] + 1; n     a--; n     now++; n   } n   if (fl && ans.size() >= 2) { n     sum = ans.back(); n     ans.insert(ans.begin(), sum); n     ans.pop_back(); n   } n   for (int i = 0; i < ans.size(); i++) { n     if (ans[i] > 50000) { n       puts( -1 ); n       return 0; n     } n   } n   for (int i = 0; i < ans.size(); i++) { n     printf( %lld  , ans[i]); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 1e9 + 1; n const long long LINF = 1e18 + 1; n int n; n int X1_1 = 1; n int Y1_1 = 1; n int X2_1 = 2; n int Y2_1 = 2; n int X1_2 = 4; n int Y1_2 = 4; n int X2_2 = 5; n int Y2_2 = 5; n int ask(int x1, int y1, int x2, int y2) { n   cout <<  ?   << x1 <<     << y1 <<     << x2 <<     << y2 << endl; n   int res; n   cin >> res; n   return res; n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   cin >> n; n   int lx, rx, ly, ry; n   { n     int left = 0; n     int right = n; n     while (right - left > 1) { n       int mid = (left + right) / 2; n       if (ask(1, 1, mid, n) == 2) { n         right = mid; n       } else { n         left = mid; n       } n     } n     rx = right; n   } n   { n     int left = 1; n     int right = n + 1; n     while (right - left > 1) { n       int mid = (left + right) / 2; n       if (ask(mid, 1, n, n) == 2) { n         left = mid; n       } else { n         right = mid; n       } n     } n     lx = left; n   } n   { n     int left = 0; n     int right = n; n     while (right - left > 1) { n       int mid = (left + right) / 2; n       if (ask(1, 1, n, mid) == 2) { n         right = mid; n       } else { n         left = mid; n       } n     } n     ry = right; n   } n   { n     int left = 1; n     int right = n + 1; n     while (right - left > 1) { n       int mid = (left + right) / 2; n       if (ask(1, mid, n, n) == 2) { n         left = mid; n       } else { n         right = mid; n       } n     } n     ly = left; n   } n   int bord_x; n   { n     int left = lx - 1; n     int right = rx; n     while (right - left > 1) { n       int mid = (left + right) / 2; n       if (ask(lx, ly, mid, ry) == 1) { n         right = mid; n       } else { n         left = mid; n       } n     } n     bord_x = right; n   } n   int bord_y; n   { n     int left = ly - 1; n     int right = ry; n     while (right - left > 1) { n       int mid = (left + right) / 2; n       if (ask(lx, ly, rx, mid) == 1) { n         right = mid; n       } else { n         left = mid; n       } n     } n     bord_y = right; n   } n   if (bord_x == rx || ask(bord_x + 1, ly, rx, ry) != 1) { n     if (bord_y == ry || ask(lx, bord_y + 1, rx, ry) != 1) { n       assert(false); n     } n     int y1_1 = ly; n     int y2_1 = bord_y; n     int x1_1, x2_1; n     { n       int left = lx - 1; n       int right = rx; n       while (right - left > 1) { n         int mid = (left + right) / 2; n         if (ask(lx, y1_1, mid, y2_1) == 1) { n           right = mid; n         } else { n           left = mid; n         } n       } n       x2_1 = right; n     } n     { n       int left = lx; n       int right = rx + 1; n       while (right - left > 1) { n         int mid = (left + right) / 2; n         if (ask(mid, y1_1, rx, y2_1) == 1) { n           left = mid; n         } else { n           right = mid; n         } n       } n       x1_1 = left; n     } n     int y1_2; n     int y2_2 = ry; n     int x1_2, x2_2; n     { n       int left = bord_y + 1; n       int right = ry + 1; n       while (right - left > 1) { n         int mid = (left + right) / 2; n         if (ask(lx, mid, rx, ry) == 1) { n           left = mid; n         } else { n           right = mid; n         } n       } n       y1_2 = left; n     } n     { n       int left = lx - 1; n       int right = rx; n       while (right - left > 1) { n         int mid = (left + right) / 2; n         if (ask(lx, y1_2, mid, y2_2) == 1) { n           right = mid; n         } else { n           left = mid; n         } n       } n       x2_2 = right; n     } n     { n       int left = lx; n       int right = rx + 1; n       while (right - left > 1) { n         int mid = (left + right) / 2; n         if (ask(mid, y1_2, rx, y2_2) == 1) { n           left = mid; n         } else { n           right = mid; n         } n       } n       x1_2 = left; n     } n     cout <<  !   << x1_1 <<     << y1_1 <<     << x2_1 <<     << y2_1 <<     n          << x1_2 <<     << y1_2 <<     << x2_2 <<     << y2_2 << endl; n   } else { n     int x1_1 = lx; n     int x2_1 = bord_x; n     int y1_1, y2_1; n     { n       int left = ly - 1; n       int right = ry; n       while (right - left > 1) { n         int mid = (left + right) / 2; n         if (ask(x1_1, ly, x2_1, mid) == 1) { n           right = mid; n         } else { n           left = mid; n         } n       } n       y2_1 = right; n     } n     { n       int left = ly; n       int right = ry + 1; n       while (right - left > 1) { n         int mid = (left + right) / 2; n         if (ask(x1_1, mid, x2_1, ry) == 1) { n           left = mid; n         } else { n           right = mid; n         } n       } n       y1_1 = left; n     } n     int x1_2; n     int x2_2 = rx; n     int y1_2, y2_2; n     { n       int left = bord_x + 1; n       int right = rx + 1; n       while (right - left > 1) { n         int mid = (left + right) / 2; n         if (ask(mid, ly, rx, ry) == 1) { n           left = mid; n         } else { n           right = mid; n         } n       } n       x1_2 = left; n     } n     { n       int left = ly - 1; n       int right = ry; n       while (right - left > 1) { n         int mid = (left + right) / 2; n         if (ask(x1_2, ly, x2_2, mid) == 1) { n           right = mid; n         } else { n           left = mid; n         } n       } n       y2_2 = right; n     } n     { n       int left = ly; n       int right = ry + 1; n       while (right - left > 1) { n         int mid = (left + right) / 2; n         if (ask(x1_2, mid, x2_2, ry) == 1) { n           left = mid; n         } else { n           right = mid; n         } n       } n       y1_2 = left; n     } n     cout <<  !   << x1_1 <<     << y1_1 <<     << x2_1 <<     << y2_1 <<     n          << x1_2 <<     << y1_2 <<     << x2_2 <<     << y2_2 << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline long long read() { n   char ch = getchar(); n   long long nega = 1; n   while (!isdigit(ch)) { n     if (ch ==  - ) nega = -1; n     ch = getchar(); n   } n   long long ans = 0; n   while (isdigit(ch)) { n     ans = ans * 10 + ch - 48; n     ch = getchar(); n   } n   if (nega == -1) return -ans; n   return ans; n } n inline long long min(long long x, long long y, long long z) { n   return min(x, min(y, z)); n } n inline long long max(long long x, long long y, long long z) { n   return max(x, max(y, z)); n } n inline long long add(long long x, long long y) { n   return x + y >= 998244353 ? x + y - 998244353 : x + y; n } n inline long long add(long long x, long long y, long long z) { n   return add(add(x, y), z); n } n inline long long sub(long long x, long long y) { n   return x - y < 0 ? x - y + 998244353 : x - y; n } n inline long long mul(long long x, long long y) { n   return 1LL * x * y % 998244353; n } n inline long long mul(long long x, long long y, long long z) { n   return mul(mul(x, y), z); n } n signed main() { n   long long a, b, c, d; n   cin >> a >> b >> c >> d; n   long long ans = 0; n   for (long long i = c; i <= d; i++) { n     long long m = i - b + 1; n     if (m >= a && c - b + 1 > 0) { n       long long l = max(a, i - c); n       long long d = c - i + l, e = c - i + min(b, m); n       if (e >= d) ans += (e + d) * (e - d + 1) / 2; n     } n     long long L = b - max(m, a - 1); n     if (c - b + 1 >= 0 && b > m) ans += L * (c - b + 1); n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long N; n int sol; n int main() { n   scanf( %I64d , &N); n   while (N % 3 == 0) N /= 3; n   printf( %I64d n , (N + 2) / 3); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using i64 = long long; n constexpr int MAX = 400010; n constexpr int MOD = 1000000007; n i64 fac[MAX], inv[MAX]; n int l[MAX], r[MAX], x[MAX], cnt[MAX]; n i64 ModPow(i64 a, i64 b, i64 p = MOD) { n   i64 ret = 1; n   for (a %= p; b; b >>= 1) { n     if (b & 1) ret = ret * a % p; n     a = a * a % p; n   } n   return ret; n } n inline i64 Inv(i64 x, i64 p = MOD) { return ModPow(x, p - 2, p); } n void Init() { n   fac[0] = 1; n   inv[0] = 1; n   for (int i = 1; i < MAX; ++i) { n     fac[i] = fac[i - 1] * i % MOD; n     inv[i] = Inv(fac[i]); n   } n } n inline i64 C(int n, int m) { n   return n < m ? 0 : fac[n] * inv[m] % MOD * inv[n - m] % MOD; n } n i64 Solve(int n, int k) { n   int m = 0; n   for (int i = 0; i < n; ++i) { n     l[i] <<= 1; n     r[i] = ((r[i] << 1) | 1); n     x[m++] = l[i]; n     x[m++] = r[i]; n   } n   sort(x, x + m); n   int a = x[0], b = x[m - 1]; n   x[m++] = a - 1; n   x[m++] = b + 1; n   sort(x, x + m); n   m = unique(x, x + m) - x; n   memset(cnt, 0, sizeof(cnt)); n   for (int i = 0; i < n; ++i) { n     int u = lower_bound(x, x + m, l[i]) - x; n     int v = lower_bound(x, x + m, r[i]) - x; n     ++cnt[u]; n     --cnt[v]; n   } n   i64 ret = 0; n   for (int i = 1; i < m - 1; ++i) { n     cnt[i] += cnt[i - 1]; n     if (cnt[i] >= k) { n       int u = ((x[i + 1] + 1) >> 1), v = ((x[i] + 1) >> 1); n       int d = u - v; n       i64 cur = C(cnt[i], k) * d % MOD; n       ret = (ret + cur) % MOD; n     } n   } n   return ret; n } n int main() { n   Init(); n   int n, k; n   while (~scanf( %d%d , &n, &k)) { n     for (int i = 0; i < n; ++i) { n       scanf( %d%d , &l[i], &r[i]); n     } n     printf( %d n , (int)Solve(n, k)); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char s[2555], t[2555]; n int n, ans[2555 * 3], o; n int main() { n   scanf( %d , &n); n   scanf( %s , s); n   scanf( %s , t); n   o = 0; n   for (int i = n - 1; i >= 0; i--) { n     int j = n - 1 - i; n     while (j < n && s[j] != t[i]) j++; n     if (j == n) { n       printf( -1 n ); n       return 0; n     } n     ans[o++] = n; n     ans[o++] = j; n     ans[o++] = 1; n     reverse(s + j, s + n); n     reverse(s, s + n); n     reverse(s + 1, s + n); n   } n   cout << o << endl; n   for (int i = 0; i < o; i++) printf( %d  , ans[i]); n   printf(  n ); n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> a; n void init(int x) { n   vector<int> b; n   while (x > 0) { n     int tmp = x % 10; n     b.push_back(tmp); n     x /= 10; n   } n   for (int i = b.size() - 1; i >= 0; i--) { n     a.push_back(b[i]); n   } n } n int main() { n   for (int i = 0; i <= 1000; ++i) init(i); n   int n; n   while (~scanf( %d , &n)) cout << a[n - 1] << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char s[505][505]; n int main() { n   int n, m; n   cin >> n >> m; n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= m; j++) { n       scanf(  %c , &s[i][j]); n     } n   } n   bool ok = 1; n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= m; j++) { n       if (s[i][j] ==  W ) { n         if (s[i + 1][j] ==  . ) n           s[i + 1][j] =  D ; n         else if (s[i + 1][j] ==  S ) n           ok = 0; n         if (s[i - 1][j] ==  . ) n           s[i - 1][j] =  D ; n         else if (s[i - 1][j] ==  S ) n           ok = 0; n         if (s[i][j + 1] ==  . ) n           s[i][j + 1] =  D ; n         else if (s[i][j + 1] ==  S ) n           ok = 0; n         if (s[i][j - 1] ==  . ) n           s[i][j - 1] =  D ; n         else if (s[i][j - 1] ==  S ) n           ok = 0; n         if (!ok) { n           cout <<  No  << endl; n           return 0; n         } n       } n     } n   } n   cout <<  Yes  << endl; n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= m; j++) { n       printf( %c , s[i][j]); n     } n     printf(  n ); n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long int _seive_size; n bitset<1000000> bs; n vector<long long int> primes; n void seive(long long int upperbound) { n   _seive_size = upperbound + 1; n   bs.set(); n   bs[0] = bs[1] = 0; n   for (long long int i = 2; i <= _seive_size; i++) { n     if (bs[i]) { n       for (long long int j = i * i; j <= _seive_size; j += i) { n         bs[j] = 0; n       } n       primes.push_back((int)i); n     } n   } n } n bool isTrime(long long int N) { n   long long int temp; n   long long int start = 0; n   long long int end = primes.size() - 1; n   while (start <= end) { n     long long int mid = start + (end - start) / 2; n     temp = primes[mid] * primes[mid]; n     if (temp == N) { n       return true; n     } else if (temp < N) { n       start = mid + 1; n     } else { n       end = mid - 1; n     } n   } n   return false; n } n int main() { n   seive(1000000); n   long long int n; n   cin >> n; n   long long int arr[n]; n   for (int i = 0; i < n; i++) { n     cin >> arr[i]; n   } n   for (int i = 0; i < n; i++) { n     if (isTrime(arr[i])) { n       cout <<  YES  << endl; n     } else { n       cout <<  NO  << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long N = (1LL << 22) + 2; n long long n, m; n long long a[N]; n bool vis[2][N]; n void dfs(long long k, long long cur) { n   if (vis[cur][k]) return; n   vis[cur][k] = 1; n   if (cur == 1) return dfs(k, cur ^ 1); n   for (long long i = 0; i < n; i++) { n     if ((k & (1LL << i)) == 0) dfs(k | (1LL << i), 0); n   } n   dfs(((1LL << n) - 1) ^ k, 1); n } n int32_t main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   ; n   cin >> n >> m; n   for (long long i = 0; i < N; i++) vis[1][i] = 1; n   for (long long i = 1; i <= m; i++) { n     cin >> a[i]; n     vis[1][a[i]] = 0; n   } n   long long ans = 0; n   for (long long i = 1; i <= m; i++) { n     if (vis[1][a[i]]) continue; n     ans++; n     dfs(a[i], 1); n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MOD = 998244353; n const int MAXN = 1000010; n int get() { n   int x; n   bool f = 0; n   char c; n   while (!isdigit(c = getchar())) n     if (c ==  - ) f = 1; n   x = c - 48; n   while (isdigit(c = getchar())) x = (x << 1) + (x << 3) + c - 48; n   if (f) n     return -x; n   else n     return x; n } n int N, A[MAXN]; n int add(int x, int v) { n   x += v; n   if (x >= MOD) x -= MOD; n   return x; n } n int main() { n   N = get(); n   for (int i = 1; i <= N; ++i) A[i] = get(); n   int F = 0, G = 0, v = 0; n   for (int i = 1; i <= N; ++i) { n     v = add(1LL * v * 2 % MOD, A[i]); n     F = add(G, v); n     G = add(G, F); n   } n   cout << F << endl; n   return 0; n } n


#include <iostream> n #include <algorithm> n #include <string.h> n #include <queue> n #include <vector> n  n #define INF 987654321 n  n using namespace std; n  n int main() { n     int t; n     scanf( %d ,&t); n     while(t--){ n         int a,b,flag=0; n         scanf( %d %d ,&a,&b); n         if(a==b)printf( YES n ); n         else if(a>b)printf( NO n ); n         else{ n             //여기가 실제로 계산해야되는 부분. n             //2^n꼴은 무조건 1->2->4->8->16으로만 이동이 가능함. n             // 3=11으로서, 3+1, 3+10, 3+11 3개가 가능함. 3->4,5,6다 가능하다. n             // 7=111으로서, 7->8,9,10,11,12,13,14다 가능하다. n             // 결국 우리가 그럼 찾아야 되는 값은 5,6과 같은 중간에 비는값이 있는 값들. n  n             // 5 = 101으로, 5+1, 5+100, 5+101.  5->6,9,10로 이동이 가능. n             // 6 = 110으로, 6+10, 6+100, 6+110. 6->8,10,12로 이동이 가능. n             // 결론. 3은 11,13,14를 못감. 8 =1000, 9=1001, 10=1010, 11=1011 n             // 와 그럼 3=11 숫자가 2개다보니, 11과 같이 3개가 필요한 곳은 못간다. n             for(int i=0;i<30;i++) n             { n               if((a>>i)&1)flag++; n               if((b>>i)&1)flag--; n               if(flag<0) n               { n                   printf( NO n ); n                   break; n               } n             } n             if(flag>=0) n             { n               printf( YES n ); n             } n         } n     } n     return 0; n }


#include <bits/stdc++.h> n using namespace std; n long long f[1200]; n long long mod = 1000000007; n int arr[1100]; n long long pw(long long x, long long sum) { n   long long res = 1, power = sum, val = x; n   while (power) { n     if (power & 1) { n       res *= val; n       res %= mod; n     } n     val *= val; n     val %= mod; n     power >>= 1ll; n   } n   return res; n } n int main() { n   f[0] = 1; n   for (int i = 1; i <= 1000; i++) f[i] = (f[i - 1] * i) % mod; n   int n, m; n   cin >> n >> m; n   long long ans = f[n - m]; n   vector<int> vec; n   for (int i = 0; i < m; i++) { n     scanf( %d , &arr[i]); n   } n   sort(arr, arr + m); n   if (!m) n     vec.push_back(n); n   else { n     vec.push_back(arr[0] - 1); n     for (int i = 1; i < m; i++) vec.push_back(arr[i] - arr[i - 1] - 1); n     vec.push_back(n - arr[m - 1]); n   } n   long long sum = 1; n   for (int i = 0; i < vec.size(); i++) sum = (sum * f[vec[i]]) % mod; n   ans = (ans * pw(sum, mod - 2)) % mod; n   for (int i = 1; i < vec.size() - 1; i++) n     if (vec[i] - 1 && vec[i]) ans = (ans * pw(2, vec[i] - 1)) % mod; n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 1e9 + 10; n const long long int INFLL = 1e18 + 10; n const long double EPS = 1e-8; n const long double EPSLD = 1e-14; n const long long int MOD = 1000000007; n template <class T> n T &chmin(T &a, const T &b) { n   return a = min(a, b); n } n template <class T> n T &chmax(T &a, const T &b) { n   return a = max(a, b); n } n struct Unionfind { n   vector<int> size; n   vector<int> par; n   Unionfind() {} n   Unionfind(int n) : size(n, 1), par(n) { n     for (int i = (0); i < (int)(n); i++) par[i] = i; n   } n   void init(int n) { n     size.resize(n); n     par.resize(n); n     for (int i = (0); i < (int)(n); i++) { n       size[i] = 1; n       par[i] = i; n     } n   } n   int find(int x) { n     if (par[x] == x) return x; n     return par[x] = find(par[x]); n   } n   bool unite(int x, int y) { n     x = find(x); n     y = find(y); n     if (x == y) return false; n     if (size[y] < size[x]) swap(x, y); n     par[x] = y; n     size[y] += size[x]; n     return true; n   } n   bool same(int x, int y) { return find(x) == find(y); } n }; n vector<long long int> compress(vector<long long int> a) { n   vector<long long int> ord = a, res; n   sort((ord).begin(), (ord).end()); n   ord.erase(unique((ord).begin(), (ord).end()), ord.end()); n   for (auto &w : a) n     res.emplace_back(lower_bound((ord).begin(), (ord).end(), w) - ord.begin()); n   return res; n } n Unionfind uf; n struct Segtree { n   vector<long long int> cnt, an; n   int size; n   void init(int n) { n     size = 1; n     while (size < n) size *= 2; n     cnt = vector<long long int>(size * 2 - 1, 0); n     an = vector<long long int>(size * 2 - 1, -2); n   } n   void add(int k, int id) { n     k += size - 1; n     cnt[k] = 1; n     an[k] = id; n     while (k > 0) { n       k = (k - 1) / 2; n       cnt[k] = cnt[k * 2 + 1] + cnt[k * 2 + 2]; n       if (an[k] == -2) n         an[k] = id; n       else n         an[k] = -1; n     } n   } n   void del(int k) { n     k += size - 1; n     cnt[k] = 0; n     an[k] = -2; n     while (k > 0) { n       k = (k - 1) / 2; n       cnt[k] = cnt[k * 2 + 1] + cnt[k * 2 + 2]; n       an[k] = -1; n       if (an[k * 2 + 1] == -2 && an[k * 2 + 2] == -2) an[k] = -2; n     } n   } n   long long int query(int a, int b, int id, int k, int l, int r) { n     if (an[k] == -2) return 0; n     if (a <= l && r <= b) { n       if (an[k] != -1) { n         if (uf.same(an[k], id)) return cnt[k]; n         uf.unite(an[k], id); n         return cnt[k] - 1; n       } n       an[k] = id; n     } else if (b <= l || r <= a) { n       return 0; n     } n     long long int chl = query(a, b, id, k * 2 + 1, l, (l + r) / 2); n     long long int chr = query(a, b, id, k * 2 + 2, (l + r) / 2, r); n     return chl + chr; n   } n   long long int query(int a, int b, int id) { n     return query(a, b, id, 0, 0, size); n   } n }; n const int MAX_N = 200010; n int n; n long long int x1[MAX_N], x2[MAX_N]; n long long int z1[MAX_N], z2[MAX_N]; n vector<long long int> ix, iy; n vector<long long int> xs, ys; n Segtree seg; n vector<pair<pair<long long int, long long int>, n             pair<long long int, long long int> > > n     qu; n long long int res[MAX_N]; n long long int ans; n int main() { n   scanf( %d , &n); n   for (int i = (0); i < (int)(n); i++) { n     scanf( %lld %lld %lld %lld , &x1[i], &z1[i], &x2[i], &z2[i]); n     ix.emplace_back(x1[i]); n     ix.emplace_back(x2[i]); n     iy.emplace_back(z1[i]); n     iy.emplace_back(z2[i]); n   } n   xs = compress(ix); n   ys = compress(iy); n   for (int i = (0); i < (int)(n); i++) { n     if (xs[i * 2] == xs[i * 2 + 1]) n       qu.emplace_back(pair<long long int, long long int>(xs[i * 2], ys[i * 2]), n                       pair<long long int, long long int>(ys[i * 2 + 1], i)); n     else { n       qu.emplace_back(pair<long long int, long long int>(xs[i * 2], -1), n                       pair<long long int, long long int>(ys[i * 2], i)); n       qu.emplace_back(pair<long long int, long long int>(xs[i * 2 + 1], INFLL), n                       pair<long long int, long long int>(ys[i * 2], i)); n       res[i] = x2[i] - x1[i]; n     } n   } n   sort((qu).begin(), (qu).end()); n   uf.init(n); n   seg.init(3 * n); n   for (auto &q : qu) { n     int id = q.second.second; n     if (q.first.second == -1) n       seg.add(q.second.first, id); n     else if (q.first.second == INFLL) n       seg.del(q.second.first); n     else n       res[id] = n           z2[id] - z1[id] - seg.query(q.first.second, q.second.first + 1, id); n   } n   for (int i = (0); i < (int)(n); i++) n     if (uf.find(i) != i) res[uf.find(i)] += res[i]; n   for (int i = (0); i < (int)(n); i++) n     if (uf.find(i) == i) chmax(ans, res[i]); n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n const int oo = 0x3f3f3f3f; n template <typename T> n inline bool chkmax(T &a, T b) { n   return a < b ? a = b, true : false; n } n template <typename T> n inline bool chkmin(T &a, T b) { n   return a > b ? a = b, true : false; n } n template <typename T> n T read(T &first) { n   int f = 1; n   char ch = getchar(); n   for (; !isdigit(ch); ch = getchar()) n     if (ch ==  - ) f = -1; n   for (first = 0; isdigit(ch); ch = getchar()) first = 10 * first + ch -  0 ; n   return first *= f; n } n template <typename T> n void write(T first) { n   if (first < 0) { n     putchar( - ); n     first = -first; n   } n   static char s[20]; n   int top = 0; n   for (; first; first /= 10) s[++top] = first % 10 +  0 ; n   if (top == 0) n     putchar( 0 ); n   else n     while (top) putchar(s[top--]); n } n const int MAXN = 1e5 + 5, MAXK = 6; n struct Line { n   int a, b, c; n   int id; n   bool on(const std::pair<double, double> &p) { n     static double EPS = 1e-8; n     return std::fabs(a * p.first + b * p.second + c) < EPS; n   } n }; n int N, K; n Line A[MAXN]; n std::pair<int, int> ans[MAXN]; n int anssize; n int st[MAXN]; n inline bool intersection(const Line &a, const Line &b, n                          std::pair<double, double> &p) { n   long long d = (long long)a.b * b.a - (long long)b.b * a.a; n   if (d == 0) return false; n   p.first = (double)((long long)b.b * a.c - (long long)a.b * b.c) / d; n   p.second = (double)((long long)b.c * a.a - (long long)a.c * b.a) / d; n   return true; n } n bool dfs(int n, int k) { n   if (n <= k) { n     for (int i = 0; i < n; ++i) { n       ans[anssize++] = std::make_pair(A[i].id + 1, -1); n     } n     return true; n   } n   if (k == 0) return false; n   for (int i = n - k - 1; i < n; ++i) { n     for (int j = i + 1; j < n; ++j) { n       std::pair<double, double> p; n       if (intersection(A[i], A[j], p) == false) continue; n       ans[anssize++] = std::make_pair(A[i].id + 1, A[j].id + 1); n       int m = n, top = 0; n       for (int k = n - 1; k >= 0; --k) { n         if (A[k].on(p)) { n           st[++top] = k; n           std::swap(A[k], A[--m]); n         } n       } n       if (dfs(m, k - 1) == true) return true; n       --anssize; n       while (top > 0) { n         std::swap(A[st[top--]], A[m++]); n       } n     } n   } n   return false; n } n void input() { n   read(N); n   read(K); n   for (int i = 0; i < N; ++i) { n     read(A[i].a); n     read(A[i].b); n     read(A[i].c); n     A[i].id = i; n   } n } n void solve() { n   srand(time(NULL)); n   if (N >= 5 * K * K) { n     int times = 100; n     while (times-- && N > 0 && K > 0) { n       int i = rand() % N; n       int j = rand() % N; n       std::pair<double, double> p; n       if (i == j || intersection(A[i], A[j], p) == false) continue; n       int top = 0; n       for (int k = N - 1; k >= 0; --k) { n         if (A[k].on(p)) st[++top] = k; n       } n       if (top > K) { n         ans[anssize++] = std::make_pair(A[i].id + 1, A[j].id + 1); n         for (int k = 1; k <= top; ++k) { n           A[st[k]] = A[--N]; n         } n         --K; n         break; n       } n     } n   } n   bool haveAns = dfs(N, K); n   if (haveAns) { n     puts( YES ); n     write(anssize); n     putchar(  n ); n     for (int i = 0; i < anssize; ++i) { n       write(ans[i].first); n       putchar(   ); n       write(ans[i].second); n       putchar(  n ); n     } n   } else n     puts( NO ); n } n int main() { n   input(); n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2e6 + 5; n const int inf = 1e9 + 5; n const double pi = acos(-1); n const int dx[] = {1, -1, 0, 0}; n const int dy[] = {0, 0, 1, -1}; n const int mod = 1e9 + 7; n int p[N], cnt[N]; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   ; n   string s; n   cin >> s; n   int n = (int)(s).size(); n   memset(p, 0, sizeof p); n   for (int i = 1; i < n; i++) { n     int prev = p[i - 1]; n     while (prev > 0 && s[prev] != s[i]) prev = p[prev - 1]; n     if (s[prev] == s[i]) prev++; n     p[i] = prev; n   } n   if (p[n - 1] == 0) { n     if (p[p[n - 1] - 1] == 0) { n       cout <<  Just a legend ; n     } else { n       cout << s.substr(0, p[p[n - 1] - 1]); n     } n   } else { n     int cnt = 0; n     for (int i = 0; i < n; i++) { n       if (p[i] == p[n - 1]) { n         ++cnt; n       } n     } n     if (cnt >= 2) { n       cout << s.substr(0, p[n - 1]); n     } else { n       if (p[p[n - 1] - 1] == 0) { n         cout <<  Just a legend ; n       } else { n         cout << s.substr(0, p[p[n - 1] - 1]); n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n string s[10100]; n string sep; n bool u[10100] = {false}; n vector<string> str; n string make(pair<string, string> p) { n   return ((p.first + sep + p.second) < (p.second + sep + p.first)) n              ? (p.first + sep + p.second) n              : (p.second + sep + p.first); n } n int main() { n   int n = 0, sumLeng = 0, len = 0; n   cin >> n; n   for (int i = 0; i < n; ++i) { n     cin >> s[i]; n     sumLeng += s[i].length(); n   } n   cin >> sep; n   len = sumLeng / (n / 2); n   sort(s, s + n); n   for (int i = 0; i < n; ++i) { n     if (u[i]) continue; n     int leng = s[i].length(); n     for (int j = 0; j < n; ++j) n       if (!u[j] && leng + s[j].length() == len && i != j) { n         str.push_back(make(make_pair(s[i], s[j]))); n         u[i] = true; n         u[j] = true; n         break; n       } n   } n   sort(str.begin(), str.end()); n   for (int i = 0; i < n / 2; ++i) cout << str[i] << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n using minpq = priority_queue<T, vector<T>, greater<T>>; n int n, m, k; n int arr[70][70]; n int dp[71][71][36][71]; n int func(int s, int e, int cnd, int rem) { n   if (cnd >= m / 2) { n     return -1e9; n   } n   if (s == n) { n     if (rem == 0) { n       return 0; n     } n     return -1e9; n   } n   if (e == m) { n     return -1e9; n   } n   if (dp[s][e][cnd][rem] != -1) { n     return dp[s][e][cnd][rem]; n   } n   int ans = -1e9; n   int nc = (rem + arr[s][e]) % k; n   ans = n       max({func(s, e + 1, cnd, rem), arr[s][e] + func(s, e + 1, cnd + 1, nc)}); n   ans = max({ans, func(s + 1, 0, 0, rem), arr[s][e] + func(s + 1, 0, 0, nc)}); n   return dp[s][e][cnd][rem] = ans; n } n void solve() { n   memset(dp, -1, sizeof(dp)); n   cin >> n >> m >> k; n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       cin >> arr[i][j]; n     } n   } n   int ans = func(0, 0, 0, 0); n   if (ans < 0) { n     ans = 0; n   } n   cout << ans << endl; n } n int32_t main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   int t = 1; n   while (t--) { n     solve(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n inline long long read() { n   long long x = 0, f = 1; n   char c = getchar(); n   while (!isdigit(c)) { n     if (c ==  - ) f = -1; n     c = getchar(); n   } n   while (isdigit(c)) { n     x = (x << 3) + (x << 1) + (c ^ 48); n     c = getchar(); n   } n   return f == -1 ? ~x + 1 : x; n } n long long n; n vector<long long> ve[11]; n long long sum[11]; n const long long N = 1e6, mod1 = 998244353, mod2 = 1e9 + 7; n long long cnt, tmp, ans; n long long m1(long long x) { return (x % mod1 + mod1) % mod1; } n void dfs1(long long x, long long v) { n   if (v > n) return; n   if (x > 6) return; n   ++cnt; n   ve[x].push_back(m1(cnt - v)); n   sum[x] += m1(cnt - v); n   for (long long i = 0; i < 10; ++i) dfs1(x + 1, v * 10 + i); n } n void dfs2(long long x, long long v) { n   if (v > n) return; n   if (x >= 1) { n     if (v * N * 10 > n && v * N + N - 1 <= n) { n       for (long long i = 0, t = 1; i <= 6; ++i, t *= 10) { n         long long val = m1(cnt - v * t); n         long long pos = n             lower_bound(ve[i].begin(), ve[i].end(), mod1 - val) - ve[i].begin(); n         (ans += val * ve[i].size() + sum[i] - mod1 * (ve[i].size() - pos)) %= n             mod2; n       } n       cnt += tmp; n       return; n     } n     ++cnt; n     (ans += m1(cnt - v)) %= mod2; n   } n   for (long long i = (x == 0 ? 1 : 0); i <= 9; ++i) dfs2(x + 1, v * 10 + i); n } n signed main() { n   n = read(); n   dfs1(0, 0); n   tmp = cnt; n   cnt = 0; n   for (long long i = 0; i <= 6; ++i) sort(ve[i].begin(), ve[i].end()); n   dfs2(0, 0); n   printf( %d n , ans); n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 10; n const int inf = 2000000000; n int f(int first, int second, int t[N]) { n   int a[N], b[N]; n   for (int i = 0; i < N; i++) { n     a[i] = b[i] = t[i]; n   } n   a[first]--; n   b[second]--; n   if (a[first] < 0 || b[second] < 0) { n     return -1; n   } n   if ((first + second) != 10) { n     return 0; n   } n   int cur = 1; n   for (int i = 0; i < N; i++) { n     cur += min(a[i], b[N - i - 1]); n   } n   return cur; n } n pair<string, string> get(int a[N], pair<pair<int, int>, int> code) { n   int q[N], w[N]; n   for (int i = 0; i < N; i++) { n     q[i] = w[i] = a[i]; n   } n   string s, t; n   for (int i = 0; i < code.second; i++) { n     s +=  0 ; n     t +=  0 ; n     q[0]--; n     w[0]--; n   } n   int first = code.first.first; n   int second = code.first.second; n   s += char(first +  0 ); n   t += char(second +  0 ); n   q[first]--; n   w[second]--; n   for (int i = 0; i < N; i++) { n     int val = min(q[i], w[N - i - 1]); n     for (int j = 0; j < val; j++) { n       s += char(i +  0 ); n       t += char(N - i - 1 +  0 ); n     } n     q[i] -= val; n     w[N - i - 1] -= val; n   } n   for (int i = 0; i < N; i++) { n     for (int j = 0; j < q[i]; j++) { n       s += char(i +  0 ); n     } n     for (int j = 0; j < w[i]; j++) { n       t += char(i +  0 ); n     } n   } n   reverse((s).begin(), (s).end()); n   reverse((t).begin(), (t).end()); n   return {s, t}; n } n int main() { n   cin.tie(0); n   ios_base::sync_with_stdio(0); n   string s; n   cin >> s; n   int a[N]; n   memset(a, 0, sizeof(a)); n   int n = s.length(); n   for (int i = 0; i < n; i++) { n     a[s[i] -  0 ]++; n   } n   int best = -1; n   pair<pair<int, int>, int> code; n   for (int i = 0; i <= a[0]; i++) { n     int b[N]; n     for (int j = 0; j < N; j++) { n       b[j] = a[j]; n     } n     b[0] -= i; n     for (int first = 0; first < N; first++) { n       for (int second = 0; second < N; second++) { n         int cur = f(first, second, b); n         if (cur + i > best) { n           best = cur + i; n           code = {{first, second}, i}; n         } n       } n     } n   } n   pair<string, string> ans = get(a, code); n   cout << ans.first <<   n  << ans.second; n } n


#include <bits/stdc++.h> n using namespace std; n const string nameFile =  test ; n ifstream in(nameFile +  .in ); n ofstream out(nameFile +  .out ); n const int nmax = 4e3; n int n, nrGond; n char ch; n int a[nmax + 2][nmax + 2]; n int dp[802][nmax + 2]; n char buffer[10000]; n inline int getCost(int i, int j) { n   return (a[j][j] + a[i - 1][i - 1] - a[j][i - 1] - a[i - 1][j]) / 2; n } n void divideDp(int ll, int rr, int limLeftSrc, int limRightSrc, int layer) { n   if (ll > rr) return; n   int mij = (ll + rr) / 2; n   pair<int, int> ob = {1e9, 0}; n   for (int i = limLeftSrc; i <= min(mij, limRightSrc); i++) n     ob = min(ob, {getCost(i, mij) + dp[layer - 1][i - 1], i}); n   dp[layer][mij] = ob.first; n   divideDp(ll, mij - 1, limLeftSrc, ob.second, layer); n   divideDp(mij + 1, rr, ob.second, limRightSrc, layer); n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   scanf( %d%d n , &n, &nrGond); n   for (int i = 1; i <= n; i++) { n     gets(buffer); n     for (int j = 1; j <= n; j++) n       a[i][j] = buffer[2 * (j - 1)] -  0  + a[i - 1][j] + a[i][j - 1] - n                 a[i - 1][j - 1]; n   } n   for (int i = 1; i <= n; i++) dp[0][i] = 1e9; n   for (int i = 1; i <= nrGond; i++) divideDp(i, n, i, n, i); n   cout << dp[nrGond][n]; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, ta; n long double x[1005][1005], tb, tc, td; n vector<int> y; n vector<long double> z; n bool used[1005]; n int main() { n   scanf( %d , &n); n   for (int a = 0; a < n; a++) n     for (int b = 0; b < n; b++) { n       scanf( %d , &ta); n       x[a][b] = ta; n       x[a][b] /= 100; n     } n   y.push_back(n - 1); n   z.push_back(0); n   used[n - 1] = 1; n   while (y.back() != 0) { n     ta = -1; n     for (int a = 0; a < n; a++) n       if (!used[a]) { n         tb = 0; n         tc = 1; n         for (int b = 0; b < y.size(); b++) { n           tb += (z[b] + 1) * tc * x[a][y[b]]; n           tc *= 1 - x[a][y[b]]; n         } n         if (abs(tc - 1) < 1e-11) continue; n         tb = (tb + tc) / (1 - tc); n         if (ta == -1 || tb < td) { n           ta = a; n           td = tb; n         } n       } n     y.push_back(ta); n     z.push_back(td); n     for (int a = z.size() - 1; a >= 1; a--) { n       if (z[a] >= z[a - 1]) break; n       swap(z[a], z[a - 1]); n       swap(y[a], y[a - 1]); n     } n     used[ta] = 1; n   } n   printf( %.15lf n , (double)z.back()); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int i, j, n, m, a, b, tmp; n int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } n int main() { n   cin >> n >> m >> a >> b; n   tmp = n * m / gcd(n, m); n   cout << b / tmp - (a - 1) / tmp; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 10005; n vector<int> gr[N]; n int ans = 0; n void dfs(int v, int p = -1) { n   for (int to : gr[v]) n     if (to != p) { n       dfs(to, v); n       ans += (gr[to].size() - 1); n     } n   ans += ((gr[v].size() - (v != 1)) * (gr[v].size() - 1 - (v != 1))) / 2; n } n int main() { n   int n; n   scanf( %d , &n); n   for (int i = 1; i < n; ++i) { n     int a, b; n     scanf( %d%d , &a, &b); n     gr[a].push_back(b); n     gr[b].push_back(a); n   } n   dfs(1); n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = int64_t; n using u64 = uint64_t; n using u32 = uint32_t; n struct Node { n   int idx; n   Node *left = nullptr, *right = nullptr; n }; n int depth(Node* v) { n   if (!v) return 0; n   return max(depth(v->left), depth(v->right)) + 1; n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(nullptr); n   int n; n   cin >> n; n   vector<int> a(n); n   for (auto& ai : a) cin >> ai; n   auto it = min_element(begin(a), end(a)); n   int orig_shift = (n - (it - begin(a))) % n; n   rotate(begin(a), it, end(a)); n   int left = 0, right = n; n   vector<int> b(n); n   vector<Node> nodes(n); n   for (int i = 0; i < n; ++i) nodes[i].idx = i; n   vector<Node*> stack; n   int mind = n; n   while (right - left > 1) { n     for (auto& node : nodes) node.left = node.right = nullptr; n     stack.clear(); n     int mid = (left + right) / 2; n     int start = (n - mid) % n; n     for (int i = start; i < n + start; ++i) { n       Node* left = nullptr; n       while (!stack.empty() && a[stack.back()->idx] > a[i % n]) { n         left = stack.back(); n         stack.pop_back(); n       } n       if (!stack.empty()) stack.back()->right = &nodes[i % n]; n       if (right) nodes[i % n].left = left; n       stack.push_back(&nodes[i % n]); n     } n     Node* root = stack.front(); n     auto ldepth = depth(root->left); n     auto rdepth = depth(root->right); n     mind = min(mind, max(ldepth, rdepth) + 1); n     if (ldepth == rdepth) { n       cout << (ldepth + 1) <<     << ((n - mid - orig_shift + n) % n) <<   n ; n       return 0; n     } else if (ldepth > rdepth) { n       right = mid; n     } else { n       left = mid; n     } n   } n   cout << mind <<     << ((n - left - orig_shift + n) % n) <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n typedef long long ll; n #define fastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); n int main() n { n  n     fastIO n     int t; n     cin>>t; n     while(t--) n     { n         int x,y; n         cin>>x>>y; n  n         if (x==y) n              cout<<x+y<<  n ; n         else  n              cout<<max(x,y)*2-1<<  n ; n  n     } n  n  n  n  n  n  n  n  n  n  n  n  n  n  n  n } n


#include <bits/stdc++.h> n using namespace std; n const int M = 500005; n int n, m, q; n struct Edge { n   Edge() {} n   Edge(int u_, int v_) : u(u_), v(v_) {} n   int u, v; n   bool operator<(const Edge &a) const { n     if (v != a.v) return v < a.v; n     return u > a.u; n   } n } edge[M << 1]; n int fa[M]; n int get(int x) { return fa[x] == x ? x : fa[x] = get(fa[x]); } n struct BIT { n   int C[M]; n   void init() { memset(C, 0, n + 1 << 2); } n   void update(int x, int f) { n     for (; x; x -= x & -x) C[x] += f; n   } n   int query(int x) { n     int res = 0; n     for (; x <= n; x += x & -x) res += C[x]; n     return res; n   } n } bit; n struct LCT { n   static const int N = M * 3; n   int fa[N], c[N][2], v[N], mn[N]; n   char rev[N]; n   void init() { n     for (int i = 0; i <= n + m; i++) { n       c[i][0] = c[i][1] = fa[i] = 0; n       v[i] = (1 << 30); n       mn[i] = i; n     } n   } n   bool isroot(int x) { return c[fa[x]][0] != x && c[fa[x]][1] != x; } n   int cmp(int x, int y) { return v[x] < v[y] ? x : y; } n   void up(int x) { mn[x] = cmp(cmp(mn[c[x][0]], mn[c[x][1]]), x); } n   int query(int x, int y) { n     makeroot(x); n     access(y); n     splay(y); n     return mn[y]; n   } n   void rotate(int x) { n     int y = fa[x], z = fa[y], l, r; n     if (c[y][0] == x) n       l = 0; n     else n       l = 1; n     r = l ^ 1; n     if (!isroot(y)) { n       if (c[z][0] == y) n         c[z][0] = x; n       else n         c[z][1] = x; n     } n     fa[x] = z; n     fa[y] = x; n     fa[c[x][r]] = y; n     c[y][l] = c[x][r]; n     c[x][r] = y; n     up(y); n   } n   int q[N]; n   void down(int x) { n     if (rev[x]) { n       rev[c[x][0]] ^= 1; n       rev[c[x][1]] ^= 1; n       swap(c[x][0], c[x][1]); n       rev[x] = 0; n     } n   } n   void splay(int x) { n     int top = 0; n     q[++top] = x; n     for (int i = x; !isroot(i); i = fa[i]) q[++top] = fa[i]; n     for (int i = top; i >= 1; i--) down(q[i]); n     while (!isroot(x)) { n       int y = fa[x], z = fa[y]; n       if (!isroot(y)) { n         if (c[z][0] == y ^ c[y][0] == x) n           rotate(x); n         else n           rotate(y); n       } n       rotate(x); n     } n     up(x); n   } n   void makeroot(int x) { n     access(x); n     splay(x); n     rev[x] ^= 1; n   } n   void access(int x) { n     for (int t = 0; x; t = x, x = fa[x]) { n       splay(x); n       c[x][1] = t; n       up(x); n     } n   } n   void cut(int x, int y) { n     makeroot(x); n     access(y); n     splay(y); n     c[y][0] = fa[x] = 0; n   } n   void link(int x, int y) { n     makeroot(x); n     fa[x] = y; n   } n } lct; n int last[M], allc; n struct Query { n   int to, l, nxt; n } que[M]; n void ins(int l, int r, int id) { n   que[allc].l = l; n   que[allc].to = id; n   que[allc].nxt = last[r]; n   last[r] = allc++; n } n int ans[M]; n void solve() { n   scanf( %d , &m); n   int tmp = 0; n   for (int u, v, i = 1; i <= m; i++) { n     scanf( %d%d , &u, &v); n     if (u == v) continue; n     if (u > v) swap(u, v); n     edge[++tmp] = Edge(u, v); n   } n   m = tmp; n   sort(edge + 1, edge + m + 1); n   for (int i = 1; i <= n; i++) fa[i] = i; n   bit.init(); n   lct.init(); n   memset(last, -1, n + 1 << 2); n   allc = 0; n   scanf( %d , &q); n   for (int l, r, i = 1; i <= q; i++) { n     scanf( %d%d , &l, &r); n     ins(l, r, i); n   } n   int pre = 1; n   for (int i = 1; i <= n; i++) { n     for (; pre <= m && edge[pre].v == i; pre++) { n       int u = edge[pre].u, v = edge[pre].v; n       if (get(u) == get(v)) { n         int id = lct.query(u, v); n         id -= n; n         if (edge[id].u >= u) continue; n         lct.cut(edge[id].u, id + n); n         lct.cut(edge[id].v, id + n); n         bit.update(edge[id].u, -1); n         lct.v[pre + n] = u; n         lct.link(u, pre + n); n         lct.link(v, pre + n); n         bit.update(u, 1); n       } else { n         lct.v[pre + n] = u; n         lct.link(u, pre + n); n         lct.link(v, pre + n); n         bit.update(u, 1); n         fa[get(u)] = get(v); n       } n     } n     for (int j = last[i]; j != -1; j = que[j].nxt) { n       int l = que[j].l, to = que[j].to; n       ans[to] = (i - l + 1) - bit.query(l); n     } n   } n   for (int i = 1; i <= q; i++) printf( %d n , ans[i]); n } n int main() { n   while (~scanf( %d%d , &n, &m)) solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline void print(char pt) { printf( %c n , pt); } n inline void print(int pt) { printf( %d n , pt); } n inline void print(long long pt) { printf( %I64d n , pt); } n inline void print(double pt) { printf( %.20f n , pt); } n inline void print(char pt[]) { printf( %s n , pt); } n inline void print() { printf(  n ); } n inline int scan(int &pt) { return scanf( %d , &pt); } n inline int scan(char &pt) { return scanf( %c , &pt); } n inline int scan(long long &pt) { return scanf( %I64d , &pt); } n inline int scan(double &pt) { return scanf( %lf , &pt); } n inline int scan(char pt[]) { return scanf( %s , pt); } n long long moda = 109098827479487ll; n using namespace std; n int n, k, m; n char stra[1000]; n int a[300000]; n int c[300000]; n int main() { n   scan(n); n   int maxai = 0; n   long long sums = 0; n   for (int i = 0; i < n; i++) { n     scan(a[i]); n     sums += a[i]; n     c[a[i]]++; n     maxai = max(a[i], maxai); n   } n   int maxn = min(maxai + 1, 200001); n   for (int i = 1; i <= maxn; i++) { n     c[i] += c[i - 1]; n   } n   sort(a, a + n); n   long long suma = 0; n   long long maxa = 0; n   for (int i = 0; i < n; i++) { n     if (suma >= sums - maxa) break; n     suma += a[i]; n     if (i && a[i] == a[i] - 1) { n       continue; n     } n     long long nowa = 0; n     for (int j = 1, tj = a[i];; j++, tj += a[i]) { n       if (tj + a[i] - 1 >= maxn) { n         nowa += 1ll * j * (c[maxn] - c[tj - 1]); n         break; n       } n       nowa += 1ll * j * (c[tj + a[i] - 1] - c[tj - 1]); n     } n     nowa *= a[i]; n     maxa = max(maxa, nowa); n   } n   print(maxa); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int T, n, m; n int x[15]; n char s[15][10005]; n int v[10005], cnt[25], tmp[25]; n int P[10005]; n int ans; n void dfs(int p, int sum) { n   if (p == n + 1) { n     int cur = m, res = sum; n     for (int i = 20; i >= 0; i--) { n       res += (i - 10) * (cur * 2 - cnt[i] + 1) * cnt[i] / 2; n       cur -= cnt[i]; n     } n     tmp[0] = cnt[0]; n     for (int i = 1; i <= 20; i++) tmp[i] = tmp[i - 1] + cnt[i]; n     if (ans <= res) { n       ans = res; n       for (int i = 1; i <= m; i++) { n         P[i] = tmp[v[i] + 10]--; n       } n     } n     return; n   } n   for (int i = 1; i <= m; i++) { n     if (s[p][i] ==  1 ) { n       cnt[v[i] + 10]--; n       v[i]++; n       cnt[v[i] + 10]++; n     } n   } n   dfs(p + 1, sum - x[p]); n   for (int i = 1; i <= m; i++) { n     if (s[p][i] ==  1 ) { n       cnt[v[i] + 10]--; n       v[i] -= 2; n       cnt[v[i] + 10]++; n     } n   } n   dfs(p + 1, sum + x[p]); n   for (int i = 1; i <= m; i++) { n     if (s[p][i] ==  1 ) { n       cnt[v[i] + 10]--; n       v[i]++; n       cnt[v[i] + 10]++; n     } n   } n } n void solve() { n   scanf( %d%d , &n, &m); n   for (int i = 1; i <= n; i++) scanf( %d , &x[i]); n   for (int i = 1; i <= n; i++) { n     scanf( %s , &s[i][1]); n   } n   for (int i = 1; i <= m; i++) v[i] = 0; n   for (int i = 0; i <= 20; i++) cnt[i] = 0; n   cnt[10] = m; n   ans = 0; n   dfs(1, 0); n   for (int i = 1; i <= m; i++) printf( %d  , P[i]); n   printf(  n ); n } n int main() { n   scanf( %d , &T); n   while (T--) solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 10; n struct edge { n   int v, nxt; n } g[N]; n int tot = 0, head[N]; n inline void add(int u, int v) { n   g[++tot] = edge{v, head[u]}; n   head[u] = tot; n } n int n, m, fa[N], sz[N], son[N], top[N], dfn[N], tpos[N], dep[N], cnt = 0; n inline void dfs2(int u, int tp) { n   dfn[++cnt] = u; n   tpos[u] = cnt; n   top[u] = tp; n   if (son[u]) dfs2(son[u], tp); n   for (int i = head[u]; i; i = g[i].nxt) n     if (g[i].v != son[u]) dfs2(g[i].v, g[i].v); n } n int tree[N << 2], mx[N << 2], cov[N << 2]; n inline void pushup(int o) { n   tree[o] = tree[o << 1] + tree[o << 1 | 1]; n   mx[o] = max(mx[o << 1 | 1], max(mx[o << 1], 0) + tree[o << 1 | 1]); n } n inline void pushdown(int o, int l, int r) { n   if (cov[o]) { n     cov[o << 1] = cov[o << 1 | 1] = 1; n     int mid = (l + r) >> 1; n     tree[o << 1] = -(mid - l + 1); n     tree[o << 1 | 1] = -(r - mid); n     mx[o << 1] = mx[o << 1 | 1] = -1; n     cov[o] = 0; n   } n } n inline void update(int p, int o, int l, int r, int x) { n   if (l == r) return (void)(tree[o] = mx[o] = x - 1); n   int mid = (l + r) >> 1; n   pushdown(o, l, r); n   mid >= p ? update(p, o << 1, l, mid, x) n            : update(p, o << 1 | 1, mid + 1, r, x); n   pushup(o); n } n inline void upd(int xl, int xr, int o, int l, int r) { n   if (xl <= l && r <= xr) n     return (void)(cov[o] = 1, tree[o] = -(r - l + 1), mx[o] = -1); n   int mid = (l + r) >> 1; n   pushdown(o, l, r); n   if (mid >= xl) upd(xl, xr, o << 1, l, mid); n   if (mid < xr) upd(xl, xr, o << 1 | 1, mid + 1, r); n   pushup(o); n } n struct node { n   int tree, mx; n }; n inline node operator+(node x, node y) { n   node ans; n   ans.tree = x.tree + y.tree; n   ans.mx = max(y.mx, x.mx + y.tree); n   return ans; n } n inline node query(int xl, int xr, int o, int l, int r) { n   if (xl <= l && r <= xr) return (node){tree[o], mx[o]}; n   int mid = (l + r) >> 1; n   pushdown(o, l, r); n   if (mid >= xl && mid < xr) n     return query(xl, xr, o << 1, l, mid) + n            query(xl, xr, o << 1 | 1, mid + 1, r); n   else if (mid >= xl) n     return query(xl, xr, o << 1, l, mid); n   else n     return query(xl, xr, o << 1 | 1, mid + 1, r); n } n inline node qtree(int u, int v) { n   if (!v) return (node){0, 0}; n   node ans; n   bool b = 0; n   while (top[u] ^ top[v]) { n     if (dep[top[u]] < dep[top[v]]) swap(u, v); n     if (b) n       ans = query(tpos[top[u]], tpos[u], 1, 1, n) + ans; n     else n       ans = query(tpos[top[u]], tpos[u], 1, 1, n), b = 1; n     u = fa[top[u]]; n   } n   if (dep[u] < dep[v]) swap(u, v); n   if (b) n     ans = query(tpos[v], tpos[u], 1, 1, n) + ans; n   else n     ans = query(tpos[v], tpos[u], 1, 1, n), b = 1; n   return ans; n } n inline void build(int o, int l, int r) { n   if (l == r) return (void)(tree[o] = mx[o] = -1); n   int mid = (l + r) >> 1; n   build(o << 1, l, mid); n   build(o << 1 | 1, mid + 1, r); n   pushup(o); n } n int main() { n   scanf( %d%d , &n, &m); n   for (int i = 2; i <= n; ++i) scanf( %d , &fa[i]), add(fa[i], i); n   for (int i = n; i >= 1; --i) { n     ++sz[i]; n     sz[fa[i]] += sz[i]; n     if (sz[i] > sz[son[fa[i]]]) son[fa[i]] = i; n   } n   for (int i = 1; i <= n; ++i) dep[i] = dep[fa[i]] + 1; n   dfs2(1, 1); n   build(1, 1, n); n   while (m--) { n     int t, v; n     scanf( %d%d , &t, &v); n     if (t == 1) { n       node x = query(tpos[v], tpos[v], 1, 1, n); n       update(tpos[v], 1, 1, n, x.tree + 2); n     } else if (t == 2) { n       node x = qtree(1, fa[v]); n       upd(tpos[v], tpos[v] + sz[v] - 1, 1, 1, n); n       update(tpos[v], 1, 1, n, min(-x.mx, 0)); n     } else if (t == 3) { n       node ans = qtree(1, v); n       puts(ans.mx >= 0 ?  black  :  white ); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2005; n string s, ans; n bool f, at; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cin >> s; n   int n = s.size(); n   f = at = false; n   for (int i = 0; i < n; i++) { n     if (i < n - 3 && s[i] ==  d  && s[i + 1] ==  o  && s[i + 2] ==  t ) { n       if (f) { n         ans +=  . ; n         i += 2; n       } else { n         ans += s[i]; n         f = true; n       } n     } else if (i < n - 2 && s[i] ==  a  && s[i + 1] ==  t ) { n       if (!at && f) { n         ans +=  @ ; n         i++; n         at = true; n       } else { n         ans += s[i]; n       } n     } else { n       if (!f) f = true; n       ans += s[i]; n     } n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int Nmax = 2e5 + 5; n int A[Nmax], start[Nmax]; n long long cnt[Nmax]; n bool cycle[Nmax]; n int go[Nmax], where[Nmax], visited[Nmax]; n vector<int> active[Nmax], when[Nmax]; n int zz[Nmax], ans[Nmax]; n int nrcomp, n, q, Nr; n vector<int> cyc[Nmax]; n vector<int> query1[Nmax], query2[Nmax], to[Nmax]; n int level[Nmax], L[Nmax], R[Nmax], Size[Nmax]; n vector<int> cc[Nmax]; n class AIB { n   int a[Nmax]; n   int ub(int x) { return (x & (-x)); } n   int query(int pos) { n     int ans = 0; n     for (; pos; pos -= ub(pos)) ans += a[pos]; n     return ans; n   } n  n  public: n   void upd(int pos, int add) { n     for (; pos <= Nr; pos += ub(pos)) a[pos] += add; n   } n   int query(int L, int R) { n     assert(1 <= L && L <= R && R <= Nr); n     return query(R) - query(L - 1); n   } n } aib; n void dfs0(int node) { n   visited[node] = 3; n   where[node] = nrcomp; n   cc[nrcomp].push_back(node); n   L[node] = ++Nr; n   for (auto it : to[node]) n     if (!cycle[it]) { n       go[it] = go[node]; n       level[it] = level[node] + 1; n       dfs0(it); n     } n   R[node] = Nr; n } n void find_comp(int root) { n   int node = root; n   vector<int> nodes; n   while (!visited[node]) { n     visited[node] = 1; n     nodes.push_back(node); n     node = A[node]; n   } n   bool ww = 0; n   for (auto it : nodes) { n     if (it == node) ww = 1; n     if (ww) ++Size[nrcomp], cycle[it] = 1; n   } n   for (auto it : nodes) n     if (cycle[it]) cyc[nrcomp].push_back(it); n   int i; n   for (i = 0; i < cyc[nrcomp].size(); ++i) { n     level[cyc[nrcomp][i]] = 0; n     go[cyc[nrcomp][i]] = i; n     dfs0(cyc[nrcomp][i]); n   } n } n void find_graph() { n   int i; n   for (i = 1; i <= n; ++i) n     if (!visited[i]) { n       ++nrcomp; n       find_comp(i); n     } n } n void solve1(int id) { n   for (auto node : cc[id]) active[level[node]].push_back(go[node]); n   sort(query1[id].begin(), query1[id].end(), n        [](int x, int y) { return cnt[x] < cnt[y]; }); n   if (id == 2) { n   } n   int i; n   int j = 0, k; n   for (i = 0; i < query1[id].size(); ++i) { n     while (j < cc[id].size() && j <= cnt[query1[id][i]]) { n       for (auto it : active[j]) { n         int md = ((it - j) % Size[id] + Size[id]) % Size[id]; n         zz[md]++; n       } n       ++j; n     } n     int tmp = n         (((long long)go[start[query1[id][i]]] - cnt[query1[id][i]]) % Size[id] + n          Size[id]) % n         Size[id]; n     ans[query1[id][i]] = zz[tmp]; n   } n   for (i = 0; i < cc[id].size(); ++i) zz[i] = 0, active[i].clear(); n } n void solve2(int id) { n   for (auto it : query2[id]) n     if (level[start[it]] + cnt[it] < (long long)cc[id].size()) n       when[level[start[it]] + cnt[it]].push_back(it); n   for (auto it : cc[id]) active[level[it]].push_back(L[it]); n   int i; n   for (i = 0; i < cc[id].size(); ++i) { n     for (auto it : active[i]) aib.upd(it, 1); n     for (auto it : when[i]) ans[it] = aib.query(L[start[it]], R[start[it]]); n     for (auto it : active[i]) aib.upd(it, -1); n   } n   for (i = 0; i < cc[id].size(); ++i) active[i].clear(), when[i].clear(); n } n int main() { n   cin.sync_with_stdio(false); n   cin.tie(0); n   int i; n   cin >> n; n   for (i = 1; i <= n; ++i) cin >> A[i], to[A[i]].push_back(i); n   cin >> q; n   for (i = 1; i <= q; ++i) cin >> cnt[i] >> start[i]; n   find_graph(); n   for (i = 1; i <= q; ++i) n     if (cycle[start[i]]) n       query1[where[start[i]]].push_back(i); n     else n       query2[where[start[i]]].push_back(i); n   for (i = 1; i <= nrcomp; ++i) solve1(i); n   for (i = 1; i <= nrcomp; ++i) solve2(i); n   for (i = 1; i <= q; ++i) cout << ans[i] <<   n ; n   return 0; n } n


#include<bits/stdc++.h> n using namespace std; n using ll = long long; n using ii = pair<int,int>; n  n #define ff first n #define se second n #define pb push_back n #define all(x) (x).begin(),(x).end() n  n const int mod = 1e9+7; n const int inf = 1e9; n const int mx  = 1e6+5; n  n #define exitYes {cout<< Yes n ; return;} n #define exitNo  {cout<< No n ;  return;} n  n bool can(vector<ll> a){ n     for(int i=1; i<a.size(); i++){ n         if(a[i-1] > a[i]) return false; n         a[i] -= a[i-1]; a[i-1] = 0; n     }return (a.back() == 0); n } n  n void solve(int cs){ n //    cout <<  Case   << cs <<  :  ; n     int n; cin >> n; n     vector<ll> v(n); n     for(auto &u:v) cin >> u; n  n     if(can(v)) exitYes n     if(n == 1) exitNo n  n     swap(v[0], v[1]);       if(can(v)) exitYes swap(v[0],v[1]); n     swap(v[n-1], v[n-2]);   if(can(v)) exitYes swap(v[n-1], v[n-2]); n  n     vector<ll> p(n), s(n), b = v; n  n     p[0] = b[0]; n     for(int i=1; i<n; i++){ n         if(p[i-1]==-1 || b[i-1]>b[i]) p[i]=-1; n         else b[i]-=b[i-1], b[i-1]=0, p[i]=b[i]; n     }b = v; n  n     s[n-1] = b[n-1]; n     for(int i=n-2; i>=0; i--){ n         if(s[i+1]==-1 || b[i+1]>b[i]) s[i]=-1; n         else b[i]-=b[i+1], b[i+1]=0, s[i]=b[i]; n     } n  n     for(int i=1; i+2<n; i++){ n         if(p[i-1] == -1 || s[i+2]==-1) continue; n         vector<ll> c = {p[i-1], v[i], v[i+1], s[i+2]}; n         swap(c[1], c[2]); if(can(c)) exitYes n     }exitNo n } n  n int main(){ n  n     ios_base::sync_with_stdio(false); n     cin.tie(nullptr); cout.tie(nullptr); n  n     int tc = 1, cs = 1; n     cin >> tc; n     while(tc--) solve(cs++); n  n     return 0; n } n  n


#include <bits/stdc++.h> n using namespace std; n struct pr { n   int type; n   int k; n   char dir; n }; n struct point { n   long long first; n   long long second; n }; n bool cmp(const point &a, const point &b) { n   return sqrt(a.first * a.first + a.second * a.second) < n          sqrt(b.first * b.first + b.second * b.second); n } n int main() { n   int n; n   cin >> n; n   vector<point> cnt; n   for (int i = 0; i < n; i++) { n     long long x, y; n     cin >> x >> y; n     point ty; n     ty.first = x; n     ty.second = y; n     cnt.push_back(ty); n   } n   sort(cnt.begin(), cnt.end(), cmp); n   int ans = 0; n   vector<pr> t; n   for (int i = 0; i < n; i++) { n     int x = cnt[i].first; n     int y = cnt[i].second; n     if (x == 0) { n       ans += 4; n       pr tt; n       tt.type = 1; n       tt.k = abs(y); n       if (y > 0) { n         tt.dir =  U ; n       } else { n         tt.dir =  D ; n       } n       t.push_back(tt); n       tt.type = 2; n       t.push_back(tt); n       tt.type = 1; n       tt.k = abs(y); n       if (y > 0) { n         tt.dir =  D ; n       } else { n         tt.dir =  U ; n       } n       t.push_back(tt); n       tt.type = 3; n       t.push_back(tt); n     } else if (y == 0) { n       ans += 4; n       pr tt; n       tt.type = 1; n       tt.k = abs(x); n       if (x > 0) { n         tt.dir =  R ; n       } else { n         tt.dir =  L ; n       } n       t.push_back(tt); n       tt.type = 2; n       t.push_back(tt); n       tt.type = 1; n       tt.k = abs(x); n       if (x > 0) { n         tt.dir =  L ; n       } else { n         tt.dir =  R ; n       } n       t.push_back(tt); n       tt.type = 3; n       t.push_back(tt); n     } else { n       ans += 6; n       if (x > 0 && y > 0) { n         pr tt; n         tt.type = 1; n         tt.k = abs(x); n         tt.dir =  R ; n         t.push_back(tt); n         tt.type = 1; n         tt.k = abs(y); n         tt.dir =  U ; n         t.push_back(tt); n         tt.type = 2; n         t.push_back(tt); n         tt.type = 1; n         tt.k = abs(x); n         tt.dir =  L ; n         t.push_back(tt); n         tt.type = 1; n         tt.k = abs(y); n         tt.dir =  D ; n         t.push_back(tt); n         tt.type = 3; n         t.push_back(tt); n       } else if (x > 0 && y < 0) { n         pr tt; n         tt.type = 1; n         tt.k = abs(x); n         tt.dir =  R ; n         t.push_back(tt); n         tt.type = 1; n         tt.k = abs(y); n         tt.dir =  D ; n         t.push_back(tt); n         tt.type = 2; n         t.push_back(tt); n         tt.type = 1; n         tt.k = abs(x); n         tt.dir =  L ; n         t.push_back(tt); n         tt.type = 1; n         tt.k = abs(y); n         tt.dir =  U ; n         t.push_back(tt); n         tt.type = 3; n         t.push_back(tt); n       } else if (x < 0 && y > 0) { n         pr tt; n         tt.type = 1; n         tt.k = abs(x); n         tt.dir =  L ; n         t.push_back(tt); n         tt.type = 1; n         tt.k = abs(y); n         tt.dir =  U ; n         t.push_back(tt); n         tt.type = 2; n         t.push_back(tt); n         tt.type = 1; n         tt.k = abs(x); n         tt.dir =  R ; n         t.push_back(tt); n         tt.type = 1; n         tt.k = abs(y); n         tt.dir =  D ; n         t.push_back(tt); n         tt.type = 3; n         t.push_back(tt); n       } else if (x < 0 && y < 0) { n         pr tt; n         tt.type = 1; n         tt.k = abs(x); n         tt.dir =  L ; n         t.push_back(tt); n         tt.type = 1; n         tt.k = abs(y); n         tt.dir =  D ; n         t.push_back(tt); n         tt.type = 2; n         t.push_back(tt); n         tt.type = 1; n         tt.k = abs(x); n         tt.dir =  R ; n         t.push_back(tt); n         tt.type = 1; n         tt.k = abs(y); n         tt.dir =  U ; n         t.push_back(tt); n         tt.type = 3; n         t.push_back(tt); n       } n     } n   } n   cout << ans << endl; n   for (int i = 0; i < t.size(); i++) { n     if (t[i].type == 1) { n       printf( %d %d %c n , t[i].type, t[i].k, t[i].dir); n     } else { n       printf( %d n , t[i].type); n     } n   } n   return 0; n } n


#include<iostream> n using namespace std; n int main() n { n  ios_base::sync_with_stdio(false); n  cin.tie(0); n  cout.tie(0); n  int a; n  cin >> a; n  cout << 2-a*a; n  return 0; n } n  n