#include <bits/stdc++.h> n using namespace std; n string A; n bool isPalindrome(int left, int right) { n   while (left < right) { n     if (A[left] != A[right]) return false; n     left++, right--; n   } n   return true; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(NULL); n   cout.tie(NULL); n   cin >> A; n   int N = A.size(); n   int bonus = 0; n   int ret = 0; n   if (N % 2 == 1) bonus = 1; n   N /= 2; n   while (N > 0) { n     if (isPalindrome(0, N - 1)) { n       if (N % 2 == 1) { n         N--; n         bonus = 1; n       } else n         N /= 2; n     } else { n       ret = 1 + bonus; n       break; n     } n   } n   if (ret == 0) n     cout <<  Impossible ; n   else n     cout << ret; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long o = 1e6 + 5; n long n, i, j, h, k, sl, g, kq = 0; n long a[o], b[o], c[o], A, B; n string s; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cin >> n; n   i = 0, j = 0, h = 0, k = 0; n   for (long p = 1; p <= n; p++) { n     cin >> s >> g; n     if (s ==  00 ) { n       i++; n       a[i] = g; n     } else if (s ==  01 ) { n       j++; n       b[j] = g; n     } else if (s ==  10 ) { n       h++; n       c[h] = g; n     } else if (s ==  11 ) { n       k++; n       kq += g; n     } n   } n   if (k == 0 && (j == 0 || h == 0)) { n     cout << 0; n     return 0; n   } n   sort(a + 1, a + 1 + i); n   sort(b + 1, b + 1 + j); n   sort(c + 1, c + 1 + h); n   a[0] = b[0] = c[0] = 0; n   A = B = 0; n   sl = min(h, j); n   while (A < sl) { n     A++; n     kq += c[h]; n     h--; n   } n   while (B < sl) { n     B++; n     kq += b[j]; n     j--; n   } n   sl = 2 * (k + sl) - (k + 2 * sl); n   for (long p = 1; p <= sl; p++) { n     long ma = max(a[i], max(b[j], c[h])); n     if (ma == 0) break; n     kq += ma; n     if (ma == a[i]) n       i--; n     else if (ma == b[j]) n       j--; n     else if (ma == c[h]) n       h--; n   } n   cout << kq; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long ans; n struct arr { n   int n; n   int v; n } a[200001], b[200001]; n int n, m, i, j; n bool cmp(arr a, arr b) { return a.n < b.n; } n int main() { n   cin >> n; n   for (i = 1; i <= n; i++) cin >> a[i].n >> a[i].v; n   cin >> m; n   for (i = 1; i <= m; i++) cin >> b[i].n >> b[i].v; n   sort(a + 1, a + n + 1, cmp); n   sort(b + 1, b + m + 1, cmp); n   i = j = 1; n   while (i <= n && j <= m) { n     if (a[i].n == b[j].n) n       ans += max(a[i].v, b[j].v), i++, j++; n     else if (a[i].n < b[j].n) n       ans += a[i].v, i++; n     else n       ans += b[j].v, j++; n   } n   if (i > n) { n     for (i = j; i <= m; i++) ans += b[i].v; n   } else { n     for (j = i; j <= n; j++) ans += a[j].v; n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void fft(vector<complex<double> > &a, bool invert) { n   int n = a.size(), lg = 0; n   while (1 << lg < n) ++lg; n   assert(1 << lg == n); n   for (int i = 0; i < n; ++i) { n     int rev = 0; n     for (int j = 0; j < lg; ++j) n       if ((i & 1 << j) != 0) rev |= 1 << (lg - j - 1); n     if (i < rev) swap(a[i], a[rev]); n   } n   vector<complex<double> > roots(n); n   for (int i = 0; i < n; ++i) { n     double a = 2 * M_PI * i / n * (invert ? -1 : 1); n     roots[i] = complex<double>(cos(a), sin(a)); n   } n   for (int len = 2; len <= n; len *= 2) n     for (int i = 0; i < n; i += len) n       for (int j = 0; j < len / 2; ++j) { n         complex<double> u = a[i + j], n                         v = a[i + j + len / 2] * roots[n / len * j]; n         a[i + j] = u + v; n         a[i + j + len / 2] = u - v; n       } n   if (invert) n     for (int i = 0; i < n; ++i) a[i] /= n; n } n vector<int> multiply(const vector<int> &a, const vector<int> &b) { n   int m = a.size(), n = b.size(), p = 2; n   while (p < m + n - 1) p <<= 1; n   vector<complex<double> > pa(p), pb(p); n   for (int i = 0; i < m; ++i) pa[i] = complex<double>(a[i], 0); n   for (int i = 0; i < n; ++i) pb[i] = complex<double>(b[i], 0); n   fft(pa, false); n   fft(pb, false); n   for (int i = 0; i < p; ++i) pa[i] *= pb[i]; n   fft(pa, true); n   vector<int> res(p); n   for (int i = 0; i < p; ++i) res[i] = (int)round(real(pa[i])); n   return res; n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(NULL); n   int n, m; n   cin >> n >> m; n   vector<bool> hasBag(m + 1); n   vector<int> p(m + 1); n   for (int i = 0; i < n; ++i) { n     int w; n     cin >> w; n     p[w] = 1; n     hasBag[w] = true; n   } n   p = multiply(p, p); n   for (int i = 1; i <= m; ++i) n     if (p[i] > 0) { n       if (!hasBag[i]) return cout <<  NO , 0; n       hasBag[i] = false; n     } n   printf( YES n%d n , count(hasBag.begin(), hasBag.end(), 1)); n   for (int i = 1; i <= m; ++i) n     if (hasBag[i] == 1) printf( %d  , i); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long inf = 1e15; n long long q[300005]; n long long d[300005]; n long long dd[300005]; n struct st { n   long long x, w, id; n }; n vector<st> v[300005]; n st t; n vector<long long> ans; n long long sum; n long long n, m; n long long x, y, z; n inline void dij(long long st) { n   for (long long i = 1; i <= n; ++i) d[i] = inf; n   set<pair<long long, long long> > s; n   d[st] = 0; n   s.insert(make_pair(0, st)); n   while (!s.empty()) { n     long long x = s.begin()->second; n     s.erase(s.begin()); n     for (long long i = 0; i < v[x].size(); ++i) { n       long long to = v[x][i].x; n       long long len = d[x] + v[x][i].w; n       if (d[to] > len) { n         s.erase(make_pair(d[to], to)); n         d[to] = len; n         s.insert(make_pair(d[to], to)); n       } n     } n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   cin >> n >> m; n   for (long long i = 1; i <= m; ++i) { n     cin >> x >> y >> z; n     t.x = y; n     t.w = z; n     t.id = i; n     v[x].push_back(t); n     t.x = x; n     v[y].push_back(t); n   } n   long long stt; n   cin >> stt; n   dij(stt); n   for (long long i = 1; i <= n; ++i) { n     long long mx = 1e9; n     for (long long j = 0; j < v[i].size(); ++j) { n       long long to = v[i][j].x; n       if (d[to] != d[i] - v[i][j].w) continue; n       mx = min(mx, v[i][j].w); n     } n     for (long long j = 0; j < v[i].size(); ++j) { n       long long to = v[i][j].x; n       if (d[to] != d[i] - v[i][j].w) continue; n       if (v[i][j].w == mx) { n         ans.push_back(v[i][j].id); n         sum += v[i][j].w; n         break; n       } n     } n   } n   cout << sum <<   n ; n   for (long long i = 0; i < ans.size(); ++i) cout << ans[i] <<    ; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(), cout.tie(); n   int n; n   cin >> n; n   int temp = 1; n   int a[] = {4, 7, 44, 47, 74, 77, 444, 447, 474, 477, 744, 747, 774, 777}; n   for (int i = 0; i < 14; i++) { n     if (n % a[i] == 0) { n       cout <<  YES  << endl; n       temp = 0; n       break; n     } n   } n   if (temp) { n     cout <<  NO  << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 100000; n const int INF = 0x3f3f3f3f; n int dis[MAXN + 10], pos[MAXN + 10], f[MAXN + 10], Max, m, n; n bool check(const int& x) { n   if (x >= dis[1] - 1) return true; n   if (2 * x < dis[1] - 1) return false; n   f[1] = 0; n   for (int i = 2; i <= n; i++) { n     f[i] = -INF; n     if (f[i - 1] >= pos[i] - 1) f[i] = pos[i] + x; n     if (f[i - 1] >= pos[i] - 1 - x) f[i] = max(f[i], pos[i]); n     if (i > 2 && f[i - 2] >= pos[i] - 1 - x) f[i] = max(pos[i - 1] + x, f[i]); n   } n   if (f[n] + x >= m - 1) return true; n   f[1] = x, f[2] = max(x, pos[2]); n   for (int i = 3; i <= n; i++) { n     f[i] = -INF; n     if (f[i - 1] >= pos[i] - 1) f[i] = pos[i] + x; n     if (f[i - 1] >= pos[i] - 1 - x) f[i] = max(f[i], pos[i]); n     if (f[i - 2] >= pos[i] - 1 - x) f[i] = max(pos[i - 1] + x, f[i]); n   } n   if (f[n] >= min(m - 1, pos[2] + m - 1 - x)) return true; n   return false; n } n int tmp[MAXN + 10]; n void _rotate(int* arr, int mid, int len) { n   int cnt = 0; n   for (int i = mid; i <= len; i++) tmp[++cnt] = arr[i]; n   for (int i = 1; i < mid; i++) tmp[++cnt] = arr[i]; n   for (int i = 1; i <= len; i++) arr[i] = tmp[i]; n } n int main() { n   scanf( %d%d , &m, &n); n   if (n == 1) { n     printf( %d n , m - 1); n     return 0; n   } n   for (int i = 1; i <= n; i++) scanf( %d , &pos[i]); n   sort(pos + 1, pos + 1 + n); n   pos[0] = pos[n]; n   int p; n   for (int i = 1; i <= n; i++) { n     dis[i] = (pos[i] - pos[i - 1] + m) % m; n     if (dis[i] > Max) p = i; n     Max = max(Max, dis[i]); n   } n   _rotate(pos, p, n); n   _rotate(dis, p, n); n   int eff = pos[1]; n   for (int i = 1; i <= n; i++) pos[i] = (pos[i] - eff + m) % m; n   int L = 1, R = Max - 1, ans = 0; n   while (L <= R) { n     int mid = (L + R) >> 1; n     if (check(mid)) { n       ans = mid; n       R = mid - 1; n     } else n       L = mid + 1; n   } n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void solve() { n   int n; n   cin >> n; n   vector<pair<long long, long long> > v(n); n   for (int i = 0; i < n; i++) { n     int a; n     cin >> a; n     v[i] = {a, 0}; n   } n   if (n == 1) { n     cout <<  T n ; n     return; n   } n   while (1) { n     sort(v.begin(), v.end(), greater<pair<long long, long long> >()); n     int t_idx = 0, hl_idx = 0; n     while (t_idx < n && v[t_idx].second == 1) t_idx++; n     if (t_idx == n || v[t_idx].first == 0) { n       cout <<  HL n ; n       return; n     } n     v[t_idx].first--; n     while (hl_idx < n && hl_idx == t_idx) hl_idx++; n     if (hl_idx == n || v[hl_idx].first == 0) { n       cout <<  T n ; n       return; n     } n     v[hl_idx].first--; n     for (int i = 0; i < n; i++) { n       if (i == hl_idx) n         v[i].second = 1; n       else n         v[i].second = 0; n     } n   } n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   int t; n   cin >> t; n   while (t--) solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(false); n   int t; n   cin >> t; n   while (t--) { n     int n; n     cin >> n; n     string a, b; n     a +=  M , b +=  M ; n     string tmp1, tmp2; n     cin >> tmp1 >> tmp2; n     a += tmp1, b += tmp2; n     for (int i = (1); i < n + 1; i++) a[i] -=  0 , b[i] -=  0 ; n     vector<int> ans; n     int pos = 1; n     for (int i = (1); i < n + 1; i++) { n       if (b[n - i + 1] == (a[pos] + i - 1) % 2) ans.push_back(1); n       ans.push_back(n - i + 1); n       if (pos <= n / 2) n         pos = n - pos + 1; n       else n         pos = n - pos + 2; n     } n     cout << ans.size() <<    ; n     for (auto p : ans) cout << p <<    ; n     cout <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   cin >> t; n   while (t--) { n     int a, b, c, d; n     cin >> a >> b >> c >> d; n     cout << b <<     << c <<     << c <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m, a, l, r, c(0), d(0); n   scanf( %d%d , &n, &m); n   while (n--) { n     scanf( %d , &a); n     if (a == 1) { n       c += 1; n     } else { n       d += 1; n     } n   } n   int up = min(c, d) * 2; n   while (m--) { n     scanf( %d%d , &l, &r); n     printf((r - l) % 2 == 1 && r - l < up ?  1 n  :  0 n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int maxx(int a[2][102], int n, int t) { n   int m = 0; n   for (int i = 0; i <= n; i++) n     if (a[t][i] > m) m = a[t][i]; n   return m; n } n int main() { n   char s[102]; n   ifstream in( input.txt ); n   long long int x, y; n   cin >> x >> y; n   if (x == 999999999) { n     cout <<  Yes ; n     return 0; n   } n   cin >> s; n   if (x == 0 && y == 1 && strcmp(s,  D ) == 0) { n     cout <<  No ; n     return 0; n   } n   int a[2][102]; n   int i; n   a[0][0] = a[1][0] = 0; n   for (i = 0; i < strlen(s); i++) { n     a[0][i + 1] = a[0][i]; n     a[1][i + 1] = a[1][i]; n     if (s[i] ==  U ) n       a[1][i + 1] = a[1][i] + 1; n     else if (s[i] ==  D ) n       a[1][i + 1] = a[1][i] - 1; n     else if (s[i] ==  L ) n       a[0][i + 1] = a[0][i] - 1; n     else if (s[i] ==  R ) n       a[0][i + 1] = a[0][i] + 1; n   } n   long long int xs = a[0][strlen(s)], ys = a[1][strlen(s)]; n   long long int n; n   if (xs == 0 && ys != 0) n     n = abs(y / ys) - (maxx(a, strlen(s), 1) - ys); n   else if (ys == 0 && xs != 0) n     n = abs(x / xs) - (maxx(a, strlen(s), 0) - xs); n   else if (xs != 0 && ys != 0) n     n = abs(min(x / xs, y / ys)); n   for (long long int j = n; j <= n + 20; j++) n     for (i = 0; i <= strlen(s); i++) { n       int xem1 = (xs * j - x) - (xs - a[0][i]); n       int xem2 = (ys * j - y) - (ys - a[1][i]); n       if (xem1 == 0 && xem2 == 0) { n         cout <<  Yes ; n         return 0; n       } n     } n   cout <<  No ; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(false), cin.tie(0); n   ; n   long long n, k, i; n   cin >> n >> k; n   long long a[n], pr[n + 1]; n   map<long long, long long> f; n   for (i = 0; i < n; i++) { n     cin >> a[i]; n     f[a[i]]++; n   } n   int fl = 0; n   for (auto e : f) { n     if (e.second >= k) { n       cout <<  0 n ; n       fl = 1; n       break; n     } n   } n   if (!fl) { n     sort(a, a + n); n     pr[0] = a[0]; n     for (i = 1; i < n; i++) pr[i] = pr[i - 1] + a[i]; n     long long ans = 1e18 + 5; n     long long left, right, ex, costl, costr; n     for (i = 0; i < n; i++) { n       left = lower_bound(a, a + n, a[i]) - a; n       right = n - (upper_bound(a, a + n, a[i]) - a); n       ex = n - left - right; n       costl = left * (a[i] - 1); n       if (left) costl -= pr[left - 1]; n       costr = pr[n - 1] - right * (a[i] + 1); n       if ((n - right - 1) >= 0) costr -= pr[n - right - 1]; n       if (left + ex >= k) ans = min(ans, costl + k - ex); n       if (right + ex >= k) ans = min(ans, costr + k - ex); n       ans = min(ans, costl + costr + k - ex); n     } n     cout << ans <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 105, M = N * N; n int n; n int a[N]; n int f[N][M]; n vector<pair<int, int> > b; n int main() { n   scanf( %d , &n); n   int sum = 0; n   for (int i = 1; i <= n; i++) { n     scanf( %d , a + i); n     sum += a[i]; n   } n   sort(a + 1, a + n + 1); n   b.push_back(pair<int, int>(a[1], 1)); n   for (int i = 2; i <= n; i++) { n     if (a[i] == b.back().first) { n       b.back().second++; n     } else { n       b.push_back(pair<int, int>(a[i], 1)); n     } n   } n   int m = b.size(); n   if (m == 1) { n     printf( %d n , n); n   } else { n     f[0][0] = 1; n     int sumc = 0; n     for (int i = 0; i < m; i++) { n       int x = b[i].first, y = b[i].second; n       sumc += y; n       for (int c = sumc; c; c--) { n         for (int j = sum; j >= x; j--) { n           for (int k = 1; k * x <= j && k <= y && k <= c && f[c][j] < 2; k++) { n             f[c][j] = min(2, f[c][j] + f[c - k][j - x * k]); n           } n         } n       } n     } n     if (m == 2) { n       int ans = 0; n       for (int i = 0; i < m; i++) { n         int x = b[i].first, y = b[i].second; n         for (int j = 1; j <= y; j++) { n           if (f[j][j * x] == 1) { n             if (j < y) { n               ans = max(ans, j); n             } else { n               ans = n; n             } n           } n         } n       } n       printf( %d n , ans); n     } else { n       int ans = 0; n       for (int i = 0; i < m; i++) { n         int x = b[i].first, y = b[i].second; n         for (int j = 1; j <= y; j++) { n           if (f[j][j * x] == 1) { n             ans = max(ans, j); n           } n         } n       } n       printf( %d n , ans); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX = 5048; n vector<int> adj[MAX]; n bool used[MAX]; n int dist[MAX][MAX]; n void solve(const int test_num) { n   (void)test_num; n   int v, e; n   cin >> v >> e; n   for (int ee = 0, a, b; ee < e; ++ee) { n     cin >> a >> b; n     adj[a].push_back(b); n   } n   memset(dist, 0, sizeof(dist)); n   queue<int> que; n   for (int st = 1; st <= v; ++st) { n     que.push(st); n     while (!que.empty()) { n       const int at = que.front(); n       que.pop(); n       for (const int to : adj[at]) { n         if (dist[st][to] == 0) { n           dist[st][to] = dist[st][at] + 1; n           que.push(to); n         } n       } n     } n   } n   memset(used, false, sizeof(used)); n   int res = v; n   for (int at = 1; at <= v; ++at) { n     if (used[at]) continue; n     used[at] = true; n     int min_cycle = dist[at][at]; n     bool is_sink = true; n     for (int to = 1; to <= v; ++to) { n       if (dist[at][to] && dist[to][at]) { n         used[to] = true; n         min_cycle = min(min_cycle, dist[to][to]); n       } n       if (dist[at][to] && !dist[to][at]) { n         is_sink = false; n       } n     } n     if (is_sink && min_cycle) { n       res += 998 * min_cycle + 1; n     } n   } n   cout << res << endl; n } n void init() {} n int main() { n   ios::sync_with_stdio(false); n   cin.tie(nullptr); n   srand(1223); n   init(); n   int tests = 1; n   for (int test = 1; test <= tests; ++test) { n     solve(test); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int ans = 1e9; n int f[1000010]; n int main() { n   int n, i, j; n   scanf( %d , &n); n   for (i = 2; i <= n; i++) { n     if (!f[i]) { n       for (j = 2 * i; j <= n; j += i) { n         f[j] = i; n       } n     } n     f[i] = i - f[i] + 1; n   } n   for (i = f[n]; i <= n; i++) { n     if (f[i] < ans) ans = f[i]; n   } n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n void solve() { n   long long int n, m; n   cin >> n >> m; n   long long int st = n / 2; n   if (n & 1) st++; n   for (long long int i = (st); i < n + 1; i++) { n     if (i % m == 0) { n       cout << i; n       return; n     } n   } n   cout << -1; n } n signed main() { n   ios::sync_with_stdio(0), cin.tie(0); n   long long int tt = 1; n   for (long long int i = (0); i < tt; i++) solve(), cout <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long func(long long arr[], long long n) { n   long long ans = 0; n   for (long long i = 2; i < n; i++) { n     if (arr[i] > arr[i - 1] && arr[i] > arr[i + 1]) { n       ans++; n     } else if (arr[i] < arr[i - 1] && arr[i] < arr[i + 1]) { n       ans++; n     } n   } n   return ans; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   long long n; n   cin >> n; n   long long arr[n + 1]; n   for (long long i = 1; i <= n; i++) { n     cin >> arr[i]; n   } n   cout << func(arr, n) << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   int available[1000000]; n   int aux; n   int aux2; n   for (int i = 0; i < 1000000; ++i) { n     available[i] = -2; n   } n   for (int i = 0; i < n; ++i) { n     int k = 0; n     cin >> aux; n     cin >> aux2; n     if (!(aux % 2)) { n       if ((i - available[2]) > aux2) { n         k++; n       } n       available[2] = i; n       if ((i - available[aux / 2]) > aux2) { n         k++; n       } n       available[aux / 2] = i; n     } n     for (int j = 1; j <= sqrt(aux); j++) { n       if (!(aux % j)) { n         if ((i - available[j]) > aux2) { n           k++; n         } n         available[j] = i; n         if ((i - available[aux / j]) > aux2) { n           k++; n         } n         available[aux / j] = i; n       } n     } n     printf( %d n , k); n   } n } n


#include <bits/stdc++.h> n using namespace std; n const double pi = acos(-1); n const int N = 1e6 + 10, M = 1e7 + 10, mod = 1e9 + 7, INF = 0x3f3f3f3f, ha = 137; n int n, q; n int mx[N], a[N]; n int s[M], ls[M], rs[M]; n int rt[N]; n int cnt; n int update(int loc, int pre, int l, int r) { n   int now = ++cnt; n   s[now] = s[pre] + 1; n   ls[now] = ls[pre]; n   rs[now] = rs[pre]; n   if (l == r) return now; n   int mid = l + r >> 1; n   if (loc <= mid) n     ls[now] = update(loc, ls[pre], l, mid); n   else n     rs[now] = update(loc, rs[pre], mid + 1, r); n   return now; n } n int query(int a, int b) { n   int x = rt[a - 1], y = rt[b]; n   int ans = 0; n   int l = 0, r = n; n   while (l < r) { n     int mid = l + r >> 1; n     if (a <= mid) n       ans += s[rs[y]] - s[rs[x]], x = ls[x], y = ls[y], r = mid; n     else { n       l = mid + 1, x = rs[x], y = rs[y]; n     } n   } n   return ans; n } n int tot; n struct dat { n   int s[N << 2], lazy[N << 2]; n   void update(int a, int b, int x, int k, int l, int r) { n     if (a == l && b == r) { n       s[x] += k; n       lazy[x] += k; n       return; n     } n     int mid = l + r >> 1, ls = x << 1, rs = x << 1 | 1; n     if (lazy[x]) { n       update(l, mid, ls, lazy[x], l, mid); n       update(mid + 1, r, rs, lazy[x], mid + 1, r); n       lazy[x] = 0; n     } n     if (b <= mid) n       update(a, b, ls, k, l, mid); n     else if (a > mid) n       update(a, b, rs, k, mid + 1, r); n     else { n       update(a, mid, ls, k, l, mid); n       update(mid + 1, b, rs, k, mid + 1, r); n     } n     s[x] = max(s[ls], s[rs]); n   } n   int query(int k) { n     int x = 1; n     int l = 1, r = n; n     while (l < r) { n       int mid = l + r >> 1, ls = x << 1, rs = x << 1 | 1; n       if (lazy[x]) { n         update(l, mid, ls, lazy[x], l, mid); n         update(mid + 1, r, rs, lazy[x], mid + 1, r); n         lazy[x] = 0; n       } n       if (s[rs] >= k) n         x = rs, l = mid + 1; n       else n         x = ls, r = mid; n     } n     return l; n   } n } tr; n int f[N]; n int ss; n int main() { n   cin >> n >> q; n   for (int i = 1; i <= n; i++) { n     scanf( %d , &a[i]); n     int k = i - a[i]; n     if (k < 0) { n       rt[i] = update(a[i] = 0, rt[i - 1], 0, n); n       continue; n     } n     int t = tr.query(k); n     a[i] = f[t]; n     if (k == 0) f[++tot] = i, a[i] = i, t = tot; n     if (k > ss) { n       a[i] = 0, t = 0; n     } else n       ss++; n     if (min(tot, t)) tr.update(1, min(tot, t), 1, 1, 1, n); n     rt[i] = update(a[i], rt[i - 1], 0, n); n   } n   int l, r; n   while (q--) { n     scanf( %d%d , &l, &r); n     printf( %d n , query(l, n - r)); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxN = 200005; n int P[maxN]; n int color[maxN]; n int cycle_count = 0; n void dfs(int s) { n   color[s] = 1; n   if (color[P[s]] == 0) n     dfs(P[s]); n   else if (color[P[s]] == 1) n     ++cycle_count; n   color[s] = 2; n } n int main() { n   int n; n   cin >> n; n   int res = 1; n   for (int i = 1; i <= n; ++i) scanf( %d , &P[i]); n   for (int i = 1; i <= n; ++i) { n     int b; n     scanf( %d , &b); n     res ^= b; n   } n   for (int i = 1; i <= n; ++i) n     if (color[i] == 0) dfs(i); n   if (cycle_count > 1) res += cycle_count; n   cout << res << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int oo = ~0u >> 2, mo = (int)1e9 + 7; n const int mn = 52, mp = ((mn) * (mn)), me = mp * 4; n const int fx[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}}; n struct EDGE { n   int y, l; n } E[me]; n int g[mp], d[mp], h[mn][mn], Q[mp]; n bool a[mn][mn]; n int n, m, tt(0); n void add(int x, int y) { E[++tt].y = y, E[tt].l = g[x], g[x] = tt; } n void fill(int x, int y) { n   h[x][y] = tt; n   for (int i = 0; i <= 3; ++i) { n     int nx = x + fx[i][0], ny = y + fx[i][1]; n     if (nx < 1 || nx > n || ny < 1 || ny > m || a[x][y] != a[nx][ny] || n         h[nx][ny]) n       continue; n     fill(nx, ny); n   } n } n int calc(int x, int y) { n   int l = 0, r = 0; n   memset(&d, -1, sizeof(d)); n   d[Q[++r] = h[x][y]] = 0; n   while (l++ != r) n     for (int i = g[Q[l]], y = E[i].y; i; i = E[i].l, y = E[i].y) n       if (d[y] == -1) d[Q[++r] = y] = d[Q[l]] + 1; n   int ret = 0; n   for (int i = 1; i <= n; ++i) n     for (int j = 1; j <= m; ++j) n       if (a[i][j]) (ret = max(ret, d[h[i][j]])); n   return ret; n } n int main() { n   scanf( %d%d , &n, &m); n   bool black = 0; n   for (int i = 1; i <= n; ++i) n     for (int j = 1; j <= m; ++j) { n       char ch; n       do { n         scanf( %c , &ch); n       } while (ch !=  B  && ch !=  W ); n       black |= (a[i][j] = (ch ==  B )); n     } n   if (!black) { n     printf( 0 n ); n     return 0; n   } n   for (int i = 1; i <= n; ++i) n     for (int j = 1; j <= m; ++j) n       if (!h[i][j]) ++tt, fill(i, j); n   tt = 0; n   for (int i = 1; i <= n; ++i) n     for (int j = 1; j <= m; ++j) n       for (int k = 0; k <= 3; ++k) { n         int x = i + fx[k][0], y = j + fx[k][1]; n         if (x < 1 || x > n || y < 1 || y > m || h[i][j] == h[x][y]) continue; n         add(h[i][j], h[x][y]); n       } n   int Ans = oo; n   for (int i = 1; i <= n; ++i) n     for (int j = 1; j <= m; ++j) { n       int tmp = calc(i, j); n       (Ans = min(Ans, tmp)); n     } n   printf( %d n , Ans + 1); n } n


#include <bits/stdc++.h> n using namespace std; n const double PI = atan(1.0) * 4.0; n int in_c() { n   int c; n   while ((c = getchar()) <=    ) { n     if (!~c) throw ~0; n   } n   return c; n } n int in() { n   int x = 0, c; n   while ((unsigned int)((c = getchar()) -  0 ) >= 10) { n     if (c ==  - ) return -in(); n     if (!~c) return ~0; n   } n   do { n     x = 10 * x + (c -  0 ); n   } while ((unsigned int)((c = getchar()) -  0 ) < 10); n   return x; n } n template <class T> n struct fenwick_tree { n   vector<T> x; n   fenwick_tree(int n) : x(n, 0) {} n   T sum(int i, int j) const { n     if (i == 0) { n       T S = 0; n       for (; j >= 0; j = (j & (j + 1)) - 1) S += x[j]; n       return S; n     } else n       return sum(0, j) - sum(0, i - 1); n   } n   void add(int k, T a) { n     for (; k < (int)x.size(); k |= k + 1) x[k] += a; n   } n   void set(int k, T a) { n     T now = at(k); n     add(k, a - now); n   } n   T at(int i) const { return sum(i, i); } n }; n int main() { n   int N, K; n   while (N = in(), N != EOF) { n     K = in(); n     int center = K / 2; n     const int INF = 1 << 28; n     vector<fenwick_tree<int> > bit(K, fenwick_tree<int>(K)); n     for (int i = (0), ___e = (N); i < ___e; ++i) { n       int M = in(); n       int ax = -1, l; n       int min_score = INF; n       for (int r = (0), ___e = (K); r < ___e; ++r) n         for (int c = (0), ___e = (K - M + 1); c < ___e; ++c) { n           if (bit[r].sum(c, c + M - 1) == 0) { n             int s = 0; n             for (int j = c; j < c + M; ++j) { n               s += abs(r - center) + abs(j - center); n             } n             if (s < min_score) { n               min_score = s; n               ax = r, l = c; n             } else if (s == min_score) { n               if (ax > r || ax == r && l > c) { n                 min_score = s; n                 ax = r, l = c; n               } n             } n           } n         } n       if (ax == -1) { n         cout << -1 << endl; n       } else { n         for (int j = l; j < l + M; ++j) bit[ax].add(j, 1); n         cout << ax + 1 <<     << l + 1 <<     << l + M << endl; n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long n; n   cin >> n; n   long long maxi = LLONG_MIN; n   for (long long i = 1LL; i <= n; i++) { n     long long x, y; n     cin >> x >> y; n     maxi = max(maxi, x + y); n   } n   cout << maxi << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main(void) { n   int n; n   cin >> n; n   int *arr = (int *)malloc(sizeof(int) * n); n   for (int i = 0; i < n; ++i) cin >> arr[i]; n   int curr = arr[0], ans = 1, temp = 1; n   for (int i = 1; i < n; ++i) { n     ans = max(ans, temp); n     if (arr[i] >= curr) { n       curr = arr[i]; n       ++temp; n     } else { n       temp = 1; n       curr = arr[i]; n     } n   } n   cout << max(ans, temp); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long nChooseR(int n, int k); n long long gcd(long long a, long long b); n vector<string> split(string target, char c); n bool isPrime(long long g); n long long n, m, t, a[] = {0, 0, 1, 2, 3, 4, 5}, k, x, y, z; n long long ans; n map<pair<int, int>, int> mp; n vector<vector<int>> grid(7); n void solve(int i) { n   for (auto u : grid[i]) { n     if (mp[make_pair(a[i], a[u])] == 1) { n       z++; n       mp[make_pair(a[i], a[u])] = 0; n       mp[make_pair(a[u], a[i])] = 0; n       solve(u); n     } n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   cin >> n >> m; n   for (int i = 0; i < (int)(m); i++) { n     cin >> x >> y; n     x--; n     y--; n     grid[x].push_back(y); n     grid[y].push_back(x); n   } n   do { n     z = 0; n     for (int i = 0; i < (int)(6); i++) { n       for (int j = 0; j < (int)(6); j++) mp[make_pair(i, j)] = 1; n     } n     for (int i = 0; i < (int)(6); i++) solve(i); n     ans = max(ans, z); n   } while (next_permutation(a, a + 7)); n   cout << ans; n   return 0; n } n long long nChooseR(int n, int k) { n   if (k > n) return 0; n   if (k * 2 > n) k = n - k; n   if (k == 0) return 1; n   long long result = n; n   for (int i = 2; i <= k; ++i) { n     result *= (n - i + 1); n     result /= i; n   } n   return result; n } n long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } n vector<string> split(string target, char c) { n   string d =   ; n   vector<string> arr; n   for (auto n : target) { n     if (n != c) n       d += n; n     else if (d !=   ) n       arr.push_back(d), d =   ; n   } n   if (d !=   ) arr.push_back(d), d =   ; n   return arr; n } n bool isPrime(long long g) { n   if ((g % 2 == 0 && g > 2) || g == 1) return 0; n   for (long long i = 3; i * i <= g; i += 2) n     if (g % i == 0) return 0; n   return 1; n } n


//IaMaNanBord// n  n #include <bits/stdc++.h> n using namespace std; n  n //Macro Shorthands n #define F                       first n #define S                       second n #define f(i,n)                  for(ll i=0;i<=n;i++) n #define rf(i,n)                 for(ll i=n;i>=0;i--) n #define Cf(i,a,b)               for(ll i=a;i<=b;i++) n #define Crf(i,b,a)              for(ll i=b;i>=a;i--) n // #define endl                      n             n #define pb                      push_back n #define mp                      make_pair n #define z                       ((ll)1e9 + 7)   n #define every(it,x)             for(auto &it:x) n #define SET(it,x)               for(auto &it:x){cin>>it;} n #define ins                     insert n #define INF      ((ll)1e18) n #define Test                    ll T; cin>>T; while(T--) n #define all(v)                  v.begin(),v.end() n #define nline                   cout<<endl n #define SZ(v)                   (ll)v.size() n #define pll                     pair<ll,ll>   n   n //Macro Shorthands n #ifndef ONLINE_JUDGE n     #define revelio(args...)        { string _s = #args; replace(_s.begin(), _s.end(),  , ,    );stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); } n #else n     #define revelio(args...)        {} n #endif n  n void err(istream_iterator<string> it) {} n template<typename T, typename... Args> n void err(istream_iterator<string> it, T a, Args... args) {cerr << *it <<   =   << a << endl; err(++it, args...);} n  n //Data types n typedef long long               ll; n typedef vector<ll>              vll; n typedef vector<string>          vstr; n typedef vector<char>            vchar; n typedef vector<pair<ll,ll> >    vpll; n typedef set<ll>                 sll; n typedef set<string>             sstr; n typedef set<pair<ll,ll> >       spll; n typedef map<ll,ll>              mllll; n typedef map<string,ll>          mstrll; n typedef queue<ll>               qll; n  n  n //Functions n ll powMod(ll x,ll y)            {ll p=1; while(y){if(y%2){p=(p*x)%z;} y/=2; x=(x*x)%z;} return p;} n ll CpowMod(ll x,ll y, ll w)     {ll p=1; while(y){if(y%2){p=(p*x)%w;} y/=2; x=(x*x)%w;}return p;} n ll invMod(ll x)                 {return powMod(x,z-2);} n ll CinvMod(ll x,ll w)           {return CpowMod(x,w-2,w);} n ll gcd(ll a, ll b)              {return b == 0 ? a : gcd(b, a % b);} n // ll exGcd(ll a,ll b,ll &x, ll &y){if(b==0){y = 0;x = 1;return a;}ll xtmp, ytmp;ll g = exGcd(b,a%b,xtmp,ytmp); n //                                 x=ytmp; y = xtmp - (a/b)*ytmp;return g;} n // vll sub; n // void subSet(ll k,ll n)          {if(k==n+1){every(it,sub)cout<<it<<   ;cout<<endl;} n //                                 else{sub.pb(k);subSet(k+1,n); n //                                 sub.pop_back();subSet(k+1,n);}} n  n // vll perm; const ll N = (ll)2e6 ;bool isSelected[N]; n // void permut(ll n)               {if(perm.size()==n){every(it,perm)cout<<it<<   ;cout<<endl;} n //                                 else{Cf(i,1,n){if(isSelected[i])continue;perm.pb(i); n //                                 isSelected[i]=1;permut(n);perm.pop_back();isSelected[i] =0;}}}  n  n void solve(){ n     Test{ n         vll a(3); n         SET(it,a); n         sort(all(a)); n         ll sum = a[0] + a[1] + a[2]; n         if(sum%9){ n             cout<< NO <<endl; n         } n         else{ n             ll x = sum/9; n             if(x>a[0]){ n                 cout<< NO <<endl; n             } n             else{ n                 cout<< YES <<endl; n             } n         } n     } n } n  n  n int main(){ n     ios_base::sync_with_stdio(0) ; n     cin.tie(0) ; cout.tie(0) ; n     cout.precision(20); n  n     #ifndef ONLINE_JUDGE n     freopen( input.txt ,  r , stdin); n     freopen( output.txt ,  w , stdout); n  freopen( error.txt , w ,stderr); n     #else n      n     #endif n     solve(); n     #ifndef ONLINE_JUDGE n         cout<<  nTime Elapsed:  <<1.0*clock()/ CLOCKS_PER_SEC<<  Sec n ; n     #endif n     return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long int is_query = LLONG_MIN; n struct Line { n   long long int m, b; n   mutable function<const Line*()> succ; n   bool operator<(const Line& rhs) const { n     if (rhs.b != is_query) return m < rhs.m; n     const Line* s = succ(); n     if (!s) return 0; n     long long int x = rhs.m; n     return b - s->b < (s->m - m) * x; n   } n }; n struct HullDynamic : public multiset<Line> { n   bool bad(iterator y) { n     auto z = next(y); n     if (y == begin()) { n       if (z == end()) return 0; n       return y->m == z->m && y->b <= z->b; n     } n     auto x = prev(y); n     if (z == end()) return y->m == x->m && y->b <= x->b; n     return (x->b - y->b) * (z->m - y->m) >= (y->b - z->b) * (y->m - x->m); n   } n   void Add(long long int m, long long int b) { n     auto y = insert({m, b}); n     y->succ = [=] { return next(y) == end() ? 0 : &*next(y); }; n     if (bad(y)) { n       erase(y); n       return; n     } n     while (next(y) != end() && bad(next(y))) erase(next(y)); n     while (y != begin() && bad(prev(y))) erase(prev(y)); n   } n   long long int Query(long long int x) { n     auto l = *lower_bound((Line){x, is_query}); n     return l.m * x + l.b; n   } n }; n long long int m[200005]; n long long int cIA[200005]; n long long int cA[200005]; n int main() { n   int n; n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) scanf( %I64d , &m[i]); n   for (int i = 1; i <= n; i++) cA[i] = cA[i - 1] + m[i]; n   for (int i = 1; i <= n; i++) cIA[i] = cIA[i - 1] + i * m[i]; n   long long int Max = 0; n   HullDynamic ch; n   ch.Add(0, 0); n   for (int i = 1; i <= n; i++) { n     Max = max(Max, ch.Query(cA[i]) + cIA[i]); n     ch.Add(-i, -cIA[i] + i * cA[i]); n   } n   cout << Max << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int m, n; n   cin >> n >> m; n   int c[n]; n   for (int i = 0; i < n; i++) cin >> c[i]; n   int a[m]; n   for (int i = 0; i < m; i++) cin >> a[i]; n   int d = 0, j = 0; n   for (int i = 0; i < n; i++) { n     if (a[j] >= c[i]) { n       d++; n       j++; n     } n     if (d == m) break; n   } n   cout << d << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   long long int max = 2000000001, min = -2000000001; n   long long int x, y; n   string question; n   char answer; n   int i; n   for (i = 0; i < n; i++) { n     int tmp; n     cin >> question; n     cin >> x >> answer; n     cin.get(); n     if (question[0] ==  < ) { n       if (answer ==  Y ) { n         if (x <= max) n           if (question.size() == 2) n             max = x; n           else n             max = x - 1; n       } else { n         if (x >= min) n           if (question.size() == 2) n             min = x + 1; n           else n             min = x; n       } n     } else { n       if (question[0] ==  > ) { n         if (answer ==  Y ) { n           if (x >= min) n             if (question.size() == 2) n               min = x; n             else n               min = x + 1; n         } else { n           if (x <= max) n             if (question.size() == 2) n               max = x - 1; n             else n               max = x; n         } n       } n     } n   } n   if (min > max) { n     cout <<  Impossible  << endl; n     return 0; n   } else { n     if (max == min) n       cout << min << endl; n     else n       cout << min + 1 << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void solve() { n   int n, k; n   cin >> n >> k; n   int *arr = new int[n]; n   for (int i = 0; i < n; i++) cin >> arr[i]; n   int res = 0; n   for (int i = 0; i < n - 1; i++) { n     int k1 = arr[i] + arr[i + 1]; n     if (k1 < k) { n       arr[i + 1] += k - k1; n       res += k - k1; n     } n   } n   cout << res <<   n ; n   for (int i = 0; i < n; i++) cout << arr[i] <<    ; n } n int main() { n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void solve(int* arr, int n) { n   int max_sum = 0; n   int answer = 0; n   for (int i = 1; i <= 30; i++) { n     int current = 0; n     max_sum = 0; n     for (int j = 0; j < n; j++) { n       if (arr[j] > i) { n         current = 0; n         continue; n       } n       current = current + arr[j]; n       if (current < 0) { n         current = 0; n       } n       max_sum = max(current, max_sum); n     } n     answer = max(answer, max_sum - i); n   } n   cout << answer << endl; n } n int main() { n   int n; n   cin >> n; n   int arr[200005]; n   for (int i = 0; i < n; i++) { n     cin >> arr[i]; n   } n   solve(arr, n); n } n


#include <bits/stdc++.h> n using namespace std; n #pragma comment(linker,  /STACK:1024000000,1024000000 ) n int _MAX(int a, int b) { return a > b ? a : b; } n int _MIN(int a, int b) { return a > b ? b : a; } n int Scan() { n   int res = 0, flag = 0; n   char ch; n   if ((ch = getchar()) ==  - ) n     flag = 1; n   else if (ch >=  0  && ch <=  9 ) n     res = ch -  0 ; n   while ((ch = getchar()) >=  0  && ch <=  9 ) res = res * 10 + (ch -  0 ); n   return flag ? -res : res; n } n void Out(int a) { n   if (a < 0) { n     putchar( - ); n     a = -a; n   } n   if (a >= 10) Out(a / 10); n   putchar(a % 10 +  0 ); n } n long long a[100005][2]; n long long dis(long long x1, long long y1, long long x2, long long y2) { n   return (x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1); n } n int main() { n   long long n, px, py, ma = 0; n   double mi = 1e16; n   scanf( %lld%lld%lld , &n, &px, &py); n   for (int i = 1; i <= n; ++i) { n     scanf( %lld%lld , &a[i][0], &a[i][1]); n     long long d = dis(a[i][0], a[i][1], px, py); n     mi = min(mi, (double)d); n     ma = max(ma, d); n   } n   a[n + 1][0] = a[1][0], a[n + 1][1] = a[1][1]; n   for (int i = 1; i <= n; ++i) { n     long long A2 = dis(px, py, a[i][0], a[i][1]); n     long long B2 = dis(px, py, a[i + 1][0], a[i + 1][1]); n     long long C2 = dis(a[i][0], a[i][1], a[i + 1][0], a[i + 1][1]); n     double A = sqrt(A2), B = sqrt(B2), C = sqrt(C2); n     if (C2 + B2 > A2 && C2 + A2 > B2) { n       double P = (A + B + C) / 2; n       double S = sqrt(P * (P - A) * (P - B) * (P - C)); n       double H = S / C * 2; n       mi = min(mi, H * H); n     } n   } n   printf( %.10lf n , acos(-1.0) * (ma - mi)); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, m, x, y, a, b, times, red, t3; n long long k; n void work3() { n   long long t1, t2; n   if (red == 0) { n     times--; n     red = m * 2 * (n - 1); n   } n   if (x != 1 && x != n) n     t3 = 2 * times; n   else n     t3 = times; n   if (red > n * m) { n     t3++; n     red -= n * m; n     a = red / m; n     b = red % m; n     if (b != 0) n       a++; n     else n       b = m; n     if (n - a == x) { n       if (y <= b) t3 += 1; n     } else if (n - a < x) { n       if (x != n) t3 += 1; n     } n     t1 = (times + 1) * 2; n     t2 = times + 1; n   } else { n     a = red / m; n     b = red % m; n     if (b != 0) n       a++; n     else n       b = m; n     if (a == x) { n       if (y <= b) n         t3 += 1; n       else n         t3 += 0; n     } else if (a > x) n       t3 += 1; n     if (a > 1) { n       t1 = times * 2 + 1; n       if (a < n || (a == n && b != m)) n         t2 = times; n       else n         t2 = times + 1; n     } else { n       t1 = times * 2; n       if (t1 == 0) t1++; n       t2 = times; n     } n   } n   cout << t1 <<     << t2 <<     << t3 << endl; n } n int main() { n   cin >> n >> m >> k >> x >> y; n   if (n > 2) { n     times = k / (m * 2 * (n - 1)); n     red = k % (m * 2 * (n - 1)); n     work3(); n   } else if (n == 1) { n     long long t2; n     times = k / (n * m); n     red = k % (n * m); n     if (red == 0) { n       red = n * m; n       times--; n     } n     if (y <= red) n       t3 = times + 1; n     else n       t3 = times; n     if (red == m) n       t2 = times + 1; n     else n       t2 = times; n     cout << times + 1 <<     << t2 <<     << t3 << endl; n   } else if (n == 2) { n     long long t2; n     times = k / (n * m); n     red = k % (n * m); n     if (red == 0) { n       red = n * m; n       times--; n     } n     a = red / m; n     b = red % m; n     if (b != 0) n       a++; n     else n       b = m; n     if (x > a) { n       t3 = times; n     } else if (x == a) { n       if (y <= b) n         t3 = times + 1; n       else n         t3 = times; n     } else if (x < a) { n       t3 = times + 1; n     } n     if (a == n && b == m) n       t2 = times + 1; n     else n       t2 = times; n     cout << times + 1 <<     << t2 <<     << t3 << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int max_n = 1500555, inf = 1000111222; n struct tree { n   long long a[4 * max_n], f[4 * max_n]; n   void clr() { n     memset(a, 0, sizeof(a)); n     memset(f, 0, sizeof(f)); n   } n   void push(int v, int l, int r) { n     if (f[v] != 0) { n       f[2 * v] += f[v]; n       f[2 * v + 1] += f[v]; n       int mid = (l + r) / 2; n       a[2 * v] += (mid - l + 1) * f[v]; n       a[2 * v + 1] += (r - mid) * f[v]; n       f[v] = 0; n     } n   } n   void update(int v, int tl, int tr, int l, int r, long long value) { n     if (tl == l && tr == r) { n       a[v] += (r - l + 1) * value; n       f[v] += value; n       return; n     } n     push(v, tl, tr); n     int mid = (tl + tr) / 2; n     if (r <= mid) { n       update(2 * v, tl, mid, l, r, value); n     } else if (l > mid) { n       update(2 * v + 1, mid + 1, tr, l, r, value); n     } else { n       update(2 * v, tl, mid, l, mid, value); n       update(2 * v + 1, mid + 1, tr, mid + 1, r, value); n     } n     a[v] = (a[2 * v] + a[2 * v + 1]); n   } n   long long get_sum(int v, int tl, int tr, int l, int r) { n     if (l > r) { n       return 0; n     } n     if (tl == l && tr == r) { n       return a[v]; n     } n     push(v, tl, tr); n     int mid = (tl + tr) / 2; n     if (r <= mid) { n       return get_sum(2 * v, tl, mid, l, r); n     } n     if (l > mid) { n       return get_sum(2 * v + 1, mid + 1, tr, l, r); n     } n     return get_sum(2 * v, tl, mid, l, mid) + n            get_sum(2 * v + 1, mid + 1, tr, mid + 1, r); n   } n }; n char buf[max_n]; n string read() { n   scanf( %s , buf); n   return buf; n } n void get_z_function(const string &s, int z[]) { n   z[0] = 0; n   int l = 0, r = 0; n   for (int i = 1; i < s.length(); ++i) { n     z[i] = 0; n     if (i <= r) { n       z[i] = min(z[i - l], r - i + 1); n     } n     while (i + z[i] < s.length() && s[i + z[i]] == s[z[i]]) { n       ++z[i]; n     } n     if (i + z[i] - 1 > r) { n       r = i + z[i] - 1; n       l = i; n     } n   } n } n int n, m, z[2][max_n], mx[2][max_n], cnt[2][max_n]; n string a[2], s, rs; n long long ans; n tree t; n vector<int> v[max_n]; n void proc1() { n   t.clr(); n   for (int i = 0; i < max_n; ++i) { n     v[i].clear(); n   } n   for (int i = 0; i < n; ++i) { n     if (mx[0][i]) { n       v[i + m - 1].push_back(max(1, m - mx[0][i])); n     } n   } n   for (int i = 0; i < n; ++i) { n     t.update(1, 0, m, 0, mx[1][i], 1); n   } n   for (int i = 0; i < n; ++i) { n     for (int l : v[i]) { n       ans -= t.get_sum(1, 0, m, l, m - 1); n     } n     t.update(1, 0, m, 0, mx[1][i], -1); n   } n } n void proc2() { n   t.clr(); n   for (int i = 0; i < max_n; ++i) { n     v[i].clear(); n   } n   for (int i = 0; i < n; ++i) { n     if (mx[1][i]) { n       v[i + 1].push_back(max(1, m - mx[1][i])); n     } n   } n   for (int i = 0; i < n; ++i) { n     t.update(1, 0, m, 0, mx[0][i], 1); n   } n   for (int i = 0; i < n; ++i) { n     for (int l : v[i]) { n       ans -= t.get_sum(1, 0, m, l, m - 1); n     } n     t.update(1, 0, m, 0, mx[0][i], -1); n   } n } n int get_sum(int tp, int l, int r) { n   if (!l) { n     return cnt[tp][r]; n   } n   return cnt[tp][r] - cnt[tp][l - 1]; n } n int main() { n   scanf( %d%d , &n, &m); n   a[0] = read(); n   a[1] = read(); n   s = read(); n   rs = s; n   reverse(rs.begin(), rs.end()); n   get_z_function(s +  #  + a[0], z[0]); n   string ra1 = a[1]; n   reverse(ra1.begin(), ra1.end()); n   get_z_function(rs +  #  + ra1, z[1]); n   for (int i = s.length() + 1; i <= s.length() + n; ++i) { n     mx[0][i - (s.length() + 1)] = z[0][i]; n     mx[1][n - 1 - (i - (s.length() + 1))] = z[1][i]; n   } n   proc1(); n   proc2(); n   for (int i = 0; i < 2; ++i) { n     for (int j = 0; j < n; ++j) { n       ++cnt[i][mx[i][j]]; n     } n     for (int j = 1; j <= m; ++j) { n       cnt[i][j] += cnt[i][j - 1]; n     } n   } n   for (int i = 1; i < m; ++i) { n     const int s0 = get_sum(0, i, m); n     const int s1 = get_sum(1, m - i, m); n     ans += 1LL * s0 * s1; n   } n   printf( %I64d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   std::ios::sync_with_stdio(false); n   std::cin.tie(0); n   int a, b, c; n   cin >> a >> b >> c; n   int s = 0; n   int min = a < b ? a : b; n   int max = a > b ? a : b; n   s += min; n   if (c > (max + min)) n     s += (max + min); n   else n     s += c; n   if ((c + min) < max) n     s += c + min; n   else n     s += max; n   cout << s << endl; n } n


#include <bits/stdc++.h> n const long long kot = LLONG_MAX; n using kk = long double; n const long long int alpha = 1e18; n using namespace std; n int gcd(long long int a, long long int b) { n   if (a == 0) return b; n   if (b == 0) return a; n   if (a == b) return a; n   if (a > b) return gcd(a - b, b); n   return gcd(a, b - a); n } n int largest(long long int arr[], long long int n) { n   return *max_element(arr, arr + n); n } n long long int lcm(long long int a, long long int b) { n   return (a * b) / gcd(a, b); n } n void sieve(bool primes[], int x) { n   primes[1] = false; n   for (int i = 2; i * i <= x; i++) { n     if (primes[i] == true) { n       for (int j = 2; j * i <= x; j++) primes[i * j] = false; n     } n   } n } n long long int power(long long int x, unsigned long long int y, n                     long long int p) { n   long long int res = 1; n   x = x % p; n   while (y > 0) { n     if (y & 1) res = (res * x) % p; n     y = y >> 1; n     x = (x * x) % p; n   } n   return res; n } n class gfg { n  public: n   int sumDigits(int no) { return no == 0 ? 0 : no % 10 + sumDigits(no / 10); } n }; n bool isPerfectSquare(long double x) { n   long double sr = sqrt(x); n   return ((sr - floor(sr)) == 0); n } n bool comp(int a, int b) { return (a < b); } n vector<long long int> ve; n void divisors(long long int n) { n   for (int i = 1; i <= sqrt(n); i++) { n     if (n % i == 0) { n       if (n / i == i) n         ve.emplace_back(i); n       else n         ve.emplace_back(i); n       ve.emplace_back(n / i); n     } n   } n } n bool isPrime(long long int n) { n   if (n == 1) { n     return false; n   } n   long long int i = 2; n   while (i * i <= n) { n     if (n % i == 0) { n       return false; n     } n     i += 1; n   } n   return true; n } n int gcdofarray(long long int v[], long long int n) { n   long long int result = v[0]; n   for (long long int i = 1; i < n; i++) result = gcd(v[i], result); n   return result; n } n int sumofdigits(long long int n) { n   long long int sum = 0; n   while (n > 0) { n     sum += n % 10; n     n /= 10; n   } n   return sum; n } n bool powertwo(long long int x) { return x && (!(x & (x - 1))); } n long long int finduncommonsubsequence(string str, string s) { n   if (!str.compare(s)) { n     return 0; n   } n   return max(str.length(), s.length()); n } n void reversec(string str) { n   for (long long int i = str.length() - 1; i >= 0; i--) cout << str[i]; n } n long long int subCount(long long int arr[], long long int n, long long int k) { n   long long int mod[k]; n   memset(mod, 0, sizeof(mod)); n   long long int cumSum = 0; n   for (long long int i = 0; i < n; i++) { n     cumSum *= arr[i]; n     mod[((cumSum % k) + k) % k]++; n   } n   long long int result = 0; n   for (long long int i = 0; i < k; i++) n     if (mod[i] > 1) result += (mod[i] * (mod[i] - 1)) / 2; n   result += mod[0]; n   return result; n } n void solve() { n   long long int t = 1; n   while (t--) { n     long long int n; n     cin >> n; n     long long int arr[n]; n     long long int i, sum = 0; n     for (i = 0; i < n; i++) { n       cin >> arr[i]; n       sum += arr[i]; n     } n     long long int j = 0, k = 0; n     while (j < n) { n       if (j % 2 == 0) { n         k += arr[j] / 2; n       } else { n         k += arr[j] - arr[j] / 2; n       } n       j++; n     } n     cout << min(k, sum - k) <<   n ; n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   ; n   solve(); n } n


#include <bits/stdc++.h> n using namespace std; n int d[1005][1005], sum, res, s, n; n int main() { n   scanf( %d , &n); n   for (int res = 3; res <= 100; res++) { n     memset(d, 0, sizeof(d)), sum = 0; n     for (int i = 1; i <= res; i++) { n       for (int j = 1; j < i; j++) { n         if (sum <= n) { n           int now = 0; n           for (int k = 1; k <= res; k++) n             if (i != k and j != k and d[i][k] and d[j][k]) now++; n           if (sum + now <= n) { n             sum += now; n             d[i][j] = d[j][i] = 1; n           } n           if (sum == n) { n             cout << res << endl; n             for (int i1 = 1; i1 <= res; i1++) { n               for (int j1 = 1; j1 <= res; j1++) cout << d[i1][j1]; n               printf(  n ); n             } n             return 0; n           } n         } n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 5e5 + 5; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   int T; n   cin >> T; n   while (T--) { n     int n, m; n     cin >> n >> m; n     if (n % m == 0) n       cout <<  YES n ; n     else n       cout <<  NO n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n void past_code(); n void file() {} n long long gcd(long long x, long long y) { n   if (y == 0) return x; n   return gcd(y, x % y); n } n long long todic(string z) { n   long long sum = 0; n   long long j = 1; n   for (long long i = 0; i < z.length(); i++) { n     sum += (z[i] -  0 ) * j; n     j *= 2; n   } n   return sum; n } n string tobin(long long a) { n   string x; n   while (a != 0) { n     x += to_string(a % 2); n     a /= 2; n   } n   return x; n } n bool isPrime(long long n) { n   if (n <= 1) return false; n   for (long long i = 2; i <= sqrt(n); i++) n     if (n % i == 0) return false; n   return true; n } n string towlo(string x) { n   string h; n   for (long long i = 0; i < x.length(); i++) { n     h += tolower(x[i]); n   } n   return h; n } n bool comp(pair<long long, long long> a, pair<long long, long long> b) { n   return a.second > b.second; n } n inline void read(int &x) { n   x = 0; n   char c = getchar(); n   int f = 1; n   while (c <  0  || c >  9 ) { n     if (c ==  - ) f = -1; n     c = getchar(); n   } n   while (c >=  0  && c <=  9 ) { n     x = 10 * x + c -  0 ; n     c = getchar(); n   } n   x *= f; n } n long long fact(long long o) { n   if (o == 0) return 1; n   return o * fact(o - 1); n } n long long sumd(long long x) { n   long long sum = 0; n   while (x != 0) { n     sum += x % 10; n     x /= 10; n   } n   return sum; n } n bool com(pair<long long, long long> a, pair<long long, long long> b) { n   return a.second > b.second; n } n bool vis[505][505]; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   string x; n   cin >> x; n   int k; n   cin >> k; n   map<string, int> m; n   string h[] = { January ,    February ,  March ,     April , n                  May ,        June ,      July ,      August , n                  September ,  October ,   November ,  December }; n   m[ January ] = 0; n   m[ June ] = 5; n   m[ November ] = 10; n   m[ February ] = 1; n   m[ July ] = 6; n   m[ December ] = 11; n   m[ March ] = 2; n   m[ August ] = 7; n   m[ April ] = 3; n   m[ September ] = 8; n   m[ May ] = 4; n   m[ October ] = 9; n   cout << h[(k + m[x]) % 12] <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n void print(const T& t) { n   cout << t <<   n ; n } n template <typename T, typename U, typename... ARGS> n void print(const T& t, const U& u, const ARGS&... args) { n   cout << t <<    ; n   print(u, args...); n } n signed main() { n   ios_base::sync_with_stdio(false), cin.tie(nullptr); n   long long tc; n   cin >> tc; n   while (tc--) { n     long long x, y, n; n     cin >> x >> y >> n; n     long long z = (n / x) * x; n     while (z + y > n) { n       z -= x; n     } n     print(z + y); n   } n   return 0; n } n


#include<bits/stdc++.h> n using namespace std; n #define l1 long long n void solve() { n     int n; cin>>n; n     vector<int> v(n); n     for(auto &i:v) cin>>i; n     l1 sum = 0; n     l1 need = 0; n     for(int i=0;i<n;i++) { n         sum+=v[i]; n         need+=i; n         if(sum<need) {cout<< NO <<endl; return;} n     } n     cout<< YES <<endl; n      n } n int main() { n     int t; cin>>t; n     while(t--) { n         solve(); n     } n }


#include <bits/stdc++.h> n using namespace std; n const int N = 500005; n const int mod = 1e9 + 7; n int n, m, l[N], r[N], f[N], sum[N]; n vector<int> g[N]; n vector<int> cmp; n int main() { n   scanf( %d %d , &n, &m); n   for (int i = 0; i < m; ++i) { n     scanf( %d %d , l + i, r + i); n     cmp.push_back(r[i]); n     cmp.push_back(l[i]); n   } n   sort(cmp.begin(), cmp.end()); n   cmp.erase(unique(cmp.begin(), cmp.end()), cmp.end()); n   if (cmp.empty() || cmp[0] != 0 || cmp.back() != n) { n     cout << 0 << endl; n     return 0; n   } n   for (int i = 0; i < m; ++i) { n     l[i] = lower_bound(cmp.begin(), cmp.end(), l[i]) - cmp.begin(); n     r[i] = lower_bound(cmp.begin(), cmp.end(), r[i]) - cmp.begin(); n     g[r[i]].push_back(l[i]); n   } n   f[0] = sum[0] = 1; n   for (int i = 1; i < (int)cmp.size(); ++i) { n     for (auto& pos : g[i]) { n       int add = sum[i - 1]; n       if (pos > 0) add = (add + (mod - sum[pos - 1])) % mod; n       f[i] = (f[i] + add) % mod; n     } n     sum[i] = (f[i] + sum[i - 1]) % mod; n   } n   cout << f[cmp.size() - 1] << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1000 * 100 + 10, mod = 100000007; n int a[N]; n int n; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   ; n   cin >> n; n   for (int i = 0; i < n; i++) cin >> a[i]; n   vector<int> ans; n   for (int i = 0; i < n; i++) { n     int val = a[i]; n     int pos = lower_bound(ans.begin(), ans.end(), val) - ans.begin(); n     if (pos < int(ans.size())) n       ans[pos] = val; n     else n       ans.push_back(val); n   } n   cout << int(ans.size()) << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int64_t Nmax = 2e5 + 10; n const int64_t mod = 1000000007; n vector<int64_t> prime; n int64_t is_power_of_two(int64_t a) { return a && (!(a & (a - 1))); } n int64_t isperfectsquare(int64_t a) { n   double b = sqrt(a); n   return (b - ceil(b) == 0); n } n int64_t pow(int64_t a, int64_t b, int64_t m) { n   a = a % m; n   int64_t res = 1; n   while (b > 0) { n     if (b & 1) { n       res = res * a % m; n     } n     a = a * a % m; n     b = b / 2; n   } n   return res; n } n int64_t mod_add(int64_t a, int64_t b, int64_t m) { n   a = a % m; n   b = b % m; n   return (((a + b) % m) + m) % m; n } n int64_t mod_mul(int64_t a, int64_t b, int64_t m) { n   a = a % m; n   b = b % m; n   return (((a * b) % m) + m) % m; n } n int64_t mod_sub(int64_t a, int64_t b, int64_t m) { n   a = a % m; n   b = b % m; n   return (((a - b) % m) + m) % m; n } n int64_t mod_div(int64_t a, int64_t b, int64_t m) { n   a = a % m; n   b = b % m; n   return (mod_mul(a, pow(b, m - 2, m), m)); n } n void sieve(int64_t n) { n   bool isprime[n + 1]; n   memset(isprime, true, sizeof(isprime)); n   prime.push_back(2); n   for (int64_t i = 3; i <= sqrt(n); i += 2) { n     if (isprime[i]) { n       for (int64_t j = i * i; j <= n; j += i) { n         isprime[j] = false; n       } n     } n   } n   for (int64_t i = 3; i <= n; i += 2) { n     if (isprime[i]) { n       prime.push_back(i); n     } n   } n } n vector<pair<int64_t, int64_t>> Getprimefactors(int64_t n) { n   vector<pair<int64_t, int64_t>> pr; n   for (int64_t i = 2; i <= sqrt(n); i++) { n     int64_t cnt = 0; n     while (n % i == 0) { n       cnt++; n       n /= i; n     } n     if (cnt) pr.push_back({i, cnt}); n   } n   if (n > 1) { n     pr.push_back({n, 1}); n   } n   return pr; n } n void solve() { n   int64_t n, k, ans = INT_MAX; n   cin >> n >> k; n   string s; n   cin >> s; n   char rgb[] = { R ,  G ,  B }; n   for (int64_t i = 0; i <= n - k; i++) { n     string tmp = s.substr(i, k); n     int64_t val1 = 0, val2 = 0, val3 = 0; n     for (int64_t j = 0; j <= k - 1; j++) { n       if (tmp[j] != rgb[(j) % 3]) val1++; n       if (tmp[j] != rgb[(j + 1) % 3]) val2++; n       if (tmp[j] != rgb[(j + 2) % 3]) val3++; n     } n     ans = min({val1, val2, val3, ans}); n   } n   cout << ans <<   n ; n } n int32_t main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int64_t t = 1; n   cin >> t; n   while (t--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int Maxn = 1e5 + 2; n const int Nn = 251; n char s[Maxn]; n int a[Maxn][26], f[Nn][Nn][Nn], length[3], i, j, k, l, Min, n, m, id, p; n char ss[3][Nn], op, c, sss[Nn]; n void done() { n   for (int i = 0; i < 26; i++) { n     a[n][i] = n + 1; n     a[n + 1][i] = n + 1; n   } n   for (int i = n - 1; i >= 0; i--) { n     for (int j = 0; j < 26; j++) a[i][j] = a[i + 1][j]; n     a[i][s[i] -  a ] = i + 1; n   } n   f[0][0][0] = 0; n } n int pos(int i, int j, int k, char c) { return a[f[i][j][k]][c -  a ]; } n void func(int i, int j, int k) { n   f[i][j][k] = n + 2; n   if (i > 0) { n     Min = pos(i - 1, j, k, ss[0][i]); n     if (Min < f[i][j][k]) f[i][j][k] = Min; n   } n   if (j > 0) { n     Min = pos(i, j - 1, k, ss[1][j]); n     if (Min < f[i][j][k]) f[i][j][k] = Min; n   } n   if (k > 0) { n     Min = pos(i, j, k - 1, ss[2][k]); n     if (Min < f[i][j][k]) f[i][j][k] = Min; n   } n } n int main() { n   scanf( %d%d , &n, &m); n   scanf( %s n , s); n   done(); n   for (l = 0; l < m; l++) { n     scanf( %c , &op); n     switch (op) { n       case  + : n         scanf( %d %c , &id, &c); n         gets(sss); n         id %= 3; n         ++length[id]; n         ss[id][length[id]] = c; n         if (id == 0) { n           for (j = 0; j <= length[1]; j++) n             for (k = 0; k <= length[2]; k++) func(length[id], j, k); n         } n         if (id == 1) { n           for (i = 0; i <= length[0]; i++) n             for (k = 0; k <= length[2]; k++) func(i, length[id], k); n         } n         if (id == 2) { n           for (i = 0; i <= length[0]; i++) n             for (j = 0; j <= length[1]; j++) func(i, j, length[id]); n         } n         break; n       case  - : n         scanf(  %d , &id); n         gets(sss); n         id %= 3; n         --length[id]; n         break; n     } n     p = f[length[0]][length[1]][length[2]]; n     if (p <= n) n       printf( YES n ); n     else n       printf( NO n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> graph[100001]; n int color[100001]; n vector<int> b, w; n void bfs(int v) { n   queue<int> q; n   q.push(v); n   color[v] = 1; n   b.push_back(v); n   while (!q.empty()) { n     int v = q.front(); n     q.pop(); n     for (int u : graph[v]) { n       if (color[u] == 0) { n         if (color[v] == 1) n           color[u] = 2, w.push_back(u); n         else n           color[u] = 1, b.push_back(u); n         q.push(u); n       } n       if (color[v] == color[u]) { n         printf( -1 ); n         exit(0); n       } n     } n   } n } n int main() { n   int n, m; n   scanf( %d %d , &n, &m); n   while (m--) { n     int a, b; n     scanf( %d %d , &a, &b); n     graph[a].push_back(b); n     graph[b].push_back(a); n   } n   for (int i = 1; i <= n; i++) n     if (color[i] == 0) bfs(i); n   printf( %d n , (int)b.size()); n   for (int i = 0; i < b.size(); i++) printf( %d  , b[i]); n   printf(  n%d n , (int)w.size()); n   for (int i : w) printf( %d  , i); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n using vi = vector<int>; n using vvi = vector<vi>; n using ii = pair<int, int>; n double x[60000], v[60000]; n int n; n bool f(double t) { n   vector<tuple<double, int> > a; n   for (int i = 0; i < n; ++i) { n     a.emplace_back(x[i] - v[i] * t, 0); n     a.emplace_back(x[i] + v[i] * t + 1e-7, 1); n   } n   sort(a.begin(), a.end()); n   int m = 0; n   for (int i = 0; i < n; ++i) { n     auto [x, e] = a[i]; n     if (e == 0) n       m++; n     else n       m--; n     if (m == n) return true; n   } n   return false; n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cin >> n; n   for (int i = 0; i < n; ++i) cin >> x[i]; n   for (int i = 0; i < n; ++i) cin >> v[i]; n   double lo = 0, hi = 1e9; n   while (hi - lo > 1e-7) { n     double mid = (hi + lo) / 2; n     if (f(mid)) n       hi = mid; n     else n       lo = mid; n   } n   cout << setprecision(15) << fixed << lo; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   int count = 0; n   for (int i = n - 1; i > 0; i--) { n     if (n % i == 0) count++; n   } n   cout << count; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 0x3f3f3f3f; n const long long LINF = 0x3f3f3f3f3f3f3f3fll; n vector<int> a; n vector<int> b; n vector<int> c; n vector<vector<int> > g; n int n, m, k; n int dp[5005][5005]; n int solve(int at, int homens) { n   if (at == n) { n     return 0; n   } n   if (dp[at][homens] != -1) { n     return dp[at][homens]; n   } n   if (a[at] > homens) { n     return dp[at][homens] = -INF; n   } n   int novoHomens = homens + b[at]; n   int resposta = solve(at + 1, novoHomens); n   int valor = 0; n   int quant = 0; n   for (int viz : g[at]) { n     quant++; n     valor += viz; n     if (novoHomens - quant >= 0) { n       resposta = max(resposta, valor + solve(at + 1, novoHomens - quant)); n     } n   } n   return dp[at][homens] = resposta; n } n bool comp(int a, int b) { return c[a] > c[b]; } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cin >> n >> m >> k; n   a.resize(n); n   b.resize(n); n   c.resize(n); n   for (int I = 0; I < n; I++) { n     cin >> a[I] >> b[I] >> c[I]; n   } n   g.resize(n); n   int x, y; n   vector<int> conexoes(n); n   for (int I = 0; I < n; I++) { n     conexoes[I] = I; n   } n   for (int I = 0; I < m; I++) { n     cin >> x >> y; n     x--; n     y--; n     conexoes[y] = max(conexoes[y], x); n   } n   for (int I = 0; I < n; I++) { n     g[conexoes[I]].push_back(c[I]); n   } n   for (int I = 0; I < n; I++) { n     sort(g[I].rbegin(), g[I].rend()); n   } n   memset(dp, -1, sizeof(dp)); n   int resposta = solve(0, k); n   if (resposta < 0) { n     cout << -1 <<   n ; n   } else { n     cout << resposta <<   n ; n   } 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 <<   n ; 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 template <typename T> n using minpq = priority_queue<T, vector<T>, greater<T>>; n template <typename T> n using maxpq = priority_queue<T>; n inline long long CC(long long n, long long y) { n   return (((n) + (y - 1) - 1) / (y - 1)) - (((n) + (y)-1) / (y)); n } n inline long long FF(long long n, long long y) { return n / y - n / (y + 1); } n inline long long __gcd(long long a, long long b) { n   return !b ? a : __gcd(b, a % b); n } n inline int add(int a, int b, int p = 1000000007) { n   int c = a + b; n   if (c >= p) c -= p; n   return c; n } n inline int sub(int a, int b, int p = 1000000007) { n   int c = a - b; n   if (c < 0) c += p; n   return c; n } n inline int mul(int a, int b, int p = 1000000007) { return (a * 1ll * b) % p; } n long long a, b, k, L; n long long lcm(long long a, long long b) { return a / __gcd(a, b) * b; } n long long bfs(long long src, long long dest) { n   __f( src, dest , src, dest); n   queue<long long> q; n   vector<bool> vis(src - dest + 1); n   q.push(src); n   q.push(0); n   vis[src - dest] = 1; n   while (1) { n     long long u = q.front(); n     q.pop(); n     long long d = q.front(); n     q.pop(); n     if (u == dest) return d; n     if (!vis[u - 1 - dest]) q.push(u - 1), q.push(d + 1); n     for (long long i = 2; i <= k; i++) { n       long long v = u / i * i; n       if (v >= dest && !vis[v - dest]) { n         vis[v - dest] = 1; n         q.push(v); n         q.push(d + 1); n       } n     } n   } n } n int32_t main() { n   ios_base::sync_with_stdio(false), cin.tie(NULL); n   clock_t clk = clock(); n   cerr <<  I will return... n ; n   cin >> a >> b >> k; n   if (k == 2) { n     cout << a - b; n     return 0; n   } n   L = 1; n   for (long long i = (2); i < (k + 1); i++) L = lcm(L, i); n   long long ans = 0; n   long long cnt = a / L - (b - 1) / L; n   __f( L, cnt , L, cnt); n   if (cnt) { n     long long m = bfs(L, 0); n     ans = m * (cnt - 1); n     __f( ans , ans); n   } n   if (!cnt) { n     ans += bfs(a, b); n     __f( ans , ans); n   } else { n     ans += bfs(a, a / L * L); n     ans += bfs((((b) + (L)-1) / (L)) * L, b); n     __f( ans , ans); n   } n   cout << ans <<   n ; n   cerr <<  ...don t you ever hang your head. n ; n   cerr <<  Time (in ms):   << double(clock() - clk) * 1000.0 / CLOCKS_PER_SEC n        <<   n ; n } n


#include <bits/stdc++.h> n int main() { n   int n; n   while (std::cin >> n) { n     if (n % 2 == 0) { n       std::cout << -1 << std::endl; n       continue; n     } n     std::vector<int> a(n), b(n), c(n), was(n); n     for (int i = 0; i < n; ++i) { n       a[i] = i; n       b[i] = (i + 1) % n; n       c[i] = (a[i] + b[i]) % n; n       assert(!was[c[i]]); n       was[c[i]] = 1; n     } n     for (auto it : a) { n       std::cout << it <<    ; n     } n     std::cout << std::endl; n     for (auto it : b) { n       std::cout << it <<    ; n     } n     std::cout << std::endl; n     for (auto it : c) { n       std::cout << it <<    ; n     } n     std::cout << std::endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int gridSize = 1000; n long long getPairs(int n) { n   long long result = 0; n   for (int i = 1; i < n; i++) result += n - i; n   return result; n } n int main() { n   std::cout.sync_with_stdio(false); n   int n, i, x, y, j; n   cin >> n; n   bool a[gridSize + 1][gridSize + 1]; n   for (i = 1; i <= gridSize; i++) n     for (j = 1; j <= gridSize; j++) a[i][j] = false; n   for (i = 0; i < n; i++) { n     cin >> x >> y; n     a[x][y] = true; n   } n   long long result = 0, attacking = 0; n   pair<int, int> startPoint(1, 1); n   for (i = 1; i <= gridSize; i++) { n     attacking = 0; n     startPoint = make_pair(1, i); n     do { n       if (a[startPoint.first][startPoint.second]) attacking++; n       startPoint.second++; n       startPoint.first++; n     } while (startPoint.second <= gridSize && startPoint.first <= gridSize); n     if (attacking > 1) result += getPairs(attacking); n   } n   for (i = 2; i <= gridSize; i++) { n     attacking = 0; n     startPoint = make_pair(i, 1); n     do { n       if (a[startPoint.first][startPoint.second]) attacking++; n       startPoint.second++; n       startPoint.first++; n     } while (startPoint.second <= gridSize && startPoint.first <= gridSize); n     if (attacking > 1) result += getPairs(attacking); n   } n   for (i = gridSize; i >= 1; i--) { n     attacking = 0; n     startPoint = make_pair(1, i); n     do { n       if (a[startPoint.first][startPoint.second]) attacking++; n       startPoint.second--; n       startPoint.first++; n     } while (startPoint.second >= 1 && startPoint.first <= gridSize); n     if (attacking > 1) result += getPairs(attacking); n   } n   for (i = 2; i <= gridSize; i++) { n     attacking = 0; n     startPoint = make_pair(i, gridSize); n     do { n       if (a[startPoint.first][startPoint.second]) attacking++; n       startPoint.second--; n       startPoint.first++; n     } while (startPoint.second >= 1 && startPoint.first <= gridSize); n     if (attacking > 1) result += getPairs(attacking); n   } n   cout << result; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   vector<int> vt; n   for (int i = 0; i < n; i++) { n     int v; n     cin >> v; n     vt.push_back(v); n   } n   sort(vt.begin(), vt.end()); n   int ans = 0; n   int prev = vt[0]; n   for (int i = 1; i < n; i++) { n     int cur = vt[i]; n     int diff = cur - prev; n     if (diff > 1) { n       ans += (diff - 1); n     } n     prev = cur; n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   static int n; n   static int a[300010], b[300010]; n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) scanf( %d%d , &a[i], &b[i]); n   int cnt[2] = {}; n   for (int i = 1; i <= n; i++) { n     if (a[i] < b[i]) n       cnt[0]++; n     else n       cnt[1]++; n   } n   if (cnt[0] > cnt[1]) { n     vector<pair<int, int> > vec; n     for (int i = 1; i <= n; i++) { n       if (a[i] < b[i]) vec.push_back(pair<int, int>(-a[i], i)); n     } n     sort(vec.begin(), vec.end()); n     printf( %d n , cnt[0]); n     for (int i = 0; i < vec.size(); i++) { n       printf( %d%c , vec[i].second, (i + 1 == vec.size()) ?   n  :    ); n     } n   } else { n     vector<pair<int, int> > vec; n     for (int i = 1; i <= n; i++) { n       if (a[i] > b[i]) vec.push_back(pair<int, int>(b[i], i)); n     } n     sort(vec.begin(), vec.end()); n     printf( %d n , cnt[1]); n     for (int i = 0; i < vec.size(); i++) { n       printf( %d%c , vec[i].second, (i + 1 == vec.size()) ?   n  :    ); n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n char s[10000]; n int num[100]; n int main() { n   int T, t, i, j, k, n, m = 0, len; n   scanf( %s , &s); n   len = strlen(s); n   for (i = 0; i < len; i++) { n     k = s[i] -  a  + 1; n     num[k]++; n   } n   for (i = 1; i <= 26; i++) n     if (num[i] % 2 == 1) m++; n   if (m == 0 || m == 1) n     printf( First n ); n   else if (m % 2 == 0) n     printf( Second n ); n   else n     printf( First n ); n } n


#include <bits/stdc++.h> n const double EPS = 1e-7, pi = 3.141592653589793; n struct unit { n   double x, y; n   unit(double _x = 0, double _y = 0) : x(_x), y(_y) {} n   double cross(const unit &A) const { return x * A.y - y * A.x; } n   inline double len() const { return sqrt(x * x + y * y); } n   double operator*(const unit &A) const { return x * A.x + y * A.y; } n   unit operator*(const double &A) const { return unit(x * A, y * A); } n   unit operator-(const unit &A) const { return unit(x - A.x, y - A.y); } n   unit operator+(const unit &A) const { return unit(x + A.x, y + A.y); } n   unit operator/(const double &A) const { return unit(x / A, y / A); } n   inline void out() { printf( %.6lf %.6lf n , x, y); } n }; n void rotate(unit &A, double the) { n   double x = A.x * cos(the) - A.y * sin(the), n          y = A.x * sin(the) + A.y * cos(the); n   A = unit(x, y); n } n double r, R, v; n unit now; n void tangentpoint(unit p, unit &A, unit &B) { n   double d = p.len(); n   p = p / d; n   double cost = r / d, sint = sqrt(d * d - r * r) / d; n   unit ver = unit(-p.y, p.x); n   A = (p * r * cost) + (ver * r * sint); n   B = (p * r * cost) - (ver * r * sint); n } n inline double min(double a, double b) { return a < b ? a : b; } n double arclength(unit A, unit B) { n   return r * acos((A * B) / A.len() / B.len()); n } n double calcdis(unit &now, unit tar) { n   unit u = unit() - now, v = tar - now; n   unit t1, t2, a, b; n   tangentpoint(now, t1, t2); n   tangentpoint(tar, a, b); n   if (v.len() < (t1 - now).len() + sqrt(R * R - r * r)) { n     return v.len(); n   } n   double ans = (t1 - now).len() + (b - tar).len() + n                min(min(arclength(t2, a), arclength(t2, b)), n                    min(arclength(t1, a), arclength(t1, b))); n   return ans; n } n double bs(double l, double u, double st, double w) { n   double low = l, up = u; n   for (int i = 0; i < 100; i++) { n     double mid = (low + up) / 2; n     double d = calcdis(now, unit(R * cos(mid), R * sin(mid))); n     if (st + (mid - l) / w > d / v) n       up = mid; n     else n       low = mid; n   } n   return low; n } n int main() { n   unit tar; n   double vp; n   while (~scanf( %lf%lf%lf , &tar.x, &tar.y, &vp)) { n     scanf( %lf%lf%lf%lf , &now.x, &now.y, &v, &r); n     double theta = acos(now * (unit(-1, 0)) / now.len()); n     if (now.y < 0) theta *= -1; n     rotate(now, theta); n     rotate(tar, theta); n     R = tar.len(); n     double w = vp / R, T = 2.0 * pi / w; n     double anst = 1e8; n     if (tar.y < -EPS) { n       double theta = acos(tar * unit(1, 0) / tar.len()); n       double st = theta / w, et = st + T / 2.0; n       double d1 = calcdis(now, unit(R, 0)), d2 = calcdis(now, unit(-R, 0)); n       int k = ceil((d2 / v - et) / (T)); n       if (et >= d2 / v) k = 0; n       if (st + k * T < d1 / v + EPS) { n         double tmp = bs(0, pi, st + k * T, +w); n         anst = min(anst, st + k * T + tmp / w); n       } n       st = et; n       et = st + T / 2.0; n       k = ceil((d1 / v - et) / (T)); n       if (et >= d1 / v) k = 0; n       if (st + k * T < d2 / v + EPS) { n         double tmp = bs(pi, 2 * pi, st + k * T, w); n         anst = min(anst, st + k * T + (tmp - pi) / w); n       } n       if (calcdis(now, unit(R, 0)) / v < theta / w + EPS) { n         double tmp = bs(-theta, 0, 0, w); n         anst = min(anst, (tmp + theta) / w); n       } n     } else { n       double theta = acos(tar * unit(-1, 0) / tar.len()); n       double st = theta / w, et = st + T / 2.0; n       double d1 = calcdis(now, unit(R, 0)), d2 = calcdis(now, unit(-R, 0)); n       int k = ceil((d1 / v - et) / (T)); n       if (et >= d1 / v) k = 0; n       if (st + k * T < d2 / v + EPS) { n         double tmp = bs(pi, 2 * pi, st + k * T, w); n         anst = min(anst, st + k * T + (tmp - pi) / w); n       } n       st = et; n       et = st + T / 2.0; n       k = ceil((d2 / v - et) / (T)); n       if (et >= d2 / v) k = 0; n       if (st + k * T < d1 / v + EPS) { n         double tmp = bs(0, pi, st + k * T, w); n         anst = min(anst, st + k * T + tmp / w); n       } n       if (calcdis(now, unit(-R, 0)) / v < theta / w + EPS) { n         double tmp = bs(pi - theta, pi, 0, w); n         anst = min(anst, (tmp - pi + theta) / w); n       } n     } n     printf( %.10lf n , anst); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int n, a, b; n int main() { n   cin >> n >> a >> b; n   n -= a; n   b++; n   cout << (n > b ? b : n); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool ask(long long l, long long r) { n   cout << l <<     << r <<   n ; n   cout.flush(); n   string res; n   cin >> res; n   return res ==  Yes ; n } n int main() { n   srand(time(NULL)); n   ios_base::sync_with_stdio(false); n   long long n, k; n   cin >> n >> k; n   long long l = 1, r = n; n   while (true) { n     if (r - l > 60ll) { n       long long mid = l + r >> 1; n       if (ask(l, mid)) { n         l = max(1ll, l - k); n         r = min(mid + k, n); n       } else { n         l = max(mid + 1 - k, 1ll); n         r = min(r + k, n); n       } n     } else { n       long long mid = rand() % (r - l + 1) + l; n       if (ask(mid, mid)) return 0; n       l = max(l - k, 1ll); n       r = min(r + k, n); n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = INT_MAX; n const long long LINF = LLONG_MAX; n const unsigned long long ULINF = ULLONG_MAX; n const double EPS = 0.000001; n char v[150][150], v_new[150][150]; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   int w, h; n   cin >> w >> h; n   for (int i = 0; i < h; i++) n     for (int j = 0; j < w; j++) cin >> v[i][j]; n   for (int i = 0; i < h; i++) n     for (int j = 0; j < w; j++) v_new[j][i] = v[i][j]; n   for (int i = 0; i < w; i++) { n     for (int j = 0; j < h; j++) { n       cout << v_new[i][j]; n       cout << v_new[i][j]; n     } n     cout <<   n ; n     for (int j = 0; j < h; j++) { n       cout << v_new[i][j]; n       cout << v_new[i][j]; n     } n     cout <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct { n   int begin, end; n } P1[60], P2[60]; n int main() { n   int num1, num2, first, last; n   scanf( %d %d %d %d , &num1, &num2, &first, &last); n   int ans = 0; n   for (int i = 1; i <= num1; i++) scanf( %d %d , &P1[i].begin, &P1[i].end); n   for (int i = 1; i <= num2; i++) scanf( %d %d , &P2[i].begin, &P2[i].end); n   for (int i = first; i <= last; i++) { n     for (int j1 = 1; j1 <= num1; j1++) { n       bool flag = 1; n       for (int j2 = 1; j2 <= num2; j2++) { n         if ((P2[j2].begin + i >= P1[j1].begin && n              P2[j2].begin + i <= P1[j1].end) || n             (P2[j2].end + i >= P1[j1].begin && P2[j2].end + i <= P1[j1].end) || n             (P2[j2].begin + i <= P1[j1].begin && n              P2[j2].end + i >= P1[j1].end)) { n           ans++; n           flag = 0; n           break; n         } n       } n       if (!flag) break; n     } n   } n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n void dbs(string str, T t) { n   cerr << str <<   :   << t <<   n ; n } n template <class T, class... S> n void dbs(string str, T t, S... s) { n   long long idx = str.find( , ); n   cerr << str.substr(0, idx) <<   :   << t <<  ,  ; n   dbs(str.substr(idx + 1), s...); n } n template <class T> n void prc(T a, T b) { n   cerr <<  [ ; n   for (T i = a; i != b; ++i) { n     if (i != a) cerr <<  ,  ; n     cerr << *i; n   } n   cerr <<  ] n ; n } n template <class T> n void prall(T a) { n   prc(a.begin(), a.end()); n } n const int inf = 1000 * 1000 * 1000 + 9; n const long long infl = 1ll * inf * inf; n const int mod = 1000 * 1000 * 1000 + 7; n void solve() { n   int t; n   cin >> t; n   while (t--) { n     int n; n     cin >> n; n     int o = 0, e = 0; n     for (int i = 0; i < n; i++) { n       int p; n       cin >> p; n       if (p & 1) n         o++; n       else n         e++; n     } n     long long ans = 0; n     int m; n     cin >> m; n     for (int i = 0; i < m; i++) { n       int p; n       cin >> p; n       if (p & 1) { n         ans += o; n       } else n         ans += e; n     } n     cout << ans <<   n ; n   } n } n int main() { n   ios_base::sync_with_stdio(NULL); n   cin.tie(NULL); n   cout << fixed << setprecision(13); n   solve(); n } n


#include <bits/stdc++.h> n using namespace std; n int const N = 2 * 1e5 + 5; n int ans = 0; n int i, j, n, m, k, z, y, x, t, mi, ma; n long long a[N]; n long long dp[N][2], d[N][2]; n char st[N]; n long long poisk(int x, int t) { n   if (dp[x][t] != 0) return dp[x][t]; n   long long y = x; n   d[x][t]++; n   if (d[x][t] > 1) { n     d[x][t] = -1; n     return d[x][t]; n   } n   if (t == 0) n     y += a[x]; n   else n     y -= a[x]; n   if (y < 1 || y > n) { n     dp[x][t] = a[x]; n     return dp[x][t]; n   } n   long long z = poisk(y, 1 - t); n   if (z > 0) n     dp[x][t] = a[x] + z; n   else n     dp[x][t] = -1; n   return dp[x][t]; n } n int main() { n   scanf( %d , &n); n   for (i = 2; i <= n; i++) scanf( %I64d , &a[i]); n   for (i = 1; i < n; i++) { n     a[1] = i; n     d[1][0] = 0; n     long long k = poisk(1 + i, 1); n     if (k > 0) k += i; n     printf( %I64d n , k); n   } n } n


#include <bits/stdc++.h> n struct M { n   int p, b; n }; n struct F { n   const int p, i; n   int r, c; n   F(int p, int t, int i) : p(p), i(i), r(p + t), c(0) {} n   int t() { return r - p; } n }; n void solve(std::vector<F> &fs, std::vector<M> &ms) { n   std::multimap<int, int> ms_landed; n   std::map<int, F *> fs_active; n   { n     std::vector<F *> fs_sort; n     fs_sort.reserve(fs.size()); n     for (int i = 0; i < fs.size(); i++) fs_sort.push_back(&fs[i]); n     std::sort(fs_sort.begin(), fs_sort.end(), n               [](const F *lhs, const F *rhs) { return lhs->p < rhs->p; }); n     fs_active.insert({fs_sort[0]->p, fs_sort[0]}); n     int curr = fs_sort[0]->r; n     for (int i = 1; i < fs_sort.size(); i++) { n       F &f = *fs_sort[i]; n       if (f.r > curr) { n         int l = std::max(curr + 1, f.p); n         curr = f.r; n         fs_active.insert({l, &f}); n       } n     } n   } n   auto update = [&](F &f, std::map<int, F *>::iterator &f_succ, const int &b) { n     f.c++; n     f.r += b; n     while (f_succ != fs_active.end()) { n       int l_succ = f_succ->first; n       int r_succ = f_succ->second->r; n       if (f.r < r_succ) { n         if (f.r >= l_succ) { n           fs_active.erase(f_succ); n           f_succ = fs_active.insert({f.r + 1, f_succ->second}).first; n         } n         break; n       } n       f_succ = fs_active.erase(f_succ); n     } n   }; n   for (const M &m : ms) { n     auto f_it = --fs_active.upper_bound(m.p); n     const int l = f_it->first; n     F &f = *f_it->second; n     if (l <= m.p && m.p <= f.r) { n       update(f, ++f_it, m.b); n       auto m_it = ms_landed.lower_bound(l); n       while (m_it != ms_landed.end()) { n         M m{m_it->first, m_it->second}; n         if (l <= m.p && m.p <= f.r) { n           update(f, f_it, m.b); n           m_it = ms_landed.erase(m_it); n         } else { n           break; n         } n       } n     } else { n       ms_landed.insert({m.p, m.b}); n     } n   } n   for (F &f : fs) { n     printf( %d %d n , f.c, f.t()); n   } n } n int main() { n   int n, m; n   scanf( %d%d , &n, &m); n   std::vector<F> fs; n   fs.reserve(n); n   std::vector<M> ms; n   ms.reserve(m); n   for (int i = 0; i < n; i++) { n     int p, t; n     scanf( %d%d , &p, &t); n     fs.push_back({p, t, i}); n   } n   for (int i = 0; i < m; i++) { n     int p, b; n     scanf( %d%d , &p, &b); n     ms.push_back({p, b}); n   } n   solve(fs, ms); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   pair<int, int> orig[3]; n   int a, b, x1, y1, t = 0; n   for (int i = 0; i < 3; i++) { n     cin >> orig[i].first >> orig[i].second; n   } n   cout <<  3  << endl; n   a = (orig[0].first + orig[1].first) / 2; n   b = (orig[0].second + orig[1].second) / 2; n   cout << (orig[0].first + orig[1].first - orig[2].first) <<     n        << (orig[0].second + orig[1].second - orig[2].second) << endl; n   a = (orig[1].first + orig[2].first); n   b = (orig[1].second + orig[2].second); n   cout << (a - orig[0].first) <<     << (b - orig[0].second) << endl; n   a = (orig[0].first + orig[2].first); n   b = (orig[0].second + orig[2].second); n   cout << (a - orig[1].first) <<     << (b - orig[1].second) << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int m, n, L, cnt, sum[1000005]; n char s[1000005], x[1000005]; n struct Node { n   Node *par, *go[26]; n   int val, sum, flag, num; n   void Clear(int _val) { n     par = NULL; n     for (int i = 0; i < 26; i++) go[i] = NULL; n     sum = flag = 0; n     val = _val; n   } n } * root, *last, *a[1000005 * 2], *b[1000005 * 2]; n void Extend(int w) { n   Node *p = last, *np = new Node; n   a[++cnt] = np; n   np->num = cnt; n   np->Clear(p->val + 1); n   for (; p && (!(p->go[w])); p = p->par) p->go[w] = np; n   if (!p) n     np->par = root; n   else { n     Node *q = p->go[w]; n     if (q->val == p->val + 1) n       np->par = q; n     else { n       Node *nq = new Node; n       a[++cnt] = nq; n       nq->num = cnt; n       nq->Clear(p->val + 1); n       for (int i = 0; i < 26; i++) nq->go[i] = q->go[i]; n       nq->par = q->par; n       q->par = np->par = nq; n       for (; p && (p->go[w] == q); p = p->par) p->go[w] = nq; n     } n   } n   last = np; n } n void BuildSAM() { n   scanf( %s , &s); n   m = strlen(s); n   cnt = 0; n   root = new Node; n   root->Clear(0); n   root->num = 0; n   last = root; n   for (int i = 0; i < m; i++) Extend(s[i] -  a ); n } n void DP() { n   for (Node *p = last; p; p = p->par) p->sum = 1; n   for (int i = 0; i <= m; i++) sum[i] = 0; n   for (int i = 1; i <= cnt; i++) sum[a[i]->val]++; n   for (int i = 1; i <= m; i++) sum[i] += sum[i - 1]; n   for (int i = 1; i <= cnt; i++) b[sum[a[i]->val]--] = a[i]; n   for (int i = cnt; i >= 1; i--) { n     Node *p = b[i]; n     for (int j = 0; j < 26; j++) n       if (p->go[j]) { n         p->sum += p->go[j]->sum; n       } n   } n } n int main() { n   BuildSAM(); n   DP(); n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) { n     scanf( %s , &x); n     L = strlen(x); n     Node *p = root; n     int len = 0; n     for (int j = 0; j < L; j++) { n       int w = x[j] -  a ; n       while (p && (!p->go[w])) p = p->par; n       if (!p) p = root; n       len = min(len, p->val); n       if (p->go[w]) { n         p = p->go[w]; n         len++; n       } n     } n     int ans = 0; n     for (int j = 0; j < L; j++) { n       int w = x[j] -  a ; n       while (p && (!p->go[w])) p = p->par; n       if (!p) { n         p = root; n         continue; n       } n       len = min(len + 1, p->val + 1); n       p = p->go[w]; n       while (p->par && (p->par->val >= L)) p = p->par; n       if (p->flag == i) continue; n       if (len >= L) { n         ans += p->sum; n         p->flag = i; n       } n     } n     printf( %d n , ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n inline void read(T &x) { n   char c; n   bool nega = 0; n   while ((!isdigit(c = getchar())) && (c !=  - )) n     ; n   if (c ==  - ) { n     nega = 1; n     c = getchar(); n   } n   x = c - 48; n   while (isdigit(c = getchar())) x = x * 10 + c - 48; n   if (nega) x = -x; n } n template <typename T> n inline void writep(T x) { n   if (x > 9) writep(x / 10); n   putchar(x % 10 + 48); n } n template <typename T> n inline void write(T x) { n   if (x < 0) { n     putchar( - ); n     x = -x; n   } n   writep(x); n } n template <typename T> n inline void writeln(T x) { n   write(x); n   putchar(  n ); n } n int n, m; n int f[5001][5001]; n char c[5001][5001]; n inline int sum(int x, int y, int u, int v) { n   return f[u][v] - f[u][y - 1] - f[x - 1][v] + f[x - 1][y - 1]; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cin >> n >> m; n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= m; j++) { n       cin >> c[i][j]; n       c[i][j] -=  0 ; n     } n   for (int i = 1; i <= 5000; i++) n     for (int j = 1; j <= 5000; j++) n       f[i][j] = f[i - 1][j] + f[i][j - 1] - f[i - 1][j - 1] + c[i][j]; n   int ans = m * n; n   for (int k = 2500; k >= 2; k--) { n     int i = 1; n     int res = 0; n     int sq = k * k; n     int t = 0; n     do { n       int j = 1; n       do { n         t = sum(i, j, i + k - 1, j + k - 1); n         res += min(t, sq - t); n         j += k; n       } while (j <= m); n       i += k; n     } while (i <= n); n     ans = min(ans, res); n   } n   writeln(ans); n } n


#include <bits/stdc++.h> n using namespace std; n int pos = -1; n void Go(vector<string> &t) { n   if (t[++pos] ==  int ) { n     cout <<  int ; n   } else { n     cout <<  pair< ; n     Go(t); n     cout <<  , ; n     Go(t); n     cout <<  > ; n   } n } n int main() { n   int n, i = 0; n   bool check = true; n   cin >> n; n   string t, t1 =   ; n   int bal = 0; n   int k = 0; n   std::vector<std::string> s; n   char c; n   std::getline(std::cin, t); n   std::getline(std::cin, t); n   for (int j = 0; j < t.length(); j++) { n     if (t[j] !=    ) { n       t1 += t[j]; n     } else { n       s.push_back(t1); n       t1 =   ; n     } n   } n   s.push_back(t1); n   k = s.size(); n   { n     for (int i = 0; i < k - 1; i++) { n       if (s[i] ==  pair ) n         bal++; n       else { n         bal--; n       } n       if (bal < 0) { n         check = false; n       } n     } n     if (s[k - 1] ==  pair ) n       bal++; n     else { n       bal--; n     } n     if (bal != -1) { n       check = false; n     } n     if (!check) { n       cout <<  Error occurred ; n       return 0; n     } n   } n   Go(s); n } n


#include <bits/stdc++.h> n using namespace std; n void pr(char c, int t) { n   while (t--) printf( %c , c); n } n int main() { n   int n, i, co(0), s; n   map<char, int> c; n   char ch; n   scanf( %d , &n); n   for (i = 0; i < n; ++i) { n     scanf(  %c , &ch); n     ++c[ch]; n   } n   for (const auto &e : c) n     if (e.second & 1) ++co; n   if (co < 2) { n     printf( 1 n ); n     for (auto it = c.begin(); it != c.end(); ++it) n       if (~it->second & 1) pr(it->first, it->second / 2); n     for (auto it = c.begin(); it != c.end(); ++it) n       if (it->second & 1) { n         pr(it->first, it->second); n         c.erase(it); n         break; n       } n     for (auto it = c.rbegin(); it != c.rend(); ++it) n       if (~it->second & 1) pr(it->first, it->second / 2); n     printf(  n ); n     return 0; n   } n   for (s = co; n % s || !(n / s & 1); ++s) n     ; n   printf( %d n , s); n   vector<set<pair<int, char>>> str; n   vector<int> tot; n   for (auto &e : c) n     if (e.second & 1) { n       set<pair<int, char>> tmp; n       tmp.insert({1, e.first}); n       str.push_back(tmp); n       tot.push_back(1); n       --e.second; n     } n   for (auto &e : c) n     while (co < s && e.second) { n       set<pair<int, char>> tmp; n       tmp.insert({1, e.first}); n       str.push_back(tmp); n       tot.push_back(1); n       --e.second; n       ++co; n     } n   map<char, int>::iterator it(c.begin()); n   for (i = 0; i < s; ++i) n     while (tot[i] < n / s) { n       while (!it->second) ++it; n       int tmp(min(it->second, n / s - tot[i])); n       str[i].insert({tmp, it->first}); n       it->second -= tmp; n       tot[i] += tmp; n     } n   for (i = 0; i < s; ++i) { n     if (i) printf(   ); n     for (auto it = str[i].rbegin(); it != str[i].rend(); ++it) n       pr(it->second, it->first / 2); n     for (auto it = str[i].begin(); it != str[i].end(); ++it) n       pr(it->second, (it->first + 1) / 2); n   } n   printf(  n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long int; n using ull = unsigned long long int; n using dd = double; n using ldd = long double; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   ll n, r; n   cin >> n >> r; n   vector<ll> arr((ll(1)) << n); n   ll sum = 0; n   n = ((ll)1) << n; n   for (int i = 0; i < n; ++i) { n     cin >> arr[i]; n     sum += arr[i]; n   } n   cout.precision(10); n   cout << ((dd)sum) / (dd(n)) <<   n ; n   for (int i = 0; i < r; ++i) { n     ll a, b; n     cin >> a >> b; n     sum -= arr[a]; n     sum += b; n     arr[a] = b; n     cout << ((dd)sum) / (dd(n)) <<   n ; n   } n } n


#include <bits/stdc++.h> n const int intINF = 999999999; n const long long i64INF = 99999999999999999ll; n const double doubleINF = 9999999999.; n using namespace std; n int abs(int a) { n   if (a < 0) a *= -1; n   return a; n } n int max(int a, int b) { n   if (a < b) a = b; n   return a; n } n int main() { n   int x1, y1, x2, y2, px, py; n   scanf( %d%d%d%d%d%d , &px, &py, &x1, &y1, &x2, &y2); n   int m; n   int p1, p2; n   p1 = abs(y1 - y2); n   p2 = abs(x1 - x2); n   if ((p1 >= 3 && p2 >= 4) || (p1 >= 4 && p2 >= 3) || p1 > 4 || p2 > 4) n     printf( Second n ); n   else n     printf( First n ); n   return 0; n } n