#include <bits/stdc++.h>   using namespace std;   const int mod = 998244353;   const int mxn = 1000001, k = 4;   const char c[k] = { ( ,  ) ,  ? ,  ? };   int n;   string second;   long long first[mxn], rf[mxn], iv[mxn], a[k];   vector<long long> dp[mxn];   long long sol() {     int x = a[2] + a[3], y = a[1] + a[3] - a[0] - 1;     if (y < 0) return 0;     if (!dp[x].empty()) return dp[x][min(x, y)];     dp[x].resize(x + 1);     dp[x][0] = 1;     for (int i = 1; i <= x; i++) {       dp[x][i] = (first[x] * rf[i] % mod * rf[x - i] + dp[x][i - 1]) % mod;     }     return dp[x][min(x, y)];   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> second;     n = second.size();     for (int i = 1; i < k; i += 2)       a[i] = count(second.begin(), second.end(), c[i]);     first[0] = rf[0] = iv[0] = 1;     for (int i = 1; i <= n; i++) {       iv[i] = ~-i ? mod - mod / i * iv[mod % i] % mod : 1;       first[i] = i * first[i - 1] % mod;       rf[i] = iv[i] * rf[i - 1] % mod;     }     long long ret = 0;     for (long long i = 0; i < n; i++) {       for (int j = 1; j < k; j += 2) a[j] -= (second[i] == c[j]);       if (!((find(c, c + k, second[i]) - c) & 1)) (ret += sol()) %= mod;       for (int j = 0; j < k; j += 2) a[j] += (second[i] == c[j]);     }     cout << ret <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     char key[] =  (8[ ;     char fir[100], sec[100];     int i, len, a, b, c;     scanf( %s%s , fir, sec);     len = strlen(fir);     c = 0;     for (i = 0; i < len; i += 2) {       a = strchr(key, fir[i]) - key;       b = strchr(key, sec[i]) - key;       if (a == b) continue;       if ((a + 1) % 3 == b)         c++;       else         c--;     }     if (c > 0)       puts( TEAM 1 WINS );     else if (c < 0)       puts( TEAM 2 WINS );     else       puts( TIE );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   typedef long long ll;   typedef __int128_t LL;   typedef long double ld;   typedef pair<int, int> pii;   typedef pair<ll, ll> pll;   #define F first   #define S second   #define pb push_back   mt19937 rnd;      const int N = 1e5 + 10;   bool good[N], ban[N];      vector<int> get(const vector<int>& a) {       vector<int> res;       for (int i = 1; i < a.size(); i++) {           res.pb(a[i] - a[i - 1] - 1);       }       return res;   }      bool solve0(int n) {       for (int i = 1; i <= n; i++) {           if (!good[i]) {               return 0;           }       }       return 1;   }      vector<int> solve1(int n) {       if (good[1] || good[n]) {           return {};       }       for (int i = 1; i <= n - 1; i++) {           if (good[i] && good[i + 1]) {               return {};           }       }       vector<int> res;       for (int i = 1, cnt = 0; i <= n; i++) {           if (!good[i]) {               cnt++;               if (i == n || good[i + 1]) {                   res.pb(cnt);                   cnt = 0;               }           }       }       return res;   }      vector<int> solve2(int n) {       if (!good[1] || !good[n]) {           return {};       }       vector<int> a = {0};       for (int i = 1, cnt = 0; i <= n; i++) {           if (good[i]) {               cnt++;               if (i == n || !good[i + 1]) {                   if (i == cnt) {                       if (!(cnt & 1)) {                           return {};                       }                       else {                           for (int j = 2; j <= i; j += 2) {                               a.pb(j);                           }                       }                   }                   else if (i == n) {                       if (!(cnt & 1)) {                           return {};                       }                       else {                           for (int j = i - cnt + 1; j <= i; j += 2) {                               a.pb(j);                           }                       }                   }                   else {                       if (cnt & 1) {                           return {};                       }                       else {                           for (int j = i - cnt + 1; j <= i; j += 2) {                               a.pb(j);                           }                       }                   }                   cnt = 0;               }           }       }       return get(a);   }      vector<int> solve3(int n) {       vector<int> kek;       for (int i = 1; i <= n; i++) {           if (!good[i]) {               ban[i] = 1;               kek.pb(i);           }       }       for (int j = 1; j <= kek.back(); j++) {           ban[j] = 1;       }       for (int j = 1; j <= n + 2 - kek.front() - 1; j++) {           ban[j] = 1;       }       ban[n - kek.front() + 3] = 1;       for (int i = 1; i <= n - 1; i++) {           if (!good[i] && good[i + 1]) {               ban[i + 2] = 1;           }       }       for (int i = 0; i + 1 < kek.size(); i++) {           ban[n + kek[i] - kek[i + 1] + 4] = 1;       }       for (int s = n - 1; s >= 2; s--) {           if (!ban[s]) {               vector<int> a = {0};               for (int i = 1, cnt = 0; i <= n; i++) {                   if (good[i]) {                       cnt++;                       if (i == n) {                           int l = i - cnt + 1;                           int r = s;                           if (l <= r) {                               for (int j = l; j <= r; j += 2) {                                   a.pb(j);                               }                               a.back() = r;                           }                           cnt = 0;                       }                       else if (!good[i + 1]) {                           int l = i - cnt + 1;                           int r = i + 1 - (n + 2 - s);                           if (i == cnt) {                               l = 2;                           }                           if (l <= r) {                               for (int j = l; j <= r; j += 2) {                                   a.pb(j);                               }                               a.back() = r;                           }                           cnt = 0;                       }                   }               }               return get(a);           }       }       return {};   }      vector<int> solve(int n) {       if (n == 1) {           if (good[1]) {               return {};           }           else {               return {1};           }       }       if (solve0(n)) {           return {};       }       vector<int> ans = solve1(n);       if (!ans.empty()) return ans;       ans = solve2(n);       if (!ans.empty()) return ans;       ans = solve3(n);       if (!ans.empty()) return ans;       return {-1};   }      int main() {       ios_base::sync_with_stdio(0); cin.tie(0);   #ifdef LOCAL       freopen( input.txt ,  r , stdin);   #endif          string s;       cin >> s;       int n = s.size();       for (int i = 1; i <= n; i++) {           good[i] = (s[i - 1] ==  _ );       }       vector<int> ans = solve(n);       if (!ans.empty() && ans.front() == -1) {           cout <<  -1 n ;       }       else {           cout << ans.size() <<   n ;           for (int i : ans) {               cout << i <<    ;           }           cout <<   n ;       }      #ifdef LOCAL       cerr <<   nTime elapsed:   << 1.0 * clock() / CLOCKS_PER_SEC <<   s. n ;   #endif       return 0;   }


#include <bits/stdc++.h>   using namespace std;   int dirx[8] = {0, 0, 1, -1, 1, 1, -1, -1};   int diry[8] = {1, -1, 0, 0, 1, -1, 1, -1};   string tostring(long long n) {     if (!n) return  0 ;     string ans =   ;     while (n != 0) {       ans += (n % 10) +  0 ;       n /= 10;     }     reverse(ans.begin(), ans.end());     return ans;   }   double toDouble(string s) {     double ans = 0;     int i = 0, flag = 0, cnt = 0, ff = 1;     while (i < s.length()) {       if (s[i] ==  - ) {         ff = -1;         i++;         continue;       }       if (s[i] ==  . ) {         flag = 1;         i++;         continue;       }       ans *= 10;       ans += s[i] -  0 ;       if (flag) cnt++;       i++;     }     ans *= ff;     return ans / pow(10, cnt);   }   int ar[1005];   int main() {     int n, a, b;     scanf( %d , &n);     for (int i = 1; i < n; i++) {       scanf( %d %d , &a, &b);       ar[a]++;       ar[b]++;     }     int ans = 0;     for (int i = 1; i <= n; i++) {       ans += (ar[i] == 1);     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string str;     cin >> str;     cout <<  Mike n ;     int freq[26] = {0};     freq[str[0] -  a ]++;     for (int i = 1; i < str.length(); i++) {       int val = 0;       for (int j = 0; j < str[i] -  a ; j++) {         if (freq[j] > 0) {           val = 1;           break;         }       }       freq[str[i] -  a ]++;       if (val == 1) {         cout <<  Ann n ;       } else {         cout <<  Mike n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[105][105];   int main() {     vector<int> v;     int n;     cin >> n;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) cin >> a[i][j];       v.push_back(i);     }     int cnt = 0;     for (int i = 1; i <= n; i++) {       int flag = 0;       for (int j = 1; j <= n; j++) {         if (a[i][j] == 1 || a[i][j] == 3 || a[j][i] == 2 || a[j][i] == 3) {           flag = 1;           v[i - 1] = 0;         }       }       if (flag == 0) cnt++;     }     cout << cnt << endl;     for (auto i = v.begin(); i != v.end(); i++) {       if (*i != 0) cout << *i <<    ;     }     v.clear();   }


#include <bits/stdc++.h>   using namespace std;   inline int read() {     int x = 0, f = 1;     char ch = getchar();     for (; !isdigit(ch); ch = getchar())       if (ch ==  - ) f = -1;     for (; isdigit(ch); ch = getchar()) x = x * 10 + ch -  0 ;     return x * f;   }   const int N = 500005, INF = 1e9;   const double DINF = 1e18;   struct Edge {     int fr, to, nxt, cap;     double cost;   } e[N << 1];   int head[N], pre[N], q[N], En = 1, S, T, n;   double dis[N];   bool vis[N];   inline void add_edge(int u, int v, int f, double w) {     ++En;     e[En].fr = u, e[En].to = v, e[En].nxt = head[u], e[En].cap = f,     e[En].cost = w;     head[u] = En;     ++En;     e[En].fr = v, e[En].to = u, e[En].nxt = head[v], e[En].cap = 0,     e[En].cost = -w;     head[v] = En;   }   bool spfa() {     for (int i = 0; i <= T; ++i) dis[i] = DINF, vis[i] = false, pre[i] = 0;     int L = 1, R = 0;     dis[S] = 0, q[++R] = S, vis[S] = true, pre[S] = 0;     while (L <= R) {       int u = q[L++];       vis[u] = false;       for (int i = head[u]; i; i = e[i].nxt) {         int v = e[i].to;         if (dis[v] > dis[u] + e[i].cost && e[i].cap > 0) {           dis[v] = dis[u] + e[i].cost;           pre[v] = i;           if (!vis[v]) q[++R] = v;         }       }     }     return dis[T] != DINF;   }   void mcf() {     int Flow = 0;     double Cost = 0;     while (spfa()) {       int now = INF;       for (int i = T; i != S; i = e[pre[i]].fr) now = min(now, e[pre[i]].cap);       for (int i = T; i != S; i = e[pre[i]].fr)         e[pre[i]].cap -= now, e[pre[i] ^ 1].cap += now;       Flow += now;       Cost += 1.0 * now * dis[T];     }     if (Flow >= n - 1)       printf( %.10lf , Cost);     else       puts( -1 );   }   struct Node {     int x, y;   } A[N];   int sqr(int x) { return x * x; }   double dist(const Node &A, const Node &B) {     return sqrt(1.0 * (sqr(A.x - B.x) + sqr(A.y - B.y)));   }   int main() {     n = read();     for (int i = 1; i <= n; ++i) A[i].x = read(), A[i].y = read();     S = 0, T = n + n + 1;     for (int i = 1; i <= n; ++i) add_edge(S, i, 2, 0), add_edge(i + n, T, 1, 0);     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= n; ++j)         if (A[j].y > A[i].y) add_edge(j, i + n, 1, dist(A[i], A[j]));     mcf();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   char s1[51], s2[51], op[50][5];   int memo1[50][50][26], memo2[50][50][26], memo3[50][50];   int check1(int l, int r, char c) {     if (l == r) return s1[l] == c;     int &ret = memo1[l][r][c -  a ];     if (ret == -1) {       ret = 0;       for (int i = l; i < r; ++i)         for (int j = 0; j < n; ++j)           if (op[j][0] == c && check1(l, i, op[j][3]) &&               check1(i + 1, r, op[j][4]))             ret = 1;     }     return ret;   }   int check2(int l, int r, char c) {     if (l == r) return s2[l] == c;     int &ret = memo2[l][r][c -  a ];     if (ret == -1) {       ret = 0;       for (int i = l; i < r; ++i)         for (int j = 0; j < n; ++j)           if (op[j][0] == c && check2(l, i, op[j][3]) &&               check2(i + 1, r, op[j][4]))             ret = 1;     }     return ret;   }   int solve(int pos1, int pos2) {     if (pos1 == -1 && pos2 == -1) return 0;     if (pos1 == -1 || pos2 == -1) return 51;     int &ret = memo3[pos1][pos2];     if (ret == -1) {       ret = 51;       for (int i = 0; i <= pos1; ++i)         for (int j = 0; j <= pos2; ++j)           for (char c =  a ; c <=  z ; ++c)             if (check1(i, pos1, c) && check2(j, pos2, c))               ret = min(ret, 1 + solve(i - 1, j - 1));     }     return ret;   }   int main() {     scanf( %s %s , s1, s2);     int L1 = strlen(s1), L2 = strlen(s2);     scanf( %d , &n);     for (int i = 0; i < n; ++i) scanf( %s , op[i]);     memset(memo1, -1, sizeof memo1);     memset(memo2, -1, sizeof memo2);     memset(memo3, -1, sizeof memo3);     int ans = solve(L1 - 1, L2 - 1);     printf( %d n , ans == 51 ? -1 : ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct Node {     int a, b, c, d;   } temp;   queue<Node> q1, q2;   string s1[305][305], s2[305][305];   int main() {     int n, m;     int ans = 0, m1 = 0, m2 = 0;     int num1 = 0, num0 = 0;     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) {         cin >> s1[i][j];         ans += 2 * s1[i][j].length();         if (i == 1 && j == m) ans -= s1[i][j].length();         if (i == n && j == 1) ans -= s1[i][j].length();       }     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) {         cin >> s2[i][j];         ans += 2 * s2[i][j].length();         if (i == 1 && j == m) ans -= s2[i][j].length();         if (i == n && j == 1) ans -= s2[i][j].length();       }     printf( %d n , ans);     for (int i = 1; i < m; i++) {       temp.a = 1;       temp.b = m;       for (int k = s1[1][i].size() - 1; k >= 0; k--) {         printf( %d %d %d %d n , 1, i, 1, m);         if (s1[1][i][k] ==  0 ) {           temp.c = 1;           temp.d = 1;         } else {           temp.c = n;           temp.d = m;         }         q1.push(temp);       }     }     for (int i = 2; i <= m; i++) {       temp.a = n;       temp.b = 1;       for (int k = s1[n][i].size() - 1; k >= 0; k--) {         printf( %d %d %d %d n , n, i, n, 1);         if (s1[n][i][k] ==  0 ) {           temp.c = 1;           temp.d = 1;         } else {           temp.c = n;           temp.d = m;         }         q2.push(temp);       }     }     for (int i = s1[1][m].size() - 1; i >= 0; i--) {       if (s1[1][m][i] ==  0 )         printf( %d %d %d %d n , 1, m, 1, 1);       else         printf( %d %d %d %d n , 1, m, n, m);     }     while (!q1.empty()) {       temp = q1.front();       q1.pop();       printf( %d %d %d %d n , temp.a, temp.b, temp.c, temp.d);     }     for (int i = s1[n][1].size() - 1; i >= 0; i--) {       if (s1[n][1][i] ==  0 )         printf( %d %d %d %d n , n, 1, 1, 1);       else         printf( %d %d %d %d n , n, 1, n, m);     }     while (!q2.empty()) {       temp = q2.front();       q2.pop();       printf( %d %d %d %d n , temp.a, temp.b, temp.c, temp.d);     }     for (int i = 2; i < n; i++)       for (int j = 1; j <= m; j++)         for (int k = s1[i][j].size() - 1; k >= 0; k--) {           if (s1[i][j][k] ==  0 ) {             if (j != 1)               printf( %d %d %d %d n%d %d %d %d n , i, j, 1, j, 1, j, 1, 1);             else               printf( %d %d %d %d n%d %d %d %d n , i, j, n, j, n, j, 1, 1);           } else {             if (j != m)               printf( %d %d %d %d n%d %d %d %d n , i, j, n, j, n, j, n, m);             else               printf( %d %d %d %d n%d %d %d %d n , i, j, 1, j, 1, j, n, m);           }         }     for (int i = 2; i < n; i++)       for (int j = 1; j <= m; j++) {         for (int k = s2[i][j].length() - 1; k >= 0; k--) {           if (s2[i][j][k] ==  0 ) {             if (j == 1)               printf( %d %d %d %d n%d %d %d %d n , 1, 1, n, j, n, j, i, j);             else               printf( %d %d %d %d n%d %d %d %d n , 1, 1, 1, j, 1, j, i, j);           } else {             if (j == m)               printf( %d %d %d %d n%d %d %d %d n , n, m, 1, j, 1, j, i, j);             else               printf( %d %d %d %d n%d %d %d %d n , n, m, n, j, n, j, i, j);           }         }       }     for (int i = 1; i < m; i++) {       temp.a = 1;       temp.b = m;       temp.c = 1;       temp.d = i;       for (int j = s2[1][i].length() - 1; j >= 0; j--) {         if (s2[1][i][j] ==  0 )           printf( %d %d %d %d n , 1, 1, 1, m);         else           printf( %d %d %d %d n , n, m, 1, m);         q1.push(temp);       }     }     for (int i = s2[1][m].length() - 1; i >= 0; i--) {       if (s2[1][m][i] ==  0 )         printf( %d %d %d %d n , 1, 1, 1, m);       else         printf( %d %d %d %d n , n, m, 1, m);     }     for (int i = 2; i <= m; i++) {       temp.a = n;       temp.b = 1;       temp.c = n;       temp.d = i;       for (int j = s2[n][i].length() - 1; j >= 0; j--) {         if (s2[n][i][j] ==  0 )           printf( %d %d %d %d n , 1, 1, n, 1);         else           printf( %d %d %d %d n , n, m, n, 1);         q2.push(temp);       }     }     for (int i = s2[n][1].length() - 1; i >= 0; i--) {       if (s2[n][1][i] ==  0 )         printf( %d %d %d %d n , 1, 1, n, 1);       else         printf( %d %d %d %d n , n, m, n, 1);     }     while (!q1.empty()) {       temp = q1.front();       q1.pop();       printf( %d %d %d %d n , temp.a, temp.b, temp.c, temp.d);     }     while (!q2.empty()) {       temp = q2.front();       q2.pop();       printf( %d %d %d %d n , temp.a, temp.b, temp.c, temp.d);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long is_query = -(1LL << 62);   struct Line {     long long m, b;     mutable function<const Line*()> succ;     bool operator<(const Line& rhs) const {       if (rhs.b != is_query) return m < rhs.m;       const Line* s = succ();       if (!s) return 0;       long long x = rhs.m;       return b - s->b < (s->m - m) * x;     }   };   struct HullDynamic : public multiset<Line> {     bool bad(iterator y) {       auto z = next(y);       if (y == begin()) {         if (z == end()) return 0;         return y->m == z->m && y->b <= z->b;       }       auto x = prev(y);       if (z == end()) return y->m == x->m && y->b <= x->b;       return (x->b - y->b) * (z->m - y->m) >= (y->b - z->b) * (y->m - x->m);     }     void insert_line(long long m, long long b) {       auto y = insert({m, b});       y->succ = [=] { return next(y) == end() ? 0 : &*next(y); };       if (bad(y)) {         erase(y);         return;       }       while (next(y) != end() && bad(next(y))) erase(next(y));       while (y != begin() && bad(prev(y))) erase(prev(y));     }     long long eval(long long x) {       auto l = *lower_bound((Line){x, is_query});       return l.m * x + l.b;     }   } convex;   const int N = 2e5 + 5;   long long dp[N], arr[N];   int n;   int main() {     long long sum = 0, ans;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %lld , &arr[i]);       dp[i] = dp[i - 1] + arr[i];       sum += arr[i] * i;     }     ans = sum;     convex.insert_line(n, -dp[n]);     for (int i = n - 1; i >= 1; i--) {       long long best = 0;       long long e = dp[i] - i * arr[i] + sum;       ans = max(ans, convex.eval(arr[i]) + e);       convex.insert_line(i, -dp[i]);     }     convex.clear();     convex.insert_line(1, 0);     for (int i = 2; i <= n; i++) {       long long e = sum + dp[i - 1] - i * arr[i];       ans = max(ans, convex.eval(arr[i]) + e);       convex.insert_line(i, -dp[i - 1]);     }     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct mat {     double a[3][3];     mat() {       for (int i = (int)(0); i <= (int)(2); ++i)         for (int j = (int)(0); j <= (int)(2); ++j) a[i][j] = 0;     }     mat operator*(const mat &b) const {       mat c;       for (int i = (int)(0); i <= (int)(2); ++i)         for (int j = (int)(0); j <= (int)(2); ++j)           for (int k = (int)(0); k <= (int)(2); ++k)             c.a[i][j] += a[i][k] * b.a[k][j];       return c;     }   };   struct node {     int id;     long long las;     mat pre;   };   vector<node> S;   mat bas[100005], f[40], org;   pair<double, double> p[100005];   int n;   long long m;   double b;   int main() {     scanf( %d%lld , &n, &m);     for (int i = (int)(1); i <= (int)(n); ++i) {       double x, y, v;       scanf( %lf%lf%lf , &x, &y, &v);       b = max(b, y * v);       p[i] = pair<double, double>(x * v, v);     }     sort(p + 1, p + n + 1, greater<pair<double, double> >());     org.a[2][0] = 1;     for (int i = (int)(1); i <= (int)(n); ++i) {       bas[i].a[1][1] = 1;       bas[i].a[2][2] = 1;       bas[i].a[0][0] = 1 - p[i].second;       bas[i].a[0][1] = p[i].second;       bas[i].a[0][2] = p[i].first;       bas[i].a[1][2] = b;     }     S.push_back((node){1, m, org});     for (int i = (int)(2); i <= (int)(n); ++i) {       for (;;)         if ((bas[i] * S.back().pre).a[0][0] >             (bas[S.back().id] * S.back().pre).a[0][0])           S.pop_back();         else           break;       if (!S.back().las) continue;       node tmp = S.back();       f[0] = bas[tmp.id];       for (int j = (int)(1); j <= (int)(35); ++j) f[j] = f[j - 1] * f[j - 1];       for (int j = (int)(35); j >= (int)(0); --j)         if (tmp.las - (1ll << j) >= 1)           if ((bas[i] * f[j] * tmp.pre).a[0][0] <=               (bas[tmp.id] * f[j] * tmp.pre).a[0][0]) {             tmp.pre = f[j] * tmp.pre;             tmp.las -= (1ll << j);           }       tmp.pre = f[0] * tmp.pre;       --tmp.las;       if (tmp.las) tmp.id = i;       S.push_back(tmp);     }     int id = S.back().id;     long long las = S.back().las;     mat ans = S.back().pre, x = bas[id];     for (; las; las /= 2, x = x * x)       if (las & 1) ans = x * ans;     printf( %.15lf n , ans.a[0][0]);   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 110, MOD = 1e9 + 7;   long long dp[MAXN][2];   int main() {     ios_base::sync_with_stdio(NULL);     cin.tie(nullptr);     cout.tie(nullptr);     int n, k, d;     cin >> n >> k >> d;     dp[0][0] = 1;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= min(k, i); j++) {         if (j >= d) {           dp[i][1] += (dp[i - j][0] + dp[i - j][1]);           dp[i][1] %= MOD;         } else {           dp[i][0] += dp[i - j][0];           dp[i][1] += dp[i - j][1];           dp[i][1] %= MOD;           dp[i][0] %= MOD;         }       }     }     cout << dp[n][1] <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   long long me[10000][1001];   long long n, m;   long long d[10000];   long long g, r;   int main() {     cin.tie(0);     ios_base::sync_with_stdio(0);     cin >> n >> m;     for (long long i = 0; i < m; i++) cin >> d[i];     sort(d, d + m);     cin >> g >> r;     queue<pair<long long, long long> > mq[2];     mq[1].push(pair<long long, long long>(0, g));     me[0][g] = 1;     int ini = 1;     while (!mq[0].empty() || !mq[1].empty()) {       while (!mq[ini % 2].empty()) {         pair<long long, long long> t = mq[ini % 2].front();         mq[ini % 2].pop();         long long i = t.first;         long long j = t.second;         long long np = me[i][j];         if (np == ini) {           if (j == 0) np++, j = g;           if (i && d[i] - d[i - 1] <= j &&               (me[i - 1][j - (d[i] - d[i - 1])] == 0 ||                me[i - 1][j - (d[i] - d[i - 1])] > np)) {             me[i - 1][j - (d[i] - d[i - 1])] = np;             mq[np % 2].push(                 pair<long long, long long>(i - 1, j - (d[i] - d[i - 1])));           }           if (i < m - 1 && d[i + 1] - d[i] <= j &&               (me[i + 1][j - (d[i + 1] - d[i])] == 0 ||                me[i + 1][j - (d[i + 1] - d[i])] > np)) {             me[i + 1][j - (d[i + 1] - d[i])] = np;             mq[np % 2].push(                 pair<long long, long long>(i + 1, j - (d[i + 1] - d[i])));           }         }       }       ini++;     }     long long res = -1;     for (int i = 0; i <= g; i++) {       if (me[m - 1][i]) {         long long can = (me[m - 1][i] - 1) * (g + r) + g - i;         if (res == -1 || can < res) res = can;       }     }     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e3 + 1;   int accept() {     int b[N] = {0};     int d[N] = {0};     int n;     cin >> n;     int mx, check;     for (int i = 0; i < n; i++) cin >> b[i];     sort(b, b + n);     for (int i = 1; i < n; i++) {       if (b[i] == b[i - 1]) {         cout <<  YES               <<   n ;         return 0;       }     }     cout <<  NO           <<   n ;     return 0;   }   int main() {     int t = 1;     cin >> t;     while (t--) {       accept();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mx = 100010;   int arr[mx];   int main() {     string x;     int n, c = -1, temp = 0;     queue<int> stek;     map<int, int> visit;     cin >> n >> x;     for (int i = 0; i < n - 1; i++) {       if ((x[i] ==  o  and x[i + 1] ==  g ) ||           (x[i] ==  g  and x[i + 1] ==  o )) {         temp++;         if (c == -1 and x[i] ==  g ) {           temp = 0;           continue;         }         if (c == -1) c = i;       } else if (c != -1) {         if (x[i] ==  g  and temp == 1) {           temp = 0;           c = -1;           continue;         } else if (x[i] ==  g  and temp > 1) {           temp--;         }         stek.push(c);         visit[c] = temp;         temp = 0;         c = -1;       }     }     if (c != -1) {       if (x[n - 1] ==  g  and temp == 1) {       } else {         if (x[n - 1] ==  g  and temp > 1) {           temp--;         }         stek.push(c);         visit[c] = temp;         temp = 0;         c = -1;       }     }     for (int i = 0; i < n; i++) {       if (stek.front() == i) {         printf( *** );         i += visit[stek.front()];         stek.pop();       } else {         printf( %c , x[i]);       }     }     printf(  n );   }


#include <bits/stdc++.h>   const long long mod = 1e9 + 7;   using namespace std;   long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }   long long n, m;   vector<long long> a, b, v, pat;   long long cal() {     v.clear();     for (long long i = 1; i < m; i++) v.push_back(a[i]);     v.push_back(1e18);     for (long long j = 1; j < n; j++) v.push_back(b[j]);     long long sz = v.size();     long long ans = 0;     pat.clear();     pat.resize(sz, 0);     for (long long i = 1; i < sz; i++) {       long long j = pat[i - 1];       while (j > 0 && v[j] != v[i]) j = pat[j - 1];       if (v[j] == v[i]) j++;       pat[i] = j;       if (j == m - 1) ans++;     }     return ans;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cin >> n >> m;     long long pre, cur;     b.clear();     b.resize(n);     for (long long i = 0; i < n; i++) {       cin >> b[i];       cur = b[i];       if (i) b[i] -= pre;       pre = cur;     }     a.clear();     a.resize(m);     for (long long i = 0; i < m; i++) {       cin >> a[i];       cur = a[i];       if (i) a[i] -= pre;       pre = cur;     }     if (m == 1) {       cout << n <<   n ;       return 0;     }     cout << cal() <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int num, skill;     cin >> num >> skill;     int A[num];     for (int i = 0; i < num; i++) cin >> A[i];     int k = 0;     while (A[k] <= skill && k < num) k++;     int soluve;     soluve = k;     int stay;     if (k == num) {       cout << num << endl;       return 0;     } else {       int z = num - 1;       while (A[z] <= skill && z >= 1) z--;       stay = num - z - 1;       soluve += stay;     }     cout << soluve << endl;   }


#include <bits/stdc++.h>   #pragma GCC optimize( inline )   int rd() {     register int k = 0;     char c = getchar();     while (c >  9  || c <  0 ) c = getchar();     while (c >=  0  && c <=  9 ) k = k * 10 + c - 48, c = getchar();     return k;   }   const int N = 100001;   struct Q {     int o, t, l, r;   } q[N];   struct C {     int x, v;   } c[N];   int n, m, p, l = 1, r, qn, cn, a[N], bl[N], ans[N], T, b[N << 1], B, v[N << 1],                sv[N], s;   bool cmp(register const Q& x, register const Q& y) {     return bl[x.l] != bl[y.l] ? x.l < y.l                               : (bl[x.r] == bl[y.r] ? x.t < y.t : x.r < y.r);   }   void Ins(register int p) { --sv[v[p]], ++sv[++v[p]]; }   void Del(register int p) { --sv[v[p]], ++sv[--v[p]]; }   void Set(register int t, register int i) {     if (q[i].l <= c[t].x && c[t].x <= q[i].r) Del(a[c[t].x]), Ins(c[t].v);     std::swap(a[c[t].x], c[t].v);   }   int main() {     B = n = rd(), m = rd(), p = pow(n, 0.66);     for (register int i = 1; i <= n; ++i) b[i] = a[i] = rd(), bl[i] = i / p;     for (register int i = 1; i <= m; ++i) {       if (rd() == 1)         ++qn, q[qn] = {qn, cn, rd(), rd()};       else         c[++cn] = {rd(), b[++B] = rd()};     }     std::sort(b + 1, b + B + 1), B = std::unique(b + 1, b + B + 1) - b - 1,                                  std::sort(q + 1, q + qn + 1, cmp);     for (register int i = 1; i <= n; ++i)       a[i] = std::lower_bound(b + 1, b + B + 1, a[i]) - b;     for (register int i = 1; i <= cn; ++i)       c[i].v = std::lower_bound(b + 1, b + B + 1, c[i].v) - b;     for (register int i = 1; i <= qn; ++i) {       while (l > q[i].l) Ins(a[--l]);       while (r < q[i].r) Ins(a[++r]);       while (l < q[i].l) Del(a[l++]);       while (r > q[i].r) Del(a[r--]);       while (T < q[i].t) Set(++T, i);       while (T > q[i].t) Set(T--, i);       for (s = 1; sv[s] > 0; ++s)         ;       ans[q[i].o] = s;     }     for (register int i = 1; i <= qn; ++i) printf( %d n , ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   #pragma optimize( -Ofast )   const int mod = 998244353;   struct num {     int x;     num(int x_ = 0) { x = x_; }   } G, _1[2222222], X[2222222], rot[2222222], inv[2222222];   inline bool operator<(const num x, const num y) { return x.x > y.x; }   inline num operator+(const num x, const num y) {     int z = x.x + y.x;     return z < mod ? num(z) : num(z - mod);   }   inline num operator-(const num x, const num y) {     int z = x.x - y.x;     return z >= 0 ? num(z) : num(z + mod);   }   inline num operator*(const num x, const num y) {     return num((long long)x.x * y.x % mod);   }   inline num operator*(const int x, const num y) {     return num((long long)x * y.x % mod);   }   inline num operator^(num x, int y) {     num z = num(1);     while (y) {       if (y & 1) {         z = z * x;       }       x = x * x;       y >>= 1;     }     return z;   }   void _(int n) {     inv[1] = num(1);     for (int i = 2; i <= n; i++) {       inv[i] = (mod - mod / i) * inv[mod % i];     }     for (int i = 2; i <= n; i <<= 1) {       rot[i] = G ^ ((mod - 1) / i);     }   }   void rader(num x[], int n) {     int i, j = 0, k;     for (register int i = 0; i != n; i++) {       if (i > j) {         swap(x[i], x[j]);       }       k = n >> 1;       while ((j ^= k) < k) {         k >>= 1;       }     }   }   void NTT(num x[], int n, int o) {     int k;     num r, u, v, w;     rader(x, n);     for (int l = 2; l <= n; l <<= 1) {       k = l >> 1;       r = rot[l];       for (int i = 0; i < n; i += l) {         w = num(1);         for (register int j = i; j < i + k; j++) {           u = x[j];           v = x[j + k] * w;           x[j] = u + v;           x[j + k] = u - v;           w = w * r;         }       }     }     if (o == -1) {       for (register int i = 0; i < n; i++) {         x[i] = x[i] * inv[n];       }       for (register int i = 1; i < (n >> 1); i++) {         swap(x[i], x[n - i]);       }     }   }   int main() {     int n, k, z[11], oo[11] = {0};     G = num(3);     scanf( %d%d , &n, &k);     n /= 2;     for (int i = 1; i <= k; i++) {       scanf( %d , &z[i]);       oo[z[i]] = 1;     }     for (int i = 0; i <= 9; i++) {       if (oo[i]) {         _1[i] = num(1);       }     }     int xxx = n;     n *= 10;     int S = 1;     while (S <= n) {       S <<= 1;     }     S <<= 1;     _(S);     X[0] = num(1);     NTT(_1, S, 1);     NTT(X, S, 1);     while (xxx) {       if (xxx & 1) {         for (register int i = 0; i < S; i++) {           X[i] = X[i] * _1[i];         }       }       for (register int i = 0; i < S; i++) {         _1[i] = _1[i] * _1[i];       }       xxx >>= 1;     }     NTT(X, S, -1);     num ans = num(0);     for (int i = 0; i <= S; i++) {       ans = ans + (X[i] * X[i]);     }     printf( %d , ans.x);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 100010;   vector<int> a[MAX], ans;   int x, y, n;   bool v[MAX], d[MAX], f[MAX], l[MAX], odd[MAX], even[MAX];   void DFS(int start) {     v[start] = true;     if (d[start] && odd[start]) {       f[start] = (1 - f[start]);     }     if (!d[start] && even[start]) {       f[start] = (1 - f[start]);     }     if (f[start] != l[start]) {       ans.push_back(start);       if (d[start]) {         odd[start] = (1 - odd[start]);       } else {         even[start] = (1 - even[start]);       }     }     int current;     for (int i = 0; i < a[start].size(); i++) {       current = a[start][i];       if (!v[current]) {         d[current] = (1 - d[start]);         odd[current] = odd[start];         even[current] = even[start];         DFS(current);       }     }   }   int main() {     cin >> n;     for (int i = 1; i < n; i++) {       cin >> x >> y;       a[x].push_back(y);       a[y].push_back(x);     }     for (int i = 1; i <= n; i++) {       cin >> f[i];     }     for (int i = 1; i <= n; i++) {       cin >> l[i];     }     DFS(1);     cout << ans.size() <<   n ;     for (int i = 0; i < ans.size(); i++) {       cout << ans[i] <<   n ;     }     cout <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[3];   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> a[0] >> a[1] >> a[2];     sort(a, a + 3);     if (a[0] + a[1] > a[2]) {       cout << 0 << endl;       return 0;     }     cout << a[2] - a[1] - a[0] + 1;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   set<int> d;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long t, n, a, k = 0;     cin >> t >> n;     int x[200] = {};     for (int i = 1; i <= t; ++i) {       cin >> a;       if (x[a] >= 1)         continue;       else {         x[a] += 1;         d.insert(i);       }     }     if (d.size() < n)       cout <<  NO n ;     else {       cout <<  YES n ;       for (auto i : d) {         k += 1;         cout << i <<    ;         if (k == n) break;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline double sq(double a) { return a * a; }   int a, b;   int n;   complex<double> p1[1024], p2[1024];   double d[1024][1024];   int vis[1024];   double distanceSP(const complex<double>& s0, const complex<double>& s1,                     const complex<double>& p) {     if (s0.real() <= p.real() && p.real() <= s1.real()) {       return sq(p.imag() - s0.imag());     }     if (s0.imag() <= p.imag() && p.imag() <= s1.imag()) {       return sq(p.real() - s0.real());     }     return min(norm(s0 - p), norm(s1 - p));   }   double distanceSS(const complex<double>& s0, const complex<double>& s1,                     const complex<double>& t0, const complex<double>& t1) {     return min(min(distanceSP(s0, s1, t0), distanceSP(s0, s1, t1)),                min(distanceSP(t0, t1, s0), distanceSP(t0, t1, s1)));   }   double solve() {     for (int i = 0; i < (int)(n); i++)       for (int j = 0; j < (int)(i); j++) {         d[i][j] = d[j][i] = distanceSS(p1[i], p2[i], p1[j], p2[j]);       }     queue<pair<double, int> > q;     q.push(make_pair(0.0, 0));     vis[0] = 1;     double ans = -1;     while (!q.empty()) {       const pair<double, int> vv(q.front());       q.pop();       const double t = -vv.first;       const int at = vv.second;       if (ans >= 0 && t >= ans) break;       for (int i = 0; i < (int)(n); i++)         if (vis[i] == 0 && d[at][i] <= a * a) {           if (i == 1) {             const double nt = t + sqrt(d[at][i]);             if (ans == -1 || ans > nt) ans = nt;           } else {             vis[i] = 1;             q.push(make_pair(-t - a - b, i));           }         }     }     return ans;   }   int main() {     scanf( %d%d , &a, &b);     for (int i = 0; i < (int)(2); i++) {       int x, y;       scanf( %d%d , &x, &y);       p1[i] = p2[i] = complex<double>(x, y);     }     scanf( %d , &n);     for (int i = 0; i < (int)(n); i++) {       int x1, y1, x2, y2;       scanf( %d%d%d%d , &x1, &y1, &x2, &y2);       if (x1 > x2) swap(x1, x2);       if (y1 > y2) swap(y1, y2);       p1[i + 2] = complex<double>(x1, y1);       p2[i + 2] = complex<double>(x2, y2);     }     n += 2;     const double ans = solve();     if (ans < 0)       printf( %d n , -1);     else       printf( %.9f n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using pi = pair<int, int>;   using pll = pair<ll, ll>;   int n, k;   vector<int> x;   bool disjoint(int l1, int r1, int l2, int r2) { return r1 < l2 || r2 < l1; }   int main() {     ios_base::sync_with_stdio(false);     cout << setprecision(12);     cin.tie(nullptr);     cin >> n >> k;     x.resize(k);     for (int i = 0; i < int(k); i++) cin >> x[i], x[i]--;     vector<int> fst(n, -1), lst(n, k);     for (int i = 0; i < int(k); i++) lst[x[i]] = i;     for (int i = k - 1; i >= 0; i--) fst[x[i]] = i;     ll ans = 0;     for (int i = 0; i < int(n); i++)       if (fst[i] == -1) ans++;     for (int i = 0; i < int(n - 1); i++) {       if (fst[i] == -1 || fst[i + 1] == -1) {         ans += 2;         continue;       }       if (lst[i] < fst[i + 1]) ans++;       if (lst[i + 1] < fst[i]) ans++;     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int mx = 110, Mod = 1e6 + 3;   int C, W, H;   struct Matrix {     int val[mx][mx];     int n;     Matrix(int _n = mx, int _base = 0) {       n = _n;       for (int i = 0; i < n; i++)         for (int j = 0; j < n; j++) val[i][j] = (i == j ? _base : 0);     }     int* operator[](int x) { return val[x]; }   };   Matrix operator*(Matrix A, Matrix B) {     Matrix res(A.n);     for (int i = 0; i < res.n; i++)       for (int j = 0; j < res.n; j++)         for (int k = 0; k < res.n; k++)           res[i][k] = (0LL + res[i][k] + 1LL * A[i][j] * B[j][k]) % Mod;     return res;   }   Matrix operator^(Matrix A, long long int B) {     Matrix res(A.n, 1);     while (B) {       if (B & 1) res = res * A;       A = A * A;       B >>= 1;     }     return res;   }   int main() {     scanf( %d%d%d , &C, &W, &H);     Matrix res(W + 1);     for (int i = 0; i <= W; i++) res[0][i] = 1, res[i + 1][i] = H;     res = res ^ C;     int ans = 0;     for (int i = 0; i <= W; i++) ans = (0LL + ans + res[i][0]) % Mod;     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e3 + 123;   const int K = (int)500;   const int maxn = (int)2e9;   const int mod = (int)1e9 + 7;   long long n;   vector<long long> v;   void solve() {     cin >> n;     long long cnt = 1;     for (int i = 0; i <= 62; ++i) {       if (i) {         cnt *= 2ll;       }       long long cnt2 = cnt - 1;       long long ok = 0;       long long l = 1, r = 1ll * 1e18;       while (l <= r) {         long long m = l + (r - l) / 2;         if (n % m) {           if ((m - 1) / 2 + cnt2 < n / m)             l = m + 1;           else             r = m - 1;           continue;         }         if ((m - 1) / 2 + cnt2 == n / m) {           if (m % 2) {             ok = m + m * cnt2;           }           break;         }         if ((m - 1) / 2 + cnt2 < n / m) {           l = m + 1;         } else {           r = m - 1;         }       }       if (ok) {         v.push_back(ok);       }     }     if (!(int)v.size()) {       cout << -1;       return;     }     sort(v.begin(), v.end());     v.resize(unique(v.begin(), v.end()) - v.begin());     for (long long i : v) {       cout << i <<   n ;     }   }   int main() {     ios_base ::sync_with_stdio(0), cin.tie(0), cout.tie(0);     int q = 1;     while (q--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   void r1(T &x) {     x = 0;     char c(getchar());     int f(1);     for (; !isdigit(c); c = getchar())       if (c ==  - ) f = -1;     for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);     x *= f;   }   const int maxn = 100000 + 5;   const int maxm = maxn << 1;   typedef int room[maxn];   int n, m, d;   int dis[maxn], f[maxn][2];   int head[maxn], cnt;   struct Edge {     int to, next;   } edg[maxn << 1];   void add(int u, int v) { edg[++cnt] = (Edge){v, head[u]}, head[u] = cnt; }   int vis[maxn];   void dfs(int p, int fa) {     if (vis[p]) f[p][0] = 0;     for (int i = head[p]; i; i = edg[i].next) {       int to = edg[i].to;       if (to == fa) continue;       dfs(to, p);       if (f[to][0] + 1 > f[p][0]) {         f[p][1] = f[p][0], f[p][0] = f[to][0] + 1;       } else         f[p][1] = max(f[p][1], f[to][0] + 1);     }   }   void dfs1(int p, int fa) {     for (int i = head[p]; i; i = edg[i].next) {       int to = edg[i].to;       if (to == fa) continue;       if (f[p][0] == f[to][0] + 1) {         dis[to] = max(f[p][1] + 1, dis[p] + 1);       } else         dis[to] = max(dis[p] + 1, f[p][0] + 1);       dfs1(to, p);     }   }   signed main() {     int i, j;     memset(f, -0x3f, sizeof(f)), memset(dis, -0x3f, sizeof(dis));     r1(n), r1(m), r1(d);     for (i = 1; i <= m; ++i) {       int x;       r1(x);       vis[x] = 1;     }     for (i = 1; i < n; ++i) {       int u, v;       r1(u), r1(v);       add(u, v), add(v, u);     }     dfs(1, 0), dfs1(1, 0);     int ans((bool)(f[1][1] <= d && f[1][0] <= d));     for (i = 2; i <= n; ++i)       if (dis[i] <= d && f[i][0] <= d) {         ++ans;       }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long inf = 0xFFFFFFFFFFFFFFFL;   clock_t time_p = clock();   void time() {     time_p = clock() - time_p;     cerr <<  Time Taken :   << (float)(time_p) / CLOCKS_PER_SEC <<   n ;   }   long long mul_mod(long long a, long long b, long long m) {     long long y =         (long long)((long double)a * (long double)b / m + (long double)1 / 2);     y = y * m;     long long x = a * b;     long long r = x - y;     if (r < 0) {       r = r + m;       y = y - 1;     }     return r;   }   long long pot(long long a, long long b, long long c) {     if (b == 0) return 1;     if (b == 1) return a % c;     long long resp = pot(a, b >> 1, c);     resp = mul_mod(resp, resp, c);     if (b & 1) resp = mul_mod(resp, a, c);     return resp;   }   bool isPrime(long long n) {     long long d = n - 1;     long long s = 0;     if (n <= 3 || n == 5) return true;     if (!(n & 1)) return false;     while (!(d & 1)) {       s++;       d >>= 1;     }     for (long long i = 0; i < 32; i++) {       long long a = rand();       a <<= 32;       a += rand();       a %= (n - 3);       a += 2;       long long x = pot(a, d, n);       if (x == 1 || x == n - 1) continue;       for (long long j = 1; j <= s - 1; j++) {         x = mul_mod(x, x, n);         if (x == 1) return false;         if (x == n - 1) break;       }       if (x != n - 1) return false;     }     return true;   }   pair<long long, long long> breaker(long long n) {     if (isPrime(n)) return {n, 0};     for (long long i = 2; i < n; i++) {       if (isPrime(i) && isPrime(n - i)) return {i, n - i};     }   }   int main(void) {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long n;     cin >> n;     if (isPrime(n)) {       cout << 1 <<   n  << n <<   n ;       return 0;     }     if (isPrime(n - 2)) {       cout << 2 <<   n ;       cout << 2 <<     << n - 2 <<   n ;       return 0;     }     if (isPrime(n - 3)) {       cout << 2 <<   n ;       cout << 3 <<     << n - 3 <<   n ;       return 0;     }     if (isPrime(n - 4)) {       cout << 3 <<   n ;       cout << 2 <<     << 2 <<     << n - 4 <<   n ;       return 0;     }     long long part1 = 0, part2 = 0, part3 = 0;     for (long long i = n - 5; i >= 0; i--) {       if (isPrime(i)) {         part1 = i;         pair<long long, long long> p = breaker(n - i);         part2 = p.first;         part3 = p.second;         break;       }     }     long long ct = 0;     vector<long long> list;     if (part1 != 0) {       ct++;       list.push_back(part1);     }     if (part2 != 0) {       ct++;       list.push_back(part2);     }     if (part3 != 0) {       ct++;       list.push_back(part3);     }     cout << ct <<   n ;     for (long long i = 0; i < (long long)list.size(); i++) cout << list[i] <<    ;     cout <<   n ;     time();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     char a[1000];     int i = 0, lower = 0, upper = 0;     cin >> a;     int len = strlen(a);     while (a[i] != 0) {       if (a[i] >=  a  && a[i] <=  z ) {         lower++;         i++;       } else if (a[i] >=  A  && a[i] <=  Z ) {         upper++;         i++;       } else         i++;     }     if (upper > lower) {       for (i = 0; i < len; i++) {         if (a[i] >= 97 && a[i] <= 122) {           a[i] = a[i] - 32;         }       }       cout << a;     } else {       for (i = 0; i < len; i++) {         if (a[i] >= 65 && a[i] <= 92) {           a[i] = a[i] + 32;         }       }       cout << a;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n;     cin >> n;     vector<int> a(n);     for (int i = 0; i < n; i++) {       cin >> a[i];     }     vector<int> t(n);     for (int i = 0; i < n; i++) {       cin >> t[i];     }     a.push_back((int)1.01e9);     t.push_back(0);     ++n;     vector<int> order(n);     iota(order.begin(), order.end(), 0);     sort(order.begin(), order.end(), [&](int i, int j) { return a[i] < a[j]; });     unsigned long long ans = 0;     int last = 0;     multiset<int> s;     long long sum = 0;     for (int i : order) {       while (a[i] > last && !s.empty()) {         ++last;         auto it = prev(s.end());         sum -= *it;         s.erase(it);         ans += sum;       }       last = a[i];       s.insert(t[i]);       sum += t[i];     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 1e9 + 10;   const long long INF = 4e18 + 10;   const int maxn = 1 * 1e5 + 5;   const int maxe = maxn;   int a[maxn];   int p[maxn];   int n, m;   bool check(long long t) {     for (int i = 1; i <= n; ++i) p[i] = a[i];     int j = n;     for (int i = 0; i < m; ++i) {       while (j > 0 && p[j] == 0) --j;       if (j == 0) return true;       long long res = t - j;       if (res <= 0) return false;       while (j > 0 && res >= p[j]) res -= p[j--];       if (j > 0) p[j] -= res;     }     if (j == 0) return true;     return false;   }   int MAIN() {     scanf( %d%d , &n, &m);     long long lb = -1, rb = 0;     for (int i = 1; i <= n; ++i) {       scanf( %d , &a[i]);       rb += i + a[i];     }     while (rb - lb > 1) {       long long mid = lb + (rb - lb) / 2;       if (check(mid))         rb = mid;       else         lb = mid;     }     printf( %I64d n , rb);     return 0;   }   int main() {     ios_base::sync_with_stdio(false);     cout << fixed << setprecision(16);     int ret = MAIN();     return ret;   }


#include <bits/stdc++.h>   using namespace std;   char a[200][200];   long long check(long long x, long long y, long long n) {     if (x >= 0 and x < n and y >= 0 and y < n and a[x][y] ==  . )       return 1;     else       return 0;   }   void solve() {     long long n;     cin >> n;     map<long long, long long> m;     for (long long i = 0; i < n; i++) {       long long t;       cin >> t;       m[t]++;     }     auto i = m.rbegin();     long long ans = 0;     long long hold = 0;     for (; i != m.rend(); i++) {       long long k = min(hold, i->second);       ans += k;       hold = hold - k + i->second;     }     cout << ans << endl;     return;   }   int32_t main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long t = 1;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int v[361 * 2], acum[360 * 2];   int main() {     int n, tmp;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> v[i];       v[i + n] = v[i];     }     int ans = (1 << 20);     for (int i = 0; i < n; i++) {       for (int j = i; j < i + n; j++) {         int acum1 = 0, acum2 = 0;         for (int k = i; k < i + n; k++) {           if (k < j)             acum1 += v[k];           else             acum2 += v[k];         }         ans = min(ans, abs(acum1 - acum2));       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<pair<int, pair<int, int> > > g[300043];   int main() {     int n, m, k;     scanf( %d %d %d , &n, &m, &k);     for (int i = 0; i < m; i++) {       int x, y, w;       scanf( %d %d %d , &x, &y, &w);       --x;       --y;       g[x].push_back(make_pair(y, make_pair(w, i)));       g[y].push_back(make_pair(x, make_pair(w, i)));     }     set<pair<long long, int> > q;     vector<long long> d(n, (long long)(1e18));     d[0] = 0;     q.insert(make_pair(0, 0));     vector<int> last(n, -1);     int cnt = 0;     vector<int> ans;     while (!q.empty() && cnt < k) {       set<pair<long long, int> >::iterator it = q.begin();       q.erase(q.begin());       pair<int, int> top = *it;       int k = top.second;       if (last[k] != -1) {         cnt++;         ans.push_back(last[k]);       }       vector<pair<int, pair<int, int> > >::iterator ii;       for (ii = g[k].begin(); ii != g[k].end(); ii++) {         pair<int, pair<int, int> > y = *ii;         int to = y.first;         int w = y.second.first;         int idx = y.second.second;         if (d[to] > d[k] + w) {           q.erase(make_pair(d[to], to));           d[to] = d[k] + w;           last[to] = idx;           q.insert(make_pair(d[to], to));         }       }     }     printf( %d n , ans.size());     vector<int>::iterator x;     for (x = ans.begin(); x != ans.end(); x++) printf( %d  , *x + 1);   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 41;   const int mod = 1e9 + 7;   const long long INF = 1e18;   const int inf = 2e9;   vector<int> g[N];   long long res;   int cnt[2];   int a[N];   int sz[N];   bool used[N];   int cur_sz;   long long cur;   void pre(int v = 1, int p = -1) {     sz[v] = 1;     for (int to : g[v])       if (to != p && !used[to]) {         pre(to, v);         sz[v] += sz[to];       }   }   int f(int v, int p = -1) {     for (int to : g[v])       if (!used[to] && to != p && sz[to] * 2 > cur_sz) {         return f(to, v);       }     return v;   }   bool kth(int val, int bit) {     if (val & (1 << bit))       return true;     else       return false;   }   void addcur(int v, int p, int bit, bool pref = 0) {     pref ^= kth(a[v], bit);     cur += cnt[pref ^ 1];     for (int to : g[v])       if (!used[to] && to != p) {         addcur(to, v, bit, pref);       }   }   void addcnt(int v, int p, int bit, bool pref = 0) {     pref ^= kth(a[v], bit);     cnt[pref]++;     for (int to : g[v])       if (!used[to] && to != p) {         addcnt(to, v, bit, pref);       }   }   void dfs(int v = 1) {     pre(v);     cur_sz = sz[v];     v = f(v);     for (int bit = 0; bit < 20; ++bit) {       cur = 0;       cnt[1] = 0, cnt[0] = 1;       for (int to : g[v])         if (!used[to]) {           bool st = kth(a[v], bit);           addcur(to, v, bit, st);           addcnt(to, v, bit);         }       res += (1ll << bit) * 1ll * cur;     }     used[v] = 1;     for (int to : g[v])       if (!used[to]) {         dfs(to);       }   }   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     ;     int n;     cin >> n;     for (int i = 1; i <= n; ++i) {       cin >> a[i];       res += a[i];     }     for (int i = 1; i < n; ++i) {       int a, b;       cin >> a >> b;       g[a].push_back(b);       g[b].push_back(a);     }     dfs();     cout << res;   }


#include <bits/stdc++.h>   using namespace std;   const int dx[] = {0, 0, -1, 1};   const int dy[] = {1, -1, 0, 0};   const int N = 505;   int n, m;   char adj[N][N];   bool vis[N][N];   struct node {     int type, x, y;     node() {}     node(int type, int x, int y) : type(type), x(x), y(y) {}     void print() {       if (type == 0)         putchar( B );       else if (type == 1)         putchar( R );       else         putchar( D );       printf(  %d %d n , x + 1, y + 1);     }   };   vector<node> ans;   void dfs(int x, int y) {     vis[x][y] = 1;     for (int i = 0; i < 4; i++) {       int xx = x + dx[i];       int yy = y + dy[i];       if (xx >= 0 && xx < n && yy >= 0 && yy < m && vis[xx][yy] == 0) {         ans.push_back(node(0, xx, yy));         dfs(xx, yy);         ans.push_back(node(2, xx, yy));         ans.push_back(node(1, xx, yy));       }     }   }   int main() {     while (scanf( %d%d , &n, &m) != EOF) {       ans.clear();       memset(vis, 0, sizeof(vis));       for (int i = 0; i < n; i++) scanf( %s , adj[i]);       for (int i = 0; i < n; i++) {         for (int j = 0; j < m; j++) {           if (adj[i][j] ==  # ) vis[i][j] = 1;         }       }       for (int i = 0; i < n; i++) {         for (int j = 0; j < m; j++)           if (vis[i][j] == 0) {             ans.push_back(node(0, i, j));             dfs(i, j);           }       }       int len = (int)ans.size();       printf( %d n , len);       for (int i = 0; i < len; i++) ans[i].print();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   int arr[N];   int main() {     int n;     memset(arr, 0, sizeof arr);     cin >> n;     int maxx = n;     int num;     for (int i = 0; i < n; i++) {       cin >> num;       arr[num] = -1;       while (arr[maxx] == -1) {         cout << maxx <<    ;         maxx -= 1;       }       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int abs(int x) { return x > 0 ? x : -x; }   int min(int x, int y) { return x < y ? x : y; }   int max(int x, int y) { return x > y ? x : y; }   int main() {     int a1, a2, a3, a4;     scanf( %d%d%d%d , &a1, &a2, &a3, &a4);     if (abs(a3 - a4) > 1 || max(a3, a4) > min(a1, a2) || a3 + a4 + 1 > a1 + a2 ||         a3 + a4 == 0) {       printf( -1 n );       return 0;     }     int c = min(a3, a4);     a3 -= c;     a4 -= c;     a1 -= c, a2 -= c;     if (!a3 && !a4) {       if (!a1) {         for (int i = 1; i <= c; i++) printf( 74 );         for (int i = 1; i <= a2; i++) printf( 7 );       } else {         for (int i = 1; i < a1; i++) printf( 4 );         for (int i = 1; i <= c; i++) printf( 47 );         for (int i = 1; i <= a2; i++) printf( 7 );         printf( 4 n );       }     } else if (a3) {       for (int i = 1; i < a1; i++) printf( 4 );       for (int i = 1; i <= c + 1; i++) printf( 47 );       for (int i = 1; i < a2; i++) printf( 7 );     } else if (a4) {       printf( 74 );       for (int i = 1; i < a1; i++) printf( 4 );       for (int i = 1; i < c; i++) printf( 74 );       for (int i = 1; i <= a2; i++) printf( 7 );       printf( 4 );     }     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void c_p_c() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }   template <typename Arg1>   void __f(const char* name, Arg1&& arg1) {     cout << name <<   :   << arg1 <<   n ;   }   template <typename Arg1, typename... Args>   void __f(const char* names, Arg1&& arg1, Args&&... args) {     const char* comma = strchr(names + 1,  , );     cout.write(names, comma - names) <<   :   << arg1 <<   |  ;     __f(comma + 1, args...);   }   long long int n, m;   char a[50][50];   long long int vis[50][50];   long long int cnt = 0;   long long int dx[] = {1, -1, 0, 0};   long long int dy[] = {0, 0, 1, -1};   bool is_valid(long long int i, long long int j) {     if (i >= 0 and j >= 0 and i < n and j < m and a[i][j] ==  B ) {       return true;     }     return false;   }   void dfs(long long int i, long long int j, long long int dn,            long long int dir) {     if (vis[i][j] == 0) {       vis[i][j] = 1;       cnt++;     }     for (long long int k = 0; k < 4; k++) {       long long int x = i + dx[k];       long long int y = j + dy[k];       if (is_valid(x, y)) {         long long int g;         long long int p;         if (dir == -1) {           g = 0;         }         if (dir != -1) {           if (k == dir) {             g = dn;           } else {             g = dn + 1;           }         }         if (g > 1) {           continue;         }         dfs(x, y, g, k);       }     }   }   int32_t main() {     c_p_c();     cin >> n >> m;     long long int k = 0;     for (long long int i = 0; i < n; i++) {       for (long long int j = 0; j < m; j++) {         cin >> a[i][j];         if (a[i][j] ==  B ) {           k++;         }       }     }     for (long long int i = 0; i < n; i++) {       for (long long int j = 0; j < m; j++) {         if (a[i][j] ==  B ) {           memset(vis, 0, sizeof(vis));           cnt = 0;           dfs(i, j, 0, -1);           if (cnt != k) {             cout <<  NO  <<   n ;             return 0;           }         }       }     }     cout <<  YES  <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     long long x, q = k - 1, flag, a[k], i, j;     for (i = 0; i < n; i++) {       cin >> x;       if (!i)         a[q--] = x;       else {         flag = 0;         for (j = k - 1; j > q; j--) {           if (a[j] == x) {             flag = 1;             break;           }         }         if (flag == 0) {           if (q < 0) {             for (j = k - 1; j > 0; j--) a[j] = a[j - 1];             a[0] = x;           } else             a[q--] = x;         }       }     }     cout << k - (q + 1) << endl;     for (i = q + 1; i < k; i++) cout << a[i] <<    ;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 1000100100;   int n, m;   string s[105];   int team[105];   int dp[21][(1 << 21)];   int a[104];   int solve(int cur, int mask) {     if (cur == m) return 0;     int &ret = dp[cur][mask];     if (ret == inf) {       if (s[cur] ==  p ) {         int j = 0;         while (j < m && ((mask >> j) & 1)) ++j;         if (team[cur] == 1)           ret = solve(cur + 1, mask | (1 << j)) + a[j];         else           ret = solve(cur + 1, mask | (1 << j)) - a[j];       } else {         ret = solve(cur + 1, mask);         for (int j = 0; j < m; ++j) {           if ((mask >> j) & 1) continue;           if (team[cur] == 1)             ret = max(ret, solve(cur + 1, mask | (1 << j)));           else             ret = min(ret, solve(cur + 1, mask | (1 << j)));         }       }     }     return ret;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cin >> n;     for (int i = 0; i < n; ++i) cin >> a[i];     sort(a, a + n, greater<int>());     cin >> m;     for (int i = 0; i < m; ++i) {       cin >> s[i] >> team[i];     }     fill(&dp[0][0], &dp[0][0] + (21 * (1 << 21)), inf);     cout << solve(0, 0);   }


#include <bits/stdc++.h>   const double PI = 3.141592653589793238460;   using namespace std;   int main() {     long long int t, n, k;     cin >> t;     while (t--) {       cin >> n >> k;       if ((n < k * k))         cout <<  NO  <<   n ;       else if ((k % 2) != (n % 2))         cout <<  NO  <<   n ;       else         cout <<  YES  <<   n ;     }   }


////JAI SHREE RAM////   #include <iostream>   #include<bits/stdc++.h>   using namespace std;   const long long int INF = (long long)1e15;   const long long int mod = 1e9+7;   #define ll long long   #define f(i,a,b) for(int i=a;i<b;i++)   #define pb push_back   #define all(c) c.begin(),c.end()   #define rall(c) c.rbegin(),c.rend()   #define yes cout<< YES n    #define no cout<< NO n    #define sd second   #define ft first   //   bool cmp(const pair<int,int> &a, const pair<int,int> &b)   {       //return (a.sd>=b.sd);       return abs(a.ft)+abs(a.sd) < abs(b.ft)+abs(b.sd);   }      void solve()   {       int n;cin>>n;       int o=0;       n*=2;       f(i,0,n){           int x;cin>>x;           if(x%2) o++;       }       if(o==n/2) yes;       else no;   }   int main()   {       //ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0);       int t=1;       cin>>t;          while(t--)       {           solve();       }       return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     double x, cx;     cin >> n >> x;     cx = x;     double a[n + 1], b[n + 1];     for (int i = 1; i <= n; i++) {       cin >> a[i];       if (a[i] == 1) {         cout << -1;         return 0;       }     }     for (int i = 1; i <= n; i++) {       cin >> b[i];       if (b[i] == 1) {         cout << -1;         return 0;       }     }     x = x + x / (b[1] - 1);     for (int i = n; i > 1; i--) {       x = x * a[i] / (a[i] - 1);       x = x * b[i] / (b[i] - 1);     }     x = x + x / (a[1] - 1);     cout << setprecision(8) << x - cx;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 7;   vector<int> gr[N];   bool access = true;   int p[N], h[N], a[N], g[N];   void dfs(int v, int ancestor = -1) {     a[v] = p[v];     int sum_g = 0;     for (int to : gr[v]) {       if (to == ancestor) continue;       dfs(to, v);       sum_g += g[to];       a[v] += a[to];     }     if ((a[v] + h[v]) % 2 == 0) {     } else       access = false;     g[v] = (a[v] + h[v]) / 2;     if (g[v] >= 0 && g[v] <= a[v]) {     } else       access = false;     if (sum_g <= g[v]) {     } else       access = false;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     int q;     cin >> q;     while (q--) {       int n, m;       cin >> n >> m;       for (int i = 0; i < n; ++i) cin >> p[i];       for (int i = 0; i < n; ++i) cin >> h[i];       for (int i = 0; i < n - 1; ++i) {         int a, b;         cin >> a >> b;         --a, --b;         gr[a].push_back(b);         gr[b].push_back(a);       }       dfs(0);       cout << (access ?  YES  :  NO ) << endl;       access = true;       for (int i = 0; i < n; ++i) gr[i].clear();     }   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   int team[101];   char c[101];   int dp[21][(1 << 20) + 5];   int a[1001];   int solve(int pos, int mask) {     if (pos == n) return 0;     if (dp[pos][mask] != -1) return dp[pos][mask];     int ans;     if (team[pos] == 1) {       ans = -(1 << 30);       for (int i = 0; i < m; i++) {         if (mask & (1 << i)) {           if (c[pos] ==  p )             ans = max(ans, a[i] + solve(pos + 1, mask ^ (1 << i)));           else             ans = max(ans, solve(pos + 1, mask ^ (1 << i)));         }       }     } else {       ans = (1 << 30);       for (int i = 0; i < m; i++) {         if (mask & (1 << i)) {           if (c[pos] ==  p )             ans = min(ans, solve(pos + 1, mask ^ (1 << i)) - a[i]);           else             ans = min(ans, solve(pos + 1, mask ^ (1 << i)));         }       }     }     return dp[pos][mask] = ans;   }   int main() {     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i];     sort(a, a + n);     reverse(a, a + n);     cin >> m;     n = m;     memset(dp, -1, sizeof(dp));     for (int i = 0; i < m; i++) {       cin >> c[i] >> team[i];     }     cout << solve(0, (1 << m) - 1) << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n;     scanf( %lld , &n);     long long a, b, c;     scanf( %lld , &a);     scanf( %lld , &b);     scanf( %lld , &c);     if (a <= (b - c)) {       printf( %lld n , n / a);     } else {       n -= b;       long long x = 0;       if (n >= 0) {         x = n / (b - c);         n %= (b - c);       }       n += b;       if (n >= b) {         n = n - (b - c);         x++;       }       x += max(n / a, n / b);       printf( %lld n , x);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, kk, a[200];     scanf( %d%d , &n, &kk);     for (int i = 0; i < n; i++) scanf( %d , &a[i]);     int sum, tp, mx = a[0];     for (int i = 0; i < n; i++)       for (int j = i; j < n; j++) {         priority_queue<int> la, sm;         sum = 0;         for (int k = 0; k < n; k++)           if (k >= i && k <= j) {             sm.push(-a[k]);             sum += a[k];           } else             la.push(a[k]);         if (mx < sum) mx = sum;         int ts = sum;         for (int k = 0; k < kk; k++) {           sum += sm.top();           la.push(-sm.top());           sm.pop();           sum += la.top();           sm.push(-la.top());           la.pop();           if (ts >= sum) break;         }         if (mx < sum) mx = sum;       }     printf( %d , mx);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string s, p;   long long l, r, dp[32][3][3][3][3];   string ts(long long x) {     string ans;     while (x) {       ans.push_back( 0  + x % 2);       x /= 2;     }     while (ans.size() != 31) ans.push_back( 0 );     reverse(ans.begin(), ans.end());     return ans;   }   long long f(int x, int a, int b, int c, int d) {     if (x == s.size()) return 1;     if (dp[x][a][b][c][d] != -1) return dp[x][a][b][c][d];     long long ans = 0;     for (int i = 0; i <= 1; i++) {       for (int j = 0; j <= 1; j++) {         if (i == j && i) continue;         char aa = i +  0 , bb = j +  0 ;         if (a && s[x] > aa) continue;         if (b && p[x] < aa) continue;         if (c && s[x] > bb) continue;         if (d && p[x] < bb) continue;         int na = (a & (s[x] == aa));         int nb = (b & (p[x] == aa));         int nc = (c & (s[x] == bb));         int nd = (d & (p[x] == bb));         ans += f(x + 1, na, nb, nc, nd);       }     }     return dp[x][a][b][c][d] = ans;   }   int main() {     int t;     cin >> t;     while (t--) {       memset(dp, -1, sizeof dp);       cin >> l >> r;       s = ts(l), p = ts(r);       cout << f(0, 1, 1, 1, 1) << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   T gcd(T a, T b) {     return !b ? a : gcd(b, a % b);   }   template <typename T>   T lcm(T a, T b) {     return a * (b / gcd(a, b));   }   template <typename T>   T sqr(T a) {     return a * a;   }   template <typename T>   T cube(T a) {     return a * a * a;   }   template <typename T>   inline void smin(T &a, T b) {     a = a < b ? a : b;   }   template <typename T>   inline void smax(T &a, T b) {     a = a > b ? a : b;   }   template <typename T>   inline void Int(T &n) {     n = 0;     int f = 1;     register int ch = getchar();     for (; !isdigit(ch); ch = getchar())       if (ch ==  - ) f = -1;     for (; isdigit(ch); ch = getchar()) n = (n << 3) + (n << 1) + ch -  0 ;     n = n * f;   }   vector<string> split(const string &s, char c) {     vector<string> v;     stringstream second(s);     string x;     while (getline(second, x, c)) v.emplace_back(x);     return move(v);   }   void err(vector<string>::iterator it) {}   template <typename T, typename... Args>   void err(vector<string>::iterator it, T a, Args... args) {     cout << it->substr((*it)[0] ==    , it->length()) <<   =   << a <<  ,  ;     err(++it, args...);   }   inline int in() {     int n;     scanf( %d , &n);     return n;   }   inline long long Lin() {     long long n;     scanf( %lld , &n);     return n;   }   inline double Din() {     double n;     scanf( %lf , &n);     return n;   }   inline int add(int a, int b, int mod) {     a += b;     return a >= mod ? a - mod : a;   }   inline int sub(int a, int b, int mod) {     a -= b;     return a < 0 ? a + mod : a;   }   inline int mul(int a, int b, int mod) { return (long long)a * b % mod; }   const int N = 2e5 + 5;   const int inf = (int)2e9 + 5;   const long long Inf = (long long)1e18 + 5;   const int mod = (int)1e9 + 7;   const long long Mod = (long long)1e9 + 7;   vector<int> b[N];   int solve() {     int n = in(), k = in();     vector<int> a(n);     for (int i = 0; i < n; i++) {       a[i] = in();     }     for (int i = 0; i < n; i++) {       int x = a[i], cur = 0;       while (x >= 1) {         b[x].push_back(cur);         x /= 2;         cur++;       }     }     long long ans = Inf;     for (int i = 0; i <= 2e5; i++) {       sort(b[i].begin(), b[i].end());       if ((int)b[i].size() >= k) {         long long cur = 0;         for (int j = 0; j < k; j++) {           cur += b[i][j];         }         smin(ans, cur);       }     }     printf( %lld n , ans);     return 0;   }   int main() {     int test = 1, tc = 0;     while (test--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const long long LL_INF = 0x3f3f3f3f3f3f3f3f;   const double PI = 3.14159265359;   const int mod = 1000 * 1000 * 1000 + 7;   int dx[4] = {1, -1, 0, 0};   int dy[4] = {0, 0, 1, -1};   string s;   int dp[100005];   int solve(int idx) {     if (idx == s.size()) return 1;     int &ret = dp[idx];     if (~ret) return ret;     ret = 0;     if (s[idx] ==  u  or s[idx] ==  n ) {       if (idx + 1 < s.size() and s[idx + 1] == s[idx]) {         ret = (solve(idx + 1) + solve(idx + 2)) % mod;       } else         ret = solve(idx + 1) % mod;     } else       ret = solve(idx + 1) % mod;     return ret;   }   int main() {     cin >> s;     if (s.find( w ) != -1 or s.find( m ) != -1) return cout << 0 << endl, 0;     memset(dp, -1, sizeof dp);     cout << solve(0) % mod << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   pair<int, int> arr[100005];   vector<int> v1[100005];   int visited[100005];   stack<int> s;   int n, m;   set<int> se[100005];   void dfs(int node) {     int i;     visited[node] = 1;     int n = v1[node].size();     for (i = 0; i < n; i++) {       if (visited[v1[node][i]] == 0) {         dfs(v1[node][i]);       }     }     s.push(node);   }   bool check(int mid) {     int i;     bool ans = true;     for (i = 1; i <= mid; i++) {       v1[arr[i].first].push_back(arr[i].second);       se[arr[i].first].insert(arr[i].second);     }     for (i = 1; i <= n; i++) visited[i] = 0;     for (i = 1; i <= n; i++) {       if (visited[i] == 0) {         dfs(i);       }     }     int x;     x = s.top();     s.pop();     while (!s.empty()) {       if (se[x].find(s.top()) == se[x].end()) ans = false;       x = s.top();       s.pop();     }     for (i = 1; i <= n; i++) {       v1[i].clear();       se[i].clear();     }     return ans;   }   int main() {     int i, j, k;     scanf( %d , &n);     scanf( %d , &m);     for (i = 1; i <= m; i++) {       scanf( %d , &arr[i].first);       scanf( %d , &arr[i].second);     }     int l = 0, r = m, mid;     while (l <= r) {       mid = (l + r) / 2;       bool temp1 = check(mid);       if (mid == m) {         if (temp1 == false) {           printf( -1 n );           return 0;         } else {           r = mid - 1;           continue;         }       }       bool temp2 = check(mid + 1);       if (temp1 == false && temp2 == true) {         printf( %d n , mid + 1);         return 0;       } else if (temp2 == true) {         r = mid - 1;       } else {         l = mid + 1;       }     }     printf( -1 n );     return 0;   }


#include <bits/stdc++.h>   const int Maxn = 1000;   const int Inf = 0x3f3f3f3f;   int n, m;   int a[Maxn + 5], b[Maxn + 5];   std::vector<int> edge[Maxn + 5];   int pre[Maxn + 5];   long long dis[Maxn + 5];   bool vis[Maxn + 5];   bool check(int x) {     for (int i = 1; i <= n; i++) {       vis[i] = 0;     }     vis[1] = 1;     long long now = x, tot = 1;     while (tot < n) {       std::queue<int> q;       for (int i = 1; i <= n; i++) {         pre[i] = 0;         dis[i] = 0;         if (vis[i]) {           q.push(i);           dis[i] = now;         }       }       int x = 0, y = 0;       while (!q.empty()) {         int u = q.front();         q.pop();         for (int i = 0; i < (int)edge[u].size(); i++) {           int v = edge[u][i];           if (!vis[v]) {             if (dis[u] <= a[v]) {               continue;             }             if (pre[v] == 0) {               pre[v] = u;               dis[v] = dis[u] + b[v];               q.push(v);             } else if (v != pre[u]) {               x = u, y = v;               goto OUT;             }           } else if (!vis[u] && v != pre[u]) {             x = u, y = v;             goto OUT;           }         }       }     OUT:;       if (x == 0) {         return 0;       }       for (int u = x; u; u = pre[u]) {         if (!vis[u]) {           vis[u] = 1;           now += b[u];           tot++;         }       }       for (int u = y; u; u = pre[u]) {         if (!vis[u]) {           vis[u] = 1;           now += b[u];           tot++;         }       }     }     return 1;   }   void solve() {     int left = Inf, right = 0;     scanf( %d%d , &n, &m);     for (int i = 2; i <= n; i++) {       scanf( %d , &a[i]);       left = std::min(left, a[i]);       right = std::max(right, a[i]);     }     right++;     for (int i = 2; i <= n; i++) {       scanf( %d , &b[i]);     }     for (int i = 1; i <= n; i++) {       edge[i].clear();     }     for (int i = 1; i <= m; i++) {       int u, v;       scanf( %d%d , &u, &v);       edge[u].push_back(v), edge[v].push_back(u);     }     while (left < right) {       int mid = (left + right) >> 1;       if (check(mid)) {         right = mid;       } else {         left = mid + 1;       }     }     printf( %d n , left);   }   int main() {     int T;     scanf( %d , &T);     while (T--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     int n = s.size();     cout <<  3 nL 2 nR 2 nR   << n + n - 1;   }


#include <bits/stdc++.h>   using namespace std;   const int Maxn = 102;   int n, K;   double dp[2][Maxn][Maxn];   int a[Maxn];   inline int c2(int x) { return x * (x - 1) / 2; }   inline int max(int x, int y) { return x > y ? x : y; }   inline int min(int x, int y) { return x < y ? x : y; }   int main() {     scanf( %d%d , &n, &K);     if (K > 875) K = 875;     for (int i = 1; i <= n; i++) scanf( %d , a + i);     for (int i = 1; i <= n; i++)       for (int j = i + 1; j <= n; j++) dp[0][i][j] = a[i] > a[j];     int cs = 1;     for (int k = 1; k <= K; k++, cs ^= 1) {       for (int i = 1; i <= n; i++)         for (int j = i + 1; j <= n; j++) {           dp[cs][i][j] = 0;           dp[cs][i][j] += dp[cs ^ 1][i][j] * (c2(i) + c2(n - j + 1) + c2(j - i));           for (int sum = j + 1; sum <= i + n; sum++) {             dp[cs][i][j] += (1.0 - dp[cs ^ 1][sum - j][sum - i]) *                             (min(i, sum - j) - max(1, sum - n) + 1);           }           for (int sum = i + 1; sum <= i + j - 1; sum++)             dp[cs][i][j] += dp[cs ^ 1][sum - i][j] *                             (min(i, sum - i) - max(1, sum - j + 1) + 1);           for (int sum = j + i + 1; sum <= n + j; sum++)             dp[cs][i][j] += dp[cs ^ 1][i][sum - j] *                             (min(j, sum - j) - max(i + 1, sum - n) + 1);           dp[cs][i][j] /= c2(n + 1);         }     }     double ans = 0;     for (int i = 1; i <= n; i++)       for (int j = i + 1; j <= n; j++) ans += dp[cs ^ 1][i][j];     printf( %.12f n , ans);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long n, x, y = 0;     cin >> n >> x;     for (int i = 1; i <= n; i++) {       char a;       long long d;       cin >> a >> d;       if (a ==  + )         x += d;       else if (x >= d)         x -= d;       else         y++;     }     cout << x <<     << y << endl;   }


#include <bits/stdc++.h>   using namespace std;   struct segtree2 {     int seg[512 * 1024 * 2];     int mum;     void init(int n) {       mum = 1;       while (mum < n) mum <<= 1;       for (int i = 0; i < mum * 2; i++) seg[i] = -1;     }     void add(int k, int x) {       k += mum - 1;       seg[k] = x;       while (k > 0) {         k = (k - 1) / 2;         seg[k] = max(seg[k * 2 + 1], seg[k * 2 + 2]);       }     }     int get(int a, int b, int k, int l, int r) {       if (b <= l || r <= a) return -1;       if (a <= l && r <= b)         return seg[k];       else {         int vl = get(a, b, k * 2 + 1, l, (l + r) / 2);         int vr = get(a, b, k * 2 + 2, (l + r) / 2, r);         return max(vl, vr);       }     }     int get(int a, int b) { return get(a, b, 0, 0, mum); }   };   struct segtree1 {     int seg[512 * 1024 * 2];     int mum;     void init(int n) {       mum = 1;       while (mum < n) mum <<= 1;       for (int i = 0; i < mum * 2; i++) seg[i] = 1000000005;     }     void update(int a, int b, int k, int l, int r, int v) {       if (b <= l || r <= a) return;       if (a <= l && r <= b)         seg[k] = min(seg[k], v);       else {         update(a, b, k * 2 + 1, l, (l + r) / 2, v);         update(a, b, k * 2 + 2, (l + r) / 2, r, v);       }     }     void update(int a, int b, int v) { update(a, b, 0, 0, mum, v); }     void pass(int k) {       seg[k * 2 + 1] = min(seg[k * 2 + 1], seg[k]);       seg[k * 2 + 2] = min(seg[k * 2 + 2], seg[k]);       seg[k] = 1000000005;     }     void erase(int x) {       int l = 0, r = mum, k = 0;       while (l + 1 < r) {         pass(k);         int m = (l + r) / 2;         if (x < m) {           r = m;           k = k * 2 + 1;         } else {           l = m;           k = k * 2 + 2;         }       }       seg[k] = 1000000005;     }     int get(int k) {       k += mum - 1;       int ret = seg[k];       while (k > 0) {         k = (k - 1) / 2;         ret = min(ret, seg[k]);       }       return ret;     }   };   segtree1 s1;   segtree2 s2;   int L[300005], R[300005], X[300005];   int pos[300005], dt[300005];   int tp[300005];   int mx[300005], nowA[300005];   set<int> st[300005];   set<int>::iterator it;   vector<int> vec[40];   bool use[300005];   bool ng[300005];   int main() {     int n, m;     scanf( %d %d , &n, &m);     s1.init(n + 2);     s2.init(n + 2);     memset(nowA, -1, sizeof(nowA));     memset(use, false, sizeof(use));     for (int i = 0; i < m; i++) {       scanf( %d , &tp[i]);       if (tp[i] == 1) {         scanf( %d %d %d , &L[i], &R[i], &X[i]);         L[i]--, R[i]--;         s1.update(L[i], R[i] + 1, X[i]);         int gt = s2.get(L[i], R[i] + 1);         if (gt > X[i]) {           puts( NO );           return 0;         }         use[i] = gt == X[i];       } else {         scanf( %d %d , &pos[i], &dt[i]);         pos[i]--;         int gt = s1.get(pos[i]);         gt = min(gt, 1000000000);         if (nowA[pos[i]] == -1) mx[pos[i]] = gt;         nowA[pos[i]] = dt[i];         s2.add(pos[i], dt[i]);       }     }     for (int i = 0; i < n; i++) {       if (nowA[i] == -1) {         mx[i] = s1.get(i);         mx[i] = min(mx[i], 1000000000);       }     }     vector<int> vx;     for (int i = 0; i < n; i++) vx.push_back(mx[i]);     sort(vx.begin(), vx.end());     vx.erase(unique(vx.begin(), vx.end()), vx.end());     for (int i = 0; i < n; i++) {       mx[i] = lower_bound(vx.begin(), vx.end(), mx[i]) - vx.begin();       st[mx[i]].insert(i);     }     for (int i = 0; i < m; i++) {       if (tp[i] == 1 && !use[i]) {         int t = lower_bound(vx.begin(), vx.end(), X[i]) - vx.begin();         if (t == vx.size() || vx[t] != X[i]) {           puts( NO );           return 0;         }         it = st[t].lower_bound(L[i]);         if (it == st[t].end() || *it > R[i]) {           puts( NO );           return 0;         }         int to = *it;         it++;         if (it == st[t].end() || *it > R[i]) {           ng[to] = true;         }       } else {         int v = pos[i];         st[mx[v]].erase(v);       }     }     for (int i = 0; i < n; i++) {       mx[i] = vx[mx[i]];       int vl = mx[i];       if (vl > 0) {         int cnt = 0;         while (vl > 0) {           vl /= 2;           cnt++;         }         vec[cnt - 1].push_back(i);       }     }     int ret = 0;     for (int i = 40 - 1; i >= 0; i--) {       if (vec[i].empty()) continue;       if (ret >> i & 1) {         bool U = true;         for (int j = 0; j < vec[i].size(); j++) {           int v = vec[i][j];           if (!ng[v] && U) {             mx[v] = ((mx[v] >> (i + 1)) << (i + 1)) + (1 << i) - 1;             U = false;           }           ret |= mx[v];         }         if (!U) break;       } else {         if (vec[i].size() == 1) {           int v = vec[i][0];           if (!ng[v]) {             int zan = mx[v] - ((mx[v] >> i) << i);             ret |= 1 << i;             if (zan > 0) {               int vl = zan, cnt = 0;               while (vl > 0) {                 vl /= 2;                 cnt++;               }               vec[cnt - 1].push_back(v);             }           } else             ret |= mx[v];         } else {           bool up = false;           for (int j = 0; j < vec[i].size(); j++) {             int v = vec[i][j];             up |= !ng[v];           }           if (up) {             for (int j = 0; j < vec[i].size(); j++) {               int v = vec[i][j];               if (!ng[v]) {                 mx[v] = ((mx[v] >> (i + 1)) << (i + 1)) + (1 << i) - 1;                 break;               }             }             ret |= (1 << (i + 1)) - 1;             break;           } else {             for (int j = 0; j < vec[i].size(); j++) {               int v = vec[i][j];               ret |= mx[v];             }           }         }       }     }     puts( YES );     for (int i = 0; i < n; i++) {       if (i != 0) printf(   );       printf( %d , mx[i]);     }     puts(  );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = (int)1e9;   int a, c;   int arrA[2000];   int arrC[2000];   void sol() {     cin >> c >> a;     for (int i = 0; i < c; i++) {       cin >> arrC[i];     }     for (int i = 0; i < a; i++) {       cin >> arrA[i];     }     int result = 0;     int j = 0;     for (int i = 0; i < a && j < c; i++, j++) {       while (j < c && arrC[j] > arrA[i]) j++;       if (j >= c) break;       result++;     }     cout << result << endl;   }   int main(void) {     sol();     return 0;   }


#include <bits/stdc++.h>   void __check(const char* expr, const char* file, unsigned int line) {     printf( %s:%u: failed check `%s  n , file, line, expr);     abort();   }   using namespace std;   template <typename T>   bool uin(T& a, T b) {     if (b < a) {       a = b;       return true;     }     return false;   }   template <typename T>   bool uax(T& a, T b) {     if (a < b) {       a = b;       return true;     }     return false;   }   template <typename T>   int sz(const T& t) {     return static_cast<int>(t.size());   }   template <typename T>   void shrink(std::vector<T>& v) {     std::vector<T>(v).swap(v);   }   const bool DBG = false;   int main() {     ios_base::sync_with_stdio(false);     int n;     cin >> n;     vector<int> v(1 + n);     for (int i = 0; i < (int)(n); ++i) {       cin >> v[i];       v[i]--;     }     v[n] = v[n - 1] ^ 1;     int prev = v[0];     array<int, 2> a;     a.fill(0);     a[prev]++;     int res = 0;     for (int i = 1; i <= n; ++i) {       int value = v[i];       if (value != prev) {         if (a[value] > 0) {           int opposite = value ^ 1;           auto local_res = min(a[opposite], a[value]) * 2;           res = max(local_res, res);           a[value] = 0;         }       }       a[value]++;       prev = value;     }     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct Player {     string name;     long int points;     map<int, int> places;   };   Player compSecond(Player a, Player b) {     if (a.points > b.points) {       return a;     } else if (a.points < b.points) {       return b;     }     for (int i = 1; i < 70; i++) {       if (a.places[i] > b.places[i]) {         return a;       }       if (a.places[i] < b.places[i]) {         return b;       }     }   }   Player compFirst(Player a, Player b) {     if (a.places[1] > b.places[1]) {       return a;     } else if (a.places[1] < b.places[1]) {       return b;     }     if (a.points > b.points) {       return a;     } else if (a.points < b.points) {       return b;     }     for (int i = 2; i < 70; i++) {       if (a.places[i] > b.places[i]) {         return a;       }       if (a.places[i] < b.places[i]) {         return b;       }     }   }   map<string, Player> parts;   vector<int> points = {25, 18, 15, 12, 10, 8, 6, 4, 2, 1};   int main() {     int n;     cin >> n;     set<Player> st;     for (int i = 0; i < n; i++) {       int players;       cin >> players;       for (int j = 1; j <= players; j++) {         string name;         cin >> name;         parts[name].points += (j <= 10) ? points[j - 1] : 0;         parts[name].places[j]++;         parts[name].name = name;       }     }     Player min;     Player first;     Player second;     first.points = 0;     second.points = 0;     for (auto i : parts) {       first = compSecond(i.second, first);       second = compFirst(i.second, second);     }     cout << first.name << endl << second.name << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, c;     cin >> a;     b = 1;     while ((b * b + 1) / 2 < a) b += 2;     cout << (a == 3 ? 5 : b);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   pair<int, int> a[111];   int m;   long long p[111];   long long an;   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) scanf( %d%d , &a[i].second, &a[i].first);     sort(a + 1, a + 1 + n);     scanf( %d , &m);     for (int i = 1; i <= m; ++i) scanf( %I64d , &p[i]);     p[++m] = 1e12;     long long cur = 0;     int ps = 1;     for (int i = 1; i <= n; ++i) {       while (a[i].second) {         if (cur + a[i].second > p[ps]) {           a[i].second -= p[ps] - cur;           an += 1ll * ps * (p[ps] - cur) * a[i].first;           cur = p[ps++];         } else {           an += 1ll * a[i].second * ps * a[i].first;           cur += a[i].second;           a[i].second = 0;         }       }     }     printf( %I64d , an);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 4e5 + 5;   struct Edge {     int v, nxt;     Edge() {}     Edge(int _v, int _nxt) : v(_v), nxt(_nxt) {}   };   Edge E[MAXN * 2];   int head[MAXN], ans[MAXN], sub[MAXN], mxsub[MAXN];   int tot = 0, fuc, n, x, y;   void addedge(int u, int v) {     E[tot] = Edge(v, head[u]);     head[u] = tot++;   }   void dfs1(int now, int fa) {     sub[now] = 1;     mxsub[now] = 1;     int tmp = 1;     for (int i = head[now]; ~i; i = E[i].nxt) {       int v = E[i].v;       if (v != fa) {         dfs1(v, now);         sub[now] += sub[v];         mxsub[now] = max(mxsub[now], mxsub[v]);         tmp += sub[v];       }     }     if (tmp <= fuc) {       mxsub[now] = tmp;     }   }   void dfs2(int now, int fa, int subfa, int mxfa) {     int cnt = subfa > fuc;     int id;     if (cnt) {       id = -1;     }     int tmp = n;     int mx1, mx2;     int id1, id2;     mx1 = mx2 = -1;     for (int i = head[now]; ~i; i = E[i].nxt) {       int v = E[i].v;       if (v != fa) {         if (id1 == -1 || mx1 < mxsub[v]) {           mx2 = mx1;           id2 = id1;           mx1 = mxsub[v];           id1 = v;         } else if (id2 == -1 || mx2 < mxsub[v]) {           mx2 = mxsub[v];           id2 = v;         }       }     }     for (int i = head[now]; ~i; i = E[i].nxt) {       int v = E[i].v;       if (v != fa) {         dfs2(v, now, sub[now] - sub[v] + subfa,              max(tmp - sub[v] <= fuc ? tmp - sub[v] : 0,                  max(mxfa, id1 == v ? mx2 : mx1)));         if (sub[v] > fuc) {           cnt++;           id = v;         }       }     }     if (cnt > 1) {       ans[now] = 0;     } else if (cnt == 0) {       ans[now] = 1;     } else if (id != -1) {       ans[now] = (sub[id] - mxsub[id] <= fuc);     } else {       ans[now] = (subfa - mxfa <= fuc);     }   }   int main() {     memset(head, -1, sizeof(head));     scanf( %d , &n);     for (int i = 1; i < n; i++) {       scanf( %d%d , &x, &y);       addedge(x, y);       addedge(y, x);     }     fuc = n / 2;     dfs1(1, 1);     dfs2(1, 1, 0, 0);     for (int i = 1; i <= n; i++) {       printf( %d  , ans[i]);     }   }


#include <bits/stdc++.h>   using namespace std;   const double EPS = 0.0000001;   const double PI = acos(-1);   const long long INFLL = 0x7FFFFFFFFFFFFFFF;   const int INF = 0x7FFFFFFF;   template <typename T>   inline void next(T &num) {     char c;     num = 0;     do {       c = getchar_unlocked();     } while (c != EOF && c ==     && c ==   n  && c ==   t );     int sign = (c ==  -  ? -1 : 1);     if (c !=  - ) num += (c -  0 );     while ((c = getchar_unlocked()) != EOF && c !=   n  && c !=   t  &&            c !=    ) {       num *= 10;       num += (c -  0 );     }     num *= sign;   }   inline string getstr() {     string str;     char k;     while ((k = getchar_unlocked()) ==     || k ==   n ) {       k = getchar_unlocked();       if (k ==     || k ==   n )         continue;       else         break;     }     str.push_back(k);     while ((k = getchar_unlocked()) != EOF && k !=   n  && k !=   t  &&            k !=   v  && k !=   0  && k !=    )       str.push_back(k);     return str;   }   const int M = 50005;   long long n, a[M];   long long ans;   void dfs(long long n, int p, long long now) {     if (now > ans) return;     if (!n) {       ans = min(ans, now);       return;     }     if (!p) return;     int need = n / a[p];     dfs(n - need * a[p], p - 1, now + p * need);     dfs((need + 1) * a[p] - n, p - 1, now + p * (need + 1));   }   int main() {     cin >> n;     for (int i = int(1), _b = int(16); i <= _b; i++) a[i] = a[i - 1] * 10 + 1;     ans = n;     dfs(n, 16, 0);     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-8;   const int INF = 1e9;   const int N = 150010;   int n, m, s, k;   int a[110][110];   int main() {     scanf( %d%d%d , &n, &m, &k);     int s0 = 0, s1 = 0;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         scanf( %d , &a[i][j]);         if (a[i][j] == 0)           s0++;         else           s1++;       }     }     int ans = min(s0, s1);     int b[110], sum, tmp;     memset(b, 0, sizeof(b));     for (int i = 0; i < n; i++) {       sum = 0, tmp = 0;       for (int j = 0; j < m; j++) {         b[j] = a[i][j];       }       for (int j = 0; j < n; j++) {         if (j == i) continue;         tmp = 0;         for (int t = 0; t < m; t++) {           if (a[j][t] != b[t]) tmp++;         }         tmp = min(tmp, m - tmp);         sum += tmp;       }       ans = min(ans, sum);     }     memset(b, 0, sizeof(b));     for (int j = 0; j < m; j++) {       sum = 0, tmp = 0;       for (int i = 0; i < n; i++) {         b[i] = a[i][j];       }       for (int i = 0; i < m; i++) {         if (i == j) continue;         tmp = 0;         for (int t = 0; t < n; t++) {           if (a[t][i] != b[t]) tmp++;         }         tmp = min(tmp, n - tmp);         sum += tmp;       }       ans = min(ans, sum);     }     if (ans > k)       puts( -1 );     else       printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long modulo = 1000000007;   int choose(int n, int r) {     if (n < r) {       return 0;     }     if (n == r || r == 0) {       return 1;     }     return choose(n - 1, r - 1) + choose(n - 1, r);   }   int get_factors(int n) {     int numFactors = 0;     for (int i = 1; i <= sqrt(n); i++) {       bool divisible = n % i == 0;       if (!divisible) {         continue;       }       int quotient = n / i;       numFactors++;       if (quotient != i) {         numFactors++;       }     }     return numFactors;   }   int sumDigits(int num) {     int sum = 0;     while (num > 0) {       sum += num % 10;       num /= 10;     }     return sum;   }   int gcd(int a, int b) {     if (b == 0) return a;     return gcd(b, a % b);   }   vector<int> dfs(int i, vector<int> graph[], vector<bool>& visited) {     vector<int> group = {i};     vector<int> connected = graph[i];     visited[i] = true;     for (int j : connected) {       if (!visited[j]) {         vector<int> vals = dfs(j, graph, visited);         for (int val : vals) {           group.push_back(val);         }       }     }     return group;   }   bool comparePairs(pair<long long, long long> p1,                     pair<long long, long long> p2) {     if (p1.first < p2.first) {       return true;     } else if (p1.first > p2.first) {       return false;     } else {       return p1.second < p2.second;     }   }   vector<int> primes(int n) {     vector<int> p(n + 1);     for (int i = 0; i <= n; i++) {       p[i] = i;     }     p[0] = -1;     p[1] = -1;     for (int i = 2; i <= n; i++) {       if (p[i] == -1) {         continue;       }       int temp = i * i;       while (temp <= n) {         p[temp] = -1;         temp += i;       }     }     return p;   }   vector<long long> nextPrimes(long long n) {     vector<long long> p(n + 1, 0);     for (long long i = 0; i <= n; i++) {       p[i] = i;     }     p[0] = -1;     p[1] = -1;     for (long long i = 2; i <= n; i++) {       if (p[i] == -1) {         continue;       }       long long temp = i * i;       while (temp <= n) {         p[temp] = -1;         temp += i;       }     }     long long last = -1;     for (long long i = n; i >= 0; i--) {       if (p[i] == -1) {         p[i] = last;       } else {         last = p[i];       }     }     return p;   }   bool comparePairs(const pair<int, int>& lhs, const pair<int, int>& rhs) {     return abs(lhs.first - lhs.second) < abs(rhs.first - lhs.second);   }   void solve() {     int n, k;     cin >> n >> k;     vector<int> want(k + 1);     vector<bool> taken(n * k + 1, false);     for (int i = 1; i < k + 1; i++) {       int iOfWant;       cin >> iOfWant;       want[i] = iOfWant;       taken[iOfWant] = true;     }     int curr = 1;     for (int i = 1; i < k + 1; i++) {       cout << want[i] <<    ;       for (int j = 0; j < n - 1; j++) {         while (taken[curr]) {           curr++;         }         cout << curr <<    ;         curr++;       }       cout <<   n ;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t = 1;     while (t-- > 0) {       solve();       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int N, K;   long long B;   long long A[100005], Ac[100005];   int main() {     cin >> N >> K >> B;     map<long long, int> ct;     for (int i = 0; i < N; i++) {       cin >> A[i];       ct[A[i]]++;     }     ct[A[N - 1]]--;     for (int i = 0; i < N - 1; i++) Ac[i] = A[i];     sort(Ac, Ac + N - 1);     reverse(Ac, Ac + N - 1);     if (K >= N) K = N - 1;     long long presum = 0;     long long nth = Ac[K - 1];     for (int i = 0; i < K; i++) presum += Ac[i];     for (int i = 0; i < N - 1; i++) {       long long s = presum - max(nth, A[i]);       if (s + A[i] > B) {         cout << i + 1 <<   n ;         return 0;       }     }     cout << N <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const int nax = 2e5;   int par[nax], dp[nax];   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     map<int, int> prev;     int ma = -1, mai;     for (int i = 0; i < n; i++) {       int a;       cin >> a;       dp[i] = 1;       par[i] = -1;       if (prev.count(a - 1)) {         par[i] = prev[a - 1];         dp[i] = dp[prev[a - 1]] + 1;       }       if (dp[i] > ma) {         ma = dp[i];         mai = i;       }       prev[a] = i;     }     cout << ma << endl;     int p = mai;     vector<int> path;     while (p != -1) {       path.push_back(p);       p = par[p];     }     reverse(path.begin(), path.end());     for (int i : path) cout << i + 1 <<    ;     cout << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a;     cin >> a;     while (a--) {       int b, c;       cin >> b >> c;       int n = abs(b - c);       n = n / 5 + (n % 5) / 2 + (n % 5) % 2;       cout << n <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   multiset<long long> buckets[30];   long long bsum[30];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int q, tot = 0;     cin >> q;     while (q--) {       char c;       long long x;       cin >> c >> x;       int p = 31 - __builtin_clz(x), ans = 0;       if (c ==  + )         buckets[p].insert(x), bsum[p] += x, tot++;       else         buckets[p].erase(buckets[p].find(x)), bsum[p] -= x, tot--;       long long sm = 0;       for (int i = 0; i < 30; i++)         if (buckets[i].size()) {           if (*buckets[i].begin() > 2 * sm) ans++;           sm += bsum[i];         }       cout << tot - ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ull = unsigned long long;   int n;   int cnt[1 << 20];   int cnt2[1 << 20];   int main() {     ios::sync_with_stdio(false);     cin.tie(0), cout.tie(0);     cin >> n;     ll res = 0;     ++cnt2[0];     for (int pref = 0, a, i = 1; i <= n; ++i) {       cin >> a;       pref ^= a;       if (i & 1) {         res += cnt[pref];         ++cnt[pref];       } else {         res += cnt2[pref];         ++cnt2[pref];       }     }     cout << res << endl;     return 0;   }