#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:256000000 )   using namespace std;   const int MAXN = 3005;   int r, c, n, k;   pair<int, int> v[MAXN];   int prv[MAXN], nxt[MAXN];   vector<int> y[MAXN], x[MAXN];   int pos[MAXN];   int num[MAXN];   int cnt;   long long ans;   int res;   bool cmp_x(int num1, int num2) { return v[num1].first < v[num2].first; }   bool cmp_y(int num1, int num2) { return v[num1].second < v[num2].second; }   int trivia(int x1, int x2) {     int cnt[MAXN];     memset(cnt, 0, sizeof(cnt));     for (int yy = 1; yy <= c; yy++) {       for (int i = 0; i < y[yy].size(); i++) {         if (x1 <= v[y[yy][i]].first && v[y[yy][i]].first <= x2) {           cnt[yy]++;         }       }     }     int res = 0;     for (int yy1 = 1; yy1 <= c; yy1++) {       int cur = 0;       for (int y2 = yy1; y2 <= c; y2++) {         cur += cnt[y2];         if (cur >= k) {           res++;         }       }     }     return res;   }   void solve() {     scanf( %d%d%d%d , &r, &c, &n, &k);     for (int i = 1; i <= n; i++) {       scanf( %d%d , &v[i].first, &v[i].second);       y[v[i].second].push_back(i);       x[v[i].first].push_back(i);     }     for (int i = 1; i <= r; i++) {       sort(x[i].begin(), x[i].end(), cmp_y);     }     for (int i = 1; i <= c; i++) {       sort(y[i].begin(), y[i].end(), cmp_x);     }     v[n + 1].second = c + 1;     for (int i = 1; i <= r; i++) {       cnt = 0;       res = 0;       for (int j = 1; j <= c; j++) {         for (int h = (int)y[j].size() - 1; h >= 0; h--) {           int curnum = y[j][h];           if (v[curnum].first < i) {             break;           }           pos[curnum] = ++cnt;           num[cnt] = curnum;           prv[cnt] = cnt - 1;           nxt[cnt - 1] = cnt;         }       }       nxt[cnt] = cnt + 1;       num[cnt + 1] = n + 1;       nxt[cnt + 1] = 0;       for (int j = k; j <= cnt; j++) {         res += (v[num[j + 1]].second - v[num[j]].second) *                (v[num[j - k + 1]].second);       }       for (int j = r; j >= i; j--) {         ans += res;         for (int h = 0; h < x[j].size(); h++) {           vector<int> all;           all.reserve(k << 1);           int back = 0;           int p = prv[pos[x[j][h]]];           while (p && all.size() < k - 1) {             all.push_back(p);             p = prv[p];           }           back = all.size();           reverse(all.begin(), all.end());           if (p) {             res +=                 (v[num[nxt[pos[x[j][h]]]]].second - v[num[pos[x[j][h]]]].second) *                 (v[num[p]].second);           }           p = pos[x[j][h]];           while (p && all.size() <= k + back) {             all.push_back(p);             p = nxt[p];           }           for (int l = max(k - 1, back); l + 1 < all.size(); l++) {             res -= (v[num[all[l + 1]]].second - v[num[all[l]]].second) *                    (v[num[all[l - k + 1]]].second);           }           for (int l = max(k, back + 1); l + 1 < all.size(); l++) {             res += (v[num[all[l + 1]]].second - v[num[all[l]]].second) *                    (v[num[all[l - k]]].second);           }           prv[nxt[pos[x[j][h]]]] = prv[pos[x[j][h]]];           nxt[prv[pos[x[j][h]]]] = nxt[pos[x[j][h]]];         }       }     }     printf( %I64d n , ans);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     srand(1313);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MAXN = 2e6;   long long cnt[MAXN];   signed main() {     long long n, m, k;     ios_base::sync_with_stdio(false);     cin >> n >> m >> k;     vector<long long> f(n);     vector<pair<long long, long long> > s(m);     for (long long i = 0; i < n; i++) cin >> f[i];     for (long long i = 0; i < m; i++) cin >> s[i].first;     for (long long i = 0; i < m; i++) s[i].second = i;     sort(s.begin(), s.end());     reverse(s.begin(), s.end());     fill(cnt, cnt + MAXN, 0);     for (auto ff : f) {       if (ff < MAXN) {         cnt[ff]++;       }     }     long long taken = 0;     bool flag = true;     for (long long i = 0; flag && i < (n + k - 1) / k; i++) {       taken += cnt[i];       long long needed = min(n, (i + 1) * k);       flag &= (taken <= needed);     }     if (!flag) {       cout << -1 << endl;     } else {       long long left = 0, right = m + 1;       while (left + 1 < right) {         long long med = (left + right) / 2;         for (long long i = 0; i < med; i++) {           if (s[i].first < MAXN) {             cnt[s[i].first]++;           }         }         taken = 0;         bool flag = true;         for (long long i = 0; flag && i < (n + k + med - 1) / k; i++) {           taken += cnt[i];           long long needed = min(n + med, (i + 1) * k);           flag &= (taken <= needed);         }         for (long long i = 0; i < med; i++) {           if (s[i].first < MAXN) {             cnt[s[i].first]--;           }         }         if (flag) {           left = med;         } else {           right = med;         }       }       cout << left << endl;       for (long long i = 0; i < left; i++) {         cout << s[i].second + 1 <<    ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int s, v1, v2, t1, t2, i1, i2;     cin >> s >> v1 >> v2 >> t1 >> t2;     i1 = s * v1 + 2 * t1;     i2 = s * v2 + 2 * t2;     if (i1 < i2)       cout <<  First ;     else if (i1 > i2)       cout <<  Second ;     else       cout <<  Friendship ;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 500 + 10;   const int P = 998244353;   int N, X, f[MAXN][MAXN], pw[MAXN][MAXN], binom[MAXN][MAXN];   void add(int& a, int b) { a = a + b >= P ? a + b - P : a + b; }   int dif(int a, int b) { return a - b < 0 ? a - b + P : a - b; }   int main() {     for (int i = (0), iend = (MAXN); i < iend; ++i) {       pw[i][0] = (i > 0);       for (int j = (1), jend = (MAXN); j < jend; ++j)         pw[i][j] = 1ll * pw[i][j - 1] * i % P;     }     binom[0][0] = 1;     for (int i = (1), iend = (MAXN); i < iend; ++i) {       binom[i][0] = 1;       for (int j = (1), jend = (i + 1); j < jend; ++j)         binom[i][j] = binom[i - 1][j - 1], add(binom[i][j], binom[i - 1][j]);     }     for (int i = (1), iend = (MAXN); i < iend; ++i) f[0][i] = 1;     for (int i = (2), iend = (MAXN); i < iend; ++i)       for (int j = (1), jend = (MAXN); j < jend; ++j) {         for (int x = i - 1; x < j; x += i - 1) {           for (int k = (1), kend = (i); k < kend; ++k)             add(f[i][j],                 1ll * binom[i][k] * f[i - k][j - x] % P * pw[i - 1][k] % P);         }         for (int x = 0; x < j; x += i - 1) add(f[i][j], pw[min(i - 1, j - x)][i]);       }     scanf( %d %d , &N, &X);     printf( %d n , f[N][X]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 10;   vector<int> e[maxn], re[maxn], List;   int n, m, id[maxn], tt, cnt[maxn], ans;   bool vis[maxn];   void input() {     scanf( %d%d , &n, &m);     for (int u, v, i = 1; i <= m; i++) {       scanf( %d%d , &u, &v);       e[u].push_back(v);       re[v].push_back(u);     }   }   void dfs(int u) {     vis[u] = 1;     for (vector<int>::iterator it = e[u].begin(); it != e[u].end(); it++) {       if (!vis[*it]) {         dfs(*it);       }     }     List.push_back(u);   }   void rdfs(int u, int k) {     id[u] = k;     cnt[k]++;     for (vector<int>::iterator it = re[u].begin(); it != re[u].end(); it++) {       if (!id[*it]) {         rdfs(*it, k);       }     }   }   void scc() {     tt = 0;     for (int i = 1; i <= n; i++)       if (!vis[i]) dfs(i);     reverse(List.begin(), List.end());     for (vector<int>::iterator it = List.begin(); it != List.end(); it++)       if (!id[*it]) {         tt++;         rdfs(*it, tt);       }   }   void bfs(int u) {     queue<int> q;     while (!q.empty()) q.pop();     q.push(u);     vis[u] = 1;     int c = 0, x = 0;     bool ok = 0;     while (!q.empty()) {       u = q.front();       q.pop();       if (cnt[id[u]]) {         c += cnt[id[u]] - 1;         x++;         if (cnt[id[u]] > 1) ok = 1;         cnt[id[u]] = 0;       }       for (vector<int>::iterator it = e[u].begin(); it != e[u].end(); it++) {         if (!vis[*it]) {           vis[*it] = 1;           q.push(*it);         }       }       for (vector<int>::iterator it = re[u].begin(); it != re[u].end(); it++) {         if (!vis[*it]) {           vis[*it] = 1;           q.push(*it);         }       }     }     ans += c + x - 1;     if (ok) ans++;   }   void solve() {     memset(vis, 0, sizeof vis);     for (int i = 1; i <= n; i++)       if (!vis[i]) {         bfs(i);       }     printf( %d , ans);   }   int main() {     input();     scc();     solve();   }


#include <bits/stdc++.h>   using namespace std;   const long long int mod = 1e9 + 7;   const long long int inf = 1e18;   const double EPS = 1E-9;   int n, m;   int main(void) {     cin >> n >> m;     if (m > n) {       int temp = m;       m = n;       n = temp;     }     if (m == 1) {       cout << n << endl;     } else if (m == 2) {       cout << 2 * (2 * (n / 4) + min(n % 4, 2)) << endl;     } else if (m >= 3) {       if ((n == 3 && m == 3) || (n == 3 && m == 5) || (n == 3 && m == 6) ||           (n == 4 && m == 4)) {         if (n == 3 && m == 3) {           cout << 5 << endl;         } else if (n == 3 && m == 5) {           cout << 7 << endl;         } else if (n == 3 && m == 6) {           cout << 7 << endl;         } else {           cout << 8 << endl;         }       } else {         cout << m * n - (m * n) / 2 << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 11111111;   const long long INF = (long long)(1e12);   const long long mod = 998244353;   const double eps = 1e-9;   long long n, mx = -1, inv[N], a[N], k, all, cnt, ans;   map<long long, long long, greater<long long> > M, S;   long long get(long long x) { return (x) * (x + 1) / 2; }   int main() {     ios_base ::sync_with_stdio(false);     cin >> n >> k;     all = (1ll << k) - 1;     ans = get(n);     M[0]++;     for (long long i = 1; i <= n; ++i) {       cin >> a[i];       a[i] ^= a[i - 1];       inv[i] = (all ^ a[i]);       if (M[a[i]] < M[inv[i]]) {         ans -= M[a[i]];         M[a[i]]++;       } else {         ans -= M[inv[i]];         M[inv[i]]++;       }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename TYPE>   inline TYPE sqr(const TYPE& a) {     return (a) * (a);   }   const int INF = 1000 * 1000 * 1000;   const long double EPS = 1e-9;   const long double PI = 2 * acos(0.0);   const int N = 100100;   int top;   int j;   int a[N];   string ans;   bool f() {     if (j >= top) return false;     if (a[j] == 0) {       ++j;       ans.append( int );       return true;     }     ++j;     ans.append( pair< );     if (!f()) return false;     ans.append( , );     if (!f()) return false;     ans.append( > );     return true;   }   int main() {     int n;     scanf( %d n , &n);     string s;     getline(cin, s);     for (int i = 0; i < int(s.size()); ++i)       if (s[i] ==  t )         a[top++] = 0;       else if (s[i] ==  p )         a[top++] = 1;     if (!f() || j < top) {       puts( Error occurred );     } else {       puts(ans.c_str());     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double PI = 3.1415926535897932238460;   bool arr[361];   void angles() {     for (int i = 3; i < 361; i++)       if ((i - 2) * 180 % i == 0) {         arr[(i - 2) * 180 / i] = true;       }   }   int main() {     int t;     cin >> t;     angles();     while (t--) {       int k;       cin >> k;       if (arr[k])         cout <<  YES               <<   n ;       else         cout <<  NO               <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   bool a[1100][26];   vector<bool> v(1100, false);   int main() {     int n;     cin >> n;     for (int i = 0; i < n; i++) {       string s;       cin >> s;       for (auto c : s) a[i][c - 97] = true;     }     for (int i = 0; i < n; i++) {       if (v[i]) continue;       for (int j = i + 1; j < n; j++) {         bool b = true;         for (int g = 0; g < 26; g++)           if (a[i][g] != a[j][g]) b = false;         if (b) {           v[j] = true;         }       }     }     int ans = 0;     for (int i = 0; i < n; i++)       if (!v[i]) ans++;     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 40;   void solve() {     long long int n, m, k;     cin >> n >> m >> k;     long long int beg = 1, end = n * m;     long long int fa;     while (beg <= end) {       long long int mid = (beg + end) / 2;       long long int cnt = 0;       for (int i = 1; i <= n; i++) {         cnt += min(m, mid / i);       }       if (cnt >= k) {         end = mid - 1;         fa = mid;       } else         beg = mid + 1;     }     cout << fa <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int T = 1;     while (T--) {       solve();       if (T) {         char c;       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9;   const int N = 1e7 + 100;   unordered_map<int, int> vis, Cnt;   vector<int> Mice;   vector<int> Cheese;   int main() {     int n, m, y0, y1;     scanf( %d%d%d%d , &n, &m, &y0, &y1);     for (int i = 0; i < n; i++) {       int x;       scanf( %d , &x);       Mice.push_back(x);     }     for (int i = 0; i < m; i++) {       int x;       scanf( %d , &x);       Cheese.push_back(x);     }     int Ans = 0;     for (int x : Mice) {       int L = INF, R = INF;       auto it = lower_bound(Cheese.begin(), Cheese.end(), x);       if (it != Cheese.end()) R = *it;       if (it != Cheese.begin()) it--;       L = *it;       int cur = min(abs(x - L), abs(R - x));       if (x - L == R - x) {         if (!vis.count(L))           vis[L] = x - L, Cnt[L] = 1;         else {           if (vis[L] == x - L)             Cnt[L]++;           else {             if (!vis.count(R))               vis[R] = cur, Cnt[R] = 1;             else if (vis[R] > cur) {               Ans += vis[R];               vis[R] = cur;               Cnt[R] = 1;             } else if (vis[R] == cur)               Cnt[R]++;             else               Ans++;           }         }       } else {         int d = (x - L < R - x ? L : R);         if (!vis.count(d))           vis[d] = cur, Cnt[d] = 1;         else {           if (vis[d] > cur) {             Ans += Cnt[d];             vis[d] = cur;             Cnt[d] = 1;           } else if (vis[d] < cur)             Ans++;           else             Cnt[d]++;         }       }     }     printf( %d n , Ans);     return 0;   }


#include<bits/stdc++.h>   #define x first   #define y second      using namespace std;      typedef long long LL;   typedef long double LD;   typedef pair<int,int> PII;      const int N=100005;      int n,m,T;      int main(){    cin>>T;       int k1,k2,t1,t2,x1,x2;       while(T--){           cin>>n>>k1>>k2;           cin>>t1>>t2;           x1=(k1+k2)/2;           if((k1+k2)&1) n--;           x2=n-x1;           if( t1<=x1 && t2<=x2 ) cout<< YES <<endl;           else cout<< NO <<endl;       }    return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, size[200010] = {0};   vector<int> w[200010];   int dpMax(int, int);   int dpMin(int, int);   int child(int x) {     int ret = 0;     for (int i = 0; i < w[x].size(); i++) ret += child(w[x][i]);     return size[x] = ret + !w[x].size();   }   int dpMax(int x, int t) {     int ret1, ret2;     ret1 = ret2 = !w[x].size();     for (int i = 0; i < w[x].size(); i++) {       if (!t)         ret1 = max(ret1, size[x] - size[w[x][i]] + dpMin(w[x][i], 0));       else         ret2 += (dpMin(w[x][i], 1));     }     return !t ? ret1 : ret2;   }   int dpMin(int x, int t) {     int ret1, ret2;     ret1 = 1;     ret2 = 1 + (1 << 28) * (w[x].size() > 0);     for (int i = 0; i < w[x].size(); i++) {       if (!t)         ret1 += (dpMax(w[x][i], 0) - 1);       else         ret2 = min(ret2, (dpMax(w[x][i], 1)));     }     return !t ? ret1 : ret2;   }   int main() {     scanf( %d , &n);     for (int i = 0, a, b; i < n - 1; i++) {       scanf( %d%d , &a, &b);       w[a].push_back(b);     }     child(1);     printf( %d %d n , dpMax(1, 0), dpMax(1, 1));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int P = 1e9 + 7;   int n, m;   namespace flow {   int n, s, t;   int head[200306], to[200306 << 1], nex[200306 << 1], wto[200306 << 1], ecn = 1;   int ade(int u, int v, int w) {     to[++ecn] = v, nex[ecn] = head[u], wto[ecn] = w, head[u] = ecn;     to[++ecn] = u, nex[ecn] = head[v], wto[ecn] = 0, head[v] = ecn;     return ecn;   }   queue<int> Q;   int dep[200306], cur[200306];   const int inf = 1e9;   void clear() {     for (int i = (1), iend = (n); i <= iend; ++i) head[i] = dep[i] = cur[i] = 0;     ecn = 1;   }   bool bfs() {     Q.push(s);     for (int i = (1), iend = (n); i <= iend; ++i) cur[i] = head[i];     memset(dep, 0x3f, sizeof dep);     dep[s] = 0;     while (!Q.empty()) {       int u = Q.front();       Q.pop();       for (int i = head[u]; i; i = nex[i])         if (dep[to[i]] > inf && wto[i]) dep[to[i]] = dep[u] + 1, Q.push(to[i]);     }     return dep[t] < inf;   }   long long dfs(int u, long long lim) {     if (!lim || u == t) return lim;     long long flow = 0, f;     for (int& i = cur[u]; i; i = nex[i])       if (dep[to[i]] == dep[u] + 1 && (f = dfs(to[i], min(lim, 1ll * wto[i])))) {         lim -= f, flow += f, wto[i] -= f, wto[i ^ 1] += f;         if (!lim) break;       }     return flow;   }   long long dinic() {     long long res = 0;     while (bfs()) res += dfs(s, 0x3f3f3f3f3f3f3f3f);     return res;   }   }  // namespace flow   pair<int, int> ed[200306];   int bc[200306];   long long chk(int x) {     for (int i = (1), iend = (n); i <= iend; ++i) flow::ade(n + m + 1, i, x);     for (int i = (1), iend = (m); i <= iend; ++i) {       int u = ed[i].first, v = ed[i].second;       bc[i] = flow::ade(u, i + n, 1);       flow::ade(v, i + n, 1);       flow::ade(i + n, n + m + 2, 1);     }     long long as = flow::dinic();     flow::clear();     return as;   }   void solve() {     cin >> n >> m;     for (int i = (1), iend = (m); i <= iend; ++i) {       int u, v;       scanf( %d%d , &u, &v);       ed[i] = make_pair(u, v);     }     int l = 0, r = n;     flow::s = n + m + 1, flow::t = n + m + 2, flow::n = n + m + 2;     while (l <= r) {       int mid = l + r >> 1;       long long as = chk(mid);       if (as == m) {         r = mid - 1;       } else         l = mid + 1;     }     cout << l << endl;     chk(l);     for (int i = (1), iend = (m); i <= iend; ++i) {       int u = ed[i].first, v = ed[i].second;       if (flow::wto[bc[i]])         printf( %d %d n , u, v);       else         printf( %d %d n , v, u);     }   }   signed main() { solve(); }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 2e5 + 5;   vector<pair<int, int> > adj[MAXN];   int n;   bool mark[MAXN];   int p[MAXN];   int curv;   void dfs(int v, int ind = -1) {     mark[v] = 1;     for (int i = 0; i < adj[v].size(); i++) {       pair<int, int> u = adj[v][i];       if (!mark[u.first]) {         dfs(u.first, u.second);       } else if (u.second != ind) {         curv = u.first;       }     }   }   int main() {     cin >> n;     int x;     int d = -1;     for (int i = 1; i <= n; i++) {       cin >> x;       if (x == i) {         d = i;       }       p[i] = x;       adj[i].push_back({x, i});       adj[x].push_back({i, i});     }     int cnt = 0;     vector<int> ve;     for (int i = 1; i <= n; i++) {       if (!mark[i]) {         dfs(i);         cnt++;         ve.push_back(curv);       }     }     if (d != -1) {       cout << cnt - 1 <<   n ;       for (int i = 0; i < ve.size(); i++) {         p[ve[i]] = d;       }       for (int i = 1; i <= n; i++) {         cout << p[i] <<    ;       }       return 0;     }     cout << cnt <<   n ;     for (int i = 0; i < ve.size(); i++) {       p[ve[i]] = ve[0];     }     for (int i = 1; i <= n; i++) {       cout << p[i] <<    ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 2000;   const int MAXE = 30001;   const int INF = 2000000002;   struct edge {     int to;     int w;     int id;     edge() {}     edge(int to, int w, int id) : to(to), w(w), id(id) {}     bool operator==(const edge& e) const {       return to == e.to && w == e.w && id == e.id;     }   };   int cost[MAXE];   int conn[MAXN][MAXN];   int find_path(int s, int t, const vector<vector<edge> >& g, vector<edge>& path,                 vector<int>& used) {     used[s] = 1;     if (s == t) {       return 1;     }     for (auto& val : g[s]) {       int to = val.to;       if (!used[to]) {         path.push_back(val);         int res = find_path(to, t, g, path, used);         if (res) {           return res;         }         path.pop_back();       }     }     return 0;   }   int timer, tin[MAXN], fup[MAXN];   void dfs(int v, const vector<vector<edge> >& g, vector<int>& bridges,            vector<int>& used, int p = -1) {     used[v] = true;     tin[v] = fup[v] = timer++;     for (auto& val : g[v]) {       int to = val.to;       if (to == p) continue;       if (used[to])         fup[v] = min(fup[v], tin[to]);       else {         dfs(to, g, bridges, used, v);         fup[v] = min(fup[v], fup[to]);         if (fup[to] > tin[v] && conn[v][to] == 1) {           int id = val.id;           bridges[id] = 1;         }       }     }   }   void find_bridges(const vector<vector<edge> >& g, vector<int>& bridges) {     timer = 0;     vector<int> used(MAXN, 0);     for (int i = 1; i < g.size(); ++i)       if (!used[i]) dfs(i, g, bridges, used);   }   pair<int, int> find_best(int s, int t, const vector<vector<edge> >& g) {     vector<edge> path;     vector<int> used(MAXN, 0);     int res = find_path(s, t, g, path, used);     if (!res) {       return make_pair(0, -1);     }     vector<int> bridges(MAXE, 0);     find_bridges(g, bridges);     int min_price = INF;     int best_id = -1;     for (auto& val : path) {       int id = val.id;       if (bridges[id] && cost[id] < min_price) {         best_id = id;         min_price = cost[id];       }     }     return make_pair(min_price, best_id);   }   void remove(vector<vector<edge> >& g, int cur, edge val) {     int to = val.to;     auto it = find(g[cur].begin(), g[cur].end(), val);     g[cur].erase(it);     val.to = cur;     it = find(g[to].begin(), g[to].end(), val);     g[to].erase(it);     conn[cur][to]--;     conn[to][cur]--;   }   void restore(vector<vector<edge> >& g, int cur, edge val) {     int to = val.to;     g[cur].push_back(val);     val.to = cur;     g[to].push_back(val);     conn[cur][to]++;     conn[to][cur]++;   }   int main(int argc, char const* argv[]) {     vector<vector<edge> > g(MAXN);     int n, m;     cin >> n >> m;     int s, t;     cin >> s >> t;     for (int i = 0; i < m; i++) {       int x, y, w;       cin >> x >> y >> w;       g[x].push_back(edge(y, w, i));       g[y].push_back(edge(x, w, i));       conn[x][y]++;       conn[y][x]++;       cost[i] = w;     }     vector<edge> path;     vector<int> used(MAXN, 0);     int res = find_path(s, t, g, path, used);     if (!res) {       cout << 0 <<   n ;       cout << 0;       return 0;     }     int best_price = INF;     int cur = s;     int id1, id2;     for (auto val : path) {       int id = val.id;       int to = val.to;       remove(g, cur, val);       pair<int, int> best = find_best(s, t, g);       if (best.first < INF) {         int cur_price = val.w + best.first;         if (cur_price < best_price) {           id1 = val.id;           id2 = best.second;           best_price = cur_price;         }       }       restore(g, cur, val);       cur = to;     }     if (best_price >= INF) {       cout << -1;       return 0;     }     cout << best_price <<   n ;     if (id2 == -1) {       cout << 1 <<   n ;       cout << id1 + 1;     } else {       cout << 2 <<   n ;       cout << id1 + 1 <<     << id2 + 1 <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long maxn = 4e5 + 1;   struct dak {     long long val, pos;   };   long long l[maxn], r[maxn];   long long pre[maxn], pre2[maxn];   vector<dak> p;   vector<pair<long long, long long> > v;   vector<pair<long long, long long> > qr;   long long n, m, q;   long long cur = 0;   long long res[maxn];   inline long long get(long long r, long long x) { return pre[r] - pre[r - x]; }   inline long long cnt(long long x) { return pre2[x] - pre2[l[x] - 1]; }   void join(long long pos) {     cur -= get(pos - 1, cnt(pos - 1)) + get(r[pos], cnt(r[pos])) -            get(r[pos], cnt(r[pos]) + cnt(pos - 1));     r[l[pos - 1]] = r[pos];     l[r[pos]] = l[pos - 1];   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> m >> q;     for (long long i = 1; i <= n; i++) {       long long x;       cin >> x;       v.push_back({x, 1});       cur += x;     }     for (long long i = 1; i <= m; i++) {       long long x;       cin >> x;       v.push_back({x, 0});     }     sort(v.begin(), v.end());     for (long long i = 1; i <= n + m; i++) {       l[i] = r[i] = i;       pre[i] = pre[i - 1] + v[i - 1].first;       pre2[i] = pre2[i - 1] + v[i - 1].second;     }     for (long long i = 1; i < n + m; i++) {       p.push_back({v[i].first - v[i - 1].first, i + 1});     }     sort(p.begin(), p.end(),          [](const dak &a, const dak &b) { return a.val < b.val; });     for (long long i = 1, x; i <= q; i++) {       cin >> x;       qr.push_back({x, i});     }     sort(qr.begin(), qr.end());     long long pos = 0;     for (pair<long long, long long> &query : qr) {       while (pos < p.size() && p[pos].val <= query.first) {         join(p[pos].pos);         pos++;       }       res[query.second] = cur;     }     for (long long i = 1; i <= q; i++) cout << res[i] <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     for (int i = 1; i <= n; i++)       if (n == i * (i + 1) / 2) {         cout <<  YES ;         return 0;       }     cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 3e5 + 2;   int n, m, a[N], cnt[N], nxt[N];   bool vis[N];   int main() {     int test;     cin >> test;     while (test--) {       cin >> n >> m;       for (int i = 0; i <= n; ++i) cnt[i] = 0;       for (int i = 1; i <= n; ++i) {         cin >> a[i];         int t1 = i + n - a[i], t2 = i - a[i] + 1;         int k1 = -1, k2 = -1;         if (t1 < n) {           k1 = t1;         }         if (t2 > 0) {           k2 = t2 - 1;         }         if (k1 >= 0) ++cnt[k1];         if (k2 >= 0) cnt[k2] += k1 != k2;       }       vector<int> ans;       ans.clear();       for (int i = 0; i < n; ++i) {         if (n - cnt[i] > m * 2) continue;         for (int j = 1; j <= n; ++j) {           vis[j] = false;           if (a[j] <= n - i) {             nxt[j] = i + a[j];           } else {             nxt[j] = a[j] - (n - i);           }         }         int cycles = 0;         for (int j = 1; j <= n; ++j)           if (nxt[j] != j && !vis[j]) {             int u = j;             ++cycles;             vis[j] = true;             while (nxt[u] != j) {               u = nxt[u];               vis[u] = true;             }           }         if (n - cnt[i] - cycles <= m) {           ans.push_back(i);         }       }       cout << (int)ans.size() <<    ;       for (int i : ans) cout << i <<    ;       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long K = 10000000000LL;   vector<long long> L;   void init(long long crr) {     if (crr > K) return;     if (crr != 0) L.push_back(crr);     init(crr * 10 + 4);     init(crr * 10 + 7);   }   bool is_lucky(long long x) {     if (x == 0) return false;     while (x > 0) {       if (x % 10 != 4 && x % 10 != 7) return false;       x /= 10;     }     return true;   }   const int MAX_M = 20;   long long fact(long long k) {     long long res = 1;     for (int i = 1; i <= k; ++i) res *= i;     return res;   }   vector<int> kth_permutation(int n, long long k) {     vector<int> res(n), num(n);     for (int i = 0; i < (int)(n); i++) num[i] = i;     if (k >= fact(n)) return vector<int>();     for (int i = 0; i < (int)(n); i++) {       long long f = fact(n - i - 1);       res[i] = num[k / f];       num.erase(num.begin() + (k / f));       k %= f;     }     return res;   }   long long perm_n, perm_m;   vector<int> perm_last;   bool init_permutation(long long n, long long k) {     perm_n = n;     perm_last = kth_permutation(min(n, 20LL), k);     if (perm_last.empty()) return false;     perm_m = perm_n - perm_last.size();     return true;   }   long long get_permutation(long long i) {     if (i < perm_m)       return i;     else       return perm_m + perm_last[i - perm_m];   }   int bruteforce(int N, int K) {     vector<int> A(N);     for (int i = 0; i < (int)(N); i++) A[i] = i + 1;     for (int i = 0; i < (int)(K - 1); i++)       next_permutation((A).begin(), (A).end());     int ans = 0;     for (int i = 0; i < (int)(N); i++)       if (is_lucky(i + 1) && is_lucky(A[i])) ++ans;     return ans;   }   int main() {     init(0);     long long N, K;     while (cin >> N >> K) {       --K;       if (!init_permutation(N, K)) {         puts( -1 );         continue;       }       long long ans = 0;       for (int i = 0; i < (int)(L.size()); i++) {         long long l = L[i];         if (1 <= l && l <= N && is_lucky(1 + get_permutation(l - 1))) ++ans;       }       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   namespace my_template {   const long double PI =       3.14159265358979323846264338327950288419716939937510582097494L;   template <typename T>   pair<T, T> operator+(const pair<T, T> &a, const pair<T, T> &b) {     return pair<T, T>(a.first + b.first, a.second + b.second);   }   template <typename T>   pair<T, T> operator-(const pair<T, T> &a, const pair<T, T> &b) {     return pair<T, T>(a.first - b.first, a.second - b.second);   }   template <typename T>   T operator*(const pair<T, T> &a, const pair<T, T> &b) {     return (a.first * b.first + a.second * b.second);   }   template <typename T>   T operator^(const pair<T, T> &a, const pair<T, T> &b) {     return (a.first * b.second - a.second * b.first);   }   template <typename T>   void print(vector<T> vec, string name =   ) {     cout << name;     for (auto u : vec) cout << u <<    ;     cout <<   n ;   }   }  // namespace my_template   using namespace my_template;   const int MOD = 1000000007;   const long long INF = std::numeric_limits<long long>::max();   const int MX = 500101;   int N;   vector<pair<int, int>> sk;   vector<int> color;   struct node {     int l, r;     int did;     int lazy;     int dp, seg;     node *left = nullptr;     node *right = nullptr;     node(int a, int b) : l(a), r(b), did(0), lazy(0), dp(0), seg(0) {       if (l != r) {         left = new node(l, (l + r) / 2);         right = new node((l + r) / 2 + 1, r);       }     }     inline void push() {       if (!lazy) return;       did += lazy;       if (l != r) {         left->lazy += lazy;         right->lazy += lazy;       } else {         seg += lazy;         assert(did == dp + seg);       }       lazy = 0;     }     void upd(int pos, int val) {       push();       if (l == r) {         dp = max(dp, val);         did = dp + seg;         return;       } else if (pos <= (l + r) / 2)         left->upd(pos, val);       else         right->upd(pos, val);       left->push();       right->push();       did = max(left->did, right->did);     }     void add(int a, int b, int val) {       push();       if (r < a or b < l)         return;       else if (a <= l and r <= b) {         lazy += val;         push();         return;       } else {         left->add(a, b, val);         right->add(a, b, val);         left->push();         right->push();         did = max(left->did, right->did);       }     }     int get(int a, int b) {       push();       if (r < a or b < l)         return 0;       else if (a <= l and r <= b) {         return did;       } else {         return max(left->get(a, b), right->get(a, b));       }     }   };   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> N;     {       vector<pair<pair<int, int>, int>> temp(N);       for (int i = 0; i < N; ++i) {         cin >> temp[i].first.first >> temp[i].first.second >> temp[i].second;       }       sort(temp.begin(), temp.end(),            [](const pair<pair<int, int>, int> &a,               const pair<pair<int, int>, int> &b) {              return a.first.second < b.first.second or                     (a.first.second == b.first.second and                      a.first.first > b.first.first);            });       sk.resize(N);       color.resize(N);       for (int i = 0; i < N; ++i) {         sk[i] = temp[i].first;         color[i] = temp[i].second - 1;       }     }     int big = 0;     {       map<int, int> rem;       for (int i = 0; i < N; ++i) {         rem[sk[i].first] = 1;         rem[sk[i].second] = 1;       }       int piv = 1;       for (auto &&u : rem) u.second = piv++;       for (int i = 0; i < N; ++i) {         sk[i].first = rem[sk[i].first];         sk[i].second = rem[sk[i].second];         big = max(big, sk[i].second);       }     }     node *dp[2];     dp[0] = new node(0, big + 10);     dp[1] = new node(0, big + 10);     int ats = 0;     for (int i = 0; i < N; ++i) {       int c = color[i];       int first = sk[i].first;       int second = sk[i].second;       int curr = dp[1 - c]->get(0, first - 1) + 1;       dp[1 - c]->add(0, first - 1, 1);       dp[c]->upd(second, curr);       ats = max(ats, curr);     }     printf( %d n , ats);   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     long long n, m;     cin >> n >> m;     vector<vector<long long> > a(m, vector<long long>(n));     for (long long i = 0; i <= n - 1; i++) {       for (long long j = 0; j <= m - 1; j++) {         cin >> a[j][i];         a[j][i]--;       }     }     long long ans = 0;     for (long long i = 0; i <= m - 1; i++) {       vector<long long> temp(n, 0);       for (long long j = 0; j <= n - 1; j++) {         if (a[i][j] % m == i) {           long long x = a[i][j] / m;           if (x < n) {             temp[(j - x + n) % n]++;           }         }       }       long long lol = INT_MAX;       for (long long j = 0; j <= n - 1; j++) {         lol = min(lol, (n - temp[j] + j));       }       ans += lol;     }     cout << ans <<   n ;     return;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long t = 1;     for (long long i = 1; i <= t; i++) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long SIZE = 1e5;   long long n, a[SIZE], dp[SIZE][2][2];   void Max(long long &a, long long b) { a = max(a, b); }   signed main() {     cin >> n;     for (long long i = 0; i < n; i++) {       cin >> a[i];     }     for (long long i = 0; i < n; i++) {       for (long long j = 0; j < 2; j++) {         for (long long k = 0; k < 2; k++) {           dp[i][j][k] = 1;         }       }     }     for (long long i = 0; i < (n - 1); i++) {       if (a[i] < a[i + 1]) {         Max(dp[i + 1][0][0], dp[i][0][0] + 1);         Max(dp[i + 1][1][0], dp[i][1][0] + 1);       }       Max(dp[i + 1][1][1], dp[i][0][0] + 1);       if (i && (a[i + 1] - a[i - 1] > 1)) {         Max(dp[i + 1][1][0], dp[i][1][1] + 1);       }     }     long long ans = 1;     for (long long i = 0; i < n; i++) {       Max(ans, min(dp[i][0][0] + 1, n));       for (long long j = 0; j < 2; j++) {         Max(ans, dp[i][1][j]);       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   typedef struct {     int op, l, r, x, y;   } query;   int n, m, seed, vmax, a[100000];   query qs[100000];   int rnd() {     int ret = seed;     seed = (1LL * seed * 7LL + 13LL) % 1000000007LL;     return ret;   }   long long get_num(map<int, long long>& mp, int i) {     auto it = mp.lower_bound(i);     if (it == mp.end() || it->first > i) it--;     return it->second;   }   long long pow(long long a, int b, int mod) {     if (b == 0) return 1LL;     if (b == 1) return a % mod;     long long c = pow(a, b / 2, mod) % mod;     if (b & 1) return (((c * c) % mod) * (a % mod)) % mod;     return (c * c) % mod;   }   void debug_range(map<int, long long>& mp) {     for (auto i = mp.begin(); i != mp.end(); i++)       printf( (%d %lld)  , i->first, i->second);     printf(  n );   }   int main() {     scanf( %d%d%d%d , &n, &m, &seed, &vmax);     for (int i = 0; i < n; i++) a[i] = (rnd() % vmax) + 1;     for (int i = 0; i < m; i++) {       qs[i].op = (rnd() % 4) + 1;       qs[i].l = (rnd() % n) + 1 - 1;       qs[i].r = (rnd() % n) + 1 - 1;       if (qs[i].l > qs[i].r) swap(qs[i].l, qs[i].r);       if (qs[i].op == 3)         qs[i].x = (rnd() % (qs[i].r - qs[i].l + 1)) + 1;       else         qs[i].x = (rnd() % vmax) + 1;       if (qs[i].op == 4) qs[i].y = (rnd() % vmax) + 1;     }     map<int, long long> mp;     mp[0] = a[0];     for (int i = 1; i < n; i++)       if (a[i] != a[i - 1]) mp[i] = a[i];     for (int i = 0; i < m; i++) {       if (qs[i].op == 1) {         long long tmp = get_num(mp, qs[i].r + 1);         mp[qs[i].r + 1] = tmp;         tmp = qs[i].x + get_num(mp, qs[i].l);         mp[qs[i].l] = tmp;         for (auto it = mp.lower_bound(qs[i].l + 1);              it != mp.end() && it->first <= qs[i].r; it++)           it->second += qs[i].x;       } else if (qs[i].op == 2) {         long long tmp = get_num(mp, qs[i].r + 1);         mp[qs[i].r + 1] = tmp;         vector<int> era;         for (auto it = mp.lower_bound(qs[i].l);              it != mp.end() && it->first <= qs[i].r; it++)           era.push_back(it->first);         for (int x : era) mp.erase(x);         mp[qs[i].l] = qs[i].x;       } else if (qs[i].op == 3) {         map<long long, int> smp;         int r = mp.lower_bound(qs[i].l) != mp.end()                     ? min(qs[i].r + 1, mp.lower_bound(qs[i].l)->first)                     : qs[i].r + 1;         smp[get_num(mp, qs[i].l)] = r - qs[i].l;         for (auto it = mp.lower_bound(qs[i].l);              it != mp.end() && it->first <= qs[i].r; it++) {           auto it2 = it;           it2++;           int r = it2 != mp.end() ? min(it2->first, qs[i].r + 1) : qs[i].r + 1;           smp[it->second] += r - it->first;         }         for (auto it = smp.begin(); it != smp.end(); it++) {           if (it->second >= qs[i].x) {             printf( %lld n , it->first);             break;           }           qs[i].x -= it->second;         }       } else {         int r = mp.lower_bound(qs[i].l) != mp.end()                     ? min(qs[i].r + 1, mp.lower_bound(qs[i].l)->first)                     : qs[i].r + 1;         long long sum = (pow(get_num(mp, qs[i].l), qs[i].x, qs[i].y) *                          ((r - qs[i].l) % qs[i].y)) %                         qs[i].y;         for (auto it = mp.lower_bound(qs[i].l);              it != mp.end() && it->first <= qs[i].r; it++) {           auto it2 = it;           it2++;           int r = it2 != mp.end() ? min(it2->first, qs[i].r + 1) : qs[i].r + 1;           sum = (sum + (pow(it->second, qs[i].x, qs[i].y) * (r - it->first)) %                            qs[i].y) %                 qs[i].y;         }         printf( %lld n , sum % qs[i].y);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long leader[110000], p[110000];   long long n, m, i, j, k;   bool can(long long cost) {     for (i = 0, j = 0; i < n && j < m; ++i) {       long long summ = cost;       if (leader[i] == p[j] && j < m) ++j;       if (j >= m) break;       summ -= abs(leader[i] - p[j]);       long long temp = leader[i] - p[j];       if (summ < 0) continue;       if (temp > 0) {         int t = j;         while (p[j] <= leader[i] && j < m) ++j;         while (cost >= p[j] - p[t] + min(p[j] - leader[i], leader[i] - p[t]) &&                j < m)           ++j;         if (j >= m) break;       } else {         while (p[j] <= leader[i] + cost && j < m) ++j;         if (j >= m) break;       }     }     if (j >= m)       return 1;     else       return 0;   }   int main() {     long long cost = 0;     scanf( %I64d%I64d , &n, &m);     for (i = 0; i < n; ++i) scanf( %I64d , &leader[i]);     for (i = 0; i < m; ++i) scanf( %I64d , &p[i]);     i = 0, j = 0;     long long l = -1, r = max(p[m - 1] * 2, leader[n - 1] * 2);     if (n != 1)       while (r - l > 1) {         long long mid = l + (r - l) / 2;         if (can(mid))           r = mid;         else           l = mid;       }     if (n != 1)       printf( %I64d , r);     else {       if (leader[0] < p[0])         printf( %I64d , p[m - 1] - leader[0]);       else if (leader[0] > p[m - 1])         printf( %I64d , leader[0] - p[0]);       else {         printf( %I64d ,                p[m - 1] - p[0] + min(leader[0] - p[0], p[m - 1] - leader[0]));       }     }     return 0;   }


#include <iostream>   using namespace std;   int main()   {       ios::sync_with_stdio(0);       int t; cin >> t;       while(t--)       {           int x,y;           cin >> x >> y;           cout << 2*max(x,y) - (min(x,y) != max(x,y)) <<   n ;       }       return 0;   }


#include <bits/stdc++.h>   using namespace std;   int mod = (int)1e9 + 7;   template <typename Arg1>   void __f(const char* name, Arg1&& arg1) {     cout << name <<   :   << arg1 <<   n ;   }   template <typename Arg1, typename... Args>   void __f(const char* names, Arg1&& arg1, Args&&... args) {     const char* comma = strchr(names + 1,  , );     cout.write(names, comma - names) <<   :   << arg1 <<   |  ;     __f(comma + 1, args...);   }   void solve() {     int n;     cin >> n;     if (n % 2 == 0) {       cout <<  -1 n ;       return;     }     for (int i = 0; i < n; i++) {       cout << i <<    ;     }     cout <<   n ;     for (int i = 0; i < n; i++) {       cout << (i + 1) % n <<    ;     }     cout <<   n ;     for (int i = 0; i < n; i++) {       cout << (i + i + 1) % n <<    ;     }   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     solve();   }


#include <bits/stdc++.h>   using namespace std;   void build(int ss, int se, int si);   long long query(int ss, int se, int si, int qs, int qe);   set<pair<long long, int> > s;   set<pair<long long, int> >::iterator it, last;   long long A[100001], st[400005], dp[100001];   int main(void) {     int i, n, c;     long long sum, ans = 0, min_i;     cin >> n >> c;     if (c == 1) {       cout << 0 << endl;       return 0;     }     for (i = 0; i < n; i++) {       cin >> A[i];       ans = ans + A[i];     }     build(0, n - 1, 0);     for (i = c - 1; i < n; i++)       dp[i] = max(dp[i - 1], ((i - c >= 0) ? dp[i - c] : 0) +                                  query(0, n - 1, 0, i - c + 1, i));     cout << ans - dp[n - 1] << endl;   }   void build(int ss, int se, int si) {     if (ss == se) {       st[si] = A[ss];       return;     }     int mid = (ss + se) / 2;     build(ss, mid, 2 * si + 1);     build(mid + 1, se, 2 * si + 2);     st[si] = min(st[2 * si + 1], st[2 * si + 2]);   }   long long query(int ss, int se, int si, int qs, int qe) {     if (ss >= qs && se <= qe) return st[si];     if (ss > qe || se < qs) return INT_MAX;     int mid = (ss + se) / 2;     return min(query(ss, mid, 2 * si + 1, qs, qe),                query(mid + 1, se, 2 * si + 2, qs, qe));   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int i, N, bitl, bitr;     long long l, r;     scanf( %d , &N);     while (N--) {       scanf( %lld%lld , &l, &r);       bitl = bitr = 0;       if (l == r) {         printf( %lld n , l);         continue;       }       while ((1LL << bitl) <= l) ++bitl;       while ((1LL << bitr) <= r) ++bitr;       --bitl;       --bitr;       if (bitl < bitr) {         if ((1LL << (bitr + 1)) - 1 == r)           printf( %lld n , r);         else           printf( %lld n , (1LL << bitr) - 1);         continue;       }       for (i = bitr; i >= 0; --i) {         if (((l >> i) % 2) != ((r >> i) % 2)) break;       }       if ((((1LL << (i + 1)) - 1) & r) == (1LL << (i + 1)) - 1)         printf( %lld n , r);       else {         r |= (1LL << i) - 1;         r &= ~(1LL << i);         printf( %lld n , r);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void cmax(long long int &a, long long int b) {     if (a < b) a = b;   }   const int mod = 1000000007;   bool comp(int x, int y) { return x > y; }   void printarr(int arr[], int n) {     for (int i = 0; i < n; ++i) std::cout << arr[i] << (i < n - 1 ?     :   n );   }   template <typename T>   void printv(T &a) {     for (auto it = a.begin(); it != a.end(); ++it) std::cerr << *it <<    ;     std::cerr <<   n ;   }   int gint() {     int n;     cin >> n;     return n;   }   const int maxn = 200009;   long long int ans;   int arr[maxn];   void solve() {     ans = 0;     bool ok = false;     int m = gint();     int n = gint();     long long int sum = 0;     for (int i = 0; i < n; ++i) {       arr[i] = i + 1;       sum += arr[i];       if (sum > m) ok = 1;     }     if (!ok) {       for (int i = 0; i < n; ++i) {         arr[i] += (m - sum) / n;       }       int res = (m - sum) % n;       for (int i = n - 2; i >= 0; --i) {         int temp;         arr[i + 1] += temp = min(arr[i] * 2 - arr[i + 1], res);         res -= temp;       }       sum = arr[0];       for (int i = 1; !ok && i < n; ++i) {         ok = (arr[i] > arr[i - 1] * 2);         sum += arr[i];       }       ok = !(sum == m);     }     std::cout << (!ok ?  YES  :  NO );     std::cout <<   n ;     if (!ok) printarr(arr, n);     std::cout <<   n ;   }   void sol() {}   int main() {     std::ios_base::sync_with_stdio(false);     std::cin.tie(nullptr);     int testcases = 1;     for (int t = 0; t < testcases; ++t) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long inf = 4e18;   const long long N = 2e5 + 10;   void testCase() {     long long n;     cin >> n;     long long a[n + 1];     for (long long i = 1; i <= n; i++) cin >> a[i];     vector<long long> sma(n + 2), suf(n + 2);     for (long long i = n; i >= 1; i--) {       sma[i] = max(a[i], sma[i + 1] + 1);       suf[i] = suf[i + 1] + sma[i] - a[i];     }     long long ans = inf;     long long pma = 0, pref = 0;     for (long long i = 1; i <= n; i++) {       pma = max(pma + 1, a[i]);       long long cur = pref + suf[i + 1] + max(pma, sma[i]) - a[i];       ans = min(ans, cur);       pref += pma - a[i];     }     cout << ans;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr), cout.tie(nullptr);     long long t_c = 1;     while (t_c--) testCase();   }


#include <bits/stdc++.h>   using namespace std;   int const N = 200001;   int main() {     int t;     scanf( %d , &t);     while (t--) {       int n;       string s, t;       scanf( %d , &n);       cin >> s >> t;       set<int> msA[200], msB[200];       map<char, int> f;       for (int i = 0; i < n; ++i) {         msA[s[i]].insert(i);         msB[t[i]].insert(i);         ++f[s[i]], ++f[t[i]];       }       bool ok = true;       for (char i =  a ; i <=  z ; ++i)         if (f[i] & 1) {           ok = false;           break;         }       vector<pair<int, int> > an;       if (!ok) {         puts( NO );         continue;       }       for (int i = 0; i < n; ++i) {         if (s[i] == t[i]) continue;         int sp = -1;         for (int j = i + 1; j < n; ++j) {           if (s[j] == s[i]) sp = j;           if (s[j] != t[j] && s[j] == s[i]) {             sp = j;             break;           }         }         if (~sp) {           an.push_back({sp, i});           swap(s[sp], t[i]);           continue;         }         for (int j = i + 1; j < n; ++j) {           if (t[j] == s[i]) sp = j;           if (s[j] != t[j] && t[j] == s[i]) {             sp = j;             break;           }         }         if (~sp) {           an.push_back({sp, sp});           swap(s[sp], t[sp]);           an.push_back({sp, i});           swap(s[sp], t[i]);           continue;         }         break;       }       if (s != t || an.size() > 2 * n)         puts( NO );       else {         printf( YES n%d n , an.size());         for (auto i : an) printf( %d %d n , i.first + 1, i.second + 1);       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int n = 5000;   const long long mod = 998244353;   long long f[n + 10][n + 10];   int main() {     int a, b, c;     for (int i = 1; i < n + 10; i++) {       for (int j = 1; j < n + 10; j++) {         if (i == 1)           f[i][j] = j + 1;         else if (j < i)           f[i][j] = f[j][i];         else {           (f[i][j] += j * f[i - 1][j - 1] % mod) %= mod;           (f[i][j] += f[i - 1][j]) %= mod;         }       }     }     while (scanf( %d%d%d , &a, &b, &c) != EOF) {       long long ans = ((f[a][b] * f[b][c]) % mod) * f[c][a] % mod;       printf( %lld n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1000055;   const int inf = 0x3f3f3f3f;   const double pi = acos(-1.0);   const int mod = 1e9 + 7;   long long pow_mod(long long a, long long b) {     long long ans = 1 % mod;     for (; b; b >>= 1) {       if (b & 1) ans = (long long)ans * a % mod;       a = (long long)a * a % mod;     }     return ans;   }   long long x, n;   long long p[MAXN], c[MAXN];   int cnt;   void divide(long long n) {     cnt = 0;     int lim = sqrt(n);     for (int i = 2; i <= lim; ++i) {       if (n % i == 0) {         p[++cnt] = i, c[cnt] = 0;         while (n % i == 0) n /= i, c[cnt]++;       }     }     if (n > 1) p[++cnt] = n, c[cnt] = 1;   }   int main() {     cin >> x >> n;     divide(x);     long long ans = 1;     for (int i = 1; i <= cnt; ++i) {       long long k = 1, tmp = 0;       while ((long long)(n / (long long)pow(p[i], k))) {         tmp += (long long)(n / (long long)pow(p[i], k));         k++;       }       ans = ans * pow_mod(p[i], tmp) % mod;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   void chmin(T &x, const T &y) {     if (x > y) x = y;   }   template <typename T>   void chmax(T &x, const T &y) {     if (x < y) x = y;   }   int read() {     char c;     while ((c = getchar()) <  - )       ;     if (c ==  - ) {       int x = (c = getchar()) -  0 ;       while ((c = getchar()) >=  0 ) x = x * 10 + c -  0 ;       return -x;     }     int x = c -  0 ;     while ((c = getchar()) >=  0 ) x = x * 10 + c -  0 ;     return x;   }   const int N = 2e5 + 5, D = 998244353;   int64_t mi(int64_t x, int y = D - 2) {     int64_t ans = 1;     while (y) {       if (y & 1) ans = ans * x % D;       x = x * x % D;       y >>= 1;     }     return ans;   }   void operator+=(pair<int64_t, int64_t> &a, const pair<int64_t, int64_t> &b) {     (a.first += b.first) %= D;     (a.second += b.second) %= D;   }   void mul(int64_t &a0, int64_t &a1, int64_t m[2][2]) {     int64_t b0 = (m[0][0] * a0 + m[0][1] * a1) % D,             b1 = (m[1][0] * a0 + m[1][1] * a1) % D;     a0 = b0;     a1 = b1;   }   int64_t m[2][2], m1[2][2];   namespace SEG {   const int64_t T = N * 4;   int64_t tag[T][2][2], sum[T][2];   int n;   void mul(int k, int64_t m[2][2]) {     for (int i = 0; i <= 1; ++i) {       ::mul(tag[k][0][i], tag[k][1][i], m);     }     ::mul(sum[k][0], sum[k][1], m);   }   void push_down(int k) {     if ((tag[k][0][0] - 1) % D || tag[k][0][1] || tag[k][1][0] ||         (tag[k][1][1] - 1) % D) {       mul((k * 2), tag[k]);       mul(((k * 2) + 1), tag[k]);       for (int i = 0; i <= 1; ++i)         for (int j = 0; j <= 1; ++j) tag[k][i][j] = i == j;     }   }   void push_up(int k) {     for (int i = 0; i <= 1; ++i)       sum[k][i] = (sum[(k * 2)][i] + sum[((k * 2) + 1)][i]) % D;   }   void add(int x, const pair<int64_t, int64_t> &a) {     int k = 1, l = 1, r = n;     while (1) {       (sum[k][0] += a.first) %= D;       (sum[k][1] += a.second) %= D;       if (l == r) break;       push_down(k);       if (x <= ((l + r) / 2)) {         k = (k * 2);         r = ((l + r) / 2);       } else {         k = ((k * 2) + 1);         l = ((l + r) / 2) + 1;       }     }   }   pair<int64_t, int64_t> query(int x) {     int k = 1, l = 1, r = n;     pair<int64_t, int64_t> ans = pair<int64_t, int64_t>(0, 0);     while (l != r) {       push_down(k);       if (x <= ((l + r) / 2)) {         ans +=             pair<int64_t, int64_t>(sum[((k * 2) + 1)][0], sum[((k * 2) + 1)][1]);         k = (k * 2);         r = ((l + r) / 2);       } else {         k = ((k * 2) + 1);         l = ((l + r) / 2) + 1;       }     }     ans += pair<int64_t, int64_t>(sum[k][0], sum[k][1]);     return ans;   }   int ql, qr;   void modify(int k, int l, int r) {     if (ql > r || qr < l) return;     if (ql <= l && qr >= r) {       mul(k, m);       return;     }     push_down(k);     modify((k * 2), l, ((l + r) / 2));     modify(((k * 2) + 1), ((l + r) / 2) + 1, r);     push_up(k);   }   void modify(int l, int r) {     ql = l;     qr = r;     modify(1, 1, n);   }   };  // namespace SEG   bool cmp(const pair<int, int> &a, const pair<int, int> &b) {     return 1LL * a.first * b.second < 1LL * a.second * b.first;   }   pair<int, int> q[N];   int t;   int main() {     int n = read();     static int x[N], v[N], p[N];     for (int i = 1; i <= n; ++i) {       x[i] = read();       v[i] = read();       p[i] = read() * mi(100) % D;     }     t = 1;     q[1] = pair<int, int>(1, 0);     for (int i = 2; i <= n; ++i) {       q[++t] = pair<int, int>(x[i] - x[i - 1], v[i] + v[i - 1]);       if (v[i] != v[i - 1])         q[++t] = pair<int, int>(x[i] - x[i - 1], abs(v[i] - v[i - 1]));     }     sort(q + 1, q + t + 1, cmp);     SEG::n = t;     SEG::add(t, pair<int64_t, int64_t>(1 - p[1], p[1]));     for (int i = 2; i <= n; ++i) {       int j0 =           lower_bound(q + 1, q + t,                       pair<int, int>(x[i] - x[i - 1], v[i] + v[i - 1]), cmp) -           q;       int j1 = lower_bound(q + 1, q + t,                            pair<int, int>(x[i] - x[i - 1], abs(v[i] - v[i - 1])),                            cmp) -                q;       pair<int64_t, int64_t> s0 = SEG::query(j0), s1 = SEG::query(j1);       int64_t np = p[i];       for (int i = 0; i <= 1; ++i)         for (int j = 0; j <= 1; ++j) m[i][j] = (i == 0) ? 1 - np : np;       SEG::modify(1, j0 - 1);       for (int i = 0; i <= 1; ++i)         for (int j = 0; j <= 1; ++j)           if (j == 1 && i == 0) {             m1[i][j] = m[i][j];             m[i][j] = 0;           } else             m1[i][j] = 0;       mul(s0.first, s0.second, m1);       SEG::modify(j0, j1 - 1);       SEG::add(j0, s0);       int ni = v[i] > v[i - 1] ? 0 : 1;       for (int i = 0; i <= 1; ++i)         for (int j = 0; j <= 1; ++j)           if (i == j && (i == ni)) {             m1[i][j] = m[i][j];             m[i][j] = 0;           } else             m1[i][j] = 0;       mul(s1.first, s1.second, m1);       SEG::modify(j1, t);       SEG::add(j1, s1);     }     auto S = [&](const pair<int64_t, int64_t> &a) -> int64_t {       return (a.first + a.second) % D;     };     int64_t ans = 0;     for (int i = 1; i <= t - 1; ++i)       (ans += (S(SEG::query(i)) - S(SEG::query(i + 1))) * q[i].first % D *               mi(q[i].second)) %= D;     cout << (ans + D) % D << endl;   }


#include <bits/stdc++.h>   using namespace std;   const double EPS = 1e-8;   const long long SZ = 1010, SSZ = 100010, APB = 26, one = 93,                   INF = 0x3f3f3f3f3f3f3f3f, mod = 1000000007;   long long n, m, bg, fn, cnt;   long long to[SSZ], wt[SSZ], head[SZ];   long long nex[SSZ], mk[SSZ];   long long dfn[SZ], low[SZ], tot;   bool vst[SZ];   void add(long long u, long long v, long long w) {     ++cnt;     nex[cnt] = head[u];     head[u] = cnt;     to[cnt] = v, wt[cnt] = w;   }   bool dfs(long long x) {     vst[x] = 1;     if (x == fn) return 1;     for (long long i = head[x]; i != -1; i = nex[i]) {       long long t = to[i];       if (!vst[t]) {         mk[i] = 1;         if (dfs(t)) return 1;         mk[i] = 0;       }     }     return 0;   }   stack<long long> stk;   void tar(long long x, long long p, long long &res2, long long &eg2) {     dfn[x] = low[x] = ++tot;     vst[x] = 1;     for (long long i = head[x]; i != -1; i = nex[i]) {       if (i != (p ^ 1) && mk[i] != 2 && mk[i ^ 1] != 2) {         long long t = to[i], w = wt[i];         if (!dfn[t]) {           tar(t, i, res2, eg2);           low[x] = min(low[x], low[t]);         } else           low[x] = min(low[x], low[t]);         if (dfn[x] < low[t] && dfn[fn] >= dfn[t]) {           if (w < res2) {             res2 = w, eg2 = i;           }         }       }     }   }   void init() {     cin >> n >> m >> bg >> fn;     cnt = -1;     memset(head, -1, sizeof(head));     for (long long i = 1; i <= m; ++i) {       long long a, b, c;       cin >> a >> b >> c;       add(a, b, c);       add(b, a, c);     }     dfs(bg);     if (vst[fn] == 0) {       cout << 0 << endl << 0;       return;     }     long long res = INF, vt1 = -1, vt2;     for (long long i = 0; i <= cnt; ++i) {       if (mk[i]) {         mk[i] = 2;         memset(vst, 0, sizeof(vst));         tot = 0;         memset(dfn, 0, sizeof(dfn));         memset(low, 0, sizeof(low));         long long res1 = wt[i], res2 = INF, eg1 = i, eg2;         tar(bg, -1, res2, eg2);         if (!vst[fn]) res2 = 0, eg2 = -5;         if (res1 + res2 < res) {           res = res1 + res2;           vt1 = eg1 / 2 + 1, vt2 = eg2 / 2 + 1;         }         mk[i] = 1;       }     }     if (vt1 == -1) {       cout << -1 << endl;       return;     }     cout << res << endl;     cout << (vt2 == -1 ? 1 : 2) << endl;     cout << vt1 <<    ;     if (vt2 != -1) cout << vt2 << endl;   }   void work() {}   int main() {     std::ios::sync_with_stdio(0);     long long casenum;     {       init();       work();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     int x;     cin >> x;     vector<int> first(x);     vector<int> second(x);     int sum_f = 0;     for (int i = 0; i < x; i++) {       cin >> first[i];       sum_f += first[i];     }     int sum_s = 0;     for (int i = 0; i < x; i++) {       cin >> second[i];       sum_s += second[i];     }     if (sum_s > sum_f) {       cout <<  No ;     } else       cout <<  Yes ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int tavan(int a, int n, int mod) {     int res = 1;     while (n) res *= (n & 1) ? a : 1, res %= mod, n /= 2, a *= a, a %= mod;     return res;   }   const int MOD = ((int)81671);   const int N = ((int)40);   const int M = ((int)12);   const int X = ((int)2e6);   int n, m, p[M];   string s[M], now;   bool mark[X];   vector<string> v;   void solve(int pos, int x) {     if (x < 0) return;     if (pos == (int)s[0].size() && x != 0) return;     if (x == 0) {       for (int i = pos; i < s[0].size(); i++)         now[i] = (s[0][i] ==  0 ) ?  1  :  0 ;       v.push_back(now);       return;     }     now[pos] = s[0][pos];     solve(pos + 1, x - 1);     now[pos] = (s[0][pos] ==  0 ) ?  1  :  0 ;     solve(pos + 1, x);     now[pos] = s[0][pos];   }   int main() {     cin >> n >> m >> s[0] >> p[0];     now = s[0];     solve(0, p[0]);     int ans = v.size();     for (int i = 1; i < m; i++) {       cin >> s[i] >> p[i];       for (int j = 0; j < v.size(); j++)         if (!mark[j]) {           int num = 0;           for (int k = 0; k < v[j].size(); k++)             if (v[j][k] == s[i][k]) num++;           if (num != p[i]) mark[j] = 1, ans--;         }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   int main() {     int T, t1 = 0, t2, maxn = 0, flag = 1, sum = 0, sum1 = 0;     scanf( %d , &T);     while (T--) {       scanf( %d , &t2);       if (flag && t2 == 0) {         maxn = max(maxn, sum);         sum1 = sum;         sum = 0;         flag = 0;         continue;       }       if (t2 == 0) {         maxn = max(maxn, sum);         sum = 0;         continue;       }       sum++;       if (T == 0) {         maxn = max(sum + sum1, maxn);       }     }     printf( %d n , maxn);   }


#include <bits/stdc++.h>   using namespace std;   int n, k, a[(int)2e5];   long long sum;   double d, res;   int main() {     cin >> n >> k;     for (int i = 0; i < n; ++i) {       cin >> a[i];       if (i < k) sum += a[i];     }     d = n - k + 1;     res += sum / d;     for (int i = k; i < n; ++i) {       sum -= a[i - k];       sum += a[i];       res += sum / d;     }     cout << fixed << setprecision(6) << res;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     int a = 0;     for (int i = 0; i < s.size(); i++) {       if (s[i] ==  a ) a++;     }     for (int i = s.size(); i >= a; i--) {       if (a > (i / 2)) {         cout << i << endl;         exit(0);       }     }   }


#include <bits/stdc++.h>   using namespace std;   int ABS(int a) {     if (a < 0) return (-a);     return a;   }   vector<int> v[50005];   int main() {     int n, r1, r2, i;     scanf( %d , &n);     scanf( %d , &r1);     scanf( %d , &r2);     for (i = (1); i < (n + 1); ++i) {       if (r1 == i) continue;       int x;       scanf( %d , &x);       v[x].push_back(i);       v[i].push_back(x);     }     int parent[50005] = {0};     bool vis[50005] = {0};     queue<int> q;     q.push(r2);     parent[r2] = -1;     vis[r2] = 1;     while (!q.empty()) {       int x = q.front();       q.pop();       for (i = (0); i < (v[x].size()); ++i) {         int next = v[x][i];         if (!vis[next]) {           q.push(next);           parent[next] = x;           vis[next] = 1;         }       }     }     for (i = (1); i < (n + 1); ++i) {       if (i == r2) continue;       printf( %d  , parent[i]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   function<void(void)> ____ = []() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);   };   const int MAXN = 555;   int n, m, match[MAXN];   bool mp[MAXN][MAXN], vis[MAXN];   vector<int> G[MAXN];   bool dfs(int u, int c) {     vis[u] = true;     for (int v : G[u]) {       if (v == c) continue;       if (match[v] == -1 or (!vis[match[v]] and dfs(match[v], c))) {         match[v] = u;         return true;       }     }     return false;   }   int hungary(int c) {     memset(match, 255, sizeof(match));     int mt = 0;     for (int i = 1; i <= n; i++) {       if (i == c) continue;       memset(vis, 0, sizeof(vis));       if (dfs(i, c)) mt++;     }     return mt;   }   int main() {     ____();     cin >> n >> m;     for (int i = 1; i <= m; i++) {       int u, v;       cin >> u >> v;       G[u].push_back(v);       mp[u][v] = true;     }     int ret = MAXN * MAXN * MAXN;     for (int i = 1; i <= n; i++) {       int centeredge = 0;       for (int j = 1; j <= n; j++) {         if (i == j and mp[i][j])           centeredge++;         else if (i != j) {           if (mp[i][j]) centeredge++;           if (mp[j][i]) centeredge++;         }       }       int mt = hungary(i);       ret = min(ret, 3 * n + m - 2 - 2 * centeredge - 2 * mt);     }     cout << ret << endl;     return 0;   }


#include <bits/stdc++.h>   const int maxn = 1e6 + 10;   using namespace std;   int pre[maxn];   int main() {     string a, b;     cin >> a;     cin >> b;     int LA = a.size();     int LB = b.size();     int flag = 0, ans = 0;     for (int i = 0; i < LB; i++) {       if (b[i] ==  1 ) flag++;     }     flag %= 2;     if (a[0] ==  1 ) pre[1] = 1;     for (int i = 1; i < LA; i++) {       if (a[i] ==  1 )         pre[i + 1] = pre[i] + 1;       else         pre[i + 1] = pre[i];     }     int T = LA - LB;     for (int i = 0; i <= T; i++) {       if ((pre[i + LB] - pre[i]) % 2 == flag) {         ans++;       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, a, b, sum = 0, sum1 = 0;     cin >> n >> m >> a >> b;     sum = n / m;     sum1 = n - (sum * m);     if (sum * b < n * a) {       cout << min((sum * b + sum1 * a), ((sum + 1) * b));     }     if (sum * b >= n * a) {       cout << n * a;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 5e5 + 5;   unordered_map<long long, long long> m1, mp;   long long m, k, n, s;   bool check() {     for (auto it : mp) {       if (it.second > m1[it.first]) return false;     }     return true;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t = 1;     while (t--) {       cin >> m >> k >> n >> s;       long long a[m];       long long i, j;       for (int i = 0; i <= m - 1; i++) {         cin >> a[i];       }       long long b[s];       for (int i = 0; i <= s - 1; i++) {         cin >> b[i];         mp[b[i]]++;       }       long long del = m - n * k;       long long req = del + k;       for (i = 0; i < m; i += k) {         m1.clear();         for (j = i; j < min(m, i + req); j++) {           m1[a[j]]++;         }         if (check()) {           cout << del <<   n ;           for (j = i; j < min(i + req, m); j++) {             if (del > 0 && m1[a[j]] > mp[a[j]]) {               cout << j + 1 <<    ;               del--;               m1[a[j]]--;             }           }           return 0;         }       }       cout << -1 <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, s, a[100005], p, w[100005], ans;   multiset<long long> st;   int main() {     cin >> n >> s;     for (int k = 1; k <= n; k++) cin >> a[k];     cin >> p;     for (int k = 1; k <= n; k++) cin >> w[k];     for (int k = 1; k <= n; k++) {       st.insert(w[k]);       while (s < a[k]) {         if (st.size() == 0) {           cout << -1;           return 0;         }         ans += *st.begin();         st.erase(st.begin());         s += p;       }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int limite = 1000000;   int n;   long long int a[limite];   long long int suma[limite];   map<long long int, int> cuantos;   int main() {     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a[i];       a[i + n] = a[i];     }     for (int i = 1; i <= 2 * n; i++) suma[i] = suma[i - 1] + a[i];     for (int i = 1; i <= n; i++) cuantos[suma[i]]++;     int sol = n;     for (int i = 1; i <= n; i++) {       sol = min(sol, n - cuantos[suma[i - 1]]);       cuantos[suma[i]]--;       cuantos[suma[i + n]]++;     }     cout << sol << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main(int argc, char* argv[]) {     int n, m, k;     vector<double> r1, p1, p2;     cin >> n;     while (n--) {       int hlp;       cin >> hlp;       r1.push_back(hlp);     }     cin >> m;     while (m--) {       int hlp;       cin >> hlp;       p1.push_back(hlp);     }     cin >> k;     while (k--) {       int hlp;       cin >> hlp;       p2.push_back(hlp);     }     double A, B;     cin >> A >> B;     double maxr2 = 0;     sort(r1.begin(), r1.end());     sort(p1.begin(), p1.end());     sort(p2.begin(), p2.end());     {       maxr2 = r1[r1.size() - 1] * sqrt(p1[p1.size() - 1] / p2[0] /                                        (A / B + p1[p1.size() - 1] / p2[0]));     }     char buf[256];     cout << gcvt(maxr2, 50, buf);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1000000;   const int INF = 1000000001;   vector<int> G[MAXN + 1];   bool vis[MAXN + 1];   vector<int> CC;   int n, m, k;   int dfs(int v) {     vis[v] = true;     int ret = 1;     for (__typeof((G[v]).begin()) u = (G[v]).begin(); u != (G[v]).end(); ++u)       if (!vis[*u]) ret += dfs(*u);     return ret;   }   int main(int argc, char *argv[]) {     scanf( %d %d %d , &n, &m, &k);     while (m--) {       int a, b;       scanf( %d %d , &a, &b);       G[a].push_back(b);       G[b].push_back(a);     }     int t = 0;     int s = 0;     for (int i = 1; i <= n; ++i)       if (!vis[i])         CC.push_back(min(k, dfs(i))), t += CC.back() == 1 ? 0 : CC.back(),             s += CC.back() != 1;     t = t - 2 * s + 2;     if (k == 1)       printf( %d n , max(0, (int)CC.size() - 2));     else       printf( %d n , (max(0, ((int)CC.size() - s) - t + 1)) / 2);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int a, b, x, y, n, ans, t;     cin >> t;     while (t--) {       ans = LLONG_MAX;       cin >> a >> b >> x >> y >> n;       if (n >= (a - x + b - y))         cout << x * y <<   n ;       else {         if ((a - n) >= x)           ans = (a - n) * b;         else {           if (b - (x - a + n) >= y) ans = min(ans, x * (b - (x - a + n)));         }         if ((b - n) >= y)           ans = min(ans, (b - n) * a);         else {           if (a - (y - b + n) >= x) ans = min(ans, y * (a - (y - b + n)));         }         cout << ans <<   n ;       }     }   }


#include <bits/stdc++.h>   int main() {     long long int a, b = 1, i;     scanf( %I64d , &a);     for (i = 1; i <= a; i++) {       b += 12 * (1 + i - 2);     }     if (a == 1)       printf( 1 );     else       printf( %I64d , b);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   pair<long long int, long long int> rec(long long int n) {     long long int mini = 1e18, maxi = -1;     while (n) {       mini = min(mini, n % 10);       maxi = max(maxi, n % 10);       n /= 10;     }     return {mini, maxi};   }   int main() {     long long int t;     cin >> t;     while (t--) {       long long int n, k;       cin >> n >> k;       k--;       while (k--) {         pair<long long int, long long int> x = rec(n);         if (x.first == 0) break;         n += (x.first * x.second);       }       cout << n << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int const maxn = 1e6 + 5;   int a[maxn], b[maxn];   pair<int, int> c[maxn];   int all_elem[2 * maxn];   int cur, inf = 1e9 + 7;   int f[2 * maxn];   int psh[8 * maxn];   pair<int, int> imin[4 * maxn];   inline pair<int, int> unions(pair<int, int> c, pair<int, int> d) {     if (c.first < d.first || (c.first == d.first && c.second > d.second))       return c;     return d;   }   void build(int i, int l, int r) {     psh[i] = 0;     if (r - l == 1)       imin[i] = {0, l};     else {       int m = (r + l) / 2;       build(2 * i + 1, l, m);       build(2 * i + 2, m, r);       imin[i] = unions(imin[2 * i + 1], imin[2 * i + 2]);     }   }   inline void push(int i) {     imin[i].first += psh[i];     psh[2 * i + 1] += psh[i];     psh[2 * i + 2] += psh[i];     psh[i] = 0;   }   void adds(int i, int l, int r, int lq, int rq, int x) {     push(i);     if (lq >= r || l >= rq) return;     if (lq <= l && r <= rq) {       psh[i] += x;       push(i);       return;     }     int m = (r + l) / 2;     adds(2 * i + 1, l, m, lq, rq, x);     adds(2 * i + 2, m, r, lq, rq, x);     imin[i] = unions(imin[2 * i + 1], imin[2 * i + 2]);   }   pair<int, int> get(int i, int l, int r, int lq, int rq) {     push(i);     if (lq >= r || l >= rq) return {inf, inf};     if (lq <= l && r <= rq) return imin[i];     int m = (r + l) / 2;     return unions(get(2 * i + 1, l, m, lq, rq), get(2 * i + 2, m, r, lq, rq));   }   inline void add(int i) {     while (i <= cur) {       f[i]++;       i = (i | (i + 1));     }   }   inline int get(int i) {     int ans = 0;     while (i > 0) {       ans += f[i];       i = (i & (i + 1)) - 1;     }     return ans;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     while (t--) {       int n, m;       cur = 0;       cin >> n >> m;       build(0, 0, n + 1);       for (int i = 1; i <= n; ++i) cin >> a[i];       for (int i = 1; i <= m; ++i) cin >> b[i];       sort(b + 1, b + m + 1);       for (int i = 1; i <= n; ++i) {         all_elem[++cur] = a[i];       }       for (int i = 1; i <= m; ++i) {         all_elem[++cur] = b[i];       }       sort(all_elem + 1, all_elem + cur + 1);       for (int i = 1; i <= n; ++i) {         a[i] = lower_bound(all_elem + 1, all_elem + cur + 1, a[i]) - all_elem;       }       for (int i = 1; i <= m; ++i) {         b[i] = lower_bound(all_elem + 1, all_elem + cur + 1, b[i]) - all_elem;       }       long long ans = 0;       for (int i = 0; i <= cur; ++i) f[i] = 0;       for (int i = n; i >= 1; --i) {         ans += get(a[i]);         add(a[i] + 1);       }       for (int i = 1; i <= n; ++i) c[i] = {a[i], i};       sort(c + 1, c + n + 1);       int pos = n;       for (int i = 1; i <= n; ++i) {         adds(0, 0, n + 1, 0, i, 1);       }       int lptr = n, rptr = n;       for (int i = m; i >= 1; --i) {         if (b[i] != b[i + 1]) {           while (rptr > lptr) {             adds(0, 0, n + 1, c[rptr].second, n + 1, 1);             rptr--;           }         }         while (rptr > 0 && b[i] < c[rptr].first) {           adds(0, 0, n + 1, 0, c[rptr].second, -1);           adds(0, 0, n + 1, c[rptr].second, n + 1, 1);           rptr--;         }         lptr = min(lptr, rptr);         while (lptr > 0 && b[i] == c[lptr].first) {           adds(0, 0, n + 1, 0, c[lptr].second, -1);           lptr--;         }         pair<int, int> best = get(0, 0, n + 1, 0, pos + 1);         ans += best.first;         pos = best.second;       }       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   int n, m, same;   string s;   int main() {     cin >> n >> m >> s;     long long ans = 1LL * n * (m - 1);     for (int i = 1; i < n; i++) {       if (s[i] == s[i - 2]) {         same++;       } else {         same = 0;       }       if (s[i] != s[i - 1]) {         ans += 1LL * n * (m - 1) - same - 1;       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   int main() {     int i, m, j;     char a[1000], b[1000];     scanf( %s %s , &a, &b);     if (strlen(a) != strlen(b)) {       printf( NO );       return 0;     }     j = strlen(b) - 1;     for (i = 0; i < strlen(a); i++) {       if (a[i] != b[j]) {         printf( NO );         return 0;       }       j--;     }     printf( YES );   }


#include <bits/stdc++.h>   using namespace std;   const long long MAX = 105;   const long long MAXV = 2e5 + 1;   const long long INF = 1e9;   bool prime[MAXV];   void sieve() {     memset(prime, true, sizeof(prime));     prime[0] = prime[1] = false;     for (long long i = 2; i * i < MAXV; i++) {       if (prime[i]) {         for (long long j = i * i; j < MAXV; j += i) prime[j] = false;       }     }   }   long long n, k, p[MAX], c[MAX], l[MAX];   struct edge {     int from, to, flow, index;     long long cap;     edge(int from, int to, long long cap, int flow, int index)         : from(from), to(to), cap(cap), flow(flow), index(index) {}   };   struct PushRelabel {     int n;     vector<vector<edge>> g;     vector<long long> excess;     vector<int> height, active, count;     queue<int> Q;     PushRelabel(int n)         : n(n), g(n), excess(n), height(n), active(n), count(2 * n) {}     void addEdge(int from, int to, long long cap) {       g[from].push_back(edge(from, to, cap, 0, g[to].size()));       if (from == to) g[from].back().index++;       g[to].push_back(edge(to, from, 0, 0, g[from].size() - 1));     }     void enqueue(int v) {       if (!active[v] && excess[v] > 0) {         active[v] = true;         Q.push(v);       }     }     void push(edge &e) {       int amt = (int)min(excess[e.from], (long long)e.cap - e.flow);       if (height[e.from] <= height[e.to] || amt == 0) return;       e.flow += amt;       g[e.to][e.index].flow -= amt;       excess[e.to] += amt;       excess[e.from] -= amt;       enqueue(e.to);     }     void relabel(int v) {       count[height[v]]--;       int d = 2 * n;       for (auto &it : g[v]) {         if (it.cap - it.flow > 0) d = min(d, height[it.to] + 1);       }       height[v] = d;       count[height[v]]++;       enqueue(v);     }     void gap(int k) {       for (int v = 0; v < n; v++) {         if (height[v] < k) continue;         count[height[v]]--;         height[v] = max(height[v], n + 1);         count[height[v]]++;         enqueue(v);       }     }     void discharge(int v) {       for (int i = 0; excess[v] > 0 && i < g[v].size(); i++) push(g[v][i]);       if (excess[v] > 0) {         if (count[height[v]] == 1)           gap(height[v]);         else           relabel(v);       }     }     long long max_flow(int source, int dest) {       count[0] = n - 1, count[n] = 1, height[source] = n,       active[source] = active[dest] = 1;       for (auto &it : g[source]) {         excess[source] += it.cap;         push(it);       }       while (!Q.empty()) {         int v = Q.front();         Q.pop();         active[v] = false;         discharge(v);       }       long long max_flow = 0;       for (auto &e : g[source]) max_flow += e.flow;       return max_flow;     }   };   bool f(long long lvl) {     vector<long long> v = {0};     long long sm = 0, mx = -1, id = 0;     for (long long i = 1; i <= n; i++) {       if (l[i] <= lvl) {         if (c[i] != 1) {           sm += p[i];           v.push_back(i);         } else {           if (p[i] > mx) {             mx = p[i];             id = i;           }         }       }     }     if (mx != -1) {       v.push_back(id);       sm += p[id];     }     long long cnt = v.size() - 1;     PushRelabel Network(cnt + 2);     long long s = 0, t = cnt + 1;     vector<int> odd, even;     odd.push_back(0), even.push_back(0);     for (int i = 1; i <= cnt; i++) {       if (c[v[i]] & 1)         odd.push_back(v[i]);       else         even.push_back(v[i]);     }     int os = odd.size() - 1, es = even.size() - 1;     for (int i = 1; i <= os; i++) Network.addEdge(s, i, p[odd[i]]);     for (int i = 1; i <= es; i++) Network.addEdge(os + i, t, p[even[i]]);     for (int i = 1; i <= os; i++) {       for (int j = 1; j <= es; j++) {         int idx1 = odd[i], idx2 = even[j];         if (prime[c[idx1] + c[idx2]]) Network.addEdge(i, os + j, INF);       }     }     long long flow = Network.max_flow(s, t);     long long mxpow = sm - flow;     return mxpow >= k;   }   void solve() {     long long l = 0, r = n + 1;     while (r - l > 1) {       long long mid = (l + r) / 2;       if (f(mid))         r = mid;       else         l = mid;     }     if (f(r))       cout << r;     else       cout << -1;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     sieve();     cin >> n >> k;     for (long long i = 1; i <= n; i++) cin >> p[i] >> c[i] >> l[i];     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline T fetch() {     T ret;     cin >> ret;     return ret;   }   template <typename T>   inline vector<T> fetch_vec(long long sz) {     vector<T> ret(sz);     for (auto& it : ret) cin >> it;     return ret;   }   template <typename T>   inline void makeUnique(vector<T>& v) {     sort(v.begin(), v.end());     v.erase(unique(v.begin(), v.end()), v.end());   }   template <typename T>   inline T max_(T a, T b) {     if (a > b) return a;     return b;   }   template <typename T>   inline T min_(T a, T b) {     if (a < b) return a;     return b;   }   void file() {}   void Match() {}   const long long N = 2e5 + 5;   long long son[N * 32][2], pos = 0, cnt[N * 32];   long long dfs(long long p, long long digit) {     long long p0 = son[p][0];     long long p1 = son[p][1];     if (digit == 0) return max(cnt[p0], cnt[p1]) + (cnt[p0] & cnt[p1]);     long long num0 = 0, num1 = 0;     if (p0) num0 = dfs(p0, digit - 1);     if (p1) num1 = dfs(p1, digit - 1);     return max(num0, num1) + (num0 && num1);   }   signed main() {     ios::sync_with_stdio(false);     cin.tie(0);     ;     file();     long long n;     cin >> n;     for (long long i = 0; i < n; i++) {       long long num, p = 0;       cin >> num;       for (long long i = 30; i >= 0; i--) {         long long& t = son[p][num >> i & 1];         if (!t) t = ++pos;         cnt[t]++;         p = t;       }     }     cout << n - dfs(0, 30) <<   n ;     Match();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, cnt, x, y, mx, tot;   int head[200005], bin[200005], V[200005 * 5], T[200005 * 5];   struct pl {     int v, nex;   } e[2 * 200005];   void add(int a, int b) {     cnt++;     e[cnt].v = b;     e[cnt].nex = head[a];     head[a] = cnt;     bin[a]++;   }   void dfs(int a, int fa, int ti) {     int fl = ti;     V[++tot] = a;     T[tot] = ti;     if (ti == mx && a != 1) {       ti -= bin[a];       V[++tot] = a;       T[tot] = ti;     }     int i = head[a];     while (i != 0) {       if (e[i].v != fa) {         dfs(e[i].v, a, ti + 1);         ti++;         V[++tot] = a;         T[tot] = ti;         if (ti == mx && a != 1) {           ti -= bin[a];           V[++tot] = a;           T[tot] = ti;         }       }       i = e[i].nex;     }     if (ti != fl - 1 && a != 1) {       ti = fl - 1;       V[++tot] = a;       T[tot] = ti;     }   }   int main() {     scanf( %d , &n);     if (n == 1) {       puts( 1 );       puts( 1 0 );       return 0;     }     for (int i = 1; i < n; i++) scanf( %d%d , &x, &y), add(x, y), add(y, x);     for (int i = 1; i <= n; i++) mx = max(mx, bin[i]);     dfs(1, 0, 0);     printf( %d n , tot);     for (int i = 1; i <= tot; i++) printf( %d %d n , V[i], T[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, k, t;   char a[3][200];   bool vis[3][200];   bool check(int x, int y) { return (x >= 0 && y >= 0 && x < 3 && y < 200); }   void solve(int cx, int cy) {     if (vis[cx][cy]) {       return;     }     vis[cx][cy] = true;     if (check(cx, cy + 3) && a[cx][cy + 1] ==  .  && a[cx][cy + 2] ==  . ) {       solve(cx, cy + 3);     }     if (check(cx + 1, cy + 3) && a[cx][cy + 1] ==  .  &&         a[cx + 1][cy + 1] ==  .  && a[cx + 1][cy + 2] ==  . ) {       solve(cx + 1, cy + 3);     }     if (check(cx - 1, cy + 3) && a[cx][cy + 1] ==  .  &&         a[cx - 1][cy + 1] ==  .  && a[cx - 1][cy + 2] ==  . ) {       solve(cx - 1, cy + 3);     }   }   int main() {     cin >> t;     while (t--) {       memset(vis, 0, sizeof(vis));       for (int i = 0; i < 3; i++) {         for (int j = 0; j < 200; j++) {           a[i][j] =  . ;         }       }       cin >> n >> k;       int x, y;       for (int i = 0; i < 3; i++) {         for (int j = 0; j < n; j++) {           cin >> a[i][j];           if (a[i][j] ==  s ) {             x = i, y = j;           }         }       }       solve(x, y);       bool ans = false;       for (int i = 0; i < 3; i++) {         for (int j = n - 1; j < 200; j++) {           ans |= vis[i][j];         }       }       if (ans) {         cout <<  YES n ;       } else {         cout <<  NO n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) {     if (b == 0) return a;     return gcd(b, a % b);   }   long long lcm(long long a, long long b) { return (a / gcd(a, b) * b); }   bool sorta(const pair<int, int> &a, const pair<int, int> &b) {     return (a.second < b.second);   }   bool sortd(const pair<int, int> &a, const pair<int, int> &b) {     return (a.second > b.second);   }   void printarr(long long arr[], long long n) {     for (int i = 0; i < n; i++) cout << arr[i] <<    ;     cout <<   n ;   }   string decToBinary(int n) {     string s =   ;     int i = 0;     while (n > 0) {       s = to_string(n % 2) + s;       n = n / 2;       i++;     }     return s;   }   long long binaryToDecimal(string n) {     string num = n;     long long dec_value = 0;     int base = 1;     int len = num.length();     for (int i = len - 1; i >= 0; i--) {       if (num[i] ==  1 ) dec_value += base;       base = base * 2;     }     return dec_value;   }   bool isPrime(long long n) {     if (n <= 1) return false;     if (n <= 3) return true;     if (n % 2 == 0 || n % 3 == 0) return false;     for (int i = 5; i * i <= n; i = i + 6)       if (n % i == 0 || n % (i + 2) == 0) return false;     return true;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long t;     cin >> t;     long long i = 1;     while (t--) {       long long w, h;       cin >> w >> h;       long long arr1[4];       for (int i = 0; i < 4; i++) {         int k;         cin >> k;         long long arr[k];         for (int j = 0; j < k; j++) cin >> arr[j];         arr1[i] = arr[k - 1] - arr[0];       }       arr1[0] *= h, arr1[1] *= h;       arr1[2] *= w, arr1[3] *= w;       long long maxan = max({arr1[0], arr1[1], arr1[2], arr1[3]});       cout << maxan <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 3 + 2e5;   int root[N], ls[N << 5], rs[N << 5], id;   int sum[N << 5];   int n, q, p[N];   void update(int &u, int v, int l, int r, int p) {     sum[u = ++id] = sum[v] + 1;     if (l == r) return;     int mid = l + r >> 1;     if (p <= mid)       rs[u] = rs[v], update(ls[u], ls[v], l, mid, p);     else       ls[u] = ls[v], update(rs[u], rs[v], mid + 1, r, p);   }   int query(int u, int v, int l, int r, int L, int R) {     if (L <= l && r <= R) return sum[v] - sum[u];     int ans = 0, mid = l + r >> 1;     if (L <= mid) ans = query(ls[u], ls[v], l, mid, L, R);     if (R > mid) ans += query(rs[u], rs[v], mid + 1, r, L, R);     return ans;   }   int query(int d, int u, int l, int r) {     if (l > r || u < d) return 0;     return query(root[l - 1], root[r], 1, n, d, u);   }   int main() {     int l, d, r, u;     scanf( %d%d , &n, &q);     for (int i = 1; i <= n; ++i) {       scanf( %d , p + i);       update(root[i], root[i - 1], 1, n, p[i]);     }     while (q--) {       scanf( %d%d%d%d , &l, &d, &r, &u);       long long a1 = query(u + 1, n, 1, l - 1);       long long a2 = query(u + 1, n, l, r);       long long a3 = query(u + 1, n, r + 1, n);       long long a4 = query(d, u, 1, l - 1);       long long a5 = query(d, u, l, r);       long long a6 = query(d, u, r + 1, n);       long long a7 = query(1, d - 1, 1, l - 1);       long long a8 = query(1, d - 1, l, r);       long long a9 = query(1, d - 1, r + 1, n);       long long ans = 0;       ans = a1 * (a5 + a6 + a8 + a9);       ans += a2 * (a4 + a5 + a6 + a7 + a8 + a9);       ans += a3 * (a4 + a5 + a7 + a8);       ans += a4 * (a5 + a6 + a8 + a9);       ans += a5 * (a6 + a7 + a8 + a9);       ans += a6 * (a7 + a8);       ans += a5 * (a5 - 1) / 2;       printf( %lld n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, k, p;     cin >> n >> k;     int l = log2(n) + 1;     for (long int i = 1; i <= 30; i++) {       if (n - i * k > 0) {         p = n - i * k;         bitset<30> b(p);         if (i > b.count() && p != 1 && p >= i) {           cout << i;           break;         } else if (i == b.count()) {           cout << i;           break;         }       } else {         cout <<  -1 ;         break;       }     }   }


#include <bits/stdc++.h>   using namespace std;   vector<pair<int, int> > sol[1 << 9];   vector<pair<int, int> > gs(int t, int x) {     static int fm[1 << 19];     static pair<int, int> fs[1 << 19];     queue<int> q;     vector<pair<pair<int, int>, int> > sb;     for (int i = 0; i < (1 << t); ++i) fm[i] = -1;     for (int i = 0; i < t; ++i)       for (int k = 1; i + k + k < t; ++k)         sb.push_back(make_pair(pair<int, int>(i, k),                                (1 << i) ^ (1 << (i + k)) ^ (1 << (i + k + k))));     q.push(x);     fm[x] = -2;     while (!q.empty()) {       int w = q.front();       q.pop();       for (auto p : sb) {         if (fm[w ^ p.second] != -1) continue;         fm[w ^ p.second] = w;         fs[w ^ p.second] = p.first;         q.push(w ^ p.second);       }     }     if (fm[0] == -1) throw  GG ;     int tt = 0;     vector<pair<int, int> > vp;     while (tt != x) vp.push_back(fs[tt]), tt = fm[tt];     return vp;   }   int n;   int a[233333];   int main() {     int mx = 0;     for (int i = 0; i < (1 << 9); ++i) {       vector<pair<int, int> > sb;       for (int j = 0; j < 12; ++j)         for (int k = 1; j + k + k < 12; ++k) sb.push_back(pair<int, int>(j, k));       random_shuffle(sb.begin(), sb.end());       int u = sb.size();       for (int x = -1; x < u; ++x)         for (int y = x; y < u; ++y)           for (int z = y; z < u; ++z) {             vector<pair<int, int> > p;             if (x >= 0) p.push_back(sb[x]);             if (y >= 0) p.push_back(sb[y]);             if (z >= 0) p.push_back(sb[z]);             int w = i;             for (auto h : p) {               int a = h.first, b = h.second;               if (a >= 0 && a < 9) w ^= 1 << a;               if (a + b >= 0 && a + b < 9) w ^= 1 << (a + b);               if (a + b + b >= 0 && a + b + b < 9) w ^= 1 << (a + b + b);             }             if (!w) {               sol[i] = p;               goto GG;             }           }       cout <<  NMSL. n ;     GG:;     }     scanf( %d , &n);     for (int i = 1; i <= n; ++i) scanf( %d , a + i);     vector<pair<pair<int, int>, int> > vp;     int l = 1;     while (n - l + 1 >= 18) {       int h = 0;       for (int p = 0; p < 9; ++p)         if (a[l + p]) h ^= 1 << p;       vector<pair<int, int> > w = sol[h];       for (auto& t : w) {         t.first += l;         vp.push_back(make_pair(make_pair(t.first, t.first + t.second),                                t.first + t.second + t.second));         a[t.first] ^= 1;         a[t.first + t.second] ^= 1;         a[t.first + t.second + t.second] ^= 1;       }       l += 9;     }     try {       int g = 0;       for (int i = l; i <= n; ++i)         if (a[i]) g ^= 1 << (i - l);       vector<pair<int, int> > w = gs(n - l + 1, g);       for (auto& t : w) {         t.first += l;         vp.push_back(make_pair(make_pair(t.first, t.first + t.second),                                t.first + t.second + t.second));         a[t.first] ^= 1;         a[t.first + t.second] ^= 1;         a[t.first + t.second + t.second] ^= 1;       }     } catch (...) {       puts( NO );       return 0;     }     for (int i = 0; i <= n + 1; ++i)       if (a[i]) throw  GG ;     puts( YES );     printf( %d n , int(vp.size()));     for (auto t : vp)       printf( %d %d %d n , t.first.first, t.first.second, t.second);   }


#include <bits/stdc++.h>   using namespace std;   inline int read() {     int s = 0, w = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) w = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       s = s * 10 + ch -  0 ;       ch = getchar();     }     return s * w;   }   pair<int, int> p[200005];   set<pair<int, int> > s;   void solve(int l, int r) {     if (l >= r) return;     int mid = (l + r) >> 1;     for (int i = l; i <= r; i++)       s.insert(pair<int, int>(p[mid].first, p[i].second));     solve(l, mid);     solve(mid + 1, r);     return;   }   int n;   void init() {     n = read();     for (int i = 1; i <= n; i++) {       p[i].first = read();       p[i].second = read();       s.insert(p[i]);     }     sort(p + 1, p + n + 1);     return;   }   void solv() {     solve(1, n);     printf( %d n , (int)s.size());     for (auto i = s.begin(); i != s.end(); i++) {       printf( %d %d n , i->first, i->second);     }     return;   }   int main() {     init();     solv();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long i, j, m, n, k, x, y, sum = 0;     cin >> n >> k;     vector<long long> sura;     vector<pair<long long, long long> > dada;     vector<pair<long long, long long> > dada2;     vector<long long> su;     long long arr[n];     priority_queue<long long, vector<long long>, greater<long long> > pq;     for (i = 0; i < n; i++) {       cin >> x;       sura.push_back(x);     }     for (i = 0; i < n; i++) {       cin >> x;       dada.push_back(make_pair(sura[i], x));       dada2.push_back(make_pair(sura[i], i));     }     sort(dada.begin(), dada.end());     sort(dada2.begin(), dada2.end());     for (i = 0; i < n; i++) {       if (k == 0) {         su.push_back(sum + dada[i].second);       } else if (k > 0) {         su.push_back(sum + dada[i].second);         if (i < k) {           sum += dada[i].second;           pq.push(dada[i].second);         } else {           if (dada[i].second > pq.top()) {             sum -= pq.top();             pq.pop();             sum += dada[i].second;             pq.push(dada[i].second);           }         }       }     }     for (i = 0; i < n; i++) {       arr[dada2[i].second] = su[i];     }     for (i = 0; i < n; i++) {       cout << arr[i] <<    ;     }   }


#include <bits/stdc++.h>   using namespace std;   template <typename T1, typename T2>   void chkmin(T1 &x, T2 y) {     if (x > y) x = y;   }   template <typename T1, typename T2>   void chkmax(T1 &x, T2 y) {     if (x < y) x = y;   }   inline void debug(int x) { fprintf(stderr,  ycx has aked ioi %d times n , x); }   namespace fastio {   char rbuf[1 << 23], *p1 = rbuf, *p2 = rbuf, wbuf[1 << 23], *p3 = wbuf;   inline char getc() {     return p1 == p2 &&                    (p2 = (p1 = rbuf) + fread(rbuf, 1, 1 << 23, stdin), p1 == p2)                ? -1                : *p1++;   }   inline void putc(char x) { (*p3++ = x); }   template <typename T>   void read(T &x) {     x = 0;     char c = getchar();     T neg = 0;     while (!isdigit(c)) neg |= !(c ^  - ), c = getchar();     while (isdigit(c)) x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();     if (neg) x = (~x) + 1;   }   template <typename T>   void recursive_print(T x) {     if (!x) return;     recursive_print(x / 10);     putc(x % 10 ^ 48);   }   template <typename T>   void print(T x) {     if (!x) putc( 0 );     if (x < 0) putc( - ), x = ~x + 1;     recursive_print(x);   }   void print_final() { fwrite(wbuf, 1, p3 - wbuf, stdout); }   }  // namespace fastio   const int MAXN = 2e5;   const int LOG_N = 19;   const int MOD = 1e9 + 7;   int qpow(int x, int e = MOD - 2) {     int ret = 1;     for (; e; e >>= 1, x = 1ll * x * x % MOD)       if (e & 1) ret = 1ll * ret * x % MOD;     return ret;   }   int pr[MAXN / 5 + 5], vis[MAXN + 5], phi[MAXN + 5], mu[MAXN + 5], prcnt = 0;   void sieve(int n) {     phi[1] = mu[1] = 1;     for (int i = 2; i <= n; i++) {       if (!vis[i]) {         pr[++prcnt] = i;         phi[i] = i - 1;         mu[i] = -1;       }       for (int j = 1; j <= prcnt && i * pr[j] <= n; j++) {         vis[i * pr[j]] = 1;         if (i % pr[j] == 0) {           phi[i * pr[j]] = phi[i] * pr[j];           break;         } else           phi[i * pr[j]] = phi[i] * phi[pr[j]], mu[i * pr[j]] = -mu[i];       }     }   }   int n, a[MAXN + 5], pos[MAXN + 5], f[MAXN + 5], res[MAXN + 5];   int hd[MAXN + 5], to[MAXN * 2 + 5], nxt[MAXN * 2 + 5], ec = 0;   void adde(int u, int v) {     to[++ec] = v;     nxt[ec] = hd[u];     hd[u] = ec;   }   int seq[MAXN * 2 + 5], dfn[MAXN + 5], tim = 0, tim_dfn = 0, dep[MAXN + 5],                                         bgt[MAXN + 5];   pair<int, int> st[MAXN * 2 + 5][LOG_N + 2];   void dfs(int x, int f) {     bgt[x] = ++tim_dfn;     for (int e = hd[x]; e; e = nxt[e]) {       int y = to[e];       if (y == f) continue;       dep[y] = dep[x] + 1;       dfs(y, x);       seq[++tim] = x;     }     seq[++tim] = x;     dfn[x] = tim;   }   pair<int, int> querymn(int l, int r) {     int k = 31 - __builtin_clz(r - l + 1);     return min(st[l][k], st[r - (1 << k) + 1][k]);   }   int getlca(int x, int y) {     if (dfn[x] > dfn[y]) x ^= y ^= x ^= y;     return querymn(dfn[x], dfn[y]).second;   }   int pt[MAXN + 5], pcnt = 0, stk[MAXN + 5], tp = 0;   bool in[MAXN + 5];   vector<pair<int, int> > g[MAXN + 5];   void adde_vir(int u, int v) { g[u].push_back(make_pair(v, dep[v] - dep[u])); }   void insert(int x) {     if (!tp) {       stk[++tp] = x;       return;     }     int lca = getlca(x, stk[tp]);     while (tp >= 2 && dep[lca] < dep[stk[tp - 1]]) {       adde_vir(stk[tp - 1], stk[tp]);       tp--;     }     if (tp && dep[lca] < dep[stk[tp]]) adde_vir(lca, stk[tp--]);     if (!tp || stk[tp] != lca) stk[++tp] = lca;     stk[++tp] = x;   }   void fin() {     while (tp >= 2) adde_vir(stk[tp - 1], stk[tp]), tp--;     tp = 0;   }   int ret = 0, dp[MAXN + 5], dis[MAXN + 5];   void dfs_vir(int x) {     dp[x] = 0;     for (int i = 0; i < g[x].size(); i++) {       int y = g[x][i].first, z = g[x][i].second;       dis[y] = dis[x] + z;       dfs_vir(y);       ret = (ret - 2ll * dp[x] * dp[y] % MOD * dis[x] % MOD + MOD) % MOD;       dp[x] = (dp[x] + dp[y]) % MOD;     }     if (in[x]) {       ret = (ret - 1ll * dp[x] * phi[a[x]] % MOD * dis[x] % MOD + MOD) % MOD;       dp[x] = (dp[x] + phi[a[x]]) % MOD;       ret = (ret - 1ll * dp[x] * phi[a[x]] % MOD * dis[x] % MOD + MOD) % MOD;     }   }   void clear(int x) {     dp[x] = dis[x] = 0;     for (int i = 0; i < g[x].size(); i++) clear(g[x][i].first);     while (g[x].size()) g[x].pop_back();   }   int solve(int x) {     pcnt = 0;     for (int i = x; i <= n; i += x) pt[++pcnt] = pos[i], in[pos[i]] = 1;     sort(pt + 1, pt + pcnt + 1, [](int x, int y) { return bgt[x] < bgt[y]; });     if (!in[1]) insert(1);     for (int i = 1; i <= pcnt; i++) insert(pt[i]);     fin();     ret = 0;     dfs_vir(1);     int s1 = 0, s2 = 0;     for (int i = 1; i <= pcnt; i++) {       s1 = (s1 + 1ll * phi[a[pt[i]]] * dis[pt[i]]) % MOD;       s2 = (s2 + phi[a[pt[i]]]) % MOD;     }     ret = (ret + 1ll * s1 * s2) % MOD;     ret = ret * 2 % MOD;     clear(1);     for (int i = x; i <= n; i += x) in[pos[i]] = 0;     return ret;   }   int main() {     scanf( %d , &n);     sieve(n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]), pos[a[i]] = i;     for (int i = 1, u, v; i < n; i++)       scanf( %d%d , &u, &v), adde(u, v), adde(v, u);     dfs(1, 0);     for (int i = 1; i <= n << 1; i++) st[i][0] = make_pair(dep[seq[i]], seq[i]);     for (int i = 1; i <= LOG_N; i++)       for (int j = 1; j + (1 << i) - 1 <= n << 1; j++)         st[j][i] = min(st[j][i - 1], st[j + (1 << i - 1)][i - 1]);     for (int i = 1; i <= n; i++) f[i] = solve(i);     for (int i = 1; i <= n; i++)       for (int j = i; j <= n; j += i) {         if (mu[j / i] == 1)           res[i] = (res[i] + f[j]) % MOD;         else if (mu[j / i] == -1)           res[i] = (res[i] - f[j] + MOD) % MOD;       }     int ans = 0;     for (int i = 1; i <= n; i++)       ans = (ans + 1ll * res[i] * i % MOD * qpow(phi[i])) % MOD;     ans = 1ll * ans * qpow(n) % MOD;     ans = 1ll * ans * qpow(n - 1) % MOD;     printf( %d n , ans);     return 0;   }