#include <bits/stdc++.h>   using namespace std;   template <class T>   ostream &operator<<(ostream &os, const vector<T> &v) {     for (T i : v) os << i <<  ,  ;     return os;   }   template <class T>   ostream &operator<<(ostream &os, const set<T> &v) {     for (T i : v) os << i <<    ;     return os;   }   template <class T>   ostream &operator<<(ostream &os, const multiset<T> &v) {     for (T i : v) os << i <<    ;     return os;   }   template <class T, class second>   ostream &operator<<(ostream &os, const pair<T, second> &v) {     os << v.first <<     << v.second;     return os;   }   template <class T, class second>   ostream &operator<<(ostream &os, const map<T, second> &v) {     for (auto i : v) os <<  (  << i.first <<   =>   << i.second <<  )  <<    ;     return os;   }   void fast() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);   }   int n, k;   long long x;   vector<long long> v;   void solve() {     int zero = 0, pos = 0, neg = 0;     for (long long &i : v) {       if (i == 0)         zero++;       else if (i > 0)         pos++;       else         neg++;     }     if (zero > k) {       for (long long &i : v) cout << i <<    ;       cout <<   n ;       return;     }     if (zero) {       if (neg % 2 == 1) {         for (long long &i : v)           if (i == 0 && k > 0) i += x, k--;       } else {         bool f = 0;         for (long long &i : v) {           if (i == 0 && k > 0) {             if (f == 0)               i -= x;             else               i += x;             f = 1;             k--;           }         }       }     }     int f = 0;     for (long long &i : v)       if (i < 0) f ^= 1;     if (f == 0) {       int idx = 0;       for (int i = 0; i < n; i++) {         if (abs(v[i]) < abs(v[idx])) idx = i;       }       if (v[idx] < 0) {         while (v[idx] <= 0 && k > 0) {           v[idx] += x;           k--;         }       } else {         while (v[idx] >= 0 && k > 0) {           v[idx] -= x;           k--;         }       }     }     set<pair<long long, int>> s;     for (int i = 0; i < n; i++) {       s.insert({abs(v[i]), i});     }     while (k > 0) {       auto it = *s.begin();       s.erase(s.begin());       if (v[it.second] < 0)         v[it.second] -= x;       else         v[it.second] += x;       s.insert({abs(v[it.second]), it.second});       k--;     }     for (long long &i : v) cout << i <<    ;     cout <<   n ;   }   int main() {     fast();     cin >> n >> k >> x;     for (int i = 0; i < n; i++) {       long long a;       cin >> a;       v.push_back(a);     }     solve();   }


#include <bits/stdc++.h>   using namespace std;   struct BookInfo {     int t;     int a;     int b;     int i;   };   struct CombinedBook {     int t;     BookInfo b1;     BookInfo b2;     bool isCombined;   };   int main() {     ios_base::sync_with_stdio(0);     cout << fixed << setprecision(10);     cerr << fixed << setprecision(10);     cin.tie(0);     int n, k;     cin >> n >> k;     vector<BookInfo> allBooks;     int aliceLikes = 0;     int bobLikes = 0;     for (int i = 0; i < n; i++) {       BookInfo info;       cin >> info.t >> info.a >> info.b;       info.i = i + 1;       if (info.a) {         aliceLikes++;       }       if (info.b) {         bobLikes++;       }       allBooks.push_back(info);     }     if (aliceLikes < k || bobLikes < k) {       cout << -1 << endl;       return 0;     }     sort(allBooks.begin(), allBooks.end(),          [](const BookInfo &a, const BookInfo &b) -> bool { return a.t < b.t; });     vector<BookInfo> aliceBooks;     vector<BookInfo> bobBooks;     vector<CombinedBook> combined;     vector<BookInfo> other;     for (BookInfo &book : allBooks) {       if (book.a && book.b) {         CombinedBook item;         item.t = book.t;         item.b1 = book;         item.b2 = book;         item.isCombined = false;         combined.push_back(item);       } else if (!book.a && !book.b) {         other.push_back(book);       } else if (book.a) {         aliceBooks.push_back(book);       } else if (book.b) {         bobBooks.push_back(book);       }     }     for (int i = 0; i < n; i++) {       if (i < aliceBooks.size() && i < bobBooks.size()) {         CombinedBook item;         item.isCombined = true;         item.b1 = aliceBooks[i];         item.b2 = bobBooks[i];         item.t = item.b1.t + item.b2.t;         combined.push_back(item);       } else if (i < aliceBooks.size()) {         other.push_back(aliceBooks[i]);       } else if (i < bobBooks.size()) {         other.push_back(bobBooks[i]);       }     }     if (combined.size() < k) {       cout << -1 << endl;       return 0;     }     sort(combined.begin(), combined.end(),          [](const CombinedBook &a, const CombinedBook &b) -> bool {            return a.t < b.t;          });     vector<int> result;     int sum = 0;     int leftLikes = k;     for (int i = 0; i < k; i++) {       sum += combined[i].t;     }     cout << sum << endl;   }


#include <bits/stdc++.h>   template <typename Tp>   inline void read(Tp &x) {     x = 0;     bool f = true;     char ch = getchar();     for (; ch <  0  || ch >  9 ; ch = getchar()) f ^= ch ==  - ;     for (; ch >=  0  && ch <=  9 ; ch = getchar()) x = x * 10 + (ch ^ 48);     x = f ? x : -x;   }   const int N = 15e4;   struct Node {     long long k, b;     bool exist;   };   struct Segment_Tree {     Node Tre[N * 4 + 5];     void build(int p, int l, int r) {       Tre[p].k = Tre[p].b = 0, Tre[p].exist = false;       if (l == r) return;       int mid = (l + r) >> 1;       build(p << 1, l, mid), build(p << 1 | 1, mid + 1, r);     }     void update(int p, int l, int r, long long k, long long b) {       if (!Tre[p].exist) {         Tre[p].exist = true;         Tre[p].k = k, Tre[p].b = b;         return;       }       long long l1 = k * l + b, r1 = k * r + b, l2 = Tre[p].k * l + Tre[p].b,                 r2 = Tre[p].k * r + Tre[p].b;       if (l1 <= l2 && r1 <= r2) return;       if (l1 >= l2 && r1 >= r2) {         Tre[p].k = k, Tre[p].b = b;         return;       }       double x = 1.0 * (b - Tre[p].b) / (Tre[p].k - k);       int mid = (l + r) >> 1;       if (l1 > l2) {         if (x <= mid)           update(p << 1, l, mid, k, b);         else {           update(p << 1 | 1, mid + 1, r, Tre[p].k, Tre[p].b);           Tre[p].k = k, Tre[p].b = b;         }       } else {         if (x <= mid) {           update(p << 1, l, mid, Tre[p].k, Tre[p].b);           Tre[p].k = k, Tre[p].b = b;         } else           update(p << 1 | 1, mid + 1, r, k, b);       }     }     long long query(int p, int l, int r, int x) {       if (l == r) return Tre[p].k * x + Tre[p].b;       int mid = (l + r) >> 1;       long long res = Tre[p].k * x + Tre[p].b;       if (x <= mid)         return std::max(res, query(p << 1, l, mid, x));       else         return std::max(res, query(p << 1 | 1, mid + 1, r, x));     }   };   Segment_Tree T;   int a[N + 5], siz[N + 5], rt, SZ, Max;   bool vis[N + 5];   long long ans;   std::vector<int> Vec[N + 5];   void find(int u, int ff) {     siz[u] = 1;     int mx = 0;     for (int i = 0; i < (int)Vec[u].size(); ++i) {       int v = Vec[u][i];       if (v == ff || vis[v]) continue;       find(v, u);       siz[u] += siz[v];       mx = std::max(mx, siz[v]);     }     mx = std::max(mx, SZ - siz[u]);     if (mx < Max) Max = mx, rt = u;   }   int m;   void dfs1(int u, int ff, int dep) {     m = std::max(m, dep);     for (int i = 0; i < (int)Vec[u].size(); ++i) {       int v = Vec[u][i];       if (vis[v] || v == ff) continue;       dfs1(v, u, dep + 1);     }   }   void dfs2(int u, int ff, long long sum, long long ssum, int dep) {     ssum += sum + a[u];     int cnt = 0;     for (int i = 0; i < (int)Vec[u].size(); ++i) {       int v = Vec[u][i];       if (v == ff || vis[v]) continue;       ++cnt;       dfs2(v, u, sum + a[u], ssum, dep + 1);     }     if (!cnt) ans = std::max(ans, ssum + T.query(1, 1, m, dep));   }   void dfs3(int u, int ff, long long sum, long long ssum, int dep) {     sum += a[u];     ssum += 1LL * dep * a[u];     int cnt = 0;     for (int i = 0; i < (int)Vec[u].size(); ++i) {       int v = Vec[u][i];       if (v == ff || vis[v]) continue;       ++cnt;       dfs3(v, u, sum, ssum, dep + 1);     }     if (!cnt) T.update(1, 1, m, sum, ssum);   }   inline void solve(int u) {     m = 0;     dfs1(u, 0, 1);     T.build(1, 1, m);     for (int i = 0; i < (int)Vec[u].size(); ++i) {       int v = Vec[u][i];       if (vis[v]) continue;       dfs2(v, u, a[u], a[u], 2);       dfs3(v, u, 0, 0, 1);     }     T.build(1, 1, m);     for (int i = (int)Vec[u].size() - 1; i >= 0; --i) {       int v = Vec[u][i];       if (vis[v]) continue;       dfs2(v, u, a[u], a[u], 2);       dfs3(v, u, 0, 0, 1);     }     ans = std::max(ans, a[u] + T.query(1, 1, m, 1));   }   void divide(int u) {     solve(u);     vis[u] = true;     for (int i = 0; i < (int)Vec[u].size(); ++i) {       int v = Vec[u][i];       if (vis[v]) continue;       SZ = Max = siz[v];       find(v, 0);       divide(rt);     }   }   int main() {     int n;     read(n);     for (int i = 1; i < n; ++i) {       int u, v;       read(u), read(v);       Vec[u].push_back(v), Vec[v].push_back(u);     }     for (int i = 1; i <= n; ++i) read(a[i]);     Max = SZ = n;     find(1, 0);     divide(rt);     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const signed int inf = (signed)((1u << 31) - 1);   const signed long long llf = (signed long long)((1ull << 61) - 1);   const double eps = 1e-6;   const int binary_limit = 128;   template <typename T>   inline bool readInteger(T& u) {     char x;     int aFlag = 1;     while (!isdigit((x = getchar())) && x !=  -  && x != -1)       ;     if (x == -1) {       ungetc(x, stdin);       return false;     }     if (x ==  - ) {       x = getchar();       aFlag = -1;     }     for (u = x -  0 ; isdigit((x = getchar())); u = (u << 1) + (u << 3) + x -  0 )       ;     ungetc(x, stdin);     u *= aFlag;     return true;   }   int n;   char a[1005];   char b[1005];   map<char, char> ctc;   const char utl =  a  -  A ;   inline void init() {     gets(a);     gets(b);     for (int i = 0; a[i]; i++) {       ctc[a[i]] = b[i];       ctc[a[i] - utl] = b[i] - utl;     }   }   inline void solve() {     gets(a);     for (int i = 0; a[i]; i++) {       if ((a[i] >=  a  && a[i] <=  z ) || (a[i] >=  A  && a[i] <=  Z )) {         putchar(ctc[a[i]]);       } else {         putchar(a[i]);       }     }   }   int main() {     init();     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXLEN = 100000;   long long have;   char s[MAXLEN + 1];   int slen;   typedef struct Node {     int start, end;     int childs[4];     int suffix;     Node(int start, int end) : start(start), end(end) {       memset(childs, -1, sizeof(childs));       suffix = -1;     }   } Node;   vector<Node> nodes;   int addnode(int start, int end) {     nodes.push_back(Node(start, end));     return ((int)(nodes).size()) - 1;   }   int create() {     int root = addnode(0, 0);     int atnode = root, atedge = 0, atlen = 0, rem = 0, prev = -1;     for (int i = 0; i < slen; ++i) {       ++rem;       prev = -1;       while (rem > 0) {         int tonode = nodes[atnode].childs[s[atedge] -  A ];         int tostart = tonode == -1 ? -1 : nodes[tonode].start;         if (tonode != -1 && nodes[tonode].start + atlen >= nodes[tonode].end) {           atedge += nodes[tonode].end - nodes[tonode].start;           atlen -= nodes[tonode].end - nodes[tonode].start;           atnode = tonode;           continue;         }         if (tonode == -1) {           int leaf = addnode(i, slen);           nodes[atnode].childs[s[atedge] -  A ] = leaf;           if (prev != -1) nodes[prev].suffix = atnode;           prev = atnode;         } else if (s[tostart + atlen] == s[i]) {           ++atlen;           if (prev != -1) nodes[prev].suffix = atnode;           prev = atnode;           break;         } else {           int branch = addnode(tostart, tostart + atlen);           nodes[tonode].start += atlen;           int leaf = addnode(i, slen);           nodes[atnode].childs[s[atedge] -  A ] = branch;           nodes[branch].childs[s[tostart + atlen] -  A ] = tonode;           nodes[branch].childs[s[i] -  A ] = leaf;           if (prev != -1) nodes[prev].suffix = branch;           prev = branch;         }         --rem;         if (atnode == root) {           if (atlen > 0) --atlen;           atedge++;         } else {           atnode = nodes[atnode].suffix;         }       }     }     return root;   }   void print(int node, int depth) {     for (int i = 0; i < depth; ++i) printf(    );     printf(   );     for (int i = nodes[node].start; i < nodes[node].end; ++i) printf( %c , s[i]);     printf(   );     printf(  -> %d , node);     if (nodes[node].suffix != -1) printf(  [%d] , nodes[node].suffix);     puts(  );     for (int i = 0; i < 4; ++i)       if (nodes[node].childs[i] != -1) print(nodes[node].childs[i], depth + 1);   }   int cst[4][4];   int bst[5][4][4];   void update(int a, int b, int cur) {     if (cur < cst[a][b]) cst[a][b] = cur;   }   void dfs(int node, int a, int len) {     int clen = nodes[node].end - nodes[node].start;     if (clen > 1) {       int x = s[nodes[node].start + 1] -  A ;       for (int b = (0); b < (4); ++b) update(a, b, len + 2 + (b == x ? 1 : 0));     } else       for (int i = (0); i < (4); ++i) {         if (nodes[node].childs[i] != -1)           dfs(nodes[node].childs[i], a, len + 1);         else           for (int b = (0); b < (4); ++b)             update(a, b, len + 2 + (b != i ? 1 : 0));       }   }   void run() {     scanf( %I64d%s , &have, s);     slen = strlen(s);     for (int i = (0); i < (4); ++i)       for (int j = (0); j < (4); ++j) cst[i][j] = INT_MAX;     int root = create();     for (int i = (0); i < (4); ++i) dfs(nodes[root].childs[i], i, 0);     for (int i = (0); i < (4); ++i)       for (int j = (0); j < (4); ++j) bst[1][i][j] = cst[i][j];     for (int len = (2); len <= (4); ++len)       for (int i = (0); i < (4); ++i)         for (int j = (0); j < (4); ++j) {           bst[len][i][j] = INT_MAX;           for (int k = (0); k < (4); ++k)             if (bst[len - 1][i][k] + cst[k][j] - 1 < bst[len][i][j])               bst[len][i][j] = bst[len - 1][i][k] + cst[k][j] - 1;         }     long long ret = 1;     for (int i = (0); i < (4); ++i)       for (int j = (0); j < (4); ++j)         for (int k = (0); k < (4); ++k)           for (int cyc = (1); cyc <= (4); ++cyc)             for (int pre = (i == j ? 0 : 1); pre < (cyc); ++pre)               for (int suf = (j == k ? 0 : 1); suf < (cyc); ++suf) {                 long long rem = have - 1;                 if (pre > 0) rem -= bst[pre][i][j] - 1;                 if (suf > 0) rem -= bst[suf][j][k] - 1;                 if (rem < 0) continue;                 long long times = rem / (bst[cyc][j][j] - 1);                 long long cur = pre + times * cyc + suf + 1;                 if (cur > ret) ret = cur;               }     printf( %I64d n , ret);   }   int main() {     run();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   int main() {     int i;     scanf( %d , &n);     if (n == 2) {       printf( -1 n );       return 0;     } else {       printf( 6 n10 n15 n );       for (i = 0; i < n - 3; i++) printf( %d n , 15 * (i + 2));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, memo[100001];   vector<long long> a;   long long x;   long long rek(int pos) {     long long &ret = memo[pos];     if (ret != -1) return ret;     ret = rek(pos - 1) + 20;     x = upper_bound(a.begin(), a.end(), a[pos] - 90) - a.begin();     if (x)       ret = min(ret, rek(x - 1) + 50);     else       ret = min(ret, 50LL);     x = upper_bound(a.begin(), a.end(), a[pos] - 1440) - a.begin();     if (x)       ret = min(ret, rek(x - 1) + 120);     else       ret = min(ret, 120LL);     return ret;   }   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       cin >> x;       a.push_back(x);     }     memset(memo, -1, sizeof(memo));     memo[0] = 20;     rek(n - 1);     for (int i = 0; i < n; i++)       if (!i)         cout << memo[i] << endl;       else         cout << memo[i] - memo[i - 1] << endl;   }


#include <bits/stdc++.h>   using namespace std;   void input(vector<long long>& v, long n) {     for (long long i = 0; i < n; i++) {       long long in;       cin >> in;       v.push_back(in);     }   }   void output(vector<long long> v) {     for (long long i = 0; i < v.size(); i++) cout << v[i] <<    ;   }   long long max_of_three(long long a, long long b, long long c) {     if (a >= b && a >= c)       return a;     else if (b >= a && b >= c)       return b;     else       return c;   }   long long max_of_4(long long a, long long b, long long c, long long d) {     if (a >= b && a >= c && a >= d)       return a;     else if (b >= a && b >= c && b >= d)       return b;     else if (c >= a && c >= d && c >= b)       return c;     else       return d;   }   map<long long, long long> frequency(vector<long long> v) {     map<long long, long long> m;     for (long long i = 0; i < v.size(); i++) {       if (m.find(v[i]) != m.end())         m[v[i]]++;       else {         m.insert({v[i], 1});       }     }     return m;   }   long long max_occuring_int(std::map<long long, long long> m) {     long long max_x = 0;     long long i = 0, n = m.size();     std::map<long long, long long>::iterator it = m.begin();     for (i = 0; i < n; i++) {       if (it->second > max_x) max_x = it->second;       it++;     }     return max_x;   }   vector<long long> give_unique_in_vector(vector<long long> v) {     sort((v).begin(), (v).end());     auto it = unique((v).begin(), (v).end());     v.resize(std::distance(v.begin(), it));     vector<long long> x = v;     return x;   }   bool isVowel(char c) {     return (c ==  a  | c ==  e  || c ==  i  || c ==  o  || c ==  u  || c ==  y  ||             c ==  A  || c ==  E  || c ==  I  || c ==  O  || c ==  U  || c ==  Y );   }   string removeWord(string str, string word) {     if (str.find(word) != string::npos) {       size_t p = -1;       string tempWord = word +    ;       while ((p = str.find(word)) != string::npos)         str.replace(p, tempWord.length(),   );       tempWord =     + word;       while ((p = str.find(word)) != string::npos)         str.replace(p, tempWord.length(),   );     }     return str;   }   long long calc(long long i, long long j, long long n) {     return (i + 1 - 1) * n + j + 1;   }   bool compare_descending(long long a, long long b) { return a > b; }   void solve() {     int n, k, i;     string s;     cin >> n >> k >> s;     if (n - k < k - 1) {       for (i = k - 1; i < n - 1; i++) cout <<  RIGHT n ;       for (i; i >= 0; i--) {         cout <<  PRINT   << s[i] << endl;         if (i != 0) cout <<  LEFT n ;       }     } else {       for (i = k - 1; i > 0; i--) cout <<  LEFT n ;       for (i; i < n; i++) {         cout <<  PRINT   << s[i] << endl;         if (i != n - 1) cout <<  RIGHT n ;       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 1e5 + 5;   const long long INF = 1e10;   const int MOD = 1e9 + 7;   const double EPS = 1e-7;   const double PI = acos(-1.0);   pair<long long, long long> p[N];   long long n, k, a[N];   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL), cout.tie(NULL);     cin >> n >> k;     for (int i = 0; i < n; i++) {       cin >> a[i];       p[i] = {a[i], i};     }     sort(p, p + n);     long long ans = LLONG_MIN;     for (int l = 0; l < n; l++) {       for (int r = l; r < n; r++) {         long long sum = 0;         vector<long long> subarr(r - l + 1);         for (int i = l, j = 0; i <= r; i++, j++) {           subarr[j] = a[i];           sum += a[i];         }         sort(subarr.begin(), subarr.end());         for (int i = 0, j = n - 1; i < min(k, r - l + 1ll); i++) {           while (j >= 0 && p[j].second <= r && p[j].second >= l) {             j--;           }           if (j >= 0) {             sum = max(sum, sum - subarr[i] + p[j].first);             j--;           }         }         ans = max(ans, sum);       }     }     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   const int infi = 2147483600;   const long long infl = 1e17;   int n;   pair<int, int> pbef[200005];   struct SegmentTree {    private:     int N;     vector<long long> node;     long long e;       public:     SegmentTree() {}     SegmentTree(long long e) : e(e) {}     void __init__(int sz) {       N = 1;       while (N < sz) N *= 2;       node.resize(2 * N - 1, e);     }     void build(vector<long long> &v) {       int sz = int(v.size());       __init__(sz);       for (long long i = 0; i < (long long)sz; i++) {         node[i + N - 1] = v[i];       }       for (int i = N - 2; i >= 0; i--) {         node[i] = (node[i * 2 + 1] + node[i * 2 + 2]);       }     }     void update(int k, long long x) {       k += N - 1;       node[k] = x;       while (k > 0) {         k = (k - 1) / 2;         node[k] = (node[2 * k + 1] + node[2 * k + 2]);       }     }     void renew(int b, int e, long long x) {       renew(b, e, 0, 0, N, x);       return;     }     void renew(int b, int e, int k, int l, int r, long long x) {       if (e <= 0 || b >= N) return;       if (k > 0) {         node[k] = (node[k] + node[(k - 1) / 2]);       }       if (r < b || e < l) return;       if (b <= l && r <= e) {         node[k] = min(node[k], x);         return;       } else if (k < N - 1) {         renew(b, e, 2 * k + 1, l, (l + r) / 2, x);         renew(b, e, 2 * k + 2, (l + r) / 2, r, x);         return;       }       return;     }     long long get(int i) {       int k = i + N - 1;       long long res = node[k];       while (k > 0) {         k = (k - 1) / 2;         res = min(res, node[k]);       }       return res;     }     long long query(int a, int b) { return query(a, b, 0, 0, N); }     long long query(int a, int b, int k, int l, int r) {       if (b <= l || r <= a) return e;       if (a <= l && r <= b) return node[k];       long long vl, vr;       vl = query(a, b, 2 * k + 1, l, (l + r) / 2);       vr = query(a, b, 2 * k + 2, (l + r) / 2, r);       return (vl + vr);     }     void recalc() {       for (long long k = 0; k < (long long)N - 1; k++) {         node[2 * k + 1] = (node[2 * k * 1] + node[k]);         node[2 * k + 2] = (node[2 * k * 2] + node[k]);       }     }     long long show_one(int i) { return node[i + N - 1]; }     void show() {       for (long long i = 0; i < (long long)N; i++) cout << node[i] <<    ;       cout << endl;       return;     }   };   int main() {     set<int> xapper, yapper;     map<int, int> xidx, yidx;     cin >> n;     for (long long i = 0; i < (long long)n; i++) {       int x, y;       cin >> x >> y;       xapper.insert(x);       yapper.insert(y);       pbef[i] = make_pair(x, y);     }     int xcnt = 0;     for (auto x : xapper) {       xidx[x] = xcnt;       xcnt++;     }     int ycnt = 0;     for (auto y : yapper) {       yidx[y] = ycnt;       ycnt++;     }     ycnt--;     map<int, set<int>> p;     for (long long i = 0; i < (long long)n; i++) {       p[yidx[pbef[i].second]].insert(xidx[pbef[i].first]);     }     SegmentTree seg(0);     seg.__init__(xcnt);     long long ans = 0;     int bef = 0;     for (long long y = (long long)ycnt; y > (long long)-1; y--) {       int cnt = 0;       int nwe = 0;       int bef = 0;       for (auto x : p[y]) {         seg.update(x, 1);       }       for (auto x : p[y]) {         if (seg.show_one(x) == 0) {           ans += (seg.query(0, x + 1) - bef) * seg.query(x, xcnt);           nwe++;         } else {           ans += (seg.query(0, x + 1) - bef) * seg.query(x, xcnt);         }         bef = seg.query(0, x + 1);         cnt++;       }     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 200200;   struct BIT {     int a[N];     void add(int x, int v = 1) {       for (; x < N; x += x & -x) {         a[x] += v;       }     }     int kth(int k) {       int x = 0;       for (int i = 18; i >= 0; i--) {         if (x + (1 << i) < N) {           int tot = a[x + (1 << i)];           if (k > tot) {             k -= tot;             x += (1 << i);           }         }       }       return x + 1;     }   };   BIT tr;   pair<int, int> p[N];   pair<pair<int, int>, int> q[N];   int a[N];   int ans[N];   int main() {     ios::sync_with_stdio(false);     int n;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];       p[i].first = -a[i];       p[i].second = i;     }     sort(p, p + n);     int m;     cin >> m;     for (int i = 0; i < m; i++) {       cin >> q[i].first.first >> q[i].first.second;       q[i].second = i;     }     sort(q, q + m);     int x = 0;     for (int i = 0; i < n; i++) {       tr.add(p[i].second + 1);       while (x < m && q[x].first.first == i + 1) {         ans[q[x].second] = a[tr.kth(q[x].first.second) - 1];         x++;       }     }     for (int i = 0; i < m; i++) {       printf( %d n , ans[i]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename Arg1>   void __f(const char* name, Arg1&& arg1) {     cout << name <<  :  << arg1 <<   n ;   }   template <typename Arg1, typename... Args>   void __f(const char* names, Arg1&& arg1, Args&&... args) {     const char* comma = strchr(names + 1,  , );     cout.write(names, comma - names) <<  :  << arg1 <<   | ;     __f(comma + 1, args...);   }   void Ishan_Pandey() {     cin.tie(0);     cout.tie(0);     ios_base::sync_with_stdio(0);     cout << setprecision(16) << fixed;   }   const long long int N = 200010;   long long int parent[N], rank1[N];   void make_set(long long int v) {     parent[v] = v;     rank1[v] = 0;   }   long long int find_set(long long int v) {     if (v == parent[v]) return v;     return parent[v] = find_set(parent[v]);   }   void union_sets(long long int a, long long int b) {     a = find_set(a);     b = find_set(b);     if (a != b) {       if (rank1[a] < rank1[b]) swap(a, b);       parent[b] = a;       if (rank1[a] == rank1[b]) rank1[a]++;     }   }   void solve() {     long long int n;     cin >> n;     vector<long long int> a(n + 2, 0);     for (long long int i = 1; i <= n; i++) {       cin >> a[i];     }     long long int ans = 0;     for (long long int i = 1; i <= n; i++) a[i] = min(a[i], a[i - 1] + 1);     for (long long int i = n; i >= 1; i--) a[i] = min(a[i], a[i + 1] + 1);     for (long long int i = 1; i <= n; i++) ans = max(ans, a[i]);     cout << ans;   }   int32_t main() {     Ishan_Pandey();     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int mostFrequent(int arr[], int n) {     sort(arr, arr + n);     int max_count = 1, res = arr[0], curr_count = 1;     for (int i = 1; i < n; i++) {       if (arr[i] == arr[i - 1])         curr_count++;       else {         if (curr_count > max_count) {           max_count = curr_count;           res = arr[i - 1];         }         curr_count = 1;       }     }     if (curr_count > max_count) {       max_count = curr_count;       res = arr[n - 1];     }     return res;   }   unsigned int countDivisors(unsigned int n) {     int cnt = 0;     for (int i = 1; i <= sqrt(n); i++) {       if (n % i == 0) {         if (n / i == i)           cnt++;         else           cnt = cnt + 2;       }     }     return cnt;   }   int main() {     int n, a;     long long int back = 0, biceps = 0, chest = 0;     cin >> n;     for (int i = 1; i <= (n); ++i) {       cin >> a;       if (i % 3 == 0) {         back += a;       } else if (i % 3 == 1) {         chest += a;       } else if (i % 3 == 2) {         biceps += a;       }     }     long long int maxi = max(back, max(biceps, chest));     if (maxi == back)       cout <<  back ;     else if (maxi == biceps)       cout <<  biceps ;     else if (maxi == chest)       cout <<  chest ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 998244353;   const int N = 100005;   int n, x, y, a, b, jc[N], ans;   char s[2];   int ksm(int a, int k) {     int ret = 1;     while (k) {       if (k & 1) ret = 1ll * ret * a % mod;       a = 1ll * a * a % mod;       k >>= 1;     }     return ret;   }   int C(int n, int m) {     return 1ll * jc[n] * ksm(1ll * jc[n - m] * jc[m] % mod, mod - 2) % mod;   }   int main() {     scanf( %d , &n);     jc[0] = 1;     int res = 1, fl1 = 1, fl2 = 1;     for (int i = 1; i < N; ++i) jc[i] = 1ll * jc[i - 1] * i % mod;     for (int i = 1; i <= n; ++i) {       scanf( %s , s);       if (s[0] ==  W ) ++x;       if (s[0] ==  ? ) ++y;       if (s[1] ==  B ) ++a;       if (s[1] ==  ? ) ++b;       if (s[0] ==  ?  && s[1] ==  ? )         res = (res * 2) % mod;       else if (s[0] == s[1])         res = 0;       if (s[0] ==  W  || s[1] ==  B ) fl1 = 0;       if (s[1] ==  W  || s[0] ==  B ) fl2 = 0;     }     res -= fl1;     res -= fl2;     for (int i = max(a, x); i <= min(x + y, a + b); ++i)       (ans += 1ll * C(y, i - x) * C(b, i - a) % mod) %= mod;     printf( %d , ans - res);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long mo(long long a) { return a % (long long)(1e9 + 7); }   long long po(long long x, long long y, long long p) {     long long res = 1;     x = x % p;     while (y > 0) {       if (y & 1) res = (res * x) % p;       y >>= 1;       x = (x * x) % p;     }     return res % p;   }   vector<vector<pair<long long, long long>>> g;   vector<long long> vis, col;   vector<vector<long long>> ty;   void dfs(long long par, long long anc = -1, long long type = -1) {     if (anc == -1) {       col[par] = 0;       ty[col[par]].push_back(par);     } else {       if (type) {         col[par] = !col[anc];         ty[col[par]].push_back(par);       } else {         col[par] = col[anc];         ty[col[par]].push_back(par);       }     }     vis[par] = 1;     for (pair<long long, long long> e : g[par]) {       if (!vis[e.first]) {         dfs(e.first, par, e.second);       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long t;     cin >> t;     while (t--) {       long long n;       cin >> n;       vector<vector<long long>> r(n, vector<long long>(2, -1)),           c(n, vector<long long>(2, -1));       for (long long i = 0; i < 2; i++) {         for (long long j = 0; j < n; j++) {           long long x;           cin >> x;           x--;           if (r[x][0] == -1)             r[x][0] = i;           else             r[x][1] = i;           if (c[x][0] == -1)             c[x][0] = j;           else             c[x][1] = j;         }       }       long long pos = 1;       for (long long i = 0; i < n; i++) {         if (r[i][0] == -1 || r[i][1] == -1) pos = 0;       }       if (!pos) {         cout << -1 <<   n ;         continue;       }       g.assign(n, {});       vis.assign(n, 0);       col.assign(n, -1);       ty.assign(2, {});       for (long long i = 0; i < n; i++) {         if (r[i][0] == r[i][1] && c[i][0] != c[i][1]) {           g[c[i][0]].push_back({c[i][1], 1});           g[c[i][1]].push_back({c[i][0], 1});         }         if (r[i][0] != r[i][1] && c[i][0] != c[i][1]) {           g[c[i][1]].push_back({c[i][0], 0});           g[c[i][0]].push_back({c[i][1], 0});         }       }       vector<long long> ans;       for (long long i = 0; i < n; i++) {         if (!vis[i]) {           ty[0].clear();           ty[1].clear();           dfs(i);           if (ty[0].size() > ty[1].size()) swap(ty[0], ty[1]);           for (long long e : ty[0]) ans.push_back(e);         }       }       cout << ans.size() <<   n ;       for (long long e : ans) cout << e + 1 <<    ;       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, a, b, max_dollars, min_tokens, n_tokens;     string raw_input;     cin >> n >> a >> b;     vector<string> tokens(n);     for (int i = 0; i < n; i++) cin >> tokens[i];     for (int i = 0; i < n; i++) {       n_tokens = stoll(tokens[i]);       max_dollars = n_tokens * a / b;       if (stoll(tokens[i]) * a % b != 0) {         min_tokens = ceil((max_dollars * 1.0) * b / a);         cout << n_tokens - min_tokens <<    ;       } else {         cout << 0 <<    ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int t, x, y, a, b;     cin >> t;     while (t--) {       cin >> x >> y >> a >> b;       if (2 * a < b)         cout << a * (x + y) <<   n ;       else         cout << b * min(x, y) + a * abs(x - y) <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int tc;     cin >> tc;     while (tc--) {       int n;       cin >> n;       string s;       cin >> s;       if (n == 2) {         if (s[0] >= s[1]) {           cout <<  NO                 <<   n ;         } else {           cout <<  YES                 <<   n ;           cout <<  2                 <<   n ;           cout << s[0] <<     << s[1] <<   n ;         }       } else {         cout <<  YES               <<   n ;         cout <<  2               <<   n ;         cout << s[0] <<    ;         for (int i = 1; i < n; i++) {           cout << s[i];         }         cout << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const int mod = 1e9 + 7;   const int maxn = 1000000 + 5;   const double PI = acos(-1.0);   const double E = 2.718281828459;   const double eps = 1e-7;   int T, n, num[100005];   int main() {     long k, n = 19, x = 0, m;     scanf( %ld , &k);     while (k - 1 > 0) {       x = 0;       n++;       m = n;       while (m > 0) {         x += m % 10;         m /= 10;       }       if (x == 10) {         k--;       }     }     printf( %ld n , n);   }


#include <bits/stdc++.h>   using namespace std;   vector<int> solve(int n) {     vector<int> v(n, 1);     if (n == 1) return v;     if (n == 2) {       v[0] = 3, v[1] = 4;       return v;     }     int k = n - 1;     if (k & 1) {       int p = k >> 1;       v[n - 1] = p;     } else {       k = k - 1 + 4;       int p = k >> 1;       v[n - 2] = 2, v[n - 1] = p;     }     return v;   }   int main() {     int n, m;     while (cin >> n >> m) {       vector<int> v1 = solve(n), v2 = solve(m);       for (int i = 0; i < n; i++)         for (int j = 0; j < m; j++)           printf( %d%c , v1[i] * v2[j], j + 1 == m ? 10 : 32);     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, n, d, x, y;     vector<pair<int, int> > v;     cin >> n >> d >> a >> b;     for (int i = 0; i < n; i++) {       cin >> x >> y;       v.push_back({x * a + y * b, i});     }     sort(v.begin(), v.end());     long long sum = 0, in = 0;     for (int i = 0; i < n; i++) {       if (sum + v[i].first > d) break;       sum += v[i].first;       in++;     }     cout << in << endl;     for (int i = 0; i < in - 1; i++) cout << v[i].second + 1 <<    ;     if (in > 0) cout << v[in - 1].second + 1;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int hy, ay, dy;   int hm, am, dm;   int h, a, d;   bool firstok = true;   bool ok(int H, int A, int D) {     int d1 = max(0, A - dm);     int d2 = max(0, am - D);     if (d1 == 0 && d2 == 0) return false;     if (d2 == 0) return true;     if (d1 == 0) return false;     int r1 = (int)ceil(double(hm) / d1);     if (H % d2 == 0 && r1 < H / d2)       return true;     else if (H % d2 != 0 && r1 <= H / d2)       return true;     return false;   }   int main() {     cin >> hy >> ay >> dy;     cin >> hm >> am >> dm;     cin >> h >> a >> d;     int minm = 100000000;     for (__typeof(200) i = 0; i < (200); ++i)       for (__typeof(200) j = 0; j < (200); ++j) {         int A = ay + i;         int D = dy + j;         int k1 = max(0, A - dm);         int k2 = max(0, am - D);         if (k1 == 0) continue;         if (k2 == 0) {           minm = min(minm, i * a + j * d);           continue;         }         int t = (int)ceil((double)hm / k1);         int k = t * k2 - hy + 1;         k = max(0, k);         minm = min(minm, i * a + j * d + k * h);       }     cout << minm << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int a[n * 2], b[n * 2];     for (int i = 0; i < (n); ++i) {       cin >> a[i] >> b[i];       a[i + n] = a[i];       b[i + n] = b[i];     }     int flag = 1;     if (n % 2 == 1) flag = 0;     for (int i = 0; i < (n); ++i) {       int x = a[i + 1] - a[i];       int y = b[i + 1] - b[i];       if (a[i + n / 2 + 1] - a[i + n / 2] != -x) flag = 0;       if (b[i + n / 2 + 1] - b[i + n / 2] != -y) flag = 0;     }     if (flag) {       puts( YES );     } else {       puts( NO );     };     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long t, n;     cin >> n;     if (n == 0)       cout << 1 << endl;     else if (n % 4 == 1)       cout << 8 << endl;     else if (n % 4 == 2)       cout << 4 << endl;     else if (n % 4 == 3)       cout << 2 << endl;     else       cout << 6 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int LIS(vector<int> A) {     int N = A.size(), i;     multiset<int> s;     multiset<int>::iterator k;     for (i = 0; i < N; i++) {       s.insert(A[i]);       if (1) {         k = s.find(A[i]);         k++;         if (k != s.end()) s.erase(k);       }     }     return s.size();   }   int main() {     int n;     cin >> n;     string s;     cin >> s;     for (int i = 1; i < n; i++) {       for (int j = 0; j + 4 * i < n; j++) {         if (s[j] !=  * ) continue;         if (s[j + i] == s[j] && s[j + 2 * i] == s[j] && s[j + 3 * i] == s[j] &&             s[j + 4 * i] == s[j]) {           cout <<  yes ;           return 0;         }       }     }     cout <<  no ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int a[n];     for (int i = 0; i < n; i++) {       cin >> a[i];     }     int current = 1, maxtotal = 0;     for (int i = 0; i < n; i++) {       current = 1;       for (int j = i; j < n - 1 && a[j] >= a[j + 1]; j++, current++)         ;       for (int j = i; j > 0 && a[j] >= a[j - 1]; j--, current++)         ;       if (current > maxtotal) {         maxtotal = current;       }     }     cout << maxtotal;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxx = 1e5 + 20;   long long a[maxx];   int main() {     int n, i;     cin >> n;     for (i = 0; i < n; i++) cin >> a[i];     sort(a, a + n);     int r;     while (a[0] % 2 == 0) a[0] /= 2;     while (a[0] % 3 == 0) a[0] /= 3;     r = a[0];     for (i = 1; i < n; i++) {       while (a[i] % 2 == 0) a[i] /= 2;       while (a[i] % 3 == 0) a[i] /= 3;       if (a[i] != r) {         cout <<  No ;         return 0;       }     }     cout <<  Yes ;     return 0;   }


#include <bits/stdc++.h>   const int Inf = 2e9;   long long LINF = (long long)4e18;   using namespace std;   int r1, r2, c1, c2, d1, d2;   bool ok(int i, int j, int k, int l) {     if (i + j != r1) return false;     if (k + l != r2) return false;     if (i + k != c1) return false;     if (j + l != c2) return false;     if (i + l != d1) return false;     if (j + k != d2) return false;     return true;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> r1 >> r2 >> c1 >> c2 >> d1 >> d2;     for (int i = 1; i <= 9; i++) {       for (int j = 1; j <= 9; j++) {         for (int k = 1; k <= 9; k++) {           for (int l = 1; l <= 9; l++) {             if (i == j) continue;             if (i == k) continue;             if (i == l) continue;             if (j == k) continue;             if (j == l) continue;             if (k == l) continue;             if (!ok(i, j, k, l)) continue;             cout << i <<     << j <<   n ;             cout << k <<     << l <<   n ;             return 0;           }         }       }     }     cout << -1;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int Maxn = 22;   int n;   int col[Maxn];   int main() {     scanf( %d , &n);     int cur = 0;     for (int a = 0; cur < n; a++) {       bool good = true;       for (int i = 0; i < cur && good; i++)         for (int j = i + 1; j < cur && good; j++)           for (int l = 0; l < cur && good; l++)             if (i != l && j != l) good = a != col[i] + col[j] - col[l];       if (good) col[cur++] = a;     }     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++)         printf( %d%c , i == j ? 0 : col[i] + col[j], j + 1 < n ?     :   n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long t, n, k, z, x, s, a[31], v[31][101], c[31];   int main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     ;     cin >> t;     for (int zxc = 1; zxc <= t; zxc++) {       cin >> n >> k;       for (int i = 1; i <= 30; i++)         for (int j = 1; j <= 100; j++) v[i][j] = 0;       for (int i = 1; i <= n; i++) cin >> a[i];       for (int i = 1; i <= n; i++) {         long long z = a[i];         long long x = 0;         while (z != 0) {           x++;           v[i][x] = z % k;           z /= k;         }       }       int ff = 0;       for (int i = 1; i <= n; i++) {         for (int j = 1; j <= 100; j++) {           if (v[i][j] > 1) {             ff = 1;             break;           }         }         if (ff == 1) break;       }       if (ff == 1)         cout <<  NO               <<   n ;       else {         for (int j = 1; j <= 100; j++) {           long long x = 0;           for (int i = 1; i <= n; i++)             if (v[i][j] == 1) x++;           if (x > 1) {             ff = 1;             break;           }         }         if (ff == 1)           cout <<  NO                 <<   n ;         else           cout <<  YES                 <<   n ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int get(int xt) {     int ans = 0;     for (int i = 0; i < 8; i++) {       ans *= 2;       ans += xt % 2;       xt /= 2;     }     return ans;   }   int main() {     char a[110] =   ;     gets(a);     int len = strlen(a);     int xt = 0;     for (int i = 0; i < len; i++) {       int tmp = a[i];       tmp = get(tmp);       if (i != len)         cout << (xt - tmp + 256) % 256 << endl;       else         cout << (xt - tmp + 256) % 256;       xt = tmp;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 5e3 + 7;   int dp[N][N];   int cnt[N * N];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n;     cin >> n;     int a[n];     memset(dp, 0, sizeof(dp));     memset(cnt, 0, sizeof(cnt));     for (int i = 0; i < n; i++) cin >> a[i];     int ini = 0;     for (int i = 1; i < n; i++) {       for (int j = 0; j < n; j++) dp[i][j] = dp[i - 1][j];       for (int j = 0; j < n; j++) {         if (a[i] > j) dp[i][j]++;       }       for (int j = 0; j < i; j++) {         if (a[j] > a[i]) ini++;       }     }     for (int i = 0; i < n; i++) {       for (int j = i + 1; j < n; j++) {         int val = dp[i][a[i]] + dp[j][a[j]] - dp[i][a[j]] - dp[j][a[i]];         val = ini - 2 * val - 1;         cnt[val]++;       }     }     for (int i = 0; i < N * N; i++) {       if (cnt[i]) {         cout << i <<     << cnt[i] << endl;         break;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int query(vector<int>& v) {     cout <<  ?  ;     for (auto& x : v) {       cout << x <<    ;     }     cout << endl;     int a;     cin >> a;     return a;   }   void solve(int n) {     int x = 1;     vector<int> v(n, 1);     for (int i = n; i >= 2; i--) {       for (int j = 0; j < n - 1; j++) {         v[j] = i;       }       int a = query(v);       if (a == 0) continue;       x = i;       break;     }     vector<int> ans(n, -1);     ans[n - 1] = x;     for (int i = 0; i < n; i++) {       v[i] = x;     }     for (int i = 1; i <= n; i++) {       if (i == x) continue;       v[n - 1] = i;       int index = query(v);       ans[index - 1] = i;     }     cout <<  !  ;     for (auto& y : ans) {       cout << y <<    ;     }     cout << endl;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long t = 1;     while (t--) {       int n;       cin >> n;       solve(n);     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1010;   int n, m, maxw, tot, w[maxn], b[maxn], fa[maxn], sumw[maxn], sumb[maxn],       dp[maxn << 1][maxn], f[maxn];   vector<int> child[maxn];   vector<pair<int, int> > vec;   unordered_set<int> ancestor;   void init() {     for (int i = 1; i <= n; i++) {       fa[i] = i;       sumw[i] = w[i];       sumb[i] = b[i];     }   }   int find(int x) { return x == fa[x] ? x : fa[x] = find(fa[x]); }   void unite(int x, int y) {     x = find(x), y = find(y);     if (x == y) return;     fa[x] = y;     sumw[y] += sumw[x];     sumb[y] += sumb[x];   }   int main() {     scanf( %d %d %d , &n, &m, &maxw);     for (int i = 1; i <= n; i++) {       scanf( %d , &w[i]);     }     for (int i = 1; i <= n; i++) {       scanf( %d , &b[i]);     }     init();     while (m--) {       int x, y;       scanf( %d %d , &x, &y);       unite(x, y);     }     for (int i = 1; i <= n; i++) {       child[find(i)].push_back(i);       ancestor.insert(find(i));     }     for (int x : ancestor) {       int last = tot;       for (int y : child[x]) {         tot++;         for (int z = 0; z <= maxw; z++) {           dp[tot][z] = f[z];           if (z >= w[y]) {             dp[tot][z] = max(dp[tot][z], f[z - w[y]] + b[y]);           }         }       }       tot++;       for (int y = 0; y <= maxw; y++) {         dp[tot][y] = f[y];         if (y >= sumw[x]) {           dp[tot][y] = max(dp[tot][y], f[y - sumw[x]] + sumb[x]);         }       }       for (int y = last + 1; y <= tot; y++) {         for (int z = 0; z <= maxw; z++) {           f[z] = max(f[z], dp[y][z]);         }       }     }     printf( %d n , *max_element(f, f + maxw + 1));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   long long a[N], n;   int to_sorted[N];   int to_nature[N];   bool done(int i, int d) {     bool lef = (i == 0 || a[i - 1] < a[i] - d);     bool rig = (i == n - 1 || a[i] + d < a[i + 1]);     return lef && rig;   }   int front(int, int);   int back(int, int);   int front(int i, int d) {     if (done(i, d)) {       return i;     }     int id = upper_bound(a, a + n, a[i] + d) - a - 1;     long long rot = 2 * abs(a[i] - a[id]);     bool safe = (i == 0 || a[i - 1] < a[i] - (d - rot));     if (safe && d >= rot) {       return front(i, d % rot);     }     return back(id, d - abs(a[i] - a[id]));   }   int back(int i, int d) {     if (done(i, d)) {       return i;     }     int id = lower_bound(a, a + n, a[i] - d) - a;     long long rot = 2 * abs(a[i] - a[id]);     bool safe = (i == n - 1 || a[i] + d - rot < a[i + 1]);     if (safe && d >= rot) {       return back(i, d % rot);     }     return front(id, d - abs(a[i] - a[id]));   }   int main() {     int m;     scanf( %d %d , &n, &m);     vector<pair<int, int>> p;     for (int i = 0; i < n; i++) {       scanf( %I64d , a + i);       p.emplace_back(a[i], i);     }     sort(a, a + n);     sort(p.begin(), p.end());     for (int i = 0; i < n; i++) {       to_sorted[p[i].second] = i;       to_nature[i] = p[i].second;     }     while (m--) {       int id, l;       scanf( %d %d , &id, &l);       id = to_sorted[id - 1];       printf( %d n , to_nature[front(id, l)] + 1);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, viz[100005], cnt, nr, x[100005], nrans, ans[400005], rad;   vector<int> v[100005];   void dfs1(int nod) {     viz[nod] = 1;     nr += x[nod];     for (auto x : v[nod])       if (!viz[x]) dfs1(x);   }   void dfs(int nod, int tata) {     viz[nod] = 1;     nrans++;     ans[nrans] = nod;     x[nod] = 1 - x[nod];     for (auto xx : v[nod])       if (!viz[xx]) {         dfs(xx, nod);         nrans++;         ans[nrans] = nod;         x[nod] = 1 - x[nod];       }     if ((x[nod] % 2) && (nod != rad)) {       nrans++;       ans[nrans] = tata;       nrans++;       ans[nrans] = nod;       x[nod] = 1 - x[nod];       x[tata] = 1 - x[tata];     }   }   int main() {     int i, xx, y;     cin >> n >> m;     for (i = 1; i <= m; i++) {       cin >> xx >> y;       v[xx].push_back(y);       v[y].push_back(xx);     }     for (i = 1; i <= n; i++) cin >> x[i];     for (i = 1; i <= n; i++)       if (!viz[i]) {         nr = 0;         dfs1(i);         if (nr % 2) cnt++;         if (cnt > 1) {           cout << -1;           return 0;         }       }     for (i = 1; i <= n; i++) viz[i] = 0;     for (i = 1; i <= n; i++)       if (x[i] % 2) {         rad = i;         break;       }     if (!rad) rad = 1;     dfs(rad, 0);     if (x[rad] % 2) nrans--;     cout << nrans <<   n ;     for (i = 1; i <= nrans; i++) cout << ans[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int i, j, k, m, n, a[1000], b[1000], t = -1;     cin >> n >> m;     for (i = 0; i < n; i++) {       cin >> a[i];     }     for (i = 0; i < m; i++) {       cin >> b[i];     }     sort(a, a + n);     sort(b, b + m);     for (i = a[n - 1]; i < b[0]; i++) {       if ((2 * a[0]) <= i) {         t = i;         break;       }     }     cout << t;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void __print(int x) { cerr << x; }   void __print(long x) { cerr << x; }   void __print(long long x) { cerr << x; }   void __print(unsigned x) { cerr << x; }   void __print(unsigned long x) { cerr << x; }   void __print(unsigned long long x) { cerr << x; }   void __print(float x) { cerr << x; }   void __print(double x) { cerr << x; }   void __print(long double x) { cerr << x; }   void __print(char x) { cerr <<      << x <<     ; }   void __print(const char *x) { cerr <<     << x <<    ; }   void __print(const string &x) { cerr <<     << x <<    ; }   void __print(bool x) { cerr << (x ?  true  :  false ); }   template <typename T, typename V>   void __print(const pair<T, V> &x) {     cerr <<  { ;     __print(x.first);     cerr <<  , ;     __print(x.second);     cerr <<  } ;   }   template <typename T>   void __print(const T &x) {     int f = 0;     cerr <<  { ;     for (auto &i : x) cerr << (f++ ?  ,  :   ), __print(i);     cerr <<  } ;   }   void _print() { cerr <<  ] n ; }   template <typename T, typename... V>   void _print(T t, V... v) {     __print(t);     if (sizeof...(v)) cerr <<  ,  ;     _print(v...);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int t = 1;     while (t--) {       long long int n = 0, m = 0, k = 0, i = 0, j = 0, p = 0, q = 0, x = 0, y = 0,                     z = 0, ans = 0, cnt = 0, l = 0, r = 0, mid = 0, lo = 0,                     hi = 0;       string s;       bool flag = false;       cin >> n;       long long int a[n + 1];       for (i = 1; i <= n; i++) cin >> a[i];       long long int dp[n + 1][n + 1][2];       long long int even = n / 2;       long long int odd = (n % 2 == 0) ? n / 2 : (n / 2) + 1;       for (i = 0; i <= n; i++)         for (j = 0; j <= n; j++)           for (k = 0; k < 2; k++) dp[i][j][k] = 1000000007;       dp[0][0][0] = 0;       dp[0][0][1] = 0;       for (i = 1; i <= n; i++)         if (a[i] == 0)           for (j = 0; j <= even; j++)             if (j > i || (i - j) > odd)               continue;             else               dp[i][j][0] = min(dp[i][j][0], dp[i - 1][j - 1][0]),               dp[i][j][0] = min(dp[i][j][0], dp[i - 1][j - 1][1] + 1),               dp[i][j][1] = min(dp[i][j][1], dp[i - 1][j][1]),               dp[i][j][1] = min(dp[i][j][1], dp[i - 1][j][0] + 1);         else           for (j = 0; j <= even; j++) {             if (j > i || (i - j) > odd) continue;             if (a[i] % 2 == 0)               dp[i][j][0] = min(dp[i][j][0], dp[i - 1][j - 1][0]),               dp[i][j][0] = min(dp[i][j][0], dp[i - 1][j - 1][1] + 1);             else               dp[i][j][1] = min(dp[i][j][1], dp[i - 1][j][1]),               dp[i][j][1] = min(dp[i][j][1], dp[i - 1][j][0] + 1);           }       ans = 1000000007;       for (j = 0; j <= even; j++)         ans = min(ans, dp[n][j][0]), ans = min(ans, dp[n][j][1]);       cout << ans << endl;       ;     }     return 0;   }


#include <bits/stdc++.h>   int t, s, x;   int main() {     scanf( %d%d%d , &t, &s, &x);     if (x == t) {       printf( YES n );       return 0;     }     for (int i = 1; i * s + t <= x; i++)       if (i * s + t == x || i * s + t + 1 == x) {         printf( YES n );         return 0;       }     printf( NO n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxN = 3042, mod = 1000000007;   const int modHash = 2013023017;   inline void add_mod(long long& a, long long b) { a = (a + b) % mod; }   inline void mult_mod(long long& a, long long b) { a = a * b % mod; }   long long dp[maxN][maxN], pref[maxN];   unordered_set<long long> S[maxN];   bool fld[42];   int in[maxN];   int main() {     fld[12] = fld[10] = fld[7] = fld[15] = true;     int n;     scanf( %d , &n);     for (int i = 1; i < (n + 1); i++) scanf( %d , in + i);     for (int i = 1; i < (n + 1); i++) {       int mask = 0;       long long H[10];       H[3] = H[5] = 0;       dp[i][i - 1] = 1;       for (int j = i; j < (n + 1); j++) {         H[3] = (H[3] * 3 + in[j] + 1) % modHash;         H[5] = (H[5] * 5 + in[j] + 1) % modHash;         mask >>= 1;         mask |= in[j] << 3;         int len = j - i + 1;         dp[i][j] = (len >= 4 and !fld[mask]) ? dp[i][j - 4] : 0;         for (int k = 1; k < (min(4, len + 1)); k++) dp[i][j] += dp[i][j - k];         dp[i][j] %= mod;         long long M = H[3] << 32 | H[5];         if ((S[len].insert(M)).second) pref[j] += dp[i][j];       }     }     long long sum = 0;     for (int i = 1; i < (n + 1); i++) {       add_mod(sum, pref[i]);       printf( %lld n , sum);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     char ch[n + 1];     cin >> ch;     int ar[200] = {0};     for (int i = 0; i < strlen(ch); i++) {       ar[ch[i]]++;     }     sort(ar, ar + 200);     if (ar[199] > k)       cout <<  NO  << endl;     else       cout <<  YES  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MX = 300000;   int arr[MX], state[MX], n, m, meet[MX], cur, is[MX], lastoff[MX];   int pres[MX];   pair<int, int> last;   vector<pair<int, int> > v[MX];   vector<int> ans;   char cc;   int main() {     memset(meet, -1, sizeof(meet));     memset(is, 0, sizeof(is));     scanf( %d %d , &n, &m);     for (int j = 1; j <= m; j++) {       cin >> cc >> arr[j];       if (cc ==  + )         state[j] = 1;       else         state[j] = 0;       if (meet[arr[j]] == -1) meet[arr[j]] = state[j];       v[arr[j]].push_back(make_pair(j, state[j]));     }     for (int j = 1; j <= n; j++) {       lastoff[j] = m * 10;       if (meet[j] == -1) ans.push_back(j);       if (meet[j] == 0) {         cur++;         is[j] = 1;       }     }     if (state[1] == 1 && cur == 0) is[arr[1]] = 1;     for (int j = 1; j <= m; j++) {       if (state[j] == 0)         cur--;       else         cur++;       pres[j] = cur;     }     for (int j = 1; j <= m; j++) {       if (!is[arr[j]]) continue;       if (state[j] == 0) {         if (pres[j] > 0) {           is[arr[j]] = 0;         }         lastoff[arr[j]] = j;       }     }     int ret;     for (int j = 1; j <= n; j++) {       if (!is[j]) continue;       ret = 1;       int szo = v[j].size();       for (int i = 0; i < szo; i++) {         if (v[j][i].second == 1 && i) {           if (v[j][i].first != v[j][i - 1].first + 1) ret = 0;         }         last = v[j][i];       }       if (last.second == 0 && last.first < m) ret = 0;       is[j] &= ret;       if (is[j]) ans.push_back(j);     }     sort(ans.begin(), ans.end());     cout << ans.size() << endl;     for (int j = 0; j < ans.size(); j++) printf( %d  , ans[j]);   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e5 + 50;   const int maxn = 1e7 + 50;   const int inf = 0x3f3f3f3f;   unordered_map<int, bool> mp;   vector<int> vec;   int main() {     int T;     scanf( %d , &T);     while (T--) {       mp.clear();       vec.clear();       int n, t;       scanf( %d , &n);       vec.push_back(0);       for (int i = 1; i * i <= n; i++) {         t = n / i;         if (!mp.count(t)) {           mp[t] = 1;           vec.push_back(t);           if (n / t == i) {             if (!mp.count(i)) {               mp[i] = 1;               vec.push_back(i);             }           }         }       }       sort(vec.begin(), vec.end());       printf( %d n , vec.size());       for (int i = 0; i < vec.size(); i++) printf( %d  , vec[i]);       putchar(10);     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     double ans, B, H;     cin >> ans;     double ff = 999999999.9;     for (double h = 1; h <= 10; h++) {       for (double b = 1; b <= 10; b++) {         double sum = h * b / sqrt(4 * h * h + b * b);         double d = fabs(ans - sum);         if (d < ff) {           ff = d;           B = b;           H = h;         }       }     }     cout << B <<     << H << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long l, r;     cin >> l >> r;     long long x = r, y = 0;     while (x > 0) {       ++y;       x /= 10;     }     x = 5;     long long k = y;     for (int i = 0; i < k - 1; ++i) {       x *= 10;     }     if (r < x)       x = r;     else if (l > x)       x = l;     k = x;     vector<long long> ans;     while (k > 0) {       ans.push_back(k % 10);       k /= 10;     }     reverse(ans.begin(), ans.end());     y = 0;     for (auto& i : ans) {       y *= 10;       y += 9 - i;     }     cout << x * y;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   typedef struct {     int y, i;     double p;   } ele;   int cmp(ele a, ele b) { return a.y > b.y || (a.y == b.y && a.i > b.i); }   vector<ele> pu[100514];   int a[100514];   double dp[5140][5140];   int mp[5140];   vector<int> e[5140];   ele sk[5140];   int top;   void sol() {     int n, q;     scanf( %d %d , &n, &q);     for (int i = 0; i < n; i++) {       scanf( %d , a + i);     }     pu[0].push_back((ele){n - 1, q, 0});     for (int i = 0; i < q; i++) {       int x, y;       double p;       scanf( %d %d %lf , &x, &y, &p);       pu[x - 1].push_back((ele){y - 1, i, p});     }     for (int i = 0; i <= q; i++) mp[i] = -7122;     top = 0;     for (int i = 0; i < n; i++) {       sort(pu[i].begin(), pu[i].end(), cmp);       for (int j = 0; j < (int)pu[i].size(); j++) {         sk[top++] = pu[i][j];       }       mp[sk[top - 1].i] = max(mp[sk[top - 1].i], a[i]);       for (; top && sk[top - 1].y == i; top--) {         int t = sk[top - 1].i;         double p = sk[top - 1].p;         for (int j = 0; j < (int)e[t].size(); j++) {           mp[t] = max(mp[t], mp[e[t][j]]);         }         for (int k = 0; k <= q + 1; k++) {           dp[t][k] = 1;           for (int j = 0; j < (int)e[t].size(); j++) {             int nk = mp[t] + k - mp[e[t][j]];             if (q + 1 >= nk) {               dp[t][k] *= dp[e[t][j]][nk];             }           }         }         for (int k = q + 1; k >= 1; k--) {           dp[t][k] = dp[t][k] * (1 - p) + dp[t][k - 1] * p;         }         dp[t][0] = dp[t][0] * (1 - p);         if (top >= 2) e[sk[top - 2].i].push_back(t);       }       pu[i].clear();     }     double ans = mp[q];     for (int i = 1; i <= q + 1; i++) {       ans += (dp[q][i] - dp[q][i - 1]) * i;     }     printf( %.10f n , ans);     for (int i = 0; i <= q; i++) e[i].clear();   }   int main() {     while (1) {       sol();       break;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, x, y;     int p = 1;     cin >> n;     cin >> x;     cin >> y;     p = n * y;     if (p % 100 != 0)       p = p / 100 + 1;     else       p = p / 100;     if (p <= x)       cout << 0 << endl;     else       cout << p - x << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int dx[9] = {0, 1, -1, 0, 0, -1, -1, 1, 1};   const int dy[9] = {0, 0, 0, -1, 1, -1, 1, -1, 1};   const double pi = acos(-1.0);   const int N = 1e5 + 100;   long long pre[N], a[N], temp[200], ans = 0;   int n, k, ma = 0;   map<long long, long long> dic;   int main() {     scanf( %d , &n), scanf( %d , &k);     long long t = 1;     temp[0] = 1;     if (k == 1 || k == -1) {       if (k == 1) {         ma = 0;         temp[0] = 1;       } else {         ma = 1;         temp[0] = 1;         temp[1] = -1;       }     } else {       while (abs(t * k) < 1e15) {         ma++;         t = t * k;         temp[ma] = t;       }     }     for (int i = 1; i <= n; i++) scanf( %lld , &a[i]);     for (int i = 0; i <= ma; i++) dic[temp[i] + 0]++;     for (int i = 1; i <= n; i++) {       pre[i] = pre[i - 1] + a[i];       ans += dic[pre[i]];       for (int j = 0; j <= ma; j++) dic[pre[i] + temp[j]]++;     }     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline void smin(int &a, const int &b) {     if (b < a) a = b;   }   inline void smax(int &a, const int &b) {     if (b > a) a = b;   }   int first[4], second[4], f[4], ans;   vector<int> dst, vx, vy;   pair<int, int> p[4], mp[4];   inline void solve(int X, int Y, int d) {     p[0] = pair<int, int>(X, Y), p[1] = pair<int, int>(X, Y + d), X += d;     p[2] = pair<int, int>(X, Y), p[3] = pair<int, int>(X, Y + d);     for (int i = 4; i--;) f[i] = i;     do {       int mx = 0;       for (int i = 4; i--;) {         if (first[i] == p[f[i]].first)           smax(mx, abs(second[i] - p[f[i]].second));         else if (second[i] == p[f[i]].second)           smax(mx, abs(first[i] - p[f[i]].first));         else           mx = 0x3f3f3f3f;       }       if (mx < ans) {         ans = mx;         for (int i = 4; i--;) mp[i] = p[f[i]];       }     } while (next_permutation(f, f + 4));   }   inline void solve(int d) {     vx.clear(), vy.clear();     for (int i = 4; i--;) {       vx.push_back(first[i] - d), vx.push_back(first[i]),           vx.push_back(first[i] + d);       vy.push_back(second[i] - d), vy.push_back(second[i]),           vy.push_back(second[i] + d);       for (int j = i; j--;) {         int xmn = min(first[i], first[j]), xmx = max(first[i], first[j]);         int ymn = min(second[i], second[j]), ymx = max(second[i], second[j]);         for (int k = 4; k--;)           if (k != i && k != j) {             smin(xmn, first[k] - d), smax(xmx, first[k] - d);             smin(ymn, second[k] - d), smax(ymx, second[k] - d);           }         vx.push_back(xmn + xmx >> 1), vy.push_back(ymn + ymx >> 1);       }     }     for (int first : vx)       for (int second : vy) solve(first, second, d);   }   int main() {     int t;     scanf( %d , &t);     while (t--) {       dst.clear();       for (int i = 0; i < 4; i++) {         scanf( %d %d , first + i, second + i);         for (int j = 0; j < i; j++) {           dst.push_back(abs(first[i] - first[j]));           dst.push_back(abs(second[i] - second[j]));         }       }       sort(dst.begin(), dst.end());       dst.resize(unique(dst.begin(), dst.end()) - dst.begin());       ans = 0x3f3f3f3f;       for (int first : dst) solve(first);       if (ans < 0x3f3f3f3f) {         printf( %d n , ans);         for (int i = 0; i < 4; i++) printf( %d %d n , mp[i].first, mp[i].second);       } else         puts( -1 );     }   }


#include <bits/stdc++.h>   using namespace std;   bool isprime(long long int n) {     if (n <= 1) return false;     if (n <= 3) return true;     if (n % 2 == 0 || n % 3 == 0) return false;     for (int i = 5; i * i <= n; i = i + 6)       if (n % i == 0 || n % (i + 2) == 0) return false;     return true;   }   vector<long long int> prime;   void sieve(long long int n) {     bool bakh[n + 1];     memset(bakh, true, sizeof(bakh));     for (long long int p = 2; p * p <= n; p++) {       if (bakh[p] == true) {         for (long long int i = p * p; i <= n; i += p) bakh[i] = false;       }     }     for (long long int p = 2; p <= n; p++)       if (bakh[p]) prime.push_back(p);   }   long long int eulertotient(long long int z) {     long long int fac = z;     for (long long int i = 0; prime[i] * prime[i] <= z; i++) {       if (z % prime[i] == 0) {         fac -= (fac / prime[i]);         while (z % prime[i] == 0) z /= prime[i];       }     }     if (z > 1) fac -= (fac / z);     return fac;   }   long long int power(long long int x, long long int y, long long int p) {     long long int res = 1;     x = x % p;     while (y > 0) {       if (y & 1) res = (res * x) % p;       y = y >> 1;       x = (x * x) % p;     }     return res;   }   long long int gcd(long long int a, long long int b) {     if (a == 0) return b;     return gcd(b % a, a);   }   long long int lcm(long long int a, long long int b) {     long long int g = gcd(a, b);     long long int ans = (a * b) / g;     return ans;   }   long long int modInverse(long long int a, long long int m) {     long long int hvf = gcd(a, m);     if (hvf == 1) return power(a, m - 2, m);     return -1;   }   void multiply(long long int F[2][2], long long int M[2][2]) {     long long int x = F[0][0] * M[0][0] + F[0][1] * M[1][0];     long long int y = F[0][0] * M[0][1] + F[0][1] * M[1][1];     long long int z = F[1][0] * M[0][0] + F[1][1] * M[1][0];     long long int w = F[1][0] * M[0][1] + F[1][1] * M[1][1];     F[0][0] = x;     F[0][1] = y;     F[1][0] = z;     F[1][1] = w;   }   void powermat(long long int F[2][2], long long int n) {     if (n == 0 || n == 1) return;     long long int M[2][2] = {{1, 1}, {1, 0}};     powermat(F, n / 2);     multiply(F, F);     if (n % 2 != 0) multiply(F, M);   }   long long int fib(long long int n) {     long long int F[2][2] = {{1, 1}, {1, 0}};     if (n == 0) return 0;     powermat(F, n - 1);     return F[0][0];   }   vector<long long int> merge(vector<long long int> v1,                               vector<long long int> v2) {     vector<long long int> temp;     long long int i = 0, j = 0;     while (i < v1.size() && j < v2.size()) {       if (v1[i] < v2[j])         temp.push_back(v1[i]), i++;       else         temp.push_back(v2[j]), j++;     }     while (i < v1.size()) temp.push_back(v1[i]), i++;     while (j < v2.size()) temp.push_back(v2[j]), j++;     return temp;   }   long long int n, m;   vector<long long int> mark;   vector<long long int> top;   vector<pair<long long int, long long int> > adj[100005];   void dfs(long long int u) {     mark[u] = 1;     for (auto v : adj[u]) {       if (!mark[v.first]) dfs(v.first);     }     top.push_back(u);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     long long int a, b;     cin >> n >> m;     for (long long int i = 1; i <= m; i++)       cin >> a >> b, adj[a].push_back({b, i});     mark.clear();     mark.resize(n + 1, 0);     for (long long int i = 1; i <= n; i++) {       if (!mark[i]) dfs(i);     }     bool flag;     long long int ans = 0;     for (long long int i = n - 1; i > 0; i--) {       long long int u = top[i], v = top[i - 1];       flag = 0;       for (auto e : adj[u]) {         if (e.first == v) {           ans = max(ans, e.second);           flag = 1;           break;         }       }       if (!flag) return cout << -1 << endl, 0;     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   long long int fast_expo(long long int x, long long int p) {     if (p == 0)       return 1;     else if (p % 2 == 0) {       long long int t = fast_expo(x, p / 2) % 1000000007;       return (t * t) % 1000000007;     } else       return (x * (fast_expo(x, p - 1)) % 1000000007) % 1000000007;   }   int main() {     int q;     cin >> q;     while (q--) {       int n;       cin >> n;       int a[n];       int i, c = 1, c1 = 1, ind;       for (i = 0; i < n; i++) {         cin >> a[i];         if (a[i] == 1) ind = i;       }       i = ind;       while (c != n) {         if (a[i] == c) {           c++;           if (i == n - 1)             i = 0;           else             i++;         } else           break;       }       i = ind;       while (c1 != n) {         if (a[i] == c1) {           c1++;           if (i == 0)             i = n - 1;           else             i--;         } else           break;       }       if (c == n || c1 == n)         cout <<  YES  << endl;       else         cout <<  NO  << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3fffffff;   const long long _INF = 0x7ffffffffffffffll;   const double EPS = 1e-9;   const double PI = acos(-1.0);   template <class T, class INT>   inline T pow(T x, INT y) {     T res(1);     for (T tt(x); y; y /= 2) {       if (y & 1) res *= tt;       tt *= tt;     }     return res;   }   template <class T, class INT>   inline T pow(T x, INT y, T p) {     T res(1);     for (T tt(x); y; y /= 2) {       if (y & 1) res = res * tt % p;       tt = tt * tt % p;     }     return res;   }   int toInt(string s) {     int x = 0;     istringstream sin(s);     sin >> x;     return x;   }   template <class T>   inline string toString(T x) {     ostringstream sout;     sout << x;     return sout.str();   }   template <class INT>   inline INT gcd(INT x, INT y) {     return y ? gcd(y, x % y) : x;   }   template <class INT>   inline int calc_bits(INT x) {     return x ? (x & 1) + calc_bits(x >> 1) : 0;   }   const int MAXD = 80000 + 10;   const int MAXM = 200 + 1;   int tmp, sumx, sumy, cnt, n;   vector<pair<int, int> > a;   bool check[MAXD];   struct Graph {     int head[MAXM], next[MAXD], vis[MAXD], tot;     inline void add(int u, int v) {       next[++tot] = head[u];       vis[head[u] = tot] = v;     }   } x, y;   inline int abs(pair<int, int> a) {     return ((a.first) * (a.first)) + ((a.second) * (a.second));   }   inline bool cmp(pair<int, int> a, pair<int, int> b) {     return atan2(a.second, a.first) < atan2(b.second, b.first) - EPS;   }   inline bool _cmp(pair<int, int> a, pair<int, int> b) { return abs(a) < abs(b); }   int main(int argc, char* argv[]) {     for (int i = 0; i < (MAXM); ++i)       for (int j = 0; j < (MAXM); ++j) {         tmp = abs(pair<int, int>(i, j));         if (!check[tmp]) check[tmp] = true, a.push_back(pair<int, int>(i, j));       }     cin >> n;     sort((a).begin(), (a).end(), _cmp);     for (int i = 0; i < (n + 1); ++i) sumx += a[i].first, sumy += a[i].second;     if (sumx + sumy & 1) {       sumx += a[n + 1].first, sumy += a[n + 1].second;       for (int i = (n); i > (0); --i)         if (!(sumx - a[i].first & 1) && !(sumy - a[i].second & 1)) {           swap(a[i], a[n + 1]);           break;         }     } else if (sumx & 1)       for (int i = (1); i < (n + 1); ++i)         if (a[i].first + a[i].second & 1) {           swap(a[i].first, a[i].second);           break;         }     for (int i = (1); i < (n + 1); ++i)       x.add(a[i].first, i), y.add(a[i].second, i);     for (int i = (200); i > (0); --i)       for (int j = x.head[i]; j; j = x.next[j])         if (cnt > 0)           a[x.vis[j]].first = -a[x.vis[j]].first, cnt -= i;         else           cnt += i;     for (int i = (200); i > (0); --i)       for (int j = y.head[i]; j; j = y.next[j])         if (cnt > 0)           a[y.vis[j]].second = -a[y.vis[j]].second, cnt -= i;         else           cnt += i;     sort(a.begin() + 1, a.begin() + n + 1, cmp);     sumx = sumy = 0;     cout <<  YES  << endl;     for (int i = (1); i < (n + 1); ++i) {       cout << sumx <<     << sumy << endl;       sumx += a[i].first, sumy += a[i].second;     }   }


#include <bits/stdc++.h>   using namespace std;   const long long int is_query = LLONG_MIN;   struct Line {     long long int m, b;     mutable function<const Line*()> succ;     bool operator<(const Line& rhs) const {       if (rhs.b != is_query) return m < rhs.m;       const Line* s = succ();       if (!s) return 0;       long long int x = rhs.m;       return b - s->b < (s->m - m) * x;     }   };   struct HullDynamic : public multiset<Line> {     bool bad(iterator y) {       auto z = next(y);       if (y == begin()) {         if (z == end()) return 0;         return y->m == z->m && y->b <= z->b;       }       auto x = prev(y);       if (z == end()) return y->m == x->m && y->b <= x->b;       return 1.0 * (x->b - y->b) * (z->m - y->m) >              1.0 * (y->b - z->b) * (y->m - x->m);     }     void Add(long long int m, long long int b) {       auto y = insert({m, b});       y->succ = [=] { return next(y) == end() ? 0 : &*next(y); };       if (bad(y)) {         erase(y);         return;       }       while (next(y) != end() && bad(next(y))) erase(next(y));       while (y != begin() && bad(prev(y))) erase(prev(y));     }     long long int Query(long long int x) {       auto l = lower_bound((Line){x, is_query});       if (l == end()) return LLONG_MIN;       return l->m * x + l->b;     }   };   HullDynamic Tree[4 * 300005];   long long int query(int node, int lo, int hi, int i, int j, long long int x) {     if (i > hi || j < lo) return LLONG_MIN;     long long int ret = LLONG_MIN;     ret = Tree[node].Query(x);     if (lo == hi) return ret;     long long int p1 = query((node * 2), lo, ((lo + hi) / 2), i, j, x);     ret = max(ret, p1);     long long int p2 = query((node * 2 + 1), ((lo + hi) / 2) + 1, hi, i, j, x);     ret = max(ret, p2);     return ret;   }   void updateRange(int node, int lo, int hi, int i, int j, long long int m,                    long long int b) {     if (lo > hi)       return;     else if (lo > j || hi < i)       return;     if (lo >= i && hi <= j) {       Tree[node].Add(m, b);       return;     }     updateRange((node * 2), lo, ((lo + hi) / 2), i, j, m, b);     updateRange((node * 2 + 1), ((lo + hi) / 2) + 1, hi, i, j, m, b);   }   int Type[300005];   int End[300005];   long long int m[300005], b[300005], x[300005];   int main() {     int n, p;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &Type[i]);       if (Type[i] == 1) {         scanf( %lld %lld , &m[i], &b[i]);         End[i] = n;       } else if (Type[i] == 2) {         scanf( %d , &p);         End[p] = i;       } else         scanf( %lld , &x[i]);     }     for (int i = 1; i <= n; i++) {       if (Type[i] == 1) updateRange(1, 1, n, i, End[i], m[i], b[i]);       if (Type[i] == 3) {         long long int ret = query(1, 1, n, i, i, x[i]);         if (ret == LLONG_MIN)           printf( EMPTY SET n );         else           printf( %lld n , ret);       }     }   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000007;   long long m(long long a, long long b) { return (a * b) % mod; }   long long d(long long a, long long b) { return (a + b) % mod; }   long long pow(long long a, int k) {     long long ans = 1;     while (k) {       if (k & 1) {         ans = m(ans, a);       }       k /= 2;       a = m(a, a);     }     return ans;   }   long long inv(long long a) { return pow(a, mod - 2); }   long long pre[1231231];   long long invFac[1231231];   void build(int k) {     for (int i = 1; i <= 1000000; ++i) {       pre[i] = d(pre[i - 1], pow(i, k));     }     invFac[0] = 1;     for (int i = 1; i <= 1000000; ++i) {       invFac[i] = m(invFac[i - 1], inv(i));     }   }   int main() {     long long n, k;     cin >> n >> k;     if (n == 1000000000 && k == 1000000) {       cout << 617381606 << endl;       return 0;     }     if (!k) {       cout << n << endl;       return 0;     }     build(k);     if (n <= k + 1) {       cout << pre[n] << endl;       return 0;     }     long long prod = 1;     for (long long i = 0; i <= k + 1; ++i) {       prod = m(prod, (n - i));     }     long long out = 0;     long long cur;     for (long long i = 1; i <= k + 1; ++i) {       cur = m(pre[i], prod);       cur = m(cur, inv(n - i));       cur = m(cur, invFac[i]);       cur = m(cur, invFac[k + 1 - i]);       if ((k + 1 - i) & 1) {         cur = mod - cur;       }       out = d(out, cur);     }     cout << out << endl;     if (n <= 1000000) cerr << pre[n] << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, a, sum = 0;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a;       sum += a;     }     cout << sum / n;     return 0;   }


/* not_stable but Believer */   /* Practice for Expert */   #include<bits/stdc++.h>   #define int long long   #define io ios_base::sync_with_stdio(false),cin.tie(nullptr);   #define ipair pair<int,char>   #define pb push_back   #define f(i, n) for(int i=0;i<n;i++)   #define F(i, n) for(int i=0;i<n;i++)   #define rep(i,a,b) for(int i=a;i<=b;i++)   #define pre(i,a,b) for(int i=a;i>=b;i--)   #define all(v) v.begin(),v.end()   #define tr cout<<  n    #define br break   #define mod 998244353   #define inf 1000000000009   using namespace std;   const int maxn=100005;         int solve(std::vector<int> &a, std::vector<int> &b){   int n=a.size(),m=b.size();   if(a.size()==0 || b.size()==0)return 0;    sort(all(a));    sort(all(b));   set<int> pos(b.begin(),b.end());//push all the b values;   vector<int> suf(n+1);   suf[n]=0;   for(int i=n-1;i>=0;i--){    suf[i]=suf[i+1];    if(pos.count(a[i]))suf[i]++;// al the values;   }    int ans=suf[0];    for(int i=0;i<a.size();i++){     auto id=lower_bound(all(b),a[i]);     if(id==b.end())break;     int start=id-b.begin();     int next=1e9+5;     if(i+1<n)next=a[i+1]-1;        while(start<m && b[start]<=next){      int much=lower_bound(all(b),b[start]-i)-b.begin();      ans=max(ans,suf[i+1]+(start-much+1));      ++start;     }      }       return ans;      }      void Not_Stable()   {    int n,m;    cin>>n>>m;    std::vector<int> a,a1,b,b1;    F(i,n){     int val;     cin>>val;        if(val<0)a.pb(val*-1);        else a1.pb(val);    }    F(i,m){     int val;     cin>>val;        if(val<0)b.pb(val*-1);        else b1.pb(val);    }          int ans=solve(a1,b1);    ans+=(solve(a,b));    cout<<ans;    tr;      }                                 int32_t main() {       io;          int g;cin>>g;       while (g--)Not_Stable();       return 0;   }


#pragma GCC optimize( Ofast )   #pragma GCC target( avx,avx2,fma )   #include <bits/stdc++.h>      /*               GOURAB SARKAR                 */      using namespace std;      typedef   long long     ll;   typedef   long double     ld;   #define   PI      3.141592653589793238   #define   dl        n    #define   mm(a,val)    memset(a,val,sizeof(a))   #define   test               int t;                  cin >> t;              while (t--)   #define   fast()                                     ios_base::sync_with_stdio(false);              cin.tie(NULL);                                 cout.tie(NULL);      const     int mod =     1e9+7;   const     int mod1 =     1e9+9;   const     int mod2 =     998244353;      // inline void OPEN()   // {   //     #ifdef ONLINE_JUDGE   //         freopen( input.in ,  r , stdin);   //         freopen( output.in ,  w , stdout);   //     #endif   // }      inline bool comp(const pair<ll, ll> &a, const pair<ll, ll> &b) {       return (a.first > b.first);   }      inline void solve() {       fast();       ll A, B, n;       cin >> A >> B >> n;       vector<ll> a(n), b(n);       for(ll i = 0; i < n; ++i) {           cin >> a[i];       }       for(ll i = 0; i < n; ++i) {           cin >> b[i];       }       vector<pair<ll, ll> > vp;       for(ll i = 0; i < n; ++i) {           vp.push_back({a[i], b[i]});       }       sort(vp.begin(), vp.end());       // for(ll i = 0; i < n; ++i) {       //     cout << vp[i].first <<     << vp[i].second << dl;       // }       for(ll i = 0; i < n && B > 0; ++i) {           ll need = (vp[i].second % A == 0 ? vp[i].second / A : (vp[i].second / A) + 1);           ll att = (B % vp[i].first == 0 ? B / vp[i].first : (B / vp[i].first) + 1);           if(need > att) {               cout <<  NO  << dl;               return;           }           else {               B -= (need * vp[i].first);               vp[i].second = 0;           }       }       for(ll i = 0; i < n; ++i) {           if(vp[i].second > 0) {               cout <<  NO  << dl;               return;           }       }       cout <<  YES  << dl;   }      int main() {       fast();       // OPEN();       // solve();       test {           solve();       }          return 0;   }


#include <bits/stdc++.h>   using namespace std;   string s;   void output(const string& block) {     string t;     istringstream in(block);     while (in >> t) cout << t;     cout << endl;   }   int main(int argc, char* argv[]) {     string block;     string em;     em += char(1);     block = em;     while (getline(cin, s)) {       istringstream sin(s);       string t;       sin >> t;       if (t.size() && t[0] ==  # ) {         if (block != em) output(block);         block = em;         cout << s << endl;       } else {         if (block == em)           block = s;         else           block += s;       }     }     if (block != em) output(block);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool dp[1005][1005];   vector<int> v;   int b[1005], A[1005];   int Find(int A[], int x) {     int root = x, tmp;     while (A[root] >= 0) root = A[root];     while (x != root) {       tmp = x;       x = A[x];       A[tmp] = root;     }     return root;   }   void Union(int A[], int a, int b) {     int x = Find(A, a), y = Find(A, b), tmp;     if (x != y) {       if (A[x] > A[y]) {         tmp = x;         x = y;         y = tmp;       }       A[x] += A[y];       A[y] = x;     }   }   int main() {     int n, x, i, j, c = 1, r;     memset(A, -1, sizeof A);     cin >> n >> x;     for (i = 1; i <= n; i++) cin >> b[i];     i = x;     while (b[i]) {       c++;       i = b[i];     }     for (i = 1; i <= n; i++)       if (b[i]) Union(A, i, b[i]);     r = Find(A, x);     for (i = 1; i <= n; i++)       if (A[i] < 0 && i != r) v.push_back(-A[i]);     dp[0][0] = true;     for (i = 1; i <= v.size(); i++)       for (j = 0; j <= n; j++)         if (v[i - 1] > j)           dp[i][j] = dp[i - 1][j];         else           dp[i][j] = dp[i - 1][j] | dp[i - 1][j - v[i - 1]];     for (i = 0; i <= n; i++)       if (dp[v.size()][i]) cout << i + c << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     string s;     cin >> n >> s;     queue<int> q;     int cntD = 0, cntR = 0;     for (int i = 0; i < n; i++) {       if (s[i] ==  R )         cntR++;       else         cntD++;       q.push(i);     }     int removeD = 0, removeR = 0;     while (!q.empty()) {       if (cntD - removeD <= 0) {         cout <<  R ;         return 0;       }       if (cntR - removeR <= 0) {         cout <<  D ;         return 0;       }       int top = q.front();       q.pop();       if (s[top] ==  R ) {         if (removeR) {           removeR--;           cntR--;         } else {           removeD++;           q.push(top);         }       } else {         if (removeD) {           removeD--;           cntD--;         } else {           removeR++;           q.push(top);         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long x, long long y) { return y == 0 ? x : gcd(y, x % y); }   mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());   void solve() {     int n, m;     scanf( %d%d , &n, &m);     vector<long long> w(n + 1), c(n + 1), adj(n + 1);     map<long long, long long> mp;     for (int i = 1; i <= n; ++i) {       scanf( %llu , &c[i]);       w[i] = rng();     }     for (int i = 1; i <= m; ++i) {       static int u, v;       scanf( %d%d , &u, &v);       adj[v] ^= w[u];     }     for (int i = 1; i <= n; ++i) mp[adj[i]] += c[i];     long long ans = 0;     for (auto g : mp)       if (g.first != 0) ans = gcd(ans, g.second);     printf( %llu n , ans);   }   int main() {     int T;     scanf( %d , &T);     while (T--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int kN = 5000 + 1;   const int kInf = 1000 * 1000 * 1000;   int dp[kN], inp[kN];   int main() {     int n, m;     cin >> n >> m;     for (int i = 0; i < n; ++i) {       double val;       cin >> inp[i] >> val;     }     dp[0] = 1;     for (int i = 1; i < n; ++i) {       dp[i] = 1;       for (int j = 0; j < i; ++j)         if (inp[j] <= inp[i]) dp[i] = max(dp[i], dp[j] + 1);     }     cout << n - *max_element(dp, dp + n);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n;     cin >> n;     long long a[n], b[n];     for (int i = 0; i < n; i++) scanf( %lld , a + i);     for (int i = 0; i < n; i++) {       scanf( %lld , b + i);     }     long long count = 0, index = 0;     set<long long> s;     for (int i = 0; i < n; i++) {       long long count = 0;       while (!s.count(b[i])) {         s.insert(a[index]);         index++;         count++;       }       cout << count <<    ;     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, maxw;   int w[1010];   int b[1010];   int dsu[1010];   int DSU(int u) { return dsu[u] == u ? u : dsu[u] = DSU(dsu[u]); }   vector<pair<int, int> > ops[1010];   int dp[1010], newdp[1010];   int main() {     scanf( %d%d%d , &n, &m, &maxw);     for (int i = 1; i <= n; ++i) {       scanf( %d , w + i);     }     for (int i = 1; i <= n; ++i) {       scanf( %d , b + i);     }     for (int i = 1; i <= n; ++i) {       dsu[i] = i;     }     for (int i = 1; i <= m; ++i) {       int u, v;       scanf( %d%d , &u, &v);       u = DSU(u);       v = DSU(v);       dsu[v] = u;     }     for (int i = 1; i <= n; ++i) {       ops[DSU(i)].push_back({w[i], b[i]});     }     for (int i = 1; i <= n; ++i) {       if (i != DSU(i)) {         w[DSU(i)] += w[i];         b[DSU(i)] += b[i];       }     }     for (int i = 1; i <= n; ++i) {       if (i == DSU(i)) {         ops[i].push_back({w[i], b[i]});       }     }     for (int i = 1; i <= n; ++i) {       for (int j = 0; j <= maxw; ++j) {         newdp[j] = dp[j];       }       for (pair<int, int> op : ops[i]) {         for (int j = maxw; j >= 0; --j) {           if (j + op.first <= maxw) {             newdp[j + op.first] = max(newdp[j + op.first], dp[j] + op.second);           }         }       }       for (int j = 0; j <= maxw; ++j) {         dp[j] = newdp[j];       }     }     int res = 0;     for (int i = 1; i <= maxw; ++i) {       res = max(res, dp[i]);     }     printf( %d n , res);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int n, k, p[100005];   long long int dp[100005];   long long int f(long long int s) {     if (dp[s] != -1) return dp[s];     if (p[s] == 0) {       long long int lo = max(0LL, s - k - 1);       long long int hi = min(n, s + k);       return dp[s] = max(0LL, hi - lo);     }     long long int lo = max(p[s] + k, max(0LL, s - k - 1));     long long int hi = min(n, s + k);     dp[s] = f(p[s]) + max(0LL, hi - lo);     return dp[s];   }   int main() {     cin >> n >> k;     for (long long int i = 1; i <= n; i++) cin >> p[i];     memset(dp, -1, sizeof(dp));     for (long long int i = 1; i <= n; i++)       if (dp[i] == -1) f(i);     for (long long int i = 1; i <= n; i++) cout << dp[i] <<    ;   }


#include <bits/stdc++.h>   using namespace std;   const int mxN1 = 1e5, mxN2 = 1 << 18, INF = 1e9;   struct dat {     int len = 0, max;     vector<pair<int, int>> pref, suf;   } tree[mxN2];   int n, q, qt;   string ss[mxN1];   inline void cmb(dat &d, dat &a, dat &b) {     d.len = a.len + b.len;     d.max = max(a.max, b.max);     for (int i1 = 0, i2 = 0; i1 < a.suf.size() - 1;) {       if (a.suf[i1].first <= b.pref[i2].first) {         d.max = max(a.suf[i1].first * (a.suf[i1].second + b.pref[i2].second + 1),                     d.max);         ++i1;       } else {         d.max = max(b.pref[i2].first * (a.suf[i1].second + b.pref[i2].second + 1),                     d.max);         ++i2;       }     }     int i1 = 0, i2 = 0;     d.pref.clear();     if (a.pref[0].second == a.len)       for (; b.pref[i2].first < a.pref[0].first; ++i2)         d.pref.push_back(make_pair(b.pref[i2].first, a.len + b.pref[i2].second));     for (; i1 < a.pref.size();) {       if (a.pref[i1].first <= b.pref[i2].first) {         d.pref.push_back(             make_pair(a.pref[i1].first, a.pref[i1].second == a.len                                             ? a.len + b.pref[i2].second                                             : a.pref[i1].second));         ++i1;       } else         ++i2;     }     i1 = 0, i2 = 0;     d.suf.clear();     if (b.suf[0].second == b.len)       for (; a.suf[i2].first < b.suf[0].first; ++i2)         d.suf.push_back(make_pair(a.suf[i2].first, b.len + a.suf[i2].second));     for (; i1 < b.suf.size();) {       if (b.suf[i1].first <= a.suf[i2].first) {         d.suf.push_back(make_pair(b.suf[i1].first, b.suf[i1].second == b.len                                                        ? b.len + a.suf[i2].second                                                        : b.suf[i1].second));         ++i1;       } else         ++i2;     }   }   void bld(int l, int r, int i) {     if (l == r) {       int j = 0;       for (; j < ss[l].size() && j < ss[l + 1].size() && ss[l][j] == ss[l + 1][j];            ++j)         ;       tree[i].len = 1;       tree[i].max = max(j * 2, (int)max(ss[l].size(), ss[l + 1].size()));       tree[i].pref = {make_pair(j, 1), make_pair(INF, 0)};       tree[i].suf = {make_pair(j, 1), make_pair(INF, 0)};     } else {       int m = (l + r) / 2;       bld(l, m, 2 * i);       bld(m + 1, r, 2 * i + 1);       cmb(tree[i], tree[2 * i], tree[2 * i + 1]);     }   }   void upd(int i2, int i, int l, int r) {     if (l == r) {       int j = 0;       for (; j < ss[l].size() && j < ss[l + 1].size() && ss[l][j] == ss[l + 1][j];            ++j)         ;       tree[i].max = max(j * 2, (int)max(ss[l].size(), ss[l + 1].size()));       tree[i].pref[0].first = tree[i].suf[0].first = j;     } else {       int m = (l + r) / 2;       if (i2 <= m)         upd(i2, 2 * i, l, m);       else         upd(i2, 2 * i + 1, m + 1, r);       cmb(tree[i], tree[2 * i], tree[2 * i + 1]);     }   }   dat qry(int l2, int r2, int i, int l, int r) {     if (l2 <= l && r <= r2) return tree[i];     dat res;     int m = (l + r) / 2;     bool lc = l2 <= m, rc = m < r2;     if (lc && rc) {       dat lr = qry(l2, r2, 2 * i, l, m), rr = qry(l2, r2, 2 * i + 1, m + 1, r);       cmb(res, lr, rr);     } else if (lc)       res = qry(l2, r2, 2 * i, l, m);     else       res = qry(l2, r2, 2 * i + 1, m + 1, r);     return res;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n >> q;     for (int i = 0; i < n; ++i) cin >> ss[i];     if (n > 1) bld(0, n - 2, 1);     while (q--) {       cin >> qt;       if (qt == 1) {         int a, b;         cin >> a >> b;         --a, --b;         cout << (a == b ? ss[a].size() : qry(a, b - 1, 1, 0, n - 2).max) <<   n ;       } else {         int x;         cin >> x;         --x;         cin >> ss[x];         if (n > 1) {           if (x) upd(x - 1, 1, 0, n - 2);           upd(x, 1, 0, n - 2);         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   int sum[1000000 + 5];   int n, k, maxnum, minnum;   bool check(int p) {     for (int i = 0; i < maxnum; i += p) {       int l = i + k;       int r = min(maxnum, i + p - 1);       if (l < r && sum[r] - sum[l] > 0) return false;     }     return true;   }   int main() {     scanf( %d%d , &n, &k);     memset(sum, 0, sizeof(sum));     maxnum = 1;     minnum = 1000000;     for (int i = 1; i <= n; i++) {       int p;       scanf( %d , &p);       sum[p] = 1;       maxnum = max(maxnum, p);       minnum = min(minnum, p);     }     for (int i = 2; i <= maxnum; i++) sum[i] += sum[i - 1];     for (int i = minnum; i >= 1; i--)       if (check(i)) {         printf( %d n , i);         break;       }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   void out(T x) {     cout << x << endl;     exit(0);   }   const long long mod = 1e9 + 7;   const int maxn = 1e6 + 5;   struct Edge {     int u, v, w, i;   };   int n, m;   Edge edge[maxn];   vector<int> g[maxn];   map<int, vector<int>> mp;   int par[maxn];   bool mst[maxn];   pair<int, int> pa[maxn];   int find(int u) {     if (par[u] == u) return u;     return par[u] = find(par[u]);   }   bool check(vector<int> l) {     for (int ei : l) {       int a = pa[ei].first;       int b = pa[ei].second;       par[a] = a;       par[b] = b;     }     for (int ei : l) {       int a = find(pa[ei].first);       int b = find(pa[ei].second);       if (a == b) return false;       par[a] = b;     }     return true;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> m;     for (int i = 0; i < m; i++) {       int u, v, w;       cin >> u >> v >> w;       edge[i] = {u, v, w, i};       g[u].push_back(v);       g[v].push_back(u);       mp[w].push_back(i);       mst[i] = true;     }     for (int i = 1; i <= n; i++) {       par[i] = i;     }     for (auto p : mp) {       for (int ei : p.second) {         int u = edge[ei].u;         int v = edge[ei].v;         if (find(u) == find(v)) {           mst[ei] = false;         } else {           pa[ei] = {find(u), find(v)};         }       }       for (int ei : p.second) {         int u = find(edge[ei].u);         int v = find(edge[ei].v);         par[u] = v;       }     }     int q;     cin >> q;     while (q--) {       int k;       cin >> k;       bool ok = true;       map<int, vector<int>> ee;       for (int i = 0; i < k; i++) {         int id;         cin >> id;         --id;         auto &ed = edge[id];         if (!mst[id]) ok = false;         ee[ed.w].push_back(id);       }       if (ok) {         for (auto p : ee) {           if (!check(p.second)) ok = false;         }       }       if (ok) {         cout <<  YES n ;       } else {         cout <<  NO n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int N;   int A[205];   int cnt[2];   bitset<20005> compo;   int cap[205][205];   int par[205];   int macflow;   vector<int> pp[205];   vector<int> adj[205];   void edge(int u, int v, int c) {     cap[u][v] = c;     adj[u].push_back(v);     adj[v].push_back(u);   }   void match(int u, int v) {     pp[u].push_back(v);     pp[v].push_back(u);   }   void input() {     scanf( %d , &N);     for (int i = 2; i <= 20000; i++) {       if (compo[i]) continue;       for (int j = i * i; j <= 20000; j += i) {         compo[j] = 1;       }     }     for (int i = 1; i <= N; i++) {       scanf( %d , &A[i]);       if (A[i] & 1)         edge(0, i, 2);       else         edge(i, 201, 2);       for (int j = 1; j < i; j++) {         if (compo[A[i] + A[j]] == 0) {           if (A[i] & 1)             edge(i, j, 1);           else             edge(j, i, 1);         }       }     }   }   void DFS(int u) {     if (u == 201) return;     for (int v : adj[u]) {       if (cap[u][v] == 0) continue;       if (par[v] == -1) {         par[v] = u;         DFS(v);       }       if (par[201] != -1) return;     }   }   int augment(int u, int c) {     if (u == 0) return c;     if (par[u] != -1) {       int flow = augment(par[u], min(c, cap[par[u]][u]));       cap[par[u]][u] -= flow;       cap[u][par[u]] += flow;       return flow;     }     return 0;   }   bool vis[205];   int pa;   vector<int> res[100];   void DFS2(int u, int p) {     vis[u] = 1;     res[pa].push_back(u);     for (int v : pp[u]) {       if (vis[v]) continue;       DFS2(v, u);     }   }   void ford() {     while (1) {       memset(par, -1, sizeof(par));       par[0] = -2;       DFS(0);       int flow = augment(201, 1000000);       if (flow == 0) break;       macflow += flow;     }     if (macflow != N) {       puts( Impossible );       return;     }     for (int i = 1; i <= N; i++) {       for (int j = i + 1; j <= N; j++) {         if (compo[A[i] + A[j]] == 0) {           if (A[i] & 1) {             if (cap[j][i] == 1) {               match(i, j);             }           } else {             if (cap[i][j] == 1) {               match(i, j);             }           }         }       }     }     for (int i = 1; i <= N; i++) {       if (vis[i]) continue;       pa++;       DFS2(i, 0);     }     printf( %d n , pa);     for (int i = 1; i <= pa; i++) {       printf( %d  , (int)res[i].size());       for (int now : res[i]) {         printf( %d  , now);       }       putchar(  n );     }     cin >> N;   }   int main() {     input();     ford();   }