#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 10;   bool is_Prime(long long a) {     for (long long i = 2; i * i <= a; ++i)       if (a % i == 0) return false;     return true;   }   bool cmp(pair<long long, long long> a, pair<long long, long long> b) {     return (a.second < b.second);   }   long long fact(long long n) {     vector<long long> v;     for (long long i = 2; i * i <= n; i++) {       if (n % i == 0) {         if (n / i == i)           v.push_back(i);         else {           v.push_back(i);           v.push_back(n / i);         }       }     }     return v.size();   }   void C(long long n, long long r) {     vector<vector<long long>> c(n + 1, vector<long long>(r + 1, 0));     for (long long i = 0; i < n + 1; i++) {       for (long long j = 0; j <= i && j <= r; j++)         if (j == 0 || j == i)           c[i][j] = 1;         else           c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % 1000000007;     }   }   bool is_pl(string s, int n) {     for (long long i = 0; i < n / 2; i++) {       if (s[i] != s[n - i - 1]) return false;     }     return true;   }   void solve() {     int n, k;     cin >> n >> k;     int cnt[5001] = {0};     vector<pair<int, int>> v(n);     for (long long i = 0; i < n; i++) {       cin >> v[i].first;       cnt[v[i].first]++;       v[i].second = (int)i;     }     for (long long i = 0; i < 5001; i++) {       if (cnt[i] > k) {         cout <<  NO n ;         return;       }     }     sort(v.begin(), v.end());     vector<int> ans(n);     int a = 1;     for (long long i = 0; i < n; i++) {       ans[v[i].second] = a;       a++;       if (a > k) a = 1;     }     cout <<  YES n ;     for (long long i = 0; i < n; i++) cout << ans[i] <<    ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0), cout.tie(0);     ;     int T = 1;     while (T--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void smain();   int main() {     ios_base::sync_with_stdio(0);     cout.precision(7);     cout << fixed;     smain();     return 0;   }   long long d[100001], d2[100001], r[100001], s[100001], sz[100001], c[100001];   struct node {     long long cnt, ps, pcnt;   };   map<long long, node> a[100001];   vector<long long> edges[100001];   long long root = -1, dr = -1;   void dfs0(long long v, long long p = -1) {     if (d[v] >= dr) root = v, dr = d[v];     for (auto i : edges[v])       if (i != p) {         c[i] = c[v];         d[i] = d[v] + 1;         dfs0(i, v);       }   }   void dfs(long long v, long long p = -1) {     d[v] = 0;     for (auto i : edges[v])       if (i != p) {         dfs(i, v);         d[v] = max(d[v], d[i] + 1);       }   }   void dfs2(long long v, long long x, long long p = -1) {     long long mx1 = 0, mx2 = 0;     for (auto i : edges[v])       if (i != p) {         if (d[i] + 1 > mx1)           mx2 = mx1, mx1 = d[i] + 1;         else if (d[i] + 1 > mx2)           mx2 = d[i] + 1;       }     d2[v] = max(d[v], x);     for (auto i : edges[v])       if (i != p) {         long long t = d[i] + 1 == mx1 ? mx2 : mx1;         dfs2(i, max(t + 1, x + 1), v);       }   }   void smain() {     long long n, m, q;     cout.precision(8);     cout << fixed;     for (; cin >> n >> m >> q;) {       for (long long i = 0; i < n; i++) edges[i].clear();       memset(c, 255, sizeof(long long) * n);       for (long long i = 0; i < m; i++) {         long long u, v;         cin >> u >> v;         u -= 1, v -= 1;         edges[u].push_back(v);         edges[v].push_back(u);       }       long long k = 0;       for (long long i = 0; i < n; i++)         if (c[i] == -1) {           c[i] = k++;           root = -1, dr = -1;           dfs0(i);           r[k - 1] = root;           dfs(root);           dfs2(root, 0);         }       memset(s, 0, sizeof(long long) * k);       memset(sz, 0, sizeof(long long) * k);       for (long long i = 0; i < k; i++) a[i].clear();       for (long long i = 0; i < n; i++) {         s[c[i]] += d2[i], sz[c[i]] += 1;         a[c[i]][d2[i]].cnt += 1;       }       for (long long i = 0; i < k; i++) {         long long ps = 0, pcnt = 0;         for (auto &j : a[i]) {           ps += j.first * j.second.cnt;           pcnt += j.second.cnt;           j.second.ps = ps;           j.second.pcnt = pcnt;         }       }       map<pair<long long, long long>, long double> cache;       for (long long _i = 0; _i < q; _i++) {         long long u = 0, v = n - 1;         cin >> u >> v;         u -= 1, v -= 1;         if (c[u] == c[v])           cout <<  -1 n ;         else {           u = c[u], v = c[v];           if (sz[u] > sz[v] || (sz[u] == sz[v] || u > v)) swap(u, v);           pair<long long, long long> key(u, v);           if (cache.count(key)) {             cout << cache.at(key) <<   n ;             continue;           }           long long t = s[u] * sz[v] + s[v] * sz[u] + sz[u] * sz[v];           long long mn = max(d[r[u]], d[r[v]]);           for (auto it : a[u]) {             if (it.first + a[v].begin()->first + 1 >= mn) break;             auto jt = a[v].upper_bound(mn - it.first - 1);             if (jt != a[v].begin()) {               jt = prev(jt);               long long j = jt->second.pcnt;               t -= jt->second.ps * it.second.cnt + j * it.first * it.second.cnt +                    j * it.second.cnt;               t += j * it.second.cnt * mn;             }           }           long double res = (long double)t / (sz[u] * sz[v]);           cache.emplace(key, res);           cout << res <<   n ;         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 998244353;   long long int qpow(long long int x, long long int y) {     long long int ans = 1;     while (y) {       if (y & 1) ans = ans * x % mod;       x = x * x % mod;       y >>= 1;     }     return ans;   }   const int maxn = 1024 * 2;   long long int dp[maxn * 2][maxn][2];   long long int inv[maxn * 4];   long long int Solve(int n, int k) {     dp[1][0][1] = 1;     long long int tem = qpow(2, mod - 2);     long long int ans = 0;     for (int i = 1; i < maxn * 4; i++) inv[i] = qpow(i, mod - 2);     for (int i = 1; i <= 2 * n; i++) {       for (int j = 0; j <= n; j++) {         if (j >= k) {           ans = (ans + dp[i][j][0]) % mod;           ans = (ans + dp[i][j][1]) % mod;         }         if (j - 1 <= (2 * n - i) && j >= 1) {           if (j - 1 == 2 * n - i) {             dp[i + 1][j - 1][0] = (dp[i + 1][j - 1][0] + dp[i][j][0]) % mod;           } else if (j == 1) {             dp[i + 1][j - 1][1] = (dp[i + 1][j - 1][1] + dp[i][j][0]) % mod;           } else {             long long int send = (2 * n - (i + j - 1));             long long int reci = j - 1;             long long int invt = inv[send + reci];             dp[i + 1][j - 1][1] =                 (dp[i + 1][j - 1][1] + dp[i][j][0] * send % mod * invt % mod) %                 mod;             dp[i + 1][j - 1][0] =                 (dp[i + 1][j - 1][0] + dp[i][j][0] * reci % mod * invt % mod) %                 mod;           }         }         if (j + 1 <= (2 * n - i)) {           if (j + 1 == (2 * n - i)) {             dp[i + 1][j + 1][0] = (dp[i + 1][j + 1][0] + dp[i][j][1]) % mod;           } else {             long long int send = (2 * n - (i + j + 1));             long long int reci = j + 1;             long long int invt = inv[send + reci];             dp[i + 1][j + 1][1] =                 (dp[i + 1][j + 1][1] + dp[i][j][1] * send % mod * invt % mod) %                 mod;             dp[i + 1][j + 1][0] =                 (dp[i + 1][j + 1][0] + dp[i][j][1] * reci % mod * invt % mod) %                 mod;           }         }       }     }     return ans;   }   int main() {     int n, k, l;     scanf( %d%d%d , &n, &k, &l);     long long int ans = Solve(n, k) * qpow(2 * n + 1, mod - 2) % mod * l % mod;     printf( %lld , ans);   }


#include <bits/stdc++.h>   using namespace std;   struct Query {     int l, r, x;     Query(int l = 0, int r = 0, int x = 0) : l(l), r(r), x(x) {}   };   struct node {     int pref, suff, val;     node(int pref = 0, int suff = 0, int val = 0)         : pref(pref), suff(suff), val(val) {}   };   int n, k;   map<int, int> ha;   int hacnt;   int a[100005];   node st[4000000];   int lazy[4000000];   Query queries[100005];   int ori[1000005];   bool changed[1000000];   set<int> vals;   int mn;   int st1[5000000];   void build1(int p = 1, int l = 0, int r = n - 1) {     if (l == r) {       st1[p] = a[l];       return;     }     int mid = (l + r) >> 1;     build1(p * 2, l, mid);     build1(p * 2 + 1, mid + 1, r);     st1[p] = min(st1[p * 2], st1[p * 2 + 1]);   }   int query1(int i, int j, int p = 1, int l = 0, int r = n - 1) {     if (i > r || j < l) return 1e9 + 3;     if (i <= l && j >= r) return st1[p];     int mid = (l + r) >> 1;     int c1 = query1(i, j, p * 2, l, mid);     int c2 = query1(i, j, p * 2 + 1, mid + 1, r);     return min(c1, c2);   }   int get(int l, int r) {     if (l > r) return 1000000008;     if (r - l + 1 >= n) return mn;     l %= n, r %= n;     if (l > r) return min(query1(l, n - 1), query1(0, r));     return query1(l, r);   }   void merge(node& ret, node& x, node& y) {     ret.pref = x.pref;     ret.suff = y.suff;     ret.val = min(x.val, x.suff);     ret.val = min(ret.val, min(y.val, y.pref));   }   void pushLazy(int p) {     if (lazy[p]) {       lazy[p * 2] = lazy[p * 2 + 1] = lazy[p];       st[p] = node(1000000008, 1000000008, lazy[p]);       lazy[p] = 0;     }   }   void build(int p = 1, int l = 1, int r = hacnt - 1) {     if (l == r) {       if (l != 1)         st[p].pref = get(ori[l - 1] + 1, ori[l] - 1);       else         st[p].pref = 1000000008;       if (r != hacnt - 1)         st[p].suff = get(ori[r] + 1, ori[r + 1] - 1);       else         st[p].suff = 1000000008;       st[p].val = get(ori[l], ori[l]);       return;     }     int mid = (l + r) >> 1;     build(p * 2, l, mid);     build(p * 2 + 1, mid + 1, r);     merge(st[p], st[p * 2], st[p * 2 + 1]);   }   void update(int i, int j, int x, int p = 1, int l = 1, int r = hacnt - 1) {     pushLazy(p);     if (i > r || j < l) return;     if (i <= l && j >= r) {       lazy[p] = x;       pushLazy(p);       return;     }     int mid = (l + r) >> 1;     update(i, j, x, p * 2, l, mid);     update(i, j, x, p * 2 + 1, mid + 1, r);     merge(st[p], st[p * 2], st[p * 2 + 1]);   }   int query(int i, int j, int p = 1, int l = 1, int r = hacnt - 1) {     pushLazy(p);     if (i > r || j < l) return 1000000008;     if (i <= l && j >= r) {       int ret = 1000000008;       if (i != l) ret = min(ret, st[p].pref);       if (j != r) ret = min(ret, st[p].suff);       ret = min(ret, st[p].val);       return ret;     }     int mid = (l + r) >> 1;     int c1 = query(i, j, p * 2, l, mid);     int c2 = query(i, j, p * 2 + 1, mid + 1, r);     return min(c1, c2);   }   int main() {     scanf( %d%d , &n, &k);     mn = 1e9 + 1;     for (int i = 0; i < n; i++) scanf( %d , &a[i]), mn = min(mn, a[i]);     build1();     int q;     scanf( %d , &q);     for (int i = 0; i < q; i++) {       int type;       scanf( %d , &type);       if (type == 1) {         int l, r, x;         scanf( %d%d%d , &l, &r, &x);         l--, r--;         queries[i] = Query(l, r, x);         ha[l];         ha[r];       } else {         int l, r;         scanf( %d%d , &l, &r);         l--, r--;         ha[l];         ha[r];         queries[i] = Query(l, r, -1);       }     }     hacnt = 1;     for (map<int, int>::iterator it = ha.begin(); it != ha.end(); it++) {       it->second = hacnt;       ori[hacnt] = it->first;       vals.insert(hacnt);       hacnt++;     }     build();     for (int i = 0; i < q; i++) {       int l = queries[i].l, r = queries[i].r, x = queries[i].x;       if (x < 0) {         int ans = query(ha[l], ha[r]);         printf( %d n , ans);       } else {         update(ha[l], ha[r], x);         int from = ha[l];         int to = ha[r];         while (1) {           set<int>::iterator it = vals.lower_bound(from);           if (it == vals.end() || *it > to) break;           changed[*it] = 1;           vals.erase(it);         }       }     }     return 0;   }


#include <bits/stdc++.h>   #define ll long long int   #define ld long double   #define NMAX 1009   using namespace std;   ll mask;   ll u,d,r,l;   ll n;   int main()   {       ios_base::sync_with_stdio(false);       cin.tie(NULL);       ll t;       cin>>t;       while(t--)       {       cin>>n>>u>>r>>d>>l;       bool ok=0;       for(mask=0;mask<16;mask++)           {               ll cu=u;           ll cd=d;           ll cl=l;           ll cr=r;          if(mask & 1)              {cu--;cl--;}           if(mask & 2)              {cu--;cr--;}                       if(mask & 4)              {cl--;cd--;}            if(mask & 8)              {cd--;cr--;}           if(cd>=0 && cd<=n-2 && cu>=0 && cu<=n-2 && cl>=0 && cl<=n-2 && cr>=0 && cr<=n-2)              {ok=1;break;}                              }        if(!ok)        cout<< NO n ;        else        cout<< YES n ;          }             return 0;   }   ///limitele si tipul de date!!


#include <bits/stdc++.h>   const int max_N = 1000 + 21;   int n, a[max_N], b[max_N], cnt[max_N];   std::vector<int> vec, _vec, ret[max_N];   int main() {     scanf( %d , &n);     for (int i = 1; i < n; ++i) {       scanf( %d%d , a + i, b + i);       if (a[i] > b[i]) std::swap(a[i], b[i]);       if (b[i] != n) return puts( NO ), 0;       ++cnt[a[i]];     }     for (int i = 1; i < n; ++i)       if (!cnt[i]) {         vec.push_back(i);       } else {         _vec.push_back(i);       }     std::reverse(vec.begin(), vec.end());     std::queue<int> Q;     int i = n - 1;     for (auto u : vec) {       while (i && i > u) {         if (cnt[i]--) {           while (cnt[i]--) Q.push(i);         }         --i;       }       if (Q.empty()) return puts( NO ), 0;       int v = Q.front();       ret[v].push_back(u);       Q.pop();     }     if (!Q.empty()) return puts( NO ), 0;     puts( YES );     for (auto u : _vec) {       if (ret[u].empty()) {         printf( %d %d n , u, n);       } else {         printf( %d %d n , ret[u][0], n);         for (auto i = 1; i < ret[u].size(); ++i) {           printf( %d %d n , ret[u][i - 1], ret[u][i]);         }         printf( %d %d n , ret[u].back(), u);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 123466;   bool is[N];   vector<int> adj[N];   int dp[N];   int mx_dep[N];   const int inf = 1 << 22;   pair<int, int> calc_dp(int v, int p) {     int res = 0;     int mx = -inf;     if (is[v]) mx = 0;     for (auto u : adj[v])       if (u != p) {         auto cur = calc_dp(u, v);         if (cur.first == -inf) continue;         res += cur.first + 1;         res += cur.second + 1;         mx = max(mx, cur.first + 1);       }     if (mx != -inf) res -= mx;     dp[v] = res, mx_dep[v] = mx;     return {mx, res};   }   int ans = inf;   int ans_pos = 1;   int final_ans[N];   void calc(int v, int p, int load_dep, int load_res) {     int added_dep = min(load_dep, mx_dep[v]);     int cur_ans = load_res + dp[v] + added_dep;     if (cur_ans < ans) ans = cur_ans, ans_pos = v;     if (cur_ans == ans && v < ans_pos) ans_pos = v;     final_ans[v] = cur_ans;     multiset<int> s;     s.insert(load_dep);     int nload = load_dep + load_res;     for (auto u : adj[v])       if (u != p) {         if (mx_dep[u] == -inf) continue;         s.insert(mx_dep[u] + 1);         nload += mx_dep[u] + 1 + dp[u] + 1;       }     for (auto u : adj[v])       if (u != p) {         if (mx_dep[u] == -inf) continue;         int cur_nload = nload - mx_dep[u] - 1 - dp[u] - 1;         s.erase(s.find(mx_dep[u] + 1));         int mx = *s.rbegin();         cur_nload -= mx;         calc(u, v, mx + 1, cur_nload + 1);         s.insert(mx_dep[u] + 1);       }   }   int main() {     int n, m;     scanf( %d %d , &n, &m);     for (int i = 0; i < n - 1; i++) {       int x, y;       scanf( %d %d , &x, &y);       adj[x].push_back(y);       adj[y].push_back(x);     }     int root = 1;     for (int i = 0; i < m; i++) {       int x;       scanf( %d , &x);       is[x] = true;       root = x;     }     calc_dp(root, 0);     calc(root, 0, 0, 0);     printf( %d n%d n , ans_pos, ans);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int a[n];     for (int i = 0; i < n; ++i) cin >> a[i];     int dp[n][n];     memset(dp, 0, sizeof dp);     int s = 0;     for (int i = 0; i < n; ++i) {       for (int j = i - 1; j >= 0; --j)         if (a[j] > a[i])           dp[i][j] = dp[i][j + 1] + 1;         else           dp[i][j] = dp[i][j + 1];       for (int j = i + 1; j < n; ++j)         if (a[j] > a[i])           dp[i][j] = dp[i][j - 1] + 1;         else           dp[i][j] = dp[i][j - 1];       s += dp[i][0];     }     int cnt = 0, m = INT_MAX;     for (int i = 0; i < n; ++i) {       for (int j = i + 1; j < n; ++j) {         int tmp = s + dp[i][j] + dp[i][j - 1] - dp[j][i] - dp[j][i + 1];         if (tmp < m) {           m = tmp;           cnt = 1;         } else if (tmp == m)           cnt++;       }     }     cout << m <<     << cnt << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   FILE* g_f_;   int g_s_;   char* g_g_;   template <class _T>   inline _T sqr(const _T& x) {     return x * x;   }   template <class _T>   inline string tostr(const _T& a) {     ostringstream os(  );     os << a;     return os.str();   }   const long double PI = 3.1415926535897932384626433832795;   const long double EPS = 1e-11;   signed long long n;   int k;   signed long long a[1024000];   int main() {     cout << setiosflags(ios::fixed) << setprecision(10);     cin >> n;     if (n % 3 != 0) {       puts( 0 );       return 0;     }     n /= 3;     k = 0;     for (int i = (1); i <= (int)(10000000); i++) {       signed long long x = i;       x *= x;       if (x > n) break;       if (n % i == 0) {         a[k++] = i;         if (x != n) a[k++] = n / i;       }     }     sort(a, a + k);     int cma = (int)(pow(n / 2.0, 1.0 / 3.0) + 1e-7);     signed long long ans = 0;     a[k] = n + 1;     for (int c = (1); c <= (int)(cma); c++) {       int bma = (int)(pow(n / 2.0 / c, 1.0 / 2.0) + 1e-7);       signed long long b = c;       while (b <= bma) {         if (n % (b + c) != 0) {           int t = upper_bound(a, a + k, n / (b + c)) - a;           if (t == 0) break;           signed long long y = a[t - 1];           signed long long nb = n / y - c;           if (nb < b) nb = b + 1;           b = nb;           continue;         }         signed long long bb = b + c;         signed long long cc = b * (signed long long)c - n / (b + c);         signed long long dd = bb * bb - 4LL * cc;         signed long long z = (int)(sqrt(dd) + 1e-7);         signed long long a = (-bb + z) / 2;         if (a < b) break;         if (z * z != dd) goto l1;         if (a != b && b != c)           ans += 6;         else if (a != b || b != c)           ans += 3;         else           ans++;       l1:;         b++;       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   bool b1[N];   int Z, num[N], in[N], dp[N][20], dep[N], freq[2][N], f[N];   long long fans[N];   vector<int> g[N], v;   map<int, int> mp;   struct qq {     int in, l, r, c;     qq(int a, int b, int e, int d) { in = a, l = b, r = e, c = d; }     bool operator<(const qq& s) const {       if (l / Z != s.l / Z) return l / Z < s.l / Z;       return r / Z < s.r / Z;     }   };   vector<qq> q;   void dfs(int u, int p, int d) {     dep[u] = d;     dp[u][0] = p;     in[u] = v.size();     v.push_back(u);     for (int i = 0; i < g[u].size(); i++) {       int v = g[u][i];       if (v != p) dfs(v, u, d + 1);     }     v.push_back(u);   }   int lca(int a, int b) {     if (dep[a] < dep[b]) swap(a, b);     int x = dep[a] - dep[b];     for (int i = 0; i < 20; i++) {       if ((1 << i) & x) a = dp[a][i];     }     if (a == b) return a;     for (int i = 19; i >= 0; i--) {       if (dp[a][i] != dp[b][i]) {         a = dp[a][i], b = dp[b][i];       }     }     return dp[a][0];   }   long long ans;   int l = 0, r = -1;   void add(int in, int d) {     int x = v[in];     f[x] += d;     if (d == 1 && f[x] == 2)       d = -1;     else if (d == -1 && f[x] == 1)       d = 1;     ans += d * freq[!b1[x]][num[x]];     freq[b1[x]][num[x]] += d;   }   void fix(int L, int R) {     while (l < L) {       add(l, -1);       l++;     }     while (l > L) {       l--;       add(l, 1);     }     while (r < R) {       r++;       add(r, 1);     }     while (r > R) {       add(r, -1);       r--;     }   }   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , b1 + i);     }     for (int i = 1; i <= n; i++) {       scanf( %d , num + i);       if (mp.find(num[i]) == mp.end()) mp[num[i]] = mp.size();       num[i] = mp[num[i]];     }     for (int i = 1, a, b; i < n; i++) {       scanf( %d%d , &a, &b);       g[a].push_back(b), g[b].push_back(a);     }     dfs(1, -1, 0);     Z = sqrt(v.size() + 0.0) + 1;     for (int k = 1; k < 20; k++) {       for (int i = 1; i <= n; i++) {         if (dp[i][k - 1] == -1)           dp[i][k] = -1;         else           dp[i][k] = dp[dp[i][k - 1]][k - 1];       }     }     int m;     scanf( %d , &m);     for (int i = 0, a, b, c; i < m; i++) {       scanf( %d%d , &a, &b);       c = lca(a, b);       bool f = (c != a) & (c != b);       q.push_back(qq(i, min(in[a], in[b]) + f, max(in[a], in[b]), c * f));     }     sort(q.begin(), q.end());     for (int i = 0; i < m; i++) {       fix(q[i].l, q[i].r);       if (q[i].c) add(in[q[i].c], 1);       fans[q[i].in] = ans;       if (q[i].c) add(in[q[i].c], -1);     }     for (int i = 0; i < m; i++) {       printf( %I64d n , fans[i]);     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, s = 0, x, m = 0;     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> x;       s += x;       m = max(m, x);     }     long long t = s / (n - 1);     if (s % (n - 1)) t++;     cout << max(m, t);   }


#include <bits/stdc++.h>   using namespace std;   long long dp[5000010], f[5000010];   int main() {     long long t, l, r, i, j, a, b, mod, ans, k = 1, final = 0;     mod = 1e9 + 7;     scanf( %lld %lld %lld , &t, &l, &r);     for (i = 2; i <= r; i++) {       if (dp[i] == 0) {         for (j = i; j <= r; j += i)           if (!dp[j]) dp[j] = i;       }       a = dp[i];       b = i / dp[i];       if (b == 1)         f[i] = (i * (i - 1) / 2) % mod;       else         f[i] = (b * f[a] + f[b]) % mod;       if (i >= l) {         final = (final + k * f[i]) % mod;         k = (k * t) % mod;       }     }     printf( %lld n , final);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int read() {     register char c =    ;     register int v = 0, x = 1;     while ((c <  0 ) || (c >  9 )) {       if (c ==  - ) x = -1;       c = getchar();     }     while ((c >=  0 ) && (c <=  9 )) {       v = (v << 1) + (v << 3) + (c ^ 48);       c = getchar();     }     return v * x;   }   inline void write(register int x) {     if (x < 0) x = -x, putchar( - );     if (x > 9) write(x / 10);     putchar(x % 10 ^ 48);   }   const int N = 2e5 + 10;   int ans, fa[N], dep[N], dp[N][3];   int n, cnt, head[N], v[N], nxt[N], ind[N];   inline void add(register int x, register int y) {     ind[x]++, ind[y]++;     v[++cnt] = y, nxt[cnt] = head[x], head[x] = cnt;     v[++cnt] = x, nxt[cnt] = head[y], head[y] = cnt;   }   inline void dfs(register int u) {     dep[u] = dep[fa[u]] + 1;     dp[u][0] = 0, dp[u][1] = 1;     for (register int i = head[u]; i; i = nxt[i])       if (v[i] != fa[u]) {         fa[v[i]] = u;         dfs(v[i]);         ans = max(ans, dp[u][0] + dp[v[i]][0]);         ans = max(ans, dp[u][1] + dp[v[i]][0]);         ans = max(ans, dp[u][0] + dp[v[i]][1]);         dp[u][0] = max(dp[u][0], dp[v[i]][0] + ind[u] - 2);         dp[u][0] = max(dp[u][0], dp[v[i]][1] + ind[u] - 2);         dp[u][1] = max(dp[u][1], dp[v[i]][0] + 1);       }     ans = max(ans, dp[u][1]);   }   int main() {     n = read();     for (register int i = 1; i < n; i++) add(read(), read());     dfs(1);     write(ans);     return ~~(0 - 0);   }


#include <bits/stdc++.h>   using namespace std;   int n, m = 3, l, c[20000];   char s[500];   int main() {     cin >> n;     while (c[m] <= n) m++, c[m] = (long long)m * (m - 1) * (m - 2) * (m - 3) / 24;     for (int i = m - 1; i >= 1; i--) {       while (c[i] >= 1 && n >= c[i]) {         s[++l] =  a ;         n -= c[i];       }       s[++l] =  b ;     }     printf( %s abbbb n , s + 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char Ma[4105];   int Mp[4105];   void Manacher(char s[], int len) {     int l = 0;     Ma[l++] =  $ ;     Ma[l++] =  # ;     for (int i = 0; i < len; i++) {       Ma[l++] = s[i];       Ma[l++] =  # ;     }     Ma[l] = 0;     int mx = 0, id = 0;     for (int i = 0; i < l; i++) {       Mp[i] = mx > i ? min(Mp[id * 2 - i], mx - i) : 1;       while (Ma[i + Mp[i]] == Ma[i - Mp[i]]) Mp[i]++;       if (i + Mp[i] > mx) {         mx = i + Mp[i];         id = i;       }     }   }   char s[4105];   long long f[4105];   int ans, cnt;   int tmp[2005 * 2005];   int main() {     scanf( %s , s);     int len = strlen(s);     Manacher(s, len);     long long ans = 0;     for (int i = 1; i < 2 * len + 2; i++) {       for (int j = 1; j < Mp[i]; j++)         if (Ma[i - j + 1] !=  # ) {           tmp[++cnt] = i + j - 1;           f[i - j + 1]++;         }     }     for (int i = 2 * len + 2; ~i; i--) f[i] += f[i + 1];     for (int i = 1; i <= cnt; i++) ans += f[tmp[i] + 1];     printf( %I64d n , ans);   }


#include <bits/stdc++.h>   using namespace std;   const int dr[]{-1, -1, 0, 1, 1, 1, 0, -1};   const int dc[]{0, 1, 1, 1, 0, -1, -1, -1};   void run() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);   }   const int sqrtQ = 150;   struct suffix_automaton {     struct state {       int len, link = 0, cnt = 0;       bool terminal = false, is_clone = false;       vector<int> nxt;       state(int len = 0) : len(len), nxt(26, -1) {}       bool have_next(char ch) { return nxt[ch -  a ] != -1; }       void clone(const state &other, int nlen) {         len = nlen;         nxt = other.nxt;         link = other.link;         is_clone = true;       }     };     vector<state> st;     int last = 0;     suffix_automaton() {       st.push_back(state());       st[0].link = -1;     }     suffix_automaton(const string &s) : suffix_automaton() {       for (char ch : s) extend(ch);       calc_number_of_occurrences();     }     void extend(char c) {       int cur = st.size();       st.push_back(state(st[last].len + 1));       st[cur].cnt = 1;       int p = last;       last = cur;       while (p != -1 && !st[p].have_next(c)) {         st[p].nxt[c -  a ] = cur;         p = st[p].link;       }       if (p == -1) return;       int q = st[p].nxt[c -  a ];       if (st[p].len + 1 == st[q].len) {         st[cur].link = q;         return;       }       int clone = st.size();       st.push_back(state());       st[clone].clone(st[q], st[p].len + 1);       while (p != -1 && st[p].nxt[c -  a ] == q) {         st[p].nxt[c -  a ] = clone;         p = st[p].link;       }       st[q].link = st[cur].link = clone;     }     void calc_number_of_occurrences() {       vector<vector<int>> lvl(st[last].len + 1);       for (int i = 1; i < st.size(); i++) lvl[st[i].len].push_back(i);       for (int i = st[last].len; i >= 0; i--)         for (auto cur : lvl[i]) st[st[cur].link].cnt += st[cur].cnt;     }     int count(const string &y) {       int cur = 0;       for (auto &it : y) {         if (!st[cur].have_next(it)) return 0;         cur = st[cur].nxt[it -  a ];       }       return st[cur].cnt;     }   } SA[(int)1e4];   string y;   vector<int> longestPrefix;   vector<int> Fail[26];   int fail(int k, char nxt) {     int &rt = Fail[nxt -  a ][k];     if (~rt) return rt;     while (k > 0 && y[k] != nxt) k = longestPrefix[k - 1];     if (nxt == y[k]) k++;     return rt = k;   }   void failure_function() {     int n = y.size();     longestPrefix = vector<int>(n);     for (int i = 0; i < 26; i++) Fail[i] = vector<int>(n + 1, -1);     for (int i = 1, k = 0; i < n; i++) longestPrefix[i] = k = fail(k, y[i]);   }   int main() {     run();     string s;     int q;     cin >> s >> q;     for (int i = 0; i < (int)(s.size()); i += sqrtQ)       SA[i / sqrtQ] = suffix_automaton(s.substr(i, sqrtQ));     auto solve = [&](int l, int r) {       int match = 0, cnt = 0;       for (int i = l; i <= r; i++) {         match = fail(match, s[i]);         if (match == (int)(y.size())) {           cnt++;           match = longestPrefix[match - 1];         }       }       return cnt;     };     while (q--) {       int t;       cin >> t;       if (t == 1) {         int idx;         char ch;         cin >> idx >> ch;         idx--;         s[idx] = ch;         SA[idx / sqrtQ] = suffix_automaton(s.substr(idx / sqrtQ * sqrtQ, sqrtQ));       } else {         int l, r;         cin >> l >> r >> y;         l--, r--;         failure_function();         if ((int)(y.size()) >= sqrtQ || r - l <= 2 * sqrtQ) {           cout << solve(l, r) <<   n ;           continue;         }         int ans = 0, len = (int)(y.size());         int st = l / sqrtQ, ed = r / sqrtQ;         for (int i = st + 1; i <= ed; i++)           ans += solve(max(l, i * sqrtQ - len + 1), min(r, i * sqrtQ + len - 2));         for (int i = st + 1; i < ed; i++) ans += SA[i].count(y);         ans += solve(l, (st + 1) * sqrtQ - 1);         ans += solve(ed * sqrtQ, r);         cout << ans <<   n ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   void _R(T &x) {     cin >> x;   }   void _R(int &x) { scanf( %d , &x); }   void _R(int64_t &x) { scanf( %lld , &x); }   void _R(double &x) { scanf( %lf , &x); }   void _R(char &x) { scanf(  %c , &x); }   void _R(char *x) { scanf( %s , x); }   void R() {}   template <class T, class... U>   void R(T &head, U &...tail) {     _R(head);     R(tail...);   }   template <class T>   void _W(const T &x) {     cout << x;   }   void _W(const int &x) { printf( %d , x); }   void _W(const int64_t &x) { printf( %lld , x); }   void _W(const double &x) { printf( %.16f , x); }   void _W(const char &x) { putchar(x); }   void _W(const char *x) { printf( %s , x); }   template <class T, class U>   void _W(const pair<T, U> &x) {     _W(x.first);     putchar(   );     _W(x.second);   }   template <class T>   void _W(const vector<T> &x) {     for (auto i = x.begin(); i != x.end(); _W(*i++))       if (i != x.cbegin()) putchar(   );   }   void W() {}   template <class T, class... U>   void W(const T &head, const U &...tail) {     _W(head);     putchar(sizeof...(tail) ?     :   n );     W(tail...);   }   int MOD = 1e9 + 7;   void ADD(long long &x, long long v) {     x = (x + v) % MOD;     if (x < 0) x += MOD;   }   const int SIZE = 1 << 20;   string s[201];   int len[201];   int n, m;   int a[202], b[202];   bitset<4096> d[201][13];   void solve() {     for (int i = (1); i <= (n); ++i) {       len[i] = ((int)(s[i]).size());       for (int l = (1); l <= (12); ++l) {         for (int k = 0; k + l <= len[i]; k++) {           int me = 0;           for (int r = 0; r < (l); ++r) {             me = me * 2 + (s[i][k + r] -  0 );           }           d[i][l][me] = 1;         }       }     }     for (int i = (n + 1); i <= (n + m); ++i) {       for (int l = (1); l <= (12); ++l) {         d[i][l] = d[a[i]][l] | d[b[i]][l];       }       string tmp = s[a[i]].substr(max(0, ((int)(s[a[i]]).size()) - 12)) +                    s[b[i]].substr(0, min(12, ((int)(s[b[i]]).size())));       for (int l = (1); l <= (12); ++l) {         for (int k = 0; k + l <= ((int)(tmp).size()); k++) {           int me = 0;           for (int r = 0; r < (l); ++r) {             me = me * 2 + (tmp[k + r] -  0 );           }           d[i][l][me] = 1;         }       }       s[i] = s[a[i]] + s[b[i]];       if (((int)(s[i]).size()) > 24) {         s[i] = s[i].substr(0, 12) + s[i].substr(((int)(s[i]).size()) - 12);       }       int ans = 0;       while (ans < 12 && d[i][ans + 1].count() == (1 << (ans + 1))) ans++;       W(ans);     }   }   void input() {     R(n);     for (int i = (1); i <= (n); ++i) {       R(s[i]);     }     R(m);     for (int i = (1); i <= (m); ++i) {       R(a[i + n], b[i + n]);     }   }   int main() {     input();     solve();     return 0;   }


#include <bits/stdc++.h>   int c[1000001];   char str[1000001];   int len;   int ct;   long long ans;   int main() {     int k;     int i;     scanf( %d , &k);     scanf( %s , str);     len = strlen(str);     if (k == 0) {       for (i = 0; i < len; i++) {         if (str[i] ==  0 )           ct++;         else {           ans += (long long)ct * (long long)(ct + 1) / 2;           ct = 0;         }       }       ans += (long long)ct * (long long)(ct + 1) / 2;     } else if (k > 0) {       for (i = 0; i < len; i++) {         if (str[i] ==  1 ) ct++;         c[ct]++;       }       ans = c[k];       for (i = k; i <= len; i++) ans += (long long)c[i] * (long long)c[i - k];     }     printf( %I64d n , ans);     scanf(   );   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 100000000;   const long long MAXN = 20100;   int n, a[MAXN], ans;   int main() {     ans = -INF;     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a[i];     }     for (int k = 1; k <= n; k++) {       if (n % k == 0) {         for (int j = 1; j <= k; j++) {           long long sum = 0, cnt = 0;           for (int i = j; i <= n; i += k) {             cnt++;             sum += a[i];           }           if (sum > ans && cnt >= 3) {             ans = sum;           }         }       }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int a[51], n;       cin >> n;       for (int i = 0; i < n; i++) cin >> a[i];       sort(a, a + n);       int res = INT_MAX;       for (int i = 1; i < n; i++) {         res = min(res, a[i] - a[i - 1]);       }       cout << res << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int q;   long long a, b, n;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> q;     while (q--) {       cin >> a >> b >> n;       if (a > b) swap(a, b);       long long ans = 0;       while (b <= n) {         a += b;         swap(a, b);         ans++;       }       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n;     long long int a[45001] = {0};     if (n == 1 || n == 2)       cout <<  No  << endl;     else {       cout <<  Yes  << endl;       cout <<  1             <<     << n << endl;       cout << n - 1;       for (int i = 1; i <= n - 1; i++) {         cout <<     << i;       }       cout << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1000000007;   const int N = 2020;   struct trie {     trie *c[26];     int cnt;   } * root, *nil;   string s1, s2, s3;   int n, l, r, f[N][N], ans;   trie *new_node() {     trie *node = new (trie);     for (int i = 0; i < 26; i++) node->c[i] = nil;     node->cnt = 0;     return node;   }   void deleteTree(trie *root) {     for (int i = 0; i < 26; i++)       if (root->c[i] != nil) {         deleteTree(root->c[i]);         delete (root->c[i]);       }   }   int main() {     getline(cin, s1);     scanf( %d n , &n);     nil = new (trie);     root = new_node();     for (int i = 1; i <= n; i++) {       deleteTree(root);       for (int t = 0; t < 26; t++) root->c[t] = nil;       cin >> s2 >> l >> r;       for (int u = 0; u < s2.size(); u++) {         trie *path = root;         for (int v = u; v < s2.size(); v++) {           int q = s2[v] -  a ;           if (path->c[q] == nil) {             trie *nw = new_node();             path->c[q] = nw;           }           path = path->c[q];           path->cnt++;         }       }       for (int u = 0; u < s1.size(); u++) {         trie *path = root;         for (int v = u; v < s1.size(); v++) {           int q = s1[v] -  a ;           if (path->c[q] == nil) {             if (l == 0)               for (int t = v; t < s1.size(); t++) f[u][t]++;             break;           }           path = path->c[q];           if (path->cnt >= l && path->cnt <= r) f[u][v]++;         }       }     }     deleteTree(root);     for (int t = 0; t < 26; t++) root->c[t] = nil;     for (int i = 0; i < s1.size(); i++) {       trie *path = root;       for (int j = i; j < s1.size(); j++) {         int q = s1[j] -  a ;         if (path->c[q] == nil) {           trie *nw = new_node();           path->c[q] = nw;         }         path = path->c[q];         if (f[i][j] == n && path->cnt == 0) ans++;         path->cnt++;       }     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using pii = pair<int, int>;   void solve(int tc) {     int n;     cin >> n;     vector<vector<int>> adj(n, vector<int>(n));     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         cin >> adj[i][j];       }     }     int k;     cin >> k;     while (k--) {       int a, b, c;       cin >> a >> b >> c;       a--, b--;       ll sumDist = 0;       for (int i = 0; i < n; i++) {         for (int j = i + 1; j < n; j++) {           int newDist = min(adj[i][a] + c + adj[b][j], adj[i][b] + c + adj[a][j]);           if (newDist < adj[i][j]) {             adj[i][j] = adj[j][i] = newDist;           }           sumDist += adj[i][j];         }       }       cout << sumDist <<    ;     }   }   signed main() {     ios::sync_with_stdio(0), cin.tie(0);     int tcs = 1;     for (int tc = 1; tc <= tcs; tc++) solve(tc);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n;     cin >> n;     vector<int> a(n);     for (int i = 0; i < n; ++i) cin >> a[i];     sort(a.begin(), a.end());     int ans = a.back() - a[0];     int eachCanRemove = (n - 2) / 2;     for (int i = 0; i + eachCanRemove + 1 < n; ++i) {       ans = min(ans, a[i + eachCanRemove + 1] - a[i]);     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int caseno = 1;   typedef long long LL;   typedef unsigned long long ULL;   template <class T>   inline void SWAP(T &a, T &b) {     T t = a;     a = b;     b = t;   }   inline LL POW(LL base, LL power) {     LL res = base;     if (power == 0) return 1;     for (int I = 0; I < power - 1; I++) res *= base;     return res;   }   int ToInt(string s) {     int r = 0;     istringstream sin(s);     sin >> r;     return r;   }   double ToDouble(string s) {     double r = 0;     istringstream sin(s);     sin >> r;     return r;   }   string ToString(int n) {     string s;     stringstream convert;     convert << n;     s = convert.str();     return s;   }   const int SIZE = 500 + 10;   string S[SIZE];   int main() {     std::ios_base::sync_with_stdio(0);     int T, I, J, K, N, n, m, k, cnt = 0, len, R, C;     cin >> R >> C;     for (I = 0; I < R; I++) cin >> S[I];     for (I = 0; I < R; I++) {       for (J = 0; J < C; J++) {         if (S[I][J] ==  . ) S[I][J] =  D ;       }     }     for (I = 0; I < R; I++) {       for (J = 0; J < C; J++) {         if (S[I][J] ==  S  && ((J + 1 < C && S[I][J + 1] ==  W ) ||                                (J - 1 >= 0 && S[I][J - 1] ==  W ) ||                                (I + 1 < R && S[I + 1][J] ==  W ) ||                                (I - 1 >= 0 && S[I - 1][J] ==  W ))) {           cout <<  No n ;           return 0;         }       }     }     cout <<  Yes n ;     for (I = 0; I < R; I++) {       for (J = 0; J < C; J++) cout << S[I][J];       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   int n, m;   int A[100005], B[100005], pass[100005];   int l;   int main() {     while (scanf( %d %d , &n, &m) != EOF) {       int i, j;       for (i = 1; i <= n; ++i) scanf( %d , &A[i]);       int sum = 0;       for (i = n; i >= 1; --i) {         if (B[A[i]] == 0) {           ++sum;           B[A[i]] = 1;         }         pass[i] = sum;       }       for (j = 1; j <= m; ++j) {         scanf( %d , &l);         printf( %d n , pass[l]);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int lower_case[26] = {0}, upper_case[26] = {0};   char buf[100010];   int main() {     scanf( %s , buf);     int len = strlen(buf);     for (int i = 0; i < len; i++) {       if (buf[i] <=  Z )         upper_case[buf[i] -  A ]++;       else         lower_case[buf[i] -  a ]++;     }     int best = 100010;     best = min(best, lower_case[ a  -  a ] / 2);     best = min(best, upper_case[ b  -  a ]);     best = min(best, lower_case[ b  -  a ]);     best = min(best, lower_case[ u  -  a ] / 2);     best = min(best, lower_case[ l  -  a ]);     best = min(best, lower_case[ s  -  a ]);     best = min(best, lower_case[ r  -  a ]);     printf( %d n , best);   }


#include <bits/stdc++.h>   using namespace std;   long long pwr(long long base, long long p, long long mod = (1000000007LL)) {     long long ans = 1;     while (p) {       if (p & 1) ans = (ans * base) % mod;       base = (base * base) % mod;       p /= 2;     }     return ans;   }   long long gcd(long long a, long long b) {     if (b == 0) return a;     return gcd(b, a % b);   }   const int N = 3002;   int n, q, K[400002], ans[400002];   vector<int> adj[N], qarr[N][N], stack_;   bool visited[N], instack[N];   set<int> cycles;   void dfs(int v, int src) {     visited[v] = true;     instack[v] = true;     stack_.push_back(v);     for (auto idx : qarr[src][v]) {       if (ans[idx] != 0) continue;       if ((int)stack_.size() >= K[idx] && cycles.empty())         ans[idx] = stack_[K[idx] - 1];       else         ans[idx] = -1;     }     for (auto vv : adj[v]) {       if (!visited[vv]) {         dfs(vv, src);       } else if (instack[vv]) {         cycles.insert(vv);       }     }     instack[v] = false;     cycles.erase(v);     stack_.pop_back();   }   int main() {     int m;     scanf( %d%d%d , &n, &m, &q);     while (m--) {       int a, b;       scanf( %d%d , &a, &b);       adj[a].push_back(b);     }     for (int i = 1; i <= n; i++) sort(adj[i].begin(), adj[i].end());     for (int i = 1; i <= q; i++) {       int s, t, k;       scanf( %d%d%d , &s, &t, &k);       K[i] = k;       qarr[s][t].push_back(i);     }     for (int i = 1; i <= n; i++) {       memset(visited, 0, sizeof(visited));       memset(instack, 0, sizeof(instack));       cycles.clear();       stack_.clear();       dfs(i, i);     }     for (int i = 1; i <= q; i++) {       if (ans[i] == 0) ans[i] = -1;       printf( %d n , ans[i]);     }     return 0;   }


#include <bits/stdc++.h>   int n, K, F[3005][3005];   char s[3005][15],       T[10][10] = { 1110111 ,  0010010 ,  1011101 ,  1011011 ,  0111010 ,                     1101011 ,  1101111 ,  1010010 ,  1111111 ,  1111011 };   int read() {     char c = getchar();     int ans = 0;     while (c <  0  || c >  9 ) c = getchar();     while (c >=  0  && c <=  9 ) ans = ans * 10 + c -  0 , c = getchar();     return ans;   }   void Write(int x) {     if (x < 10)       putchar(x ^ 48);     else       Write(x / 10), putchar((x % 10) ^ 48);     return;   }   int Count(int id, int x) {     int k = 0;     for (register int i = 0; i < 7; i++) {       if (s[id][i] ==  1  && T[x][i] ==  0 ) return -1;       if (s[id][i] ==  0  && T[x][i] ==  1 ) ++k;     }     return k;   }   int main() {     n = read(), K = read();     F[n + 1][0] = 1;     for (register int i = 1; i <= n; i++) scanf( %s , s[i]);     for (register int i = n; i; i--)       for (register int j = 0, now; j < 10; j++) {         if ((now = Count(i, j)) == -1) continue;         for (register int k = K; k >= now; k--) F[i][k] |= F[i + 1][k - now];       }     if (!F[1][K]) {       putchar( - ), putchar( 1 );       return 0;     }     for (register int i = 1; i <= n; i++)       for (register int j = 9, now; j >= 0; j--) {         if ((now = Count(i, j)) == -1) continue;         if (K >= now && F[i + 1][K - now]) {           putchar( 0  + j), K -= now;           break;         }       }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ii = pair<int, int>;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int q;     cin >> q;     for (int cas = 0; cas < q; ++cas) {       ll a, b, m;       cin >> a >> b >> m;       if (a == b) {         cout << 1 <<     << a <<   n ;         continue;       }       if (b - a <= m) {         cout << 2 <<     << a <<     << b <<   n ;         continue;       }       bool poss = false;       for (ll ans = 3; ans <= 50; ++ans) {         vector<ll> sum(ans + 1, 0);         sum[1] = a;         sum[2] = a + 1;         bool loc = true;         for (int i = 3; i <= ans; ++i) {           for (int j = 1; j < i; ++j) {             sum[i] += sum[j];             if (sum[i] > b) {               loc = false;               break;             }           }           sum[i]++;           if (sum[i] > b) loc = false;           if (!loc) break;         }         if (!loc) continue;         vector<ll> v(ans + 1, 1);         for (int i = 2; i <= ans; ++i) {           ll l = 0, r = m;           for (int j = 0; j < 50; ++j) {             ll mm = (l + r) / 2;             if (i == ans) {               if (sum[ans] + mm > b)                 r = mm;               else                 l = mm;             } else {               if (sum[ans] + mm * (1LL << (ans - (i + 1LL))) > b)                 r = mm;               else                 l = mm;             }           }           v[i] += l;           if (i == ans)             sum[ans] += l;           else             sum[ans] += (l * (1LL << (ans - (i + 1LL))));         }         if (sum[ans] > b) break;         if (sum[ans] == b) {           cout << ans <<    ;           ll curr = a;           vector<ll> res(ans + 1, 0);           res[1] = a;           for (int i = 2; i <= ans; ++i) {             for (int j = 1; j < i; ++j) res[i] += res[j];             res[i] += v[i];           }           for (int i = 1; i <= ans; ++i) cout << res[i] <<    ;           cout <<   n ;           poss = true;           break;         }       }       if (!poss) cout << -1 <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long max(long long a, long long b) {     if (a > b) {       return a;     } else {       return b;     }   }   long long min(long long a, long long b) {     if (a < b) {       return a;     } else {       return b;     }   }   int ma[101][101], yes[101];   int main() {     int n;     cin >> n;     int r = n / 2;     if (n % 2 == 1) {       r++;     }     cout << (n / 2) * r << endl;     for (long long i = 1; i <= n / 2; i++) {       for (long long j = n / 2 + 1; j <= n; j++) {         cout << i <<     << j << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int M, N, x, a[400010], mini = 0;     cin >> M >> N;     memset(a, 0, sizeof(a));     for (int i = 1; i <= M; i++) {       scanf( %d , &x);       a[x % N]++;       if (x % N != mini)         printf( %d n , a[mini] * N + mini);       else {         if (i < N) {           for (int j = mini; j <= min(N - 1, i); j++) {             if (a[j] == 0) {               mini = j;               break;             }             if (a[mini] > a[j]) mini = j;           }         } else {           mini = 0;           for (int j = 1; j <= min(N - 1, i); j++) {             if (a[j] == 0) {               mini = j;               break;             }             if (a[mini] > a[j]) mini = j;           }         }         printf( %d n , a[mini] * N + mini);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long read() {     long long x = 0, f = 0;     char c = getchar();     while (!isdigit(c)) f |= c ==  - , c = getchar();     while (isdigit(c)) x = x * 10 + c -  0 , c = getchar();     return f ? -x : x;   }   inline int max(int a, int b, int c) { return max(a, max(b, c)); }   int n, m, a[200010];   struct Trie {     int nxt[2], sz;   } T[200010 * 31];   int rt = 1, top = 1;   void insert(int x) {     int now = rt;     for (int i = 31; ~i; --i) {       if (!T[now].nxt[x >> i & 1]) T[now].nxt[x >> i & 1] = ++top;       now = T[now].nxt[x >> i & 1];     }     T[now].sz = 1;   }   int ans;   int dfs(int i, int d) {     if (!i) return 0;     int ls, rs;     if (d == -1) return min(2, T[i].sz);     ls = dfs(T[i].nxt[0], d - 1);     T[i].sz += T[T[i].nxt[0]].sz;     rs = dfs(T[i].nxt[1], d - 1);     T[i].sz += T[T[i].nxt[1]].sz;     if (ls == 2 && rs == 2)       ans += min(T[T[i].nxt[0]].sz, T[T[i].nxt[1]].sz) - 1,           T[i].sz -= min(T[T[i].nxt[0]].sz, T[T[i].nxt[1]].sz) - 1;     return min(2, ls + rs);   }   int main() {     cin >> n;     for (int i = 1; i <= n; ++i) a[i] = read(), insert(a[i]);     dfs(rt, 31);     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   std::mt19937_64 rng(       std::chrono::steady_clock::now().time_since_epoch().count());   long long int myRand(long long int R) {     long long int val = rng() % R;     assert(val >= 0);     return val;   }   const long double PI = atan(1.0) * 4;   const int32_t INF32 = 2e9 + 7;   const int64_t INF64 = 3e18;   const int32_t LOG = 21;   const int32_t MOD = 1e9 + 7;   using namespace std;   void my_debugger(string second, long long int LINE_NUM) { cerr <<   n ; }   template <typename start, typename... end>   void my_debugger(string second, long long int LINE_NUM, start x, end... y) {     if (second.back() !=  , ) {       second +=  , ;       cerr <<  LINE(  << LINE_NUM <<  ):  ;     }     long long int i = second.find( , );     cerr << second.substr(0, i) <<   =   << x;     second = second.substr(i + 1);     if (!second.empty()) cerr <<  ,  ;     my_debugger(second, LINE_NUM, y...);   }   int32_t main() {     ios_base::sync_with_stdio(false), cin.tie(nullptr);     long long int tests = 1;     for (long long int ii = 0; ii < (long long int)tests; ii++) {       vector<long long int> a(6);       for (long long int i = 0; i < (long long int)6; i++) cin >> a[i];       long long int n;       cin >> n;       vector<long long int> b(n);       for (long long int i = 0; i < (long long int)n; i++) cin >> b[i];       long long int ans = 2e9;       vector<pair<long long int, long long int> > v;       for (long long int fret = 0; fret < (long long int)6; fret++) {         for (long long int i = 0; i < (long long int)n; i++) {           long long int x = b[i] - a[fret];           v.push_back({b[i] - a[fret], i});         }       }       sort(v.begin(), v.end());       long long int siz = v.size();       vector<long long int> cnt(n, 0);       long long int cur = 0;       long long int tot = 0;       for (long long int i = 0; i < (long long int)v.size(); i++) {         while (cur < siz && tot < n) {           cnt[v[cur].second]++;           if (cnt[v[cur].second] == 1) tot++;           cur++;         }         if (tot == n) ans = min(ans, v[cur - 1].first - v[i].first);         cnt[v[i].second]--;         if (cnt[v[i].second] == 0) tot--;       }       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string a, b;   int r = 0;   int main() {     getline(cin, a);     getline(cin, b);     int k = 0;     while (a[k] ==  0 ) k++;     a = a.substr(k, a.size() - k);     k = 0;     while (b[k] ==  0 ) k++;     b = b.substr(k, b.size() - k);     if (a.size() < b.size()) {       cout <<  <  << endl;       return 0;     }     if (a.size() > b.size()) {       cout <<  >  << endl;       return 0;     }     for (int i = 0; i < a.size(); i++) {       if (a[i] > b[i]) {         cout <<  >  << endl;         return 0;       }       if (a[i] < b[i]) {         cout <<  <  << endl;         return 0;       }     }     cout <<  =  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     char arr[n];     int sf = 0, fs = 0;     for (int i = 0; i < n; i++) {       cin >> arr[i];     }     for (int j = 0; j < n - 1; j++) {       if (arr[j] ==  S ) {         if (arr[j + 1] ==  F ) sf++;       } else if (arr[j] ==  F ) {         if (arr[j + 1] ==  S ) fs++;       }     }     if (sf > fs)       cout <<  YES ;     else       cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 502;   int n, m, l = -1, ok = 1, r;   string s[N];   int main() {     cin >> n >> m;     for (int i = 0; i < n; i++) cin >> s[i];     for (int j = 0; j < n; j++) {       l = r = -1;       for (int i = 0; i < s[j].length(); i++) {         if (l == -1 && s[j][i] ==  X )           l = r = i;         else if (l != -1 && s[j][i] ==  X ) {           r = i;         }       }       if (l != -1) break;     }     if (l == -1) {       cout <<  NO ;       return 0;     }     for (int i = 0; i < n; i++) {       int cnt = 0;       for (int j = l; j <= r; j++)         if (s[i][j] ==  X ) cnt++;       if (cnt != r - l + 1 && cnt != 0) ok = 0;     }     if (ok == 1)       for (int i = 0; i < n; i++)         for (int j = 0; j < s[i].length(); j++)           if ((j < l || j > r) && s[i][j] ==  X ) ok = 0;     if (ok)       cout <<  YES ;     else       cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string str;     cin >> str;     string s =  WUB ;     size_t pos = str.find(s);     while (pos != string::npos) {       string token = str.substr(0, pos);       if (token.length() != 0) cout << token <<    ;       str.erase(0, pos + 3);       pos = str.find(s);     }     cout << str << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7, M = 2e6 + 7, INF = INT_MAX / 10;   long long powe(long long x, long long y) {     x = x % mod, y = y % (mod - 1);     long long ans = 1;     while (y > 0) {       if (y & 1) {         ans = (1ll * x * ans) % mod;       }       y >>= 1;       x = (1ll * x * x) % mod;     }     return ans;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     int n, m, p;     cin >> n >> m >> p;     int a1[n], a2[m];     for (int i = 0; i < n; i++) cin >> a1[i];     for (int i = 0; i < m; i++) cin >> a2[i];     int p1, p2;     for (p1 = 0; p1 < n; p1++) {       if (a1[p1] % p) break;     }     for (p2 = 0; p2 < m; p2++) {       if (a2[p2] % p) break;     }     int ans = p1 + p2;     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, ans = 1e9;   int a[100005];   inline int read() {     int x = 0, f = 1;     char ch = getchar();     for (; ch <  0  || ch >  9 ; ch = getchar())       if (ch ==  - ) f = -1;     for (; ch >=  0  && ch <=  9 ; ch = getchar()) x = x * 10 + ch -  0 ;     return x * f;   }   inline void print(int x) {     if (x >= 10) print(x / 10);     putchar(x % 10 +  0 );   }   int main() {     n = read(), m = read();     for (int i = 1, l, r; i <= m; i++)       l = read(), r = read(), ans = min(ans, r - l + 1);     for (int i = 1; i <= ans; i++) a[i] = i - 1;     for (int i = ans + 1; i <= n; i++) a[i] = a[i - ans];     print(ans);     puts(  );     for (int i = 1; i <= n; i++) print(a[i]), putchar(   );     puts(  );     return 0;   }


#include <bits/stdc++.h>   const long long mod = (long long)1e9 + 7;   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long n, m;     cin >> n >> m;     vector<long long> v(m);     bool valid = true;     for (long long i = 0; i < m; i++) {       cin >> v[i];       if (v[i] == n or v[i] == 1) valid = 0;     }     if (!valid) {       cout <<  NO             <<   n ;       return 0;     }     sort(v.begin(), v.end());     for (long long i = 2; i < m; i++) {       if (v[i] - 1 == v[i - 1] and v[i] - 2 == v[i - 2]) {         valid = 0;         break;       }     }     if (valid)       cout <<  YES             <<   n ;     else       cout <<  NO             <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     string out, chr;     cin >> n >> k;     for (int i = 0; i < k; ++i) chr +=  a  + i;     for (int i = 0; i < n; ++i) out += chr[i % k];     cout << out;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O2 )   #pragma GCC optimize( unroll-loops )   using namespace std;   const int MAX = 47 + 5;   const long long MAX2 = 11;   const long long MOD = 1000000007;   const long long MOD2 = 1000005329;   const long long INF = 2e18;   const int dr[] = {1, 0, -1, 0, 1, 1, -1, -1, 0};   const int dc[] = {0, 1, 0, -1, 1, -1, 1, -1, 0};   const double pi = acos(-1);   const double EPS = 1e-9;   const int block = 555;   int n, x[MAX], sm, k, tmp;   long long dp[MAX][MAX][MAX], fr[MAX];   double ans, res;   long long f(int nw, int rem, int cnt) {     if (rem == 0) return cnt == 0;     if (cnt < 0 || nw > n) return 0;     long long &ret = dp[nw][rem][cnt];     if (ret != -1) return ret;     ret = f(nw + 1, rem, cnt);     if (x[nw] <= rem) ret += f(nw + 1, rem - x[nw], cnt - 1);     return ret;   }   int main() {     cout << fixed << setprecision(10);     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n;     for (int i = 1; i <= n; ++i) cin >> x[i], sm += x[i];     cin >> k;     if (k >= sm) return cout << n <<   n , 0;     for (int i = 1; i <= n; ++i) {       tmp = x[i];       x[i] = 100;       memset(dp, -1, sizeof dp);       for (int j = max(1, k - tmp + 1); j <= k; ++j)         for (int o = 1; o <= n; ++o) fr[o] += f(1, j, o);       x[i] = tmp;     }     for (int i = 1; i <= n; ++i) {       res = fr[i] * i;       for (int j = i + 1; j < n; ++j) res /= j, res *= n - j;       res /= n;       ans += res;     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, x;   int main() {     scanf( %d%d , &n, &m);     x = n;     for (int i = 0; i < m; i++) {       int l, r;       scanf( %d%d , &l, &r);       x = min(x, r - l + 1);     }     printf( %d n , x);     for (int i = 0; i < n; i++) printf( %d  , i % x);     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n, m;     cin >> n >> m;     vector<int> g(n), v(m), b(m);     for (auto &i : g) cin >> i;     for (auto &i : v) cin >> i;     for (auto &i : b) cin >> i;     int res = 0;     vector<bool> news(n, false);     vector<int> x(n, 1);     for (int i = 1; i <= m; ++i) {       int a = (v[i - 1] + res - 1) % n + 1;       int rating = b[i - 1] >= n ? n : b[i - 1], ctr = 0, temp = a;       if (!news[a - 1]) {         news[a - 1] = 1;         ctr++;       }       while (rating) {         rating -= x[a - 1];         if (rating <= 0) break;         temp = g[a - 1];         if (!news[temp - 1]) {           news[temp - 1] = 1;           ctr++;         }         x[a - 1] += x[temp - 1];         g[a - 1] = g[temp - 1];         a = temp;       }       res = ctr;       cout << ctr <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int in() {     int x, y;     y = scanf( %d , &x);     return x;   }   const int N = 2 * 100 * 1000 + 5;   int a[N], ans[N];   vector<pair<int, int>> v;   int seg[4 * N];   void add(int p, int s = 0, int e = N, int x = 1) {     seg[x]++;     if (e - s == 1) return;     int mid = (s + e) / 2;     if (p < mid)       add(p, s, mid, 2 * x);     else       add(p, mid, e, 2 * x + 1);   }   int pth(int p, int s = 0, int e = N, int x = 1) {     if (e - s == 1) return s;     int mid = (s + e) / 2;     if (seg[2 * x] >= p)       return pth(p, s, mid, 2 * x);     else       return pth(p - seg[2 * x], mid, e, 2 * x + 1);   }   int main() {     int n = in();     for (int i = 0; i < n; i++) {       a[i] = in();       v.push_back({-a[i], i});     }     sort(v.begin(), v.end());     vector<pair<pair<int, int>, int>> que;     int m = in();     for (int i = 0; i < m; i++) {       int k = in(), p = in();       que.push_back({{k, p}, i});     }     sort(que.begin(), que.end());     int r = 0;     for (auto q : que) {       int k = q.first.first, p = q.first.second, t = q.second;       while (r < k) {         add(v[r++].second);       }       ans[t] = a[pth(p)];     }     for (int i = 0; i < m; i++) cout << ans[i] <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 100000 + 10;   const int Alpha = 27;   string str;   int sum[Alpha], need[Alpha];   int get(char a) {     if (a ==  9 ) a =  6 ;     if (a ==  5 ) a =  2 ;     return a -  0 ;   }   int main() {     int i;     cin >> str;     for ((i) = (0); (i) != ((int)str.size()); ++(i)) ++need[get(str[i])];     cin >> str;     for ((i) = (0); (i) != ((int)str.size()); ++(i)) ++sum[get(str[i])];     int ans = 1000000000;     for ((i) = (0); (i) != (Alpha); ++(i))       if (!sum[i] && need[i])         ans = 0;       else if (need[i])         ans = min(ans, sum[i] / need[i]);     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string s;   long long a[101], b[101];   int main() {     long long i, j, k, l, n, c, m, x, y, lft, rgt, p, q;     cin >> n;     for (i = 0; i < 2 * n; i++) {       cin >> a[i];     }     sort(a, a + 2 * n);     c = 0;     p = 0;     long long mnm = 1267357834;     for (i = 0; i < 2 * n; i++) {       if (i > 0) {         p = 0;         for (j = 0; j < i; j++) {           b[p++] = a[j];         }       }       for (j = i + 1; j < 2 * n; j++) {         q = p;         for (k = i + 1; k < 2 * n; k++) {           if (k != j) {             b[q++] = a[k];           }         }         long long x = 0;         for (k = 0; k < q; k += 2) {           x += abs(b[k] - b[k + 1]);         }         mnm = min(mnm, x);       }     }     cout << mnm << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool arr[1001][1001];   struct node {     int ct;     int lastind;   };   struct node1 {     int ct;     int lastind;   };   node row[1001];   node1 col[1001];   int main() {     vector<int> a;     int n, i, x, y, j, temp;     scanf( %d , &n);     for (i = 0; i < n - 1; i++) {       scanf( %d%d , &x, &y);       arr[x][y] = 1;     }     for (i = 1; i <= n; i++) {       row[i].ct = 0;       row[i].lastind = 0;       for (j = 1; j <= n; j++) {         if (arr[i][j]) {           row[i].ct++;           row[i].lastind = j;         }       }     }     for (i = 1; i <= n; i++) {       temp = i;       for (j = i + 1; j <= n; j++) {         if (row[temp].ct > row[j].ct) {           temp = j;         } else if (row[temp].ct == row[j].ct &&                    row[temp].lastind > row[j].lastind)           temp = j;       }       if (temp != i) {         a.push_back(1);         a.push_back(i);         a.push_back(temp);         swap(row[i], row[temp]);         for (j = 1; j <= n; j++) {           swap(arr[i][j], arr[temp][j]);         }       }     }     for (i = 1; i <= n; i++) {       col[i].ct = 0;       col[i].lastind = n;       for (j = 1; j <= n; j++) {         if (arr[j][i]) {           col[i].ct++;           col[i].lastind = min(col[i].lastind, j);         }       }     }     for (i = 1; i <= n; i++) {       temp = i;       for (j = i + 1; j <= n; j++) {         if (col[temp].ct < col[j].ct) {           temp = j;         } else if (col[temp].ct == col[j].ct &&                    col[temp].lastind > col[j].lastind)           temp = j;       }       if (temp != i) {         a.push_back(2);         a.push_back(i);         a.push_back(temp);         swap(col[i], col[temp]);       }     }     printf( %d n , a.size() / 3);     for (i = 0; i < a.size(); i += 3) {       printf( %d %d %d n , a[i], a[i + 1], a[i + 2]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const int maxn = 2e5 + 5;   int a[maxn], lst[maxn];   bool used[maxn];   int occ[maxn];   int main() {     ios::sync_with_stdio(false);     int n;     cin >> n;     int ans = n;     for (int i = 1; i <= n; i++) {       cin >> a[i];       lst[a[i]] = i;       if (occ[a[i]] == 0) ans--;       occ[a[i]]++;     }     cout << ans <<   n ;     int j = 1;     for (int i = 1; i <= n; i++) {       if (!used[a[i]] && (a[i] < j || lst[a[i]] == i)) {         used[a[i]] = true;         cout << a[i] <<    ;       } else {         while ((j != a[i] && occ[j] > 0) || occ[j] == 1 || used[j]) j++;         used[j] = true;         cout << j <<    ;       }     }     cout <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6 + 10, maxm = 2e6 + 10;   const long long INF = 0x3f3f3f3f, mod = 1e9 + 7;   int casn, n, m, k;   namespace graph {   vector<int> g[maxn];   int all, sz[maxn], root, maxt;   bool vis[maxn];   int dfs_root(int now, int fa) {     int cnt = 1;     for (auto to : g[now]) {       if (to == fa || vis[to]) continue;       cnt += dfs_root(to, now);     }     int tmp = max(cnt - 1, all - cnt);     if (maxt > tmp) maxt = tmp, root = now;     return sz[now] = cnt;   }   int ans[maxn];   void dfs_col(int now, int fa, int c) {     ans[now] = c;     for (auto to : g[now])       if (to != fa && !vis[to]) dfs_col(to, now, c);   }   void dfs_dv(int now, int d = 0) {     vis[now] = 1;     dfs_col(now, now, d);     for (auto to : g[now]) {       if (vis[to]) continue;       maxt = root = n + 1;       all = sz[to];       dfs_root(to, now);       dfs_dv(root, d + 1);     }   }   void solve(int n) {     all = maxt = root = n + 1;     dfs_root(1, 1);     dfs_dv(root);   }   }  // namespace graph   using namespace graph;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n;     for (int i = 2; i <= n; ++i) {       int a, b;       cin >> a >> b;       g[a].push_back(b);       g[b].push_back(a);     }     solve(n);     for (int i = 1; i <= n; ++i) cout << char(ans[i] +  A ) <<    ;   }


#include <bits/stdc++.h>   using namespace std;   long long read() {     long long s = 0, w = 1;     char c;     while (c = getchar(), c >  9  || c <  0 )       if (c ==  - ) w = -1;     while (c >=  0  && c <=  9 ) s = s * 10 + c -  0 , c = getchar();     return s * w;   }   void write(long long x) {     if (x < 0) putchar( - ), x = -x;     if (x >= 10) write(x / 10);     putchar(x % 10 +  0 );   }   void writeln(long long x) {     write(x);     puts(  );   }   const long long N = 1e5 + 7, B = 20, inf = 1e9;   long long n, m, x;   long long a[N];   struct tree {     long long la[B], ra[B];     long long ans;   } tr[N << 2];   long long chu(tree ls, tree rs, long long l, long long r, long long mid) {     long long ln = 0, rn = 0;     long long la[B + 2], ra[B + 2];     long long las[B + 2], ras[B + 2];     for (long long i = 0; i < B; i++)       if (ls.ra[i]) ra[++rn] = ls.ra[i];     for (long long i = 0; i < B; i++)       if (rs.la[i] <= n) la[++ln] = rs.la[i];     sort(la + 1, la + ln + 1);     sort(ra + 1, ra + rn + 1);     ln = unique(la + 1, la + ln + 1) - la - 1;     rn = unique(ra + 1, ra + rn + 1) - ra - 1;     if (!ln && !rn) return x == 0 ? (mid - l + 1) * (r - mid) : 0;     las[0] = 0;     ras[rn + 1] = 0;     ra[rn + 1] = mid;     la[0] = mid + 1;     if (!ln) {       for (long long i = rn; i >= 1; i--) ras[i] = ras[i + 1] | a[ra[i]];       for (long long i = rn + 1; i >= 1; i--) {         if (ras[i] >= x) return (ra[i] - l + 1) * (r - mid);       }     } else if (!rn) {       for (long long i = 1; i <= ln; i++) las[i] = las[i - 1] | a[la[i]];       for (long long i = 0; i <= ln; i++) {         if (las[i] >= x) return (mid - l + 1) * (r - la[i] + 1);       }     } else {       long long ans = 0;       for (long long i = rn; i >= 1; i--) ras[i] = ras[i + 1] | a[ra[i]];       for (long long i = 1; i <= ln; i++) las[i] = las[i - 1] | a[la[i]];       for (long long i = 1, j = 0; i <= rn; i++) {         while (j <= ln && (ras[i] | las[j]) < x) j++;         if (j > ln) break;         ans += (ra[i] - (i == 1 ? l - 1 : ra[i - 1])) * (r - la[j] + 1);       }       if (ras[rn] != mid) {         long long j = 0;         while (j <= ln && las[j] < x) j++;         if (j <= ln) ans += (mid - ra[rn]) * (r - la[j] + 1);       }       return ans;     }     return 0;   }   tree pushup(tree ls, tree rs, long long l, long long r, long long mid) {     tree c;     for (long long i = 0; i < B; i++) {       c.la[i] = min(ls.la[i], rs.la[i]);       c.ra[i] = max(ls.ra[i], rs.ra[i]);     }     c.ans = ls.ans + rs.ans + chu(ls, rs, l, r, mid);     return c;   }   void change(long long ts, long long v, long long l) {     tr[ts].ans = (v >= x);     for (long long i = 0; i < B; i++) {       long long k = v >> i & 1;       if (k)         tr[ts].la[i] = l, tr[ts].ra[i] = l;       else         tr[ts].la[i] = inf, tr[ts].ra[i] = 0;     }   }   void build(long long ts, long long l, long long r) {     if (l == r) {       change(ts, a[l], l);       return;     }     long long mid = (l + r) >> 1;     build(ts << 1, l, mid);     build(ts << 1 | 1, mid + 1, r);     tr[ts] = pushup(tr[ts << 1], tr[ts << 1 | 1], l, r, mid);   }   void update(long long ts, long long l, long long r, long long k, long long v) {     if (l == r) {       change(ts, v, l);       return;     }     long long mid = (l + r) >> 1;     if (k <= mid)       update(ts << 1, l, mid, k, v);     else       update(ts << 1 | 1, mid + 1, r, k, v);     tr[ts] = pushup(tr[ts << 1], tr[ts << 1 | 1], l, r, mid);   }   tree query(long long ts, long long l, long long r, long long L, long long R) {     if (l == L && r == R) return tr[ts];     long long mid = (l + r) >> 1;     if (R <= mid)       return query(ts << 1, l, mid, L, R);     else if (L > mid)       return query(ts << 1 | 1, mid + 1, r, L, R);     else       return pushup(query(ts << 1, l, mid, L, mid),                     query(ts << 1 | 1, mid + 1, r, mid + 1, R), L, R, mid);   }   signed main() {     n = read(), m = read(), x = read();     for (long long i = 1; i <= n; i++) a[i] = read();     build(1, 1, n);     for (long long i = 1, opt, l, r; i <= m; i++) {       opt = read(), l = read(), r = read();       if (opt == 1)         a[l] = r, update(1, 1, n, l, r);       else {         writeln(query(1, 1, n, l, r).ans);       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   int main() {     int t;     scanf( %d , &t);     ;     while (t--) {       int n;       scanf( %d , &n);       ;       if (n % 2 == 0) {         n = n / 2;         while (n--) {           cout << 1;         }         cout <<   n ;       } else {         n = n / 2;         n--;         cout << 7;         while (n--) {           cout << 1;         }         cout <<   n ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int dp[1 << 6][1 << 6][41][41];   int h, w;   const int dy[] = {-1, 0, 0, 1, 0};   const int dx[] = {0, -1, 1, 0, 0};   int dfs(const int up, const int down, const int cx, const int cy) {     if (cy == h) {       int cnt = 0;       for (int i = 0; i < w; i++)         if (!((up >> i) & 1)) cnt++;       return cnt;     } else if (cx == w)       return dfs(up, down, 0, cy + 1);     if (dp[up][down][cy][cx] != -1) return dp[up][down][cy][cx];     int res = 0;     for (int i = 0; i < 5; i++) {       const int mx = cx + dx[i];       const int my = cy + dy[i];       if (!(my >= 0 && mx >= 0 && mx < w && my < h)) continue;       int nup = up;       int ndown = down;       if (dy[i] == -1) {         if ((down >> cx) & 1)           nup |= (1 << cx);         else           nup &= ~(1 << cx);         ndown &= ~(1 << cx);         int adNum = 0;         if (cy == 0) adNum = 0;         res = max(res, dfs(nup, ndown, cx + 1, cy) + adNum);       } else if (dy[i] == 1) {         if ((down >> cx) & 1)           nup |= (1 << cx);         else           nup &= ~(1 << cx);         ndown |= (1 << cx);         int adNum = !((up >> cx) & 1);         if (cy == 0) adNum = 0;         res = max(res, dfs(nup, ndown, cx + 1, cy) + adNum);       } else if (dx[i] == 1) {         ndown |= (1 << mx);         if ((down >> cx) & 1)           nup |= (1 << cx);         else           nup &= ~(1 << cx);         ndown &= ~(1 << cx);         int adNum = !((up >> cx) & 1);         if (cy == 0) adNum = 0;         res = max(res, dfs(nup, ndown, cx + 1, cy) + adNum);       } else if (dx[i] == -1) {         nup |= (1 << mx);         if ((down >> cx) & 1)           nup |= (1 << cx);         else           nup &= ~(1 << cx);         ndown &= ~(1 << cx);         int adNum = !((up >> cx) & 1);         if (cy == 0) adNum = 0;         res = max(res, dfs(nup, ndown, cx + 1, cy) + adNum);       } else {         ndown &= ~(1 << cx);         nup |= (1 << cx);         int adNum = !((up >> cx) & 1);         if (cy == 0) adNum = 0;         res = max(res, dfs(nup, ndown, cx + 1, cy) + adNum);       }     }     return dp[up][down][cy][cx] = res;   }   int main() {     int n, m;     cin >> n >> m;     if (n > m) swap(n, m);     w = n;     h = m;     memset(dp, -1, sizeof(dp));     int res = dfs(0, 0, 0, 0);     cout << res << endl;     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   int gi() {     int x = 0, w = 1;     char ch = getchar();     while ((ch <  0  || ch >  9 ) && ch !=  - ) ch = getchar();     if (ch ==  - ) w = 0, ch = getchar();     while (ch >=  0  && ch <=  9 )       x = (x << 3) + (x << 1) + ch -  0 , ch = getchar();     return w ? x : -x;   }   const int N = 4e5 + 5;   int n, m, col[N], fa[N];   long long ans[N];   vector<int> E[N];   vector<pair<int, int> > vec[N];   namespace lct {   int fa[N], ch[2][N], sz[N], si[N];   long long sz2[N], si2[N];   bool son(int x) { return x == ch[1][fa[x]]; }   bool isrt(int x) { return x != ch[0][fa[x]] && x != ch[1][fa[x]]; }   void up(int x) {     sz[x] = sz[ch[0][x]] + sz[ch[1][x]] + si[x];     sz2[x] = 1ll * sz[ch[0][x]] * sz[ch[0][x]] +              1ll * sz[ch[1][x]] * sz[ch[1][x]] + si2[x];   }   void rotate(int x) {     int y = fa[x], z = fa[y], c = son(x);     ch[c][y] = ch[c ^ 1][x];     if (ch[c][y]) fa[ch[c][y]] = y;     fa[x] = z;     if (!isrt(y)) ch[son(y)][z] = x;     ch[c ^ 1][x] = y;     fa[y] = x;     up(y);   }   void splay(int x) {     for (int y = fa[x]; !isrt(x); rotate(x), y = fa[x])       if (!isrt(y)) rotate(son(x) ^ son(y) ? x : y);     up(x);   }   void access(int x) {     for (int y = 0; x; y = x, x = fa[x]) {       splay(x);       si[x] += sz[ch[1][x]];       si2[x] += 1ll * sz[ch[1][x]] * sz[ch[1][x]];       ch[1][x] = y;       si[x] -= sz[y];       si2[x] -= 1ll * sz[y] * sz[y];       up(x);     }   }   void link(int x, int y) {     access(y);     splay(y);     splay(x);     fa[x] = y;     si[y] += sz[x];     si2[y] += 1ll * sz[x] * sz[x];     up(y);   }   void cut(int x, int y) {     access(x);     access(y);     splay(y);     splay(x);     fa[x] = 0;     si[y] -= sz[x];     si2[y] -= 1ll * sz[x] * sz[x];     up(y);   }   int findrt(int x) {     access(x);     splay(x);     while (ch[0][x]) x = ch[0][x];     splay(x);     return x;   }   long long query(int x) {     splay(x);     return sz2[x];   }   void init() {     for (int i = 1; i <= n + 1; ++i) sz[i] = si[i] = 1;     for (int i = 1; i <= n; ++i) link(i, ::fa[i]);   }   }  // namespace lct   void dfs(int u) {     for (int v : E[u])       if (v != fa[u]) fa[v] = u, dfs(v);   }   int main() {     n = gi();     m = gi();     for (int i = 1; i <= n; ++i) col[i] = gi();     for (int i = 1; i < n; ++i) {       int x = gi(), y = gi();       E[x].push_back(y);       E[y].push_back(x);     }     fa[1] = n + 1;     dfs(1);     for (int i = 1; i <= n; ++i) vec[col[i]].push_back(make_pair(0, i << 1 | 1));     for (int i = 1; i <= m; ++i) {       int x = gi(), y = gi();       vec[col[x]].push_back(make_pair(i, x << 1));       col[x] = y;       vec[col[x]].push_back(make_pair(i, x << 1 | 1));     }     for (int i = 1; i <= n; ++i) vec[col[i]].push_back(make_pair(m + 1, i << 1));     lct::init();     for (int i = 1; i <= n; ++i)       for (auto x : vec[i]) {         int u = x.second >> 1, f = lct::findrt(fa[u]);         if (x.second & 1) {           ans[x.first] += lct::query(f);           lct::cut(u, fa[u]);           ans[x.first] -= lct::query(u) + lct::query(f);         } else {           ans[x.first] += lct::query(u) + lct::query(f);           lct::link(u, fa[u]);           ans[x.first] -= lct::query(f);         }       }     for (int i = 1; i <= m; ++i) ans[i] += ans[i - 1];     for (int i = 0; i <= m; ++i) printf( %lld n , ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     vector<pair<int, int> > v;     while (n--) {       int x, y;       cin >> x >> y;       v.push_back(make_pair(-x, y));     }     sort(v.begin(), v.end());     int ind = k - 1;     int res = 1;     while (ind - 1 >= 0 && v[ind] == v[ind - 1]) {       ind--;       res++;     }     ind = k - 1;     while (ind + 1 < v.size() && v[ind] == v[ind + 1]) {       ind++;       res++;     }     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int T, b, w, tmp;     scanf( %d , &T);     while (T--) {       scanf( %d %d , &b, &w);       if (b >= w)         tmp = 2;       else         tmp = 3, swap(b, w);       if (b > 3 * w + 1)         printf( NO n );       else {         printf( YES n );         for (int i = 1; i <= w; ++i) {           printf( %d t%d n , tmp, 2 * i);           printf( %d t%d n , tmp, 2 * i - 1);         }         b -= w;         if (b) printf( %d t%d n , tmp, 2 * w + 1), b--;         int i = 1;         while (b) {           printf( %d t%d n , tmp - 1, 2 * i);           b--;           if (b) printf( %d t%d n , tmp + 1, 2 * i), b--;           i++;         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   template <typename T1, typename T2>   inline bool chmin(T1 &a, T2 b) {     if (a > b) {       a = b;       return 1;     }     return 0;   }   template <typename T1, typename T2>   inline bool chmax(T1 &a, T2 b) {     if (a < b) {       a = b;       return 1;     }     return 0;   }   template <typename T>   T gcd(T a, T b) {     if (b == 0) return a;     return gcd(b, a % b);   }   template <typename T>   T lcm(T a, T b) {     return a / gcd(a, b) * b;   }   template <typename T>   T pow(T a, int b) {     return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1;   }   const int mod = 998244353;   long long modpow(long long a, int b) {     return b ? modpow(a * a % mod, b / 2) * (b % 2 ? a : 1) % mod : 1;   }   void solve();   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int T;     T = 1;     while (T--) {       solve();     }   }   struct UnionFind {     vector<double> data;     int sz;     UnionFind(int _sz) : data(_sz, -1) { sz = _sz; }     bool connect(int x, int y) {       if ((x = root(x)) == (y = root(y))) return false;       if (data[x] > data[y]) swap(x, y);       data[x] += data[y];       data[y] = x;       sz--;       return true;     }     bool issame(int x, int y) { return root(x) == root(y); }     int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); }     int size(int x) { return -data[root(x)]; }     int size() { return sz; }   };   void solve() {     int n;     cin >> n;     set<int> s;     for (int i = 0; i < (n); ++i) {       int b;       cin >> b;       s.insert(b);     }     vector<int> a;     for (auto e : s) a.emplace_back(e);     sort(a.begin(), a.end());     map<long long, int> mp;     for (int i = 0; i < (n); ++i) mp[a[i]] = i + 1;     for (int i = 0; i < (33); ++i) {       UnionFind uni(n);       for (int j = 0; j < (n - 1); ++j) {         long long num = a[j] + pow(2LL, i);         if (mp.count(num)) {           uni.connect(j, mp[num] - 1);         }       }       vector<vector<int> > v(n);       for (int j = 0; j < (n); ++j) {         v[uni.root(j)].emplace_back(a[j]);       }       for (int j = 0; j < (n); ++j) {         if ((int)v[j].size() >= 3) {           cout << 3 << endl;           for (int k = 0; k < (3); ++k) cout << v[j][k] <<    ;           cout << endl;           return;         }       }     }     for (int i = 0; i < (33); ++i) {       UnionFind uni(n);       for (int j = 0; j < (n - 1); ++j) {         long long num = a[j] + pow(2LL, i);         if (mp.count(num)) {           uni.connect(j, mp[num] - 1);         }       }       vector<vector<int> > v(n);       for (int j = 0; j < (n); ++j) {         v[uni.root(j)].emplace_back(a[j]);       }       for (int j = 0; j < (n); ++j) {         if ((int)v[j].size() >= 2) {           cout << 2 << endl;           for (int k = 0; k < (2); ++k) cout << v[j][k] <<    ;           cout << endl;           return;         }       }     }     cout << 1 << endl;     cout << a[0] << endl;   }


#include <bits/stdc++.h>   using namespace std;   int T;   int main() {     cin.tie(0);     ios_base::sync_with_stdio(0);     cin >> T;     for (int i = 0; i < T; i++) {       int n, oneCnt = 0, zeroCnt = 0;       cin >> n;       string str;       for (int j = 0; j < n; j++) {         char ch;         cin >> ch;         str.push_back(ch);         if (ch ==  1 ) oneCnt++;       }       if (oneCnt == 1) {         cout << 0 <<   n ;         continue;       };       int len = str.length();       int start = 0, end = 0;       for (int j = 0; j < len; j++) {         if (str[j] ==  1 ) {           start = j;           break;         }       }       for (int j = len - 1; j > -1; j--) {         if (str[j] ==  1 ) {           end = j;           break;         }       }       for (int j = start; j <= end; j++) {         if (str[j] ==  0 ) zeroCnt++;       }       cout << zeroCnt <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long dx[] = {1, -1, 0, 0};   long long dy[] = {0, 0, 1, -1};   const int sz = 2e6 + 5, mod = 998244353;   long long t, n, m, k;   const int MAXN = 2e5 + 7;   const long long lim = 1e18;   const long long inf = 1e15;   vector<long long> Prime;   vector<bool> sie(sz, 1);   void sieve() {     sie[0] = 0;     sie[1] = 0;     for (long long i = 2; i < sz; i++) {       if (sie[i]) {         for (long long j = i * i; j < sz; j += i) sie[j] = 0;       }     }     for (long long i = 0; i < sz; i++) {       if (sie[i]) Prime.push_back(i);     }     return;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     sieve();     cin >> n;     vector<long long> v(n);     for (auto &i : v) cin >> i;     map<long long, long long> track;     vector<long long> ans;     long long in = -1;     for (int i = 0; i < n; i++) {       long long a = v[i];       bool flag = 0;       vector<long long> pp;       for (long long j = 2; j * j <= a; j++) {         if (a % j == 0) {           while (a % j == 0) {             a /= j;           }           if (track.find(j) != track.end()) {             flag = 1;             break;           } else             track[j];           pp.push_back(j);         }       }       if (a != 1 && flag == 0) {         if (track.find(a) != track.end()) {           flag = 1;         } else           track[a];       }       if (flag) {         for (auto j : pp) track.erase(j);         for (long long j = v[i] + 1; j < sz; j++) {           long long a = j;           bool f = 1;           vector<long long> arr;           for (long long k = 2; k * k <= a; k++) {             if (a % k == 0) {               while (a % k == 0) {                 a /= k;               }               if (track.find(k) != track.end()) {                 f = 0;                 break;               } else                 track[k];               arr.push_back(k);             }           }           if (a != 1 && f) {             if (track.find(a) != track.end()) {               f = 0;             } else               track[a];           }           if (f) {             ans.push_back(j);             break;           } else {             for (auto j : arr) track.erase(j);           }         }         in = i + 1;         break;       }       ans.push_back(v[i]);     }     if (in == -1) {       for (auto i : ans) cout << i <<    ;       return 0;     }     int cnt = ans.size();     int i = 0;     while (cnt < n) {       if (track.find(Prime[i]) == track.end()) {         cnt++;         ans.push_back(Prime[i]);       }       i++;     }     for (auto i : ans) cout << i <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int i, j, p, d, n, m, total, k, ok, a, b, c, op, maxi, rasp, m1, m2,       p1, p2, rez, modu = 1000000007, mini, mij, ls, ld;   pair<long long int, long long int> v[300500];   priority_queue<pair<long long int, long long int> > nxt;   priority_queue<long long int> q;   string s;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> n;     cin >> a >> b;     n--;     for (i = 1; i <= n; i++) {       cin >> v[i].first >> v[i].second;     }     sort(v + 1, v + 1 + n);     for (i = 1; i <= n; i++) {       if (v[i].first > a)         q.push((v[i].second - v[i].first + 1) * -1), rez++;       else {         nxt.push(v[i]);       }     }     mini = rez;     while (a && q.size()) {       a += q.top();       q.pop();       if (a < 0) break;       rez--;       while (nxt.size() && nxt.top().first > a) {         q.push((nxt.top().second - nxt.top().first + 1) * -1), rez++;         nxt.pop();       }       mini = min(rez, mini);     }     cout << mini + 1;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long bipow(long long a) {     if (a == 0) return 1;     long long aea = bipow(a / 2) % 998244353;     if (a % 2 == 0)       return (aea * aea) % 998244353;     else       return ((aea * aea) % 998244353 * 2) % 998244353;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long n, m;     cin >> n >> m;     cout << bipow(n + m) % 998244353 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct numer {     int rost;     int num_of;     numer() : rost(0), num_of(0) {}     numer(int _rost, int _num_of) : rost(_rost), num_of(_num_of) {}   };   int maxim(int a, int b) { return a > b ? a : b; }   int comp(const void *a, const void *b) {     int *A = (int *)a, *B = (int *)b;     return *A < *B ? -1 : *A > *B ? 1 : 0;   }   void push(stack<int> &S, numer &chel) {     for (int i = 0; i < chel.num_of; i++) S.push(chel.rost);   }   int balance(int *Rost, int num, int *&ring, bool else_good = false,               bool good = false) {     qsort(Rost, num, sizeof(int), comp);     vector<numer> people;     numer temp(Rost[0], 1);     stack<int> Stack;     for (int i = 1; i < num; i++) {       if (Rost[i] == Rost[i - 1])         temp.num_of++;       else {         people.push_back(temp);         temp = numer(Rost[i], 1);       }     }     people.push_back(temp);     int kol = people.size(), min = 0, curr = 0, tmp = 0, tmp1, *p = 0;     if (else_good == false) {       for (int i = 1; i <= kol; i++) {         curr += people[i - 1].num_of;         if (i == kol) {           tmp1 = balance(Rost + min, curr - min, p, true, false);           if (tmp1 > tmp) {             ring = p;             tmp = tmp1;           }           continue;         }         if (people[i].rost - people[i - 1].rost >= 2) {           tmp1 = balance(Rost + min, curr - min, p, true, false);           if (tmp1 > tmp) {             ring = p;             tmp = tmp1;           }           min = curr;         }       }     }     if (tmp == 0) {       int new_curr = people[0].num_of, new_min = 0;       if (good == false) {         for (int i = 1; i < kol; i++) {           new_curr += people[i].num_of;           if (people[i].num_of == 1 || i == kol - 1) {             tmp1 = balance(Rost + new_min, new_curr - new_min, p, true, true);             if (tmp1 > tmp) {               ring = p;               tmp = tmp1;             }             new_min = new_curr - people[i].num_of;           }         }         if (kol == 1) {           tmp = tmp1 = new_curr;           ring = new int[tmp];           for (int j = 0; j < tmp; j++) ring[j] = people[0].rost;         }       } else {         for (int i = 0; i < kol; i++) {           Stack.push(people[i].rost);           people[i].num_of--;         }         for (int i = kol - 1; i >= 0; i--) push(Stack, people[i]);         tmp = Stack.size();         ring = new int[tmp];         for (int i = 0; i < tmp; i++) {           ring[i] = Stack.top();           Stack.pop();         }       }     }     return tmp;   }   int main() {     int n;     cin >> n;     int *A = new int[n], *B = 0;     for (int i = 0; i < n; i++) cin >> A[i];     int k = balance(A, n, B);     cout << k << endl;     for (int i = 0; i < k; i++) cout << B[i] <<    ;     delete[] A;     delete[] B;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6 + 10;   int tree[maxn * 4], add[maxn * 4];   void push(int v, int tl, int tr) {     if (add[v] != 0) {       tree[v] += add[v];       if (tl != tr) {         int vv = v + v;         add[vv] += add[v];         add[vv + 1] += add[v];         tree[v] = max(tree[vv] + add[vv], tree[vv + 1] + add[vv + 1]);       }       add[v] = 0;     }   }   void upd(int v, int tl, int tr, int l, int r, int x) {     push(v, tl, tr);     if (tl == l and tr == r) {       add[v] += x;       push(v, tl, tr);       return;     }     int tm = tl + tr >> 1, vv = v + v;     if (r <= tm)       upd(vv, tl, tm, l, r, x);     else if (l > tm)       upd(vv + 1, tm + 1, tr, l, r, x);     else {       upd(vv, tl, tm, l, tm, x);       upd(vv + 1, tm + 1, tr, tm + 1, r, x);     }     tree[v] = max(tree[vv] + add[vv], tree[vv + 1] + add[vv + 1]);   }   int get(int v, int tl, int tr) {     push(v, tl, tr);     if (tl == tr) return (tree[v] > 0 ? tl : -1);     int vv = v + v, tm = tl + tr >> 1;     if (tree[vv + 1] + add[vv + 1] > 0) return get(vv + 1, tm + 1, tr);     return get(vv, tl, tm);   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n, m;     cin >> n >> m;     int a[n], b[m];     for (int i = 0; i < n; i++) {       cin >> a[i];       upd(1, 1, maxn, 1, a[i], 1);     }     for (int i = 0; i < m; i++) {       cin >> b[i];       upd(1, 1, maxn, 1, b[i], -1);     }     int q;     cin >> q;     while (q--) {       int type, i, x;       cin >> type >> i >> x;       if (type == 1) {         upd(1, 1, maxn, 1, a[i - 1], -1);         a[i - 1] = x;         upd(1, 1, maxn, 1, a[i - 1], 1);       } else {         upd(1, 1, maxn, 1, b[i - 1], 1);         b[i - 1] = x;         upd(1, 1, maxn, 1, b[i - 1], -1);       }       cout << get(1, 1, maxn) <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   void chmax(T& a, const T& b) {     a = max(a, b);   }   template <class T>   void chmin(T& a, const T& b) {     a = min(a, b);   }   using ll = long long;   using P = pair<int, int>;   using VI = vector<int>;   using VVI = vector<VI>;   using VL = vector<ll>;   using VVL = vector<VL>;   int dp[6][410][410];   int d[410];   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int tt;     cin >> tt;     while (tt--) {       int n, m;       cin >> n >> m;       for (int k = 0; k < int(5); ++k)         for (int i = 0; i < int(m + 1); ++i)           for (int j = 0; j < int(m + 1); ++j) dp[k][i][j] = 100;       int ans = 100;       for (int _ = 0; _ < int(n); ++_) {         for (int j = 0; j < int(m); ++j) {           char c;           cin >> c;           d[j + 1] = c -  0 ;         }         for (int j = 0; j < int(m); ++j) d[j + 1] += d[j];         for (int k = int(5) - 1; k >= 0; --k)           for (int r = 0; r < int(m + 1); ++r)             for (int l = int(r - 4 + 1) - 1; l >= 0; --l) {               if (k == 0 || k == 4) {                 int x = r - 1 - (l + 1) - (d[r - 1] - d[l + 1]);                 if (k == 4) {                   chmin(ans, x + dp[k][l][r]);                   dp[k][l][r] += d[r - 1] - d[l + 1] + 1 - (d[l + 1] - d[l]) + 1 -                                  (d[r] - d[r - 1]);                 } else {                   dp[1][l][r] = x;                 }               } else {                 int x = d[r - 1] - d[l + 1] + 1 - (d[l + 1] - d[l]) + 1 -                         (d[r] - d[r - 1]);                 if (k < 3) {                   dp[k + 1][l][r] = dp[k][l][r] + x;                 } else {                   chmin(dp[k + 1][l][r], dp[k][l][r] + x);                 }               }             }       }       cout << ans <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   vector<long long> t1, t2;   long long a, b, n, k, q, day, val, p, t;   void update1(long long i, long long l, long long r, long long qi,                long long qx) {     if (l + 1 == r) {       t1[i] += qx;       t1[i] = min(t1[i], a);       return;     }     long long m = (r + l) >> 1;     if (qi < m) {       update1(2 * i + 1, l, m, qi, qx);     } else {       update1(2 * i + 2, m, r, qi, qx);     }     t1[i] = t1[2 * i + 1] + t1[2 * i + 2];   }   void update2(long long i, long long l, long long r, long long qi,                long long qx) {     if (l + 1 == r) {       t2[i] += qx;       t2[i] = min(t2[i], b);       return;     }     long long m = (r + l) >> 1;     if (qi < m) {       update2(2 * i + 1, l, m, qi, qx);     } else {       update2(2 * i + 2, m, r, qi, qx);     }     t2[i] = t2[2 * i + 1] + t2[2 * i + 2];   }   long long get1(long long i, long long l, long long r, long long ql,                  long long qr) {     if (r <= ql || qr <= l) {       return 0;     }     if (ql <= l && r <= qr) {       return t1[i];     }     long long m = (r + l) / 2;     return get1(2 * i + 1, l, m, ql, qr) + get1(2 * i + 2, m, r, ql, qr);   }   long long get2(long long i, long long l, long long r, long long ql,                  long long qr) {     if (r <= ql || qr <= l) {       return 0;     }     if (ql <= l && r <= qr) {       return t2[i];     }     long long m = (r + l) / 2;     return get2(2 * i + 1, l, m, ql, qr) + get2(2 * i + 2, m, r, ql, qr);   }   void Not_Stable() {     cin >> n >> k >> a >> b >> q;     t1.resize(4 * n);     t2.resize(4 * n);     long long x, y, z;     for (long long i = 0; i < q; i++) {       cin >> x >> y;       if (x == 1) {         cin >> z;         update1(0, 0, n, y - 1, z);         update2(0, 0, n, y - 1, z);       } else {         cout << get2(0, 0, n, 0, y - 1) + get1(0, 0, n, y - 1 + k, n) << endl;       }     }   }   int32_t main() {     ios_base::sync_with_stdio(false), cin.tie(nullptr);     ;     long long g = 1;     while (g--) Not_Stable();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void read_file(bool outToFile = true) {}   int n, K;   int cnt50, cnt100;   const int MAXN = 51 + 9;   int memo[MAXN][MAXN][2];   int memoo[MAXN][MAXN][2];   int vis[MAXN][MAXN][2];   int C[MAXN][MAXN];   inline void add(int &x, int v) {     x += v;     if (x >= (1000000007)) x -= (1000000007);   }   void build_C() {     for (int k = 1; k < MAXN; k++) C[0][k] = 0;     for (int n = 0; n < MAXN; n++) C[n][0] = 1;     for (int n = 1; n < MAXN; n++) {       for (int k = 1; k < MAXN; k++) {         C[n][k] = C[n - 1][k];         add(C[n][k], C[n - 1][k - 1]);       }     }   }   struct state {     int cnt50l, cnt100l, cur;     state(int a, int b, int c) { cnt50l = a, cnt100l = b, cur = c; }   };   void BFS() {     memset(vis, 0, sizeof vis);     memset(memo, -1, sizeof memo);     vis[0][0][1] = 1;     queue<state> Q;     Q.push(state(0, 0, 1));     while (!Q.empty()) {       state s = Q.front();       Q.pop();       int cnt50l = s.cnt50l, cnt100l = s.cnt100l, cur = s.cur;       int cur50, cur100;       if (cur == 0)         cur50 = cnt50l, cur100 = cnt100l;       else         cur50 = cnt50 - cnt50l, cur100 = cnt100 - cnt100l;       int nret, ncnt;       int new50, new100;       for (int i = 0; i <= cur50; i++) {         for (int j = 0; j <= cur100; j++) {           if (i + j == 0) continue;           if (i * 50 + j * 100 > K) break;           if (cur == 0) {             new50 = cnt50l - i;             new100 = cnt100l - j;           } else {             new50 = cnt50l + i;             new100 = cnt100l + j;           }           int &old = vis[new50][new100][!cur];           if (old == 1) continue;           old = 1;           Q.push(state(new50, new100, !cur));         }       }       if (cnt50l == 0 && cnt100l == 0 && cur == 1) {         memo[0][0][1] = 0;         memoo[0][0][1] = 1;         continue;       }       int &ret = memo[cnt50l][cnt100l][cur];       int &cnt = memoo[cnt50l][cnt100l][cur];       ret = (2000000000), cnt = 0;       for (int i = 0; i <= cur50; i++) {         for (int j = 0; j <= cur100; j++) {           if (i + j == 0) continue;           if (i * 50 + j * 100 > K) break;           if (cur == 0) {             new50 = cnt50l - i;             new100 = cnt100l - j;           } else {             new50 = cnt50l + i;             new100 = cnt100l + j;           }           ncnt = 1LL * C[cur50][i] * C[cur100][j] % (1000000007);           ncnt = 1LL * ncnt * memoo[new50][new100][!cur] % (1000000007);           int nret = memo[new50][new100][!cur];           if (nret == -1) continue;           nret++;           if (ret > nret)             ret = nret, cnt = ncnt;           else             add(cnt, ncnt);         }       }       if (cnt50l == cnt50 && cnt100l == cnt100 && cur == 0) break;     }     int ans = memo[cnt50][cnt100][0];     int ansc = memoo[cnt50][cnt100][0];     if (ans == -1) ans = -1, ansc = 0;     printf( %d n%d n n , ans, ansc);   }   int main() {     read_file();     build_C();     while (scanf( %d%d , &n, &K) != -1) {       cnt50 = 0, cnt100 = 0;       for (int i = 0; i < n; i++) {         int x;         scanf( %d , &x);         if (x == 50)           cnt50++;         else           cnt100++;       }       BFS();     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int a[n];     for (int i = 1; i <= n; i++) cin >> a[i];     int c = 0, t = 0;     for (int i = 1; i <= n; i++) {       if (a[i] < 0) {         c++;       } else {         t++;       }     }     if (t == n || n == 1) {       cout <<  1  << endl << n << endl;       return 0;     }     if (c % 2 == 0)       cout << c / 2 << endl;     else       cout << c / 2 + 1 << endl;     int f = 0, d = 0;     for (int i = 1; i < n; i++) {       if (a[i] < 0) {         d++;       }       if (d == 2 && a[i + 1] < 0) {         cout << i - f <<    ;         f = i;         d = 0;       }     }     cout << n - f << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string a, b;     cin >> a;     b = a;     long long int x = 0, y = 0, z = 0;     long long int i;     for (i = 0; i < a.size(); i++) {       if (a[i] ==  a ) {         x++;       }       if (a[i] ==  b ) {         y++;       }       if (a[i] ==  c ) {         z++;       }     }     sort(b.begin(), b.end());     if (b == a && (z == x || z == y) && x != 0 && y != 0 && z != 0) {       cout <<  YES  << endl;     } else {       cout <<  NO  << endl;     }     return 0;   }