#include <bits/stdc++.h>   using namespace std;   const int maxn = 250005;   int n, m, k, dep[maxn], fa[maxn];   bool leaf[maxn], vis[maxn];   vector<int> e[maxn];   void dfs(int p) {     leaf[p] = vis[p] = 1;     for (int i = 0, v; i < e[p].size(); ++i) {       if (vis[v = e[p][i]]) continue;       leaf[p] = 0;       dep[v] = dep[p] + 1;       fa[v] = p;       dfs(v);     }   }   int main() {     scanf( %d%d%d , &n, &m, &k);     for (int i = 1, u, v; i <= m; ++i) {       scanf( %d%d , &u, &v);       e[u].push_back(v), e[v].push_back(u);     }     dep[1] = 1, dfs(1);     int tmp = (n + k - 1) / k;     for (int i = 1; i <= n; ++i) {       if (dep[i] >= tmp) {         printf( PATH n );         printf( %d n , dep[i]);         while (i) {           printf( %d  , i);           i = fa[i];         }         return 0;       }     }     printf( CYCLES n );     vector<int> pos;     for (int i = 1; i <= n && pos.size() < k; ++i)       if (leaf[i]) pos.push_back(i);     for (int i = 1; i <= k; ++i) {       bool f = 0;       int p = pos[i - 1];       for (int j = 0, v; j < e[p].size(); ++j) {         v = e[p][j];         if (v != fa[p] && (dep[p] - dep[v] + 1) % 3) {           printf( %d n , dep[p] - dep[v] + 1);           f = 1;           while (fa[p] != fa[v]) {             printf( %d  , p);             p = fa[p];           }           printf( %d n , p);           break;         }       }       if (f) continue;       vector<int> bad;       for (int j = 0, v; j < e[p].size() && bad.size() < 2; ++j)         if ((v = e[p][j]) != fa[p]) bad.push_back(v);       int x = bad[0], y = bad[1];       if (dep[x] > dep[y]) swap(x, y);       printf( %d n , dep[y] - dep[x] + 2);       printf( %d  , p);       while (fa[x] != fa[y]) {         printf( %d  , y);         y = fa[y];       }       printf( %d n , y);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using i64 = long long;   const int N = 2e5 + 5;   struct Nod {     i64 sum;     int max_pos, max_pos2;   };   Nod pom[N * 4];   int v[N];   int n, q, update_pos, update_val, current_pos;   i64 query_sum, peak_sum;   static void pom_build(int nod, int l, int r) {     if (l == r) {       pom[nod] = {v[l], l, n + 1};       return;     }     int med = (l + r) / 2;     pom_build(2 * nod, l, med);     pom_build(2 * nod + 1, med + 1, r);     pom[nod].sum = pom[2 * nod].sum + pom[2 * nod + 1].sum;     if (v[pom[2 * nod].max_pos] > v[pom[2 * nod + 1].max_pos]) {       pom[nod].max_pos = pom[2 * nod].max_pos;       pom[nod].max_pos2 = v[pom[2 * nod].max_pos2] > v[pom[2 * nod + 1].max_pos]                               ? pom[2 * n].max_pos2                               : pom[2 * nod + 1].max_pos;     } else {       pom[nod].max_pos = pom[2 * nod + 1].max_pos;       pom[nod].max_pos2 = pom[2 * nod + 1].max_pos2;     }   }   static void internal_update(int nod, int l, int r) {     if (l == r) {       pom[nod].sum = update_val;       return;     }     int med = (l + r) / 2;     if (update_pos <= med)       internal_update(2 * nod, l, med);     else       internal_update(2 * nod + 1, med + 1, r);     pom[nod].sum = pom[2 * nod].sum + pom[2 * nod + 1].sum;     if (v[pom[2 * nod].max_pos] > v[pom[2 * nod + 1].max_pos]) {       pom[nod].max_pos = pom[2 * nod].max_pos;       pom[nod].max_pos2 = v[pom[2 * nod].max_pos2] > v[pom[2 * nod + 1].max_pos]                               ? pom[2 * n].max_pos2                               : pom[2 * nod + 1].max_pos;     } else {       pom[nod].max_pos = pom[2 * nod + 1].max_pos;       pom[nod].max_pos2 = pom[2 * nod + 1].max_pos2;     }   }   static int find_peak(int nod, int l, int r) {     if (l == r) return l;     if (v[pom[1].max_pos] == 0) return n >= 2 ? 2 : -1;     int med = (l + r) / 2;     if (current_pos < med && (pom[2 * nod].max_pos != current_pos                                   ? v[pom[2 * nod].max_pos]                                   : v[pom[2 * nod].max_pos2]) >= query_sum)       return find_peak(2 * nod, l, med);     else if (current_pos < r &&              (pom[2 * nod + 1].max_pos != current_pos                   ? v[pom[2 * nod + 1].max_pos]                   : v[pom[2 * nod + 1].max_pos2]) >= query_sum) {       peak_sum += pom[2 * nod].sum;       return find_peak(2 * nod + 1, med + 1, r);     } else       return -1;   }   static void update(int pos, int val) {     update_val = val;     update_pos = pos;     v[pos] = val;     internal_update(1, 1, n);   }   static int query() {     int pos = 0;     peak_sum = 0;     query_sum = 0;     current_pos = 0;     while ((pos = find_peak(1, 1, n)) != -1) {       query_sum = peak_sum + v[pos];       if (peak_sum == v[pos]) return pos;       current_pos = pos;       peak_sum = 0;     }     return -1;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0), cout.tie(0);     int pos, val;     cin >> n >> q;     for (int i = 1; i <= n; ++i) cin >> v[i];     pom_build(1, 1, n);     while (q--) {       cin >> pos >> val;       update(pos, val);       cout << query() <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename A, typename B>   string to_string(pair<A, B> p);   template <typename A, typename B, typename C>   string to_string(tuple<A, B, C> p);   template <typename A, typename B, typename C, typename D>   string to_string(tuple<A, B, C, D> p);   string to_string(const string& s) { return     + s +    ; }   string to_string(const char* s) { return to_string((string)s); }   string to_string(bool b) { return (b ?  true  :  false ); }   string to_string(vector<bool> v) {     bool first = true;     string res =  { ;     for (int i = 0; i < static_cast<int>(v.size()); i++) {       if (!first) {         res +=  ,  ;       }       first = false;       res += to_string(v[i]);     }     res +=  } ;     return res;   }   template <size_t N>   string to_string(bitset<N> v) {     string res =   ;     for (size_t i = 0; i < N; i++) {       res += static_cast<char>( 0  + v[i]);     }     return res;   }   template <typename A>   string to_string(A v) {     bool first = true;     string res =  { ;     for (const auto& x : v) {       if (!first) {         res +=  ,  ;       }       first = false;       res += to_string(x);     }     res +=  } ;     return res;   }   template <typename A, typename B>   string to_string(pair<A, B> p) {     return  (  + to_string(p.first) +  ,   + to_string(p.second) +  ) ;   }   template <typename A, typename B, typename C>   string to_string(tuple<A, B, C> p) {     return  (  + to_string(get<0>(p)) +  ,   + to_string(get<1>(p)) +  ,   +            to_string(get<2>(p)) +  ) ;   }   template <typename A, typename B, typename C, typename D>   string to_string(tuple<A, B, C, D> p) {     return  (  + to_string(get<0>(p)) +  ,   + to_string(get<1>(p)) +  ,   +            to_string(get<2>(p)) +  ,   + to_string(get<3>(p)) +  ) ;   }   void debug_out() { cerr << endl; }   template <typename Head, typename... Tail>   void debug_out(Head H, Tail... T) {     cerr <<     << to_string(H);     debug_out(T...);   }   const long long mod = 998244353;   long long binpow(long long a, long long n) {     if (n == 0) return 1;     if (n % 2 != 0)       return binpow(a, n - 1) * a;     else {       long long b = binpow(a, n / 2);       return b * b;     }   }   long long gcd(long long a, long long b) {     while (b) {       a %= b;       swap(a, b);     }     return a;   }   long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }   bool check(vector<int> a, vector<int> b) {     for (int i = 0; i < 26; i++)       if (b[i] > a[i]) return false;     return true;   }   void solve() {     int n, m, k;     cin >> n >> m >> k;     if (m < n || k < n)       cout <<  No  << endl;     else       cout <<  Yes  << endl;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t = 1;     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   const long long inf = 1e18;   const long long mod = 1e9 + 7;   long long ExtendedEuclid(long long a, long long b, long long &x, long long &y) {     if (b == 0) {       x = 1;       y = 0;       return a;     }     long long g = ExtendedEuclid(b, a % b, x, y);     long long nx = y, ny = x - a / b * y;     x = nx;     y = ny;     return g;   }   long long modInverse(long long x, long long m) {     long long a, q;     ExtendedEuclid(x, m, a, q);     if (a < 0) {       a = a + (abs(a) + m - 1) / m * m;     }     return a;   }   long long n, m, q;   vector<vector<set<long long>>> adj;   void solve(int testcase) {     cin >> n >> m;     adj = vector<vector<set<long long>>>(n, vector<set<long long>>(2));     for (long long i = 0; i < m; i++) {       long long u, v;       cin >> u >> v;       u--;       v--;       adj[u][(v > u)].insert(v);       adj[v][(u > v)].insert(u);     }     long long ans = 0;     for (long long i = 0; i < n; i++) {       if (adj[i][1].size() == 0) ans++;     }     cin >> q;     while (q--) {       long long op;       cin >> op;       if (op == 3) {         cout << ans <<   n ;       } else if (op == 1) {         long long u, v;         cin >> u >> v;         u--;         v--;         if (u > v) swap(u, v);         if (adj[u][1].size() == 0) ans--;         adj[u][(v > u)].insert(v);         adj[v][(u > v)].insert(u);       } else if (op == 2) {         long long u, v;         cin >> u >> v;         u--;         v--;         if (u > v) swap(u, v);         if (adj[u][1].size() == 1) ans++;         adj[u][(v > u)].erase(adj[u][(v > u)].find(v));         adj[v][(u > v)].erase(adj[v][(u > v)].find(u));       }     }     return;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int t = 0;     solve(t);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   #pragma GCC diagnostic ignored  -Wmissing-declarations    inline int safe_mul(const int x, const int y)       __attribute__((warn_unused_result));   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int n, k;     cin >> n >> k;     int c = (n - k) / 2;     string ans;     for (int i = 0; i < n; ++i) ans.push_back( 0  + (i % (c + 1) < c));     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 123456;   const int mod = 1e9 + 7;   class table {    public:     int id;     int size;   };   class group {    public:     int id;     int size;     int income;   };   bool byIncome(const group &r1, const group &r2) {     return r1.income > r2.income;   }   bool bySize(const table &t1, const table &t2) { return t1.size < t2.size; }   bool canFit(table &t, const group &g) { return t.size < g.size; }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n;     cin >> n;     vector<group> groups(n);     for (int i = 0; i < n; i++) {       groups[i].id = i + 1;       cin >> groups[i].size >> groups[i].income;     }     int k;     cin >> k;     vector<table> tables(k);     for (int i = 0; i < k; i++) {       tables[i].id = i + 1;       cin >> tables[i].size;     }     sort(groups.begin(), groups.end(), byIncome);     sort(tables.begin(), tables.end(), bySize);     int sum = 0;     vector<pair<int, int> > v;     for (int i = 0; i < n; i++) {       group g = groups[i];       vector<table>::iterator t =           lower_bound(tables.begin(), tables.end(), g, canFit);       if (t == tables.end()) {         continue;       }       sum += g.income;       v.push_back(make_pair(g.id, t->id));       tables.erase(t);     }     cout << v.size() <<     << sum << endl;     for (int i = 0; i < v.size(); i++) {       cout << v[i].first <<     << v[i].second << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, limak;     cin >> n;     int len = n - 1;     cin >> limak;     int array[n - 1];     for (int i = 0; i < len; i++) cin >> array[i];     sort(array, array + len);     int cnt = 0;     while (array[len - 1] >= limak) {       cnt++;       limak++;       array[len - 1]--;       sort(array, array + len);     }     cout << cnt << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int tc;     cin >> tc;     while (tc--) {       long long int n, k;       cin >> n >> k;       long long int a[n], m = INT_MIN;       for (long long int i = 0; i < n; i++) {         cin >> a[i];         m = max(m, a[i]);       }       long long int ans[n];       if (k & 1) {         for (long long int i = 0; i < n; i++) cout << m - a[i] <<    ;       } else {         long long int d = INT_MIN;         for (long long int i = 0; i < n; i++) {           a[i] = m - a[i];           d = max(d, a[i]);         }         for (long long int i = 0; i < n; i++) cout << d - a[i] <<    ;       }       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T1, typename T2>   inline ostream& operator<<(ostream& os, const pair<T1, T2>& p) {     return os <<  (  << p.first <<  ,   << p.se <<  ) ;   }   template <typename T1, typename T2>   inline ostream& operator<<(ostream& os, const map<T1, T2>& c) {     bool first = true;     os <<  [ ;     for (typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it) {       if (!first) os <<  ,  ;       os << *it;       first = false;     }     return os <<  ] ;   }   template <typename T>   inline ostream& operator<<(ostream& os, const vector<T>& v) {     bool first = true;     os <<  [ ;     for (long long i = (0); i <= (((int)(v).size()) - 1); i += (1)) {       if (!first) os <<  ,  ;       os << v[i];       first = false;     }     return os <<  ] ;   }   template <typename T>   inline ostream& operator<<(ostream& os, const set<T>& c) {     bool first = true;     os <<  [ ;     for (typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it) {       if (!first) os <<  ,  ;       os << *it;       first = false;     }     return os <<  ] ;   }   const int dx4[] = {-1, 0, 0, +1};   const int dx8[] = {-1, -1, -1, 0, 0, +1, +1, +1};   const int dy4[] = {0, -1, +1, 0};   const int dy8[] = {-1, 0, +1, -1, +1, -1, 0, +1};   unsigned long long m;   bool first;   vector<int> r, l;   int main() {     int(n);     scanf( %d , &(n));     cin >> m;     cerr << ( m ) <<   =   << (m) << endl;     m--;     r.push_back(n);     n--;     for (long long i = (0); i <= (n - 1); i += (1))       if (m & (1LL << i))         r.push_back(n - i);       else         l.push_back(n - i);     bool first = true;     for (long long i = (((int)(l).size()) - 1); i >= (0); i -= (1)) {       if (!first) cout <<    ;       first = false;       cout << l[i];     }     for (long long i = (0); i <= (((int)(r).size()) - 1); i += (1)) {       if (!first) cout <<    ;       first = false;       cout << r[i];     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     scanf( %d , &n);     scanf( %d , &m);     int mat[n + 1][m + 1];     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         scanf( %d , &mat[i][j]);       }     }     vector<int> dp(n + 1, 0);     for (int j = 1; j <= m; j++) {       vector<int> dp2(n + 1, 0);       for (int k = n - 1; k >= 1; k--) {         if (mat[k][j] <= mat[k + 1][j]) dp2[k] = 1 + dp2[k + 1];       }       for (int i = 1; i <= n; i++) dp[i] = max(dp[i], dp2[i]);     }     int q, l, r;     scanf( %d , &q);     while (q--) {       scanf( %d , &l);       scanf( %d , &r);       if (l + dp[l] >= r)         printf( Yes );       else         printf( No );       printf(  n );     }   }


#include <bits/stdc++.h>   using namespace std;   inline int max(int a, int b) { return a > b ? a : b; }   map<int, int> mp;   int a[200005], id;   inline int read(int x) {     if (mp.count(x) > 0) return mp[x];     mp[x] = ++id;     return id;   }   int main() {     int n;     scanf( %d , &n);     int x;     for (int i = 1; i <= n; ++i) {       scanf( %d , &x);       ++a[read(x)];     }     sort(a + 1, a + 1 + id);     int ans = 0, last, now, pos;     for (int i = 1; i <= n; ++i) {       last = 1;       now = 0;       for (int k = i; k <= n; k <<= 1) {         pos = lower_bound(a + last, a + id + 1, k) - a;         if (pos > id) break;         now += k;         last = pos + 1;       }       ans = max(ans, now);     }     printf( %d n , ans);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string a, b;     cin >> a >> b;     int p = max(a.size(), b.size());     cout << (a == b ? -1 : p) << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b;     cin >> a >> b;     int ans = b / a;     if (b % a) {       cout <<  -1  << endl;       return 0;     }     int cnt = 0;     while (ans % 2 == 0) {       ans = ans / 2;       cnt++;     }     while (ans % 3 == 0) {       ans = ans / 3;       cnt++;     }     if (ans == 1)       cout << cnt << endl;     else       cout <<  -1  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 1e9;   const int MOD = 1e9 + 7;   const int N = 2e2 + 10, M = 1e6 + 10;   const int alp = 10;   vector<pair<int, int> > pos;   pair<int, int> s[M];   int n, m, q, a[N][N], f[N][N], h[N][N], len[N][N], dx[10], dy[10], deg[N][N],       g[M];   string str;   bool check(int x, int y) { return x > 0 && x <= n && y > 0 && y <= m; }   void DFS(int sx, int sy) {     int top = 1, spe = 0;     int v = 0;     s[1] = pair<int, int>(sx, sy);     while (!spe) {       int cx = s[top].first, cy = s[top].second;       h[cx][cy] = top;       int nx = cx + dx[a[cx][cy]], ny = cy + dy[a[cx][cy]];       if (!check(nx, ny))         spe = top;       else {         if (f[nx][ny]) {           spe = top + 1;           v = f[nx][ny];           s[top + 1] = pair<int, int>(nx, ny);           break;         }         if (!h[nx][ny])           s[++top] = pair<int, int>(nx, ny);         else           spe = h[nx][ny];       }     }     for (auto i = spe; i <= top; i++) v |= (1 << (a[s[i].first][s[i].second]));     for (auto i = 1; i <= top; i++) f[s[i].first][s[i].second] = v;     for (auto i = spe - 1; i >= 1; i--)       len[s[i].first][s[i].second] = len[s[i + 1].first][s[i + 1].second] + 1;   }   void prepare() {     cin >> n >> m >> q;     for (auto i = 1; i <= n; i++) {       cin >> str;       for (auto j = 1; j <= m; j++) a[i][j] = str[j - 1] -  0 ;     }     for (auto i = 0; i < alp; i++) cin >> dx[i] >> dy[i];     for (auto i = 1; i <= n; i++)       for (auto j = 1; j <= m; j++) {         int nx = i + dx[a[i][j]], ny = j + dy[a[i][j]];         if (check(nx, ny)) deg[nx][ny]++;       }     for (auto i = 1; i <= n; i++)       for (auto j = 1; j <= m; j++)         if (!deg[i][j]) {           DFS(i, j);           pos.push_back(pair<int, int>(i, j));         }     for (auto i = 1; i <= n; i++)       for (auto j = 1; j <= m; j++)         if (!f[i][j]) {           DFS(i, j);           pos.push_back(pair<int, int>(i, j));         }   }   string solve() {     int n1 = str.length();     g[n1] = 0;     for (auto i = n1 - 1; i >= 0; i--) g[i] = g[i + 1] | (1 << (str[i] -  0 ));     for (auto x : pos) {       int cur = 0;       pair<int, int> cx = x;       while (cur < n1 && len[cx.first][cx.second]) {         int v = a[cx.first][cx.second];         if (str[cur] -  0  == v) cur++;         int nx = cx.first + dx[v], ny = cx.second + dy[v];         cx = pair<int, int>(nx, ny);       }       if ((g[cur] & f[cx.first][cx.second]) == g[cur]) return  YES ;     }     return  NO ;   }   int main() {     prepare();     while (q--) {       cin >> str;       cout << solve() <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int i, j, n, arr[26];     string s;     memset(&arr, -1, sizeof(arr));     cin >> s;     int l = s.length();     if (l < 26) {       cout << -1;       return 0;     }     i = 0;     j = 0;     while (j < l) {       if (j - i == 26) break;       if (s[j] ==  ? )         j++;       else if (arr[s[j] -  A ] != -1) {         int temp = i;         i = arr[s[j] -  A ] + 1;         for (; temp < i; temp++)           if (s[temp] !=  ? ) arr[s[temp] -  A ] = -1;       } else if (s[j] !=  ?  && arr[s[j] -  A ] == -1) {         arr[s[j] -  A ] = j;         j++;       }     }     if (j - i == 26) {       int temp = i, temp2;       for (temp2 = 0; temp2 < 26; temp2++) {         if (arr[temp2] == -1) {           while (s[temp] !=  ?  && temp < j) temp++;           s[temp] =  A  + temp2;         }       }       while (i--) {         if (s[i] ==  ? ) s[i] = s[i + 26];       }       while (j < l) {         if (s[j] ==  ? ) s[j] = s[j - 26];         j++;       }       cout << s;     } else       cout << -1;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   double a, v, l, d, w, ans, L, t1, t2, v_2;   int main() {     scanf( %lf%lf%lf%lf%lf , &a, &v, &l, &d, &w);     L = l - d;     double A = w * w;     if (v <= w || A >= 2 * a * d) {       if (2 * a * l >= v * v) {         ans = v / a;         ans += (l - v * v / 2 / a) / v;       } else         ans = sqrt(2 * l / a);     } else {       double V = sqrt((2 * a * d + w * w) / 2);       if (V >= v) {         t1 = v / a + (v - w) / a;         t1 += (d - (2 * v * v - w * w) / 2 / a) / v;       } else {         t1 = V / a + (V - w) / a;       }       if (w * w + 2 * a * L <= v * v) {         v_2 = sqrt(w * w + 2 * a * L);         t2 = (v_2 - w) / a;       } else {         t2 = (v - w) / a;         t2 += (L - (v * v - w * w) / (2 * a)) / v;       }       ans = t1 + t2;     }     printf( %.12lf , ans);     return 0;   }


// shirley smokes weed   #include <bits/stdc++.h>   #define sz(v) ((int)(v).size())   #define all(v) (v).begin(), (v).end()   using namespace std;   using lint = long long;   using pi = pair<int, int>;   const int MAXN = 400;      int n, m, s[MAXN], e[MAXN], x[MAXN];   int dp[1 << 18], indep[1 << 18], w[1 << 18], tk[1 << 18];      int main(){    scanf( %d %d ,&n,&m);    for(int i=0; i<m; i++){     scanf( %d %d %d ,&s[i],&e[i],&x[i]);     s[i]--; e[i]--;    }    for(int i=1; i<(1<<n); i++){     indep[i] = 1;     for(int j=0; j<m; j++){      int b1 = (i >> s[j]) & 1;      int b2 = (i >> e[j]) & 1;      if(b1 && b2) indep[i] = 0;      if(b1 == b2) continue;      if(b1 == 1 && b2 == 0) w[i] = 1e9;      else w[i] += x[j];     }    }    dp[0] = 0;    for(int i=1; i<(1<<n); i++){     dp[i] = 1e9;     if(w[i] > 1e8) continue;     for(int j=i; j; j=(j-1)&i){      if(indep[j] && dp[i] > dp[i ^ j]){       dp[i] = dp[i ^ j];       tk[i] = j;      }     }     dp[i] += w[i];    }    vector<int> a(n);    for(int i = (1 << n) - 1; i; i ^= tk[i]){     for(int j = 0; j < n; j++){      if((i >> j) & 1) a[j]++;     }    }    for(int i=0; i<n; i++) printf( %d  , n + 1 - a[i]);   }


#include <bits/stdc++.h>   using namespace std;   int N, M;   char A[2020][2020];   int B[2020][2020];   int D[2020][2020];   queue<int> qx;   queue<int> qy;   int dx[4] = {1, 0, -1, 0};   int dy[4] = {0, 1, 0, -1};   long long ans;   int main() {     scanf( %d%d , &N, &M);     for (int i = 1; i <= N; i++) {       scanf( %s , A[i] + 1);     }     ans = N * M;     for (int i = 2; i < N; i++) {       for (int j = 2; j < M; j++) {         B[i][j] = 1;         for (int d = 0; d < 4; d++) {           if (A[i][j] != A[i + dx[d]][j + dy[d]]) B[i][j] = 0;         }       }     }     for (int i = 1; i <= N; i++) {       for (int j = 1; j <= M; j++) {         if (B[i][j]) {           int c = 0;           for (int d = 0; d < 4; d++) {             c += B[i + dx[d]][j + dy[d]];           }           if (c < 4) {             D[i][j] = 1;             qx.push(i);             qy.push(j);           }         }       }     }     while (qx.size()) {       int x = qx.front();       qx.pop();       int y = qy.front();       qy.pop();       for (int i = 0; i < 4; i++) {         int nx = x + dx[i], ny = y + dy[i];         if (!B[nx][ny] || D[nx][ny]) continue;         D[nx][ny] = D[x][y] + 1;         qx.push(nx);         qy.push(ny);       }     }     for (int i = 1; i <= N; i++)       for (int j = 1; j <= M; j++) ans += D[i][j];     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<vector<int> > lang(105);   vector<vector<int> > emp(105);   vector<int> visited(105, false);   int n, m;   void dfs(int i) {     if (!visited[i]) {       visited[i] = true;       int n_lang = emp[i].size();       for (int k = 0; k < n_lang; k++) {         int lg = emp[i][k];         int n_emp = lang[lg].size();         for (int x = 0; x < n_emp; x++) {           dfs(lang[lg][x]);         }       }     }   }   int main() {     cin >> n >> m;     for (int i = 0; i < n; i++) {       int n_l;       cin >> n_l;       for (int j = 0; j < n_l; j++) {         int lg;         cin >> lg;         lg--;         lang[lg].push_back(i);         emp[i].push_back(lg);       }     }     bool flag = false;     for (int i = 0; i < m; i++) {       if (lang[i].size() != 0) {         flag = true;         break;       }     }     if (flag == false) {       cout << n << endl;       return 0;     }     int cc = 0;     for (int i = 0; i < n; i++) {       if (!visited[i]) {         cc++;         dfs(i);       }     }     cout << cc - 1 << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 505;   int x[N];   int n, m;   int main() {     cin >> n >> m;     for (int i = 0; i < n; i++) cin >> x[i];     double ret = 0;     while (m--) {       int u, v, c;       cin >> u >> v >> c;       u--, v--;       ret = max(1.0 * (x[u] + x[v]) / c, ret);     }     cout << fixed << setprecision(12) << ret <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, a[205], cnt[105], used[105], ans[205], sz[3];   int push(int x) {     if (x) {       sz[x]++;       return x;     } else if (sz[1] < sz[2]) {       sz[1]++;       return 1;     } else {       sz[2]++;       return 2;     }   }   int main() {     cin >> n;     for (int i = 1; i <= n * 2; i++) {       cin >> a[i];       cnt[a[i]]++;     }     for (int i = 1; i <= n * 2; i++)       if (cnt[a[i]] > 1 && used[a[i]] < 2) ans[i] = push(++used[a[i]]);     for (int i = 1; i <= n * 2; i++)       if (cnt[a[i]] == 1) ans[i] = push(0);     cout << sz[1] * sz[2] <<   n ;     for (int i = 1; i <= n * 2; i++) {       if (!ans[i]) ans[i] = push(0);       cout << ans[i] <<    ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 5;   int A[maxn][2];   bool vis[maxn];   vector<int> v[maxn];   int main() {     int T;     cin >> T;     while (T--) {       int n;       cin >> n;       for (int i = 1; i <= n; i++) {         v[i].clear();       }       for (int i = 1; i <= n; i++) {         scanf( %d , &A[i][0]);         v[A[i][0]].push_back(i);       }       for (int i = 1; i <= n; i++) {         scanf( %d , &A[i][1]);         v[A[i][1]].push_back(i);       }       int bad = 0;       for (int i = 1; i <= n; i++) {         vis[i] = 0;         if (v[i].size() != 2) {           bad = 1;           break;         }       }       if (bad) {         printf( -1 n );         continue;       }       vector<int> ans;       ans.clear();       for (int i = 1; i <= n; i++) {         if (A[i][0] == A[i][1]) {           vis[i] = 1;           continue;         }         if (vis[i]) {           continue;         }         int now = i;         vector<int> v1, v2;         int st = now;         v1.push_back(now);         while (!vis[now]) {           vis[now] = 1;           int b = A[now][1];           int nex;           if (v[b][0] == now)             nex = v[b][1];           else             nex = v[b][0];           now = nex;           if (now == st) break;           if (A[now][0] == b) {             v1.push_back(now);           } else {             v2.push_back(now);             swap(A[now][0], A[now][1]);           }         }         if (v1.size() < v2.size()) {           for (auto j : v1) {             ans.push_back(j);           }         } else {           for (auto j : v2) {             ans.push_back(j);           }         }       }       printf( %d n , ans.size());       for (auto i : ans) {         printf( %d  , i);       }       puts(  );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int parent[100010];   int Rank[100010];   int cnt;   int st[100010];   int st_cnt = 0;   void rollback(int id) {     if (id < 0)       Rank[-id - 1]--;     else {       parent[id] = id;       cnt++;     }   }   int find(int cur) {     if (parent[cur] == cur) return cur;     return find(parent[cur]);   }   void Union(int x, int y, bool revert = false) {     int xroot = find(x);     int yroot = find(y);     if (xroot == yroot) return;     cnt--;     if (Rank[xroot] < Rank[yroot]) swap(xroot, yroot);     if (revert) st[st_cnt++] = yroot;     parent[yroot] = xroot;     if (Rank[yroot] == Rank[xroot]) {       Rank[xroot]++;       if (revert) st[st_cnt++] = -xroot - 1;     }   }   void init(int n) {     st_cnt = 0;     cnt = n;     for (int i = 0; i <= n; ++i) {       Rank[i] = 0;       parent[i] = i;     }   }   int x[100010], y[100010], Out[100010];   vector<int> List[600][600];   vector<int> befor[100010], after[100010];   int main() {     int n, k, m, q, i, j;     scanf( %d , &n);     scanf( %d , &k);     scanf( %d , &m);     while (m--) {       int x, y;       scanf( %d , &x);       scanf( %d , &y);       --x;       --y;       if (x < y) {         after[x].push_back(y);         befor[y].push_back(x);       } else {         after[y].push_back(x);         befor[x].push_back(y);       }     }     init(n);     scanf( %d , &q);     for (i = 0; i < q; i++) {       scanf( %d , &x[i]);       scanf( %d , &y[i]);       --x[i];       --y[i];       if (x[i] >= n) {         Out[i] = 0;         continue;       }       if (y[i] >= n) y[i] = n - 1;       int sb = x[i] / 500;       if (sb * 500 != x[i]) sb++;       int eb = y[i] / 500;       if ((eb + 1) * 500 != y[i] + 1) eb--;       if (eb < sb) {         for (j = x[i]; j <= y[i]; j++)           for (auto z : befor[j])             if (z >= x[i]) Union(j, z, true);         Out[i] = cnt;         while (st_cnt) {           rollback(st[--st_cnt]);         }       } else         List[sb][eb].push_back(i);     }     for (i = 0; i * 500 < n; i++) {       init(n);       for (j = i; (j + 1) * 500 <= n; j++) {         for (int k = j * 500; k < (j + 1) * 500; k++)           for (auto x : befor[k])             if (x >= i * 500) Union(k, x);         for (int k = 0; k < List[i][j].size(); k++) {           for (int l = x[List[i][j][k]]; l < i * 500; l++)             for (auto x : after[l])               if (x < (j + 1) * 500) Union(l, x, true);           for (int l = (j + 1) * 500; l <= y[List[i][j][k]]; l++)             for (auto z : befor[l])               if (z >= x[List[i][j][k]]) Union(l, z, true);           Out[List[i][j][k]] = cnt;           while (st_cnt) {             rollback(st[--st_cnt]);           }         }       }     }     for (i = 0; i < q; i++) printf( %d n , Out[i] - (n - (y[i] - x[i] + 1)));   }


#include <bits/stdc++.h>   using namespace std;   namespace input {   const int InputBufferSize = (1 << 24) + 5;   char buffer[InputBufferSize], *s, *eof;   inline void init() {     assert(stdin != NULL);     s = buffer;     eof = s + fread(buffer, 1, InputBufferSize, stdin);   }   inline bool read(int& x) {     x = 0;     int flag = 1;     while (!isdigit(*s) && *s !=  - ) s++;     if (eof <= s) return false;     if (*s ==  - ) flag = -1, s++;     while (isdigit(*s)) x = x * 10 + *s++ -  0 ;     x *= flag;     return true;   }   inline bool read(char* str) {     *str = 0;     while (isspace(*s)) s++;     if (eof < s) return false;     while (!isspace(*s)) *str = 0, *str = *s, str++, s++;     *str = 0;     return true;   }   }  // namespace input   using namespace input;   int const p = 1e9 + 7;   int pr[305], cnt, a[400005], tmp[65], id[305], c[305], tree[1600005],       tag[1600005];   long long b[400005], tree2[1600005], tag2[1600005];   bool flag[305];   long long res(int x) {     memset(tmp, 0, sizeof(tmp));     long long res = 0;     for (int i = 0; i <= 6; i++)       while (!(x % pr[i])) x /= pr[i], res |= (1ll << i);     if (x != 1) res |= (1ll << id[x]);     return res;   }   int pw(int x, int y) {     int res = 1;     while (y) {       if (y & 1) res = 1ll * res * x % p;       x = 1ll * x * x % p;       y >>= 1;     }     return res;   }   void build(int l, int r, int x) {     if (l == r) {       tree[x] = a[l];       tag[x] = 1;       return;     }     int mid = (l + r) >> 1;     build(l, mid, x * 2), build(mid + 1, r, x * 2 + 1);     tree[x] = 1ll * tree[x * 2] * tree[x * 2 + 1] % p;     tag[x] = 1;   }   void build2(int l, int r, int x) {     if (l == r) {       tree2[x] = b[l];       return;     }     int mid = (l + r) >> 1;     build2(l, mid, x * 2), build2(mid + 1, r, x * 2 + 1);     tree2[x] = (tree2[x * 2] | tree2[x * 2 + 1]);   }   void pushdown(int l, int r, int x) {     if (tag[x] == 1) return;     tree[x] = 1ll * tree[x] * pw(tag[x], r - l + 1) % p;     if (l != r)       tag[x * 2] = 1ll * tag[x * 2] * tag[x] % p,               tag[x * 2 + 1] = 1ll * tag[x * 2 + 1] * tag[x] % p;     tag[x] = 1;   }   void modify(int l, int r, int x, int a, int b, int c) {     if (l >= a && r <= b) {       tag[x] = 1ll * tag[x] * c % p;       return;     }     int mid = (l + r) >> 1;     if (a <= mid) modify(l, mid, x * 2, a, b, c);     if (b > mid) modify(mid + 1, r, x * 2 + 1, a, b, c);     pushdown(l, mid, x * 2), pushdown(mid + 1, r, x * 2 + 1);     tree[x] = 1ll * tree[x * 2] * tree[x * 2 + 1] % p;   }   void pushdown2(int l, int r, int x) {     if (!tag2[x]) return;     tree2[x] |= tag2[x];     if (l != r) tag2[x * 2] |= tag2[x], tag2[x * 2 + 1] |= tag2[x];     tag2[x] = 0;   }   void modify2(int l, int r, int x, int a, int b, long long c) {     if (l >= a && r <= b) {       tag2[x] = (tag2[x] | c);       return;     }     int mid = (l + r) >> 1;     if (a <= mid) modify2(l, mid, x * 2, a, b, c);     if (b > mid) modify2(mid + 1, r, x * 2 + 1, a, b, c);     pushdown2(l, mid, x * 2), pushdown2(mid + 1, r, x * 2 + 1);     tree2[x] = (tree2[x * 2] | tree2[x * 2 + 1]);   }   int ask(int l, int r, int x, int a, int b) {     pushdown(l, r, x);     if (l >= a && r <= b) return tree[x];     int mid = (l + r) >> 1, res = 1;     if (a <= mid) res = ask(l, mid, x * 2, a, b);     if (b > mid) res = 1ll * res * ask(mid + 1, r, x * 2 + 1, a, b) % p;     return res;   }   long long ask2(int l, int r, int x, int a, int b) {     pushdown2(l, r, x);     if (l >= a && r <= b) return tree2[x];     int mid = (l + r) >> 1;     long long res = 0;     if (a <= mid) res = ask2(l, mid, x * 2, a, b);     if (b > mid) res = (res | ask2(mid + 1, r, x * 2 + 1, a, b));     return res;   }   char op[15];   int main() {     for (int i = 2; i <= 300; i++) {       if (!flag[i])         pr[cnt] = i, id[i] = cnt, c[cnt] = 1ll * (i - 1) * pw(i, p - 2) % p,         cnt++;       for (int j = i * 2; j <= 300; j += i) flag[j] = 1;     }     init();     int n, q, l, r, x;     long long y;     read(n), read(q);     for (int i = 1; i <= n; i++) {       read(a[i]);       b[i] = res(a[i]);     }     build(1, n, 1), build2(1, n, 1);     while (q--) {       read(op);       if (op[0] ==  M ) {         read(l), read(r), read(x);         y = res(x);         modify(1, n, 1, l, r, x), modify2(1, n, 1, l, r, y);       } else {         read(l), read(r);         x = ask(1, n, 1, l, r), y = ask2(1, n, 1, l, r);         for (int j = 0; j <= 61; j++)           if (y & (1ll << j)) x = 1ll * x * c[j] % p;         printf( %d n , x);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long OO = (long long)1e9 + 7;   using namespace std;   long long inv(long long a, long long b) {     return 1 < a ? b - inv(b % a, a) * b / a : 1;   }   long long Pow(long long B, long long P) {     long long R = 1;     while (P > 0) {       if (P & 1) R = (R * B);       P /= 2;       B = (B * B);     }     return R;   }   long long GCD(long long a, long long b) {     while (b) {       b ^= a ^= b ^= a %= b;     }     return a;   }   long long LCM(long long a, long long b) { return (a / GCD(a, b) * b); }   long long BigMod(long long B, long long P, long long M) {     long long R = 1;     while (P > 0) {       if (P & 1) {         R = (R * B) % M;       }       P /= 2;       B = (B * B) % M;     }     return (long long)R;   }   vector<long long> primes;   void factorization(long long n) {     for (long long i = 2; i * i <= n; ++i)       while (n % i == 0) primes.push_back(i), n /= i;     if (n > 1) primes.push_back(n);   }   int main() {     ios::sync_with_stdio(0);     long long n;     cin >> n;     factorization(n);     if (primes.size() == 2) {       cout << 2;     } else {       if (n == 1 || primes.size() == 1) {         cout <<  1 n0 ;       } else {         cout << 1 << endl;         cout << primes[0] * primes[1];       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<pair<int, pair<int, int> > > V;   const int maxn = 1010;   int n, N;   int a[maxn][maxn], r[maxn], c[maxn];   void sr(int x, int y) {     if (x == y) return;     V.push_back(make_pair(1, pair<int, int>(x, y)));     for (int i = 1; i <= N; ++i) swap(a[x][i], a[y][i]);     swap(r[x], r[y]);   }   void sc(int x, int y) {     if (x == y) return;     V.push_back(make_pair(2, pair<int, int>(x, y)));     for (int i = 1; i <= N; ++i) swap(a[i][x], a[i][y]);     swap(c[x], c[y]);   }   int main() {     int x, y, i, j;     scanf( %d , &n), N = n;     for (i = 1; i < n; ++i) {       scanf( %d%d , &x, &y);       a[x][y] = 1, ++r[x], ++c[y];     }     while (n > 1) {       for (i = 1; i <= n; ++i) {         for (j = i; j <= n; ++j)           if (a[i][j]) break;         if (a[i][j]) break;       }       if (!a[i][j]) break;       sr(i, n), sc(j, 1);       for (i = 1; i <= n; ++i)         if (!c[i]) break;       sc(i, n);       for (i = 1; i <= n; ++i) c[i] -= a[n][i], r[i] -= a[i][n];       --n;     }     printf( %d n , V.size());     for (typeof(V.end()) i = V.begin(); i != V.end(); ++i)       printf( %d %d %d n , i->first, (i->second).first, (i->second).second);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mxn = 100000;   long long n, k;   int a[2][mxn], first[mxn];   vector<pair<int, int> > v;   void sol() {     cout << k <<   n ;     for (pair<int, int> i : v) cout << (i.first + 1) <<     << i.second <<   n ;     exit(0);   }   void add(int x, int y) {     if (a[0][x + 1] + y < 0 || a[0][x + 1] + y > 9) add(x + 1, -y);     if (v.size() == mxn) sol();     a[0][x] += y, a[0][x + 1] += y;     v.push_back({x, y});   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n;     for (int i = 0; i < 2; i++)       for (int j = 0; j < n; j++) {         char c;         cin >> c;         a[i][j] = c -  0 ;       }     memcpy(first, a[0], sizeof(first));     for (int i = 0; i < n - 1; i++) {       int x = a[1][i] - first[i];       k += abs(x), first[i] += x, first[i + 1] += x;     }     if (a[1][n - 1] != first[n - 1]) k = -1, sol();     for (int i = 0; i < n - 1; i++)       while (a[0][i] != a[1][i]) {         add(i, 2 * (a[0][i] < a[1][i]) - 1);       }     sol();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool dbg = 0;   int main() {     int N, K;     cin >> N >> K;     long long Count = 0;     int x, y;     for (int n = 0; n < N; ++n) {       scanf( %d%d , &x, &y);       Count += (long long)(y - x + 1);     }     cout << (K - Count % K) % K << endl;     return 0;   }


#include <bits/stdc++.h>   struct Swap {     int i;     int j;   };   std::vector<Swap> swaps;   void solve4(int a, int b, int c, int d, bool firstLast) {     if (firstLast) swaps.push_back(Swap{a, b});     swaps.push_back(Swap{a, c});     swaps.push_back(Swap{b, d});     swaps.push_back(Swap{a, d});     swaps.push_back(Swap{b, c});     if (firstLast) swaps.push_back(Swap{c, d});   }   void solve5(int a, int b, int c, int d, int e, bool firstLast) {     if (firstLast) {       swaps.push_back(Swap{a, b});       swaps.push_back(Swap{a, c});       swaps.push_back(Swap{b, c});     }     swaps.push_back(Swap{b, e});     swaps.push_back(Swap{a, d});     swaps.push_back(Swap{c, e});     swaps.push_back(Swap{c, d});     swaps.push_back(Swap{a, e});     swaps.push_back(Swap{b, d});     if (firstLast) swaps.push_back(Swap{d, e});   }   int main(void) {     int n;     scanf( %d , &n);     if (n == 1) {       printf( YES n );     } else if (n % 4 <= 1) {       if (n % 4 == 0) {         int k = n / 4;         for (int i = 0; i < k; i++) {           solve4(4 * i + 1, 4 * i + 2, 4 * i + 3, 4 * i + 4, true);         }         for (int i = 0; i + 1 < k; i++) {           for (int j = i + 1; j < k; j++) {             solve4(4 * i + 1, 4 * i + 2, 4 * j + 1, 4 * j + 2, false);             solve4(4 * i + 1, 4 * i + 2, 4 * j + 3, 4 * j + 4, false);             solve4(4 * i + 3, 4 * i + 4, 4 * j + 1, 4 * j + 2, false);             solve4(4 * i + 3, 4 * i + 4, 4 * j + 3, 4 * j + 4, false);           }         }       } else {         int k = (n - 5) / 4;         solve5(1, 2, 3, 4, 5, true);         for (int i = 0; i < k; i++) {           solve4(5 + 4 * i + 1, 5 + 4 * i + 2, 5 + 4 * i + 3, 5 + 4 * i + 4,                  true);         }         for (int i = 0; i < k; i++) {           solve5(1, 2, 3, 5 + 4 * i + 1, 5 + 4 * i + 2, false);           solve5(1, 2, 3, 5 + 4 * i + 3, 5 + 4 * i + 4, false);           solve4(4, 5, 5 + 4 * i + 1, 5 + 4 * i + 2, false);           solve4(4, 5, 5 + 4 * i + 3, 5 + 4 * i + 4, false);         }         for (int i = 0; i + 1 < k; i++) {           for (int j = i + 1; j < k; j++) {             solve4(5 + 4 * i + 1, 5 + 4 * i + 2, 5 + 4 * j + 1, 5 + 4 * j + 2,                    false);             solve4(5 + 4 * i + 1, 5 + 4 * i + 2, 5 + 4 * j + 3, 5 + 4 * j + 4,                    false);             solve4(5 + 4 * i + 3, 5 + 4 * i + 4, 5 + 4 * j + 1, 5 + 4 * j + 2,                    false);             solve4(5 + 4 * i + 3, 5 + 4 * i + 4, 5 + 4 * j + 3, 5 + 4 * j + 4,                    false);           }         }       }       printf( YES n );       for (Swap swap : swaps) printf( %d %d n , swap.i, swap.j);       printf(  n );     } else {       printf( NO n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, k, res, xx, yy;   int main() {     scanf( %d%d%d , &n, &m, &k);     while (k--) {       scanf( %d%d , &xx, &yy);       int mn = xx - 1;       mn = min(mn, n - xx);       mn = min(mn, yy - 1);       mn = min(mn, m - yy);       res = max(res, (int)(mn <= 4));     }     if (res)       printf( YES );     else       printf( NO );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int N, ap[3009], dp[3009], how[3009];   char sir[3009];   bool cons(char c) {     if (c ==  a  || c ==  e  || c ==  i  || c ==  o  || c ==  u ) return 0;     return 1;   }   int main() {     gets(sir + 1), N = strlen(sir + 1);     dp[0] = 0;     for (int i = 1; i <= N; i++) {       char mini = sir[i], maxi = sir[i];       int L = cons(sir[i]);       dp[i] = dp[i - 1] + 1, how[i] = i;       for (int j = i - 1; j >= 1; j--) {         if (cons(sir[j]) == 0)           L = 0;         else {           if (L == 0)             mini = maxi = sir[j], L = 1;           else             L++, mini = min(mini, sir[j]), maxi = max(maxi, sir[j]);         }         if (L >= 3 && mini < maxi) break;         if (dp[j - 1] + 1 < dp[i]) dp[i] = dp[j - 1] + 1, how[i] = j;       }     }     int pos = N;     while (pos > 0) pos = how[pos] - 1, ap[pos] = 1;     for (int i = 1; i <= N; i++) {       printf( %c , sir[i]);       if (ap[i]) printf(   );     }     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, x, a[5005], uc, sum, mux = 0;   vector<long long> myvec;   int main() {     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i];     for (int i = 1; i <= n; i++) {       sum = 0;       for (int j = i; j <= n; j++) {         sum += a[j];         if ((j - i + 1) * 100 < sum) mux = max(mux, (long long)(j - i + 1));       }     }     cout << mux;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int N, K;   void init() { scanf( %d%d , &N, &K); }   void work() {     if (K == 1 && N > 1) {       printf( -1 );       return;     }     if (K == 1 && N == 1) {       printf( a );       return;     }     if (N < K) {       printf( -1 );       return;     }     if (N == K) {       for (int i = 1; i <= K; i++) printf( %c ,  a  + i - 1);       return;     }     for (int i = 1; i <= N - K + 2; i++) {       if (i & 1)         printf( a );       else         printf( b );     }     char j =  c ;     for (int i = N - K + 3; i <= N; i++) printf( %c , j++);   }   int main() {     init();     work();     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long p = 998244353;   int gcd(int a, int b, int& x, int& y) {     if (a == 1) {       x = 1;       y = 0;       return 1;     }     if (b == 1) {       x = 0;       y = 1;       return 1;     }     if (b == 0) {       x = 1;       y = 0;       return a;     }     int res = gcd(b, a % b, y, x);     y = y - x * (a / b);     return res;   }   long long Denominator(long long a) {     int x = 0, y = 0;     if (a == 0) return 1;     gcd(p, a, x, y);     return (y + p) % p;   }   int main() {     long long n, res = 1;     cin >> n;     for (long long i = 1; i <= n; ++i) {       res *= (n + i);       res = res % p;       res *= Denominator(i);       res = res % p;     }     long long sum = 0;     vector<long long> a(2 * n);     for (int i = 0; i < 2 * n; ++i) {       cin >> a[i];     }     sort(a.begin(), a.end());     for (int i = 0; i < n; ++i) {       sum += a[2 * n - 1 - i] - a[i];     }     cout << res * (sum % p) % p << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct pp {     long long nu, we;   } c;   struct Info {     long long l, r, ta, nu;     pp a;   } a[1000010];   long long b[100010], n, ansn, m, l, r, opt, x, sum;   pp mi(pp a, pp b) {     if (a.nu < b.nu) return b;     return a;   }   pp ga(long long nu, long long l, long long r) {     if (a[nu].l == l && a[nu].r == r) return a[nu].a;     long long mid = (a[nu].l + a[nu].r) / 2;     pp u;     u.nu = -1e18;     if (l <= mid) u = mi(u, ga(nu * 2, l, min(mid, r)));     if (r > mid) u = mi(u, ga(nu * 2 + 1, max(mid + 1, l), r));     return u;   }   void build(long long x, long long l, long long r) {     a[x].l = l;     a[x].r = r;     a[x].ta = 0;     if (l == r) {       a[x].nu = b[l];       a[x].a.we = l;       if (l != 0 && l != n + 1) {         a[x].a.nu = b[l] - max(b[l + 1], b[l - 1]);       } else         a[x].a.nu = -1e18;     } else {       build(x * 2, l, (l + r) / 2);       build(x * 2 + 1, (l + r) / 2 + 1, r);       if (a[x * 2].a.nu >= a[x * 2 + 1].a.nu)         a[x].a = a[x * 2].a;       else         a[x].a = a[x * 2 + 1].a;     }   }   void ya(long long x) {     if (a[x].ta != 0 && a[x].l != a[x].r) {       a[x * 2].ta += a[x].ta;       a[x * 2 + 1].ta += a[x].ta;       a[x].ta = 0;     }   }   long long que(long long nu, long long x) {     if (a[nu].l == a[nu].r) {       a[nu].nu += a[nu].ta;       a[nu].ta = 0;       return a[nu].nu;     } else {       ya(nu);       if (x <= (a[nu].l + a[nu].r) / 2) return que(nu * 2, x);       return que(nu * 2 + 1, x);     }   }   void add(long long nu, long long l, long long r, long long x) {     if (a[nu].l == l && a[nu].r == r) {       a[nu].ta += x;       return;     }     long long mid = (a[nu].l + a[nu].r) / 2;     if (l <= mid) add(nu * 2, l, min(mid, r), x);     if (r > mid) add(nu * 2 + 1, max(mid + 1, l), r, x);   }   void chang(long long nu, long long x, long long y) {     if (a[nu].l == a[nu].r) {       a[nu].a.nu = y;     } else {       if (x <= (a[nu].l + a[nu].r) / 2)         chang(nu * 2, x, y);       else         chang(nu * 2 + 1, x, y);       if (a[nu * 2].a.nu >= a[nu * 2 + 1].a.nu)         a[nu].a = a[nu * 2].a;       else         a[nu].a = a[nu * 2 + 1].a;     }   }   long long cou(pp a) {     return ansn - abs(que(1, a.we - 1) - que(1, a.we)) -            abs(que(1, a.we + 1) - que(1, a.we)) +            abs(que(1, a.we - 1) - que(1, a.we) - x) +            abs(que(1, a.we + 1) - que(1, a.we) - x);   }   void chan(long long x) {     if (x < 1 || x > n) return;     long long y = que(1, x) - max(que(1, x + 1), que(1, x - 1));     chang(1, x, y);   }   int main() {     scanf( %d , &n);     for (long long i = 1; i <= n; i++) scanf( %d , &b[i]);     b[0] = b[1];     b[n + 1] = b[n];     for (long long i = 1; i < n; i++) ansn += abs(b[i + 1] - b[i]);     build(1, 0, n + 1);     scanf( %d , &m);     while (m--) {       scanf( %d %d %d %d , &opt, &l, &r, &x);       if (opt == 1) {         c = ga(1, l, r);         if (c.nu >= 0)           cout << ansn + x * 2 << endl;         else {           sum = cou(c);           if (l <= c.we - 1) sum = max(sum, cou(ga(1, l, c.we - 1)));           if (c.we + 1 <= r) sum = max(sum, cou(ga(1, c.we + 1, r)));           cout << sum << endl;         }       } else {         ansn -= abs(que(1, l - 1) - que(1, l));         ansn -= abs(que(1, r + 1) - que(1, r));         if (l == 1) l--;         if (r == n) r--;         add(1, l, r, x);         if (l == 0) l++;         if (r == n + 1) r++;         chan(l);         chan(l - 1);         chan(r);         chan(r + 1);         ansn += abs(que(1, l - 1) - que(1, l));         ansn += abs(que(1, r + 1) - que(1, r));       }     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma )   #pragma GCC optimize( unroll-loops )   using namespace std;   long long MOD = 998244353;   double eps = 1e-12;   long long mpow(long long a, long long b) {     if (a == 0) return 0;     if (b == 0) return 1;     long long t1 = mpow(a, b / 2);     t1 *= t1;     t1 %= MOD;     if (b % 2) t1 *= a;     t1 %= MOD;     return t1;   }   long long mpow(long long a, long long b, long long p) {     if (a == 0) return 0;     if (b == 0) return 1;     long long t1 = mpow(a, b / 2, p);     t1 *= t1;     t1 %= p;     if (b % 2) t1 *= a;     t1 %= p;     return t1;   }   long long modinverse(long long a, long long m) {     long long m0 = m;     long long y = 0, x = 1;     if (m == 1) return 0;     while (a > 1) {       long long q = a / m;       long long t = m;       m = a % m, a = t;       t = y;       y = x - q * y;       x = t;     }     if (x < 0) x += m0;     return x;   }   mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());   long long range(long long l, long long r) { return l + mt() % (r - l + 1); }   long long rev(long long v) { return mpow(v, MOD - 2); }   void solve() {     long long n;     cin >> n;     long long a[n];     long long alpha = 0, sign = 1;     set<long long> s;     long long st = -1, en = -1;     long long ans = 1;     for (long long i = 0; i < n; i++) {       cin >> a[i];     }     if (a[0] % 2) {       st = 1;       en = a[0] - 1;       ans++;     } else {       st = a[0] / 2;       en = a[0] / 2;     }     for (long long i = 1; i < n; i++) {       long long alpha1 = a[i] - alpha;       long long sign1 = -sign;       if (a[i] % 2) {         ans++;         long long val = a[i] - alpha;         if (sign > 0) {           auto it = s.lower_bound(val);           while (it != s.end()) {             s.erase(it);             it = s.lower_bound(val);           }         } else {           auto it = s.lower_bound(-val + 1);           while (it != s.begin()) {             it--;             s.erase(it);             it = s.lower_bound(-val + 1);           }         }         if (st >= a[i] && ((long long)(s).size()) == 0) {           ans++;           st = 1, en = a[i] - 1;         } else if (st >= a[i]) {           long long val = alpha1 + sign1 * (*(s.begin()));           s.erase(s.begin());           st = val, en = val;         } else {           long long t1 = a[i] - st, t2 = a[i] - en;           st = max((long long)1, t2), en = max((long long)1, t1);         }       } else {         long long mid = sign * (a[i] / 2 - alpha);         if (s.find(mid) != s.end() || (st <= a[i] / 2 && en >= a[i] / 2)) {           s.clear();           st = a[i] / 2;           en = a[i] / 2;         } else {           ans++;           long long val = a[i] - alpha;           if (sign > 0) {             auto it = s.lower_bound(val);             while (it != s.end()) {               s.erase(it);               it = s.lower_bound(val);             }           } else {             auto it = s.lower_bound(-val + 1);             while (it != s.begin()) {               it--;               s.erase(it);               it = s.lower_bound(-val + 1);             }           }           if (st >= a[i] && ((long long)(s).size()) == 0) {             st = a[i] / 2, en = a[i] / 2;           } else if (st >= a[i]) {             long long val = alpha1 + sign1 * (*(s.begin()));             s.erase(s.begin());             st = val, en = val;             s.insert(sign1 * (a[i] / 2 - alpha1));           } else {             long long t1 = a[i] - st, t2 = a[i] - en;             st = max((long long)1, t2), en = max((long long)1, t1);             s.insert(mid);           }         }       }       alpha = a[i] - alpha;       sign *= -1;     }     cout << ans <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long t = 1;     cin >> t;     for (long long i = 0; i < t; i++) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t, m, num = 1;     string com;     int arg;     vector<pair<pair<int, int>, int> > d;     cin >> t >> m;     for (int _n((t)-1), q(0); q <= _n; q++) {       sort((d).begin(), (d).end());       cin >> com;       if (com ==  defragment ) {         if (d.size() > 0) {           d[0].first.second -= d[0].first.first;           d[0].first.first = 0;           for (int _n((d.size() - 1)), i(1); i <= _n; i++) {             int delta = d[i].first.first - d[i - 1].first.second;             d[i].first.first -= delta;             d[i].first.second -= delta;           }         }         continue;       }       cin >> arg;       if (com ==  alloc ) {         int res = -1;         if (d.size() > 0)           if (d[0].first.first >= arg) {             d.push_back(make_pair(make_pair(0, arg), num++));             res = 1;           }         if (res == -1)           for (int _n((d.size() - 1)), i(1); i <= _n; i++)             if (d[i].first.first - d[i - 1].first.second >= arg) {               d.push_back(make_pair(                   make_pair(d[i - 1].first.second, d[i - 1].first.second + arg),                   num++));               res = 1;               break;             }         if (res == -1)           if (d.size() > 0)             if (m - d[d.size() - 1].first.second >= arg) {               d.push_back(make_pair(make_pair(d[d.size() - 1].first.second,                                               d[d.size() - 1].first.second + arg),                                     num++));               res = 1;             }         if (res == -1)           if (d.size() == 0)             if (m >= arg) {               d.push_back(make_pair(make_pair(0, arg), num++));               res = 1;             }         if (res == -1)           cout <<  NULL  << endl;         else           cout << num - 1 << endl;         continue;       }       if (com ==  erase ) {         bool res = false;         for (int i = 0; i < d.size(); i++)           if (d[i].second == arg) {             swap(d[i], d[d.size() - 1]);             d.pop_back();             res = true;             break;           }         if (!res) cout <<  ILLEGAL_ERASE_ARGUMENT  << endl;         continue;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100050;   struct str {     int pre[26], suf[26], mx[26], len;     str() {}     void Build(char s[], int n) {       len = n;       for (int i = 0; i < 26; i++) pre[i] = suf[i] = mx[i] = 0;       int len = 0;       for (int i = 1; i <= n; i++) {         if (i != 1 && s[i] == s[i - 1])           len++;         else           len = 1;         mx[s[i] -  a ] = max(mx[s[i] -  a ], len);       }       for (int i = 0; i < 26; i++) {         while (pre[i] < n && s[pre[i] + 1] ==  a  + i) pre[i]++;         while (suf[i] < n && s[n - suf[i]] ==  a  + i) suf[i]++;       }     }   } STR[N];   str operator*(str x, str y) {     str ans;     ans.len = y.len * (x.len + 1) + x.len;     for (int i = 0; i < 26; i++) {       if (y.pre[i] == y.len) {         if (x.pre[i] == x.len)           ans.pre[i] = ans.len;         else           ans.pre[i] = y.len * (x.pre[i] + 1) + x.pre[i];         if (x.suf[i] == x.len)           ans.suf[i] = ans.len;         else           ans.suf[i] = y.len * (x.suf[i] + 1) + x.suf[i];         ans.mx[i] = y.len * (x.mx[i] + 1) + x.mx[i];       } else {         ans.pre[i] = y.pre[i];         ans.suf[i] = y.suf[i];         if (x.mx[i] > 0)           ans.mx[i] = y.pre[i] + y.suf[i] + 1;         else           ans.mx[i] = y.mx[i];         ans.mx[i] = max(ans.mx[i], y.mx[i]);       }     }     return ans;   }   char s[N];   int main() {     int n, len, i;     scanf( %i , &n);     for (i = 1; i <= n; i++) {       scanf( %s , s + 1);       len = strlen(s + 1);       STR[i].Build(s, len);     }     for (i = 2; i <= n; i++) {       STR[1] = STR[1] * STR[i];     }     int ans = 0;     for (i = 0; i < 26; i++) ans = max(ans, STR[1].mx[i]);     printf( %i n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double PI = 2.0 * acos(0.0);   const double EPS = 1e-6;   int dp[100005];   static int topp;   void LIS(int x) {     if (topp == 0)       dp[topp++] = x;     else if (x > dp[topp - 1])       dp[topp++] = x;     else {       int left = 0, right = topp;       while (left < right) {         int mid = (left + right) >> 1;         if (dp[mid] > x)           right = mid;         else           left = mid + 1;       }       while (left < topp - 1 && dp[left] == dp[left + 1]) left++;       dp[left] = x;     }   }   int main() {     int n;     scanf( %d , &n);     ::topp = 0;     for (int i = 0; i < n; i++) {       int a;       scanf( %d , &a);       LIS(a);     }     printf( %d n , topp);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> x[100100], y[100100];   vector<int> p[100100], q[100100], v[100100], w[100100];   int a[100100], b[100100], c[100100];   map<pair<int, int>, int> mp;   void solve() {     mp.clear();     int n, m;     scanf( %d%d , &n, &m);     for (int i = 0; i < m; i++) {       scanf( %d%d , &a[i], &b[i]);       x[a[i]].push_back(b[i]);       y[b[i]].push_back(a[i]);       if (a[i] + b[i] <= n + 1) {         int o = a[i] - 1, oo = o + b[i];         p[oo].push_back(b[i]);       } else {         int oo = n - b[i], o = a[i] - oo;         q[o].push_back(a[i]);       }       if (a[i] <= b[i]) {         int o = a[i] - 1, oo = b[i] - o;         v[oo].push_back(b[i]);       } else {         int oo = b[i], o = a[i] - oo + 1;         w[o].push_back(a[i]);       }     }     for (int i = 1; i <= n; i++) {       if (x[i].size() <= 1) continue;       sort(x[i].begin(), x[i].end());       for (int j = 0; j < x[i].size(); j++) {         int xx = i, yy = x[i][j];         if (j == 0 || j == x[i].size() - 1) {           mp[make_pair(xx, yy)]++;         } else {           mp[make_pair(xx, yy)] += 2;         }       }     }     for (int i = 1; i <= n; i++) {       if (y[i].size() <= 1) continue;       sort(y[i].begin(), y[i].end());       for (int j = 0; j < y[i].size(); j++) {         int xx = y[i][j], yy = i;         if (j == 0 || j == y[i].size() - 1) {           mp[make_pair(xx, yy)]++;         } else {           mp[make_pair(xx, yy)] += 2;         }       }     }     for (int i = 1; i <= n; i++) {       if (p[i].size() <= 1) continue;       sort(p[i].begin(), p[i].end());       for (int j = 0; j < p[i].size(); j++) {         int yy = p[i][j];         int xx = i - yy + 1;         if (j == 0 || j == p[i].size() - 1) {           mp[make_pair(xx, yy)]++;         } else {           mp[make_pair(xx, yy)] += 2;         }       }     }     for (int i = 1; i <= n; i++) {       if (q[i].size() <= 1) continue;       sort(q[i].begin(), q[i].end());       for (int j = 0; j < q[i].size(); j++) {         int xx = q[i][j];         int yy = n - (xx - i);         if (j == 0 || j == q[i].size() - 1) {           mp[make_pair(xx, yy)]++;         } else {           mp[make_pair(xx, yy)] += 2;         }       }     }     for (int i = 1; i <= n; i++) {       if (v[i].size() <= 1) continue;       sort(v[i].begin(), v[i].end());       for (int j = 0; j < v[i].size(); j++) {         int yy = v[i][j];         int xx = yy - i + 1;         if (j == 0 || j == v[i].size() - 1) {           mp[make_pair(xx, yy)]++;         } else {           mp[make_pair(xx, yy)] += 2;         }       }     }     for (int i = 1; i <= n; i++) {       if (w[i].size() <= 1) continue;       sort(w[i].begin(), w[i].end());       for (int j = 0; j < w[i].size(); j++) {         int xx = w[i][j];         int yy = xx - i + 1;         if (j == 0 || j == w[i].size() - 1) {           mp[make_pair(xx, yy)]++;         } else {           mp[make_pair(xx, yy)] += 2;         }       }     }     map<pair<int, int>, int>::iterator iter;     iter = mp.begin();     int s = 0;     while (iter != mp.end()) {       int o = iter->second;       pair<int, int> v = iter->first;       c[o]++;       s++;       iter++;     }     printf( %d , m - s);     for (int i = 1; i < 9; i++) printf(  %d , c[i]);   }   int main() { solve(); }


#include <bits/stdc++.h>   using namespace std;   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     long long n;     cin >> n;     string s, t;     cin >> s >> t;     long long sa = 0, sb = 0, ta = 0, tb = 0;     for (long long i = 0; i < n; i++) {       if (s[i] ==  a )         sa++;       else         sb++;       if (t[i] ==  a )         ta++;       else         tb++;     }     if ((ta + sa) % 2 == 1 || (tb + sb) % 2 == 1) return cout << -1, 0;     vector<pair<long long, long long> > ans;     vector<long long> va, vb;     for (long long i = 0; i < n; i++) {       if (s[i] != t[i]) {         if (s[i] ==  a )           va.push_back(i);         else           vb.push_back(i);       }     }     {       for (long long i = 0;            i < (long long)va.size() && (long long)va.size() > i + 1; i += 2)         ans.push_back(make_pair(va[i], va[i + 1]));       for (long long i = 0;            i < (long long)vb.size() && (long long)vb.size() > i + 1; i += 2)         ans.push_back(make_pair(vb[i], vb[i + 1]));     }     if ((long long)va.size() % 2 == 1) {       ans.push_back(           make_pair(va[(long long)va.size() - 1], va[(long long)va.size() - 1]));       ans.push_back(           make_pair(va[(long long)va.size() - 1], vb[(long long)vb.size() - 1]));     }     cout << ans.size() <<   n ;     for (long long i = 0; i < (long long)ans.size(); i++)       cout << ans[i].first + 1 <<     << ans[i].second + 1 <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline T abs(T a) {     return ((a < 0) ? -a : a);   }   template <typename T>   inline T sqr(T a) {     return a * a;   }   const int INF = (int)1E9 + 7;   const long double EPS = 1E-9;   const long double PI = 3.1415926535897932384626433832795;   int n, m;   pair<int, int> a[100];   int solve(int x, int y, int i) {     int ans = i;     if (y == m) x++, y = 0;     if (x == n) return ans;     ans = max(ans, solve(x, y + 1, i));     bool ok = true;     for (int j = 0; j < int(i); ++j) {       if (sqr(a[j].first - x) + sqr(a[j].second - y) == 5) {         ok = false;         break;       }     }     if (ok) {       a[i] = make_pair(x, y);       ans = max(ans, solve(x, y + 1, i + 1));     }     return ans;   }   long long solve(long long n, long long m) {     if (n < m) swap(n, m);     if (m > 2) return (n * m) / 2 + ((n * m) & 1);     if (m == 1) return n;     int k = (n - 2) / 4, rem = (n - 2) % 4;     int start = 4 + k * 4;     if (rem < 3) return start;     return start + 2;   }   int main() {     int n, m;     cin >> n >> m;     cout << solve(n, m) << endl;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC target( avx,avx2,fma )   #pragma GCC optimization( unroll-loops )   using namespace std;   const long long MOD = 998244353;   const long long INF = 0x7f7f7f7f7f7f7f7f;   const int INFi = 0x7f7f7f7f;   const long long N = 150001;   vector<long long> adj[N];   long long vis[N] = {};   int dx8[] = {0, 1, 1, 1, 0, -1, -1, -1}, dy8[] = {1, 1, 0, -1, -1, -1, 0, 1};   int dx4[] = {0, 1, 0, -1}, dy4[] = {1, 0, -1, 0};   int t = 1;   long long n, a[2 * N + 10], fact[2 * N + 10];   long long mult(long long a, long long b) { return (a % MOD * b % MOD) % MOD; }   long long add(long long a, long long b) { return (a % MOD + b % MOD) % MOD; }   long long subt(long long a, long long b) {     return (a % MOD - b % MOD + MOD) % MOD;   }   long long fastModInv(long long x) {     long long res = 1;     long long y = MOD - 2;     while (y) {       if (y & 1) res = mult(res, x);       y >>= 1;       x = mult(x, x);     }     return res;   }   void MAIN() {     cin >> n;     long long ans = 0;     for (long long i = 1; i <= 2 * n; i++) cin >> a[i], a[i] = 2 * a[i];     sort(a + 1, a + 1 + 2 * n);     long long val =         (fact[2 * n - 1] * fastModInv(fact[2 * n - 1 - n + 1]) % MOD) *         fastModInv(fact[n - 1]) % MOD;     for (long long i = 1; i <= n; i++) ans = subt(ans, val * a[i] % MOD);     for (long long i = n + 1; i <= 2 * n; i++) ans = add(ans, val * a[i] % MOD);     cout << ans <<   n ;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cout << fixed;     cout << setprecision(10);     ;     mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());     ;     fact[0] = 1;     for (long long i = 1; i <= 2 * N; i++) fact[i] = fact[i - 1] * i % MOD;     while (t--) {       MAIN();     }   }


#include <bits/stdc++.h>   using namespace std;   int gcd(int a, int b) {     while (b) {       a %= b;       swap(a, b);     }     return a;   }   int check(vector<int> v) {     int k = 0;     for (int i = 0; i < v.size(); ++i) k += (gcd(i + 1, v[i]) > 1);     return k;   }   int main() {     int n, k;     cin >> n >> k;     if (n == k)       cout << -1 << endl;     else {       vector<int> v(n);       v[n - k - 1] = 1;       int p = 2;       for (int i = 0; i < n; ++i) {         if (i == n - k - 1) continue;         v[i] = p++;       }       for (int i = 0; i < n; ++i) cout << v[i] <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, m, i, j, k, x, y, z, t;     long long hh, mm, h, d, c, N;     cin >> hh >> mm;     cin >> h >> d >> c >> N;     if (hh >= 20) {       double cc = 0.8 * c;       k = (h + N - 1) / N;       double ans = 1.0 * k * cc;       cout << fixed << setprecision(10) << ans << endl;       return 0;     }     double ans1, ans2;     k = (h + N - 1) / N;     ans1 = 1.0 * k * c;     x = (60 - mm) + (20 - hh - 1) * 60;     h += x * d;     double cc = 0.8 * c;     k = (h + N - 1) / N;     ans2 = 1.0 * k * cc;     cout << fixed << setprecision(10) << min(ans1, ans2) << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 7;   const long long MOD = 1e9 + 7;   long long f[N << 2], lazy[N << 2], a[N], b[N], c[N];   void up(int x, int l, int r, long long y) {     f[x] = (f[x] + y * (r - l + 1)) % MOD;     lazy[x] = (lazy[x] + y) % MOD;   }   void push_down(int x, int l, int r) {     int mid = (l + r) / 2;     up(x << 1, l, mid, lazy[x]);     up(x << 1 | 1, mid + 1, r, lazy[x]);     lazy[x] = 0;   }   void update(int x, int l, int r, int left, int right, long long y) {     if (left > r || right < l) return;     if (left <= l && right >= r) {       up(x, l, r, y);       return;     }     push_down(x, l, r);     int mid = (l + r) / 2;     update(x << 1, l, mid, left, right, y);     update(x << 1 | 1, mid + 1, r, left, right, y);     f[x] = (f[x << 1] + f[x << 1 | 1]) % MOD;   }   long long query(int x, int l, int r, int left, int right) {     if (left > r || right < l) return 0;     if (left <= l && right >= r) return f[x];     push_down(x, l, r);     int mid = (l + r) / 2;     return (query(x << 1, l, mid, left, right) +             query(x << 1 | 1, mid + 1, r, left, right)) %            MOD;   }   int sz[N], son[N], l[N], r[N], n;   vector<int> p[N];   long long res, ans;   void getsize(int x, int fa) {     sz[x] = 1;     son[x] = -1;     for (int v : p[x])       if (v != fa) {         getsize(v, x);         sz[x] += sz[v];         if (son[x] == -1 || sz[v] > sz[son[x]]) son[x] = v;       }   }   void calc(int x, long long y, int op) {     if (op) {       long long tmp = a[r[x]] - a[l[x] - 1] -                       query(1, 1, 100000, l[x], r[x]) * 2 - y * (r[x] - l[x] + 1);       tmp = (tmp % MOD + MOD) % MOD;       res = (res + tmp * y) % MOD;     }     update(1, 1, 100000, l[x], r[x], y);   }   void clear(int x, int fa) {     calc(x, -c[x] + MOD, 0);     for (int v : p[x])       if (v != fa) clear(v, x);   }   void add(int x, int fa) {     calc(x, c[x], 1);     for (int v : p[x])       if (v != fa) add(v, x);   }   void gao(int x, int fa) {     for (int v : p[x])       if (v != fa && v != son[x]) {         gao(v, x);         clear(v, x);         res = 0;       }     if (son[x] != -1) gao(son[x], x);     for (int v : p[x])       if (v != fa && v != son[x]) {         add(v, x);       }     calc(x, c[x], 1);     ans = (ans + res) % MOD;   }   long long qpow(long long x, long long y) {     long long z = 1;     while (y > 0) {       if (y & 1) z = z * x % MOD;       x = x * x % MOD;       y /= 2;     }     return z;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d%d , &l[i], &r[i]);       long long t = qpow(r[i] - l[i] + 1, MOD - 2);       c[i] = t;       a[l[i]] = (a[l[i]] + t) % MOD;       a[r[i] + 1] = (a[r[i] + 1] - t + MOD) % MOD;     }     for (int i = 1; i < N; i++) b[i] = (b[i - 1] + a[i]) % MOD;     memset(a, 0, sizeof(a));     for (int i = 1; i < N; i++) a[i] = (a[i - 1] + b[i]) % MOD;     for (int i = 1; i < n; i++) {       int u, v;       scanf( %d%d , &u, &v);       p[u].push_back(v);       p[v].push_back(u);     }     getsize(1, 0);     gao(1, 0);     for (int i = 1; i <= n; i++) {       ans = ans * (r[i] - l[i] + 1) % MOD;     }     printf( %lld , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long const N = 2e5 + 20, MOD = 1e9 + 7;   long long n, x, dp[N][2];   bool vis[N], col[N];   vector<long long> child[N];   void dfs(int v = 0) {     for (auto u : child[v]) dfs(u);     vector<long long> preChild, sufChild;     preChild.push_back(1), sufChild.push_back(1);     for (auto u : child[v]) {       preChild.push_back((preChild.back() * ((dp[u][0] + dp[u][1]) % MOD)) % MOD);     }     for (int i = child[v].size() - 1; i >= 0; i--) {       int u = child[v][i];       sufChild.push_back((sufChild.back() * ((dp[u][0] + dp[u][1]) % MOD)) % MOD);     }     if (col[v]) {       dp[v][0] = 0;       dp[v][1] = preChild.back();       return;     }     dp[v][0] = preChild.back();     dp[v][1] = 0;     preChild.push_back(1), sufChild.push_back(1);     for (int i = 0; i < child[v].size(); i++) {       int u = child[v][i];       dp[v][1] = (dp[v][1] + ((dp[u][1] * preChild[i] % MOD) *                               (sufChild[sufChild.size() - 3 - i] % MOD) % MOD)) %                  MOD;     }     return;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> n;     for (int i = 0; i < n - 1; i++) {       cin >> x;       child[x].push_back(i + 1);     }     for (int i = 0; i < n; i++) cin >> col[i];     dfs();     return cout << dp[0][1], 0;   }


#include <bits/stdc++.h>   int n, t1, t2;   int num = 0;   int dfs(int l, int r) {     int k = (l + r) / 2;     num++;     if (t1 <= k && t2 > k) {       return num;     }     if (t1 <= k && t2 <= k) {       return dfs(l, k);     } else {       return dfs(k, r);     }   }   int FastLog2(int x) {     float fx;     unsigned long ix, exp;     fx = (float)x;     ix = *(unsigned long*)&fx;     exp = (ix >> 23) & 0xFF;     return exp - 127;   }   int main() {     int a, b;     scanf( %d%d%d , &n, &a, &b);     t1 = std::min(a, b);     t2 = std::max(a, b);     int ans = FastLog2(n) + 1 - dfs(1, n);     if (ans == FastLog2(n))       puts( Final! );     else       printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int get(int n, int p) {     int res = 0;     while (n >= p) res += n / p, n /= p;     return res;   }   template <class T>   T power(T N, T P) {     return (P == 0) ? 1 : N * power(N, P - 1);   }   void VC(vector<long long int>& v) {     for (int i = 0; i < v.size(); i++) printf( %lld  , v[i]);     printf(  n );   }   struct hash_pair {     template <class T1, class T2>     size_t operator()(const pair<T1, T2>& p) const {       auto hash1 = hash<T1>{}(p.first);       auto hash2 = hash<T2>{}(p.second);       return hash1 ^ hash2;     }   };   template <typename T>   void print(const T& v) {     cerr << v <<    ;   }   template <typename T1, typename... T2>   void print(const T1& first, const T2&... rest) {     print(first);     print(rest...);   }   const int Maxn = 1e5 + 1;   template <typename T, typename T1>   T mod(T x, T1 p) {     x %= p;     if (x < 0) x += p;     return x;   }   int fact[Maxn];   void factorial() {     fact[0] = 1;     for (int i = 1; i < Maxn; i++) {       fact[i] = 1LL * fact[i - 1] * i % 1000000007;     }   }   int inv[Maxn], ifact[Maxn];   template <typename T>   T inverse(T x, T p) {     x = mod(x, p);     if (x == 1) return x;     return mod((1LL * (-p / x) * (inv[p % x] % p)), p);   }   void inverse_fact() {     ifact[0] = 1;     for (int i = 1; i < Maxn; i++) {       inv[i] = inverse(i, 1000000007);       ifact[i] = (1LL * ifact[i - 1] * inv[i]) % 1000000007;     }   }   int nCr(int n, int r) {     int ret = (1LL * ifact[n - r] * ifact[r]) % 1000000007;     ret = (1LL * ret * fact[n]) % 1000000007;     return ret;   }   bool cmp(int a, int b) { return a > b; }   int main() {     int n, m, p, x, a, b;     scanf( %d , &(n));     scanf( %d , &(m));     scanf( %d , &(p));     int aa[n + 3], bb[m + 4];     for (int i = 0; i < n; i++) {       scanf( %d , &(aa[i]));     }     for (int i = 0; i < m; i++) {       scanf( %d , &(bb[i]));     }     for (int i = 0; i < n; i++) {       if (aa[i] % p) {         a = i;       }     }     for (int i = 0; i < m; i++) {       if (bb[i] % p) {         b = i;       }     }     printf( %d n , a + b);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   class Data {    public:     long long lazy, val;     Data() {       lazy = -1;       val = 0;     }   };   long long pr = 107;   long long c_pr[100010];   Data tree[4 * 100010];   long long ara[100010];   void updval(int node, int le_ran, int ri_ran, long long lazy) {     long long poo = c_pr[ri_ran] - c_pr[le_ran - 1];     poo %= 1000000007;     if (poo < 0) {       poo = (poo + 1000000007) % 1000000007;     }     tree[node].val = poo * lazy;     tree[node].val %= 1000000007;     tree[node].lazy = lazy;   }   void update(int node, int le_ran, int ri_ran) {     if (tree[node].lazy != -1) {       if (le_ran != ri_ran) {         int mid = (le_ran + ri_ran) / 2;         updval(node * 2, le_ran, mid, tree[node].lazy);         updval((node * 2) + 1, mid + 1, ri_ran, tree[node].lazy);       }       tree[node].lazy = -1;     }   }   void update_range(int node, int le_ran, int ri_ran, int le, int ri,                     long long val) {     if ((ri_ran < le) || (le_ran > ri)) {       return;     }     if ((le_ran >= le) && (ri_ran <= ri)) {       updval(node, le_ran, ri_ran, val);       return;     }     update(node, le_ran, ri_ran);     int mid = (le_ran + ri_ran) / 2;     update_range(node * 2, le_ran, mid, le, ri, val);     update_range((node * 2) + 1, mid + 1, ri_ran, le, ri, val);     tree[node].val = tree[node * 2].val + tree[(node * 2) + 1].val;     tree[node].val %= 1000000007;   }   long long query(int node, int le_ran, int ri_ran, int le, int ri) {     if ((ri_ran < le) || (le_ran > ri)) {       return 0;     }     if ((le_ran >= le) && (ri_ran <= ri)) {       return tree[node].val;     }     update(node, le_ran, ri_ran);     int mid = (le_ran + ri_ran) / 2;     long long ans = 0;     ans += query(node * 2, le_ran, mid, le, ri);     ans %= 1000000007;     ans += query((node * 2) + 1, mid + 1, ri_ran, le, ri);     ans %= 1000000007;     return ans;   }   string str;   int n, q;   long long bm(long long base, long long power) {     if (power == 0) {       return 1;     }     if (power % 2 == 0) {       long long ret = bm(base, power / 2);       return (ret * ret) % 1000000007;     } else {       return (base * bm(base, power - 1)) % 1000000007;     }   }   long long mod_inv(long long num) { return bm(num, 1000000007 - 2); }   long long get_hash(int l, int r) {     long long yo = query(1, 1, n, l, r);     yo %= 1000000007;     if (yo < 0) {       yo = (yo + 1000000007) % 1000000007;     }     yo = yo * mod_inv(bm(pr, l));     yo %= 1000000007;     return yo;   }   int main() {     std::ios_base::sync_with_stdio(false);     int m, k;     cin >> n >> m >> k;     q = m + k;     long long tmp_pr = 1;     for (int i = 1; i <= n; i++) {       c_pr[i] = c_pr[i - 1] + tmp_pr;       c_pr[i] %= 1000000007;       tmp_pr = tmp_pr * pr;       tmp_pr %= 1000000007;     }     cin >> str;     for (int i = 0; i <= n - 1; i++) {       update_range(1, 1, n, i + 1, i + 1, str[i] -  0 );     }     for (int i = 1; i <= q; i++) {       int cmd;       cin >> cmd;       int l, r, val;       cin >> l >> r >> val;       if (cmd == 1) {         update_range(1, 1, n, l, r, val);       } else {         if (get_hash(l, r - val) == get_hash(l + val, r)) {           cout <<  YES n ;         } else {           cout <<  NO n ;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, i, mx = 2, j;     cin >> n;     int a[n];     for (i = 0; i < n; i++) cin >> a[i];     if (n == 1)       cout <<  1 ;     else if (n == 2)       cout <<  2 ;     else {       for (i = 2; i < n;) {         int x = 0;         for (j = i; j < n; j++) {           if ((a[j] != (a[j - 1] + a[j - 2]))) break;           x++;         }         i = ++j;         mx = max(x + 2, mx);       }       cout << mx;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e6 + 1;   const int INF = 1e9 + 9;   const int B = 1e9 + 7;   int n, b[N], d[N];   long long a[N];   int main() {     ios_base ::sync_with_stdio(0);     cin.tie(0);     cin >> n;     int ans = n;     for (int i = int(1); i <= int(n); ++i) {       cin >> a[i];       while (a[i] % 2 == 0) a[i] /= 2, ++b[i];       d[i] = i - 1;       for (int j = int(1); j <= int(i - 1); ++j)         if (a[j] % a[i] == 0 &&             (b[j] + (i - j) == b[i] || b[i] <= i - j - 1 || b[i] == 0))           d[i] = min(d[i], d[j] + (i - j - 1));       ans = min(ans, d[i] + (n - i));     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s1, s2;     cin >> s1 >> s2;     int n = s1.length(), k = 0, s;     for (int i = 0; i < n; i++)       if (s1[i] != s2[i]) k++;     if (k % 2 == 1)       printf( impossible );     else {       int s = k / 2;       string ans;       for (int i = 0; i < n; i++)         if (s1[i] != s2[i])           if (s > 0) {             ans += s1[i];             s--;           } else             ans += s2[i];         else           ans += s1[i];       cout << ans;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   const int MOD2 = 1e9 + 9;   const int PR = 727;   const int INF = INT_MAX;   const long long LINF = LLONG_MAX;   const int N = 1e5 + 20;   vector<int> G[N], p;   int n, m, k, f[N], tmp;   bool visited[N];   int main() {     ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);     cin >> n >> m >> k;     for (int i = 0, v, u; i < m; i++) {       cin >> v >> u;       G[v].push_back(u);       G[u].push_back(v);     }     int v = 1;     while (1) {       visited[v] = 1;       f[v] = tmp++;       p.push_back(v);       for (int u : G[v])         if (!visited[u]) v = u;       if (visited[v]) break;     }     int idx = INF;     for (int v : G[p.back()]) idx = min(idx, f[v]);     cout << p.size() - idx << endl;     for (int i = idx; i < p.size(); i++) cout << p[i] <<    ;     cout << endl;   }


#include <bits/stdc++.h>   using namespace std;   #pragma GCC optimize( O3 )   #pragma GCC target( avx )   #pragma GCC optimize( Ofast )   #pragma GCC optimize( unroll-loops )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   long long int dx[] = {0, 1, 0, -1, -1, 1, -1, 1};   long long int dy[] = {-1, 0, 1, 0, -1, 1, 1, -1};   const long long int MAXN = 2e6 + 5;   const long long int N = 1e5 + 5;   long long int n, m;   long long int binpow(long long int n, long long int p) {     long long int res = 1;     while (p > 0) {       if (p & 1) res = res * n;       n = n * n;       p >>= 1;     }     return res;   }   long long int power(long long int n, long long int p) {     long long int res = 1;     n %= 1000000007;     while (p > 0) {       if (p & 1) res = (res * n) % 1000000007;       n = (n * n) % 1000000007;       p >>= 1;     }     return res;   }   long long int modInverse(long long int n, long long int p) {     return power(n, p - 2);   }   long long int fact[MAXN], inv[MAXN], invfact[MAXN];   void initFactorials() {     fact[0] = 1;     for (long long int i = 1; i < MAXN; i++) {       fact[i] = (fact[i - 1] * i * 1LL) % 1000000007;     }     inv[1] = 1;     for (long long int i = 2; i < MAXN; i++)       inv[i] = inv[1000000007 % i] * (1000000007 - 1000000007 / i) % 1000000007;     invfact[0] = 1;     for (long long int i = 1; i < MAXN; i++)       invfact[i] = (invfact[i - 1] * inv[i]) % 1000000007;   }   long long int nCrMod(long long int n, long long int r) {     if (n < r) return 0;     if (r == 0) return 1;     long long int num = fact[n], den = (fact[r] * fact[n - r]) % 1000000007;     long long int inv = modInverse(den, 1000000007);     return (num * inv) % 1000000007;   }   string s;   vector<long long int> res;   long long int mx = 1000111000111000111LL;   bool isVowel(char c) {     return (c ==  a  || c ==  e  || c ==  i  || c ==  o  || c ==  u );   }   void go(long long int pos, long long int cnt, vector<long long int> temp) {     if (pos >= n) {       if (temp.size() < mx) {         mx = temp.size();         res = temp;       }       return;     }     if (isVowel(s[pos])) {       return go(pos + 1, 0, temp);     }     if (cnt == 2) {       temp.push_back(pos);       go(pos, 0, temp);     } else if (cnt == 1) {       temp.push_back(pos);       go(pos, 0, temp);       temp.pop_back();       go(pos + 1, cnt + 1, temp);     } else {       go(pos + 1, cnt + 1, temp);     }   }   void solve() {     cin >> s;     n = s.size();     string temp;     long long int constant = 0, consecutive = 0;     temp = s[0];     if (!isVowel(s[0])) constant = 1, consecutive = 1;     for (long long int i = 1; i < n; i++) {       if (isVowel(s[i])) {         consecutive = 0;         constant = 0;         temp += s[i];         continue;       }       if (consecutive >= 3) {         if (!isVowel(s[i]) && s[i] != s[i - 1]) {           cout << temp <<    ;           temp = s[i];           consecutive = 1;           constant = 1;           continue;         }       }       if (!isVowel(s[i]) && s[i] == s[i - 1]) {         consecutive++;       } else {         consecutive = 1;       }       if (!isVowel(s[i])) {         constant++;       }       if (consecutive >= 3) {         temp += s[i];         constant = 0;         continue;       }       if (constant == 3) {         cout << temp <<    ;         temp = s[i];         constant = 1;       } else {         temp += s[i];       }     }     cout << temp <<   n ;   }   signed main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long int t = 1;     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 500000;   int a[MAX], last[MAX], prv[MAX], inSet[MAX], current[MAX];   int n, k;   int main() {     ios_base::sync_with_stdio(false);     cin >> n >> k;     memset(last, -1, sizeof(last));     memset(prv, -1, sizeof(prv));     for (int i = 0; i < n; i++) {       cin >> a[i];       prv[i] = last[a[i]];       last[a[i]] = i;     }     set<pair<int, int> > s;     int ans = 0;     for (int i = n - 1; i >= 0; i--) {       int cur = a[i];       if (inSet[cur]) {         s.erase(s.find(make_pair(current[cur], cur)));         s.insert(make_pair(prv[i], cur));         current[cur] = prv[i];         continue;       }       ans++;       if (s.size() < k) {         inSet[cur] = true;         s.insert(make_pair(prv[i], cur));         current[cur] = prv[i];       } else {         pair<int, int> fr = (*s.begin());         inSet[cur] = true;         inSet[fr.second] = false;         s.erase(s.begin());         s.insert(make_pair(prv[i], cur));         current[cur] = prv[i];       }     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int n, k;     cin >> n >> k;     vector<int> v(n + 1, 0);     for (int i = 1; i <= n; i++) {       cin >> v[i];     }     sort(v.begin() + 1, v.end());     v[0] = v[1];     auto get = [&](int x) {       vector<int> p;       p.emplace_back(0);       for (int i = 1; i <= n; i++) {         int left = lower_bound(v.begin(), v.end(), v[i] - x) - v.begin() - 1;         int right = i - k;         auto it = lower_bound(p.begin(), p.end(), left);         if (it != p.end() and *it <= right) {           p.emplace_back(i);         }       }       return (find(p.begin(), p.end(), n) != p.end());     };     int lo = 0, hi = (v[n] - v[1]), ans = 1e9;     while (lo <= hi) {       int md = (lo + hi) / 2;       if (get(md))         ans = md, hi = md - 1;       else         lo = md + 1;     }     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     long long int n, k;     cin >> n >> k;     if (k > n)       cout << -1 <<   n ;     else if (n != 1 && k == 1)       cout << -1 <<   n ;     else if (k == n) {       char x =  a ;       for (long long int i = 1; i <= (long long int)n; i++) {         cout << x;         x++;       }     } else if (k < n) {       long long int t = n - (k - 2);       for (long long int i = 1; i <= (long long int)t; i++) {         if (i % 2 != 0)           cout <<  a ;         else           cout <<  b ;       }       long long int q = n - t;       char y =  c ;       if (q > 0) {         for (long long int i = 1; i <= (long long int)q; i++) {           cout << y;           y++;         }       }     }   }   int main() {     std::ios::sync_with_stdio(false);     int t = 1;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     int n, s, k, a[55], dp[55][2505];     cin >> n >> s >> k;     for (int i = 0; i < n; i++) cin >> a[i];     string s1;     cin >> s1;     priority_queue<pair<int, pair<int, int> > > q;     s--;     for (int i = 0; i < 55; i++)       for (int j = 0; j < 2505; j++) dp[i][j] = 1e7 + 7;     for (int i = 0; i < n; i++) {       dp[i][a[i]] = abs(i - s);       q.push(make_pair(abs(i - s), make_pair(i, a[i])));     }     while (!q.empty()) {       pair<int, pair<int, int> > p = q.top();       q.pop();       int dd = p.first;       int at = p.second.first;       int choc = p.second.second;       for (int i = 0; i < n; i++) {         if (a[i] > a[at] && s1[i] != s1[at]) {           int dis = abs(i - at);           if (dp[at][choc] + dis < dp[i][choc + a[i]]) {             dp[i][choc + a[i]] = dp[at][choc] + dis;             q.push(make_pair(-dp[i][choc + a[i]], make_pair(i, choc + a[i])));           }         }       }     }     int ans = 1e7 + 7;     for (int i = 0; i < n; i++)       for (int j = k; j <= 2505; j++) ans = min(ans, dp[i][j]);     if (ans > 1e6)       cout <<  -1 ;     else       cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int x, cnt = 0;     cin >> x;     int arr1[x], arr2[x];     for (int i = 0; i < x; i++) {       cin >> arr1[i] >> arr2[i];     }     for (int i = 0; i < x; i++) {       for (int j = 0; j < x; j++) {         if (i == j) {           continue;         }         if (arr1[i] == arr2[j]) {           cnt++;         }       }     }     cout << cnt;   }


#include <bits/stdc++.h>   using namespace std;   void IO() {     mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }   int main() {     IO();     int t;     cin >> t;     while (t--) {       long long int n;       cin >> n;       long long int sum = 0;       vector<long long int> arr(n + 1);       for (__typeof(n + 1) i = (1) - ((1) > (n + 1));            i != (n + 1) - ((1) > (n + 1)); i += 1 - 2 * ((1) > (n + 1))) {         cin >> arr[i];         sum += arr[i];       }       long long int rem = sum % n;       if (rem)         cout << -1 <<   n ;       else {         long long int want = sum / n;         vector<pair<pair<long long int, long long int>, long long int> > ans;         for (__typeof(n + 1) i = (2) - ((2) > (n + 1));              i != (n + 1) - ((2) > (n + 1)); i += 1 - 2 * ((2) > (n + 1))) {           long long int rem = arr[i] % i;           arr[1] += arr[i];           if (rem) {             long long int more = i - rem;             ans.push_back(make_pair(make_pair(1, i), more));           }           ans.push_back(make_pair(make_pair(i, 1), (arr[i] + i - 1) / i));         }         for (__typeof(n + 1) i = (2) - ((2) > (n + 1));              i != (n + 1) - ((2) > (n + 1)); i += 1 - 2 * ((2) > (n + 1))) {           ans.push_back(make_pair(make_pair(1, i), want));         }         long long int a = (int)(ans.size());         cout << a <<   n ;         for (__typeof(a) i = (0) - ((0) > (a)); i != (a) - ((0) > (a));              i += 1 - 2 * ((0) > (a))) {           cout << ans[i].first.first <<     << ans[i].first.second <<                    << ans[i].second <<   n ;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main(int argc, char** argv) {     long long r, x1, y1, x2, y2;     while (cin >> r >> x1 >> y1 >> x2 >> y2) {       double dis = sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2) + 0.0);       cout << ceil(dis / 2 / r) << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using LL = long long;   const int N = 400005;   const int mod = 998244353;   int n, m;   int fact[N], infact[N];   int qmi(int a, int k, int p) {     int res = 1;     while (k) {       if (k & 1) res = (LL)res * a % p;       a = (LL)a * a % p;       k >>= 1;     }     return res;   }   int C(int a, int b) {     return (LL)fact[a] * infact[a - b] % mod * infact[b] % mod;   }   int main() {     scanf( %d%d , &n, &m);     fact[0] = infact[0] = 1;     for (int i = 1; i < N; ++i) {       fact[i] = (LL)fact[i - 1] * i % mod;       infact[i] = (LL)infact[i - 1] * qmi(i, mod - 2, mod) % mod;     }     if (n == 2) {       printf( %d n , 0);       return 0;     }     int res = (LL)C(m, n - 1) * (n - 2) % mod;     int p = qmi(2, n - 3, mod) % mod;     printf( %d n , (LL)res * p % mod);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     const int maxn = 1005;     char a[2 * maxn], b[maxn];     scanf( %s , a);     scanf( %s , b);     int lenA = strlen(a);     int lenB = strlen(b);     int cntA = 0, cntB = 0;     int i;     for (i = 0; i < lenA; i++)       if (a[i] ==  1 ) cntA++;     for (i = 0; i < lenB; i++)       if (b[i] ==  1 ) cntB++;     if (cntA % 2 == 0) {       if (cntA < cntB) {         puts( NO );       } else {         puts( YES );       }     } else {       if (cntB - cntA > 1) {         puts( NO );       } else {         puts( YES );       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int H = 1000000;   template <typename Key, typename Val>   struct Hash {     char *used;     Key *key;     Val *val;     Hash() {       used = new char[H];       key = new Key[H];       val = new Val[H];       memset(used, 0, sizeof(used));     }     int hash_func(const Key &k) { return k % H; }     pair<bool, int> find(const Key &k) {       int h = hash_func(k);       for (;; h++, h = (h == H) ? 0 : h) {         if (not used[h]) return make_pair(false, h);         if (key[h] == k) return make_pair(true, h);       }     }     void insert(const Key &k, const Val &v) {       int h = find(k).second;       used[h] = 1;       key[h] = k;       val[h] = v;     }     Val &get(const Key &k) {       pair<bool, int> f = find(k);       if (!f.first) assert(false);       return val[f.second];     }   };   int mod;   long long find(const long long &n, long long l, long long r, long long u,                  long long v, long long &num) {     num = 0;     if (l > r or u > v) return 0;     if (v < 1 or n < u) return 0;     if (r < 1 or n < l) return 0;     if (n == 1) {       if (l <= 1 and 1 <= r and u <= 1 and 1 <= v) {         num = 1;         return 1;       } else {         num = 0;         return 0;       }     }     l = max(1ll, l);     r = min(n, r);     u = max(1ll, u);     v = min(n, v);     if (l == 1 and r == n) {       num = v - u + 1;       long long c1 = v + u, c2 = (v - u + 1);       if (c1 % 2 == 0)         c1 /= 2;       else         c2 /= 2;       c1 %= mod;       c2 %= mod;       return c1 * c2 % mod;       ;     }     num = 0;     const long long n1 = (n + 1) / 2, n2 = n / 2;     long long ans = 0;     if (l <= n1) {       long long u1 = u, v1 = v, nn;       if (u1 % 2 == 0) u1++;       if (v1 % 2 == 0) v1--;       ans += find(n1, l, min(r, n1), (u1 + 1) / 2, (v1 + 1) / 2, nn) * 2;       num += nn;       ans -= nn;     }     if (n1 + 1 <= r) {       long long u1 = u, v1 = v, nn;       if (u1 % 2 == 1) u1++;       if (v1 % 2 == 1) v1--;       ans += find(n2, max(l, n1 + 1) - n1, r - n1, u1 / 2, v1 / 2, nn) * 2;       num += nn;     }     ans = (ans % mod + mod) % mod;     return ans;   }   long long n;   int m;   long long l, r, u, v;   int main() {     scanf( %I64d%d%d , &n, &m, &mod);     for (int i = 0; i < (int)(m); ++i) {       scanf( %I64d%I64d%I64d%I64d , &l, &r, &u, &v);       long long n1;       printf( %lld n , find(n, l, r, u, v, n1));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool sortmd(pair<long long, long long> &a, pair<long long, long long> &b) {     if (a.first != b.first)       return a.first < b.first;     else       return a.second < b.second;   }   int main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     srand(time(NULL));     long long t, i, j, a, b;     cin >> t;     while (t--) {       cin >> a >> b;       if (a == b) {         cout << 0 << endl;       } else if (a < b) {         j = b - a;         if (j % 2 == 0)           cout << 2 << endl;         else           cout << 1 << endl;       } else {         j = a - b;         if (j % 2 == 0)           cout << 1 << endl;         else           cout << 2 << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int read() {     char c = getchar();     int x = 0;     bool f = 0;     for (; !isdigit(c); c = getchar()) f ^= !(c ^ 45);     for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);     if (f) x = -x;     return x;   }   int mod;   struct modint {     int x;     modint(int o = 0) { x = o; }     modint &operator=(int o) { return x = o, *this; }     modint &operator+=(modint o) {       return x = x + o.x >= mod ? x + o.x - mod : x + o.x, *this;     }     modint &operator-=(modint o) {       return x = x - o.x < 0 ? x - o.x + mod : x - o.x, *this;     }     modint &operator*=(modint o) { return x = 1ll * x * o.x % mod, *this; }     modint &operator^=(int b) {       modint a = *this, c = 1;       for (; b; b >>= 1, a *= a)         if (b & 1) c *= a;       return x = c.x, *this;     }     modint &operator/=(modint o) { return *this *= o ^= mod - 2; }     modint &operator+=(int o) {       return x = x + o >= mod ? x + o - mod : x + o, *this;     }     modint &operator-=(int o) {       return x = x - o < 0 ? x - o + mod : x - o, *this;     }     modint &operator*=(int o) { return x = 1ll * x * o % mod, *this; }     modint &operator/=(int o) { return *this *= ((modint(o)) ^= mod - 2); }     template <class I>     friend modint operator+(modint a, I b) {       return a += b;     }     template <class I>     friend modint operator-(modint a, I b) {       return a -= b;     }     template <class I>     friend modint operator*(modint a, I b) {       return a *= b;     }     template <class I>     friend modint operator/(modint a, I b) {       return a /= b;     }     friend modint operator^(modint a, int b) { return a ^= b; }     friend bool operator==(modint a, int b) { return a.x == b; }     friend bool operator!=(modint a, int b) { return a.x != b; }     bool operator!() { return !x; }     modint operator-() { return x ? mod - x : 0; }   };   inline modint qpow(modint a, int b) { return a ^ b; }   int n, k;   map<int, int> mp;   modint iv[100005], sum[100005];   void div(int l, int r, int k) {     if (k <= 1 || l == r) return mp[r - l + 1]++, void();     int mid = l + r >> 1;     div(l, mid, k - 1), div(mid + 1, r, k - 1);   }   modint getprob(int x, int y) {     modint res = modint(x) * y;     for (register int i = (1); i <= (x); ++i) res -= 2 * (sum[i + y] - sum[i]);     return res;   }   signed main() {     n = read(), k = read(), mod = read();     iv[1] = 1;     for (register int i = (2); i <= (max(4, n)); ++i)       iv[i] = iv[mod % i] * (mod - mod / i);     for (register int i = (1); i <= (n); ++i) sum[i] = sum[i - 1] + iv[i];     div(1, n, k);     modint res = 0;     for (auto it1 : mp)       for (auto it2 : mp) {         if (it1.first == it2.first) {           int cnt = it1.second, len = it1.first;           res += iv[2] * len * (len - 1) * cnt;           res += modint(cnt) * (cnt - 1) * iv[2] * getprob(len, len);         } else if (it1.first < it2.first) {           int l1 = it1.first, l2 = it2.first, c1 = it1.second, c2 = it2.second;           res += getprob(l1, l2) * c1 * c2;         }       }     res *= iv[2];     cout << res.x;     return 0;   }