#include <bits/stdc++.h>   using namespace std;   int dp[123000];   int n, m;   long long d, k, a, b, t;   void input() {}   void solve() {     long long ans = 0;     if (d <= k) {       ans = (long long)a * (long long)d;       printf( %lld n , ans);       return;     }     d -= k;     ans += (long long)a * (long long)k;     long long i = (long long)(a - b) * (long long)k + (long long)t;     if (i >= 0) {       ans += (long long)b * (long long)d;     } else {       long long x = d / k;       long long s = (long long)d - x * (long long)k;       long long j1 = x * i + (long long)b * (long long)d;       long long j2 = ((long long)a * (long long)k + (long long)t) * x +                      (long long)t + (long long)a * s;       ans += j1 < j2 ? j1 : j2;     }     printf( %lld n , ans);   }   int main() {     while (scanf( %lld %lld %lld %lld %lld , &d, &k, &a, &b, &t) != EOF) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   #define LL long long   #define PII pair<int, int>   #define PLL pair<LL, LL>   #define all_of(v) (v).begin(), (v).end()   #define sort_unique(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))   #define fi first   #define se second   const int MAXN = 401;   //const LL INF = (LL) 1e9 + 8763;   //const LL MOD = (LL) 1e9 + 7;   using namespace std;   const LL MOD = 998244353;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());      LL n, cnt[26], dall[MAXN], dp1[MAXN][MAXN][2], dp2[2][MAXN][MAXN][3], have[MAXN];      void solve() {    cin >> n;    for (int i = 0; i < 26; i++) {     cin >> cnt[i];    }        int a = n / 2, b = n - a;    for (int i = 1; i <= n; i++) {     have[i] = 1;    }    have[a] = have[n] = 0;        // [pos][used 0][used 1][last]    dall[1] = 1;    dp1[1][1][0] = 1;    dp1[1][0][1] = 1;    dp2[1][0][0][2] = 1;    dp2[1][0][1][1] = 1;    dp2[1][1][0][0] = 1;        // 2    for (int i = 2; i <= n; i++) {     for (int u0 = 0; u0 <= i; u0++) {      for (int u1 = 0; u1 <= i; u1++) {       for (int last = 0; last < 3; last++) {        LL &now = dp2[i % 2][u0][u1][last];        now = 0;        if (last == 0 && u0 == 0) continue;        if (last == 1 && u1 == 0) continue;        if (!have[i - 1] || last != 0) {         now = (now + dp2[(i - 1) % 2][u0 - (last == 0)][u1 - (last == 1)][0]) % MOD;        }        if (!have[i - 1] || last != 1) {         now = (now + dp2[(i - 1) % 2][u0 - (last == 0)][u1 - (last == 1)][1]) % MOD;        }        LL coe = 23 + (!have[i - 1] || last != 2);        now = (now + dp2[(i - 1) % 2][u0 - (last == 0)][u1 - (last == 1)][2] * coe) % MOD;       }      }     }    }    // 1    for (int i = 2; i <= n; i++) {     for (int u0 = 0; u0 <= i; u0++) {      for (int last = 0; last < 2; last++) {       if (last == 0 && u0 == 0) continue;       LL &now = dp1[i][u0][last];       if (!have[i - 1] || last != 0) {        now = (now + dp1[i - 1][u0 - (last == 0)][0]) % MOD;       }       LL coe = 24 + (!have[i - 1] || last != 1);       now = (now + dp1[i - 1][u0 - (last == 0)][1] * coe) % MOD;      }     }    }    // 0    for (int i = 2; i <= n; i++) {     LL coe = 25 + !have[i - 1];     dall[i] = (dall[i - 1] * coe) % MOD;    }        LL tot = dall[n] * 26 % MOD;    for (int t0 = 0; t0 < 26; t0++) {     for (int u0 = cnt[t0] + 1; u0 <= n; u0++) {      tot = (tot - dp1[n][u0][0] - dp1[n][u0][1] * 25) % MOD;     }    }    for (int t0 = 0; t0 < 26; t0++) {     for (int t1 = t0 + 1; t1 < 26; t1++) {      for (int u0 = cnt[t0] + 1; u0 <= n; u0++) {       for (int u1 = cnt[t1] + 1; u1 <= n; u1++) {        tot = (tot + dp2[n % 2][u0][u1][0] + dp2[n % 2][u0][u1][1] + dp2[n % 2][u0][u1][2] * 24) % MOD;       }      }     }    }        cout << (tot % MOD + MOD) % MOD <<   n ;   }      int main() {    ios_base::sync_with_stdio(0); cin.tie(0);       int tc = 1;   // cin >> tc;    for (int i = 1; i <= tc; i++) {     solve();    }       return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       string a, b, c;       cin >> a >> b >> c;       int i = 0, flag = 0;       for (; i < a.size(); i++) {         if ((a[i] == c[i] || b[i] == c[i]) || (a[i] == c[i] && b[i] == c[i])) {           flag = 0;         } else {           flag = 1;           break;         }       }       if (flag == 0) {         cout <<  YES n ;       } else         cout <<  NO n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   long long A[100000 + 8], mark[20 + 8];   long long result = 0;   long long getC(int n, int k) {     if (n < k) return 0;     if (n == k) return 1;     long long result = 1;     for (long long i = max(k, n - k) + 1; i <= n; i++) result *= i;     return result / min(k, n - k);   }   int main() {     memset(mark, 0, sizeof mark);     cin >> n;     for (int i = 0; i < n; i++) {       cin >> A[i];       mark[A[i] + 10]++;     }     for (int i = 0; i <= 9; i++) result += mark[i] * mark[20 - i];     result += getC(mark[10], 2);     cout << result << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int middle(int a, int b, int c) {     if ((a <= b && b <= c) || (c <= b && b <= a))       return b;     else if ((b <= a && a <= c) || (c <= a && a <= b))       return a;     else       return c;   }   template <typename KeyType, typename ValueType>   std::pair<KeyType, ValueType> get_max(const std::map<KeyType, ValueType> &x) {     using pairtype = std::pair<KeyType, ValueType>;     return *std::max_element(x.begin(), x.end(),                              [](const pairtype &p1, const pairtype &p2) {                                return p1.second < p2.second;                              });   }   static inline bool isvowel(char ch) {     static const std::string vowels( aeiouEAIOU );     return vowels.end() != std::find(vowels.begin(), vowels.end(), ch);   }   template <typename Map>   bool map_compare(Map const &lhs, Map const &rhs) {     return lhs.size() == rhs.size() &&            std::equal(lhs.begin(), lhs.end(), rhs.begin());   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long t;     cin >> t;     while (t--) {       long long n, g, b;       cin >> n >> g >> b;       long long mid = (n + 1) / 2;       long long ans = ((mid - 1) / g) * (g + b);       if (mid % g == 0)         ans += g;       else         ans += (mid % g);       cout << max(ans, n) << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[200005];   int main() {     ios::sync_with_stdio(0);     cin.tie(NULL);     int t;     cin >> t;     for (int z = 1; z <= t; z++) {       int n;       cin >> n;       for (int i = 1; i <= n; i++) {         cin >> a[i];       }       int res = n;       for (int i = 1; i < n; i++) {         if (a[i] != a[i + 1]) {           res = 1;           break;         }       }       cout << res <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   string s;   pair<int, int> best;   map<pair<int, int>, int> visited, mark;   void dfs(int i, int x, int y) {     if (i == n) {       return;     }     if (mark[make_pair(x, y)] == 0) {       mark[make_pair(x, y)] = 1;       visited[make_pair(x, y)] = i;       pair<int, int> move;       if (s[i] ==  L ) {         dfs(i + 1, x, y - 1);         move = {0, -1};       } else if (s[i] ==  R ) {         dfs(i + 1, x, y + 1);         move = {0, 1};       } else if (s[i] ==  U ) {         dfs(i + 1, x - 1, y);         move = {-1, 0};       } else if (s[i] ==  D ) {         dfs(i + 1, x + 1, y);         move = {1, 0};       }       if (visited.count({x + move.first, y + move.second})) {         auto val = visited[make_pair(x + move.first, y + move.second)];         cerr <<  found cycle   << val << endl;         if (i - val < best.second) {           best.first = val;           best.second = i - val;         }       }     }     visited.erase(visited.find(make_pair(x, y)));   }   void solve() {     cin >> n >> s;     best = {-1, 1e9};     map<pair<int, int>, int> seen;     pair<int, int> was = {0, 0};     seen[was] = 0;     for (int i = 1; i <= n; ++i) {       if (s[i - 1] ==  L )         was.second--;       else if (s[i - 1] ==  R )         was.second++;       else if (s[i - 1] ==  U )         was.first--;       else if (s[i - 1] ==  D )         was.first++;       if (seen.count(was)) {         auto index = seen[was];         int length = i - index;         if (best.second > length) {           best.first = index;           best.second = length;         }       }       seen[was] = i;     }     if (best.first == -1) {       cout << -1 << endl;     } else {       cout << best.first + 1 <<     << best.first + best.second << endl;     }   }   int main() {     int t;     cin >> t;     while (t--) solve();   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long i, j, k, n, t;     cin >> n;     vector<long long> adj[n + 1];     vector<long long> par(n + 1, 0);     for (i = 2; i <= n; i++) {       cin >> k;       par[i] = k;       adj[k].push_back(i);     }     vector<long long> level(n + 1, 0);     level[1] = 0;     queue<long long> q;     q.push(1);     vector<bool> vis;     long long maxim = INT_MIN;     while (!q.empty()) {       long long u = q.front();       q.pop();       for (j = 0; j < adj[u].size(); j++) {         level[adj[u][j]] = level[u] + 1;         maxim = max(level[u] + 1, maxim);         q.push(adj[u][j]);       }     }     vector<long long> maxiy[maxim + 1];     for (j = 1; j <= n; j++) {       k = level[j];       maxiy[k].push_back(j);     }     vector<long long> ans(maxim + 1, 1);     k = 0;     for (j = maxim; j >= 0; j--) {       k += maxiy[j].size() % 2;     }     cout << k << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int A, D, C;   vector<int> atk, def, ciel;   bool used[110];   int partial(void) {     int N = min(A, C), i, ans = 0;     for ((i) = 0; (i) < (int)(N); (i)++)       if (atk[i] < ciel[C - 1 - i]) ans += ciel[C - 1 - i] - atk[i];     return ans;   }   int search(int x) {     int i;     for ((i) = 0; (i) < (int)(C); (i)++)       if (ciel[i] >= x && !used[i]) {         used[i] = true;         return i;       }     return -1;   }   int all(void) {     int i, defsum = 0;     for ((i) = 0; (i) < (int)(D); (i)++) {       int x = search(def[i] + 1);       if (x == -1) return 0;       defsum += ciel[x];     }     for ((i) = 0; (i) < (int)(A); (i)++) {       int x = search(atk[i]);       if (x == -1) return 0;     }     int ans = 0;     for ((i) = 0; (i) < (int)(C); (i)++) ans += ciel[i];     for ((i) = 0; (i) < (int)(A); (i)++) ans -= atk[i];     ans -= defsum;     return ans;   }   int main(void) {     int N, i, x;     cin >> N >> C;     for ((i) = 0; (i) < (int)(N); (i)++) {       string type;       cin >> type >> x;       if (type ==  ATK )         atk.push_back(x);       else         def.push_back(x);     }     for ((i) = 0; (i) < (int)(C); (i)++) {       cin >> x;       ciel.push_back(x);     }     sort(atk.begin(), atk.end());     sort(def.begin(), def.end());     sort(ciel.begin(), ciel.end());     A = atk.size();     D = def.size();     int ans1 = partial();     int ans2 = all();     cout << max(ans1, ans2) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, k, i, j, a[2 * 100010];   vector<char> ans;   int main() {     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a[i];     }     long long l = 1, r = n, f = -1e18;     while (l <= r) {       if (f >= a[l] && f >= a[r]) break;       if (a[l] <= f && f < a[r]) {         ans.push_back( R );         f = a[r];         r--;         continue;       }       if (a[l] > f && f >= a[r]) {         ans.push_back( L );         f = a[l];         l++;         continue;       }       if (a[l] < a[r]) {         ans.push_back( L );         f = a[l];         l++;       } else {         if (a[l] > a[r]) {           ans.push_back( R );           f = a[r];           r--;         } else {           int k1 = 0, k2 = 0;           for (int j = l + 1; j <= r; j++) {             if (a[j] > a[j - 1])               k1++;             else               break;           }           for (int j = r - 1; j >= l; j--) {             if (a[j] > a[j + 1])               k2++;             else               break;           }           if (k1 > k2) {             ans.push_back( L );             for (int j = l + 1; j <= r; j++) {               if (a[j] > a[j - 1])                 ans.push_back( L );               else                 break;             }           } else {             ans.push_back( R );             for (int j = r - 1; j >= l; j--) {               if (a[j] > a[j + 1])                 ans.push_back( R );               else                 break;             }           }           break;         }       }     }     cout << ans.size() <<   n ;     for (int i = 0; i < ans.size(); i++) {       cout << ans[i];     }   }


#include <bits/stdc++.h>   using namespace std;   vector<int> d[256];   int mask[256];   vector<int> q;   bool b[256];   bool good[256];   int kd[256];   vector<int> g;   vector<pair<pair<int, int>, pair<int, int> > > res;   int n;   int need;   void Debug(vector<int> A) {     for (int i = 0; i < A.size(); i++) {       printf( %d  , A[i]);     }     puts(  );   }   int read() {     char ch =    ;     int x = 0;     while (!isdigit(ch)) ch = getchar();     while (isdigit(ch)) {       x = (x << 3) + (x << 1) + ch -  0 ;       ch = getchar();     }     return x;   }   void Init() {     n = read();     for (int i = 0; i < n; i++) {       int x = read();       need = need | (1 << x);       b[x] = true;     }     if (n > 6) {       puts( 0 );       exit(0);     }     for (int i = 255; i >= 0; i--) {       good[i] = true;       int x = i;       mask[i] = 0;       while (x > 0) {         mask[i] = mask[i] | (1 << (x % 10));         if (!b[x % 10]) good[i] = false;         d[i].push_back(x % 10);         x = x / 10;       }       if (i == 0 and !b[i]) good[i] = false;       if (i == 0) {         d[i].push_back(0);         mask[i] = mask[i] | 1;       }       if (good[i]) g.push_back(i);     }   }   void Solve() {     for (int x = 0; x < 256; x++) {       if (good[x]) {         for (int y = 0; y < 256; y++) {           if (good[y]) {             for (int w = 0; w < 256; w++) {               if (good[w]) {                 if ((mask[x] | mask[y] | mask[w]) != need) continue;                 for (int z = 0; z < 256; z++) {                   if (good[z]) {                     q.clear();                     for (int i = d[x].size() - 1; i >= 0; i--)                       q.push_back(d[x][i]);                     for (int i = d[y].size() - 1; i >= 0; i--)                       q.push_back(d[y][i]);                     for (int i = d[w].size() - 1; i >= 0; i--)                       q.push_back(d[w][i]);                     for (int i = d[z].size() - 1; i >= 0; i--)                       q.push_back(d[z][i]);                     bool ok = true;                     for (int i = 0; i < q.size(); i++) {                       if (q[i] != q[q.size() - 1 - i]) {                         ok = false;                         break;                       }                     }                     if (ok)                       res.push_back(make_pair(make_pair(x, y), make_pair(w, z)));                   }                 }               }             }           }         }       }     }   }   void Print() {     printf( %d n , res.size());     for (int i = 0; i < res.size(); i++) {       printf( %d.%d.%d.%d n , res[i].first.first, res[i].first.second,              res[i].second.first, res[i].second.second);     }   }   int main() {     Init();     Solve();     Print();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct SUBS {     string _s;     int l, r;     SUBS() {}     SUBS(string s, int l, int r) : _s(s), l(l), r(r) {}     bool operator<(const SUBS& subs) const { return _s > subs._s; }   };   priority_queue<SUBS> pq;   string s;   long long n, k;   int main() {     cin >> s;     cin >> k;     n = s.length();     if (2 * k > n * (n + 1)) {       cout <<  No such line.  << endl;       return 0;     }     for (int i = 0; i < n; i++) pq.push(SUBS(s.substr(i, 1), i, i + 1));     SUBS subs;     for (int i = 0; i < k; i++) {       subs = pq.top();       pq.pop();       if (subs.r < n) {         int len = subs.r - subs.l;         pq.push(SUBS(s.substr(subs.l, len + 1), subs.l, subs.r + 1));       }     }     cout << subs._s << endl;   }


#include <bits/stdc++.h>   using namespace std;   const long double pi = 3.1415926535897932384626433832795l;   template <typename T>   inline auto sqr(T x) -> decltype(x * x) {     return x * x;   }   template <typename T1, typename T2>   inline bool umx(T1& a, T2 b) {     if (a < b) {       a = b;       return 1;     }     return 0;   }   template <typename T1, typename T2>   inline bool umn(T1& a, T2 b) {     if (b < a) {       a = b;       return 1;     }     return 0;   }   bool use[26];   int main() {     cout.setf(ios::showpoint | ios::fixed);     cout.precision(20);     string s;     getline(cin, s);     bool ok = 1;     for (int i = int(0); i < int(((int)(s).size())); ++i) {       int idx = s[i] -  a ;       if (idx > 0) {         if (!use[idx - 1]) {           ok = 0;         }       }       use[idx] = 1;     }     if (!ok) {       puts( NO );     } else {       puts( YES );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct Number {     array<int, 4> powers = {{0, 0, 0, 0}};     Number() {}     Number(int a) {       if (a != -1) powers[a]++;     }     long double log_value() const {       if (powers[0] > 0) return -INFINITY;       return powers[2] * log(2L) + powers[3] * log(3L);     }     int mod() const {       long long result = 1;       for (int i = 0; i < 4; i++)         for (int j = 0; j < powers[i]; j++)           result = (result * i) % (int)(1e9 + 7);       return result;     }     bool is_zero() const { return powers[0] > 0; }   };   bool operator<(const Number& a, const Number& b) {     return a.log_value() < b.log_value();   }   Number operator*(const Number& a, const Number& b) {     Number result;     for (int i = 0; i < 4; i++) result.powers[i] = a.powers[i] + b.powers[i];     return result;   }   Number operator/(const Number& a, const Number& b) {     Number result;     for (int i = 0; i < 4; i++) result.powers[i] = a.powers[i] - b.powers[i];     return result;   }   template <typename T>   using Matrix = vector<vector<T>>;   template <typename T>   Matrix<T> matrix(int R, int C, T x = T()) {     return Matrix<T>(R, vector<T>(C, x));   }   struct RangeProduct {     int N;     Matrix<int> grid;     Matrix<Number> hprod;     Matrix<Number> vprod;     bool valid(int r, int c) { return 0 <= r && r < N && 0 <= c && c < N; }     RangeProduct(int N, Matrix<int> grid) : N(N), grid(grid) {       hprod = matrix<Number>(N + 1, N + 1);       vprod = matrix<Number>(N + 1, N + 1);       for (int r = 0; r < N; r++)         for (int c = 0; c < N; c++) {           hprod[r][c + 1] = hprod[r][c] * grid[r][c];           vprod[r + 1][c] = vprod[r][c] * grid[r][c];         }     }     Number hquery(int r, int c, int radius) {       int c1 = c - radius, c2 = c + radius;       if (!valid(r, c1) || !valid(r, c2)) return 0;       return hprod[r][c2 + 1] / hprod[r][c1];     }     Number vquery(int r, int c, int radius) {       int r1 = r - radius, r2 = r + radius;       if (!valid(r1, c) || !valid(r2, c)) return 0;       return vprod[r2 + 1][c] / vprod[r1][c];     }     Number cross(int r, int c, int radius) {       return hquery(r, c, radius) * vquery(r, c, radius) / grid[r][c];     }     Number max_cross(int r, int c) {       int a = 0, b = N;       while (a < b) {         int mid = (a + b + 1) / 2;         if (cross(r, c, mid).is_zero())           b = mid - 1;         else           a = mid;       }       return cross(r, c, a);     }   };   Number solve(int N, Matrix<int> grid) {     RangeProduct rp(N, grid);     Number result(0);     for (int r = 0; r < N; r++)       for (int c = 0; c < N; c++) result = max(result, rp.max_cross(r, c));     return result;   }   Matrix<int> rotate(int N, const Matrix<int>& grid, int shift) {     auto ngrid = matrix<int>(N, N);     for (int r = 0; r < N; r++)       for (int c = 0; c < N; c++)         if ((r + c) % 2 == shift)           ngrid[(r + c) / 2][(r - c + N) / 2] = grid[r][c];     return ngrid;   }   int main() {     int N;     cin >> N;     auto grid = matrix<int>(N, N);     for (int i = 0; i < N; i++) {       string s;       cin >> s;       for (int j = 0; j < N; j++) grid[i][j] = s[j] -  0 ;     }     auto rgrid0 = rotate(N, grid, 0);     auto rgrid1 = rotate(N, grid, 1);     Number answer = max({solve(N, grid), solve(N, rgrid0), solve(N, rgrid1)});     cout << answer.mod() << endl;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e18;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n, m, k;     long long zero = 0;     cin >> n >> m >> k;     long long x, s;     cin >> x >> s;     long long a[m], b[m], c[k], d[k];     long long i, j;     long long ans = n * x;     for (i = 0; i < m; i++) {       cin >> a[i];     }     for (i = 0; i < m; i++) {       cin >> b[i];       if (b[i] <= s) {         ans = min(ans, n * a[i]);       }     }     for (i = 0; i < k; i++) {       cin >> c[i];     }     for (i = 0; i < k; i++) {       cin >> d[i];       if (d[i] <= s) {         ans = min(ans, x * max(zero, n - c[i]));       }     }     for (i = 0; i < m; i++) {       if (b[i] <= s) {         long long p = s - b[i];         auto it = upper_bound(d, d + k, p);         if (it != d) {           it--;         } else {           continue;         }         long long reduce = c[it - d];         reduce = min(n, reduce);         long long temp = (n - reduce) * a[i];         ans = min(ans, temp);       }     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string x;     getline(cin, x);     sort(x.begin(), x.end());     int res = unique(x.begin(), x.end()) - x.begin();     if (res % 2 == 0) {       cout <<  CHAT WITH HER! ;     } else {       cout <<  IGNORE HIM! ;     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast,no-stack-protector )   #pragma GCC target( avx )   using namespace std;   template <typename T, typename U>   inline void smin(T &a, const U &b) {     if (a > b) a = b;   }   template <typename T, typename U>   inline void smax(T &a, const U &b) {     if (a < b) a = b;   }   char gchar() {     static char tbuf1[1000], *tmp_st = tbuf1, *tmp_ed = tbuf1;     if (tmp_st == tmp_ed) {       int len = fread(tbuf1, 1, 1000, stdin);       if (len == 0) return -1;       tmp_ed = tbuf1 + len;       tmp_st = tbuf1;     }     return *(tmp_st++);   }   inline bool gn(int &x) {     char c, sg = 0;     while (c = gchar(), (c >  9  || c <  0 ) && c !=  -  && ~c)       ;     if (c == -1) return 0;     for ((c ==  -  ? sg = 1, c = gchar() : 0), x = 0; c >=  0  && c <=  9 ;          c = gchar())       x = (x << 1) + (x << 3) + c -  0 ;     if (sg) x = -x;     return 1;   }   int id[100100], LL[400400], RR[400400];   int xx, XX, yy, YY, zz, ZZ;   int Xmn = 100100, Ymn = 100100, Zmn = 100100, Xmx, Ymx, Zmx;   int x[100100], y[100100], z[100100], xmn[400400], xmx[400400], ymn[400400],       ymx[400400];   vector<int> vec[400400];   inline void select(int L, int mid, int R, int *val) {     R--;     while (L + 1 <= R) {       if (L + 1 == R) {         if (val[id[L]] > val[id[R]]) swap(id[L], id[R]);         return;       }       int S = L + 1, X = S + rand() * rand() % (R - L);       swap(id[L], id[X]);       if (val[id[L]] > val[id[R]]) swap(id[L], id[R]);       if (val[id[L]] > val[id[S]]) swap(id[L], id[S]);       if (val[id[S]] > val[id[R]]) swap(id[S], id[R]);       int i = L, j = R, p = val[id[S]];       while (1) {         while (i <= R && val[id[i]] <= p) i++;         while (j >= L && val[id[j]] >= p) j--;         if (i > j) break;         swap(id[i], id[j]);       }       if (mid <= j)         R = j;       else if (mid >= i)         L = i;       else         break;     }   }   inline void build(int u, int L, int R, int dp = 0) {     LL[u] = L, RR[u] = R;     if (L + 1 == R) {       xmn[u] = xmx[u] = x[id[L]];       ymn[u] = ymx[u] = y[id[L]];       vec[u].push_back(z[id[L]]);       return;     }     int ls = u << 1, rs = ls | 1, mid = L + R >> 1;     if (dp)       select(L, mid, R, x);     else       select(L, mid, R, y);     dp ^= 1;     build(ls, L, mid, dp);     build(rs, mid, R, dp);     for (int i = 0, j = 0, mn;;) {       mn = i < vec[ls].size() ? vec[ls][i] : 100100;       if (j < vec[rs].size() && mn >= vec[rs][j])         vec[u].push_back(vec[rs][j++]);       else if (mn < 100100)         vec[u].push_back(vec[ls][i++]);       else         break;     }     xmn[u] = min(xmn[ls], xmn[rs]), xmx[u] = max(xmx[ls], xmx[rs]);     ymn[u] = min(ymn[ls], ymn[rs]), ymx[u] = max(ymx[ls], ymx[rs]);   }   inline bool calc(int u) {     if (xmx[u] < xx || xmn[u] > XX || ymx[u] < yy || ymn[u] > YY) return false;     if (xx <= xmn[u] && xmx[u] <= XX && yy <= ymn[u] && ymx[u] <= YY) {       return upper_bound(vec[u].begin(), vec[u].end(), ZZ) -              lower_bound(vec[u].begin(), vec[u].end(), zz);     }     if (LL[u] + 1 == RR[u]) return false;     int ls = u << 1;     if (calc(ls)) return true;     return calc(ls | 1);   }   inline bool in(int x, int y, int z) {     return Xmn <= x && x <= Xmx && Ymn <= y && y <= Ymx && Zmn <= z && z <= Zmx;   }   int main() {     srand(time(0));     int n, m, k;     for (int i = 2; i--;) gn(n), gn(m), gn(k);     while (n--) {       gn(xx), smin(Xmn, xx), smax(Xmx, xx);       gn(yy), smin(Ymn, yy), smax(Ymx, yy);       gn(zz), smin(Zmn, zz), smax(Zmx, zz);     }     for (int i = 0; i < m; i++) {       gn(x[i]), gn(y[i]), gn(z[i]);       if (in(x[i], y[i], z[i])) return puts( INCORRECT );       id[i] = i;     }     if (m) build(1, 0, m);     puts( CORRECT );     while (k--) {       int x, y, z;       gn(x), gn(y), gn(z);       if (in(x, y, z))         puts( OPEN );       else if (m) {         xx = min(Xmn, x), XX = max(Xmx, x);         yy = min(Ymn, y), YY = max(Ymx, y);         zz = min(Zmn, z), ZZ = max(Zmx, z);         if (calc(1))           puts( CLOSED );         else           puts( UNKNOWN );       } else         puts( UNKNOWN );     }   }


#include <bits/stdc++.h>   using namespace std;   int Min(int aa, int bb) { return aa < bb ? aa : bb; }   int Max(int aa, int bb) { return aa > bb ? aa : bb; }   struct hh {     int aaa, bbb;   } cc[200005];   char ss[200005];   bool cmp(hh xa, hh ya) { return xa.aaa < ya.aaa; };   int main() {     int n, a[200005], cnt = 0;     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     scanf( %s , ss);     for (int i = 1; i <= n; i++)       if (a[i] != i) {         cc[++cnt].aaa = Min(i, a[i]);         cc[cnt].bbb = Max(i, a[i]);       }     int lst = 0;     sort(cc + 1, cc + 1 + cnt, cmp);     for (int i = 1; i <= cnt; i++) {       lst = Max(lst, cc[i].aaa);       for (; lst < cc[i].bbb; lst++) {         if (ss[lst - 1] ==  0 ) {           printf( NO );           return 0;         }       }     }     printf( YES );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool isPrime(int n) {     if (n <= 1) return false;     for (int i = 2; i < n; i++)       if (n % i == 0) return false;     return true;   }   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       int sum = 0;       vector<long long> a(n + 1, 0);       long long odd = -1;       for (int i = 1; i <= n; i++) {         cin >> a[i];         sum += a[i];         if (a[i] & 1) odd = i;       }       if (isPrime(sum)) {         cout << n - 1 << endl;         for (int i = 1; i <= n; i++) {           if (i == odd) continue;           cout << i <<    ;         }         cout << endl;       } else {         cout << n << endl;         for (int i = 1; i <= n; i++) {           cout << i <<    ;         }         cout << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int r, c, i;     cin >> r >> c;     string s;     int R[11] = {0}, C[11] = {0};     for (i = 0; i < r; ++i) {       cin >> s;       for (int j = 0; j < c; ++j) {         if (s[j] ==  S ) {           R[i] = 1;           C[j] = 1;         }       }     }     int count = 0;     for (i = 0; i < r; ++i) {       for (int j = 0; j < c; ++j) {         if (R[i] == 0 || C[j] == 0) {           count += 1;         }       }     }     cout << count;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1000 * 300 + 100;   vector<pair<int, int> > v[N], e;   pair<int, int> dir[N];   bool mark[N], mark2[N], use[N];   void sfd(int p) {     mark2[p] = true;     for (int i = 0; i < v[p].size(); i++) {       int id = v[p][i].second, q = v[p][i].first;       if (use[id] == false && mark2[q] == false) {         use[id] = true;         dir[id].first = q;         dir[id].second = p;         sfd(q);       } else if (dir[id].first == q && mark2[q] == false) {         sfd(q);       }     }   }   void dfs(int p) {     mark[p] = true;     for (int i = 0; i < v[p].size(); i++) {       int id = v[p][i].second, q = v[p][i].first;       if (mark[q] == false) {         dir[id].first = p;         dir[id].second = q;         use[id] = true;         dfs(q);       }     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n, m;     cin >> n >> m;     for (int i = 0; i < m; i++) {       int a, b;       cin >> a >> b;       v[a].push_back(make_pair(b, i));       v[b].push_back(make_pair(a, i));       e.push_back(make_pair(a, b));     }     dfs(1);     sfd(1);     for (int i = 1; i <= n; i++)       if (mark[i] == false || mark2[i] == false) {         cout << 0;         return 0;       }     for (int i = 0; i < m; i++) {       if (use[i])         cout << dir[i].first <<     << dir[i].second <<   n ;       else         cout << e[i].first <<     << e[i].second <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, a[110][110];   bool equal_row(int i, int k) {     for (int j = 0; j < m; j++)       if (a[i][j] != a[k][j]) return false;     return true;   }   bool can(int from, int mid, int end) {     int i = mid - 1, k = mid;     while (i >= 0 && k < end) {       if (!equal_row(i, k)) return false;       i--, k++;     }     return true;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> n >> m;     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) cin >> a[i][j];     if (n & 1)       cout << n <<   n ;     else {       int ans = n;       int end = n;       while (ans % 2 == 0) {         int mid = ans / 2;         if (!can(0, mid, end) || mid == 0) break;         ans = mid;         end = mid;       }       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int T, n, m, sum, tot;   struct P {     int val, x, y;   } a[500];   struct R {     int x, y;   } b[10];   bool cmp1(const P& a, const P& b) { return a.val > b.val; }   bool cmp2(const R& a, const R& b) { return a.y > b.y; }   bool Judge(int i, int j, int k, int u) {     int num[5], tmp = 1;     memset(num, 0, sizeof(num));     b[1].x = a[i].x, b[1].y = a[i].y;     b[2].x = a[j].x, b[2].y = a[j].y;     b[3].x = a[k].x, b[3].y = a[k].y;     b[4].x = a[u].x, b[4].y = a[u].y;     sort(b + 1, b + 4 + 1, cmp2);     num[1]++;     for (int l = 2; l <= 4; l++)       if (b[l].y == b[l - 1].y)         num[tmp]++;       else         num[tmp + 1]++, tmp++;     if (num[1] > num[2]) swap(num[1], num[2]);     if (tmp != 2 || num[1] == 1 && num[2] == 3) return true;     int t1 = abs(b[1].x - b[2].x), t2 = abs(b[3].x - b[4].x);     if (t1 < t2) swap(t1, t2);     if (t1 == 3 && t2 == 2 || t1 == 2 && t2 == 1) return false;     return true;   }   int main() {     scanf( %d , &T);     while (T--) {       sum = tot = 0;       scanf( %d%d , &n, &m);       for (int i = 1; i <= n; i++)         for (int j = 1; j <= m; j++) {           scanf( %d , &a[++tot].val);           a[tot].x = i;           a[tot].y = j;         }       sort(a + 1, a + tot + 1, cmp1);       if (n <= 3 || n == 4 && m == 1) {         for (int i = 1; i <= n; i++) sum += a[i].val;         printf( %d n , sum);         continue;       }       for (int i = 1; i <= 8; i++)         for (int j = i + 1; j <= 8; j++)           for (int k = j + 1; k <= 8; k++)             for (int u = k + 1; u <= 8; u++)               if (Judge(i, j, k, u))                 sum = max(sum, a[i].val + a[j].val + a[k].val + a[u].val);       printf( %d n , sum);     }   }


#include <bits/stdc++.h>   using namespace std;   vector<int> a(201), b(201);   int n, m;   int dp[201][2000];   int fun(int ind, int val) {     if (ind >= n) return val;     if (dp[ind][val] != (-1)) return dp[ind][val];     int i, temp = INT_MAX, j;     for (i = 0; i < m; i++) {       j = fun(ind + 1, ((a[ind] & b[i]) | val));       temp = min(temp, j);     }     return dp[ind][val] = temp;   }   int main() {     int i, j;     cin >> n >> m;     for (i = 0; i < n; i++) cin >> a[i];     for (i = 0; i < m; i++) cin >> b[i];     for (i = 0; i < n; i++)       for (j = 0; j < 2000; j++) dp[i][j] = (-1);     cout << fun(0, 0);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 300020;   inline int read() {     int s = 0, w = 1;     char ch = getchar();     while (ch >  9  || ch <  0 ) {       if (ch ==  - ) w = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) s = s * 10 + ch -  0 , ch = getchar();     return s * w;   }   int T, n;   char x[N];   int main() {     T = read();     while (T--) {       n = read();       scanf( %s , x);       int c1 = 0, c2 = 0, c3 = 0;       for (int i = 0; i < n; i++) {         if (x[i] ==  > ) c1++;         if (x[i] ==  < ) c2++;         if (x[i] ==  -  || x[(i + 1) % n] ==  - ) c3++;       }       if (c1 != 0 && c2 != 0)         printf( %d n , c3);       else         printf( %d n , n);     }     return 0;   }


#include<cstdio>   #include<cstring>   #include<algorithm>   using namespace std;   int t,n,m,f[100005];   int main()   {    scanf( %d ,&t);    while(t--)    {     memset(f,0,sizeof(f));     scanf( %d%d ,&n,&m);     for(int i=1;i<=n;i++)      for(int j=1;j<=m;j++)      {       int x;       scanf( %d ,&x);       f[i+j]^=x;      }     int fl=0;     for(int i=1;i<=n+m;i++)      if(f[i]) fl=1;     if(fl) printf( Ashish n );     else printf( Jeel n );    }    return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<long long> v[70];   int n;   long long ans[100010], cur = 0;   int main() {     cin >> n;     for (int i = 1; i <= n; i++) {       long long x;       cin >> x;       for (int j = 60; j >= 0; j--)         if ((x >> j) & 1) {           v[j].push_back(x);           break;         }     }     for (int i = 1; i <= n; i++) {       bool flag = 0;       for (int j = 0; j <= 60; j++)         if (!(cur & (1ll << j)) && !v[j].empty()) {           cur ^= (ans[i] = v[j].back());           v[j].pop_back();           flag = 1;           break;         }       if (!flag) {         cout <<  No  << endl;         return 0;       }     }     cout <<  Yes  << endl;     for (int i = 1; i <= n; i++) cout << ans[i] <<    ;     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     long long int n, ans, c = 1, i;     cin >> t;     while (t--) {       cin >> n;       c = 1, ans = 0, i = 1;       while (n > 0) {         if (n <= 4) {           if (i % 2 != 0) {             ans = ans + max(c, n - 1);           } else             ans += n - max(c, n - 1);           break;         } else if (n > 4 && (n % 2 != 0 || n % 4 == 0)) {           if (i % 2 != 0) ans = ans + 1;           i++;           n--;         } else {           if (i % 2 != 0) {             ans = ans + n / 2;           }           i++;           n = n / 2;         }       }       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> v[200001];   int deg[200001];   bool vis[200001];   void dfs(int s) {     vis[s] = 1;     deg[s] = 1;     for (auto i : v[s]) {       if (vis[i]) continue;       dfs(i);       deg[s] += deg[i];     }   }   void solve(int s) {     for (auto i : v[s])       if (deg[i] % 2 == 0) solve(i);     cout << s <<   n ;     for (auto i : v[s])       if (deg[i] % 2 == 1) solve(i);   }   int main() {     int n;     cin >> n;     if (n % 2 == 0) {       cout <<  NO n ;       return 0;     }     cout <<  YES n ;     int rt;     for (int i = 1; i <= n; i++) {       int x;       cin >> x;       if (x == 0)         rt = i;       else         v[x].push_back(i);     }     dfs(rt);     solve(rt);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n, h;     cin >> n >> h;     vector<int> v(n);     for (auto &a : v) cin >> a;     int res = 0;     for (int i = 0; i < n; i++) {       if (v[i] <= h)         res++;       else         res += 2;     }     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void rip() {     cout << -1;     exit(0);   }   set<int> st;   set<int> seen;   vector<int> ans;   int main() {     int N;     cin >> N;     for (int i = 1; i <= N; i++) {       int x;       cin >> x;       if (x > 0) {         if (!seen.insert(x).second) rip();         st.insert(x);       } else {         if (st.find(-x) == st.end()) rip();         st.erase(-x);       }       if (st.empty()) {         ans.push_back(i);         seen.clear();       }     }     if (ans.empty() || ans.back() != N) rip();     assert(st.empty());     cout << ans.size() <<   n ;     for (int i = 0; i < ans.size(); i++)       cout << ans[i] - (i == 0 ? 0 : ans[i - 1]) <<    ;   }


#include <bits/stdc++.h>   using namespace std;   int n, mz;   char tmp;   bool t[51][51];   bool m[51][51];   int mel, skm;   bool atr;   bool state;   void apstaig(int x, int y) {     int i, j, z;     for (i = x; i <= mz; i++) {       if (t[i][y] == false)         break;       else {         m[i][y] = !state;         skm++;         j = y - 1;         while (j > 0) {           if (t[i][j] == false)             break;           else {             if (m[i][j] == state) {               m[i][j] = !state;               skm++;             }           }           j--;         }         j = y + 1;         while (j <= n) {           if (t[i][j] == false)             break;           else {             if (m[i][j] == state) {               m[i][j] = !state;               skm++;             }           }           j++;         }       }     }     for (i = x - 1; i > 0; i--) {       if (t[i][y] == false)         break;       else {         m[i][y] = !state;         skm++;         j = y - 1;         while (j > 0) {           if (t[i][j] == false)             break;           else {             if (m[i][j] == state) {               m[i][j] = !state;               skm++;             }           }           j--;         }         j = y + 1;         while (j <= n) {           if (t[i][j] == false)             break;           else {             if (m[i][j] == state) {               m[i][j] = !state;               skm++;             }           }           j++;         }       }     }     for (i = y - 1; i > 0; i--) {       if (t[x][i] == false)         break;       else {         if (m[x][i] == state) {           m[j][i] = !state;           skm++;         }         j = x - 1;         while (j > 0) {           if (t[j][i] == false)             break;           else {             if (m[j][i] == state) {               m[j][i] = !state;               skm++;             }           }           j--;         }         j = x + 1;         while (j <= mz) {           if (t[j][i] == false)             break;           else {             if (m[j][i] == state) {               m[j][i] = !state;               skm++;             }           }           j++;         }       }     }     for (i = y + 1; i <= n; i++) {       if (t[x][i] == false)         break;       else {         if (m[x][i] == state) {           m[j][i] = !state;           skm++;         }         j = x - 1;         while (j > 0) {           if (t[j][i] == false)             break;           else {             if (m[j][i] == state) {               m[j][i] = !state;               skm++;             }           }           j--;         }         j = x + 1;         while (j <= mz) {           if (t[j][i] == false)             break;           else {             if (m[j][i] == state) {               m[j][i] = !state;               skm++;             }           }           j++;         }       }     }   }   int main() {     int i, j;     cin >> n >> mz;     mel = 0;     for (i = 1; i <= n; i++)       for (j = 1; j <= mz; j++) {         cin >> tmp;         if (tmp ==  B ) {           t[j][i] = true;           mel++;           m[j][i] = false;         } else           t[j][i] = false;       }     atr = true;     state = false;     for (i = 1; i <= n; i++)       for (j = 1; j <= mz; j++) {         if (t[j][i] == true) {           skm = 0;           apstaig(j, i);           if (skm != mel) {             atr = false;             break;           }           state = !state;         }       }     if (atr)       cout <<  YES ;     else       cout <<  NO ;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 5e3 + 10, INF = 0x3f3f3f3f;   struct edge {     int x;     int y;   } e[maxn];   int w[maxn][maxn];   int num[maxn];   vector<int> vec[maxn];   int depth[maxn];   int fa[maxn];   void dfs(int cur, int p, int dep) {     fa[cur] = p;     depth[cur] = dep;     for (int x : vec[cur]) {       if (x != p) {         dfs(x, cur, dep + 1);       }     }     num[cur] = INF;   }   bool lca_modify(int x, int y, int k) {     int minn = INF;     if (depth[x] < depth[y]) swap(x, y);     while (depth[x] != depth[y]) {       if (num[x] == INF) {         num[x] = k;         w[x][fa[x]] = w[fa[x]][x] = k;       }       minn = min(minn, num[x]);       x = fa[x];     }     while (x != y) {       if (num[x] == INF) {         num[x] = k;         w[x][fa[x]] = w[fa[x]][x] = k;       }       minn = min(minn, num[x]);       x = fa[x];       if (num[y] == INF) {         num[y] = k;         w[y][fa[y]] = w[fa[y]][y] = k;       }       minn = min(minn, num[y]);       y = fa[y];     }     return minn == k;   }   const int maxm = 5e3 + 10;   struct query {     int x, y, len;   } q[maxm];   bool cmp(query a, query b) { return a.len > b.len; }   int main() {     int n, m;     cin >> n;     for (int i = 0; i < n - 1; i++) {       int x, y;       cin >> x >> y;       e[i].x = x, e[i].y = y;       vec[x].push_back(y);       vec[y].push_back(x);     }     dfs(1, 0, 1);     cin >> m;     int x, y, len;     for (int i = 1; i <= m; i++) {       cin >> x >> y >> len;       q[i].x = x, q[i].y = y, q[i].len = len;     }     sort(q + 1, q + 1 + m, cmp);     int flag = 1;     for (int i = 1; i <= m; i++) {       x = q[i].x, y = q[i].y, len = q[i].len;       if (lca_modify(x, y, len) == false) {         flag = 0;         break;       }     }     if (!flag) {       cout << -1 << endl;     } else {       for (int i = 0; i < n - 1; i++) {         x = e[i].x, y = e[i].y;         if (x > y) swap(x, y);         if (w[x][y] == 0)           cout << 1000000;         else           cout << w[x][y];         if (i != n - 2)           cout <<    ;         else           cout << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int L = 20, N = 1e6 + 5;   const long long MOD = 1e9 + 7;   int dp[1 << L], n;   long long pow2[N];   int main() {     scanf( %d , &n);     int a;     for (int i = (int)1; i <= n; i++) {       scanf( %d , &a);       dp[a]++;     }     pow2[0] = 1;     for (int i = (int)1; i <= N - 1; i++) pow2[i] = pow2[i - 1] * 2 % MOD;     for (int i = (int)0; i <= L - 1; i++)       for (int msk = (int)0; msk <= (1 << L) - 1; msk++)         if (msk >> i & 1 ^ 1) dp[msk] += dp[msk ^ (1 << i)];     for (int msk = (int)0; msk <= (1 << L) - 1; msk++) {     }     long long ans = (pow2[dp[0]] - 1 + MOD) % MOD;     for (int msk = (int)1; msk <= (1 << L) - 1; msk++) {       if (dp[msk] == 0) continue;       if (__builtin_popcount(msk) % 2) {         ans = (ans - pow2[dp[msk]] + 1 + MOD) % MOD;       } else {         ans = (ans + pow2[dp[msk]] - 1 + MOD) % MOD;       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   const int INF = 107374182;   using namespace std;   int n, k;   int ans[100005][2];   struct sa {     int ma, mi;   } segTree[1000000];   void build(int l, int r, int root) {     if (l == r) {       if (l != n + 1) {         scanf( %d , &segTree[root].ma);         segTree[root].mi = segTree[root].ma;       } else {         segTree[root].ma = 0;         segTree[root].mi = INF;       }       return;     }     int mid = (l + r) >> 1;     build(l, mid, root << 1);     build(mid + 1, r, (root << 1) | 1);     segTree[root].ma = max(segTree[root << 1].ma, segTree[(root << 1) | 1].ma);     segTree[root].mi = min(segTree[root << 1].mi, segTree[(root << 1) | 1].mi);   }   sa query(int L, int R, int l, int r, int root) {     if (L <= l && r <= R) {       return segTree[root];     }     sa ans, temp;     if (l == r) {       temp.ma = 0;       temp.mi = INF;       return temp;     }     int mid = (l + r) >> 1;     ans.ma = 0;     ans.mi = INF;     if (L <= mid) {       temp = query(L, R, l, mid, root << 1);       ans.ma = max(ans.ma, temp.ma);       ans.mi = min(ans.mi, temp.mi);     }     if (R > mid) {       temp = query(L, R, mid + 1, r, (root << 1) | 1);       ans.ma = max(ans.ma, temp.ma);       ans.mi = min(ans.mi, temp.mi);     }     return ans;   }   int main() {     scanf( %d%d , &n, &k);     {       build(1, n, 1);       int maxlength = 0, cnt = 0;       sa tempx, tempy;       for (int i = 1; i <= n; i++) {         int l = i, r = n + 1;         while (r > l + 1) {           int mid = (l + r) >> 1;           tempx = query(i, mid + 1, 1, n, 1);           if (tempx.ma - tempx.mi > k)             r = mid;           else             l = mid;         }         tempx = query(i, l, 1, n, 1);         tempy = query(i, r, 1, n, 1);         if (tempx.ma - tempx.mi <= tempy.ma - tempy.mi &&             tempy.ma - tempy.mi <= k && l < n)           l++;         if (maxlength < l - i + 1) {           maxlength = l - i + 1;           ans[0][0] = i;           ans[0][1] = l;           cnt = 1;         } else if (maxlength == l - i + 1) {           ans[cnt][0] = i;           ans[cnt++][1] = l;         }       }       printf( %d %d n , maxlength, cnt);       for (int i = 0; i < cnt; i++) {         printf( %d %d n , ans[i][0], ans[i][1]);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct two {     long long int f, s;   };   signed main() {     long long int n;     cin >> n;     map<string, set<string> > mp;     while (n--) {       string str;       cin >> str;       for (long long int i = 0; i < str.size(); i++) {         string tmp =   ;         for (long long int j = i; j < str.size(); j++) {           tmp += str[j];           mp[tmp].insert(str);         }       }     }     long long int q;     cin >> q;     while (q--) {       string str;       cin >> str;       if (mp.find(str) != mp.end())         cout << mp[str].size() <<     << *mp[str].begin() << endl;       else         cout << 0 <<     <<  -  << endl;     }   }


#include <bits/stdc++.h>   inline long long read() {     long long x = 0, f = 1;     char c = getchar();     for (; c >  9  || c <  0 ; c = getchar()) {       if (c ==  - ) f = -1;     }     for (; c >=  0  && c <=  9 ; c = getchar()) {       x = x * 10 + c -  0 ;     }     return x * f;   }   int cnt[27][105];   char s[105], s1[105];   std::string sss, halfans, halfans2;   std::vector<char> ans;   std::map<std::string, int> H1[105], H2[105];   inline char getA(std::string a, std::string b) {     int c[30];     memset(c, 0, sizeof c);     for (int i = 0; i < a.size(); i++) c[a[i] -  a ]++;     for (int i = 0; i < b.size(); i++) c[b[i] -  a ]--;     for (int i = 0; i < 26; i++) {       if (c[i] > 0) return i +  a ;     }     return  a ;   }   inline std::string solve(int n) {     printf( ? 1 %d n , n);     fflush(stdout);     for (int i = 1; i <= n * (n + 1) >> 1; i++) {       scanf( %s , s);       sss = std::string(s);       std::sort(sss.begin(), sss.end());       H1[sss.size()][sss]++;     }     printf( ? 2 %d n , n);     fflush(stdout);     for (int i = 1; i <= n * (n - 1) >> 1; i++) {       scanf( %s , s);       sss = std::string(s);       std::sort(sss.begin(), sss.end());       H2[sss.size()][sss]++;     }     for (int i = 1; i <= n; i++) {       for (auto p : H2[i]) {         H1[i][p.first] -= H2[i][p.first];       }       for (auto p : H1[i]) {         if (p.second > 0) {           std::string new1 = (  );           for (int j = 0; j < ans.size(); j++) new1 += ans[j];           ans.push_back(getA(p.first, new1));         }       }     }     std::string new1 = (  );     for (int j = 0; j < ans.size(); j++) new1 += ans[j];     return new1;   }   inline void work() {     int n = read();     if (n == 1) {       puts( ? 1 1 );       fflush(stdout);       scanf( %s , s);       printf( ! %s n , s);       fflush(stdout);     } else if (n == 2) {       puts( ? 1 1 );       fflush(stdout);       scanf( %s , s);       puts( ? 2 2 );       fflush(stdout);       scanf( %s , s1);       printf( ! %s%s n , s, s1);       fflush(stdout);     } else {       halfans = solve(n + 1 >> 1);       printf( ? 1 %d n , n);       fflush(stdout);       for (int i = 1; i <= n * (n + 1) >> 1; i++) {         scanf( %s , s);         sss = std::string(s);         for (int j = 0; j < sss.size(); j++) {           cnt[sss[j] -  a ][sss.size()]++;         }       }       halfans2 = std::string(  );       for (int i = 1; i <= n >> 1; i++) {         for (int j = 0; j < 26; j++) {           int num = cnt[j][1] - (cnt[j][i + 1] - cnt[j][i]);           for (int k = 0; k < i; k++) {             if (halfans[k] -  a  == j) {               num--;             }           }           for (int k = 0; k < halfans2.size(); k++) {             if (halfans2[k] -  a  == j) {               num--;             }           }           if (num > 0) {             halfans2 += ( a  + j);             break;           }         }       }       for (int i = halfans2.size() - 1; ~i; i--) halfans += halfans2[i];       printf( ! %s n , halfans.c_str());       fflush(stdout);     }   }   int main() {     work();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 3e3 + 5, mod = 1e9 + 7;   struct p {     int x, y;   } c[N];   int n, D, num;   int h[N], w[N];   int f[N][N];   int read() {     int x(0);     char ch = getchar();     for (; !isdigit(ch); ch = getchar())       ;     for (; isdigit(ch); x = x * 10 + ch - 48, ch = getchar())       ;     return x;   }   void add(int x, int y) { c[++num] = (p){h[x], y}, h[x] = num; }   void dfs(int x = 1) {     for (int i = 1; i <= n; ++i) f[x][i] = 1;     for (int i = h[x]; i; i = c[i].x) {       dfs(c[i].y);       for (int j = 1; j <= n; ++j) f[x][j] = 1ll * f[x][j] * f[c[i].y][j] % mod;     }     for (int i = 1; i <= n; ++i) {       f[x][i] += f[x][i - 1];       if (f[x][i] >= mod) f[x][i] -= mod;     }   }   int Pow(int a, int b) {     int ans = 1;     for (; b; b >>= 1, a = 1ll * a * a % mod)       if (b & 1) ans = 1ll * ans * a % mod;     return ans;   }   int L(int x) {     int ans = 1;     for (int i = 0; i <= n; ++i)       if (x != i)         ans = (1ll * ans * (D - i) % mod * (x - i < 0 ? -1 : 1) *                    w[x - i < 0 ? i - x : x - i] % mod +                mod) %               mod;     return ans;   }   void Solve() {     if (n >= D) return void(printf( %d , f[1][D]));     int ans = 0;     for (int i = 1; i <= n; ++i) w[i] = Pow(i, mod - 2);     for (int i = 0; i <= n; ++i) {       ans += 1ll * f[1][i] * L(i) % mod;       if (ans >= mod) ans -= mod;     }     printf( %d , ans);   }   int main() {     n = read(), D = read();     for (int i = 2; i <= n; ++i) add(read(), i);     return dfs(), Solve(), 0;   }


#include <bits/stdc++.h>   using namespace std;   string to_string(char c) { return string(1, c); }   string to_string(string s) { return s; }   template <class A, class B>   string to_string(pair<A, B> p) {     return  (  + to_string(p.first) +  ,   + to_string(p.second) +  ) ;   }   template <class T>   string to_string(T v) {     bool f = true;     string res =  { ;     for (auto &x : v) {       if (!f) {         res +=  ,  ;       }       f = false;       res += to_string(x);     }     res +=  } ;     return res;   }   void DBG() { cerr <<  ]  << endl; }   template <class H, class... T>   void DBG(H h, T... t) {     cerr << to_string(h);     if (sizeof...(t)) cerr <<  ,  ;     DBG(t...);   }   string getCode(char c) {     string res;     if (c ==  > ) {       res =  1000 ;     } else if (c ==  < ) {       res =  1001 ;     } else if (c ==  + ) {       res =  1010 ;     } else if (c ==  - ) {       res =  1011 ;     } else if (c ==  . ) {       res =  1100 ;     } else if (c ==  , ) {       res =  1101 ;     } else if (c ==  [ ) {       res =  1110 ;     } else if (c ==  ] ) {       res =  1111 ;     } else {       assert(false);     }     return res;   }   const long long mod = 1e6 + 3;   long long powmod(long long a, long long b) {     long long res = 1;     a %= mod;     assert(b >= 0);     for (; b; b >>= 1) {       if (b & 1) res = res * a % mod;       a = a * a % mod;     }     return res;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     string s;     cin >> s;     string ss;     for (char c : s) {       ss += getCode(c);     }     long long ans = 0;     int n = (int)(ss).size();     for (int i = 0; i < n; i++) {       if (ss[i] ==  1 ) {         ans = (ans + powmod(2, n - i - 1)) % mod;       }     }     cout << ans <<   n ;     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   int i, j, k, l, x, y, z, m, n, ans, dir, s, f, current, p, q;   pair<int, int> a;   pair<int, pair<int, int> > spies[300000];   int main() {     scanf( %d %d %d %d , &n, &m, &s, &f);     for (i = 0; i < m; i++) {       scanf( %d %d %d , &x, &y, &z);       a = make_pair(y, z);       spies[i] = make_pair(x, a);     }     if (s > f)       dir = -1;     else       dir = 1;     current = s;     i = 0;     j = 1;     while (current != f) {       a = spies[i].second;       x = spies[i].first;       if (x == j) {         i++;         y = a.first;         z = a.second;         p = current;         q = current + dir;         if ((p >= y && p <= z) || (q >= y && q <= z)) {           printf( X );         } else {           current = current + dir;           if (dir == 1)             printf( R );           else             printf( L );         }       } else {         current = current + dir;         if (dir == 1)           printf( R );         else           printf( L );       }       j++;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<pair<int, int> > E[200005];   int U[200005], V[200005], D[200005];   int n, m;   int vs[200005];   queue<int> q;   int dfs(int u, int in) {     q.push(u);     for (int len = 0;; len++) {       int sz = q.size();       if (sz == 0) break;       in = len % 2;       for (int i = 0; i < sz; i++) {         u = q.front();         q.pop();         if (vs[u] != -1) {           if (vs[u] != in)             return false;           else             continue;         }         vs[u] = in;         for (auto e : E[u]) {           if (vs[e.first] == -1)             q.push(e.first);           else if (vs[e.first] != in ^ 1)             return false;         }       }     }     for (int i = 0; i < m; i++) {       if (vs[U[i]] == 0 && vs[V[i]] == 1) {         D[i] = 1;       } else if (vs[U[i]] == 1 && vs[V[i]] == 0) {         D[i] = 0;       } else         assert(1 == 2);     }     return true;   }   int main() {     memset(vs, -1, sizeof(vs));     scanf( %d%d , &n, &m);     for (int i = 0; i < m; i++) {       scanf( %d%d , &U[i], &V[i]);       D[i] = -1;       E[U[i]].push_back(make_pair(V[i], i));       E[V[i]].push_back(make_pair(U[i], i));     }     if (dfs(1, 0)) {       printf( YES n );       for (int i = 0; i < m; i++) printf( %d , D[i]);       printf(  n );     } else {       printf( NO n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b);   long long nCr(long long n, long long r);   long long pow(long long b, long long n);   void read(long long a[], long long n);   void solve() {     long long n;     cin >> n;     vector<long long> v;     for (long long i = 2; i * i <= n; i++) {       if (n % i == 0) {         v.push_back(i);         n /= i;         if (v.size() == 2) {           v.push_back(n);           break;         }       }     }     if (v.size() != 3) {       cout <<  NO  << endl;       return;     }     if (v[0] != v[1] && v[0] != v[1] && v[1] != v[2]) {       cout <<  YES  << endl;       cout << v[0] <<     << v[1] <<     << v[2] << endl;     } else {       cout <<  NO  << endl;     }   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long t;     cin >> t;     while (t--) {       solve();     }   }   long long gcd(long long a, long long b) { return (b == 0) ? a : gcd(b, a % b); }   long long nCr(long long n, long long r) {     if (r > n) return 0;     if (r * 2 > n) r = n - r;     if (r == 0) return 1;     long long ans = n;     for (long long i = 2; i <= r; i++) {       ans *= (n - i + 1);       ans /= i;     }     return ans;   }   long long pow(long long b, long long n) {     long long p = b, ans = 1;     while (n) {       if (n & 1) {         ans *= p;       }       p *= p;       n = n >> 1;     }     return ans;   }   void read(long long a[], long long n) {     for (long long i = 0; i < n; i++) {       cin >> a[i];     }   }


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


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     string nonz;     int ans = 0;     string s =   ;     bool zr = false;     for (int i = 0; i < n; i++) {       string a;       cin >> a;       if (a ==  0 ) zr = true;       string x = a;       bool beauty = true;       int zero = 0, one = 0;       for (auto j : a) {         if (j ==  1 )           one++;         else if (j ==  0 )           zero++;         else {           beauty = false;           nonz = x;         }       }       if (one > 1) {         beauty = false;         nonz = x;       } else if (beauty) {         ans += zero;       }     }     if (!zr) {       if (nonz.size())         cout << nonz;       else         cout << 1;       for (int i = 0; i < ans; i++) {         cout << 0;       }       cout << endl;     } else {       cout << 0 << endl;     }   }


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


#include <bits/stdc++.h>   using namespace std;   bool debug = false;   int n, m, k;   long long ln, lk, lm;   int b[5105], a[5105];   void update(int x) {     for (int i = x; i <= n; i += i & -i) {       b[i]++;     }   }   int query(int x) {     int ret = 0;     for (; x > 0; ret += b[x], x -= x & -x)       ;     return ret;   }   int main() {     scanf( %d , &n);     for (int(i) = 1; (i) <= (int)(n); (i)++) {       scanf( %d , a + i);       a[i]++;     }     int tt = -((1 << 30)), cnt = 0;     pair<int, int> pp;     for (int i = n; i; i--) {       memset(b, 0, sizeof b);       for (int j = i - 1; j; j--) {         if (a[j] > a[i]) {           update(a[j]);           int x = query(a[j]) - 1;           if (x > tt) {             cnt = 1;             tt = x;             pp = {i, j};           } else if (x == tt)             cnt++;         }       }     }     swap(a[pp.first], a[pp.second]);     memset(b, 0, sizeof b);     int num = 0;     for (int(i) = 1; (i) <= (int)(n); (i)++) {       update(a[i]);       num += i - query(a[i]);     }     printf( %d %d n , num, cnt);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> adj1[1000050], adj2[1000050];   bool vis1[1000050], vis2[1000050];   vector<int> ans;   int main() {     int n, m;     scanf( %d %d , &n, &m);     for (int i = 0; i < m; i++) {       int u, v;       scanf( %d %d , &u, &v);       adj1[u].push_back(v);       adj2[v].push_back(u);     }     for (int i = n; i >= 0; i--) {       if (!vis1[i]) {         vis1[i] = true;         vis2[i] = true;         for (auto c : adj1[i]) vis1[c] = true;       }     }     for (int i = 1; i <= n; i++) {       if (vis2[i]) {         for (auto c : adj2[i]) {           if (vis2[c]) vis2[i] = false;         }         if (vis2[i]) ans.push_back(i);       }     }     printf( %d n , ans.size());     for (auto c : ans) printf( %d  , c);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a, b, c;   vector<int> ans;   int sum(int curr) {     int sum = 0;     while (curr > 0) {       sum += curr % 10;       curr = curr / 10;     }     return sum;   }   long long go(long long x, int n) {     long long ans = 1;     for (int i = 0; i < n; i++) {       ans = ans * x;     }     return ans;   }   int main() {     scanf( %d %d %d , &a, &b, &c);     for (int i = 0; i <= 81; i++) {       long long curr = go(i, a) * b + c;       if (curr > 1000000000LL || curr <= 0) continue;       if (sum(curr) == i) ans.push_back(curr);     }     printf( %d n , ans.size());     for (int i = 0; i < ans.size(); i++) {       printf( %d  , ans[i]);     }     return 0;   }


#include <bits/stdc++.h>   int a, b, c, prad[1000001];   using namespace std;   int main() {     long long pro = 0;     for (int i = 1; i < 1000001; ++i) {       for (int j = 1; j * i < 1000001; ++j) {         ++prad[j * i];       }     }     cin >> a >> b >> c;     for (int j = 1; j < a + 1; ++j)       for (int ja = 1; ja < b + 1; ++ja)         for (int ha = 1; ha < c + 1; ++ha) {           pro += prad[ha * ja * j];           long long ta = pro >> 30;           ta << 30;           pro = pro - ta;         }     cout << pro;   }


#include <bits/stdc++.h>   using namespace std;   int vis[110000];   int st[110000], top;   int main() {     int n, m, i, j, k, x;     scanf( %d , &n);     if (n & 1) {       puts( -1 );       return 0;     }     st[++top] = 0;     x = n / 2;     while (x) {       st[++top] = x;       vis[x] = 1;       if (x + n >> 1 < n && !vis[x + n >> 1])         x = x + n >> 1;       else         x = x >> 1;     }     st[++top] = 0;     while (top) printf( %d  , st[top--]);     return 0;   }


#include<bits/stdc++.h>   #define For(i,a,b) for(register int i=(a);i<=(b);++i)   #define Rep(i,a,b) for(register int i=(a);i>=(b);--i)   using namespace std;   inline int read()   {       char c=getchar();int x=0;bool f=0;       for(;!isdigit(c);c=getchar())f^=!(c^45);       for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+(c^48);       if(f)x=-x;return x;   }       #define mod 998244353   struct modint{       int x;       modint(int o=0){x=o;}       modint &operator = (int o){return x=o,*this;}       modint &operator +=(modint o){return x=x+o.x>=mod?x+o.x-mod:x+o.x,*this;}       modint &operator -=(modint o){return x=x-o.x<0?x-o.x+mod:x-o.x,*this;}       modint &operator *=(modint o){return x=1ll*x*o.x%mod,*this;}       modint &operator ^=(int b){           modint a=*this,c=1;           for(;b;b>>=1,a*=a)if(b&1)c*=a;           return x=c.x,*this;       }       modint &operator /=(modint o){return *this *=o^=mod-2;}       modint &operator +=(int o){return x=x+o>=mod?x+o-mod:x+o,*this;}       modint &operator -=(int o){return x=x-o<0?x-o+mod:x-o,*this;}       modint &operator *=(int o){return x=1ll*x*o%mod,*this;}       modint &operator /=(int o){return *this *= ((modint(o))^=mod-2);}       template<class I>friend modint operator +(modint a,I b){return a+=b;}       template<class I>friend modint operator -(modint a,I b){return a-=b;}       template<class I>friend modint operator *(modint a,I b){return a*=b;}       template<class I>friend modint operator /(modint a,I b){return a/=b;}       friend modint operator ^(modint a,int b){return a^=b;}       friend bool operator ==(modint a,int b){return a.x==b;}       friend bool operator !=(modint a,int b){return a.x!=b;}       bool operator ! () {return !x;}       modint operator - () {return x?mod-x:0;}   };   inline modint qpow(modint a,int b){return a^b;}      #define maxn 800005   const modint G=3,Ginv=modint(1)/3;   struct poly{       vector<modint>a;       modint& operator [](int i){return a[i];}       int size(){return a.size();}       void resize(int n){a.resize(n);}   };   inline poly one(){poly a;a.a.push_back(1);return a;}   int rev[maxn];   inline int ext(int n){    int k=0;    while((1<<k)<n)++k;return k;    }   inline void init(int k){    int n=1<<k;    For(i,0,n-1)rev[i]=(rev[i>>1]>>1)|((i&1)<<(k-1));   }   void ntt(poly&a,int k,int typ)   {    int n=1<<k;    For(i,0,n-1)if(i<rev[i])swap(a[i],a[rev[i]]);     for(int mid=1;mid<n;mid<<=1)    {     modint wn=(typ>0?G:Ginv)^((mod-1)/(mid<<1));     for(int r=mid<<1,j=0;j<n;j+=r){      modint w=1;      for(int k=0;k<mid;++k,w=w*wn){       modint x=a[j+k],y=w*a[j+k+mid];       a[j+k]=x+y,a[j+k+mid]=x-y;      }     }    }    if(typ<0){     modint inv=modint(1)/n;     For(i,0,n-1)a[i]*=inv;    }   }      poly operator *(poly a,poly b)   {    int n=(int)a.size()+(int)b.size()-1,k=ext(n);    a.resize(1<<k),b.resize(1<<k),init(k);    ntt(a,k,1),ntt(b,k,1);    For(i,0,(1<<k)-1)a[i]*=b[i];    ntt(a,k,-1),a.resize(n);return a;   }      int n,k;   modint fac[maxn],ifac[maxn],iv[maxn];   inline modint sign(int x){return (x&1)?(mod-1):(1);}   poly f,g,s,a,b;   inline void get_s(int n){    fac[0]=ifac[0]=1;    For(i,1,n+n)     fac[i]=fac[i-1]*i,     iv[i]=modint(1)/i,     ifac[i]=ifac[i-1]*iv[i];    int sz=n+1;    a.resize(sz),b.resize(sz);    For(i,0,n)     a[i]=sign(i)*ifac[i],     b[i]=(modint(i)^n)*ifac[i];    s=a*b; s.resize(n+1);   }      int main()   {    n=read(),k=read();    get_s(k);    modint res=0,C=1;    For(i,1,k){     if(n-i+1==0)break;     C*=(n-i+1),C/=i;     res+=s[i]*fac[i]*C*qpow(n+1,n-i);    }    cout<<res.x;       return 0;   }


#include<bits/stdc++.h>   using namespace std;      #define f first   #define s second      using ll = long long;      const int mxN = 200000;   const int lgN = 18;   const int mod = 1e9 + 7;   const ll inf = 1e15;      void solve() {           int n; cin >> n;           int a[n + 1];           int check = true;           for (int i = 1; i <= n; i++) {                   cin >> a[i];                   if (i > 1 && a[i] < a[i - 1]) check = false;           }                      if (check) cout <<  0 ;           else if (a[1] == 1 || a[n] == n) cout <<  1 ;           else if (a[1] != n || a[n] != 1) cout <<  2 ;           else cout <<  3 ;   }      int main() {           /*if (fopen( input.txt ,  r )) {                   freopen( input.txt ,  r , stdin);                   freopen( output.txt ,  w , stdout);           }*/              ios_base::sync_with_stdio(0); cin.tie(0);              int n_test = 1; cin >> n_test;           for (int test = 1; test <= n_test; test++) {                   //cout <<  Case #  << test <<  :  ;                   solve(); cout <<   n ;           }              return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100050, inf = 1e9 + 7;   struct tree {     int l, r, mid, rx, id;   } t[N << 3];   struct node {     int l, r, t, id;     bool operator<(const node &p) const {       if (l == p.l) return id < p.id;       return l < p.l;     }   } g[N << 1];   int n, m, ans[N];   vector<int> v;   int get(int x) { return lower_bound(v.begin(), v.end(), x) - v.begin() + 1; }   void pushup(int rt) { t[rt].rx = max(t[rt << 1].rx, t[rt << 1 | 1].rx); }   void build(int l, int r, int rt) {     int m = (l + r) >> 1;     t[rt].l = l;     t[rt].r = r;     t[rt].mid = m;     if (l == r) {       t[rt].rx = -inf;       return;     }     build(l, m, rt << 1);     build(m + 1, r, rt << 1 | 1);     pushup(rt);   }   void update(int pos, int id, int x, int rt) {     if (t[rt].l == t[rt].r) {       t[rt].rx = x;       t[rt].id = id;       return;     }     if (pos <= t[rt].mid) {       update(pos, id, x, rt << 1);     }     if (pos > t[rt].mid) {       update(pos, id, x, rt << 1 | 1);     }     pushup(rt);   }   int query(int pos, int x, int rt) {     if (t[rt].rx < x) return -1;     if (t[rt].l == t[rt].r) return t[rt].id;     int ans = -1;     if (pos <= t[rt].mid) {       ans = query(pos, x, rt << 1);       if (ans > 0) return ans;     }     return query(pos, x, rt << 1 | 1);   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n + m; i++) {       scanf( %d%d%d , &g[i].l, &g[i].r, &g[i].t);       g[i].id = i;       v.push_back(g[i].t);     }     sort(v.begin(), v.end());     v.erase(unique(v.begin(), v.end()), v.end());     build(1, v.size(), 1);     sort(g + 1, g + n + m + 1);     for (int i = 1; i <= n + m; i++) {       int pos = get(g[i].t);       if (g[i].id <= n) {         update(pos, g[i].id, g[i].r, 1);       } else {         ans[g[i].id - n] = query(pos, g[i].r, 1);       }     }     for (int i = 1; i <= m; i++) {       printf( %d  , ans[i]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int t, n, a[5], ans[5], f1[19491001], cxk, f2[19491001];   int mod1 = 19260817, mod2 = 233317;   string s;   inline int Read() {     int x = 0, f = 1;     char ch = getchar();     while (!isdigit(ch)) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (isdigit(ch)) {       x = (x << 3) + (x << 1) + ch -  0 ;       ch = getchar();     }     return x * f;   }   void Write(int x) {     if (x < 0) {       putchar( - );       x = -x;     }     if (x > 9) Write(x / 10);     putchar(x % 10 +  0 );   }   inline int HAsh1() {     long long last = 0;     for (int i = 1; i <= 4; ++i) {       last = last * 13331 + a[i];       last %= mod1;     }     return last;   }   inline int HAsh2() {     long long last = 0;     for (int i = 1; i <= 4; ++i) {       last = last * 13331 + a[i];       last %= mod2;     }     return last;   }   void dfs(int k, int now) {     if (f1[HAsh1()] && f2[HAsh2()]) return;     f1[HAsh1()] = f2[HAsh2()] = 1;     if (cxk) return;     if (k == n + 1) {       int minn = 2147482647;       for (register int i = 1; i <= 4; ++i) {         if (minn > a[i]) minn = a[i];       }       for (register int i = 1; i <= 4; ++i) {         if (a[i] == minn) {           ans[i] = 1;         }       }       int flag = 1;       for (register int i = 1; i <= 4; ++i)         if (!ans[i]) flag = 0;       if (flag) cxk = 1;       return;     }     if (s[k - 1] ==  G ) {       a[1]++;       dfs(k + 1, 1);     } else if (s[k - 1] ==  H ) {       a[2]++;       dfs(k + 1, 2);     } else if (s[k - 1] ==  R ) {       a[3]++;       dfs(k + 1, 3);     } else if (s[k - 1] ==  S ) {       a[4]++;       dfs(k + 1, 4);     } else {       int minn = 2147482647;       for (register int i = 1; i <= 4; ++i) {         if (minn > a[i]) minn = a[i];       }       for (register int i = 1; i <= 4; ++i) {         if (a[i] == minn) {           int a1 = a[1], a2 = a[2], a3 = a[3], a4 = a[4];           a[i]++;           dfs(k + 1, i);           a[1] = a1, a[2] = a2, a[3] = a3, a[4] = a4;         }       }     }   }   int main() {     n = Read();     cin >> s;     memset(a, 0, sizeof(a));     memset(ans, 0, sizeof(ans));     memset(f1, 0, sizeof(f1));     memset(f2, 0, sizeof(f2));     cxk = 0;     dfs(1, 0);     if (ans[1]) puts( Gryffindor );     if (ans[2]) puts( Hufflepuff );     if (ans[3]) puts( Ravenclaw );     if (ans[4]) puts( Slytherin );     putchar(  n );   }


#include <bits/stdc++.h>   using namespace std;   long long n, m, k, i, j;   string s;   int main() {     cin >> n;     cin >> s;     for (i = 1; i <= n; i++) {       if (s[i - 1] != s[i]) k++;     }     cout << min(k + 2, n);   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     int n, m;     cin >> n >> m;     vector<pair<int, int> > v;     v.resize(n * m);     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= m; ++j) {         v[m * (i - 1) + j - 1] = {i, j};       }     }     bool low = true;     int l = 0, r = m * n - 1;     while (r >= l) {       pair<int, int> u;       if (low) {         u = v[l];         l++;         low = false;       } else {         u = v[r];         r--;         low = true;       }       cout << u.first <<     << u.second <<   n ;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t = 1;     for (int i = 0; i < t; ++i) {       solve();     }   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast,inline,unroll-loops,fast-math )   using namespace std;   class Point {    public:     int x;     int y;     Point(int _x = 0, int _y = 0) : x(_x), y(_y) { return; }     Point operator-(Point that) {       return Point(this->x - that.x, this->y - that.y);     }     long long Cross(Point that) {       return (long long)this->x * that.y - (long long)this->y * that.x;     }     int Eval(int p) { return x * p + y; }   };   int n, f[102][20002];   pair<int, int> q[15][20002];   deque<Point> g[20002 << 1];   Point h[20002 << 2];   void InitSegment(int x, int l, int r) {     int m;     h[x] = Point(0, INT_MAX >> 2);     if (l == r) return;     m = (l + r) >> 1;     InitSegment(x << 1, l, m);     InitSegment(x << 1 | 1, m + 1, r);     return;   }   void InsertSegment(int x, int l, int r, int s, int t, Point v) {     int m, p[3], q[3];     if (l > t || r < s) return;     if (l >= s && r <= t) {       m = (l + r) >> 1;       p[0] = v.Eval(l);       p[1] = v.Eval(r);       p[2] = v.Eval(m);       q[0] = h[x].Eval(l);       q[1] = h[x].Eval(r);       q[2] = h[x].Eval(m);       if (l == r) {         if (p[0] <= q[0]) h[x] = v;       } else {         if (p[0] <= q[0] && p[1] <= q[1]) {           h[x] = v;           return;         }         if (p[0] > q[0] && p[1] > q[1]) return;         if (p[0] <= q[0])           if (p[2] <= q[2]) {             InsertSegment(x << 1 | 1, m + 1, r, s, t, h[x]);             h[x] = v;           } else             InsertSegment(x << 1, l, m, s, t, v);         else if (p[2] <= q[2]) {           InsertSegment(x << 1, l, m, s, t, h[x]);           h[x] = v;         } else           InsertSegment(x << 1 | 1, m + 1, r, s, t, v);       }       return;     }     m = (l + r) >> 1;     InsertSegment(x << 1, l, m, s, t, v);     InsertSegment(x << 1 | 1, m + 1, r, s, t, v);     return;   }   int MinSegment(int x, int l, int r, int p) {     int m, o;     if (l > p || r < p) return INT_MAX >> 2;     o = h[x].Eval(p);     if (l == r) return o;     m = (l + r) >> 1;     o = min(         o, min(MinSegment(x << 1, l, m, p), MinSegment(x << 1 | 1, m + 1, r, p)));     return o;   }   Point Tangent(deque<Point> &f, Point v) {     int l, m, r;     for (l = -1, r = (signed)f.size() - 1; l + 1 < r;) {       m = (l + r) / 2;       if ((f[m + 1] - f[m]).Cross(v) > 0)         l = m;       else         r = m;     }     return f[r];   }   int MaxRMQ(int l, int r) {     int t;     t = 31 - __builtin_clz(r - l + 1);     return max(q[t][l], q[t][r - (1 << t) + 1]).second;   }   int DP(int &c, int l, int r, int *f) {     int m;     Point t;     deque<Point> p, q;     if (l == r) {       g[c].clear();       g[c].push_back(Point(l, f[l]));       return c++;     }     m = MaxRMQ(l + 1, r);     p.swap(g[DP(c, l, m - 1, f)]);     t = Tangent(p, Point(1, ::q[0][m].first));     InsertSegment(1, 0, n, m, r,                   Point(::q[0][m].first, t.y - t.x * ::q[0][m].first));     q.swap(g[DP(c, m, r, f)]);     if (p.size() > q.size()) {       for (; !q.empty(); q.pop_front()) {         for (; p.size() > 1 &&                (p.back() - p[p.size() - 2]).Cross(q.front() - p.back()) < 0;              p.pop_back())           ;         p.push_back(q.front());       }       g[c].swap(p);     } else {       for (; !p.empty(); p.pop_back()) {         for (; q.size() > 1 && (q.front() - q[1]).Cross(p.back() - q.front()) > 0;              q.pop_front())           ;         q.push_front(p.back());       }       g[c].swap(q);     }     return c++;   }   int main(void) {     int k;     int i, j, c;     scanf( %d %d , &n, &k);     for (i = 1; i <= n; i++) {       scanf( %d , &q[0][i].first);       q[0][i].second = i;     }     for (i = 1; i < 15; i++)       for (j = 1; j + (1 << i) - 1 <= n; j++)         q[i][j] = max(q[i - 1][j], q[i - 1][j + (1 << (i - 1))]);     fill(f[0] + 1, f[0] + 20002, INT_MAX >> 2);     for (i = 1; i <= k; i++) {       InitSegment(1, 0, n);       DP(c = 0, 0, n, f[i - 1]);       for (j = 0; j <= n; j++) f[i][j] = MinSegment(1, 0, n, j);     }     printf( %d n , f[k][n]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long res = 1;   long long countn = 1;   void solve(long long a[], long long n) {     if (n == 0) {       res = max(countn, res);       cout << res;     } else if (a[n] >= a[n - 1]) {       countn++;       solve(a, n - 1);     } else {       res = max(countn, res);       countn = 1;       solve(a, n - 1);     }   }   int main() {     long long n;     cin >> n;     long long a[n];     for (long long i = 0; i < n; i++) {       cin >> a[i];     }     solve(a, n - 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     pair<int, int> a, b, c;     int s = 0;     cin >> a.first >> a.second >> b.first >> b.second >> c.first >> c.second;     s = a.first * a.second + b.first * b.second + c.first * c.second;     if ((int)sqrt(s + 0.0) * (int)sqrt(s + 0.0) != s) {       cout << -1;       return 0;     }     s = sqrt(s + 0.0);     if (a.first < a.second) swap(a.first, a.second);     if (b.first < b.second) swap(b.first, b.second);     if (c.first < c.second) swap(c.first, c.second);     char mp[] = { A ,  B ,  C };     if (a.first < b.first) {       swap(a, b);       swap(mp[0], mp[1]);     }     if (b.first < c.first) {       swap(mp[1], mp[2]);       swap(b, c);     }     if (a.first < b.first) {       swap(mp[0], mp[1]);       swap(a, b);     }     if (a.first == s) {       if (b.first == c.first && a.first == b.first) {         if (a.second + b.second + c.second == s) {           cout << s << endl;           for (int i = 0; i < a.second; ++i, cout << endl)             for (int j = 0; j < a.first; ++j) cout << mp[0];           for (int i = 0; i < b.second; ++i, cout << endl)             for (int j = 0; j < b.first; ++j) cout << mp[1];           for (int i = 0; i < c.second; ++i, cout << endl)             for (int j = 0; j < c.first; ++j) cout << mp[2];         }       } else if (b.second + c.second == a.first && a.second + b.first == s &&                  b.first == c.first) {         cout << s << endl;         for (int i = 0; i < a.second; ++i, cout << endl)           for (int j = 0; j < a.first; ++j) cout << mp[0];         for (int i = 0; i < b.first; ++i, cout << endl)           for (int j = 0; j < s; ++j)             if (j < b.second)               cout << mp[1];             else               cout << mp[2];       } else if (b.first + c.first == a.first && a.second + b.second == s &&                  b.second == c.second) {         cout << s << endl;         for (int i = 0; i < a.second; ++i, cout << endl)           for (int j = 0; j < a.first; ++j) cout << mp[0];         for (int i = 0; i < s - a.second; ++i, cout << endl)           for (int j = 0; j < s; ++j)             if (j < b.first)               cout << mp[1];             else               cout << mp[2];       } else if (b.first + c.second == a.first && a.second + b.second == s &&                  b.second == c.first) {         cout << s << endl;         for (int i = 0; i < a.second; ++i, cout << endl)           for (int j = 0; j < a.first; ++j) cout << mp[0];         for (int i = 0; i < s - a.second; ++i, cout << endl)           for (int j = 0; j < s; ++j)             if (j < b.first)               cout << mp[1];             else               cout << mp[2];       } else         cout << -1;     } else       cout << -1;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline void ckmax(T& x, T y) {     x = (y > x ? y : x);   }   template <typename T>   inline void ckmin(T& x, T y) {     x = (y < x ? y : x);   }   const int MAXN = 80;   const int INF = 0x3f3f3f3f;   int n, a[MAXN + 5], cnt[2], pos[MAXN + 5], cnt_pos,       ans[MAXN * (MAXN - 1) / 2 + 5];   int total, max_op;   int dp[MAXN + 5][MAXN * (MAXN - 1) / 2 + 5][MAXN + 5];   int calc(int len) { return len * (len - 1) / 2; }   int main() {     cin >> n;     for (int i = 1; i <= n; ++i) {       cin >> a[i];       cnt[a[i]]++;       if (a[i] == 1) {         pos[++cnt_pos] = i;       }     }     total = calc(cnt[0]);     max_op = calc(n);     if (!cnt[1]) {       for (int i = 0; i <= max_op; ++i) {         cout << 0 <<    ;       }       cout << endl;       return 0;     }     memset(dp, 0x3f, sizeof(dp));     for (int i = 1; i < n; ++i) {       dp[i][abs(pos[1] - i)][1] = calc(i - 1);       for (int j = 0; j <= max_op; ++j) {         for (int k = 1; k <= i && k < cnt[1]; ++k)           if (dp[i][j][k] != INF) {             int rest = cnt[1] - k;             for (int l = i + 1; l <= n - rest + 1; ++l) {               int newj = j + abs(pos[k + 1] - l);               if (newj <= max_op)                 ckmin(dp[l][newj][k + 1], dp[i][j][k] + calc(l - i - 1));             }           }       }     }     for (int i = 0; i <= max_op; ++i) ans[i] = total;     for (int i = cnt[1]; i <= n; ++i) {       for (int j = 0; j <= max_op; ++j) {         ckmin(ans[j], dp[i][j][cnt[1]] + calc(n - i));       }     }     for (int i = 0; i <= max_op; ++i) {       if (i) ckmin(ans[i], ans[i - 1]);       cout << total - ans[i] <<    ;     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   template <class T>   inline void read(T &x) {     T f = 1;     x = 0;     char s = getchar();     while (s <  0  || s >  9 ) {       if (s ==  - ) f = -1;       s = getchar();     }     while (s >=  0  && s <=  9 ) {       x = x * 10 + s -  0 ;       s = getchar();     }     x *= f;   }   const int p = 1e9 + 7;   struct Edge {     int u, v;   } e[201];   int head[101], ecnt;   inline void addedge(int u, int v) {     e[++ecnt].v = v;     e[ecnt].u = head[u];     head[u] = ecnt;   }   inline void add(int u, int v) {     addedge(u, v);     addedge(v, u);   }   int f[101][41], a, b, ans, n, k, g[101];   inline void dfs(int x, int fa) {     f[x][0] = 1;     f[x][k + 1] = 1;     for (int yny = head[x], v; yny && (v = e[yny].v); yny = e[yny].u) {       if (v == fa) continue;       dfs(v, x);       memset(g, 0, sizeof(g));       for (int i = 0; i <= 2 * k; i++)         for (int j = 0; j <= 2 * k; j++) {           if ((i + j) > (2 * k))             (g[std::max(i, j + 1)] += 1ll * f[x][i] * f[v][j] % p) %= p;           else             (g[std::min(i, j + 1)] += 1ll * f[x][i] * f[v][j] % p) %= p;         }       for (int i = 0; i <= 2 * k; i++) f[x][i] = g[i];     }   }   inline void solve() {     read(n);     read(k);     for (int i = 1; i <= n - 1; i++) read(a), read(b), add(a, b);     dfs(1, 0);     for (int i = 0; i <= k; i++) (ans += f[1][i]) %= p;     printf( %d n , ans);   }   signed main() { solve(); }


#include <bits/stdc++.h>   using namespace std;   const long long N = 10000000;   long long n, a, b;   long long dp[N + 1];   signed main() {     cin >> n >> a >> b;     dp[0] = 0;     for (long long i = 1; i <= n; i++)       if (i & 1)         dp[i] = min(dp[i - 1] + a, dp[i + 1 >> 1] + a + b);       else         dp[i] = min(dp[i - 1] + a, dp[i >> 1] + b);     cout << dp[n];     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string stringg;     string test =  new string for test ;     cin >> stringg;     int a = 5, b = 20;     int length = stringg.size();     int lower = 5 * 20;     for (int i = 1; i <= 5; i++)       for (int j = 1; j <= 20; j++) {         if (length <= i * j && i * j <= lower && i <= a) {           lower = i * j;           a = i;           b = j;         }       }     vector<vector<char> > mat(a, vector<char>(b));     for (int i = 0; i < 1000; i++) {       test +=  a ;     }     int currentcount = 0;     int zv = (lower - length) / a;     int zv2asdasd = (lower - length) % a;     bool k = 1;     cout << a <<     << b << endl;     for (int i = 0; i < 1000; i++) {       test +=  aa ;     }     for (int i = 0; i < a; i++) {       k = 1;       for (int j = 0; j < b; j++) {         if (j + 1 <= zv)           mat[i][j] =  * ;         else if (zv2asdasd != 0 && k) {           mat[i][j] =  * ;           zv2asdasd--;           k = 0;         } else {           mat[i][j] = stringg[currentcount];           currentcount++;         }         cout << mat[i][j];       }       cout << endl;     }     for (int i = 0; i < 1000; i++) {       test +=  aa ;     }     cin >> k;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool sortbysec(const pair<int, int> &a, const pair<int, int> &b);   long long int gcd(long long int a, long long int b);   int prime(int n);   long long int lcm(long long int a, long long int b) {     return (a * b) / gcd(a, b);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int t = 1;     cin >> t;     while (t--) {       string a;       cin >> a;       long long int n = a.size();       long long int k = 0;       for (int i = 0; i < n; i++) {         if (a[i] !=  0 ) k++;       }       cout << k << endl;       for (int i = 0; i < n; i++) {         if (a[i] !=  0 ) {           cout << a[i];           for (int j = i + 1; j < n; j++) cout <<  0 ;           cout <<    ;         }       }       cout << endl;     }   }   bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) {     return (a.second < b.second);   }   long long int gcd(long long int a, long long int b) {     if (b == 0) return a;     return gcd(b, a % b);   }   int prime(int n) {     int flag = 1;     for (int i = 2; i <= sqrt(n); i++) {       if (n % i == 0) {         flag = 0;         break;       }     }     return flag;   }


#include <bits/stdc++.h>   using namespace std;   int mat[1005][1005];   long long cols[1000005];   long long rows[1000005];   priority_queue<long long> pq;   int main() {     int n, m;     long long k, p;     scanf( %d %d %lld %lld , &n, &m, &k, &p);     for (int i = 0; i < n; i++) {       long long sum = 0;       for (int j = 0; j < m; j++) {         scanf( %d , &mat[i][j]);         sum += mat[i][j];       }       pq.push(sum);     }     for (int i = 1; i <= k; i++) {       long long val = pq.top();       pq.pop();       pq.push(val - p * m);       rows[i] = rows[i - 1] + val;     }     while (pq.size()) pq.pop();     for (int i = 0; i < m; i++) {       long long sum = 0;       for (int j = 0; j < n; j++) {         sum += mat[j][i];       }       pq.push(sum);     }     for (int i = 1; i <= k; i++) {       long long val = pq.top();       pq.pop();       pq.push(val - p * n);       cols[i] = cols[i - 1] + val;     }     long long ans = -1e18;     for (long long i = 0; i <= k; i++) {       ans = max(ans, rows[i] + cols[k - i] - i * (k - i) * p);     }     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long int Maxn = 2e5 + 5, N = 4e5 + 5, Mod = 1e9 + 7, Inf = 1e18,                       Log = 22;   int n, h[Maxn], r, mx;   vector<int> adj[Maxn];   bool mrk[Maxn];   bool flg[2];   void Dfs(int v, int p) {     for (int i = 0; i < adj[v].size(); i++) {       int u = adj[v][i];       if (u == p) continue;       h[u] = h[v] + 1;       if (adj[u].size() == 1) {         if (h[u] & 1) {           flg[0] = 1;         } else {           flg[1] = 1;         }       }       Dfs(u, v);     }     return;   }   void DFs(int v, int p) {     for (int i = 0; i < adj[v].size(); i++) {       int u = adj[v][i];       if (u == p) continue;       if (adj[u].size() == 1) {         mrk[v] = 1;         mx--;         continue;       }       DFs(u, v);     }     mx += mrk[v];     return;   }   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     cin >> n;     for (int i = 0; i < n - 1; i++) {       int u, v;       cin >> u >> v;       adj[u].push_back(v);       adj[v].push_back(u);       if (1 < adj[v].size())         r = v;       else if (1 < adj[u].size())         r = u;     }     Dfs(r, -1);     if (flg[0] && flg[1])       cout << 3 <<    ;     else       cout << 1 <<    ;     DFs(r, -1);     cout << n - 1 + mx <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long a[5000007], b[5000007];   long long mod = 1e9 + 7;   unsigned long long power(unsigned long long x, long long y, long long p) {     unsigned long long res = 1;     x = x % p;     while (y > 0) {       if (y & 1) res = (res * x) % p;       y = y >> 1;       x = (x * x) % p;     }     return res;   }   unsigned long long modInverse(unsigned long long n, long long p) {     return power(n, p - 2, p);   }   unsigned long long nCrModPFermat(unsigned long long n, long long r,                                    long long p) {     if (n < r) return 0;     if (r == 0) return 1;     unsigned long long fac[n + 1];     fac[0] = 1;     for (long long i = 1; i <= n; i++) fac[i] = (fac[i - 1] * i) % p;     return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) %            p;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long t = 1;     while (t--) {       long long i, j, k, l, ans = 0, count = 0, n, m, x, y;       bool flag = 0;       string s;       long long maxa = -1000000000000000, mina = 1000000000000000;       cin >> n;       for (i = 0; i < 2 * n; i++) cin >> a[i];       sort(a, a + 2 * n);       for (i = 0; i < n; i++) ans -= a[i];       for (i = n; i < 2 * n; i++) ans += a[i];       cout << ((ans % 998244353) * (nCrModPFermat(2 * n, n, 998244353))) %                   998244353            <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   void albus() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }   bool asec(long long a, long long b) { return a < b; }   bool desc(long long a, long long b) { return a > b; }   bool Asec_and_desc(pair<long long, pair<long long, long long>> a,                      pair<long long, pair<long long, long long>> b) {     if (a.first == b.first) {       if (a.second.first == b.second.first) {         return a.second.second < b.second.second;       }       return a.second.first < b.second.first;     }     return a.first > b.first;   }   bool compare(pair<long long, long long> a, pair<long long, long long> b) {     return a.second < b.second;   }   typedef struct data {     data *bit[2];     long long cnt = 0;   } trie;   trie *head;   void insert(long long x) {     trie *node = head;     for (long long i = 30; i >= 0; i--) {       long long cur = (x >> i) & 1;       if (node->bit[cur] == NULL) {         node->bit[cur] = new trie();       }       node = node->bit[cur];       node->cnt++;     }   }   long long countXor(long long x, long long q) {     trie *node = head;     long long ans = 0, sum = 0;     for (long long i = 30; i >= 0; i--) {       long long cur = (x >> i) & 1;       long long cur2 = (q >> i) & 1;       if (cur2 == 0) {         if (node->bit[!cur] != NULL) ans += node->bit[!cur]->cnt;         if (node->bit[cur] != NULL) {           node = node->bit[cur];         } else           return ans;       } else if (cur2 == 1) {         if (node->bit[!cur] != NULL)           node = node->bit[!cur];         else           return ans;       }     }     ans += node->cnt;     return ans;   }   int32_t main() {     albus();     head = new trie();     insert(0);     long long n, q;     cin >> n >> q;     vector<long long> A;     for (long long i = 1; i <= n; i++) {       long long a;       cin >> a;       A.push_back(a);     }     long long xo = 0, final = 0;     for (long long i = 0; i < A.size(); i++) {       xo ^= A[i];       final += countXor(xo, q);       insert(xo);     }     cout << final << endl;   }


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


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 3e5 + 10;   long long ans[MAXN];   int vis[MAXN], in[MAXN], worst[MAXN];   vector<int> adj[MAXN], idx[MAXN], path;   vector<pair<int, int> > bad, qs[MAXN];   struct BIT {     long long b[MAXN];     BIT() { fill(b, b + MAXN, 0); }     void upd(int p, long long v) {       for (; p < MAXN; p += (p & -p)) b[p] += v;     }     long long sum(int p) {       long long res = 0;       for (; p; p -= (p & -p)) res += b[p];       return res;     }     long long qry(int l, int r) { return sum(r) - sum(l - 1); }   };   BIT wo, cn;   void dfs(int s, int p = 0) {     vis[s] = 1;     in[s] = 1;     path.push_back(s);     for (auto v : adj[s]) {       if (v == p) continue;       if (!vis[v])         dfs(v, s);       else if (in[v]) {         int u, mi = MAXN, ma = -MAXN;         do {           u = path.back();           path.pop_back();           in[u] = 0;           ma = max(ma, u);           mi = min(mi, u);         } while (u != v);         worst[ma] = max(worst[ma], mi);       }     }   }   int main() {     int n, m;     cin >> n >> m;     for (int i = 0; i < m; i++) {       int u, v;       cin >> u >> v;       adj[u].push_back(v);       adj[v].push_back(u);     }     for (int u = 1; u <= n; u++)       if (!vis[u]) dfs(u);     int cur = 0;     for (int i = 1; i <= n; i++) {       worst[i] = max(worst[i], cur);       cur = worst[i];       wo.upd(i, worst[i]);       idx[cur].push_back(i);     }     int q;     cin >> q;     for (int i = 0; i < q; i++) {       int l, r;       cin >> l >> r;       qs[l].push_back({r, i});     }     for (int l = 1; l <= n; l++) {       for (auto i : idx[l - 1]) {         wo.upd(i, -worst[i]);         cn.upd(i, 1);       }       for (auto p : qs[l]) {         int r = p.first;         long long d = r - l + 1;         long long tot = (long long)r * (r + 1) / 2 - (long long)l * (l - 1) / 2;         tot -= wo.qry(l, r);         tot -= cn.qry(l, r) * (l - 1);         ans[p.second] = tot;       }     }     for (int i = 0; i < q; i++) cout << ans[i] <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int n, pos, l, r, ind, ans = 0, ans1 = 0, ans2 = 0;   int main(void) {     ios ::sync_with_stdio(0);     cin.tie(0);     cin >> n >> pos >> l >> r;     if (pos < l) {       ans += l - pos + 1;       if (n - r > 0) {         ans += r - l + 1;       }     } else if (pos > r) {       ans += pos - r + 1;       if (l - 1 > 0) {         ans += r - l + 1;       }     } else {       ind = pos;       if (l - 1 > 0) {         ans1 += ind - l + 1;         ind = l;       }       if (n - r > 0) {         ans1 += r - ind + 1;       }       ind = pos;       if (n - r > 0) {         ans2 += r - ind + 1;         ind = r;       }       if (l - 1 > 0) {         ans2 += ind - l + 1;       }       ans = min(ans1, ans2);     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int m, n = 0, x, y, s = 0;     cin >> m;     vector<int> c(m);     for (int i = 0; i < (int)(m); ++i) {       cin >> c[i];       n += c[i];     }     cin >> x >> y;     for (int i = 0; i < (int)(m); ++i) {       s += c[i];       if (s <= y && s >= x && n - s <= y && n - s >= x) {         cout << i + 2 << endl;         return 0;       }     }     cout << 0 << endl;   }