#include <bits/stdc++.h>   constexpr auto Inf = 0X3F3F3F3F;   using namespace std;   namespace IO {   inline long long read() {     long long o = 0, f = 1;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) f = -1;       c = getchar();     }     while (c >  /  && c <  : ) {       o = o * 10 + c -  0 ;       c = getchar();     }     return o * f;   }   inline char recd() {     char o;     while ((o = getchar()) <  0  || o >  9 )       ;     return o;   }   inline double reod() {     double o = read(), f = 1;     char c;     while ((c = getchar()) >  /  && c <  : ) o += (c -  0 ) / (f *= 10);     return o;   }   }  // namespace IO   using namespace IO;   const int SIZE = 2E5 + 7, Mod = 1E9 + 7;   vector<pair<int, pair<long long, int> > > vec[SIZE];   long long TS = 0;   struct Node {     long long w;     int c, cost;     Node(long long w, long long c, long long cost) : w(w), c(c), cost(cost){};     bool operator<(const Node& Tmp) const {       return (w - w / 2) * c < (Tmp.w - Tmp.w / 2) * Tmp.c;     }   };   priority_queue<Node> oque, sque;   int DFS(int now, int F) {     int son = 0;     for (int pos = 0; pos < vec[now].size(); pos++) {       int v = vec[now][pos].first;       if (v != F) {         int s = DFS(v, now);         TS += s * vec[now][pos].second.first;         son += s;         if (vec[now][pos].second.second == 1)           oque.push(               Node(vec[now][pos].second.first, s, vec[now][pos].second.second));         else           sque.push(               Node(vec[now][pos].second.first, s, vec[now][pos].second.second));       }     }     return son == 0 ? 1 : son;   }   long long aw[int(2E6)], bw[int(2E6)];   int main() {     int T = read();     while (T--) {       int N = read();       long long S = read(), Tmp;       for (int pos = 1, u, v, w, c; pos < N; pos++) {         u = read(), v = read(), w = read(), c = read();         vec[u].push_back({v, {w, c}});         vec[v].push_back({u, {w, c}});       }       DFS(1, 0);       int ans = Inf, aInd = 1, bInd = 1;       long long d = TS - S;       Tmp = d;       while (Tmp > 0 && !oque.empty()) {         Node now = oque.top();         oque.pop();         Tmp -= (now.w - now.w / 2) * now.c;         aw[aInd] = aw[aInd - 1] + (now.w - now.w / 2) * now.c;         aInd++, now.w /= 2;         if (now.w) oque.push(now);       }       Tmp = d;       while (Tmp > 0 && !sque.empty()) {         Node now = sque.top();         sque.pop();         Tmp -= (now.w - now.w / 2) * now.c;         bw[bInd] = bw[bInd - 1] + (now.w - now.w / 2) * now.c;         bInd++, now.w /= 2;         if (now.w) sque.push(now);       }       int L = 0, R = bInd - 1;       while (L < aInd && R >= 0) {         while (R >= 0 && aw[L] + bw[R] >= d) ans = min(ans, L + (R << 1)), R--;         L++;       }       printf( %d n , TS <= S ? 0 : ans);       for (int pos = 1; pos <= N; pos++) vec[pos].clear();       TS = 0;       while (!oque.empty()) oque.pop();       while (!sque.empty()) sque.pop();     }   }


#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 N = 300005;   const long long INF = 1e18;   int n, m, s, dep[N], ff[N], fa[N][21], de[N];   long long dis[N];   bool vis[N];   vector<pair<int, int> > adj[N];   vector<int> bdj[N];   priority_queue<pair<long long, int> > q;   void dij() {     for (int i = 1; i <= n; i++) dis[i] = INF;     while (!q.empty()) q.pop();     dis[s] = 0LL;     q.push(make_pair(0LL, s));     while (!q.empty()) {       int x = q.top().second;       q.pop();       if (vis[x]) continue;       vis[x] = 1;       for (auto e : adj[x]) {         int y = e.first;         long long w = e.second;         if (dis[y] > dis[x] + w) {           dis[y] = dis[x] + w;           q.push(make_pair(-dis[y], y));         }       }     }   }   int lca(int x, int y) {     if (dep[x] < dep[y]) swap(x, y);     for (int i = 20; ~i; i--)       if (dep[fa[x][i]] >= dep[y]) x = fa[x][i];     for (int i = 20; ~i; i--)       if (fa[x][i] != fa[y][i]) x = fa[x][i], y = fa[y][i];     return (x == y) ? x : fa[x][0];   }   queue<int> Q;   int ver[N], nxt[N], fst[N], tot, siz[N], ans;   void addedge(int x, int y) {     ver[++tot] = y;     nxt[tot] = fst[x];     fst[x] = tot;   }   void dfs(int x) {     siz[x] = 1;     for (int i = fst[x]; i; i = nxt[i]) {       int y = ver[i];       dfs(y);       siz[x] += siz[y];     }   }   int main() {     n = read();     m = read();     s = read();     for (int i = 1; i <= m; i++) {       int x = read(), y = read(), w = read();       adj[x].push_back(make_pair(y, w));       adj[y].push_back(make_pair(x, w));     }     dij();     for (int x = 1; x <= n; x++) {       for (auto e : adj[x]) {         int y = e.first;         long long w = e.second;         if (dis[y] == dis[x] + w) {           bdj[x].push_back(y);           de[y]++;         }       }     }     memset(ff, -1, sizeof(ff));     dep[0] = 1;     for (int i = 1; i <= n; i++) {       if (!de[i] && dis[i] < INF) {         ff[i] = 0;         Q.push(i);       }     }     while (!Q.empty()) {       int x = Q.front();       Q.pop();       dep[x] = dep[ff[x]] + 1;       fa[x][0] = ff[x];       for (int i = 1; i <= 20; i++) fa[x][i] = fa[fa[x][i - 1]][i - 1];       for (auto y : bdj[x]) {         if (ff[y] == -1)           ff[y] = x;         else           ff[y] = lca(ff[y], x);         de[y]--;         if (!de[y]) Q.push(y);       }     }     for (int i = 1; i <= n; i++) addedge(ff[i], i);     dfs(0);     for (int i = 1; i <= n; i++)       if (i != s) ans = max(ans, siz[i]);     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void O_o() {     ios::sync_with_stdio(0);     ios_base::sync_with_stdio(0);     cin.tie(0), cout.tie(0);   }   int main() {     O_o();     int x, y;     bool flag;     vector<int> vec;     cin >> x;     y = x;     while (x != 0) {       vec.push_back(x % 10);       x = x / 10;     }     for (int i = 0; i < vec.size(); i++) {       if (vec[i] == 4 || vec[i] == 7)         flag = 1;       else {         flag = 0;         break;       }     }     if (flag)       cout <<  YES ;     else if (y % 7 == 0 || y % 4 == 0 || y == 799 || y == 94 || y == 141)       cout <<  YES ;     else       cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MAXN = 1e6 + 100;   const long long MAXL = 21;   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long x, r, l;     cin >> x >> l >> r;     long long ans = 0;     long long a = 1;     while (2 * a <= x) a = 2 * a;     for (long long i = l; i <= r; i++) ans += bool(x & (a / (i & -i)));     cout << ans;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:16777216 )   #pragma warning(disable : 4786)   using namespace std;   int MIN(int a, int b) { return a < b ? a : b; }   int MAX(int a, int b) { return a > b ? a : b; }   int GCD(int a, int b) {     while (b) b ^= a ^= b ^= a %= b;     return a;   }   int LCM(int a, int b) { return a * (b / GCD(a, b)); }   void SWAP(int &a, int &b) {     a = a ^ b;     b = a ^ b;     a = a ^ b;   }   const double PI = acos(-1);   const double EPS = 1e-11;   int arr[310][310], memo[310][310][310], N, M;   int dp(int i, int j, int k) {     int l = i + j - k;     if (i == N - 1 && j == M - 1) {       return arr[i][j];     }     if (i == N || j == M || k >= N || l >= N) {       return -(1 << 29);       ;     }     int &ret = memo[i][j][k];     if (ret != -1) {       return ret;     }     int res, r1, val;     res = -(1 << 29);     ;     if (i == k && j == l) {       val = arr[i][j];     } else {       val = arr[i][j] + arr[k][l];     }     r1 = dp(i + 1, j, k + 1) + val;     res = MAX(res, r1);     r1 = dp(i + 1, j, k) + val;     res = MAX(res, r1);     r1 = dp(i, j + 1, k + 1) + val;     res = MAX(res, r1);     r1 = dp(i, j + 1, k) + val;     res = MAX(res, r1);     return ret = res;   }   int main() {     int T, res, n, i, ind, m, j;     while (scanf( %d , &n) != EOF) {       int a = -(1 << 29);       ;       memset(memo, -1, sizeof(memo));       memset(arr, 0, sizeof(arr));       m = n;       for (i = 0; i < (n); i++) {         for (j = 0; j < (m); j++) {           scanf( %d , &arr[i][j]);         }       }       N = n;       M = m;       res = dp(0, 0, 0);       printf( %d n , res);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int Mod = 1e9 + 7;   const int N = 1e3 + 100;   const int M = 3e4 + 100;   const int INF = 0x3f3f3f3f;   const long long LINF = 0x3f3f3f3f3f3f3f3f;   inline long long dpow(long long a, long long b) {     long long r = 1, t = a;     while (b) {       if (b & 1) r = (r * t) % Mod;       b >>= 1;       t = (t * t) % Mod;     }     return r;   }   inline long long fpow(long long a, long long b) {     long long r = 1, t = a;     while (b) {       if (b & 1) r = (r * t);       b >>= 1;       t = (t * t);     }     return r;   }   vector<pair<int, int> > G[N << 1];   vector<int> g;   int dfn[N], low[N], n, m, cnt;   int val[M], sp, tp;   int edge[M], res;   bool vis[N], cut[M];   int ID[5], ans;   bool path(int x) {     if (x == tp) return true;     vis[x] = true;     for (auto it : G[x]) {       int v = it.first, id = it.second;       if (!vis[v] && path(v)) {         edge[++res] = id;         return true;       }     }     return false;   }   bool dfs(int x, int no) {     if (x == tp) return true;     vis[x] = true;     for (auto it : G[x]) {       int v = it.first;       int id = it.second;       if (id != no && !vis[v] && dfs(v, no)) {         g.push_back(id);         return true;       }     }     return false;   }   void tarjan(int x, int fa, int no) {     dfn[x] = low[x] = ++cnt;     for (auto it : G[x]) {       int v = it.first, id = it.second;       if (id == fa || id == no) continue;       if (!dfn[v]) {         tarjan(v, id, no);         low[x] = min(low[x], low[v]);         if (low[v] > dfn[x]) cut[id] = true;       } else         low[x] = min(low[x], dfn[v]);     }   }   int main() {     cin >> n >> m >> sp >> tp;     for (int i = 1; i <= m; i++) {       int u, v;       scanf( %d %d %d , &u, &v, &val[i]);       G[u].push_back({v, i});       G[v].push_back({u, i});     }     if (!path(sp)) printf( 0 n0 n ), exit(0);     ans = INT_MAX;     for (int i = 1; i <= res; i++) {       int ii = edge[i];       memset(vis, 0, sizeof(vis)), g.clear();       if (!dfs(sp, ii)) {         if (val[ii] < ans) ans = val[ii], ID[1] = ii, ID[2] = 0;       } else {         cnt = 0;         memset(dfn, 0, sizeof(dfn)), memset(low, 0, sizeof(low));         memset(cut, 0, sizeof(cut));         for (int j = 1; j <= n; j++) {           if (!dfn[j]) tarjan(j, 0, ii);         }         for (auto it : g) {           if (cut[it] && val[it] + val[ii] < ans)             ans = val[it] + val[ii], ID[1] = ii, ID[2] = it;         }       }     }     if (ans == INT_MAX)       printf( -1 n );     else {       printf( %d n , ans);       if (!ID[2])         printf( 1 n%d n , ID[1]);       else         printf( 2 n%d %d n , ID[1], ID[2]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int n, p, k;   long long int cost[200010];   long long int price() {     long long int dp[200010] = {0};     sort(cost, cost + n);     long long int ans = 0;     for (long long int i = 0; i < n; i++) {       if (i < k - 1) {         dp[i] = cost[i] + (i == 0 ? 0 : dp[i - 1]);       } else if (i == k - 1) {         dp[i] = cost[i];       } else {         dp[i] = dp[i - k] + cost[i];       }       if (dp[i] <= p) ans = i + 1;     }     return ans;   }   int main() {     int t;     cin >> t;     while (t--) {       cin >> n >> p >> k;       for (int i = 0; i < n; i++) {         cin >> cost[i];       };       cout << price() << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int ans;   int visited[1001];   int cc = 0;   vector<int> arr[1001];   void dfs(int node) {     visited[node]++;     if (visited[node] == 2) {       ans = node;       return;     }     for (auto child : arr[node]) {       if (visited[node] < 2) dfs(child);     }   }   int main() {     int n, v, a, b;     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a;       arr[i].push_back(a);     }     for (int i = 1; i <= n; i++) {       memset(visited, 0, sizeof(visited));       dfs(i);       cout << ans <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long MOD = 1e9 + 7;   long long pow(long long x, long long v) {     if (v == 0) return 1LL;     if (v % 2) return (x % MOD) * pow(x % MOD, v - 1) % MOD;     return pow((x * x) % MOD, v / 2) % MOD;   }   int main() {     int n;     long long x, sum = 0, v, mx = 0;     scanf( %d%lld , &n, &x);     map<long long, int> cnt;     vector<long long> a(n);     for (int i = 0; i < n; ++i)       scanf( %lld , &a[i]), sum += a[i], mx = max(mx, a[i]);     for (int i = 0; i < n; ++i) cnt[sum - a[i]]++;     for (map<long long, int>::iterator it = cnt.begin(); it != cnt.end(); ++it) {       v = it->first;       if (it->second % x == 0) {         cnt[v + 1] += it->second / x;       } else         break;     }     v = min(v, sum);     printf( %lld , pow(x, v));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t, n;     cin >> t;     while (t--) {       cin >> n;       vector<int> numbers(n);       vector<int> trayectoria(n + 1);       for (int &i : numbers) cin >> i;       if (numbers[0] == 1) {         cout << n + 1 <<    ;         for (int i = 1; i < n + 1; i++) cout << i <<    ;         cout <<   n ;       } else if (numbers[n - 1] == 0) {         for (int i = 1; i < n; i++) cout << i <<    ;         cout << n <<     << n + 1 <<    ;         cout <<   n ;       } else {         bool poss = false;         for (int i = 0; i < n; i++) {           if (i < n - 1 && numbers[i] < numbers[i + 1]) {             for (int j = 0; j < i; j++) cout << j + 1 <<    ;             cout << i + 1 <<     << n + 1 <<    ;             for (int j = i + 1; j < n; j++) cout << j + 1 <<    ;             cout << endl;             poss = true;             break;           }         }         if (!poss) cout <<  -1 n ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, c;     while (cin >> a >> b) {       if (a == 0 && b == 0)         cout <<  NO  << endl;       else {         c = abs(a - b);         if (c == 0 || c == 1)           cout <<  YES  << endl;         else           cout <<  NO  << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 10;   const int inf = 0x3f3f3f3f;   const int mod = 1e9 + 7;   int n, m, k, t, mx, mi, x, y, dx, dy, idx, cnt, tot, sum, res, flag, st;   vector<int> e[maxn];   void dfs(int u, int pre, int dep, int op) {     if (dep > mx) {       mx = dep;       idx = u;     }     if (u == y && op) {       if (dep <= dx) {         flag = 1;         return;       }     }     for (int v : e[u]) {       if (v == pre) continue;       dfs(v, u, dep + 1, op);     }   }   int main() {     scanf( %d , &t);     while (t--) {       flag = 0;       scanf( %d %d %d %d %d , &n, &x, &y, &dx, &dy);       for (int i = 1; i <= n; i++) {         e[i].clear();       }       for (int i = 1; i < n; i++) {         int u, v;         scanf( %d %d , &u, &v);         e[u].push_back(v);         e[v].push_back(u);       }       mx = 0;       dfs(x, 0, 0, 1);       if (flag) {         puts( Alice );         continue;       }       mx = 0;       dfs(idx, 0, 0, 0);       if (2 * dx >= mx || dy <= 2 * dx) {         puts( Alice );       } else {         puts( Bob );       }     }     return 0;   }


#include <bits/stdc++.h>   int n;   int length;   int num[1000];   int main() {     scanf( %d , &n);     while (n--) {       int max = 0;       int mark = 0;       scanf( %d , &length);       for (int i = 1; i <= length; i++) {         scanf( %d , &num[i]);         if (num[i] > (i + mark)) {           mark += num[i] - i - mark;         }       }       printf( %d n , mark);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   void read(T &x) {     x = 0;     bool f = 0;     char c = getchar();     for (; !isdigit(c); c = getchar())       if (c ==  - ) f = 1;     for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48);     if (f) x = -x;   }   template <typename F>   inline void write(F x, char ed =   n ) {     static short st[30];     short tp = 0;     if (x < 0) putchar( - ), x = -x;     do st[++tp] = x % 10, x /= 10;     while (x);     while (tp) putchar( 0  | st[tp--]);     putchar(ed);   }   template <typename T>   inline void write(T *st, int n, string s =   ) {     if (s.size()) cout << s <<  :  ;     while (n--) write(*st++,    );     puts(  );   }   const int N = 200050;   const int P = 1e9 + 7;   long long len[N], p[N], sum[N], ans;   int L[N], R[N], n;   long long fpw(long long x, long long mi, long long res = 1) {     for (; mi; mi >>= 1, x = x * x % P)       if (mi & 1) res = res * x % P;     return res;   }   int main() {     read(n);     for (int i = 1; i <= n; ++i) read(L[i]);     for (int i = 1; i <= n; ++i) read(R[i]), len[i] = R[i] - L[i] + 1;     long long ans = p[0] = 1;     len[0] = 1;     sum[0] = 1;     for (int i = 1; i < n; ++i) {       p[i] = max(0, min(R[i], R[i + 1]) - max(L[i], L[i + 1]) + 1);       p[i] = p[i] * fpw(len[i] * len[i + 1] % P, P - 2) % P,       p[i] = (P + 1 - p[i]) % P;       ans = (ans + p[i] + (i > 1 ? 2 * p[i] * sum[i - 2] : 0)) % P,       sum[i] = (sum[i - 1] + p[i]) % P;       int tr = min(min(R[i], R[i + 1]), R[i - 1]),           tl = max(max(L[i], L[i + 1]), L[i - 1]);       int t = max(tr - tl + 1, 0) *               fpw(len[i - 1] * len[i] % P * len[i + 1] % P, P - 2) % P;       t = (1ll - (1 - p[i - 1] + 1 - p[i]) + t) % P;       ans = (ans + 2 * t) % P;     }     write((ans % P + P) % P);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     if (s.size() == 1 &&         (s[0] ==  A  || s[0] ==  I  || s[0] ==  M  || s[0] ==  O  ||          s[0] ==  T  || s[0] ==  U  || s[0] ==  V  || s[0] ==  W  ||          s[0] ==  X  || s[0] ==  Y  || s[0] ==  H )) {       cout <<  YES ;       return 0;     }     for (int i = 0; i < s.size() / 2; i++)       if (s[i] == s[s.size() - 1 - i] &&           (s[i] ==  A  || s[i] ==  I  || s[i] ==  M  || s[i] ==  O  ||            s[i] ==  T  || s[i] ==  U  || s[i] ==  V  || s[i] ==  W  ||            s[i] ==  X  || s[i] ==  Y  || s[i] ==  H ))         continue;       else {         cout <<  NO ;         return 0;       }     if (s.size() % 2 == 1) {       if (s[s.size() / 2] ==  B ) {         cout <<  NO ;         return 0;       }       if (s[s.size() / 2] ==  C ) {         cout <<  NO ;         return 0;       }       if (s[s.size() / 2] ==  D ) {         cout <<  NO ;         return 0;       }       if (s[s.size() / 2] ==  E ) {         cout <<  NO ;         return 0;       }       if (s[s.size() / 2] ==  F ) {         cout <<  NO ;         return 0;       }       if (s[s.size() / 2] ==  G ) {         cout <<  NO ;         return 0;       }       if (s[s.size() / 2] ==  J ) {         cout <<  NO ;         return 0;       }       if (s[s.size() / 2] ==  K ) {         cout <<  NO ;         return 0;       }       if (s[s.size() / 2] ==  L ) {         cout <<  NO ;         return 0;       }       if (s[s.size() / 2] ==  P ) {         cout <<  NO ;         return 0;       }       if (s[s.size() / 2] ==  N ) {         cout <<  NO ;         return 0;       }       if (s[s.size() / 2] ==  Q ) {         cout <<  NO ;         return 0;       }       if (s[s.size() / 2] ==  R ) {         cout <<  NO ;         return 0;       }       if (s[s.size() / 2] ==  S ) {         cout <<  NO ;         return 0;       }       if (s[s.size() / 2] ==  Z ) {         cout <<  NO ;         return 0;       }     }     cout <<  YES ;   }


#include <bits/stdc++.h>   struct MinCostFlow {     const long long INF1 = 1000000000LL;     const long long INF2 = 100000000LL;     struct edge {       long long u, v;       long long cap, cost;       edge* rev;       edge(const long long& uu, const long long& vv, const long long& _cap,            const long long& _cost, edge* _rev = nullptr)           : u(uu), v(vv), cap(_cap), cost(_cost), rev(_rev) {}     };     struct node {       long long id, d;       node(const long long& _id, const long long& _d) : id(_id), d(_d) {}       bool operator<(const node& o) const { return d < o.d; }       bool operator>(const node& o) const { return d > o.d; }     };     std::vector<std::vector<edge*>> adj;     long long s, t, mS, mT;     std::vector<edge*> prev;     std::vector<long long> w, pi;     MinCostFlow(long long n) {       s = n++;       t = n++;       mS = n++;       mT = n++;       adj.assign(n, std::vector<edge*>());     }     ~MinCostFlow(void) {       for (auto& row : adj)         for (auto& e : row) delete e;     }     edge* add_edge(const long long& a, const long long& b, const long long& cap,                    const long long& cost) {       edge* e1 = new edge(a, b, cap, cost);       edge* e2 = new edge(b, a, 0, -cost);       e1->rev = e2;       e2->rev = e1;       adj[a].push_back(e1);       adj[b].push_back(e2);       return e1;     }     std::pair<long long, long long> min_cost_max_flow(void) {       long long flow = 0;       long long cost = 0;       get_potential();       while (find_path()) {         flow += w[t];         cost += update();       }       return {flow, cost};     }     void get_potential(void) {       pi.assign(adj.size(), INF1);       pi[s] = 0;       for (long long i = 0; i + 1 < adj.size(); ++i) {         bool upd = false;         for (long long j = 0; j < adj.size(); ++j) {           for (edge* e : adj[j]) {             if (e->cap > 0 && pi[e->v] > pi[e->u] + e->cost) {               pi[e->v] = pi[e->u] + e->cost;               upd = true;             }           }         }         if (!upd) break;       }     }     bool find_path(void) {       std::vector<long long> d(adj.size(), INF1);       d[s] = 0;       prev.assign(adj.size(), nullptr);       w.assign(adj.size(), INF1);       std::priority_queue<node, std::vector<node>, std::greater<node>> pq;       pq.push({s, 0});       while (!pq.empty()) {         node best = pq.top();         pq.pop();         if (best.d != d[best.id]) continue;         for (edge* e : adj[best.id]) {           long long nd = d[best.id] + e->cost + pi[e->u] - pi[e->v];           if (e->cap > 0 && d[e->v] > nd) {             d[e->v] = nd;             prev[e->v] = e;             w[e->v] = std::min(w[best.id], e->cap);             pq.push({e->v, nd});           }         }       }       for (long long i = 0; i < pi.size(); ++i) pi[i] += d[i];       return d[t] < INF1;     }     long long update(void) {       long long v = t;       long long curr = 0;       while (prev[v] != nullptr) {         prev[v]->cap -= w[t];         prev[v]->rev->cap += w[t];         curr += w[t] * prev[v]->cost;         v = prev[v]->u;       }       return curr;     }   };   int main(void) {     std::ios::sync_with_stdio(false);     std::cin.tie(nullptr);     long long n, q;     std::cin >> n >> q;     std::vector<std::vector<char>> adj_mat(n, std::vector<char>(n, true));     for (long long type, l, r, v; q > 0; --q) {       std::cin >> type >> l >> r >> v;       --l;       --r;       --v;       if (type == 1) {         for (long long i = 0; i < v; ++i) {           for (long long j = l; j <= r; ++j) adj_mat[i][j] = false;         }       } else {         for (long long i = v + 1; i < n; ++i) {           for (long long j = l; j <= r; ++j) adj_mat[i][j] = false;         }       }     }     MinCostFlow graph(n + n);     for (long long num = 0; num < n; ++num) {       for (long long quant = 1, last = 0; quant <= n;            last = quant * quant, quant++) {         graph.add_edge(graph.s, num, 1, quant * quant - last);       }     }     for (long long spot = n; spot < 2 * n; ++spot)       graph.add_edge(spot, graph.t, 1, 0);     for (long long i = 0; i < n; ++i) {       for (long long j = 0; j < n; ++j) {         if (adj_mat[i][j]) graph.add_edge(i, n + j, 1, 0);       }     }     const std::pair<long long, long long> ret = graph.min_cost_max_flow();     if (ret.first != n) {       std::cout <<  -1 n ;     } else {       std::cout << ret.second <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   int n, m;   const int maxN = 42;   vector<int> g[maxN];   int deg[maxN];   bool ed[maxN][maxN];   long long f() { return (1LL << n); }   const int maxK = 20;   bool bad[(1 << maxK) + 10];   int from[(1 << maxK) + 10];   bool other_bad[(1 << maxK) + 10];   int cnt[(1 << maxK) + 10];   long long indep() {     int half = n / 2;     for (int i = 0; i < half; i++) {       for (int j = i + 1; j < half; j++) {         if (ed[i][j]) {           bad[(1 << i) + (1 << j)] = true;         }       }       for (int j = half; j < n; j++) {         if (ed[i][j]) {           from[(1 << i)] |= (1 << (j - half));         }       }     }     for (int bit = 0; bit < half; bit++) {       for (int mask = 0; mask < (1 << half); mask++) {         if (mask & (1 << bit)) {           bad[mask] |= bad[mask ^ (1 << bit)];           from[mask] |= from[mask ^ (1 << bit)];         }       }     }     int other_half = n - half;     for (int i = half; i < n; i++) {       for (int j = i + 1; j < n; j++) {         if (ed[i][j]) {           other_bad[(1 << (i - half)) + (1 << (j - half))] = true;         }       }     }     for (int bit = 0; bit < other_half; bit++) {       for (int mask = 0; mask < (1 << other_half); mask++) {         if (mask & (1 << bit)) {           other_bad[mask] |= other_bad[mask ^ (1 << bit)];         }       }     }     for (int mask = 0; mask < (1 << other_half); mask++) {       if (!other_bad[mask]) cnt[mask] = 1;     }     for (int bit = 0; bit < other_half; bit++) {       for (int mask = 0; mask < (1 << other_half); mask++) {         if (mask & (1 << bit)) {           cnt[mask] += cnt[mask ^ (1 << bit)];         }       }     }     int all = (1 << other_half) - 1;     long long tot = 0;     for (int my_mask = 0; my_mask < (1 << half); my_mask++) {       if (bad[my_mask]) continue;       int bad_guys = from[my_mask];       int good_guys = all ^ bad_guys;       tot += cnt[good_guys];     }     return tot;   }   bool used[maxN];   void dfs(int v) {     used[v] = true;     for (int to : g[v]) {       if (used[to]) continue;       dfs(to);     }   }   long long ones() {     int tot = 0;     memset(used, 0, sizeof used);     for (int i = 0; i < n; i++) {       if (!used[i]) {         dfs(i);         tot++;       }     }     return (1LL << tot);   }   long long f01() {     int tot = 0;     for (int i = 0; i < n; i++)       if (deg[i] == 0) tot++;     return (1LL << tot);   }   int clr[maxN];   bool ALL_OK = true;   void other_dfs(int v) {     used[v] = true;     for (int to : g[v]) {       if (used[to]) {         if (clr[to] != clr[v] ^ 1) {           ALL_OK = false;           return;         }       } else {         clr[to] = clr[v] ^ 1;         other_dfs(to);       }     }   }   long long f02() {     int tot = 0;     memset(used, 0, sizeof used);     for (int i = 0; i < n; i++) {       if (!used[i]) {         tot++;         other_dfs(i);       }     }     if (!ALL_OK) return 0;     return (1LL << tot);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cin >> n >> m;     if (m == 0) {       cout << 0;       return 0;     }     for (int i = 0; i < m; i++) {       int a, b;       cin >> a >> b;       a--;       b--;       deg[a]++;       deg[b]++;       g[a].push_back(b);       g[b].push_back(a);       ed[a][b] = ed[b][a] = true;     }     long long x = f();     long long y = indep();     long long z = ones();     long long t = f01();     long long q = f02();     cout << x - 2 * y - z + 2 * t + q;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long inf = (long long)3e18;   struct data {     long long x, flag, id;     int operator<(const data& d) const { return x < d.x; }   } d[200010 << 2];   long long dp[200010 << 2][2], c[200010 << 2], s[200010 << 2], v[200010 << 2],       nw, ans;   long long _s[200010 << 2], n, np, m, C, tp, pre;   bool is2[200010 << 2];   struct zkw {     long long zkwm, s[2100000], atg[2100000];     void init(int len) {       zkwm = 1;       while (zkwm <= len + 2) zkwm <<= 1;       for (int i = 1; i <= zkwm + zkwm; ++i) s[i] = -inf;     }     long long query(int l, int r) {       if (l > r || r <= 0 || l > np) return -inf;       l = max(l, 1), r = min((long long)r, np);       long long lans = -inf, rans = -inf;       for (l += zkwm - 1 - 1, r += zkwm + 1 - 1; l ^ r ^ 1; l >>= 1, r >>= 1) {         if (lans != -inf) lans += atg[l];         if (rans != -inf) rans += atg[r];         if (~l & 1) lans = max(lans, s[l ^ 1]);         if (r & 1) rans = max(rans, s[r ^ 1]);       }       if (lans != -inf) lans += atg[l];       if (rans != -inf) rans += atg[r];       lans = max(lans, rans);       if (lans != -inf)         for (l >>= 1; l; l >>= 1) lans += atg[l];       return lans;     }     void mdy(int l, int r, long long a) {       if (l > r || r <= 0 || l > np) return;       l = max(l, 1), r = min((long long)r, np);       int f = 0;       for (l += zkwm - 1 - 1, r += zkwm + 1 - 1; l ^ r ^ 1;            l >>= 1, r >>= 1, f = 1) {         if (~l & 1) atg[l ^ 1] += a, s[l ^ 1] += a;         if (r & 1) atg[r ^ 1] += a, s[r ^ 1] += a;         if (f)           s[l] = max(s[l << 1], s[l << 1 | 1]) + atg[l],           s[r] = max(s[r << 1], s[r << 1 | 1]) + atg[r];       }       s[l] = max(s[l << 1], s[l << 1 | 1]) + atg[l],       s[r] = max(s[r << 1], s[r << 1 | 1]) + atg[r];       for (l >>= 1; l; l >>= 1) s[l] = max(s[l << 1], s[l << 1 | 1]) + atg[l];     }     void _mdy(int l, long long a) {       l += zkwm - 1;       atg[l] = 0;       for (int _l = l >> 1; _l; _l >>= 1) a -= atg[_l];       if (s[l] < a)         s[l] = a;       else         return;       for (l >>= 1; l; l >>= 1) s[l] = max(s[l << 1], s[l << 1 | 1]) + atg[l];     }   } A[4];   int main() {     scanf( %lld%lld%lld , &n, &m, &C);     for (long long i = 1, L, R; i <= n; ++i)       scanf( %lld%lld , &L, &R), d[++tp] = data{L, 1ll, 0ll},                                  d[++tp] = data{R, -1ll, 0ll};     for (long long i = 1, L, R; i <= m; ++i)       scanf( %lld%lld , &L, &R), d[++tp] = data{L, 1ll, 1ll},                                  d[++tp] = data{R, -1ll, 1ll};     sort(d + 1, d + tp + 1);     int tg = 0, ch = 0;     for (int i = 1; i <= tp; ++i) {       if (i > 1) {         long long x = d[i].x - d[i - 1].x;         if (tg == 2)           v[i] = x, s[i] = 0, is2[i - 1] = true;         else if (tg == 1)           v[i] = (ch == 0 ? 1 : 0) * x, s[i] = (ch == 0 ? 1 : -1) * x;         else           v[i] = s[i] = 0;         s[i] += s[i - 1], c[i] = v[i] + c[i - 1];       }       if (d[i].flag > 0)         tg++, ch = d[i].id;       else if (d[i].flag < 0)         tg--, ch = 1 - d[i].id;       _s[i] = s[i];     }     sort(_s + 1, _s + tp + 1);     np = unique(_s + 1, _s + tp + 1) - _s - 1;     for (int i = 0; i < 4; ++i) A[i].init(np);     for (int i = 0; i <= tp + 1; ++i) dp[i][0] = dp[i][1] = -inf;     for (int i = 1; i < tp; ++i) {       if (is2[i]) {         if (s[i] >= C)           dp[i][0] = max(dp[i][0], pre - s[i] + C + v[i + 1] * 2);         else if (s[i] <= -C)           dp[i][1] = max(dp[i][1], pre + v[i + 1] * 2);       }       if (abs(nw) <= C && is2[i])         pre += v[i + 1] * 2;       else         pre += v[i + 1], nw += s[i + 1] - s[i];       if (!is2[i]) continue;       dp[i][0] =           max(dp[i][0],               A[0].query(1, upper_bound(_s + 1, _s + np + 1, s[i]) - _s - 1) +                   c[i + 1] - s[i] + v[i + 1]);       dp[i][1] = max(           dp[i][1],           A[1].query(lower_bound(_s + 1, _s + np + 1, s[i] + 2 * C) - _s, np) +               c[i + 1] + v[i + 1]);       dp[i][0] = max(           dp[i][0],           A[2].query(1, upper_bound(_s + 1, _s + np + 1, s[i] - 2 * C) - _s - 1) -               s[i] + v[i + 1] + c[i + 1] + 2 * C);       dp[i][1] = max(dp[i][1],                      A[3].query(lower_bound(_s + 1, _s + np + 1, s[i]) - _s, np) +                          c[i + 1] + v[i + 1]);       int l = lower_bound(_s + 1, _s + np + 1, s[i]) - _s,           r = upper_bound(_s + 1, _s + np + 1, s[i] + 2 * C) - _s - 1;       if (A[0].s[1] >= (long long)(-2e18)) A[0].mdy(l, r, v[i + 1]);       if (A[1].s[1] >= (long long)(-2e18)) A[1].mdy(l, r, v[i + 1]);       l = lower_bound(_s + 1, _s + np + 1, s[i] - 2 * C) - _s,       r = upper_bound(_s + 1, _s + np + 1, s[i]) - _s - 1;       if (A[2].s[1] >= (long long)(-2e18)) A[2].mdy(l, r, v[i + 1]);       if (A[3].s[1] >= (long long)(-2e18)) A[3].mdy(l, r, v[i + 1]);       int x = lower_bound(_s + 1, _s + np + 1, s[i + 1]) - _s;       if (dp[i][0] >= 0)         A[0]._mdy(x, dp[i][0] + s[i + 1] - c[i + 1]),             A[1]._mdy(x, dp[i][0] - c[i + 1]);       if (dp[i][1] >= 0)         A[2]._mdy(x, dp[i][1] + s[i + 1] - c[i + 1]),             A[3]._mdy(x, dp[i][1] - c[i + 1]);     }     ans = max(ans, pre);     ans = max(ans, A[1].query(1, np) + c[tp]);     ans = max(ans, A[3].query(1, np) + c[tp]);     printf( %lld , ans);   }


#include <bits/stdc++.h>   using namespace std;   const long long maxn = 500002;   const long long mod = 1000000000;   const long double eps = 1e-9;   const long long inf = ((1ll << 31ll) - 1ll);   const long long INF = 2000000000000000000ll;   const long double pi = acos(-1);   long long qpow(long long b, long long e) {     if (!e) return 1;     if (e & 1) return qpow(b, e - 1) * b;     long long pwur = qpow(b, e >> 1);     return pwur * pwur;   }   long long modinv(long long x) { return qpow(x, mod - 2); }   long long n, a[maxn], lst, psum[maxn], ssum[maxn];   bool try_(long long id) {     long long sw = 0;     for (long long i = id; i <= n; i++) {       if (psum[i] <= psum[i - id]) return false;     }     return true;   }   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.setf(ios::fixed);     cout.precision(0);     srand(time(NULL));     cin >> n;     for (long long i = 1; i <= (n + 1) / 2; i++) {       cin >> a[i];     }     cin >> lst;     for (long long i = (n + 1) / 2 + 1; i <= n; i++) {       a[i] = lst;     }     for (long long i = 1; i <= n; i++) psum[i] = psum[i - 1] + a[i];     for (long long i = n; i >= 1; i--) ssum[i] = ssum[i + 1] + a[i];     if (lst >= 0) {       if (try_(n))         cout << n <<   n ;       else         cout << -1 <<   n ;       return 0;     }     long long cnt = 0;     for (long long i = 1; i <= n; i++) {       if ((psum[i] > 0 && ssum[n - i + 1] > 0) && (i >= (n + 1) / 2)) {         if (try_(i)) {           cout << i <<   n ;           return 0;         } else {           cnt++;         }       }     }     cout << -1 <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline long long read() {     register char ch;     while (!isdigit(ch = getchar()))       ;     register long long x = ch ^  0 ;     while (isdigit(ch = getchar())) x = (((x << 2) + x) << 1) + (ch ^  0 );     return x;   }   vector<pair<long long, long long> > e[200005];   long long n, m, q, a[200005], b[200005], c[200005], sum[200005 << 2],       lzy[200005 << 2];   void build(long long o, long long l, long long r, long long p[]) {     lzy[o] = 0;     if (l == r) {       sum[o] = p[l];       return;     }     long long mid = l + r >> 1;     build(o << 1, l, mid, p);     build(o << 1 | 1, mid + 1, r, p);     sum[o] = min(sum[o << 1], sum[o << 1 | 1]);   }   void pushdown(long long o) {     sum[o << 1] += lzy[o];     sum[o << 1 | 1] += lzy[o];     lzy[o << 1] += lzy[o];     lzy[o << 1 | 1] += lzy[o];     lzy[o] = 0;   }   void updata(long long o, long long l, long long r, long long L, long long R,               long long val) {     if (L == l && r == R) {       sum[o] += val;       lzy[o] += val;       return;     }     if (lzy[o]) pushdown(o);     long long mid = l + r >> 1;     if (L <= mid) updata(o << 1, l, mid, L, min(mid, R), val);     if (R > mid) updata(o << 1 | 1, mid + 1, r, max(mid + 1, L), R, val);     sum[o] = min(sum[o << 1], sum[o << 1 | 1]);   }   signed main() {     n = read();     m = read();     q = read();     for (long long i = 1; i < n; ++i) {       a[i] = read();       b[i + 1] = read();     }     build(1, 1, n, b);     for (long long i = 1; i <= m; ++i) {       long long u, v, w;       u = read();       v = read();       w = read();       e[u].push_back(make_pair(v, w));     }     for (long long i = 1; i <= n; ++i) {       for (long long j = 0; j < e[i].size(); ++j) {         long long v = e[i][j].first, w = e[i][j].second;         updata(1, 1, n, 1, v, w);       }       c[i] = sum[1] + a[i];     }     build(1, 1, n, c);     printf( %lld n , sum[1]);     while (q--) {       long long x, y;       x = read();       y = read();       updata(1, 1, n, x, x, y - a[x]);       a[x] = y;       printf( %lld n , sum[1]);     }     return 0;   }


#include <bits/stdc++.h>   const int t = 50;   int f[t][t][t], g[t][t];   long long p[t];   int cnt;   void mul(int c[t][t], int a[t][t], int b[t][t], int n) {     int d[t][t];     memset(d, 0, sizeof d);     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++)         for (int k = 0; k < n; k++) d[i][k] ^= a[i][j] & b[j][k];     memcpy(c, d, sizeof d);   }   bool quick(long long m, int n) {     int i, j, k, res[t], ans[t];     for (i = 0; i < n; i++) ans[i] = 1;     for (i = 0; m; m >>= 1, i++)       if (m & 1) {         memset(res, 0, sizeof res);         for (j = 0; j < n; j++)           for (k = 0; k < n; k++) res[k] ^= ans[j] & f[i][j][k];         memcpy(ans, res, sizeof ans);       }     for (i = 0; i < n && ans[i]; i++)       ;     return i == n;   }   bool checker(long long m, int n) {     if (!quick(m, n)) return false;     for (int i = 0; i < cnt; i++)       if (quick(p[i], n)) return false;     return true;   }   int main() {     int ans, i, j, n;     long long s, m;     srand(0x51ac);     scanf( %d , &n);     m = s = (1ll << n) - 1;     for (cnt = 0, i = 2; i * (long long)i <= s; i++)       if (s % i == 0) {         p[cnt++] = m / i;         for (; s % i == 0; s /= i)           ;       }     if (s != 1) p[cnt++] = m / s;     do {       memset(f, 0, sizeof f);       for (i = 1; i < n; i++) f[0][i][i - 1] = 1;       for (f[0][0][n - 1] = i = 1; i < n; i++, j >>= 1)         f[0][i][n - 1] = rand() & 1;       for (i = 1; i < n; i++) mul(f[i], f[i - 1], f[i - 1], n);     } while (!checker(m, n));     for (i = 0; i < n; i++) printf( %d  , f[0][n - 1 - i][n - 1]);     for (puts(  ), i = 0; i < n; i++) printf( 1  );     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx )   using namespace std;   namespace SimplexMethod {   const long double EPS = 1.0E-12;   vector<vector<long double>> a;   vector<long double> b, c, res;   vector<int> N, kt;   int m;   void pivot(int k, int s, int e) {     int first = kt[s];     long double p = a[s][e];     for (int _n((k)-1), i(0); i <= _n; i++) a[s][i] /= p;     b[s] /= p;     N[e] = false;     for (int _n((m)-1), i(0); i <= _n; i++)       if (i != s) {         b[i] -= a[i][e] * b[s];         a[i][first] = -a[i][e] * a[s][first];       }     for (int _n((k)-1), j(0); j <= _n; j++)       if (N[j]) {         c[j] -= c[e] * a[s][j];         for (int _n((m)-1), i(0); i <= _n; i++)           if (i != s) a[i][j] -= a[i][e] * a[s][j];       }     kt[s] = e;     N[first] = true;     c[first] = -c[e] * a[s][first];   }   vector<long double> doit(int k) {     vector<long double> res;     while (true) {       int e = -1, s = -1;       for (int _n((k)-1), i(0); i <= _n; i++)         if (N[i] && c[i] > EPS) {           e = i;           break;         }       if (e == -1) break;       for (int _n((m)-1), i(0); i <= _n; i++)         if (a[i][e] > EPS && (s == -1 || b[i] / a[i][e] < b[s] / a[s][e])) s = i;       if (s == -1) return vector<long double>();       pivot(k, s, e);     }     res.resize(k, 0);     for (int _n((m)-1), i(0); i <= _n; i++) res[kt[i]] = b[i];     return res;   }   void apply_rand(vector<long double>& a, const vector<int>& ind) {     for (int _n(((int)((a).size())) - 1), i(0); i <= _n; i++) {       if (i < ind[i]) {         swap(a[i], a[ind[i]]);       }     }   }   long double simplex(vector<vector<long double>> _A, vector<long double> _b,                       vector<long double> _c) {     vector<int> ind((int)((_A[0]).size()));     for (int _n(((int)((ind).size())) - 1), i(0); i <= _n; i++) {       ind[i] = i;     }     srand(std::chrono::duration_cast<std::chrono::nanoseconds>(               (std::chrono::high_resolution_clock::now().time_since_epoch()))               .count() +           time(0));     auto rgen = [](int n) -> unsigned {       return ((unsigned)(rand() << 15) + (unsigned)rand()) % n;     };     random_shuffle(ind.begin(), ind.end(), rgen);     for (int _n(((int)((_A).size())) - 1), i(0); i <= _n; i++) {       apply_rand(_A[i], ind);     }     apply_rand(_c, ind);     a = _A;     b = _b;     c = _c;     m = (int)((a).size());     int n = (int)((a[0]).size());     int k = n + m + 1;     c.resize(n + m);     kt.resize(m);     N = vector<int>(k, true);     for (int _n((m)-1), i(0); i <= _n; i++) {       a[i].resize(k);       a[i][n + i] = 1;       a[i][k - 1] = -1;       kt[i] = n + i;       N[kt[i]] = false;     }     int s = min_element((b).begin(), (b).end()) - b.begin();     if (b[s] < -EPS) {       c = vector<long double>(k, 0);       c[k - 1] = -1;       pivot(k, s, k - 1);       res = doit(k);       if (res[k - 1] > EPS) return -1e100;       for (int _n((m)-1), i(0); i <= _n; i++)         if (kt[i] == k - 1)           for (int _n((k - 1) - 1), j(0); j <= _n; j++)             if (N[j] && (a[i][j] < -EPS || EPS < a[i][j])) {               pivot(k, i, j);               break;             }       c = _c;       c.resize(k, 0);       for (int _n((m)-1), i(0); i <= _n; i++)         for (int _n((k)-1), j(0); j <= _n; j++)           if (N[j]) c[j] -= c[kt[i]] * a[i][j];     }     res = doit(k - 1);     if (!res.empty()) res.resize(n);     long double ans = 0.0;     for (int _n(((int)((res).size())) - 1), i(0); i <= _n; i++) {       ans += res[i] * _c[i];     }     return ans;   }   }  // namespace SimplexMethod   int d, n, m, k, p, q;   int main() {     scanf( %d%d%d , &n, &p, &q);     vector<long double> a, b, c;     a.resize(n);     b.resize(n);     c.resize(n);     vector<pair<int, int>> tp;     for (int _n((n)-1), i(0); i <= _n; i++) {       int first, second;       scanf( %d%d , &first, &second);       tp.push_back(make_pair(first, second));     }     for (int _n((n)-1), i(0); i <= _n; i++) {       int first = tp[i].first, second = tp[i].second;       a[i] = -first;       b[i] = -second;       c[i] = -1.0;     }     vector<vector<long double>> A;     A.push_back(a);     A.push_back(b);     vector<long double> B;     B.push_back(-p);     B.push_back(-q);     auto res = -SimplexMethod::simplex(A, B, c);     printf( %.12lf n , (double)res);   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 100000 + 10;   int n;   int main() {     scanf( %d , &n);     if (n <= 8) {       int a = 2;       int b = (n) / a;       int c = (n) % a;       for (int i = 1; i <= n;) {         if (c > 0) {           printf( %d  , c);           c--;           i++;         } else if (c == 0) {           for (int j = a - 1; j >= 0; j--) {             printf( %d  , i + j);           }           i += a;         }       }     } else {       int a;       for (a = 3; a <= 1000; a++) {         if (a * a > n) break;       }       a--;       int b = (n) / a;       int c = n % a;       for (int i = 1; i <= n;) {         if (c > 0) {           printf( %d  , c);           c--;           i++;         } else if (c == 0) {           for (int j = a - 1; j >= 0; j--) {             printf( %d  , i + j);           }           i += a;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 10;   int n;   int mxm[4 * maxn];   int get(int id, int L, int R, int l, int r, int x) {     if (l >= r) return -1;     if (L == l and R == r) {       if (mxm[id] < x) return -1;       if (L + 1 == R) return L;       int mid = (L + R) >> 1;       if (mxm[2 * id + 0] >= x) return get(2 * id + 0, L, mid, L, mid, x);       return get(2 * id + 1, mid, R, mid, R, x);     }     int mid = (L + R) >> 1;     int k = get(2 * id + 0, L, mid, l, min(mid, r), x);     if (k != -1) return k;     return get(2 * id + 1, mid, R, max(l, mid), r, x);   }   void change(int id, int L, int R, int idx, int x) {     if (L + 1 == R) {       mxm[id] = x;       return;     }     int mid = (L + R) >> 1;     if (idx < mid)       change(2 * id + 0, L, mid, idx, x);     else       change(2 * id + 1, mid, R, idx, x);     mxm[id] = max(mxm[2 * id + 0], mxm[2 * id + 1]);   }   long long fen[maxn];   void add(int x, int val) {     for (; x <= n; x += x & -x) fen[x] += val;   }   long long get(int x) {     long long ret = 0;     for (; x; x -= x & -x) ret += fen[x];     return ret;   }   long long get(int L, int R) { return get(R) - get(L - 1); }   int a[maxn];   int solve() {     int now = 1;     while (now < n) {       long long x = get(1, now - 1);       if (a[now] == x) return now;       x += a[now];       if (x > int(1e9)) return -1;       now = get(1, 1, n + 1, now + 1, n + 1, x);       if (now == -1) return now;     }     if (get(1, n - 1) == a[n]) return n;     return -1;   }   int main() {     ios_base::sync_with_stdio(false);     int q;     cin >> n >> q;     for (int i = 1; i <= n; i++) {       cin >> a[i];       add(i, a[i]);       change(1, 1, n + 1, i, a[i]);     }     for (int i = 1; i <= q; i++) {       int idx, x;       cin >> idx >> x;       add(idx, x - a[idx]);       a[idx] = x;       change(1, 1, n + 1, idx, a[idx]);       cout << solve() <<   n ;     }   }


#include <bits/stdc++.h>   char ch;   bool fs;   void re(int& x) {     while (ch = getchar(), ch < 33)       ;     if (ch ==  - )       fs = 1, x = 0;     else       fs = 0, x = ch - 48;     while (ch = getchar(), ch > 33) x = x * 10 + ch - 48;     if (fs) x = -x;   }   using namespace std;   pair<int, int> d[62];   int n;   int m, a[32], use[32][64][2048];   bool f[32][64][2048], edge[64][64];   int main() {     re(m);     for (int i = 1; i <= m; ++i) re(a[i]);     sort(a + 1, a + m + 1);     f[0][0][0] = 1;     for (int i = 1; i <= m; ++i)       for (int j = i; j <= 61; ++j)         for (int k = j * (j - 1) / 2; k <= 2000; ++k)           for (int l = 1; l <= j && l * a[i] <= k; ++l)             if (f[i - 1][j - l][k - l * a[i]]) {               f[i][j][k] = 1;               use[i][j][k] = l;               break;             }     for (int i = 1; i <= 61; ++i)       if (f[m][i][i * (i - 1) / 2]) {         printf( %d n , i);         int a = m, b = i, c = i * (i - 1) / 2;         while (a) {           int t = use[a][b][c];           for (int j = 1; j <= t; ++j) d[++n].first = ::a[a], d[n].second = n;           c -= t * ::a[a];           b -= t;           --a;         }         for (int j = 1; j <= n; ++j) {           sort(d + j, d + n + 1);           for (int k = j + 1; k <= j + d[j].first; ++k)             edge[d[j].second][d[k].second] = 1;           for (int k = j + d[j].first + 1; k <= n; ++k)             edge[d[k].second][d[j].second] = 1, --d[k].first;           d[j].first = 0;         }         for (int j = 1; j <= n; ++j, puts(  ))           for (int k = 1; k <= n; ++k) printf( %d , edge[j][k]);         return 0;       }     puts( -1 );   }


#include <bits/stdc++.h>   using namespace std;   string a;   int main() {     cin >> a;     cout << a;     reverse(a.begin(), a.end());     cout << a << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 100 + 7;   int n, k;   string second;   string s2;   string s1;   int main() {     cin >> n >> k;     cin >> second;     sort(second.begin(), second.end());     for (int i = 0; i < n; i++) {       if (second[i] != second[i + 1]) {         s2 += second[i];       }     }     second =   ;     second += s2;     sort(second.begin(), second.end());     for (int i = 0; i < second.size(); i++) {       s1 += second[i];       if (second[i] + 1 == second[i + 1] || second[i] == second[i + 1]) {         i++;       }     }     if (s1.size() >= k) {       int cnt = 0;       for (int i = 0; i < k; i++) {         cnt += s1[i] -  a  + 1;       }       cout << cnt;     } else {       cout << -1;     }   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 207;   int n, f[MAXN];   long long mmc_atual = 1;   vector<int> folhas, Gr[MAXN];   bool in_cycle[MAXN], mrk[MAXN];   int marca_ciclo(int u) {     if (in_cycle[u]) return 0;     in_cycle[u] = true;     return 1 + marca_ciclo(f[u]);   }   void dfsr(int u) {     mrk[u] = true;     bool flag = true;     for (int i = 0; i < (int)Gr[u].size(); i++) {       int viz = Gr[u][i];       flag = false;       if (mrk[viz]) continue;       dfsr(viz);     }     if (flag) folhas.push_back(u);   }   int dfs(int u) {     if (in_cycle[u]) return 0;     return 1 + dfs(f[u]);   }   long long mdc(long long a, long long b) { return (a == 0) ? b : mdc(b % a, a); }   long long mmc(long long a, long long b) { return (a / mdc(a, b)) * b; }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> f[i];       Gr[f[i]].push_back(i);     }     long long ans = 1;     long long mx_chain = 0;     for (int i = 1; i <= n; i++) {       if (!mrk[i]) {         int turtoise = i;         int hare = i;         do {           turtoise = f[turtoise];           hare = f[f[hare]];         } while (turtoise != hare);         int tam_ciclo = marca_ciclo(hare);         mmc_atual = mmc(mmc_atual, (long long)tam_ciclo);         dfsr(hare);       }     }     for (int i = 0; i < (int)folhas.size(); i++) {       int tam_chain = dfs(folhas[i]);       mx_chain = max(mx_chain, (long long)tam_chain);     }     if (mx_chain % mmc_atual != 0)       mx_chain = (mx_chain - mx_chain % mmc_atual) + mmc_atual;     ans = max(mmc_atual, mx_chain);     cout << ans << endl;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   #pragma GCC optimize( unroll-loops )   using namespace std;   using ll = long long;   using db = long double;   using ii = pair<int, int>;   const int N = 1e5 + 5, LG = 17, MOD = 998244353;   const int SQ = 225;   const long double EPS = 1e-7;   int n, m, a[N], b[N];   set<int> pos[N];   bool vis[N];   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n;     for (int i = 1; i < n + 1; i++) cin >> a[i];     cin >> m;     for (int i = 1; i < m + 1; i++) cin >> b[i];     sort(b + 1, b + m + 1);     vector<int> lis;     for (int i = 1; i < n + 1; i++) {       if (a[i] == -1) {         int p = lower_bound(lis.begin(), lis.end(), b[m]) - lis.begin();         if (p == lis.size()) lis.push_back(INT_MAX);         for (int j = m; j; --j) {           while (p > 0 && b[j] <= lis[p - 1]) --p;           lis[p] = min(lis[p], b[j]);         }       } else {         int p = lower_bound(lis.begin(), lis.end(), a[i]) - lis.begin();         if (p == lis.size()) lis.push_back(0);         lis[p] = a[i];         pos[p].insert(i);       }     }     int idx = n, prv = INT_MAX, ptr = m;     for (int i = lis.size() - 1; i >= 0; --i) {       auto it = pos[i].upper_bound(idx);       if (it != pos[i].begin()) {         --it;         if (a[*it] < prv) {           idx = *it;           prv = a[idx];           continue;         }       }       while (~a[idx]) --idx;       while (b[ptr] >= prv) --ptr;       prv = a[idx] = b[ptr];       vis[ptr] = true;     }     int tmp = 1;     for (int i = 1; i < n + 1; i++) {       while (tmp <= m && vis[tmp]) tmp++;       if (a[i] == -1) a[i] = b[tmp++];       cout << a[i] <<    n [i == n];     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 200010, M = 7000010;   int n, a[N], rt, tot;   map<int, int> mp;   int val[M];   vector<int> g[M];   int ans, ansx, ansy, S, T, cur, fa[M];   bool vis[M];   void dfs(int x, int fath, int dis, int *var) {     vis[x] = true;     if (x <= n && dis > cur) *var = x, cur = dis;     for (int y : g[x])       if (y != fath) dfs(y, x, dis + 1, var);   }   int getfa(int v) {     int t = 0, x = mp[v];     if (fa[x] != -1) return fa[x];     while ((1 << t) < v) t++;     int w = (1 << t) - v;     if (mp[w] == 0) tot++, mp[w] = tot, val[tot] = w;     g[x].push_back(mp[w]), g[mp[w]].push_back(x);     return fa[x] = w;   }   int main() {     cin >> n, tot = n;     for (int i = 1; i <= n; i++) scanf( %d , &a[i]), mp[a[i]] = i, val[i] = a[i];     sort(a + 1, a + n + 1), rt = a[1];     for (int i = 1; i <= n * 32; i++) fa[i] = -1;     for (int i = 2; i <= n; i++) {       int x = a[i], y = rt;       while (x != y) {         if (x < y) swap(x, y);         x = getfa(x);       }       rt = x;     }     ans = -1;     for (int i = 1; i <= n; i++)       if (!vis[i]) {         cur = 0, dfs(i, 0, 0, &S);         cur = 0, dfs(S, 0, 0, &T);         if (cur > ans) ans = cur, ansx = S, ansy = T;       }     printf( %d %d %d n , ansx, ansy, cur);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n;     cin >> n;     while (n) {       if (n % 10 != 1 && n % 100 != 14 && n % 1000 != 144) {         cout <<  NO ;         return 0;       }       n /= 10;     }     cout <<  YES ;     return 0;   }


#include <bits/stdc++.h>   char s[200005];   int res[200005];   int ptr;   int main() {     int n, a, b, k;     scanf( %d%d%d%d , &n, &a, &b, &k);     scanf( %s , s);     int cons = 0;     int cnt = 0;     for (int i = 0; i < n; i++) {       if (s[i] ==  0 ) cons++;       if (s[i] ==  1 ) {         cnt += cons / b;         cons = 0;       }     }     cnt += cons / b;     cons = 0;     for (int i = 0; i < n; i++) {       if (s[i] ==  0 )         cons++;       else         cons = 0;       if (cons == b && cnt > a - 1) {         res[ptr++] = i + 1;         cons = 0;         cnt--;       }     }     printf( %d n , ptr);     for (int i = 0; i < ptr; i++) printf( %d  , res[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   int prefix[N];   int main() {     string s;     int n, k;     cin >> n >> k >> s;     for (int i = int(1); i <= int(n); i++)       prefix[i] = prefix[i - 1] +  1  - s[i - 1];     int ans = n + 1;     for (int i = int(1); i <= int(n); i++) {       if (s[i - 1] ==  0 ) {         int l = 0, r = n - 1;         while (l + 1 < r) {           int mid = (l + r) >> 1;           int L = i - mid, R = i + mid;           L = max(1, L), R = min(n, R);           if (prefix[R] - prefix[L - 1] > k)             r = mid;           else             l = mid;         }         ans = min(ans, r);       }     }     cout << ans << endl;     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   const int sz = 1e3;   int adjm[sz + 1][sz + 1];   vector<int> adjl[(int)(1e6 + 1)];   vector<bool> vis((int)1e6 + 1, 0);   void init_adjm(int n) {     for (int i = 0; i <= n; i++) {       for (int j = 0; j <= n; j++) adjm[i][j] = 0;     }   }   void bfs(int s, int n, int m) {     queue<int> q;     q.push(s);     q.push(-1);     vis[s] = 1;     while (!q.empty()) {       int p = q.front();       q.pop();       if (p == -1) {         if (!q.empty()) {           q.push(-1);         }       } else {         for (int i = 0; i < adjl[p].size(); i++) {           int curr{adjl[p][i]};           if (!vis[curr]) {             q.push(curr);             vis[curr] = 1;           }         }       }     }   }   void dfs(int s) {     vis[s] = 1;     for (int i{0}; i < adjl[s].size(); i++) {       if (!vis[adjl[s][i]]) {         dfs(adjl[s][i]);       }     }   }   vector<bool> is_prime(1e6 + 1, true);   long long gcd(long long x, long long y) {     if (x == 0) return y;     return gcd(y % x, x);   }   void sievePrime(long long n) {     for (long long p{2}; p * p <= n; p++) {       if (is_prime[p]) {         for (long long i{p * p}; i <= n; i += p) {           is_prime[i] = false;         }       }     }   }   vector<int> SPF((int)1e6 + 1);   vector<long long> prime;   void manipulated_seive(int N) {     is_prime[0] = is_prime[1] = false;     for (int i = 2; i < N; i++) {       if (is_prime[i]) {         prime.push_back(i);         SPF[i] = i;       }       for (int j{0};            j < (int)prime.size() && i * prime[j] < N && prime[j] <= SPF[i]; j++) {         is_prime[i * prime[j]] = false;         SPF[i * prime[j]] = prime[j];       }     }   }   class my_compare {    public:     bool operator()(pair<int, int> &p1, pair<int, int> &p2) {       return p1.second < p2.second;     }   };   long long fact(int n) {     long long res{1};     for (int i = 2; i <= n; i++) res *= i;     return res;   }   long long nPr(int n, int r) {     long long num{1}, denom{1};     for (int i = 0; i < r; i++) {       denom *= (i + 1);       num *= (n - i);     }     return num / denom;   }   long long nCr(int n, int r) {     long long num{1}, denom{1};     for (int i = 0; i < r; i++) {       denom = (denom * (i + 1));       num = (num * (n - i));     }     return num / denom;   }   unsigned long long power(unsigned long long x, int y, int p) {     unsigned long long res = 1;     x = x % p;     while (y > 0) {       if (y & 1) res = (res * x) % p;       y = y >> 1;       x = (x * x) % p;     }     return res;   }   unsigned long long modInverse(unsigned long long n, int p) {     return power(n, p - 2, p);   }   unsigned long long nCrModPFermat(unsigned long long n, int r, int p) {     if (n < r) return 0;     if (r == 0) return 1;     unsigned long long fac[n + 1];     fac[0] = 1;     for (int i = 1; i <= n; i++) fac[i] = (fac[i - 1] * i) % p;     return (fac[n] * (modInverse(fac[r], p) % p) *             (modInverse(fac[n - r], p) % p)) %            p;   }   void solve() {     int n, m, x;     cin >> n >> m;     multiset<int, greater<int>> reqd;     for (int i = 0; i < n; i++) {       cin >> x;       reqd.insert(x);     }     for (int i = 0; i < m; i++) {       cin >> x;       auto it = reqd.lower_bound(x);       if (it != reqd.end()) {         reqd.erase(it);       }     }     cout << reqd.size() <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     bool test_case{0}, fileop{0};     if (fileop) {       freopen( input.txt ,  r , stdin);       freopen( output.txt ,  w , stdout);     }     int t;     if (test_case) {       cin >> t;       while (t--) {         solve();       }     } else       solve();   }


#include <bits/stdc++.h>   using namespace std;   int n, k, i, j, m, p, a[510];   double b[710000];   double calc(int x, int y, double a) { return (y - x) * a + x; }   int main() {     scanf( %d%d , &n, &k);     m = 700000 / k;     for (i = 1; i <= n; i++) {       double ans = 0;       for (j = 0; j <= k; j++) scanf( %d , &a[j]);       for (j = 0; j < k; j++) {         for (p = 0; p < m; p++) {           double s = calc(a[j], a[j + 1], 1.0 / m * (p + 0.5));           if (s > b[j * m + p]) ans += s - b[j * m + p], b[j * m + p] = s;         }       }       printf( %.10lf n , ans / m);     }   }


#include <bits/stdc++.h>   using namespace std;   int x[100], y[100];   int l1, l2, l3, l4, s, f[10], n;   int len(int g1, int g2) {     int res =         (((x[g1] - x[g2]) * (x[g1] - x[g2]) + (y[g1] - y[g2]) * (y[g1] - y[g2])));     return res;   }   bool prr(int kk1, int kk2, int kk3, int kk4) {     int ii, jj = 0, aa[4], kk, qq;     for (ii = 0; ii < 8; ii++)       if (ii != kk1 && ii != kk2 && ii != kk3 && ii != kk4) {         aa[jj++] = ii;       }     for (ii = 0; ii < 4; ii++)       for (jj = 0; jj < 4; jj++)         for (kk = 0; kk < 4; kk++)           for (qq = 0; qq < 4; qq++)             if (ii != jj && ii != kk && ii != qq && jj != kk && jj != qq &&                 kk != qq)               if (len(aa[ii], aa[jj]) == len(aa[kk], aa[qq]) &&                   len(aa[ii], aa[jj]) ==                       len(aa[ii], aa[kk]) + len(aa[ii], aa[qq]) &&                   len(aa[qq], aa[kk]) ==                       len(aa[ii], aa[kk]) + len(aa[jj], aa[kk]) &&                   len(aa[ii], aa[qq]) == len(aa[kk], aa[jj]) &&                   len(aa[ii], aa[kk]) == len(aa[jj], aa[qq]))                 return true;     return false;   }   bool kv(int q1, int q2, int q3, int q4) {     int i, a[4], j, k, q;     a[0] = q1;     a[1] = q2;     a[2] = q3;     a[3] = q4;     for (i = 0; i < 4; i++)       for (j = 0; j < 4; j++)         for (k = 0; k < 4; k++)           for (q = 0; q < 4; q++)             if (i != j && j != k && i != k && i != q && j != q && k != q) {               if (len(a[i], a[j]) == len(a[k], a[q]) &&                   len(a[i], a[j]) == len(a[i], a[q]) + len(a[i], a[k]) &&                   len(a[i], a[k]) == len(a[i], a[q]) &&                   len(a[k], a[q]) == len(a[k], a[i]) + len(a[k], a[j]) &&                   len(a[q], a[i]) == len(a[q], a[j])) {                 if (prr(q1, q2, q3, q4)) return true;               }             }     return false;   }   int main() {     for (l1 = 0; l1 < 8; l1++) scanf( %d %d , &x[l1], &y[l1]);     for (l1 = 0; l1 < 8; l1++)       for (l2 = 0; l2 < 8; l2++)         for (l3 = 0; l3 < 8; l3++)           for (l4 = 0; l4 < 8; l4++)             if (l1 != l2 && l1 != l3 && l1 != l4 && l2 != l3 && l2 != l4 &&                 l3 != l4 && kv(l1, l2, l3, l4)) {               printf( YES n );               printf( %d %d %d %d n , l1 + 1, l2 + 1, l3 + 1, l4 + 1);               for (s = 0; s < 8; s++)                 if (s != l1 && s != l2 && s != l3 && s != l4) f[n++] = s;               for (s = 0; s < 3; s++) printf( %d  , f[s] + 1);               printf( %d n , f[3] + 1);               return 0;             }     printf( NO n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, p;   struct Node {     int i, d;   } d[100005];   vector<int> v[100005 << 1];   bool cmp(Node x, Node y) { return x.d > y.d; }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &d[i].d);       d[i].i = 2 * i;     }     sort(d + 1, d + n + 1, cmp);     for (int i = 1; i <= n; i++) {       v[p++].push_back(d[i].i);     }     for (int i = 1; i <= n; i++) {       if (i + d[i].d - 1 == p) {         v[p++].push_back(d[i].i - 1);       } else {         v[i + d[i].d - 2].push_back(d[i].i - 1);       }     }     for (int i = 0; i < p; i++) {       for (int j = 1; j < v[i].size(); j++) {         printf( %d %d n , v[i][0], v[i][j]);       }     }     for (int i = 1; i < p; i++) {       printf( %d %d n , v[i - 1][0], v[i][0]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long int mod = 1000000000 + 7;   const long long int N = 10000000 + 6;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int a, b;     cin >> a >> b;     vector<pair<int, int> > bb, aa;     for (int i = 1; i < 1000; i++) {       for (int j = 1; j < 1000; j++) {         if (i * i + j * j == a * a) aa.push_back(make_pair(i, j));         if (i * i + j * j == b * b) bb.push_back(make_pair(i, j));       }     }     bool flag = false;     for (int i = 0; i < aa.size(); i++) {       for (int j = 0; j < bb.size(); j++) {         int p = aa[i].first;         int q = aa[i].second;         int r = bb[j].first;         int s = bb[j].second;         if (p * s == q * r) {           if (p != s) {             cout <<  YES n                   <<  0 0 n                   << p <<     << q <<   n                   << s <<     << -r;             flag = true;             break;           }         }       }       if (flag == true) break;     }     if (flag == false) cout <<  NO n  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct Info {     int h, l, r;     vector<int> A;     Info(vector<int> _A, int _h, int _l, int _r) : A(_A), h(_h), l(_l), r(_r) {}   };   int FindMaxGoodSleep(int idx, int time, vector<vector<int>>& memo,                        const Info& input) {     if (idx >= input.A.size()) {       return 0;     }     if (memo[idx][time] != -1) {       return memo[idx][time];     }     int new_time = (time + input.A[idx]) % input.h;     int a = (new_time >= input.l && new_time <= input.r ? 1 : 0) +             FindMaxGoodSleep(idx + 1, new_time, memo, input);     new_time = (time + input.A[idx] - 1) % input.h;     int b = (new_time >= input.l && new_time <= input.r ? 1 : 0) +             FindMaxGoodSleep(idx + 1, new_time, memo, input);     memo[idx][time] = max(a, b);     return memo[idx][time];   }   int main(void) {     int n, h, l, r;     cin >> n >> h >> l >> r;     vector<int> A(n);     for (int i = 0; i < n; i++) {       cin >> A[i];     }     Info info(A, h, l, r);     vector<vector<int>> memo(n + 5, vector<int>(2005, -1));     cout << FindMaxGoodSleep(0, 0, memo, info) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> G[100009];   map<string, int> pr;   struct comp {     bool operator()(const pair<string, int>& l, const pair<string, int>& r) {       return l.second > r.second;     }   };   int main() {     pr[ captain ] = 1;     pr[ man ] = 2;     pr[ child ] = 3;     pr[ woman ] = 3;     pr[ rat ] = 4;     int n;     cin >> n;     getchar();     vector<pair<string, int> > v;     while (n--) {       string a, b;       cin >> a >> b;       v.push_back({a, pr[b]});     }     stable_sort(v.begin(), v.end(), comp());     for (int i = 0; i < v.size(); i++) cout << v[i].first << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<string> split(const string& s, char c) {     vector<string> v;     stringstream ss(s);     string x;     while (getline(ss, x, c)) v.emplace_back(x);     return move(v);   }   void err(vector<string>::iterator it) {}   template <typename T, typename... Args>   void err(vector<string>::iterator it, T a, Args... args) {     cerr << it->substr((*it)[0] ==    , it->length()) <<   =   << a <<   n ;     err(++it, args...);   }   typedef tuple<int, int, int> State;   int dx[] = {0, 1, 0, -1};   int dy[] = {1, 0, -1, 0};   const int N = 1e6 + 5;   const double EPS = 1e-10;   const long long INF = 1e18;   const double PI = acos(-1);   int n, m, k;   int dcmp(double a, double b) { return fabs(a - b) <= EPS ? 0 : a < b ? -1 : 1; }   string s, s2;   int arr[26];   int arr2[26];   int cnt = 0;   bool ok() {     for (int i = 0; i < 26; i++) {       if (arr[i] > arr2[i]) return 0;     }     return 1;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     cin >> s >> s2;     if (s.size() < s2.size()) {       cout <<  0 ;       return 0;     }     for (int i = 0; i < s2.size(); i++) {       arr2[s2[i] -  a ]++;       if (s[i] !=  ? )         arr[s[i] -  a ]++;       else         cnt++;     }     int ans = ok();     n = s2.size();     for (int i = s2.size(); i < s.size(); i++) {       if (s[i] !=  ? )         arr[s[i] -  a ]++;       else         cnt++;       if (s[i - n] !=  ? )         arr[s[i - n] -  a ]--;       else         cnt--;       ans += ok();     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int N = (int)1e5 + 123;   const long long INF = (long long)1e18 + 123;   const int inf = (int)1e9 + 123;   const int MOD = (int)1e9 + 7;   int type(string a) {     if (a ==  S ) return 1;     if (a ==  M ) return 2;     if (a ==  L ) return 3;     if (a ==  XL ) return 4;     if (a ==  XXL ) return 5;     if (a ==  XXXL ) return 6;     return 7;   }   int a[10], n;   string t, name[10] = {  ,  S ,  M ,  L ,  XL ,  XXL ,  XXXL }, res[N];   set<int> st[10];   vector<pair<int, pair<int, int> > > g;   int main() {     for (int i = 1; i <= 6; i++) cin >> a[i];     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> t;       string tmp1 =   , tmp2 =   ;       int pos = (int)(t.size());       for (int j = 0; j < (int)(t.size()); j++) {         if (t[j] ==  , ) {           pos = j + 1;           break;         }         tmp1 += t[j];       }       for (int j = pos; j < (int)(t.size()); j++) tmp2 += t[j];       if (type(tmp2) < type(tmp1)) swap(tmp1, tmp2);       if (type(tmp2) == 7) {         res[i] = tmp1, a[type(tmp1)]--;         continue;       }       g.push_back(make_pair(type(tmp1), make_pair(type(tmp2), i)));     }     sort(g.begin(), g.end());     for (auto i : g) {       if (a[i.first] > 0)         a[i.first]--, res[i.second.second] = name[i.first];       else         a[i.second.first]--, res[i.second.second] = name[i.second.first];     }     for (int i = 1; i <= 6; i++)       if (a[i] < 0) {         puts( NO );         return 0;       }     puts( YES );     for (int i = 1; i <= n; i++) cout << res[i] <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   int t, n, inp[3], cnt[100010];   map<pair<int, int>, vector<pair<int, int>>> el;   int root;   vector<int> qans;   vector<int> neigh[100010];   void solve() {     cin >> n;     el.clear();     for (int i = 1; i <= n; ++i) cnt[i] = 0, neigh[i].clear();     for (int i = 1; i + 2 <= n; ++i) {       for (int j = 0; j < 3; ++j) {         cin >> inp[j];         ++cnt[inp[j]];       }       sort(inp, inp + 3);       if (el.count({inp[0], inp[1]}))         el[{inp[0], inp[1]}].push_back({inp[2], i});       else         el[{inp[0], inp[1]}] = {{inp[2], i}};       if (el.count({inp[0], inp[2]}))         el[{inp[0], inp[2]}].push_back({inp[1], i});       else         el[{inp[0], inp[2]}] = {{inp[1], i}};       if (el.count({inp[1], inp[2]}))         el[{inp[1], inp[2]}].push_back({inp[0], i});       else         el[{inp[1], inp[2]}] = {{inp[0], i}};     }     for (auto& x : el) {       if (x.second.size() == 1) {         neigh[x.first.first].push_back(x.first.second);         neigh[x.first.second].push_back(x.first.first);       }     }     cout << 1 <<     << neigh[1][0];     int curr = neigh[1][0], prev = 1;     for (int i = 3; i <= n; ++i) {       if (neigh[curr][0] == prev) {         cout <<     << neigh[curr][1];         prev = curr;         curr = neigh[curr][1];       } else {         cout <<     << neigh[curr][0];         prev = curr;         curr = neigh[curr][0];       }     }     cout << endl;     for (int i = 1; i <= n; ++i)       if (cnt[i] == 1) {         root = i;         break;       }     pair<int, int> ce = {neigh[root][0], neigh[root][1]};     if (ce.first > ce.second) swap(ce.first, ce.second);     for (auto& x : el[ce]) {       if (x.first == root) {         qans.push_back(x.second);       }     }     queue<pair<pair<int, int>, int>> qq;     qq.push({ce, root});     while (!qq.empty()) {       auto x = qq.front();       qq.pop();       if (el[x.first].size() == 1) {         continue;       }       pair<int, int> y =           (el[x.first][0].first == x.second ? el[x.first][1] : el[x.first][0]);       qans.push_back(y.second);       pair<int, int> nxt1 = {x.first.first, y.first},                      nxt2 = {x.first.second, y.first};       if (nxt1.first > nxt1.second) swap(nxt1.first, nxt1.second);       if (nxt2.first > nxt2.second) swap(nxt2.first, nxt2.second);       qq.push({nxt1, x.first.second});       qq.push({nxt2, x.first.first});     }     while (!qans.empty()) {       cout << qans.back() <<    ;       qans.pop_back();     }     cout << endl;   }   int main() {     ios::sync_with_stdio(false);     for (cin >> t; t--;) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline T gcd(T a, T b) {     if (a < 0) return gcd(-a, b);     if (b < 0) return gcd(a, -b);     return (b == 0) ? a : gcd(b, a % b);   }   template <class T>   inline T lcm(T a, T b) {     if (a < 0) return lcm(-a, b);     if (b < 0) return lcm(a, -b);     return a * (b / gcd(a, b));   }   template <class T>   inline T sqr(T x) {     return x * x;   }   template <class T>   T power(T N, T P) {     return (P == 0) ? 1 : N * power(N, P - 1);   }   template <class T>   bool inside(T a, T b, T c) {     return (b >= a && b <= c);   }   const long long INF64 = (long long)1E16;   int distsq2d(int x1, int y1, int x2, int y2) {     return sqr(x1 - x2) + sqr(y1 - y2);   }   double dist2d(double x1, double y1, double x2, double y2) {     return sqrt(sqr(x1 - x2) + sqr(y1 - y2));   }   double dist3d(double x1, double y1, double z1, double x2, double y2,                 double z2) {     return sqrt(sqr(x1 - x2) + sqr(y1 - y2) + sqr(z1 - z2));   }   long long toInt64(string s) {     long long r = 0;     istringstream sin(s);     sin >> r;     return r;   }   double LOG(long long N, long long B) { return (log10l(N)) / (log10l(B)); }   string itoa(long long a) {     if (a == 0) return  0 ;     string ret;     for (long long i = a; i > 0; i = i / 10) ret.push_back((i % 10) + 48);     reverse(ret.begin(), ret.end());     return ret;   }   vector<string> token(string a, string b) {     const char *q = a.c_str();     while (count(b.begin(), b.end(), *q)) q++;     vector<string> oot;     while (*q) {       const char *e = q;       while (*e && !count(b.begin(), b.end(), *e)) e++;       oot.push_back(string(q, e));       q = e;       while (count(b.begin(), b.end(), *q)) q++;     }     return oot;   }   int isvowel(char s) {     s = tolower(s);     if (s ==  a  || s ==  e  || s ==  i  || s ==  o  || s ==  u ) return 1;     return 0;   }   int isupper(char s) {     if (s >=  A  and s <=  Z ) return 1;     return 0;   }   int Set(int N, int pos) { return N = N | (1 << pos); }   int reset(int N, int pos) { return N = N & ~(1 << pos); }   int check(int N, int pos) { return (N & (1 << pos)); }   int toggle(int N, int pos) {     if (check(N, pos)) return N = reset(N, pos);     return N = Set(N, pos);   }   void pbit(int N) {     printf( ( );     for (int i = 10; i >= 0; i--) {       bool x = check(N, i);       cout << x;     }     puts( ) );   }   char ts[200];   int n, m;   int a[14][104];   int b[14][104];   int c[14][104];   int dp[14][14][104][104];   int call(int p1, int p2, int idx, int left) {     if (idx == m) return 0;     if (dp[p1][p2][idx][left] != -1) {       return dp[p1][p2][idx][left];     }     int mxx = 0;     for (int i = 1; i <= left and i <= c[p1][idx]; i++) {       int bcost = a[p1][idx] * i;       int scost = b[p2][idx] * i;       int ret = (scost - bcost) + call(p1, p2, idx + 1, left - i);       mxx = max(ret, mxx);     }     int ret = call(p1, p2, idx + 1, left);     mxx = max(ret, mxx);     return dp[p1][p2][idx][left] = mxx;   }   int main() {     memset(dp, -1, sizeof(dp));     ;     int k;     cin >> n >> m >> k;     for (int i = 0; i < n; i++) {       scanf( %s , ts);       for (int j = 0; j < m; j++) {         scanf( %d%d%d , &a[i][j], &b[i][j], &c[i][j]);       }     }     int best = 0;     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         if (i == j) continue;         int ret = call(i, j, 0, k);         best = max(ret, best);       }     }     cout << best << endl;   }


#include <bits/stdc++.h>      using namespace std;      const int N = 1000 * 1000 + 10;   long long int a[N], mm[N], visited[N], anss[N], ans;   int n;   vector <int> e[N];      void dfs(int v){    visited[v] = 1;    if (e[v].size() == 1 and v != 1){     anss[v] = 1;     return;    }    vector <int> vec;    for (auto u : e[v]){     if (visited[u] == 0){      dfs(u);/*      if (v == 6){       cout << u <<   kk  ;      }*/      vec.push_back(anss[u]);     }    }    sort(vec.begin(), vec.end());        if (v != 1){     if (vec.size() > 1){      ans = max(ans, vec.back() + 1ll);     }         }    else{          if (vec.size() > 1){      ans = max(ans, vec.back() + 0ll);      ans = max(ans, vec[vec.size() - 2] + 1ll);     }    }    anss[v] = vec[0] + 1;    ans = max(ans, vec[0] + 0ll);/*    if (ans == 4){     cout << v <<     << vec.back() + 1 <<   n ;    }*/    vec.clear();       }      int main(){    int tt;    cin >> tt;    while (tt--){     ans = 0;     int n;     cin >> n;     for (int i = 0; i < n - 1; i++){      int x, y;      cin >> x >> y;      e[x].push_back(y);      e[y].push_back(x);     }//vec.clear();     dfs(1);     /*     for (int i = 1; i <= n; i++){      cout << anss[i] <<    ;     }     cout <<   n ;*/     cout << ans <<   n ;     for (int i = 1; i <= n; i++){      e[i].clear();      visited[i] = 0;      anss[i] = 0;     }       }   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   T gcd(T a, T b) {     if (a == 0) return b;     return gcd(b % a, a);   }   template <typename T>   T pow(T a, T b, long long m) {     T ans = 1;     while (b > 0) {       if (b % 2 == 1) ans = (ans * a) % m;       b /= 2;       a = (a * a) % m;     }     return ans % m;   }   int bit[100005];   int n;   int a[100005];   int lis[100005];   void update(int x, int val) {     for (int i = x; i < 100005; i += (i & -i)) bit[i] = max(bit[i], val);   }   int read(int x) {     int res = 0;     for (int i = x; i; i -= (i & -i)) res = max(res, bit[i]);     return res;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     cin >> n;     int ans = 0;     for (int i = 1; i <= n; i++) cin >> a[i];     for (int i = 1; i <= n; i++) {       lis[i] = read(a[i] - 1) + 1;       update(a[i], lis[i]);       ans = max(ans, lis[i]);     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long H, L;     scanf( %lld%lld , &H, &L);     printf( %f , 0.5 * (L * L - H * H) / H);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     if (n < k || (n > 1 && k == 1)) {       cout << -1 << endl;       return 0;     }     if (n <= 2) {       n == 1 ? cout <<  a  << endl : cout <<  ab  << endl;       return 0;     }     char *str = new char[n + 1];     str[n] =   0 ;     int pos = 0;     int prev = 1;     char used =  a  - 1;     while (n - pos > k - 2) {       if (prev == 1) {         str[pos] =  a ;         prev = 0;       } else {         str[pos] =  b ;         prev = 1;       }       if (used < str[pos]) {         used = str[pos];       }       pos++;     }     while (pos != n) {       used++;       str[pos] = used;       pos++;     }     cout << str << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, k, a, b, c, d, now, f[1001];   bool jud[1001];   int main() {     cin.sync_with_stdio(false);     cin >> n >> k;     cin >> a >> b >> c >> d;     if (k < n + 1 || n == 4) {       cout << -1 << endl;       return 0;     }     f[1] = a;     f[2] = c;     f[n - 1] = d;     f[n] = b;     jud[a] = jud[b] = jud[c] = jud[d] = true;     int now = 1;     for (int i = 3; i <= n - 2; i++) {       while (jud[now]) now++;       f[i] = now;       now++;     }     for (int i = 1; i <= n - 1; i++) cout << f[i] <<    ;     cout << f[n] << endl;     cout << f[2] <<     << f[1] <<    ;     for (int i = 3; i <= n - 2; i++) cout << f[i] <<    ;     cout << f[n] <<     << f[n - 1];   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 2e5 + 50;   const long long mod = 1e9 + 7;   const long long INF = 1e18;   long long dx[] = {-1, 0, 1, 0};   long long dy[] = {0, 1, 0, -1};   bool compare(const pair<long long, long long>& i,                const pair<long long, long long>& j) {     return i.second > j.second;   }   long long fact[N];   vector<bool> is_prime(100000, true);   vector<long long> prime;   void pre() {     fact[0] = 1;     for (long long i = 1; i < N; i++) {       fact[i] = i * fact[i - 1];       fact[i] %= mod;     }   }   long long modexp(long long x, long long n) {     long long r = 1;     while (n) {       if (n & 1) r = (r * x) % mod;       x = (x * x) % mod;       n >>= 1;     }     return r % mod;   }   long long modinv(long long x) { return modexp(x, mod - 2); }   long long ncr(long long n, long long r) {     if (n < r) return 0;     long long ans =         (fact[n] % mod * modinv(fact[r]) % mod * modinv(fact[n - r]) % mod) % mod;     return ans;   }   long long exp(long long x, long long n) {     long long r = 1;     while (n) {       if (n & 1) r = (r * x);       x = (x * x);       n >>= 1;     }     return r;   }   void solve() {     long long n;     cin >> n;     long long x = 1;     long long A[n + 2];     for (long long i = 1; i <= n; i += 2) {       A[i] = x;       x++;     }     for (long long i = n - n % 2; i >= 2; i -= 2) {       A[i] = x;       x++;     }     for (long long i = 1; i <= n; i++) cout << A[i] <<    ;     cout << endl;     return;   }   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long t = 1;     for (long long i = 0; i < t; i++) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     int songs = n + m - 1;     cout << songs << endl;     for (int i = 1; i <= n; i++) {       cout << i <<     << 1 << endl;     }     for (int i = 2; i <= m; i++) {       cout << 1 <<     << i << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     scanf( %d , &t);     while (t--) {       int a, b, c;       int d, e, f;       scanf( %d%d%d , &a, &b, &c);       scanf( %d%d%d , &d, &e, &f);       int sum = 0;       sum = min(c, e) * 2;       e = e - sum / 2;       c = c - sum / 2;       if (c > 0) {         f = f - min(c, f);       }       if (d + e < b) {         sum = sum - min((b - d - e), f) * 2;       }       printf( %d n , sum);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     int m = 0, c = 0;     while (t--) {       int a, b;       cin >> a >> b;       if (a > b)         m++;       else if (a < b)         c++;       else {         m++;         c++;       }     }     if (m > c)       cout <<  Mishka ;     else if (m < c)       cout <<  Chris ;     else {       cout <<  Friendship is magic!^^ ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = (int)6e4 + 2;   int n;   map<string, int> mp;   vector<pair<string, int>> v;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> n;     string str;     for (int i = 0; i < n; ++i) {       cin >> str;       mp[str] = i;     }     for (map<string, int>::iterator it = mp.begin(); it != mp.end(); ++it) {       v.push_back(*it);     }     sort(v.begin(), v.end(),          [](const pair<string, int>& a, pair<string, int>& b) {            return a.second > b.second;          });     for (int i = 0; i < v.size(); ++i) cout << v[i].first << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MAXN = 1e6, mod = 1000000007;   long long n, m, x, k, d, p, z, sum;   vector<long long> v, ans;   set<long long> st;   int main() {     cin >> n >> k;     for (long long i = 1; i <= 2 * n; i *= 2) v.push_back(i - 1);     if (k == 1) {       cout << n;       return 0;     } else {       for (int i = v.size() - 1; i >= 0; i--) {         if (i == 0 || (v[i] >= n && v[i - 1] < n)) {           cout << v[i];           return 0;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   string toStr(const T &x) {     stringstream s;     s << x;     return s.str();   }   template <class T>   int toInt(const T &x) {     stringstream s;     s << x;     int r;     s >> r;     return r;   }   vector<string> pals;   bool check(string s) {     for (int i = 0, j = s.size() - 1; i < s.size() / 2; i++, j--) {       if (s[i] != s[j]) return false;     }     return true;   }   void gen() {     for (int i = 0; i < 24; ++i) {       for (int j = 0; j < 60; ++j) {         string t1 = i < 10 ?  0  :   ;         string t2 = j < 10 ?  0  :   ;         string t = t1 + toStr(i) +  :  + t2 + toStr(j);         if (check(t)) pals.push_back(t);       }     }   }   int main() {     gen();     string line;     cin >> line;     if (line >  23:32 )       cout <<  00:00  << endl;     else {       vector<string>::iterator it = upper_bound(pals.begin(), pals.end(), line);       cout << pals[(it - pals.begin())] << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 1e5 + 5, MX = 2e5, MN = 0;   struct node;   extern node* empty;   struct node {     int mx;     node *LF, *RT;     node() : mx(0), LF(this), RT(this) {}     node(int val, node* lf = empty, node* rt = empty) : mx(val), LF(lf), RT(rt) {}   };   node* empty = new node();   node* insert(int val, int ind, node* cur, int ns = 0, int ne = MX) {     if (ind > ne or ind < ns) return cur;     if (ns == ne) return new node(val);     int mid = ns + (ne - ns) / 2;     node* lf = insert(val, ind, cur->LF, ns, mid);     node* rt = insert(val, ind, cur->RT, mid + 1, ne);     return new node(max(lf->mx, rt->mx), lf, rt);   }   int getMax(int qe, node* cur, int ns = 0, int ne = MX) {     if (qe < 0) return 0;     if (ns > qe) return 0;     if (ne <= qe) return cur->mx;     int mid = ns + (ne - ns) / 2;     return max(getMax(qe, cur->LF, ns, mid), getMax(qe, cur->RT, mid + 1, ne));   }   node* roots[N];   int main() {     int n, m;     scanf( %d%d , &n, &m);     for (long long i = 1; i <= n; i++) {       roots[i] = empty;     }     for (long long i = 0; i < m; i++) {       int a, b, w;       scanf( %d%d%d , &a, &b, &w);       roots[b] = insert(getMax(w - 1, roots[a]) + 1, w, roots[b]);     }     int ans = 0;     for (long long i = 1; i <= n; i++) {       ans = max(ans, getMax(MX, roots[i]));     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);     int n;     cin >> n;     int arr[n + 5][n + 5], a, b;     map<int, int> mp, mp2;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         arr[i][j] = 0;       }     }     for (int i = 1; i < n; i++) {       cin >> a >> b;       arr[a][b] = 1;       mp[a]++;       mp2[b]++;     }     vector<pair<int, pair<int, int>>> v;     int tmp = n;     while (tmp > 1) {       if (mp2[tmp]) {         for (int i = 1; i < tmp; i++) {           if (!mp2[i]) {             v.push_back({2, {i, tmp}});             mp2[i] = mp2[tmp];             for (int ii = 1; ii <= tmp; ii++) {               swap(arr[ii][tmp], arr[ii][i]);             }             break;           }         }       }       if (!mp[tmp]) {         for (int i = 1; i < tmp; i++) {           if (mp[i]) {             v.push_back({1, {i, tmp}});             mp[i] = mp[tmp];             for (int ii = 1; ii <= tmp; ii++) {               mp2[ii] -= arr[i][ii];               swap(arr[tmp][ii], arr[i][ii]);             }             break;           }         }       } else {         for (int ii = 1; ii <= tmp; ii++) {           mp2[ii] -= arr[tmp][ii];           arr[tmp][ii] = 0;         }       }       tmp--;     }     cout << v.size() <<   n ;     for (auto i : v) {       cout << i.first <<     << i.second.first <<     << i.second.second <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long res, rec, d, h, v, e, p = 3.1415926535;   int main() {     cin >> d >> h;     if (d == 1 && h == 1) {       cout << 0;       return 0;     }     while (d != 0 && h != 0) {       if (d <= h) {         d++;         h -= 2;       } else if (d > h) {         d -= 2;         h++;       }       e++;     }     cout << e;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int kocka[25] = {};     for (int i = 1; i <= 24; i++) cin >> kocka[i];     if (kocka[1] == kocka[2] && kocka[2] == kocka[3] && kocka[3] == kocka[4] &&         kocka[17] == kocka[18] && kocka[18] == kocka[7] && kocka[7] == kocka[8] &&         kocka[21] == kocka[22] && kocka[22] == kocka[19] &&         kocka[19] == kocka[20]) {       cout <<  YES ;       exit(0);     }     if (kocka[1] == kocka[2] && kocka[2] == kocka[3] && kocka[3] == kocka[4] &&         kocka[13] == kocka[14] && kocka[14] == kocka[7] && kocka[7] == kocka[8] &&         kocka[5] == kocka[6] && kocka[6] == kocka[19] && kocka[19] == kocka[20]) {       cout <<  YES ;       exit(0);     }     if (kocka[1] == kocka[2] && kocka[2] == kocka[17] && kocka[17] == kocka[19] &&         kocka[5] == kocka[6] && kocka[6] == kocka[7] && kocka[7] == kocka[8] &&         kocka[10] == kocka[18] && kocka[18] == kocka[9] &&         kocka[9] == kocka[20]) {       cout <<  YES ;       exit(0);     }     if (kocka[1] == kocka[2] && kocka[2] == kocka[16] && kocka[16] == kocka[14] &&         kocka[5] == kocka[6] && kocka[6] == kocka[7] && kocka[7] == kocka[8] &&         kocka[3] == kocka[18] && kocka[18] == kocka[4] && kocka[4] == kocka[20]) {       cout <<  YES ;       exit(0);     }     if (kocka[5] == kocka[2] && kocka[2] == kocka[7] && kocka[7] == kocka[4] &&         kocka[9] == kocka[6] && kocka[6] == kocka[11] && kocka[11] == kocka[8] &&         kocka[17] == kocka[18] && kocka[18] == kocka[19] &&         kocka[19] == kocka[20]) {       cout <<  YES ;       exit(0);     }     if (kocka[24] == kocka[2] && kocka[2] == kocka[22] && kocka[22] == kocka[4] &&         kocka[1] == kocka[6] && kocka[6] == kocka[3] && kocka[3] == kocka[8] &&         kocka[17] == kocka[18] && kocka[18] == kocka[19] &&         kocka[19] == kocka[20]) {       cout <<  YES ;       exit(0);     }     cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e5 + 5;   const double eps = 1e-14;   char buf[1 << 12], *pp1 = buf, *pp2 = buf, nc;   int ny;   inline char gc() { return getchar(); }   inline long long read() {     long long x = 0;     for (ny = 1; nc = gc(), (nc < 48 || nc > 57) && nc != EOF;)       if (nc == 45) ny = -1;     if (nc < 0) return nc;     for (x = nc - 48; nc = gc(), 47 < nc && nc < 58 && nc != EOF;          x = (x << 3) + (x << 1) + (nc ^ 48))       ;     return x * ny;   }   int n, top, a[MAXN], b[MAXN];   long long t;   double p[MAXN], Max;   struct Point {     double x, y;     int id;     Point(double x = 0, double y = 0, int id = 0) : x(x), y(y), id(id) {}     double K() { return y / x; }   } s[MAXN], stk[MAXN];   inline Point operator-(Point a, Point b) { return Point(a.x - b.x, a.y - b.y); }   inline double operator^(Point a, Point b) { return a.x * b.y - a.y * b.x; }   inline int sig(double x) { return x < -eps ? -1 : x > eps ? 1 : 0; }   struct Mat {     double a[3][3];     inline double* operator[](int x) { return a[x]; }     inline friend Mat operator*(Mat a, Mat b) {       Mat c;       for (int i = (0); i <= (2); i++)         for (int j = (0); j <= (2); j++) c[i][j] = 0;       for (int i = (0); i <= (2); i++)         for (int j = (0); j <= (2); j++)           for (int k = (0); k <= (2); k++) c[i][j] += a[i][k] * b[k][j];       return c;     }   } coef, st, ST[40];   int main() {     n = read(), t = read();     for (int i = (1); i <= (n); i++)       scanf( %d%d%lf , a + i, b + i, p + i), s[i] = Point(p[i], p[i] * a[i], i),                                              Max = max(Max, p[i] * b[i]);     sort(s + 1, s + n + 1, [](Point x, Point y) {       return !sig(x.x - y.x) ? sig(x.y - y.y) > 0 : sig(x.x - y.x) < 0;     });     for (int i = (1); i <= (n); i++) {       if (i != 1 && !sig(s[i].x - s[i - 1].x)) continue;       for (;            top > 1 && sig((s[i] - stk[top - 1]) ^ (stk[top] - stk[top - 1])) <= 0;            top--)         ;       stk[++top] = s[i];     }     int now = 1;     st[2][0] = 1;     for (long long l = 0, r; l < t; l = r) {       double s = st[1][0] * Max - st[0][0];       for (; now < top && (stk[now + 1] - stk[now]).K() >= -s; now++)         ;       int j = stk[now].id;       coef[0][0] = 1 - p[j], coef[0][1] = p[j] * Max, coef[0][2] = p[j] * a[j];       coef[1][0] = 0, coef[1][1] = coef[1][2] = 1, coef[2][0] = coef[2][1] = 0,       coef[2][2] = 1;       ST[0] = coef;       for (int i = (1); i <= (34); i++) ST[i] = ST[i - 1] * ST[i - 1];       r = l;       for (int i = (34); i >= (0); i--)         if (r + (1ll << i) < t) {           Mat t = ST[i] * st;           double ss = t[1][0] * Max - t[0][0];           if (now == top || (stk[now + 1] - stk[now]).K() < -ss)             r += 1ll << i, st = t;         }       st = ST[0] * st, r++;     }     printf( %.10lf , st[0][0]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 100005;   const long long INF = 1e18;   const long long MOD = 1000000007;   long double A[100005], B[100005];   int main() {     int n, p;     cin >> n >> p;     for (int i = 0; i < n; i++) {       int x, y;       cin >> x >> y;       A[i] = y / p;       A[i] -= (x - 1) / p;       B[i] = (y - x + 1);     }     long double res;     long double ans = 0;     for (int i = 1; i < n; i++) {       res = (A[i] * A[i - 1]) + (A[i] * (B[i - 1] - A[i - 1])) +             (A[i - 1] * (B[i] - A[i]));       long double d = B[i] * B[i - 1];       res = res / d;       res = res * 2000;       ans += res;     }     res = (A[0] * A[n - 1]) + (A[0] * (B[n - 1] - A[n - 1])) +           (A[n - 1] * (B[0] - A[0]));     long double d = B[0] * B[n - 1];     res = res / d;     res = res * 2000;     ans += res;     cout << setprecision(10) << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mxn = 105;   const long long mxm = 1;   const long long INF = 0x3f3f3f3f;   const long long mod = 1e9 + 7;   const double eps = 1e-7;   long long a[mxn];   signed main(void) {     long long q;     cin >> q;     while (q--) {       long long n;       cin >> n;       long long ct1 = 0, ct2 = 0, ct0 = 0, ans = 0;       for (long long i = 1; i <= n; i++) {         cin >> a[i];         a[i] = a[i] % 3;         if (a[i] == 1) ct1++;         if (a[i] == 2) ct2++;         if (a[i] == 0) ct0++;       }       ans = ct0;       if (ct1 >= ct2) {         ans += ct2;         ct1 -= ct2;         ans += ct1 / 3;       } else {         ans += ct1;         ct2 -= ct1;         ans += ct2 / 3;       }       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int a[n];     vector<int> v;     for (int i = 0; i < n; i++) cin >> a[i];     sort(a, a + n);     v.push_back(1);     int flag = 0;     for (int i = 1; i < n; i++) {       flag = 0;       for (int j = 0; j < v.size(); j++) {         if (a[i] >= v[j]) {           v[j]++;           flag = 1;           break;         }       }       if (!flag) v.push_back(1);     }     cout << v.size();   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5;   const int M = N + 7;   const int MOD = 1e9 + 7;   const long long INF = 1e16 + 17;   const int K = 5;   void ex() {     printf( -1 n );     exit(0);   }   int a[M];   int l[M], r[M], len[M];   int an[M];   bool dp[M][K + 3];   pair<int, int> par[M][K + 3];   bool cmp(int i, int j) { return l[i] < l[j]; }   void fillLR(int tl, int tr, int cnt, int st) {     if (tl > tr) return;     int d = tr - tl + 1;     int cur = d / cnt;     for (int i = st; i < st + cnt; ++i) {       int x = cur + (d % cnt > i - st);       while (x-- && tl <= tr) an[tl++] = i;     }   }   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; ++i) {       scanf( %d , &a[i]);       l[a[i]] = l[a[i]] ? l[a[i]] : i;       r[a[i]] = i;     }     vector<int> ord;     for (int i = 1; i <= N; ++i) {       if (l[i]) {         len[i] = r[i] - l[i] + 1;         ord.push_back(i);       }       if (len[i] > 5) ex();     }     l[0] = -4;     r[0] = 0;     len[0] = K;     ord.push_back(0);     sort(ord.begin(), ord.end(), cmp);     for (int t = 1; t < (int)ord.size(); ++t) {       if (l[ord[t]] <= r[ord[t - 1]]) ex();     }     dp[0][0] = true;     int m = (int)ord.size() - 1;     for (int t = 1; t <= m; ++t) {       int i = ord[t];       int j = ord[t - 1];       for (int rr = 0; rr + len[j] <= K; ++rr) {         if (!dp[t - 1][rr]) continue;         for (int tr = 0; tr + len[i] <= K; ++tr) {           for (int tl = 0; tl + tr + len[i] <= K; ++tl) {             if (tr + tl + len[i] < 2) continue;             int dist = (l[i] - tl) - (r[j] + rr) - 1;             int cnt = i - j - 1;             if (cnt * 2 <= dist && dist <= cnt * 5) {               dp[t][tr] = true;               par[t][tr] = make_pair(tl, rr);             }           }         }       }     }     int ans = 0, k = 0;     for (int tr = 0; tr + len[ord[m]] <= K && r[ord[m]] + tr <= n; ++tr) {       if (dp[m][tr]) {         int len = n - r[ord[m]] - tr;         if (len != 1) {           fillLR(r[ord[m]] + tr + 1, n, len / 2, ord[m] + 1);           k = tr;           ans = ord[m] + len / 2;           break;         }       }     }     if (!ans) ex();     while (m) {       int cnt = ord[m] - ord[m - 1] - 1;       pair<int, int> cur = par[m][k];       fillLR(l[ord[m]] - cur.first, r[ord[m]] + k, 1, ord[m]);       fillLR(r[ord[m - 1]] + cur.second + 1, l[ord[m]] - cur.first - 1, cnt,              ord[m - 1] + 1);       m--;       k = cur.second;     }     printf( %d n , ans);     for (int i = 1; i <= n; ++i) printf( %d  , an[i]);     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mxN = 302;   bool ar[mxN];   int p, n;   void solve() {     cin >> p >> n;     for (int i = 0; i < n; i++) {       int a;       cin >> a;       int temp = a % p;       if (ar[temp] == 0) {         ar[temp] = 1;       } else {         cout << i + 1;         return;       }     }     cout << -1;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int t = 1, i = 1;     while (t--) {       solve();     }     return 0;   }