#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, q; n   scanf( %d , &n); n   bool grid[n + 1][n + 1], ans = false; n   string s; n   for (int i = 0; i < n; i++) n     for (int j = 0; j < n; j++) scanf( %d , &grid[i][j]); n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < n; j++) { n       ans ^= (grid[j][i] && grid[i][j]); n     } n   } n   scanf( %d , &q); n   while (q--) { n     int t; n     scanf( %d , &t); n     if (t == 1 || t == 2) { n       scanf( %d , &t); n       ans ^= 1; n     } else n       s += (ans +  0 ); n   } n   printf( %s , s.c_str()); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long k, ans, a[501], i, g, n; n long long check(long long x) { n   k = 0; n   if (x == 1) return 0; n   for (long long i = 1; i <= n; i++) n     if (a[i] / (x - 1) * x < a[i]) n       return 0; n     else n       k += (a[i] + x - 1) / x; n   if (k < ans) ans = k; n } n int main() { n   scanf( %d , &n); n   for (i = 1; i <= n; i++) scanf( %d , &a[i]), ans += a[i] / 2 + a[i] % 2; n   sort(a + 1, a + n + 1); n   for (i = 2; i <= sqrt(a[n]) + 2; i++) check(i); n   for (i = 1; i <= sqrt(a[n]); i++) { n     g = a[n] / i, check(g), check(g + 1), check(g + 2); n   } n   printf( %lld n , ans); n } n


#include <bits/stdc++.h> n using namespace std; n inline int nxt() { n   int x; n   scanf( %d , &x); n   return x; n } n const int N = 55; n int a[N][N]; n char skdjflfsdj[N][N]; n int score[N]; n void add(int u, int v, int x) { n   a[u][v] += x; n   score[u] += x; n } n vector<int> all_out(int v, int n) { n   vector<char> used(n); n   vector<int> st = {v}; n   used[v] = 1; n   vector<int> par(n, -1); n   while (!st.empty()) { n     int u = st.back(); n     st.pop_back(); n     for (int i = 0; i < n; ++i) { n       if (!skdjflfsdj[i][u] && a[u][i]) { n         if (!used[i]) { n           used[i] = 1; n           par[i] = u; n           st.push_back(i); n         } n       } n     } n   } n   return par; n } n int main() { n   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); n   int n = nxt(), m = nxt(); n   for (int i = 0; i < m; ++i) { n     int u = nxt() - 1, v = nxt() - 1; n     add(u, v, 1); n     skdjflfsdj[u][v] = skdjflfsdj[v][u] = 1; n   } n   for (int i = 0; i < n; ++i) { n     for (int j = 0; j < i; ++j) { n       if (!skdjflfsdj[i][j]) { n         if (rng() % 2) { n           add(i, j, 1); n         } else { n           add(j, i, 1); n         } n       } n     } n   } n   while (true) { n     bool ok = false; n     for (int i = 0; i < n; ++i) { n       if (ok) { n         break; n       } n       auto par = all_out(i, n); n       for (int j = 0; j < n; ++j) { n         if (i != j && par[j] > -1 && score[j] < score[i] - 1) { n           for (int u = j; u != i; u = par[u]) { n             add(u, par[u], 1); n             add(par[u], u, -1); n           } n           ok = true; n           break; n         } n       } n     } n     if (!ok) { n       break; n     } n   } n   for (int i = 0; i < n; ++i) { n     for (int j = 0; j < n; ++j) { n       cout << a[i][j]; n     } n     cout <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int mod = 256; n int getNum(char tch) { n   int num = tch; n   char ch[10]; n   int cnt = 0; n   while (cnt < 8) { n     ch[cnt++] = num % 2 +  0 ; n     num /= 2; n   } n   num = 0; n   for (int i = 0; i < 8; i++) { n     num = num * 2 + (ch[i] -  0 ); n   } n   return num; n } n int main() { n   char ch[1000]; n   gets(ch); n   int len = strlen(ch); n   int pre = 0; n   for (int i = 0; i < len; i++) { n     int tmp = getNum(ch[i]); n     cout << (pre - tmp + 10 * 256) % mod << endl; n     pre = tmp; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m, a[100001]; n   cin >> n >> m; n   for (int i = 1; i <= m; i++) { n     cin >> a[i]; n   } n   sort(a + 1, a + 1 + m); n   int ans = 100000000; n   for (int i = 1; i <= m - n + 1; i++) { n     ans = min(ans, a[i + n - 1] - a[i]); n   } n   cout << ans; n } n


#include <bits/stdc++.h> n #pragma warning(disable : 6031) n #pragma warning(disable : 4101) n using namespace std; n const int INF = 1e9; n const long long LINF = 1e18; n const double PI = acos(-1); n const int MAXN = 1000006; n int n, m, v1, v2, Deg[MAXN], visited[MAXN]; n vector<unordered_set<int>> G; n vector<int> C; n set<pair<int, int>> erased; n void find_component(int v) { n   visited[v] = true; n   C.push_back(v); n   for (int c : G[v]) { n     if (!visited[c]) { n       find_component(c); n     } n   } n } n void eulerian_cycle(int v) { n   stack<int> S; n   vector<int> ans; n   S.push(v); n   while (!S.empty()) { n     int s = S.top(); n     if (G[s].empty()) { n       ans.push_back(s); n       S.pop(); n     } else { n       int c = *G[s].begin(); n       G[s].erase(G[s].begin()); n       G[c].erase(s); n       S.push(c); n     } n   } n   int ans_size = ((int)(ans).size()); n   for (int i = 1; i < ((int)(ans).size()); i += 2) { n     if (ans[i] != 0 && ans[i + 1] != 0) { n       if (ans[i - 1] != 0 && ans[(i + 2) % ans_size] != 0) { n         if (ans[i] < ans[i + 1]) { n           erased.erase({ans[i], ans[i + 1]}); n         } else { n           erased.erase({ans[i + 1], ans[i]}); n         } n       } n     } n   } n } n int main() { n   scanf( %d%d , &n, &m); n   G.resize(n + 1); n   while (m--) { n     scanf( %d%d , &v1, &v2); n     G[v1].insert(v2); n     G[v2].insert(v1); n     if (v1 < v2) { n       erased.insert({v1, v2}); n     } else { n       erased.insert({v2, v1}); n     } n     Deg[v1]++; n     Deg[v2]++; n   } n   for (int i = 1; i <= n; i++) { n     if (!visited[i]) { n       assert(G[0].empty()); n       C.clear(); n       find_component(i); n       if (((int)(C).size()) == 1) { n         continue; n       } n       for (int v : C) { n         if (Deg[v] % 2 == 1) { n           G[0].insert(v); n           G[v].insert(0); n         } n       } n       eulerian_cycle(C.front()); n     } n   } n   printf( %d n , ((int)(erased).size())); n   for (pair<int, int> p : erased) { n     printf( %d %d n , p.first, p.second); n   } n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optmize( Ofast ) n using namespace std; n const int maxn = 20009; n const int inf = 1e8; n int n, m, K, T; n int e[1 << 10][maxn << 1]; n int head[maxn], cntedge = 1; n int from[maxn], to[maxn], cap[maxn], flow[maxn], nex[maxn]; n void Addedge(int x, int y, int z) { n   nex[++cntedge] = head[x]; n   from[cntedge] = x; n   to[cntedge] = y; n   cap[cntedge] = z; n   flow[cntedge] = 0; n   head[x] = cntedge; n } n int cur[maxn]; n int d[maxn]; n int vis[maxn]; n int q[maxn], r; n int Bfs() { n   for (int i = 1; i <= n; ++i) vis[i] = 0; n   vis[1] = 1; n   d[1] = 0; n   q[r = 1] = 1; n   for (int l = 1; l <= r; ++l) { n     int x = q[l]; n     for (int i = head[x]; i; i = nex[i]) { n       int v = to[i]; n       if ((cap[i] > flow[i]) && (!vis[v])) { n         vis[v] = 1; n         d[v] = d[x] + 1; n         q[++r] = v; n       } n     } n   } n   return vis[n]; n } n int Dfs(int x, int a) { n   if ((x == n) || (a == 0)) return a; n   int nowflow = 0, f = 0; n   for (int i = cur[x]; i; i = nex[i]) { n     cur[x] = i; n     int v = to[i]; n     if (d[x] + 1 == d[v]) { n       f = Dfs(v, min(a, cap[i] - flow[i])); n       nowflow += f; n       a -= f; n       flow[i] += f; n       flow[i ^ 1] -= f; n       if (a == 0) break; n     } n   } n   return nowflow; n } n int p[maxn], pf[maxn] = {0, 1000000}; n int augment() { n   for (int i = 1; i <= n; ++i) vis[i] = 0; n   q[r = 1] = 1; n   int flag = 0; n   for (int l = 1; l <= r; ++l) { n     int x = q[l]; n     for (int i = head[x]; i; i = nex[i]) { n       int v = to[i]; n       if ((cap[i] > flow[i]) && (!vis[v])) { n         vis[v] = 1; n         p[v] = i; n         q[++r] = v; n         pf[v] = min(pf[x], cap[i] - flow[i]); n         if (v == n) { n           flag = 1; n           break; n         } n       } n     } n     if (flag) break; n   } n   if (!vis[n]) return 0; n   int f = pf[n], x = n; n   while (x != 1) { n     flow[p[x]] += f; n     flow[p[x] ^ 1] -= f; n     x = from[p[x]]; n   } n   return f; n } n int Maxflow() { n   int flow = 0; n   while (Bfs()) { n     for (int i = 1; i <= n; ++i) cur[i] = head[i]; n     flow += Dfs(1, inf); n   } n   return flow; n } n int f[1024]; n int sum[1 << 10]; n int lg2[1 << 11]; n int w[maxn]; n int read() { n   int r = 0, k = 1; n   char c = getchar(); n   for (; c <  0  || c >  9 ; c = getchar()) n     if (c ==  - ) k = -1; n   for (; c >=  0  && c <=  9 ; c = getchar()) r = r * 10 + c -  0 ; n   return r * k; n } n int main() { n   scanf( %d%d%d%d , &n, &m, &K, &T); n   for (int i = 1; i <= m; ++i) { n     int x, y, z; n     scanf( %d%d%d , &x, &y, &z); n     Addedge(x, y, z); n     Addedge(y, x, 0); n   } n   f[0] = Maxflow(); n   for (int i = 2; i <= cntedge; ++i) e[0][i] = flow[i]; n   for (int s = 1; s < (1 << K); ++s) { n     for (int i = 1; i <= K; ++i) { n       if (s & (1 << (i - 1))) { n         cap[i << 1] = 25; n       } else { n         cap[i << 1] = 0; n       } n     } n     int pre = s ^ (s & (-s)); n     for (int i = 2; i <= cntedge; ++i) flow[i] = e[pre][i]; n     f[s] = f[pre]; n     int tmp; n     while (tmp = augment()) f[s] += tmp; n     for (int i = 2; i <= cntedge; ++i) e[s][i] = flow[i]; n   } n   for (int s = 0; s < (1 << K); ++s) { n     int t = (~s) & ((1 << K) - 1); n     if (t < s) swap(f[s], f[t]); n   } n   for (int i = 1; i <= 10; ++i) lg2[1 << i] = i; n   while (T--) { n     for (int i = 1; i <= K; ++i) w[i] = read(); n     int ans = f[0]; n     for (int s = 1; s < (1 << K); ++s) { n       int l = s & (-s); n       sum[s] = sum[s ^ l] + w[lg2[l] + 1]; n       ans = min(ans, sum[s] + f[s]); n     } n     printf( %d n , ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void desperate_optimization(int precision) { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   cout.setf(ios::fixed); n   cout.setf(ios::showpoint); n   cout.precision(precision); n } n const int N = 2e5; n int arr[N + 5]; n int pre[N + 5]; n int mark[N + 5]; n vector<int> lis; n void hora(int tc) { n   int n; n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> arr[i]; n     mark[i] = 1; n     if (lis.size() == 0 || arr[lis.back()] < arr[i]) { n       pre[i] = -1; n       if (lis.size() != 0) pre[i] = lis.back(); n       lis.push_back(i); n     } else { n       int lo = 0; n       int hi = lis.size() - 1; n       int res = -1; n       while (lo <= hi) { n         int mid = (lo + hi) / 2; n         if (arr[lis[mid]] >= arr[i]) { n           res = mid; n           hi = mid - 1; n         } else n           lo = mid + 1; n       } n       lis[res] = i; n       pre[i] = -1; n       if (res != 0) pre[i] = lis[res - 1]; n     } n   } n   int tmp = lis.back(); n   for (int i = 0; i < n; i++) { n     if (pre[tmp] == pre[i] && arr[tmp] < arr[i]) tmp = i; n   } n   while (tmp != -1) { n     mark[tmp] = 0; n     tmp = pre[tmp]; n   } n   int hi = 1e9; n   int lo = -1; n   bool ada = true; n   for (int i = 0; i < n; i++) { n     if (mark[i] == 0) { n       if (lo >= arr[i]) ada = false; n       lo = arr[i]; n     } else { n       if (hi <= arr[i]) ada = false; n       hi = arr[i]; n     } n   } n   if (ada == false) { n     lis.clear(); n     for (int i = 0; i < n; i++) { n       mark[i] = 0; n       if (lis.size() == 0 || arr[lis.back()] > arr[i]) { n         pre[i] = -1; n         if (lis.size() != 0) pre[i] = lis.back(); n         lis.push_back(i); n       } else { n         int lo = 0; n         int hi = lis.size() - 1; n         int res = -1; n         while (lo <= hi) { n           int mid = (lo + hi) / 2; n           if (arr[lis[mid]] <= arr[i]) { n             res = mid; n             hi = mid - 1; n           } else n             lo = mid + 1; n         } n         lis[res] = i; n         pre[i] = -1; n         if (res != 0) pre[i] = lis[res - 1]; n       } n     } n     int tmp = lis.back(); n     for (int i = 0; i < n; i++) { n       if (pre[tmp] == pre[i] && arr[tmp] > arr[i]) tmp = i; n     } n     while (tmp != -1) { n       mark[tmp] = 1; n       tmp = pre[tmp]; n     } n     int hi = 1e9; n     int lo = -1; n     bool ada = true; n     for (int i = 0; i < n; i++) { n       if (mark[i] == 0) { n         if (lo >= arr[i]) ada = false; n         lo = arr[i]; n       } else { n         if (hi <= arr[i]) ada = false; n         hi = arr[i]; n       } n     } n     if (ada == false) n       cout <<  NO  <<   n ; n     else { n       cout <<  YES  <<   n ; n       for (int i = 0; i < n; i++) cout << mark[i] <<    ; n       cout <<   n ; n     } n   } else { n     cout <<  YES  <<   n ; n     for (int i = 0; i < n; i++) cout << mark[i] <<    ; n     cout <<   n ; n   } n } n int main() { n   desperate_optimization(10); n   int ntc = 1; n   for (int tc = 1; tc <= ntc; tc++) hora(tc); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n string to_str(T str) { n   stringstream stream; n   stream << str; n   return stream.str(); n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   long long n, d, e; n   long long result = 1000000000; n   cin >> n >> d >> e; n   while (n >= 0) { n     result = min(n % (5 * e), result); n     n = n - d; n   } n   cout << result << endl; n   return 0; n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n } n


#include <bits/stdc++.h> n using namespace std; n bool debug = 1; n int n, m, k; n int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0}; n long long ln, lk, lm; n int a[100005]; n int main() { n   scanf( %d , &n); n   for (int(i) = 0; (i) < (int)(n); (i)++) { n     scanf( %d , a + i); n   } n   sort(a, a + n); n   vector<int> vp; n   for (int i = n - 1; i >= 1;) { n     if (a[i] == a[i - 1] || a[i] - 1 == a[i - 1]) { n       vp.push_back(a[i - 1]); n       i -= 2; n     } else n       i--; n   } n   long long ans = 0; n   for (int i = 0; i + 1 < vp.size(); i += 2) { n     ans += (long long)vp[i] * vp[i + 1]; n   } n   printf( %lld n , ans); n } n


#include <bits/stdc++.h> n using namespace std; n uint64_t rnd_data = 0xDEADBEEFDULL; n inline void my_srand(int seed) { rnd_data = ((uint64_t)seed << 16) | 0x330E; } n inline int my_rand() { n   rnd_data = rnd_data * 0x5DEECE66DULL + 0xB; n   return (rnd_data >> 17) & 0x7FFFFFFF; n } n template <typename T> n void my_random_shuffle(T b, T e) { n   for (int i = (1); i <= (int)((int)(e - b) - 1); i++) { n     swap(b[i], b[my_rand() % (i + 1)]); n   } n } n template <class _T> n inline _T sqr(const _T &x) { n   return x * x; n } n template <typename type_t, typename less_t = std::less<type_t>> n inline bool uin(type_t &a, const type_t &b, const less_t &ls = less_t()) { n   return ls(b, a) ? a = b, true : false; n } n template <typename type_t, typename less_t = std::less<type_t>> n inline bool uax(type_t &a, const type_t &b, const less_t &ls = less_t()) { n   return ls(a, b) ? a = b, true : false; n } n const long double PI = 3.1415926535897932384626433832795L; n const long double EPS = 1e-9; n const int MAXN = 1 << 17; n int n, k; n int a[MAXN]; n bool g[MAXN]; n int d[MAXN * 2][2][2]; n int main() { n   scanf( %d%d , &n, &k); n   memset((g), 0, sizeof(g)); n   for (int i = 0; i < (int)(k); i++) { n     scanf( %d , &a[i]); n     g[a[i] - 1] = true; n   } n   memset(d, 0x80, sizeof(d)); n   int z = 1 << (n - 1); n   for (int i = 0; i < (int)(z); i++) { n     int x = i << 1; n     int y = x + 1; n     d[z + i][g[x]][g[y]] = g[x] || g[y]; n     d[z + i][g[y]][g[x]] = g[x] || g[y]; n   } n   for (int i = (z - 1); i >= (int)(1); i--) { n     int x = i * 2; n     int y = x + 1; n     for (int xw = 0; xw < (int)(2); xw++) { n       for (int xl = 0; xl < (int)(2); xl++) { n         if (d[x][xw][xl] < 0) continue; n         for (int yw = 0; yw < (int)(2); yw++) { n           for (int yl = 0; yl < (int)(2); yl++) { n             if (d[y][yw][yl] < 0) continue; n             int gw[2] = {xw, yw}; n             bool ggl = xl || yl; n             for (int t = 0; t < (int)(2); t++) { n               int cur = (xw || yw) + ggl; n               int nw = gw[t]; n               int nl0 = gw[t ^ 1]; n               int nl = nl0 || ggl; n               cur += nl; n               uax(d[i][nw][nl], d[x][xw][xl] + d[y][yw][yl] + cur); n             } n           } n         } n       } n     } n   } n   int ans = 0; n   for (int i = 0; i < (int)(2); i++) { n     for (int j = 0; j < (int)(2); j++) { n       int add = (i || j); n       uax(ans, d[1][i][j] + add); n     } n   } n   printf( %d n , ans); n   return 0; n } n


#include<bits/stdc++.h> n #define FOR(i,l,r) for(int i=l;i<=r;i++) n #define ROF(i,l,r) for(int i=l;i>=r;i--) n #define lson k<<1,l,mid n #define rson k<<1|1,mid+1,r n #define r(x) read(x) n #define rr(x,y) read(x);read(y) n #define rrr(x,y,z) read(x);read(y);read(z) n #define pb(x) push_back(x) n #define mp(x,y) make_pair(x,y) n #define fi first n #define se second n #define sss(str) scanf( %s ,str+1) n using namespace std; n typedef long long LL; n typedef pair<int,int> pt; n const int N=1e6+5; n const int M=2e3+5; n const int mod=1e9+7; n const int INF=2e9; n const double eps=1e-8; n const double pi=acos(-1); n template <class T> n inline void read(T &x) { n     char c;x = 1; n     while ((c = getchar()) <  0  || c >  9 ) if (c ==  - ) x = -1; n     T res = c -  0 ; n     while ((c = getchar()) >=  0  && c <=  9 ) res = res * 10 + c -  0 ; n     x *= res; n } n int n,m; n char str[N]; n int f[N]; n void solve(int cas) n { n     r(n); n     int cnt1=n/2,cnt2=n-cnt1; n     LL ans=0; n     set<pt> s; n     for(int i=cnt1;i>=-cnt1;i-=2){ n         for(int j=cnt2;j>=-cnt2;j-=2){ n             s.insert(mp(i,j)); n             s.insert(mp(j,i)); n         } n     } n     cout<<s.size()<<endl; n } n int main() n { n     int t; n //    r(t); n     t=1; n //    init(); n     FOR(i,1,t){ n         solve(i); n     } n     return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n T gcd(T a, T b) { n   return (b != 0 ? gcd<T>(b, a % b) : a); n } n template <class T> n T lcm(T a, T b) { n   return (a / gcd<T>(a, b) * b); n } n long long pwr(long long base, long long p) { n   long long ans = 1; n   while (p) { n     if (p & 1) ans = (ans * base) % (1000000007LL); n     base = (base * base) % (1000000007LL); n     p >>= 1; n   } n   return ans; n } n long long modInv(long long n, long long mod) { return pwr(n, mod - 2); } n int bitCount(int n) { n   int c = 0; n   while (n) { n     c++; n     n &= n - 1; n   } n   return c; n } n int main() { n   double n, m, cost; n   ; n   int i, a, b; n   cin >> n >> m; n   int ver[100000]; n   for (i = 1; i < n + 1; i++) { n     scanf( %d , &ver[i]); n   } n   double ans = 0; n   for (i = 0; i < m; i++) { n     cin >> a >> b >> cost; n     ans = max(ans, (ver[a] + ver[b]) / cost); n   } n   printf( %.12lf n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int Inf = (1 << 30) - 1; n const long long lInf = (1LL << 62) - 1; n const long long Mod = 1000000007; n long long fac[1000010]; n long long inv[1000010]; n long long powm[1000010]; n long long pown[1000010]; n int a, b; n long long n, m; n long long fpow(long long a, long long b, long long Mod) { n   a %= Mod; n   b %= Mod; n   long long mul = 1; n   while (b) { n     if (b & 1) (mul *= a) %= Mod; n     (a *= a) %= Mod; n     b >>= 1; n   } n   return mul; n } n void init() { n   int tmp = max(n, m); n   fac[0] = fac[1] = 1; n   for (int i = 2; i <= tmp; ++i) fac[i] = fac[i - 1] * i % Mod; n   inv[tmp] = fpow(fac[tmp], Mod - 2, Mod); n   for (int i = tmp; i >= 1; --i) inv[i - 1] = inv[i] * i % Mod; n   powm[0] = pown[0] = 1; n   for (int i = 1; i <= tmp; ++i) n     powm[i] = powm[i - 1] * m % Mod, pown[i] = pown[i - 1] * n % Mod; n } n long long A(int x, int y) { n   if (x - y < 0 || x < 0) return 0; n   return fac[x] * inv[x - y] % Mod; n } n long long C(int x, int y) { n   if (x - y < 0 || x < 0 || y < 0) return 0; n   return fac[x] * inv[y] % Mod * inv[x - y] % Mod; n } n int main() { n   ios::sync_with_stdio(false); n   cin >> n >> m >> a >> b; n   init(); n   long long ans = 0; n   for (long long i = 1; i <= n - 1; ++i) { n     long long mul = n         A(n - 2, i - 1) * C(m - 1, i - 1) % Mod * powm[n - i - 1] % Mod; n     if (n - i - 2 >= 0) (mul *= (i + 1) * pown[n - i - 2] % Mod) %= Mod; n     (ans += mul) %= Mod; n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n long long A, B; n struct node { n   long long vx, vy, w; n } p[400005]; n bool cmp(const node p1, const node p2) { n   if (p1.w == p2.w) return p1.vx < p2.vx; n   return p1.w < p2.w; n } n int main() { n   scanf( %d%I64d%I64d , &n, &A, &B); n   int i, j; n   long long gg; n   for (i = 1; i <= n; i++) scanf( %I64d%I64d%I64d , &gg, &p[i].vx, &p[i].vy); n   long long ans = 0; n   for (i = 1; i <= n; i++) { n     p[i].w = p[i].vy - p[i].vx * A; n   } n   sort(p + 1, p + n + 1, cmp); n   for (i = 1; i <= n; i++) { n     j = i; n     while (j + 1 <= n && p[j + 1].w == p[i].w) j = j + 1; n     long long num = j - i + 1; n     int k; n     for (int t = i; t <= j; t++) { n       k = t; n       while (k + 1 <= j && p[k + 1].vx == p[t].vx) k = k + 1; n       long long siz = k - t + 1; n       ans += siz * (num - siz); n       t = k; n     } n     i = j; n   } n   printf( %I64d , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void solve() { n   string S; n   cin >> S; n   int M; n   cin >> M; n   for (int i = 0; i < M; i++) { n     int l, r, k; n     cin >> l >> r >> k; n     l--; n     rotate(S.begin() + l, S.begin() + r - k % (r - l), S.begin() + r); n   } n   cout << S <<   n ; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int t = 1; n   while (t--) solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t, n; n   cin >> t; n   while (t--) { n     cin >> n; n     int a[n]; n     for (int i = 0; i < n; i++) { n       cin >> a[i]; n     } n     sort(a, a + n); n     int flag = 0; n     for (int i = 0; i < n - 1; i++) { n       if ((a[i + 1] - a[i]) > 1 || (a[i + 1] - a[i]) < -1) { n         flag = 1; n       } n     } n     if (flag == 1) { n       cout <<  NO  n            <<   n ; n     } else { n       cout <<  YES  n            <<   n ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   long n, m; n   cin >> n >> m; n   if (m % 2 == 1) { n     bool f = true; n     long ptr = (m + 1) / 2; n     long p1 = ptr - 1, p2 = ptr; n     for (long i = 1; i <= n; i++) { n       if (f && p2 <= m) { n         cout << p2 <<   n ; n         p2++; n         f = false; n       } else if (p1 >= 1) { n         cout << p1 <<   n ; n         p1--; n         f = true; n       } else { n         i--; n         f = !f; n         p1 = ptr - 1; n         p2 = ptr; n       } n     } n   } else { n     bool f = true; n     long ptr = (m + 1) / 2; n     if (n >= 2) n       cout << ptr <<   n  << ptr + 1 <<   n ; n     else n       cout << ptr; n     long p1 = ptr - 1; n     long p2 = ptr + 2; n     for (long i = 3; i <= n; i++) { n       if (f && p1 >= 1) { n         cout << p1 <<   n ; n         p1--; n         f = false; n       } else if (p2 <= m) { n         cout << p2 <<   n ; n         p2++; n         f = true; n       } else { n         i++; n         if (i < n) n           cout << ptr <<   n  << ptr + 1 <<   n ; n         else n           cout << ptr <<   n ; n         p1 = ptr - 1; n         p2 = ptr + 2; n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n map<long long, long long> mp; n string s; n long long n, m, k, ans; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   srand(time(0)); n   cin >> n; n   vector<long long> a(n + 1, 0); n   for (long long i = 1; i <= n; ++i) cin >> a[i]; n   for (long long i = n; i >= 1; --i) n     if (a[i] && !m) n       m = i; n     else if (!a[i] && !k) n       k = i; n   cout << min(m, k); n } n


#include <bits/stdc++.h> n using namespace std; n int prime[1000005]; n int ans[5]; n int idx; n set<int> s, s1; n set<int>::iterator it; n int main() { n   int i, j; n   for (i = 2; i <= 1000000; i++) { n     if (prime[i] == 1) continue; n     for (j = i + i; j <= 1000000; j += i) prime[j] = 1; n   } n   int n; n   scanf( %d , &n); n   if (n == 1) n     printf( 1 n ); n   else if (n == 2) n     printf( 2 n ); n   else { n     long long sum = n; n     for (i = 2; i < n; i++) { n       if (n % i == 0) s.insert(i); n     } n     int countt = 0; n     for (i = n - 1; i >= 1; i--) { n       bool no = 0; n       for (it = s.begin(); it != s.end(); it++) { n         if (i % (*it) == 0) { n           no = 1; n           break; n         } n       } n       if (!no) { n         sum *= (long long)i; n         countt++; n       } n       if (countt == 2) break; n     } n     long long sum1 = n - 1; n     for (i = 2; i < n - 1; i++) { n       if ((n - 1) % i == 0) s1.insert(i); n     } n     countt = 0; n     for (i = n - 2; i >= 1; i--) { n       bool no = 0; n       for (it = s1.begin(); it != s1.end(); it++) { n         if (i % (*it) == 0) { n           no = 1; n           break; n         } n       } n       if (!no) { n         sum1 *= (long long)i; n         countt++; n       } n       if (countt == 2) break; n     } n     printf( %I64d n , max(sum, sum1)); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 10; n pair<int, int> a[N]; n int main() { n   int n; n   cin >> n; n   int mn = 1e9, mx = -1e9; n   for (int i = 0; i < n; ++i) { n     cin >> a[i].first >> a[i].second; n     mn = min(mn, a[i].first); n     mx = max(mx, a[i].second); n   } n   int ans = -1; n   for (int i = 0; i < n; ++i) { n     if (a[i].first <= mn && a[i].second >= mx) { n       ans = i + 1; n       break; n     } n   } n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int dp[101][101][28]; n vector<pair<int, int> > graph[101]; n int fun(int x, int y, int val) { n   if (dp[x][y][val] != -1) return dp[x][y][val]; n   for (int i = 0; i < graph[x].size(); i++) { n     if (graph[x][i].second >= val) { n       bool mark = true; n       for (int j = 0; j < graph[y].size(); j++) { n         if (graph[y][j].second >= graph[x][i].second) { n           if (fun(graph[x][i].first, graph[y][j].first, graph[y][j].second) == n               0) { n             mark = false; n             break; n           } n         } n       } n       if (mark == true) { n         dp[x][y][val] = 1; n         return 1; n       } n     } n   } n   dp[x][y][val] = 0; n   return 0; n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(NULL); n   int n, m; n   cin >> n >> m; n   for (int i = 0; i < m; i++) { n     int x, y; n     char d; n     cin >> x >> y >> d; n     graph[x - 1].push_back(make_pair(y - 1, d - 96)); n   } n   memset(dp, -1, sizeof(dp)); n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < n; j++) { n       if (fun(i, j, 0)) n         cout <<  A ; n       else n         cout <<  B ; n     } n     cout <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2e5 + 10; n int n, m; n int volume[N]; n int amount[N]; n int parent[N]; n int tofill[N]; n int weight[N]; n std::set<int> notFull; n void reducePath(int index, int lead) { n   while (parent[index] != index) { n     int oldParent = parent[index]; n     parent[index] = lead; n     index = oldParent; n   } n } n int find(int index) { n   int lead = index; n   while (parent[lead] != lead) { n     lead = parent[lead]; n   } n   reducePath(index, lead); n   return lead; n } n bool merge(int l, int r) { n   int ll = find(l); n   int rl = find(r); n   if (ll == rl) { n     return false; n   } n   if (weight[ll] < weight[rl]) swap(ll, rl); n   parent[rl] = ll; n   weight[ll] += weight[rl]; n   if (tofill[ll] < tofill[rl]) tofill[ll] = tofill[rl]; n   return true; n } n void fill(int p, int x) { n   while (x > 0) { n     int lead = find(p); n     int f = tofill[lead]; n     int remainingVolume = volume[f] - amount[f]; n     int fillAmount = std::min(remainingVolume, x); n     amount[f] += fillAmount; n     x -= fillAmount; n     if (amount[f] == volume[f]) { n       if (f == n - 1) n         break; n       else n         ++f; n       merge(lead, f); n     } n   } n } n void fill2(int p, int x) { n   auto lb = notFull.lower_bound(p); n   while (x > 0 && lb != notFull.end()) { n     int remainingVolume = volume[*lb] - amount[*lb]; n     int fillAmount = std::min(remainingVolume, x); n     amount[*lb] += fillAmount; n     x -= fillAmount; n     if (amount[*lb] == volume[*lb]) n       lb = notFull.erase(lb); n     else n       lb++; n   } n } n void init() { n   for (int i = 0; i < n; ++i) { n     parent[i] = i; n     tofill[i] = i; n     weight[i] = 1; n     notFull.insert(i); n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(nullptr); n   cin >> n; n   for (int i = 0; i < n; ++i) { n     cin >> volume[i]; n   } n   init(); n   cin >> m; n   for (int i = 0; i < m; ++i) { n     int q; n     cin >> q; n     if (q == 1) { n       int p, x; n       cin >> p >> x; n       fill2(--p, x); n     } else { n       int k; n       cin >> k; n       cout << amount[--k] <<   n ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m; n   scanf( %d %d , &n, &m); n   vector<int> v(n + 1); n   for (int i = 1; i <= n; i++) scanf( %d , &v[i]); n   double ans = 0.0; n   int a, b, w; n   for (int i = 1; i <= m; i++) { n     scanf( %d %d %d , &a, &b, &w); n     ans = max(ans, 1.0 * (v[a] + v[b]) / w); n   } n   printf( %0.9lf n , ans); n   return 0; n } n


#include <bits/stdc++.h> n const int max_n = 150; n const unsigned int lowest = 31; n const int size = (max_n >> 5) + 1; n struct row { n   unsigned int bits[size]; n   void set_bit(unsigned int j) { bits[j >> 5] |= (1 << (j & lowest)); } n   bool get_bit(unsigned int j) { n     return ((bits[j >> 5] >> (j & lowest)) & 1) == 1; n   } n   bool is_zero() { n     for (int i = 0; i < size; ++i) n       if (bits[i]) return false; n     return true; n   } n }; n row operator&(row a, row b) { n   row c; n   for (int i = 0; i < size; ++i) c.bits[i] = a.bits[i] & b.bits[i]; n   return c; n } n row operator|(row a, row b) { n   row c; n   for (int i = 0; i < size; ++i) c.bits[i] = a.bits[i] | b.bits[i]; n   return c; n } n row operator~(row a) { n   row c; n   for (int i = 0; i < size; ++i) c.bits[i] = ~a.bits[i]; n   return c; n } n row left(row a) { n   for (int i = 0; i < size - 1; ++i) { n     a.bits[i] >>= 1; n     if (a.bits[i + 1] & 1) a.bits[i] |= (1 << lowest); n   } n   a.bits[size - 1] >>= 1; n   return a; n } n row right(row a) { n   for (int i = size - 1; i > 0; --i) { n     a.bits[i] <<= 1; n     if (a.bits[i - 1] & (1 << lowest)) a.bits[i] |= 1; n   } n   a.bits[0] <<= 1; n   return a; n } n int ei, ej, n, m, k; n row table[max_n], where[max_n]; n bool check() { n   for (int i = 0; i < n; ++i) n     if ((i != ei) && !where[i].is_zero()) return false; n   for (int j = 0; j < m; ++j) n     if ((j != ej) && where[ei].get_bit(j)) return false; n   return true; n } n int main() { n   memset(table, 0, sizeof(table)); n   memset(where, 0, sizeof(where)); n   scanf( %d%d%d n , &n, &m, &k); n   for (int i = 0; i < n; ++i) { n     for (int j = 0; j < m; ++j) { n       char c; n       scanf( %c , &c); n       if (c ==  E ) ei = i, ej = j, c =  . ; n       if (c ==  . ) table[i].set_bit(j), where[i].set_bit(j); n     } n     scanf(  n ); n   } n   if (check()) { n     printf( 0 n ); n     return 0; n   } n   for (int i = 1; i <= k; ++i) { n     char c; n     scanf( %c , &c); n     switch (c) { n       case  L : n         for (int r = 1; r <= n - 2; ++r) n           where[r] = n               (left(where[r]) & table[r]) | (where[r] & ~right(table[r])); n         break; n       case  R : n         for (int r = 1; r <= n - 2; ++r) n           where[r] = n               (right(where[r]) & table[r]) | (where[r] & ~left(table[r])); n         break; n       case  D : n         for (int r = n - 2; r >= 1; --r) n           where[r] = (where[r - 1] & table[r]) | (where[r] & ~table[r + 1]); n         break; n       case  U : n         for (int r = 1; r <= n - 2; ++r) n           where[r] = (where[r + 1] & table[r]) | (where[r] & ~table[r - 1]); n         break; n     } n     if (check()) { n       printf( %d n , i); n       return 0; n     } n   } n   printf( -1 n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, k; n vector<pair<int, int> > g[1001]; n int obtenpadre(int u, int padre[1001]) { n   if (padre[u] == 0) return u; n   padre[u] = obtenpadre(padre[u], padre); n   return padre[u]; n } n void unir(int u, int v, int padre[1001], int llaves[1001][1001]) { n   padre[v] = u; n   for (int i = 1; i <= m; i++) n     if (llaves[v][i]) llaves[u][i] = 1; n } n void ejecuta(int padre[1001], int llaves[1001][1001]) { n   bool cambios = true; n   while (cambios) { n     cambios = false; n     for (int u = 1; u <= n; u++) { n       vector<pair<int, int> > &ar = g[u]; n       for (int i = 0; i < int(ar.size()); i++) { n         int v = ar[i].first; n         int l = ar[i].second; n         int pu = obtenpadre(u, padre); n         int pv = obtenpadre(v, padre); n         if (pu != pv and (llaves[pu][l] or llaves[pv][l])) { n           unir(pu, pv, padre, llaves); n           cambios = true; n         } n       } n     } n   } n } n map<string, int> posini[2]; n int padre[2][1001]; n int llaves[2][1001][1001]; n int visto[2][1001]; n int main() { n   cin >> n >> m >> k; n   for (int i = 1; i <= m; i++) { n     int u, v; n     cin >> u >> v; n     g[u].push_back(pair<int, int>(v, i)); n     g[v].push_back(pair<int, int>(u, i)); n   } n   for (int p = 0; p < 2; p++) { n     for (int i = 1; i <= k; i++) { n       string s; n       int h, amount; n       cin >> s >> h >> amount; n       posini[p][s] = h; n       for (int j = 0; j < amount; j++) { n         int x; n         cin >> x; n         llaves[p][h][x] = 1; n       } n     } n     ejecuta(padre[p], llaves[p]); n   } n   for (map<string, int>::iterator it = posini[0].begin(); it != posini[0].end(); n        it++) { n     string s = it->first; n     int h0 = it->second; n     int h1 = posini[1][s]; n     if (obtenpadre(h0, padre[0]) != obtenpadre(h1, padre[0])) { n       cout <<  NO  << endl; n       exit(0); n     } n   } n   for (int u = 1; u <= n; u++) { n     int h0 = obtenpadre(u, padre[0]); n     int h1 = obtenpadre(u, padre[1]); n     if (visto[0][h0] != visto[1][h1]) { n       cout <<  NO  << endl; n       exit(0); n     } n     if (visto[0][h0] == 0) { n       visto[0][h0] = visto[1][h1] = 1; n       for (int j = 1; j <= m; j++) { n         if (llaves[0][h0][j] != llaves[1][h1][j]) { n           cout <<  NO  << endl; n           exit(0); n         } n       } n     } n   } n   cout <<  YES  << endl; n } n


#include <bits/stdc++.h> n const int inf = 0x3f3f3f3f; n const long long int INF = 0x3f3f3f3f3f3f3f3f; n using namespace std; n inline void INP() {} n long long int n, m; n vector<pair<long long int, long long int> > v; n void solve() { n   cin >> n >> m; n   long long int mn = INF; n   long long int mx = 0; n   for (long long int i = 0; i < m; i++) { n     long long int x, y; n     cin >> x >> y; n     v.push_back({-1 * y, x}); n     mn = min(mn, y); n     mx = max(mx, y); n   } n   sort(begin(v), end(v)); n   long long int ans = 0; n   for (long long int i = 0; i < m; i++) { n     if (v[i].second <= n) { n       ans += (-1 * v[i].first) * v[i].second; n       n -= v[i].second; n     } else { n       ans += (-1 * v[i].first) * n; n       n = 0; n     } n     if (n == 0) break; n   } n   cout << ans <<   n ; n } n int32_t main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int t = 1; n   while (t--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 100005; n long long int ara[N]; n int main() { n   long long int n, i, j, k, s = 0, ts; n   cin >> n; n   for (i = 1; i <= n; i++) cin >> ara[i]; n   for (i = 1; i < n; i++) { n     for (j = 30; ara[i] > 0 && j >= 0; j--) { n       if ((i + (1 << j)) > n) continue; n       s += ara[i]; n       ara[(i + (1 << j))] += ara[i]; n       ara[i] = 0; n     } n     cout << s <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int cha[1000100]; n int num[1000100]; n int a[5010]; n int limit[] = {0, 1, 3, 6, 10}; n int n, k; n int che[1000100]; n bool check(int mod) { n   int bad = 0; n   int mostI = -1; n   for (int i = 0; i < n; i++) { n     int t = a[i] % mod; n     che[t]++; n     if (che[t] > 1) bad++; n     if (bad > k) { n       mostI = i; n       break; n     } n   } n   for (int i = 0; i <= mostI; i++) { n     int t = a[i] % mod; n     che[t]--; n   } n   return (bad <= k); n } n int main() { n   scanf( %d%d , &n, &k); n   for (int i = 0; i < n; i++) scanf( %d , &a[i]); n   sort(a, a + n); n   for (int i = 0; i <= a[n - 1]; i++) cha[i] = 0; n   int maxn = a[n - 1] - a[0]; n   for (int i = 0; i <= maxn; i++) che[i] = 0; n   for (int i = 0; i <= maxn; i++) num[i] = 0; n   for (int i = 0; i < n - 1; i++) n     for (int j = i + 1; j < n; j++) { n       int cc = a[j] - a[i]; n       num[cc]++; n     } n   if (n - k == 1) { n     printf( 1 n ); n     return 0; n   } n   for (int i = 1;; i++) { n     int ans = 0; n     for (int j = i; j <= maxn; j += i) { n       ans += num[j]; n       if (ans > k) break; n     } n     if (ans <= limit[k] && check(i)) { n       printf( %d n , i); n       break; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n #pragma comment(linker,  /STACK:16777216 ) n const char DEBUG = 0; n mt19937 gen(chrono::high_resolution_clock::now().time_since_epoch().count()); n struct pp { n   int pos, id; n }; n long long pos[200000]; n int type[200000]; n int res[100000]; n vector<int> arr; n int get_id1(int x) { n   int l = 0, r = arr.size(); n   while (r - l > 1) { n     int m = (l + r) / 2; n     if (arr[m] >= x) n       r = m; n     else n       l = m; n   } n   return l; n } n int get_id2(int x) { n   int l = -1, r = arr.size() - 1; n   while (r - l > 1) { n     int m = (l + r) / 2; n     if (arr[m] <= x) n       l = m; n     else n       r = m; n   } n   return r; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cin.sync_with_stdio(0); n   cout.tie(0); n   cout.sync_with_stdio(0); n   int n, m; n   cin >> n >> m; n   for (int i = 0; i < n + m; i++) cin >> pos[i]; n   for (int i = 0; i < n + m; i++) cin >> type[i]; n   for (int i = 0; i < n + m; i++) n     if (type[i]) arr.push_back(pos[i]); n   for (int i = 0; i < n + m; i++) { n     if (type[i]) continue; n     long long d1 = 1000000000000000000LL, d2 = 1000000000000000000LL; n     int p1 = get_id1(pos[i]); n     int p2 = get_id2(pos[i]); n     d1 = abs(arr[p1] - pos[i]); n     d2 = abs(arr[p2] - pos[i]); n     if (d1 < d2) n       res[p1]++; n     else if (d2 < d1) n       res[p2]++; n     else { n       if (arr[p1] < arr[p2]) n         res[p1]++; n       else n         res[p2]++; n     } n   } n   for (int i = 0; i < m; i++) cout << res[i] <<    ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int base1 = 115019, mod1 = 1e9 + 13; n vector<int> pos[100005]; n int n, t[100005], a[100005]; n long long p1[100005], sum1[100005]; n struct node { n   int st, len; n   bool operator<(const node &A) const { n     if (len == A.len) return st < A.st; n     return len < A.len; n   } n }; n vector<node> S; n bool check(int x, int y) { n   if (y + (y - x) - 1 > n) return false; n   long long sx1 = n       ((sum1[y - 1] - sum1[x - 1] * p1[y - x]) % mod1 + mod1) % mod1; n   long long sy1 = n       ((sum1[y + y - x - 1] - sum1[y - 1] * p1[y - x]) % mod1 + mod1) % mod1; n   return sx1 == sy1; n } n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; ++i) scanf( %d , &a[i]), t[i] = a[i]; n   sort(t + 1, t + n + 1); n   int m = unique(t + 1, t + n + 1) - t - 1; n   p1[0] = 1; n   for (int i = 1; i <= n; ++i) { n     a[i] = lower_bound(t + 1, t + m + 1, a[i]) - t; n     pos[a[i]].push_back(i); n     p1[i] = p1[i - 1] * base1 % mod1; n     sum1[i] = (sum1[i - 1] * base1 + a[i]) % mod1; n   } n   for (int i = 1; i <= m; ++i) n     for (int j = 0; j < pos[i].size(); ++j) n       for (int k = j + 1; k < pos[i].size(); ++k) { n         int x = pos[i][j], y = pos[i][k]; n         if (check(x, y)) S.push_back((node){x, y - x}); n       } n   sort(S.begin(), S.end()); n   int now = 1; n   for (int i = 0; i < S.size(); ++i) { n     node p = S[i]; n     if (p.st < now) n       continue; n     else n       now = p.st + p.len; n   } n   printf( %d n , n - now + 1); n   for (int i = now; i <= n; ++i) printf( %d  , t[a[i]]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, p; n   string s, number; n   cin >> n; n   string name[n]; n   int taxi[n], pizza[n], cg[n], tax, pizz, cgc, taxmax = -1, pizzmax = -1, n                                                 cgcmax = -1; n   int taxifinal[n], pizzafinal[n], cgcfinal[n], ct = 0, cp = 0, cc = 0; n   for (int i = 0; i < n; i++) { n     cin >> p >> name[i]; n     tax = 0; n     pizz = 0; n     cgc = 0; n     for (int j = 0; j < p; j++) { n       cin >> number; n       if (((number[0] == number[3]) && (number[3] == number[6])) && n           ((number[0] == number[1]) && (number[3] == number[4]) && n            (number[6] == number[7]))) { n         tax++; n       } else if ((int(number[0]) > int(number[1])) && n                  (int(number[1]) > int(number[3])) && n                  (int(number[3]) > int(number[4])) && n                  (int(number[4]) > int(number[6])) && n                  (int(number[6]) > int(number[7]))) { n         pizz++; n       } else { n         cgc++; n       } n     } n     taxi[i] = tax; n     pizza[i] = pizz; n     cg[i] = cgc; n   } n   for (int i = 0; i < n; i++) { n     taxmax = max(taxmax, taxi[i]); n     pizzmax = max(pizzmax, pizza[i]); n     cgcmax = max(cgcmax, cg[i]); n   } n   for (int i = 0; i < n; i++) { n     if (taxmax == taxi[i]) { n       taxifinal[ct] = i; n       ct++; n     } n     if (pizzmax == pizza[i]) { n       pizzafinal[cp] = i; n       cp++; n     } n     if (cgcmax == cg[i]) { n       cgcfinal[cc] = i; n       cc++; n     } n   } n   cout <<  If you want to call a taxi, you should call: ; n   if (ct > 1) { n     for (int j = 0; j < ct - 1; j++) { n       cout <<     << name[taxifinal[j]] <<  , ; n     } n     cout <<     << name[taxifinal[ct - 1]] <<  .  << endl; n   } else { n     cout <<     << name[taxifinal[ct - 1]] <<  .  << endl; n   } n   cout <<  If you want to order a pizza, you should call: ; n   if (cp > 1) { n     for (int j = 0; j < cp - 1; j++) { n       cout <<     << name[pizzafinal[j]] <<  , ; n     } n     cout <<     << name[pizzafinal[cp - 1]] <<  .  << endl; n   } else { n     cout <<     << name[pizzafinal[cp - 1]] <<  .  << endl; n   } n   cout <<  If you want to go to a cafe with a wonderful girl, you should call: ; n   if (cc > 1) { n     for (int j = 0; j < cc - 1; j++) { n       cout <<     << name[cgcfinal[j]] <<  , ; n     } n     cout <<     << name[cgcfinal[cc - 1]] <<  .  << endl; n   } else { n     cout <<     << name[cgcfinal[cc - 1]] <<  .  << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   ; n   string s[10]; n   for (int i = 0; i < 8; i++) { n     cin >> s[i]; n   } n   bool ans = 1; n   for (int i = 0; i < 8 && ans; i++) { n     for (int k = 1; k < 8; k++) { n       if (s[i][k - 1] == s[i][k]) { n         ans = 0; n         break; n       } n     } n   } n   if (ans) { n     cout <<  YES  << endl; n   } else n     cout <<  NO  << endl; n   return 0; n } n


/* Clearink */ n  n #include <queue> n #include <cstdio> n #include <algorithm> n  n #define rep( i, l, r ) for ( int i = l, repEnd##i = r; i <= repEnd##i; ++i ) n #define per( i, r, l ) for ( int i = r, repEnd##i = l; i >= repEnd##i; --i ) n  n inline int rint() { n  int x = 0, f = 1, s = getchar(); n  for ( ; s <  0  ||  9  < s; s = getchar() ) f = s ==  -  ? -f : f; n  for ( ;  0  <= s && s <=  9 ; s = getchar() ) x = x * 10 + ( s ^  0  ); n  return x * f; n } n  n template<typename Tp> n inline void wint( Tp x ) { n  if ( x < 0 ) putchar(  -  ), x = -x; n  if ( 9 < x ) wint( x / 10 ); n  putchar( x % 10 ^  0  ); n } n  n const int MAXN = 1.5e3; n int n, m, a[MAXN + 5][MAXN + 5], b[MAXN + 5][MAXN + 5]; n int d[MAXN + 5], ocnt, opt[MAXN + 5], p[MAXN + 5], q[MAXN + 5], tmp[MAXN + 5]; n bool era[MAXN + 5]; n std::queue<int> que; n  n int main() { n  n = rint(), m = rint(); n  rep ( i, 1, n ) rep ( j, 1, m ) a[i][j] = rint(); n  rep ( i, 1, n ) rep ( j, 1, m ) b[i][j] = rint(); n  rep ( i, 2, n ) rep ( j, 1, m ) d[j] += b[i - 1][j] > b[i][j]; n  rep ( i, 1, m ) if ( !d[i] ) que.push( i ); n  while ( !que.empty() ) { n   int c = que.front(); que.pop(); n   opt[++ocnt] = c; n   rep ( i, 2, n ) if ( b[i - 1][c] < b[i][c] && !era[i] ) { n    era[i] = true; n    rep ( j, 1, m ) if ( b[i - 1][j] > b[i][j] && !--d[j] ) { n     que.push( j ); n    } n   } n  } n  rep ( i, 1, n ) q[i] = i; n  per ( k, ocnt, 1 ) { n   rep ( i, 1, n ) p[i] = i; n   std::sort( p + 1, p + n + 1, [=]( const int i, const int j ) { n    int u = a[q[i]][opt[k]], v = a[q[j]][opt[k]]; n    return u != v ? u < v : i < j; n   } ); n   rep ( i, 1, n ) tmp[i] = q[i]; n   rep ( i, 1, n ) q[i] = tmp[p[i]]; n  } n  rep ( i, 1, n ) rep ( j, 1, m ) if ( a[q[i]][j] != b[i][j] ) { n   return puts(  -1  ), 0; n  } n  wint( ocnt ), putchar(   n  ); n  per ( i, ocnt, 1 ) wint( opt[i] ), putchar( i > 1 ?     :   n  ); n  return 0; n } n  n


#include <bits/stdc++.h> n using namespace std; n int main() { n   std::ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   long long int n; n   cin >> n; n   long long int a[n]; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n   } n   map<long long int, long long int> m; n   m[0] = 0; n   long long int sum = 0, ans = 0, k = (-1); n   for (int i = 0; i < n; i++) { n     sum += a[i]; n     if (m.count(sum)) { n       if (m[sum] >= k) { n         ans++; n         k = (i - 1); n       } n     } n     m[sum] = i; n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int loc[200000 + 10]; n int n; n int ans[4]; n int fnext(int y) { n   int l = 1, r = n + 1, mid = (l + r) / 2; n   while (l < r) { n     if (loc[mid] <= y) n       l = mid + 1; n     else n       r = mid; n     mid = (l + r) / 2; n   } n   return mid; n } n int ok(int x) { n   int i, j; n   int z = 1; n   for (i = 1; i <= 3; i++) { n     z = fnext(loc[z] + x); n     ans[i] = z; n     if (z >= n + 1) return 1; n   } n   return 0; n } n int main() { n   while (scanf( %d , &n) != EOF) { n     int i, j, k; n     for (i = 1; i <= n; i++) { n       scanf( %d , &loc[i]); n     } n     sort(loc + 1, loc + n + 1); n     int r = (loc[n] - loc[1]); n     int l = 0, mid; n     while (l < r) { n       mid = (r + l) / 2; n       if (ok(mid)) n         r = mid; n       else n         l = mid + 1; n     } n     ok(l); n     double radius = l * 1.0 / 2.0; n     double radar1 = (loc[ans[1] - 1] + loc[1]) * 1.0 / 2.0; n     double radar2 = (loc[ans[2] - 1] + loc[ans[1]]) / 2.0; n     double radar3 = (loc[ans[3] - 1] + loc[ans[2]]) / 2.0; n     printf( %.6f n , radius); n     printf( %.6f  , radar1); n     printf( %.6f  , radar2); n     printf( %.6f n , radar3); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int x, y, x1, y1; n   cin >> x >> y >> x1 >> y1; n   int X = abs(x1 - x), Y = abs(y1 - y); n   cout << max(X, Y); n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( O3 ) n using namespace std; n using ii = long long; n int main() { n   int n, k; n   scanf( %d%d , &n, &k); n   vector<int> v(n); n   vector<ii> s(n); n   for (int &x : v) { n     scanf( %d , &x); n   } n   for (int i = n - 2; i + 1; --i) { n     s[i] = v[i + 1] + s[i + 1]; n   } n   s.pop_back(); n   ii r = v[0] + (n > 1 ? s[0] : 0); n   sort(s.begin(), s.end(), greater<ii>()); n   r += accumulate(s.begin(), s.begin() + k - 1, 0ll); n   printf( %lld n , r); n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 55, MAXM = 20020; n int n, m, k, acc[MAXN][MAXM], dp[MAXN][MAXM], ans; n struct no { n   int beg, end, mid, mx, lz; n   no *l, *r; n   no(int beg, int end) n       : beg(beg), end(end), mid((beg + end) >> 1), mx(0), lz(0) { n     if (beg != end) l = new no(beg, mid), r = new no(mid + 1, end); n   } n   void refresh() { n     if (!lz) return; n     mx += lz; n     if (beg != end) l->lz += lz, r->lz += lz; n     lz = 0; n   } n   void upd(int a, int b, int inc) { n     refresh(); n     if (end < a || b < beg) return; n     if (a <= beg && end <= b) return lz += inc, refresh(); n     l->upd(a, b, inc), r->upd(a, b, inc); n     mx = max(l->mx, r->mx); n   } n   void set(int pos, int val) { n     refresh(); n     if (beg == end) return void(mx = val); n     (pos <= mid ? l : r)->set(pos, val); n     mx = max(l->mx, r->mx); n   } n   int get(int a, int b) { n     refresh(); n     if (end < a || b < beg) return 0; n     if (a <= beg && end <= b) return mx; n     return max(l->get(a, b), r->get(a, b)); n   } n   void print() { n     refresh(); n     if (beg == end) return printf( %d  , mx), void(); n     l->print(), r->print(); n   } n }; n int main() { n   scanf( %d %d %d , &n, &m, &k); n   for (int i = 1; i <= n; ++i) n     for (int j = 1; j <= m; ++j) n       scanf( %d , &acc[i][j]), acc[i][j] += acc[i][j - 1]; n   no seg(1, m - k + 1); n   for (int i = n; i >= 1; --i) { n     for (int j = 1; j <= k; ++j) n       seg.upd(1, j, -(acc[i + 1][j] - acc[i + 1][j - 1])); n     for (int j = 1; j <= m - k + 1; ++j) { n       int aux = acc[i][j + k - 1] - acc[i][j - 1] + acc[i + 1][j + k - 1] - n                 acc[i + 1][j - 1]; n       if (i == n) { n         dp[i][j] = aux; n         continue; n       } n       dp[i][j] = max(dp[i][j], seg.get(j - k + 1, j + k - 1)); n       if (j > k) dp[i][j] = max(dp[i][j], seg.get(1, j - k)); n       if (j + k <= m - k + 1) n         dp[i][j] = max(dp[i][j], seg.get(j + k, m - k + 1)); n       dp[i][j] += aux; n       seg.upd(max(1, j - k + 1), j, (acc[i + 1][j] - acc[i + 1][j - 1])); n       seg.upd(j + 1, j + k, -(acc[i + 1][j + k] - acc[i + 1][j + k - 1])); n     } n     for (int j = 1; j <= m - k + 1; ++j) seg.set(j, dp[i][j]); n   } n   printf( %d n , seg.get(1, m - k + 1)); n } n


#include <bits/stdc++.h> n using namespace std; n int n; n int d[262144][4]; n map<int, int> comp; n int r[262144], R, pr[262144]; n vector<int> vec; n bool cmp(int a, int b) { return d[a][1] > d[b][1]; } n struct BIT { n   int m[262144 * 2]; n   vector<int> v[262144]; n   void init() { n     int i; n     for (i = 0; i < n; i++) v[comp[d[i][0]]].push_back(i); n     for (i = 0; i < 262144; i++) { n       if (v[i].size()) { n         sort(v[i].begin(), v[i].end(), cmp); n         m[262144 + i] = d[v[i].back()][1]; n       } else n         m[262144 + i] = 2147483647; n     } n     for (i = 262144 - 1; i >= 1; i--) n       m[i] = m[i * 2] < m[i * 2 + 1] ? m[i * 2] : m[i * 2 + 1]; n   } n   void gohelp(int p, int i) { n     if (m[p] > d[i][3]) return; n     if (p < 262144) { n       gohelp(p * 2, i); n       gohelp(p * 2 + 1, i); n     } else { n       while (v[p - 262144].size()) { n         int j = v[p - 262144].back(); n         if (d[j][1] <= d[i][3]) { n           vec.push_back(j); n           r[j] = R; n           pr[j] = i; n           v[p - 262144].pop_back(); n         } else n           break; n       } n       if (v[p - 262144].size()) n         m[p] = d[v[p - 262144].back()][1]; n       else n         m[p] = 2147483647; n       for (p /= 2; p; p /= 2) n         m[p] = m[p * 2] < m[p * 2 + 1] ? m[p * 2] : m[p * 2 + 1]; n     } n   } n   void go(int p, int i) { n     p += 262144; n     gohelp(p, i); n     for (; p > 1; p /= 2) { n       if (p & 1) gohelp(p - 1, i); n     } n   } n } bit; n int main() { n   int i; n   scanf( %d , &n); n   comp[0] = 1; n   for (i = 0; i < n; i++) { n     scanf( %d%d%d%d , &d[i][0], &d[i][1], &d[i][2], &d[i][3]); n     comp[d[i][0]] = comp[d[i][2]] = 1; n   } n   i = 0; n   for (auto& it : comp) it.second = i++; n   bit.init(); n   memset(r, -1, sizeof(r)); n   vector<int> vecpr; n   vecpr.push_back(n); n   while (vecpr.size()) { n     vec.clear(); n     R++; n     for (int i : vecpr) bit.go(comp[d[i][2]], i); n     vecpr = vec; n   } n   printf( %d n , r[n - 1]); n   if (r[n - 1] != -1) { n     vector<int> path; n     for (i = n - 1; r[i] > 1; i = pr[i]) path.push_back(i); n     path.push_back(i); n     for (i = path.size() - 1; i >= 0; i--) printf( %d  , path[i] + 1); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX_N = 1e5 + 5; n bool mark[MAX_N]; n int main() { n   ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); n   int n; n   cin >> n; n   for (int i = 0; i < n - 1; i++) { n     int a; n     cin >> a; n     mark[a - 1] = true; n   } n   for (int i = 0; i < n; i++) n     if (!mark[i]) cout << i + 1; n } n


#include <bits/stdc++.h> n using namespace std; n char a[100]; n int main() { n   int i, l, c = 0; n   scanf( %s , a); n   l = strlen(a); n   for (i = 1; i < l; i++) { n     if (a[i] <=  Z ) { n       c++; n     } n   } n   int t = 0; n   if (a[1] <=  Z  && c >= l - 1) t++; n   if (t != 0) { n     for (i = 0; i < l; i++) { n       if (a[i] >=  a ) { n         a[i] = a[i] -  a  +  A ; n       } else { n         a[i] = a[i] -  A  +  a ; n       } n     } n   } n   printf( %s , a); n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 105; n const int mod = 998244353; n const double Pi = acos(-1.0); n const long long INF = 1e18; n const int G = 3, Gi = 332748118; n long long qpow(long long a, long long b) { n   long long res = 1; n   while (b) { n     if (b) res = (res * a) % mod; n     a = (a * a) % mod; n     b >>= 1; n   } n   return res; n } n long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } n int T, n, m; n long long dp[105][105], a[105][105]; n int main() { n   scanf( %d , &T); n   while (T--) { n     scanf( %d%d , &n, &m); n     for (int i = 1; i <= n; ++i) { n       for (int j = 1; j <= m; ++j) scanf( %lld , &a[i][j]); n     } n     long long res = INF; n     for (int x = 1; x <= n; ++x) { n       for (int y = 1; y <= m; ++y) { n         for (int i = 0; i <= n; ++i) n           for (int j = 0; j <= m; ++j) dp[i][j] = INF; n         dp[1][0] = 0; n         for (int i = 1; i <= n; ++i) { n           for (int j = 1; j <= m; ++j) { n             long long dis = abs(x - i) + abs(y - j); n             if (i <= x && j <= y && a[i][j] >= a[x][y] - dis) { n               dp[i][j] = n                   min(dp[i - 1][j], dp[i][j - 1]) + a[i][j] - (a[x][y] - dis); n             } n             if (i >= x && j >= y && a[i][j] >= a[x][y] + dis) { n               dp[i][j] = n                   min(dp[i - 1][j], dp[i][j - 1]) + a[i][j] - (a[x][y] + dis); n             } n           } n         } n         res = min(res, dp[n][m]); n       } n     } n     printf( %lld n , res); n   } n   return 0; n } n


#include <bits/stdc++.h> n const int MAXN = 100010, inf = 2147483233; n using namespace std; n inline int read() { n   int x = 0, f = 1; n   char ch = getchar(); n   while (!isdigit(ch)) { n     if (ch ==  - ) f = -1; n     ch = getchar(); n   } n   while (isdigit(ch)) { n     x = x * 10 + ch -  0 ; n     ch = getchar(); n   } n   return x * f; n } n int n, q, tot, nxt[MAXN << 1], to[MAXN << 1], fst[MAXN], cnt; n int fa[MAXN], hsh[MAXN], dep[MAXN], f[MAXN][25], HSH[MAXN], size[MAXN]; n int mx[MAXN << 2][2], mn[MAXN << 2][2], mx1, mx2, mn1, mn2; n namespace hh { n using namespace std; n inline int read() { n   int x = 0, f = 1; n   char ch = getchar(); n   for (; !isdigit(ch); ch = getchar()) n     if (ch ==  - ) f = -f; n   for (; isdigit(ch); ch = getchar()) x = 10 * x + ch -  0 ; n   return x * f; n } n const int maxn = 500010; n int n, m, lastans; n int first[maxn], to[maxn << 1], nx[maxn << 1], cnt; n inline void add(int u, int v) { n   to[++cnt] = v; n   nx[cnt] = first[u]; n   first[u] = cnt; n } n inline void ins(int u, int v) { n   add(u, v); n   add(v, u); n } n namespace LCA { n int dep[maxn], bl[maxn], fa[maxn], size[maxn]; n inline void dfs1(int x) { n   size[x] = 1; n   for (int i = first[x]; i; i = nx[i]) { n     if (to[i] == fa[x]) continue; n     fa[to[i]] = x; n     dep[to[i]] = dep[x] + 1; n     dfs1(to[i]); n     size[x] += size[to[i]]; n   } n } n inline void dfs2(int x, int col) { n   int k = 0; n   bl[x] = col; n   for (int i = first[x]; i; i = nx[i]) n     if (dep[to[i]] > dep[x] && size[to[i]] > size[k]) k = to[i]; n   if (!k) return; n   dfs2(k, col); n   for (int i = first[x]; i; i = nx[i]) n     if (dep[to[i]] > dep[x] && to[i] != k) dfs2(to[i], to[i]); n } n inline int lca(int x, int y) { n   while (bl[x] != bl[y]) { n     if (dep[bl[x]] < dep[bl[y]]) swap(x, y); n     x = fa[bl[x]]; n   } n   return dep[x] > dep[y] ? y : x; n } n }  // namespace LCA n namespace SEG { n int root[maxn][2], ls[maxn << 4], rs[maxn << 4], val[maxn << 4], size; n inline void Insert(int &x, int l, int r, int pos, int va) { n   if (!x) x = ++size; n   val[x] += va; n   if (l == r) return; n   int mid = (l + r) >> 1; n   if (pos <= mid) n     Insert(ls[x], l, mid, pos, va); n   else n     Insert(rs[x], mid + 1, r, pos, va); n } n inline int query(int x, int l, int r, int L, int R) { n   if (!x) return 0; n   if (L <= l && r <= R) return val[x]; n   int mid = (l + r) >> 1, ans = 0; n   if (L <= mid) ans += query(ls[x], l, mid, L, R); n   if (R > mid) ans += query(rs[x], mid + 1, r, L, R); n   return ans; n } n }  // namespace SEG n inline int q_dis(int x, int y) { n   return LCA::dep[x] + LCA::dep[y] - (LCA::dep[LCA::lca(x, y)] << 1); n } n int size[maxn], f[maxn], vis[maxn], d[maxn], v[maxn], son, root; n int nfa[maxn]; n inline void solve(int rt, int type, int x, int fa) { n   SEG::Insert(SEG::root[rt][type], 0, n, d[x], v[x]); n   for (int i = first[x]; i; i = nx[i]) { n     if (to[i] == fa || vis[to[i]]) continue; n     d[to[i]] = d[x] + 1; n     solve(rt, type, to[i], x); n   } n } n inline void getroot(int x, int fa) { n   size[x] = 1, f[x] = 0; n   for (int i = first[x]; i; i = nx[i]) { n     if (to[i] == fa || vis[to[i]]) continue; n     getroot(to[i], x); n     size[x] += size[to[i]]; n     f[x] = max(f[x], size[to[i]]); n   } n   f[x] = max(f[x], son - size[x]); n   if (f[x] < f[root]) root = x; n } n inline void work(int x) { n   vis[x] = 1; n   d[x] = 0; n   solve(x, 0, x, 0); n   for (int i = first[x]; i; i = nx[i]) { n     if (vis[to[i]]) continue; n     son = size[to[i]]; n     root = 0; n     d[to[i]] = 1; n     getroot(to[i], 0); n     solve(root, 1, to[i], x); n     nfa[root] = x; n     work(root); n   } n } n inline int query(int x, int k) { n   int ret = SEG::query(SEG::root[x][0], 0, n, 0, k); n   for (int i = x; nfa[i]; i = nfa[i]) { n     int du = q_dis(x, nfa[i]); n     ret += SEG::query(SEG::root[nfa[i]][0], 0, n, 0, k - du); n     ret -= SEG::query(SEG::root[i][1], 0, n, 0, k - du); n   } n   return ret; n } n inline void update(int x, int k) { n   int delt = k - SEG::query(SEG::root[x][0], 0, n, 0, 0); n   SEG::Insert(SEG::root[x][0], 0, n, 0, delt); n   for (int i = x; nfa[i]; i = nfa[i]) { n     int du = q_dis(x, nfa[i]); n     SEG::Insert(SEG::root[nfa[i]][0], 0, n, du, delt); n     SEG::Insert(SEG::root[i][1], 0, n, du, delt); n   } n } n int main() { n   n = read(), m = read(); n   for (int i = 1; i <= n; i++) v[i] = read(); n   for (int i = 2; i <= n; i++) { n     int u = read(), v = read(); n     ins(u, v); n   } n   LCA::dfs1(1); n   LCA::dfs2(1, 1); n   f[0] = son = n; n   getroot(1, 0); n   work(root); n   while (m--) { n     int opt = read(), x = read() ^ lastans, y = read() ^ lastans; n     if (opt) n       update(x, y); n     else n       printf( %d n , lastans = query(x, y)); n   } n } n }  // namespace hh n void dfs(int x) { n   hsh[x] = ++tot, HSH[tot] = x; n   dep[x] = dep[f[x][0]] + 1; n   for (int i = 1; i <= 23; i++) f[x][i] = f[f[x][i - 1]][i - 1]; n   for (int i = fst[x]; i; i = nxt[i]) dfs(to[i]); n } n int lca(int u, int v) { n   if (dep[u] < dep[v]) swap(u, v); n   int t = dep[u] - dep[v]; n   for (int i = 23; i >= 0; i--) n     if ((1 << i) & t) u = f[u][i]; n   if (u == v) return u; n   for (int i = 23; i >= 0; i--) n     if (f[u][i] != f[v][i]) u = f[u][i], v = f[v][i]; n   return f[u][0]; n } n void pushup(int x) { n   mx[x][0] = max(mx[(x << 1)][0], mx[((x << 1) | 1)][0]); n   mx[x][1] = max(min(mx[(x << 1)][0], mx[((x << 1) | 1)][0]), n                  max(mx[(x << 1)][1], mx[((x << 1) | 1)][1])); n   mn[x][0] = min(mn[(x << 1)][0], mn[((x << 1) | 1)][0]); n   mn[x][1] = min(max(mn[(x << 1)][0], mn[((x << 1) | 1)][0]), n                  min(mn[(x << 1)][1], mn[((x << 1) | 1)][1])); n } n void build(int x, int l, int r) { n   if (l == r) { n     mx[x][1] = 0; n     mn[x][1] = inf; n     mx[x][0] = mn[x][0] = hsh[l]; n     return; n   } n   int mid = l + r >> 1; n   build((x << 1), l, mid); n   build(((x << 1) | 1), mid + 1, r); n   pushup(x); n } n void query(int x, int l, int r, int a, int b) { n   if (a <= l && r <= b) { n     if (mx[x][0] > mx1) n       mx2 = mx1, mx1 = mx[x][0]; n     else if (mx[x][0] > mx2) n       mx2 = mx[x][0]; n     if (mx[x][1] > mx2) mx2 = mx[x][1]; n     if (mn[x][0] < mn1) n       mn2 = mn1, mn1 = mn[x][0]; n     else if (mn[x][0] < mn2) n       mn2 = mn[x][0]; n     if (mn[x][1] < mn2) mn2 = mn[x][1]; n     return; n   } n   int mid = l + r >> 1; n   if (a <= mid) query((x << 1), l, mid, a, b); n   if (b > mid) query(((x << 1) | 1), mid + 1, r, a, b); n } n void init() { n   cin >> n >> q; n   for (int i = 2; i <= n; i++) { n     f[i][0] = read(); n     to[++cnt] = i, nxt[cnt] = fst[f[i][0]], fst[f[i][0]] = cnt; n   } n } n void work() { n   dfs(1); n   build(1, 1, n); n } n int a, b; n void gogo() { n   mx1 = mx2 = 0; n   mn1 = mn2 = inf; n   query(1, 1, n, a, b); n } n void print() { n   while (q--) { n     int l1, l2; n     cin >> a >> b; n     gogo(); n     l1 = lca(HSH[mx1], HSH[mn2]); n     l2 = lca(HSH[mx2], HSH[mn1]); n     if (dep[l1] > dep[l2]) n       printf( %d %d n , HSH[mn1], dep[l1] - 1); n     else n       printf( %d %d n , HSH[mx1], dep[l2] - 1); n   } n } n int main() { n   init(); n   work(); n   print(); n } n


#include <bits/stdc++.h> n using namespace std; n struct node { n   int from, to, next, w, dir, id; n } e[1500000]; n int head[350000]; n int in[350000]; n int out[350000]; n int ans[350000]; n int n, m, cont; n void add(int from, int to, int w, int dir, int id) { n   e[cont].from = from; n   e[cont].to = to; n   e[cont].w = w; n   e[cont].dir = dir; n   e[cont].id = id; n   e[cont].next = head[from]; n   head[from] = cont++; n } n void Top() { n   queue<int> s; n   s.push(1); n   in[1] = out[1] = 0; n   while (!s.empty()) { n     int u = s.front(); n     s.pop(); n     for (int i = head[u]; i != -1; i = e[i].next) { n       int v = e[i].to; n       int w = e[i].w; n       int dir = e[i].dir; n       if (v == 1 || (in[v] == out[v] && v != n)) continue; n       if (u == 1 || v == n) { n         if (u == 1) { n           ans[e[i].id] = dir; n           in[v] += w; n         } else { n           ans[e[i].id] = dir; n         } n       } else { n         if (in[v] != out[v]) { n           in[v] += w; n           ans[e[i].id] = dir; n         } else n           ans[e[i].id] = 1 - dir; n       } n       if (in[v] == out[v] && v != n) { n         s.push(v); n       } n     } n   } n   for (int i = 1; i <= m; i++) printf( %d n , ans[i]); n } n int main() { n   while (~scanf( %d%d , &n, &m)) { n     cont = 0; n     memset(in, 0, sizeof(in)); n     memset(out, 0, sizeof(out)); n     memset(head, -1, sizeof(head)); n     for (int i = 1; i <= m; i++) { n       int x, y, w; n       scanf( %d%d%d , &x, &y, &w); n       add(x, y, w, 0, i); n       add(y, x, w, 1, i); n       out[y] += w; n       out[x] += w; n     } n     for (int i = 1; i <= n; i++) out[i] = out[i] / 2; n     Top(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n void solution() { n   int n, k; n   cin >> n >> k; n   vector<long long> v(n * k + 1, 0), brr(n * k + 1, 0); n   long long sum = 0; n   for (int i = 1; i <= n * k; i++) { n     cin >> v[i]; n     brr[i] = v[i]; n   } n   brr[0] = INT_MAX; n   sort(brr.rbegin(), brr.rend()); n   if (n % 2 == 0) { n     int right = n / 2 + 1; n     int i = right; n     int j = 0; n     while (j < k) { n       sum = sum + brr[i]; n       i = i + right; n       j++; n     } n   } else { n     int right = n / 2 + n % 2; n     int i = right; n     int j = 0; n     while (j < k) { n       sum = sum + brr[i]; n       i = i + right; n       j++; n     } n   } n   cout << sum << endl; n } n int main() { n   int t; n   cin >> t; n   while (t--) { n     solution(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long MXN = 80 + 10; n const long long MX5 = 4e5 + 10; n const long long MX6 = 1e6 + 10; n const long long LOG = 20; n const long long INF = 8e18; n const double eps = 1e-9; n const long long MOD = 1e9 + 7; n long long power(long long a, long long b, long long md) { n   return (!b ? 1 n              : (b & 1 ? a * power(a * a % md, b / 2, md) % md n                       : power(a * a % md, b / 2, md) % md)); n } n long long bmm(long long a, long long b) { n   return (a % b == 0 ? b : bmm(b, a % b)); n } n string base2(long long n) { n   string a =   ; n   while (n >= 2) { n     a += (char)(n % 2 +  0 ); n     n /= 2; n   } n   a += (char)(n +  0 ); n   reverse((a).begin(), (a).end()); n   return a; n } n long long n; n long long PS[MX5], Ans[MX5], ex[MX5]; n vector<long long> second, T; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   cin >> n; n   for (int i = 0; i < n; i++) { n     long long x; n     cin >> x; n     second.push_back(x); n   } n   for (int i = 0; i < n; i++) { n     long long x; n     cin >> x; n     T.push_back(x); n   } n   PS[0] = T[0]; n   for (int i = 1; i < n; i++) PS[i] = PS[i - 1] + T[i]; n   PS[n] = INF; n   for (int i = 0; i < n; i++) { n     long long men = (i - 1 < 0 ? 0 : PS[i - 1]); n     if (second[i] <= T[i]) { n       ex[i] += second[i]; n       continue; n     } n     long long l = i, r = n; n     while (r - l > 1) { n       long long mid = (l + r) / 2; n       if (PS[mid] - men <= second[i]) { n         l = mid; n       } else { n         r = mid; n       } n     } n     Ans[l + 1]--, Ans[i]++; n     if (PS[l] - men < second[i]) { n       ex[l + 1] += second[i] - PS[l] + men; n     } n   } n   for (int i = 1; i < n; i++) Ans[i] += Ans[i - 1]; n   for (int i = 0; i < n; i++) { n     cout << Ans[i] * T[i] + ex[i] <<    ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int points(int p, int t) { n   int first = 75 * p; n   int second = 250 * p - p * t; n   return max(first, second); n } n int main() { n   int a, b, c, d; n   scanf( %d %d %d %d , &a, &b, &c, &d); n   int misha = points(a, c); n   int vasia = points(b, d); n   if (misha > vasia) { n     cout <<  Misha  << endl; n   } else if (vasia > misha) { n     cout <<  Vasya  << endl; n   } else { n     cout <<  Tie  << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int mod = 998244353; n const int maxn = 50; n int k, w, h; n int read() { n   int x = 0, y = 1; n   char ch = getchar(); n   while (ch <  0  || ch >  9 ) { n     if (ch ==  - ) y = -1; n     ch = getchar(); n   } n   while (ch >=  0  && ch <=  9 ) n     x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar(); n   return x * y; n } n int pw[5]; n inline int add(int x) { return x >= mod ? x - mod : x; } n inline int sub(int x) { return x < 0 ? x + mod : x; } n inline int power(int x, int b) { n   int res = 1; n   while (b) { n     if (b & 1) res = 1ll * res * x % mod; n     x = 1ll * x * x % mod; n     b >>= 1; n   } n   return res; n } n vector<int> p[6]; n int pos[maxn]; n void dfs1(int d, int v, int S) { n   if (!d) { n     v = add(v + 1ll * p[d][0] * w % mod); n     pos[p[d][0]] = 1; n     if (v == S) { n       for (int i = 1; i <= (1 << k); i++) printf( %d  , pos[i]); n       puts(  ); n       exit(0); n     } n     return; n   } n   int len = (1 << (d - 1)); n   p[d - 1].resize(len); n   for (int s = 0; s < (1 << len); s++) { n     int val = 0; n     for (int i = 0; i < len; i++) { n       int u = p[d][2 * i], v = p[d][2 * i + 1]; n       if (s & (1 << i)) n         p[d - 1][i] = v, pos[u] = len + 1, n               val = add(val + 1ll * u * pw[d - 1] % mod); n       else n         p[d - 1][i] = u, pos[v] = len + 1, n               val = add(val + 1ll * v * pw[d - 1] % mod); n     } n     dfs1(d - 1, add(v + val), S); n   } n   return; n } n unordered_map<int, bool> mp[(1 << 16) + 5]; n void dfs2(int S, int d, int v) { n   if (!d) { n     v = add(v + 1ll * w * p[d][0] % mod); n     mp[S][v] = 1; n     return; n   } n   int len = (1 << (d - 1)); n   p[d - 1].resize(len); n   for (int s = 0; s < (1 << len); s++) { n     int val = 0; n     for (int i = 0; i < len; i++) { n       int u = p[d][2 * i], v = p[d][2 * i + 1]; n       if (s & (1 << i)) n         p[d - 1][i] = v, val = add(val + 1ll * u * pw[d - 1] % mod); n       else n         p[d - 1][i] = u, val = add(val + 1ll * v * pw[d - 1] % mod); n     } n     dfs2(S, d - 1, add(v + val)); n   } n   return; n } n void dfs3(int d, int v) { n   if (d == 3) { n     int s = 0; n     for (int i = 7; i >= 0; i--) s <<= 2, s |= (p[d][i] - 4 * i - 1); n     if (mp[s][sub(h - v)]) { n       dfs1(d, v, h); n       exit(0); n     } n     return; n   } n   int len = (1 << (d - 1)); n   p[d - 1].resize(len); n   for (int s = 0; s < (1 << len); s++) { n     int val = 0; n     for (int i = 0; i < len; i++) { n       int u = p[d][2 * i], v = p[d][2 * i + 1]; n       if (s & (1 << i)) n         p[d - 1][i] = v, pos[u] = len + 1, n               val = add(val + 1ll * u * pw[d - 1] % mod); n       else n         p[d - 1][i] = u, pos[v] = len + 1, n               val = add(val + 1ll * v * pw[d - 1] % mod); n     } n     dfs3(d - 1, add(v + val)); n   } n   return; n } n int main() { n   k = read(); n   w = read(); n   h = read(); n   for (int i = 0; i <= 4; i++) pw[i] = power(w, (1 << i) + 1); n   if (k <= 4) { n     p[k].resize(1 << k); n     for (int i = 0; i < p[k].size(); i++) p[k][i] = i + 1; n     dfs1(k, 0, h); n     puts( -1 ); n     return 0; n   } n   for (int s = 0; s < (1 << 16); s++) { n     p[3].resize(8); n     for (int i = 0; i < 8; i++) { n       int op = (s >> (2 * i)) & 3; n       p[3][i] = 4 * i + op + 1; n     } n     dfs2(s, 3, 0); n   } n   p[5].resize(32); n   for (int i = 0; i < p[5].size(); i++) p[5][i] = i + 1; n   dfs3(k, 0); n   puts( -1 ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 6000 + 10; n int n, t, arr[MAXN][MAXN]; n void dfs(int i, int j, int val) { n   arr[i][j] += val; n   if (arr[i][j] < 4) return; n   int me = arr[i][j] / 4; n   arr[i][j] %= 4; n   dfs(i + 1, j, me); n   dfs(i - 1, j, me); n   dfs(i, j + 1, me); n   dfs(i, j - 1, me); n   return; n } n int main() { n   ios::sync_with_stdio(0); n   cin >> n >> t; n   dfs(MAXN / 2, MAXN / 2, n); n   for (int i = 0; i < t; i++) { n     int l, r; n     cin >> l >> r; n     l += MAXN / 2; n     r += MAXN / 2; n     if (l < 0 || r < 0 || l > MAXN || r > MAXN) { n       cout << 0 << endl; n       continue; n     } n     cout << arr[l][r] << endl; n   } n   cin >> n; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e6 + 5; n struct edge { n   int x, y, w, p; n   edge() {} n   void input() { scanf( %d%d%d%d , &x, &y, &w, &p); } n } E[N], EE[N]; n int n; n vector<int> G[N]; n long long W[N], WW[N]; n void dfs(int x, int y, int id, int mi) { n   if (id) { n     int tmp = EE[id].p - E[id].p; n     tmp = min(mi, tmp); n     E[id].p += tmp; n     E[id].w += tmp; n     mi = min(mi - tmp, E[id].p - (int)W[y]); n     WW[id] = tmp; n   } n   for (int i = 0; i < G[y].size(); i++) { n     int ID = G[y][i]; n     if (id == 0) mi = 2e9; n     dfs(E[ID].x, E[ID].y, ID, mi); n     mi -= WW[ID]; n     WW[id] += WW[ID]; n   } n } n void dfs(int x, int y, int id) { n   for (int i = 0; i < G[y].size(); i++) { n     int ID = G[y][i]; n     dfs(E[ID].x, E[ID].y, ID); n   } n   if (id == 0) return; n   if (E[id].p < W[y]) { n     puts( -1 ); n     exit(0); n   } n   long long tmp = min(E[id].p - W[y], (long long)E[id].w - 1); n   E[id].p -= tmp; n   E[id].w -= tmp; n   W[x] += W[y]; n   W[x] += E[id].w; n } n int main() { n   scanf( %d , &n); n   for (int i = 1; i < n; i++) { n     E[i].input(); n     EE[i] = E[i]; n     G[E[i].x].push_back(i); n   } n   dfs(0, 1, 0); n   dfs(0, 1, 0, 2e9); n   cout << n << endl; n   for (int i = 1; i < n; i++) { n     printf( %d %d %d %d n , E[i].x, E[i].y, E[i].w, E[i].p); n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long unsigned int n; n long long unsigned int val(long long unsigned int x, long long unsigned int k) { n   if (x >= 1e10) return n + 1; n   long long unsigned int ans = x * (x - 1); n   ans /= 2; n   long long unsigned int kt = k; n   if (ans > n) return n + 1; n   while (k--) { n     x *= 2; n     if (x > 1e19) return n + 1; n   } n   for (int i = 1; i <= kt; i++) { n     ans = ans + x / 2; n     if (ans > n) return n + 1; n     x /= 2; n   } n   if (ans > n) return n + 1; n   return ans; n } n long long unsigned int calc(long long unsigned int k) { n   long long unsigned int lo = 0; n   long long unsigned int hi = 1e10; n   long long unsigned int mid; n   while (hi - lo > 1) { n     mid = (hi + lo) / 2; n     if (val(2 * mid - 1, k) >= n) n       hi = mid; n     else n       lo = mid; n   } n   if (val(2 * hi - 1, k) == n) { n     return (2 * hi - 1) * (1LL << k); n   } n   return 0; n } n int main() { n   cin >> n; n   long long unsigned int g; n   vector<long long unsigned int> ans; n   for (int i = 0; i <= 60; i++) { n     g = calc(i); n     if (g != 0) ans.push_back(g); n   } n   sort(ans.begin(), ans.end()); n   for (auto x : ans) { n     cout << x <<    ; n   } n   if (ans.size() == 0) cout << -1; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int i, j, t; n   int n; n   int a[100005]; n   int b[100005]; n   cin >> n; n   for (i = 0; i < n; i++) { n     cin >> a[i]; n     b[i] = a[i]; n   } n   sort(a, a + n); n   int cnt = 0; n   for (i = 0; i < n; i++) { n     if (a[i] != b[i]) cnt++; n   } n   if (cnt == 0 || cnt == 2) n     printf( YES n ); n   else n     printf( NO n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int st[200005]; n int main() { n   int tam1, tam2, i; n   string s, t; n   cin >> s >> t; n   long long r = 0; n   tam1 = s.size(); n   tam2 = t.size(); n   st[0] = 0; n   for (i = 0; i < tam2; i++) { n     st[i + 1] = st[i] + (t[i] -  0 ); n   } n   for (i = 0; i < tam1; i++) { n     if (s[i] ==  0 ) { n       r += (st[tam2 - tam1 + i + 1] - st[i]); n     } else { n       r += (tam2 - tam1 + 1 - (st[tam2 - tam1 + i + 1] - st[i])); n     } n   } n   cout << r << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, a[10]; n char c[100007]; n int main() { n   scanf( %d , &n); n   scanf( %s , &c); n   for (int i = 0; i < n; i++) { n     if (c[i] ==  L ) { n       for (int j = 0; j < 10; j++) { n         if (a[j] == 0) { n           a[j] = 1; n           break; n         } n       } n     } else if (c[i] ==  R ) { n       for (int j = 9; j >= 0; j--) { n         if (a[j] == 0) { n           a[j] = 1; n           break; n         } n       } n     } else { n       a[c[i] -  0 ] = 0; n     } n   } n   for (int i = 0; i <= 9; i++) { n     printf( %d , a[i]); n   } n   printf(  n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   int T; n   cin >> T; n   for (int t = 0; t < T; ++t) { n     long long int n; n     long long int a, b; n     cin >> n >> a >> b; n     string s; n     cin >> s; n     long long int bc = n * (a + b) + b; n     bool ftram = true; n     bool ztram = true; n     long long int fzero = -1; n     long long int nc = 0; n     for (int i = 0; i < n; ++i) { n       if (s[i] ==  0 ) { n         if (!ztram) { n           fzero = i; n           ztram = true; n         } n       } else { n         if (ztram) { n           if (ftram) { n             nc += a; n             ftram = false; n           } else { n             nc += min(2 * a, (i - fzero - 1) * b); n           } n           ztram = false; n           nc += b; n         } n         nc += b; n       } n     } n     if (!ftram) nc += a; n     cout << bc + nc << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n inline bool isPowerOfTwo(int x) { return (x != 0 && (x & (x - 1)) == 0); } n double pi = 3.141592653589793238462643; n int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1}; n int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1}; n inline int add(int a, int b, int m = 1000000007) { n   a += b; n   if (a >= m) a -= m; n   return a; n } n inline int mul(int a, int b, int m = 1000000007) { n   return (int)(((long long)a * (long long)b) % m); n } n inline bool ispalin(string &str) { n   int n = str.length(); n   for (int i = 0; i < n / 2; i++) n     if (str[i] != str[n - i - 1]) return false; n   return true; n } n long long expo(long long base, long long pow) { n   long long ans = 1; n   while (pow != 0) { n     if (pow & 1 == 1) { n       ans = ans * base; n       ans = ans % 1000000007; n     } n     base *= base; n     base %= 1000000007; n     pow /= 2; n   } n   return ans; n } n void swapp(int *a, int *b) { n   int temp = *a; n   *a = *b; n   *b = temp; n } n long long invt(long long x) { return expo(x, 1000000007 - 2); } n int expFactor(int n, int p) { n   int x = p; n   int exponent = 0; n   while ((n / x) > 0) { n     exponent += n / x; n     x *= p; n   } n   return exponent; n } n inline int countsetbit(int n) { n   unsigned int count = 0; n   while (n) { n     n &= (n - 1); n     count++; n   } n   return count; n } n inline int abs(int x) { n   if (x < 0) return -x; n   return x; n } n bool isPal(string ss) { n   int len = ss.length(); n   for (int i = 0; i < len / 2; i++) { n     int comp = len - i - 1; n     if (ss[i] != ss[comp]) return false; n   } n   return true; n } n vector<long long> fact, inv; n void calfal(int maxn) { n   fact.resize(maxn); n   inv.resize(maxn); n   fact[0] = inv[0] = inv[1] = 1; n   for (int i = (1); i <= (maxn - 1); ++i) n     fact[i] = i * fact[i - 1] % 1000000007; n   for (int i = (2); i <= (maxn - 1); ++i) n     inv[i] = (1000000007 - 1000000007 / i) * inv[1000000007 % i] % 1000000007; n   for (int i = (1); i <= (maxn - 1); ++i) n     inv[i] = inv[i] * inv[i - 1] % 1000000007; n } n long long ncr(int n, int r) { n   if (r > n) return 0; n   return (fact[n] * inv[r] % 1000000007) * inv[n - r] % 1000000007; n } n long long _sieve_size; n bitset<10000010> bs; n vector<int> primes; n void sieve(long long upperbound) { n   _sieve_size = upperbound + 1; n   bs.set(); n   bs[0] = bs[1] = 0; n   for (long long i = 2; i <= _sieve_size; i++) n     if (bs[i]) { n       for (long long j = i * i; j <= _sieve_size; j += i) bs[j] = 0; n       primes.push_back((int)i); n     } n } n bool isPrime(long long N) { n   if (N <= _sieve_size) return bs[N]; n   for (int i = 0; i < (int)primes.size(); i++) n     if (N % primes[i] == 0) return false; n   return true; n } n map<int, int> v, p; n int main() { n   int n, m; n   cin >> n >> m; n   int d = 0; n   for (int i = (0); i <= (m - 1); ++i) { n     int k; n     cin >> k; n     int f = 0; n     for (int j = (0); j <= (k - 1); ++j) { n       int x; n       cin >> x; n       if (x > 0) { n         v[x] = 1; n         if (p[x]) { n           f = 1; n         } n       } else { n         x = -x; n         p[x] = 1; n         if (v[x]) { n           f = 1; n         } n       } n     } n     if (f == 0) { n       d = 1; n     } else { n       v.clear(); n       p.clear(); n     } n   } n   if (d) { n     cout <<  YES  << endl; n   } else { n     cout <<  NO  << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n bool sortbysec(const pair<long long int, long long int> &a, n                const pair<long long int, long long int> &b) { n   return (a.second < b.second); n } n int main() { n   vector<pair<long long int, long long int>> v; n   long long int n, m, k; n   cin >> n >> m >> k; n   long long int a[n]; n   for (long long int i = 0; i < n; i++) { n     cin >> a[i]; n     v.push_back(make_pair(a[i], i)); n   } n   sort(v.begin(), v.end()); n   reverse(v.begin(), v.end()); n   long long int beauty = 0; n   for (long long int i = 0; i < m * k; i++) { n     beauty += v[i].first; n   } n   cout << beauty <<   n ; n   long long int j = 0, q = 0; n   int pos[999999]; n   for (int i = 0; i < n; i++) { n     pos[v[i].second] = i; n   } n   for (int i = 0; i < n; i++) { n     if (pos[i] < m * k) { n       j++; n       if (j == m) { n         q++; n         if (q < k) { n           cout << i + 1 <<    ; n           j = 0; n         } n       } n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long gcd(long long a, long long b) { n   long long c; n   while (a != 0) { n     c = a; n     a = b % a; n     b = c; n   } n   return b; n } n long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); } n long long triple(long long x) { n   long long ans = x * max(1LL, x - 1LL) * max(1LL, x - 2LL); n   if (x % 2 == 0) { n     return x * max(1LL, x - 1LL) * max(1LL, x - 3LL); n   } n   if (x >= 4 && x % 2 == 0) { n     ans /= 2; n   } n   return ans; n } n int main() { n   std::ios::sync_with_stdio(false); n   int N; n   cin >> N; n   long long ans; n   switch (N) { n     case 1: { n       ans = 1; n       break; n     } n     case 2: { n       ans = 2; n       break; n     } n     default: { n       if (N % 2 != 0) { n         ans = N * (N - 1LL) * (N - 2LL); n       } else { n         ans = (N - 1LL) * (N - 2LL) * (N - 3LL); n         long long tmp = N * (N - 1LL); n         for (int i = N - 2; i >= 1; i--) { n           long long val = lcm(tmp, i); n           if (val > ans) { n             ans = val; n             break; n           } n         } n       } n       break; n     } n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool comp(int a, int b) { return a > b; } n int gcd(int a, int b) { n   if (b == 0) return a; n   return gcd(b, a % b); n } n bool isPrime(int n) { n   if (n <= 1) return false; n   if (n <= 3) return true; n   if (n % 2 == 0 || n % 3 == 0) return false; n   for (int i = 5; i * i <= n; i = i + 6) { n     if (n % i == 0 || n % (i + 2) == 0) { n       return false; n     } n   } n   return true; n } n void primeFactors(int n) { n   while (n % 2 == 0) { n     cout << 2 <<    ; n     n = n / 2; n   } n   for (int i = 3; i <= sqrt(n); i = i + 2) { n     while (n % i == 0) { n       cout << i <<    ; n       n = n / i; n     } n   } n   if (n > 2) { n     cout << n <<    ; n   } n } n int dayofweek(int d, int m, int y) { n   static int t[] = {0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4}; n   y -= m < 3; n   return (y + y / 4 - y / 100 + y / 400 + t[m - 1] + d) % 7; n } n void BellmanFord(int graph[][3], int V, int E, int src) { n   int dis[V]; n   for (int i = 0; i < V; i++) dis[i] = INT_MAX; n   dis[src] = 0; n   for (int i = 0; i < V - 1; i++) { n     for (int j = 0; j < E; j++) { n       if (dis[graph[j][0]] + graph[j][2] < dis[graph[j][1]]) n         dis[graph[j][1]] = dis[graph[j][0]] + graph[j][2]; n     } n   } n   bool flag = true; n   for (int i = 0; i < E; i++) { n     int x = graph[i][0], y = graph[i][1], weight = graph[i][2]; n     if (dis[x] != INT_MAX && dis[x] + weight < dis[y]) { n       flag = false; n       break; n     } n   } n } n void topoSort(int n, int m, vector<vector<bool>> &e, vector<bool> &visited, n               int x) { n   visited[x] = true; n   for (int i = n - 1; i >= 0; i--) { n     if (e[x][i] and !visited[i]) { n       topoSort(n, m, e, visited, i); n     } n   } n   return; n } n void convertGraphToTree(int x, vector<vector<int>> &v, vector<bool> &visited, n                         vector<vector<int>> &newedges) { n   visited[x] = true; n   for (int i = 0; i < v[x].size(); i++) { n     if (!visited[v[x][i]]) { n       newedges[x].push_back(v[x][i]); n       convertGraphToTree(v[x][i], v, visited, newedges); n     } n   } n   return; n } n int subtreeCount(int x, vector<vector<int>> &v, vector<bool> &visited, n                  vector<int> &count) { n   visited[x] = true; n   int ans = 1; n   for (int i = 0; i < v[x].size(); i++) { n     if (!visited[v[x][i]]) { n       ans += subtreeCount(v[x][i], v, visited, count); n     } n   } n   count[x] = ans; n   return ans; n } n void helper(int n) { n   double ans = 0.0; n   for (int i = n; i >= 1; i--) { n     double temp = 1.0 / double(i); n     ans += temp; n   } n   cout << ans << endl; n   return; n } n int main() { n   int n; n   cin >> n; n   helper(n); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int ALF_SIZE = 26; n int val[200], sizeB = 1; n struct bor { n   char q; n   int a[ALF_SIZE]; n   int val, par; n   int go[ALF_SIZE]; n   int link; n   bool updated; n   void init(int q) { n     this->q = q; n     val = par = 0; n     link = -1; n     updated = 0; n     for (int w = 0; w < ALF_SIZE; w++) { n       a[w] = -1; n       go[w] = -1; n     } n   } n }; n bor a[201]; n int go(int c, char v); n int get_link(int c) { n   if (a[c].link < 0) { n     if ((c == 0) || (a[c].par == 0)) { n       a[c].link = 0; n     } else { n       a[c].link = go(get_link(a[c].par), a[c].q); n     } n   } n   return a[c].link; n } n int go(int c, char v) { n   if (a[c].go[v] < 0) { n     if (a[c].a[v] >= 0) { n       a[c].go[v] = a[c].a[v]; n     } else { n       if (c == 0) { n         a[c].go[v] = 0; n       } else { n         a[c].go[v] = go(get_link(c), v); n       } n     } n   } n   return a[c].go[v]; n } n char h[201]; n int calc_val(int c) { n   if (a[c].updated == 0) { n     a[c].updated = 1; n     a[c].val += calc_val(get_link(c)); n   } n   return a[c].val; n } n long long d[201][201]; n void mult(long long **a, long long **s, long long **f) { n   int w, e, r; n   for (e = 0; e < sizeB; e++) { n     for (r = 0; r < sizeB; r++) { n       d[e][r] = -1; n     } n   } n   for (w = 0; w < sizeB; w++) { n     for (e = 0; e < sizeB; e++) { n       for (r = 0; r < sizeB; r++) { n         if ((a[w][e] >= 0) && (s[e][r] >= 0)) { n           d[w][r] = max(d[w][r], a[w][e] + s[e][r]); n         } n       } n     } n   } n   for (e = 0; e < sizeB; e++) { n     for (r = 0; r < sizeB; r++) { n       f[e][r] = d[e][r]; n     } n   } n } n int main() { n   int q, w, e, r, t, c, v; n   long long len; n   a[0].init(0); n   cin >> q >> len; n   for (w = 0; w < q; w++) { n     scanf( %d , &val[w]); n   } n   for (w = 0; w < q; w++) { n     scanf( %s , h); n     c = 0; n     for (e = 0; h[e]; e++) { n       h[e] -=  a ; n       if (a[c].a[h[e]] == -1) { n         a[sizeB].init(h[e]); n         a[sizeB].par = c; n         a[c].a[h[e]] = sizeB; n         sizeB++; n       } n       c = a[c].a[h[e]]; n     } n     a[c].val += val[w]; n   } n   for (w = 0; w < sizeB; w++) { n     calc_val(w); n   } n   long long **s = new long long *[sizeB]; n   long long **d = new long long *[sizeB]; n   for (e = 0; e < sizeB; e++) { n     s[e] = new long long[sizeB]; n     d[e] = new long long[sizeB]; n     for (r = 0; r < sizeB; r++) { n       s[e][r] = -1; n       d[e][r] = -1; n     } n   } n   d[0][0] = 0; n   for (e = 0; e < sizeB; e++) { n     for (c = 0; c < 26; c++) { n       if (a[e].a[c] >= 0) { n         v = a[e].a[c]; n         s[e][v] = max(s[e][v], (long long)(a[v].val)); n       } else { n         v = go(get_link(e), c); n         s[e][v] = max(s[e][v], (long long)a[v].val); n       } n     } n   } n   for (; len; len /= 2) { n     if (len % 2 == 1) { n       mult(d, s, d); n     } n     mult(s, s, s); n   } n   long long ans = 0; n   for (w = 0; w < sizeB; w++) { n     ans = max(ans, d[0][w]); n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n double s = 10000000, a, b, m; n int n; n int main() { n   cin >> n >> m; n   for (int i = 1; i <= n; i++) { n     cin >> a >> b; n     s = min(s, a / b); n   } n   printf( %.8f , s * m); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n signed main() { n   ios::sync_with_stdio(0); n   cin.sync_with_stdio(0); n   cin.tie(0); n   long long t; n   cin >> t; n   while (t--) { n     long long a, b; n     cin >> a >> b; n     if (a > b) swap(a, b); n     long long ans = 0; n     while (a * 8 <= b) { n       a *= 8; n       ans++; n     } n     while (a * 4 <= b) { n       a *= 4; n       ans++; n     } n     while (a * 2 <= b) { n       a *= 2; n       ans++; n     } n     if (a == b) { n       cout << ans <<   n ; n     } else { n       cout << -1 <<   n ; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n int getbit(T s, int i) { n   return (s >> i) & 1; n } n template <class T> n T onbit(T s, int i) { n   return s | (T(1) << i); n } n template <class T> n T offbit(T s, int i) { n   return s & (~(T(1) << i)); n } n template <class T> n int cntbit(T s) { n   return __builtin_popcount(s); n } n template <class T> n T gcd(T a, T b) { n   T r; n   while (b != 0) { n     r = a % b; n     a = b; n     b = r; n   } n   return a; n } n template <class T> n T lcm(T a, T b) { n   return a / gcd(a, b) * b; n } n int n, m; n vector<int> V[200005]; n int res[200005]; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cin >> n >> m; n   for (int i = (1); i <= (n); ++i) { n     int x; n     cin >> x; n     V[x].push_back(i); n   } n   int RR = 1; n   for (int i = (1); i <= (m); ++i) { n     int x; n     cin >> x; n     if (V[x].size() > 1 && RR == 1) { n       RR = 2; n     } else if (V[x].size() == 0) { n       RR = 0; n     } n     if (RR == 1) { n       res[i] = V[x][0]; n     } n   } n   if (!RR) { n     cout <<  Impossible  << endl; n   } else if (RR == 1) { n     cout <<  Possible  << endl; n     for (int i = (1); i <= (m); ++i) cout << res[i] <<    ; n   } else { n     cout <<  Ambiguity  << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 4e5 + 7; n char s[maxn]; n int sa[maxn], str[maxn], _rank[maxn], height[maxn]; n int t1[maxn], t2[maxn], c[maxn]; n int RMQ[maxn], mm[maxn], best[20][maxn], len; n bool cmp(int *r, int a, int b, int l) { n   return r[a] == r[b] && r[a + l] == r[b + l]; n } n void da(int n, int m) { n   int i, j, p, *x = t1, *y = t2; n   for (i = 0; i < m; i++) c[i] = 0; n   for (i = 0; i < n; i++) c[x[i] = str[i]]++; n   for (i = 1; i < m; i++) c[i] += c[i - 1]; n   for (i = n - 1; i >= 0; i--) sa[--c[x[i]]] = i; n   for (j = 1; j <= n; j <<= 1) { n     p = 0; n     for (i = n - j; i < n; i++) y[p++] = i; n     for (i = 0; i < n; i++) n       if (sa[i] >= j) y[p++] = sa[i] - j; n     for (i = 0; i < m; i++) c[i] = 0; n     for (i = 0; i < n; i++) c[x[y[i]]]++; n     for (i = 1; i < m; i++) c[i] += c[i - 1]; n     for (i = n - 1; i >= 0; i--) sa[--c[x[y[i]]]] = y[i]; n     swap(x, y); n     p = 1; n     x[sa[0]] = 0; n     for (i = 1; i < n; i++) n       x[sa[i]] = cmp(y, sa[i - 1], sa[i], j) ? p - 1 : p++; n     if (p >= n) break; n     m = p; n   } n   int k = 0; n   n--; n   for (i = 0; i <= n; i++) _rank[sa[i]] = i; n   for (i = 0; i < n; i++) { n     if (k) k--; n     j = sa[_rank[i] - 1]; n     while (str[i + k] == str[j + k]) k++; n     height[_rank[i]] = k; n   } n } n void initRMQ(int n) { n   mm[0] = -1; n   for (int i = 1; i <= n; i++) n     mm[i] = ((i & (i - 1)) == 0) ? mm[i - 1] + 1 : mm[i - 1]; n   for (int i = 1; i <= n; i++) best[0][i] = i; n   for (int i = 1; i <= mm[n]; i++) n     for (int j = 1; j + (1 << i) - 1 <= n; j++) { n       int a = best[i - 1][j]; n       int b = best[i - 1][j + (1 << (i - 1))]; n       if (RMQ[a] < RMQ[b]) n         best[i][j] = a; n       else n         best[i][j] = b; n     } n } n int askRMQ(int a, int b) { n   int t = mm[b - a + 1]; n   b -= (1 << t) - 1; n   a = best[t][a]; n   b = best[t][b]; n   return RMQ[a] < RMQ[b] ? a : b; n } n int lcp(int a, int b) { n   if (a == b) return len - a; n   a = _rank[a]; n   b = _rank[b]; n   if (a > b) swap(a, b); n   return height[askRMQ(a + 1, b)]; n } n int _stack[maxn][2]; n int main() { n   int q, lim, x; n   scanf( %d%d , &len, &q); n   scanf( %s , s); n   for (int i = 0; i < len; i++) str[i] = s[i]; n   str[len] = 0; n   da(len + 1, 256); n   for (int i = 1; i <= len; i++) RMQ[i] = height[i]; n   initRMQ(len); n   while (q--) { n     int n, m; n     long long ans = 0; n     vector<pair<int, int> > Q; n     scanf( %d%d , &n, &m); n     for (int i = 1; i <= n; i++) scanf( %d , &x), Q.emplace_back(x - 1, 1); n     for (int i = 1; i <= m; i++) scanf( %d , &x), Q.emplace_back(x - 1, 0); n     sort(Q.begin(), Q.end(), n          [](const pair<int, int> &L, const pair<int, int> &R) { n            if (L.first == R.first) return L.second < R.second; n            int l = lcp(L.first, R.first); n            return s[L.first + l] < s[R.first + l]; n          }); n     int sz = Q.size(); n     for (int ss = 0; ss < 2; ss++) { n       long long tot = 0; n       map<int, int> W; n       for (int i = 0; i < sz; i++) { n         int id = Q[i].first; n         int state = Q[i].second; n         if (state == 0) n           ans += tot; n         else n           W[len - id]++, tot += len - id; n         if (i < sz - 1) { n           int LCP = lcp(Q[i].first, Q[i + 1].first); n           while (!W.empty()) { n             auto it = --W.end(); n             if (it->first <= LCP) break; n             tot -= 1LL * (it->first - LCP) * it->second; n             W[LCP] += it->second; n             W.erase(it); n           } n         } n       } n       reverse(Q.begin(), Q.end()); n     } n     printf( %lld n , ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, q, s, e, cc, sz, t, l, r; n long long tt[150000]; n void inc(int i, long long w) { n   for (; i <= n; i |= i + 1) tt[i] += w; n } n long long sum(int i) { n   long long sum = 0; n   for (; i >= 0; i = (i & (i + 1)) - 1) sum += tt[i]; n   return sum; n } n long long que(int l, int r) { n   if (l > r) swap(l, r); n   return sum(r) - sum(l - 1); n } n int conv(int i) { n   if (!cc) n     return i + s; n   else n     return e - i; n } n int main() { n   cin >> n >> q; n   e = n - 1; n   for (int i = 0; i < n; i++) inc(i, 1); n   while (q--) { n     sz = e - s + 1; n     cin >> t >> l; n     if (t == 1) { n       if (!(sz / 2 >= l)) { n         l = sz - l; n         cc ^= 1; n       } n       for (int i = 1; i <= l; i++) n         inc(conv(2 * l - i), que(conv(i - 1), conv(i - 1))); n       if (!cc) n         s += l; n       else n         e -= l; n     } else { n       cin >> r; n       cout << que(conv(l), conv(r - 1)) << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, a, curr; n vector<long long int> v; n void start() { n   cin >> n; n   int times = 0; n   bool flag = false; n   for (int i = 0; i < n; i++) { n     cin >> a; n     if (i == 0) { n       curr = a; n       times++; n       if (i == n - 1) v.push_back(times); n       continue; n     } else if (curr != a) { n       v.push_back(times); n       times = 1; n       if (i == n - 1) v.push_back(times); n       curr = a; n     } else { n       times++; n       if (i == n - 1) v.push_back(times); n     } n   } n   long long int sol = 0; n   for (int i = 0; i < v.size(); i++) { n     long long int t = v[i]; n     sol += (t * (t + 1)) / 2; n   } n   cout << sol <<   n ; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   start(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n T gcd(T x, T y) { n   if (x < y) swap(x, y); n   while (y > 0) { n     T f = x % y; n     x = y; n     y = f; n   } n   return x; n } n template <typename T> n pair<T, T> exgcd(T x, T y) { n   int sw = 0; n   if (x < y) sw = true, swap(x, y); n   pair<T, T> r = make_pair(1, 0); n   while (y > 0) { n     T f = x % y; n     r = make_pair(r.second, r.first - (x / y) * r.second); n     x = y; n     y = f; n   }; n   if (sw) swap(r.first, r.second); n   return r; n } n int rot[][12] = { n     { n         1, n         2, n         4, n         3, n         13, n         14, n         5, n         6, n         17, n         18, n         21, n         22, n     }, n     { n         9, n         10, n         11, n         12, n         15, n         16, n         7, n         8, n         19, n         20, n         23, n         24, n     }, n     {13, 14, 16, 15, 1, 3, 5, 7, 9, 11, 24, 22}, n     {17, 18, 20, 19, 2, 4, 6, 8, 10, 12, 23, 21}, n     {5, 6, 8, 7, 3, 4, 17, 19, 10, 9, 16, 14}, n     {21, 22, 24, 23, 18, 20, 12, 11, 15, 13, 1, 2}, n }; n bool solved(int s[25]) { n   for (int i = 1; i < 24; i += 4) { n     if (s[i] != s[i + 1] || s[i] != s[i + 2] || s[i] != s[i + 3]) return false; n   } n   return true; n } n int main(int argc, char *argv[]) { n   std::cin.sync_with_stdio(false); n   std::cin.tie(nullptr); n   int s[25]; n   cin >> s[1]; n   { n     for (int i = 2; i <= 24; i++) cin >> s[i]; n     int t[25]; n     bool ok = false; n     for (int i = 0; i < 6; i++) { n       memcpy(t, s, sizeof(t)); n       for (int j = 0; j < 4; j++) t[rot[i][(j + 1) % 4]] = s[rot[i][j]]; n       for (int j = 0; j < 8; j++) n         t[rot[i][4 + ((j + 2) % 8)]] = s[rot[i][4 + j]]; n       if (solved(t)) { n         ok = true; n         break; n       } n       memcpy(t, s, sizeof(t)); n       for (int j = 0; j < 4; j++) t[rot[i][(j + 3) % 4]] = s[rot[i][j]]; n       for (int j = 0; j < 8; j++) n         t[rot[i][4 + ((j + 6) % 8)]] = s[rot[i][4 + j]]; n       if (solved(t)) { n         ok = true; n         break; n       } n     } n     cout << (ok ?  YES  :  NO ) << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int minx, maxx, miny, maxy, sumofarea = 0; n   int n; n   cin >> n; n   for (int i = 0; i < n; i++) { n     int x1, y1, x2, y2; n     cin >> x1 >> y1 >> x2 >> y2; n     if (i == 0) { n       minx = x1; n       maxx = x2; n       miny = y1; n       maxy = y2; n     } else { n       minx = min(minx, x1); n       maxx = max(maxx, x2); n       miny = min(miny, y1); n       maxy = max(maxy, y2); n     } n     sumofarea += ((x2 - x1) * (y2 - y1)); n   } n   int final_square_area = (maxx - minx) * (maxy - miny); n   int lengthofside1 = maxx - minx; n   int lengthofside2 = maxy - miny; n   if (sumofarea == final_square_area && (lengthofside1 == lengthofside2)) { n     cout <<  YES ; n   } else { n     cout <<  NO ; n   } n   return 0; n } n