#include <bits/stdc++.h>   using namespace std;   inline void read(int &data) {     data = 0;     int e = 1;     char ch = getchar();     while ((ch <  0  || ch >  9 ) && ch !=  - ) ch = getchar();     if (ch ==  - ) e = -1, ch = getchar();     while (ch >=  0  && ch <=  9 ) data = data * 10 + ch - 48, ch = getchar();     data *= e;   }   inline void read(long long &data) {     data = 0;     int e = 1;     char ch = getchar();     while ((ch <  0  || ch >  9 ) && ch !=  - ) ch = getchar();     if (ch ==  - ) e = -1, ch = getchar();     while (ch >=  0  && ch <=  9 ) data = data * 10 + ch - 48, ch = getchar();     data *= e;   }   inline void write(int data) {     if (data < 0) data = -data, putchar( - );     if (data > 9) write(data / 10);     putchar(data % 10 + 48);   }   inline void write(long long data) {     if (data < 0) data = -data, putchar( - );     if (data > 9) write(data / 10);     putchar(data % 10 + 48);   }   bool cmp(int a, int b) { return a < b; }   priority_queue<long long, vector<long long>, greater<long long> > q;   long long n, x, ans = 0;   int main() {     read(n);     for (int i = 1; i <= n; ++i) {       read(x);       if (q.empty() || q.top() > x)         q.push(x);       else {         ans += x - q.top();         q.pop();         q.push(x), q.push(x);       }     }     write(ans), puts(  );   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 4e5 + 5;   const long long M = 1e6 + 5;   const long long inf = 1e18;   const long long eps = 1e-5;   inline long long read() {     long long s = 0;     register bool neg = 0;     register char c = getchar();     for (; c <  0  || c >  9 ; c = getchar()) neg |= (c ==  - );     for (; c >=  0  && c <=  9 ; s = s * 10 + (c ^ 48), c = getchar())       ;     s = (neg ? -s : s);     return s;   }   long long a, b, c, fa[N][21], mx[N][21], F[N], dep[N], C[N];   bool vis[N];   struct node {     long long x, y, val, real, id;     bool vis;     bool operator<(const node &o) const { return val < o.val; }   } s[N];   vector<pair<long long, long long> > st[N];   inline long long f(long long n) { return F[n] == n ? n : F[n] = f(F[n]); }   inline void dfs(long long n, long long lst, long long p) {     dep[n] = dep[lst] + 1;     fa[n][0] = lst;     mx[n][0] = p;     for (long long i = (1); i <= (20); ++i) {       fa[n][i] = fa[fa[n][i - 1]][i - 1];       mx[n][i] = max(mx[n][i - 1], mx[fa[n][i - 1]][i - 1]);     }     for (long long i = (0); i <= (((long long)((st[n]).size())) - 1); ++i) {       long long v = st[n][i].first;       if (v == lst) continue;       dfs(v, n, st[n][i].second);     }   }   inline long long LCA(long long n, long long m) {     if (dep[n] < dep[m]) swap(n, m);     long long res = -inf;     for (long long i = (20); i >= (0); --i)       if (dep[fa[n][i]] >= dep[m]) {         res = max(res, mx[n][i]);         n = fa[n][i];       }     if (n == m) return res;     for (long long i = (20); i >= (0); --i)       if (fa[n][i] != fa[m][i]) {         res = max(res, max(mx[n][i], mx[m][i]));         n = fa[n][i];         m = fa[m][i];       }     res = max(res, max(mx[n][0], mx[m][0]));     return res;   }   inline void del(long long n, long long m) {     vis[n] = vis[m] = 1;     while (n != m) {       if (dep[n] <= dep[m])         m = fa[m][0];       else         n = fa[n][0];       vis[n] = vis[m] = 1;     }   }   signed main() {     memset(mx, -0x3f, sizeof(mx));     a = read();     b = read();     for (long long i = (1); i <= (a); ++i) F[i] = i;     for (long long i = (1); i <= (b); ++i) s[i].val = read();     for (long long i = (1); i <= (b); ++i) C[i] = read();     for (long long i = (1); i <= (b); ++i) {       s[i].x = read();       s[i].y = read();       s[i].id = i;     }     c = read();     for (long long i = (1); i <= (b); ++i) s[i].real = s[i].val - c / C[i];     sort(s + 1, s + b + 1);     long long mn = 1, ans = 0, a1, a2 = inf, t1, t2, t3, mn1;     for (long long i = (1); i <= (b); ++i) {       long long f1 = f(s[i].x), f2 = f(s[i].y);       if (f1 == f2) continue;       F[f1] = f2;       ans += s[i].val;       if (s[i].real - s[i].val < s[mn].real - s[mn].val) mn = i;       s[i].vis = 1;       st[s[i].x].push_back(make_pair(s[i].y, s[i].val));       st[s[i].y].push_back(make_pair(s[i].x, s[i].val));     }     a1 = ans + s[mn].real - s[mn].val;     dfs(1, 0, -inf);     for (long long i = (1); i <= (b); ++i) {       if (s[i].vis) continue;       long long tmp = LCA(s[i].x, s[i].y);       if (ans - tmp + s[i].real < a2) {         a2 = ans - tmp + s[i].real;         t3 = tmp;         t1 = s[i].x, t2 = s[i].y;         mn1 = i;       }     }     printf( %lld n , min(a1, a2));     if (a1 < a2) {       for (long long i = (1); i <= (b); ++i)         if (s[i].vis) {           if (mn == i)             printf( %lld %lld n , s[i].id, s[i].real);           else             printf( %lld %lld n , s[i].id, s[i].val);         }     } else {       del(t1, t2);       for (long long i = (1); i <= (b); ++i) {         if (!s[i].vis) continue;         if (t1 && vis[s[i].x] && vis[s[i].y] && s[i].val == t3)           t1 = 0;         else           printf( %lld %lld n , s[i].id, s[i].val);       }       printf( %lld %lld n , s[mn1].id, s[mn1].real);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int x;   void dfsUtil(int node, int count, bool visited[], int& maxCount,                vector<vector<int> >& adj) {     visited[node] = true;     count++;     for (auto& i : adj[node]) {       if (!visited[i]) {         if (count >= maxCount) {           maxCount = count;           x = i;         }         dfsUtil(i, count, visited, maxCount, adj);       }     }   }   void dfs(int node, int n, vector<vector<int> >& adj, int& maxCount) {     bool visited[n];     int count = 0;     for (int i = 0; i < n; ++i) visited[i] = false;     dfsUtil(node, 1, visited, maxCount, adj);   }   int diameter(vector<vector<int> >& adj, int n) {     int maxCount = INT_MIN;     dfs(0, n, adj, maxCount);     dfs(x, n, adj, maxCount);     return maxCount;   }   bool vis[100010];   int dist[100010];   void dfs1(int v, int p, vector<vector<int> >& adj) {     if (vis[v]) return;     vis[v] = true;     if (p == -1)       dist[v] = 0;     else       dist[v] = dist[p] + 1;     for (auto& u : adj[v]) {       dfs1(u, v, adj);     }   }   void solve() {     int n, a, b, da, db;     cin >> n >> a >> b >> da >> db;     a--;     b--;     vector<vector<int> > adj(n);     for (int i = 0; i < n - 1; i++) {       int u, v;       cin >> u >> v;       u--;       v--;       adj[u].push_back(v);       adj[v].push_back(u);     }     if (db <= 2 * da) {       cout <<  Alice  << endl;       return;     }     for (int i = 0; i < n; i++) {       vis[i] = false;     }     dfs1(a, -1, adj);     if (dist[b] <= da) {       cout <<  Alice  << endl;       return;     }     if (diameter(adj, n) - 1 >= 2 * da + 1) {       cout <<  Bob  << endl;     } else {       cout <<  Alice  << endl;     }   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());     int t;     cin >> t;     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   struct Nod {     int mark, label;   } nod[200010];   int val[200010];   bool cmp1(Nod n1, Nod n2) {     if (n1.mark != n2.mark) return n1.mark > n2.mark;     return n1.label < n2.label;   }   bool cmp2(Nod n1, Nod n2) {     if (n1.mark != n2.mark) return n1.mark > n2.mark;     return n1.label > n2.label;   }   int main() {     int n, a, b;     scanf( %d , &n);     scanf( %d%d , &a, &b);     for (int i = 0; i < n; ++i) {       scanf( %d , &nod[i].mark);       nod[i].label = i;     }     if (a == b) {       for (int i = 1; i < n; ++i)         if (i <= n / 2)           printf( 1  );         else           printf( 2  );       printf( 2 n );       return 0;     }     if (a < b) {       sort(nod, nod + n, cmp1);       for (int i = 0; i < n; ++i) {         if (i < a)           val[nod[i].label] = 1;         else           val[nod[i].label] = 2;       }     } else {       sort(nod, nod + n, cmp2);       for (int i = 0; i < n; ++i) {         if (i < b)           val[nod[i].label] = 2;         else           val[nod[i].label] = 1;       }     }     for (int i = 0; i < n - 1; ++i) printf( %d  , val[i]);     printf( %d n , val[n - 1]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int s[100], t[100], n, p, i, j, solv, tim, c;     scanf( %d%d , &n, &p);     for (i = 0; i < n; i++) {       scanf( %d%d , &s[i], &t[i]);     }     for (i = 1; i < n; i++)       for (j = 0; j < n - i; j++)         if (s[j] < s[j + 1] || (s[j] == s[j + 1] && t[j] > t[j + 1])) {           swap(s[j], s[j + 1]);           swap(t[j], t[j + 1]);         }     solv = s[p - 1];     tim = t[p - 1];     c = 0;     for (i = p - 1; i >= 0; i--) {       if (solv == s[i] && t[i] == tim)         c++;       else         break;     }     for (i = p; i < n; i++) {       if (solv == s[i] && t[i] == tim)         c++;       else         break;     }     printf( %d , c);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool valid(string s) {     int start = 0, end = s.length() - 1;     while (start < end) {       if (s[start] ==  a  && s[end] ==  a ) {         start++;         end--;       } else if (s[start] ==  a  && s[end] ==  z ) {         return false;       } else if (s[start] ==  z  && s[end] ==  a ) {         return false;       } else if (s[start] ==  z  && s[end] ==  z ) {         start++;         end--;       } else if (s[start] ==  z ) {         if (abs(s[start] - s[end]) == 2 || abs(s[start] - s[end]) == 0) {           start++;           end--;         } else {           return false;         }       } else if (s[start] ==  a ) {         if (abs(s[start] - s[end]) == 2 || abs(s[start] - s[end]) == 0) {           start++;           end--;         } else {           return false;         }       } else if (s[end] ==  a ) {         if (abs(s[start] - s[end]) == 2 || abs(s[start] - s[end]) == 0) {           start++;           end--;         } else {           return false;         }       } else if (s[end] ==  z ) {         if (abs(s[start] - s[end]) == 2 || abs(s[start] - s[end]) == 0) {           start++;           end--;         } else {           return false;         }       } else {         if (abs(s[start] - s[end]) == 2 || abs(s[start] - s[end]) == 0) {           start++;           end--;         } else {           return false;         }       }     }   }   int main() {     int n, t;     string s;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d , &t);       cin >> s;       if (valid(s))         cout <<  YES  << endl;       else         cout <<  NO  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using lli = long long int;   int main() {     std::string str;     lli q, a, b, n, needSum;     lli ost = 0;     std::cin >> q;     for (int i = 0; i < q; ++i) {       std::cin >> a >> b >> n >> needSum;       if (a * n == needSum || b == needSum) {         std::cout <<  Yes  << std::endl;         continue;       }       if (a * n > needSum) {         ost = needSum % n;         if (b >= ost) {           std::cout <<  Yes  << std::endl;           continue;         }       } else {         if (a * n + b >= needSum) {           std::cout <<  Yes  << std::endl;           continue;         }       }       std::cout <<  No  << std::endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 5;   int num[5005], cnt[5005] = {}, id[5005];   int dp[5005][5005];   bool used[5005];   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n, k;     cin >> n >> k;     for (int i = 1; i <= n; i++) cin >> num[i];     sort(num + 1, num + n + 1);     for (int i = 1; i <= n; i++) {       int r = i;       while (r + 1 <= n && (num[r + 1] - num[i]) <= 5) r++;       cnt[i] = r;     }     for (int i = n; i >= 1; i--) {       for (int j = 1; j <= k; j++) {         dp[i][j] = dp[i + 1][j];         dp[i][j] = max(dp[i][j], dp[cnt[i] + 1][j - 1] + cnt[i] - i + 1);       }     }     int ans = 0;     for (int i = 1; i <= n; i++) ans = max(ans, dp[1][i]);     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   long long int powerMod(long long int x, unsigned long long int y) {     if (y == 0) return 1;     long long int p = powerMod(x, y / 2) % 1000000007;     p = (p * p) % 1000000007;     return (y % 2 == 0) ? p : (x * p) % 1000000007;   }   long long int power(long long int x, unsigned long long int y) {     if (y == 0) return 1;     long long int p = power(x, y / 2);     p = (p * p);     return (y % 2 == 0) ? p : (x * p);   }   int main() {     cin.tie(0)->sync_with_stdio(0);     int t;     cin >> t;     while (t--) {       long long int n;       cin >> n;       vector<long long int> arr(n);       for (int i = 0; i < n; ++i) cin >> arr[i];       if (n % 2 == 0)         cout <<  YES n ;       else {         bool ok = true;         for (int i = 0; i < n - 1; ++i) {           if (arr[i + 1] <= arr[i]) {             ok = false;             break;           }         }         if (!ok)           cout <<  YES n ;         else           cout <<  NO n ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 7;   int n, m, B, a[N], c[N], ans[N];   struct Node {     int l, r, id;     Node() {}     Node(int _l, int _r, int _id) { l = _l, r = _r, id = _id; }     bool operator<(const Node &p) const { return r < p.r; }   } Q[N];   vector<int> V, q[400];   int calc(int l, int r) {     int ret = 0;     for (int i = (l); i < (r + 1); ++i) {       int x = a[i];       ++c[x];       ret += c[x] == V[x];       ret -= c[x] == V[x] + 1;     }     for (int i = (l); i < (r + 1); ++i) c[a[i]] = 0;     return ret;   }   int main() {     scanf( %d%d , &n, &m);     B = sqrt(n);     for (int i = (0); i < (n); ++i) {       scanf( %d , &a[i]);       V.push_back(a[i]);     }     sort(V.begin(), V.end());     V.erase(unique(V.begin(), V.end()), V.end());     for (int i = (0); i < (n); ++i)       a[i] = lower_bound(V.begin(), V.end(), a[i]) - V.begin();     for (int i = (0); i < (m); ++i) {       int l, r;       scanf( %d%d , &l, &r);       Q[i] = Node(l - 1, r - 1, i);     }     sort(Q, Q + m);     for (int i = (0); i < (m); ++i)       if (Q[i].r - Q[i].l + 1 <= B) {         ans[Q[i].id] = calc(Q[i].l, Q[i].r);       } else {         q[Q[i].l / B + (Q[i].l % B > 0)].push_back(i);       }     for (int i = (0); i < (B + 1); ++i) {       int j = 0, k = 0, cnt = 0;       for (j = B * i; j < n && k < ((int)(q[i]).size()); ++j) {         ++c[a[j]];         cnt += c[a[j]] == V[a[j]], cnt -= c[a[j]] == V[a[j]] + 1;         while (k < ((int)(q[i]).size()) && j == Q[q[i][k]].r) {           int tmp = cnt;           for (int r = (Q[q[i][k]].l); r < (B * i); ++r) {             ++c[a[r]];             tmp += c[a[r]] == V[a[r]], tmp -= c[a[r]] == V[a[r]] + 1;           }           for (int r = (Q[q[i][k]].l); r < (B * i); ++r) --c[a[r]];           ans[Q[q[i][k++]].id] = tmp;         }       }       for (int r = (B * i); r < (j); ++r) c[a[r]] = 0;     }     for (int i = (0); i < (m); ++i) printf( %d n , ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double pi = acos(-1);   const double eps = 1e-8;   const int maxn = 1e6 + 5;   const int maxm = 3e4 + 5;   const long long mod = 1e9 + 7;   const long long inf = 0x3f3f3f3f;   const int _inf = -1e9 + 7;   inline int scan() {     int m = 0;     char c = getchar();     while (c <  0  || c >  9 ) c = getchar();     while (c >=  0  && c <=  9 ) m = m * 10 + c -  0 , c = getchar();     return m;   }   int N, Q, S, M, K;   int num[200];   int dp[200][30000];   int main() {     cin >> N >> K >> S;     for (int i = 1; i <= N; i++) {       scanf( %d , num + i);     }     memset(dp, inf, sizeof dp);     dp[0][0] = 0;     for (int i = 1; i <= N; i++) {       for (int j = i - 1; j >= 0; j--) {         for (int k = i * j; k >= 0; k--) {           dp[j + 1][k + i - j - 1] =               min(dp[j + 1][k + i - j - 1], dp[j][k] + num[i]);         }       }     }     int ans = inf;     for (int i = 0; i <= min(S, N * N); i++) ans = min(ans, dp[K][i]);     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void read(int &x) {     register int c = getchar();     x = 0;     for (; c < 48 || c > 57; c = getchar())       ;     for (; c > 47 && c < 58; c = getchar()) x = (x << 1) + (x << 3) + c - 48;   }   queue<int> y[300005], v;   int main() {     int n, q, w = 0, x, z = 0, t = 0;     read(n);     read(q);     while (q--) {       read(x);       if (x == 1) {         read(x);         v.push(x);         y[x].push(t++);       } else if (x == 2) {         read(x);         z += y[x].size();         while (!y[x].empty()) y[x].pop();       } else {         read(x);         while (x > w) {           if (!y[v.front()].empty() && y[v.front()].front() < x) {             y[v.front()].pop();             z++;           }           ++w;           v.pop();         }       }       printf( %d n , t - z);     }   }


#include <bits/stdc++.h>   using namespace std;   struct P {     int x;     int a;   };   P data[105];   bool cmp(P x, P y) { return x.x < y.x; }   int main() {     int n;     int x, a;     int po = 0, ne = 0;     int res = 0;     scanf( %d , &n);     for (int i = 0; i < n; ++i) {       scanf( %d%d , &x, &a);       data[i].x = x;       data[i].a = a;       if (x < 0)         ++ne;       else         ++po;     }     sort(data, data + n, cmp);     if (ne > po) {       for (int i = n - 1; i >= n - po * 2 - 1; --i) {         res += data[i].a;       }     } else {       for (int i = 0; i < ne * 2 + 1; ++i) {         res += data[i].a;       }     }     printf( %d n , res);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int count = 0;   bool YES = false;   vector<string> record;   int compare(vector<string> cards, int pile1, int pile2) {     if (cards.at(pile1)[0] == cards.at(pile2)[0] ||         cards.at(pile1)[1] == cards.at(pile2)[1])       return 1;     return 0;   }   void move(vector<string> cards) {     int N = cards.size();     int end = N - 1;     if (N >= 4) {       if (compare(cards, end, end - 3)) {         string str =   ;         for (int k = 0; k < cards.size(); k++) {           str += cards.at(k);         }         for (int k = 0; k < record.size(); k++) {           if (str == record.at(k)) return;         }         record.push_back(str);         vector<string> cards_t = cards;         cards_t.at(end - 3) = cards_t.at(end);         cards_t.pop_back();         move(cards_t);         if (YES) return;       }       if (compare(cards, end, end - 1)) {         vector<string> cards_t = cards;         cards_t.at(end - 1) = cards_t.at(end);         cards_t.pop_back();         move(cards_t);         if (YES) return;       }     } else if (N > 1) {       if (compare(cards, end, end - 1)) {         vector<string> cards_t = cards;         cards_t.at(end - 1) = cards_t.at(end);         cards_t.pop_back();         move(cards_t);         if (YES) return;       }     } else if (N == 1) {       YES = true;       return;     }     return;   }   int main() {     vector<string> cards;     int t;     string card;     cin >> t;     for (int i = 0; i < t; i++) {       cin >> card;       cards.push_back(card);     }     move(cards);     if (YES)       cout <<  YES  << endl;     else       cout <<  NO  << endl;     return 0;   }


/* in the name of Anton */      /*     Compete against Yourself.     Author - Aryan (@aryanc403)     Atcoder library - https://atcoder.github.io/ac-library/production/document_en/   */      #include <algorithm>   #include <cassert>   #include <limits>   #include <queue>   #include <vector>         #include <algorithm>   #include <utility>   #include <vector>      namespace atcoder {   namespace internal {      template <class E> struct csr {       std::vector<int> start;       std::vector<E> elist;       csr(int n, const std::vector<std::pair<int, E>>& edges)           : start(n + 1), elist(edges.size()) {           for (auto e : edges) {               start[e.first + 1]++;           }           for (int i = 1; i <= n; i++) {               start[i] += start[i - 1];           }           auto counter = start;           for (auto e : edges) {               elist[counter[e.first]++] = e.second;           }       }   };      }  // namespace internal      }  // namespace atcoder         #include <vector>      namespace atcoder {      namespace internal {      template <class T> struct simple_queue {       std::vector<T> payload;       int pos = 0;       void reserve(int n) { payload.reserve(n); }       int size() const { return int(payload.size()) - pos; }       bool empty() const { return pos == int(payload.size()); }       void push(const T& t) { payload.push_back(t); }       T& front() { return payload[pos]; }       void clear() {           payload.clear();           pos = 0;       }       void pop() { pos++; }   };      }  // namespace internal      }  // namespace atcoder         namespace atcoder {      template <class Cap, class Cost> struct mcf_graph {     public:       mcf_graph() {}       mcf_graph(int n) : _n(n) {}          int add_edge(int from, int to, Cap cap, Cost cost) {           assert(0 <= from && from < _n);           assert(0 <= to && to < _n);           assert(0 <= cap);           assert(0 <= cost);           int m = int(_edges.size());           _edges.push_back({from, to, cap, 0, cost});           return m;       }          struct edge {           int from, to;           Cap cap, flow;           Cost cost;       };          edge get_edge(int i) {           int m = int(_edges.size());           assert(0 <= i && i < m);           return _edges[i];       }       std::vector<edge> edges() { return _edges; }          std::pair<Cap, Cost> flow(int s, int t) {           return flow(s, t, std::numeric_limits<Cap>::max());       }       std::pair<Cap, Cost> flow(int s, int t, Cap flow_limit) {           return slope(s, t, flow_limit).back();       }       std::vector<std::pair<Cap, Cost>> slope(int s, int t) {           return slope(s, t, std::numeric_limits<Cap>::max());       }       std::vector<std::pair<Cap, Cost>> slope(int s, int t, Cap flow_limit) {           assert(0 <= s && s < _n);           assert(0 <= t && t < _n);           assert(s != t);              int m = int(_edges.size());           std::vector<int> edge_idx(m);              auto g = [&]() {               std::vector<int> degree(_n), redge_idx(m);               std::vector<std::pair<int, _edge>> elist;               elist.reserve(2 * m);               for (int i = 0; i < m; i++) {                   auto e = _edges[i];                   edge_idx[i] = degree[e.from]++;                   redge_idx[i] = degree[e.to]++;                   elist.push_back({e.from, {e.to, -1, e.cap - e.flow, e.cost}});                   elist.push_back({e.to, {e.from, -1, e.flow, -e.cost}});               }               auto _g = internal::csr<_edge>(_n, elist);               for (int i = 0; i < m; i++) {                   auto e = _edges[i];                   edge_idx[i] += _g.start[e.from];                   redge_idx[i] += _g.start[e.to];                   _g.elist[edge_idx[i]].rev = redge_idx[i];                   _g.elist[redge_idx[i]].rev = edge_idx[i];               }               return _g;           }();              auto result = slope(g, s, t, flow_limit);              for (int i = 0; i < m; i++) {               auto e = g.elist[edge_idx[i]];               _edges[i].flow = _edges[i].cap - e.cap;           }              return result;       }        private:       int _n;       std::vector<edge> _edges;          struct _edge {           int to, rev;           Cap cap;           Cost cost;       };          std::vector<std::pair<Cap, Cost>> slope(internal::csr<_edge>& g,                                               int s,                                               int t,                                               Cap flow_limit) {              std::vector<std::pair<Cost, Cost>> dual_dist(_n);           std::vector<int> prev_e(_n);           std::vector<bool> vis(_n);           struct Q {               Cost key;               int to;               bool operator<(Q r) const { return key > r.key; }           };           std::vector<int> que_min;           std::vector<Q> que;           auto dual_ref = [&]() {               for (int i = 0; i < _n; i++) {                   dual_dist[i].second = std::numeric_limits<Cost>::max();               }               std::fill(vis.begin(), vis.end(), false);               que_min.clear();               que.clear();                  size_t heap_r = 0;                  dual_dist[s].second = 0;               que_min.push_back(s);               while (!que_min.empty() || !que.empty()) {                   int v;                   if (!que_min.empty()) {                       v = que_min.back();                       que_min.pop_back();                   } else {                       while (heap_r < que.size()) {                           heap_r++;                           std::push_heap(que.begin(), que.begin() + heap_r);                       }                       v = que.front().to;                       std::pop_heap(que.begin(), que.end());                       que.pop_back();                       heap_r--;                   }                   if (vis[v]) continue;                   vis[v] = true;                   if (v == t) break;                   Cost dual_v = dual_dist[v].first, dist_v = dual_dist[v].second;                   for (int i = g.start[v]; i < g.start[v + 1]; i++) {                       auto e = g.elist[i];                       if (!e.cap) continue;                       Cost cost = e.cost - dual_dist[e.to].first + dual_v;                       if (dual_dist[e.to].second - dist_v > cost) {                           Cost dist_to = dist_v + cost;                           dual_dist[e.to].second = dist_to;                           prev_e[e.to] = e.rev;                           if (dist_to == dist_v) {                               que_min.push_back(e.to);                           } else {                               que.push_back(Q{dist_to, e.to});                           }                       }                   }               }               if (!vis[t]) {                   return false;               }                  for (int v = 0; v < _n; v++) {                   if (!vis[v]) continue;                   dual_dist[v].first -= dual_dist[t].second - dual_dist[v].second;               }               return true;           };           Cap flow = 0;           Cost cost = 0, prev_cost_per_flow = -1;           std::vector<std::pair<Cap, Cost>> result = {{Cap(0), Cost(0)}};           while (flow < flow_limit) {               if (!dual_ref()) break;               Cap c = flow_limit - flow;               for (int v = t; v != s; v = g.elist[prev_e[v]].to) {                   c = std::min(c, g.elist[g.elist[prev_e[v]].rev].cap);               }               for (int v = t; v != s; v = g.elist[prev_e[v]].to) {                   auto& e = g.elist[prev_e[v]];                   e.cap += c;                   g.elist[e.rev].cap -= c;               }               Cost d = -dual_dist[s].first;               flow += c;               cost += c * d;               if (prev_cost_per_flow == d) {                   result.pop_back();               }               result.push_back({flow, cost});               prev_cost_per_flow = d;           }           return result;       }   };      }  // namespace atcoder         #ifdef ARYANC403       #include <header.h>   #else       #pragma GCC optimize ( Ofast )       #pragma GCC target ( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx )       #pragma GCC optimize ( -ffloat-store )       #include<bits/stdc++.h>       #define dbg(args...) 42;   #endif      using namespace std;   #define fo(i,n)   for(i=0;i<(n);++i)   #define repA(i,j,n)   for(i=(j);i<=(n);++i)   #define repD(i,j,n)   for(i=(j);i>=(n);--i)   #define all(x) begin(x), end(x)   #define sz(x) ((lli)(x).size())   #define pb push_back   #define mp make_pair   #define X first   #define Y second   #define endl   n       typedef long long int lli;   typedef long double mytype;   typedef pair<lli,lli> ii;   typedef vector<ii> vii;   typedef vector<lli> vi;         const auto start_time = std::chrono::high_resolution_clock::now();   void aryanc403()   {   #ifdef ARYANC403   auto end_time = std::chrono::high_resolution_clock::now();   std::chrono::duration<double> diff = end_time-start_time;       cerr<< Time Taken :  <<diff.count()<<  n ;   #endif   }      const lli INF = 0xFFFFFFFFFFFFFFFL;      lli seed;   mt19937 rng(seed=chrono::steady_clock::now().time_since_epoch().count());   inline lli rnd(lli l=0,lli r=INF)   {return uniform_int_distribution<lli>(l,r)(rng);}      class CMP   {public:   bool operator()(ii a , ii b) //For min priority_queue .   {    return ! ( a.X < b.X || ( a.X==b.X && a.Y <= b.Y ));   }};      void add( map<lli,lli> &m, lli x,lli cnt=1)   {       auto jt=m.find(x);       if(jt==m.end())         m.insert({x,cnt});       else                    jt->Y+=cnt;   }      void del( map<lli,lli> &m, lli x,lli cnt=1)   {       auto jt=m.find(x);       if(jt->Y<=cnt)            m.erase(jt);       else                      jt->Y-=cnt;   }      bool cmp(const ii &a,const ii &b)   {       return a.X<b.X||(a.X==b.X&&a.Y<b.Y);   }      const lli mod = 1000000007L;   // const lli maxN = 1000000007L;          lli T,n,i,j,k,in,cnt,l,r,u,v,x,y;       lli m;       string s;       vi a;       vii b;       //priority_queue < ii , vector < ii > , CMP > pq;// min priority_queue .      lli countPaths(vii edges){       const int inf=1e9;       atcoder::mcf_graph<lli,lli> g(2*n + 2);       for(int i=0;i<n;++i){           g.add_edge(2*n,i,1,0);           g.add_edge(i+n,2*n+1,1,0);       }       for(auto x:edges){           g.add_edge(x.X,n+x.Y,1,inf-1);       }       return n-g.flow(2*n,2*n+1).X;   }      lli removeOne(vii &edges,int curVal){       for(int i=0;i<n;++i){           vii ed;           for(auto x:edges){               if(x.Y==i)                   continue;               ed.pb(x);           }           if(curVal==countPaths(ed)){               edges.swap(ed);               return -(i+1);           }              ed.clear();           for(auto x:edges){               if(x.X==i)                   continue;               ed.pb(x);           }           if(curVal==countPaths(ed)){               edges.swap(ed);               return (i+1);           }       }       assert(false);   }      vi solve(vii edges,lli k){       vi answers(k+1,-INF);       dbg(countPaths(edges));       const int st=countPaths(edges);       for(int fw=st;fw<=k;++fw){           answers[fw]=removeOne(edges,fw+1);       }       return answers;   }      int main(void) {       ios_base::sync_with_stdio(false);cin.tie(NULL);       // freopen( txt.in ,  r , stdin);       // freopen( txt.out ,  w , stdout);   // cout<<std::fixed<<std::setprecision(35);   // cin>>T;while(T--)   {          cin>>n>>m>>k;       vii edges;       fo(i,m)       {           cin>>u>>v;           u--;v--;           edges.pb({u,v});       }          auto operations=solve(edges,k);       b.resize(k+1);       for(int i=1;i<=k;++i){           cin>>b[i].X>>b[i].Y;           b[i].Y=min(b[i].X,b[i].Y);       }          b[0]={INF,1e12};       lli curVal=-INF;       vector<vi> ansb(k+1);       auto getBest=[&](const lli rest){           vector<vi> before(k+1);           auto bb=b;              auto insert=[&](const int place,const int op){               before[place].pb(op);               bb[place].X-=bb[place].Y;               bb[place].X=max(bb[place].X,0LL);               bb[place].Y=min(bb[place].Y,bb[place].X);           };              for(int i=1;i<rest&&i<=k;++i){               if(operations[i]==-INF)                   continue;               const int op=operations[i];               int place=0;               for(int j=1;j<=i;++j){                   if(bb[place].Y>bb[j].Y)                       place=j;               }               insert(place,op);           }              for(int i=rest;i<=k;++i){               if(operations[i]==-INF)                   continue;               const int op=operations[i];               insert(rest,op);           }              lli cst=0;           for(int i=1;i<=k;++i)               cst+=bb[i].X;           dbg(bb,cst);           if(cst>curVal){               curVal=cst;               ansb.swap(before);           }       };       for(int rest=1;rest<=k+1;++rest){           getBest(rest);       }       dbg(curVal);       vi ans;       for(int i=1;i<=k;++i){           for(auto x:ansb[i])               ans.pb(x);           ans.pb(0);       }          cout<<sz(ans)<<endl;       for(auto x:ans)           cout<<x<<   ;       cout<<endl;   }   aryanc403();       return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, a[3005], ans;   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d , a + i);       for (int j = 0; j < i; j++) {         if (a[j] > a[i]) ans++;       }     }     if (ans % 2)       printf( %.6lf , (ans - 1) * 2.0 + 1);     else       printf( %.6lf , ans * 2.0);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int arr[100000 + 1];     int n, a;     set<int> s;     cin >> n;     vector<bool> vst(n, false);     for (int i = 0; i < n; ++i) {       cin >> a;       arr[i] = a;       s.insert(a);     }     int k = 1;     if (n != 1)       for (int i = 0; i < n; ++i) {         int j = arr[i];         if (!vst[j] && j <= n) {           vst[j] = 1;           cout << j <<    ;         } else {           while (s.count(k) || vst[k]) {             k++;           }           vst[k] = true;           cout << k <<    ;           k++;         }       }     else       cout <<  1 ;   }


#include <bits/stdc++.h>   using namespace std;   int perm[55];   int main() {     int n;     long long m;     scanf( %d%lld , &n, &m);     m--;     int l = 1;     int r = n;     for (long long i = n - 2; i >= 0; i--) {       if (m & (1LL << i)) {         perm[r] = n - 2 - i + 1;         r--;       } else {         perm[l] = n - 2 - i + 1;         l++;       }     }     perm[l] = n;     for (int i = 1; i <= n; i++) {       printf( %d  , perm[i]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   pair<long int, long int> p[500005];   bool cmp(pair<long int, long int> p1, pair<long int, long int> p2) {     if (p1.second < p2.second)       return true;     else {       if (p1.first < p2.first)         return true;       else         return false;     }   }   int main() {     int n;     int i, ans = 0, l;     cin >> n;     for (i = 0; i < n; i++) cin >> p[i].second >> p[i].first;     sort(p, p + n);     ans++;     l = p[0].first;     for (i = 1; i < n; i++) {       if (p[i].second > l) {         l = p[i].first;         ans++;       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> alz(string a) {     int n = a.size();     vector<int> res(n);     int left = 0, right = 0;     for (int k = 1; k < n; k++) {       if (right < k) {         right = left = k;         while (right < n && a[right] == a[right - left]) right++;         res[k] = right - left;         right--;       } else {         int k1 = k - left;         if (res[k1] < right - k + 1)           res[k] = res[k1];         else {           left = k;           while (right < n && a[right] == a[right - left]) right++;           res[k] = right - left;           right--;         }       }     }     return res;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     string ar[3];     cin >> ar[0] >> ar[1] >> ar[2];     int ta = ar[0].size() + ar[1].size() + ar[2].size();     int res = ta;     int a = ar[0].size(), b = ar[1].size(), c = ar[2].size();     string neo;     int per[] = {0, 1, 2};     vector<int> z;     do {       z = alz(ar[per[1]] +  $  + ar[per[0]]);       int mi = 0;       int ta = ar[per[1]].size() + 1 + ar[per[0]].size();       bool ins = false;       for (int i = ar[per[1]].size() + 1; i < ta; i++) {         if (z[i] == ar[per[1]].size()) {           ins = true;           break;         }         if (z[i] + i == ta) {           mi = z[i];           break;         }       }       if (ins)         neo = ar[per[0]];       else         neo = ar[per[0]].substr(0, ar[per[0]].size() - mi) + ar[per[1]];       ins = false;       z = alz(ar[per[2]] +  $  + neo);       ta = ar[per[2]].size() + 1 + neo.size();       mi = 0;       for (int i = ar[per[2]].size() + 1; i < ta; i++) {         if (z[i] == ar[per[2]].size()) {           ins = true;           break;         }         if (z[i] + i == ta) {           mi = z[i];           break;         }       }       if (ins) {         res = min(res, (int)neo.size());       } else         res = min(res, (int)neo.size() + (int)ar[per[2]].size() - mi);     } while (next_permutation(per, per + 3));     cout << res <<   n ;     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int t, n, x, m, z, u, v, f, a, b, l, r;     cin >> t;     while (t--) {       cin >> n >> x >> m;       a = x;       b = x;       for (int i = 0; i < m; i++) {         cin >> l >> r;         if (a >= l && a <= r && b >= l && b <= r) {           a = min(a, l);           b = max(b, r);         } else if (a >= l && a <= r && b >= r) {           a = min(a, l);           b = max(b, r);         } else if (a <= l && b >= l && b <= r) {           a = min(a, l);           b = max(b, r);         } else if (a == l || b == l || a == r || b == r) {           a = min(a, l);           b = max(b, r);         }       }       cout << b - a + 1 << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int x;     cin >> x;     int a[x], i;     for (i = 0; i < x; i++) {       cin >> a[i];     }     sort(a, a + x);     int s = 0;     int j = 0, m = 0;     for (i = 0; i < x; i++) {       while (j < x && a[j] - a[i] <= 5) {         j++;         s = max(s, j - i);       }     }     cout << s;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   vector<pair<char, long long> > s1;   vector<pair<char, long long> > s2;   vector<pair<char, long long> > p;   int sl, pl;   int lps[1000009];   vector<int> ii;   void calclps() {     lps[0] = 0;     int j = 0, i = 1;     while (i < pl) {       if (p[j] == p[i]) {         if (j == 0) {           lps[i] = 1;         } else {           lps[i] = j + 1;         }         j++;         i++;       } else {         if (j == 0) {           lps[i] = 0;           i++;         } else {           j = lps[j - 1];         }       }     }   }   void kmp() {     ii.clear();     if (p.size() == 1) {       for (int i = 0; i < (int)sl; i++) {         if (s1[i] == p[0]) ii.push_back(i);       }       return;     }     calclps();     int i = 0, j = 0;     while (i < sl) {       if (s1[i] == p[j]) {         if (j == pl - 1) {           ii.push_back(i - pl + 1);           j = lps[j - 1];         } else {           i++;           j++;         }       } else {         if (j == 0)           i++;         else           j = lps[j - 1];       }     }   }   void print(vector<pair<char, long long> > v) {     cout <<  printing :   << endl;     for (int i = 0; i < (int)v.size(); i++) {       cout << v[i].first <<     << v[i].second << endl;     }   }   int main() {     scanf( %d , &n);     scanf( %d , &m);     for (int i = 0; i < n; i++) {       long long a;       cin >> a;       getchar();       char c = getchar();       if (i != 0 && s1[s1.size() - 1].first == c) {         s1[s1.size() - 1].second += a;       } else {         s1.push_back(make_pair(c, a));       }     }     for (int i = 0; i < m; i++) {       long long a;       cin >> a;       getchar();       char c = getchar();       if (i != 0 && s2[s2.size() - 1].first == c) {         s2[s2.size() - 1].second += a;       } else {         s2.push_back(make_pair(c, a));       }     }     long long ans = 0;     if (s2.size() == 1) {       char c = s2[0].first;       long long v = s2[0].second;       for (int i = 0; i < (int)s1.size(); i++) {         if (c == s1[i].first && s1[i].second >= v) {           ans += s1[i].second - v + 1;         }       }     } else if (s2.size() == 2) {       char c1 = s2[0].first;       char c2 = s2[1].first;       long long v1 = s2[0].second;       long long v2 = s2[1].second;       for (int i = 1; i < (int)s1.size(); i++) {         if (s1[i - 1].first == c1 && s1[i].first == c2 &&             s1[i - 1].second >= v1 && s1[i].second >= v2)           ans++;       }     } else {       for (int i = 1; i < (int)s2.size() - 1; i++) {         p.push_back(s2[i]);       }       sl = s1.size();       pl = p.size();       kmp();       for (int i = 0; i < (int)ii.size(); i++) {         int x = ii[i];         if (x > 0 && x + pl < n && s1[x - 1].first == s2[0].first &&             s1[x - 1].second >= s2[0].second &&             s1[x + pl].first == s2[s2.size() - 1].first &&             s1[x + pl].second >= s2[s2.size() - 1].second)           ans++;       }     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9;   const int MOD = 1e9 + 7;   const long long INF64 = 1e18;   const long double EPS = 1e-7;   mt19937 myrand(time(NULL));   const int N = 100 * 1000 + 13;   int n, ac, d;   pair<int, int> a[N];   long double t[N];   bool read() {     if (scanf( %d%d%d , &n, &ac, &d) != 3) return 0;     for (int i = 0; i < (n); i++) scanf( %d%d , &a[i].first, &a[i].second);     return 1;   }   void solve() {     for (int i = 0; i < (n); i++) {       long double cur = a[i].second * 1.0 / ac;       t[i] = a[i].first;       if (cur * cur * ac / 2 > d - EPS)         t[i] += sqrtl(d * 2.0 / ac);       else         t[i] += cur + (d - cur * cur * ac / 2) / a[i].second;       if (i && t[i] < t[i - 1]) t[i] = t[i - 1];       printf( %.10f n , (double)t[i]);     }   }   int main() {     while (read()) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int maxint = ~0U >> 1;   int flow, cost;   int pi[200001 + 1], v[200001 + 1];   int S, T;   int INF = 1000000000;   int tempAdd = 100000;   struct etype {     int t, c;     etype* next;     etype* pair;     etype() { next = 0; }     etype(int _t, int _c, etype* _n) { t = _t, c = _c, next = _n; }   } * e[200001 + 1], *eb[200001 + 1], *Pe, *Pool;   int aug(int w, int lim) {     int t;     v[w] = 1;     if (w == T) {       flow += lim;       return lim;     }     for (etype*& i = e[w]; i; i = i->next)       if (i->c && !v[i->t] && pi[w] == pi[i->t] + 1)         if (t = aug(i->t, min(lim, i->c))) return i->c -= t, i->pair->c += t, t;     return 0;   }   bool fix() {     int t = maxint;     for (int i = S; i <= T; i++)       if (v[i]) {         for (etype* j = eb[i]; j; j = j->next)           if (j->c && !v[j->t]) t = min(t, pi[j->t] + 1 - pi[i]);       }     if (t == maxint) return 0;     for (int i = S; i <= T; i++)       if (v[i]) e[i] = eb[i], pi[i] += t;     return 1;   }   void addedge(int s, int t, int c) {     ++Pe;     Pe->t = t, Pe->c = c, Pe->next = e[s];     e[s] = Pe;     ++Pe;     Pe->t = s, Pe->c = 0, Pe->next = e[t];     e[t] = Pe;     e[s]->pair = e[t];     e[t]->pair = e[s];   }   void prepare() {     if (Pool == NULL) Pool = new etype[1000001];     Pe = Pool;     memset(e, 0, sizeof(e));   }   int MaxFlow() {     flow = 0, cost = 0;     memcpy(eb, e, sizeof(e));     memset(pi, 0, sizeof(pi));     do {       do memset(v, 0, sizeof(v));       while (aug(S, maxint));     } while (fix());     return flow;   }   int nDog, nPeople;   int oriSex[10001];   int g;   int dogNode(int x) { return 1 + x; }   int peopleNode(int x) { return 1 + 10000 + x; }   int MAIN() {     prepare();     S = 1, T = 1 + 10000 + 2000 + 1;     cin >> nDog >> nPeople >> g;     int ifAllGet = 0;     for (int i = 1; i <= nDog; i++) cin >> oriSex[i];     for (int i = 1; i <= nDog; i++) {       int t;       cin >> t;       addedge(S, dogNode(i), tempAdd);       addedge(dogNode(i), T, tempAdd);       if (oriSex[i] == 0)         addedge(dogNode(i), T, t);       else         addedge(S, dogNode(i), t);     }     for (int i = 1; i <= nPeople; i++) {       addedge(S, peopleNode(i), tempAdd);       addedge(peopleNode(i), T, tempAdd);       int wantSex, pay, needDog;       cin >> wantSex >> pay >> needDog;       ifAllGet += pay;       if (wantSex == 0)         addedge(peopleNode(i), T, pay);       else         addedge(S, peopleNode(i), pay);       for (int j = 1; j <= needDog; j++) {         int t;         cin >> t;         if (wantSex == 1)           addedge(peopleNode(i), dogNode(t), INF);         else           addedge(dogNode(t), peopleNode(i), INF);       }       int isFriend;       cin >> isFriend;       if (isFriend) {         if (wantSex == 0)           addedge(peopleNode(i), T, g);         else           addedge(S, peopleNode(i), g);       }     }     cout << ifAllGet - MaxFlow() + (nDog + nPeople) * tempAdd << endl;     return 0;   }   int main() {     ios ::sync_with_stdio(false);     cout << fixed << setprecision(16);     return MAIN();   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   bool inside(T a, T b, T c) {     return a <= b && b <= c;   }   long long modpower(long long x, long long n) {     long long m = 1000000007;     long long ans = 1;     x = (x + m) % m;     while (n > 0) {       if (n & 1) {         ans = (ans * x) % m;       }       n = n >> 1;       x = (x * x) % m;     }     return ans;   }   long long am(long long a, long long b) { return (a + b) % 1000000007; }   long long sm(long long a, long long b) {     return (a - b + 1000000007) % 1000000007;   }   long long mm(long long a, long long b) { return (a * b) % 1000000007; }   long long dm(long long a, long long b) {     return (a * modpower(b, 1000000007 - 2)) % 1000000007;   }   int main() {     ios_base::sync_with_stdio(false);     ;     cin.tie(NULL);     cout.tie(NULL);     ;     long long n;     cin >> n;     cout << sm(modpower(3, 3 * n), modpower(7, n)) <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 222222;   const int inf = 1e9 + 7;   vector<int> adj[MAXN], radj[MAXN];   int vis[MAXN], q[MAXN], qn, C;   int cost[MAXN], mn[MAXN], cnt[MAXN];   void dfs(int u) {     vis[u] = 1;     for (auto v : adj[u]) {       if (vis[v] == 1) continue;       dfs(v);     }     q[qn++] = u;   }   void rdfs(int u) {     vis[u] = C;     for (int i = 0; i < radj[u].size(); i++) {       int v = radj[u][i];       if (vis[v] == 0) rdfs(v);     }   }   void SCC(int n) {     for (int i = 1; i <= n; i++) vis[i] = 0;     qn = C = 0;     for (int i = 1; i <= n; i++) {       if (!vis[i]) {         dfs(i);       }     }     for (int i = 1; i <= n; i++) vis[i] = 0;     for (int i = qn - 1; i >= 0; i--) {       int cc = q[i];       if (!vis[cc]) {         C++;         rdfs(cc);       }     }   }   int main() {     int n, m, u, v;     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , cost + i);     scanf( %d , &m);     for (int i = 0; i < m; i++) {       scanf( %d%d , &u, &v);       adj[u].push_back(v);       radj[v].push_back(u);     }     SCC(n);     for (int i = 1; i <= C; i++) {       mn[i] = inf;       cnt[i] = 0;     }     for (int i = 1; i <= n; i++) {       int cc = vis[i];       if (mn[cc] == cost[i]) cnt[cc]++;       if (mn[cc] > cost[i]) mn[cc] = cost[i], cnt[cc] = 1;     }     long long ansc = 0, ansn = 1;     for (int i = 1; i <= C; i++) {       ansc += mn[i];       ansn = (1LL * ansn * cnt[i]) % inf;     }     printf( %lld %lld n , ansc, ansn);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = (2e5) + 10;   pair<int, int> ara[MAX];   int id[MAX];   vector<int> didi[MAX];   void solve() {     int n;     cin >> n;     for (int i = 0; i <= n - 1; i++) {       cin >> ara[i].first;     }     for (int i = 0; i <= n - 1; i++) {       cin >> ara[i].second;     }     sort(ara, ara + n, [](pair<int, int> x, pair<int, int> y) {       return (x.first == y.first) ? x.second > y.second : x.first < y.first;     });     int cp = -1;     priority_queue<int> que;     long long sum, prin;     sum = prin = 0;     for (int i = 0; i <= n - 1; i++) {       if (cp >= ara[i].first) {         que.push(ara[i].second);         sum += ara[i].second;       } else {         if (!que.empty()) {           sum -= que.top();           que.pop();           prin += sum;           cp++;           i--;         } else {           cp = ara[i].first;           i--;         }       }     }     while (!que.empty()) {       sum -= que.top();       que.pop();       prin += sum;     }     cout << prin << endl;   }   int main() {     ios::sync_with_stdio(false);     int tc;     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, m, num[200001], sum[200001], ans;   set<int> s;   int main() {     cin >> n >> m;     for (int i = 0; i < m; i++) s.insert(i);     for (int i = 0; i < n; i++) {       int d, tmp;       cin >> num[i];       d = num[i] % m;       if (d > *s.rbegin())         tmp = *s.begin();       else         tmp = *s.lower_bound(d);       sum[tmp]++;       if (sum[tmp] == n / m) s.erase(tmp);       int s = (tmp - d + m) % m;       ans += s;       num[i] += s;     }     cout << ans << endl;     for (int i = 0; i < n; i++) cout << num[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int m[100100];   vector<int> diff[100100];   int main() {     int n;     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> m[i];       diff[i - m[i]].push_back(i);     }     long long sum = 0;     int d = 0, tot = 1;     for (int i = 2; i <= n; i++) {       auto it = upper_bound(diff[d + 1].begin(), diff[d + 1].end(), i);       sum += tot - m[i];       if (it != diff[d + 1].end() || m[i] == tot)         tot++;       else {         d++;         sum--;       }     }     cout << sum << endl;     return 0;   }


#include <bits/stdc++.h>   int main() {     int a, b;     scanf( %d %d , &a, &b);     printf( %d , a * b / 2);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, i, j;     cin >> n;     set<int> row;     set<int> col;     map<int, int> row_map;     map<int, int> col_map;     for (i = 1; i <= n; i++) {       string s;       cin >> s;       for (j = 1; j <= n; j++) {         if (s[j - 1] ==  . ) {           row.insert(i);           col.insert(j);           row_map[i] = j;           col_map[j] = i;         }       }     }     if (row.size() == n) {       for (i = 1; i <= n; i++) {         cout << i <<     << row_map[i] << endl;       }     } else if (col.size() == n) {       for (j = 1; j <= n; j++) {         cout << col_map[j] <<     << j << endl;       }     } else       cout << -1 << endl;   }


#include <bits/stdc++.h>   using namespace std;   int n, a[200005], sum;   int main() {     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i], sum ^= a[i];     if (n % 2 == 0) {       if (sum) {         puts( NO );         return 0;       }       n--;     }     puts( YES );     printf( %d n , n - 1);     for (int i = 1; i <= n - 2; i += 2) printf( %d %d %d n , i, i + 1, i + 2);     for (int i = 1; i <= n - 2; i += 2) printf( %d %d %d n , i, i + 1, n);   }


#include  bits/stdc++.h       using namespace std;      typedef long long ll;   typedef long double ld;   typedef complex<ld> cd;      typedef pair<int, int> pi;   typedef pair<ll,ll> pl;   typedef pair<ld,ld> pd;      typedef vector<int> vi;   typedef vector<ld> vd;   typedef vector<ll> vl;   typedef vector<pi> vpi;   typedef vector<pl> vpl;   typedef vector<cd> vcd;      #define FOR(i, a, b) for (int i=a; i<(b); i++)   #define F0R(i, a) for (int i=0; i<(a); i++)   #define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)   #define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)   #define trav(a,x) for (auto& a : x)   #define uid(a, b) uniform_int_distribution<int>(a, b)(rng)      #define sz(x) (int)(x).size()   #define mp make_pair   #define pb push_back   #define f first   #define s second   #define lb lower_bound   #define ub upper_bound   #define all(x) x.begin(), x.end()   #define ins insert      template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }   template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }      mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());      const int MOD = 1000000007;   const char nl =   n ;   const int MX = 100001; //check the limits, dummy      int main() {       //freopen( input.txt ,  r , stdin);       ios_base::sync_with_stdio(0); cin.tie(0);          int T; cin >> T;       while(T--) {           int N; cin >> N;           vector<string> A(N); F0R(i, N) {               cin >> A[i];               //debug(A[i]);           }           bool good[N][N];           F0R(i, N) F0R(j, N) good[i][j] = false;           F0R(x, 10) {               F0R(i, N) {                   F0R(j, N) {                       if (A[i][j] -  0  == x) {                           good[i][j] = true; break;                       }                   }                   F0Rd(j, N) {                       if (A[i][j] -  0  == x) {                           good[i][j] = true; break;                       }                   }               }               F0R(j, N) {                   F0R(i, N) {                       if (A[i][j] -  0  == x) {                           good[i][j] = true; break;                       }                   }                   F0Rd(i, N) {                       if (A[i][j] -  0  == x) {                           good[i][j] = true; break;                       }                   }               }           }              vpi pos[10];           F0R(i, N) {               F0R(j, N) {                   if (good[i][j]) {                       int cur = A[i][j] -  0 ;                       //debug(cur, A[i][j]);                       pos[cur].pb({i, j});                   }                   //cout << good[i][j] <<    ;               }               //cout <<   n ;           }              F0R(x, 10) {               int ans = 0;               //debug(pos[x].size());               F0R(i, sz(pos[x])) {                   FOR(j, i+1, sz(pos[x])) {                       pi X = pos[x][i], Y = pos[x][j];                       //debug(X.f, X.s, Y.f, Y.s);                       if (X.f == Y.f) {                           ckmax(ans, abs(X.s - Y.s) * max(X.f, N-1-X.f));                       } else if (X.s == Y.s) {                           ckmax(ans, abs(X.f - Y.f) * max(X.s, N-1-X.s));                       } else {                           ckmax(ans, max(abs(X.s-Y.s)*max(max(X.f, Y.f), N-1-min(X.f, Y.f)), abs(X.f-Y.f)*max(max(X.s, Y.s), N-1-min(X.s, Y.s))));                       }                   }               }               cout << ans <<    ;           }           cout << nl;       }          return 0;   }      // read the question correctly (ll vs int)   // template by bqi343


#include <bits/stdc++.h>   using namespace std;   unsigned long long t1, t2, c1, c2, t0;   unsigned long long yy1 = 0, y2 = 0;   unsigned long long resyy1, resy2;   inline bool besser(unsigned long long res1, unsigned long long res2,                      unsigned long long res3, unsigned long long res4) {     return res1 * t1 * res4 + res2 * t2 * res3 <            res3 * t1 * res2 + res4 * t2 * res1;   }   inline bool eq(unsigned long long res1, unsigned long long res2,                  unsigned long long res3, unsigned long long res4) {     return res1 * t1 * res4 + res2 * t2 * res3 ==            res3 * t1 * res2 + res4 * t2 * res1;   }   int main() {     cin >> t1 >> t2 >> c1 >> c2 >> t0;     if (t1 == t2) {       cout << c1 <<     << c2 << endl;       return 0;     }     resyy1 = 0, resy2 = c2;     yy1 = 1;     while (yy1 <= c1) {       while (y2 <= c2 && (t1 * yy1 + t2 * y2 < t0 * (yy1 + y2))) y2++;       if (y2 > c2) break;       if ((t1 * yy1 + t2 * y2 < t0 * (yy1 + y2))) {         break;       } else {         if (besser(yy1, y2, resyy1, resy2)) {           resyy1 = yy1, resy2 = y2;           yy1++;           continue;         }         if (eq(yy1, y2, resyy1, resy2) && (yy1 + y2 > resyy1 + resy2)) {           resyy1 = yy1, resy2 = y2;           yy1++;           continue;         }       }       yy1++;     }     cout << resyy1 <<     << resy2 << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   const long long INF = 1e18;   const long double PI = 4 * atan((long double)1);   const int INFTY = 1e7;   template <unsigned int N>   class Field {     inline unsigned int pow(unsigned int a, unsigned int p) {       unsigned int r = 1, e = a;       while (p) {         if (p & 1) {           r = ((unsigned long long)r * e) % N;         }         e = ((unsigned long long)e * e) % N;         p >>= 1;       }       return r;     }     inline unsigned int inv(unsigned int a) { return pow(a, N - 2); }       public:     inline Field(int x = 0) : v(x) {}     inline Field<N> pow(int p) { return (*this) ^ p; }     inline Field<N> operator^(int p) { return {(int)pow(v, (unsigned int)p)}; }     inline Field<N> &operator+=(const Field<N> &o) {       if (v + o.v >= N)         v += o.v - N;       else         v += o.v;       return *this;     }     inline Field<N> &operator-=(const Field<N> &o) {       if (v < o.v)         v -= o.v - N;       else         v -= o.v;       return *this;     }     inline Field<N> &operator*=(const Field<N> &o) {       v = (unsigned long long)v * o.v % N;       return *this;     }     inline Field<N> &operator/=(const Field<N> &o) { return *this *= inv(o.v); }     inline Field<N> operator+(const Field<N> &o) const {       Field<N> r{*this};       return r += o;     }     inline Field<N> operator-(const Field<N> &o) const {       Field<N> r{*this};       return r -= o;     }     inline Field<N> operator*(const Field<N> &o) const {       Field<N> r{*this};       return r *= o;     }     inline Field<N> operator/(const Field<N> &o) const {       Field<N> r{*this};       return r /= o;     }     inline Field<N> operator-() {       if (v)         return {(int)(N - v)};       else         return {0};     };     inline Field<N> &operator++() {       ++v;       if (v == N) v = 0;       return *this;     }     inline Field<N> operator++(int) {       Field<N> r{*this};       ++*this;       return r;     }     inline Field<N> &operator--() {       --v;       if (v == -1) v = N - 1;       return *this;     }     inline Field<N> operator--(int) {       Field<N> r{*this};       --*this;       return r;     }     inline bool operator==(const Field<N> &o) const { return o.v == v; }     inline bool operator!=(const Field<N> &o) const { return o.v != v; }     inline explicit operator unsigned int() const { return v; }     inline static vector<Field<N>> fact(int t) {       vector<Field<N>> F(t + 1, 1);       for (int i = 2; i <= t; ++i) {         F[i] = F[i - 1] * i;       }       return F;     }     inline static vector<Field<N>> invfact(int t) {       vector<Field<N>> F(t + 1, 1);       Field<N> X{1};       for (int i = 2; i <= t; ++i) {         X = X * i;       }       F[t] = 1 / X;       for (int i = t - 1; i >= 2; --i) {         F[i] = F[i + 1] * (i + 1);       }       return F;     }       private:     unsigned int v;   };   template <unsigned int N>   istream &operator>>(std::istream &is, Field<N> &first) {     unsigned int v;     is >> v;     first = v;     return is;   }   template <unsigned int N>   ostream &operator<<(std::ostream &os, const Field<N> &first) {     return os << (unsigned int)first;   }   template <unsigned int N>   Field<N> operator+(int i, const Field<N> &first) {     return Field<N>(i) + first;   }   template <unsigned int N>   Field<N> operator-(int i, const Field<N> &first) {     return Field<N>(i) - first;   }   template <unsigned int N>   Field<N> operator*(int i, const Field<N> &first) {     return Field<N>(i) * first;   }   template <unsigned int N>   Field<N> operator/(int i, const Field<N> &first) {     return Field<N>(i) / first;   }   long long fact[200005];   long long MI[200005];   int main() {     ios::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     long long n, m;     cin >> n;     vector<pair<long long, long long>> a(2 * n);     for (int i = 0; i < (2 * n); i++) cin >> a[i].first, a[i].second = i % n;     sort(a.begin(), a.end());     cin >> m;     fact[0] = fact[1] = 1;     for (int i = 2; i <= 200000; ++i) fact[i] = (1ll * fact[i - 1] * i) % m;     MI[0] = 1;     MI[1] = (m + 1) / 2;     for (int i = 2; i <= 200000; ++i) MI[i] = (MI[i - 1] * MI[1]) % m;     int i = 0;     long long ans = 1;     while (i < 2 * n) {       int j = i, c = 0;       while (j < 2 * n && a[i].first == a[j].first) {         if (j > i && a[j].second == a[j - 1].second) {           c++;         }         j++;       }       for (int x = 1; x <= j - i; x++) {         int y = x;         while (y % 2 == 0 && c > 0) {           y /= 2;           c--;         }         ans = (ans * y) % m;       }       i = j;     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-6;   double r;   int main() {     scanf( %lf , &r);     for (int a = 1; a <= 10; ++a) {       for (int h = 1; h <= 10; ++h) {         double area = (a / 2.0 * h);         double bot = sqrt(a * a / 4.0 + h * h);         double tmp = area / bot;         if (fabs(tmp - r) < eps) {           printf( %d %d n , a, h);           return 0;         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   long long modpow(long long a, long long p, long long mod) {     long long ret = 1;     while (p) {       if (p & 1) ret = (ret * a) % mod;       a = (a * a) % mod;       p /= 2;     }     return ret;   }   long long power(long long a, long long p) {     long long ret = 1;     while (p) {       if (p & 1) ret = (ret * a);       a = (a * a);       p /= 2;     }     return ret;   }   int compare(const void* a, const void* b) { return (*(int*)a - *(int*)b); }   int main() {     int i, j, k, tmp;     ios_base::sync_with_stdio(0);     cin.tie(NULL);     int n, m;     cin >> n >> m;     vector<pair<int, int> > f(n);     vector<int> b(m);     vector<int> f1(n);     int fch[100010] = {0};     int fin[100010] = {0};     for (i = 0; i < n; i++) {       cin >> j;       f[i] = make_pair(j, i);       f1[i] = j;       fch[j] += 1;       fin[j] = i;     }     for (i = 0; i < m; i++) {       cin >> b[i];     }     vector<int> a(m);     int flam = 0;     int flim = 0;     for (i = 0; i < m; i++) {       if (fch[b[i]] == 0) {         flim = 1;       }       if (fch[b[i]] > 1) {         flam = 1;       }       a[i] = fin[b[i]] + 1;     }     if (flim == 1) {       cout <<  Impossible  << endl;       return 0;     }     if (flam == 1) {       cout <<  Ambiguity  << endl;       return 0;     }     cout <<  Possible  << endl;     for (i = 0; i < m; i++) cout << a[i] <<    ;     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 501010;   int n, k;   int a[maxn], b[maxn];   long long s;   int cnt;   priority_queue<pair<int, int> > q;   void Check(int d) {     s = 0;     cnt = 0;     for (int i = 1; i <= n; ++i) {       q.push(make_pair(d - a[i], 0));       int tmp = b[i] - q.top().first;       if (tmp < 0) {         s += tmp;         if (!q.top().second) ++cnt;         q.pop();         q.push(make_pair(b[i], 1));       }     }     while (q.size()) q.pop();   }   int main() {     scanf( %d%d , &n, &k);     for (int i = 1; i <= n; ++i) scanf( %d , a + i);     for (int i = 1; i <= n; ++i) scanf( %d , b + i);     long long l = 0, r = 2e9, mid;     while (l < r) {       mid = (l + r) >> 1;       Check(mid);       if (cnt < k)         l = mid + 1;       else         r = mid;     }     Check(l);     printf( %lld n , s + 1ll * l * k);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int power(long long int x, long long int y, long long int p) {     long long int res = 1;     x = x % p;     while (y > 0) {       if (y & 1) res = (res * x) % p;       y = y / 2;       x = (x * x) % p;     }     return res;   }   void solve() {     long long int n, m, l, h, i;     cin >> n >> m;     l = 0;     h = n * m - 1;     while (l < h) {       cout << l / m + 1 <<     << l % m + 1 <<   n ;       cout << h / m + 1 <<     << h % m + 1 <<   n ;       ++l, --h;     }     if (l == h) cout << l / m + 1 <<     << l % m + 1 <<   n ;   }   int main() {     long long int t = 1;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void read_file(bool outToFile = true) {}   int n, m;   bool vis[500 + 9][500 + 9];   string s;   int l;   int x, y;   int ans[100000 + 1 + 9];   string alpha =  *URDL ;   int dij[5][2] = {{0, 0}, {-1, 0}, {0, +1}, {+1, 0}, {0, -1}};   bool valid(int i, int j) { return 0 <= i && i < n && 0 <= j && j < m; }   int main() {     read_file();     while (scanf( %d%d , &n, &m) != EOF) {       scanf( %d%d , &x, &y);       x--, y--;       memset(vis, 0, sizeof vis);       cin >> s;       s =  *  + s;       l = s.length();       for (int i = 0; i < l - 1; i++) {         int nx, ny;         nx = x + dij[alpha.find(s[i])][0];         ny = y + dij[alpha.find(s[i])][1];         if (!valid(nx, ny)) {           ans[i] = 0;           continue;         }         x = nx, y = ny;         if (!vis[x][y]) {           vis[x][y] = 1;           ans[i] = 1;         } else           ans[i] = 0;       }       int cnt = n * m;       for (int i = 0; i < n; i++)         for (int j = 0; j < m; j++) cnt -= vis[i][j];       ans[l - 1] = cnt;       for (int i = 0; i < l; i++) printf( %d%c , ans[i],    n [i == l - 1]);     }   }


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


#include <bits/stdc++.h>   template <typename T>   inline void read(T& x) {     T res = 0, flag = 1;     char ch;     ch = getchar();     while (!isdigit(ch)) {       if (ch ==  - ) flag = -1;       ch = getchar();     }     while (isdigit(ch)) {       res = res * 10 + ch - 48;       ch = getchar();     }     x = res * flag;   }   const long long INF = 1LL << 32;   int l;   long long ans, x;   char buf[10];   std::stack<long long> s;   int main() {     read(l);     s.push(1);     for (int i = 1; i <= l; ++i) {       scanf( %s , buf);       if (buf[0] ==  a )         ans += s.top();       else if (buf[0] ==  e )         s.pop();       else {         read(x);         s.push(std::min(INF, x * s.top()));       }     }     if (ans >= INF)       puts( OVERFLOW!!! );     else       printf( %lld n , ans);   }


#include <bits/stdc++.h>   using namespace std;   long long powmod(long long base, long long exponent, long long mod) {     long long result = 1;     while (exponent > 0) {       if (exponent % 2 == 0) {         exponent /= 2;         base = (base * base) % mod;       } else {         result = (result * base) % mod;         exponent /= 2;         base = (base * base) % mod;       }     }     return result;   }   bool decresing(long long x, long long y) { return x > y; }   long long trin(long long start, long long stop) {     return (stop - start + 1) * (stop + start) / 2;   }   bool sortvectorf(pair<long long, long long> a, pair<long long, long long> b) {     return ((a.first > b.first) || (a.first == b.first && a.second > b.second));   }   bool sortvectorfv(pair<long long, long long> a, pair<long long, long long> b) {     return ((a.first > b.first) || (a.first == b.first && a.second < b.second));   }   bool sortvectors(pair<long long, long long> a, pair<long long, long long> b) {     return ((a.second > b.second) || (a.second == b.second && a.first > b.first));   }   bool negasortvectorf(pair<long long, long long> a,                        pair<long long, long long> b) {     return ((a.first < b.first) || (a.first == b.first && a.second < b.second));   }   bool negasortvectors(pair<long long, long long> a,                        pair<long long, long long> b) {     return ((a.second < b.second) || (a.second == b.second && a.first < b.first));   }   vector<vector<long long>> findPermutations(vector<long long> &a) {     sort(a.begin(), a.end());     vector<vector<long long>> sol;     do {       sol.push_back(a);     } while (next_permutation(a.begin(), a.end()));     return sol;   }   long long gcd(long long a, long long b) {     if (a == 0) {       return b;     }     if (b == 0) {       return a;     }     return gcd(b % a, a);   }   bool isprime(long long n) {     for (int i = 2; i < n; i += 1) {       if (i * i > n) {         break;       }       if ((n / i) * i == n) {         return false;       }     }     return true;   }   long long fdivisor(long long n, long long fro) {     for (int i = 1; i < n + 1; i += 1) {       if ((n / i) * i == n && i >= fro) {         return i;       }     }     return -1;   }   vector<long long> divlist(long long n) {     vector<long long> curr;     for (int i = 2; i < n; i += 1) {       if ((long long)i * i > n) {         break;       }       if ((n / i) * i == n) {         curr.push_back(i);         curr.push_back(n / i);       }       if ((long long)i * i == n) {         curr.pop_back();       }     }     sort(curr.begin(), curr.end());     return curr;   }   long long digsum(long long num) {     long long cr = 0;     while (num > 0) {       cr += num % 10;       num /= 10;     }     return cr;   }   long long modInverse(long long a, long long b) {     long long m = b;     long long y = 0, x = 1;     while (a > 1) {       long long q = a / m;       long long t = m;       m = a % m, a = t;       t = y;       y = x - q * y;       x = t;     }     if (x < 0) {       x += b;     }     return x;   }   long long azeret(long long num, long long mod) {     long long sil = 1;     while (num > 1) {       sil *= num;       sil %= mod;       num--;     }     return sil;   }   long long moddiv(long long to, long long by, long long mod) {     to %= mod;     while (to % by != 0) {       to += mod;       if (to > (by + 1) * mod) {         return -1;       }     }     return (to / by) % mod;   }   pair<long long, long long> func(pair<long long, long long> a,                                   pair<long long, long long> b) {     if (a.first < b.first) {       return a;     }     if (b.first < a.first) {       return b;     }     return {a.first, (a.second + b.second) % 1000000007};   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long n;     cin >> n;     vector<pair<long long, long long>> matrioskas(n);     set<long long> alls;     for (int i = 0; i < n; i += 1) {       cin >> matrioskas[i].second >> matrioskas[i].first;       alls.insert(matrioskas[i].first);       alls.insert(matrioskas[i].second);     }     alls.insert(0);     sort(matrioskas.begin(), matrioskas.end(), negasortvectorf);     vector<long long> ral;     for (auto it = alls.begin(); it != alls.end(); it++) {       ral.push_back(*it);     }     long long siz = ral.size();     vector<vector<long long>> cons(siz);     vector<pair<long long, long long>> pts(siz,                                            {999999999999999, 99999999999999});     pts[0] = {0, 1};     for (int i = 0; i < n; i += 1) {       long long left, right, mid;       left = 0;       right = siz - 1;       while (right > left) {         mid = (right + left + 1) / 2;         if (ral[mid] > matrioskas[i].first) {           right = mid - 1;         } else {           left = mid;         }       }       long long inpart = left;       left = 0;       right = siz - 1;       while (right > left) {         mid = (right + left + 1) / 2;         if (ral[mid] > matrioskas[i].second) {           right = mid - 1;         } else {           left = mid;         }       }       long long outpart = left;       cons[inpart].push_back(outpart);     }     for (int i = 1; i < siz; i += 1) {       pair<long long, long long> ptt = pts[i - 1];       ptt.first += ral[i] - ral[i - 1];       pts[i] = func(pts[i], ptt);       for (int ii = 0; ii < cons[i].size(); ii += 1) {         pts[cons[i][ii]] = func(pts[i], pts[cons[i][ii]]);       }     }     pair<long long, long long> ans = {999999999999999, 99999999999999};     for (int i = siz - 1; i >= 0; i += -1) {       if (cons[i].size() > 0) {         break;       }       ans = func(ans, pts[i]);     }     cout << ans.second << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, x;   vector<int> v[1005], a[1005];   int main() {     ios::sync_with_stdio(false);     cin >> n;     for (int i = 1; i <= n; ++i) {       cin >> x;       a[x].push_back(i);       v[i].resize(n + 1, 0);     }     int st = -1;     for (int i = n; i >= 1; --i) {       for (int k : a[i]) {         st++;         int cur = st;         for (int j = 1; j <= i; ++j) {           v[k][cur] = 1;           cur++;           cur %= (n + 1);         }       }     }     cout << n + 1 <<   n ;     for (int i = 0; i < n + 1; ++i) {       for (int j = 1; j <= n; ++j) cout << v[j][i];       cout <<   n ;     }     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   class solution {    public:     void solve() {       int n;       cin >> n;       int i = 1;       int prev = 0;       vector<int> sol;       while (n != 0) {         if (n > prev) {           prev++;           sol.push_back(prev);           n = n - prev;         } else {           sol[prev - 1] = sol[prev - 1] + n;           n = 0;         }       }       cout << sol.size() <<   n ;       for (auto it : sol) {         cout << it <<    ;       }     }   };   int main() {     ios::sync_with_stdio(0), cout.tie(0), cin.tie(0);     long long i = 0;     solution second;     second.solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6 + 10;   const long long mod = 1e9 + 7;   long long n, m;   long long fac[maxn];   long long ksm(long long a, long long b) {     long long ans = 1, base = a % mod;     while (b) {       if (b & 1) ans = ans * base % mod;       base = base * base % mod;       b >>= 1;     }     return ans % mod;   }   long long C(int x, int y) {     return fac[x] * ksm(fac[y] * fac[x - y] % mod, mod - 2) % mod;   }   int main() {     cin >> n >> m;     fac[0] = 1;     for (int i = 1; i <= m * 2 + n + 1; ++i) fac[i] = fac[i - 1] * i % mod;     cout << C(n + m * 2 - 1, n - 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main(int argc, char *argv[]) {     int n;     unsigned int a[200];     unsigned int ans;     scanf( %d , &n);     ans = 0;     for (int i = 0; i < n; i++) scanf( %u , &a[i]);     for (int i = 0; i < n; i++) {       unsigned int temp = a[i];       if (temp > ans) ans = temp;       for (int j = i + 1; j < n; j++) {         temp = temp ^ a[j];         if (temp > ans) ans = temp;       }     }     printf( %u n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void result() {}   string resultstr() {     string ans;     return ans;   }   int resultint() {     int ans;     return ans;   }   long long resultlong(long long n) {     long long c5;     return c5;   }   bool checkValidity(long long a, long long b, long long c) {     if (a + b <= c || a + c <= b || b + c <= a)       return false;     else       return true;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     int t;     cin >> t;     while (t--) {       long long cnt = 0;       string s;       vector<long long> v;       cin >> s;       for (int i = 0; i < s.length(); i++) {         if (s.at(i) ==  1 ) {           cnt++;         } else if (s.at(i) ==  0 ) {           v.push_back(cnt);           cnt = 0;         }       }       v.push_back(cnt);       sort(v.begin(), v.end(), greater<int>());       ;       long long sum = 0;       for (int i = 0; i < v.size(); i = i + 2) {         sum += v[i];       }       cout << sum <<   n ;     }   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   #pragma GCC optimize( unroll-loops )   using namespace std;   constexpr long long mod = 998244353;   const long long INF = mod * mod;   const long double eps = 1e-12;   const long double pi = acosl(-1.0);   long long mod_pow(long long x, long long n, long long m = mod) {     if (n < 0) {       long long res = mod_pow(x, -n, m);       return mod_pow(res, m - 2, m);     }     if (abs(x) >= m) x %= m;     if (x < 0) x += m;     long long res = 1;     while (n) {       if (n & 1) res = res * x % m;       x = x * x % m;       n >>= 1;     }     return res;   }   struct modint {     long long n;     modint() : n(0) { ; }     modint(long long m) : n(m) {       if (n >= mod)         n %= mod;       else if (n < 0)         n = (n % mod + mod) % mod;     }     operator int() { return n; }   };   bool operator==(modint a, modint b) { return a.n == b.n; }   modint operator+=(modint& a, modint b) {     a.n += b.n;     if (a.n >= mod) a.n -= mod;     return a;   }   modint operator-=(modint& a, modint b) {     a.n -= b.n;     if (a.n < 0) a.n += mod;     return a;   }   modint operator*=(modint& a, modint b) {     a.n = ((long long)a.n * b.n) % mod;     return a;   }   modint operator+(modint a, modint b) { return a += b; }   modint operator-(modint a, modint b) { return a -= b; }   modint operator*(modint a, modint b) { return a *= b; }   modint operator^(modint a, long long n) {     if (n == 0) return modint(1);     modint res = (a * a) ^ (n / 2);     if (n % 2) res = res * a;     return res;   }   long long inv(long long a, long long p) {     return (a == 1 ? 1 : (1 - p * inv(p % a, a)) / a + p);   }   modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }   modint operator/=(modint& a, modint b) {     a = a / b;     return a;   }   const int max_n = 1 << 18;   modint fact[max_n], factinv[max_n];   void init_f() {     fact[0] = modint(1);     for (int i = 0; i < max_n - 1; i++) {       fact[i + 1] = fact[i] * modint(i + 1);     }     factinv[max_n - 1] = modint(1) / fact[max_n - 1];     for (int i = max_n - 2; i >= 0; i--) {       factinv[i] = factinv[i + 1] * modint(i + 1);     }   }   modint comb(int a, int b) {     if (a < 0 || b < 0 || a < b) return 0;     return fact[a] * factinv[b] * factinv[a - b];   }   modint combP(int a, int b) {     if (a < 0 || b < 0 || a < b) return 0;     return fact[a] * factinv[a - b];   }   struct uf {    private:     vector<int> par, ran;       public:     uf(int n) {       par.resize(n, 0);       ran.resize(n, 0);       for (int i = 0; i < n; i++) {         par[i] = i;       }     }     int find(int x) {       if (par[x] == x)         return x;       else         return par[x] = find(par[x]);     }     void unite(int x, int y) {       x = find(x), y = find(y);       if (x == y) return;       if (ran[x] < ran[y]) {         par[x] = y;       } else {         par[y] = x;         if (ran[x] == ran[y]) ran[x]++;       }     }     bool same(int x, int y) { return find(x) == find(y); }   };   const int mn = 1000005;   vector<int> ps;   vector<int> chp[mn];   bool isp[mn];   void init() {     fill(isp + 2, isp + mn, true);     for (int i = 2; i < mn; i++) {       if (!isp[i]) continue;       ps.push_back(i);       chp[i].push_back(i);       for (int j = 2 * i; j < mn; j += i) {         isp[j] = false;         chp[j].push_back(i);       }     }   }   void solve() {     int n, q;     cin >> n >> q;     vector<int> a(n);     for (int i = 0; i < n; i++) cin >> a[i];     vector<int> trans(mn);     for (int i = 0; i < ps.size(); i++) trans[ps[i]] = i;     uf u(ps.size());     for (int i = 0; i < n; i++) {       int pre = -1;       for (int j = 0; j < chp[a[i]].size(); j++) {         int id = trans[chp[a[i]][j]];         if (pre >= 0) {           u.unite(id, pre);         }         pre = id;       }     }     vector<unordered_map<int, int>> mp(ps.size());     for (int i = 0; i < n; i++) {       vector<int> ids;       ids.push_back(u.find(trans[chp[a[i]][0]]));       for (int p : chp[a[i] + 1]) {         int id = trans[p];         id = u.find(id);         ids.push_back(id);       }       for (int j = 0; j < ids.size(); j++)         for (int k = j + 1; k < ids.size(); k++) {           int a = ids[j];           int b = ids[k];           if (a == b) continue;           if (a > b) swap(a, b);           mp[a][b] = true;         }     }     for (int i = 0; i < q; i++) {       int s, t;       cin >> s >> t;       s--;       t--;       s = trans[chp[a[s]][0]];       t = trans[chp[a[t]][0]];       s = u.find(s);       t = u.find(t);       if (s == t) {         cout << 0 <<   n ;       } else {         if (s > t) swap(s, t);         if (mp[s][t]) {           cout << 1 <<   n ;         } else {           cout << 2 <<   n ;         }       }     }   }   signed main() {     ios::sync_with_stdio(false);     cin.tie(0);     init();     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int i, j, n, k, s, min, max;     cin >> n >> k;     if (k % n)       cout << k / n + 1;     else       cout << k / n;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main(void) {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t;     cin >> t;     while (t--) {       long long n;       cin >> n;       cout << (n / 2) + 1 <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long mul(long long a, long long b, long long p = 1000000007) {     return ((a % p) * (b % p)) % p;   }   long long add(long long a, long long b, long long p = 1000000007) {     return (a % p + b % p) % p;   }   void input(long long a[], long long sz) {     for (long long i = 0; i < sz; i++) cin >> a[i];   }   void print(long long a[], long long sz) {     for (long long i = 0; i < sz; i++) {       if (i == sz - 1)         cout << a[i] <<   n ;       else         cout << a[i] <<    ;     }   }   long long maxr(long long a[], long long sz) {     long long ma;     for (long long i = 0; i < sz; i++) {       if (i == 0)         ma = a[i];       else if (a[i] > ma)         ma = a[i];     }     return ma;   }   long long minr(long long a[], long long sz) {     long long mi;     for (long long i = 0; i < sz; i++) {       if (i == 0)         mi = a[i];       else if (a[i] < mi)         mi = a[i];     }     return mi;   }   long long isprm(long long n) {     if (n <= 1) return 0;     if (n <= 3) return 1;     if (n % 2 == 0 || n % 3 == 0) return 0;     for (int i = 5; i * i <= n; i = i + 6)       if (n % i == 0 || n % (i + 2) == 0) return 0;     return 1;   }   long long power(long long x, long long y, long long p = 1000000007) {     long long res = 1;     x = x % p;     while (y > 0) {       if (y & 1) res = (res * x) % p;       y = y >> 1;       x = (x * x) % p;     }     return res;   }   long long modInverse(long long n, long long p = 1000000007) {     return power(n, p - 2, p);   }   long long ncrMod(long long n, long long r, long long p = 1000000007) {     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;   }   struct comp {     bool operator()(const pair<long long, long long> &a,                     const pair<long long, long long> &b) const {       if (a.first == b.first) {         return (a.second > b.second);       }       return (a.first < b.first);     }   };   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     int t;     cin >> t;     while (t--) {       long long n, q;       cin >> n >> q;       long long a[n + 5];       input(a, n);       if (n == 1) {         cout << a[0] <<   n ;         for (long long i = 0; i < q; i++) {           long long l, r;           cin >> l >> r;           cout << a[0] <<   n ;         }         continue;       }       map<long long, long long> mp;       long long ans = 0;       long long k = 0;       for (long long i = 0; i < n; i++) {         if (k % 2 == 0) {           if ((i - 1) >= 0 && (i + 1) < n && a[i] > a[i - 1] && a[i] > a[i + 1]) {             ans += a[i];             mp[i] = 1;             k++;           } else if ((i - 1) < 0 && a[i] > a[i + 1]) {             ans += a[i];             mp[i] = 1;             k++;           } else if ((i + 1) >= n && a[i] > a[i - 1]) {             ans += a[i];             mp[i] = 1;             k++;           }         } else {           if ((i - 1) >= 0 && (i + 1) < n && a[i] < a[i - 1] && a[i] < a[i + 1]) {             ans -= a[i];             mp[i] = -1;             k++;           }         }       }       if (k % 2 == 0) {         auto it = mp.end();         it--;         long long i = (*it).first;         ans += a[i];         mp.erase(it);       }       cout << ans <<   n ;       for (long long i = 0; i < q; i++) {         long long l, r;         cin >> l >> r;         l--;         r--;         long long x = max(l - 1, (long long)0);         long long y = min(l + 1, n - 1);         for (long long i = x; i < y + 1; i++) {           if (mp[i] == 1)             ans -= a[i];           else if (mp[i] == -1)             ans += a[i];           else             mp.erase(i);         }         x = max(r - 1, y + 1);         y = min(r + 1, n - 1);         for (long long i = x; i < y + 1; i++) {           if (mp[i] == 1)             ans -= a[i];           else if (mp[i] == -1)             ans += a[i];           else             mp.erase(i);         }         long long t = a[l];         a[l] = a[r];         a[r] = t;         x = max(l - 1, (long long)0);         y = min(l + 1, n - 1);         long long h;         auto it = mp.lower_bound(x);         if (it == mp.end()) {           it--;           h = (*it).second;           if (h == 1)             h = -1;           else             h = 1;         } else {           h = (*it).second;         }         for (long long i = x; i < y + 1; i++) {           if (h == 1) {             if ((i - 1) >= 0 && (i + 1) < n && a[i] > a[i - 1] &&                 a[i] > a[i + 1]) {               ans += a[i];               mp[i] = 1;               h = -1;             } else if ((i - 1) < 0 && a[i] > a[i + 1]) {               ans += a[i];               mp[i] = 1;               h = -1;             } else if ((i + 1) >= n && a[i] > a[i - 1]) {               ans += a[i];               mp[i] = 1;               h = -1;             } else               mp.erase(i);           } else {             if ((i - 1) >= 0 && (i + 1) < n && a[i] < a[i - 1] &&                 a[i] < a[i + 1]) {               ans -= a[i];               mp[i] = -1;               h = 1;             } else               mp.erase(i);           }         }         x = max(r - 1, y + 1);         y = min(r + 1, n - 1);         auto it2 = mp.lower_bound(x);         if (it2 == mp.begin()) {           h = 1;         } else {           it2--;           h = (*it2).second;           if (h == 1)             h = -1;           else             h = 1;         }         for (long long i = x; i < y + 1; i++) {           if (h == 1) {             if ((i - 1) >= 0 && (i + 1) < n && a[i] > a[i - 1] &&                 a[i] > a[i + 1]) {               ans += a[i];               mp[i] = 1;               h = -1;             } else if ((i - 1) < 0 && a[i] > a[i + 1]) {               ans += a[i];               mp[i] = 1;               h = -1;             } else if ((i + 1) >= n && a[i] > a[i - 1]) {               ans += a[i];               mp[i] = 1;               h = -1;             } else               mp.erase(i);           } else {             if ((i - 1) >= 0 && (i + 1) < n && a[i] < a[i - 1] &&                 a[i] < a[i + 1]) {               ans -= a[i];               mp[i] = -1;               h = 1;             } else               mp.erase(i);           }         }         if (mp.size() % 2 == 0 && mp.size() > 0) {           auto it = mp.end();           it--;           long long i = (*it).first;           ans += a[i];           mp.erase(it);         }         cout << ans <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int C = 500001;   vector<vector<int> > gr(C), E(C);   int ij[C], ji[C], a, b, n, m;   int s[C], sE[C], low[C], pre[C], nV[C], nE[C], par[C], cor[C], corn;   bool ch[C], chE[C];   int main() {     int i, j, is = 1, iE = 0, iV = 1, ip = 2, k, e, vn, en;     scanf( %d %d , &n, &m);     for (int z = 0; z < m; z++)       scanf( %d %d , &a, &b), gr[a].push_back(b), gr[b].push_back(a),           E[a].push_back(z), E[b].push_back(z), ij[a]++, ij[b]++;     for (i = 1; i <= n; i++) ji[i] = ij[i];     for (j = 1; j <= n; j++) {       if (ch[j] == 0) {         s[0] = j, ch[j] = 1;         low[j] = pre[j] = 1, iV = 1, iE = 0, ip = 2, is = 1;         while (is > 0) {           a = s[is - 1];           if (ij[a] > 0) k = gr[a][ij[a] - 1], e = E[a][ij[a] - 1];           if (ij[a] > 0 && ch[gr[a][ij[a] - 1]] == 1) {             if (chE[e] == 0) {               chE[e] = 1;               sE[iE] = e, iE++;             }             if (k != par[a]) low[a] = min(low[a], pre[k]);             ij[a]--;           } else if (ij[a] > 0 && ch[gr[a][ij[a] - 1]] == 0) {             ch[k] = 1, chE[e] = 1;             par[k] = a;             nV[k] = iV, nE[k] = iE, iV++;             sE[iE] = e, iE++;             s[is] = k, low[k] = pre[k] = ip, is++, ip++;             ij[a]--;           } else {             if (low[par[a]] > low[a]) low[par[a]] = low[a];             if (low[a] >= pre[par[a]]) {               vn = iV - nV[a] + 1, en = iE - nE[a];               if (en == vn) {                 for (i = nE[a]; i < iE; i++) cor[sE[i]] = 1, corn++;               }               iV = nV[a], iE = nE[a];             }             is--;           }         }       }     }     printf( %d n , corn);     for (i = 0; i < m; i++)       if (cor[i] == 1) printf( %d  , i + 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 200005;   bool r[MAXN];   int main() {     int n;     vector<pair<int, pair<int, int>>> v;     cin >> n;     for (int i = 0; i < n; ++i) {       int l, r;       cin >> l >> r;       v.emplace_back(l, make_pair(1, i));       v.emplace_back(r + 1, make_pair(0, i));     }     sort(v.begin(), v.end());     set<int> s;     for (int i = 0; i < v.size(); ++i) {       while (i < v.size()) {         if (v[i].second.first == 1) s.insert(v[i].second.second);         if (v[i].second.first == 0) s.erase(s.find(v[i].second.second));         if (v[i].first == v[i + 1].first)           i++;         else           break;       }       if (s.size() == 1) r[*s.begin()] = 1;     }     for (int i = 0; i < n; ++i) {       if (r[i] == 0) {         cout << i + 1 << endl;         return 0;       }     }     cout << -1 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int qp(int a, long long b) {     int ans = 1;     do {       if (b & 1) ans = 1ll * ans * a % 1000000007;       a = 1ll * a * a % 1000000007;     } while (b >>= 1);     return ans;   }   int ans[222222], atot = 0;   char s[222222], t[222222];   long long ct[26];   int n, m;   long long cs[26];   int sd = 10007;   map<pair<long long, long long>, int> ma;   long long ps[222222];   int test() {     ma.clear();     for (int i = 0; i < 26; i++) {       if (cs[i] == ct[i]) continue;       if (ma[make_pair(ct[i], cs[i])])         ma[make_pair(ct[i], cs[i])]--;       else         ma[make_pair(cs[i], ct[i])]++;     }     for (map<pair<long long, long long>, int>::iterator it = ma.begin();          it != ma.end(); it++) {       if (it->second) return 0;     }     return 1;   }   int main() {     ps[0] = 1;     for (int i = 1; i <= 211111; i++) ps[i] = ps[i - 1] * sd;     scanf( %d%d , &n, &m);     scanf( %s , s + 1);     scanf( %s , t + 1);     for (int i = 1; i <= m; i++) ct[t[i] -  a ] += ps[m - i + 1];     for (int i = 1; i <= m; i++) cs[s[i] -  a ] += ps[m - i + 1];     for (int i = 1; i + m - 1 <= n; i++) {       if (test()) ans[++atot] = i;       cs[s[i] -  a ] -= ps[m];       for (int j = 0; j < 26; j++) cs[j] *= sd;       cs[s[i + m] -  a ] += ps[1];     }     printf( %d n , atot);     for (int i = 1; i <= atot; i++) printf( %d  , ans[i]);     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline bool chmax(T &a, const T &b) {     return b > a ? a = b, true : false;   }   template <class T>   inline bool chmin(T &a, const T &b) {     return b < a ? a = b, true : false;   }   template <class T>   using MaxHeap = priority_queue<T>;   template <class T>   using MinHeap = priority_queue<T, vector<T>, greater<T>>;   template <class T, class F = less<T>>   void sort_uniq(vector<T> &v, F f = F()) {     sort(begin(v), end(v), f);     v.resize(unique(begin(v), end(v)) - begin(v));   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int tt;     cin >> tt;     while (tt--) {       int n;       cin >> n;       vector<int> a(n);       for (int i = 0; i < (int)(n); i++) cin >> a[i];       int last = a[0], alice = a[0], bob = 0;       int i = 1, j = n - 1, turn = 1, moves = 1;       while (i <= j) {         int cnt = 0;         if (turn) {           while (i <= j && cnt <= last) {             cnt += a[j--];           }           bob += cnt;         } else {           while (i <= j && cnt <= last) {             cnt += a[i++];           }           alice += cnt;         }         last = cnt;         moves++;         turn ^= 1;       }       cout << moves <<     << alice <<     << bob <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[2 * 100000 + 5];   int k, n;   long long dp[2][2 * 100000 + 5];   int mark[2 * 100000 + 5];   inline long long solve(int i, int lst) {     if (i == 0) {       if (lst == 1)         return 1ll;       else         return 0ll;     }     long long &ret = dp[lst][i];     if (ret != -1ll) return ret;     ret = 0ll;     if (lst == 0)       ret = (((k - 1) * 1ll) * solve(i - 1, 1)) % 998244353;     else {       long long tem = (k - 2) * 1ll;       tem = (tem * solve(i - 1, 1)) % 998244353;       tem = (tem + solve(i - 1, 0)) % 998244353;       ret = tem;     }     return ret;   }   inline int getNext(int i) {     for (int j = i + 2;; j += 2) {       if (a[j] != -1) return j;     }   }   inline long long pwr(int x, int p) {     if (p == 0) return 1ll;     if (p & 1) return ((1ll * x) * pwr(x, p - 1)) % 998244353;     long long ret = pwr(x, p / 2);     return (ret * ret) % 998244353;   }   int main() {     scanf( %d %d , &n, &k);     for (int i = 0; i < n; i++) {       scanf( %d , &a[i]);     }     a[n] = 10000000;     a[n + 1] = 10000000;     for (int i = 0; i < n; i++) {       if (a[i] == a[i + 2] && a[i] != -1) {         printf( 0 n );         return 0;       }     }     memset((dp), (-1), sizeof((dp)));     ;     long long ans = 1ll;     for (int i = 0; i < n; i++) {       if (a[i] == -1) {         if (i == 0 || i == 1) {           int nxt = getNext(i);           int pl = (nxt - i) / 2;           if (nxt >= n) {             ans = (ans * ((pwr(k - 1, pl - 1)) % 998244353)) % 998244353;             ans = (ans * (k * 1ll)) % 998244353;             continue;           }           ans = (ans * ((pwr(k - 1, pl)) % 998244353)) % 998244353;           continue;         }         if (a[i - 2] == -1) continue;         int nxt = getNext(i);         if (nxt >= n) {           int pl = (nxt - i) / 2;           ans = (ans * pwr(k - 1, pl)) % 998244353;         } else {           if (a[i - 2] == a[nxt]) {             int pl = (nxt - i) / 2;             ans = (ans * (k - 1ll)) % 998244353;             ans = (ans * solve(pl - 1, 1)) % 998244353;           } else {             int pl = (nxt - i) / 2;             long long tem;             tem = (k - 2ll) % 998244353;             tem = (tem * solve(pl - 1, 1)) % 998244353;             tem = (tem + (solve(pl - 1, 0))) % 998244353;             ans = (tem * ans) % 998244353;           }         }       }     }     printf( %lld n , ans);     ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int tree[300000];   int ar[100005];   int make(int l, int r, int ind) {     if (l >= r) {       tree[ind] = ar[r];       return tree[ind];     }     int mid = (l + r) / 2;     tree[ind] = make(l, mid, 2 * ind + 1) + make(mid + 1, r, 2 * ind + 2);     return tree[ind];   }   int query(int ql, int qr, int l, int r, int ind) {     if (ql <= l && qr >= r) {       return tree[ind];     }     if (qr < l || ql > r) return 0;     int mid = (l + r) / 2;     return query(ql, qr, l, mid, 2 * ind + 1) +            query(ql, qr, mid + 1, r, 2 * ind + 2);   }   int main() {     int n, i, q, l, r;     cin >> n;     for (i = 0; i < n; i++) {       cin >> ar[i];     }     make(0, n - 1, 0);     cin >> q;     while (q--) {       cin >> l >> r;       cout << query((l - 1), (r - 1), 0, n - 1, 0) / 10 << endl;     }   }