#include <bits/stdc++.h> n const int N = 100010; n const int inf = 0x3f3f3f3f; n using namespace std; n map<string, int> A, B; n string y; n int solve(string x) { n   y =   ; n   int sz = x.size(); n   int a = 0, b = 0; n   for (int i = 0; i < sz; i++) { n     if (x[i] ==  * ) n       a++; n     else if (x[i] ==  & ) n       b++; n     else n       y += x[i]; n   } n   if (B[y] == 0 || A[y] == inf || (A[y] + a - b) < 0) return inf; n   return A[y] + a - b; n } n int main() { n   int n; n   cin >> n; n   A[ void ] = 0; n   B[ void ] = 1; n   for (int i = 0; i < n; i++) { n     string a, b, c; n     cin >> a >> b; n     if (a ==  typedef ) { n       cin >> c; n       A[c] = solve(b); n       B[c] = B[y]; n     } else { n       A[b] = solve(b); n       if (A[b] == inf) n         puts( errtype ); n       else { n         printf( void ); n         for (int j = 0; j < A[b]; j++) printf( * ); n         puts(  ); n       } n     } n   } n   return 0; n } n


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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