#include <bits/stdc++.h>   using namespace std;   const int INFint = 2147483647;   const long long INF = 9223372036854775807ll;   const long long MOD = 1000000007ll;   char f[2020][2020];   int n, m;   bool c(int x, int y, int d, int cnt) {     int cur = 0;     cerr << x <<     << y << endl;     if (x > 0 && y > 0 && x + d - 1 <= n && y + d - 1 <= m) {       for (int i = x; i < x + d; i++) {         cur += (f[i][y] ==  w );         cur += (f[i][y + d - 1] ==  w );       }       for (int i = y + 1; i < y + d - 1; i++) {         cur += (f[x][i] ==  w );         cur += (f[x + d - 1][i] ==  w );       }       return (cur == cnt);     }     return 0;   }   int main() {     ios_base::sync_with_stdio(0);     int minx = INFint, miny = INFint, maxx = -INFint, maxy = -INFint;     cin >> n >> m;     int cnt = 0;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         cin >> f[i][j];         if (f[i][j] ==  w ) {           minx = min(minx, i);           miny = min(miny, j);           maxx = max(maxx, i);           maxy = max(maxy, j);           cnt++;         }       }     }     int d = max(maxx - minx + 1, maxy - miny + 1);     cerr << d << endl;     if (d == 1) {       for (int it = 1; it <= n; it++) {         for (int l = 1; l <= m; l++) cout << f[it][l];         cout << endl;       }       return 0;     }     int x[3] = {minx, maxx - d + 1, 1};     int y[3] = {miny, maxy - d + 1, 1};     for (int i = 0; i < 3; i++) cerr << x[i] <<    ;     cerr << endl;     for (int i = 0; i < 3; i++) cerr << y[i] <<    ;     cerr << endl;     for (int i = 0; i < 3; i++)       for (int j = 0; j < 3; j++) {         if (c(x[i], y[j], d, cnt)) {           for (int it = x[i]; it < x[i] + d; it++) {             if (f[it][y[j]] !=  w ) f[it][y[j]] =  + ;             if (f[it][y[j] + d - 1] !=  w ) f[it][y[j] + d - 1] =  + ;           }           for (int it = y[j]; it < y[j] + d; it++) {             if (f[x[i]][it] !=  w ) f[x[i]][it] =  + ;             if (f[x[i] + d - 1][it] !=  w ) f[x[i] + d - 1][it] =  + ;           }           for (int it = 1; it <= n; it++) {             for (int l = 1; l <= m; l++) cout << f[it][l];             cout << endl;           }           return 0;         }       }     cout << -1 << endl;     fprintf(stderr,   nTIME = %lf n , 1.0 * clock() / CLOCKS_PER_SEC);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int a[n];     for (int i = 0; i < n; i++) {       cin >> a[i];     }     int count1 = 0;     for (int i = 0; i < n; i++) {       int sum = 0;       for (int j = 0; j < n; j++) {         if (i == j) {           continue;         } else {           sum += a[j];         }       }       if (sum % 2 == 0) {         count1++;       }     }     cout << count1 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int sgn(double x) { return (x > 1e-8) - (x < -1e-8); }   int count_bit(int x) { return x == 0 ? 0 : count_bit(x >> 1) + (x & 1); }   template <class T>   inline void ckmin(T& a, const T b) {     if (b < a) a = b;   }   template <class T>   inline void ckmax(T& a, const T b) {     if (b > a) a = b;   }   const int MAXN = 100000 + 10;   struct binary_indexed_tree {     int a[MAXN], val[MAXN];     void clear() {       memset(a, 0, sizeof(a));       memset(val, 0, sizeof(val));     }     void update(int x, int y) {       val[x] += y;       for (; x < MAXN; x += ((x) & (-(x)))) {         a[x] += y;       }     }     int getsum(int x) {       int ret = 0;       for (; x; x -= ((x) & (-(x)))) {         ret += a[x];       }       return ret;     }     int getsum(int l, int r) {       int ret = 0;       while (l <= r) {         if (r - ((r) & (-(r))) + 1 >= l) {           ret += a[r];           r -= ((r) & (-(r)));         } else {           ret += val[r--];         }       }       return ret;     }   } bit;   void filp_left(int& l, int& r, int len) {     for (int i = (1); i <= (len); ++i) {       bit.update(l + len + len - i, bit.val[l + i - 1]);     }     l += len;   }   void filp_right(int& l, int& r, int len) {     for (int i = (1); i <= (len); ++i) {       bit.update(r - len - len + i, bit.val[r - i + 1]);     }     r -= len;   }   int main() {     int n, q;     while (scanf( %d%d , &n, &q) != EOF) {       bit.clear();       for (int i = 0; i < (n); ++i) {         bit.update(i + 1, 1);       }       int off = 0;       int l = 1, r = n;       bool rev = false;       for (int i = 0; i < (q); ++i) {         int optype, flen, cl, cr;         scanf( %d , &optype);         if (optype == 1) {           scanf( %d , &flen);           int clen = r - l + 1;           if (2 * flen > clen) {             if (!rev) {               filp_right(l, r, clen - flen);             } else {               filp_left(l, r, clen - flen);             }             rev = !rev;           } else {             if (!rev) {               filp_left(l, r, flen);             } else {               filp_right(l, r, flen);             }           }         } else {           scanf( %d%d , &cl, &cr);           int ret;           if (!rev) {             ret = bit.getsum(l + cl, l + cr - 1);           } else {             ret = bit.getsum(r - cr + 1, r - cl);           }           printf( %d n , ret);         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n, m;     cin >> n >> m;     int c1 = 0, c2 = 0;     for (int i = 0; i < n; ++i) {       int aux;       cin >> aux;       c1 += aux == 1;       c2 += aux == -1;     }     for (int i = 0; i < m; ++i) {       int a, b;       cin >> a >> b;       if ((b - a + 1) % 2 == 0) {         if (c1 >= (b - a + 1) / 2 && c2 >= (b - a + 1) / 2)           cout <<  1 n ;         else           cout <<  0 n ;       } else         cout <<  0 n ;     }     return 0;   }


#include <bits/stdc++.h>   int main() {     char s[15];     char a;     int len;     scanf( %s , s);     len = strlen(s);     a =  a  - 1;     for (int i = 0; i < len; i++) {       if (a <= s[i]) {         a = s[i];       }     }     for (int i = 0; i < len; i++) {       if (s[i] == a) printf( %c , s[i]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1000000 + 239;   const int inf = (int)1e9 + 1;   const long long big = (long long)1e18 + 1;   const int P = 31;   const int MOD = (int)1e9 + 7;   const int MOD1 = (int)1e9 + 9;   const double eps = 1e-9;   const double pi = atan2(0, -1);   int a[N];   vector<int> g[N];   int d[N];   void dfs(int u) {     for (int v : g[u]) {       dfs(v);       d[u] = max(d[u], d[v] + 1);     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.precision(20);     int n;     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 1; i < n; i++) {       int p;       cin >> p;       p--;       g[p].push_back(i);     }     dfs(0);     int res = 0;     for (int i = 0; i < n; i++)       if (d[i] % 2 == 0) res ^= a[i];     map<int, int> cnt;     for (int i = 0; i < n; i++)       if (d[i] % 2 == 1) cnt[a[i]]++;     long long ans = 0;     for (int i = 0; i < n; i++)       if (d[i] % 2 == 0) ans += cnt[res ^ a[i]];     if (res == 0) {       int cnt0 = 0, cnt1 = 0;       for (int i = 0; i < n; i++)         if (d[i] % 2 == 0)           cnt0++;         else           cnt1++;       ans += (long long)cnt0 * (cnt0 - 1) / 2;       ans += (long long)cnt1 * (cnt1 - 1) / 2;     }     cout << ans << endl;     return 0;   }


//#pragma GCC target ( avx2 )   //#pragma GCC optimization ( O3 )   //#pragma GCC optimization ( unroll-loops )   #include<bits/stdc++.h>   //#include <ext/pb_ds/assoc_container.hpp>   //#include <ext/pb_ds/tree_policy.hpp>   //using namespace __gnu_pbds;   #define eps 1e-8   #define eq(x,y) (fabs((x)-(y)) < eps)   using namespace std;   typedef long long ll;   typedef long double ld;   typedef pair<int,int>pii;   const ll mod= 998244353;   long double PI = acosl(-1);   const ll infl = 1e17+100;   const int inf = 1e9+100;   const int nmax = 3e5+5;   //const int MAXLG = log2(nmax)+1;   //mt19937 rng(chrono::system_clock::now().time_since_epoch().count());   //typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ost;      bool vis[nmax];   vector<int>g[nmax];      void dfs(int u){       vis[u] = true;       for(int v : g[u]) if(!vis[v])           dfs(v);   }         int main(){          ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);          int tc;       cin>>tc;       while(tc--){           int n,m;           cin>>n>>m;           for(int i=0; i<m; i++){               int u,v;               cin>>u>>v;               g[u].push_back(v);               g[v].push_back(u);           }           bool hoise = false;           bool unposibol = false;           for(int i=1; i<=n; i++){               if(!vis[i]){                   if(!hoise){                       dfs(i);                       hoise = true;                   }                   else unposibol = true;               }           }           if(unposibol) cout<< NO n ;           else{               cout<< YES n ;               for(int i=1; i<=n; i++) vis[i] = false;               vector<int>ans;               set<int>st; st.insert(1);               while(st.size()){                   int u = *st.begin();                   st.erase(u);                   if(vis[u]) continue;                   vis[u] = true;                   ans.push_back(u);                   vector<int>tmp;                   for(int v : g[u]) if(!vis[v]){                       vis[v] = true;                       tmp.push_back(v);                   }                   for(int v : tmp){                       for(int z : g[v]) if(!vis[z]){                           st.insert(z);                       }                   }               }               cout<<ans.size()<<  n ;               for(int x : ans) cout<<x<<   ;               cout<<  n ;           }           for(int i=1; i<=n; i++) vis[i] = false, g[i].clear();       }         }   /*      */


#include <bits/stdc++.h>   using namespace std;   long long mysqrt(long long x) {     long long l = 0;     long long r = 1;     while (r * r <= x) r *= 2;     while (r - l > 1) {       long long m = (l + r) / 2;       if (m * m <= x)         l = m;       else         r = m;     }     return l;   }   int main() {     long long n;     cin >> n;     long long a[n + 2][n + 2];     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         cin >> a[i][j];       }     }     for (int i = 0; i < n; i++) {       int j = (i + 1) % n;       int k = (j + 1) % n;       cout << mysqrt(1ll * a[i][j] * a[i][k] / a[j][k]) <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, mx = 0, i, j, value;     cin >> n;     vector<int> v(n + 1, 0);     for (i = 1; i <= n; i++) {       cin >> v[i];       v[i] += v[i - 1];     }     for (i = 1; i <= n; i++) {       for (j = 0; j < i; j++) {         if ((v[i] - v[j]) > (100 * (i - j))) {           mx = max(mx, i - j);           break;         }       }     }     cout << mx << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve();   string conc(long long int a, long long int b) {     return to_string(a) +  |  + to_string(b);   }   long long int rev(long long int x) {     long long int ans = 0;     while (x != 0) {       ans = ans * 10 + (x % 10);       x /= 10;     }     return ans;   }   long long int numdig(long long int x) {     long long int ans = 0;     while (x != 0) {       ans++;       x /= 10;     }     return ans;   }   void printvec(vector<long long int> &v) {     for (long long int i = 0; i < v.size(); i++) cout << v[i] <<    ;     cout <<   n ;   }   void printmat(vector<vector<long long int>> &mat) {     for (long long int i = 0; i < mat.size(); i++) {       for (long long int j = 0; j < mat[0].size(); j++) cout << mat[i][j] <<    ;       cout <<   n ;     }   }   void solve() {     long long int n, k;     cin >> n >> k;     string s;     cin >> s;     vector<long long int> f(26, 0);     vector<pair<char, long long int>> v;     long long int vsize = 0;     for (auto c : s) f[c -  a ]++;     for (long long int i = 0; i < 26; i++) {       if (f[i] > 0) {         v.push_back({ a  + i, f[i]});         vsize++;       }     }     if (v[0].second < k) {       long long int count = 0;       for (long long int i = 0; i < vsize; i++) {         count += v[i].second;         if (count >= k) {           cout << v[i].first <<   n ;           return;         }       }       return;     }     string init =   ;     init = init + v[0].first;     vector<string> words(k, init);     v[0].second -= k;     for (long long int i = 0; i < vsize; i++) {       if (i == vsize - 1) {         long long int j = 0;         long long int c = 0;         while (j < k && words[j] == words[0]) j++;         while (v[i].second--) {           words[c] += v[i].first;           c = (c + 1) % j;         }       } else {         while (v[i].second--) {           words[0] += v[i].first;         }       }     }     sort(words.begin(), words.end());     cout << words[k - 1] <<   n ;   }   int main(void) {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int t;     t = 1;     cin >> t;     while (t--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 998244353;   pair<int, int> calc(int a, int b) {     if (a <= b) return {a, 0};     int r = a / b;     if (a % b == 0) return {b, r - 1};     return {a / (r + 1), r};   }   vector<pair<int, int>> compact(const vector<pair<int, int>>& V) {     vector<pair<int, int>> R;     int p = -1, c = 0;     for (auto [a, b] : V) {       if (a != p && p != -1) {         R.emplace_back(p, c);         c = 0;       }       p = a;       c += b;     }     R.emplace_back(p, c);     return R;   }   int main() {     ios_base::sync_with_stdio(false);     int tn;     cin >> tn;     for (int ti = 0; ti < tn; ++ti) {       int n;       cin >> n;       vector<int> A(n);       for (int& a : A) cin >> a;       vector<pair<int, int>> B;       uint64_t r = 0;       for (int i = n - 1; i > 0; --i) {         B.emplace_back(A[i], 1);         vector<pair<int, int>> C;         for (auto [x, y] : B) {           auto [z, t] = calc(A[i - 1], x);           C.emplace_back(z, y);           r = (r + 1ull * t * i * y) % MOD;         }         sort(C.begin(), C.end());         B = compact(C);       }       cout << r << endl;     }     return 0;   }


#include<bits/stdc++.h>   #define maxn 1000005   #define inf 9999999999999999   #define mod 100003   typedef long long LL;   using namespace std;   LL a[maxn];   int main()   {       ios::sync_with_stdio(false);       //freopen( bwxnQAQin.txt , r ,stdin);       LL T;       cin>>T;       while(T--)       {           LL n;           cin>>n;           if(n&1)           {               LL zong=n-1,fuyi=zong/2;               for(LL i=zong;i>=1;i--)               {                   for(LL j=1;j<=i-fuyi;j++)cout<< 1  ;                   for(LL j=1;j<=fuyi;j++)cout<< -1  ;                   if(fuyi)fuyi--;               }               cout<<endl;           }           else           {               LL zong=n-1,ban=zong/2;               for(LL i=1;i<=zong;i++)               {                   for(LL j=i;j<=zong;j++)                   {                       if(j<i+ban)cout<< 1  ;                       else if(j==i+ban)cout<< 0  ;                       else cout<< -1  ;                   }               }               cout<<endl;           }       }       return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline long long read() {     long long x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x * f;   }   double p[200010];   int n, cnt;   double ans;   inline void solve(int a, int b) {     ans += (double)(a - b) / 2;     p[++cnt] = (double)(a + b) / 2;   }   int main() {     n = read();     for (int i = 1; i <= n; i++) {       long long a = read(), b = read(), c = read(), d = read();       if (a + b >= c + d) {         solve(a, b);         solve(c, d);       } else {         if (a >= d) solve(a - d, d - a);         if (b >= c) solve(c - b, b - c);       }     }     sort(p + 1, p + cnt + 1, greater<double>());     for (int i = 1; i <= cnt; i++) {       if (i & 1)         ans += p[i];       else         ans -= p[i];     }     printf( %.0f n , ans);   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1000010;   int f[N];   void init() {     for (int i = 1; i <= N; i++) {       f[i] = f[i - 1] + i * 2 + (i - 1);       if (f[i] >= 1e9) {         break;       }     }   }   int Find(int x) {     int l = 0, r = 25820;     while (l < r) {       int mid = (l + r + 1) / 2;       if (f[mid] <= x)         l = mid;       else         r = mid - 1;     }     return l;   }   int main() {     int T;     scanf( %d , &T);     init();     while (T--) {       int x;       scanf( %d , &x);       int ans = 0;       while (true) {         int t = Find(x);         if (f[t] <= 0) break;         x -= f[t];         ans++;       }       printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = ~0ull / 2;   const int maxn = 100100;   int seen[maxn];   int ind[maxn];   int par[maxn][22];   int bd[maxn];   int h[maxn];   vector<int> adj[maxn];   vector<int> adlist[maxn];   vector<int> tree[maxn];   vector<pair<int, int> > edges;   void dfs1(int root, int dad = -1) {     seen[root] = 1;     bd[root] = h[root];     for (auto v : adj[root]) {       if (!seen[v]) {         h[v] = h[root] + 1;         dfs1(v, root);         bd[root] = min(bd[v], bd[root]);         if (!(bd[v] > h[root])) {           adlist[root].push_back(v);           adlist[v].push_back(root);         } else {           edges.push_back(make_pair(root, v));         }       } else {         if (v != dad) {           adlist[root].push_back(v);           adlist[v].push_back(root);           bd[root] = min(bd[root], h[v]);         }       }     }   }   void dfs2(int root, int t) {     seen[root] = 2;     ind[root] = t;     for (auto v : adlist[root]) {       if (seen[v] == 1) {         dfs2(v, t);       }     }   }   void dfs3(int root, int dad) {     par[root][0] = dad;     for (auto v : tree[root]) {       if (v != dad) {         h[v] = h[root] + 1;         dfs3(v, root);       }     }   }   int dis(int x, int y) {     x = ind[x];     y = ind[y];     if (h[x] < h[y]) swap(x, y);     int X = x;     int Y = y;     int t = 20;     while (h[x] != h[y]) {       if (h[par[x][t]] >= h[y]) x = par[x][t];       t--;     }     if (x == y) return h[X] - h[x];     int A;     t = 20;     while (par[x][0] != par[y][0] and t >= 0) {       if (par[x][t] != par[y][t]) {         x = par[x][t];         y = par[y][t];       }       t--;     }     A = par[x][0];     return (h[X] + h[Y] - 2 * h[A]);   }   int main() {     ios::sync_with_stdio(false), cin.tie(0);     int n, m, k;     cin >> n >> m;     for (int i = 0; i < m; i++) {       int a, b;       cin >> a >> b;       a--, b--;       adj[a].push_back(b);       adj[b].push_back(a);     }     dfs1(0);     int t = 1;     for (int i = 0; i < n; i++) {       if (seen[i] == 1) {         dfs2(i, t);         t++;       }     }     for (auto e : edges) {       int x = e.first;       int y = e.second;       x = ind[x];       y = ind[y];       tree[x].push_back(y);       tree[y].push_back(x);     }     h[0] = 0;     h[1] = 1;     dfs3(1, 0);     fill(par[0], par[0] + 22, 0);     for (int i = 1; i < 22; i++)       for (int j = 1; j < t; j++) par[j][i] = par[par[j][i - 1]][i - 1];     cin >> k;     for (int i = 0; i < k; i++) {       int s, l;       cin >> s >> l;       s--, l--;       cout << dis(s, l) <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 5;   double dp[maxn], p[maxn];   int main() {     int n;     scanf( %d , &n);     double ans = 0, d;     for (int i = 1; i <= n; i++) {       scanf( %lf , &p[i]);       ans += p[i];     }     for (int i = 2; i <= n; i++) {       dp[i] = (dp[i - 1] + p[i - 1]) * p[i];       ans += 2 * dp[i];     }     printf( %.10f n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int read() {     int x = 0;     char c = getchar();     bool p = 1;     for (; !isdigit(c); c = getchar())       if (c ==  - ) p = 0;     for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);     return p ? x : -x;   }   const int N = 1000105;   struct edge {     int to, nt;   } e[N * 2];   int n, k, x, y, ans, cnt, head[N], rt = 1, du[N];   void add(int u, int v) {     e[++cnt] = (edge){v, head[u]};     head[u] = cnt;   }   int dfs(int u, int fa) {     vector<int> v;     int i;     for (i = head[u]; i; i = e[i].nt)       if (e[i].to != fa) v.push_back(dfs(e[i].to, u) + 1);     sort(v.begin(), v.end());     for (i = v.size() - 1; i > 0; i--)       if (v[i] + v[i - 1] > k)         ans++;       else         break;     return v.size() == 0 ? 0 : v[i];   }   int main() {     n = read();     k = read();     for (int i = 1; i < n; i++) {       x = read();       y = read();       add(x, y);       add(y, x);       du[x]++;       du[y]++;       if (du[x] > 1) rt = x;       if (du[y] > 1) rt = y;     }     dfs(rt, 0);     cout << ans + 1;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   int main() {     ios_base ::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int n, m;     cin >> n >> m;     long long a[n + 1];     for (int i = 1; i <= n; i++) cin >> a[i];     long long v, x, add = 0, y, q;     int t;     while (m--) {       cin >> t;       if (t == 1) {         cin >> v >> x;         a[v] = x - add;       } else if (t == 2) {         cin >> y;         add += y;       } else {         cin >> q;         cout << a[q] + add <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   double areaa(int x1, int x2, int x3, int y1, int y2, int y3);   int gcd(int x, int y);   int lcm(int x, int y);   int egcd(int a, int b, int& x, int& y);   vector<int> prime_possible_factors(int n);   vector<int> primes_included(int n, int m);   map<int, int> factor(int N);   bool isPrime(int N);   int charType(char c);   double areaa(int x1, int x2, int x3, int y1, int y2, int y3) {     double area = abs((x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2)) / 4.0);     return area;   }   int gcd(int x, int y) { return y == 0 ? x : gcd(y, x % y); }   int lcm(int x, int y) { return (x * y / gcd(x, y)); }   int egcd(int a, int b, int& x, int& y) {     if (b == 0) {       x = 1;       y = 0;       return a;     } else {       int d = egcd(b, a % b, x, y);       x -= a / b * y;       swap(x, y);       return d;     }   }   vector<int> prime_possible_factors(int n) {     bool* isPrime = new bool[n];     for (int i = 0; i < n; i++) {       isPrime[i] = true;     }     vector<int> primes;     for (int i = 2; i * i <= n; ++i) {       if (isPrime[i]) {         primes.push_back(i);         for (int j = i; j < n; j += i) isPrime[j] = false;       }     }     return primes;   }   vector<int> primes_included(int n, int m) {     bool* isPrime = new bool[m];     for (int i = 0; i < m; i++) {       isPrime[i] = true;     }     vector<int> primes;     for (int i = 2; i < m; ++i) {       if (isPrime[i]) {         if (i >= n) primes.push_back(i);         for (int j = i; j < m; j += i) isPrime[j] = false;       }     }     return primes;   }   map<int, int> factor(int N) {     vector<int> primes;     primes = primes_included(0, N);     map<int, int> factors;     for (int i = 0; i < primes.size(); ++i) {       int prime = primes[i], power = 0;       while (N % prime == 0) {         power++;         N /= prime;       }       factors[prime] = power;     }     return factors;   }   bool isPrime(int N) {     vector<int> check = prime_possible_factors(N);     for (int i = 0; i < check.size(); i++) {       if (N % check[i] == 0) {         return false;       }     }     return true;   }   int main() {     int T;     long long int n, s, t;     cin >> T;     int i = 0;     for (i; i < T; i++) {       cin >> n >> s >> t;       cout << max(n - s, n - t) + 1 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string s, t, tmp1, tmp2;   vector<int> ans;   int cnt, n;   int main() {     cin >> n;     cin >> s >> t;     tmp1 = s, tmp2 = t;     sort(tmp1.begin(), tmp1.end());     sort(tmp2.begin(), tmp2.end());     if (tmp1 != tmp2) return cout << -1, 0;     if (s[0] == t[n - 1]) cnt++;     while (cnt != n) {       int i;       for (i = cnt; i < n; i++) {         if (s[i] == t[n - cnt - 1]) break;       }       ans.push_back(n);       for (int j = 0; j < n / 2; j++) swap(s[j], s[n - j - 1]);       s = s.substr(n - i, i) + s.substr(0, n - i);       for (int j = 0; j < i / 2; j++) swap(s[j], s[i - j - 1]);       s = s.substr(n - 1, 1) + s.substr(0, n - 1);       ans.push_back(i);       ans.push_back(1);       cnt++;     }     cout << ans.size() << endl;     for (int i = 0; i < (int)ans.size(); i++) cout << ans[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 2;   int a[N], b[N];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     for (int i = 0; i < (int)n; i++) cin >> a[i], b[i + 1] += b[i] + a[i];     int t = 0;     for (int i = 0; i < (int)n; i++) {       for (int j = 0; j < (int)i + 1; j++) {         if (b[i + 1] - b[j] > 100 * (i - j + 1)) t = max(t, i - j + 1);       }     }     cout << t <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int MIN(int a, int b) { return a < b ? a : b; };   int MAX(int a, int b) { return a > b ? a : b; };   int gcd(int a, int b) {     if (b == 0)       return a;     else       return gcd(b, a % b);   }   int n, m, q;   int h;   int a[20] = {2,  4,  3,  9,  5,  25, 7,  49, 11, 13,                17, 19, 23, 29, 31, 37, 41, 43, 47, 53};   int main() {     int i, j, x, y, T, num, t;     string str;     t = num = 0;     for (i = 0; i < 20; i++) {       cout << a[i] << endl;       cin >> str;       num++;       x = a[i];       if (str ==  yes ) {         t++;       }       if (t > 1) break;     }     if (i == 20)       cout <<  prime n ;     else       cout <<  composite n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   struct edge {     int from;     int to;     int next;   } E[500005 << 1];   int head[100005];   int deg[100005];   int tmp[500005];   int used[500005 << 1];   int size = 1;   void add_edge(int u, int v) {     size++;     E[size].from = u;     E[size].to = v;     E[size].next = head[u];     head[u] = size;   }   stack<int> s, ans;   void euler() {     s.push(1);     while (!s.empty()) {       int x = s.top();       int i = head[x];       while (i != 0 && used[i] == 1) i = E[i].next;       if (i != 0) {         s.push(E[i].to);         used[i] = used[i ^ 1] = 1;         head[x] = E[i].next;       } else {         s.pop();         ans.push(x);       }     }   }   int main() {     int u, v;     scanf( %d %d , &n, &m);     for (int i = 1; i <= m; i++) {       scanf( %d %d , &u, &v);       add_edge(u, v);       add_edge(v, u);       deg[u]++;       deg[v]++;     }     int pre = 0;     int cnt = 0;     for (int i = 1; i <= n; i++) {       if (deg[i] % 2 == 1) {         if (pre != 0) {           add_edge(pre, i);           add_edge(i, pre);           pre = 0;         } else           pre = i;       }     }     if (((size - 1) / 2) % 2 == 1) {       add_edge(1, 1);       size++;     }     euler();     printf( %d n , (size - 1) / 2);     int ptr = 0;     while (!ans.empty()) {       tmp[++ptr] = ans.top();       ans.pop();     }     for (int i = 1; i <= ptr - 1; i++) {       if (i & 1)         printf( %d %d n , tmp[i], tmp[i + 1]);       else         printf( %d %d n , tmp[i + 1], tmp[i]);     }   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1123456;   const int MAXINT = 2147483098;   const long long MAXLL = 9223372036854775258LL;   set<pair<int, int> > s;   int ans[MAXN];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n, m, d, pos = 0, mx = 0;     cin >> n >> m >> d;     for (int i = 1; i <= n; ++i) {       int a;       cin >> a;       s.insert(make_pair(a, i));     }     for (int i = 1; i <= n; ++i) {       if (!s.size()) break;       ans[s.begin()->second] = i;       mx = i;       long long val = s.begin()->first;       s.erase(s.begin());       while (1) {         if (!s.size()) break;         auto it = s.lower_bound(make_pair(val + d + 1, 0LL));         if (it == s.end()) break;         ans[it->second] = i;         val = it->first;         s.erase(it);       }     }     cout << mx <<   n ;     for (int i = 1; i <= n; ++i) cout << ans[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   char s[200005];   using namespace std;   int main() {     int n, k;     cin >> n >> k;     getchar();     cin >> s;     int maxn1 = 0;     for (int i = 0; i < 26; i++) {       char t =  a  + i;       int sum1 = 0;       int maxn = 0;       for (int j = 0; j < n; j++) {         if (s[j] == t && s[j + 1] == t)           sum1++;         else if (s[j] == t && s[j + 1] != t) {           sum1++;           maxn += sum1 / k;           sum1 = 0;         }       }       maxn1 = max(maxn, maxn1);     }     cout << maxn1 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 200010;   vector<int> G[maxn];   int n, k;   int u, v;   int siz[maxn], dep[maxn];   int val[maxn], fa[maxn];   void dfs(int x, int d) {     dep[x] = d;     siz[x] = 1;     for (int i = 0; i < G[x].size(); ++i) {       int to = G[x][i];       if (to == fa[x]) continue;       fa[to] = x;       dfs(to, d + 1);       siz[x] += siz[to];     }     val[x] = siz[x] - dep[x];   }   int main() {     scanf( %d%d , &n, &k);     for (int i = 1; i < n; ++i) {       scanf( %d%d , &u, &v);       G[u].push_back(v);       G[v].push_back(u);     }     dfs(1, 1);     sort(val + 1, val + 1 + n);     long long ans = 0;     for (int i = k + 1; i <= n; ++i) ans += (long long)val[i];     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, k;     cin >> n >> k;     pair<long long, long long> a[n];     for (long long i = 0; i < n; i++) {       cin >> a[i].first;       a[i].second = i;     }     sort(a, a + n);     queue<long long> q;     set<long long> s;     bool turn = true;     long long ans[n];     for (long long i = n - 1; i >= 0; i--) {       q.push(a[i].second);       s.insert(i);     }     while (!q.empty()) {       long long top = q.front();       q.pop();       if (s.find(top) == s.end()) continue;       vector<long long> v;       long long count = 0;       for (auto itr = prev(s.find(top)); count < k && itr != prev(s.begin());            itr--) {         v.push_back(*itr);         count++;       }       count = 0;       for (auto itr = s.find(top); count <= k && itr != s.end(); itr++) {         v.push_back(*itr);         count++;       }       for (long long i = 0; i < v.size(); i++) {         s.erase(v[i]);         ans[v[i]] = turn;       }       turn = !turn;     }     for (long long i = 0; i < n; i++) {       if (ans[i])         cout << 1;       else         cout << 2;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     int n, m;     cin >> n >> m;     vector<pair<string, int>> a(n);     int c = 1;     for (auto &t : a) {       cin >> t.first;       t.second = c++;     }     for (auto &t : a) {       for (int i = 1; i < m; i += 2) {         t.first[i] =  z  - t.first[i] +  a ;       }     }     sort(a.begin(), a.end());     for (auto t : a) {       cout << t.second <<    ;     }   }   int main() {     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> g[100005];   double dfs(int i, int ult) {     double ans = 0;     int c = g[i].size() - (i != 1);     for (int j = 0; j < g[i].size(); j++) {       if (g[i][j] != ult) {         ans += (dfs(g[i][j], i) + 1.0) / c;       }     }     return ans;   }   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i < n; i++) {       int a, b;       scanf( %d %d , &a, &b);       g[a].push_back(b);       g[b].push_back(a);     }     printf( %.15lf n , dfs(1, 0));   }


#include <bits/stdc++.h>   using namespace std;   const long long MXN = 2e5 + 10;   const long long LOG = 21;   const long long MXM = (1LL << LOG);   const long long INF = 1e9;   int n, m, ans;   int dp[MXN], ps[MXN], Best[LOG][MXM];   string S[MXN];   int Cost(int i, int j) {     for (int x = m; x; x--) {       if (S[i].substr(m - x + 1, x) == S[j].substr(1, x)) {         return m - x;       }     }     return m;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     memset(dp, 31, sizeof dp), memset(Best, 31, sizeof Best);     cin >> n, ans = INF;     for (int i = 1; i <= n; i++) {       cin >> S[i], m = (long long)S[i].size();       S[i] =  0  + S[i];     }     ps[1] = dp[1] = m;     for (int i = 2; i <= n; i++) ps[i] = ps[i - 1] + Cost(i - 1, i);     for (int i = 2; i <= n; i++) {       dp[i] = ps[i - 1] + m;       long long mask = 0;       for (int x = 0; x <= m; x++) {         mask = mask * 2 + (S[i][x] -  0 );         if (Best[x][mask] < INF) {           dp[i] = min(dp[i], ps[i - 1] + m - x + Best[x][mask]);         }       }       mask = 0;       for (int x = 0; x <= m; x++) {         if (x && S[i - 1][m - x + 1] ==  1 ) {           mask += (1LL << (x - 1));         }         Best[x][mask] = min(Best[x][mask], dp[i] - ps[i]);       }     }     for (int i = 1; i <= n; i++) ans = min(ans, dp[i] + ps[n] - ps[i]);     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> idb[100002];   int dp[301];   int main() {     int n, m, s, e;     cin >> n >> m >> s >> e;     vector<int> a(n);     for (int i = 0; i < n; i++) scanf( %d , &a[i]);     for (int i = 0; i < m; i++) {       int b;       scanf( %d , &b);       idb[b].push_back(i);     }     int ans = 0;     memset(dp, 127, sizeof dp);     dp[0] = 0;     for (int i = 0; i < n; i++) {       for (int j = 300; j >= 1; j--) {         int pos2array = dp[j - 1];         int nextPos = lower_bound(idb[a[i]].begin(), idb[a[i]].end(), pos2array) -                       idb[a[i]].begin();         if (nextPos == idb[a[i]].size()) continue;         int abspos2ar = idb[a[i]][nextPos];         dp[j] = min(dp[j], abspos2ar + 1);         if (i + 1 + dp[j] + j * e <= s) ans = max(ans, j);       }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 4e5;   int T, n, m, k, f[N + 5], ans[N + 5];   struct People {     int a, r, d, u, id;   } p[N + 5];   struct Info {     int opt, l, r;     Info() {}     Info(int opt, int l, int r) : opt(opt), l(l), r(r) {}   };   template <int MAX>   struct BIT {     static const int N = MAX;     int b[N + 5];     void clear() { fill(b + 1, b + N + 1, 0); }     void modify(int x, int v) {       for (; x <= N; x += x & -x) b[x] += v;     }     int query(int x) {       int ans = 0;       for (; x > 0; x ^= x & -x) ans += b[x];       return ans;     }     int query(int l, int r) { return query(r) - query(l - 1); }   };   template <int MAX>   struct SegmentTree {     static const int N = MAX << 2;     int val[N + 5];     void clear() { fill(val + 1, val + N + 1, -1); }     void modify(int p, int l, int r, int x, int v) {       if (l == r) {         val[p] = max(val[p], v);         return;       }       int mid = (l + r) >> 1;       if (x <= mid) {         modify((p << 1), l, mid, x, v);       } else {         modify((p << 1 | 1), mid + 1, r, x, v);       }       val[p] = max(val[(p << 1)], val[(p << 1 | 1)]);     }     int query(int p, int l, int r, int x, int y) {       if (x == l && r == y) return val[p];       int mid = (l + r) >> 1;       if (y <= mid) {         return query((p << 1), l, mid, x, y);       } else if (x > mid) {         return query((p << 1 | 1), mid + 1, r, x, y);       } else {         return max(query((p << 1), l, mid, x, mid),                    query((p << 1 | 1), mid + 1, r, mid + 1, y));       }     }   };   BIT<N> bit;   SegmentTree<N> seg;   vector<Info> que[N + 5];   void disc() {     vector<int> u, v;     for (int i = 1; i <= n; i++) {       u.push_back(p[i].r);       v.push_back(p[i].a);       v.push_back(p[i].d);       v.push_back(p[i].u);     }     sort(u.begin(), u.end());     sort(v.begin(), v.end());     u.erase(unique(u.begin(), u.end()), u.end());     v.erase(unique(v.begin(), v.end()), v.end());     for (int i = 1; i <= n; i++) {       p[i].r = lower_bound(u.begin(), u.end(), p[i].r) - u.begin() + 1;       p[i].a = lower_bound(v.begin(), v.end(), p[i].a) - v.begin() + 1;       p[i].d = lower_bound(v.begin(), v.end(), p[i].d) - v.begin() + 1;       p[i].u = lower_bound(v.begin(), v.end(), p[i].u) - v.begin() + 1;     }   }   void calc() {     sort(p + 1, p + n + 1,          [](const People &x, const People &y) { return x.r < y.r; });     bit.clear();     for (int i = 1; i <= n;) {       int j = i - 1;       for (; j < n && p[j + 1].r == p[i].r; j++, bit.modify(p[j].a, 1))         ;       for (int k = i; k <= j; k++) {         f[p[k].id] = bit.query(p[k].d, p[k].u);       }       i = j + 1;     }     sort(p + 1, p + n + 1,          [](const People &x, const People &y) { return x.id < y.id; });   }   void solve() {     scanf( %d%d , &n, &k);     for (int i = 1; i <= n; i++) scanf( %d , &p[i].r);     for (int i = 1; i <= n; i++) {       scanf( %d , &p[i].a);       p[i].d = p[i].a - k;       p[i].u = p[i].a + k;       p[i].id = i;     }     disc();     calc();     for (int i = 1; i <= n; i++) {       que[p[i].r].push_back(Info(0, p[i].a, f[i]));     }     scanf( %d , &m);     for (int u, v, i = 1; i <= m; i++) {       scanf( %d%d , &u, &v);       int l = max(p[u].d, p[v].d);       int r = min(p[u].u, p[v].u);       if (l > r) {         ans[i] = -1;       } else {         que[max(p[u].r, p[v].r)].push_back(Info(i, l, r));       }     }     seg.clear();     for (int i = n; i >= 1; i--) {       for (const auto &t : que[i]) {         if (t.opt == 0) {           seg.modify(1, 1, 3 * n, t.l, t.r);         } else {           ans[t.opt] = seg.query(1, 1, 3 * n, t.l, t.r);         }       }       que[i].clear();     }     for (int i = 1; i <= m; i++) printf( %d n , ans[i]);   }   int main() {     solve();     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   int n, K, m;   set<pair<int, int> > Set;   set<int> SS;   int O[524288];   struct Tree {     int K[524288 + 524288], M[524288 + 524288];     void UDT(int nd) { M[nd] = max(M[nd * 2], M[nd * 2 + 1]); }     void init(int nd, int b, int e) {       K[nd] = 0;       if (b == e) {         M[nd] = b;         return;       }       int m = (b + e) >> 1;       init(nd * 2, b, m);       init(nd * 2 + 1, m + 1, e);       UDT(nd);     }     void Add2(int nd, int x) {       M[nd] += x;       K[nd] += x;     }     void Spread(int nd) {       Add2(nd * 2, K[nd]);       Add2(nd * 2 + 1, K[nd]);       K[nd] = 0;     }     void Add(int nd, int b, int e, int s, int l, int x) {       if (s > l) return;       if (s <= b && e <= l) {         Add2(nd, x);         return;       }       Spread(nd);       int m = (b + e) >> 1;       if (s <= m) Add(nd * 2, b, m, s, l, x);       if (l > m) Add(nd * 2 + 1, m + 1, e, s, l, x);       UDT(nd);     }     int Max(int nd, int b, int e, int s, int l) {       if (s > l) return -99999999;       if (s <= b && e <= l) return M[nd];       Spread(nd);       int m = (b + e) >> 1, r = -99999999;       if (s <= m) r = max(r, Max(nd * 2, b, m, s, l));       if (l > m) r = max(r, Max(nd * 2 + 1, m + 1, e, s, l));       return r;     }   } T;   void Solve() {     int i;     for (i = 1; i < 524288; i++) O[i] = 1;     T.init(1, 0, 524288 - 1);     scanf( %d%d%d , &n, &K, &m);     for (i = 1; i <= m; i++) {       int x, y;       scanf( %d%d , &x, &y);       int t = abs(x - K) + y;       if (Set.find(pair<int, int>(x, y)) != Set.end()) {         Set.erase(pair<int, int>(x, y));         O[t]++;         if (O[t] == 1) SS.erase(t);         T.Add(1, 0, 524288 - 1, t, 524288 - 1, 1);       } else {         Set.insert(pair<int, int>(x, y));         O[t]--;         if (O[t] == 0) SS.insert(t);         T.Add(1, 0, 524288 - 1, t, 524288 - 1, -1);       }       if (SS.empty()) {         puts( 0 );         continue;       }       t = *SS.rbegin();       int t1 = T.Max(1, 0, 524288 - 1, 0, t);       int t2 = T.Max(1, 0, 524288 - 1, t, t);       printf( %d n , max(t + (t1 - t2) - n, 0));     }   }   int main() {     int TC = 1;     while (TC--) {       Solve();     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 5;   int a[maxn], b[maxn];   bool v[maxn];   int main() {     int n;     cin >> n;     a[0] = -1;     for (int i = 1; i <= n; ++i) {       cin >> a[i];       v[a[i]] = 1;       if (a[i] > a[i - 1])         b[i] = a[i - 1];       else         b[i] = -1;     }     int c = 0;     for (int i = 1; i <= n; ++i) {       if (b[i] == -1) {         while (v[c]) c++;         b[i] = c++;       }     }     for (int i = 1; i <= n; ++i) cout << b[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int isTandom(string s, int n) {     if (n > s.size() / 2) return 0;     for (int i = 0; i < n; i++)       if (s[i + n] !=     && s[i] != s[i + n]) return 0;     return 1;   }   int main() {     string s;     int k;     cin >> s >> k;     int len = s.size();     for (int i = 0; i < k; i++) s +=    ;     for (int i = s.size() / 2; i >= 1; i--)       for (int j = 0; j + i < s.size(); j++)         if (isTandom((s.substr(j, 2 * i)), i)) {           cout << 2 * i << endl;           return 0;         }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, i, x, y;     cin >> n;     long long a[n], b[n - 1], c[n - 2];     for (i = 0; i < n; i++) cin >> a[i];     sort(a, a + n);     for (i = 0; i < n - 1; i++) cin >> b[i];     sort(b, b + (n - 1));     for (i = 0; i < n - 2; i++) cin >> c[i];     sort(c, c + (n - 2));     for (i = 0; i < n; i++) {       if (a[i] != b[i]) {         x = a[i];         break;       }     }     for (i = 0; i < n - 1; i++) {       if (b[i] != c[i]) {         y = b[i];         break;       }     }     cout << x << endl;     cout << y << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, t, x, c, d, ch = 0, caser = 0, lol = 0, sum = 0, rating = -1,                        upper = 1e9, lower = -1e9;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> c >> d;       if (i == 0) {         if (d == 1)           lower = 1900;         else           upper = 1899;       } else {         if (d == 2) {           upper = min(upper, sum + 1899);         } else {           lower = max(lower, sum + 1900);         }       }       sum -= c;     }     if (upper == 1e9)       cout <<  Infinity n ;     else if (lower > upper)       cout <<  Impossible n ;     else       cout << upper - sum << endl;   }


#include <bits/stdc++.h>   using namespace std;   long long f[6][10010], b = 1;   int main() {     for (int i = 1; i <= 5; ++i)       for (int j = 1; j <= (i == 5 ? 1 : 10000); ++j) {         long long now = f[i - 1][j];         for (int k = 1; k <= j; ++k)           now += f[i - 1][min(now + j + 1, 10000ll)] + 1;         f[i][j] = now;       }     for (int i = 5, d; i >= 1; --i) {       long long now = 0;       printf( %lld  , min(b, 10000ll));       for (int j = 1; j <= min(b, 10000ll); ++j) {         now += f[i - 1][min(b + now, 10000ll)];         printf( %lld  , b + now);         ++now;       }       printf(  n );       fflush(stdout);       scanf( %d , &d);       if (d == -1)         break;       else {         now = 0;         for (int j = 1; j <= d; ++j) now += f[i - 1][min(b + now, 10000ll)] + 1;         b += now;       }     }   }


#include <bits/stdc++.h>   using namespace std;   bool kjg[100002];   int isi[100002];   long long dp[100002];   vector<int> adlis[100002], radlis[100002];   int rut, nvert, u, v;   void ruted(int x) {     kjg[x] = 1;     for (int i = 0; i < adlis[x].size(); i++) {       if (!kjg[adlis[x][i]]) {         radlis[x].push_back(adlis[x][i]);         ruted(adlis[x][i]);       }     }   }   long long rek(int x) {     if (radlis[x].size() == 0) {       return 0;     } else if (dp[x] != -1) {       return dp[x];     } else {       dp[x] = 0;       if (x != rut) {         isi[x]--;       }       int jum = 0;       vector<long long> cal;       cal.clear();       for (int i = 0; i < radlis[x].size(); i++) {         if (isi[radlis[x][i]] <= 1) continue;         if (rek(radlis[x][i]) > 0) {           cal.push_back(rek(radlis[x][i]));         }       }       for (int i = 0; i < radlis[x].size(); i++) {         jum += isi[radlis[x][i]];       }       sort(cal.begin(), cal.end());       if (cal.size() > 0) {         for (int i = cal.size() - 1; i >= 0; i--) {           dp[x] += (long long)cal[i];           dp[x] += 2LL;           isi[x]--;           if (isi[x] == 0) break;         }       }       if (isi[x] > 0) {         if (isi[x] < jum) {           dp[x] += 2LL * isi[x];           isi[x] = 0;         } else {           dp[x] += 2LL * jum;           isi[x] -= jum;         }       }       return dp[x];     }   }   int main() {     scanf( %d , &nvert);     for (int i = 0; i < nvert; i++) {       scanf( %d , &isi[i]);     }     for (int i = 0; i < nvert - 1; i++) {       scanf( %d%d , &u, &v);       u--;       v--;       adlis[u].push_back(v);       adlis[v].push_back(u);     }     scanf( %d , &rut);     rut--;     memset(kjg, 0, sizeof kjg);     ruted(rut);     memset(dp, -1, sizeof dp);     printf( %I64d n , rek(rut));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   int main() {     cin >> n;     if ((n % 2) == 0)       cout <<  home ;     else       cout <<  contest ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e6 + 7, M = 1e9 + 7;   vector<int> primes;   bool isp[N];   void sieve() {     fill(isp, isp + N, 1);     isp[0] = isp[1] = 0;     for (int i = 2; i * i < N; i++)       if (isp[i])         for (int j = i * i; j < N; j += i) isp[j] = 0;     for (int i = 2; i < N; i++)       if (isp[i]) primes.push_back(i);   }   vector<pair<int, int> > factorize(int x) {     vector<pair<int, int> > ans;     for (int i : primes) {       if (i * i > x) break;       int cnt = 0;       while (x % i == 0) cnt++, x /= i;       if (cnt) ans.push_back(make_pair(i, cnt));     }     if (x > 1) ans.push_back(make_pair(x, 1));     return ans;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     sieve();     int n;     cin >> n;     long long ans = 1;     map<int, int> fac;     map<int, int> cnt;     vector<vector<pair<int, int> > > factors;     int pp[n];     for (int i = 0; i < n; i++) cin >> pp[i];     sort(pp, pp + n);     reverse(pp, pp + n);     for (int i = 1; i <= n; i++) {       int p = pp[i - 1];       if (fac.count(p) == 0) {         ans = (ans * p) % M;         fac[p] = 1;         cnt[p] = 1;         vector<pair<int, int> > v;         v.push_back(make_pair(p, 1));         factors.push_back(v);       } else {         vector<pair<int, int> > pf = factorize(p - 1);         factors.push_back(pf);         for (auto pr : pf) {           int p = pr.first;           int e = pr.second;           int dif = e - fac[p];           if (dif < 0) continue;           if (dif == 0) {             cnt[p]++;             continue;           }           fac[p] += dif;           cnt[p] = 1;           for (int i = 0; i < dif; i++) ans = (ans * p) % M;         }       }     }     for (auto pf : factors) {       bool found = true;       for (auto pr : pf) {         int p = pr.first;         int e = pr.second;         int mx = fac[p];         assert(e <= mx);         if (e == mx && cnt[p] == 1) {           found = false;           break;         }       }       if (found) {         ans++;         break;       }     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> v[26];   int A[26], m;   void solve() {     string s;     cin >> s;     for (int i = 0; i < s.length(); i++) v[s[i] -  a ].push_back(i);     for (int i = 0; i < 26; i++) {       if (s.find(i +  a ) != string::npos) {         m = v[i][0] + 1;         for (int j = 1; j < (int)v[i].size(); j++)           m = max(m, v[i][j] - v[i][j - 1]);         m = max(m, (int)s.length() - v[i][(int)v[i].size() - 1]);         A[i] = m;       }     }     m = INT_MAX;     for (int i = 0; i < 26; i++) {       if (A[i] != 0) m = min(m, A[i]);     }     cout << m <<   n ;   }   signed main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t;     t = 1;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 5010, mod = 1LL * 1000 * 1000 * 1000 + 7;   long long dp[N][N], inv_fact[N], fact[N], n, k;   long long Pow(long long a, long long b) {     return b ? (b & 1 ? a : 1) % mod * Pow(a * a % mod, b >> 1) % mod : 1;   }   int C(int r, int n) {     if (r > n) return 0;     int num = 1;     for (int i = n; i >= n - r + 1; i--) num = 1LL * num * i % mod;     num = 1LL * num * inv_fact[r] % mod;     return num;   }   int main() {     ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);     fact[0] = 1;     for (int i = 1; i < N; i++) fact[i] = 1LL * fact[i - 1] * i % mod;     inv_fact[N - 1] = Pow(fact[N - 1], mod - 2);     for (int i = N - 2; i >= 0; i--)       inv_fact[i] = 1LL * inv_fact[i + 1] * (i + 1) % mod;     for (int i = 1; i < N; i++) dp[1][i] = 1;     for (int i = 2; i < N; i++)       for (int j = i; j < N; j++)         dp[i][j] = 1LL * (dp[i - 1][j - 1] + dp[i][j - 1]) % mod * i % mod;     cin >> n >> k;     long long ans = 0;     for (int r = 1; r <= min(k, n); r++) {       long long t = Pow(2, n - r);       t = 1LL * t * dp[r][k] % mod;       t = 1LL * t * C(r, n) % mod;       ans = (1LL * ans + t) % mod;     }     cout << ans <<   n ;     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   priority_queue<pair<long long int, int> > pq;   vector<pair<int, int> > vp;   map<long long int, int> mp, m;   const int N = 1e5 + 6;   long long int ans[N];   vector<int> v, v1;   set<long long int> s, s1;   int visit[N];   struct domingo {     int val, left, right;   } o[N];   bool used[102];   int main() {     int a, b, c, ct = 1;     cin >> a >> b >> c;     a = a % b;     a *= 10;     for (int i = 0; i < 1e5 + 5; i++) {       int x = a / b;       a %= b;       if (x == c) return cout << ct, 0;       a *= 10;       ct++;     }     cout << -1;   }


#include <bits/stdc++.h>   using namespace std;   const long long M = 1e9 + 7;   const long long N = 1e5 + 10;   const long long INF = 1e9 + 7;   vector<long long> fact(N), ifact(N);   long long gcd(long long x, long long y) {     if (y % x == 0) return x;     return gcd(y % x, x);   }   long long inv(long long x) {     long long res = 1;     long long b = M - 2;     while (b) {       if (b & 1) res = (res * x) % M;       x = (x * x) % M;       b >>= 1;     }     return res;   }   bool prime[1000006];   void SieveOfEratosthenes(long long n) {     for (long long p = 2; p * p <= n; p++) {       if (prime[p] == true) {         for (long long i = p * p; i <= n; i += p) prime[i] = false;       }     }   }   void init() {     fact[0] = 1;     for (long long i = 1; i < N; i++) fact[i] = (fact[i - 1] * i) % M;     ifact[(long long)2e5] = inv(fact[(long long)2e5]);     for (long long i = (long long)2e5 - 1; i >= 0; i--)       ifact[i] = (ifact[i + 1] * (i + 1)) % M;   }   long long ncr(long long n, long long r) {     if (r > n) return 0;     long long res = fact[n];     res = (res * ifact[r]) % M;     res = (res * ifact[n - r]) % M;     return res;   }   long long power(long long x, long long y, long long p) {     long long res = 1;     x = x % p;     while (y > 0) {       if (y & 1) res = (res * x) % p;       y = y >> 1;       x = (x * x) % p;     }     return res;   }   long long lowbit(long long x) {     for (long long i = 0;; i++) {       if (x & (1 << i)) return 1 << i;     }   }   string decimal_to_binary(long long n) {     long long t = 0;     long long tt = n;     while (tt > 0) {       t++;       tt /= 2;     }     bitset<32> s = bitset<32>(n);     string str =   ;     for (long long i = 0; i < s.size(); i++) {       str += s[i] +  0 ;     }     reverse(str.begin(), str.end());     return str;   }   bool checkPrime(long long x) {     if (x == 1) {       return false;     }     if (x <= 3) {       return true;     }     long long t = 2;     if (x % 2 == 0) {       return false;     }     t = 3;     for (t; t <= sqrt(x); t += 2) {       if (x % t == 0) {         return false;       }     }     return true;   }   vector<long long> primeDivisor(long long x) {     if (x <= 3) {       vector<long long> r = {x};       return r;     }     long long n = floor(sqrt(x));     vector<long long> res;     for (long long i = 2; i <= n; i++) {       if (x % i == 0) {         res.push_back(i);       }       while (x % i == 0) {         x = x / i;       }       if (x < 2) {         break;       }     }     if (x > 2) {       res.push_back(x);     }     return res;   }   struct comp {     bool operator()(const pair<long long, long long> &x,                     const pair<long long, long long> &y) {       return x.first < y.first;     }   };   void solve() {     int a, b, c;     cin >> a >> b >> c;     int ans = 0;     if (a) {       a--;       ans++;     }     if (b) {       b--;       ans++;     }     if (c) {       c--;       ans++;     }     if (c == 1) {       if (a && b) {         a--;         b--;         ans++;       }       if (a && c) {         a--;         c--;         ans++;       }       if (b && c) {         b--;         c--;         ans++;       }     } else {       if (a && c) {         a--;         c--;         ans++;       }       if (b && c) {         b--;         c--;         ans++;       }       if (a && b) {         a--;         b--;         ans++;       }     }     if (a && b && c) {       a--;       b--;       c--;       ans++;     }     cout << ans << endl;     return;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     long long t = 1;     cin >> t;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using vint = vector<long long>;   using pint = pair<long long, long long>;   using vpint = vector<pint>;   template <typename A, typename B>   inline void chmin(A& a, B b) {     if (a > b) a = b;   }   template <typename A, typename B>   inline void chmax(A& a, B b) {     if (a < b) a = b;   }   template <class A, class B>   ostream& operator<<(ostream& ost, const pair<A, B>& p) {     ost <<  {  << p.first <<  ,  << p.second <<  } ;     return ost;   }   template <class T>   ostream& operator<<(ostream& ost, const vector<T>& v) {     ost <<  { ;     for (long long i = 0; i < v.size(); i++) {       if (i) ost <<  , ;       ost << v[i];     }     ost <<  } ;     return ost;   }   inline long long topbit(unsigned long long x) {     return x ? 63 - __builtin_clzll(x) : -1;   }   inline long long popcount(unsigned long long x) {     return __builtin_popcountll(x);   }   inline long long parity(unsigned long long x) { return __builtin_parity(x); }   template <uint32_t mod>   struct ModInt {     uint32_t a;     ModInt& s(uint32_t vv) {       a = vv < mod ? vv : vv - mod;       return *this;     }     ModInt(int64_t x = 0) { s(x % mod + mod); }     ModInt& operator+=(const ModInt& x) { return s(a + x.a); }     ModInt& operator-=(const ModInt& x) { return s(a + mod - x.a); }     ModInt& operator*=(const ModInt& x) {       a = uint64_t(a) * x.a % mod;       return *this;     }     ModInt& operator/=(const ModInt& x) {       *this *= x.inv();       return *this;     }     ModInt operator+(const ModInt& x) const { return ModInt(*this) += x; }     ModInt operator-(const ModInt& x) const { return ModInt(*this) -= x; }     ModInt operator*(const ModInt& x) const { return ModInt(*this) *= x; }     ModInt operator/(const ModInt& x) const { return ModInt(*this) /= x; }     bool operator==(const ModInt& x) const { return a == x.a; }     bool operator!=(const ModInt& x) const { return a != x.a; }     bool operator<(const ModInt& x) const { return a < x.a; }     ModInt operator-() const { return ModInt() - *this; }     ModInt pow(int64_t n) const {       ModInt res(1), x(*this);       while (n) {         if (n & 1) res *= x;         x *= x;         n >>= 1;       }       return res;     }     ModInt inv() const { return pow(mod - 2); }   };   template <uint32_t mod>   istream& operator>>(istream& in, ModInt<mod>& a) {     return (in >> a.a);   }   template <uint32_t mod>   ostream& operator<<(ostream& out, const ModInt<mod>& a) {     return (out << a.a);   }   using mint = ModInt<10007>;   using mat = vector<vector<mint>>;   string S;   long long N;   mint dp[210][210][210];   mat matmul(const mat& A, const mat& B) {     mat C(A.size(), vector<mint>(A.size()));     for (long long i = 0; i < A.size(); i++) {       for (long long j = i; j < A.size(); j++) {         for (long long k = i; k <= j; k++) {           C[i][j] += A[i][k] * B[k][j];         }       }     }     return C;   }   mat matpow(mat A, long long k) {     mat ret(A.size(), vector<mint>(A.size()));     for (long long i = 0; i < (A.size()); i++) ret[i][i] = 1;     while (k) {       if (k & 1) ret = matmul(ret, A);       A = matmul(A, A);       k >>= 1;     }     return ret;   }   signed main() {     cin >> S >> N;     N += S.size();     for (long long i = 0; i < (S.size()); i++) dp[0][i][i] = 1;     for (long long i = 0; i < (S.size()); i++) dp[0][i][i + 1] = 1;     for (long long i = S.size() - 1; i >= 0; i--) {       for (long long j = i + 2; j <= S.size(); j++) {         for (long long k = 0; k < S.size(); k++) {           if (S[i] == S[j - 1]) {             dp[k][i][j] += dp[k][i + 1][j - 1];           } else {             if (k == 0) continue;             dp[k][i][j] += dp[k - 1][i + 1][j];             dp[k][i][j] += dp[k - 1][i][j - 1];           }         }       }     }     const long long X = S.size();     const long long Y = (S.size() + 1) / 2;     const long long Z = Y;     vector<vector<mint>> A(X + Y + Z, vector<mint>(X + Y + Z));     for (long long i = 0; i < (X); i++) {       A[i][i] = 24;       A[i][i + 1] = 1;     }     for (long long i = 0; i < (Y); i++) {       A[X + i][X + i] = 25;       if (i + 1 < Y) A[X + i][X + i + 1] = 1;       A[X + i][X + Y + i] = 1;     }     for (long long i = 0; i < (Z); i++) {       A[X + Y + i][X + Y + i] = 26;     }     mat C = matpow(A, (N + 1) / 2 - 1);     A = matmul(C, A);     mint ans = 0;     for (long long k = 0; k < S.size(); k++) {       long long l = (S.size() - k + 1) / 2;       ans += dp[k][0][S.size()] * A[X - k][X + Y + l - 1];       if ((S.size() - k) % 2 == 0 && N % 2) {         ans -= dp[k][0][S.size()] * C[X - k][X + l - 1];       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ld = long double;   using uint = unsigned int;   using ull = unsigned long long;   template <class T>   bool set_max(T &a, const T &b) {     if (a < b) {       a = b;       return true;     }     return false;   }   template <class T>   bool set_min(T &a, const T &b) {     if (a > b) {       a = b;       return true;     }     return false;   }   template <typename A, typename B>   string to_string(pair<A, B> p);   template <typename A, typename B, typename C>   string to_string(tuple<A, B, C> p);   template <typename A, typename B, typename C, typename D>   string to_string(tuple<A, B, C, D> p);   string to_string(const string &s) { return     + s +    ; }   string to_string(const char *s) { return to_string((string)s); }   string to_string(bool b) { return (b ?  true  :  false ); }   string to_string(vector<bool> v) {     bool first = true;     string res =  { ;     for (int i = 0; i < static_cast<int>(v.size()); i++) {       if (!first) {         res +=  ,  ;       }       first = false;       res += to_string(v[i]);     }     res +=  } ;     return res;   }   template <size_t N>   string to_string(bitset<N> v) {     string res =   ;     for (size_t i = 0; i < N; i++) {       res += static_cast<char>( 0  + v[i]);     }     return res;   }   template <typename A>   string to_string(A v) {     bool first = true;     string res =  { ;     for (const auto &x : v) {       if (!first) {         res +=  ,  ;       }       first = false;       res += to_string(x);     }     res +=  } ;     return res;   }   template <typename A, typename B>   string to_string(pair<A, B> p) {     return  (  + to_string(p.first) +  ,   + to_string(p.second) +  ) ;   }   template <typename A, typename B, typename C>   string to_string(tuple<A, B, C> p) {     return  (  + to_string(get<0>(p)) +  ,   + to_string(get<1>(p)) +  ,   +            to_string(get<2>(p)) +  ) ;   }   template <typename A, typename B, typename C, typename D>   string to_string(tuple<A, B, C, D> p) {     return  (  + to_string(get<0>(p)) +  ,   + to_string(get<1>(p)) +  ,   +            to_string(get<2>(p)) +  ,   + to_string(get<3>(p)) +  ) ;   }   void debug_out() { cerr << endl; }   template <typename Head, typename... Tail>   void debug_out(Head H, Tail... T) {     cerr <<     << to_string(H);     debug_out(T...);   }   const int N = 3e5 + 10;   const int MOD = 1e9 + 7;   const double eps = 1e-6;   const ll INF = 1e18;   const int inf = 1e9;   int a[N];   void solve() {     int n;     cin >> n;     int sum = 0;     for (int i = 1; i <= n; i++) {       cin >> a[i];       sum += a[i];     }     if (sum % n) {       cout <<  -1 n ;       return;     }     int avg = sum / n;     vector<tuple<int, int, int>> ops;     auto move = [&](int i, int j, int x) {       assert(a[i] >= x * i);       ops.emplace_back(i, j, x);       a[j] += x * i;       a[i] -= x * i;     };     for (int i = 2; i <= n; i++) {       int x = (i - a[i] % i) % i;       if (x > 0) {         move(1, i, x);       }       assert(a[i] % i == 0);       move(i, 1, a[i] / i);     }     for (int i = 2; i <= n; i++) {       move(1, i, avg);     }     cout << ops.size() <<   n ;     for (auto x : ops) {       cout << get<0>(x) <<     << get<1>(x) <<     << get<2>(x) <<   n ;     }   }   int main() {     ios::sync_with_stdio(false), cin.tie(nullptr);     int t = 1;     cin >> t;     while (t--) solve();   }


#include <bits/stdc++.h>   using namespace std;   const int M = 1e9 + 7;   const int MN = 1e6 + 6;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cout << fixed << setprecision(10);     long long n;     cin >> n;     long long p_x = 0, p_y = 0;     long long res = 1;     for (long long i = 0; i < n; ++i) {       long long n_x, n_y;       cin >> n_x >> n_y;       if (p_x == n_x && p_y == n_y) continue;       long long a = max(p_x, p_y);       long long b = min(n_x, n_y);       if (p_x == p_y) {         a++;       }       if (a <= b) res += b - a + 1;       p_x = n_x;       p_y = n_y;     }     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, a, i, j, mid, cnt = 0;     cin >> n;     for (i = 0; i < n; i++) {       for (j = 0; j < n; j++) {         cin >> a;         if (i == j) cnt = cnt + a;         if (i + j == n - 1) cnt = cnt + a;         if (i == n / 2) cnt = cnt + a;         if (j == n / 2) cnt = cnt + a;         if (i == n / 2 && j == n / 2) mid = a;       }     }     cout << cnt - (3 * mid) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     int i = n, j = n;     vector<int> a(2 * n + 1), b(2 * n + 1);     long long s = 0, x = 1, y = a[n] = b[n] = 1;     while (n--) {       int v;       cin >> v;       if (v < m)         x += a[++i]++, y += b[++j]++;       else if (v == m)         x += a[++i]++, y -= b[j], ++b[--j];       else         x -= a[i], ++a[--i], y -= b[j], ++b[--j];       s += x - y;     }     cout << s;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   T abs(T x) {     return x > 0 ? x : -x;   }   int n;   int m;   int mask[500][500][17];   int x[500], y[500], X[500], Y[500];   double xx[500], yy[500], XX[500], YY[500];   double vect(double x1, double y8687969, double x2, double y2) {     return x1 * y2 - x2 * y8687969;   }   int main() {     int n, m;     scanf( %d%d , &n, &m);     for (int i = 0; i < n; i++) scanf( %d%d , &x[i], &y[i]);     for (int i = 0; i < m; i++) scanf( %d%d , &X[i], &Y[i]);     double *cx, *cy, *CX, *CY;     for (int i = 0; i < n; i++) {       for (int j = i + 1; j < n; j++) {         xx[j] = x[j] - x[i], yy[j] = y[j] - y[i];       }       for (int j = 0; j < m; j++) {         XX[j] = X[j] - x[i];         YY[j] = Y[j] - y[i];       }       cx = xx + i;       cy = yy + i;       for (int j = i + 1; j < n; j++) {         cx++;         cy++;         CX = XX;         CY = YY;         int *ap = mask[i][j], *ar = mask[j][i];         int b = 0;         for (int k = 0; k < m; k++, CX++, CY++) {           if ((*cx) * (*CY) - (*cy) * (*CX) > 0)             (*ap) |= (1 << b);           else             (*ar) |= (1 << b);           b++;           if (b == 30) {             ap++;             ar++;             b = 0;           }         }       }     }     int ans = 0;     double *jx, *jy, *kx, *ky;     for (int i = 0; i < n; i++) {       for (int j = i + 1; j < n; j++) {         xx[j] = x[j] - x[i];         yy[j] = y[j] - y[i];       }       jx = xx + i;       jy = yy + i;       for (int j = i + 1; j < n; j++) {         jx++;         jy++;         kx = jx;         ky = jy;         for (int k = j + 1; k < n; k++) {           kx++;           ky++;           if ((*jx) * (*ky) - (*jy) * (*kx) > 0) {             ans++;             for (int l = 0; l < 17; l++)               if (mask[i][j][l] & mask[j][k][l] & mask[k][i][l]) {                 ans--;                 break;               }           } else {             ans++;             for (int l = 0; l < 17; l++)               if (mask[i][k][l] & mask[k][j][l] & mask[j][i][l]) {                 ans--;                 break;               }           }         }       }     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, k;   string s;   int main() {     cin >> n >> k >> s;     int del = (n - k) / 2;     stack<int> st;     for (char ch : s) {       if (ch ==  ( ) {         if (del) {           st.push(1);           del--;         } else {           st.push(0);           putchar( ( );         }       } else {         int v = st.top();         st.pop();         if (v == 0) putchar( ) );       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6 + 4;   int n, ans, ar[maxn], flag[maxn], dp[maxn];   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> n;     for (int i = 0; i < n; i++) {       cin >> ar[i];     }     for (int i = 0; i < maxn; i++) dp[i] = 1;     for (int i = n - 1; i >= 0; i--) {       int mx = 0;       for (int j = 2 * ar[i]; j < maxn; j += ar[i]) {         if (flag[j]) mx = max(dp[j], mx);       }       dp[ar[i]] = mx + 1;       flag[ar[i]] = 1;       ans = max(ans, mx + 1);     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1.01e9;   const double PI = acos(-1);   bool eq(double A, double B) { return abs(A - B) < 1e-9; }   bool ls(double A, double B) { return A < B && !eq(A, B); }   bool le(double A, double B) { return A < B || eq(A, B); }   struct pt {     double x, y, id;     pt() {}     pt(double xx, double yy) : x(xx), y(yy) {}     pt operator+(pt A) { return pt(x + A.x, y + A.y); }     pt operator-(pt A) { return pt(x - A.x, y - A.y); }     pt operator*(double k) { return pt(x * k, y * k); }     pt operator/(double k) {       assert(abs(k) > 1e-20);       return pt(x / k, y / k);     }     double operator*(pt A) { return x * A.y - y * A.x; }     double operator%(pt A) { return x * A.x + y * A.y; }     bool operator==(pt A) { return eq(x, A.x) && eq(y, A.y); }     bool operator!=(pt A) { return !eq(x, A.x) || !eq(y, A.y); }     double len() { return sqrt(x * x + y * y); }     double len2() { return x * x + y * y; }     pt rotate() { return pt(-y, x); }     pt norm() { return (*this) / len(); }     bool operator<(pt A) { return x < A.x || (eq(x, A.x) && ls(y, A.y)); }     void read() { scanf( %lf%lf , &x, &y); }     void Epr() { cerr <<  x y:   << x <<     << y << endl; }   };   struct Line {     pt O, v;     Line(pt A, pt B) : O(A), v((B - A).norm()) {}     pt operator*(Line l) {       pt u = l.v.rotate();       double t = (l.O - O) % u / (v % u);       return O + v * t;     }   };   int main() {     int n, q;     scanf( %d%d , &n, &q);     vector<pt> p(n);     for (int i = 0; i < n; i++) {       p[i].read();     }     reverse((p).begin(), p.end());     int idMn = 0;     int idMx = 0;     for (int i = 0; i < n; i++) {       if (p[i] < p[idMn]) {         idMn = i;       }       if (p[idMx] < p[i]) {         idMx = i;       }     }     vector<double> tr(n);     vector<double> prefArea(n + 1);     auto getTrap = [&](pt A, pt B) { return (A.x - B.x) * (A.y + B.y) / 2; };     for (int i = 0; i < n; i++) {       tr[i] = getTrap(p[i], p[(i + 1) % n]);       prefArea[i + 1] = prefArea[i] + tr[i];     }     for (int i = 0; i < n; i++) p[i].id = i;     vector<pt> part[2];     for (int tt = 0; tt < 2; tt++) {       for (int i = idMn; i != idMx; i = (i + 1) % n) {         part[tt].push_back(p[i]);       }       part[tt].push_back(p[idMx]);       swap(idMn, idMx);     }     auto getFarPoint = [&](pt v) {       int where = 0;       int tt;       if (v.y < 0) {         tt = 0;       } else {         tt = 1;       }       int l = 0;       int r = part[tt].size() - 1;       while (r - l > 3) {         int m1 = (l + l + r) / 3;         int m2 = (l + r + r) / 3;         if (part[tt][m1] % v > part[tt][m2] % v) {           r = m2;         } else {           l = m1;         }       }       for (int i = l; i <= r; i++) {         if (part[tt][i] % v > p[where] % v) {           where = part[tt][i].id;         }       }       return where;     };     auto getSegArea = [&](int l, int r) {       l %= n;       r %= n;       if (l <= r) {         return prefArea[r] - prefArea[l];       }       return prefArea[n] - prefArea[l] + prefArea[r];     };     auto getArea = [&](pt O, double ang) {       pt v(cos(ang), sin(ang));       pt u = v.rotate();       int p1 = getFarPoint(u);       int p2 = getFarPoint(u * -1);       int ret[2];       for (int tt = 0; tt < 2; tt++) {         int l = p2;         int r = p1;         assert(l != r);         if (r < l) {           r += n;         }         while (r - l > 1) {           if ((p[(l + r) / 2 % n] - O) * v > 0) {             l = (l + r) / 2;           } else {             r = (l + r) / 2;           }         }         ret[tt] = l;         v = v * -1;         swap(p1, p2);       }       pt G1 = Line(p[ret[0] % n], p[(ret[0] + 1) % n]) * Line(O, O + v);       pt G2 = Line(p[ret[1] % n], p[(ret[1] + 1) % n]) * Line(O, O + v);       double res = 0;       res += getSegArea((ret[0] + 1) % n, ret[1]);       res += getTrap(p[ret[1] % n], G2);       res += getTrap(G2, G1);       res += getTrap(G1, p[(ret[0] + 1) % n]);       return res;     };     for (int tt = 0; tt < q; tt++) {       pt O;       O.read();       double l, r;       double res = getArea(O, 0);       if (res * 2 < prefArea.back()) {         l = 0;         r = PI;       } else {         l = PI;         r = PI * 2;       }       for (int it = 0; it < 40; it++) {         double tmp = getArea(O, (l + r) / 2);         if (tmp * 2 < prefArea.back()) {           l = (l + r) / 2;         } else {           r = (l + r) / 2;         }       }       double ang = (l + r) / 2;       if (ang > PI) {         ang -= PI;       }       printf( %.17f n , ang);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, t;   int ult, casas;   string s;   int solve(int k) {     int u = -1;     int acc = k;     for (int i = 0; i < n; i++)       if (s[i] ==  S ) {         acc++;         if (acc >= casas) {           u = i;           break;         }       }     if (u == -1) return 2000000000;     u = max(u, ult);     acc = k;     int last = 2000000000;     int t = 1, need = 0;     int ans = 2000000000;     for (int i = 0; i < n; i++) {       if (s[i] ==  H ) {         if (acc) {           acc--;           if (i == ult && need == 0) ans = min(ans, t);         } else {           last = min(last, i);           need++;         }         t++;       } else if (s[i] ==  S ) {         acc++;         if (need && acc >= need) {           ans = min(ans, t + 2 * (u - i) + (i - last));           acc -= need;           need = 0;           if (i >= ult) {             t += (i - last);             ans = min(ans, t);             return ans;           } else             t += (2 * (i - last)) + 1;           last = 2000000000;         } else           t++;       } else         t++;     }     return ans;   }   int main() {     cin >> n >> t;     cin >> s;     casas = 0;     ult = -1;     for (int i = 0; i < n; i++)       if (s[i] ==  H ) casas++, ult = max(ult, i);     int ini = 0, fim = casas;     if (solve(fim) > t) {       printf( -1 n );       return 0;     }     while (ini < fim) {       int mid = (ini + fim) / 2;       if (solve(mid) <= t)         fim = mid;       else         ini = mid + 1;     }     cout << ini << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const bool ready = []() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout << fixed << setprecision(12);     return true;   }();   const double PI = acos(-1);   using ll = long long;   using pii = pair<ll, ll>;   using pdd = pair<double, double>;   using vd = vector<double>;   using vb = vector<bool>;   using vi = vector<ll>;   using vvi = vector<vi>;   using vs = vector<string>;   void solve() {     ll n;     cin >> n;     ;     ll m;     cin >> m;     ;     vb sx(n + 1);     vb sy(n + 1);     for (ll i = 0; i < m; i++) {       ll x;       cin >> x;       ;       ll y;       cin >> y;       ;       sx[x] = true;       sy[y] = true;     }     ll ans = 0;     for (ll i = 2; i < n / 2 + 1; i++) {       if (!sy[n - i + 1]) ans++;       if (!sy[i]) ans++;       if (!sx[n - i + 1]) ans++;       if (!sx[i]) ans++;     }     if (n & 1) {       if ((!sx[n / 2 + 1]) || (!sy[n / 2 + 1])) ans++;     }     cout << ans << endl;   }   signed main() { solve(); }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   T id(T b) {     return b;   };   template <class It>   bool all(It f, It l) {     return std::all_of(f, l, id<bool>);   }   template <class It>   bool any(It f, It l) {     return std::any_of(f, l, id<bool>);   }   const int MAX_N = 2000, MAX_A = 1000000;   int n, k, s;   int a[MAX_N];   int main() {     cin >> k;     s = a[0] = -1;     n = 1;     while (s - n + 1 != k) {       a[n] = min(k - (s - n), MAX_A);       s += a[n];       n++;     }     cout << n << endl;     for (int i = 0; i < n; i++) cout << a[i] <<    n [i + 1 == n];     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int arr[1007];   int main() {     char c;     int t = 3;     while (t--) {       scanf(  %c , &c);       char temp;       scanf( %c , &temp);       char d;       scanf( %c , &d);       if (temp ==  > ) {         arr[c]++;         arr[d]--;       } else {         arr[c]--;         arr[d]++;       }     }     int flag1 = 0;     char x, y, z;     int flag2 = 0;     int flag3 = 0;     for (int i =  A ; i <=  C ; i++) {       if (arr[i] == 2) {         flag1 = 1;         x = (char)i;       }       if (arr[i] == 0) {         flag2 = 1;         y = (char)i;       }       if (arr[i] == -2) {         flag3 = 1;         z = (char)i;       }     }     if (flag1 && flag2 && flag3) {       cout << z << y << x << endl;     } else       puts( Impossible );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<int> q(3 * n + 1);     for (int i = 0; i < 3 * n; i++) {       int a;       cin >> a;       q[a] = i;     }     vector<vector<int>> v(n, vector<int>(3));     for (int i = 0; i < n; i++) {       for (int j = 0; j < 3; j++) {         cin >> v[i][j];       }     }     int is;     cin >> is;     int team;     int ind;     for (int i = 0; i < n; i++) {       for (int j = 0; j < 3; j++) {         if (v[i][j] == is) {           team = i;           ind = j;         }       }     }     int m = 1e9;     for (int i = 0; i < 3; i++) {       m = min(m, q[v[team][i]]);     }     if (q[is] == m) {       vector<int> ans;       vector<int> dop;       int mi = 1e9;       for (int i = 0; i < 3; i++) {         if (v[team][i] < mi && i != ind) mi = v[team][i];       }       ans.push_back(mi);       mi = 0;       for (int i = 0; i < 3; i++) {         if (v[team][i] > mi && i != ind) mi = v[team][i];       }       ans.push_back(mi);       for (int i = 0; i < team; i++) {         for (int j = 0; j < 3; j++) {           if (v[i][j] < mi)             ans.push_back(v[i][j]);           else             dop.push_back(v[i][j]);         }       }       sort(ans.begin(), ans.end());       for (int i = team + 1; i < n; i++) {         for (int j = 0; j < 3; j++) {           dop.push_back(v[i][j]);         }       }       sort(dop.begin(), dop.end());       for (int i = 0; i < ans.size(); i++) {         cout << ans[i] <<    ;       }       for (int i = 0; i < dop.size(); i++) {         cout << dop[i] <<    ;       }     } else {       for (int i = 1; i <= 3 * n; i++) {         if (i != is) {           cout << i <<    ;         }       }     }   }


#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 max(long long a, long long b) { return (a > b ? a : b); }   void printa(long long arr[], long long n) {     for (long long i = 0; i < n; i++) {       cout << arr[i] <<    ;     }     cout <<   n ;   }   void printv(vector<long long> v) {     for (long long i = 0; i < v.size(); i++) {       cout << v[i] <<    ;     }     cout <<   n ;   }   void printset(set<long long> s) {     for (auto x : s) {       cout << x <<    ;     }     cout <<   n ;   }   void printmset(multiset<long long> s) {     for (auto x : s) {       cout << x <<    ;     }     cout <<   n ;   }   void printmgset(multiset<long long, greater<long long>> s) {     for (auto x : s) {       cout << x <<    ;     }     cout <<   n ;   }   const long long inf = 1e18;   const int32_t M = 1e9 + 7;   const int32_t MM = 998244353;   long long fact(long long n) { return (n == 1 || n == 0) ? 1 : n * fact(n - 1); }   const long long N = 1e5 + 1;   void solve() {     long long n;     cin >> n;     vector<long long> v(n);     for (long long i = 0; i < (n); ++i) {       cin >> v[i];     }     long long x, f;     cin >> x >> f;     long long c = 0;     long long idk = 0;     for (long long i = 0; i < (n); ++i) {       if (v[i] > x) {         idk += ((v[i] - x) / (x + f) + ((v[i] - x) % (x + f) > 0));       }     }     cout << idk * f <<   n ;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long t = 1;     while (t--) {       solve();     }     cerr <<   nTime elapsed:   << 1000 * clock() / CLOCKS_PER_SEC <<  ms n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 7;   int n, m, x[N], y[N], num[N], val[N], dp[2][N], cnt;   vector<int> adj[N];   bool vis[N];   void DFS(int u) {     vis[u] = true;     for (int i = 0; i < (int)adj[u].size(); ++i) {       int v = adj[u][i];       if (vis[v] == false) DFS(v);     }     num[u] = cnt;     val[cnt--] = u;   }   bool Check(int k) {     for (int i = 1; i <= n; ++i) adj[i].clear();     for (int i = 1; i <= k; ++i) adj[x[i]].push_back(y[i]);     for (int i = 1; i <= n; ++i) num[i] = 0, vis[i] = false;     cnt = n;     for (int i = 1; i <= n; ++i)       if (vis[i] == false) DFS(i);     memset(dp, 0, sizeof dp);     for (int u = 1; u <= n; ++u) {       for (int i = 0; i < (int)adj[val[u]].size(); ++i) {         int v = adj[val[u]][i];         dp[0][v] = max(dp[0][v], dp[0][val[u]] + 1);       }     }     for (int u = n; u >= 1; --u) {       for (int i = 0; i < (int)adj[val[u]].size(); ++i) {         int v = adj[val[u]][i];         dp[1][val[u]] = max(dp[1][val[u]], dp[1][v] + 1);       }     }     for (int i = 1; i <= n; ++i)       if (dp[0][i] + 1 + dp[1][i] != n) return false;     return true;   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= m; ++i) scanf( %d%d , &x[i], &y[i]);     int l = 1, r = m, res = -1;     while (l <= r) {       int mid = (l + r) >> 1;       if (Check(mid)) {         res = mid;         r = mid - 1;       } else         l = mid + 1;     }     printf( %d , res);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     scanf( %d %d , &n, &m);     vector<vector<int>> x(m + 1, vector<int>(n + 1));     for (int i = 1; i <= n; i++) {       int k;       scanf( %d , &k);       for (int j = 1; j <= m; j++) {         x[j][i] = x[j][i - 1];         if (j == k) {           x[j][i] += 1;         }       }     }     vector<int> y(m + 1);     for (int i = 1; i <= m; i++) {       scanf( %d , &y[i]);     }     for (int i = 1; i <= n; i++) {       for (int j = i; j <= n; j++) {         for (int k = 1; k <= m; k++) {           if (x[k][j] - x[k][i - 1] != y[k]) {             break;           }           if (k == m) {             printf( YES n );             return 0;           }         }       }     }     printf( NO n );   }


#include <bits/stdc++.h>   using namespace std;   int IN() {     int x = 0, f = 0, ch;     for (; (ch = getchar()) <  0  || ch >  9 ;) f = (ch ==  - );     for (; ch >=  0  && ch <=  9 ; (ch = getchar())) x = x * 10 + ch -  0 ;     return f ? -x : x;   }   const double Pi = acos(-1), eps = 1e-11;   int N, M, T, C, ID[2005];   struct Nod {     double x, y;   } A[2005], B[2005];   struct Opt {     double x;     int k, t;   } Q[2005 << 3];   bool Equ(double a, double b) { return abs(a - b) < eps; }   double Dis(const Nod& a, const Nod& b) {     return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));   }   void Upd(double l, double r, int k) {     if (r - l < 0) return;     for (; l < 0; l += 2 * Pi)       ;     for (; l > 2 * Pi; l -= 2 * Pi)       ;     for (; r < 0; r += 2 * Pi)       ;     for (; r > 2 * Pi; r -= 2 * Pi)       ;     if (l < r)       Q[++T] = (Opt){l, k, 1}, Q[++T] = (Opt){r, k, -1};     else       Q[++T] = (Opt){0, k, 1}, Q[++T] = (Opt){r, k, -1}, Q[++T] = (Opt){l, k, 1},       Q[++T] = (Opt){2 * Pi, k, -1};   }   bool Cmp(const Opt& a, const Opt& b) { return a.x < b.x; }   bool RightRed(int d, double r) {     T = 0;     Upd(0, 2 * Pi, 1);     for (int i = 1, lim = M; i <= lim; i++) {       double a = Dis(A[d], B[i]);       if (r + r <= a) continue;       double o = atan2(B[i].y - A[d].y, B[i].x - A[d].x), t = acos(a / r / 2);       Upd(o - t, o + t, 0);     }     sort(Q + 1, Q + T + 1, Cmp);     int s1 = 0, s2 = 0;     for (int i = 1, j; i <= T; i = j) {       for (j = i; j <= T && Equ(Q[i].x, Q[j].x); j++)         if (Q[j].k == 1)           s1 += Q[j].t;         else           s2 += Q[j].t;       if (s1 && !s2) return 1;     }     return 0;   }   bool RightBlue(int d, double r) {     T = 0;     for (int i = 1, lim = M; i <= lim; i++)       if (i != d) {         double a = Dis(B[d], B[i]);         if (r + r <= a) continue;         double o = atan2(B[i].y - B[d].y, B[i].x - B[d].x), t = acos(a / r / 2);         Upd(o - t, o + t, 0);       }     for (int i = 1, lim = N; i <= lim; i++) {       double a = Dis(B[d], A[i]);       if (r + r <= a) continue;       double o = atan2(A[i].y - B[d].y, A[i].x - B[d].x), t = acos(a / r / 2);       Upd(o - t, o + t, 1);     }     sort(Q + 1, Q + T + 1, Cmp);     int s1 = 0, s2 = 0;     for (int i = 1, j; i <= T; i = j) {       for (j = i; j <= T && Equ(Q[i].x, Q[j].x); j++)         if (Q[j].k == 1)           s1 += Q[j].t;         else           s2 += Q[j].t;       if (s1 && !s2) return 1;     }     return 0;   }   bool check(double r) {     for (int i = 1, lim = N; i <= lim; i++)       if (RightRed(i, r)) return 1;     for (int i = 1, lim = M; i <= lim; i++)       if (RightBlue(i, r)) return 1;     return 0;   }   int main(int argc, char* argv[]) {     N = IN();     M = IN();     for (int i = 1, lim = N; i <= lim; i++) A[i] = (Nod){1. * IN(), 1. * IN()};     for (int i = 1, lim = M; i <= lim; i++) B[i] = (Nod){1. * IN(), 1. * IN()};     if (check(1e10)) return puts( -1 ), 0;     for (int i = 1, lim = N; i <= lim; i++) ID[++C] = i;     for (int i = 1, lim = M; i <= lim; i++) ID[++C] = N + i;     random_shuffle(ID + 1, ID + N + 1);     random_shuffle(ID + N + 1, ID + C + 1);     double Ans = 0;     for (int k = 1, lim = C; k <= lim; k++) {       if (ID[k] <= N) {         int i = ID[k];         if (RightRed(i, Ans)) {           double l = Ans, r = 1e10;           for (; l + (1e-6) < r;) {             double Mid = (l + r) * .5;             if (RightRed(i, Mid))               l = Mid;             else               r = Mid;           }           Ans = l;         }       } else {         int i = ID[k] - N;         if (RightBlue(i, Ans)) {           double l = Ans, r = 1e10;           for (; l + (1e-6) < r;) {             double Mid = (l + r) * .5;             if (RightBlue(i, Mid))               l = Mid;             else               r = Mid;           }           Ans = l;         }       }     }     printf( %.12lf n , Ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   double EPS = 1e-9;   int INF = 1000000005;   long long INFF = 1000000000000000005ll;   double PI = acos(-1);   int dirx[8] = {-1, 0, 0, 1, -1, -1, 1, 1};   int diry[8] = {0, 1, -1, 0, -1, 1, -1, 1};   long long MOD = 1000000007;   template <typename T_vector>   void output_vector(const T_vector &v, bool line_break = false,                      bool add_one = false, int start = -1, int end = -1) {     if (start < 0) start = 0;     if (end < 0) end = int(v.size());     for (int i = start; i < end; i++) {       cout << v[i] + (add_one ? 1 : 0)            << (line_break    ?   n                 : i < end - 1 ?                                  :   n );     }   }   void solve() {     int n;     cin >> n;     vector<int> a(n);     for (auto &(z) : a) cin >> z;     ;     int ans = 0;     for (int(i) = (0); (i) < (n); ++(i)) {       int j = i;       while (j + 1 < n && a[j + 1] <= a[j] * 2) j++;       ans = max(ans, j - i + 1);       i = j;     }     cout << ans << endl;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100010;   const int D = 10000010;   const int MAXW = N + 1000;   const int mod = 1e9 + 7;   int n, m;   int pw2[MAXW + 10];   struct edge {     int to, nx, w;   } ee[N * 2];   int eq[N], en = 1;   int dn, flag;   int l[D], r[D], hs[D];   int ans[N], root[N], pred[N];   bool done[N];   int sv[N], svt;   bool cmp(int u, int v) {     if (!l[u] && !r[u])       return hs[u] <= hs[v];     else       return hs[r[u]] == hs[r[v]] ? cmp(l[u], l[v]) : cmp(r[u], r[v]);   }   struct compare {     bool operator()(const pair<int, int>& u, const pair<int, int>& v) {       if (hs[u.first] == hs[v.first])         return u > v;       else         return !cmp(u.first, v.first);     }   };   priority_queue<pair<int, int>, vector<pair<int, int> >, compare> Q;   void update(int d, int lt, int rt) {     int md = (lt + rt) >> 1;     hs[d] = (1LL * hs[r[d]] * pw2[md - lt + 1] + hs[l[d]]) % mod;   }   int add(int d, int lt, int rt) {     int nd = ++dn, md = (lt + rt) >> 1;     if (lt == rt)       hs[nd] = 1;     else {       if ((hs[l[d]] + 1) % mod != pw2[md - lt + 1]) {         l[nd] = add(l[d], lt, md);         r[nd] = r[d];       } else {         l[nd] = 0;         r[nd] = add(r[d], md + 1, rt);       }       update(nd, lt, rt);     }     return nd;   }   int add(int d, int lt, int rt, int w) {     int nd = ++dn, md = (lt + rt) >> 1;     if (lt == rt) {       if (hs[d])         return 0;       else {         flag = 1;         return hs[nd] = 1, nd;       }     }     if (w <= md) {       l[nd] = add(l[d], lt, md, w);       if (flag) {         r[nd] = r[d];       } else {         if ((hs[r[d]] + 1) % mod == pw2[rt - md])           r[nd] = 0;         else {           flag = 1;           r[nd] = add(r[d], md + 1, rt);         }       }     } else {       l[nd] = l[d];       r[nd] = add(r[d], md + 1, rt, w);     }     update(nd, lt, rt);     return nd;   }   void link(int u, int v, int w) { ee[++en] = (edge){v, eq[u], w}, eq[u] = en; }   int main() {     scanf( %d %d , &n, &m);     for (int i = 0; i <= MAXW; ++i) {       pw2[i] = !i ? 1 : (pw2[i - 1] * 2) % mod;     }     for (int i = 1; i <= m; ++i) {       int u, v, w;       scanf( %d %d %d , &u, &v, &w);       link(u, v, w);       link(v, u, w);     }     int s, t;     scanf( %d %d , &s, &t);     for (int i = 1; i <= n; ++i) {       if (i != s) {         flag = 0;         root[i] = add(root[i], 0, MAXW, MAXW);       }       Q.push(make_pair(root[i], i));     }     while (!Q.empty()) {       int u = Q.top().second;       Q.pop();       if (done[u]) continue;       done[u] = 1;       for (int j = eq[u], v; v = ee[j].to, j; j = ee[j].nx)         if (!done[v]) {           flag = 0;           int nt = add(root[u], 0, MAXW, ee[j].w);           if (cmp(nt, root[v])) {             root[v] = nt;             pred[v] = u;             ans[v] = (ans[u] + pw2[ee[j].w]) % mod;             flag = 0;             int nt = add(root[u], 0, MAXW, ee[j].w);             Q.push(make_pair(root[v], v));           }         }     }     if (s == t || pred[t]) {       printf( %d n , ans[t]);       svt = 0;       for (int o = t; o; o = pred[o]) sv[++svt] = o;       printf( %d n , svt);       for (int i = svt; i >= 1; --i) printf( %d  , sv[i]);       putchar(  n );     } else {       printf( -1 n );     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 5;   ;   const int inf = 1e9 + 5;   const int mod = 1e9 + 7;   const int logN = 17;   int x, y, n, m, a[N], b[N], w[N], p[N], score[N];   vector<int> v[N];   long long ans[N], upsum[N], downsum[N];   bool cmp(int x, int y) { return score[x] < score[y]; }   int main() {     scanf( %d %d , &n, &m);     for (int i = 1; i <= n; i++) {       scanf( %d %d , &a[i], &b[i]);       score[i] = a[i] - b[i];       p[i] = i;     }     sort(p + 1, p + n + 1, cmp);     for (int i = 1; i <= n; i++) {       w[p[i]] = i;     }     for (int i = 1; i <= m; i++) {       scanf( %d %d , &x, &y);       v[x].push_back(y);       v[y].push_back(x);     }     for (int i = 1; i <= n; i++) upsum[i] = upsum[i - 1] + a[p[i]];     for (int i = n; i >= 1; i--) downsum[i] = downsum[i + 1] + b[p[i]];     for (int i = 1; i <= n; i++) {       int up = i - 1;       int down = n - i;       long long ups = upsum[i - 1];       long long dws = downsum[i + 1];       int cur = p[i];       for (auto go : v[cur]) {         if (w[go] > i) {           down--;           dws -= b[go];         } else {           up--;           ups -= a[go];         }       }       ans[cur] = ups + dws + up * (long long)b[cur] + down * (long long)a[cur];     }     for (int i = 1; i <= n; i++) printf( %lld  , ans[i]);     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, potezi = 1, bodovi = 0;     scanf( %d , &n);     pair<int, int> a[n];     for (int i = 0; i < n; i++) {       scanf( %d %d , &a[i].second, &a[i].first);     }     sort(a, a + n);     for (int i = n - 1; i >= 0; i--) {       if (!potezi) break;       potezi += a[i].first - 1;       bodovi += a[i].second;     }     printf( %d n , bodovi);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string a, b;   int pas = 0;   int main() {     cin >> a >> b;     for (int i = 0; i < a.size(); i++) {       if (a[i] != b[a.size() - 1 - i]) {         pas++;       }     }     if (pas > 0) {       cout <<  NO ;     } else {       cout <<  YES ;     }   }


#include <bits/stdc++.h>   const long long N = 200005;   long long hi, ls, n, X[N], t, A[N], bk[N];   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cin >> n >> t;     for (int i = 0; i < n; ++i) {       cin >> A[i];     }     for (int i = 0; i < n; ++i) {       cin >> X[i], --X[i];     }     for (int i = 0; i < n; ++i) {       if ((X[i] < i || (i < n - 1 && X[i] > X[i + 1])) ||           (X[i] != i &&            (X[X[i]] != X[i] || (X[i] + 1 < n && A[X[i] + 1] - 1 == A[X[i]])))) {         cout <<  No , std::exit(0);       }     }     for (int i = 0; i < n; ++i) {       if (X[i] > i) {         for (int j = max(hi, 1ll + i); j < X[i] + 1; ++j) {           bk[j] = 1;         }         hi = max(hi, X[i]);       }     }     cout <<  Yes n ;     for (int i = 0; i < n; ++i)       (i < n - 1 && bk[i + 1] ? hi = A[i + 1] + t : hi = A[i] + t),           (i > 0 && hi == ls ? cout << hi + 1 <<     : cout << hi <<    ),           ls = hi;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   string a;   void convA() {     int c = 0, r = 0;     int i;     for (i = 1; a[i] !=  C ; i++) {       r *= 10;       r += a[i] -  0 ;     }     i++;     for (; i < a.size(); i++) {       c *= 10;       c += a[i] -  0 ;     }     vector<int> ans;     while (c != 0) {       if (c % 26 == 0) {         ans.push_back(26);         c--;       } else         ans.push_back(c % 26);       c /= 26;     }     for (int i = ans.size() - 1; i >= 0; i--) {       char ab = ans[i] + ( A  - 1);       cout << ab;     }     cout << r;     cout << endl;   }   void convB() {     vector<int> ans;     int i;     for (i = 0; a[i] >=  A  && a[i] <=  Z ; i++) {       if (a[i] ==  Z )         ans.push_back(26);       else         ans.push_back(a[i] -  A  + 1);     }     int c = 0, r;     for (int j = 0; j < ans.size(); j++) {       c += ans[j] * pow(26, ans.size() - j - 1);     }     cout <<  R ;     for (; i < a.size(); i++) cout << a[i];     cout <<  C  << c << endl;   }   int main() {     ios::sync_with_stdio(false);     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a;       bool RC = false, k = false;       if (a.size() >= 4) {         if (a[0] ==  R  && !(a[1] >=  A  && a[1] <=  Z ))           RC = true;         else           RC = false;         for (int i = 2; RC && i < a.size(); i++) {           if (a[i] >=  A  && a[i] <=  Z  && k) {             RC = false;             break;           }           if (a[i] ==  C  && !k) k = true;         }         if (RC && k) convA();       }       if (!RC || !k) convB();     }   }


#include <bits/stdc++.h>   #pragma GCC optimize( -O3 )   using namespace std;   const long long N = 1e6 + 5;   void pairsort(long long a[], long long b[], long long n) {     pair<long long, long long> pairt[n];     for (long long i = 0; i < n; i++) {       pairt[i].first = a[i];       pairt[i].second = b[i];     }     sort(pairt, pairt + n);     for (long long i = 0; i < n; i++) {       a[i] = pairt[i].first;       b[i] = pairt[i].second;     }   }   long long gcd(long long a, long long b) {     if (b == 0) return a;     return gcd(b, a % b);   }   long long isPrime(long long n) {     if (n < 2) return 0;     if (n < 4) return 1;     if (n % 2 == 0 or n % 3 == 0) return 0;     for (long long i = 5; i * i <= n; i += 6)       if (n % i == 0 or n % (i + 2) == 0) return 0;     return 1;   }   long long C(long long n, long long r) {     if (r > n - r) r = n - r;     long long ans = 1;     for (long long i = 1; i <= r; i++) {       ans *= n - r + i;       ans /= i;     }     return ans;   }   long long mod = 1e9 + 7;   long long modexpo(long long x, long long p) {     long long res = 1;     x = x % mod;     while (p) {       if (p % 2) res = res * x;       p >>= 1;       x = x * x % mod;       res %= mod;     }     return res;   }   struct pair_hash {     template <class T1, class T2>     std::size_t operator()(std::pair<T1, T2> const &pair) const {       std::size_t h1 = std::hash<T1>()(pair.first);       std::size_t h2 = std::hash<T2>()(pair.second);       return h1 ^ h2;     }   };   long long n, x, y, f[N], vis[N], a[N], k;   set<pair<long long, long long>, greater<pair<long long, long long>>> s;   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     cin >> n >> x;     for (long long i = 1; i <= n; i++) {       cin >> y, a[i] = y;       if (x == y)         f[x]++;       else {         s.erase({f[y], y}), f[y]++, s.insert({f[y], y});         pair<long long, long long> p = *s.begin();         if (p.first >= f[x]) k = 1;       }     }     if (!k) return cout << -1, 0;     memset(f, 0, sizeof(f));     unordered_set<pair<long long, long long>, pair_hash> ss;     for (long long i = 1; i <= 1e6; i++)       if (x != i) ss.insert({0, i});     for (long long i = 1; i <= n; i++) {       if (x == a[i]) {         f[x]++;         vector<long long> vv;         for (auto it = ss.begin(); it != ss.end(); it++)           if ((*it).first < f[x])             vv.push_back({(*it).second}), vis[(*it).second] = 1;         for (long long i = 0; i < vv.size(); i++) ss.erase({f[vv[i]], vv[i]});       } else if (!vis[a[i]])         ss.erase({f[a[i]], a[i]}), f[a[i]]++, ss.insert({f[a[i]], a[i]});     }     vector<long long> vv;     for (auto it = ss.begin(); it != ss.end(); it++)       if (vis[(*it).second]) vv.push_back((*it).second);     for (long long i = 0; i < vv.size(); i++) ss.erase({f[vv[i]], vv[i]});     if (!ss.size()) return cout << -1, 0;     cout << (*ss.begin()).second;     return 0;   }