#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, k; n   cin >> n; n   if (n % 2 == 0) n     printf( -1 n ); n   else { n     for (k = 0; k < n; k++) printf( %d  , ((n / 2 + 1 - k) + n) % n); n     cout << endl; n     for (k = 0; k < n; k++) printf( %d  , ((n / 2 + 2 * k) + n) % n); n     cout << endl; n     for (k = 0; k < n; k++) printf( %d  , k); n   } n   cout << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 0x3f3f3f3f; n int n; n int arr1[10]; n int arr2[100005]; n pair<int, int> diffs[600005]; n int cnts[100005]; n int main() { n   while (scanf( %d , arr1) == 1) { n     for (int i = 1; i < 6; ++i) { n       scanf( %d , arr1 + i); n     } n     scanf( %d , &n); n     for (int i = 0; i < n; ++i) { n       scanf( %d , arr2 + i); n     } n     int idx = 0; n     for (int i = 0; i < 6; ++i) { n       for (int j = 0; j < n; ++j) { n         diffs[idx].first = arr2[j] - arr1[i]; n         diffs[idx].second = j; n         ++idx; n       } n     } n     sort(diffs, diffs + idx); n     memset(cnts, 0, sizeof(cnts)); n     int cnt = 0; n     int j = 0; n     int ans = INF; n     for (int i = 0; i < 5 * n; ++i) { n       if (i && --cnts[diffs[i - 1].second] <= 0) { n         --cnt; n       } n       while (cnt < n && j < 6 * n) { n         if (cnts[diffs[j].second]++ == 0) { n           ++cnt; n         } n         ++j; n       } n       if (cnt >= n) { n         ans = min(ans, diffs[j - 1].first - diffs[i].first); n       } n     } n     printf( %d n , ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   char a; n   cin >> a; n   string str1, str2; n   cin >> str1 >> str2; n   int b1, b2; n   switch (str1[0]) { n     case  T : n       b1 = 10; n       break; n     case  J : n       b1 = 11; n       break; n     case  Q : n       b1 = 12; n       break; n     case  K : n       b1 = 13; n       break; n     case  A : n       b1 = 14; n       break; n     default: n       b1 = str1[0] -  0 ; n   } n   switch (str2[0]) { n     case  T : n       b2 = 10; n       break; n     case  J : n       b2 = 11; n       break; n     case  Q : n       b2 = 12; n       break; n     case  K : n       b2 = 13; n       break; n     case  A : n       b2 = 14; n       break; n     default: n       b2 = str2[0] -  0 ; n   } n   if (str1[1] == a) n     if (str2[1] != str1[1]) { n       cout <<  YES ; n     } else { n       if (b1 > b2) { n         cout <<  YES ; n       } else n         cout <<  NO ; n     } n   else { n     if (str2[1] == str1[1]) { n       if (b1 > b2) { n         cout <<  YES ; n       } else n         cout <<  NO ; n     } else { n       cout <<  NO ; n     }; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 5001; n int n, m, x, y, c[N], p[N], A; n int main() { n   cin >> n >> m; n   for (int i = 1; i <= n; i++) p[i] = N; n   while (m-- && cin >> x >> y) c[x]++, p[x] = min(p[x], (y + n - x) % n); n   for (int i = 1; i <= n; i++) { n     A = 0; n     for (int j = 1; j <= n; j++) n       if (c[j]) A = max(A, (j + n - i) % n + (c[j] - 1) * n + p[j]); n     cout << A <<    ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 50; n int n, q; n int lca[N][25], mark[N], sum[N], h[N], a[N][4]; n vector<int> adj[N]; n map<int, map<int, int> > m; n void DFS(int v, int p, int hi) { n   h[v] = hi; n   lca[v][0] = p; n   for (auto u : adj[v]) { n     if (u == p) continue; n     DFS(u, v, hi + 1); n   } n } n void dfs_sum(int v, int p) { n   sum[v] += mark[v]; n   for (auto u : adj[v]) { n     if (u == p) continue; n     dfs_sum(u, v); n     sum[v] += sum[u]; n   } n   m[p][v] = sum[v]; n } n void LCA() { n   for (int j = 1; j <= 20; j++) n     for (int i = 1; i <= n; i++) lca[i][j] = lca[lca[i][j - 1]][j - 1]; n } n int find_par(int v, int k) { n   for (int j = 0; j <= 20; j++) { n     if (k & (1 << j)) v = lca[v][j]; n   } n   return v; n } n int find_lca(int u, int v) { n   v = find_par(v, h[v] - h[u]); n   if (v == u) return u; n   for (int j = 20; j >= 0; j--) { n     if (lca[u][j] != lca[v][j]) { n       u = lca[u][j]; n       v = lca[v][j]; n     } n   } n   return lca[u][0]; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(); n   cin >> n; n   for (int i = 1; i < n; i++) { n     cin >> a[i][0] >> a[i][1]; n     adj[a[i][0]].push_back(a[i][1]); n     adj[a[i][1]].push_back(a[i][0]); n   } n   DFS(n - 1, 0, 1); n   LCA(); n   cin >> q; n   for (int i = 0; i < q; i++) { n     int u, v; n     cin >> u >> v; n     if (h[u] > h[v]) swap(u, v); n     int lca = find_lca(u, v); n     mark[u]++; n     mark[v]++; n     mark[lca] -= 2; n   } n   dfs_sum(n - 1, 0); n   for (int i = 1; i < n; i++) { n     cout << max(m[a[i][0]][a[i][1]], m[a[i][1]][a[i][0]]) <<    ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const long long mod = 1e9 + 7; n const long long maxn = 1e5 + 5; n void solve() { n   long long k; n   cin >> k; n   long long first = pow(2, 17); n   cout << 2 <<     << 3 <<   n ; n   cout << first + k <<     << first <<     << 0 <<   n  n        << k <<     << first + k <<     << k; n } n signed main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   long long tc = 1; n   while (tc--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e6 + 6; n int n, m, k; n int s[N], c[N]; n bool vis[N]; n int fir[N]; n long long ans = 1e15; n void can(int u) { n   long long rep = 0; n   for (int i = 1; i <= n;) { n     if (fir[i + u] == i) { n       return; n     } n     rep += c[u]; n     if (i + u > n) { n       break; n     } n     i = fir[i + u]; n   } n   ans = min(ans, rep); n } n int main() { n   scanf( %d%d%d , &n, &m, &k); n   for (int i = 1; i <= m; i++) { n     scanf( %d , &s[i]); n     vis[s[i] + 1] = 1; n   } n   for (int i = 1; i <= k; i++) { n     scanf( %d , &c[i]); n   } n   for (int i = 1; i <= n; i++) { n     if (vis[i]) { n       fir[i] = fir[i - 1]; n     } else { n       fir[i] = i; n     } n   } n   if (!fir[1]) { n     printf( -1 n ); n     return 0; n   } n   for (int i = 1; i <= k; i++) { n     can(i); n   } n   if (ans == 1e15) { n     printf( -1 n ); n   } else { n     printf( %lld n , ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int where[26][26]; n int n, dp[(1 << 23) + 5], d[35]; n bool fdp[(1 << 23) + 5]; n int rec(int mask) { n   if (fdp[mask]) return dp[mask]; n   int next = 0; n   for (int i = n - 1; i >= 0; --i) { n     if (mask & (1 << i)) { n       next = i; n       break; n     } n   } n   next++; n   fdp[mask] = 1; n   if (next == n) return dp[mask] = __builtin_popcount(mask); n   int make = d[next + 1]; n   dp[mask] = 30; n   int valid = 0; n   for (int i = 0; i < n; ++i) { n     if (mask & (1 << i)) { n       int j = where[next + 1][i + 1]; n       if (d[i + 1] < make and j) { n         j--; n         if (mask & (1 << j)) valid = 1; n       } n     } n   } n   if (valid) { n     dp[mask] = rec(mask | (1 << next)); n     for (int i = 0; i < next; ++i) { n       if (mask & (1 << i)) n         dp[mask] = min(dp[mask], rec((mask ^ (1 << i)) | (1 << next))); n     } n   } n   return dp[mask]; n } n int main() { n   cin >> n; n   for (int i = 1; i <= n; ++i) { n     cin >> d[i]; n   } n   for (int i = 1; i <= n; ++i) { n     for (int j = 1; j <= n; ++j) { n       int f = d[i] - d[j]; n       for (int k = 1; k <= n; ++k) { n         if (d[k] == f) { n           where[i][j] = k; n         } n       } n     } n   } n   int ans = rec(1); n   if (ans == 30) ans = -1; n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n long long a, b, p, q, ay, by, tx, g, l, ty, x, y, n = 15, d, m, tot, last, lst2; n map<int, int> wow; n long long shob[104]; n vector<int> all; n char c; n int setbit(int n, int pos) { return n | (1 << (pos)); } n int isbit(int n, int pos) { return n & (1 << (pos)); } n int how(int a, long long &x) { n   int ret = 0, boom = 1, wow = 0; n   while (a > 0) { n     ret++; n     int md = a % 7; n     wow = boom * md + wow; n     boom *= 10; n     a /= 7; n   } n   x = wow; n   return ret; n } n int Bboom(int n, int len, int mask, int A) { n   if (len > b) { n     return 0; n   } n   int now = n, ans = 0; n   for (int i = 0; i < 7; i++) { n     if (isbit(mask, i) == 0) { n       now = n * 10 + i; n       if (len == b && now <= y) { n         ans++; n       } else if (len < b && now <= y && isbit(mask, i) == 0) { n         ans += Bboom(now, len + 1, setbit(mask, i), A); n       } n     } n   } n   return ans; n } n int Aboom(int n, int len, int mask) { n   if (len > a) { n     return 0; n   } n   int now = n, ans = 0; n   for (int i = 0; i < 7; i++) { n     if (isbit(mask, i) == 0) { n       now = n * 10 + i; n       if (len == a && now <= x) { n         ans += Bboom(0, 1, setbit(mask, i), now); n       } else if (len < a && now <= x) { n         ans += Aboom(now, len + 1, setbit(mask, i)); n       } n     } n   } n   return ans; n } n int main() { n   cin >> n >> m; n   n--; n   m--; n   a = max(how(n, x), 1); n   b = max(how(m, y), 1); n   if (a + b > 7) { n     cout << 0 << endl; n   } else { n     n = a + b; n     p = x; n     q = y; n     cout << Aboom(0, 1, 0); n   } n } n


#include <bits/stdc++.h> n using namespace std; n const long long mod = (long long)1e9 + 7; n const long long inf = (long long)1e16; n const long double eps = 1e-12; n const long long N = (int)1e5 + 5; n const long long LOGN = 19; n const long double PI = 3.14159265358979323846; n inline long long mul(long long a, long long b, long long m = mod) { n   return (long long)(a * b) % m; n } n inline long long add(long long a, long long b, long long m = mod) { n   a += b; n   if (a >= m) a -= m; n   if (a < 0) a += m; n   return a; n } n inline long long power(long long a, long long b, long long m = mod) { n   if (b == 0) return 1; n   if (b == 1) return (a % m); n   long long x = power(a, b / 2, m); n   x = mul(x, x, m); n   if (b % 2) x = mul(x, a, m); n   return x; n } n bool check(string& k) { n   int l = 0, r = k.size() - 1; n   while (l < r) { n     if (k[l] != k[r]) { n       return false; n     } n     l++; n     r--; n   } n   return true; n } n bool poss(string& k) { n   map<char, int> mp; n   int num = 0; n   for (int i = 0; i < k.length(); i++) { n     if (mp.find(k[i]) == mp.end()) { n       mp[k[i]]++; n       num++; n     } n   } n   if (num == 1) return false; n   return true; n } n int rec(string& s) { n   int n = s.length(); n   if (!poss(s)) return -1; n   if (!check(s)) return 0; n   string k; n   for (int i = 0; i < n / 2; i++) { n     k += s[i]; n   } n   bool ok = check(k); n   if (!ok) { n     if (n & 1) return 2; n     return 1; n   } n   int ret = rec(k); n   if (ret == -2) { n     if (n & 1) return 2; n     return 1; n   } n   if (ret == -1) { n     if (n & 1) return -2; n     return -1; n   } n   return ret; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   if (0) { n     freopen( C:  Users  Dishant  Desktop  Collection-DEV c++  input.txt ,  r , n             stdin); n     freopen( C:  Users  Dishant  Desktop  Collection-DEV c++  output.txt ,  w , n             stdout); n   } n   string s; n   cin >> s; n   int n = s.length(); n   int ans = rec(s); n   if (ans <= -1) { n     cout <<  Impossible ; n   } else n     cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long n, k; n   cin >> n >> k; n   if (n / k % 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 maxx(int fd, int sd) { return (fd > sd) ? fd : sd; } n int minn(int fd, int sd) { return (fd < sd) ? fd : sd; } n long long nod(long long a, long long b) { n   if (a < b) { n     return nod(b, a); n   } n   if (b == 0) { n     return a; n   } n   return nod(b, a % b); n } n long long nok(long a, long b) { n   long long result = (long long)a * (long long)b; n   result = result / nod(a, b); n   return result; n } n int main() { n   long long n, k; n   long long overallNOK = 1LL; n   scanf( %I64d %I64d , &n, &k); n   for (int i = 0; i < n; ++i) { n     long long c; n     scanf( %I64d , &c); n     overallNOK = nok(nod(k, c), overallNOK); n   } n   printf( %s , (overallNOK % k == 0) ?  Yes  :  No ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long mod = 1000000007; n long long powmod(long long a, long long b) { n   long long res = 1; n   a %= mod; n   assert(b >= 0); n   for (; b; b >>= 1) { n     if (b & 1) res = res * a % mod; n     a = a * a % mod; n   } n   return res; n } n long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } n const int maxx = 10005; n const int INF = 0x3f3f3f3f; n int n, m, k; n int vis[maxx]; n int ans = 0, cnt = 0, pos = 0; n int l = 0, r = 0; n string a, b; n string s1, s2; n int main() { n   scanf( %d%d , &n, &m); n   cin >> a >> b; n   if (n > m + 1) { n     printf( NO n ); n     return 0; n   } n   int fk = 0; n   int tag = 0; n   for (int i = 0; i < n; i++) { n     if (a[i] ==  * ) { n       tag = 1; n       continue; n     } n     if (tag == 0) n       s1.push_back(a[i]); n     else n       s2.push_back(a[i]); n   } n   if (tag) { n     fk = 0; n     for (int i = 0; i < ((int)(s1).size()); i++) { n       if (b[i] != s1[i]) fk = 1; n     } n     for (int i = ((int)(s2).size()) - 1; i >= 0; i--) { n       if (b[m - ((int)(s2).size()) + i] != s2[i]) { n         fk = 1; n       } n     } n   } else { n     if (n != m) n       fk = 1; n     else { n       for (int i = 0; i < n; i++) { n         if (a[i] != b[i]) { n           fk = 1; n           break; n         } n       } n     } n   } n   if (a ==  * ) fk = 0; n   if (fk) n     printf( NO n ); n   else n     printf( YES n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct edge { n   int b; n   bool x; n   edge *next; n } E[100010], *rt[100010]; n int o = 0; n int mi = 100000000; n int N; n void addedge(int a, int b) { n   edge *p = &E[o++]; n   p->b = b; n   p->x = false; n   p->next = rt[a]; n   rt[a] = p; n   p = &E[o++]; n   p->b = a; n   p->x = true; n   p->next = rt[b]; n   rt[b] = p; n } n int S[10010]; n bool jud[10010]; n void init() { n   for (int i = 1; i <= N; i++) { n     jud[i] = false; n     S[i] = 0; n   } n } n void pdfs(int n) { n   jud[n] = true; n   for (edge *p = rt[n]; p != NULL; p = p->next) { n     int b = p->b; n     if (!jud[b]) { n       pdfs(b); n       S[n] += S[b]; n       if (p->x) S[n]++; n     } n   } n } n void dfs(int n, int s0, int s1) { n   jud[n] = true; n   int b, s, t0, t1; n   for (edge *p = rt[n]; p != NULL; p = p->next) { n     b = p->b; n     if (!jud[b]) { n       s = S[n]; n       mi = min(mi, s + s0); n       t0 = s + s0 - S[b]; n       if (p->x) n         s = S[n] - 1; n       else n         s = S[n] + 1; n       mi = min(mi, s + s1); n       t1 = s + s1 - S[b]; n       s = S[n] - (p->x == true); n       mi = min(mi, s + s0); n       t1 = min(t1, s + s0 - S[b]); n       dfs(b, t0, t1); n     } n   } n } n int main() { n   o = 0; n   int i, j, k; n   int a, b, s; n   scanf( %d , &N); n   if (N == 1) { n     printf( 0 n ); n     return 0; n   } n   for (i = 0; i <= N; i++) { n     rt[i] = NULL; n   } n   for (i = 1; i < N; i++) { n     scanf( %d%d , &a, &b); n     addedge(a, b); n   } n   for (i = 1; i <= N; i++) { n     init(); n     pdfs(i); n     for (j = 0; j <= N; j++) jud[j] = false; n     dfs(i, 0, 0); n   } n   printf( %d n , mi); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   long long h[100000], ans[100000]; n   cin >> n; n   for (int i = 0; i < n; i++) cin >> h[i]; n   ans[n - 1] = 0; n   for (int i = n - 2; i >= 0; i--) { n     if (h[i] <= h[i + 1]) n       ans[i] = h[i + 1] - h[i] + 1; n     else n       ans[i] = 0; n     h[i] = max(h[i], h[i + 1]); n   } n   for (int i = 0; i < n; i++) cout << ans[i] <<    ; n } n


#include <bits/stdc++.h> n int inp() { n   char c = getchar(); n   while (c <  0  || c >  9 ) c = getchar(); n   int sum = 0; n   while (c >=  0  && c <=  9 ) { n     sum = sum * 10 + c -  0 ; n     c = getchar(); n   } n   return sum; n } n int root[1000010]; n struct President_Tree { n   int lc[10000000], rc[10000000]; n   long long k[10000000], b[10000000]; n   int cnt; n   void push_up(int cur) { n     k[cur] = k[lc[cur]] + k[rc[cur]]; n     b[cur] = b[lc[cur]] + b[rc[cur]]; n   } n   void insert(int &cur, int last, int x, int kc, int bc, int l, int r) { n     cur = ++cnt; n     if (l == r) { n       k[cur] = k[last] + kc; n       b[cur] = b[last] + bc; n       return; n     } n     int mid = (l + r) >> 1; n     if (x <= mid) { n       insert(lc[cur], lc[last], x, kc, bc, l, mid); n       rc[cur] = rc[last]; n     } else { n       lc[cur] = lc[last]; n       insert(rc[cur], rc[last], x, kc, bc, mid + 1, r); n     } n     push_up(cur); n   } n   long long query(int cur, int last, int ql, int qr, long long x, int l, n                   int r) { n     if (l > qr || r < ql) return 0; n     if (l >= ql && r <= qr) return x * (k[cur] - k[last]) + (b[cur] - b[last]); n     int mid = (l + r) >> 1; n     return query(lc[cur], lc[last], ql, qr, x, l, mid) + n            query(rc[cur], rc[last], ql, qr, x, mid + 1, r); n   } n } t; n int main() { n   int n = inp(); n   for (int i = 1; i <= n; i++) { n     int xl = inp(); n     int xr = inp(); n     int yl = inp(); n     int k = inp(); n     int b = inp(); n     int yr = inp(); n     t.insert(root[i], root[i - 1], 0, 0, yl, 0, 1e9); n     t.insert(root[i], root[i], xl + 1, k, b - yl, 0, 1e9); n     t.insert(root[i], root[i], xr + 1, -k, yr - b, 0, 1e9); n   } n   int m = inp(); n   long long lastans = 0; n   while (m--) { n     int l = inp(); n     int r = inp(); n     int x = (inp() + lastans) % 1000000000; n     lastans = t.query(root[r], root[l - 1], 0, x, x, 0, 1e9); n     printf( %lld n , lastans); n   } n } n


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


#include <bits/stdc++.h> n using namespace std; n long long date(int y, int m, int d) { n   if (m < 3) y--, m += 12; n   return (long long)365 * y + y / 4 - y / 100 + y / 400 + (153 * m - 457) / 5 + n          d - 306; n } n int main() { n   int y1, y2, m1, m2, d1, d2; n   scanf( %d:%d:%d , &y1, &m1, &d1); n   scanf( %d:%d:%d , &y2, &m2, &d2); n   printf( %lld n , llabs(date(y1, m1, d1) - date(y2, m2, d2))); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n mt19937 Rand(time(0)); n long long rnd(long long a) { return Rand() % a; } n long long rnd(long long a, long long b) { return Rand() % (b - a + 1) + a; } n double rnd_01d() { return (double)Rand() / (1ll << 32); } n double rnd_d(double r) { return rnd_01d() * r; } n const long long inf = 1e9 + 7; n void run() { n   long long n; n   cin >> n; n   vector<long long> h(n); n   for (long long i = 0; i < n; ++i) cin >> h[i]; n   long long l = -1, r = 1e9 + 3; n   while (r - l > 1) { n     long long mid = (l + r) / 2; n     vector<long long> b; n     copy(begin(h), end(h), back_inserter(b)); n     bool bad = false; n     for (long long i = n - 1; i >= 2; --i) { n       if (b[i] < mid) bad = true; n       long long d = min(b[i] - mid, h[i]) / 3; n       b[i - 1] += d; n       b[i - 2] += 2 * d; n     } n     if (b[1] < mid || b[0] < mid || bad) n       r = mid; n     else n       l = mid; n   } n   cout << l << endl; n } n signed main() { n   cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(0); n   cout.precision(5); n   long long t = 1; n   cin >> t; n   while (t--) { n     run(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int minimum(int x, int y) { return (x < y ? x : y); } n template <typename type> n struct even { n   bool operator()(const type &x, const type &y) const { return x % 2 == 0; } n }; n template <typename type> n struct odd { n   bool operator()(const type &x, const type &y) const { return x % 2 != 0; } n }; n bool flusher(int x) { n   string s; n   cout << x << endl; n   fflush(stdout); n   cin >> s; n   return s ==  yes ; n } n long long int magic(string s) { n   long long int sum = 0; n   for (int i = 0; i < s.size(); i++) { n     sum += s[i] -  0 ; n   } n   return sum; n } n long long int binaryToInt(string s) { n   long long int n = s.length(); n   long long int res = 0; n   long long int base = 1; n   for (long long int i = n - 1; i >= 0; i--) { n     if (s[i] ==  1 ) { n       res += base; n     } n     base *= 2; n   } n   return res; n } n int main() { n   ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); n   int n, k; n   cin >> n >> k; n   int length = n * 2 + 1; n   int res = 0; n   int x[length]; n   for (int i = 0; i < length; i++) { n     cin >> x[i]; n   } n   for (int i = 1; i < length; i += 2) { n     if (x[i] - 1 > x[i - 1] && x[i] - 1 > x[i + 1]) { n       x[i]--; n       res++; n     } n     if (res == k) { n       break; n     } n   } n   for (int i = 0; i < length; i++) { n     cout << x[i] <<    ; n   } n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n const int N = 1e6 + 50; n long long kol, sum, id, ans; n string s; n vector<long long> a; n int main() { n   cin >> s; n   ans = 0; n   sum = 0; n   for (int i = 0; i < s.size(); i++) { n     if (s[i] ==  v ) { n       id += 1; n       if (i == s.size() - 1) { n         sum += id - 1; n       } n     } else { n       if (id != 0) { n         sum += id - 1; n         id = 0; n       } n       a.push_back(sum); n       kol += 1; n     } n   } n   if (a.size() == 0) { n     cout << 0; n     return 0; n   } n   for (int i = 0; i < a.size(); i++) { n     ans += a[i] * (sum - a[i]); n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(NULL); n   int n, x; n   cin >> n; n   while (n--) { n     cin >> x; n     if (x < 3 || x == 4 || x == 5 || x == 8 || x == 11) n       cout <<  NO  << endl; n     else n       cout <<  YES  << endl; n   } n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 300005; n const int MAXINT = 1073741823; n vector<int> neighbors[MAXN]; n int a[MAXN]; n int greater_right[MAXN]; n int greater_left[MAXN]; n int less_right[MAXN]; n int less_left[MAXN]; n int dp[MAXN]; n stack<int> s; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   int n; n   cin >> n; n   for (int i = 0; i < n; i++) cin >> a[i]; n   for (int i = 0; i < n; i++) { n     while (!s.empty() && a[s.top()] < a[i]) s.pop(); n     greater_left[i] = (s.empty() ? -1 : s.top()); n     s.push(i); n   } n   stack<int>().swap(s); n   for (int i = 0; i < n; i++) { n     while (!s.empty() && a[s.top()] > a[i]) s.pop(); n     less_left[i] = (s.empty() ? -1 : s.top()); n     s.push(i); n   } n   stack<int>().swap(s); n   for (int i = n - 1; i >= 0; i--) { n     while (!s.empty() && a[s.top()] < a[i]) s.pop(); n     greater_right[i] = (s.empty() ? -1 : s.top()); n     s.push(i); n   } n   stack<int>().swap(s); n   for (int i = n - 1; i >= 0; i--) { n     while (!s.empty() && a[s.top()] > a[i]) s.pop(); n     less_right[i] = (s.empty() ? -1 : s.top()); n     s.push(i); n   } n   for (int i = 0; i < n; i++) { n     if (greater_left[i] != -1) neighbors[greater_left[i]].push_back(i); n     if (greater_right[i] != -1) neighbors[i].push_back(greater_right[i]); n     if (less_left[i] != -1) neighbors[less_left[i]].push_back(i); n     if (less_right[i] != -1) neighbors[i].push_back(less_right[i]); n   } n   fill(dp, dp + n, MAXINT); n   dp[0] = 0; n   for (int i = 0; i < n; i++) n     for (int j : neighbors[i]) dp[j] = min(dp[j], dp[i] + 1); n   cout << dp[n - 1]; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename Arg1> n void __f(const char* name, Arg1&& arg1) { n   cerr << name <<   :   << arg1 << std::endl; n } n template <typename Arg1, typename... Args> n void __f(const char* names, Arg1&& arg1, Args&&... args) { n   const char* comma = strchr(names + 1,  , ); n   cerr.write(names, comma - names) <<   :   << arg1 <<   |  ; n   __f(comma + 1, args...); n } n const int N = 2e5 + 5; n int n; n vector<int> adj[N]; n int root; n int degree[N], removed[N], level[N]; n void dfs(int u, int p) { n   for (auto v : adj[u]) { n     if (v == p) continue; n     level[v] = level[u] + 1; n     dfs(v, u); n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   ; n   cin >> n; n   for (int i = 1; i <= n; i++) { n     int x; n     cin >> x; n     if (x == 0) { n       root = i; n       continue; n     } n     adj[x].push_back(i); n     adj[i].push_back(x); n     degree[i]++, degree[x]++; n   } n   if (n % 2 == 0) { n     cout <<  NO n ; n     return 0; n   } n   dfs(root, 0); n   set<pair<int, int> > s; n   for (int i = 1; i <= n; i++) { n     if (degree[i] % 2 == 0) s.insert({level[i], i}); n   } n   vector<int> ans; n   while (!s.empty()) { n     auto top = *s.rbegin(); n     s.erase(prev(s.end())); n     int node = top.second; n     for (auto v : adj[node]) { n       if (removed[v]) continue; n       degree[v]--; n       if (degree[v] % 2 == 1) { n         s.erase(s.find({level[v], v})); n       } else { n         s.insert({level[v], v}); n       } n     } n     ans.push_back(node); n     removed[node] = 1; n   } n   if (ans.size() == n) { n     cout <<  YES n ; n     for (auto i : ans) cout << i <<   n ; n   } else n     cout <<  NO n ; n   return 0; n } n


#include <bits/stdc++.h> n using ll = long long; n using ld = long double; n using ull = unsigned long long; n using namespace std; n const int N = 2e5 + 2, mod = 998244353; n int n, m, d[N][20]; n pair<int, int> dist[N][2]; n vector<int> g[2][N]; n struct State { n   int d, ver, B; n   bool operator<(const State& oth) const { return d > oth.d; } n }; n struct State1 { n   int B, A, ver; n   bool operator<(const State1& oth) const { n     return B > oth.B || (B == oth.B && A > oth.A); n   } n }; n void solve1() { n   priority_queue<State1> pq; n   for (int i = (1); i <= (n); ++i) dist[i][0] = dist[i][1] = {1e9, 1e9}; n   dist[1][0] = {0, 0}; n   pq.push({0, 0, 1}); n   while (!pq.empty()) { n     State1 cur = pq.top(); n     pq.pop(); n     int side = cur.B & 1; n     if (pair<int, int>(cur.B, cur.A) != dist[cur.ver][side]) continue; n     for (int v : g[side][cur.ver]) n       if (dist[v][side].first > cur.B || n           (dist[v][side].first == cur.B && dist[v][side].second > cur.A + 1)) { n         dist[v][side] = {cur.B, cur.A + 1}; n         pq.push({cur.B, cur.A + 1, v}); n       } n     if (dist[cur.ver][side ^ 1].first > cur.B + 1 || n         (dist[cur.ver][side ^ 1].first == cur.B + 1 && n          dist[cur.ver][side ^ 1].second > cur.A)) { n       dist[cur.ver][side ^ 1] = {cur.B + 1, cur.A}; n       pq.push({cur.B + 1, cur.A, cur.ver}); n     } n   } n   pair<int, int> ans = dist[n][0]; n   if (dist[n][1].first < ans.first || n       (dist[n][1].first == ans.first && dist[n][1].second < ans.second)) n     ans = dist[n][1]; n   assert(ans.first != 1e9 && ans.second != 1e9); n   int res = 1; n   for (int i = (1); i <= (ans.first); ++i) res = res * 2LL % mod; n   cout << (res + ans.second - 1) % mod; n } n void solve() { n   int LG = 32 - __builtin_clz(m); n   assert(LG <= 19); n   priority_queue<State> pq; n   pq.push({0, 1, 0}); n   for (int i = (1); i <= (n); ++i) n     for (int j = (0); j <= (19); ++j) d[i][j] = 1e9; n   d[1][0] = 0; n   while (!pq.empty()) { n     State cur = pq.top(); n     pq.pop(); n     if (cur.d != d[cur.ver][cur.B]) continue; n     for (int v : g[cur.B & 1][cur.ver]) n       if (d[v][cur.B] > cur.d + 1) { n         d[v][cur.B] = cur.d + 1; n         pq.push({d[v][cur.B], v, cur.B}); n       } n     if (cur.B < LG) { n       if (d[cur.ver][cur.B + 1] > cur.d + (1 << cur.B)) { n         d[cur.ver][cur.B + 1] = cur.d + (1 << cur.B); n         pq.push({d[cur.ver][cur.B + 1], cur.ver, cur.B + 1}); n       } n     } n   } n   int ans = 1e9; n   for (int i = (0); i <= (LG); ++i) n     if (ans > d[n][i]) ans = d[n][i]; n   if (ans == 1e9) n     solve1(); n   else n     cout << ans; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(nullptr); n   cin >> n >> m; n   for (int i = (1); i <= (m); ++i) { n     int u, v; n     cin >> u >> v; n     g[0][u].emplace_back(v); n     g[1][v].emplace_back(u); n   } n   solve(); n   return 0; n } n


#include <iostream> n #include <algorithm> n #include <cassert> n #include <fstream> n  n using ll = long long; n const int maxn = 5007; n ll t, n, S[maxn], ans[maxn]; n ll res; n  n int main(int argc, char *argv[]) {   n  std::ios::sync_with_stdio(false); n  std::cin.tie(0);  n  std::cin >> t; n  while (t--) { n   res = 0; n   std::cin >> n; n   for (ll i = 0; i < n; i++) { n    std::cin >> S[i]; n    ans[i] = 0; n   } n   for (ll i = 0; i < n; i++) { n    ll temp = ans[i]; n    if (temp < S[i]-1){ n     res += S[i] - 1 - temp; n     temp += S[i] - 1 - temp; n    } n    ans[i+1] += temp - S[i] + 1; n    if (i+2 < n) { n     for (int j = i+2; j < std::min(n,i+S[i]+1); j++) { n      ans[j]++; n     } n    } n    } n   std::cout << res <<   n ; n  } n }


#include <bits/stdc++.h> n using namespace std; n int n, k, pos; n long long a[200005], sum[200005], ans; n vector<long long> vec; n int main() { n   cin.tie(0), ios::sync_with_stdio(0); n   cin >> n >> k; n   for (int i = 1; i <= n; i++) { n     cin >> a[i]; n     sum[i] = a[i]; n     sum[i] += sum[i - 1]; n     if (a[i] > 1) vec.push_back(i); n   } n   a[n + 1] = 1; n   vec.push_back(n + 1); n   for (int i = 1; i <= n; i++) { n     pos = i; n     long long tich = a[i]; n     while (1) { n       int it = lower_bound(vec.begin(), vec.end(), pos + 1) - vec.begin(); n       int l = pos, r = vec[it] - 1, mid; n       if (tich % k == 0) { n         long long val = tich / k; n         while (l < r) { n           mid = (l + r) / 2; n           if (sum[mid] - sum[i - 1] >= val) n             r = mid; n           else n             l = mid + 1; n         } n         if (l >= pos && sum[l] - sum[i - 1] == val) { n           ans++; n         } n       } n       long long amount = LLONG_MAX / a[vec[it]]; n       if (tich >= amount) break; n       tich *= a[vec[it]]; n       pos = vec[it]; n       if (pos == n + 1) break; n     } n   } n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n int a[300000]; n int ans[300000]; n map<int, int> m; n int gcd(int a, int b) { n   if (b == 0) n     return a; n   else n     return gcd(b, a % b); n } n int main() { n   int n; n   scanf( %d , &n); n   for (int i = 0; i < n * n; i++) { n     scanf( %d , &a[i]); n     m[a[i]]++; n   } n   sort(a, a + n * n); n   int k = 0; n   for (int i = n * n - 1; i >= 0; i--) { n     if (m[a[i]] > 0) { n       ans[k++] = a[i]; n       for (int j = 0; j < k; j++) { n         m[gcd(a[i], ans[j])] -= 2; n       } n     } n   } n   for (int i = 0; i < k - 1; i++) { n     printf( %d  , ans[i]); n   } n   printf( %d , ans[k - 1]); n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<pair<long long int, long long int>> v1; n int main() { n   long long int n, i, A[300005], minn, t1, a1, i1; n   cin >> n; n   for (i = 1; i <= n; i++) { n     cin >> A[i]; n     v1.push_back(make_pair(A[i], i)); n   } n   minn = 10000000000; n   for (i = 2; i <= n; i++) { n     t1 = min(A[1], A[i]) / (i - 1); n     if (t1 < minn) minn = t1; n   } n   for (i = n - 1; i >= 1; i--) { n     t1 = min(A[n], A[i]) / (n - i); n     if (t1 < minn) minn = t1; n   } n   sort(v1.begin(), v1.end()); n   a1 = v1[0].first; n   i1 = v1[0].second; n   for (i = 1; i < v1.size(); i++) { n     t1 = min(a1, v1[i].first) / (abs(i1 - v1[i].second)); n     if (t1 < minn) minn = t1; n   } n   cout << minn << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxN = 2e5 + 10; n const long long oo = 1e18; n char s[maxN]; n long long cost[maxN][2]; n int main() { n   int test; n   scanf( %d , &test); n   while (test--) { n     int n, a, b; n     scanf( %d%d%d%*c , &n, &a, &b); n     gets(s); n     cost[0][0] = b; n     cost[0][1] = oo; n     for (int i = 0; i < n; i++) { n       if (s[i] ==  0 ) { n         cost[i + 1][0] = min(cost[i][0] + a + b, cost[i][1] + a * 2 + b); n         cost[i + 1][1] = min(cost[i][0] + 2 * (a + b), cost[i][1] + a + b * 2); n       } else { n         cost[i + 1][1] = cost[i][1] + a + b * 2; n         cost[i + 1][0] = oo; n       } n     } n     printf( %lld n , cost[n][0]); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, a[100001], g[100001], h[100001], m; n set<int> events[100001]; n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) events[i].clear(); n   for (int i = 1; i <= n; i++) scanf( %d , &a[i]), events[a[i]].insert(i); n   m = 0; n   bool ok = true; n   for (int i = 1; i <= n; ++i) n     if (!events[i].empty()) n       if (events[i].find(i) == events[i].end()) { n         ok = false; n         break; n       } n   if (!ok) { n     printf( -1 n ); n     return 0; n   } n   for (int i = 1; i <= n; i++) n     if (!events[i].empty()) { n       h[++m] = i; n       for (set<int>::iterator itr = events[i].begin(); itr != events[i].end(); n            ++itr) n         g[*itr] = m; n     } n   printf( %d n , m); n   for (int i = 1; i <= n; i++) printf( %d  , g[i]); n   printf(  n ); n   for (int i = 1; i <= m; i++) printf( %d  , h[i]); n   printf(  n ); n } n


#include<bits/stdc++.h> n using namespace std; n long long a,b,c,d,e,i,j,ii,jj,zx,xc,tes,t,f[200009],A[200009],B[200009],rg[200009][20],rgx[200009][20],lf[200009][20],lfx[200009][20],P[200009],pas; n stack <long long> st; n set <long long> s; n set <long long>::iterator it,lft,rgt; n long long uprg(long long q, long long w){ n  if(q>=w) return 0; n  long long jm=0; n  long long h=0; n  for(h=18; h>=0; h--){ n   if(rg[q][h]!=0&&rg[q][h]<w){ n    jm+=rgx[q][h]; n    q=rg[q][h]; n   } n  } n  jm+=rgx[q][0]; n  return jm; n } n long long uplf(long long q, long long w){ n  if(w<=q) return 0; n  long long jm=0; n  long long h=0; n  for(h=19; h>=0; h--){ n   if(lf[w][h]!=0&&lf[w][h]>q){ n    jm+=lfx[w][h]; n    w=lf[w][h]; n   } n  } n  jm+=lfx[w][0]; n  return jm; n } n long long fun(long long q, long long w){ n  if(q>=w) return 0; n  long long jm=0; n  long long h=0; n  for(h=18; h>=0; h--){ n   if(rg[q][h]!=0&&rg[q][h]<=w){ n    jm+=rgx[q][h]; n    q=rg[q][h]; n   } n  } n  if(q==w) return jm; n  jm+=uplf(q,w); n  return jm; n } n int main(){ n  ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0); n  cin>>a>>tes; n  for(i=1; i<=a; i++) cin>>f[i]; n  for(i=1; i<=a; i++) cin>>A[i]; n  for(i=1; i<=a; i++) cin>>B[i]; n  while(st.size()) st.pop(); n  st.push(a+1); n  f[a+1]=a+2; n  for(i=a; i>=1; i--){ n   while(st.size()>0&&f[st.top()]<f[i]) st.pop(); n   if(st.size()==0){ n     n   }else{ n    rg[i][0]=st.top(); n    rgx[i][0]=min(B[i],A[i]+uprg(i+1,st.top())); n   } n   for(j=1; j<=18; j++){ n    rg[i][j]=rg[rg[i][j-1]][j-1]; n    rgx[i][j]=rgx[i][j-1]+rgx[rg[i][j-1]][j-1]; n   } n   st.push(i); n  } n  while(st.size()) st.pop(); n  for(i=1; i<=a; i++){ n   while(st.size()>0&&f[st.top()]<f[i]) st.pop(); n   if(st.size()==0){ n     n   }else{ n    lf[i][0]=st.top(); n    lfx[i][0]=A[st.top()]+uprg(st.top()+1,i); n   } n   for(j=1; j<=18; j++){ n    lf[i][j]=lf[lf[i][j-1]][j-1]; n    lfx[i][j]=lfx[i][j-1]+lfx[lf[i][j-1]][j-1]; n   } n   st.push(i); n  } n  s.insert(1); n  s.insert(a+1); n  P[1]=fun(1,a+1); n  pas+=P[1]; n  for(t=1; t<=tes; t++){ n   cin>>c; n   if(c==1){ n    cout<<pas<<endl; n    continue; n   } n   it=s.lower_bound(c); n   if(it==s.end()||(*it)!=c){ n    P[c]=fun(c,(*it)); n    pas+=P[c]; n    lft=it;lft--; n    pas-=P[(*lft)]; n    P[(*lft)]=fun((*lft),c); n    pas+=P[(*lft)]; n    s.insert(c); n   }else{ n    lft=it;lft--; n    pas-=P[(*lft)]; n    rgt=it;rgt++; n    pas-=P[c]; n    P[(*lft)]=fun((*lft),(*rgt)); n    pas+=P[(*lft)]; n    s.erase(it); n   } n   cout<<pas<<endl; n  } n  P[0]=2*6; n  pas=P[0]+5; n  return 0; n }


#include <bits/stdc++.h> n using namespace std; n int solve(int n, int m, int k) { n   if (n > m) return 0; n   if (n == 0) return min(m + 1, (1 << (k + 1))); n   if ((1 << k) & n) { n     int c = solve(n - (1 << k), m - (1 << k), k - 1); n     if (c == (1 << k)) n       return (1 << (k + 1)); n     else n       return c; n   } else { n     int z = solve(n, m - (1 << k), k - 1); n     if (z == (1 << k)) n       return 2 * z; n     else { n       int c = solve(n, m, k - 1); n       if (c == (1 << k)) n         return (1 << k) + z; n       else n         return c; n     } n   } n } n void solve() { n   int n, m; n   cin >> n >> m; n   cout << solve(n, m, 29) <<   n ; n } n signed main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   int t; n   cin >> t; n   while (t--) solve(); n } n


#include <bits/stdc++.h> n using namespace std; n bool f = 0; n const double eps = 1e-8; n int n; n struct point { n   double x, y; n } p[100010]; n inline int rd() { n   int x = 0; n   bool f = 0; n   char c = getchar(); n   while (!isdigit(c)) { n     if (c ==  - ) f = 1; n     c = getchar(); n   } n   while (isdigit(c)) { n     x = (x << 1) + (x << 3) + (c ^ 48); n     c = getchar(); n   } n   return f ? -x : x; n } n inline bool valid(double x) { n   double l = -(double)1e18, r = (double)1e18, dlt; n   for (register int i = 1; i <= n; ++i) { n     if (p[i].y > x + x) return 0; n     dlt = sqrt(p[i].y * (2 * x - p[i].y)); n     l = max(l, p[i].x - dlt); n     r = min(r, p[i].x + dlt); n   } n   return (r - l + eps >= 0.0); n } n int main() { n   n = rd(); n   for (register int i = 1; i <= n; ++i) { n     p[i].x = (double)rd(); n     p[i].y = (double)rd(); n     if (p[i].y < 0.0) f = 1; n   } n   if (f == 1) n     for (register int i = 1; i <= n; ++i) { n       p[i].y = -p[i].y; n       if (p[i].y < 0.0) { n         puts( -1 ); n         return 0; n       } n     } n   int t = 0; n   register double l = 0.0, r = (double)1e18, mid; n   while (t <= 300) { n     mid = (l + r) / 2.0; n     ++t; n     valid(mid) ? r = mid : l = mid; n   } n   printf( %.10lf , l); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int mod = 1e9 + 7; n const long long inf = 2e9 + 10; n template <typename T1, typename T2> n static void relax(T1 &x, T2 y) { n   if (x > y) x = y; n } n template <typename T1, typename T2> n static void gain(T1 &x, T2 y) { n   if (x < y) x = y; n } n long long powmod(long long a, long long b) { n   long long res = 1; n   while (b) { n     if (b & 1) 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 inline void add(int &x, int y) { n   x += y; n   if (x >= mod) x -= mod; n } n inline void sub(int &x, int y) { n   x -= y; n   if (x < 0) x += mod; n } n const int maxl = 2e3 + 3; n int m, d; n string a, b; n int dp[maxl][maxl][2]; n int solve(string s) { n   int n = (int)s.length(); n   for (int(i) = 0; (i) < (int)(n + 1); ++(i)) n     for (int(j) = 0; (j) < (int)(m); ++(j)) n       for (int(k) = 0; (k) < (int)(2); ++(k)) dp[i][j][k] = 0; n   dp[0][0][1] = 1; n   for (int(i) = 0; (i) < (int)(n); ++(i)) n     for (int(j) = 0; (j) < (int)(m); ++(j)) n       for (int(k) = 0; (k) < (int)(2); ++(k)) n         for (int dgt = 0; dgt <= (k ? int(s[i] -  0 ) : 9); ++dgt) { n           if ((i & 1) && dgt != d) continue; n           if (!(i & 1) && dgt == d) continue; n           int ni = i + 1; n           int nj = ((j * 10 + dgt) % m); n           int nk = k && (dgt == int(s[i] -  0 )); n           add(dp[ni][nj][nk], dp[i][j][k]); n         } n   int ans = 0; n   for (int(k) = 0; (k) < (int)(2); ++(k)) add(ans, dp[n][0][k]); n   return ans; n } n bool ok(string s) { n   int n = (int)s.length(); n   int rem = 0; n   for (int(i) = 0; (i) < (int)(n); ++(i)) { n     int dgt = int(s[i] -  0 ); n     if ((i & 1) && dgt != d) return false; n     if (!(i & 1) && dgt == d) return false; n     rem = (rem * 10 + dgt) % m; n   } n   return !rem; n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(NULL); n   cin >> m >> d; n   cin >> a; n   cin >> b; n   int ans = 0; n   add(ans, solve(b)); n   sub(ans, solve(a)); n   add(ans, ok(a)); n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long a[200010]; n int main() { n   cin.tie(0); n   ios_base::sync_with_stdio(false); n   int n; n   cin >> n; n   for (int i = 0; i < n; i++) cin >> a[i]; n   int f = 0; n   for (int i = 1; i < n; i++) n     if (a[i] != a[i - 1]) { n       f = 1; n       break; n     } n   if (f == 0) { n     if (a[0] == 0) { n       cout <<  YES  << endl; n       for (int i = 0; i < n; i++) cout <<  1  <<    ; n       exit(0); n     } n     cout <<  NO  << endl; n     exit(0); n   } n   long long mx = 0, mxer = 0; n   for (int i = 0; i < n; i++) n     if (a[i] > mx) mx = a[mxer = i]; n   while (true) { n     int x = mxer - 1; n     if (x < 0) x += n; n     if (a[x] == a[mxer]) n       mxer = x; n     else n       break; n   } n   int flag = 1; n   for (int i = 1; i < n; i++) { n     int x = mxer - 1; n     if (x < 0) x += n; n     if (flag && a[x] == 0) { n       a[x] += a[mxer]; n       flag = 0; n     } n     a[x] += a[mxer]; n     mxer = x; n   } n   cout <<  YES  << endl; n   for (int i = 0; i < n; i++) cout << a[i] <<    ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int gcd(int(a), int(b)) { return ((a) % (b) ? gcd((b), (a) % (b)) : (b)); } n long long lgcd(long long(a), long long(b)) { n   return ((a) % (b) ? gcd((b), (a) % (b)) : (b)); n } n int lcm(int a, int b) { return (a) / gcd((a), (b)) * b; } n long long llcm(long long a, long long b) { return (a) / lgcd((a), (b)) * b; } n int n, m, ans[100010], crime[100010], notcrime[100010]; n int main() { n   memset(ans, 0, sizeof(ans)); n   memset(crime, 0, sizeof(crime)); n   memset(notcrime, 0, sizeof(notcrime)); n   scanf( %d%d , &n, &m); n   getchar(); n   for (int i = 1; i <= n; i++) { n     char c; n     int temp; n     scanf( %c%d , &c, &temp); n     getchar(); n     if (c ==  + ) { n       crime[temp]++; n       ans[i] = temp; n     } else { n       notcrime[temp]++; n       ans[i] = -temp; n     } n   } n   int nnc = 0; n   for (int i = 1; i <= n; i++) nnc += notcrime[i]; n   int nc = 0; n   bool cc[100010]; n   memset(cc, false, sizeof(cc)); n   for (int i = 1; i <= n; i++) { n     if (crime[i] + nnc - notcrime[i] == m) { n       cc[i] = true; n       nc++; n     } n   } n   for (int i = 1; i <= n; i++) { n     if (ans[i] > 0) { n       if (cc[((ans[i]) > 0 ? (ans[i]) : -(ans[i]))]) { n         if (nc > 1) n           printf( Not defined n ); n         else n           printf( Truth n ); n       } else n         printf( Lie n ); n     } else { n       if (cc[((ans[i]) > 0 ? (ans[i]) : -(ans[i]))]) { n         if (nc == 1) n           printf( Lie n ); n         else n           printf( Not defined n ); n       } else n         printf( Truth n ); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int dx[] = {-1, 0, 1, 0}; n const int dy[] = {0, -1, 0, 1}; n const int dx8[] = {-1, 0, 1, 0, 1, 1, -1, -1}; n const int dy8[] = {0, -1, 0, 1, 1, -1, 1, -1}; n void solve() { n   long long n; n   cin >> n; n   vector<long long> a(n); n   vector<vector<long long>> dp(n, vector<long long>(n)); n   vector<vector<long long>> sum(n, vector<long long>(n)); n   for (long long i = 0; i < n; i++) cin >> a[i]; n   sort(a.begin(), a.end()); n   vector<long long> s(n), l(n); n   for (long long i = 0; i < n; i++) { n     for (long long j = 0; j < n; j++) { n       if (a[i] >= 2 * a[j]) { n         l[i] = j; n         s[i]++; n       } n     } n   } n   for (long long i = 0; i < n; i++) { n     for (long long j = 0; j < n; j++) { n       if (j == 0) { n         dp[i][j] = 1; n         long long x = i - 1 >= 0 ? sum[i - 1][j] : 0; n         sum[i][j] = x + dp[i][j]; n         sum[i][j] %= 998244353; n         continue; n       } n       if (s[i] - j + 1 > 0) { n         dp[i][j] = n             (dp[i][j - 1] * (s[i] - j + 1)) % 998244353 + sum[l[i]][j - 1]; n         dp[i][j] %= 998244353; n       } else n         dp[i][j] = 0; n       long long x = i - 1 >= 0 ? sum[i - 1][j] : 0; n       sum[i][j] = x + dp[i][j]; n       sum[i][j] %= 998244353; n     } n   } n   cout << dp[n - 1][n - 1] <<   n ; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   solve(); n } n


#include <bits/stdc++.h> n using namespace std; n template <class node> n struct link_cut_tree { n   bool connected(node* u, node* v) { return lca(u, v) != NULL; } n   int depth(node* u) { n     access(u); n     return get_sz(u->ch[0]); n   } n   node* get_root(node* u) { n     access(u); n     while (u->ch[0]) u = u->ch[0], u->push(); n     return access(u), u; n   } n   node* ancestor(node* u, int k) { n     k = depth(u) - k; n     assert(k >= 0); n     for (;; u->push()) { n       int sz = get_sz(u->ch[0]); n       if (sz == k) return access(u), u; n       if (sz < k) n         k -= sz + 1, u = u->ch[1]; n       else n         u = u->ch[0]; n     } n     assert(0); n   } n   node* lca(node* u, node* v) { n     if (u == v) return u; n     access(u); n     access(v); n     if (!u->p) return NULL; n     u->splay(); n     return u->p ?: u; n   } n   void link(node* u, node* v) { n     make_root(v); n     access(u); n     set_link(v, u, 0); n     v->update(); n   } n   void cut(node* u) { n     access(u); n     u->ch[0]->p = NULL; n     u->ch[0] = NULL; n     u->update(); n   } n   void cut(node* u, node* v) { cut(depth(u) > depth(v) ? u : v); } n   void make_root(node* u) { n     access(u); n     u->reverse(); n     access(u); n     assert(!u->ch[0] && !u->ch[1]); n   } n   void access(node* u) { n     for (node *v = u, *pre = NULL; v; v = v->p) { n       v->splay(); n       if (pre) v->update_vsub(pre, false); n       if (v->ch[1]) v->update_vsub(v->ch[1], true); n       v->ch[1] = pre; n       v->update(); n       pre = v; n     } n     u->splay(); n     assert(!u->ch[1]); n   } n   node* operator[](int i) { return &data[i]; } n   int operator[](node* i) { return i - &data[0]; } n   vector<node> data; n   link_cut_tree(int n) : data(n) {} n }; n template <typename pnode> n struct splay_tree { n   pnode ch[2], p; n   splay_tree() { ch[0] = ch[1] = p = NULL; } n   int dir() { n     if (!p) return -2; n     if (p->ch[0] == this) return 0; n     if (p->ch[1] == this) return 1; n     return -1; n   } n   bool is_root() { return dir() < 0; } n   friend void set_link(pnode u, pnode v, int d) { n     if (v) v->p = u; n     if (d >= 0) u->ch[d] = v; n   } n   void rotate() { n     assert(!is_root()); n     int x = dir(); n     pnode g = p; n     set_link(g->p, static_cast<pnode>(this), g->dir()); n     set_link(g, ch[x ^ 1], x); n     set_link(static_cast<pnode>(this), g, x ^ 1); n     g->update(); n   } n   void splay() { n     const pnode& self = static_cast<pnode>(this); n     while (!is_root() && !p->is_root()) { n       p->p->push(), p->push(), self->push(); n       dir() == p->dir() ? p->rotate() : self->rotate(); n       self->rotate(); n     } n     if (!is_root()) p->push(), self->push(), self->rotate(); n     self->push(); n     self->update(); n   } n }; n template <typename pnode, class splay_tree_vchs> n struct splay_tree_lct : splay_tree<pnode> { n   splay_tree_vchs vnode; n   using splay_tree<pnode>::ch; n   bool rev; n   splay_tree_vchs* root; n   splay_tree_lct() : splay_tree<pnode>() { n     root = NULL; n     rev = 0; n   } n   void update() {} n   void push() { n     if (rev) { n       if (ch[0]) ch[0]->reverse(); n       if (ch[1]) ch[1]->reverse(); n       rev = 0; n     } n   } n   void rotate() { n     swap(vnode, this->p->vnode); n     splay_tree<pnode>::rotate(); n   } n   void splay() { n     auto v = &vnode; n     bool r = !v->key; n     splay_tree<pnode>::splay(); n     if (r && v->key) { n       if (v->p) v->p->ch[v->p->ch[1] == &v->key->vnode] = v; n       if (v->ch[0]) v->ch[0]->p = v; n       if (v->ch[1]) v->ch[1]->p = v; n       v->key = static_cast<pnode>(this); n     } n   } n   void reverse() { n     rev ^= 1; n     swap(ch[0], ch[1]); n   } n   void update_vsub(pnode v, bool add) { n     auto& u = root; n     if (add) { n       v->vnode = splay_tree_vchs(v); n       if (!u) { n         u = &v->vnode; n         return; n       } n       while (u->ch[1]) u = u->ch[1]; n       u->ch[1] = &v->vnode; n       u->ch[1]->p = u; n       u = u->ch[1]; n       u->splay(); n     } else { n       auto x = &v->vnode; n       x->splay(); n       if (!x->ch[0]) { n         u = x->ch[1]; n       } else if (!x->ch[1]) { n         u = x->ch[0]; n       } else { n         u = x->ch[0]; n         u->p = NULL; n         while (u->ch[1]) u = u->ch[1]; n         u->ch[1] = x->ch[1]; n         x->ch[1]->p = u; n         u->splay(); n       } n       if (u) u->p = NULL; n       x->key = NULL; n     } n   } n }; n const int inf = -1e8; n template <typename pnode> n struct splay_tree_vchs : splay_tree<splay_tree_vchs<pnode>*> { n   using splay_tree<splay_tree_vchs<pnode>*>::ch; n   pnode key; n   int x; n   array<int, 4> y; n   splay_tree_vchs(){}; n   splay_tree_vchs(const pnode& key) n       : splay_tree<splay_tree_vchs<pnode>*>(), key(key) { n     build(); n   } n   void build() { n     x = key->x; n     y[0] = key->pp[0]; n     y[1] = 0; n     y[2] = key->pp[1]; n     y[3] = inf; n   } n   void update() { n     build(); n     for (int c = 0; c < 2; ++c) n       if (ch[c]) { n         x = max(x, ch[c]->x); n         for (int i = 0; i < 4; i += 2) { n           if (ch[c]->y[i] > y[i]) { n             y[i + 1] = y[i]; n             y[i] = ch[c]->y[i]; n             if (ch[c]->y[i + 1] > y[i + 1]) y[i + 1] = ch[c]->y[i + 1]; n           } else if (ch[c]->y[i] > y[i + 1]) n             y[i + 1] = ch[c]->y[i]; n         } n       } n   } n   void push() {} n }; n const array<int, 4> ainf = {0, inf, 0, inf}; n struct node : splay_tree_lct<node*, splay_tree_vchs<node*>> { n   bool val, len, sval; n   int slen; n   int x; n   array<int, 4> pp; n   node() : splay_tree_lct() { n     val = len = sval = 0; n     slen = x = 0; n     pp = ainf; n   } n   void update() { n     splay_tree_lct::update(); n     x = 0; n     sval = val; n     slen = len; n     array<int, 4> up = ainf, dw = ainf; n     array<int, 2> v1 = {0, inf}, v2 = v1; n     bool upsval = val; n     int upslen = len; n     bool dwsval = val; n     int dwslen = len; n     if (ch[0]) { n       x = max(x, ch[0]->x); n       up = ch[0]->pp; n       sval ^= ch[0]->sval; n       slen += ch[0]->slen; n       upsval ^= ch[0]->sval; n       upslen += ch[0]->slen; n     } n     if (ch[1]) { n       x = max(x, ch[1]->x); n       dw = ch[1]->pp; n       sval ^= ch[1]->sval; n       slen += ch[1]->slen; n       dwsval ^= ch[1]->sval; n       dwslen += ch[1]->slen; n     } n     if (root) { n       x = max(x, root->x); n       v1[0] = root->y[0]; n       v1[1] = root->y[2]; n       v2[0] = root->y[1]; n       v2[1] = root->y[3]; n     } n     pp[0] = up[0], pp[1] = up[1]; n     pp[2] = dw[2], pp[3] = dw[3]; n     for (int i = 0; i < 2; ++i) { n       x = max(x, len + max({up[2 + i] + dw[i ^ val], up[2 + i] + v1[i ^ val], n                             dw[i] + v1[i ^ val], v1[i] + v2[i ^ val]})); n       pp[i ^ upsval] = max(pp[i ^ upsval], upslen + max(dw[i], v1[i])); n       pp[2 + (i ^ dwsval)] = n           max(pp[2 + (i ^ dwsval)], dwslen + max(up[2 + i], v1[i])); n     } n   } n   void push() { splay_tree_lct::push(); } n   void reverse() { n     splay_tree_lct::reverse(); n     swap(pp[0], pp[2]); n     swap(pp[1], pp[3]); n   } n }; n int main() { n   ios_base::sync_with_stdio(0), cin.tie(0); n   int n; n   cin >> n; n   link_cut_tree<node> lct(2 * n); n   vector<vector<tuple<int, bool, int>>> adj(n); n   for (int i = 1, u, v, w; i < n; ++i) { n     cin >> u >> v >> w; n     --u, --v; n     adj[u].push_back({v, w, i}); n     adj[v].push_back({u, w, i}); n   } n   function<void(int, int)> dfs = [&](int u, int p) { n     for (auto [v, w, i] : adj[u]) n       if (v != p) { n         dfs(v, u); n         lct[n + i]->val = w; n         lct[n + i]->len = true; n         lct[n + i]->update(); n         lct.link(lct[u], lct[n + i]); n         lct.link(lct[n + i], lct[v]); n       } n   }; n   dfs(0, -1); n   int q; n   cin >> q; n   for (int i = 0, u; i < q; ++i) { n     cin >> u; n     lct.access(lct[n + u]); n     lct[n + u]->val ^= 1; n     lct[n + u]->update(); n     cout << lct[n + u]->x <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n map<int, map<int, int> > m; n long long int lol(long long int a, long long int r) { n   if (a >= 0 && r <= 0) return a; n   if (a <= 0 && r >= 0) return a; n   return a % r; n } n int main() { n   long long int a, b; n   cin >> a >> b; n   string s; n   cin >> s; n   long x = 0; n   long y = 0; n   if (a == 0 && b == 0) { n     cout <<  Yes  << endl; n     return 0; n   } n   for (long i = 0; i < s.size(); i++) { n     if (s[i] ==  L ) x--; n     if (s[i] ==  R ) x++; n     if (s[i] ==  U ) y++; n     if (s[i] ==  D ) y--; n   } n   long p = 2; n   long w = 0; n   long q = 0; n   int d = 0; n   for (long i = 0; i < s.size(); i++) { n     if (s[i] ==  L ) w--; n     if (s[i] ==  R ) w++; n     if (s[i] ==  U ) q++; n     if (s[i] ==  D ) q--; n     long long int u = a - w; n     long long int e = b - q; n     if (x != 0) { n       if (y != 0) { n         long long int v = u / x; n         long long int z = e / y; n         if (v == z && v >= 0 && u % x == 0 && e % y == 0) d = 1; n       } else { n         long long int v = a / x; n         if (e == 0 && v >= 0 && u % x == 0) d = 1; n       } n     } else { n       if (y != 0) { n         long long int z = e / y; n         if (z >= 0 && u == 0 && e % y == 0) d = 1; n       } else { n         if (u == 0 && e == 0) d = 1; n       } n     } n   } n   if (d == 1) n     cout <<  Yes  << endl; n   else n     cout <<  No  << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int V = 100100; n int l[V], r[V], a[V], ret, n; n int main() { n   while (~scanf( %d , &n)) { n     ret = 0; n     for (int i = 1; i <= n; i++) scanf( %d , &a[i]); n     for (int i = 1; i <= n; i++) l[i] = r[i] = i; n     for (int i = 1; i <= n; i++) { n       while (l[i] != 1 && a[l[i] - 1] < a[i]) l[i] = l[l[i] - 1]; n       if (l[i] != 1) ret = max(ret, a[i] ^ a[l[i] - 1]); n     } n     for (int i = n; i >= 1; i--) { n       while (r[i] != n && a[r[i] + 1] < a[i]) r[i] = r[r[i] + 1]; n       if (r[i] != n) ret = max(ret, a[i] ^ a[r[i] + 1]); n     } n     printf( %d n , ret); n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX_N = 17; n int n; n vector<int> adj[(1 << MAX_N) + 9]; n bool used[(1 << MAX_N) + 9]; n int cnt[(1 << MAX_N) + 9]; n vector<int> vRoot; n vector<int> ans; n void buildCnt(int x) { n   used[x] = true; n   cnt[x] = 1; n   for (int y : adj[x]) { n     if (!used[y]) { n       buildCnt(y); n       cnt[x] += cnt[y]; n     } n   } n   used[x] = false; n } n void findRoot(int x, vector<int>& vRoot) { n   used[x] = true; n   for (int y : adj[x]) { n     if (!used[y]) { n       findRoot(y, vRoot); n     } n   } n   if ((1 << n) - 2 - cnt[x] == (1 << n - 1) - 1) { n     vRoot.push_back(x); n   } else { n     for (int y : adj[x]) { n       if (!used[y]) { n         if (cnt[y] == (1 << n - 1) - 1) { n           vRoot.push_back(x); n           break; n         } n       } n     } n   } n   used[x] = false; n } n bool checkTree1(int x, int depth) { n   used[x] = true; n   bool result = false; n   if (cnt[x] != (1 << depth) - 1) { n     result = false; n   } else if (depth == 1) { n     result = true; n   } else { n     result = true; n     for (int y : adj[x]) { n       if (!used[y]) { n         if (!checkTree1(y, depth - 1)) { n           result = false; n           break; n         } n       } n     } n   } n   used[x] = false; n   return result; n } n int checkTree2(int x, int depth) { n   used[x] = true; n   int result = -1; n   if (cnt[x] != (1 << depth) - 2) { n     result = -1; n   } else if (depth == 2) { n     result = x; n   } else { n     vector<pair<int, int>> children; n     for (int y : adj[x]) { n       if (!used[y]) { n         children.push_back(make_pair(cnt[y], y)); n       } n     } n     sort(children.begin(), children.end()); n     if (children.size() == 2) { n       int tmp = checkTree2(children[0].second, depth - 1); n       if (tmp != -1 && checkTree1(children[1].second, depth - 1)) { n         result = tmp; n       } else { n         result = -1; n       } n     } else if (children.size() == 3) { n       if (checkTree1(children[0].second, depth - 2) && n           checkTree1(children[1].second, depth - 2) && n           checkTree1(children[2].second, depth - 1)) { n         result = x; n       } else { n         result = -1; n       } n     } else { n       result = -1; n     } n   } n   used[x] = false; n   return result; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cin >> n; n   for (int i = 1; i <= (1 << n) - 3; i++) { n     int x; n     int y; n     cin >> x >> y; n     adj[x].push_back(y); n     adj[y].push_back(x); n   } n   buildCnt(1); n   findRoot(1, vRoot); n   for (int root : vRoot) { n     buildCnt(root); n     int x = checkTree2(root, n); n     if (x != -1) { n       ans.push_back(x); n     } n   } n   sort(ans.begin(), ans.end()); n   cout << ans.size() <<   n ; n   for (int x : ans) { n     cout << x <<    ; n   } n   cout <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, k, maxx, idx, max1, s; n int main(int argc, char *argv[]) { n   pair<int, int> a[10000]; n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> a[i].first; n     a[i].second = 0; n   } n   maxx = 0; n   max1 = 0; n   for (int i = 0; i < n; i++) { n     if (a[i].first > maxx) { n       max1 = maxx; n       maxx = a[i].first; n       idx = i; n     } else if (max1 < a[i].first) n       max1 = a[i].first; n   } n   cout << idx + 1 <<     << max1 << endl; n   return EXIT_SUCCESS; n } n


#include <bits/stdc++.h> n using namespace std; n long long z, mn, mx, sum, ans, k, pos, pos1, r, xx, yy, zz, n, m, x, y; n vector<int> v; n bool OK[1000002], KO[1000002], zoom; n int b[100003], c[100002]; n map<char, int> mp, mr; n set<int> st; n int main() { n   cin >> n; n   for (int i = 0; i < n; ++i) { n     cin >> x >> y >> k; n     cout << ((k + 1) / 2 * x) - (k / 2 * y) <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main(void) { n   long long int n = 0ll, k = 0ll, p = 0ll, pn = 0ll, even = 0ll, odd = 0ll; n   while (cin >> n) { n     cin >> k >> p; n     if (k == 0) { n       for (long long int i = 0; i < p; i++) { n         cin >> pn; n         cout <<  . ; n       } n       cout << endl; n     } else { n       if (n % 2 == 0) { n         if (k >= (n >> 1)) { n           even = 2; n           k -= (n >> 1); n           odd = n + 1 - (k << 1); n         } else { n           odd = n + 1; n           even = n + 2 - (k << 1); n         } n         for (int i = 0; i < p; i++) { n           cin >> pn; n           if (pn % 2 == 0) { n             if (pn >= even) { n               cout <<  X ; n             } else { n               cout <<  . ; n             } n           } else { n             if (pn >= odd) { n               cout <<  X ; n             } else { n               cout <<  . ; n             } n           } n         } n         cout << endl; n       } else { n         n--; n         k--; n         if (k >= (n >> 1)) { n           even = 2; n           k -= (n >> 1); n           odd = n + 1 - (k << 1); n         } else { n           odd = n + 1; n           even = n + 2 - (k << 1); n         } n         for (int i = 0; i < p; i++) { n           cin >> pn; n           if (pn == n + 1) { n             cout <<  X ; n           } else if (pn % 2 == 0) { n             if (pn >= even) { n               cout <<  X ; n             } else { n               cout <<  . ; n             } n           } else { n             if (pn >= odd) { n               cout <<  X ; n             } else { n               cout <<  . ; n             } n           } n         } n         cout << endl; n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n map<int, int> mp; n int fin(int rem) { n   for (auto p : mp) { n     if (p.first >= rem) return p.first; n   } n   return -1; n } n int main() { n   long long ans = 0, rem = 0, p, x, y, n, RES = 1e9; n   cin >> n >> x >> y; n   long long a[] = {x, x, x, x, y, y}; n   sort(a, a + 6); n   do { n     mp.clear(); n     ans = 0; n     for (int i = 0; i < 6; ++i) { n       if ((x = fin(a[i])) == -1) { n         ++ans; n         ++mp[n - a[i]]; n       } else { n         ++mp[x - a[i]]; n         if (!--mp[x]) mp.erase(x); n       } n     } n     RES = min(RES, ans); n   } while (next_permutation(a, a + 6)); n   cout << RES; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 2000005; n template <typename T> n void read(T &x) { n   x = 0; n   int f = 1; n   char c = getchar(); n   for (; !isdigit(c); c = getchar()) n     if (c ==  - ) f = -f; n   for (; isdigit(c); c = getchar()) x = x * 10 + c -  0 ; n   x *= f; n } n template <typename T> n void write(T x) { n   if (x < 0) x = -x, putchar( - ); n   if (x > 9) write(x / 10); n   putchar(x % 10 +  0 ); n } n template <typename T> n void writeln(T x) { n   write(x); n   puts(  ); n } n int n, m1, m2, m, t; n int x1[MAXN], x2[MAXN]; n int mid1[MAXN], mid2[MAXN]; n int pos1[MAXN], pos2[MAXN]; n int dp[3][MAXN], path[3][MAXN], pos[MAXN]; n int main() { n   read(n), read(m1), read(m2), read(t); n   for (int i = 1; i <= m1; i++) read(x1[i]); n   for (int i = 1; i <= m2; i++) read(x2[i]); n   pos[++m] = 0; n   int p1 = 1, p2 = 1; n   while (p1 <= m1 || p2 <= m2) { n     if (p1 > m1) n       pos[++m] = x2[p2++] + 1; n     else if (p2 > m2) n       pos[++m] = x1[p1++] + 1; n     else { n       int Min = min(x1[p1], x2[p2]); n       pos[++m] = Min + 1; n       if (Min == x1[p1]) p1++; n       if (Min == x2[p2]) p2++; n     } n   } n   if (pos[m] != n + 1) pos[++m] = n + 1; n   p1 = 1; n   for (int i = 1; i <= m1; i++) { n     while (x1[i] > pos[p1]) p1++; n     if (pos[p1] > x1[i]) mid1[p1] = x1[i]; n     pos1[p1] += x1[i] == pos[p1]; n   } n   p2 = 1; n   for (int i = 1; i <= m2; i++) { n     while (x2[i] > pos[p2]) p2++; n     if (pos[p2] > x2[i]) mid2[p2] = x2[i]; n     pos2[p2] += x2[i] == pos[p2]; n   } n   memset(dp, -1, sizeof(dp)); n   dp[1][1] = 0; n   for (int i = 1; i <= m - 1; i++) { n     if (dp[1][i] != -1 && pos2[i] == 0) { n       int tmp = min(dp[1][i], t); n       if (tmp > dp[2][i]) { n         dp[2][i] = tmp; n         path[2][i] = 1; n       } n     } n     if (dp[2][i] != -1 && pos1[i] == 0) { n       int tmp = min(dp[2][i], t); n       if (tmp > dp[1][i]) { n         dp[1][i] = tmp; n         path[1][i] = 1; n       } n     } n     if (dp[1][i] != -1) { n       int tmp = dp[1][i]; n       if (pos1[i + 1] == 0 && mid1[i + 1] == 0) tmp += pos[i + 1] - pos[i]; n       if (pos1[i + 1] == 0 && mid1[i + 1] != 0) { n         tmp += mid1[i + 1] - pos[i] - 1; n         if (tmp < t) n           tmp = -1; n         else n           tmp -= t; n         if (tmp != -1) tmp += pos[i + 1] - mid1[i + 1] + 1; n       } n       if (pos1[i + 1] != 0 && mid1[i + 1] == 0) { n         tmp += pos[i + 1] - pos[i] - 1; n         if (tmp < t) n           tmp = -1; n         else n           tmp -= t; n         if (tmp != -1) tmp += 1; n       } n       if (pos1[i + 1] != 0 && mid1[i + 1] != 0) { n         tmp += mid1[i + 1] - pos[i] - 1; n         if (tmp < t) n           tmp = -1; n         else n           tmp -= t; n         if (tmp != -1) tmp += pos[i + 1] - mid1[i + 1]; n         if (tmp < t) n           tmp = -1; n         else n           tmp -= t; n         if (tmp != -1) tmp += 1; n       } n       dp[1][i + 1] = tmp; n     } n     if (dp[2][i] != -1) { n       int tmp = dp[2][i]; n       if (pos2[i + 1] == 0 && mid2[i + 1] == 0) tmp += pos[i + 1] - pos[i]; n       if (pos2[i + 1] == 0 && mid2[i + 1] != 0) { n         tmp += mid2[i + 1] - pos[i] - 1; n         if (tmp < t) n           tmp = -1; n         else n           tmp -= t; n         if (tmp != -1) tmp += pos[i + 1] - mid2[i + 1] + 1; n       } n       if (pos2[i + 1] != 0 && mid2[i + 1] == 0) { n         tmp += pos[i + 1] - pos[i] - 1; n         if (tmp < t) n           tmp = -1; n         else n           tmp -= t; n         if (tmp != -1) tmp += 1; n       } n       if (pos2[i + 1] != 0 && mid2[i + 1] != 0) { n         tmp += mid2[i + 1] - pos[i] - 1; n         if (tmp < t) n           tmp = -1; n         else n           tmp -= t; n         if (tmp != -1) tmp += pos[i + 1] - mid2[i + 1]; n         if (tmp < t) n           tmp = -1; n         else n           tmp -= t; n         if (tmp != -1) tmp += 1; n       } n       dp[2][i + 1] = tmp; n     } n   } n   if (dp[1][m] == -1 && dp[2][m] == -1) { n     printf( No n ); n     return 0; n   } n   printf( Yes n ); n   int px, py; n   if (dp[1][m] == -1) n     py = 2, px = m; n   else n     py = 1, px = m; n   static int shifts[MAXN], cnts = 0; n   static int x[MAXN], y[MAXN], cnt = 0; n   int now = 0; n   while (px != 1 || py != 1) { n     if (path[py][px]) { n       cnt += now; n       int tx = pos[px] - dp[py][px]; n       for (int i = 1; i <= now; i++) { n         tx += t; n         x[cnt - i + 1] = tx; n         y[cnt - i + 1] = py; n       } n       py = 3 - py; n       now = 0; n       shifts[++cnts] = pos[px]; n     } else { n       if (py == 1) n         now += mid1[px] != 0, now += pos1[px] != 0; n       else n         now += mid2[px] != 0, now += pos2[px] != 0; n       px = px - 1; n     } n   } n   cnt += now; n   int tx = 0; n   for (int i = 1; i <= now; i++) { n     tx += t; n     x[cnt - i + 1] = tx; n     y[cnt - i + 1] = py; n   } n   writeln(cnts); n   reverse(shifts + 1, shifts + cnts + 1); n   for (int i = 1; i <= cnts; i++) printf( %d  , shifts[i]); n   printf(  n ); n   writeln(cnt); n   reverse(x + 1, x + cnt + 1); n   reverse(y + 1, y + cnt + 1); n   for (int i = 1; i <= cnt; i++) printf( %d %d n , x[i], y[i]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int sum[100005]; n int main() { n   int h1, h2, a, b, k, x; n   cin >> h1 >> h2 >> a >> b; n   int num = h1 + a * 8; n   if (num >= h2) n     x = 0; n   else if (a <= b) n     x = -1; n   else { n     x = 1; n     num -= b * 12; n     for (int i = 1;; i++) { n       num += a * 12; n       if (num >= h2) n         break; n       else { n         x++; n         num -= b * 12; n       } n     } n   } n   cout << x << endl; n   return 0; n } n


#include <bits/stdc++.h> n const int N = 200010; n const long long INF = 1ll << 60; n const int inf = 0x3f3f3f3f; n class SegmentTree { n  public: n   SegmentTree() {} n   void Init(int n, int v[]) { n     n_ = n; n     Build(1, n, 1, v); n   } n   void ChangeSingle(int l, int r, int rt, int id, int x) { n     if (l == r) { n       min_[rt] = std::pair<int, int>(x, l); n       return; n     } n     int m = (l + r) >> 1; n     if (id <= m) { n       ChangeSingle(l, m, rt << 1, id, x); n     } else { n       ChangeSingle(m + 1, r, rt << 1 | 1, id, x); n     } n     Up(rt); n   } n   std::pair<int, int> MinInterval(int l, int r, int rt, int L, int R) { n     if (L > R) { n       return std::pair<int, int>(inf, inf); n     } n     if (L <= l && r <= R) { n       return min_[rt]; n     } n     int m = (l + r) >> 1; n     std::pair<int, int> ans(inf, inf); n     if (L <= m) { n       ans = std::min(ans, MinInterval(l, m, rt << 1, L, R)); n     } n     if (R > m) { n       ans = std::min(ans, MinInterval(m + 1, r, rt << 1 | 1, L, R)); n     } n     return ans; n   } n  n  private: n   void Build(int l, int r, int rt, int v[]) { n     if (l == r) { n       min_[rt].first = v[l]; n       min_[rt].second = l; n       return; n     } n     int m = (l + r) >> 1; n     Build(l, m, rt << 1, v); n     Build(m + 1, r, rt << 1 | 1, v); n     Up(rt); n   } n   void Up(int rt) { min_[rt] = std::min(min_[rt << 1], min_[rt << 1 | 1]); } n   int n_; n   std::pair<int, int> min_[N << 2 | 1]; n } seg; n int t; n int n, m; n int a[N]; n int b[N]; n std::multiset<int> se[N]; n int pre[N]; n int v[N]; n int main() { n   scanf( %d , &t); n   while (t--) { n     scanf( %d , &n); n     for (int i = 0; i < n; ++i) { n       se[i].clear(); n       pre[i] = 0; n     } n     for (int i = 1; i <= n; ++i) { n       scanf( %d%d , &a[i], &b[i]); n       se[a[i]].insert(b[i]); n     } n     if (n == 1) { n       printf( 0 n ); n       continue; n     } n     for (int i = 0; i < n; ++i) { n       pre[i] = (i == 0 ? se[i].size() : pre[i - 1] + se[i].size()); n       v[i] = (se[i].size() ? (*se[i].begin()) : inf); n     } n     seg.Init(n - 1, v); n     int id_st = n - 1; n     while (id_st >= 0 && pre[id_st] > id_st) { n       --id_st; n     } n     int num = 0; n     int num_last = 0; n     int num2 = 0; n     long long ans = 0ll; n     while (num < n) { n       int inc = 0; n       for (int i = num_last; i <= num; ++i) { n         if (se[i].size()) { n           inc += se[i].size(); n           se[i].clear(); n         } n       } n       num_last = num + 1; n       if (inc) { n         num += inc; n         continue; n       } else { n         while (id_st >= num + 1 && pre[id_st] + num2 > id_st) { n           --id_st; n         } n         std::pair<int, int> x = seg.MinInterval(1, n - 1, 1, id_st + 1, n - 1); n         ans += x.first; n         int id = x.second; n         se[id].erase(se[id].begin()); n         if (se[id].size()) { n           seg.ChangeSingle(1, n - 1, 1, id, *se[id].begin()); n         } else { n           seg.ChangeSingle(1, n - 1, 1, id, inf); n         } n         ++num2; n         ++num; n       } n     } n     printf( %lld n , ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n int main() { n   int n, k; n   scanf( %d %d , &n, &k); n   printf( %d n , 6 * n * k - k); n   for (int i = 0; i < n; ++i) { n     printf( %d %d %d %d n , 6 * i * k + k, 6 * i * k + 2 * k, 6 * i * k + 3 * k, n            6 * i * k + 5 * k); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long t, fact[405], inv[405], dp[405][405], ans[405], n, dp2[405]; n long long p; n long long exp(long long x, long long k) { n   if (k == 0) return 1; n   if (k % 2 == 1) return x * exp(x, k - 1) % p; n   long long y = exp(x, k / 2); n   return y * y % p; n } n int main() { n   cin >> t >> p; n   fact[0] = 1; n   for (int i = 1; i < 405; ++i) { n     fact[i] = i * fact[i - 1] % p; n     inv[i] = exp(i, p - 2); n   } n   dp[0][0] = 1; n   for (int i = 0; i <= 399; ++i) n     for (int k = 1; k <= 400; ++k) n       for (int j = 0; j <= 400 - k; ++j) n         dp[j + k][i + 1] = (dp[j + k][i + 1] + fact[k] * dp[j][i]) % p; n   dp2[1] = dp2[2] = 1; n   for (int i = 3; i <= 400; ++i) { n     dp2[i] = fact[i]; n     for (int j = 1; j < i; ++j) n       dp2[i] = (p + dp2[i] - dp2[j] * fact[i - j] % p) % p; n   } n   for (int i = 1; i <= 400; ++i) { n     ans[i] = fact[i]; n     for (int j = 3; j < i; ++j) ans[i] = (ans[i] + p - dp[i][j] * ans[j]) % p; n     for (int j = 1; j <= i - 1; ++j) n       ans[i] = (ans[i] + p - 2 * dp2[j] * fact[i - j] % p) % p; n     ans[2] = 2; n   } n   for (int i = 0; i < t; ++i) { n     int x; n     cin >> x; n     cout << ans[x] <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n struct Amulet { n   char p[2][2]; n   void Read() { cin >> p[0][0] >> p[0][1] >> p[1][0] >> p[1][1]; } n   Amulet Rotate() const { n     Amulet ret(*this); n     ret.p[0][0] = this->p[0][1]; n     ret.p[0][1] = this->p[1][1]; n     ret.p[1][0] = this->p[0][0]; n     ret.p[1][1] = this->p[1][0]; n     return ret; n   } n }; n bool Equiv(Amulet const& a1, Amulet const& a2) { n   return a1.p[0][0] == a2.p[0][0] && a1.p[0][1] == a2.p[0][1] && n          a1.p[1][0] == a2.p[1][0] && a1.p[1][1] == a2.p[1][1]; n } n bool operator==(Amulet const& a1, Amulet const& a2) { n   Amulet tmp(a1); n   for (int i = 0; i < 4; ++i) { n     if (Equiv(tmp, a2)) return true; n     tmp = tmp.Rotate(); n   } n   return false; n } n int main() { n   vector<Amulet> v; n   int n; n   cin >> n; n   for (int i = 0; i < n; ++i) { n     Amulet a; n     a.Read(); n     vector<Amulet>::iterator it = find(v.begin(), v.end(), a); n     if (it == v.end()) { n       v.push_back(a); n     } n     char dummy; n     cin >> dummy >> dummy; n   } n   cout << v.size() << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, k; n   cin >> n >> k; n   cout << (n / k + 1) * k; n } n


#include <bits/stdc++.h> n using namespace std; n struct node { n   int a; n   int id; n   bool operator<(const node &b) const { n     if (a != b.a) n       return a < b.a; n     else n       return id > b.id; n   } n }; n struct node que[305]; n bool vis[305]; n int main() { n   int t, n, m; n   scanf( %d , &t); n   while (t--) { n     memset(vis, 0, sizeof(vis)); n     scanf( %d%d , &n, &m); n     for (int i = 1; i <= m; i++) { n       scanf( %d , &que[i].a); n       que[i].id = i; n     } n     sort(que + 1, que + m + 1); n     long long ans = 0; n     for (int i = 1; i <= m; i++) { n       for (int j = 1; j < que[i].id; j++) ans += vis[j]; n       vis[que[i].id] = 1; n     } n     printf( %lld n , ans); n   } n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   string s; n   cin >> s; n   set<char> ss; n   for (char c : s) ss.insert(c); n   if (ss.size() < n) n     cout <<  NO  << endl; n   else { n     cout <<  YES  << endl; n     int vis[30]; n     memset(vis, 0, sizeof vis); n     string res =   ; n     for (char c : s) { n       if (n == 1) n         res += c; n       else { n         if (res.size() > 0 and !vis[c -  a ]) { n           n--; n           vis[c -  a ] = 1; n           cout << res << endl; n           res = string(1, c); n         } else { n           vis[c -  a ] = 1; n           res += c; n         } n       } n     } n     cout << res << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n long long stk[300001][3], top = 1, n, m, best = 1, nownum, K, B; n long long eval(long long x) { n   return (K + stk[x][0]) * stk[x][2] + B + stk[x][1]; n } n double intersect(long long x, long long y) { n   return (double)(stk[x][0] - stk[y][0]) / (stk[y][1] - stk[x][1]); n } n bool comp(long long x) { n   return eval(top) * (stk[top][2] - stk[top - 1][2]) >= n          (eval(top - 1) - eval(top)) * (x - stk[top][2]); n } n signed main() { n   scanf( %I64d%I64d , &nownum, &m); n   --nownum; n   for (long long i = 1, opt, k, b, s; i <= m; i++) { n     scanf( %I64d , &opt); n     if (opt == 1) { n       scanf( %I64d , &k); n       top = 1; n       K = B = 0; n       stk[top][0] = 0; n       stk[top][1] = 0; n       stk[top][2] = 0; n       nownum += k; n     } else if (opt == 2) { n       scanf( %I64d , &k); n       if (eval(top) == 0) { n         nownum += k; n         goto loop; n       } n       while (top > 1 && comp(nownum + 1)) --top; n       ++top; n       stk[top][0] = -K; n       stk[top][1] = -B; n       stk[top][2] = nownum + 1; n       nownum += k; n     } else { n       scanf( %I64d%I64d , &b, &s); n       K += s; n       B += b; n       while (top > 1 && eval(top - 1) <= eval(top)) --top; n     } n   loop: n     printf( %I64d %I64d n , stk[top][2] + 1, eval(top)); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, k, p, x; n   cin >> n >> k >> p; n   int impair(k - p); n   vector<int> pai, imp; n   for (int i = 0; i < n; ++i) { n     cin >> x; n     if (x & 1) n       imp.push_back(x); n     else n       pai.push_back(x); n   } n   int avpair(pai.size()), avimpair(imp.size()); n   avimpair -= impair; n   if (avimpair < 0 || (avpair + (avimpair >> 1)) < p || (avimpair & 1)) { n     cout <<  NO ; n     return 0; n   } n   cout <<  YES n ; n   vector<vector<int> > res; n   res.resize(k); n   int iimp(0), ipai(0); n   for (int i = 0; i < impair; ++i) res[i].push_back(imp[iimp++]); n   for (int i = impair; i < k; ++i) n     if (ipai < pai.size()) n       res[i].push_back(pai[ipai++]); n     else { n       res[i].push_back(imp[iimp++]); n       res[i].push_back(imp[iimp++]); n     } n   while (ipai < pai.size()) res[0].push_back(pai[ipai++]); n   while (iimp < imp.size()) res[0].push_back(imp[iimp++]); n   for (int i = 0; i < k; ++i) { n     cout << res[i].size() <<    ; n     for (int j = 0; j < res[i].size(); ++j) cout << res[i][j] <<    ; n     cout <<   n ; n   } n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n template <typename T> n inline void read(T &x) { n   x = 0; n   bool f = false; n   char ch = getchar(); n   while (!isdigit(ch)) { n     f |= ch ==  - , ch = getchar(); n   } n   while (isdigit(ch)) { n     x = (x << 1) + (x << 3) + (ch ^ 48); n     ch = getchar(); n   } n   x = f ? -x : x; n   return; n } n template <typename T> n inline void write(T x) { n   if (x < 0) x = -x, putchar( - ); n   if (x > 9) write(x / 10); n   putchar(x % 10 ^ 48); n   return; n } n const int N = 1e3 + 5, MOD = 998244353; n int n, m, val[N], dp[N], Ans, C[N][N]; n int main() { n   read(n); n   for (int i = 1; i <= n; i++) read(val[i]), C[i][i] = C[i][0] = 1; n   for (int i = 1; i <= n; i++) n     for (int j = 1; j < i; j++) n       C[i][j] = (C[i - 1][j - 1] + C[i - 1][j] > +MOD n                      ? C[i - 1][j - 1] + C[i - 1][j] - MOD n                      : C[i - 1][j - 1] + C[i - 1][j]); n   dp[n + 1] = 1; n   for (int i = n; i >= 1; i--) { n     if (val[i] <= 0) continue; n     for (int j = val[i] + i + 1; j <= n + 1; j++) n       dp[i] = (dp[i] + 1ll * dp[j] * C[j - i - 1][val[i]] % MOD > +MOD n                    ? dp[i] + 1ll * dp[j] * C[j - i - 1][val[i]] % MOD - MOD n                    : dp[i] + 1ll * dp[j] * C[j - i - 1][val[i]] % MOD); n   } n   for (int i = 1; i <= n; i++) n     Ans = (Ans + dp[i] > +MOD ? Ans + dp[i] - MOD : Ans + dp[i]); n   write(Ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class t> n t mag(t a) { n   return a > 0 ? a : -a; n } n template <class T, class U> n T cdiv(T num, U den) { n   return (num / den) + ((num % den) > 0); n } n std::ifstream term( /dev/tty ); n std::string tempstring; n using ll = int_fast64_t; n using ii = pair<int, int>; n using vi = vector<int>; n using vl = vector<ll>; n using vii = vector<ii>; n const int &sij = 400010; n const ll &mod = 998244353ll; n int n; n ll add(ll a, ll b) { return (a + b) % mod; } n int esc(int tcase) { n   cin >> n; n   vi vec(n); n   for (auto &e : vec) cin >> e; n   vl dp0(201), sdp0(201), dp1(201), sdp1(201); n   for (int i = 1; i <= 200; i++) { n     if (vec.back() == -1 or i == vec.back()) dp0[i] = 1; n   } n   partial_sum(dp0.begin(), dp0.end(), sdp0.begin(), add); n   partial_sum(dp1.begin(), dp1.end(), sdp1.begin(), add); n   ; n   auto get0 = [&](int l, int r) -> ll { n     if (r < l) return 0; n     return (sdp0[r] - sdp0[l - 1] + mod) % mod; n   }; n   auto get1 = [&](int l, int r) -> ll { n     if (r < l) return 0; n     return (sdp1[r] - sdp1[l - 1] + mod) % mod; n   }; n   for (auto i = n - 2; i >= 0; i--) { n     vl ndp0(201), ndp1(201); n     for (int x = 1; x <= 200; x++) { n       if (vec[i] == -1 or x == vec[i]) { n         ndp0[x] = (get0(1, x - 1) + get1(1, x - 1)) % mod; n         ndp1[x] = (get1(x + 1, 200) + get1(x, x) + get0(x, x)) % mod; n       } n     } n     partial_sum(ndp0.begin(), ndp0.end(), sdp0.begin(), add); n     partial_sum(ndp1.begin(), ndp1.end(), sdp1.begin(), add); n     ; n     ; n     ; n   } n   cout << get1(1, 200) <<   n ; n   return 0; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int tc = 1; n   for (int i = 1; i <= tc; i++) esc(i); n } n


#include <bits/stdc++.h> n using namespace std; n const long long INF = 1 << 28; n const long long LINF = 1ll << 61; n inline long long getnum() { n   register long long r = 0; n   register bool ng = 0; n   register char c; n   c = getchar(); n   while (c !=  -  && (c <  0  || c >  9 )) c = getchar(); n   if (c ==  - ) ng = 1, c = getchar(); n   while (c !=     && c !=   n ) r = r * 10 + c -  0 , c = getchar(); n   if (ng) r = -r; n   return r; n } n template <class T> n inline void putnum(T x) { n   if (x < 0) putchar( - ), x = -x; n   register short a[20] = {}, sz = 0; n   while (x > 0) a[sz++] = x % 10, x /= 10; n   if (sz == 0) putchar( 0 ); n   for (int i = sz - 1; i >= 0; i--) putchar( 0  + a[i]); n } n inline void putsp() { putchar(   ); } n inline void putendl() { putchar(  n ); } n inline char mygetchar() { n   register char c = getchar(); n   while (c ==     || c ==   n ) c = getchar(); n   return c; n } n const int dx[] = {1, -1, 0, 0}; n const int dy[] = {0, 0, 1, -1}; n const int maxn = 1700; n int w, h, c[maxn][maxn], ans[12345]; n bool g[maxn][maxn], ng[2][maxn][maxn], vis[maxn][maxn], p; n void color(int x, int y, int id) { n   c[x][y] = id; n   for (int i = 0; i < 4; i++) { n     int nx = x + dx[i], ny = y + dy[i]; n     if (nx > 0 && nx <= w && ny > 0 && ny <= h && g[nx][ny] && c[nx][ny] == 0) { n       color(nx, ny, id); n     } n   } n } n void dfs(int x, int y) { n   vis[x][y] = 1; n   for (int i = 0; i < 4; i++) { n     int nx = x + dx[i], ny = y + dy[i]; n     if (nx > 0 && nx <= w && ny > 0 && ny <= h && g[nx][ny] && !vis[nx][ny]) { n       dfs(nx, ny); n     } n   } n } n void getsmaller() { n   p ^= 1; n   for (int i = 1; i <= w; i++) { n     for (int j = 1; j <= h; j++) { n       ng[p][i][j] = ng[p ^ 1][i][j]; n       for (int k = 0; k < 4; k++) { n         if (!ng[p ^ 1][i + dx[k]][j + dy[k]]) { n           ng[p][i][j] = 0; n         } n       } n     } n   } n } n void getbigger() { n   p ^= 1; n   for (int i = 1; i <= w; i++) { n     for (int j = 1; j <= h; j++) { n       ng[p][i][j] = ng[p ^ 1][i][j]; n       for (int k = 0; k < 4; k++) { n         if (ng[p ^ 1][i + dx[k]][j + dy[k]]) { n           ng[p][i][j] = 1; n         } n       } n     } n   } n } n void see() { n   for (int i = 1; i <= w; i++) { n     for (int j = 1; j <= h; j++) { n       putnum(g[i][j] & (!vis[i][j])), putsp(); n     } n     putendl(); n   } n   putendl(); n } n int main() { n   w = getnum(), h = getnum(); n   for (int i = 1; i <= w; i++) { n     for (int j = 1; j <= h; j++) { n       g[i][j] = getnum(); n     } n   } n   int id = 0; n   for (int i = 1; i <= w; i++) { n     for (int j = 1; j <= h; j++) { n       if (g[i][j] && c[i][j] == 0) { n         id++; n         color(i, j, id); n       } n     } n   } n   for (int i = 1; i <= w; i++) n     for (int j = 1; j <= h; j++) ng[p][i][j] = g[i][j]; n   getsmaller(); n   getsmaller(); n   getsmaller(); n   getbigger(); n   getbigger(); n   getbigger(); n   getbigger(); n   getbigger(); n   for (int i = 1; i <= w; i++) { n     for (int j = 1; j <= h; j++) { n       g[i][j] &= !ng[p][i][j]; n     } n   } n   for (int i = 1; i <= w; i++) n     for (int j = 1; j <= h; j++) ng[p][i][j] = g[i][j]; n   getsmaller(); n   getbigger(); n   for (int i = 1; i <= w; i++) n     for (int j = 1; j <= h; j++) g[i][j] = ng[p][i][j]; n   for (int i = 1; i <= w; i++) { n     for (int j = 1; j <= h; j++) { n       if (g[i][j] && !vis[i][j]) { n         ans[c[i][j]]++; n         dfs(i, j); n       } n     } n   } n   sort(ans + 1, ans + id + 1); n   putnum(id), putsp(), putendl(); n   for (int i = 1; i <= id; i++) putnum(ans[i]), putsp(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n class Solve { n  public: n   int num; n   int inputNum[2005]; n   int inversion[2005][2]; n   int sequence[2005]; n  n  public: n   Solve() { n     num = 0; n     memset(inputNum, 0, sizeof(inputNum)); n     memset(inversion, 0, sizeof(inversion)); n     memset(sequence, 0, sizeof(sequence)); n   } n   void stat() { n     for (int i = 0; i < num; ++i) { n       for (int j = 0; j < i; ++j) { n         if (inputNum[j] < inputNum[i]) { n           ++inversion[i][0]; n         } n       } n     } n     for (int i = 0; i < num; ++i) { n       for (int j = i + 1; j < num; ++j) { n         if (inputNum[i] > inputNum[j]) { n           ++inversion[i][1]; n         } n       } n     } n   } n   void calculate() { n     for (int i = 0; i < num; ++i) { n       if (inversion[i][0] < inversion[i][1]) { n         sequence[i] = -inputNum[i]; n       } else { n         sequence[i] = inputNum[i]; n       } n     } n   } n   int getResult() { n     int total = 0; n     for (int i = 0; i < num; ++i) { n       for (int j = i + 1; j < num; ++j) { n         if (sequence[i] > sequence[j]) { n           ++total; n         } n       } n     } n     return total; n   } n   void readData() { n     cin >> num; n     for (int i = 0; i < num; ++i) { n       cin >> inputNum[i]; n       if (inputNum[i] < 0) { n         inputNum[i] = -1 * inputNum[i]; n       } n     } n   } n   int facade() { n     readData(); n     stat(); n     calculate(); n     return getResult(); n   } n }; n int main() { n   Solve solve; n   cout << solve.facade() << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m, x, y; n   cin >> n >> m; n   y = 3 * m; n   x = 2 * n; n   for (int i = 6; i <= x && i <= y; i += 6) { n     if (x <= y) n       x += 2; n     else n       y += 3; n   } n   cout << max(x, y); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 505; n bool arr[N][N]; n int dp[N][N]; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   int n, m, k; n   cin >> n >> m >> k; n   for (int i = 1; i <= n; i++) { n     string s; n     cin >> s; n     for (int j = 1; j <= m; j++) { n       arr[i][j] = (int)(s[j - 1] -  0 ); n     } n   } n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= m; j++) { n       if (arr[i][j] && arr[i - 1][j] && arr[i + 1][j] && arr[i][j - 1] && n           arr[i][j + 1]) { n         dp[i][j] = 1; n       } n     } n   } n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= m; j++) { n       dp[i][j] += dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1]; n     } n   } n   long long int ans = 0; n   for (int a = 2; a < n; a++) { n     for (int b = a; b < n; b++) { n       int ptr = 1; n       for (int c = 2; c < m; c++) { n         while (ptr < m && n                (dp[a - 1][c - 1] - dp[b][c - 1] - dp[a - 1][ptr] + dp[b][ptr] < n                 k)) { n           ptr++; n         } n         ans += (m - ptr); n       } n     } n   } n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n static long long mi[400005][20]; n static bool mark[400005][20]; n static long long psum[400005]; n long long f(int x, int k) { n   if (k == 0) return psum[x]; n   if (mark[x][k]) return mi[x][k]; n   mark[x][k] = 1; n   return mi[x][k] = min(f(x, k - 1), f(x + (1 << (k - 1)), k - 1)); n } n long long qry(int l, int r) { n   int t = r - l + 1; n   int lg = 31 - __builtin_clz(t); n   return min(f(l, lg), f(r - (1 << lg) + 1, lg)); n } n int main() { n   long long n, a, b, c, d, start, len; n   scanf( %lld %lld %lld %lld %lld %lld %lld , &n, &a, &b, &c, &d, &start, &len); n   vector<pair<long long, long long> > v; n   for (long long i = 0; i < n; i++) { n     long long x, y; n     scanf( %lld %lld , &x, &y); n     v.push_back(make_pair(y, x)); n   } n   if (v[0].first == 0) n     psum[0] = -d; n   else n     psum[0] = c; n   for (int i = 1; i < n; i++) { n     if (v[i].first) n       psum[i] = psum[i - 1] + c; n     else n       psum[i] = psum[i - 1] - d; n   } n   psum[n] = 1000000000000000000; n   vector<long long> t; n   t.push_back(0); n   for (int i = 0; i < n; i++) { n     t.push_back(v[i].second + 1); n     if (v[i].second - len + 1 >= 0) t.push_back(v[i].second - len + 1); n   } n   sort(t.begin(), t.end()); n   int l = 0, r = 0; n   long long at = start; n   for (int i = 0; i < t.size(); i++) { n     while (l < v.size() && v[l].second < t[i]) { n       if (v[l].first) n         at += a; n       else n         at -= b; n       if (at < 0) { n         printf( -1 n ); n         return 0; n       } n       l++; n     } n     while (r < v.size() && v[r].second < t[i] + len) r++; n     long long low = qry(l, r - 1) - (l > 0 ? psum[l - 1] : 0) + at; n     if (low >= 0) { n       printf( %lld n , t[i]); n       return 0; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int get() { n   char ch; n   while (ch = getchar(), (ch <  0  || ch >  9 ) && ch !=  - ) n     ; n   if (ch ==  - ) { n     int s = 0; n     while (ch = getchar(), ch >=  0  && ch <=  9 ) s = s * 10 + ch -  0 ; n     return -s; n   } n   int s = ch -  0 ; n   while (ch = getchar(), ch >=  0  && ch <=  9 ) s = s * 10 + ch -  0 ; n   return s; n } n const int mo = 1e9 + 7; n const int N = 2e6 + 5; n int cnt[N]; n int val[N]; n int lst[N]; n int pri[N], k; n int n; n int tim[N]; n bool bz[N]; n int main() { n   n = get(); n   for (int i = 1; i <= n; i++) { n     int x = get(); n     cnt[x]++; n   } n   lst[1] = 1; n   for (int i = 2; i <= 2e6; i++) { n     if (!lst[i]) pri[++k] = lst[i] = i; n     for (int j = 1; j <= k; j++) { n       if (1ll * pri[j] * i > 2e6) break; n       lst[i * pri[j]] = pri[j]; n       if (i % pri[j] == 0) break; n     } n   } n   for (int i = 1; i <= 2e6; i++) val[i] = 1; n   int C = 0; n   for (int i = 2e6; i >= 2; i--) { n     for (int T = 1; T <= cnt[i]; T++) { n       if (val[i] < i) n         bz[i] = 1, tim[i] = 1, val[i] = i; n       else { n         bz[i - 1] = 1; n         int x = i - 1; n         while (x > 1) { n           int v = lst[x]; n           int t = 1; n           while (x % v == 0) { n             x /= v; n             t = t * v; n           } n           if (t > val[v]) { n             val[v] = t; n             tim[v] = 1; n           } else if (val[v] == t) n             tim[v]++; n         } n       } n     } n   } n   for (int i = 1; i <= 2e6; i++) n     if (bz[i]) { n       bool can = 1; n       for (int x = i; x > 1;) { n         int v = lst[x], t = 1; n         for (; x % v == 0;) x /= v, t *= v; n         if (val[v] == t && tim[v] == 1) can = 0; n       } n       if (can) { n         C = 1; n         break; n       } n     } n   int ans = 1; n   for (int i = 1; i <= 2e6; i++) ans = 1ll * ans * val[i] % mo; n   ans = (ans + C) % mo; n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool vis[50]; n bool OK(vector<set<int> > v) { n   for (int i = 0; i < (int)v.size(); i++) n     if ((int)v[i].size() > 3) return 1; n   return 0; n } n int Find(vector<set<int> > v, int x) { n   for (int i = 0; i < (int)v.size(); i++) n     if (find(v[i].begin(), v[i].end(), x) != v[i].end()) return i; n   return -1; n } n int main() { n   int n, q, x, y, ex, ey, c = 0; n   scanf( %d %d , &n, &q); n   if (n % 3) { n     cout << -1; n     return 0; n   } n   vector<set<int> > v(n / 3); n   while (q--) { n     scanf( %d %d , &x, &y); n     vis[x] = 1, vis[y] = 1; n     ex = Find(v, x), ey = Find(v, y); n     if (ex != -1) n       v[ex].insert(y); n     else if (ey != -1) n       v[ey].insert(x); n     else { n       if (c == n / 3) { n         cout << -1; n         return 0; n       } n       v[c].insert(x), v[c].insert(y), c++; n     } n   } n   if (OK(v)) { n     cout << -1; n     return 0; n   } n   c = 1; n   for (int i = 0; i < (int)v.size(); i++) { n     for (int j = 0; j < 3 - (int)v[i].size(); j++) { n       for (int k = c; k < n + 1; k++) n         if (!vis[k]) { n           v[i].insert(k); n           c = k + 1; n           j--; n           break; n         } n     } n   } n   for (int i = 0; i < (int)v.size(); i++) { n     for (set<int>::iterator it = v[i].begin(); it != v[i].end(); it++) n       printf( %d  , *it); n     printf(  n ); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long w1, h1, w2, h2; n   cin >> w1 >> h1 >> w2 >> h2; n   long long ans = h1 + h2 + 2; n   ans += h1 + h2 + 2 + (w1 - w2); n   ans += w1 + w2; n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 100005; n vector<int> cnt[N]; n int res[N]; n int main() { n   int n; n   while (cin >> n) { n     for (int i = 1; i < N; i++) cnt[i].clear(); n     for (int i = 1; i <= n; i++) { n       int v; n       cin >> v; n       cnt[v].push_back(i); n     } n     bool ok = true; n     for (int i = 1; i < N; i++) { n       if (i > 1 && cnt[i].size() > cnt[i - 1].size()) ok = false; n       for (int j = 0; j < cnt[i].size(); j++) { n         res[cnt[i][j]] = j + 1; n       } n     } n     if (!ok) { n       printf( %d n , -1); n     } else { n       printf( %d n , cnt[1].size()); n       for (int i = 1; i <= n; i++) printf( %d%c , res[i], i == n ?   n  :    ); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   while (n--) { n     int a, s, d; n     cin >> a >> s >> d; n     if (a > s) swap(a, s); n     if (a > d) swap(a, d); n     if (s > d) swap(s, d); n     if (s == d) { n       cout <<  YES  << endl; n       cout << a <<     << a <<     << d << endl; n     } else { n       cout <<  NO  << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1005; n const int INF = 1e9; n pair<int, int> NULLPOINT = make_pair(INF, INF); n int n; n int gcd(int x, int y) { n   while (y) { n     int t = x; n     x = y; n     y = t % y; n   } n   return x; n } n struct Line { n   int x, y, xx, yy; n   pair<int, int> slope() { n     pair<int, int> ret = {x - xx, y - yy}; n     if (ret.second < 0) { n       ret.first *= -1; n       ret.second *= -1; n     } n     int g = gcd(abs(ret.first), ret.second); n     ret.first /= g, ret.second /= g; n     return ret; n   } n   pair<int, int> intersect(const Line &l) const { n     long long den = n         1LL * (x - xx) * (l.y - l.yy) - 1LL * (y - yy) * (l.x - l.xx); n     if (den == 0) return NULLPOINT; n     long long c1 = 1LL * x * yy - 1LL * y * xx; n     long long c2 = 1LL * l.x * l.yy - 1LL * l.y * l.xx; n     long long ix = c1 * (l.x - l.xx) - (x - xx) * c2; n     long long iy = c1 * (l.y - l.yy) - (y - yy) * c2; n     if (ix % den != 0) return NULLPOINT; n     if (iy % den != 0) return NULLPOINT; n     ix /= den; n     iy /= den; n     if (ix < min(x, xx) || ix > max(x, xx) || ix < min(l.x, l.xx) || n         ix > max(l.x, l.xx)) n       return NULLPOINT; n     if (iy < min(y, yy) || iy > max(y, yy) || iy < min(l.y, l.yy) || n         iy > max(l.y, l.yy)) n       return NULLPOINT; n     return pair<int, int>(ix, iy); n   } n }; n Line lines[N]; n int main() { n   scanf( %d , &n); n   for (int i = 0; i < n; ++i) { n     scanf( %d %d %d %d , &lines[i].x, &lines[i].y, &lines[i].xx, &lines[i].yy); n   } n   long long ans = 0; n   for (int i = 0; i < n; ++i) { n     pair<int, int> slope = lines[i].slope(); n     if (slope.first == 0) n       ans += abs((lines[i].y - lines[i].yy) / slope.second) + 1; n     else n       ans += abs((lines[i].x - lines[i].xx) / slope.first) + 1; n   } n   set<pair<int, int>> intersects; n   intersects.insert(NULLPOINT); n   for (int i = 0; i < n; ++i) { n     set<pair<int, int>> lineIntersects; n     lineIntersects.insert(NULLPOINT); n     for (int j = 0; j < n; ++j) { n       pair<int, int> p = lines[i].intersect(lines[j]); n       lineIntersects.insert(p); n       intersects.insert(p); n     } n     ans -= lineIntersects.size() - 1; n   } n   ans += intersects.size() - 1; n   printf( %lld n , ans); n   return 0; n } n


#include <bits/stdc++.h> n int main() { n   long long n, k; n   scanf( %lld%lld , &n, &k); n   if (k < 2) { n     printf( %lld , n); n     return 0; n   } n   long long s = 1; n   while (s - 1 < n) s *= 2; n   printf( %lld , s - 1); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   cin.sync_with_stdio(0); n   cin.tie(0); n   cin.exceptions(cin.failbit); n   int n; n   cin >> n; n   vector<long long> a(n); n   long long s = 0; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n     s += a[i]; n   } n   sort(a.begin(), a.end()); n   reverse(a.begin(), a.end()); n   if (s % 2 == 1) { n     cout <<  NO  << endl; n     return 0; n   } n   if (a[0] <= s / 2) { n     cout <<  YES  << endl; n   } else { n     cout <<  NO  << endl; n   } n   return 0; n } n