#include <bits/stdc++.h>   using namespace std;   const int HX = 0x3F3F3F3F;   int n, m, p, q;   long long k;   int f[1111];   int main() {     cin >> n >> m >> k;     memset(f, 0x3F, sizeof f);     for (int i = 0; i < (n); ++i) {       cin >> p >> q;       f[p] = min(f[p], q);     }     long long ans = 0;     for (int i = (1); i <= (m); ++i) ans += f[i];     cout << min(ans, k) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2 * 1000 * 100 + 100;   int n, m, w[N], deg[N], ans[N];   vector<pair<int, int>> adj[N];   bool vis[N];   int main() {     ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);     cin >> n >> m;     for (int i = 1; i <= n; i++) cin >> w[i];     for (int i = 1, v, u; i <= m; i++) {       cin >> v >> u;       deg[v]++, deg[u]++;       adj[v].push_back({u, i});       adj[u].push_back({v, i});     }     queue<int> q;     for (int i = 1; i <= n; i++)       if (deg[i] <= w[i]) q.push(i), vis[i] = true;     int ind = m;     while (q.size()) {       int x = q.front();       q.pop();       for (auto u : adj[x]) {         deg[u.first]--, deg[x]--;         if (deg[u.first] <= w[u.first] && !vis[u.first])           vis[u.first] = true, q.push(u.first);         if (!ans[u.second]) ans[u.second] = ind--;       }     }     vector<int> res(m + 10);     for (int i = 1; i <= m; i++) {       if (!ans[i]) return cout <<  DEAD n , 0;       res[ans[i]] = i;     }     cout <<  ALIVE n ;     for (int i = 1; i <= m; i++) cout << res[i] <<    ;     cout <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<vector<int> > adj(601);   vector<int> unvisited, even, odd;   int d[601], parent[601];   bool visited[601];   map<vector<int>, int> M;   void RemoveFromUnvisited(int v) {     int i = 0;     for (; i < unvisited.size() && unvisited[i] != v; ++i)       ;     unvisited.erase(unvisited.begin() + i);   }   void PrintQueryOrAnswer(char c, vector<int> &A) {     printf( %c %lu n , c, A.size());     for (auto x : A) {       printf( %d  , x);     }     printf(  n );     fflush(stdout);   }   int PrintQuery(vector<int> A) {     sort(A.begin(), A.end());     if (M.find(A) != M.end()) {       return M[A];     }     PrintQueryOrAnswer( ? , A);     int m;     scanf( %d , &m);     M[A] = m;     return m;   }   int Query(vector<int> &A, int s = 0) {     if (s) {       A.push_back(s);     }     int m = PrintQuery(A);     if (s) {       A.pop_back();     }     return m;   }   int NextChild(int i, vector<int> A) {     if (A.size() == 0) {       return 0;     }     int m1 = Query(A, i);     if (m1 == 0) {       return 0;     }     if (A.size() == 1) {       return A.back();     }     int m2 = Query(A);     if (m2 == m1) {       return 0;     }     int j = NextChild(i, vector<int>(A.begin(), A.begin() + (A.size() / 2)));     if (j == 0) {       j = NextChild(i, vector<int>(A.begin() + (A.size() / 2), A.end()));     }     return j;   }   void AddEdge(int i, int j) {     adj[i].push_back(j);     adj[j].push_back(i);   }   void AddEdgeDFS(int i, bool markEvenOdd) {     RemoveFromUnvisited(i);     if (markEvenOdd) {       if (d[i]) {         odd.push_back(i);       } else {         even.push_back(i);       }     }     for (int j = NextChild(i, unvisited); j > 0; j = NextChild(i, unvisited)) {       AddEdge(i, j);       if (markEvenOdd) {         d[j] = 1 - d[i];       }       AddEdgeDFS(j, markEvenOdd);     }   }   pair<int, int> BipartiteDFS(int i, int p) {     parent[i] = p;     d[i] = 1 + d[p];     visited[i] = 1;     pair<int, int> ans = make_pair(0, 0);     for (auto j : adj[i]) {       if (j == p) {         continue;       }       if (visited[j]) {         if ((d[i] - d[j]) % 2 == 0 && d[i] > d[j]) {           return make_pair(i, j);         }         continue;       }       ans = max(ans, BipartiteDFS(j, i));     }     return ans;   }   void AddEdges(vector<int> v, bool markEvenOdd) {     unvisited = vector<int>(v);     while (unvisited.size()) {       AddEdgeDFS(unvisited.back(), markEvenOdd);     }   }   int main() {     int n;     vector<int> V;     scanf( %d , &n);     for (int i = 1; i <= n; ++i) {       V.push_back(i);     }     AddEdges(V, true);     AddEdges(even, false);     AddEdges(odd, false);     pair<int, int> p = make_pair(0, 0);     for (int i = 1; i <= n; ++i) {       if (visited[i]) {         continue;       }       p = max(p, BipartiteDFS(i, 0));     }     int u, v;     tie(u, v) = p;     vector<int> ans;     if (u == 0) {       for (int i = 1; i <= n; ++i) {         if (d[i] % 2) {           ans.push_back(i);         }       }     } else {       for (; u != parent[v]; u = parent[u]) {         ans.push_back(u);       }     }     PrintQueryOrAnswer(v ?  N  :  Y , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int pow2[30];   int ar[1000900], mark[1000090];   int main() {     int n;     int a, b;     pow2[0] = 1;     for (int i = 1, _n = 30; i < _n; i++) pow2[i] = pow2[i - 1] * 2;     while (cin >> n) {       memset(mark, -1, sizeof(mark));       int m = n - 1, r = 0;       while (m > 1) {         if (m % 2) r = 1;         m /= 2;       }       if (n != 2 && !r) {         mark[1] = 0;         mark[0] = 1;       }       for (int i = n; i >= 0; i--) {         if (mark[i] == -1) {           int hi = 29, low = 0, x = 0;           while (hi >= low) {             int mid = (hi + low) / 2;             if (pow2[mid] > i) {               hi = mid - 1;             } else if (pow2[mid] <= i)               low = mid + 1, x = pow2[mid];           }           int d = i - x;           mark[i] = x - d - 1;           mark[x - d - 1] = i;         }       }       long long ret = 0;       for (int i = 0, _n = n + 1; i < _n; i++) ret += (i ^ max(mark[i], 0));       cout << ret << endl;       for (int i = 0, _n = n + 1; i < _n; i++) {         if (i) cout <<    ;         if (mark[i] == -1) mark[i] = 0;         cout << mark[i];       }       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long T, n, a[300010], c[300010], l[300010], r[300010];   long long lowbit(long long x) { return x & (-x); }   void add(long long x, long long k) {     for (long long i = x; i <= n; i += lowbit(i)) c[i] += k;   }   long long query(long long x) {     long long sum = 0;     for (long long i = x; i >= 1; i -= lowbit(i)) sum += c[i];     return sum;   }   signed main() {     memset(l, 0, sizeof(l));     memset(r, 0, sizeof(r));     scanf( %lld , &n);     for (long long i = 1; i <= n; i++) scanf( %lld , &a[i]);     memset(c, 0, sizeof(c));     for (long long i = 1; i <= n; i++) {       if (2 * a[i] - 1 <= n)         l[i] = query(2 * a[i] - 1);       else         l[i] = query(n) - query(2 * a[i] - n - 1);       add(a[i], a[i]);     }     memset(c, 0, sizeof(c));     for (long long i = n; i >= 1; i--) {       if (2 * a[i] - 1 <= n)         r[i] = query(2 * a[i] - 1);       else         r[i] = query(n) - query(2 * a[i] - n - 1);       add(a[i], a[i]);     }     long long f = 0;     for (long long i = 1; i <= n; i++)       if (l[i] % (2 * a[i]) && r[i] % (2 * a[i])) {         printf( YES n );         f = 1;         break;       }     if (!f) printf( NO n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     vector<pair<int, int> > v_p;     int x1, y1, x2, y2;     cin >> x1 >> y1 >> x2 >> y2;     if (x2 < x1) swap(x1, x2);     if (y2 < y1) swap(y1, y2);     for (int i = y1; i <= y2; i++) {       v_p.push_back(make_pair(x1, i));       v_p.push_back(make_pair(x2, i));     }     for (int i = x1 + 1; i < x2; i++) {       v_p.push_back(make_pair(i, y1));       v_p.push_back(make_pair(i, y2));     }     int n, x, y, r;     cin >> n;     vector<tuple<int, int, int> > v;     for (int i = 0; i < n; i++) {       cin >> x >> y >> r;       v.push_back(make_tuple(x, y, r));     }     int cnt = 0;     for (int i = 0; i < v_p.size(); i++) {       bool flag = 1;       for (int j = 0; j < n; j++) {         int x2 = get<0>(v[j]);         int y2 = get<1>(v[j]);         int r = get<2>(v[j]);         if (r * r >= ((v_p[i].first - x2) * (v_p[i].first - x2)) +                          ((v_p[i].second - y2) * (v_p[i].second - y2))) {           flag = 0;           break;         }       }       if (flag) cnt++;     }     cout << cnt;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   int main() {     int n;     cin >> n;     while (n--) {       string s;       cin >> s;       int szs = s.size();       bool z = 0, e = 0;       int sum = 0;       for (int i = 0; i < szs; i++) {         sum += s[i] -  0 ;         e |= (!((s[i] -  0 ) & 1) && ((s[i] -  0 ) || z));         z |= (s[i] ==  0 );       }       if (sum == 0 || (z && e && !(sum % 3)))         cout <<  red n ;       else         cout <<  cyan n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 1;   namespace fastinput {   inline int readChar();   template <class T = int>   inline T readInt();   template <class T>   inline void writeInt(T x, char end = 0);   inline void writeChar(int x);   inline void writeWord(const char *s);   static const int buf_size = 16384;   inline int getChar() {     static char buf[buf_size];     static int len = 0, pos = 0;     if (pos == len) pos = 0, len = fread(buf, 1, buf_size, stdin);     if (pos == len) return -1;     return buf[pos++];   }   inline int readChar() {     int c = getChar();     while (c <= 32) c = getChar();     return c;   }   template <class T>   inline T readInt() {     int s = 1, c = readChar();     T x = 0;     if (c ==  - ) s = -1, c = getChar();     while ( 0  <= c && c <=  9 ) x = x * 10 + c -  0 , c = getChar();     return s == 1 ? x : -x;   }   static int write_pos = 0;   static char write_buf[buf_size];   inline void writeChar(char x) {     if (write_pos == buf_size)       fwrite(write_buf, 1, buf_size, stdout), write_pos = 0;     write_buf[write_pos++] = x;   }   template <class T>   inline void writeInt(T x, char end) {     if (x < 0) writeChar( - ), x = -x;     char s[24];     int n = 0;     while (x || !n) s[n++] =  0  + x % 10, x /= 10;     while (n--) writeChar(s[n]);     if (end) writeChar(end);   }   inline void writeWord(const char *s) {     while (*s) writeChar(*s++);   }   struct Flusher {     ~Flusher() {       if (write_pos) fwrite(write_buf, 1, write_pos, stdout), write_pos = 0;     }   } flusher;   }  // namespace fastinput   using namespace fastinput;   const string arr[6] = { S ,  M ,  L ,  XL ,  XXL ,  XXXL };   int decode(string s) {     for (int i = 0; i < 6; ++i)       if (s == arr[i]) return i;   }   int cnt[6];   int answer[N];   pair<int, int> want[N];   int give[N];   map<pair<int, int>, vector<int> > whowant;   void NO() {     puts( NO );     exit(0);   }   int main() {     ::ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     for (int i = 0; i < 6; ++i) cin >> cnt[i];     int n;     cin >> n;     for (int i = 0; i < n; ++i) {       string t;       cin >> t;       size_t x = t.find( , );       if (x != std::string::npos) {         want[i].first = decode(t.substr(0, x));         want[i].second = decode(t.substr(x + 1));       } else         want[i].first = decode(t), want[i].second = -1;       whowant[want[i]].push_back(i);     }     for (int i = 0; i < 6; ++i) {       vector<int> tmp = whowant[{i, -1}];       while (cnt[i] > 0 && tmp.size() > 0) {         give[tmp.back()] = i;         tmp.pop_back();         --cnt[i];       }       if (tmp.size() > 0) NO();       tmp = whowant[{i - 1, i}];       while (cnt[i] > 0 && tmp.size() > 0) {         give[tmp.back()] = i;         tmp.pop_back();         --cnt[i];       }       if (tmp.size() > 0) NO();       tmp = whowant[{i, i + 1}];       while (cnt[i] > 0 && tmp.size() > 0) {         give[tmp.back()] = i;         tmp.pop_back();         --cnt[i];       }       whowant[{i, i + 1}] = tmp;     }     cout <<  YES n ;     for (int i = 0; i < n; ++i) cout << arr[give[i]] <<   n ;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   using namespace std;   long long S[500005];   void add(int first, int a) {     for (int i = first; i < 500005; i += i & -i) {       S[i] += a;     }   }   long long query(int first) {     long long res = 0;     for (int i = first; i > 0; i -= i & -i) {       res += S[i];     }     return res;   }   struct node {     node *l, *r;     int a, b;     long long Min;     long long tag;     node(int _a, int _b) : l(NULL), r(NULL) {       a = _a;       b = _b;       Min = 1e18;       tag = 0;     }   } * root;   void build(node *n) {     if (n->a == n->b) return;     int mid = (n->a + n->b) / 2;     n->l = new node(n->a, mid);     n->r = new node(mid + 1, n->b);     build(n->l);     build(n->r);   }   long long Min(node *n) { return n->Min + n->tag; }   void pull(node *n) { n->Min = min(Min(n->l), Min(n->r)); }   void push(node *n) {     n->l->tag += n->tag;     n->r->tag += n->tag;     n->tag = 0;   }   void Set(node *n, int first, long long k) {     if (n->a == n->b) {       n->Min = k;       n->tag = 0;       return;     }     push(n);     int mid = (n->a + n->b) / 2;     if (first <= mid)       Set(n->l, first, k);     else       Set(n->r, first, k);     pull(n);   }   void add(node *n, int l, int r, int k) {     if (n->a >= l && n->b <= r) {       n->tag += k;       return;     }     if (n->b < l || n->a > r) return;     push(n);     add(n->l, l, r, k);     add(n->r, l, r, k);     pull(n);   }   int loc[500005];   map<int, vector<int> > qu;   int dfs(node *n) {     if (Min(n) >= 0) {       return 0;     }     if (n->a == n->b) return 1;     push(n);     int ret = dfs(n->l) + dfs(n->r);     pull(n);     return ret;   }   int main() {     int q;     scanf( %d , &q);     vector<pair<char, int> > v;     v.push_back(make_pair(( + ), (0)));     vector<pair<int, int> > num;     num.push_back(make_pair((0), (0)));     for (int i = 1; i <= q; i++) {       char c;       int first;       scanf(  %c %d , &c, &first);       v.push_back(make_pair((c), (first)));       if (c ==  + ) num.push_back(make_pair((first), (i)));     }     sort(num.begin(), num.end());     for (int i = 1; i < num.size(); i++) {       loc[num[i].second] = i;       qu[num[i].first].push_back(i);     }     for (auto &it : qu) {       reverse(it.second.begin(), it.second.end());     }     root = new node(1, num.size() - 1);     int R = num.size() - 1;     build(root);     int sum = 0;     for (int i = 1; i <= q; i++) {       char c;       c = v[i].first;       if (c ==  + ) {         sum++;         int first;         first = v[i].second;         int Index = loc[i];         long long val = query(Index - 1) * 2 - first;         add(root, Index + 1, R, first * 2);         Set(root, Index, val);         add(Index, first);       } else {         sum--;         int first;         first = v[i].second;         int Index = qu[first].back();         qu[first].pop_back();         add(root, Index + 1, R, -first * 2);         Set(root, Index, 1e18);         add(Index, -first);       }       printf( %d n , sum - dfs(root));     }   }


#include <bits/stdc++.h>   using namespace std;   struct Node {     int r, idx;   } p, q, t;   struct Fin {     int x, y, z;     Fin(){};     Fin(int _x, int _y, int _z) { x = _x, y = _y, z = _z; }   };   bool operator<(Node a, Node b) { return a.r < b.r; }   priority_queue<Node> que;   vector<Fin> vec;   vector<Node> tmp;   int main() {     int n, mini = 110;     scanf( %d , &n);     for (int i = 1; i <= n; i++)       scanf( %d , &p.r), p.idx = i, que.push(p), mini = min(mini, p.r);     while (1) {       tmp.clear();       tmp.push_back(que.top());       que.pop();       while (!que.empty()) {         if (tmp[0].r == que.top().r)           tmp.push_back(que.top()), que.pop();         else           break;       }       if (que.empty()) {         mini = tmp[0].r;         break;       }       if (tmp.size() == 1) tmp.push_back(que.top()), que.pop();       for (int i = 0; i < tmp.size(); i++) tmp[i].r = max(0, tmp[i].r - 1);       if (tmp.size() & 1) {         for (int i = 0; i < tmp.size() - 3; i += 2)           vec.push_back(Fin(tmp[i].idx, tmp[i + 1].idx, 0)), que.push(tmp[i]),               que.push(tmp[i + 1]);         vec.push_back(Fin(tmp[tmp.size() - 3].idx, tmp[tmp.size() - 2].idx,                           tmp[tmp.size() - 1].idx));         que.push(tmp[tmp.size() - 3]), que.push(tmp[tmp.size() - 2]),             que.push(tmp[tmp.size() - 1]);       } else         for (int i = 0; i < tmp.size(); i += 2)           vec.push_back(Fin(tmp[i].idx, tmp[i + 1].idx, 0)), que.push(tmp[i]),               que.push(tmp[i + 1]);     }     printf( %d n%d n , mini, vec.size());     for (int i = 0; i < vec.size(); i++) {       for (int j = 1; j <= n; j++) {         if (j == vec[i].x || j == vec[i].y || j == vec[i].z)           printf( 1 );         else           printf( 0 );       }       printf(  n );     }   }


#include <bits/stdc++.h>   using namespace std;   int ok[1 << 20];   int F[1 << 9][1 << 9];   int d[1 << 9];   int bfs(int n) {     d[0] = 0;     for (int i = 1; i <= n; ++i) d[i] = -1;     queue<int> Q;     Q.push(0);     while (!Q.empty() && d[n] == -1) {       int node = Q.front();       Q.pop();       for (int i = 0; i <= n; ++i)         if (d[i] == -1 && F[node][i]) Q.push(i), d[i] = node;     }     if (d[n] == -1) return 0;     int flow = 1e9;     for (int vertex = n; vertex; vertex = d[vertex])       flow = min(flow, F[d[vertex]][vertex]);     for (int vertex = n; vertex; vertex = d[vertex])       F[d[vertex]][vertex] -= flow, F[vertex][d[vertex]] += flow;     return flow;   }   vector<int> order;   int mark[1 << 9];   void dfs(int node, int n, int how) {     mark[node] = 1;     order.push_back(node);     for (int i = 1; i <= n; ++i)       if (!mark[i] && (F[node][i] == how && F[i][node] != how))         dfs(i, n, 1 - how);   }   int Val[1 << 9];   int main(void) {     int n;     for (int i = 2; i <= 1e6; ++i) ok[i] = 1;     for (int i = 2; i <= 1e3; ++i)       if (ok[i])         for (int j = i * i; j <= 1e6; j += i) ok[j] = 0;     cin >> n;     vector<int> a, b, pa, pb;     for (int i = 1; i <= n; ++i) {       int val;       cin >> val;       Val[i] = val;       if (val & 1)         a.push_back(val), pa.push_back(i);       else         b.push_back(val), pb.push_back(i);     }     if (a.size() != b.size()) return puts( Impossible ) * 0;     int sz = a.size();     for (int i = 1; i <= sz; ++i) F[0][i] = 2;     for (int i = 1; i <= sz; ++i) F[i + sz][sz + sz + 1] = 2;     for (int i = 0; i < sz; ++i)       for (int j = 0; j < sz; ++j)         if (ok[a[i] + b[j]]) F[i + 1][j + 1 + sz] = 1;     int flow = 0;     int cnt = 0;     while ((cnt = bfs(sz + sz + 1)) != 0) flow += cnt;     if (flow != sz + sz) return puts( Impossible ) * 0;     vector<vector<int> > cycles;     for (int i = 1; i <= sz + sz; ++i)       if (!mark[i]) {         order.clear();         dfs(i, sz + sz, 0);         for (auto &it : order)           if (it <= sz)             it = pa[it - 1];           else             it = pb[it - sz - 1];         cycles.push_back(order);       }     cout << (cycles.size()) <<   n ;     for (auto cycle : cycles) {       cout << cycle.size() <<    ;       for (auto it : cycle) cout << it <<    ;       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     int pearls = 0, links = 0;     cin >> s;     for (int i = 0; i < s.size(); i++) {       if (s[i] ==  - )         links++;       else         pearls++;     }     if (pearls == 0)       cout <<  yes  << endl;     else if (links % pearls == 0)       cout <<  yes  << endl;     else       cout <<  no  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using namespace std;   int n, m, q;   int a[210000];   int nxt[210000][20];   int loc[210000];   int p[210000];   int rp[210000];   int ans[210000];   pair<pair<int, int>, int> queries[210000];   int main() {     scanf( %d %d %d , &n, &m, &q);     for (int i = 0; i < n; i++) {       scanf( %d , &p[i]);       p[i]--;       rp[p[i]] = i;     }     for (int i = 0; i < m; i++) {       scanf( %d , &a[i]);       a[i]--;       a[i] = rp[a[i]];     }     for (int i = 0; i < q; i++) {       int l, r;       scanf( %d %d , &l, &r);       r--;       l--;       queries[i] = {{r, l}, i};     }     memset(loc, -1, sizeof(loc));     for (int i = 0; i < m; i++) {       int prev = (a[i] + n - 1) % n;       nxt[i][0] = loc[prev];       loc[a[i]] = i;     }     for (int lvl = 1; lvl < 20; lvl++) {       for (int i = 0; i < m; i++) {         if (nxt[i][lvl - 1] == -1)           nxt[i][lvl] = -1;         else           nxt[i][lvl] = nxt[nxt[i][lvl - 1]][lvl - 1];       }     }     sort(queries, queries + q);     int cur_query = 0;     int best = -1;     for (int i = 0; i < m; i++) {       int cur = i;       for (int lvl = 0; lvl < 20; lvl++)         if ((1 << lvl) & (n - 1)) cur = nxt[cur][lvl];       best = max(best, cur);       for (; cur_query < q && queries[cur_query].first.first == i; cur_query++) {         ans[queries[cur_query].second] =             (best >= queries[cur_query].first.second);       }     }     for (int i = 0; i < q; i++) {       printf( %d , ans[i]);     }   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   struct Matrix {     long long a, b, c, d;     Matrix(long long _a = 0, long long _b = 0, long long _c = 0,            long long _d = 0) {       a = _a;       b = _b;       c = _c;       d = _d;     }     void normalize(Matrix& mat) {       mat.a %= mod;       mat.b %= mod;       mat.c %= mod;       mat.d %= mod;     }     const Matrix operator+(const Matrix& mat) {       Matrix tmp(this->a + mat.a, this->b + mat.b, this->c + mat.c,                  this->d + mat.d);       normalize(tmp);       return tmp;     }     const Matrix operator*(const Matrix& mat) {       Matrix tmp(           this->a * mat.a + this->b * mat.c, this->a * mat.b + this->b * mat.d,           this->c * mat.a + this->d * mat.c, this->c * mat.b + this->d * mat.d);       normalize(tmp);       return tmp;     }     bool operator==(const Matrix& mat) const {       if (this->a == mat.a && this->b == mat.b && this->c == mat.c &&           this->d == mat.d)         return true;       return false;     }     bool operator!=(const Matrix& mat) const { return !(*this == mat); }     void pprint() {       return;       cerr <<  ---------------------------  << endl;       cerr << this->a <<   |   << this->b << endl;       cerr << this->c <<   |   << this->d << endl;       cerr <<  ---------------------------  << endl;     }   };   class SegmentTree {    private:     vector<Matrix> A, st, lazy;     int n;     Matrix lazyId;     int left(int p) { return p << 1; }     int right(int p) { return (p << 1) + 1; }     void build(int p, int l, int r) {       if (r - l == 1) {         st[p] = A[l];         return;       }       int mid = (l + r) / 2;       build(left(p), l, mid);       build(right(p), mid, r);       st[p] = st[left(p)] + st[right(p)];     }     void apply(int p, int l, int r) {       st[p] = lazy[p] * st[p];       if (r - l > 1) {         lazy[left(p)] = lazy[p] * lazy[left(p)];         lazy[right(p)] = lazy[p] * lazy[right(p)];       }       lazy[p] = lazyId;     }     void lazyUpdate(int p, int l, int r, int i, int j, Matrix& val) {       if (lazy[p] != lazyId) apply(p, l, r);       if (j <= l || r <= i) return;       if (i <= l && r <= j) {         lazy[p] = lazy[p] * val;         apply(p, l, r);         return;       }       int mid = (l + r) / 2;       lazyUpdate(left(p), l, mid, i, j, val);       lazyUpdate(right(p), mid, r, i, j, val);       st[p] = st[left(p)] + st[right(p)];     }     Matrix query(int p, int l, int r, int i, int j) {       if (j <= l || r <= i) return Matrix();       if (lazy[p] != lazyId) apply(p, l, r);       if (i <= l && r <= j) return st[p];       int mid = (l + r) / 2;       Matrix uno = query(left(p), l, mid, i, j);       Matrix dos = query(right(p), mid, r, i, j);       return uno + dos;     }       public:     SegmentTree(vector<Matrix> v) {       A = v;       n = v.size();       st.assign(4 * n, Matrix());       lazyId = Matrix(1, 0, 0, 1);       lazy.assign(4 * n, lazyId);       build(1, 0, n);     }     void update(int i, int j, Matrix& val) { lazyUpdate(1, 0, n, i, j, val); }     Matrix query(int i, int j) { return query(1, 0, n, i, j); }   };   Matrix pot(Matrix b, int k) {     if (k == 0) return Matrix(1, 0, 0, 1);     if (k % 2 == 0) {       Matrix tmp = pot(b, k / 2);       return tmp * tmp;     } else {       return b * pot(b, k - 1);     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     ;     int n, m;     cin >> n >> m;     Matrix base = Matrix(1, 1, 1, 0);     vector<Matrix> vec;     for (int i = 0; i < n; i++) {       int a;       cin >> a;       Matrix tmp = pot(base, a);       vec.push_back(tmp);       ;       ;       tmp.pprint();     }     SegmentTree st(vec);     for (int i = 0; i < m; i++) {       int t;       cin >> t;       if (t == 1) {         int l, r, x;         cin >> l >> r >> x;         l--;         r--;         Matrix tmp = pot(base, x);         ;         ;         tmp.pprint();         st.update(l, r + 1, tmp);       } else {         int l, r;         cin >> l >> r;         l--;         r--;         Matrix tmp = st.query(l, r + 1);         tmp.pprint();         long long res = tmp.c % mod;         cout << res << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 10, p = 1e9 + 7;   map<int, int> mp;   char s[N];   inline void A(int &x, int y) { x = (x + y >= p ? x + y - p : x + y); }   inline void Append(int w) {     int v1 = 0, v2 = 0;     map<int, int>::iterator it;     for (it = mp.begin(); it != mp.end() && it->first <= w; ++it) {       A(v1, it->second);       v2 = (v2 + 1ll * it->second * (w - it->first + 1)) % p;     }     mp.erase(mp.begin(), it);     A(mp[w + 1], v1);     mp[0] = v2;   }   int main() {     scanf( %s , s + 1);     int ln = 1, rn = strlen(s + 1);     int time_l = 1, time_r = 1;     while (s[ln] ==  0 ) ++time_l, ++ln;     if (ln > rn) {       printf( %d n , rn);       return 0;     }     while (s[rn] ==  0 ) ++time_r, --rn;     mp[0] = 1;     while (ln != rn) {       ++ln;       int w = 0;       while (s[ln] ==  0 ) ++ln, ++w;       Append(w);     }     int ans = 0;     for (auto x : mp) A(ans, x.second);     printf( %lld n , 1ll * ans * time_l % p * time_r % p);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> odd, even;   int main() {     int cnt1 = 0, cnt2 = 0, tem = -1;     int n, k, p, x;     scanf( %d%d%d , &n, &k, &p);     for (int i = 0; i < n; i++) {       scanf( %d , &x);       if (x % 2 == 0) {         cnt2++;         even.push_back(x);       } else {         if (cnt1 >= k - p) {           if (tem == -1)             tem = x;           else {             even.push_back(tem);             even.push_back(x);             cnt2++;             tem = -1;           }         } else {           cnt1++;           odd.push_back(x);         }       }     }     if (cnt1 < k - p || cnt2 < p || tem != -1)       printf( NO n );     else {       printf( YES n );       if (p == 0) {         for (int i = 0; i < k - p - 1; i++) printf( %d %d n , 1, odd[i]);         printf( %d , n - (k - p - 1));         for (int i = 0; i < even.size(); i++) printf(  %d , even[i]);         printf(  %d n , odd[k - p - 1]);         return 0;       }       for (int i = 0; i < k - p; i++) printf( %d %d n , 1, odd[i]);       int tem2 = 0, cur = 0;       while (tem2 < p - 1) {         if (even[cur] % 2 == 0) {           printf( %d %d n , 1, even[cur]);           cur++;         } else {           printf( %d %d %d n , 2, even[cur], even[cur + 1]);           cur++;           cur++;         }         tem2++;       }       if (even.size() > cur) printf( %d , even.size() - cur);       for (int i = cur; i < even.size(); i++) printf(  %d , even[i]);     }     return 0;   }


#include<iostream>   #include<stdio.h>   using namespace std;    int main()   {long int max,x,y,t;   cin>>t;       while(t--)   {   cin>>x>>y;       if(x==y)       {cout<<2*x<<endl;       continue;                                }       max=x;              if(x<y)       {           max=y;       }       cout<<2*max-1<<endl;          }       return 0;      }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 10;   int n;   int L;   int R;   struct data {     int u;     int f;     int dis;     int dep;   };   queue<data> q1, q2;   struct ed {     int v;     int val;     int siz;     int ori;     friend bool operator<(ed a, ed b) { return a.siz < b.siz; }   };   vector<ed> v[N];   int ng[N];   int tim;   int nsiz[N];   int w[N];   int nu[N];   int siz[N];   bool cut[N];   int ans1;   int ans2;   struct dq {     int q[3 * N];     int hd;     int tl;     inline void clr() {       hd = 1;       tl = 0;     }     inline bool emp() { return hd <= tl; }     inline void ins(int j) {       while (hd <= tl && w[j] >= w[q[tl]]) tl--;       q[++tl] = j;     }     inline void del(int k) {       while (hd <= tl && q[hd] > k) hd++;     }     inline int qmx() { return q[hd]; }   } q;   inline void clear(queue<data>& q) {     queue<data> emp;     swap(q, emp);   }   inline int dfs1(int u, int f) {     siz[u] = 1;     for (vector<ed>::iterator it = v[u].begin(); it != v[u].end(); ++it)       if (it->v != f && !cut[it->v]) siz[u] += dfs1(it->v, u);     return siz[u];   }   inline int find(int u, int f, const int& tot) {     for (vector<ed>::iterator it = v[u].begin(); it != v[u].end(); ++it)       if (it->v != f && !cut[it->v] && 2 * siz[it->v] >= tot)         return find(it->v, u, tot);     return u;   }   inline int dfs3(int u, int f) {     int mx = 0;     for (vector<ed>::iterator it = v[u].begin(); it != v[u].end(); ++it)       if (it->v != f && !cut[it->v]) mx = max(mx, dfs3(it->v, u));     return mx + 1;   }   inline bool bfs(data st, int mxsiz) {     q.clr();     clear(q1);     clear(q2);     int j = min(R, mxsiz);     for (; j >= L; j--) q.ins(j);     for (q1.push(st); !q1.empty();) {       data nw = q1.front();       q2.push(nw);       q1.pop();       if (nw.dep > R) continue;       int dl = max(L - nw.dep, 0);       int dr = min(R - nw.dep, mxsiz);       for (; j >= dl; j--) q.ins(j);       q.del(dr);       if (q.emp()) {         int p = q.qmx();         if (nw.dis + w[p] >= 0) {           ans1 = nu[p];           ans2 = nw.u;           return true;         }       }       for (vector<ed>::iterator it = v[nw.u].begin(); it != v[nw.u].end(); ++it)         if (it->v != nw.f && !cut[it->v])           q1.push((data){it->v, nw.u, nw.dis + it->val, nw.dep + 1});     }     for (; !q2.empty(); q2.pop()) {       data a = q2.front();       if (w[a.dep] < a.dis) w[a.dep] = a.dis, nu[a.dep] = a.u;     }     return false;   }   inline bool solve(int u) {     ++tim;     int g;     if (ng[tim] == -1) {       dfs1(u, 0);       g = find(u, 0, siz[u]);       cut[g] = true;       ng[tim] = g;       nsiz[tim] = siz[u];       if (siz[u] == 1) return false;       for (int i = 1; i <= siz[u]; i++) w[i] = -0x3f3f3f3f, nu[i] = 0;       for (vector<ed>::iterator it = v[g].begin(); it != v[g].end(); ++it)         if (!cut[it->v]) it->siz = dfs3(it->v, g);       sort(v[g].begin(), v[g].end());       w[0] = 0;       nu[0] = g;     } else {       g = ng[tim];       cut[g] = true;       if (nsiz[tim] == 1) return false;       for (int i = 1; i <= nsiz[tim]; i++) w[i] = -0x3f3f3f3f, nu[i] = 0;       w[0] = 0;       nu[0] = g;     }     for (vector<ed>::iterator it = v[g].begin(); it != v[g].end(); ++it)       if (!cut[it->v])         if (bfs((data){it->v, g, it->val, 1}, it->siz)) return true;     for (vector<ed>::iterator it = v[g].begin(); it != v[g].end(); ++it)       if (!cut[it->v])         if (solve(it->v)) return true;     return false;   }   inline bool jud(int mid) {     tim = 0;     for (int i = 1; i <= n; i++)       for (vector<ed>::iterator it = v[i].begin(); it != v[i].end(); ++it)         it->val = (it->ori >= mid) ? 1 : -1;     for (int i = 1; i <= n; i++) cut[i] = false;     return solve(1);   }   int main() {     scanf( %d%d%d , &n, &L, &R);     int l = 0;     int r = 0;     for (int i = 1; i <= n; i++) ng[i] = -1;     for (int i = 1, u, V, va; i < n; i++) {       scanf( %d%d%d , &u, &V, &va);       r = max(r, va);       v[u].push_back((ed){V, 0, 0, va});       v[V].push_back((ed){u, 0, 0, va});     }     while (l != r) {       int mid = (l + r + 1) / 2;       if (jud(mid))         l = mid;       else         r = mid - 1;     }     jud(l);     printf( %d %d , ans1, ans2);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1000000007;   long long fact[200001], invfact[200001];   int n50 = 0, n100 = 0, k = 0;   struct node {     int l[2], r[2], b;   };   long long nways[51][51][51][51][2], shortest[51][51][51][51][2];   queue<node> q;   long long pmod(long long base, long long p) {     if (p == 0) return 1LL;     long long ret = pmod(base, p / 2);     ret = (ret * ret) % MOD;     if (p % 2 == 1) ret = (ret * base) % MOD;     return ret;   }   long long invEuler(long long x) { return pmod(x, MOD - 2); }   long long nCr(long long n, long long r) {     long long ret = 1;     ret *= fact[n];     ret = (ret * invfact[r]) % MOD;     ret = (ret * invfact[n - r]) % MOD;     return ret;   }   void bfs() {     memset(nways, 0, sizeof(nways));     memset(shortest, -1, sizeof(shortest));     nways[n50][n100][0][0][0] = 1;     shortest[n50][n100][0][0][0] = 0;     node temp;     temp.l[0] = n50;     temp.l[1] = n100;     temp.r[0] = 0;     temp.r[1] = 0;     temp.b = 0;     q.push(temp);     while (!q.empty()) {       temp = q.front();       q.pop();       int l0, l1, r0, r1, b;       l0 = temp.l[0];       l1 = temp.l[1];       r0 = temp.r[0];       r1 = temp.r[1];       b = temp.b;       if (b == 0) {         for (int i = 0; i <= l0; ++i) {           for (int j = 0; j <= l1; ++j) {             if (50 * i + 100 * j > k || (!i && !j)) continue;             int _l0 = l0 - i, _l1 = l1 - j, _r0 = r0 + i, _r1 = r1 + j, _b = !b;             if (shortest[_l0][_l1][_r0][_r1][_b] == -1 ||                 shortest[_l0][_l1][_r0][_r1][_b] >                     shortest[l0][l1][r0][r1][b] + 1) {               shortest[_l0][_l1][_r0][_r1][_b] = 1 + shortest[l0][l1][r0][r1][b];               nways[_l0][_l1][_r0][_r1][_b] =                   (((nCr(l0, i) * nCr(l1, j)) % MOD) * nways[l0][l1][r0][r1][b]) %                   MOD;               temp.l[0] = _l0;               temp.l[1] = _l1;               temp.r[0] = _r0;               temp.r[1] = _r1;               temp.b = _b;               q.push(temp);             } else if (shortest[_l0][_l1][_r0][_r1][_b] ==                        shortest[l0][l1][r0][r1][b] + 1)               nways[_l0][_l1][_r0][_r1][_b] =                   (nways[_l0][_l1][_r0][_r1][_b] +                    (((nCr(l0, i) * nCr(l1, j)) % MOD) *                     nways[l0][l1][r0][r1][b]) %                        MOD) %                   MOD;           }         }       } else {         for (int i = 0; i <= r0; ++i) {           for (int j = 0; j <= r1; ++j) {             if (50 * i + 100 * j > k || (!i && !j)) continue;             int _l0 = l0 + i, _l1 = l1 + j, _r0 = r0 - i, _r1 = r1 - j, _b = !b;             if (shortest[_l0][_l1][_r0][_r1][_b] == -1 ||                 shortest[_l0][_l1][_r0][_r1][_b] >                     shortest[l0][l1][r0][r1][b] + 1) {               shortest[_l0][_l1][_r0][_r1][_b] = 1 + shortest[l0][l1][r0][r1][b];               nways[_l0][_l1][_r0][_r1][_b] =                   (((nCr(r0, i) * nCr(r1, j)) % MOD) * nways[l0][l1][r0][r1][b]) %                   MOD;               temp.l[0] = _l0;               temp.l[1] = _l1;               temp.r[0] = _r0;               temp.r[1] = _r1;               temp.b = _b;               q.push(temp);             } else if (shortest[_l0][_l1][_r0][_r1][_b] ==                        shortest[l0][l1][r0][r1][b] + 1)               nways[_l0][_l1][_r0][_r1][_b] =                   (nways[_l0][_l1][_r0][_r1][_b] +                    (((nCr(r0, i) * nCr(r1, j)) % MOD) *                     nways[l0][l1][r0][r1][b]) %                        MOD) %                   MOD;           }         }       }     }   }   int main() {     int n, in;     fact[0] = 1;     fact[1] = 1;     invfact[0] = invEuler(1);     invfact[1] = invfact[0];     for (int i = 2; i < 200001; ++i) {       fact[i] = (fact[i - 1] * i) % MOD;       invfact[i] = invEuler(fact[i]);     }     scanf( %d %d , &n, &k);     for (int i = 0; i < n; ++i) {       scanf( %d , &in);       if (in == 50)         n50++;       else         n100++;     }     bfs();     cout << shortest[0][0][n50][n100][1] << endl << nways[0][0][n50][n100][1];   }


#include <bits/stdc++.h>   using namespace std;   unsigned long xor128() {     static unsigned long x = time(NULL), y = 362436069, z = 521288629,                          w = 88675123;     unsigned long t = (x ^ (x << 11));     x = y;     y = z;     z = w;     return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));   }   double dot(complex<double> a, complex<double> b) {     return a.real() * b.real() + a.imag() * b.imag();   }   double gyaku_dot(complex<double> a, complex<double> b) {     return a.real() * b.imag() - a.imag() * b.real();   }   double leng(complex<double> a) {     return sqrt(a.real() * a.real() + a.imag() * a.imag());   }   double angles(complex<double> a, complex<double> b) {     double cosine = dot(a, b) / (leng(a) * leng(b));     double sine = gyaku_dot(a, b) / (leng(a) * leng(b));     double kaku = acos(min((double)1.0, max((double)-1.0, cosine)));     if (sine <= 0) {       kaku = 2 * 3.141592653589793 - kaku;     }     return kaku;   }   vector<int> convex_hull(vector<complex<double>> a) {     vector<int> ans;     double now_minnest = a[0].real();     int now_itr = 0;     for (long long i = 0; i < a.size(); ++i) {       if (now_minnest > a[i].real()) {         now_minnest = a[i].real();         now_itr = i;       }     }     ans.push_back(now_itr);     complex<double> ba(0, 1);     while (true) {       int now_go = 0;       double now_min = 0;       double now_length = 0;       int starter = ans[ans.size() - 1];       for (int i = 0; i < a.size(); ++i) {         if (i != starter) {           double goa = angles(ba, a[i] - a[starter]);           if (goa - now_min >= 1e-5 ||               (abs(goa - now_min) <= 1e-5 &&                (abs(a[i] - a[starter]) - now_length) >= 1e-5)) {             now_min = goa;             now_go = i;             now_length = abs(a[i] - a[starter]);           }         }       }       if (now_go == ans[0]) break;       ans.push_back(now_go);       ba = complex<double>(a[now_go] - a[starter]);     }     return ans;   }   int ruiseki[1000000];   int main() {     int test_case;     cin >> test_case;     for (long long i = 0; i < test_case; ++i) {       string s;       cin >> s;       int ans = 0;       ruiseki[0] = 0;       for (int i = 0; i < s.length(); ++i) {         if (i != 0) ruiseki[i] = ruiseki[i - 1];         if (s[i] ==  1 ) {           ruiseki[i]++;         }       }       for (int i = 0; i < s.length(); ++i) {         int now = 0;         for (int q = i; q >= 0; --q) {           if (i - q > 25) {             int now_back = i - now + 1;             int now_front = q;             if (now_back > now_front) break;             if (now_back < 0) break;             int hoge = ruiseki[now_front];             if (now_back != 0) {               hoge -= ruiseki[now_back - 1];             }             if (hoge == 0) ans++;             break;           }           if (s[q] ==  1 ) {             now += (1 << (i - q));           }           if (now == i - q + 1) ans++;         }       }       cout << ans << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int a[212345];   int cnts[212345];   int lft[212345];   int rght[212345];   int cumsum[212345];   int get_right_ans(int i) { return cumsum[rght[i]] - cumsum[i]; }   int get_left_ans(int i) {     if (lft[i]) return cumsum[i - 1] - cumsum[lft[i] - 1];     return cumsum[i - 1];   }   void print_ans(int fin_ans, int slope) {     if (cnts[fin_ans] < 1) {       return;     }     if (cnts[fin_ans] < 2) {       cnts[fin_ans] -= 1;       printf( %d  , fin_ans);       return;     }     printf( %d  , fin_ans);     cnts[fin_ans] -= 1;     print_ans(fin_ans + slope, slope);     while (cnts[fin_ans]) {       printf( %d  , fin_ans);       cnts[fin_ans]--;     }   }   int main() {     int n, tmp, fnd;     scanf( %d , &n);     ;     for (int i = 0; i < n; i++) {       scanf( %d , &a[i]);       ;       cnts[a[i]] += 1;     }     int lst_val = -1;     for (int i = 0; i < 212345; i++) {       lft[i] = lst_val;       if (cnts[i] < 2) lst_val = i;     }     lst_val = 212345;     for (int i = 212345 - 1; i >= 0; i--) {       rght[i] = lst_val;       if (cnts[i] < 2) lst_val = i;     }     for (int i = 1; i < 212345; i++) cumsum[i] = cumsum[i - 1] + cnts[i];     int maxi = 0;     int fin_ans = -1;     for (int i = 1; i < 212345; i++) {       if (cnts[i] == 1) {         if (1 + max(get_right_ans(i), get_left_ans(i)) > maxi) {           maxi = max(maxi, 1 + max(get_right_ans(i), get_left_ans(i)));           fin_ans = i;         }       } else if (cnts[i] > 1) {         if (cnts[i] + get_right_ans(i) + get_left_ans(i) > maxi) {           maxi = max(maxi, cnts[i] + get_right_ans(i) + get_left_ans(i));           fin_ans = i;         }       }     }     printf( %d n , maxi);     if (cnts[fin_ans] == 1) {       printf( %d  , fin_ans);       if (get_left_ans(fin_ans) > get_right_ans(fin_ans))         print_ans(fin_ans - 1, -1);       else         print_ans(fin_ans + 1, +1);     } else {       if (get_left_ans(fin_ans)) {         printf( %d  , fin_ans);         print_ans(fin_ans - 1, -1);         cnts[fin_ans] -= 1;       }       if (get_right_ans(fin_ans)) {         printf( %d  , fin_ans);         print_ans(fin_ans + 1, 1);         cnts[fin_ans] -= 1;       }       while (cnts[fin_ans]) {         printf( %d  , fin_ans);         cnts[fin_ans]--;       }     }   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   const long long INF = 1e10;   template <typename T>   void cmax(T &a, T b) {     a = max(a, b);   }   template <typename T>   void cmin(T &a, T b) {     a = min(a, b);   }   signed main() {     string s;     cin >> s;     long long a[5555] = {};     long long b[5555] = {};     for (long long i = 0; i < (s.size()); i++) {       a[i + 1] += a[i];       b[i + 1] += b[i];       if (s[i] ==  a )         a[i + 1]++;       else         b[i + 1]++;     }     long long ans = 0;     for (long long i = 0; i < (s.size() + 1); i++)       for (long long j = (i); j < (s.size() + 1); j++)         cmax(ans, a[s.size()] - a[j] + b[j] - b[i] + a[i]);     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int gcd(int a, int b) {     if (a == 0) return 0;     return gcd(b % a, a) + b / a;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     while (n--) {       int a, b;       cin >> a >> b;       cout << gcd(a, b) << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long p, ans, num;   int n;   string s[500000];   int main() {     cin >> n >> p;     p /= 2;     for (int i = 1; i <= n; ++i) {       cin >> s[i];     }     for (int i = n; i >= 1; --i) {       num *= 2;       if (s[i] ==  halfplus ) num++;       ans += num;     }     cout << ans * p << endl;   }


#include <bits/stdc++.h>   using namespace std;   template <typename G1, typename G2 = G1, typename G3 = G1>   struct triple {     G1 first;     G2 second;     G3 T;   };   const long double eps = 1e-12;   int sign(long double x) { return x < -eps ? -1 : x > eps; }   int dblcmp(long double x, long double y) { return sign(x - y); }   long double dot(complex<long double> a, complex<long double> b) {     return real(conj(a) * b);   }   long double cross(complex<long double> a, complex<long double> b) {     return imag(conj(a) * b);   }   struct Point {     complex<long double> p;     int id;     long double operator*(const Point o) const { return cross(this->p, o.p); }     Point operator-(const Point o) const { return {p - o.p}; }     bool operator<(const Point o) const {       if (dblcmp(p.real(), o.p.real()) == 0)         return dblcmp(p.imag(), o.p.imag()) < 0;       return dblcmp(p.real(), o.p.real()) < 0;     }   };   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     vector<vector<int>> mp1(n);     map<pair<long long, long long>, int> mp2;     vector<Point> v;     int c = 0;     for (int i = 0; i < n; i++) {       int x, y;       cin >> x >> y;       if (mp2.count({x, y}) == 0) {         v.push_back({{10000.0 / x, 10000.0 / y}, c});         mp2[{x, y}] = c++;       }       mp1[mp2[{x, y}]].push_back(i + 1);     }     sort(v.begin(), v.end());     vector<Point> hull;     for (int i = 0; i < c; i++) {       while (hull.size() > 1 &&              dblcmp((hull.end()[-1] - hull.end()[-2]) * (v[i] - hull.end()[-1]),                     0) < 0)         hull.pop_back();       hull.push_back(v[i]);     }     while (hull.size() > 1 &&            dblcmp(hull.end()[-2].p.imag(), hull.end()[-1].p.imag()) <= 0)       hull.pop_back();     vector<int> ans;     for (auto &i : hull)       for (auto j : mp1[i.id]) ans.push_back(j);     sort(ans.begin(), ans.end());     for (int i = 0; i < ans.size(); i++)       cout << ans[i] <<    n [i == ans.size() - 1];     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long M = 1e9 + 7;   long long powmodM(long long a, long long b, long long c = M) {     long long res = 1;     while (b) {       if (b & 1) res = (res * a) % M;       a = (a * a) % M;       b /= 2;     }     return res;   }   long long power(long long a, long long b) {     long long res = 1;     while (b) {       if (b & 1) res = (res * a);       a = (a * a);       b /= 2;     }     return res;   }   long long gcd(long long a, long long b) {     while (a && b) a > b ? a %= b : b %= a;     return a + b;   }   long long lcm(long long a, long long b) {     return (max(a, b) / gcd(a, b)) * min(a, b);   }   vector<long long int> sieve(long long int n) {     vector<long long int> ans, prime(2 * 1e6);     prime[0] = false;     prime[1] = false;     for (long long int p = 2; p * p <= n; p++)       if (prime[p])         for (long long int i = p * p; i <= n; i += p) prime[i] = 0;     for (long long p = (2); p <= (n); ++p)       if (prime[p]) ans.push_back(p);     return ans;   }   long long modInverse(long long n, long long p = M) {     return powmodM(n, p - 2, p);   }   long long nCrModP(long long n, long long r, long long p = M) {     if (r == 0) return 1;     long long fac[n + 1];     fac[0] = 1;     for (long long i = (1); i <= (n); ++i) fac[i] = fac[i - 1] * i % p;     return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) %            p;   }   double pie = 3.14159265358979323846264338;   const long long int INF = 0x3f3f3f3f;   class l {    public:     char data;     l *next;     l *prev;     l(char a) {       data = a;       prev = NULL;       next = NULL;     }   };   map<long long int, long long int> fre;   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int n, m;     cin >> n >> m;     vector<long long int> arr(n);     for (long long i = (0); i <= (n - 1); ++i) cin >> arr[i];     if (m == arr[0]) {       cout << -1;       return 0;     }     long long int ma = 0;     fre[arr[ma]] = 1;     bool ok = 1;     long long int uski = 0;     for (long long i = (1); i <= (n - 1); ++i) {       if (arr[i] == m) {         uski++;         vector<long long int> re;         for (auto u : fre) {           if (u.second < uski) re.push_back(u.first);         }         for (auto u : re) {           fre.erase(u);         }         if (!fre.size()) {           cout << -1;           return 0;         }       }       if (!uski)         fre[arr[i]]++;       else if (fre[arr[i]]) {         fre[arr[i]]++;       }     }     vector<long long int> re;     for (auto u : fre) {       if (u.second < uski) re.push_back(u.first);     }     for (auto u : re) {       fre.erase(u);     }     if (!fre.size()) {       cout << -1;       return 0;     }     if (fre.size()) {       cout << fre.begin()->first;     } else {       cout << -1;     }   }


#include <bits/stdc++.h>   using namespace std;   vector<int> temp(100005);   vector<int> v(100005);   int fn(int l, int h, int x) {     while (h - l > 1) {       int mid = (h + l) / 2;       if (temp[mid] >= x) {         h = mid;       } else {         l = mid;       }     }     if (temp[h] > x)       return h;     else       return l;   }   int main() {     ios_base::sync_with_stdio(false);     int n;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> v[i];     }     int len = 1;     temp[0] = v[0];     for (int i = 1; i < n; i++) {       if (temp[0] > v[i]) {         temp[0] = v[i];       } else if (v[i] > temp[len - 1]) {         temp[len] = v[i];         len++;       } else {         int index = fn(0, len - 1, v[i]);         temp[index] = v[i];       }     }     cout << len;   }


#include <bits/stdc++.h>   using namespace std;   const int M = 1e9 + 7;   long long fastpower(long long x, long long n, long long M) {     if (n == 0)       return 1;     else if (n % 2 == 0)       return fastpower((x * x) % M, n / 2, M);     else       return (x * fastpower((x * x) % M, (n - 1) / 2, M)) % M;   }   long long GCD(long long A, long long B) {     if (B == 0)       return A;     else       return GCD(B, A % B);   }   bool vowl(char c) {     return c ==  a  || c ==  e  || c ==  i  || c ==  o  || c ==  u ;   }   long long modInverse(long long A, long long M) {     return fastpower(A, M - 2, M);   }   void sieve(long long N) {     bool isPrime[N + 1];     for (long long i = 0; i <= N; ++i) {       isPrime[i] = true;     }     isPrime[0] = false;     isPrime[1] = false;     for (long long i = 2; i * i <= N; ++i) {       if (isPrime[i] == true) {         for (long long j = i * i; j <= N; j += i) isPrime[j] = false;       }     }   }   vector<long long> factorize(long long n) {     vector<long long> res;     for (long long i = 2; i * i <= n; ++i) {       while (n % i == 0) {         res.push_back(i);         n /= i;       }     }     if (n != 1) {       res.push_back(n);     }     return res;   }   long long dp[300000][20];   long long n, m, k;   long long arr[20];   long long cost[20][20];   long long cal(string s) {     reverse(s.begin(), s.end());     long long ans = 0;     for (long long i = 0; i < s.length(); i++) {       if (s[i] ==  1 ) ans += (1 << i);     }     return ans;   }   long long solve(string &s, int prev) {     int p = 0;     int a = 0;     for (int i = n - 1; i >= 0; i--) {       if (s[i] ==  1 ) {         a++;         p += (1 << (n - i - 1));       }     }     if (a == m) return 0;     if (dp[p][prev] != -1) return dp[p][prev];     long long ans = 0;     for (long long i = 0; i < n; i++) {       if (s[i] ==  0 ) {         s[i] =  1 ;         ans = max(ans, arr[i + 1] + cost[prev][i + 1] + solve(s, i + 1));         s[i] =  0 ;       }     }     return dp[p][prev] = ans;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> m >> k;     string s =   ;     for (long long i = 1; i <= n; i++) {       cin >> arr[i];       s +=  0 ;     }     for (long long i = 0; i < k; i++) {       long long x, y, c;       cin >> x >> y >> c;       cost[x][y] = c;     }     memset(dp, -1, sizeof(dp));     cout << solve(s, 0) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 5;   int main() {     int a, b, c, d;     scanf( %d%d%d%d , &a, &b, &c, &d);     if (a == 0 && b == 0 && c == 0 && d == 0) {       printf( 1 n );     } else if (a == 0 && d == 0 && c != 0) {       printf( 0 n );     } else if (a != d) {       printf( 0 n );     } else {       printf( 1 n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     cin.tie(0);     cin.sync_with_stdio(0);     long long n, a[5001], cnt = 1, maxn = 0;     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i];     sort(a, a + n);     for (int i = 0; i < n - 1; i++) {       if (a[i] == a[i + 1]) cnt++;       if (a[i] != a[i + 1]) cnt = 1;       maxn = max(maxn, cnt);     }     maxn = max(maxn, cnt);     cout << maxn;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s, ans, s1;     cin >> s;     s1 = s;     int l = s.length(), i;     int j = l - 1, flag = 0;     while (i < j) {       if (s[i] != s[j]) {         flag = 1;         break;       }       i++;       j--;     }     if (flag) {       reverse(s1.begin(), s1.end());       ans = s + s1;       cout << ans;     } else       cout << s;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     s[0] = toupper(s[0]);     cout << s << endl;     return 0;   }


#include <bits/stdc++.h>   const long long md = 1e9 + 7;   const int Inf = 1e9;   const long long Inf64 = 1e18;   const long long MaxN = 1e6 + 100;   const long double eps = 1e-15;   using namespace std;   long long Tree[4 * MaxN];   long long getSum(long long l, long long r, long long x, long long y,                    long long id) {     if (l == x && r == y) {       return Tree[id];     } else {       long long mid = (l + r) / 2;       if (mid >= y) {         return getSum(l, mid, x, y, 2 * id + 1);       } else if (mid + 1 <= x) {         return getSum(mid + 1, r, x, y, 2 * id + 2);       } else {         return getSum(l, mid, x, mid, 2 * id + 1) +                getSum(mid + 1, r, mid + 1, y, 2 * id + 2);       }     }   }   void edit(long long l, long long r, long long x, long long id) {     if (l == r) {       Tree[id]++;     } else {       long long mid = (l + r) / 2;       if (mid >= x) {         edit(l, mid, x, 2 * id + 1);         Tree[id] = Tree[2 * id + 1] + Tree[2 * id + 2];       } else {         edit(mid + 1, r, x, 2 * id + 2);         Tree[id] = Tree[2 * id + 1] + Tree[2 * id + 2];       }     }   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long N;     cin >> N;     vector<pair<long long, long long> > Zip(N);     for (int i = 0; i < N; i++) {       long long a;       cin >> a;       Zip[i] = {a, i};     }     sort(Zip.begin(), Zip.end());     vector<long long> Ans(N);     for (int i = 0; i < N; i++) {       long long t = getSum(0, N - 1, Zip[i].second, N - 1, 0);       Ans[Zip[i].second] = t;       edit(0, N - 1, Zip[i].second, 0);     }     fill(Tree, Tree + 4 * MaxN, 0);     reverse(Zip.begin(), Zip.end());     long long Res = 0;     for (int i = 0; i < N; i++) {       long long t = getSum(0, N - 1, 0, Zip[i].second, 0);       Res += Ans[Zip[i].second] * t;       edit(0, N - 1, Zip[i].second, 0);     }     cout << Res;     cerr <<   n           <<  Time execute:   << clock() / (double)CLOCKS_PER_SEC <<   sec           <<   n ;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   const long long MOD = 1e9 + 7;   long long a[200012];   long long in[200021], out[200012];   void solve() {     long long n, m, i, j, c, sum;     i = j = c = sum = 0;     cin >> n;     for (i = 0; i < n; ++i) {       cin >> a[i];       --a[i];       if (a[i] != -1) {         ++in[a[i]];         ++out[i];       }     }     vector<long long> loops;     for (i = 0; i < n; ++i) {       if (in[i] == 0 and out[i] == 0) {         loops.push_back(i);       }     }     if (loops.size() == 1) {       long long init = loops[0];       for (i = 0; i < n; ++i) {         if (in[i] == 0 and i != init) {           a[init] = i;           ++out[init];           ++in[i];           break;         }       }     } else if (loops.size() > 1) {       for (i = 0; i < loops.size(); ++i) {         long long curr = loops[i];         long long nxt = loops[(i + 1) % loops.size()];         a[curr] = nxt;         ++in[nxt];         ++out[curr];       }     }     vector<long long> ins, outs;     for (i = 0; i < n; ++i) {       if (in[i] == 0) ins.push_back(i);       if (out[i] == 0) outs.push_back(i);     }     for (i = 0; i < outs.size(); ++i) {       a[outs[i]] = ins[i];     }     for (i = 0; i < n; ++i) {       cout << a[i] + 1 <<    ;     }     cout <<   n ;   }   signed main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long t = 1;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> prefix_function(const vector<int>& s) {     int n = s.size();     vector<int> pi(n);     for (int i = 1; i < n; ++i) {       int j = pi[i - 1];       while (j > 0 && s[i] != s[j]) j = pi[j - 1];       if (s[i] == s[j]) ++j;       pi[i] = j;     }     return pi;   }   int n;   set<int> f[100005];   int getLen(int a, int b) {     int len = b - a;     if (len <= 0) len += n;     return len;   }   int go(int len) {     if (f[len].size() == 0)       return 1;     else if (f[len].size() < 2)       return -1;     vector<int> diffs;     int last = -1, fir = -1;     for (int x : f[len]) {       if (last == -1)         fir = x;       else         diffs.push_back(getLen(last, x));       last = x;     }     diffs.push_back(getLen(last, fir));     vector<int> pref = prefix_function(diffs);     int cand = diffs.size() - pref.back();     if (diffs.size() % cand == 0 && cand < diffs.size()) {       int sum = 0;       for (int i = 0; i < cand; ++i) sum += diffs[i];       return sum;     }     return -1;   }   long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }   long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }   int main() {     ios::sync_with_stdio(false);     int m;     cin >> n >> m;     for (int i = 0; i < m; ++i) {       int a, b;       cin >> a >> b;       int len = getLen(a, b);       if (2 * len > n || 2 * len == n && a > b) len = n - len, swap(a, b);       f[len].insert(a - 1);     }     long long ans = 1;     for (int i = 1; i < n; ++i) {       if (2 * i == n) continue;       int cur = go(i);       if (cur == -1) {         cout <<  No  << endl;         return 0;       }       ans = lcm(ans, cur);       if (ans >= n) {         cout <<  No  << endl;         return 0;       }     }     if (n % 2 == 0) {       int cur = go(n / 2);       if (cur != -1 && lcm(ans, cur) < n || lcm(ans, n / 2) < n) {       } else {         cout <<  No  << endl;         return 0;       }     }     cout <<  Yes  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<long long> arr;   long long binarySearchCount(long long n, long long key) {     long long left = 0, right = n;     long long mid;     while (left < right) {       mid = (right + left) >> 1;       if (arr[mid] == key) {         while (mid + 1 < n && arr[mid + 1] == key) mid++;         break;       } else if (arr[mid] > key)         right = mid;       else         left = mid + 1;     }     while (mid > -1 && arr[mid] > key) mid--;     return mid;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long n;     cin >> n;     long long x;     for (long long i = 0; i < n; i++) {       cin >> x;       arr.push_back(abs(x));     }     sort(arr.begin(), arr.end());     long long ans = 0;     for (long long i = 0; i < n - 1; i++) {       long long temp = binarySearchCount(n, 2 * arr[i]);       ans += temp - i;     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   const int N = 2e5 + 5;   inline int read() {     int res = 0, ch, flag = 0;     if ((ch = getchar()) ==  - )       flag = 1;     else if (ch >=  0  && ch <=  9 )       res = ch -  0 ;     while ((ch = getchar()) >=  0  && ch <=  9 ) res = res * 10 + ch -  0 ;     return flag ? -res : res;   }   int n, m, cnt;   struct node {     int x, y;   };   node p[N];   vector<int> data;   int bit[N], t[N];   long long ans;   void add(int i) {     while (i <= m) {       bit[i]++;       i += i & -i;     }   }   int sum(int i) {     int res = 0;     while (i > 0) {       res += bit[i];       i -= i & -i;     }     return res;   }   bool cmp(node a, node b) {     if (a.y != b.y) return a.y > b.y;     return a.x < b.x;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d%d , &p[i].x, &p[i].y);       data.push_back(p[i].x);     }     sort(data.begin(), data.end());     data.erase(unique(data.begin(), data.end()), data.end());     m = data.size();     for (int i = 1; i <= n; i++)       p[i].x = lower_bound(data.begin(), data.end(), p[i].x) - data.begin() + 1;     sort(p + 1, p + n + 1, cmp);     for (int i = 1; i <= n;) {       int j = i;       while (j < n && p[j].y == p[j + 1].y) j++;       t[i - 1] = 0;       for (int k = i; k <= j; k++) {         if (sum(p[k].x) - sum(p[k].x - 1) == 0) {           add(p[k].x);           cnt++;         }         t[k] = sum(p[k].x);       }       for (int k = i; k <= j; k++)         ans += 1LL * (t[k] - t[k - 1]) * (cnt - t[k] + 1);       i = j + 1;     }     printf( %I64d n , ans);     return 0;   }


#include<bits/stdc++.h>   using namespace std;      int main()   {       int t;       cin >> t;       while(t--)       {           string s;           cin >> s;           cout << s.size() << endl;       }       return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string b;     cin >> b;     if (b ==  1 ) {       cout <<  0  << endl;       return 0;     }     int n = (int)((b).size());     string a((int)((b).size()),  - );     bool flag = true;     if (n > 2) {       if (b[0] !=  1 ) flag = false;       for (__typeof(n) i = (1); i != (n); i++)         if (b[i] !=  0 ) flag = false;       if (flag) {         cout <<  0  << endl;         return 0;       }       flag = true;     }     int i = 0, j = n - 1;     int pc = 0, cc = 0;     while (i <= j) {       int sum = b[j] + (10 * cc) - pc -  0 ;       if (sum == -1) {         if (cc == 0 && b[i] !=  9 ) {           flag = false;           break;         } else if (cc == 1 && b[i] !=  0 ) {           flag = false;           break;         }         sum = 9;         cc = 1;       }       if (i == 0) {         if (b[j] ==  0 ) {           flag = false;           break;         }         if (j == 0) {           if (sum % 2 != 0) {             flag = false;             break;           }           a[i] = (char)(sum / 2 +  0 );         } else {           a[i] =  1 ;           a[j] = (char)(sum - 1 +  0 );         }       } else {         if (i == j) {           if (sum % 2 != 0) {             flag = false;             break;           }           a[i] = (char)(sum / 2) +  0 ;         } else {           if (sum == 19) {             if (b[i] ==  0  && i != j - 1) {               a[i] =  0 ;               a[j] =  9 ;               pc = 0;               cc = 1;               i++;               j--;               continue;             } else {               flag = false;               break;             }           }           if (sum < 10) {             a[i] =  0 ;             a[j] = (char)(sum +  0 );           } else {             a[i] =  9 ;             a[j] = (char)(sum - 9 +  0 );           }         }       }       if (i == j - 1) {         if (b[i] -  0  != (sum + cc) % 10) {           flag = false;         }         break;       } else {         pc = cc;         if (b[i] -  0  == sum % 10)           cc = 0;         else if (b[i] -  0  == (sum + 1) % 10)           cc = 1;         else {           flag = false;           break;         }         i++;         j--;       }     }     if (flag) {       cout << a << endl;       return 0;     }     if (b[0] !=  1 ) {       cout <<  0  << endl;       return 0;     }     i = 1;     j = n - 1;     pc = 0;     cc = 1;     flag = true;     while (i <= j) {       int sum = b[j] + (10 * cc) - pc -  0 ;       if (sum == -1) {         if (cc == 0 && b[i] !=  9 ) {           flag = false;           break;         } else if (cc == 1 && b[i] !=  0 ) {           flag = false;           break;         }         sum = 9;         cc = 1;       }       if (i == 1) {         if (j == 0) {           if (sum % 2 != 0) {             flag = false;             break;           }           a[i] = (char)(sum / 2 +  0 );         } else {           a[i] =  9 ;           a[j] = (char)(sum - 9 +  0 );         }       } else {         if (i == j) {           if (sum % 2 != 0) {             flag = false;             break;           }           a[i] = (char)(sum / 2) +  0 ;         } else {           if (sum == 19 && i != j - 1) {             if (b[i] ==  0 ) {               a[i] =  0 ;               a[j] =  9 ;               pc = 0;               cc = 1;               i++;               j--;               continue;             } else {               flag = false;               break;             }           }           if (sum < 10) {             a[i] =  0 ;             a[j] = (char)(sum +  0 );           } else {             a[i] =  9 ;             a[j] = (char)(sum - 9 +  0 );           }         }       }       if (i == j - 1) {         if (b[i] -  0  != (sum + cc) % 10) {           flag = false;         }         break;       } else {         pc = cc;         if (b[i] -  0  == sum % 10)           cc = 0;         else if (b[i] -  0  == (sum + 1) % 10)           cc = 1;         else {           flag = false;           break;         }         i++;         j--;       }     }     if (flag) {       cout << a.substr(1) << endl;     } else {       cout <<  0  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int seed = 131;   const int maxn = 2e5 + 5;   const int mod = 1e9 + 7;   int n, k;   char a[maxn];   int main() {     scanf( %d%d , &n, &k);     scanf( %s , a + 1);     int cnt1 = 0;     int cnt2 = 0;     k /= 2;     for (int i = 1; i <= n; i++) {       if (cnt1 == k) break;       if (a[i] ==  ( ) {         cnt1++;       } else         cnt2++;       printf( %c , a[i]);     }     for (int i = cnt2; i < k; i++) printf( ) );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int byk[3][3];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int n;     cin >> n;     string s;     cin >> s;     for (int i = 0; i < n; i++) {       if (s[i] ==  B ) byk[i % 3][0]++;       if (s[i] ==  G ) byk[i % 3][1]++;       if (s[i] ==  R ) byk[i % 3][2]++;     }     int mini = 10000000;     vector<int> jwb;     vector<int> V;     V.push_back(0);     V.push_back(1);     V.push_back(2);     do {       int x = byk[0][0] + byk[0][1] + byk[0][2];       x -= byk[0][V[0]];       int y = byk[1][0] + byk[1][1] + byk[1][2];       y -= byk[1][V[1]];       int z = byk[2][0] + byk[2][1] + byk[2][2];       z -= byk[2][V[2]];       if (x + y + z < mini) {         mini = x + y + z;         jwb.clear();         jwb.push_back(V[0]);         jwb.push_back(V[1]);         jwb.push_back(V[2]);       }     } while (next_permutation(V.begin(), V.end()));     cout << mini << endl;     for (int i = 0; i < n; i++) {       if (i % 3 == 0) {         if (jwb[0] == 0) cout <<  B ;         if (jwb[0] == 1) cout <<  G ;         if (jwb[0] == 2) cout <<  R ;       }       if (i % 3 == 1) {         if (jwb[1] == 0) cout <<  B ;         if (jwb[1] == 1) cout <<  G ;         if (jwb[1] == 2) cout <<  R ;       }       if (i % 3 == 2) {         if (jwb[2] == 0) cout <<  B ;         if (jwb[2] == 1) cout <<  G ;         if (jwb[2] == 2) cout <<  R ;       }     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 501;   const long long DIM = 3e5 + 1;   int in, n, t, a[DIM];   int main() {     ios_base::sync_with_stdio;     cin.tie(0);     cout.tie(0);     in = scanf( %d , &t);     while (t--) {       in = scanf( %d , &n);       set<int> s;       for (int i = 1; i <= n; i++) {         in = scanf( %d , &a[i]);         s.insert(a[i]);       }       if (s.size() == 1)         printf( -1 n );       else {         auto it = s.end();         it--;         for (int i = 1; i <= n; i++) {           if (a[i] == *it &&               ((i > 1 && a[i - 1] != *it) || (i < n && a[i + 1] != *it))) {             printf( %d n , i);             break;           }         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 5, mod = 1e9 + 7;   int a[N], st[N][20], pos[N][20];   int seg_query(int l, int r) {     int k = log2(r - l + 1);     if (st[l][k] > st[r - (1 << k) + 1][k])       return pos[l][k];     else       return pos[r - (1 << k) + 1][k];   }   long long f[N];   signed main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n - 1; ++i)       scanf( %d , a + i), st[i][0] = a[i], pos[i][0] = i;     a[n] = n, st[n][0] = pos[n][0] = n;     for (int j = 1; j <= 17; ++j)       for (int i = 1; i + (1 << j) - 1 <= n; ++i)         if (st[i][j - 1] > st[i + (1 << (j - 1))][j - 1])           st[i][j] = st[i][j - 1], pos[i][j] = pos[i][j - 1];         else           st[i][j] = st[i + (1 << (j - 1))][j - 1],           pos[i][j] = pos[i + (1 << (j - 1))][j - 1];     long long ans = 0;     for (int i = n - 1; i >= 1; --i) {       int k = seg_query(i + 1, a[i]);       f[i] = f[k] + n - i - (a[i] - k);       ans += f[i];     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   typedef struct graph {     list<int> edges[1001];   } graph;   void dfs(graph *g, int i, int group[], int gn) {     for (list<int>::iterator it = g->edges[i].begin(); it != g->edges[i].end();          it++) {       if (group[*it] == -1) {         group[*it] = gn;         dfs(g, *it, group, gn);       }     }   }   void printArray(int arr[], int n) {     for (int i = 1; i <= n; i++) cout << arr[i] <<    ;     cout << endl;   }   int main() {     int n;     graph *g = new graph;     cin >> n;     bool flag = false;     int fin[1001], pref[1001], group[1001];     for (int i = 1; i <= n; i++) cin >> fin[i];     for (int i = 1; i <= n; i++) {       cin >> pref[i];       if (i + pref[i] <= n) {         g->edges[i].push_back(i + pref[i]);         g->edges[i + pref[i]].push_back(i);       }       if (i - pref[i] >= 1) {         g->edges[i].push_back(i - pref[i]);         g->edges[i - pref[i]].push_back(i);       }     }     fill_n(group, n + 1, -1);     int gn = 0;     for (int i = 1; i <= n; i++) {       if (group[i] == -1) {         group[i] = gn;         dfs(g, i, group, gn);         gn++;       }     }     for (int i = 1; i <= n; i++) {       if (group[i] == group[fin[i]]) {       } else {         flag = true;         cout <<  NO  << endl;         break;       }     }     if (!flag) {       cout <<  YES  << endl;     }   }


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


#include <bits/stdc++.h>   using namespace std;   const int N = 20;   const int inf = 1e9;   int dp[N][2];   vector<int> a;   void upd(int& at, int val) { at = max(at, val); }   int main() {     long long n;     scanf( %lld , &n);     while (n) {       a.push_back(n % 10);       n /= 10;     }     for (int i = 0; i < N; i++) {       dp[i][0] = dp[i][1] = -inf;     }     dp[0][0] = 0;     for (int i = 0; i < a.size(); i++) {       for (int add = 0; add <= 10; add += 10) {         for (int st = 0; st <= 1; st++) {           int sum = add + a[i] - st;           for (int j = 0; j <= min(9, sum); j++) {             int k = sum - j;             if (0 <= k && k <= 9) {               upd(dp[i + 1][add / 10], dp[i][st] + j + k);             }           }         }       }     }     cout << dp[a.size()][0] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 400004;   const long long Mod = 1000000007;   int Stop, Bcnt, Dindex, Ecnt;   int Low[N], Dfn[N], Step[N], Belong[N];   bool instack[N];   struct Edge {     int t;     int next;   } edge[N];   int head[N];   void addEdge(int s, int t) {     edge[Ecnt].t = t;     edge[Ecnt].next = head[s];     head[s] = Ecnt++;   }   void tarjan(int i) {     int j;     Dfn[i] = Low[i] = ++Dindex;     instack[i] = true;     Step[++Stop] = i;     for (int e = head[i]; e != -1; e = edge[e].next) {       j = edge[e].t;       if (!Dfn[j]) {         tarjan(j);         if (Low[j] < Low[i]) Low[i] = Low[j];       } else if (instack[j] && Dfn[j] < Low[i])         Low[i] = Dfn[j];     }     if (Dfn[i] == Low[i]) {       Bcnt++;       do {         j = Step[Stop--];         instack[j] = false;         Belong[j] = Bcnt;       } while (j != i);     }   }   void init() {     Ecnt = 0;     memset(head, -1, sizeof(head));   }   void solve(int n) {     int i;     Stop = Bcnt = Dindex = 0;     memset(Dfn, 0, sizeof(Dfn));     memset(Low, -1, sizeof(Low));     memset(instack, 0, sizeof(instack));     for (i = 1; i <= n; i++) {       if (!Dfn[i]) {         tarjan(i);       }     }   }   long long num[N];   long long Pow(int x, int y) {     long long a = (long long)x;     long long b = y;     long long ans = 1;     if (b == 0) return 1ll;     while (b > 0) {       if (b & 1) {         ans = (ans * (long long)a) % Mod;       }       a *= a;       a %= Mod;       b >>= 1;     }     return ans;   }   int main() {     int n, x;     while (~scanf( %d , &n)) {       init();       for (int i = 1; i <= n; i++) {         scanf( %d , &x);         addEdge(i, x);       }       solve(n);       memset(num, 0, sizeof(num));       for (int i = 1; i <= n; i++) {         num[Belong[i]]++;       }       long long ans = 1;       for (int i = 1; i <= n; i++) {         if (num[i]) {           if (num[i] == 1) {             ans = (ans * 2) % Mod;           } else {             long long tm = ((Pow(2, num[i]) - 2) % Mod + Mod) % Mod;             ans = ans * tm % Mod;           }         }       }       printf( %I64d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   const long long maxn = 3 * 1e5 + 1;   void swap(long long *xp, long long *yp) {     long long temp = *xp;     *xp = *yp;     *yp = temp;   }   void print(vector<long long> v) {     long long i, j, n = v.size();     for (i = 0; i < n; i++) {       cout << v[i] <<    ;     }     cout <<   n ;   }   void scan(vector<long long> &v, long long n) {     for (long long i = 0; i < n; i++) cin >> v[i];   }   long long gcd(long long a, long long b) {     if (b == 0) return a;     return gcd(b, a % b);   }   long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); }   long long power(long long x, long long y) {     long long res = 1;     while (y > 0) {       if (y & 1) res = (res * x) % mod;       y = y / 2;       x = (x * x) % mod;     }     return res % mod;   }   long long modinv(long long x) { return power(x, mod - 2) % mod; }   vector<bool> prime(maxn, true);   void sieve() {     long long n = maxn;     prime[0] = false;     prime[1] = false;     for (long long p = 2; p * p <= n; p++) {       if (prime[p] == true) {         for (long long i = p * p; i <= n; i += p) prime[i] = false;       }     }   }   int main() {     long long int i, j, inc, dec, t, r;     long long int c, d, e, temp, m, p, w, k, x, y, sum, pre, temp2, mid, n, low,         high, ans;     t = 1;     n = 1;     while (t--) {       cin >> n;       sum = 0;       vector<long long> a;       vector<long long> tem(maxn, 0);       a.push_back(0);       while (n--) {         long long type;         cin >> type;         if (type == 1) {           cin >> x >> y;           sum += (x * y);           tem[x] += y;         } else if (type == 2) {           cin >> k;           a.push_back(k);           sum += k;         } else {           y = a.size();           sum -= (a.back() + tem[y]);           tem[y - 1] += tem[y];           tem[y] = 0;           a.pop_back();         }         x = a.size();         double an = (sum * 1.0) / (x * 1.0);         cout << fixed << setprecision(10) << an <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, k, arr[1005][1005];   void ch_col(int x, int y) {     for (int i = 1; i <= n; i++) swap(arr[i][x], arr[i][y]);   }   void ch_row(int x, int y) {     for (int i = 1; i <= m; i++) swap(arr[x][i], arr[y][i]);   }   int row[1005], col[1005];   int main() {     for (int i = 1; i <= 1005; i++) {       row[i] = i;       col[i] = i;     }     scanf( %d %d %d , &n, &m, &k);     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) scanf( %d , &arr[i][j]);     while (k--) {       char order;       int x, y;       scanf(  %c %d %d , &order, &x, &y);       if (order ==  g ) printf( %d n , arr[row[x]][col[y]]);       if (order ==  c ) swap(col[x], col[y]);       if (order ==  r ) swap(row[x], row[y]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, l, t, a[3000010], gx;   double Ans;   signed main() {     scanf( %lld%lld%lld , &n, &l, &t);     t *= 2;     gx = t / l, t %= l;     for (long long i = 1; i <= n; i++) scanf( %lld , &a[i + n]);     for (long long i = 1; i <= n; i++) a[i] = a[i + n] - l;     for (long long i = 1; i <= n; i++) a[i + n + n] = a[i + n] + l;     for (long long i = 1, j1 = 1, j2 = i + 1; i <= n; i++) {       while (a[i + n] - a[j1] > t) j1++;       while (a[j2 + 1] - a[i + n] <= t && j2 + 1 <= 3 * n) j2++;       Ans += 0.25 * ((n - 1) * gx + i + n - j1 + (n - 1) * gx + j2 - i - n);     }     printf( %.6lf n , Ans / 2);   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1000001;   const long long mod = 1000000009;   long long f[N];   long long getall(int m) {     long long res = 2;     for (int i = 1; i < m; ++i) res = (res * 2) % mod;     return res - 1;   }   long long solve(int n, int m) {     long long all = getall(m);     f[1] = getall(m);     for (int i = 2; i <= n; ++i) f[i] = ((f[i - 1] * (all - (i - 1))) % mod);     return f[n];   }   int main() {     int n, m;     cin >> n >> m;     cout << solve(n, m) << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n, res = 0, m = 0, mx = 0;     cin >> n;     vector<int> v(n);     for (int i = 0; i < n; i++) cin >> v[i];     for (int i = 0; i < n; i++) {       int x = v[i], c = 1;       for (int j = i + 1; j < n; j++) {         if (x >= v[j]) {           c++;           x = min(v[j], x);         } else           break;       }       x = v[i];       for (int j = i - 1; j >= 0; j--) {         if (x >= v[j]) {           c++;           x = min(v[j], x);         } else           break;       }       res = max(res, c);     }     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   #pragma comment(linker,  /STACK:102400000,102400000 )   const long long INF = 1e18 + 1LL;   const double Pi = acos(-1.0);   const int N = 3e3 + 10, M = 1e3 + 20, mod = 2017, inf = 2e9;   int b[N][N], m, n, a[N][N];   vector<int> ans1, ans2, ans3, ans4;   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= m; ++j) scanf( %d , &a[i][j]), b[i][j] = a[i][j];     }     int fi = 0;     for (int i = 1; i <= n; ++i) {       int sum = inf;       for (int j = 1; j <= m; ++j) {         sum = min(sum, a[i][j]);       }       if (sum) {         for (int j = 1; j <= sum; ++j) ans1.push_back(i);         for (int j = 1; j <= m; ++j) a[i][j] -= sum;       }     }     for (int i = 1; i <= m; ++i) {       int sum = inf;       for (int j = 1; j <= n; ++j) {         sum = min(sum, a[j][i]);       }       if (sum) {         for (int j = 1; j <= sum; ++j) ans2.push_back(i);         for (int j = 1; j <= n; ++j) a[j][i] -= sum;       }     }     fi = ans1.size() + ans2.size();     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= m; ++j) {         if (a[i][j]) {           puts( -1 );           return 0;         }       }     }     for (int i = 1; i <= m; ++i) {       int sum = inf;       for (int j = 1; j <= n; ++j) {         sum = min(sum, b[j][i]);       }       if (sum) {         for (int j = 1; j <= sum; ++j) ans4.push_back(i);         for (int j = 1; j <= n; ++j) b[j][i] -= sum;       }     }     for (int i = 1; i <= n; ++i) {       int sum = inf;       for (int j = 1; j <= m; ++j) {         sum = min(sum, b[i][j]);       }       if (sum) {         for (int j = 1; j <= sum; ++j) ans3.push_back(i);         for (int j = 1; j <= m; ++j) b[i][j] -= sum;       }     }     int se = ans3.size() + ans4.size();     if (fi <= se) {       cout << ans1.size() + ans2.size() << endl;       for (int i = 0; i < ans1.size(); ++i) {         cout <<  row               <<     << ans1[i] << endl;       }       for (int i = 0; i < ans2.size(); ++i) {         cout <<  col               <<     << ans2[i] << endl;       }     } else {       cout << ans3.size() + ans4.size() << endl;       for (int i = 0; i < ans3.size(); ++i) {         cout <<  row               <<     << ans3[i] << endl;       }       for (int i = 0; i < ans4.size(); ++i) {         cout <<  col               <<     << ans4[i] << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int SIZE = 1e5 + 10;   int a[SIZE];   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int T, n;     cin >> T;     while (T--) {       cin >> n;       vector<int> ans;       for (int i = 1; i <= n; i++) {         cin >> a[i];         if (a[i] % 2 == 0) ans.push_back(i);       }       if (ans.size()) {         cout << 1 << endl << ans[0] << endl;         continue;       }       if (n == 1) {         cout << -1 << endl;         continue;       }       cout << 2 << endl;       cout << 1 <<     << 2 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct Point {     long long x, y;     Point(long long x_, long long y_) {       x = x_;       y = y_;     }     Point() {}     Point operator-(const Point &other) const {       return Point(x - other.x, y - other.y);     }     long long dist(const Point &other) const {       long long dx = x - other.x;       long long dy = y - other.y;       return dx * dx + dy * dy;     }     friend long long operator*(const Point &a, const Point &b) {       return a.x * b.y - a.y * b.x;     }   };   long long up(const Point &a) { return a.y > 0 || (a.y == 0 && a.x >= 0); }   long long solve(long long n, vector<Point> poly, Point to) {     auto cmp = [&](const Point &a, const Point &b) {       Point f = a - to;       Point s = b - to;       if (up(f) == up(s)) {         return f * s > 0;       } else {         return up(f) < up(s);       }     };     sort(poly.begin(), poly.end(), cmp);     long long ans = (n * (n - 1) * (n - 2)) / 6;     for (long long i = 0; i < n; i++) {       long long rs = 0;       {         long long l = 1;         long long r = n;         while (r - l > 1) {           long long m = (r + l) >> 1;           if ((poly[(i + m) % n] - poly[i]) * (to - poly[i]) >= 0) {             l = m;           } else {             r = m;           }         }         rs = l;       }       long long len = rs;       ans -= (len) * (len - 1) / 2;     }     assert(ans >= 0);     return ans;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     long long n;     cin >> n;     vector<Point> poly(n);     for (auto &t : poly) {       cin >> t.x >> t.y;     }     long long ans = 0;     for (long long i = 0; i < n; i++) {       auto np = poly;       np.erase(np.begin() + i);       ans += solve(n - 1, np, poly[i]);     }     cout << ans * (n - 4) / 2 << endl;   }


#include <bits/stdc++.h>   using namespace std;   int n, a[201], dp[201][201][1001];   const long long int MOD = 1e9 + 7;   int solve(int i, int g, int k) {     if (g < 0 || k < 0) return 0;     if (i == n) return (g == 0);     if (dp[i][g][k] != -1) return dp[i][g][k];     long long int ret = 0;     int nk = k - g * (a[i] - a[i - 1]);     if (nk >= 0) {       ret = (ret + 1LL * g * solve(i + 1, g - 1, nk)) % MOD;       ret = (ret + 1LL * (g + 1) * solve(i + 1, g, nk)) % MOD;       ret = (ret + 1LL * solve(i + 1, g + 1, nk)) % MOD;     }     return dp[i][g][k] = ret;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int k;     cin >> n >> k;     for (int i = 0; i < n; i++) cin >> a[i];     sort(a, a + n);     memset(dp, -1, sizeof dp);     cout << solve(0, 0, k);   }


#include<stdio.h>   #include<iostream>   #include<string.h>   #include<vector>   #include<queue>   #include<map>   #include<math.h>   #include<algorithm>   #include<stdlib.h>   #include<string>   #include<stack>   #include<set>   using namespace std;   #define pb push_back   #define POP pop_back()   #define DEBUG cout <<  DEBUG n ;   #define ll long long   #define db double   #define endl   n    #define fo(i,a,b) for(int i = a;i <= b;i++)   #define lowbit(x) (x&-x);   const int maxn = 5e5+5;   const int inf = 0x3f3f3f3f;   const ll inF = 0x3f3f3f3f3f3f3f3f;   const ll mod = 1e8;   const db eps = 1e-8;   struct node{    int v , id;    bool operator < (const node &b)const{     return v < b.v;    }   };   node cnt[maxn];   int a[maxn];   int main(){    int t , n;cin >> t;    while(t--){     cin >> n;     for(int i = 1;i <= n;i++)cnt[i].v = cnt[i].id = 0;     for(int i = 1;i <= n;i++)scanf( %d ,&a[i]) , cnt[a[i]].v++ , cnt[a[i]].id = i;     int ans = -1;     for(int i = 1;i <= n;i++){      if(cnt[i].v == 1){ans = cnt[i].id;break;}     }     if(ans == -1){      cout <<  -1 n ;     }     else cout << ans << endl;    }    return 0;   }


#include <bits/stdc++.h>   using namespace std;   char s[120][120];   int n, m;   int main() {     int i, j, k, res = 30, now = 0;     string ss =   ;     scanf( %d%d , &n, &m);     for (i = 0; i < n; i++) scanf( %s , s[i]);     for (i = 0; i < n; i++) {       for (j = 0; j < m; j++) {         char c = s[i][j];         int f = 0;         for (k = 0; k < n; k++) {           if (i == k) continue;           if (s[k][j] == c) f = 1;         }         for (k = 0; k < m; k++) {           if (j == k) continue;           if (s[i][k] == c) f = 1;         }         if (!f) ss += c;       }     }     cout << ss << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool within(int x1, int x2, int y1, int y2, int px, int py) {     if (x1 <= px and px <= x2 and y1 <= py and py <= y2) {       return true;     }     return false;   }   int main() {     ios::sync_with_stdio(false);     int y, x, v, n;     cin >> y >> x >> v >> n;     int py[v], px[v];     for (int i = 0; i < v; i++) {       cin >> px[i] >> py[i];       py[i]--, px[i]--;     }     int res = 0;     for (int x1 = 0; x1 < x; x1++) {       for (int x2 = x1; x2 < x; x2++) {         for (int y1 = 0; y1 < y; y1++) {           for (int y2 = y1; y2 < y; y2++) {             int found = 0;             for (int i = 0; i < v; i++) {               if (within(x1, x2, y1, y2, py[i], px[i])) {                 found++;               }             }             if (found >= n) {               res++;             }           }         }       }     }     cout << res;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, x = 4, y = 5;     scanf( %d , &n);     if (n == 1 || n == 2) {       cout << 1;       return 0;     }     while (y < n) {       if (x & 1)         x = 2 * y, y = x + 1;       else         x = 2 * y - 1, y = x + 1;     }     printf( %d , (x == n || y == n));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const long long INFF = 0x3f3f3f3f3f3f3f3fll;   const long long M = 1e9 + 7;   const long long maxn = 1e6 + 7;   const double pi = acos(-1.0);   const double eps = 0.0000000001;   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   template <typename T>   inline void pr2(T x, int k = 64) {     long long i;     for (i = 0; i < k; i++) fprintf(stderr,  %d , (x >> i) & 1);     putchar(   );   }   template <typename T>   inline void add_(T &A, int B) {     A += B;     (A >= M) && (A -= M);   }   template <typename T>   inline void mul_(T &A, long long B) {     (A *= B) %= M;   }   template <typename T>   inline void mod_(T &A, long long B = M) {     A %= M;   }   template <typename T>   inline void max_(T &A, T B) {     (A < B) && (A = B);   }   template <typename T>   inline void min_(T &A, T B) {     (A > B) && (A = B);   }   template <typename T>   inline T abs(T a) {     return a > 0 ? a : -a;   }   template <typename T>   inline T powMM(T a, T b) {     T ret = 1;     for (; b; b >>= 1ll, a = (long long)a * a % M)       if (b & 1) ret = (long long)ret * a % M;     return ret;   }   int n, m, q;   char str[maxn];   int TaskA();   void Task_one() { TaskA(); }   void Task_T() {     int T;     scanf( %d , &T);     while (T--) TaskA();   }   void Task_more_n() {     while (~scanf( %d , &n)) TaskA();   }   void Task_more_n_m() {     while (~scanf( %d%d , &n, &m)) TaskA();   }   void Task_more_n_m_q() {     while (~scanf( %d%d%d , &n, &m, &q)) TaskA();   }   void Task_more_string() {     while (~scanf( %s , str)) TaskA();   }   int A[maxn];   int TaskA() {     int i, t, k;     scanf( %d%d , &n, &k);     t = k;     for (i = 1; i <= n; i++) scanf( %d , &A[i]), t = gcd(t, A[i]);     printf( %d n , k / t);     for (i = 0; i < k / t; i++) printf( %d  , i * t);     return 0;   }   void initialize() {}   int main() {     int startTime = clock();     initialize();     fprintf(stderr,  /--- initializeTime: %ld milliseconds ---/ n ,             clock() - startTime);     Task_one();   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<int> arr(n);     for (int i = 0; i < n; i++) {       cin >> arr[i];     }     int m;     cin >> m;     while (m--) {       int k, pos;       cin >> k >> pos;       pos--;       vector<vector<int>> ans(k);       vector<long long> sums(k);       int last = 0;       for (int i = 0; i < n; i++) {         for (int j = last; j >= 0; j--) {           if (j >= k) continue;           if (ans[j].size() == 0) {             if (j == 0) {               ans[j].push_back(arr[i]);               sums[j] = arr[i];             } else {               ans[j] = ans[j - 1];               ans[j].push_back(arr[i]);               sums[j] = sums[j - 1] + arr[i];             }           } else {             if (j == 0) {               if (arr[i] > sums[j]) {                 ans[j][0] = arr[i];                 sums[j] = arr[i];               }             } else if (sums[j - 1] + arr[i] > sums[j]) {               sums[j] = sums[j - 1] + arr[i];               ans[j] = ans[j - 1];               ans[j].push_back(arr[i]);             } else if (sums[j - 1] + arr[i] == sums[j]) {               bool change = 0;               for (int k = 0; k < ans[j - 1].size(); k++) {                 if (ans[j - 1][k] < ans[j][k]) {                   change = 1;                   break;                 } else if (ans[j - 1][k] > ans[j][k]) {                   break;                 }               }               if (change) {                 ans[j] = ans[j - 1];                 ans[j].push_back(arr[i]);               }             }           }         }         last += 1;       }       cout << ans[k - 1][pos] <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void Fast() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);   }   void File() {}   using ll = long long;   using ull = unsigned long long;   ll gcd(ll a, ll b) { return !b ? a : gcd(b, a % b); }   const int N = 100001;   bool prime[N];   int n, res[N];   vector<int> v, primes;   vector<vector<int>> numFactors, primeIdx;   vector<int>::iterator it;   void sieve() {     for (int i = 0; i < N; i++) prime[i] = 1;     prime[0] = prime[1] = 0;     for (int i = 4; i < N; i += 2) {       prime[i] = 0;     }     for (int i = 3; i * i < N; i += 2) {       if (prime[i]) {         for (int j = i * i; j < N; j += i + i) {           prime[j] = 0;         }       }     }     for (int i = 2; i < N; i++) {       if (prime[i]) {         primes.push_back(i);       }     }   }   void Prime_Factors_Faster(int n, int id) {     int temp = n;     if (prime[n]) {       primeIdx[n].push_back(id);       numFactors[temp].push_back(n);       return;     }     int idx = 0;     while (idx < primes.size() && primes[idx] * primes[idx] <= n) {       int cnt = 0;       while (n % primes[idx] == 0) {         n /= primes[idx];         cnt++;       }       if (cnt)         numFactors[temp].push_back(primes[idx]),             primeIdx[primes[idx]].push_back(id);       ;       idx++;     }     if (n > 1) {       primeIdx[n].push_back(id);       numFactors[temp].push_back(n);     }   }   int solve(int idx) {     int& ans = res[idx];     if (~ans) return ans;     ans = 1;     for (int i = 0; i < numFactors[v[idx]].size(); i++) {       int pr = numFactors[v[idx]][i];       it = upper_bound(primeIdx[pr].begin(), primeIdx[pr].end(), idx);       if (it != primeIdx[pr].end()) ans = max(ans, solve(*it) + 1);     }     return ans;   }   int main() {     File(), Fast();     sieve();     numFactors.resize(N), primeIdx.resize(N);     cin >> n;     v.resize(n);     for (int i = 0; i < n; i++) {       cin >> v[i], Prime_Factors_Faster(v[i], i);     }     int* dp = new int[n];     for (int i = 0; i < n; i++) dp[i] = 1;     for (int i = 0; i < n; i++) cin >> v[i], Prime_Factors_Faster(v[i], i);     for (int i = n - 1; i >= 0; i--) {       for (int j = 0; j < numFactors[v[i]].size(); j++) {         int pr = numFactors[v[i]][j];         it = upper_bound(primeIdx[pr].begin(), primeIdx[pr].end(), i);         if (it != primeIdx[pr].end() and v[*it] > v[i])           dp[i] = max(dp[i], dp[*it] + 1);       }     }     cout << *max_element(dp, dp + n) <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int n, k, cnt;   pair<int, int> Ans[100010];   int main() {     scanf( %d%d , &n, &k);     if (k == 1 || k > 3 || n <= 3 || (k == 2 && n == 4)) {       puts( -1 );       return 0;     }     if (k == 2) {       printf( %d n , n - 1);       for (int i = 1; i < n; i++) printf( %d %d n , i, i + 1);     } else {       Ans[++cnt] = make_pair(2, 3);       for (int i = 5; i <= n; i++)         Ans[++cnt] = make_pair(2, i), Ans[++cnt] = make_pair(3, i);       Ans[++cnt] = make_pair(1, 2);       Ans[++cnt] = make_pair(3, 4);       printf( %d n , cnt);       for (int i = 1; i <= cnt; i++)         printf( %d %d n , Ans[i].first, Ans[i].second);     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   #pragma GCC optimize( unroll-loops )   #pragma GCC optimize( Ofast )   #pragma GCC optimize( O3 )   #pragma GCC target( avx )   using namespace std;   long long fpow(long long x, long long y, long long m) {     long long temp;     if (y == 0 || x == 1) return 1;     temp = fpow(x, y / 2, m);     if (y % 2 == 0)       return ((temp) * (temp)) % m;     else       return (((x) % m) * ((temp * temp) % m)) % m;   }   long long gcd(long long a, long long b) {     if (b == 0) return a;     return gcd(b, a % b);   }   void sieve(long long n) {     bool prime[5 * 300005];     memset(prime, true, sizeof(prime));     for (long long p = 2; p * p <= n; p++)       if (prime[p] == true)         for (long long i = p * p; i <= n; i += p) prime[i] = false;     prime[1] = 0;   }   inline long long read() {     long long p = 1, ans = 0;     char ch = getchar();     while (ch < 48 || ch > 57) {       if (ch ==  - ) p = -1;       ch = getchar();     }     while (ch >= 48 && ch <= 57) {       ans = (ans << 3) + (ans << 1) + ch - 48;       ch = getchar();     }     return ans * p;   }   long long cnt, sum, mid, mx = -1e17, mn = 1e17, a[2 * 300005];   long long n, m, d, t, i, j, k, l, r, x, y, z;   bool f, f1, f2;   string s;   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     n = read();     vector<long long> s(n + 2);     for ((i) = 1; (i) <= ((n + 1) / 2); (i)++) {       a[i] = read();       s[i] = a[i] + s[i - 1];     }     x = read();     for (; i <= n; i++) s[i] = s[i - 1] + x;     if (s[n] > 0) {       cout << n;       return 0;     }     if (x >= 0) {       cout << -1;     } else {       vector<long long> dp(n + 2);       sum = 0;       for ((i) = 1; (i) <= ((n + 1) / 2); (i)++) {         sum += x - a[i];         dp[i] = min(dp[i - 1], sum);       }       for (k = ((n + 1) >> 1); k <= n; k++) {         if (s[k] + dp[n - k] > 0) {           cout << k;           return 0;         }       }       cout << -1;     }   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1000000007;   const double eps = 1e-6;   const int inf = 0x3f3f3f3f;   const long long INF = 100000000000000000ll;   const int MAXN = 4004;   const int MAXM = 300030;   int dp[MAXN][MAXN];   int main() {     int n;     cin >> n;     dp[0][0] = 1;     for (int i = 1; i <= n + 1; i++) {       dp[i][0] = dp[i - 1][i - 1];       for (int j = 1; j <= i; j++) {         dp[i][j] = (dp[i][j - 1] + dp[i - 1][j - 1]) % mod;       }     }     printf( %d n , (dp[n + 1][0] - dp[n][0] + mod) % mod);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n;     string second;     cin >> n >> second;     int i;     int p = 0;     for (i = 0; i < n; i++) {       if (second[i] ==  8 ) p++;     }     int m = (n - p) / 10;     if (p > m) {       cout << n / 11;     } else       cout << min(p, m);     return 0;   }