#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       string s;       cin >> s;       vector<vector<int>> lcp(n, vector<int>(n));       for (int i = n - 1; i >= 0; --i) {         for (int j = n - 1; j >= 0; --j) {           lcp[i][j] =               (s[i] == s[j]                    ? ((i < n - 1 && j < n - 1) ? lcp[i + 1][j + 1] : 0) + 1                    : 0);         }       }       vector<int> dp(n);       for (int i = 0; i < n; ++i) {         dp[i] = n - i;         for (int j = 0; j < i; ++j) {           if (i + lcp[i][j] < n && s[j + lcp[i][j]] < s[i + lcp[i][j]]) {             dp[i] = max(dp[i], dp[j] + (n - lcp[j][i] - i));           }         }       }       cout << *max_element(dp.begin(), dp.end()) <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int64_t MAXN = 1000000007;   struct point {     int64_t x = 0;     int64_t y = 0;     point(const int64_t& x, const int64_t& y) : x(x), y(y) {}     static point read() {       int64_t x, y;       cin >> x >> y;       return point(x, y);     }   };   double distance(const int64_t& x1, const int64_t& y1, const int64_t& x2,                   const int64_t& y2) {     return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));   }   signed main() {     int64_t n, k;     cin >> n >> k;     double total = 0.0;     int64_t x1, y1;     int64_t x2, y2;     cin >> x1 >> y1;     while (--n) {       cin >> x2 >> y2;       total += distance(x1, y1, x2, y2);       x1 = x2;       y1 = y2;     }     total = total * k / 50;     printf( %.6f , total);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class L, class R>   ostream& operator<<(ostream& os, pair<L, R> P) {     return os <<  (  << P.first <<  ,  << P.second <<  ) ;   }   template <class T>   ostream& operator<<(ostream& os, vector<T> V) {     os <<  [  ;     for (auto v : V) os << v <<    ;     return os <<  ] ;   }   template <class T>   ostream& operator<<(ostream& os, set<T> second) {     os <<  {  ;     for (auto s : second) os << s <<    ;     return os <<  } ;   }   template <class L, class R>   ostream& operator<<(ostream& os, map<L, R> M) {     os <<  {  ;     for (auto m : M) os <<  (  << m.first <<   :   << m.second <<  )  ;     return os <<  } ;   }   template <typename Arg1>   void __f(const char* name, Arg1&& arg1) {     cout << name <<   :   << arg1 <<   n ;   }   template <typename Arg1, typename... Args>   void __f(const char* names, Arg1&& arg1, Args&&... args) {     const char* comma = strchr(names + 1,  , );     cout.write(names, comma - names) <<   :   << arg1 <<   | ;     __f(comma + 1, args...);   }   void solve() {     map<int, int> cnt;     int n;     cin >> n;     for (int i = 0; i < n; ++i) {       int x;       cin >> x;       cnt[x]++;     }     int a = -1;     for (int i = 0; i <= 101; ++i) {       if (cnt[i] == 0) {         cout << i + (a == -1 ? i : a) <<   n ;         return;       } else if (cnt[i] == 1 and a == -1) {         a = i;       }     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int T = 1, tc = 1;     cin >> T;     while (T--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = (int)2e5 + 7;   int n, m, q;   set<int> ds[N];   set<int> us[N];   struct T {     int min_d;     int max_u;     bool ok;   };   T operator+(T a, T b) {     int min_d = min(a.min_d, b.min_d);     int max_u = max(a.max_u, b.max_u);     bool ok = a.ok & b.ok & (a.min_d > b.max_u);     return {min_d, max_u, ok};   }   T t[4 * N];   void rec(int v, int tl, int tr, int i) {     if (tr < i || i < tl) {       return;     }     if (tl == tr) {       auto it1 = ds[tl].begin();       t[v].min_d = *it1;       auto it2 = us[tl].end();       it2--;       t[v].max_u = *it2;       t[v].ok = (t[v].min_d > t[v].max_u);       return;     }     int tm = (tl + tr) / 2;     rec(2 * v, tl, tm, i);     rec(2 * v + 1, tm + 1, tr, i);     t[v] = t[2 * v] + t[2 * v + 1];   }   void ins(int r, int c) {     int x = (r + 1) / 2, y = (c + 1) / 2;     if (r % 2 == 1) {       ds[x].insert(y);     } else {       us[x].insert(y);     }     rec(1, 1, n, x);   }   void del(int r, int c) {     int x = (r + 1) / 2, y = (c + 1) / 2;     if (r % 2 == 1) {       ds[x].erase(y);     } else {       us[x].erase(y);     }     rec(1, 1, n, x);   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m >> q;     for (int i = 1; i <= n; i++) {       ds[i].insert((int)1e9);       us[i].insert(-(int)1e9);       rec(1, 1, n, i);     }     set<pair<int, int>> s;     for (int i = 1; i <= q; i++) {       int r, c;       cin >> r >> c;       if (s.count({r, c}) == 0) {         ins(r, c);         s.insert({r, c});       } else {         del(r, c);         s.erase({r, c});       }       if (t[1].ok) {         cout <<  YES n ;       } else {         cout <<  NO n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int N, M, K, dp[505][505];   char g[505][505];   bool check(int r, int c) {     int dx[] = {-1, 1, 0, 0};     int dy[] = {0, 0, -1, 1};     if (r < 0 || c < 0) return false;     if (g[r][c] ==  0 ) return false;     for (int i = 0; i < 4; ++i) {       int nextR = r + dx[i];       int nextC = c + dy[i];       if (nextR < 0 || nextC < 0) return false;       if (g[nextR][nextC] ==  0 ) return false;     }     return true;   }   int cntStars(int r1, int c1, int r2, int c2) {     return dp[r2][c2] - dp[r1 + 1][c2] - dp[r2][c1 + 1] + dp[r1 + 1][c1 + 1];   }   int main() {     scanf( %d %d %d , &N, &M, &K);     for (int i = 0; i < N; ++i) scanf( %s , &g[i]);     for (int i = 0; i < N; ++i) {       for (int j = 0; j < M; ++j) {         dp[i + 1][j + 1] =             dp[i][j + 1] + dp[i + 1][j] - dp[i][j] + check(i - 1, j - 1);       }     }     long long res = 0;     for (int r2 = 3; r2 <= N; ++r2) {       for (int c2 = 3; c2 <= M; ++c2) {         int c1 = c2 - 2;         for (int r1 = 1; r1 < r2 - 1; ++r1) {           while (c1 >= 1 && cntStars(r1, c1, r2, c2) < K) --c1;           if (c1 >= 1 && cntStars(r1, c1, r2, c2) >= K) res += c1;         }       }     }     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INFI = 2000000000;   const int goX[4] = {-1, 0, 1, 0};   const int goY[4] = {0, 1, 0, -1};   const string PROBLEM_NAME =  test ;   const string INPUT_FILE = PROBLEM_NAME +  .in ;   const string OUTPUT_FILE = PROBLEM_NAME +  .out ;   ofstream fout(OUTPUT_FILE.c_str());   ifstream fin(INPUT_FILE.c_str());   void read_input() {}   long long a, b, c, d, e, f;   string solve() {     if (c == 0 && d > 0) return  Ron ;     if (a == 0 && b > 0 && d > 0) return  Ron ;     if (b == 0 || d == 0 || f == 0) return  Hermione ;     if (a == 0 || c == 0 || e == 0) return  Ron ;     return (a * c * e < b * d * f) ?  Ron  :  Hermione ;   }   void m_main() {     cin >> a >> b >> c >> d >> e >> f;     cout << solve() << endl;   }   int main() {     read_input();     m_main();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void input() {     freopen( give_me.txt ,  r , stdin);     freopen( see_it.txt ,  w , stdout);   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     long long n, k;     cin >> n >> k;     long long a[n], sum = 0, w = n - k + 1;     for (int i = 0; i < n; i++) cin >> a[i];     long long gun[n], cur = 1, mx = k;     if (k > n / 2) mx = (n - k) + 1;     if (n % 2 == 0) {       for (int i = 0; i < n / 2; i++) {         gun[i] = cur;         gun[n - i - 1] = cur;         if (cur <= mx - 1) cur++;       }     } else {       for (int i = 0; i <= n / 2; i++) {         gun[i] = cur;         gun[n - i - 1] = cur;         if (cur <= k - 1) cur++;       }     }     for (int i = 0; i < n; i++) {       sum += (a[i] * gun[i]);     }     double ans = (1.0 * sum / w);     printf( %.6lf , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long double eps = 1e-12;   const int maxn = 100000 + 1912;   const int MX = 1e6;   int n;   pair<int, int> a[maxn];   vector<int> p[MX * 2 + 3];   long long res = 0;   void ReadData() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d%d , &a[i].first, &a[i].second);       a[i].first += MX;       a[i].second += MX;       p[a[i].first].push_back(a[i].second);     }     for (int i = 0; i <= MX * 2; i++)       if (((int)p[i].size())) sort(p[i].begin(), p[i].end());   }   bool Found(int x, int y) {     if (x < 0 || x > MX * 2) return false;     vector<int>::iterator it = lower_bound(p[x].begin(), p[x].end(), y);     if (it != p[x].end() && (*it) == y) return true;     return false;   }   void Process() {     for (int i = 0; i <= MX * 2; i++)       if (((int)p[i].size())) {         if (((int)p[i].size()) <= 520) {           for (int fi = 0; fi < ((int)p[i].size()); fi++)             for (int se = 0; se < fi; se++) {               int len = p[i][fi] - p[i][se];               if (i >= len && Found(i - len, p[i][se]) &&                   Found(i - len, p[i][fi]))                 res++;             }         } else {           for (int j = 0; j <= i - 1; j++) {             int len = i - j;             for (int k = 0; k < ((int)p[j].size()); k++) {               if (Found(i, p[j][k]) && Found(j, p[j][k] + len) &&                   Found(i, p[j][k] + len))                 res++;             }           }         }       }     cout << res << endl;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     ReadData();     Process();   }


#include <bits/stdc++.h>   using namespace std;   void setIO(string name) {     freopen((name +  .in ).c_str(),  r , stdin);     freopen((name +  .out ).c_str(),  w , stdout);   }   long long inv(long long base, long long mod = 998244353) {     if (base == 0) return mod;     long long res = (1 - mod * inv(mod % base, base)) / base;     return (res < 0) ? res + mod : res;   }   int N;   int c[300001];   long long pref[300001];   long long mod = 998244353ll;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> N;     for (int i = 1; i < N + 1; i++) cin >> c[i];     sort(c + 1, c + N + 1, greater<int>());     for (int i = 1; i < N + 1; i++) pref[i] = (pref[i - 1] + c[i]) % mod;     for (int k = 1; k < N + 1; k++) {       long long score = 0;       long long i;       for (i = k; i <= N; i += k) {         score += (pref[i] - pref[i - k] + mod) * (i / k - 1) % mod;         if (score > mod) score -= mod;       }       score +=           (i + k > N) ? (pref[N] - pref[i - k] + mod) * (i / k - 1) % mod : 0;       if (score > mod) score -= mod;       score *= inv(N);       score %= mod;       cout << score <<    ;     }     return 0;   }


#include <bits/stdc++.h>   int main() {     int n, i, j, r;     char lvl[110];     scanf( %d , &n);     scanf(  %s , lvl);     for (r = 1; r < n; r++) {       for (i = 0; i < n; i++) {         for (j = 0; j <= 4; j++) {           if (i + j * r >= n || lvl[i + j * r] !=  * ) break;         }         if (j >= 5) {           printf( yes n );           return 0;         }       }     }     printf( no n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int x, y;     cin >> x >> y;     int m = 0;     while (x * 100 + y * 10 >= 220) {       int kx, ky;       if (m % 2 == 0) {         kx = min(2, x);         x -= kx;         ky = (220 - 100 * kx) / 10;         y -= ky;         if (y < 0) break;       } else {         if (y >= 22)           ky = 22;         else if (y >= 12)           ky = 12;         else           ky = 2;         y -= ky;         if (y < 0) break;         kx = (220 - ky * 10) / 100;         x -= kx;         if (x < 0) break;       }       m++;     }     if (m % 2 == 1) {       cout <<  Ciel n ;     } else       cout <<  Hanako n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2000 + 10;   const int maxm = 4e5 + 10;   const long long mod = 1e9 + 7;   const int inf = 0x3f3f3f3f;   const double eps = 1e-5;   const double pi = acos(-1.0);   int t;   int n, a[maxn];   int cnt[maxn];   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> t;     while (t--) {       cin >> n;       vector<int> res;       for (int i = 0; i <= n; i++) cnt[i] = 0;       for (int i = 0; i < n; i++) {         cin >> a[i];         cnt[a[i]]++;       }       int now;       while (1) {         now = 0;         bool flag = false;         for (int i = 1; i < n; i++)           if (a[i] < a[i - 1]) flag = true;         if (flag == false) break;         for (int i = 0; i < n; i++) {           if (cnt[i])             now = i + 1;           else             break;         }         if (now == n) {           int index = 0, minnum = maxn;           for (int i = 0; i < n; i++)             if (a[i] != i) {               if (a[i] < minnum) {                 index = i;                 minnum = a[i];               }             }           int p = a[index];           cnt[p]--;           cnt[now]++;           a[index] = now;           res.push_back(index);           continue;         }         int p = a[now];         cnt[p]--;         cnt[now]++;         a[now] = now;         res.push_back(now);       }       cout << res.size() << endl;       for (int i = 0; i < res.size(); i++) cout << res[i] + 1 <<    ;       cout << endl;     }     return ~~(0 - 0);   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1 << 17;   int st[N], op[N], sz[N], dp[N], pid[N], c[N], hd[N], p[N], f[N], g[N], add[N];   double ans[N];   vector<int> adj[N], V[N];   long long sum[N];   int T, pn;   void dfs(int u) {     sz[u] = 1;     dp[u] = dp[p[u]] + 1;     for (auto v : adj[u]) {       dfs(v);       sz[u] += sz[v];     }   }   void dfs1(int u) {     st[u] = ++T;     pid[u] = pn;     if (!hd[pn]) hd[pn] = u;     int w = 0;     for (auto v : adj[u])       if (sz[v] > sz[w]) w = v;     if (w) dfs1(w);     for (auto v : adj[u]) {       if (v != w) {         pn++;         dfs1(v);       }     }   }   long long ret2, ret1;   void renew(int u, int l, int k) {     add[u] += k;     sum[u] += k * l;   }   void push_down(int u, int l) {     if (add[u]) {       renew(u + u, (l + 1) / 2, add[u]);       renew(u + u + 1, l / 2, add[u]);       add[u] = 0;     }   }   void push_up(int u) { sum[u] = sum[u + u] + sum[u + u + 1]; }   void modify(int u, int l, int r, int ll, int rr, int k) {     if (ll <= l && r <= rr) {       renew(u, r - l + 1, k);       return;     }     int mid = l + r >> 1;     push_down(u, r - l + 1);     if (ll <= mid) modify(u + u, l, mid, ll, rr, k);     if (mid < rr) modify(u + u + 1, mid + 1, r, ll, rr, k);     push_up(u);   }   long long query(int u, int l, int r, int ll, int rr) {     if (ll <= l && r <= rr) return sum[u];     int mid = l + r >> 1;     long long ret = 0;     push_down(u, r - l + 1);     if (ll <= mid) ret += query(u + u, l, mid, ll, rr);     if (mid < rr) ret += query(u + u + 1, mid + 1, r, ll, rr);     return ret;   }   int n;   void update(int u, int k) {     ret1 += k * dp[u];     ret2 += dp[u];     while (u) {       int l = hd[pid[u]];       ret2 += 2 * k * query(1, 1, n, st[l], st[u]);       modify(1, 1, n, st[l], st[u], k);       u = p[l];     }   }   int main() {     int m, q, C;     scanf( %d%d%d%d , &n, &m, &q, &C);     for (int i = 1; i <= n; i++)       scanf( %d , &f[i]), V[f[i]].push_back(i), g[i] = f[i];     for (int i = 2; i <= n; i++) scanf( %d , &p[i]), adj[p[i]].push_back(i);     for (int i = 1; i <= m; i++) scanf( %d , &c[i]);     for (int i = 1; i <= q; i++) {       scanf( %d , &op[i]);       if (op[i] == 1) {         int x, w;         scanf( %d%d , &x, &w);         V[g[x]].push_back(-x);         g[x] = w;         V[g[x]].push_back(x);       } else {         int k;         scanf( %d , &k);         V[k].push_back(n + i);       }     }     dfs(1);     dfs1(1);     set<int> S;     for (int i = 1; i <= m; i++) {       for (auto e : S) update(e, -1);       S.clear();       ret2 = 0, ret1 = 0;       for (int event : V[i]) {         if (event < 0) {           S.erase(-event);           update(-event, -1);         } else if (event <= n) {           S.insert(event);           update(event, 1);         } else {           ans[event - n] = (long double)(ret2 * c[i] * c[i] -                                          2 * ret1 * c[i] * C + C * 1LL * C * n) /                            n;         }       }     }     for (int i = 1; i <= q; i++)       if (op[i] == 2) printf( %.10lf n , ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     std::ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long int n, even = 0, odd = 0;     cin >> n;     long long int a[n];     for (long long int i = 0; i < n; i++) cin >> a[i];     if (n == 1)       cout << a[0] <<   n ;     else {       sort(a, a + n);       long long int flag = 0;       for (long long int i = 1; i < n; i++) {         if (a[i] % a[0] != 0) {           flag = 1;           break;         }       }       if (flag == 0)         cout << a[0] <<   n ;       else         cout <<  -1               <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   using namespace std;   void _print(long long int t) { cerr << t; }   void _print(int t) { cerr << t; }   void _print(string t) { cerr << t; }   void _print(char t) { cerr << t; }   void _print(long double t) { cerr << t; }   void _print(double t) { cerr << t; }   void _print(unsigned long long t) { cerr << t; }   template <class T, class V>   void _print(pair<T, V> p);   template <class T>   void _print(vector<T> v);   template <class T>   void _print(set<T> v);   template <class T, class V>   void _print(map<T, V> v);   template <class T>   void _print(multiset<T> v);   template <class T, class V>   void _print(pair<T, V> p) {     cerr <<  { ;     _print(p.first);     cerr <<  , ;     _print(p.second);     cerr <<  } ;   }   template <class T>   void _print(vector<T> v) {     cerr <<  [  ;     for (T i : v) {       _print(i);       cerr <<    ;     }     cerr <<  ] ;   }   template <class T>   void _print(set<T> v) {     cerr <<  [  ;     for (T i : v) {       _print(i);       cerr <<    ;     }     cerr <<  ] ;   }   template <class T>   void _print(multiset<T> v) {     cerr <<  [  ;     for (T i : v) {       _print(i);       cerr <<    ;     }     cerr <<  ] ;   }   template <class T, class V>   void _print(map<T, V> v) {     cerr <<  [  ;     for (auto i : v) {       _print(i);       cerr <<    ;     }     cerr <<  ] ;   }   long long int mod1 = 1e9 + 7;   long long int INF = 1e9 + 5;   long long int mod = 998244353;   void solve(long long int test_case) {     string s;     cin >> s;     long long int n = s.size();     long long int take = n / 2;     string ans, rev;     long long int i = 0, j = n - 1;     while (j >= i && take > 0) {       if (j > i && s[i] == s[j]) {         ans.push_back(s[i]);         rev.push_back(s[i]);         i++;         j--;         take -= 2;       } else if (j - 1 > i && s[i] == s[j - 1]) {         ans.push_back(s[i]);         rev.push_back(s[i]);         j -= 2;         i++;         take -= 2;       } else if (j > i + 1 && s[i + 1] == s[j]) {         ans.push_back(s[j]);         rev.push_back(s[j]);         j--;         i += 2;         take -= 2;       } else if (j - 1 > i + 1 && s[j - 1] == s[i + 1]) {         ans.push_back(s[j - 1]);         rev.push_back(s[j - 1]);         j -= 2;         i += 2;         take -= 2;       } else {         ans.push_back(s[i]);         i++;         take--;         break;       }     }     reverse(rev.begin(), rev.end());     ans += rev;     if (take > 0 || ans.size() < n / 2) {       cout <<  IMPOSSIBLE n ;     } else {       cout << ans;     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long int t = 1;     long long int i = 1ll;     while (t--) {       solve(i);       i++;     }   }


#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1.0);   template <class T>   T SQR(const T &a) {     return a * a;   }   void run() {     int A[4][4];     int n;     cin >> n;     int B[16];     for (int i = (0), ei = (n * n); i < ei; i++) scanf( %d , B + i);     int nsq = n * n;     sort(B, B + nsq);     int S[4], G[4];     do {       memset(S, 0, 16);       for (int i = (0), ei = (n); i < ei; i++)         for (int j = (0), ej = (n); j < ej; j++) S[i] += B[i * n + j];       bool ok = 1;       for (int i = (1), ei = (n); i < ei; i++)         if (S[i] != S[0]) ok = 0;       if (!ok) continue;       memset(G, 0, 16);       for (int j = (0), ej = (n); j < ej; j++)         for (int i = (0), ei = (n); i < ei; i++) G[j] += B[i * n + j];       if (S[0] != G[0]) continue;       for (int i = (1), ei = (n); i < ei; i++)         if (G[i] != G[0]) ok = 0;       int d = 0;       for (int i = (0), ei = (n); i < ei; i++) d += B[i * n + i];       if (d != S[0]) continue;       d = 0;       for (int i = (0), ei = (n); i < ei; i++) d += B[i * n + n - i - 1];       if (d != S[0]) continue;       if (ok) {         printf( %d n , S[0]);         for (int i = (0), ei = (n); i < ei; i++)           for (int j = (0), ej = (n); j < ej; j++) {             printf( %d , B[i * n + j]);             if (j != n - 1)               putchar(   );             else               putchar(  n );           }         return;       }     } while (next_permutation(B, B + nsq));   }   int main() {     time_t beg = clock();     run();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 5e5 + 10;   long long n;   vector<long long> v;   void init() {     for (int i = 0; i <= 38; i++) v.push_back(pow(3, i));   }   int main() {     init();     int t;     cin >> t;     while (t--) {       cin >> n;       long long res = 0, cur = 0;       while (res < n) {         res += v[cur];         cur++;       }       while (cur >= 0) {         if (res - v[cur] >= n) res -= v[cur];         cur--;       }       cout << res << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   T gcd(T a, T b) {     return b ? gcd(b, a % b) : a;   }   const int maxn = 1000100;   char s[maxn];   vector<int> a[maxn];   void solve() {     cin >> s;     int n = strlen(s);     int c = 0;     for (int i = 0; i < n; i++) {       c += s[i] ==  0  ? 1 : -1;       if (c < 0) {         puts( -1 );         return;       }     }     c = 0;     for (int i = n - 1; i >= 0; i--) {       c += s[i] ==  0  ? 1 : -1;       if (c < 0) {         puts( -1 );         return;       }     }     int nol = 0, bir = 0;     for (int i = 0; i < n; i++) {       if (s[i] ==  0 ) {         if (bir) {           a[bir - 1].push_back(i + 1);           bir--;         } else {           nol++;           a[nol - 1].push_back(i + 1);         }       } else {         a[bir].push_back(i + 1);         bir++;       }     }     cout << nol << endl;     for (int i = 0; i < nol; i++) {       printf( %d , a[i].size());       for (int j = 0; j < a[i].size(); j++) printf(  %d , a[i][j]);       cout << endl;     }   }   int main() {     int t = 1;     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 11;   const long long mod = 1e9 + 7;   const int inf = 1e9;   const int bl = 320;   deque<int> arr[bl];   int cnt[bl][N];   void shift(int l, int r) {     vector<int> a;     int b = l / bl;     while (!arr[b].empty()) {       a.push_back(arr[b].front());       arr[b].pop_front();     }     int last = a[r - b * bl];     for (int i = l - b * bl; i <= r - b * bl; i++) {       swap(a[i], last);     }     while (!a.empty()) {       arr[b].push_front(a.back());       a.pop_back();     }   }   int del(int first) {     int b = first / bl;     int second = first - b * bl;     vector<int> a;     for (int i = 0; i < second; i++) {       a.push_back(arr[b].front());       arr[b].pop_front();     }     int res = arr[b].front();     arr[b].pop_front();     while (!a.empty()) {       arr[b].push_front(a.back());       a.pop_back();     }     return res;   }   void add(int first, int val) {     int b = first / bl;     int second = first - b * bl;     vector<int> a;     for (int i = arr[b].size() - 1; i >= second; i--) {       a.push_back(arr[b].back());       arr[b].pop_back();     }     arr[b].push_back(val);     while (!a.empty()) {       arr[b].push_back(a.back());       a.pop_back();     }   }   void solve() {     int n;     cin >> n;     arr[0].push_back(0);     for (int i = 1; i <= n; i++) {       int first;       cin >> first;       arr[i / bl].push_back(first);       cnt[i / bl][first]++;     }     int q;     cin >> q;     int lastans = 0;     for (int i = 1; i <= q; i++) {       int type, l, r, k;       cin >> type >> l >> r;       if (type == 1) {         l = (l + lastans - 1) % n + 1;         r = (r + lastans - 1) % n + 1;         if (l > r) swap(l, r);         if (l / bl == r / bl) {           shift(l, r);         } else {           int last = del(r);           cnt[r / bl][last]--;           add(l, last);           cnt[l / bl][last]++;           for (int i = l / bl; i <= r / bl; i++) {             if (i > l / bl) {               arr[i].push_front(last);               cnt[i][last]++;             }             if (i < r / bl) {               int first = arr[i].back();               arr[i].pop_back();               cnt[i][first]--;               last = first;             }           }         }       } else {         cin >> k;         l = (l + lastans - 1) % n + 1;         r = (r + lastans - 1) % n + 1;         k = (k + lastans - 1) % n + 1;         if (l > r) swap(l, r);         int ans = 0;         if (l / bl == r / bl) {           int b = l / bl;           for (int i = l - b * bl; i <= r - b * bl; i++) {             if (arr[b][i] == k) ans++;           }         } else {           int b = l / bl;           for (int i = l; i < (b + 1) * bl; i++) {             if (arr[b][i - b * bl] == k) ans++;           }           b = r / bl;           for (int i = b * bl; i <= r; i++) {             if (arr[b][i - b * bl] == k) ans++;           }           for (int i = l / bl + 1; i < r / bl; i++) {             ans += cnt[i][k];           }         }         cout << ans <<   n ;         lastans = ans;       }     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0), cout.tie(0);     int T = 1;     while (T--) {       solve();       cout <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int MX = 5005;   int n, m;   int n1, n2, n3;   vector<int> g[5005];   int pars[5005];   map<int, vector<int>> roots;   vector<int> roots_v;   vector<int> cs;   int rootNum = 0;   bool dp[5005][5005][2];   int find(int u) {     if (pars[u] == u) return u;     int p = find(pars[u]);     pars[u] = p;     return p;   }   void un(int u, int v) {     int pu = find(u), pv = find(v);     pars[pv] = pu;   }   bool color(int u, int c) {     stack<vector<int>> sk;     sk.push({u, c});     while (!sk.empty()) {       vector<int> it = sk.top();       sk.pop();       u = it[0];       c = it[1];       if (cs[u] != 0 && cs[u] != c) return false;       if (cs[u] != 0) continue;       int pu = find(u);       cs[u] = c;       roots[pu][c]++;       int nc = c == 1 ? 2 : 1;       for (int v : g[u]) {         if (cs[v] == 0) sk.push({v, nc});       }     }     return true;   }   void solve() {     for (int u = 1; u <= n; u++) {       pars[u] = u;     }     for (int u = 1; u <= n; u++) {       for (int v : g[u]) {         un(u, v);       }     }     for (int u = 1; u <= n; u++) {       int pu = find(u);       roots[pu] = vector<int>(3);     }     cs = vector<int>(n + 1, 0);     for (auto it = roots.begin(); it != roots.end(); it++) {       int u = it->first;       roots_v.push_back(u);       if (!color(u, 1)) {         cout <<  NO  << endl;         return;       }     }     rootNum = roots.size();     memset(dp, 0, sizeof(dp));     int root = roots_v[0];     if (roots[root][2] <= n2) dp[0][roots[root][2]][0] = 1;     if (roots[root][1] <= n2) dp[0][roots[root][1]][1] = 1;     for (int i = 1; i < rootNum; i++) {       root = roots_v[i];       int c1 = roots[root][1], c2 = roots[root][2];       for (int v = 0; v <= n2; v++) {         if (v >= c2) {           dp[i][v][0] = dp[i - 1][v - c2][0] || dp[i - 1][v - c2][1];         }         if (v >= c1) {           dp[i][v][1] = dp[i - 1][v - c1][0] || dp[i - 1][v - c1][1];         }       }     }     if (!dp[rootNum - 1][n2][0] && !dp[rootNum - 1][n2][1]) {       cout <<  NO  << endl;       return;     }     int i = rootNum - 1;     int tar = n2;     map<int, int> reverse;     while (i >= 0) {       int root = roots_v[i];       if (dp[i][tar][1]) {         reverse[root] = 1;         tar -= roots[root][1];       } else {         reverse[root] = 0;         tar -= roots[root][2];       }       i--;     }     for (int u = 1; u <= n; u++) {       int pu = find(u);       if (reverse[pu]) {         cs[u] = cs[u] == 1 ? 2 : 1;       }     }     int x = n3;     for (int u = 1; u <= n && x; u++) {       if (cs[u] == 1) {         cs[u] = 3;         x--;       }     }     cout <<  YES  << endl;     for (int u = 1; u <= n; u++) {       cout << cs[u];     }     cout << endl;   }   int main() {     cin >> n >> m >> n1 >> n2 >> n3;     for (int i = 0; i < m; i++) {       int u, v;       cin >> u >> v;       g[u].push_back(v);       g[v].push_back(u);     }     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long begtime = clock();   template <typename Arg1>   void __f(const char* name, Arg1&& arg1) {     cout << name <<   :   << arg1 <<   n ;   }   template <typename Arg1, typename... Args>   void __f(const char* names, Arg1&& arg1, Args&&... args) {     const char* comma = strchr(names + 1,  , );     cout.write(names, comma - names) <<   :   << arg1 <<   |  ;     __f(comma + 1, args...);   }   void splitx(string s, char c, vector<string>& v) {     long long i = 0, j;     while (i < (long long)(s).size()) {       j = i;       string temp;       while (j < (long long)(s).size() && s[j] != c) {         temp += s[j];         j++;       }       v.push_back(temp);       i = j + 1;     }   }   vector<long long> dx{1, 0, -1, 0, 1, 1, -1, -1};   vector<long long> dy{0, 1, 0, -1, 1, -1, 1, -1};   signed main() {     std::ios::sync_with_stdio(false);     cin.tie(NULL);     long long n, m, k;     cin >> n >> m >> k;     vector<string> v(n);     for (long long i = 0; i < n; i++) {       cin >> v[i];     }     vector<vector<long long> > vis(n, vector<long long>(m, 0));     vector<vector<long long> > dist(n, vector<long long>(m, 1000000000000000007));     long long x1, y1, x2, y2;     cin >> x1 >> y1 >> x2 >> y2;     x1--;     y1--;     x2--;     y2--;     queue<pair<long long, long long> > q;     q.push({x1, y1});     dist[x1][y1] = 0;     while (!q.empty()) {       pair<long long, long long> p = q.front();       q.pop();       long long x = p.first;       long long y = p.second;       if (vis[x][y]) continue;       vis[x][y] = 1;       for (long long i = 0; i < 4; i++) {         for (long long j = 1; j < k + 1; j++) {           long long nx = x + dx[i] * j;           long long ny = y + dy[i] * j;           if (nx < 0 || nx >= n || ny < 0 || ny >= m) break;           if (v[nx][ny] ==  #  || dist[nx][ny] < dist[x][y] + 1) break;           dist[nx][ny] = dist[x][y] + 1;           q.push({nx, ny});         }       }     }     if (dist[x2][y2] == 1000000000000000007) {       cout << -1 <<   n ;     } else {       cout << dist[x2][y2] <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 203;   const int mod = 1e9 + 7;   vector<int> g[N];   int dp[N];   int ans, n;   int len1, len2;   void cal(int u, int fa, int &len) {     dp[u] = 0;     int &mx1 = dp[u], mx2 = 0;     int v;     for (__typeof((g[u]).begin()) v = (g[u]).begin(); v != (g[u]).end(); v++) {       if (*v == fa) continue;       cal(*v, u, len);       if (mx2 < dp[*v] + 1) {         mx2 = dp[*v] + 1;         if (mx2 > mx1) swap(mx1, mx2);       }     }     len = max(len, mx1 + mx2);   }   void dfs(int u, int fa) {     int v;     for (__typeof((g[u]).begin()) v = (g[u]).begin(); v != (g[u]).end(); v++) {       if (*v == fa) continue;       len1 = len2 = 0;       cal(*v, u, len1);       cal(u, *v, len2);       ans = max(ans, len1 * len2);       dfs(*v, u);     }   }   int main() {     int i, j;     scanf( %d , &n);     for (i = 1; i < n; i++) {       int x, y;       scanf( %d%d , &x, &y);       g[x].push_back(y);       g[y].push_back(x);     }     dfs(1, 0);     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, k;   long long a[200010];   long long b[200010];   int s[200010];   long long ans;   bool check(long long val) {     memset(s, 0, sizeof(s));     int num = k;     for (int i = 1; i <= n; i++) {       if (!b[i]) {         continue;       }       long long sum = a[i];       s[min(sum / b[i] + 1, 1ll * (k + 1))]++;       while (sum < 1ll * k * b[i]) {         if (!num) {           break;         }         sum += val;         s[min(sum / b[i] + 1, 1ll * (k + 1))]++;         num--;       }     }     for (int i = 1; i <= k; i++) {       s[i] += s[i - 1];       if (s[i] > i) {         return false;       }     }     return true;   }   int main() {     scanf( %d%d , &n, &k);     k--;     for (int i = 1; i <= n; i++) {       scanf( %lld , &a[i]);     }     for (int i = 1; i <= n; i++) {       scanf( %lld , &b[i]);     }     long long l = 0, r = 2000000000000ll;     while (l <= r) {       long long mid = (l + r) >> 1;       if (check(mid)) {         ans = mid;         r = mid - 1;       } else {         l = mid + 1;       }     }     if (!ans) {       printf(check(0) ?  0  :  -1 );     } else {       printf( %lld , ans);     }   }


#include <bits/stdc++.h>   using namespace std;   void require(bool cond, const string& message =  Runtime error ) {     if (!cond) {       cerr << message << endl;       assert(false);     }   }   void readData() {}   long long mina, maxa;   void solve(long long x, long long n) {     long long m = n / x;     for (long long y = 1; y * y <= m; ++y) {       if (m % y) continue;       long long z = m / y;       long long nn = (x + 1) * (y + 2) * (z + 2);       if (mina == -1) mina = nn - n;       mina = min(mina, nn - n);       maxa = max(maxa, nn - n);     }   }   void solve() {     long long n;     cin >> n;     mina = -1;     maxa = 1;     for (long long x = 1; x * x <= n; ++x) {       if (n % x) continue;       solve(x, n);       solve(n / x, n);     }     cout << mina <<     << maxa << endl;   }   int main() {     ios_base::sync_with_stdio(false);     readData();     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long arr[1005];   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long t;     cin >> t;     while (t--) {       long long n;       cin >> n;       for (long long i = 0; i < n; i++) {         cin >> arr[i];       }       long long left = 1;       long long right = n - 1;       long long cnt = 1;       long long leftSum, rightSum;       leftSum = rightSum = 0;       leftSum = arr[0];       long long turn = 1;       long long prevSum = arr[0];       while (left <= right) {         if (turn == 0) {           long long currSum = 0;           while (currSum <= prevSum) {             currSum += arr[left];             left++;             if (left > right) break;           }           prevSum = currSum;           leftSum += currSum;           turn = 1;         } else {           long long currSum = 0;           while (currSum <= prevSum) {             currSum += arr[right];             right--;             if (left > right) break;           }           prevSum = currSum;           rightSum += currSum;           turn = 0;         }         cnt++;       }       cout << cnt <<     << leftSum <<     << rightSum <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MXN = 100100;   const int QQ = 500;   const int INF = (int)1e9;   const long long LINF = (long long)1e18;   const int mod = 1000000007;   set<pair<int, int> > eds;   int x[MXN];   int main() {     int n, m;     scanf( %d%d , &n, &m);     int a, b;     for (int i = 0; i < (m); i++) {       scanf( %d%d , &a, &b);       eds.insert(make_pair(a, b));       eds.insert(make_pair(b, a));     }     for (int i = 0; i < (n); i++) x[i] = i + 1;     for (int i = 0; i < (QQ); i++) {       random_shuffle(x, x + n);       bool bad = false;       for (int i = 0; i < (m); i++)         if (eds.find(make_pair(x[i % n], x[(i + 1) % n])) != eds.end()) {           bad = true;           break;         }       if (bad) continue;       for (int i = 0; i < (m); i++) {         printf( %d %d n , x[i % n], x[(i + 1) % n]);       }       return 0;     }     printf( -1 );   }


#include <bits/stdc++.h>   using namespace std;   bool comp(long long a, long long b) {     if (a > b)       return true;     else       return false;   }   int isP(long long n) {     if (n == 1) return 0;     if (n == 2 || n == 3) return 1;     for (long long i = 2; i <= sqrt(n); i++) {       if (n % i == 0) return 0;     }     return 1;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long t, n, k, va;     bool ha;     cin >> t;     while (t--) {       cin >> n >> k;       if (n == 0)         ha = false;       else if (n == 1 || n == 2)         ha = true;       else if (n == 3) {         if (k == 3)           ha = true;         else           ha = false;       } else {         if (k % 3 != 0) {           va = n % 3;           if (va == 0)             ha = false;           else             ha = true;         } else {           n %= (k + 1);           if (n % 3 == 0)             ha = false;           else             ha = true;           if (n == k) ha = true;         }       }       if (ha)         cout <<  Alice n ;       else         cout <<  Bob n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int how_many(string s, vector<string>& deleted) {     int res = 0;     for (auto i : deleted)       for (int j = 0; j < s.size(); j++) {         if (i[j] != s[j]) break;         if (j == s.size() - 1) res++;       }     return res;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     while (t--) {       int n, m;       cin >> n >> m;       vector<string> deleted(n);       for (int i = 0; i < n; i++) cin >> deleted[i];       string res =   ;       long long curr = ((1LL << m) + 1 - n) / 2;       for (int i = 0; i < m; i++) {         long long x = (1LL << (m - i - 1)) - how_many(res +  0 , deleted);         if (x >= curr)           res.push_back( 0 );         else {           res.push_back( 1 );           curr -= x;         }       }       cout << res <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long ans = 0;   int n, m, w[2010];   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) {       scanf( %d , &w[i]);     }     for (int i = 1, a, b; i <= m; i++) {       scanf( %d%d , &a, &b);       ans += min(w[a], w[b]);     }     printf( %d , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   map<string, int> g;   bool can;   int n, i;   char s[100][5];   void find(int x) {     char temp[10];     string ss;     int j;     if (x == 1) {       can = true;       return;     }     if ((s[x][0] == s[x - 1][0]) || (s[x][1] == s[x - 1][1])) {       strcpy(temp, s[x - 1]);       strcpy(s[x - 1], s[x]);       ss.clear();       for (j = 1; j <= x - 1; j++) ss = ss + s[j];       if (g[ss] == 0) {         g[ss] = 1;         find(x - 1);       }       strcpy(s[x - 1], temp);     }     if (x > 3)       if ((s[x][0] == s[x - 3][0]) || s[x][1] == s[x - 3][1]) {         strcpy(temp, s[x - 3]);         strcpy(s[x - 3], s[x]);         for (j = 1; j <= x - 1; j++) ss = ss + s[j];         if (g[ss] == 0) {           g[ss] = 1;           find(x - 1);         }         strcpy(s[x - 3], temp);       }   }   int main() {     can = false;     cin >> n;     g.clear();     memset(s, 0, sizeof(s));     for (i = 1; i <= n; i++) scanf( %s , s[i]);     find(n);     if (can)       cout <<  YES  << endl;     else       cout <<  NO  << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long m, n, p[30], ans;     cin >> m >> n;     for (__typeof(0) i = 0; i <= n - 1; i++) {       cout <<  1 n ;       fflush(stdout);       cin >> ans;       if (ans == 0) return 0;       if (ans == -1)         p[i] = 0;       else         p[i] = 1;     }     long long low = 1, high = m, mid, i = 0;     while (low <= high) {       mid = (low + high) / 2;       cout << mid <<   n ;       fflush(stdout);       cin >> ans;       if (p[i] == 0) ans *= -1;       i = (i + 1) % n;       if (ans == 0 || ans == -2 || ans == 2) return 0;       if (ans == -1)         high = mid - 1;       else if (ans == 1)         low = mid + 1;       else         return 0;     }     return 0;   }


#include <bits/stdc++.h>   inline int Abs(int x) { return x < 0 ? -x : x; }   inline int Sgn(int x) { return x < 0 ? -1 : 1; }   const int MN = 100005, Sig = 26;   const int ML = 100005;   const int MQ = 100005;   const int T = 400;   const int B = 400;   int N, Id[MN], Len[MN];   char str[ML];   int nxt[ML][Sig], faz[ML], fail[ML], Num[ML], cnt;   int que[ML], l, r;   std::vector<int> G[ML];   inline int Ins(char *S) {     int now = 0;     for (; *S; ++S) {       int j = *S -  a ;       if (!nxt[now][j]) nxt[now][j] = ++cnt, faz[cnt] = now;       now = nxt[now][j];     }     return now;   }   inline void BuildAC() {     fail[0] = faz[0] = -1;     que[l = r = 1] = 0;     while (l <= r) {       int u = que[l++];       for (int j = 0; j < Sig; ++j) {         if (nxt[u][j]) {           fail[nxt[u][j]] = u ? nxt[fail[u]][j] : 0;           G[fail[nxt[u][j]]].push_back(nxt[u][j]);           que[++r] = nxt[u][j];         } else           nxt[u][j] = u ? nxt[fail[u]][j] : 0;       }     }   }   int ldf[ML], rdf[ML], dfc;   void DFS(int u) {     ldf[u] = ++dfc;     for (auto v : G[u]) DFS(v);     rdf[u] = dfc;   }   int blk[ML], add[ML], tag[ML / B + 10];   inline void Add(int ql, int qr) {     if (blk[ql] == blk[qr])       for (int i = ql; i <= qr; ++i) ++add[i];     else {       for (int i = ql; blk[i] == blk[ql]; ++i) ++add[i];       for (int i = qr; blk[i] == blk[qr]; --i) ++add[i];       for (int i = blk[ql] + 1; i < blk[qr]; ++i) ++tag[i];     }   }   inline int Qur(int p) { return add[p] + tag[blk[p]]; }   int Q, ql[MQ], qr[MQ], qk[MQ];   long long Ans[MQ];   std::vector<std::pair<int, int>> C0[MN], C1[MN];   int main() {     scanf( %d%d , &N, &Q);     for (int i = 1; i <= N; ++i) {       scanf( %s , str);       Len[i] = strlen(str);       Id[i] = Ins(str);     }     BuildAC();     DFS(0);     for (int i = 1; i <= dfc; ++i) blk[i] = (i - 1) / B + 1;     for (int i = 1; i <= Q; ++i) {       scanf( %d%d%d , &ql[i], &qr[i], &qk[i]);       if (ql[i] > 1) C0[ql[i] - 1].push_back({qk[i], -i});       C0[qr[i]].push_back({qk[i], i});     }     for (int i = 1; i <= N; ++i) {       Add(ldf[Id[i]], rdf[Id[i]]);       for (auto j : C0[i]) {         if (Len[j.first] > T)           C1[j.first].push_back({i, j.second});         else {           int k = j.first;           long long Sum = 0;           for (int x = Id[k]; x != -1; x = faz[x]) Sum += Qur(ldf[x]);           Ans[Abs(j.second)] += Sgn(j.second) * Sum;         }       }     }     for (int i = 1; i <= N; ++i)       if (Len[i] > T) {         for (int x = Id[i]; x != -1; x = faz[x]) ++Num[x];         for (int j = r; j > 1; --j) Num[fail[que[j]]] += Num[que[j]];         int p = 0;         long long Sum = 0;         for (auto x : C1[i]) {           while (p < x.first) Sum += Num[Id[++p]];           Ans[Abs(x.second)] += Sgn(x.second) * Sum;         }         for (int j = 0; j <= cnt; ++j) Num[j] = 0;       }     for (int i = 1; i <= Q; ++i) printf( %lld n , Ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 2 * 100 * 1000 + 100;   int n, dp[MAXN], d[MAXN], mark[MAXN], ans[MAXN], D = 0, MIN = MAXN;   pair<int, int> par[MAXN];   vector<pair<int, int> > g[MAXN];   vector<int> q, depth[MAXN], res;   void bfs() {     for (int i = 0; i < q.size(); i++) {       int v = q[i];       for (int j = 0; j < g[v].size(); j++) {         int u = g[v][j].first;         if (!mark[u]) {           mark[u] = true;           par[u] = make_pair(v, (g[v][j].second + 1) % 2);           d[u] = d[v] + 1;           D = max(D, d[u]);           depth[d[u]].push_back(u);           q.push_back(u);         }       }     }   }   int main() {     cin >> n;     for (int i = 0; i < n - 1; i++) {       int x, y;       cin >> x >> y;       x--, y--;       g[x].push_back(make_pair(y, 0));       g[y].push_back(make_pair(x, 1));     }     d[0] = 0;     mark[0] = true;     q.push_back(0);     depth[0].push_back(0);     bfs();     for (int i = D - 1; i >= 0; i--) {       for (int j = 0; j < depth[i].size(); j++) {         int v = depth[i][j];         for (int z = 0; z < g[v].size(); z++) {           int u = g[v][z].first;           if (u != par[v].first) dp[v] += dp[u] + g[v][z].second;         }       }     }     ans[0] = dp[0];     MIN = ans[0];     for (int i = 1; i <= D; i++) {       for (int j = 0; j < depth[i].size(); j++) {         int v = depth[i][j];         int p = par[v].first;         ans[v] = ans[p];         if (par[v].second == 0)           ans[v] -= 1;         else           ans[v] += 1;         MIN = min(ans[v], MIN);       }     }     cout << MIN << endl;     for (int i = 0; i < n; i++)       if (ans[i] == MIN) cout << i + 1 <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   #pragma comment(linker,  /STACK:102400000,102400000 )   const int INF = 0x3f3f3f3f3f, mod = 1e9 + 7;   const double eps = 1e-6, PI = acos(-1);   template <typename T>   inline void read(T &x) {     x = 0;     T f = 1;     char ch;     do {       ch = getchar();       if (ch ==  - ) f = -1;     } while (ch <  0  || ch >  9 );     do x = x * 10 + ch -  0 , ch = getchar();     while (ch <=  9  && ch >=  0 );     x *= f;   }   long long n, m;   int main() {     read(n), read(m);     long long min1 = max(0LL, n - m * 2);     if (m == 0) {       printf( %lld %lld n , n, n);       return 0;     }     long long max1 = 0;     for (int i = 2; i <= n; i++) {       long long now = 1LL * i * (i - 1) / 2;       if (m <= now) {         max1 = n - i;         break;       }     }     printf( %lld %lld n , min1, max1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int INF = 100000000;   int n, m, x, y;   char ch;   long long int pre[2][(int)1e3 + 5], dp[2][(int)1e3 + 5];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> n >> m >> x >> y;     memset(pre, 0, sizeof(pre));     memset(dp, 0, sizeof(dp));     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         cin >> ch;         if (ch ==  . )           pre[1][j]++;         else           pre[0][j]++;       }     }     for (int i = 1; i <= m; i++) {       pre[0][i] += pre[0][i - 1];       pre[1][i] += pre[1][i - 1];     }     for (int i = 1; i <= m; i++) {       dp[0][i] = INT_MAX;       dp[1][i] = INT_MAX;       for (int j = x; j <= y; j++) {         if (i - j < 0) {           break;         }         dp[0][i] = min(dp[0][i], dp[1][i - j] + pre[0][i] - pre[0][i - j]);         dp[1][i] = min(dp[1][i], dp[0][i - j] + pre[1][i] - pre[1][i - j]);       }     }     cout << min(dp[0][m], dp[1][m]) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 100007, INF = 1000000007;   int main() {     int n, m, k, cnt = 0;     long long d[MAXN], d1[MAXN];     vector<pair<int, int> > G[MAXN];     pair<long long, int> used[MAXN];     set<pair<long long, int> > S;     scanf( %d%d%d , &n, &m, &k);     for (int i = (1); i < (n); ++i) d[i] = d1[i] = 1LL * INF * INF;     for (int i = (0); i < (m); ++i) {       int u, v, x;       scanf( %d%d%d , &u, &v, &x);       --u;       --v;       G[u].push_back(make_pair(v, x));       G[v].push_back(make_pair(u, x));     }     for (int i = (0); i < (k); ++i) {       int s, ys;       scanf( %d%d , &s, &ys);       --s;       d[s] = min(d[s], 1LL * ys);     }     d1[0] = d[0] = 0;     for (int i = (0); i < (n); ++i) S.insert(make_pair(d[i], i));     for (int j = (0); j < (n); ++j) {       int v = S.begin()->second, to;       for (int i = (0); i < (((int)(G[v]).size())); ++i) {         to = G[v][i].first;         if (S.count(make_pair(d[to], to)) && d[v] + G[v][i].second < d[to]) {           S.erase(make_pair(d[to], to));           d[to] = d[v] + G[v][i].second;           S.insert(make_pair(d[to], to));         }       }       S.erase(S.begin());       used[j] = make_pair(d[v], v);     }     sort(used, used + n);     for (int i = (0); i < (n); ++i) {       int v = used[i].second, to;       for (int j = (0); j < (((int)(G[v]).size())); ++j) {         to = G[v][j].first;         d1[v] = min(d1[v], d1[to] + G[v][j].second);       }       if (d1[v] != d[v]) ++cnt;       d1[v] = d[v];     }     printf( %d , k - cnt);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long powerFunction(long long x, long long y) {     long long res = 1;     long long p = 1000000007;     x = x % p;     while (y > 0) {       if (y & 1) res = (res * x) % p;       y = y >> 1;       x = (x * x) % p;     }     return res;   }   bool prime[10000001];   long long P = 1000000007 - 2;   long long fact[10000001] = {0};   void sieveFunction(long long maxLimit) {     memset(prime, true, sizeof(prime));     prime[0] = prime[1] = false;     for (long long i = 2; maxLimit >= i; i++) {       if (prime[i]) {         for (long long j = 2 * i; maxLimit >= j; j += i) prime[j] = false;       }     }   }   void factorialFunction(long long maxLimit) {     fact[0] = 1;     for (long long i = 1; i <= maxLimit; i++)       fact[i] = (fact[i - 1] * i) % 1000000007;     return;   }   long long nCr(long long n, long long r) {     long long a = fact[n];     long long b = powerFunction(fact[n - r], 1000000007 - 2);     long long c = powerFunction(fact[r], 1000000007 - 2);     return (a * (b % 1000000007 * c % 1000000007) % 1000000007) % 1000000007;   }   signed main() {     long long n;     cin >> n;     vector<pair<long long, long long>> adj[n + 1];     long long vis[n + 1];     long long ind;     long long f;     for (long long i = 0; i < n - 1; i++) {       vis[i] = -1;       long long u, v;       cin >> u >> v;       adj[u].push_back({i, v});       adj[v].push_back({i, u});     }     long long p = 0;     for (long long i = 1; i < n + 1; i++) {       if ((long long)adj[i].size() < 3)         continue;       else {         for (auto it : adj[i]) {           if (vis[it.first] == -1) {             vis[it.first] = p;             p++;           }         }       }     }     for (long long i = 0; i < n - 1; i++) {       if (vis[i] == -1) {         vis[i] = p;         p++;       }       cout << vis[i] <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   vector<vector<int>> edge;   int n, m;   int parent[100000];   int size[100000];   int visited[100000];   int finished[100000];   int has_loop[100000];   int find_root(int v) {     if (parent[v] == -1) {       return v;     }     return parent[v] = find_root(parent[v]);   }   void merge(int u, int v) {     u = find_root(u), v = find_root(v);     if (u == v) {       return;     }     if (size[u] < size[v]) {       merge(v, u);       return;     }     parent[v] = u;     size[u] += size[v];   }   void dfs(int here) {     visited[here] = true;     for (int there : edge[here]) {       if (finished[there]) {         continue;       } else if (visited[there]) {         has_loop[find_root(here)] = 1;       } else {         dfs(there);       }     }     finished[here] = true;   }   void loop_check() {     for (int i = 0; i < n; i++) {       if (!visited[i]) {         dfs(i);       }     }   }   int main() {     cin >> n >> m;     edge = vector<vector<int>>(n, vector<int>());     for (int i = 0; i < n; i++) {       parent[i] = -1;       size[i] = 1;     }     for (int i = 0; i < m; i++) {       int from, to;       cin >> from >> to;       edge[from - 1].push_back(to - 1);       merge(from - 1, to - 1);     }     vector<int> wcc_list;     for (int i = 0; i < n; i++) {       if (find_root(i) == i) {         wcc_list.push_back(i);       }     }     loop_check();     int ans = 0;     for (int wcc : wcc_list) {       ans += size[wcc] - 1;       if (has_loop[wcc]) {         ans++;       }     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   int T, a[4], ans;   inline bool cmp(int x, int y) { return x > y; }   int main() {     scanf( %d , &T);     while (T--) {       ans = 0;       scanf( %d%d%d , &a[1], &a[2], &a[3]);       sort(a + 1, a + 3 + 1, cmp);       for (int i = 1; i <= 3; ++i) {         if (a[i]) a[i]--, ans++;       }       for (int i = 1; i <= 2; ++i) {         for (int j = i + 1; j <= 3; ++j) {           if (a[i] && a[j]) ans++, a[i]--, a[j]--;         }       }       if (a[1] && a[2] && a[3]) ans++;       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   bool uin(T &a, T b) {     return a > b ? (a = b, true) : false;   }   template <class T>   bool uax(T &a, T b) {     return a < b ? (a = b, true) : false;   }   long long f[2001], dp[2001][2001], m = 998244353;   long long fun(long long i, long long j) {     if (i == 0)       return (f[j]);     else       return (f[j] - f[i - 1]);   }   long long fpow(long long a, long long p) {     if (p == 0) return (1);     long long b = fpow(a, p / 2);     if (p % 2 == 0)       return ((b * b) % m);     else       return ((((b * b) % m) * a) % m);   }   int main() {     string s;     cin >> s;     if (s[0] ==  ? ) f[0] = 1;     for (long long i = 1; i < s.length(); i++) {       if (s[i] ==  ? ) f[i] += 1;       f[i] += f[i - 1];     }     for (long long i = 2; i <= s.length(); i++) {       for (long long j = 0; j <= (s.length() - i); j++) {         if (s[j] !=  ( )           dp[j][j + i - 1] = (dp[j][j + i - 1] + dp[j + 1][j + i - 1]) % m;         if (s[j + i - 1] !=  ) )           dp[j][j + i - 1] = (dp[j][j + i - 1] + dp[j][j + i - 2]) % m;         if ((s[j] !=  ( ) && (s[j + i - 1] !=  ) ))           dp[j][j + i - 1] = (dp[j][j + i - 1] - dp[j + 1][j + i - 2] + m) % m;         if ((s[j] !=  ) ) && (s[j + i - 1] !=  ( ))           dp[j][j + i - 1] = (dp[j][j + i - 1] + dp[j + 1][j + i - 2] +                               (long long)fpow(2, fun(j + 1, j + i - 2))) %                              m;       }     }     cout << dp[0][s.length() - 1];   }


#include <bits/stdc++.h>   using namespace std;   template <typename T, typename T1>   T amax(T& a, T1 b) {     if (b > a) a = b;     return a;   }   template <typename T, typename T1>   T amin(T& a, T1 b) {     if (b < a) a = b;     return a;   }   const long long N = 200005, INF = 2000000000000000000;   const long long SIX = 1000000;   bool prime(long long n) {     long long i = 0;     for (i = 2; i * i <= n; i++) {       if (n % i == 0) {         return false;       }     }     return true;   }   void solve() {     long long n, k;     cin >> n >> k;     string s;     cin >> s;     long long i = 0;     long long ans = 0;     if (n == 1 && k != 0) {       cout <<  0 ;       return;     }     for (i = 0; i < n; i++) {       if (i == 0 && ans < k) {         if (s[i] !=  1 ) {           s[i] =  1 ;           ans++;         }       } else if (i > 0 && ans < k) {         if (s[i] !=  0 ) {           s[i] =  0 ;           ans++;         }       }     }     cout << s <<   n ;   }   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     long long t;     t = 1;     while (t--) solve();   }


#include <bits/stdc++.h>   using namespace std;   map<pair<long long, long long>, long long> ma;   void put(long long u, long long v, long long w) {     while (v != u) {       long long par;       if (v > u) {         par = v / 2;         ma[make_pair(par, v)] += w;         ma[make_pair(v, par)] += w;         v /= 2;       } else {         par = u / 2;         ma[make_pair(par, u)] += w;         ma[make_pair(u, par)] += w;         u /= 2;       }     }   }   long long solve(long long u, long long v) {     long long ans = 0;     while (v != u) {       long long par;       if (v > u) {         par = v / 2;         ans += ma[make_pair(par, v)];         v /= 2;       } else {         par = u / 2;         ans += ma[make_pair(par, u)];         u /= 2;       }     }     return ans;   }   int main() {     long long u, v, w, ans;     int q, ty;     cin >> q;     while (q--) {       cin >> ty;       if (ty == 1) {         cin >> u >> v >> w;         put(u, v, w);       } else {         cin >> u >> v;         cout << solve(u, v) << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string str, s =  QWERTYUIOPASDFGHJKLZXCVBNM ;     cin >> str;     set<char> m;     long long result = 1;     for (int i = 0; i < str.size(); i++) {       if (str[i] ==  ? ) {         if (i == 0) {           result *= 9;         } else           result *= 10;       } else if (s.find(str[i]) != string::npos) {         if (i == 0) {           result *= 9;           m.insert(str[i]);         } else {           if (m.find(str[i]) == m.end()) {             result *= (10 - m.size());             m.insert(str[i]);           }         }       }     }     cout << result <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100010;   int T, n, cnt, now[N], ans[N];   char ch[N];   vector<int> A, B, C;   map<pair<int, int>, bool> col;   inline void ask() {     int i, j;     if (!A.size()) return;     printf( Q %d  , (int)A.size());     for (i = 0; i < A.size(); i++) printf( %d %d  , A[i], B[i]);     puts(  );     fflush(stdout);     scanf( %s , ch + 1);     for (i = 1; i <= A.size(); i++)       col[make_pair(A[i - 1], B[i - 1])] = (ch[i] ==  1 );   }   int main() {     int i, j, t;     cin >> T;     while (T--) {       cnt = 0, col.clear();       memset(ans, 0, sizeof(ans));       scanf( %d , &n);       A.clear(), B.clear();       for (int i = 2; i <= n; i += 2) {         A.push_back(i - 1);         B.push_back(i);       }       ask();       A.clear();       B.clear();       for (int i = 3; i <= n; i += 2) {         A.push_back(i - 1);         B.push_back(i);       }       ask();       now[++cnt] = 1;       for (int i = 2; i <= n; i++)         if (!col[make_pair(i - 1, i)]) now[++cnt] = i;       A.clear();       B.clear();       for (int i = 3; i <= cnt; i += 4)         A.push_back(now[i - 2]), B.push_back(now[i]);       for (int i = 4; i <= cnt; i += 4)         A.push_back(now[i - 2]), B.push_back(now[i]);       ask();       A.clear();       B.clear();       for (int i = 5; i <= cnt; i += 4)         A.push_back(now[i - 2]), B.push_back(now[i]);       for (int i = 6; i <= cnt; i += 4)         A.push_back(now[i - 2]), B.push_back(now[i]);       ask();       ans[now[1]] = 1;       if (cnt > 1) ans[now[2]] = 2;       for (int i = 3; i <= cnt; i++) {         if (col[make_pair(now[i - 2], now[i])])           ans[now[i]] = ans[now[i - 2]];         else           ans[now[i]] = 6 - ans[now[i - 2]] - ans[now[i - 1]];       }       A.clear();       B.clear();       C.clear();       for (int i = 1, t; i <= n; i++) {         if (ans[i]) t = ans[i];         ans[i] = t;         if (ans[i] == 1)           A.push_back(i);         else if (ans[i] == 2)           B.push_back(i);         else if (ans[i] == 3)           C.push_back(i);       }       printf( A %d %d %d n , (int)A.size(), (int)B.size(), (int)C.size());       for (int i = 0; i < A.size(); i++) printf( %d  , A[i]);       puts(  );       for (int i = 0; i < B.size(); i++) printf( %d  , B[i]);       puts(  );       for (int i = 0; i < C.size(); i++) printf( %d  , C[i]);       puts(  );       fflush(stdout);     }   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   #pragma GCC optimize( unroll-loops )   #pragma GCC optimize( no-stack-protector )   #pragma GCC target( sse,sse2,ssse3,sse3,sse4,popcnt,avx,mmx,abm,tune=native )   using namespace std;   signed main() {     cin.tie(nullptr)->sync_with_stdio(false);     long long n, k;     cin >> n >> k;     string s, t;     cin >> s >> t;     long long ans = 0, hv = 1;     for (long long i = 0; i < n; i++) {       if (hv < k) {         hv *= 2;         if (s[i] == t[i]) {           hv--;         } else if (s[i] ==  b  && t[i] ==  a ) {           hv -= 2;         }         hv = min(hv, k);       }       ans += hv;     }     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n;     cin >> n;     vector<long long> a(2 * n);     for (long long i = 0; i < 2 * n; ++i) {       cin >> a[i];     }     sort(a.begin(), a.end());     if (n == 1) {       cout << 0;       return 0;     }     long long mn = 2e9;     for (long long i = 1; i < n; ++i) {       mn = min(a[i + n - 1] - a[i], mn);     }     cout << min(min((a[n - 1] - a[0]) * (a[2 * n - 1] - a[n]),                     (a[2 * n - 1] - a[n]) * (a[n - 1] - a[0])),                 mn * (a[2 * n - 1] - a[0]));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 2e5 + 5;   const int MOD = 998244353;   long long fac[MAXN];   struct Edge {     int to, next;   } edge[MAXN * 2];   int head[MAXN], tot;   void AddEdge(int s, int t) {     edge[tot].to = t;     edge[tot].next = head[s];     head[s] = tot++;     edge[tot].to = s;     edge[tot].next = head[t];     head[t] = tot++;   }   int visit[MAXN];   void init() {     memset(head, -1, sizeof(head));     memset(visit, 0, sizeof(visit));     tot = 0;   }   long long DFS(int u) {     visit[u] = 1;     long long ret = 1;     int cnt = 1;     if (u == 1) cnt = 0;     for (int e = head[u]; e != -1; e = edge[e].next) {       int v = edge[e].to;       if (!visit[v]) {         cnt++;         ret = (ret * DFS(v)) % MOD;       }     }     ret = (ret * fac[cnt]) % MOD;     return ret;   }   int main() {     int n;     cin >> n;     long long fa = 1;     for (int i = 1; i < MAXN; i++) {       fa = (fa * i) % MOD;       fac[i] = fa;     }     init();     int u, v;     for (int i = 0; i < n - 1; i++) {       scanf( %d%d , &u, &v);       AddEdge(u, v);     }     cout << (DFS(1) * n) % MOD << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int block;   unordered_map<int, int> x;   vector<long long> a;   struct query {     int l, r, pos;     bool operator<(const query &other) const {       if (l / block == other.l / block) return r < other.r;       return l / block < other.l / block;     }   };   int l = 0, r = -1, cnt = 0;   void remove(int val) {     if (x[val] == val) cnt--;     x[val]--;     if (x[val] == val) cnt++;     if (x[val] == 0) x.erase(val);   }   void add(int val) {     if (x[val] == val) cnt--;     x[val]++;     if (x[val] == val) cnt++;   }   void solve() {     long long n, m;     cin >> n >> m;     block = sqrt(n) + 1;     a.resize(n);     for (long long i = 0; i < n; i++) cin >> a[i];     vector<query> q(m);     for (int i = 0; i < m; i++) {       cin >> q[i].l >> q[i].r;       q[i].pos = i;       q[i].l--, q[i].r--;     }     sort(q.begin(), q.end());     vector<int> ans(m);     for (int i = 0; i < m; i++) {       while (l < q[i].l) remove(a[l++]);       while (l > q[i].l) add(a[--l]);       while (r < q[i].r) add(a[++r]);       while (r > q[i].r) remove(a[r--]);       ans[q[i].pos] = cnt;     }     for (auto i : ans) cout << i <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long t = 1;     while (t--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int arr[n];     map<int, int> m;     for (int i = 0; i < n; i++) {       cin >> arr[i];       if (arr[i] != 0) {         m[arr[i]]++;       }     }     cout << m.size() << endl;     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:536870912 )   #pragma warning(disable : 4996)   using namespace std;   const int N = 2e5 + 100, X[2] = {997, 449};   char s[N], t[N];   long long int h[2][N], p[2][N];   int w[N], g[N], lb[N], rb[N];   int n;   pair<long long int, long long int> getH(int l, int r) {     return {h[0][r] - h[0][l - 1] * p[0][r - l + 1],             h[1][r] - h[1][l - 1] * p[1][r - l + 1]};   }   int lcp(int a, int b) {     int l = 0, r = n - max(a, b) + 1;     while (r - l > 1) {       int p = (r + l) >> 1;       if (getH(a + 1, a + p) == getH(b + 1, b + p))         l = p;       else         r = p;     }     return l;   }   int main() {     scanf( %d %s %s , &n, s, t);     reverse(s, s + n);     reverse(t, t + n);     for (int i = 0; i < 2; i++) {       p[i][0] = 1;       for (int j = 0; j < n; j++) {         p[i][j + 1] = p[i][j] * X[i];         h[i][j + 1] = h[i][j] * X[i] + s[j];       }     }     int c = 0;     for (int i = 0; i < n; i++) {       if (t[i] ==  0 ) w[c++] = i;     }     sort(w, w + c, [](int a, int b) {       int x = lcp(a, b);       return s[a + x] < s[b + x];     });     for (int i = 0; i < c - 1; i++) {       g[i] = lcp(w[i], w[i + 1]);     }     vector<int> v;     for (int i = 0; i < c - 1; i++) {       while (!v.empty() && g[v.back()] >= g[i]) v.pop_back();       lb[i] = v.empty() ? -1 : v.back();       v.push_back(i);     }     v.clear();     for (int i = c - 2; i >= 0; i--) {       while (!v.empty() && g[v.back()] >= g[i]) v.pop_back();       rb[i] = v.empty() ? c - 1 : v.back();       v.push_back(i);     }     long long int ans = 0;     for (int i = 0; i < c; i++) ans = max(ans, (long long int)n - w[i]);     for (int i = 0; i < c - 1; i++) {       ans = max(ans, g[i] * (long long int)(rb[i] - lb[i]));     }     printf( %lld , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   const int N = 20 + 5;   int go[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};   int n, m, k;   char s[N][N];   struct Node {     int x, y, v;   } t[N];   int tot;   int sx, sy;   struct State {     int x, y, S;   };   int vis[N][N][1 << 10];   int dis[N][N][1 << 10];   inline int calc(int S) {     int sum = 0;     for (register int i = 1; i <= k; i++)       if (S & (1 << (i - 1))) {         sum += t[i].v;       }     return sum;   }   inline int ok(int x, int y, int nx, int ny, int i) {     if (nx == t[i].x && ny < t[i].y)       if (x < nx) return 1;     if (x == t[i].x && y < t[i].y)       if (x > nx) return 1;     return 0;   }   int main() {     cin >> n >> m;     k = 0;     for (register int i = 1; i <= n; i++) {       for (register int j = 1; j <= m; j++) {         cin >> s[i][j];         if (s[i][j] ==  S ) sx = i, sy = j;         if (isdigit(s[i][j])) {           k = max(k, s[i][j] -  0 );           t[s[i][j] -  0 ] = {i, j, 0};         }       }     }     for (register int i = 1; i <= k; i++) cin >> t[i].v;     for (register int i = 1; i <= n; i++)       for (register int j = 1; j <= m; j++)         if (s[i][j] ==  B ) {           t[++k] = {i, j, -inf / 1000};         }     queue<State> Q;     memset(dis, 0x3f, sizeof(dis));     Q.push(State{sx, sy, 0});     dis[sx][sy][0] = 0;     int ans = 0;     while (Q.size()) {       State tmp = Q.front();       Q.pop();       int x = tmp.x, y = tmp.y, S = tmp.S;       if (x == sx && y == sy) {         ans = max(ans, calc(S) - dis[x][y][S]);       }       for (register int i = 0; i < 4; i++) {         int nx = x + go[i][0];         int ny = y + go[i][1];         if (nx < 1 || ny < 1 || nx > n || ny > m ||             (s[nx][ny] !=  .  && s[nx][ny] !=  S ))           continue;         int T = S;         for (register int j = 1; j <= k; j++)           if (ok(x, y, nx, ny, j)) T ^= (1 << (j - 1));         if (dis[nx][ny][T] == inf) {           dis[nx][ny][T] = dis[x][y][S] + 1;           Q.push(State{nx, ny, T});         }       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = (1 << 23);   bool vis[maxn], num[maxn];   int n, m;   void dfs(int x) {     if (vis[x]) return;     vis[x] = 1;     for (int i = 0; i < n; i++) {       if (x & (1 << i)) dfs(x ^ (1 << i));     }     if (num[x]) dfs((1 << n) - 1 - x);   }   int main() {     int x;     scanf( %d%d , &n, &m);     for (int i = 1; i <= m; i++) {       scanf( %d , &x);       num[x] = 1;     }     int ans = 0;     for (int i = 0; i < (1 << n); i++) {       if (num[i] && !vis[i]) dfs(((1 << n) - 1) & (~i)), ans++;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long c1, c2;   int n, k;   long long p(long long m) {     long long mini = LLONG_MAX;     for (int i = 1; i <= n; ++i)       if ((n + i) / (i + 1) <= m and m <= n / i)         mini = min(mini, 1LL * i * i * (m * (i + 1) - n) +                              1LL * (i + 1) * (i + 1) * (n - m * i));     return m * (c1 + c2) - 2 * c2 * n + c2 * mini;   }   int main() {     scanf( %d %lld %lld%*c , &n, &c1, &c2);     for (int i = 0; i < n; ++i) k += getchar() ==  1 ;     int lo = 1, hi = k;     while (lo < hi) {       int mid = lo + (hi - lo) / 2;       if (p(mid) <= p(mid + 1))         hi = mid;       else         lo = mid + 1;     }     printf( %lld n , p(lo));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   static const double EPS = 1e-5;   int main() {     int n, k;     cin >> n >> k;     vector<int> cur(n);     vector<int> p(n);     vector<int> goal(n);     for (int i = 0; i < n; i++) {       cin >> p[i];     }     for (int i = 0; i < n; i++) cin >> goal[i];     bool ok = true;     for (int i = 0; i < n; i++) {       cur[i] = i + 1;       if (goal[i] != cur[i]) ok = false;     }     if (ok) {       cout <<  NO  << endl;       return 0;     }     int step_forward = 1000;     int step_backward = 1000;     for (int i = 0; i < k; i++) {       bool ok = true;       vector<int> nxt;       for (int j = 0; j < n; j++) {         nxt.push_back(cur[p[j] - 1]);         if (nxt[j] != goal[j]) ok = false;       }       if (ok) {         step_forward = i + 1;         break;       }       cur = nxt;     }     cur = goal;     for (int i = 0; i < k; i++) {       bool ok = true;       vector<int> nxt;       for (int j = 0; j < n; j++) {         nxt.push_back(cur[p[j] - 1]);         if (nxt[j] != j + 1) ok = false;       }       if (ok) {         step_backward = i + 1;         break;       }       cur = nxt;     }     if (step_forward == 1 && step_backward == 1 && k > 1) {       cout <<  NO  << endl;       return 0;     }     if (step_forward <= k && step_forward % 2 == k % 2) {       cout <<  YES  << endl;       return 0;     }     if (step_backward <= k && step_backward % 2 == k % 2) {       cout <<  YES  << endl;       return 0;     }     cout <<  NO  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class A, class B>   ostream& operator<<(ostream& out, const pair<A, B>& a) {     return out <<  (  << a.first <<  ,   << a.second <<  ) ;   }   template <class A>   ostream& operator<<(ostream& out, const vector<A>& v) {     out <<  [ ;     for (int i = 0; i < v.size(); i++) {       if (i) out <<  ,  ;       out << v[i];     }     return out <<  ] ;   }   bool Check(int n, int pos) { return (bool)(n & (1 << pos)); }   struct edg {     long long to, w, c;   };   vector<edg> g[100005];   vector<long long> v1, v2;   int vis[100005];   long long sum, s;   void calc(long long ws, long long lf, long long c) {     while (ws) {       long long wy = ws;       ws /= 2LL;       wy = wy - ws;       if (c == 1)         v1.emplace_back(wy * lf);       else         v2.emplace_back(wy * lf);     }   }   long long dfs(long long i, long long ws) {     vis[i] = 1;     long long ret = 0;     bool is_leaf = true;     for (auto j : g[i]) {       if (vis[j.to] == -1) {         is_leaf = false;         int r = dfs(j.to, ws + j.w);         ret += r;         calc(j.w, r, j.c);       }     }     if (is_leaf) {       sum += ws;       return 1LL;     }     return ret;   }   void solve() {     int n;     cin >> n >> s;     for (int i = 1; i < n; i++) {       int u, v, w, c;       cin >> u >> v >> w >> c;       u--, v--;       g[u].push_back({v, w, c});       g[v].push_back({u, w, c});     }     memset(vis, -1, sizeof(vis));     dfs(0, 0);     sort(v1.begin(), v1.end(), greater<long long>());     sort(v2.begin(), v2.end(), greater<long long>());     int len1 = v1.size();     int len2 = v2.size();     long long res = 0;     int i = -1, j = 0;     while (sum > s && i + 1 < len1) {       res++;       i++;       sum -= v1[i];     }     while (sum > s && j < len2) {       res += 2;       sum -= v2[j];       j++;     }     long long cur = res;     while (i >= 0) {       sum += v1[i];       cur--;       i--;       while (sum > s && j < len2) {         sum -= v2[j];         cur += 2;         j++;       }       if (sum <= s) {         res = min(res, cur);       }     }     cout << res <<   n ;     for (int i = 0; i <= n; i++) g[i].clear();     v1.clear();     v2.clear();     sum = 0;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int q = 1;     cin >> q;     for (int kase = 1; kase <= q; kase++) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:256000000 )   using namespace std;   int main() {     int n;     scanf( %d , &n);     if (n % 2 == 0) {       printf( -1 n );       return 0;     }     for (int i = 0; i < n; ++i) {       printf( %d  , i);     }     printf(  n );     for (int i = 0; i < n; ++i) {       printf( %d  , (i + 1) % n);     }     printf(  n );     for (int i = 0; i < n; ++i) {       printf( %d  , (2 * i + 1) % n);     }     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string a;     int n, m;     cin >> a >> n;     m = a.size();     string ans =   ;     while (n--) {       string b;       cin >> b;       if (b.substr(0, 0 + m) == a) {         if (ans ==   )           ans = b;         else if (b < ans)           ans = b;       }     }     if (ans !=   )       cout << ans;     else       cout << a;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, x, q[100100];   char t;   vector<int> d;   bool used[100100];   void calc(int x) {     d.resize(0);     for (int i = 2; i * i <= x; i++)       if (x % i == 0) {         while (x % i == 0) x /= i;         d.push_back(i);       }     if (x != 1) d.push_back(x);   }   int main() {     scanf( %d%d n , &n, &m);     memset((used), (false), sizeof((used)));     memset((q), (0), sizeof((q)));     for (int i = 0; i < (m); i++) {       while (t = getchar(), t !=  +  && t !=  - )         ;       scanf( %d , &x);       if (t ==  + ) {         if (used[x]) {           puts( Already on );           continue;         }         calc(x);         bool ok = true;         for (int j = 0; j < (d.size()); j++)           if (q[d[j]]) {             printf( Conflict with %d n , q[d[j]]);             ok = false;             break;           }         if (ok) {           for (int j = 0; j < (d.size()); j++) q[d[j]] = x;           used[x] = true;           puts( Success );         }       } else {         if (!used[x]) {           puts( Already off );           continue;         }         used[x] = false;         calc(x);         for (int j = 0; j < (d.size()); j++) q[d[j]] = 0;         puts( Success );       }     }   }


#include <bits/stdc++.h>   using namespace std;   int n, m, notFind;   vector<pair<int, int>> edge[100001];   vector<int> ans[2], e[2];   int vis[100001];   void DFS(int u, int c, int vit) {     vis[u] = c;     e[c].push_back(u);     for (auto k : edge[u]) {       int v, col, nextCol;       tie(v, col) = k;       col = (col + c) % 2;       nextCol = col == vit ? 0 : 1;       if (vis[v] != -1) {         if (vis[v] != nextCol) notFind = 1;         continue;       }       DFS(v, nextCol, vit);     }   }   bool solve(int vit) {     memset(vis, -1, sizeof(vis));     notFind = 0;     for (int i = 1; i <= n; ++i) {       if (vis[i] != -1) continue;       e[0].clear();       e[1].clear();       DFS(i, 0, vit);       if (notFind) return 0;       if (e[0].size() > e[1].size()) swap(e[0], e[1]);       for (auto j : e[0]) ans[vit].push_back(j);     }     return 1;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m;     for (int i = 0; i < m; ++i) {       int u, v;       char chr;       cin >> u >> v >> chr;       edge[u].push_back({v, chr ==  R });       edge[v].push_back({u, chr ==  R });     }     bool n1, n2;     int id = 0;     n1 = solve(0);     n2 = solve(1);     if (!n1 && !n2) return cout <<  -1 , 0;     if (!n1 || n1 && n2 && ans[0].size() > ans[1].size()) id = 1;     cout << ans[id].size() <<   n ;     for (auto k : ans[id]) cout << k <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<long long> v[100];   int n;   long long tmp;   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       int cnt = 0;       scanf( %I64d , &tmp);       while (tmp % 2 == 0) {         tmp >>= 1;         cnt++;       }       v[cnt].push_back(tmp);     }     tmp = 0;     for (int i = 1; i <= 64; i++)       if (v[i].size() > v[tmp].size()) tmp = i;     printf( %d n , n - v[tmp].size());     for (int i = 0; i <= 64; i++) {       if (i == tmp) continue;       for (int j = 0; j < v[i].size(); j++) printf( %I64d  , v[i][j] << i);     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 100000 * 2 + 5;   const int maxd = 25;   long long d[maxn], h[maxn], s[maxn], f[maxn], g[maxn];   int f_fst[maxd][maxn], f_snd[maxd][maxn], g_fst[maxd][maxn], g_snd[maxd][maxn];   void GetMax(long long a[], int &r0, int &r1, int x0, int x1, int y0, int y1) {     if (a[x0] > a[y0]) {       r0 = x0;       r1 = x1 != x0 && a[x1] > a[y0] ? x1 : y0;     } else if (a[x0] < a[y0]) {       r0 = y0;       r1 = y1 != y0 && a[y1] > a[x0] ? y1 : x0;     } else {       r0 = x0;       if (x0 == y0)         r1 = a[x1] > a[y1] ? x1 : y1;       else         r1 = y0;     }   }   void BuildRMQ(long long a[maxn], int fst[][maxn], int snd[][maxn], int n) {     for (int k = 0; (1 << k) <= n; k++)       for (int i = 1; i + (1 << k) - 1 <= n; i++)         if (k == 0)           fst[k][i] = snd[k][i] = i;         else {           int j = i + (1 << k - 1);           GetMax(a, fst[k][i], snd[k][i], fst[k - 1][i], snd[k - 1][i],                  fst[k - 1][j], snd[k - 1][j]);         }   }   pair<int, int> QueryRMQ(long long a[maxn], int fst[][maxn], int snd[][maxn],                           int n, int x, int y) {     for (int k = maxd - 1; k >= 0; k--)       if ((y - x + 1) >> k) {         int i = x, j = y - (1 << k) + 1;         pair<int, int> ret;         GetMax(a, ret.first, ret.second, fst[k][i], snd[k][i], fst[k][j],                snd[k][j]);         return ret;       }   }   int main() {     int n, m;     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) {       scanf( %I64d , &d[i]);       s[i + 1] = s[i] + d[i];     }     for (int i = 1; i <= n; i++) {       scanf( %I64d , &h[i]);       h[i + n] = h[i];       s[i + n + 1] = s[i + n] + d[i];     }     for (int i = 1; i <= n * 2; i++) {       f[i] = h[i] * 2LL - s[i];       g[i] = h[i] * 2LL + s[i];     }     BuildRMQ(f, f_fst, f_snd, n * 2);     BuildRMQ(g, g_fst, g_snd, n * 2);     for (int i = 0; i < m; i++) {       int ai, bi;       scanf( %d%d , &ai, &bi);       if (ai <= bi) ai += n;       bi++;       ai--;       pair<int, int> fmax = QueryRMQ(f, f_fst, f_snd, n * 2, bi, ai);       pair<int, int> gmax = QueryRMQ(g, g_fst, g_snd, n * 2, bi, ai);       long long ans;       if (fmax.first != gmax.first)         ans = f[fmax.first] + g[gmax.first];       else         ans = max(f[fmax.first] + g[gmax.second], f[fmax.second] + g[gmax.first]);       printf( %I64d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     cout <<  INTERCAL  <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int res = INT_MAX;   int i, j;   int n, d;   int a[2018];   int main() {     cin >> n >> d;     for (int x = 0; x < n; x++) cin >> a[x];     sort(a, a + n);     for (i = 0; i < n; i++)       for (j = n - 1; j >= i; j--) {         if (a[j] - a[i] <= d) {           res = min(res, n - j + i - 1);           break;         }       }     return !printf( %d , res);   }


#include <bits/stdc++.h>   using namespace std;   long long int mod = 1e9 + 7;   long long int exp(long long int t, long long int x) {     if (x == 0) return 1;     if (x == 1) return t;     if (x % 2 == 1) return (t * exp((t * t) % mod, x / 2)) % mod;     if (x % 2 == 0) return exp((t * t) % mod, x / 2);   }   long long int gcd(long long int x, long long int y) {     return x % y == 0 ? y : gcd(y, x % y);   }   long long int lcm(long long int x, long long int y) {     return x * (y / gcd(x, y));   }   long long int bsum(long long int u, long long int b) {     return u < b ? u : bsum(u / b, b) + u % b;   }   long long int prival(long long int u, long long int p) {     int cn = 0;     while (u % p == 0) {       cn++;       u = u / p;     }     return cn;   }   bool isprime(long long int x) {     for (long long int i = 2; i * i <= x; i++) {       if (x % i == 0) {         return false;       }     }     return true;   }   void YAY(void) { cout <<  YES  << endl; }   void NAY(void) { cout <<  NO  << endl; }   struct var {     string id;     string val;     int def;     int V1, V2;     string OP;   } num[5111];   int temp[5111];   map<string, int> go;   string mmin, mmax;   int n, m;   int getbit(int loc, int b) {     int i;     int ret = 0;     for (i = 1; i <= n; i++) {       temp[i] = 0;     }     for (i = 1; i <= n; i++) {       if (num[i].def == 0) {         ret += num[i].val[loc] -  0 ;         temp[i] = num[i].val[loc] -  0 ;       } else {         int u, v;         if (num[i].V1 == 0) {           u = b;         } else if (num[i].V1 != 0) {           u = temp[num[i].V1];         }         if (num[i].V2 == 0) {           v = b;         } else if (num[i].V2 != 0) {           v = temp[num[i].V2];         }         if (num[i].OP ==  XOR ) {           ret += u ^ v;           temp[i] = u ^ v;         } else if (num[i].OP ==  OR ) {           ret += u | v;           temp[i] = u | v;         } else if (num[i].OP ==  AND ) {           ret += u & v;           temp[i] = u & v;         }       }     }     for (i = 1; i <= n; i++) {       temp[i] = 0;     }     return ret;   }   int main(void) {     int i, j;     cin >> n >> m;     for (i = 1; i <= n; i++) {       string s, trash, num1;       cin >> s >> trash >> num1;       go[s] = i;       num[i].id = s;       if (num1[0] ==  0  || num1[0] ==  1 ) {         num[i].def = 0;         num[i].val = num1;       } else {         num[i].def = 1;         if (num1[0] ==  ? ) {           num[i].V1 = 0;         } else {           num[i].V1 = go[num1];         }         string op, num2;         cin >> op >> num2;         num[i].OP = op;         if (num2[0] ==  ? ) {           num[i].V2 = 0;         } else {           num[i].V2 = go[num2];         }       }     }     for (i = 0; i <= m - 1; i++) {       int X = getbit(i, 0);       int Y = getbit(i, 1);       if (X > Y) {         mmin.push_back( 1 );         mmax.push_back( 0 );       } else if (X < Y) {         mmin.push_back( 0 );         mmax.push_back( 1 );       } else if (X == Y) {         mmin.push_back( 0 );         mmax.push_back( 0 );       }     }     cout << mmin << endl << mmax;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 150009;   long long a[N];   long long b[N], n, m, h;   struct Tree {     long long l, r;     long long ly, mi;   } t[N << 2];   void build_tree(long long p, long long l, long long r) {     t[p].l = l, t[p].r = r;     if (l == r) {       t[p].mi = l - m - 1;       t[p].ly = 0;       return;     }     build_tree((p << 1), l, ((t[p].l + t[p].r) >> 1));     build_tree(((p << 1) | 1), ((t[p].l + t[p].r) >> 1) + 1, r);     t[p].mi = min(t[(p << 1)].mi, t[((p << 1) | 1)].mi);   }   void push_down(long long p) {     if (t[p].ly) {       t[(p << 1)].ly += t[p].ly;       t[((p << 1) | 1)].ly += t[p].ly;       t[(p << 1)].mi += t[p].ly;       t[((p << 1) | 1)].mi += t[p].ly;       t[p].ly = 0;     }   }   void modify(long long p, long long l, long long r, long long v) {     if (t[p].l == l && t[p].r == r) {       t[p].mi += v;       t[p].ly += v;       return;     }     push_down(p);     if (r <= ((t[p].l + t[p].r) >> 1))       modify((p << 1), l, r, v);     else if (l > ((t[p].l + t[p].r) >> 1))       modify(((p << 1) | 1), l, r, v);     else {       modify((p << 1), l, ((t[p].l + t[p].r) >> 1), v);       modify(((p << 1) | 1), ((t[p].l + t[p].r) >> 1) + 1, r, v);     }     t[p].mi = min(t[(p << 1)].mi, t[((p << 1) | 1)].mi);   }   long long query(long long p, long long l, long long r) {     if (t[p].l == l && t[p].r == r) {       return t[p].mi;     }     push_down(p);     if (r <= ((t[p].l + t[p].r) >> 1))       return query((p << 1), l, r);     else if (l > ((t[p].l + t[p].r) >> 1))       return query(((p << 1) | 1), l, r);     else       return min(query((p << 1), l, ((t[p].l + t[p].r) >> 1)),                  query(((p << 1) | 1), ((t[p].l + t[p].r) >> 1) + 1, r));   }   long long cal(long long x) {     long long s = 1, t = m;     while (s <= t) {       long long i = (s + t) >> 1;       if (b[i] > x)         t = i - 1;       else         s = i + 1;     }     return t;   }   long long p[N];   int main() {     cin >> n >> m >> h;     for (long long i = 1; i <= m; i++) cin >> b[i], b[i] = h - b[i];     sort(b + 1, b + m + 1);     build_tree(1, 1, m);     for (long long i = 0; i < m; i++) {       long long v;       cin >> v;       p[i] = cal(v);       if (p[i]) modify(1, 1, p[i], 1);     }     long long ans = (query(1, 1, m) >= 0);     for (long long i = m; i < n; i++) {       long long v;       cin >> v;       p[i] = cal(v);       if (p[i]) modify(1, 1, p[i], 1);       if (p[i - m]) modify(1, 1, p[i - m], -1);       ans += (query(1, 1, m) >= 0);     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   int n;   map<int, pair<int, int> > m;   int main() {     scanf( %i , &n);     for (int i = 0; i < n; i++) {       int a, b;       scanf( %i%i , &a, &b);       if (m.find(a) == m.end())         m[a] = make_pair(1, 0);       else         m[a].first += 1;       if (b != a)         if (m.find(b) == m.end())           m[b] = make_pair(0, 1);         else           m[b].second += 1;     }     int ans = 1e9;     for (map<int, pair<int, int> >::iterator it = m.begin(); it != m.end(); it++)       if (it->second.first + it->second.second >= (n + 1) / 2)         ans = min(ans, max(0, (n + 1) / 2 - it->second.first));     if (ans == 1e9)       cout << -1;     else       cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int arr[30] = {}, n, i = 0;     cin >> n;     while (n > 0) arr[i] = n % 2, n /= 2, i++;     for (i = 29; i >= 0; i--)       if (arr[i]) cout << i + 1 <<    ;     cout <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int s = 0;     int d = 0;     vector<int> a(n);     for (int i = 0; i < n; i++) {       cin >> a[i];     }     int i = 0;     int count = 1;     int beg = 0;     int last = n - 1;     while (count <= n) {       if (i == 0) {         if (a[beg] > a[last]) {           s = s + a[beg];           beg++;           i = 1;         } else {           s = s + a[last];           last--;           i = 1;         }       } else {         if (a[beg] > a[last]) {           d = d + a[beg];           beg++;           i = 0;         } else {           d = d + a[last];           last--;           i = 0;         }       }       count++;     }     cout << s <<     << d;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int i, count = 1, ans = 0;     string input;     cin >> input;     for (i = 1; i < input.length(); i++) {       if (input[i] != input[i - 1]) {         ans += (count / 5) + (count % 5 > 0);         count = 0;       }       count++;     }     ans += (count / 5) + (count % 5 > 0);     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 300005;   int needread[maxn];   int readed[maxn];   int cnt[maxn];   int main() {     int n, q, type, num, pop_cnt = 0;     queue<int> que;     scanf( %d %d , &n, &q);     int ans = 0;     while (q--) {       scanf( %d %d , &type, &num);       if (type == 1) {         ans++;         needread[num]++;         que.push(num);       } else if (type == 2) {         ans -= needread[num] - readed[num];         readed[num] = needread[num];       } else {         int t = num - pop_cnt;         while (!que.empty() && t > 0) {           t--;           int cur = que.front();           que.pop();           pop_cnt++;           cnt[cur]++;           if (cnt[cur] > readed[cur]) {             ans -= cnt[cur] - readed[cur];             readed[cur] = cnt[cur];           }         }       }       printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<pair<int, int> > vec[105];   int main() {     int n, k;     scanf( %d%d , &n, &k);     for (int i = 1; i <= n; i++) vec[i].push_back(make_pair(i, i));     int ct = 101;     int a, b;     for (int i = 1; i <= k; i++) {       scanf( %d%d , &a, &b);       vec[a].push_back(make_pair(ct, a));       vec[b].push_back(make_pair(ct, b));       ct++;     }     for (int i = 1; i <= n; i++) {       printf( %d n , vec[i].size());       for (int j = 0; j < vec[i].size(); j++)         printf( %d %d n , vec[i][j].first, vec[i][j].second);     }   }


#include <bits/stdc++.h>   using namespace std;   bool sortin(const pair<long long int, long long int> &e,               const pair<long long int, long long int> &f) {     return (e.first < f.first);   }   long long int i, j, k, l, m, n, c, p, q, ts, mn = 10e17, mod = 10e8 + 7;   long long int a[250002], b[250002], x[250002];   int main() {     {       ios_base::sync_with_stdio(false);       cin.tie(0);       cout.tie(0);     };     cin >> n >> m >> k;     l = ((n + k - 1) / k) * ((m + k - 1) / k) * ((n - 1) % k + 1) *         ((m - 1) % k + 1);     cout << l;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1111;   int n;   struct Edge {     int u, v;     long long weight;     int adj(int x) { return x == u ? v : u; }   };   struct Path {     int u, v;     long long weight;   };   vector<Edge> E;   vector<int> G[N];   vector<Path> res;   int Trace[N];   int FindLeaf(int u, int parent) {     if ((int)G[u].size() == 1) return u;     for (auto e : G[u]) {       int v = E[e].adj(u);       if (v == parent) continue;       Trace[v] = u;       int l = FindLeaf(v, u);       if (l != -1) return l;     }     return -1;   }   void Solve() {     for (int i = 1; i <= n; ++i) {       if ((int)G[i].size() == 2) {         cout <<  NO n ;         return;       }     }     cout <<  YES n ;     for (auto e : E) {       vector<int> U, V;       int u = e.u;       int v = e.v;       long long w = e.weight;       for (int i = 0; i < (int)G[u].size(); ++i) {         int uu = E[G[u][i]].adj(u);         if (uu == v) continue;         U.push_back(FindLeaf(uu, u));       }       if (U.empty()) U.push_back(u);       for (int i = 0; i < (int)G[v].size(); ++i) {         int vv = E[G[v][i]].adj(v);         if (vv == u) continue;         V.push_back(FindLeaf(vv, v));       }       if (V.empty()) V.push_back(v);       res.push_back({U[0], V[0], w / 2});       if ((int)U.size() > 1 && (int)V.size() > 1)         res.push_back({U[1], V[1], w / 2});       else if ((int)U.size() > 1)         res.push_back({U[1], V[0], w / 2});       else if ((int)V.size() > 1)         res.push_back({U[0], V[1], w / 2});       else         res.push_back({U[0], V[0], w / 2});       if ((int)U.size() > 1) res.push_back({U[0], U[1], -w / 2});       if ((int)V.size() > 1) res.push_back({V[0], V[1], -w / 2});     }     cout << (int)res.size() <<   n ;     for (int i = 0; i < (int)res.size(); ++i) {       cout << res[i].u <<     << res[i].v <<     << res[i].weight <<   n ;     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n;     for (int i = 0; i < n - 1; ++i) {       int u, v;       long long w;       cin >> u >> v >> w;       G[u].push_back(i);       G[v].push_back(i);       E.push_back({u, v, w});     }     Solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long n;     cin >> n;     int arr[n];     int sum = 0;     int ans = 0;     for (int i = 0; i < n; i++) {       cin >> arr[i];       sum += arr[i];     }     sum = sum / 2 + 1;     sort(arr, arr + n, greater<int>());     for (int j = 0; j < n; j++) {       if (sum <= 0) break;       sum -= arr[j];       ans++;     }     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, k;   pair<string, int> A[11];   int main() {     scanf( %i , &n);     for (int i = 0; i < 7; i++) A[i].second = 2e7;     for (int i = 0; i < n; i++) {       string s;       int p;       cin >> p >> s;       sort(s.begin(), s.end());       if (s ==  ABC )         A[0] = make_pair(s, min(A[0].second, p));       else if (s ==  AB )         A[1] = make_pair(s, min(A[1].second, p));       else if (s ==  AC )         A[2] = make_pair(s, min(A[2].second, p));       else if (s ==  BC )         A[3] = make_pair(s, min(A[3].second, p));       else if (s ==  A )         A[4] = make_pair(s, min(A[4].second, p));       else if (s ==  B )         A[5] = make_pair(s, min(A[5].second, p));       else if (s ==  C )         A[6] = make_pair(s, min(A[6].second, p));     }     int ans = 2e7;     for (int i = 0; i < 1 << 7; i++) {       int occ[3] = {0};       int cost = 0;       for (int j = 0; j < 7; j++) {         if (i & 1 << j) {           for (int k = 0; k < A[j].first.size(); k++) occ[A[j].first[k] -  A ]++;           cost += A[j].second;         }       }       if (occ[0] && occ[1] && occ[2]) ans = min(cost, ans);     }     printf( %i n , ans == 2e7 ? -1 : ans);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     int n;     cin >> n;     vector<int> x(n);     vector<int> p(n);     for (int i = (0); i < ((n)); ++i) {       cin >> x[i];       --x[i];       p[x[i]] = i;     }     int const MAX_SUM = 100001;     vector<int> primes;     for (int k = (2); k < (2 * n + 1); ++k) {       bool isPrime = true;       for (int j = 2; j * j <= k; ++j) {         if (k % j == 0) {           isPrime = false;           break;         }       }       if (isPrime) {         primes.push_back(k);       }     }     vector<pair<int, int> > res;     for (int i = (0); i < ((n)); ++i) {       int const pos1 = p[i];       int const pos2 = i;       int p1 = min(pos1, pos2);       int const p2 = max(pos1, pos2);       vector<int> positions;       positions.push_back(p1);       while (p1 != p2) {         int const diff = p2 - p1 + 1;         auto it = lower_bound(primes.begin(), primes.end(), diff);         if (it == primes.end() || *it > diff) --it;         int const usedPrime = *it;         p1 += usedPrime - 1;         positions.push_back(p1);       }       if (pos1 > pos2) reverse(positions.begin(), positions.end());       for (int j = (0); j < (((int)positions.size() - 1)); ++j) {         int const p1 = positions[j];         int const p2 = positions[j + 1];         swap(x[p1], x[p2]);         p[x[p1]] = p1;         p[x[p2]] = p2;         res.push_back(make_pair(min(p1, p2), max(p1, p2)));       }     }     vector<int> orig(n);     for (int i = (0); i < ((n)); ++i) orig[i] = i;     if (orig != x) {       cout <<  FAILED! n ;       throw 10;     }     cout << (int)res.size() << endl;     for (int i = (0); i < (((int)res.size())); ++i) {       cout << res[i].first + 1 <<     << res[i].second + 1 <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:66777216 )   using namespace std;   int a, b, c, d, i, j, n, m, k;   inline void die(long double first) {     printf( %.15lf n , (double)first);     exit(0);   }   long double check(long double y1, long double y2, long double yw,                     long double xb, long double yb, long double r,                     long double xx) {     long double h = yw - r - yb;     double a = xx, b = xb - xx;     return yw - r - h / b * a;   }   struct line {     long double a, b, c;     line() : a(0), b(0), c(0) {}     line(pair<long double, long double> t1, pair<long double, long double> t2) {       a = t2.second - t1.second;       b = t1.first - t2.first;       c = -a * t1.first - b * t1.second;       long double s = sqrt(a * a + b * b);       a /= s;       b /= s;       c /= s;     }     inline long double dist(pair<long double, long double> t) {       return abs(a * t.first + b * t.second + c);     }   };   int main() {     long double y1, y2, yw, xb, yb, r;     cin >> y1 >> y2 >> yw >> xb >> yb >> r;     if (y1 > y2) swap(y1, y2);     long double bottom = y1 + r;     long double top = min(y2 - r, yw - r);     if (bottom > top + 1e-9) {       printf( -1 n );       exit(0);     }     long double low = 0.0, high = xb;     for (int _n((300)), hod(1); hod <= _n; hod++) {       long double xx = (low + high) / 2;       long double ff = check(y1, y2, yw, xb, yb, r, xx);       line l(make_pair(xx, yw - r), make_pair(0, ff));       if (ff + 1e-9 > bottom && l.dist(make_pair(0, y2)) + 1e-9 > r &&           ff < top + 1e-9) {         die(xx);       }       if (ff < bottom)         high = xx;       else         low = xx;     }     printf( -1 n );   }


#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-8;   const double pi = acos(-1.0);   int dblcmp(double d) {     if (fabs(d) < eps) return 0;     return d > eps ? 1 : -1;   }   long long n, t;   int a[66], l, p;   long long dp[66][2][66];   long long getdp(int len, int less, int tot) {     if (len == l) {       return (tot == p);     }     if (dp[len][less][tot] != -1) return dp[len][less][tot];     long long res = 0;     int u, i;     if (less)       u = 1;     else       u = a[len];     for (i = 0; i <= u; i++) {       res += getdp(len + 1, less || (i < a[len]), tot + i);     }     return dp[len][less][tot] = res;   }   long long gao(long long x) {     l = 0;     while (x) {       a[l++] = x % 2;       x /= 2;     }     reverse(a, a + l);     memset((dp), -1, sizeof(dp));     return getdp(0, 0, 0);   }   int main() {     cin >> n >> t;     if (t & (t - 1LL)) {       puts( 0 );       return 0;     }     int i, j, k;     for (p = 0;; p++) {       if (t == (1LL << p)) break;     }     p++;     long long ans = gao(n + 1);     if (t == 1) ans--;     cout << ans << endl;     return 0;   }