#include <bits/stdc++.h> n using namespace std; n const long long inf = 0x3f3f3f3f3f3f3f3f; n const long long N = 5000; n long long n, m, s, t; n vector<pair<long long, long long> > nei[N + 1]; n vector<long long> rv[N + 1]; n void ae(long long x, long long y, long long z) { n   nei[x].push_back(make_pair(y, z)), nei[y].push_back(make_pair(x, 0)); n   rv[x].push_back(nei[y].size() - 1), rv[y].push_back(nei[x].size() - 1); n } n long long dep[N + 1]; n bool bfs() { n   memset(dep, -1, sizeof(dep)); n   dep[s] = 0; n   queue<long long> q; n   q.push(s); n   while (q.size()) { n     long long x = q.front(); n     q.pop(); n     for (long long i = 0; i < nei[x].size(); i++) { n       long long y = nei[x][i].first, c = nei[x][i].second; n       if (c && !~dep[y]) dep[y] = dep[x] + 1, q.push(y); n     } n   } n   return ~dep[t]; n } n long long now[N + 1]; n long long dfs(long long x = s, long long flw = inf) { n   if (x == t || !flw) return flw; n   long long res = 0, tmp; n   for (long long &i = now[x]; i < nei[x].size(); i++) { n     long long y = nei[x][i].first, &c = nei[x][i].second; n     if (dep[y] == dep[x] + 1 && (tmp = dfs(y, min(flw, c)))) { n       res += tmp, flw -= tmp; n       c -= tmp, nei[y][rv[x][i]].second += tmp; n       if (!flw) break; n     } n   } n   return res; n } n long long dinic() { n   long long res = 0; n   while (bfs()) { n     memset(now, 0, sizeof(now)); n     res += dfs(); n   } n   return res; n } n long long a[N], b[N], c[N], d[N]; n vector<long long> nums_x, nums_y; n void discrete() { n   sort(nums_x.begin(), nums_x.end()), sort(nums_y.begin(), nums_y.end()); n   nums_x.resize(unique(nums_x.begin(), nums_x.end()) - nums_x.begin()); n   nums_y.resize(unique(nums_y.begin(), nums_y.end()) - nums_y.begin()); n   for (long long i = 1; i <= n; i++) n     a[i] = lower_bound(nums_x.begin(), nums_x.end(), a[i] - 1) - n            nums_x.begin() + 1, n     b[i] = lower_bound(nums_y.begin(), nums_y.end(), b[i] - 1) - n            nums_y.begin() + 1, n     c[i] = lower_bound(nums_x.begin(), nums_x.end(), c[i]) - nums_x.begin(), n     d[i] = lower_bound(nums_y.begin(), nums_y.end(), d[i]) - nums_y.begin(); n } n long long row[N], col[N]; n signed main() { n   cin >> m >> n; n   for (long long i = 1; i <= n; i++) { n     cin >> a[i] >> b[i] >> c[i] >> d[i]; n     nums_x.push_back(a[i] - 1), nums_x.push_back(c[i]); n     nums_y.push_back(b[i] - 1), nums_y.push_back(d[i]); n   } n   discrete(); n   s = 1, t = 2; n   long long now = 2; n   for (long long i = 1; i < nums_x.size(); i++) n     row[i] = ++now, ae(s, now, nums_x[i] - nums_x[i - 1]); n   for (long long i = 1; i < nums_y.size(); i++) n     col[i] = ++now, ae(now, t, nums_y[i] - nums_y[i - 1]); n   for (long long i = 1; i <= n; i++) { n     for (long long j = a[i]; j <= c[i]; j++) n       for (long long k = b[i]; k <= d[i]; k++) ae(row[j], col[k], inf); n   } n   cout << dinic(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n string s; n int dp[50][2000], r[50], n; n const int inf = 1e6; n int abs(int a) { return a > 0 ? a : -a; } n int getTime(int id, int k) { n   if (k <= 0) return 0; n   if (dp[id][k]) return dp[id][k]; n   dp[id][k] = inf; n   for (int i = 0; i < n; i++) { n     if (s[i] == s[id] or r[i] <= r[id]) continue; n     dp[id][k] = min(dp[id][k], abs(i - id) + getTime(i, k - r[i])); n   } n   return dp[id][k]; n } n int solve(int st, int k) { n   int ans = inf; n   for (int id = 0; id < n; id++) n     ans = min(ans, abs(st - id) + getTime(id, k - r[id])); n   return ans == inf ? -1 : ans; n } n int main() { n   int st, k; n   cin >> n >> st >> k; n   for (int i = 0; i < n; i++) cin >> r[i]; n   cin >> s; n   cout << solve(st - 1, k) << endl; n } n


#include <bits/stdc++.h> n using namespace std; n char s[1000500]; n int ones[1000500], zeros[1000500], dp[1000500]; n inline int solve(const vector<int> &vt) { n   int n = vt.size(); n   int cnt = 0; n   for (int i = 0; i < n; i++) { n     if (!vt[i]) cnt++; n     zeros[i] = cnt; n   } n   cnt = 0; n   for (int i = n - 1; i >= 0; i--) { n     ones[i] = cnt; n     if (vt[i]) cnt++; n   } n   cnt = n; n   for (int i = n - 1; i >= 0; i--) { n     cnt = min(cnt, zeros[i] + ones[i]); n     dp[i] = cnt; n   } n   int ret = n; n   cnt = 0; n   dp[n] = n; n   for (int i = 0; i <= n; i++) { n     ret = min(ret, dp[i] + cnt); n     if (vt[i]) cnt++; n     if (!vt[i]) cnt--; n   } n   return ret; n } n int main() { n   int test; n   scanf( %d , &test); n   while (test--) { n     int n, k; n     scanf( %d %d , &n, &k); n     scanf( %s , s); n     int cnt = 0; n     for (int i = 0; i < n; i++) { n       if (s[i] ==  1 ) cnt++; n     } n     int ans = n; n     for (int i = 0; i < k; i++) { n       int tem = 0; n       vector<int> vt; n       for (int j = i; j < n; j += k) { n         if (s[j] ==  1 ) tem++; n         vt.push_back((int)s[j] -  0 ); n       } n       ans = min(ans, solve(vt) + cnt - tem); n     } n     printf( %d n , ans); n     ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline void intialize() { n   cin.tie(0); n   ios_base::sync_with_stdio(0); n   cout.tie(0); n } n void clearArr(int arr[], int n); n bool arr[105][105]; n bool farr[105]; n queue<int> q; n queue<int> done; n int main() { n   intialize(); n   string ans[2] = { No ,  Yes }; n   string s; n   cin >> s; n   int ss = s.length(), i; n   stack<int> st; n   int t = 0; n   for (i = 0; i < ss; ++i) { n     if (st.empty()) n       st.push(s[i]); n     else { n       if (s[i] == st.top()) { n         t = (t + 1) % 2; n         st.pop(); n       } else { n         st.push(s[i]); n       } n     } n   } n   cout << ans[t] << endl; n } n void clearArr(int arr[], int n) { n   for (int i = 0; i < n; ++i) arr[i] = 0; n } n


#include <bits/stdc++.h> n int f[10005], c, d, n, m, k; n inline int min(int x, int y) { return x < y ? x : y; } n int main() { n   scanf( %d %d %d %d %d , &c, &d, &n, &m, &k); n   if (n * m <= k) { n     puts( 0 ); n     return 0; n   } n   memset(f, 0x3f, sizeof(f)); n   f[0] = 0; n   for (int i = 1; i <= n * m; ++i) { n     if (i >= n) f[i] = f[i - n] + c; n     f[i] = min(f[i], f[i - 1] + d); n   } n   int ans = 0x3f3f3f3f; n   for (int i = n * m - k; i <= n * m; ++i) n     if (f[i] < ans) ans = f[i]; n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX = 1e6 + 1; n struct node { n   int ans = 0; n   int o = 0; n   int c = 0; n   node() : ans(0), o(0), c(0) {} n   node(int x) : ans(0), o((x == 1 ? 1 : 0)), c((x == 1 ? 0 : 1)) {} n }; n node t[2 * MAX]; n int n; n node combine(node x, node y) { n   node cur; n   int t = min(x.o, y.c); n   cur.ans = t + x.ans + y.ans; n   cur.o = x.o + y.o - t; n   cur.c = x.c + y.c - t; n   return cur; n } n int query(int l, int r) { n   node resl, resr; n   for (l += n, r += n; l < r; l >>= 1, r >>= 1) { n     if (l & 1) resl = combine(resl, t[l++]); n     if (r & 1) resr = combine(t[--r], resr); n   } n   return combine(resl, resr).ans; n } n int main() { n   string s; n   cin >> s; n   n = s.length(); n   for (int i = 0; i < n; i++) { n     int ch = (s[i] ==  (  ? 1 : 0); n     t[i + n] = node(ch); n   } n   for (int i = n - 1; i > 0; i--) { n     int x = i << 1; n     int y = i << 1 | 1; n     if (x > y) { n       t[i] = combine(t[y], t[x]); n     } else { n       t[i] = combine(t[x], t[y]); n     } n   } n   int m; n   cin >> m; n   for (int i = 0; i < m; i++) { n     int l, r; n     scanf( %d%d , &l, &r); n     printf( %d n , query(l - 1, r) * 2); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = (int)1e9; n const double eps = 1e-9; n const int N = 1 << 19; n const int P = (int)1e9 + 7; n const int Z = 239; n inline int add(int a, int b) { n   a += b; n   if (a >= P) a -= P; n   return a; n } n int powP[2 * N]; n inline int shift(int a, int n) { return (a * (long long)powP[n]) % P; } n int hash1[2 * N]; n int hash2[2 * N]; n int len[2 * N]; n inline void upd(int x, int dx) { n   x += N; n   hash1[x] = dx; n   hash2[x] = dx; n   while (x > 1) { n     x >>= 1; n     hash1[x] = add(hash1[2 * x], shift(hash1[2 * x + 1], len[2 * x])); n     hash2[x] = add(hash2[2 * x + 1], shift(hash2[2 * x], len[2 * x])); n   } n } n int vleft[2 * N], vleftc = 0; n int vright[2 * N], vrightc = 0; n inline int get1(int l, int r) { n   if (l > r) return 0; n   l += N; n   r += N; n   vleftc = 0; n   vrightc = 0; n   while (l <= r) { n     if ((l & 1) == 1) vleft[vleftc++] = l; n     if ((r & 1) == 0) vright[vrightc++] = r; n     l = (l + 1) >> 1; n     r = (r - 1) >> 1; n   } n   int res = 0; n   int toshift = 0; n   for (int i = 0; i < vleftc; ++i) { n     int v = vleft[i]; n     res = add(res, shift(hash1[v], toshift)); n     toshift += len[v]; n   } n   for (int i = vrightc - 1; i >= 0; --i) { n     int v = vright[i]; n     res = add(res, shift(hash1[v], toshift)); n     toshift += len[v]; n   } n   return res; n } n inline int get2(int l, int r) { n   if (l > r) return 0; n   l += N; n   r += N; n   vleftc = 0; n   vrightc = 0; n   while (l <= r) { n     if ((l & 1) == 1) vleft[vleftc++] = l; n     if ((r & 1) == 0) vright[vrightc++] = r; n     l = (l + 1) >> 1; n     r = (r - 1) >> 1; n   } n   int res = 0; n   int toshift = 0; n   for (int i = 0; i < vrightc; ++i) { n     int v = vright[i]; n     res = add(res, shift(hash2[v], toshift)); n     toshift += len[v]; n   } n   for (int i = vleftc - 1; i >= 0; --i) { n     int v = vleft[i]; n     res = add(res, shift(hash2[v], toshift)); n     toshift += len[v]; n   } n   return res; n } n int a[N]; n int main() { n   powP[0] = 1; n   for (int i = 1; i <= N; ++i) powP[i] = (powP[i - 1] * (long long)Z) % P; n   for (int i = 2 * N - 1; i >= 1; --i) { n     if (i >= N) n       len[i] = 1; n     else n       len[i] = 2 * len[2 * i]; n   } n   int n; n   scanf( %d , &n); n   for (int i = 0; (i) < (n); ++i) scanf( %d , &a[i]); n   for (int i = 0; (i) < (n); ++i) a[i] -= 1; n   bool res = false; n   for (int i = 0; (i) < (n); ++i) { n     int val = a[i]; n     if (val <= n - val - 1) { n       int left = get1(0, val - 1); n       int right = get2(val + 1, 2 * val); n       if (left != right) { n         res = true; n       } n     } else { n       int left = get1(val - (n - 1 - val), val - 1); n       int right = get2(val + 1, n - 1); n       if (left != right) { n         res = true; n       } n     } n     upd(val, 1); n   } n   if (res) n     printf( YES n ); n   else n     printf( NO n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   long long int a[n], sum = 0; n   vector<int> v; n   vector<int> u; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n     sum += a[i]; n     if (a[i] > 0) n       u.push_back(a[i]); n     else n       v.push_back(0 - a[i]); n   } n   if (sum > 0) n     cout <<  first ; n   else if (sum < 0) n     cout <<  second ; n   else { n     int f = 0, m = u.size(); n     if (m > v.size()) m = v.size(); n     for (int i = 0; i < m; i++) { n       if (v[i] < u[i]) { n         f = 1; n         break; n       } else if (v[i] > u[i]) { n         f = 2; n         break; n       } n     } n     if (!f) { n       if (u.size() > v.size()) n         f = 1; n       else if (u.size() < v.size()) n         f = 2; n       else { n         if (a[n - 1] > 0) n           f = 1; n         else n           f = 2; n       } n     } n     if (f == 1) n       cout <<  first ; n     else n       cout <<  second ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int a1, a2, b1, b2, c1, c2; n   while (scanf( %d%d%d%d%d%d , &a1, &b1, &c1, &a2, &b2, &c2) != EOF) { n     if (a1 == 0 && b1 == 0 && c1 != 0) { n       printf( 0 n ); n       continue; n     } n     if (a2 == 0 && b2 == 0 && c2 != 0) { n       printf( 0 n ); n       continue; n     } n     if ((a1 == 0 && b1 == 0 && c1 == 0) || (a2 == 0 && b2 == 0 && c2 == 0)) { n       printf( -1 n ); n       continue; n     } n     if (a1 == 0 && a2 == 0) { n       if (c1 * b2 == c2 * b1) { n         printf( -1 n ); n       } else { n         printf( 0 n ); n       } n       continue; n     } n     if (b1 == 0 && b2 == 0) { n       if (c1 * a2 == c2 * a1) { n         printf( -1 n ); n       } else { n         printf( 0 n ); n       } n       continue; n     } n     if (a1 == 0 && b1 != 0) { n       printf( 1 n ); n       continue; n     } n     if (a1 != 0 && b1 == 0) { n       printf( 1 n ); n       continue; n     } n     if (a2 == 0 && b2 != 0) { n       printf( 1 n ); n       continue; n     } n     if (a2 != 0 && b2 == 0) { n       printf( 1 n ); n       continue; n     } n     if (a1 * b2 == a2 * b1) { n       if (fabs(c1 * 1.0 / b1 - c2 * 1.0 / b2) < 1e-8) { n         printf( -1 n ); n       } else { n         printf( 0 n ); n       } n     } else { n       printf( 1 n ); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, k; n   cin >> n >> k; n   string sub; n   for (int i = 0; i < k; i++) { n     sub.push_back( k ); n   } n   long long int count = 0; n   set<string> arra; n   for (int i = 0; i < n; i++) { n     string a; n     cin >> a; n     arra.insert(a); n   } n   set<string>::iterator it1, it2; n   for (it1 = arra.begin(); it1 != arra.end(); it1++) { n     for (it2 = arra.begin(); it2 != arra.end(); it2++) { n       string a = *it1; n       string b = *it2; n       if (a != b) { n         for (int i = 0; i < k; i++) { n           if (a[i] == b[i]) { n             sub[i] = a[i]; n           } else if ((a[i] ==  S  && b[i] ==  T ) || n                      (a[i] ==  T  && b[i] ==  S )) { n             sub[i] =  E ; n           } else if ((a[i] ==  S  && b[i] ==  E ) || n                      (a[i] ==  E  && b[i] ==  S )) { n             sub[i] =  T ; n           } else if ((a[i] ==  E  && b[i] ==  T ) || n                      (a[i] ==  T  && b[i] ==  E )) { n             sub[i] =  S ; n           } n         } n         if (arra.find(sub) != arra.end()) { n           count++; n         } n       } n     } n   } n   cout << count / 6 << endl; n } n


#include <bits/stdc++.h> n int a[100], i, j, maxim, h, l, n, b; n int main() { n   scanf( %d , &n); n   scanf( %d , &l); n   for (i = 0; i < n; i++) { n     scanf( %d , &a[i]); n   } n   i = 0; n   j = 0; n   b = 0; n   h = l; n   maxim = l; n   while (i < n) { n     if (l % a[i] == 0) { n       h = l / a[i]; n     } n     if (h < maxim) maxim = h; n     i++; n   } n   printf( %d , maxim); n } n


#include <bits/stdc++.h> n using namespace std; n int b[255]; n int main() { n   string a; n   cin >> a; n   for (int i = 0; i < a.size(); i++) { n     b[a[i]]++; n   } n   int u = b[ a ] - 1 + b[ a ]; n   int u2 = a.size(); n   cout << min(u, u2); n   return 0; n } n


#include <bits/stdc++.h> n #define ll long long n #define real long double n #define fr(i,l,n) for(ll i=l;i<n;i++) n #define br cout<<  n  n #define al(fu) (fu).begin(), (fu).end() n #define prl(c) cout<<(c)<<  n  n #define prv(v) {fr(qz,0,v.size()) cout<<(v)[qz]<<   ; br;} n #define alr(fu) (fu).rbegin(), (fu).rend() n #define mod 1000000007LL n #define mod1 998244353LL n #define nfi 1000000000000000013LL n #define skoree ios::sync_with_stdio(0); cin.tie(0) n #define danet(b) cout<<(b? YES : NO ) n #define Danet(b) cout<<(b? Yes : No ) n using namespace std; n  n char aq(char a){ n     if(a== 0 ) return  1 ; n     else return  0 ; n } n  n int main(){ n     skoree; n     ll o0o; n     cin>>o0o; n     while(o0o--){ n         ll n; n         cin>>n; n         vector<string> a(n),b(n); n         fr(i,0,n) cin>>a[i]; n         fr(i,0,n) cin>>b[i]; n         fr(i,0,n) if(a[0][i]!=b[0][i]){ n             fr(j,0,n) a[j][i]=aq(a[j][i]); n         } n         bool bb=1; n         fr(i,1,n) if(a[i]!=b[i]){ n             fr(j,0,n) a[i][j]=aq(a[i][j]); n             if(a[i]!=b[i]) bb=0; n         } n         danet(bb);br; n     } n     return 0; n } n /* n */ n


#include <bits/stdc++.h> n using namespace std; n pair<long long int, long long int> operator+( n     pair<long long int, long long int> p0, n     pair<long long int, long long int> p1) { n   return pair<long long int, long long int>(p0.first + p1.first, n                                             p0.second + p1.second); n } n pair<long long int, long long int> operator-( n     pair<long long int, long long int> p0, n     pair<long long int, long long int> p1) { n   return pair<long long int, long long int>(p0.first - p1.first, n                                             p0.second - p1.second); n } n vector<long long int> E[100005]; n vector<pair<long long int, long long int> > ans; n long long int type[100005]; n long long int used[100005]; n pair<long long int, long long int> dp[2][100005]; n long long int bef[100005]; n long long int parent[100005]; n pair<long long int, long long int> recur(long long int pos) { n   used[pos] = true; n   dp[0][pos] = make_pair(0, 0); n   for (long long int i = 0; n        i < ((long long int)(((long long int)(E[pos]).size()))); ++i) n     dp[0][pos] = dp[0][pos] + recur(E[pos][i]); n   dp[1][pos] = dp[0][pos]; n   bef[pos] = -1; n   for (long long int i = 0; n        i < ((long long int)(((long long int)(E[pos]).size()))); ++i) { n     pair<long long int, long long int> tmp = n         dp[0][pos] - dp[1][E[pos][i]] + dp[0][E[pos][i]] + make_pair(1, 0); n     if (type[pos] != type[E[pos][i]]) tmp.second++; n     if (dp[1][pos] < tmp) { n       bef[pos] = E[pos][i]; n       dp[1][pos] = tmp; n     } n   } n   return dp[1][pos]; n } n void dump(long long int pos, bool ok, n           vector<pair<long long int, long long int> > &root) { n   for (long long int i = 0; n        i < ((long long int)(((long long int)(E[pos]).size()))); ++i) { n     if (ok && bef[pos] == E[pos][i]) root.push_back(make_pair(pos, E[pos][i])); n     dump(E[pos][i], !(ok && bef[pos] == E[pos][i]), root); n   } n } n pair<long long int, long long int> cal(long long int pos) { n   for (; !used[pos]; pos = parent[pos]) used[pos] = true; n   vector<pair<long long int, long long int> > root; n   pair<long long int, long long int> res = make_pair(0, 0); n   for (long long int i = 0; i < ((long long int)(2)); ++i) { n     long long int par = parent[pos]; n     E[par].erase(find(E[par].begin(), E[par].end(), pos)); n     pair<long long int, long long int> tmp = recur(pos); n     if (res < tmp) { n       res = tmp; n       root.clear(); n       dump(pos, true, root); n     } n     E[par].push_back(pos); n     pos = par; n   } n   for (long long int i = 0; n        i < ((long long int)(((long long int)(root).size()))); ++i) n     ans.push_back(root[i]); n   return res; n } n int main() { n   pair<long long int, long long int> res = n       pair<long long int, long long int>(0, 0); n   long long int n, a; n   cin >> n; n   for (long long int i = 0; i < ((long long int)(n)); ++i) parent[i] = i; n   for (long long int i = 0; i < ((long long int)(n)); ++i) { n     cin >> parent[i] >> type[i]; n     parent[i]--; n     E[parent[i]].push_back(i); n   } n   for (long long int i = 0; i < ((long long int)(n)); ++i) n     if (!used[i]) res = res + cal(i); n   cout << res.first <<     << res.second << endl; n   for (long long int i = 0; n        i < ((long long int)(((long long int)(ans).size()))); ++i) n     cout << ans[i].first + 1 <<     << ans[i].second + 1 << endl; n } n


#include <bits/stdc++.h> n using namespace std; n void fastIO() { n   std::ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n } n template <typename T, typename U> n inline void mnze(T &x, U y) { n   if (y < x) x = y; n } n template <typename T, typename U> n inline void mxze(T &x, U y) { n   if (x < y) x = y; n } n void _scan(int &x) { scanf( %d , &x); } n void _scan(long long &x) { scanf( %lld , &x); } n void _scan(double &x) { scanf( %lf , &x); } n void _scan(char &x) { scanf(  %c , &x); } n void _scan(char *x) { scanf( %s , x); } n template <typename T> n void _scan(vector<T> &v) { n   for (int i = 0; i < (int)v.size(); i++) _scan(v[i]); n } n void scan() {} n template <typename T, typename... U> n void scan(T &head, U &...tail) { n   _scan(head); n   scan(tail...); n } n template <typename T> n void _dbg(const char *sdbg, T h) { n   cerr << sdbg <<  =  << h <<   n ; n } n template <typename T, typename... U> n void _dbg(const char *sdbg, T h, U... t) { n   while (*sdbg !=  , ) cerr << *sdbg++; n   cerr <<  =  << h <<  , ; n   _dbg(sdbg + 1, t...); n } n long long MOD = 1e9 + 7; n inline long long Msum(long long x) { return x; } n template <typename... Rest> n inline long long Msum(long long x, Rest... rest) { n   return (x + Msum(rest...)) % MOD; n } n inline long long Mprod(long long x) { return x; } n template <typename... Rest> n inline long long Mprod(long long x, Rest... rest) { n   return x * Mprod(rest...) % MOD; n } n inline long long Mnorm(long long x) { return (x % MOD + MOD) % MOD; } n inline long long Msq(long long x) { return (x * x) % MOD; } n inline long long Mpot(long long x, long long e) { n   if (!e) return 1; n   return Msq(Mpot(x, e >> 1)) * (e & 1 ? x : 1) % MOD; n } n const int MAXN = 2e3 + 3; n char g[MAXN][MAXN]; n int x[MAXN][MAXN]; n int R, C; n int main() { n   scan(R, C); n   for (int r = 0; r < R; r++) scan(g[r]); n   for (int r = R - 1; r > -1; r--) { n     for (int c = 0; c < C; c++) { n       x[r][c] = 1; n       char cc = g[r][c]; n       if (r + 2 >= R) continue; n       if (g[r + 1][c] != cc) continue; n       if (g[r + 2][c] != cc) continue; n       if (c - 1 < 0) continue; n       if (g[r + 1][c - 1] != cc) continue; n       if (c + 1 >= C) continue; n       if (g[r + 1][c + 1] != cc) continue; n       x[r][c] = min(x[r + 2][c], min(x[r + 1][c - 1], x[r + 1][c + 1])) + 1; n     } n   } n   long long ans = 0; n   for (int r = R - 1; r > -1; r--) n     for (int c = 0; c < C; c++) { n       ans += x[r][c]; n     } n   printf( %lld n , ans); n } n


#include <bits/stdc++.h> n using namespace std; n int inf = (1e9) + 7; n int mod = 998244353; n int c(int num, int div) { return (num + div - 1) / div; } n int main() { n   int n, k; n   scanf( %d %d , &n, &k); n   int nr = 2 * n; n   int ng = 5 * n; n   int nb = 8 * n; n   printf( %d n , c(nr, k) + c(ng, k) + c(nb, k)); n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e5 + 50; n const double eps = 1e-10; n const int max_index = 62; n const int inf = 0x3f3f3f3f; n const int MOD = 1e9 + 7; n inline int read() { n   char c = getchar(); n   while (!isdigit(c)) c = getchar(); n   int x = 0; n   while (isdigit(c)) { n     x = x * 10 + c -  0 ; n     c = getchar(); n   } n   return x; n } n int N, n, m, K; n long long dp[55][55][1110]; n long long C[55][55]; n int main() { n   scanf( %d%d , &N, &K); n   n = m = 0; n   for (int i = 0; i < N; i++) { n     int x = read(); n     if (x == 50) n       n++; n     else n       m++; n   } n   for (int i = 0; i <= 50; i++) C[i][0] = 1, C[i][i] = 1; n   for (int i = 0; i <= 50; i++) { n     for (int j = 1; j < i; j++) { n       C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % MOD; n     } n   } n   dp[n][m][0] = 1; n   for (int k = 1; k < 200 && dp[0][0][k - 1] == 0; k++) { n     bool flag = 0; n     for (int i = 0; i <= n; i++) { n       for (int j = 0; j <= m; j++) { n         if (k & 1) { n           for (int a = 0; a * 50 <= K && a + i <= n; a++) { n             for (int b = 0; b * 100 + a * 50 <= K && b + j <= m; b++) { n               if (a == 0 && b == 0) continue; n               long long tmp = dp[i + a][j + b][k - 1] * C[i + a][a] % MOD * n                               C[j + b][b] % MOD; n               dp[i][j][k] = (dp[i][j][k] + tmp) % MOD; n             } n           } n         } else { n           for (int a = 0; a * 50 <= K && a <= i; a++) { n             for (int b = 0; b * 100 + a * 50 <= K && b <= j; b++) { n               if (a == 0 && b == 0) continue; n               long long tmp = dp[i - a][j - b][k - 1] * C[n - i + a][a] % MOD * n                               C[m - j + b][b] % MOD; n               dp[i][j][k] = (dp[i][j][k] + tmp) % MOD; n             } n           } n         } n       } n     } n   } n   int k = 0; n   while (dp[0][0][k] == 0 && k < 200) k++; n   if (k >= 200) n     puts( -1 n0 ); n   else n     cout << k <<   n  << dp[0][0][k] <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename _T> n inline void read(_T &f) { n   f = 0; n   _T fu = 1; n   char c = getchar(); n   while (c <  0  || c >  9 ) { n     if (c ==  - ) { n       fu = -1; n     } n     c = getchar(); n   } n   while (c >=  0  && c <=  9 ) { n     f = (f << 3) + (f << 1) + (c & 15); n     c = getchar(); n   } n   f *= fu; n } n template <typename T> n void print(T x) { n   if (x < 0) putchar( - ), x = -x; n   if (x < 10) n     putchar(x + 48); n   else n     print(x / 10), putchar(x % 10 + 48); n } n template <typename T> n void print(T x, char t) { n   print(x); n   putchar(t); n } n const int N = 1e5 + 5, B = 310; n vector<int> pos[N * 2], big; n unordered_map<int, int> id; n int a[N], lc[N * 40], rc[N * 40], sum[N * 40], rt[N * 2], root[B + 5], n     tag[N * 2], rub[N * 40]; n int n, m, tot, cnt_id, top; n inline int newNode() { n   if (top) { n     int u = rub[top]; n     --top; n     lc[u] = rc[u] = 0; n     return u; n   } n   return ++tot; n } n void add(int &u, int l, int r, int x, int y) { n   if (!u) u = newNode(); n   sum[u] += y; n   if (l == r) { n     if (!sum[u]) rub[++top] = u, u = 0; n     return; n   } n   int mid = (l + r) >> 1; n   if (mid >= x) n     add(lc[u], l, mid, x, y); n   else n     add(rc[u], mid + 1, r, x, y); n   if (!sum[u]) rub[++top] = u, u = 0; n } n int query(int u, int l, int r, int x) { n   if (!u) return 0; n   if (r <= x) return sum[u]; n   int mid = (l + r) >> 1, ans = query(lc[u], l, mid, x); n   if (mid + 1 <= x) ans += query(rc[u], mid + 1, r, x); n   return ans; n } n void add(int x, int y) { n   if (!id.count(x)) id[x] = ++cnt_id; n   x = id[x]; n   add(rt[x], 1, n, y, 1); n   if (!tag[x] && (int)pos[x].size() + 1 > B) { n     for (int i = 0; i <= B; i++) add(root[i], 1, n, pos[x][i], -1); n     tag[x] = 1; n     big.push_back(x); n   } n   if (tag[x]) return; n   pos[x].push_back(y); n   int tmp = (int)pos[x].size() - 1; n   while (tmp && pos[x][tmp - 1] > pos[x][tmp]) { n     add(root[tmp - 1], 1, n, pos[x][tmp - 1], -1); n     add(root[tmp], 1, n, pos[x][tmp - 1], 1); n     swap(pos[x][tmp - 1], pos[x][tmp]); n     --tmp; n   } n   add(root[tmp], 1, n, y, 1); n } n void del(int x, int y) { n   x = id[x]; n   add(rt[x], 1, n, y, -1); n   if (tag[x]) return; n   int tmp = lower_bound(pos[x].begin(), pos[x].end(), y) - pos[x].begin(); n   add(root[tmp], 1, n, y, -1); n   while (tmp < (int)pos[x].size() - 1) { n     add(root[tmp + 1], 1, n, pos[x][tmp + 1], -1); n     add(root[tmp], 1, n, pos[x][tmp + 1], 1); n     swap(pos[x][tmp], pos[x][tmp + 1]); n     ++tmp; n   } n   pos[x].pop_back(); n } n int main() { n   read(n); n   for (int i = 1; i <= n; i++) read(a[i]), add(a[i], i); n   read(m); n   while (m--) { n     int opt; n     read(opt); n     if (opt == 1) { n       int x, y; n       read(y); n       read(x); n       del(a[x], x); n       a[x] = y; n       add(a[x], x); n     } n     if (opt == 2) { n       int x, y; n       read(x); n       read(y); n       if (x == 1) n         print(a[y],   n ); n       else if (x & 1) { n         int rk = query(rt[id[a[y]]], 1, n, y), ans = 0; n         if (rk <= B + 1) ans += query(root[rk - 1], 1, n, y); n         for (int i = 0; i < (int)big.size(); i++) { n           int id = big[i]; n           ans += (query(rt[id], 1, n, y) >= rk); n         } n         print(ans,   n ); n       } else { n         print(query(rt[id[a[y]]], 1, n, y),   n ); n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long inf = 1100000000000000000; n void solve() { n   long long n, k; n   cin >> n >> k; n   long long a[n]; n   for (long long i = 0; i < n; i++) cin >> a[i]; n   sort(a, a + n); n   long long dp[k + 5][k + 5]; n   memset(dp, 0, sizeof(dp)); n   long long x = n % k, c = (n + k - 1) / k, s = n / k; n   ; n   long long y = k - x; n   for (long long i = 0; i <= x; i++) n     for (long long j = 0; j <= y; j++) dp[i][j] = inf; n   dp[0][0] = 0; n   for (long long i = 0; i <= x; i++) { n     if (i) n       for (long long j = 0; j <= y; j++) { n         long long idx = (i - 1) * c + s * j; n         dp[i][j] = min(dp[i][j], abs(a[idx + c - 1] - a[idx]) + dp[i - 1][j]); n       } n     for (long long j = 1; j <= y; j++) { n       long long idx = i * c + s * (j - 1); n       dp[i][j] = min(dp[i][j], abs(a[idx + s - 1] - a[idx]) + dp[i][j - 1]); n     } n   } n   cout << dp[x][y]; n } n signed main() { n   ios_base::sync_with_stdio(false), cin.tie(nullptr); n   long long T = 1; n   while (T--) { n     solve(); n     cout <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a[100005], ans[100005]; n int main() { n   int n, a1, a2, num = 0, gg = 0, t = 0; n   cin >> n; n   bool ty = true, zz = true; n   for (int i = 1; i <= n - 1; ++i) { n     cin >> a1 >> a2; n     a[a1]++; n     a[a2]++; n   } n   for (int i = 1; i <= n; ++i) { n     if (a[i] > 2) { n       num++; n       gg = i; n     } n     if (num > 1) { n       ty = false; n       break; n     } else if (a[i] == 1) { n       ans[i] = i; n       t++; n     } n   } n   if (!ty) { n     cout <<  No  << endl; n   } else { n     cout <<  Yes  << endl; n     if (num == 1) { n       cout << t << endl; n       for (int i = 1; i <= n; ++i) { n         if (ans[i] != 0) { n           cout << gg <<     << ans[i] << endl; n         } n       } n     } else { n       cout << 1 << endl; n       for (int i = 1; i <= n; ++i) { n         if (ans[i] != 0 && zz) { n           cout << ans[i] <<    ; n           zz = false; n         } else if (ans[i] != 0 && !zz) { n           cout << ans[i] << endl; n         } n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n vector<pair<long long, int> > v; n vector<int> lef, rig; n long long pitaj(int t, int a, int b, int c) { n   long long res; n   cout << 3 - t <<     << a <<     << b <<     << c << endl; n   cin >> res; n   return res; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cin >> n; n   int ind = 2; n   for (int i = 3; i <= n; i++) { n     if (pitaj(1, 1, i, ind) == 1) ind = i; n   } n   for (int i = 2; i <= n; i++) { n     if (i == ind) continue; n     v.push_back({pitaj(2, 1, ind, i), i}); n   } n   sort(v.begin(), v.end()); n   for (int i = 1; i < v.size(); i++) { n     if (pitaj(1, 1, v[i - 1].second, v[i].second) == 1) { n       lef.push_back(v[i - 1].second); n     } else { n       rig.push_back(v[i - 1].second); n     } n   } n   lef.push_back(v.back().second); n   cout << 0 <<     << 1 <<     << ind <<    ; n   for (int i = 0; i < lef.size(); i++) cout << lef[i] <<    ; n   for (int i = (int)rig.size() - 1; i >= 0; i--) cout << rig[i] <<    ; n   return 0; n } n


#include <bits/stdc++.h> n const double eps = 1e-06; n int main() { n   double t, s, q; n   scanf( %lf%lf%lf , &t, &s, &q); n   double v = (q - 1.0) / q; n   int cnt = 1; n   while (true) { n     s = s / (1 - v); n     if (s > t - eps) break; n     cnt++; n   } n   printf( %d n , cnt); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int x, a, b, mx = 2500, Mx = -2500, my = 2500, My = -2500, ans; n int main() { n   cin >> x; n   for (int i = 1; i <= x; i++) { n     cin >> a >> b; n     mx = min(mx, a); n     Mx = max(Mx, a); n     my = min(my, b); n     My = max(My, b); n   } n   if (x == 1 || mx == Mx || my == My) { n     cout << -1 << endl; n   } else { n     ans = (Mx - mx) * (My - my); n     cout << ans << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e5 + 10, mod = 1e9 + 7, INF = 0x3f3f3f3f; n int main() { n   int n, a, x, b, y; n   cin >> n >> a >> x >> b >> y; n   while (a != x && b != y) { n     a++; n     if (a > n) a = 1; n     b--; n     if (b < 1) b = n; n     if (a == b) { n       printf( YES ); n       return 0; n     } n   } n   cout <<  NO ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long ans; n int a, b, c, d, e, f, g; n int main() { n   scanf( %d%d%d%d%d%d , &a, &b, &c, &d, &e, &f); n   if (e > f) ans += min(a, d); n   a -= ans, d -= ans; n   ans *= e; n   g = min(min(b, c), d); n   ans += f * g; n   b -= g, c -= g, d -= g; n   ans += e * min(a, d); n   printf( %lld , ans); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   if (n & 1) { n     cout <<  Ehab ; n   } else { n     cout <<  Mahmoud ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e6 + 10; n const int M = 1e7 + 1; n ; n const long long INF = 2e9 + 10; n const long long MOD = 1000 * 1000 * 1000 + 7; n const long double EPS = 1e-9; n int a[N]; n bool prime(int x) { n   for (int i = 2; i < (int)sqrt(x) + 1; ++i) n     if (x % i == 0) return false; n   return true; n } n int main() { n   ios_base::sync_with_stdio(false); n   int n; n   cin >> n; n   if (prime(n)) n     cout << 1; n   else if (prime(n - 2)) n     cout << 2; n   else if (n % 2 == 0) n     cout << 2; n   else n     cout << 3; n } n


#include <bits/stdc++.h> n using namespace std; n long long n; n long long m; n long long t; n void solve() {} n struct point { n   long long x, y; n }; n bool isSquare(point a, point b, point c, point d) { n   long long dist1 = n       (long long)(b.x - a.x) * (b.x - a.x) + (b.y - a.y) * (b.y - a.y); n   long long dist2 = n       (long long)(b.x - c.x) * (b.x - c.x) + (b.y - c.y) * (b.y - c.y); n   long long dist3 = n       (long long)(c.x - d.x) * (c.x - d.x) + (c.y - d.y) * (c.y - d.y); n   long long dist4 = n       (long long)(a.x - d.x) * (a.x - d.x) + (a.y - d.y) * (a.y - d.y); n   return dist1 == dist2 && dist1 == dist3 && dist1 == dist4; n } n bool noZeroArea(point a, point b, point c, point d) { n   long long dist1 = n       (long long)(b.x - a.x) * (b.x - a.x) + (b.y - a.y) * (b.y - a.y); n   long long dist2 = n       (long long)(b.x - c.x) * (b.x - c.x) + (b.y - c.y) * (b.y - c.y); n   long long dist3 = n       (long long)(c.x - d.x) * (c.x - d.x) + (c.y - d.y) * (c.y - d.y); n   long long dist4 = n       (long long)(a.x - d.x) * (a.x - d.x) + (a.y - d.y) * (a.y - d.y); n   if (dist1 > 0 && dist2 > 0 && dist3 > 0 && dist4 > 0) return true; n   return false; n } n long long IsOrthogonal(point a, point b, point c) { n   return (b.x - a.x) * (b.x - c.x) + (b.y - a.y) * (b.y - c.y) == 0; n } n long long IsRectangle(point a, point b, point c, point d) { n   return IsOrthogonal(a, b, c) && IsOrthogonal(b, c, d) && n          IsOrthogonal(c, d, a) && noZeroArea(a, b, c, d); n } n long long IsRectangleAnyOrder(point a, point b, point c, point d) { n   return IsRectangle(a, b, c, d) || IsRectangle(b, c, a, d) || n          IsRectangle(c, a, b, d); n } n long long IsSquareAnyOrder(point a, point b, point c, point d) { n   return (IsRectangle(a, b, c, d) && isSquare(a, b, c, d)) || n          (IsRectangle(b, c, a, d) && isSquare(b, c, a, d)) || n          (IsRectangle(c, a, b, d) && isSquare(c, a, b, d)); n } n int main() { n   ios_base::sync_with_stdio(false); n   point pt[10]; n   for (int i = 1; i <= 8; i++) { n     long long x, y; n     cin >> x >> y; n     pt[i].x = x; n     pt[i].y = y; n   } n   int mtints[] = {1, 2, 3, 4, 5, 6, 7, 8}; n   sort(mtints, mtints + 8); n   do { n     if (IsSquareAnyOrder(pt[mtints[0]], pt[mtints[1]], pt[mtints[2]], n                          pt[mtints[3]]) && n         IsRectangleAnyOrder(pt[mtints[4]], pt[mtints[5]], pt[mtints[6]], n                             pt[mtints[7]])) { n       cout <<  YES  << endl; n       cout << mtints[0] <<     << mtints[1] <<     << mtints[2] <<     n            << mtints[3] << endl; n       cout << mtints[4] <<     << mtints[5] <<     << mtints[6] <<     n            << mtints[7] << endl; n       return 0; n     } n   } while (next_permutation(mtints, mtints + 8)); n   cout <<  NO  << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct Edge { n   int to, w, type; n   Edge() {} n   Edge(int _to, int _w, int _type) : to(_to), w(_w), type(_type) {} n   bool operator<(const Edge other) { return type < other.type; } n }; n const long long N = 1e5 + 5, oo = 1e18; n long long n, m, k, dist[N], res; n int deg[N]; n vector<Edge> adj[N]; n bool mark[N]; n int main(int argc, char const *argv[]) { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   clock_t tStart = clock(); n   cin >> n >> m >> k; n   for (long long huy = 0, _n = (m); huy < _n; huy++) { n     long long u, v, w; n     cin >> u >> v >> w; n     adj[u].push_back(Edge(v, w, 0)); n     adj[v].push_back(Edge(u, w, 0)); n   } n   for (long long nene = 0, _n = (k); nene < _n; nene++) { n     long long v, t; n     cin >> v >> t; n     adj[1].push_back(Edge(v, t, 1)); n     adj[v].push_back(Edge(1, t, 1)); n   } n   set<pair<long long, long long> > pq; n   pq.clear(); n   pq.insert(pair<long long, long long>(0, 1)); n   for (long long i = (2), _b = (n); i <= _b; i++) dist[i] = oo; n   while (!pq.empty()) { n     pair<long long, long long> front = *(pq.begin()); n     long long d = front.first, u = front.second; n     pq.erase(pq.begin()); n     if (d > dist[u]) continue; n     for (Edge e : adj[u]) n       if (dist[u] + e.w < dist[e.to]) { n         dist[e.to] = dist[u] + e.w; n         pq.insert(pair<long long, long long>(dist[e.to], e.to)); n       } n   } n   for (long long u = (1), _b = (n); u <= _b; u++) n     for (Edge e : adj[u]) { n       if (dist[u] + e.w == dist[e.to]) { n         deg[e.to]++; n       } n     } n   res = k; n   for (long long u = (1), _b = (n); u <= _b; u++) n     for (Edge e : adj[u]) { n       if (e.type == 1 && dist[u] + e.w == dist[e.to]) { n         if (deg[e.to] == 1) res--; n         deg[e.to]--; n       } n     } n   cout << res <<   n ; n   fprintf(stderr,  Time taken: %.2fs n , n           (double)(clock() - tStart) / CLOCKS_PER_SEC); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, d; n bool b; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   int t; n   cin >> t; n   while (t--) { n     cin >> n >> d; n     b = false; n     if (d <= n) { n       cout <<  YES n ; n       continue; n     } n     for (long long x = 1; x * x <= d; x++) { n       long long X = x + 1; n       long long D = 0; n       D = d / X; n       if (d % X != 0) { n         D++; n       } n       long long sol = x + (D); n       if (sol <= n) { n         cout <<  YES n ; n         b = true; n         break; n       } n     } n     if (b == false) { n       cout <<  NO n ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int64_t n; n int64_t numbers[200000]; n int64_t exists[200000 + 1]; n struct Node { n   int64_t l, r, sum; n   Node *left, *right; n   int64_t first, last; n }; n deque<Node> nodes; n Node *root; n Node *newNode() { n   nodes.emplace_back(); n   return &nodes.back(); n } n Node *fillNode(int64_t first, int64_t last) { n   if (first >= last) { n     return nullptr; n   } n   int64_t mid = (first + (last - first) / 2); n   Node *result = newNode(); n   result->first = first; n   result->last = last; n   result->l = first; n   result->r = last - 1; n   if (first + 1 != last) { n     result->left = fillNode(first, mid); n     result->right = fillNode(mid, last); n   } else { n     result->left = nullptr; n     result->right = nullptr; n   } n   result->sum = 0; n   if (!result->left && !result->right) { n     result->sum = result->l; n   } else { n     if (result->left) { n       result->sum += result->left->sum; n     } n     if (result->right) { n       result->sum += result->right->sum; n     } n   } n   return result; n } n void fixup(Node *node, Node *parent) { n   if (node->r <= parent->l) { n     node->sum = (node->last - node->first) * parent->l; n     node->l = node->r = parent->l; n   } n } n int64_t update(Node *node, int64_t first, int64_t last, int64_t size, n                Node *parent) { n   if (first >= node->last || last <= node->first) return 0; n   if (parent) fixup(node, parent); n   if (node->l >= size) return 0; n   if (first <= node->first && node->last <= last && node->r <= size) { n     int64_t new_sum = (node->last - node->first) * size; n     int64_t result = new_sum - node->sum; n     node->sum = new_sum; n     node->l = size; n     node->r = size; n     return result; n   } n   int64_t sum_from_child = 0; n   if (node->left) { n     sum_from_child += update(node->left, first, last, size, node); n   } n   if (node->right) { n     int64_t res = update(node->right, first, last, size, node); n     sum_from_child += res; n   } n   if (node->left) { n     if (node->left->l > node->l) { n     } n     node->l = max(node->l, node->left->l); n   } n   if (node->right) { n     if (node->right->r > node->r) { n     } n     node->r = max(node->r, node->right->r); n   } n   node->sum += sum_from_child; n   return sum_from_child; n } n int64_t set_from(int64_t first, int64_t last) { n   if (first >= last) return 0; n   int64_t barSize = last; n   int64_t barIdx = first; n   int64_t res = update(root, barIdx, n, barSize, nullptr); n   return res; n } n int main() { n   std::ios_base::sync_with_stdio(false); n   cin >> n; n   root = fillNode(0, n); n   fill(begin(exists), end(exists), -1); n   for (int64_t i = 0; i < n; ++i) { n     cin >> numbers[i]; n     exists[numbers[i]] = i; n   } n   int64_t result = 0; n   for (int64_t gcd = 200000; gcd >= 1; --gcd) { n     std::vector<int64_t> idxs; n     for (int64_t i = gcd; i <= 200000; i += gcd) { n       if (exists[i] >= 0) idxs.push_back(exists[i]); n     } n     if (idxs.size() < 2) continue; n     nth_element(begin(idxs), begin(idxs) + 2, end(idxs)); n     int64_t x1 = idxs[0]; n     int64_t x2 = idxs[1]; n     if (x1 > x2) swap(x1, x2); n     nth_element(begin(idxs), begin(idxs) + idxs.size() - 2, end(idxs)); n     int64_t x3 = idxs[idxs.size() - 2]; n     int64_t x4 = idxs[idxs.size() - 1]; n     if (x3 > x4) swap(x3, x4); n     result += gcd * set_from(0, x3); n     result += gcd * set_from(x2 + 1, n); n     result += gcd * set_from(x1 + 1, x4); n   } n   cout << result << endl; n } n


#include <bits/stdc++.h> n using namespace std; n std::vector<long long> digit(long long num) { n   string str, s; n   std::vector<long long> v; n   str = to_string(num); n   for (int i = 0; i < str.size(); ++i) { n     s = str[i]; n     v.push_back(stoi(s)); n   } n   return v; n } n void solve() { n   long long num, best; n   cin >> num; n   std::vector<long long> arr(num + 11); n   std::vector<long long> d; n   arr[0] = 0; n   for (int i = 1; i < 10; ++i) { n     arr[i] = 1; n   } n   for (int i = 10; i <= num; ++i) { n     best = 2000000000000000000; n     d = digit(i); n     for (auto y : d) { n       if (y != 0) { n         best = min(best, arr[i - y] + 1); n       } n     } n     arr[i] = best; n   } n   cout << arr[num] << endl; n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   int tt = 1; n   while (tt--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int T; n   cin >> T; n   while (T--) { n     string s[9]; n     for (long long int i = 0; i < 9; i++) { n       cin >> s[i]; n     } n     for (long long int i = 0; i < 9; i++) { n       for (long long int j = 0; j < 9; j++) { n         if (s[i][j] ==  3 ) s[i][j] =  1 ; n       } n     } n     for (long long int i = 0; i < 9; i++) { n       cout << s[i] <<   n ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int32_t main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   long long n; n   cin >> n; n   long long l = 1, k = n, cnt = 0, h = n, ans = 0; n   while (l <= h) { n     long long mid = l + (h - l) / 2; n     k = n; n     cnt = 0; n     while (k > 0) { n       if (k >= mid) { n         k = k - mid; n         cnt += mid; n         k = k - (k / 10); n       } else { n         cnt += k; n         break; n       } n     } n     if (cnt >= (n + 1) / 2) { n       ans = mid; n       h = mid - 1; n     } else { n       l = mid + 1; n     } n   } n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long l1, l2, r1, r2, k; n int main() { n   cin >> l1 >> r1 >> l2 >> r2 >> k; n   if (l2 > r1 || r2 < l1) { n     cout << 0 <<   n ; n     return 0; n   } n   long long l, r; n   if (r1 < r2) { n     r = r1; n   } else { n     r = r2; n   } n   if (l1 > l2) { n     l = l1; n   } else { n     l = l2; n   } n   long long flag = 0; n   if (k >= l && k <= r) { n     flag = 1; n   } n   cout << r - l - flag + 1 <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 200005; n int n, c[30], a[N], s[N], st[N], t, w, k, m; n char b[N]; n void sol() { n   scanf( %s , b + 1); n   n = strlen(b + 1); n   for (int i = 0; i < 26; i++) c[i] = 0; n   t = m = w = k = 0; n   for (int i = 1; i <= n; i++) { n     s[i] = b[i] -  a ; n     if (i > 1 && s[i] == s[i - 1]) k++, c[s[i]]++; n   } n   for (int i = 0; i < 26; i++) m = max(m, c[i]); n   printf( %d n , max((k + 1) / 2, m) + 1); n   for (int i = 1; i <= n; i++) { n     a[++w] = s[i]; n     if (w <= 1 || a[w] != a[w - 1]) continue; n     if (a[w] == a[st[t]] || !t) { n       st[++t] = w; n       continue; n     } n     m = 0; n     for (int j = 0; j < 26; j++) n       if (c[j] > c[m]) m = j; n     if (c[m] * 2 < k || m == a[w] || m == a[st[t]]) { n       k -= 2; n       c[a[w]]--; n       c[a[st[t]]]--; n       printf( %d %d n , st[t], w - 1); n       a[st[t]] = a[w]; n       w = st[t]; n       t--; n     } else n       st[++t] = w; n   } n   for (int l = w, i = w; i >= 1; i--) { n     if (i == 1 || a[i - 1] == a[i]) { n       printf( %d %d n , i, l); n       l = i - 1; n     } n   } n } n int main() { n   int t; n   scanf( %d , &t); n   while (t--) sol(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, w1[555][555], w2[555][555], w3[555][555], gl, Pre[300011], anslen; n char ch; n struct AnsNode { n   int x, y, z; n   void init(int _x, int _y, int _z) { x = _x, y = _y, z = _z; } n } Ans[1000111]; n struct Node { n   int x, y; n   void init(int _x, int _y) { x = _x, y = _y; } n } gg[300011]; n void Read(int &res) { n   for (ch = getchar(); ch !=  .  && ch !=  # ; ch = getchar()) n     ; n   res = (ch ==  . ); n } n void Work(int nowx, int nowy) { n   int i, dx, dy; n   gg[gl = 1].init(nowx, nowy); n   w2[nowx][nowy] = 1; n   for (i = 1; i <= gl; ++i) { n     dx = gg[i].x, dy = gg[i].y; n     if (dx > 1 && w1[dx - 1][dy] && w2[dx - 1][dy] == 0) { n       w2[dx - 1][dy] = 1; n       gg[++gl].init(dx - 1, dy); n       Pre[gl] = i; n     } n     if (dx < n && w1[dx + 1][dy] && w2[dx + 1][dy] == 0) { n       w2[dx + 1][dy] = 1; n       gg[++gl].init(dx + 1, dy); n       Pre[gl] = i; n     } n     if (dy > 1 && w1[dx][dy - 1] && w2[dx][dy - 1] == 0) { n       w2[dx][dy - 1] = 1; n       gg[++gl].init(dx, dy - 1); n       Pre[gl] = i; n     } n     if (dy < m && w1[dx][dy + 1] && w2[dx][dy + 1] == 0) { n       w2[dx][dy + 1] = 1; n       gg[++gl].init(dx, dy + 1); n       Pre[gl] = i; n     } n   } n   for (i = gl; i > 1; --i) { n     dx = gg[Pre[i]].x, dy = gg[Pre[i]].y; n     if (w3[dx][dy] == 0) { n       Ans[++anslen].init(1, dx, dy); n       w3[dx][dy] = 1; n     } n     if (w3[gg[i].x][gg[i].y] == 1) Ans[++anslen].init(0, gg[i].x, gg[i].y); n     if (w3[gg[i].x][gg[i].y] < 2) Ans[++anslen].init(2, gg[i].x, gg[i].y); n     w3[gg[i].x][gg[i].y] = 2; n   } n   if (w3[dx][dy] == 0) { n     Ans[++anslen].init(1, nowx, nowy); n     w3[nowx][nowy] = 1; n   } n } n int main() { n   int i, j; n   scanf( %d%d , &n, &m); n   for (i = 1; i <= n; ++i) n     for (j = 1; j <= m; ++j) Read(w1[i][j]); n   memset(w2, 0, sizeof(w2)); n   memset(w3, 0, sizeof(w3)); n   anslen = 0; n   for (i = 1; i <= n; ++i) n     for (j = 1; j <= m; ++j) n       if (w2[i][j] == 0 && w1[i][j] != 0) Work(i, j); n   cout << anslen << endl; n   for (i = 1; i <= anslen; ++i) { n     if (Ans[i].x == 0) n       printf( D %d %d n , Ans[i].y, Ans[i].z); n     else if (Ans[i].x == 1) n       printf( B %d %d n , Ans[i].y, Ans[i].z); n     else n       printf( R %d %d n , Ans[i].y, Ans[i].z); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline int read() { n   int x = 0, f = 1; n   char c = getchar(); n   for (; c <  0  || c >  9 ; c = getchar()) n     if (c ==  - ) f = -1; n   for (; c >=  0  && c <=  9 ; c = getchar()) x = x * 10 + c -  0 ; n   return x * f; n } n int n; n char a[1000010], b[1000010]; n int fail[1000010]; n int main() { n   n = read(); n   scanf( %s , b + 1); n   scanf( %s , a + 1); n   n--; n   for (int i = (1); i <= (n); i++) n     if (a[i] ==  N ) n       a[i] =  S ; n     else if (a[i] ==  S ) n       a[i] =  N ; n     else if (a[i] ==  E ) n       a[i] =  W ; n     else if (a[i] ==  W ) n       a[i] =  E ; n   reverse(a + 1, a + n + 1); n   int j = 0; n   for (int i = (2); i <= (n); i++) { n     for (; j && a[j + 1] != a[i]; j = fail[j]) n       ; n     fail[i] = (a[j + 1] == a[i]) ? ++j : j; n   } n   j = 0; n   for (int i = (1); i <= (n); i++) { n     for (; j && a[j + 1] != b[i]; j = fail[j]) n       ; n     if (a[j + 1] == b[i]) j++; n   } n   if (j) n     printf( NO n ); n   else n     printf( YES n ); n } n


#include <bits/stdc++.h> n using namespace std; n int A[10000][2]; n int main() { n   int N, M, K; n   cin >> N >> M >> K; n   int cur = 0; n   for (int i = 0; i < M; i++) n     for (int j = (i + 1); j < M; j++) { n       A[cur][K] = i + 1; n       A[cur][1 - K] = j + 1; n       cur++; n     } n   cout << cur << endl; n   for (int i = 0; i < cur; i++) cout << A[i][0] <<     << A[i][1] << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 0x3f3f3f3f; n const int MAXN = 1e6 + 5; n long long a[MAXN], b[MAXN]; n int main() { n   int x; n   cin >> x; n   for (int i = 1; i <= x; i++) n     for (int j = 1; j <= x; j++) { n       if (i * j > x && (i / j) < x && (i % j == 0)) { n         cout << i <<     << j << endl; n         return 0; n       } n     } n   cout << -1 << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long maxN = 1e5 + 10; n const long long MOD = 1e9 + 17; n long long s, t, n, m; n long long d[2][maxN]; n vector<pair<long long, long long> > g[maxN], h[maxN]; n vector<pair<pair<long long, long long>, long long> > edge; n long long dp[2][maxN]; n void dij0(long long source) { n   fill(d[0], d[0] + maxN, 1e18 + 10); n   d[0][source] = 0; n   dp[0][source] = 1; n   set<pair<long long, long long> > s; n   s.insert(make_pair(d[0][source], source)); n   while (!s.empty()) { n     long long v = s.begin()->second; n     s.erase(s.begin()); n     for (long long i = 0; i < g[v].size(); i++) { n       long long u = g[v][i].first, w = g[v][i].second; n       if (d[0][u] > d[0][v] + w) { n         dp[0][u] = dp[0][v] % MOD; n         s.erase(make_pair(d[0][u], u)); n         d[0][u] = d[0][v] + w; n         s.insert(make_pair(d[0][u], u)); n       } else if (d[0][u] == d[0][v] + w) n         dp[0][u] += dp[0][v], dp[0][u] %= MOD; n     } n   } n } n void dij1(long long source) { n   fill(d[1], d[1] + maxN, 1e18 + 10); n   d[1][source] = 0; n   dp[1][source] = 1; n   set<pair<long long, long long> > s; n   s.insert(make_pair(d[1][source], source)); n   while (!s.empty()) { n     long long v = s.begin()->second; n     s.erase(s.begin()); n     for (long long i = 0; i < h[v].size(); i++) { n       long long u = h[v][i].first, w = h[v][i].second; n       if (d[1][u] > d[1][v] + w) { n         dp[1][u] = dp[1][v] % MOD; n         s.erase(make_pair(d[1][u], u)); n         d[1][u] = d[1][v] + w; n         s.insert(make_pair(d[1][u], u)); n       } else if (d[1][u] == d[1][v] + w) n         dp[1][u] += dp[1][v], dp[1][u] %= MOD; n     } n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin >> n >> m >> s >> t; n   s--; n   t--; n   for (long long i = 0; i < m; i++) { n     long long v, u, w; n     cin >> v >> u >> w; n     v--, u--; n     g[v].push_back(make_pair(u, w)); n     h[u].push_back(make_pair(v, w)); n     edge.push_back(make_pair(make_pair(v, u), w)); n   } n   dij0(s); n   dij1(t); n   for (long long i = 0; i < m; i++) { n     long long v = edge[i].first.first, u = edge[i].first.second; n     long long w = edge[i].second; n     if (d[0][v] + w + d[1][u] == d[0][t]) { n       if ((dp[0][v] * dp[1][u]) % MOD == dp[0][t]) { n         cout <<  YES  <<   n ; n         continue; n       } n     } n     if (d[0][v] + d[1][u] + 1 < d[0][t]) { n       cout <<  CAN   << d[0][v] + w + d[1][u] - d[0][t] + 1 <<   n ; n       continue; n     } n     cout <<  NO  <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int a, b, c, d, i, j, k, l, arr[26], max = 1; n   long long int dp[1005], len[1005]; n   for (i = 0; i < 1005; i++) dp[i] = 0; n   cin >> a; n   string s; n   cin >> s; n   for (i = 0; i < 26; i++) cin >> arr[i]; n   dp[0] = 1; n   dp[1] = 1; n   len[0] = 0; n   for (i = 2; i <= a; i++) { n     int t = 0; n     l = 99999; n     j = i + 1; n     while (j > 1) { n       j--; n       t++; n       if (l > arr[s[j - 1] - 97]) l = arr[s[j - 1] - 97]; n       if (l >= t) { n         dp[i] += dp[j - 1]; n       } else { n         if (i - j > max) max = i - j; n         len[i] = j; n         break; n       } n       if (j == 1) { n         if (max < i) max = i; n       } n       len[i] = 0; n     } n     dp[i] = dp[i] % 1000000007; n   } n   int ss = 1; n   i = a; n   while (len[i] != 0) { n     i = len[i]; n     ss++; n   } n   cout << dp[a] << endl; n   cout << max << endl; n   cout << ss << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n typedef struct { n   long long v; n   long long c; n } double_pair; n struct line { n   long long k, b; n   line() {} n   line(long long _k, long long _b) : k(_k), b(_b) {} n   long long Solve(long long val) { n     long long _a = val - b, _b = k; n     if (_a % _b == 0) n       return _a / _b; n     else n       return _a / _b + 1; n   } n   long long f(long long x) { return k * x + b; } n }; n double_pair D[300000]; n int n; n line St[300000]; n int top; n long long X[300000], s; n long long intersection(line a, line b) { n   long long _a = a.b - b.b, _b = b.k - a.k; n   if (_a % _b == 0) n     return _a / _b; n   else n     return _a / _b + 1; n } n bool slope_compare(double_pair d1, double_pair d2) { n   return ((d1.c < d2.c) || (d1.c == d2.c && d1.v > d2.v)); n } n bool check(long long x, long long _s) { n   if (x > X[top - 1]) return x >= St[top].Solve(_s); n   int pos = lower_bound(X + 1, X + top, x) - X; n   if (X[pos] == x) pos++; n   return x >= St[pos].Solve(_s); n } n long long chat(long long _s) { n   long long l = 0, r = _s, mid; n   while (l + 1 < r) { n     mid = (l + r) >> 1; n     if (check(mid, _s)) n       r = mid; n     else n       l = mid; n   } n   return r; n } n void find_hull() { n   St[++top] = line(D[0].v, -D[0].c); n   long long i1, i2; n   for (int i = 1; i < n; ++i) { n     long long x0 = chat(D[i].c); n     long long p = lower_bound(X + 1, X + top, x0) - X; n     long long y0 = n         St[p + (X[p] == x0)].k * x0 + St[p + (X[p] == x0)].b - D[i].c; n     line tmp(D[i].v, y0 - x0 * D[i].v); n     while (top >= 2 && (((i1 = intersection(tmp, St[top])) <= n                              (i2 = intersection(St[top], St[top - 1])) || n                          (i1 == i2 && tmp.f(i1) >= St[top].f(i1))))) n       --top; n     St[++top] = tmp; n     X[top - 1] = intersection(St[top], St[top - 1]); n   } n } n int main() { n   cin >> n >> s; n   for (int i = 1; i <= n; i++) cin >> D[i].v >> D[i].c; n   sort(D + 1, D + n + 1, slope_compare); n   int tmp_n = n, maxv = 0; n   n = 0; n   for (int i = 1; i <= tmp_n; i++) { n     if (maxv >= D[i].v) continue; n     maxv = D[i].v; n     D[n++] = D[i]; n   } n   find_hull(); n   cout << chat(s); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 123457; n int n, m, S, A, D, R, h[N]; n vector<int> adj[N]; n bool is[N]; n bool dfs(int v, int par = 0) { n   h[v] = h[par] + 1; n   bool c = is[v]; n   if (c && h[v] >= D) D = h[v], R = v; n   if (c && h[v] == D && v < S) S = v; n   for (int i = 0; i < adj[v].size(); ++i) n     if (adj[v][i] != par) c |= dfs(adj[v][i], v); n   if (c) ++A; n   return c; n } n int main() { n   cin >> n >> m; n   int a, b; n   for (int i = 0; i < n - 1; ++i) { n     cin >> a >> b; n     adj[a].push_back(b), adj[b].push_back(a); n   } n   h[0] = -1; n   memset(is, false, sizeof(is)); n   S = 0, A = 0, D = 0; n   for (int i = 0; i < m; ++i) { n     cin >> R; n     is[R] = true; n   } n   dfs(R); n   dfs(R); n   S = N; n   dfs(R), dfs(R); n   cout << S << endl << (A - 4) / 2 - D << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int MD = 1000000007; n long long A[100000 + 1], dp[100000 + 1]; n long long exp(long long a, long long b) { n   long long r = 1; n   while (b > 0) { n     if (b & 1) r = r * a; n     b /= 2; n     a = a * a; n   } n   return r; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   long long t, n, i, s, j, p, m, x, y, k, q; n   string s1; n   map<long long, long long> mp; n   for (i = 0; i <= 32; i++) mp.insert({exp(2, i), i}); n   cin >> n >> m; n   for (long long i = 1; i <= n; i++) { n     cin >> x; n     A[mp[x]]++; n   } n   while (m--) { n     cin >> x; n     p = 0; n     for (i = 32; i >= 0; --i) { n       k = min(x / exp(2, i), A[i]); n       p += k; n       x -= k * exp(2, i); n     } n     if (x != 0) n       cout <<  -1 n ; n     else n       cout << p <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   int server, temp; n   int a, b; n   a = 0; n   b = 0; n   int sum1, sum2; n   sum1 = 0; n   sum2 = 0; n   for (int i = 0; i < n; i++) { n     cin >> server; n     if (server == 1) { n       cin >> temp; n       a++; n       sum1 += temp; n     } else { n       cin >> temp; n       b++; n       sum2 += temp; n     } n     cin >> temp; n   } n   if (sum1 / a >= 5) n     cout <<  LIVE  << endl; n   else n     cout <<  DEAD  << endl; n   if (sum2 / b >= 5) n     cout <<  LIVE  << endl; n   else n     cout <<  DEAD  << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = 1 << 30; n const long long linf = 1LL << 60; n const int maxn = 100 + 5; n int A[maxn]; n bool used[maxn]; n vector<int> Q; n vector<vector<int> > B; n vector<int> C; n int n, k, m, q; n long double anal() { n   long double res = 0; n   for (int i = 0; i < m; ++i) { n     res += (long double)A[B.back()[i] - 1]; n     used[B.back()[i] - 1] = 1; n   } n   res /= (long double)m; n   return res; n } n int main() { n   long double _min = inf; n   long double _max = -1; n   cin >> n >> k; n   for (int i = 0; i < n; ++i) cin >> A[i]; n   m = n / k; n   Q.reserve(m); n   cin >> q; n   for (int i = 0; i < q; ++i) { n     Q.clear(); n     for (int j = 0; j < m; ++j) { n       int x; n       cin >> x; n       Q.push_back(x); n     } n     sort((Q).begin(), (Q).end()); n     bool _new = 1; n     for (int j = 0; j < B.size(); ++j) { n       if (B[j][0] == Q[0]) { n         _new = 0; n         break; n       } n     } n     if (_new) { n       B.push_back(Q); n       long double _res = anal(); n       if (_min > _res) _min = _res; n       if (_max < _res) _max = _res; n     } n   } n   if ((int)(B).size() < k) { n     C.reserve(n); n     for (int i = 0; i < n; ++i) { n       if (!used[i]) C.push_back(A[i]); n     } n     sort((C).begin(), (C).end()); n     long double res = 0; n     for (int i = 0; i < m; ++i) { n       res += (long double)C[i]; n     } n     res /= (long double)m; n     if (_min > res) _min = res; n     if (_max < res) _max = res; n     res = 0; n     for (int i = (int)(C).size() - 1; i >= (int)(C).size() - m; --i) { n       res += (long double)C[i]; n     } n     res /= (long double)m; n     if (_min > res) _min = res; n     if (_max < res) _max = res; n   } n   cout.setf(ios::fixed); n   cout.precision(8); n   cout << _min <<     << _max <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int mod = 1e9 + 7; n const double eps = 1e-4; n const long long INF = 0x3f3f3f3f3f3f3f3f; n const int inf = 0x3f3f3f3f; n const int maxn = 1e5 + 7; n const int maxm = 1e6 + 7; n const double pi = acos(-1.0); n long long a[maxn]; n long long b[maxn], c[maxn]; n int main() { n   int n; n   scanf( %d , &n); n   ; n   for (int i = 1; i <= n; i++) scanf( %lld , &a[i]); n   for (int i = 1; i < n; i++) { n     int tmp = a[i] - a[i + 1]; n     if (tmp < 0) tmp = -tmp; n     if (i % 2 == 1) { n       b[i] = tmp; n       c[i] = -tmp; n     } else { n       b[i] = -tmp; n       c[i] = tmp; n     } n   } n   long long sum = 0; n   long long mx1 = -1, mx2 = -1; n   for (int i = 1; i < n; i++) { n     sum += b[i]; n     mx1 = max(mx1, sum); n     if (sum < 0) { n       sum = 0; n       if (i % 2 == 1) i--; n     } n   } n   sum = 0; n   for (int i = 2; i < n; i++) { n     sum += c[i]; n     mx2 = max(mx2, sum); n     if (sum < 0) { n       sum = 0; n       if (i % 2 == 0) i--; n     } n   } n   cout << max(mx1, mx2) << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   string s; n   cin >> n >> s; n   vector<int> spareIndices; n   vector<bool> LetterPresent(n); n   for (int i = 0, j = s.length() - 1; i < (s.length() + 1) / 2; ++i, --j) { n     if (s[i] != s[j]) { n       if (s[i] ==  ? ) { n         s[i] = s[j]; n         LetterPresent[s[i] -  a ] = true; n         continue; n       } n       if (s[j] ==  ? ) { n         s[j] = s[i]; n         LetterPresent[s[i] -  a ] = true; n         continue; n       } n       cout <<  IMPOSSIBLE ; n       return 0; n     } n     if (s[i] ==  ? ) { n       spareIndices.push_back(i); n       continue; n     } n     LetterPresent[s[i] -  a ] = true; n   } n   vector<char> unused_letters; n   for (int i = 0; i < LetterPresent.size(); ++i) { n     if (!LetterPresent[i]) unused_letters.push_back( a  + i); n   } n   if (unused_letters.size() > spareIndices.size()) { n     cout <<  IMPOSSIBLE ; n     return 0; n   } n   int a = spareIndices.size() - unused_letters.size(); n   int i = 0; n   for (; i < a; ++i) { n     s[spareIndices[i]] = s[s.size() - 1 - spareIndices[i]] =  a ; n   } n   for (; i < spareIndices.size(); ++i) { n     s[spareIndices[i]] = s[s.size() - 1 - spareIndices[i]] = n         unused_letters[i - a]; n   } n   cout << s; n } n


#include <bits/stdc++.h> n using namespace std; n char s[1000001], t[1000001]; n long long z[1000001], c[1000001]; n int main() { n   int n, k; n   scanf( %d%d%s%s , &n, &k, s + 1, t + 1); n   if (k == 1) { n     printf( %d n , k * n); n     return 0; n   } n   int o = 1; n   while (o <= n && s[o] == t[o]) o++; n   if (o > n) { n     printf( %d n , n); n     return 0; n   } n   long long ans = n + (n - o + 1); n   k -= 2; n   o++; n   while (o <= n) { n     if (s[o] ==  a ) z[n - o + 1]++; n     if (t[o] ==  b ) z[n - o + 1]++; n     o++; n   } n   for (int i = n; i; i--) { n     z[i] += c[i]; n     c[i - 1] += c[i]; n     int kk = min(1ll * k, z[i]); n     ans += 1ll * i * kk; n     k -= kk; n     c[i - 1] += kk; n   } n   printf( %I64d n , ans); n } n


#include <bits/stdc++.h> n using namespace std; n int n; n string s; n long long rights[1000010], lefts[1000010], mins[1000010]; n long long suml[1000010], sumr[1000010]; n int min(int a, int b) { return a < b ? a : b; } n int main() { n   scanf( %d , &n); n   cin >> s; n   lefts[0] = 0; n   rights[n - 1] = 0; n   for (int i = 1; i < n; i++) { n     if (s[i - 1] ==  U ) lefts[i]++; n     lefts[i] += lefts[i - 1]; n   } n   for (int i = n - 2; i >= 0; i--) { n     if (s[i + 1] ==  D ) rights[i]++; n     rights[i] += rights[i + 1]; n   } n   for (int i = 0; i < n; i++) n     mins[i] = min(lefts[i] + (s[i] ==  U  ? 1 : 0), n                   rights[i] + (s[i] ==  D  ? 1 : 0)); n   long long t = 0; n   queue<long long> q; n   for (int i = 0; i < n; i++) { n     t += q.size(); n     if (q.size() <= mins[i]) { n       suml[i] = t; n     } else { n       while (q.size() > mins[i]) { n         t -= i - q.front(); n         q.pop(); n       } n       suml[i] = t; n     } n     if (s[i] ==  U ) q.push(i); n   } n   while (!q.empty()) q.pop(); n   t = 0; n   for (int i = n - 1; i >= 0; i--) { n     t += q.size(); n     if (q.size() <= mins[i]) { n       sumr[i] = t; n     } else { n       while (q.size() > mins[i]) { n         t -= q.front() - i; n         q.pop(); n       } n       sumr[i] = t; n     } n     if (s[i] ==  D ) q.push(i); n   } n   for (long long i = 0; i < n; i++) { n     if (rights[i] > lefts[i]) { n       cout << sumr[i] * 2 + suml[i] * 2 + i + 1 <<    ; n     } else if (rights[i] < lefts[i]) { n       cout << sumr[i] * 2 + suml[i] * 2 + n - i <<    ; n     } else { n       if (s[i] ==  D ) n         cout << sumr[i] * 2 + suml[i] * 2 + i + 1 <<    ; n       else n         cout << sumr[i] * 2 + suml[i] * 2 + n - i <<    ; n     } n   } n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MX = 2e5 + 5; n vector<int> v(MX); n struct Q { n   int t, l, r; n }; n vector<Q> qs(MX); n int n, q, m, p; n int main() { n   cin >> n >> q >> m; n   for (int i = 1; i <= n; i++) cin >> v[i]; n   for (int i = 1; i <= q; i++) cin >> qs[i].t >> qs[i].l >> qs[i].r; n   while (m--) { n     cin >> p; n     for (int i = q; i > 0; i--) { n       if (p < qs[i].l || p > qs[i].r) continue; n       if (qs[i].t == 1) { n         p--; n         if (p < qs[i].l) p = qs[i].r; n       } else n         p = qs[i].r - (p - qs[i].l); n     } n     cout << v[p] <<    ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<string> v; n int main(void) { n   int n; n   scanf( %d , &n); n   for (int i = 0; i < n; i++) { n     char s[50]; n     scanf( %s , &s); n     v.push_back((string)s); n   } n   int res = 0; n   while (true) { n     int ok = 1; n     for (int i = 0; i < n; i++) n       if (v[i][res] != v[0][res]) { n         printf( %d n , res); n         return 0; n       } n     res++; n   } n   printf( %d n , res); n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, i, carry = 0, flag = 1; n   cin >> n; n   int ar[n]; n   for (i = 0; i < n; i++) { n     cin >> ar[i]; n     if (ar[i] == 0 && carry == 1) { n       flag = 0; n     } n     if (ar[i] % 2 == 0 && carry == 0) { n       continue; n     } n     if (i == (n - 1)) { n       if (ar[i] % 2 == 0 && carry == 1) { n         cout <<  NO n ; n         return 0; n       } n       if (ar[i] % 2 == 1 && carry == 0) { n         cout <<  NO n ; n         return 0; n       } n     } n     if (ar[i] % 2 == 1 && carry == 1) { n       carry = 0; n       continue; n     } n     carry = 1; n   } n   if (flag == 0) { n     cout <<  NO n ; n     return 0; n   } n   cout <<  YES n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double eps = 1e-12; n struct P { n   double x, y; n   P(double x = 0, double y = 0) : x(x), y(y){}; n } a, b, c, o, p; n P operator+(P a, P b) { return P(a.x + b.x, a.y + b.y); } n P operator*(P a, double b) { return P(a.x * b, a.y * b); } n inline double dis(P a, P b) { n   return sqrt(((a.x - b.x) * (a.x - b.x)) + ((a.y - b.y) * (a.y - b.y))); n } n inline void read(P &a) { scanf( %lf%lf , &a.x, &a.y); } n double t1, t2, l, r, m, m1, m2, ab, bc, ac, ap; n double Calc(double k) { n   p = b * (1 - k) + c * k; n   ap = dis(a, p); n   if (ap + bc * (1 + k) < t1 && ap + bc * (1 - k) < t2) n     return min(t1 - bc * (1 + k), t2 - bc * (1 - k)); n   double l = 0, r = 1; n   for (int i = 0; i < 100; ++i) { n     m = (l + r) * 0.5; n     o = a * (1 - m) + p * m; n     if (ap * m + dis(o, b) + bc < t1 && ap * m + dis(o, c) < t2) n       l = m; n     else n       r = m; n   } n   return (l + r) * 0.5 * ap; n } n int main() { n   scanf( %lf%lf , &t1, &t2); n   read(a); n   read(c); n   read(b); n   ab = dis(a, b); n   bc = dis(b, c); n   ac = dis(a, c); n   t1 += ab + bc + eps; n   t2 += ac + eps; n   if (ab + bc < t2) { n     printf( %.10lf n , min(t1, t2)); n     return 0; n   } n   l = 0, r = 1; n   for (int i = 0; i < 100; ++i) { n     m1 = (l + l + r) / 3; n     m2 = (l + r + r) / 3; n     if (Calc(m1) < Calc(m2)) n       l = m1; n     else n       r = m2; n   } n   printf( %.10lf n , Calc((l + r) * .5)); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void solve(istream& in, ostream& out) { n   int n; n   in >> n; n   int res = n % 2 ? 0 : 1LL << (n / 2); n   out << res << endl; n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(nullptr); n   std::istream& in(std::cin); n   std::ostream& out(std::cout); n   solve(in, out); n } n


#include <bits/stdc++.h> n using namespace std; n long long mi, mx, n, ta, tb, tc; n void C(long long x, long long y, long long z) { n   ta = (x + 1) * (y + 2) * (z + 2); n   if (ta > mx) mx = ta; n   if (ta < mi) mi = ta; n } n int main() { n   long long a, b, c, d, uu; n   uu = 1000000; n   scanf( %I64d , &n); n   int k = (int)sqrt(double(n)); n   mx = -999; n   mi = uu * uu * uu; n   for (int i = 1; i <= k; i++) { n     if (n % i == 0) { n       a = i; n       b = n / i; n       int kk = (int)sqrt(double(b)); n       for (int j = 1; j <= kk; j++) n         if (b % j == 0) { n           c = b / j; n           d = j; n           C(a, c, d); n           C(c, a, d); n           C(d, a, c); n         } n     } n   } n   printf( %I64d %I64d n , mi - n, mx - n); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long expo(long long a, long long b, long long m) { n   long long result = 1; n   while (b) { n     if (b & 1) { n       result = (result * a) % m; n     } n     b = (b >> 1) % m; n     a = (a * a) % m; n   } n   return result; n } n double expof(double a, int b) { n   double result = 1; n   while (b) { n     if (b & 1) { n       result = (result * a); n     } n     b = (b >> 1); n     a = (a * a); n   } n   return result; n } n bool comp(pair<long long, long long> a, pair<long long, long long> b) { n   if (a.second < b.second) return true; n } n int main() { n   long long m, n, t, c, l, x; n   vector<pair<long long, pair<long long, long long> > > p; n   vector<long long> v; n   cin >> m; n   long long ans = 0; n   for (int i = 0; i < m; ++i) { n     cin >> t; n     if (t == 1) { n       cin >> x; n       ans++; n       v.push_back(ans); n       p.push_back(make_pair(1, make_pair(x, 0))); n     } else { n       cin >> l >> c; n       ans += c * l; n       v.push_back(ans); n       p.push_back(make_pair(2, make_pair(l, c))); n     } n   } n   cin >> n; n   long long q[100005]; n   for (int i = 0; i < n; ++i) { n     cin >> q[i]; n   } n   for (int i = 0; i < n; ++i) { n     x = q[i]; n     vector<long long>::iterator it = upper_bound(v.begin(), v.end(), x); n     long long ix = it - v.begin(); n     ix--; n     if (v[ix] == x) { n       if (p[ix].first == 1) { n         cout << p[ix].second.first <<    ; n         continue; n       } else { n         x = p[ix].second.first; n       } n     } else { n       if ((x - v[ix]) % p[ix + 1].second.first == 0) { n         x = p[ix + 1].second.first; n       } else n         x = (x - v[ix]) % p[ix + 1].second.first; n     } n     while (1) { n       vector<long long>::iterator it = upper_bound(v.begin(), v.end(), x); n       long long ix = it - v.begin(); n       ix--; n       if (v[ix] == x) { n         if (p[ix].first == 1) { n           cout << p[ix].second.first <<    ; n           break; n         } else { n           x = p[ix].second.first; n           continue; n         } n       } n       if ((x - v[ix]) % p[ix + 1].second.first == 0) { n         x = p[ix + 1].second.first; n       } else n         x = (x - v[ix]) % p[ix + 1].second.first; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 0x3f3f3f3f; n const int MAXN = 200005; n const int MOD = 1e9 + 9; n vector<int> g[MAXN]; n int n, m, q, ans; n int rows[MAXN]; n bool vist[MAXN]; n pair<int, int> samp[MAXN]; n void dfs(int st) { n   if (vist[st]) return; n   vist[st] = 1; n   for (int i = 0; i < g[st].size(); i++) { n     dfs(g[st][i]); n   } n } n void buildG() { n   sort(samp, samp + q); n   for (int i = 1; i < q; ++i) { n     int r = samp[i].first, c = samp[i].second; n     int rl = samp[i - 1].first, cl = samp[i - 1].second; n     if (r == rl) { n       g[c].push_back(cl); n       g[cl].push_back(c); n     } n   } n } n int main() { n   scanf( %d %d %d , &n, &m, &q); n   for (int i = 0; i < q; ++i) { n     int r, c; n     scanf( %d %d , &r, &c); n     r--; n     c--; n     rows[r] = 1; n     samp[i] = {r, c}; n   } n   buildG(); n   for (int i = 0; i < m; ++i) { n     if (!vist[i]) { n       ans++; n       dfs(i); n     } n   } n   ans--; n   for (int i = 1; i < n; ++i) rows[i] += rows[i - 1]; n   ans += n - rows[n - 1]; n   printf( %d 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(NULL); n   cout.tie(NULL); n   const long maxSteps = 1000000000; n   long n, m; n   cin >> n >> m; n   long x, y; n   cin >> x >> y; n   int k; n   cin >> k; n   long long total = 0; n   while (k--) { n     long dx = 0, dy = 0; n     cin >> dx >> dy; n     long stepsX = maxSteps, stepsY = maxSteps; n     if (dx > 0) { n       stepsX = (n - x) / dx; n     } else if (dx < 0) { n       stepsX = (x - 1) / -dx; n     } n     if (dy > 0) { n       stepsY = (m - y) / dy; n     } else if (dy < 0) { n       stepsY = (y - 1) / -dy; n     } n     long stepsnum = 0; n     if (stepsY > 0 && stepsX > 0) { n       stepsnum = min(stepsX, stepsY); n     } n     x += stepsnum * dx; n     y += stepsnum * dy; n     total += stepsnum; n   } n   cout << total; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int l, r; n   scanf( %d%d , &l, &r); n   if (l == r) n     printf( %d n , l); n   else n     puts( 2 ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double eps = 1e-9; n const int inf = 2000000000; n const long long infLL = 9000000000000000000; n template <typename first, typename second> n ostream &operator<<(ostream &os, const pair<first, second> &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   for (auto 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   for (auto 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   for (auto it = v.begin(); it != v.end(); ++it) { n     if (it != v.begin()) os <<  ,  ; n     os << *it; n   } n   return os <<  ] ; n } n template <typename first, typename second> n ostream &operator<<(ostream &os, const map<first, second> &v) { n   os <<  [ ; n   for (auto 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 void faltu() { cerr <<   n ; } n template <typename T> n void faltu(T a[], int n) { n   for (int i = 0; i < n; ++i) cerr << a[i] <<    ; n   cerr <<   n ; n } n template <typename T, typename... hello> n void faltu(T arg, const hello &...rest) { n   cerr << arg <<    ; n   faltu(rest...); n } n const int mx = 2e5 + 5; n vector<int> adjlist[mx]; n int n; n bool isleaf[mx]; n int deg[mx]; n struct info { n   int leaf, child, dist; n }; n bool cmp(const info &lhs, const info &rhs) { return lhs.dist > rhs.dist; } n vector<info> dp[mx]; n void dfs(int u, int par) { n   vector<info> store; n   store.push_back({u, u, 0}); n   for (auto v : adjlist[u]) { n     if (v == par) continue; n     dfs(v, u); n     info temp = dp[v][0]; n     ++temp.dist; n     temp.child = v; n     store.push_back(temp); n   } n   sort(store.begin(), store.end(), cmp); n   while (store.size() > 3) store.pop_back(); n   dp[u] = store; n } n int ans = 0; n vector<int> vec; n void dfs2(int u, int par) { n   if (dp[u].size() >= 3) { n     if (ans < dp[u][0].dist + dp[u][1].dist + dp[u][2].dist) { n       ans = dp[u][0].dist + dp[u][1].dist + dp[u][2].dist; n       vec.clear(); n       vec.push_back(dp[u][0].leaf); n       vec.push_back(dp[u][1].leaf); n       vec.push_back(dp[u][2].leaf); n     } n   } n   for (auto v : adjlist[u]) { n     if (v == par) continue; n     for (int i = 0; i < dp[u].size(); ++i) { n       if (dp[u][i].child == v) continue; n       info temp = dp[u][i]; n       temp.child = u; n       ++temp.dist; n       dp[v].push_back(temp); n       sort(dp[v].begin(), dp[v].end(), cmp); n       dfs2(v, u); n       break; n     } n   } n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   ; n   cin >> n; n   for (int i = 0; i < n - 1; ++i) { n     int a, b; n     cin >> a >> b; n     adjlist[a].push_back(b); n     adjlist[b].push_back(a); n     ++deg[a]; n     ++deg[b]; n   } n   for (int i = 1; i <= n; ++i) { n     if (deg[i] == 1) isleaf[i] = 1; n   } n   dfs(1, 0); n   dfs2(1, 0); n   cout << ans <<   n ; n   for (int i = 0; i < vec.size(); ++i) cout << vec[i] <<    ; n   cout <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n struct edge { n   int link, next; n } e[100010]; n int n, k, f[50010][510], h[100010], jud[50010], tt = 0; n long long ans[50010], tot; n void addEdge(int x, int y) { n   tt++; n   e[tt].link = y; n   e[tt].next = h[x]; n   h[x] = tt; n } n void dfs(int x) { n   jud[x] = 1; n   f[x][0] = 1; n   for (int i = h[x]; i != 0; i = e[i].next) n     if (jud[e[i].link] == 0) { n       int y = e[i].link; n       dfs(y); n       for (int j = 0; j < k; j++) n         ans[x] = ans[x] + 1LL * f[x][j] * f[y][k - j - 1]; n       for (int j = 0; j < k; j++) f[x][j + 1] += f[y][j]; n     } n   tot += ans[x]; n   return; n } n int main() { n   scanf( %d%d , &n, &k); n   for (int i = 1; i < n; i++) { n     int a, b; n     scanf( %d%d , &a, &b); n     addEdge(a, b); n     addEdge(b, a); n   } n   memset(jud, 0, sizeof(jud)); n   dfs(1); n   cout << tot << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int st[100100][20]; n vector<int> graph[100100], ind[100100]; n int lev[100100]; n int t[100100], l[100100], lg[100100]; n int s[100100]; n void blg(int n) { n   lg[0] = -1; n   for (int i = 0; i < n; ++i) lg[i + 1] = lg[i] + !(i & (i + 1)); n } n void dfs(int u, int p, int l) { n   st[u][0] = p; n   for (int i = 1; (1 << i) <= l; ++i) st[u][i] = st[st[u][i - 1]][i - 1]; n   lev[u] = l; n   for (int v : graph[u]) n     if (v != p) dfs(v, u, l + 1); n } n int getParent(int u, int d) { n   if (lev[u] < d) return -1; n   for (int i = d; i; i -= i & -i) u = st[u][lg[i & -i]]; n   return u; n } n int LCA(int u, int v) { n   if (lev[u] < lev[v]) v = getParent(v, lev[v] - lev[u]); n   if (lev[u] > lev[v]) u = getParent(u, lev[u] - lev[v]); n   int r = lev[u], l = 0, m; n   while (l < r) { n     m = (l + r) / 2; n     if (getParent(u, m) == getParent(v, m)) n       r = m; n     else n       l = m + 1; n   } n   return getParent(u, l); n } n int solve(int u, int p) { n   int y = l[u] - t[u]; n   for (int j = 0; j < graph[u].size(); ++j) { n     int v = graph[u][j]; n     if (v != p) { n       y += s[ind[u][j]] = solve(v, u); n     } n   } n   return y; n } n int main() { n   int n, k, x, y; n   cin >> n; n   blg(n); n   for (int i = 1; i < n; ++i) { n     scanf( %d%d , &x, &y); n     graph[x].push_back(y), graph[y].push_back(x); n     ind[x].push_back(i); n     ind[y].push_back(i); n   } n   dfs(1, 1, 0); n   cin >> k; n   while (k--) { n     scanf( %d%d , &x, &y); n     t[LCA(x, y)] += 2; n     l[x]++, l[y]++; n   } n   solve(1, 0); n   for (int i = 1; i < n; ++i) cout << s[i] <<    ; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 3e5 + 2; n const long long mod = 998244353; n long long fpow(long long a, long long b) { n   if (b == 0) return 1; n   long long cur = fpow(a, b >> 1); n   cur *= cur; n   cur %= mod; n   if (b & 1) cur *= a; n   return cur % mod; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   long long n, m, L, R; n   cin >> n >> m >> L >> R; n   long long dif = R - L + 1; n   long long par = 0, impar = 0; n   if (L & 1) n     impar = dif >> 1ll, par = dif - impar; n   else n     par = dif >> 1ll, impar = dif - par; n   if (n * m & 1) n     cout << fpow(par + impar, n * m) <<   n ; n   else n     cout << ((((fpow(par + impar, n * m) + fpow(par - impar, n * m)) * n                fpow(2, mod - 2)) % n               mod) + n              mod) % n                 mod n          <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n bool tomax(T &x, T y) { n   if (x < y) return x = y, 1; n   return 0; n } n template <class T> n bool tomin(T &x, T y) { n   if (x > y) return x = y, 1; n   return 0; n } n int A[400005], n, K; n int cnt[400005], B[400005], res; n void Add(int x, int v) { n   if (cnt[x] == 0 && v > 0) res++; n   if (cnt[x] == 1 && v < 0) res--; n   cnt[x] += v; n } n bool Check() { n   int p = log2(res); n   if (1.0 * pow(2, p) != 1.0 * res) p++; n   return 1LL * p * n <= 8LL * K; n } n bool check(int x) { n   if (x == n) return 1; n   memset(cnt, 0, sizeof(cnt)); n   x = n - x; n   res = 0; n   for (int i = 1; i <= x; i++) Add(A[i], 1); n   if (Check()) return 1; n   for (int i = x + 1; i <= n; i++) { n     Add(A[i - x], -1), Add(A[i], 1); n     if (Check()) return 1; n   } n   return 0; n } n int main() { n   cin >> n >> K; n   for (int i = 1; i <= n; i++) scanf( %d , &A[i]), B[i] = A[i]; n   sort(B + 1, B + 1 + n); n   int len = unique(B + 1, B + 1 + n) - B - 1; n   for (int i = 1; i <= n; i++) A[i] = lower_bound(B + 1, B + 1 + len, A[i]) - B; n   sort(A + 1, A + 1 + n); n   int L = 0, R = n, ans = 0; n   while (L <= R) { n     int mid = L + R >> 1; n     if (check(mid)) n       ans = mid, R = mid - 1; n     else n       L = mid + 1; n   } n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n const double PI = atan(1) * 4; n const double E = exp(1); n const int oo = 1e9; n const int eps = 1e-9; n using namespace std; n bool vo(char c) { n   return (c ==  a  or c ==  e  or c ==  i  or c ==  o  or c ==  u ); n } n int main() { n   ios::sync_with_stdio(0); n   string s; n   cin >> s; n   bool b = true; n   for (int i = 0; i < ((int)((s).size())) and b; i++) { n     if ((!vo(s[i]) and s[i] !=  n ) and n         (i + 1 >= ((int)((s).size())) or !vo(s[i + 1]))) n       b = false; n   } n   if (b) n     cout <<  YES n ; n   else n     cout <<  NO n ; n } n


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


#include <bits/stdc++.h> n const int mod = 1000000007; n const int gmod = 3; n const int inf = 1039074182; n const double eps = 1e-9; n const long long llinf = 2LL * inf * inf; n template <typename T1, typename T2> n inline void chmin(T1 &x, T2 b) { n   if (b < x) x = b; n } n template <typename T1, typename T2> n inline void chmax(T1 &x, T2 b) { n   if (b > x) x = b; n } n inline void chadd(int &x, int b) { n   x += b - mod; n   x += (x >> 31 & mod); n } n template <typename T1, typename T2> n inline void chadd(T1 &x, T2 b) { n   x += b; n   if (x >= mod) x -= mod; n } n template <typename T1, typename T2> n inline void chmul(T1 &x, T2 b) { n   x = 1LL * x * b % mod; n } n template <typename T1, typename T2> n inline void chmod(T1 &x, T2 b) { n   x %= b, x += b; n   if (x >= b) x -= b; n } n template <typename T> n inline T mabs(T x) { n   return (x < 0 ? -x : x); n } n using namespace std; n using namespace std; n template <typename T> n ostream &operator<<(ostream &cout, vector<T> vec) { n   cout <<  { ; n   for (int i = 0; i < (int)vec.size(); i++) { n     cout << vec[i]; n     if (i != (int)vec.size() - 1) cout <<  , ; n   } n   cout <<  } ; n   return cout; n } n template <typename T1, typename T2> n ostream &operator<<(ostream &cout, pair<T1, T2> p) { n   cout <<  (  << p.first <<  ,  << p.second <<  ) ; n   return cout; n } n template <typename T, typename T2> n ostream &operator<<(ostream &cout, set<T, T2> s) { n   vector<T> t; n   for (auto x : s) t.push_back(x); n   cout << t; n   return cout; n } n template <typename T, typename T2> n ostream &operator<<(ostream &cout, multiset<T, T2> s) { n   vector<T> t; n   for (auto x : s) t.push_back(x); n   cout << t; n   return cout; n } n template <typename T> n ostream &operator<<(ostream &cout, queue<T> q) { n   vector<T> t; n   while (q.size()) { n     t.push_back(q.front()); n     q.pop(); n   } n   cout << t; n   return cout; n } n template <typename T1, typename T2, typename T3> n ostream &operator<<(ostream &cout, map<T1, T2, T3> m) { n   for (auto &x : m) { n     cout <<  Key:   << x.first <<     <<  Value:   << x.second << endl; n   } n   return cout; n } n template <typename T1, typename T2> n void operator+=(pair<T1, T2> &x, const pair<T1, T2> y) { n   x.first += y.first; n   x.second += y.second; n } n template <typename T1, typename T2> n pair<T1, T2> operator+(const pair<T1, T2> &x, const pair<T1, T2> &y) { n   return make_pair(x.first + y.first, x.second + y.second); n } n template <typename T1, typename T2> n pair<T1, T2> operator-(const pair<T1, T2> &x, const pair<T1, T2> &y) { n   return make_pair(x.first - y.first, x.second - y.second); n } n template <typename T1, typename T2> n pair<T1, T2> operator-(pair<T1, T2> x) { n   return make_pair(-x.first, -x.second); n } n template <typename T> n vector<vector<T>> operator~(vector<vector<T>> vec) { n   vector<vector<T>> v; n   int n = vec.size(), m = vec[0].size(); n   v.resize(m); n   for (int i = 0; i < m; i++) { n     v[i].resize(n); n   } n   for (int i = 0; i < m; i++) { n     for (int j = 0; j < n; j++) { n       v[i][j] = vec[j][i]; n     } n   } n   return v; n } n void print0x(int x) { n   std::vector<int> vec; n   while (x) { n     vec.push_back(x & 1); n     x >>= 1; n   } n   std::reverse(vec.begin(), vec.end()); n   for (int i = 0; i < (int)vec.size(); i++) { n     std::cout << vec[i]; n   } n   std::cout <<    ; n } n template <typename T> n void print0x(T x, int len) { n   std::vector<int> vec; n   while (x) { n     vec.push_back(x & 1); n     x >>= 1; n   } n   reverse(vec.begin(), vec.end()); n   for (int i = (int)vec.size(); i < len; i++) { n     putchar( 0 ); n   } n   for (size_t i = 0; i < vec.size(); i++) { n     std::cout << vec[i]; n   } n   std::cout <<    ; n } n vector<string> vec_splitter(string s) { n   s +=  , ; n   vector<string> res; n   while (!s.empty()) { n     res.push_back(s.substr(0, s.find( , ))); n     s = s.substr(s.find( , ) + 1); n   } n   return res; n } n void debug_out(vector<string> __attribute__((unused)) args, n                __attribute__((unused)) int idx, n                __attribute__((unused)) int LINE_NUM) { n   cerr << endl; n } n template <typename Head, typename... Tail> n void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) { n   if (idx > 0) n     cerr <<  ,  ; n   else n     cerr <<  Line(  << LINE_NUM <<  )  ; n   stringstream ss; n   ss << H; n   cerr << args[idx] <<   =   << ss.str(); n   debug_out(args, idx + 1, LINE_NUM, T...); n } n template <int mod> n struct ModInt { n   int x; n   ModInt() { x = 0; } n   ModInt(int _x) { n     x = _x % mod; n     if (x < 0) x += mod; n   } n   ModInt(long long _x) { n     x = _x % mod; n     if (x < 0) x += mod; n   } n   ModInt<mod> &operator++() { n     ++x; n     if (x == mod) x = 0; n     return *this; n   } n   ModInt<mod> operator++(int) { n     int t = x; n     x++; n     if (x == mod) x = 0; n     return t; n   } n   ModInt<mod> &operator--() { n     --x; n     if (x == -1) x += mod; n     return *this; n   } n   ModInt<mod> operator--(int) { n     int t = x; n     x--; n     if (x == -1) x += mod; n     return t; n   } n   ModInt<mod> operator-() const { return ModInt<mod>((x == 0 ? 0 : mod - x)); } n }; n template <int mod> n inline int mabs(const ModInt<mod> &a) { n   return a.x; n } n template <int mod> n bool operator==(const ModInt<mod> &a, const ModInt<mod> &b) { n   return a.x == b.x; n } n template <int mod> n bool operator==(ModInt<mod> a, int x) { n   return (a.x == x); n } n template <int mod> n bool operator!=(const ModInt<mod> &a, const ModInt<mod> &b) { n   return (a.x != b.x); n } n template <int mod> n bool operator!=(ModInt<mod> a, int x) { n   return (a.x != x); n } n template <int mod> n inline ModInt<mod> operator+(ModInt<mod> a, int b) { n   a.x += b; n   if (a.x >= mod) a.x -= mod; n   return a; n } n template <int mod> n inline ModInt<mod> operator+(ModInt<mod> a, ModInt<mod> b) { n   int tmp = a.x + b.x; n   if (tmp >= mod) tmp -= mod; n   return tmp; n } n template <int mod> n inline ModInt<mod> operator-(ModInt<mod> a, ModInt<mod> b) { n   int tmp = a.x - b.x; n   if (tmp < 0) tmp += mod; n   return tmp; n } n template <int mod> n inline ModInt<mod> operator-(ModInt<mod> a, int b) { n   return a - (ModInt<mod>)b; n } n template <int mod> n inline void operator-=(ModInt<mod> &a, ModInt<mod> b) { n   a.x -= b.x; n   a.x += (a.x >> 31 & mod); n } n template <int mod, typename T> n inline void operator-=(ModInt<mod> &a, const T &b) { n   a.x -= b; n   a.x += (a.x >> 31 & mod); n } n template <int mod> n inline ModInt<mod> operator*(const ModInt<mod> &a, const ModInt<mod> &b) { n   return 1LL * a.x * b.x % mod; n } n template <int mod> n inline ModInt<mod> operator*(const ModInt<mod> &a, const int &b) { n   return 1LL * a.x * b % mod; n } n template <int mod> n inline void operator*=(ModInt<mod> &a, const ModInt<mod> &b) { n   a.x = 1LL * a.x * b.x % mod; n } n template <int mod, typename T> n inline void operator*=(ModInt<mod> &a, const T &b) { n   a = a * b; n } n template <int mod> n inline void operator+=(ModInt<mod> &a, const ModInt<mod> &b) { n   a.x += b.x; n   if (a.x >= mod) a.x -= mod; n } n template <int mod, typename T> n void operator+=(ModInt<mod> &a, const T &b) { n   a.x += b; n   if (a.x >= mod) a.x -= mod; n } n template <int mod> n inline ModInt<mod> mod_inv(ModInt<mod> x) { n   int m = mod - 2; n   ModInt<mod> basic = x; n   x = 1; n   while (m) { n     if (m & 1) x *= basic; n     m >>= 1; n     basic *= basic; n   } n   return x; n } n template <int mod> n ModInt<mod> operator/(ModInt<mod> a, ModInt<mod> b) { n   return a * mod_inv(b); n } n template <int mod> n ModInt<mod> operator/(ModInt<mod> a, int b) { n   return a * mod_inv((ModInt<mod>)b); n } n template <int mod> n void operator/=(ModInt<mod> &a, int b) { n   a *= mod_inv(ModInt<mod>(b)); n } n template <int mod> n void operator/=(ModInt<mod> &a, ModInt<mod> b) { n   a = a / b; n } n template <int mod> n inline ModInt<mod> operator^(ModInt<mod> basic, int x) { n   ModInt<mod> res = 1; n   while (x) { n     if (x & 1) res *= basic; n     basic *= basic; n     x >>= 1; n   } n   return res; n } n template <int mod> n istream &operator>>(istream &cin, ModInt<mod> &x) { n   cin >> x.x; n   x.x %= mod; n   if (x.x < 0) x.x += mod; n   return cin; n } n template <int mod> n ostream &operator<<(ostream &cout, ModInt<mod> x) { n   cout << x.x; n   return cout; n } n template <int mod, int g, int LogN> n struct NTT { n   using Int = ModInt<mod>; n   static const int MaxN = (1 << LogN); n   int w[MaxN + 5]; n   int fastpow(int basic, int x) { n     int res = 1; n     while (x) { n       if (x & 1) res = 1LL * res * basic % mod; n       basic = 1LL * basic * basic % mod; n       x >>= 1; n     } n     return res; n   } n   int inv[MaxN + 5]; n   int buf[MaxN + 5]; n   int ww[MaxN + 5]; n   inline void ntt(vector<int> &v, int rev, int lg) { n     int n = (1 << lg); n     memset(buf, 0, sizeof(int) * n); n     v.resize(n, 0); n     for (int i = 0; i < n; i++) { n       inv[i] = (inv[i >> 1] >> 1) | ((i & 1) << (lg - 1)); n     } n     for (int i = 0; i < n; i++) { n       buf[i] = v[inv[i]]; n     } n     int lvl = LogN; n     int *ba, *bb, *wa, *wb; n     int tmp; n     for (int b = 1; b < n; b *= 2) { n       lvl--; n       for (int i = 0; i < b * 2; i++) n         ww[i] = (rev ? w[MaxN - (i << lvl)] : w[i << lvl]); n       for (int i = 0; i < n; i += b * 2) { n         ba = buf + i; n         bb = buf + i + b; n         wa = ww; n         wb = ww + b; n         for (int j = 0; j < b; j++) { n           tmp = 1LL * *wa * *bb % mod; n           *bb = *ba - tmp; n           *ba += tmp; n           *ba -= mod; n           *ba += ((*ba) >> 31 & mod); n           *bb += ((*bb) >> 31 & mod); n           ba++; n           bb++; n           wa++; n           wb++; n         } n       } n     } n     int t = fastpow(n, mod - 2); n     if (rev) { n       for (int i = 0; i < (1 << lg); i++) { n         buf[i] = 1LL * buf[i] * t % mod; n       } n     } n     for (int i = 0; i < (1 << lg); i++) v[i] = buf[i]; n   } n   void multiply(vector<int> a, vector<int> b, vector<int> &c) { n     int n = (int)a.size() + b.size() - 1; n     if (min(a.size(), b.size()) <= 60) { n       c.clear(); n       c.resize(max(0, n), 0); n       for (int i = 0; i < (int)a.size(); i++) { n         for (int j = 0; j < (int)b.size(); j++) { n           c[i + j] = (1LL * a[i] * b[j] + c[i + j]) % mod; n         } n       } n       while (c.size() && c.back() == 0) c.pop_back(); n     } n     int nn = 1, lg = 0; n     while (nn < n) { n       nn <<= 1; n       lg++; n     } n     c.resize(nn); n     a.resize(nn, 0); n     b.resize(nn, 0); n     ntt(a, 0, lg); n     ntt(b, 0, lg); n     for (int i = 0; i < nn; i++) { n       c[i] = 1LL * a[i] * b[i] % mod; n     } n     ntt(c, 1, lg); n     while (c.size() && c.back() == 0) c.pop_back(); n   } n   void sqr(vector<int> &a) { n     int n = (int)a.size() + a.size() - 1; n     int nn = 1, lg = 0; n     while (nn < n) { n       nn <<= 1; n       lg++; n     } n     a.resize(nn, 0); n     ntt(a, 0, lg); n     for (int i = 0; i < nn; i++) { n       a[i] = 1LL * a[i] * a[i] % mod; n     } n     ntt(a, 1, lg); n     while (a.size() && a.back() == 0) a.pop_back(); n   } n   vector<Int> multiply(const vector<Int> &a, const vector<Int> &b) { n     vector<int> ta(a.size()), tb(b.size()); n     for (int i = 0; i < (int)a.size(); i++) ta[i] = a[i].x; n     for (int i = 0; i < (int)b.size(); i++) tb[i] = b[i].x; n     vector<int> tc; n     multiply(ta, tb, tc); n     vector<Int> c(tc.size()); n     for (int i = 0; i < (int)c.size(); i++) c[i].x = tc[i]; n     return c; n   } n   NTT() { n     w[0] = 1; n     int ur = fastpow(g, (mod - 1) >> LogN); n     for (int i = 1; i <= MaxN; i++) { n       w[i] = 1LL * w[i - 1] * ur % mod; n     } n   } n }; n using namespace std; n int n, k; n int fac[30005]; n int ifac[30005]; n inline int fastpow(long long basic, int x) { n   long long res = 1; n   while (x) { n     if (x & 1) (res *= basic) %= mod; n     (basic *= basic) %= mod; n     x >>= 1; n   } n   return res; n } n vector<int> Ex; n vector<int> Ex1; n inline int fastpow(long long basic, int x, int mod) { n   long long res = 1; n   while (x) { n     if (x & 1) (res *= basic) %= mod; n     (basic *= basic) %= mod; n     x >>= 1; n   } n   return res; n } n template <int mod> n struct MTT { n   NTT<998244353, 3, 17> ntt1; n   NTT<469762049, 3, 17> ntt2; n   NTT<1004535809, 3, 17> ntt3; n   static const int p1 = 998244353; n   static const int p2 = 469762049; n   static const int p3 = 1004535809; n   vector<int> c1, c2, c3; n   inline void multiply(vector<int> a, vector<int> b, vector<int> &c) { n     ntt1.multiply(a, b, c1); n     ntt2.multiply(a, b, c2); n     ntt3.multiply(a, b, c3); n     c.clear(); n     int n = max({c1.size(), c2.size(), c3.size()}); n     c1.resize(n, 0); n     c2.resize(n, 0); n     c3.resize(n, 0); n     c.resize(n); n     for (int i = 0; i < n; i++) { n       int x = c1[i]; n       int y = c2[i]; n       int z = c3[i]; n       long long t = n           (1LL * (x - y + p1) * fastpow(p2, p1 - 2, p1) % p1 * p2 + y); n       c[i] = (1LL * ((z - t) % p3 + p3) % p3 * fastpow(p2, p3 - 2, p3) % p3 * n                   fastpow(p1, p3 - 2, p3) % p3 * p1 % mod * p2 % mod + n               t % mod) % n              mod; n     } n   } n }; n MTT<mod> mtt; n inline void multiply(vector<int> a, vector<int> b, vector<int> &c) { n   mtt.multiply(a, b, c); n } n inline vector<int> replacex(vector<int> x, int len) { n   int v = fastpow(2, len); n   for (int i = 0; i < x.size(); i++) { n     x[i] = 1LL * x[i] * fastpow(v, i) % mod; n   } n   return x; n } n vector<int> fastpow(int n) { n   vector<int> res; n   res.push_back(1); n   int len = 0; n   for (int i = 14; i >= 0; i--) { n     if ((1 << i) & n) multiply(replacex(res, 1), Ex1, res), len++; n     if (i) multiply(replacex(res, len), res, res), len <<= 1; n     if (res.size() > k) res.resize(k + 1); n   } n   return res; n } n int main() { n   fac[0] = 1; n   for (int i = 1; i <= 30000; i++) fac[i] = 1LL * fac[i - 1] * i % mod; n   for (int i = 0; i <= 30000; i++) ifac[i] = fastpow(fac[i], mod - 2); n   long long _n; n   cin >> _n >> k; n   if (_n > k) { n     cout << 0 << endl; n     exit(0); n   }; n   n = _n; n   for (int i = 0; i <= k; i++) Ex.push_back(ifac[i]); n   Ex1 = Ex; n   Ex1[0] = 0; n   vector<int> v = fastpow(n); n   multiply(v, Ex, v); n   cout << 1LL * v[k] * fac[k] % mod << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 200010; n const int INF = 1; n const double eps = 1e-10; n int N, M, T = INF, Cases = 0; n int arr[MAXN]; n char a[MAXN], b[MAXN]; n long long zeros[MAXN], ones[MAXN]; n int main() { n   while (T-- && gets(a + 1) && gets(b + 1)) { n     a[0] = b[0] =  ? ; n     N = strlen(a) - 1; n     M = strlen(b) - 1; n     memset(ones, 0, sizeof(ones)); n     memset(zeros, 0, sizeof(zeros)); n     for (int i = 1; i <= M; i++) { n       if (b[i] ==  1 ) n         ones[i] = ones[i - 1] + 1, zeros[i] = zeros[i - 1]; n       else n         ones[i] = ones[i - 1], zeros[i] = zeros[i - 1] + 1; n     } n     int sp = M - N; n     long long ans = 0; n     for (int i = 1; i <= N; i++) { n       int j = i + sp; n       if (a[i] ==  0 ) n         ans += ones[j] - ones[i - 1]; n       else n         ans += zeros[j] - zeros[i - 1]; n     } n     printf( %I64d n , ans); n   } n   return 0; n } n