#include <bits/stdc++.h> n using namespace std; n template <typename T> n void chkmax(T &x, T y) { n   x = x > y ? x : y; n } n template <typename T> n void chkmin(T &x, T y) { n   x = x > y ? y : x; n } n template <typename T> n void update(T &x, T y, T mod) { n   x = x + y > mod ? x + y - mod : x + y; n } n template <typename T> n void multi(T &x, T y, T mod) { n   x = 1ll * x * y % mod; n } n const int INF = (1ll << 30); n template <typename T> n void read(T &x) { n   x = 0; n   bool f = 1; n   char ch; n   do { n     ch = getchar(); n     if (ch ==  - ) f = 0; n   } while (ch >  9  || ch <  0 ); n   do { n     x = x * 10 + ch -  0 ; n     ch = getchar(); n   } while (ch >=  0  && ch <=  9 ); n   x = f ? x : -x; n } n template <typename T> n void write(T x) { n   if (x < 0) x = ~x + 1, putchar( - ); n   if (x > 9) write(x / 10); n   putchar(x % 10 +  0 ); n } n const int N = 1e5 + 7; n struct Segment_Tree { n   int l, r, sum, rem, mul, fac[20]; n } t[N << 2]; n int n, m, mod, cnt, tot, phi, a[N], P[N], tmp[N], prime[N]; n bool vis[N]; n inline int calc(int x) { n   for (int i = 1; i <= tot; i++) { n     tmp[i] = 0; n     while (x % P[i] == 0) { n       x /= P[i]; n       tmp[i]++; n     } n   } n   return x; n } n inline int qpow(int a, int b) { n   long long ret = 1; n   while (b) { n     if (b & 1) ret = 1ll * ret * a % mod; n     a = 1ll * a * a % mod; n     b >>= 1; n   } n   return ret % mod; n } n inline void mul(int p, int mul, int rem, int *tmp) { n   multi(t[p].rem, rem, mod); n   for (int i = 1; i <= tot; i++) t[p].fac[i] += tmp[i]; n   multi(t[p].sum, mul, mod); n   multi(t[p].mul, mul, mod); n } n inline void divide(int p, int y, int *tmp) { n   multi(t[p].rem, qpow(y, phi - 1), mod); n   int tp = t[p].rem; n   for (int i = 1; i <= tot; i++) { n     t[p].fac[i] -= tmp[i]; n     multi(tp, qpow(P[i], t[p].fac[i]), mod); n   } n   t[p].sum = tp % mod; n } n inline void pushdown(int p) { n   if (t[p].mul != 1 || t[p].rem != 1) { n     mul((p << 1), t[p].mul, t[p].rem, t[p].fac); n     mul((p << 1 | 1), t[p].mul, t[p].rem, t[p].fac); n     t[p].mul = t[p].rem = 1; n     for (int i = 1; i <= tot; i++) t[p].fac[i] = 0; n   } n } n inline void build(int p, int l, int r) { n   t[p].l = l; n   t[p].r = r; n   t[p].mul = t[p].rem = 1; n   if (l == r) { n     t[p].sum = a[l] % mod; n     t[p].rem = calc(a[l]); n     for (int i = 1; i <= tot; i++) t[p].fac[i] = tmp[i]; n     return; n   } n   pushdown(p); n   int mid = (t[p].l + t[p].r) >> 1; n   build((p << 1), l, mid); n   build((p << 1 | 1), mid + 1, r); n   t[p].sum = (t[(p << 1)].sum + t[(p << 1 | 1)].sum) % mod; n } n inline void multi(int p, int l, int r, int x, int k, int *tmp) { n   if (l <= t[p].l && t[p].r <= r) { n     mul(p, k, x, tmp); n     return; n   } n   pushdown(p); n   int mid = (t[p].l + t[p].r) >> 1; n   if (l <= mid) multi((p << 1), l, r, x, k, tmp); n   if (r > mid) multi((p << 1 | 1), l, r, x, k, tmp); n   t[p].sum = (t[(p << 1)].sum + t[(p << 1 | 1)].sum) % mod; n } n inline void divide(int p, int x, int y, int *tmp) { n   if (t[p].l == t[p].r) { n     divide(p, y, tmp); n     return; n   } n   pushdown(p); n   int mid = (t[p].l + t[p].r) >> 1; n   if (x <= mid) n     divide((p << 1), x, y, tmp); n   else n     divide((p << 1 | 1), x, y, tmp); n   t[p].sum = (t[(p << 1)].sum + t[(p << 1 | 1)].sum) % mod; n } n inline int query(int p, int l, int r) { n   if (l <= t[p].l && t[p].r <= r) return t[p].sum; n   pushdown(p); n   int mid = (t[p].l + t[p].r) >> 1, ans = 0; n   if (l <= mid) update(ans, query((p << 1), l, r), mod); n   if (r > mid) update(ans, query((p << 1 | 1), l, r), mod); n   return ans; n } n inline void init(int NN) { n   for (int i = 2; i <= NN; i++) { n     if (!vis[i]) { n       prime[++cnt] = i; n     } n     for (int j = 1; j <= cnt && prime[j] * i <= NN; j++) { n       vis[i * prime[j]] = true; n       if (i % prime[j] == 0) break; n     } n   } n } n inline int getphi(int x) { n   int ans = x; n   for (int i = 1; i <= cnt && prime[i] * prime[i] <= x; i++) { n     if (x % prime[i] == 0) { n       ans = 1ll * ans * (prime[i] - 1) / prime[i]; n       while (x % prime[i] == 0) x /= prime[i]; n     } n   } n   if (x != 1) ans = 1ll * ans * (x - 1) / x; n   return ans; n } n inline void divide(int x) { n   for (int i = 1; i <= cnt && prime[i] * prime[i] <= x; i++) { n     if (x % prime[i] == 0) { n       while (x % prime[i] == 0) x /= prime[i]; n       P[++tot] = prime[i]; n     } n   } n   if (x != 1) P[++tot] = x; n } n int main() { n   read(n); n   read(mod); n   init(1e5); n   divide(mod); n   phi = getphi(mod); n   for (int i = 1; i <= n; i++) read(a[i]); n   build(1, 1, n); n   read(m); n   for (int i = 1, opt, l, r, x; i <= m; i++) { n     read(opt); n     if (opt == 1) { n       read(l); n       read(r); n       read(x); n       multi(1, l, r, calc(x), x, tmp); n     } n     if (opt == 2) { n       read(l); n       read(x); n       divide(1, l, calc(x), tmp); n     } n     if (opt == 3) { n       read(l); n       read(r); n       printf( %d n , query(1, l, r) % mod); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, a, b, h[15], side = 0, dsh[15], cent = 52; n vector<int> sshot, cshot; n void recur(int now, int tot) { n   if (now == n - 1) { n     int ok = 1; n     for (int i = 1; i < n - 1; i++) n       if (dsh[i] * a + dsh[i - 1] * b + dsh[i + 1] * b <= h[i]) { n         ok = 0; n         break; n       } n     if (ok == 1 && tot < cent) { n       cent = tot; n       cshot.clear(); n       for (int i = 1; i < n - 1; i++) n         for (int j = 0; j < dsh[i]; j++) cshot.push_back(i); n     } n     return; n   } n   if (tot >= cent) return; n   for (int i = 0; i <= 8; i++) { n     dsh[now] = i; n     recur(now + 1, tot + i); n   } n } n int main() { n   scanf( %d%d%d , &n, &a, &b); n   for (int i = 0; i < n; i++) { n     scanf( %d , &h[i]); n   } n   while (h[0] >= 0) { n     h[0] -= b; n     h[2] -= b; n     h[1] -= a; n     side++; n     sshot.push_back(1); n   } n   while (h[n - 1] >= 0) { n     h[n - 1] -= b; n     h[n - 3] -= b; n     h[n - 2] -= a; n     side++; n     sshot.push_back(n - 2); n   } n   memset(dsh, 0, sizeof(dsh)); n   recur(1, 0); n   printf( %d n , cent + side); n   printf( %d , sshot[0] + 1); n   for (int i = 1; i < sshot.size(); i++) printf(  %d , sshot[i] + 1); n   for (int i = 0; i < cshot.size(); i++) printf(  %d , cshot[i] + 1); n   printf(  n ); n } n


#include <bits/stdc++.h> n using namespace std; n void solve() { n   int n; n   cin >> n; n   vector<int> v(n); n   for (long long i = 0; i < n; i++) cin >> v[i]; n   ; n   vector<int> u(n); n   for (long long i = 0; i < n; i++) cin >> u[i]; n   ; n   sort((v).begin(), (v).end()); n   sort((u).begin(), (u).end()); n   bool turn = 0; n   long long a = 0LL, b = 0LL; n   while (!v.empty() || !u.empty()) { n     if (!turn) { n       if (v.back() >= u.back()) { n         if (!v.empty()) { n           a += v.back(); n           v.pop_back(); n         } else if (!u.empty()) { n           u.pop_back(); n         } else { n           break; n         } n       } else { n         if (!u.empty()) { n           u.pop_back(); n         } else if (!v.empty()) { n           a += v.back(); n           v.pop_back(); n         } else { n           break; n         } n       } n       turn = 1; n     } else { n       if (u.back() >= v.back()) { n         if (!u.empty()) { n           b += u.back(); n           u.pop_back(); n         } else if (!v.empty()) { n           v.pop_back(); n         } else { n           break; n         } n       } else { n         if (!v.empty()) { n           v.pop_back(); n         } else if (!u.empty()) { n           b += u.back(); n           u.pop_back(); n         } else { n           break; n         } n       } n       turn = 0; n     } n   } n   cout << a - b << endl; n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m; n   scanf( %d%d , &n, &m); n   int l = (n - 1) / m; n   if ((n - 1) % m == 0) n     printf( %d n , 2 * l); n   else n     printf( %d n , 2 * l + 1 + ((n - 1) % m >= 2)); n   int need = (n - 1) % m; n   for (int i = 2; i <= n;) { n     int maxn = min(n, i + l - 1 + (need-- > 0)); n     printf( %d %d n , 1, i); n     int j = i; n     while (j++ < maxn) printf( %d %d n , j - 1, j); n     i = maxn + 1; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int Int() { n   int x; n   scanf( %d , &x); n   return x; n } n long long Long() { n   long long x; n   scanf( %lld , &x); n   return x; n } n void err(istream_iterator<string> it) { cout << endl; } n template <typename T, typename... Args> n void err(istream_iterator<string> it, T a, Args... args) { n   cerr << *it <<   =   << a <<    ; n   err(++it, args...); n } n const int N = (int)2e5 + 5; n const int maxN = (int)1e6 + 6; n const long long Mod = (long long)1e9 + 7; n const int inf = (int)2e9; n const long long Inf = (long long)1e18; n struct lowest_common_ancestor { n   const static int N = 1e5 + 5; n   const static int k = 17; n   int par[N][k + 1], lev[N]; n   vector<vector<int>> g, city; n   vector<int> ID[N][k + 1]; n   lowest_common_ancestor() { n     for (int i = 0; i < N; ++i) { n       for (int j = 0; j <= k; ++j) par[i][j] = 0; n       lev[i] = 0; n     } n   } n   vector<int> merge(vector<int> &a, vector<int> &b) { n     vector<int> tmp; n     auto i = a.begin(), j = b.begin(); n     for (int k = 1; k <= min(10, (int)a.size() + (int)b.size()); ++k) { n       if (i != a.end() and j != b.end()) { n         if (*i < *j) n           tmp.push_back(*i), ++i; n         else n           tmp.push_back(*j), ++j; n       } else if (i != a.end()) n         tmp.push_back(*i), ++i; n       else n         tmp.push_back(*j), ++j; n     } n     return tmp; n   } n   void build(int s, int p = 0) { n     lev[s] = 1 + lev[p]; n     par[s][0] = p; n     ID[s][0].assign(city[p].begin(), city[p].end()); n     for (int i = 1; i <= k; ++i) { n       par[s][i] = par[par[s][i - 1]][i - 1]; n       ID[s][i] = merge(ID[s][i - 1], ID[par[s][i - 1]][i - 1]); n     } n     for (int i : g[s]) n       if (i != p) build(i, s); n   } n   void getLCA(int a, int b, int num) { n     if (lev[a] < lev[b]) swap(a, b); n     vector<int> res(city[a].begin(), city[a].end()); n     int d = lev[a] - lev[b]; n     int t = b; n     for (int i = k; i >= 0; --i) { n       if ((d >> i) & 1) { n         res = merge(res, ID[a][i]); n         a = par[a][i]; n       } n     } n     if (a == b) { n       printf( %d , min((int)res.size(), num)); n       for (int i = 0; i < min(num, (int)res.size()); ++i) printf(  %d , res[i]); n       cout <<   n ; n       return; n     } n     for (int i = k; i >= 0; --i) { n       if (par[a][i] != par[b][i]) { n         res = merge(res, ID[a][i]); n         res = merge(res, ID[b][i]); n         b = par[b][i]; n         a = par[a][i]; n       } n     } n     res = merge(res, city[par[a][0]]); n     res = merge(res, city[t]); n     printf( %d , min((int)res.size(), num)); n     for (int i = 0; i < min(num, (int)res.size()); ++i) printf(  %d , res[i]); n     cout <<   n ; n     return; n   } n   void solve() { n     int n = Int(), m = Int(), q = Int(); n     g.resize(n + 1); n     city.resize(n + 1); n     for (int i = 1; i < n; ++i) { n       int x = Int(), y = Int(); n       g[x].emplace_back(y); n       g[y].emplace_back(x); n     } n     for (int i = 1; i <= m; ++i) { n       int c = Int(); n       city[c].emplace_back(i); n     } n     for (int i = 1; i <= n; ++i) { n       sort(city[i].begin(), city[i].end()); n       while ((int)city[i].size() > 10) city[i].pop_back(); n     } n     build(1); n     while (q--) { n       int l = Int(), r = Int(), t = Int(); n       getLCA(l, r, t); n     } n   } n }; n lowest_common_ancestor lca; n int main() { n   int test = 1, tc = 0; n   while (test--) { n     lca.solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e5 + 50; n const int inf = 0x3f3f3f3f; n int A[maxn]; n int n, k; n void solve(int l, int r) { n   if (l + 1 == r || !k) return; n   int mid = (l + r) >> 1; n   k -= 2; n   swap(A[mid], A[mid - 1]); n   solve(l, mid); n   solve(mid, r); n } n int main() { n   scanf( %d%d , &n, &k); n   for (int i = 0; i < n; i++) A[i] = i + 1; n   k--; n   if (k & 1) { n     puts( -1 ); n     return 0; n   } n   solve(0, n); n   if (k) n     puts( -1 ); n   else { n     for (int i = 0; i < n; i++) printf( %d  , A[i]); n     puts(  ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int Imx = 2147483647; n const long long Lbig = 2e18; n const int mod = 1e9 + 7; n struct fastio { n   char s[100000]; n   int it, len; n   fastio() { it = len = 0; } n   inline char get() { n     if (it < len) return s[it++]; n     it = 0; n     len = fread(s, 1, 100000, stdin); n     if (len == 0) n       return EOF; n     else n       return s[it++]; n   } n   bool notend() { n     char c = get(); n     while (c ==     || c ==   n ) c = get(); n     if (it > 0) it--; n     return c != EOF; n   } n } _buff; n inline long long getnum() { n   long long r = 0; n   bool ng = 0; n   char c; n   c = _buff.get(); n   while (c !=  -  && (c <  0  || c >  9 )) c = _buff.get(); n   if (c ==  - ) ng = 1, c = _buff.get(); n   while (c >=  0  && c <=  9 ) r = r * 10 + c -  0 , c = _buff.get(); n   return ng ? -r : r; n } n template <class T> n inline void putnum(T x) { n   if (x < 0) putchar( - ), x = -x; n   register short a[20] = {}, sz = 0; n   while (x) a[sz++] = x % 10, x /= 10; n   if (sz == 0) putchar( 0 ); n   for (int i = sz - 1; i >= 0; i--) putchar( 0  + a[i]); n } n inline char getreal() { n   char c = _buff.get(); n   while (c ==     || c ==   n ) c = _buff.get(); n   return c; n } n int n; n int ask(int x, int y) { n   printf( ? %d %d n , x, y); n   fflush(stdout); n   int ans; n   scanf( %d , &ans); n   return ans; n } n int a[5011], b[5011]; n int A[5011], B[5011]; n bool hs[5011]; n int tans[5011]; n bool check() { n   memset(hs, 0, sizeof(hs)); n   for (int i = 0; i < n; i++) { n     if (A[i] < 0 || A[i] >= n || hs[A[i]]) return false; n     hs[A[i]] = 1; n   } n   memset(hs, 0, sizeof(hs)); n   for (int i = 0; i < n; i++) { n     if (B[i] < 0 || B[i] >= n || hs[B[i]]) return false; n     hs[B[i]] = 1; n   } n   for (int i = 0; i < n; i++) { n     if (A[B[i]] != i) return false; n   } n   return true; n } n int main() { n   scanf( %d , &n); n   for (int i = 0; i < n; i++) { n     a[i] = ask(i, 0); n   } n   for (int i = 0; i < n; i++) { n     b[i] = ask(0, i); n   } n   int cnt = 0; n   for (int i = 0; i < n; i++) { n     A[0] = i; n     B[0] = A[0] ^ a[0]; n     for (int j = 1; j < n; j++) { n       A[j] = A[0] ^ a[0] ^ a[j]; n       B[j] = B[0] ^ b[0] ^ b[j]; n     } n     if (check()) { n       cnt++; n       for (int j = 0; j < n; j++) tans[j] = A[j]; n     } n   } n   printf( ! n ); n   printf( %d n , cnt); n   for (int i = 0; i < n; i++) printf( %d%c , tans[i], i + 1 < n ?     :   n ); n   fflush(stdout); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2e6 + 5; n const long long M = 1e9 + 7; n const long long inf = 1e18 + 5; n vector<int> prefix_function(string &s) { n   int n = s.size(); n   vector<int> pre(n); n   int pos = 0; n   pre[0] = 0; n   for (int i = 1; i < n; i++) { n     while (pos and s[pos] != s[i]) pos = pre[pos - 1]; n     if (s[pos] == s[i]) pos++; n     pre[i] = pos; n   } n   return pre; n } n int main() { n   string s, t; n   cin >> t >> s; n   int n = s.size(); n   vector<int> pre = prefix_function(s); n   int a[n][26]; n   for (int i = 0; i < n; i++) { n     for (int c = 0; c < 26; c++) { n       if (i and s[i] !=  a  + c) n         a[i][c] = a[pre[i - 1]][c]; n       else n         a[i][c] = i + (s[i] ==  a  + c); n     } n   } n   int tz = t.size(); n   int dp[tz + 1][n]; n   memset(dp, -1, sizeof(dp)); n   dp[0][0] = 0; n   for (int i = 0; i < tz; i++) { n     for (int j = 0; j < n; j++) { n       if (dp[i][j] != -1) { n         if (t[i] ==  ? ) { n           for (int ch = 0; ch < 26; ch++) { n             int val = a[j][ch]; n             if (val == n) n               dp[i + 1][pre[n - 1]] = max(dp[i + 1][n - 1], dp[i][j] + 1); n             else n               dp[i + 1][val] = max(dp[i + 1][val], dp[i][j]); n           } n         } else { n           int val = a[j][t[i] -  a ]; n           if (val == n) n             dp[i + 1][pre[n - 1]] = max(dp[i + 1][n - 1], dp[i][j] + 1); n           else n             dp[i + 1][val] = max(dp[i + 1][val], dp[i][j]); n         } n       } n     } n   } n   int ans = 0; n   for (int i = 0; i < n; i++) ans = max(ans, dp[tz][i]); n   printf( %d  , ans); n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /STACK:256000000 ) n using namespace std; n const int INF = 1000001000; n const long long INFLL = INF * 1LL * INF; n const int mod = 1000 * 1000 * 1000 + 7; n const int mod9 = 1000 * 1000 * 1000 + 9; n const int modr = 99990001; n const long double PI = 3.1415926535897932385; n template <class T> n void zero(T val, T& first) { n   first = val; n } n template <class T, class... Targs> n void zero(T val, T& first, Targs&... Fargs) { n   first = val; n   zero(val, Fargs...); n } n template <class T, class T2> n std::istream& operator>>(std::istream& is, pair<T, T2>& p) { n   return is >> p.first >> p.second; n } n template <class T> n std::istream& readN(T& first, int n, int st = 0) { n   for (int i = st, iend = (st + n - 1); i <= iend; i++) cin >> first[i]; n   return cin; n } n template <class T> n std::istream& readS(set<T>& first, int n) { n   T second = *first.rbegin(); n   for (int i = 0, iend = (n - 1); i <= iend; i++) { n     cin >> second; n     first.insert(second); n   } n   return cin; n } n template <class T> n std::istream& read(T& first) { n   return cin >> first; n } n template <class T, class... Targs> n std::istream& read(T& first, Targs&... Fargs) { n   return read(first), read(Fargs...); n } n template <class T, class T2> n std::ostream& operator<<(std::ostream& os, pair<T, T2> p) { n   return os << p.first <<     << p.second; n } n template <class T> n std::ostream& operator<<(std::ostream& os, vector<T> v) { n   bool f = true; n   for (auto second : v) { n     if (!f) os <<    ; n     os << second; n     f = false; n   } n   return os; n } n template <class T> n std::ostream& operator<<(std::ostream& os, set<T> v) { n   bool f = true; n   for (auto second : v) { n     if (!f) os <<    ; n     os << second; n     f = false; n   } n   return os; n } n template <class T> n std::ostream& operator<<(std::ostream& os, multiset<T> v) { n   bool f = true; n   for (auto second : v) { n     if (!f) os <<    ; n     os << second; n     f = false; n   } n   return os; n } n template <class T, class T2> n std::ostream& operator<<(std::ostream& os, map<T, T2> v) { n   bool f = true; n   for (pair<T, T2> second : v) { n     if (!f) os <<    ; n     os << second.first <<  =>  << second.second; n     f = false; n   } n   return os; n } n template <class T> n std::ostream& outV(T first, char del =    ) { n   bool f = true; n   for (auto second : first) { n     if (!f) cout << del; n     cout << second; n     f = false; n   } n   return cout; n } n template <class T> n std::ostream& outN(T first, int n = -1, int st = 0) { n   for (int i = st, iend = (n == -1 ? (int)first.size() - 1 : st + n - 1); n        i <= iend; i++) { n     cout << first[i]; n     if (i < iend) cout <<    ; n   } n   return cout; n } n template <class T> n std::ostream& outAN(T first, int n = -1, int st = 0) { n   for (int i = st, iend = (n - 1); i <= iend; i++) { n     cout << first[i]; n     if (i < iend) cout <<    ; n   } n   return cout; n } n template <class T> n std::ostream& outA2(T first, int n, int m) { n   for (int i = 0, iend = (n - 1); i <= iend; i++) { n     for (int j = 0, jend = (m - 1); j <= jend; j++) n       cout << first[i][j] << (j == m - 1 ?   n  :    ); n   } n   return cout; n } n template <class T> n std::ostream& out(T first) { n   return cout << first; n } n template <class T, class... Targs> n std::ostream& out(T first, Targs... Fargs) { n   return out(first) <<    , out(Fargs...); n } n template <typename T> n void srt(T& a, int st, int fn, bool isArr) { n   sort(a + st, a + fn + 1); n } n template <class T> n void srt(T& a, int st = 0, int fn = 0) { n   sort(a.begin() + st, fn ? a.begin() + fn + 1 : a.end()); n } n template <typename T> n T rev_num(T a) { n   T r = 0; n   for (; a; a /= 10) r = r * 10 + a % 10; n   return r; n } n template <typename T> n void rev(T& a, int st, int fn, bool isArr) { n   reverse(a + st, a + fn + 1); n } n template <class T> n void rev(T& a, int st = 0, int fn = 0) { n   reverse(a.begin() + st, fn ? a.begin() + fn + 1 : a.end()); n } n long long sqr(long long a) { return a * a; }; n long long sqr(int a) { return a * 1LL * a; }; n long double sqr(long double a) { return a * a; }; n long long phi(int n) { n   int res = n; n   for (long long i = 2; i * i <= n; i++) n     if (n % i == 0) { n       while (n % i == 0) n /= i; n       res -= res / i; n     } n   if (n > 1) res -= res / n; n   return res; n } n long long bpm(long long a, long long n = -2, long long m = mod) { n   n = n < 0 ? n + m : n; n   long long r = 1; n   while (n) { n     if (n & 1) r = (r * a) % m; n     a = (a * a) % m; n     n >>= 1; n   } n   return r; n } n unsigned long long gcd(unsigned long long a, unsigned long long b) { n   while (b) { n     a %= b; n     swap(a, b); n   } n   return a; n } n vector<int> ero_p, ero_l; n void ero(int n) { n   ero_l.resize(n + 1); n   ero_l[0] = -1; n   for (int i = 2, iend = (n); i <= iend; i++) n     if (!ero_l[i]) { n       ero_p.push_back(i); n       ero_l[i] = i; n       for (long long j = i * 1LL * i; j <= n; j += i) { n         ero_l[j] = i; n       } n     } n } n long long gcd_cb(long long a, long long b, long long& first, n                  long long& second) { n   if (!b) { n     first = 1; n     second = 0; n     return a; n   } n   long long x1, y1, g; n   g = gcd_cb(b, a % b, x1, y1); n   first = y1; n   second = x1 - a / b * y1; n   return g; n } n vector<long long> fact; n void fact_prec(int n = 20) { n   fact.resize(n + 1); n   fact[0] = 1; n   for (int i = 1, iend = (n); i <= iend; i++) { n     fact[i] = fact[i - 1] * i; n   } n } n vector<long double> factd; n void fact_precd(int n = 146) { n   factd.resize(n + 1); n   factd[0] = 1; n   for (int i = 1, iend = (n); i <= iend; i++) { n     factd[i] = factd[i - 1] * i; n   } n } n string str(long long a) { n   string r =   ; n   for (; a; a /= 10) r += a % 10 +  0 ; n   rev(r); n   return r; n } n const int N = 200005; n void solution() { n   long long n, first, second; n   read(n, first, second); n   string s; n   read(s); n   int pv = -1; n   long long res = 0; n   for (int i = 0, iend = (n - 1); i <= iend; i++) { n     if (s[i] ==  0 ) { n       if (pv + 1 < i && pv != -1) { n         res += min(first, second); n       } n       pv = i; n     } n   } n   res += pv == -1 ? 0LL : second; n   out(res) <<   n ; n } n int main() { n   ios::sync_with_stdio(false); n   solution(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 0x3f3f3f3f; n const int N = 1e5 + 10; n string a; n int main() { n   int n; n   while (~scanf( %d , &n)) { n     map<string, int> q; n     q.clear(); n     int num = 0; n     for (int i = 0; i < n; i++) { n       cin >> a; n       q[a]++; n       num = max(num, q[a]); n     } n     printf( %d n , num); n   } n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n int m, n; n string bs[50]; n long long component[1000]; n long long combo[1001][1001]; n long long pseudopart[1001]; n bool visited[1000]; n int main() { n   cin >> m >> n; n   for (int i = 0; i < n; i++) cin >> bs[i]; n   for (int i = 0; i < m; i++) n     for (int j = 0; j < n; j++) { n       component[i] *= 2LL; n       component[i] += (long long)((int)bs[j][i] - (int) 0 ); n     } n   combo[0][0] = 1; n   for (int i = 1; i < 1001; i++) n     for (int j = 0; j <= i; j++) { n       if (j == 0 || j == i) n         combo[i][j] = 1; n       else n         combo[i][j] = combo[i - 1][j] + combo[i - 1][j - 1]; n       combo[i][j] %= 1000000007; n     } n   pseudopart[0] = 1; n   pseudopart[1] = 1; n   for (int i = 2; i <= m; i++) { n     for (int j = 0; j < i; j++) { n       pseudopart[i] += combo[i - 1][j] * pseudopart[i - 1 - j]; n       pseudopart[i] %= 1000000007; n     } n   } n   long long ans = 1; n   for (int i = 0; i < m; i++) { n     if (visited[i]) continue; n     long long temp = 0; n     for (int j = 0; j < m; j++) n       if (component[j] == component[i]) { n         visited[j] = true; n         temp++; n       } n     ans *= pseudopart[temp]; n     ans %= 1000000007; n   } n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 1e9 + 7; n const int maxn = 1e5 + 5; n const int MAX = 314000000; n int n, m; n int dis[maxn], tot[maxn], sum[maxn], dp[maxn]; n vector<int> have[maxn]; n queue<int> q; n priority_queue<pair<int, int>, vector<pair<int, int> >, n                greater<pair<int, int> > > n     pq; n class Edge { n  public: n   int from, l, dia, cur; n   vector<int> mons; n } ed[maxn]; n int main() { n   scanf( %d%d , &m, &n); n   for (int i = (1); i <= (n); ++i) dis[i] = INF; n   for (int i = (0); i < (m); ++i) { n     scanf( %d%d , &ed[i].from, &ed[i].l); n     for (int j = (0); j < (ed[i].l); ++j) { n       int v; n       scanf( %d , &v); n       if (!~v) { n         ++ed[i].dia; n         continue; n       } n       ed[i].mons.push_back(v); n       have[v].push_back(i); n     } n     if (!ed[i].mons.size()) { n       dis[ed[i].from] = min(dis[ed[i].from], ed[i].dia); n     } n   } n   for (int i = (1); i <= (n); ++i) n     if (dis[i] != INF) pq.push(make_pair(dis[i], i)); n   for (; !pq.empty(); pq.pop()) { n     int u = pq.top().second, d = pq.top().first; n     if (d != dis[u]) continue; n     for (int i = (0); i < (have[u].size()); ++i) { n       int id = have[u][i]; n       ++ed[id].cur; n       if (ed[id].cur == ed[id].mons.size()) { n         int v = ed[id].from; n         int w = ed[id].dia; n         for (int j = (0); j < (ed[id].mons.size()); ++j) { n           w += dis[ed[id].mons[j]]; n           w = min(w, MAX); n         } n         if (w < dis[v]) { n           dis[v] = w; n           pq.push(make_pair(dis[v], v)); n         } n       } n     } n   } n   for (int i = (0); i < (m); ++i) { n     bool ok = true; n     ed[i].cur = 0; n     for (int j = (0); j < (ed[i].mons.size()); ++j) n       ok &= (dis[ed[i].mons[j]] != INF); n     if (ok) ++tot[ed[i].from]; n   } n   for (int i = (1); i <= (n); ++i) n     if (dis[i] != INF && !tot[i]) q.push(i); n   for (int i = (0); i < (m); ++i) { n     if (!ed[i].mons.size() && dis[ed[i].from] != INF) { n       int w = ed[i].dia; n       for (int j = (0); j < (ed[i].mons.size()); ++j) { n         w += dis[ed[i].mons[j]]; n         w = min(w, MAX); n       } n       dp[ed[i].from] = max(dp[ed[i].from], w); n       --tot[ed[i].from]; n       if (!tot[ed[i].from]) { n         q.push(ed[i].from); n       } n     } n   } n   for (; !q.empty(); q.pop()) { n     int u = q.front(); n     for (int i = (0); i < (have[u].size()); ++i) { n       int id = have[u][i]; n       int v = ed[id].from; n       if (dis[v] != INF) { n         sum[id] += dp[u]; n         sum[id] = min(sum[id], MAX); n         ++ed[id].cur; n         if (ed[id].cur == ed[id].mons.size()) { n           dp[v] = max(dp[v], min(MAX, sum[id] + ed[id].dia)); n           --tot[v]; n           if (!tot[v]) q.push(v); n         } n       } n     } n   } n   for (int i = (1); i <= (n); ++i) { n     if (dis[i] == INF) { n       puts( -1 -1 ); n     } else { n       printf( %d  , dis[i]); n       if (!tot[i]) n         printf( %d , dp[i]); n       else n         printf( -2 ); n       puts(  ); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MOD = 1e9 + 7; n const int SIZE = 1e6 + 10; n using namespace std; n struct E { n   int k, c; n   E() {} n   E(int _k, int _c) : k(_k), c(_c) {} n } es[4200010]; n struct Flow { n   int n, m, dis[500010]; n   int qq[500010], qr, ql; n   vector<int> e[500010]; n   void init(int _n) { n     n = _n; n     m = 0; n     for (int i = 0; i < n; i++) e[i] = vector<int>(); n   } n   void add_edge(int a, int b, int c) { n     e[a].push_back(m); n     es[m] = E(b, c); n     m++; n     e[b].push_back(m); n     es[m] = E(a, 0); n     m++; n   } n   bool BFS() { n     memset(dis, -1, n * sizeof(int)); n     ql = qr = 0; n     qq[qr++] = 0; n     dis[0] = 0; n     while (ql != qr && dis[n - 1] == -1) { n       int p = qq[ql++]; n       for (__typeof((e[p]).begin()) it = (e[p]).begin(); it != (e[p]).end(); n            it++) { n         E ee = es[*it]; n         if (ee.c == 0 || dis[ee.k] != -1) continue; n         dis[ee.k] = dis[p] + 1; n         qq[qr++] = ee.k; n       } n     } n     return dis[n - 1] != -1; n   } n   long long go(int p, long long c) { n     if (p == n - 1) return c; n     long long ret = 0, tmp; n     for (__typeof((e[p]).begin()) it = (e[p]).begin(); it != (e[p]).end(); n          it++) { n       E &ee = es[*it]; n       if (ee.c == 0 || dis[p] + 1 != dis[ee.k]) continue; n       tmp = go(ee.k, min(c - ret, (long long)ee.c)); n       ret += tmp; n       ee.c -= tmp; n       es[(*it) ^ 1].c += tmp; n       if (ret == c) break; n     } n     if (ret == 0) dis[p] = -1; n     return ret; n   } n   long long maxflow() { n     long long ret = 0; n     while (BFS()) ret += go(0, 1LL << 60); n     return ret; n   } n } flow; n vector<int> cc[301][301], cn[301]; n int need_id, an[301], xx[301], yy[301]; n pair<int, int> need[1000001]; n int to[301]; n bool used[301]; n bool match(pair<int, int> X, pair<int, int> Y) { n   if (X.first != Y.first && Y.first != -1) return 0; n   if (X.second != Y.second && Y.second != -1) return 0; n   return 1; n } n void go(int ma_id, int ma_hi, int n) { n   if (ma_id != 1 && ((int)(cc[ma_id][0]).size()) == 0) return; n   vector<pair<int, int> > qq; n   int oo = need_id; n   for (int i = ma_hi; i >= 0; i--) { n     if (((int)(cc[ma_id][i]).size()) == 0) { n       need[++need_id] = make_pair(ma_id, i); n       cc[ma_id][i].push_back(-need_id); n       qq.push_back(make_pair(ma_id, i)); n     } n   } n   if (need_id > n) { n     for (int i = 0; i < (((int)(qq).size())); ++i) n       cc[qq[i].first][qq[i].second].pop_back(); n     need_id = oo; n     return; n   } n   flow.init(need_id + n + 2); n   for (int i = (1); i < (n + 1); ++i) n     flow.add_edge(need_id + i, need_id + n + 1, 1); n   for (int i = (1); i < (need_id + 1); ++i) { n     flow.add_edge(0, i, 1); n     for (int j = (1); j < (n + 1); ++j) { n       if (used[j]) continue; n       if (match(need[i], make_pair(yy[j], xx[j]))) n         flow.add_edge(i, need_id + j, 1); n     } n   } n   if (flow.maxflow() != need_id) { n     need_id = oo; n     return; n   } n   for (int i = 0; i < flow.m; i += 2) { n     if (es[i].k > need_id && es[i + 1].k <= need_id && es[i].c == 0) { n       used[es[i].k - need_id] = 1; n       to[es[i + 1].k] = es[i].k - need_id; n     } n   } n   for (int i = (1); i < (n + 1); ++i) { n     for (int j = 0; j < (n); ++j) { n       for (int k = 0; k < (((int)(cc[i][j]).size())); ++k) { n         if (cc[i][j][k] < 0) cc[i][j][k] = to[-cc[i][j][k]]; n       } n     } n   } n   for (int i = (1); i < (n + 1); ++i) { n     if (!used[i]) { n       used[i] = 1; n       if (xx[i] == -1 && yy[i] == -1) n         cc[1][0].push_back(i); n       else if (yy[i] != -1) n         cc[yy[i]][1].push_back(i); n       else if (xx[i] != -1) { n         if (xx[i] == 0) n           cc[1][0].push_back(i); n         else n           cc[ma_id][xx[i]].push_back(i); n       } n     } n   } n   for (int i = (1); i < (n + 1); ++i) { n     for (int j = 0; j < (((int)(cc[i][0]).size())); ++j) { n       if (j % i == 0) n         an[cc[i][0][j]] = cc[i][0][j + i - 1]; n       else n         an[cc[i][0][j]] = cc[i][0][j - 1]; n     } n     for (int j = (1); j < (n); ++j) { n       for (int k = 0; k < (((int)(cc[i][j]).size())); ++k) n         an[cc[i][j][k]] = cc[i][j - 1][0]; n     } n   } n   for (int i = (1); i < (n + 1); ++i) printf( %d%c , an[i],    n [i == n]); n   exit(0); n } n int main() { n   int(n); n   scanf( %d , &n); n   int ma_hi = -1; n   for (int i = (1); i < (n + 1); ++i) { n     char s1[20], s2[20]; n     scanf( %s , (s1)); n     scanf( %s , (s2)); n     int x = -1, y = -1; n     if (s1[0] !=  ? ) x = atoi(s1); n     if (s2[0] !=  ? ) y = atoi(s2); n     if (x != -1 && y != -1) { n       cc[y][x].push_back(i); n       used[i] = 1; n     } else if (y != -1) n       cn[y].push_back(i); n     xx[i] = x; n     yy[i] = y; n     ma_hi = max(ma_hi, x); n   } n   int mi = 10000, ma_id = 1; n   for (int i = (1); i < (n + 1); ++i) { n     int hi = n - 1; n     while (hi >= 0 && ((int)(cc[i][hi]).size()) == 0) hi--; n     while (hi >= 0) { n       if (!((int)(cc[i][hi]).size())) { n         need[++need_id] = make_pair(i, hi); n         cc[i][hi].push_back(-need_id); n       } n       hi--; n     } n     if (((int)(cn[i]).size()) && ((int)(cc[i][0]).size()) == 0) { n       need[++need_id] = make_pair(i, 0); n       cc[i][0].push_back(-need_id); n     } n     while (((int)(cc[i][0]).size()) % i) { n       need[++need_id] = make_pair(i, 0); n       cc[i][0].push_back(-need_id); n     } n   } n   for (int ker = 1; ker <= n; ker++) { n     go(ker, ma_hi, n); n   } n   return 0 * puts( -1 ); n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n istream& operator>>(istream& is, vector<T>& v) { n   for (T& x : v) is >> x; n   return is; n } n template <typename T> n ostream& operator<<(ostream& os, const vector<T>& v) { n   for (int i = 0; i < (int)v.size(); i++) { n     os << v[i] << (i + 1 == (int)v.size() ?    :    ); n   } n   return os; n } n template <typename T, typename U> n ostream& operator<<(ostream& os, const pair<T, U>& p) { n   os <<  (  << p.first <<  ,  << p.second <<  ) ; n   return os; n } n template <typename T, typename U, typename V> n ostream& operator<<(ostream& os, const tuple<T, U, V>& t) { n   os <<  (  << get<0>(t) <<  ,  << get<1>(t) <<  ,  << get<2>(t) <<  ) ; n   return os; n } n template <typename T, typename U, typename V, typename W> n ostream& operator<<(ostream& os, const tuple<T, U, V, W>& t) { n   os <<  (  << get<0>(t) <<  ,  << get<1>(t) <<  ,  << get<2>(t) <<  ,  n      << get<3>(t) <<  ) ; n   return os; n } n template <typename T, typename U> n ostream& operator<<(ostream& os, const map<T, U>& m) { n   os <<  { ; n   for (auto itr = m.begin(); itr != m.end();) { n     os <<  (  << itr->first <<  ,  << itr->second <<  ) ; n     if (++itr != m.end()) os <<  , ; n   } n   os <<  } ; n   return os; n } n template <typename T, typename U> n ostream& operator<<(ostream& os, const unordered_map<T, U>& m) { n   os <<  { ; n   for (auto itr = m.begin(); itr != m.end();) { n     os <<  (  << itr->first <<  ,  << itr->second <<  ) ; n     if (++itr != m.end()) os <<  , ; n   } n   os <<  } ; n   return os; n } n template <typename T> n ostream& operator<<(ostream& os, const set<T>& s) { n   os <<  { ; n   for (auto itr = s.begin(); itr != s.end();) { n     os << *itr; n     if (++itr != s.end()) os <<  , ; n   } n   os <<  } ; n   return os; n } n template <typename T> n ostream& operator<<(ostream& os, const multiset<T>& s) { n   os <<  { ; n   for (auto itr = s.begin(); itr != s.end();) { n     os << *itr; n     if (++itr != s.end()) os <<  , ; n   } n   os <<  } ; n   return os; n } n template <typename T> n ostream& operator<<(ostream& os, const unordered_set<T>& s) { n   os <<  { ; n   for (auto itr = s.begin(); itr != s.end();) { n     os << *itr; n     if (++itr != s.end()) os <<  , ; n   } n   os <<  } ; n   return os; n } n template <typename T> n ostream& operator<<(ostream& os, const deque<T>& v) { n   for (int i = 0; i < (int)v.size(); i++) { n     os << v[i] << (i + 1 == (int)v.size() ?    :    ); n   } n   return os; n } n void debug_out() { cerr <<   n ; } n template <class Head, class... Tail> n void debug_out(Head&& head, Tail&&... tail) { n   cerr << head; n   if (sizeof...(Tail) > 0) cerr <<  ,  ; n   debug_out(move(tail)...); n } n template <typename T> n T gcd(T x, T y) { n   return y != 0 ? gcd(y, x % y) : x; n } n template <typename T> n T lcm(T x, T y) { n   return x / gcd(x, y) * y; n } n template <class T1, class T2> n inline bool chmin(T1& a, T2 b) { n   if (a > b) { n     a = b; n     return true; n   } n   return false; n } n template <class T1, class T2> n inline bool chmax(T1& a, T2 b) { n   if (a < b) { n     a = b; n     return true; n   } n   return false; n } n const int INF = 1e9; n const long long IINF = 1e18; n const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1}; n const char dir[4] = { D ,  R ,  U ,  L }; n const long long MOD = 1000000007; n vector<bool> binary_conversion(const string& s) { n   using u64 = uint64_t; n   vector<u64> num(s.size() / 9 + 10, 0); n   for (size_t i = 0; i < s.size(); i += 9) { n     const string t = s.substr(i, 9); n     u64 add = 0, mul = 1; n     for (const auto c : t) { n       add = add * 10 + (c -  0 ); n       mul *= 10; n     } n     for (auto& d : num) { n       d = d * mul + add; n       add = d >> 32; n       d -= add << 32; n     } n   } n   vector<bool> res(num.size() * 32); n   for (size_t i = 0; i < num.size(); i++) { n     for (size_t j = 0; j < 32; j++) { n       res[i * 32 + j] = num[i] >> j & 1; n     } n   } n   while (!res.empty() && !res.back()) res.pop_back(); n   return res; n }; n namespace n91 { n using usize = std::size_t; n using u64 = std::uint64_t; n std::vector<bool> stob(std::string s) { n   std::vector<u64> num(s.size() / 9 + 10, 0); n   for (usize i = 0; i < s.size(); i += 9) { n     const std::string t = s.substr(i, 9); n     u64 mul = 1; n     u64 add = 0; n     for (const auto c : t) { n       add = add * 10 + (c -  0 ); n       mul *= 10; n     } n     for (auto& d : num) { n       d = d * mul + add; n       add = d >> 32; n       d -= add << 32; n     } n   } n   std::vector<bool> res(num.size() * 32); n   for (usize i = 0; i < num.size(); ++i) { n     for (usize j = 0; j < 32; ++j) { n       res[i * 32 + j] = num[i] >> j & 1; n     } n   } n   while (!res.empty() && !res.back()) { n     res.pop_back(); n   } n   return res; n } n }  // namespace n91 n const int MAX = 2048; n using u64 = uint64_t; n using BS = bitset<2 * MAX>; n BS calc(const string& s) { n   BS res; n   vector<bool> v = binary_conversion(s); n   for (int i = 0; i < v.size(); i++) { n     if (v[i]) { n       res.set(i, 1); n     } n   } n   return res; n } n vector<BS> bases; n vector<int> idx(MAX, -1); n vector<int> solve(BS b, int x) { n   for (int i = MAX - 1; i >= 0; i--) { n     if (!b[i]) continue; n     if (~idx[i]) n       b ^= bases[idx[i]]; n     else { n       b.set(MAX + x, 1); n       idx[i] = bases.size(); n       bases.emplace_back(b); n       return {}; n     } n   } n   vector<int> res; n   for (int i = 0; i < MAX; i++) { n     if (b[MAX + i]) { n       res.emplace_back(i); n     } n   } n   return res; n }; n int main() { n   cin.tie(0); n   ios::sync_with_stdio(false); n   int m; n   cin >> m; n   for (int i = 0; i < m; i++) { n     string S; n     cin >> S; n     vector<int> ans = solve(calc(S), i); n     cout << ans.size(); n     for (int x : ans) cout <<     << x; n     cout <<   n ; n   } n   return 0; n } n


#include<bits/stdc++.h> n using namespace std; n #define ll long long n #define pb push_back n #define fi first n #define se second n #define pii pair<int,int>  n  n void solve() { n     int n, m; n     cin>>n>>m; n     vector<int> a(n), b(n), c(m), vis(n, 1); n     int cnt = 0; n     for(int i=0;i<n;i++) cin>>a[i]; n     for(int i=0;i<n;i++) { n         cin>>b[i]; n         if(a[i] != b[i]) { n             vis[i] = 0; n             cnt++; n         }     n          n     } n     vector<vector<int>> arr(n); n     for(int i=0;i<m;i++) { n         cin>>c[i]; n         arr[c[i] - 1].pb(i); n     } n     if(cnt > m) { n         cout<< NO ; n         return ; n     } n     vector<int> ans(m, -1); n     for(int i=0;i<n;i++) { n         if(a[i] != b[i]) { n             if(arr[b[i] - 1].empty()) { n                 cout<< NO ; n                 return ; n             } n             else { n                 ans[arr[b[i] - 1].back()] = i; n                 arr[b[i] - 1].pop_back();  n             } n         } n     } n     for(int i=0;i<n;i++) { n         if(a[i] == b[i]) { n             if(!arr[b[i] - 1].empty())  { n                 ans[arr[b[i] - 1].back()] = i; n                 arr[b[i] - 1].pop_back();  n             } n         } n     } n     int last = ans[m-1]; n     for(int i=m-2;i>=0;i--) { n         if(last != -1) { n             if(ans[i] == -1) { n                 ans[i] = last; n             }  n             else last = ans[i]; n         } n         else last = ans[i]; n     } n     for(int i=0;i<m;i++) { n         if(ans[i] == -1) { n             cout<< NO ; n             return ; n         } n     } n     cout<< YES <<  n ; n     for(int i=0;i<m;i++) cout<<ans[i] + 1<<   ;  n } n  n int main() { n     int t = 1; n     cin>>t; n     while(t--) { n         solve(); n         cout<<  n ; n     } n     return 0; n } n  n


#include  list  n #include <iostream> n #include <utility> n #include <vector> n #include  fstream  n #include <fstream> n #include <map> n #include  algorithm  n #include <iomanip> n #include  cmath  n #include  set  n #include <climits> n #include  queue  n #include  complex  n  n #define all(x) (x).begin(), (x).end() n #define ll long long n using namespace std; n long long mod = 1e9 + 7; n void solve() { n     int n, k; n     cin >> n >> k; n     long long res = 1; n     for (int i = 0; i < k; ++i) { n         res *= n; n         res %= mod; n     } n     cout << res << endl; n } n signed main() { n     int n; n     cin >> n; n     while (n--) solve(); n  n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX_N = 1e6 + 200, RANGE = 1e6 + 20; n const long long INF = 0x3f3f3f3f3f3f3f3f; n int n, m, p; n long long pre_min[MAX_N], nodes[MAX_N << 2], tag[MAX_N << 2]; n pair<int, int> ai[MAX_N], bi[MAX_N]; n struct tup { n   int x, y, z; n   bool operator<(const tup &rhs) const { n     return x < rhs.x || (x == rhs.x && y < rhs.y); n   } n } tups[MAX_N]; n void pushdown(int p) { n   if (tag[p] != 0) { n     tag[(p << 1)] += tag[p], tag[((p << 1) | 1)] += tag[p]; n     nodes[(p << 1)] += tag[p], nodes[((p << 1) | 1)] += tag[p]; n     tag[p] = 0; n   } n } n void pushup(int p) { nodes[p] = max(nodes[(p << 1)], nodes[((p << 1) | 1)]); } n void update(int ql, int qr, int l, int r, int p, long long val) { n   if (ql <= l && r <= qr) return (void)(nodes[p] += val, tag[p] += val); n   pushdown(p); n   if (ql <= ((l + r) >> 1)) update(ql, qr, l, ((l + r) >> 1), (p << 1), val); n   if (((l + r) >> 1) < qr) n     update(ql, qr, ((l + r) >> 1) + 1, r, ((p << 1) | 1), val); n   pushup(p); n } n int main() { n   scanf( %d%d%d , &n, &m, &p); n   for (int i = 1; i <= n; i++) scanf( %d%d , &ai[i].first, &ai[i].second); n   for (int i = 1; i <= m; i++) scanf( %d%d , &bi[i].first, &bi[i].second); n   for (int i = 1; i <= p; i++) n     scanf( %d%d%d , &tups[i].x, &tups[i].y, &tups[i].z), tups[i].y++, n         tups[i].x++; n   sort(ai + 1, ai + 1 + n), sort(bi + 1, bi + 1 + m), n       sort(tups + 1, tups + 1 + p); n   pre_min[m + 1] = INF; n   for (int i = m; i >= 1; i--) n     pre_min[i] = min(pre_min[i + 1], 1LL * bi[i].second); n   int last_pos = 1; n   for (int i = 1; i <= m; i++) n     update(last_pos, bi[i].first, 1, RANGE, 1, -pre_min[i]), n         last_pos = bi[i].first + 1; n   update(last_pos, RANGE, 1, RANGE, 1, -INF); n   long long ans = -INF; n   for (int i = 1, ptr = 1; i <= n; i++) { n     int pos = ai[i].first, cost = ai[i].second; n     while (ptr <= p && tups[ptr].x <= pos) n       update(tups[ptr].y, RANGE, 1, RANGE, 1, tups[ptr].z), ptr++; n     ans = max(ans, nodes[1] - cost); n   } n   printf( %lld n , ans); n   return 0; n } n


#include <bits/stdc++.h> n #include <unordered_map> n #include <cctype> n #include <string.h> n  n #define PB push_back n #define EB emplace_back  n #define MP make_pair n #define endl   n  n #define ll long long n #define ull unsigned long long n #define STR string n #define VEC vector<int> n #define IOS {ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);} n #define loop(i,a,b,c) for(ll i=a;i<b;i+=c) n #define MOD (int)1000000007 n #define sp     n #define pii pair<int,int> n  n  n using namespace std; n using namespace std::chrono; n  n /* Debugging */ n template <typename T> n void printarr(T *A, int n){ n   for (int i = 0; i < n; i++) n   { n     cout<<A[i]<<   ; n   } n   cout<<endl;   n } n template <typename T> n void arrinit(T *A, int n, T data){ n   for (int i = 0; i < n; i++) n   { n     A[i] = data; n   } n    n } n template <typename T> n void takeinput(T *A, int n){ n   for(int i=0;i<n;i++){ n     cin>>A[i]; n   } n } n template <typename T> n void printcont(T A){ n   for(auto a: A){ n     cout<<a+1<<   ; n   } n   cout<<endl; n } n template <typename T> n T binpowmod(T a, T b, T p){ n   if(b==0) return 1; n   if(b==1) return a; n   if(b%2==0) return ((binpowmod(a,b/2,p)%p)*(binpowmod(a,b/2,p)%p))%p; n   return ((a%p)*(binpowmod(a,b-1,p)%p))%p; n } n // template <typename T> n // T gcd(T a,T b){ n //   if(a==0) return b; n //   if(b==0) return a; n //   if(a>b) return gcd(b,a%b); n //   return gcd(b%a,a); 1 2 3 4  => 1 2  n // } n  n void solve (){ n   int n; n   cin>>n; n   int k = n; n   vector <pii> steps{}; n   if(n<=8){ n     for (int i = 3; i < n; i++) n     { n         steps.PB({i,i+1}); n     } n     while(n!=1){ n         steps.PB({k,2}); n         if(n%2==1) n = n/2 + 1; n         else n/=2; n     }   n   } n   else{ n     for (int i = 3; i < n; i++) n     { n         if(i!=8)steps.PB({i,i+1}); n     } n     while(n!=1){ n         steps.PB({k,8}); n         if(n%8!=0) n = n/8 + 1; n         else n = n/8; n     } n     steps.PB({8,2}); n     steps.PB({8,2}); n     steps.PB({8,2}); n   } n   cout<<steps.size()<<endl; n   for (int i = 0; i < steps.size(); i++) n   { n       cout<<steps[i].first<<   <<steps[i].second<<endl; n   } n    n    n } n  n int main(){ n     auto start = high_resolution_clock::now();  n     IOS n     // freopen( input.txt , r ,stdin); n     // freopen( output.txt , w ,stdout); n     // freopen( output.txt , w ,stderr); n     ll t; n     cin>>t;   n     while(t--){ n       solve(); n     } n     auto stop = high_resolution_clock::now();  n     auto duration = duration_cast<milliseconds>(stop - start);  n     // cout << Time taken :  <<duration.count() <<  milliseconds n ; n     return 0; n }


#include <bits/stdc++.h> n int main() { n   long long n; n   scanf( %lld , &n); n   if (n <= 1) { n     printf( -1 ); n   } else { n     printf( %lld %lld %lld , n, n + 1, n * (n + 1)); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n class T { n  private: n   long node[262145]; n   long low[262145]; n   long high[262145]; n   void update(long n); n   long amount(long a, long b, long n, long n_a, long n_b); n   long firstUp(long k, long n, long n_a, long n_b); n   long firstDown(long k, long n, long n_a, long n_b); n  n  public: n   long amount(long a, long b); n   long firstUp(long k); n   long firstDown(long k); n   void pop(long n); n   void push(long n); n   long size(); n   T(); n } WaitTree, DestTree; n T::T() { n   for (long i = 0; i < 262145; i++) { n     low[i] = 1000000000; n     high[i] = -1000000000; n   } n } n long T::size() { return node[1]; } n long T::amount(long a, long b, long n, long n_a, long n_b) { n   if (a > n_b || b < n_a) return 0; n   if (n_a >= a && n_b <= b) return node[n]; n   return amount(a, b, 2 * n, n_a, (n_a + n_b) / 2) + n          amount(a, b, 2 * n + 1, (n_a + n_b) / 2 + 1, n_b); n } n long T::firstDown(long k, long n, long n_a, long n_b) { n   if (node[n] == 0 || n_a > k) return -1000000000; n   if (n > 131071) return n - 131071; n   if (n_b > k) { n     long a = firstDown(k, 2 * n + 1, (n_a + n_b) / 2 + 1, n_b); n     if (a > 0) return a; n     return firstDown(k, 2 * n, n_a, (n_a + n_b) / 2); n   } else n     return high[n]; n } n long T::firstUp(long k, long n, long n_a, long n_b) { n   if (node[n] == 0 || n_b < k) return 1000000000; n   if (n > 131071) return n - 131071; n   if (n_a < k) { n     long a = firstUp(k, 2 * n, n_a, (n_a + n_b) / 2); n     if (a < 1000000000) return a; n     return firstUp(k, 2 * n + 1, (n_a + n_b) / 2 + 1, n_b); n   } else n     return low[n]; n } n long T::firstUp(long k) { return firstUp(k, 1, 1, 131071 + 1); } n long T::firstDown(long k) { return firstDown(k, 1, 1, 131071 + 1); } n long T::amount(long a, long b) { return amount(a, b, 1, 1, 131071 + 1); } n void T::update(long n) { n   n /= 2; n   while (n > 0) { n     low[n] = (low[2 * n + 1] < low[2 * n] ? low[2 * n + 1] : low[2 * n]); n     high[n] = (high[2 * n] > high[2 * n + 1] ? high[2 * n] : high[2 * n + 1]); n     node[n] = node[2 * n] + node[2 * n + 1]; n     n /= 2; n   } n } n void T::pop(long n) { n   node[131071 + n]--; n   if (node[131071 + n] == 0) { n     low[131071 + n] = 1000000000; n     high[131071 + n] = -1000000000; n   } n   update(131071 + n); n } n void T::push(long n) { n   high[131071 + n] = n; n   low[131071 + n] = n; n   node[131071 + n]++; n   update(131071 + n); n } n struct A { n   long id; n   long time, wait, dest; n }; n bool operator<(const A &a, const A &b) { return a.time < b.time; } n vector<A> P(100005); n class X { n  public: n   long id, floor; n   X(long _id, long _floor); n }; n X::X(long _id, long _floor) { n   id = _id; n   floor = _floor; n } n vector<X> Waiting[100005]; n vector<X> Dest[100005]; n long long Arrive[100005]; n long Arrived; n long N, M; n void in() { n   scanf( %ld %ld , &N, &M); n   for (long i = 0; i < N; i++) { n     scanf( %ld %ld %ld , &P[i].time, &P[i].wait, &P[i].dest); n     P[i].id = i; n   } n   sort(P.begin(), P.begin() + N); n } n void processEvent(long f, long long t, long &nextP) { n   X x(0, 0); n   while (P[nextP].time == t && nextP < N) { n     Waiting[P[nextP].wait].push_back(X(P[nextP].id, P[nextP].dest)); n     WaitTree.push(P[nextP].wait); n     nextP++; n   } n   while (Waiting[f].size() > 0) { n     x = Waiting[f].back(); n     Dest[x.floor].push_back(X(x.id, x.floor)); n     WaitTree.pop(f); n     DestTree.push(x.floor); n     Waiting[f].pop_back(); n   } n   while (Dest[f].size() > 0) { n     x = Dest[f].back(); n     Arrive[x.id] = t; n     Arrived++; n     DestTree.pop(f); n     Dest[f].pop_back(); n   } n } n void solve() { n   const int UP = 1; n   const int DOWN = 2; n   int dir; n   long nextMove; n   long nextP = 0; n   long p_up, p_down; n   long f = 1; n   long long t = 0; n   while (Arrived < N) { n     processEvent(f, t, nextP); n     p_up = p_down = 0; n     p_up += WaitTree.amount(f, 131071 + 1); n     p_up += DestTree.amount(f, 131071 + 1); n     p_down += WaitTree.amount(1, f); n     p_down += DestTree.amount(1, f); n     if (p_up >= p_down) n       dir = UP; n     else n       dir = DOWN; n     if (dir == UP) { n       nextMove = 1000000000; n       nextMove = (nextMove < WaitTree.firstUp(f) - f ? nextMove n                                                      : WaitTree.firstUp(f) - f); n       nextMove = (nextMove < DestTree.firstUp(f) - f ? nextMove n                                                      : DestTree.firstUp(f) - f); n       if (nextP < N) n         nextMove = n             (nextMove < P[nextP].time - t ? nextMove : P[nextP].time - t); n       t += nextMove; n       if (DestTree.size() > 0 || WaitTree.size() > 0) { n         f += nextMove; n       } n     } n     if (dir == DOWN) { n       nextMove = 1000000000; n       nextMove = n           (nextMove < f - WaitTree.firstDown(f) ? nextMove n                                                 : f - WaitTree.firstDown(f)); n       nextMove = n           (nextMove < f - DestTree.firstDown(f) ? nextMove n                                                 : f - DestTree.firstDown(f)); n       if (nextP < N) n         nextMove = n             (nextMove < P[nextP].time - t ? nextMove : P[nextP].time - t); n       t += nextMove; n       if (DestTree.size() > 0 || WaitTree.size() > 0) { n         f -= nextMove; n       } n     } n   } n } n void out() { n   for (long i = 0; i < N; i++) printf( %I64d n , Arrive[i]); n } n int main() { n   in(); n   solve(); n   out(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n inline T abs(T a) { n   return ((a < 0) ? -a : a); n } n template <typename T> n inline T sqr(T a) { n   return a * a; n } n const int INF = (int)1E9 + 7; n const long double EPS = 1E-10; n const long double PI = 3.1415926535897932384626433832795; n int n; n vector<long double> a; n bool check(const vector<long double>& a) { n   if (int((a).size()) <= 1) return true; n   if (fabs(a[0]) < EPS) { n     for (int i = 0; i < int(int((a).size())); ++i) n       if (fabs(a[i]) > EPS) return false; n     return true; n   } n   long double b = a[1] / a[0], cur = a[0]; n   for (int i = 0; i < int(int((a).size())); ++i) { n     if (fabs(a[i] - cur) > EPS) return false; n     cur *= b; n   } n   return true; n } n vector<int> getz(const vector<long double>& a) { n   vector<int> z(int((a).size())); n   int l = 0, r = -1; n   for (int i = int(1); i < int(int((a).size())); ++i) { n     z[i] = i > r ? 0 : min(z[i - l], r - i + 1); n     while (i + z[i] < int((a).size()) && fabs(a[z[i]] - a[i + z[i]]) < EPS) n       z[i]++; n     if (i + z[i] - 1 > r) l = i, r = i + z[i] - 1; n   } n   return z; n } n int main() { n   cin >> n; n   a.resize(n); n   for (int i = 0; i < int(n); ++i) { n     int x; n     scanf( %d , &x); n     a[i] = x; n   } n   if (check(a)) { n     puts( 0 ); n     exit(0); n   } n   for (int i = 0; i < int(2); ++i) { n     vector<long double> b = a; n     b.erase(b.begin() + i); n     if (check(b)) { n       puts( 1 ); n       exit(0); n     } n   } n   vector<long double> ok(n - 1, 0); n   if (fabs(a[0]) > EPS) { n     long double d = a[1] / a[0]; n     ok[0] = a[0], ok[1] = a[1]; n     for (int i = int(2); i < int(int((ok).size())); ++i) ok[i] = ok[i - 1] * d; n   } n   vector<long double> t1 = ok; n   t1.insert(t1.end(), (a).begin(), (a).end()); n   vector<int> z1 = getz(t1); n   reverse((ok).begin(), (ok).end()); n   reverse((a).begin(), (a).end()); n   ok.insert(ok.end(), (a).begin(), (a).end()); n   vector<int> z2 = getz(ok); n   if (z1[n - 1] + z2[n - 1] >= n - 1) n     puts( 1 ); n   else n     puts( 2 ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void err(istream_iterator<string> it) {} n template <typename T, typename... Args> n void err(istream_iterator<string> it, T a, Args... args) { n   cerr << *it <<   =   << a <<   n ; n   err(++it, args...); n } n const double PI = acos(-1); n const double eps = (1e-9); n const long long int INF = (1e18); n const int M = (1e9) + 7; n const int N = 2050; n const int K = 5250; n int dp[N][N]; n int n, m, k; n vector<pair<int, int> > fire; n int saare[2][N]; n int val[2][N]; n int last[2][N]; n int sz[2]; n void compress(int ind, int n) { n   vector<pair<int, int> > tp(n); n   int i, j, r; n   for (i = 0; i < n; i++) tp[i].first = saare[ind][i], tp[i].second = i; n   sort(tp.begin(), tp.end()); n   i = 0, r = 1, j = 0; n   while (i < n) { n     while (j < n && tp[i].first == tp[j].first) n       saare[ind][tp[j].second] = r, j++; n     val[ind][r++] = tp[i].first; n     if (j < n && tp[i].first + 1 < tp[j].first) n       val[ind][r] = tp[i].first + 1, last[ind][r] = tp[j].first - 1, r++; n     i = j; n   } n   sz[ind] = r; n   return; n } n int build() { n   int i, j, x, y, a, b; n   for (i = 0; i < sz[0]; ++i) { n     for (j = 0; j < sz[1]; ++j) dp[i][j] = 0; n   } n   for (i = 0; i < k; ++i) { n     x = saare[0][i], y = saare[1][i]; n     a = saare[0][i + k], b = saare[1][i + k]; n     dp[x][y] += 1; n     dp[x][b + 1] -= 1; n     dp[a + 1][y] -= 1; n     dp[a + 1][b + 1] += 1; n   } n   for (i = 1; i < sz[0]; ++i) { n     for (j = 1; j < sz[1]; ++j) n       dp[i][j] += (dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1]); n   } n   x = n + 1, a = 0; n   y = m + 1, b = 0; n   for (i = 1; i < sz[0]; ++i) { n     for (j = 1; j < sz[1]; ++j) { n       if (dp[i][j] == 0) { n         x = min(x, val[0][i]); n         a = max(a, val[0][i]); n         a = max(a, last[0][i]); n         y = min(y, val[1][j]); n         b = max(b, val[1][j]); n         b = max(b, last[1][j]); n       } n     } n   } n   int z = max(0, max(a - x, b - y)); n   return z; n } n int check(int t) { n   vector<pair<int, int> > point(2 * k); n   int i, x, y, a, b; n   for (i = 0; i < k; ++i) { n     tie(x, y) = fire[i]; n     a = max(x - t, 1), b = max(y - t, 1); n     point[i] = {a, b}; n     a = min(x + t, n), b = min(y + t, m); n     point[i + k] = {a, b}; n   } n   for (i = 0; i < 2 * k; ++i) tie(saare[0][i], saare[1][i]) = point[i]; n   int s = 2 * k; n   saare[0][s] = 1, saare[1][s] = 1, s++; n   saare[0][s] = n, saare[1][s] = m, s++; n   compress(0, s); n   compress(1, s); n   { n     string _s =  t ; n     replace(_s.begin(), _s.end(),  , ,    ); n     stringstream _ss(_s); n     istream_iterator<string> _it(_ss); n     err(_it, t); n   }; n   int z = build(); n   return (z <= 2 * t); n } n void solve() { n   scanf( %d%d%d , &n, &m, &k); n   fire.resize(k); n   int i; n   for (i = 0; i < k; ++i) scanf( %d%d , &fire[i].first, &fire[i].second); n   int mid, l = 0, r = (max(n, m) / 2); n   while (l < r) { n     mid = ((l + r) >> 1); n     if (check(mid)) n       r = mid; n     else n       l = mid + 1; n   } n   printf( %d n , l); n } n int main() { n   int t; n   t = 1; n   while (t--) solve(); n } n


#include <bits/stdc++.h> n using namespace std; n vector<string> str; n const string di =  .. ; n char ss[500]; n int main() { n   int ti; n   scanf( %d , &ti); n   for (int i = 0; i < ti; i++) { n     scanf( %s , ss); n     if (ss[0] ==  p ) { n       printf( / ); n       for (int i = 0; i < str.size(); i++) printf( %s/ , str[i].c_str()); n       printf(  n ); n     } else { n       scanf( %s , ss); n       if (ss[0] ==  / ) str.clear(); n       char *tmp = strtok(ss,  / ); n       while (tmp != NULL) { n         if (di == tmp) n           str.pop_back(); n         else n           str.push_back(tmp); n         tmp = strtok(NULL,  / ); n       } n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n const long long MOD = 100000000; n const long long MAXN = 2e6 + 20; n struct edge { n   long long from, to, cost; n }; n int main() { n   long long i, j, k, t1, t2, t3, n, m, t; n   std::ios::sync_with_stdio(0); n   cin >> n >> k; n   cout << (k + n - 1) / n <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int i, j, n, a[5002], b, c, d; n   cin >> n; n   cout <<  ?  <<     << 1 <<     << 2 << endl; n   fflush(stdout); n   cin >> b; n   cout <<  ?  <<     << 2 <<     << 3 << endl; n   fflush(stdout); n   cin >> c; n   cout <<  ?  <<     << 1 <<     << 3 << endl; n   fflush(stdout); n   cin >> d; n   a[1] = (b + d - c) / 2; n   a[2] = b - a[1]; n   a[3] = d - a[1]; n   for (i = 4; i <= n; i++) { n     cout <<  ?  <<     << 1 <<     << i << endl; n     fflush(stdout); n     cin >> b; n     a[i] = b - a[1]; n   } n   cout <<  !  <<    ; n   for (i = 1; i <= n; i++) cout << a[i] <<    ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 200000 + 10; n const int hashnum = 3; n long long base[] = {233, 23, 97}; n long long mod[] = {122420729, 1000000007, 1000000009}; n int sum[maxn]; n char s[maxn]; n long long power[hashnum][maxn]; n int n; n struct node { n   long long hv[hashnum]; n   int pref, suf, len; n }; n node zer; n inline void init() { n   zer.pref = zer.suf = zer.len = 0; n   for (int i = (0); i < (hashnum); ++i) zer.hv[i] = 0; n   for (int i = (0); i < (hashnum); ++i) { n     power[i][0] = 1; n     for (int j = (1); j < (maxn); ++j) n       power[i][j] = power[i][j - 1] * base[i] % mod[i]; n   } n } n node merge(node& a, node& b) { n   node c = zer; n   if (a.len == 0 && b.len == 0) n     c.suf = c.pref = a.pref + b.pref; n   else if (a.len == 0) n     c = b, c.pref += a.pref; n   else if (b.len == 0) n     c = a, c.suf += b.pref; n   else { n     c.len = a.len + b.len + (a.suf + b.pref) % 2; n     c.pref = a.pref; n     c.suf = b.suf; n     for (int i = (0); i < (hashnum); ++i) { n       if ((a.suf + b.pref) % 2 == 1) { n         c.hv[i] = a.hv[i] * power[i][b.len + 1] % mod[i]; n         (c.hv[i] += 2 * power[i][b.len] % mod[i]) %= mod[i]; n         (c.hv[i] += b.hv[i]) %= mod[i]; n       } else { n         c.hv[i] = a.hv[i] * power[i][b.len] % mod[i]; n         (c.hv[i] += b.hv[i]) %= mod[i]; n       } n     } n   } n   return c; n } n struct segtree { n   node t[maxn << 2]; n   int n, ql, qr; n   node ans; n   void init(int n) { this->n = n; } n   void maintain(int o) { t[o] = merge(t[o << 1], t[o << 1 | 1]); } n   void build(int l, int r, int o) { n     t[o] = zer; n     if (l == r) { n       if (s[l] ==  0 ) { n         t[o].len++; n         for (int i = (0); i < (hashnum); ++i) t[o].hv[i] = 1; n       } else n         t[o].suf = t[o].pref = 1; n       return; n     } n     int mid = l + r >> 1; n     build(l, mid, o << 1), build(mid + 1, r, o << 1 | 1); n     maintain(o); n   } n   void query(int l, int r, int o) { n     if (ql <= l && qr >= r) n       ans = merge(ans, t[o]); n     else { n       int mid = l + r >> 1; n       if (ql <= mid) query(l, mid, o << 1); n       if (qr > mid) query(mid + 1, r, o << 1 | 1); n     } n   } n   node Query(int l, int r) { n     ans = zer; n     ql = l, qr = r; n     query(1, n, 1); n     return ans; n   } n }; n segtree tree; n bool judge(node& a, node& b) { n   if (a.suf % 2 != b.suf % 2 || a.pref % 2 != b.pref % 2 || a.len != b.len) n     return false; n   for (int i = (0); i < (hashnum); ++i) n     if (a.hv[i] != b.hv[i]) return false; n   return true; n } n int main(void) { n   scanf( %d%s , &n, s + 1); n   init(); n   tree.init(n); n   tree.build(1, n, 1); n   for (int i = (1); i <= (n); ++i) { n     sum[i] = sum[i - 1]; n     if (s[i] ==  1 ) sum[i]++; n   } n   int q; n   scanf( %d , &(q)); n   for (; q--;) { n     int l1, l2, r1, r2, len; n     scanf( %d%d%d , &l1, &l2, &len); n     r1 = l1 + len - 1; n     r2 = l2 + len - 1; n     if (sum[r2] - sum[l2 - 1] != sum[r1] - sum[l1 - 1]) { n       puts( No ); n       continue; n     } n     node x = tree.Query(l1, r1); n     node y = tree.Query(l2, r2); n     if (judge(x, y)) n       puts( Yes ); n     else n       puts( No ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool Notlucky(int x) { n   for (int i = x; i != 0; i /= 10) { n     if (i % 10 == 8 || i % 10 == -8) return false; n   } n   return true; n } n int main() { n   int a, b; n   cin >> a; n   b = a + 1; n   while (Notlucky(b)) { n     b++; n   } n   cout << b - a; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void __print(int x) { cerr << x; } n void __print(long x) { cerr << x; } n void __print(long long x) { cerr << x; } n void __print(unsigned x) { cerr << x; } n void __print(unsigned long x) { cerr << x; } n void __print(unsigned long long x) { cerr << x; } n void __print(float x) { cerr << x; } n void __print(double x) { cerr << x; } n void __print(long double x) { cerr << x; } n void __print(char x) { cerr <<      << x <<     ; } n void __print(const char *x) { cerr <<     << x <<    ; } n void __print(const string &x) { cerr <<     << x <<    ; } n void __print(bool x) { cerr << (x ?  true  :  false ); } n template <typename T, typename V> n void __print(const pair<T, V> &x) { n   cerr <<  { ; n   __print(x.first); n   cerr <<  , ; n   __print(x.second); n   cerr <<  } ; n } n template <typename T> n void __print(const T &x) { n   int f = 0; n   cerr <<  { ; n   for (auto &i : x) cerr << (f++ ?  ,  :   ), __print(i); n   cerr <<  } ; n } n void _print() { cerr <<  ] n ; } n template <typename T, typename... V> n void _print(T t, V... v) { n   __print(t); n   if (sizeof...(v)) cerr <<  ,  ; n   _print(v...); n } n mt19937_64 rnd; n const int N = 2e5 + 5; n void tc() { n   int n; n   cin >> n; n   vector<int> v; n   int p = 1; n   while (n) { n     if (n % 10) { n       v.push_back(n % 10 * p); n     } n     n /= 10; n     p *= 10; n   } n   cout << int((v).size()) <<   n ; n   for (auto x : v) cout << x <<    ; n   cout <<   n ; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   int t; n   cin >> t; n   while (t--) tc(); n   return 0; n } n


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


#include <bits/stdc++.h> n #pragma GCC target( avx,avx2 ) n using namespace std; n using LF = double; n using LL = long long; n using basis = complex<LF>; n const LF PI = acos(-1.0l); n const int N = 125005; n vector<int> rev; n vector<basis> omega; n inline void calc_rev(int n, int log_n) { n   omega.assign(n, 0); n   rev.assign(n, 0); n   for (int i = 0; i < n; i++) { n     rev[i] = 0; n     for (int j = 0; j < log_n; j++) { n       if ((i >> j) & 1) rev[i] |= 1 << (log_n - j - 1); n     } n   } n } n inline void fft(vector<basis> &A, int n, bool invert) { n   for (int i = 0; i < n; i++) { n     if (i < rev[i]) swap(A[i], A[rev[i]]); n   } n   for (int len = 2; len <= n; len <<= 1) { n     LF ang = 2 * PI / len * (invert ? -1 : +1); n     int half = (len >> 1); n     basis curomega(cos(ang), sin(ang)); n     omega[0] = basis(1, 0); n     for (int i = 1; i < half; i++) omega[i] = omega[i - 1] * curomega; n     for (int i = 0; i < n; i += len) { n       basis t; n       int pu = i, pv = i + half, pu_end = i + half, pw = 0; n       for (; pu != pu_end; pu++, pv++, pw++) { n         t = A[pv] * omega[pw]; n         A[pv] = A[pu] - t; n         A[pu] += t; n       } n     } n   } n   if (invert) n     for (int i = 0; i < n; i++) A[i] /= n; n } n inline void multiply(int n, vector<basis> &A, vector<basis> &B, n                      vector<int> &C) { n   fft(A, n, false); n   fft(B, n, false); n   for (int i = 0; i < n; i++) A[i] *= B[i]; n   fft(A, n, true); n   for (int i = 0; i < n; i++) { n     C[i] = (int)(A[i].real() + 0.5); n   } n } n inline void solve(int n, vector<int> &coefficients_of_A, n                   vector<int> &coefficients_of_B, vector<int> &result) { n   vector<basis> A(n), B(n); n   for (int i = 0; i < n; i++) { n     A[i] = coefficients_of_A[i]; n     B[i] = 0; n   } n   for (int i = 0; i < n; i++) { n     B[i] = coefficients_of_B[i]; n   } n   vector<int> C(n); n   multiply(n, A, B, C); n   for (int i = 0; i < n; i++) { n     int add = C[i]; n     result[i] += add; n   } n } n inline void do_FFT(vector<int> &A, vector<int> &B, vector<int> &result) { n   int n = 1, bits = 0; n   while (n < 2 * A.size() || n < 2 * B.size()) { n     n <<= 1, bits++; n   } n   result.assign(n, 0); n   calc_rev(n, bits); n   vector<int> tempA(A.begin(), A.end()); n   vector<int> tempB(B.begin(), B.end()); n   tempA.resize(n); n   tempB.resize(n); n   solve(n, tempA, tempB, result); n } n int n, m; n string S, T; n vector<int> indexes[6][2]; n vector<int> graph[N][6]; n int visited[6]; n int dfs(int u, int v) { n   int ans = 1; n   visited[v] = 1; n   for (auto k : graph[u][v]) { n     if (!visited[k]) ans += dfs(u, k); n   } n   return ans; n } n int work(int curr_position) { n   int ans = 0; n   memset(visited, 0, sizeof(visited)); n   for (int i = 0; i < 6; i++) { n     if (!visited[i]) ans += dfs(curr_position, i) - 1; n   } n   return ans; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   cin >> S >> T; n   int i, j; n   n = S.size(); n   m = T.size(); n   for (i = 0; i <= n - 1; i++) { n     indexes[S[i] -  a ][0].push_back(i); n   } n   for (j = 0; j <= m - 1; j++) { n     indexes[T[j] -  a ][1].push_back(j); n   } n   for (i = 0; i <= 5; i++) { n     for (j = 0; j <= 5; j++) { n       if (i == j) continue; n       vector<int> polynomial1(n + 1, 0), polynomial2(m, 0); n       for (int x : indexes[i][0]) polynomial1[x] = 1; n       for (int x : indexes[j][1]) polynomial2[m - 1 - x] = 1; n       vector<int> res; n       do_FFT(polynomial1, polynomial2, res); n       for (int k = 0; k < n - m + 1; k++) { n         if (res[m - 1 + k]) { n           graph[k][i].push_back(j); n           graph[k][j].push_back(i); n         } n       } n     } n   } n   for (i = 0; i <= n - m; i++) { n     cout << work(i) <<    ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<pair<int, int> > a[60]; n int c[60], d[60], e[60]; n int main() { n   int i, j, k, m, n; n   double w; n   while (scanf( %d%lf%d , &n, &w, &m) != EOF) { n     for (i = 0; i < n; i++) d[i] = m; n     memset(c, 0, sizeof(c)); n     k = 0; n     int f = 0; n     for (i = 0; i < m; i++) a[i].clear(); n     for (i = 0; i < n; i++) { n       int cnt = 0; n       while (d[i] > 0) { n         if (d[i] >= n - c[k]) { n           a[k].push_back(make_pair(i, n - c[k])); n           d[i] -= n - c[k]; n           c[k] = n; n           k++; n         } else { n           a[k].push_back(make_pair(i, d[i])); n           c[k] += d[i]; n           d[i] = 0; n         } n         cnt++; n       } n       if (cnt > 2) f = 1; n     } n     if (f) { n       puts( NO ); n       continue; n     } n     puts( YES ); n     for (i = 0; i < m; i++) { n       for (j = 0; j < a[i].size(); j++) { n         printf( %d %.10lf%c , a[i][j].first + 1, a[i][j].second * w / m, n                j < a[i].size() - 1 ?     :   n ); n       } n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long N, i, j, k, a, b; n long long gcd(long long a, long long b) { n   long long t; n   while (b > 0) { n     t = b; n     b = a % b; n     a = t; n   } n   return a; n } n long long lcm(long long a, long long b, long long c) { n   long long d = a * b / gcd(a, b); n   return c * d / gcd(c, d); n } n int main() { n   scanf( %I64d , &N); n   for (i = max(1ll, N - 100); i <= N; i++) { n     for (j = i; j <= N; j++) { n       for (k = j; k <= N; k++) { n         b = lcm(i, j, k); n         if (b > a) a = b; n       } n     } n   } n   printf( %I64d n , a); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e5 + 5; n const int INF = 0x3f3f3f3f; n int vis[105]; n int main() { n   string s; n   cin >> s; n   int len = s.size(); n   int ans = 0; n   for (int i = 0; i < len - 1; i++) { n     if (s[i] ==  V  && s[i + 1] ==  K ) ans++; n   } n   for (int i = 0; i < len; i++) { n     char ch = s[i]; n     s[i] =  V ; n     int temp = 0; n     for (int j = 0; j < len - 1; j++) { n       if (s[j] ==  V  && s[j + 1] ==  K ) temp++; n     } n     s[i] = ch; n     ans = max(ans, temp); n   } n   for (int i = 0; i < len; i++) { n     char ch = s[i]; n     s[i] =  K ; n     int temp = 0; n     for (int j = 0; j < len - 1; j++) { n       if (s[j] ==  V  && s[j + 1] ==  K ) temp++; n     } n     s[i] = ch; n     ans = max(ans, temp); n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int m, n, q, a[13][110005], id; n bitset<4100> s[110005]; n inline int read() { n   int ret = 0, ff = 1; n   char ch = getchar(); n   while (!isdigit(ch)) { n     if (ch ==  - ) ff = -1; n     ch = getchar(); n   } n   while (isdigit(ch)) { n     ret = (ret << 3) + (ret << 1) + (ch ^ 48); n     ch = getchar(); n   } n   return ret * ff; n } n signed main() { n   m = read(), n = read(), q = read(); n   id = n; n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= m; j++) a[i][j] = read(); n     for (int j = 0; j < (1 << n); j++) n       if (j & (1 << (i - 1))) s[i][j] = 1; n   } n   for (int que = 1; que <= q; que++) { n     int opt = read(), x = read(), y = read(); n     if (opt == 1) { n       s[++id] = s[x] & s[y]; n       continue; n     } n     if (opt == 2) { n       s[++id] = s[x] | s[y]; n       continue; n     } n     if (opt == 3) { n       vector<pair<int, int> > v; n       for (int i = 1; i <= n; i++) v.push_back(make_pair(a[i][y], i)); n       sort(v.begin(), v.end()); n       int sum = 0; n       for (int i = 0; i < n; i++) { n         sum |= (1 << (v[i].second - 1)); n         if (s[x][sum]) { n           printf( %d n , v[i].first); n           break; n         } n       } n       continue; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void read(vector<long long int> &a, int n) { n   a.resize(n); n   for (int i = 0; i < n; i++) cin >> a[i]; n } n bool fine = 0; n void solve() { n   int x, y, z; n   cin >> x >> y >> z; n   vector<int> a(x), b(y), c(z); n   for (int i = 0; i < x; i++) cin >> a[i]; n   for (int i = 0; i < y; i++) cin >> b[i]; n   for (int i = 0; i < z; i++) cin >> c[i]; n   sort(a.begin(), a.end()); n   sort(b.begin(), b.end()); n   sort(c.begin(), c.end()); n   reverse(a.begin(), a.end()); n   reverse(c.begin(), c.end()); n   reverse(b.begin(), b.end()); n   long long int ans = 0; n   long long int dp[x + 1][y + 1][z + 1]; n   memset(dp, 0, sizeof(dp)); n   for (int i = 0; i < x + 1; i++) { n     for (int j = 0; j < y + 1; j++) { n       for (int k = 0; k < z + 1; k++) { n         if ((i + j + k) < 2 || (i + j + k) & 1) continue; n         if (i && j) n           dp[i][j][k] = n               max(dp[i][j][k], dp[i - 1][j - 1][k] + a[i - 1] * b[j - 1]); n         if (i && k) n           dp[i][j][k] = n               max(dp[i][j][k], dp[i - 1][j][k - 1] + a[i - 1] * c[k - 1]); n         if (k && j) n           dp[i][j][k] = n               max(dp[i][j][k], dp[i][j - 1][k - 1] + b[j - 1] * c[k - 1]); n         ans = max(dp[i][j][k], ans); n       } n     } n   } n   cout << ans << endl; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   if (fine) { n     int t; n     cin >> t; n     while (t--) { n       solve(); n     } n   } else n     solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n const int N = 2e5 + 10; n struct node { n   int l, r, id; n   friend bool operator<(node A, node B) { n     return A.r == B.r ? A.l < B.l : A.r < B.r; n   } n }; n node a[N]; n bool add[N]; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   ll n, m; n   ; n   cin >> n >> m; n   for (int i = 1; i <= n; ++i) { n     cin >> a[i].l >> a[i].r; n     a[i].id = i; n   } n   sort(a + 1, a + 1 + n); n   multiset<int> b; n   for (int i = 0; i < m; ++i) b.insert(0); n   for (int i = 1; i <= n; ++i) { n     auto p = b.lower_bound(a[i].l); n     if (p != b.begin()) { n       add[a[i].id] = 1; n       --p; n       b.erase(p); n       b.insert(a[i].r); n     } n   } n   vector<int> ans; n   for (int i = 1; i <= n; ++i) n     if (!add[i]) ans.emplace_back(i); n   cout << ans.size() << endl; n   for (auto i : ans) cout << i <<    ; n   cout << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const long long maxn = 3e3 + 100; n const long long inf = 0x3f3f3f3f; n const long long iinf = 1 << 30; n const long long linf = 2e18; n const long long mod = 998244353; n const double eps = 1e-7; n template <class T = long long> n T chmin(T &a, T b) { n   return a = min(a, b); n } n template <class T = long long> n T chmax(T &a, T b) { n   return a = max(a, b); n } n template <class T = long long> n inline void red(T &x) { n   x -= mod, x += x >> 31 & mod; n } n template <class T = long long> n T read() { n   T f = 1, a = 0; n   char ch = getchar(); n   while (!isdigit(ch)) { n     if (ch ==  - ) f = -1; n     ch = getchar(); n   } n   while (isdigit(ch)) { n     a = (a << 3) + (a << 1) + ch -  0 ; n     ch = getchar(); n   } n   return a * f; n } n long long n, m, ans; n char s[maxn], t[maxn]; n long long f[maxn][maxn]; n signed main() { n   scanf( %s %s , s + 1, t + 1); n   long long n = strlen(s + 1), m = strlen(t + 1); n   for (long long i = (1); i <= (n); ++i) f[i][i] = 2 * (i > m || s[1] == t[i]); n   for (long long i = (2); i <= (n); ++i) n     for (long long l = (1); l <= (n - i + 1); ++l) { n       long long r = l + i - 1; n       if (l > m || s[i] == t[l]) red(f[l][r] += f[l + 1][r]); n       if (r > m || s[i] == t[r]) red(f[l][r] += f[l][r - 1]); n     } n   for (long long i = (m); i <= (n); ++i) red(ans += f[1][i]); n   printf( %lld n , ans); n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( no-stack-protector ) n #pragma GCC optimize( -funroll-loops ) n #pragma GCC target( avx,sse4 ) n using namespace std; n const int P = 1e9 + 7, i2 = P / 2 + 1, i6 = P / 6 + 1, N = 1e6 + 5; n long long n, m; n int r, f1[N], f2[N], f3[N]; n int main() { n   scanf( %lld , &n); n   long long g1 = (n + 1) % P, g3 = (long long)g1 * g1 % P * g1 % P; n   while ((long long)m * m <= n) m++; n   m--; n   for (register int i = 1, _lim_ = m; i <= _lim_; i++) { n     long long v1 = (long long)i * i % P, v2 = (long long)v1 * v1 % P, n               v3 = (long long)v1 * v2 % P; n     f1[i] = (f1[i - 1] + v1) % P; n     f2[i] = (f2[i - 1] + v2) % P; n     f3[i] = (f3[i - 1] + v3) % P; n   } n   for (register int x = 0, _lim_ = m; x <= _lim_; x++) { n     long long s = 0, v1 = (long long)x * x % P, v2 = (long long)v1 * v1 % P, n               v3 = (long long)v1 * v2 % P; n     while ((long long)x * x + (long long)m * m > n) m--; n     s = ((g3 + g1 * (3 * v1 - 3 * v2 - 1) + v1 - v2 * 3 + v3 * 2) % P * n              (m + 1) % P + n          (3 * g1 + 1 - (3 * g1 + 3) * v1 * 2 + v2 * 6) % P * f1[m] % P + n          3 * (v1 * 2 - g1 - 1) * f2[m] + 2 * f3[m]) % n         P; n     s = (s * 2 - g3 + g1 - v1 * (3 * g1 + 1) + v2 * (3 * g1 + 3) - v3 * 2) % P; n     r = (r + s * (1 << (x > 0))) % P; n   } n   r = (long long)r * i6 % P; n   if (r < 0) r += P; n   printf( %d n , r); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, co[200010], to[200010]; n int cnt = 0; n int dfn[200010], low[200010]; n int scc_cnt; n int sccno[200010]; n int nt[200010], va[200010]; n stack<int> S; n void dfs(int u) { n   dfn[u] = low[u] = ++cnt; n   S.push(u); n   int v = to[u]; n   if (dfn[v] == 0) { n     dfs(v); n     low[u] = min(low[u], low[v]); n   } else if (!sccno[v]) { n     low[u] = min(low[u], dfn[v]); n   } n   int MMM = 0x3f3f3f3f; n   if (low[u] == dfn[u]) { n     ++scc_cnt; n     while (true) { n       int x = S.top(); n       S.pop(); n       sccno[x] = scc_cnt; n       MMM = min(MMM, co[x]); n       if (x == u) { n         break; n       } n     } n     va[scc_cnt] = MMM; n   } n } n int num[200010]; n int main() { n   cin >> n; n   for (int i = 1; i <= n; i++) cin >> co[i]; n   for (int i = 1; i <= n; i++) cin >> to[i]; n   memset(dfn, 0, sizeof(dfn)); n   cnt = scc_cnt = 0; n   for (int i = 1; i <= n; ++i) { n     if (!dfn[i]) { n       dfs(i); n     } n   } n   for (int u = 1; u <= n; ++u) { n     int v = to[u]; n     if (sccno[u] != sccno[v]) { n       nt[sccno[u]] = sccno[v]; n       num[sccno[u]]++; n     } n   } n   queue<int> q; n   int ans = 0; n   for (int i = 1; i <= scc_cnt; i++) { n     if (num[i] == 0) { n       ans += va[i]; n     } n   } n   cout << ans << endl; n   ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 10; n char s[N], t[N]; n int n, m; n int ch[N][26]; n int lps[N]; n void calcLps() { n   memset(lps, 0, sizeof(lps)); n   int i = 1; n   int len = 0; n   lps[0] = 0; n   while (i < m) { n     if (t[i + 1] == t[len + 1]) { n       len++; n       lps[i] = len; n       i++; n     } else { n       if (len == 0) { n         lps[i] = 0; n         i++; n       } else { n         len = lps[len - 1]; n       } n     } n   } n } n int main() { n   scanf( %s , s + 1); n   scanf( %s , t + 1); n   n = strlen(s + 1), m = strlen(t + 1); n   for (int i = 1; i <= m; i++) ch[i - 1][t[i] -  a ] = i; n   calcLps(); n   for (int i = 1; i <= m; i++) { n     for (int j = 0; j < 26; j++) { n       if (!ch[i][j]) { n         ch[i][j] = ch[lps[i - 1]][j]; n       } n     } n   } n   vector<vector<int> > dp(n + 1, vector<int>(m + 1, -1)); n   dp[0][0] = 0; n   for (int i = 0; i < n; i++) { n     for (int j = 0; j <= m; j++) { n       if (dp[i][j] == -1) continue; n       if (s[i + 1] ==  ? ) { n         for (int c = 0; c < 26; c++) { n           dp[i + 1][ch[j][c]] = n               max(dp[i + 1][ch[j][c]], dp[i][j] + (ch[j][c] == m)); n         } n       } else { n         int c = s[i + 1] -  a ; n         dp[i + 1][ch[j][c]] = n             max(dp[i + 1][ch[j][c]], dp[i][j] + (ch[j][c] == m)); n       } n     } n   } n   int ans = 0; n   for (int i = 0; i <= m; i++) { n     ans = max(ans, dp[n][i]); n   } n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 107; n int n, k; n int f[N][N]; n int main() { n   int i, j, tmp; n   bool ok = 0; n   cin >> k; n   f[1][2] = f[2][1] = 1; n   tmp = 0; n   for (i = 3; i <= 100; i++) { n     f[1][i] = f[i][1] = 1; n     for (j = 2; j < i; j++) { n       if (tmp + j - 1 > k) break; n       tmp += j - 1; n       f[i][j] = f[j][i] = 1; n       if (tmp == k) { n         ok = 1; n         break; n       } n     } n     if (ok) break; n   } n   cout << i << endl; n   k = i; n   for (i = 1; i <= k; i++) { n     for (j = 1; j < k; j++) { n       cout << f[i][j]; n     } n     cout << f[i][k] << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 100500; n int n, m; n int a[30]; n string s, t; n char ans[5500]; n void po_poryadky(int x) { n   for (int i = x; i < n; i++) { n     for (int j = 0; j < 30; j++) n       if (a[j]) { n         ans[i] = (char)( a  + j); n         a[j]--; n         break; n       } n   } n } n void ubiraem(int x) { n   for (int i = x; i >= 0; i--) { n     int num = ans[i] -  a ; n     a[num]++; n     for (int j = num + 1; j < 30; j++) n       if (a[j]) { n         ans[i] = (char)( a  + j); n         a[j]--; n         po_poryadky(i + 1); n         return; n       } n   } n   cout << -1; n   exit(0); n } n void v_roven() { n   for (int i = 0; i < m; i++) { n     int num = t[i] -  a ; n     if (a[num] != 0) { n       ans[i] = t[i]; n       a[num]--; n       continue; n     } n     for (int j = num + 1; j < 30; j++) n       if (a[j]) { n         a[j]--; n         ans[i] = (char)( a  + j); n         po_poryadky(i + 1); n         return; n       } n     ubiraem(i - 1); n     return; n   } n   if (n == m) n     ubiraem(m - 1); n   else n     po_poryadky(m); n } n int main() { n   cin >> s >> t; n   n = s.size(); n   m = t.size(); n   for (int i = 0; i < n; i++) a[(int)(s[i] -  a )]++; n   v_roven(); n   ans[n] =   0 ; n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n const int MAXN = 2e5 + 5; n int n, a[MAXN]; n long long sm[MAXN]; n int ans = 0; n int pc[MAXN]; n inline bool check(int l, int r) { return (a[l] ^ a[r]) == sm[r - 1] - sm[l]; } n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; ++i) scanf( %d , a + i), sm[i] = sm[i - 1] + a[i]; n   for (int i = 1; i <= n; ++i) { n     int x = a[i]; n     while (x) x >>= 1, ++pc[i]; n   } n   for (int l = 1; l <= n - 2; ++l) { n     int r = l + 2; n     while (r <= n && sm[r - 1] - sm[l] < (1ll << pc[l])) { n       if (pc[l] >= pc[r]) ans += check(l, r); n       ++r; n     } n   } n   std::reverse(a + 1, a + n + 1); n   std::reverse(pc + 1, pc + n + 1); n   for (int i = 1; i <= n; ++i) sm[i] = sm[i - 1] + a[i]; n   for (int l = 1; l <= n - 2; ++l) { n     int r = l + 2; n     while (r <= n && sm[r - 1] - sm[l] < (1ll << pc[l])) { n       if (pc[l] > pc[r]) ans += check(l, r); n       ++r; n     } n   } n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX_N = 2e5 + 10; n int n, m, l, r, x, a[MAX_N], left_ancestor[MAX_N]; n int main() { n   scanf( %d %d , &n, &m); n   for (int i = 1; i <= n; i++) scanf( %d , a + i); n   for (int i = 2; i <= n; i++) n     if (a[i] == a[i - 1]) n       left_ancestor[i] = left_ancestor[i - 1]; n     else n       left_ancestor[i] = i - 1; n   while (m--) { n     scanf( %d %d %d , &l, &r, &x); n     if (a[r] != x) n       printf( %d n , r); n     else if (left_ancestor[r] and l <= left_ancestor[r]) n       printf( %d n , left_ancestor[r]); n     else n       puts( -1 ); n   } n   return (0); n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 5 * 1e5; n long long s[maxn], del[maxn], mark[maxn]; n void build(int u, int l, int r) { n   if (l < r) { n     int mid = (l + r) / 2; n     build(u * 2, l, mid), build(u * 2 + 1, mid + 1, r); n   } else n     mark[u] = l; n } n long long query(int u, int l, int r, int x, int y) { n   if (y < l || x > r) return 0; n   if (x <= l && r <= y) return s[u]; n   int mid = (l + r) / 2; n   long long L = query(u * 2, l, mid, x, y); n   long long R = query(u * 2 + 1, mid + 1, r, x, y); n   return L + R + max(0, min(r, y) - max(l, x) + 1) * del[u]; n } n void clear(int u, int l, int r, int z) { n   if (mark[u]) { n     del[u] += abs(mark[u] - z); n     s[u] += 1LL * (r - l + 1) * abs(mark[u] - z); n     mark[u] = 0; n   } else { n     if (l == r) return; n     int mid = (l + r) / 2, lc = u * 2, rc = u * 2 + 1; n     clear(lc, l, mid, z); n     clear(rc, mid + 1, r, z); n     s[u] = s[lc] + s[rc] + 1LL * (r - l + 1) * del[u]; n   } n } n void modify(int u, int l, int r, int x, int y, int z) { n   if (y < l || x > r) return; n   if (x <= l && r <= y) { n     clear(u, l, r, z); n     mark[u] = z; n     return; n   } n   int mid = (l + r) / 2, lc = u * 2, rc = u * 2 + 1; n   if (mark[u]) mark[lc] = mark[rc] = mark[u], mark[u] = 0; n   modify(lc, l, mid, x, y, z); n   modify(rc, mid + 1, r, x, y, z); n   s[u] = s[lc] + s[rc] + 1LL * (r - l + 1) * del[u]; n } n int main() { n   int n, m; n   scanf( %d%d , &n, &m); n   build(1, 1, n); n   int type, x, y, z; n   ; n   for (int i = 0; i < m; i++) { n     scanf( %d%d%d , &type, &x, &y); n     if (type == 1) { n       scanf( %d , &z); n       modify(1, 1, n, x, y, z); n     } else n       (cout << query(1, 1, n, x, y) << endl); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 100001; n int n, m, ind[N], dpth[N], s[N], e[N], t, seg[4 * N], lazy[4 * N], a[N]; n vector<vector<int> > g, gift; n vector<pair<int, int> > anc; n vector<int> ans, root; n void dfs(int u) { n   s[u] = t++; n   for (int i = 0; i < g[u].size(); i++) { n     dpth[g[u][i]] = dpth[u] + 1; n     dfs(g[u][i]); n   } n   e[u] = t - 1; n } n void dfs2(int u) { n   if (gift[a[u]].empty()) { n     anc.push_back(make_pair(-dpth[a[u]], a[u])); n   } n   gift[a[u]].push_back(u); n   for (int i = 0; i < g[u].size(); i++) dfs2(g[u][i]); n } n void checkLazy(int p, int s, int e) { n   if (lazy[p] != 0) { n     seg[p] += (e - s + 1) * lazy[p]; n     if (s != e) lazy[2 * p] += lazy[p], lazy[2 * p + 1] += lazy[p]; n     lazy[p] = 0; n   } n } n void build(int p, int s, int e) { n   if (s == e) { n     seg[p] = 1; n     lazy[p] = 0; n     return; n   } n   build(2 * p, s, (s + e) / 2); n   build(2 * p + 1, (s + e) / 2 + 1, e); n   seg[p] = seg[2 * p] + seg[2 * p + 1]; n   lazy[p] = lazy[2 * p] + lazy[2 * p + 1]; n } n void update(int p, int s, int e, int a, int b, int v) { n   checkLazy(p, s, e); n   if (s >= a && e <= b) { n     seg[p] += (e - s + 1) * v; n     if (s != e) lazy[2 * p] += v, lazy[2 * p + 1] += v; n     return; n   } n   if (s > b || e < a) return; n   update(2 * p, s, (s + e) / 2, a, b, v); n   update(2 * p + 1, (s + e) / 2 + 1, e, a, b, v); n   seg[p] = seg[2 * p] + seg[2 * p + 1]; n } n int get(int p, int s, int e, int a) { n   checkLazy(p, s, e); n   if (s == e) return seg[p]; n   if (a <= (s + e) / 2) return get(2 * p, s, (s + e) / 2, a); n   return get(2 * p + 1, (s + e) / 2 + 1, e, a); n } n int main() { n   std::ios::sync_with_stdio(false); n   scanf( %d%d , &n, &m); n   g.resize(n); n   memset(ind, 0, sizeof(ind)); n   build(1, 0, n - 1); n   for (int i = 0, a, b; i < m; i++) { n     scanf( %d%d , &a, &b); n     a--, b--; n     g[a].push_back(b); n     ind[b]++; n   } n   for (int i = 0; i < n; i++) n     if (ind[i] == 0) root.push_back(i); n   for (int i = 0; i < n; i++) { n     scanf( %d , a + i); n     a[i]--; n   } n   t = 0; n   gift.resize(n); n   for (int i = 0; i < root.size(); i++) { n     int r = root[i]; n     dpth[r] = 0; n     dfs(r); n     anc.clear(); n     dfs2(r); n     sort(anc.begin(), anc.end()); n     for (int j = 0; j < anc.size(); j++) { n       for (int k = 0; k < gift[anc[j].second].size(); k++) n         if (get(1, 0, n - 1, s[gift[anc[j].second][k]]) <= 0) { n           puts( -1 ); n           return 0; n         } n       ans.push_back(anc[j].second + 1); n       update(1, 0, n - 1, s[anc[j].second], e[anc[j].second], -1); n     } n   } n   printf( %d n , ans.size()); n   for (int i = 0; i < ans.size(); i++) printf( %d n , ans[i]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void matches(vector<int> arr) { n   int i; n   for (i = 0; i < arr.size(); i++) { n     if (arr[i] == 2) n       cout << 2 << endl; n     else if (arr[i] % 2 == 0 && arr[i] != 2) n       cout << 0 << endl; n     else n       cout << 1 << endl; n   } n } n int main() { n   int i, n; n   cin >> n; n   vector<int> arr(n); n   for (i = 0; i < n; i++) { n     cin >> arr[i]; n   } n   matches(arr); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MOD = 1000000007; n const int INF = 1000000001; n const long long LINF = 1000000000000000001LL; n struct ConvexHullTrick { n   struct line { n     int a; n     long long b; n     long long eval(int x) { return (long long)a * x + b; } n   }; n   bool incrSlope, incrQueries, queryMax; n   ConvexHullTrick(bool incrSlope, bool incrQueries, bool queryMax) n       : incrSlope(incrSlope), incrQueries(incrQueries), queryMax(queryMax) { n     assert(incrSlope xor incrQueries xor queryMax); n   } n   deque<line> lines; n   long long overtakes(const line &p, const line &q) { n     long long x = p.b - q.b; n     int y = p.a - q.a; n     return (x >= 0 ? x : x - y + 1) / y; n   } n   bool redundantTop(const line &l) { n     int s = lines.size(); n     if (l.a == lines[s - 1].a) { n       return true; n     } else { n       return overtakes(l, lines[s - 1]) >= n              overtakes(lines[s - 1], lines[s - 2]); n     } n   } n   void add(int a, long long b) { n     if (!(incrSlope xor incrQueries xor queryMax)) a *= -1; n     if (queryMax) b *= -1; n     if (!lines.empty() && a == lines.back().a && b >= lines.back().b) { n       return; n     } n     line l = {a, b}; n     while (lines.size() >= 2 && redundantTop(l)) { n       lines.pop_back(); n     } n     lines.push_back(l); n   } n   long long query(int x) { n     if (!(incrSlope xor incrQueries)) x *= -1; n     while (lines.size() >= 2 && lines[0].eval(x) > lines[1].eval(x)) { n       lines.pop_front(); n     } n     return lines.front().eval(x) * (queryMax ? -1 : 1); n   } n }; n int main() { n   ios_base::sync_with_stdio(false); n   ConvexHullTrick hull(false, false, true); n   auto add = [&](long long dpValue, int x) { hull.add(-x, dpValue); }; n   int n; n   cin >> n; n   struct rect { n     int x, y; n     long long a; n   }; n   vector<rect> rects(n); n   for (auto &e : rects) { n     cin >> e.x >> e.y >> e.a; n   } n   sort(rects.begin(), rects.end(), n        [&](const rect &a, const rect &b) { return a.x < b.x; }); n   vector<long long> dp(n + 1, 0); n   add(0, 0); n   for (int i = (1); i <= (n); i++) { n     auto r = rects[i - 1]; n     dp[i] = (long long)r.x * r.y - r.a + hull.query(r.y); n     add(dp[i], r.x); n   } n   long long ans = *max_element(dp.begin(), dp.end()); n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int N, M; n long long tblX[1001001]; n int minp[1001001]; n long long gs[1001001]; n long long bsum[1001001]; n long long bsums0[1001001]; n long long bsums1[1001001]; n long long bsums2[1001001]; n long long linsum(long long K) { n   long long P = K, Q = K + 1; n   if (P % 2 == 0) n     P /= 2; n   else n     Q /= 2; n   return (P * Q) % 1000000007; n } n long long sqrsum(long long K) { n   long long ret = K; n   ret = ret * (K + 1) % 1000000007; n   ret = ret * ((2 * K + 1) % 1000000007) % 1000000007; n   return ret * ((1000000007 + 1) / 6) % 1000000007; n } n void erat() { n   for (int i = 0; i <= 1000000; i++) minp[i] = -1; n   for (int i = 2; i <= 1000000; i++) n     if (minp[i] == -1) { n       for (int j = i; j <= 1000000; j += i) n         if (minp[j] == -1) minp[j] = i; n     } n } n long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } n long long count(long long a, long long b) { n   if (min(N, M) <= a + b - 1) return 0; n   long long pat = (long long)(N - (a + b - 1)) * (M - (a + b - 1)) % 1000000007; n   long long ec = a * a + b * b - 2 * (a + b) + 2 * gcd(a, b); n   ec %= 1000000007; n   return pat * ec % 1000000007; n } n void calc_gs() { n   gs[1] = 1; n   for (int i = 2; i <= 1000000; i++) { n     int p = i, q = i; n     long long aux = 0; n     int ord = 0; n     while (q % minp[i] == 0) { n       ++ord; n       q /= minp[i]; n     } n     long long pow = 1; n     for (int j = 0; j < ord - 1; j++) pow = (pow * minp[i]); n     aux += pow * minp[i]; n     aux += pow * (minp[i] - 1) * ord; n     aux %= 1000000007; n     aux = aux * gs[q] % 1000000007; n     gs[i] = aux; n   } n } n void calc_bsum() { n   bsum[0] = 0; n   for (int i = 1; i <= 1000000; i++) { n     long long tmp = sqrsum(i) + sqrsum(i - 1) + 2 * 1000000007 - n                     (2 * i * (long long)i % 1000000007) + 2 * gs[i]; n     bsum[i] = tmp % 1000000007; n   } n } n void totalize() { n   bsums0[0] = bsums1[0] = bsums2[0] = 0; n   for (int i = 1; i <= 1000000; i++) { n     bsums0[i] = (bsums0[i - 1] + bsum[i]) % 1000000007; n     bsums1[i] = (bsums1[i - 1] + bsum[i] * i % 1000000007) % 1000000007; n     bsums2[i] = (bsums2[i - 1] + bsum[i] * i % 1000000007 * i % 1000000007) % n                 1000000007; n   } n } n int main() { n   erat(); n   calc_gs(); n   calc_bsum(); n   totalize(); n   int T; n   scanf( %d , &T); n   for (int i = 0; i < T; i++) { n     scanf( %d%d , &N, &M); n     if (N > M) swap(N, M); n     long long ret = (long long)(N + 1) * (M + 1) % 1000000007 * bsums0[N]; n     ret += 1000000007 - ((long long)(N + M + 2) * bsums1[N] % 1000000007); n     ret += bsums2[N]; n     ret %= 1000000007; n     printf( %d n , (int)ret); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n1; n int i, j; n int main() { n   int a[10] = {4, 7, 47, 74, 447, 474, 477, 774, 747, 744}; n   string n; n   cin >> n; n   int z = n.length(); n   stringstream stoi(n); n   stoi >> n1; n   for (i = 0; i < 10; i++) { n     if (n1 % a[i] == 0) { n       cout <<  YES ; n       return 0; n     } n   } n   cout <<  NO ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double eps = 1e-6; n const double pi = acos(-1); n int sign(double k) { n   if (k > eps) n     return 1; n   else if (k < -eps) n     return -1; n   return 0; n } n int cmp(double k1, double k2) { return sign(k1 - k2); } n int inmid(double k1, double k2, double k3) { n   return sign(k1 - k3) * sign(k2 - k3) <= 0; n } n struct point { n   double x, y; n   point operator+(const point &k1) const { return (point){k1.x + x, k1.y + y}; } n   point operator-(const point &k1) const { return (point){x - k1.x, x - k1.y}; } n   point operator*(double &k1) const { return (point){x * k1, y * k1}; } n   point operator/(double &k1) const { return (point){x / k1, y / k1}; } n   int operator==(const point &k1) const { n     return cmp(x, k1.x) == 0 && cmp(y, k1.y) == 0; n   } n   double abs() { return sqrt(x * x + y * y); } n   double abs2() { return x * x + y * y; } n   double dis(point k1) { return ((*this) - k1).abs(); } n }; n struct osc { n   double ang; n   int v; n }; n bool osccmp(osc a, osc b) { n   int res = cmp(a.ang, b.ang); n   if (res == -1) return 1; n   if (res == 0 && a.v > b.v) return 1; n   return 0; n } n int n, K; n int sz; n osc angle[400050]; n point a[100050]; n bool check(double R) { n   sz = 0; n   int now = 0; n   for (int i = 1; i <= n; i++) { n     double d = a[i].abs() / 2; n     if (cmp(d, R) == 1) continue; n     double t = atan2(a[i].y, a[i].x); n     if (t < 0) t += 2 * pi; n     double dt = acos(d / R); n     double f = t - dt, s = t + dt; n     if (cmp(f, 0.0) == -1) f += 2 * pi; n     if (cmp(s, 2 * pi) == 1) s -= 2 * pi; n     if (cmp(f, s) == 1 || cmp(f, 0.0) == 0) now++; n     angle[++sz] = (osc){f, 1}; n     angle[++sz] = (osc){s, -1}; n   } n   sort(angle + 1, angle + sz + 1, osccmp); n   for (int i = 1; i <= sz; i++) { n     now += angle[i].v; n     if (now >= K) return 1; n   } n   return 0; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin >> n >> K; n   for (int i = 1; i <= n; i++) { n     int x, y; n     cin >> x >> y; n     if (x == 0 && y == 0) { n       K--; n       i--; n       n--; n       continue; n     } n     a[i] = (point){(double)x, (double)y}; n   } n   if (K <= 0) { n     cout << fixed << setprecision(10) << 0.0 <<   n ; n     return 0; n   } n   double l = 0, r = 200000; n   for (int round = 1; round <= 100; round++) { n     double mid = (l + r) / 2; n     if (check(mid)) n       r = mid; n     else n       l = mid; n   } n   cout << fixed << setprecision(10) << l <<   n ; n   return 0; n } n