#include <bits/stdc++.h> n using namespace std; n const int N = 305; n long long dist[10][N][N], I[2][N][N]; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int n, m; n   cin >> n >> m; n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= n; j++) { n       if (i != j) dist[0][i][j] = INT_MIN; n       I[0][i][j] = dist[0][i][j]; n     } n   for (int i = 1; i <= m; i++) { n     int x, y, c1, c2; n     cin >> x >> y >> c1 >> c2; n     dist[0][x][y] = c1; n     dist[0][y][x] = c2; n   } n   for (int c = 1; c < 10; c++) { n     for (int i = 1; i <= n; i++) n       for (int j = 1; j <= n; j++) dist[c][i][j] = dist[c - 1][i][j]; n     for (int i = 1; i <= n; i++) n       for (int k = 1; k <= n; k++) n         for (int j = 1; j <= n; j++) n           dist[c][i][j] = n               max(dist[c][i][j], dist[c - 1][i][k] + dist[c - 1][k][j]); n   } n   bool ok = 0; n   for (int i = 1; i <= n; i++) n     if (dist[9][i][i] > 0) { n       ok = 1; n       break; n     } n   if (!ok) { n     cout << 0; n     return 0; n   } n   int ans = 1; n   for (int bit = 9; bit >= 0; bit--) { n     ok = 0; n     for (int i = 1; i <= n; i++) n       for (int j = 1; j <= n; j++) I[1][i][j] = I[0][i][j]; n     for (int i = 1; i <= n; i++) n       for (int k = 1; k <= n; k++) n         for (int j = 1; j <= n; j++) n           I[1][i][j] = max(I[1][i][j], I[0][i][k] + dist[bit][k][j]); n     for (int i = 1; i <= n; i++) n       if (I[1][i][i] > 0) { n         ok = 1; n         break; n       } n     if (!ok) { n       ans += (1 << bit); n       for (int i = 1; i <= n; i++) n         for (int j = 1; j <= n; j++) I[0][i][j] = I[1][i][j]; n     } n   } n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 200025; n int n, m, i, j, t, k, s, mod, a[maxn], fat[maxn]; n bool flg, vis[maxn << 1]; n inline int Pow(int x, int y, int mo) { n   int ret = 1; n   while (y) { n     if (y & 1) ret = 1ll * ret * x % mo; n     x = 1ll * x * x % mo; n     y >>= 1; n   } n   return ret; n } n int father(int x) { return x == fat[x] ? x : fat[x] = father(fat[x]); } n void solve(int delt) { n   for (i = 1; i <= n; ++i) fat[i] = i; n   for (i = 1; i <= n; ++i) { n     k = (a[i] - delt + mod) % mod; n     t = lower_bound(a + 1, a + n + 1, k) - a; n     if (a[t] == k) fat[father(t)] = father(i); n   } n   t = 0; n   for (i = 1; i <= n; ++i) { n     if (fat[i] == i) n       t++; n     else n       fat[i] = i; n   } n   delt = delt * 1ll * Pow(t, mod - 2, mod) % mod; n   for (i = 1; i <= n; ++i) { n     k = (a[i] - delt + mod) % mod; n     t = lower_bound(a + 1, a + n + 1, k) - a; n     if (a[t] == k) fat[father(t)] = father(i); n   } n   for (i = 2; i <= n; ++i) n     if (father(i) ^ father(1)) break; n   if (i > n) { n     for (i = 1; i <= n; ++i) { n       k = (a[i] - delt + mod) % mod; n       t = lower_bound(a + 1, a + n + 1, k) - a; n       if (a[t] != k) break; n     } n     if (i > n) { n       if (flg) n         printf( %d %d n , a[1], delt); n       else n         t = (1ll * n * delt + a[1]) % mod, printf( %d %d n , t, delt); n     } else { n       if (flg) n         printf( %d %d n , a[i], delt); n       else n         t = (1ll * n * delt + a[i]) % mod, printf( %d %d n , t, delt); n     } n     exit(0); n   } n } n int main() { n   scanf( %d%d , &mod, &n); n   for (i = 1; i <= n; ++i) scanf( %d , &a[i]); n   a[n + 1] = mod + 114514; n   if (n == 1 || n == mod) { n     printf( %d %d n , a[1], 1); n     return 0; n   } n   if (n == 2) { n     printf( %d %d n , a[1], (a[2] - a[1] + mod) % mod); n     return 0; n   } n   sort(a + 1, a + n + 1); n   flg = 1; n   if (2 * n > mod) { n     flg = 0; n     for (i = 1; i <= n; ++i) vis[a[i]] = 1; n     n = 0; n     for (i = 0; i < mod; ++i) n       if (!vis[i]) a[++n] = i; n     a[n + 1] = mod + 114514; n     if (n == 1) { n       printf( %d %d n , (a[1] + 1) % mod, 1); n       return 0; n     } n   } n   solve(a[2] - a[1]); n   solve((a[1] - a[2] + mod) % mod); n   puts( -1 ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char mainstr[111111]; n char substr1[111]; n char substr2[111]; n int main() { n   while (scanf( %s %s %s , mainstr, substr1, substr2) != EOF) { n     bool flag1 = false, flag2 = false; n     int len = strlen(mainstr); n     int len1 = strlen(substr1); n     int len2 = strlen(substr2); n     char *pos = search(mainstr, mainstr + len, substr1, substr1 + len1); n     if (pos != mainstr + len && search(pos + len1, mainstr + len, substr2, n                                        substr2 + len2) != mainstr + len) n       flag1 = true; n     reverse(mainstr, mainstr + len); n     pos = search(mainstr, mainstr + len, substr1, substr1 + len1); n     if (pos != mainstr + len && search(pos + len1, mainstr + len, substr2, n                                        substr2 + len2) != mainstr + len) n       flag2 = true; n     if (flag1 && flag2) n       printf( both n ); n     else if (flag1) n       printf( forward n ); n     else if (flag2) n       printf( backward n ); n     else n       printf( fantasy n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long mod = 1e9 + 7; n const double pi = acos(-1); n long long n; n string str; n int main() { n   cin >> n >> str; n   sort(str.begin(), str.end()); n   cout << str << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1000 * 100 + 10, LG = 20; n int n, h[N], st[N], en[N], par[N][LG], seg[N << 2], lazy[N << 2], TM, ver[N], n     ans[N]; n vector<int> adj[N]; n struct Query { n   int l, r, id; n   Query(int x = 0, int y = 0, int z = 0) { l = x, r = y, id = z; } n }; n vector<Query> query[N]; n void dfs(int v) { n   st[v] = TM++; n   ver[st[v]] = h[v]; n   for (int i = 1; i < LG; i++) par[v][i] = par[par[v][i - 1]][i - 1]; n   for (auto u : adj[v]) n     if (u != par[v][0]) { n       par[u][0] = v; n       h[u] = h[v] + 1; n       dfs(u); n     } n   en[v] = TM; n } n int k_par(int v, int k) { n   for (int i = 0; i < LG; i++) n     if (k >> i & 1) v = par[v][i]; n   return v; n } n int lca(int v, int u) { n   if (h[v] < h[u]) swap(v, u); n   v = k_par(v, h[v] - h[u]); n   if (v == u) return v; n   for (int i = LG - 1; i >= 0; i--) n     if (par[v][i] != par[u][i]) v = par[v][i], u = par[u][i]; n   return par[v][0]; n } n int d(int v, int u) { return h[v] + h[u] - 2 * h[lca(v, u)]; } n void build(int l = 0, int r = n, int id = 1) { n   if (l + 1 == r) { n     seg[id] = ver[l]; n     return; n   } n   int mid = l + r >> 1; n   build(l, mid, id << 1), build(mid, r, id << 1 | 1); n   seg[id] = max(seg[id << 1], seg[id << 1 | 1]); n } n void add(int id, int x) { n   seg[id] += x; n   lazy[id] += x; n } n void shift(int id) { n   add(id << 1, lazy[id]); n   add(id << 1 | 1, lazy[id]); n   lazy[id] = 0; n } n int get(int s, int e, int l = 0, int r = n, int id = 1) { n   if (s <= l && e >= r) return seg[id]; n   if (s >= r || e <= l) return 0; n   shift(id); n   int mid = l + r >> 1; n   return max(get(s, e, l, mid, id << 1), get(s, e, mid, r, id << 1 | 1)); n } n void upd(int s, int e, int x, int l = 0, int r = n, int id = 1) { n   if (s <= l && e >= r) { n     add(id, x); n     return; n   } n   if (s >= r || e <= l) return; n   shift(id); n   int mid = l + r >> 1; n   upd(s, e, x, l, mid, id << 1), upd(s, e, x, mid, r, id << 1 | 1); n   seg[id] = max(seg[id << 1], seg[id << 1 | 1]); n } n void dfs_ans(int v) { n   for (auto q : query[v]) ans[q.id] = max(ans[q.id], get(q.l, q.r)); n   for (auto u : adj[v]) n     if (u != par[v][0]) { n       upd(st[u], en[u], -1); n       upd(0, st[u], +1); n       upd(en[u], n, +1); n       dfs_ans(u); n       upd(st[u], en[u], +1); n       upd(0, st[u], -1); n       upd(en[u], n, -1); n     } n } n int main() { n   ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); n   cin >> n; n   for (int i = 1, v, u; i < n; i++) { n     cin >> v >> u; n     --v, --u; n     adj[v].push_back(u); n     adj[u].push_back(v); n   } n   dfs(0); n   build(); n   int Q; n   cin >> Q; n   for (int i = 0, v, u; i < Q; i++) { n     cin >> v >> u; n     --v, --u; n     if (h[v] < h[u]) swap(v, u); n     int dis = d(v, u); n     int w = k_par(v, (dis - 1) / 2); n     query[v].push_back(Query(st[w], en[w], i)); n     query[u].push_back(Query(0, st[w], i)); n     query[u].push_back(Query(en[w], n, i)); n   } n   dfs_ans(0); n   for (int i = 0; i < Q; i++) cout << ans[i] <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   int tt; n   cin >> tt; n   while (tt--) { n     int n; n     cin >> n; n     vector<int> a(n); n     for (int i = 0; i < n; ++i) { n       cin >> a[i]; n     } n     int ans = 0; n     function<void(int, int)> dfs = [&](int p, int s) { n       if (p == n) { n         if (!s) { n           ++ans; n         } n         return; n       } n       dfs(p + 1, s - a[p]); n       dfs(p + 1, s); n       dfs(p + 1, s + a[p]); n     }; n     dfs(0, 0); n     cout << (ans >= 2 ?  YES  :  NO ) <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void print(vector<int> v) { n   for (int i = 0; i < v.size(); i++) { n     if (v[i] != 0) { n       cout << v[i]; n     } n   } n   cout << endl; n } n void solve(vector<int>& v, int even, int odd) { n   if (v.size() == 1) { n     cout << -1 << endl; n     return; n   } else if (v.size() == 2) { n     if (odd != 2) { n       cout << -1 << endl; n       return; n     } else { n       print(v); n       return; n     } n   } else if (odd == 0) { n     cout << -1 << endl; n     return; n   } else { n     while (v[v.size() - 1] % 2 == 0) { n       v.pop_back(); n       even--; n     } n     if (odd == 1) { n       cout << -1 << endl; n       return; n     } else if (odd % 2 == 0) { n       print(v); n       return; n     } else { n       for (int i = 0; i < v.size(); i++) { n         if (v[i] % 2 == 1) { n           v.erase(v.begin() + i); n           print(v); n           return; n         } n       } n     } n   } n } n int main() { n   int t; n   cin >> t; n   while (t--) { n     int e = 0, o = 0; n     int n; n     cin >> n; n     string s; n     cin >> s; n     vector<int> v(n); n     for (int i = 0; i < s.size(); i++) { n       v[i] = s[i] - 48; n       if (v[i] % 2 == 0) n         e++; n       else n         o++; n     } n     solve(v, e, o); n   } n } n


#include <bits/stdc++.h> n using std::max; n using std::min; n const int inf = 0x3f3f3f3f, Inf = 0x7fffffff; n const long long INF = 0x3f3f3f3f3f3f3f3f; n std::mt19937 rnd(std::chrono::steady_clock::now().time_since_epoch().count()); n template <typename _Tp> n _Tp gcd(const _Tp &a, const _Tp &b) { n   return (!b) ? a : gcd(b, a % b); n } n template <typename _Tp> n inline _Tp abs(const _Tp &a) { n   return a >= 0 ? a : -a; n } n template <typename _Tp> n inline void chmax(_Tp &a, const _Tp &b) { n   (a < b) && (a = b); n } n template <typename _Tp> n inline void chmin(_Tp &a, const _Tp &b) { n   (b < a) && (a = b); n } n template <typename _Tp> n inline void read(_Tp &x) { n   char ch(getchar()); n   bool f(false); n   while (!isdigit(ch)) f |= ch == 45, ch = getchar(); n   x = ch & 15, ch = getchar(); n   while (isdigit(ch)) x = (((x << 2) + x) << 1) + (ch & 15), ch = getchar(); n   f && (x = -x); n } n template <typename _Tp, typename... Args> n inline void read(_Tp &t, Args &...args) { n   read(t); n   read(args...); n } n inline int read_str(char *s) { n   char ch(getchar()); n   while (ch ==     || ch ==   r  || ch ==   n ) ch = getchar(); n   char *tar = s; n   *tar++ = ch, ch = getchar(); n   while (ch !=     && ch !=   r  && ch !=   n  && ch != EOF) n     *tar++ = ch, ch = getchar(); n   return *tar = 0, tar - s; n } n const int max_len = 1 << 18; n const int N = max_len + 9; n const int mod = 998244353; n int _inv_[N]; n template <typename _Tp1, typename _Tp2> n inline void add(_Tp1 &a, _Tp2 b) { n   (a += b) >= mod && (a -= mod); n } n template <typename _Tp1, typename _Tp2> n inline void sub(_Tp1 &a, _Tp2 b) { n   (a -= b) < 0 && (a += mod); n } n template <typename _Tp> n inline _Tp _sub(_Tp a, const _Tp &b) { n   (a += mod - b) >= mod && (a -= mod); n   return a; n } n long long ksm(long long a, long long b = mod - 2) { n   long long res = 1; n   while (b) { n     if (b & 1) res = res * a % mod; n     a = a * a % mod, b >>= 1; n   } n   return res; n } n void print(const std::vector<int> &a) { n   for (auto it : a) printf( %d  , it); n   printf(  n ); n } n std::vector<int> operator<<(const std::vector<int> &a, unsigned int b) { n   std::vector<int> o(a.size() + b); n   for (unsigned int i = 0; i < b; ++i) o[i] = 0; n   for (unsigned int i = 0; i < a.size(); ++i) o[i + b] = a[i]; n   return o; n } n inline std::vector<int> operator<<=(std::vector<int> &a, unsigned int b) { n   return a = a << b; n } n inline std::vector<int> operator>>(const std::vector<int> &a, unsigned int b) { n   return b >= a.size() ? std::vector<int>() n                        : std::vector<int>{a.begin() + b, a.end()}; n } n inline std::vector<int> operator>>=(std::vector<int> &a, unsigned int b) { n   return a = b >= a.size() ? std::vector<int>() n                            : std::vector<int>{a.begin() + b, a.end()}; n } n std::vector<int> operator+=(std::vector<int> &a, const std::vector<int> &b) { n   if (((int)b.size()) > ((int)a.size())) a.resize(((int)b.size())); n   for (unsigned int i = 0; i < b.size(); ++i) add(a[i], b[i]); n   return a; n } n inline std::vector<int> operator+(const std::vector<int> &a, n                                   const std::vector<int> &b) { n   std::vector<int> tmp(a); n   tmp += b; n   return tmp; n } n std::vector<int> operator-=(std::vector<int> &a, const std::vector<int> &b) { n   if (((int)b.size()) > ((int)a.size())) a.resize(((int)b.size())); n   for (unsigned int i = 0; i < b.size(); ++i) sub(a[i], b[i]); n   return a; n } n inline std::vector<int> operator-(const std::vector<int> &a, n                                   const std::vector<int> &b) { n   std::vector<int> tmp(a); n   tmp -= b; n   return tmp; n } n int Omgs[N], r[N]; n const long long G = ksm(3, (mod - 1) / max_len); n int calc(int len) { n   int limit = 1; n   while (limit < len) limit <<= 1; n   for (int i = 0; i < limit; ++i) n     r[i] = (r[i >> 1] >> 1) | ((i & 1) ? (limit >> 1) : 0); n   return limit; n } n void setup() { n   _inv_[0] = _inv_[1] = 1; n   for (int i = 2; i < N; ++i) n     _inv_[i] = 1ll * _inv_[mod % i] * (mod - mod / i) % mod; n   Omgs[max_len >> 1] = 1; n   for (int i = (max_len >> 1) + 1; i < max_len; ++i) n     Omgs[i] = 1LL * Omgs[i - 1] * G % mod; n   for (int i = (max_len >> 1) - 1; i >= 0; --i) Omgs[i] = Omgs[i << 1]; n } n void dft(std::vector<int> &a, int limit) { n   static int A[N]; n   for (int i = 0; i < limit; ++i) A[r[i]] = a[i]; n   for (int len = 2, hf = 1; len <= limit; len <<= 1, hf <<= 1) n     for (int pos = 0; pos < limit; pos += len) { n       int *w(Omgs + hf), *p(A + pos), *q(A + pos + hf); n       for (int i = 0; i < hf; ++i, ++p, ++q) { n         int tmp = 1LL * (*w++) * (*q) % mod; n         *q = _sub(*p, tmp), add(*p, tmp); n       } n     } n   for (int i = 0; i < limit; ++i) a[i] = A[i] % mod; n } n void idft(std::vector<int> &a, int limit) { n   std::reverse(&a[1], &a[limit]); n   dft(a, limit); n   unsigned long long inv = mod - (mod - 1) / limit; n   for (int i = 0; i < limit; ++i) a[i] = inv * a[i] % mod; n } n std::vector<int> operator*(std::vector<int> a, std::vector<int> b) { n   if (a.size() <= 40u || b.size() <= 40u) { n     std::vector<int> c(((int)a.size()) + ((int)b.size()) - 1); n     for (unsigned int i = 0; i < a.size(); ++i) n       for (unsigned int j = 0; j < b.size(); ++j) n         add(c[i + j], 1ull * a[i] * b[j] % mod); n     return c; n   } n   int tmp = ((int)a.size()) + ((int)b.size()), limit = calc(tmp); n   a.resize(limit), b.resize(limit), dft(a, limit), dft(b, limit); n   for (int i = 0; i < limit; ++i) a[i] = 1ull * a[i] * b[i] % mod; n   return idft(a, limit), a.resize(tmp - 1), a; n } n std::vector<int> sqr(std::vector<int> a) { n   if (a.size() <= 40u) { n     std::vector<int> c(((int)a.size()) + ((int)a.size()) - 1); n     for (unsigned int i = 0; i < a.size(); ++i) n       for (unsigned int j = 0; j < a.size(); ++j) n         add(c[i + j], 1ull * a[i] * a[j] % mod); n     return c; n   } n   int tmp = ((int)a.size()) << 1, limit = calc(tmp); n   a.resize(limit), dft(a, limit); n   for (int i = 0; i < limit; ++i) a[i] = 1ull * a[i] * a[i] % mod; n   return idft(a, limit), a.resize(tmp - 1), a; n } n inline std::vector<int> operator*=(std::vector<int> &a, n                                    const std::vector<int> &b) { n   return a = a * b; n } n template <typename _Tp> n inline std::vector<int> operator*=(std::vector<int> &a, const _Tp &b) { n   for (auto &&it : a) it = 1ll * it * b % mod; n   return a; n } n template <typename _Tp> n inline std::vector<int> operator*(std::vector<int> a, const _Tp &b) { n   return a *= b; n } n template <typename _Tp> n inline std::vector<int> operator*(const _Tp &b, std::vector<int> a) { n   return a *= b; n } n template <typename _Tp> n inline std::vector<int> operator/=(std::vector<int> &a, const _Tp &b) { n   long long inv = ksm(b); n   for (auto &&it : a) it = 1ll * it * inv % mod; n   return a; n } n template <typename _Tp> n inline std::vector<int> operator/(std::vector<int> a, const _Tp &b) { n   return a /= b; n } n template <typename _Tp> n inline std::vector<int> operator/(const _Tp &b, std::vector<int> a) { n   return a /= b; n } n std::vector<int> _inv(const std::vector<int> &F) { n   int len = ((int)F.size()); n   if (len == 1) return {(int)ksm(F[0])}; n   std::vector<int> H(_inv({F.begin(), F.begin() + (len >> 1)})), tmp(F * H), n       ans(H); n   tmp = std::vector<int>{tmp.begin() + (len >> 1), tmp.end()} * H; n   ans.resize(len); n   for (int i = 0; i < len >> 1; ++i) n     tmp[i] && (ans[(len >> 1) + i] = mod - tmp[i]); n   return ans; n } n std::vector<int> Inv(std::vector<int> F) { n   int tmp = ((int)F.size()), L = 1; n   for (; L < tmp; L <<= 1) n     ; n   F.resize(L); n   std::vector<int> ans(_inv(F)); n   return ans.resize(tmp), ans; n } n std::pair<std::vector<int>, std::vector<int> > divide( n     const std::vector<int> &f, const std::vector<int> &g) { n   int n = ((int)f.size()), m = ((int)g.size()); n   std::vector<int> F(f), G(g); n   std::reverse(F.begin(), F.end()), F.resize(n - m + 1); n   std::reverse(G.begin(), G.end()), G.resize(n - m + 1); n   std::vector<int> Q(F * Inv(G)); n   Q.resize(n - m + 1), std::reverse(Q.begin(), Q.end()); n   std::vector<int> R(f - Q * g); n   return R.resize(m - 1), std::make_pair(Q, R); n } n inline std::vector<int> Mod(const std::vector<int> &f, n                             const std::vector<int> &g) { n   return divide(f, g).second; n } n std::vector<int> _sqrt(const std::vector<int> &F) { n   int len = ((int)F.size()); n   if (len == 1) return {1}; n   std::vector<int> H(_sqrt({F.begin(), F.begin() + (len >> 1)})); n   H.resize(len); n   return (H + F * _inv(H)) / 2; n } n std::vector<int> Sqrt(std::vector<int> F) { n   int tmp = ((int)F.size()), L = 1; n   for (; L < tmp; L <<= 1) n     ; n   F.resize(L); n   std::vector<int> ans(_sqrt(F)); n   return ans.resize(tmp), ans; n } n std::vector<int> deri(std::vector<int> a) { n   for (int i = 0; i + 1 < ((int)a.size()); ++i) n     a[i] = 1ll * (i + 1) * a[i + 1] % mod; n   return a.pop_back(), a; n } n std::vector<int> inte(std::vector<int> a) { n   a.resize(((int)a.size()) + 1); n   for (int i = ((int)a.size()) - 1; i >= 1; --i) n     a[i] = 1ll * a[i - 1] * _inv_[i] % mod; n   return a[0] = 0, a; n } n std::vector<int> Ln(std::vector<int> F) { n   std::vector<int> ans(inte(deri(F) * Inv(F))); n   return ans.resize(((int)F.size())), ans; n } n std::vector<int> _exp(const std::vector<int> &F) { n   int len = ((int)F.size()); n   if (len == 1) return {1}; n   std::vector<int> H(_exp({F.begin(), F.begin() + (len >> 1)})); n   H.resize(len); n   std::vector<int> ans(F - Ln(H)); n   add(ans[0], 1); n   H.resize(len >> 1); n   return ans *= H, ans.resize(len), ans; n } n std::vector<int> Exp(std::vector<int> F) { n   int tmp = ((int)F.size()), L = 1; n   for (; L < tmp; L <<= 1) n     ; n   F.resize(L); n   std::vector<int> ans(_exp(F)); n   return ans.resize(tmp), ans; n } n std::vector<int> ksm(std::vector<int> a, int b) { n   a = Ln(a); n   for (auto &&it : a) it = 1ll * it * b % mod; n   return Exp(a); n } n long long fac[N], inv[N], ifac[N]; n int main() { n   setup(); n   fac[0] = fac[1] = inv[0] = inv[1] = ifac[0] = ifac[1] = 1; n   for (int i = 2; i < N; ++i) n     fac[i] = fac[i - 1] * i % mod, n     inv[i] = inv[mod % i] * (mod - mod / i) % mod, n     ifac[i] = ifac[i - 1] * inv[i] % mod; n   int n; n   read(n); n   std::vector<int> H(n + 5); n   for (int i = 0; i < n + 5; ++i) H[i] = i & 1 ? mod - inv[i + 1] : inv[i + 1]; n   H = Inv(H); n   std::vector<int> tp(Inv((std::vector<int>{1} - H) >> 1)), tmp(ksm(H, n + 1)), n       B(tmp * tp); n   B.resize(n + 5); n   std::vector<int> A(deri(H) * B); n   A.resize(n + 5), A *= tp, A.resize(n + 5); n   std::vector<int> C(n + 5); n   for (int i = 0; i <= n; ++i) n     C[i] = 1LL * inv[n + 1] * n            ((A[i + 1] + 1LL * B[i + 1] * (n - i + 1)) % mod) % mod; n   std::vector<int> D(n + 5); n   for (int i = 2; i < n + 5; ++i) D[i - 2] = mod - ifac[i]; n   D = Inv(D) >> 1; n   std::vector<int> F(D - C); n   sub(F[0], 1), F.resize(n + 1); n   for (int i = 0; i < ((int)F.size()); ++i) F[i] = fac[i] * F[i] % mod; n   std::vector<int> G(n + 5); n   for (int i = 0; i <= n; ++i) G[n - i] = i & 1 ? mod - ifac[i] : ifac[i]; n   F *= G; n   for (int i = 0; i < n; ++i) n     printf( %lld%c , 1LL * fac[n] * ifac[i] % mod * F[i + n] % mod, n               n [i == n]); n   return 0; n } n


#include <bits/stdc++.h> n const long long N = 200200; n const long long Q = 100100; n const long long mod = 998244353; n const long long block = 500; n using namespace std; n string s; n int cnt; n bool t; n void solve() { n   cin >> s; n   for (int i = 0; i < s.size(); i++) { n     if (s[i] ==  1 ) { n       t = 1; n     } else if (t) { n       cnt++; n     } n   } n   if (cnt >= 6) { n     cout <<  yes  n          <<   n ; n   } else { n     cout <<  no  n          <<   n ; n   } n } n bool mtest = false; n int main() { n   ios_base::sync_with_stdio(0); n   int TE = 1; n   if (mtest) cin >> TE; n   while (TE--) solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 100005; n int N; n int a[MAXN]; n vector<int> lol; n int main(int argc, char *argv[]) { n   scanf( %d , &N); n   int p = 1; n   while (p < MAXN) { n     lol.push_back(p); n     p <<= 1; n   } n   for (int i = 0, _i = N; i < _i; ++i) { n     scanf( %d , a + i); n   } n   long long ans = 0; n   for (int i = 0, _i = N - 1; i < _i; ++i) { n     ans += a[i]; n     cout << ans <<   n ; n     a[i + *(--upper_bound(lol.begin(), lol.end(), N - i - 1))] += a[i]; n     a[i] = 0; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void display(vector<int> &a) { n   for (int z : a) cout << z <<    ; n   cout << endl; n } n int dx[4] = {0, 0, 1, -1}; n int dy[4] = {1, -1, 0, 0}; n const int mod = 998244353; n const long long INF64 = 3e18; n void smxl(long long &a, long long b) { n   if (a < b) a = b; n } n void smnl(long long &a, long long b) { n   if (a > b) a = b; n } n void adsl(long long &a, long long b) { n   a += b; n   if (a >= mod) a -= mod; n } n void misl(long long &a, long long b) { n   a -= b; n   if (a >= mod) a -= mod; n   if (a < 0) a += mod; n } n void smx(long long &a, long long b) { n   if (a < b) a = b; n } n void smn(long long &a, long long b) { n   if (a > b) a = b; n } n void ads(long long &a, long long b) { n   a += b; n   if (a >= mod) a -= mod; n } n void mis(long long &a, long long b) { n   a -= b; n   if (a >= mod) a -= mod; n   if (a < 0) a += mod; n } n long long gcd(long long a, long long b) { return (b == 0 ? a : gcd(b, a % b)); } n long long egcd(long long a, long long b, long long &x, long long &y) { n   if (a == 0) { n     x = 0; n     y = 1; n     return b; n   } n   long long x1, y1; n   long long d = egcd(b % a, a, x1, y1); n   x = y1 - (b / a) * x1; n   y = x1; n   return d; n } n long long mbinp(long long a, long long b) { n   a %= mod; n   if (b == 0) return 1; n   long long ans = mbinp(a, b / 2); n   long long tmp = (ans * ans) % mod; n   if (b % 2) return ((tmp * a) % mod); n   return ((tmp) % mod); n } n long long binp(long long a, long long b) { n   if (b == 0) return 1; n   long long ans = binp(a, b / 2); n   long long tmp = (ans * ans); n   if (b % 2) return ((tmp * a)); n   return ((tmp)); n } n long long C(int n, int m) { n   long long ret = 1; n   for (int i = 1; i <= m; i++) { n     ret *= (n - i + 1); n     ret /= i; n   } n   return ret; n } n long long overbinp(long long a, int b) { n   long long res = 1; n   while (b) { n     if (b & 1) { n       if (res < INF64 / a) n         res *= a; n       else n         return INF64; n     } n     if (b > 1) { n       if (a < INF64 / a) n         a *= a; n       else n         return INF64; n     } n     b >>= 1; n   } n   return res; n } n class DSU { n   vector<int> par; n   vector<int> siize; n  n  public: n   DSU(int n) { n     par.resize(n); n     siize.resize(n); n     for (int i = 0; i < n; i++) { n       par[i] = i; n       siize[i] = 1; n     } n   } n  n  public: n   int get(int x) { return (x == par[x] ? x : par[x] = get(par[x])); } n  n  public: n   void merge(int a, int b) { n     int x = get(a); n     int y = get(b); n     if (x == y) return; n     if (siize[x] < siize[y]) swap(x, y); n     par[y] = x; n     siize[x] += siize[y]; n   } n }; n class BinaryLift { n   vector<vector<int> > binlift; n   int n; n  n  public: n   BinaryLift(vector<int> rnk, vector<int> par) { n     n = (int)par.size(); n     binlift.resize(n); n     for (int i = 0; i < n; i++) binlift[i].resize(20); n     for (int i = 0; i < n; i++) binlift[i][0] = par[i]; n     for (int j = 1; j < 20; j++) n       for (int i = 0; i < n; i++) { n         if ((1 << j) < rnk[i]) n           binlift[i][j] = binlift[binlift[i][j - 1]][j - 1]; n         else n           binlift[i][j] = -1; n       } n   } n  n  public: n   int get_kth_ancestor(int x, int k) { n     int pt = x; n     for (int i = 19; i >= 0; i--) { n       if (pt == -1) exit(0); n       if (k & (1 << i)) pt = binlift[pt][i]; n     } n     return pt; n   } n  n  public: n   int get_th_ancestor(int x, int k) { n     int pt = x; n     for (int i = 19; i >= 0; i--) { n       if (k & (1 << i)) pt = binlift[pt][i]; n     } n     return pt; n   } n }; n class SparseTable2D { n   vector<vector<vector<vector<int> > > > sparse; n   vector<vector<int> > inp; n   int m, n; n  n  private: n   int lg2(int x) { n     int out = 0; n     while ((1 << out) <= x) out++; n     return out - 1; n   } n  n  public: n   int rmin(int x1, int y1, int x2, int y2) { n     int lenx = x2 - x1 + 1; n     int lx = lg2(lenx) + 1; n     int leny = y2 - y1 + 1; n     int ly = lg2(leny) + 1; n     return min( n         min(sparse[lx][x1][ly][y1], sparse[lx][x1][ly][y2 + 1 - (1 << ly)]), n         min(sparse[lx][x2 + 1 - (1 << lx)][ly][y1], n             sparse[lx][x2 + 1 - (1 << lx)][ly][y2 + 1 - (1 << ly)])); n   } n  n  public: n   SparseTable2D(vector<vector<int> > input, string param) { n     n = input.size(); n     m = input[0].size(); n     inp = input; n     if (param ==  min ) prepromin(); n   } n  n  private: n   void prepromin() { n     int lln, lm; n     lln = lg2(n) + 1; n     lm = lg2(m) + 1; n     sparse.resize(lln); n     for (int i = 0; i < lln; i++) sparse[i].resize(n); n     for (int i = 0; i < lln; i++) n       for (int j = 0; j < n; j++) sparse[i][j].resize(lm); n     for (int i = 0; i < lln; i++) n       for (int j = 0; j < n; j++) n         for (int k = 0; k < lm; k++) sparse[i][j][k].resize(m); n     for (int i = 0; i < n; i++) { n       for (int j = 0; j < m; j++) sparse[0][i][0][j] = inp[i][j]; n       for (int j = 1; j < lm; j++) n         for (int k = 0; k + (1 << j) - 1 < m; k++) n           sparse[0][i][j][k] = min(sparse[0][i][j - 1][k], n                                    sparse[0][i][j - 1][k + (1 << (j - 1))]); n     } n     for (int i = 1; i < lln; i++) n       for (int j = 0; j + (1 << i) - 1 < n; j++) n         for (int k = 0; k < lm; k++) n           for (int h = 0; h < m; h++) n             sparse[i][j][k][h] = min(sparse[i - 1][j][k][h], n                                      sparse[i - 1][j + (1 << (i - 1))][k][h]); n   } n }; n class SparseTable { n   vector<vector<long long> > sparse; n   int n; n   vector<int> input; n  n  private: n   int lg2(int x) { n     int out = 0; n     while ((1 << out) <= x) out++; n     return out - 1; n   } n  n  public: n   int rmaxpos(int left, int right) { n     int len = right - left + 1; n     int lg = lg2(len); n     return (input[sparse[left][lg]] > input[sparse[left + len - (1 << lg)][lg]] n                 ? sparse[left][lg] n                 : sparse[left + len - (1 << lg)][lg]); n   } n  n  public: n   int rmaxval(int left, int right) { n     int len = right - left + 1; n     int lg = lg2(len); n     return (input[sparse[left][lg]] > input[sparse[left + len - (1 << lg)][lg]] n                 ? input[sparse[left][lg]] n                 : input[sparse[left + len - (1 << lg)][lg]]); n   } n  n  public: n   int rminpos(int left, int right) { n     int len = right - left + 1; n     int lg = lg2(len); n     return (input[sparse[left][lg]] < input[sparse[left + len - (1 << lg)][lg]] n                 ? sparse[left][lg] n                 : sparse[left + len - (1 << lg)][lg]); n   } n  n  public: n   int rminval(int left, int right) { n     int len = right - left + 1; n     int lg = lg2(len); n     return (input[sparse[left][lg]] < input[sparse[left + len - (1 << lg)][lg]] n                 ? input[sparse[left][lg]] n                 : input[sparse[left + len - (1 << lg)][lg]]); n   } n  n  public: n   long long rsum(int left, int right) { n     long long ans = 0; n     int pos; n     while (left <= right) { n       for (int i = 19; i >= 0; i--) n         if ((1 << i) <= right - left + 1) { n           pos = i; n           break; n         } n       ans += sparse[left][pos]; n       left = left + (1 << pos); n     } n     return ans; n   } n  n  public: n   SparseTable(vector<int> inp, string operation) { n     input = inp; n     n = inp.size(); n     if (operation ==  min ) n       prepromin(); n     else if (operation ==  max ) n       prepromax(); n     else if (operation ==  sum ) n       preprosum(); n   } n  n  private: n   void prepromin() { n     sparse.resize(n); n     int x = lg2(n) + 1; n     for (int i = 0; i < n; i++) sparse[i].resize(x); n     for (int i = 0; i < n; i++) sparse[i][0] = i; n     for (int j = 1; j < x; j++) n       for (int i = 0; i + (1 << (j)) - 1 < n; i++) n         sparse[i][j] = n             (input[sparse[i][j - 1]] < input[sparse[i + (1 << (j - 1))][j - 1]] n                  ? sparse[i][j - 1] n                  : sparse[i + (1 << (j - 1))][j - 1]); n   } n   void prepromax() { n     sparse.resize(n); n     int x = lg2(n) + 1; n     for (int i = 0; i < n; i++) sparse[i].resize(x); n     for (int i = 0; i < n; i++) sparse[i][0] = i; n     for (int j = 1; j < x; j++) n       for (int i = 0; i + (1 << (j)) - 1 < n; i++) n         sparse[i][j] = n             (input[sparse[i][j - 1]] > input[sparse[i + (1 << (j - 1))][j - 1]] n                  ? sparse[i][j - 1] n                  : sparse[i + (1 << (j - 1))][j - 1]); n   } n   void preprosum() { n     sparse.resize(n); n     int x = lg2(n) + 1; n     for (int i = 0; i < n; i++) sparse[i].resize(x); n     for (int i = 0; i < n; i++) sparse[i][0] = input[i]; n     for (int j = 1; j < x; j++) n       for (int i = 0; i + (1 << (j)) - 1 < n; i++) n         sparse[i][j] = sparse[i][j - 1] + sparse[i + (1 << (j - 1))][j - 1]; n   } n }; n class Vector { n  public: n   pair<long long, long long> x; n  n  public: n   Vector(pair<long long, long long> a, pair<long long, long long> b) { n     x.first = b.first - a.first; n     x.second = b.second - a.second; n   } n  n  public: n   long double getMagnitude() { n     return sqrtl(x.first * x.first + x.second * x.second); n   } n }; n class Line { n  public: n   pair<long long, long long> x, y; n  n  public: n   Line(pair<long long, long long> a, pair<long long, long long> b) { n     x = a; n     y = b; n   } n  n  private: n   long double dotProduct(Vector a, Vector b) { n     return a.x.first * b.x.first + a.x.second * b.x.second; n   } n  n  private: n   long double crossProduct(Vector a, Vector b) { n     return a.x.first * b.x.second - a.x.second * b.x.first; n   } n  n  private: n   long double magnitude(Vector a) { return a.getMagnitude(); } n  n  public: n   long double distanceToA(pair<long long, long long> c) { n     return dotProduct(Vector(x, y), Vector(x, c)) / magnitude(Vector(x, y)); n   } n  n  public: n   long double orthogonalDistance(pair<long long, long long> c) { n     return crossProduct(Vector(x, y), Vector(x, c)) / magnitude(Vector(x, y)); n   } n  n  public: n   pair<long double, long double> intersection(Line l) { n     pair<long double, long double> ans; n     ans.first = (long double)((x.first * y.second - x.second * y.first) * n                                   (l.x.first - l.y.first) - n                               (x.first - y.first) * (l.x.first * l.y.second - n                                                      l.x.second * l.y.first)) / n                 ((x.first - y.first) * (l.x.second - l.y.second) - n                  (x.second - y.second) * (l.x.first - l.y.first)); n     ans.second = n         (long double)((x.first * y.second - x.second * y.first) * n                           (l.x.second - l.y.second) - n                       (x.second - y.second) * n                           (l.x.first * l.y.second - l.x.second * l.y.first)) / n         ((x.first - y.first) * (l.x.second - l.y.second) - n          (x.second - y.second) * (l.x.first - l.y.first)); n     return ans; n   } n }; n class PruferCode { n   vector<int> code; n   vector<pair<int, int> > edges; n  n  public: n   PruferCode(vector<int> cc) { n     code = cc; n     findEdges(); n   } n  n  private: n   void findEdges() { n     map<int, int> mp; n     set<int> has; n     set<int> wait; n     for (int z : code) { n       mp[z]++; n       has.insert(z); n     } n     for (int i = 0; i < code.size() + 2; i++) n       if (!has.count(i)) wait.insert(i); n     for (int i = 0; i < code.size(); i++) { n       int now = *wait.begin(); n       edges.push_back(make_pair(now, code[i])); n       mp[now]++; n       mp[code[i]]--; n       if (mp[code[i]] == 0) { n         has.erase(code[i]); n         wait.insert(code[i]); n       } n       wait.erase(now); n     } n     assert(wait.size() == 2); n     edges.push_back(make_pair(*wait.begin(), *wait.rbegin())); n   } n  n  public: n   vector<pair<int, int> > getEdges() { return edges; } n }; n class Segment { n   pair<long long, long long> x, y; n  n  public: n   Segment(pair<long long, long long> a, pair<long long, long long> b) { n     x = a; n     y = b; n   } n  n  private: n   long double dotProduct(Vector a, Vector b) { n     return a.x.first * b.x.first + a.x.second * b.x.second; n   } n  n  private: n   long double crossProduct(Vector a, Vector b) { n     return a.x.first * b.x.second - a.x.second * b.x.first; n   } n  n  private: n   long double magnitude(Vector a) { return a.getMagnitude(); } n  n  public: n   long double distanceToA(pair<long long, long long> c) { n     return dotProduct(Vector(x, y), Vector(x, c)) / magnitude(Vector(x, y)); n   } n  n  public: n   long double distanceToSegment(pair<long long, long long> c) { n     if (distanceToA(c) >= 0 && distanceToA(c) <= magnitude(Vector(x, y))) n       return crossProduct(Vector(x, y), Vector(x, c)) / magnitude(Vector(x, y)); n     else n       return min(magnitude(Vector(x, c)), magnitude(Vector(y, c))); n   } n }; n class HopcroftKarp { n   vector<int> matched; n   vector<vector<pair<int, int> > > adj; n   int left; n   int right; n  n  public: n   HopcroftKarp(vector<vector<pair<int, int> > > inp, int l, int r) { n     adj = inp; n     left = l; n     matched.resize(l); n     for (int i = 0; i < l; i++) matched[i] = -1; n     right = r; n   } n  n  public: n   vector<int> match() { n     bool cont = true; n     set<int> lfree, rfree; n     for (int i = 0; i < left; i++) lfree.insert(i); n     for (int i = left; i < left + right; i++) rfree.insert(i); n     vector<bool> yet(left, 0); n     for (int i = 0; i < left; i++) n       for (int j = 0; j < adj[i].size(); j++) n         if (adj[i][j].second == 1 && rfree.count(adj[i][j].first) && !yet[i]) { n           yet[i] = true; n           matched[i] = adj[i][j].first; n           adj[i][j].second = 2; n           for (int x = 0; x < adj[adj[i][j].first].size(); x++) n             if (adj[adj[i][j].first][x].first == i) n               adj[adj[i][j].first][x].second = 2; n           rfree.erase(adj[i][j].first); n           lfree.erase(i); n         } n     while (cont) { n       vector<int> par(left + right, -1); n       queue<pair<int, int> > kyou; n       for (int z : lfree) kyou.push(make_pair(z, 0)); n       int update = -1; n       vector<int> vis(left + right, 0); n       while (kyou.size()) { n         pair<int, int> frt = kyou.front(); n         kyou.pop(); n         if (rfree.count(frt.first)) { n           update = frt.first; n           break; n         } n         if (frt.second == 0) { n           for (pair<int, int> z : adj[frt.first]) { n             if (z.second == 1 && !vis[z.first]) { n               par[z.first] = frt.first; n               vis[z.first] = 1; n               kyou.push(make_pair(z.first, 1)); n             } n           } n         } else { n           for (pair<int, int> z : adj[frt.first]) { n             if (z.second == 2 && !vis[z.first]) { n               par[z.first] = frt.first; n               vis[z.first] = 1; n               kyou.push(make_pair(z.first, 0)); n             } n           } n         } n       } n       int x = update; n       int cnt = 0; n       while (x != -1 && par[x] != -1) { n         for (int i = 0; i < adj[x].size(); i++) n           if (adj[x][i].first == par[x]) { n             adj[x][i].second = (cnt == 0 ? 2 : 1); n             if (cnt == 0) { n               matched[par[x]] = x; n               rfree.erase(x); n               lfree.erase(par[x]); n             } n           } n         for (int i = 0; i < adj[par[x]].size(); i++) n           if (adj[par[x]][i].first == x) n             adj[par[x]][i].second = (cnt == 0 ? 2 : 1); n         cnt++; n         cnt %= 2; n         x = par[x]; n       } n       if (update == -1) cont = false; n     } n     return matched; n   } n }; n class Triangle { n   pair<long long, long long> x, y, z; n  n  public: n   Triangle(pair<long long, long long> a, pair<long long, long long> b, n            pair<long long, long long> c) { n     x = a; n     y = b; n     z = c; n   } n  n  private: n   long double crossProduct(Vector a, Vector b) { n     return a.x.first * b.x.second - a.x.second * b.x.first; n   } n  n  public: n   long double perimeter() { n     long double s1, s2, s3; n     s1 = Vector(x, y).getMagnitude(); n     s2 = Vector(y, z).getMagnitude(); n     s3 = Vector(x, z).getMagnitude(); n     return s1 + s2 + s3; n   } n  n  public: n   long double area() { return abs(crossProduct(Vector(x, y), Vector(x, z))); } n }; n class SuffixArray { n   vector<int> order; n   vector<int> lcp; n   string str; n  n  public: n   SuffixArray(string in) { n     str = in; n     str +=  $ ; n     order.resize(str.length()); n     lcp.resize(str.length()); n     compute(); n   } n   void compute() { n     vector<pair<char, int> > a; n     vector<int> equi(order.size()); n     vector<int> bij(order.size()); n     for (int i = 0; i < str.length(); i++) a.push_back(make_pair(str[i], i)); n     sort(a.begin(), a.end()); n     for (int i = 0; i < str.length(); i++) order[i] = a[i].second; n     equi[order[0]] = 0; n     int r = 0; n     for (int i = 1; i < str.length(); i++) { n       if (a[i].first == a[i - 1].first) n         equi[order[i]] = r; n       else n         equi[order[i]] = ++r; n     } n     int k = 0; n     while ((1 << k) < str.length()) { n       vector<pair<pair<int, int>, int> > a(str.length()); n       for (int i = 0; i < str.length(); i++) n         a[i] = make_pair( n             make_pair(equi[i], equi[(i + (1 << k)) % (str.length())]), i); n       sort(a.begin(), a.end()); n       for (int i = 0; i < str.length(); i++) { n         order[i] = a[i].second; n         bij[order[i]] = i; n       } n       int r = 0; n       equi[order[0]] = 0; n       for (int i = 1; i < str.length(); i++) { n         if (a[i].first == a[i - 1].first) n           equi[order[i]] = r; n         else n           equi[order[i]] = ++r; n       } n       k++; n     } n     k = 0; n     for (int i = 0; i < str.length() - 1; i++) { n       int p = bij[i]; n       int j = order[p - 1]; n       while (i + k < str.length() && j + k < str.length() && n              str[i + k] == str[j + k]) n         k++; n       lcp[p] = k; n       k = max(k - 1, 0); n     } n   } n  n  public: n   int count(string ptr) { n     int low = 0; n     int hi = str.length() - 1; n     int res1, res2; n     res1 = 0; n     res2 = 1e9; n     while (low <= hi) { n       int mid = (low + hi) / 2; n       bool gr = false; n       int i = 0; n       for (i; i < min(ptr.length(), str.length() - order[mid]); i++) { n         if (ptr[i] != str[order[mid] + i]) { n           if (ptr[i] > str[order[mid] + i]) gr = true; n           break; n         } n       } n       if (i == ptr.length()) { n         res2 = min(res2, mid); n         hi = mid - 1; n       } else if (!gr) n         hi = mid - 1; n       else n         low = mid + 1; n     } n     low = 0; n     hi = str.length() - 1; n     while (low <= hi) { n       int mid = (low + hi) / 2; n       bool gr = false; n       int i = 0; n       for (i; i < min(ptr.length(), str.length() - order[mid] + 1); i++) { n         if (ptr[i] != str[order[mid] + i]) { n           if (ptr[i] > str[order[mid] + i]) gr = true; n           break; n         } n       } n       if (i == ptr.length()) { n         res1 = max(res1, mid); n         low = mid + 1; n       } else if (!gr) n         hi = mid - 1; n       else n         low = mid + 1; n     } n     if (res2 == 1e9) return 0; n     return (res1 - res2 + 1); n   } n  n  public: n   vector<int> get() { return order; } n  n  public: n   vector<int> getLcp() { return lcp; } n  n  public: n   long long diffSubstrings() { n     long long out = 0; n     for (int i = 1; i < str.length(); i++) n       out += str.length() - order[i] - lcp[i] - 1; n     return out; n   } n }; n string longestCommonSubstring(string a, string b) { n   int len = 0; n   string res = a +  %  + b; n   SuffixArray sf = SuffixArray(res); n   vector<int> order = sf.get(); n   vector<int> lcp = sf.getLcp(); n   vector<int> col(order.size()); n   for (int i = 0; i < order.size(); i++) { n     if (order[i] < a.length()) n       col[order[i]] = 1; n     else if (order[i] > a.length()) n       col[order[i]] = 2; n   } n   int pos = -1; n   for (int i = 1; i < order.size(); i++) n     if (col[order[i]] + col[order[i - 1]] == 3) { n       if (lcp[i] > len) { n         len = max(len, lcp[i]); n         pos = (col[order[i]] == 1 ? order[i] : order[i - 1]); n       } n     } n   return a.substr(pos, len); n } n void solve() { n   int n, k; n   cin >> n >> k; n   vector<int> all(n); n   vector<int> bij(n + 1); n   set<int> st; n   for (int i = 0; i < n; i++) { n     cin >> all[i]; n     bij[all[i]] = i; n     st.insert(i); n   } n   set<int> b; n   vector<int> bb(k); n   for (int i = 0; i < k; i++) { n     int x; n     cin >> x; n     bb[i] = x; n     b.insert(x); n   } n   long long ans = 1; n   for (int i = 0; i < k; i++) { n     int pos = bij[bb[i]]; n     auto t = st.find(pos); n     auto m = t; n     m++; n     if (t == st.begin()) { n       auto r = t; n       r++; n       if (b.count(all[*r])) { n         cout << 0 <<   n ; n         return; n       } else { n         st.erase(*r); n       } n     } else if (m == st.end()) { n       auto r = t; n       r--; n       if (b.count(all[*r])) { n         cout << 0 <<   n ; n         return; n       } else n         st.erase(*r); n     } else { n       auto r = t; n       auto q = t; n       r++; n       q--; n       if (!b.count(all[*r]) && !b.count(all[*q])) { n         ans *= 2; n         ans %= mod; n         st.erase(*r); n       } else if (!b.count(all[*r])) n         st.erase(*r); n       else if (!b.count(all[*q])) n         st.erase(*q); n       else { n         cout << 0 <<   n ; n         return; n       } n     } n     b.erase(bb[i]); n   } n   cout << ans <<   n ; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   int t; n   cin >> t; n   while (t--) solve(); n } n


#include <bits/stdc++.h> n using namespace std; n long long cap[200005]; n int n, m; n inline long long tri(int n) { return n * (n + 1LL) / 2; } n inline long long arithsum(int a, int d, int n) { n   long long ret = a * (long long)n; n   ret += tri(n - 1) * d; n   return ret; n } n int main() { n   scanf( %d%d , &n, &m); n   for (int i = 0; i < n; i++) { n     scanf( %lld , &cap[i]); n   } n   long long ret = 0; n   for (int rep = 1; (rep)*n <= m; rep++) { n     long long total = 0; n     bool bad = false; n     long long currVal = min(arithsum(m, -n, rep), cap[n - 1]); n     for (int i = 0; i < n; i++) { n       currVal = min(currVal, cap[i] + m - rep * (i + 1)); n     } n     for (int i = n - 1; !bad && i >= 0; i--) { n       total += currVal; n       if (i > 0) { n         long long drop = currVal - cap[i - 1]; n         if (drop > m - rep) bad = true; n         currVal = min(currVal - rep, cap[i - 1]); n       } n     } n     long long lowFirst = arithsum(1, n, rep); n     if (!bad && currVal >= lowFirst) { n       ret = max(ret, total); n     } n   } n   printf( %lld n , ret); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t, s, x; n   cin >> t >> s >> x; n   int tmp = x - t; n   if ((tmp % s == 0 || tmp % s == 1) && tmp >= 0 && tmp != 1) n     cout <<  YES ; n   else n     cout <<  NO ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int mod = 1e9 + 7; n struct edge { n   int v, next; n }; n int ans, ans2, f[1005][1 << 12]; n int Pow(int a, int b) { n   int rec = 1; n   for (; b; b >>= 1, a = 1ll * a * a % mod) n     if (b & 1) rec = 1ll * rec * a % mod; n   return rec; n } n struct nade { n   int head[1005], edgenum, d[1005][1005], num[1005], sta[1005], n; n   edge e[1005 << 1]; n   void add(int u, int v) { n     e[++edgenum] = edge{v, head[u]}; n     head[u] = edgenum; n   } n   void dfs(int u, int fa) { n     num[u] = sta[u] = 0; n     for (int i = head[u], v; i; i = e[i].next) n       if ((v = e[i].v) ^ fa) { n         dfs(d[u][num[u]++] = v, u); n         sta[u] |= 1 << v - 1; n       } n   } n } s, t; n int dfs(int u, int i, int sta) { n   if (!i) return !sta; n   int &rec = f[s.d[u][i - 1]][sta]; n   if (rec != -1) return rec; n   rec = dfs(u, i - 1, sta); n   for (int v = s.d[u][i - 1], k = 0; k < t.n; k++) n     if (sta >> k & 1) n       rec = (rec + 1ll * dfs(u, i - 1, sta ^ (1 << k)) * n                        dfs(v, s.num[v], t.sta[k + 1])) % n             mod; n   return rec; n } n int main() { n   scanf( %d , &s.n); n   for (int i = 1, u, v; i < s.n; i++) { n     scanf( %d%d , &u, &v); n     s.add(u, v); n     s.add(v, u); n   } n   scanf( %d , &t.n); n   for (int i = 1, u, v; i < t.n; i++) { n     scanf( %d%d , &u, &v); n     t.add(u, v); n     t.add(v, u); n   } n   s.dfs(1, 0); n   memset(f, -1, sizeof f); n   for (int r = 1; r <= t.n; r++) { n     t.dfs(r, 0); n     for (int i = 1; i <= s.n; i++) n       ans = (ans + dfs(i, s.num[i], t.sta[r])) % mod; n     memset(f, -1, sizeof f); n   } n   s = t; n   s.dfs(1, 0); n   for (int r = 1; r <= t.n; r++) { n     t.dfs(r, 0); n     ans2 = (ans2 + dfs(1, s.num[1], t.sta[r])) % mod; n     memset(f, -1, sizeof f); n   } n   ans = 1ll * ans * Pow(ans2, mod - 2) % mod; n   printf( %d , ans); n } n


#include <bits/stdc++.h> n using namespace std; n using LL = long long; n using pii = pair<int, int>; n const int mod = 998244353; n const int inf = 0x3f3f3f3f; n const int N = 2e5 + 10; n int n, m, a[N]; n LL sum[N], fac[N], rev[N]; n LL pow_mod(LL x, int p) { n   LL s = 1; n   while (p) { n     if (p & 1) s = s * x % mod; n     x = x * x % mod; n     p >>= 1; n   } n   return s; n } n LL C(int n, int m) { return fac[n] * rev[m] % mod * rev[n - m] % mod; } n LL solve(int A, int d) { n   int p = lower_bound(a, a + n, d) - a; n   int q = n - p; n   if (q < A) return 0; n   LL ret1, ret2; n   if (q > A) { n     ret1 = C(n, q) * C(q - 1, A) % mod * (q - A) % mod * n            ((sum[n] - sum[p] + mod) % mod) % mod * fac[p] % mod * fac[A] % mod * n            fac[q - 1 - A] % mod; n   } else { n     ret1 = 0; n   } n   if (p) { n     ret2 = C(n, q + 1) * C(q, A) % mod * (q + 1 - A) % mod * sum[p] % mod * n            fac[p - 1] % mod * fac[A] % mod * fac[q - A] % mod; n   } else { n     ret2 = 0; n   } n   LL ret = (ret1 + ret2) % mod; n   return ret * rev[n] % mod; n } n int main() { n   int x, y; n   scanf( %d %d , &n, &m); n   for (int i = (0); i < (n); ++i) scanf( %d , a + i); n   sort(a, a + n); n   fac[0] = 1; n   for (int i = (1); i < (n + 1); ++i) { n     fac[i] = fac[i - 1] * i % mod; n   } n   rev[n] = pow_mod(fac[n], mod - 2); n   for (int i = (n); i > (0); --i) rev[i - 1] = rev[i] * i % mod; n   sum[0] = 0; n   for (int i = (0); i < (n); ++i) { n     sum[i + 1] = (sum[i] + a[i]) % mod; n   } n   while (m--) { n     scanf( %d %d , &x, &y); n     printf( %lld n , solve(x, y)); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int input; n   vector<int> ret; n   cin >> input; n   for (int i = 1; i < input; i += 2) { n     ret.push_back(i + 1); n     ret.push_back(i); n   } n   if (ret.empty() || ret.size() != input) ret = {-1}; n   for (auto &d : ret) { n     cout << d <<    ; n   } n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n double ans[1024 * 1024], l, r, x[20], y[20], a[20], cosA[20], sinA[20], maxi; n int main() { n   scanf( %d %lf %lf , &n, &l, &r); n   maxi = l; n   for (int i = 0; i < n; i++) { n     scanf( %lf %lf %lf , &x[i], &y[i], &a[i]); n     cosA[i] = cos(a[i] * 3.14159265359 / 180); n     sinA[i] = sin(a[i] * 3.14159265359 / 180); n   } n   int maxiMask = 1 << n; n   for (int i = 0; i < maxiMask; i++) ans[i] = l; n   for (int i = 0; i < maxiMask; i++) { n     double curAns = ans[i]; n     for (int j = 0; j < n; j++) { n       int newPotPos = 1 << j; n       if (!(newPotPos & i)) { n         double vx = curAns - x[j]; n         double vy = -y[j]; n         double nvx = vx * cosA[j] - vy * sinA[j]; n         double nvy = vx * sinA[j] + vy * cosA[j]; n         double pAns = x[j] - y[j] * nvx / nvy; n         int newPos = newPotPos ^ i; n         if (nvy >= 0.0) { n           ans[newPos] = r; n           maxi = r; n         } else { n           ans[newPos] = max(ans[newPos], pAns); n           maxi = max(maxi, ans[newPos]); n         } n       } n     } n   } n   maxi = min(maxi, r); n   printf( %.11lf , maxi - l); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int n, count = 0, count1 = 0, ans = 0, i, ma; n   cin >> n; n   long long int a[n]; n   for (i = 0; i < n; i++) { n     cin >> a[i]; n   } n   ma = a[0]; n   for (i = 0; i < n; i++) { n     if (a[i] > ma) { n       ma = a[i]; n     } n   } n   for (i = 0; i < n; i++) { n     count = ma - a[i]; n     ans = ans + count; n   } n   cout << ans <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n bool ok(int a, int b) { n   int c = 0; n   for (int i = 0; i < 4; i++) { n     if ((a % 10) != (b % 10)) c++; n     if (c > 1) return false; n     a /= 10; n     b /= 10; n   } n   return true; n } n int getlow(int a, int m) { n   for (int i = m; i <= 2011; i++) n     if (ok(a, i)) return i; n   return -1; n } n int main() { n   int n; n   scanf( %d , &n); n   int p = 1000; n   vector<int> v; n   for (int i = 0; i < n; i++) { n     int t; n     scanf( %d , &t); n     t = getlow(t, p); n     p = t; n     if (t == -1) { n       printf( No solution n ); n       return 0; n     } n     v.push_back(t); n   } n   for (int i = 0; i < n; i++) printf( %d n , v[i]); n } n


#include <bits/stdc++.h> n using namespace std; n inline void read(register int *n) { n   register char c; n   *n = 0; n   do { n     c = getchar(); n   } while (c <  0  || c >  9 ); n   do { n     *n = c -  0  + *n * 10; n     c = getchar(); n   } while (c >=  0  && c <=  9 ); n } n long long C[2048][2048], fac[1000001], dfac[1000001], D[2048][2048]; n long long pmod(long long x, long long y) { n   if (y == 0) return 1; n   if (y % 2) return pmod(x, y - 1) * x % 1000000007; n   long long r = pmod(x, y / 2); n   return r * r % 1000000007; n } n long long calc(long long n, long long k, long long c = 0) { n   long long res = 0; n   for (register int i = (0); i < (int)(k + 1); ++i) { n     long long tmp = C[k][i] * pmod(i + c, n); n     tmp %= 1000000007; n     if (i % 2) n       res -= tmp; n     else n       res += tmp; n     res %= 1000000007; n   } n   return res; n } n inline long long binom(long long n, long long r) { n   if (r < 0 || r > n) return 0; n   long long res = 1; n   res = res * fac[n] % 1000000007; n   res = res * dfac[r] % 1000000007; n   res = res * dfac[n - r] % 1000000007; n   return res; n } n int main() { n   for (register int i = (0); i < (int)(1000001); ++i) n     fac[i] = (i ? fac[i - 1] * i : 1) % 1000000007, n     dfac[i] = pmod(fac[i], 1000000007 - 2); n   for (register int i = (0); i < (int)(2048); ++i) n     for (register int j = (0); j < (int)(i + 1); ++j) n       C[i][j] = (j == 0 || j == i) ? 1 : (C[i - 1][j - 1] + C[i - 1][j]); n   for (register int i = (0); i < (int)(2048); ++i) n     for (register int j = (0); j < (int)(2048); ++j) n       if (i == 0) n         D[i][j] = j == 0; n       else if (j <= 1) n         D[i][j] = j; n       else n         D[i][j] = (j * D[i - 1][j] + D[i - 1][j - 1]) % 1000000007; n   int n, m, k; n   cin >> n >> m >> k; n   if (m == 1) { n     cout << pmod(k, n) << endl; n     return 0; n   } n   long long res = 0; n   for (register int x = (1); x < (int)(min(k, n) + 1); ++x) n     for (int y = 0; y <= x; y++) n       if (x * 2 - y <= k) { n         long long tmp = binom(k, x * 2 - y); n         tmp = tmp * binom(x * 2 - y, x - y) % 1000000007; n         tmp = tmp * binom(x, x - y) % 1000000007; n         tmp = tmp * D[n][x] % 1000000007; n         tmp = tmp * D[n][x] % 1000000007; n         tmp = tmp * fac[x] % 1000000007; n         tmp = tmp * fac[x] % 1000000007; n         tmp = tmp * pmod(y, n * (m - 2)); n         res = (res + tmp) % 1000000007; n       } n   cout << res << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   long long int n, x, ans = 0, i; n   cin >> n; n   for (i = 0; i < n; i++) { n     cin >> x; n     ans += (i + 1) * x; n   } n   ans -= (((n - 1) * (n)) / 2); n   cout << ans <<   n ; n } n


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


#include <bits/stdc++.h> n using namespace std; n const int MAX_L = 3000; n int T[MAX_L][MAX_L]; n int last[MAX_L], z[MAX_L]; n ; n char s[MAX_L], p[MAX_L]; n int main() { n   int Ls, Lp, is, ip, k, i, j, r; n   scanf( %s%s , &s, &p); n   Ls = strlen(s); n   Lp = strlen(p); n   for (i = 0; s[i]; i++) { n     is = i; n     ip = 0; n     while (s[is] && p[ip]) { n       while (s[is] && p[ip] && s[is] != p[ip]) is++; n       if (s[is] == p[ip]) { n         is++; n         ip++; n       } n     } n     if (!p[ip]) { n       last[i] = is - 1; n       z[i] = is - i - Lp; n     } else n       last[i] = -1; n   } n   if (last[0] != -1) T[last[0]][z[0]] = 1; n   for (i = 0; i < Ls - 1; i++) n     for (k = 0; k <= i + 1; k++) { n       j = i + 1; n       T[j][k] = max(T[j][k], T[i][k]); n       T[j][k + 1] = max(T[j][k + 1], T[i][k]); n       if (last[j] != -1) { n         r = last[j]; n         T[r][k + z[j]] = max(T[r][k + z[j]], T[i][k] + 1); n       } n     } n   i = Ls - 1; n   for (j = 0; j <= Ls; j++) printf( %d  , T[i][j]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int v0, v1, v2, vm, a0, a1, a2; n   bool err = true; n   scanf( %d%d%d%d , &v2, &v1, &v0, &vm); n   for (int i = v0; i <= v0 * 2; i++) { n     for (int j = v1; j <= v1 * 2; j++) { n       for (int k = v2; k <= v2 * 2; k++) { n         if (vm <= i && vm <= j && vm <= k && i < j && j < k && vm * 2 >= i && n             vm * 2 < j) { n           a0 = k; n           a1 = j; n           a2 = i; n           err = false; n           break; n         } n       } n     } n   } n   if (err) { n     printf( -1 n ); n   } else { n     printf( %d n%d n%d n , a0, a1, a2); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 1e5 + 5; n int main() { n   int n; n   cin >> n; n   string s; n   cin >> s; n   queue<int> D, R; n   for (int i = 0; i < n; i++) { n     if (s[i] ==  D ) D.push(i); n     if (s[i] ==  R ) R.push(i); n   } n   while (D.size() && R.size()) { n     if (D.front() < R.front()) { n       R.pop(); n       D.push(D.front() + n); n       D.pop(); n     } else { n       D.pop(); n       R.push(R.front() + n); n       R.pop(); n     } n   } n   cout << (D.size() ?  D  :  R ) << endl; n   return 0; n } n


#include <bits/stdc++.h> n const double eps = 1e-19; n const double PI = acos(-1.0); n const int INF = 1000 * 1000 * 1000 + 7; n const int MAXN = 300005; n using namespace std; n int n, m; n int ans[MAXN]; n vector<int> g[MAXN]; n bool used[MAXN]; n void dfs(int v) { n   int kol = 0; n   for (int j = 0; j < (int)g[v].size(); j++) n     if (ans[v] == ans[g[v][j]]) kol++; n   if (kol > 1) { n     ans[v] ^= 1; n     for (int j = 0; j < (int)g[v].size(); j++) { n       dfs(g[v][j]); n     } n   } n } n int main() { n   scanf( %d %d , &n, &m); n   for (int i = 0; i < m; i++) { n     int ta, tb; n     scanf( %d %d , &ta, &tb); n     ta--; n     tb--; n     g[ta].push_back(tb); n     g[tb].push_back(ta); n   } n   memset(ans, 0, sizeof ans); n   for (int i = 0; i < n; i++) dfs(i); n   for (int i = 0; i < n; i++) printf( %d , ans[i]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n template <class T, class U> n ostream& operator<<(ostream& o, const pair<T, U>& p) { n   o <<  (  << p.first <<  ,  << p.second <<  ) ; n   return o; n } n template <class T> n ostream& operator<<(ostream& o, const vector<T>& v) { n   o <<  [ ; n   for (T t : v) { n     o << t <<  , ; n   } n   o <<  ] ; n   return o; n } n const int MAX_V = 300003; n const int MAX_LOG_V = 19; n vector<int> G[MAX_V]; n int root = 0; n int parent[MAX_LOG_V][MAX_V]; n int depth[MAX_V]; n void lca_dfs(int v, int p, int d) { n   parent[0][v] = p; n   depth[v] = d; n   for (int i = 0; i < (int)(G[v].size()); ++i) { n     if (G[v][i] != p) { n       lca_dfs(G[v][i], v, d + 1); n     } n   } n } n void lca_init(int V) { n   lca_dfs(root, -1, 0); n   for (int k = 0; k + 1 < MAX_LOG_V; ++k) { n     for (int v = 0; v < V; ++v) { n       if (parent[k][v] < 0) n         parent[k + 1][v] = -1; n       else n         parent[k + 1][v] = parent[k][parent[k][v]]; n     } n   } n } n int lca(int u, int v) { n   if (depth[u] > depth[v]) swap(u, v); n   for (int k = 0; k < MAX_LOG_V; ++k) { n     if ((depth[v] - depth[u]) >> k & 1) v = parent[k][v]; n   } n   if (u == v) return u; n   for (int k = MAX_LOG_V - 1; k >= 0; --k) { n     if (parent[k][u] != parent[k][v]) { n       u = parent[k][u]; n       v = parent[k][v]; n     } n   } n   return parent[0][u]; n } n const int N = MAX_V; n const ll mod = 998244353; n int n, k; n int a[N]; n int L[N]; n bool invalid = false; n ll dp[N][2] = {}; n int dfs(int x, int par) { n   map<int, int> m; n   for (int e : G[x]) n     if (e != par) { n       int res = dfs(e, x); n       if (res != 0) m[e] = res; n     } n   if (m.empty()) { n     int idx = (a[x] != 0); n     dp[x][idx] = 1; n     if (L[a[x]] == x) return -1; n     return a[x]; n   } n   unordered_set<int> s; n   vector<int> ch; n   for (const auto& p : m) { n     ch.push_back(p.first); n     if (p.second != -1) s.insert(p.second); n   } n   if (s.size() > 1) { n     invalid = true; n     return 0; n   } n   if (a[x] == 0 && s.size() == 0) { n     dp[x][0] = 1; n     for (int v : ch) (dp[x][0] *= (dp[v][0] + dp[v][1])) %= mod; n     int C = ch.size(); n     vector<ll> pre(C), suf(C); n     for (int i = 0; i < (int)(C); ++i) n       pre[i] = suf[i] = (dp[ch[i]][0] + dp[ch[i]][1]) % mod; n     for (int i = 0; i < (int)(C - 1); ++i) (pre[i + 1] *= pre[i]) %= mod; n     for (int i = C - 1; i > 0; --i) (suf[i - 1] *= suf[i]) %= mod; n     dp[x][1] = 0; n     for (int i = 0; i < (int)(C); ++i) { n       ll mul = 1; n       if (i != 0) (mul *= pre[i - 1]) %= mod; n       if (i != C - 1) (mul *= suf[i + 1]) %= mod; n       ll add = (mul * dp[ch[i]][1]) % mod; n       (dp[x][1] += add) %= mod; n     } n     return -1; n   } else { n     int col = a[x]; n     if (!s.empty()) { n       assert(s.size() == 1); n       int h = *s.begin(); n       if (col != 0 && col != h) { n         invalid = true; n         return 0; n       } n       col = h; n     } n     dp[x][1] = 1; n     for (int v : ch) { n       if (m[v] == -1) n         (dp[x][1] *= (dp[v][0] + dp[v][1])) %= mod; n       else n         (dp[x][1] *= dp[v][1]) %= mod; n     } n     return (x == L[col]) ? -1 : col; n   } n } n int main() { n   scanf(  %d %d , &n, &k); n   vector<vector<int>> col(k + 1); n   for (int i = 0; i < (int)(n); ++i) { n     scanf(  %d , &a[i]); n     col[a[i]].push_back(i); n   } n   for (int i = 0; i < (int)(n - 1); ++i) { n     int u, v; n     scanf(  %d %d , &u, &v); n     --u; n     --v; n     G[u].push_back(v); n     G[v].push_back(u); n   } n   lca_init(n); n   for (int i = 1; i <= k; ++i) { n     int x = col[i][0]; n     for (int j : col[i]) x = lca(x, j); n     if (a[x] != 0 && a[x] != i) invalid = true; n     a[x] = i; n     L[i] = x; n   } n   dfs(0, -1); n   printf( %lld n , invalid ? 0 : dp[0][1]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1510, INF = 1e9 + 9; n int n, s, m, k, last[N], a[N], dp[N][N]; n bool check(int x) { n   memset(dp, 0, sizeof dp); n   for (int i = 0; i < n; i++) { n     int val = 0; n     for (int j = last[i]; j <= i; j++) val += a[j] <= x; n     for (int j = 1; j <= m; j++) n       dp[i + 1][j] = max(dp[i][j], dp[last[i]][j - 1] + val); n   } n   return k <= dp[n][m]; n } n int main() { n   ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); n   cin >> n >> s >> m >> k; n   for (int i = 0; i < n; i++) cin >> a[i]; n   fill(last, last + n, n + 1); n   while (s--) { n     int l, r; n     cin >> l >> r; n     for (int i = --l; i < r; i++) last[i] = min(last[i], l); n   } n   int l = 0, r = INF; n   while (r - l > 1) { n     int mid = l + r >> 1; n     check(mid) ? r = mid : l = mid; n   } n   cout << (r == INF ? -1 : r) << endl; n } n


#include <bits/stdc++.h> n using namespace std; n struct Node { n   pair<int, int> A; n   int x, y; n   Node() {} n   Node(pair<int, int> A, int x, int y) { n     this->A = A; n     this->x = x; n     this->y = y; n   } n }; n char s[1001][1001]; n int sp[10], cur, ans[10]; n Node heap[1000001]; n void swap(Node& a, Node& b) { n   Node t = a; n   a = b; n   b = t; n } n bool cmp(Node a, Node b) { n   int val_a = a.A.first / sp[a.A.second]; n   int val_b = b.A.first / sp[b.A.second]; n   if (val_a != val_b) n     return val_a < val_b; n   else if (a.A.second != b.A.second) n     return a.A.second < b.A.second; n   else n     return a.A.first < b.A.first; n } n void push(Node x) { n   int now = cur++; n   heap[now] = x; n   while (now > 1) { n     int par = now / 2; n     if (cmp(heap[now], heap[par])) n       swap(heap[now], heap[par]); n     else n       break; n     now = par; n   } n   return; n } n Node pop() { n   Node ret = heap[1]; n   heap[1] = heap[--cur]; n   int now = 1; n   while (now * 2 < cur) { n     int l = now * 2, r = now * 2 + 1, t; n     if (r == cur) r = l; n     if (cmp(heap[l], heap[r])) n       t = l; n     else n       t = r; n     if (cmp(heap[t], heap[now])) n       swap(heap[t], heap[now]); n     else n       break; n     now = t; n   } n   return ret; n } n int dx[4] = {1, 0, 0, -1}; n int dy[4] = {0, 1, -1, 0}; n int main() { n   int n, m, p; n   cur = 1; n   scanf( %d %d %d , &n, &m, &p); n   for (int i = 1; i <= p; i++) scanf( %d , &sp[i]); n   for (int i = 0; i < n; i++) scanf( %s , s[i]); n   for (int i = 0; i < n; i++) n     for (int j = 0; j < m; j++) { n       if (s[i][j] >=  0  && s[i][j] <=  9 ) { n         push(Node(pair<int, int>(0, s[i][j] -  0 ), i, j)); n       } n     } n   while (cur > 1) { n     Node now = pop(); n     pair<int, int> A = now.A; n     int x = now.x, y = now.y; n     int cnt = A.first, who = A.second; n     for (int i = 0; i < 4; i++) { n       int nx = x + dx[i], ny = y + dy[i]; n       if (nx < 0 || ny < 0 || nx >= n || ny >= m || s[nx][ny] !=  . ) continue; n       s[nx][ny] =  0  + who; n       push(Node(pair<int, int>(cnt + 1, who), nx, ny)); n     } n   } n   for (int i = 0; i < n; i++) n     for (int j = 0; j < m; j++) { n       if (s[i][j] >=  0  && s[i][j] <=  9 ) { n         ans[s[i][j] -  0 ]++; n       } n     } n   for (int i = 1; i <= p; i++) printf( %d  , ans[i]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int len(int n) { n   if (n < 10) return 0; n   return 1 + len(n / 10); n } n int main() { n   int n, l; n   long long sum = 0, z = 1; n   cin >> n; n   l = len(n); n   for (int x = 0; x < l; x++) z *= 10; n   while (n > 0) { n     sum += (n - z + 1) * (l + 1); n     n = z - 1; n     z /= 10; n     l--; n   } n   cout << sum << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 100005, mod = 1000000007; n int n, m, T, q, f[6]; n int main() { n   cin >> n; n   for (int i = 1; i <= n; i++) { n     int x; n     scanf( %d , &x); n     for (int j = 1; j <= 4; j++) { n       if ((j & 1) == (x & 1)) f[j]++; n     } n     for (int j = 2; j <= 4; j++) f[j] = max(f[j], f[j - 1]); n   } n   printf( %d n , f[4]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a[200005]; n long double b[200005]; n int n; n long double dp1[200005], dp2[200005]; n long double check(long double val) { n   int i; n   for (i = 0; i < n; i++) b[i + 1] = a[i] - val; n   dp1[1] = b[1]; n   long double ans = b[1]; n   for (i = 2; i <= n; i++) { n     dp1[i] = max(dp1[i - 1], (long double)0) + b[i]; n     ans = max(ans, dp1[i]); n   } n   for (i = 0; i <= n + 1; i++) b[i + 1] = -b[i + 1]; n   ans = max(ans, b[1]); n   dp2[1] = b[1]; n   for (i = 2; i <= n; i++) { n     dp2[i] = max(dp2[i - 1], (long double)0) + b[i]; n     ans = max(ans, dp2[i]); n   } n   return ans; n } n int main() { n   scanf( %d , &n); n   int i; n   for (i = 0; i < n; i++) scanf( %d , &a[i]); n   long double lo, hi; n   lo = -(1e4); n   hi = 1e4; n   long double eps = 1e-12; n   while (lo < hi - eps) { n     long double mid1, mid2; n     mid1 = (2 * lo + hi) / 3; n     mid2 = (lo + hi * 2) / 3; n     long double sol1, sol2; n     sol1 = check(mid1); n     sol2 = check(mid2); n     if (sol1 < sol2 - eps) { n       hi = mid2; n     } else { n       lo = mid1; n     } n   } n   cout << fixed << setprecision(9) << check(lo) << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int dx[8] = {-2, -2, -1, -1, 1, 1, 2, 2}; n const int dy[8] = {-1, 1, -2, 2, -2, 2, -1, 1}; n int n, m; n int xw, yw, xb, yb; n int xtw, ytw, xtb, ytb; n deque<pair<int, int>> ww, wb, bw, bb; n int dist[1000][1000], parx[1000][1000], pary[1000][1000]; n int crap; n void shortestWay(int sx, int sy, int tx, int ty, deque<pair<int, int>> &res) { n   for (int i = 0; i < n; ++i) n     for (int j = 0; j < m; ++j) dist[i][j] = -1; n   dist[sx][sy] = 0; n   queue<pair<int, int>> q; n   q.push({sx, sy}); n   while (!q.empty()) { n     int x = q.front().first, y = q.front().second; n     q.pop(); n     if (x == tx && y == ty) break; n     for (int i = 0; i < 8; ++i) { n       int xx = x + dx[i], yy = y + dy[i]; n       if (xx < 0 || yy < 0 || xx >= n || yy >= m) continue; n       if (dist[xx][yy] == -1) { n         dist[xx][yy] = dist[x][y] + 1; n         parx[xx][yy] = x, pary[xx][yy] = y; n         q.push({xx, yy}); n       } n     } n   } n   int cx = tx, cy = ty; n   while (cx != sx || cy != sy) { n     res.push_front({cx, cy}); n     int ccx = parx[cx][cy]; n     cy = pary[cx][cy]; n     cx = ccx; n   } n } n void normal(deque<pair<int, int>> &way, int ox, int oy) { n   for (int i = 0; i < way.size(); ++i) { n     cout << way[i].first + 1 <<     << way[i].second + 1 <<   n  << flush; n     if (way[i].first == ox && way[i].second == oy) exit(0); n     if (i < way.size() - 1) { n       cin >> ox >> oy; n       ox--; n       oy--; n     } n   } n } n void normalWhite() { n   cout <<  WHITE n  << flush; n   normal(ww, xb, yb); n } n void normalBlack() { n   cout <<  BLACK n  << flush; n   cin >> xw >> yw; n   xw--; n   yw--; n   normal(bb, xw, yw); n } n void advanced(deque<pair<int, int>> &way, int x, int y, int tx, int ty, int ox, n               int oy) { n   if (way.size() > 0) { n     normal(way, ox, oy); n     cin >> ox >> oy; n     ox--; n     oy--; n     x = way.back().first, y = way.back().second; n   } n   for (int i = 0; i < 8; ++i) { n     int xx = x + dx[i], yy = y + dy[i]; n     if (xx == ox && yy == oy) { n       cout << xx + 1 <<     << yy + 1 <<   n  << flush; n       exit(0); n     } n   } n   deque<pair<int, int>> d; n   if (tx > x) { n     d.push_back({x + 1, y + 2}); n     d.push_back({x + 3, y + 1}); n     d.push_back({x + 1, y}); n   } else { n     d.push_back({x - 1, y + 2}); n     d.push_back({x - 3, y + 1}); n     d.push_back({x - 1, y}); n   } n   normal(d, ox, oy); n } n void advancedWhite() { n   cout <<  WHITE n  << flush; n   advanced(wb, xw, yw, xtw, ytw, xb, yb); n } n void advancedBlack() { n   cout <<  BLACK n  << flush; n   cin >> xw >> yw; n   xw--; n   yw--; n   advanced(bw, xb, yb, xtb, ytb, xw, yw); n } n int main() { n   cin >> n >> m >> xw >> yw >> xb >> yb; n   xw--; n   yw--; n   xb--; n   yb--; n   xtw = n / 2 - 1; n   ytw = m / 2 - 1; n   xtb = n / 2; n   ytb = m / 2 - 1; n   shortestWay(xw, yw, xtw, ytw, ww); n   shortestWay(xw, yw, xtb, ytb, wb); n   shortestWay(xb, yb, xtw, ytw, bw); n   shortestWay(xb, yb, xtb, ytb, bb); n   if ((xw + yw) % 2 != (xb + yb) % 2) { n     if (ww.size() <= bb.size()) n       normalWhite(); n     else if (wb.size() >= bb.size() + 2) n       normalBlack(); n     else n       advancedWhite(); n   } else { n     if (bb.size() < ww.size()) n       normalBlack(); n     else if (bw.size() > ww.size()) n       normalWhite(); n     else n       advancedBlack(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n template <class T, class U> n void ckmin(T &a, U b) { n   if (a > b) a = b; n } n template <class T, class U> n void ckmax(T &a, U b) { n   if (a < b) a = b; n } n int N, M; n bitset<1013> grid[1013]; n int dn[1013][1013], rt[1013][1013]; n int upd[1013][1013]; n int x = -1, y = -1; n int ans = 998244353; n void check(int sx, int sy) { n   for (auto i = (0); i < (N + 1); i++) { n     for (auto j = (0); j < (M + 1); j++) { n       upd[i][j] = 0; n     } n   } n   int cx = x, cy = y; n   while (true) { n     upd[cx][cy]++; n     upd[cx + sx][cy]--; n     upd[cx][cy + sy]--; n     upd[cx + sx][cy + sy]++; n     if (grid[cx + sx][cy]) { n       cx++; n       continue; n     } n     if (grid[cx][cy + sy]) { n       cy++; n       continue; n     } n     break; n   } n   for (auto i = (0); i < (N); i++) { n     for (auto j = (0); j < (M); j++) { n       if (i) upd[i][j] += upd[i - 1][j]; n       if (j) upd[i][j] += upd[i][j - 1]; n       if (i && j) upd[i][j] -= upd[i - 1][j - 1]; n       if (upd[i][j] && !grid[i][j]) return; n       if (!upd[i][j] && grid[i][j]) return; n     } n   } n   ckmin(ans, sx * sy); n } n int32_t main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cin >> N >> M; n   for (auto i = (0); i < (N); i++) { n     string temps; n     cin >> temps; n     for (auto j = (0); j < (M); j++) { n       grid[i][j] = (temps[j] ==  X ); n     } n   } n   for (auto i = (N)-1; i >= (0); i--) { n     for (auto j = (M)-1; j >= (0); j--) { n       if (grid[i][j]) { n         x = i; n         y = j; n       } n     } n   } n   for (auto i = (0); i < (N); i++) { n     for (auto j = (0); j < (y); j++) { n       if (grid[i][j]) { n         cout <<  -1 n ; n         return 0; n       } n     } n   } n   for (auto i = (0); i < (N); i++) { n     for (auto j = (M)-1; j >= (0); j--) { n       rt[i][j] = (grid[i][j] ? 1 + rt[i][j + 1] : 0); n     } n   } n   for (auto i = (0); i < (M); i++) { n     for (auto j = (N)-1; j >= (0); j--) { n       dn[j][i] = (grid[j][i] ? 1 + dn[j + 1][i] : 0); n     } n   } n   int dy = rt[x][y], dx = dn[x][y]; n   for (auto i = (x); i < (x + dx); i++) { n     for (auto j = (y); j < (y + dy); j++) { n       if (!grid[i][j]) { n         cout <<  -1 n ; n         return 0; n       } n     } n   } n   check(dx, dy); n   check(dx, 1); n   check(1, dy); n   for (auto i = (0); i < (dy); i++) { n     if (grid[x + dx][y + i]) { n       check(dx, dy - i); n       break; n     } n   } n   for (auto i = (0); i < (dx); i++) { n     if (grid[x + i][y + dy]) { n       check(dx - i, dy); n       break; n     } n   } n   if (ans == 998244353) { n     cout <<  -1 n ; n     return 0; n   } n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 2e5 + 7; n const int sz = 10; n map<int, int> mp[11]; n int n, k; n unsigned long long a[maxn], ans; n unsigned long long fac[13]; n int main() { n   fac[0] = 1; n   for (int i = 1; i <= 10; i++) fac[i] = 10LL * fac[i - 1]; n   scanf( %d%d , &n, &k); n   for (int i = 1; i <= n; i++) { n     scanf( %llu , &a[i]); n     for (int j = 1; j <= 10; j++) { n       int now = (a[i] * fac[j]) % k; n       mp[j][now]++; n     } n   } n   for (int i = 1; i <= n; i++) { n     int len = 0; n     unsigned long long now = a[i]; n     while (now) { n       now /= 10; n       len++; n     } n     int res = a[i] % k; n     int p = 0; n     if (res == 0) { n       int need = 0; n       if ((a[i] * fac[len]) % k == need) { n         ans += mp[len][need] - 1; n       } else { n         ans += mp[len][need]; n       } n     } else { n       int need = k - res; n       if ((a[i] * fac[len]) % k == need) { n         ans += mp[len][need] - 1; n       } else { n         ans += mp[len][need]; n       } n     } n   } n   printf( %lld n , ans); n } n


#include <bits/stdc++.h> n using namespace std; n const int mx = 1123; n int limit[26]; n const long long mod = 1e9 + 7; n int n; n string s; n struct Node { n   int maxstr, minpart; n   long long ways; n   Node(int maxstr, int minpart, long long ways) n       : maxstr(maxstr), minpart(minpart), ways(ways){}; n   Node() { n     ways = -1; n     minpart = 1e9; n   } n }; n Node dp[mx]; n Node ways(int on = 0) { n   if (on == n) { n     return {0, 0, 1}; n   } n   Node &ans = dp[on]; n   if (ans.ways == -1) { n     ans.ways = 0; n     int maxsz = 1e9; n     for (int i = on; i < n; i++) { n       maxsz = min(maxsz, limit[s[i] -  a ]); n       if (i - on + 1 <= maxsz) { n         auto r = ways(i + 1); n         ans.ways += r.ways; n         ans.minpart = (i != n - 1) + min(ans.minpart, r.minpart); n         ans.maxstr = max(ans.maxstr, max(i - on + 1, r.maxstr)); n       } n     } n   } n   ans.ways = (ans.ways) % mod; n   return ans; n } n int main() { n   cin >> n; n   cin >> s; n   for (int i = 0; i < 26; i++) { n     cin >> limit[i]; n   } n   auto ans = ways(); n   cout << ans.ways << endl; n   cout << ans.maxstr << endl; n   cout << ans.minpart + 1 << endl; n } n


#include <bits/stdc++.h> n using namespace std; n bool is_prime(int n) { n   if (n <= 1) return false; n   for (int i = 2; i * i <= n; i++) { n     if (n % i == 0) { n       return false; n     } n   } n   return true; n } n vector<int> gen_primes(int l, int r) { n   vector<int> primes; n   for (int i = l; i <= r; i++) { n     if (is_prime(i)) { n       primes.push_back(i); n     } n   } n   return primes; n } n vector<long long> gen_batch(const vector<int>& primes) { n   constexpr long long limit = (long long)1e18; n   vector<long long> batch; n   long long cur = 1; n   for (int i = 0; i < primes.size(); i++) { n     if (cur <= limit / primes[i]) { n       cur *= primes[i]; n     } else { n       batch.push_back(cur); n       cur = primes[i]; n     } n   } n   if (cur > 1) { n     batch.push_back(cur); n   } n   return batch; n } n vector<long long> get_gcds(const vector<long long>& batch) { n   vector<long long> gcds; n   for (long long x : batch) { n     cout <<  ?   << x << endl; n     long long g; n     cin >> g; n     gcds.push_back(g); n   } n   return gcds; n } n vector<int> get_candidates(const vector<int>& primes, n                            const vector<long long>& gcds) { n   vector<int> candidates; n   for (long long g : gcds) { n     for (int p : primes) { n       if (g % p == 0) { n         candidates.push_back(p); n       } n     } n   } n   return candidates; n } n long long build_one(int c) { n   constexpr long long limit = (long long)1e9; n   long long cur = 1; n   while (cur <= limit / c) cur *= c; n   return cur; n } n long long build_two(int c1, int c2) { n   long long res1 = build_one(c1); n   long long res2 = build_one(c2); n   return res1 * res2; n } n void solve() { n   auto primes = gen_primes(1, 177); n   auto batch = gen_batch(primes); n   auto gcds = get_gcds(batch); n   auto candidates = get_candidates(primes, gcds); n   if (candidates.size() == 0) { n     cout <<  ! 1  << endl; n     return; n   } n   vector<pair<int, long long>> divs; n   if (candidates.size() == 1) { n     long long output = build_one(candidates[0]); n     cout <<  ?   << output << endl; n     long long g; n     cin >> g; n     if (candidates[0] == g) { n       cout <<  ! 8  << endl; n       return; n     } n     divs.push_back(make_pair(candidates[0], g)); n   } else { n     for (int i = 0; i + 1 < candidates.size(); i += 2) { n       long long output = build_two(candidates[i], candidates[i + 1]); n       cout <<  ?   << output << endl; n       long long g; n       cin >> g; n       divs.push_back(make_pair(candidates[i], g)); n       divs.push_back(make_pair(candidates[i + 1], g)); n     } n     if (candidates.size() % 2 == 1) { n       long long output = build_one(candidates.back()); n       cout <<  ?   << output << endl; n       long long g; n       cin >> g; n       divs.push_back(make_pair(candidates.back(), g)); n     } n   } n   long long lim = (long long)1e9, res = 1; n   for (const pair<int, long long>& d : divs) { n     int a = d.first; n     long long b = d.second; n     long long c = 1; n     int tmp = 0; n     while (b % a == 0) { n       ++tmp; n       b /= a; n       c *= a; n     } n     res *= (tmp + 1); n     lim /= c; n   } n   int upto = (int)pow((double)lim, 1.0 / 3); n   primes = gen_primes(178, upto); n   batch = gen_batch(primes); n   gcds = get_gcds(batch); n   for (long long g : gcds) { n     if (g != 1) { n       res *= 2; n       break; n     } n   } n   cout <<  !   << 2 * res << endl; n } n int main() { n   int tst; n   cin >> tst; n   while (tst--) solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void FLASH() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n } n void SETF() { n   cout.ios_base::setf(ios_base::fixed); n   cerr.ios_base::setf(ios_base::fixed); n } n void UNSETF() { n   cout.ios_base::unsetf(ios_base::fixed); n   cerr.ios_base::unsetf(ios_base::fixed); n } n bool sortinrev(const pair<long long int, long long int> &a, n                const pair<long long int, long long int> &b) { n   return (a.first > b.first); n } n long long int A[1000000]; n long long int B[1000000]; n map<int, vector<int> > node; n int main() { n   FLASH(); n   long long int t; n   cin >> t; n   while (t--) { n     string s; n     long long int n; n     cin >> n >> s; n     if (n == 2) { n       if (s[0] >= s[1]) n         cout <<  NO  << endl; n       else n         cout <<  YES  << endl << 2 << endl << s[0] <<     << s[1] << endl; n     } else { n       cout <<  YES  << endl; n       cout << 2 << endl; n       cout << s[0] <<    ; n       for (long long int i = 1; i < n; i++) cout << s[i]; n       cout << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int x[6]; n int m[6]; n int w[6]; n int h, uh; n int main() { n   x[0] = 500; n   for (int i = 0; i < 5; i++) { n     cin >> m[i]; n     if (i) x[i] = x[i - 1] + 500; n   } n   for (int i = 0; i < 5; i++) cin >> w[i]; n   cin >> h >> uh; n   int score = 0; n   for (int i = 0; i < 5; i++) { n     int bla = 3 * x[i] / 10; n     score += max(bla, (x[i] * (250 - m[i])) / 250 - 50 * w[i]); n   } n   cout << score + 100 * h - 50 * uh << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MM = 1005; n const long long MOD = 1000000007; n int vis[MM][MM] = {0}; n int n, m, k; n bool judge(int x, int y) { n   if (x - 1 >= 0 && y - 1 >= 0) { n     if (vis[x - 1][y - 1] && vis[x - 1][y] && vis[x][y - 1]) return true; n   } n   if (x - 1 >= 0 && y + 1 < m) { n     if (vis[x - 1][y + 1] && vis[x - 1][y] && vis[x][y + 1]) return true; n   } n   if (x + 1 < n && y - 1 >= 0) { n     if (vis[x + 1][y - 1] && vis[x][y - 1] && vis[x + 1][y]) return true; n   } n   if (x + 1 < n && y + 1 < m) { n     if (vis[x + 1][y + 1] && vis[x + 1][y] && vis[x][y + 1]) return true; n   } n   return false; n } n int main() { n   int ans = 0, flag = 0; n   scanf( %d%d%d , &n, &m, &k); n   for (int i = 0; i < k; i++) { n     int x, y; n     scanf( %d%d , &x, &y); n     x--; n     y--; n     vis[x][y] = 1; n     if (!flag && judge(x, y)) { n       ans = i + 1; n       flag = 1; n     } n   } n   if (!flag) n     puts( 0 ); n   else n     printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, m, x, y, a, b; n int main() { n   cin >> n >> m >> x >> y >> a >> b; n   long long W = min(n, (m * a) / b); n   long long divA = a, divB = b; n   for (long long i = 2; i * i <= divB; i++) { n     while (divB % i == 0) { n       if (divA % i == 0) { n         divA /= i; n       } n       divB /= i; n     } n   } n   if (divA % divB == 0) divA /= divB; n   W -= (W % divA); n   long long H = (W * b) / a; n   long long x1 = x - ((W + 1) / 2); n   long long y1 = y - ((H + 1) / 2); n   long long x2 = x1 + W; n   long long y2 = y1 + H; n   if (x2 > n) { n     x2 = n; n     x1 = x2 - W; n   } n   if (x1 < 0) { n     x1 = 0; n     x2 = W; n   } n   if (y2 > m) { n     y2 = m; n     y1 = y2 - H; n   } n   if (y1 < 0) { n     y1 = 0; n     y2 = H; n   } n   W = x2 - x1; n   H = y2 - y1; n   cout << x1 <<     << y1 <<     << x2 <<     << y2 << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e5 + 1e4; n int a[maxn], mod; n int b[maxn]; n int n; n int pow(int a, int b) { n   if (b == 1) return a; n   int t = pow(a, b >> 1); n   t = 1LL * t * t % mod; n   if (b & 1) t = 1LL * t * a % mod; n   return t; n } n int ny(int a) { return pow(a, mod - 2); } n int ans, dd; n void solve(int a[], int n) { n   if (n == 1) { n     ans = a[1]; n     dd = 1; n     return; n   } n   int cc = a[2] - a[1]; n   int s = 0; n   for (int i = (1); i <= (n); ++i) n     if (!binary_search(a + 1, a + n + 1, (a[i] + cc) % mod)) ++s; n   cc = 1LL * cc * ny(s) % mod; n   ans = -1, dd = mod - cc; n   for (int i = (1); i <= (n); ++i) n     if (!binary_search(a + 1, a + n + 1, (a[i] + cc) % mod)) { n       if (ans == -1) n         ans = a[i]; n       else { n         ans = -1; n         break; n       } n     } n } n void init() { n   scanf( %d%d , &mod, &n); n   for (int i = (1); i <= (n); ++i) scanf( %d , &a[i]); n   if (n == mod) { n     printf( %d %d n , 0, 1); n     return; n   } n   sort(a + 1, a + n + 1); n   if (n * 2 > mod) { n     int t = 0; n     for (int i = (0); i <= (mod - 1); ++i) n       if (!binary_search(a + 1, a + n + 1, i)) b[++t] = i; n     solve(b, t); n     if (ans != -1) (ans += 1LL * dd * t % mod) %= mod; n   } else n     solve(a, n); n   if (ans == -1) n     printf( %d n , ans); n   else n     printf( %d %d n , ans, dd); n } n int main() { n   init(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, rsp, ans, taram; n char first; n int main() { n   cin >> n; n   cin >> first; n   if (first ==  U ) { n     taram = 2; n     rsp++; n   } else n     taram = 1; n   for (int i = 2; i <= n; i++) { n     cin >> first; n     if (rsp * 2 == i - 1) { n       ans += (first ==  R  && taram == 2); n       ans += (first ==  U  && taram == 1); n       if ((first ==  R  && taram == 2) || (first ==  U  && taram == 1)) n         taram = taram % 2 + 1; n     } n     if (first ==  U ) rsp++; n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main(int argc, char const *argv[]) { n   int n, x, y; n   cin >> n >> x >> y; n   vector<int> arr(n, 0); n   for (int i = 0; i < n; ++i) { n     cin >> arr[i]; n   } n   sort(arr.begin(), arr.end()); n   if (x > y) { n     cout << n <<   n ; n   } else { n     int index = -1; n     for (int i = 0; i < n; ++i) { n       if (arr[i] > x) { n         index = i; n         break; n       } n     } n     if (index == -1) { n       if (n % 2 == 1) { n         cout << n / 2 + 1 <<   n ; n       } else { n         cout << n / 2 <<   n ; n       } n     } else { n       if ((index) % 2 == 1) { n         cout << (index) / 2 + 1 <<   n ; n       } else { n         cout << (index) / 2 <<   n ; n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int t; n   cin >> t; n   while (t--) { n     long long int a, b; n     cin >> a >> b; n     long long int x; n     x = a % b; n     if (x == 0) n       cout << x << endl; n     else { n       long long int r = a / b; n       long long int res = (r + 1) * b - a; n       cout << res << endl; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int gcd(int u, int v) { n   int tmp; n   while (v) { n     tmp = v; n     v = u % v; n     u = tmp; n   } n   return u; n } n int main() { n   int a, b, t; n   cin >> a >> b; n   if (a > b) { n     swap(a, b); n   } n   if ((t = gcd(a, b)) == 1) { n     cout <<  NO  << endl; n     return 0; n   } n   int flag = 1; n   for (int i = 1; i <= t; i++) { n     for (int j = i; j <= t; j++) { n       if (t * t == i * i + j * j) { n         flag = 0; n         cout <<  YES  << endl; n         cout <<  0 0  << endl; n         cout << i * a / t <<     << -j * a / t << endl; n         cout << j * b / t <<     << i * b / t << endl; n         return 0; n       } n     } n   } n   if (flag) cout <<  NO  << endl; n   return 0; n } n


#include <bits/stdc++.h> n #define ll long long n #define ld long double n #define vec vector n #define pii pair<int, int>  n using namespace std; n  n const long long MAXVAL = (long long) 1e18 + 1; n const long long MOD = 1000000007ll; n //const long long MOD = 998244353ll; n const int INF = 1000000001; n  n long long poww(int x, long long pow) { n   if (pow == 0ll ) return 1; n   if (pow == 1ll) return x % MOD; n   long long ans = poww(x, pow >> 1) % MOD; n   ans = (ans * ans) % MOD; n   if ((pow & 1) == 1) { n     ans = (ans * x ) % MOD; n   } n   return ans % MOD; n } n  n ll gcd(ll x, ll y) { n   if (x == 0) return y; n   while (y) { n     x %= y; n     swap(x, y); n   } n   return x; n } n  n ll sq(int x, int y){  n   return x * 1ll * x + y  * 1ll * y; n } n  n //vector<int> pi(1000); n //vector<int> w(1000); n  n //int dsu_get(int x) { n   //if (pi[x] == x) return x; n   //int res = dsu_get(pi[x]); n   //pi[x] = res; n   //return res; n //} n //void dsu_merge(int x, int y) { n   //if (x == y) return; n   //x = dsu_get(x); n   //y = dsu_get(y); n   //if (x == y) return; n   //if (w[x] > w[y]) swap(x, y); n   //pi[y] = x; n   //w[y] += w[x]; n //} n  n //struct intr { n   //int x, a, lb, rb; n   //intr(int x_, int a_, int lb_, int rb_) { n     //x = x_; n     //a = a_; n     //lb = lb_; n     //rb = rb_; n   //} n //}; n // n //vec<int> t; n  n //void init (int nn) { n   //n = nn; n   //t.assign (n, 0); n //} n  n //int sum (int r) { n   //int result = 0; n   //for (; r >= 0; r = (r & (r+1)) - 1) result += t[r]; n   //return result; n //} n  n //void inc (int i, int delta) { n   //for (; i < n; i = (i | (i+1))) t[i] += delta; n //} n // n  n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   int q = 1; n   //cin >> q; n   while (q-- > 0) {  n     int n,k; n     cin >> n >> k; n     vec<set<int>> gr(n); n     vec<set<int>> gr2(n); n     for (int i = 0; i < n; ++i) { n       int x; n       cin >> x; n       if (x == 0) continue; n       --x; n       gr[x].insert(i); n     } n     vec<pii> req; n     vec<int> pi(n); n     for (int i = 0; i < n; ++i) pi[i] = i; n     bool fail = false; n     vec<int> was(n, 0); n     gr2 = gr; n     vec<set<int>> gr2t(n); n     for (int i  =0; i < n; ++i) { n       for (int j : gr2[i]) { n         gr2t[j].insert(i); n       } n     } n     //for (int i = 0; i < n; ++i)labels[i] = {i}; n     vec<int>was2(n, 0); n     for (int j = 0; j < k; ++j) { n       int x, y; n       cin >> x >> y; n       --x; n       --y; n       req.emplace_back(x, y); n       //cout <<   req   << j << endl; n       if (gr2[y].count(x)) { n         //cout <<   y -> x   << y +1 <<     << x+1 << endl; n         fail = true; n       } else { n         //if (gr[x].count(y)) { n           //gr[x].erase(gr[x].find(y)); n         //} n         gr2[x].insert(y); n         if (pi[y] != y) { n           // cannot be n           //cout <<   cannot bE   << fail << endl; n           fail = true; n         } n         int top = x; n         vec<int> path; n         while (top != pi[top]) { n           path.push_back(top); n           top = pi[top]; n         } n         for (auto& s : path) { n           pi[s] = top; n         } n         pi[y] = pi[x]; n         was[y] = 2; n       } n     } n     if (fail) { n       cout << 0 <<   n ; n       continue; n     } n  n     function<void(int)>  dfs = [&] (int v) { n       //cout <<   cur v   << v + 1 << endl; n       was2[v] = 1; n       for (int next : gr2[v]) { n         if (was2[next] == 0) { n           dfs(next); n         } else if (was2[next] == 1) { n           //cout <<   next gives cycle   << next + 1 << endl; n           fail = true; n           break; n         } n       } n       was2[v] = 2; n       //cout <<   OUT   << v + 1 << endl; n     }; n     for (int i = 0; i < n; ++i) if (was2[i] == 0) dfs(i); n     if (fail) { n       cout <<  0 n ; n       continue; n     } n     vec<set<int>> grnew(n); n     for (int i = 0; i < n; ++i) { n         vec<int> path; n         int top = i; n         while (top != pi[top]) { n           path.push_back(top); n           top = pi[top]; n         } n         for (int s : path) { n           pi[s] = top; n         } n       for (int out : gr[i]) { n         if (pi[out] != pi[i]) { n           grnew[pi[i]].insert(pi[out]); n         } n       } n       for (int in : gr2t[i]) { n         if (pi[in] != pi[i]) { n           grnew[pi[in]].insert(pi[i]); n         } n       } n     } n     //for (auto r: req) { n       //gr2[r.first].insert(r.second); n     //} n     vec<int> topo; n     bool cycle = false; n     vec<int> next; n     vec<int> prev; n     for (int i =0 ;i < n; ++i) { n       prev.push_back(i); n       next.push_back(i); n     } n     for (int i = 0; i < k; ++i) { n       int x = req[i].first; n       int y = req[i].second; n       next[x] = y; n       prev[y] = x; n     } n  n     function<void(int)>  topo_dfs = [&] (int v) { n       //cout <<   cur v   << v + 1 << endl; n       was[v] = 1; n       for (int next : grnew[v]) { n         if (was[next] == 0) { n           topo_dfs(next); n         } else if (was[next] == 1) { n           //cout <<   next gives cycle   << next + 1 << endl; n           cycle = true; n         } n       } n       was[v] = 2; n       //cout <<   OUT of   << v + 1  << endl; n       topo.push_back(v); n     }; n     for (int i = 0; i < n; ++i) { n       if (was[i]) continue; n       topo_dfs(i); n     } n     if (cycle) { n       cout << 0 <<   n ; n     } else { n       reverse(topo.begin(), topo.end()); n       vec<int> ans; n       vec<bool> was(n, false); n       for (int i = 0 ; i < topo.size(); ++i) { n         int x = topo[i]; n         //cout <<   Cur x   << x + 1 << endl; n         if (prev[x] != x) continue; n         while (x != next[x]) { n           if (was[x]) { n             //cout <<  was in   << x + 1 << endl; n             fail = true; n             break; n           } n           was[x] = true; n           //cout <<   next x   << x + 1 << endl; n           ans.push_back(x); n           x = next[x]; n         } n         ans.push_back(x); n       } n       if (fail || ans.size() < n) { n         cout << 0 <<   n ; n       } else { n         for (auto l : ans) { n           cout << 1 + l <<    ; n         } n         cout <<   n ; n       } n     } n  n  n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   string str1, str2; n   cin >> str1 >> str2; n   int diffcount = 0; n   for (int i = 0; i < str1.length(); i++) { n     if (str1[i] != str2[i]) diffcount++; n   } n   if (diffcount % 2 == 1) { n     cout <<  impossible ; n     return 0; n   } n   int index = 0; n   int toreach = diffcount / 2; n   while (diffcount != toreach) { n     if (str1[index] != str2[index]) { n       if (str1[index] ==  1 ) n         str1[index] =  0 ; n       else n         str1[index] =  1 ; n       diffcount--; n     } n     index++; n   } n   cout << str1; n } n


#include<iostream> n #include<algorithm> n using namespace std; n class node{ n     public: n         int a; n         int b; n }; n bool com(node a,node b){ n     return a.a<b.a; n } n int main(){ n     int times=0; n     cin>>times; n     while(times--){ n         int t=0; n         cin>>t; n         node *arr=new node[t+5](); n         for(int i=0;i<t;i++){ n             scanf( %d ,&arr[i].a); n             arr[i].b=i+1; n         } n         if(t==1){ n             cout<<arr[0].a<<endl; n             continue; n         } n         sort(arr,arr+t,com); n         bool fl=false; n         for(int i=0;i<t;i++){ n             if(i==0){ n                 if(arr[i].a!=arr[i+1].a){ n                     cout<<arr[i].b<<endl; n                     fl=true; n                     break; n                 } n             } n             if(i==t-1){ n                 if(arr[i].a!=arr[i-1].a){ n                     cout<<arr[i].b<<endl; n                     fl=true; n                     break; n                 } n             } n             if(arr[i].a!=arr[i+1].a&&arr[i].a!=arr[i-1].a){ n                 cout<<arr[i].b<<endl; n                     fl=true; n                     break; n             } n         } n         if(!fl) n         cout<<-1<<endl; n     } n     return 0; n }


#include <bits/stdc++.h> n using namespace std; n int n; n long double l, v1, v2; n long double a[100000]; n long double p[100001]; n vector<pair<long double, int> > events; n int main() { n   cout << fixed << setprecision(12); n   cin >> n >> l >> v1 >> v2; n   long double dist = l * v2 / (v1 + v2); n   events.push_back(make_pair(0, 0)); n   events.push_back(make_pair(2 * l, 0)); n   for (int i = 0; i < n; ++i) { n     cin >> a[i]; n     events.push_back(make_pair(a[i] - dist, 1)); n     events.push_back(make_pair(a[i] + 2 * l - dist, 1)); n     events.push_back(make_pair(a[i], -1)); n   } n   sort(events.begin(), events.end()); n   memset(p, 0, sizeof p); n   int choc = 0, i = 0; n   while (events[i].second != 0) { n     choc += events[i].second; n     ++i; n   } n   ++i; n   while (events[i].second != 0) { n     p[choc] += events[i].first - events[i - 1].first; n     choc += events[i].second; n     ++i; n   } n   p[choc] += events[i].first - events[i - 1].first; n   for (int i = 0; i <= n; ++i) cout << (p[i] / 2 / l) << endl; n } n


#include<bits/stdc++.h> n using namespace std; n #define ll long long n #define ull unsigned long long n #define f(i,x,y) for(int i=x;i<=y;i++) n #define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); n //priority_queue<int>Q; n //unordered_map<string,int> Q; n const int MAX=3e5+10; n ll a[MAX]; n void solve() { n  ll n; n  cin>>n; n  for(int i=1; i<=n*2; i++) { n   cin>>a[i]; n  } n  int flag1=1; n  sort(a+1,a+1+n*2,greater<ll>()); n  ll last; n  int v=-1; n  ll flag=0; n  ll cnt=n; n  for(int i=1; i<=n*2; i+=2) { n   if(a[i]!=a[i+1]||a[i]<2||a[i]%2) { n    flag1=0; n    cout<< NO <<endl; n    break; n   } n   a[i]-=flag; n   if((v!=-1&&a[i]>=last*cnt)||a[i]<=0) { n    flag1=0; n    cout<< NO <<endl; n    break; n   } n   if(a[i]%cnt==0) { n    v=1; n    last=a[i]/cnt; n   } else { n    flag1=0; n    cout<< NO <<endl; n    break; n   } n   if(last&1) n   { n    flag1=0; n    cout<< NO <<endl; n       break; n   } n   flag+=last; n   cnt--; n  } n  if(flag1) n   cout<< YES <<endl; n } n int main() { n  IOS; n  int t; n  cin>>t; n  while(t--) { n   solve(); n  } n } n