#include <bits/stdc++.h>       using namespace std;   using ll=long long;   using pii=pair<int,int>;      int np[17][200000];   int pre[(1<<17)+1];      int main() {    int n,k;    cin >> n >> k;       string s;       cin >> s;    int l=0,r=n/k;       while (l<r) {           int m=(l+r+1)/2;           for (int j=0;j<k;j++) {               int cnt=0, nextpos=n+1;               for (int i=n-1;i>=0;i--) {                   if (s[i]== ?  || s[i]== a +j) cnt++;                   else cnt=0;                   if (cnt>=m) nextpos=i;                   np[j][i]=nextpos;               }           }           /*cerr << m << endl;           for (int j=0;j<k;j++) {               cerr << (char)( a +j) <<  :  ;               for (int i=0;i<n;i++) cerr << np[j][i] <<    ;               cerr << endl;           }*/           pre[0]=0;           for (int i=1;i<(1<<k);i++) {               pre[i]=n+1;               /*for (int j=0;j<k;j++) if (i&(1<<j)) {                   cerr << (char)( a +j) <<  , ;               }               cerr <<   t  << i << endl;*/               for (int j=0;j<k;j++) if (i&(1<<j)) {                   int x=(i&(~(1<<j)));                   //cerr << (char)( a +j) <<    << x <<     << pre[x] <<     << np[j][pre[x]] << endl;                   if (pre[x]<n) pre[i]=min(pre[i],np[j][pre[x]]+m);                   //cerr << (char)( a +j) <<     << pre[i] << endl;               }           }           /*for (int i=0;i<(1<<k);i++) {               for (int j=0;j<k;j++) if (i&(1<<j)) {                   cerr << (char)( a +j) <<  , ;               }               cerr <<   t  << pre[i] << endl;           }*/           if (pre[(1<<k)-1]<=n) l=m;           else r=m-1;       }       printf( %d n ,l);       return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 1005;   char ch[MAX];   int ans[MAX];   int main() {     int n;     scanf( %d%s , &n, ch);     ans[0] = 1;     for (int i = 1; i < n; i++) {       if (ch[i - 1] ==  = )         ans[i] = ans[i - 1];       else if (ch[i - 1] ==  L ) {         ans[i] = 1;         for (int j = i - 1; j >= 0; j--) {           if (ch[j] ==  L  && ans[j] <= ans[j + 1])             ans[j] = ans[j + 1] + 1;           else if (ch[j] ==  =  && ans[j] != ans[j + 1])             ans[j] = ans[j + 1];           else             break;         }       } else         ans[i] = ans[i - 1] + 1;     }     for (int i = 0; i < n; i++) {       if (i == 0)         printf( %d , ans[i]);       else         printf(  %d , ans[i]);     }     printf(  n );   }


#include <bits/stdc++.h>   using namespace std;   void printAll(int n, ...) {     if (1) {       va_list ap;       va_start(ap, n);       for (int i = 1; i <= n; i++) cout << va_arg(ap, long long int) <<    ;       cout << endl;       va_end(ap);     }   }   template <typename T>   string toString(T n) {     stringstream ss;     ss << n;     string s;     ss >> s;     return s;   }   void init() {     cout << fixed << setprecision(0);     ios_base::sync_with_stdio(false);     cin.tie(0);   }   bool isInteger(double n) {     if (n - (long long int)n == 0)       return true;     else       return false;   }   int main() {     init();     long long int i, j, k;     int n, w;     cin >> n >> w;     int x;     int low = 0;     int high = w;     int lowsum = 0;     int highsum = w;     for (int i = 0; i < n; i++) {       cin >> x;       if (lowsum + x < 0) {         low -= (lowsum + x);         lowsum = 0;       } else         lowsum += x;       if (highsum + x > w) {         high = high + (w - highsum - x);         highsum = w;       } else         highsum += x;     }     high < low ? cout << 0 << endl : cout << high - low + 1 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int dp[100000];   int main() {     int n, a, b, c;     cin >> n >> a >> b >> c;     dp[a] = dp[b] = dp[c] = 1;     int x = min(a, min(b, c));     for (int i = x; i <= n; i++) {       if (i - a >= 0 && dp[i - a] > 0) dp[i] = max(dp[i], dp[i - a] + 1);       if (i - b >= 0 && dp[i - b] > 0) dp[i] = max(dp[i], dp[i - b] + 1);       if (i - c >= 0 && dp[i - c] > 0) dp[i] = max(dp[i], dp[i - c] + 1);     }     cout << dp[n];     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int L[100007], R[100007];   int n;   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d%d , L + i, R + i);     }     sort(L + 1, L + n + 1);     sort(R + 1, R + n + 1);     long long ans = 0;     for (int i = 1; i <= n; i++) {       ans += max(L[i], R[i]);     }     printf( %I64d n , ans + n);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int ball[100005];   int main() {     int n, m;     cin >> n >> m;     if (m % 2) {       int basket = m / 2;       while (n--) {         cout << basket + 1 <<   n ;         basket = m - basket - 1;         if (basket <= m / 2) basket--;         if (basket < 0) basket = m / 2;       }     } else {       int basket = m / 2 - 1;       while (n--) {         cout << basket + 1 <<   n ;         basket = m - basket - 1;         if (basket < m / 2) basket--;         if (basket < 0) basket = m / 2 - 1;       }     }   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e18;   const int N = 1000 + 10;   int n, l, k;   double dp[202][202][404];   double pro[300];   int a[N];   double solve(int i, int sofar, int cap) {     if (i == n + 1) {       return sofar >= l && cap >= 0;     }     double &ret = dp[i][sofar][cap + 200];     if (ret == ret) return ret;     int toref = min(200, cap + a[i]);     toref = max(toref, -200);     double c1 = solve(i + 1, sofar + 1, toref) * pro[i];     double c2 = solve(i + 1, sofar, cap) * (1 - pro[i]);     return ret = c1 + c2;   }   int main() {     cin >> n >> l >> k;     for (int i = 1; i <= n; ++i) {       cin >> pro[i];       pro[i] /= 100.0;     }     for (int i = 1; i <= n; ++i) cin >> a[i];     memset(dp, -1, sizeof(dp));     cout << fixed << setprecision(10) << solve(1, 0, k) << endl;   }


#include <bits/stdc++.h>   using namespace std;   using namespace std;   const int N = 3030;   const int INF = (int)2e9;   int n, m;   int len[N];   int f[N][N];   vector<int> g[N];   vector<int> gr[N];   vector<pair<int, int> > have[N];   vector<pair<int, int> > gave[N];   queue<int> q;   void bfs(int v) {     for (int i = 1; i <= n; i++) len[i] = INF;     len[v] = 0;     q.push(v);     while (!q.empty()) {       int ver = q.front();       q.pop();       for (int i = 0; i < (int)g[ver].size(); i++) {         int to = g[ver][i];         if (len[to] > len[ver] + 1) {           len[to] = len[ver] + 1;           q.push(to);         }       }     }     for (int i = 1; i <= n; i++) {       f[v][i] = len[i];       if (len[i] != INF && i != v) {         gave[i].push_back(make_pair(len[i], v));       }     }     for (int i = 1; i <= n; i++) len[i] = INF;     len[v] = 0;     q.push(v);     while (!q.empty()) {       int ver = q.front();       q.pop();       for (int i = 0; i < (int)gr[ver].size(); i++) {         int to = gr[ver][i];         if (len[to] > len[ver] + 1) {           len[to] = len[ver] + 1;           q.push(to);         }       }     }     for (int i = 1; i <= n; i++) {       if (len[i] != INF && i != v) {         have[i].push_back(make_pair(len[i], v));       }     }   }   int main() {     scanf( %d%d , &n, &m);     int u, v;     for (int i = 1; i <= m; i++) {       scanf( %d%d , &u, &v);       g[u].push_back(v);       gr[v].push_back(u);     }     for (int i = 1; i <= n; i++) {       bfs(i);     }     for (int i = 1; i <= n; i++) {       sort(have[i].begin(), have[i].end());       reverse(have[i].begin(), have[i].end());       sort(gave[i].begin(), gave[i].end());       reverse(gave[i].begin(), gave[i].end());     }     int res = 0;     int a, b, c, d, sz, ptr, cost;     for (int i = 1; i <= n; i++) {       sz = min(3, (int)gave[i].size());       for (int idx = 0; idx < sz; idx++) {         for (int j = 1; j <= n; j++) {           if (j == i) continue;           if (f[i][j] == INF) continue;           ptr = 0;           while (true) {             if (ptr >= (int)have[j].size()) break;             if (have[j][ptr].second == i ||                 have[j][ptr].second == gave[i][idx].second ||                 j == gave[i][idx].second) {               ++ptr;               continue;             } else {               cost = gave[i][idx].first + f[i][j] + have[j][ptr].first;               if (cost > res) {                 res = cost;                 a = gave[i][idx].second;                 b = i;                 c = j;                 d = have[j][ptr].second;               }               break;             }           }         }       }     }     printf( %d %d %d %d n , a, b, c, d);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   void printvec(vector<T>& vec) {     for (int i = 0; i < vec.size(); i++) {       cout << vec[i] <<    ;     }     cout <<   n ;   }   vector<vector<int> > adj;   vector<int> comp;   vector<vector<int> > memb, arr;   vector<vector<long long> > cum;   vector<bool> visited(1000 * 100 + 5, false);   int ctr = 0;   vector<int> dia1, dia2;   vector<vector<int> > dist(2, vector<int>(1000 * 100 + 5, INT_MAX));   vector<int> distmax(1000 * 100 + 5);   vector<int> dialen;   void dfs(int curr, int prev) {     int i;     visited[curr] = true;     comp[curr] = ctr;     for (i = 0; i < adj[curr].size(); i++) {       if (adj[curr][i] == prev) continue;       dfs(adj[curr][i], curr);     }   }   int findend(int a) {     queue<int> q;     int ans;     q.push(a);     visited[a] = true;     while (!q.empty()) {       ans = q.front();       q.pop();       for (int i = 0; i < adj[ans].size(); i++) {         if (!visited[adj[ans][i]]) {           q.push(adj[ans][i]);           visited[adj[ans][i]] = true;         }       }     }     return ans;   }   void applybfs(int a, int type) {     queue<int> q;     int ans;     q.push(a);     visited[a] = true;     dist[type][a] = 0;     while (!q.empty()) {       ans = q.front();       q.pop();       for (int i = 0; i < adj[ans].size(); i++) {         if (!visited[adj[ans][i]]) {           q.push(adj[ans][i]);           visited[adj[ans][i]] = true;           dist[type][adj[ans][i]] = dist[type][ans] + 1;         }       }     }   }   int main() {     int ttt = 1;     while (ttt--) {       int n, m, q, i, j;       scanf( %d%d%d , &n, &m, &q);       adj.resize(n);       comp.resize(n);       for (i = 0; i < m; i++) {         int a, b;         scanf( %d%d , &a, &b);         a--;         b--;         adj[a].push_back(b);         adj[b].push_back(a);       }       for (i = 0; i < n; i++) {         if (!visited[i]) {           dfs(i, -1);           ctr++;         }       }       memb.resize(ctr);       dialen.resize(ctr);       for (i = 0; i < n; i++) memb[comp[i]].push_back(i);       for (i = 0; i < visited.size(); i++) visited[i] = false;       dia1.resize(ctr);       dia2.resize(ctr);       for (i = 0; i < ctr; i++) dia1[i] = findend(memb[i][0]);       for (i = 0; i < visited.size(); i++) visited[i] = false;       for (i = 0; i < ctr; i++) dia2[i] = findend(dia1[i]);       for (i = 0; i < visited.size(); i++) visited[i] = false;       for (i = 0; i < ctr; i++) applybfs(dia1[i], 0);       for (i = 0; i < visited.size(); i++) visited[i] = false;       for (i = 0; i < ctr; i++) applybfs(dia2[i], 1);       for (i = 0; i < ctr; i++) dialen[i] = dist[1][dia1[i]];       arr.resize(ctr);       cum.resize(ctr);       for (i = 0; i < n; i++) arr[comp[i]].push_back(max(dist[0][i], dist[1][i]));       for (i = 0; i < ctr; i++) sort(arr[i].begin(), arr[i].end());       for (i = 0; i < ctr; i++) cum[i].resize(arr[i].size());       for (i = 0; i < ctr; i++) cum[i][0] = arr[i][0];       for (i = 0; i < ctr; i++) {         for (j = 1; j < arr[i].size(); j++) {           cum[i][j] = cum[i][j - 1] + (long long)arr[i][j];         }       }       map<pair<int, int>, double> mapp;       for (int iii = 0; iii < q; iii++) {         int a, b;         scanf( %d%d , &a, &b);         a--;         b--;         if (memb[comp[a]].size() > memb[comp[b]].size()) swap(a, b);         int comp1 = comp[a], comp2 = comp[b];         map<pair<int, int>, double>::iterator it2 =             mapp.find(make_pair(comp1, comp2));         if (it2 != mapp.end()) {           printf( %.20f n , it2->second);           continue;         }         if (comp1 == comp2) {           printf( -1 n );           continue;         }         long long sz1 = memb[comp1].size(), sz2 = memb[comp2].size();         int maxdia = max(dialen[comp1], dialen[comp2]);         vector<int>& vec1 = arr[comp1];         vector<long long>& cum1 = cum[comp1];         vector<int>& vec2 = arr[comp2];         vector<long long>& cum2 = cum[comp2];         long long den = sz1 * sz2;         long long num = 0;         vector<int>::iterator it;         for (i = 0; i < vec1.size(); i++) {           it = upper_bound(vec2.begin(), vec2.end(), maxdia - vec1[i] - 1);           long long temp1 = 0, temp2 = 0;           if (it == vec2.begin()) {             temp1 = 0;             temp2 = ((long long)vec1[i]) * sz2;             temp2 += cum2[cum2.size() - 1];             temp2 += sz2;           } else {             long long abc = it - vec2.begin();             temp1 = maxdia * abc;             long long abc2 = sz2 - abc;             temp2 = ((long long)vec1[i]) * abc2;             temp2 += abc2;             temp2 += (cum2[vec2.size() - 1] - cum2[abc - 1]);           }           num += (temp1 + temp2);         }         double ans = (double)num / den;         mapp[make_pair(comp1, comp2)] = ans;         printf( %.20f n , ans);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int v[100009];   map<double, bool> mb;   int main() {     long long n, k, i, j, l, cnt = 0;     cin >> n >> k;     for (i = 0; i < n; i++) {       cin >> v[i];     }     sort(v, v + n);     for (i = 0; i < n; i++) {       double val = (double)(v[i] / (double)k);       if (!mb[val]) {         cnt++;         mb[v[i]] = true;       }     }     cout << cnt << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int const siz = 1e9, bound = 7e5, mod = siz + 9;   long long const oo = 1e18;   int aa[bound];   int main() {     int n, k;     scanf( %d , &n), scanf( %d , &k);     for (int(i) = 0; (i) < (n); (i)++) scanf( %d , &aa[i]);     int l = 0, r = n, mid, rob;     while (l <= r) {       mid = (l + r) >> 1;       if ((long long)mid * (mid + 1) / 2 >= k) {         rob = mid;         r = mid - 1;       } else         l = mid + 1;     }     long long cur = (long long)(rob - 1) * rob / 2 + 1;     int idn = 0;     while (cur < k) {       cur++;       idn++;     }     printf( %d n , aa[idn]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int MOD = 1e9 + 7;   long long INF = 1e18;   int n, q, a[200005];   int d[200005] = {};   int solve() {     cin >> n >> q;     for (int i = 0; i < n; i++) cin >> a[i];     while (q--) {       int l, r;       cin >> l >> r, l--, r--;       d[l]++;       d[r + 1]--;     }     for (int i = 1; i < n; i++) d[i] += d[i - 1];     sort(a, a + n);     sort(d, d + n);     long long sum = 0;     for (int i = 0; i < n; i++) sum += 1LL * a[i] * d[i];     cout << sum << endl;     return 0;   }   int main() {     ios::sync_with_stdio(0);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e9 + 7;   const int N = 1e3 + 10;   long long dis[N][N][4];   int dx[] = {0, 0, -1, 1};   int dy[] = {1, -1, 0, 0};   char c[N][N];   queue<pair<int, int>> q[4];   int n, m;   long long check(int o) {     long long d[4] = {0, INF * INF, INF * INF, INF * INF};     while (!q[o].empty()) {       int x, y;       tie(x, y) = q[o].front();       q[o].pop();       if (isdigit(c[x][y])) {         long long &oo = d[c[x][y] -  0 ];         oo = min(oo, dis[x][y][o]);       }       for (int i = 0; i < 4; i++) {         int tx = x + dx[i];         int ty = y + dy[i];         if (tx < 0 || tx >= n) continue;         if (ty < 0 || ty >= m) continue;         if (c[tx][ty] ==  # ) continue;         if (dis[tx][ty][o] > dis[x][y][o] + 1) {           dis[tx][ty][o] = dis[x][y][o] + 1;           q[o].push({tx, ty});         }       }     }     return min(INF, d[1] + d[2] + d[3] - 2);   }   int main() {     cin >> n >> m;     memset((dis), (0x1f), sizeof(dis));     for (int i = 0; i < n; i++) {       cin >> c[i];       for (int j = 0; j < m; j++) {         if (isdigit(c[i][j])) {           q[c[i][j] -  0 ].push({i, j});           dis[i][j][c[i][j] -  0 ] = 0;         }       }     }     long long ans = min(check(1), min(check(2), check(3)));     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (c[i][j] !=  . ) continue;         ans = min(ans, dis[i][j][1] + dis[i][j][2] + dis[i][j][3] - 2);       }     }     if (ans >= INF) ans = -1;     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   using namespace std;   inline int read() {     int ret = 0, t = 1;     char c = getchar();     while ((c <  0  || c >  9 ) && c !=  - ) c = getchar();     if (c ==  - ) t = -1, c = getchar();     while (c >=  0  && c <=  9 ) ret = ret * 10 + c -  0 , c = getchar();     return ret * t;   }   const int MAXN = 262145;   int n, a[MAXN], fa[MAXN];   int v[MAXN];   int gf(int x) {     if (fa[x] == x) return x;     return fa[x] = gf(fa[x]);   }   int main() {     n = read();     int i, j;     ++v[0];     long long ans = 0;     for (i = 1; i <= n; i++) a[i] = read(), ++v[a[i]], ans -= a[i];     for (i = 0; i <= 262144; i++) fa[i] = i;     for (i = 262144; i >= 1; i--) {       for (j = i; 1; j = i & (j - 1)) {         int x = j, y = i ^ j;         if (v[x] && v[y] && gf(x) != gf(y))           fa[gf(x)] = gf(y), ans += 1ll * i * (v[x] + v[y] - 1), v[x] = v[y] = 1;         if (!j) break;       }     }     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, k, arr[1005], ro[1005], co[1005];   char s[2000000];   int main() {     int a, b;     cin >> s + 1;     a = count(s + 1, s + strlen(s + 1) + 1,  x );     b = count(s + 1, s + strlen(s + 1) + 1,  y );     for (int i = 1; i <= a - b; i++) cout <<  x ;     for (int i = 1; i <= b - a; i++) cout <<  y ;     cout << endl;   }


#include <bits/stdc++.h>   auto clk = clock();   const int dx[] = {0, 0, -1, 1}, dy[] = {-1, 1, 0, 0};   const int dx8[] = {-1, -1, -1, 0, 1, 1, 1, 0},             dy8[] = {-1, 0, 1, 1, 1, 0, -1, -1};   using namespace std;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   long long Gcd(long long a, long long b) {     if (a % b == 0) return b;     return Gcd(b, a % b);   }   long long Max(long long a, long long b) {     if (a > b) return a;     return b;   }   long long Min(long long a, long long b) {     if (a < b) return a;     return b;   }   void printvector(std::vector<long long> v) {     for (int i = 0; i < v.size(); ++i) {       cout << v[i] <<    ;     }     cout <<    << endl;   }   void printarray(long long a[], long long n) {     for (long long i = 0; i < n; ++i) {       cout << a[i] <<    ;     }     cout <<    << endl;   }   long long findlcm(vector<long long> arr, long long n) {     long long ans = arr[0];     for (int i = 1; i < n; i++) ans = (((arr[i] * ans)) / (Gcd(arr[i], ans)));     return ans;   }   long long gcdExtended(long long a, long long b, long long *x, long long *y) {     if (a == 0) {       *x = 0, *y = 1;       return b;     }     long long x1, y1;     long long gcd = gcdExtended(b % a, a, &x1, &y1);     *x = y1 - (b / a) * x1;     *y = x1;     return gcd;   }   long long power(long long x, long long y, long long p) {     long long res = 1;     x = x % p;     while (y > 0) {       if (y & 1) res = (res * x) % p;       y = y >> 1;       x = (x * x) % p;     }     return res;   }   long long modInverse(long long a, long long m) {     long long x, y;     long long g = gcdExtended(a, m, &x, &y);     if (g != 1)       return -1;     else {       long long res = (x % m + m) % m;       return res;     }   }   long long inverse(long long x, long long mod) { return power(x, mod - 2, mod); }   vector<long long> primeFactors(long long n) {     vector<long long> v;     while (n % 2 == 0) {       v.push_back(2);       n = n / 2;     }     for (int i = 3; i <= sqrt(n); i = i + 2) {       while (n % i == 0) {         v.push_back(i);         n = n / i;       }     }     if (n > 2) v.push_back(n);     return v;   }   long long lowerbound(long long k, vector<long long> v) {     long long l = 0;     long long size = v.size();     long long r = size - 1;     long long mid;     while (l <= r) {       mid = (l + r) / 2;       if (v[mid] < k)         l = mid + 1;       else {         r = mid - 1;       }     }     return l;   }   long long upperbound(long long k, vector<long long> v) {     long long l = 0;     long long size = v.size();     long long r = size - 1;     long long mid;     while (l <= r) {       mid = (l + r) / 2;       if (v[mid] > k)         r = mid - 1;       else {         l = mid + 1;       }     }     return l;   }   long long C[2001][2000];   void binomialCoeff(long long n, long long k) {     long long i, j;     for (i = 0; i <= n; i++) {       for (j = 0; j <= k; j++) {         if (j == 0 || j == i)           C[i][j] = 1;         else           C[i][j] = (C[i - 1][j - 1] % 1000000007 + C[i - 1][j] % 1000000007) %                     1000000007;       }     }   }   string convertToNewString(const string &s) {     string newString =  @ ;     for (long long i = 0; i < s.size(); i++) {       newString +=  #  + s.substr(i, 1);     }     newString +=  #$ ;     return newString;   }   string longestPalindromeSubstring(const string &s) {     string Q = convertToNewString(s);     long long c = 0, r = 0;     long long P[Q.size() + 4];     memset(P, 0, sizeof(P));     for (long long i = 1; i < Q.size() - 1; i++) {       long long iMirror = c - (i - c);       if (r > i) {         P[i] = min(r - i, P[iMirror]);       }       while (Q[i + 1 + P[i]] == Q[i - 1 - P[i]]) {         P[i]++;       }       if (i + P[i] > r) {         c = i;         r = i + P[i];       }     }     int maxPalindrome = 0;     int centerIndex = 0;     for (int i = 1; i < Q.size() - 1; i++) {       if (P[i] > maxPalindrome) {         maxPalindrome = P[i];         centerIndex = i;       }     }     cout << maxPalindrome <<   n ;     return s.substr((centerIndex - 1 - maxPalindrome) / 2, maxPalindrome);   }   long long spf[100010];   void sieve() {     spf[1] = 1;     for (int i = 2; i < 100010; i++) spf[i] = i;     for (int i = 4; i < 100010; i += 2) spf[i] = 2;     for (int i = 3; i * i < 100010; i++) {       if (spf[i] == i) {         for (int j = i * i; j < 100010; j += i)           if (spf[j] == j) spf[j] = i;       }     }   }   long long binarySearch(long long arr[], long long l, long long r, long long x) {     if (r >= l) {       long long mid = l + (r - l) / 2;       if (arr[mid] == x) return mid;       if (arr[mid] > x) return binarySearch(arr, l, mid - 1, x);       return binarySearch(arr, mid + 1, r, x);     }     return -1;   }   const long long N = 100000;   long long n;   long long tree[2 * N];   void build(long long arr[]) {     for (long long i = 0; i < n; i++) {       tree[n + i] = arr[i];     }     for (long long i = n - 1; i > 0; --i) {       tree[i] = tree[i << 1] + tree[i << 1 | 1];     }   }   void updateTreeNode(long long p, long long value) {     tree[p + n] = value;     p = p + n;     for (long long i = p; i > 1; i >>= 1) {       tree[i >> 1] = tree[i] + tree[i ^ 1];     }   }   long long query(long long l, long long r) {     long long res = 0;     for (l += n, r += n; l < r; l >>= 1, r >>= 1) {       if (l & 1) {         res += tree[l++];       }       if (r & 1) {         res += tree[--r];       }     }     return res;   }   vector<long long> shortPath(vector<pair<long long, long long> > v[],                               long long src, long long V = 0) {     set<pair<long long, long long> > setds;     long long sizee = V;     long long IN = LLONG_MAX;     vector<long long> dist(sizee, IN);     vector<bool> vis(sizee, false);     setds.insert(make_pair(0, src));     dist[src] = 0;     while (!setds.empty()) {       pair<long long, long long> tmp = *(setds.begin());       setds.erase(setds.begin());       long long u = tmp.second;       if (vis[u]) continue;       vis[u] = true;       vector<pair<long long, long long> >::iterator i;       for (auto i = v[u].begin(); i != v[u].end(); ++i) {         long long v = (*i).first;         long long weight = (*i).second;         if (dist[v] > dist[u] + weight) {           if (dist[v] != LLONG_MAX)             setds.erase(setds.find(make_pair(dist[v], v)));           dist[v] = dist[u] + weight;           setds.insert(make_pair(dist[v], v));         }       }     }     return dist;   }   long long root(long long a[], long long r) {     if (a[r] == r) {       return r;     } else {       long long x = root(a, a[r]);       a[r] = x;       return x;     }   }   void unio(long long a[], long long size[], long long x, long long y) {     x = root(a, x);     y = root(a, y);     if (x == y) {       return;     }     if (size[x] >= size[y]) {       a[y] = x;       size[x] += size[y];     } else {       a[x] = y;       size[y] += size[x];     }   }   void dfs(std::vector<long long> v[], long long s, bool visited[]) {     visited[s] = true;     for (long long i = 0; i < v[s].size(); ++i) {       if (!visited[v[s][i]]) {         dfs(v, v[s][i], visited);       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long txt = 1;     while (txt--) {       cin >> n;       vector<long long> suf(n, 0);       vector<long long> sufb(n, 0);       vector<long long> pre(n, 0);       vector<long long> p(n);       string s;       long long mx = 0;       for (int i = 0, _n = (n); i < _n; i++) cin >> p[i];       cin >> s;       for (int i = 0, _n = (n); i < _n; i++) {         if (!i) {           if (s[i] ==  B ) sufb[i] = p[i];         } else {           if (s[i] ==  B )             sufb[i] = p[i] + sufb[i - 1];           else {             sufb[i] = sufb[i - 1];           }         }       }       for (int i = n - 1; i >= 0; i--) {         if (i == n - 1) {           if (s[i] ==  B ) {             pre[i] = p[i];           }           continue;         }         if (s[i] ==  B ) {           pre[i] = p[i] + pre[i + 1];         } else {           pre[i] = pre[i + 1];         }       }       long long sum = 0;       long long sumb = 0;       long long suma = 0;       for (int i = n - 1; i >= 0; i--) {         sum += p[i];         if (s[i] ==  A ) {           suma += p[i];           if (i)             mx = max(suma + sufb[i - 1], mx), mx = max(sumb + sufb[i - 1], mx);           else {             mx = max(sumb, mx);             mx = max(suma, mx);           }         } else {           sumb += p[i];           if (i)             mx = max(sumb + sufb[i - 1], mx);           else {             mx = max(sumb, mx);           }         }       }       suma = sumb = 0;       for (int i = 0, _n = (n); i < _n; i++) {         if (s[i] ==  A ) {           suma += p[i];           if (i != n - 1)             mx = max(sumb + pre[i + 1], mx), mx = max(suma + pre[i + 1], mx);           else {             mx = max(sumb, mx);             mx = max(suma, mx);           }         } else {           sumb += p[i];           if (i != n - 1)             mx = max(sumb + pre[i + 1], mx), mx = max(suma + pre[i + 1], mx);           else {             mx = max(sumb, mx);             mx = max(suma, mx);           }         }       }       cout << mx << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 2e5 + 10;   long long n, m, nn, cnt, tot, k, k_, x, y, ww, rt, ans;   long long to[N], nextn[N], h[N];   long long mxsize[N], size[N];   long long w[N];   struct dis {     long long d, d_;     bool operator<(const dis &x) const { return x.d > d; }   } tmp[N], q[N], q0[N];   long long t[N];   bool b[N];   long long lowbit(long long x) { return x & (-x); }   void update(long long x, long long v) {     for (long long i = x; i <= n; i += lowbit(i)) t[i] += v;   }   long long inquiry(long long x) {     long long res = 0;     for (long long i = x; i; i -= lowbit(i)) res += t[i];     return res;   }   void add(long long x, long long y, long long ww) {     cnt++;     to[cnt] = y;     nextn[cnt] = h[x];     h[x] = cnt;     w[cnt] = ww;   }   void findrt(long long x, long long anc) {     mxsize[x] = 0;     size[x] = 1;     for (long long i = h[x]; i; i = nextn[i]) {       long long y = to[i];       if (y == anc || b[y]) continue;       findrt(y, x);       size[x] += size[y];       mxsize[x] = max(mxsize[x], size[y]);     }     mxsize[x] = max(mxsize[x], nn - size[x]);     if (mxsize[x] < mxsize[rt]) rt = x;   }   void dfs(long long x, long long anc, long long dis1, long long dis_) {     tmp[++tot] = (dis){dis1, dis_};     if (dis1 <= k && dis_ <= k_) ans++;     for (long long i = h[x]; i; i = nextn[i]) {       long long y = to[i];       if (y == anc || b[y]) continue;       dfs(y, x, dis1 + w[i], dis_ + 1);     }   }   void work(long long x) {     cnt = 0;     for (long long i = h[x]; i; i = nextn[i]) {       long long y = to[i];       if (b[y]) continue;       tot = 0;       dfs(y, x, w[i], 1);       sort(tmp + 1, tmp + tot + 1);       long long last = 0;       for (long long j = tot; j >= 1; j--)         if (tmp[j].d < k && tmp[j].d_ < k_) {           long long pos =               lower_bound(q + 1, q + cnt + 1, dis{k - tmp[j].d + 1, 0}) - q;           while (q[pos].d > k - tmp[j].d) pos--;           for (long long l = last + 1; l <= pos && l <= cnt; l++)             update(q[l].d_, 1);           ans += inquiry(k_ - tmp[j].d_);           last = pos;         }       for (long long l = 1; l <= last && l <= cnt; l++) update(q[l].d_, -1);       merge(tmp + 1, tmp + tot + 1, q + 1, q + cnt + 1, q0 + 1);       cnt += tot;       for (long long i = 1; i <= cnt; i++) q[i] = q0[i];     }   }   void solve(long long x) {     b[x] = 1;     work(x);     for (long long i = h[x]; i; i = nextn[i]) {       long long y = to[i];       if (b[y]) continue;       rt = 0, mxsize[0] = n;       nn = size[y];       findrt(y, x);       solve(rt);     }   }   signed main() {     scanf( %lld%lld%lld , &n, &k_, &k);     for (long long i = 1; i < n; i++) {       scanf( %lld%lld , &y, &ww);       add(i + 1, y, ww), add(y, i + 1, ww);     }     rt = 0, nn = n;     mxsize[0] = n;     findrt(1, 0);     solve(rt);     printf( %lld , ans);   }


#include <bits/stdc++.h>   using namespace std;   const int N = 505;   int n, m, x, cnt[N], ne[N][10], g[15], f[15], dp[N][N][15], sd[N], tot;   char s[N];   void dfs(int x) {     for (int i = 0; i < 10; i++)       if (ne[x][i]) dfs(ne[x][i]);     for (int i = 0; i <= sd[x]; i++) {       memset(f, 0, sizeof f);       for (int j = 0; j < 10; j++)         if (ne[x][j]) {           memset(g, 0x3f, sizeof g);           int to = ne[x][j];           for (int x = 0; x <= m; x++)             for (int y = 0; y <= m - x; y++)               g[x + y] = min(g[x + y], f[x] + dp[to][i][y]);           for (int x = 0; x <= m; x++) f[x] = g[x];         }       if (i != sd[x]) {         for (int j = 0; j <= m; j++) dp[x][i][j] = f[j] + cnt[x] * (sd[x] - i);       } else {         if (i == 0)           printf( %d n , f[m]);         else           for (int j = 0; j < sd[x]; j++)             for (int k = 0; k < m; k++)               dp[x][j][k + 1] = min(dp[x][j][k + 1], f[k]);       }     }   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) {       scanf( %s%d , s + 1, &x);       int p = 0;       for (int j = 1; s[j]; j++) {         int t = s[j] -  0 ;         if (!ne[p][t]) ne[p][t] = ++tot, sd[tot] = j;         p = ne[p][t];       }       cnt[p] += x;     }     dfs(0);   }


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


#include <bits/stdc++.h>   using namespace std;   int find_set(int v, vector<int> &p) {     if (v == p[v]) return v;     return p[v] = find_set(p[v], p);   }   void union_set(int a, int b, vector<int> &p) {     a = find_set(a, p);     b = find_set(b, p);     if (a != b) {       p[b] = a;     }   }   long long int ans = 0;   void dfs(int i, vector<int> &vis, vector<int> adj[]) {     vis[i] = 1;     for (int k = 0; k < adj[i].size(); k++) {       if (vis[adj[i][k]] == 0) {         dfs(adj[i][k], vis, adj);       }     }   }   void solve() {     int n, m;     cin >> n >> m;     vector<int> adj[n];     int a, b;     for (int i = 0; i < m; i++) {       cin >> a >> b;       a--;       b--;       adj[a].push_back(b);       adj[b].push_back(a);     }     vector<int> vis(n, 0);     dfs(0, vis, adj);     if (find(vis.begin(), vis.end(), 0) != vis.end()) {       cout <<  NO  << endl;       return;     }     if (m - n + 1 == 1) {       cout <<  FHTAGN!  << endl;       return;     }     cout <<  NO  << endl;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int T;     T = 1;     while (T--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   int num[30];   char ans[100050];   int gcd(int a, int b) {     if (b == 0) return a;     return gcd(b, a % b);   }   int main() {     cin >> n;     int neven = 0;     int sut = 0;     for (int i = 0; i < n; i++) {       cin >> num[i];       if (num[i] % 2) neven++;       sut += num[i];     }     if (n == 1) {       printf( %d n , num[0]);       for (int i = 1; i <= num[0]; i++) printf( a );       puts(  );       return 0;     }     if (neven > 1) {       puts( 0 );       for (int i = 0; i < n; i++)         for (int k = 0; k < num[i]; k++) printf( %c ,  a  + i);       puts(  );     } else {       int counts = num[0];       for (int i = 1; i < n; i++) {         counts = gcd(counts, num[i]);       }       if (counts % 2 == 1) {         int l = 1, r = sut / counts;         for (int i = 0; i < n; i++) {           if (num[i] & 1) {             num[i]--;             ans[(sut / counts + 1) / 2] = i +  a ;           }           for (int k = num[i] / counts; k > 0; k -= 2) {             ans[l++] = i +  a ;             ans[r--] = i +  a ;           }         }         l = sut / counts + 1;         int subarry = sut / counts;         for (int i = 2; i <= counts; i++) {           for (int k = 1; k <= subarry; k++) {             ans[l] = ans[l - (k * 2 - 1)];             l++;           }         }         printf( %d n , counts);       } else {         int subarry = sut / counts;         int l = 1;         for (int i = 0; i < n; i++) {           for (int k = 1; k <= num[i] / counts; k++) ans[l++] = i +  a ;         }         for (int i = 2; i <= counts; i++) {           for (int k = 1; k <= subarry; k++) {             ans[l] = ans[l - (k * 2 - 1)];             l++;           }         }         printf( %d n , counts);       }       for (int i = 1; i <= sut; i++) {         printf( %c , ans[i]);       }       puts(  );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, b, g, x, y;     bool women[100], man[100];     cin >> n >> m;     cin >> b;     for (int i = 0; i < n; i++) man[i] = 0;     for (int i = 0; i < m; i++) women[i] = 0;     for (int i = 0; i < b; i++) {       cin >> x;       man[x] = 1;     }     cin >> g;     for (int i = 0; i < g; i++) {       cin >> y;       women[y] = 1;     }     for (int i = 0; i <= (n * m) * (n * m); i++) {       if (man[i % n] == 1)         women[i % m] = 1;       else {         if (women[i % m] == 1) man[i % n] = 1;       }     }     bool flag1 = 1, flag2 = 1;     for (int i = 0; i < n; i++) flag1 *= man[i];     for (int i = 0; i < m; i++) flag2 *= women[i];     if (flag1 == 1 && flag2 == 1)       cout <<  Yes ;     else       cout <<  No ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     getline(cin, s);     bool in_quotes{false};     string sub;     vector<string> vec;     for (int i{}; i < s.size(); ++i) {       if (s[i] ==    ) {         if (!in_quotes) {           in_quotes = true;           if (!sub.empty()) vec.push_back(sub);           sub.clear();         } else {           in_quotes = false;           vec.push_back(sub);           sub.clear();         }       } else {         if (in_quotes) {           sub += s[i];         } else {           if (s[i] !=    ) {             sub += s[i];             if (i == s.size() - 1) {               if (!sub.empty()) vec.push_back(sub);             }           } else {             if (!sub.empty()) vec.push_back(sub);             sub.clear();           }         }       }     }     for (auto val : vec) cout <<  <  << val <<  > n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long inf = INT_MAX, df = 4e5 + 7;   priority_queue<pair<long long, long long>> que[df];   int i, j, k, l, m, n, o, q, s, t, u, v, w, x, y, z, tot, cur[df], pos[df];   long long r[df], p[df], d[df], b[df], a[df];   inline long long read() {     long long x = 0, y = 1;     char ch = getchar();     while (ch >  9  || ch <  0 ) y = (ch ==  - ) ? -1 : 1, ch = getchar();     while (ch >=  0  && ch <=  9 )       x = (x << 3) + (x << 1) + ch -  0 , ch = getchar();     return x * y;   }   int main() {     x = read(), y = read(), p[0] = read(), r[0] = read(), n = read();     r[0] *= r[0], tot = 0;     for (int i = (1); i <= (n); ++i) {       s = read(), t = read(), m = read(), p[i] = read(), r[i] = read();       d[i] = 1ll * (s - x) * (s - x) + 1ll * (t - y) * (t - y), r[i] *= r[i];       b[i] = m;       a[++tot] = m;       pos[i] = 1;     }     sort(a + 1, a + tot + 1), tot = unique(a + 1, a + tot + 1) - a - 1;     int cnt = 0;     for (int i = (1); i <= (n); ++i)       for (int j = lower_bound(a + 1, a + tot + 1, b[i]) - a; j <= tot;            j += j & -j)         que[j].push(make_pair(-d[i], i));     for (cur[0] = i = 0; i <= cnt; ++i) {       for (int j = upper_bound(a + 1, a + tot + 1, p[cur[i]]) - a - 1; j;            j -= j & -j) {         for (; (!que[j].empty()) && -que[j].top().first <= r[cur[i]];              que[j].pop())           if (pos[que[j].top().second]) pos[cur[++cnt] = que[j].top().second] = 0;       }     }     return printf( %d n , cnt), 0;   }


#include <bits/stdc++.h>   using namespace std;   int32_t main() {     long long n;     cin >> n;     vector<pair<long long, long long>> a(n);     for (long long i = 0; i < n; ++i) {       cin >> a[i].first >> a[i].second;       a[i].first *= 2;       a[i].second *= 2;     }     if (n % 2) {       cout <<  NO ;       return 0;     }     long long x, y;     x = (a[0].first + a[n / 2].first) / 2;     y = (a[0].second + a[n / 2].second) / 2;     vector<long long> q(n);     for (long long i = 0; i < n; ++i) {       long long d = (x - a[i].first) * (x - a[i].first) +                     (y - a[i].second) * (y - a[i].second);       q[i] = d;     }     bool ok = true;     for (long long i = 0; i < n; ++i) {       if (q[i] != q[(i + n / 2) % n]) {         ok = 0;       }       if (2 * x != (a[i].first + a[(i + n / 2) % n].first)) ok = 0;       if (2 * y != (a[i].second + a[(i + n / 2) % n].second)) ok = 0;     }     if (ok) {       cout <<  YES n ;     } else {       cout <<  NO ;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, res;     cin >> n;     res = n / 5;     if (n % 5 != 0) res++;     cout << res;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long t;     cin >> t;     while (t--) {       long long n;       cin >> n;       set<long long> d[n + 1];       vector<long long> kingdom(n + 1, 0);       for (long long i = 1; i < n + 1; i++) {         long long k, x;         cin >> k;         for (long long j = 1; j < k + 1; j++) {           cin >> x;           d[i].insert(x);         }       }       vector<long long> none;       for (long long i = 1; i < n + 1; i++) {         long long flag = 0;         for (auto x : d[i]) {           if (kingdom[x] != 1) {             kingdom[x] = 1;             flag = 1;             break;           }         }         if (flag == 0) {           none.push_back(i);         }       }       long long index2 = -1;       long long index = -1;       for (long long i = 1; i < n + 1; i++) {         for (long long j = 0; j < none.size(); j++) {           if (kingdom[i] == 0 && d[none[j]].find(i) == d[none[j]].end()) {             index2 = i;             index = none[j];             break;           }         }         if (index2 != -1) {           break;         }       }       if (none.size() == 0 || index2 == -1) {         cout <<  OPTIMAL  n ;       } else {         cout <<  IMPROVE  n ;         cout << index <<     << index2 <<   n ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     long long a, b;     cin >> a >> b;     if (a == b) {       cout << a << endl;       return;     } else if (a > b) {       cout << a + b << endl;       return;     } else {       if (b % a == 0) {         cout << b << endl;         return;       } else {         long long x = b - a - b % a;         if (x == 0) {           cout << a + (b - a) / 2;         } else {           cout << (b + x) / 2;         }         cout << endl;         return;       }     }     cout << -1 << endl;   }   signed main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     int t = 1;     cin >> t;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, t1, t2, k, a[1005], b[1005];   vector<pair<double, int> > ans;   bool cmp(pair<double, int> x, pair<double, int> y) {     if (fabs(x.first - y.first) < 1e-5) return x.second < y.second;     return x.first > y.first;   }   double h(int x, int y) {     return (double)x * t1 * (100.0 - k) / 100.0 + (double)y * t2;   }   int main() {     scanf( %d%d%d%d , &n, &t1, &t2, &k);     for (int i = 0; i < n; ++i) scanf( %d%d , &a[i], &b[i]);     for (int i = 0; i < n; ++i) {       ans.push_back(make_pair(max(h(a[i], b[i]), h(b[i], a[i])), i));     }     sort((ans).begin(), (ans).end(), cmp);     for (int i = 0; i < n; ++i)       printf( %d %.2lf n , ans[i].second + 1, ans[i].first);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int F[100000], S[100000];   int main(int argc, char *argv[]) {     int n, x, adg, i, j, k, L, A, B;     cin >> n >> x;     for (i = 0; i < n; i++) cin >> F[i];     for (i = 0; i < n; i++) cin >> S[i];     if (n == 1)       cout << 1 <<     << 1;     else {       cout << 1 <<    ;       sort(F, F + n);       sort(S, S + n);       adg = 0;       j = L = 0;       i = k = n - 1;       while (adg < n && i >= L && k >= j) {         A = F[i] + S[j];         B = S[k] + F[L];         if (A >= B && A >= x) {           adg++;           i--;           j++;         } else if (B > A && B >= x) {           adg++;           k--;           L++;         } else if (A < B)           j++;         else           L++;       }       cout << adg;     }     return EXIT_SUCCESS;   }


#include <bits/stdc++.h>   using namespace std;   long long int gcd(long long int a, long long int b) {     if (a == 0) {       return b;     } else {       return gcd(b % a, a);     }   }   long long int lcm(long long int a, long long int b) {     return a * b / gcd(a, b);   }   int f(char c) { return (int)c - 48; }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     ;     int t;     cin >> t;     while (t--) {       long long int n, x;       cin >> n >> x;       long long int a[1005];       long long int sum = 0;       long long int count = 0;       for (int i = 1; i <= n; i++) {         cin >> a[i];         sum += (a[i] - x);         if (a[i] == x) {           count++;         }       }       if (count == n) {         cout << 0 << endl;       } else if (count > 0) {         cout << 1 << endl;       } else if (sum == 0) {         cout << 1 << endl;       } else {         cout << 2 << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int Maxn = 500005;   int n;   int a[Maxn];   long long L[Maxn], R[Maxn];   int delt[Maxn];   long long res;   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       L[i] = L[i - 1] + a[i];     }     if (L[n] % 3)       printf( 0 n );     else {       long long need = L[n] / 3;       for (int i = n; i >= 1; i--) {         R[i] = R[i + 1] + a[i];         delt[i] = delt[i + 1] + (R[i] == need);       }       for (int i = 1; i <= n; i++)         if (L[i] == need) res += delt[i + 2];       printf( %I64d n , res);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long int INF = 1000000007;   const int N = 100000 + 7;   int power(int x, unsigned int y) {     int res = 1;     while (y > 0) {       if (y & 1) res = res * x;       y = y >> 1;       x = x * x;     }     return res;   }   int GCD(int A, int B) {     if (B == 0)       return A;     else       return GCD(B, A % B);   }   string decToBin(int number) {     if (number == 0) return  0 ;     if (number == 1) return  1 ;     if (number % 2 == 0)       return decToBin(number / 2) +  0 ;     else       return decToBin(number / 2) +  1 ;   }   int binToDec(string number) {     int result = 0, pow = 1;     for (int i = number.length() - 1; i >= 0; --i, pow <<= 1)       result += (number[i] -  0 ) * pow;     return result;   }   void seive(int n) {     vector<int> primeNums;     bool prime[n + 1];     memset(prime, true, sizeof(prime));     for (int p = 2; p * p <= n; p++) {       if (prime[p]) {         for (int i = 2 * p; i <= n; i += p) prime[i] = false;       }     }     for (int i = 2; i <= n; i++) {       if (prime[i]) {         primeNums.push_back(i);       }     }   }   long long powerMod(long long x, int y, int m) {     x = x % m;     long long res = 1;     while (y > 0) {       if (y & 1) {         res = (res * x) % m;       }       y = y >> 1;       x = (x * x) % m;     }     return res;   }   long long D, X, Y;   void extendedEuclid(int a, int b) {     if (b == 0) {       D = a;       X = 1;       Y = 0;     } else {       extendedEuclid(b, a % b);       int temp = X;       X = Y;       Y = temp - (a / b) * Y;     }   }   long long solve(long long n) {     if (n == 1) return 0;     return n / 2 + 2 * solve((n + 1) / 2);   }   int main() {     long long n;     cin >> n;     cout << solve(n) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 200010;   int n, t[N];   int main() {     scanf( %d , &n);     set<int> st;     int ans = 0;     for (int i = 0; i < n; i++) scanf( %d , &t[i]);     for (int i = 1; i <= n; i++) {       set<int>::iterator it = st.lower_bound(t[i - 1]);       int cur = *it;       if (it == st.end() || cur != t[i - 1]) {         ans++;       } else {         st.erase(it);       }       st.insert(i);     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   typedef int STDD[1010];   struct lst {     int po;     int num;     lst* nxt;   };   lst* hd[1001];   int n, m, sx, sy, ans = 2E9 + 1, a1, a2;   STDD seq, tseq, fa, clr, far;   int x[30010], y[30010], z[30010];   bool vis[1001];   int getfa(int x) { return (fa[x] != x) ? (fa[x] = getfa(fa[x])) : (x); }   bool dfs(int x, int fb) {     vis[x] = 1;     if (x == sy) return 1;     for (lst* p = hd[x]; p; p = p->nxt)       if (!vis[p->po] && p->num != fb) {         seq[++seq[0]] = p->num;         if (!dfs(p->po, fb))           --seq[0];         else           return 1;       }     return 0;   }   int main() {     scanf( %d%d%d%d , &n, &m, &sx, &sy);     for (int i = 1; i <= m; ++i) {       scanf( %d%d%d , x + i, y + i, z + i);       hd[x[i]] = new lst{y[i], i, hd[x[i]]};       ;       hd[y[i]] = new lst{x[i], i, hd[y[i]]};       ;     }     if (!dfs(sx, 0)) {       printf( 0 n0 n );       return 0;     }     for (int i = 0; i <= seq[0]; ++i) tseq[i] = seq[i];     for (int i = 1; i <= tseq[0]; ++i) {       memset(vis, 0, sizeof(vis));       seq[0] = 0;       if (!dfs(sx, tseq[i]) && ans > z[tseq[i]]) {         ans = z[tseq[i]];         a1 = tseq[i];         a2 = 0;         continue;       }       memset(clr, 0, sizeof(clr));       for (int j = 1; j <= n; ++j) far[j] = fa[j] = j;       for (int j = 1; j <= seq[0]; ++j) z[seq[j]] *= -1;       z[tseq[i]] *= -1;       for (int j = 1; j <= m; ++j)         if (z[j] > 0) fa[getfa(x[j])] = getfa(y[j]);       for (int j = 1; j <= seq[0]; ++j) z[seq[j]] *= -1;       z[tseq[i]] *= -1;       int cr = clr[sx] = 1;       for (int j = 1; j <= seq[0]; ++j)         clr[(!clr[x[seq[j]]]) ? (x[seq[j]]) : (y[seq[j]])] = ++cr;       for (int j = 1; j <= n; ++j)         if (clr[far[getfa(j)]] < clr[j]) far[getfa(j)] = j;       int now = far[getfa(sx)];       for (int j = 1; j <= seq[0]; ++j) {         if (clr[x[seq[j]]] > clr[y[seq[j]]]) swap(x[seq[j]], y[seq[j]]);         if (clr[now] >= clr[y[seq[j]]]) {           if (clr[far[getfa(y[seq[j]])]] > clr[now]) now = far[getfa(y[seq[j]])];           continue;         }         if (z[tseq[i]] + z[seq[j]] < ans) {           ans = z[tseq[i]] + z[seq[j]];           a1 = tseq[i];           a2 = seq[j];         }         now = far[getfa(y[seq[j]])];       }     }     if (!a1)       printf( -1 n );     else if (!a2)       printf( %d n1 n%d n , ans, a1);     else       printf( %d n2 n%d %d n , ans, a1, a2);   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 3;   const long long MOD = 1e9 + 7;   const long long INF = 2e9;   const int fullmask = (1 << 10) - 1;   long long fpow(int n, int p) {     if (!p) return 1;     if (p == 1) return n;     long long tmp = fpow(n, p / 2);     if (p & 1) return tmp * tmp % MOD * n % MOD;     return tmp * tmp % MOD;   }   long long Hash[10][10];   int k, n, m, u, v, w, c[10], ans;   vector<pair<int, int> > g[N];   void solve(int id) {     if (id > k) {       long long op = 0;       for (int i = 1; i <= k; i++) op += Hash[i][c[i]], op %= MOD;       if (op == ((fpow(2, n + 1) - 2 + MOD) % MOD)) ans++;       return;     }     for (int i = 1; i <= id; i++) {       c[id] = i;       solve(id + 1);     }   }   void process() {     cin >> n >> m >> k;     for (int i = 1; i <= m; i++) {       cin >> u >> v >> w;       g[u].push_back(pair<int, int>(w, v));     }     for (int i = 1; i <= n; i++) sort(g[i].begin(), g[i].end());     for (int i = 1; i <= n; i++) {       int deg = g[i].size();       for (int j = 1; j <= deg; j++) {         int v = g[i][j - 1].second;         Hash[deg][j] += fpow(2, v);         Hash[deg][j] %= MOD;       }     }     solve(1);     cout << ans << endl;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie();     process();   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 998244353;   int n, m;   int f[2][25][25][25][25][2][2];   int x[6], y[6];   int tpx[1 << 6], tqx[1 << 6], tpy[1 << 6], tqy[1 << 6];   inline void update(int &x, int y) { x = x + y >= mod ? x + y - mod : x + y; }   inline bool check(int now, int px, int qx, int py, int qy) {     for (int a = 0; a < 2; a++)       for (int b = 0; b < 2; b++)         if (f[now][px][qx][py][qy]) return true;     return false;   }   int main() {     scanf( %d %d , &n, &m);     for (int i = 1; i <= n; i++) scanf( %d %d , &x[i], &y[i]);     for (int s = 0; s < (1 << n); s++)       for (int j = 1; j <= n; j++)         if (s >> j - 1 & 1) {           if (x[j] > 0)             tpx[s] += x[j];           else             tqx[s] -= x[j];           if (y[j] > 0)             tpy[s] += y[j];           else             tqy[s] -= y[j];         }     int now = 0, lim = (1 << n) - 1;     f[now][0][0][0][0][1][1] = 1;     for (int i = 31; i >= 1; i--) {       now ^= 1;       memset(f[now], 0, sizeof(f[now]));       int v = m >> i - 1 & 1;       for (int px = 0; px <= tpx[lim]; px++)         for (int qx = 0; qx <= tqx[lim]; qx++)           for (int py = 0; py <= tpy[lim]; py++)             for (int qy = 0; qy <= tqy[lim]; qy++) {               if (!check(now ^ 1, px, qx, py, qy)) continue;               for (int s = 0; s <= lim; s++)                 for (int a = 0; a < 2; a++)                   for (int b = 0; b < 2; b++) {                     int res = f[now ^ 1][px][qx][py][qy][a][b], na, nb;                     if (!res) continue;                     int npx = px * 2 - tpx[s], nqx = qx * 2 - tqx[s],                         npy = py * 2 - tpy[s], nqy = qy * 2 - tqy[s];                     if (npx > tpx[lim] || nqx > tqx[lim] || npy > tpy[lim] ||                         nqy > tqy[lim])                       continue;                     if (npx >= 0 && nqx >= 0 && npy >= 0 && nqy >= 0) {                       na = a & (v == 0), nb = b & (v == 0);                       update(f[now][npx][nqx][npy][nqy][na][nb], res);                     }                     bool f1 = a & (v == 0), f2 = b & (v == 0);                     if (!f1 && npx + 1 >= 0 && nqx + 1 >= 0 && npy >= 0 &&                         nqy >= 0) {                       na = a & (v == 1), nb = b & (v == 0);                       update(f[now][npx + 1][nqx + 1][npy][nqy][na][nb], res);                     }                     if (!f2 && npx >= 0 && nqx >= 0 && npy + 1 >= 0 &&                         nqy + 1 >= 0) {                       na = a & (v == 0), nb = b & (v == 1);                       update(f[now][npx][nqx][npy + 1][nqy + 1][na][nb], res);                     }                     if (!f1 && !f2 && npx + 1 >= 0 && nqx + 1 >= 0 &&                         npy + 1 >= 0 && nqy + 1 >= 0) {                       na = a & (v == 1), nb = b & (v == 1);                       update(f[now][npx + 1][nqx + 1][npy + 1][nqy + 1][na][nb],                              res);                     }                   }             }     }     int ans = mod - 1;     for (int a = 0; a < 2; a++)       for (int b = 0; b < 2; b++) update(ans, f[now][0][0][0][0][a][b]);     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int a = -2147483647, b = 0;     for (int i = 0; i < n - 1; ++i) {       int x;       cin >> x;       a = max(a, x);     }     cin >> b;     a = max(a, b);     cout << (int)(a ^ b);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     if (n % 2 == 1) {       string input;       cin >> input;       cout <<  No  << endl;       return 0;     }     stack<char> parenthesis;     char input;     bool flag = true;     cin >> input;     parenthesis.push(input);     for (int i = 1; i < n; i++) {       cin >> input;       if (parenthesis.empty())         parenthesis.push(input);       else if (parenthesis.top() ==  (  && input ==  ) ) {         parenthesis.pop();       } else {         parenthesis.push(input);       }     }     if (parenthesis.empty())       cout <<  Yes  << endl;     else if (parenthesis.size() > 2)       cout <<  No  << endl;     else {       input = parenthesis.top();       parenthesis.pop();       if (parenthesis.top() ==  )  && input ==  ( )         cout <<  Yes  << endl;       else         cout <<  No  << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 300100;   const int MOD = 998244353;   inline int mnoz(long long a, long long b) {     a *= b;     a %= MOD;     return a;   }   inline int dodaj(long long a, long long b) {     a += b;     a %= MOD;     return a;   }   long long quick_pow(int i, int x) {     int wynik = 1;     while (x) {       if (x % 2) wynik = mnoz(wynik, i);       i = mnoz(i, i);       x >>= 1;     }     return wynik;   }   int odwr(int i) { return quick_pow(i, MOD - 2); }   int n;   vector<vector<int> > tree(MAX_N);   int bez_kraw[MAX_N];   int czeka[MAX_N];   int ma_pod[MAX_N];   int p[MAX_N];   void wczytaj() {     cin >> n;     for (int i = 1; i <= n - 1; i++) {       int a, b;       cin >> a >> b;       tree[a].push_back(b);       tree[b].push_back(a);     }   }   void licz(int i) {     czeka[i] = 1;     bez_kraw[i] = 1;     for (__typeof(tree[i].begin()) it = tree[i].begin(); it != tree[i].end();          it++)       if (*it != p[i]) {         p[*it] = i;         licz(*it);         czeka[i] = mnoz(czeka[i], dodaj(mnoz(ma_pod[*it], 2), bez_kraw[*it]));         bez_kraw[i] = mnoz(bez_kraw[i], dodaj(ma_pod[*it], bez_kraw[*it]));       }     for (__typeof(tree[i].begin()) it = tree[i].begin(); it != tree[i].end();          it++)       if (*it != p[i])         ma_pod[i] =             dodaj(ma_pod[i],                   mnoz(czeka[*it], mnoz(czeka[i], odwr(dodaj(mnoz(ma_pod[*it], 2),                                                              bez_kraw[*it])))));   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     wczytaj();     licz(1);     int wynik = dodaj(bez_kraw[1], ma_pod[1]);     cout << wynik << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long int MAX = 1000000007;   const long long int MAXN = 100005;   int solve() {     int n, sx = 0, sy = 0, ans = -1;     cin >> n;     int x[n], y[n];     for (int i = 0; i < n; i++) {       cin >> x[i] >> y[i];       sx += x[i];       sy += y[i];     }     if (sx % 2 == 0 && sy % 2 == 0)       cout <<  0  << endl;     else if (sx % 2 == 0 && sy % 2 == 1 || sx % 2 == 1 && sy % 2 == 0) {       cout <<  -1 ;     } else if (sx % 2 == 1 && sy % 2 == 1) {       for (int i = 0; i < n; i++) {         if (x[i] % 2 == 0 && y[i] % 2 == 1 || x[i] % 2 == 1 && y[i] % 2 == 0) {           ans = 1;           break;         }       }       cout << ans;     }     return 0;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int t;     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long maxn = 100;   string v[maxn];   long long cn[26];   char mp[101][10000];   signed main() {     long long n;     cin >> n;     string ts =  aouie ;     for (long long i = 5; i < n && n / i >= 5; i++) {       if (n % i) continue;       for (long long j = 0; j < i; j++)         for (long long l = 0; l < n / i; l++) mp[j][l] = ts[(j + l) % 5];       for (long long j = 0; j < i; j++) {         for (long long l = 0; l < n / i; l++) cout << mp[j][l];       }       return 0;     }     cout << -1;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   void read(T &t) {     t = 0;     char ch = getchar();     int f = 1;     while ( 0  > ch || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     do {       (t *= 10) += ch -  0 ;       ch = getchar();     } while ( 0  <= ch && ch <=  9 );     t *= f;   }   const int maxn = (1e5) + 10;   int n, m, c, q, fa[maxn];   map<int, int> fst[maxn];   set<int> s[maxn];   set<int>::iterator it;   char S[2];   int find(int x) {     if (fa[x] == x) return x;     return fa[x] = find(fa[x]);   }   void merge(int x, int y) {     x = find(x);     y = find(y);     if (x == y) return;     if (s[x].size() > s[y].size()) swap(x, y);     for (it = s[x].begin(); it != s[x].end(); it++) s[y].insert(*it);     s[x].clear();     fa[x] = y;   }   void add(int x, int y, int z) {     if (fst[x][z])       merge(fst[x][z], y);     else       fst[x][z] = y;     if (fst[y][z])       merge(fst[y][z], x);     else       fst[y][z] = x;     s[find(x)].insert(y);     s[find(y)].insert(x);   }   int main() {     read(n);     read(m);     read(c);     read(q);     int x, y;     for (int i = 1; i <= n; i++) fa[i] = i, s[i].insert(i);     for (int i = 1; i <= m + q; i++) {       if (i <= m)         S[1] =  + ;       else         scanf( %s , S + 1);       read(x);       read(y);       if (S[1] ==  + )         read(c), add(x, y, c);       else {         if (find(x) == find(y) || s[find(x)].count(y))           printf( Yes n );         else           printf( No n );       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string mirror =  AHIMOTUVWXY ;   string letter =  ABCDEFGHIJKLMNOPQRSTUVWXYZ ;   int main() {     long long n, m, i, j, k, x, y, z, t;     cin >> x >> y;     if ((x == 0 || x == 1) && y == 0) {       cout << 0 << endl;       return 0;     }     if (x == 1 && y == 1) {       cout << 1 << endl;       return 0;     }     if (x > 0) {       if (y > -(x - 1) && y <= x) y = 0;     } else {       if (y >= x && y < -x) y = 0;     }     if (y > 0) {       if (x >= -y && x < y) x = 0;     } else {       if (x > y && x <= abs(y) + 1) x = 0;     }     if (x == 0) {       long long ans = max(0LL, abs(y) - 1) * 4;       if (y > 0)         ans += 2;       else         ans += 4;       cout << ans << endl;       return 0;     }     if (y == 0) {       long long ans = max(0LL, abs(x) - 1) * 4;       if (x < 0)         ans += 3;       else         ans++;       cout << ans << endl;       return 0;     }   }


#include <bits/stdc++.h>   int main() {     long long int n;     scanf( %lld , &n);     printf( %lld , 6 * n * (n + 1) / 2 + 1);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int b, g, n;     cin >> b >> g >> n;     cout << min(g, n) - max(0LL, n - b) + 1;     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   struct s {     char g;     long s, e;   };   int main() {     long n, i, j, c, ans = 0, day = 0, m = 0, f = 0;     struct s a[5005];     cin >> n;     for (i = 0; i < n; ++i) cin >> a[i].g >> a[i].s >> a[i].e;     for (day = 1; day <= 366; ++day) {       m = 0;       f = 0;       for (i = 0; i < n; ++i)         if (a[i].s <= day && a[i].e >= day) {           if (a[i].g ==  M )             m++;           else             f++;         }       ans = max(ans, 2 * (min(m, f)));     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int arr[100007];   int main() {     int i, n, k, distinct, r;     map<int, int> M;     while (scanf( %d%d , &n, &k) == 2) {       bool flag = true;       M.clear();       distinct = 0;       for (i = 0; i < n; i++) {         scanf( %d , &arr[i]);         if (M[arr[i]] == 0) {           M[arr[i]]++;           distinct++;         } else if (flag) {           M[arr[i]]++;         }         if (distinct == k && flag) {           r = i;           flag = false;         }       }       if (distinct < k)         puts( -1 -1 );       else {         i = 0;         while (M[arr[i]] > 1) {           M[arr[i]]--;           i++;         }         if (i > r) i = r;         printf( %d %d n , i + 1, r + 1);       }     }     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   long long a[100];   struct node {     long long l;     long long r;     long long x;   } p[100];   bool cmp(node aa, node bb) { return aa.x > bb.x; }   int main() {     long long n, h, m, i, ans = 0;     cin >> n >> h >> m;     for (i = 1; i <= n; i++) {       a[i] = -1;     }     for (i = 1; i <= m; i++) {       cin >> p[i].l >> p[i].r >> p[i].x;     }     sort(p + 1, p + 1 + m, cmp);     for (i = 1; i <= m; i++) {       for (long long j = p[i].l; j <= p[i].r; j++) {         a[j] = min(p[i].x, h);       }     }     for (i = 1; i <= n; i++) {       if (a[i] < 0) {         ans += h * h;       } else {         ans += a[i] * a[i];       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   const double pi = acos(-1.0), eps = 1e-9;   const int dx[8] = {1, -1, 0, 0, 1, 1, -1, -1};   const int dy[8] = {0, 0, 1, -1, 1, -1, -1, 1};   const int MO = (int)(1e9 + 7);   using namespace std;   string s[2001];   int n, k, l[1001][1001];   int lcp(int a, int b) {     int ret = 0;     while (ret < min((int)((s[a]).size()), (int)((s[b]).size())) &&            s[a][ret] == s[b][ret])       ++ret;     return ret;   }   int who[1001], ans;   void dfs(int dep, int get) {     if (dep == n) {       int ret = 0;       if (get != k) return;       for (int i = 1; i <= k; i++)         for (int j = i + 1; j <= k; j++) ret += l[who[i]][who[j]];       {         if (ret > ans) ans = ret;       };       return;     }     dfs(dep + 1, get);     who[get + 1] = dep + 1;     dfs(dep + 1, get + 1);   }   int main() {     cin >> n >> k;     for (int i = 1; i <= n; i++) cin >> s[i];     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++) l[i][j] = lcp(i, j);     dfs(0, 0);     cout << ans << endl;   }


#pragma GCC optimize ( Ofast )   #include<bits/stdc++.h>   using namespace std;   void*wmem;   char memarr[96000000];   template<class T> inline void walloc1d(T **arr, int x, void **mem = &wmem){     static int skip[16] = {0, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1};     (*mem) = (void*)( ((char*)(*mem)) + skip[((unsigned long long)(*mem)) & 15] );     (*arr)=(T*)(*mem);     (*mem)=((*arr)+x);   }   template<class T> inline void walloc1d(T **arr, int x1, int x2, void **mem = &wmem){     walloc1d(arr, x2-x1, mem);     (*arr) -= x1;   }   template<class T1> void sortA_L(int N, T1 a[], void *mem = wmem){     sort(a, a+N);   }   template<class T1, class T2> void sortA_L(int N, T1 a[], T2 b[], void *mem = wmem){     int i;     pair<T1, T2>*arr;     walloc1d(&arr, N, &mem);     for(i=(0);i<(N);i++){       arr[i].first = a[i];       arr[i].second = b[i];     }     sort(arr, arr+N);     for(i=(0);i<(N);i++){       a[i] = arr[i].first;       b[i] = arr[i].second;     }   }   inline int my_getchar(){     static char buf[1048576];     static int s = 1048576;     static int e = 1048576;     if(s == e && e == 1048576){       e = fread(buf, 1, 1048576, stdin);       s = 0;     }     if(s == e){       return EOF;     }     return buf[s++];   }   inline void rd(int &x){     int k;     int m=0;     x=0;     for(;;){       k = my_getchar();       if(k== - ){         m=1;         break;       }       if( 0 <=k&&k<= 9 ){         x=k- 0 ;         break;       }     }     for(;;){       k = my_getchar();       if(k< 0 ||k> 9 ){         break;       }       x=x*10+k- 0 ;     }     if(m){       x=-x;     }   }   inline int rd_int(void){     int x;     rd(x);     return x;   }   struct MY_WRITER{     char buf[1048576];     int s;     int e;     MY_WRITER(){       s = 0;       e = 1048576;     }     ~MY_WRITER(){       if(s){         fwrite(buf, 1, s, stdout);       }     }   }   ;   MY_WRITER MY_WRITER_VAR;   void my_putchar(int a){     if(MY_WRITER_VAR.s == MY_WRITER_VAR.e){       fwrite(MY_WRITER_VAR.buf, 1, MY_WRITER_VAR.s, stdout);       MY_WRITER_VAR.s = 0;     }     MY_WRITER_VAR.buf[MY_WRITER_VAR.s++] = a;   }   inline void wt_L(char a){     my_putchar(a);   }   inline void wt_L(int x){     int s=0;     int m=0;     char f[10];     if(x<0){       m=1;       x=-x;     }     while(x){       f[s++]=x%10;       x/=10;     }     if(!s){       f[s++]=0;     }     if(m){       my_putchar( - );     }     while(s--){       my_putchar(f[s]+ 0 );     }   }   template<class S, class T> inline S divup_L(S a, T b){     return (a+b-1)/b;   }   int M;   int K;   int A[200000];   int sz;   int arr[200000];   int ind[200000];   int n;   int res[1000][1000];   int main(){     int Lj4PdHRW;     wmem = memarr;     int KL2GvlyY = rd_int();     for(Lj4PdHRW=(0);Lj4PdHRW<(KL2GvlyY);Lj4PdHRW++){       int i;       rd(M);       rd(K);       {         int cTE1_r3A;         for(cTE1_r3A=(0);cTE1_r3A<(K);cTE1_r3A++){           rd(A[cTE1_r3A]);         }       }       for(i=(0);i<(K);i++){         ind[i] = i+1;       }       sortA_L(K, A, ind);       sz = n = 0;       for(i=(0);i<(K);i++){         int ao_dF3pO;         for(ao_dF3pO=(0);ao_dF3pO<(A[i]);ao_dF3pO++){           arr[sz++] = ind[i];         }       }       while( ((divup_L(n,2))) * n + (n/2) * ((divup_L(n,2))) < M ){         n++;       }       while( ((divup_L(n,2))) * n < A[K-1] ){         n++;       }       for(i=(0);i<(n);i++){         int j;         for(j=(0);j<(n);j++){           res[i][j] = 0;         }       }       for(i=(0);i<(n);i+=(2)){         int j;         for(j=(1);j<(n);j+=(2)){           if(sz > 0){             res[i][j] = arr[--sz];           }         }       }       for(i=(0);i<(n);i+=(2)){         int j;         for(j=(0);j<(n);j+=(2)){           if(sz > 0){             res[i][j] = arr[--sz];           }         }       }       for(i=(1);i<(n);i+=(2)){         int j;         for(j=(0);j<(n);j+=(2)){           if(sz > 0){             res[i][j] = arr[--sz];           }         }       }       wt_L(n);       wt_L(  n );       {         int szDqbNYU;         int ytthggxT;         for(szDqbNYU=(0);szDqbNYU<(n);szDqbNYU++){           if(n==0){             wt_L(  n );           }           else{             for(ytthggxT=(0);ytthggxT<(n-1);ytthggxT++){               wt_L(res[szDqbNYU][ytthggxT]);               wt_L(   );             }             wt_L(res[szDqbNYU][ytthggxT]);             wt_L(  n );           }         }       }     }     return 0;   }   // cLay version 20210502-1 [beta]      // --- original code ---   // //no-unlocked   // int M, K, A[2d5];   // int sz, arr[], ind[];   // int n, res[1000][1000];   // {   //   REP(rd_int()){   //     rd(M,K,A(K));   //    //     rep(i,K) ind[i] = i+1;   //     sortA(K, A, ind);   //    //     sz = n = 0;   //     rep(i,K) rep(A[i]) arr[sz++] = ind[i];   //    //     while( (n/+2) * n + (n/2) * (n/+2) < M ) n++;   //     while( (n/+2) * n < A[K-1] ) n++;   //    //     rep(i,n) rep(j,n) res[i][j] = 0;   //     rep(i,0,n,2) rep(j,1,n,2) if(sz > 0) res[i][j] = arr[--sz];   //     rep(i,0,n,2) rep(j,0,n,2) if(sz > 0) res[i][j] = arr[--sz];   //     rep(i,1,n,2) rep(j,0,n,2) if(sz > 0) res[i][j] = arr[--sz];   //    //     wt(n);   //     wt(res(n,n));   //   }   // }


#include <bits/stdc++.h>   using namespace std;   string s[3];   int a[200][200];   int n;   int main() {     char card, team;     int tm, player;     cin >> s[0] >> s[1];     cin >> n;     for (int i = 0; i < n; i++) {       cin >> tm >> team >> player >> card;       if (card ==  y )         a[team][player]++;       else         a[team][player] += 2;       if (a[team][player] >= 2) {         if (team ==  a )           cout << s[1];         else           cout << s[0];         cout <<     << player <<     << tm << endl;         a[team][player] -= 9000;       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 3e5;   int arr[N + 100];   vector<pair<long long, int> > v;   set<int> st;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n, k;     cin >> n >> k;     for (int i = 1; i <= n; i++) {       long long c;       cin >> c;       v.push_back(make_pair(c, i));     }     for (int i = k + 1; i <= k + n; i++) st.insert(i);     sort(v.begin(), v.end(), greater<pair<long long, int> >());     long long ans = 0;     for (auto it : v) {       int ind = it.second;       auto cur = st.lower_bound(ind);       ans += (*cur - ind) * it.first;       arr[ind] = *cur;       st.erase(cur);     }     cout << ans <<   n ;     for (int i = 1; i <= n; i++) {       cout << arr[i] <<    ;     }     cout <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 7;   int n, q, fa[N];   double p[N], sum[N], ans;   vector<int> son[N];   void dfs(int x, int f) {     fa[x] = f;     for (int i = 0; i < son[x].size(); ++i) {       int y = son[x][i];       if (y == f) continue;       dfs(y, x);       sum[x] += 1 - p[y];       ans += p[x] * (1 - p[y]);     }   }   int main() {     scanf( %d , &n);     p[0] = 1;     for (int i = 1; i <= n; ++i) scanf( %lf , p + i);     for (int i = 1; i < n; ++i) {       int u, v;       scanf( %d%d , &u, &v);       ++u, ++v;       son[u].push_back(v);       son[v].push_back(u);     }     ans = 1 - p[1];     dfs(1, 0);     scanf( %d , &q);     while (q--) {       int k;       double p1;       scanf( %d%lf , &k, &p1);       ++k;       sum[fa[k]] -= p1 - p[k];       ans += sum[k] * (p1 - p[k]) - (p1 - p[k]) * p[fa[k]];       p[k] = p1;       printf( %.5lf n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1100;   int n, m, t;   int a[N];   int main() {     scanf( %d , &n);     memset(a, 0, sizeof(a));     for (int i = 1; i <= n; i++) {       int x;       scanf( %d , &x);       a[x]++;     }     scanf( %d , &t);     int mx = -1;     for (int i = 1; i <= 1000; i++) {       int j = i;       int sum = 0;       int k = t + 1;       while (k && j <= 1000) {         sum += a[j];         j++;         k--;       }       if (sum > mx) {         mx = sum;       }     }     printf( %d n , mx);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int i, j;     int n, a = 1, b = 1, c = 0, x;     scanf( %d , &n);     for (i = 0; i < n; i++) {       scanf( %d , &x);       if (x == 1) {         if (a == 0) {           printf( NO n );           break;         } else if (b == 0) {           b = 1;           c = 0;         } else if (c == 0) {           c = 1;           b = 0;         }       }       if (x == 2) {         if (b == 0) {           printf( NO n );           break;         } else if (a == 0) {           a = 1;           c = 0;         } else if (c == 0) {           c = 1;           a = 0;         }       }       if (x == 3) {         if (c == 0) {           printf( NO n );           break;         } else if (a == 0) {           a = 1;           b = 0;         } else if (b == 0) {           b = 1;           a = 0;         }       }     }     if (i == n) {       printf( YES n );     }   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1000000000;   long long A[100005];   map<long long, long long> mp;   int main() {     long long n, a, i;     cin >> n;     for (i = 1; i <= n; i++) {       cin >> a;       mp[a] += a;     }     A[1] = mp[1];     A[0] = 0;     for (i = 2; i <= 100000; i++) {       A[i] = max(A[i - 1], A[i - 2] + mp[i]);     }     cout << A[100000] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct elem {     int i1, i2, p1, p2, tipo;     elem() {}     elem(int i1, int i2) : i1(i1), i2(i2) { tipo = 0; }     elem(int i1, int i2, int p1, int p2) : i1(i1), i2(i2), p1(p1), p2(p2) {       tipo = 1;     }   };   int inverso(int x) {     if (x == 2) return 3;     if (x == 3) return 2;     return x;   }   vector<elem> lista;   const int limite = 505;   int m, n;   int t[limite][limite];   char buff[limite];   int b[limite];   void escribe() {     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) cout << t[i][j] <<  , ;       cout << endl;     }     cout << endl;   }   int main() {     scanf( %d%d , &m, &n);     for (int j = 0; j < m; j++) {       scanf( %s , buff);       for (int i = 0; i < n; i++) t[i][j] = buff[i] -  a ;     }     int jlibres = 0;     int itope;     {       int jj = 0;       int i = 0;       while (i < n and jj < m) {         int ii = i;         while (ii < n and t[ii][jj] == 0) ii++;         if (ii == n) {           jj++;           jlibres++;         } else {           lista.push_back(elem(i, ii));           for (int j = jj; j < m; j++) swap(t[i][j], t[ii][j]);           for (int ii = i + 1; ii < n; ii++) {             if (t[ii][jj]) {               int p1 = -t[ii][jj];               int p2 = t[i][jj];               lista.push_back(elem(i, ii, p1, p2));               for (int j = jj; j < m; j++)                 t[ii][j] = (t[ii][j] * p2 + t[i][j] * p1) % 5;             }           }           i++;           jj++;         }       }       itope = i;       jlibres += m - jj;     }     long long int sol = 1;     for (int j = 0; j < jlibres; j++) sol = sol * 5 % int(1e9 + 7);     int casos;     scanf( %d , &casos);     for (int cas = 0; cas < casos; cas++) {       scanf( %s , buff);       for (int i = 0; i < n; i++) b[i] = buff[i] -  a ;       for (int k = 0; k < int(lista.size()); k++) {         elem &e = lista[k];         int i1 = e.i1;         int i2 = e.i2;         int p1 = e.p1;         int p2 = e.p2;         if (e.tipo == 0) {           swap(b[i1], b[i2]);         } else {           b[i2] = (b[i2] * p2 + b[i1] * p1) % 5;         }       }       bool error = false;       for (int i = itope; i < n and not error; i++) error = b[i] != 0;       if (error)         printf( %d n , 0);       else         printf( %d n , int(sol));     }   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     int n;     string s;     cin >> n >> s;     if (s.find( 0 ) == string::npos) {       cout << 1 <<     << n / 2 <<    ;       cout << 2 <<     << n / 2 + 1;       return;     } else {       for (int i = 0; i < n / 2; i++) {         if (s[i] ==  0 ) {           cout << i + 2 <<     << n <<    ;           cout << i + 1 <<     << n;           return;         }       }       for (int i = n / 2; i < n; i++) {         if (s[i] ==  0 ) {           cout << 1 <<     << i + 1 <<    ;           cout << 1 <<     << i;           return;         }       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int t;     cin >> t;     while (t--) {       solve();       cout <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, m, k, i, j, x, y, z, c, f, t, s, p;     cin >> k >> n >> s >> p;     if (n % s == 0) {       z = (n / s) * k;       if (z % p == 0) {         cout << z / p << endl;       } else {         cout << z / p + 1 << endl;       }     } else {       z = (n / s + 1) * k;       if (z % p == 0) {         cout << z / p << endl;       } else {         cout << z / p + 1 << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   const int nmax = 3e5 + 1;   using namespace std;   struct node {     int ind;     int cur;     node() {}     node(int cur, int ind) : cur(cur), ind(ind){};   };   node bolshe(node a, node b) {     return (a.cur == b.cur ? (a.ind > b.ind ? a : b) : (a.cur > b.cur ? a : b));   }   struct vertex {     vertex *l;     vertex *r;     int sum;     vertex(){};     vertex(int sum) : l(nullptr), r(nullptr), sum(sum){};     vertex(vertex *l, vertex *r) : l(l), r(r), sum(0) {       if (l != nullptr) sum += l->sum;       if (r != nullptr) sum += r->sum;     };   };   struct segment_tree {     node tr[nmax * 5];     int add[nmax * 5];     void build(vector<int> &a, int v, int cl, int cr) {       if (cl == cr) {         if (a[cl] > (cl + 1))           tr[v].cur = -1e9;         else           tr[v].cur = a[cl] - (cl + 1);         tr[v].ind = cl;         return;       }       int mid = (cl + cr) / 2;       build(a, v * 2, cl, mid);       build(a, v * 2 + 1, mid + 1, cr);       tr[v] = bolshe(tr[v * 2], tr[v * 2 + 1]);     }     void push(int v) {       add[v * 2] += add[v];       add[v * 2 + 1] += add[v];       tr[v].cur += add[v];       add[v] = 0;       return;     }     void increase(int v, int cl, int cr, int left, int right) {       if (left > right) return;       if (cl == left && cr == right) {         add[v] += 1;         return;       }       push(v);       int mid = (cl + cr) / 2;       increase(v * 2, cl, mid, left, min(right, mid));       increase(v * 2 + 1, mid + 1, cr, max(left, mid + 1), right);       tr[v] = bolshe(node(tr[v * 2].cur + add[v * 2], tr[v * 2].ind),                      node(tr[v * 2 + 1].cur + add[v * 2 + 1], tr[v * 2 + 1].ind));     }     void decrease(int v, int cl, int cr, int left, int right, int x) {       if (left > right) return;       if (cl == left && cr == right) {         add[v] -= x;         return;       }       push(v);       int mid = (cl + cr) / 2;       decrease(v * 2, cl, mid, left, min(right, mid), x);       decrease(v * 2 + 1, mid + 1, cr, max(left, mid + 1), right, x);       tr[v] = bolshe(node(tr[v * 2].cur + add[v * 2], tr[v * 2].ind),                      node(tr[v * 2 + 1].cur + add[v * 2 + 1], tr[v * 2 + 1].ind));     }     node find_max(int v, int cl, int cr, int left, int right) {       if (left > right) return node(-1e9, 1e9);       if (cl == left && cr == right) return node(tr[v].cur + add[v], tr[v].ind);       push(v);       int mid = (cl + cr) / 2;       return bolshe(find_max(v * 2, cl, mid, left, min(right, mid)),                     find_max(v * 2 + 1, mid + 1, cr, max(left, mid + 1), right));     }   };   segment_tree sg;   struct segment_tree_2 {     int tr[(int)(nmax * 5)];     void push(int v) {       if (tr[v] != -1) tr[v * 2] = tr[v * 2 + 1] = tr[v], tr[v] = -1;     }     void update(int v, int cl, int cr, int left, int right, int x) {       if (left > right) return;       if (cl == left && cr == right) {         tr[v] = x;         return;       }       push(v);       int mid = (cl + cr) / 2;       update(v * 2, cl, mid, left, min(right, mid), x);       update(v * 2 + 1, mid + 1, cr, max(left, mid + 1), right, x);     }     int get_number(int v, int cl, int cr, int pos) {       if (cl == cr) return tr[v];       push(v);       int mid = (cl + cr) / 2;       if (pos <= mid)         return get_number(v * 2, cl, mid, pos);       else         return get_number(v * 2 + 1, mid + 1, cr, pos);     }   };   segment_tree_2 sg2;   struct segment_tree_3 {     vector<int> tr[nmax * 5];     void build(vector<int> &a, int v, int cl, int cr) {       if (cl == cr) {         tr[v].push_back(a[cl]);         return;       }       int mid = (cl + cr) / 2;       build(a, v * 2, cl, mid);       build(a, v * 2 + 1, mid + 1, cr);       merge(tr[v * 2].begin(), tr[v * 2].end(), tr[v * 2 + 1].begin(),             tr[v * 2 + 1].end(), back_inserter(tr[v]));     }     int get(int v, int cl, int cr, int left, int right, int x) {       if (left > right) return 0;       if (cl == left && cr == right) {         int cur = lower_bound(tr[v].begin(), tr[v].end(), x) - tr[v].begin();         return tr[v].size() - cur;       }       int mid = (cl + cr) / 2;       return get(v * 2, cl, mid, left, min(right, mid), x) +              get(v * 2 + 1, mid + 1, cr, max(left, mid + 1), right, x);     }   };   segment_tree_3 sg3;   int32_t main() {     int n, m;     cin >> n >> m;     vector<int> a(n);     for (int i = 0; i < n; i += 1) cin >> a[i];     sg.build(a, 1, 0, n - 1);     sg2.update(1, 0, n - 1, 0, n - 1, 1e9);     vector<int> pr;     int lst = -1;     vector<int> need(n, -1e9);     while (1) {       node found = sg.find_max(1, 0, n - 1, 0, n - 1);       if (found.ind > n) break;       if (found.cur != 0) break;       int wow = sg2.get_number(1, 0, n - 1, found.ind);       if (wow == 1e9)         need[found.ind] = wow;       else if (need[wow] == 1e9)         need[found.ind] = wow;       else         need[found.ind] = need[wow];       pr.push_back(found.ind);       sg.increase(1, 0, n - 1, found.ind + 1, n - 1);       sg.decrease(1, 0, n - 1, found.ind, found.ind, 1e9);       sg2.update(1, 0, n - 1, found.ind + 1, n - 1, found.ind);     }     sg3.build(need, 1, 0, n - 1);     for (int i = 0; i < m; i += 1) {       int l, r;       cin >> l >> r;       r = n - 1 - r;       cout << sg3.get(1, 0, n - 1, l, r, l) <<   n ;     }   }


#include <bits/stdc++.h>   #pragma GCC optimize(2)   #pragma G++ optimize(2)   using namespace std;   const int MAX_N = 2e3 + 5;   char s[MAX_N], t[MAX_N];   int sufs[MAX_N][26], suft[MAX_N][26];   int dp[MAX_N][MAX_N];   int solve(int i, int j) {     if (j == 0) return 0;     if (~dp[i][j]) return dp[i][j];     int res = 2e9;     if (i > 0) {       res = 1 + solve(i - 1, j);       if (s[i] == t[j]) res = min(res, solve(i - 1, j - 1));     }     int c = t[j] -  a ;     if (sufs[i + 1][c] > suft[j + 1][c]) res = min(res, solve(i, j - 1));     return dp[i][j] = res;   }   int main() {     int T;     scanf( %d , &T);     while (T--) {       int n;       scanf( %d , &n), scanf( %s , s + 1), scanf( %s , t + 1);       for (register int i = 0; i <= 25; ++i) sufs[n + 1][i] = suft[n + 1][i] = 0;       for (register int i = 0; i <= n; ++i)         for (register int j = 0; j <= n; ++j) dp[i][j] = -1;       for (register int i = n; i >= 1; --i) {         for (register int j = 0; j <= 25; ++j)           sufs[i][j] = sufs[i + 1][j], suft[i][j] = suft[i + 1][j];         sufs[i][s[i] -  a ]++, suft[i][t[i] -  a ]++;       }       int ans = solve(n, n);       if (ans > 1e9) ans = -1;       printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long int mxn = 1e5 + 5;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int t = 1;     cin >> t;     while (t--) {       long long int i, j, k, n, m;       cin >> n >> k;       string s;       cin >> s;       map<long long int, long long int> mp;       long long int sum = 0;       for (i = 0; i < n; i++) {         if (s[i] ==  0 )           sum++;         else           sum--;         mp[sum]++;       }       if (sum == 0 && mp[k])         cout << -1 <<   n ;       else if (sum == 0)         cout << 0 <<   n ;       else {         long long int ans = 0, p = 0;         if (p == k) {           ans++;         }         for (i = 0; i < n; i++) {           if (s[i] ==  0 )             p++;           else             p--;           if ((k - p) % sum == 0 && ((k - p) / sum) >= 0) {             ans++;           }         }         cout << ans <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:167772160000 )   using namespace std;   void redirectIO() {     ios::sync_with_stdio(false);     cin.tie(0);   }   int sc1, sc2;   int best;   vector<pair<int, int> > bestAns;   vector<pair<int, int> > solve() {     best = -10;     bestAns.clear();     for (int a = 0; a <= 3; a++) {       for (int b = 0; a + b <= 3; b++) {         for (int c = 0; c <= 3; c++) {           for (int d = 0; d + c <= 3; d++) {             for (int aa = 0; aa <= 1; aa++)               for (int bb = 0; aa + bb <= 1; bb++)                 for (int cc = 0; cc + bb + aa <= 1; cc++)                   for (int dd = 0; dd + bb + cc + aa <= 1; dd++) {                     if (a + b - c - d + aa + bb - cc - dd <= best) continue;                     if ((d + c + dd + cc == 3) == (a + b + aa + bb == 3))                       continue;                     if (dd + cc + aa + bb > 0 && a + b + c + d != 4) continue;                     if (a + b + c + d > 4) continue;                     if (aa + bb > 0 && a + b != 2) continue;                     if (cc + dd > 0 && c + d != 2) continue;                     vector<pair<int, int> > cur;                     cur.reserve(5);                     int s1 = sc1, s2 = sc2;                     for (int i = 0; i < (a); i++) {                       s1 -= 26;                       s2 -= 24;                       cur.push_back(make_pair(26, 24));                     }                     for (int i = 0; i < (b); i++) {                       s1 -= 25;                       cur.push_back(make_pair(25, 0));                     }                     for (int i = 0; i < (c); i++) {                       s1 -= 24;                       s2 -= 26;                       cur.push_back(make_pair(24, 26));                     }                     for (int i = 0; i < (d); i++) {                       s2 -= 25;                       cur.push_back(make_pair(0, 25));                     }                     for (int i = 0; i < (aa); i++) {                       s1 -= 16;                       s2 -= 14;                       cur.push_back(make_pair(16, 14));                     }                     for (int i = 0; i < (bb); i++) {                       s1 -= 15;                       cur.push_back(make_pair(15, 0));                     }                     for (int i = 0; i < (cc); i++) {                       s1 -= 14;                       s2 -= 16;                       cur.push_back(make_pair(14, 16));                     }                     for (int i = 0; i < (dd); i++) {                       s2 -= 15;                       cur.push_back(make_pair(0, 15));                     }                     if (s1 < 0 || s2 < 0) continue;                     if (a > 0) {                       int df = min(s1, s2);                       int ind = 0;                       cur[ind].first += df;                       cur[ind].second += df;                       s1 -= df;                       s2 -= df;                     }                     if (c > 0) {                       int df = min(s1, s2);                       int ind = a + b;                       cur[ind].first += df;                       cur[ind].second += df;                       s1 -= df;                       s2 -= df;                     }                     if (aa > 0) {                       int df = min(s1, s2);                       int ind = a + b + c + d;                       cur[ind].first += df;                       cur[ind].second += df;                       s1 -= df;                       s2 -= df;                     }                     if (cc > 0) {                       int df = min(s1, s2);                       int ind = a + b + c + d;                       cur[ind].first += df;                       cur[ind].second += df;                       s1 -= df;                       s2 -= df;                     }                     for (int ind = a + b + c + d + aa;                          ind < a + b + c + d + aa + bb; ind++) {                       int take = min(13, s2);                       s2 -= take;                       cur[ind].second += take;                     }                     for (int ind = a; ind < a + b; ind++) {                       int take = min(23, s2);                       s2 -= take;                       cur[ind].second += take;                     }                     for (int ind = a + b + c; ind < a + b + c + d; ind++) {                       int take = min(23, s1);                       s1 -= take;                       cur[ind].first += take;                     }                     for (int ind = a + b + c + d + aa + bb + cc;                          ind < a + b + c + d + aa + bb + cc + dd; ind++) {                       int take = min(13, s1);                       s1 -= take;                       cur[ind].first += take;                     }                     if (s1 != 0 || s2 != 0) continue;                     best = a + b - c - d + aa + bb - cc - dd;                     if (a + b == 3) {                       swap(cur[0], cur.back());                     }                     bestAns = cur;                   }           }         }       }     }     return bestAns;   }   int main() {     redirectIO();     int m;     cin >> m;     while (m--) {       cin >> sc1 >> sc2;       vector<pair<int, int> > cur = solve();       if (cur.empty())         cout <<  Impossible n ;       else {         int cnta = 0;         for (pair<int, int> x : cur)           if (x.first > x.second) cnta++;         cout << cnta <<  :  << cur.size() - cnta <<   n ;         for (pair<int, int> x : cur) cout << x.first <<  :  << x.second <<    ;         cout <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long pw(long long x, long long a) {     if (a == 0) return 1;     long long t = pw(x, a / 2);     if (a % 2 == 0)       return (t * t);     else       return (t * t * x);   }   bool prime(int x) {     if (x < 2) return false;     for (int i = 2; i <= sqrt(x); i++) {       if ((x % i) == 0) return false;     }     return true;   }   bool cmp(const pair<int, int> &a, const pair<int, int> &b) {     return (a.first < b.first);   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n;     cin >> n;     string x;     cin >> x;     int ind = 0;     int dif = 0;     bool cut = 0;     long long ans = 0;     for (int i = 0; i < n; i++) {       if (x[i] ==  ( )         dif++;       else         dif--;       if (dif < 0) cut = 1;       if (dif == 0 && cut) {         ans += i - ind + 1;         ind = i + 1;         cut = 0;       }       if (dif == 0) ind = i + 1;     }     if (dif != 0)       cout << -1 << endl;     else       cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long fpow(long long n, long long k, long long p = 1000000007) {     long long r = 1;     for (; k; k >>= 1) {       if (k & 1) r = r * n % p;       n = n * n % p;     }     return r;   }   long long inv(long long a, long long p = 1000000007) {     return fpow(a, p - 2, p);   }   long long fact[100001];   void pre() {     fact[0] = 1;     fact[1] = 1;     for (long long i = 2; i <= 100000; i++)       fact[i] = (i * fact[i - 1]) % 1000000007;   }   int main() {     pre();     long long n, k;     cin >> n >> k;     long long arr[n], cnt = 0;     map<long long, long long> m;     for (long long i = 0; i < n; i++) {       cin >> arr[i];       string temp = to_string(arr[i]);       long long flag = 1;       for (long long j = 0; j < temp.size(); j++) {         if (temp[j] ==  4  or temp[j] ==  7 ) {         } else {           flag = 0;           break;         }       }       if (flag) {         m[arr[i]]++;         cnt++;       }     }     long long dp[m.size()][m.size()];     vector<long long> freq;     memset(dp, 0, sizeof(dp));     for (map<long long, long long>::iterator it = m.begin(); it != m.end(); it++)       freq.push_back(it->second);     sort(freq.begin(), freq.end());     for (long long i = 0; i < freq.size(); i++) dp[0][i] = freq[i];     long long cutoff = m.size() - 2;     for (long long i = 1; i < m.size(); i++) {       long long sum = 0;       for (long long j = 0; j <= cutoff; j++) {         long long smallest = dp[0][j];         if (j == 0) {           for (long long k = j + 1; k <= cutoff + 1; k++) {             dp[i][j] =                 (dp[i][j] + (smallest * dp[i - 1][k]) % 1000000007) % 1000000007;             sum = dp[i][j];           }         } else {           sum = (sum * inv(dp[0][j - 1])) % 1000000007;           sum = (sum - dp[i - 1][j] + 1000000007) % 1000000007;           sum = (sum * dp[0][j]) % 1000000007;           dp[i][j] = sum;         }       }       cutoff--;     }     if (m.size() + n - cnt < k)       cout << 0;     else {       long long ans = 0;       for (long long i = 1; i <= min((long long)m.size(), k); i++) {         long long temp = 0;         if (k - i <= n - cnt) {           for (long long j = 0; j < m.size(); j++)             temp = (temp + dp[i - 1][j]) % 1000000007;           long long num = fact[n - cnt];           long long den = (fact[k - i] * fact[n - cnt - k + i]) % 1000000007;           num = (num * inv(den)) % 1000000007;           ans = (ans + (num * temp) % 1000000007) % 1000000007;         }       }       if (n - cnt >= k) {         long long num = fact[n - cnt];         long long den = (fact[k] * fact[n - cnt - k]) % 1000000007;         num = (num * inv(den)) % 1000000007;         ans = (ans + num) % 1000000007;       }       cout << ans;     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 7;   int is0(int d) { return d << 1; }   int is1(int d) { return d << 1 | 1; }   struct TwoSat {     static const int N = ::N << 1;     vector<int> G[N];     int pre[N], dfn[N], dfs_clock;     int scc[N], sccn;     int mark[N], n;     stack<int> S;     void init(int _n) {       for (int i = ((n = _n << 1)) - 1; i >= (0); --i) G[i].clear();     }     void addAnd(int a) { G[a ^ 1].push_back(a); }     void addThen(int a, int b) {       G[a].push_back(b);       G[b ^ 1].push_back(a ^ 1);     }     void addOr(int a, int b) {       G[a ^ 1].push_back(b);       G[b ^ 1].push_back(a);     }     void addXor(int a, int b) {       G[a].push_back(b ^ 1);       G[a ^ 1].push_back(b);       G[b].push_back(a ^ 1);       G[b ^ 1].push_back(a);     }     void dfs(int u) {       pre[u] = dfn[u] = ++dfs_clock;       S.push(u);       for (int _v = (0); _v < (((int)(G[u]).size())); ++_v) {         int v = G[u][_v];         if (!pre[v]) {           dfs(v);           dfn[u] = min(dfn[u], dfn[v]);         } else if (!scc[v])           dfn[u] = min(dfn[u], pre[v]);       }       if (pre[u] == dfn[u]) {         sccn++;         while (1) {           int x = S.top();           S.pop();           scc[x] = sccn;           if (x == u) break;         }       }     }     void find() {       dfs_clock = sccn = 0;       fill(pre, pre + n, 0);       fill(scc, scc + n, 0);       for (int i = (0); i < (n); ++i)         if (!pre[i]) dfs(i);     }     bool solve() {       find();       for (int i = 0; i < n; i += 2) {         if (scc[i] == scc[i + 1]) return false;         mark[i >> 1] = (scc[i] > scc[i + 1]);       }       return true;     }   } G;   int n, m;   vector<int> s[N];   pair<int, int> diff(vector<int> &a, vector<int> &b) {     int L = min(((int)(a).size()), ((int)(b).size()));     for (int i = (0); i < (L); ++i)       if (a[i] != b[i]) return make_pair(a[i], b[i]);     return make_pair(-1, -1);   }   void solve() {     G.init(m);     for (int i = (0); i < (n - 1); ++i) {       pair<int, int> r = diff(s[i], s[i + 1]);       if (!~r.first && ((int)(s[i]).size()) > ((int)(s[i + 1]).size())) {         puts( No );         return;       }       if (~r.first) {         if (r.first > r.second) {           G.addAnd(is1(r.first));           G.addAnd(is0(r.second));         } else {           G.addThen(is1(r.second), is1(r.first));         }       }     }     if (G.solve()) {       puts( Yes );       vector<int> ans;       for (int i = (0); i < (m); ++i)         if (G.mark[i]) ans.push_back(i + 1);       printf( %d n , ((int)(ans).size()));       for (int i = (0); i < (((int)(ans).size())); ++i)         printf( %d%c , ans[i],    n [i == ((int)(ans).size()) - 1]);     } else {       puts( No );     }   }   int main() {     scanf( %d%d , &n, &m);     for (int i = (0); i < (n); ++i) {       int li;       scanf( %d , &li);       for (int j = (0); j < (li); ++j) {         int x;         scanf( %d , &x);         s[i].push_back(x - 1);       }     }     solve();     return 0;   }