#include <bits/stdc++.h>   using namespace std;   template <typename T>   ostream& operator<<(ostream& s, vector<T> t) {     for (int i = 0; i < (int)(t.size()); i++) s << (i ?     :   ) << t[i];     return s;   }   template <typename T>   istream& operator>>(istream& s, vector<T>& t) {     for (int i = 0; i < (int)(t.size()); i++) s >> t[i];     return s;   }   template <typename T, typename U>   ostream& operator<<(ostream& s, pair<T, U> t) {     s <<  (  << t.first <<  ,  << t.second <<  ) ;     return s;   }   template <typename T, typename U>   istream& operator>>(istream& s, pair<T, U>& t) {     s >> t.first >> t.second;     return s;   }   typedef pair<double, double> it;   const double EPS = 1e-15;   it intersect(it a, it b) {     if (a.first == -1 || b.first == -1) return {-1, -1};     it res = {max(a.first, b.first), min(a.second, b.second)};     if (res.first + EPS >= res.second) return {-1, -1};     return res;   }   it get1D(double r, double v, double x1, double x2) {     if (v == 0) {       if (r > x1 && r < x2)         return {0, 1e18};       else         return {-1, -1};     }     double t1 = (x1 - r) / v, t2 = (x2 - r) / v;     if (t2 < t1) swap(t1, t2);     if (t2 < 0) return {-1, -1};     if (t1 < 0) t1 = 0;     return {t1, t2};   }   int main() {     ios_base::sync_with_stdio(false);     int n;     cin >> n;     double x1, y1, x2, y2;     cin >> x1 >> y1 >> x2 >> y2;     it res = {0, 1e18};     for (int i = 0; i < (int)(n); i++) {       double rx, ry, vx, vy;       cin >> rx >> ry >> vx >> vy;       it xi = get1D(rx, vx, x1, x2);       it yi = get1D(ry, vy, y1, y2);       it cur = intersect(xi, yi);       res = intersect(res, cur);     }     cout << fixed << setprecision(9);     if (res.first == -1) {       cout <<  -1  << endl;     } else {       cout << res.first << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int off = 1 << 18;   const int MOD = 1e9 + 7;   int q, n = 1;   int st[off << 1] = {}, sp[off], st2[off << 1];   vector<int> g[200001];   int qt[200000], qv[200000], qval[200000], ch[200001] = {};   int tin[200001], tout[200001], timer = -1, par[200001];   void dfs(int v) {     tin[v] = ++timer;     for (int to : g[v]) {       dfs(to);     }     tout[v] = timer;   }   void stBuild() {     for (int i = off - 1; i >= 1; --i) {       st[i] = st[2 * i] + st[2 * i + 1];       sp[i] = 1;     }     for (int i = 0; i < (int)(2 * off); ++i) st2[i] = 1;   }   void stPush(int v) {     for (int i = 2 * v; i <= 2 * v + 1; ++i) {       st[i] = (long long)st[i] * sp[v] % MOD;       if (i < off) {         sp[i] = (long long)sp[i] * sp[v] % MOD;       }     }     sp[v] = 1;   }   int mul;   void stMul(int v, int L, int R, int l, int r) {     if (L == l && R == r) {       st[v] = (long long)st[v] * mul % MOD;       if (L != R) sp[v] = (long long)sp[v] * mul % MOD;       return;     }     int mid = (L + R) >> 1;     if (sp[v] != 1) {       stPush(v);     }     if (l <= mid) stMul(2 * v, L, mid, l, min(r, mid));     if (r > mid) stMul(2 * v + 1, mid + 1, R, max(l, mid + 1), r);     st[v] = st[2 * v] + st[2 * v + 1];     if (st[v] >= MOD) st[v] -= MOD;   }   int pos, val;   void stAssign(int v, int L, int R) {     if (L == R) {       st[v] = val;       return;     }     int mid = (L + R) >> 1;     if (sp[v] != 1) {       stPush(v);     }     if (pos <= mid)       stAssign(2 * v, L, mid);     else       stAssign(2 * v + 1, mid + 1, R);     st[v] = st[2 * v] + st[2 * v + 1];     if (st[v] >= MOD) st[v] -= MOD;   }   int stGet(int v, int L, int R, int l, int r) {     if (l > r) return 0;     if (L == l && R == r) {       return st[v];     }     int mid = (L + R) >> 1;     if (sp[v] != 1) {       stPush(v);     }     int res = stGet(2 * v, L, mid, l, min(r, mid)) +               stGet(2 * v + 1, mid + 1, R, max(l, mid + 1), r);     if (res >= MOD) res -= MOD;     return res;   }   void st2Mul(int v, int L, int R, int l, int r) {     if (L == l && R == r) {       st2[v] = (long long)st2[v] * mul % MOD;       return;     }     int mid = (L + R) >> 1;     if (l <= mid) st2Mul(2 * v, L, mid, l, min(r, mid));     if (r > mid) st2Mul(2 * v + 1, mid + 1, R, max(l, mid + 1), r);   }   int st2Get(int pos) {     int res = 1;     for (pos += off; pos >= 1; pos >>= 1) {       res = (long long)res * st2[pos] % MOD;     }     return res;   }   int binPow(long long x, int p) {     long long res = 1;     while (p) {       if (p & 1) res = res * x % MOD;       p >>= 1;       if (p) x = x * x % MOD;     }     return (int)res;   }   int main() {     scanf( %d%d , st + off, &q);     for (int i = 0; i < (int)(q); ++i) {       scanf( %d%d , qt + i, qv + i), --qv[i];       if (qt[i] == 1) {         scanf( %d , qval + i);         g[qv[i]].push_back(n);         par[n++] = qv[i];       }     }     dfs(0);     stBuild();     n = 1;     for (int i = 0; i < (int)(q); ++i) {       if (qt[i] == 1) {         val = (long long)st2Get(tin[qv[i]]) * qval[i] % MOD;         pos = tin[n++];         stAssign(1, 0, off - 1);         mul = (long long)(ch[qv[i]] + 2) * binPow(ch[qv[i]] + 1, MOD - 2) % MOD;         ++ch[qv[i]];         stMul(1, 0, off - 1, tin[qv[i]], tout[qv[i]]);         st2Mul(1, 0, off - 1, tin[qv[i]], tout[qv[i]]);       } else {         int res = stGet(1, 0, off - 1, tin[qv[i]], tout[qv[i]]);         if (qv[i] != 0) {           res = (long long)res * binPow(st2Get(tin[par[qv[i]]]), MOD - 2) % MOD;         }         printf( %d n , res);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void _print(long long int x) { cerr << x <<    ; }   void _print(float x) { cerr << x <<    ; }   void _print(double x) { cerr << x <<    ; }   void _print(char x) { cerr << x <<    ; }   void _print(string x) { cerr << x <<    ; }   void _print(bool x) { cerr << x <<    ; }   template <class T, class V>   void _print(pair<T, V> x) {     cerr <<  { ;     _print(x.first);     cerr <<  , ;     _print(x.second);     cerr <<  } ;   }   template <class T>   void _print(vector<T> x) {     cerr <<  [  ;     for (T i : x) {       _print(i);       cerr <<    ;     }     cerr <<  ] ;   }   template <class T>   void _print(set<T> x) {     cerr <<  [  ;     for (T i : x) {       _print(i);       cerr <<    ;     }     cerr <<  ] ;   }   template <class T>   void _print(multiset<T> x) {     cerr <<  [  ;     for (T i : x) {       _print(i);       cerr <<    ;     }     cerr <<  ] ;   }   template <class T, class V>   void _print(map<T, V> x) {     cerr <<  [  ;     for (auto i : x) {       _print(i);       cerr <<    ;     }     cerr <<   ] ;   }   void solve() {     string s;     cin >> s;     long long int n = s.size();     if (n % 2 == 1) {       cout <<  NO  << endl;       return;     }     for (long long int i = 0; i <= (n / 2) - 1; i++) {       if (s[i] != s[i + (n / 2)]) {         cout <<  NO  << endl;         return;       }     }     cout <<  YES  << endl;   }   signed main() {     ios_base ::sync_with_stdio(false);     cin.tie(NULL);     clock_t start, end;     start = clock();     long long int t;     cin >> t;     while (t--) {       solve();     }     end = clock();     double time_taken = double(end - start) / double(CLOCKS_PER_SEC);     cerr <<  Time taken by program is :   << fixed << time_taken          << setprecision(5);     cerr <<   sec   << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 5;   char s[maxn];   int vis[maxn];   pair<char, int> sta[maxn];   int main() {     scanf( %s , s);     int o = -1;     for (int i = 0; s[i]; i++) {       if (s[i] ==  0  && o >= 0 && sta[o].first ==  1 ) {         vis[sta[o].second] = 1;         o--;       } else         sta[++o] = make_pair(s[i], i);     }     for (int i = 0; s[i]; i++) printf( %d , vis[i]);   }


#include <bits/stdc++.h>   using namespace std;   vector<long long int> prime;   unordered_set<long long int> stprime;   void sieve(long long int n) {     bool p[n + 1];     memset(p, true, sizeof(p));     for (long long int i = 2; i * i <= n; i++) {       if (p[i]) {         for (int j = i * i; j <= n; j += i) {           p[j] = false;         }       }     }     for (long long int i = 2; i <= n; i++) {       if (p[i]) {         prime.push_back(i);         stprime.insert(i);       }     }   }   void solve() {     long long int m;     cin >> m;     long long int arr[8];     memset(arr, 0, sizeof(arr));     for (int i = 0; i < m; i++) {       long long int a;       cin >> a;       arr[a]++;     }     m /= 3;     if (arr[1] != m || arr[5] | arr[7] || arr[2] < arr[4] || arr[6] < arr[3] ||         arr[2] + arr[3] != arr[4] + arr[6]) {       cout <<  -1  << endl;     } else {       for (int i = 1; i <= arr[4]; i++) cout <<  1 2 4  << endl;       for (int i = 1; i <= arr[2] - arr[4]; i++) cout <<  1 2 6  << endl;       for (int i = 1; i <= arr[3]; i++) cout <<  1 3 6  << endl;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int t;     t = 1;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int frd[2110][2110], rev[2110][2110];   vector<int> v;   int main() {     int a, b, c, d, e, i, j, p, q, mx, mx1, len;     string x, y;     cin >> x >> y;     a = x.length();     b = y.length();     x =  %  + x;     y =  *  + y;     for (i = b; i >= 1; i--) {       for (j = a; j >= 1; j--) {         if (y[i] == x[j]) {           frd[i][j] = frd[i + 1][j + 1] + 1;         }       }       for (j = 1; j <= a; j++) {         if (y[i] == x[j]) {           rev[i][j] = rev[i + 1][j - 1] + 1;         }       }     }     for (i = 1; i <= b;) {       p = -1;       q = -1;       mx = -1;       mx1 = -1;       for (j = 1; j <= a; j++) {         if (frd[i][j] > mx) {           mx = frd[i][j];           p = j;         }       }       for (j = 1; j <= a; j++) {         if (rev[i][j] > mx1) {           mx1 = rev[i][j];           q = j;         }       }       len = max(mx, mx1);       if (len == 0) {         cout <<  -1  << endl;         return 0;       }       if (len == mx) {         v.push_back(p);         v.push_back(p + len - 1);       } else {         v.push_back(q);         v.push_back(q - len + 1);       }       i = i + len;     }     cout << v.size() / 2 << endl;     e = v.size();     for (i = 0; i < e; i = i + 2) {       cout << v[i] <<     << v[i + 1] << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int arr[1000000];   int main() {     int n, x, counter = 0;     cin >> n >> x;     for (int i = 0; i < n; i++) scanf( %d , &arr[i]);     sort(arr, arr + n);     while (arr[((n + 1) / 2 - 1)] != x) {       arr[n++] = x;       sort(arr, arr + n);       counter++;     }     cout << counter;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MX = 305;   vector<int> adj[MX];   vector<int> l, ans;   int dfs(int u, int v, vector<int>& p, int par = 0) {     int sum = 0;     for (int w : adj[u]) {       if (w != par) {         p.push_back(w);         sum = max(sum, dfs(w, v, p, u));         p.pop_back();       }     }     if (u == v) {       for (int i : p) ans.push_back(i);       return p.size();     }     return sum;   }   int main() {     int n, k = 0;     cin >> n;     for (int i = 1; i < n; i++) {       int u, v;       cin >> u >> v;       adj[u].push_back(v);       adj[v].push_back(u);     }     for (int i = 2; i <= n; i++)       if (adj[i].size() == 1) k++;     for (int i = 0; i < k; i++) {       int u;       cin >> u;       l.push_back(u);     }     l.push_back(1);     vector<int> vec[k + 1];     int sum = 0;     int u = 1;     for (int i = 0; i <= k; i++) {       sum += dfs(u, l[i], vec[i], u);       u = l[i];     }     if (sum != 2 * n - 2)       cout <<  -1  <<   n ;     else {       cout <<  1  <<    ;       for (int i : ans) cout << i <<    ;     }   }


#include <bits/stdc++.h>   using namespace std;   using namespace std::chrono;   template <typename A>   ostream &operator<<(ostream &cout, vector<A> const &v);   template <typename A, typename B>   ostream &operator<<(ostream &cout, pair<A, B> const &p) {     return cout <<  (  << p.first <<  ,   << p.second <<  ) ;   }   template <typename A>   ostream &operator<<(ostream &cout, vector<A> const &v) {     cout <<  [ ;     for (int i = 0; i < v.size(); i++) {       if (i) cout <<  ,  ;       cout << v[i];     }     return cout <<  ] ;   }   template <typename A, typename B>   istream &operator>>(istream &cin, pair<A, B> &p) {     cin >> p.first;     return cin >> p.second;   }   mt19937 rng(steady_clock::now().time_since_epoch().count());   void usaco(string filename) {     freopen((filename +  .in ).c_str(),  r , stdin);     freopen((filename +  .out ).c_str(),  w , stdout);   }   const long double pi = 3.14159265358979323846;   const long long mod = 998244353;   long long n, m, k, q, Q, T, l, r, x, y, z;   long long a[1000005];   long long b[1000005];   long long c[1000005];   string second, t;   long long ans = -mod * mod;   vector<pair<long long, long long> > edges[300005];   long long dis[300005];   long long bfirst[300005];   long long blast[300005];   bool has[300005];   vector<long long> res;   void dfs1(int v, int p, long long d) {     dis[v] = d;     for (pair<long long, long long> x : edges[v])       if (x.first != p) dfs1(x.first, v, d + x.second);   }   long long why, why2;   long long why3 = -mod * mod;   bool dfs2(int v, int p, long long d, long long d2) {     if (v == n - 1) {       why = d2;       why2 = p;       return has[v] = 1;     }     bfirst[v] = d;     blast[v] = dis[v];     int targ = -1;     ans = max(ans, d + why3);     for (pair<long long, long long> x : edges[v])       if (x.first != p) {         has[v] |= dfs2(x.first, v, d + x.second, d);         bfirst[v] = max(bfirst[v], bfirst[x.first]);         blast[v] = max(blast[v], blast[x.first]);         if (has[x.first]) {           targ = x.first;           res.push_back(x.second);         }       }     if (has[v]) {       for (pair<long long, long long> x : edges[v])         if (x.first != p && x.first != targ) {           long long va = bfirst[x.first] + blast[targ];           ans = max(ans, va);           ans = max(ans, blast[x.first] + d2);         }     }     return has[v];   }   int cc = 0;   void dfs3(int v, int p, long long d) {     if (v != n - 1) ans = max(ans, why + d);     ++cc;     if (v != n - 1) why3 = max(why3, d);     for (pair<long long, long long> x : edges[v])       if (x.first != p) dfs3(x.first, v, d + x.second);   }   bool first = 0;   void dfs4(int v, int p) {     for (pair<long long, long long> x : edges[v])       if (x.first != p) {         if (p != -1 && !has[v]) first = 1;         dfs4(x.first, v);       }   }   int main() {     {       ios_base::sync_with_stdio(false);       cin.tie(NULL);       cout.tie(NULL);     };     cin >> n >> m;     for (long long i = 0; i < (n - 1); i++) {       cin >> x >> y >> z;       --x;       --y;       edges[x].push_back(make_pair(y, z));       edges[y].push_back(make_pair(x, z));     }     dfs1(n - 1, -1, 0);     memset(bfirst, 0, sizeof(bfirst));     memset(blast, 0, sizeof(blast));     dfs2(0, -1, 0, -mod * mod);     for (long long i = 0; i < (res.size() - 1); i++)       ans = max(ans, dis[0] - res[i] - res[i + 1]);     dfs3(n - 1, why2, 0);     dfs2(0, -1, 0, -mod * mod);     if (cc > 2) first = 1;     dfs4(0, -1);     for (long long i = 0; i < (m); i++) {       cin >> x;       cout << (first ? dis[0] : min(ans + x, dis[0])) <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   bool debug = 0;   int n, m, k;   int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};   long long ln, lk, lm;   const int MN = 10000;   int mod;   char s[505][505];   pair<int, int> id[2][MN], rid[505][505];   int sz[2];   vector<int> mp[MN], mpc[MN];   long long A[505][505];   int col[MN], C, cnt;   long long ans;   void pp(int N) {     for (int(i) = 1; (i) <= (int)(N); (i)++) {       for (int(j) = 1; (j) <= (int)(N); (j)++) printf( %lld  , A[i][j]);       puts(  );     }     puts(  );   }   long long fastPow(long long x, long long y) {     long long ans = 1;     while (y > 0) {       if (y & 1) ans = (x * ans) % mod;       x = x * x % mod;       y >>= 1;     }     return ans;   }   long long gauss(int N) {     long long tmp = 1;     for (int(i) = 1; (i) <= (int)(N); (i)++)       for (int(j) = 1; (j) <= (int)(N); (j)++)         A[i][j] = (A[i][j] % mod + mod) % mod;     for (int i = 2; i <= N; i++) {       int j = i;       while (j <= N && A[j][i] == 0) j++;       if (j > N) {         return 0;       }       if (i != j) {         for (int(k) = 1; (k) <= (int)(N); (k)++) swap(A[i][k], A[j][k]);         tmp = mod - tmp;       }       for (int j = i + 1; j <= N; j++) {         long long base = A[j][i] * fastPow(A[i][i], mod - 2) % mod;         for (int k = i; k <= N; k++) {           A[j][k] = A[j][k] - A[i][k] * base % mod;           A[j][k] = (A[j][k] % mod + mod) % mod;         }       }       tmp *= A[i][i];       tmp %= mod;     }     return tmp;   }   void dfs(int x, int pa) {     col[x] = C;     for (int c : mp[x])       if (c != pa) {         if (col[c] == 0)           dfs(c, x);         else {           puts( 0 );           exit(0);         }       }   }   bool vis[MN];   void dfs1(int x) {     vis[x] = 1;     cnt++;     for (int c : mpc[x])       if (vis[c] == 0) dfs1(c);   }   void cal(int t) {     for (int(i) = 0; (i) < (int)(MN); (i)++) mp[i].clear();     for (int(i) = 0; (i) < (int)(MN); (i)++) mpc[i].clear();     for (int(i) = 0; (i) < (int)(n); (i)++)       for (int(j) = 0; (j) < (int)(m); (j)++) {         int u, v;         if (s[i][j] ==  /  && rid[i][j + 1].first == t) {           u = rid[i][j + 1].second;           v = rid[i + 1][j].second;           mp[u].push_back(v);           mp[v].push_back(u);         } else if (s[i][j] ==      && rid[i][j].first == t) {           u = rid[i][j].second;           v = rid[i + 1][j + 1].second;           mp[u].push_back(v);           mp[v].push_back(u);         }       }     C = 0;     memset(col, 0, sizeof col);     for (int(i) = 0; (i) < (int)(sz[t]); (i)++)       if (col[i] == 0) {         C++;         dfs(i, -1);       }     for (int(i) = 0; (i) < (int)(505); (i)++)       for (int(j) = 0; (j) < (int)(505); (j)++) A[i][j] = 0;     for (int(i) = 0; (i) < (int)(n); (i)++)       for (int(j) = 0; (j) < (int)(m); (j)++)         if (s[i][j] ==  * ) {           int u, v;           if (rid[i][j + 1].first == t) {             u = rid[i][j + 1].second;             v = rid[i + 1][j].second;           } else {             assert(rid[i][j].first == t);             u = rid[i][j].second;             v = rid[i + 1][j + 1].second;           }           u = col[u];           v = col[v];           if (u == v) continue;           A[u][u]++;           A[v][v]++;           A[u][v]--;           A[v][u]--;           mpc[u].push_back(v);           mpc[v].push_back(u);         }     cnt = 0;     for (int(i) = 0; (i) < (int)(MN); (i)++) vis[i] = 0;     dfs1(1);     if (cnt == C) {       ans += gauss(C);     }     ans += mod;     ans %= mod;   }   void fmain() {     scanf( %d%d%d , &n, &m, &mod);     for (int(i) = 0; (i) < (int)(n); (i)++) scanf( %s , s[i]);     for (int(i) = 0; (i) < (int)(n + 1); (i)++) {       int t = i % 2;       for (int(j) = 0; (j) < (int)(m + 1); (j)++) {         id[t][sz[t]++] = make_pair(i, j);         rid[i][j] = {t, sz[t] - 1};         t ^= 1;       }     }     for (int(i) = 0; (i) < (int)(2); (i)++) cal(i);     printf( %lld n , ans);   }   int main() {     fmain();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a, b, x, y;   int main() {     cin >> a >> b;     if (a > b) {       x = b;       y = (a - b) / 2;     } else {       x = a;       y = (b - a) / 2;     }     cout << x <<     << y;   }


#include <bits/stdc++.h>   using namespace std;   int t[110], w[110];   int main() {     int n, cnt = 0;     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %d%d , &t[i], &w[i]);     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         if (i != j) {           if (t[i] == w[j]) {             cnt++;             break;           }         }       }     }     printf( %d , n - cnt);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   void rd(T& ret) {     ret = 0;     bool ok = 0, u = 0;     for (;;) {       int c = getchar();       if (c >=  0  && c <=  9 )         ret = (ret << 3) + (ret << 1) + c -  0 , ok = 1;       else if (c ==  - )         u = 1;       else if (ok) {         if (u) ret *= -1;         return;       }     }   }   long long powmod(long long p, long long n, long long mod) {     long long ret = 1;     for (; n; n >>= 1) {       if (n & 1) ret = ret * p % mod;       p = p * p % mod;     }     return ret;   }   template <class T>   bool chmin(T& a, const T& b) {     return b < a ? a = b, 1 : 0;   }   template <class T>   bool chmax(T& a, const T& b) {     return b > a ? a = b, 1 : 0;   }   int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }   const long long mod = (long long)1e9 + 7;   const int N = 1 << 21;   pair<pair<int, int>, int> qn[N];   int stk[N], top, an[N], ans[N];   bool has[N];   int main() {     int n, q;     scanf( %d%d , &n, &q);     for (int i = (0); i < (n); i++) scanf( %d , an + i);     for (int i = (0); i < (q); i++) {       int l, first;       scanf( %d%d , &l, &first);       --l;       qn[i].first = pair<int, int>(l, first);       qn[i].second = i;     }     sort(qn, qn + q);     has[0] = 1;     stk[top++] = 0;     long long t = 1, it = 0;     for (int i = (0); i < (n); i++) {       if (has[an[i]])         t = (t << 1) % mod;       else {         int tn = top, second;         for (int j = (0); j < (tn); j++) {           second = an[i] ^ stk[j];           stk[top++] = second;           has[second] = 1;         }         has[an[i]] = 1;         stk[top++] = an[i];       }       while (it < q && qn[it].first.first == i) {         int val = qn[it].first.second;         ans[qn[it].second] = has[val] ? t : 0;         ++it;       }     }     for (int i = (0); i < (q); i++) printf( %d n , ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1000000007;   const long long MAX = 100005;   const long double PI = 3.14159265359;   const long double G = 9.807;   const long long INF = 1e18;   const long double EPS = 1e-6;   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   bool isprime(long long a) {     if (a == 2) return 1;     if (!(a & 1)) return 0;     for (long long i = 3; i * i <= a; i += 2)       if (a % i == 0) return 0;     return 1;   }   long long mpow(long long base, long long exponent, long long modulus) {     if (modulus == 1) return 0;     long long result = 1;     base = base % modulus;     while (exponent) {       if (exponent % 2 == 1) result = (result * base) % modulus;       exponent = exponent >> 1;       base = (base * base) % modulus;     }     return result;   }   long long minv(long long a, long long mod) {     long long _gcd = gcd(a, mod);     assert(_gcd == 1);     return mpow(a, mod - 2, mod);   }   long long n;   long long ans;   long long a[1005];   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     cin >> n;     for (int i = 1; i <= n; ++i) {       cin >> a[i];     }     for (int i = 2; i < n; ++i) {       if (a[i - 1] > a[i] and a[i] < a[i + 1])         ans++;       else if (a[i - 1] < a[i] and a[i] > a[i + 1])         ans++;     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC optimize( unroll-loops )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   using namespace std;   const int maxn = 3e5 + 10, lg = 20;   vector<pair<long long, long long> > v[maxn];   long long n, w[maxn], rmq[lg + 2][maxn], dp[maxn], up[maxn], W[maxn],       par[lg + 2][maxn], h[maxn], q;   void dfs_down(int i, int j) {     h[i] = h[j] + 1;     dp[i] = w[i];     for (int y = 0; y < v[i].size(); y++) {       int x = v[i][y].first;       if (x - j) {         W[x] = v[i][y].second;         dfs_down(x, i);         dp[i] += max(0LL, dp[x] - 2 * W[x]);       }     }   }   long long get_dp(int pes) {     long long s = 0;     if (dp[pes] - 2 * W[pes] >= 0 && pes != 1) s = -(dp[pes] - 2 * W[pes]);     return s;   }   void dfs_up(int i, int j) {     if (i != 1) {       up[i] = max(0LL, up[j] + dp[j] + get_dp(i) - 2 * W[i]);     }     for (int y = 0; y < v[i].size(); y++) {       int x = v[i][y].first;       if (x - j) {         dfs_up(x, i);       }     }   }   void get_par(int i, int j) {     par[0][i] = j;     rmq[0][i] = -W[i] + dp[j] + get_dp(i);     for (int y = 1; y <= lg; y++) {       int p = par[y - 1][i];       par[y][i] = par[y - 1][p];       rmq[y][i] = rmq[y - 1][i] + rmq[y - 1][p];     }     for (int y = 0; y < v[i].size(); y++) {       int x = v[i][y].first;       if (x - j) {         get_par(x, i);       }     }   }   long long query(int i, int j) {     if (i == j) return up[i] + dp[i];     if (h[i] > h[j]) swap(i, j);     int o = h[j] - h[i];     int I = i;     int J = j;     long long Ans = 0;     for (int y = 0; y <= lg; y++) {       if (o & (1 << y)) {         Ans += rmq[y][j];         j = par[y][j];       }     }     if (j == i) return Ans + dp[J] + up[i];     Ans += dp[I] + dp[J];     for (int y = lg; y > -1; y--) {       if (par[y][i] != par[y][j])         Ans += rmq[y][j] + rmq[y][i], i = par[y][i], j = par[y][j];     }     int p = par[0][j];     Ans += up[p] + rmq[0][i] + rmq[0][j] + get_dp(i) + get_dp(j) -            (dp[p] + get_dp(i) + get_dp(j));     return Ans;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> q;     for (int y = 1; y <= n; y++) cin >> w[y];     for (int y = 1; y < n; y++) {       int i, j, p;       cin >> i >> j >> p;       v[i].push_back(pair<long long, long long>(j, p));       v[j].push_back(pair<long long, long long>(i, p));     }     dfs_down(1, 0);     dfs_up(1, 0);     get_par(1, 0);     while (q--) {       int i, j;       cin >> i >> j;       cout << query(i, j) << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   #pragma comment(linker,  /STACK:100000000 )   int mod = 1000000007;   int mas[1010];   int pow2(int b) {     if (b == -1) return 0;     int res = 1;     for (int i = 1; i <= b; i++) {       res <<= 1;       res %= mod;     }     return res;   }   int GCD(int a, int b) {     if (b == 0)       return a;     else       return GCD(b, a % b);   }   vector<int> v;   vector<int> C;   int main() {     int n, m;     scanf( %d %d , &n, &m);     for (int i = 0; i < m; i++) scanf( %d , &mas[i]);     sort(mas, mas + m);     if (mas[0] != 1) v.push_back(mas[0] - 1);     if ((n > 1 || m != 1) && mas[m - 1] != n) v.push_back(n - mas[m - 1]);     for (int i = 1; i < m; i++) {       int a = pow2(mas[i] - mas[i - 1] - 2);       if (mas[i] - 1 != mas[i - 1]) v.push_back(mas[i] - mas[i - 1] - 1);       a = max(a, 1);       C.push_back(a);     }     sort(v.begin(), v.end());     int S = 0;     vector<int> F;     for (int i = 0, maxi = (int)(v).size(); i < maxi; i++) S += v[i];     for (int i = 2; i <= S; i++) F.push_back(i);     vector<int> VVV;     for (int i = 0, maxi = (int)(v).size(); i < maxi; i++)       for (int j = 2; j <= v[i]; j++) VVV.push_back(j);     for (int i = 0, maxi = (int)(VVV).size(); i < maxi; i++) {       for (int j = 0, maxj = (int)(F).size(); j < maxj; j++) {         if (VVV[i] == 1) break;         int G = GCD(F[j], VVV[i]);         VVV[i] /= G;         F[j] /= G;       }     }     long long ans = 1;     for (int i = 0, maxi = (int)(F).size(); i < maxi; i++)       ans *= (long long)F[i], ans %= (long long)mod;     for (int i = 0, maxi = (int)(C).size(); i < maxi; i++)       ans *= (long long)C[i], ans %= (long long)mod;     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     int a[1000]{};     for (int i = 0; i < t; i++) {       int n, s, k;       cin >> n >> s >> k;       set<int> b;       for (int j = 0; j < k; j++) {         cin >> a[j];         b.insert(a[j]);       }       int ans = n;       for (int i = max(1, s - k); i <= min(n, s + k + 1); i++) {         if (b.count(i) == 0) {           ans = min(ans, abs(s - i));         }       }       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   using namespace std;   const double PI = acos(-1.0);   const long long MOD = 1000000007LL;   template <class T>   inline bool chmax(T &a, T b) {     if (a < b) {       a = b;       return true;     }     return false;   }   template <class T>   inline bool chmin(T &a, T b) {     if (a > b) {       a = b;       return true;     }     return false;   }   int dp[500][500];   void solve() {     string S, T;     cin >> S >> T;     int N = S.size();     int M = T.size();     for (int i = 0; i < (int)(M); ++i) {       for (int j = 0; j < (int)(N + 1); ++j)         for (int k = 0; k < (int)(M + 1); ++k) dp[j][k] = -1;       for (int j = 0; j < (int)(N + 1); ++j) dp[j][0] = 0;       for (int j = 0; j < (int)(N); ++j) {         for (int k = 0; k < (int)(i + 1); ++k) {           chmax(dp[j + 1][k], dp[j][k]);           if (k < i && S[j] == T[k]) {             chmax(dp[j + 1][k + 1], dp[j][k]);           }           if (dp[j][k] >= 0 && dp[j][k] < M - i && S[j] == T[i + dp[j][k]]) {             chmax(dp[j + 1][k], dp[j][k] + 1);           }         }       }       if (dp[N][i] == M - i) {         cout <<  YES  <<   n ;         return;       }     }     cout <<  NO  <<   n ;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     int Q;     cin >> Q;     while (Q--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   int t, n;   int hmz, hmbz, bsz = -100000, sum;   int main() {     cin >> t;     for (; t; t--) {       cin >> n;       hmz = 0;       hmbz = 0;       bsz = -100000;       sum = 0;       for (int i = 1; i <= n; i++) {         int x;         cin >> x;         if (x == 0)           hmz++;         else if (x < 0)           bsz = max(bsz, x);         else           hmbz++;         sum += x;       }       int sol = 0;       if (hmz) sum += hmz, sol += hmz;       if (sum == 0) {         if (hmbz)           sol++;         else           sol += (1 - hmbz);       }       cout << sol <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e3 + 5;   int times[maxn][maxn], Time, cost[maxn][maxn], n, m;   string k[maxn];   int dfs(int x, int y) {     if (!min(x, y) or x > n or y > m) return 0;     times[x][y] = ++Time;     int now = k[x][y - 1];     int nextx, nexty;     if (now ==  R )       nextx = x, nexty = y + 1;     else if (now ==  L )       nextx = x, nexty = y - 1;     else if (now ==  U )       nextx = x - 1, nexty = y;     else       nextx = x + 1, nexty = y;     if (times[nextx][nexty]) {       cost[x][y] = Time - times[nextx][nexty] + 1;       times[x][y] = 0;       return cost[x][y] - 1;     }     if (cost[nextx][nexty]) {       cost[x][y] = cost[nextx][nexty] + 1;       times[x][y] = 0;       return 0;     }     int gg = dfs(nextx, nexty);     if (!gg) {       cost[x][y] = cost[nextx][nexty] + 1;       times[x][y] = 0;       return 0;     } else {       cost[x][y] = cost[nextx][nexty];       times[x][y] = 0;       return gg - 1;     }   }   void solve() {     cin >> n >> m;     for (int i = 1; i <= n; i++) cin >> k[i];     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         Time = 0;         if (!cost[i][j]) dfs(i, j);       }     }     int ans = 0, ansx, ansy;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++)         if (cost[i][j] > ans) ans = cost[i][j], ansx = i, ansy = j;     cout << ansx <<     << ansy <<     << ans <<   n ;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) cost[i][j] = times[i][j] = 0;   }   int main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     int t;     cin >> t;     for (int i = 1; i <= t; i++) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> graf[1000001];   vector<int> chains[1000001];   vector<int> chainsbit[1000001];   int chainwhere[1000001], chainposition[1000001];   void update(int chainidx, int x, int val) {     while (x <= chainsbit[chainidx].size() - 1) {       chainsbit[chainidx][x] += val;       x += (x & -x);     }   }   int read(int chainidx, int x) {     if (chainsbit[chainidx].size() < x)       x = min(x, (int)(chainsbit[chainidx].size()) - 1);     int ret = 0;     while (x > 0) {       ret += chainsbit[chainidx][x];       x -= (x & -x);     }     return ret;   }   void DFS(int u, int chainidx, int prev) {     chains[chainidx].push_back(u);     chainsbit[u].push_back(0);     chainwhere[u] = chainidx;     chainposition[u] = chains[chainidx].size() - 1;     for (int i = 0; i < graf[u].size(); i++)       if (graf[u][i] != prev) DFS(graf[u][i], chainidx, u);   }   int rootvalue = 0;   int main() {     int n, q;     scanf( %d%d , &n, &q);     for (int i = 0; i < n - 1; i++) {       int u, v;       scanf( %d%d , &u, &v);       graf[u].push_back(v);       graf[v].push_back(u);     }     int chainnum = graf[1].size();     for (int i = 0; i < n + 15; i++) chainsbit[0].push_back(0);     for (int i = 0; i < graf[1].size(); i++) {       chains[i + 1].push_back(0);       chainsbit[i + 1].push_back(0);       DFS(graf[1][i], i + 1, 1);       int ln = chains[i + 1].size() * 100;       for (int j = 0; j < ln; j++) {         chains[i + 1].push_back(0);         chainsbit[i + 1].push_back(0);       }     }     while (q--) {       int t;       scanf( %d , &t);       if (t == 0) {         int v, x, d;         scanf( %d%d%d , &v, &x, &d);         if (v == 1) {           rootvalue += x;           update(0, 1, +x);           update(0, d + 1, -x);         } else {           int ch = chainwhere[v];           int depth = chainposition[v];           if (depth - d >= 1) {             update(ch, depth - d, +x);             update(ch, depth + d + 1, -x);           } else {             update(ch, 1, +x);             update(ch, depth + d + 1, -x);             int rest = d - depth;             rootvalue += x;             if (rest > 0) {               update(0, 1, +x);               update(0, rest + 1, -x);               update(ch, 1, -x);               update(ch, rest + 1, +x);             }           }         }       } else {         int v;         scanf( %d , &v);         if (v == 1)           printf( %d n , rootvalue);         else {           int ret =               read(0, chainposition[v]) + read(chainwhere[v], chainposition[v]);           printf( %d n , ret);         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n, k;       cin >> n >> k;       vector<int> v(n);       for (int i = 0; i < n; i++) cin >> v[i];       vector<int> f(n, 0);       unordered_map<int, vector<int>> mp;       for (int i = 0; i < n; i++) mp[v[i]].push_back(i);       auto it = mp.begin();       int fg = 0;       bool flg = 0;       int ts = 0;       for (it; it != mp.end(); it++) {         auto vv = it->second;         if (vv.size() < k) continue;         ts += vv.size();         if (vv.size() >= k) {           int tt = 0;           while (tt < k) {             f[vv[tt]] = tt + 1;             tt++;           }         }       }       it = mp.begin();       for (it; it != mp.end(); it++) {         auto vv = it->second;         if (vv.size() >= k)           continue;         else {           int ii = 0;           while (ii < vv.size()) {             if (fg == 0 && (n - ts < k)) {               flg = 1;               break;             }             ts++;             f[vv[ii]] = fg + 1;             fg = (fg + 1) % k;             ii++;           }           if (flg) break;         }       }       for (int i = 0; i < n; i++) cout << f[i] <<    ;       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   T gcd(T a, T b) {     return (b != 0 ? gcd<T>(b, a % b) : a);   }   template <class T>   T lcm(T a, T b) {     return (a / gcd<T>(a, b) * b);   }   template <class T>   inline bool read(T &x) {     int c = getchar();     int sgn = 1;     while (~c && c <  0  || c >  9 ) {       if (c ==  - ) sgn = -1;       c = getchar();     }     for (x = 0; ~c &&  0  <= c && c <=  9 ; c = getchar()) x = x * 10 + c -  0 ;     x *= sgn;     return ~c;   }   const int INF = 2000000009;   const int MX = 100005;   const long double EPS = 1e-9;   const int MOD = 1000000007;   struct PT {     long double x, y;     PT() {}     PT(long double x, long double y) : x(x), y(y) {}     PT operator+(const PT &p) const { return PT(x + p.x, y + p.y); }     PT operator-(const PT &p) const { return PT(x - p.x, y - p.y); }     PT operator*(long double c) const { return PT(x * c, y * c); }     PT operator/(long double c) const { return PT(x / c, y / c); }   };   long double cross(PT a, PT b) { return a.x * b.y - a.y * b.x; }   long double dot(PT a, PT b) { return a.x * b.x + a.y * b.y; }   long double area2(PT a, PT b, PT c) {     return cross(a, b) + cross(b, c) + cross(c, a);   }   long double dist2(PT a, PT b) { return dot(b - a, b - a); }   inline int sign(long double a) {     int ret = (a < -EPS) ? -1 : ((a > EPS) ? 1 : 0);     return ret;   }   struct Line {     PT v;     long double a, b, c;     Line() {}     Line(PT p, PT q) : v(q - p), a(-v.y), b(v.x), c(cross(v, p)) {}     long double side(PT p) { return cross(v, p) - c; }   };   long double commonLength(vector<PT> &p, PT a, PT b) {     Line l = Line(a, b);     long double ans = 0.0;     int n = p.size();     p.push_back(p[0]);     vector<pair<long double, int> > vec;     for (int i = 0; i < n; i++) {       int s1 = sign(cross(b - a, p[i] - a));       int s2 = sign(cross(b - a, p[i + 1] - a));       if (s1 == s2) continue;       Line t = Line(p[i], p[i + 1]);       PT inter = (t.v * l.c - l.v * t.c) / cross(l.v, t.v);       long double tmp = dot(inter, l.v);       int f;       if (s1 > s2)         f = s1 && s2 ? 2 : 1;       else         f = s1 && s2 ? -2 : -1;       vec.push_back(make_pair(tmp, f));     }     sort(vec.begin(), vec.end());     for (int i = 0, j = 0; i + 1 < (int)vec.size(); i++) {       j += vec[i].second;       if (j) ans += vec[i + 1].first - vec[i].first;     }     ans = ans / sqrt(dot(l.v, l.v));     p.pop_back();     return ans;   }   int main() {     int n = ({       int a;       read(a);       a;     }),         m = ({           int a;           read(a);           a;         });     vector<PT> pol;     for (int i = 0; i < n; i++) {       long double x = ({         long double a;         scanf( %Lf , &a);         a;       }),                   y = ({                     long double a;                     scanf( %Lf , &a);                     a;                   });       pol.push_back(PT(x, y));     }     while (m--) {       PT a, b;       a.x = ({         long double a;         scanf( %Lf , &a);         a;       }),       a.y = ({         long double a;         scanf( %Lf , &a);         a;       }),       b.x = ({         long double a;         scanf( %Lf , &a);         a;       }),       b.y = ({         long double a;         scanf( %Lf , &a);         a;       });       printf( %.8Lf n , commonLength(pol, a, b));     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   const int N = 1e2 + 5, M = 1e5 + 5;   int lim = (1 << 10) - 1;   bool vis[M];   vector<int> primes;   int idx[M];   void pre() {     for (int i = 2; primes.size() < 110; ++i) {       if (vis[i]) continue;       primes.emplace_back(i);       for (int j = i; j < M; j += i) vis[j] = true;     }     for (int i = 0; i < 110; ++i) idx[primes[i]] = i;   }   vector<int> tmp;   void fac(int x) {     tmp.clear();     for (int i = 2; i * i <= x; ++i) {       if (x % i) continue;       tmp.emplace_back(idx[i]);       while (x % i == 0) x /= i;     }     if (x > 1) tmp.emplace_back(idx[x]);   }   int n, a[N];   int dp[N][1 << 10][N + 10];   int solve(int i, int msk, int j) {     if (i == n) return 0;     if (msk == lim && j == 110) return (int)1e7;     int &ret = dp[i][msk][j];     if (~ret) return ret;     ret = (int)1e7;     if (j < 110 && a[i] > primes[j])       cout <<  yala n2fl ya 3mna kda mb2tsh nf3a  << endl;     if (j < 110) ret = min(ret, solve(i + 1, msk, j + 1) - a[i] + primes[j]);     for (int f = 0; f < 10; ++f) {       if ((msk & (1 << f))) continue;       int nw = primes[f];       for (int k = 0; k <= 15 && (int)1e7 / nw >= primes[f]; ++k, nw *= primes[f])         ret = min(ret, solve(i + 1, (msk | (1 << f)), j) + abs(a[i] - nw));     }     for (int hna = 1; hna <= 30; ++hna) {       bool baz = false;       int nmsk = msk;       fac(hna);       for (auto f : tmp) {         nmsk |= (1 << f);         baz |= ((msk & (1 << f)) > 0);       }       if (baz) continue;       ret = min(ret, solve(i + 1, nmsk, j) + abs(a[i] - hna));     }     return ret;   }   vector<int> out;   void build(int i, int msk, int j) {     if (i == n) {       for (auto x : out) printf( %d%c , x,    n [&x == &out.back()]);       exit(0);     }     if (msk == lim && j == 110) return;     int m3lsh = solve(i, msk, j);     if (j < 110 && m3lsh == solve(i + 1, msk, j + 1) - a[i] + primes[j]) {       out.emplace_back(primes[j]);       build(i + 1, msk, j + 1);       return;     }     for (int f = 0; f < 10; ++f) {       if ((msk & (1 << f))) continue;       int nw = primes[f];       for (int k = 0; k <= 15 && (int)1e7 / nw >= primes[f];            ++k, nw *= primes[f]) {         if (m3lsh == solve(i + 1, (msk | (1 << f)), j) + abs(a[i] - nw)) {           out.emplace_back(nw);           build(i + 1, (msk | (1 << f)), j);           return;         }       }     }     for (int hna = 1; hna <= 30; ++hna) {       bool baz = false;       int nmsk = msk;       fac(hna);       for (auto f : tmp) {         nmsk |= (1 << f);         baz |= (msk & (1 << f));       }       if (baz) continue;       if (m3lsh == solve(i + 1, nmsk, j) + abs(a[i] - hna)) {         out.emplace_back(hna);         build(i + 1, nmsk, j);         return;       }     }   }   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     ;     pre();     scanf( %d , &n);     for (int i = 0; i < n; ++i) scanf( %d , a + i);     memset(dp, -1, sizeof dp);     solve(0, 0, 10);     build(0, 0, 10);   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     long long a, b;     cin >> a >> b;     if (a == 0 || b == 0) {       cout << 0 << endl;       return;     }     cout << min((a + b) / 3, min(a, b)) << endl;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int tc = 1;     cin >> tc;     while (tc--) solve();   }


#include <bits/stdc++.h>   using namespace std;   bool isvowel(char c) {     c = tolower(c);     return (c ==  a  || c ==  e  || c ==  i  || c ==  o  || c ==  u );   }   long long gcd(long long a, long long b) {     if (b == 0) return a;     return gcd(b, a % b);   }   long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); }   long long fastpow(long long base, long long p) {     if (p == 0) return 1;     long long num = fastpow(base, p / 2);     num *= num;     if (p % 2) num *= base;     return num;   }   int main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     int n, m, x, q, ans = 0;     cin >> n >> m >> x;     string KeyBoard[n + 5], t;     map<char, bool> check;     vector<pair<int, int>> S;     for (int i = 1; i <= n; i++) {       cin >> KeyBoard[i];       for (int j = 0; j < m; j++) {         if (KeyBoard[i][j] ==  S ) S.push_back(make_pair(i, j + 1));       }     }     for (int i = 1; i <= n; i++) {       for (int j = 0; j < m; j++) {         if (KeyBoard[i][j] ==  S ) continue;         check[KeyBoard[i][j]] = true;         for (int k = 0; k < (int)S.size(); k++) {           if (sqrt(pow(i - S[k].first, 2) + pow(j - S[k].second + 1, 2)) <= x) {             check[toupper(KeyBoard[i][j])] = true;             break;           }         }       }     }     cin >> q >> t;     for (int i = 0; i < (int)t.size(); i++) {       if (!check[t[i]]) {         if (islower(t[i]) || !check[tolower(t[i])] || !S.size()) {           cout << -1;           return 0;         }         ans++;       }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, a, b;     while (cin >> n >> m >> a >> b) {       a--;       b--;       int oa, pa, ob, pb;       oa = a / m;       pa = a % m;       ob = b / m;       pb = b % m;       if (b == n - 1) {         pb = m - 1;       }       if (oa == ob) {         cout <<  1 ;         continue;       }       if (pa == 0 && pb == m - 1) {         cout <<  1 ;         continue;       }       if (pa - pb == 1) {         cout <<  2 ;         continue;       }       int hang = ob - oa;       if (pa > 0 && pb < m - 1) {         if (hang == 1) {           cout <<  2 ;           continue;         } else {           cout <<  3 ;           continue;         }       }       cout <<  2 ;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n, m, k;     cin >> n >> m >> k;     int arr[n][m];     int row[n];     int col[m];     for (int i = 0; i < n; i++) {       row[i] = i;       for (int j = 0; j < m; j++) {         col[j] = j;         cin >> arr[i][j];       }     }     while (k--) {       char c;       int x, y;       cin >> c >> x >> y;       if (c ==  c ) {         x -= 1;         y -= 1;         swap(col[x], col[y]);       } else if (c ==  r ) {         x -= 1;         y -= 1;         swap(row[x], row[y]);       } else {         x = row[x - 1];         y = col[y - 1];         cout << arr[x][y] <<   n ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1000000007;   const long long SIZE = 100000;   const int INF = 0x3f3f3f3f;   const long long LL_INF = 0x3f3f3f3f3f3f3f3f;   const long double PI = acos(-1);   const long long MAXN = numeric_limits<long long>::max();   template <class T>   T maxT(T a, T b) {     return (a > b ? a : b);   }   template <class T>   T minT(T a, T b) {     return (a < b ? a : b);   }   template <class T>   void setmin(T &a, T b) {     a = (a > b ? a : b);   }   template <class T>   void setmax(T &a, T b) {     a = (a < b ? a : b);   }   void fileio() {     freopen( input.txt ,  r , stdin);     freopen( output.txt ,  w , stdout);     freopen( debug.txt ,  w , stderr);   }   void ofileio() {     freopen( input.txt ,  r , stdin);     freopen( output.txt ,  w , stdout);   }   void clock_out() {     cerr <<   nTime Elapsed :   << 1.0 * clock() / CLOCKS_PER_SEC <<   s n ;   }   void debug_out() { cerr << endl; }   template <typename Head, typename... Tail>   void debug_out(Head H, Tail... T) {     cerr <<     << H;     debug_out(T...);   }   void solve() {     string s;     cin >> s;     string temp =   ;     vector<int> cnt;     int c = 1;     temp += s[0];     for (int i = 1; i < s.size(); i++) {       if (s[i] == s[i - 1]) {         c++;       } else {         temp += s[i];         cnt.push_back(c);         c = 1;       }     }     cnt.push_back(c);     string w = temp;     reverse((w).begin(), (w).end());     if (w != temp) {       cout << 0;       return;     } else {       int pos = (cnt.size()) / 2;       for (long long i = 0; i < pos; i++) {         if ((cnt[i] + cnt[cnt.size() - i - 1]) < 3) {           cout << 0;           return;         }       }       if (cnt[pos] >= 2)         cout << cnt[pos] + 1;       else         cout << 0;       return;     }   }   int main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     srand(time(NULL));     1;     long long t = 1;     while (t--) {       solve();     }     1;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     char c[2] = { w ,  b };     cin >> n;     if (n % 2 == 1)       cout <<  -1 ;     else {       for (int i = 1; i <= n; i++) {         for (int j = 0; j < n; j++) {           for (int k = 0; k < n; k++) {             if ((j / 2) % 2 == 0)               if ((k / 2) % 2 == 0)                 cout << c[i % 2];               else                 cout << c[!(i % 2)];             if ((j / 2) % 2 == 1)               if ((k / 2) % 2 == 0)                 cout << c[!(i % 2)];               else                 cout << c[i % 2];           }           cout << endl;         }         cout << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   ostream& operator<<(ostream& os, const vector<T>& v) {     for (auto i : v) os << i <<    ;     return os;   }   template <typename T>   ostream& operator<<(ostream& os, const set<T>& v) {     for (auto i : v) os << i <<    ;     return os;   }   template <typename T>   T read() {     char c = getchar();     T sgn = 1;     T t = 0;     while (!isdigit(c)) {       if (c ==  - ) sgn = -sgn;       c = getchar();     }     while (isdigit(c)) {       t *= 10;       t += c -  0 ;       c = getchar();     }     return t * sgn;   }   const int N = 1e5;   vector<int> atk, def, had;   bool used[N];   int main() {     int n = read<int>();     int m = read<int>();     for (int i = 0; i < n; ++i) {       char s[10];       int val;       scanf( %s %d , s, &val);       getchar();       if (s[0] ==  A ) atk.push_back(val);       if (s[0] ==  D ) def.push_back(val);     }     for (int i = 0; i < m; ++i) had.push_back(read<int>());     sort(atk.begin(), atk.end());     sort(def.begin(), def.end());     sort(had.begin(), had.end());     int ans = 0;     for (int i = m - 1; i >= 0; --i) {       int cur = 0;       for (int j = 0, t = atk.size(); j < m - i && j < t; ++j)         if (had[i + j] >= atk[j]) cur += had[i + j] - atk[j];       ans = max(ans, cur);     }     int p = 0;     for (auto i : def) {       while (p < m && had[p] <= i) p++;       if (p == m) {         printf( %d n , ans);         exit(0);       }       used[p] = true;       p++;     }     p = m - 1;     int ans2 = 0;     for (int i = atk.size() - 1; i >= 0; --i) {       int j = atk[i];       while (p >= 0 && used[p]) p--;       if (p == -1 || had[p] < j) {         printf( %d n , ans);         exit(0);       }       ans2 += had[p] - j;       used[p] = true;       p--;     }     for (int i = 0; i < m; ++i)       if (!used[i]) ans2 += had[i];     printf( %d n , max(ans, ans2));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   int lazy[600005];   bool haslazy[600005];   int tree[600005];   int arr[200005];   int lft(int x) { return 2 * x + 1; }   int ryt(int x) { return 2 * x + 2; }   struct lol {     int x;     int y;     int z;   };   void updt(int x, int l, int r, int value) {     tree[x] = (value | tree[x]);     if (haslazy[x])       lazy[x] = (lazy[x] | value);     else       lazy[x] = value;     haslazy[x] = true;   }   void laze(int x, int l, int r) {     if (!haslazy[x]) return;     int mid = (l + r) / 2;     updt(ryt(x), mid + 1, r, lazy[x]);     updt(lft(x), l, mid, lazy[x]);     lazy[x] = 0;     haslazy[x] = false;   }   void prop(int x, int l, int r, int a, int b, int value) {     if (r < a || l > b) return;     if (l >= a && r <= b) {       updt(x, l, r, value);       return;     }     laze(x, l, r);     int mid = (l + r) / 2;     prop(lft(x), l, mid, a, b, value);     prop(ryt(x), mid + 1, r, a, b, value);     int ta = tree[lft(x)];     int tb = tree[ryt(x)];     tree[x] = (ta & tb);   }   int query(int x, int l, int r, int a, int b) {     if (l > b || r < a) return ((long long)1 << (long long)31) - 1;     if (l >= a && r <= b) {       return tree[x];     }     laze(x, l, r);     int mid = (l + r) / 2;     int ta = query(lft(x), l, mid, a, b);     int tb = query(ryt(x), mid + 1, r, a, b);     return (ta & tb);   }   void build(int x, int a, int b) {     if (a == b) {       tree[x] = 0;       return;     }     int mid = (a + b) / 2;     build(lft(x), a, mid);     build(ryt(x), mid + 1, b);     tree[x] = 0;   }   int main() {     cin >> n;     build(0, 0, n - 1);     int m;     cin >> m;     vector<lol> q;     for (int i = 0; i < m; i++) {       lol temp;       cin >> temp.x >> temp.y >> temp.z;       prop(0, 0, n - 1, temp.x - 1, temp.y - 1, temp.z);       q.push_back(temp);     }     bool flag = false;     for (int i = 0; i < m; i++) {       if (query(0, 0, n - 1, q[i].x - 1, q[i].y - 1) != q[i].z) {         flag = true;         break;       }     }     if (flag) {       cout <<  NO ;     } else {       cout <<  YES  << endl;       for (int i = 0; i < n; i++) {         int temp = query(0, 0, n - 1, i, i);         cout << temp <<    ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int i;   double a, b, c, d, base, top, mid, x11, x22, y11, y22, minim1, minim2, maxim1,       maxim2;   int main() {     scanf( %lf%lf%lf%lf , &a, &b, &c, &d);     base = 0.0;     top = 1000000000.0;     for (i = 1; i <= 100; i++) {       mid = (base + top) / 2.0;       x11 = a - mid;       x22 = a + mid;       y11 = d - mid;       y22 = d + mid;       minim1 = min(min(x11 * y11, x11 * y22), min(x22 * y11, x22 * y22));       maxim1 = max(max(x11 * y11, x11 * y22), max(x22 * y11, x22 * y22));       x11 = b - mid;       x22 = b + mid;       y11 = c - mid;       y22 = c + mid;       minim2 = min(min(x11 * y11, x11 * y22), min(x22 * y11, x22 * y22));       maxim2 = max(max(x11 * y11, x11 * y22), max(x22 * y11, x22 * y22));       if (maxim1 < minim2 || maxim2 < minim1)         base = mid;       else         top = mid;     }     printf( %.9lf n , top);   }


#include <bits/stdc++.h>   using namespace std;   int n;   pair<int, int> point[int(2e5 + 10)];   map<int, int> mark_x, mark_y;   long long res;   void sol() {     cin >> n;     for (int i = 0; i < n; i++) {       cin >> point[i].first >> point[i].second;       mark_x[point[i].first]++;       mark_y[point[i].second]++;     }     sort(point, point + n);     for (int i = 0; i < n; i++) {       if (i == 0 || point[i].first != point[i - 1].first) {         for (int j = i; point[j].first == point[i].first && j < n; j++) {           mark_y[point[j].second]--;         }       }       mark_x[point[i].first]--;       res += mark_x[point[i].first];       res += mark_y[point[i].second];     }     cout << res;   }   int main() {     std::ios::sync_with_stdio(false);     cin.tie(NULL);     sol();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   bool isPrime(T x) {     if (x <= 1) return false;     T i;     for (i = 2; i * i <= x; i++)       if (x % i == 0) return false;     return true;   }   template <class T>   class Prime {    public:     vector<T> z;     Prime() {       z.resize(1e5 + 7);       for (int i = (0); i < (((int)z.size())); i++) z[i] = 1;       z[0] = 0;       z[1] = 0;       T j;       for (int i = (2); i < (((int)z.size())); i++) {         if (z[i]) {           j = i + i;           while (j < ((int)z.size())) {             z[j] = 0;             j += i;           }         }       }     }   };   template <class T>   double dist(T x1, T y1, T x2, T y2) {     return sqrt(1. * (x2 - x1) * (x2 - x1) + 1. * (y2 - y1) * (y2 - y1));   }   template <class T>   class Point {    public:     T x, y;     Point() {}     Point(T a, T b) : x(a), y(b) {}     bool operator==(const Point& tmp) const { return (x == tmp.x && y == tmp.y); }     Point operator-(const Point& tmp) const {       return Point<T>(x - tmp.x, y - tmp.y);     }   };   char toLowerCase(char x) { return (x + 32); }   char toUpperCase(char x) { return (x - 32); }   bool isUpperCase(char x) { return (65 <= x && x <= 90) ? 1 : 0; }   bool isLowerCase(char x) { return (97 <= x && x <= 122) ? 1 : 0; }   bool isAlpha(char x) { return (isUpperCase(x) || isLowerCase(x)) ? 1 : 0; }   bool isDigit(char x) { return ( 0  <= x && x <=  9 ) ? 1 : 0; }   template <class T>   T toDec(string s) {     stringstream is(s);     T res;     is >> res;     return res;   }   template <class T>   string toStr(T n) {     string s;     stringstream is;     is << n;     is >> s;     return s;   }   template <class T>   void checkmin(T& a, T b) {     if (a > b) a = b;   }   template <class T>   void checkmax(T& a, T b) {     if (a < b) a = b;   }   vector<int> res;   string s;   void parse(int ind) {     string tmp = s.substr(ind + 7);     int p = tmp.find( <table> );     if (p != -1) {       parse(ind + 7 + p);       tmp = s.substr(ind + 7);     }     p = tmp.find( </table> ) + ind + 14;     int i, tot;     i = ind;     tot = 0;     while (i <= p) {       if (i + 3 <= p && s.substr(i, 4) ==  <td> ) tot++;       s[i] =  1 ;       i++;     }     res.push_back(tot);   }   int main() {     int c;     while ((c = getchar()) != EOF) {       if (c !=   n ) s += c;     }     parse(0);     sort(res.begin(), res.end());     for (int i = (0); i < (((int)res.size())); i++) cout << res[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     cout << 3 * n - 1 <<     << 2 << endl;     cout <<  1 3  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool ispalindrom(string s) {     string rs;     reverse(s.begin(), s.end());     rs = s;     reverse(s.begin(), s.end());     if (rs == s)       return true;     else       return false;   }   int main() {     string s;     int k;     cin >> s >> k;     int n = s.length();     if (n % k != 0) {       cout <<  NO ;       return 0;     }     int i = n / k, count = 0;     for (int j = 0; j + i <= n; j += i) {       string temp = s.substr(j, i);       if (!ispalindrom(temp)) {         cout <<  NO ;         return 0;       }     }     cout <<  YES ;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 300001;   int f[maxn], a[maxn];   inline void add(int x, int val) {     for (int i = x + 1; i < maxn; i += i & (-i)) f[i] += val;   }   inline int get(int x) {     int ans = 0;     for (int i = x; i > 0; i -= i & (-i)) ans += f[i];     return ans;   }   inline int sum(int x, int y) { return get(y) - get(x); }   int main() {     int q, l, r, n, m, rev = 0;     scanf( %d%d , &n, &m);     int cr = n - 1, cl = 0;     int len = cr - cl + 1;     for (int i = 0; i < n; ++i) add(i, a[i] = 1);     for (int t = 0; t < m; ++t) {       scanf( %d , &q);       if (q == 1) {         scanf( %d , &l);         if (l > len - l) rev ^= 1, l = len - l;         if (rev) {           cr = cr - l;           for (int i = cr; i >= cr - l + 1; --i)             add(i, a[2 * cr - i + 1]), a[i] += a[2 * cr - i + 1];         } else {           cl = cl + l;           for (int i = cl; i <= cl + l - 1; ++i)             add(i, a[2 * cl - i - 1]), a[i] += a[2 * cl - i - 1];         }         len = cr - cl + 1;       }       if (q == 2) {         scanf( %d%d , &l, &r);         int ln = (r - l);         if (rev)           l = cr - l + 1, r = l - ln, swap(l, r);         else           l += cl, r += cl;         printf( %d n , sum(l, r));       }     }   }


#include <bits/stdc++.h>   #pragma GCC optimize( O2 )   using namespace std;   int n, s;   int frq[1002];   int t;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cin >> n >> s;     for (int i = 1; i <= n; ++i) {       int a, b;       cin >> a >> b;       frq[a] = max(frq[a], b);     }     for (int i = s; i >= 0; --i) {       t = max(t, frq[i]);       if (i != 0) ++t;     }     cout << t;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   unsigned long long gcd(unsigned long long a, unsigned long long b) {     return b == 0 ? a : gcd(b, a % b);   }   const int MAXTREE = 50;   const int MOD = 998244353;   const int INV6 = 166374059;   const int MINCOORD = -1000000000;   const int MAXCOORD = +1000000000;   struct P {     int x, y;     P() {}     P(int x, int y) : x(x), y(y) {}   };   P operator-(const P &a, const P &b) { return P(a.x - b.x, a.y - b.y); }   bool operator==(const P &a, const P &b) { return a.x == b.x && a.y == b.y; }   struct Pol {     vector<P> p;   };   int ntree, tlast;   P t[MAXTREE];   void rotate(P &p) { p = P(-p.y, +p.x); }   void rotate(Pol &pol) {     for (int i = (0); i < (((int)(pol.p).size())); ++i) rotate(pol.p[i]);   }   void flip(P &p) { swap(p.x, p.y); }   void flip(Pol &pol) {     for (int i = (0); i < (((int)(pol.p).size())); ++i) flip(pol.p[i]);     reverse(pol.p.begin(), pol.p.end());   }   P infleftup(const P &p) {     int t = min(p.x - MINCOORD, MAXCOORD - p.y);     return P(p.x - t, p.y + t);   }   P infleftdown(const P &p) {     int t = min(p.x - MINCOORD, p.y - MINCOORD);     return P(p.x - t, p.y - t);   }   P infrightup(const P &p) {     int t = min(MAXCOORD - p.x, MAXCOORD - p.y);     return P(p.x + t, p.y + t);   }   P infrightdown(const P &p) {     int t = min(MAXCOORD - p.x, p.y - MINCOORD);     return P(p.x + t, p.y - t);   }   int getdelta(const P &a, const P &b) {     P ba = b - a;     assert(ba.y == 0 || abs(ba.y) == abs(ba.x));     return ba.y / ba.x;   }   int getdir(const P &a, const P &b) {     P ba = b - a;     int mag = max(abs(ba.x), abs(ba.y));     assert(mag != 0 && ba.x % mag == 0 && ba.y % mag == 0);     ba.x /= mag, ba.y /= mag;     if (ba == P(1, 1)) return 0;     if (ba == P(1, 0)) return 1;     if (ba == P(1, -1)) return 2;     if (ba == P(0, -1)) return 3;     if (ba == P(-1, -1)) return 4;     if (ba == P(-1, 0)) return 5;     if (ba == P(-1, 1)) return 6;     if (ba == P(0, 1)) return 7;     assert(false);     return -1;   }   int gety(int x, const vector<P> &path) {     int idx = 0;     while (idx + 1 < ((int)(path).size()) && path[idx + 1].x <= x) ++idx;     assert(idx + 1 < ((int)(path).size()));     int v = getdelta(path[idx], path[idx + 1]);     return path[idx].y + (x - path[idx].x) * v;   }   vector<pair<P, P>> segmentsbeloworequal(P a, P b, const vector<P> &path) {     bool swapab = false;     if (a.x > b.x) swapab = true, swap(a, b);     P ba = b - a;     vector<pair<P, P>> ret;     if (ba.x == 0) {       int x = a.x, py = gety(x, path);       assert(!swapab);       if (a.y <= py)         ret.push_back(make_pair(a, P(x, min(py, b.y))));       else if (b.y <= py)         ret.push_back(make_pair(P(x, py), b));     } else {       int x = a.x, y = a.y, u = getdelta(a, b), idx = 0;       P oth = a;       while (true) {         while (idx + 1 < ((int)(path).size()) && path[idx + 1].x <= x) ++idx;         assert(idx + 1 < ((int)(path).size()));         int v = getdelta(path[idx], path[idx + 1]);         int py = path[idx].y + (x - path[idx].x) * v;         if (x == b.x) {           if (y <= py) ret.push_back(make_pair(oth, b));           break;         }         int dx = min(b.x - x, path[idx + 1].x - x);         if (y <= py) {           if (u - v >= 1) {             int t = (py - y) / (u - v);             if (t < dx) ret.push_back(make_pair(oth, P(x + t, y + u * t)));           }         } else {           if (v - u >= 1) {             int t = (y - py - 1) / (v - u);             if (t < dx) oth = P(x + t + 1, y + u * (t + 1));           }         }         x += dx, y += u * dx;       }     }     if (swapab) {       swapab = false, swap(a, b), reverse(ret.begin(), ret.end());       for (int i = (0); i < (((int)(ret).size())); ++i)         swap(ret[i].first, ret[i].second);     }     return ret;   }   bool isbeloworequal(const P &a, const vector<P> &path) {     return a.y <= gety(a.x, path);   }   bool isinside(const P &p, const Pol &pol) {     if (((int)(pol.p).size()) == 1) return pol.p[0] == p;     bool ret = false;     for (int i = (0); i < (((int)(pol.p).size())); ++i) {       P a = pol.p[i], b = pol.p[(i + 1) % ((int)(pol.p).size())],         c = pol.p[(i + 2) % ((int)(pol.p).size())],         d = pol.p[(i + 3) % ((int)(pol.p).size())];       int pdir = getdir(a, b), cdir = getdir(b, c), ndir = getdir(c, d);       int sgn, delta;       P l, r;       bool includefirst, includelast;       if (cdir < 4) {         includefirst = pdir < 3 || pdir >= cdir + 4,         includelast = cdir != 3 && ndir >= 4 && ndir <= cdir + 4;         if (cdir == 3) {           sgn = includefirst ? +1 : 0, delta = 0, l = r = b;           ++l.y, ++r.y;         } else {           sgn = +1, delta = getdelta(b, c);           l = b, r = c;           ++l.y, ++r.y;           if (!includefirst) ++l.x, l.y += delta;           if (!includelast) --r.x, r.y -= delta;         }       } else {         includefirst = pdir != 7 && pdir >= cdir - 4,         includelast = cdir != 7 && ndir <= cdir - 4;         if (cdir == 7) {           sgn = includefirst ? -1 : 0, delta = 0, l = r = b;         } else {           sgn = -1, delta = getdelta(c, b), l = c, r = b;           if (!includefirst) --r.x, r.y -= delta;           if (!includelast) ++l.x, l.y += delta;         }       }       if (sgn != 0 && l.x <= p.x && p.x <= r.x && p.y < l.y + (p.x - l.x) * delta)         ret = !ret;     }     return ret;   }   void updatepol(Pol &pol, bool prvonpol, const P p, const vector<P> &path,                  const Pol &orig) {     if (((int)(pol.p).size()) >= 1 && p == pol.p[((int)(pol.p).size()) - 1])       return;     if (!prvonpol && ((int)(pol.p).size()) >= 1) {       P a = pol.p[((int)(pol.p).size()) - 1], b = p;       bool swapab = false;       if (a.x > b.x) swapab = true, swap(a, b);       int ay = gety(a.x, path), by = gety(b.x, path);       if (ay != a.y) {         assert(ay == a.y + 1);         if (isinside(P(a.x, a.y + 1), orig))           ++a.y;         else           ++a.x, --ay;       }       if (by != b.y) {         assert(by == b.y + 1);         if (isinside(P(b.x, b.y + 1), orig))           ++b.y;         else           --b.x, --by;       }       vector<P> extra;       if (!(a == pol.p[((int)(pol.p).size()) - 1])) extra.push_back(a);       for (int i = (0); i < (((int)(path).size())); ++i)         if (a.x < path[i].x && path[i].x < b.x) extra.push_back(path[i]);       if (!(b == p) && !(b == a)) extra.push_back(b);       if (swapab) reverse(extra.begin(), extra.end());       for (int i = (0); i < (((int)(extra).size())); ++i)         pol.p.push_back(extra[i]);     }     if (((int)(pol.p).size()) == 0 || !(p == pol.p[((int)(pol.p).size()) - 1]))       pol.p.push_back(p);   }   Pol cutabove(Pol pol, const vector<P> &path) {     if (((int)(pol.p).size()) == 0) return pol;     Pol ret;     if (((int)(pol.p).size()) == 1)       return isbeloworequal(pol.p[0], path) ? pol : ret;     bool prvonpol = false;     for (int i = (0); i < (((int)(pol.p).size())); ++i) {       P a = pol.p[i], b = pol.p[(i + 1) % ((int)(pol.p).size())];       vector<pair<P, P>> segments = segmentsbeloworequal(a, b, path);       if (((int)(segments).size()) == 0 || !(segments[0].first == a))         prvonpol = false;       for (int k = (0); k < (((int)(segments).size())); ++k) {         if (segments[k].first == b) {           assert(segments[k].second == b);           assert(k == ((int)(segments).size()) - 1);           prvonpol = false;         } else {           updatepol(ret, prvonpol, segments[k].first, path, pol);           if (segments[k].first == segments[k].second) {             prvonpol = false;           } else if (segments[k].second == b) {             prvonpol = true;           } else {             updatepol(ret, true, segments[k].second, path, pol);             prvonpol = false;           }         }       }     }     if (((int)(ret.p).size()) >= 1) {       if (!(ret.p[0] == pol.p[0])) prvonpol = false;       updatepol(ret, prvonpol, ret.p[0], path, pol);       if (((int)(ret.p).size()) >= 2 &&           ret.p[((int)(ret.p).size()) - 1] == ret.p[0])         ret.p.pop_back();     }     return ret;   }   Pol cut(Pol pol, P a, P b, bool winequal) {     int nrot = 0, nflip = 0;     while (b.y <= a.y || b.x < a.x) rotate(pol), rotate(a), rotate(b), ++nrot;     if (b.y - a.y < b.x - a.x) flip(pol), flip(a), flip(b), ++nflip;     P d = b - a;     int between = d.y - 1;     int asteps = between / 2, bsteps = between / 2, turn = winequal ? 0 : 1;     if (between % 2 == 1)       if (turn == 0)         ++asteps, turn = 1;       else         ++bsteps, turn = 0;     vector<P> path;     int y = a.y + asteps;     if (d.x == d.y) {       P m(a.x + asteps + (turn == 0 ? 1 : 0), y);       path.push_back(infleftup(m));       path.push_back(infrightdown(m));     } else if (d.x == 0) {       if (asteps < bsteps) {         assert(turn == 0);         ++asteps, turn = 1;       }       if (bsteps < asteps) {         assert(turn == 1);         ++bsteps, turn = 0;       }       assert(asteps == bsteps);       P l(a.x - asteps, y), r(a.x + asteps, y);       path.push_back(turn == 0 ? infleftup(l) : infleftdown(l));       path.push_back(l);       if (l.x != r.x || l.y != r.y) path.push_back(r);       path.push_back(turn == 0 ? infrightup(r) : infrightdown(r));     } else {       P l(a.x + d.x - bsteps - (turn == 0 ? 0 : 1), y),           r(a.x + asteps + (turn == 0 ? 1 : 0), y);       path.push_back(infleftup(l));       path.push_back(l);       path.push_back(r);       path.push_back(infrightdown(r));     }     pol = cutabove(pol, path);     while (nflip % 2 != 0) flip(pol), flip(a), flip(b), ++nflip;     while (nrot % 4 != 0) rotate(pol), rotate(a), rotate(b), ++nrot;     return pol;   }   int sum(int a, int b) { return (long long)(a + b) * (b - a + 1) / 2 % MOD; }   int sumsq(int a, int b) {     return ((long long)2 * a * a + (long long)2 * b * b + (long long)2 * a * b +             b - a) %            MOD * (b - a + 1) % MOD * INV6 % MOD;   }   int calcsum(const P &l, const P &r, int delta) {     int y = l.y % MOD;     if (y < 0) y += MOD;     int x = l.x % MOD;     if (x < 0) x += MOD;     if (delta == 0) {       return (long long)sum(l.x, r.x) * y % MOD;     } else if (delta == 1) {       return ((long long)sum(l.x, r.x) * (y + MOD - x) + sumsq(l.x, r.x)) % MOD;     } else if (delta == -1) {       return ((long long)sum(l.x, r.x) * (y + x) + MOD - sumsq(l.x, r.x)) % MOD;     } else {       assert(false);     }   }   int xcalc(Pol pol) {     int ret = 0;     if (((int)(pol.p).size()) >= 2)       for (int i = (0); i < (((int)(pol.p).size())); ++i) {         P a = pol.p[i], b = pol.p[(i + 1) % ((int)(pol.p).size())],           c = pol.p[(i + 2) % ((int)(pol.p).size())],           d = pol.p[(i + 3) % ((int)(pol.p).size())];         int pdir = getdir(a, b), cdir = getdir(b, c), ndir = getdir(c, d);         int sgn, delta;         P l, r;         bool includefirst, includelast;         if (cdir < 4) {           includefirst = pdir < 3 || pdir >= cdir + 4,           includelast = cdir != 3 && ndir >= 4 && ndir <= cdir + 4;           if (cdir == 3) {             sgn = includefirst ? +1 : 0, delta = 0, l = r = b;             ++l.y, ++r.y;           } else {             sgn = +1, delta = getdelta(b, c);             l = b, r = c;             ++l.y, ++r.y;             if (!includefirst) ++l.x, l.y += delta;             if (!includelast) --r.x, r.y -= delta;           }         } else {           includefirst = pdir != 7 && pdir >= cdir - 4,           includelast = cdir != 7 && ndir <= cdir - 4;           if (cdir == 7) {             sgn = includefirst ? -1 : 0, delta = 0, l = r = b;           } else {             sgn = -1, delta = getdelta(c, b), l = c, r = b;             if (!includefirst) --r.x, r.y -= delta;             if (!includelast) ++l.x, l.y += delta;           }         }         int cur = sgn != 0 && l.x <= r.x ? calcsum(l, r, delta) : 0;         if (sgn == +1)           ret = (ret + cur) % MOD;         else           ret = (ret + MOD - cur) % MOD;       }     if (((int)(pol.p).size()) == 1) ret = (ret + pol.p[0].x) % MOD;     return ret;   }   Pol cutbelow(Pol pol, vector<P> path) {     for (int rep = (0); rep < (2); ++rep) {       rotate(pol);       for (int i = (0); i < (((int)(path).size())); ++i) rotate(path[i]);     }     reverse(path.begin(), path.end());     pol = cutabove(pol, path);     for (int rep = (0); rep < (2); ++rep) {       rotate(pol);       for (int i = (0); i < (((int)(path).size())); ++i) rotate(path[i]);     }     reverse(path.begin(), path.end());     return pol;   }   int calc(Pol pol) {     int ret = 0;     for (int rep = (0); rep < (4); ++rep) {       vector<P> upath;       upath.push_back(infleftdown(P(0, 0)));       upath.push_back(infrightup(P(0, 0)));       vector<P> lpath;       lpath.push_back(P(MINCOORD, 0));       lpath.push_back(P(1, 0));       lpath.push_back(infrightdown(P(1, 0)));       Pol cpol = cutbelow(cutabove(pol, upath), lpath);       ret = (ret + xcalc(cpol)) % MOD;       rotate(pol);     }     return ret;   }   int solve() {     if (tlast == 0) return 0;     int ret = 0;     for (int i = (0); i < (ntree); ++i) {       Pol pol;       pol.p.push_back(P(t[i].x - tlast, t[i].y + tlast));       pol.p.push_back(P(t[i].x + tlast, t[i].y + tlast));       pol.p.push_back(P(t[i].x + tlast, t[i].y - tlast));       pol.p.push_back(P(t[i].x - tlast, t[i].y - tlast));       for (int j = (0); j < (ntree); ++j)         if (j != i) {           pol = cut(pol, t[i], t[j], i < j);         }       for (int k = (0); k < (((int)(pol.p).size())); ++k)         pol.p[k] = pol.p[k] - t[i];       ret = (ret + calc(pol)) % MOD;     }     return ret;   }   void run() {     scanf( %d%d , &ntree, &tlast);     for (int i = (0); i < (ntree); ++i) scanf( %d%d , &t[i].x, &t[i].y);     printf( %d n , solve());   }   int solvestupid() {     int lx = INT_MAX, hx = INT_MIN, ly = INT_MAX, hy = INT_MIN;     for (int i = (0); i < (ntree); ++i)       lx = min(lx, t[i].x - tlast), hx = max(hx, t[i].x + tlast),       ly = min(ly, t[i].y - tlast), hy = max(hy, t[i].y + tlast);     vector<vector<int>> d(hx - lx + 1, vector<int>(hy - ly + 1, INT_MAX));     for (int i = (0); i < (ntree); ++i)       for (int x = (t[i].x - tlast); x <= (t[i].x + tlast); ++x)         for (int y = (t[i].y - tlast); y <= (t[i].y + tlast); ++y) {           int &v = d[x - lx][y - ly];           v = min(v, max(abs(x - t[i].x), abs(y - t[i].y)));         }     int ret = 0;     for (int x = (lx); x <= (hx); ++x)       for (int y = (ly); y <= (hy); ++y) {         int v = d[x - lx][y - ly];         if (v != INT_MAX) ret += v;       }     return ret;   }   void stress() {     mt19937 rnd(12344);     int mxn = 100, mxt = 100, mncoord = 0, mxcoord = 100;     for (int rep = (0); rep < (100000); ++rep) {       ntree = rnd() % mxn + 1;       tlast = rnd() % (mxt + 1);       set<pair<int, int>> seen;       for (int i = (0); i < (ntree); ++i)         while (true) {           t[i].x = rnd() % (mxcoord - mncoord + 1) + mncoord,           t[i].y = rnd() % (mxcoord - mncoord + 1) + mncoord;           if (seen.count(make_pair(t[i].x, t[i].y))) continue;           seen.insert(make_pair(t[i].x, t[i].y));           break;         }       int have = solve();       int want = solvestupid();       if (have == want) {         if (rep % 100 == 99) printf( . );         continue;       }       puts(  );       printf( %d %d n , ntree, tlast);       for (int i = (0); i < (ntree); ++i) printf( %d %d n , t[i].x, t[i].y);       printf( err have=%d want=%d n , have, want);       break;     }   }   int main() {     run();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline void read(T& a) {     char c = getchar();     int f = 1;     a = 0;     for (; c >  9  || c <  0 ; c = getchar())       if (c ==  - ) f = -1;     for (; c <=  9  && c >=  0 ; c = getchar()) a = a * 10 + c - 48;     a *= f;   }   const int o = 1e5 + 10;   inline long long Max(long long a, long long b) { return a > b ? a : b; }   long long T, n, k, a[o];   pair<long long, long long> p[o];   signed main() {     for (read(T); T--;) {       read(n);       for (long long i = 1; i <= n; ++i) {         read(k);         for (long long j = 0; j < k; ++j) read(a[j]);         a[k] = 0;         for (long long j = k - 1; j + 1; --j) a[j] = Max(a[j + 1], a[j] - j);         p[i] = make_pair(a[0], k);       }       sort(p + 1, p + 1 + n);       for (long long i = 2, j = p[1].second; i <= n; j += p[i++].second)         p[i].first = Max(p[i - 1].first, p[i].first - j);       printf( %lld n , p[n].first + 1);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> dif;   map<int, int> g;   int a[120000];   int main() {     int n, flag;     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i];     sort(a + 1, a + 1 + n);     for (int i = 2; i <= n; i++) {       if (g[a[i] - a[i - 1]] == 0) dif.push_back(a[i] - a[i - 1]);       g[a[i] - a[i - 1]]++;     }     int sz = dif.size();     if (sz > 2 || n == 1) {       if (sz > 2)         cout << 0 << endl;       else         cout << -1 << endl;       return 0;     }     if (sz == 1) {       int D = dif[0];       if (dif[0] == 0) {         cout << 1 << endl;         cout << a[1] << endl;         return 0;       }       if (n == 2) {         if ((a[2] - a[1]) % 2 == 0) {           cout << 3 << endl;           cout << a[1] - D <<     << (a[2] + a[1]) / 2 <<     << a[2] + D << endl;           return 0;         }       }       cout << 2 << endl;       cout << a[1] - D <<     << a[n] + D << endl;       return 0;     }     int D1 = min(dif[0], dif[1]), D2 = max(dif[0], dif[1]);     if (D1 * 2 != D2 || g[D2] > 1) {       cout << 0 << endl;       return 0;     }     cout << 1 << endl;     for (int i = 2; i <= n; i++) {       if (a[i] - a[i - 1] == D2) {         cout << a[i] - D1 << endl;         return 0;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void init_code() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }   set<pair<int, int>> es;   map<int, list<int>> m;   void add(int a, int b) {     m[a].push_back(b);     m[b].push_back(a);   }   int v[1001];   void dfs(int node) {     v[node] = 1;     for (int i : m[node]) {       if (v[i] == 0) {         es.erase({node, i});         es.erase({i, node});         dfs(i);       }     }   }   int main() {     init_code();     int n;     cin >> n;     for (int i = 0; i < n - 1; i++) {       int a, b;       cin >> a >> b;       add(a, b);       es.insert({a, b});     }     vector<int> ans;     for (int i = 1; i <= n; i++) {       if (v[i] == 0) {         ans.push_back(i);         dfs(i);       }     }     cout << es.size() << endl;     vector<pair<int, int>> ans2, ans3;     for (auto i : es) {       ans2.push_back(i);     }     for (int i = 1; i < ans.size(); i++) {       ans3.push_back({ans[i], ans[i - 1]});     }     for (int i = 0; i < ans2.size(); i++) {       cout << ans2[i].first <<     << ans2[i].second <<     << ans3[i].first            <<     << ans3[i].second << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 4040, inF = 1e9;   int n, a, b, c, dp[N];   int main() {     cin >> n >> a >> b >> c;     dp[0] = 0;     for (int i = 1; i <= n; i++) {       dp[i] = -inF;       if (i >= a) dp[i] = max(dp[i], dp[i - a] + 1);       if (i >= b) dp[i] = max(dp[i], dp[i - b] + 1);       if (i >= c) dp[i] = max(dp[i], dp[i - c] + 1);     }     cout << dp[n];     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long K = 10001;   signed main() {     long long n, l, r, ans = 0;     cin >> n >> l >> r;     vector<long long> a(n), b(n);     for (long long i = 0; i < n; i++) cin >> a[i];     for (long long i = 0; i < n; i++) cin >> b[i];     vector<long long> bad, good;     for (long long i = 0; i < n; i++) {       if (b[i] == 0)         bad.push_back(a[i]);       else         good.push_back(a[i]);     }     if (good.size() == 0) {       cout << 0 << endl;       return 0;     }     sort(good.begin(), good.end());     long long S = 0;     for (long long i = 0; i < good.size(); i++) S += good[i];     bool knapbad[K], knapgood[K];     for (long long i = 0; i < K; i++) knapbad[i] = false;     for (long long i = 0; i < K; i++) knapgood[i] = false;     knapbad[0] = true;     knapgood[0] = true;     for (long long i = 0; i < bad.size(); i++) {       for (long long j = K - 1; j >= bad[i]; j--)         knapbad[j] |= knapbad[j - bad[i]];     }     long long pref[K + 1];     pref[0] = 0;     for (long long i = 1; i <= K; i++) pref[i] = pref[i - 1] + knapbad[i - 1];     vector<vector<long long> > close(good.size());     long long INF = 1e9;     close[good.size() - 1].push_back(0);     for (long long i = good.size() - 1; i >= 0; i--) {       for (long long j = K - 1; j >= good[i]; j--) {         if (!knapgood[j] && knapgood[j - good[i]]) {           if (i != 0) close[i - 1].push_back(j);           knapgood[j] = true;         }       }     }     for (long long i = l; i <= r; i++)       if (knapgood[i] && i != S) ans = max(ans, (long long)1);     long long Kn[K];     for (long long i = 0; i < K; i++) Kn[i] = -INF;     Kn[0] = 0;     for (long long i = 0; i < good.size(); i++) {       for (long long j = K - 1; j >= good[i]; j--) {         Kn[j] = max(Kn[j], Kn[j - good[i]] + 1);       }       for (long long j = 0; j < close[i].size(); j++) {         long long N = close[i][j];         for (long long p = 0; p < K; p++) {           if (Kn[p] < 0) continue;           long long L = max((long long)0, l - N), R = r - N - p;           if (L > R) continue;           if (pref[R + 1] - pref[L] == 0) continue;           if (N + p == S)             ans = max(ans, Kn[p]);           else             ans = max(ans, Kn[p] + 1);         }       }     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const int mnx = 1e5 + 9;   long long q, n;   long long a[mnx], k;   map<int, int> m;   int main() {     cin >> q;     while (q--) {       cin >> n;       for (int j = 1; j * j <= n; j++) {         int jk = n / j;         if (j == n / jk) {           m[n / j]++;           m[j]++;         }       }       cout << m.size() + 1 <<   n ;       cout << 0 <<    ;       for (auto i : m) {         cout << i.first <<    ;       }       m.clear();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e18;   int main() {     string s;     cin >> s;     int index = s.size() - 1;     vector<char> din3(s.size(), 0);     vector<char> din2(s.size(), 0);     if (index - 2 >= 5) din3[index - 2] = 1;     if (index - 1 >= 5) din2[index - 1] = 1;     index -= 3;     set<string> res;     while (index >= 5) {       if (din2[index + 2] == 1 and s.substr(index, 2) != s.substr(index + 2, 2)) {         din2[index] = 1;       }       if (din3[index + 3] == 1 and s.substr(index, 3) != s.substr(index + 3, 3)) {         din3[index] = 1;       }       if (din2[index + 3] == 1) {         din3[index] = 1;       }       if (din3[index + 2] == 1) {         din2[index] = 1;       }       --index;     }     for (auto i(0); i < din2.size(); ++i) {       if (din2[i] == 1) {         res.insert(s.substr(i, 2));       }     }     for (auto i(0); i < din3.size(); ++i) {       if (din3[i] == 1) {         res.insert(s.substr(i, 3));       }     }     cout << res.size() << endl;     while (!res.empty()) {       cout << *res.begin() << endl;       res.erase(res.begin());     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long a, b, c, l, tmp;   long long read() {     long long x = 0, f = 1;     char ch = getchar();     while (!isdigit(ch)) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (isdigit(ch)) x = x * 10 + ch -  0 , ch = getchar();     return x * f;   }   long long cal(long long x, long long y, long long z) {     if (x < y) return 0;     long long p = min(z, x - y);     return (p + 2) * (p + 1) / 2;   }   int main() {     a = read();     b = read();     c = read();     l = read();     for (int i = 0; i <= l; i++)       tmp += cal(a + i, b + c, l - i) + cal(b + i, a + c, l - i) +              cal(c + i, a + b, l - i);     printf( %I64d n , (l + 1) * (l + 2) * (l + 3) / 6 - tmp);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 3e5 + 50;   long long mod = 998244353;   int n, m, u, v;   vector<int> adj[N];   long long toAdd[N + N];   vector<pair<int, int> > q[N];   long long ans[N];   void dfs(int src, int par, int dep, long long sum) {     for (auto i : q[src]) {       toAdd[dep] += i.second;       toAdd[dep + i.first + 1] -= i.second;     }     sum += toAdd[dep];     ans[src] = sum;     for (auto i : adj[src])       if (i != par) dfs(i, src, dep + 1, sum);     for (auto i : q[src]) {       toAdd[dep] -= i.second;       toAdd[dep + i.first + 1] += i.second;     }   }   int main() {     scanf( %d , &n);     for (int i = 0; i < n - 1; ++i) {       scanf( %d%d , &u, &v);       adj[u].push_back(v);       adj[v].push_back(u);     }     scanf( %d , &m);     int d, x;     while (m--) {       scanf( %d%d%d , &v, &d, &x);       d = min(d, n);       q[v].push_back(make_pair(d, x));     }     dfs(1, 0, 0, 0);     for (int i = 1; i <= n; ++i) printf( %lld  , ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   long long a[200010] = {};   vector<int> e[200010];   long long t[200010] = {};   long long q[200010] = {};   int s, b;   long long ans = -222147483600ll;   bool cmp(long long x, long long y) { return x > y; }   void dfs(int x, int y) {     vector<long long> w;     t[x] += a[x];     q[x] = -2221483600ll;     for (int i = 0; i < e[x].size(); i++) {       if (e[x][i] == y) continue;       dfs(e[x][i], x);       t[x] += t[e[x][i]];       q[x] = max(q[x], q[e[x][i]]);       w.push_back(q[e[x][i]]);     }     sort(w.begin(), w.end(), cmp);     q[x] = max(t[x], q[x]);     if (w.size() >= 2) {       ans = max(w[0] + w[1], ans);     }   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %lld , &a[i]);     }     for (int i = 1; i < n; i++) {       scanf( %d%d , &s, &b);       e[s].push_back(b);       e[b].push_back(s);     }     dfs(1, 0);     if (ans == -222147483600ll)       cout <<  Impossible  << endl;     else       cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   const int N = 1e5 + 5;   struct ooo {     int v, id;   } p[N << 1];   bool operator<(const ooo& a, const ooo& b) { return a.v < b.v; }   int n, ans, id, h, m, k, x;   int main() {     scanf( %d%d%d%d , &n, &h, &m, &k);     m /= 2;     for (int i = 1; i <= n; i++)       scanf( %d%d , &x, &p[i].v), p[i].v %= m, p[i].id = i;     std::sort(p + 1, p + 1 + n);     for (int i = 1; i <= n; i++) p[i + n] = p[i], p[i + n].v += m;     ans = 1e9;     x = -1;     for (int i = 1, j = 1; i <= n * 2; i++) {       while (p[i].v - p[j].v >= k) j++;       if (i > n && i - j < ans) ans = i - j, x = p[i].v;     }     printf( %d %d n , ans, x % m);     for (int i = 1; i <= n * 2; i++)       if (x - k < p[i].v && p[i].v < x) printf( %d  , p[i].id);   }


#include <bits/stdc++.h>   using namespace std;   using int64 = long long;   struct Primal_Dual {     const int INF = 1 << 30;     struct edge {       int to, cap, cost, rev;     };     vector<vector<edge> > graph;     vector<int> potential, min_cost, prevv, preve;     Primal_Dual(int V) : graph(V) {}     void add_edge(int from, int to, int cap, int cost) {       graph[from].push_back((edge){to, cap, cost, (int)graph[to].size()});       graph[to].push_back((edge){from, 0, -cost, (int)graph[from].size() - 1});     }     int min_cost_flow(int s, int t, int f) {       int V = graph.size(), ret = 0;       priority_queue<pair<int, int>, vector<pair<int, int> >,                      greater<pair<int, int> > >           que;       potential.assign(V, 0);       preve.assign(V, -1);       prevv.assign(V, -1);       while (f > 0) {         min_cost.assign(V, INF);         que.push(pair<int, int>(0, s));         min_cost[s] = 0;         while (!que.empty()) {           pair<int, int> p = que.top();           que.pop();           if (min_cost[p.second] < p.first) continue;           for (int i = 0; i < graph[p.second].size(); i++) {             edge &e = graph[p.second][i];             int nextCost = min_cost[p.second] + e.cost + potential[p.second] -                            potential[e.to];             if (e.cap > 0 && min_cost[e.to] > nextCost) {               min_cost[e.to] = nextCost;               prevv[e.to] = p.second, preve[e.to] = i;               que.push(pair<int, int>(min_cost[e.to], e.to));             }           }         }         if (min_cost[t] == INF) return -1;         for (int v = 0; v < V; v++) potential[v] += min_cost[v];         int addflow = f;         for (int v = t; v != s; v = prevv[v]) {           addflow = min(addflow, graph[prevv[v]][preve[v]].cap);         }         f -= addflow;         ret += addflow * potential[t];         for (int v = t; v != s; v = prevv[v]) {           edge &e = graph[prevv[v]][preve[v]];           e.cap -= addflow;           graph[v][e.rev].cap += addflow;         }       }       return ret;     }   };   int main() {     int N, B[100];     string S;     cin >> N;     cin >> S;     int sum[26] = {};     for (int i = 0; i < N; i++) {       sum[S[i] -  a ]++;     }     for (int i = 0; i < N; i++) {       cin >> B[i];     }     Primal_Dual flow(N / 2 + 28);     int s = N / 2 + 26, t = N / 2 + 27;     for (int i = 0; i < 26; i++) {       flow.add_edge(s, N / 2 + i, sum[i], 0);     }     for (int i = 0; i < N / 2; i++) {       flow.add_edge(i, t, 2, 0);     }     for (int i = 0; i < N / 2; i++) {       for (int j = 0; j < 26; j++) {         int ret = 0;         if (S[i] -  a  == j) ret = max(ret, B[i]);         if (S[N - i - 1] -  a  == j) ret = max(ret, B[N - i - 1]);         flow.add_edge(N / 2 + j, i, 1, -ret);       }     }     cout << -flow.min_cost_flow(s, t, N) << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     string s;     cin >> s;     for (int i = 0; i < s.size(); i++) {       if (s[i] ==  W  && s[i + 1] ==  U  && s[i + 2] ==  B ) {         i += 2;         cout <<    ;       } else {         cout << s[i];       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void fastIO() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.precision(20);   }   int main() {     fastIO();     int n;     int m;     int total;     int day = 0;     cin >> n >> m;     while (n != 0) {       day++;       n = n - 1;       if (day % m == 0) {         n = n + 1;       }     }     cout << day << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, sum = 0;     cin >> n;     vector<long long int> v;     for (long long int i = 0; i < n; i++) {       long long int el;       cin >> el, sum += el;       v.push_back(el);     }     sum = sum / n;     long long int res = 0, curr = 0;     for (long long int i = 0; i < n; i++) {       curr += v[i] - sum;       (curr > 0) ? res += curr : res -= curr;     }     cout << res;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     long long int n, k;     cin >> n >> k;     string s;     cin >> s;     if (k == 0) {       cout << s;       return;     }     if (n == 1)       cout <<  0 ;     else {       if (s[0] >  1 ) {         s[0] =  1 ;         k--;       }       for (long long int i = 1; i < n && k > 0; i++) {         if (s[i] >  0 ) {           s[i] =  0 ;           k--;         }       }       cout << s;     }   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     long long int t;     t = 1;     while (t--) {       solve();       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     int n;     cin >> n;     string s;     cin >> s;     int ans = 0;     int count = 0;     for (int i = 0; i < s.size(); i++) {       if (s[i] ==  ) ) {         ans--;         if (ans < 0) {           count++;           ans = 0;         }       } else {         ans++;       }     }     cout << count << endl;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t = 1;     cin >> t;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 4e18;   const long long MAX = 2e5 + 5;   const long long MOD = 1e9 + 7;   int n, m;   void exgcd(int a, int b, long long &c, long long &d) {     if (a == 0) {       c = 0;       d = 1;       return;     }     exgcd(b % a, a, d, c);     c -= b / a * d;   }   long long gcd(int a, int b) {     if (a == 0) return b;     return gcd(b % a, a);   }   int g[MAX];   bool arv[MAX], avb[MAX];   int sz[MAX];   pair<int, int> ma[MAX];   vector<int> v;   vector<int> son[MAX];   void build() {     for (int i = 0; i < m; i++) {       g[i] = gcd(i, m);       sz[g[i]]++;       son[g[i]].push_back(i);     }     g[m] = m;     int x = m;     for (int i = 2; i <= sqrt(x); i++) {       if (x % i == 0) v.push_back(i);       while (x % i == 0) x /= i;     }     if (x > 1) v.push_back(x);   }   void read() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m;     build();     for (int i = 0; i < n; i++) {       int x;       cin >> x;       avb[x] = 1;       if (!x) avb[m] = 1;       sz[gcd(x, m)]--;     }   }   void dfs(long long x) {     if (arv[x]) return;     for (int i : v) {       if (i * x > m) break;       if (g[i * x] == i * x) {         dfs(i * x);         ma[x] = max(ma[x], {ma[i * x].first, i * x});       }     }     ma[x].first += sz[x];     ;     arv[x] = 1;   }   vector<int> ans;   void output() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout << ((long long)(ans).size()) <<   n ;     for (int i : ans) cout << i <<    ;     cout <<   n ;     ;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     read();     for (int i = 1; i <= m; i++)       if (g[i] == i && !arv[i]) dfs(i);     long long now = 1, pre = 1;     long long cod;     while (now <= m) {       ;       for (long long i : son[now]) {         if (!avb[i]) {           long long r, y;           exgcd(pre, m, r, y);           if (r < 0) r += m;           ans.push_back(i / gcd(pre, m) * r % m);           pre = i;         }       }       if (ma[now].second)         now = ma[now].second;       else         break;     }     output();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct node {     int l, r;   } line[1000005];   int a[5000005], ls[5000005], b[5000005];   vector<node> ans;   bool cmp(node a, node b) { return a.l < b.l; }   int main() {     int n, k;     while (~scanf( %d %d , &n, &k)) {       memset(a, 0, sizeof(a));       memset(b, 0, sizeof(b));       ans.clear();       int p = 0;       for (int i = 1; i <= n; i++) {         int l, r;         scanf( %d %d , &l, &r);         line[i] = node{l, r};         ls[++p] = l;         ls[++p] = r;       }       sort(ls + 1, ls + p + 1);       p = unique(ls + 1, ls + p + 1) - (ls + 1);       for (int i = 1; i <= n; i++) {         int l = lower_bound(ls + 1, ls + p + 1, line[i].l) - ls;         int r = lower_bound(ls + 1, ls + p + 1, line[i].r) - ls;         a[l]++;         a[r]--;         b[l]++;         b[r + 1]--;       }       for (int i = 1; i <= p; i++) {         a[i] = a[i - 1] + a[i];         b[i] = b[i - 1] + b[i];       }       for (int i = 0; i <= p; i++) {         if (a[i] >= k) {           int r = i + 1;           while (a[r] >= k) {             r++;           }           ans.push_back(node{ls[i], ls[r]});           i = r - 1;         }         if (a[i - 1] < k && a[i] < k && b[i] >= k) {           ans.push_back(node{ls[i], ls[i]});         }       }       sort(ans.begin(), ans.end(), cmp);       printf( %d n , ans.size());       for (int i = 0; i < (int)ans.size(); i++) {         printf( %d %d n , ans[i].l, ans[i].r);       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long i, j, m, a, s, c, b, n, x, y, ar[1001];     cin >> n;     while (n--) {       cin >> s >> a >> b >> c;       x = s / c;       y = x / a * b;       cout << x + y << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using vi = vector<int>;   using pi = pair<int, int>;   const int mxn = 2e5;   int n;   string ar[mxn];   void solve() {     cin >> n;     for (int i = 0; i < n; ++i) cin >> ar[i];     set<string> second;     for (int i = n - 1; i >= 0; --i) {       if (second.count(ar[i])) continue;       cout << ar[i] <<   n ;       second.insert(ar[i]);     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int t;     t = 1;     while (t--) solve();   }


#include <bits/stdc++.h>   using namespace std;   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int x;     cin >> x;     while (x--) {       int n, m, ans = 0;       cin >> n >> m;       char a[n][m];       for (int i = 0; i < n; i++) {         for (int j = 0; j < m; j++) cin >> a[i][j];       }       int i = n - 1;       for (int j = 0; j < m - 1; j++) {         if (a[i][j] ==  D ) ans++;       }       int j = m - 1;       for (i = 0; i < n - 1; i++) {         if (a[i][j] ==  R ) ans++;       }       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int Maxn = 4e5;   int n, m, q;   int head[Maxn], tot, father[Maxn], cnt[Maxn];   int vis[Maxn];   struct Edge {     int to, next;   } edge[Maxn * 10];   void init() {     memset(head, -1, sizeof(head));     tot = 0;     for (int i = 0; i < Maxn; i++) father[i] = i;   }   int Find(int x) {     int y = x;     while (y != father[y]) {       y = father[y];     }     while (x != father[x]) {       int temp = father[x];       father[x] = y;       x = temp;     }     return y;   }   void Union(int a, int b) {     int ra = Find(a), rb = Find(b);     if (ra == rb) return;     father[ra] = rb;     cnt[rb] =         max((cnt[ra] + 1) / 2 + (cnt[rb] + 1) / 2 + 1, max(cnt[ra], cnt[rb]));     cnt[ra] = 0;   }   void add_edge(int u, int v) {     edge[tot].to = v;     edge[tot].next = head[u];     head[u] = tot++;   }   int pos, len;   void dfs(int u, int deep, int tar) {     if (vis[u] == tar) return;     vis[u] = tar;     if (deep > len) {       len = deep;       pos = u;     }     for (int i = head[u]; ~i; i = edge[i].next) {       int v = edge[i].to;       dfs(v, deep + 1, tar);       Union(u, v);     }   }   int process(int u) {     pos = len = -1;     dfs(u, 0, 1);     dfs(pos, 0, 2);     return len;   }   int main() {     init();     scanf( %d %d %d , &n, &m, &q);     while (m--) {       int u, v;       scanf( %d %d , &u, &v);       add_edge(u, v);       add_edge(v, u);     }     for (int i = 1; i <= n; i++) {       if (vis[i]) continue;       int Root = Find(i);       cnt[Root] = process(i);     }     while (q--) {       int op;       scanf( %d , &op);       if (op == 1) {         int u;         scanf( %d , &u);         printf( %d n , cnt[Find(u)]);       } else {         int u, v;         scanf( %d %d , &u, &v);         Union(u, v);       }     }     return 0;   }