#include <bits/stdc++.h> n using namespace std; n const int N = 605; n int n; n vector<int> g[N]; n map<vector<int>, int> memo; n int ask(vector<int> &vs) { n   if (int((vs).size()) <= 1) return 0; n   sort((vs).begin(), (vs).end()); n   if (memo.count(vs)) return memo[vs]; n   cout <<  ?   << int((vs).size()) << endl; n   for (int x = (0), qwerty = (int((vs).size())); x < qwerty; x++) { n     if (x) cout <<    ; n     cout << vs[x]; n   } n   cout << endl; n   int v; n   cin >> v; n   return memo[vs] = v; n } n pair<int, int> f(vector<int> vs1, vector<int> vs2, bool b) { n   if (int((vs1).size()) == 1 && int((vs2).size()) == 1) { n     if (!b) { n       vector<int> vs = {vs1[0], vs2[0]}; n       int v = ask(vs); n       if (!v) return {-1, -1}; n     } n     return {vs1[0], vs2[0]}; n   } n   vector<int> vs = vs1; n   for (int v : vs2) vs.push_back(v); n   int A, B, AB, abo; n   if (!b) n     A = ask(vs1), B = ask(vs2), AB = ask(vs), abo = AB - A - B; n   else n     abo = 1; n   if (!abo) return {-1, -1}; n   bool rev = 0; n   if (int((vs2).size()) == 1) swap(vs1, vs2), rev = 1; n   vector<int> vs2_0, vs2_1; n   for (int x = (0), qwerty = (int((vs2).size()) / 2); x < qwerty; x++) n     vs2_0.push_back(vs2[x]); n   for (int x = (int((vs2).size()) / 2), qwerty = (int((vs2).size())); n        x < qwerty; x++) n     vs2_1.push_back(vs2[x]); n   pair<int, int> tmp = f(vs1, vs2_0, 0); n   if (tmp.first == -1) tmp = f(vs1, vs2_1, 1); n   if (rev) swap(tmp.first, tmp.second); n   return tmp; n } n vector<int> cs[2]; n int dep[N], par[N]; n void dfs(int u, int p, int c) { n   cs[c].push_back(u); n   for (int v : g[u]) n     if (v != p) par[v] = u, dep[v] = dep[u] + 1, dfs(v, u, !c); n } n pair<int, int> solve(vector<int> vs) { n   vector<int> vs1, vs2; n   for (int x = (0), qwerty = (int((vs).size()) / 2); x < qwerty; x++) n     vs1.push_back(vs[x]); n   for (int x = (int((vs).size()) / 2), qwerty = (int((vs).size())); x < qwerty; n        x++) n     vs2.push_back(vs[x]); n   int A = ask(vs1), B = ask(vs2), AB = ask(vs), ABo = AB - A - B; n   if (A) return solve(vs1); n   if (B) return solve(vs2); n   assert(ABo > 0); n   return f(vs1, vs2, 0); n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cin >> n; n   vector<int> nused, used; n   for (int x = (1), qwerty = (n + 1); x < qwerty; x++) nused.push_back(x); n   random_shuffle((nused).begin(), (nused).end()); n   used.push_back(nused.back()); n   nused.pop_back(); n   for (int x = (1), qwerty = (n); x < qwerty; x++) { n     pair<int, int> tmp = f(used, nused, 0); n     int idx = -1; n     for (int i = (0), qwerty = (int((nused).size())); i < qwerty; i++) n       if (nused[i] == tmp.second) idx = i; n     assert(idx != -1); n     swap(nused.back(), nused[idx]); n     nused.pop_back(); n     used.push_back(tmp.second); n     sort((used).begin(), (used).end()); n     g[tmp.first].push_back(tmp.second); n     g[tmp.second].push_back(tmp.first); n   } n   dfs(1, 0, 0); n   if (ask(cs[0]) == 0 && ask(cs[1]) == 0) { n     cout <<  Y   << int((cs[0]).size()) << endl; n     for (int x = (0), qwerty = (int((cs[0]).size())); x < qwerty; x++) { n       if (x) cout <<    ; n       cout << cs[0][x]; n     } n     cout << endl; n   } else { n     if (ask(cs[0]) == 0) swap(cs[0], cs[1]); n     pair<int, int> tmp = solve(cs[0]); n     assert(tmp.first != -1); n     vector<int> vs1, vs2; n     int u = tmp.first, v = tmp.second; n     while (u != v) { n       if (dep[u] < dep[v]) { n         vs2.push_back(v); n         v = par[v]; n       } else { n         vs1.push_back(u); n         u = par[u]; n       } n     } n     vs1.push_back(u); n     reverse((vs1).begin(), (vs1).end()); n     for (int v : vs2) vs1.push_back(v); n     cout <<  N   << int((vs1).size()) << endl; n     for (int x = (0), qwerty = (int((vs1).size())); x < qwerty; x++) { n       if (x) cout <<    ; n       cout << vs1[x]; n     } n     cout << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 2e5 + 10; n int cnt2[maxn]; n int cnt[maxn]; n struct trie { n   int nxt[maxn][26], fail[maxn], g[maxn]; n   int ed[maxn]; n   int rt, L; n   int newnode() { n     memset(nxt[L], -1, sizeof nxt[L]); n     ed[L++] = 0; n     return L - 1; n   } n   void init() { n     L = 0; n     rt = newnode(); n   } n   void insert(const string& buf) { n     int len = buf.size(); n     int now = rt; n     for (int i = 0; i < len; ++i) { n       if (nxt[now][buf[i] -  a ] == -1) nxt[now][buf[i] -  a ] = newnode(); n       now = nxt[now][buf[i] -  a ]; n     } n     ed[now]++; n   } n   void build() { n     queue<int> q; n     fail[rt] = rt; n     g[rt] = rt; n     for (int i = 0; i < 26; ++i) { n       if (nxt[rt][i] == -1) n         nxt[rt][i] = rt; n       else { n         fail[nxt[rt][i]] = rt; n         g[nxt[rt][i]] = rt; n         q.push(nxt[rt][i]); n       } n     } n     while (!q.empty()) { n       int now = q.front(); n       q.pop(); n       for (int i = 0; i < 26; ++i) { n         if (nxt[now][i] == -1) n           nxt[now][i] = nxt[fail[now]][i]; n         else { n           fail[nxt[now][i]] = nxt[fail[now]][i]; n           if (ed[fail[nxt[now][i]]]) { n             g[nxt[now][i]] = fail[nxt[now][i]]; n           } else n             g[nxt[now][i]] = g[fail[nxt[now][i]]]; n           q.push(nxt[now][i]); n         } n       } n     } n   } n   void query(const string& buf) { n     int len = buf.size(); n     int now = rt; n     for (int i = 0; i < len; ++i) { n       now = nxt[now][buf[i] -  a ]; n       int tmp = now; n       while (tmp != rt) { n         cnt[i] += ed[tmp]; n         tmp = g[tmp]; n       } n     } n   } n } a, b; n string t; n string s[maxn]; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cin >> t; n   int n; n   cin >> n; n   a.init(); n   for (int i = 1; i <= n; ++i) { n     cin >> s[i]; n     a.insert(s[i]); n   } n   a.build(); n   a.query(t); n   memcpy(cnt2, cnt, sizeof cnt); n   memset(cnt, 0, sizeof cnt); n   b.init(); n   for (int i = 1; i <= n; ++i) { n     reverse(s[i].begin(), s[i].end()); n     b.insert(s[i]); n   } n   b.build(); n   reverse(t.begin(), t.end()); n   b.query(t); n   long long ans = 0; n   for (int i = 0; i < t.size() - 1; ++i) { n     ans += 1ll * cnt2[i] * cnt[t.size() - i - 2]; n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a, b; n int main() { n   cin >> a >> b; n   if (a > b + 1 or (a + 1) * 2 < b) { n     cout << -1; n     return 0; n   } n   string s; n   s.push_back( 1 ); n   int n = a + b, ok = 1; n   for (int i = 1; i < n; i++) { n     if (ok and b > a) { n       s.push_back( 1 ); n       ok = 0; n       b--; n     } else { n       if (s[i - 1] ==  0 ) { n         ok = 1; n         s.push_back( 1 ); n         b--; n       } else { n         s.push_back( 0 ); n         a--; n       } n     } n   } n   if (a == 1) s.pop_back(), s =  0  + s; n   cout << s; n } n


#include <iostream> n #include <iomanip> n #include <cstdio> n #include <cstdlib> n #include <algorithm> n #include <cmath> n #include <vector> n #include <set> n #include <map> n #include <unordered_set> n #include <unordered_map> n #include <queue> n #include <ctime> n #include <cassert> n #include <complex> n #include <string> n #include <cstring> n #include <chrono> n #include <random> n #include <bitset> n  n using namespace std; n #define ll long long n #define pi pair<int,int> n #define pll pair<ll,ll> n #define ld  long double n    n const int INF = 1e9 + 7; n long long MOD; n  n  n  n const int N = 405; n  n long long dp[N][N]; n long long ncr[N][N]; n long long p2[N]; n  n void solve(){ n     int n; n     cin >> n >> MOD; n     /* n         Trivial observation : If the number of segments of `x` is k and the sizes are x_1 , x_2 , ... , x_k.  n         Then, the number of ways is X! / (x_1! x_2!... x_k!) 2^(x_1 - 1) 2^(x_2 - 1) ..  n     */ n      n     p2[0] = 1LL; n     for(int i = 1; i < N; i++){ n         p2[i] = p2[i - 1] * 2LL % MOD;  n     } n     ncr[1][0] = ncr[1][1] = 1; n  n     for(int i = 2; i < N; i++){ n         for(int r = 0; r <= i; r++){ n             if(r == 0 || r == i) ncr[i][r] = 1; n             else ncr[i][r] = (ncr[i - 1][r] + ncr[i - 1][r - 1]) % MOD; n         } n     } n      n     dp[1][1] = 1; n  n     for(int i = 2; i <= n; i++){ n         for(int manual = 0; manual <= i; manual++){ n             for(int last = 1; last <= min(manual , i); last++){ n                 if(i - last - 1 >= 0){ n                     dp[i][manual] += dp[i - last - 1][manual - last] * ncr[manual][last] % MOD * p2[last - 1] % MOD; n                     dp[i][manual] %= MOD; n                 } else{ n                     assert(i == last); n                     dp[i][manual] = p2[i - 1]; n                 } n             } n         } n     } n  n     long long ans = 0; n     for(int manual = 1; manual <= n; manual++){ n         ans += dp[n][manual]; ans %= MOD; n     } n     cout << ans << endl; n } n  n int main(){ n     ios :: sync_with_stdio(false);  n     cin.tie(nullptr);  n     cout.tie(nullptr); n     int tt = 1; n     #ifdef SIEVE n     construct(); n     #endif n     for(int tc = 1; tc <= tt; tc++){ n         // cout <<  Case #  << tc <<  :  ; n         solve(); n     } n }


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int a = 100, c = 20, d = 10, e = 5; n   long long int note, n, rem; n   while (scanf( %lld , &n) != EOF) { n     note = n / a; n     rem = n % a; n     note = note + (rem / c); n     rem = rem % c; n     note = note + (rem / d); n     rem = rem % d; n     note = note + (rem / e) + (rem % e); n     cout << note << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 2000000009; n const int Max = 1000007; n const double PI = acos(-1.0); n long long nc2(long long n) { return (n * (n - 1)) / 2; } n map<long long, long long> mp1, mp2; n map<pair<long long, long long>, long long> mp3; n int main() { n   long long i, j, k, l, temp, t, n, m, caseno = 0, ans; n   string str; n   while (cin >> n) { n     mp1.clear(); n     mp2.clear(); n     mp3.clear(); n     for (i = 0; i < n; i++) { n       cin >> j >> k; n       if (mp1.find(j) == mp1.end()) mp1[j] = 0; n       if (mp2.find(k) == mp2.end()) mp2[k] = 0; n       mp1[j]++; n       mp2[k]++; n       pair<long long, long long> ttmp = make_pair(j, k); n       if (mp3.find(ttmp) == mp3.end()) mp3[ttmp] = 0; n       mp3[ttmp]++; n     } n     map<long long, long long>::iterator it; n     ans = 0; n     for (it = mp1.begin(); it != mp1.end(); ++it) { n       ans += nc2(it->second); n     } n     for (it = mp2.begin(); it != mp2.end(); ++it) { n       ans += nc2(it->second); n     } n     map<pair<long long, long long>, long long>::iterator itr; n     for (itr = mp3.begin(); itr != mp3.end(); ++itr) { n       ans -= nc2(itr->second); n     } n     cout << ans << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int lis(vector<int>& a) { n   if (a.empty()) return 0; n   int n = a.size(); n   int INF = 1000; n   vector<int> b(n + 1, INF); n   b[0] = -INF; n   for (int i = 0; i < n; ++i) { n     int val = a[i]; n     int pos = upper_bound(b.begin(), b.end(), val) - b.begin(); n     b[pos] = min(b[pos], val); n   } n   int res = 0; n   for (int j = n; j >= 0; --j) n     if (b[j] != INF) { n       res = j; n       break; n     } n   return res; n } n int brute(int n, int t, vector<int> a) { n   for (int i = 0; i < t - 1; ++i) n     for (int j = 0; j < n; ++j) a.push_back(a[j]); n   int res = lis(a); n   return res; n } n int main() { n   ios_base::sync_with_stdio(false); n   int n, t; n   cin >> n >> t; n   vector<int> a(n); n   for (int i = 0; i < n; ++i) cin >> a[i]; n   int t0 = 100; n   int t1 = 101; n   int res = -1; n   if (t <= t0) { n     res = brute(n, t, a); n   } else { n     int res0 = brute(n, t0, a); n     int res1 = brute(n, t1, a); n     res = res1 + (t - t1) * (res1 - res0); n   } n   cout << res << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long inf = 1e18 + 1; n int n, ans[51], t[51]; n long long k, fac[51], dp[51]; n bool v[51]; n long long mul(long long x, long long y) { n   return !x ? 0 : inf / x < y ? inf : x * y; n } n long long cal(int x) { return x < 2 ? 1 : fac[x - 2]; } n void work(int l, int r) { n   for (auto i = (l); i <= (r); ++i) t[i] = i, v[i] = 0; n   ans[l] = r; n   v[r] = 1; n   swap(t[l], t[r]); n   for (auto i = (l + 1); i <= (r - 1); ++i) { n     for (auto j = (l); j <= (r); ++j) n       if (!v[j] && i != t[j]) { n         if (mul(fac[r - i - 1], dp[n - r]) >= k) { n           ans[i] = j; n           v[j] = 1; n           int x = t[i], y = t[j]; n           t[x] = y; n           t[y] = x; n           break; n         } else n           k -= mul(fac[r - i - 1], dp[n - r]); n       } n   } n   ans[r] = t[r]; n } n void sol() { n   scanf( %d%lld , &n, &k); n   if (dp[n] < k) return (void)printf( -1 n ); n   int nw = 1; n   while (nw <= n) n     for (auto i = (1); i <= (n - nw + 1); ++i) { n       if (mul(cal(i), dp[n - nw - i + 1]) >= k) { n         work(nw, nw + i - 1); n         nw += i; n         break; n       } else n         k -= mul(cal(i), dp[n - nw - i + 1]); n     } n   for (auto i = (1); i <= (n); ++i) printf( %d%c , ans[i], i == n ?   n  :    ); n } n int main() { n   int t; n   fac[0] = 1; n   dp[0] = 1; n   for (auto i = (1); i <= (50); ++i) fac[i] = mul(fac[i - 1], i); n   for (auto i = (1); i <= (50); ++i) n     for (auto j = (1); j <= (i); ++j) n       dp[i] = min(inf, dp[i] + mul(dp[i - j], cal(j))); n   scanf( %d , &t); n   for (auto i = (1); i <= (t); ++i) sol(); n } n


# include <bits/stdc++.h> n # define sz(x) (int)x.size() n # define f first n # define s second n  n using namespace std; n using ll = long long; n  n void solve() { n   int n, a, b; n   cin >> n >> a >> b; n   int x, y; n   cin >> x >> y; n   int c = n - max(a, b) + abs(a - b) / 2; n   int d = min(a, b) + abs(a - b) / 2; n   if (d >= x && c >= y) cout <<  YES n ; n   else cout <<  NO n ; n } n   n int main(){ n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   int t; cin >> t; while (t--)  n   solve(); n }


#include <bits/stdc++.h> n using namespace std; n int a[1010], ans[1010]; n int main() { n   int n, i, cur = 0, x, y, l1 = 1, l2 = 1; n   cin >> n; n   for (i = 1; i < n; i++) { n     cin >> x >> y; n     if (x > y) swap(x, y); n     a[x]++; n     if (y != n) { n       cout <<  NO ; n       return 0; n     } n   } n   for (i = 1; i < n; i++) { n     cur += a[i]; n     if (cur > i) { n       cout <<  NO ; n       return 0; n     } n   } n   cout <<  YES  << endl; n   ans[1] = n; n   for (i = n - 1; i; i--) { n     if (!a[i]) { n       while (ans[l2]) l2++; n       ans[l2] = i; n       continue; n     } n     l1 += a[i]; n     ans[l1] = i; n   } n   for (i = 1; i < n; i++) cout << ans[i] <<     << ans[i + 1] << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = (int)3e5 + 10; n const int inf = (int)1e9 + 5; n const long long llinf = (long long)1e18 + 5; n long long a[maxn]; n long long d, i, n, k, l, query, first, second, pruf, pruf2, j, m, p, last, sum, n     h, z, r; n int main() { n   cin >> n; n   for (i = 1; i < n + 1; i++) cin >> a[i]; n   string x; n   for (i = 0; i < n + 1; i++) { n     getline(cin, x); n     k = 0; n     if (i != 0) { n       for (int re = 0; re < x.size(); re++) { n         if ((x[re] ==  a ) or (x[re] ==  e ) or (x[re] ==  i ) or n             (x[re] ==  o ) or (x[re] ==  u ) or (x[re] ==  y )) n           k++; n       } n       if (k != a[i]) { n         cout <<  NO ; n         return 0; n       } n     } n   } n   cout <<  YES ; n   return 0; n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /STACK:32000000 ) n const int nil = -1; n using namespace std; n inline bool read(int& val) { return scanf( %d , &val) != -1; } n inline bool read(long long& val) { return scanf( %I64d , &val) != -1; } n inline bool read(double& val) { return scanf( %lf , &val) != -1; } n inline bool read(char* val) { return scanf( %s , val) != -1; } n template <class T1, class T2> n inline bool read(T1& a, T2& b) { n   return read(a) && read(b); n } n template <class T1, class T2, class T3> n inline bool read(T1& a, T2& b, T3& c) { n   return read(a) && read(b) && read(c); n } n template <class T1, class T2, class T3, class T4> n inline bool read(T1& a, T2& b, T3& c, T4& d) { n   return read(a) && read(b) && read(c) && read(d); n } n template <class T1, class T2, class T3, class T4, class T5> n inline bool read(T1& a, T2& b, T3& c, T4& d, T5& e) { n   return read(a) && read(b) && read(c) && read(d) && read(e); n } n const int N = 1111111; n const long long mod = 1000000007; n char str[N]; n long long cnt[N]; n int main() { n   read(str); n   int n = strlen(str); n   cnt[0] = 0; n   long long sum = 0; n   long long pow2 = 1; n   for (int i = 0, _ = (n); i < _; ++i) { n     if (str[i] ==  a ) { n       pow2 = pow2 * 2 % mod; n     } else { n       sum = (sum + pow2 - 1) % mod; n     } n   } n   cout << sum % mod << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 500; n const int M = 1e6 + 500; n const int INF = 0x3f3f3f3f; n const int MOD = 1e9 + 7; n const int BASE = 31337; n const int LOG = 18; n const int OFF = (1 << LOG); n const double EPS = 1e-9; n const double PI = 3.1415926535; n int n, k, bio[2 * M + 10]; n vector<int> v; n int main() { n   scanf( %d%d , &n, &k); n   for (int i = 0; i < n; i++) { n     int x; n     scanf( %d , &x); n     v.push_back(x); n     bio[x]++; n   } n   for (int i = 1; i < 2 * M; i++) { n     bio[i] += bio[i - 1]; n   } n   int sol = 0; n   for (int i = 0; i < v.size(); i++) { n     if ((bio[v[i] + k] - bio[v[i]]) == 0) sol++; n   } n   printf( %d n , sol); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a[100005], b[100005], f[100005], cnt[100005], ans[100005]; n int main() { n   int i, j, k, l, n, m; n   cin >> n >> m; n   for (i = 1; i <= n; i++) { n     cin >> j; n     if (!cnt[j]) f[j] = i; n     cnt[j]++; n   } n   int flag = 1; n   l = 1; n   for (i = 1; i <= m; i++) { n     cin >> j; n     if (flag) n       if (!cnt[j]) n         flag = 0; n       else if (cnt[j] > 1) n         flag = 2; n       else n         ans[l++] = f[j]; n   } n   if (l == m + 1) { n     cout <<  Possible n ; n     for (i = 1; i <= m; i++) cout << ans[i] <<    ; n     cout << endl; n   } else if (!flag) n     cout <<  Impossible n ; n   else n     cout <<  Ambiguity n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, x, y; n   cin >> n >> x >> y; n   cout << max((int)ceil((double)y * n / 100) - x, 0); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> e[200010]; n struct Node { n   int sz, l; n } c[200010]; n bool cmp(const Node &p, const Node &q) { return (p.sz - p.l) > (q.sz - q.l); } n void dfs(int x, int fa) { n   c[x].l = c[fa].l + 1; n   for (int i = 0; i < (int)e[x].size(); i++) { n     int y = e[x][i]; n     if (y == fa) continue; n     dfs(y, x); n     c[x].sz += c[y].sz; n   } n   c[x].sz++; n } n int main() { n   int n, k; n   scanf( %d%d , &n, &k); n   k = n - k; n   for (int i = 1; i < n; i++) { n     int a, b; n     scanf( %d%d , &a, &b); n     e[a].push_back(b); n     e[b].push_back(a); n   } n   dfs(1, 0); n   sort(c + 1, c + n + 1, cmp); n   long long ans = 0; n   for (int i = 1; i <= k; i++) { n     ans += (c[i].sz - c[i].l); n   } n   printf( %I64d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int TESTS = 1; n   while (TESTS--) { n     long long n, q; n     cin >> n >> q; n     while (q--) { n       long long x; n       cin >> x; n       long long c = 1; n       for (long long int i = 0; i < 63; i++) n         if ((x + c - 2 * n) % (2 * c) == 0) { n           cout << ((x + c - 2 * n) / (2 * c)) + n <<   n ; n           break; n         } else n           c *= 2; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   if (n <= 2) n     cout <<  -1 ; n   else if (n == 3) n     cout <<  210 ; n   else { n     int mod = 1; n     for (int i = 1; i < n; ++i) mod = (mod * 10) % 210; n     if (n > 3) cout <<  1 ; n     for (int i = 0; i < n - 4; ++i) cout <<  0 ; n     if (210 - mod < 100) cout <<  0 ; n     cout << 210 - mod; n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long int d[(100010)]; n const long long int mod = 1e9 + 7; n int main() { n   int n, m; n   cin >> n >> m; n   d[0] = d[1] = 1; n   int k = max(n, m); n   for (int i = 2; i <= k; i++) { n     d[i] = (d[i - 1] + d[i - 2]) % mod; n   } n   long long int ans = (d[n] + d[m] - 1) % mod; n   ans = (ans * 2) % mod; n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n #pragma warning(disable : 4996) n #pragma comment(linker,  /STACK:256000000 ) n FILE *stream; n const int INF = 1e9 + 7; n const long long INFL = (long long)1e18 + 1; n const int SIZE = 2e5 + 10; n const int TSIZE = 1e3 + 10; n const long double eps = 0.000001; n const long long MOD = 1e9 + 7; n char POW(char a, char b) { n   if (b == 0) return 1; n   char cur = POW(a, b / 2); n   if (b % 2 == 0) n     return cur * cur; n   else n     return cur * cur * a; n } n long long gcd(long long &x, long long &y, long long a, long long b) { n   if (a == 0) { n     y = 1; n     x = 0; n     return abs(b); n   } n   long long x1 = 0, y1 = 0; n   long long d = gcd(x1, y1, b % a, a); n   x = y1 - (b / a) * x1; n   y = x1; n   return d; n } n long long gcd(long long a, long long b) { n   if (a == 0) { n     return abs(b); n   } n   long long d = gcd(b % a, a); n   return d; n } n void accept() { n   int n, k, j = 2; n   cin >> n >> k; n   vector<int> ans; n   while (n > 1 && ans.size() < k) { n     while (n % j == 0 && ans.size() < k - 1) { n       n /= j; n       ans.push_back(j); n     } n     if (n > 1 && ans.size() == k - 1) { n       ans.push_back(n); n       break; n     } n     j++; n   } n   if (ans.size() == k) { n     for (int i = 0; i < k; i++) { n       cout << ans[i] <<    ; n     } n   } else { n     cout << -1; n   } n } n void solution() { n   long long t = 1; n   for (long long i = 0; i < t; i++) { n     accept(); n   } n   return; n } n void test() { n   cout <<  100000 n ; n   for (int k = 0; k < 100000 - 1; k++) { n     cout << k + 1 <<    ; n   } n   cout <<  100000 n ; n } n int main() { n   srand(time(0)); n   solution(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long int pow_mod(long long int a, long long int b) { n   long long int res = 1; n   while (b != 0) { n     if (b & 1) { n       res = (res * a) % 1000000007; n     } n     a = (a * a) % 1000000007; n     b /= 2; n   } n   return res; n } n void solve() { n   long long int n, m, k; n   cin >> n >> m >> k; n   long long int a[n + 1][m]; n   for (long long int i = 0; i < n; i++) { n     for (long long int j = 0; j < m; j++) cin >> a[i][j]; n   } n   for (long long int j = 0; j < m; j++) a[n][j] = 0; n   long long int dp[n + 1][m]; n   memset(dp, 0, sizeof(dp)); n   long long int sum[n + 1][m], mx_p[n + 1][m], mx_s[n + 1][m]; n   memset(sum, 0, sizeof(sum)); n   memset(mx_s, 0, sizeof(mx_s)); n   memset(mx_p, 0, sizeof(mx_p)); n   for (long long int i = 0; i <= n; i++) { n     for (long long int j = 0; j < m; j++) { n       if (j == 0) n         sum[i][j] = a[i][j]; n       else n         sum[i][j] = a[i][j] + sum[i][j - 1]; n     } n   } n   for (long long int i = 1; i <= n; i++) { n     for (long long int j = 0; j < m; j++) { n       if (j - k + 1 >= 0) { n         if (i == 0) { n           dp[i][j] = sum[i][j] - (j - k >= 0 ? sum[i][j - k] : 0LL); n         } else { n           dp[i][j] = sum[i][j] - (j - k >= 0 ? sum[i][j - k] : 0LL); n           dp[i][j] += sum[i - 1][j] - (j - k >= 0 ? sum[i - 1][j - k] : 0LL); n           if (i != 1) { n             long long int res = 0; n             if (j + k < m) res = mx_s[i - 1][j + k]; n             if (j - k >= 0) res = max(res, mx_p[i - 1][j - k]); n             for (long long int xx = j; xx > max(-1LL, j - k); xx--) n               res = max(res, dp[i - 1][xx] - sum[i - 1][xx] + n                                  (j - k >= 0 ? sum[i - 1][j - k] : 0LL)); n             for (long long int xx = j + 1; xx < min(m, j + k); xx++) n               res = max(res, dp[i - 1][xx] - sum[i - 1][j] + n                                  (xx - k >= 0 ? sum[i - 1][xx - k] : 0LL)); n             dp[i][j] += res; n           } n         } n         mx_p[i][j] = dp[i][j]; n         if (j - 1 >= 0) mx_p[i][j] = max(mx_p[i][j], mx_p[i][j - 1]); n       } n     } n     for (long long int j = m - 1; j >= 0; j--) { n       if (j == m - 1) n         mx_s[i][j] = dp[i][j]; n       else n         mx_s[i][j] = max(mx_s[i][j + 1], dp[i][j]); n     } n   } n   long long int ans = 0; n   for (long long int j = 0; j < m; j++) { n     ans = max(ans, dp[n][j]); 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   long long int t; n   t = 1; n   while (t--) solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int T = 1; n   cin >> T; n   while (T--) { n     string s; n     int x; n     cin >> s >> x; n     string ans; n     int n = s.size(); n     for (int i = 0; i < n; i++) ans.push_back( 1 ); n     for (int i = 0; i < n; i++) { n       if (s[i] ==  0 ) { n         if (i - x >= 0) ans[i - x] =  0 ; n         if (i + x < n) ans[i + x] =  0 ; n       } n     } n     bool f = 1; n     for (int i = 0; i < n; i++) { n       if (s[i] ==  1 ) { n         bool t = 0; n         if (i + x < n && ans[i + x] ==  1 ) t = 1; n         if (i - x >= 0 && ans[i - x] ==  1 ) t = 1; n         if (!t) f = 0; n       } n     } n     if (f) n       cout << ans << endl; n     else n       cout <<  -1 n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 1e5 + 1; n int n, m; n vector<int> A[MAXN]; n int d[MAXN]; n void dfs(int nod) { n   for (int i = 0; i < A[nod].size(); i++) { n     int v = A[nod][i]; n     if (d[v] == 0) { n       d[v] = d[nod] + 1; n       dfs(v); n     } n   } n } n int main() { n   cin >> n >> m; n   for (int i = 0; i < m; i++) { n     int a, b; n     cin >> a >> b; n     A[a].push_back(b); n     A[b].push_back(a); n   } n   d[1] = 1; n   dfs(1); n   int u = max_element(d + 1, d + n + 1) - d; n   fill(d + 1, d + n + 1, 0); n   d[u] = 1; n   dfs(u); n   int sol = *max_element(d + 1, d + n + 1); n   sol--; n   cout << sol <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 7, mod = 1e9 + 7; n int dp[N], sum[N], i, n, m, j, k, nxt[N], v[N]; n char a[N], b[N]; n int main() { n   for (scanf( %s%s , a + 1, b + 1), n = strlen(a + 1), m = strlen(b + 1), i = 2; n        i <= m; ++i) { n     while (b[j + 1] != b[i] && j) j = nxt[j]; n     if (b[j + 1] == b[i]) j++; n     nxt[i] = j; n   } n   for (i = 1, j = 0; i <= n; ++i) { n     while (b[j + 1] != a[i] && j) j = nxt[j]; n     if (b[j + 1] == a[i]) j++; n     if (j == m) v[i] = 1, j = nxt[j]; n   } n   for (i = 1, j = -1; i <= n; ++i) { n     dp[i] = dp[i - 1]; n     if (v[i]) j = i - m + 1; n     if (j != -1) dp[i] += sum[j - 1] + j, dp[i] %= mod; n     sum[i] = (sum[i - 1] + dp[i]) % mod; n   } n   return 0 * printf( %d n , dp[n]); n } n


#include <bits/stdc++.h> n using namespace std; n long long int vis[1005][1005]; n char a[1005][1005]; n pair<pair<long long int, long long int>, long long int> fuck[1005][1005]; n long long int dfs(long long int i, long long int j, n                   pair<long long int, long long int> par) { n   vis[i][j] = 1; n   long long int ret = 1; n   if (a[i + 1][j] ==  .  && vis[i + 1][j] == 0) ret += dfs(i + 1, j, par); n   if (a[i - 1][j] ==  .  && vis[i - 1][j] == 0) ret += dfs(i - 1, j, par); n   if (a[i][j + 1] ==  .  && vis[i][j + 1] == 0) ret += dfs(i, j + 1, par); n   if (a[i][j - 1] ==  .  && vis[i][j - 1] == 0) ret += dfs(i, j - 1, par); n   fuck[i][j] = make_pair(par, ret); n   return ret; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int TESTS = 1; n   while (TESTS--) { n     long long int i, j; n     for (i = 0; i < 1005; i++) { n       for (j = 0; j < 1005; j++) { n         vis[i][j] = 0; n         a[i][j] =  * ; n       } n     } n     long long int n, m; n     cin >> n >> m; n     for (i = 1; i <= n; i++) { n       for (j = 1; j <= m; j++) { n         cin >> a[i][j]; n       } n     } n     for (i = 1; i <= n; i++) { n       for (j = 1; j <= m; j++) { n         if (a[i][j] ==  .  && vis[i][j] == 0) { n           dfs(i, j, make_pair(i, j)); n         } n       } n     } n     for (i = 1; i <= n; i++) { n       for (j = 1; j <= m; j++) { n         if (a[i][j] ==  . ) { n           cout <<  . ; n         } else { n           map<pair<long long int, long long int>, long long int> ma; n           if (a[i + 1][j] ==  . ) { n             ma[fuck[i + 1][j].first] = n                 fuck[fuck[i + 1][j].first.first][fuck[i + 1][j].first.second] n                     .second; n           } n           if (a[i - 1][j] ==  . ) { n             ma[fuck[i - 1][j].first] = n                 fuck[fuck[i - 1][j].first.first][fuck[i - 1][j].first.second] n                     .second; n           } n           if (a[i][j + 1] ==  . ) { n             ma[fuck[i][j + 1].first] = n                 fuck[fuck[i][j + 1].first.first][fuck[i][j + 1].first.second] n                     .second; n           } n           if (a[i][j - 1] ==  . ) { n             ma[fuck[i][j - 1].first] = n                 fuck[fuck[i][j - 1].first.first][fuck[i][j - 1].first.second] n                     .second; n           } n           long long int ans = 1; n           for (auto it : ma) { n             ans += it.second; n           } n           cout << ans % 10; n         } n       } n       cout <<   n ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int mod = 998244353, N = 1e5; n int cnt[200], seq[200][17], fac[20], inv[20], ifac[20], popcnt[N], ln[N][17], n     tmp[N][17], ans[N], finalans[N], w[N], n, K, c; n int qmod1(const int &x) { return x >= mod ? x - mod : x; } n int qmod2(const int &x) { return x + (x >> 31 & mod); } n int qpower(int a, int b) { n   int ans = 1; n   for (; b; b >>= 1, a = 1ll * a * a % mod) n     if (b & 1) ans = 1ll * ans * a % mod; n   return ans; n } n void prework(int n) { n   fac[0] = ifac[0] = 1; n   for (int i = 1; i <= n; i++) fac[i] = 1ll * fac[i - 1] * i % mod; n   inv[1] = 1; n   for (int i = 2; i <= n; i++) n     inv[i] = 1ll * (mod - mod / i) * inv[mod % i] % mod; n   for (int i = 1; i <= n; i++) ifac[i] = 1ll * ifac[i - 1] * inv[i] % mod; n   for (int i = 1; i < (1 << 16); i++) popcnt[i] = popcnt[i >> 1] + (i & 1); n } n struct Basis { n   int size, a[20], id[20]; n   void clear() { n     for (int i = 0; i < c; i++) a[i] = 0, id[i] = -1; n     size = 0; n   } n   void ins(int x) { n     for (int i = c - 1; i >= 0; i--) n       if (x >> i & 1) { n         if (!a[i]) { n           a[i] = x, id[i] = size++; n           return; n         } n         x ^= a[i]; n       } n   } n   int get(int x) { n     int ans = 0; n     for (int i = c - 1; i >= 0; i--) n       if (a[i] && (x >> i & 1)) ans ^= 1 << id[i], x ^= a[i]; n     return ans; n   } n   int iget(int x) { n     int ans = 0; n     for (int i = c - 1; i >= 0; i--) n       if (a[i] && (x >> id[i] & 1)) ans ^= a[i]; n     return ans; n   } n } xxj; n int main() { n   scanf( %d%d%d , &n, &K, &c); n   prework(K); n   int wsum = 0; n   int seqn = 0; n   map<unsigned long long, int> mp; n   for (int i = 1; i <= n; i++) { n     scanf( %d , w + i); n     wsum ^= w[i]; n     int tmpseq[17]; n     for (int j = 1; j <= K; j++) tmpseq[j] = w[i] ^ (w[i] - j); n     unsigned long long hsh = 0; n     for (int j = 1; j <= K; j++) hsh = hsh * 19260817 + tmpseq[j] + 233; n     if (!mp[hsh]) { n       ++seqn; n       copy(tmpseq + 1, tmpseq + K + 1, seq[seqn] + 1); n       mp[hsh] = seqn; n       cnt[seqn] = 1; n     } else n       cnt[mp[hsh]]++; n   } n   for (int T = 1, tS[17]; T <= seqn; T++) { n     xxj.clear(); n     for (int i = 1; i <= K; i++) xxj.ins(seq[T][i]); n     int B = xxj.size; n     for (int i = 1; i <= K; i++) tS[i] = xxj.get(seq[T][i]); n     for (int S = 0; S < (1 << B); S++) fill(tmp[S], tmp[S] + K + 1, 0); n     for (int i = 1; i <= K; i++) { n       for (int S = 0; S < (1 << B); S++) { n         unsigned long long t = 0; n         for (int j = 1; j <= i; j++) n           t += 1ull * tmp[S ^ tS[j]][i - j] * ifac[j]; n         tmp[S][i] = qmod2(-(int)(t % mod)); n       } n       tmp[tS[i]][i] = qmod1(tmp[tS[i]][i] + ifac[i - 1]); n     } n     for (int S = 0, rS; S < (1 << B); S++) { n       rS = xxj.iget(S); n       for (int i = 1; i <= K; i++) n         ln[rS][i] = (ln[rS][i] + 1ull * cnt[T] * tmp[S][i]) % mod; n     } n   } n   for (int i = 1, tmp[17]; i < (1 << c); i <<= 1) n     for (int j = 0; j < (1 << c); j += i << 1) n       for (int k = 0; k < i; k++) { n         int *a = ln[j + k], *b = ln[i + j + k]; n         copy(b, b + K + 1, tmp); n         for (int t = 0; t <= K; t++) n           b[t] = qmod2(a[t] - b[t]), a[t] = qmod1(a[t] + tmp[t]); n       } n   for (int S = 0, f[17], g[17]; S < (1 << c); S++) { n     copy(ln[S], ln[S] + K + 1, f); n     g[0] = 1; n     for (int i = 1; i <= K; i++) { n       unsigned long long t = 0; n       for (int j = 1; j <= i; j++) t += 1ull * f[j] * g[i - j]; n       g[i] = t % mod * inv[i] % mod; n     } n     ans[S] = 1ll * g[K] * fac[K] % mod; n   } n   for (int i = 1; i < (1 << c); i <<= 1) n     for (int j = 0; j < (1 << c); j += i << 1) n       for (int k = 0; k < i; k++) { n         int t = ans[i + j + k]; n         ans[i + j + k] = qmod2(ans[j + k] - t), n                     ans[j + k] = qmod1(ans[j + k] + t); n       } n   int iv = mod - ((mod - 1) >> c); n   iv = 1ll * iv * qpower(n, mod - 1 - K) % mod; n   for (int i = 0; i < (1 << c); i++) ans[i] = 1ll * ans[i] * iv % mod; n   for (int i = 0; i < (1 << c); i++) finalans[i ^ wsum] = ans[i]; n   for (int i = 0; i < (1 << c); i++) printf( %d  , finalans[i]); n   puts(  ); n } n


#include <bits/stdc++.h> n #pragma GCC optimize( unroll-loops ) n using namespace std; n mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); n const int N = 45000; n int h, lgn, n, t, r, x, y, a[N], dis[N], lp[N], dp[N][17]; n vector<pair<int, int> > e1, e2; n vector<int> g[N]; n bool mark[N]; n int lg(int xx) { n   int l = 0; n   while (xx > 1) { n     xx /= 2; n     ++l; n   } n   return l; n } n void bfs(int d, vector<int> &v) { n   vector<int> w; n   for (int i = 0; i < v.size(); i++) { n     for (int j = 0; j < g[v[i]].size(); j++) { n       if (dis[g[v[i]][j]] == INT32_MAX) { n         dis[g[v[i]][j]] = d + 1; n         w.push_back(g[v[i]][j]); n       } n     } n   } n   if (!w.empty()) bfs(d + 1, w); n } n void dfs(int v) { n   mark[v] = true; n   for (int i = 0; i < g[v].size(); i++) { n     if (!mark[g[v][i]]) { n       dis[g[v][i]] = dis[v] + 1; n       dp[g[v][i]][0] = v; n       for (int j = 1; j <= lgn; j++) n         dp[g[v][i]][j] = dp[dp[g[v][i]][j - 1]][j - 1]; n       dfs(g[v][i]); n     } n   } n } n int par(int v, int p) { n   while (p > 0) { n     int pp = p & (-p); n     v = dp[v][lg(pp)]; n     p -= pp; n   } n   return v; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   cin >> h >> t >> r >> x; n   int hh, tt; n   for (int i = 0; i < x; i++) { n     cin >> hh >> tt; n     e1.push_back({hh, tt}); n   } n   cin >> y; n   for (int i = 0; i < y; i++) { n     cin >> hh >> tt; n     e2.push_back({hh, tt}); n   } n   for (int i = r; i >= 0; i--) { n     for (int j = r - i; j >= 0; j--) { n       for (int k = 0; k < min(x, i); k++) { n         if ((i - k - 1 + e1[k].first + j + e1[k].second) <= r) n           g[(r + 1) * i + j].push_back((i - k - 1 + e1[k].first) * (r + 1) + j + n                                        e1[k].second); n       } n       for (int k = 0; k < min(y, j); k++) { n         if ((i + e2[k].first + j - k - 1 + e2[k].second) <= r) n           g[(r + 1) * i + j].push_back((i + e2[k].first) * (r + 1) + j - k - 1 + n                                        e2[k].second); n       } n     } n   } n   n = (r + 1) * (r + 1); n   lgn = lg(n); n   int s = h * (r + 1) + t; n   fill(dis, dis + n, INT32_MAX); n   vector<int> v; n   v.push_back(s); n   dis[s] = 0; n   bfs(0, v); n   if (dis[0] != INT32_MAX) { n     cout <<  Ivan n  << dis[0]; n     return 0; n   } n   for (int i = 0; i < n; i++) fill(dp[i], dp[i] + 17, s); n   dfs(s); n   for (int i = 0; i < n; i++) { n     if (dis[i] != INT32_MAX) { n       for (int j = 0; j < g[i].size(); j++) { n         if (dis[g[i][j]] <= dis[i] && n             g[i][j] == par(i, dis[i] - dis[g[i][j]])) { n           cout <<  Draw ; n           return 0; n         } n       } n     } n   } n   for (int i = 0; i < n; i++) { n     if (dis[i] != INT32_MAX) { n       for (int j = 0; j < g[i].size(); j++) ++a[g[i][j]]; n     } n   } n   vector<int> w; n   w.push_back(s); n   while (!w.empty()) { n     int u = w[w.size() - 1]; n     w.pop_back(); n     for (int i = 0; i < g[u].size(); i++) { n       --a[g[u][i]]; n       lp[g[u][i]] = max(lp[g[u][i]], lp[u] + 1); n       if (a[g[u][i]] == 0) w.push_back(g[u][i]); n     } n   } n   int ans = 0; n   for (int i = 0; i < n; i++) ans = max(ans, lp[i]); n   cout <<  Zmey n  << ans + 1; n } n


#include <bits/stdc++.h> n typedef long long ll; n typedef long double ld; n #define fr(i, a, b) for (ll i = a; i < b; i++) n #define rf(i, a, b) for (ll i = a; i >= b; i--) n typedef std::vector<long long> vi; n #define F first n #define S second n #define fast                        n     ios_base::sync_with_stdio(0);   n     cin.tie(0);                     n     cout.tie(0); n #define mod 1000000007 n #define PB push_back n #define MP make_pair n #define PI 3.14159265358979323846 n #define all(a) a.begin(), a.end() n #define mx(a) *max_element(all(a)) n #define mn(a) *min_element(all(a)) n const ll INF = LLONG_MAX / 2; n const ll N = 2e5 + 1; n using namespace std; n void solve() n { n     ll n, c; n     cin >> n >> c; n     ll a[n], b[n]; n     fr(i, 0, n) n     { n         cin >> a[i]; n     } n     fr(i, 1, n) n             cin >> n         b[i]; n     ll ans = INF, prevcoins = 0, prevdays = 0; n     fr(i, 0, n - 1) n     { n         if (c <= prevcoins) n             ans = min(prevdays, ans); n         ans = min(prevdays + (c - prevcoins + a[i] - 1) / a[i], ans); n         // cout << prevdays + (c - prevcoins + a[i] - 1) / a[i] <<    ; n         if (prevcoins >= b[i + 1]) n         { n             prevcoins = prevcoins - b[i + 1]; n             prevdays++; n         } n         else n         { n             prevdays = prevdays + (b[i + 1] + a[i] - 1 - prevcoins) / a[i] + 1; n             prevcoins = ((b[i + 1] + a[i] - 1 - prevcoins) / a[i]) * a[i] + prevcoins - b[i + 1]; n         } n         // cout << prevdays <<     << prevcoins <<   n ; n     } n     ll i = n - 1; n     ans = min(prevdays + (c - prevcoins + a[i] - 1) / a[i], ans); n     // cout <<   n ; n     cout << ans <<   n ; n } n int main() n { n     fast; n     ll t = 1; n     std::cin >> t; n     while (t--) n     { n         solve(); n     } n }


#include <bits/stdc++.h> n using namespace std; n long long int max(long long int a, long long int b) { n   if (a > b) return a; n   return b; n } n long long int min(long long int a, long long int b) { n   if (a < b) return a; n   return b; n } n long long int msb(long long int n) { n   long long int ans; n   for (long long int i = 31; i >= 0; i--) n     if ((1LL << i) & (n)) { n       ans = i; n       break; n     } n   return ans; n } n long long power(long long x, int y, int p) { n   long long res = 1; n   x = x % p; n   while (y > 0) { n     if (y & 1) res = (res * x) % p; n     y = y >> 1; n     x = (x * x) % p; n   } n   return res; n } n long long int modFact(long long int n, long long int p) { n   if (n >= p) return 0; n   long long int result = 1; n   for (long long int i = 1; i <= n; i++) result = (result * i) % p; n   return result; n } n long long modInverse(long long n, int p) { return power(n, p - 2, p); } n long long nCrModPFermat(long long n, int r, int p) { n   if (r == 0) return 1; n   long long fac[n + 1]; n   fac[0] = 1; n   for (int i = 1; i <= n; i++) fac[i] = (fac[i - 1] * i) % p; n   return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) % n          p; n } n vector<long long int> primes; n void sieve(long long int n) { n   bool prime[n + 1]; n   memset(prime, true, sizeof(prime)); n   for (long long int p = 2; p <= n; p++) { n     if (prime[p] == true) { n       for (long long int i = p * p; i <= n; i += p) prime[i] = false; n     } n   } n   for (long long int p = 2; p <= n; p++) n     if (prime[p]) primes.push_back(p); n } n vector<long long int> adj[100001], rev[100001]; n bool vis[100001], recur[100001]; n void init(long long int n) { n   for (long long int i = 0; i <= n; i++) { n     adj[i].clear(); n     rev[i].clear(); n     vis[i] = false; n     recur[i] = false; n   } n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   long long int n, x, k; n   cin >> n >> x >> k; n   long long int ar[n]; n   for (int i = 0; i < n; i++) cin >> ar[i]; n   if (x > k) n     cout << n << endl; n   else { n     int ct = 0; n     for (int i = 0; i < n; i++) { n       if (ar[i] <= x) ct++; n     } n     double ans = double(ct) / 2.0; n     cout << ceil(ans) << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long oo = 1LL << 55; n const int MAX_N = 100005; n const int MAX_M = 100005; n const int MAX_P = 105; n template <class T> n class Deque { n  public: n   Deque() { Clear(); } n   void Clear() { front = 1, back = 0; } n   void PushBack(const T x) { values[++back] = x; } n   void PopBack() { --back; } n   void PopFront() { ++front; } n   T Front() const { return values[front]; } n   T Back() const { return values[back]; } n   bool Empty() const { return front > back; } n   int Size() const { return back - front + 1; } n   T &operator[](const int index) { return values[front + index]; } n  n  private: n   T values[MAX_M]; n   int front, back; n }; n class Line { n  public: n   long long m, n; n   Line() {} n   Line(const long long m, const long long n) { n     this->m = m; n     this->n = n; n   } n   long long Value(const long long x) const { return m * x + n; } n   static double Intersect(const Line &L1, const Line &L2) { n     return (1.0 * L2.n - L1.n) / (1.0 * L1.m - L2.m); n   } n }; n int N, M, P, D[MAX_N], T[MAX_M]; n long long SumT[MAX_M], DP[2][MAX_M], Solution; n void Preprocess() { n   T[0] = 0; n   sort(T + 1, T + M + 1); n   SumT[0] = 0; n   for (int i = 1; i <= M; ++i) SumT[i] = SumT[i - 1] + T[i]; n } n void Solve() { n   Preprocess(); n   DP[0][0] = 0; n   for (int i = 1; i <= M; ++i) DP[0][i] = 1LL * T[i] * i - SumT[i]; n   for (int p = 2; p <= P; ++p) { n     Deque<Line> deq; n     for (int i = p; i <= M; ++i) { n       Line L = Line(-(i - 1), SumT[i - 1] + DP[0][i - 1]); n       while (deq.Size() > 1 && n              Line::Intersect(deq[deq.Size() - 1], L) < n                  Line::Intersect(deq[deq.Size() - 2], deq[deq.Size() - 1])) n         deq.PopBack(); n       deq.PushBack(L); n       while (deq.Size() > 1 && Line::Intersect(deq[0], deq[1]) < 1.0 * T[i]) n         deq.PopFront(); n       DP[1][i] = deq.Front().Value(T[i]) + 1LL * i * T[i] - SumT[i]; n     } n     memcpy(DP[0], DP[1], sizeof(DP[1])); n   } n   Solution = DP[0][M]; n } n void Read() { n   cin >> N >> M >> P; n   D[1] = 0; n   for (int i = 2; i <= N; ++i) { n     cin >> D[i]; n     D[i] += D[i - 1]; n   } n   for (int i = 1; i <= M; ++i) { n     int h, t; n     cin >> h >> t; n     T[i] = t - D[h]; n   } n } n void Print() { cout << Solution <<   n ; } n int main() { n   Read(); n   Solve(); n   Print(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 355001; n const int SQRTN = 320; n const int LOGN = 20; n const long double PI = acos(-1); n const long double TAU = 2 * PI; n long long nk, n, k, a, b; n vector<long long> first, last; n long long gcd(long long x, long long b) { n   if (b == 0) return x; n   return gcd(b, x % b); n } n signed main() { n   cin >> n >> k >> a >> b; n   nk = n * k; n   first.push_back(a); n   first.push_back(k - a); n   last.push_back(b); n   last.push_back(k - b); n   for (int i = 0; i < n; i++) { n     last.push_back((last[0] + nk - i * k) % nk); n     last.push_back((last[1] + nk - i * k) % nk); n     last.push_back((i * k + last[0]) % nk); n     last.push_back((i * k + last[1]) % nk); n   } n   long long mn = 100000000000000ll, mx = 0; n   for (int i = 0; i < last.size(); i++) { n     mn = min(mn, nk / gcd(nk, abs(last[i] - first[0]))); n     mx = max(mx, nk / gcd(nk, abs(last[i] - first[0]))); n     mx = max(mx, nk / gcd(nk, abs(last[i] - first[1]))); n     mn = min(mn, nk / gcd(nk, abs(last[i] - first[1]))); n   } n   cout << mn <<     << mx << endl; n } n


#include <bits/stdc++.h> n using namespace std; n long long R[10 << 10][1 << 10]; n int A[10 << 10]; n int n, m, g, r; n int main() { n   cin >> n >> m; n   int i, j; n   for (i = (0); i < (m); ++i) cin >> A[i]; n   cin >> g >> r; n   sort(A, A + m); n   for (i = (0); i < (m); ++i) n     for (j = (0); j < (g + 1); ++j) R[i][j] = (1LL << 60); n   R[0][0] = 0; n   deque<pair<long long, pair<int, int>>> q; n   q.push_front(make_pair(R[0][0], pair<int, int>(0, 0))); n   long long res = (1LL << 60); n   while (!q.empty()) { n     int pos = q.front().second.first; n     int rem = q.front().second.second; n     long long val = q.front().first; n     q.pop_front(); n     if (R[pos][rem] != val) continue; n     if (pos == m - 1) res = min(res, val); n     int p[] = {pos - 1, pos + 1}; n     int d[] = {pos == 0 ? -1 : A[pos] - A[pos - 1], n                pos + 1 == m ? -1 : A[pos + 1] - A[pos]}; n     for (i = (0); i < (2); ++i) n       if (0 <= p[i] && p[i] < m && d[i] > 0 && rem + d[i] <= g) { n         int pos2 = p[i]; n         int rem2 = rem + d[i]; n         int val2 = val + d[i]; n         if (R[pos2][rem2] > val2) { n           R[pos2][rem2] = val2; n           q.push_front(make_pair(R[pos2][rem2], pair<int, int>(pos2, rem2))); n         } n       } n     if (rem == g) { n       int pos2 = pos; n       int rem2 = 0; n       int val2 = val + r; n       if (R[pos2][rem2] > val2) { n         R[pos2][rem2] = val2; n         q.push_back(make_pair(R[pos2][rem2], pair<int, int>(pos2, rem2))); n       } n     } n   } n   if (res == (1LL << 60)) res = -1; n   cout << res << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   int t; n   cin >> t; n   for (int i = 0; i < t; i++) { n     int a, b; n     cin >> a >> b; n     int moves = 0; n     if (a == b) { n       cout << 0 <<   n ; n       continue; n     } else if (a < b) { n       int needed = b - a; n       moves = needed % 2 == 1 ? 1 : 2; n     } else { n       int needed = a - b; n       moves = needed % 2 == 0 ? 1 : 2; n     } n     cout << moves <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct lady { n   int b, i, r; n } a[500005]; n bool operator<(const lady& a, const lady& b) { n   if (a.b != b.b) return a.b > b.b; n   if (a.i != b.i) return a.i < b.i; n   return a.r < b.r; n } n int n; n void inp() { n   scanf( %d , &n); n   for (int i = 1; i <= n; ++i) scanf( %d , &a[i].b); n   for (int i = 1; i <= n; ++i) scanf( %d , &a[i].i); n   for (int i = 1; i <= n; ++i) scanf( %d , &a[i].r); n } n set<int> s; n int x[500005], m; n void ready() { n   for (int i = 1; i <= n; ++i) s.insert(a[i].i); n   for (typeof((s).begin()) it = (s).begin(); it != (s).end(); ++it) n     x[++m] = *it; n } n int bi[500005], ans; n inline void update(int u, int val) { n   u = lower_bound(x + 1, x + m + 1, u) - x; n   for (; u; u &= u - 1) bi[u] = max(bi[u], val); n } n inline int get(int u) { n   u = lower_bound(x + 1, x + m + 1, u) - x; n   int res = 0; n   for (; u <= m; u += u & -u) res = max(res, bi[u]); n   return res; n } n void solve() { n   ready(); n   sort(a + 1, a + n + 1); n   for (int i = 1; i <= n; ++i) { n     ans += get(a[i].i + 1) > a[i].r; n     update(a[i].i, a[i].r); n   } n   printf( %d n , ans); n } n int main() { n   srand(time(NULL)); n   inp(); n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   int n, s; n   cin >> n >> s; n   vector<int> g(n); n   for (int i = 0; i < n - 1; i++) { n     int u, v; n     cin >> u >> v; n     u--; n     v--; n     g[u]++; n     g[v]++; n   } n   int cnt = 0; n   for (int i = 0; i < n; i++) { n     if (g[i] == 1) { n       cnt++; n     } n   } n   double ans = s; n   if (n > 2) { n     ans = 2.0 * s / cnt; n   } n   cout.precision(10); n   cout << fixed << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e5 + 5; n int n; n double r, v, l; n double tim(double p1, double p2) { n   double rem = p2 - p1; n   double k = int(rem / l); n   rem = rem - k * l; n   double le = 0, ri = 1e9, mid; n   for (int I = 1; I <= 200; I++) { n     mid = (le + ri) / 2.0; n     if (v * mid + 2 * sin(v * mid / (2 * r)) * r >= rem) { n       ri = mid; n     } else { n       le = mid; n     } n   } n   return mid + double(k * l) / v; n } n int main() { n   scanf( %d%lf%lf , &n, &r, &v); n   l = 3.141592653589 * r * 2; n   for (int i = 1; i <= n; i++) { n     int p1, p2; n     scanf( %d%d , &p1, &p2); n     printf( %.10f n , float(tim(double(p1), double(p2)))); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } n const int MAXN = 58; n const int MAXQ = 5000; n int n; n int bto[MAXN - 1], rto[MAXN - 1]; n int nq; n int qat[MAXQ]; n char qlast[MAXQ][MAXN - 1 + 1]; n long long qans[MAXQ]; n int dr[MAXN - 1]; n void mlt64(unsigned long long x, unsigned long long y, unsigned long long& hi, n            unsigned long long& lo) { n   unsigned long long xhi = x >> 32, xlo = x & ((1ULL << 32) - 1), yhi = y >> 32, n                      ylo = y & ((1ULL << 32) - 1); n   unsigned long long zlo = xlo * ylo, tmp = xhi * ylo + (zlo >> 32), n                      zmi = tmp & ((1ULL << 32) - 1), zhi = tmp >> 32; n   zmi += xlo * yhi, zhi += xhi * yhi; n   lo = (zlo & (1ULL << 32) - 1) + ((zmi & (1ULL << 32) - 1) << 32), n   hi = zhi + (zmi >> 32); n } n template <int k> n struct MersenneMod64bit { n   constexpr static unsigned long long mod() { return (1ULL << k) - 1; } n   unsigned long long val; n   MersenneMod64bit() { val = 0; } n   MersenneMod64bit(unsigned long long _val) { n     val = (_val & mod()) + (_val >> k); n     if (val >= mod()) val -= mod(); n   } n   const unsigned long long operator()() const { return val; } n   MersenneMod64bit& operator+=(const MersenneMod64bit& other) { n     val += other.val; n     if (val >= mod()) val -= mod(); n     return *this; n   } n   MersenneMod64bit& operator-=(const MersenneMod64bit& other) { n     if (val >= other.val) n       val -= other.val; n     else n       val += mod() - other.val; n     return *this; n   } n   MersenneMod64bit& operator*=(const MersenneMod64bit& other) { n     unsigned long long hi, lo; n     mlt64(val, other.val, hi, lo); n     val = (lo & mod()) + (lo >> k) + (hi << (64 - k)); n     if (val >= mod()) val -= mod(); n     return *this; n   } n   MersenneMod64bit& operator/=(const MersenneMod64bit& other) { n     return *this *= other.inverse(); n   } n   MersenneMod64bit operator*(const MersenneMod64bit& other) const { n     return MersenneMod64bit(*this) *= other; n   } n   bool operator==(const MersenneMod64bit& other) { return val == other.val; } n   bool operator!=(const MersenneMod64bit& other) { return val != other.val; } n   MersenneMod64bit pw(unsigned long long n) const { n     MersenneMod64bit ret = 1, x = *this; n     while (true) { n       if (n & 1) ret *= x; n       if ((n >>= 1) == 0) return ret; n       x *= x; n     } n   } n   MersenneMod64bit inverse() const { return pw(mod() - 2); } n }; n template <int k> n ostream& operator<<(ostream& stream, const MersenneMod64bit<k>& number) { n   return stream << number(); n } n template <typename T> n struct Matrix { n   int n, m; n   vector<vector<T>> A; n   Matrix(int n) : n(n), m(n) { A = vector<vector<T>>(n, vector<T>(m, 0)); } n   Matrix(int n, int m) : n(n), m(m) { n     A = vector<vector<T>>(n, vector<T>(m, 0)); n   } n   vector<T>& operator[](int i) { return A[i]; } n   void gaussjord() { n     int R = n, C = m, r = 0, c = 0; n     while (r < R && c < C) { n       { n         int rr = r; n         while (rr < R && A[rr][c] == 0) ++r; n         if (rr >= R) { n           ++c; n           continue; n         } n         if (rr != r) n           for (int cc = (c); cc < (C); ++cc) swap(A[r][cc], A[rr][cc]); n       } n       if (A[r][c] != 1) { n         T x = 1; n         x /= A[r][c]; n         for (int cc = (c + 1); cc < (C); ++cc) A[r][cc] *= x; n         A[r][c] = 1; n       } n       for (int rr = (0); rr < (R); ++rr) n         if (rr != r && A[rr][c] != 0) { n           for (int cc = (c + 1); cc < (C); ++cc) n             A[rr][cc] -= A[rr][c] * A[r][cc]; n           A[rr][c] = 0; n         } n       ++r, ++c; n     } n   } n   Matrix inverse() { n     assert(n == m); n     Matrix B(n, 2 * n); n     for (int i = (0); i < (n); ++i) n       for (int j = (0); j < (n); ++j) n         B[i][j] = A[i][j], B[i][n + j] = i == j ? 1 : 0; n     B.gaussjord(); n     for (int i = (0); i < (n); ++i) assert(B[i][i] == 1); n     Matrix ret(n); n     for (int i = (0); i < (n); ++i) n       for (int j = (0); j < (n); ++j) ret[i][j] = B[i][n + j]; n     return ret; n   } n   Matrix operator*(const Matrix& other) const { n     assert(m == other.n); n     Matrix ret(n, other.m); n     for (int i = (0); i < (n); ++i) n       for (int j = (0); j < (other.m); ++j) n         for (int k = (0); k < (m); ++k) ret[i][j] += A[i][k] * other.A[k][j]; n     return ret; n   } n   vector<T> operator*(const vector<T>& vec) const { n     assert(m == ((int)(vec).size())); n     vector<T> ret(n, 0); n     for (int i = (0); i < (n); ++i) n       for (int k = (0); k < (m); ++k) ret[i] += A[i][k] * vec[k]; n     return ret; n   } n   void print() { n     for (int i = (0); i < (n); ++i) { n       for (int j = (0); j < (m); ++j) { n         if (j != 0) cout <<    ; n         cout << A[i][j]; n       } n       cout <<   n ; n     } n   } n }; n using M61 = MersenneMod64bit<61>; n using Mat = Matrix<M61>; n using Vec = vector<M61>; n bool dec(unsigned long long& a, unsigned long long b) { n   if (a < b) return false; n   a -= b; n   return true; n } n bool solveslinearequation(int q, const Vec& x) { n   for (int i = (0); i < (n - 1); ++i) dr[i] = qlast[q][i] ==  B  ? 0 : 1; n   bool ok = true; n   vector<unsigned long long> bal(n, 0); n   for (int i = (0); i < (n - 1); ++i) bal[i] += 2 * x[i]() + dr[i]; n   ++bal[qat[q]]; n   for (int i = (0); i < (n - 1); ++i) { n     ok = ok && dec(bal[bto[i]], x[i]()); n     ok = ok && dec(bal[rto[i]], x[i]() + dr[i]); n   } n   ok = ok && dec(bal[0], 1); n   for (int i = (0); i < (n); ++i) ok = ok && bal[i] == 0; n   return ok; n } n bool visitedstatesgotodestination(int q, const Vec& x) { n   for (int i = (0); i < (n - 1); ++i) dr[i] = qlast[q][i] ==  B  ? 0 : 1; n   vector<bool> visited(n - 1); n   for (int i = (0); i < (n - 1); ++i) visited[i] = x[i]() > 0 || dr[i] > 0; n   vector<vector<int>> radj(n); n   for (int i = (0); i < (n); ++i) n     if (qlast[q][i] ==  B ) n       radj[bto[i]].push_back(i); n     else n       radj[rto[i]].push_back(i); n   queue<int> queue; n   vector<bool> todest(n, false); n   todest[qat[q]] = true, queue.push(qat[q]); n   while (!queue.empty()) { n     int at = queue.front(); n     queue.pop(); n     for (int i = (0); i < (((int)(radj[at]).size())); ++i) { n       int to = radj[at][i]; n       if (!todest[to]) todest[to] = true, queue.push(to); n     } n   } n   for (int i = (0); i < (n); ++i) n     if (visited[i] && !todest[i]) return false; n   return true; n } n void solve() { n   Mat A(n - 1); n   for (int i = (0); i < (n - 1); ++i) { n     A[i][i] -= 2; n     if (bto[i] != n - 1) A[bto[i]][i] += 1; n     if (rto[i] != n - 1) A[rto[i]][i] += 1; n   } n   Mat Ainv = A.inverse(); n   for (int q = (0); q < (nq); ++q) { n     for (int i = (0); i < (n - 1); ++i) dr[i] = qlast[q][i] ==  B  ? 0 : 1; n     Vec y(n - 1); n     y[0] -= 1; n     y[qat[q]] += 1; n     for (int i = (0); i < (n - 1); ++i) { n       y[i] += dr[i]; n       if (rto[i] != n - 1) y[rto[i]] -= dr[i]; n     } n     Vec x = Ainv * y; n     bool ok = solveslinearequation(q, x) && visitedstatesgotodestination(q, x); n     if (!ok) n       qans[q] = -1; n     else { n       qans[q] = 0; n       for (int i = (0); i < (n - 1); ++i) qans[q] += 2 * x[i]() + dr[i]; n     } n   } n } n void run() { n   scanf( %d , &n); n   for (int i = (0); i < (n - 1); ++i) n     scanf( %d%d , &bto[i], &rto[i]), --bto[i], --rto[i]; n   scanf( %d , &nq); n   for (int i = (0); i < (nq); ++i) scanf( %d%s , &qat[i], qlast[i]), --qat[i]; n   solve(); n   for (int i = (0); i < (nq); ++i) printf( %lld n , qans[i]); n } n int main() { n   run(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double EPS = 1e-9; n const double PI = 3.14159265359; n vector<long long> primes; n void GeneratingPrimes(int top) { n   vector<bool> p(top + 1, 1); n   p[0] = p[1] = 0; n   for (int i = 2; i <= sqrt(top); i++) { n     if (!p[i]) continue; n     if (p[i]) { n       for (int j = i * i; j <= top; j += i) { n         p[j] = 0; n       } n     } n   } n   for (int i = 0; i < top + 1; i++) n     if (p[i]) primes.push_back(i); n } n long long gcd(long long a, long long b) { return (b == 0) ? a : gcd(b, a % b); } n long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); } n void EXTgcd(long long a, long long b, int& x0, int& y0) { n   if (b == 0) { n     x0 = 1, y0 = 0; n     return; n   } n   EXTgcd(b, a % b, x0, y0); n   long long x1 = y0; n   long long y1 = x0 - (a / b) * y0; n   x0 = x1; n   y0 = y1; n } n unsigned long long power(unsigned long long x, unsigned long long y) { n   long long res = 1; n   while (y > 0) { n     if (y & 1) res = (res * x); n     y = y >> 1; n     x = (x * x); n   } n   return res; n } n double dist(double a, double b, double x, double y) { n   return sqrt(pow(a - x, 2) + pow(b - y, 2)); n } n double dist3(double a, double b, double c, double x, double y, double z) { n   return sqrt(pow(a - x, 2) + pow(b - y, 2) + pow(c - z, 2)); n } n int xadd[9] = {1, -1, 0, 1, -1, 0, 1, -1, 0}; n int yadd[9] = {1, -1, 0, -1, 0, 1, 0, 1, -1}; n long long const N = 10007; n long long mod = 1e9 + 7; n int n; n long long x[N], y[N]; n long long c[N], k[N]; n int setsNum; n int siz[N], par[N]; n void build(int n) { n   setsNum = 0; n   for (int i = 0; i < n; i++) { n     par[i] = i; n     siz[i] = 1; n   } n } n int findSet(int x) { n   if (par[x] == x) return x; n   par[x] = findSet(par[x]); n   return par[x]; n } n bool sameSet(int x, int y) { return (par[findSet(x)] == par[findSet(y)]); } n void unionSets(int x, int y) { n   int X = findSet(x), Y = findSet(y); n   if (X == Y) return; n   if (c[X] < c[Y]) { n     par[Y] = par[X]; n   } else { n     par[X] = par[Y]; n   } n } n vector<vector<long long>> sortedE; n int state[N]; n vector<pair<int, int>> e; n int main() { n   cin >> n; n   long long ans = 0, conn = 0, st = n; n   for (int i = 0; i < n; i++) state[i] = 1; n   build(n + 100); n   for (int i = 0; i < n; i++) { n     cin >> x[i] >> y[i]; n   } n   for (int i = 0; i < n; i++) cin >> c[i], ans += c[i]; n   for (int i = 0; i < n; i++) cin >> k[i]; n   for (int i = 0; i < n; i++) n     for (int j = i + 1; j < n; j++) { n       vector<long long> t; n       t.push_back((k[i] + k[j]) * (abs(x[i] - x[j]) + abs(y[i] - y[j]))); n       t.push_back(i); n       t.push_back(j); n       sortedE.push_back(t); n     } n   sort(sortedE.begin(), sortedE.end()); n   for (int i = 0; i < sortedE.size(); i++) { n     if (!sameSet(sortedE[i][1], sortedE[i][2]) && n         sortedE[i][0] + min(c[par[sortedE[i][1]]], c[par[sortedE[i][2]]]) < n             c[par[sortedE[i][1]]] + c[par[sortedE[i][2]]]) { n       ans -= max(c[par[sortedE[i][1]]], c[par[sortedE[i][2]]]); n       if (c[par[sortedE[i][1]]] > c[par[sortedE[i][2]]]) { n         state[par[sortedE[i][1]]] = 0; n       } else n         state[par[sortedE[i][2]]] = 0; n       ans += sortedE[i][0]; n       unionSets(sortedE[i][1], sortedE[i][2]); n       e.push_back(make_pair(sortedE[i][1], sortedE[i][2])); n       conn++, st--; n     } n   } n   cout << ans << endl << st << endl; n   for (int i = 0; i < n; i++) n     if (state[i]) printf( %d  , i + 1); n   cout << endl << conn << endl; n   for (int i = 0; i < e.size(); i++) { n     printf( %d %d n , e[i].first + 1, e[i].second + 1); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, p, q; n   string s; n   bool can = true; n   vector<string> vec; n   int aux = 0; n   int pos = 0; n   cin >> n >> p >> q; n   cin >> s; n   aux = n; n   if (n % p == 0) { n     cout << n / p << endl; n     for (int i = 0; i < n; i += p) { n       cout << s.substr(i, p) << endl; n     } n   } else if (n % q == 0) { n     cout << n / q << endl; n     for (int i = 0; i < n; i += q) { n       cout << s.substr(i, q) << endl; n     } n   } else { n     while (((aux % q != 0)) && pos < n) { n       vec.push_back(s.substr(pos, p)); n       pos += p; n       aux -= p; n       if (aux < 0) { n         can = false; n       } n     } n     if (can) { n       while (pos < n) { n         vec.push_back(s.substr(pos, q)); n         pos += q; n       } n       cout << vec.size() << endl; n       for (int i = 0; i < vec.size(); i++) { n         cout << vec[i] << endl; n       } n     } else { n       cout << -1; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void solve() { n   long long int n, k; n   cin >> n >> k; n   long long int i, a[n + 1]; n   for (i = 1; i <= n; i++) cin >> a[i]; n   if (a[1] == a[n]) { n     cout << 1 << endl; n     return; n   } n   if (k == 1 && a[1] != a[n]) { n     cout << -1 << endl; n     return; n   } n   long long int c = 0; n   for (i = 1; i < n; i++) { n     if (a[i] != a[i + 1]) c++; n   } n   long long int ans = ceil(c * 1.0 / (k - 1)); n   if (ans < 0) ans = 1; n   cout << ans << endl; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   ; n   long long int t; n   cin >> t; n   while (t--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long MOD = 1000 * 1000 * 1000 + 7; n long long mod(long long n) { n   if (n < 0) { n     return (n % MOD + MOD) % MOD; n   } else { n     if (n < MOD) n       return n; n     else if (n < 2 * MOD) n       return n - MOD; n     else n       return n % MOD; n   } n } n long long fp(long long a, long long p) { n   long long ans = 1, cur = a; n   for (long long i = 0; (1 << i) <= p; ++i) { n     if ((p >> i) & 1) ans = mod(ans * cur); n     cur = mod(cur * cur); n   } n   return ans; n } n long long dv(long long a, long long b) { return mod(a * fp(b, MOD - 2)); } n const long long N = 101; n long long m[N][N], ans[N][N], t[N][N]; n void add(long long a[N][N], long long b[N][N]) { n   for (long long i = 0; i < N; ++i) { n     for (long long j = 0; j < N; ++j) { n       t[i][j] = 0; n     } n   } n   for (long long i = 0; i < N; ++i) { n     for (long long j = 0; j < N; ++j) { n       for (long long k = 0; k < N; ++k) { n         t[i][j] = mod(t[i][j] + a[i][k] * b[k][j]); n       } n     } n   } n   for (long long i = 0; i < N; ++i) { n     for (long long j = 0; j < N; ++j) { n       a[i][j] = t[i][j]; n     } n   } n } n void pw(long long p) { n   for (long long i = 0; i < N; ++i) ans[i][i] = 1; n   for (long long i = 0; (1 << i) <= p; ++i) { n     if ((p >> i) & 1) add(ans, m); n     add(m, m); n   } n } n bool a[N]; n long long cnt[2]; n signed main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   long long n, k; n   cin >> n >> k; n   for (long long i = 0; i < n; ++i) { n     cin >> a[i]; n     ++cnt[a[i]]; n   } n   long long l = cnt[0]; n   long long r = n - l; n   long long op = n * (n - 1) / 2; n   for (long long l1 = 0; l1 <= cnt[0] && l1 <= cnt[1]; ++l1) { n     long long l0 = l - l1; n     long long r0 = cnt[0] - l0; n     long long r1 = cnt[1] - l1; n     m[l1][l1] = op; n     if (l1) { n       m[l1][l1 - 1] = mod(l1 * r0); n       m[l1][l1] = mod(m[l1][l1] - m[l1][l1 - 1]); n     } n     m[l1][l1 + 1] = mod(l0 * r1); n     m[l1][l1] = mod(m[l1][l1] - m[l1][l1 + 1]); n   } n   pw(k); n   long long sum = 0; n   for (long long i = 0; i < l; ++i) sum += a[i]; n   cout << dv(ans[sum][0], fp(op, k)) <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n void solve() { n   int a, b, ans; n   cin >> a >> b; n   int x = (a / 4) * 4; n   int i = x, val = 0; n   while (i < a) { n     val = val ^ i; n     i++; n   } n   if (val == b) { n     ans = a; n   } else if ((val ^ a) == b) { n     ans = a + 2; n   } else { n     ans = a + 1; n   } n   cout << ans << endl; n   return; n } n int main() { n   int t; n   cin >> t; n   while (t > 0) { n     solve(); n     t--; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n typedef long long ll; n typedef long double ld; n typedef string str; n  n #define pb push_back n #define ppp pop_back n #define pii pair<int,int> n #define fi first n #define se second n #define stie std::tie n #define vec vector n #define forn(i, l, r) for (int i=l; i<=r; i++) n #define forb(i, r, l) for (int i=r; i>=l; i--) n #define emp empty n #define beg begin n #define ins insert n #define cle clear n #define era erase n #define que queue n #define pque priority_queue n #define mset multiset n #define deq deque n #define sta stack n #define con const n #define rsz resize n #define ass assign n #define lowb lower_bound n #define uppb upper_bound n  n template<class T> void mini(T& a, T b) { a = min(a, b); } n template<class T> void maxi(T& a, T b) { a = max(a, b); } n template<class T1, class T2> ostream& operator<<(ostream &out, pair<T1, T2> a) { return out << a.first <<     << a.second; } n template<class T> ostream& operator<<(ostream& out, vector<T> a) { for (auto& i : a) out << i <<    ; return out; } n template<class T> ostream& operator<<(ostream& out, set<T> a) { for (auto& i : a) out << i <<    ; return out; } n template<class T> ostream& operator<<(ostream& out, multiset<T> a) { for (auto& i : a) out << i <<    ; return out; } n template<class T1, class T2> ostream& operator<<(ostream& out, map<T1, T2> a) { for (auto& i : a) out << i <<   n ; return out; } n template<class T1, class T2> ostream& operator<<(ostream& out, unordered_map<T1, T2> a) { for (auto& i : a) out << i <<   n ; return out; } n template<class T> ostream& operator<<(ostream& out, queue<T> a) { while (!a.empty()) { out << a.front() <<    ; a.pop(); } return out; } n template<class T> ostream& operator<<(ostream& out, deque<T> a) { while (!a.empty()) { out << a.front() <<    ; a.pop_front(); } return out; } n template<class T> ostream& operator<<(ostream& out, priority_queue<T> a) { while (!a.empty()) { out << a.top() <<   n ; a.pop(); } return out; } n template<class T> void out(T a) { cout << a << endl; } n template<class T1, class T2> void out(T1 a, T2 b) { cout << a <<     << b << endl; } n template<class T1, class T2, class T3> void out(T1 a, T2 b, T3 c) { cout << a <<     << b <<     << c << endl; } n template<class T1, class T2, class T3, class T4> void out(T1 a, T2 b, T3 c, T4 d) { cout << a <<     << b <<     << c <<     << d << endl; } n template<class T> void out(vector<vector<T>> a) { for (vector<T> i : a) out(i); } n template<class T> void out_(T a[], int l, int r) { for (int i = l; i <= r; i++) cout << a[i] <<    ; cout << endl; } n void out() { cout <<  OK  << endl; } n template<class T> void sort(vector<T>& a) { sort(a.begin(), a.end()); } n template<class T> void uniq(vector<T>& a) { sort(a); a.erase(unique(a.begin(), a.end()), a.end()); } n template<class T> vector<T> set_int(vector<T> a, vector<T> b) { sort(a); sort(b); vector<T> res; set_intersection(a.begin(), a.end(), b.begin(), b.end(), back_inserter(res)); return res; } n clock_t start_time; void start_timer() { start_time = clock(); } n double get_time() { return (double)(clock() - start_time) / CLOCKS_PER_SEC; } n #if __SIZEOF_INT128__ >= 16 n typedef __int128 LL; n istream& operator>>(istream& in, __int128& a) { int64_t b; cin >> b; a = b; return in; } n ostream& operator<<(ostream& out, const __int128 a) { n  unsigned __int128 b = a < 0 ? -a : a; char buf[128]; char* c = end(buf); do { --c; *c =  0123456789 [b % 10]; b /= 10; } while (b); n  if (a < 0) { --c; *c =  - ; } int len = end(buf) - c; out.rdbuf()->sputn(c, len); return out; n } n #endif n  n con int N = 3005; n  n set<int> g[N]; n int p[N]; n int d[N]; n set<pii> used; n vec<int> path; n int comps; n  n void init(int n) { n  comps = n; n  forn(i, 1, n) { n   p[i] = i; n   d[i] = 0; n  } n  used.cle(); n  path.cle(); n } n  n int find(int v) { n  if (p[v] == v) return v; n  return p[v] = find(p[v]); n } n  n void unite(int u, int v) { n  u = find(u); n  v = find(v); n  if (u == v) return; n  if (d[u] < d[v]) swap(u, v); n  p[v] = u; n  if (d[u] == d[v]) d[u]++; n  comps--; n } n  n bool connected() { n  return comps == 1; n } n  n void rest(int i, set<int>& star) { n  for (int j : star) { n   g[i].ins(j); n   g[j].ins(i); n  } n } n  n void dfs(int v) { n  for (int u : g[v]) { n   if (used.count({min(u, v), max(u, v)})) continue; n   used.ins({min(u, v), max(u, v)}); n   dfs(u); n   path.pb(u); n  } n } n  n void Solve() { n  int n, m; n  cin >> n >> m; n  forn(i, 1, m) { n   int u, v; n   cin >> u >> v; n   g[u].ins(v); n   g[v].ins(u); n  } n  forn(i, 1, n) { n   set<int> all; n   for (int j : g[i]) { n    if (g[j].size() & 1) all.ins(j); n   } n   vec<int> cand(all.begin(), all.end()); n   cand.pb(0); n   for (int can : cand) { n    set<int> star = all; n    star.era(can); n    for (int j : star) { n     g[i].era(j); n     g[j].era(i); n    } n    init(n); n    set<int> odd; n    forn(v, 1, n) { n     for (int u : g[v]) { n      unite(v, u); n     } n     if ((g[v].size() & 1) && odd.size() <= 2) { n      odd.ins(v); n     } n    } n    if (odd.size() > 2) { n     rest(i, star); n     continue; n    } n    bool ok = 1; n    forn(v, 1, n) { n     if (!g[v].emp() && find(v) != find(i)) { n      ok = 0; n      break; n     } n    } n    if (!ok || (odd.size() == 2 && !odd.count(i))) { n     rest(i, star); n     continue; n    } n    dfs(i); n    path.pb(i); n    if (!star.emp()) path.pb(-1); n    for (int j : star) { n     path.pb(j); n     path.pb(i); n    } n    out(path.size()); n    out(path); n    return; n   } n  } n  out(0); n } n  n int main() { n  ios_base::sync_with_stdio(0); cin.tie(0); n #ifdef LOCAL n  freopen( input.txt ,  r , stdin); n #endif n  start_timer(); n  Solve(); n  return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 5005; n int a[N]; n int main() { n   int n, m; n   scanf( %d%d , &n, &m); n   int tot = 0; n   for (int i = 1; i <= n; i++) { n     if (m < (i - 1) / 2) break; n     a[++tot] = i; n     m -= (i - 1) / 2; n   } n   if (!m) { n     int cnt = 1e8; n     for (int i = tot + 1; i <= n; i++) a[i] = cnt, cnt += 10000; n     for (int i = 1; i <= n; i++) cout << a[i] <<    ; n   } else { n     if (tot == n) n       puts( -1 ); n     else { n       a[tot + 1] = a[tot] + a[tot] - m * 2 + 1; n       int cnt = 1e8; n       for (int i = tot + 2; i <= n; i++) a[i] = cnt, cnt += 10000; n       for (int i = 1; i <= n; i++) cout << a[i] <<    ; n     } n   } n } n


#include <bits/stdc++.h> n const int N = 500500; n std::vector<int> g[N]; n int d[N]; n int n, maxM, maxD; n void go(int cur, int par = -1, int dist = 0) { n   if (dist > maxD) maxD = dist; n   bool f = false; n   for (auto v : g[cur]) n     if (v != par) { n       go(v, cur, dist + 1); n       f = true; n     } n   if (!f) ++d[dist]; n } n int main() { n   scanf( %d , &n); n   for (int i = 1; i < n; ++i) { n     int x, y; n     scanf( %d%d , &x, &y); n     g[x].push_back(y); n     g[y].push_back(x); n   } n   for (auto v : g[1]) { n     for (int i = 0; i <= maxD; ++i) d[i] = 0; n     maxD = 0; n     go(v, 1); n     int p = -1; n     for (int i = 0; i <= maxD; ++i) n       if (d[i] > 0) { n         if (i > p) n           p = i + d[i] - 1; n         else n           p += d[i]; n       } n     if (p + 1 > maxM) maxM = p + 1; n   } n   printf( %d n , maxM); n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n void solve() { n   int n; n   cin >> n; n   vector<pair<int, bool>> v(2 * n); n   for (int i = 0; i < 2 * n; i++) cin >> v[i].first, v[i].second = true; n   long long ans = 0, cc = 0; n   for (int i = 0; i < 2 * n; i++) { n     if (!v[i].second) continue; n     cc = 0; n     v[i].second = false; n     for (int j = i + 1; j < 2 * n; j++) { n       if (v[j].second && v[i].first != v[j].first) { n         cc++; n       } else if (v[i].first == v[j].first) { n         v[j].second = false; n         break; n       } n     } n     ans += cc; n   } n   cout << ans; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   int chill = 1; n   while (chill--) { n     solve(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long n, m, dp[1 << 21], b, ans = 3e18; n pair<long long, pair<long long, long long> > a[1 << 21]; n int main() { n   cin >> n >> m >> b; n   for (long long i = 0, m, x; i < n; i++) { n     cin >> a[i].second.first >> a[i].first >> m; n     while (m--) cin >> x, x--, a[i].second.second += 1 << x; n   } n   for (long long i = 0; i < (1 << m); i++) dp[i] = ans; n   dp[0] = 0, sort(a, a + n); n   for (long long i = 0; i < n; i++) { n     for (int j = 0; j < (1 << m); j++) n       dp[j] = min(dp[j], dp[j & (j ^ a[i].second.second)] + a[i].second.first); n     ans = min(ans, dp[(1 << m) - 1] + a[i].first * b); n   } n   cout << (ans < (long long)3e18 ? ans : -1); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int L; n int a[100005], n; n int Min[100005 << 2], sub[100005 << 2]; n vector<pair<int, int> > ans; n void PushUp(int rt) { Min[rt] = min(Min[rt << 1], Min[rt << 1 | 1]); } n void PushDown(int rt) { n   if (sub[rt]) { n     sub[rt << 1] += sub[rt]; n     sub[rt << 1 | 1] += sub[rt]; n     Min[rt << 1] -= sub[rt]; n     Min[rt << 1 | 1] -= sub[rt]; n     sub[rt] = 0; n   } n } n void Build(int l, int r, int rt) { n   int m; n   if (l == r) { n     Min[rt] = a[l]; n     return; n   } n   m = (l + r) >> 1; n   Build(l, m, rt << 1); n   Build(m + 1, r, rt << 1 | 1); n   PushUp(rt); n } n void Update(int L, int R, int x, int l, int r, int rt) { n   int m; n   if (L <= l && R >= r) { n     sub[rt] += x; n     Min[rt] -= x; n     return; n   } n   m = (l + r) >> 1; n   PushDown(rt); n   if (L <= m) Update(L, R, x, l, m, rt << 1); n   if (R > m) Update(L, R, x, m + 1, r, rt << 1 | 1); n   PushUp(rt); n } n int Query(int L, int R, int l, int r, int rt) { n   int ans = 1 << 30, m; n   if (L <= l && R >= r) return Min[rt]; n   m = (l + r) >> 1; n   PushDown(rt); n   if (L <= m) ans = min(ans, Query(L, R, l, m, rt << 1)); n   if (R > m) ans = min(ans, Query(L, R, m + 1, r, rt << 1 | 1)); n   PushUp(rt); n   return ans; n } n pair<int, int> bin() { n   while (L <= n && Query(L, L, 1, n, 1) == 0) L++; n   if (L == n + 1) return pair<int, int>(n + 1, 0); n   int R, l = L, r = n, m; n   while (l <= r) { n     m = (l + r) >> 1; n     if (Query(L, m, 1, n, 1) == 0) n       r = m - 1; n     else n       l = m + 1; n   } n   R = r; n   return pair<int, int>(L, R); n } n int main() { n   int i, minv, l, r; n   while (scanf( %d , &n) != EOF && n) { n     L = 1; n     (ans).clear(); n     for (i = 1; i <= n; i++) scanf( %d , &a[i]); n     Build(1, n, 1); n     while (1) { n       pair<int, int> now = bin(); n       l = now.first, r = now.second; n       if (l == n + 1) break; n       ans.push_back(pair<int, int>(l, r)); n       Update(l, r, 1, 1, n, 1); n     } n     printf( %d n , ((int)(ans).size())); n     for (i = 0; i < ((int)(ans).size()); i++) n       printf( %d %d n , ans[i].first, ans[i].second); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char s[10]; n int n, h; n double tw[100]; n int main() { n   cin >> s >> n >> h; n   if (s[0] ==  B ) { n     printf( %d n , n); n     return 0; n   } n   tw[0] = 1; n   for (int i = 1; i <= 2 * h; i++) tw[i] = tw[i - 1] * 2.0; n   double r = n; n   for (int i = 1; i <= h; i++) n     for (int j = 1; j <= n; j++) n       r += ((double)n - (double)j) * (1 / tw[2 * i]) * n            pow(1 - 1 / tw[i], j - 1) * n            (tw[i] - tw[i - 1] * (1 + (j - 1) / (tw[i] - 1))); n   printf( %.9lf n , r); n } n


#include <bits/stdc++.h> n using namespace std; n const int c = 200002; n int n, m, maxi, pos = c, cnt, id[c], szint[c], kezd; n vector<int> sz[c]; n bool v[c], v2[c], jo[c]; n void dfs2(int a) { n   v2[a] = true; n   bool s = jo[a]; n   for (int x : sz[a]) { n     if (!v2[x]) { n       dfs2(x); n       if (jo[x]) { n         s = 1; n       } n     } n   } n   jo[a] = s; n   cnt += jo[a] * 2; n } n void dfs(int a) { n   if (!jo[a]) { n     return; n   } n   v[a] = true; n   int x1 = a, x2 = a; n   for (int x : sz[a]) { n     if (!v[x]) { n       szint[x] = szint[a] + 1; n       dfs(x); n       int aa = szint[x1], bb = szint[x2], cc = szint[id[x]]; n       if (cc > bb || (cc == bb && id[x] < x2)) { n         x2 = id[x]; n         if (cc > aa || (cc == aa && id[x] < x1)) { n           swap(x1, x2); n         } n       } n     } n   } n   id[a] = x1; n   int s = szint[x1] + szint[x2] - 2 * szint[a]; n   if (s > maxi || (s == maxi && min(x1, x2) < pos)) { n     maxi = s; n     pos = min(x1, x2); n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin >> n >> m; n   for (int i = 1; i < n; i++) { n     int a, b; n     cin >> a >> b; n     sz[a].push_back(b), sz[b].push_back(a); n   } n   for (int i = 1; i <= m; i++) { n     int x; n     cin >> x; n     kezd = x; n     jo[x] = 1; n   } n   dfs2(kezd), cnt -= 2; n   szint[kezd] = 1, dfs(kezd); n   cout << pos <<   n  << cnt - maxi <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   ; n   long long int ans = 1000000000000, n, m, i, d, j, a, fo = 0; n   vector<long long int> v; n   set<long long int> mset; n   cin >> n >> m >> d; n   for (i = 0; i < n; i++) { n     for (j = 0; j < m; j++) { n       cin >> a; n       mset.insert(a); n       v.emplace_back(a); n     } n   } n   sort(v.begin(), v.end()); n   for (auto x : mset) { n     long long int counter = 0; n     for (j = 0; j < v.size(); j++) { n       a = abs(x - v[j]); n       if (a % d != 0 || counter >= ans) { n         counter = 1000000000000; n         break; n       } n       counter += (a / d); n     } n     if (ans > counter) { n       ans = counter; n     } n   } n   if (ans == 1000000000000) n     cout <<  -1  << endl; n   else n     cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 110005; n long long arr[maxn], arr1[maxn], n, m; n int judge(long long x) { n   memcpy(arr1, arr, sizeof(arr)); n   long long i = n, countt = 1, t = 0; n   while (i >= 1 && arr1[i] <= 0) --i; n   while (countt <= m) { n     t = x - i; n     while (t > 0) { n       if (t >= arr1[i]) { n         t = t - arr1[i]; n         arr1[i] = 0; n         i--; n         if (i < 1) return 1; n       } else { n         arr1[i] = arr1[i] - t; n         t = 0; n       } n     } n     ++countt; n   } n   return 0; n } n long long aa(long long x) { n   long long i = n, temp; n   while (i >= 1 && arr[i] <= 0) --i; n   temp = arr[i]; n   int countt = 1; n   while (countt <= m) { n     long long t = x - i; n     while (t > 0) { n       if (t >= temp) { n         t -= temp; n         i--; n         while (i >= 1 && arr[i] <= 0) --i; n         if (i < 1) return 1; n         temp = arr[i]; n       } else { n         temp -= t; n         break; n       } n     } n     countt++; n   } n   return 0; n } n int main() { n   long long left, right, ans, mid; n   scanf( %lld%lld , &n, &m); n   left = 0; n   right = 1e18; n   ans = 0; n   for (int i = 1; i <= n; i++) { n     scanf( %lld , &arr[i]); n   } n   while (left <= right) { n     mid = (left + right) / 2; n     if (aa(mid)) { n       ans = mid; n       right = mid - 1; n     } else { n       left = mid + 1; n     } n   } n   printf( %lld n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 3e5; n int n, u, v, tp; n int par[2][N], sz[2][N]; n long long ans; n int find_set(int v) { n   if (par[tp][v] == v) return v; n   return par[tp][v] = find_set(par[tp][v]); n } n void union_sets(int a, int b) { n   a = find_set(a); n   b = find_set(b); n   if (sz[tp][a] < sz[tp][b]) swap(a, b); n   par[tp][b] = a; n   sz[tp][a] += sz[tp][b]; n } n int main() { n   cin >> n; n   for (int i = 0; i < n; ++i) { n     par[0][i] = par[1][i] = i; n     sz[0][i] = sz[1][i] = 1; n   } n   for (int i = 1; i < n; ++i) { n     cin >> u >> v >> tp; n     --u; n     --v; n     union_sets(u, v); n   } n   for (int i = 0; i < n; ++i) { n     if (par[0][i] == i) ans += (long long)sz[0][i] * (sz[0][i] - 1); n     if (par[1][i] == i) ans += (long long)sz[1][i] * (sz[1][i] - 1); n     tp = 0; n     int v = find_set(i); n     tp = 1; n     int u = find_set(i); n     ans += (long long)(sz[0][v] - 1) * (sz[1][u] - 1); n   } n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n struct Tpoint { n   double x, y; n   Tpoint() {} n   Tpoint(double _x, double _y) { n     x = _x; n     y = _y; n   } n   inline void read() { scanf( %lf%lf , &x, &y); } n   inline void show() { printf( %lf %lf n , x, y); } n   inline double norm() { return sqrt(((x) * (x)) + ((y) * (y))); } n }; n inline Tpoint operator+(const Tpoint &a, const Tpoint &b) { n   return Tpoint(a.x + b.x, a.y + b.y); n } n inline Tpoint operator-(const Tpoint &a, const Tpoint &b) { n   return Tpoint(a.x - b.x, a.y - b.y); n } n inline Tpoint operator*(const Tpoint &a, const double &b) { n   return Tpoint(a.x * b, a.y * b); n } n inline Tpoint operator/(const Tpoint &a, const double &b) { n   return Tpoint(a.x / b, a.y / b); n } n inline double det(const Tpoint &a, const Tpoint &b) { n   return a.x * b.y - a.y * b.x; n } n inline double dot(const Tpoint &a, const Tpoint &b) { n   return a.x * b.x + a.y * b.y; n } n const int maxn = 100005; n bool mark[(1 << 20) + 10]; n int n, a[maxn], last[maxn][20]; n int main() { n   scanf( %d , &n); n   for (int i = 0; i < n; ++i) { n     scanf( %d , &a[i]); n   } n   for (int i = 0; i < 20; ++i) { n     last[n][i] = n; n   } n   for (int i = n - 1; i >= 0; --i) { n     memcpy(last[i], last[i + 1], sizeof(last[i])); n     for (int j = 0; j < 20; ++j) { n       if (a[i] >> j & 1) { n         last[i][j] = i; n       } n     } n   } n   for (int i = 0; i < n; ++i) { n     int x = a[i], pos = i + 1; n     mark[x] = true; n     while (1) { n       int u = -1; n       for (int j = 0; j < 20; ++j) { n         if (x >> j & 1) { n           continue; n         } n         if (u == -1 || last[pos][j] < last[pos][u]) { n           u = j; n         } n       } n       if (u == -1 || last[pos][u] >= n) { n         break; n       } n       pos = last[pos][u]; n       x |= a[pos]; n       mark[x] = true; n       pos++; n     } n   } n   int res = 0; n   for (int i = 0; i < 1 << 20; ++i) { n     res += mark[i]; n   } n   printf( %d n , res); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 2e5 + 7; n map<long long, int> G; n map<long long, map<long long, int> > multiMap; n int main() { n   long long i, j, k, f1, f2, f3, f4, t1, t2, t3, t4; n   long long n, m, T; n   long long a, b; n   cin >> n >> a >> b; n   m = 0; n   for (i = 1; i <= n; i++) { n     cin >> t1 >> t2 >> t3; n     f1 = a * t2 - t3; n     m += G[f1] * 2; n     m -= 2 * multiMap[t2][t3]; n     multiMap[t2][t3]++; n     G[f1]++; n   } n   cout << m << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n using vll = vector<ll>; n using vii = vector<int>; n using pii = pair<int, int>; n template <typename T = vii> n using vec = vector<T>; n const ll INF = 1e18, MOD = 1e9 + 7; n const int MAX = 1e6; n int main() { n   cin.tie(NULL); n   ios_base::sync_with_stdio(false); n   int n, m; n   cin >> n >> m; n   map<int, vec<pii> > d; n   for (int i = 0; i < m; i++) { n     int u, v, w; n     cin >> u >> v >> w; n     d[w].emplace_back(--u, --v); n   } n   vii dp(n); n   for (auto [_, V] : d) { n     map<int, int> new_dp; n     for (auto [u, v] : V) { n       new_dp[v] = max({new_dp[v], dp[v], dp[u] + 1}); n     } n     for (auto [i, x] : new_dp) { n       dp[i] = x; n     } n   } n   cout << *max_element(dp.begin(), dp.end()) <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   int a[1000000]; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n   } n   int cur = a[n - 1]; n   long long total = a[n - 1]; n   for (int i = n - 2; i >= 0; i--) { n     cur = min(cur - 1, a[i]); n     cur = max(0, cur); n     total += cur; n   } n   cout << total; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 1e8; n const int N = 300100; n int n, m, ans, nans; n string mat[N], ansmat[N], nmat[N]; n void upd() { n   if (nans >= ans) return; n   ans = nans; n   for (int i = 0; i < n; ++i) ansmat[i] = nmat[i]; n } n int main() { n   cin.tie(NULL); n   ios_base::sync_with_stdio(0); n   cin >> n >> m; n   for (int i = 0; i < n; ++i) cin >> mat[i]; n   for (int i = 0; i < n; ++i) ansmat[i] = nmat[i] = mat[i]; n   vector<char> v = { A ,  C ,  G ,  T }; n   ans = INF; n   do { n     nans = 0; n     for (int j = 0; j < m; ++j) { n       int op1 = 0, op2 = 0; n       for (int i = 0; i < n; ++i) { n         op1 += v[2 * (j & 1) + (i & 1)] != mat[i][j]; n         op2 += v[2 * (j & 1) + !(i & 1)] != mat[i][j]; n       } n       nans += min(op1, op2); n       bool f = op1 > op2; n       for (int i = 0; i < n; ++i) nmat[i][j] = v[2 * (j & 1) + (f ^ (i & 1))]; n     } n     upd(); n     nans = 0; n     for (int i = 0; i < n; ++i) { n       int op1 = 0, op2 = 0; n       for (int j = 0; j < m; ++j) { n         op1 += v[2 * (i & 1) + (j & 1)] != mat[i][j]; n         op2 += v[2 * (i & 1) + !(j & 1)] != mat[i][j]; n       } n       nans += min(op1, op2); n       bool f = op1 > op2; n       for (int j = 0; j < m; ++j) nmat[i][j] = v[2 * (i & 1) + (f ^ (j & 1))]; n     } n     upd(); n   } while (next_permutation(v.begin(), v.end())); n   for (int i = 0; i < n; ++i) cout << ansmat[i] <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 200010; n vector<int> e[N]; n set<int> l[N]; n int n; n void exitno() { n   printf( -1 n ); n   exit(0); n } n int exitans(int x) { n   while (x % 2 == 0) x /= 2; n   printf( %d n , x); n   exit(0); n } n void _dfs(int p, int fa) { n   if (fa && e[p].size() == 1) l[p].insert(0); n   for (int i = 0; i < e[p].size(); i++) { n     int x = e[p][i]; n     if (x == fa) continue; n     _dfs(x, p); n     for (auto j : l[x]) l[p].insert(j + 1); n   } n   if (l[p].size() >= 3) exitno(); n } n void work(int p) { n   for (int i = 1; i <= n; i++) l[i].clear(); n   _dfs(p, 0); n   int x = 0; n   for (auto i : l[p]) x += i; n   exitans(x); n } n void dfs(int p = 1, int fa = 0) { n   if (fa && e[p].size() == 1) l[p].insert(0); n   for (int i = 0; i < e[p].size(); i++) { n     int x = e[p][i]; n     if (x == fa) continue; n     dfs(x, p); n     for (auto j : l[x]) l[p].insert(j + 1); n   } n   if (l[p].size() >= 3) exitno(); n   if (l[p].size() == 2) work(p); n } n int main() { n   cin >> n; n   for (int i = 1; i <= n - 1; i++) { n     int x, y; n     scanf( %d%d , &x, &y); n     e[x].push_back(y); n     e[y].push_back(x); n   } n   dfs(); n   exitans(*l[1].begin()); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(0); n   int x; n   string y, z; n   cin >> x >> y >> z; n   if (z[0] ==  w ) { n     int fd = 5, ans = 0; n     for (int i = 1; i <= 366; ++i) { n       if (fd == x) ans++; n       fd++; n       if (fd == 8) fd = 1; n     } n     cout << ans <<   n ; n   } else { n     if (x <= 29) n       cout << 12 <<   n ; n     else if (x <= 30) n       cout << 11 <<   n ; n     else n       cout << 7 <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename... T> n void show(T&&... args) { n   ((cerr << args <<    ), ...); n } n template <typename F, typename S> n ostream& operator<<(ostream& os, const pair<F, S>& p) { n   return os <<  (  << p.first <<  ,   << p.second <<  ) ; n } n template <typename T> n ostream& operator<<(ostream& os, const vector<T>& v) { n   os <<  { ; n   typename vector<T>::const_iterator it; n   for (it = v.begin(); it != v.end(); it++) { n     if (it != v.begin()) os <<  ,  ; n     os << *it; n   } n   return os <<  } ; n } n template <typename T> n ostream& operator<<(ostream& os, const set<T>& v) { n   os <<  [ ; n   typename set<T>::const_iterator it; n   for (it = v.begin(); it != v.end(); it++) { n     if (it != v.begin()) os <<  ,  ; n     os << *it; n   } n   return os <<  ] ; n } n template <typename T> n ostream& operator<<(ostream& os, const multiset<T>& v) { n   os <<  [ ; n   typename multiset<T>::const_iterator it; n   for (it = v.begin(); it != v.end(); it++) { n     if (it != v.begin()) os <<  ,  ; n     os << *it; n   } n   return os <<  ] ; n } n template <typename F, typename S> n ostream& operator<<(ostream& os, const map<F, S>& v) { n   os <<  [ ; n   typename map<F, S>::const_iterator it; n   for (it = v.begin(); it != v.end(); it++) { n     if (it != v.begin()) os <<  ,  ; n     os << it->first <<   =   << it->second; n   } n   return os <<  ] ; n } n template <typename F, typename S> n ostream& operator<<(ostream& os, const unordered_map<F, S>& v) { n   os <<  [ ; n   typename unordered_map<F, S>::const_iterator it; n   for (it = v.begin(); it != v.end(); it++) { n     if (it != v.begin()) os <<  ,  ; n     os << it->first <<   =   << it->second; n   } n   return os <<  ] ; n } n template <typename... T> n void read(T&... args) { n   ((cin >> args), ...); n } n template <typename... T> n void write(T&&... args) { n   ((cout << args <<    ), ...); n } n inline void file_io(string path1 =   , string path2 =   ) { n   if (path2.size() == 0) path2 = path1; n   freopen(path1.c_str(),  r , stdin); n   freopen(path2.c_str(),  w , stdout); n } n template <typename T> n T egcd(T a, T b, T& x, T& y) { n   x = 1, y = 0; n   T x1 = 0, y1 = 1, a1 = a, b1 = b; n   while (b1) { n     T q = a1 / b1; n     tie(x, x1) = make_tuple(x1, x - q * x1); n     tie(y, y1) = make_tuple(y1, y - q * y1); n     tie(a1, b1) = make_tuple(b1, a1 - q * b1); n   } n   return a1; n } n template <typename F, typename S> n F bigMod(F a, F b, S mod) { n   a %= mod; n   F res = 1; n   while (b > 0) { n     if (b & 1) res = ((long long)res * a) % mod; n     a = ((long long)a * a) % mod; n     b >>= 1; n   } n   return res; n } n inline int modAdd(long long _a, long long _b, long long mod) { n   if (_a < 0) { n     _a += mod; n   } n   if (_b < 0) { n     _b += mod; n   } n   if (_a + _b >= mod) return (_a + _b - mod); n   return (_a + _b); n } n inline int modMul(long long _a, long long _b, long long mod) { n   if (_a < 0) { n     _a += mod; n   } n   if (_b < 0) { n     _b += mod; n   } n   return (_a * _b) % mod; n } n inline int modInv(long long a, long long mod) { n   return bigMod(a, mod - 2, mod); n } n const long long mod = 998244353; n int solve() { n   int n; n   cin >> n; n   int dp[n + 5][2], ans = 0; n   memset(dp, 0, sizeof dp); n   dp[0][0] = 1; n   for (int i = 0; i < n; i++) { n     int val; n     cin >> val; n     dp[val + 1][0] = modAdd(dp[val + 1][0], dp[val + 1][0], mod); n     dp[val + 1][0] = modAdd(dp[val + 1][0], dp[val][0], mod); n     if (val - 1 >= 0) n       dp[val - 1][1] = modAdd(dp[val - 1][1], dp[val - 1][1], mod); n     if (val - 1 >= 0) n       dp[val - 1][1] = modAdd(dp[val - 1][1], dp[val - 1][0], mod); n     dp[val + 1][1] = modAdd(dp[val + 1][1], dp[val + 1][1], mod); n   } n   for (int i = 0; i < n + 5; i++) { n     ans = modAdd(ans, dp[i][0], mod); n     ans = modAdd(ans, dp[i][1], mod); n   } n   ans = modAdd(ans, -1, mod); n   cout << ans <<   n ; n   return 0; n } n int main() { n   ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); n   ; n   ; n   int t = 1, cs = 0; n   cin >> t; n   while (t--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int n, m, s, f; n   cin >> n >> m >> s >> f; n   map<int, pair<int, int> > mop; n   for (int i = 0; i < m; i++) { n     int t, l, r; n     cin >> t >> l >> r; n     mop[t] = {l, r}; n   } n   string ans; n   while (s != f) { n     pair<int, int> p = mop[ans.size() + 1]; n     if (s < f) { n       if ((s >= p.first && s <= p.second) || n           (s + 1 >= p.first && s + 1 <= p.second)) n         ans +=  X ; n       else n         ans +=  R , s++; n     } else { n       if ((s >= p.first && s <= p.second) || n           (s - 1 >= p.first && s - 1 <= p.second)) n         ans +=  X ; n       else n         ans +=  L , s--; n     } n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n namespace dinic { n using ll = int; n const ll oo = 1e6; n const int N = 202 * 202 * 2; n const int E = 202 * 202 * 6 * 2 * 2; n vector<int> g[N]; n int ne; n struct Edge { n   int from, to; n   ll flow, cap; n } edge[E]; n int lvl[N], vis[N], pass, start = N - 2, target = N - 1; n int qu[N], qt, px[N]; n ll run(int s, int sink, ll minE) { n   if (s == sink) return minE; n   ll ans = 0; n   for (; px[s] < (int)g[s].size(); px[s]++) { n     int e = g[s][px[s]]; n     auto &v = edge[e], &rev = edge[e ^ 1]; n     if (lvl[v.to] != lvl[s] + 1 || v.flow >= v.cap) continue; n     ll tmp = run(v.to, sink, min(minE, v.cap - v.flow)); n     v.flow += tmp, rev.flow -= tmp; n     ans += tmp, minE -= tmp; n     if (minE == 0) break; n   } n   return ans; n } n bool bfs(int source, int sink) { n   qt = 0; n   qu[qt++] = source; n   lvl[source] = 1; n   vis[source] = ++pass; n   for (int i = 0; i < qt; i++) { n     int u = qu[i]; n     px[u] = 0; n     if (u == sink) return true; n     for (auto& ed : g[u]) { n       auto v = edge[ed]; n       if (v.flow >= v.cap || vis[v.to] == pass) continue; n       vis[v.to] = pass; n       lvl[v.to] = lvl[u] + 1; n       qu[qt++] = v.to; n     } n   } n   return false; n } n ll flow(int source = start, int sink = target) { n   ll ans = 0; n   while (bfs(source, sink)) ans += run(source, sink, oo); n   return ans; n } n void addEdge(int u, int v, ll c = 1, ll rc = 0) { n   edge[ne] = {u, v, 0, c}; n   g[u].push_back(ne++); n   edge[ne] = {v, u, 0, rc}; n   g[v].push_back(ne++); n } n };  // namespace dinic n const int N = 205; n int n, m; n char mat[N][N]; n int main() { n   scanf( %d %d , &n, &m); n   for (int i = 0; i < n; i++) scanf( %s , mat[i]); n   const int s = dinic::start; n   const int t = dinic::target; n   const int add = n * m; n   int tot = 0; n   for (int i = 0; i < n; i++) n     for (int j = 0; j < m; j++) { n       if (mat[i][j] !=  # ) continue; n       tot++; n       if (mat[i + 1][j] !=  # ) continue; n       if (j - 1 >= 0 and mat[i][j - 1] ==  # ) { n         dinic::addEdge(i * m + j, add + i * m + j - 1); n       } n       if (mat[i][j + 1] ==  # ) { n         dinic::addEdge(i * m + j, add + i * m + j); n       } n       if (j - 1 >= 0 and mat[i + 1][j - 1] ==  # ) { n         dinic::addEdge(i * m + j, add + (i + 1) * m + j - 1); n       } n       if (mat[i + 1][j + 1] ==  # ) { n         dinic::addEdge(i * m + j, add + (i + 1) * m + j); n       } n     } n   int ver = 0; n   for (int i = 0; i < n; i++) n     for (int j = 0; j < m; j++) { n       if (mat[i][j] !=  # ) continue; n       if (mat[i][j + 1] ==  # ) { n         ver++; n         dinic::addEdge(add + i * m + j, t); n       } n       if (mat[i + 1][j] ==  # ) { n         ver++; n         dinic::addEdge(s, i * m + j); n       } n     } n   printf( %d n , tot - (ver - dinic::flow(s, t))); n } n