#include <bits/stdc++.h> n using namespace std; n const long long INF = 1e18; n const int inf = 1e9; n int main() { n   long long n, m, grt = 0, eq = 0, less = 0, i; n   cin >> n >> m; n   for (i = 0; i < n; i++) { n     long long temp; n     cin >> temp; n     if (temp == m) n       eq++; n     else if (temp < m) n       less++; n     else n       grt++; n   } n   long long ans = 0, tot; n   if (eq == 0) { n     eq++; n     ans++; n   } n   tot = less + eq + grt; n   long long temp = (tot + 1) / 2; n   if (less + eq < temp) { n     ans += grt - less - eq; n     less += grt - less - eq; n   } else if (tot - (grt + eq) > temp) { n     ans += less - eq - grt; n     grt += less - eq - grt; n   } n   tot = less + eq + grt; n   temp = (tot + 1) / 2; n   if (less == temp) ans++; n   if (grt == tot - temp + 1) ans++; n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool prime(int n) { n   for (int i = 2; i * i <= n; i++) { n     if (n % i == 0) return false; n   } n   return true; n } n int main() { n   int n; n   cin >> n; n   if (prime(n)) { n     cout << 1 <<   n  << n << endl; n     return 0; n   } n   if (prime(n - 2)) { n     cout << 2 <<   n  << 2 <<   n  << n - 2 << endl; n     return 0; n   } n   cout << 3 <<   n  << 3 << endl; n   n -= 3; n   for (int i = 2; i <= n; i++) { n     if (prime(i) and prime(n - i)) { n       cout << i <<   n  << n - i << endl; n       break; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n using ld = long double; n using ii = pair<ll, ll>; n using vi = vector<ll>; n using vb = vector<bool>; n using vvi = vector<vi>; n using vii = vector<ii>; n using vvii = vector<vii>; n const int INF = 2000000000; n const ll LLINF = 9000000000000000000; n int main() { n   int N; n   scanf( %d , &N); n   vi A(N, 0LL), B(N, 0LL); n   for (int i = 0; i < N; ++i) { n     int v; n     scanf( %d , &v); n     A[i] = ll(v); n     B[i] = A[i] + (i > 0 ? B[i - 1] : 0LL); n   } n   ll mx = 0LL; n   for (int i = 0; i < N; ++i) mx += ll(i + 1) * A[i]; n   vii lns; n   vector<ld> start(1, -std::numeric_limits<ld>::infinity()); n   lns.push_back({0, 0}); n   for (int i = 0; i < N; ++i) { n     while (lns.size() > 1 && start.back() >= ld(-B[i] - lns.back().second) / n                                                  ld(lns.back().first - i - 1)) { n       lns.pop_back(); n       start.pop_back(); n     } n     start.push_back(ld(-B[i] - lns.back().second) / n                     ld(lns.back().first - i - 1)); n     lns.push_back({i + 1, -B[i]}); n   } n   ll bestchange = 0LL; n   int D = 5; n   for (int i = 0; i < N; ++i) { n     ll change = B[i] - A[i] * ll(i + 1); n     int l = 0, r = int(lns.size()) - 1; n     while (l < r) { n       int m = (l + r + 1) / 2; n       if (start[m] > A[i]) n         r = m - 1; n       else n         l = m; n     } n     for (int j = max(0, l - D); j < min(int(lns.size()), l + D + 1); ++j) { n       if (bestchange < change + A[i] * lns[j].first + lns[j].second) { n         bestchange = change + A[i] * lns[j].first + lns[j].second; n       } n     } n   } n   cout << (mx + bestchange) << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n void read(vector<T> &a, long long n) { n   T x; n   a.clear(); n   for (long long i = 0; i < n; i++) { n     cin >> x; n     a.push_back(x); n   } n } n template <class T> n void write(vector<T> &a) { n   for (T x : a) cout << x <<    ; n   cout << endl; n } n const int N = 300005; n const int S = 500; n long long sum[S][S]; n long long ans[N]; n vector<pair<pair<int, int>, int> > q; n int n, m; n int w[N]; n int main() { n   ios_base::sync_with_stdio(0); n   cin >> n; n   for (int i = 1; i <= n; i++) cin >> w[i]; n   cin >> m; n   for (int i = 0; i < m; i++) { n     int a, b; n     cin >> a >> b; n     q.push_back(make_pair(make_pair(a, b), i)); n   } n   sort(q.begin(), q.end()); n   reverse(q.begin(), q.end()); n   int pos = n; n   for (int i = 0; i < q.size(); i++) { n     int a = q[i].first.first; n     int b = q[i].first.second; n     int id = q[i].second; n     while (pos >= a) { n       for (int j = 1; j < S; j++) sum[j][pos % j] += w[pos]; n       pos--; n     } n     if (b < S) n       ans[id] = sum[b][a % b]; n     else { n       long long res = 0; n       for (int j = a; j <= n; j += b) res += w[j]; n       ans[id] = res; n     } n   } n   for (int i = 0; i < m; i++) cout << ans[i] << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   int n; n   cin >> n; n   map<int, int> mp1, mp2; n   map<int, int>::iterator it; n   for (int i = 0; i < n; i++) { n     int a, b; n     cin >> a >> b; n     mp1[a] = b; n   } n   int m; n   cin >> m; n   for (int i = 0; i < m; i++) { n     int a, b; n     cin >> a >> b; n     if (mp1.find(a) != mp1.end()) { n       it = mp1.find(a); n       if (it->second > b) { n         continue; n       } else { n         mp1.erase(it); n         mp2[a] = b; n       } n     } else { n       mp2[a] = b; n     } n   } n   long long sum = 0; n   it = mp1.begin(); n   while (it != mp1.end()) { n     sum += it->second; n     it++; n   } n   it = mp2.begin(); n   while (it != mp2.end()) { n     sum += it->second; n     it++; n   } n   cout << sum <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long test(long long k) { n   long long a[] = {-1, 1, k + 2}; n   int c = -1; n   long long cur = 0, res = 0; n   for (int i = 0; i < 3; i++) { n     cur += a[i]; n     if (cur < 0) { n       cur = 0; n       c = i; n     } n     res = max(res, (i - c) * cur); n   } n   return res; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   long long k; n   cin >> k; n   int a = k + 2000; n   cout << 2000 << endl << -1 <<    ; n   for (int i = 1; i < 2000; i++) { n     cout << min(a, (int)1e6) <<    ; n     a -= min(a, (int)1e6); n   } n   return 0; n } n


#include <bits/stdc++.h> n #define task  suffixarray  n #define ll long long n #define FOR( i, l, r) for(int i = (l), _r = (r); i <= _r; ++i) n #define FOD( i, l, r) for(int i = (l), _r = (r); i >= _r; --i) n #define REP( i, n)    for(int i = 0, _n = (n); i < _n; ++i) n #define pii pair<int,int> n #define fi  first n #define se  second n #define MASK(x)  (1ll << (x)) n #define BIT(x,k) (((x) >> (k)) & 1ll) n #define OFF(x,k) ((x) & ~(1ll << (k))) n #define ON(x,k)  ((1ll << (k)) | (x)) n #define endl   n  n #define __builtin_popcount __builtin_popcountll n /* n  Author: Diem Quynh :>> //d_quynh_2811 n */ n using namespace std; n int const N = 4e5 + 5; n int const mod = 998244353; n int n, k, a[N], idx[N], fact[N], ifact[N]; n int num = 1, ans; n void inp() n { n     cin >> n >> k; n     FOR( i, 1, n) n     { n         cin >> a[i]; n         ++a[i]; n         idx[a[i]] = i; n     } n } n int Pow(int a, int b) n { n     if(b == 0) n         return 1; n     int tmp = Pow(a, b / 2); n     if(b & 2) n         return (1ll * tmp * tmp) % mod * a % mod; n     return 1ll * tmp * tmp % mod; n } n int nCk(int n, int k) n { n     return 1ll * fact[n] * ifact[k] % mod * ifact[n - k] % mod; n } n void solve() n { n     FOR( i, 1, n - 1) k += idx[a[i] + 1] < idx[a[i + 1] + 1]; n     if(n > k) n     { n         cout << 0; n         return; n     } n     fact[0] = 1; n     FOR( i, 1, k) fact[i] = (1ll * fact[i - 1] * i) % mod; n     ifact[k] = Pow(fact[k], mod - 2); n     FOD( i, k - 1, 0) ifact[i] = 1ll * (i + 1) * ifact[i + 1] % mod; n     cout << nCk(k, n); n } n int main() n { n     ios_base::sync_with_stdio(0); n     cin.tie(0); n     cout.tie(0); n //    freopen(task .inp , r ,stdin); n //    freopen(task .out , w ,stdout); n     inp(); n     solve(); n     return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename _T> n inline void read(_T &f) { n   f = 0; n   _T fu = 1; n   char c = getchar(); n   while (c <  0  || c >  9 ) { n     if (c ==  - ) fu = -1; n     c = getchar(); n   } n   while (c >=  0  && c <=  9 ) { n     f = (f << 3) + (f << 1) + (c & 15); n     c = getchar(); n   } n   f *= fu; n } n template <typename T> n void print(T x) { n   if (x < 0) putchar( - ), x = -x; n   if (x < 10) n     putchar(x + 48); n   else n     print(x / 10), putchar(x % 10 + 48); n } n template <typename T> n void print(T x, char t) { n   print(x); n   putchar(t); n } n template <typename T> n struct hash_map_t { n   vector<T> v, val, nxt; n   vector<int> head; n   int mod, tot, lastv; n   T lastans; n   bool have_ans; n   hash_map_t(int md = 0) { n     head.clear(); n     v.clear(); n     val.clear(); n     nxt.clear(); n     tot = 0; n     mod = md; n     nxt.resize(1); n     v.resize(1); n     val.resize(1); n     head.resize(mod); n     have_ans = 0; n   } n   bool count(int x) { n     int u = x % mod; n     for (register int i = head[u]; i; i = nxt[i]) { n       if (v[i] == x) { n         have_ans = 1; n         lastv = x; n         lastans = val[i]; n         return 1; n       } n     } n     return 0; n   } n   void ins(int x, int y) { n     int u = x % mod; n     nxt.push_back(head[u]); n     head[u] = ++tot; n     v.push_back(x); n     val.push_back(y); n   } n   int qry(int x) { n     if (have_ans && lastv == x) return lastans; n     count(x); n     return lastans; n   } n }; n const int N = 755, MAXN = 1e7 + 5; n queue<int> q; n char c[MAXN]; n vector<int> adj[N << 1]; n int ch[MAXN][2], fail[MAXN], id[MAXN], l[N], r[N], pre[N << 1], used[N << 1], n     vis[N << 1]; n int f[N][N], n, len, tot, dfn, ans; n int dfs1(int u) { n   for (register unsigned i = 0; i < adj[u].size(); i++) { n     int v = adj[u][i]; n     if (used[v] != dfn) { n       used[v] = dfn; n       if (!pre[v] || dfs1(pre[v])) { n         pre[v] = u; n         pre[u] = v; n         return 1; n       } n     } n   } n   return 0; n } n void dfs2(int u) { n   vis[u] = 1; n   for (register unsigned i = 0; i < adj[u].size(); i++) { n     int v = adj[u][i]; n     if (!vis[v] && pre[v]) vis[v] = 1, dfs2(pre[v]); n   } n } n int main() { n   read(n); n   for (register int i = 1; i <= n; i++) { n     scanf( %s , c + r[i - 1] + 1); n     len = strlen(c + r[i - 1] + 1); n     l[i] = r[i - 1] + 1; n     r[i] = l[i] + len - 1; n     int now = 0; n     for (register int j = l[i]; j <= r[i]; j++) { n       int x = c[j] -  a ; n       if (!ch[now][x]) ch[now][x] = ++tot; n       now = ch[now][x]; n     } n     id[now] = i; n   } n   for (register int i = 0; i <= 1; i++) n     if (ch[0][i]) q.push(ch[0][i]); n   while (!q.empty()) { n     int u = q.front(); n     q.pop(); n     for (register int i = 0; i <= 1; i++) { n       int v = ch[u][i]; n       if (!v) continue; n       int now = fail[u], last = 1; n       while (last) { n         if (ch[now][i]) { n           fail[v] = ch[now][i]; n           break; n         } n         last = now; n         now = fail[now]; n       } n       if (!id[v]) id[v] = id[fail[v]]; n       q.push(v); n     } n   } n   for (register int i = 1; i <= n; i++) { n     int now = 0; n     for (register int j = l[i]; j <= r[i]; j++) { n       int x = c[j] -  a ; n       now = ch[now][x]; n       if (j == r[i]) n         f[i][id[fail[now]]] = 1; n       else n         f[i][id[now]] = 1; n     } n   } n   for (register int k = 1; k <= n; k++) { n     for (register int i = 1; i <= n; i++) { n       for (register int j = 1; j <= n; j++) { n         f[i][j] |= (f[i][k] & f[k][j]); n       } n     } n   } n   for (register int i = 1; i <= n; i++) { n     for (register int j = 1; j <= n; j++) { n       if (f[i][j]) { n         adj[i].push_back(j + n); n         adj[j + n].push_back(i); n       } n     } n   } n   ans = n; n   for (register int i = 1; i <= n; i++) n     if (!pre[i]) ++dfn, ans -= dfs1(i); n   print(ans,   n ); n   for (register int i = 1; i <= n; i++) n     if (!pre[i]) dfs2(i); n   for (register int i = 1; i <= n; i++) n     if (vis[i] && !vis[i + n]) print(i,    ); n   putchar(  n ); n   return 0; n } n


#include <bits/stdc++.h> n int main() { n   int arr[1000], n, i, j, k, counter = 99999999, x, y; n   scanf( %d , &n); n   for (i = 0; i < n; ++i) { n     scanf( %d , &arr[i]); n   } n   for (j = 1; j < n; ++j) { n     for (k = j - 1; k < j; ++k) { n       if (abs(arr[j] - arr[k]) < counter) { n         counter = abs(arr[j] - arr[k]); n         x = j + 1; n         y = k + 1; n       } n     } n   } n   if (abs(arr[0] - arr[n - 1]) < counter) { n     counter = abs(arr[0] - arr[n - 1]); n     x = 1; n     y = n; n   } n   printf( %d %d , y, x); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MOD = 1e9 + 7; n const int eps = -1e6; n const int MAX = 200010; n long long int n, k, x; n long long int a[MAX], pre[MAX], s[MAX]; n long long int expo(long long int a, long long int b) { n   long long int x = 1, y = a; n   while (b > 0) { n     if (b & 1) x = (x * y); n     y = (y * y); n     b >>= 1; n   } n   return x; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin >> n >> k >> x; n   for (int i = 0, _n = (n); i < _n; ++i) { n     cin >> a[i]; n     if (i == 0) n       pre[i] = a[i]; n     else n       pre[i] = pre[i - 1] | a[i]; n   } n   for (int i = n - 1; i >= 0; i--) { n     if (i == n - 1) n       s[i] = a[i]; n     else n       s[i] = s[i + 1] | a[i]; n   } n   long long int tmp = expo(x, k); n   long long int res = 0; n   for (int i = 0, _n = (n); i < _n; ++i) { n     long long int z = a[i] * 1ll * tmp; n     if (i == 0) n       res = max(res, z | s[1]); n     else if (i == n - 1) n       res = max(res, pre[n - 2] | z); n     else n       res = max(res, pre[i - 1] | z | s[i + 1]); n   } n   cout << res << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int arr[100000]; n int pre[100000]; n int leftMax; n int main() { n   ios_base ::sync_with_stdio(false); n   cin.tie(NULL); n   ; n   int t; n   cin >> t; n   while (t--) { n     int maxLen = 0; n     int n, x; n     cin >> n >> x; n     for (int i = 0; i < n; i++) cin >> arr[i]; n     pre[0] = arr[0]; n     for (int i = 1; i < n; i++) pre[i] = arr[i] + pre[i - 1]; n     leftMax = -1; n     for (int i = 0; i < n; i++) { n       pre[i] = pre[i] % x; n       if (pre[i] != 0) maxLen = i + 1; n       if (pre[i] != 0 && leftMax == -1) leftMax = i; n     } n     if (maxLen == 0) n       cout <<  -1 n ; n     else { n       int finalLen = maxLen; n       for (int i = 0; i < n; i++) { n         if (pre[i] == 0) n           finalLen = max(finalLen, max(abs(i - leftMax), abs(i - maxLen))); n       } n       cout << finalLen <<   n ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using ll = long long; n constexpr int INF = 1073741823; n constexpr int MINF = -1073741823; n constexpr ll LINF = ll(4661686018427387903); n constexpr ll MOD = 1000000007; n const long double PI = acosl(-1.0L); n using namespace std; n void scans(string& str) { n   char c; n   str =   ; n   scanf( %c , &c); n   if (c ==   n ) scanf( %c , &c); n   while (c !=   n  && c != -1 && c !=    ) { n     str += c; n     scanf( %c , &c); n   } n } n void scanc(char& str) { n   char c; n   scanf( %c , &c); n   if (c == -1) return; n   while (c ==   n ) { n     scanf( %c , &c); n   } n   str = c; n } n double acot(double x) { return PI / 2 - atan(x); } n ll LSB(ll n) { return (n & (-n)); } n ll p(ll a) { return a * a; } n int main() { n   int t; n   scanf( %d , &t); n   while (t--) { n     int r, g, b; n     scanf( %d%d%d , &r, &g, &b); n     vector<int> R(r), G(g), B(b); n     for (int i = 0; i < (r); ++i) scanf( %d , &R[i]); n     for (int i = 0; i < (g); ++i) scanf( %d , &G[i]); n     for (int i = 0; i < (b); ++i) scanf( %d , &B[i]); n     sort((R).begin(), (R).end()); n     sort((G).begin(), (G).end()); n     sort((B).begin(), (B).end()); n     ll ans = LINF; n     for (int i = 0; i < (r); ++i) { n       auto itegreen1 = lower_bound((G).begin(), (G).end(), R[i]), n            iteblue1 = lower_bound((B).begin(), (B).end(), R[i]); n       ll green1 = -1; n       if (itegreen1 != G.end()) n         green1 = *itegreen1; n       else n         green1 = G[G.size() - 1]; n       if (itegreen1 != G.begin()) --itegreen1; n       ll green2 = -1; n       if (itegreen1 != G.begin()) n         green2 = *itegreen1; n       else n         green2 = G[0]; n       ll blue1 = -1; n       if (iteblue1 != B.end()) n         blue1 = *iteblue1; n       else n         blue1 = B[B.size() - 1]; n       if (iteblue1 != B.begin()) --iteblue1; n       ll blue2 = -1; n       if (iteblue1 != B.begin()) n         blue2 = *iteblue1; n       else n         blue2 = B[0]; n       ans = n           min<ll>({(green1 != -1 and blue1 != -1) n                        ? p(green1 - R[i]) + p(R[i] - blue1) + p(blue1 - green1) n                        : LINF, n                    (green2 != -1 and blue1 != -1) n                        ? p(green2 - R[i]) + p(R[i] - blue1) + p(blue1 - green2) n                        : LINF, n                    (green1 != -1 and blue2 != -1) n                        ? p(green1 - R[i]) + p(R[i] - blue2) + p(blue2 - green1) n                        : LINF, n                    (green2 != -1 and blue2 != -1) n                        ? p(green2 - R[i]) + p(R[i] - blue2) + p(blue2 - green2) n                        : LINF, n                    ans}); n     } n     for (int i = 0; i < (g); ++i) { n       auto itered1 = lower_bound((R).begin(), (R).end(), G[i]), n            iteblue1 = lower_bound((B).begin(), (B).end(), G[i]); n       ll red1 = -1; n       if (itered1 != R.end()) n         red1 = *itered1; n       else n         red1 = R[R.size() - 1]; n       if (itered1 != R.begin()) --itered1; n       ll red2 = -1; n       if (itered1 != R.begin()) n         red2 = *itered1; n       else n         red2 = R[0]; n       ll blue1 = -1; n       if (iteblue1 != B.end()) n         blue1 = *iteblue1; n       else n         blue1 = B[B.size() - 1]; n       if (iteblue1 != B.begin()) --iteblue1; n       ll blue2 = -1; n       if (iteblue1 != B.begin()) n         blue2 = *iteblue1; n       else n         blue2 = B[0]; n       ans = min<ll>({(red1 != -1 and blue1 != -1) n                          ? p(red1 - G[i]) + p(G[i] - blue1) + p(blue1 - red1) n                          : LINF, n                      (red2 != -1 and blue1 != -1) n                          ? p(red2 - G[i]) + p(G[i] - blue1) + p(blue1 - red2) n                          : LINF, n                      (red1 != -1 and blue2 != -1) n                          ? p(red1 - G[i]) + p(G[i] - blue2) + p(blue2 - red1) n                          : LINF, n                      (red2 != -1 and blue2 != -1) n                          ? p(red2 - G[i]) + p(G[i] - blue2) + p(blue2 - red2) n                          : LINF, n                      ans}); n     } n     for (int i = 0; i < (b); ++i) { n       auto itered1 = lower_bound((R).begin(), (R).end(), B[i]), n            itegreen1 = lower_bound((G).begin(), (G).end(), B[i]); n       ll green1 = -1; n       if (itegreen1 != G.end()) n         green1 = *itegreen1; n       else n         green1 = G[G.size() - 1]; n       if (itegreen1 != G.begin()) --itegreen1; n       ll green2 = -1; n       if (itegreen1 != G.begin()) n         green2 = *itegreen1; n       else n         green2 = G[0]; n       ll red1 = -1; n       if (itered1 != R.end()) n         red1 = *itered1; n       else n         red1 = R[R.size() - 1]; n       if (itered1 != R.begin()) --itered1; n       ll red2 = -1; n       if (itered1 != R.begin()) n         red2 = *itered1; n       else n         red2 = R[0]; n       ans = min<ll>({(red1 != -1 and green1 != -1) n                          ? p(red1 - B[i]) + p(B[i] - green1) + p(green1 - red1) n                          : LINF, n                      (red2 != -1 and green1 != -1) n                          ? p(red2 - B[i]) + p(B[i] - green1) + p(green1 - red2) n                          : LINF, n                      (red1 != -1 and green2 != -1) n                          ? p(red1 - B[i]) + p(B[i] - green2) + p(green2 - red1) n                          : LINF, n                      (red2 != -1 and green2 != -1) n                          ? p(red2 - B[i]) + p(B[i] - green2) + p(green2 - red2) n                          : LINF, n                      ans}); n     } n     printf( %lld n , ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct cmp { n   bool operator()(long long a, long long b) { return a > b; } n }; n multiset<long long> mex, msy; n multiset<long long, cmp> msx, mey; n int main() { n   long long n; n   cin >> n; n   long long sx[n], ex[n], sy[n], ey[n]; n   for (long long i = 0; i < n; i++) { n     cin >> sx[i] >> ey[i] >> ex[i] >> sy[i]; n     msx.insert(sx[i]); n     mex.insert(ex[i]); n     msy.insert(sy[i]); n     mey.insert(ey[i]); n   } n   for (long long i = 0; i < n; i++) { n     msx.erase(msx.find(sx[i])); n     mex.erase(mex.find(ex[i])); n     msy.erase(msy.find(sy[i])); n     mey.erase(mey.find(ey[i])); n     if (*msx.begin() <= *mex.begin() && *msy.begin() >= *mey.begin()) { n       cout << *msx.begin() <<     << *msy.begin() << endl; n       return 0; n     } n     msx.insert(sx[i]); n     mex.insert(ex[i]); n     msy.insert(sy[i]); n     mey.insert(ey[i]); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m; n   cin >> n >> m; n   pair<int, int> cc[105]; n   for (int i = 1; i <= m; i++) { n     int a, b, c, d; n     cin >> a >> b >> c >> d; n     for (int j = a; j <= b; j++) { n       if (!cc[j].first || c < cc[j].first) { n         cc[j].first = c; n         cc[j].second = d; n       } n     } n   } n   int ans = 0; n   for (int i = 1; i <= n; i++) ans += cc[i].second; n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, m; n long long q_pow(long long a, long long b, long long c) { n   if (b == 0) return 1; n   long long ret = q_pow(a, b / 2, c); n   ret = (ret * ret) % c; n   if (b & 1) ret = (ret * a) % c; n   return ret; n } n int main() { n   scanf( %d%d , &n, &m); n   long long ans = (q_pow(3, n, m) + m - 1) % m; n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const char nl =   n ; n const int mod = 1000000007; n const double pi = 4 * atan(1); n const int inf = 2000000000; n const long long linf = (long long)1e18; n const int pr = 37; n const int maxn = 1000001; n const int maxn_big = 1000001; n string s; n vector<int> v; n unsigned long long h[maxn], p[maxn]; n unsigned long long get_hash(int l, int r) { n   int len = (r - l) + 1; n   if (!l) return h[r]; n   return h[r] - h[l - 1] * p[len]; n } n bool check(int pf) { n   unsigned long long pref_hash = get_hash(0, pf); n   bool has_ans = 0; n   for (int i = 1; i < ((int)(s.size())) - 1; ++i) { n     int r = i + pf; n     if (r >= ((int)(s.size())) - 1) break; n     if (get_hash(i, r) == pref_hash) { n       has_ans = 1; n       break; n     } n   } n   return has_ans; n } n int main() { n   ios_base ::sync_with_stdio(0); n   cin.tie(0); n   srand(time(NULL)); n   cin >> s; n   h[0] = s[0]; n   p[0] = 1; n   for (int i = 1; i < ((int)(s.size())); ++i) { n     h[i] = h[i - 1] * pr + s[i]; n     p[i] = p[i - 1] * pr; n   } n   for (int i = 0; i < ((int)(s.size())); ++i) { n     int l = ((int)(s.size())) - 1 - i; n     if (get_hash(0, i) == get_hash(l, ((int)(s.size())) - 1)) v.push_back(i); n   } n   if (!((int)(v.size()))) { n     cout <<  Just a legend ; n     return 0; n   } n   int l = -1, r = ((int)(v.size())); n   bool has = 0; n   while (r - l > 1) { n     int mid = (r + l) / 2; n     if (check(v[mid])) { n       l = mid; n       has = 1; n     } else { n       r = mid; n     } n   } n   if (!has) { n     cout <<  Just a legend ; n     return 0; n   } n   string res =   ; n   for (int i = 0; i <= v[l]; ++i) res += s[i]; n   cout << res; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 25; n int main(int argc, char *argv[]) { n   long long n; n   cin >> n; n   long long ret1 = (1LL << 60); n   long long ret2 = 0; n   for (long long x = 1; x * x <= n; ++x) { n     if (n % x) continue; n     long long m = n / x; n     for (long long y = 1; y * y <= m; ++y) { n       if ((n / x) % y) continue; n       long long z = m / y; n       long long a = x + 1; n       long long b = y + 2; n       long long c = z + 2; n       ret1 = min(a * b * c - n, ret1); n       ret2 = max(a * b * c - n, ret2); n       b = x + 2; n       c = z + 2; n       a = y + 1; n       ret1 = min(a * b * c - n, ret1); n       ret2 = max(a * b * c - n, ret2); n       a = z + 1; n       b = x + 2; n       c = y + 2; n       ret1 = min(a * b * c - n, ret1); n       ret2 = max(a * b * c - n, ret2); n     } n   } n   cout << ret1 <<     << ret2 <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /STACK:1000000000 ) n using namespace std; n inline void solve(); n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   solve(); n } n string abc =  abcdefghijklmnopqrstuvwxyz ; n string ABC =  ABCDEFGHIJKLMNOPQRSTUVWXYZ ; n string digits =  0123456789 ; n void solve() { n   vector<long long> ind[30]; n   string s; n   cin >> s; n   long long n = s.length(); n   for (long long i = 0; i < n; i++) ind[s[i] -  a ].push_back(i); n   double ans = 0; n   s = s + s; n   long long p[30] = {0}; n   for (long long i = 0; i < 26; i++) { n     for (long long len = 1; len < n; len++) { n       long long c[30] = {0}; n       for (long long l = 0; l < ind[i].size(); l++) { n         c[s[ind[i][l] + len] -  a ]++; n       } n       long long cnt = 0; n       for (long long j = 0; j < 30; j++) n         if (c[j] == 1) cnt++; n       p[i] = max(p[i], cnt); n     } n     ans += p[i] * 1. / n; n   } n   cout << setprecision(15) << fixed << ans; n } n


#include <bits/stdc++.h> n using namespace std; n void qmax(long long &x, long long y) { n   if (x < y) x = y; n } n void qmin(long long &x, long long y) { n   if (x > y) x = y; n } n inline long long read() { n   char s; n   long long k = 0, base = 1; n   while ((s = getchar()) !=  -  && s != EOF && !(isdigit(s))) n     ; n   if (s == EOF) exit(0); n   if (s ==  - ) base = -1, s = getchar(); n   while (isdigit(s)) { n     k = k * 10 + (s ^  0 ); n     s = getchar(); n   } n   return k * base; n } n inline void write(long long x) { n   static char cnt, num[15]; n   cnt = 0; n   if (!x) { n     putchar( 0 ); n     return; n   } n   for (; x; x /= 10) num[++cnt] = x % 10; n   for (; cnt; putchar(num[cnt--] + 48)) n     ; n } n const long long maxn = 100000 + 100; n long long n, d, b, d1; n long long a[maxn]; n long long s1[maxn], s2[maxn]; n signed main() { n   n = read(); n   d = read(); n   b = read(); n   d1 = n / 2 * b; n   for (long long i = 1; i <= n; i++) a[i] = read(); n   for (long long i = 1; i <= n; i++) { n     s1[i] = min(a[i], d1) + s1[i - 1]; n     d1 -= min(d1, a[i]); n   } n   d1 = n / 2 * b; n   for (long long i = n; i >= 1; i--) { n     s2[i] = min(a[i], d1) + s2[i + 1]; n     d1 -= min(d1, a[i]); n   } n   d1 = 0; n   long long R = n / 2, r = 0, ans1 = 0, ans2 = 0; n   for (long long i = 1; i <= R; i++) { n     r += d + 1; n     r = min(n, r); n     if (d1 + b <= s1[r]) n       d1 += b; n     else n       ans1++; n   } n   R = (n + 1) / 2 + 1; n   d1 = 0; n   r = 0; n   long long l = n + 1; n   for (long long i = n; i >= R; i--) { n     l -= d + 1; n     l = max(1ll, l); n     if (d1 + b <= s2[l]) n       d1 += b; n     else n       ans2++; n   } n   cout << max(ans1, ans2); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int t, n, d, x, y, javab1, javab2, ans[1000]; n   cin >> t; n   for (int i = 0; i < t; i++) { n     cin >> n >> x >> y >> d; n     javab1 = javab2 = n; n     if ((y - x) % d == 0) { n       ans[i] = ((abs(y - x)) / d); n     } else if ((y - 1) % d == 0 || (n - y) % d == 0) { n       if ((n - y) % d == 0) { n         javab1 = (n - x + d - 1) / d; n         javab1 += (n - y) / d; n       } n       if ((y - 1) % d == 0) { n         javab2 = (x - 1 + d - 1) / d; n         javab2 += (y - 1) / d; n       } n       ans[i] = (min(javab2, javab1)); n     } else { n       ans[i] = -1; n     } n   } n   for (int i = 0; i < t; i++) { n     cout << ans[i] << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using gg = long long; n constexpr gg MAX = 1e6 + 5; n constexpr gg mod = 1e9 + 7; n constexpr gg INF = 1e10; n constexpr double thre = 1e-7; n gg ti, ni, mi, ki, di, pi, xi, yi; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   ti = 1; n   cin >> ti; n   while (ti--) { n     string a, b; n     cin >> ni >> a >> b; n     map<char, set<char>> m; n     for (gg i = 0; i < ni; ++i) { n       if (a[i] != b[i]) { n         m[a[i]].insert(b[i]); n       } n     } n     gg ans = 0; n     bool f = true; n     while (not m.empty()) { n       auto& [i, j] = *m.begin(); n       if (*j.begin() < i) { n         f = false; n         break; n       } n       if (j.size() != 1) { n         for (auto k = next(j.begin()); k != j.end(); ++k) { n           m[*j.begin()].insert(*k); n         } n       } n       m.erase(m.begin()); n       ans++; n     } n     cout << (f ? ans : -1) <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, s, h, m, qh, qm, qhm, d; n   cin >> n >> s; n   qh = 0, qm = 0; n   qhm = 0; n   for (int i = 0; i < n; i++) { n     cin >> h >> m; n     d = h * 60 + m; n     if (i == 0 && d >= s + 1) { n       cout << 0 <<     << 0; n       return 0; n     } n     if (d - qhm >= 2 * s + 2) { n       qhm += s + 1; n       cout << qhm / 60 <<     << qhm % 60; n       return 0; n     } n     qhm = d; n   } n   qhm += s + 1; n   cout << qhm / 60 <<     << qhm % 60; n } n


#include <bits/stdc++.h> n using namespace std; n long long gcd(long long a, long long b) { return (a ? gcd(b % a, a) : b); } n long long power(long long a, long long n) { n   long long p = 1; n   while (n > 0) { n     if (n % 2) { n       p = p * a; n     } n     n >>= 1; n     a *= a; n   } n   return p; n } n const int maxN = 3000; n int dist[maxN + 10][maxN + 10], n, m, a, b, s[2], t[2], l[2], ans; n vector<int> e[maxN + 10]; n void bfs(int u) { n   memset(dist[u], -1, sizeof(dist[u])); n   dist[u][u] = 0; n   queue<int> q; n   q.push(u); n   while (!q.empty()) { n     int x = q.front(); n     q.pop(); n     for (int i = 0; i < e[x].size(); i++) { n       int y = e[x][i]; n       if (dist[u][y] == -1) { n         dist[u][y] = dist[u][x] + 1; n         q.push(y); n       } n     } n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin >> n >> m; n   for (int i = 0; i < m; i++) { n     cin >> a >> b; n     a--; n     b--; n     e[a].push_back(b); n     e[b].push_back(a); n   } n   for (int i = 0; i < 2; i++) { n     cin >> s[i] >> t[i] >> l[i]; n     s[i]--; n     t[i]--; n   } n   for (int i = 0; i < n; i++) { n     bfs(i); n   } n   if (dist[s[0]][t[0]] > l[0] || dist[s[1]][t[1]] > l[1]) return cout << -1, 0; n   ans = dist[s[0]][t[0]] + dist[s[1]][t[1]]; n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < n; j++) { n       int d1 = dist[s[0]][i] + dist[i][j] + dist[j][t[0]]; n       int d2 = dist[s[1]][i] + dist[i][j] + dist[j][t[1]]; n       if (d1 <= l[0] && d2 <= l[1]) { n         ans = min(ans, d1 + d2 - dist[i][j]); n       } n       d2 = dist[t[1]][i] + dist[i][j] + dist[j][s[1]]; n       if (d1 <= l[0] && d2 <= l[1]) { n         ans = min(ans, d1 + d2 - dist[i][j]); n       } n       d1 = dist[t[0]][i] + dist[i][j] + dist[j][s[0]]; n       if (d1 <= l[0] && d2 <= l[1]) { n         ans = min(ans, d1 + d2 - dist[i][j]); n       } n       d2 = dist[s[1]][i] + dist[i][j] + dist[j][t[1]]; n       if (d1 <= l[0] && d2 <= l[1]) { n         ans = min(ans, d1 + d2 - dist[i][j]); n       } n     } n   } n   cout << m - ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MOD = 1e9 + 7; n const int maxn = 2e3 + 1; n const int maxm = 2e3 + 1; n char a[maxn], b[maxn]; n int num[maxn]; n int m, d; n long long dp[maxn][maxm]; n int len; n int judge(const char* s, int lena) { n   int mod = 0; n   for (int i = 1; i <= lena; i++) { n     mod = (mod * 10 + s[i]) % m; n     if ((i & 1) == 0 && s[i] != d) { n       return 0; n     } n     if ((i & 1) && s[i] == d) return 0; n   } n   return (mod == 0); n } n int val[maxn]; n long long dfs(int pos, int mod, bool limit) { n   if (pos == len + 1) { n     return mod == 0; n   } n   if (!limit && dp[pos][mod] != -1) return dp[pos][mod]; n   int up = (limit ? num[pos] : 9); n   long long res = 0; n   for (int i = 0; i <= up; i++) { n     int tmod = (mod * 10 + i) % m; n     if ((pos & 1) && (i == d)) continue; n     if (!(pos & 1) && (i != d)) continue; n     res = (res + dfs(pos + 1, tmod, limit && i == up)) % MOD; n   } n   if (!limit) dp[pos][mod] = res; n   return res; n } n long long solve(const char* s, int lena) { n   for (int i = 1; i <= lena; i++) num[i] = s[i]; n   len = lena; n   memset(dp, -1, sizeof(dp)); n   return dfs(1, 0, true) % MOD; n } n int main() { n   cin >> m >> d; n   cin >> (a + 1); n   cin >> (b + 1); n   int lena = strlen(a + 1), lenb = strlen(b + 1); n   for (int i = 1; i <= lena; i++) a[i] -=  0 ; n   for (int i = 1; i <= lenb; i++) b[i] -=  0 ; n   cout << ((solve(b, lenb) - solve(a, lena) + judge(a, lena)) % MOD + MOD) % MOD n        << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long inf = LLONG_MAX; n struct minimum_cost_bipartite_matching { n   int nl, nr; n   long long mc = 0; n   vector<int> ml, mr, ly; n   minimum_cost_bipartite_matching(int nl, int nr, vector<vector<long long>> &c) n       : nl(nl), nr(nr), ml(nl, -1), mr(nr, -1), ly(nr) { n     vector<long long> s(nl), t(nr); n     for (int i = 0; i < nl; i++) { n       int x = i, y = -1; n       vector<bool> u(nr); n       vector<long long> md(nr, inf); n       while (x != -1) { n         long long ny = -1, d = inf; n         for (int j = 0; j < nr; j++) n           if (!u[j]) { n             long long v = c[x][j] - s[x] - t[j]; n             if (v < md[j]) md[j] = v, ly[j] = y; n             if (md[j] < d) d = md[j], ny = j; n           } n         s[i] += d; n         mc += d; n         for (int j = 0; j < nr; j++) n           if (u[j]) n             s[mr[j]] += d, t[j] -= d; n           else n             md[j] -= d; n         y = ny; n         u[y] = true; n         x = mr[y]; n       } n       while (y != -1) { n         mr[y] = ly[y] != -1 ? mr[ly[y]] : i; n         ml[mr[y]] = y; n         y = ly[y]; n       } n     } n   } n }; n int charToInt(char c) { return c >=  a  && c <=  z  ? c -  a  : c -  A  + 26; } n char intToChar(int c) { return c < 26 ?  a  + c :  A  + c - 26; } n int main() { n   int n, k; n   cin >> n >> k; n   string s[2]; n   cin >> s[0] >> s[1]; n   vector<vector<long long>> c(k, vector<long long>(k)); n   for (int i = 0; i < n; i++) c[charToInt(s[0][i])][charToInt(s[1][i])]--; n   minimum_cost_bipartite_matching mcbm(k, k, c); n   cout << -mcbm.mc <<   n ; n   for (int i = 0; i < k; i++) cout << intToChar(mcbm.ml[i]); n   cout <<   n ; n } n


#include <bits/stdc++.h> n #pragma GCC target( avx,avx2,fma ) n #pragma GCC optimization( O8 ) n #pragma GCC optimization( unroll-loops ) n using namespace std; n const long long int N = 4e6 + 20, mod = 1e9 + 7, inf = 1e9, dlt = 12250, n                     maxm = 2e6; n int poww(long long a, int k) { n   if (!k) return 1; n   if (k == 1) return a; n   long long r = poww(a, k / 2); n   return (((r * r) % mod) * poww(a, k & 1)) % mod; n } n int trie[N][3], cnt; n long long a[N / 10]; n void build(string s) { n   int p = 0; n   string t =   ; n   for (char ch : s) { n     int u = ch -  0 ; n     t += ch; n     if (!trie[p][u]) { n       cnt++; n       trie[p][u] = cnt; n     } n     p = trie[p][u]; n   } n } n long long que(long long x) { n   int p = 0, h = 0; n   long long y = 0; n   for (int i = 0; i < 40; i++) { n     if (!trie[p][0] && !trie[p][1]) return y; n     bool f = (!(x & (1ll << (39 - i)))); n     if (!trie[p][0] || (trie[p][1] && f)) { n       if (f) y += (1ll << (39 - i)); n       p = trie[p][1]; n       continue; n     } n     if (!f) y += (1ll << (39 - i)); n     p = trie[p][0]; n   } n   return y; n } n int main() { n   ios ::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int n; n   long long x = 0; n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n     x ^= a[i]; n   } n   long long ans = x; n   string st =   ; n   for (int i = 0; i < 40; i++) st +=  0 ; n   build(st); n   long long y = 0; n   for (int i = 0; i < n; i++) { n     x ^= a[i]; n     y ^= a[i]; n     string s =   ; n     for (int j = 0; j < 40; j++) { n       if (y & (1ll << j)) n         s =  1  + s; n       else n         s =  0  + s; n     } n     build(s); n     ans = max(que(x), ans); n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename Arg1> n void __f(const char* name, Arg1&& arg1) { n   cerr << name <<   :   << arg1 << std::endl; n } n template <typename Arg1, typename... Args> n void __f(const char* names, Arg1&& arg1, Args&&... args) { n   const char* comma = strchr(names + 1,  , ); n   cerr.write(names, comma - names) <<   :   << arg1 <<   |  ; n   __f(comma + 1, args...); n } n int main() { n   long long a, b; n   scanf( %lld , &a); n   scanf( %lld , &b); n   while (a > 0 && b > 0 && (a >= 2 * b || b >= 2 * a)) n     if (a >= 2 * b) n       a %= 2 * b; n     else n       b %= 2 * a; n   printf( %lld %lld n , a, b); n } n


#include <bits/stdc++.h> n using namespace std; n void boost() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n } n const long long mod = 1000000007; n int tablica[2]; n long long potega(long long base, long long pot) { n   if (pot == 0) return 1; n   if (pot == 1) return base; n   if (pot % 2 == 0) { n     long long res = potega(base, pot / 2); n     return ((res * res) % mod); n   } else n     return ((potega(base, pot - 1) * base) % mod); n } n int bs(int pocz, int kon, int szu) { n   int sr; n   while (pocz < kon) { n     sr = (pocz + kon) / 2; n     if (tablica[sr] >= szu) n       kon = sr; n     else n       pocz = sr + 1; n   } n   return pocz; n } n int n, k, a[1007], ile; n void reset_arrays() { ile = 0; } n void solve() { n   reset_arrays(); n   scanf( %d%d , &n, &k); n   for (int i = 0; i < n; i++) scanf( %d , &a[i]); n   sort(a, a + n); n   for (int i = 1; i < n; i++) { n     int pom = (k - a[i]) / a[0]; n     ile += pom; n   } n   printf( %d n , ile); n } n int main() { n   int t = 1; n   scanf( %d , &t); n   while (t--) solve(); 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 readInt() { 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 readCh() { n   readAhead(16); n   while (*stdinPos ==     || *stdinPos ==   n ) ++stdinPos; n   char ans = *stdinPos; n   ++stdinPos; n   return ans; n } n inline int rri() { n   char c; n   while (c = getchar(), c <=    ) n     ; n   bool sign = c ==  - ; n   if (sign) { n     c = getchar(); n   } n   int res = c -  0 ; n   while (c = getchar(), c >=  0  && c <=  9 ) { n     res = res * 10 + (c -  0 ); n   } n   return sign ? -res : res; n } n inline long long rrl() { n   char c; n   while (c = getchar(), c <=    ) n     ; n   bool sign = c ==  - ; n   if (sign) { n     c = getchar(); n   } n   long long res = c -  0 ; n   while (c = getchar(), c >=  0  && c <=  9 ) { n     res = res * 10 + (c -  0 ); n   } n   return sign ? -res : res; n } n inline char rrc() { n   char c; n   while (c = getchar(), c <=    ) n     ; n   return c; n } n inline int rrs(char *target) { n   char c; n   while (c = getchar(), c <=    ) n     ; n   int idx = -1; n   target[++idx] = c; n   while (1) { n     c = getchar(); n     if (c <=    ) { n       target[++idx] =   0 ; n       return idx; n     } n     target[++idx] = c; n   } n } n vector<vector<int> > matrixUnit(long long n) { n   vector<vector<int> > res(n, vector<int>(n)); n   for (long long i = 0; i < n; i++) res[i][i] = 1; n   return res; n } n vector<vector<int> > matrixMul(const vector<vector<int> > &a, n                                const vector<vector<int> > &b) { n   long long n = a.size(); n   long long m = a[0].size(); n   long long k = b[0].size(); n   vector<vector<int> > res(n, vector<int>(k)); n   for (long long i = 0; i < n; i++) n     for (long long j = 0; j < k; j++) n       for (long long p = 0; p < m; p++) n         res[i][j] = (res[i][j] + (long long)a[i][p] * b[p][j]) % 1000000007LL; n   return res; n } n void matrixMult(vector<vector<int> > &res, const vector<vector<int> > &a, n                 const vector<vector<int> > &b) { n   long long n = a.size(); n   long long m = a[0].size(); n   long long k = b[0].size(); n   for (long long i = 0; i < n; i++) n     for (long long j = 0; j < k; j++) { n       long long ans = 0; n       for (long long p = 0; p < m; p++) n         ans = (ans + (long long)a[i][p] * b[p][j]) % 1000000007LL; n       res[i][j] = ans; n     } n } n const int mn = 2004; n bitset<mn> g[mn]; n bool bf(int n) { n   vector<vector<int> > inp; n   inp.resize(n); n   for (int x = 0; x < n; x++) { n     inp[x].resize(n); n     for (int y = 0; y < n; y++) inp[x][y] = g[x][y]; n   } n   vector<vector<int> > a = inp; n   for (int k = 0; k < 500; k++) { n     bool ok = 1; n     for (int i = 0; i < n; i++) n       for (int j = 0; j < n; j++) { n         if (a[i][j] == 0) { n           ok = 0; n           break; n         } n       } n     if (ok) return 1; n     a = matrixMul(a, inp); n   } n   return 0; n } n bitset<mn> h[mn]; n bitset<mn> seen; n bool solve2(int n) { n   queue<int> q; n   for (int x = 0; x < n; x++) { n     if (h[0][x]) q.push(x); n   } n   seen = h[0]; n   while (!q.empty()) { n     int x = q.front(); n     q.pop(); n     for (int y = 0; y < n; y++) { n       if ((!seen[y]) && h[x][y]) { n         q.push(y); n         seen[y] = true; n       } n     } n   } n   assert(seen.count() <= n); n   return (int)seen.count() == n; n } n bool solve(int n) { n   int spec = -1; n   for (int k = 0; k < n; k++) n     if (g[k][k]) spec = k; n   assert(spec != -1); n   for (int x = 0; x < n; x++) n     for (int y = 0; y < n; y++) { n       int sx = (x == spec || x == 0) ? x ^ spec : x; n       int sy = (y == spec || y == 0) ? y ^ spec : y; n       h[sx][sy] = g[x][y]; n     } n   assert(h[0][0]); n   if (!solve2(n)) return 0; n   for (int x = 0; x < n; x++) n     for (int y = 0; y < n; y++) { n       g[x][y] = h[y][x]; n     } n   for (int x = 0; x < n; x++) h[x] = g[x]; n   if (!solve2(n)) return 0; n   return 1; n } n void test() { n   srand(time(0) + clock() + rand()); n   for (int j = 0; j < 1000; j++) { n     int n = (rand() % 6) + 1; n     for (int x = 0; x < n; x++) { n       h[x].reset(); n       g[x].reset(); n       for (int y = 0; y < n; y++) g[x][y] = rand() & 1; n     } n     int k = rand() % n; n     g[k][k] = 1; n     bool b = bf(n); n     bool s = solve(n); n     if (b != s) { n       for (int x = 0; x < n; x++) { n         for (int y = 0; y < n; y++) printf( %d , (int)g[x][y]); n         printf(  n ); n       } n       printf( b:%d s:%d n , b, s); n     } n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   int n = readInt(); n   for (int x = 0; x < n; x++) n     for (int y = 0; y < n; y++) { n       int t = readInt(); n       t = (t > 0) ? 1 : 0; n       g[x][y] = t; n     } n   bool final = solve(n); n   if (final) n     printf( YES n ); n   else n     printf( NO n ); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long n, m; n   scanf( %lld%lld , &n, &m); n   long long t = m / 2; n   if (t >= n) { n     printf( 0 n ); n   } else { n     if (m % 2 == 1) { n       printf( %lld n , min(t, n - (t + 1) + 1)); n     } else { n       printf( %lld n , min(t - 1, n - (t + 1) + 1)); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long M = 3e4 + 1; n long long n, m, d; n const long long K = 3e4 + 5; n const long long huge = 1e15; n long long dp[K][500]; n long long a[K], ps[K]; n long long solve(long long i, long long j) { n   if (i >= M) return 0; n   long long jj = j - (d - 250); n   if (dp[i][jj] != -1) return dp[i][jj]; n   long long ans = 0; n   if (j != 1) n     ans = a[i] + max(solve(i + j, j), n                      max(solve(i + j + 1, j + 1), solve(i + j - 1, j - 1))); n   else n     ans = a[i] + max(solve(i + j, j), solve(i + j + 1, j + 1)); n   return dp[i][jj] = ans; n } n signed main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   ; n   cin >> n; n   cin >> d; n   while (n--) { n     cin >> m; n     a[m]++; n   } n   memset(dp, -1, sizeof dp); n   cout << a[0] + solve(d, d); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s; n   cin >> s; n   int n = s.length(); n   for (int i = 1; i < n - 1; i++) n     if (s[i] == s[i - 1] && s[i] == s[i + 1]) { n       if (s[i] ==  a ) n         s[i] =  b ; n       else n         s[i] =  a ; n     } n   for (int i = 1; i < n; i++) n     if (s[i] == s[i - 1]) { n       if (s[i] ==  a ) { n         if (i != n - 1 && s[i + 1] !=  b ) n           s[i] =  b ; n         else n           s[i] =  c ; n       } else if (s[i + 1] !=  a ) n         s[i] =  a ; n       else if (s[i] !=  b ) n         s[i] =  b ; n       else n         s[i] =  c ; n     } n   cout << s; n } n


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


#include <bits/stdc++.h> n using namespace std; n int n, m; n int main() { n   cin >> n >> m; n   if (n == 1) { n     cout << 1; n     exit(0); n   } n   cout << fixed << setprecision(12) n        << 1.0 / n + (1.0 * (n - 1)) / n * (1.0 * (m - 1)) / (m * n - 1); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   vector<pair<int, int> > p; n   int a[n + 1], b[n + 1]; n   for (int i = 1; i <= n; i++) cin >> a[i]; n   for (int i = 1; i <= n; i++) cin >> b[i]; n   for (int i = 1; i <= n; i++) { n     if (a[i] != b[i]) { n       for (int j = i + 1; j <= n; j++) { n         if (a[i] == b[j]) { n           for (int k = j; k > i; k--) { n             p.push_back(make_pair(k - 1, k)); n             swap(b[k], b[k - 1]); n           } n           break; n         } n       } n     } n   } n   cout << p.size() << endl; n   for (int i = 0; i < p.size(); i++) n     cout << p[i].first <<     << p[i].second << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int a[1002], b[1002], n, m; n   while (cin >> n >> m) { n     for (int i = 0; i < n; i++) cin >> a[i]; n     for (int i = 0; i < n; i++) cin >> b[i]; n     double be = m; n     bool flag = 0; n     for (int i = n - 1; i >= 0; i--) { n       be = be * b[(i + 1) % n] / (b[(i + 1) % n] - 1); n       if (be > 1000000000) { n         flag = 1; n         break; n       } n       be = be * a[i] / (a[i] - 1); n     } n     if (flag) n       cout << -1 << endl; n     else n       cout << fixed << setprecision(10) << be - m << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long int power(long long int a, long long int b) { n   a %= 1000000007; n   long long int res = 1; n   while (b > 0) { n     if (b & 1) res = res * a % 1000000007; n     a = a * a % 1000000007; n     b >>= 1; n   } n   return res; n } n long long int modinv(long long int p) { return power(p, 1000000007 - 2); } n vector<long long int> arr[200000]; n long long int dp[100005][2] = {0}; n void dfs(long long int s, long long int p, long long int a[]) { n   if (a[s] == 0) { n     long long int su = 1; n     dp[s][1] = 0; n     for (auto it : arr[s]) { n       if (it != p) { n         dfs(it, s, a); n         su *= (dp[it][0] + dp[it][1]); n         su %= 1000000007; n       } n     } n     dp[s][0] = su % 1000000007; n     for (auto it : arr[s]) { n       if (it != p) { n         if (dp[it][0] + dp[it][1] > 0) { n           dp[s][1] += (dp[it][1] * n                        ((su * modinv(dp[it][0] + dp[it][1])) % 1000000007)) % n                       1000000007; n           dp[s][1] %= 1000000007; n         } n       } n     } n   } else { n     dp[s][0] = 0; n     dp[s][1] = 1; n     for (auto it : arr[s]) { n       if (it != p) { n         dfs(it, s, a); n         dp[s][1] *= (dp[it][0] + dp[it][1]) % 1000000007; n         dp[s][1] %= 1000000007; n       } n     } n   } n } n int main() { n   long long int n; n   cin >> n; n   long long int q; n   for (long long int x = 1; x < n; x++) { n     cin >> q; n     arr[q].push_back(x); n     arr[x].push_back(q); n   } n   long long int a[n]; n   for (int x = 0; x < n; x++) { n     cin >> a[x]; n   } n   dfs(0, -1, a); n   cout << dp[0][1] % 1000000007 <<   n ; n } n


#include <bits/stdc++.h> n const int N = 2e4 + 42, M = 1e6 + 61, LN = 16; n struct edge { n   int to, next, w; n } e[M << 1]; n int head[M], cnt = 1, nc; n void addedge(int x, int y, int z) { n   if (!y) return; n   e[++cnt] = (edge){y, x[head], z}, x[head] = cnt; n   e[++cnt] = (edge){x, y[head], 0}, y[head] = cnt; n } n int fa[N][LN], pt[N][LN], dep[N], eid[N]; n std::vector<std::pair<int, int> > g[N]; n void dfs(int x, int p) { n   x[fa][0] = p, x[pt][0] = ++nc; n   addedge(nc, x, 1e9); n   for (int i = 1; i < LN; i++) { n     x[fa][i] = x[fa][i - 1][fa][i - 1], x[pt][i] = ++nc; n     addedge(nc, x[pt][i - 1], 1e9), addedge(nc, x[fa][i - 1][pt][i - 1], 1e9); n   } n   for (auto [nx, id] : x[g]) n     if (nx != p) nx[eid] = id, nx[dep] = x[dep] + 1, dfs(nx, x); n } n int lca(int x, int y) { n   if (x[dep] < y[dep]) std::swap(x, y); n   for (int i = LN - 1; i >= 0; i--) n     if (x[fa][i][dep] >= y[dep]) x = x[fa][i]; n   if (x == y) return x; n   for (int i = LN - 1; i >= 0; i--) n     if (x[fa][i] != y[fa][i]) x = x[fa][i], y = y[fa][i]; n   return x[fa][0]; n } n int get(int x, int k) { n   for (int i = 0; i < LN; i++) n     if ((k >> i) & 1) x = x[fa][i]; n   return x; n } n void link(int p, int x, int y) { n   if (x == y) return; n   int sub = x[dep] - y[dep]; n   int k = 31 - __builtin_clz(sub); n   addedge(p, x[pt][k], 1e9); n   addedge(p, get(x, sub - (1 << k))[pt][k], 1e9); n } n int lv[M], cur[M]; n bool bfs(int s, int t) { n   memset(lv, 0, sizeof lv); n   std::queue<int> q; n   for (s[lv] = 1, q.push(s); !q.empty(); q.pop()) n     for (int x = q.front(), i = x[cur] = x[head], nx; i; i = e[i].next) n       if (!(nx = e[i].to)[lv] && e[i].w) nx[lv] = x[lv] + 1, q.push(nx); n   return t[lv]; n } n int dfs(int s, int t, int f) { n   if (s == t || !f) return f; n   int r = 0, tt; n   for (int &i = s[cur], nx; i; i = e[i].next) n     if ((nx = e[i].to)[lv] == s[lv] + 1 && n         (tt = dfs(nx, t, std::min(f, (int)e[i].w)))) { n       e[i].w -= tt, e[i ^ 1].w += tt, r += tt, f -= tt; n       if (!f) return r; n     } n   if (f) s[lv] = 0; n   return r; n } n int dinic(int s, int t) { n   int r = 0; n   while (bfs(s, t)) r += dfs(s, t, 1e9); n   return r; n } n bool vis[M]; n void dfs2(int x) { n   x[vis] = true; n   for (int i = x[head], nx; i; i = e[i].next) n     if (e[i].w && !(nx = e[i].to)[vis]) dfs2(nx); n } n std::vector<int> v1, v2; n int n, m, S, T, c_pt[N]; n int main() { n   scanf( %d%d , &n, &m), nc = n; n   for (int i = 1, x, y; i < n; i++) { n     scanf( %d%d , &x, &y); n     x[g].push_back({y, i}); n     y[g].push_back({x, i}); n   } n   dep[1] = 1, dfs(1, 0); n   S = ++nc, T = ++nc; n   for (int i = 1; i <= n; i++) addedge(i, T, 1); n   for (int i = 1, x, y; i <= m; i++) { n     scanf( %d%d , &x, &y); n     int l = lca(x, y), p = ++nc; n     c_pt[i] = p; n     addedge(S, p, 1); n     link(p, x, l), link(p, y, l); n   } n   printf( %d n , dinic(S, T)); n   dfs2(S); n   for (int i = 1; i <= m; i++) n     if (!c_pt[i][vis]) v1.push_back(i); n   for (int i = 2; i <= n; i++) n     if (i[vis]) v2.push_back(eid[i]); n   printf( %lu , v1.size()); n   for (int i : v1) printf(  %d , i); n   puts(  ); n   printf( %lu , v2.size()); n   for (int i : v2) printf(  %d , i); n   puts(  ); n } n


#include <bits/stdc++.h> n using namespace std; n const double one = 1.0; n const double PI = 3.14159265; n const long long maxn = 2e3 + 10; n const long long maxx = 1e6 + 10; n const long double eps = 1e-14; n const long long max_len = 1e6 + 1; n const long long mod1 = 1000000007; n const long long mod2 = 998244353; n long long dp[maxn][maxn]; n void solve() { n   long long n, k; n   cin >> n >> k; n   vector<long long> vl(n + 2); n   for (long long i = 1; i < long long(n + 1); i++) cin >> vl[i]; n   for (long long i = 0; i < long long(n + 1); i++) { n     for (long long j = 0; j < long long(n + 1); j++) dp[i][j] = 0; n   } n   for (long long i = 1; i < long long(n + 1); i++) { n     for (long long j = 0; j < long long(i + 1); j++) { n       dp[i][j] = max(dp[i][j], dp[i - 1][j] + (i - j == vl[i])); n       if (j > 0) dp[i][j] = max(dp[i - 1][j - 1], dp[i][j]); n     } n   } n   long long ans = 1000000000000000000; n   for (long long j = 0; j < long long(n + 1); j++) { n     if (dp[n][j] >= k) ans = min(ans, j); n   } n   if (ans >= 1000000000000000000) ans = -1; n   cout << ans << endl; n   return; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cerr.tie(0); n   long long t; n   cin >> t; n   while (t--) solve(); n   return 0; n } n


#include <bits/stdc++.h> n int a, b, k; n int main() { n   scanf( %d%d%d , &b, &a, &k); n   if (b + k < a) { n     printf( %.12f n , 0.0f); n     return 0; n   } n   double ans = 1; n   for (int i = 0; i <= k; i++) { n     ans *= (a - i); n     ans /= (b + 1 + i); n   } n   ans = 1 - ans; n   printf( %.12f n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int SZ = (int)3e7 + 10; n int cnt[SZ]; n int n[3], t[3], sum[3]; n int main() { n   int k; n   cin >> k; n   for (int i = 0; i < 3; i++) cin >> n[i]; n   for (int i = 0; i < 3; i++) cin >> t[i]; n   for (int i = 0; i < 3; i++) sum[i] = 0; n   for (int tme = 0;; tme++) { n     int mn = k; n     for (int s = 0; s < 3; s++) { n       mn = min(mn, n[s] - sum[s]); n     } n     cnt[tme] = mn; n     k -= mn; n     if (k == 0) { n       printf( %d , tme + t[0] + t[1] + t[2]); n       return 0; n     } n     for (int s = 0; s < 3; s++) { n       sum[s] += mn; n       if (tme - t[s] + 1 >= 0) sum[s] -= cnt[tme - t[s] + 1]; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, k; n long double ans, eps = 1e-10, l, v1, v2; n bool solve(long double mid) { n   int x = (n + k - 1) / k; n   long double tl = mid, pos = l; n   while (x--) { n     if (tl < 0) return 0; n     long double trav = (v2 * v1 * tl - v2 * pos) / (v1 - v2); n     if (trav > pos) return 0; n     long double oldTime = tl; n     tl -= trav / v2 + (trav - v1 * trav / v2) / (v1 + v2); n     pos -= v1 * (oldTime - tl); n   } n   return 1; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cin >> n >> l >> v1 >> v2 >> k; n   double long hi = 1e10, lo = 0; n   while (hi - lo >= eps) { n     long double mid = (hi + lo) / 2; n     if (solve(mid)) { n       ans = mid; n       hi = mid - eps; n     } else n       lo = mid + eps; n   } n   cout << setprecision(12) << ans; n   solve(ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 3010; n const int MOD = 1000000007; n int n, m; n long long f[MAXN][MAXN], ans1, ans2, ans3, ans4; n char a[MAXN][MAXN]; n int main() { n   scanf( %d%d , &n, &m); n   for (int i = 1; i <= n; i++) scanf( %s , a[i] + 1); n   if (a[1][2] ==  . ) f[1][2] = 1; n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= m; j++) { n       if (i == 1 && j == 2) continue; n       if (a[i][j] ==  . ) f[i][j] = (f[i - 1][j] + f[i][j - 1]) % MOD; n     } n   ans1 = f[n - 1][m]; n   memset(f, 0, sizeof(f)); n   if (a[2][1] ==  . ) f[2][1] = 1; n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= m; j++) { n       if (i == 2 && j == 1) continue; n       if (a[i][j] ==  . ) f[i][j] = (f[i - 1][j] + f[i][j - 1]) % MOD; n     } n   ans2 = f[n][m - 1]; n   memset(f, 0, sizeof(f)); n   if (a[1][2] ==  . ) f[1][2] = 1; n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= m; j++) { n       if (i == 1 && j == 2) continue; n       if (a[i][j] ==  . ) f[i][j] = (f[i - 1][j] + f[i][j - 1]) % MOD; n     } n   ans3 = f[n][m - 1]; n   memset(f, 0, sizeof(f)); n   if (a[2][1] ==  . ) f[2][1] = 1; n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= m; j++) { n       if (i == 2 && j == 1) continue; n       if (a[i][j] ==  . ) f[i][j] = (f[i - 1][j] + f[i][j - 1]) % MOD; n     } n   ans4 = f[n - 1][m]; n   memset(f, 0, sizeof(f)); n   printf( %I64d n , ((ans1 * ans2) % MOD - (ans3 * ans4) % MOD + MOD) % MOD); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a[212345], s1[212345], s2[212345], pos1[212345], pos2[212345], n; n vector<pair<int, int> > res; n int main() { n   cin >> n; n   for (int i = 1; i <= n; i++) cin >> a[i]; n   for (int i = 1; i <= n; i++) { n     s1[i] = s1[i - 1] + (a[i] == 1); n     s2[i] = s2[i - 1] + (a[i] == 2); n   } n   for (int i = n; i >= 1; i--) { n     pos1[s1[i]] = i; n     pos2[s2[i]] = i; n   } n   for (int i = 1; i <= n; i++) pos1[s1[n] + i] = pos2[s2[n] + i] = n + 1; n   for (int t = 1; t <= n; t++) { n     int curPos = 0; n     int win1 = 0; n     int win2 = 0; n     while (curPos < n) { n       curPos = min(pos1[s1[curPos] + t], pos2[s2[curPos] + t]); n       if (curPos <= n) { n         if (a[curPos] == 1) n           win1++; n         else n           win2++; n       } n     } n     if (curPos == n && win1 != win2 && ((win1 > win2) == (a[curPos] == 1))) n       res.push_back(make_pair(max(win1, win2), t)); n   } n   sort(res.begin(), res.end()); n   cout << (int)res.size() << endl; n   for (int i = 0; i < (int)res.size(); i++) n     cout << res[i].first <<     << res[i].second << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int n; n   cin >> n; n   long long d = 0; n   for (int i = 9; n > 0; i *= 10) { n     d += n; n     n -= i; n   } n   cout << d << endl; n } n


#include <bits/stdc++.h> n using namespace std; n namespace FGF { n const int N = 1e5 + 5, mo = 1e9 + 7, inv2 = (mo + 1) / 2; n int a[N], b[N], pre[N], lst[N], nxt[N], sum[N << 2][4], ta[N << 2][2], n, st[N], n     tp, mi[N], mx[N], ans, cnt[N]; n void pushtag(int ro, int l, int r, int x, int o) { n   sum[ro][3] = 1ll * x * sum[ro][o ^ 1] % mo; n   sum[ro][o] = 1ll * (r - l + 1) * x % mo; n   ta[ro][o] = x; n   if (!o) sum[ro][2] = 1ll * (r + l) * (r - l + 1) % mo * inv2 % mo * x % mo; n } n void pushdown(int ro, int l, int r) { n   for (int i = 0; i <= 1; i++) n     if (ta[ro][i]) n       pushtag(ro << 1, l, ((l + r) >> 1), ta[ro][i], i), n           pushtag(ro << 1 | 1, ((l + r) >> 1) + 1, r, ta[ro][i], i), n           ta[ro][i] = 0; n } n void pushup(int ro) { n   for (int i = 0; i < 4; i++) n     sum[ro][i] = (sum[ro << 1][i] + sum[ro << 1 | 1][i]) % mo; n } n void updat(int ro, int l, int r, int L, int R, int x, int o) { n   if (L <= l && r <= R) return pushtag(ro, l, r, x, o); n   pushdown(ro, l, r); n   if (L <= ((l + r) >> 1)) updat(ro << 1, l, ((l + r) >> 1), L, R, x, o); n   if (R > ((l + r) >> 1)) updat(ro << 1 | 1, ((l + r) >> 1) + 1, r, L, R, x, o); n   pushup(ro); n } n int query(int ro, int l, int r, int L, int R, int o) { n   if (L <= l && r <= R) return sum[ro][o]; n   pushdown(ro, l, r); n   return ((L <= ((l + r) >> 1) ? query(ro << 1, l, ((l + r) >> 1), L, R, o) n                                : 0) + n           (R > ((l + r) >> 1) n                ? query(ro << 1 | 1, ((l + r) >> 1) + 1, r, L, R, o) n                : 0)) % n          mo; n } n void work() { n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) scanf( %d , &a[i]), b[i] = a[i]; n   sort(b + 1, b + n + 1); n   for (int i = 1; i <= n; i++) a[i] = lower_bound(b + 1, b + n + 1, a[i]) - b; n   for (int i = 1; i <= n; i++) pre[i] = lst[a[i]] + 1, lst[a[i]] = i; n   for (int i = n; i; i--) lst[i] = n + 1; n   for (int i = n; i; i--) nxt[i] = lst[a[i]] - 1, lst[a[i]] = i; n   for (int i = n; i; i--) { n     while (tp && pre[i] > pre[st[tp]]) tp--; n     mx[i] = tp ? st[tp] - 1 : n, st[++tp] = i; n   } n   tp = 0; n   for (int i = n; i; i--) { n     while (tp && nxt[i] < nxt[st[tp]]) tp--; n     mi[i] = tp ? st[tp] - 1 : n, st[++tp] = i; n   } n   for (int i = n, j = n; i; i--) { n     updat(1, 1, n, i, mx[i], pre[i], 0), updat(1, 1, n, i, mi[i], nxt[i], 1); n     cnt[a[i]]++; n     while (cnt[a[i]] > 1) cnt[a[j]]--, j--; n     ans = (ans + 1ll * i * query(1, 1, n, i, j, 1) % mo + n            query(1, 1, n, i, j, 2) - n            1ll * i * (i + j) % mo * (j - i + 1) % mo * inv2 % mo - n            query(1, 1, n, i, j, 3)) % n           mo; n   } n   printf( %d n , (ans + mo) % mo); n } n }  // namespace FGF n int main() { n   FGF::work(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 0x3f3f3f3f; n const double PI = 3.14159265; n const double E = 2.718281828459; n const double EPS = 1e-8; n const int M = 2e5 + 5; n long long n, A; n long long a[M]; n int main() { n   while (~scanf( %I64d %I64d , &n, &A)) { n     long long sumb = 0; n     for (int i = 0; i < n; i++) { n       scanf( %I64d , a + i); n       sumb += a[i]; n     } n     long long minb = n - 1; n     bool first = true; n     for (int i = 0; i < n; i++) { n       long long cnt = 0; n       long long x = A - minb; n       if (a[i] > x) cnt += a[i] - x; n       long long y = A - (sumb - a[i]); n       if (y > 0) cnt += y - 1; n       if (first) { n         printf( %I64d , cnt); n         first = false; n       } else n         printf(  %I64d , cnt); n     } n     printf(  n ); n   } n } n


#include <bits/stdc++.h> n using namespace std; n struct Node { n   int v; n   int id; n } node[110]; n int t[110]; n bool cmp(Node x, Node y) { return x.v > y.v; } n int main() { n   int n, w; n   cin.sync_with_stdio(false); n   while (cin >> n >> w) { n     for (int i = 0; i < n; i++) { n       cin >> node[i].v; n       node[i].id = i; n     } n     bool flag = true; n     for (int i = 0; i < n; i++) { n       if (node[i].v & 1) n         t[i] = node[i].v / 2 + 1, w -= t[i]; n       else n         t[i] = node[i].v / 2, w -= t[i]; n       if (w < 0) { n         flag = false; n         printf( -1 n ); n         break; n       } n     } n     if (!flag) continue; n     sort(node, node + n, cmp); n     for (int i = 0; i < n; i++) { n       if (w > (node[i].v - t[node[i].id])) { n         int d = node[i].v - t[node[i].id]; n         t[node[i].id] = node[i].v; n         w = w - d; n       } else { n         t[node[i].id] += w; n         break; n       } n     } n     for (int i = 0; i < n - 1; i++) cout << t[i] <<    ; n     cout << t[n - 1] << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 2e5 + 2; n int n; n struct Node { n   int l, r; n }; n Node a[maxn]; n bool cmp(Node x, Node y) { n   if (x.r == y.r) return x.l < y.l; n   return x.r < y.r; n } n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) { n     int x, w; n     scanf( %d%d , &x, &w); n     a[i].l = x - w; n     a[i].r = x + w; n   } n   sort(a + 1, a + n + 1, cmp); n   int max = a[1].r, ans = 1; n   for (int i = 2; i <= n; i++) n     if (a[i].l >= max) { n       ans++; n       max = a[i].r; n     } n   printf( %d , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n unsigned int dp[100100]; n char s[100100]; n int main() { n   unsigned int n; n   cin >> n; n   if (n & 1) { n     return !printf( 0 ); n   } n   scanf( %s , s + 1); n   int m = n / 2; n   dp[0] = 1; n   for (int i = 1; i <= n; i++) { n     if (s[i] ==  ? ) { n       for (int j = i / 2; j >= max(1, i - m); j--) dp[j] += dp[j - 1]; n     } n   } n   for (int i = 1; i <= n; i++) { n     if (s[i] ==  ? ) continue; n     m--; n   } n   for (int i = 1; i <= m; i++) dp[n / 2] *= 25; n   cout << dp[n / 2] <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int modInverse(int a, int m); n int gcd(int a, int b); n int power(int x, unsigned int y, unsigned int m); n void pairsort(int a[], int b[], int n); n int logint(int x, int y); n int gcd(int a, int b) { n   if (a == 0) return b; n   return gcd(b % a, a); n } n int power(int x, unsigned int y, unsigned int m) { n   if (y == 0) return 1; n   int p = power(x, y / 2, m) % m; n   p = (p * p) % m; n   return (y % 2 == 0) ? p : (x * p) % m; n } n int modInverse(int a, int m) { n   int m0 = m; n   int y = 0, x = 1; n   if (m == 1) return 0; n   while (a > 1) { n     int q = a / m; n     int t = m; n     m = a % m, a = t; n     t = y; n     y = x - q * y; n     x = t; n   } n   if (x < 0) x += m0; n   return x; n } n void pairsort(int a[], int b[], int n) { n   pair<int, int> pairt[n]; n   for (int i = 0; i < n; i++) { n     pairt[i].first = a[i]; n     pairt[i].second = b[i]; n   } n   sort(pairt, pairt + n); n   for (int i = 0; i < n; i++) { n     a[i] = pairt[i].first; n     b[i] = pairt[i].second; n   } n } n int logint(int x, int y) { n   int ans = 0; n   int a = 1; n   for (int i = 0; i < x; i++) { n     if (x <= a) { n       return ans; n     } n     ans++; n     a *= y; n   } n   return -1; n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int n; n   cin >> n; n   int mink; n   int k = 0; n   int a[n]; n   for (int i = 0; i < n; i++) { n     int t; n     cin >> t; n     a[i] = t; n     if (i == 0) n       mink = t; n     else n       mink = min(mink, t); n   } n   for (int i = 0; i < n; i++) { n     int t = a[i]; n     if (t == mink) k++; n   } n   if (k > (n / 2)) { n     cout <<  Bob ; n   } else { n     cout <<  Alice ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int visit[210000]; n int ans[210000]; n queue<int> q; n int a[210000]; n int n; n vector<int> g[210000]; n int main() { n   int n; n   cin >> n; n   for (int i = 1; i <= n; i++) scanf( %d , &a[i]); n   for (int i = 1; i <= n; i++) { n     if (a[i] & 1) { n       q.push(i); n       visit[i] = 1; n     } n     if (i - a[i] >= 1) g[i - a[i]].push_back(i); n     if (i + a[i] <= n) g[i + a[i]].push_back(i); n   } n   while (!q.empty()) { n     int pos = q.front(); n     q.pop(); n     for (auto p : g[pos]) n       if (!visit[p]) { n         q.push(p); n         ans[p] = visit[p] = visit[pos] + 1; n       } n   } n   memset((visit), (0), sizeof(visit)); n   for (int i = 1; i <= n; i++) n     if (!(a[i] & 1)) { n       q.push(i); n       visit[i] = 1; n     } n   while (!q.empty()) { n     int pos = q.front(); n     q.pop(); n     for (auto p : g[pos]) n       if (!visit[p]) { n         q.push(p); n         ans[p] = visit[p] = visit[pos] + 1; n       } n   } n   for (int i = 1; i <= n; i++) cout << ans[i] - 1 <<    ; n   return ~~(0 ^ 0 ^ 0); n } n


#include <bits/stdc++.h> n using namespace std; n const int P = 998244353, INF = 0x3f3f3f3f; n long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } n long long qpow(long long a, long long n) { n   long long r = 1 % P; n   for (a %= P; n; a = a * a % P, n >>= 1) n     if (n & 1) r = r * a % P; n   return r; n } n long long inv(long long first) { n   return first <= 1 ? 1 : inv(P % first) * (P - P / first) % P; n } n inline int rd() { n   int first = 0; n   char p = getchar(); n   while (p <  0  || p >  9 ) p = getchar(); n   while (p >=  0  && p <=  9 ) first = first * 10 + p -  0 , p = getchar(); n   return first; n } n const int N = 1e6 + 10; n int n, m, a[N], w[N], s1, s0; n int in[N]; n int dp[55][55][55]; n int solve(int a, int w) { n   memset(dp, 0, sizeof dp); n   dp[0][0][0] = 1; n   int ans = 0; n   if (a) { n     for (int i = 1; i <= m + 1; ++i) n       for (int j = 0; j <= i - 1; ++j) n         for (int k = 0; k <= j; ++k) n           if (dp[i - 1][j][k]) { n             int &r = dp[i - 1][j][k]; n             int now = w + k, tot = s1 + s0 + j - (i - 1 - j), n                 p = (long long)now * in[tot] % P; n             dp[i][j + 1][k + 1] = (dp[i][j + 1][k + 1] + (long long)p * r) % P; n             now = s1 - w + j - k, p = (long long)now * in[tot] % P; n             dp[i][j + 1][k] = (dp[i][j + 1][k] + (long long)p * r) % P; n             now = s0 - (i - 1 - j), p = (long long)now * in[tot] % P; n             dp[i][j][k] = (dp[i][j][k] + (long long)p * r) % P; n             if (i - 1 == m) ans = (ans + (long long)(w + k) * r) % P; n           } n     return ans; n   } n   for (int i = 1; i <= m + 1; ++i) n     for (int j = 0; j <= i - 1; ++j) n       for (int k = 0; k <= min(w, j); ++k) n         if (dp[i - 1][j][k]) { n           int &r = dp[i - 1][j][k]; n           int now = w - k, tot = s0 + s1 - j + (i - 1 - j), n               p = (long long)now * in[tot] % P; n           dp[i][j + 1][k + 1] = (dp[i][j + 1][k + 1] + (long long)p * r) % P; n           now = s1 + (i - 1 - j), p = (long long)now * in[tot] % P; n           dp[i][j][k] = (dp[i][j][k] + (long long)p * r) % P; n           now = s0 - w - j + k, p = (long long)now * in[tot] % P; n           dp[i][j + 1][k] = (dp[i][j + 1][k] + (long long)p * r) % P; n           if (i - 1 == m) ans = (ans + (long long)(w - k) * r) % P; n         } n   return ans; n } n int main() { n   in[0] = 1; n   for (int i = 1; i <= N - 1; ++i) in[i] = inv(i); n   scanf( %d%d , &n, &m); n   for (int i = 1; i <= n; ++i) scanf( %d , a + i); n   for (int i = 1; i <= n; ++i) { n     scanf( %d , w + i); n     if (a[i]) n       s1 += w[i]; n     else n       s0 += w[i]; n   } n   for (int i = 1; i <= n; ++i) printf( %d n , solve(a[i], w[i])); n } n


#include <bits/stdc++.h> n using namespace std; n inline int read() { n   int num = 0; n   char c = getchar(); n   if (c ==  - ) return -read(); n   while (c >=  0  && c <=  9 ) { n     num = (num << 3) + (num << 1) + c -  0 ; n     c = getchar(); n   } n   return num; n } n inline long long READ() { n   long long num = 0; n   char c = getchar(); n   if (c ==  - ) return -READ(); n   while (c >=  0  && c <=  9 ) { n     num = (num << 3) + (num << 1) + c -  0 ; n     c = getchar(); n   } n   return num; n } n struct prob { n   long long ss, sl, ts, tl; n   long double ps, psl, ptl; n   void input() { n     cin >> ss >> sl >> ts >> tl >> ps; n     ps = 1 - ps; n     psl = sl * ps; n     ptl = tl * ps; n   } n }; n int n, t; n prob pr[1007]; n inline bool cmp(const prob& a, const prob& b) { n   return a.tl * (1 - a.ps) / a.ps < b.tl * (1 - b.ps) / b.ps; n } n inline bool eq(const long double& a, const long double& b) { n   return a - b > -1e-16 && a - b < 1e-16; n } n inline bool sm(const long double& a, const long double& b) { n   return a - b < -1e-16; n } n inline bool bg(const long double& a, const long double& b) { n   return a - b > 1e-16; n } n long double dps[1007][1607], dpt[1007][1607]; n int main() { n   scanf( %d%d , &n, &t); n   for (int i = 1; i <= n; i++) pr[i].input(); n   sort(pr + 1, pr + n + 1, cmp); n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= t; j++) dps[i][j] = -((long long)0x7f7f7f7f7f7f7f7f); n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= t; j++) dpt[i][j] = ((long long)0x7f7f7f7f7f7f7f7f); n   long double ansa = -((long long)0x7f7f7f7f7f7f7f7f), n               ansb = ((long long)0x7f7f7f7f7f7f7f7f); n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= t; j++) { n       if (sm(dps[i][j], dps[i][j - 1]) || n           (eq(dps[i][j], dps[i][j - 1]) && bg(dpt[i][j], dpt[i][j - 1]))) { n         dps[i][j] = dps[i][j - 1]; n         dpt[i][j] = dpt[i][j - 1]; n       } n       if (j >= pr[i].ts + pr[i].tl) { n         long double wls = n             dps[i - 1][j - pr[i].ts - pr[i].tl] + pr[i].ss + pr[i].psl; n         long double wlt = n             (1 - pr[i].ps) * (dpt[i - 1][j - pr[i].ts - pr[i].tl] + pr[i].ts) + n             pr[i].ps * j; n         if (sm(dps[i][j], wls) || (eq(dps[i][j], wls) && bg(dpt[i][j], wlt))) { n           dps[i][j] = wls; n           dpt[i][j] = wlt; n         } n       } n       if (j >= pr[i].ts) { n         long double wls = dps[i - 1][j - pr[i].ts] + pr[i].ss; n         long double wlt = dpt[i - 1][j - pr[i].ts] + pr[i].ts; n         if (sm(dps[i][j], wls) || (eq(dps[i][j], wls) && bg(dpt[i][j], wlt))) { n           dps[i][j] = wls; n           dpt[i][j] = wlt; n         } n       } n       if (sm(dps[i][j], dps[i - 1][j]) || n           (eq(dps[i][j], dps[i - 1][j]) && bg(dpt[i][j], dpt[i - 1][j]))) { n         dps[i][j] = dps[i - 1][j]; n         dpt[i][j] = dpt[i - 1][j]; n       } n       if (sm(ansa, dps[i][j]) || (eq(ansa, dps[i][j]) && bg(ansb, dpt[i][j]))) { n         ansa = dps[i][j]; n         ansb = dpt[i][j]; n       } n     } n   return printf( %.15Lf %.15Lf n , ansa, ansb), 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long num[505]; n int n; n long long minval = 0x3f3f3f3f3f3f3f3fll; n long long check(int x) { n   long long ans = 0; n   for (int i = 1; i <= n; i++) { n     if (num[i] % x == 0) { n       ans += num[i] / x; n     } else { n       if (num[i] % x + num[i] / x >= x - 1) { n         ans += num[i] / x + 1; n       } else { n         return 0; n       } n     } n   } n   return ans; n } n void solve(int x) { n   long long t = check(x); n   if (t) { n     printf( %I64d n , t); n     exit(0); n   } n } n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) { n     scanf( %I64d , &num[i]); n     minval = min(minval, num[i]); n   } n   long long t = (long long)sqrt(minval); n   for (long long i = 1; i <= t; i++) { n     solve(minval / i + 1); n     solve(minval / i); n     solve(minval / i - 1); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n double tick() { n   static clock_t oldt, newt = clock(); n   double diff = 1.0 * (newt - oldt) / CLOCKS_PER_SEC; n   oldt = newt; n   return diff; n } n inline long long int read() { n   long long int f = 1, x = 0; n   char ch = getchar(); n   while (ch <  0  || ch >  9 ) { n     if (ch ==  - ) f = -1; n     ch = getchar(); n   } n   while (ch >=  0  && ch <=  9 ) { n     x = x * 10 + ch -  0 ; n     ch = getchar(); n   } n   return x * f; n } n long long int fastExpo(long long int a, long long int n) { n   long long int res = 1; n   while (n) { n     if (n % 2) res = res * a; n     n /= 2; n     a = a * a; n   } n   return res; n } n int dx[] = {-1, 0, 1, 0}; n int dy[] = {0, 1, 0, -1}; n vector<int> v[200010]; n int col[200010]; n vector<int> l, r; n void dfs(int n, int c) { n   col[n] = c; n   for (int j : v[n]) { n     if (col[j] == -1) dfs(j, 1 - c); n   } n } n int main() { n   int t = read(); n   while (t--) { n     int n = read(), m = read(); n     while (m--) { n       int a, b; n       cin >> a >> b; n       v[a].push_back(b); n       v[b].push_back(a); n     } n     for (int i = 1; i <= n; i++) col[i] = -1; n     dfs(1, 0); n     long long int c1 = 0, c2 = 0; n     for (int i = 1; i <= n; i++) { n       if (col[i]) n         c1++; n       else n         c2++; n     } n     if (c1 <= n / 2) { n       cout << c1 << endl; n       for (int i = 1; i <= n; i++) n         if (col[i]) cout << i <<    ; n     } else { n       cout << c2 << endl; n       for (int i = 1; i <= n; i++) n         if (!col[i]) cout << i <<    ; n     } n     cout << endl; n     for (int i = 1; i <= n; i++) v[i].clear(), col[i] = -1; n   } n   cerr <<  execution time is:   << tick() <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n int a[100100]; n int main() { n   int i, n; n   scanf( %d , &n); n   for (i = 0; i < n; i++) scanf( %d , &a[i]); n   sort(a, a + n); n   int sign = 1; n   for (i = 0; i < n; i++) { n     if (a[i] >= sign) { n       a[i] = sign; n       sign++; n     } n   } n   printf( %d n , sign); n   return 0; n } n


#include<bits/stdc++.h> n typedef int LL; n typedef double dl; n #define opt operator n #define pb push_back n #define pii std::pair<LL,LL> n const LL maxn=2e4+9,mod=998244353,inf=0x3f3f3f3f; n LL Read(){ n  LL x(0),f(1); char c=getchar(); n  while(c< 0  || c> 9 ){ n   if(c== - ) f=-1; c=getchar(); n  } n  while(c>= 0  && c<= 9 ){ n   x=(x<<3ll)+(x<<1ll)+c- 0 ; c=getchar(); n  }return x*f; n } n void Chkmin(LL &x,LL y){ n  if(y<x) x=y; n } n void Chkmax(LL &x,LL y){ n  if(y>x) x=y; n } n LL add(LL x,LL y){ n  return x+=y,x>=mod?x-mod:x; n } n LL dec(LL x,LL y){ n  return x-=y,x<0?x+mod:x; n } n LL mul(LL x,LL y){ n  return 1ll*x*y%mod; n } n LL Pow(LL base,LL b){ n  LL ret(1); while(b){ n   if(b&1) ret=mul(ret,base); base=mul(base,base); b>>=1; n  }return ret; n } n const LL Ul=15,Ku=30; n namespace Rmq{ n  LL lg[maxn]; n  pii mx[maxn][16]; n  void Init(LL *A,LL N){ n   for(LL i=1;i<=N;++i){ n    mx[i][0]=pii(A[i],i); n   } n   for(LL i=1;i<=15;++i){ n    for(LL j=1;j+(1<<i)-1<=N;++j){ n     mx[j][i]=std::max(mx[j][i-1],mx[j+(1<<i-1)][i-1]); n    } n   } n   for(LL i=1;i<=N;++i) lg[i]=lg[i>>1]+1; n  } n  LL Query(LL l,LL r){ n   LL len(lg[r-l+1]-1); n   return std::max(mx[l][len],mx[r-(1<<len)+1][len]).second; n  } n } n LL n,q; n LL a[maxn],f[16][maxn][31]; n void Init(){ n  n=Read(); q=Read(); n  for(LL i=1;i<=n;++i){ n   a[i]=Read(); n  } n  for(LL i=1;i<=n+1;++i){ n   a[i]+=i; n  } n // for(LL i=1;i<=n;++i) printf( %d  ,a[i]-i); puts(  ); n  Rmq::Init(a,n+1); n // puts( #1 ); n  for(LL j=0;j<=Ul;++j){ n   for(LL k=0;k<=Ku;++k) f[j][n+1][k]=n+1; n  } n // puts( #2 ); n  for(LL i=n;i>=1;--i){ n //  printf( (%d) n ,i); n   for(LL k=0;k<=Ku;++k){ n    f[0][i][k]=std::min(a[i]+k,n+1); n   } n   for(LL j=1;j<=Ul;++j){ n    for(LL k=0;k<=Ku;++k){ n     LL mx(0); n     for(LL k1=k;k1>=0 && mx<n;--k1){ n      Chkmax(mx,f[j-1][Rmq::Query(i,f[j-1][i][k1])][k-k1]); n     } n     f[j][i][k]=mx; n    } n   } n  } n } n void Solve(LL l,LL r,LL K){ n  static LL g[31]; n  if(l==r){ n   puts( 0 ); n   return; n  } n  Chkmin(K,r-l-1); n  for(LL i=0;i<=Ku;++i){ n   g[i]=std::min(n+1,a[l]+i); n  } n  LL ret(1); n  for(LL i=0;i<=K;++i) if(g[i]>=r){ n   puts( 1 ); n   return; n  } n  for(LL i=Ul;i>=0;--i){ n   LL flag(0); n   static LL h[31]; n   for(LL k=K;k>=0;--k){ n    LL mx(0); n    for(LL k1=0;k1<=k && mx<r;++k1){ n     Chkmax(mx,f[i][Rmq::Query(l,g[k1])][k-k1]); n    } n    h[k]=mx; n    if(mx>=r){ n     flag=1; break; n    } n   } n   if(!flag){ n    for(LL k=0;k<=Ku;++k) g[k]=h[k]; n    ret+=(1<<i); n   } n  } n  printf( %d n ,ret+1); n // exit(0); n } n void Solve(){ n  while(q--){ n   LL l(Read()),r(Read()),K(Read()); n   Solve(l,r,K); n  } n } n int main(){ n  Init(); n  Solve(); n  return 0; n } n  n  n  n


#include <bits/stdc++.h> n using namespace std; n long long a[1001]; n long long b[2001]; n int main() { n   long long n, k, p; n   cin >> n >> k >> p; n   for (int i = 1; i <= n; i++) cin >> a[i]; n   for (int i = 1; i <= k; i++) cin >> b[i]; n   sort(a + 1, a + n + 1); n   sort(b + 1, b + k + 1); n   long long ans = (long long)2e15 + 1; n   for (int i = 1; i <= k - n + 1; i++) { n     long long maks = 0; n     for (int j = 1; j <= n; j++) { n       maks = max(abs(a[j] - b[i + j - 1]) + abs(b[i + j - 1] - p), maks); n     } n     ans = min(maks, ans); n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int s1, s2, t1, t2; n   char ch1, ch2; n   cin >> s1 >> ch1 >> s2; n   cin >> t1 >> ch2 >> t2; n   int a = s1 - t1; n   int b = s2 - t2; n   if (b < 0) { n     b += 60; n     a--; n   } n   if (a < 0) { n     a += 24; n   } n   cout << right << setw(2) << setfill( 0 ) << a <<  : ; n   cout << right << setw(2) << setfill( 0 ) << b << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, a; n   cin >> n >> a; n   int arr[n]; n   int sum = 0; n   for (int i = 0; i < n; i++) { n     cin >> arr[i]; n     sum += arr[i]; n   } n   sum += (n - 1) * 10; n   if (sum > a) { n     cout << -1 << endl; n   } else { n     cout << (n - 1) * 2 + (a - sum) / 5 << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1000000 + 5; n vector<int> g[N]; n bool used[N]; n int n, m; n int main() { n   scanf( %d %d , &n, &m); n   for (int i = 0; i < m; i++) { n     int u, v; n     scanf( %d %d , &u, &v); n     u--, v--; n     g[u].push_back(v); n   } n   for (int i = 0; i < n; i++) { n     if (!used[i]) { n       for (auto x : g[i]) { n         if (x > i) used[x] = true; n       } n     } n   } n   for (int i = n - 1; i >= 0; i--) { n     if (!used[i]) { n       for (auto x : g[i]) { n         used[x] = true; n       } n     } n   } n   int ans = 0; n   for (int i = 0; i < n; i++) { n     if (!used[i]) ans++; n   } n   printf( %d n , ans); n   for (int i = 0; i < n; i++) { n     if (!used[i]) printf( %d  , i + 1); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxN = 500 + 5; n const int maxM = 100000 + 5; n inline long long read() { n   long long sum = 0, f = 1; n   char ch = getchar(); n   while (ch <  0  || ch >  9 ) { n     if (ch ==  - ) f = -1; n     ch = getchar(); n   } n   while (ch >=  0  && ch <=  9 ) { n     sum = sum * 10 + ch -  0 ; n     ch = getchar(); n   } n   return f * sum; n } n int dp[maxN][maxN]; n char G[maxN][maxN]; n const int dr[] = {1, 0}; n const int dc[] = {0, 1}; n int main() { n   ios::sync_with_stdio(false); n   int n = read(), m = read(), len = (n + m) / 2; n   for (int i = 1; i <= n; i++) scanf( %s , G[i] + 1); n   if (G[1][1] != G[n][m]) { n     printf( 0 n ); n     return 0; n   } n   dp[1][n] = 1; n   for (int k = 2; k <= len; k++) { n     for (int i = k; i >= 1; i--) { n       int x1 = i, y1 = 1 + k - x1; n       if (x1 > n || y1 < 1 || y1 > m) continue; n       for (int j = n - k + 1; j <= n; j++) { n         int x2 = j, y2 = n + m - k - x2 + 1; n         if (x2 < 1 || x2 > n || y2 < 1 || y2 > m) n           continue; n         else if (G[x1][y1] != G[x2][y2]) { n           dp[x1][x2] = 0; n           continue; n         } n         dp[x1][x2] = (dp[x1][x2] + dp[x1][x2 + 1]) % 1000000007; n         dp[x1][x2] = (dp[x1][x2] + dp[x1 - 1][x2]) % 1000000007; n         dp[x1][x2] = (dp[x1][x2] + dp[x1 - 1][x2 + 1]) % 1000000007; n       } n     } n   } n   int ans = 0; n   if ((n + m) % 2 == 0) { n     for (int x1 = 1; x1 <= len; x1++) { n       int y1 = 1 + len - x1; n       if (x1 >= 1 && x1 <= n && y1 >= 1 && y1 <= m) n         ans = (ans + dp[x1][x1]) % 1000000007; n     } n   } else { n     for (int x1 = 1; x1 <= len; x1++) { n       int y1 = 1 + len - x1; n       if (x1 < 1 || x1 > n || y1 < 1 || y1 > m) continue; n       if (y1 + 1 <= m) ans = (ans + dp[x1][x1]) % 1000000007; n       if (x1 + 1 <= n) ans = (ans + dp[x1][x1 + 1]) % 1000000007; n     } n   } n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n int main() { n   long int n, s, sum = 0, z, count = 0; n   scanf( %ld%ld , &n, &s); n   z = s; n   do { n     if (s >= n) { n       sum = sum + (s / n) * n; n       count = count + (s / n); n       s = s - (s / n) * n; n     } else n       n = n - 1; n   } while (s != 0 && n != 0); n   printf( %ld , count); n   return 0; n } n


#include <bits/stdc++.h> n const double EPS = 0.00000001; n int main() { n   std::ios_base::sync_with_stdio(false); n   std::cin.tie(nullptr); n   int32_t t; n   std::cin >> t; n   for (int32_t cs = 1; cs <= t; cs++) { n     int32_t n, l; n     std::cin >> n >> l; n     std::vector<int32_t> a(n); n     for (auto &x : a) { n       std::cin >> x; n     } n     int32_t indL = 0, indR = n - 1, speed1 = 1, speed2 = 1; n     double pos1 = 0, pos2 = l; n     double currT = 0.0, ans; n     while (1) { n       if (indL > indR) { n         ans = currT + (pos2 - pos1) / (speed1 + speed2); n         break; n       } n       double t1 = ((double)a[indL] - pos1) / speed1; n       double t2 = ((double)pos2 - a[indR]) / speed2; n       if (indL == indR) { n         if (fabs(t1 - t2) < EPS) { n           ans = currT + t1; n           break; n         } n       } n       if (t1 < t2) { n         indL++; n         currT += t1; n         speed1++; n         pos1 = a[indL - 1]; n         pos2 -= t1 * speed2; n       } else { n         indR--; n         currT += t2; n         speed2++; n         pos1 += t2 * speed1; n         pos2 = a[indR + 1]; n       } n     } n     std::cout << std::fixed << std::setprecision(8); n     std::cout << ans <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n void solve() {} n const long long maxn = 1050; n long long n, a, b; n long long ans[maxn][maxn]; n void no() { n   cout <<  NO  <<   n ; n   exit(0); n } n signed main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cin >> n >> a >> b; n   if (min(a, b) > 1) no(); n   if ((n == 2 or n == 3) and a == 1 and b == 1) no(); n   long long c = 1, d = 0; n   if (b != 1) { n     swap(a, b); n     swap(c, d); n   } n   for (long long i = 1; i <= n; i++) { n     ans[i][i] = 0; n     for (long long j = 1; j <= n; j++) { n       if (i != j) { n         ans[i][j] = ans[j][i] = d; n       } n     } n   } n   for (long long i = a; i + 1 <= n; i++) { n     ans[i][i + 1] = ans[i + 1][i] = c; n   } n   cout <<  YES  <<   n ; n   for (long long i = 1; i <= n; i++) { n     for (long long j = 1; j <= n; j++) { n       cout << ans[i][j]; n     } n     cout <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int i, n; n   int a, b, c; n   int sum_a, sum_b, sum_c; n   sum_a = 0; n   sum_b = 0; n   sum_c = 0; n   cin >> n; n   for (i = 1; i <= n; i++) { n     cin >> a >> b >> c; n     sum_a = sum_a + a; n     sum_b = sum_b + b; n     sum_c = sum_c + c; n   } n   if (sum_a == 0 && sum_b == 0 && sum_c == 0) { n     cout <<  YES  << endl; n   } else { n     cout <<  NO  << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double PI = 2.0 * acos(0.0); n const double eps = 1e-6; n const long long _mod = 1000000007LL; n const int save[10][4] = {{0}, {0}, {6, 2, 4, 8}, {1, 3, 9, 7}, {6, 4}, n                          {0}, {0}, {1, 7, 9, 3}, {6, 8, 4, 2}, {1, 9}}; n int todigit(char c) { return (isdigit(c)) ? (c - 48) : c; } n int toint(string s) { n   int r = 0; n   istringstream sin(s); n   sin >> r; n   return r; n } n long long tolong(string s) { n   long long r = 0; n   istringstream sin(s); n   sin >> r; n   return r; n } n double todouble(string s) { n   double r = 0.0; n   istringstream sin(s); n   sin >> r; n   return r; n } n bool bit_check(int k, int p) { return (bool)(k & (1 << p)); } n int bit_set(int k, int p) { return k = (k | (1 << p)); } n template <class T> n string toString(T n) { n   ostringstream ost; n   ost << n; n   ost.flush(); n   return ost.str(); n } n template <class T> n T Abs(T x) { n   return x > 0 ? x : -x; n } n template <class T> n T power(T N, T P) { n   return (P == 0) ? 1 : N * power(N, P - 1); n } n template <class T> n inline T max_(T a, T b) { n   return a > b ? a : b; n } n template <class T> n inline T min_(T a, T b) { n   return a < b ? a : b; n } n template <class T> n inline T gcd(T a, T b) { n   if (a < 0) return gcd(-a, b); n   if (b < 0) return gcd(a, -b); n   return (b == 0) ? a : gcd(b, a % b); n } n template <class T> n inline T lcm(T a, T b) { n   if (a < 0) return lcm(-a, b); n   if (b < 0) return lcm(a, -b); n   return a * (b / gcd(a, b)); n } n int di(string num, int b); n int dig(int num); n int main() { n   int a, b; n   cin >> a >> b; n   int mn = max(dig(a), dig(b)); n   mn++; n   int mx = 0; n   for (int i = mn; i < 17; ++i) { n     mx = max(mx, di(toString(a + b), i)); n   } n   printf( %d n , mx); n   return 0; n } n int di(string num, int b) { n   int n = 0; n   for (int i = 0; i < num.size(); ++i) { n     n = (n * b) + (num[i] -  0 ); n   } n   int cnt = 0; n   while (n) { n     n = n / b; n     ++cnt; n   } n   return cnt; n } n int dig(int num) { n   int mn = 0; n   while (num) { n     mn = max(mn, num % 10); n     num = num / 10; n   } n   return mn; n } n


#include <bits/stdc++.h> n using namespace std; n int n, mem[505][505]; n string s; n int dp(int i, int j) { n   if (i > j) return 0; n   int &ans = mem[i][j]; n   if (ans != -1) return ans; n   ans = dp(i + 1, j) + 1; n   for (int k = i + 1; k <= j; k++) n     if (s[i] == s[k]) ans = min(ans, dp(i + 1, k - 1) + dp(k, j)); n   return ans; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   memset(mem, -1, sizeof(mem)); n   cin >> n >> s; n   cout << dp(0, n - 1) <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   int a[n][2]; n   for (int i = 0; i < n; i++) { n     cin >> a[i][0] >> a[i][1]; n   } n   int sum1 = 0; n   int sum2 = 0; n   for (int i = 0; i < n; i++) { n     if (abs(sum1 + a[i][0] - sum2) <= 500) { n       sum1 += a[i][0]; n       a[i][0] = -1; n     } else { n       sum2 += a[i][1]; n     } n   } n   if (abs(sum1 - sum2) > 500) { n     cout <<  -1 ; n   } else { n     for (int i = 0; i < n; i++) { n       if (a[i][0] == -1) { n         cout <<  A ; n       } else { n         cout <<  G ; n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t, j; n   cin >> t; n   for (j = 0; j <= t - 1; j++) { n     int a, b, c, n; n     cin >> a >> b >> n; n     n = n % 3; n     c = a ^ b; n     if (n == 0) { n       cout << a << endl; n     } else if (n == 1) { n       cout << b << endl; n     } else { n       cout << c << endl; n     } n   } n } n


#include <bits/stdc++.h> n char _; n using namespace std; n int N, C, D; n pair<int, int> A[400000]; n long long Z, ZO, ZOZ, O, OZ, OZO; n inline bool cmp(const pair<int, int>& a, const pair<int, int>& b) { n   if ((b.second < 0) ^ (a.second < 0)) n     return 1LL * a.first * b.second > 1LL * b.first * a.second; n   return 1LL * a.first * b.second < 1LL * b.first * a.second; n } n inline bool eq(const pair<int, int>& a, const pair<int, int>& b) { n   return 1LL * a.first * b.second == 1LL * b.first * a.second; n } n int main() { n   do { n     while ((N = getchar()) <  0 ) n       ; n     for (N -=  0 ;  0  <= (_ = getchar()); N = (N << 3) + (N << 1) + _ -  0 ) n       ; n   } while (0); n   do { n     while ((C = getchar()) <  0 ) n       ; n     for (C -=  0 ;  0  <= (_ = getchar()); C = (C << 3) + (C << 1) + _ -  0 ) n       ; n   } while (0); n   do { n     while ((D = getchar()) <  0 ) n       ; n     for (D -=  0 ;  0  <= (_ = getchar()); D = (D << 3) + (D << 1) + _ -  0 ) n       ; n   } while (0); n   for (int i = 0; i < N; i++) { n     do { n       while ((A[i].first = getchar()) <  0 ) n         ; n       for (A[i].first -=  0 ;  0  <= (_ = getchar()); n            A[i].first = (A[i].first << 3) + (A[i].first << 1) + _ -  0 ) n         ; n     } while (0); n     do { n       while ((A[i].second = getchar()) <  0 ) n         ; n       for (A[i].second -=  0 ;  0  <= (_ = getchar()); n            A[i].second = (A[i].second << 3) + (A[i].second << 1) + _ -  0 ) n         ; n     } while (0); n     A[i].first -= C, A[i].second -= D; n   } n   sort(A, A + N, cmp); n   for (int i = 0, j; i < N; i = j) { n     long long NZ = Z, NZO = ZO, NZOZ = ZOZ, NO = O, NOZ = OZ, NOZO = OZO; n     for (j = i; j < N && eq(A[i], A[j]); j++) { n       if (A[j].second < 0) { n         NOZO += OZ; n         NZO += Z; n         NO++; n       } else { n         NZOZ += ZO; n         NOZ += O; n         NZ++; n       } n     } n     Z = NZ, ZO = NZO, ZOZ = NZOZ, O = NO, OZ = NOZ, OZO = NOZO; n   } n   int L = 0, R = 0, D = 0; n   for (int i = 0; i < N; i++) n     if (A[i].second == 0) { n       if (A[i].first < 0) n         L++; n       else n         R++; n     } n   for (int i = 0; i < N; i++) n     if (A[i].second < 0) D++; n   printf( %lld n , OZO + ZOZ - 1LL * L * R * D); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 0x3F3F3F3F; n const int NEGINF = 0xC0C0C0C0; n const double EPS = 1e-8; n int cmp(double x, double y = 0, double tol = EPS) { n   return (x <= y + tol) ? (x + tol < y) ? -1 : 0 : 1; n } n string s; n bool test(long long inx) { n   int pos = 0; n   int m = 0; n   int im = 0; n   for (auto &x : s) { n     if (x ==  R ) n       pos++; n     else n       pos--; n     if (inx >= 0 && pos == inx) pos--; n     if (pos < m) { n       m = pos; n       im = &x - &(s[0]); n     } n   } n   return im == s.size() - 1; n } n int main() { n   cin >> s; n   if (s.back() ==  R ) n     for (auto &x : s) x =  R  +  L  - x; n   if (test(-1)) { n     cout <<  1 n ; n     return 0; n   } else if (!test(1)) { n     cout <<  0 n ; n     return 0; n   } n   long long m = 1, M = 0x7fffffffffffffffll; n   long long ans = 1; n   while (M >= m) { n     long long med = m + (M - m) / 2; n     if (test(med)) { n       ans = med; n       m = med + 1; n     } else n       M = med - 1; n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a[500005]; n int main() { n   int n; n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) scanf( %d , &a[i]); n   int kk = 1; n   sort(a + 1, a + n + 1); n   for (int i = 1; i <= n; i++) { n     if (a[i] >= a[kk] * 2) { n       ++kk; n     } n   } n   --kk; n   kk = min(n / 2, kk); n   printf( %d n , n - kk); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 200005; n int now[30]; n char s[maxn]; n int num[maxn]; n int main() { n   int n; n   scanf( %d , &n); n   scanf( %s , s + 1); n   int ans = 0; n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= 30; j++) { n       if (s[i] >= now[j]) { n         num[i] = j; n         now[j] = s[i]; n         ans = max(ans, j); n         break; n       } n     } n   } n   printf( %d n , ans); n   for (int i = 1; i <= n; i++) { n     printf( %d  , num[i]); n   } n   printf(  n ); n } n


#include <bits/stdc++.h> n using namespace std; n int read() { n   char ch; n   for (ch = getchar(); ch <  0  || ch >  9 ; ch = getchar()) n     ; n   int x = ch -  0 ; n   for (ch = getchar(); ch >=  0  && ch <=  9 ; ch = getchar()) n     x = x * 10 + ch -  0 ; n   return x; n } n const int N = 3e5 + 5; n int n, m, q, p[N], u[N], v[N]; n struct Graph { n   int t[N << 1], nxt[N << 1], lst[N], l; n   void add(int x, int y) { n     t[++l] = y; n     nxt[l] = lst[x]; n     lst[x] = l; n   } n   int n, dfn[N], low[N], sta[N], col[N], top, tot, id; n   void init(int N) { n     n = N; n     l = 1; n     tot = id = 0; n     for (int i = 1; i <= n; i++) col[i] = low[i] = dfn[i] = lst[i] = 0; n   } n   void tarjan(int x, int y) { n     dfn[x] = low[x] = ++tot; n     sta[++top] = x; n     for (int i = lst[x]; i; i = nxt[i]) { n       if (i == y) continue; n       if (!dfn[t[i]]) { n         tarjan(t[i], i ^ 1); n         low[x] = min(low[x], low[t[i]]); n       } else n         low[x] = min(low[x], dfn[t[i]]); n     } n     if (dfn[x] == low[x]) n       for (sta[top + 1] = 0, id++; sta[top + 1] != x; top--) col[sta[top]] = id; n   } n } g1, g2; n struct Tree { n   int t[N << 1], nxt[N << 1], lst[N], l; n   void add(int x, int y) { n     t[++l] = y; n     nxt[l] = lst[x]; n     lst[x] = l; n   } n   int dfn[N], ed[N], dep[N], fa[N][19], tot; n   void dfs(int x, int y) { n     dfn[x] = ++tot; n     fa[x][0] = y; n     dep[x] = dep[y] + 1; n     for (int i = lst[x]; i; i = nxt[i]) n       if (t[i] != y) dfs(t[i], x); n     ed[x] = tot; n   } n   void init(int n) { n     for (int i = 1; i <= n; i++) n       if (!dfn[i]) dfs(i, 0); n     for (int j = 1; j <= 18; j++) n       for (int i = 1; i <= n; i++) fa[i][j] = fa[fa[i][j - 1]][j - 1]; n   } n   int lca(int x, int y) { n     if (dep[x] < dep[y]) swap(x, y); n     for (int j = 18; j >= 0; j--) n       if (dep[fa[x][j]] > dep[y]) x = fa[x][j]; n     x = dep[x] == dep[y] ? x : fa[x][0]; n     for (int j = 18; j >= 0; j--) n       if (fa[x][j] != fa[y][j]) x = fa[x][j], y = fa[y][j]; n     return x == y ? x : fa[x][0]; n   } n } t; n bool cmp(int x, int y) { return t.dfn[x] < t.dfn[y]; } n int sta[N], pr[N], id[N], sz, top; n vector<int> pt; n void build() { n   sort(pt.begin(), pt.end(), cmp); n   sz = pt.size(); n   for (int i = 1; i <= sz - 1; i++) { n     int x = t.lca(pt[i], pt[i - 1]); n     if (x) pt.push_back(x); n   } n   sort(pt.begin(), pt.end(), cmp); n   sz = unique(pt.begin(), pt.end()) - pt.begin(); n   while (pt.size() > sz) pt.pop_back(); n   for (int i = 0; i <= sz - 1; i++) pr[pt[i]] = 0; n   top = 0; n   for (int i = 0; i < sz; i++) { n     for (; top && t.ed[sta[top]] < t.dfn[pt[i]]; top--) n       ; n     if (top) pr[pt[i]] = sta[top]; n     sta[++top] = pt[i]; n   } n   g2.init(sz); n   for (int i = 0; i <= sz - 1; i++) id[pt[i]] = i + 1; n   for (int i = 0; i <= sz - 1; i++) { n     int x = id[pr[pt[i]]], y = i + 1; n     if (x) g2.add(x, y), g2.add(y, x); n   } n } n int main() { n   n = read(); n   m = read(); n   q = read(); n   g1.init(n); n   for (int i = 1; i <= m; i++) { n     u[i] = read(); n     v[i] = read(); n     g1.add(u[i], v[i]); n     g1.add(v[i], u[i]); n   } n   for (int i = 1; i <= n; i++) n     if (!g1.dfn[i]) g1.tarjan(i, 0); n   for (int i = 1; i <= m; i++) { n     int x = g1.col[u[i]], y = g1.col[v[i]]; n     if (x != y) t.add(x, y), t.add(y, x); n   } n   t.init(g1.id); n   int cnt = 0; n   for (int ty = 1; ty <= q; ty++) { n     int nn = read(), mm = read(); n     pt.clear(); n     for (int i = 1; i <= nn; i++) { n       p[i] = g1.col[(read() + cnt + n - 1) % n + 1]; n       pt.push_back(p[i]); n     } n     for (int i = 1; i <= mm; i++) { n       u[i] = g1.col[(read() + cnt + n - 1) % n + 1]; n       v[i] = g1.col[(read() + cnt + n - 1) % n + 1]; n       pt.push_back(u[i]); n       pt.push_back(v[i]); n     } n     build(); n     for (int i = 1; i <= mm; i++) { n       int x = id[u[i]], y = id[v[i]]; n       if (x != y) g2.add(x, y), g2.add(y, x); n     } n     for (int i = 1; i <= sz; i++) n       if (!g2.dfn[i]) g2.tarjan(i, 0); n     bool ok = 1; n     for (int i = 2; i <= nn; i++) n       if (g2.col[id[p[i]]] != g2.col[id[p[1]]]) { n         ok = 0; n         break; n       } n     if (ok) { n       puts( YES ); n       (cnt += ty) %= n; n     } else n       puts( NO ); n   } n   return 0; n } n