#include <bits/stdc++.h> n using namespace std; n int const N = 1010; n int const M = 1001000; n int n, m; n struct Graph { n   struct edges { n     int u, next; n     long long c; n   } e[M]; n   int p[N], idx; n   void addedge(int u, int v, long long c) { n     e[idx].u = v, e[idx].next = p[u], e[idx].c = c, p[u] = idx++; n   } n   void init() { n     idx = 0; n     memset(p, (0xff), sizeof p); n   } n   queue<int> q; n   long long dis[N]; n   bool used[N]; n   void spfa(int s) { n     int t, u; n     long long w; n     while (!q.empty()) q.pop(); n     memset(used, 0, sizeof used); n     for (int i = 1; i <= (n); ++i) dis[i] = 0x3FFFFFFFFFFFFFFFLL; n     dis[s] = 0; n     q.push(s); n     while (!q.empty()) { n       t = q.front(); n       q.pop(); n       used[t] = false; n       for (int i = p[t]; ~i; i = e[i].next) { n         u = e[i].u, w = e[i].c; n         if (dis[t] + w < dis[u]) { n           dis[u] = dis[t] + w; n           if (!used[u]) { n             used[u] = true; n             q.push(u); n           } n         } n       } n     } n   } n } g1, g2; n long long ti[N], ci[N]; n int main() { n   scanf( %d%d , &n, &m); n   g1.init(); n   int s, t; n   scanf( %d%d , &s, &t); n   for (int i = 0; i < (m); ++i) { n     int x, y, z; n     scanf( %d%d%d , &x, &y, &z); n     g1.addedge(x, y, z); n     g1.addedge(y, x, z); n   } n   for (int i = 1; i <= (n); ++i) scanf( %I64d %I64d , &ti[i], &ci[i]); n   g2.init(); n   for (int i = 1; i <= (n); ++i) { n     g1.spfa(i); n     for (int j = 1; j <= (n); ++j) n       if (i != j) { n         if (g1.dis[j] <= ti[i]) { n           g2.addedge(i, j, ci[i]); n         } n       } n   } n   g2.spfa(s); n   if (g2.dis[t] == 0x3FFFFFFFFFFFFFFFLL) n     puts( -1 ); n   else n     printf( %I64d n , g2.dis[t]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long int maxn = 1e5 + 6; n const long long int MOD = 1e9 + 7; n vector<int> prim(1000005, 1); n int fact[maxn]; n long long int binomialCoeff(long long int n, long long int k) { n   long long int res = 1; n   if (k > n - k) k = n - k; n   for (long long int i = 0; i < k; ++i) { n     res *= (n - i); n     res /= (i + 1); n   } n   return res; n } n bool isVowel(char ch) { n   if (ch ==  a  || ch ==  i  || ch ==  e  || ch ==  u  || ch ==  o ) { n     return true; n   } n   return false; n } n long long int power(long long int x, long long int i, long long int mod) { n   long long int ans = 1; n   while (i > 0) { n     if (i & 1) ans = (ans * x) % mod; n     i >>= 1; n     x = (x * x) % mod; n   } n   return ans; n } n long long int modInverse(long long int x, long long int mod) { n   return power(x, mod - 2, mod); n } n int nCr(int n, int r) { n   if (n < r) { n     return 0; n   } n   return (((fact[n] * modInverse(fact[n - r], MOD)) % MOD) * n           modInverse(fact[r], MOD)) % n          MOD; n } n long long int power(int x, unsigned int y) { n   long long int temp; n   if (y == 0) return 1; n   temp = power(x, y / 2); n   if (y % 2 == 0) n     return temp * temp; n   else n     return x * temp * temp; n } n void erath(int n) { n   prim[1] = 0; n   prim[0] = 0; n   prim[2] = 1; n   for (int i = 2; i * i <= n; i++) { n     if (prim[i]) { n       for (int j = i * i; j <= n; j += i) { n         prim[j] = 0; n       } n     } n   } n } n long long int gcd(long long int a, long long int b) { n   if (b == 0) return a; n   return gcd(b, a % b); n } n long long int lcm(long long int a, long long int b) { n   return (a / gcd(a, b)) * b; n } n bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) { n   return (a.second < b.second); n } n long long int n, m, k; n int getmid(int l, int r) { return (l + (r - l) / 2); } n struct segtree { n   int siz; n   vector<pair<long long int, long long int> > sums; n   void init(int n) { n     siz = 1; n     while (siz < n) siz *= 2; n     sums.assign(2 * siz, {LONG_MAX, 0}); n   } n   void set(int i, int v, int cur, int l, int r) { n     if (r - l == 1) { n       sums[cur].first = v; n       sums[cur].second = 1; n       return; n     } n     int m = getmid(l, r); n     if (i < m) { n       set(i, v, 2 * cur + 1, l, m); n     } else n       set(i, v, 2 * cur + 2, m, r); n     sums[cur].first = min(sums[2 * cur + 1].first, sums[2 * cur + 2].first); n     if (sums[2 * cur + 1].first == sums[cur].first && n         sums[2 * cur + 2].first == sums[cur].first) { n       sums[cur].second = sums[cur * 2 + 1].second + sums[cur * 2 + 2].second; n     } else if (sums[2 * cur + 1].first == sums[cur].first) { n       sums[cur].second = sums[cur * 2 + 1].second; n     } else { n       sums[cur].second = sums[cur * 2 + 2].second; n     } n   } n   void set(int i, int v) { set(i, v, 0, 0, siz); } n   pair<long long int, long long int> sum(int l, int r, int cur, int lx, n                                          int rx) { n     if (lx >= r || l >= rx) return {LONG_MAX, 0}; n     if (lx >= l && rx <= r) return {sums[cur].first, sums[cur].second}; n     int mid = getmid(lx, rx); n     pair<long long int, long long int> s1 = sum(l, r, 2 * cur + 1, lx, mid), n                                        s2 = sum(l, r, 2 * cur + 2, mid, rx); n     if (s1.first < s2.first) { n       return s1; n     } else if (s1.first > s2.first) n       return s2; n     else n       return {s1.first, s1.second + s2.second}; n   } n   pair<long long int, long long int> sum(int l, int r) { n     return sum(l, r, 0, 0, siz); n   } n }; n int nCrModp(int n, int r, int p) { n   if (r > n - r) r = n - r; n   int C[r + 1]; n   memset(C, 0, sizeof(C)); n   C[0] = 1; n   for (int i = 1; i <= n; i++) { n     for (int j = min(i, r); j > 0; j--) C[j] = (C[j] + C[j - 1]) % p; n   } n   return C[r]; n } n void ans(int top) { n   cin >> n >> k; n   long long int h[n], mx = INT_MIN, mn = INT_MAX; n   vector<long long int> fin(200002, 0); n   for (int i = 0; i < n; i++) { n     cin >> h[i]; n     if (h[i] > 0) fin[1] += 1; n     if (h[i] > 0) fin[h[i] + 1] -= 1; n     mx = max(mx, h[i]); n     mn = min(mn, h[i]); n   } n   for (int i = 1; i < mx + 1; i++) { n     fin[i] += fin[i - 1]; n   } n   int i = mx, ans = 0; n   while (i > mn) { n     int j = i, sum = 0; n     while (sum + fin[j] <= k) { n       sum += fin[j]; n       j--; n     } n     i = j; n     ans++; n   } n   cout << ans << endl; n } n int main() { n   ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); n   int t = 1, co = 1; n   while (t--) { n     ans(co); n     co++; n   } n   return 0; n } n


#include <bits/stdc++.h> n int main() { n   int num, i, j, k, p; n   double prob[110], temp, tot, high, temp2; n   scanf( %d , &num); n   i = 0; n   while (i < num) { n     scanf( %lf , &prob[i]); n     i++; n   } n   i = 0; n   while (i < num) { n     p = i + 1; n     while (p < num) { n       if (prob[p] > prob[i]) { n         temp2 = prob[p]; n         prob[p] = prob[i]; n         prob[i] = temp2; n       } n       p++; n     } n     i++; n   } n   high = 0; n   i = 1; n   while (i <= num) { n     tot = 0; n     for (j = 0; j < i; j++) { n       temp = prob[j]; n       for (k = 0; k < i; k++) { n         if (j != k) temp *= 1 - prob[k]; n       } n       tot += temp; n     } n     if (tot > high) high = tot; n     i++; n   } n   printf( %.12f n , high); n } n


#include <bits/stdc++.h> n using namespace std; n long long min_val(long long a, long long b) { n   if (a <= b) n     return a; n   else n     return b; n } n long long max_val(long long a, long long b) { n   if (a >= b) n     return a; n   else n     return b; n } n long long abs(long long a, long long b) { n   long long tmp = min_val(a, b); n   if (tmp == a) { n     return b - a; n   } else n     return a - b; n } n int main() { n   int t; n   cin >> t; n   while (t--) { n     int n; n     cin >> n; n     int a[n]; n     for (int i = 0; i < n; i++) { n       cin >> a[i]; n     } n     sort(a, a + n, greater<int>()); n     for (int i = 0; i < n; i++) { n       cout << a[i] <<    ; n     } n     cout << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n string s; n int n; n int main() { n   ios_base::sync_with_stdio(false); n   cin >> n >> s; n   for (long long i = 0; i < n; i++) { n     if (s[i] ==  * ) n       for (long long t = 1; t <= n - 1; t++) { n         bool check = true; n         for (long long j = 0; j < 5; j++) n           if (i + j * t >= n || s[i + j * t] ==  . ) check = false; n         if (check == 1) { n           cout <<  yes ; n           return 0; n         } n       } n   } n   cout <<  no  << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, k, a, m, cur; n set<int> S; n int main() { n   cin >> n >> k >> a; n   cin >> m; n   S.insert(0); n   S.insert(n + 1); n   cur = (n + 1) / (a + 1); n   for (int i = 0; i < m; i++) { n     int x; n     cin >> x; n     auto prv = S.lower_bound(x); n     auto nxt = prv; n     prv--; n     cur -= (*nxt - *prv) / (a + 1); n     cur += (x - *prv) / (a + 1); n     cur += (*nxt - x) / (a + 1); n     S.insert(x); n     if (cur < k) return cout << i + 1, 0; n   } n   cout << -1; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e5 + 5; n vector<int> G[maxn], a, b; n int n, m, flag; n int col[maxn]; n bool bfs(int s) { n   queue<int> p; n   p.push(s); n   col[s] = 1; n   while (!p.empty()) { n     int from = p.front(); n     p.pop(); n     int len = G[from].size(); n     for (int i = 0; i < len; ++i) { n       int v = G[from][i]; n       if (col[v] == -1) { n         p.push(v); n         col[v] = !col[from]; n       } n       if (col[from] == col[v]) return false; n     } n   } n   return true; n } n int main() { n   scanf( %d%d , &n, &m); n   a.clear(); n   b.clear(); n   for (int i = 0; i <= n; ++i) G[i].clear(); n   for (int i = 0; i < m; ++i) { n     int u, v; n     scanf( %d%d , &u, &v); n     G[u].push_back(v); n     G[v].push_back(u); n   } n   flag = 0; n   memset(col, -1, sizeof(col)); n   for (int i = 1; i <= n; i++) n     if (col[i] == -1 && !bfs(i)) { n       flag = true; n       break; n     } n   if (flag) { n     puts( -1 ); n   } else { n     for (int i = 1; i <= n; ++i) { n       if (G[i].size() == 0) col[i] = -1; n       if (col[i] == 0) { n         a.push_back(i); n       } else if (col[i] == 1) { n         b.push_back(i); n       } n     } n     int len = a.size(); n     printf( %d n , len); n     for (int i = 0; i < len; ++i) { n       if (i) printf(   ); n       printf( %d , a[i]); n     } n     len = b.size(); n     printf(  n%d n , len); n     for (int i = 0; i < len; ++i) { n       if (i) printf(   ); n       printf( %d , b[i]); n     } n     puts(  ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a[2000010], b[1000010], n; n int solve(int s) { n   int cnt = 0, cur = s; n   bool flag = 0; n   while (1) { n     cur = b[cur]; n     cnt++; n     if (cur >= s && flag) return cnt; n     if (cur >= n) { n       cur -= n; n       flag = 1; n     } n     if (cur >= s && flag) return cnt; n   } n } n int main() { n   int q; n   scanf( %d%d , &n, &q); n   int i; n   long long sum = 0; n   for (i = 0; i < n; i++) { n     scanf( %d , &a[i]); n     sum += a[i]; n     a[n + i] = a[i]; n   } n   for (i = 0; i < q; i++) { n     long long x, cur = 0; n     int r = 0, j; n     scanf( %lld , &x); n     if (x >= sum) { n       printf( 1 n ); n       continue; n     } n     for (j = 0; j < n; j++) { n       while (cur + a[r] <= x) cur += a[r++]; n       b[j] = r; n       cur -= a[j]; n     } n     int min_ = 998244353, pos, ans = 998244353; n     for (j = 0; j < n; j++) { n       if (b[j] - j < min_) { n         min_ = b[j] - j; n         pos = j; n       } n     } n     for (j = pos; j <= b[pos]; j++) { n       ans = min(ans, solve(j % n)); n     } n     printf( %d n , ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long UNDEF = -1; n const long long INF = 1e18; n template <typename T> n inline bool chkmax(T& aa, T bb) { n   return aa < bb ? aa = bb, true : false; n } n template <typename T> n inline bool chkmin(T& aa, T bb) { n   return aa > bb ? aa = bb, true : false; n } n static char stdinBuffer[1024]; n static char* stdinDataEnd = stdinBuffer + sizeof(stdinBuffer); n static const char* stdinPos = stdinDataEnd; n void readAhead(size_t amount) { n   size_t remaining = stdinDataEnd - stdinPos; n   if (remaining < amount) { n     memmove(stdinBuffer, stdinPos, remaining); n     size_t sz = fread(stdinBuffer + remaining, 1, n                       sizeof(stdinBuffer) - remaining, stdin); n     stdinPos = stdinBuffer; n     stdinDataEnd = stdinBuffer + remaining + sz; n     if (stdinDataEnd != stdinBuffer + sizeof(stdinBuffer)) *stdinDataEnd = 0; n   } n } n int rint() { n   readAhead(16); n   int x = 0; n   bool neg = false; n   while (*stdinPos ==     || *stdinPos ==   n ) ++stdinPos; n   if (*stdinPos ==  - ) { n     ++stdinPos; n     neg = true; n   } n   while (*stdinPos >=  0  && *stdinPos <=  9 ) { n     x *= 10; n     x += *stdinPos -  0 ; n     ++stdinPos; n   } n   return neg ? -x : x; n } n char rch() { n   readAhead(16); n   while (*stdinPos ==     || *stdinPos ==   n ) ++stdinPos; n   char ans = *stdinPos; n   ++stdinPos; n   return ans; n } n long long rlong() { n   readAhead(32); n   long long x = 0; n   bool neg = false; n   while (*stdinPos ==     || *stdinPos ==   n ) ++stdinPos; n   if (*stdinPos ==  - ) { n     ++stdinPos; n     neg = true; n   } n   while (*stdinPos >=  0  && *stdinPos <=  9 ) { n     x *= 10; n     x += *stdinPos -  0 ; n     ++stdinPos; n   } n   return neg ? -x : x; n } n const int mc = 26, mn = 1e6 + 4; n char s[mn], t[mn]; n int sc[mc + 1], tc[mc + 1], wc[mc + 1]; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   scanf( %s n%s n , s, t); n   int sl = strlen(s), tl = strlen(t); n   int q = 0; n   for (int i = 0; i < sl; i++) { n     if (s[i] !=  ? ) n       sc[s[i] -  a ]++; n     else n       q++; n   } n   for (int i = 0; i < tl; i++) { n     tc[t[i] -  a ]++; n   } n   int imin = 0, imax = mn; n   while (imin < imax) { n     int imid = (imin + imax) >> 1; n     long long need = 0; n     for (int c = 0; c < 26; c++) { n       long long want = (tc[c] * (long long)imid) - sc[c]; n       if (want >= 0) need += want; n     } n     if (need <= q) n       imin = imid + 1; n     else n       imax = imid; n   } n   imin--; n   for (int c = 0; c < 26; c++) { n     wc[c] = tc[c] * imin - sc[c]; n   } n   int cidx = 0; n   for (int i = 0; i < sl; i++) { n     if (s[i] ==  ? ) { n       while (cidx < mc && wc[cidx] <= 0) cidx++; n       if (cidx < mc) { n         s[i] =  a  + cidx; n         wc[cidx]--; n       } else { n         s[i] =  a ; n       } n     } n   } n   printf( %s n , s); n } n


#include <bits/stdc++.h> n using namespace std; n int arr[100005]; n int reduce(int n) { n   while (n % 2 == 0) n /= 2; n   while (n % 3 == 0) n /= 3; n   return n; n } n int main() { n   int n; n   scanf( %d , &n); n   for (int i = 0; i < n; i++) { n     scanf( %d , &arr[i]); n   } n   int r = reduce(arr[0]); n   bool ok = true; n   for (int i = 1; i < n; i++) { n     if (reduce(arr[i]) != r) { n       ok = false; n       break; n     } n   } n   if (ok) n     printf( Yes n ); n   else n     printf( No n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = 0x3f3f3f3f; n void err() { cout <<   033[39;0m  << endl; } n template <class T, class... Ts> n void err(const T& arg, const Ts&... args) { n   cout << arg <<    ; n   err(args...); n } n const int N = 100000 + 5; n int n, h, m, k; n int H[N]; n pair<int, int> M[N]; n int main() { n   scanf( %d%d%d%d , &n, &h, &m, &k); n   m /= 2; n   for (int i = 1; i <= n; i++) { n     scanf( %d%d , &H[i], &M[i].first); n     M[i].second = i; n     M[i].first %= m; n     M[i].first++; n   } n   sort(M + 1, M + 1 + n); n   int res = 0, t = 0; n   for (int i = 1; i <= n; i++) { n     int num = 0; n     if (M[i].first < k) { n       int l = lower_bound(M + 1, M + 1 + n, make_pair(M[i].first, 0)) - M; n       int r = n           upper_bound(M + 1, M + 1 + n, make_pair(m - k + M[i].first, inf)) - n           M - 1; n       num = r - l + 1; n     } else { n       num += n           upper_bound(M + 1, M + 1 + n, make_pair(M[i].first - k, inf)) - M - 1; n       num += n           n - (lower_bound(M + 1, M + 1 + n, make_pair(M[i].first, 0)) - M) + 1; n     } n     if (res < num) { n       res = num; n       t = M[i].first; n     } n   } n   vector<int> kk; n   for (int i = 1; i <= n; i++) { n     int num = 0; n     if (M[i].first < k) { n       int l = lower_bound(M + 1, M + 1 + n, make_pair(M[i].first, 0)) - M; n       int r = n           upper_bound(M + 1, M + 1 + n, make_pair(m - k + M[i].first, inf)) - n           M - 1; n       num = r - l + 1; n       if (num == res) { n         for (int i = 1; i < l; i++) kk.push_back(M[i].second); n         for (int i = r + 1; i <= n; i++) kk.push_back(M[i].second); n         break; n       } n     } else { n       int l = n           upper_bound(M + 1, M + 1 + n, make_pair(M[i].first - k, inf)) - M - 1; n       num += l; n       int r = lower_bound(M + 1, M + 1 + n, make_pair(M[i].first, 0)) - M; n       num += n - r + 1; n       if (num == res) { n         for (int i = l + 1; i < r; i++) kk.push_back(M[i].second); n         break; n       } n     } n   } n   cout << (n - res) <<     << t - 1 << endl; n   sort(kk.begin(), kk.end()); n   for (int i = 0; i < kk.size(); i++) { n     printf( %d  , kk[i]); n   } n   puts(  ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2e5 + 7, inf = 1e8; n int read() { n   int s = 0, w = 1; n   char c; n   while (c = getchar(), c >  9  || c <  0 ) n     if (c ==  - ) w = -1; n   while (c >=  0  && c <=  9 ) s = s * 10 + c -  0 , c = getchar(); n   return s * w; n } n void write(int x) { n   if (x < 0) x = -x, putchar( - ); n   if (x >= 10) write(x / 10); n   putchar(x % 10 |  0 ); n } n void writeln(int x) { n   write(x); n   puts(  ); n } n struct edge { n   int t, nxt; n } e[N]; n struct node { n   int s, tag; n }; n int n, cnt, rt; n int head[N], siz[N], Mx[N], Cx[N], Mn[N], Mson[N], Bigs[N], ans[N], vis[N]; n void add(int u, int t) { n   e[++cnt].t = t; n   e[cnt].nxt = head[u]; n   head[u] = cnt; n } n struct tree { n   node tr[N << 1]; n   void pushdown(int ts) { n     if (!tr[ts].tag) return; n     tr[ts << 1].s = 0; n     tr[ts << 1 | 1].s = 0; n     tr[ts << 1].tag = 1; n     tr[ts << 1 | 1].tag = 1; n     tr[ts].tag = 0; n   } n   inline void add(int ts, int l, int r, int pos, int x) { n     pushdown(ts); n     tr[ts].s += x; n     if (l == r) return; n     int mid = (l + r) >> 1; n     if (pos <= mid) n       add(ts << 1, l, mid, pos, x); n     else n       add(ts << 1 | 1, mid + 1, r, pos, x); n   } n   inline void clear() { n     tr[1].s = 0; n     tr[1].tag = 1; n   } n   inline int query1(int ts, int l, int r, int L, int R) { n     if (L > R) return 0; n     if (l == L && r == R) return tr[ts].s; n     pushdown(ts); n     int mid = (l + r) >> 1; n     if (R <= mid) n       return query1(ts << 1, l, mid, L, R); n     else if (L > mid) n       return query1(ts << 1 | 1, mid + 1, r, L, R); n     else n       return query1(ts << 1, l, mid, L, mid) + n              query1(ts << 1 | 1, mid + 1, R, mid + 1, R); n   } n   inline int query2(int ts, int l, int r, int L, int R) { n     if (L > R || !tr[ts].s) return 0; n     if (l == r) return l; n     pushdown(ts); n     int mid = (l + r) >> 1; n     if (R <= mid) n       return query2(ts << 1, l, mid, L, R); n     else if (L > mid) n       return query2(ts << 1 | 1, mid + 1, r, L, R); n     else { n       int v = query2(ts << 1 | 1, mid + 1, r, mid + 1, R); n       if (v) n         return v; n       else n         return query2(ts << 1, l, mid, L, mid); n     } n   } n   inline int query3(int ts, int l, int r, int L, int R) { n     if (L > R || !tr[ts].s) return inf; n     if (l == r) return l; n     pushdown(ts); n     int mid = (l + r) >> 1; n     if (R <= mid) n       return query3(ts << 1, l, mid, L, R); n     else if (L > mid) n       return query3(ts << 1 | 1, mid + 1, r, L, R); n     else { n       int v = query3(ts << 1, l, mid, L, mid); n       if (v != inf) n         return v; n       else n         return query3(ts << 1 | 1, mid + 1, r, mid + 1, R); n     } n   } n } T1, T2, T3; n void chu(int &mx, int &cx, int &mn, int v, int &id, int t) { n   if (v > mx) n     cx = mx, mx = v, id = t; n   else if (v > cx) n     cx = v; n   if (v) mn = min(mn, v); n } n void dfs1(int u) { n   siz[u] = 1; n   Mson[u] = -1; n   for (int i = head[u]; i; i = e[i].nxt) { n     int t = e[i].t; n     dfs1(t); n     siz[u] += siz[t]; n     chu(Mx[u], Cx[u], Mn[u], siz[t], Mson[u], t); n   } n   Bigs[u] = Mson[u]; n   chu(Mx[u], Cx[u], Mn[u], n - siz[u], Mson[u], 0); n   T1.add(1, 1, n, siz[u], 1); n } n void Add(int u) { n   T3.add(1, 1, n, siz[u], 1); n   for (int i = head[u]; i; i = e[i].nxt) { n     int t = e[i].t; n     if (vis[t]) continue; n     Add(t); n   } n } n int query2(int ts, int l, int r, int L, int R) { n   if (L > R || T1.tr[ts].s - T3.tr[ts].s <= 0) return 0; n   if (l == r) return l; n   T3.pushdown(ts); n   int mid = (l + r) >> 1; n   if (R <= mid) n     return query2(ts << 1, l, mid, L, R); n   else if (L > mid) n     return query2(ts << 1 | 1, mid + 1, r, L, R); n   else { n     int v = query2(ts << 1 | 1, mid + 1, r, mid + 1, R); n     if (v) n       return v; n     else n       return query2(ts << 1, l, mid, L, mid); n   } n } n int query3(int ts, int l, int r, int L, int R) { n   if (L > R || T1.tr[ts].s - T3.tr[ts].s <= 0) return inf; n   if (l == r) return l; n   T3.pushdown(ts); n   int mid = (l + r) >> 1; n   if (R <= mid) n     return query3(ts << 1, l, mid, L, R); n   else if (L > mid) n     return query3(ts << 1 | 1, mid + 1, r, L, R); n   else { n     int v = query3(ts << 1, l, mid, L, mid); n     if (v != inf) n       return v; n     else n       return query3(ts << 1 | 1, mid + 1, r, mid + 1, R); n   } n } n void dfs2(int u) { n   T1.add(1, 1, n, siz[u], -1); n   T2.add(1, 1, n, siz[u], 1); n   for (int i = head[u]; i; i = e[i].nxt) { n     int t = e[i].t; n     if (t == Bigs[u]) continue; n     dfs2(t); n     T3.clear(); n   } n   if (Bigs[u] != -1) dfs2(Bigs[u]), vis[Bigs[u]] = 1; n   int v = 0; n   if (Mson[u] == Bigs[u]) { n     v = T3.query2(1, 1, n, 1, (Mx[u] - Mn[u]) / 2); n     ans[u] = max(max(Mx[u] - v, Mn[u] + v), Cx[u]); n     v = T3.query3(1, 1, n, (Mx[u] - Mn[u]) / 2, n); n     ans[u] = min(ans[u], max(max(Mx[u] - v, Mn[u] + v), Cx[u])); n   } n   Add(u); n   if (Bigs[u] != -1) vis[Bigs[u]] = 0; n   T1.add(1, 1, n, siz[u], 1); n   T2.add(1, 1, n, siz[u], -1); n   if (Mson[u] != Bigs[u]) { n     v = max( n         query2(1, 1, n, 1, (Mx[u] - Mn[u]) / 2), n         T2.query2(1, 1, n, 1 + siz[u], min((Mx[u] - Mn[u]) / 2 + siz[u], n)) - n             siz[u]); n     ans[u] = max(max(Mx[u] - v, Mn[u] + v), Cx[u]); n     v = min(query3(1, 1, n, (Mx[u] - Mn[u]) / 2, n), n             T2.query3(1, 1, n, (Mx[u] - Mn[u]) / 2 + siz[u], n) - siz[u]); n     ans[u] = min(ans[u], max(max(Mx[u] - v, Mn[u] + v), Cx[u])); n   } n } n int main() { n   n = read(); n   if (n == 1) return puts( 0 ), 0; n   memset(Mn, 60, sizeof Mn); n   for (int i = 1, u, v; i <= n; i++) { n     u = read(), v = read(); n     if (u == 0) n       rt = v; n     else n       add(u, v); n   } n   dfs1(rt); n   dfs2(rt); n   for (int i = 1; i <= n; i++) writeln(ans[i]); n } n


#include <bits/stdc++.h> n using namespace std; n signed main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   long long n; n   cin >> n; n   if (n % 2) { n     cout <<  black ; n   } else { n     cout <<  white  << endl; n     cout <<  1 2 ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n string s; n long long int n, m, c, ans = 0; n string x; n void count() { n   int v = 0; n   for (long long int i = 0; i < n; i++) { n     if (s[i] ==  . ) { n       v++; n     } else { n       if (v > 0) { n         ans += (v - 1); n         v = 0; n       } n     } n   } n   if (s[n - 1] ==  . ) ans += v - 1; n } n int main() { n   cin >> n >> m; n   cin >> s; n   count(); n   for (long long int i = 1; i <= m; i++) { n     cin >> c >> x; n     if ((s[c - 1] ==  .  && x[0] ==  . ) || (s[c - 1] !=  .  && x[0] !=  . )) { n     } else if (s[c - 1] !=  .  && x[0] ==  . ) { n       if (s[c - 2] ==  .  && s[c] ==  . ) { n         ans += 2; n       } else if (s[c] ==  .  || s[c - 2] ==  . ) { n         ans += 1; n       } n     } else if (s[c - 1] ==  .  && x[0] !=  . ) { n       if (s[c - 2] ==  .  && s[c] ==  . ) { n         ans -= 2; n       } else if (s[c] ==  .  || s[c - 2] ==  . ) { n         ans -= 1; n       } n     } n     cout << ans << endl; n     s[c - 1] = x[0]; n   } n } n


#include <bits/stdc++.h> n int s, i, e; n int main() { n   int t; n   scanf( %d , &t); n   while (t--) { n     int ans = 0; n     scanf( %d%d%d , &s, &i, &e); n     if (s > i + e) { n       printf( %d n , e + 1); n     } else if (s + e <= i) { n       printf( %d n , 0); n     } else { n       int k = e - (i + e - s) / 2; n       printf( %d n , k); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double pi = acos(-1.0); n const double eps = 1e-11; n template <class T> n inline void ckmin(T &a, T b) { n   if (b < a) a = b; n } n template <class T> n inline void ckmax(T &a, T b) { n   if (b > a) a = b; n } n template <class T> n inline T sqr(T x) { n   return x * x; n } n using VI = vector<int>; n int main() { n   std::ios::sync_with_stdio(false); n   int n, k; n   while (cin >> n >> k) { n     vector<int> a(n, -1); n     vector<int> b(n, -1); n     for (int i = 0; i < (k); ++i) { n       int p; n       cin >> p; n       --p; n       if (a[p] < 0) a[p] = i; n       b[p] = i; n     } n     int ret = 0; n     for (int x = 0; x < (n); ++x) n       for (int d = -1; d <= 1; d++) { n         int y = x + d; n         if (y < 0 || y >= n) continue; n         if (a[x] < 0) n           ++ret; n         else if (b[y] < a[x]) n           ++ret; n       } n     printf( %d n , ret); n     break; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1000000 + 20; n int xor_n[maxn]; n int p[maxn]; n int n; n int q; n void init() { n   xor_n[0] = 0; n   for (int i = 1; i < maxn; i++) { n     xor_n[i] = i ^ xor_n[i - 1]; n   } n } n int main() { n   init(); n   while (~scanf( %d , &n)) { n     q = 0; n     for (int i = 1; i <= n; i++) { n       scanf( %d , &p[i]); n       q = q ^ p[i]; n     } n     for (int i = 1; i <= n; i++) { n       int tmp = n / i; n       if (n % i == 0) { n         if (tmp & 1) q = q ^ xor_n[i - 1]; n       } else { n         if (tmp & 1) n           q = q ^ xor_n[i - 1] ^ xor_n[n % i]; n         else n           q = q ^ xor_n[n % i]; n       } n     } n     printf( %d n , q); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int i, j, k, n, x, y, a, ans = 0; n   cin >> n; n   int arr[n]; n   for (i = 0; i < n; i++) { n     cin >> arr[i]; n     if (arr[i] > ans) ans = arr[i]; n   } n   for (i = 2; i <= n; i++) { n     for (j = 0; j < n - i + 1; j++) { n       int a = arr[j]; n       for (k = 1; k < i; k++) { n         a = a ^ arr[j + k]; n       } n       if (a > ans) ans = a; n     } n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void solve() { n   string s; n   cin >> s; n   int p = s.find( . ); n   if (s[p - 1] ==  9 ) { n     cout <<  GOTO Vasilisa.  <<   n ; n   } else if (s[p + 1] <  5 ) { n     cout << s.substr(0, p) <<   n ; n   } else { n     string z = s.substr(0, p); n     z[p - 1]++; n     cout << z <<   n ; n   } n } n void t(int t) { n   if (!t) { n     cin >> t; n   } n   while (t--) { n     solve(); n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   t(1); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int dp[1000007]; n int main() { n   int n; n   scanf( %d , &n); n   dp[1] = dp[2] = 1; n   for (int i = 3; i <= n; i++) { n     int im = (i - 1) / 2; n     if (2 * im == (i - 1) && im % 2 == 0) n       dp[i] = dp[im]; n     else if ((2 * im + 1) == (i - 1)) n       dp[i] = dp[im] && dp[im + 1]; n   } n   printf( %d n , dp[n]); n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 5500; n const int INF = 1E9; n int a[MAXN], b[MAXN], c[MAXN], d[MAXN]; n int f[MAXN][MAXN]; n vector<int> g[MAXN]; n inline bool cmp(int a, int b) { return c[a] > c[b]; } n int main() { n   int n, m, k, s; n   scanf( %d%d%d , &n, &m, &k); n   s = k; n   for (int i = 1; i <= n; i++) { n     scanf( %d%d%d , &a[i], &b[i], &c[i]); n     s += b[i]; n     d[i] = i; n   } n   for (int i = 1; i <= m; i++) { n     int u, v; n     scanf( %d%d , &u, &v); n     d[v] = max(d[v], u); n   } n   for (int i = 1; i <= n; i++) g[d[i]].push_back(i); n   for (int i = 1; i <= n; i++) sort(g[i].begin(), g[i].end(), cmp); n   for (int i = 0; i <= n; i++) n     for (int j = 0; j <= s; j++) f[i][j] = -INF; n   for (int i = n; i >= 0; i--) n     for (int j = 0; j <= s - b[i]; j++) { n       if (j + b[i] >= a[i + 1]) f[i][j] = max(f[i][j], f[i + 1][j + b[i]]); n       for (int l = 0, t = 0; l < g[i].size() && j + b[i] - (l + 1) >= a[i + 1]; n            l++) { n         t += c[g[i][l]]; n         f[i][j] = max(f[i][j], f[i + 1][j + b[i] - (l + 1)] + t); n       } n     } n   printf( %d n , f[0][k] < 0 ? -1 : f[0][k]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<long long> a; n int main() { n   int n; n   cin >> n; n   for (long long x, y, z, i = 1; i <= n; i++) { n     cin >> x >> y >> z; n     long long l = 0; n     if (x % 2 == 1) { n       l = y; n       x--; n       long long h = min(x * y, x / 2 * z); n       l = l + h; n     } else { n       l = min(x / 2 * z, x * y); n     } n     a.push_back(l); n   } n   for (long long i = 0; i < a.size(); i++) { n     cout << a[i] << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void solve() { n   long long n; n   cin >> n; n   if (n % 2) n     cout << setprecision(0) << fixed <<  -  << ceil((1.0 * n) / 2) <<   n ; n   else n     cout << fixed << n / 2 <<   n ; n } n int main() { solve(); } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, a, b; n   cin >> n >> a >> b; n   int cnt = 0; n   for (int i = 1; i < n + 1; i++) { n     if (i <= b + 1 && (n - i) >= a) cnt++; n   } n   cout << cnt << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long double eps = 1e-9; n const long double pi = acos(-1.0); n int gcd(int a, int b) { return (b == 0) ? a : gcd(b, a % b); } n int xabs(int a) { return a > 0 ? a : -a; } n struct spoint { n   double x; n   double y; n   int id; n   spoint(); n   spoint(double x, double y) : x(x), y(y){}; n }; n struct svector { n   double x; n   double y; n   svector(); n   svector(double x, double y) : x(x), y(y) {} n   svector(spoint a, spoint b) { n     x = b.x - a.x; n     y = b.y - a.y; n   } n   double len() const { return sqrt((x * x) + (y * y)); } n   friend svector operator+(const svector a, const svector b) { n     return svector(a.x + b.x, a.y + b.y); n   } n   friend bool operator==(const svector a, const svector b) { n     return (a.x == b.x && a.y == b.y); n   } n   friend double operator*(const svector a, const svector b) { n     return a.x * b.x + a.y * b.y; n   } n }; n int main() { n   vector<spoint> mas; n   for (int i = 0; i < 8; i++) { n     double a, b; n     cin >> a >> b; n     mas.push_back(spoint(a, b)); n   } n   for (int i = 0; i < 5; i++) { n     for (int k = i + 1; k < 6; k++) { n       for (int j = k + 1; j < 7; j++) { n         for (int z = j + 1; z < 8; z++) { n           svector a1(mas[i], mas[k]); n           svector b1(mas[i], mas[j]); n           svector c1(mas[i], mas[z]); n           if ((a1 + b1 == c1 && fabs(a1.len() - b1.len()) < eps && n                a1 * b1 == 0) || n               (a1 + c1 == b1 && fabs(a1.len() - c1.len()) < eps && n                a1 * c1 == 0) || n               (b1 + c1 == a1 && fabs(c1.len() - b1.len()) < eps && n                b1 * c1 == 0)) { n             vector<spoint> mm; n             vector<int> qw; n             for (int q = 0; q < 8; q++) { n               if (q != i && q != k && q != j && q != z) { n                 mm.push_back(mas[q]); n                 qw.push_back(q); n               } n             } n             svector a2(mm[0], mm[1]); n             svector b2(mm[0], mm[2]); n             svector c2(mm[0], mm[3]); n             if ((a2 + b2 == c2 && a2 * b2 == 0) || n                 (a2 + c2 == b2 && a2 * c2 == 0) || n                 (b2 + c2 == a2 && b2 * c2 == 0)) { n               cout <<  YES  << endl; n               cout << i + 1 <<     << k + 1 <<     << j + 1 <<     << z + 1 n                    << endl; n               cout << qw[0] + 1 <<     << qw[1] + 1 <<     << qw[2] + 1 <<     n                    << qw[3] + 1 << endl; n               return 0; n             } n           } n         } n       } n     } n   } n   cout <<  NO ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   int n, m, k; n   cin >> n >> m >> k; n   int mn = INT_MAX; n   for (int i = 1; i <= n; i++) { n     int x; n     cin >> x; n     if (i != m && x != 0 && x <= k) { n       mn = min(mn, abs(i - m)); n     } n   } n   cout << mn * 10; n } n


#include <bits/stdc++.h> n using namespace std; n const long long inf = 1e9 + 7; n const long long INF = 1LL << 60; n const long long mod = 1e9 + 7; n const long double eps = 1e-8; n const long double pi = acos(-1.0); n template <class T> n inline bool chmax(T& a, T b) { n   if (a < b) { n     a = b; n     return 1; n   } n   return 0; n } n template <class T> n inline bool chmin(T& a, T b) { n   if (a > b) { n     a = b; n     return 1; n   } n   return 0; n } n struct P { n   long long x, y; n }; n long double ex(P s, P t, P r) { n   long double x1 = (long double)t.x - (long double)s.x; n   long double y1 = (long double)t.y - (long double)s.y; n   long double x2 = (long double)r.x - (long double)s.x; n   long double y2 = (long double)r.y - (long double)s.y; n   return x1 * y2 - x2 * y1; n } n bool cross(P a, P b, P s, P t) { n   if (ex(a, b, s) * ex(a, b, t) > 0) return false; n   if (ex(b, a, s) * ex(b, a, t) > 0) return false; n   if (ex(t, s, a) * ex(t, s, b) > 0) return false; n   return ex(s, t, a) * ex(s, t, b) < eps; n } n pair<bool, pair<long double, long double>> intersection_ls(P a1, P a2, P b1, n                                                            P b2) { n   long double d1 = abs(ex(b1, a1, b2)); n   long double d2 = abs(ex(b1, a2, b2)); n   if (!cross(a1, a2, b1, b2)) { n     return {false, {0.0, 0.0}}; n   } n   return {true, n           {a1.x + (a2.x - a1.x) * d1 / (d1 + d2), n            a1.y + (a2.y - a1.y) * d1 / (d1 + d2)}}; n } n long long gcd(long long x, long long y) { n   if (y == 0) return x; n   return gcd(y, x % y); n } n void solve() { n   long long n; n   cin >> n; n   vector<pair<P, P>> vec; n   long long ans = 0; n   for (long long i = 0; i < n; i++) { n     long long ax, ay, bx, by; n     cin >> ax >> ay >> bx >> by; n     vec.push_back({P{ax, ay}, P{bx, by}}); n     ans += gcd(abs(ax - bx), abs(ay - by)) + 1; n   } n   map<pair<long long, long long>, long long> mp; n   for (long long i = 0; i < n; i++) { n     for (long long j = i + 1; j < n; ++j) { n       auto res = intersection_ls(vec[i].first, vec[i].second, vec[j].first, n                                  vec[j].second); n       if (!res.first) continue; n       long double X = res.second.first, Y = res.second.second; n       if (floor(X + eps) < X + 2 * eps && floor(X + eps) > X - 2 * eps) { n         if (floor(Y + eps) < Y + 2 * eps && floor(Y + eps) > Y - 2 * eps) { n           mp[{floor(X + eps), floor(Y + eps)}]++; n         } n       } n     } n   } n   for (auto p : mp) { n     long long k = 2; n     while (k * (k - 1) / 2 <= p.second) { n       if (k * (k - 1) / 2 == p.second) { n         ans -= (k - 1); n         break; n       } n       ++k; n     } n   } n   cout << ans << endl; n } n signed main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, a[20], st, tp, i; n int main() { n   cin >> n; n   for (i = 0; i < n; i++) cin >> a[i]; n   for (st = 0; st < (1 << n); st++) { n     tp = 0; n     for (i = 0; i < n; i++) { n       if (st & (1 << i)) { n         tp += a[i]; n         tp %= 360; n       } else { n         tp -= a[i]; n         tp += 360; n         tp %= 360; n       } n     } n     if (tp == 0) { n       cout <<  yes ; n       return 0; n     } n   } n   cout <<  no ; n } n


#include <bits/stdc++.h> n using namespace std; n long long ans = 0; n long long rootans = 0; n vector<long long> dp1(200001, 1); n vector<long long> dp2(200001, 1); n vector<int> adj[200001]; n void dfs(int u, int p) { n   for (int i : adj[u]) { n     if (i != p) { n       dfs(i, u); n       dp1[u] += dp1[i]; n     } n   } n } n void dfs2(int u, int p) { n   rootans += dp1[u]; n   for (int i : adj[u]) { n     if (i != p) { n       dfs2(i, u); n     } n   } n } n void dfs3(int u, int p) { n   for (int i : adj[u]) { n     if (i != p) { n       dp2[i] = dp2[u] - dp1[i] + dp1[1] - dp1[i]; n       ans = max(ans, dp2[i]); n       dfs3(i, u); n     } n   } n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   int n; n   cin >> n; n   int a, b; n   for (int i = 1; i < n; i++) { n     cin >> a >> b; n     adj[a].push_back(b); n     adj[b].push_back(a); n   } n   dfs(1, 0); n   dfs2(1, 0); n   dp2[1] = rootans; n   dfs3(1, 0); n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long n; n   cin >> n; n   if (n % 2 == 0) { n     cout << n / 2 << endl; n   } else { n     cout << ((n / 2) - n) << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n static const int maxn = 100012; n int K1, K2, K3; n int T1, T2, T3; n int N; n int C[maxn]; n void Read() { n   int i; n   scanf( %d%d%d , &K1, &K2, &K3); n   scanf( %d%d%d , &T1, &T2, &T3); n   scanf( %d , &N); n   for (i = 0; i < N; ++i) { n     scanf( %d , &C[i]); n   } n } n inline bool Greater(long long x, long long y) { return x > y; } n long long Result; n long long X[maxn]; n long long Y[maxn]; n long long Z[maxn]; n void Work() { n   int i; n   Result = 0; n   memset(X, 0, sizeof(X)); n   memset(Y, 0, sizeof(Y)); n   memset(Z, 0, sizeof(Z)); n   if (K1 > N) K1 = N; n   if (K2 > N) K2 = N; n   if (K3 > N) K3 = N; n   make_heap(X, X + K1, Greater); n   make_heap(Y, Y + K2, Greater); n   make_heap(Z, Z + K3, Greater); n   for (i = 0; i < N; ++i) { n     long long t = C[i]; n     pop_heap(X, X + K1, Greater); n     if (t < X[K1 - 1]) t = X[K1 - 1]; n     t += T1; n     X[K1 - 1] = t; n     push_heap(X, X + K1, Greater); n     pop_heap(Y, Y + K2, Greater); n     if (t < Y[K2 - 1]) t = Y[K2 - 1]; n     t += T2; n     Y[K2 - 1] = t; n     push_heap(Y, Y + K2, Greater); n     pop_heap(Z, Z + K3, Greater); n     if (t < Z[K3 - 1]) t = Z[K3 - 1]; n     t += T3; n     Z[K3 - 1] = t; n     push_heap(Z, Z + K3, Greater); n     if (Result < t - C[i]) Result = t - C[i]; n   } n } n void Write() { printf( %I64d n , Result); } n int main() { n   Read(); n   Work(); n   Write(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char s[100005]; n long long int V[256]; n map<pair<int, long long int>, int> M; n int main() { n   int i, n; n   long long int prefixSum = 0, ans = 0; n   for (i = 0; i < 26; i++) scanf( %lld , &V[ a  + i]); n   scanf( %s , s); n   n = strlen(s); n   for (i = 0; i < n; i++) { n     ans += M[make_pair(s[i], prefixSum)]; n     prefixSum += V[(int)s[i]]; n     M[make_pair(s[i], prefixSum)]++; n   } n   printf( %lld n , ans); n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /STACK:16777216 ) n using namespace std; n int n, k; n char g[3][100005]; n bool f; n bool isval(int i, int j) { n   if (j >= n) return true; n   if (j < 0) return false; n   if (g[i][j] ==  X ) return false; n   return true; n } n void dfs(int i, int j, int t) { n   if (j >= n) n     f = true; n   else { n     g[i][j] =  X ; n     if (j + k > t && isval((i + 1) % 2, j + k)) n       dfs((i + 1) % 2, (j + k), t + 1); n     if (j + 1 > t && isval(i, j + 1)) dfs(i, j + 1, t + 1); n     if (j - 1 > t && isval(i, j - 1)) dfs(i, (j - 1), t + 1); n   } n } n int main() { n   cin >> n >> k; n   for (int i = 0; i < 2; i++) cin >> g[i]; n   f = 0; n   dfs(0, 0, 0); n   if (!f) n     cout <<  NO  << endl; n   else n     cout <<  YES  << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n,i,j,k,a[5050],x[5050],y[5050]; n long long scp(int i, int j, int k) { n   long long xa=x[i]-x[j]; n   long long ya=y[i]-y[j]; n   long long xb=x[k]-x[j]; n   long long yb=y[k]-y[j]; n   return xa*xb+ya*yb; n } n int main() { n   scanf( %d ,&n); n   for (i=0; i<n; i++) scanf( %d%d ,&x[i],&y[i]); n   a[0]=0; n   a[1]=1; n   for (i=2; i<n; i++) { n     for (j=i; j>=0; --j) { n       if (j>=2 && scp(a[j-2],a[j-1],i)<=0) continue; n       if (j>=1 && j<i && scp(a[j-1],i,a[j])<=0) continue; n       if (j+1<i && scp(i,a[j],a[j+1])<=0) continue; n       for (k=i; k>j; --k) a[k]=a[k-1]; n       a[j]=i; n       break; n     } n     if (j<0) { puts( -1 ); return 0; } n   } n   for (i=0; i<n; i++) printf( %d  ,a[i]+1); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, ans[16]; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   cin >> n; n   if (!(n & 1)) { n     cout << 0 <<   n ; n     return 0; n   } n   ans[1] = 1; n   ans[3] = 18; n   ans[5] = 1800; n   ans[7] = 670320; n   ans[9] = 734832000; n   ans[11] = 890786230; n   ans[13] = 695720788; n   ans[15] = 150347555; n   cout << ans[n] <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = 0x3f3f3f3f; n const long long infL = LLONG_MAX; n struct psychotronic_induction { n   int electromagnetic_wave = 7; n }; n const int nmax = 1e5 + 10; n int n, m, a[nmax]; n ; n int s[nmax], used[nmax]; n vector<int> g[nmax]; n pair<int, int> edge[nmax]; n int second_node(int idx, int node) { n   return (edge[idx].first == node) ? edge[idx].second : edge[idx].first; n } n bool dfs(int node, int curr = 0) { n   s[node] ^= curr; n   used[node] = 1; n   for (auto &it : g[node]) { n     if (used[second_node(it, node)]) { n       if (s[second_node(it, node)] != 1 ^ a[it] ^ s[node]) return 0; n       continue; n     } n     s[second_node(it, node)] = 1 ^ a[it] ^ s[node]; n     if (!dfs(second_node(it, node))) return 0; n   } n   return 1; n } n void mark(int node, int s) { n   used[node] = s; n   for (auto &it : g[node]) { n     if (used[second_node(it, node)] == s) continue; n     mark(second_node(it, node), s); n   } n } n int main() { n   scanf( %d %d , &n, &m); n   for (int i = 1; i <= n; ++i) scanf( %d , &a[i]); n   for (int i = 1; i <= m; ++i) { n     int nr; n     scanf( %d , &nr); n     for (int j = 1; j <= nr; ++j) { n       int x; n       scanf( %d , &x); n       if (!edge[x].first) n         edge[x].first = i; n       else n         edge[x].second = i; n     } n   } n   swap(n, m); n   for (int i = 1; i <= m; ++i) n     g[edge[i].first].push_back(i), g[edge[i].second].push_back(i); n   for (int i = 1; i <= n; ++i) { n     if (used[i]) continue; n     if (!dfs(i, 0)) { n       mark(i, 0); n       if (!dfs(i, 1)) { n         printf( NO n ); n         return 0; n       } n     } n     mark(i, 1); n   } n   printf( YES n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int Nmax = 1e5 + 5; n string s, t; n int n, m, pos, l, r; n int pre[Nmax]; n int suf[Nmax]; n int main() { n   cin >> s; n   cin >> t; n   n = s.size(); n   m = t.size(); n   s =     + s; n   t =     + t; n   pos = 1; n   for (int i = 1; i <= m; i++) { n     while (pos <= n && s[pos] != t[i]) pos++; n     if (pos > n) break; n     pre[pos++] = i; n   } n   for (int i = 1; i <= n; i++) { n     if (pre[i] == 0) pre[i] = pre[i - 1]; n   } n   pos = n; n   for (int i = m; i >= 1; i--) { n     while (pos > 0 && s[pos] != t[i]) pos--; n     if (pos == 0) break; n     suf[pos--] = m - i + 1; n   } n   for (int i = n; i >= 1; i--) { n     if (suf[i] == 0) suf[i] = suf[i + 1]; n   } n   for (int i = 0; i <= n; i++) { n     if (pre[i] + suf[i + 1] > l + r) { n       l = pre[i]; n       r = suf[i + 1]; n     } n   } n   if (l + r == 0) n     cout <<  - ; n   else { n     if (l + r > m) { n       for (int i = 1; i <= m; i++) cout << t[i]; n       return 0; n     } n     for (int i = 1; i <= l; i++) cout << t[i]; n     for (int i = m - r + 1; i <= m; i++) cout << t[i]; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(0); n   int depth; n   cin >> depth; n   int n = (1 << (depth + 1)) - 1; n   vector<int> pre(n + 1, 0), add(n + 1, 0); n   for (int i = 2; i <= n; ++i) { n     cin >> pre[i]; n   } n   vector<int> way(n + 1, 0); n   for (int i = 2; i <= n; ++i) { n     way[i] = way[i / 2] + pre[i]; n   } n   int target = *max_element((way).begin(), (way).end()); n   for (int i = n / 2 + 1; i <= n; ++i) { n     add[i] = target - way[i]; n   } n   for (int i = n / 2; i >= 2; --i) { n     add[i] = min(add[2 * i], add[2 * i + 1]); n     add[2 * i] -= add[i]; n     add[2 * i + 1] -= add[i]; n   } n   cout << accumulate((add).begin(), (add).end(), 0) <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n bool ispos(long long x, long long y, long long n, long long m) { n   if (x < 0 or x >= n or y < 0 or y >= m) n     return false; n   else n     return true; n } n signed solve() { n   long long n, m; n   cin >> n >> m; n   string s[n]; n   for (long long i = 0; i < n; i++) cin >> s[i]; n   char a[n][m]; n   vector<pair<pair<long long, long long>, long long>> v; n   for (long long i = 0; i < n; i++) { n     for (long long j = 0; j < m; j++) a[i][j] =  . ; n   } n   for (long long i = 0; i < n; i++) { n     for (long long j = 0; j < m; j++) { n       long long sz = 0; n       if (s[i][j] ==  * ) { n         for (long long k = 1; k <= max(n, m); k++) { n           if (ispos(i - k, j, n, m) and s[i - k][j] ==  *  and n               ispos(i, j - k, n, m) and s[i][j - k] ==  *  and n               ispos(i + k, j, n, m) and s[i + k][j] ==  *  and n               ispos(i, j + k, n, m) and s[i][j + k] ==  * ) { n             sz++; n           } else n             break; n         } n       } n       if (sz > 0) { n         a[i][j] =  * ; n         v.push_back({{i + 1, j + 1}, sz}); n         for (long long k = 1; k <= sz; k++) { n           a[i - k][j] =  * ; n           a[i + k][j] =  * ; n           a[i][j - k] =  * ; n           a[i][j + k] =  * ; n         } n       } n     } n   } n   for (long long i = 0; i < n; i++) { n     for (long long j = 0; j < m; j++) { n       if (s[i][j] != a[i][j]) { n         cout <<  -1  n              <<   n ; n         return 0; n       } n     } n   } n   cout << v.size() <<   n ; n   for (long long i = 0; i < v.size(); i++) { n     cout << v[i].first.first <<     << v[i].first.second <<     << v[i].second n          <<   n ; n   } n } n signed main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   long long tests = 1; n   while (tests--) { n     solve(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX = 100005; n const int N = 200005; n int from[N], to[N]; n stack<pair<int, int> > G[MAX]; n stack<int> res; n bool visited[2 * N]; n void dfs(int src, int ind = -1) { n   if (ind != -1) { n     visited[ind] = true; n   } n   while (!G[src].empty()) { n     int v = G[src].top().first, e = G[src].top().second; n     G[src].pop(); n     if (!visited[e]) { n       dfs(v, e); n     } n   } n   res.push(src); n } n int main() { n   int n, m; n   scanf( %d %d , &n, &m); n   for (int i = 0; i < m; i++) { n     scanf( %d %d , &from[i], &to[i]); n     from[i]--; n     to[i]--; n     G[from[i]].push(make_pair(to[i], i)); n     G[to[i]].push(make_pair(from[i], i)); n   } n   int pre = -1, cnt = 0; n   for (int i = 0; i < n; i++) { n     if (G[i].size() % 2) { n       if (pre == -1) { n         pre = i; n       } else { n         G[pre].push(make_pair(i, cnt + m)); n         G[i].push(make_pair(pre, cnt++ + m)); n         pre = -1; n       } n     } n   } n   if ((cnt + m) % 2) { n     G[0].push(make_pair(0, cnt + m)); n   } n   dfs(0); n   pre = res.top(); n   res.pop(); n   printf( %d n , res.size()); n   while (!res.empty()) { n     if (res.size() % 2) { n       printf( %d %d n , 1 + pre, 1 + res.top()); n     } else { n       printf( %d %d n , 1 + res.top(), 1 + pre); n     } n     pre = res.top(); n     res.pop(); n   } n   return 0; n } n


#include <bits/stdc++.h> n const long long mod = 1000000007; n long long qpow(long long v, long long st) { n   long long r = 1; n   while (st) { n     if (st & 1) { n       r *= v; n       r %= mod; n     } n     v = v * v; n     v %= mod; n     st = st / 2; n   } n   return r; n } n long long f[1024]; n long long dp[1024][1024]; n long long sdp[1024][1024]; n long long getDP(int, int); n long long getSdp(int b1, int b2) { n   if (sdp[b1][b2] != -1) return sdp[b1][b2]; n   if (b2 == 0) return getDP(b1 - 2, 0); n   sdp[b1][b2] = getSdp(b1, b2 - 1) + getDP(b1 - 2, b2) * qpow(f[b2], mod - 2); n   sdp[b1][b2] %= mod; n   return sdp[b1][b2]; n } n long long getDP(int b1, int b2) { n   if (dp[b1][b2] != -1) return dp[b1][b2]; n   if (!b1) return f[b2]; n   long long sol = 0; n   if (b1 >= 2) { n     long long p = getSdp(b1, b2); n     p *= f[b2]; n     p %= mod; n     p *= (b1 - 1); n     p %= mod; n     sol += p; n     sol %= mod; n   } n   if (b2 > 0) { n     sol += getDP(b1, b2 - 1) * b2; n     sol %= mod; n   } n   sol += getDP(b1 - 1, b2); n   if (sol >= mod) sol %= mod; n   dp[b1][b2] = sol; n   return dp[b1][b2]; n } n int main() { n   int i, j, k; n   f[0] = 1; n   for (i = 1; i <= 1000; i++) { n     f[i] = f[i - 1] * i; n     f[i] %= mod; n   } n   j = k = 0; n   int n, l; n   scanf( %d , &n); n   for (i = 0; i < n; i++) { n     scanf( %d , &l); n     if (l == 1) n       j++; n     else n       k++; n   } n   memset(dp, -1, sizeof(dp)); n   memset(sdp, -1, sizeof(sdp)); n   printf( %d n , (int)getDP(j, k)); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int frombase(int x, int base) { n   int i = 0; n   int ans = 0; n   while (x) { n     ans += ((x % base) * pow((double)10, i)); n     i++; n     x /= base; n   } n   return ans; n } n int tobase(int x, int base) { n   int i = 0; n   int ans = 0; n   while (x) { n     ans += ((x % 10) * pow((double)base, i)); n     i++; n     x /= 10; n   } n   return ans; n } n int main() { n   int a, b; n   cin >> a >> b; n   int maxi = 0; n   int x = a; n   while (x) { n     maxi = max(x % 10, maxi); n     x /= 10; n   } n   x = b; n   while (x) { n     maxi = max(x % 10, maxi); n     x /= 10; n   } n   maxi++; n   int sum = tobase(a, maxi) + tobase(b, maxi); n   sum = frombase(sum, maxi); n   x = 0; n   while (sum) { n     sum /= 10; n     x++; n   } n   cout << x << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, k, sum = 0; n   cin >> n >> k; n   int a[n]; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n   } n   for (int j = 0; j < k; j++) { n     int c1 = 0, c2 = 0; n     for (int i = j; i < n; i += k) { n       if (a[i] == 1) n         c1++; n       else n         c2++; n     } n     (c1 > c2) ? (sum += c2) : (sum += c1); n   } n   cout << sum << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s; n   cin >> s; n   if ((int)s.size() < 26) { n     cout << -1; n     return 0; n   } n   char cur =  a ; n   bool fg = 0; n   for (int i = 0; i < (int)s.size(); i++) { n     if (s[i] <= cur) { n       if (cur ==  z ) { n         s[i] = cur; n         fg = 1; n         break; n       } else n         s[i] = cur; n       cur++; n     } n   } n   if (cur ==  z  && fg) n     cout << s; n   else n     cout << -1; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 5500; n char s[N]; n int ans[N], dp[N][N]; n int main() { n   scanf( %s , s + 1); n   int n = strlen(s + 1); n   for (int i = 1; i <= n; i++) { n     dp[i][i] = 1; n     ans[1]++; n     if (i < n && s[i] == s[i + 1]) { n       dp[i][i + 1] = 2; n       ans[1]++; n       ans[2]++; n     } n   } n   for (int k = 3; k <= n; k++) { n     for (int i = 1; i + k - 1 <= n; i++) { n       if (dp[i + 1][i + k - 2] && s[i] == s[i + k - 1]) { n         dp[i][i + k - 1] = dp[i][i + k / 2 - 1] + 1; n         for (int j = 1; j <= dp[i][i + k - 1]; j++) ans[j]++; n       } n     } n   } n   for (int i = 1; i <= n; i++) printf( %d  , ans[i]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n T nextInt() { n   T x = 0, p = 1; n   char ch; n   do { n     ch = getchar(); n   } while (ch <=    ); n   if (ch ==  - ) { n     p = -1; n     ch = getchar(); n   } n   while (ch >=  0  && ch <=  9 ) { n     x = x * 10 + (ch -  0 ); n     ch = getchar(); n   } n   return x * p; n } n const int maxN = (int)4e5 + 10; n const int INF = (int)1e9; n const int mod = (int)1e9 + 7; n const long long LLINF = (long long)1e15; n int fw[maxN]; n int answer[maxN]; n vector<pair<int, int> > g[maxN]; n int get(int r) { n   int ret = 0; n   for (; r >= 0; r = (r & (r + 1)) - 1) { n     ret += fw[r]; n   } n   return ret; n } n void update(int r) { n   for (; r < maxN; r |= r + 1) { n     fw[r]++; n   } n } n int l[maxN]; n int r[maxN]; n int main() { n   ios_base::sync_with_stdio(0); n   int n; n   cin >> n; n   vector<int> x; n   for (int i = 0; i < n; ++i) { n     cin >> l[i] >> r[i]; n     x.push_back(l[i]); n     x.push_back(r[i]); n   } n   sort(x.begin(), x.end()); n   for (int i = 0; i < n; ++i) { n     l[i] = lower_bound(x.begin(), x.end(), l[i]) - x.begin(); n     r[i] = lower_bound(x.begin(), x.end(), r[i]) - x.begin(); n     g[r[i]].push_back(make_pair(l[i], i)); n   } n   for (int i = 0; i < maxN; ++i) { n     for (auto x : g[i]) { n       int l = x.first; n       int idx = x.second; n       answer[idx] = get(maxN - 1) - get(l); n       update(l); n     } n   } n   for (int i = 0; i < n; ++i) { n     cout << answer[i] <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int read() { n   int q = 0; n   char ch =    ; n   while (ch <  0  || ch >  9 ) ch = getchar(); n   while (ch >=  0  && ch <=  9 ) q = q * 10 + ch -  0 , ch = getchar(); n   return q; n } n const int N = 100005; n double P[N][110], ans; n int n, m, a[N], b[N]; n double C(int d, int u) { n   if (d < u || d < 0 || u < 0) return 0; n   double ans = 1; n   for (register int i = d - u + 1; i <= d; ++i) ans *= i; n   for (register int i = 1; i <= u; ++i) ans /= i; n   return ans; n } n int main() { n   n = read(); n   for (register int i = 1; i <= n; ++i) n     a[i] = b[i] = read(), P[i][a[i]] = 1, ans += (a[i] == 0); n   m = read(); n   while (m--) { n     int x = read(), y = read(), k = read(); n     ans -= P[x][0]; n     for (register int i = 0; i <= a[x]; ++i) { n       double tmp = 0, all = C(b[x], k); n       for (register int j = 0; j <= k; ++j) n         tmp += P[x][i + j] * C(b[x] - i - j, k - j) * C(i + j, j); n       P[x][i] = tmp / all; n     } n     ans += P[x][0], b[x] -= k, b[y] += k; n     printf( %.10lf n , ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n int const INF = 2e9; n int const MOD = 1000000007; n int const MAXN = 100010; n using namespace std; n int n, m, sum1, sum2, ans; n int a[MAXN], b[MAXN]; n int main() { n   ios_base::sync_with_stdio(0); n   cin >> n >> m; n   for (int i = 0; i < n; i++) cin >> a[i]; n   for (int j = 0; j < m; j++) cin >> b[j]; n   int i = 1, j = 1; n   sum1 = a[0], sum2 = b[0]; n   while (true) { n     if (sum1 < sum2) n       sum1 += a[i], i++; n     else if (sum2 < sum1) n       sum2 += b[j], j++; n     else { n       if (i == n && j == m) { n         ans++; n         break; n       } else n         sum1 = a[i], sum2 = b[j], i++, j++, ans++; n     } n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a[100010], dp[100010], rec[100010]; n int n; n int main() { n   while (~scanf( %d , &n)) { n     int maxn = 0; n     for (int i = 1; i <= n; i++) { n       dp[i] = 1; n       scanf( %d , &a[i]); n     } n     for (int i = 1; i <= n; i++) { n       rec[a[i]] = 1; n       if (rec[a[i] - 1] > 0) { n         dp[a[i]] = dp[a[i] - 1] + 1; n       } n       maxn = max(maxn, dp[a[i]]); n     } n     printf( %d n , n - maxn); n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long zyo[114514], sum[114514], kai[114514]; n long long mo = 1000000007; n long long extgcd(long long a, long long b, long long &x, long long &y) { n   long long g = a; n   x = 1; n   y = 0; n   if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x; n   return g; n } n long long invMod(long long a, long long m) { n   long long x, y; n   if (extgcd(a, m, x, y) == 1) return (x + m) % m; n   return 0; n } n long long co(int a, int b) { n   if (a < 0 || b < 0 || b > a) return 0; n   return ((kai[a] * invMod(kai[b], mo)) % mo * invMod(kai[a - b], mo)) % mo; n } n int main() { n   long long out = 0; n   int n, k; n   string s; n   zyo[0] = kai[0] = 1; n   sum[0] = 0; n   for (int i = 0; i < 100100; i++) { n     zyo[i + 1] = (zyo[i] * 10) % mo; n     kai[i + 1] = (kai[i] * (i + 1)) % mo; n   } n   cin >> n >> k; n   cin >> s; n   reverse(s.begin(), s.end()); n   for (int i = 0; i < n; i++) sum[i + 1] = sum[i] + (s[i] -  0 ); n   for (int i = 0; i < n; i++) { n     int now = (s[i] -  0 ); n     out = (out + (zyo[i] * co(n - i - 1, k)) % mo * now) % mo; n   } n   for (int i = 1; i < n; i++) { n     long long now = sum[n] - sum[i]; n     out = (out + (zyo[i - 1] * co(n - i - 1, k - 1)) % mo * now) % mo; n   } n   cout << out << endl; n } n


#include <bits/stdc++.h> n using namespace std; n long long gcd(long long a, long long b) { n   if (b == 0) n     return a; n   else n     return gcd(b, a % b); n } n long long lcm(long long a, long long b) { return (a / gcd(a, b)) * b; } n bool isPrime(int n) { n   if (n <= 1) return false; n   if (n <= 3) return true; n   if (n % 2 == 0 || n % 3 == 0) return false; n   for (int i = 5; i * i <= n; i = i + 6) n     if (n % i == 0 || n % (i + 2) == 0) return false; n   return true; n } n struct segment { n   int start; n   int end; n }; n struct monster { n   int a; n   int b; n   int nof_to_kill; n   monster(int attack, int health) { n     a = attack; n     b = health; n   } n   bool operator<(const monster &new_monster) const { n     return (nof_to_kill * a < new_monster.nof_to_kill * new_monster.a); n   } n }; n void solution() { n   int64_t n{}; n   cin >> n; n   cout << -n + 1 <<     << n << endl; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int t; n   cin >> t; n   while (t--) { n     solution(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2e6; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int n; n   cin >> n; n   int h[n]; n   for (int i = 0; i < n; ++i) { n     cin >> h[i]; n   } n   vector<int> v(n, 0); n   int maxx = 0; n   for (int i = n - 1; i >= 0; i--) { n     v[i] = max(0, maxx - h[i] + 1); n     maxx = max(maxx, h[i]); n   } n   for (int i = 0; i < n; i++) { n     cout << v[i] <<    ; n   } n } n


#include <bits/stdc++.h> n int n, m, i, j; n int ord[200000], a0[200000]; n bool use[200000]; n long long a[200000]; n long long k, p, t, q, s; n void qsort(int l, int r) { n   int i, j, t, x; n   i = l; n   j = r; n   x = ord[(l + r) / 2]; n   while (i < j) { n     while (a[ord[i]] < a[x]) i++; n     while (a[ord[j]] > a[x]) j--; n     if (i <= j) { n       t = ord[i]; n       ord[i] = ord[j]; n       ord[j] = t; n       i++; n       j--; n     } n   } n   if (l < j) qsort(l, j); n   if (i < r) qsort(i, r); n } n int main() { n   while (scanf( %d%I64d , &n, &k) != EOF) { n     for (i = 1; i <= n; i++) scanf( %I64d , &a[i]); n     for (i = 1; i <= n; i++) ord[i] = i; n     qsort(1, n); n     p = n; n     memset(use, 0, sizeof(use)); n     for (i = 1; i <= n; i++) { n       if (k < (a[ord[i]] - a[ord[i - 1]]) * (n - i + 1)) break; n       use[ord[i]] = true; n       k -= (a[ord[i]] - a[ord[i - 1]]) * (n - i + 1); n       s = a[ord[i]]; n     } n     j = n - i + 1; n     if (i == n + 1) { n       if (k != 0) printf( -1 n ); n     } else { n       for (i = 1; i <= n; i++) n         if (!use[i]) { n           a[i] -= k / j + s; n         } n       t = k % j; n       for (i = 1; t != 0 && i <= n; i++) n         if (!use[i]) { n           if (a[i] == 1) { n             use[i] = true; n             a[i] == 1; n           } n           t--; n         } n       j = i; n       q = 0; n       for (i = j; i <= n; i++) n         if (!use[i]) { n           q++; n           a0[q] = i; n         } n       for (i = 1; i < j; i++) n         if (!use[i]) { n           q++; n           a0[q] = i; n         } n       for (i = 1; i < q; i++) printf( %d  , a0[i]); n       printf( %d n , a0[q]); n     } n   } n } n


#include <bits/stdc++.h> n int main() { n   int n, m; n   int a, b; n   int min1, min2; n   int s1 = 0, s2 = 0, k1 = 0, k2 = 0; n   scanf( %d%d , &n, &m); n   while (n--) { n     scanf( %d , &a); n     if (a % 2 == 0) n       s1++; n     else n       s2++; n   } n   while (m--) { n     scanf( %d , &b); n     if (b % 2 == 0) n       k1++; n     else n       k2++; n   } n   if (s1 > k2) n     min1 = k2; n   else n     min1 = s1; n   if (k1 > s2) n     min2 = s2; n   else n     min2 = k1; n   printf( %d , min1 + min2); n } n


#include <bits/stdc++.h> n using namespace std; n long long pow_mod(long long x, long long y) { n   long long ret = 1; n   while (y) { n     if (y & 1) ret = (ret * x) % 1000000007; n     x = (x * x) % 1000000007; n     y >>= 1; n   } n   return ret; n } n long long f[2000010]; n void init() { n   f[0] = 1; n   for (int i = 1; i <= 2000005; i++) f[i] = (f[i - 1] * i) % 1000000007; n } n long long inv(long long x) { return pow_mod(x, 1000000007 - 2); } n long long C(long long x, long long y) { n   long long ret; n   ret = (f[x] * inv(f[y])) % 1000000007; n   ret = (ret * inv(f[x - y])) % 1000000007; n   return ret; n } n int main() { n   init(); n   int n; n   scanf( %d , &n); n   long long ans = 0; n   for (int i = 0; i <= n; i++) ans = (ans + C(i + n + 1, n)) % 1000000007; n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long t; n   cin >> t; n   while (t--) { n     long long n, i; n     cin >> n; n     long long c1 = 0, c2 = 0; n     vector<long long> a(n); n     for (i = 0; i < n; i++) { n       cin >> a[i]; n       if (a[i] % 2) n         c1++; n       else n         c2++; n     } n     if (!c2 and c1 == 1) n       cout << -1 << endl; n     else { n       if (c2) { n         cout << 1 << endl; n         for (i = 0; i < n; i++) { n           if (a[i] % 2 == 0) { n             cout << i + 1 << endl; n             break; n           } n         } n       } else { n         cout << 2 << endl; n         long long k = 0; n         for (i = 0; i < n; i++) { n           if (a[i] % 2 == 1) { n             cout << i + 1 <<    ; n             k++; n             if (k == 2) { n               cout << endl; n               break; n             } n           } n         } n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int casex, n, k; n int num, hed[200010], nex[400010], vt[400010]; n long long dp[200010][10], sum[200010], ans; n int read() { n   int u = 0; n   char c = getchar(); n   while (c <  0  || c >  9 ) c = getchar(); n   while (c >=  0  && c <=  9 ) u = (u << 1) + (u << 3) + c -  0 , c = getchar(); n   return u; n } n void add(int x, int y) { n   vt[++num] = y, nex[num] = hed[x], hed[x] = num; n   vt[++num] = x, nex[num] = hed[y], hed[y] = num; n } n void dfs1(int u, int fa) { n   for (int i = hed[u]; i; i = nex[i]) { n     if (vt[i] == fa) continue; n     dfs1(vt[i], u); n     for (int j = 1; j < k; j++) dp[u][j] += dp[vt[i]][j - 1]; n     sum[u] += sum[vt[i]] + dp[vt[i]][k - 1]; n     dp[u][0] += dp[vt[i]][k - 1]; n   } n   dp[u][0]++; n } n void dfs2(int u, int fa) { n   int tmp1 = dp[u][k - 1], tmp2 = dp[u][max(0, k - 2)]; n   for (int j = k - 1; j >= 2; j--) dp[u][j] += dp[fa][j - 1] - dp[u][j - 2]; n   dp[u][1] += dp[fa][0] - tmp1; n   dp[u][0] += dp[fa][k - 1] - tmp2; n   sum[u] += sum[fa] - sum[u] - tmp1 + dp[fa][k - 1] - tmp2; n   for (int i = hed[u]; i; i = nex[i]) { n     if (vt[i] == fa) continue; n     dfs2(vt[i], u); n   } n } n int main() { n   n = read(), k = read(); n   for (int i = 1; i <= n - 1; i++) { n     int x = read(), y = read(); n     add(x, y); n   } n   dfs1(1, 0); n   for (int i = hed[1]; i; i = nex[i]) dfs2(vt[i], 1); n   for (int i = 1; i <= n; i++) { n     ans += sum[i]; n     for (int j = 1; j < k; j++) ans += dp[i][j]; n   } n   printf( %lld , ans / 2); n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n using pii = pair<int, int>; n using vi = vector<int>; n using vii = vector<vector<int>>; n const ll LINF = 1LL << 60; n const int INF = 1 << 29; n const int MOD = 1e9 + 7; n int main() { n   int n; n   cin >> n; n   vector<pii> v(n); n   for (int i = 0; i < n; i++) { n     int x, w; n     cin >> x >> w; n     v[i] = {x + w, x - w}; n   } n   sort((v).begin(), (v).end()); n   int ans = 0, cur = -1e9 - 5; n   for (int i = 0; i < n; i++) { n     if (cur <= v[i].second) { n       cur = v[i].first; n       ans++; n     } n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1100; n int n, m, l[N], u[N], dd, ll; n double d[N][N], p = 1; n vector<pair<int, int> > el; n vector<int> eld; n int main() { n   int i, j, x; n   cin >> n >> m; n   for (i = 1; i <= m; ++i) { n     cin >> l[i]; n     for (j = 1; j <= l[i]; ++j) { n       cin >> x; n       el.push_back(pair<int, int>(x, i)); n     } n   } n   sort(el.begin(), el.end()); n   dd = el[el.size() - n].first; n   for (i = el.size() - 1; el[i].first != dd; --i) { n     p = p * (u[el[i].second] + 1) / (l[el[i].second] ? l[el[i].second] : 1); n     ++u[el[i].second]; n     --l[el[i].second]; n   } n   ll = i - el.size() + n + 1; n   for (; i >= 0 && el[i].first == dd; --i) eld.push_back(el[i].second); n   d[0][0] = p; n   for (j = 0; j < eld.size(); ++j) n     for (i = 0; i <= j; ++i) { n       d[i + 1][j + 1] += d[i][j] * (i + 1.0) / (j + 1.0) * (u[eld[j]] + 1) / n                          (l[eld[j]] ? l[eld[j]] : 1); n       d[i][j + 1] += d[i][j] * (j - i + 1.0) / (j + 1.0); n     } n   cout << setprecision(10) << fixed << d[ll][eld.size()]; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n void out(T x) { n   cout << x << endl; n   exit(0); n } n const int maxn = 1e6 + 5; n int n, k; n int bsize; n set<int> alive[maxn]; n int cnt; n char ask(int i) { n   cnt++; n   cout <<  ?   << i + 1 << endl; n   cout.flush(); n   char res; n   cin >> res; n   if (res ==  E ) exit(0); n   return res; n } n void reset() { n   cout <<  R  << endl; n   cout.flush(); n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   cin >> n >> k; n   bsize = max(1, k / 2); n   for (int i = 0; i < n; i++) { n     alive[i / bsize].insert(i); n   } n   reset(); n   set<int> kill; n   for (int i = 0; i < n; i++) { n     if (ask(i) ==  Y ) { n       kill.insert(i); n     } n   } n   for (int x : kill) { n     alive[x / bsize].erase(x); n   } n   for (int i = 0; i < n / bsize; i++) { n     for (int j = i + 1; j < n / bsize; j++) { n       if (alive[j].empty()) continue; n       reset(); n       for (int x : alive[i]) { n         assert(ask(x) ==  N ); n       } n       set<int> kill; n       for (int x : alive[j]) { n         if (ask(x) ==  Y ) { n           kill.insert(x); n         } n       } n       for (int x : kill) { n         alive[j].erase(x); n       } n     } n   } n   int ans = 0; n   for (int i = 0; i < n / bsize; i++) { n     ans += alive[i].size(); n   } n   cout <<  !   << ans << endl; n   cout.flush(); n   return 0; n } n


#include<bits/stdc++.h> n #define ll long long n #define ri register int n #define lowbit(x) x&(-x) n #define lson rt<<1, l, mid n #define rson rt<<1|1, mid+1, r n using namespace std; n const int p = 1e9+7; n const int maxn = 4e5+10; n int n, m, t, q; n int a[maxn], vis[maxn], go[maxn], two; n int dp[maxn][30]; n void divide(int x, int k){ n  int t = sqrt(x); n  for(int i = 2;i <= t;i ++){ n   if(x%i == 0){ n    vis[i] += k; n    if(vis[i] == 1 && k == -1) two --; n    else if(vis[i] >= 2) two ++; n    while(x%i == 0) x /= i; n   } n  } n  if(x > 1){ n   vis[x] += k; n   if(vis[x] == 1 && k == -1) two --; n   else if(vis[x] >= 2) two ++; n  } n } n int main(){ n  scanf( %d%d ,&n,&q); n  for(int i = 1;i <= n;i ++) n   scanf( %d ,&a[i]); n  int l = 1, r = 0; n  while(r < n){ n   r ++; n   divide(a[r], 1); n   if(two){ n    go[l] = r; n    while(two){ n     divide(a[l], -1); n     l ++; n     go[l] = r; n    } n   } n  } n  for(int i = l;i <= n+1;i ++) n   go[i] = n+1; n  for(int i = 1;i <= n;i ++){ n   dp[i][0] = go[i]; n  } n  for(int j = 1;j <= 20;j ++) n   for(int i = 1;i <= n+1;i ++){ n    if(dp[dp[i][j-1]][j-1]) n     dp[i][j] = dp[dp[i][j-1]][j-1]; n    else dp[i][j] = n+1; n   } n  for(int i = 1;i <= q;i ++){ n   int l, r; n   ll ans = 0; n   scanf( %d%d ,&l,&r); n   for(int j = 20;j >= 0;j --){ n    //cout << l <<     << j <<     << dp[l][j] << endl; n    if(dp[l][j] <= r){ n     l = dp[l][j]; n     ans += 1ll<<j; n    } n   } n   printf( %lld n ,ans+1); n  } n  return 0; n }


#include <bits/stdc++.h> n using namespace std; n int sqr(int v) { return v * v; } n int main() { n   int x1, y1, x2, y2, r1, r2; n   cin >> x1 >> y1 >> r1 >> x2 >> y2 >> r2; n   if (r1 < r2) swap(x1, x2), swap(y1, y2), swap(r1, r2); n   int t1 = sqr(x1 - x2) + sqr(y1 - y2); n   long double ans(0); n   if (t1 < sqr(r1 - r2)) n     ans = r1 - r2 - sqrt((long double)t1); n   else if (t1 > sqr(r1 + r2)) n     ans = sqrt((long double)t1) - r1 - r2; n   cout << fixed << setprecision(20) << ans / 2 << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int mod = 998244353; n int c[80][80], m; n struct tree { n   int n, ans[80], f[80][5000], g[80][5000]; n   int root, sum, siz[5000], w[5000], a[5000], tot; n   bool vis[5000]; n   vector<int> v[5000]; n   inline void getrt(int x, int fa) { n     siz[x] = 1; n     w[x] = 0; n     for (int i = 0; i < v[x].size(); i++) n       if (v[x][i] != fa && !vis[v[x][i]]) { n         getrt(v[x][i], x); n         siz[x] += siz[v[x][i]]; n         w[x] = max(w[x], siz[v[x][i]]); n       } n     w[x] = max(w[x], sum - siz[x]); n     if (!root || w[x] < w[root]) root = x; n   } n   inline void dfs(int x, int fa) { n     a[++tot] = x; n     siz[x] = 1; n     for (int i = 0; i < v[x].size(); i++) n       if (v[x][i] != fa && !vis[v[x][i]]) { n         dfs(v[x][i], x); n         siz[x] += siz[v[x][i]]; n       } n   } n   inline void work(int x) { n     tot = 0; n     dfs(x, 0); n     int i, j, k; n     memset(f, 0, sizeof(f)); n     memset(g, 0, sizeof(g)); n     f[0][x] = g[0][x] = 1; n     for (i = 1; i <= m; i++) n       for (j = 1; j <= tot; j++) { n         for (k = 0; k < v[a[j]].size(); k++) { n           if (vis[v[a[j]][k]]) continue; n           if (a[j] != x) f[i][a[j]] = (f[i][a[j]] + f[i - 1][v[a[j]][k]]) % mod; n           g[i][a[j]] = (g[i][a[j]] + g[i - 1][v[a[j]][k]]) % mod; n         } n       } n     for (i = 1; i <= tot; i++) { n       if (a[i] == x) { n         for (j = 0; j <= m; j++) ans[j] = (ans[j] + g[j][a[i]]) % mod; n       } else { n         for (j = 0; j <= m; j++) n           for (k = 0; k + j <= m; k++) n             ans[k + j] = n                 (ans[k + j] + (long long)f[j][a[i]] * g[k][a[i]] % mod) % mod; n       } n     } n     vis[x] = 1; n     for (i = 0; i < v[x].size(); i++) n       if (!vis[v[x][i]]) { n         root = 0; n         sum = siz[v[x][i]]; n         getrt(v[x][i], x); n         work(root); n       } n   } n   inline void solve() { n     sum = n; n     root = 0; n     memset(vis, 0, sizeof(vis)); n     memset(ans, 0, sizeof(ans)); n     getrt(1, 0); n     work(root); n   } n }; n tree t1, t2; n int main() { n   int i, j, k; n   scanf( %d%d%d , &t1.n, &t2.n, &m); n   c[0][0] = 1; n   for (i = 1; i <= m; i++) c[i][i] = c[i][0] = 1; n   for (i = 1; i <= m; i++) n     for (j = 1; j < i; j++) c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % mod; n   for (i = 0; i <= t1.n; i++) t1.v[i].clear(); n   for (i = 0; i <= t2.n; i++) t2.v[i].clear(); n   for (i = 1; i < t1.n; i++) { n     int x, y; n     scanf( %d%d , &x, &y); n     t1.v[x].push_back(y); n     t1.v[y].push_back(x); n   } n   for (i = 1; i < t2.n; i++) { n     int x, y; n     scanf( %d%d , &x, &y); n     t2.v[x].push_back(y); n     t2.v[y].push_back(x); n   } n   t1.solve(), t2.solve(); n   int Ans = 0; n   for (i = 0; i <= m; i++) n     Ans = (Ans + (long long)t1.ans[i] * t2.ans[m - i] % mod * c[m][i]) % mod; n   cout << Ans; n   return 0; n } n


#include <bits/stdc++.h> n const int N = 400 + 10, MOD = 1000000007; n inline void add(int &lhs, long long rhs) { lhs = (lhs + rhs) % MOD; } n int n, f[N][N]; n int main() { n   scanf( %d , &n); n   f[1][0] = f[1][1] = 1; n   for (int i = 2; i <= n; ++i) { n     for (int x = 0; x <= n; ++x) { n       for (int y = 0; x + y <= n; ++y) { n         int cur = (long long)f[i - 1][x] * f[i - 1][y] % MOD; n         if (!cur) continue; n         add(f[i][x + y], cur); n         add(f[i][x + y + 1], cur); n         if (x) add(f[i][x + y], 2LL * x * cur); n         if (y) add(f[i][x + y], 2LL * y * cur); n         if (x || y) add(f[i][x + y - 1], (x + y) * (x + y - 1LL) * cur); n       } n     } n   } n   printf( %d n , f[n][1]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long power(int base, long long p) { n   long long res = 1; n   while (p) { n     if (p & 1) { n       res *= base; n       --p; n     } n     base *= base; n     p /= 2; n   } n   return res; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   ; n   int t; n   cin >> t; n   while (t--) { n     int n; n     cin >> n; n     vector<int> vec; n     for (int i = 0; i < (int)(n); ++i) { n       int x; n       cin >> x; n       vec.push_back(x); n     } n     sort((vec).begin(), (vec).end()); n     int sz = unique((vec).begin(), (vec).end()) - vec.begin(); n     if (sz == n) n       cout <<  No  <<   n ; n     else n       cout <<  Yes  <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX = 5000; n long long n, a, b, c, d; n pair<long long, long long> p[MAX]; n bool cmp(pair<int, int> x, pair<int, int> y) { n   if (x.first > y.first) return 1; n   if (x.first == y.first) return x.second < y.second; n   return 0; n } n int main() { n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> a >> b >> c >> d; n     long long sum = a + b + c + d; n     p[i].first = sum; n     p[i].second = i + 1; n   } n   sort(p, p + n, cmp); n   for (int i = 0; i < n; i++) n     if (p[i].second == 1) { n       cout << i + 1 << endl; n       break; n     } n   return 0; n } n


#include <bits/stdc++.h> n template <class c> n int popc(c a) { n   if (sizeof(c) == 8) n     return __builtin_popcountll(a); n   else n     return __builtin_popcount(a); n } n template <class c> n int ctz(c a) { n   if (sizeof(c) == 8) n     return __builtin_ctzll(a); n   else n     return __builtin_ctz(a); n } n template <class c> n int clz(c a) { n   if (sizeof(c) == 8) n     return __builtin_clzll(a); n   else n     return __builtin_clz(a); n } n inline int min(const int &first, const int &second) { n   return (((second - first) >> (32 - 1)) & (first ^ second)) ^ first; n } n inline int max(const int &first, const int &second) { n   return (((second - first) >> (32 - 1)) & (first ^ second)) ^ second; n } n inline long long min(const long long &first, const long long &second) { n   return (((second - first) >> (64 - 1)) & (first ^ second)) ^ first; n } n inline long long max(const long long &first, const long long &second) { n   return (((second - first) >> (64 - 1)) & (first ^ second)) ^ second; n } n using namespace std; n char string_in_buffer[(int)260]; n void fast_scan(int &first) { scanf( %d , &first); } n void fast_scan(long long &first) { scanf( %lld , &first); } n void fast_scan(unsigned long long &first) { scanf( %llu , &first); } n void fast_scan(double &first) { scanf( %lf , &first); } n void fast_scan(long double &first) { scanf( %Lf , &first); } n void fast_scan(char &first) { n   scanf( %c , &first); n   if (first ==   n ) { n     fast_scan(first); n   } n } n void fast_scan(string &first) { n   scanf( %s , string_in_buffer); n   first = string(string_in_buffer); n } n template <class TFirst, class TSecond> n void fast_scan(pair<TFirst, TSecond> &p) { n   fast_scan(p.first); n   fast_scan(p.second); n } n template <class T> n void fast_scan(vector<T> &v) { n   for (auto &first : v) fast_scan(first); n } n void fast_print(const int &first) { printf( %d , first); } n void fast_print(const unsigned int &first) { printf( %u , first); } n void fast_print(const long long &first) { printf( %lld , first); } n void fast_print(const unsigned long long &first) { printf( %llu , first); } n void fast_print(const char &first) { printf( %c , first); }; n void fast_print(const double &first) { printf( %.15lf , first); } n void fast_print(const long double &first) { printf( %.15Lf , first); } n void fast_print(const string &first) { printf( %s , first.c_str()); } n void fast_print(const char v[]) { fast_print((string)v); } n template <class TFirst, class TSecond> n void fast_print(const pair<TFirst, TSecond> &p) { n   fast_print(p.first); n   fast_print(   ); n   fast_print(p.second); n } n template <class T> n void fast_print(const vector<T> &v) { n   if (v.empty()) return; n   fast_print(v[0]); n   for (int i = 1; i < v.size(); i++) { n     fast_print(   ); n     fast_print(v[i]); n   } n } n template <class T> n void fast_print(const vector<vector<T>> &v) { n   if (v.empty()) return; n   fast_print(v[0]); n   for (int i = 1; i < v.size(); i++) { n     fast_print(  n ); n     fast_print(v[i]); n   } n } n template <class T> n void fast_print(const T &v) { n   for (const auto &first : v) { n     fast_print(first); n     fast_print(   ); n   } n } n using namespace std; n namespace smart_io { n string print_start =   ; n string sep =    ; n bool first_print = false; n void precall_print() { n   fast_print(print_start); n   print_start =   n ; n   first_print = true; n } n void _print(deque<string>) {} n template <class T, class... Args> n void _print(deque<string> names, T elem, Args... args) { n   if (!first_print) { n     fast_print(  n ); n   } else { n     first_print = false; n   } n   fast_print(names.front()); n   fast_print(  =  ); n   fast_print(elem); n   names.pop_front(); n   _print(names, args...); n } n }  // namespace smart_io n template <class T> n ostream &operator,(ostream &os, const T &object) { n   if (!smart_io::first_print) { n     fast_print(smart_io::sep); n   } else { n     smart_io::first_print = false; n   } n   fast_print(object); n   return os; n } n template <class T> n istream &operator,(istream &is, T &object) { n   fast_scan(object); n   return is; n } n namespace escape__from__random__aetuhoetnuhshe { n using namespace std::chrono; n mt19937 rng(duration_cast<milliseconds>(system_clock::now().time_since_epoch()) n                 .count()); n uniform_real_distribution<> prob_dist(0.0, 1.0); n };  // namespace escape__from__random__aetuhoetnuhshe n namespace typedefs {} n namespace numbers_operation { n template <class T> n inline T floor_mod(T a, const T &b) { n   a %= b; n   if (a < 0) a += b; n   return a; n } n }  // namespace numbers_operation n using namespace numbers_operation; n using namespace typedefs; n using namespace escape__from__random__aetuhoetnuhshe; n long long n; n vector<long long> v; n void solve() { n   cin, n; n   v.clear(); n   v.resize(n); n   cin, v; n   long long _max = v[0]; n   long long rez = 0; n   for (long long i = 0; i < n; i++) { n     _max = max(_max, v[i]); n     if (_max > v[i]) { n       rez = max(rez, (long long)(64 - clz(_max - v[i]))); n     } n   } n   smart_io::precall_print(); n   cout, rez; n } n signed main(signed argc, char *argv[]) { n   long long tests; n   cin, tests; n   for (long long test = 0; test < (tests); test++) { n     solve(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); n struct Event { n   long long x, t, i; n   Event() {} n   Event(long long x, long long t, long long i) : x(x), t(t), i(i) {} n }; n bool cmpEvents(const Event &a, const Event &b) { n   return tie(a.x, a.t, a.i) < tie(b.x, b.t, b.i); n } n const long long MAX_N = 2e5 + 5; n long long n; n long long cnt[MAX_N]; n pair<bool, bool> cover[MAX_N]; n void solve() { n   cin >> n; n   vector<Event> sc; n   for (long long i = 1; i <= n; ++i) { n     cnt[i] = 0; n     cover[i] = make_pair(false, false); n     long long l, r; n     cin >> l >> r; n     l *= 2, r *= 2; n     sc.emplace_back(l, -1, i); n     sc.emplace_back(r, 1, i); n   } n   sort(sc.begin(), sc.end(), cmpEvents); n   for (long long i = 1; i < 2 * n; ++i) { n     sc.emplace_back((sc[i - 1].x + sc[i].x) / 2, 0, 0); n   } n   sort(sc.begin(), sc.end(), cmpEvents); n   set<long long> alive; n   long long start_ans = 2; n   for (long long i = 0; i < (long long)sc.size();) { n     long long j = i; n     while (j < (long long)sc.size() && sc[i].x == sc[j].x && sc[j].t == -1) { n       alive.emplace(sc[j].i); n       ++j; n     } n     while (i < j) { n       cover[sc[i].i].first = (long long)alive.size() > 1; n       ++i; n     } n     while (j < (long long)sc.size() && sc[i].x == sc[j].x && sc[j].t == 0) { n       if ((long long)alive.size() == 1) { n         cnt[*alive.begin()]++; n       } n       ++j; n     } n     if (alive.empty()) { n       start_ans++; n     } n     i = j; n     while (j < (long long)sc.size() && sc[i].x == sc[j].x && sc[j].t == 1) { n       cover[sc[j].i].second = (long long)alive.size() > 1; n       ++j; n     } n     while (i < j) { n       alive.erase(sc[i].i); n       ++i; n     } n   } n   long long ans = 0; n   for (long long i = 1; i <= n; ++i) { n     ans = max(ans, start_ans + cnt[i] - !cover[i].first - !cover[i].second - 1); n   } n   cout << ans <<   n ; n } n signed main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   long long T; n   cin >> T; n   while (T--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, in[100010], sum1, sum2; n int main() { n   cin >> n >> m; n   for (int i = 1; i <= m; i++) { n     int x, y; n     cin >> x >> y; n     in[x]++; n     in[y]++; n   } n   for (int i = 1; i <= n + 1; i++) n     if (in[i] == 1) n       sum1++; n     else if (in[i] == 2) n       sum2++; n   if (sum1 == 2 && sum2 == n - 2) { n     cout <<  bus topology ; n     return 0; n   } n   sum1 = sum2 = 0; n   for (int i = 1; i <= n; i++) n     if (in[i] == 2) sum1++; n   if (sum1 == n) { n     cout <<  ring topology ; n     return 0; n   } n   sum1 = sum2 = 0; n   for (int i = 1; i <= n + 1; i++) n     if (in[i] == 1) n       sum1++; n     else if (in[i] == n - 1) n       sum2++; n   if (sum1 == n - 1 && sum2 == 1) { n     cout <<  star topology ; n     return 0; n   } n   cout <<  unknown topology ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(0); n   long long n, m, k, t; n   cin >> n >> m >> k >> t; n   pair<int, int> mp[k + 1]; n   long long x, y, a, b; n   for (int i = 0; i < k; i++) { n     cin >> mp[i].first >> mp[i].second; n   } n   sort(mp, mp + k); n   for (int i = 0; i < t; i++) { n     cin >> x >> y; n     long long idx = m * (x - 1) + y; n     bool f = true; n     for (int i = 0; i < k; i++) { n       if (mp[i].first > x || (mp[i].first == x && mp[i].second > y)) { n         idx -= (i + 1); n         break; n       } n       if (mp[i].first == x && mp[i].second == y) { n         f = false; n         cout <<  Waste  << endl; n         break; n       } n       if (i == k - 1) idx = idx - k - 1; n     } n     if (idx % 3 == 0 && f) n       cout <<  Carrots  << endl; n     else if (idx % 3 == 1 && f) n       cout <<  Kiwis  << endl; n     else if (idx % 3 == 2 && f) n       cout <<  Grapes  << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 100 + 10; n const int INF = int(1e9); n int main() { n   int n; n   char str1[maxn], str2[maxn]; n   while (~scanf( %d , &n)) { n     scanf( %s %s , str1, str2); n     int h, m; n     h = (str1[0] -  0 ) * 10 + str1[1] -  0 ; n     m = (str2[0] -  0 ) * 10 + str2[1] -  0 ; n     int ans = 0; n     while (h % 10 != 7 && m % 10 != 7) { n       if (m - n < 0) { n         m = m - n + 60; n         if (h == 0) n           h = 23; n         else n           h--; n       } else n         m = m - n; n       ans++; n     } n     printf( %d n , ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long INF = 9e18; n const int inf = 2147483647; n long long qpow(long long a, long long b, long long mod) { n   long long r = 1; n   for (; b; b >>= 1) { n     if (b & 1) r = (r * a) % mod; n     a = (a * a) % mod; n   } n   return r; n } n const int N = 1e5 + 5; n void work() { n   int t; n   scanf( %d , &t); n   while (t--) { n     int r, g, b, w; n     scanf( %d%d , &r, &g); n     scanf( %d%d , &b, &w); n     int sum = 0; n     if (r % 2) sum++; n     if (g % 2) sum++; n     if (b % 2) sum++; n     if (sum == 0) n       puts( YES ); n     else if (sum == 1) { n       puts(w % 2 == 0 ?  YES  :  NO ); n     } else if (sum == 2) { n       if (r && g && b) n         puts(w % 2 ?  YES  :  NO ); n       else n         puts( NO ); n     } else { n       puts( YES ); n     } n   } n } n int main() { n   work(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int a[1000], b, c, d; n   cin >> b >> c >> d; n   a[0] = b; n   a[1] = c; n   for (int i = 2; i <= d; i++) { n     a[i] = a[i - 1] + a[i - 2]; n   } n   cout << a[d]; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   int a[n], i, j, k1 = 0, k2 = 0; n   for (i = 0; i < n; i++) { n     cin >> a[i]; n     if (a[i] == 1) n       k1++; n     else n       k2++; n   } n   int k3 = 0, k4 = 0; n   for (i = 0; i < n; i++) { n     if (a[i] == 1) n       k3++; n     else n       k4++; n     if (k3 >= k1 || k4 >= k2) { n       j = i; n       break; n     } n   } n   cout << j + 1; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m; n struct Node { n   long long x, y; n } Edge[300005]; n long long pre[300005]; n bool cmp(Node a, Node b) { return a.y > b.y; } n int main() { n   scanf( %d%d , &n, &m); n   for (int i = 1; i <= n; i++) { n     scanf( %lld%lld , &Edge[i].x, &Edge[i].y); n   } n   sort(Edge + 1, Edge + n + 1, cmp); n   priority_queue<int, vector<int>, greater<int>> q; n   long long ans = 0; n   for (int i = 1; i <= n; i++) { n     if (q.size() < m) { n       q.push(Edge[i].x); n       pre[i] = pre[i - 1] + Edge[i].x; n       ans = max(ans, Edge[i].y * pre[i]); n     } else { n       if (Edge[i].x <= q.top()) { n         pre[i] = pre[i - 1]; n       } else { n         pre[i] = pre[i - 1] - q.top() + Edge[i].x; n         q.pop(); n         q.push(Edge[i].x); n         ans = max(ans, Edge[i].y * pre[i]); n       } n     } n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char x, y, t; n struct node { n   char c; n   int p; n } ans[4]; n inline bool cmp(const node &a, const node &b) { return a.p < b.p; } n int main() { n   for (register int i = 1; i <= 3; i++) { n     ans[i].c =  A  + i - 1; n     cin >> x >> t >> y; n     if (t ==  > ) swap(x, y); n     ans[x -  A  + 1].p++; n     ans[y -  A  + 1].p += 2; n   } n   sort(ans + 1, ans + 4, cmp); n   if (ans[1].p == ans[2].p || ans[2].p == ans[3].p) { n     cout <<  Impossible ; n     return 0; n   } n   cout << ans[1].c << ans[2].c << ans[3].c; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MX = 1e6 + 5; n long long ans[MX]; n long long upd[MX]; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   int n, w; n   cin >> n >> w; n   vector<int> a[n]; n   int mx[n]; n   for (int i = 0; i < n; i++) { n     int l; n     cin >> l; n     a[i] = vector<int>(l); n     mx[i] = -1000000000; n     for (int j = 0; j < l; j++) { n       cin >> a[i][j]; n       mx[i] = max(mx[i], a[i][j]); n     } n   } n   memset(ans, 0, sizeof(ans)); n   for (int i = 0; i < n; i++) { n     if (w >= 2 * a[i].size() + 1) { n       int currmx = 0; n       for (int j = 0; j < a[i].size(); j++) { n         currmx = max(currmx, a[i][j]); n         ans[j + 1] += currmx; n       } n       currmx = 0; n       for (int j = a[i].size() - 1; j >= 0; j--) { n         currmx = max(currmx, a[i][j]); n         ans[w - ((a[i].size() - 1) - j)] += currmx; n       } n       upd[a[i].size()] -= max(mx[i], 0); n       upd[w - a[i].size()] += max(mx[i], 0); n     } else { n       deque<int> q; n       int idx = 0; n       bool zero = false; n       for (int j = 1; j <= w; j++) { n         if (idx < a[i].size()) { n           while (!q.empty() && a[i][q.back()] <= a[i][idx]) { n             q.pop_back(); n           } n           q.push_back(idx++); n         } n         zero = (a[i].size() <= (j - 1)) || (a[i].size() <= (w - j)); n         if (zero) n           ans[j] += max(a[i][q.front()], 0); n         else n           ans[j] += a[i][q.front()]; n         if (((a[i].size() - q.front()) + j) >= w + 1) { n           q.pop_front(); n         } n       } n     } n   } n   for (int i = w; i >= 1; i--) { n     upd[i] += upd[i + 1]; n   } n   for (int i = 1; i <= w; i++) cout << ans[i] + upd[i] <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(nullptr); n   cout.tie(nullptr); n   string a; n   string b; n   cin >> a >> b; n   int order = 0; n   while (a[order] ==  0 ) { n     order++; n   } n   a.erase(0, order); n   order = 0; n   while (b[order] ==  0 ) { n     order++; n   } n   b.erase(0, order); n   if (a.size() > b.size()) { n     cout <<  > ; n   } else if (a.size() < b.size()) { n     cout <<  < ; n   } else { n     for (int i = 0; i < a.size(); i++) { n       if (a[i] > b[i]) { n         cout <<  > ; n         return 0; n       } else if (a[i] < b[i]) { n         cout <<  < ; n         return 0; n       } n     } n     cout <<  = ; n   } n } n


#include <bits/stdc++.h> n using i8 = std::int8_t; n using i16 = std::int16_t; n using i32 = std::int32_t; n using i64 = std::int64_t; n using u8 = std::uint8_t; n using u16 = std::uint16_t; n using u32 = std::uint32_t; n using u64 = std::uint64_t; n auto SolveTest() -> void { n   int n; n   std::cin >> n; n   std::vector<int> a(n); n   for (auto &elem : a) { n     std::cin >> elem; n   } n   std::set<int> numbers(std::begin(a), std::end(a)); n   for (auto it = std::begin(numbers); std::next(it) != std::end(numbers); n        ++it) { n     if (std::abs(*it - *std::next(it)) > 1) { n       std::cout <<  NO n ; n       return; n     } n   } n   std::cout <<  YES n ; n } n int main() { n   std::ios_base::sync_with_stdio(false); n   std::cin.tie(nullptr); n   std::cout.tie(nullptr); n   i32 test_count; n   std::cin >> test_count; n   for (i32 t = 0; t < test_count; ++t) { n     SolveTest(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int n; n unordered_map<int, int> mask, f; n int SG(int s) { n   if (f.count(s)) return f[s]; n   bool t[30] = {0}; n   for (int i = 0; s >> i; i++) { n     t[SG(s >> (i + 1) | (s & ((1 << i) - 1)))] = 1; n   } n   for (int i = 0; i < 30; i++) n     if (!t[i]) return f[s] = i; n   return 30; n } n int main() { n   scanf( %d , &n); n   for (int i = 1, x; i <= n; i++) { n     scanf( %d , &x); n     for (int d = 2; d * d <= x; d++) n       if (x % d == 0) { n         int c = 0; n         while (x % d == 0) x /= d, c++; n         mask[d] |= 1 << (c - 1); n       } n     if (x > 1) mask[x] |= 1; n   } n   int ans = 0; n   for (auto s : mask) ans ^= SG(s.second); n   puts(ans ?  Mojtaba  :  Arpa ); n   return 0; n } n


//Author: AnandRaj uux n #include <bits/stdc++.h> n using namespace std; n  n typedef long long ll; n typedef long double ld; n typedef pair<int,int> pii; n typedef vector<int> vi; n typedef vector<vi> vvi; n typedef vector<pii> vpii; n typedef pair<ll,ll> pll; n typedef vector<ll> vl; n typedef vector<vl> vvl; n typedef vector<pll> vpll;  n  n #define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); n #define test() int t;cin>>t;while(t--) n #define all(v) v.begin(),v.end() n #define prinp(p) cout<<p.first<<   <<p.second<<endl n #define prinv(V) for(auto v:V) cout<<v<<   ;cout<<endl n #define take(V,f,n) for(int in=f;in<f+n;in++) cin>>V[in] n #define what(x) cerr<<#x<<  =  <<x<<endl n #define KStest() int t,t1;cin>>t;t1=t;while(t--) n #define KScout cout<< Case # <<t1-t<< :   n mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); n const int MOD = 1e9+7,MAX = 1e6+5; n const ll INF = 1e18+5; n  n vvi A; n bool can = true; n vi TS; n vi vis,inStack; n void dfs(int x, int parent)  n { n     vis[x] = true; n     inStack[x] = true; n     for(auto v:A[x])  n     { n         if (vis[v] && inStack[v])  n         { n             can = false; n             return; n         } n         if(!vis[v])  n         { n             dfs(v, x); n         } n     } n     inStack[x] = false; n     TS.push_back(x); n } n  n int main() n { n  int n,m,k; n  cin>>n>>m>>k; n  A.resize(n+1); n  vector<string> P(n+1); n  map<string,int> Sp; n  take(P,1,n); n  for(int i=1;i<=n;i++) Sp[P[i]] = i; n   n  vis.resize(n+1); n  inStack.resize(n+1); n  n  vector<int> MT(m+1); n  vector<string> S(m+1); n  n  for(int i=1;i<=m;i++) n  { n   cin>>S[i]>>MT[i]; n   set<string> X; n   X.insert(  ); n   for(int j=0;j<k;j++) n   { n    set<string> XX; n    for(auto x:X) n    { n     XX.insert(x+ _ ); n     XX.insert(x+S[i][j]); n    } n    X = XX; n   } n   if(X.count(P[MT[i]])==0) {can = false;break;} n   for(auto x:X) n   { n    if(Sp.find(x)==Sp.end() || Sp[x]==MT[i]) continue; n    else n    { n     A[MT[i]].push_back(Sp[x]); n    } n   } n  } n  // for(int i=1;i<=n;i++) n  // { n  //  prinv(A[i]); n  // } n  for(int i=1;i<=n;i++) n  { n   if(!vis[i]) dfs(i,-1); n  } n  if(can) n  { n   cout<< YES <<endl; n   reverse(all(TS)); n   prinv(TS); n  } n  else cout<< NO <<endl; n  n  n }


#include <bits/stdc++.h> n using namespace std; n const int maxn = 5; n inline long long rd() { n   long long x = 0; n   char c = getchar(); n   int neg = 1; n   while (c <  0  || c >  9 ) { n     if (c ==  - ) neg = -1; n     c = getchar(); n   } n   while (c >=  0  && c <=  9 ) x = x * 10 + c -  0 , c = getchar(); n   return x * neg; n } n pair<int, int> p[maxn]; n int main() { n   int i, j, k; n   for (i = 1; i <= 3; i++) p[i].first = rd(), p[i].second = rd(); n   sort(p + 1, p + 4); n   if (p[1].second <= p[2].second && p[1].second <= p[3].second) { n     if (p[2].second <= p[3].second) { n       int ans = p[2].second - p[1].second + p[3].first - p[1].first + n                 p[3].second - p[2].second + 1; n       printf( %d n , ans); n       for (i = p[1].second; i <= p[2].second; i++) n         printf( %d %d n , p[1].first, i); n       for (i = p[1].first + 1; i <= p[3].first; i++) n         printf( %d %d n , i, p[2].second); n       for (i = p[2].second + 1; i <= p[3].second; i++) n         printf( %d %d n , p[3].first, i); n     } else { n       int ans = p[3].second - p[1].second + p[3].first - p[1].first + n                 p[2].second - p[3].second + 1; n       printf( %d n , ans); n       for (i = p[1].second; i <= p[3].second; i++) n         printf( %d %d n , p[1].first, i); n       for (i = p[1].first + 1; i <= p[3].first; i++) n         printf( %d %d n , i, p[3].second); n       for (i = p[3].second + 1; i <= p[2].second; i++) n         printf( %d %d n , p[2].first, i); n     } n   } else if (p[1].second <= p[2].second && p[1].second > p[3].second) { n     int ans = p[1].second - p[3].second + p[3].first - p[1].first + n               p[2].second - p[1].second + 1; n     printf( %d n , ans); n     for (i = p[3].second; i <= p[1].second; i++) n       printf( %d %d n , p[3].first, i); n     for (i = p[1].first; i <= p[3].first - 1; i++) n       printf( %d %d n , i, p[1].second); n     for (i = p[1].second + 1; i <= p[2].second; i++) n       printf( %d %d n , p[2].first, i); n   } else if (p[1].second > p[2].second && p[1].second <= p[3].second) { n     int ans = p[3].second - p[1].second + p[3].first - p[1].first + n               p[1].second - p[2].second + 1; n     printf( %d n , ans); n     for (i = p[1].second; i <= p[3].second; i++) n       printf( %d %d n , p[3].first, i); n     for (i = p[1].first; i <= p[3].first - 1; i++) n       printf( %d %d n , i, p[1].second); n     for (i = p[2].second; i <= p[1].second - 1; i++) n       printf( %d %d n , p[2].first, i); n   } else if (p[1].second > p[2].second && p[1].second > p[3].second) { n     if (p[2].second <= p[3].second) { n       int ans = p[1].second - p[2].second + p[2].first - p[1].first + n                 p[3].first - p[2].first + 1; n       printf( %d n , ans); n       for (i = p[1].first; i <= p[3].first; i++) n         printf( %d %d n , i, p[3].second); n       for (i = p[2].second; i <= p[3].second - 1; i++) n         printf( %d %d n , p[2].first, i); n       for (i = p[3].second + 1; i <= p[1].second; i++) n         printf( %d %d n , p[1].first, i); n     } else { n       int ans = p[3].first - p[1].first + p[1].second - p[3].second + 1; n       printf( %d n , ans); n       for (i = p[2].second; i <= p[1].second; i++) n         printf( %d %d n , p[1].first, i); n       for (i = p[1].first + 1; i <= p[3].first; i++) n         printf( %d %d n , i, p[2].second); n       for (i = p[3].second; i <= p[2].second - 1; i++) n         printf( %d %d n , p[3].first, i); n     } n   } n   return 0; n } n