#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using pii = pair<int, int>;   constexpr int N = 1e2 + 5;   int n, m, k, g[N][N], ans = -1, id;   unordered_set<int> dp[N][N];   char c;   bool check(int i, int j, int val) {     for (auto el : dp[i][j]) {       if (ans == el + val) {         ans -= val;         return true;       }     }     return false;   }   void Solve() {     cin >> n >> m >> k;     for (int i = 0; i < N; i++)       for (int j = 0; j < N; j++) {         dp[i][j].reserve(1024);         dp[i][j].max_load_factor(0.25);       }     for (int i = 0; i < N; i++) dp[0][i] = {0};     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) {         cin >> c;         g[i][j] = c -  0 ;       }     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) {         for (auto el : dp[i - 1][j - 1]) dp[i][j].insert(el + g[i][j]);         for (auto el : dp[i - 1][j + 1]) dp[i][j].insert(el + g[i][j]);       }     for (int i = 1; i <= m; i++)       for (auto el : dp[n][i]) {         if (!(el % (k + 1))) {           if (ans < el) {             ans = el;             id = i;           }         }       }     cout << ans <<   n ;     if (ans == -1) return;     cout << id <<   n ;     for (int i = n; i > 1; i--) {       if (check(i - 1, id - 1, g[i][id])) {         id = id - 1;         cout <<  L ;       } else if (check(i - 1, id + 1, g[i][id])) {         id = id + 1;         cout <<  R ;       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     Solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int SG(double x) { return x > -1E-8 ? x < 1E-8 ? 0 : 1 : -1; }   int c[1000000];   int main() {     int n, m, r, i, j, k, d;     long long md;     scanf( %d %d %d , &n, &m, &r);     for (i = 0; i < (n); i++) {       scanf( %d , &c[i]);     }     if (n % 2 == 0) {       puts( 0 );       return 0;     }     d = (n + 1) / 2;     md = (long long)(m / d) * (long long)r;     for (i = 0; i < n; i += 2) {       if (c[i] < md) md = c[i];     }     printf( %I64d n , md);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     double general_sum, sum;     general_sum = sum = 0;     int i = 0;     int j = 0;     cin >> n >> k;     vector<int> a(n);     double w = n - k + 1;     for (i; i < w; i++) {       if (i == 0) {         for (j; j < k; j++) {           cin >> a[j];           sum += a[j];         }       } else {         cin >> a[j];         sum += a[j];         sum -= a[i - 1];         j++;       }       general_sum += sum;     }     cout.precision(6);     cout << fixed << general_sum / w << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 5005;   const int inf = 0x3f3f3f3f;   int n, a[N], ma[N][N];   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     int cnt = 0;     for (int i = 1; i <= n; i++)       for (int j = i + 1; j <= n; j++)         if (a[i] > a[j]) cnt++;     int ans = cnt, tot = 1;     for (int i = 1; i <= n; i++)       for (int j = i + 1; j <= n; j++) ma[i][j] = ma[i][j - 1] + (a[i] < a[j]);     for (int i = n; i >= 1; i--)       for (int j = i - 1; j >= 1; j--) ma[i][j] = ma[i][j + 1] + (a[i] > a[j]);     for (int i = 1; i <= n; i++) {       for (int j = i + 1; j <= n; j++) {         int aa = ma[i][j - 1], bb = ma[j][i + 1];         int tmp = cnt + aa - (j - i - 1 - aa) + bb - (j - i - 1 - bb);         tmp += (a[i] < a[j] ? 1 : -1);         if (ans > tmp) {           ans = tmp;           tot = 1;         } else if (ans == tmp)           tot++;       }     }     printf( %d %d n , ans, tot);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int arr[100001];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> arr[i];     }     sort(arr, arr + n);     int cur = 1;     for (int i = 0; i < n; i++) {       if (cur <= arr[i]) {         cur++;       }     }     cout << cur;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n;     cin >> n;     int a[n];     for (int i = 0; i < n; i++) cin >> a[i];     int i = 1;     while (i < n) {       if (a[i] > a[i - 1])         i++;       else         break;     }     if (n == 1) {       cout <<  YES ;       return 0;     }     while (i < n) {       if (a[i] == a[i - 1])         i++;       else         break;     }     while (i < n) {       if (a[i] < a[i - 1])         i++;       else         break;     }     if (i == n)       cout <<  YES ;     else       cout <<  NO ;   }


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


#include <bits/stdc++.h>   using namespace std;   int a, b, c, x, y, z, q, w, e;   int main() {     cin >> a >> b >> c >> x >> y >> z;     q = a - x;     if (q > 0) q /= 2;     w = b - y;     if (w > 0) w /= 2;     e = c - z;     if (e > 0) e /= 2;     if (q + w + e >= 0)       cout <<  YES ;     else       cout <<  NO ;   }


#include <bits/stdc++.h>   using namespace std;   const double eps = 0.000000001;   double x[200000];   int n;   void solve() {     if (abs(x[1]) < eps) {       int p = 0;       for (int i = 1; i < n; i++)         if (abs(x[i]) > eps) p++;       if (p == 0) {         printf( 1 n );         exit(0);       }       return;     }     double q = x[2] / x[1];     for (int i = 3; i < n; i++) {       if (abs(x[i]) < eps) {         if (abs(q) > eps) return;       } else if (abs(x[i] / x[i - 1] - q) > eps)         return;     }     printf( 1 n );     exit(0);   }   int main() {     cin >> n;     for (int i = 0; i < n; i++) scanf( %lf , &x[i]);     if (abs(x[0]) < eps) {       int p = 0;       for (int i = 0; i < n; i++)         if (abs(x[i]) > eps) p++;       if (p < 2) {         printf( %d n , p);         return 0;       }       solve();       printf( 2 n );       return 0;     }     if (n < 3) {       printf( 0 n );       return 0;     }     double q = x[1] / x[0];     int p = 0;     for (int i = 2; i < n; i++) {       if (abs(x[i]) < eps) {         if (abs(q) > eps) {           if (p == 1) {             p = 2;             break;           }           p = 1;           x[i] = x[i - 1];         }       } else if (abs(x[i] / x[i - 1] - q) > eps) {         if (p == 1) {           p = 2;           break;         }         p = 1;         if (abs(x[i] - x[i - 1]) > eps && i != n - 1) {           if (abs(x[i + 1] / x[i - 1] - q) < eps)             x[i] = x[i - 1];           else if (abs(x[i + 1] / x[i] - q) > eps) {             p = 2;             break;           }         }       }     }     if (p < 2) {       printf( %d n , p);       return 0;     }     solve();     swap(x[0], x[1]);     solve();     printf( 2 n );     return 0;   }


#pragma GCC optimize ( O3 )   #include <bits/stdc++.h>      using namespace std;   typedef long long ll;   #define endl   n    const ll DIM = 607;   const ll INF = 1E18;   vector<pair<int,ll> > G[DIM];   ll dist[DIM],mod[DIM*4];   bool vis[DIM];   struct node{       ll dist;       int x,y;   };   const bool operator > (const node &a,const node &b){       return a.dist>b.dist;   }   int main() {       ios_base::sync_with_stdio(0);       cin.tie(0);       cout.tie(0);          ll n, m;       cin >> n >> m;       for(ll i = 0;i<DIM*4;++i)           mod[i] = i%n;       for (int i = 1; i <= m; ++i) {           ll a, b, c;           cin >> a >> b >> c;           G[a].push_back({b, c});       }       for (ll i = 0; i < n; ++i) {           sort(G[i].begin(), G[i].end());           vector<pair<int, ll> > V;           int mi = 0;           for (int j = 1; j < G[i].size(); ++j) {               if (G[i][mi].second > G[i][j].second)                   mi = j;           }           for (int j = mi; j < G[i].size(); ++j)               V.push_back(G[i][j]);           for (int j = 0; j < mi; ++j)               V.push_back(G[i][j]);           G[i] = V;       }          for (ll x = 0; x < n; ++x) {           for(ll j = 0;j<n;++j){               dist[j] = INF;               vis[j] = 0;           }           dist[x] = 0;              while(1){               int y = -1;               for(int j = 0;j<n;++j){                   if (vis[j])                       continue;                   if (y==-1 || dist[y]>dist[j])                       y = j;               }               if (y==-1)                   break;               vis[y] = 1;               ll dd = dist[y];               ll dm = dd%n;               pair<int, ll> cur = G[y][0];               int start = mod[G[y][0].first + dm];               int ptr = 1;               ll ss = G[y][0].second - 1;               for (int i = start; i < n; ++i) {                   ++ss;                   while (ptr < G[y].size() && mod[G[y][ptr].first + dm] == i) {                       if (G[y][ptr].second < ss) {                           cur = G[y][ptr];                           ss = G[y][ptr].second;                       }                       ++ptr;                   }                   ll ds = ss + dd;                   if (dist[i] > ds) {                       dist[i] = ds;                      }               }               for (int i = 0; i < start; ++i) {                   ++ss;                   while (ptr < G[y].size() && mod[G[y][ptr].first + dm] == i) {                       if (G[y][ptr].second < ss) {                           cur = G[y][ptr];                           ss = G[y][ptr].second;                       }                       ++ptr;                   }                   ll ds = ss + dd;                   if (dist[i] > ds) {                       dist[i] = ds;                      }               }           }           for(ll i = 0;i<n;++i)               cout<<dist[i]<<   ;           cout<<endl;       }             return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long int mod = 1e9 + 7;   const int N = 5001;   int dp[N][26][26];   int main(void) {     ios::sync_with_stdio(false);     cin.tie(0);     string s;     cin >> s;     int n = s.length();     for (int i = (int)(0); i < (int)(n); i++) {       int ch = s[i] -  a ;       for (int j = (int)(0); j < (int)(n); j++) {         int dh = s[(i + j) % n] -  a ;         dp[j][ch][dh] += 1;       }     }     int cnt = 0;     for (int j = (int)(0); j < (int)(26); j++) {       int ma = 0;       for (int i = (int)(1); i < (int)(n); i++) {         int uq = 0;         for (int k = (int)(0); k < (int)(26); k++) {           if (dp[i][j][k] == 1) {             uq++;           }         }         ma = max(ma, uq);       }       cnt += ma;     }     cout << setprecision(15) << ((double)cnt / (double)n) <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e4 + 123;   int n, c;   int made[N], preparedToSell[N];   long long goods[N], limit[N];   long long toSell[N], toSend[N];   void readData() {     cin >> n >> c;     for (int i = 1; i <= n; ++i) {       cin >> made[i];     }     for (int i = 1; i <= n; ++i) {       cin >> preparedToSell[i];     }   }   void generateData() {     n = rand() % 6;     c = rand() % 4;     for (int i = 1; i <= n; ++i) {       made[i] = rand() % 6;     }     for (int i = 1; i <= n; ++i) {       preparedToSell[i] = rand() % 6;     }   }   void writeLog() {     cout << n <<     << c <<   n ;     for (int i = 1; i <= n; ++i) {       cout << made[i] <<    ;     }     cout <<   n ;     for (int i = 1; i <= n; ++i) {       cout << preparedToSell[i] <<    ;     }     cout <<   n ;   }   long long capacity[102][102], flow[102][102], excess[102];   int height[102];   set<int> overfilled, lowerChildren[102], higherChildren[102];   void push(int u, int v) {     long long additionalFlow = min(excess[u], capacity[u][v] - flow[u][v]);     if (!excess[v] && additionalFlow && v != n + 1) {       overfilled.insert(v);     }     if (excess[u] == additionalFlow) {       overfilled.erase(u);     }     flow[u][v] += additionalFlow;     flow[v][u] -= additionalFlow;     excess[u] -= additionalFlow;     excess[v] += additionalFlow;     if (flow[u][v] == capacity[u][v]) {       capacity[u][v] = 0;       lowerChildren[u].erase(v);       higherChildren[v].insert(u);     }   }   void relabel(int u) {     if (u == 0) {       overfilled.erase(0);       return;     }     int minHeight = height[0];     for (int v : higherChildren[u]) {       minHeight = min(minHeight, height[v]);     }     height[u] = minHeight + 1;     for (int i = 0; i <= n + 1; ++i) {       if (height[i] >= height[u]) continue;       auto it = higherChildren[u].find(i);       if (it != higherChildren[u].end()) {         higherChildren[u].erase(it);         lowerChildren[u].insert(i);       }     }     for (int i = 0; i <= n + 1; ++i) {       auto it = lowerChildren[i].find(u);       if (it != lowerChildren[i].end()) {         lowerChildren[i].erase(it);         higherChildren[i].insert(u);       }     }   }   long long flowSolve() {     memset(capacity, 0, sizeof(capacity));     memset(flow, 0, sizeof(flow));     memset(excess, 0, sizeof(excess));     overfilled.clear();     for (auto& s : higherChildren) {       s.clear();     }     for (auto& s : lowerChildren) {       s.clear();     }     for (int i = 1; i <= n; ++i) {       capacity[0][i] = made[i];       lowerChildren[0].insert(i);       for (int j = i + 1; j <= n; ++j) {         capacity[i][j] = c;         higherChildren[i].insert(j);       }       capacity[i][n + 1] = preparedToSell[i];       higherChildren[i].insert(n + 1);     }     excess[0] = 1e18;     height[0] = n + 2;     overfilled.insert(0);     while (!overfilled.empty()) {       int u = *(overfilled.begin());       if (!lowerChildren[u].empty()) {         int v = *(lowerChildren[u].begin());         push(u, v);       } else {         relabel(u);       }     }     return excess[n + 1];   }   long long table[2][N];   long long solve() {     long long cll = c;     for (int k = 1; k <= n; ++k) {       long long* oldRow = table[k & 1];       long long* newRow = table[!(k & 1)];       newRow[0] = oldRow[0] + made[k];       for (int i = 1; i < k; ++i) {         newRow[i] =             min(oldRow[i] + made[k] + i * cll, oldRow[i - 1] + preparedToSell[k]);       }       newRow[k] = oldRow[k - 1] + preparedToSell[k];     }     long long* lastRow = table[!(n & 1)];     long long result = lastRow[0];     for (int i = 1; i <= n; ++i) {       result = min(result, lastRow[i]);     }     return result;   }   int main() {     ios_base::sync_with_stdio(false);     srand(time(0));     readData();     cout << solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   void Read(T &cn) {     char c;     int sig = 1;     while (!isdigit(c = getchar()))       if (c ==  - ) sig = -1;     cn = c - 48;     while (isdigit(c = getchar())) cn = cn * 10 + c - 48;     cn *= sig;   }   template <typename T>   void Write(T cn) {     if (cn < 0) {       putchar( - );       cn = 0 - cn;     }     int wei = 0;     T cm = 0;     int cx = cn % 10;     cn /= 10;     while (cn) cm = cm * 10 + cn % 10, cn /= 10, wei++;     while (wei--) putchar(cm % 10 + 48), cm /= 10;     putchar(cx + 48);   }   int f[500 / 2 + 1][500 + 1][500 + 1];   int n, m, q;   int a[500 + 1][500 + 1];   int b[500 + 1][500 + 1];   int jian_c(int cn, int cm, int cx) {     if (a[cn - cx + 1][cm - cx + 1] !=  R  || b[cn - cx + 1][cm - cx + 1] != cx)       return 0;     if (a[cn - cx + 1][cm + 1] !=  G  || b[cn - cx + 1][cm + 1] != cx) return 0;     if (a[cn + 1][cm - cx + 1] !=  Y  || b[cn + 1][cm - cx + 1] != cx) return 0;     if (a[cn + 1][cm + 1] !=  B  || b[cn + 1][cm + 1] < cx) return 0;     return 1;   }   void jian(int cn, int cm) {     int lin = min(min(cn, cm), min(n - cn, m - cm));     for (int i = 1; i <= lin; i++) {       if (!jian_c(cn, cm, i)) return;       f[i][cn - i + 1][cm - i + 1] = 1;     }   }   void yuchu() {     for (int i = 1; i <= n; i++) b[i][m] = 1;     for (int i = 1; i <= m; i++) b[n][i] = 1;     for (int i = n - 1; i >= 1; i--)       for (int j = m - 1; j >= 1; j--) {         if (a[i][j] == a[i + 1][j + 1] && a[i][j] == a[i + 1][j] &&             a[i][j] == a[i][j + 1])           b[i][j] = 1 + min(min(b[i + 1][j], b[i][j + 1]), b[i + 1][j + 1]);         else           b[i][j] = 1;       }   }   int suan(int cn, int cx1, int cy1, int cx2, int cy2) {     return f[cn][cx2][cy2] - f[cn][cx2][cy1] - f[cn][cx1][cy2] + f[cn][cx1][cy1];   }   int main() {     Read(n);     Read(m);     Read(q);     for (int i = 1; i <= n; i++) {       while (!isalpha(a[i][1] = getchar()))         ;       for (int j = 2; j <= m; j++) a[i][j] = getchar();     }     yuchu();     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) jian(i, j);     for (int ij = 1; ij <= n / 2; ij++)       for (int i = 1; i <= n; i++)         for (int j = 1; j <= m; j++)           f[ij][i][j] = f[ij][i - 1][j] + f[ij][i][j - 1] - f[ij][i - 1][j - 1] +                         f[ij][i][j];     for (int i = 1; i <= q; i++) {       int bx1, by1, bx2, by2;       Read(bx1);       Read(by1);       Read(bx2);       Read(by2);       int ans = 0;       int lin = (min(bx2 - bx1, by2 - by1) + 1) / 2;       for (int j = lin; j >= 1; j--)         if (suan(j, bx1 - 1, by1 - 1, bx2 - j * 2 + 1, by2 - j * 2 + 1)) {           ans = 4 * j * j;           break;         }       Write(ans);       puts(  );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   long long pow(long long x, long long n) {     long long res = 1;     while (n) {       if (n & 1) res = (res * x);       x = (x * x);       n >>= 1;     }     return res;   }   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long t;     cin >> t;     while (t--) {       long long n;       cin >> n;       long long x = n / 2;       if (x % 2) {         cout <<  NO  <<   n ;         continue;       }       cout <<  YES  <<   n ;       vector<long long> a;       for (long long i = 0; i < n; i += 2) {         a.push_back(i + 2);       }       long long c = a.size() / 2;       for (long long i = 0; i < c; i++) {         a.push_back(a[i] - 1);         a.push_back(a[x - i - 1] + 1);       }       for (auto x : a) cout << x <<    ;       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   char a[15][15];   vector<long long int> dp[1 << 14][14];   int main() {     cin.tie(nullptr);     ios::sync_with_stdio(false);     cin >> n;     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++) {       dp[1 << i][i].push_back(1LL);     }     for (int i = 1; i < (1 << n); i++) {       int p = __builtin_popcount(i);       for (int j = 0; j < n; j++) {         if (((i >> j) & 1) == 0) continue;         for (int k = 0; k < n; k++) {           if ((i >> k) & 1) continue;           if (dp[i + (1 << k)][k].size() == 0) {             dp[i + (1 << k)][k].resize((1 << p));           }           int t = 0;           if (a[j][k] ==  1 ) t = 1;           for (int l = 0; l < dp[i][j].size(); l++) {             dp[i + (1 << k)][k][t * (1 << (p - 1)) + l] += dp[i][j][l];           }         }       }     }     for (int i = 0; i < (1 << (n - 1)); i++) {       long long int res = 0;       for (int j = 0; j < n; j++) {         res += dp[(1 << n) - 1][j][i];       }       printf( %lld  , res);     }     printf(  n );   }


#include <bits/stdc++.h>   using namespace std;   static const int maxn = 1000 + 10;   int n, m, f[maxn][maxn];   char s[maxn], t[maxn];   int main() {     scanf( %d %d , &n, &m);     scanf( %s , s);     scanf( %s , t);     int mn = n + 1;     vector<int> ans;     for (int i = 0; i + n <= m; i++) {       int count = 0;       vector<int> now;       for (int j = 0; j < n; j++)         if (s[j] != t[i + j]) {           count++;           now.emplace_back(j + 1);         }       if (count < mn) {         mn = count;         ans = now;       }     }     printf( %d n , mn);     for (int i = 0; i < ans.size(); i++)       printf( %d%c , ans[i],    n [i == mn - 1]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void swapll(long long *a, long long *b) {     long long tmp = *a;     *a = *b;     *b = tmp;   }   void swapc(char *a, char *b) {     char tmp = *a;     *a = *b;     *b = tmp;   }   void solve() {     long long n;     cin >> n;     vector<long long> v(n, 0);     for (long long i = 0; i < n; i++) cin >> v[i];     ;     long long count = 0;     long long idx = -1;     for (long long i = 0; i < n; i++) {       if (v[i] == 1 && idx == -1) {         count++;         idx = i;       } else if (v[i] == 1 && i - idx == 1) {         count++;         idx = i;       } else if (v[i] == 1 && i - idx != 1) {         count += 2;         idx = i;       }     }     cout << count << endl;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, a, b, ans;     cin >> n >> a >> b;     if (n == 1)       cout <<  1  << endl;     else {       ans = (a + b + abs(b) * n) % n;       if (ans == 0) ans = n;       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100010;   struct Node {     int l, r, w, s;   } t[N << 2];   vector<int> a[N], c[N];   int p[N], q[N], L[N], R[N], s[N], z[N];   int cnt, n, m, x, y;   void update(int x) {     if (t[x].w)       t[x].s = t[x].r - t[x].l + 1;     else if (t[x].r != t[x].l)       t[x].s = t[x << 1].s + t[x << 1 | 1].s;     else       t[x].s = 0;   }   void build(int x, int l, int r) {     t[x].l = l, t[x].r = r;     if (l == r) return;     int m = (l + r) >> 1;     build(x << 1, l, m);     build(x << 1 | 1, m + 1, r);     update(x);   }   void change(int x, int l, int r, int d) {     if (t[x].l > r || t[x].r < l)       return;     else if (l <= t[x].l && t[x].r <= r)       t[x].w += d;     else       change(x << 1, l, r, d), change(x << 1 | 1, l, r, d);     update(x);   }   void dfs(int x, int y) {     L[x] = ++cnt;     for (__typeof(a[x].begin()) i = a[x].begin(); i != a[x].end(); i++)       if (*i != y) dfs(*i, x);     R[x] = cnt;   }   inline void tcg(int k, int d) { change(1, L[k], R[k], d); }   void DFS(int x, int y) {     for (__typeof(c[x].begin()) i = c[x].begin(); i != c[x].end(); i++)       tcg(p[*i], 1), tcg(q[*i], 1);     z[x] = t[1].s;     for (__typeof(a[x].begin()) i = a[x].begin(); i != a[x].end(); i++)       if (*i != y) DFS(*i, x);     for (__typeof(c[x].begin()) i = c[x].begin(); i != c[x].end(); i++)       tcg(p[*i], -1), tcg(q[*i], -1);   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i < n; i++) {       scanf( %d%d , &x, &y);       a[x].push_back(y);       a[y].push_back(x);     }     dfs(1, 0);     build(1, 1, n);     for (int i = 0; i < m; i++) {       scanf( %d%d , p + i, q + i);       c[p[i]].push_back(i);       c[q[i]].push_back(i);     }     DFS(1, 0);     for (int i = 1; i <= n; i++) printf( %d  , max(z[i] - 1, 0));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, ans = 0;   long long f[1000001];   int main(int argc, char **argv) {     cin >> n;     for (int i = 1; i <= n; i++) {       long long b;       cin >> b;       f[b - i + 400000] += b;       ans = max(ans, f[b - i + 400000]);     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1 << 18;   int a[MAXN];   long long s[MAXN << 2];   int h[MAXN << 2];   void build(int id, int l, int r) {     if (l == r) {       s[id] = a[l];       h[id] = 0;       return;     }     int mid = (l + r) >> 1;     build(id << 1, l, mid);     build(id << 1 | 1, mid + 1, r);     s[id] = s[id << 1] + s[id << 1 | 1];     h[id] = h[id << 1] + 1;   }   long long query(int id, int l, int r, int ll, int rr) {     if (ll <= l && r <= rr) return s[id];     int mid = (l + r) >> 1;     long long ret = 0;     if (ll <= mid) ret += query(id << 1, l, mid, ll, rr);     if (rr > mid) ret += query(id << 1 | 1, mid + 1, r, ll, rr);     return ret;   }   void modify(int id, int l, int r, int pos, int v) {     if (l == r) {       s[id] = v;       return;     }     int mid = (l + r) >> 1;     if (pos <= mid)       modify(id << 1, l, mid, pos, v);     else       modify(id << 1 | 1, mid + 1, r, pos, v);     s[id] = s[id << 1] + s[id << 1 | 1];   }   int S;   int v = 0;   long long query1(int id, int l, int r, int ll, int rr) {     if (ll <= l && r <= rr) {       int LLL = ((v & (S - (1 << h[id]))) ^ l),           RRR = ((v & (S - (1 << h[id]))) ^ r);       if (LLL > RRR) swap(LLL, RRR);       return query(1, 0, S - 1, LLL, RRR);     }     int mid = (l + r) >> 1;     long long ret = 0;     if (ll <= mid) ret += query1(id << 1, l, mid, ll, rr);     if (rr > mid) ret += query1(id << 1 | 1, mid + 1, r, ll, rr);     return ret;   }   int main() {     int n, q;     scanf( %d%d , &n, &q);     for (int i = 0; i < (1 << n); ++i) scanf( %d , &a[i]);     build(1, 0, (1 << n) - 1);     S = (1 << n);     for (int i = 1; i <= q; ++i) {       int tp;       scanf( %d , &tp);       if (tp == 1) {         int x, k;         scanf( %d%d , &x, &k);         x--;         x ^= v;         modify(1, 0, (1 << n) - 1, x, k);       } else if (tp == 2) {         int k;         scanf( %d , &k);         v ^= (1 << k) - 1;       } else if (tp == 3) {         int k;         scanf( %d , &k);         v ^= (1 << k);       } else {         int l, r;         scanf( %d%d , &l, &r);         l--;         r--;         printf( %lld n , query1(1, 0, (1 << n) - 1, l, r));       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   int z[N], t1[N], t2[N];   string s;   vector<pair<int, int> > ans;   int n;   void BuildZArray() {     int L = 0, R = 0;     for (int i = 1; i < n; i++) {       if (i > R) {         L = R = i;         while (R < n && s[R - L] == s[R]) R++;         z[i] = R - L;         R--;       } else {         int k = i - L;         if (z[k] < R - i + 1)           z[i] = z[k];         else {           L = i;           while (R < n && s[R - L] == s[R]) R++;           z[i] = R - L;           R--;         }       }     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> s;     n = s.size();     BuildZArray();     for (int i = 0; i < n; i++) {       t1[z[i]]++;     }     t1[n]++;     for (int i = N - 1; i >= 0; i--) {       t2[i] = t1[i] + t2[i + 1];     }     for (int i = 0; i < n; i++)       if (z[i] >= n - i) ans.push_back(pair<int, int>(z[i], t2[z[i]]));     ans.push_back(pair<int, int>(n, 1));     sort(ans.begin(), ans.end());     cout << ans.size() <<   n ;     for (auto it : ans) cout << it.first <<     << it.second <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   inline int read() {     int s = 0, w = 0;     char ch = getchar();     while (ch <  0  || ch >  9 ) w |= (ch ==  - ), ch = getchar();     while (ch >=  0  && ch <=  9 ) s = s * 10 + ch -  0 , ch = getchar();     return w ? -s : s;   }   struct rr {     int nt, to;   } bl[100005 << 1];   int hd[100005], itot = 0;   inline void adde(int x, int y) {     bl[++itot] = (rr){hd[x], y};     hd[x] = itot;     bl[++itot] = (rr){hd[y], x};     hd[y] = itot;     return;   }   vector<int> to[100005];   int belong[100005], cnt = 0, sz[100005];   int dfn[100005], low[100005], num = 0, stk[100005], top = 0;   int vis[100005];   void tarjan(int u, int fa) {     dfn[u] = low[u] = ++num;     stk[++top] = u;     vis[u] = 1;     for (int i = hd[u], y; i; i = bl[i].nt)       if ((y = bl[i].to) != fa && vis[y] != 2) {         if (!dfn[y]) {           tarjan(y, u);           low[u] = min(low[u], low[y]);         } else           low[u] = min(low[u], dfn[y]);       }     if (dfn[u] == low[u]) {       int z;       ++cnt;       do {         z = stk[top--];         belong[z] = cnt;         sz[cnt]++;         vis[z] = 2;       } while (z != u);     }     return;   }   int n, m;   int dist[100005], sd[100005];   int f[100005][20], LOG[100005];   inline int LCA(int x, int y) {     if (sd[x] < sd[y]) swap(x, y);     for (int j = LOG[sd[x]]; j >= 0; --j)       if (f[x][j] && sd[f[x][j]] >= sd[y]) x = f[x][j];     if (x == y) return x;     for (int j = LOG[sd[x]]; j >= 0; --j)       if (f[x][j] && f[y][j] && f[x][j] != f[y][j]) x = f[x][j], y = f[y][j];     return f[x][0];   }   void dfs(int u, int fa) {     dist[u] = dist[fa] + (sz[u] != 1);     sd[u] = sd[fa] + 1;     f[u][0] = fa;     for (int j = 1; j <= LOG[sd[u]]; ++j) f[u][j] = f[f[u][j - 1]][j - 1];     for (int i = 0; i < to[u].size(); ++i)       if (to[u][i] != fa) dfs(to[u][i], u);     return;   }   int bin[100005];   int main() {     n = (read()), m = (read());     bin[0] = 1, bin[1] = 2;     for (int i = 2; i <= n; ++i) {       LOG[i] = LOG[i >> 1] + 1;       bin[i] = bin[i - 1] + bin[i - 1];       if (bin[i] >= mod) bin[i] -= mod;     }     for (int i = 1, x, y; i <= m; ++i) x = (read()), y = (read()), adde(x, y);     tarjan(1, 0);     for (int i = 1; i <= n; ++i)       for (int j = hd[i], y; j; j = bl[j].nt)         if (belong[i] != belong[y = bl[j].to]) to[belong[i]].push_back(belong[y]);     dfs(1, 0);     int q = (read()), x, y;     while (q--) {       x = belong[(read())], y = belong[(read())];       int lca = LCA(x, y);       printf( %d n , bin[dist[x] + dist[y] - dist[lca] - dist[f[lca][0]]]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 100005;   const int MAXE = 200005;   const int mod = 1e9 + 7;   struct Edge {     int v;     Edge* next;   } E[MAXE], *H[MAXN], *cur;   int color[MAXN];   long long dp[MAXN][2];   void clear() {     cur = E;     memset(H, 0, sizeof H);     memset(color, 0, sizeof color);     memset(dp, 0, sizeof dp);   }   void addedge(int u, int v) {     cur->v = v;     cur->next = H[u];     H[u] = cur++;   }   void scanf(int& x, char c = 0) {     while ((c = getchar()) <  0  || c >  9 )       ;     x = c -  0 ;     while ((c = getchar()) >=  0  && c <=  9 ) x = x * 10 + c -  0 ;   }   void dfs(int u, int f = 0) {     dp[u][color[u]] = 1;     for (Edge* e = H[u]; e; e = e->next) {       int v = e->v;       if (v == f) continue;       dfs(v, u);       dp[u][1] =           (dp[u][1] * (dp[v][0] + dp[v][1]) % mod + dp[u][0] * dp[v][1]) % mod;       dp[u][0] = dp[u][0] * (dp[v][0] + dp[v][1]) % mod;     }   }   void solve() {     int n, x;     while (~scanf( %d , &n)) {       clear();       for (int i = (1); i < (n); ++i) {         scanf(x);         addedge(x, i);         addedge(i, x);       }       for (int i = (0); i < (n); ++i) scanf(color[i]);       dfs(0);       printf( %I64d n , dp[0][1]);     }   }   int main() {     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, l, x, y;     cin >> n >> l >> x >> y;     set<int> d;     for (int i = 0; i < n; ++i) {       int t;       cin >> t;       d.insert(t);     }     bool issetX = false, issetY = false;     for (set<int>::iterator i = d.begin(); i != d.end(); ++i) {       if (d.find(*i + x) != d.end()) {         issetX = true;       }       if (d.find(*i + y) != d.end()) {         issetY = true;       }     }     if (issetX && issetY) {       cout << 0;       return 0;     } else if (issetX) {       cout <<  1   << endl << y;     } else if (issetY) {       cout <<  1   << endl << x;     } else {       int point = -1;       for (set<int>::iterator i = d.begin(); i != d.end(); ++i) {         if (d.find(*i + (y - x)) != d.end()) {           if (*i - x >= 0) {             point = *i - x;             break;           } else if (*i + (y - x) + x <= l) {             point = *i + (y - x) + x;             break;           }         }         if (d.find(*i + (y + x)) != d.end()) {           point = *i + x;           break;         }       }       if (point < 0) {         cout <<  2   << endl << x <<     << y;       } else {         cout <<  1   << endl << point;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, flag;     cin >> n >> m;     int l[m], ans[n], check[n];     memset(ans, 0, sizeof(ans));     memset(check, 0, sizeof(check));     for (int i = 0; i < m; i++) cin >> l[i];     for (int i = 0; i < m - 1; i++) {       if (l[i + 1] > l[i]) {         flag = 0;         if (ans[l[i] - 1] != 0) {           if (ans[l[i] - 1] != l[i + 1] - l[i]) {             cout <<  -1 ;             return 0;           } else             flag = 1;         }         ans[l[i] - 1] = l[i + 1] - l[i];         if (check[ans[l[i] - 1] - 1] == 0)           check[ans[l[i] - 1] - 1] = 1;         else if (flag == 0) {           cout <<  -1 ;           return 0;         }       } else {         flag = 0;         if (ans[l[i] - 1] != 0) {           if (ans[l[i] - 1] != l[i + 1] - l[i] + n) {             cout <<  -1 ;             return 0;           } else             flag = 1;         }         ans[l[i] - 1] = l[i + 1] - l[i] + n;         if (check[ans[l[i] - 1] - 1] == 0)           check[ans[l[i] - 1] - 1] = 1;         else if (flag == 0) {           cout <<  -1 ;           return 0;         }       }     }     for (int i = 0; i < n; i++) {       if (ans[i])         cout << ans[i] <<    ;       else {         for (int j = 0; j < n; j++)           if (check[j] == 0) {             cout << j + 1 <<    ;             check[j] = 1;             break;           }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct node {     int x, id;   } s[100101];   bool cmp(node a, node b) { return a.x < b.x; }   int main() {     int n, i, j, x;     cin >> n;     for (i = 0; i < n; i++) {       cin >> s[i].x;       s[i].id = i + 1;     }     sort(s, s + n, cmp);     if (n % 2)       x = n / 2 + 1;     else       x = n / 2;     cout << x << endl;     for (i = 0; i < n; i += 2) cout << s[i].id <<    ;     cout << endl << n - x << endl;     for (i = 1; i < n; i += 2) cout << s[i].id <<    ;     cout << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 1e5 + 9, MAX2 = 3e5 + 9;   const long long MOD = 1e9 + 7;   vector<pair<int, int> > g[MAX];   pair<int, int> e[MAX2];   int h[MAX], mark[MAX2], dp[MAX], par[MAX];   bool vis[MAX];   void dfs(int v, int height) {     vis[v] = true;     h[v] = height;     for (auto x : g[v]) {       int u = x.first;       if (!vis[u]) {         mark[x.second] = true;         par[u] = v;         dfs(u, height + 1);       }     }   }   void dfs2(int v) {     dp[v] = h[v];     bool f = false;     if (v == 2) f = true;     for (auto x : g[v]) {       int u = x.first;       if (mark[x.second]) {         if (par[u] == v) {           dfs2(u);           dp[v] = min(dp[v], dp[u]);         }         continue;       }       dp[v] = min(dp[v], h[u]);     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     memset(par, -1, sizeof(par));     int n, m;     cin >> n >> m;     for (int i = 0; i < m; i++) {       int v, u;       cin >> v >> u;       v--, u--;       g[v].push_back({u, i});       g[u].push_back({v, i});       e[i] = {v, u};     }     memset(vis, 0, sizeof(vis));     dfs(0, 0);     dfs2(0);     for (int i = 0; i < m; i++) {       if (!mark[i]) continue;       int v = e[i].first, u = e[i].second;       if (v != par[u]) swap(v, u);       if (dp[u] > h[v]) return cout <<  0 n , 0;     }     for (int i = 0; i < m; i++) {       int v = e[i].first, u = e[i].second;       if (mark[i]) {         if (v != par[u]) swap(v, u);       } else {         if (h[v] < h[u]) swap(v, u);       }       cout << v + 1 <<     << u + 1 <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int a[500], c, i, n, big;   int main() {     while (~scanf(  %d %d , &n, &c)) {       for (i = 0; i < n; i++) {         scanf(  %d , &a[i]);       }       big = 0;       for (i = 0; i < n - 1; i++) {         if (a[i] - a[i + 1] - c > big) big = a[i] - a[i + 1] - c;       }       printf( %d n , big);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int dist[2 * 100000 + 2 + 5], N, K;   vector<int> G[2 * 100000 + 2 + 5];   void addedge(const string &wall, const string &wall2, int i, int offs) {     int here = i + offs, there = i + N - offs;     if (wall[i] ==  X ) return;     if (i != 0 && wall[i - 1] !=  X ) G[here].push_back(here - 1);     if (i == N - 1 || wall[i + 1] !=  X ) G[here].push_back(here + 1);     if (i + K >= N) {       G[here].push_back(2 * N);     } else if (wall2[i + K] !=  X ) {       G[here].push_back(there + K);     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     string L, R;     cin >> N >> K >> L >> R;     for (int i = 0; i < N; i++) {       addedge(L, R, i, 0);       addedge(R, L, i, N);     }     memset(dist, -1, sizeof(dist));     queue<int> q;     dist[0] = 0;     q.push(0);     while (!q.empty()) {       int fr = q.front(), d = dist[fr];       q.pop();       for (int to : G[fr]) {         if (dist[to] == -1 && (to % N > d || to >= 2 * N)) {           dist[to] = d + 1;           q.push(to);         }       }     }     if (dist[2 * N] != -1 || dist[2 * N + 1] != -1)       cout <<  YES n ;     else       cout <<  NO n ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int a, b;       cin >> a >> b;       if (b > a)         cout << b - a << endl;       else {         if (a % b) {           cout << a / b * b + b - a << endl;         } else           cout << 0 << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = (int)1e5 + 5;   const int INF = (int)1e9 + 9;   const int MOD = (int)1e9 + 7;   void go(int x) {     cout << x;     exit(0);   }   vector<int> g[N];   set<int> st[N];   int c[N];   bool used[N];   int main() {     int n, m, cnt = -1, ans = -1;     cin >> n >> m;     for (int i = 1; i <= n; i++) {       scanf( %d , &c[i]);       used[c[i]] = 1;     }     for (int i = 1; i <= m; i++) {       int u, v;       scanf( %d%d , &u, &v);       g[u].push_back(v);       g[v].push_back(u);       used[c[u]] = 1;       used[c[v]] = 1;       if (c[u] == c[v]) {         continue;       }       st[c[u]].insert(c[v]);       st[c[v]].insert(c[u]);     }     for (int i = 1; i <= 1e5; i++) {       if (used[i] && (int)st[i].size() > cnt) {         cnt = (int)st[i].size();         ans = i;       }     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   int h[100005], ans[100005];   int l[100005], r[100005], w[100005];   vector<int> mid2[100005];   int lo2[100005], hi2[100005];   vector<int> cur[100005];   struct st {     int le, ri, len, all;   };   st seg[400005];   st update_seg(st a, st b) {     st res;     res.len = a.len + b.len;     res.all = max(max(a.all, b.all), a.ri + b.le);     if (a.len == a.le)       res.le = a.len + b.le;     else       res.le = a.le;     if (b.len == b.le)       res.ri = a.ri + b.len;     else       res.ri = b.ri;     return res;   }   void update(int n, int s, int e, int idx, int v) {     if (s == e) {       seg[n].le = max(0, v);       seg[n].ri = max(0, v);       seg[n].all = max(0, v);       seg[n].len = 1;     } else {       int mid = (s + e) / 2;       if (idx <= mid)         update(n + n, s, mid, idx, v);       else         update(n + n + 1, mid + 1, e, idx, v);       seg[n] = update_seg(seg[n + n], seg[n + n + 1]);     }   }   st query(int n, int s, int e, int l, int r) {     if (s > r || l > e) {       st res;       res.le = res.ri = res.len = res.all = 0;       return res;     }     if (l <= s && e <= r) return seg[n];     int mid = (s + e) / 2;     st q1 = query(n + n, s, mid, l, r);     st q2 = query(n + n + 1, mid + 1, e, l, r);     return update_seg(q1, q2);   }   int main() {     int n, q;     scanf( %d , &n);     vector<int> v;     for (int i = 1; i <= n; i++) {       scanf( %d , &h[i]);       v.push_back(h[i]);     }     sort(v.begin(), v.end());     v.erase(unique(v.begin(), v.end()), v.end());     for (int i = 1; i <= n; i++) {       int idx = lower_bound(v.begin(), v.end(), h[i]) - v.begin();       cur[idx].push_back(i);     }     scanf( %d , &q);     for (int i = 1; i <= q; i++) {       scanf( %d%d%d , &l[i], &r[i], &w[i]);       lo2[i] = 0, hi2[i] = v.size() - 1;     }     while (1) {       for (int i = 0; i < v.size(); i++) {         mid2[i].clear();         int h = v[i];         int idx = lower_bound(v.begin(), v.end(), h) - v.begin();         for (int j = 0; j < cur[idx].size(); j++) {           int k = cur[idx][j];           update(1, 1, n, k, 0);         }       }       bool ok = 1;       for (int i = 1; i <= q; i++) {         if (lo2[i] <= hi2[i]) {           int mid = (lo2[i] + hi2[i]) / 2;           mid2[mid].push_back(i);           ok = 0;         }       }       if (ok) break;       for (int i = v.size() - 1; i >= 0; i--) {         int h = v[i];         int idx = lower_bound(v.begin(), v.end(), h) - v.begin();         for (int j = 0; j < cur[idx].size(); j++) {           int k = cur[idx][j];           update(1, 1, n, k, 1);         }         for (int j = 0; j < mid2[i].size(); j++) {           int idx = mid2[i][j];           st q = query(1, 1, n, l[idx], r[idx]);           if (q.all >= w[idx]) {             lo2[idx] = i + 1;             ans[idx] = i;           } else {             hi2[idx] = i - 1;           }         }       }     }     for (int i = 1; i <= q; i++) printf( %d n , v[ans[i]]);   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 100000 + 10;   bool lucky(int x) {     while (x) {       if (x % 10 != 4 && x % 10 != 7) {         return false;       }       x /= 10;     }     return true;   }   int id[maxn], a[maxn], pos[maxn], n;   bool f[maxn];   bool check() {     for (int i = 0; i + 1 < n; ++i) {       if (a[i + 1] < a[i]) {         return false;       }     }     return true;   }   bool comp(int x, int y) { return a[x] < a[y]; }   int main() {     while (scanf( %d , &n) != EOF) {       int c = -1;       for (int i = 0; i < n; ++i) {         scanf( %d , a + i);         if (lucky(a[i])) c = i;         id[i] = i;       }       if (c == -1) {         printf( %d n , check() ? 0 : -1);         continue;       }       sort(id, id + n, comp);       for (int i = 0; i < n; ++i) {         pos[id[i]] = i;         f[i] = false;       }       int posc = c;       vector<pair<int, int> > ans;       while (posc != pos[c]) {         ans.push_back(pair<int, int>(posc, id[posc]));         f[posc] = true;         posc = id[posc];       }       f[posc] = true;       for (int i = 0; i < n; ++i) {         if (pos[i] != i && !f[i]) {           ans.push_back(pair<int, int>(posc, i));           int tmp = posc;           posc = i;           while (pos[i] != posc) {             ans.push_back(pair<int, int>(posc, id[posc]));             f[posc] = true;             posc = id[posc];           }           f[posc] = true;           ans.push_back(pair<int, int>(posc, tmp));           posc = tmp;         }       }       printf( %d n , ((int)((ans).size())));       for (int i = 0; i < ((int)((ans).size())); ++i) {         printf( %d %d n , ans[i].first + 1, ans[i].second + 1);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   map<string, string> mp;   map<string, int> stn;   void Print(string cur) {     string res =  / ;     while (cur !=  / ) {       string tmp = cur;       while (int(tmp.size()) &&              ( 0  <= tmp[tmp.size() - 1] && tmp[tmp.size() - 1] <=  9 ))         tmp.erase(tmp.begin() + tmp.size() - 1);       res =  /  + tmp + res;       cur = mp[cur];     }     cout << res << endl;   }   int main() {     int n;     string s, cur =  / ;     cin >> n;     for (int cn = 0; cn < int(n); cn++) {       cin >> s;       if (s ==  pwd ) {         Print(cur);       } else {         cin >> s;         int ssize = s.size();         string acc =   ;         int st = 0;         if (s[0] ==  . ) {           cur = mp[cur];           st = 3;         }         if (s[0] ==  / ) {           cur =  / ;           st = 1;         }         acc =   ;         for (int i = st; i < ssize; i++) {           if (s[i] ==  / ) {             if (acc ==  .. ) {               cur = mp[cur];             } else {               stn[acc]++;               stringstream ss;               string nw;               ss << stn[acc];               ss >> nw;               acc += nw;               mp[acc] = cur;               cur = acc;             }             acc =   ;           } else {             acc += s[i];           }         }         if (acc.size()) {           if (acc ==  .. ) {             cur = mp[cur];           } else {             stn[acc]++;             stringstream ss;             string nw;             ss << stn[acc];             ss >> nw;             acc += nw;             mp[acc] = cur;             cur = acc;           }         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   struct str {     int x1;     int y1;     int x2;     int y2;   };   bool compare(str &a, str &b) {     if (a.x1 < b.x1)       return true;     else if (a.x1 == b.x1) {       if (a.x2 < b.x2)         return true;       else if (a.x2 == b.x2) {         if (a.y1 < b.y1)           return true;         else if (a.y1 <= b.y1) {           return (a.y2 < b.y2);         }       }     }     return false;   }   int main() {     int n;     cin >> n;     vector<str> v(n);     for (int i = 0; i < n; i++) {       cin >> v[i].x1 >> v[i].y1 >> v[i].x2 >> v[i].y2;     }     sort(v.begin(), v.end(), compare);     int x11 = v[0].x1;     int y11 = v[0].y1;     int x22 = v[0].x2;     int y22 = v[0].y2;     int flag = 0, ind = 0, counter = 1;     for (int i = 1; i < n; i++) {       int x1 = max(x11, v[i].x1);       int x2 = min(x22, v[i].x2);       int y1 = max(y11, v[i].y1);       int y2 = min(y22, v[i].y2);       int x1r = x2 - x1;       int y1r = y2 - y1;       if ((x1r < 0 || y1r < 0) && !flag) {         ind = i;       } else {         x11 = x1, y11 = y1, x22 = x2, y22 = y2;         counter++;       }     }     if (counter == n - 1)       cout << x11 <<     << y11 << endl;     else {       x11 = v[ind].x1, y11 = v[ind].y1, x22 = v[ind].x2, y22 = v[ind].y2;       for (int i = 1; i < n; i++) {         int x1 = max(x11, v[i].x1);         int x2 = min(x22, v[i].x2);         int y1 = max(y11, v[i].y1);         int y2 = min(y22, v[i].y2);         int x1r = x2 - x1;         int y1r = y2 - y1;         if ((x1r < 0 || y1r < 0) && !flag) {           ind = i;         } else {           x11 = x1, y11 = y1, x22 = x2, y22 = y2;           counter++;         }       }       cout << x11 <<     << y11 << endl;     }   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   const int m = 1e9 + 7;   int bin_pow(int x, int k) {     if (k == 0) return 1;     int g = bin_pow(x, k / 2);     g = (1ll * g * g) % m;     if (k % 2 > 0) g = (1ll * g * x) % m;     return g;   }   signed main() {     iostream::sync_with_stdio(0);     cin.tie(0);     setlocale(LC_ALL,  Russian );     int tt, n, p, i, j, r, second, ans, add;     vector<int> read, k, cnt, st;     cin >> tt;     for (; tt > 0; tt--) {       cin >> n >> p;       read.assign(n, 0);       k.clear();       cnt.clear();       st.clear();       for (i = 0; i < n; i++) cin >> read[i];       if (p == 1) {         if (n % 2 > 0)           cout <<  1 n ;         else           cout <<  0 n ;         continue;       }       sort(read.begin(), read.end());       for (i = 0; i < n; i++) {         j = i + 1;         while (j < n && read[i] == read[j]) j++;         k.push_back(read[i]);         cnt.push_back(j - i);         i = j - 1;       }       st.push_back(bin_pow(p, k[0]));       for (i = 1; i < k.size(); i++)         st.push_back((1ll * st[i - 1] * bin_pow(p, k[i] - k[i - 1])) % m);       ans = 0;       for (i = k.size() - 1; i >= 0; i--) {         if (cnt[i] % 2 == 0) continue;         j = i - 1;         second = 1;         while (j >= 0) {           for (r = 0; r < k[j + 1] - k[j] && second <= n; r++) second *= p;           if (r < k[j + 1] - k[j] || second > n) break;           add = min(second, cnt[j]);           second -= add;           ans = (ans - 1ll * cnt[j] * st[j] + 2ll * m * m) % m;           cnt[j] -= add;           if (second == 0) break;           j--;         }         if (second > 0) {           while (j >= 0) {             ans = (ans - 1ll * cnt[j] * st[j] + 2ll * m * m) % m;             j--;           }           ans = (ans + st[i]) % m;           break;         }         ans = 0;         i = j + 1;       }       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void add_edge(vector<long long> adj[], long long a, long long b) {     adj[a].push_back(b);     adj[b].push_back(a);   }   class myComparator {    public:     int operator()(int p1, int p2) { return p1 > p2; }   };   long long fun(long long x, long long n) {     long long mid, beg = 1, last = x / 2;     while (beg < last) {       mid = (beg + last) / 2;       long long t = x - mid;       if (t <= n) {         last = mid;       } else {         beg = mid + 1;       }     }     return (x / 2) - last + 1;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     ;     long long n;     cin >> n;     long long t = (2 * n) - 1;     string v = to_string(t);     string s;     long long i;     for (i = 0; i < v.size(); i++) s +=  9 ;     long long num = stoll(s);     if (num > t) {       num /= 10;       s.pop_back();     }     long long ans = 0;     for (i = 0; i < 9; i++) {       string temp = to_string(i);       string ma = temp + s;       long long num = stoll(ma);       if (num > t) break;       ans += fun(num, n);     }     if (n > 4)       cout << ans << endl;     else {       long long k;       long long ans = 1;       for (k = 3; k <= n; k++) ans *= k;       if (n == 4) ans = ans / 2;       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int arr[111];   int main() {     int n;     scanf( %d , &n);     arr[0] = 0;     for (int i = (1); i < (n + 1); ++i) scanf( %d , &arr[i]);     int ans = 0;     if (n % 2 == 0 || n == 1) {       printf( -1 n );       return 0;     }     for (int i = n; i >= 1; i -= 2) {       int tmp = max(arr[i], arr[i - 1]);       ans += tmp;       arr[i] = arr[i - 1] = 0;       arr[(i - 1) / 2] = max(0, arr[(i - 1) / 2] - tmp);     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 2010;   int n, m, k;   char a[MAXN][MAXN];   int pref[MAXN][MAXN];   int getSumLine(int i, int j) {     return pref[i][j + k - 1] - pref[i][j - 1] - pref[i - 1][j + k - 1] +            pref[i - 1][j - 1];   }   int getSumRow(int i, int j) {     return pref[i + k - 1][j] - pref[i - 1][j] - pref[i + k - 1][j - 1] +            pref[i - 1][j - 1];   }   int main() {     scanf( %d%d%d n , &n, &m, &k);     for (int i = 1; i <= n; i++) {       scanf( %s , a[i] + 1);     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         if (a[i][j] ==  * ) {           pref[i][j]++;         }         pref[i][j] += pref[i - 1][j];         pref[i][j] += pref[i][j - 1];         pref[i][j] -= pref[i - 1][j - 1];       }     }     int ans = 0;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         if (i + k - 1 <= n) {           if (getSumRow(i, j) == 0) ans++;         }         if (j + k - 1 <= m && k != 1) {           if (getSumLine(i, j) == 0) ans++;         }       }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int t;   long long int a, b, n, S;   int main() {     cin >> t;     while (t--) {       cin >> a >> b >> n >> S;       if (b >= S) {         cout <<  YES  << endl;         continue;       }       if (a * n + b < S) {         cout <<  NO  << endl;         continue;       }       long long int x = S / n;       x = min(x, a);       long long int res = (S - x * n);       if (res <= b) {         cout <<  YES  << endl;         continue;       }       if (res > b) {         cout <<  NO  << endl;         continue;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct debugger {     template <typename T>     debugger& operator,(const T& v) {       cerr << v <<    ;       return *this;     }   } dbg;   long long gcd(long long a, long long b) { return (b == 0) ? a : gcd(b, a % b); }   int main() {     int n, k;     cin >> n;     cin >> k;     int c[n];     for (int i = 0; i < n; ++i) cin >> c[i];     ;     map<int, int> table;     vector<long long> capitals;     long long csum = 0;     for (int i = 0; i < k; ++i) {       int id;       cin >> id;       id -= 1;       capitals.push_back(c[id]);       ;       ;       csum += c[id];       table[id] = 1;     };     long long ans = 0;     long long ncsum = 0;     for (int i = 0; i < n; ++i) {       if (table[i] != 1) ncsum += c[i];     };     long long dncsum = 0;     for (int i = 0; i < n; ++i) {       int right = (i + 1 == n ? 0 : i + 1);       if (table[i] != 1) {         if (table[right] != 1) {           ;           ;           dncsum += c[i] * c[right];         }       }     };     vector<long long> prefix(k);     for (int i = 0; i < k; ++i) {       if (i == 0)         prefix[i] = capitals[i];       else         prefix[i] = prefix[i - 1] + capitals[i];     }     long long fcsum = 0;     for (int i = 0; i < k; ++i) {       fcsum += capitals[i] * (csum - prefix[i]);       fcsum += capitals[i] * ncsum;     }     ans = fcsum + dncsum;     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   #pragma comment(linker,  /STACK:36777216 )   template <class T>   inline T &RD(T &);   template <class T>   inline void OT(const T &);   inline int RD() {     int x;     return RD(x);   }   inline double &RF(double &);   inline double RF() {     double x;     return RF(x);   }   inline char *RS(char *s);   inline char &RC(char &c);   inline char RC();   inline char &RC(char &c) {     scanf(  %c , &c);     return c;   }   inline char RC() {     char c;     return RC(c);   }   template <class T>   inline T &RDD(T &x) {     char c;     for (c = getchar(); c <  - ; c = getchar())       ;     if (c ==  - ) {       x =  0  - getchar();       for (c = getchar();  0  <= c && c <=  9 ; c = getchar())         x = x * 10 +  0  - c;     } else {       x = c -  0 ;       for (c = getchar();  0  <= c && c <=  9 ; c = getchar())         x = x * 10 + c -  0 ;     }     return x;   }   inline int RDD() {     int x;     return RDD(x);   }   template <class T0, class T1>   inline T0 &RD(T0 &x0, T1 &x1) {     RD(x0), RD(x1);     return x0;   }   template <class T0, class T1, class T2>   inline T0 &RD(T0 &x0, T1 &x1, T2 &x2) {     RD(x0), RD(x1), RD(x2);     return x0;   }   template <class T0, class T1, class T2, class T3>   inline T0 &RD(T0 &x0, T1 &x1, T2 &x2, T3 &x3) {     RD(x0), RD(x1), RD(x2), RD(x3);     return x0;   }   template <class T0, class T1, class T2, class T3, class T4>   inline T0 &RD(T0 &x0, T1 &x1, T2 &x2, T3 &x3, T4 &x4) {     RD(x0), RD(x1), RD(x2), RD(x3), RD(x4);     return x0;   }   template <class T0, class T1, class T2, class T3, class T4, class T5>   inline T0 &RD(T0 &x0, T1 &x1, T2 &x2, T3 &x3, T4 &x4, T5 &x5) {     RD(x0), RD(x1), RD(x2), RD(x3), RD(x4), RD(x5);     return x0;   }   template <class T0, class T1, class T2, class T3, class T4, class T5, class T6>   inline T0 &RD(T0 &x0, T1 &x1, T2 &x2, T3 &x3, T4 &x4, T5 &x5, T6 &x6) {     RD(x0), RD(x1), RD(x2), RD(x3), RD(x4), RD(x5), RD(x6);     return x0;   }   template <class T0, class T1>   inline void OT(const T0 &x0, const T1 &x1) {     OT(x0), OT(x1);   }   template <class T0, class T1, class T2>   inline void OT(const T0 &x0, const T1 &x1, const T2 &x2) {     OT(x0), OT(x1), OT(x2);   }   template <class T0, class T1, class T2, class T3>   inline void OT(const T0 &x0, const T1 &x1, const T2 &x2, const T3 &x3) {     OT(x0), OT(x1), OT(x2), OT(x3);   }   template <class T0, class T1, class T2, class T3, class T4>   inline void OT(const T0 &x0, const T1 &x1, const T2 &x2, const T3 &x3,                  const T4 &x4) {     OT(x0), OT(x1), OT(x2), OT(x3), OT(x4);   }   template <class T0, class T1, class T2, class T3, class T4, class T5>   inline void OT(const T0 &x0, const T1 &x1, const T2 &x2, const T3 &x3,                  const T4 &x4, const T5 &x5) {     OT(x0), OT(x1), OT(x2), OT(x3), OT(x4), OT(x5);   }   template <class T0, class T1, class T2, class T3, class T4, class T5, class T6>   inline void OT(const T0 &x0, const T1 &x1, const T2 &x2, const T3 &x3,                  const T4 &x4, const T5 &x5, const T6 &x6) {     OT(x0), OT(x1), OT(x2), OT(x3), OT(x4), OT(x5), OT(x6);   }   inline char &RC(char &a, char &b) {     RC(a), RC(b);     return a;   }   inline char &RC(char &a, char &b, char &c) {     RC(a), RC(b), RC(c);     return a;   }   inline char &RC(char &a, char &b, char &c, char &d) {     RC(a), RC(b), RC(c), RC(d);     return a;   }   inline char &RC(char &a, char &b, char &c, char &d, char &e) {     RC(a), RC(b), RC(c), RC(d), RC(e);     return a;   }   inline char &RC(char &a, char &b, char &c, char &d, char &e, char &f) {     RC(a), RC(b), RC(c), RC(d), RC(e), RC(f);     return a;   }   inline char &RC(char &a, char &b, char &c, char &d, char &e, char &f, char &g) {     RC(a), RC(b), RC(c), RC(d), RC(e), RC(f), RC(g);     return a;   }   inline double &RF(double &a, double &b) {     RF(a), RF(b);     return a;   }   inline double &RF(double &a, double &b, double &c) {     RF(a), RF(b), RF(c);     return a;   }   inline double &RF(double &a, double &b, double &c, double &d) {     RF(a), RF(b), RF(c), RF(d);     return a;   }   inline double &RF(double &a, double &b, double &c, double &d, double &e) {     RF(a), RF(b), RF(c), RF(d), RF(e);     return a;   }   inline double &RF(double &a, double &b, double &c, double &d, double &e,                     double &f) {     RF(a), RF(b), RF(c), RF(d), RF(e), RF(f);     return a;   }   inline double &RF(double &a, double &b, double &c, double &d, double &e,                     double &f, double &g) {     RF(a), RF(b), RF(c), RF(d), RF(e), RF(f), RF(g);     return a;   }   inline void RS(char *s1, char *s2) { RS(s1), RS(s2); }   inline void RS(char *s1, char *s2, char *s3) { RS(s1), RS(s2), RS(s3); }   template <class T0, class T1>   inline void RDD(const T0 &a, const T1 &b) {     RDD(a), RDD(b);   }   template <class T0, class T1, class T2>   inline void RDD(const T0 &a, const T1 &b, const T2 &c) {     RDD(a), RDD(b), RDD(c);   }   template <class T>   inline void RST(T &A) {     memset(A, 0, sizeof(A));   }   template <class T>   inline void FLC(T &A, int x) {     memset(A, x, sizeof(A));   }   template <class T>   inline void CLR(T &A) {     A.clear();   }   template <class T0, class T1>   inline void RST(T0 &A0, T1 &A1) {     RST(A0), RST(A1);   }   template <class T0, class T1, class T2>   inline void RST(T0 &A0, T1 &A1, T2 &A2) {     RST(A0), RST(A1), RST(A2);   }   template <class T0, class T1, class T2, class T3>   inline void RST(T0 &A0, T1 &A1, T2 &A2, T3 &A3) {     RST(A0), RST(A1), RST(A2), RST(A3);   }   template <class T0, class T1, class T2, class T3, class T4>   inline void RST(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4) {     RST(A0), RST(A1), RST(A2), RST(A3), RST(A4);   }   template <class T0, class T1, class T2, class T3, class T4, class T5>   inline void RST(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5) {     RST(A0), RST(A1), RST(A2), RST(A3), RST(A4), RST(A5);   }   template <class T0, class T1, class T2, class T3, class T4, class T5, class T6>   inline void RST(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5, T6 &A6) {     RST(A0), RST(A1), RST(A2), RST(A3), RST(A4), RST(A5), RST(A6);   }   template <class T0, class T1>   inline void FLC(T0 &A0, T1 &A1, int x) {     FLC(A0, x), FLC(A1, x);   }   template <class T0, class T1, class T2>   inline void FLC(T0 &A0, T1 &A1, T2 &A2, int x) {     FLC(A0, x), FLC(A1, x), FLC(A2, x);   }   template <class T0, class T1, class T2, class T3>   inline void FLC(T0 &A0, T1 &A1, T2 &A2, T3 &A3, int x) {     FLC(A0, x), FLC(A1, x), FLC(A2, x), FLC(A3, x);   }   template <class T0, class T1, class T2, class T3, class T4>   inline void FLC(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, int x) {     FLC(A0, x), FLC(A1, x), FLC(A2, x), FLC(A3, x), FLC(A4, x);   }   template <class T0, class T1, class T2, class T3, class T4, class T5>   inline void FLC(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5, int x) {     FLC(A0, x), FLC(A1, x), FLC(A2, x), FLC(A3, x), FLC(A4, x), FLC(A5, x);   }   template <class T0, class T1, class T2, class T3, class T4, class T5, class T6>   inline void FLC(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5, T6 &A6, int x) {     FLC(A0, x), FLC(A1, x), FLC(A2, x), FLC(A3, x), FLC(A4, x), FLC(A5, x),         FLC(A6, x);   }   template <class T>   inline void CLR(priority_queue<T, vector<T>, less<T> > &Q) {     while (!Q.empty()) Q.pop();   }   template <class T>   inline void CLR(priority_queue<T, vector<T>, greater<T> > &Q) {     while (!Q.empty()) Q.pop();   }   template <class T0, class T1>   inline void CLR(T0 &A0, T1 &A1) {     CLR(A0), CLR(A1);   }   template <class T0, class T1, class T2>   inline void CLR(T0 &A0, T1 &A1, T2 &A2) {     CLR(A0), CLR(A1), CLR(A2);   }   template <class T0, class T1, class T2, class T3>   inline void CLR(T0 &A0, T1 &A1, T2 &A2, T3 &A3) {     CLR(A0), CLR(A1), CLR(A2), CLR(A3);   }   template <class T0, class T1, class T2, class T3, class T4>   inline void CLR(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4) {     CLR(A0), CLR(A1), CLR(A2), CLR(A3), CLR(A4);   }   template <class T0, class T1, class T2, class T3, class T4, class T5>   inline void CLR(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5) {     CLR(A0), CLR(A1), CLR(A2), CLR(A3), CLR(A4), CLR(A5);   }   template <class T0, class T1, class T2, class T3, class T4, class T5, class T6>   inline void CLR(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5, T6 &A6) {     CLR(A0), CLR(A1), CLR(A2), CLR(A3), CLR(A4), CLR(A5), CLR(A6);   }   template <class T>   inline void CLR(T &A, int n) {     for (int i = 0; i < int(n); ++i) CLR(A[i]);   }   template <class T>   inline T &SRT(T &A) {     sort(A.begin(), A.end());     return A;   }   template <class T, class C>   inline T &SRT(T &A, C B) {     sort(A.begin(), A.end(), B);     return A;   }   template <class T>   inline T &UNQ(T &A) {     A.resize(unique(SRT(A).begin(), SRT(A).end()) - A.begin());     return A;   }   const int dx4[] = {-1, 0, 1, 0};   const int dy4[] = {0, 1, 0, -1};   const int dx8[] = {-1, 0, 1, 0, -1, -1, 1, 1};   const int dy8[] = {0, 1, 0, -1, -1, 1, -1, 1};   const int dxhorse[] = {-2, -2, -1, -1, 1, 1, 2, 2};   const int dyhorse[] = {1, -1, 2, -2, 2, -2, 1, -1};   const int MOD = 1000000007;   const int INF = 0x3f3f3f3f;   const double EPS = 1e-9;   const double OO = 1e15;   const double PI = acos(-1.0);   template <class T>   inline void checkMin(T &a, const T b) {     if (b < a) a = b;   }   template <class T>   inline void checkMax(T &a, const T b) {     if (a < b) a = b;   }   template <class T>   inline void checkMin(T &a, T &b, const T x) {     checkMin(a, x), checkMin(b, x);   }   template <class T>   inline void checkMax(T &a, T &b, const T x) {     checkMax(a, x), checkMax(b, x);   }   template <class T, class C>   inline void checkMin(T &a, const T b, C c) {     if (c(b, a)) a = b;   }   template <class T, class C>   inline void checkMax(T &a, const T b, C c) {     if (c(a, b)) a = b;   }   template <class T>   inline T min(T a, T b, T c) {     return min(min(a, b), c);   }   template <class T>   inline T max(T a, T b, T c) {     return max(max(a, b), c);   }   template <class T>   inline T min(T a, T b, T c, T d) {     return min(min(a, b), min(c, d));   }   template <class T>   inline T max(T a, T b, T c, T d) {     return max(max(a, b), max(c, d));   }   template <class T>   inline T sqr(T a) {     return a * a;   }   template <class T>   inline T cub(T a) {     return a * a * a;   }   inline int ceil(int x, int y) { return (x - 1) / y + 1; }   inline int sgn(double x) { return x < -EPS ? -1 : x > EPS; }   inline int sgn(double x, double y) { return sgn(x - y); }   template <class T>   inline T &RD(T &x) {     char c;     for (c = getchar(); c <  0 ; c = getchar())       ;     x = c -  0 ;     for (c = getchar();  0  <= c && c <=  9 ; c = getchar()) x = x * 10 + c -  0 ;     return x;   }   inline double &RF(double &x) {     scanf( %lf , &x);     return x;   }   inline char *RS(char *s) {     scanf( %s , s);     return s;   }   int Case;   template <class T>   inline void OT(const T &x) {     cout << x << endl;   }   const int N = 309;   int a[N][N];   int t, tt;   int tp, tu, td;   int n, m;   int U[N][N], D[N][N], L[N][N], R[N][N];   struct ANS {     int T;     int lx, ly, rx, ry;   } ans;   void upd(int lx, int rx, int ly, int ry, int T) {     if (ans.T == -1 || abs(T - t) < abs(ans.T - t)) {       ans.T = T;       ans.lx = lx;       ans.ly = ly;       ans.rx = rx;       ans.ry = ry;     }   }   set<pair<int, int> > hh;   int f(int pre, int now) {     if (pre < now) return tu;     if (pre > now) return td;     return tp;   }   int main() {     RD(n, m);     RD(t, tp, tu, td);     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= m; ++j) RD(a[i][j]);     RST(U, D, L, R);     ans.T = -1;     for (int i = 1; i <= n; ++i) {       for (int j = 2; j <= m; ++j) {         L[i][j] = L[i][j - 1];         if (a[i][j] > a[i][j - 1])           L[i][j] += tu;         else if (a[i][j] == a[i][j - 1])           L[i][j] += tp;         else           L[i][j] += td;       }     }     for (int i = 2; i <= n; ++i) {       for (int j = 1; j <= m; ++j) {         U[i][j] = U[i - 1][j];         if (a[i][j] < a[i - 1][j])           U[i][j] += tu;         else if (a[i][j] == a[i - 1][j])           U[i][j] += tp;         else           U[i][j] += td;       }     }     for (int i = n - 1; i >= 1; --i) {       for (int j = 1; j <= m; ++j) {         D[i][j] = D[i + 1][j];         if (a[i][j] < a[i + 1][j])           D[i][j] += tu;         else if (a[i][j] == a[i + 1][j])           D[i][j] += tp;         else           D[i][j] += td;       }     }     for (int i = 1; i <= n; ++i) {       for (int j = m - 1; j >= 1; --j) {         R[i][j] = R[i][j + 1];         if (a[i][j] > a[i][j + 1])           R[i][j] += tu;         else if (a[i][j] == a[i][j + 1])           R[i][j] += tp;         else           R[i][j] += td;       }     }     for (int lx = 1; lx <= n; ++lx)       for (int rx = lx + 3 - 1; rx <= n; ++rx) {         hh.clear();         int head = 1;         int tot = 0, now;         for (int ry = 1; ry <= m; ++ry) {           if (ry != 1) {             tot += f(a[lx][ry - 1], a[lx][ry]);             tot += f(a[rx][ry], a[rx][ry - 1]);           }           now = tot + D[lx][ry] - D[rx][ry];           if (!hh.empty()) {             static set<pair<int, int> >::iterator iter, liter, riter;             iter = hh.lower_bound(make_pair(t - now, 0));             liter = iter, riter = iter;             if (liter != hh.begin()) liter--;             if (riter != hh.end()) riter++;             if (iter != hh.end()) {               pair<int, int> me = *iter;               upd(lx, rx, me.second, ry, now + me.first);             }             if (liter != hh.end()) {               pair<int, int> me = *liter;               upd(lx, rx, me.second, ry, now + me.first);             }             if (riter != hh.end()) {               pair<int, int> me = *riter;               upd(lx, rx, me.second, ry, now + me.first);             }           }           while (ry + 1 - head + 1 >= 3) {             pair<int, int> me;             me.first = 0;             me.second = head;             me.first += U[rx][head] - U[lx][head];             me.first -= L[lx][head];             me.first -= R[rx][1] - R[rx][head];             hh.insert(me);             ++head;           }         }       }     cout << ans.lx <<     << ans.ly <<     << ans.rx <<     << ans.ry << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1000000007;   struct Node {     int t[26], len, f, tf, d, s;   } a[1000500];   int tn, las;   void linkd(int u) {     int fa = a[u].f;     a[u].d = a[u].len - a[fa].len;     a[u].tf = (a[u].d == a[fa].d && a[u].d * 2 <= a[u].len) ? a[fa].tf : u;   }   void ins(int k, int c, char *str) {     int p = las;     while (str[k - a[p].len - 1] != c) p = a[p].f;     if (!a[p].t[c]) {       int np = las = ++tn, v;       for (v = a[p].f; str[k - a[v].len - 1] != c; v = a[v].f)         ;       if (!a[v].t[c])         a[np].f = 2;       else         a[np].f = a[v].t[c];       a[a[p].t[c] = np].len = a[p].len + 2;       linkd(np);     } else       las = a[p].t[c];   }   int f[1000500];   void dp(int k) {     for (int p = las; p > 2; p = a[a[p].tf].f) {       int tl = a[a[p].tf].len;       a[p].s = f[k - tl];       if (a[p].tf != p) a[p].s = (a[a[p].f].s + a[p].s) % mod;       if (!(k & 1)) f[k] = (f[k] + a[p].s) % mod;     }   }   void Init() {     a[1].f = a[2].f = 1;     a[1].len = -1;     las = tn = 2;   }   int n;   char s[1000500], s2[1000500];   int main() {     scanf( %s , s2 + 1);     n = strlen(s2 + 1);     if (n & 1) {       puts( 0 );       return 0;     }     for (int i = 1; i + i <= n; i++) {       s[i * 2 - 1] = s2[n - i + 1];       s[i * 2] = s2[i];     }     s[0] = -1;     f[0] = 1;     Init();     for (int i = 1; i <= n; i++) {       ins(i, s[i] -=  a , s);       dp(i);     }     printf( %d , f[n]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   namespace IO {   const int sz = 1 << 15;   char inbuf[sz], outbuf[sz];   char *pinbuf = inbuf + sz;   char *poutbuf = outbuf;   inline char _getchar() {     if (pinbuf == inbuf + sz) fread(inbuf, 1, sz, stdin), pinbuf = inbuf;     return *(pinbuf++);   }   inline void _putchar(char x) {     if (poutbuf == outbuf + sz) fwrite(outbuf, 1, sz, stdout), poutbuf = outbuf;     *(poutbuf++) = x;   }   inline void flush() {     if (poutbuf != outbuf)       fwrite(outbuf, 1, poutbuf - outbuf, stdout), poutbuf = outbuf;   }   }  // namespace IO   inline int read() {     int x = 0, p = 1;     char c = IO::_getchar();     while (c <= 32) c = IO::_getchar();     if (c == 45) p = -p, c = IO::_getchar();     while (c > 32) x = x * 10 + c - 48, c = IO::_getchar();     return x * p;   }   namespace Mymath {   long long qp(long long x, long long p, long long mod) {     long long ans = 1;     while (p) {       if (p & 1) ans = ans * x % mod;       x = x * x % mod;       p >>= 1;     }     return ans;   }   long long inv(long long x, long long mod) { return qp(x, mod - 2, mod); }   long long C(long long N, long long K, long long fact[], long long mod) {     return fact[N] * inv(fact[K], mod) % mod * inv(fact[N - K], mod) % mod;   }   template <typename Tp>   Tp gcd(Tp A, Tp B) {     if (B == 0) return A;     return gcd(B, A % B);   }   template <typename Tp>   Tp lcm(Tp A, Tp B) {     return A * B / gcd(A, B);   }   };  // namespace Mymath   namespace fwt {   using namespace Mymath;   void FWT(int a[], int n, long long mod) {     for (int d = 1; d < n; d <<= 1)       for (int m = d << 1, i = 0; i < n; i += m)         for (int j = 0; j < d; j++) {           int x = a[i + j], y = a[i + j + d];           a[i + j] = (x + y) % mod, a[i + j + d] = (x - y + mod) % mod;         }   }   void UFWT(int a[], int n, long long mod) {     long long rev = inv(2, mod);     for (int d = 1; d < n; d <<= 1)       for (int m = d << 1, i = 0; i < n; i += m)         for (int j = 0; j < d; j++) {           int x = a[i + j], y = a[i + j + d];           a[i + j] = 1LL * (x + y) * rev % mod,                 a[i + j + d] = (1LL * (x - y) * rev % mod + mod) % mod;         }   }   void solve(int a[], int b[], int n, long long mod) {     FWT(a, n, mod);     FWT(b, n, mod);     for (int i = 0; i < n; i++) a[i] = 1LL * a[i] * b[i] % mod;     UFWT(a, n, mod);   }   };  // namespace fwt   namespace Maxflow {   const int Maxn = 1005;   struct edge {     int to, rev, cap;     edge(int _to, int _rev, int _cap) { to = _to, rev = _rev, cap = _cap; }   };   int src = 1002, snk = 1003;   vector<edge> G[Maxn];   int dist[Maxn], seen[Maxn];   int n;   void Clear() {     for (int i = 0; i < Maxn; i++) G[i].clear();   }   void bfs(int s) {     for (int i = 0; i < Maxn; i++) dist[i] = -1;     dist[s] = 0;     queue<int> Q;     Q.push(s);     while (!Q.empty()) {       int x = Q.front();       Q.pop();       for (int i = 0; i < G[x].size(); i++) {         edge &e = G[x][i];         if (e.cap && dist[e.to] == -1) {           dist[e.to] = dist[x] + 1;           Q.push(e.to);         }       }     }   }   int dfs(int now, int dest, int fl) {     if (now == dest) return fl;     for (int &i = seen[now]; i < G[now].size(); i++) {       edge &ed = G[now][i];       if (ed.cap && dist[ed.to] == dist[now] + 1) {         int f = dfs(ed.to, dest, min(fl, ed.cap));         if (f) {           ed.cap -= f;           G[ed.to][ed.rev].cap += f;           return f;         }       }     }     return 0;   }   int dinic(int s = src, int t = snk) {     int ret = 0;     while (1) {       memset(seen, 0, sizeof(seen));       bfs(s);       if (dist[t] == -1) return ret;       int f = dfs(s, t, 2147483647);       while (f) {         ret += f;         f = dfs(s, t, 2147483647);       }     }   }   };  // namespace Maxflow   namespace Geometry {   struct iP {     long long x, y;     iP(long long _x, long long _y) { x = _x, y = _y; }     iP() { x = y = 0; }     iP operator+(iP p) { return iP(x + p.x, y + p.y); }     iP operator-(iP p) { return iP(x - p.x, y - p.y); }     iP operator*(long long k) { return iP(x * k, y * k); }     long long det(iP p) { return x * p.y - y * p.x; }     long long dot(iP p) { return x * p.x + y * p.y; }     long long dist() { return x * x + y * y; }     bool operator<(const iP &p) const {       if (x != p.x) return x < p.x;       return y < p.y;     }   };   struct dP {     double x, y;     dP(double _x, double _y) { x = _x, y = _y; }     dP() { x = y = 0.0; }     dP operator+(dP p) { return dP(x + p.x, y + p.y); }     dP operator-(dP p) { return dP(x - p.x, y - p.y); }     dP operator*(double k) { return dP(x * k, y * k); }     double det(dP p) { return x * p.y - y * p.x; }     double dot(dP p) { return x * p.x + y * p.y; }     double dist() { return x * x + y * y; }     bool operator<(const dP &p) const {       if (x != p.x) return x < p.x;       return y < p.y;     }   };   vector<iP> convex_hull(iP X[], int l) {     vector<iP> ret;     sort(X + 1, X + 1 + l);     ret.push_back(X[1]);     for (int i = 2; i <= l; i++) {       while (ret.size() >= 2 &&              (ret[ret.size() - 2] - X[i]).det(ret[ret.size() - 1] - X[i]) >= 0) {         ret.pop_back();       }       ret.push_back(X[i]);     }     int rs = ret.size() + 1;     for (int i = l - 1; i >= 1; i--) {       while (ret.size() >= rs &&              (ret[ret.size() - 2] - X[i]).det(ret[ret.size() - 1] - X[i]) >= 0) {         ret.pop_back();       }       ret.push_back(X[i]);     }     return ret;   }   };  // namespace Geometry   int main() {     int n, m;     n = read();     m = read();     if (n > m) swap(n, m);     long long tot = 1ll * n * m;     if (n == 1) {       m = m % 6;       if (m == 0) {         cout << tot / 2 * 2 << endl;       } else if (m == 1) {         cout << tot / 2 * 2 << endl;       } else if (m == 2) {         cout << (tot / 2 - 1) * 2 << endl;       } else if (m == 3) {         cout << (tot / 2 - 1) * 2 << endl;       } else if (m == 4) {         cout << (tot / 2 - 1) * 2 << endl;       } else if (m == 5) {         cout << (tot / 2) * 2 << endl;       }     } else if (n == 2) {       if (m == 2) {         cout << 0 << endl;         return 0;       }       if (m == 3) {         cout << 4 << endl;         return 0;       }       if (m == 7) {         cout << 12 << endl;         return 0;       }       cout << tot << endl;       return 0;     } else {       cout << tot / 2 * 2 << endl;     }     return ~~(0 ^ 0 ^ 0);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int m, n, i, j, k, a, b;     scanf( %d , &a);     if (a == 1)       printf( 1 n );     else {       printf( %d n , (a - 1) * a / 2 * 12 + 1);     }   }


#include <bits/stdc++.h>   using namespace std;   const long long M = 1e9 + 7;   void solve() {     long long n;     cin >> n;     map<long long, long long> m;     for (long long i = 0; i < n; i++) {       long long x;       cin >> x;       m[x]++;     }     long long mx = 0;     long long ans = 0;     for (auto it : m) {       ans += min(mx, it.second);       mx = max(mx, it.second);     }     cout << ans <<   n ;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     long long t = 1;     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   bool cmp(pair<long long int, char> p1, pair<long long int, char> p2) {     return p1.first > p2.first;   }   vector<vector<long long int> > graph;   vector<bool> vis;   vector<vector<long long int> > level;   vector<long long int> d, childp;   void dfs(long long int node, long long int prev) {     vis[node] = true;     d[node] = prev + 1;     long long int temp = 1, i;     long long int x = 0, k = 1;     for (i = 0; i < graph[node].size(); i++) {       if (vis[graph[node][i]] == false) {         dfs(graph[node][i], d[node]);         x += childp[graph[node][i]];       }     }     childp[node] = x + 1;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int n, i, p;     cin >> n;     long double ans[n + 1];     graph.resize(n + 1);     level.resize(n + 1);     vis.resize(n + 1);     d.resize(n + 1);     childp.resize(n + 1);     for (i = 1; i <= n; i++) {       vis[i] = false;       d[i] = 0;       ans[i] = 0.0;       childp[i] = 0;     }     for (i = 2; i <= n; i++) {       cin >> p;       graph[p].push_back(i);       graph[i].push_back(p);     }     dfs(1, 0);     for (i = 1; i <= n; i++)       printf( %0.8lf  , ((n - childp[i] - d[i] + 1) / 2.0) + d[i]);   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 0x7fffffff;   long long a[510][510], n;   int main() {     while (~scanf( %I64d , &n)) {       if (n == 1) {         scanf( %I64d , &n);         printf( 1 n );         continue;       }       for (int i = 1; i <= n; ++i) {         for (int j = 1; j <= n; ++j) scanf( %I64d , &a[i][j]);       }       int zr = 0, zc;       for (int i = 1; i <= n && !zr; ++i) {         for (int j = 1; j <= n && !zr; ++j) {           if (a[i][j] == 0) {             zr = i;             zc = j;           }         }       }       long long zv, sum = 0, zsum = 0;       for (int i = 1; i <= n; ++i) zsum += a[zr][i];       if (zr == 1) {         for (int i = 1; i <= n; ++i) sum += a[n][i];         zv = sum - zsum;       } else {         for (int i = 1; i <= n; ++i) sum += a[1][i];         zv = sum - zsum;       }       if (zv <= 0) {         printf( -1 n );         continue;       }       a[zr][zc] = zv;       bool ok = true;       for (int i = 1; i <= n; ++i) {         long long tmpsum = 0;         for (int j = 1; j <= n; ++j) tmpsum += a[i][j];         if (tmpsum != sum) {           ok = false;           break;         }         tmpsum = 0;         for (int j = 1; j <= n; ++j) tmpsum += a[j][i];         if (tmpsum != sum) {           ok = false;           break;         }       }       long long tmpsum = 0;       for (int i = 1; i <= n; ++i) tmpsum += a[i][i];       if (tmpsum != sum) ok = false;       tmpsum = 0;       for (int i = n; i >= 1; --i) tmpsum += a[i][n + 1 - i];       if (tmpsum != sum) ok = false;       if (ok) {         printf( %I64d n , zv);       } else         printf( -1 n );     }     return 0;   }


#include <bits/stdc++.h>   const int N = 105;   int n, m, i, j, k, s[N], h[N], id[N], a[N], l[N], r[N];   int fr[N], fl[N];   bool cmp(int x, int y) { return s[x] < s[y]; }   int main() {     scanf( %d%d , &n, &m);     for (i = 1; i <= m; ++i) scanf( %d%d , s + i, h + i), id[i] = i;     if (m == 1) {       printf( %d n1 n , s[1]);       return 0;     }     std::sort(id + 1, id + m + 1, cmp);     for (i = 1; i <= n; ++i) scanf( %d , a + i);     for (i = 1; i <= m; ++i) {       long long ss;       ss = h[i];       for (l[i] = s[i]; l[i] && ss >= 0; ss += a[--l[i]])         ;       ++l[i];       ss = h[i];       for (r[i] = s[i]; r[i] <= n && ss >= 0; ss += a[++r[i]])         ;       --r[i];     }     fr[m] = m;     for (i = m - 1; i; --i) {       for (j = i + 1; j <= m; ++j)         if (fr[j] && l[id[j]] <= s[id[i]]) fr[i] = j;     }     fl[1] = 1;     for (i = 2; i <= m; ++i) {       for (j = 1; j < i; ++j)         if (fl[j] && r[id[j]] >= s[id[i]]) fl[i] = j;     }     if (fr[1]) {       static bool bb[N];       static int st[N];       int w = 0;       printf( %d n , s[id[1]]);       for (j = 1; j < m; j = fr[j]) st[++w] = id[j];       st[++w] = id[m];       std::reverse(st + 1, st + w + 1);       for (; w; --w) bb[st[w]] = 1, printf( %d  , st[w]);       for (j = 1; j <= m; ++j)         if (!bb[j]) printf( %d  , j);       exit(0);     }     if (fl[m]) {       static bool bb[N];       static int st[N];       int w = 0;       printf( %d n , s[id[m]]);       for (j = m; j > 1; j = fl[j]) st[++w] = id[j];       st[++w] = id[1];       std::reverse(st + 1, st + w + 1);       for (; w; --w) bb[st[w]] = 1, printf( %d  , st[w]);       for (j = 1; j <= m; ++j)         if (!bb[j]) printf( %d  , j);       exit(0);     }     for (i = 1; i < m; ++i)       for (k = i + 1; k <= m; ++k)         if (fl[i] && fr[k] && r[id[i]] + 1 >= l[id[k]]) {           printf( %d n , l[id[k]]);           static int st[N];           int w = 0;           static bool bb[N];           for (j = k; j < m; j = fr[j]) st[++w] = id[j];           st[++w] = id[m];           std::reverse(st + 1, st + w + 1);           for (; w; --w) bb[st[w]] = 1, printf( %d  , st[w]);           w = 0;           for (j = i; j > 1; j = fl[j]) st[++w] = id[j];           st[++w] = id[1];           std::reverse(st + 1, st + w + 1);           for (; w; --w) bb[st[w]] = 1, printf( %d  , st[w]);           for (j = 1; j <= m; ++j)             if (!bb[j]) printf( %d  , j);           exit(0);         }     puts( -1 );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int ar[111];   int in[111];   long long n, s, now, t;   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       cin >> ar[i];       s += ar[i];       in[i] = i;     }     if (s < n - 1 || ar[0] == 0) {       cout << -1;       return 0;     }     for (int ii = 1; ii < n - 1; ii++)       for (int i = 1; i < n - 1; i++)         if (ar[in[i]] < ar[in[i + 1]]) swap(in[i], in[i + 1]);     cout << n - 1;     s = 0;     now = 1;     while (now < n) {       while (ar[in[s]] > 0 && now < n) {         cout << endl << in[s] + 1 <<     << in[now++] + 1;         ar[in[s]]--;       }       s++;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 2e5 + 6;   const long long M = 1e9 + 1;   char mat[105][105];   void solve() {     long long n;     cin >> n;     long long row[n];     vector<pair<long long, long long> > vecr;     vector<pair<long long, long long> > vecc;     long long col[n];     memset(row, 0, sizeof(row));     memset(col, 0, sizeof(col));     for (long long i = 0; i < n; i++) {       for (long long j = 0; j < n; j++) {         cin >> mat[i][j];         if (mat[i][j] ==  . ) {           if (row[i] != 1) vecr.push_back({i, j});           row[i] = 1;           if (col[j] != 1) vecc.push_back({i, j});           col[j] = 1;         }       }     }     bool rowok = true;     bool colok = true;     for (long long i = 0; i < n; i++) {       if (row[i] == 0) rowok = false;       if (col[i] == 0) colok = false;     }     if (!rowok && !colok)       cout << -1;     else if (rowok) {       for (long long i = 0; i < vecr.size(); i++)         cout << vecr[i].first + 1 <<     << vecr[i].second + 1 <<   n ;     } else if (colok) {       for (long long i = 0; i < vecc.size(); i++)         cout << vecc[i].first + 1 <<     << vecc[i].second + 1 <<   n ;     }   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long t = 1;     while (t--) solve();   }


#include <bits/stdc++.h>   using namespace std;   long long int mod = 1000000007;   bool check(int i, int j, int k) {     return (i + j > k && j + k > i && j + i > j);   }   int main() {     int n, ct = 0;     cin >> n;     for (int i = 1; i <= n; i++) {       for (int j = i; j <= n; j++) {         int k = i ^ j;         if (k <= n && k >= j && check(i, j, k)) ct++;       }     }     cout << ct << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int number_of_usb;   int file_size;   int usb_required = 0;   int summing = 0;   int temp;   int main() {     cin >> number_of_usb;     cin >> file_size;     int usb_sizes[number_of_usb];     for (int i = 0; i < number_of_usb; i++) {       cin >> usb_sizes[i];     }     for (int i = 0; i < number_of_usb; i++) {       for (int j = 0; j < number_of_usb; j++) {         if (usb_sizes[i] > usb_sizes[j]) {           temp = usb_sizes[j];           usb_sizes[j] = usb_sizes[i];           usb_sizes[i] = temp;         }       }     }     for (int i = 0; i < number_of_usb; i++) {       if (summing < file_size) {         usb_required++;       }       summing += usb_sizes[i];     }     cout << usb_required;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 2e5 + 5;   const int MOD = 1e4 + 7;   int n, m, q;   int main() {     scanf( %d , &q);     while (q--) {       int a, b;       scanf( %d%d , &a, &b);       int delt = abs(a - b);       int ans = delt / 10 + (delt % 10 != 0);       printf( %d n , ans);     }     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   const long long int mod = 1000000007;   const long long int p = 27;   string s;   long long int hashnum(int lw, int up) {     if ((up - lw) % 2 == 0)       return (((hashnum(lw, (lw + up) / 2) * p) % mod + 1) *               ((hashnum((lw + up) / 2, up) * p) % mod + 1)) %              mod;     long long int res = 0;     for (int i = lw; i < up; i++) {       res *= p;       res %= mod;       res += (s[i] -  a );       res %= mod;     }     return res;   }   int main() {     cin >> s;     long long int tmp = hashnum(0, s.length());     cin >> s;     long long int tmp1 = hashnum(0, s.length());     if (tmp == tmp1)       puts( YES );     else       puts( NO );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct point {     int x, y;   } a[200005];   bool cmp(struct point A, struct point B) {     if (A.x != B.x) return A.x < B.x;     return A.y < B.y;   }   int m;   int main() {     int n;     cin >> n;     for (int i = 0; i < n; i++) {       scanf( %d , &a[i].x);       a[i].y = i + 1;     }     int num = 0;     for (int i = n; i < 2 * n; i++) {       scanf( %d , &a[i].x);       a[i].y = i + 1 - n;       if (a[i].x == a[i - n].x) num++;     }     n *= 2;     a[n].x = 1e9 + 1;     n++;     sort(a, a + n, cmp);     cin >> m;     long long ans = 1;     int count = 1;     for (int i = 1; i < n; i++) {       if (a[i].x == a[i - 1].x) {         count++;         ans = (ans * count);         while (num && ans % 2 == 0) {           ans /= 2;           num--;         }         ans %= m;       } else         count = 1;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 2;   int tree[N * 32][2], cnt[N * 32];   long long int curr = 1, n, ans;   vector<long long int> arr(N);   void clean() {     for (long long int i = 0; i <= N * 32 - 1; i++) tree[i][0] = tree[i][1] = -1;   }   void add(long long int x) {     long long int v = 0;     cnt[v]++;     for (long long int i = 32; i >= 0; i--) {       long long int b = (x >> i) & 1;       if (tree[v][b] == -1) tree[v][b] = curr++;       v = tree[v][b];       cnt[v]++;     }   }   long long int calc(int v) {     if (v == -1) return 0;     int s0 = 0, s1 = 0;     if (tree[v][0] != -1) s0 = cnt[tree[v][0]];     if (tree[v][1] != -1) s1 = cnt[tree[v][1]];     if (s0 == 0 && s1 == 0) return cnt[v];     if (s0 == 0) return calc(tree[v][1]);     if (s1 == 0) return calc(tree[v][0]);     return 1 + max(calc(tree[v][0]), calc(tree[v][1]));   }   int main() {     clean();     cin >> n;     for (long long int i = 0; i <= n - 1; i++) cin >> arr[i], add(arr[i]);     cout << n - calc(0);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int i, j, k, l, max1 = 0, n, p, sum = 0;     string a, b, c;     cin >> n;     int x[26] = {0};     cin >> a;     if (n > 26)       cout <<  -1  << endl;     else {       for (i = 0; i < n; i++) {         p = a[i] -  a ;         x[p]++;       }       for (i = 0; i < 26; i++) {         if (x[i] > 1) {           sum += (x[i] - 1);           if (x[i] > max1) max1 = x[i];         }       }       cout << sum << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 10;   const int MAX = 30;   long long x, num;   long long a[40];   bool check(long long x) {     for (int i = 1; i < MAX; ++i) {       if (a[i] == x) return 1;     }     return 0;   }   vector<int> ans;   int main() {     long long x = 1;     for (int i = 1; i < MAX; ++i) {       x <<= 1;       a[i] = x - 1;     }     scanf( %lld , &x);     while (check(x) == 0) {       int i;       num++;       for (i = MAX - 1; i >= 0; --i) {         if (x >> i) break;       }       x ^= a[i + 1];       ans.push_back(i + 1);       if (check(x)) break;       num++;       x++;     }     printf( %d n , num);     for (auto i : ans) printf( %d  , i);     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:67108864 )   using namespace std;   vector<int> g[200000];   bool def[200000], del[200000];   int all[200000], good[200000], _good[200000];   int n, m, k;   int main() {     scanf( %d%d%d , &n, &m, &k);     for (int i = 0; i < k; i++) {       int t;       scanf( %d , &t);       def[t - 1] = true;     }     for (int i = 0; i < m; i++) {       int from, to;       scanf( %d%d , &from, &to);       from--, to--;       g[from].push_back(to);       g[to].push_back(from);       if (def[from]) good[to]--;       if (def[to]) good[from]--;       all[from]++, all[to]++;     }     memcpy(_good, good, sizeof good);     priority_queue<pair<double, int>, vector<pair<double, int>>,                    greater<pair<double, int>>>         q;     for (int i = 0; i < n; i++) {       good[i] += all[i];       if (!def[i]) q.push(make_pair((double)good[i] / all[i], i));     }     double best = -1;     while (!q.empty()) {       int v = q.top().second;       double ratio = q.top().first;       q.pop();       if (del[v]) continue;       del[v] = true;       best = max(best, ratio);       for (auto it = g[v].begin(); it != g[v].end(); it++) {         if (def[*it] || del[*it]) continue;         good[*it]--;         q.push(make_pair((double)good[*it] / all[*it], *it));       }     }     memset(del, false, sizeof del);     memcpy(good, _good, sizeof _good);     for (int i = 0; i < n; i++) {       good[i] += all[i];       if (!def[i]) q.push(make_pair((double)good[i] / all[i], i));     }     double cur = -1;     while (!q.empty()) {       int v = q.top().second;       double ratio = q.top().first;       q.pop();       if (del[v]) continue;       cur = max(cur, ratio);       if (cur == best) break;       del[v] = true;       for (auto it = g[v].begin(); it != g[v].end(); it++) {         if (def[*it] || del[*it]) continue;         good[*it]--;         q.push(make_pair((double)good[*it] / all[*it], *it));       }     }     int r = 0;     for (int i = 0; i < n; i++)       if (!(del[i] || def[i])) r++;     printf( %d n , r);     for (int i = 0; i < n; i++)       if (!(del[i] || def[i])) printf( %d  , i + 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long double pi = 3.14159265358979323846;   const long long mod = 1e9 + 7;   const long long N = 5e5;   const long long INF = 1e9 + 1;   long long n, m, ans;   int main() {     std::ios_base::sync_with_stdio(false);     std::cin.tie(0);     std::cout.tie(0);     cin >> n >> m;     for (long long i = 1; i <= n; ++i) {       long long a, b;       cin >> a >> b;       ans = max(ans, a + b);     }     cout << max(ans, m);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base ::sync_with_stdio(0);     long long int n;     cin >> n;     cout << 1 <<    ;     n--;     for (int i = 1; i <= 2; i++) {       if ((n - i) % 3 != 0) {         cout << i <<     << n - i;         break;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int n, sum, prv[100010], val[100010], a[100010];   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %d , &a[i]);     for (int i = n - 1; i >= 0; i--) {       if (i == n - 1)         val[i] = 1, sum = a[i];       else {         if (sum <= a[i]) {           val[i] = 1;           prv[i] = -1;           sum = a[i] - sum;         } else {           val[i] = -1;           prv[i] = 1;           sum -= a[i];         }       }     }     for (int i = 0; i < n - 1; i++) {       val[i + 1] *= prv[i];       prv[i + 1] *= prv[i];     }     for (int i = 0; i < n; i++) printf(val[i] == 1 ?  +  :  - );     puts(  );   }


#include <bits/stdc++.h>   using namespace std;   int next(int a) { return a < 2 ? 1 : (next(a - 2) + (a - 1) / 2); }   int main() {     long int N;     cin >> N;     long int ret = 1;     cout << (N + 1) / 2 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       long long n, f = 0, ans = 0;       cin >> n;       long long a[n];       for (int i = 0; i < n; i++) cin >> a[i];       for (int i = 0; i < n - 1; i++) {         if (a[i + 1] < a[i]) ans += (a[i] - a[i + 1]);       }       cout << ans << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long n, h, x, m1 = 0, m2 = 0;     cin >> n >> h;     for (int i = 1; i <= n; i++) {       cin >> x;       if (x > h) {         m1 += 2;       } else {         m2++;       }     }     cout << m1 + m2 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 4, inf = 1e9 + 7;   vector<int> vec[N];   vector<pair<int, int> > qry[N];   int col[N], cnt[N], frq[N];   int vis[N], siz[N], Res[N];   void dfs(int u, int p) {     siz[u] = 1;     for (auto v : vec[u]) {       if (v == p) continue;       dfs(v, u);       siz[u] += siz[v];     }   }   void Add(int u, int p) {     cnt[++frq[col[u]]]++;     for (auto v : vec[u]) {       if (v == p || vis[v]) continue;       Add(v, u);     }   }   void Rem(int u, int p) {     cnt[frq[col[u]]--]--;     for (auto v : vec[u]) {       if (v == p || vis[v]) continue;       Rem(v, u);     }   }   void DFS(int u, int p, bool first) {     int mx = -1, id = -1;     for (auto v : vec[u]) {       if (v == p) continue;       if (siz[v] > mx) mx = siz[v], id = v;     }     for (auto v : vec[u]) {       if (v == p || v == id) continue;       DFS(v, u, 1);     }     if (id != -1) DFS(id, u, 0), vis[id] = 1;     Add(u, p);     for (auto x : qry[u]) Res[x.second] = cnt[x.first];     if (id != -1) vis[id] = 0;     if (first) Rem(u, p);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n, q;     cin >> n >> q;     for (int i = 1; i <= n; i++) cin >> col[i];     int m = n - 1;     while (m--) {       int u, v;       cin >> u >> v;       vec[u].push_back(v);       vec[v].push_back(u);     }     dfs(1, 1);     for (int i = 1; i <= q; i++) {       int v, k;       cin >> v >> k;       qry[v].push_back(make_pair(k, i));     }     DFS(1, 1, 0);     for (int i = 1; i <= q; i++) cout << Res[i] <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 1000 * 1000 * 1000;   struct rib {     long long b, u, c, f;     size_t back;   };   void add_rib(vector<vector<rib> >& g, long long a, long long b, long long u,                long long c) {     rib r1 = {b, u, c, 0, g[b].size()};     rib r2 = {a, 0, -c, 0, g[a].size()};     g[a].push_back(r1);     g[b].push_back(r2);   }   namespace k {   long long n, m, k, c, d;   }   vector<long long> vr[55];   long long lr[50];   int main() {     long long n = 6001, m, k = INF;     vector<vector<rib> > g(n);     long long s, t;     cin >> k::n >> k::m >> k::k >> k::c >> (k::d);     long long tim = 100;     for (int i = 1; i < k::k + 1; i++) {       cin >> lr[i];       add_rib(g, 0, lr[i], 1, 0);     }     for (int j = 0; j < tim - 1; j++) {       for (int i = 2; i < k::n + 1; i++)         add_rib(g, j * 50 + i, (j + 1) * 50 + i, 50, k::c);     }     for (int j = 1; j < tim; j++) {       add_rib(g, j * 50 + 1, 1, 50, 0);     }     for (int i = 0; i < k::m; i++) {       long long x, y;       cin >> x >> y;       vr[x].push_back(y);       vr[y].push_back(x);       for (int j = 0; j < tim - 1; j++) {         for (int l = 0; l < 50; l++) {           add_rib(g, j * 50 + x, (j + 1) * 50 + y, 1,                   (k::c) + (k::d) * ((l + 1) * (l + 1) - (l * l)));           add_rib(g, j * 50 + y, (j + 1) * 50 + x, 1,                   (k::c) + (k::d) * ((l + 1) * (l + 1) - (l * l)));         }       }     }     s = 0, t = 1;     long long flow = 0, cost = 0;     while (flow < k) {       vector<long long> id(n, 0);       vector<long long> d(n, INF);       vector<long long> q(n);       vector<long long> p(n);       vector<size_t> p_rib(n);       long long qh = 0, qt = 0;       q[qt++] = s;       d[s] = 0;       while (qh != qt) {         long long v = q[qh++];         id[v] = 2;         if (qh == n) qh = 0;         for (size_t i = 0; i < g[v].size(); ++i) {           rib& r = g[v][i];           if (r.f < r.u && d[v] + r.c < d[r.b]) {             d[r.b] = d[v] + r.c;             if (id[r.b] == 0) {               q[qt++] = r.b;               if (qt == n) qt = 0;             } else if (id[r.b] == 2) {               if (--qh == -1) qh = n - 1;               q[qh] = r.b;             }             id[r.b] = 1;             p[r.b] = v;             p_rib[r.b] = i;           }         }       }       if (d[t] == INF) break;       long long addflow = k - flow;       for (long long v = t; v != s; v = p[v]) {         long long pv = p[v];         size_t pr = p_rib[v];         addflow = min(addflow, g[pv][pr].u - g[pv][pr].f);       }       for (long long v = t; v != s; v = p[v]) {         long long pv = p[v];         size_t pr = p_rib[v], r = g[pv][pr].back;         g[pv][pr].f += addflow;         g[v][r].f -= addflow;         cost += g[pv][pr].c * addflow;       }       flow += addflow;     }     cout << cost <<   n ;   }