#include <bits/stdc++.h>   using namespace std;   const long long linf = 1e18 + 9;   const int inf = 1e9 + 9;   const long long mod = 1e9 + 7;   const int N = 4e5 + 9;   int n, u, v, ans[N], sub[N], mx[N], centroid;   vector<int> gr[N], c[N];   int dfs(int v, int f) {     sub[v] = 1;     for (int i = 0; i < gr[v].size(); i++) {       if (gr[v][i] == f) continue;       int t = dfs(gr[v][i], v);       sub[v] += t;       mx[v] = max(mx[v], t);       c[v].push_back(t);     }     if ((n - sub[v]) <= n / 2 and mx[v] <= n / 2) {       ans[v] = 1;       centroid = v;     }     return sub[v];   }   void dfs2(int v, int f, int cur, int root) {     if (v != centroid and ans[v] == 0) {       int t = c[centroid].size() - 1;       if (sub[root] == c[centroid][t]) t--;       if (t >= 0 and n - sub[v] - c[centroid][t] <= n / 2)         ans[v] = 1;       else {         if (cur - sub[v] <= n / 2)           ans[v] = 1;         else           ans[v] = 0;       }     }     if (n - sub[v] <= n / 2) cur = sub[v];     for (int i = 0; i < gr[v].size(); i++) {       if (gr[v][i] == f) continue;       if (v == centroid) root = gr[v][i];       dfs2(gr[v][i], v, cur, root);     }   }   int main() {     scanf( %d , &n);     for (int i = 1; i < n; i++) {       scanf( %d %d , &u, &v);       gr[u].push_back(v);       gr[v].push_back(u);     }     dfs(1, 0);     memset(mx, 0, sizeof mx);     for (int i = 1; i <= n; i++) c[i].clear();     dfs(centroid, 0);     for (int i = 1; i <= n; i++) sort(c[i].begin(), c[i].end());     dfs2(centroid, 0, 0, 0);     for (int i = 1; i <= n; i++) printf( %d n , ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int gcd(int x, int y) { return (y == 0 ? x : gcd(y, x % y)); }   const int N = (int)1e6 + 100;   int a[30];   int n;   int m = 0;   char s[N];   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %d , &a[i]);     for (int i = 0; i < n; i++) m += a[i];     if (n == 1) {       printf( %d n , m);       for (int i = 0; i < m; i++) s[i] =  a ;       s[m] = (char)0;       printf( %s n , s);       return 0;     }     int cntOdd = 0;     for (int i = 0; i < n; i++)       if (a[i] & 1) cntOdd++;     if (cntOdd > 1) {       printf( 0 n );       int idx = 0;       for (int i = 0; i < n; i++)         for (int j = 0; j < a[i]; j++) s[idx++] = (char)( a  + i);       s[m] = (char)0;       printf( %s n , s);       return 0;     }     if (cntOdd == 1) {       int g = 0;       for (int i = 0; i < n; i++) {         if (a[i] & 1)           g = gcd(g, a[i]);         else           g = gcd(g, a[i] / 2);       }       printf( %d n , g);       int idx = 0;       for (int i = 0; i < n; i++) {         if (a[i] & 1) continue;         for (int j = 0; j < a[i] / 2 / g; j++) s[idx++] = (char)( a  + i);       }       for (int i = 0; i < n; i++) {         if ((a[i] & 1) == 0) continue;         for (int j = 0; j < a[i] / g; j++) s[idx++] = (char)( a  + i);       }       for (int i = n - 1; i >= 0; i--) {         if (a[i] & 1) continue;         for (int j = 0; j < a[i] / 2 / g; j++) s[idx++] = (char)( a  + i);       }       int p = idx;       for (int i = p; i < m; i++) s[i] = s[i - p];       s[m] = (char)0;       printf( %s n , s);       return 0;     }     int g = 0;     for (int i = 0; i < n; i++) g = gcd(g, a[i] / 2);     printf( %d n , 2 * g);     int idx = 0;     for (int i = 0; i < n; i++)       for (int j = 0; j < a[i] / 2 / g; j++) s[idx++] = (char)( a  + i);     for (int i = n - 1; i >= 0; i--)       for (int j = 0; j < a[i] / 2 / g; j++) s[idx++] = (char)( a  + i);     int p = idx;     for (int i = p; i < m; i++) s[i] = s[i - p];     s[m] = (char)0;     printf( %s n , s);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5;   int d[maxn];   int w[maxn];   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     int n;     cin >> n;     string s;     cin >> s;     for (int i = 0; i < n; ++i) {       cin >> d[i];     }     int cur = 0;     while (cur >= 0 && cur < n && !w[cur]) {       w[cur] = 1;       cur = cur + (s[cur] ==  <  ? -1 : 1) * d[cur];     }     if (cur < 0 || cur >= n) {       cout <<  FINITE n ;     } else {       cout <<  INFINITE n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int max_n = 22, max_q = 11111, mod = 1000000007;   struct matrix {     vector<vector<int> > v;     matrix() {}     matrix(int n, int m) { v.resize(n, vector<int>(m, 0)); }     matrix operator*(const matrix &m) const {       matrix res(v.size(), m.v[0].size());       for (int i = 0; i < res.v.size(); ++i) {         for (int j = 0; j < res.v[i].size(); ++j) {           for (int k = 0; k < v[i].size(); ++k) {             res.v[i][j] += (1LL * v[i][k] * m.v[k][j]) % mod;             res.v[i][j] %= mod;           }         }       }       return res;     }   };   matrix power(matrix a, int b) {     if (b == 0) {       matrix res(a.v.size(), a.v.size());       for (int i = 0; i < res.v.size(); ++i) {         res.v[i][i] = 1;       }       return res;     }     if (b % 2 == 0) {       return power(a * a, b / 2);     }     return a * power(a, b - 1);   }   const int dx[] = {-1, 1, 0, 0, 0};   const int dy[] = {0, 0, -1, 1, 0};   int n, m, q, tp[max_q], x[max_q], y[max_q], t[max_q], f[max_q], a[max_n][max_n];   matrix dp, p;   bool is_in(int x, int y) { return 0 <= x && 0 <= y && x < n && y < m; }   void get_p() {     for (int i = 0; i < n; ++i) {       for (int j = 0; j < m; ++j) {         for (int k = 0; k < 5; ++k) {           int x = i + dx[k];           int y = j + dy[k];           if (is_in(x, y)) {             p.v[i * m + j][x * m + y] = 0;             if (a[x][y] == 0) {               p.v[i * m + j][x * m + y] = 1;             }           }         }       }     }   }   int main() {     scanf( %d%d%d , &n, &m, &q);     for (int i = 0; i < q; ++i) {       scanf( %d%d%d%d , &tp[i], &x[i], &y[i], &t[i]);       --x[i];       --y[i];       if (tp[i] == 3) {         ++t[i];       }     }     dp = matrix(1, n * m);     p = matrix(n * m, n * m);     get_p();     dp.v[0][0] = 1;     int nt = 1;     for (int i = 0; i < q; ++i) {       if (t[i] != nt) {         dp = dp * power(p, t[i] - nt - 1);       }       while (i + 1 < q && t[i] == t[i + 1]) {         if (tp[i] == 2) {           a[x[i]][y[i]] = 1;         }         if (tp[i] == 3) {           a[x[i]][y[i]] = 0;         }         ++i;       }       if (tp[i] == 2) {         a[x[i]][y[i]] = 1;       }       if (tp[i] == 3) {         a[x[i]][y[i]] = 0;       }       get_p();       if (t[i] != nt) {         dp = dp * p;       }       nt = t[i];       if (tp[i] == 1) {         printf( %d n , dp.v[0][x[i] * m + y[i]]);       }     }     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   int N, S, L, A[100009];   int c[100009], dp[100009];   deque<pair<int, int>> s, t, u;   int main() {     scanf( %d%d%d , &N, &S, &L);     for (int i = 1; i <= N; i++) dp[i] = 1e6;     for (int i = 1, ptr = 1; i <= N; i++) {       scanf( %d , &A[i]);       while (s.size() && s.back().first >= A[i]) s.pop_back();       s.push_back({A[i], i});       while (t.size() && t.back().first <= A[i]) t.pop_back();       t.push_back({A[i], i});       while (ptr < i && t.front().first - s.front().first > S) {         ptr++;         while (s.front().second < ptr) s.pop_front();         while (t.front().second < ptr) t.pop_front();       }       c[i] = ptr - 1;     }     for (int i = 1; i <= N; i++) c[i] = min(c[i], i - L + 1);     for (int i = 1, ptr = 0; i <= N; i++) {       if (i >= L) {         while (u.size() && u.back().first >= dp[i - L]) u.pop_back();         u.push_back({dp[i - L], i - L});       }       for (; ptr < c[i]; ptr++) {         while (u.size() && u.front().second <= ptr) u.pop_front();       }       if (u.size()) dp[i] = u.front().first + 1;     }     printf( %d n , dp[N] >= 1e6 ? -1 : dp[N]);   }


#include <bits/stdc++.h>   using namespace std;   void dfs(long long v, vector<long long> adj[], vector<bool>& visited) {     cout << char(v +  a );     visited[v] = true;     for (long long u : adj[v]) {       if (!visited[u]) dfs(u, adj, visited);     }   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     long long n;     cin >> n;     vector<long long> adj[26];     set<char> st;     vector<string> store;     for (long long i = 0; i < n; i++) {       string s;       cin >> s;       store.push_back(s);       st.insert(s[0]);       for (long long j = 0; j < s.length() - 1; j++) {         long long a = s[j] -  a , b = s[j + 1] -  a ;         adj[a].push_back(b);       }     }     queue<long long> q;     vector<bool> visited(26, false);     for (auto it : st) {       bool boo = true;       for (long long i = 0; i < store.size(); i++) {         string s = store[i];         for (long long j = 1; j < s.length(); j++) {           if (s[j] == it) {             boo = false;             goto h;           }         }       }     h:;       if (boo) {         q.push(it -  a );         visited[it -  a ] = true;       }     }     while (!q.empty()) {       long long v = q.front();       q.pop();       dfs(v, adj, visited);     }   }


#include <bits/stdc++.h>   using namespace std;   vector<int> set1;   vector<int> set2;   int col[100004], vis[100004];   int flag = 1;   class Graph {     int V;     list<int> *adj;       public:     Graph(int V);     void addEdge(int v, int w);     void BFS(int s);   };   Graph::Graph(int V) {     this->V = V;     adj = new list<int>[V];   }   void Graph::addEdge(int v, int w) {     adj[v].push_back(w);     adj[w].push_back(v);   }   void Graph::BFS(int s) {     list<int> queue;     vis[s] = 1;     queue.push_back(s);     col[s] = 0;     list<int>::iterator i;     while (!queue.empty()) {       s = queue.front();       queue.pop_front();       if (col[s] == 0) {         set1.push_back(s);       } else {         set2.push_back(s);       }       for (i = adj[s].begin(); i != adj[s].end(); ++i) {         if (vis[*i] != 1) {           vis[*i] = 1;           queue.push_back(*i);           col[*i] = (col[s] + 1) % 2;         } else {           if ((col[s] + 1) % 2 != col[*i]) {             flag = 0;             return;           }         }       }     }   }   int main() {     int n, m;     cin >> n >> m;     Graph g(n);     memset(col, -1, sizeof(col));     memset(vis, -1, sizeof(vis));     int a, b;     while (m--) {       cin >> a >> b;       vis[a - 1] = 0;       vis[b - 1] = 0;       g.addEdge(a - 1, b - 1);     }     for (int i = 0; i < n; i++) {       if (vis[i] == 0) g.BFS(i);       if (flag == 0) break;     }     if (flag == 0) {       cout <<  -1 n ;     } else {       cout << set1.size() <<   n ;       for (vector<int>::iterator i = set1.begin(); i != set1.end(); ++i)         cout << (*i) + 1 <<    ;       cout <<   n ;       cout << set2.size() <<   n ;       for (vector<int>::iterator i = set2.begin(); i != set2.end(); ++i)         cout << (*i) + 1 <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int NMax = 100005;   const int sqrNMax = 330;   int N;   int Nb[NMax][sqrNMax + 5];   int A[NMax], B[sqrNMax + 5][2 * sqrNMax + 5], Start[sqrNMax + 5], Block[NMax],       totalB, Size[sqrNMax + 5];   void Read() {     scanf( %d , &N);     for (int i = 1; i <= N; i++) scanf( %d , &A[i]);   }   void buildB() {     int currentBlock = 1, cnt = 0;     Start[1] = 1;     for (int i = 1; i <= N; i++) {       ++cnt;       if (cnt == sqrNMax) {         ++currentBlock;         Start[currentBlock] = i;         cnt = 1;       }       ++Size[currentBlock];       B[currentBlock][cnt] = A[i];       Nb[A[i]][currentBlock]++;       Block[i] = currentBlock;     }     totalB = currentBlock;   }   int findBlock(int pos) {     int sum = 0;     for (int i = 1; i <= totalB; i++) {       if (sum + Size[i] >= pos) {         Start[i] = sum + 1;         return i;       }       sum += Size[i];     }   }   int deleteElem(int block, int pos) {     int p = pos - Start[block] + 1;     int res = B[block][p];     Nb[res][block]--;     for (int j = p; j < Size[block]; j++) swap(B[block][j], B[block][j + 1]);     --Size[block];     return res;   }   void addElem(int block, int pos, int val) {     int p = pos - Start[block] + 1;     Nb[val][block]++;     B[block][++Size[block]] = val;     for (int j = Size[block] - 1; j >= p; j--) swap(B[block][j], B[block][j + 1]);   }   void makeCircularPerm(int left, int right) {     int b = findBlock(right);     int val = deleteElem(b, right);     b = findBlock(left);     addElem(b, left, val);   }   void buildA() {     int cnt = 0;     for (int i = 1; i <= totalB; i++) {       for (int j = 1; j <= Size[i]; j++) A[++cnt] = B[i][j];     }   }   void initialize() {     for (int i = 1; i <= totalB; i++) {       for (int j = 1; j <= Size[i]; j++) Nb[B[i][j]][i] = 0;       Size[i] = 0;       Start[i] = 0;     }   }   inline int decode(int nb, int lastans) { return (nb + lastans - 1) % N + 1; }   int Query(int left, int right, int val) {     int ans = 0, b = findBlock(left), b2 = findBlock(right);     for (int i = b + 1; i < b2; i++) ans += Nb[val][i];     int l = left - Start[b] + 1, r = right - Start[b2] + 1;     if (b == b2) {       for (int j = l; j <= r; j++)         if (B[b][j] == val) ++ans;       return ans;     }     for (int j = l; j <= Size[b]; j++)       if (B[b][j] == val) ans++;     for (int j = 1; j <= r; j++)       if (B[b2][j] == val) ++ans;     return ans;   }   void Solve() {     int Q;     scanf( %d , &Q);     buildB();     int lastans = 0, cntQ = 0;     for (int i = 1; i <= Q; i++) {       int type, l, r, k;       scanf( %d%d%d , &type, &l, &r);       l = decode(l, lastans);       r = decode(r, lastans);       if (l > r) swap(l, r);       if (type == 1) {         ++cntQ;         makeCircularPerm(l, r);         if (cntQ == sqrNMax) {           cntQ = 0;           buildA();           initialize();           buildB();         }       } else {         scanf( %d , &k);         k = decode(k, lastans);         lastans = Query(l, r, k);         printf( %d n , lastans);       }     }   }   int main() {     Read();     Solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct ter {     int cx, cy, dir, pt, rem;     ter(){};     ter(int _cx, int _cy, int _dir, int _pt, int _rem)         : cx(_cx), cy(_cy), dir(_dir), pt(_pt), rem(_rem){};   };   const int dx[] = {0, 1, 1, 1, 0, -1, -1, -1};   const int dy[] = {1, 1, 0, -1, -1, -1, 0, 1};   ter on;   queue<ter> Q;   int n, t[32], cx, cy, dir, pt, rem, dir1, dir2, sol, maxx = -3;   bool bio[312][312][8][31][6], mp[312][312];   void radi() {     while (!Q.empty()) {       on = Q.front();       cx = on.cx;       cy = on.cy;       dir = on.dir;       pt = on.pt;       rem = on.rem;       Q.pop();       if (bio[cx][cy][dir][pt][rem]) continue;       bio[cx][cy][dir][pt][rem] = 1;       if (mp[cx][cy] == 0) ++sol;       mp[cx][cy] = 1;       if (rem > 0) {         Q.push(ter(cx + dx[dir], cy + dy[dir], dir, pt, rem - 1));       } else {         if (pt == n) continue;         dir1 = (dir + 1) % 8;         dir2 = (dir + 7) % 8;         Q.push(ter(cx + dx[dir1], cy + dy[dir1], dir1, pt + 1, t[pt + 1] - 1));         Q.push(ter(cx + dx[dir2], cy + dy[dir2], dir2, pt + 1, t[pt + 1] - 1));       }     }   }   int main() {     std::ios::sync_with_stdio(false);     cin >> n;     for (int i = 1; i <= n; ++i) cin >> t[i];     Q.push(ter(155, 155, 0, 1, t[1] - 1));     radi();     cout << sol << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     map<int, int> a;     for (int i = 0; i < n; i++) {       int temp;       cin >> temp;       a[temp]++;     }     map<int, int> b;     for (int i = 0; i < n - 1; i++) {       int temp;       cin >> temp;       b[temp]++;     }     map<int, int> c;     for (int i = 0; i < n - 2; i++) {       int temp;       cin >> temp;       c[temp]++;     }     for (map<int, int>::iterator it = a.begin(); it != a.end(); ++it) {       if (it->second != b[it->first]) {         cout << it->first << endl;         break;       }     }     for (map<int, int>::iterator it = b.begin(); it != b.end(); ++it) {       if (it->second != c[it->first]) {         cout << it->first << endl;         break;       }     }     return 0;   }


#include <bits/stdc++.h>   int main() {     int n;     scanf( %d , &n);     int people_in_queue[n];     for (int i = 0; i < n; i++) {       scanf( %d  , &people_in_queue[i]);     }     int num_of_product[n][100], sum[n];     for (int i = 0; i < n; i++) {       sum[i] = 0;       for (int j = 0; j < people_in_queue[i]; j++) {         scanf( %d , &num_of_product[i][j]);         sum[i] = sum[i] + num_of_product[i][j];       }     }     int time[n];     for (int i = 0; i < n; i++) {       time[i] = sum[i] * 5 + people_in_queue[i] * 15;     }     int min = time[0];     for (int i = 0; i < n; i++) {       if (min > time[i]) {         min = time[i];       }     }     printf( %d , min);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void err(istream_iterator<string> it) {}   template <typename T, typename... Args>   void err(istream_iterator<string> it, T a, Args... args) {     cerr << *it <<   =   << a << endl;     err(++it, args...);   }   template <typename T>   void printV(const T &t) {     std::copy(t.cbegin(), t.cend(),               std::ostream_iterator<typename T::value_type>(std::cout,    ));     cout <<   n ;   }   template <typename T>   void printVV(const T &t) {     for (int i = 0; i < t.size(); i++) {       printf( %d:  , i);       printV(t[i]);     }   }   template <typename T, typename S>   void printVP(vector<pair<T, S>> vp) {     if (vp.empty()) {       cout <<   n ;       return;     }     for (int i = 0; i < vp.size() - 1; i++) {       cout <<  (  << vp[i].first <<     << vp[i].second <<  )  ;     }     cout <<  (  << vp[vp.size() - 1].first <<     << vp[vp.size() - 1].second          <<  ) n ;   }   template <typename T>   void printVVP(vector<vector<pair<T, T>>> vvp) {     for (int i = 0; i < vvp.size(); i++) {       cout << i <<  :  ;       printVP(vvp[i]);     }   }   vector<string> split(const string &s, char delim) {     vector<string> result;     stringstream ss(s);     string item;     while (getline(ss, item, delim)) {       result.push_back(item);     }     return result;   }   bool is_number(const string &s) {     string::const_iterator it = s.begin();     while (it != s.end() && isdigit(*it)) ++it;     return !s.empty() && it == s.end();   }   void fast() {     ios::sync_with_stdio(false);     cin.tie(NULL);   }   bool isValid(int r, int c, int R, int C) {     return (r >= 0 && r < R && c >= 0 && c < C);   }   struct Can {     long long x, r, id;   };   bool compareByX(const Can &lhs, const Can &rhs) { return lhs.x < rhs.x; }   class Person {    public:     string name, speak;     unordered_set<string> understands;     friend ostream &operator<<(ostream &os, const Person &p) {       os << p.name <<  (  << p.speak <<  ): ;       for (auto s : p.understands) os <<     << s;       return os;     }   };   vector<pair<int, int>> deltas = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}};   const int INF = 1e9 + 10;   const long long inf = 1e18 + 10;   const long double PI = 3.14159265359;   int main() {     int N;     cin >> N;     vector<int> A(N), B(N);     for (int i = 0; i < (N); ++i) {       cin >> A[i];       B[i] = A[i];     }     sort(B.begin(), B.end());     unordered_map<int, int> m;     for (int i = 0; i < (N); ++i) m[B[i]] = i;     vector<int> C(N);     for (int i = 0; i < (N); ++i) {       C[i] = B[(m[A[i]] + 1) % N];     }     printV(C);   }


#include <bits/stdc++.h>   using namespace std;   const int ms = 100010;   vector<int> g[ms];   int in[ms], out[ms];   int main() {     int n, m;     int a, b;     cin >> n >> m;     for (int i = 0; i < m; ++i) {       scanf( %d%d , &a, &b);       if (a > b) swap(a, b);       in[a]++, out[b]++;       g[a].push_back(b);     }     long long res = 0;     for (int i = 0; i < n; ++i) {       res += 1ll * in[i + 1] * out[i + 1];     }     printf( %lld n , res);     int q;     cin >> q;     for (int i = 0; i < q; ++i) {       scanf( %d , &a);       res -= 1ll * out[a] * in[a];       for (int j : g[a]) {         res -= 1ll * out[j] * in[j];         g[j].push_back(a);         out[a]++;         in[j]++;         out[j]--;         res += 1ll * out[j] * in[j];       }       g[a].clear();       in[a] = 0;       printf( %lld n , res);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   priority_queue<int, vector<int>, greater<int> > p;   bool visited[100005];   vector<int> G[100005];   int n, m;   void prime() {     p.push(1);     while (!p.empty()) {       int v = p.top();       p.pop();       if (visited[v]) continue;       visited[v] = true;       printf( %d  , v);       for (int i = 0; i < G[v].size(); i++) {         if (!visited[G[v][i]]) p.push(G[v][i]);       }     }   }   int main() {     scanf( %d%d , &n, &m);     int x, y;     for (int i = 0; i < m; i++) {       scanf( %d%d , &x, &y);       G[x].push_back(y);       G[y].push_back(x);     }     memset(visited, false, sizeof(visited));     prime();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2005, P = 998244353;   using ll = long long;   ll qpow(ll a, ll b) {     ll ret = 1;     while (b) {       if (b & 1) ret = ret * a % P;       a = a * a % P;       b >>= 1;     }     return ret;   }   int n, a, b;   ll pw[N * N], pw1[N * N];   ll dp[N][N], f[N], g[N], h[N];   int main() {     ios::sync_with_stdio(false);     cin >> n >> a >> b;     ll p = a * qpow(b, P - 2) % P;     if (n == 1) {       cout << 0 << endl;       return 0;     }     if (n == 2) {       cout << 1 << endl;       return 0;     }     pw[0] = pw1[0] = 1;     for (int i = 1; i <= n * n; i++) {       pw[i] = pw[i - 1] * p % P;       pw1[i] = pw1[i - 1] * (P - p + 1) % P;     }     dp[0][0] = 1;     for (int i = 1; i <= n; i++) {       dp[i][0] = 1;       for (int j = 1; j <= i; j++)         dp[i][j] = (dp[i - 1][j] * pw1[j] + dp[i - 1][j - 1] * pw[i - j]) % P;     }     for (int i = 1; i <= n; i++) {       f[i] = 1;       for (int j = 1; j < i; j++) f[i] = (f[i] + P - f[j] * dp[i][j] % P) % P;     }     for (int i = 3; i <= n; i++) {       ll tt = i * (i - 1) / 2;       for (int j = 1; j < i; j++) {         ll tmp = (g[j] + h[i - j]) * f[j] % P * dp[i][j] % P;         tt = (tt + tmp) % P;       }       g[i] = tt * qpow(P + 1 - f[i], P - 2) % P;       tt = f[i] * g[i] % P;       for (int j = 1; j < i; j++) {         ll tmp = (g[j] + h[i - j]) * f[j] % P * dp[i][j] % P;         tt = (tt + tmp) % P;       }       h[i] = tt;     }     cout << g[n] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 132674;   const int MOD = 1e9 + 7;   int main() {     set<int> ar;     set<int> to_buy;     set<int> to_sell;     long long multiplyier = 1;     int n;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       int temp;       string l;       cin >> l;       scanf( %d , &temp);       if (l.size() == 3) {         if (to_buy.size() > 0 && *to_buy.rbegin() > temp) {           to_buy.insert(temp);         } else if (to_sell.size() > 0 && *to_sell.begin() < temp) {           to_sell.insert(temp);         } else           ar.insert(temp);       } else {         if (ar.find(temp) != ar.end()) {           for (auto u : ar) {             if (u != temp) {               if (u < temp)                 to_buy.insert(u);               else                 to_sell.insert(u);             }           }           ar.clear();           multiplyier = (multiplyier * 2) % MOD;         } else if (to_buy.find(temp) != to_buy.end()) {           if (*to_buy.rbegin() != temp) {             cout << 0;             return 0;           }           to_buy.erase(temp);           for (auto u : ar) to_sell.insert(u);           ar.clear();         } else if (to_sell.find(temp) != to_sell.end()) {           if (*to_sell.begin() != temp) {             cout << 0;             return 0;           }           to_sell.erase(temp);           for (auto u : ar) to_buy.insert(u);           ar.clear();         }       }     }     cout << (multiplyier * ((int)ar.size() + 1)) % MOD;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2010, M = N * N;   int n, m, dist[N][N], deg[N][N], fx[N][N], fy[N][N];   char str[N][N];   pair<int, int> p[M];   int hh, tt;   bool st[N][N];   void topsort() {     hh = 0;     tt = -1;     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= m; ++j) {         dist[i][j] = 1;         fx[i][j] = i;         fy[i][j] = j;         if (!deg[i][j]) p[++tt] = {i, j};       }     pair<int, int> u;     int x, y, distance;     while (hh <= tt) {       u = p[hh++];       x = u.first, y = u.second, distance = dist[x][y];       if (str[x][y] ==  U )         x--;       else if (str[x][y] ==  D )         x++;       else if (str[x][y] ==  L )         y--;       else if (str[x][y] ==  R )         y++;       if (x <= 0 || x > n || y <= 0 || y > m) continue;       deg[x][y]--;       if (!deg[x][y]) p[++tt] = {x, y};       if (dist[x][y] < distance + 1) {         dist[x][y] = distance + 1;         fx[x][y] = fx[u.first][u.second];         fy[x][y] = fy[u.first][u.second];       }     }   }   void dfs(int x, int y) {     if (st[x][y]) return;     p[tt++] = {x, y};     st[x][y] = 1;     if (str[x][y] ==  U )       x--;     else if (str[x][y] ==  D )       x++;     else if (str[x][y] ==  L )       y--;     else if (str[x][y] ==  R )       y++;     dfs(x, y);   }   int main() {     int T, res, x, y;     cin >> T;     while (T--) {       cin >> n >> m;       for (int i = 1; i <= n; ++i)         for (int j = 1; j <= m; ++j) deg[i][j] = st[i][j] = 0;       for (int i = 1; i <= n; ++i) {         scanf( %s , str[i] + 1);         for (int j = 1; j <= m; ++j) {           int x = i, y = j;           if (str[i][j] ==  U ) x--;           if (str[i][j] ==  D ) x++;           if (str[i][j] ==  L ) y--;           if (str[i][j] ==  R ) y++;           if (x <= 0 || x > n || y <= 0 || y > m) continue;           deg[x][y]++;         }       }       topsort();       for (int i = 1; i <= n; ++i)         for (int j = 1; j <= m; ++j)           if (deg[i][j]) {             tt = 0;             dfs(i, j);             for (int k = 0; k < tt; ++k) {               int x = p[k].first, y = p[k].second;               deg[x][y] = 0;               dist[x][y] += tt - 1;             }           }       res = 0;       for (int i = 1; i <= n; ++i)         for (int j = 1; j <= m; ++j)           if (res < dist[i][j]) {             res = dist[i][j];             x = fx[i][j];             y = fy[i][j];           }       cout << x <<     << y <<     << res << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double PI = 3.1415926536;   int n, m, spaces;   bool a[100005], vis[505][505];   void walk(int x, int y, string s) {     int counter = 1;     for (int i = 0; i < s.size(); i++) {       if (s[i] ==  U ) {         if (x > 1) {           x--;           if (!vis[x][y]) spaces--, vis[x][y] = 1, a[counter] = 1;         }       } else if (s[i] ==  D ) {         if (x < n) {           x++;           if (!vis[x][y]) spaces--, vis[x][y] = 1, a[counter] = 1;         }       } else if (s[i] ==  R ) {         if (y < m) {           y++;           if (!vis[x][y]) spaces--, vis[x][y] = 1, a[counter] = 1;         }       } else {         if (y > 1) {           y--;           if (!vis[x][y]) spaces--, vis[x][y] = 1, a[counter] = 1;         }       }       counter++;     }     if (a[s.size()]) spaces++;   }   int main() {     int x, y;     string s;     cin >> n >> m >> x >> y >> s;     spaces = n * m - 1;     vis[x][y] = 1;     walk(x, y, s);     cout <<  1  ;     for (int i = 1; i < s.size(); i++) cout << a[i] <<    ;     cout << spaces <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = (long long)1e12;   const int maxn = 100050;   struct STU {     int b, c, id;     bool operator<(const STU &s) const {       return c < s.c || (c == s.c && id < s.id);     }   };   map<STU, int> mp;   bool cmp(const STU &a, const STU &b) { return a.b < b.b; }   struct BUG {     int a, id;     bool operator<(const BUG &s) const { return a < s.a; }   };   STU stu[maxn];   BUG bug[maxn];   int N, M, S;   int ans[maxn];   bool judge(int times) {     mp.clear();     long long pass = 0;     int p = M - 1, q = N - 1;     map<STU, int>::iterator it;     for (; p >= 0; p--) {       while (q >= 0 && stu[q].b >= bug[p].a) {         mp[stu[q]] = times;         q--;       }       if (p == M - 1 || it->second <= 0) {         if (p != M - 1) mp.erase(it);         it = mp.begin();         if (it == mp.end()) return false;         pass += it->first.c;       }       ans[bug[p].id] = it->first.id;       it->second--;     }     return pass <= S;   }   int main() {     scanf( %d%d%d , &N, &M, &S);     int max_a = 0;     for (int i = 0; i < M; i++)       scanf( %d , &bug[i].a), bug[i].id = i + 1, max_a = max(max_a, bug[i].a);     for (int i = 0; i < N; i++) scanf( %d , &stu[i].b);     for (int i = 0; i < N; i++) scanf( %d , &stu[i].c), stu[i].id = i + 1;     bool ok = false;     for (int i = 0; i < N; i++)       if (stu[i].b >= max_a && stu[i].c <= S) ok = true;     if (!ok) {       printf( NO n );       return 0;     } else       printf( YES n );     sort(bug, bug + M);     sort(stu, stu + N, cmp);     int L = 1, H = M, mid;     while (L < H) {       mid = L + (H - L) / 2;       if (judge(mid))         H = mid;       else         L = mid + 1;     }     judge(L);     for (int i = 1; i < M; i++) printf( %d  , ans[i]);     printf( %d n , ans[M]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n, i;       cin >> n;       string s;       int ans = 0;       cin >> s;       for (i = 1; i < n; i++) {         if (s[i] != s[0]) break;       }       if (i != n) {         int c = 1;         for (int j = i + 1; j != i; j = (j + 1) % n) {           if ((j != 0 && s[j] == s[j - 1]) || (j == 0 && s[0] == s[n - 1])) {             c++;           } else {             while (c >= 3) {               ans++;               c -= 3;             }             c = 1;           }         }         while (c >= 3) {           ans++;           c -= 3;         }       } else {         int c = n - 1;         ans = 1;         while (c >= 3) {           ans++;           c -= 3;         }       }       cout << ans << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   long long a, b, c, Minus, tmp, pos, lar_pos, ans;   long long gcd(long long a, long long b) {     if (b == 0) return a;     return gcd(b, a % b);   }   long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }   long long f(long long a, long long b) {     if (b == 0)       return 0ll;     else       return 1ll + f(a, b - gcd(a, b));   }   vector<long long> v, base;   int main() {     scanf( %lld %lld , &a, &b);     c = a;     for (long long i = 2; i * i <= c; i++) {       if (a % i == 0ll) v.push_back(i);       while (a % i == 0ll) a /= i;     }     if (a != 1ll) v.push_back(a);     for (int i = (0); i < (v.size()); i++) base.push_back(v[i]);     a = c;     while (b > 0) {       Minus = gcd(a, b);       for (int i = (0); i < (v.size()); i++)         while (Minus % v[i] == 0) v[i] *= base[i];       lar_pos = 0ll;       for (int i = (0); i < (v.size()); i++) {         if (a % v[i] != 0ll) continue;         tmp = lcm(Minus, v[i]);         pos = b / tmp * tmp;         lar_pos = max(pos, lar_pos);       }       ans += (b - lar_pos) / Minus;       b = lar_pos;     }     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int N, M, K;   vector<pair<int, char> > r, rr;   int main() {     scanf( %d %d %d , &N, &M, &K);     if (4 * N * M - 2 * N - 2 * M < K) return !printf( NO );     printf( YES n );     int c;     char d;     c = M - 1;     d =  R ;     r.push_back({min(c, K), d});     K -= c;     if (K <= 0) goto END;     for (int i = 0; i < M - 1; i++) {       c = N - 1;       d =  D ;       r.push_back({min(c, K), d});       K -= c;       if (K <= 0) goto END;       c = N - 1;       d =  U ;       r.push_back({min(c, K), d});       K -= c;       if (K <= 0) goto END;       c = 1;       d =  L ;       r.push_back({min(c, K), d});       K -= c;       if (K <= 0) goto END;     }     for (int i = 0; i < N - 1; i++) {       c = 1;       d =  D ;       r.push_back({min(c, K), d});       K -= c;       if (K <= 0) goto END;       c = M - 1;       d =  R ;       r.push_back({min(c, K), d});       K -= c;       if (K <= 0) goto END;       c = M - 1;       d =  L ;       r.push_back({min(c, K), d});       K -= c;       if (K <= 0) goto END;     }     c = N - 1;     d =  U ;     r.push_back({min(c, K), d});     K -= c;     if (K <= 0) goto END;   END:     for (int i = 0; i < r.size(); i++)       if (r[i].first > 0) rr.push_back(r[i]);     r = rr;     printf( %d n , r.size());     for (int i = 0; i < r.size(); i++) printf( %d %c n , r[i].first, r[i].second);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1000020;   const int maxx = 1000000;   const int MOd = 1e9 + 7;   const int K = 1000;   const int P = 143;   int loc[maxn];   class Aho_Corasick {    public:     int last, next[maxn][26];     short used[maxn][26], step;     int deg[maxn], dad[maxn];     int dep, fail[maxn];     char name[maxn];     int now[maxn], pre[maxn], E, go[maxn];     int beg[maxn], end[maxn], cnt;     int n, segment[1 << 21];     vector<int> w[maxn];     void update(int k, int x) {       for (int l = beg[k] + n - 1, r = end[k] + n - 1; l <= r;            l = (l + 1) >> 1, r = (r - 1) >> 1) {         if (l & 1) segment[l] += x;         if (~r & 1) segment[r] += x;       }     }     inline void add(int i, int j) {       pre[++E] = now[i];       now[i] = E;       go[E] = j;     }     void calc() {       for (int l = 1; l <= dep; l++) {         for (int i = now[l]; i; i = pre[i]) {           int t = fail[dad[go[i]]];           char c = name[go[i]];           while (t && used[t][c] != step) t = fail[t];           if (used[t][c] == step && next[t][c] != go[i]) t = next[t][c];           fail[go[i]] = t;           w[t].push_back(go[i]);         }       }     }     void dfs(int n) {       beg[n] = ++cnt;       for (int i = 0; i < w[n].size(); i++) dfs(w[n][i]);       end[n] = cnt;     }     inline long long find(int k) {       long long ret = 0;       for (k += n - 1; k; k >>= 1) ret += segment[k];       return ret;     }     void build(char *ar, int sz, int id) {       int p = 0;       for (int i = 1; i <= sz; i++) {         char h = ar[i] -  a ;         if (used[p][h] != step) {           used[p][h] = step;           next[p][h] = ++last;           deg[last] = deg[p] + 1;           dep = max(dep, (deg[last]));           dad[last] = p;           name[last] = h;           add(deg[last], last);         }         p = next[p][h];         if (i == sz) loc[id] = p;       }     }     long long get(char *ar, int sz) {       long long ret = 0;       int p = 0;       for (int i = 1; i <= sz; i++) {         char c = ar[i] -  a ;         while (p && used[p][c] != step) p = fail[p];         if (used[p][c] == step) p = next[p][c];         ret += find(beg[p]);       }       return ret;     }   } trie;   int len[maxn];   bool exist[maxn], used[maxn];   char ch[maxn];   int q, a;   char *ar[maxn];   int main() {     scanf( %d %d , &q, &a);     trie.n = 1 << 20;     trie.step = 1;     for (int i = 1; i <= a; i++) {       scanf(  %s , ch);       exist[i] = 1;       ar[i] = new char[strlen(ch) + 20];       memset(ar[i], 0, sizeof(ar[i]));       len[i] = strlen(ch);       for (int j = 1; j <= len[i]; j++) {         ar[i][j] = ch[j - 1];         ch[j - 1] = 0;       }       trie.build(ar[i], len[i], i);     }     trie.calc();     trie.dfs(0);     for (int i = 1; i <= a; i++) trie.update(loc[i], 1);     vector<int> w;     while (q--) {       char c;       int x;       scanf(  %c , &c);       if (c ==  ? ) {         scanf(  %s , ch + 1);         int l = strlen(ch + 1);         cout << trie.get(ch, l) << endl;       }       if (c ==  -  || c ==  + ) {         scanf( %d , &x);         if (c ==  -  && exist[x]) trie.update(loc[x], -1), exist[x] = 0;         if (c ==  +  && !exist[x]) trie.update(loc[x], 1), exist[x] = 1;       }     }     return 0;   }


#include <bits/stdc++.h>   int main(int argc, char const *argv[]) {     int h1, a1, c1, h2, a2;     std::cin >> h1 >> a1 >> c1;     std::cin >> h2 >> a2;     std::string s =  STRIKE n , h =  HEAL n ;     int n(0);     std::string ans;     while (h2 > 0) {       n++;       if (h1 <= a2 && h2 > a1) {         h1 += c1;         ans += h;       } else {         h2 -= a1;         ans += s;       }       h1 -= a2;     }     std::cout << n <<   n ;     std::cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int t[123];   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int a, n;     cin >> n >> a;     --a;     for (int i = 0; i < n; ++i) cin >> t[i];     int l, r;     l = r = a;     int res = 0;     while (l >= 0 || r < n) {       if (l >= 0 && r < n) {         if (t[l] > 0 && t[r] > 0) res += t[l] + t[r];       } else if (l >= 0)         res += t[l];       else         res += t[r];       --l, ++r;     }     if (t[a] > 0) res--;     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int lsone(int n) { return (n & -n); }   void mult(long long int a[25][25], long long int b[25][25],             long long int c[25][25], int m, int n, int p) {     for (int i = 1; i <= m; i++) {       for (int j = 1; j <= p; j++) {         c[i][j] = 0;         for (int k = 1; k <= n; k++) {           c[i][j] += (a[i][k] * b[k][j]) % 1000000007;           c[i][j] %= 1000000007;         }       }     }   }   void mat_pow(long long int a[25][25], long long int c[25][25], int n,                long long int p) {     if (p == 0) {       for (int i = 1; i <= n; i++) c[i][i] = 1;     } else if (p == 1) {       for (int i = 1; i <= n; i++) {         for (int j = 1; j <= n; j++) c[i][j] = a[i][j];       }     } else {       long long int d[25][25];       mat_pow(a, d, n, p / 2);       if (p % 2) {         long long int e[25][25];         mult(d, d, e, n, n, n);         mult(e, a, c, n, n, n);       } else {         mult(d, d, c, n, n, n);       }     }   }   long long int pow1(long long int a, long long int b) {     if (b == 0)       return 1ll;     else if (b == 1)       return a;     else {       long long int x = pow1(a, b / 2);       x *= x;       x %= 1000000007;       if (b % 2) {         x *= a;         x %= 1000000007;       }       return x;     }   }   int n, ans[110000];   int s(int y) {     int ans = 0;     while (y) {       y /= 10;       ans++;     }     return ans;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     ans[1] = 1;     for (int i = 2; i <= 1e5; i++) {       ans[i] = ans[i - 1] * 10;       ans[i] %= 210;     }     cin >> n;     int req = (210 - ans[n]) % 210;     if (n <= 2) {       cout << -1 <<   n ;     } else if (n == 3)       cout << 210 <<   n ;     else {       int numdig = s(req);       cout << 1;       for (int i = 0; i < n - numdig - 1; i++) cout << 0;       cout << req <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2005;   char mp[N][N];   int deg[N][N];   int cnt[2], n, m;   int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};   string str =  ><v^ , tmp =  <>^v ;   bool check(int x, int y) { return x >= 1 && x <= n && y >= 1 && y <= m; }   int main() {     ios ::sync_with_stdio(0);     cin >> n >> m;     for (int i = (int)(1); i <= (int)(n); ++i) {       cin >> (mp[i] + 1);     }     for (int i = (int)(1); i <= (int)(n); ++i) {       for (int j = (int)(1); j <= (int)(m); ++j) {         if (mp[i][j] ==  . ) {           if ((i + j) & 1) {             cnt[1]++;           } else             cnt[0]++;         }       }     }     if (cnt[0] != cnt[1]) {       cout <<  Not unique  << endl;       return 0;     } else {       queue<int> q;       for (int i = (int)(1); i <= (int)(n); ++i) {         for (int j = (int)(1); j <= (int)(m); ++j) {           if (mp[i][j] ==  . ) {             for (int k = 0; k < (int)(4); ++k) {               int x = i + dx[k];               int y = j + dy[k];               if (check(x, y) && mp[x][y] ==  . ) {                 deg[i][j]++;               }             }             if (deg[i][j] == 1) {               q.push(i);               q.push(j);             }           }         }       }       while (q.size()) {         int x = q.front();         q.pop();         int y = q.front();         q.pop();         for (int k = 0; k < (int)(4); ++k) {           int tx = x + dx[k];           int ty = y + dy[k];           if (check(tx, ty) && mp[tx][ty] ==  .  && deg[tx][ty] > 0) {             mp[x][y] = tmp[k];             mp[tx][ty] = str[k];             deg[tx][ty] = 0;             deg[x][y] = 0;             for (int t = 0; t < (int)(4); ++t) {               int ax = tx + dx[t];               int ay = ty + dy[t];               if (check(ax, ay) && mp[ax][ay] ==  .  && deg[ax][ay] > 0) {                 deg[ax][ay]--;                 if (deg[ax][ay] == 1) {                   q.push(ax);                   q.push(ay);                 }               }             }             break;           }         }       }       for (int i = (int)(1); i <= (int)(n); ++i) {         for (int j = (int)(1); j <= (int)(m); ++j) {           if (deg[i][j] > 0 || mp[i][j] ==  . ) {             cout <<  Not unique  << endl;             return 0;           }         }       }       for (int i = (int)(1); i <= (int)(n); ++i) {         cout << mp[i] + 1 << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void flash() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);   }   void solve() {     long long n;     cin >> n;     vector<long long> v(n);     long long sm = 0;     long long mx = 0;     for (long long i = 0; i < n; i++) {       cin >> v[i];       sm += v[i];       mx = max(mx, v[i]);     }     function<long long(long long)> dfs = [&](long long l) -> long long {       if (l <= 0) return 0;       return dfs(l - 1);     };     long long val1 = mx;     long long val2 = sm - mx;     if (n == 1) {       cout <<  T             <<   n ;       return;     }     long long ok = dfs(n);     if (ok > 5) {       cout <<  T             <<   n ;       return;     }     ok = dfs(n - 1);     if (ok > 4) {       cout <<  HL             <<   n ;       return;     }     if (sm - n == 0) {       if (n % 2) {         cout <<  T               <<   n ;         return;       } else {         cout <<  HL               <<   n ;         return;       }     }     if (val1 > val2) {       cout <<  T             <<   n ;       return;     }     if (sm % 2 == 0) {       cout <<  HL             <<   n ;       return;     } else {       cout <<  T             <<   n ;       return;     }   }   int32_t main() {     flash();     long long t;     t = 1;     cin >> t;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool SR(int &_x) { return scanf( %d , &_x) == 1; }   bool SR(long long &_x) { return scanf( %lld , &_x) == 1; }   bool SR(double &_x) { return scanf( %lf , &_x) == 1; }   bool SR(char *_s) { return scanf( %s , _s) == 1; }   bool RI() { return true; }   template <typename I, typename... T>   bool RI(I &_x, T &..._tail) {     return SR(_x) && RI(_tail...);   }   void SP(const int _x) { printf( %d , _x); }   void SP(const long long _x) { printf( %lld , _x); }   void SP(const double _x) { printf( %.16lf , _x); }   void SP(const char *s) { printf( %s , s); }   void PL() { puts(  ); }   template <typename I, typename... T>   void PL(const I _x, const T... _tail) {     SP(_x);     if (sizeof...(_tail)) putchar(   );     PL(_tail...);   }   const int maxn = 1e6 + 6;   char in[maxn];   void read() { RI(in); }   deque<char> q;   void build() {     q = deque<char>(in, in + strlen(in));     while (((int)(q).size()) && q[0] ==  F ) q.pop_front();   }   void sol() {     int prv = 0, cur = 0, cnt = 0;     for (int i = 0; i < int(((int)(q).size())); i++)       if (q[i] ==  F ) {         swap(prv, cur);         cur = max(prv + 1, i - (cnt++));       }     PL(cur);   }   int main() {     read();     build();     sol();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   int n, a[100005], sta[100005];   vector<int> V;   int calc(int k) {     while (k) {       int d = k % 10;       k /= 10;       if (d != 4 && d != 7) return 0;     }     return 1;   }   using pii = pair<int, int>;   int tar[100005], to[100005];   vector<pii> Ans;   void Swap(int first, int second) {     if (first == second) return;     to[tar[first]] = second, to[tar[second]] = first;     swap(tar[second], tar[first]);     Ans.push_back(pii(first, second));     return;   }   int main() {     V.resize(1100800);     for (auto first : V) first = rand();     scanf( %d , &n);     int g = 0, pos = -1;     vector<pii> vec;     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       sta[i] = calc(a[i]);       g += sta[i];       if (sta[i]) pos = i;       vec.push_back(pii(a[i], i));     }     sort(vec.begin(), vec.end());     for (int i = 0; i < vec.size(); i++) {       tar[vec[i].second] = i + 1;       to[i + 1] = vec[i].second;     }     if (g == 0) {       bool flag = 0;       for (int i = 1; i < n; i++)         if (a[i] > a[i + 1]) flag = 1;       if (flag)         puts( -1 );       else         puts( 0 );     } else {       assert(pos > 0);       for (int i = 1; i <= n; i++) {         Swap(pos, i);         pos = i;         int prv = to[i];         Swap(pos, to[i]);         pos = prv;       }       int sz = Ans.size();       printf( %d n , sz);       for (auto first : Ans) {         printf( %d %d n , first.first, first.second);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct node {     int lb, rb, l_max, r_max, s_max;   };   int n, m, l, r, k, offset = 1 << 19, a[300004], z, t;   long long d[600004];   node trn[1100000];   int sgn(long long x) {     if (x > 0) return 1;     if (x < 0) return -1;     return 0;   }   void update(int pos) {     if (pos < 0) return;     if (d[pos + 1] == 0) {       trn[pos + offset].l_max = 0;       trn[pos + offset].r_max = 0;       trn[pos + offset].s_max = 0;     } else {       trn[pos + offset].l_max = 1;       trn[pos + offset].r_max = 1;       trn[pos + offset].s_max = 1;     }     pos = (pos + offset) >> 1;     while (pos > 0) {       z = 2 * pos;       trn[pos].s_max = max(trn[z].s_max, trn[z + 1].s_max);       trn[pos].l_max = trn[z].l_max;       trn[pos].r_max = trn[z + 1].r_max;       if (sgn(d[trn[z].rb]) >= sgn(d[trn[z + 1].lb])) {         int len = trn[z].r_max + trn[z + 1].l_max;         trn[pos].s_max = max(len, trn[pos].s_max);         if (trn[z].l_max == trn[z].rb - trn[z].lb + 1)           trn[pos].l_max += trn[z + 1].l_max;         if (trn[z + 1].r_max == trn[z + 1].rb - trn[z + 1].lb + 1)           trn[pos].r_max += trn[z].r_max;       }       pos = pos >> 1;     }   }   int readInt() {     bool mnus = false;     int result = 0;     char ch;     ch = getchar();     while (true) {       if (ch ==  - ) break;       if (ch >=  0  && ch <=  9 ) break;       ch = getchar();     }     if (ch ==  - )       mnus = true;     else       result = ch -  0 ;     while (true) {       ch = getchar();       if (ch <  0  || ch >  9 ) break;       result = result * 10 + (ch -  0 );     }     if (mnus)       return -result;     else       return result;   }   int main() {     std::ios::sync_with_stdio(false);     n = readInt();     for (int i = 1; i <= n; ++i) a[i] = readInt();     for (int i = 1; i < n; ++i) d[i] = a[i + 1] - a[i];     for (int i = 0; i < offset; ++i) {       trn[i + offset].lb = i + 1;       trn[i + offset].rb = i + 1;       if (d[i + 1] == 0) {         trn[i + offset].l_max = 0;         trn[i + offset].r_max = 0;         trn[i + offset].s_max = 0;       } else {         trn[i + offset].l_max = 1;         trn[i + offset].r_max = 1;         trn[i + offset].s_max = 1;       }     }     for (int i = offset - 1; i >= 1; --i) {       t = 2 * i;       trn[i].lb = trn[t].lb;       trn[i].rb = trn[t + 1].rb;       trn[i].s_max = max(trn[t].s_max, trn[t + 1].s_max);       trn[i].l_max = trn[t].l_max;       trn[i].r_max = trn[t + 1].r_max;       if (sgn(d[trn[t].rb]) >= sgn(d[trn[t + 1].lb])) {         int len = trn[t].r_max + trn[t + 1].l_max;         trn[i].s_max = max(len, trn[i].s_max);         if (trn[t].l_max == trn[t].rb - trn[t].lb + 1)           trn[i].l_max += trn[t + 1].l_max;         if (trn[t + 1].r_max == trn[t + 1].rb - trn[t + 1].lb + 1)           trn[i].r_max += trn[t].r_max;       }     }     m = readInt();     for (int i = 0; i < m; ++i) {       l = readInt();       r = readInt();       k = readInt();       d[l - 1] += k;       d[r] -= k;       d[0] = 0;       d[n] = 0;       update(l - 2);       update(r - 1);       cout << trn[1].s_max + 1 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 0x7fffffff;   const double eps = 1e-10;   const double pi = acos(-1.0);   inline int read() {     int x = 0, f = 1;     char ch;     ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x * f;   }   const int N = 2e5 + 10;   int n, a, b, k;   string s;   int mark[N];   int tot, ans[N];   int main() {     n = read();     a = read();     b = read();     k = read();     cin >> s;     for (int i = 1; i <= n; i++) mark[i] = (s[i - 1] -  0 );     int cnt = 0;     for (int i = 1; i <= n; ++i)       if (mark[i])         cnt = 0;       else {         if (++cnt == b) {           ans[++tot] = i;           cnt = 0;         }       }     tot -= a - 1;     printf( %d n , tot);     for (int i = 1; i <= tot; i++) printf( %d  , ans[i]);     return 0;   }


#include <bits/stdc++.h>   const long long int mrx = 1e6 + 5, M = 1e9 + 7;   long long int mx = INT_MIN, mn = INT_MAX;   using namespace std;   long long int x1, x2, s, t1, t2, p, d;   long long int poezd, igor;   int main() {     ios_base::sync_with_stdio(NULL);     cin.tie(NULL);     cin >> s >> x1 >> x2;     cin >> t1 >> t2;     cin >> p >> d;     if (t2 <= t1) {       cout << abs(x1 - x2) * t2;       return 0;     } else {       if (d == 1) {         if (x1 < x2) {           if (p == x1) {             cout << (x2 - x1) * t1;           } else if (p < x1) {             cout << min((x2 - x1) * t2, (x2 - p) * t1);           } else {             cout << min((x2 - x1) * t2, (s - p) * t1 + s * t1 + x2 * t1);           }         } else {           cout << min((x1 - x2) * t2, (s - p) * t1 + (s - x2) * t1);         }       }       if (d == -1) {         if (x1 < x2) {           cout << min((x2 - x1) * t2, p * t1 + x2 * t1);         } else {           if (p == x1) {             cout << (x1 - x2) * t1;           } else if (p < x1) {             cout << min((x1 - x2) * t2, p * t1 + s * t1 + (s - x2) * t1);           } else {             cout << min((x1 - x2) * t2, (p - x2) * t1);           }         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n;     int sl = 0;     for (int i = 1; i <= n; ++i) {       int x, y;       cin >> x >> y;       if (x > 0) ++sl;     }     if (sl == n || sl == 0 || sl == n - 1 || sl == 1) {       cout <<  Yes ;       return 0;     }     cout <<  No ;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   void printQueue(T& q) {     while (!q.empty()) {       cout << q.top() << endl;       q.pop();     }   }   vector<int> adj[200009];   vector<pair<int, int> > levels;   bool visited[200009];   bool cmp(pair<int, int> a, pair<int, int> b) {     if (a.first == b.first) {       return a.second < b.second;     } else {       return a.first > b.first;     }   }   void dfs(int s, int level) {     visited[s] = true;     levels.push_back(make_pair(level, s));     for (int i = 0; i < adj[s].size(); i++) {       if (visited[adj[s][i]] == false) {         dfs(adj[s][i], level + 1);       }     }   }   int main() {     int t = 1;     while (t--) {       int n, x;       cin >> n;       long long dp[n + 1][2];       memset(dp, 0, sizeof(dp));       for (int i = 1; i < n; i++) {         cin >> x;         adj[x].push_back(i);         adj[i].push_back(x);       }       dfs(1, 1);       for (int j = 0; j < n; j++) {         cin >> x;         if (x == 1) {           dp[j][0] = 1;           dp[j][1] = 0;         } else {           dp[j][0] = 0;           dp[j][1] = 1;         }       }       sort(levels.begin(), levels.end(), cmp);       bool visit[n + 1];       memset(visit, false, sizeof(visit));       int index;       for (int i = 0; i < levels.size(); i++) {         visit[levels[i].second] = true;         index = levels[i].second;         for (int j = 0; j < adj[index].size(); j++) {           if (visit[adj[index][j]] == false) {             dp[adj[index][j]][0] =                 ((dp[index][0] * dp[adj[index][j]][0]) % 1000000007ll) +                 ((dp[index][0] * dp[adj[index][j]][1]) % 1000000007ll) +                 ((dp[index][1] * dp[adj[index][j]][0]) % 1000000007ll);             dp[adj[index][j]][0] %= 1000000007ll;             dp[adj[index][j]][1] =                 ((dp[index][0] * dp[adj[index][j]][1]) % 1000000007ll) +                 ((dp[index][1] * dp[adj[index][j]][1]) % 1000000007ll);             dp[adj[index][j]][1] %= 1000000007ll;           }         }       }       cout << dp[1][0] << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   void compute() {     long long n;     cin >> n;     n -= 2;     string s[n];     cin >> s[0];     string ans = s[0];     for (long long i = 1; i < n; i++) {       cin >> s[i];       if (s[i][0] == ans[ans.size() - 1])         ans.push_back(s[i][1]);       else         ans += s[i];     }     if (ans.size() != n + 2) ans.push_back( a );     cout << ans << endl;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long t;     cin >> t;     while (t--) {       compute();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> ans;   int m;   int main() {     int n, ans = 0;     string s;     cin >> n;     cin >> s;     for (int i = 0; i < n; i++)       if (s[i] ==  < )         ans++;       else         break;     for (int i = n - 1; i >= 0; i--)       if (s[i] ==  > )         ans++;       else         break;     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000 * 1000 * 1000 + 7LL;   const double EXP = 1e-6;   const int MAX = 100001;   int main() {     int n, k;     while (cin >> n >> k) {       int a[10001];       for (int i = 1; i <= n; i++) a[i] = 1;       a[n] = 0;       while (k--) {         for (int i = 1; i <= n; i++) {           if (a[i] + a[i] > n - i) {             int p = n - i - a[i];             int o = n - p;             a[i] += a[o];             cout << o <<    ;           } else if (a[i] == n - i)             cout << n <<    ;           else {             a[i] += a[i];             cout << i <<    ;           }         }         cout << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void sprint(string s) {     for (int i = 0; i < s.size(); ++i) printf( %c , s[i]);     printf(  n );   }   int main() {     int n, k, d;     cin >> n >> k >> d;     int a[n];     int b[n];     for (int i = 0; i < n; ++i) {       scanf( %d , &a[i]);       b[i] = 0;     }     sort(a, a + n);     if (k == 1) b[n - 1] = 1;     for (int i = n - 2; i >= 0; --i) {       if (n - i < k) continue;       if (n - i >= k and a[n - 1] - a[i] <= d)         b[i] = b[i + 1] + 1;       else if (a[i + k - 1] - a[i] > d)         b[i] = b[i + 1];       else {         auto it = upper_bound(a, a + n, a[i] + d);         it--;         int id = it - a;         if (id < i + k - 1) {           b[i] = b[i + 1];         } else {           id++;           if (id == n - 1) {             if (b[i + k])               b[i] = b[i + 1] + 1;             else               b[i] = b[i + 1];           } else {             if (b[i + k] - b[id + 1] > 0)               b[i] = b[i + 1] + 1;             else               b[i] = b[i + 1];           }         }       }     }     for (int i = 0; i < n; ++i) {     }     if (n == 1) {       printf( YEs n );     } else if (b[0] - b[1])       printf( YES n );     else       printf( NO n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct myQueue {     stack<pair<long long, long long> > s1, s2;     int size() { return s1.size() + s2.size(); }     bool isEmpty() { return size() == 0; }     long long getMax() {       if (isEmpty()) {         return -2e9;       }       if (!s1.empty() && !s2.empty()) {         return max(s1.top().second, s2.top().second);       }       if (!s1.empty()) {         return s1.top().second;       }       return s2.top().second;     }     void push(long long val) {       if (s2.empty()) {         s2.push({val, val});       } else {         s2.push({val, max(val, s2.top().second)});       }     }     void pop() {       if (s1.empty()) {         while (!s2.empty()) {           if (s1.empty()) {             s1.push({s2.top().first, s2.top().first});           } else {             s1.push({s2.top().first, max(s2.top().first, s1.top().second)});           }           s2.pop();         }       }       assert(!s1.empty());       s1.pop();     }   };   int main() {     cin.tie(NULL);     cout.tie(NULL);     ios_base::sync_with_stdio(0);     long long n, k, x;     cin >> n >> k >> x;     vector<int> a(n);     for (long long i = 0; i < n; i++) {       cin >> a[i];     }     vector<myQueue> q(x + 1);     for (long long i = 0; i < n; i++) {       vector<long long> dp(x + 1, -2e9);       if (i)         for (long long j = 1; j < x + 1; j++) {           if (i < k && j == 1) dp[j] = a[i];           long long getMax = q[j - 1].getMax();           if (getMax != -2e9) dp[j] = max(dp[j], getMax + 1LL * a[i]);         }       if (!i) dp[1] = a[0];       for (long long j = 1; j < x + 1; j++) {         if (q[j].size() == k) {           q[j].pop();         }         q[j].push(dp[j]);       }     }     long long ans = q[x].getMax();     if (ans == -2e9) return cout << -1, 0;     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string s1, s2;   int len1, len2;   int dp[5002][5002];   int func(int p1, int p2) {     if ((p1 == len1) || (p2 == len2)) {       return 0;     }     if (dp[p1][p2] != -1) {       return dp[p1][p2];     }     int ans = 0;     if (s1[p1] == s2[p2]) {       ans = (1 + ans + func(p1 + 1, p2 + 1)) % 1000000007;     }     ans = (ans + func(p1, p2 + 1)) % 1000000007;     return dp[p1][p2] = ans;   }   int main() {     std::ios_base::sync_with_stdio(false);     ;     cin >> s1 >> s2;     len1 = s1.size();     len2 = s2.size();     memset((dp), -1, sizeof(dp));     int ans = 0;     for (int i = 0; i <= len1 - 1; i++) {       ans = (ans + func(i, 0)) % 1000000007;     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using namespace std;   int get_type(int a, int b, int c) {     if (a == 0 && b == 0 && c != 0) return 0;     if (a == 0 && b == 0 && c == 0) return -1;     if (a == 0) return 1;     if (b == 0) return 2;     return 3;   }   int main() {     int a1, b1, c1, a2, b2, c2;     cin >> a1 >> b1 >> c1 >> a2 >> b2 >> c2;     int t1 = get_type(a1, b1, c1);     int t2 = get_type(a2, b2, c2);     if (t1 == 0 || t2 == 0)       cout <<  0 ;     else if (t1 == -1 || t2 == -1)       cout <<  -1 ;     else if (t1 != t2)       cout <<  1 ;     else {       if (t1 == 1) {         if (c1 * b2 == c2 * b1)           cout <<  -1 ;         else           cout <<  0 ;       } else if (t1 == 2) {         if (c1 * a2 == c2 * a1)           cout <<  -1 ;         else           cout <<  0 ;       } else {         if (b1 * a2 != a1 * b2)           cout <<  1 ;         else {           if (c1 * b2 == c2 * b1)             cout <<  -1 ;           else             cout <<  0 ;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 10;   struct node {     long long v[10];     int tag[10];     void init(int x) {       int y = 1;       memset(v, 0, sizeof(v));       while (x) {         v[x % 10] += y;         x /= 10;         y *= 10;       }     }     void updtag(int* _tag) {       for (int i = 0; i < 10; i++) tag[i] = _tag[tag[i]];     }     bool havetag() {       for (int i = 0; i < 10; i++)         if (tag[i] != i) return 1;       return 0;     }   } f[N * 4];   int a[N];   int n, q;   int tag[10];   long long ans;   void upd(int s) {     for (int i = 0; i < 10; i++) f[s].v[i] = f[s + s].v[i] + f[s + s + 1].v[i];   }   void build(int l, int r, int s) {     for (int i = 0; i < 10; i++) f[s].tag[i] = i;     if (l == r) {       f[s].init(a[l]);       return;     }     build(l, (l + r) / 2, s + s);     build((l + r) / 2 + 1, r, s + s + 1);     upd(s);   }   long long tmp[10] = {0};   void down(int l, int r, int s) {     if (!f[s].havetag()) return;     for (int i = 0; i < 10; i++) tmp[f[s].tag[i]] += f[s].v[i];     for (int i = 0; i < 10; i++) f[s].v[i] = tmp[i], tmp[i] = 0;     if (l != r) f[s + s].updtag(f[s].tag), f[s + s + 1].updtag(f[s].tag);     for (int i = 0; i < 10; i++) f[s].tag[i] = i;   }   void change(int l, int r, int s, int ll, int rr) {     down(l, r, s);     if (r < ll || rr < l) return;     if (ll <= l && r <= rr) {       f[s].updtag(tag);       down(l, r, s);       return;     }     change(l, (l + r) / 2, s + s, ll, rr);     change((l + r) / 2 + 1, r, s + s + 1, ll, rr);     upd(s);   }   void get(int l, int r, int s, int ll, int rr) {     down(l, r, s);     if (r < ll || rr < l) return;     if (ll <= l && r <= rr) {       for (int i = 1; i < 10; i++) ans += f[s].v[i] * i;       return;     }     get(l, (l + r) / 2, s + s, ll, rr);     get((l + r) / 2 + 1, r, s + s + 1, ll, rr);   }   int main() {     scanf( %d %d , &n, &q);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);     }     build(1, n, 1);     while (q--) {       int sig, l, r, x, y;       scanf( %d %d %d , &sig, &l, &r);       if (sig == 1) {         scanf( %d %d , &x, &y);         for (int i = 0; i < 10; i++) tag[i] = i;         tag[x] = y;         change(1, n, 1, l, r);         continue;       }       ans = 0;       get(1, n, 1, l, r);       printf( %lld n , ans);     }     return 0;   }


#include<bits/stdc++.h>   using namespace std;      //#pragma GCC optimize( Ofast,unroll-loops,no-stack-protector )   //#pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )         #define pb push_back   #define fi first   #define se second   #define ll long long   #define ld long double   #define lll __int128   #define tp top()   #define fr front()   #define vi vector<int>   #define sz size()   #define rep(i,a,b) for(int i = a; i < b; ++i)   #define mem(a,  b) memset(a,  (b),  sizeof(a))   #define clr(a) memset(a,  0,  sizeof(a))   #define sqr(x) ( (x) * (x) )   #define all(v) v.begin(),  v.end()      typedef pair<int, int> pii;   typedef pair<int,pii> pip;   typedef pair<pii,int> ppi;   typedef pair<pii,pii> ppp;            void nonint(){    ios_base::sync_with_stdio(0);    cin.tie(0);    cout.tie(0);   }   #define N 200020   int st[4*N],maksl[4*N], maksr[4*N], minsl[4*N], minsr[4*N];      vector<int> vec[N];   int n;   void merge(int v){    st[v] = st[v<<1] + st[v<<1|1];    maksr[v] = max(maksr[v<<1], st[v<<1] + maksr[v<<1|1]);    maksl[v] = max(maksl[v<<1|1], st[v<<1|1] + maksl[v<<1]);    minsr[v] = min(minsr[v<<1], st[v<<1] + minsr[v<<1|1]);    minsl[v] = min(minsl[v<<1|1], st[v<<1|1] + minsl[v<<1]);   }      void build(int v, int l, int r){    if (l==r){     st[v] = 1;     maksl[v] = maksr[v] = minsl[v] = minsr[v] = st[v];     return;    }    int m = (l+r)>>1;    build(v<<1,l,m);    build(v<<1|1,m+1,r);    merge(v);   }      void update(int v, int l, int r, int x, int val){    if (l==r){     st[v] = val;     maksl[v] = maksr[v] = minsl[v] = minsr[v] = st[v];     return;    }    int m = (l+r)>>1;    if (x <= m) update(v<<1,l,m,x,val);    else update(v<<1|1,m+1,r,x,val);    merge(v);   // cout<<v<<   <<maksl[v]<<   <<maksr[v]<<  n ;   }      int querysum(int v, int l, int r, int ss, int se){    if (ss > se) return 0;    if (l==ss && r==se) return st[v];    int m = (l+r)>>1;    return querysum(v<<1,l,m,ss,min(se,m)) + querysum(v<<1|1,m+1,r,max(m+1,ss),se);   }      int querymaksr(int v, int l, int r, int ss, int se){    if (ss > se) return -1e9;    if (l == ss && r == se) return maksr[v];    int m = (l+r)>>1;    ll res = max(querymaksr(v<<1,l,m,ss,min(m,se)), querysum(1,0,n-1,ss,min(m,se)) + querymaksr(v<<1|1,m+1,r,max(m+1,ss),se));    return res;   }      int querymaksl(int v, int l, int r, int ss, int se){    if (ss > se) return -1e9;    if (l == ss && r == se) return maksl[v];    int m = (l+r)>>1;    return max(querysum(1,0,n-1,max(m+1,ss),se) + querymaksl(v<<1,l,m,ss,min(m,se)), querymaksl(v<<1|1,m+1,r,max(m+1,ss),se));    }      int queryminsr(int v, int l, int r, int ss, int se){    if (ss > se) return 1e9;    if (l == ss && r == se) return minsr[v];    int m = (l+r)>>1;    return min(queryminsr(v<<1,l,m,ss,min(m,se)), querysum(1,0,n-1,ss,min(m,se)) + queryminsr(v<<1|1,m+1,r,max(m+1,ss),se));   }      int queryminsl(int v, int l, int r, int ss, int se){    if (ss > se) return 1e9;    if (l == ss && r == se) return minsl[v];    int m = (l+r)>>1;    return min(querysum(1,0,n-1,max(m+1,ss),se) + queryminsl(v<<1,l,m,ss,min(m,se)), queryminsl(v<<1|1,m+1,r,max(m+1,ss),se));   }      ll ans[N];   void solve(){    cin>>n;    rep(i,0,n) {     int x; cin>>x;     vec[x].pb(i);    }        build(1,0,n-1);     rep(i,1,n+1){     for(auto j : vec[i]){      ll ma1 = max(0,querymaksl(1,0,n-1,0,j-1));      ll ma2 = max(0,querymaksr(1,0,n-1,j+1,n-1));      ll mk = ma1+ma2+1;         ans[j] = max(ans[j], mk/2);     }                rep(j,0,vec[i].sz) update(1,0,n-1,vec[i][j],-1);          for(auto j : vec[i]){         ll mi1 = min(0,queryminsl(1,0,n-1,0,j-1));      ll mi2 = min(0,queryminsr(1,0,n-1,j+1,n-1));      ll mn = -(mi1+mi2)+1;      ans[j] = max(ans[j], (mn-1)/2);     }    }    rep(i,0,n) cout<<ans[i]<<   ;    cout<<  n ;   }      int main()   {    nonint();   //  freopen( input.txt ,  r , stdin);   //  freopen( output.txt ,  w , stdout);    int t=1;   // cin>>t;    while(t--){     solve();    }    return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<pair<int, pair<int, int> > > horz, vert, tmp;   set<int> y_com;   map<int, int> y_map;   void cleanup(vector<pair<int, pair<int, int> > >& v) {     sort(v.begin(), v.end());     for (auto it = v.begin(); it != v.end();) {       if (it != v.begin()) {         auto prev = it;         prev--;         if (prev->first == it->first &&             prev->second.second >= it->second.first - 1) {           prev->second.second = max(it->second.second, prev->second.second);           it = v.erase(it);         } else           it++;       } else         it++;     }   }   int BIT[211111];   void update(int pos, int val) {     while (pos < 211111) {       BIT[pos] += val;       pos += (pos & (-pos));     }   }   int get(int pos) {     int ans = 0;     while (pos > 0) {       ans += BIT[pos];       pos -= (pos & (-pos));     }     return ans;   }   int main() {     ios_base::sync_with_stdio(false);     int n;     cin >> n;     long long ans = 0;     for (int i = 0; i < n; i++) {       int x[2], y[2];       cin >> x[0] >> y[0] >> x[1] >> y[1];       x[0] += 1000000001;       x[1] += 1000000001;       y[0] += 1000000001;       y[1] += 1000000001;       if (y[0] == y[1]) {         horz.push_back(             make_pair(y[0], make_pair(min(x[0], x[1]), max(x[0], x[1]))));       } else {         vert.push_back(             make_pair(x[0], make_pair(min(y[0], y[1]), max(y[0], y[1]))));       }     }     cleanup(horz);     cleanup(vert);     for (auto it : horz) {       ans += it.second.second - it.second.first + 1;       y_com.insert(it.first);     }     for (auto it : vert) {       ans += it.second.second - it.second.first + 1;       y_com.insert(it.second.first);       y_com.insert(it.second.second);     }     int cnt = 1;     for (auto it : y_com) y_map[it] = cnt++;     for (auto it : horz) {       tmp.push_back(make_pair(it.second.first, make_pair(it.first, 1)));       tmp.push_back(make_pair(it.second.second + 1, make_pair(it.first, -1)));     }     sort(tmp.begin(), tmp.end());     int cur = 0;     for (auto it : vert) {       while (cur < tmp.size() && tmp[cur].first <= it.first) {         update(y_map[tmp[cur].second.first], tmp[cur].second.second);         cur++;       }       ans -= get(y_map[it.second.second]) - get(y_map[it.second.first] - 1);     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-7;   const int inf = 0x3f3f3f3f;   const int hinf = 0x3f3f3f3f;   const long long mod = 1000000009;   struct node {     int l, r;     double expe;     double add;   } sgt[100010 << 2];   int n, m;   int a[100010], h[100010], l[100010], r[100010];   struct mushroom {     int b, z;     bool operator<(const mushroom& bb) const { return b < bb.b; }   } dat[100010];   void up(int root) {     sgt[root].expe = sgt[root << 1].expe + sgt[root << 1 | 1].expe;   }   void down(int root) {     sgt[root << 1].add *= sgt[root].add;     sgt[root << 1].expe *= sgt[root].add;     sgt[root << 1 | 1].add *= sgt[root].add;     sgt[root << 1 | 1].expe *= sgt[root].add;     sgt[root].add = 1.0;   }   void build(int l, int r, int root) {     sgt[root].l = l;     sgt[root].r = r;     sgt[root].expe = 0.0;     sgt[root].add = 1.0;     if (l == r) {       sgt[root].expe = dat[sgt[root].l].z;       return;     }     int mid = (l + r) >> 1;     build(l, mid, root << 1);     build(mid + 1, r, root << 1 | 1);     up(root);   }   void upd(int l, int r, double val, int root) {     if (l > dat[sgt[root].r].b || r < dat[sgt[root].l].b) return;     if (dat[sgt[root].l].b >= l && dat[sgt[root].r].b <= r) {       sgt[root].add *= val;       sgt[root].expe *= val;       return;     }     down(root);     int mid = (sgt[root].l + sgt[root].r) >> 1;     if (l <= dat[mid].b) upd(l, r, val, root << 1);     if (r >= dat[mid].b) upd(l, r, val, root << 1 | 1);     up(root);   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) {       scanf( %d%d%d%d , &a[i], &h[i], &l[i], &r[i]);     }     for (int i = 1; i <= m; i++) {       scanf( %d%d , &dat[i].b, &dat[i].z);     }     sort(dat + 1, dat + 1 + m);     build(1, m, 1);     for (int i = 1; i <= n; i++) {       upd(a[i] - h[i], a[i] - 1, 1.0 - l[i] / 100.0, 1);       upd(a[i] + 1, a[i] + h[i], 1.0 - r[i] / 100.0, 1);     }     printf( %.15lf n , sgt[1].expe);   }


#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-9;   const long long int MOD1 = 1e9 + 7;   const long long int MAX5 = 1e5;   const long long int MAX6 = 1e6;   const long long int MAX7 = 1e7;   const long long int MAX8 = 1e8;   const long long int MAX9 = 1e9;   const long long int MAX10 = 1e10;   const long long int MAXX = 1e18;   long long int pow(long long int x, long long int y) {     long long int res = 1;     while (y > 0) {       res = res * x;       x = x * x;       y >>= 1;     }     return res;   }   long long int gcd(int a, int b) {     if (a < b) swap(a, b);     if (b == 0) return a;     return gcd(a % b, b);   }   void solve() {     int n, q;     cin >> n >> q;     set<int> p;     for (int ii = 0; ii < n; ii++) {       int aa;       cin >> aa;       p.insert(aa);     }     auto it = p.begin();     multiset<int> m;     m.insert(0);     for (int ii = 0; ii < p.size() - 1; ii++) {       int x = *it;       it++;       m.insert(x - *it);     }     cout << *p.rbegin() - *p.begin() + *m.begin();     cout <<   n ;     ;     for (int ii = 0; ii < q; ii++) {       int t, x;       cin >> t >> x;       int y, z;       bool Y = false, Z = false;       if (t == 0) {         it = p.find(x);         if (it != p.begin()) {           it--;           y = *it;           Y = true;           m.erase(m.find(y - x));         }         it = p.find(x);         if (it != (--p.end())) {           it++;           z = *it;           Z = true;           m.erase(m.find(x - z));         }         if (Y && Z) m.insert(y - z);         p.erase(x);       }       if (t == 1) {         p.insert(x);         it = p.find(x);         if (it != p.begin()) {           it--;           y = *it;           Y = true;           m.insert(y - x);         }         it = p.find(x);         if (it != (--p.end())) {           it++;           z = *it;           Z = true;           m.insert(x - z);         }         if (Y && Z) m.erase(m.find(y - z));       }       if (!p.empty())         cout << *p.rbegin() - *p.begin() + *m.begin();       else         cout << 0;       cout <<   n ;       ;     }   }   int main() {     { solve(); }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     pair<int, int> mmx[3];     for (int i = 0; i < 3; i++) cin >> mmx[i].first >> mmx[i].second;     int a, b, c;     a = min(n - mmx[1].first - mmx[2].first, mmx[0].second);     b = min(n - a - mmx[2].first, mmx[1].second);     c = n - a - b;     cout << a <<     << b <<     << c;     return 0;   }


#include<bits/stdc++.h>      using namespace :: std;      #define ll long long   #define mp make_pair   #define ld long double   #define F first   #define S second   #define pii pair<int,int>   #define pb push_back      const int maxn=2e5+500;   const int inf=1e9+900;   const int mod=1e9+7;      pair<int,int> tip,che;      ld lenght(pair<ld,ld> a){    return sqrt(a.F*a.F+a.S*a.S);   }   bool mibin(pair<ld,ld> x){     complex<ld> a,b;     a.real(((ld)(che.F)-(x.F)));     a.imag(((ld)(che.S)-(x.S)));     b.real(((ld)(che.F)-(tip.F)));     b.imag(((ld)(che.S)-(tip.S)));     a*=-1;     b*=-1;     if(arg(a)<=0 && arg(b)<=0){      return (arg(a)<=arg(b));     }     if(arg(a)>=0 && arg(b)>=0){      return (arg(a)<=arg(b));     }     if(arg(a)>=0 && arg(b)<=0){      return 1;     }     if(arg(a)<=0 && arg(b)>=0){      return 0;     }     return (arg(a)<=arg(b));   }      void add(pair<int,int> x){    if(mibin(mp((ld)x.F,(ld)x.S))){     tip=x;    }   }   ld mibine(pair<int,int> s,pair<int,int> t){    pair<int,int> v=mp(t.F-s.F,t.S-s.S);    if(!mibin(s)){    // cout<< NOting n ;     return 0;    }    if(mibin(t)){    // cout<< ALL n ;     return lenght(v);    }    ld b=0;    ld e=1;    for(int i=0;i<60;i++){     ld mid=(e+b)/2;     if(mibin(mp((s.F)+mid*(v.F),(s.S)+mid*(v.S)))){      b=mid;     }else{      e=mid;     }    }   // cout<<b<<endl;    return lenght(v)*b;   }         int x[maxn];   int y[maxn];         int main(){    ios_base::sync_with_stdio(false);    cin.tie(0);       int n,h;    cin>>n>>h;    for(int i=0;i<n;i++){     cin>>x[i]>>y[i];    }    ld ans=lenght(mp(x[n-1]-x[n-2],y[n-1]-y[n-2]));    tip=mp(x[n-2],y[n-2]);    che=mp(x[n-1],y[n-1]+h);    for(int i=n-3;i>=0;i--){     add(mp(x[i+1],y[i+1]));     ans+=mibine(mp(x[i],y[i]),mp(x[i+1],y[i+1]));    }    cout<<fixed<<setprecision(10)<<ans;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   T read1() {     T t = 0;     char k;     bool v = 0;     do (k = getchar()) ==  -  && (v = 1);     while ( 0  > k || k >  9 );     while ( 0  <= k && k <=  9 )       t = (t << 3) + (t << 1) + (k ^  0 ), k = getchar();     return v ? -t : t;   }   int v[1200005], s, fl[1200005], w[1200005];   vector<pair<int, pair<int, int> > > a[300005], b;   void down(int d) {     fl[d << 1] += fl[d];     fl[d << 1 | 1] += fl[d];     v[d << 1] += fl[d];     v[d << 1 | 1] += fl[d];     fl[d] = 0;   }   void up(int d) {     v[d << 1] > v[d << 1 | 1] ? (w[d] = w[d << 1], v[d] = v[d << 1])                               : (w[d] = w[d << 1 | 1], v[d] = v[d << 1 | 1]);   }   void add(int l, int r, int x, int y, int z, int d) {     if (l == x && r == y) {       v[d] += z, fl[d] += z;       return;     }     down(d);     int mid = l + r >> 1;     if (y <= mid)       add(l, mid, x, y, z, d << 1);     else if (mid < x)       add(mid + 1, r, x, y, z, d << 1 | 1);     else       add(l, mid, x, mid, z, d << 1), add(mid + 1, r, mid + 1, y, z, d << 1 | 1);     up(d);   }   void build(int l, int r, int d) {     if (l == r)       w[d] = l;     else {       build(l, l + r >> 1, d << 1);       build(l + r + 2 >> 1, r, d << 1 | 1);       w[d] = w[d << 1];     }   }   int wh, g;   int main() {     s = read1<long long>();     build(1, 300000, 1);     for (int i = 1; i <= s; ++i) {       int l = read1<long long>(), v = read1<long long>(), r = read1<long long>();       b.push_back(make_pair(l, make_pair(v, r)));       a[l].push_back(make_pair(1, make_pair(v, r)));       a[v + 1].push_back(make_pair(-1, make_pair(v, r)));     }     int ans = 0;     for (int i = 1; i <= 300000; ++i) {       for (int j = 0; j < a[i].size(); ++j)         add(1, 300000, a[i][j].second.first, a[i][j].second.second, a[i][j].first,             1);       if (v[1] > ans) ans = v[1], wh = i, g = w[1];     }     cout << ans << endl;     for (int i = 0; i < s; ++i)       if (b[i].first <= wh && wh <= b[i].second.first && b[i].second.first <= g &&           g <= b[i].second.second)         printf( %d  , i + 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int c, d, n, m, k;     cin >> c >> d >> n >> m >> k;     int users = n * m - k;     int ans = 1000000000;     for (int i = 0; i <= m; i++)       for (int j = 0; j <= 10000; j++) {         if (i * n + j >= users) {           if (c * i + j * d < ans) ans = c * i + j * d;         }       }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int i;     int n, d, l;     cin >> n >> d >> l;     int pos = (n + 1) / 2;     int neg = n / 2;     int a[n + 1];     if (d > (pos * l - neg) || d < (pos - neg * l)) {       cout <<  -1 ;       return 0;     }     if (d > 0) {       for (i = 1; i <= n; i++) a[i] = 1;       i = 1;       if (n & 1) d--;       while (d) {         a[2 * i - 1] += min(l - 1, d);         d -= min(l - 1, d);         i++;       }     } else {       for (i = 1; i <= n; i++) a[i] = 1;       i = 1;       d = -d;       if (n & 1) d++;       while (d) {         a[2 * i] += min(l - 1, d);         d -= min(l - 1, d);         i++;       }     }     for (i = 1; i <= n; i++) cout << a[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 2e5 + 10;   int n, m;   bool lie[40];   int ask(int d) {     int ret;     cout << d << endl;     cin >> ret;     if (ret == 0) exit(0);     return ret;   }   int main() {     cin >> m >> n;     for (int i = 0; i < n; i++)       if (ask(m) == 1) lie[i] = true;     int l = 1, r = m;     int cnt = 0;     while (l < r) {       int mid = l + (r - l) / 2;       int ans = ask(mid);       if (lie[(cnt++) % n]) ans = -ans;       if (ans > 0)         l = mid + 1;       else         r = mid - 1;     }     ask(l);   }


#include <bits/stdc++.h>   using namespace std;   vector<long long int> v1, v2;   vector<char> v4;   string s1, s2, s3;   long long int visited[2000005];   set<char> st;   set<long long int>::iterator it;   int main() {     long long int a, b, c, d, e, f, i, j, k,         cnt1 = 0, cnt2 = 0, sum1 = 0, sum2 = 0, first, chk1 = 0, chk2 = 0, T;     cin >> a >> b;     char xx;     long long int indx, chk = 0;     cin >> s1;     s2 = s1;     for (i = 0; i < a; i++) {       if (visited[i] == 0) {         v1.push_back(i);         for (j = i; j < a; j += b) {           visited[j] = 1;           s1[j] = s1[i];         }       }     }     for (i = 0; i < a; i++) {       if (s1[i] > s2[i]) {         chk = 1;         for (j = 0; j < v1.size(); j++) {           if (v1[j] > i) {             for (int k = v1[j]; k < a; k += b) {               s1[k] =  0 ;             }           }         }         break;       } else if (s1[i] == s2[i])         cnt1++;       else {         first = i;         break;       }     }     if (cnt1 == a) chk = 1;     if (chk == 0) {       long long int x = upper_bound(v1.begin(), v1.end(), first) - v1.begin();       x--;       xx = s1[v1[x]];       if (xx ==  9 ) {         for (i = x - 1; i >= 0; i--) {           if (s1[v1[i]] !=  9 ) {             xx = s1[v1[i]] + 1;             for (j = v1[i]; j < a; j += b) {               s1[j] = xx;             }             for (j = i + 1; j < v1.size(); j++) {               if (s1[v1[j]] !=  0 ) {                 for (int k = v1[j]; k < a; k += b) {                   s1[k] =  0 ;                 }               }             }             break;           }         }       } else {         for (i = v1[x]; i < a; i += b) {           s1[i] = xx + 1;         }       }     }     cout << s1.size() << endl;     cout << s1 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int d[1000000];   int main() {     int n, k;     scanf( %d%d , &n, &k);     for (int i = 0; i < (n); ++i) {       int(x);       scanf( %d , &x);       d[i % k] += x;     }     int mi = (int)1e9;     int id = -1;     for (int i = 0; i < (k); ++i) {       if (mi > d[i]) {         mi = d[i];         id = i;       }     }     printf( %d n , id + 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int dy[] = {-1, 0, 1, 0}, dx[] = {0, 1, 0, -1};   const double EPS = 1e-8;   const double PI = acos(-1.0);   int popcount(int n) { return __builtin_popcount(n); }   int popcount(long long n) { return __builtin_popcountll(n); }   template <class T>   int SIZE(T a) {     return a.size();   }   template <class T>   string IntToString(T num) {     string res;     stringstream ss;     ss << num;     return ss.str();   }   template <class T>   T StringToInt(string str) {     T res = 0;     for (int i = 0; i < SIZE(str); i++) res = (res * 10 + str[i] -  0 );     return res;   }   template <class T>   T gcd(T a, T b) {     if (b == 0) return a;     return gcd(b, a % b);   }   template <class T>   T lcm(T a, T b) {     return a / gcd(a, b) * b;   }   template <class T>   void PrintSeq(T &a, int sz) {     for (int i = 0; i < sz; i++) {       cout << a[i];       if (sz == i + 1)         cout << endl;       else         cout <<    ;     }   }   bool EQ(double a, double b) { return abs(a - b) < EPS; }   void fastStream() {     cin.tie(0);     std::ios_base::sync_with_stdio(0);   }   vector<string> split(string str, char del) {     vector<string> res;     for (int i = 0, s = 0; i < SIZE(str); i++) {       if (str[i] == del) {         if (i - s != 0) res.push_back(str.substr(s, i - s));         s = i + 1;       } else if (i == SIZE(str) - 1) {         res.push_back(str.substr(s));       }     }     return res;   }   int N;   long long as[100001];   long long leftDP[2][100001];   long long rightDP[2][100001];   long long goLeft(int pari, int pos) {     if (leftDP[pari][pos] >= 0) return leftDP[pari][pos];     long long res = 0;     if (pos == 0) {     } else {       if (pari == 0) {         res = max(res,                   goLeft(pari, pos - 1) + as[pos - 1] - (as[pos - 1] % 2 == 0));         if (as[pos - 1] != 1)           res = max(res, goLeft(pari ^ 1, pos - 1) + as[pos - 1] -                              (as[pos - 1] % 2 == 1));       } else {         if (as[pos - 1] != 1)           res = max(res,                     goLeft(pari, pos - 1) + as[pos - 1] - (as[pos - 1] % 2 == 1));       }     }     return leftDP[pari][pos] = res;   }   long long goRight(int pari, int pos) {     if (rightDP[pari][pos] >= 0) return rightDP[pari][pos];     long long res = 0;     if (pos == N - 1) {     } else {       if (pari == 0) {         res = max(res, goRight(pari, pos + 1) + as[pos] - (as[pos] % 2 == 0));         if (as[pos] != 1)           res =               max(res, goRight(pari ^ 1, pos + 1) + as[pos] - (as[pos] % 2 == 1));       } else {         if (as[pos] != 1)           res = max(res, goRight(pari, pos + 1) + as[pos] - (as[pos] % 2));       }     }     return rightDP[pari][pos] = res;   }   int main() {     memset(leftDP, -1, sizeof(leftDP));     memset(rightDP, -1, sizeof(rightDP));     cin >> N;     for (int i = 0; i < N - 1; i++) cin >> as[i];     long long res = 0;     for (int i = 0; i < N; i++) {       res = max(res, goLeft(1, i) + goRight(1, i));       res = max(res, goLeft(1, i) + goRight(0, i));       res = max(res, goLeft(0, i) + goRight(1, i));     }     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int dirty[3009];   int main() {     int n, m;     cin >> n >> m;     for (typeof(0) i = (0); i < (m); i++) cin >> dirty[i];     sort(dirty, dirty + m);     if (!m)       cout <<  YES n ;     else if ((dirty[0] != 1) && (dirty[m - 1] != n)) {       if (m < 3)         cout <<  YES n ;       else {         bool YES = true;         for (typeof(0) i = (0); i < (m - 2); i++)           if ((dirty[i] == (dirty[i + 1] - 1)) &&               (dirty[i + 1] == (dirty[i + 2] - 1)))             YES = false;         if (YES)           cout <<  YES n ;         else           cout <<  NO n ;       }     } else       cout <<  NO n ;     return 0;   }


#include <bits/stdc++.h>   const double pi = acos(-1.0);   using namespace std;   inline long long MAX2(long long a, long long b) {     return (a) > (b) ? (a) : (b);   }   inline long long MAX3(long long a, long long b, long long c) {     return (a) > (b) ? ((a) > (c) ? (a) : (c)) : ((b) > (c) ? (b) : (c));   }   inline long long MIN2(long long a, long long b) {     return (a) < (b) ? (a) : (b);   }   inline long long MIN3(long long a, long long b, long long c) {     return (a) < (b) ? ((a) < (c) ? (a) : (c)) : ((b) < (c) ? (b) : (c));   }   int mod = 1e9 + 7;   int64_t extGcd(int64_t a, int64_t b, int64_t& x, int64_t& y) {     if (!a) {       x = 0;       y = 1;       return b;     }     int64_t x1, y1;     int64_t d = extGcd(b % a, a, x1, y1);     x = y1 - (b / a) * x1;     y = x1;     return d;   }   inline long long addmod(long long a, long long b) {     a = a % mod + b % mod;     if (a > mod) a %= mod;     return a;   }   inline long long submod(long long a, long long b) {     a = a % mod - b % mod;     if (a < 0) a += mod;     return a;   }   inline long long mulmod(long long a, long long b) {     return (a % mod * b % mod) % mod;   }   int dx[] = {1, 1, 0, -1, -1, -1, 0, 1};   int dy[] = {0, 1, 1, 1, 0, -1, -1, -1};   inline long long exp(long long a, long long b) {     if (a == 0) return 0ll;     long long r = 1LL;     while (b > 0) {       if (b & 1) {         r = r * (a % mod);         r = (r + mod) % mod;       }       b /= 2;       a = (a % mod) * (a % mod);       a = (a + mod) % mod;     }     return (r + mod) % mod;   }   long long gcd(long long a, long long b) {     if (b == 0) return a;     if (a == 0) return b;     return gcd(b, a % b);   }   unsigned long int setbits(long long n) {     unsigned long int count = 0;     while (n) {       n &= (n - 1);       count++;     }     return count;   }   int main() {     if (fopen( input.txt ,  r ))       freopen( input.txt ,  r , stdin), freopen( output.txt ,  w , stdout);     ;     int t;     cin >> t;     while (t--) {       int n, k, z;       cin >> n >> k >> z;       long long a[n];       long long pre[n + 1];       pre[0] = 0;       for (long long i = (long long)(0); i < (long long)(n); i++) {         cin >> a[i];         pre[i + 1] = pre[i] + a[i];       }       long long ans = 0;       long long curr_sum = a[0];       for (int i = 1; i <= min(k, n - 1); i++) {         curr_sum += a[i];         long long prev = a[i - 1];         long long last = a[i];         int rem = (k - i);         int resz = z;         long long res = curr_sum;         int nxt = i;         while (resz > 0 and rem > 0) {           if (rem <= 0) {             nxt = i;             break;           }           res += prev;           resz--;           rem--;           if (rem <= 0) {             nxt = i - 1;             break;           }           res += last;           rem--;         }         res += pre[nxt + rem + 1] - pre[nxt + 1];         ans = MAX2(ans, res);       }       cout << ans <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   unsigned long long B[31][31], res = 0;   int main(void) {     for (int i = 0; i <= 30; i++) {       B[i][0] = B[i][i] = 1;       for (int j = 1; j < i; j++) B[i][j] = B[i - 1][j - 1] + B[i - 1][j];     }     int n, m, k;     cin >> n >> m >> k;     for (int b = 4; b < k; b++) {       res += (b <= n && k - b <= m) ? B[n][b] * B[m][k - b] : 0;     }     cout << res;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1000005;   const int SQRTN = 1003;   const int LOGN = 22;   const double PI = acos(-1);   const int INF = 1e9;   int MOD = 1000000007;   const int FMOD = 998244353;   const double eps = 1e-9;   long long gcd(long long a, long long b) {     if (a == 0) return (b);     return (gcd(b % a, a));   }   long long lcm(long long a, long long b) { return (a / gcd(a, b) * b); }   void solve() {     long long n, m1;     cin >> n >> m1;     long long x, k, y;     cin >> x >> k >> y;     long long arr[n];     for (int i = 0; i < n; i++) cin >> arr[i];     long long brr[m1];     for (int i = 0; i < m1; i++) cin >> brr[i];     bool flag = false;     long long i = 0, j = 0, m = -1, pos, l = -1, r;     long long result = 0;     while (i < n && j < m1) {       if (flag == true) break;       m = max(m, arr[i]);       if (m == arr[i]) pos = i;       if (arr[i] != brr[j])         i++;       else {         r = i;         i++;         j++;         int len = r - l - 1;         if (pos > l && pos < r && len < k) {           flag = true;           break;         } else {           long long c1, c2;           if (len % k == 0)             c1 = x * (len / k);           else             c1 = x * (len / k) + (len - k * (len / k)) * y;           c2 = y * len;           if (pos > l && pos < r) c2 = y * (len - k) + x;           result += min(c1, c2);         }         l = r;         m = arr[l];       }     }     if (j == m1 && i < n) {       m = arr[i - 1];       pos = i - 1;       l = i - 1;       r = n;       int len = 0;       while (i < n) {         m = max(m, arr[i]);         if (m == arr[i]) pos = i;         i++;         len++;       }       if (pos > l && pos < r && len < k)         flag = true;       else {         long long c1, c2;         if (len % k == 0)           c1 = x * (len / k);         else           c1 = x * (len / k) + (len - k * (len / k)) * y;         c2 = y * len;         if (pos > l && pos < r) c2 = (len - k) * y + x;         result += min(c1, c2);       }     }     if (i == n && j < m1) {       cout << -1 <<   n ;     } else {       if (flag)         cout << -1 <<   n ;       else         cout << result <<   n ;     }   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long t = 1;     while (t--) {       solve();     }     return (0);   }


#include <bits/stdc++.h>   using namespace std;   const int NMax = 1100000;   inline int read() {     int x = 0;     char ch = getchar();     bool positive = 1;     for (; ch <  0  || ch >  9 ; ch = getchar())       if (ch ==  - ) positive = 0;     for (; ch >=  0  && ch <=  9 ; ch = getchar()) x = x * 10 + ch -  0 ;     return positive ? x : -x;   }   struct node {     int w, id, sz;     node *left, *right;     int lsize() { return left ? left->sz : 0; }     int rsize() { return right ? right->sz : 0; }   } * T, pool[NMax];   void update(node *p) {     if (!p) return;     p->sz = p->lsize() + p->rsize() + 1;   }   int L;   struct pnn {     node *x, *y;   };   pnn mp(node *x, node *y) {     pnn ret;     ret.x = x;     ret.y = y;     return ret;   }   node *new_node(int id) {     node *p = &pool[L++];     p->w = rand() * rand();     p->id = id;     p->sz = 1;     p->left = p->right = NULL;     return p;   }   node *new_node(int id, int w) {     node *p = &pool[L++];     p->w = w;     p->id = id;     p->sz = 1;     p->left = p->right = NULL;     return p;   }   int N, M;   node *merge(node *a, node *b) {     if (!a) return b;     if (!b) return a;     if (b->w > a->w) {       a->right = merge(a->right, b);       update(a);       return a;     } else {       b->left = merge(a, b->left);       update(b);       return b;     }   }   pnn split(node *a, int l) {     if (!a) return mp((node *)NULL, (node *)NULL);     if (l >= a->sz) return mp(a, (node *)NULL);     if (l <= 0) return mp((node *)NULL, a);     if (l <= a->lsize()) {       pnn ret = split(a->left, l);       a->left = ret.y;       update(a);       ret.y = a;       return ret;     } else {       pnn ret = split(a->right, l - a->lsize() - 1);       a->right = ret.x;       update(a);       ret.x = a;       return ret;     }   }   int have[NMax], chose[NMax], nn;   int oper[NMax];   void DFS(node *p) {     if (p->left) DFS(p->left);     if (p->id == -1) p->id = chose[nn++];     if (p->right) DFS(p->right);   }   void DFS1(node *p) {     if (p->left) DFS1(p->left);     printf( %d  , p->id);     if (p->right) DFS1(p->right);   }   node *Build(int x, int y, int w) {     if (x == y) {       node *p = new_node(-1, w);       return p;     }     int mid = (x + y) >> 1;     node *p = new_node(-1, w);     if (mid > x) p->left = Build(x, mid - 1, w + rand());     if (mid < y) p->right = Build(mid + 1, y, w + rand());     update(p);     return p;   }   int main() {     N = read();     M = read();     T = Build(1, N, -100000000);     for (int i = 1; i <= M; i++) {       int x, y;       x = read();       y = read();       swap(x, y);       oper[i] = x;       pnn tmp = split(T, x - 1);       pnn tmq = split(tmp.y, 1);       if (have[y] && tmq.x->id != y) {         puts( -1 );         getchar();         getchar();         return 0;       }       have[y] = 1;       if (tmq.x->id != -1 && tmq.x->id != y) {         puts( -1 );         getchar();         getchar();         return 0;       }       tmq.x->id = y;       tmp.x = merge(tmq.x, tmp.x);       T = merge(tmp.x, tmq.y);     }     for (int i = 1; i <= N; i++)       if (!have[i]) chose[nn++] = i;     nn = 0;     DFS(T);     for (int i = M; i >= 1; i--) {       pnn tmp = split(T, oper[i]);       pnn tmq = split(tmp.x, 1);       tmp.x = merge(tmq.y, tmq.x);       T = merge(tmp.x, tmp.y);     }     DFS1(T);     puts(  );     getchar();     getchar();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, cnt[100015], x[100015], y[100015], z[100015];   vector<int> a[100015];   int getpos(int i, int u) {     if (x[i] == u) return 0;     if (y[i] == u) return 1;     if (z[i] == u) return 2;   }   void dfs(int u, int v) {     cout << u <<    ;     if (cnt[v] == 0) {       cout << v;       return;     }     for (int i : a[u])       if (i) {         --cnt[x[i]];         --cnt[y[i]];         --cnt[z[i]];         int k = 3 - getpos(i, u) - getpos(i, v);         for (int &j : a[x[i]])           if (j == i) j = 0;         for (int &j : a[y[i]])           if (j == i) j = 0;         for (int &j : a[z[i]])           if (j == i) j = 0;         if (k == 0) dfs(v, x[i]);         if (k == 1) dfs(v, y[i]);         if (k == 2) dfs(v, z[i]);       }   }   int main() {     cin >> n;     for (int i = 1; i <= n - 2; ++i)       cin >> x[i] >> y[i] >> z[i], a[x[i]].push_back(i), a[y[i]].push_back(i),           a[z[i]].push_back(i), ++cnt[x[i]], ++cnt[y[i]], ++cnt[z[i]];     for (int i = 1; i <= n; ++i)       if (cnt[i] == 1) {         if (cnt[x[a[i][0]]] == 2) dfs(i, x[a[i][0]]);         if (cnt[y[a[i][0]]] == 2) dfs(i, y[a[i][0]]);         if (cnt[z[a[i][0]]] == 2) dfs(i, z[a[i][0]]);       }   }


#include <bits/stdc++.h>   const int INF = 1e7;   using namespace std;   const int N = 20;   int n, m;   int c[N];   int a[N];   int like[N];   string s[N];   int T_res = 0;   int Lika = 0;   bool Check_Res() {     int Lik;     for (int i = 2; i <= m; i++) {       {         Lik = 0;         for (int j = 0; j <= n - 1; j++)           if (a[j] == (s[i][j] -  0 )) Lik++;         if (Lik != like[i]) return false;       }     }     return true;   }   void attempt(int i, int same) {     if (i == n) {       if (same == like[1] && Check_Res() == true) {         T_res++;       }       return;     }     a[i] = !((s[1][i]) -  0 );     attempt(i + 1, same);     if (same < like[1]) {       a[i] = (s[1][i] -  0 );       attempt(i + 1, same + 1);     }   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= m; i++) {       cin >> s[i];       cin >> like[i];     }     attempt(0, 0);     cout << T_res;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     long long n;     cin >> n;     long long out = n * (n + 1) * (n + 2) / 6;     out *= n * (n + 1) * (n + 2) * (n + 3) * (n + 4) / 120;     cout << out <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int m = 320;   struct data {     int n, x, a[2 * m + 10];     data *next;   };   data *head;   int get(int value, int limit) {     int ret = 0;     data *k;     for (k = head; k != NULL; k = k->next) {       if (k->x > value) break;       ret += k->n;     }     if (k != NULL)       for (int i = 1; i <= k->n; i++) {         if (k->a[i] > value) break;         ret++;       }     return (min(ret, limit) + 1);   }   void split(data *k) {     data *t = new (data);     t->x = k->x = 0;     for (int i = 1; i <= m; i++) {       t->a[i] = k->a[i + m];       t->x = max(t->x, t->a[i]);       k->x = max(k->x, k->a[i]);     }     k->n = t->n = m;     t->next = k->next;     k->next = t;   }   void insert(int value, int pos) {     if (head == NULL) {       head = new (data);       head->n = 1;       head->x = head->a[1] = value;       head->next = NULL;       return;     }     data *k;     for (k = head; k != NULL; k = k->next) {       if (pos <= k->n + 1) break;       pos -= k->n;     }     for (int i = k->n; i >= pos; i--) k->a[i + 1] = k->a[i];     k->a[pos] = value;     k->x = max(k->x, value);     k->n++;     if (k->n == 2 * m) split(k);   }   int ans[100010], p[100010];   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       int x, y;       scanf( %d%d , &x, &y);       p[x] = i;       int pos = get(x, y);       insert(x, pos);     }     int t = 0;     for (data *k = head; k != NULL; k = k->next)       for (int i = 1; i <= k->n; i++) ans[++t] = k->a[i];     reverse(ans + 1, ans + n + 1);     for (int i = 1; i <= n; i++) printf( %d%c , p[ans[i]], i == n ?   n  :    );     return (0);   }