#include <bits/stdc++.h>   using namespace std;   const int nmax = 5e5 + 42;   int n, m;   struct edges {     int u, v, w;     int id_original;   };   edges inp[nmax], all[nmax];   bool cmp(edges a, edges b) { return a.w < b.w; }   int parent[nmax];   int root(int node) {     if (parent[node] == node) return node;     parent[node] = root(parent[node]);     return parent[node];   }   int max_cost = 0;   int group[nmax], id = 0;   bool can_be[nmax];   bool cmp2(int edge_1, int edge_2) { return group[edge_1] < group[edge_2]; }   int sz, test[nmax];   map<pair<int, int>, vector<int> > types;   int main() {     scanf( %i%i , &n, &m);     for (int i = 1; i <= m; i++) {       scanf( %i%i%i , &inp[i].u, &inp[i].v, &inp[i].w);       inp[i].id_original = i;       all[i] = inp[i];     }     sort(all + 1, all + m + 1, cmp);     for (int i = 1; i <= n; i++) parent[i] = i;     for (int i = 1; i <= m; i++) {       int j = i;       while (j <= m && all[i].w == all[j].w) j++;       j--;       max_cost = all[i].w;       types = {};       for (int k = i; k <= j; k++) {         if (root(all[k].u) != root(all[k].v)) {           can_be[all[k].id_original] = 1;           pair<int, int> work = {root(all[k].u), root(all[k].v)};           if (work.first > work.second) swap(work.first, work.second);           types[work].push_back(all[k].id_original);         }       }       for (auto w : types) {         id++;         for (auto k : w.second) group[k] = id;       }       for (int k = i; k <= j; k++) parent[root(all[k].u)] = root(all[k].v);       i = j;     }     for (int i = 1; i <= n; i++) parent[i] = i;     int q;     scanf( %i , &q);     for (int i = 1; i <= q; i++) {       scanf( %i , &sz);       for (int j = 1; j <= sz; j++) scanf( %i , &test[j]);       bool can = 1;       for (int j = 1; j <= sz; j++)         if (can_be[test[j]] == 0) {           can = 0;           break;         }       sort(test + 1, test + sz + 1, cmp2);       for (int j = 2; j <= sz; j++)         if (group[test[j - 1]] == group[test[j]]) can = 0;       for (int j = 1; j <= sz; j++)         if (root(inp[test[j]].u) == root(inp[test[j]].v))           can = 0;         else           parent[root(inp[test[j]].u)] = root(inp[test[j]].v);       for (int j = 1; j <= sz; j++)         parent[inp[test[j]].u] = inp[test[j]].u,         parent[inp[test[j]].v] = inp[test[j]].v;       if (can)         printf( YES n );       else         printf( NO n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int read() {     int x = 0, f = 1;     char c = getchar();     while (!isdigit(c)) {       if (c ==  - ) f = -1;       c = getchar();     }     while (isdigit(c)) {       x = (x << 1) + (x << 3) + c - 48;       c = getchar();     }     return x * f;   }   const int N = 510;   const int mod = 998244353;   int n, cnt1, cnt2, cnt3, cnt4;   int s[N][N], A[N][N], C[N][N];   int a[N], b[N];   int f[N], g[N], G[N];   int tmp[N], ans[N];   int vis[N << 1], nxt[N];   int ru[N];   void dfs(int u, int fa) {     vis[u] = 1;     if (nxt[u]) {       if (!vis[nxt[u]])         dfs(nxt[u], fa);       else         cnt3++;     } else {       if (fa > n && u > n)         cnt4++;       else if (fa <= n && u > n)         cnt1++;       else if (fa > n && u <= n)         cnt2++;     }   }   void init() {     s[0][0] = C[0][0] = A[0][0] = 1;     for (int i = 1; i <= n; i++) {       C[i][0] = A[i][0] = 1;       for (int j = 1; j <= i; j++) {         C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % mod;         A[i][j] = (A[i - 1][j] + 1ll * j * A[i - 1][j - 1] % mod) % mod;         s[i][j] = (1ll * (i - 1) * s[i - 1][j] % mod + s[i - 1][j - 1]) % mod;       }     }   }   void getans(int n, int *f) {     for (int i = 0; i <= n; i++) {       for (int j = i; j <= n; j++) {         f[i] = (f[i] +                 1ll * C[n][j] * s[j][i] % mod * A[n - j + cnt4][n - j] % mod) %                mod;       }     }     memset(G, 0, sizeof G);     for (int i = 0; i <= n; i++) {       for (int j = i, fz = 1; j <= n; j++, fz = -fz)         G[i] = (G[i] + 1ll * C[j][i] * f[j] % mod * fz + mod) % mod;     }     memcpy(f, G, sizeof(G));   }   int main() {     n = read();     for (int i = 1; i <= n + n; i++) vis[i] = 1;     for (int i = 1; i <= n; i++) a[i] = read();     for (int i = 1; i <= n; i++) b[i] = read();     for (int i = 1; i <= n; i++) {       int x = a[i] ? a[i] : i + n;       int y = b[i] ? b[i] : i + n;       vis[x] = vis[y] = 0;       if (x <= n || y <= n) nxt[x] = y, ru[y]++;     }     for (int i = 1; i <= n + n; i++)       if (!vis[i] && !ru[i]) dfs(i, i);     for (int i = 1; i <= n + n; i++)       if (!vis[i]) dfs(i, i);     init();     getans(cnt1, f);     getans(cnt2, g);     for (int i = 0; i <= n; i++) {       for (int j = 0; j <= i; j++) {         tmp[i] = (tmp[i] + 1ll * f[j] * g[i - j] % mod) % mod;       }     }     for (int i = 0; i <= n; i++) {       for (int j = 0; j <= i; j++) {         ans[i] = (ans[i] + 1ll * tmp[j] * s[cnt4][i - j] % mod) % mod;       }       ans[i] = 1ll * ans[i] * A[cnt4][cnt4] % mod;     }     for (int i = 0; i < n; i++)       printf( %d  , (n - i - cnt3 < 0) ? 0 : ans[n - i - cnt3]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = numeric_limits<int>::max();   const long long LLINF = numeric_limits<long long>::max();   const unsigned long long ULLINF = numeric_limits<unsigned long long>::max();   const double PI = acos(-1.0);   vector<int> ans;   void solve(int n, int p, int maxN) {     if (!p) return;     int mx = n - (p - 1);     int cur = min(maxN, mx);     ans.push_back(cur);     solve(n - cur, p - 1, maxN);   }   vector<char> type;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     char c;     type.push_back(1);     int p = 1, m = 0;     cin >> c;     while (c !=  = ) {       if (c ==  + ) {         p++;         type.push_back( + );       } else if (c ==  - ) {         type.push_back( - );         m++;       }       cin >> c;     }     int n;     cin >> n;     if (!p) {       cout <<  Impossible ;       return 0;     }     if (!m) {       if (p > n) {         cout <<  Impossible ;         return 0;       }       cout <<  Possible n ;       solve(n, p, n);       cout << ans.back() <<    ;       ans.pop_back();       while (ans.size()) {         cout <<  +   << ans.back() <<    ;         ans.pop_back();       }       cout <<  =   << n;       return 0;     }     vector<int> positive, negative;     bool found = 0;     for (int pos = n; pos <= n * p; pos++) {       int neg = pos - n;       if (neg / m > 0 && n * m >= neg) {         if (p > pos) continue;         solve(pos, p, n);         positive = ans;         solve(neg, m, n);         negative = ans;         found = 1;         break;       }     }     if (!found) {       cout <<  Impossible ;       return 0;     }     cout <<  Possible n ;     cout << positive.back() <<    ;     positive.pop_back();     for (int i = 1; i < type.size(); i++) {       if (type[i] ==  + ) {         cout <<  +   << positive.back() <<    ;         positive.pop_back();       } else {         cout <<  -   << negative.back() <<    ;         negative.pop_back();       }     }     cout <<  =   << n;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using namespace std::chrono;   inline long long lrand() {     long long x = 0;     for (int i = 0; i < (4); i++) {       x <<= 16;       x ^= rand();     }     return x;   }   string fname(string s, vector<long long> v) {     string x =  C:/leet/  + s;     for (auto& k : (v)) x +=  _  + to_string(k);     x +=  .txt ;     return x;   }   long long now() {     return duration_cast<milliseconds>(system_clock::now().time_since_epoch())         .count();   }   template <typename T>   void W(vector<T>& v) {     for (int i = 0; i < (v.size()); i++) cout << v[i] <<    ;   }   int main(int argc, char** argv) {     cin.sync_with_stdio(false);     long long n;     scanf( %lld , &n);     vector<long long> a(100007, 0), x(100007, 0);     for (int i = (1); i <= (n); i++) scanf( %lld , &a[i]);     for (int i = (1); i <= (n); i++) {       x[i] = x[i - 1];       x[i] = max(x[i], a[i] + 1);     }     for (int i = n - 1; i >= 1; i--) {       x[i] = max(x[i], x[i + 1] - 1);     }     long long sum = 0;     for (int i = 1; i <= n; i++) {       sum += x[i] - a[i] - 1;     }     printf( %lld n , sum);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void write(int num) {     if (num >= 10) write(num / 10);     putchar(num % 10 +  0 );   }   string s;   vector<int> l, r;   int id[100001];   vector<int> v[100001];   vector<int> ll, lr, rl, rr;   int main() {     cin >> s;     int cnt = 0;     for (int i = 0; i < s.size(); i++) switch (s[i]) {         case  L : {           if (r.size())             id[i] = *(id + *(r.end() - 1)), r.pop_back();           else             id[i] = ++cnt;           l.push_back(i);           break;         }         case  R : {           if (l.size())             id[i] = *(id + *(l.end() - 1)), l.pop_back();           else             id[i] = ++cnt;           r.push_back(i);           break;         }       }     for (int i = 0; i < s.size(); i++) v[id[i]].push_back(i);     for (int i = 1; i <= cnt; i++) {       if (s[v[i][0]] ==  L  && s[*(v[i].end() - 1)] ==  L ) ll.push_back(i);       if (s[v[i][0]] ==  L  && s[*(v[i].end() - 1)] ==  R ) lr.push_back(i);       if (s[v[i][0]] ==  R  && s[*(v[i].end() - 1)] ==  L ) rl.push_back(i);       if (s[v[i][0]] ==  R  && s[*(v[i].end() - 1)] ==  R ) rr.push_back(i);     }     write(cnt - 1), putchar(  n );     while (ll.size() && rr.size()) {       int x = *(ll.end() - 1), y = *(rr.end() - 1);       for (int i = 0; i < v[y].size(); i++) v[x].push_back(v[y][i]);       lr.push_back(x), ll.pop_back(), rr.pop_back();     }     while (ll.size() && lr.size()) {       int x = *(lr.end() - 1), y = *(ll.end() - 1);       for (int i = 0; i < v[y].size(); i++) v[x].push_back(v[y][i]);       *(ll.end() - 1) = x, lr.pop_back();     }     while (ll.size() && rl.size()) {       int x = *(ll.end() - 1), y = *(rl.end() - 1);       for (int i = 0; i < v[y].size(); i++) v[x].push_back(v[y][i]);       rl.pop_back();     }     while (rr.size() && rl.size()) {       int x = *(rl.end() - 1), y = *(rr.end() - 1);       for (int i = 0; i < v[y].size(); i++) v[x].push_back(v[y][i]);       *(rr.end() - 1) = x, rl.pop_back();     }     while (rr.size() && lr.size()) {       int x = *(rr.end() - 1), y = *(lr.end() - 1);       for (int i = 0; i < v[y].size(); i++) v[x].push_back(v[y][i]);       lr.pop_back();     }     if (ll.size() || rr.size()) {       int x;       if (ll.size())         x = ll[0];       else         x = rr[0];       for (int i = 0; i < v[x].size(); i++) write(v[x][i] + 1), putchar(   );       putchar(  n );       return 0;     }     if (lr.size()) {       int x = lr[0];       while (lr.size() >= 2) {         int y = *(lr.end() - 1);         for (int i = 0; i < v[y].size(); i++) v[x].push_back(v[y][i]);         lr.pop_back();       }     }     if (rl.size()) {       int x = rl[0];       while (rl.size() >= 2) {         int y = *(rl.end() - 1);         for (int i = 0; i < v[y].size(); i++) v[x].push_back(v[y][i]);         rl.pop_back();       }     }     if (!(lr.size() && rl.size())) {       int x;       if (lr.size())         x = lr[0];       else         x = rl[0];       for (int i = 0; i < v[x].size(); i++) write(v[x][i] + 1), putchar(   );       putchar(  n );       return 0;     }     int x = lr[0], y = rl[0];     if (*(v[x].end() - 1) > *(v[y].end() - 1)) swap(x, y);     v[x].push_back(*(v[y].end() - 1)), v[y].pop_back();     for (int i = 0; i < v[x].size(); i++) write(v[x][i] + 1), putchar(   );     for (int i = 0; i < v[y].size(); i++) write(v[y][i] + 1), putchar(   );     putchar(  n );   }


#include <bits/stdc++.h>   using namespace std;   vector<int> e[200100], g[200100];   int n, m, q;   int low[200100], dfn[200100], sta[200100], idx, top;   bool in[200100];   void tarjan(int u, int pre) {     low[u] = dfn[u] = ++idx;     sta[top++] = u;     in[u] = true;     for (auto v : g[u]) {       if (v == pre) continue;       if (!dfn[v]) {         tarjan(v, u);         if (low[u] > low[v]) low[u] = low[v];         if (low[v] >= dfn[u]) {           ++m;           e[u].push_back(m);           e[m].push_back(u);           int vn;           do {             vn = sta[--top];             e[vn].push_back(m);             e[m].push_back(vn);             in[vn] = 0;           } while (vn != v);         }       } else if (in[v] && low[u] > dfn[v])         low[u] = dfn[v];     }   }   int fa[200100][20], dep[200100], dis[200100];   void dfs(int u, int pre) {     fa[u][0] = pre;     for (int i = 1; i < 20; ++i) fa[u][i] = fa[fa[u][i - 1]][i - 1];     dep[u] = dep[pre] + 1;     dis[u] = dis[pre] + (u <= n);     for (auto v : e[u])       if (v != pre) dfs(v, u);   }   int LCA(int u, int v) {     if (dep[u] > dep[v]) swap(u, v);     int hu = dep[u], hv = dep[v];     int tu = u, tv = v;     for (int det = hv - hu, i = 0; det; det >>= 1, i++)       if (det & 1) tv = fa[tv][i];     if (tu == tv) return tu;     for (int i = 19; i >= 0; --i) {       if (fa[tu][i] == fa[tv][i]) continue;       tu = fa[tu][i];       tv = fa[tv][i];     }     return fa[tu][0];   }   int main() {     scanf( %d%d%d , &n, &m, &q);     while (m--) {       int u, v;       scanf( %d%d , &u, &v);       g[u].push_back(v);       g[v].push_back(u);     }     m = n;     tarjan(1, -1);     dfs(1, 1);     while (q--) {       int u, v;       scanf( %d%d , &u, &v);       int lca = LCA(u, v);       int ans = dis[u] + dis[v] - 2 * dis[lca] - (lca > n);       printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int a[1000001], has[1000001];   int main() {     long long int n, i;     cin >> n;     for (i = 0; i < n; i++) {       cin >> a[i];       has[a[i]] = 1;     }     long long int c = 0;     for (i = 1; i <= n; i++)       if (has[i]) c++;     cout << n - c;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 100;   const long long inf = 1e18;   vector<int> g[maxn];   bool visit[maxn];   int cnt = 0;   void dfs(int u) {     cnt = 0;     queue<int> q;     q.push(u);     visit[u] = true;     cnt++;     while (!q.empty()) {       int u = q.front();       q.pop();       for (auto v : g[u])         if (visit[v] == false) {           q.push(v);           visit[v] = true;           cnt++;         }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     int n, m;     cin >> n >> m;     vector<int> st;     int u, v;     memset(visit, false, sizeof visit);     for (int i = 1; i <= m; i++) {       cin >> u >> v;       g[u].push_back(v);       g[v].push_back(u);       st.push_back(u);       st.push_back(v);     }     int ans = 0;     for (auto v : st) {       if (visit[v] == false) {         dfs(v);         ans += (cnt - 1);         cnt = 0;       }     }     cout << (m - ans) << endl;     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:200000000 )   using namespace std;   const long long oo = 1LL << 60;   const long long kNumMoves = 4;   const long long kMoves[kNumMoves][2] = {{1, 0}, {-1, 0}, {0, -1}, {0, 1}};   int n, v, e;   vector<int> a, b;   vector<vector<int> > conn, edges;   vector<int> ansX, ansY, ansD;   vector<int> topSort;   vector<int> seen;   void DFS_Topological(int node) {     if (seen[node]) return;     seen[node] = 1;     for (int i = 0; i < int(n); ++i) {       if (edges[node][i] && !seen[i]) {         DFS_Topological(i);         conn[node].push_back(i);         conn[i].push_back(node);       }     }     topSort.push_back(node);   }   int AddTransfusionStep(int src, int dest, int delta) {     int mxMoveOut = min(a[src], delta);     int mxMoveIn = min(v - a[dest], mxMoveOut);     a[src] -= mxMoveIn;     a[dest] += mxMoveIn;     if (mxMoveIn)       ansX.push_back(src + 1), ansY.push_back(dest + 1), ansD.push_back(mxMoveIn);     return mxMoveIn;   }   int Transfuse_Out(int node, int dest, int delta) {     if (!delta || seen[node] || seen[dest]) return 0;     int step1 = AddTransfusionStep(node, dest, delta);     if (step1 == delta) return delta;     for (int i = 0; i < int(conn[dest].size()); ++i) {       int newDest = conn[dest][i];       if (newDest == node) continue;       if (seen[newDest]) continue;       Transfuse_Out(dest, newDest, v);     }     int step2 = AddTransfusionStep(node, dest, delta - step1);     return step1 + step2;   }   int Transfuse_In(int node, int dest, int delta) {     if (!delta || seen[node] || seen[dest]) return 0;     int step1 = AddTransfusionStep(dest, node, delta);     if (step1 == delta) return delta;     for (int i = 0; i < int(conn[dest].size()); ++i) {       int newDest = conn[dest][i];       if (newDest == node) continue;       if (seen[newDest]) continue;       Transfuse_In(dest, newDest, v);     }     int step2 = AddTransfusionStep(dest, node, delta - step1);     return step1 + step2;   }   bool Transfuse(int node) {     int delta = a[node] - b[node];     if (delta > 0) {       for (int i = 0; i < int(conn[node].size()); ++i) {         int dest = conn[node][i];         if (seen[dest]) continue;         delta -= Transfuse_Out(node, dest, delta);       }       return (delta == 0 && a[node] == b[node]);     } else if (delta < 0) {       delta = -delta;       for (int i = 0; i < int(conn[node].size()); ++i) {         int dest = conn[node][i];         if (seen[dest]) continue;         delta -= Transfuse_In(node, dest, delta);       }       return (delta == 0 && a[node] == b[node]);     }     return true;   }   bool FindTransfusions() {     seen.clear();     seen.resize(n, 0);     for (int i = 0; i < int(n); ++i) DFS_Topological(i);     seen.clear();     seen.resize(n, 0);     for (int i = 0; i < int(n); ++i) {       if (!Transfuse(topSort[i])) return false;       seen[topSort[i]] = 1;     }     return true;   }   int main() {     cin >> n >> v >> e;     a.resize(n), b.resize(n);     for (int i = 0; i < int(n); ++i) cin >> a[i];     for (int i = 0; i < int(n); ++i) cin >> b[i];     conn.resize(n);     edges.resize(n, vector<int>(n, 0));     for (int i = 0; i < int(e); ++i) {       int x, y;       cin >> x >> y;       --x, --y;       edges[x][y] = edges[y][x] = 1;     }     if (FindTransfusions()) {       cout << ansX.size() << endl;       for (int i = 0; i < int(ansX.size()); ++i)         cout << ansX[i] <<     << ansY[i] <<     << ansD[i] << endl;     } else {       cout <<  NO ;     }     int i;     cin >> i;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<vector<int>> graph(200005), revGraph(200005);   vector<int> vis(200005, 0), revVis(200005, 0);   bool dfs(int u, vector<vector<int>> &curGraph, vector<int> &curVis) {     curVis[u] = -1;     for (auto v : curGraph[u]) {       if (curVis[v] == -1) return false;       if (curVis[v] == 1) continue;       if (!dfs(v, curGraph, curVis)) return false;     }     curVis[u] = 1;     return true;   }   int main() {     cin.tie(0);     ios_base::sync_with_stdio(false);     int n, edges;     cin >> n >> edges;     int first, second;     for (int i = 0; i < edges; ++i) {       cin >> first >> second;       graph[first].push_back(second);       revGraph[second].push_back(first);     }     int qtt = 0;     string ans =   ;     for (int i = 1; i <= n; ++i) {       if (!vis[i] && !revVis[i]) {         ++qtt;         ans.push_back( A );       } else {         ans.push_back( E );       }       if (!dfs(i, graph, vis) || !dfs(i, revGraph, revVis)) {         qtt = -1;         break;       }     }     cout << qtt <<   n ;     if (qtt != -1) {       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   string to_string(const vector<T>& vc, int w) {     if (vc.empty()) return   ;     if (w + 1 == vc.size()) return to_string(vc[w]);     return to_string(vc[w]) +  ,  + to_string(vc, w + 1);   }   template <typename T>   string to_string(const vector<T>& vc) {     return  {  + to_string(vc, 0) +  } ;   }   void debug_out() { cerr << endl; }   template <typename Head, typename... Tail>   void debug_out(Head H, Tail... T) {     cerr <<     << to_string(H);     debug_out(T...);   }   class DebugStream {   } LOG;   template <typename T>   DebugStream& operator<<(DebugStream& s, const T&) {     return s;   }   const int MAX = 200200;   int a[MAX];   int dp[MAX];   int cnt[MAX];   bool isLast[MAX], isFirst[MAX];   int b[MAX], pointer[MAX], q[MAX];   int main() {     int T;     scanf( %d , &T);     for (int t = 0; t < int(T); t++) {       int n;       scanf( %d , &n);       for (int i = 0; i < int(n); i++)         scanf( %d , a + i), isLast[i] = false, isFirst[i] = false, b[i] = a[i];       map<int, int> dic, last, first, invLast;       for (int i = n - 1; i >= 0; i--) {         if (dic[a[i]] == 0) {           last[a[i]] = i;           isLast[i] = true;           invLast[a[i]] = i;         }         dic[a[i]]++;         cnt[i] = dic[a[i]];       }       dic.clear();       for (int i = 0; i < int(n); i++) {         if (dic[a[i]] == 0) {           first[a[i]] = i;           isFirst[i] = true;         }         dic[a[i]]++;       }       map<int, int> nxt;       sort(b, b + n);       for (int i = 0; i < int(n - 1); i++) {         nxt[b[i]] = b[i + 1];       }       nxt[b[n - 1]] = -1;       dic.clear();       for (int i = n - 1; i >= 0; i--) {         if (dic.count(a[i])) {           q[i] = dic[a[i]];         } else {           q[i] = -1;         }         dic[a[i]] = i;         if (nxt[a[i]] != -1 && dic.count(nxt[a[i]]) == 1) {           pointer[i] = dic[nxt[a[i]]];         } else {           pointer[i] = -1;         }       }       int ans = 0;       for (int i = n - 1; i >= 0; i--) {         int j = i;         dp[i] = cnt[j];         j = invLast[a[i]];         if (pointer[j] != -1) {           if (isFirst[pointer[j]]) {             dp[i] += dp[pointer[j]];           } else {             dp[i] += cnt[pointer[j]];           }         }         ans = max(ans, dp[i]);         42;       }       printf( %d n , n - ans);     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100010;   int n, x[N], y[N];   struct pt {     int s, id, ans;   } p[N], w[N];   bool cmpID(pt A, pt B) { return A.id < B.id; }   bool cmpSw(pt A, pt B) { return (A.s < B.s) || (A.s == B.s && A.id < B.id); }   bool cmpSp(pt A, pt B) {     return (A.s < B.s) ||            (A.s == B.s && x[A.id] <= x[B.id] && y[A.id] <= y[B.id]);   }   int maxX, lb[N << 2], rb[N << 2], maxv[N << 2];   void build(int l, int r, int i) {     lb[i] = l;     rb[i] = r;     maxv[i] = -1;     if (l < r) {       build(l, ((lb[i] + rb[i]) / 2), ((i) << 1));       build(((lb[i] + rb[i]) / 2) + 1, r, (((i) << 1) + 1));     }   }   void modify(int p, int v, int i) {     if (lb[i] == rb[i])       maxv[i] = max(maxv[i], v);     else {       if (p <= ((lb[i] + rb[i]) / 2))         modify(p, v, ((i) << 1));       else         modify(p, v, (((i) << 1) + 1));       maxv[i] = max(maxv[((i) << 1)], maxv[(((i) << 1) + 1)]);     }   }   int findmax(int l, int r, int i) {     if (l > r) return -1;     if (l == lb[i] && r == rb[i]) return maxv[i];     return max(findmax(l, min(r, ((lb[i] + rb[i]) / 2)), ((i) << 1)),                findmax(max(l, ((lb[i] + rb[i]) / 2) + 1), r, (((i) << 1) + 1)));   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= (n); i++) {       scanf( %d%d , &x[i], &y[i]);       p[i].s = y[i] - x[i];       p[i].id = i;       maxX = max(x[i], maxX);     }     for (int i = 1; i <= (n); i++) {       scanf( %d , &w[i].s);       w[i].id = i;     }     sort(p + 1, p + n + 1, cmpSp);     sort(w + 1, w + n + 1, cmpSw);     bool flag = true;     for (int i = 1; i <= (n); i++) {       w[i].ans = p[i].id;       if (w[i].s != p[i].s) flag = false;     }     if (!flag) {       printf( NO n );       return 0;     }     sort(w + 1, w + n + 1, cmpID);     build(0, maxX, 1);     for (int i = 1; i <= (n); i++) {       if (findmax(x[w[i].ans], maxX, 1) >= y[w[i].ans]) flag = false;       modify(x[w[i].ans], y[w[i].ans], 1);     }     if (!flag) {       printf( NO n );       return 0;     }     printf( YES n );     for (int i = 1; i <= (n); i++) printf( %d %d n , x[w[i].ans], y[w[i].ans]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 3100;   int n, m;   vector<int> eds[MAXN];   vector<int> reds[MAXN];   vector<pair<int, int> > go[MAXN];   vector<pair<int, int> > rgo[MAXN];   int dd[MAXN];   int ddg[MAXN][MAXN];   void bfs(int v) {     for (int i = 0; i < n; ++i) dd[i] = -1;     dd[v] = 0;     queue<int> qu;     qu.push(v);     while (!qu.empty()) {       int x = qu.front();       qu.pop();       for (int u : eds[x])         if (dd[u] == -1) dd[u] = dd[x] + 1, qu.push(u);     }   }   void rbfs(int v) {     for (int i = 0; i < n; ++i) dd[i] = -1;     dd[v] = 0;     queue<int> qu;     qu.push(v);     while (!qu.empty()) {       int x = qu.front();       qu.pop();       for (int u : reds[x])         if (dd[u] == -1) dd[u] = dd[x] + 1, qu.push(u);     }   }   int main() {     cin >> n >> m;     for (int i = 0; i < m; ++i) {       int a, b;       cin >> a >> b;       --a;       --b;       eds[a].push_back(b);       reds[b].push_back(a);     }     for (int i = 0; i < n; ++i) {       bfs(i);       int mn1 = i, mn2 = i, mn3 = i;       for (int j = 0; j < n; ++j) {         if (i == j) continue;         if (dd[j] == -1) continue;         if (dd[mn3] < dd[j]) mn3 = j;         if (dd[mn3] > dd[mn2]) swap(mn2, mn3);         if (dd[mn2] > dd[mn1]) swap(mn1, mn2);       }       go[i].push_back(make_pair(mn1, dd[mn1]));       go[i].push_back(make_pair(mn2, dd[mn2]));       go[i].push_back(make_pair(mn3, dd[mn3]));       for (int j = 0; j < n; ++j) ddg[i][j] = dd[j];       rbfs(i);       mn1 = i, mn2 = i, mn3 = i;       for (int j = 0; j < n; ++j) {         if (i == j) continue;         if (dd[j] == -1) continue;         if (dd[mn3] < dd[j]) mn3 = j;         if (dd[mn3] > dd[mn2]) swap(mn2, mn3);         if (dd[mn2] > dd[mn1]) swap(mn1, mn2);       }       rgo[i].push_back(make_pair(mn1, dd[mn1]));       rgo[i].push_back(make_pair(mn2, dd[mn2]));       rgo[i].push_back(make_pair(mn3, dd[mn3]));     }     int bst = -1;     int ba = 0, bb = 0, bc = 0, bd = 0;     for (int i = 0; i < n; ++i)       for (int j = 0; j < n; ++j) {         if (i == j) continue;         if (ddg[i][j] == -1) continue;         for (int i1 = 0; i1 < (int)rgo[i].size(); ++i1)           for (int j1 = 0; j1 < (int)go[j].size(); ++j1) {             if (rgo[i][i1].second <= 0) continue;             if (go[j][j1].second <= 0) continue;             int a = rgo[i][i1].first;             int b = go[j][j1].first;             if (a == b || a == j || b == i) continue;             int sum = ddg[a][i] + ddg[i][j] + ddg[j][b];             if (sum > bst) {               ba = a;               bb = i;               bc = j;               bd = b;               bst = sum;             }           }       }     cout << ba + 1 <<     << bb + 1 <<     << bc + 1 <<     << bd + 1 <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long i, j, n, c[223456], d[223456], a[456789], l, r, s, t, tt, k, x, y, z,       m, b[1111111];   string p, q, du, qq;   vector<long long> u[345678], uu, ui;   multiset<long long> mm;   int main() {     cin >> n >> t;     for (i = 0; i < n; i++) {       cin >> a[i];     }     m = t;     cin >> k;     for (i = 0; i < n; i++) {       cin >> b[i];       mm.insert(b[i]);       while (t < a[i]) {         if (mm.empty()) {           cout << -1;           return 0;         }         s += *mm.begin();         mm.erase(mm.begin());         t += k;       }     }     cout << s;     return 0;   }


#include <bits/stdc++.h>   using namespace std;            #define ios   ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)   #define FOR(i,m)  for(int i = 0 ;i  < m ;i++)   #define mem(a ,b)  memset(a,  (b) , sizeof(a))   #define all(cont)  cont.begin(),cont.end()   #define mp   make_pair   #define pb   push_back   #define F   first   #define S   second   #define cn   cout<<  n          typedef pair<int,int>  pi;   typedef vector<int>  vi;   typedef long long   ll;   typedef long double  ld;   typedef unsigned long long int  ull;         const int maxN = 1e5 + 1;   const int mod  = 1e9 + 7;               void solve(){       int n;    cin >> n;    int a[n];       for(int i = 0 ;i <  n;i++) cin >> a[i];       cout<<n/2<<  n ;    for(int i = 0 ; i + 1< n; i+=2 ){     cout<<i+1<<   <<i+2<<   <<min(a[i] , a[i+1]) <<    <<mod<<  n ;    }                  }               int main(){               int T = 1;    cin >> T;        while(T--){     solve();    }       return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct code {     int x, y;   };   int res, k;   string s;   int gcd(int a, int b) {     while (b) {       a %= b;       swap(a, b);     }     return a;   }   int a[100001], ans;   int main() {     int n;     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a[i];     }     int ans = 0;     while (1) {       int ok = 0;       for (int i = 2; i <= n; i++) {         if (a[1] > a[i]) ok++;       }       if (ok == n - 1) break;       int q = -1e9, id = 0;       for (int j = 2; j <= n; j++) {         if (q < a[j]) {           q = a[j];           id = j;         }       }       a[1]++;       a[id]--;       ans++;     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   inline void solve() {     int d, m;     scanf( %d%d , &d, &m);     int ans = 1;     for (int i = 0; (1 << i) <= d; ++i) {       ans = 1ll * ans * ((1 << i) + 1) % m;       d -= (1 << i);     }     if (d) ans = 1ll * ans * (d + 1) % m;     printf( %d n , (ans - 1 + m) % m);   }   int main() {     int T;     scanf( %d , &T);     while (T--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 200100;   const int mod = 1e9 + 7;   int add(int a, int b) {     a += b;     if (a >= mod) a -= mod;     if (a < 0) a += mod;     return a;   }   int mul(int a, int b) { return 1ll * a * b % mod; }   int N;   int F[maxn];   int Ans[maxn];   vector<int> pre[maxn];   vector<int> suf[maxn];   vector<int> G[maxn];   void DFS(int u, int p = 0) {     F[u] = 1;     vector<int> ch;     for (int v : G[u])       if (v != p) {         DFS(v, u);         F[u] = mul(F[u], add(F[v], 1));         ch.push_back(v);       }     pre[u].resize((int)ch.size());     suf[u].resize((int)ch.size());     for (int i = 0; i < (int)ch.size(); ++i) {       int v = ch[i];       if (i)         pre[u][i] = pre[u][i - 1];       else         pre[u][i] = 1;       pre[u][i] = mul(pre[u][i], add(F[v], 1));     }     for (int i = (int)ch.size() - 1; i >= 0; --i) {       int v = ch[i];       if (i < (int)ch.size() - 1)         suf[u][i] = suf[u][i + 1];       else         suf[u][i] = 1;       suf[u][i] = mul(suf[u][i], add(F[v], 1));     }   }   void dfs(int u, int p = 0, int buf = 1) {     Ans[u] = F[u];     vector<int> ch;     for (int v : G[u])       if (v != p) {         ch.push_back(v);       }     for (int i = 0; i < (int)ch.size(); ++i) {       int v = ch[i];       int nFu = buf;       if (i) nFu = mul(nFu, pre[u][i - 1]);       if (i < (int)ch.size() - 1) nFu = mul(nFu, suf[u][i + 1]);       int tm = F[v];       F[v] = mul(F[v], add(nFu, 1));       dfs(v, u, add(nFu, 1));       F[v] = tm;     }   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> N;     for (int p, i = 2; i <= N; ++i) {       cin >> p;       G[p].push_back(i);       G[i].push_back(p);     }     F[1] = 1;     DFS(1);     dfs(1);     for (int i = 1; i <= N; ++i) cout << Ans[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 300000 + 9;   const int Mod = 1000000007;   int A[N], n, B[N];   multiset<int> S;   bool ok(int l, int r) {     if (l == r) {       auto it = S.find(l);       return it != S.end();     }     auto it = S.lower_bound(l);     auto it2 = S.lower_bound(r);     if (it == it2) {       if (it2 != S.end() && (*it2) == r) return true;       return false;     } else {       return true;     }   }   const int Maxint = 29;   int main() {     cin >> n;     for (int i = 0; i < n; i++) scanf( %d , A + i);     for (int i = 0; i < n; i++) {       int t;       scanf( %d , &t);       S.insert(t);     }     for (int i = 0; i < n; i++) {       int tmp = 0;       for (int j = Maxint; j >= 0; j--) {         if (A[i] & (1 << j)) {           int Tp = tmp | 1 << j;           if (ok(Tp, Tp + (1 << j) - 1)) {             tmp = Tp;           } else {             ;           }         } else {           if (ok(tmp, tmp + (1 << j) - 1)) {             ;           } else {             tmp |= 1 << j;           }         }       }       B[i] = tmp;       S.erase(S.lower_bound(tmp));     }     for (int i = 0; i < n; i++) printf( %d  , B[i] ^ A[i]);   }


#include <bits/stdc++.h>   using namespace std;   long long a, b, ans;   void gcd(long long a, long long b) {     if (a == 0 || b == 0) return;     if (a > b) swap(a, b);     ans += (b / a);     gcd(b % a, a);   }   int main() {     cin >> a >> b;     gcd(a, b);     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e9;   const long long mod = 1e9 + 7;   const long long N = 1e5 + 5;   const long long Sz = 1e6 + 5;   string to_string(const string& s) { return     + s +    ; }   void DBG() { cerr <<  ]  << endl; }   template <class H, class... T>   void DBG(H h, T... t) {     cerr << to_string(h);     if (sizeof...(t)) cerr <<  ,  ;     DBG(t...);   }   void setIO() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     if (fopen(                  .inp ,                r )) {       freopen(                         .inp ,            r , stdin);       freopen(                         .out ,            w , stdout);     }   }   long long n, a[200];   void test_case() {     cin >> n;     long long result = 0, pre = 0;     for (long long i = (1); i <= (n); ++i) {       cin >> a[i];       if (a[i] <= i + result) {         ++pre;         continue;       }       result += a[i] - pre - 1;       pre = a[i];     }     cout << result <<   n ;   }   signed main() {     setIO();     long long TC = 1;     cin >> TC;     while (TC--) {       test_case();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxx = 5e5 + 7;   long long a[maxx], prime[maxx], cnt[maxx], sum, tedad;   bool mark[maxx];   int main() {     int n, q;     cin >> n >> q;     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 2; i < maxx; i++) {       if (prime[i] == 0)         for (int j = i; j < maxx; j += i) prime[j] = i;     }     while (q--) {       int ind, adad, ans = 0;       cin >> ind;       ind--;       adad = a[ind];       vector<int> v;       while (adad > 1) {         int p = prime[adad];         v.push_back(p);         while (adad % p == 0) adad /= p;       }       int sz = (int)v.size();       for (int mask = 0; mask < (1 << sz); mask++) {         if (!mark[ind]) {           int t = 1;           for (int i = 0; i < sz; i++)             if ((mask >> i) & 1) t *= v[i];           if (__builtin_popcount(mask) % 2 == 0)             ans += cnt[t];           else             ans -= cnt[t];           cnt[t]++;         } else {           int t = 1;           for (int i = 0; i < sz; i++)             if ((mask >> i) & 1) t *= v[i];           cnt[t]--;           if (__builtin_popcount(mask) % 2 == 0)             ans += cnt[t];           else             ans -= cnt[t];         }       }       if (!mark[ind]) {         mark[ind] = true;         sum += ans;         tedad++;       } else {         mark[ind] = false;         sum -= ans;         tedad--;       }       cout << sum <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int i, j, n, x = (int)(1e7 + 1);     cin >> n;     vector<bool> p(x, true);     p[0] = p[1] = false;     int c = 0;     for (i = 2; i <= x; i++) {       if (p[i]) {         c++;         cout << i <<    ;         if (c == n) break;         for (j = i; (long long)i * j <= x; j++) {           p[i * j] = false;         }       }     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<bool> isthere(2000010, false);   vector<int> nextmax(2000010);   int main() {     ios::sync_with_stdio(false);     int n, i;     cin >> n;     vector<int> a(n);     for (i = 0; i < n; i++) {       cin >> a[i];       isthere[a[i]] = true;     }     sort(a.begin(), a.end());     for (i = 1; i < 2000005; i++) {       if (isthere[i - 1])         nextmax[i] = i - 1;       else         nextmax[i] = nextmax[i - 1];     }     int ans = 0, range;     for (i = 0; i < a.size(); i++) {       if (i && a[i] == a[i - 1]) continue;       range = (a[a.size() - 1] / a[i]) + 1;       for (int j = 2; j <= range; j++) {         int temp = a[i] * j;         ans = max(ans, nextmax[temp] % a[i]);       }     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int x0, y0, x1, y1;     cin >> x0 >> y0 >> x1 >> y1;     int n;     cin >> n;     multimap<int, pair<long long int, long long int> > sections;     for (long long int i = 0; i < n; i++) {       int r, a, b;       cin >> r >> a >> b;       sections.insert(make_pair(r, make_pair(a, b)));     }     map<pair<long long int, long long int>, bool> visited;     map<pair<long long int, long long int>, int> dist;     pair<long long int, long long int> start = make_pair(x0, y0);     pair<long long int, long long int> target = make_pair(x1, y1);     queue<pair<long long int, long long int> > que;     que.push(start);     visited[start] = true;     dist[start] = 0;     int dx[] = {-1, -1, -1, 0, 1, 1, 1, 0};     int dy[] = {-1, 0, 1, 1, 1, 0, -1, -1};     while (que.size()) {       pair<long long int, long long int> cur = que.front();       que.pop();       if (cur == target) {         break;       };       for (long long int i = 0; i < 8; i++) {         long long int nr = cur.first + dy[i];         long long int nc = cur.second + dx[i];         bool ok = false;         if (visited[make_pair(nr, nc)]) continue;         auto range = sections.equal_range(nr);         for (auto it = range.first; it != range.second; it++) {           pair<long long int, long long int> sec = it->second;           if (nc <= sec.second && nc >= sec.first) {             ok = true;             break;           }         }         if (ok) {           visited[make_pair(nr, nc)] = true;           dist[make_pair(nr, nc)] = dist[cur] + 1;           que.push(make_pair(nr, nc));         }       }     }     if (dist.find(target) == dist.end()) {       cout << -1 << endl;     } else {       cout << dist[target] << endl;     }   }


#include <bits/stdc++.h>   const int maxn = 2222;   using namespace std;   char s1[maxn], s2[maxn];   int dp[maxn][maxn];   int n, m;   int solve(int i) {     int top = m;     int rq = 0;     if (i < m) return maxn;     while (top && i) {       if (s1[i] == s2[top])         top--;       else         rq++;       i--;     }     if (top)       return maxn;     else       return rq;   }   int main() {     scanf( %s%s , s1 + 1, s2 + 1);     n = strlen(s1 + 1);     m = strlen(s2 + 1);     for (int i = 0; i <= n; i++)       for (int j = i + 1; j <= n; j++) dp[i][j] = -maxn;     for (int i = 1; i <= n; i++) {       int k = solve(i);       for (int j = 0; j <= i; j++) {         dp[i][j] = max(dp[i - 1][j], dp[i][j]);         if (j >= k) {           dp[i][j] = max(dp[i][j], dp[i - m - k][j - k] + 1);         }       }     }     for (int i = 0; i <= n; i++) {       printf( %d  , dp[n][i]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int N;     scanf( %d , &N);     if (N <= 2)       printf( %d , -1);     else {       for (int i = N; i >= 1; i--) {         printf( %d , i);         printf(   );       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   pair<long double, long double> A[200666];   int st[200666], ind[200666];   long double val[200666];   bool comp(int i1, int i2) { return A[i1] < A[i2]; }   bool eql(long double v1, long double v2) {     return (v1 - v2 > -((long double)0.00000000000001) &&             v1 - v2 < ((long double)0.00000000000001));   }   long double bs(long double vmax, pair<long double, long double> v1,                  pair<long double, long double> v2) {     long double pos, step;     for (step = 1; step <= vmax; step *= (long double)2.0)       ;     for (pos = 0; step > ((long double)0.0000000000000000001);          step /= (long double)2.0)       if (pos + step <= vmax) {         long double val_1 = 1.0 / v1.first + (pos + step) / (v1.second);         long double val_2 = 1.0 / v2.first + (pos + step) / (v2.second);         if (val_2 < val_1 || eql(val_2, val_1)) pos += step;       }     return pos;   }   int main() {     int n, i;     scanf( %d , &n);     for (i = 1; i <= n; ++i) {       int v1, v2;       scanf( %d%d , &v1, &v2);       A[i].first = v1;       A[i].second = v2;       ind[i] = i;     }     sort(ind + 1, ind + n + 1, comp);     int k = 1;     st[1] = ind[1];     val[1] = ((long double)1000000000000000);     for (i = 2; i <= n; ++i) {       int l = ind[i];       while (true && k > 0) {         long double v1 = 1.0 / A[st[k]].first + val[k] / (A[st[k]].second);         long double v2 = 1.0 / A[l].first + val[k] / (A[l].second);         if (eql(v1, v2)) break;         if (v2 < v1) {           --k;           continue;         }         break;       }       if (k == 0) {         st[++k] = l;         continue;       }       st[++k] = l;       val[k] = bs(val[k - 1], A[st[k - 1]], A[l]);     }     sort(st + 1, st + k + 1);     for (i = 1; i <= k; ++i) cout << st[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   template <typename T>   ostream &operator<<(ostream &o, const vector<T> &v) {     for (size_t i = 0; i < v.size(); i++)       o << v[i] << (i + 1 != v.size() ?     :   );     return o;   }   template <int n, class... T>   typename enable_if<(n >= sizeof...(T))>::type _ot(ostream &,                                                     tuple<T...> const &) {}   template <int n, class... T>   typename enable_if<(n < sizeof...(T))>::type _ot(ostream &os,                                                    tuple<T...> const &t) {     os << (n == 0 ?    :  ,  ) << get<n>(t);     _ot<n + 1>(os, t);   }   template <class... T>   ostream &operator<<(ostream &o, tuple<T...> const &t) {     o <<  ( ;     _ot<0>(o, t);     o <<  ) ;     return o;   }   template <class T, class U>   ostream &operator<<(ostream &o, pair<T, U> const &p) {     o <<  (  << p.first <<  ,   << p.second <<  ) ;     return o;   }   int n;   int cnt = 0;   int ask(int y1, int x1, int y2, int x2) {     cnt++;     assert(cnt <= 4 * n);     assert(abs(y2 - y1) + abs(x2 - x1) >= n - 1);     if (y1 > y2) swap(y1, y2);     if (x1 > x2) swap(x1, x2);     cout <<  ?   << y1 + 1 <<     << x1 + 1 <<     << y2 + 1 <<     << x2 + 1          << endl;     string s;     cin >> s;     assert(s !=  BAD );     return s[0] ==  Y ;   }   string ans;   int yy, xx;   int dfs(int y1, int x1, int y2, int x2, int i, int ok, int rev) {     if (!ok && !ask(y1, x1, y2, x2)) return 0;     if (abs(y2 - y1) + abs(x2 - x1) == n - 1) return 1;     int sg = y2 - y1 < 0 ? -1 : 1;     if (rev) {       if (dfs(y1, x1, y2 - sg, x2, i - sg, 0, rev)) {         ans[i] =  D ;       } else if (dfs(y1, x1, y2, x2 - sg, i - sg, 1, rev)) {         ans[i] =  R ;       }     } else {       if (dfs(y1, x1, y2, x2 - sg, i - sg, 0, rev)) {         ans[i] =  R ;       } else if (dfs(y1, x1, y2 - sg, x2, i - sg, 1, rev)) {         ans[i] =  D ;       }     }     return 1;   }   int main() {     std::ios::sync_with_stdio(false), std::cin.tie(0);     cin >> n;     ans = string(2 * n - 2,  - );     dfs(0, 0, n - 1, n - 1, 2 * n - 3, 1, 0);     dfs(n - 1, n - 1, 0, 0, 0, 1, 1);     assert((int)ans.find( - ) == -1);     cout <<  !   << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int dp[1024], n, m, c1, c2, c3, c4, an[1024], am[1024];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> c1 >> c2 >> c3 >> c4;     cin >> n >> m;     for (int i = 0; i < n; ++i) cin >> an[i];     for (int i = 0; i < m; ++i) cin >> am[i];     int mini = INT_MAX;     mini = min(mini, c4);     mini = min(mini, 2 * c3);     int s1 = 0;     for (int i = 0; i < n; ++i) {       s1 += min(c1 * an[i], c2);     }     mini = min(mini, c3 + s1);     int s2 = 0;     for (int i = 0; i < m; ++i) {       s2 += min(c1 * am[i], c2);     }     mini = min(mini, c3 + s2);     mini = min(mini, s1 + s2);     cout << mini << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   map<pair<long long, long long>, bool> blocked;   vector<vector<pair<long long, long long> > > graph;   vector<bool> used;   int part(int v) {     vector<long long> adj;     for (int i = 0; i < graph[v].size(); i++) {       long long w = graph[v][i].first;       long long ui = graph[v][i].second;       if (!used[ui]) {         adj.push_back(w);         used[ui] = true;       }     }     long long lst = 0;     for (int i = 0; i < adj.size(); i++) {       long long w = part(adj[i]);       if (w == 0) {         if (lst == 0) {           lst = adj[i];         } else {           cout << lst <<     << v <<     << adj[i] <<   n ;           lst = 0;         }       } else {         cout << v <<     << adj[i] <<     << w <<   n ;       }     }     return lst;   }   int main() {     int n, m;     cin >> n >> m;     graph.resize(n + 1);     used.resize(m);     for (int i = 0; i < m; i++) {       long long a, b;       cin >> a >> b;       graph[a].push_back(make_pair(b, i));       graph[b].push_back(make_pair(a, i));     }     if (m % 2 == 1) {       cout <<  No solution             <<   n ;     } else {       part(1);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool acompare(int lhs, int rhs) { return lhs > rhs; }   struct t {     int a, pos;   };   int b[1000];   struct t aa[1000];   int main() {     int i, j, k, l, m, n;     vector<int> a;     string s, s1, s2, s3, s4;     cin >> n;     cin >> k;     for (i = 0; i < n; i++) cin >> m, a.push_back(m);     for (i = 0; i < k; i++) cin >> b[i];     sort(b, b + 1000, acompare);     j = 0;     for (i = 0; i < n; i++) {       if (a[i] == 0) a[i] = b[j++];     }     for (i = 0; i < n - 1; i++)       if (a[i] > a[i + 1]) {         cout <<  Yes ;         return 0;       }     cout <<  No ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 200100;   vector<pair<int, int> > d[2];   vector<int> S[2];   int n, v;   int main() {     cin >> n >> v;     int sum = 0;     for (int i = 0; i < n; i++) {       int t, s;       cin >> t >> s;       sum += s;       d[t - 1].push_back(make_pair(s, i + 1));     }     for (int i = 0; i < 2; i++) {       sort(d[i].begin(), d[i].end());       reverse(d[i].begin(), d[i].end());       S[i].push_back(0);       for (auto x : d[i]) {         S[i].push_back(S[i].back() + x.first);       }     }     int ans = 0;     int I = 0;     for (int i = 0; i * 2 <= v && i <= d[1].size(); i++) {       int cur = S[1][i];       if (v - 2 * i >= d[0].size()) {         cur += S[0].back();       } else {         cur += S[0][v - 2 * i];       }       if (cur > ans) {         ans = cur;         I = i;       }     }     cout << ans <<   n ;     for (int i = 0; i < I; i++) {       cout << d[1][i].second <<    ;     }     for (int i = 0; i < v - 2 * I && i < d[0].size(); i++) {       cout << d[0][i].second <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main(void) {     long long a, b;     cin >> a >> b;     if (a >= b) {       printf( %.12f , (a + b) / ((double)2 * ((a + b) / (2 * b))));     } else       printf( -1 );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long i, j, n, m, d, f, x, d1, ans = 1e9;     cin >> n >> m;     long long a[n], b[n];     for (i = 0; i < n; i++) cin >> a[i];     for (i = 0; i < n; i++) cin >> b[i];     sort(a, a + n);     sort(b, b + n);     for (i = 0; i < n; i++) {       x = i;       d = (b[0] - a[i % n] + m) % m;       f = 1;       for (j = 1; j < n; j++) {         x++;         d1 = (b[j] - a[x % n] + m) % m;         if (d1 != d) {           f = 0;           break;         }       }       if (f) ans = min(ans, d);     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1001;   const long long INF = (long long)1000 * 1000 * 1000 * 1000;   const int INF_SMAL = 1000 * 1000 * 1000;   const int K = 13;   struct edge {     int u, v, cap, flow;     edge(){};     edge(int u, int v, int cap) : u(u), v(v), cap(cap), flow(0){};   };   int x[2 * K * K], y[2 * K * K], ti[2 * K * K];   char p[K][K];   int n, m, female, male;   bool was[K][K];   int s, t;   vector<edge> ed;   vector<int> g[MAXN];   int dx[4] = {0, 1, 0, -1};   int dy[4] = {-1, 0, 1, 0};   void add_edge(int u, int v, int cap) {     g[u].push_back(((int)(ed.size())));     ed.push_back(edge(u, v, cap));     g[v].push_back(((int)(ed.size())));     ed.push_back(edge(v, u, 0));   }   int getc(edge &a) { return a.cap - a.flow; }   bool in_range(int l, int s, int r) { return (l <= s && s < r); }   pair<int, int> deq[MAXN];   void get_g(int ind, int x, int y, long long ti, int fl) {     int di[K][K];     int l = 0, r = 0;     memset(was, 0, sizeof was);     di[x][y] = 0;     was[x][y] = 1;     deq[r++] = {x, y};     while (l < r) {       int x = deq[l].first, y = deq[l].second;       l++;       if (p[x][y] ==  # ) continue;       if (di[x][y] <= ti) {         if (fl == 0) {           add_edge(ind, x * m + y + male + female, 1);         } else {           add_edge(x * m + y + male + female + n * m, ind, 1);         }       }       for (int i = 0; i < 4; i++) {         if (in_range(0, x + dx[i], n) && in_range(0, y + dy[i], m)) {           if (!was[x + dx[i]][y + dy[i]]) {             was[x + dx[i]][y + dy[i]] = 1;             deq[r++] = {x + dx[i], y + dy[i]};             di[x + dx[i]][y + dy[i]] = di[x][y] + 1;           }         }       }     }   }   int di[MAXN];   int bfs(int s, int t) {     int deq[MAXN];     int l = 0, r = 0;     bool was[MAXN];     memset(was, 0, sizeof was);     memset(di, 0, sizeof di);     di[s] = 0;     was[s] = 1;     deq[r++] = s;     while (l < r) {       int u = deq[l++];       for (int i = 0; i < ((int)(g[u].size())); i++) {         if (getc(ed[g[u][i]]) > 0) {           edge buf = ed[g[u][i]];           if (!was[buf.v]) {             was[buf.v] = 1;             di[buf.v] = di[buf.u] + 1;             deq[r++] = buf.v;           }         }       }     }     if (was[t]) return 1;     return 0;   }   int pnt[MAXN];   int dfs(int u, int t, int flow) {     if (u == t || flow == 0) return flow;     for (int &i = pnt[u]; i < ((int)(g[u].size())); i++) {       edge buf = ed[g[u][i]];       if (di[u] + 1 == di[buf.v] && getc(buf) > 0) {         int lans = dfs(buf.v, t, min(flow, getc(buf)));         if (lans > 0) {           ed[g[u][i]].flow += lans;           ed[g[u][i] ^ 1].flow -= lans;           return lans;         }       }     }     return 0;   }   int find_max_flow(int s, int t) {     int ans = 0;     while (bfs(s, t) > 0) {       int lans = -1;       memset(pnt, 0, sizeof pnt);       while ((lans = dfs(s, t, INF_SMAL)) > 0) {         ans += lans;       }     }     return ans;   }   bool check(long long s) {     int t = male + female + 2 * n * m;     int st = t + 1;     for (int i = 0; i < MAXN; i++) {       g[i].clear();     }     ed.clear();     for (int i = 0; i < male; i++) {       get_g(i, x[i], y[i], s / ti[i], 0);       add_edge(st, i, 1);     }     for (int i = 0; i < female; i++) {       get_g(male + i, x[male + i], y[male + i], s / ti[male + i], 1);       add_edge(male + i, t, 1);     }     for (int i = 0; i < n * m; i++) {       add_edge(male + female + i, male + female + i + n * m, 1);     }     int ans = find_max_flow(st, t);     if (ans == male) return 1;     return 0;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cin >> n >> m >> male >> female;     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) cin >> p[i][j];     if (abs(male - female) != 1) {       cout << -1;       return 0;     }     for (int i = 0; i < 1 + female + male; i++) {       cin >> x[i] >> y[i] >> ti[i];       x[i]--;       y[i]--;     }     if (male > female) {       swap(x[0], x[male]);       swap(y[0], y[male]);       swap(ti[0], ti[male]);     }     male = female = max(male, female);     long long l = -1, r = INF;     while (l + 1 < r) {       long long s = (l + r) / 2;       if (check(s))         r = s;       else         l = s;     }     if (r == INF) {       cout << -1;       return 0;     }     cout << r;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = (int)1e6 + 1;   const int INF = (int)1e9;   const int logN = 20;   int n, k, a[N], Log2[N];   int maxValue[N][21];   int getMax(int l, int r) {     int k = Log2[r - l + 1];     return max(maxValue[l][k], maxValue[r - (1 << k) + 1][k]);   }   void solve() {     cin >> n >> k;     int minV = INF;     for (int i = 1; i <= n; ++i) {       cin >> a[i];       maxValue[a[i]][0] = a[i];       minV = min(minV, a[i]);     }     for (int j = 1; (1 << j) < N; ++j) {       for (int i = 1; i + (1 << j) - 1 < N; ++i) {         maxValue[i][j] =             max(maxValue[i][j - 1], maxValue[i + (1 << (j - 1))][j - 1]);       }     }     for (int i = 0; (1 << i) < N; ++i) Log2[(1 << i)] = i;     for (int i = 1; i < N; ++i) Log2[i] = max(Log2[i], Log2[i - 1]);     int res = 1;     for (int i = 2; i <= minV; ++i) {       bool check = 1;       for (int j = i; j < N; j += i) {         int d = getMax(j, min(N - 1, j + i - 1)) - j;         if (d > k) {           check = 0;         }       }       if (check) res = i;     }     cout << res;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 7;   map<int, int> euler;   long long w[maxn];   int phi(int n) {     int now = n;     int ret = n;     if (euler.count(now)) return euler[now];     for (int i = 2; i <= sqrt(n); i++) {       if (n % i == 0) {         ret = ret / i * (i - 1);         while (n % i == 0) n /= i;       }     }     if (n > 1) ret = ret / n * (n - 1);     euler[now] = ret;     return ret;   }   long long MOD(long long n, int mod) { return n < mod ? n : (n % mod + mod); }   long long quick_mod(long long base, long long p, int mod) {     long long ret = 1;     do {       if (p & 1) ret = MOD(base * ret, mod);       base = MOD(base * base, mod);     } while (p >>= 1);     return ret;   }   long long solve(int l, int r, int mod) {     if (l == r || mod == 1) return MOD(w[l], mod);     return quick_mod(w[l], solve(l + 1, r, phi(mod)), mod);   }   int main() {     int n, mod;     scanf( %d%d , &n, &mod);     for (int i = 1; i <= n; i++) scanf( %lld , &w[i]);     int q;     scanf( %d , &q);     while (q--) {       int l, r;       scanf( %d%d , &l, &r);       long long ans = solve(l, r, mod) % mod;       printf( %lld n , ans);     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     char s[55], t[55], i = 0, j = 0;     scanf( %s , s);     scanf( %s , t);     while (t[i] !=   0 ) {       if (t[i] == s[j]) j++;       i++;       if (j >= strlen(s)) break;     }     cout << j + 1;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool comp(pair<long long, long long> a, pair<long long, long long> b) {     if (a.first > a.second && a.first > b.first) return 1;     return 0;   }   void solve() {     long long n;     cin >> n;     vector<pair<double, pair<long long, long long>>> v(n);     for (long long i = (0); i < (n); ++i) {       cin >> v[i].second.first >> v[i].second.second;       v[i].first = v[i].second.first - v[i].second.second;     }     sort(v.begin(), v.end());     reverse(v.begin(), v.end());     long long s = 0;     for (long long i = (0); i < (n); ++i) {       s += v[i].second.first * i + v[i].second.second * (n - i - 1);     }     cout << s;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long t1 = 1;     while (t1--) {       solve();       cout <<   n ;       ;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<int> v(n);     map<int, int> freq;     for (int i = 0; i < n; i++) cin >> v[i];     int min = v[0], max = v[0], maximum = 0;     freq[v[0]]++;     int i = 0, j = 1;     while (j < n) {       while (((v[j] == min || v[j] == max) ||               ((min == max) && abs(v[j] - min) == 1)) &&              j < n) {         freq[v[j]]++;         if (v[j] > min) max = v[j];         if (v[j] < min) min = v[j];         j++;       }       if (j - i > maximum) maximum = j - i;       while (!((v[j] == min || v[j] == max) ||                ((min == max) && abs(v[j] - min) == 1)) &&              i < n) {         freq[v[i]]--;         if (freq[v[i]] == 0) {           if (min == max) {             min = v[j];             max = v[j];             freq[v[j]]++;             j++;           } else if (v[i] == max)             max--;           else if (v[i] == min)             min++;         }         i++;       }     }     cout << maximum;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 14;   int dp[1 << maxn], n, m, ver[maxn][maxn][1 << maxn];   pair<pair<int, int>, int> pre[1 << maxn];   bool valid[maxn][maxn][1 << maxn];   vector<int> G[maxn];   int main() {     scanf( %d%d , &n, &m);     while (m--) {       int u, v;       scanf( %d%d , &u, &v);       u--, v--;       G[u].emplace_back(v);       G[v].emplace_back(u);     }     for (int(u) = (0); (u) <= ((n)-1); (u)++)       for (int v : G[u]) valid[u][v][0] = true;     for (int(mask) = (0); (mask) <= ((1 << n) - 1); (mask)++)       for (int(i) = (0); (i) <= ((n)-1); (i)++)         for (int(j) = (0); (j) <= ((n)-1); (j)++) {           if (!valid[i][j][mask]) continue;           for (int k : G[i])             if (!(mask & (1 << k)) && !valid[k][j][mask | (1 << i)] &&                 (mask || k != j)) {               ver[k][j][mask | (1 << i)] = i;               valid[k][j][mask | (1 << i)] = true;             }         }     memset(dp, 0x3f, sizeof(dp));     for (int(mask) = (1); (mask) <= ((1 << n) - 1); (mask)++) {       int cnt = __builtin_popcount(mask);       if (cnt == 1) {         dp[mask] = 0;         pre[mask] = {{-1, -1}, 0};         continue;       }       for (int sub = mask & (mask - 1); sub; sub = mask & (sub - 1)) {         int rem = mask ^ sub, inc = __builtin_popcount(rem) + 1;         for (int(i) = (0); (i) <= ((n)-1); (i)++)           if (sub & (1 << i)) {             for (int(j) = (0); (j) <= ((n)-1); (j)++)               if (sub & (1 << j)) {                 if (valid[i][j][rem] && dp[sub] + inc < dp[mask]) {                   dp[mask] = dp[sub] + inc;                   pre[mask] = {{i, j}, rem};                 }               }           }       }     }     printf( %d n , dp[(1 << n) - 1]);     for (int mask = (1 << n) - 1; __builtin_popcount(mask) > 1;) {       int u = pre[mask].first.first, v = pre[mask].first.second,           rem = pre[mask].second;       for (int sub = rem; sub;) {         int nxt = ver[u][v][sub];         printf( %d %d n , u + 1, nxt + 1);         sub ^= 1 << nxt;         u = nxt;       }       printf( %d %d n , u + 1, v + 1);       mask = mask ^ rem;     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2010;   const int mod = 998244353;   inline int Pow(int x, int y) {     int res = 1;     for (; y; y >>= 1, x = (long long)x * x % mod)       if (y & 1) res = (long long)res * x % mod;     return res;   }   int f0[N], f1[N], f2[N], g[N];   inline int calc(int len, int tot) {     if (len < 0 || len & 1) return 0;     return (long long)tot * tot % mod * g[len] % mod;   }   inline vector<int> BM(vector<int> y) {     vector<int> coef, diff;     static int delta[N];     int fail = -1;     for (int i = 0, n = y.size(); i < n; i++) {       delta[i] = y[i];       for (int j = 0; j < coef.size(); j++)         delta[i] =             (delta[i] - (long long)coef[j] * y[i - j - 1] % mod + mod) % mod;       if (!delta[i]) continue;       if (fail == -1) {         fail = i, coef.resize(i + 1);         continue;       }       int scale = (long long)delta[i] * Pow(delta[fail], mod - 2) % mod;       vector<int> tmp = coef;       coef.clear(), coef.resize(i - fail - 1), coef.push_back(scale);       for (auto t : diff) coef.push_back((long long)t * (mod - scale) % mod);       fail = i, diff = tmp;       if (coef.size() < tmp.size()) coef.resize(tmp.size());       for (int i = 0; i < tmp.size(); i++) coef[i] = (coef[i] + tmp[i]) % mod;     }     return coef;   }   inline void pre(int n) {     g[0] = g[2] = 1;     for (int i = 4; i <= n; i += 2) g[i] = (g[i - 2] + g[i - 4]) % mod;     for (int i = 2; i <= n; i++) {       f0[i] = calc(i - 1, i - 1), f1[i] = calc(i - 2, i - 1),       f2[i] = calc(i - 3, i - 1);       for (int j = 2; j < i; j++) {         f0[i] = (f0[i] + (long long)calc(j - 1, j - 1) * f0[i - j] +                  (long long)calc(j - 2, j - 1) * f1[i - j]) %                 mod;         f1[i] = (f1[i] + (long long)calc(j - 2, j - 1) * f0[i - j] +                  (long long)calc(j - 3, j - 1) * f1[i - j]) %                 mod;         f2[i] = (f2[i] + (long long)calc(j - 2, j - 1) * f1[i - j] +                  (long long)calc(j - 3, j - 1) * f2[i - j]) %                 mod;       }     }   }   inline int solve(int n) {     int res = (long long)n * (calc(n - 1, n - 1) + calc(n - 3, n - 1)) % mod;     for (int i = 2; i <= n; i++) {       res = (res + (long long)calc(i - 1, i - 1) * f0[n - i] % mod * i) % mod;       res = (res + (long long)calc(i - 2, i - 1) * f1[n - i] % mod * i * 2) % mod;       res = (res + (long long)calc(i - 3, i - 1) * f2[n - i] % mod * i) % mod;     }     return res;   }   int dp[2000010];   int main() {     pre(1000);     vector<int> tmp;     for (int i = 3; i <= 1000; i++) tmp.push_back(dp[i] = solve(i));     auto now = BM(tmp);     int n;     scanf( %d , &n);     for (int i = 1001; i <= n; i++)       for (int j = 0; j < now.size(); j++)         dp[i] = (dp[i] + (long long)now[j] * dp[i - j - 1]) % mod;     printf( %d n , dp[n]);   }


#include <bits/stdc++.h>   #pragma GCC optimize( -O2 )   using namespace std;   string doSum(string a, string b) {     if (a.size() < b.size()) swap(a, b);     int j = a.size() - 1;     for (int i = b.size() - 1; i >= 0; i--, j--) a[j] += (b[i] -  0 );     for (int i = a.size() - 1; i > 0; i--) {       if (a[i] >  9 ) {         int d = a[i] -  0 ;         a[i - 1] = ((a[i - 1] -  0 ) + d / 10) +  0 ;         a[i] = (d % 10) +  0 ;       }     }     if (a[0] >  9 ) {       string k;       k += a[0];       a[0] = ((a[0] -  0 ) % 10) +  0 ;       k[0] = ((k[0] -  0 ) / 10) +  0 ;       a = k + a;     }     return a;   }   const int LIM = 1e5 + 5, MOD = 1e9 + 7;   const long double EPS = 1e-9;   string minofstrings(string a, string b) {     if (a.size() == 0) return b;     if (b.size() == 0) return a;     if (a.size() > b.size()) return b;     if (a.size() < b.size()) return a;     if (a >= b) return b;     return a;   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long l;     cin >> l;     string s;     cin >> s;     vector<int> v;     string ans1, ans2, ans3;     int n = s.length();     if (s[n / 2] !=  0 ) {       ans1 = doSum(s.substr(0, n / 2), s.substr(n / 2, n - n / 2));     } else {       int g = n / 2;       int f = -1;       for (int i = n / 2; i >= 0; --i) {         if (s[i] !=  0 ) {           f = i;           break;         }       }       if (f != -1) ans1 = doSum(s.substr(0, f), s.substr(f, n - f));     }     if (s[(n - 1) / 2] !=  0 ) {       ans2 =           doSum(s.substr(0, (n - 1) / 2), s.substr((n - 1) / 2, n - (n - 1) / 2));     } else {       int g = (n - 1) / 2;       int f = -1;       for (int i = (n - 1) / 2; i < n; ++i) {         if (s[i] !=  0 ) {           f = i;           break;         }       }       if (f != -1) ans2 = doSum(s.substr(0, f), s.substr(f, n - f));     }     if (s[(n + 1) / 2] !=  0 ) {       ans3 =           doSum(s.substr(0, (n + 1) / 2), s.substr((n + 1) / 2, n - (n + 1) / 2));     } else {       int g = (n + 1) / 2;       int f = -1;       for (int i = (n + 1) / 2; i < n; ++i) {         if (s[i] !=  0 ) {           f = i;           break;         }       }       if (f != -1) ans3 = doSum(s.substr(0, f), s.substr(f, n - f));     }     ans1 = minofstrings(ans1, ans2);     ans1 = minofstrings(ans1, ans3);     cout << ans1 <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, k, a[100010], w[100010];   int main() {     while (~scanf( %lld%lld , &n, &k)) {       for (long long i = 1; i <= n; i++) scanf( %lld , &a[i]);       memset(w, -1, sizeof(w));       for (long long i = 1; i <= n; i++)         if (w[a[i]] == -1) {           long long tmp = 256;           for (long long j = a[i] - k + 1; j <= a[i]; j++) {             if (j < 0) continue;             if (w[j] == -1 || w[j] == j) {               tmp = j;               break;             }           }           for (long long k = tmp; k <= a[i]; k++) w[k] = tmp;         }       for (long long i = 1; i <= n; i++) printf( %lld  , w[a[i]]);       printf(  n );     }     return 0;   }


#include <bits/stdc++.h>   const int SIZE = 200000;   int p[SIZE];   int ans[SIZE][2];   int ans_cnt;   bool judge(int a[], int n) {     static int used[SIZE + 1];     for (int i = 1; i <= n; i++) used[i] = 0;     for (int i = 0; i < n; i++) used[a[i]] = 1;     for (int i = 1; i <= n; i++) {       if (!used[i]) return 0;     }     return 1;   }   bool judge(int len1, int n) {     return judge(p, len1) && judge(p + len1, n - len1);   }   int main() {     int t = 0;     scanf( %d , &t);     while (t--) {       ans_cnt = 0;       int n;       scanf( %d , &n);       int ma = 0;       for (int i = 0; i < n; i++) {         scanf( %d , &p[i]);         if (ma < p[i]) ma = p[i];       }       if (judge(n - ma, n)) {         ans[ans_cnt][0] = n - ma;         ans[ans_cnt++][1] = ma;       }       if (ma * 2 != n && judge(ma, n)) {         ans[ans_cnt][0] = ma;         ans[ans_cnt++][1] = n - ma;       }       printf( %d n , ans_cnt);       for (int i = 0; i < ans_cnt; i++) {         printf( %d %d n , ans[i][0], ans[i][1]);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     long long ans = 0;     for (int i = (0); i < (n); ++i) {       long long t, T, x, cost;       cin >> t >> T >> x >> cost;       if (t >= T) {         ans += cost + m * x;         continue;       }       long long aux1 = cost;       if (m > (T - t)) aux1 += m * x;       long long aux2 = (long long)ceil((double)(m - (T - t)) / (T - t)) + 1;       aux2 *= cost;       ans += min(aux1, aux2);     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 10000001;   int a, n, x[maxn];   int main() {     scanf( %d%d , &a, &n);     for (int i = a; i <= a + n - 1; i++) x[i] = i;     for (int i = 2; i * i <= a + n - 1; i++) {       int p = i * i;       int t = ((a + p - 1) / p) * p;       for (int j = t; j <= a + n - 1; j += p)         while (x[j] % p == 0) x[j] /= p;     }     long long ans = 0;     for (int i = a; i <= a + n - 1; i++) ans += x[i];     printf( %I64d n , ans);     return 0;   }


// Copyright (C) 2021 JacderZhang   //   // This program is free software: you can redistribute it and/or modify   // it under the terms of the GNU General Public License as published by   // the Free Software Foundation, either version 3 of the License, or   // (at your option) any later version.   //   // This program is distributed in the hope that it will be useful,   // but WITHOUT ANY WARRANTY; without even the implied warranty of   // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the   // GNU General Public License for more details.   //   // You should have received a copy of the GNU General Public License   // along with this program.  If not, see <https://www.gnu.org/licenses/>.         #ifndef SCANNER_H_   #define SCANNER_H_ 1   #include <stdio.h>   #include <stdlib.h>   class Scanner {   private:     static const int BUFFER_SIZE = 1 << 18;     char buff[BUFFER_SIZE];     char *buffPos, *buffLim;     FILE *file;      public:     Scanner(FILE *file) {       this->file = file;       buffLim = buff + fread(buff, 1, BUFFER_SIZE, file);       buffPos = buff; }      private:     inline void flushBuff() {       buffLim = buff + fread(buff, 1, BUFFER_SIZE, file);       if (buffLim == buff) {         *buffLim++ =   n ; }       buffPos = buff; }     inline bool isWS(char t) {       return t <=    ; }     inline bool isDig(char t) {       return t >=  0  && t <=  9 ; }     inline void nextPos() {       buffPos++;       if (buffPos == buffLim) {         flushBuff(); } }   public:     inline char getchar() {       char ch = *buffPos;       nextPos();       return ch; }     inline void next(char* s) {       while (isWS(*buffPos)) {         nextPos(); }       while (!isWS(*buffPos)) {         *s = *buffPos;         s++;         nextPos(); }       *s =   0 ; }     inline void nextLine(char* s) {       while (*buffPos !=   n ) {         nextPos(); }       if (*buffPos ==   n ) {         nextPos(); }       while (*buffPos !=   n ) {         *s++ = *buffPos;         nextPos(); }       *s =   0 ; }     inline int nextInt() {       while (!isDig(*buffPos) && *buffPos !=  - ) {         nextPos(); }       int sign = (*buffPos ==  - ) ? nextPos(), -1 : 1;       int res = 0;       while (isDig(*buffPos)) {         res = res * 10 + *buffPos -  0 ;         nextPos(); }       return res * sign; }     inline long long nextLong() {       while (!isDig(*buffPos) && *buffPos !=  - ) {         nextPos(); }       long long sign = (*buffPos ==  - ) ? nextPos(), -1 : 1;       long long res = 0;       while (isDig(*buffPos)) {         res = res * 10 + *buffPos -  0 ;         nextPos(); }       return res * sign; }     inline int n() {       while (*buffPos <  0  || *buffPos >  9 ) {         buffPos++;         if (buffPos == buffLim) {           flushBuff(); } }       int res = 0;       while (*buffPos >=  0  && *buffPos <=  9 ) {         res = res * 10 + (*buffPos -  0 );         buffPos++;         if (buffPos == buffLim) {           flushBuff(); } }       return res; }     inline long long nl() {       while (*buffPos <  0  || *buffPos >  9 ) {         buffPos++;         if (buffPos == buffLim) {           flushBuff(); } }       long long res = 0;       while (*buffPos >=  0  && *buffPos <=  9 ) {         res = res * 10 + (*buffPos -  0 );         buffPos++;         if (buffPos == buffLim) {           flushBuff(); } }       return res; }     inline long long nlm(const int MOD) {       while (*buffPos <  0  || *buffPos >  9 ) {         buffPos++;         if (buffPos == buffLim) {           flushBuff(); } }       long long res = 0;       while (*buffPos >=  0  && *buffPos <=  9 ) {         res = (res * 10 + (*buffPos -  0 )) % MOD;         buffPos++;         if (buffPos == buffLim) {           flushBuff(); } }       return res; }     inline double nextDouble() {       while (isWS(*buffPos)) {         nextPos(); }       int sign = (*buffPos ==  - ) ? nextPos(), -1 : 1;       double res = 0;       while (isDig(*buffPos)) {         res = res * 10 + *buffPos -  0 ;         nextPos(); }       if (*buffPos ==  . ) {         nextPos();         double ep = 1;         while (isDig(*buffPos)) {           ep *= 0.1;           res += ep * (*buffPos -  0 );           nextPos(); } }       return sign * res; }     inline char nextChar() {       while (isWS(*buffPos))         nextPos();       char res = *buffPos;       nextPos();       return res; }     ~Scanner() {       fclose(file); } };   #ifndef SCANNER_H_CUSTOM   Scanner sc(stdin);   #endif   #endif /* SCANNER_H_ */   #ifndef LOG_H_   #define LOG_H_ 1      #include <iostream>   #include <utility>   #include <iterator>   #include <string>      std::string cout_list_sep =    ;   template<class IterateType, typename = decltype(std::declval<IterateType>().begin()),                               typename = decltype(std::declval<IterateType>().end()),                               typename = typename std::enable_if<std::is_convertible<                                   typename std::iterator_traits< typename IterateType::iterator> ::iterator_category,                                   std::input_iterator_tag> ::value> ::type,                               typename = typename std::enable_if<!std::is_same<std::string, typename std::decay<IterateType>::type>::value>::type,                               typename value_type = typename IterateType::value_type>   std::ostream& operator<< (std::ostream& out, const IterateType& a)   {     for (const auto& i: a)        out << i << cout_list_sep;     return out;    }      template<class __TyFirst, class __TySecond>   std::ostream&   operator<<(std::ostream& out, const std::pair<__TyFirst, __TySecond>& o)   {     out <<  (  << o.first <<  ,  << o.second <<  ) ;     return out;   }      #ifdef __LOCALE__      template<typename T>   void   __ses(const T& a)   {     std::cout << a <<    ;   }   template<typename T, typename... Args>   void   __ses(const T& a, Args... b)   {     std::cout << a <<    ;     __ses(b...);   }   #define ses(...)                                                                    {                                                                                std::cout << #__VA_ARGS__ <<   =  ;                                               __ses(__VA_ARGS__);                                                             }   #define see(...)                                                                    {                                                                                ses(__VA_ARGS__);                                                                 std::cout << std::endl;                                                         }   #define slog(format, ...) printf(format   n , __VA_ARGS__)      static constexpr char __log_space[] =    ;   template<typename _ForwardIterator>   void   logArray(_ForwardIterator __begin,            _ForwardIterator __end,            const char* __sep = 0)   {     if (__sep == 0) {       __sep = __log_space;     }     while (__begin != __end) {       std::cout << *__begin << *__sep;       ++__begin;     }     std::cout << std::endl;   }      #else      #define see(...)   #define ses(...)   #define slog(format, ...)   template<typename _ForwardIterator>   void   logArray(_ForwardIterator,            _ForwardIterator,            const char* = 0)   {}      #endif      #endif /* LOG_H_ */   #ifndef RANGE_H_   #define RANGE_H_      #include <stdexcept>   #include <iterator>   #include <type_traits>      namespace Temps {      template <typename _IntType>   class RangeInt {     static_assert(std::is_integral<_IntType>::value,  RangeInt object must have integral value type );      public:     class iterator : public std::iterator<std::input_iterator_tag, _IntType, _IntType, const _IntType*, _IntType> {       _IntType val, step;        public:       using typename std::iterator<std::input_iterator_tag, _IntType, _IntType, const _IntType*, _IntType>::reference;       explicit constexpr iterator(int val, int step) noexcept : val(val), step(step) {}       constexpr iterator& operator++() noexcept { val += step; return *this; }       constexpr iterator operator++(int) noexcept { iterator ret = *this; val += step; return ret; }       constexpr bool operator== (const iterator& rhs) const noexcept { return val == rhs.val; }       constexpr bool operator!= (const iterator& rhs) const noexcept { return val != rhs.val; }       constexpr reference operator*() const { return val; }     };        typedef  _IntType    value_type;     typedef  _IntType    size_type;     const value_type _begin, _step, _end;        explicit constexpr RangeInt(const value_type end) noexcept : _begin(0), _step(1), _end(end>0 ? end : 0) {}     explicit constexpr RangeInt(const value_type begin, const value_type end) noexcept :        _begin(begin), _step(1), _end(end>begin ? end : begin) {}     explicit constexpr RangeInt(const value_type begin, const value_type end, const value_type step) :       _begin(begin), _step(step), _end(         ((step>0&&end<=begin) || (step<0&&end>=begin)) ? begin :         (step>0 ? begin+(end-begin+step-1)/step*step : begin+(begin-end-step-1)/(-step)*step)) {}        constexpr iterator begin() const noexcept { return iterator(_begin, _step); }     constexpr iterator end() const noexcept { return iterator(_end, _step); }     constexpr size_type size() const noexcept { return (_end - _begin) / _step; }   };      template <class IntType,             typename = typename std::enable_if<               std::is_integral<IntType>::value>::type>   inline constexpr    RangeInt<IntType> range(IntType arg1) {     return RangeInt<IntType>(arg1);   }      template <class IntType,             typename = typename std::enable_if<               std::is_integral<IntType>::value>::type>   inline constexpr    RangeInt<IntType> range(IntType arg1, IntType arg2) {     return RangeInt<IntType>(arg1, arg2);   }      template <class IntType,             typename = typename std::enable_if<               std::is_integral<IntType>::value>::type>   inline constexpr    RangeInt<IntType> range(IntType arg1, IntType arg2, IntType arg3) {     return RangeInt<IntType>(arg1, arg2, arg3);   }      } /* namespace Temps */      using Temps::range;      #endif      #ifndef UTIL_H_   #define UTIL_H_ 1      #include <algorithm>      #ifndef VECTOR_H_   #include <vector>   #endif      namespace Temps {      template<class T>   inline bool   checkMin(T& a, T b)   { return (b < a ? a = b, 1 : 0); }      template<class T>   inline bool   checkMax(T& a, T b)   { return (a < b ? a = b, 1 : 0); }      template <class IntType, typename = typename             std::enable_if<std::is_integral<IntType>::value>::type>   IntType   gcd(const IntType a, const IntType b) {     return b == 0 ? a : gcd(b, a % b); }      template <class ForwardIterator, class OutputIterator>   void dissociate(ForwardIterator __begin, ForwardIterator __end, OutputIterator __dest) {      #ifdef VECTOR_H_     Temps::Vector   #else     std::vector   #endif       <typename std::iterator_traits<ForwardIterator>::value_type> values(__begin, __end);      std::sort(values.begin(), values.end()); std::unique(values.begin(), values.end());      while (__begin != __end) {       *__dest = std::distance(values.begin(), std::lower_bound(values.begin(), values.end(), *__begin));       __dest++; __begin++; } }      }      using Temps::checkMin;   using Temps::checkMax;      #endif /* UTIL_H_ */   #ifndef VECTOR_H_   #define VECTOR_H_      #include <cstdlib>   #include <utility>   #include <iterator>   #include <initializer_list>   #include <type_traits>      namespace Temps {      template <class Type>   class Vector {     static_assert(std::is_trivial<Type>::value,                     Temps::Vector can only be used for trival types );      public:     typedef Type         value_type;     typedef unsigned int size_type;     typedef Type&        reference;     typedef const Type&  const_reference;        class iterator : public std::iterator<std::random_access_iterator_tag, value_type> {     public:       friend class Vector;       using typename std::iterator<std::random_access_iterator_tag, value_type>::difference_type;       using typename std::iterator<std::random_access_iterator_tag, value_type>::pointer;       using typename std::iterator<std::random_access_iterator_tag, value_type>::reference;          private:       pointer ptr;       iterator(pointer ptr) : ptr(ptr) {}        public:       bool operator== (const iterator rhs) const { return ptr == rhs.ptr; }       bool operator!= (const iterator rhs) const { return ptr != rhs.ptr; }       bool operator<  (const iterator rhs) const { return ptr <  rhs.ptr; }       bool operator<= (const iterator rhs) const { return ptr <= rhs.ptr; }       bool operator>  (const iterator rhs) const { return ptr >  rhs.ptr; }       bool operator>= (const iterator rhs) const { return ptr >= rhs.ptr; }          iterator operator++ ()    { return iterator(++ptr); }       iterator operator++ (int) { return iterator(ptr++); }       iterator operator-- ()    { return iterator(--ptr); }       iterator operator-- (int) { return iterator(ptr--); }          iterator operator+ (const difference_type dif) const { return iterator(ptr + dif); }       iterator operator- (const difference_type dif) const { return iterator(ptr - dif); }       iterator operator+= (const difference_type dif) { ptr += dif; return *this; }       iterator operator-= (const difference_type dif) { ptr -= dif; return *this; }          difference_type operator- (const iterator& rhs) const { return ptr - rhs.ptr; }          operator pointer() { return ptr; }     };         protected:     value_type *a = nullptr;     size_type _capacity=0, _size=0;        void __grow_capacity(size_type least_size) {       if (_capacity >= least_size) { return; }       if (_capacity == 0) { _capacity = 1; }       while (_capacity < least_size) { _capacity = _capacity * 2; }       a = static_cast<value_type*>(realloc(a, sizeof(value_type) * _capacity)); }      public:     Vector() =default;     explicit Vector(size_type size, const value_type& initial_value = value_type()) : _capacity(size), _size(size) {       a = static_cast<value_type*>(malloc(sizeof(value_type) * _capacity));       value_type *__first = a, *const __last = a + _size;       while (__first != __last) { *__first++ = initial_value; } }        Vector(const Vector& rhs) : _capacity(rhs._size), _size(rhs._size) {       a = static_cast<value_type*>(malloc(sizeof(value_type) * _capacity));       value_type *__first = a, *__r_p = rhs.a, *const __last = a + _size;       while (__first != __last) { *__first++ = *__r_p++; } }     Vector(Vector&& rhs) : _capacity(rhs._capacity), _size(rhs._size) {       a = rhs.a; rhs.a = nullptr; }          template <typename Container, typename =               decltype(std::declval<Container>().begin(),                        std::declval<Container>().end())>     Vector(const Container& list) : _capacity(std::distance(list.begin(), list.end())), _size(_capacity) {       a = static_cast<value_type*>(malloc(sizeof(value_type) * _capacity));       value_type *p = a; for (const auto& i: list) { *p++ = i; } }        template <typename _InputIterator, typename = typename                std::enable_if<std::is_convertible<typename std::iterator_traits<_InputIterator>::iterator_category,                                                  std::input_iterator_tag>::value>::type>     explicit Vector(_InputIterator __first, _InputIterator __last) {       _size = _capacity = std::distance(__first, __last);       a = static_cast<value_type*>(malloc(sizeof(value_type) * _capacity));       value_type *p = a; while (__first != __last) { *p++ = *__first++; } }        inline bool empty() const { return _size == 0; }     inline size_type size() const { return _size; }     inline size_type capacity() const { return _capacity; }        void reserve(size_type __capacity) {       _capacity = __capacity;       if (_size > _capacity) { _size = _capacity; }       a = static_cast<value_type*>(realloc(a, sizeof(value_type) * _capacity)); }     void resize(size_type  __size) {       if (_size > __size) { _size = __size; return; }       __grow_capacity(__size);       value_type *__un = a + _size, *const __ed = a + __size;       while (__un != __ed) { *__un++ = value_type(); }       _size = __size; }     inline void clear() { resize(0); }        Vector& operator= (const Vector& rhs) {       __grow_capacity(rhs._size);       _size = rhs._size;       value_type *__first = a;       const value_type *const __last = a+_size, *__r_p = rhs.a;       while (__first != __last) { *__first++ = *__r_p++; }       return *this; }     Vector& operator= (Vector&& rhs) {       _size = rhs._size; _capacity = rhs._capacity;       free(a); a = rhs.a; rhs.a = nullptr;        return *this; }        value_type operator[] (const size_type id) const { return a[id]; }     value_type& operator[] (const size_type id) { return a[id]; }     value_type front() const { return a[0]; }     value_type& front() { return a[0]; }     value_type back() const { return a[_size - 1]; }     value_type& back() { return a[_size - 1]; }     void pop_back() { _size--; }        Vector& push_back(const value_type& b) {       __grow_capacity(_size + 1); a[_size] = b; _size++; return *this; }     Vector& push_back(const Vector& rhs) {       __grow_capacity(_size + rhs._size);       for (const auto& i: rhs) { a[_size++] = i; }        return *this; }     Vector& push_back(const std::initializer_list<value_type>& rhs) {       __grow_capacity(_size + rhs.size());       for (const auto& i: rhs) { a[_size++] = i; }        return *this; }        inline iterator begin() const { return iterator(a); }     inline iterator end() const { return iterator(a + _size); }        ~Vector() { free(a); }      };      } /* namespace Temps */      using Temps::Vector;      #endif /* VECTOR_H_ */      // #include  /home/jack/code/creats/STree.h    // #include  /home/jack/code/creats/Tree.h    // #include  /home/jack/code/creats/Graph.h    // #include  /home/jack/code/creats/Intm.h    // #include  /home/jack/code/Math/Poly/main.h       #include <bits/stdc++.h>      #define MULTIPLE_TEST_CASES_WITH_T   // #define MULTIPLE_TEST_CASES_WITHOUT_T   #ifndef _BODY_MAIN   #define _BODY_MAIN 1      #ifndef CUSTOM_MAIN   void   preInit();   void   init();   void   solve();   int32_t   main()   {     preInit();   #ifdef MULTIPLE_TEST_CASES_WITH_T     int T;   #ifdef SCANNER_H_     T = sc.nextInt();   #else     scanf( %d , &T);   #endif /* SCANNER_H_ */     while (T--) {       init();       solve();     }   #else   #ifdef MULTIPLE_TEST_CASES_WITHOUT_T     while (1) {       try {         init();       } catch (bool t) {         return 0;       }       solve();     }   #else     init();     solve();   #endif /* MULTIPLE_TEST_CASES_WITHOUT_T  */   #endif /* MULTIPLE_TEST_CASES_WITH_T */     return 0;   }   #endif /* CUSTOM_MAIN */      #endif /* _BODY_MAIN */   // #define int long long      /** My code begins here **/         const int kN = 5e5 + 5;      int n, m, dg[kN], p[kN], q[kN], siz[kN], rt[kN], col[kN], col_cnt;   std::vector <int> st_E[kN];   std::set <int> S, E[kN];      void Add(int u, int v) {     E[u].insert(v);     E[v].insert(u);     ++dg[u]; ++dg[v]; }   void AddTree(int u, int v) {     st_E[u].push_back(v);     st_E[v].push_back(u); }   void Dfs(int u, int p) {     for(auto v : S) if(!E[u].count(v))         AddTree(u, v);     for(auto v : st_E[u]) if(v != p) S.erase(v);     for(auto v : st_E[u]) if(v != p) Dfs(v, u); }   void Dfs2(int u, int p) {     bool flag = false;     if(!col[u]) {       for(auto v : st_E[u])         if(!col[v]) flag = true;       if(flag) {         col[u] = ++col_cnt;         rt[col[u]] = u; siz[col[u]] = 1;         for(auto v : st_E[u]) {           if(!col[v]) {             ++siz[col[u]];             col[v] = col[u]; } } }       else {         for(auto v : st_E[u])           if(col[v]) {             if(rt[col[v]] == v) {               ++siz[col[v]]; col[u] = col[v]; }             else if(siz[col[v]] > 2) {               col[u] = ++col_cnt;               rt[col[u]] = u; siz[col[u]] = 2;               --siz[col[v]];               col[v] = col[u]; }             else {               rt[col[v]] = v;               col[u] = col[v];               ++siz[col[u]]; }             break; } } }     for(auto v : st_E[u]) if(v != p)         Dfs2(v, u); }      std::queue <int> que;   std::vector <int> V_col[kN];      void preInit() {}   void init() {     col_cnt = 0;     n = sc.n(); m = sc.n();     for(int i = 1; i <= n; ++i) {       dg[i] = col[i] = siz[i] = p[i] = q[i] = 0;       E[i].clear(); st_E[i].clear();       V_col[i].clear();       S.insert(i); }     for(int i = 1; i <= m; ++i) {       int u, v;       u = sc.n(); v = sc.n();       Add(u, v); }     for(int i = 1; i <= n; ++i)       if(dg[i] == n - 1) {         S.erase(i);         que.push(i); } }      void solve() {     int tot = n;     while(!que.empty()) {       int u = que.front(); que.pop();       p[u] = q[u] = tot--;       for(auto v : E[u]) {         --dg[v];         if(S.count(v) && dg[v] >= tot - 1) {           que.push(v); S.erase(v); } } }        for(int i = 1; i <= n; ++i) if(S.count(i)) { S.erase(i); Dfs(i, 0); }     for(int i = 1; i <= n; ++i) if(!p[i] && !col[i]) Dfs2(i, 0);     for(int i = 1; i <= n; ++i) if(col[i]) V_col[col[i]].push_back(i);     for(int i = 1, s = 1; i <= col_cnt; ++i, ++s) {       q[rt[i]] = s;       for(auto u : V_col[i]) {         if(u != rt[i]) {           p[u] = s;           q[u] = ++s; } }       p[rt[i]] = s; }        for(int i = 1; i <= n; ++i)       printf( %d  , p[i]);     printf(  n );     for(int i = 1; i <= n; ++i)       printf( %d  , q[i]);     printf(  n ); }


#include <bits/stdc++.h>   using namespace std;   const long long N = 400010;   inline long long read() {     long long s = 0, w = 1;     register char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) w = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 )       s = (s << 3) + (s << 1) + (ch ^ 48), ch = getchar();     return s * w;   }   long long n, m, head[N], maxE, tot, deg[N], ot[N], cnt;   struct Edge {     long long nxt, to;   } e[N];   struct Node {     long long w, id;   } p[N];   inline void Add(long long u, long long v) {     e[++maxE].nxt = head[u];     head[u] = maxE;     e[maxE].to = v;   }   inline bool cp(Node x, Node y) { return x.w < y.w; }   inline void Topo() {     queue<long long> Q;     for (register long long i = 1; i <= tot; i++)       if (!deg[i]) Q.push(i);     while (!Q.empty()) {       long long x = Q.front();       Q.pop();       if (x <= m) ot[++cnt] = x;       for (register long long i = head[x]; i; i = e[i].nxt) {         deg[e[i].to]--;         if (!deg[e[i].to]) Q.push(e[i].to);       }     }     if (m > cnt) {       puts( -1 );       exit(0);     }     return;   }   signed main() {     n = read(), m = read();     tot = m;     for (register long long i = 1; i <= n; tot++, i++) {       for (register long long j = 1; j <= m; j++) p[j].w = read(), p[j].id = j;       sort(p + 1, p + 1 + m, cp);       for (register long long j = 1; j <= m; j++) {         if (p[j].w == -1) continue;         if (j == 1 || p[j].w ^ p[j - 1].w) tot++;         Add(tot, p[j].id), Add(p[j].id, tot + 1);         deg[p[j].id]++, deg[tot + 1]++;       }     }     Topo();     for (register long long i = 1; i <= m; i++) printf( %lld  , ot[i]);     puts(  );     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   const long double pi = 3.141592653589793238462643383279;   const long double log23 = 1.58496250072115618145373894394781;   const long double eps = 1e-8;   const long long INF = 1e18 + 239;   const long long prost = 239;   const int two = 2;   const int th = 3;   const long long MOD = 1e9 + 7;   const long long MOD2 = MOD * MOD;   const int BIG = 1e9 + 239;   const int alf = 26;   const int dx[4] = {-1, 0, 1, 0};   const int dy[4] = {0, 1, 0, -1};   const int dxo[8] = {-1, -1, -1, 0, 1, 1, 1, 0};   const int dyo[8] = {-1, 0, 1, 1, 1, 0, -1, -1};   const int dig = 10;   const string str_alf =  abcdefghijklmnopqrstuvwxyz ;   const string str_alf_big =  ABCDEFGHIJKLMNOPQRSTUVWXYZ ;   const int day[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};   const int digarr[10] = {6, 2, 5, 5, 4, 5, 6, 3, 7, 6};   const int bt = 31;   const int fr = 4;   template <typename T>   inline T gcd(T a, T b) {     return a ? gcd(b % a, a) : b;   }   template <typename T>   inline T lcm(T a, T b) {     return (a / gcd(a, b)) * b;   }   inline bool is_down(char x) { return ( a  <= x && x <=  z ); }   inline bool is_upper(char x) { return ( A  <= x && x <=  Z ); }   inline bool is_digit(char x) { return ( 0  <= x && x <=  9 ); }   inline int power(long long a, int b) {     long long res = 1;     while (b > 0) {       if (b & 1) res = (res * a) % MOD;       a = (a * a) % MOD;       b >>= 1;     }     return res;   }   mt19937 rnd(239);   const int M = 1e5 + 239;   const int N = 2 * 1e3 + 239;   const int L = 200;   const int T = (1 << 20);   const int B = trunc(sqrt(M)) + 1;   const int X = 110;   const long long R = (1e17);   int n, x[M], y[M], np[M], mp[M], ms[M], ns[M];   inline long long mysqrt(long long x) {     long long l = 0;     long long r = BIG;     while (r - l > 1) {       long long h = (l + r) >> 1LL;       if (h * h <= x)         l = h;       else         r = h;     }     return l;   }   inline long long dist(pair<int, int> &a, pair<int, int> &b) {     return (long long)(b.first - a.first) * (long long)(b.first - a.first) +            (long long)(b.second - a.second) * (long long)(b.second - a.second);   }   inline long long diam(vector<pair<int, int> > &v) {     long long ans = 0;     for (int i = 0; i < (int)v.size(); i++)       for (int j = i + 1; j < (int)v.size(); j++)         ans = max(ans, dist(v[i], v[j]));     return ans;   }   inline bool checkup(int i, long long r, int z) {     if (y[i] > 0) return false;     int j = upper_bound(y, y + n, min(-y[i], y[i] + z)) - y;     if (i + (n - j) == 0) return true;     int mn = np[i];     int mx = mp[i];     mn = min(mn, ns[j]);     mx = max(mx, ms[j]);     if ((long long)(mn - mx) * (long long)(mn - mx) > r) return false;     mx = max(abs(mx), abs(mn));     mn = max(abs(y[i]), abs(y[j - 1]));     return ((long long)mx * (long long)mx + (long long)mn * (long long)mn <= r);   }   inline bool checkdn(int j, long long r, int z) {     if (y[j] < 0) return false;     int i = lower_bound(y, y + n, max(-y[j], y[j] - z)) - y;     j++;     if (i + (n - j) == 0) return true;     int mn = np[i];     int mx = mp[i];     mn = min(mn, ns[j]);     mx = max(mx, ms[j]);     if ((long long)(mn - mx) * (long long)(mn - mx) > r) return false;     mx = max(abs(mx), abs(mn));     mn = max(abs(y[i]), abs(y[j - 1]));     return ((long long)mx * (long long)mx + (long long)mn * (long long)mn <= r);   }   int main() {     ios_base::sync_with_stdio(0);     cin >> n;     for (int i = 0; i < n; i++) cin >> x[i] >> y[i];     vector<tuple<int, int, int> > v;     for (int i = 0; i < n; i++) v.push_back(make_tuple(y[i], x[i], i));     sort(v.begin(), v.end());     for (int i = 0; i < n; i++) x[i] = get<1>(v[i]), y[i] = get<0>(v[i]);     np[0] = BIG;     mp[0] = -BIG;     for (int i = 0; i < n; i++) {       np[i + 1] = min(np[i], x[i]);       mp[i + 1] = max(mp[i], x[i]);     }     ns[n] = BIG;     ms[n] = -BIG;     for (int i = n - 1; i >= 0; i--) {       ns[i] = min(ns[i + 1], x[i]);       ms[i] = max(ms[i + 1], x[i]);     }     long long l = -1;     long long r = R;     while (r - l > 1) {       long long h = (l + r) >> 1LL;       int z = mysqrt(h);       bool ok = false;       for (int i = 0; i < n; i++) {         if (checkup(i, h, z)) {           ok = true;           break;         }         if (checkdn(i, h, z)) {           ok = true;           break;         }       }       if (!ok)         l = h;       else         r = h;     }     long long ans =         min(r, (long long)(mp[n] - np[n]) * (long long)(mp[n] - np[n]));     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int solve() {     long long n;     cin >> n;     vector<vector<long long> > mat(n, vector<long long int>(n, 0));     for (long long int i = 0; i < n - 1; i++) {       long long x, y;       cin >> x >> y;       x--, y--;       mat[x][y] = 1;     }     vector<pair<long long, pair<long long int, long long int> > > ans;     vector<long long int> row(n, 0);     for (long long int i = 0; i < n; i++)       for (long long int j = 0; j < n; j++) row[i] += mat[i][j];     long long tot = 0;     for (long long int i = 0; i < n; i++)       for (long long int j = i; j < n; j++)         if (row[i] > row[j] && i != j) {           swap(mat[i], mat[j]);           swap(row[i], row[j]);           ans.push_back(make_pair(1, make_pair(i, j)));         }     for (long long int i = 0; i < n; i++) {       for (long long int j = i; j < n; j++) {         if (row[j] + tot == i) {           long long x = row[j];           tot += x;           if (j != i) {             swap(mat[i], mat[j]);             swap(row[i], row[j]);             ans.push_back(make_pair(1, make_pair(i, j)));           }           for (long long int k = i - x; k < i; k++) {             if (mat[i][k] != 1) {               for (long long int k1 = i; k1 < n; k1++)                 if (mat[i][k1] == 1) {                   ans.push_back(make_pair(2, make_pair(k, k1)));                   for (long long int s = 0; s < n; s++)                     swap(mat[s][k], mat[s][k1]);                 }             }           }           break;         }         long long x = row[i];         for (long long int k = i; k < n; k++) {           if (mat[i][k] == 1) {             for (long long int k1 = i - x; k1 < i; k1++)               if (mat[i][k1] == 0) {                 ans.push_back(make_pair(2, make_pair(k, k1)));                 for (long long int s = 0; s < n; s++) swap(mat[s][k], mat[s][k1]);               }           }         }       }     }     cout << (long long int)ans.size() <<   n ;     for (long long int i = 0; i < (long long int)ans.size(); i++) {       cout << ans[i].first <<     << ans[i].second.first + 1 <<                << ans[i].second.second + 1 <<   n ;     }     return 0;   }   int main() {     auto start = chrono::high_resolution_clock::now();     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long test_cases = 1;     while (test_cases--) solve();     auto stop = chrono::high_resolution_clock::now();     auto duration = chrono::duration_cast<chrono::milliseconds>(stop - start);   }


#include <bits/stdc++.h>   using namespace std;   int a, b, c, d;   int gcd(int first, int second) {     if (!second) return first;     return gcd(second, first % second);   }   pair<int, int> sol, curr;   int main() {     cin >> a >> b >> c >> d;     int dd = gcd(a, b);     a /= dd;     b /= dd;     dd = gcd(c, d);     c /= dd;     d /= dd;     sol.first = 1;     sol.second = 1;     if (a * d < b * c) {       curr.first = (b * c - a * d) * a;       curr.second = c * a * b;       dd = gcd(curr.first, curr.second);       curr.first /= dd;       curr.second /= dd;       if (curr.first * sol.second < sol.first * curr.second) sol = curr;     } else {       curr.first = (a * d - b * c) * b;       curr.second = d * a * b;       dd = gcd(curr.first, curr.second);       curr.first /= dd;       curr.second /= dd;       if (curr.first * sol.second < sol.first * curr.second) sol = curr;     }     cout << sol.first <<  /  << sol.second <<   n ;     return 0;   }