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


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


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


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


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


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


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


#include <bits/stdc++.h> n using namespace std; n char s[1010000]; n int main() { n   int i, j, k, m, n; n   scanf( %s , s); n   n = strlen(s); n   if (n % 2 == 1) { n     n = (n + 1) / 2; n     for (i = 1; i <= n; i++) putchar( 4 ); n     for (i = 1; i <= n; i++) putchar( 7 ); n     puts(  ); n   } else { n     char u =  7 ; n     int flag = 0; n     for (i = 0; i < n; i++) { n       if (i + i == n) u =  4 ; n       if (s[i] > u) { n         flag = -1; n         break; n       } else if (s[i] < u) { n         flag = 1; n         break; n       } n     } n     if (flag == -1) { n       n = (n + 2) / 2; n       for (i = 1; i <= n; i++) putchar( 4 ); n       for (i = 1; i <= n; i++) putchar( 7 ); n       puts(  ); n     } else { n       int pos = -1; n       int c4 = 0, c7 = 0; n       int f = 0; n       for (i = 0; i < n; i++) { n         if (f || s[i] <=  4 ) { n           if (s[i] <  4 ) f = 1; n           s[i] =  4 ; n           pos = i; n           c4++; n         } else if (s[i] <=  7 ) { n           if (s[i] <  7 ) f = 1; n           s[i] =  7 ; n           c7++; n         } else { n           s[i] =  4 ; n           s[pos] =  7 ; n           pos = i; n           c7++; n           f = 1; n         } n       } n       if (c7 > c4) { n         int cnt = 0; n         for (i = n - 1; i >= 0; i--) { n           if (s[i] ==  7 ) cnt++; n           if (cnt >= (c7 - c4) / 2 + 1) break; n         } n         for (; i >= 0; i--) n           if (s[i] ==  4 ) { n             c7++; n             c4--; n             s[i] =  7 ; n             break; n           } n         for (i = i + 1; i < n; i++) n           if (s[i] ==  7 ) { n             s[i] =  4 ; n             c7--; n             c4++; n           } n       } n       if (c7 < c4) { n         for (i = n - 1; i >= 0; i--) { n           if (c4 > c7 && s[i] ==  4 ) { n             s[i] =  7 ; n             c4--; n             c7++; n           } n         } n       } n       puts(s); n     } n   } n   scanf( %*d ); n } n


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


#include <bits/stdc++.h> n using namespace std; n template <typename T> n struct Point { n  public: n   T x, y; n   Point() : x(0), y(0) {} n   Point(T x_, T y_) : x(x_), y(y_) {} n   template <typename U> n   explicit Point(const Point<U>& p) : x(p.x), y(p.y) {} n   Point(const std::pair<T, T>& p) : x(p.first), y(p.second) {} n   Point(const std::complex<T>& p) : x(real(p)), y(imag(p)) {} n   explicit operator std::pair<T, T>() const { return std::pair<T, T>(x, y); } n   explicit operator std::complex<T>() const { return std::complex<T>(x, y); } n   friend std::ostream& operator<<(std::ostream& o, const Point& p) { n     return o <<  (  << p.x <<  ,  << p.y <<  ) ; n   } n   friend std::istream& operator>>(std::istream& i, Point& p) { n     return i >> p.x >> p.y; n   } n   friend bool operator==(const Point& a, const Point& b) { n     return a.x == b.x && a.y == b.y; n   } n   friend bool operator!=(const Point& a, const Point& b) { return !(a == b); } n   friend bool operator<(const Point& a, const Point& b) { n     return (a.x != b.x ? a.x < b.x : a.y < b.y); n   } n   friend T norm(const Point& a) { return a.x * a.x + a.y * a.y; } n   friend T abs(const Point& p) { return std::hypot(p.x, p.y); } n   friend T unit(const Point& a) { n     if (a == Point()) return a; n     return a / abs(a); n   } n   friend Point conj(const Point& a) { return Point(a.x, -a.y); } n   friend Point perp(const Point& a) { return Point(-a.y, a.x); } n   friend long double arg(const Point& p) { return atan2(p.y, p.x); } n   friend Point dir(long double angle) { return Point(cos(angle), sin(angle)); } n   Point& operator+=(const Point& p) { n     x += p.x, y += p.y; n     return *this; n   } n   Point& operator-=(const Point& p) { n     x -= p.x, y -= p.y; n     return *this; n   } n   Point& operator*=(const T& t) { n     x *= t, y *= t; n     return *this; n   } n   Point& operator/=(const T& t) { n     x /= t, y /= t; n     return *this; n   } n   Point& operator*=(const Point& t) { n     Point res = Point(x, y) * t; n     x = res.x, y = res.y; n     return *this; n   } n   Point& operator/=(const Point& t) { n     Point res = Point(x, y) / t; n     x = res.x, y = res.y; n     return *this; n   } n   friend Point operator+(const Point& a, const Point& b) { n     return Point(a.x + b.x, a.y + b.y); n   } n   friend Point operator-(const Point& a, const Point& b) { n     return Point(a.x - b.x, a.y - b.y); n   } n   friend Point operator*(const Point& a, const T& t) { n     return Point(a.x * t, a.y * t); n   } n   friend Point operator*(const T& t, const Point& a) { n     return Point(t * a.x, t * a.y); n   } n   friend Point operator/(const Point& a, const T& t) { n     return Point(a.x / t, a.y / t); n   } n   friend Point operator*(const Point& a, const Point& b) { n     return Point(a.x * b.x - a.y * b.y, a.y * b.x + a.x * b.y); n   } n   friend Point operator/(const Point& a, const Point& b) { n     return Point(a * conj(b) / norm(b)); n   } n   friend T int_norm(const Point& a) { return __gcd(a.x, a.y); } n   friend T int_unit(const Point& a) { n     if (a == Point()) return a; n     return a / int_norm(a); n   } n   friend T cross(const Point& a, const Point& b) { n     return a.x * b.y - a.y * b.x; n   } n   friend T dot(const Point& a, const Point& b) { return a.x * b.x + a.y * b.y; } n   friend T area(const Point& a, const Point& b, const Point& c) { n     return cross(b - a, c - a); n   } n   friend Point rotation(const Point& a, const Point& b) { n     return Point(dot(a, b), cross(a, b)); n   } n   friend bool same_dir(const Point& a, const Point& b) { n     return cross(a, b) == 0 && dot(a, b) > 0; n   } n   friend bool is_reflex(const Point& a, const Point& b) { n     auto c = cross(a, b); n     return c ? (c < 0) : (dot(a, b) < 0); n   } n   friend bool angle_less(const Point& base, const Point& second, n                          const Point& t) { n     int r = is_reflex(base, second) - is_reflex(base, t); n     return r ? (r < 0) : (0 < cross(second, t)); n   } n   friend bool angle_cmp(const Point& base) { n     return [base](const Point& second, const Point& t) { n       return angle_less(base, second, t); n     }; n   } n   friend bool angle_cmp_center(const Point& center, const Point& dir) { n     return [center, dir](const Point& second, const Point& t) -> bool { n       return angle_less(dir, second - center, t - center); n     }; n   } n   friend int angle_between(const Point& second, const Point& t, n                            const Point& p) { n     if (same_dir(p, second) || same_dir(p, t)) return 0; n     return angle_less(second, p, t) ? 1 : -1; n   } n }; n int main() { n   int n; n   cin >> n; n   auto query = [&](int t, int x, int y, int z) { n     cout << t <<     << y + 1 <<     << z + 1 <<     << x + 1 << endl; n     long long ret; n     cin >> ret; n     return ret; n   }; n   int e1 = 0; n   int e2 = 1; n   vector<int> L, R; n   vector<long long> A(n); n   for (int i = 2; i < n; i++) { n     if (query(2, e1, i, e2) > 0) { n       R.push_back(i); n     } else { n       L.push_back(i); n     } n   } n   int nl = (int)(L).size(); n   int nr = (int)(R).size(); n   for (int i = 2; i < n; i++) { n     A[i] = query(1, e1, e2, i); n   } n   vector<int> hull; n   hull.push_back(e2); n   { n     sort((L).begin(), (L).end(), [&](int x, int y) { return A[x] < A[y]; }); n     deque<int> d; n     int big = -1; n     if ((int)(L).size()) big = L.back(); n     while ((int)(L).size()) { n       int x = L.back(); n       L.pop_back(); n       if ((int)(d).size() == 0) { n         d.push_back(x); n       } else { n         if (query(2, e2, x, big) > 0) { n           d.push_front(x); n         } else { n           d.push_back(x); n         } n       } n     } n     for (int x : d) hull.push_back(x); n     hull.push_back(e1); n   } n   { n     sort((R).begin(), (R).end(), [&](int x, int y) { return A[x] < A[y]; }); n     deque<int> d; n     int big = -1; n     if ((int)(R).size()) big = R.back(); n     while ((int)(R).size()) { n       int x = R.back(); n       R.pop_back(); n       if ((int)(d).size() == 0) { n         d.push_back(x); n       } else { n         if (query(2, e1, x, big) > 0) { n           d.push_front(x); n         } else { n           d.push_back(x); n         } n       } n     } n     for (int x : d) hull.emplace_back(x); n   } n   cout << 0 <<    ; n   vector<int> res; n   int id = 0; n   for (int i = 0; i < n; i++) { n     if (hull[i] == 0) id = i; n   } n   for (int i = 0; i < n; i++) { n     res.emplace_back(hull[(id + i) % n]); n   } n   for (int x : res) { n     cout << x + 1 <<    ; n   } n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n pair<pair<int, int>, pair<int, int> > find_pramougolnik(int x1, int y1, int x2, n                                                         int y2) { n   int lef = x1 - 1, rig = x2; n   while (lef + 1 < rig) { n     int mid = (lef + rig) / 2; n     cout <<  ?   << x1 <<     << y1 <<     << mid <<     << y2 << endl; n     int kol; n     cin >> kol; n     if (kol == 1) n       rig = mid; n     else n       lef = mid; n   } n   int up = rig; n   lef = x1 - 1, rig = x2; n   while (lef + 1 < rig) { n     int mid = (lef + rig) / 2; n     cout <<  ?   << mid + 1 <<     << y1 <<     << x2 <<     << y2 << endl; n     int kol; n     cin >> kol; n     if (kol == 1) n       lef = mid; n     else n       rig = mid; n   } n   int down = lef + 1; n   lef = y1 - 1, rig = y2; n   while (lef + 1 < rig) { n     int mid = (lef + rig) / 2; n     cout <<  ?   << x1 <<     << y1 <<     << x2 <<     << mid << endl; n     int kol; n     cin >> kol; n     if (kol == 1) n       rig = mid; n     else n       lef = mid; n   } n   int rights = rig; n   lef = y1 - 1, rig = y2; n   while (lef + 1 < rig) { n     int mid = (lef + rig) / 2; n     cout <<  ?   << x1 <<     << mid + 1 <<     << x2 <<     << y2 << endl; n     int kol; n     cin >> kol; n     if (kol == 1) n       lef = mid; n     else n       rig = mid; n   } n   int lefts = lef + 1; n   return make_pair(make_pair(down, lefts), make_pair(up, rights)); n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   int n; n   cin >> n; n   int lef = 0, rig = n; n   while (lef + 1 < rig) { n     int mid = (lef + rig) / 2; n     cout <<  ? 1 1   << n <<     << mid << endl; n     int kol; n     cin >> kol; n     if (kol > 0) n       rig = mid; n     else n       lef = mid; n   } n   if (rig != n) { n     cout <<  ? 1   << rig + 1 <<     << n <<     << n << endl; n     int kol; n     cin >> kol; n     if (kol == 1) { n       pair<pair<int, int>, pair<int, int> > A = find_pramougolnik(1, 1, n, rig); n       pair<pair<int, int>, pair<int, int> > B = n           find_pramougolnik(1, rig + 1, n, n); n       cout <<  !   << A.first.first <<     << A.first.second <<     n            << A.second.first <<     << A.second.second <<     << B.first.first n            <<     << B.first.second <<     << B.second.first <<     n            << B.second.second << endl; n       exit(0); n     } n   } n   lef = 0, rig = n; n   while (lef + 1 < rig) { n     int mid = (lef + rig) / 2; n     cout <<  ? 1 1   << mid <<     << n << endl; n     int kol; n     cin >> kol; n     if (kol > 0) n       rig = mid; n     else n       lef = mid; n   } n   pair<pair<int, int>, pair<int, int> > A = find_pramougolnik(1, 1, rig, n); n   pair<pair<int, int>, pair<int, int> > B = find_pramougolnik(rig + 1, 1, n, n); n   cout <<  !   << A.first.first <<     << A.first.second <<     n        << A.second.first <<     << A.second.second <<     << B.first.first n        <<     << B.first.second <<     << B.second.first <<     n        << B.second.second << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(nullptr); n   int Q; n   cin >> Q; n   while (Q-- > 0) { n     int N; n     string S; n     cin >> N >> S; n     if (N == 2 && S[0] >= S[1]) { n       cout <<  NO  <<   n ; n     } else { n       cout <<  YES  <<   n ; n       cout << 2 <<   n ; n       cout << S[0] <<     << S.substr(1) <<   n ; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int ques[50005]; n int ma[26]; n int main() { n   string s; n   cin >> s; n   int i, j; n   memset(ques, 0, sizeof(ques)); n   int br = 1; n   for (i = 0; i < (s.size()); i++) { n     if (i != 0) ques[i] = ques[i] + ques[i - 1]; n     if (s[i] ==  ? ) ques[i] += 1; n   } n   for (i = 0; i < 26; i++) ma[i] = -100; n   vector<char> second_bag; n   int first_ind = 0; n   for (i = 0; i < s.size(); i++) { n     ma[s[i] -  A ] = i; n     if (i >= 25) { n       int t; n       int char_count = 0; n       vector<char> bag; n       for (t = 0; t < 26; t++) { n         if (!(ma[t] >= (i - 25) && (ma[t] <= i))) { n           char_count++; n           char ss =  A  + t; n           bag.push_back(ss); n         } n       } n       int ques_count = ques[i]; n       if ((i - 25) > 0) ques_count = ques_count - ques[i - 26]; n       if (char_count > ques_count) n         bag.clear(); n       else { n         int tt; n         first_ind = i - 25; n         int vc_count = 0; n         for (tt = (i - 25); tt <= i; tt++) { n           if (s[tt] ==  ? ) { n             second_bag.push_back(bag[vc_count]); n             vc_count++; n           } else { n             second_bag.push_back(s[tt]); n           } n         } n         br = 0; n         break; n       } n     } n   } n   if (br == 0) { n     i = 0; n     while (i < s.size()) { n       if (i != first_ind) { n         if (s[i] !=  ? ) n           cout << s[i]; n         else n           cout <<  A ; n       } else { n         int temp1 = i - i; n         for (temp1 = 0; temp1 < 26; temp1++) { n           cout << second_bag[temp1]; n           i = i + 1; n         } n         i = i - 1; n       } n       i = i + 1; n     } n   } n   if (br == 1) cout << -1 << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long double area(long double a, long double b, long double c) { n   long double s = (a + b + c) / 2.0; n   return sqrt(s * (s - a) * (s - b) * (s - c)); n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int i, j; n   long double l[9], a = 0; n   for (i = 0; i < 6; i++) cin >> l[i]; n   for (i = 0, j = 6; i < 6; i += 2, j++) { n     l[j] = n         sqrt(((l[i]) * (l[i])) + ((l[i + 1]) * (l[i + 1])) + l[i] * l[i + 1]); n     a += area(l[i], l[i + 1], l[j]); n   } n   a += area(l[6], l[7], l[8]); n   int temp = (4.0 * a) / (long double)sqrt(3); n   cout << temp <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int N, M; n vector<int> graph[200005]; n int nd[2], deg[2]; n int cnt[2][200005]; n int dsu[200005]; n int olddsu[200005]; n int sz[4]; n int getrt(int n) { return dsu[n] = (dsu[n] == n ? n : getrt(dsu[n])); } n int getoldrt(int n) { n   return olddsu[n] = (olddsu[n] == n ? n : getoldrt(olddsu[n])); n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cin >> N >> M; n   for (int i = 1; i <= M; i++) { n     int a, b; n     cin >> a >> b; n     graph[a].push_back(b); n     graph[b].push_back(a); n   } n   cin >> nd[0] >> nd[1] >> deg[0] >> deg[1]; n   for (int i = 1; i <= N; i++) { n     dsu[i] = i; n   } n   vector<pair<int, int>> ans; n   for (int n = 1; n <= N; n++) { n     for (int e : graph[n]) { n       if (n != nd[0] && n != nd[1] && e != nd[0] && e != nd[1]) { n         if (getrt(n) != getrt(e)) { n           dsu[getrt(n)] = getrt(e); n           ans.emplace_back(n, e); n         } n       } n     } n   } n   bool spedge = 0; n   for (int k = 0; k < 2; k++) { n     for (int e : graph[nd[k]]) { n       cnt[k][getrt(e)]++; n       if (e == nd[0] || e == nd[1]) { n         spedge = 1; n       } n     } n     cnt[k][nd[0]] = cnt[k][nd[1]] = 0; n   } n   for (int i = 1; i <= N; i++) { n     olddsu[i] = dsu[i]; n   } n   for (int k = 0; k < 2; k++) { n     for (int e : graph[nd[k]]) { n       if (getrt(e) != getrt(nd[k]) && cnt[k][getoldrt(e)] && n           !cnt[k ^ 1][getoldrt(e)]) { n         ans.emplace_back(e, nd[k]); n         dsu[getrt(e)] = getrt(nd[k]); n         deg[k]--; n       } n     } n   } n   for (int k = 0; k < 2; k++) { n     for (int e : graph[nd[k]]) { n       if (cnt[k][getoldrt(e)] && cnt[k ^ 1][getoldrt(e)] && n           getrt(e) != getrt(nd[k]) && deg[k] > 0) { n         ans.emplace_back(e, nd[k]); n         dsu[getrt(e)] = getrt(nd[k]); n         deg[k]--; n       } n     } n   } n   if (deg[0] > 0 && deg[1] > 0 && spedge && getrt(nd[0]) != getrt(nd[1])) { n     deg[0]--, deg[1]--; n     ans.emplace_back(nd[0], nd[1]); n     dsu[getrt(nd[0])] = getrt(nd[1]); n   } n   if (ans.size() == N - 1 && deg[0] >= 0 && deg[1] >= 0) { n     cout <<  Yes n ; n     for (auto p : ans) { n       cout << p.first <<     << p.second <<   n ; n     } n   } else { n     cout <<  No n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int a[200]; n int main() { n   int n, k; n   cin >> n >> k; n   for (int i = 0; i < n; i++) { n     string d; n     cin >> d; n     a[d.size()]++; n   } n   string s; n   cin >> s; n   int k1 = s.size(); n   int r = 0; n   for (int i = 1; i < 150; i++) { n     if (k1 > i) r += a[i]; n   } n   int p = r / k; n   cout << p * 5 + r + 1 <<    ; n   r += a[k1]; n   r--; n   p = r / k; n   cout << p * 5 + r + 1; n   return 0; n } n