#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   int n, q, a[N], node[4 * N];   vector<int> pos[N];   void init(int i, int l, int r) {     if (l == r) {       node[i] = (a[l] == 0 ? 1e9 : a[l]);       return;     }     int m = (l + r) >> 1;     init(i << 1, l, m);     init(i << 1 | 1, m + 1, r);     node[i] = min(node[i << 1], node[i << 1 | 1]);   }   int get(int i, int l, int r, int a, int b) {     if (l > r || a > r || b < l) return (int)1e9;     if (a <= l && r <= b) return node[i];     int m = (l + r) >> 1;     return min(get(i << 1, l, m, a, b), get(i << 1 | 1, m + 1, r, a, b));   }   int main() {     scanf( %d %d , &n, &q);     bool f = false;     bool zero = false;     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       if (a[i] == q) f = true;       if (a[i])         pos[a[i]].push_back(i);       else         zero = true;     }     if (!f && !zero) return !printf( NO );     init(1, 1, n);     for (int i = 1; i <= q; i++) {       if (pos[i].size() > 0) {         if (get(1, 1, n, pos[i][0], pos[i][pos[i].size() - 1]) < i)           return !printf( NO );       }     }     puts( YES );     int l = 1;     while (l <= n) {       while (l <= n && a[l]) l++;       int r = l;       while (r <= n && !a[r]) r++;       if (l > 1) {         for (int j = l; j < r; j++) a[j] = f ? a[l - 1] : q;         if (!f) f = true;       } else if (r <= n) {         for (int j = l; j < r; j++) a[j] = f ? a[r] : q;         if (!f) f = true;       } else         for (int j = l; j < r; j++) a[j] = q;       l = r;     }     for (int i = 1; i <= n; i++) printf( %d  , a[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline void ckmax(T& x, T y) {     x = (y > x ? y : x);   }   template <typename T>   inline void ckmin(T& x, T y) {     x = (y < x ? y : x);   }   namespace Fread {   const int SIZE = 1 << 21;   char buf[SIZE], *S, *T;   inline char getchar() {     if (S == T) {       T = (S = buf) + fread(buf, 1, SIZE, stdin);       if (S == T) return   n ;     }     return *S++;   }   }  // namespace Fread   namespace Fwrite {   const int SIZE = 1 << 21;   char buf[SIZE], *S = buf, *T = buf + SIZE;   inline void flush() {     fwrite(buf, 1, S - buf, stdout);     S = buf;   }   inline void putchar(char c) {     *S++ = c;     if (S == T) flush();   }   struct NTR {     ~NTR() { flush(); }   } ztr;   }  // namespace Fwrite   namespace Fastio {   struct Reader {     template <typename T>     Reader& operator>>(T& x) {       char c = Fread ::getchar();       T f = 1;       while (c <  0  || c >  9 ) {         if (c ==  - ) f = -1;         c = Fread ::getchar();       }       x = 0;       while (c >=  0  && c <=  9 ) {         x = x * 10 + (c -  0 );         c = Fread ::getchar();       }       x *= f;       return *this;     }     Reader& operator>>(char& c) {       c = Fread ::getchar();       while (c ==   n  || c ==    ) c = Fread ::getchar();       return *this;     }     Reader& operator>>(char* str) {       int len = 0;       char c = Fread ::getchar();       while (c ==   n  || c ==    ) c = Fread ::getchar();       while (c !=   n  && c !=    ) {         str[len++] = c;         c = Fread ::getchar();       }       str[len] =   0 ;       return *this;     }     Reader() {}   } cin;   const char endl =   n ;   struct Writer {     template <typename T>     Writer& operator<<(T x) {       if (x == 0) {         Fwrite ::putchar( 0 );         return *this;       }       if (x < 0) {         Fwrite ::putchar( - );         x = -x;       }       static int sta[45];       int top = 0;       while (x) {         sta[++top] = x % 10;         x /= 10;       }       while (top) {         Fwrite ::putchar(sta[top] +  0 );         --top;       }       return *this;     }     Writer& operator<<(char c) {       Fwrite ::putchar(c);       return *this;     }     Writer& operator<<(char* str) {       int cur = 0;       while (str[cur]) Fwrite ::putchar(str[cur++]);       return *this;     }     Writer& operator<<(const char* str) {       int cur = 0;       while (str[cur]) Fwrite ::putchar(str[cur++]);       return *this;     }     Writer() {}   } cout;   }  // namespace Fastio   const int MAXN = 1000, MAXM = 3e4;   const int INF = 2e9 + 233;   int n, m, s, t;   struct EDGE {     int nxt, to, w, id;   } edge[MAXM * 2 + 5];   int head[MAXN + 5], tot;   inline void add_edge(int u, int v, int w, int id) {     edge[++tot].nxt = head[u];     edge[tot].to = v;     edge[tot].w = w;     edge[tot].id = id;     head[u] = tot;   }   pair<int, pair<int, int> > ans;   int dfn[MAXN + 5], ofn[MAXN + 5], cnt_dfn;   int fa[MAXN + 5], fw[MAXN + 5], fid[MAXN + 5];   int num[MAXN + 5];   long long sum[MAXN + 5], sumid[MAXN + 5];   unsigned long long sumhash[MAXN + 5];   map<unsigned long long, bool> vis;   int id[MAXN + 5], lca[MAXN + 5];   set<pair<int, int> > S[MAXN + 5];   vector<pair<int, int> > to_del[MAXN + 5];   int an[MAXN + 5][10], dep[MAXN + 5];   int get_lca(int u, int v) {     if (dep[u] < dep[v]) swap(u, v);     for (int i = 9; i >= 0; --i) {       if (dep[an[u][i]] >= dep[v]) {         u = an[u][i];       }     }     if (u == v) return u;     for (int i = 9; i >= 0; --i) {       if (an[u][i] != an[v][i]) {         u = an[u][i];         v = an[v][i];       }     }     return an[u][0];   }   int l(int id) {     int x = edge[id * 2].to;     int y = edge[id * 2 - 1].to;     if (dfn[x] < dfn[y]) swap(x, y);     return x;   }   void dfs(int u) {     dfn[u] = ++cnt_dfn;     an[u][0] = fa[u];     dep[u] = dep[fa[u]] + 1;     for (int i = 1; i <= 9; ++i) {       an[u][i] = an[an[u][i - 1]][i - 1];     }     for (int i = head[u]; i; i = edge[i].nxt) {       int v = edge[i].to;       if (edge[i].id == fid[u]) continue;       if (!dfn[v]) {         fa[v] = u;         fw[v] = edge[i].w;         fid[v] = edge[i].id;         dfs(v);         num[u] += num[v];         sum[u] += sum[v];         sumid[u] += sumid[v];         sumhash[u] += sumhash[v];         if (((int)(S[id[u]]).size()) < ((int)(S[id[v]]).size())) {           swap(id[u], id[v]);         }         for (set<pair<int, int> >::iterator it = S[id[v]].begin();              it != S[id[v]].end(); ++it) {           S[id[u]].insert(*it);         }       } else if (dfn[v] < dfn[u]) {         num[u]++;         num[v]--;         sum[u] += edge[i].w;         sum[v] -= edge[i].w;         sumid[u] += edge[i].id;         sumid[v] -= edge[i].id;         S[id[u]].insert(make_pair(dfn[u], edge[i].id));         to_del[v].push_back(make_pair(dfn[u], edge[i].id));         unsigned long long hashw =             (((unsigned long long)rand() << 30) ^ (rand() << 15) ^ rand());         while (vis[hashw]) {           hashw = (((unsigned long long)rand() << 30) ^ (rand() << 15) ^ rand());         }         vis[hashw] = 1;         sumhash[u] += hashw;         sumhash[v] -= hashw;       }     }     for (int i = 0; i < ((int)(to_del[u]).size()); ++i) {       S[id[u]].erase(to_del[u][i]);     }     assert(((int)(S[id[u]]).size()) == num[u]);     if (num[u] >= 2) {       lca[u] = get_lca(l(S[id[u]].begin()->second), l(S[id[u]].rbegin()->second));     }     ofn[u] = cnt_dfn;   }   int main() {     srand((unsigned long long)time(0) ^ (unsigned long long)(new char));     Fastio ::cin >> n >> m;     Fastio ::cin >> s >> t;     for (int i = 1; i <= m; ++i) {       int u, v, w;       Fastio ::cin >> u >> v >> w;       add_edge(u, v, w, i);       add_edge(v, u, w, i);     }     for (int i = 1; i <= n; ++i) {       id[i] = i;     }     ans = make_pair(INF, make_pair(INF, INF));     dfs(s);     if (!dfn[t]) {       Fastio ::cout << 0 << Fastio ::endl;       Fastio ::cout << 0 << Fastio ::endl;       Fastio ::cout << Fastio ::endl;       return 0;     }     for (int u = t; u != s; u = fa[u]) {       if (num[u] == 0) {         ckmin(ans, make_pair(fw[u], make_pair(fid[u], 0)));       } else if (num[u] == 1) {         ckmin(ans,               make_pair(fw[u] + (int)sum[u], make_pair(fid[u], (int)sumid[u])));         int x = l(sumid[u]);         for (int v = x; v != u; v = fa[v]) {           if (num[v] == 1) {             if (dfn[get_lca(t, x)] < dfn[v]) {               ckmin(ans, make_pair(fw[u] + fw[v], make_pair(fid[u], fid[v])));             }           }         }       } else {         int x = lca[u];         for (int v = x; v != u; v = fa[v]) {           if (num[u] == num[v] && sum[u] == sum[v] && sumid[u] == sumid[v] &&               sumhash[u] == sumhash[v]) {             if (dfn[get_lca(t, x)] < dfn[v]) {               ckmin(ans, make_pair(fw[u] + fw[v], make_pair(fid[u], fid[v])));             }           }         }       }     }     if (ans.first == INF) {       Fastio ::cout << -1 << Fastio ::endl;       return 0;     }     Fastio ::cout << ans.first << Fastio ::endl;     if (ans.second.second == 0) {       Fastio ::cout << 1 << Fastio ::endl;       Fastio ::cout << ans.second.first << Fastio ::endl;     } else {       Fastio ::cout << 2 << Fastio ::endl;       Fastio ::cout << ans.second.first <<     << ans.second.second                     << Fastio ::endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     long long a, f, sec, t = 0, h = 0;     cin >> a;     vector<long long> par;     vector<long long> m;     for (int i = 0; i < s.length(); i++) {       if (s[i - 1] == s[i]) {         h++;       }       par.push_back(h);     }     for (int i = 0; i < a; i++) {       cin >> f >> sec;       m.push_back(par[sec - 1] - par[f - 1]);     }     for (int i = 0; i < a; i++) {       cout << m[i] << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   long long dp[2];   void solve() {     long long n;     cin >> n;     for (int i = 0; i < n; i++) {       dp[i % 2] = dp[i % 2] + dp[!(i % 2)] + 1;       if (dp[i % 2] > 1000000007) dp[i % 2] %= 1000000007;     }     cout << (dp[0] + dp[1] + 1000000007) % (1000000007);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     ;     solve();   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, t;     cin >> n >> t;     int* time = new int[n];     for (int i = 0; i < n; i++) {       cin >> time[i];     }     int sum = 0, count = 0;     int ans = INT_MIN;     for (int i = 0; i < n; i++) {       if (sum + time[i] <= t) {         sum += time[i];         count++;       } else {         sum = sum - time[i - count] + time[i];       }       ans = max(ans, count);     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   vector<int> a;   int was[100100];   int t[100100];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n;     for (int i = 1; i <= 2 * n; i++) {       int x;       cin >> x;       a.push_back(x);     }     vector<int> ans;     int cnt = 0;     for (int i = 0; i < 2 * n; i++) {       if (!was[a[i]]) {         t[a[i]] = i;         ans.push_back(a[i]);         was[a[i]] = true;       } else {         was[a[i]] = true;         cnt += i - t[a[i]] - 1;         ans.insert(ans.begin() + t[a[i]] + 1, a[i]);         for (int j = 0; j < ans.size(); j++) {           t[ans[j]] = j;         }       }     }     cout << cnt;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> tab[100100], ans;   int n, ls[10];   bool used[100100];   bool chek(int a, int b) {     for (int i = 0; i < 4; i++)       if (tab[a][i] == b) return true;     return false;   }   int main() {     scanf( %d , &n);     for (int i = 0; i < n + n; i++) {       int a, b;       scanf( %d%d , &a, &b);       if (a == b) {         puts( -1 );         return 0;       }       tab[a].push_back(b);       tab[b].push_back(a);     }     for (int i = 1; i <= n; i++) {       if (tab[i].size() != 4) {         puts( -1 );         return 0;       }     }     if (n <= 10) {       int ar[30] = {};       for (int i = 0; i < n; i++) ar[i] = i + 1;       do {         ar[n] = ar[0];         ar[n + 1] = ar[1];         bool ok = true;         for (int i = 0; i < n; i++) {           if (!chek(ar[i], ar[i + 1]) || !chek(ar[i], ar[i + 2])) {             ok = false;             break;           }         }         if (ok) {           for (int i = 0; i < n; i++)             printf( %d%c , ar[i], i == n - 1 ?   n  :    );           return 0;         }       } while (std::next_permutation(ar, ar + n));       puts( -1 );       return 0;     }     int start = 1, pre = -1;     while (!used[start]) {       used[start] = true;       ans.push_back(start);       int nxt = start;       for (int i = 0; i < 4; i++) {         int cnt = 0;         for (int j = 0; j < 4; j++)           if (chek(tab[start][i], tab[start][j])) cnt++;         if (cnt == 2 && tab[start][i] != pre) {           nxt = tab[start][i];           break;         }       }       if (nxt == start) {         puts( -1 );         return 0;       }       pre = start;       start = nxt;     }     if ((int)ans.size() < n) {       puts( -1 );       return 0;     }     ans.push_back(ans[0]);     ans.push_back(ans[1]);     for (int i = 0; i < n; i++) {       if (!chek(ans[i], ans[i + 1]) || !chek(ans[i], ans[i + 2])) {         puts( -1 );         return 0;       }     }     for (int i = 0; i < n; i++) printf( %d%c , ans[i], i == n - 1 ?   n  :    );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, q, sum, x;   int main(void) {     scanf( %lld%lld , &n, &q);     while (q--) {       scanf( %lld , &x);       while (x % 2 == 0) {         sum = (x + 1) / 2 + 1, sum = n - sum, x += sum + 1;       }       printf( %lld n , x / 2 + 1);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   set<pair<int, int> > s[2];   bool eq(pair<int, int> a, pair<int, int> b) {     return (a.first == b.first && a.second == b.second);   }   int main() {     int n, m, i, a, b, j;     scanf( %d%d , &n, &m);     for (i = 0; i < n; i++) {       scanf( %d%d , &a, &b);       if (b < a) swap(a, b);       s[0].insert(make_pair(a, b));     }     for (i = 0; i < m; i++) {       scanf( %d%d , &a, &b);       if (b < a) swap(a, b);       s[1].insert(make_pair(a, b));     }     set<int> ans;     for (auto i : s[0])       for (auto j : s[1]) {         if (i.first == j.first && i.second == j.second)           continue;         else if (i.first != j.first && i.first != j.second &&                  i.second != j.first && i.second != j.second)           continue;         else if (i.first == j.first) {           for (auto k : s[0]) {             if (eq(k, j)) continue;             if (k.first == j.second || k.second == j.second)               return !printf( -1 n );           }           for (auto k : s[1]) {             if (eq(k, i)) continue;             if (k.first == i.second || k.second == i.second)               return !printf( -1 n );           }           ans.insert(i.first);         } else if (i.first == j.second) {           for (auto k : s[0]) {             if (eq(k, j)) continue;             if (k.first == j.first || k.second == j.first) return !printf( -1 n );           }           for (auto k : s[1]) {             if (eq(k, i)) continue;             if (k.first == i.second || k.second == i.second)               return !printf( -1 n );           }           ans.insert(i.first);         } else if (i.second == j.second) {           for (auto k : s[0]) {             if (eq(k, j)) continue;             if (k.first == j.first || k.second == j.first) return !printf( -1 n );           }           for (auto k : s[1]) {             if (eq(k, i)) continue;             if (k.first == i.first || k.second == i.first) return !printf( -1 n );           }           ans.insert(i.second);         } else if (i.second == j.first) {           for (auto k : s[0]) {             if (eq(k, j)) continue;             if (k.first == j.second || k.second == j.second)               return !printf( -1 n );           }           for (auto k : s[1]) {             if (eq(k, i)) continue;             if (k.first == i.first || k.second == i.first) return !printf( -1 n );           }           ans.insert(i.second);         }       }     if ((int)ans.size() > 1) return !printf( 0 n );     cout << *ans.begin() << endl;   }


#include <bits/stdc++.h>   using namespace std;   using LL = long long;   const LL INF = 2000000000000000000L;   struct Event {     char c;     LL v;     int pos;   };   void Dfs(int pos, vector<vector<pair<LL, int>>>& edge, vector<bool>& parallel,            vector<LL>& ans) {     if (edge[pos].size() == 0) {       ans[pos] = 1;       return;     }     if (parallel[pos]) {       for (auto [vv, j] : edge[pos]) {         Dfs(j, edge, parallel, ans);       }     } else {       int j = 0;       for (int i = 0; i < edge[pos].size(); ++i) {         if (edge[pos][i].first < edge[pos][j].first) j = i;       }       Dfs(edge[pos][j].second, edge, parallel, ans);     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int times;     cin >> times;     while (times--) {       int n;       cin >> n;       string ss;       getline(cin, ss);       string s;       for (char c : ss) {         if (c ==    ) continue;         s.push_back(c);       }       vector<vector<pair<LL, int>>> edge(s.size());       vector<bool> sign(s.size());       stack<Event> st;       for (int i = 0; i < s.size(); ++i) {         if (s[i] ==  ) ) {           vector<pair<LL, int>> x;           bool parallel = false;           int j = i;           while (true) {             Event e = st.top();             st.pop();             if (e.c ==  ( ) {               j = e.pos;               break;             }             if (e.c ==  P ) parallel = true;             if (e.c ==  S ) parallel = false;             if (e.c ==  * ) {               x.push_back({e.v, e.pos});             }           }           sign[j] = parallel;           for (int i = 0; i < x.size(); ++i) {             edge[j].push_back(x[i]);           }           if (parallel) {             LL ans = 0;             for (auto [a, b] : x) ans += a;             st.push({ * , ans, j});           } else {             LL ans = INF;             for (auto [a, b] : x) ans = min(ans, a);             st.push({ * , ans, j});           }         } else {           st.push({s[i], 1, i});         }       }       vector<LL> ans(s.size());       Dfs(0, edge, sign, ans);       cout <<  REVOLTING  ;       for (int i = 0; i < s.size(); ++i) {         if (s[i] ==  * ) cout << ans[i] * n * st.top().v <<    ;       }       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     int *arr = new int[n];     for (int i = 0; i < n; i++) cin >> arr[i];     sort(arr, arr + n);     reverse(arr, arr + n);     cout << arr[k - 1];     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int basecon(int n, int b);   int gcd(int a, int b) {     if (b == 0)       return a;     else       return gcd(b, a % b);   }   int basecon(int n, int b) {     int sum = 0;     while (n) {       sum = sum + (n % b);       n = n / b;     }     return sum;   }   int main() {     int n, sum = 0, y, g;     cin >> n;     y = n - 2;     for (int i = 2; i < n; ++i) {       sum = sum + basecon(n, i);     }     g = gcd(sum, y);     sum = sum / g;     y = y / g;     cout << sum <<  /  << y << endl;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> v, ans;   void op(int i) {     int x = v[i + 2];     v[i + 2] = v[i + 1];     v[i + 1] = v[i];     v[i] = x;     if (ans.size() >= 2 && ans[ans.size() - 1] == i + 1 &&         ans[ans.size() - 2] == i + 1)       ans.pop_back(), ans.pop_back();     else       ans.push_back(i + 1);   }   void reach(int x, int y) {     while (y > x + 1) op(y - 2), y -= 2;     if (y == x + 1) op(y - 1), op(y - 1);   }   int main(int argc, char **argv) {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     while (t--) {       int n, st = 0, temp = 0;       ans.clear();       cin >> n;       v.resize(n);       vector<int> ar(501, -1);       int val = -1, x, y;       for (int i = 0; i < n; i++) {         cin >> v[i];         if (ar[v[i]] != -1) val = v[i], x = ar[v[i]], y = i;         ar[v[i]] = i;       }       if (val != -1) v[x] = v[y] = 2000;       while (n - st > 3) {         int mi = 1000, in;         for (int j = st; j < n; j++)           if (v[j] < mi) mi = v[j], in = j;         reach(st, in);         st++;       }       if (val == -1) {         while (!(v[st] <= v[st + 1] && v[st + 1] <= v[st + 2])) {           op(st), temp++;           if (temp > 5) {             cout << -1 << endl;             goto brk;           }         }       } else {         while (v[st + 1] != 2000 || v[st + 2] != 2000) op(st);         while (st >= 0 && val < v[st]) op(st), op(st), st--;       }       cout << ans.size() << endl;       for (auto x : ans) cout << x <<    ;       cout << endl;     brk:;     }   }


#include <bits/stdc++.h>   using namespace std;   char a[5004][5004];   int vis[5004] = {0};   int fl = 0;   int n;   void dfs(int x, int par) {     if (fl == 1) return;     vis[x] = 1;     for (int i = 0; i < n; i++) {       if (a[x][i] ==  1  && a[i][par] ==  1 ) {         printf( %d %d %d n , par + 1, x + 1, i + 1);         fl = 1;         return;       }       if (vis[i] == 0 && a[x][i] ==  1 ) {         if (fl == 1) return;         dfs(i, x);         if (fl == 1) return;       }     }   }   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %s , a[i]);     }     for (int i = 0; i < n; i++) {       if (vis[i] == 0) {         dfs(i, i);       }     }     if (fl == 0) {       printf( -1 n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e3 + 20;   bool A[maxn][maxn];   int d[maxn];   vector<pair<int, int> > ans;   void solve(set<int> &a) {     if ((int)a.size() == 1) {       int k = *a.begin();       for (int i = 0; i < k + 1; i++)         for (int j = i + 1; j < k + 1; j++) A[i][j] = A[j][i] = 1;       return;     }     set<int> tmp;     int k = *a.rbegin(), mn = *a.begin();     for (auto x : a)       if (x != k) tmp.insert(k - x);     solve(tmp);     for (int i = 0; i <= k - mn; i++)       for (int j = i + 1; j <= k - mn; j++)         A[i][j] = !A[i][j], A[j][i] = !A[j][i];     for (int i = 0; i <= k - mn; i++)       for (int j = k - mn + 1; j <= k; j++) A[i][j] = A[j][i] = 1;     for (int i = k - mn + 1; i <= k; i++)       for (int j = i + 1; j <= k; j++) A[i][j] = A[j][i] = 1;   }   int main() {     int m;     cin >> m;     set<int> tmp;     for (int i = 0; i < m; i++) cin >> d[i], tmp.insert(d[i]);     solve(tmp);     for (int i = 0; i <= d[m - 1]; i++)       for (int j = i + 1; j <= d[m - 1]; j++)         if (A[i][j]) ans.push_back({i, j});     printf( %d n , (int)ans.size());     for (auto x : ans) printf( %d %d n , x.first + 1, x.second + 1);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long int n, m, i;     cin >> n >> m;     long long int arr[n + 5];     map<long long int, long long int> ma;     queue<long long int> q;     for (i = 0; i < n; i++) {       cin >> arr[i];       ma[arr[i]] = 0;       q.push(arr[i]);     }     long long int result = 0, cnt = 0;     long long int ans[m + 5];     while (!q.empty()) {       if (cnt >= m) break;       long long int x = q.front();       if (!ma.count(x + 1)) {         q.push(x + 1);         ans[cnt] = x + 1;         ma[x + 1] = ma[x] + 1;         result += ma[x + 1];         cnt++;       }       if (cnt >= m) break;       if (!ma.count(x - 1)) {         q.push(x - 1);         ans[cnt] = x - 1;         ma[x - 1] = ma[x] + 1;         result += ma[x - 1];         cnt++;       }       q.pop();     }     cout << result <<   n ;     for (i = 0; i < m; i++) cout << ans[i] <<    ;     cout <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX_H = 100;   const int MAX_W = 100;   int hs[MAX_H], vs[MAX_W];   int ps[MAX_H][MAX_W], as[MAX_H * MAX_W];   int main() {     int h, w, q;     scanf( %d%d%d , &h, &w, &q);     for (int y = 0, p = 0; y < h; y++)       for (int x = 0; x < w; x++, p++) ps[y][x] = p;     while (q--) {       int op;       scanf( %d , &op);       if (op == 1) {         int y;         scanf( %d , &y);         y--;         int tp = ps[y][0];         for (int x = 1; x < w; x++) ps[y][x - 1] = ps[y][x];         ps[y][w - 1] = tp;       } else if (op == 2) {         int x;         scanf( %d , &x);         x--;         int tp = ps[0][x];         for (int y = 1; y < h; y++) ps[y - 1][x] = ps[y][x];         ps[h - 1][x] = tp;       } else {         int y, x, v;         scanf( %d%d%d , &y, &x, &v);         y--, x--;         as[ps[y][x]] = v;       }     }     for (int y = 0, p = 0; y < h; y++)       for (int x = 0; x < w; x++, p++) {         printf( %d , as[p]);         putchar(x + 1 < w ?     :   n );       }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 1000000000000000000;   struct fun {     long long a, b, nr;   };   void Dodaj(deque<fun>& D, fun nowy) {     while (D.size() >= 2) {       fun ost = D.front();       D.pop_front();       fun przed = D.front();       if ((ost.b - nowy.b) * (ost.a - przed.a) >           (nowy.a - ost.a) * (przed.b - ost.b)) {         D.push_front(ost);         break;       }     }     D.push_front(nowy);   }   int Pytaj(deque<fun>& D, long long x) {     while (D.size() >= 2) {       fun ost = D.back();       D.pop_back();       fun przed = D.back();       if (ost.a * x + ost.b < przed.a * x + przed.b) {         D.push_back(ost);         break;       }     }     return D.back().nr;   }   int main() {     ios_base::sync_with_stdio(0);     int n, m, p;     cin >> n >> m >> p;     vector<long long> s(n);     s[0] = 0;     for (int i = 1; i < n; ++i) {       cin >> s[i];       s[i] += s[i - 1];     }     vector<long long> a(m);     for (int i = 0; i < m; ++i) {       int h, t;       cin >> h >> t;       --h;       a[i] = t - s[h];     }     sort(a.begin(), a.end());     vector<long long> prefA(m);     prefA[0] = a[0];     for (int i = 1; i < m; ++i) prefA[i] = prefA[i - 1] + a[i];     vector<vector<long long> > dp(p, vector<long long>(m, INF));     for (int i = 0; i < m; ++i) dp[0][i] = a[i] * (i + 1) - prefA[i];     for (int i = 1; i < p; ++i) {       deque<fun> D;       Dodaj(D, {-(i - 1), dp[i - 1][i - 1] + prefA[i - 1], i - 1});       for (int j = i; j < m; ++j) {         int nr = Pytaj(D, a[j]);         dp[i][j] = dp[i - 1][nr] + a[j] * (j - nr) - prefA[j] + prefA[nr];         Dodaj(D, {-j, dp[i - 1][j] + prefA[j], j});       }     }     long long odp = INF;     for (int i = 0; i < p; ++i) odp = min(odp, dp[i][m - 1]);     cout << odp;     return 0;   }


#include <bits/stdc++.h>   using std::abs;   using std::cerr;   using std::cin;   using std::cout;   using std::map;   using std::max;   using std::min;   using std::pair;   using std::set;   using std::string;   using std::swap;   using std::vector;   using ll = long long;   using uint = unsigned int;   using pii = pair<int, int>;   using pll = pair<ll, ll>;   template <typename T>   void err(vector<string>::iterator it, T a) {     cerr << it->substr((*it)[0] ==    ) <<   =   << a <<   n ;   }   template <typename T, typename... Ts>   void err(vector<string>::iterator it, T a, Ts... as) {     cerr << it->substr((*it)[0] ==    ) <<   =   << a <<  ,  ;     err(++it, as...);   }   struct init {     init() {       cin.tie(0);       std::iostream::sync_with_stdio(0);       cout << std::fixed << std::setprecision(10);       cerr << std::fixed << std::setprecision(10);       srand(228);     }     ~init() {       cerr <<  Time elapsed:   << 1.0 * (double)clock() / CLOCKS_PER_SEC            <<  s. n ;     }   } init;   const int MAXN = 1001, INF = 1e9 + 7;   int ans[MAXN];   vector<int> wo[MAXN];   int ret[20][MAXN];   int main() {     int n;     cin >> n;     for (int step = 1, pw = 0; step < n; step *= 2, ++pw) {       vector<int> q0, q1;       for (int i = 0; i < n; i += step * 2) {         for (int j = 0; j < step && i + j < n; ++j) {           wo[i + j].emplace_back(pw * 2 + 1);           q0.emplace_back(i + j);         }         for (int j = step; j < step + step && i + j < n; ++j) {           q1.emplace_back(i + j);           wo[i + j].emplace_back(pw * 2);         }       }       if (!q0.empty()) {         cout << q0.size() <<   n ;         for (int i : q0) cout << i + 1 <<    ;         cout << std::endl;         for (int i = 0; i < n; ++i) cin >> ret[pw * 2][i];       }       if (!q1.empty()) {         cout << q1.size() <<   n ;         for (int i : q1) cout << i + 1 <<    ;         cout << std::endl;         for (int i = 0; i < n; ++i) cin >> ret[pw * 2 + 1][i];       }     }     cout <<  -1 n ;     for (int i = 0; i < n; ++i) {       int mn = INF;       for (int j : wo[i]) mn = min(mn, ret[j][i]);       cout << mn <<    ;     }     cout << std::endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long vis[80];   long long prime[80] = {0};   long long a[200000];   long long fc[80][200000] = {{0}};   int n;   int pnum;   int get_primes(int m) {     memset(vis, 0, sizeof(vis));     int cnt = 1;     for (int i = 2; i < m; i++) {       if (!vis[i]) {         prime[cnt++] = i;         for (int j = i * i; j < m; j += i) vis[j] = 1;       }     }     return cnt;   }   void change(long long k, long long g) {     for (int i = 1; i <= pnum;) {       if (k % prime[i] == 0) {         fc[i][g] ^= 1;         k /= prime[i];       } else         i++;     }     return;   }   long long gauss() {     long long g = 0;     int i, j;     for (j = 1; j <= n && g < pnum; j++) {       for (i = g + 1; i <= pnum; i++)         if (fc[i][j] == 1) break;       if (i <= pnum) {         g++;         for (int p = j; p <= n; p++) swap(fc[g][p], fc[i][p]);         for (int p = g + 1; p <= pnum; p++) {           if (fc[p][j] == 1) {             for (int q = j; q <= n; q++) fc[p][q] ^= fc[g][q];           }         }       }     }     return g;   }   long long qpow(long long a, long long b, long long m) {     long long ans = 1;     while (b) {       if (b & 1) {         ans = (ans * a) % m;         b--;       }       b /= 2;       a = a * a % m;     }     return ans;   }   int main() {     int cas = 1;     int t = 1;     get_primes(70);     pnum = 19;     {       memset(fc, 0, sizeof(fc));       cin >> n;       for (int i = 1; i <= n; i++) cin >> a[i], change(a[i], i);       int r = gauss();       long long ans = qpow(2, (long long)(n - r), 1000000007) - 1;       printf( %lld n , ans);     }   }


#include <bits/stdc++.h>   using namespace std;   long long MOD = 1e9 + 7;   long long FastPower(long long x, long long y) {     long long res = 1;     x = x % MOD;     while (y > 0) {       if (y & 1) res = (res * x) % MOD;       y = y >> 1;       x = (x * x) % MOD;     }     return res;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n, k;     string s;     cin >> s;     n = s.size();     long long x = 0, y = 0;     y = FastPower(2, n - 1);     for (int i = 0, j = n - 1; i < n; i++, j--) {       if (s[j] ==  1 ) {         x += FastPower(2, i);         x %= MOD;       }     }     cout << (x * y) % MOD;     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   string s[100000];   int u = 0;   char nonu[2][5] = { etr ,  etra };   int nonul[2] = {3, 4};   char adj[2][10] = { lios ,  liala };   int adjl[2] = {4, 5};   char ver[2][10] = { initis ,  inites };   int verl[2] = {6, 6};   bool isn(int v, int &u) {     int len = s[v].length();     for (int j = 0; j < 2; j++)       if (len >= nonul[j]) {         bool f = false;         for (int i = 0; i < nonul[j]; i++)           if (s[v][len - nonul[j] + i] != nonu[j][i]) {             f = true;             break;           }         if (!f) {           u = j;           return true;         }       }     return false;   }   bool judge(int v) {     int len = s[v].length();     for (int j = 0; j < 2; j++)       if (len >= nonul[j]) {         bool f = false;         for (int i = 0; i < nonul[j]; i++)           if (s[v][len - nonul[j] + i] != nonu[j][i]) {             f = true;             break;           }         if (!f) return true;       }     for (int j = 0; j < 2; j++)       if (len >= adjl[j]) {         bool f = false;         for (int i = 0; i < adjl[j]; i++)           if (s[v][len - adjl[j] + i] != adj[j][i]) {             f = true;             break;           }         if (!f) return true;       }     for (int j = 0; j < 2; j++)       if (len >= verl[j]) {         bool f = false;         for (int i = 0; i < verl[j]; i++)           if (s[v][len - verl[j] + i] != ver[j][i]) {             f = true;             break;           }         if (!f) return true;       }     return false;   }   bool judge1(int v, int u) {     int len = s[v].length();     for (int j = 0; j < 2; j++)       if (len >= adjl[j]) {         bool f = false;         for (int i = 0; i < adjl[j]; i++)           if (s[v][len - adjl[j] + i] != adj[j][i]) {             f = true;             break;           }         if (!f) {           if (j != u)             return false;           else             return true;         }       }     for (int j = 0; j < 2; j++)       if (len >= verl[j]) {         bool f = false;         for (int i = 0; i < verl[j]; i++)           if (s[v][len - verl[j] + i] != ver[j][i]) {             f = true;             break;           }         if (!f) return false;       }     return false;   }   bool judge2(int v, int u) {     int len = s[v].length();     for (int j = 0; j < 2; j++)       if (len >= adjl[j]) {         bool f = false;         for (int i = 0; i < adjl[j]; i++)           if (s[v][len - adjl[j] + i] != adj[j][i]) {             f = true;             break;           }         if (!f) return false;       }     for (int j = 0; j < 2; j++)       if (len >= verl[j]) {         bool f = false;         for (int i = 0; i < verl[j]; i++)           if (s[v][len - verl[j] + i] != ver[j][i]) {             f = true;             break;           }         if (!f) {           if (j != u)             return false;           else             return true;         }       }     return false;   }   int main() {     int n = 0;     while (cin >> s[n]) n++;     if (n == 1 && judge(0)) {       cout <<  YES  << endl;       return 0;     }     bool f = false;     int y = 0;     for (int i = 0; i < n; i++)       if (isn(i, u)) {         y = i;         if (!f)           f = true;         else {           cout <<  NO  << endl;           return 0;         }       }     if (!f) {       cout <<  NO  << endl;       return 0;     }     for (int i = 0; i < y; i++)       if (!judge1(i, u)) {         cout <<  NO  << endl;         return 0;       }     for (int i = y + 1; i < n; i++)       if (!judge2(i, u)) {         cout <<  NO  << endl;         return 0;       }     cout <<  YES  << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int t;     cin >> t;     while (t--) {       long long int n;       cin >> n;       long long int to = 0, thr = 0;       while (n % 2 == 0) {         to++;         n = n / 2;       }       while (n % 3 == 0) {         thr++;         n = n / 3;       }       if (n > 1) {         cout <<  -1 ;         cout <<   n ;       } else {         if (to > thr) {           cout <<  -1 ;           cout <<   n ;         } else {           cout << 2 * thr - to;           cout <<   n ;         }       }     }   }


#include <bits/stdc++.h>   int cmp(const void *a, const void *b) { return (*(int *)a - *(int *)b); }   int main() {     char str[100005];     int i, j, k;     scanf( %s , str);     int l = strlen(str);     int cB = 0, cb = 0, cu = 0, ca = 0, cs = 0, cr = 0, cl = 0;     for (i = 0; i < l; i++) {       if (str[i] ==  B ) {         cB++;       } else if (str[i] ==  b ) {         cb++;       } else if (str[i] ==  u ) {         cu++;       } else if (str[i] ==  a ) {         ca++;       } else if (str[i] ==  s ) {         cs++;       } else if (str[i] ==  l ) {         cl++;       } else if (str[i] ==  r ) {         cr++;       } else {         continue;       }     }     int arry[5];     arry[0] = cB;     arry[1] = cs;     arry[2] = cr;     arry[3] = cl;     arry[4] = cb;     qsort(arry, 5, sizeof(int), cmp);     int m1 = arry[0];     int m2;     if (cu <= ca) {       m2 = cu;     } else {       m2 = ca;     }     int ans;     if (m2 >= 2 * m1) {       ans = m1;     } else if (m2 < 2 * m1) {       ans = m2 / 2;     }     printf( %d n , ans);     return (0);   }


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


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const int MAXN = 1111111;   const int N = 105;   const int M = 25;   int cmp(int a, int b) { return a > b; }   int n, m, s[N], c[M], t[M], dp[MAXN], st;   void init() {     memset(dp, INF, sizeof(dp));     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %d , &s[i]);     scanf( %d%*c , &m);     for (int j = 0; j < m; j++) scanf( %c%*c%d%*c , &c[j], &t[j]);   }   int DP(int state, int num) {     if (dp[state] != INF) return dp[state];     int &ans = dp[state];     ans = 0;     if (c[num] ==  p ) {       int bit;       for (bit = 0; bit < m; bit++)         if ((state & (1 << bit))) break;       if (t[num] == 1)         ans = (DP((state ^ (1 << bit)), num + 1) + s[bit]);       else         ans = (DP((state ^ (1 << bit)), num + 1) - s[bit]);     } else if (c[num] ==  b ) {       if (t[num] == 1)         ans = -INF;       else         ans = INF;       for (int i = 0; i < m; i++) {         if ((state & (1 << i))) {           if (t[num] == 1)             ans = (ans) > (DP((state ^ (1 << i)), num + 1))                       ? (ans)                       : (DP((state ^ (1 << i)), num + 1));           else             ans = (ans) < (DP((state ^ (1 << i)), num + 1))                       ? (ans)                       : (DP((state ^ (1 << i)), num + 1));         }       }     }     return ans;   }   void solve() {     sort(s, s + n, cmp);     st = (1 << m) - 1;     printf( %d n , DP(st, 0));   }   int main() {     init();     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long a[] = {0, 1, 2, 9, 64, 625, 7776, 117649, 2097152};   const long long M = 1000000007ll;   int main(void) {     std::ios::sync_with_stdio(false);     long long k, n, m, t;     while (cin >> n >> m) {       n -= m;       t = 1;       k = n;       while (k) {         if (k & 1) t = t * n % M;         n = n * n % M;         k >>= 1;       }       cout << a[m] * t % M << endl;     }     return 0;   }


#include <bits/stdc++.h>   const long long N = 1e5 + 5;   using namespace std;   struct node {     long long sum[10], lazy[10];   } lv[4 * N];   long long n, a[N], q;   void init(long long i, long long l, long long r) {     for (long long k = 0; k < 10; k++) lv[i].lazy[k] = k;     if (l == r) {       long long x = 1, z;       while (a[l] != 0) {         z = a[l] % 10;         lv[i].sum[z] += x;         x *= 10;         a[l] /= 10;       }       return;     }     long long mid = (l + r) / 2;     init(i * 2, l, mid);     init(i * 2 + 1, mid + 1, r);     for (long long k = 0; k < 10; k++)       lv[i].sum[k] = lv[i * 2].sum[k] + lv[i * 2 + 1].sum[k];   }   void dolazy(long long i, long long l, long long r) {     if (l != r) {       for (long long k = 0; k < 10; k++) {         lv[i * 2].lazy[k] = lv[i].lazy[lv[i * 2].lazy[k]];         lv[i * 2 + 1].lazy[k] = lv[i].lazy[lv[i * 2 + 1].lazy[k]];       }     }     long long cur[10];     for (long long k = 0; k < 10; k++) cur[k] = 0;     for (long long k = 0; k < 10; k++) cur[lv[i].lazy[k]] += lv[i].sum[k];     for (long long k = 0; k < 10; k++) lv[i].sum[k] = cur[k], lv[i].lazy[k] = k;   }   void update(long long i, long long l, long long r, long long L, long long R,               long long x, long long y) {     dolazy(i, l, r);     if (L > r || l > R) return;     if (L <= l && r <= R) {       lv[i].lazy[x] = y;       dolazy(i, l, r);       return;     }     long long mid = (l + r) / 2;     update(i * 2, l, mid, L, R, x, y);     update(i * 2 + 1, mid + 1, r, L, R, x, y);     for (long long k = 0; k < 10; k++)       lv[i].sum[k] = lv[i * 2].sum[k] + lv[i * 2 + 1].sum[k];   }   long long get(long long i, long long l, long long r, long long L, long long R) {     dolazy(i, l, r);     if (L > r || l > R) return 0;     if (L <= l && r <= R) {       long long ans = 0;       for (int k = 0; k < 10; k++) ans += lv[i].sum[k] * k;       return ans;     }     long long mid = (l + r) / 2;     return get(i * 2, l, mid, L, R) + get(i * 2 + 1, mid + 1, r, L, R);   }   int main() {     cin >> n >> q;     for (long long i = 1; i <= n; i++) cin >> a[i];     init(1, 1, n);     while (q--) {       long long query, l, r, x, y;       cin >> query >> l >> r;       if (query == 1) {         cin >> x >> y;         update(1, 1, n, l, r, x, y);       } else {         cout << get(1, 1, n, l, r) <<   n ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   void init() { return; }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     init();     int n;     cin >> n;     long long int a[n];     for (int i = 0; i < n; i++) {       cin >> a[i];     }     long long int ans = 0ll, prev = 0ll;     for (int i = 0; i < n; i++) {       long long int temp1 = min(a[i] / 2, prev);       long long int temp2 = (a[i] - 2 * temp1) / 3;       ans += temp1 + temp2;       prev += a[i] - 3 * (temp1 + temp2);     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, t;     cin >> n >> m;     vector<int> f;     for (int i = 0; i < m; i++) {       cin >> t;       f.insert(f.begin(), t);     }     for (int i = 0; i < m; i++) {       t = i;       for (int j = i + 1; j < m; j++)         if (f[j] > f[t]) t = j;       swap(f[i], f[t]);     }     t = f[0] - f[n - 1];     for (int i = 0; i < m - n + 1; i++) {       if ((f[i] - f[i + n - 1]) < t) t = f[i] - f[i + n - 1];     }     cout << t;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int ALL = (1 << 30) - 1;   int ans[(1 << 22) + 10];   int a[int(1e6) + 2];   int n;   void add(int x, int val) {     if (ans[x] != 0) return;     ans[x] = val;     for (int i = 0; i < 22; ++i) add(x & (ALL - (1 << i)), val);   }   void task() {     scanf( %d , &n);     for (int i = 0; i < n; ++i) scanf( %d , &a[i]);     for (int i = 0; i < n; ++i) {       int x = 0;       for (int j = 0; j < 22; ++j)         if (!(a[i] & (1 << j))) x += 1 << j;       add(x, a[i]);     }     for (int i = 0; i < n; ++i) printf( %d  , ans[a[i]] ? ans[a[i]] : -1);   }   int main() {     task();     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   const int N = 4e5 + 10;   const int inf = 1e9;   int main() {     ios::sync_with_stdio(false);     string s;     cin >> s;     s =     + s;     int i;     int ans = 0;     int sum = 0;     for (i = 1; i < (int)s.size(); i++) {       if (s[i] ==  M ) {         sum++;       }       if (s[i] ==  F  && sum > 0) {         ans = max(ans + 1, sum);       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int a, b, c, d, e, f;     cin >> a >> b >> c >> d >> e >> f;     long long int minbcd;     minbcd = min(b, min(c, d));     long long int cnt;     cnt = minbcd * f;     long long int x;     x = d - minbcd;     cnt = cnt + (min(x, a) * e);     long long int minad;     minad = min(a, d);     long long int cnt1;     cnt1 = minad * e;     long long int y;     y = d - minad;     long long int minbcy;     minbcy = min(b, min(c, y));     cnt1 = cnt1 + (minbcy * f);     if (cnt >= cnt1)       cout << cnt;     else       cout << cnt1;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char inp1[100005];   char inp2[100005];   char res[100005];   bool mk[100005];   bool mk1[100005];   char getDiff(char a, char b, char c) {     for (int i = 0; i < 26; i++)       if (a != ( a  + i) && b != ( a  + i) && c != ( a  + i)) return ( a  + i);     return -1;   }   int main() {     int n, t, s = 0;     cin >> n >> t;     cin >> inp1 >> inp2;     memset(mk, 0, sizeof mk);     memset(mk1, 0, sizeof mk1);     for (int i = 0; i < n; i++)       if (inp1[i] != inp2[i]) s++;     res[n] =   0 ;     if (s > 2 * t) {       cout << -1 << endl;       return 0;     }     if (s <= 2 * t && s >= t) {       int c = 0;       for (int i = 0; i < n; i++)         if (inp1[i] != inp2[i] && c < t) mk[i] = true, c++;       c = 0;       for (int i = n - 1; i >= 0; i--)         if (inp1[i] != inp2[i] && c < t) mk1[i] = true, c++;       for (int i = 0; i < n; i++) {         if (mk[i] == true && mk1[i] == true)           res[i] = getDiff(inp1[i], inp2[i], 0);         else if (mk[i])           res[i] = inp2[i];         else if (mk1[i])           res[i] = inp1[i];         else           res[i] = inp1[i];       }       cout << res << endl;       return 0;     }     if (s < t) {       int c = 0;       for (int i = 0; i < n; i++) {         if (inp1[i] != inp2[i]) res[i] = getDiff(inp1[i], inp2[i], 0), c++;       }       for (int i = 0; i < n; i++) {         if (inp1[i] == inp2[i] && c < t)           res[i] = getDiff(inp1[i], inp2[i], 0), c++;         else if (inp1[i] == inp2[i])           res[i] = inp1[i];       }       cout << res << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int m, n, k;   pair<long long, long long> ptsx[100005];   pair<long long, long long> ptsy[100005];   bool removed[100005];   long long get(int l, int r, int u, int d, int dep) {     while (removed[ptsx[l].second]) l++;     while (removed[ptsx[r].second]) r--;     while (removed[ptsy[u].second]) u++;     while (removed[ptsy[d].second]) d--;     if (dep == k) {       long long xd = ptsx[r].first - ptsx[l].first;       long long yd = ptsy[d].first - ptsy[u].first;       if (xd == 0) xd++;       if (yd == 0) yd++;       return ((xd + 1) / 2) * ((yd + 1) / 2);     }     long long ans = (1LL) << 62;     removed[ptsx[l].second] = true;     ans = min(ans, get(l + 1, r, u, d, dep + 1));     removed[ptsx[l].second] = false;     removed[ptsx[r].second] = true;     ans = min(ans, get(l, r - 1, u, d, dep + 1));     removed[ptsx[r].second] = false;     removed[ptsy[u].second] = true;     ans = min(ans, get(l, r, u + 1, d, dep + 1));     removed[ptsy[u].second] = false;     removed[ptsy[d].second] = true;     ans = min(ans, get(l, r, u, d - 1, dep + 1));     removed[ptsy[d].second] = false;     return ans;   }   int main() {     ios_base::sync_with_stdio(0);     cout << fixed << setprecision(12);     cin >> n >> k;     for (int i = 0, _i = (n); i < _i; ++i) {       int x1, y1, x2, y2;       cin >> x1 >> y1 >> x2 >> y2;       ptsx[i] = make_pair(x1 + x2, i);       ptsy[i] = make_pair(y1 + y2, i);     }     sort(ptsx, ptsx + n);     sort(ptsy, ptsy + n);     cout << get(0, n - 1, 0, n - 1, 0) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ld = long double;   using pii = pair<int, int>;   using pil = pair<int, ll>;   using pli = pair<ll, int>;   using pll = pair<ll, ll>;   const ll MOD = 1e9 + 7;   const int inf = (1 << 30) - 1;   const ll INF = (1LL << 60) - 1;   const ld EPS = 1e-10;   template <typename T>   bool chmax(T &x, const T &y) {     return (x < y) ? (x = y, true) : false;   };   template <typename T>   bool chmin(T &x, const T &y) {     return (x > y) ? (x = y, true) : false;   };   int main() {     int T;     cin >> T;     while (T--) {       int N, K, L;       cin >> N >> K >> L;       int d[N];       for (int i = 0; i < N; i++) {         cin >> d[i];         d[i] = L - d[i];       }       int pos = -inf;       bool ans = true;       for (int i = 0; i < N; i++) {         if (d[i] < 0) {           ans = false;           break;         } else if (d[i] >= K)           pos = -inf;         else if (pos == -inf)           pos = -d[i];         else if (d[i] <= pos) {           ans = false;           break;         } else if (pos < -d[i])           pos = -d[i];         else           pos++;       }       cout << (ans ?  Yes  :  No ) << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   set<long long> f, l, s;   long long sf = 0, sl = 0;   long long ksum = 0, cnt = 0, kmin = 0;   void update(long long b, long long t) {     int c = l.size();     if (t == 1)       s.insert(b);     else       s.erase(b);     if (c == 1 && cnt == 0) {       ksum = kmin = *s.rbegin();       cnt = 1;       return;     }     if (c > cnt) {       if (b > kmin) {         ksum += b;       } else {         kmin = *(--s.find(kmin));         ksum += kmin;       }       cnt++;     } else if (c < cnt) {       ksum -= max(b, kmin);       if (b <= kmin) {         kmin = *s.upper_bound(kmin);       }       cnt--;     } else {       if (c == 0) return;       if (b >= kmin) {         if (t == 1) {           ksum += b - kmin;           kmin = *s.upper_bound(kmin);         } else {           kmin = *(--s.lower_bound(kmin));           ksum -= b - kmin;         }       }     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     while (n--) {       long long a, b;       cin >> a >> b;       if (a == 0) {         if (b < 0) {           f.erase(f.find(-b));         } else {           f.insert(b);         }         sf += b;       } else {         if (b < 0) {           l.erase(l.find(-b));         } else {           l.insert(b);         }         sl += b;       }       if (b < 0)         update(-b, -1);       else         update(b, 1);       if (l.size() == 0) {         cout << sf << endl;       } else if (f.size() == 0) {         cout << 2 * sl - *l.begin() << endl;       } else {         if (*f.rbegin() > *l.begin()) {           cout << sf + sl + ksum << endl;         } else {           cout << sf + 2 * sl - *l.begin() + *f.rbegin() << endl;         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     scanf( %d , &t);     int ji = 0;     while (t--) {       int n;       scanf( %d , &n);       int arr[n + 1];       int brr[n + 1];       memset(arr, 0, sizeof(arr));       memset(brr, 0, sizeof(brr));       int ls;       int size = 0;       for (int a = 0; a < n; a++) {         scanf( %d , &ls);         if (arr[ls] == 0) {           brr[size] = ls;           size++;         }         arr[ls]++;       }       int min = n;       for (int a = 0; a < size; a++) {         if (arr[brr[a]] < min) {           min = arr[brr[a]];         }       }       int num = n;       int bo = true;       for (int a = 2; a < min + 2; a++) {         ls = 0;         bo = true;         for (int b = 0; b < size; b++) {           int tt = arr[brr[b]] / a + 1;           if (arr[brr[b]] % a == 0) {             ls = ls + arr[brr[b]] / a;           } else if (arr[brr[b]] >= (tt * (a - 1)) && arr[brr[b]] <= (tt * a)) {             ls = ls + tt;           } else {             bo = false;             break;           }         }         if (bo && num > ls) {           num = ls;         }       }       printf( %d n , num);     }   }


#include <bits/stdc++.h>   int n, k, m, c, arr[100005], ans;   inline void check() {     int i = 0;     while (i < m) {       if (arr[i] == i + 1)         i++;       else         break;     }     if (i)       c += (m - i + 1), ans += (m - i);     else       c += m, ans += (m - 1);   }   int main() {     scanf( %d %d , &n, &k);     ans = c = 0;     while (k--) {       scanf( %d , &m);       for (int i = 0; i < m; ++i) scanf( %d , &arr[i]);       check();     }     ans += (c - 1);     printf( %d , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   template <class t, class u>   void chmax(t& first, u second) {     if (first < second) first = second;   }   template <class t, class u>   void chmin(t& first, u second) {     if (second < first) first = second;   }   template <class t>   using vc = vector<t>;   template <class t>   using vvc = vc<vc<t>>;   using pi = pair<ll, ll>;   using vi = vc<ll>;   template <class t, class u>   ostream& operator<<(ostream& os, const pair<t, u>& p) {     return os <<  {  << p.first <<  ,  << p.second <<  } ;   }   template <class t>   ostream& operator<<(ostream& os, const vc<t>& v) {     os <<  { ;     for (auto e : v) os << e <<  , ;     return os <<  } ;   }   using uint = unsigned;   using ull = unsigned long long;   template <ll i, class T>   void print_tuple(ostream&, const T&) {}   template <ll i, class T, class H, class... Args>   void print_tuple(ostream& os, const T& t) {     if (i) os <<  , ;     os << get<i>(t);     print_tuple<i + 1, T, Args...>(os, t);   }   template <class... Args>   ostream& operator<<(ostream& os, const tuple<Args...>& t) {     os <<  { ;     print_tuple<0, tuple<Args...>, Args...>(os, t);     return os <<  } ;   }   void print(ll x, ll suc = 1) {     cout << x;     if (suc == 1) cout <<   n ;     if (suc == 2) cout <<    ;   }   ll read() {     ll i;     cin >> i;     return i;   }   vi readvi(ll n, ll off = 0) {     vi v(n);     for (ll i = ll(0); i < ll(n); i++) v[i] = read() + off;     return v;   }   template <class T>   void print(const vector<T>& v, ll suc = 1) {     for (ll i = ll(0); i < ll(v.size()); i++)       print(v[i], i == ll(v.size()) - 1 ? suc : 2);   }   string readString() {     string s;     cin >> s;     return s;   }   template <class T>   T sq(const T& t) {     return t * t;   }   void yes(bool ex = true) {     cout <<  Yes  << endl;     if (ex) exit(0);   }   void no(bool ex = true) {     cout <<  No  << endl;     if (ex) exit(0);   }   constexpr ll ten(ll n) { return n == 0 ? 1 : ten(n - 1) * 10; }   const ll infLL = LLONG_MAX / 3;   const ll inf = infLL;   ll topbit(signed t) { return t == 0 ? -1 : 31 - __builtin_clz(t); }   ll topbit(ll t) { return t == 0 ? -1 : 63 - __builtin_clzll(t); }   ll botbit(signed first) { return first == 0 ? 32 : __builtin_ctz(first); }   ll botbit(ll first) { return first == 0 ? 64 : __builtin_ctzll(first); }   ll popcount(signed t) { return __builtin_popcount(t); }   ll popcount(ll t) { return __builtin_popcountll(t); }   bool ispow2(ll i) { return i && (i & -i) == i; }   ll mask(ll i) { return (ll(1) << i) - 1; }   bool inc(ll first, ll second, ll c) { return first <= second && second <= c; }   template <class t>   void mkuni(vc<t>& v) {     sort(v.begin(), v.end());     v.erase(unique(v.begin(), v.end()), v.end());   }   ll rand_int(ll l, ll r) {     static random_device rd;     static mt19937_64 gen(rd());     return uniform_int_distribution<ll>(l, r)(gen);   }   void priv(vi s) {     cout << s.size();     for (auto i : s) cout <<     << i + 1;     cout << endl;   }   ll ask(vi s, vi t, ll v) {     static ll num = 0;     num++;     assert(num <= 11111);     priv(s);     priv(t);     cout << v + 1 << endl;     ll res;     cin >> res;     return res;   }   void answer(vc<pi> ans) {     cout <<  ANSWER  << endl;     for (auto e : ans) cout << e.first + 1 <<     << e.second + 1 << endl;   }   const ll nmax = 510;   vi t[nmax];   bool rem[nmax];   ll tsize(ll v, ll p) {     ll ret = 1;     for (auto to : t[v])       if (to != p && !rem[to]) ret += tsize(to, v);     return ret;   }   ll findc(ll v, ll p, ll s) {     ll ret = 1, mx = 0;     for (auto to : t[v])       if (to != p && !rem[to]) {         ll f = findc(to, v, s);         if (f <= 0)           return f;         else {           ret += f;           chmax(mx, f);         }       }     chmax(mx, s - ret);     if (mx * 2 <= s)       return -v;     else       return ret;   }   signed main() {     cin.tie(0);     ios::sync_with_stdio(0);     cout << fixed << setprecision(20);     ll n;     cin >> n;     vi sz(n);     for (ll i = ll(1); i < ll(n); i++) {       vi s{0};       vi tmp(n - 1);       iota(tmp.begin(), tmp.end(), 1);       sz[i] = ask(s, tmp, i);     }     vi idx(n - 1);     iota(idx.begin(), idx.end(), 1);     sort(idx.begin(), idx.end(), [&](ll i, ll j) { return sz[i] > sz[j]; });     vc<pi> ans;     for (auto i : idx) {       memset(rem, 0, sizeof(rem));       ll cur = 0;       while (1) {         cur = -findc(cur, -1, tsize(cur, -1));         vi vs;         for (auto to : t[cur])           if (!rem[to]) vs.push_back(to);         ll lw = 0, up = vs.size() + 1;         while (up - lw > 1) {           const ll m = (lw + up) / 2;           vi s(vs.begin(), vs.begin() + m);           if (ask(s, {i}, cur) < m)             up = m;           else             lw = m;         }         if (lw == (ll)vs.size()) break;         rem[cur] = true;         cur = vs[lw];       }       t[cur].push_back(i);       t[i].push_back(cur);       ans.emplace_back(cur, i);     }     answer(ans);   }


#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-10;   struct point {     double x, y;   };   struct segment {     double a, b, c;   };   point operator+(point a, point b) { return (point){a.x + b.x, a.y + b.y}; }   point operator-(point a, point b) { return (point){a.x - b.x, a.y - b.y}; }   double operator*(point a, point b) { return a.x * b.x + a.y * b.y; }   double operator/(point a, point b) { return a.x * b.y - a.y * b.x; }   point operator*(point a, double b) { return (point){a.x * b, a.y * b}; }   point operator/(point a, double b) { return (point){a.x / b, a.y / b}; }   int T;   point I, J, K, L;   segment midline(point A, double a, double b) {     segment line;     line.a = b;     line.b = -a;     line.c = -(A.x * line.a + A.y * line.b);     return line;   }   point getpoint(segment A, segment B) {     point C;     C.x = (-A.c * B.b + B.c * A.b) / (A.a * B.b - B.a * A.b);     C.y = (-A.a * B.c + B.a * A.c) / (A.a * B.b - B.a * A.b);     return C;   }   point mirror(point A, point B) {     point C;     C = A + (B - A) * 2;     return C;   }   int zero1(double x) { return x > eps; }   int zero0(double x) { return x < -eps; }   int solve(point A, point B, point C) {     point D, E, F, G, H;     point IJ, JK, KL, LI;     segment lineAC, lineBC, lineD, lineE, lineHG;     bool ans;     ans = false;     lineAC = (segment){A.y - C.y, C.x - A.x, A / C};     lineBC = (segment){B.y - C.y, C.x - B.x, B / C};     D = (A + C) / 2;     E = (B + C) / 2;     lineD = midline(D, lineAC.a, lineAC.b);     lineE = midline(E, lineBC.a, lineBC.b);     F = getpoint(lineD, lineE);     G = mirror(E, C);     H = mirror(F, C);     lineHG = (segment){H.y - G.y, G.x - H.x, H / G};     I = getpoint(lineHG, lineD);     J = mirror(I, C);     K = mirror(J, B);     L = mirror(I, A);     IJ = J - I;     JK = K - J;     KL = L - K;     LI = I - L;     if (zero1(IJ / JK) && zero1(JK / KL) && zero1(KL / LI) && zero1(LI / IJ))       ans = true;     if (zero0(IJ / JK) && zero0(JK / KL) && zero0(KL / LI) && zero0(LI / IJ))       ans = true;     return ans;   }   void print() {     printf( YES n%.9lf %.9lf %.9lf %.9lf %.9lf %.9lf %.9lf %.9lf n , I.x, I.y,            J.x, J.y, K.x, K.y, L.x, L.y);   }   int main() {     point A, B, C;     scanf( %d , &T);     while (T--) {       scanf( %lf%lf%lf%lf%lf%lf , &A.x, &A.y, &B.x, &B.y, &C.x, &C.y);       if (solve(A, B, C))         print();       else if (solve(A, C, B))         print();       else if (solve(B, C, A))         print();       else         printf( NO n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   int a[111];   int memo[111][1 << 17];   pair<pair<int, int>, int> child[111][1 << 17];   int bt[66];   class MathFunction {    private:     long long sieve_size;     bitset<1010> bs;     vector<int> primes;       public:     int primeid[1010];     bool isPrime(long long N) {       if (N <= sieve_size) return bs[N];       for (int i = 0; i < (int)primes.size(); i++)         if (N % primes[i] == 0) return false;       return true;     }     void sieve(long long upperbound) {       sieve_size = upperbound + 1;       bs.set();       bs[0] = bs[1] = 0;       for (long long i = 2; i < sieve_size; i++) {         if (bs[i]) {           for (long long j = i * i; j < sieve_size; j += i) bs[j] = 0;           primeid[(int)i] = primes.size();           primes.push_back((int)i);         }       }     }     vector<int> primeFactors(long long N) {       vector<int> factors;       long long idx = 0, pf = primes[idx];       while (N != 1 && (pf * pf <= N)) {         while (N % pf == 0) {           N /= pf;           factors.push_back(pf);         }         pf = primes[++idx];       }       if (N != 1) factors.push_back(N);       return factors;     }   };   MathFunction mat;   int dp(int pos, int bitmask) {     if (pos == n) return 0;     if (memo[pos][bitmask] >= 0) return memo[pos][bitmask];     int q = abs(1 - a[pos]) + dp(pos + 1, bitmask);     child[pos][bitmask] =         pair<pair<int, int>, int>(pair<int, int>(pos + 1, bitmask), 1);     for (int i = 2; i < a[pos] + a[pos]; i++) {       if ((bitmask & bt[i]) == 0) {         int d = abs(i - a[pos]) + dp(pos + 1, bitmask | bt[i]);         if (d < q) {           q = d;           child[pos][bitmask] = pair<pair<int, int>, int>(               pair<int, int>(pos + 1, bitmask | bt[i]), i);         }       }     }     return memo[pos][bitmask] = q;   }   void printAns(int pos, int bitmask) {     if (pos == n) return;     pair<int, int> nx = child[pos][bitmask].first;     int val = child[pos][bitmask].second;     printf( %d  , val);     printAns(nx.first, nx.second);   }   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d , &a[i]);     }     mat.sieve(100);     bt[1] = 0;     for (int i = 2; i <= 61; i++) {       vector<int> v = mat.primeFactors(i);       int b = 0;       for (int j = 0; j < v.size(); j++) {         if (mat.primeid[v[j]] <= 15) b |= (1 << mat.primeid[v[j]]);       }       bt[i] = b;     }     memset(memo, -1, sizeof memo);     dp(0, 0);     printAns(0, 0);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using namespace std;   const long long mod2 = 998244353;   long long fpow(long long x, long long y) {     x = x % 1000000007;     long long sum = 1;     while (y) {       if (y & 1) sum = sum * x;       sum %= 1000000007;       y = y >> 1;       x = x * x;       x %= 1000000007;     }     return sum;   }   long long inv(long long a, long long m = 1000000007) {     long long c = m;     long long y = 0, x = 1;     if (m == 1) return 0;     while (a > 1) {       long long q = a / m;       long long t = m;       m = a % m, a = t;       t = y;       y = x - q * y;       x = t;     }     if (x < 0) x += c;     return x;   }   long long gcd(long long a, long long b) {     if (!a) return b;     return gcd(b % a, a);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());     long long n;     cin >> n;     vector<long long> a(n);     for (int i = 0; i < n; i++) cin >> a[i];     long long res = 1;     for (int i = 0; i < 10; i++) {       long long ele = a[rng() % n];       vector<long long> div, cnt;       for (long long j = 1; j * j <= ele; j++) {         if ((ele % j) == 0) {           if (j * j == ele) {             div.push_back(j);             cnt.push_back(0);           } else {             div.push_back(j);             cnt.push_back(0);             div.push_back(ele / j);             cnt.push_back(0);           }         }       }       sort(div.begin(), div.end());       for (int j = 0; j < n; j++) {         long long g = gcd(ele, a[j]);         cnt[lower_bound(div.begin(), div.end(), g) - div.begin()]++;       }       for (int j = 0; j < div.size(); j++) {         for (int k = j + 1; k < div.size(); k++) {           if (div[k] % div[j] == 0) cnt[j] += cnt[k];         }         if (2 * cnt[j] >= n) res = max(res, div[j]);       }     }     cout << res <<   n ;   }


#include <bits/stdc++.h>   #define int long long   #define mod 1000000007    #define inv 500000004      using namespace std;      int ksm(int a, int b) {    int ans = 1, base = a % mod;    while (b) {     if (b & 1) ans = (ans * base) % mod;     base = (base * base) % mod;     b /= 2;    }    return ans % mod;   }      struct Edge{    int to;    int next;   };      Edge edge[405];   int head[205], cnt = 0;      void add(int u, int v) {    cnt++;    edge[cnt].to = v;    edge[cnt].next = head[u];    head[u] = cnt;   }      int n, fa[205][25], f[205][205], dep[205];      void dfs(int u, int fath) {    for (int i = head[u]; i; i = edge[i].next) {     int v = edge[i].to;     if (v == fath) continue;     dep[v] = dep[u] + 1;     fa[v][0] = u;     for (int j = 1; j <= 22; j++) {      fa[v][j] = fa[fa[v][j - 1]][j - 1];     }     dfs(v, u);    }   }      int lca(int x, int y) {    if (dep[x] < dep[y]) swap(x, y);    for (int i = 22; i >= 0; i--) {     if (dep[fa[x][i]] >= dep[y]) {      x = fa[x][i];     }    }    if (x == y) return x;    for (int i = 22; i >= 0; i--) {     if (fa[x][i] != fa[y][i]) {      x = fa[x][i]; y = fa[y][i];     }    }    return fa[x][0];   }      signed main() {    cin >> n;    for (int i = 1; i < n; i++) {     int u, v;     cin >> u >> v;     add(u, v); add(v, u);    }    for (int i = 1; i <= n; i++) f[0][i] = 1;    for (int i = 1; i <= n; i++) {     for (int j = 1; j <= n; j++) {      f[i][j] = ((f[i - 1][j] + f[i][j - 1]) % mod * inv % mod) % mod;     }    }    int ans = 0;    for (int rt = 1; rt <= n; rt++) {     memset(dep, 0, sizeof dep);     memset(fa, 0, sizeof fa);     dep[rt] = 1;     dfs(rt, 0);     for (int i = 1; i <= n; i++) {      for (int j = 1; j <= i - 1; j++) {       int LCA = lca(i, j);       ans = (ans % mod + f[dep[i]-dep[LCA]][dep[j]-dep[LCA]] % mod) % mod;      }      }    }    cout << (ans % mod * ksm(n, mod - 2) % mod) % mod;    return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T1, typename T2>   inline bool umin(T1& x, const T2& y) {     return x > y ? x = y, true : false;   }   template <typename T1, typename T2>   inline bool umax(T1& x, const T2& y) {     return x < y ? x = y, true : false;   }   const int N = (int)5e2 + 5;   const int INF = (int)1e9 + 17;   const long long LLINF = (long long)1e18 + 17;   const int mod = 998244353;   inline void add(int& x, int y) { x = (x + y >= mod ? x + y - mod : x + y); }   inline int mul(int x, int y) { return 1ll * x * y % mod; }   int n, m;   int cnt[N];   int nxt[N][N];   int prv[N][N];   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr), cout.tie(nullptr);     cin >> n >> m;     prv[0][0] = 1;     for (int total = (0); total < (n); ++total) {       for (int maxEqual = (0); maxEqual < (total + 1); ++maxEqual) {         for (int equal = (0); equal < (total + 1); ++equal) {           if (prv[maxEqual][equal] == 0) continue;           add(nxt[max(maxEqual, equal + 1)][equal + 1], prv[maxEqual][equal]);           add(nxt[max(maxEqual, 1)][1], prv[maxEqual][equal]);         }       }       memcpy(prv, nxt, sizeof nxt);       memset(nxt, 0, sizeof nxt);     }     for (int maxEqual = (0); maxEqual < (n + 1); ++maxEqual) {       for (int equal = (0); equal < (maxEqual + 1); ++equal) {         add(cnt[maxEqual], prv[maxEqual][equal]);       }     }     int answer = 0;     for (int a = (0); a < (n + 1); ++a)       for (int b = (0); b < (n + 1); ++b) {         if (a * b >= m) continue;         add(answer, mul(cnt[a], cnt[b]));       }     if (answer % 2 == 0)       answer /= 2;     else       answer = (answer + mod) / 2;     cout << answer << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 100010;   const long long INF = (long long)1 << 60;   long long x[maxn], y[maxn], n;   inline long long sqr(long long x) { return x * x; }   long long p[maxn], cnt;   long long ans;   bool cmpy(int a, int b) { return y[a] < y[b]; }   void solve(int l, int r) {     if (l == r) return;     int m = (l + r) >> 1;     solve(l, m);     solve(m + 1, r);     cnt = 0;     for (int i = l; i <= r; i++) {       if (sqr(x[m] - x[i]) >= ans) continue;       p[cnt++] = i;     }     sort(p, p + cnt, cmpy);     for (int i = 0; i < cnt; i++) {       for (int j = i + 1; j < cnt && sqr(y[p[j]] - y[p[i]]) < ans; j++)         ans = min(ans, sqr(y[p[j]] - y[p[i]]) + sqr(x[p[j]] - x[p[i]]));     }   }   int main() {     scanf( %lld , &n);     y[0] = 0;     for (int i = 1; i <= n; i++) scanf( %lld , &y[i]), x[i] = i, y[i] += y[i - 1];     ans = INF;     solve(1, n);     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxsize = 100005;   const int inf = 1061109567;   vector<int> edge[maxsize];   vector<pair<int, int> > base[maxsize];   int nnext[maxsize];   int n;   int deepth[maxsize];   int siz[maxsize];   int last = 0;   int ans[10 * maxsize];   int cnt = 0;   void dfs1(int u) {     if (edge[u].size() == 0) {       deepth[u] = 1;       return;     }     int maxi = 0;     for (auto v : edge[u]) {       siz[v] = siz[u] + 1;       dfs1(v);       maxi = max(deepth[v], maxi);       base[u].push_back({deepth[v], v});     }     deepth[u] = maxi + 1;     sort(base[u].begin(), base[u].end());     return;   }   void dfs2(int u) {     for (auto v : base[u]) {       nnext[last] = v.second;       last = v.second;       printf( %d  , v.second);       dfs2(v.second);     }     return;   }   int main() {     scanf( %d , &n);     for (int i = 0; i < n - 1; i++) {       int u;       scanf( %d , &u);       edge[u].push_back(i + 1);     }     dfs1(0);     printf( 0  );     dfs2(0);     puts(  );     int gg = 0;     while (nnext[gg]) {       int r = siz[gg] - siz[nnext[gg]] + 1;       for (int i = 0; i < r; i++) ans[cnt++] = nnext[gg];       gg = nnext[gg];     }     printf( %d n , cnt);     for (int i = 0; i < cnt; i++) printf( %d  , ans[i]);     puts(  );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, cnt = 0, i;     char str[10], o[5];     scanf( %d , &n);     scanf( %s , o);     for (i = 0; i < n; i++) {       scanf( %s , str);       if (str[5] == o[0] && str[6] == o[1] && str[7] == o[2]) cnt++;       if (str[0] == o[0] && str[1] == o[1] && str[2] == o[2]) cnt++;     }     if (cnt % 2)       printf( contest n );     else       printf( home n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void input(vector<long long>& v, long n) {     for (long long i = 0; i < n; i++) {       long long in;       cin >> in;       v.push_back(in);     }   }   void output(vector<long long> v) {     for (long long i = 0; i < v.size(); i++) cout << v[i] <<    ;   }   long long max_of_three(long long a, long long b, long long c) {     if (a >= b && a >= c)       return a;     else if (b >= a && b >= c)       return b;     else       return c;   }   long long max_of_4(long long a, long long b, long long c, long long d) {     if (a >= b && a >= c && a >= d)       return a;     else if (b >= a && b >= c && b >= d)       return b;     else if (c >= a && c >= d && c >= b)       return c;     else       return d;   }   map<long long, long long> frequency(vector<long long> v) {     map<long long, long long> m;     for (long long i = 0; i < v.size(); i++) {       if (m.find(v[i]) != m.end())         m[v[i]]++;       else {         m.insert({v[i], 1});       }     }     return m;   }   long long max_occuring_int(std::map<long long, long long> m) {     long long max_x = 0;     long long i = 0, n = m.size();     std::map<long long, long long>::iterator it = m.begin();     for (i = 0; i < n; i++) {       if (it->second > max_x) max_x = it->second;       it++;     }     return max_x;   }   vector<long long> give_unique_in_vector(vector<long long> v) {     sort((v).begin(), (v).end());     auto it = unique((v).begin(), (v).end());     v.resize(std::distance(v.begin(), it));     vector<long long> x = v;     return x;   }   bool isVowel(char c) {     return (c ==  a  | c ==  e  || c ==  i  || c ==  o  || c ==  u  || c ==  y  ||             c ==  A  || c ==  E  || c ==  I  || c ==  O  || c ==  U  || c ==  Y );   }   string removeWord(string str, string word) {     if (str.find(word) != string::npos) {       size_t p = -1;       string tempWord = word +    ;       while ((p = str.find(word)) != string::npos)         str.replace(p, tempWord.length(),   );       tempWord =     + word;       while ((p = str.find(word)) != string::npos)         str.replace(p, tempWord.length(),   );     }     return str;   }   long long calc(long long i, long long j, long long n) {     return (i + 1 - 1) * n + j + 1;   }   bool compare_descending(long long a, long long b) { return a > b; }   void solve() {     long long n, k;     cin >> n >> k;     vector<long long> v;     input(v, n);     long long max_change_of_min = *min_element((v).begin(), (v).end()) + k;     long long price = max_change_of_min;     for (long long i = 0; i < (long long)(n); ++i) {       long long low = v[i] - k;       long long high = v[i] + k;       if (low <= 0) low = 1;       if (price >= low && price <= high) {       } else {         cout <<  -1 n ;         return;       }     }     cout << price << endl;     ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long test;     cin >> test;     while (test--) solve();     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize(2)   using namespace std;   const int maxn = 100001, inf = 2147483647;   const long long mod = 1 ? 998244353 : 1000000007, linf = 9223372036854775807;   const double pi = acos(-1);   inline long long mi(long long a, long long b, long long mm = mod) {     a %= mm;     long long u = 1;     while (b) {       if (b & 1) u = u * a % mm;       a = a * a % mm, b >>= 1;     }     return u;   }   inline long long gcd(long long a, long long b) {     long long c = a % b;     while (c) a = b, b = c, c = a % b;     return b;   }   inline void mem(int* a, int p = 0, int len = maxn) {     for (int i = 0; i < len; i++) a[i] = p;   }   struct p {   } e;   int t, n, a[maxn], b[maxn], x, m;   signed main() {     ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);     cin >> t;     while (t--) {       x = 0;       b[0] = 10000, b[1] = 0;       cin >> n >> m;       for (int i = 0; i < n; i++)         for (int j = 0; j < m; j++)           cin >> a[0], x += abs(a[0]), b[0] = min(b[0], abs(a[0])),                                        b[1] += a[0] < 0;       cout << x - 2 * b[0] * (b[1] % 2) << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int N;   int A[5005];   int DP[5005][5005];   void Read() {     scanf( %d , &N);     for (int i = 1; i <= N; i++) scanf( %d , &A[i]);   }   void precalcDP() {     for (int i = 1; i <= N; i++) {       for (int j = i; j <= N; j++) DP[i][j - i] = A[j];       for (int k = 0; (1 << k) <= N; k++)         for (int j = 0; j < N; j++)           if ((j & (1 << k)) != 0) DP[i][j] ^= DP[i][j ^ (1 << k)];     }     for (int j = 1; j <= N; j++) {       for (int i = 1; j + i <= N; i++)         DP[i][j] = max(DP[i][j], max(DP[i][j - 1], DP[i + 1][j - 1]));     }   }   void Query(int a, int b) {     int dist = b - a;     printf( %d n , DP[a][dist]);   }   int main() {     Read();     precalcDP();     int Q;     scanf( %d , &Q);     for (int i = 1; i <= Q; i++) {       int x, y;       scanf( %d%d , &x, &y);       Query(x, y);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, i, j, k, t, s, x, y, h[100005], hh[100005], d, l;   int main() {     cin >> n;     for (i = 0; i < n; i++) scanf( %d , h + i);     m = h[n - 1];     for (i = n - 2; i >= 0; i--) {       if (h[i] <= m)         hh[i] = m - h[i] + 1;       else         m = h[i];     }     for (i = 0; i < n; i++) printf( %d  , hh[i]);   }


#include <bits/stdc++.h>   using namespace std;   template <typename T, typename U>   std::istream& operator>>(std::istream& i, pair<T, U>& p) {     i >> p.first >> p.second;     return i;   }   template <typename T>   std::istream& operator>>(std::istream& i, vector<T>& t) {     for (auto& v : t) {       i >> v;     }     return i;   }   template <typename T, typename U>   std::ostream& operator<<(std::ostream& o, const pair<T, U>& p) {     o << p.first <<     << p.second;     return o;   }   template <typename T>   std::ostream& operator<<(std::ostream& o, const vector<T>& t) {     if (t.empty()) o <<   n ;     for (size_t i = 0; i < t.size(); ++i) {       o << t[i] <<    n [i == t.size() - 1];     }     return o;   }   template <typename T>   using minheap = priority_queue<T, vector<T>, greater<T>>;   template <typename T>   using maxheap = priority_queue<T, vector<T>, less<T>>;   template <typename T>   bool in(T a, T b, T c) {     return a <= b && b < c;   }   unsigned int logceil(int first) {     return 8 * sizeof(int) - __builtin_clz(first);   }   namespace std {   template <typename T, typename U>   struct hash<pair<T, U>> {     hash<T> t;     hash<U> u;     size_t operator()(const pair<T, U>& p) const {       return t(p.first) ^ (u(p.second) << 7);     }   };   }  // namespace std   template <typename T, typename F>   T bsh(T l, T h, const F& f) {     T r = -1, m;     while (l <= h) {       m = (l + h) / 2;       if (f(m)) {         l = m + 1;         r = m;       } else {         h = m - 1;       }     }     return r;   }   template <typename F>   double bshd(double l, double h, const F& f, double p = 1e-9) {     unsigned int r = 3 + (unsigned int)log2((h - l) / p);     while (r--) {       double m = (l + h) / 2;       if (f(m)) {         l = m;       } else {         h = m;       }     }     return (l + h) / 2;   }   template <typename T, typename F>   T bsl(T l, T h, const F& f) {     T r = -1, m;     while (l <= h) {       m = (l + h) / 2;       if (f(m)) {         h = m - 1;         r = m;       } else {         l = m + 1;       }     }     return r;   }   template <typename F>   double bsld(double l, double h, const F& f, double p = 1e-9) {     unsigned int r = 3 + (unsigned int)log2((h - l) / p);     while (r--) {       double m = (l + h) / 2;       if (f(m)) {         h = m;       } else {         l = m;       }     }     return (l + h) / 2;   }   template <typename T>   T gcd(T a, T b) {     if (a < b) swap(a, b);     return b ? gcd(b, a % b) : a;   }   template <typename T>   class vector2 : public vector<vector<T>> {    public:     vector2() {}     vector2(size_t a, size_t b, T t = T())         : vector<vector<T>>(a, vector<T>(b, t)) {}   };   template <typename T>   class vector3 : public vector<vector2<T>> {    public:     vector3() {}     vector3(size_t a, size_t b, size_t c, T t = T())         : vector<vector2<T>>(a, vector2<T>(b, c, t)) {}   };   template <typename T>   class vector4 : public vector<vector3<T>> {    public:     vector4() {}     vector4(size_t a, size_t b, size_t c, size_t d, T t = T())         : vector<vector3<T>>(a, vector3<T>(b, c, d, t)) {}   };   template <typename T>   class vector5 : public vector<vector4<T>> {    public:     vector5() {}     vector5(size_t a, size_t b, size_t c, size_t d, size_t e, T t = T())         : vector<vector4<T>>(a, vector4<T>(b, c, d, e, t)) {}   };   template <typename F>   struct NoOp {     void setup(unsigned int) {}     void op(F& p, F n, unsigned int, unsigned int) { p = n; }     void down(F&, F&, F&, unsigned int, unsigned int) {}   };   template <typename F, typename SetOp, typename PowerOp>   struct Lazy {     void setup(unsigned int s) {       this->s = s;       L = new F[s]();     }     void down(F& u, F& l, F& r, unsigned int i, unsigned int s) {       op(l, L[i], i << 1, s >> 1);       op(r, L[i], i << 1 | 1, s >> 1);       L[i] = 0;     }     void op(F& p, F n, unsigned int i, unsigned int s) {       p = sop(p, pop(n, s));       if (i < this->s) this->L[i] = sop(this->L[i], n);     }     SetOp sop;     PowerOp pop;     F* L;     unsigned int s;   };   template <typename F, typename CombineOp, typename ModifyOp = NoOp<F>>   struct SegTree {     void setup(unsigned int s, F def) {       n = 1 << logceil(s);       T = vector<F>(2 * n, def);       for (unsigned int i = n - 1; i > 0; i--)         T[i] = cop(T[i << 1], T[i << 1 | 1]);       mop.setup(2 * n);     }     void setup(vector<F>& data, F def = F()) {       n = 1 << logceil(data.size());       T = vector<F>(2 * n, def);       copy(data.begin(), data.end(), T.begin() + n);       for (unsigned int i = n - 1; i > 0; i--)         T[i] = cop(T[i << 1], T[i << 1 | 1]);       mop.setup(2 * n);     }     inline void put(unsigned int first, F n) { put(first, first, n); }     inline void put(unsigned int from, unsigned int to, F v) {       put2(from, to + 1, v, 1, n);     }     inline F get(unsigned int first) { return get(first, first); }     inline F get(unsigned int from, unsigned int to) {       return get2(from, to + 1, 1, n);     }     void put2(unsigned int from, unsigned int to, F v, unsigned int i,               unsigned int s) {       if (from == 0 && to == s) {         mop.op(T[i], v, i, s);         return;       }       mop.down(T[i], T[i << 1], T[i << 1 | 1], i, s);       s >>= 1;       i <<= 1;       if (to <= s) {         put2(from, to, v, i, s);       } else if (from >= s) {         put2(from - s, to - s, v, i | 1, s);       } else {         put2(from, s, v, i, s);         put2(0, to - s, v, i | 1, s);       }       T[i >> 1] = cop(T[i], T[i | 1]);     }     F get2(unsigned int from, unsigned int to, unsigned int i, unsigned int s) {       while (true) {         if (from == 0 && to == s) return T[i];         mop.down(T[i], T[i << 1], T[i << 1 | 1], i, s);         s >>= 1;         i <<= 1;         if (to > s) {           to -= s;           if (from >= s) {             from -= s;             i |= 1;           } else             return cop(get2(from, s, i, s), get2(0, to, i | 1, s));         }       }     }     unsigned int n;     vector<F> T;     CombineOp cop;     ModifyOp mop;   };   template <typename F>   struct AddOp {     F operator()(F a, F b) { return a + b; }   };   template <typename F>   struct MinOp {     F operator()(F a, F b) { return std::min(a, b); }   };   template <typename F>   struct MaxOp {     F operator()(F a, F b) { return std::max(a, b); }   };   template <typename F>   struct MultiplyOp {     F operator()(F a, F b) { return a * b; }   };   template <typename F>   struct MultOp {     F operator()(F a, unsigned int b) { return a * b; }   };   template <typename F>   struct IdempOp {     F operator()(F a, unsigned int b) { return a; }   };   template <typename F>   struct InverseOp {     F operator()(F a, F b) { return b ? b - a : a; }   };   template <typename T>   using AddSumTree = SegTree<T, AddOp<T>, Lazy<T, AddOp<T>, MultOp<T>>>;   template <typename T>   using AddMaxTree = SegTree<T, MaxOp<T>, Lazy<T, AddOp<T>, IdempOp<T>>>;   template <typename T>   using AddMinTree = SegTree<T, MinOp<T>, Lazy<T, AddOp<T>, IdempOp<T>>>;   template <typename T>   using AssignMinTree = SegTree<T, MinOp<T>, Lazy<T, MinOp<T>, IdempOp<T>>>;   template <typename T>   using AssignMaxTree = SegTree<T, MaxOp<T>, Lazy<T, MaxOp<T>, IdempOp<T>>>;   template <typename T>   using XorTree = SegTree<T, AddOp<T>, Lazy<T, InverseOp<T>, MultOp<T>>>;   template <typename T>   using SetMinTree = SegTree<T, MinOp<T>>;   template <typename T>   using SetMaxTree = SegTree<T, MaxOp<T>>;   template <typename T>   using SetMulTree = SegTree<T, MultiplyOp<T>>;   class developinggame {    public:     void solve(istream& cin, ostream& cout) {       int N;       cin >> N;       vector<pair<int, std::pair<int, int>>> P(N);       cin >> P;       vector<vector<int>> In(3e5 + 1), Out(3e5 + 1);       for (int i = 0; i < N; ++i) {         In[P[i].first].push_back(i);         Out[P[i].second.first].push_back(i);       }       AddMaxTree<int> A;       A.setup(3e5 + 1, 0);       std::pair<int, int> best{-1, 0};       for (int i = 1; i <= 3e5; ++i) {         for (int j : In[i]) A.put(P[j].second.first, P[j].second.second, 1);         int g = A.get(0, 3e5);         best = max(best, {g, i});         for (int j : Out[i]) A.put(P[j].second.first, P[j].second.second, -1);       }       int l = best.second;       vector<int> X(3e5 + 2, 0);       for (auto& p : P) {         if (p.first <= l && p.second.first >= l) {           X[p.second.first]++;           X[p.second.second + 1]--;         }       }       std::pair<int, int> ans{-1, 0};       for (int i = 1; i <= 3e5; ++i) {         X[i] += X[i - 1];         ans = max(ans, {X[i], i});       }       int first = ans.second;       vector<int> Ans;       for (int i = 0; i < N; ++i) {         auto& p = P[i];         if (p.first <= l && p.second.first >= l && p.second.first <= first &&             p.second.second >= first) {           Ans.push_back(i + 1);         }       }       cout << best.first <<   n  << Ans;     }   };   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     developinggame solver;     std::istream& in(std::cin);     std::ostream& out(std::cout);     solver.solve(in, out);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int h, r, spheres = 0;     cin >> r >> h;     spheres = (h / r) * 2;     if (h % r < r / 2.)       spheres += 1;     else {       spheres += 2;       if (h % r > 1.732 * r / 2.) spheres += 1;     }     cout << spheres;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, x = 0, y = 0;     string a, b;     cin >> a >> b;     if (a.size() > b.size()) {       n = a.size();     } else {       n = b.size();     }     for (int i = 0; i < n; i++) {       if (b[x] == a[y]) {         x++;         y++;       } else {         x++;       }       if (b[x] == 0 || a[y] == 0) {         cout << (y + 1);         break;       }     }   }


#include <bits/stdc++.h>   long long x, n, d1, d2, now;   int main() {     scanf( %lld %lld , &n, &x);     d1 = x;     d2 = x;     long long l, r, ans = 0l;     for (int i = 1; i <= n; i++) {       scanf( %lld %lld , &l, &r);       if (l <= d1 && r >= d2) continue;       if (r < d1) {         ans += (d1 - r);         d2 = d1;         d1 = r;       } else if (l > d2) {         ans += (l - d2);         d1 = d2;         d2 = l;       } else {         d1 = (d1 < l) ? l : d1;         d2 = (d2 > r) ? r : d2;       }     }     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long inf = 1e10;   void solve() {     long long n, m, k;     cin >> n >> m >> k;     long long moves = (n + m - 2) + (n * m) - 1;     for (long long i = 0; i < m + n; i++) {       cin >> k;     }     cout << moves <<   n ;     for (long long i = 0; i < n - 1; i++) {       cout <<  U ;     }     for (long long i = 0; i < m - 1; i++) {       cout <<  L ;     }     string r(m - 1,  R );     string l(m - 1,  L );     for (long long i = 0; i < n; i++) {       if (i % 2) {         cout << l;       } else         cout << r;       if (i != n - 1) cout <<  D ;     }     cout <<   n ;   }   int32_t main() {     std::ios::sync_with_stdio(false);     std::cin.tie(nullptr);     long long t = 1;     while (t--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int X, Y;   int n;   int cnt;   bool used[1000][1000];   bool edge[1000][1000][4];   const int DX[] = {1, 0, -1, 0}, DY[] = {0, 1, 0, -1};   vector<int> ans;   void dfs(int x, int y) {     if (x < 0 || x >= X || y < 0 || y >= Y || used[x][y]) return;     used[x][y] = true;     cnt++;     for (int i = 0; i < 4; i++) {       if (!edge[x][y][i]) {         dfs(x + DX[i], y + DY[i]);       }     }   }   int main() {     scanf( %d%d%d , &X, &Y, &n);     for (int i = 1; i <= n; i++) {       int x1, y1, x2, y2;       scanf( %d%d%d%d , &x1, &y1, &x2, &y2);       if (x1 == x2) {         for (int j = y1; j < y2; j++) {           edge[x1 - 1][j][0] = true;           edge[x1][j][2] = true;         }       } else if (y1 == y2) {         for (int j = x1; j < x2; j++) {           edge[j][y1 - 1][1] = true;           edge[j][y1][3] = true;         }       }     }     for (int i = 0; i < X; i++)       for (int j = 0; j < Y; j++)         if (!used[i][j]) {           cnt = 0;           dfs(i, j);           ans.push_back(cnt);         }     sort(ans.begin(), ans.end());     for (int i = 0; i < ans.size(); i++) printf( %d  , ans[i]);     puts(  );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1010;   char s[100];   bool ops[256];   int relabel[N * 6];   int va[N * 6][2];   int typ[N * 6];   bool vis[N * 6], beres[N * 6];   string detail[N * 6];   map<string, int> ex;   map<pair<pair<int, int>, int>, int> rel;   vector<string> ans;   char usea;   int usev;   string nxtvar() {     while (true) {       string cur = string() + usea + to_string(usev);       if (!ex.count(cur)) {         ex.insert(make_pair(cur, 0));         return cur;       }       if (++usev == 1000) {         usev = 0;         ++usea;       }     }   }   int strcnt;   int gid(const string& str) {     auto it = ex.find(str);     if (it != ex.end()) return it->second;     ex.insert(make_pair(str, ++strcnt));     detail[strcnt] = str;     return strcnt;   }   int nid(const string& str) {     detail[++strcnt] = str;     return ex[str] = strcnt;   }   void dfs(int u) {     if (vis[u]) return;     vis[u] = true;     if (typ[u] == 0) {       relabel[u] = u;       return;     }     if (typ[u] == -1) {       if (beres[u]) {         if (typ[va[u][0]]) {           beres[va[u][0]] = true;         } else {           if (detail[va[u][0]] !=  res ) ans.push_back( res=  + detail[va[u][0]]);           return;         }       }       dfs(va[u][0]);       relabel[u] = relabel[va[u][0]];       return;     }     dfs(va[u][0]);     dfs(va[u][1]);     pair<pair<int, int>, int> spec(         make_pair(relabel[va[u][0]], relabel[va[u][1]]), typ[u]);     relabel[u] = u;     if (!rel.count(spec)) {       rel.insert(make_pair(spec, u));       detail[u] = nxtvar();       ans.push_back((beres[u] ? string( res ) : detail[u]) +  =  +                     detail[relabel[va[u][0]]] + char(typ[u]) +                     detail[relabel[va[u][1]]]);     } else       relabel[u] = rel[spec];   }   int main() {     usea =  a ;     usev = 0;     ops[ $ ] = true;     ops[ ^ ] = true;     ops[ # ] = true;     ops[ & ] = true;     int t;     scanf( %d , &t);     while (t--) {       scanf( %s , s);       char *p1 = s, *p2;       while (*p1 !=  = ) ++p1;       string a(s, p1);       p2 = p1;       while (!ops[*p2] && *p2) ++p2;       if (ops[*p2]) {         string b(p1 + 1, p2), c(p2 + 1);         int bi = gid(b), ci = gid(c);         int ai = nid(a);         typ[ai] = *p2;         va[ai][0] = bi;         va[ai][1] = ci;       } else {         string b(p1 + 1);         int bi = gid(b);         int ai = nid(a);         typ[ai] = -1;         va[ai][0] = bi;       }     }     int resi = gid( res );     beres[resi] = true;     dfs(resi);     printf( %lu n , ans.size());     for (auto str : ans) puts(str.c_str());     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void read(vector<long long> &v) {     for (int i = 0; i < v.size(); i++) cin >> v[i];   }   void print(vector<long long> v) {     for (int i = 0; i < v.size(); i++) cout << v[i] <<    ;   }   long long n, m, a, b, temp, x, y;   string str;   set<string> strings;   unordered_map<string, vector<int>> mp;   bool check(int l, int r) {     for (auto s : strings) {       if (r - l + 1 < s.size()) continue;       auto it = lower_bound(mp[s].begin(), mp[s].end(), l);       if (it == mp[s].end()) continue;       int val = *it;       if (val <= (r - s.size() + 1)) return 0;     }     return 1;   }   int start;   int solve() {     int l = 0;     int r = 0;     int ans = 0;     for (int l = 0; l < str.size(); l++) {       while (r < l) r++;       if (!check(l, r)) {         if (r - l > ans) {           ans = r - l;           start = l;         }         continue;       }       while (r < str.size()) {         if (check(l, r))           r++;         else           break;       }       if (r - l > ans) {         ans = r - l;         start = l;       }     }     return ans;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cin >> str;     cin >> n;     for (int i = 0; i < n; i++) {       string s;       cin >> s;       strings.insert(s);     }     for (auto s : strings) {       string temp;       if (s.size() > str.size()) continue;       for (int i = 0; i <= str.length() - s.length(); i++) {         temp = str.substr(i, s.length());         if (temp == s) mp[s].push_back(i);       }     }     long long ans = solve();     cout << ans <<     << start;   }


#include <bits/stdc++.h>   using namespace std;   long long x, y;   int n;   pair<long long, long long> a[200001];   vector<long long> numbers;   map<long long, int> matchs;   long long matchsReverse[400001];   int increase[400001];   int decrease[400001];   long long answer[400001];   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       cin >> x >> y;       a[i] = make_pair(x, y);       numbers.push_back(x);       numbers.push_back(y);     }     sort(numbers.begin(), numbers.end());     int last = -1, num = 0;     for (int i = 0; i < numbers.size(); i++) {       if (last != numbers[i]) {         num++;         matchs[numbers[i]] = num;         matchsReverse[num] = numbers[i];         last = numbers[i];       }     }     for (int i = 0; i < n; i++) {       a[i] = make_pair(matchs[a[i].first], matchs[a[i].second]);       increase[a[i].first]++;       decrease[a[i].second]++;     }     long long cnt = 0;     for (int i = 1; i <= 400000; i++) {       answer[cnt] += matchsReverse[i] - 1 - matchsReverse[i - 1];       answer[cnt + increase[i]]++;       cnt += increase[i];       cnt -= decrease[i];     }     for (int i = 1; i <= n; i++) cout << answer[i] <<    ;   }


#include <bits/stdc++.h>   using namespace std;   int pos[200000 + 10], b[200000 + 10];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n;     cin >> n;     for (int i = 1; i <= n; i++) {       int x;       cin >> x;       if (x) {         pos[x] = 0;       }     }     for (int i = 1; i <= n; i++) {       cin >> b[i];       if (b[i]) {         pos[b[i]] = i;       }     }     int start = 1;     int end = b[n];     bool flag = true;     for (int i = n - 1, j = end - 1; j > 0; j--, i--) {       if (b[i] != j) {         flag = false;       }     }     if (flag) {       start = end + 1;     }     if (start != 1) {       for (int i = start; i <= n; i++) {         if (pos[i] > i - start) {           start = 1;           break;         }       }     }     int ans = n - start + 1;     ans += pos[start];     int mx = 0;     for (int i = start + 1; i <= n; i++) {       int t = pos[i] - pos[start];       mx = max(mx, t - i + start);     }     cout << ans + mx <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const double PI = 3.141592653589793238460;   using namespace std;   const int N = 200200;   vector<int> g[N];   int w[N], vis[N], done[N];   int can_back[N];   int n, m, s;   long long maximum = 0;   void dfs(int u, int par) {     vis[u] = 1;     for (auto v : g[u]) {       if (v == par) continue;       if (vis[v])         can_back[v] = 1;       else         dfs(v, u);       if (can_back[v] == 1) can_back[u] = 1;     }   }   void findmax(int u, long long sum) {     done[u] = 1;     if (g[u].size() == 1 and u != s) {       sum += w[u];       maximum = max(maximum, sum);       return;     }     if (can_back[u] == 0) sum += w[u];     for (auto v : g[u]) {       if (!done[v]) findmax(v, sum);     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> m;     for (int i = 1; i <= n; i++) {       cin >> w[i];     }     for (int i = 1; i <= m; i++) {       int u, v;       cin >> u >> v;       g[u].push_back(v);       g[v].push_back(u);     }     cin >> s;     can_back[s] = 1;     dfs(s, 0);     long long ans = 0;     for (int i = 1; i <= n; i++) {       if (can_back[i] == 1) ans += w[i];     }     findmax(s, 0);     ans += maximum;     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int N;     cin >> N;     vector<int> adjL(N, -1);     for (int n = 0; n < N; n++) {       cin >> adjL[n];       adjL[n]--;     }     bool c = false;     for (int i = 0; i < N; i++) {       int node = i;       for (int x = 0; x < 3; x++) {         if (adjL[node] != -1) {           node = adjL[node];         }       }       if (node == i) {         cout <<  YES ;         c = true;         break;       }     }     if (!c) cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e6 + 5;   int n, ri[N];   char s[N];   struct node {     int ch[26], par, val;   } t[N];   int sz = 1, root = 1, last = 1;   void extend(int c) {     int p = last, np = ++sz;     t[np].val = t[p].val + 1;     ri[np]++;     for (; p && !t[p].ch[c]; p = t[p].par) t[p].ch[c] = np;     if (!p)       t[np].par = root;     else {       int q = t[p].ch[c];       if (t[q].val == t[p].val + 1)         t[np].par = q;       else {         int nq = ++sz;         t[nq] = t[q];         t[nq].val = t[p].val + 1;         t[q].par = t[np].par = nq;         for (; p && t[p].ch[c] == q; p = t[p].par) t[p].ch[c] = nq;       }     }     last = np;   }   int vis[N];   void walk(int id) {     int u = root, len = n + n - 1, ans = 0, nowLen = 0;     for (int i = 1; i <= len; i++) {       int c = s[i] -  a ;       if (t[u].ch[c])         u = t[u].ch[c], nowLen++;       else {         while (u && !t[u].ch[c]) u = t[u].par;         if (!u)           u = root, nowLen = 0;         else           nowLen = t[u].val + 1, u = t[u].ch[c];       }       if (vis[u] != id && nowLen >= n) vis[u] = id, ans += ri[u];       if (n != 1)         while (t[t[u].par].val + 1 >= n) u = t[u].par, nowLen = t[u].val;     }     printf( %d n , ans);   }   int c[N], a[N];   void RadixSort() {     for (int i = 1; i <= sz; i++) c[t[i].val]++;     for (int i = 1; i <= n; i++) c[i] += c[i - 1];     for (int i = sz; i >= 1; i--) a[c[t[i].val]--] = i;   }   void solve() {     RadixSort();     int u;     for (int i = sz; i >= 1; i--) u = a[i], ri[t[u].par] += ri[u];     int m;     scanf( %d , &m);     for (int i = 1; i <= m; i++) {       scanf( %s , s + 1);       n = strlen(s + 1);       for (int i = 1; i < n; i++) s[i + n] = s[i];       walk(i);     }   }   int main() {     scanf( %s , s + 1);     n = strlen(s + 1);     for (int i = 1; i <= n; i++) extend(s[i] -  a );     solve();   }