#include <bits/stdc++.h>   using namespace std;   int q, c, i1, i2;   long long v, u, w;   bool flag;   map<long long, long long> cost;   vector<long long> a, b;   void Rule() {     for (int i = i1 - 1; i >= 0; --i) {       cost[a[i]] += w;     }     for (int i = i2 - 1; i >= 0; --i) {       cost[b[i]] += w;     }   }   long long Cuddle() {     long long ret = 0;     for (int i = i1 - 1; i >= 0; --i) {       ret += cost[a[i]];     }     for (int i = i2 - 1; i >= 0; --i) {       ret += cost[b[i]];     }     return ret;   }   int main() {     scanf( %d , &q);     while (q--) {       scanf( %d , &c);       a.clear(), b.clear();       cin >> v >> u;       while (v) {         a.push_back(v);         if (v % 2)           v = (v - 1) / 2;         else           v /= 2;       }       while (u) {         b.push_back(u);         if (u % 2)           u = (u - 1) / 2;         else           u /= 2;       }       flag = 0;       for (int i = 0; i < ((int)(a).size()); ++i) {         for (int j = 0; j < ((int)(b).size()); ++j) {           if (a[i] == b[j]) {             i1 = i, i2 = j, flag = 1;             break;           }         }         if (flag) break;       }       if (c == 1)         cin >> w, Rule();       else         printf( %I64d n , Cuddle());     }   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   int a[1000100];   long long calc(int idx) {     long long ans = 0;     int x = -1, y = -1;     for (int i = 0; i < idx; i += m) {       ans += (long long)abs(a[i] - a[idx]) * 2;       x = i;     }     for (int i = n - 1; i > idx; i -= m) {       ans += (long long)abs(a[i] - a[idx]) * 2;       y = i;     }     return ans;   }   long long solve(long long l, long long r) {     while (l < r) {       long long ml = (2 * l + r) / 3;       long long mr = (l + 2 * r + 2) / 3;       long long vl = calc(ml);       long long vr = calc(mr);       if (vl < vr)         r = mr - 1;       else if (vl > vr)         l = ml + 1;       else {         l = ml;         r = mr - 1;       }     }     return l;   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i < n; i++) {       scanf( %d , &a[i]);     }     int ansid = solve(0, n - 1);     cout << calc(ansid) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char _buf[100000], *_p1 = _buf, *_p2 = _buf;   inline int gi() {     int x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = (x << 3) + (x << 1) + (ch ^ 48);       ch = getchar();     }     return (f == 1) ? x : -x;   }   const int maxn = 2e5 + 5, inf = 1e9, mod = 1e9 + 7;   int n, k, a[maxn];   vector<pair<int, int>> e[maxn];   int siz[maxn], maxv[maxn], rt, dis[maxn];   long long val[maxn], ans;   vector<int> now;   struct segmentree {     static const int maxn = 8e5 + 5;     long long sum[maxn];     inline void pushup(int u) { sum[u] = sum[u << 1] + sum[u << 1 | 1]; }     inline void update(int u, int l, int r, int x, long long v) {       if (l == r) return sum[u] += v, void();       int mid = (l + r) >> 1;       if (x <= mid)         update(u << 1, l, mid, x, v);       else         update(u << 1 | 1, mid + 1, r, x, v);       pushup(u);     }     inline long long query(int u, int l, int r, int x, int y) {       if (x <= l && y >= r) return sum[u];       int mid = (l + r) >> 1;       long long ret = 0;       if (x <= mid) ret = query(u << 1, l, mid, x, y);       if (y > mid) ret += query(u << 1 | 1, mid + 1, r, x, y);       return ret;     }   } tree[2], T[2];   inline void init() {}   inline void input() {     n = gi(), k = gi();     for (int i = 1; i <= n; ++i) a[i] = gi();     for (int i = 1; i <= n - 1; ++i) {       int u = gi(), v = gi(), w = gi();       e[u].push_back({v, w});       e[v].push_back({u, w});     }   }   bool vis[maxn];   int sum;   inline void getrt(int u, int fa) {     now.push_back(u);     siz[u] = 1;     maxv[u] = 0;     for (auto x : e[u]) {       int v = x.first;       if (v == fa || vis[v]) continue;       getrt(v, u);       siz[u] += siz[v];       maxv[u] = max(maxv[u], siz[v]);     }     maxv[u] = max(maxv[u], sum - siz[u]);     if (maxv[u] < maxv[rt]) rt = u;   }   inline void getdis(int u, int fa, int nowc) {     now.push_back(u);     for (auto x : e[u]) {       int v = x.first, w = x.second;       if (v == fa || vis[v]) continue;       val[v] = val[u] + a[v], dis[v] = dis[u] + (nowc != w);       getdis(v, u, w);     }   }   inline void count(int u) {     vector<pair<int, int>> temp;     dis[u] = 0, val[u] = 0;     ans = (ans + a[u]) % mod;     for (auto x : e[u]) {       now.clear();       int v = x.first, w = x.second;       if (vis[v]) continue;       dis[v] = 0, val[v] = a[v];       getdis(v, u, w);       for (int x : now) temp.push_back({w, x});       for (int x : now)         if (dis[x] <= k) ans = (ans + val[x] + a[u]) % mod;       for (int x : now) {         if (dis[x] > k) continue;         long long sum = tree[w].query(1, 0, n, 0, k - dis[x]) +                         1ll * T[w].query(1, 0, n, 0, k - dis[x]) * val[x];         if (dis[x] < k)           sum += tree[w ^ 1].query(1, 0, n, 0, k - dis[x] - 1) +                  1ll * T[w ^ 1].query(1, 0, n, 0, k - dis[x] - 1) * val[x];         ans = (ans + sum) % mod;       }       for (int x : now)         if (dis[x] <= k)           tree[w].update(1, 0, n, dis[x], val[x] + a[u]),               T[w].update(1, 0, n, dis[x], 1);     }     for (auto x : temp) {       int w = x.first, v = x.second;       if (dis[v] > k) continue;       tree[w].update(1, 0, n, dis[v], -val[v] - a[u]);       T[w].update(1, 0, n, dis[v], -1);     }   }   inline void Divide(int u) {     vis[u] = 1;     count(u);     for (auto x : e[u]) {       int v = x.first;       if (vis[v]) continue;       maxv[rt = 0] = inf;       sum = siz[v];       getrt(v, u);       Divide(rt);     }   }   inline void solve() {     maxv[rt = 0] = inf;     sum = n;     getrt(1, 0);     Divide(rt);     printf( %lld n , ans);   }   int main() {     int T = 1;     while (T--) {       init();       input();       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solution1(int a, int b, map<pair<int, int>, bool>& mp1,                  map<pair<int, int>, int>& mp2) {     if (a == b) {       mp2[{a, b}] = a;       return;     }     int j = a;     while (j <= b) {       if (j == a) {         if (mp1[{j + 1, b}]) {           mp2[{a, b}] = j;           solution1(j + 1, b, mp1, mp2);           break;         }       } else if (j == b) {         if (mp1[{a, j - 1}]) {           mp2[{a, b}] = j;           solution1(a, j - 1, mp1, mp2);           break;         }       } else {         if (mp1[{a, j - 1}] && mp1[{j + 1, b}]) {           mp2[{a, b}] = j;           solution1(a, j - 1, mp1, mp2);           solution1(j + 1, b, mp1, mp2);           break;         }       }       j++;     }   }   void solve() {     int a;     cin >> a;     map<pair<int, int>, bool> mp1;     map<pair<int, int>, int> mp2;     int x, y;     for (int i = 0; i < a; i++) {       cin >> x >> y;       mp1[{x, y}] = 1;     }     solution1(1, a, mp1, mp2);     vector<vector<int>> v1;     int i = 0;     for (auto x : mp1) {       if (mp2[x.first]) {         cout << x.first.first <<     << x.first.second <<     << mp2[x.first]              << endl;       }     }   }   int main() {     ios_base ::sync_with_stdio(false);     cin.tie(NULL);     int a;     cin >> a;     while (a--) {       solve();       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, k;     cin >> n >> k;     vector<pair<long long int, long long int>> v;     for (long long int i = 0; i < n; i++) {       long long int x;       cin >> x;       v.push_back({x, i + 1});     }     sort(v.begin(), v.end());     vector<long long int> ans;     for (auto i : v) {       if (k >= i.first) {         ans.push_back(i.second);         k = k - i.first;       } else         break;     }     cout << ans.size() <<   n ;     for (auto i : ans) cout << i <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int arr[200005];   map<int, int> mp;   int main() {     int n, k;     cin >> n >> k;     vector<int> v;     for (int i = 0; i < n; i++) {       int a;       cin >> a;       v.push_back(a);     }     sort(v.begin(), v.end());     int ans = 1e9;     for (int i = 0; i < n; i++) {       int zz = v[i];       int cnt = 0;       mp[zz]++;       if (mp[zz] == k) ans = min(ans, arr[zz]);       while (zz > 0) {         zz /= 2;         mp[zz]++;         cnt++;         arr[zz] += cnt;         if (mp[zz] == k) {           ans = min(ans, arr[zz]);         }       }     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   vector<long long int> vec;   map<int, int> mp;   multiset<long long int> st;   long long int n, m;   string s, s1, s2;   int arr[] = {4, 8, 15, 16, 23, 42};   int main() {     long long int i, j, k, c = INT_MAX, ans = 0, t, z, x, y;     for (i = 0; i < 6; i++) mp[arr[i]] = 0;     cout <<  ?   << 1 <<     << 2 << endl;     fflush(stdout);     cin >> z;     for (i = 0; i < 6; i++) {       if (z % arr[i] == 0) {         y = z / arr[i];         for (j = i + 1; j < 6; j++) {           if (y == arr[j]) {             vec.push_back(z);             mp[arr[i]]++;             mp[arr[j]]++;             ans = 1;             break;           }         }         if (ans == 1) break;       }     }     ans = 0;     cout <<  ?   << 1 <<     << 3 << endl;     fflush(stdout);     cin >> z;     for (i = 0; i < 6; i++) {       if (z % arr[i] == 0) {         y = z / arr[i];         for (j = i + 1; j < 6; j++) {           if (y == arr[j]) {             vec.push_back(z);             mp[arr[i]]++;             mp[arr[j]]++;             ans = 1;             break;           }         }         if (ans == 1) break;       }     }     ans = 0;     cout <<  ?   << 1 <<     << 4 << endl;     fflush(stdout);     cin >> z;     for (i = 0; i < 6; i++) {       if (z % arr[i] == 0) {         y = z / arr[i];         for (j = i + 1; j < 6; j++) {           if (y == arr[j]) {             vec.push_back(z);             mp[arr[i]]++;             mp[arr[j]]++;             ans = 1;             break;           }         }         if (ans == 1) break;       }     }     ans = 0;     cout <<  ?   << 1 <<     << 5 << endl;     fflush(stdout);     cin >> z;     for (i = 0; i < 6; i++) {       if (z % arr[i] == 0) {         y = z / arr[i];         for (j = i + 1; j < 6; j++) {           if (y == arr[j]) {             vec.push_back(z);             mp[arr[i]]++;             mp[arr[j]]++;             ans = 1;             break;           }         }         if (ans == 1) break;       }     }     cout <<  !  ;     if (mp[4] == 4) {       cout << 4 <<    ;       cout << vec[0] / 4 <<    ;       cout << vec[1] / 4 <<    ;       cout << vec[2] / 4 <<    ;       cout << vec[3] / 4 <<    ;       for (i = 0; i < 6; i++) {         if (mp[arr[i]] == 0) {           cout << arr[i];           return 0;         }       }     } else if (mp[8] == 4) {       cout << 8 <<    ;       cout << vec[0] / 8 <<    ;       cout << vec[1] / 8 <<    ;       cout << vec[2] / 8 <<    ;       cout << vec[3] / 8 <<    ;       for (i = 0; i < 6; i++) {         if (mp[arr[i]] == 0) {           cout << arr[i];           return 0;         }       }     } else if (mp[15] == 4) {       cout << 15 <<    ;       cout << vec[0] / 15 <<    ;       cout << vec[1] / 15 <<    ;       cout << vec[2] / 15 <<    ;       cout << vec[3] / 15 <<    ;       for (i = 0; i < 6; i++) {         if (mp[arr[i]] == 0) {           cout << arr[i];           return 0;         }       }     } else if (mp[16] == 4) {       cout << 16 <<    ;       cout << vec[0] / 16 <<    ;       cout << vec[1] / 16 <<    ;       cout << vec[2] / 16 <<    ;       cout << vec[3] / 16 <<    ;       for (i = 0; i < 6; i++) {         if (mp[arr[i]] == 0) {           cout << arr[i];           return 0;         }       }     } else if (mp[23] == 4) {       cout << 23 <<    ;       cout << vec[0] / 23 <<    ;       cout << vec[1] / 23 <<    ;       cout << vec[2] / 23 <<    ;       cout << vec[3] / 23 <<    ;       for (i = 0; i < 6; i++) {         if (mp[arr[i]] == 0) {           cout << arr[i];           return 0;         }       }     } else if (mp[42] == 4) {       cout << 42 <<    ;       cout << vec[0] / 42 <<    ;       cout << vec[1] / 42 <<    ;       cout << vec[2] / 42 <<    ;       cout << vec[3] / 42 <<    ;       for (i = 0; i < 6; i++) {         if (mp[arr[i]] == 0) {           cout << arr[i];           return 0;         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   inline void readInt(int &x) {     int neg = 1;     char ch;     while (!isdigit(ch = getchar())) {       if (ch ==  - ) {         neg = -1;       }     }     x = ch -  0 ;     while (isdigit(ch = getchar())) {       x = x * 10 + ch -  0 ;     }     x *= neg;   }   int N;   vector<bool> visited;   vector<bool> isprime;   vector<pair<int, int> > groups;   vector<int> rejected;   void solve(int X);   int main() {     int i, j;     readInt(N);     isprime.resize(N + 1, true);     visited.resize(N + 1);     for (i = 2; i <= (N >> 1); ++i) {       if (isprime[i]) {         for (j = i << 1; j <= (N >> 1); j += i) {           isprime[j] = false;         }       }     }     for (i = N >> 1; i > 1; --i) {       if (isprime[i]) {         solve(i);       }     }     for (i = rejected.size() - 1; i > 0; i -= 2) {       groups.push_back(make_pair(rejected[i], rejected[i - 1]));     }     printf( %d n , (int)groups.size());     for (auto x : groups) {       printf( %d %d n , x.first, x.second);     }     return 0;   }   void solve(int X) {     int i, aux = 0;     for (i = X * 3; i <= N; i += X) {       if (!visited[i]) {         if (aux == 0) {           aux = i;         } else {           visited[aux] = visited[i] = true;           groups.push_back(make_pair(aux, i));           aux = 0;         }       }     }     visited[X] = visited[aux] = visited[X << 1] = true;     if (aux != 0) {       groups.push_back(make_pair(X, aux));       rejected.push_back(X << 1);     } else {       groups.push_back(make_pair(X, X << 1));     }   }


#include <bits/stdc++.h>   int kx[8] = {+2, +2, -2, -2, +1, +1, -1, -1};   int ky[8] = {+1, -1, +1, -1, +2, -2, +2, -2};   int d9x[9] = {+1, +1, +1, +0, +0, +0, -1, -1, -1};   int d9y[9] = {+1, +0, -1, +1, +0, -1, +1, +0, -1};   int dx4[4] = {+0, +0, +1, -1};   int dy4[4] = {+1, -1, +0, +0};   long long int gcd(unsigned long long int a, unsigned long long int b) {     return (a == 0) ? b : gcd(b % a, a);   }   long long int lcm(unsigned long long int a, unsigned long long int b) {     return a * (b / gcd(a, b));   }   const long long INF = 1e18;   using namespace std;   int main() {     int T;     cin >> T;     while (T--) {       int n;       cin >> n;       int a[n];       int earliest[n + 1];       memset(earliest, -1, sizeof(earliest));       for (int i = 0; i < n; ++i) {         cin >> a[i];       }       for (int i = 0; i < n; ++i) {         if (earliest[a[i]] == -1) {           earliest[a[i]] = i;         } else if (earliest[a[i]] < i - 1) {           cout <<  YES n ;           goto end_of_loop;         }       }       cout <<  NO n ;     end_of_loop:;     }   }


#include <bits/stdc++.h>   using namespace std;   vector<long long> adj[200001];   long long a[200001];   vector<long long> start;   stack<long long> last;   long long ans;   bool f;   void dfs(long long);   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long n;     cin >> n;     set<long long> roots;     for (long long i = 1; i <= n; i++) roots.insert(i);     for (long long i = 1; i <= n; i++) cin >> a[i];     long long x;     for (long long i = 1; i <= n; i++) {       cin >> x;       if (x != -1) {         adj[x].push_back(i);         roots.erase(i);       }     }     start.clear();     while (!last.empty()) last.pop();     ans = 0;     for (auto x : roots) {       dfs(x);     }     cout << ans <<   n ;     for (auto x : start) {       cout << x <<    ;     }     while (!last.empty()) {       cout << last.top() <<    ;       last.pop();     }   }   void dfs(long long v) {     for (auto x : adj[v]) {       dfs(x);       if (a[x] > 0) a[v] += a[x];     }     ans += a[v];     if (a[v] > 0) {       start.push_back(v);     } else {       last.push(v);     }   }


#include <bits/stdc++.h>   using namespace std;   int output = 0;   int N, consCats;   vector<int> adj[999999];   int vCats[999999];   bool visited[999999];   bool leafs[999999];   bool aux;   void deep(int s, bool visited[], vector<int> adj[], int consCats, int var,             int vCats[]);   int main() {     cin >> N >> consCats;     for (int i = 1; i <= N; i++) {       visited[i] = false;       leafs[i] = false;     }     int cat;     for (int i = 1; i <= N; i++) {       cin >> cat;       vCats[i] = cat;     }     for (int i = 1; i < N; i++) {       int x, y;       cin >> x >> y;       adj[x].push_back(y);       adj[y].push_back(x);     }     deep(1, visited, adj, consCats, 0, vCats);     cout << output;     return 0;   }   void deep(int s, bool visited[], vector<int> adj[], int consCats, int var,             int vCats[]) {     if (visited[s]) return;     visited[s] = true;     aux = true;     for (int i = 0; i < adj[s].size(); i++) {       if (visited[adj[s][i]] == false) {         aux = false;         break;       }     }     (aux) ? leafs[s] = true : leafs[s] = false;     vCats[s] ? var += vCats[s] : var = 0;     if (leafs[s] && var <= consCats) {       output++;       return;     }     for (auto u : adj[s]) {       if (var > consCats)         continue;       else         deep(u, visited, adj, consCats, var, vCats);     }   }


#include <bits/stdc++.h>   using namespace std;   using namespace std;   long long i, n, x, m, k, ans;   int main() {     cin >> n;     x = n;     while (x) {       x /= 10;       m++;     }     ans = n * m + m - 1;     k = 1;     for (i = 0; i < m - 1; i++) {       k *= 10;       ans -= k;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int ost(int k, int res) {     int ans = 0;     while (k < (double)res / 2) {       ans++;       k *= 2;     }     return ans;   }   int main() {     int n, k;     cin >> n >> k;     vector<int> a(n);     for (int i = 0; i < n; i++) cin >> a[i];     sort(a.begin(), a.end());     int ans = 0;     for (int i = 0; i < n; i++) {       if (k < ((double)a[i]) / 2) ans += ost(k, a[i]);       k = max(k, a[i]);     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string scan();   const int mod = 1000000007;   const int MAXN = 10010;   int sta[MAXN], stb[MAXN];   long long s, x;   long long memo[MAXN][2];   long long bt(int i, int rem) {     if (i > 52 && rem == 0) return 1;     if (i == 60) return 0;     long long &ret = memo[i][rem];     if (ret != -1) return ret;     ret = 0;     if (sta[i] == 1 && ((rem + 1) % 2) == stb[i])       return ret = 2 * bt(i + 1, (rem + 1) / 2);     if (sta[i] == 1) return rem = 0;     if ((rem + 2) % 2 == stb[i]) ret += bt(i + 1, (rem + 2) / 2);     if (rem % 2 == stb[i]) ret += bt(i + 1, 0);     return ret;   }   int main() {     memset(memo, -1, sizeof memo);     long long a, b;     cin >> a >> b;     s = a, x = b;     for (int i = 0; a; a /= 2, i++) stb[i] = a % 2;     for (int i = 0; b; b /= 2, i++) sta[i] = b % 2;     cout << bt(0, 0) - (s == x ? 2 : 0) << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     ;     int n;     cin >> n;     int a[n];     for (int i = 0; i < n; i++) cin >> a[i];     int mi = *min_element(a, a + n);     int p = -1;     int f = 0;     int ans = INT_MAX;     for (int i = 0; i < n; i++) {       if (a[i] == mi and !f) {         f = 1;         p = i;       } else if (a[i] == mi and f) {         ans = min(ans, i - p);         p = i;       }     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   int a[20007];   int main() {     ios_base::sync_with_stdio(0);     int t = 1;     while (t--) {       int n;       cin >> n;       map<int, int> mp;       for (int i = 0; i < n; i++) {         int x, y;         cin >> x >> y;         mp[x] = y;         if (mp[x] == -1 * mp[x + y]) {           cout <<  YES ;           return 0;         }       }       cout <<  NO             <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<long long> v[100010];   long long dp[100010];   void dfs(long long i, long long first) {     dp[first]++;     for (auto x : v[i]) {       dfs(x, first + 1);     }   }   signed main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long n;     cin >> n;     for (long long i = 2; i <= n; i++) {       long long x;       cin >> x;       v[x].push_back(i);     }     long long ans = 0;     dfs(1, 1);     for (long long i = 1; i <= n; i++) {       ans += (dp[i] % 2);     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct node {     int num;     string ss;   };   unordered_map<string, node> mm;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n;     while (cin >> n) {       mm.clear();       for (int i = 0; i < n; i++) {         string s;         cin >> s;         for (int j = 0; j < s.length(); j++) {           for (int k = 1; k <= (s.length() - j); k++) {             string sb = s.substr(j, k);             if (mm.find(sb) != mm.end() && mm[sb].ss != s) {               mm[sb].num++;               mm[sb].ss = s;             } else if (mm.find(sb) == mm.end()) {               node temp;               temp.num = 1;               temp.ss = s;               mm[sb] = temp;             }           }         }       }       int q;       cin >> q;       for (int i = 0; i < q; i++) {         string s;         cin >> s;         if (mm.find(s) != mm.end()) {           cout << mm[s].num <<     << mm[s].ss << endl;         } else {           cout << 0 <<   -  << endl;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 100005;   long long p = 1e9 + 7;   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long n;     cin >> n;     long long sum = 0;     for (long long i = 1; i <= n; i++) {       long long a;       cin >> a;       sum += a;     }     for (long long i = 1; i <= n; i++) {       long long a;       cin >> a;       sum -= a;     }     if (sum < 0)       cout <<  No ;     else       cout <<  Yes ;     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:102400000,102400000 )   using namespace std;   const int maxn = 2e5 + 10;   const int inf = 0x7fffffff;   const long long INF = 9E18;   const int mod = 1e9 + 7;   const long long mod2 = 1e9 + 9;   const int eps = 1e-7;   const double pi = acos(-1.0);   template <typename T>   inline void read(T &x) {     T f = 1;     char ch = getchar();     for (; ch <  0  || ch >  9 ; ch = getchar())       if (ch ==  - ) f = -1;     for (x = 0; ch >=  0  && ch <=  9 ; ch = getchar()) x = x * 10 + ch -  0 ;     x *= f;   }   struct matrix {     long long a[2][2];     matrix() { memset(a, 0, sizeof a); }     matrix(long long x, long long y, long long p, long long q) {       a[0][0] = x;       a[0][1] = y;       a[1][0] = p;       a[1][1] = q;     }     matrix operator*(const matrix b) {       matrix c;       for (int i = 0; i <= 1; i++)         for (int j = 0; j <= 1; j++)           for (int k = 0; k <= 1; k++)             c.a[i][j] = (c.a[i][j] + ((a[i][k] * b.a[k][j]) % mod)) % mod;       return c;     }     matrix operator+(const matrix b) {       matrix c;       for (int i = 0; i <= 1; i++)         for (int j = 0; j <= 1; j++) c.a[i][j] = (a[i][j] + b.a[i][j]) % mod;       return c;     }     bool operator==(const matrix b) {       for (int i = 0; i <= 1; i++) {         for (int j = 0; j <= 1; j++) {           if (a[i][j] != b.a[i][j]) return 0;         }       }       return 1;     }     matrix operator^(long long x) {       matrix c(1, 0, 0, 1), b = *this;       while (x) {         if (x & 1) c = c * b;         b = b * b;         x >>= 1;       }       return c;     }   } change(1, 1, 1, 0), ori(1, 0, 0, 0), tree[maxn << 2], lazy[maxn << 2],       I(1, 0, 0, 1);   long long a[maxn];   int n, m;   void push_up(int rt) { tree[rt] = tree[rt << 1] + tree[rt << 1 | 1]; }   void push_down(int rt) {     if (lazy[rt] == I) return;     lazy[rt << 1] = lazy[rt << 1] * lazy[rt];     lazy[rt << 1 | 1] = lazy[rt << 1 | 1] * lazy[rt];     tree[rt << 1] = tree[rt << 1] * lazy[rt];     tree[rt << 1 | 1] = tree[rt << 1 | 1] * lazy[rt];     lazy[rt] = I;   }   void build(int l, int r, int rt) {     lazy[rt] = I;     if (l == r) {       tree[rt] = ori * (change ^ (a[l] - 1));       return;     }     int mid = (l + r) >> 1;     build(l, mid, rt << 1);     build(mid + 1, r, rt << 1 | 1);     push_up(rt);   }   void update(int l, int r, int rt, int x, int y, matrix val) {     if (x <= l && r <= y) {       tree[rt] = (tree[rt] * val);       lazy[rt] = lazy[rt] * val;       return;     }     push_down(rt);     int mid = (l + r) >> 1;     if (x <= mid) update(l, mid, rt << 1, x, y, val);     if (y > mid) update(mid + 1, r, rt << 1 | 1, x, y, val);     push_up(rt);   }   long long query(int l, int r, int rt, int x, int y) {     push_down(rt);     if (x <= l && r <= y) return ((tree[rt].a[0][0] + mod) % mod);     int mid = (l + r) >> 1;     long long ans = 0;     if (x <= mid) ans += query(l, mid, rt << 1, x, y);     if (y > mid) ans += query(mid + 1, r, rt << 1 | 1, x, y);     return ((ans + mod) % mod);   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) read(a[i]);     build(1, n, 1);     while (m--) {       int op, l, r;       scanf( %d%d%d , &op, &l, &r);       if (op == 1) {         long long x;         read(x);         update(1, n, 1, l, r, change ^ x);       } else {         cout << query(1, n, 1, l, r) << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const long double pi = acos(-1);   const int MOD = 1e9 + 7;   int ocor[26];   int prefix[100010][26];   int blaublau[100010];   string s, t;   bool confere(int idx) {     int cu = blaublau[idx];     int aux[26];     for (int i = 0; i < 26; i++) aux[i] = prefix[idx][i];     idx -= t.size();     if (idx >= 0) {       cu -= blaublau[idx];       for (int i = 0; i < 26; i++) aux[i] -= prefix[idx][i];     }     for (int i = 0; i < 26; i++) {       if (aux[i] < ocor[i]) {         if (cu >= ocor[i] - aux[i]) {           cu -= (ocor[i] - aux[i]);         } else           return false;       }     }     return true;   }   int main() {     ios::sync_with_stdio(false);     ;     cin >> s >> t;     memset(prefix, 0, sizeof(prefix));     memset(blaublau, 0, sizeof(blaublau));     memset(ocor, 0, sizeof(ocor));     for (int i = 0; i < s.size(); i++) {       int aux = 0;       if (s[i] ==  ? )         blaublau[i]++;       else         prefix[i][s[i] -  a ] = 1;       if (i == 0) continue;       blaublau[i] += blaublau[i - 1];       for (int j = 0; j < 26; j++) {         prefix[i][j] += prefix[i - 1][j];       }     }     for (int i = 0; i < t.size(); i++) ocor[t[i] -  a ]++;     int r = 0;     for (int i = t.size() - 1; i < s.size(); i++) {       if (confere(i)) r++;     }     cout << r <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, k;   vector<int> digits;   vector<vector<bool>> dp;   vector<int> bin_digits;   bool can;   void In() {     cin >> n >> k;     digits.resize(n);     string next;     for (int i = 0; i < n; i++) {       cin >> next;       digits[i] = stoi(next, 0, 2);     }   }   int GetDistance(int from, int result) {     int count = 0;     for (int bit = 0; bit <= 6; bit++) {       int num = 1 << bit;       int first = from & num;       int second = result & num;       if (first != second) {         if (first == 0)           count++;         else           return -1;       }     }     return count;   }   bool Solve() {     bin_digits.push_back(stoi( 1110111 , 0, 2));     bin_digits.push_back(stoi( 0010010 , 0, 2));     bin_digits.push_back(stoi( 1011101 , 0, 2));     bin_digits.push_back(stoi( 1011011 , 0, 2));     bin_digits.push_back(stoi( 0111010 , 0, 2));     bin_digits.push_back(stoi( 1101011 , 0, 2));     bin_digits.push_back(stoi( 1101111 , 0, 2));     bin_digits.push_back(stoi( 1010010 , 0, 2));     bin_digits.push_back(stoi( 1111111 , 0, 2));     bin_digits.push_back(stoi( 1111011 , 0, 2));     dp.resize(n + 1, vector<bool>(k + 1, false));     dp[n][0] = true;     for (int n_index = n - 1; n_index >= 0; n_index--)       for (int i = 0; i <= k; i++)         for (int j = 0; j <= 9; j++) {           int next_distance = GetDistance(digits[n_index], bin_digits[j]);           if (next_distance == -1) continue;           if (i - next_distance < 0) continue;           if (dp[n_index + 1][i - next_distance]) dp[n_index][i] = true;         }     if (!dp[0][k]) return false;     return true;   }   void Out() {     if (!can) {       cout << -1 << endl;       return;     }     for (int n_index = 0; n_index < n; n_index++) {       int distance;       int next_digit;       for (int j = 0; j <= 9; j++) {         int next_distance = GetDistance(digits[n_index], bin_digits[j]);         if (next_distance == -1) continue;         if (k - next_distance < 0) continue;         if (dp[n_index + 1][k - next_distance]) {           next_digit = j;           distance = next_distance;         }       }       k -= distance;       cout << next_digit;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     In();     can = Solve();     Out();   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 1e5 + 5;   void solve() {     int n;     cin >> n;     vector<int> v(n);     map<int, int> mpp;     for (int i = 0; i < n; i++) {       cin >> v[i];       mpp[v[i]]++;     }     int ans1 = 0, ans2 = 0;     bool flag = false;     for (int i = 0; i <= 100; i++) {       if (mpp[i] >= 2) {         if (!flag) {           ans1++;         }         ans2++;       } else if (mpp[i] == 1) {         flag = true;         ans2++;       } else {         break;       }     }     cout << ans1 + ans2 <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long t = 1;     cin >> t;     while (t--) solve();     cerr <<  Time :   << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC          <<  ms n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     scanf( %d , &n);     int a[1010];     for (int i = 0; i < n; i++) {       scanf( %d , &a[i]);     }     sort(a, a + n);     if (a[0] == 1) {       printf( -1 n );     } else {       printf( 1 n );     }   }


#include <bits/stdc++.h>   using namespace std;   const uint64_t seed =       std::chrono::system_clock::now().time_since_epoch().count();   mt19937_64 rnd(seed);   const int MOD = 998244353;   struct Dinic {     struct Edge {       int from, to;       long long cap, flow;       Edge(int u, int v, long long c) : from(u), to(v), cap(c), flow(0) {}     };     int n, m, s, t;     vector<vector<int>> g;     vector<Edge> edges;     vector<int> dis;     vector<int> cur;     int curFlow;     vector<bool> cut;     Dinic(int n, int s, int t)         : n(n), s(s), t(t), g(n), dis(n), cur(n), cut(n, false) {       curFlow = 0;       cut[0] = true;     }     void addEdge(int from, int to, long long cap) {       edges.push_back(Edge(from, to, cap));       edges.push_back(Edge(to, from, 0));       m = edges.size();       g[from].push_back(m - 2);       g[to].push_back(m - 1);     }     bool bfs() {       fill(dis.begin(), dis.end(), n);       dis[s] = 0;       queue<int> qq;       qq.push(s);       int cnt = 0;       while (!qq.empty()) {         cnt++;         int len = qq.size();         while (len--) {           int p = qq.front();           qq.pop();           for (int a : g[p]) {             Edge &e = edges[a];             if (e.flow >= e.cap) continue;             if (dis[e.to] == n) {               dis[e.to] = cnt;               qq.push(e.to);             }           }         }       }       return dis[t] != n;     }     long long dfs(int x, long long a) {       if (x == t || a == 0) return a;       long long flow = 0, f;       for (; cur[x] < g[x].size(); cur[x]++) {         Edge &e = edges[g[x][cur[x]]];         if (e.cap > e.flow && dis[x] + 1 == dis[e.to] &&             (f = dfs(e.to, min(a, e.cap - e.flow))) > 0) {           flow += f;           e.flow += f;           edges[g[x][cur[x]] ^ 1].flow -= f;           a -= f;           if (a == 0) break;         }       }       return flow;     }     long long maxFlow() {       long long flow = 0;       while (bfs()) {         fill(cur.begin(), cur.end(), 0);         flow += dfs(s, INT_MAX);       }       return flow;     }     long long dfs2(int x, long long limit, vector<bool> &vis) {       vis[x] = true;       if (x == t) return limit;       for (int ne : g[x]) {         Edge &e = edges[ne];         if (e.cap > e.flow && !vis[e.to] && !cut[e.to]) {           int r = dfs2(e.to, min(limit, e.cap - e.flow), vis);           if (r > 0) {             e.flow += r;             edges[ne ^ 1].flow -= r;             return r;           }         }       }       return 0;     }     long long work(int node) {       int e1, e2;       for (int i = 0; i < g[t].size(); i++) {         if (edges[g[t][i]].to == node) {           e1 = g[t][i];           break;         }       }       for (int i = 0; i < g[node].size(); i++) {         if (edges[g[node][i]].to == t) {           e2 = g[node][i];           break;         }       }       g[t].erase(find(g[t].begin(), g[t].end(), e1));       g[s].push_back(e1);       edges[e1].from = s;       edges[e1].cap = 1e9;       edges[e2].to = s;       curFlow -= edges[e2].flow;       do {         vector<bool> vis(n, false);         vis[s] = 0;         long long f = dfs2(node, edges[e2].cap - edges[e2].flow, vis);         edges[e2].flow += f;         edges[e2 ^ 1].flow -= f;         curFlow += f;         if (f == 0) {           swap(cut, vis);           break;         }       } while (true);       return curFlow;     }   };   void solve(int caseNum) {     int n;     cin >> n;     vector<vector<int>> a(n, vector<int>(n));     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         cin >> a[i][j];       }     }     int dd[][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};     Dinic dinic(n * n + 2, n * n, n * n + 1);     vector<pair<int, int>> nodes;     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         if (a[i][j] == -1) continue;         int n1 = i * n + j;         if (a[i][j] > 0) {           dinic.addEdge(n1, n * n + 1, 1e9);           nodes.push_back({a[i][j], n1});         }         for (int k = 0; k < 4; k++) {           int ii = i + dd[k][0];           int jj = j + dd[k][1];           if (ii < 0 || ii >= n || jj < 0 || jj >= n) continue;           int n2 = ii * n + jj;           dinic.addEdge(n1, n2, 1);         }       }     }     sort(nodes.begin(), nodes.end());     int p = 0;     long long ans = 0;     int last = 0;     long long lastF = 0;     while (p < nodes.size()) {       int q = p;       ans += (nodes[p].first - last) * lastF;       while (q < nodes.size() && nodes[q].first == nodes[p].first) {         int node = nodes[q].second;         dinic.work(node);         q++;       }       lastF = dinic.curFlow;       last = nodes[p].first;       p = q;     }     cout << ans <<   n ;   }   int main() {     std::ios::sync_with_stdio(false);     cin.tie(NULL);     cout.precision(10);     int T = 1;     for (int i = 1; i <= T; i++) {       solve(i);     }     cout.flush();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = (1 << 30) + 7;   const int N = 1e5 + 7;   int main() {     ios::sync_with_stdio(false);     int q, l, r, d, ans;     cin >> q;     while (q--) {       cin >> l >> r >> d;       ans = (r / d + 1) * d;       if (d < l)         ans = d;       else         ans = (r / d + 1) * d;       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline void read(T& x) {     bool fu = 0;     char c;     for (c = getchar(); c <= 32; c = getchar())       ;     if (c ==  - ) fu = 1, c = getchar();     for (x = 0; c > 32; c = getchar()) x = x * 10 + c -  0 ;     if (fu) x = -x;   };   template <class T>   inline void read(T& x, T& y) {     read(x);     read(y);   }   template <class T>   inline void read(T& x, T& y, T& z) {     read(x);     read(y);     read(z);   }   inline char getc() {     char c;     for (c = getchar(); c <= 32; c = getchar())       ;     return c;   }   int n, p, i, j, k, l, g, x;   int a[50010];   int pos[40], c[40];   long long len[1111];   char f[33][32][50010], f2[33][32][50010];   int v[11111];   long long pow(long long a, long long b, long long c) {     long long ans = 1;     for (a %= c; b; b >>= 1, a = a * a % c)       if (b & 1) ans = ans * a % c;     return ans;   }   void xx(char& x, char y) { x = min(10, x + y); }   int main() {     read(n, p);     for (i = 1; i <= n; i++) {       read(x);       if (x < 32) {         g++;         pos[g] = i;         c[g] = x;         for (len[g] = 1; len[g] <= c[g]; len[g] *= 10)           ;       }     }     f[0][0][0] = 1;     for (i = 0; i <= g - 1; i++)       for (j = 0; j <= 31; j++)         for (k = 0; k <= p - 1; k++)           if (f[i][j][k] > 0) {             xx(f[i + 1][j ^ c[i + 1]][(1LL * k * len[i + 1] + c[i + 1]) % p],                f[i][j][k]);             f2[i + 1][j ^ c[i + 1]][(1LL * k * len[i + 1] + c[i + 1]) % p] = 1;             xx(f[i + 1][j][k], f[i][j][k]);           }     if (f[g][0][0] < 2) {       printf( No n );       return 0;     }     printf( Yes n );     i = g;     j = 0;     k = 0;     while (i) {       if (f2[i][j][k]) v[++v[0]] = pos[i];       if (f2[i][j][k]) {         bool h = 0;         for (int j2 = (0); j2 <= (31); j2++) {           for (int k2 = (0); k2 <= (p - 1); k2++)             if (f[i - 1][j2][k2])               if ((j2 ^ c[i]) == j)                 if ((1LL * k2 * len[i] + c[i]) % p == k) {                   j = j2;                   k = k2;                   h = 1;                   break;                 }           if (h) break;         }       }       i--;     }     printf( %d n , v[0]);     for (i = v[0]; i >= 1; i--) printf( %d  , v[i]);     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void read() {}   int main() {     read();     string s;     while (cin >> s) {       int l = s.size();       string ans;       bool f = 0;       for (int i = 0; i < l; i++) {         if (i != 0) {           if (s[i] ==  a  && i + 1 < l - 1 && s[i + 1] ==  t  && !f) {             ans.push_back( @ );             i += 1;             f = 1;             continue;           } else if (s[i] ==  d  && i + 2 < l - 1 && s[i + 1] ==  o  &&                      s[i + 2] ==  t ) {             ans.push_back( . );             i += 2;             continue;           }         }         ans.push_back(s[i]);       }       cout << ans <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     int arr[n];     for (int i = 0; i < n; i++) cin >> arr[i];     sort(arr, arr + n);     int c[1005] = {0};     int u[1005] = {0}, t = 0;     for (int i = 0; i < n; i++) {       if (c[arr[i]] == 0) {         u[t++] = arr[i];       }       c[arr[i]]++;     }     int fans = 0;     while (1) {       int ans = -1;       for (int i = 0; i < t; i++) {         if (c[u[i]] > 0) {           ans++;           c[u[i]]--;         }       }       if (ans <= 0) break;       fans += ans;     }     cout << fans;   }


#include <bits/stdc++.h>   using namespace std;   long long int a, b, c, d, n, ans = 0;   int main() {     cin >> a;     cin >> b;     cin >> c;     cin >> d;     if ((a + b > c && a + c > b && b + c > a) ||         (a + b > d && a + d > b && b + d > a) ||         (a + d > c && a + c > d && d + c > a) ||         (d + b > c && d + c > b && b + c > d)) {       cout <<  TRIANGLE ;     } else if ((a + b == c) || (a + b == d) || (a + c == b) || (a + c == d) ||                (a + d == c) || (a + d == b) || (b + c == a) || (b + c == d) ||                (b + d == a) || (b + d == c) || (c + d == a) || (c + d == b)) {       cout <<  SEGMENT ;     } else {       cout <<  IMPOSSIBLE ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   const int _inf = 0xc0c0c0c0;   const long long INF = 0x3f3f3f3f3f3f3f3f;   const long long _INF = 0xc0c0c0c0c0c0c0c0;   const long long mod = (int)1e9 + 7;   const int N = 3e5 + 100;   vector<int> vc[N], e[N];   int col[N];   int vis[N];   int mx = 0;   void dfs(int o, int u) {     for (int v : vc[u]) {       vis[col[v]]++;     }     int b = 1;     for (int v : vc[u]) {       if (col[v]) continue;       while (vis[b]) ++b;       vis[b] = 1;       col[v] = b;     }     mx = max(mx, b);     for (int v : vc[u]) {       vis[col[v]] = 0;     }     for (int v : e[u]) {       if (v == o) continue;       dfs(u, v);     }   }   int main() {     int n, m;     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; ++i) {       int si, tv;       scanf( %d , &si);       for (int j = 1; j <= si; ++j) {         scanf( %d , &tv);         vc[i].push_back(tv);       }     }     int u, v;     for (int i = 1; i < n; ++i) {       scanf( %d%d , &u, &v);       e[u].push_back(v);       e[v].push_back(u);     }     dfs(0, 1);     printf( %d n , mx);     for (int i = 1; i <= m; ++i) {       if (!col[i]) col[i] = 1;       printf( %d%c , col[i],    n [i == m]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     for (int l = 0; l < n; l++) {       string b;       cin >> b;       string a;       a = b[0];       string c;       for (int i = 1; i <= b.length(); i += 2) {         c = b[i];         a += c;       }       cout << a <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int sz = 1500000;   const long long MAX = 10000000000000000;   template <typename T>   T abs(T a) {     return a < 0 ? -a : a;   }   int main() {     int n, m;     cin >> n >> m;     vector<vector<int> > graph(n);     for (long long i = 0; i < m; i++) {       int u, v;       cin >> u >> v;       graph[u - 1].push_back(v - 1);       graph[v - 1].push_back(u - 1);     }     vector<int> val(n, 0);     set<int> q;     vector<int> flag(n, 0);     vector<int> a(n);     for (long long i = 0; i < n; i++) {       cin >> a[i];       if (!a[i]) {         q.insert(i);       }     }     vector<int> ans;     while (!q.empty()) {       int top = *q.begin();       q.erase(q.begin());       if (flag[top]) {         return 1;       }       val[top]++;       flag[top] = true;       ans.push_back(top);       for (vector<int>::iterator i = graph[top].begin(); i != graph[top].end();            i++) {         val[*i]++;         if (val[*i] == a[*i]) {           q.insert(*i);         }       }     }     cout << ans.size() << endl;     for (vector<int>::iterator i = ans.begin(); i != ans.end(); i++) {       cout << (*i) + 1 <<    ;     }     return 0;   }


#include <bits/stdc++.h>   int main() {     int a, b;     scanf( %d%d , &a, &b);     if (a > b)       printf( %d %d n , b, (a - b) / 2);     else       printf( %d %d n , a, (b - a) / 2);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     char grid[n][n];     int hash_count = 0, cross = 0;     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         cin >> grid[i][j];         if (grid[i][j] ==  # ) hash_count++;       }     }     for (int i = 0; i < n - 2; i++) {       for (int j = 0; j < n - 2; j++) {         if (grid[i][j + 1] ==  #  && grid[i + 1][j] ==  #  &&             grid[i + 1][j + 1] ==  #  && grid[i + 1][j + 2] ==  #  &&             grid[i + 2][j + 1] ==  # ) {           cross += 5;           grid[i][j + 1] =  x ;           grid[i + 1][j] =  x ;           grid[i + 1][j + 1] =  x ;           grid[i + 1][j + 2] =  x ;           grid[i + 2][j + 1] =  x ;         }       }     }     if (hash_count == cross)       cout <<  YES ;     else       cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     int n, k;     cin >> n >> k;     vector<int> v(n);     long long sum = 0;     for (int i = 0; i < n; i++) {       cin >> v[i];       sum += v[i];     }     if (sum % k != 0)       cout <<  No n ;     else {       int num = sum / k;       for (int i = 1; i < n; i++) {         v[i] += v[i - 1];       }       int cnt = 0;       vector<int> res;       int q = 0;       for (int i = 0; i < n; i++) {         q++;         if (v[i] % num == 0) {           cnt++;           res.push_back(q);           q = 0;         }       }       if (cnt == k) {         cout <<  Yes n ;         for (int i = 0; i < k; i++) cout << res[i] <<    ;       } else         cout <<  No n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   long long a[200200];   int f(int x) { return ((x % n) + n) % n; }   int main() {     scanf( %d%d , &n, &m);     m--;     for (int i = (0); i < (n); i++) cin >> a[i];     int p = m;     for (int i = (1); i <= (n); i++)       if (a[p] >= a[f(m + i)]) p = f(m + i);     long long tmp = a[p] * n + f(m - p);     for (int i = (0); i < (n); i++)       if (i != p) a[i] -= a[p];     for (int i = (0); i < (n); i++) {       a[f(i + p)]--;       if (f(i + p) == m) break;     }     a[p] = tmp;     cout << a[0];     for (int i = (1); i < (n); i++) cout <<     << a[i];     puts(  );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<long long> v[10001];   long long n, ass1, ass2;   int main() {     v[1].push_back(1);     v[1].push_back(2);     v[2].push_back(1);     v[2].push_back(3);     v[3].push_back(2);     v[3].push_back(3);     cin >> n;     ass1 = ass2 = 3;     while (ass1 + ass2 <= n) {       v[1].push_back(ass2 + 1);       v[ass1 + 1].push_back(ass2 + 1);       for (int i = 2; i <= ass1; i++) {         v[i].push_back(ass2 + i);         v[ass1 + 1].push_back(ass2 + i);       }       ass2 += ass1;       ass1++;     }     cout << ass1 << endl;     for (int i = 1; i <= ass1; i++) {       for (int j = 0; j < v[i].size(); j++) {         if (j != 0) cout <<    ;         cout << v[i][j];       }       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int cnt = -1;   struct node {     bool op;     string val;     int op1, op2;     int type;     node() {       op = 0;       val =   ;       type = 0;     }   } m[5020];   map<string, int> ind;   inline int cti(char i) { return (int)(i -  0 ); }   vector<string> vct;   bool ansx[2020], ansm[2020];   int tb[5020];   int main() {     int n, mm;     string t, p;     cin >> n >> mm;     for (int i = 0; i < n; i++) {       cin >> t;       if (ind.find(t) == ind.end()) {         ind[t] = ++cnt;       }       cin >> p;       cin >> p;       if (p[0] ==  1  or p[0] ==  0 ) {         m[cnt].val = p;         continue;       }       m[cnt].op = 1;       if (p ==  ? )         m[cnt].op1 = -1;       else         m[cnt].op1 = ind[p];       cin >> p;       if (p[0] ==  O ) m[cnt].type = 1;       if (p[0] ==  A ) m[cnt].type = 2;       if (p[0] ==  X ) m[cnt].type = 3;       cin >> p;       if (p ==  ? )         m[cnt].op2 = -1;       else         m[cnt].op2 = ind[p];     }     int x0, x1, pic1, pic2;     for (int i = 0; i < mm; i++) {       x0 = x1 = 0;       for (int k = 0; k < n; k++) {         auto j = m[k];         if (j.op == 0) {           x0 += cti(j.val[i]);           tb[k] = cti(j.val[i]);         } else {           if (j.op1 == -1)             pic1 = 0;           else             pic1 = tb[j.op1];           if (j.op2 == -1)             pic2 = 0;           else             pic2 = tb[j.op2];           if (j.type == 1) {             x0 += pic1 | pic2;             tb[k] = pic1 | pic2;           } else if (j.type == 2) {             x0 += pic1 & pic2;             tb[k] = pic1 & pic2;           } else {             x0 += pic1 ^ pic2;             tb[k] = pic1 ^ pic2;           }         }       }       for (int k = 0; k < n; k++) {         auto j = m[k];         if (j.op == 0) {           x1 += cti(j.val[i]);           tb[k] = cti(j.val[i]);         } else {           if (j.op1 == -1)             pic1 = 1;           else             pic1 = tb[j.op1];           if (j.op2 == -1)             pic2 = 1;           else             pic2 = tb[j.op2];           if (j.type == 1) {             x1 += pic1 | pic2;             tb[k] = pic1 | pic2;           } else if (j.type == 2) {             x1 += pic1 & pic2;             tb[k] = pic1 & pic2;           } else {             x1 += pic1 ^ pic2;             tb[k] = pic1 ^ pic2;           }         }       }       if (x0 > x1) {         ansx[i] = 0;         ansm[i] = 1;       }       if (x0 == x1) {         ansx[i] = 0;         ansm[i] = 0;       }       if (x0 < x1) {         ansx[i] = 1;         ansm[i] = 0;       }     }     for (int i = 0; i < mm; i++) cout << ansm[i];     cout << endl;     for (int i = 0; i < mm; i++) cout << ansx[i];     cout << endl;   }


#include <bits/stdc++.h>   using namespace std;   typedef struct T {     int ind;     int st;     int ds;     bool operator<(const T &one) const {       if (st != one.st) return st < one.st;       return ds < one.ds;     }   } gr;   gr grps[10000];   int n;   vector<int> mv;   int valid(int nt) {     int en = 0;     for (int i = 0; i < n; i++) {       if (i == nt) continue;       if (grps[i].st < en) return 0;       en = max(en, grps[i].ds);     }     return 1;   }   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       cin >> grps[i].st;       cin >> grps[i].ds;       grps[i].ind = i + 1;     }     sort(grps, grps + n);     for (int i = 0; i < n; i++) {       if (valid(i) == 1) mv.push_back(grps[i].ind);     }     cout << mv.size() << endl;     sort(mv.begin(), mv.end());     for (int i = 0; i < mv.size(); i++) cout << mv[i] <<    ;     return 0;   }


#include<iostream>   #include<cstdlib>   #include<cstdio>   #include<cmath>   #include<iomanip>   #include<cstring>   #include<algorithm>   #include<ctime>   using namespace std;   const int MAXN=2010;   int read()   {    int kkk=0,x=1;    char c=getchar();    while((c< 0  || c> 9 ) && c!= - ) c=getchar();    if(c== - ) c=getchar(),x=-1;    while(c>= 0  && c<= 9 ) kkk=kkk*10+(c- 0 ),c=getchar();    return kkk*x;   }   int n,X[MAXN],Y[MAXN],tag[MAXN],father[MAXN],id[MAXN],cur,ans[MAXN*MAXN][2],ANS,dl[MAXN],h,t,pd[MAXN];   double Theta[MAXN];   int find(int k){return father[k]==k?k:father[k]=find(father[k]);}   void solve(int S)   {    h=t=0;    dl[++t]=S;    while(h!=t)    {     int u=dl[++h];     father[u]=S;     if(tag[u]==S) break;     dl[++t]=tag[u];    }    if(t==1) pd[S]=1;   }   bool cmp(int x,int y){return Theta[x]<Theta[y];}   int main()   {    n=read();    for(int i=1;i<=n;++i) X[i]=read(),Y[i]=read(),tag[i]=read();    for(int i=1;i<=n;++i) if(!father[i]) solve(i);    for(int i=1;i<=n;++i) if(!pd[i])    {     if(!cur) cur=i;     else if(X[i]<X[cur] || (X[i]==X[cur] && Y[i]<Y[cur])) cur=i;    }    for(int i=1;i<=n;++i) Theta[i]=atan2(Y[i]-Y[cur],X[i]-X[cur]);    for(int i=1;i<=n;++i) id[i]=i;    sort(id+1,id+n+1,cmp);    pd[cur]=1;    for(int i=1,las=0;i<=n;++i) if(!pd[id[i]])    {     if(las)     {      int alas=find(las),aid=find(id[i]);      if(alas!=aid)      {       father[alas]=aid;       ans[++ANS][0]=las;       ans[ANS][1]=id[i];       swap(tag[las],tag[id[i]]);      }     }     las=id[i];    }    while(tag[cur]!=cur)    {     ans[++ANS][0]=cur;     ans[ANS][1]=tag[cur];     swap(tag[cur],tag[tag[cur]]);    }    printf( %d n ,ANS);    for(int i=1;i<=ANS;++i) printf( %d %d n ,ans[i][0],ans[i][1]);    return 0;   }


#include <bits/stdc++.h>   using namespace std;   int read() {     char ch = getchar();     int x = 0, fl = 1;     for (; !isdigit(ch); ch = getchar())       if (ch ==  - ) fl = -1;     for (; isdigit(ch); ch = getchar()) x = (x << 3) + (x << 1) + (ch -  0 );     return x * fl;   }   const int NN = 500000 + 17;   void open() {     freopen( a.in ,  r , stdin);     freopen( a.out ,  w , stdout);   }   void OK() { printf( OK n ); }   int n, q;   int c[NN];   int ans[NN];   vector<pair<int, int> > e[NN];   pair<int, int> ep[NN];   struct Tree {     int fa[NN], dep[NN], d[NN], ll[NN], rr[NN], rev[NN];     int tim;     struct node {       int w[2];     } t[NN << 2];     int tag[NN << 2];     node merge(node a, node b) {       node c;       c.w[0] = max(a.w[0], b.w[0]);       c.w[1] = max(a.w[1], b.w[1]);       return c;     }     void set_tag(int rt) {       tag[rt] ^= 1;       swap(t[rt].w[0], t[rt].w[1]);     }     void psd(int rt) {       if (tag[rt]) {         set_tag(rt << 1);         set_tag(rt << 1 | 1);         tag[rt] = 0;       }     }     void build(int rt, int l, int r) {       if (l == r) {         t[rt].w[d[rev[l]]] = dep[rev[l]];         return;       }       int mid = (l + r) >> 1;       build(rt << 1, l, mid);       build(rt << 1 | 1, mid + 1, r);       t[rt] = merge(t[rt << 1], t[rt << 1 | 1]);     }     void flip(int rt, int l, int r, int ll, int rr) {       if (ll <= l && r <= rr) {         set_tag(rt);         return;       }       psd(rt);       int mid = (l + r) >> 1;       if (ll <= mid) flip(rt << 1, l, mid, ll, rr);       if (rr > mid) flip(rt << 1 | 1, mid + 1, r, ll, rr);       t[rt] = merge(t[rt << 1], t[rt << 1 | 1]);     }     void dfs(int x, int ff) {       fa[x] = ff;       dep[x] = dep[ff] + 1;       ll[x] = ++tim;       rev[tim] = x;       for (int i = 0, top = e[x].size(); i < top; i++) {         int y = e[x][i].first, z = e[x][i].second;         if (y != ff) {           d[y] = (d[x] + z) & 1;           dfs(y, x);         }       }       rr[x] = tim;     }     void work(int root) {       dfs(root, 0);       build(1, 1, n);       for (int i = 1; i <= q; i++) {         int x = ep[c[i]].first, y = ep[c[i]].second;         if (fa[x] == y) swap(x, y);         flip(1, 1, n, ll[y], rr[y]);         ans[i] = max(ans[i], t[1].w[0]);       }     }   } tx, ty;   int mx, pos, px, py;   void dfs(int x, int dep, int ff) {     if (dep > mx) mx = dep, pos = x;     for (int i = 0, top = e[x].size(); i < top; i++) {       int y = e[x][i].first;       if (y != ff) dfs(y, dep + 1, x);     }   }   void get_path() {     dfs(1, 0, 0);     px = pos;     mx = -1;     dfs(px, 0, 0);     py = pos;     tx.work(px);     ty.work(py);   }   int main() {     n = read();     for (int i = 1; i < n; i++) {       int x = read(), y = read(), z = read();       e[x].push_back(make_pair(y, z));       e[y].push_back(make_pair(x, z));       ep[i] = make_pair(x, y);     }     q = read();     for (int i = 1; i <= q; i++) c[i] = read();     get_path();     for (int i = 1; i <= q; i++) {       ans[i]--;       printf( %d n , ans[i]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int getDiff(int n, string s1, string s2) {     int cnt = 0;     for (int i = 0; i < n; i++) {       if (s1[i] != s2[i]) {         cnt++;       }     }     return cnt;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n;     cin >> n;     string s;     cin >> s;     string temp = s;     for (int i = 0; i < n - 1; i++) {       if (i < n - 2) {         if (s[i] == s[i + 1] && s[i + 1] == s[i + 2] && s[i + 2] == s[i]) {           if (s[i] ==  R ) {             s[i + 1] =  G ;           } else if (s[i] ==  G ) {             s[i + 1] =  R ;           } else {             s[i + 1] =  R ;           }           continue;         }       }       if (s[i] == s[i + 1]) {         if (i == 0) {           if (s[i] ==  R ) {             s[i] =  G ;           } else if (s[i] ==  G ) {             s[i] =  R ;           } else {             s[i] =  R ;           }         } else {           if (s[i - 1] ==  R ) {             if (s[i] ==  B ) {               s[i] =  G ;             } else {               s[i] =  B ;             }           } else if (s[i - 1] ==  B ) {             if (s[i] ==  R ) {               s[i] =  G ;             } else {               s[i] =  R ;             }           } else {             if (s[i] ==  B ) {               s[i] =  R ;             } else {               s[i] =  B ;             }           }         }       }     }     int ans = getDiff(n, s, temp);     cout << ans <<   n ;     cout << s <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 5e3 + 99;   complex<int> read() {     int x, y;     cin >> x >> y;     return complex<int>(x, y);   }   long double dist(complex<int> a, complex<int> b) {     return hypot(abs(a.real() - b.real()), abs(a.imag() - b.imag()));   }   complex<long double> conv(complex<int> a) {     return complex<long double>(a.real(), a.imag());   }   bool _90_deg(complex<int> a, complex<int> b, complex<int> c) {     return fabs(((conj(((conv(b)) - (conv(a)))) * (((conv(c)) - (conv(b)))))                      .real())) < 1e-9;   }   bool isSquare(vector<complex<int>> vec) {     sort(vec.begin(), vec.end(), [](complex<int> a, complex<int> b) {       if (a.real() == b.real()) return a.imag() < b.imag();       return a.real() < b.real();     });     long double len = dist(vec[0], vec[1]);     if (fabs(len) < 1e-9) return false;     vector<pair<int, int>> _ = {{0, 2}, {1, 3}, {2, 3}};     for (auto cur : _) {       auto __ = dist(vec[cur.first], vec[cur.second]);       if (fabs(len - dist(vec[cur.first], vec[cur.second])) > 1e-9) return false;     }     long double diag1 = dist(vec[1], vec[2]);     long double diag2 = dist(vec[0], vec[3]);     if (fabs(diag1 - diag2) > 1e-9) return false;     swap(vec[2], vec[3]);     for (int i = 0; i < 4; ++i) vec.push_back(vec[i]);     for (int i = 2; i < vec.size(); ++i) {       if (!_90_deg(vec[i - 2], vec[i - 1], vec[i])) {         return false;       }     }     return true;   }   vector<complex<int>> home;   int go(int i, vector<complex<int>> vec) {     if (i >= 4) {       return isSquare(vec) ? 0 : 1e9;     }     int ret = 1e9;     for (int j = 0; j < 4; ++j) {       ret = min(ret, go(i + 1, vec) + j);       vec[i] -= home[i];       complex<int> r(-vec[i].imag(), vec[i].real());       vec[i] = r + home[i];     }     return ret;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     home.resize(4);     int t;     cin >> t;     while (t--) {       vector<complex<int>> v(4);       for (int i = 0; i < 4; ++i) {         v[i] = read();         home[i] = read();       }       int ret = go(0, v);       cout << (ret > 1e8 ? -1 : ret) <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   #pragma comment(linker,  /STACK:64000000 )   const int N = 5e3 + 10;   int n;   int t[N];   int cnt[N];   int res[N];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> t[i];     }     for (int r = 1; r <= n; r++) {       memset(cnt, 0, sizeof(cnt));       int mxCnt = 0, val = -1;       for (int l = r; l >= 1; l--) {         cnt[t[l]]++;         if (cnt[t[l]] > mxCnt || (cnt[t[l]] == mxCnt && t[l] < val)) {           mxCnt = cnt[t[l]];           val = t[l];         }         res[val]++;       }     }     for (int i = 1; i <= n; i++) {       cout << res[i] <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long freq[100005];   int32_t main() {     long long n;     cin >> n;     string s;     cin >> s;     sort(s.begin(), s.end());     reverse(s.begin(), s.end());     cout << s[0];     for (long long i = 1; i < n; i++) {       if (s[i] ==  0 ) cout << s[i];     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e18;   const int NMAX = 1e6;   struct eq {     int x, c;     bool operator<(const eq &aux) const { return x < aux.x; }   };   eq a[200005], b[200005];   stack<pair<int, int> > st;   void prec(int &n, eq a[]) {     for (int i = 1; i <= n; ++i) scanf( %d%d , &a[i].x, &a[i].c);     sort(a + 1, a + n + 1);     st.push({a[1].x, a[1].c});     for (int i = 2; i <= n; ++i) {       while (!st.empty() && st.top().second >= a[i].c) st.pop();       st.push({a[i].x, a[i].c});     }     int sz = st.size();     n = sz;     while (!st.empty()) {       a[sz].x = st.top().first;       a[sz].c = st.top().second;       st.pop();       --sz;     }   }   struct monster {     int x, y, c;     bool operator<(const monster &aux) const { return x < aux.x; }   };   monster A[200005];   long long Arb[NMAX * 4 + 5], pref[NMAX * 4 + 5];   void update(int x, long long val, int st = 0, int dr = NMAX, int nod = 1) {     if (st == dr) {       Arb[nod] += val;       pref[nod] = Arb[nod];       return;     }     int mij = (st + dr) / 2;     if (x <= mij)       update(x, val, st, mij, nod * 2);     else       update(x, val, mij + 1, dr, nod * 2 + 1);     Arb[nod] = Arb[nod * 2] + Arb[nod * 2 + 1];     pref[nod] =         max(Arb[nod], max(pref[nod * 2], Arb[nod * 2] + pref[nod * 2 + 1]));   }   int n, m, p;   int main() {     scanf( %d%d%d , &n, &m, &p);     prec(n, a);     prec(m, b);     for (int i = 1; i <= m; ++i) update(b[i - 1].x, -b[i].c + b[i - 1].c);     update(b[m].x, -INF);     for (int i = 1; i <= p; ++i) scanf( %d%d%d , &A[i].x, &A[i].y, &A[i].c);     sort(A + 1, A + p + 1);     int j = 1;     long long Sol = -a[1].c - b[1].c;     for (int i = 1; i <= n; ++i) {       while (j <= p && A[j].x < a[i].x) {         update(A[j].y, A[j].c);         ++j;       }       Sol = max(Sol, pref[1] - a[i].c);     }     printf( %lld , Sol);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int t;     cin >> t;     while (t--) {       int n, x;       cin >> n >> x;       ;       int a[n];       int b[n];       for (int i = 0; i < n; i++) {         cin >> a[i];         cin >> b[i];       }       reverse(b, b + n);       bool ans = 1;       for (int i = 0; i < n; i++) {         if (a[i] + b[i] > x) {           ans = 0;           break;         }       }       if (ans)         cout <<  Yes  << endl;       else         cout <<  No  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     long long int n, a, s = 0, c = 0;     cin >> n;     for (long long int i = 0; i < n; i++) {       cin >> a;       s += a;     }     for (long long int i = 1; i <= 5; i++) {       s += i;       if (s % (n + 1) != 1) c++;       s -= i;     }     cout << c;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     ;     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000007;   const long long inf = mod * mod;   const long long d2 = (mod + 1) / 2;   const long double EPS = 1e-9;   const long double PI = acos(-1.0);   int ABS(int a) { return max(a, -a); }   long long ABS(long long a) { return max(a, -a); }   long double ABS(long double a) { return max(a, -a); }   int p[110000];   int main() {     int a;     scanf( %d , &a);     for (int i = 0; i < a; i++) scanf( %d , p + i);     std::sort(p, p + a);     long long sum = 0;     set<int> S;     for (int i = 0; i < a; i++) S.insert(p[i]);     for (int i = 0; i < a; i++) sum += p[i];     if (a == 1 || sum == 0) {       if (sum % 2 == 0)         printf( cslnb n );       else         printf( sjfnb n );       return 0;     }     bool dame = false;     int cnt = 0;     for (int i = 0; i < a - 1; i++) {       if (p[i] == p[i + 1]) {         cnt++;         if (p[i] == 0 || S.count(p[i] - 1)) dame = true;       }     }     if (cnt > 1) dame = true;     if (dame) {       printf( cslnb n );       return 0;     }     long long val = 0;     for (int i = 0; i < a; i++) {       val += p[i] - i;     }     if (val % 2 == 0)       printf( cslnb n );     else       printf( sjfnb n );   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(), cout.tie();     long long n, k;     cin >> n >> k;     long long a[n];     map<long long, long long> mp;     for (int i = 0; i < n; i++) {       cin >> a[i];       mp[a[i]]++;     }     sort(a, a + n);     int i = 0, j = n - 1;     long long mini = a[0], maxi = a[n - 1];     while (k && i < j) {       while (i + 1 < n && a[i] == a[i + 1]) i++;       while (j - 1 >= 0 && a[j] == a[j - 1]) j--;       if (i < j) {         long long x = mp[a[i]], y = mp[a[j]];         if (x < y) {           long long d = a[i + 1] - a[i];           long long mn = min(k / x, d);           if ((a[i] + mn) == a[i + 1]) {             mp[a[i + 1]] += mp[a[i]];             k -= (mn * mp[a[i]]);             mini = a[i + 1];             i++;           } else {             mini = a[i] + mn;             break;           }         } else {           long long d = a[j] - a[j - 1];           long long mn = min(k / y, d);           if ((a[j] - mn) == a[j - 1]) {             mp[a[j - 1]] += mp[a[j]];             k -= (mn * mp[a[j]]);             maxi = a[j - 1];             j--;           } else {             maxi = a[j] - mn;             break;           }         }       } else {         mini = a[i], maxi = a[i];       }     }     cout << maxi - mini << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int N;   string s;   int pows[4] = {0, 0, 0, 0};   void Desc(int q) {     if (q <= 1) return;     switch (q) {       case 2:         pows[0]--;         break;       case 3:         pows[1]--;         break;       case 4:         pows[0] -= 2;         break;       case 5:         pows[2]--;         break;       case 6:         pows[0]--;         pows[1]--;         break;       case 7:         pows[3]--;         break;       case 8:         pows[0] -= 3;         break;       case 9:         pows[1] -= 2;         break;     }     Desc(q - 1);   }   void Proc(int q) {     if (q <= 1) return;     switch (q) {       case 2:         pows[0]++;         break;       case 3:         pows[1]++;         break;       case 4:         pows[0] += 2;         break;       case 5:         pows[2]++;         break;       case 6:         pows[0]++;         pows[1]++;         break;       case 7:         pows[3]++;         break;       case 8:         pows[0] += 3;         break;       case 9:         pows[1] += 2;         break;     }     Proc(q - 1);   }   int conv(int q) {     switch (q) {       case 0:         return 2;       case 1:         return 3;       case 2:         return 5;       case 3:         return 7;     }   }   int main() {     ios_base::sync_with_stdio(0);     cout.precision(20);     cin >> N;     cin >> s;     for (int i = 0; i < N; ++i) Proc(s[i] -  0 );     for (int i = 3; i >= 0; --i) {       while (pows[i] != 0) {         cout << conv(i);         Desc(conv(i));       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> status(26);   vector<vector<int> > adjList(200000);   vector<string> names(100);   vector<int> ts;   vector<int> processing(26);   void dfs(int u, bool &valid) {     status[u] = 1;     processing[u] = true;     for (int j = 0; j < adjList[u].size(); j++) {       int v = adjList[u][j];       if (processing[v] == true) {         valid = false;         return;       }       if (status[v] == 0) {         dfs(v, valid);       }     }     processing[u] = false;     ts.push_back(u);   }   int main() {     int n;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> names[i];     }     for (int i = 0; i < 26; i++) {       status[i] = 0;       processing[i] = false;     }     for (int i = 0; i < n - 1; i++) {       int c1 = -1;       int c2 = -1;       for (int j = 0; j < names[i].size() && j < names[i + 1].size(); j++) {         if (names[i][j] != names[i + 1][j]) {           c1 = names[i][j];           c2 = names[i + 1][j];           adjList[(c1 -  a )].push_back(c2 -  a );           break;         }       }       if (c1 == -1 && c2 == -1 && names[i].size() > names[i + 1].size()) {         cout <<  Impossible  << endl;         return 0;       }     }     for (int i = 0; i < 26; i++) {       if (status[i] == 0) {         bool valid = true;         dfs(i, valid);         if (!valid) {           cout <<  Impossible  << endl;           return 0;         }       }     }     for (int i = ts.size() - 1; i >= 0; i--) {       cout << (char)( a  + ts[i]);     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 123456;   char buffer[N];   string solve(string s, int k) {     const int n = s.size();     sort(s.begin(), s.end());     string res;     int ptr = 0;     while (ptr < n) {       int p = ptr;       char mini =  ~ ;       char maxi =   0 ;       assert(mini >  z  && maxi <  a );       for (int i = 0; i < k && ptr < n; i++) {         mini = min(mini, s[ptr]);         maxi = max(maxi, s[ptr]);         ptr++;       }       if (!res.empty()) {         if (mini == s.back()) {           res += mini;         } else {           res += s.substr(p);           break;         }       } else {         if (mini == maxi) {           res += mini;         } else {           res += maxi;           break;         }       }     }     return res;   }   string brute_force(string s, int k) {     assert(k == 2);     int n = s.size();     string res =  ~~~ ;     sort(s.begin(), s.end());     for (int i = 0; i < (1 << n); i++) {       string left, right;       for (int j = 0; j < n; j++) {         if (i & (1 << j)) {           left += s[j];         } else {           right += s[j];         }       }       if (left.empty() || right.empty()) {         continue;       }       res = min(res, max(left, right));     }     return res;   }   void test() {     assert(solve( ccbbb , 2) ==  bbcc );     assert(solve( bbabc , 2) ==  b );     assert(solve( bababc , 2) ==  abbbc );     assert(solve( babab , 2) ==  abb );     assert(solve( baba , 2) ==  ab );     assert(solve( baacb , 2) ==  abbc );     assert(solve( baacb , 3) ==  b );     assert(solve( aaaaa , 3) ==  aa );     assert(solve( aaxxzz , 4) ==  x );     assert(solve( phoenix , 1) ==  ehinopx );     assert(solve( phoenix , 2) ==  h );     for (int i = 0; i < 100; i++) {       int n = 10;       string s;       for (int j = 0; j < n; j++) {         s += rand() % 5 +  a ;       }       assert(brute_force(s, 2) == solve(s, 2));     }   }   int main() {     int T;     cin >> T;     int n, k;     while (T--) {       scanf( %d%d , &n, &k);       scanf( %s , buffer);       puts(solve(buffer, k).c_str());     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t, fl;     cin >> t;     while (t--) {       fl = 1;       int a, b, c, d, x, y, x1, y1, x2, y2;       cin >> a >> b >> c >> d >> x >> y >> x1 >> y1 >> x2 >> y2;       int p = x - a + b, q = y - c + d;       if ((p >= x1 && p <= x2) && (x1 < x2 || a + b == 0))         ;       else         fl = 0;       if ((q >= y1 && q <= y2) && (y1 < y2 || c + d == 0))         ;       else         fl = 0;       if (fl)         cout <<  YES  << endl;       else         cout <<  NO  << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int N;     cin >> N;     string s;     cin >> s;     int current = N;     int count = 0;     while (true) {       if (current >= s.size()) break;       set<char> vs;       vs.insert(s[current - 1]);       vs.insert(s[current - 2]);       vs.insert(s[current - 3]);       if (vs.size() == 1) count++;       current += N;     }     cout << count;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long int n, h, A, B, k, S, T, ta, tb, fa, fb;     cin >> n >> h >> A >> B >> k;     for (long int i = 0; i < k; i++) {       S = 0;       cin >> ta >> fa >> tb >> fb;       if (ta == tb) {         S = abs(fa - fb);       } else {         if (fa < A) {           S += abs(A - fa);           T = A;         } else if (fa > B) {           S += abs(fa - B);           T = B;         } else {           S += 0;           T = fa;         }         S += abs(ta - tb);         S += abs(fb - T);       }       cout << S << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long power(long long a, long long b, long long p) {     if (a == 0) return 0;     long long res = 1;     a %= p;     while (b > 0) {       if (b & 1) res = (res * a) % p;       b >>= 1;       a = (a * a) % p;     }     return res;   }   int32_t main() {     std::ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     long long t;     cin >> t;     while (t--) {       long long n;       cin >> n;       long long ar[n];       for (long long i = 0; i < n; i++) cin >> ar[i];       sort(ar, ar + n);       for (long long i = n - 1; i >= 0; i--) cout << ar[i] <<    ;       cout <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 10;   const int INF = 1.01e9;   const long long INF18 = 1.01e18;   int main() {     int n;     long long C;     scanf( %d%lld , &n, &C);     vector<long long> a(n);     vector<long long> b(n - 1);     for (int i = 0; i < (n); i++) {       scanf( %lld , &a[i]);       if (i + 1 != n) {         scanf( %lld , &b[i]);       }     }     b.push_back(0);     vector<long long> c(n);     set<pair<long long, int>> q;     long long shift = 0;     vector<long long> hist(n);     int cur = 0;     vector<long long> prefB;     prefB.push_back(0);     for (int i = 0; i < n; i++) {       prefB.push_back(prefB.back() + a[i] + b[i]);     }     vector<long long> prefC;     prefC.push_back(0);     for (int i = 0; i < n; i++) {       if (i > 0) {         long long diff = b[i - 1] - c[i - 1];         shift += diff;         q.insert({-shift, i});         hist[i] = -shift;       }       if (i == 0) {         q.insert({0, i});         hist[i] = 0;       }       for (; cur < i && (prefB[i] - prefB[cur]) + a[i] > C;) {         assert(q.erase({hist[cur], cur}));         cur++;       }       long long val = 0;       if (!q.empty()) {         val = max(q.rbegin()->first + shift, val);       }       val = max(           min(prefB[i] + a[i], C) - ((prefC[i] - prefC[max(0, cur - 1)]) + a[i]),           val);       c[i] = val;       prefC.push_back(prefC.back() + a[i] + c[i]);     }     long long answer = 0;     for (auto x : c) {       answer += x;     }     for (auto x : a) {       answer += min(x, C);     }     cout << answer << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int x[1000 + 1], y[1000 + 1];   void solve() {     int n;     cin >> n;     for (int i = 0; i < n + 1; i++) cin >> x[i] >> y[i];     int res = 0;     for (int i = 1; i < n; i++) {       double X = x[i], Y = y[i];       int cnt = 0;       if (x[i - 1] == x[i]) {         if (y[i] > y[i - 1])           Y += 0.2;         else           Y -= 0.2;         for (int j = 0; j < n; j++)           if (x[j] == x[j + 1] && x[j] < x[i] && min(y[j], y[j + 1]) < Y &&               Y < max(y[j], y[j + 1]))             cnt++;         if (cnt % 2 == 1) res++;       } else {         if (x[i] > x[i - 1])           X += 0.2;         else           X -= 0.2;         for (int j = 0; j < n; j++)           if (y[j] == y[j + 1] && y[j] < y[i] && min(x[j], x[j + 1]) < X &&               X < max(x[j], x[j + 1]))             cnt++;         if (cnt % 2 == 1) res++;       }     }     cout << res;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     int fac[4];     fac[0] = 1;     fac[1] = 1;     fac[2] = 1;     for (int i = 3; i < 10; i++) {       int y1213 = 100;       int n1113;       vector<int> ans112;       int tempor = 100;     }     while (t--) {       int n;       cin >> n;       long long res = 1;       for (int i = 0; i < 10; i++) {         int j661;         int k771;         string k772;       }       int y1213 = 100;       int n1113;       long long modu = 1e9 + 7;       for (int i = 2 * n; i >= 3; i--) {         res = (res * i) % modu;       }       vector<int> ans1222;       int tem33por = 100;       for (int i = 0; i < 10; i++) {         int j12;         int k15;         string k277;       }       res = res % modu;       cout << res <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<int> v;     for (int i = 1; i * i <= n; i++) {       if (n % i == 0) {         v.push_back(i);         if (i != n / i) {           v.push_back(n / i);         }       }     }     sort(v.begin(), v.end());     int ans = 0;     for (int i = v.size() - 1; i > -1; i--) {       int p = v[i];       int q = 0;       while (p % 2 == 0) {         q++;         p /= 2;       }       int r = pow(2, q + 1) + 0.5;       r--;       if (p == r) {         ans = v[i];         break;       }     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 20;   long long int c[15][maxn];   int lowbit(int x) { return x & (-x); }   void upDate(int pos, long long int val, int which) {     while (pos <= maxn - 20) {       c[which][pos] += val;       pos += lowbit(pos);     }   }   long long int ask(int pos, int which) {     long long int ans = 0;     while (pos) {       ans += c[which][pos];       pos -= lowbit(pos);     }     return ans;   }   long long int dp[maxn][15];   void work() {     int n, k;     cin >> n >> k;     for (int i = 1; i <= n; ++i) {       int x;       cin >> x;       dp[i][1] = 1;       for (int j = 2; j <= k + 1; ++j) {         dp[i][j] += ask(x - 1, j - 1);       }       for (int j = 1; j <= k + 1; ++j) {         upDate(x, dp[i][j], j);       }     }     long long int ans = 0;     for (int i = 1; i <= n; ++i) ans += dp[i][k + 1];     cout << ans << endl;   }   int main() {     ios::sync_with_stdio(false);     work();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100005;   int n, m, q;   int c[N];   vector<pair<long long, int> > girl[N];   int head[N], to[N * 2], pre[N * 2], tot;   void addedge(int u, int v) {     to[++tot] = v;     pre[tot] = head[u];     head[u] = tot;   }   int L[N], R[N], dfn, id[N], dep[N], top[N], son[N], fa[N];   int dfs1(int u, int depth) {     dep[u] = depth;     int mx = 0, sum = 1, tmp;     for (int v, i = head[u]; i; i = pre[i])       if ((v = to[i]) != fa[u]) {         fa[v] = u;         tmp = dfs1(v, depth + 1);         if (tmp > mx) mx = tmp, son[u] = v;         sum += tmp;       }     return sum;   }   void dfs2(int u, int anc) {     top[u] = anc;     L[u] = ++dfn;     id[dfn] = u;     if (son[u]) dfs2(son[u], anc);     for (int i = head[u]; i; i = pre[i])       if (to[i] != fa[u] && to[i] != son[u]) dfs2(to[i], to[i]);     R[u] = dfn;   }   pair<long long, int> min(pair<long long, int> a, pair<long long, int> b) {     if (a.first < b.first) return a;     if (a.first > b.first) return b;     if (c[a.second] < c[b.second]) return a;     return b;   }   pair<long long, int> mi[N * 4];   long long add[N * 4];   void up(int i) {     mi[i] = min(mi[i << 1], mi[i << 1 | 1]);     mi[i].first += add[i];   }   void build(int i, int l, int r) {     if (l == r) {       if (girl[id[l]].begin() == girl[id[l]].end())         mi[i] = make_pair((1e17), (0));       else         mi[i] = *(girl[id[l]].end() - 1);       return;     }     int mid = (l + r) >> 1;     build(i << 1, l, mid);     build(i << 1 | 1, mid + 1, r);     up(i);   }   pair<long long, int> ans;   pair<long long, int> query(int i, int l, int r, int opl, int opr) {     if (l == opl && r == opr) return mi[i];     pair<long long, int> ans;     int mid = (l + r) >> 1;     if (opr <= mid)       ans = query(i << 1, l, mid, opl, opr);     else if (mid < opl)       ans = query(i << 1 | 1, mid + 1, r, opl, opr);     else       ans = min(query(i << 1, l, mid, opl, mid),                 query(i << 1 | 1, mid + 1, r, mid + 1, opr));     ans.first += add[i];     return ans;   }   void work(int i, int l, int r, int pos) {     if (l == r) {       girl[id[l]].pop_back();       if (girl[id[l]].begin() == girl[id[l]].end())         mi[i] = make_pair((1e17), (0));       else         mi[i] = *(girl[id[l]].end() - 1);       mi[i].first += add[i];       return;     }     int mid = (l + r) >> 1;     if (pos <= mid)       work(i << 1, l, mid, pos);     else       work(i << 1 | 1, mid + 1, r, pos);     up(i);   }   int work(int u, int v) {     ans = make_pair((1e17), (0));     while (top[u] != top[v]) {       if (dep[top[u]] < dep[top[v]]) swap(u, v);       ans = min(query(1, 1, n, L[top[u]], L[u]), ans);       u = fa[top[u]];     }     if (dep[u] > dep[v]) swap(u, v);     ans = min(ans, query(1, 1, n, L[u], L[v]));     if (ans.first == 1e17) return -1;     work(1, 1, n, L[c[ans.second]]);     return ans.second;   }   void updata(int i, int l, int r, int opl, int opr, long long k) {     if (l == opl && r == opr) {       add[i] += k;       mi[i].first += k;       return;     }     int mid = (l + r) >> 1;     if (opr <= mid)       updata(i << 1, l, mid, opl, opr, k);     else if (mid < opl)       updata(i << 1 | 1, mid + 1, r, opl, opr, k);     else       updata(i << 1, l, mid, opl, mid, k),           updata(i << 1 | 1, mid + 1, r, mid + 1, opr, k);     up(i);   }   int num, tmp[N];   int main() {     int ty, u, v, k;     scanf( %d%d%d , &n, &m, &q);     for (int i = 1; i < n; i++) {       scanf( %d%d , &u, &v);       addedge(u, v);       addedge(v, u);     }     for (int i = 1; i <= m; i++) {       scanf( %d , &c[i]);       girl[c[i]].push_back(make_pair((i), (i)));     }     dfs1(1, 1);     dfs2(1, 1);     for (int i = 1; i <= n; i++)       sort(girl[i].begin(), girl[i].end(), greater<pair<long long, int> >());     build(1, 1, n);     for (int i = 1; i <= q; i++) {       scanf( %d , &ty);       if (ty == 1) {         scanf( %d%d%d , &u, &v, &k);         num = 0;         while (k--) {           tmp[++num] = work(u, v);           if (tmp[num] == -1) {             num--;             break;           }         }         printf( %d  , num);         for (int i = 1; i <= num; i++) printf( %d  , tmp[i]);         puts(  );       } else {         scanf( %d%d , &u, &k);         updata(1, 1, n, L[u], R[u], k);       }     }     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, v, a, b, x;     cin >> n >> v;     int mp[3002] = {0};     for (int i = 0; i < n; i++) {       cin >> a >> b;       mp[a] += b;     }     int prev = 0, ans = 0;     for (int i = 1; i <= 3001; i++) {       int now = mp[i];       if (now + prev <= v) {         ans += (now + prev);         prev = 0;       } else {         ans += v;         prev = now - max(v - prev, 0);       }     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct node {     node *c[3];     bool flag;   };   node *root;   void insert(string a) {     node *cur = root;     for (int i = 0; i < a.size(); i++) {       if (!(cur->c[a[i] -  a ])) cur->c[a[i] -  a ] = new node();       cur = cur->c[a[i] -  a ];     }     cur->flag = 1;   }   string s;   bool solve(node *root, int pos, int diff) {     if (!root) return 0;     if (diff > 1) return 0;     if (pos == s.size()) return diff == 1 && root->flag;     int ret = 0;     for (int i = 0; i < 3; i++)       ret = ret || solve(root->c[i], pos + 1, (s[pos] -  a  != i) + diff);     return ret;   }   int main() {     int n, m;     cin >> n >> m;     root = new node();     for (int i = 0; i < n; i++) {       string s;       cin >> s;       insert(s);     }     for (int i = 0; i < m; i++) {       cin >> s;       if (solve(root, 0, 0))         cout <<  YES n ;       else         cout <<  NO n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1000000007;   const int INF = int(1e9);   const int MAX = 200;   int num[MAX], mixt[MAX];   int n;   bool substring(string &a, string &b) {     for (int i = 0; i < n; i++) {       bool found = true;       for (int j = 0; j < 3; j++) {         if (a[i + j] != b[j]) {           found = false;         }       }       if (found) {         return true;       }     }     return false;   }   int main() {     ios_base::sync_with_stdio(false);     string s;     cin >> s;     n = s.size();     string t =  ABC ;     do {       if (substring(s, t)) {         cout <<  Yes n ;         return 0;       }     } while (next_permutation(t.begin(), t.end()));     cout <<  No n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long mod(long long a, long long b) {     if (a % b < 0) {       return a % b + b;     }     return a % b;   }   long long mod_exp(long long a, long long b, long long c) {     long long res = 1;     a = a % c;     while (b > 0) {       if (b % 2 == 1) {         res = (res * a) % c;       }       b /= 2;       a = (a * a) % c;     }     return res;   }   long long mymod(long long a, long long b) { return ((a % b) + b) % b; }   bool prime[200001];   void SieveOfEratosthenes() {     memset(prime, true, sizeof(prime));     prime[1] = false;     for (int p = 2; p * p <= 200000; p++) {       if (prime[p] == true) {         for (int i = p * p; i <= 200000; i += p) prime[i] = false;       }     }     return;   }   long long powe[200005];   void power() {     powe[0] = 1;     for (long long i = 1; i < 200005; i++) {       powe[i] = mymod(2 * powe[i - 1], 1000000007);     }   }   long long gcdExtended(long long, long long, long long *, long long *);   long long modInverse(long long a, long long m) {     long long x, y;     long long g = gcdExtended(a, m, &x, &y);     long long res = (x % m + m) % m;     return res;   }   long long gcdExtended(long long a, long long b, long long *x, long long *y) {     if (a == 0) {       *x = 0, *y = 1;       return b;     }     long long x1, y1;     long long gcd = gcdExtended(b % a, a, &x1, &y1);     *x = y1 - (b / a) * x1;     *y = x1;     return gcd;   }   long long n;   struct node {     vector<long long> adj;     long long colour;   };   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long n;     cin >> n;     string second;     cin >> second;     long long count[36001] = {0};     for (long long i = 0; i < second.size(); i++) {       long long sum = 0;       for (long long j = i; j < second.size(); j++) {         sum += (second[j] - 48);         if (sum <= 36000) {           count[sum]++;         } else           break;       }     }     vector<long long> factors;     for (long long i = 1; i < sqrt(n); i++) {       if (n % i == 0) {         factors.push_back(i);         factors.push_back(n / i);       }     }     if ((long long)(sqrt(n)) * (long long)(sqrt(n)) == n)       factors.push_back((long long)(sqrt(n)));     long long ans = 0;     if (n == 0) {       long long p = second.size();       long long ways0 = count[0];       long long waysn0 = (p * (p + 1)) / 2 - count[0];       ans = 2 * ways0 * waysn0 + ways0 * ways0;       cout << ans << endl;       exit(0);     }     for (auto x : factors) {       if (x <= 36000 && (n / x) <= 36000) ans += (count[x] * count[n / x]);     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   double h, luas, top;   int n;   double f(double x) { return ((x / h + top / h) * (x - top)) / 2; }   double binser(double l, double r) {     double ret = 0;     for (int i = 1; i <= 100; i++) {       double mid = (l + r) / 2;       if (f(mid) >= luas) {         ret = mid;         r = mid;       } else         l = mid;     }     return ret;   }   int main() {     cin >> n >> h;     luas = h / (2 * n);     for (int i = 1; i <= n - 1; i++) {       top = binser(0, h);       cout << fixed << setprecision(6) << top;       if (i < n - 1) cout <<    ;     }     cout << endl;   }


#include <bits/stdc++.h>   using namespace std;   unsigned long long n, H;   unsigned long long bound[60];   unsigned long long cnt(unsigned long long p, unsigned long long h,                          unsigned long long n) {     if (h == 1) {       if (p == 0 && n == 1) return 1;       if (p == 1 && n == 2) return 1;       return 2;     }     unsigned long long res = 1;     if (n > bound[h - 1] && p == 0 || n <= bound[h - 1] && p == 1)       res += 2 * bound[h - 1] - 1;     if (n > bound[h - 1])       res += cnt(0, h - 1, n - bound[h - 1]);     else       res += cnt(1, h - 1, n);     return res;   }   int main() {     cin >> H >> n;     bound[0] = 1;     for (unsigned long long i = 0; i < H; ++i) bound[i + 1] = 2 * bound[i];     cout << cnt(0, H, n);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T, typename U>   std::pair<T, U> operator+(const std::pair<T, U> &l, const std::pair<T, U> &r) {     return {l.first + r.first, l.second + r.second};   }   typedef void (*callback_function)(void);   const long long INF64 = 1e18;   const long long INF32 = 1e9;   long long dist(pair<long long, long long> &a, pair<long long, long long> &b) {     return abs(a.first - b.first) + abs(a.second - b.second);   }   long long dist(pair<long long, long long> &a) {     return abs(a.first) + abs(a.second);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie();     {       long long n;       string s;       cin >> n >> s;       long long res = 1;       bool first[2] = {true, true};       char hv[2];       string HV[2] = { LR ,  DU };       for (long long i = (0); i < (s.length()); i++) {         for (long long j = (0); j < (2); j++) {           if (HV[j].find(s[i]) != string::npos) {             if (first[j]) {               first[j] = false;               hv[j] = s[i];             } else if (hv[j] != s[i]) {               first[1 - j] = true;               res++;               hv[j] = s[i];             }             break;           }         }       }       cout << res << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int gcd(long long int a, long long int b) {     if (a < b) swap(a, b);     if (b == 0)       return a;     else       gcd(b, a % b);   }   int main() {     long long int ncr[62][62];     for (long long int i = 0; i < 62; i++) {       ncr[i][0] = 1;       ncr[i][i] = 1;     }     for (long long int i = 1; i < 62; i++) {       for (long long int j = 1; j <= i; j++) {         ncr[i][j] = ncr[i - 1][j - 1] + ncr[i - 1][j];       }     }     long long int n, m, t, ans = 0;     cin >> n >> m >> t;     for (long long int i = 4; i <= t - 1; i++) {       ans += (ncr[n][i] * ncr[m][t - i]);     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long n, q;     cin >> n >> q;     long i, j;     int** a = new int*[2];     for (i = 0; i < 2; ++i) {       a[i] = new int[n + 2];       for (j = 0; j < n + 2; j++) {         a[i][j] = 0;       }     }     long res = 0;     long x, y;     while (q--) {       cin >> x >> y;       if (a[x - 1][y] == 0) {         a[x - 1][y] = 1;         for (i = -1; i <= 1; i++) {           if (a[2 - x][y + i] == 1) res++;         }       } else {         a[x - 1][y] = 0;         for (i = -1; i <= 1; i++) {           if (a[2 - x][y + i] == 1) {             res--;           }         }       }       if (res == 0)         cout <<  Yes  << endl;       else         cout <<  No  << endl;     }     return 0;   }


#include <bits/stdc++.h>   #pragma warning(disable : 4996)   using namespace std;   using ld = long double;   template <class T>   using Table = vector<vector<T>>;   const ld eps = 1e-9;   template <class S, class T>   ostream &operator<<(ostream &os, const pair<S, T> v) {     os <<  (   << v.first <<  ,   << v.second <<  ) ;     return os;   }   template <class T>   ostream &operator<<(ostream &os, const vector<T> &v) {     for (int i = 0; i < v.size(); i++) {       if (i > 0) {         os <<    ;       }       os << v[i];     }     return os;   }   template <class T>   ostream &operator<<(ostream &os, const vector<vector<T>> &v) {     for (int i = 0; i < v.size(); i++) {       if (i > 0) {         os << endl;       }       os << v[i];     }     return os;   }   template <class T>   ostream &operator<<(ostream &os, const vector<set<T>> &v) {     for (int i = 0; i < v.size(); i++) {       if (i > 0) {         os << endl;       }       os << v[i];     }     return os;   }   template <class T>   ostream &operator<<(ostream &os, const set<T> &v) {     int i = 0;     for (auto it : v) {       if (i > 0) {         os <<    ;       }       os << it;       i++;     }     return os;   }   using ll = long long int;   pair<int, bool> get_c(const vector<vector<int>> &graph, int N) {     vector<int> comes(N);     vector<int> colors(N, -1);     bool ok = true;     queue<int> que;     int sum = 0;     for (int i = 0; i < N; ++i) {       if (!comes[i]) {         colors[i] = 0;         sum++;         que.emplace(i);         while (!que.empty()) {           int now = que.front();           comes[now] = true;           que.pop();           for (auto e : graph[now]) {             if (!comes[e]) {               que.emplace(e);               colors[e] = 1 ^ colors[now];             }             if (colors[e] == colors[now]) ok = false;           }         }       }     }     return make_pair(sum, ok);   }   ll int_pow(int a, int b) {     if (b == 0)       return 1;     else       return a * int_pow(a, b - 1);   }   int main() {     ios::sync_with_stdio(false);     int N, M;     cin >> N >> M;     vector<vector<int>> edges(N);     for (int i = 0; i < M; ++i) {       int u, v;       cin >> u >> v;       u--;       v--;       edges[u].push_back(v);       edges[v].push_back(u);     }     auto p = get_c(edges, N);     int C = p.first;     bool b_ok = p.second;     int isolated_v_cnt = 0;     for (int i = 0; i < N; ++i) {       if (edges[i].empty()) isolated_v_cnt++;     }     vector<vector<vector<ll>>> cnts(2, vector<vector<ll>>(2, vector<ll>(2)));     cnts[1][0][0] = cnts[0][0][1] = int_pow(2, isolated_v_cnt);     cnts[0][1][0] = b_ok ? int_pow(2, C) : 0;     cnts[1][1][1] = int_pow(2, N);     cnts[1][0][1] = int_pow(2, C);     {       int K = N / 2;       vector<int> yys(1ll << (N - K));       for (int xx = 0; xx < (1ll << K); ++xx) {         bool ok = true;         vector<int> uses(K);         for (int i = 0; i < K; ++i) {           uses[i] = (xx & (1ll << i)) != 0;         }         int yy = 0;         for (int i = 0; i < K; ++i) {           for (auto e : edges[i]) {             if (uses[i]) {               if (e < K) {                 if (uses[i] && uses[e]) ok = false;               } else {                 yy |= (1ll << (e - K));               }             }           }         }         if (ok) {           yys[yy ^ ((1ll << (N - K)) - 1)]++;         } else {         }       }       for (int i = 0; i < (N - K); ++i) {         for (int x = 0; x < (1ll << (N - K)); ++x) {           if ((x & (1ll << i)) != 0) {             yys[x ^ (1ll << i)] += yys[x];           }         }       }       ll answer = 0;       for (int yy = 0; yy < (1ll << (N - K)); ++yy) {         bool ok = true;         vector<int> uses(N - K);         for (int i = 0; i < N - K; ++i) {           uses[i] = (yy & (1ll << i)) != 0;         }         for (int i = 0; i < N - K; ++i) {           for (auto e : edges[K + i]) {             if (e >= K) {               if (uses[i] && uses[e - K]) ok = false;             } else {             }           }         }         if (ok) {           answer += yys[yy];         }       }       cnts[1][1][0] = cnts[0][1][1] = answer;     }     if (!M) cnts[0][0][0] = (1ll << N);     ll answer = 0;     answer = cnts[1][1][1] - cnts[1][1][0] - cnts[1][0][1] - cnts[0][1][1] +              cnts[1][0][0] + cnts[0][1][0] + cnts[0][0][1] - cnts[0][0][0];     cout << answer << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   #define ll long long int   #define mp make_pair   //ll const MAX_N=100000;   ll const MAX_A = (ll)1e9 + 1;   const ll MOD = 1e9 + 7;               void solve()   {    ll n, l,u,v,w,n1,n2,n3,h,sum=0,suma=0,sumb=0,sumc=0,minia=MAX_A,minib=MAX_A,minic=MAX_A, ansa,ansb,ansc;    cin>>n1>>n2>>n3;    ll a[n1],b[n2],c[n3];    vector<ll> pos;    for(auto & i: a)    {     cin>>i;     minia=min(i,minia);     suma+=i;     }    for(auto & i: b)    {     cin>>i;     minib=min(i,minib);     sumb+=i;     }    for(auto & i: c)    {     cin>>i;     minic=min(i,minic);     sumc+=i;    }    sum=suma+sumb+sumc;    sort(a,a+n1);    sort(b,b+n2);    sort(c,c+n3);    ansa=sum-2*minia-2*min(min(minib,minic),suma-minia);    ansb=sum-2*minib-2*min(min(minia,minic),sumb-minib);    ansc=sum-2*minic-2*min(min(minib,minia),sumc-minic);           cout<<max(ansa,max(ansb,ansc))<<endl;   }      int main()   {    //freopen( luka.in , r , stdin);    ios_base::sync_with_stdio(false);       cin.tie(NULL);    ll t = 1;    //cin >> t;    for (ll i = 1; i <= t; i++)    {     solve();    }    return 0;   }


#include <bits/stdc++.h>   using namespace std;   priority_queue<int, vector<int>, greater<int> > q;   int main() {     int n, m;     while (cin >> n) {       long long sum = 0;       if (!q.empty()) {         q.pop();       }       while (n--) {         scanf( %d , &m);         if (!q.empty() && m > q.top()) {           sum += m - q.top();           q.pop();           q.push(m);           q.push(m);         } else {           q.push(m);         }       }       cout << sum << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     char str[100];     int n, z;     cin >> z;     while (z--) {       cin >> str;       n = strlen(str);       if (n > 10) {         cout << str[0] << n - 2 << str[n - 1] << endl;       } else         cout << str << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     double l, r, x, y, k, i, f = 0;     cin >> l >> r >> x >> y >> k;     for (i = x; i <= y; i++) {       if ((i * k) >= l && (i * k) <= r) {         f = 1;         break;       } else         continue;     }     if (f == 1)       cout <<  YES n ;     else       cout <<  NO n ;     return 0;   }