#include <bits/stdc++.h> n using namespace std; n template <typename G1, typename G2 = G1, typename G3 = G1> n struct triple { n   G1 first; n   G2 second; n   G3 T; n }; n const long double eps = 1e-12; n int sign(long double x) { return x < -eps ? -1 : x > eps; } n int dblcmp(long double x, long double y) { return sign(x - y); } n long double dot(complex<long double> a, complex<long double> b) { n   return real(conj(a) * b); n } n long double cross(complex<long double> a, complex<long double> b) { n   return imag(conj(a) * b); n } n struct Point { n   complex<long double> p; n   int id; n   long double operator*(const Point o) const { return cross(this->p, o.p); } n   Point operator-(const Point o) const { return {p - o.p}; } n   bool operator<(const Point o) const { n     if (dblcmp(p.real(), o.p.real()) == 0) n       return dblcmp(p.imag(), o.p.imag()) < 0; n     return dblcmp(p.real(), o.p.real()) < 0; n   } n }; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   int n; n   cin >> n; n   vector<vector<int>> mp1(n); n   map<pair<long long, long long>, int> mp2; n   vector<Point> v; n   int c = 0; n   for (int i = 0; i < n; i++) { n     int x, y; n     cin >> x >> y; n     if (mp2.count({x, y}) == 0) { n       v.push_back({{10000.0 / x, 10000.0 / y}, c}); n       mp2[{x, y}] = c++; n     } n     mp1[mp2[{x, y}]].push_back(i + 1); n   } n   sort(v.begin(), v.end()); n   vector<Point> hull; n   for (int i = 0; i < c; i++) { n     while (hull.size() > 1 && n            dblcmp((hull.end()[-1] - hull.end()[-2]) * (v[i] - hull.end()[-1]), n                   0) < 0) n       hull.pop_back(); n     hull.push_back(v[i]); n   } n   while (hull.size() > 1 && n          dblcmp(hull.end()[-2].p.imag(), hull.end()[-1].p.imag()) <= 0) n     hull.pop_back(); n   vector<int> ans; n   for (auto &i : hull) n     for (auto j : mp1[i.id]) ans.push_back(j); n   sort(ans.begin(), ans.end()); n   for (int i = 0; i < ans.size(); i++) n     cout << ans[i] <<    n [i == ans.size() - 1]; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long M = 1e9 + 7; n long long powmodM(long long a, long long b, long long c = M) { n   long long res = 1; n   while (b) { n     if (b & 1) res = (res * a) % M; n     a = (a * a) % M; n     b /= 2; n   } n   return res; n } n long long power(long long a, long long b) { n   long long res = 1; n   while (b) { n     if (b & 1) res = (res * a); n     a = (a * a); n     b /= 2; n   } n   return res; n } n long long gcd(long long a, long long b) { n   while (a && b) a > b ? a %= b : b %= a; n   return a + b; n } n long long lcm(long long a, long long b) { n   return (max(a, b) / gcd(a, b)) * min(a, b); n } n vector<long long int> sieve(long long int n) { n   vector<long long int> ans, prime(2 * 1e6); n   prime[0] = false; n   prime[1] = false; n   for (long long int p = 2; p * p <= n; p++) n     if (prime[p]) n       for (long long int i = p * p; i <= n; i += p) prime[i] = 0; n   for (long long p = (2); p <= (n); ++p) n     if (prime[p]) ans.push_back(p); n   return ans; n } n long long modInverse(long long n, long long p = M) { n   return powmodM(n, p - 2, p); n } n long long nCrModP(long long n, long long r, long long p = M) { n   if (r == 0) return 1; n   long long fac[n + 1]; n   fac[0] = 1; n   for (long long i = (1); i <= (n); ++i) fac[i] = fac[i - 1] * i % p; n   return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) % n          p; n } n double pie = 3.14159265358979323846264338; n const long long int INF = 0x3f3f3f3f; n class l { n  public: n   char data; n   l *next; n   l *prev; n   l(char a) { n     data = a; n     prev = NULL; n     next = NULL; n   } n }; n map<long long int, long long int> fre; n int32_t main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   long long int n, m; n   cin >> n >> m; n   vector<long long int> arr(n); n   for (long long i = (0); i <= (n - 1); ++i) cin >> arr[i]; n   if (m == arr[0]) { n     cout << -1; n     return 0; n   } n   long long int ma = 0; n   fre[arr[ma]] = 1; n   bool ok = 1; n   long long int uski = 0; n   for (long long i = (1); i <= (n - 1); ++i) { n     if (arr[i] == m) { n       uski++; n       vector<long long int> re; n       for (auto u : fre) { n         if (u.second < uski) re.push_back(u.first); n       } n       for (auto u : re) { n         fre.erase(u); n       } n       if (!fre.size()) { n         cout << -1; n         return 0; n       } n     } n     if (!uski) n       fre[arr[i]]++; n     else if (fre[arr[i]]) { n       fre[arr[i]]++; n     } n   } n   vector<long long int> re; n   for (auto u : fre) { n     if (u.second < uski) re.push_back(u.first); n   } n   for (auto u : re) { n     fre.erase(u); n   } n   if (!fre.size()) { n     cout << -1; n     return 0; n   } n   if (fre.size()) { n     cout << fre.begin()->first; n   } else { n     cout << -1; n   } n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> temp(100005); n vector<int> v(100005); n int fn(int l, int h, int x) { n   while (h - l > 1) { n     int mid = (h + l) / 2; n     if (temp[mid] >= x) { n       h = mid; n     } else { n       l = mid; n     } n   } n   if (temp[h] > x) n     return h; n   else n     return l; n } n int main() { n   ios_base::sync_with_stdio(false); n   int n; n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> v[i]; n   } n   int len = 1; n   temp[0] = v[0]; n   for (int i = 1; i < n; i++) { n     if (temp[0] > v[i]) { n       temp[0] = v[i]; n     } else if (v[i] > temp[len - 1]) { n       temp[len] = v[i]; n       len++; n     } else { n       int index = fn(0, len - 1, v[i]); n       temp[index] = v[i]; n     } n   } n   cout << len; n } n


#include <bits/stdc++.h> n using namespace std; n const int M = 1e9 + 7; n long long fastpower(long long x, long long n, long long M) { n   if (n == 0) n     return 1; n   else if (n % 2 == 0) n     return fastpower((x * x) % M, n / 2, M); n   else n     return (x * fastpower((x * x) % M, (n - 1) / 2, M)) % M; n } n long long GCD(long long A, long long B) { n   if (B == 0) n     return A; n   else n     return GCD(B, A % B); n } n bool vowl(char c) { n   return c ==  a  || c ==  e  || c ==  i  || c ==  o  || c ==  u ; n } n long long modInverse(long long A, long long M) { n   return fastpower(A, M - 2, M); n } n void sieve(long long N) { n   bool isPrime[N + 1]; n   for (long long i = 0; i <= N; ++i) { n     isPrime[i] = true; n   } n   isPrime[0] = false; n   isPrime[1] = false; n   for (long long i = 2; i * i <= N; ++i) { n     if (isPrime[i] == true) { n       for (long long j = i * i; j <= N; j += i) isPrime[j] = false; n     } n   } n } n vector<long long> factorize(long long n) { n   vector<long long> res; n   for (long long i = 2; i * i <= n; ++i) { n     while (n % i == 0) { n       res.push_back(i); n       n /= i; n     } n   } n   if (n != 1) { n     res.push_back(n); n   } n   return res; n } n long long dp[300000][20]; n long long n, m, k; n long long arr[20]; n long long cost[20][20]; n long long cal(string s) { n   reverse(s.begin(), s.end()); n   long long ans = 0; n   for (long long i = 0; i < s.length(); i++) { n     if (s[i] ==  1 ) ans += (1 << i); n   } n   return ans; n } n long long solve(string &s, int prev) { n   int p = 0; n   int a = 0; n   for (int i = n - 1; i >= 0; i--) { n     if (s[i] ==  1 ) { n       a++; n       p += (1 << (n - i - 1)); n     } n   } n   if (a == m) return 0; n   if (dp[p][prev] != -1) return dp[p][prev]; n   long long ans = 0; n   for (long long i = 0; i < n; i++) { n     if (s[i] ==  0 ) { n       s[i] =  1 ; n       ans = max(ans, arr[i + 1] + cost[prev][i + 1] + solve(s, i + 1)); n       s[i] =  0 ; n     } n   } n   return dp[p][prev] = ans; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cin >> n >> m >> k; n   string s =   ; n   for (long long i = 1; i <= n; i++) { n     cin >> arr[i]; n     s +=  0 ; n   } n   for (long long i = 0; i < k; i++) { n     long long x, y, c; n     cin >> x >> y >> c; n     cost[x][y] = c; n   } n   memset(dp, -1, sizeof(dp)); n   cout << solve(s, 0) << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e5 + 5; n int main() { n   int a, b, c, d; n   scanf( %d%d%d%d , &a, &b, &c, &d); n   if (a == 0 && b == 0 && c == 0 && d == 0) { n     printf( 1 n ); n   } else if (a == 0 && d == 0 && c != 0) { n     printf( 0 n ); n   } else if (a != d) { n     printf( 0 n ); n   } else { n     printf( 1 n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   cin.tie(0); n   cin.sync_with_stdio(0); n   long long n, a[5001], cnt = 1, maxn = 0; n   cin >> n; n   for (int i = 0; i < n; i++) cin >> a[i]; n   sort(a, a + n); n   for (int i = 0; i < n - 1; i++) { n     if (a[i] == a[i + 1]) cnt++; n     if (a[i] != a[i + 1]) cnt = 1; n     maxn = max(maxn, cnt); n   } n   maxn = max(maxn, cnt); n   cout << maxn; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s, ans, s1; n   cin >> s; n   s1 = s; n   int l = s.length(), i; n   int j = l - 1, flag = 0; n   while (i < j) { n     if (s[i] != s[j]) { n       flag = 1; n       break; n     } n     i++; n     j--; n   } n   if (flag) { n     reverse(s1.begin(), s1.end()); n     ans = s + s1; n     cout << ans; n   } else n     cout << s; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s; n   cin >> s; n   s[0] = toupper(s[0]); n   cout << s << endl; n   return 0; n } n


#include <bits/stdc++.h> n const long long md = 1e9 + 7; n const int Inf = 1e9; n const long long Inf64 = 1e18; n const long long MaxN = 1e6 + 100; n const long double eps = 1e-15; n using namespace std; n long long Tree[4 * MaxN]; n long long getSum(long long l, long long r, long long x, long long y, n                  long long id) { n   if (l == x && r == y) { n     return Tree[id]; n   } else { n     long long mid = (l + r) / 2; n     if (mid >= y) { n       return getSum(l, mid, x, y, 2 * id + 1); n     } else if (mid + 1 <= x) { n       return getSum(mid + 1, r, x, y, 2 * id + 2); n     } else { n       return getSum(l, mid, x, mid, 2 * id + 1) + n              getSum(mid + 1, r, mid + 1, y, 2 * id + 2); n     } n   } n } n void edit(long long l, long long r, long long x, long long id) { n   if (l == r) { n     Tree[id]++; n   } else { n     long long mid = (l + r) / 2; n     if (mid >= x) { n       edit(l, mid, x, 2 * id + 1); n       Tree[id] = Tree[2 * id + 1] + Tree[2 * id + 2]; n     } else { n       edit(mid + 1, r, x, 2 * id + 2); n       Tree[id] = Tree[2 * id + 1] + Tree[2 * id + 2]; n     } n   } n } n signed main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   long long N; n   cin >> N; n   vector<pair<long long, long long> > Zip(N); n   for (int i = 0; i < N; i++) { n     long long a; n     cin >> a; n     Zip[i] = {a, i}; n   } n   sort(Zip.begin(), Zip.end()); n   vector<long long> Ans(N); n   for (int i = 0; i < N; i++) { n     long long t = getSum(0, N - 1, Zip[i].second, N - 1, 0); n     Ans[Zip[i].second] = t; n     edit(0, N - 1, Zip[i].second, 0); n   } n   fill(Tree, Tree + 4 * MaxN, 0); n   reverse(Zip.begin(), Zip.end()); n   long long Res = 0; n   for (int i = 0; i < N; i++) { n     long long t = getSum(0, N - 1, 0, Zip[i].second, 0); n     Res += Ans[Zip[i].second] * t; n     edit(0, N - 1, Zip[i].second, 0); n   } n   cout << Res; n   cerr <<   n  n        <<  Time execute:   << clock() / (double)CLOCKS_PER_SEC <<   sec  n        <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( O3 ) n using namespace std; n const long long MOD = 1e9 + 7; n long long a[200012]; n long long in[200021], out[200012]; n void solve() { n   long long n, m, i, j, c, sum; n   i = j = c = sum = 0; n   cin >> n; n   for (i = 0; i < n; ++i) { n     cin >> a[i]; n     --a[i]; n     if (a[i] != -1) { n       ++in[a[i]]; n       ++out[i]; n     } n   } n   vector<long long> loops; n   for (i = 0; i < n; ++i) { n     if (in[i] == 0 and out[i] == 0) { n       loops.push_back(i); n     } n   } n   if (loops.size() == 1) { n     long long init = loops[0]; n     for (i = 0; i < n; ++i) { n       if (in[i] == 0 and i != init) { n         a[init] = i; n         ++out[init]; n         ++in[i]; n         break; n       } n     } n   } else if (loops.size() > 1) { n     for (i = 0; i < loops.size(); ++i) { n       long long curr = loops[i]; n       long long nxt = loops[(i + 1) % loops.size()]; n       a[curr] = nxt; n       ++in[nxt]; n       ++out[curr]; n     } n   } n   vector<long long> ins, outs; n   for (i = 0; i < n; ++i) { n     if (in[i] == 0) ins.push_back(i); n     if (out[i] == 0) outs.push_back(i); n   } n   for (i = 0; i < outs.size(); ++i) { n     a[outs[i]] = ins[i]; n   } n   for (i = 0; i < n; ++i) { n     cout << a[i] + 1 <<    ; n   } n   cout <<   n ; n } n signed main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   long long t = 1; n   while (t--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> prefix_function(const vector<int>& s) { n   int n = s.size(); n   vector<int> pi(n); n   for (int i = 1; i < n; ++i) { n     int j = pi[i - 1]; n     while (j > 0 && s[i] != s[j]) j = pi[j - 1]; n     if (s[i] == s[j]) ++j; n     pi[i] = j; n   } n   return pi; n } n int n; n set<int> f[100005]; n int getLen(int a, int b) { n   int len = b - a; n   if (len <= 0) len += n; n   return len; n } n int go(int len) { n   if (f[len].size() == 0) n     return 1; n   else if (f[len].size() < 2) n     return -1; n   vector<int> diffs; n   int last = -1, fir = -1; n   for (int x : f[len]) { n     if (last == -1) n       fir = x; n     else n       diffs.push_back(getLen(last, x)); n     last = x; n   } n   diffs.push_back(getLen(last, fir)); n   vector<int> pref = prefix_function(diffs); n   int cand = diffs.size() - pref.back(); n   if (diffs.size() % cand == 0 && cand < diffs.size()) { n     int sum = 0; n     for (int i = 0; i < cand; ++i) sum += diffs[i]; n     return sum; n   } n   return -1; n } n long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } n long long lcm(long long a, long long b) { return a / gcd(a, b) * b; } n int main() { n   ios::sync_with_stdio(false); n   int m; n   cin >> n >> m; n   for (int i = 0; i < m; ++i) { n     int a, b; n     cin >> a >> b; n     int len = getLen(a, b); n     if (2 * len > n || 2 * len == n && a > b) len = n - len, swap(a, b); n     f[len].insert(a - 1); n   } n   long long ans = 1; n   for (int i = 1; i < n; ++i) { n     if (2 * i == n) continue; n     int cur = go(i); n     if (cur == -1) { n       cout <<  No  << endl; n       return 0; n     } n     ans = lcm(ans, cur); n     if (ans >= n) { n       cout <<  No  << endl; n       return 0; n     } n   } n   if (n % 2 == 0) { n     int cur = go(n / 2); n     if (cur != -1 && lcm(ans, cur) < n || lcm(ans, n / 2) < n) { n     } else { n       cout <<  No  << endl; n       return 0; n     } n   } n   cout <<  Yes  << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<long long> arr; n long long binarySearchCount(long long n, long long key) { n   long long left = 0, right = n; n   long long mid; n   while (left < right) { n     mid = (right + left) >> 1; n     if (arr[mid] == key) { n       while (mid + 1 < n && arr[mid + 1] == key) mid++; n       break; n     } else if (arr[mid] > key) n       right = mid; n     else n       left = mid + 1; n   } n   while (mid > -1 && arr[mid] > key) mid--; n   return mid; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   long long n; n   cin >> n; n   long long x; n   for (long long i = 0; i < n; i++) { n     cin >> x; n     arr.push_back(abs(x)); n   } n   sort(arr.begin(), arr.end()); n   long long ans = 0; n   for (long long i = 0; i < n - 1; i++) { n     long long temp = binarySearchCount(n, 2 * arr[i]); n     ans += temp - i; n   } n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const long long mod = 1e9 + 7; n const int N = 2e5 + 5; n inline int read() { n   int res = 0, ch, flag = 0; 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 int n, m, cnt; n struct node { n   int x, y; n }; n node p[N]; n vector<int> data; n int bit[N], t[N]; n long long ans; n void add(int i) { n   while (i <= m) { n     bit[i]++; n     i += i & -i; n   } n } n int sum(int i) { n   int res = 0; n   while (i > 0) { n     res += bit[i]; n     i -= i & -i; n   } n   return res; n } n bool cmp(node a, node b) { n   if (a.y != b.y) return a.y > b.y; n   return a.x < b.x; n } n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) { n     scanf( %d%d , &p[i].x, &p[i].y); n     data.push_back(p[i].x); n   } n   sort(data.begin(), data.end()); n   data.erase(unique(data.begin(), data.end()), data.end()); n   m = data.size(); n   for (int i = 1; i <= n; i++) n     p[i].x = lower_bound(data.begin(), data.end(), p[i].x) - data.begin() + 1; n   sort(p + 1, p + n + 1, cmp); n   for (int i = 1; i <= n;) { n     int j = i; n     while (j < n && p[j].y == p[j + 1].y) j++; n     t[i - 1] = 0; n     for (int k = i; k <= j; k++) { n       if (sum(p[k].x) - sum(p[k].x - 1) == 0) { n         add(p[k].x); n         cnt++; n       } n       t[k] = sum(p[k].x); n     } n     for (int k = i; k <= j; k++) n       ans += 1LL * (t[k] - t[k - 1]) * (cnt - t[k] + 1); n     i = j + 1; n   } n   printf( %I64d n , ans); n   return 0; n } n


#include<bits/stdc++.h> n using namespace std; n  n int main() n { n     int t; n     cin >> t; n     while(t--) n     { n         string s; n         cin >> s; n         cout << s.size() << endl; n     } n     return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string b; n   cin >> b; n   if (b ==  1 ) { n     cout <<  0  << endl; n     return 0; n   } n   int n = (int)((b).size()); n   string a((int)((b).size()),  - ); n   bool flag = true; n   if (n > 2) { n     if (b[0] !=  1 ) flag = false; n     for (__typeof(n) i = (1); i != (n); i++) n       if (b[i] !=  0 ) flag = false; n     if (flag) { n       cout <<  0  << endl; n       return 0; n     } n     flag = true; n   } n   int i = 0, j = n - 1; n   int pc = 0, cc = 0; n   while (i <= j) { n     int sum = b[j] + (10 * cc) - pc -  0 ; n     if (sum == -1) { n       if (cc == 0 && b[i] !=  9 ) { n         flag = false; n         break; n       } else if (cc == 1 && b[i] !=  0 ) { n         flag = false; n         break; n       } n       sum = 9; n       cc = 1; n     } n     if (i == 0) { n       if (b[j] ==  0 ) { n         flag = false; n         break; n       } n       if (j == 0) { n         if (sum % 2 != 0) { n           flag = false; n           break; n         } n         a[i] = (char)(sum / 2 +  0 ); n       } else { n         a[i] =  1 ; n         a[j] = (char)(sum - 1 +  0 ); n       } n     } else { n       if (i == j) { n         if (sum % 2 != 0) { n           flag = false; n           break; n         } n         a[i] = (char)(sum / 2) +  0 ; n       } else { n         if (sum == 19) { n           if (b[i] ==  0  && i != j - 1) { n             a[i] =  0 ; n             a[j] =  9 ; n             pc = 0; n             cc = 1; n             i++; n             j--; n             continue; n           } else { n             flag = false; n             break; n           } n         } n         if (sum < 10) { n           a[i] =  0 ; n           a[j] = (char)(sum +  0 ); n         } else { n           a[i] =  9 ; n           a[j] = (char)(sum - 9 +  0 ); n         } n       } n     } n     if (i == j - 1) { n       if (b[i] -  0  != (sum + cc) % 10) { n         flag = false; n       } n       break; n     } else { n       pc = cc; n       if (b[i] -  0  == sum % 10) n         cc = 0; n       else if (b[i] -  0  == (sum + 1) % 10) n         cc = 1; n       else { n         flag = false; n         break; n       } n       i++; n       j--; n     } n   } n   if (flag) { n     cout << a << endl; n     return 0; n   } n   if (b[0] !=  1 ) { n     cout <<  0  << endl; n     return 0; n   } n   i = 1; n   j = n - 1; n   pc = 0; n   cc = 1; n   flag = true; n   while (i <= j) { n     int sum = b[j] + (10 * cc) - pc -  0 ; n     if (sum == -1) { n       if (cc == 0 && b[i] !=  9 ) { n         flag = false; n         break; n       } else if (cc == 1 && b[i] !=  0 ) { n         flag = false; n         break; n       } n       sum = 9; n       cc = 1; n     } n     if (i == 1) { n       if (j == 0) { n         if (sum % 2 != 0) { n           flag = false; n           break; n         } n         a[i] = (char)(sum / 2 +  0 ); n       } else { n         a[i] =  9 ; n         a[j] = (char)(sum - 9 +  0 ); n       } n     } else { n       if (i == j) { n         if (sum % 2 != 0) { n           flag = false; n           break; n         } n         a[i] = (char)(sum / 2) +  0 ; n       } else { n         if (sum == 19 && i != j - 1) { n           if (b[i] ==  0 ) { n             a[i] =  0 ; n             a[j] =  9 ; n             pc = 0; n             cc = 1; n             i++; n             j--; n             continue; n           } else { n             flag = false; n             break; n           } n         } n         if (sum < 10) { n           a[i] =  0 ; n           a[j] = (char)(sum +  0 ); n         } else { n           a[i] =  9 ; n           a[j] = (char)(sum - 9 +  0 ); n         } n       } n     } n     if (i == j - 1) { n       if (b[i] -  0  != (sum + cc) % 10) { n         flag = false; n       } n       break; n     } else { n       pc = cc; n       if (b[i] -  0  == sum % 10) n         cc = 0; n       else if (b[i] -  0  == (sum + 1) % 10) n         cc = 1; n       else { n         flag = false; n         break; n       } n       i++; n       j--; n     } n   } n   if (flag) { n     cout << a.substr(1) << endl; n   } else { n     cout <<  0  << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int seed = 131; n const int maxn = 2e5 + 5; n const int mod = 1e9 + 7; n int n, k; n char a[maxn]; n int main() { n   scanf( %d%d , &n, &k); n   scanf( %s , a + 1); n   int cnt1 = 0; n   int cnt2 = 0; n   k /= 2; n   for (int i = 1; i <= n; i++) { n     if (cnt1 == k) break; n     if (a[i] ==  ( ) { n       cnt1++; n     } else n       cnt2++; n     printf( %c , a[i]); n   } n   for (int i = cnt2; i < k; i++) printf( ) ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int byk[3][3]; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   int n; n   cin >> n; n   string s; n   cin >> s; n   for (int i = 0; i < n; i++) { n     if (s[i] ==  B ) byk[i % 3][0]++; n     if (s[i] ==  G ) byk[i % 3][1]++; n     if (s[i] ==  R ) byk[i % 3][2]++; n   } n   int mini = 10000000; n   vector<int> jwb; n   vector<int> V; n   V.push_back(0); n   V.push_back(1); n   V.push_back(2); n   do { n     int x = byk[0][0] + byk[0][1] + byk[0][2]; n     x -= byk[0][V[0]]; n     int y = byk[1][0] + byk[1][1] + byk[1][2]; n     y -= byk[1][V[1]]; n     int z = byk[2][0] + byk[2][1] + byk[2][2]; n     z -= byk[2][V[2]]; n     if (x + y + z < mini) { n       mini = x + y + z; n       jwb.clear(); n       jwb.push_back(V[0]); n       jwb.push_back(V[1]); n       jwb.push_back(V[2]); n     } n   } while (next_permutation(V.begin(), V.end())); n   cout << mini << endl; n   for (int i = 0; i < n; i++) { n     if (i % 3 == 0) { n       if (jwb[0] == 0) cout <<  B ; n       if (jwb[0] == 1) cout <<  G ; n       if (jwb[0] == 2) cout <<  R ; n     } n     if (i % 3 == 1) { n       if (jwb[1] == 0) cout <<  B ; n       if (jwb[1] == 1) cout <<  G ; n       if (jwb[1] == 2) cout <<  R ; n     } n     if (i % 3 == 2) { n       if (jwb[2] == 0) cout <<  B ; n       if (jwb[2] == 1) cout <<  G ; n       if (jwb[2] == 2) cout <<  R ; n     } n   } n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long INF = 501; n const long long DIM = 3e5 + 1; n int in, n, t, a[DIM]; n int main() { n   ios_base::sync_with_stdio; n   cin.tie(0); n   cout.tie(0); n   in = scanf( %d , &t); n   while (t--) { n     in = scanf( %d , &n); n     set<int> s; n     for (int i = 1; i <= n; i++) { n       in = scanf( %d , &a[i]); n       s.insert(a[i]); n     } n     if (s.size() == 1) n       printf( -1 n ); n     else { n       auto it = s.end(); n       it--; n       for (int i = 1; i <= n; i++) { n         if (a[i] == *it && n             ((i > 1 && a[i - 1] != *it) || (i < n && a[i + 1] != *it))) { n           printf( %d n , i); n           break; n         } n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e6 + 5, mod = 1e9 + 7; n int a[N], st[N][20], pos[N][20]; n int seg_query(int l, int r) { n   int k = log2(r - l + 1); n   if (st[l][k] > st[r - (1 << k) + 1][k]) n     return pos[l][k]; n   else n     return pos[r - (1 << k) + 1][k]; n } n long long f[N]; n signed main() { n   int n; n   scanf( %d , &n); n   for (int i = 1; i <= n - 1; ++i) n     scanf( %d , a + i), st[i][0] = a[i], pos[i][0] = i; n   a[n] = n, st[n][0] = pos[n][0] = n; n   for (int j = 1; j <= 17; ++j) n     for (int i = 1; i + (1 << j) - 1 <= n; ++i) n       if (st[i][j - 1] > st[i + (1 << (j - 1))][j - 1]) n         st[i][j] = st[i][j - 1], pos[i][j] = pos[i][j - 1]; n       else n         st[i][j] = st[i + (1 << (j - 1))][j - 1], n         pos[i][j] = pos[i + (1 << (j - 1))][j - 1]; n   long long ans = 0; n   for (int i = n - 1; i >= 1; --i) { n     int k = seg_query(i + 1, a[i]); n     f[i] = f[k] + n - i - (a[i] - k); n     ans += f[i]; n   } n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n typedef struct graph { n   list<int> edges[1001]; n } graph; n void dfs(graph *g, int i, int group[], int gn) { n   for (list<int>::iterator it = g->edges[i].begin(); it != g->edges[i].end(); n        it++) { n     if (group[*it] == -1) { n       group[*it] = gn; n       dfs(g, *it, group, gn); n     } n   } n } n void printArray(int arr[], int n) { n   for (int i = 1; i <= n; i++) cout << arr[i] <<    ; n   cout << endl; n } n int main() { n   int n; n   graph *g = new graph; n   cin >> n; n   bool flag = false; n   int fin[1001], pref[1001], group[1001]; n   for (int i = 1; i <= n; i++) cin >> fin[i]; n   for (int i = 1; i <= n; i++) { n     cin >> pref[i]; n     if (i + pref[i] <= n) { n       g->edges[i].push_back(i + pref[i]); n       g->edges[i + pref[i]].push_back(i); n     } n     if (i - pref[i] >= 1) { n       g->edges[i].push_back(i - pref[i]); n       g->edges[i - pref[i]].push_back(i); n     } n   } n   fill_n(group, n + 1, -1); n   int gn = 0; n   for (int i = 1; i <= n; i++) { n     if (group[i] == -1) { n       group[i] = gn; n       dfs(g, i, group, gn); n       gn++; n     } n   } n   for (int i = 1; i <= n; i++) { n     if (group[i] == group[fin[i]]) { n     } else { n       flag = true; n       cout <<  NO  << endl; n       break; n     } n   } n   if (!flag) { n     cout <<  YES  << endl; n   } n } n


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


#include <bits/stdc++.h> n using namespace std; n const int N = 20; n const int inf = 1e9; n int dp[N][2]; n vector<int> a; n void upd(int& at, int val) { at = max(at, val); } n int main() { n   long long n; n   scanf( %lld , &n); n   while (n) { n     a.push_back(n % 10); n     n /= 10; n   } n   for (int i = 0; i < N; i++) { n     dp[i][0] = dp[i][1] = -inf; n   } n   dp[0][0] = 0; n   for (int i = 0; i < a.size(); i++) { n     for (int add = 0; add <= 10; add += 10) { n       for (int st = 0; st <= 1; st++) { n         int sum = add + a[i] - st; n         for (int j = 0; j <= min(9, sum); j++) { n           int k = sum - j; n           if (0 <= k && k <= 9) { n             upd(dp[i + 1][add / 10], dp[i][st] + j + k); n           } n         } n       } n     } n   } n   cout << dp[a.size()][0] << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 400004; n const long long Mod = 1000000007; n int Stop, Bcnt, Dindex, Ecnt; n int Low[N], Dfn[N], Step[N], Belong[N]; n bool instack[N]; n struct Edge { n   int t; n   int next; n } edge[N]; n int head[N]; n void addEdge(int s, int t) { n   edge[Ecnt].t = t; n   edge[Ecnt].next = head[s]; n   head[s] = Ecnt++; n } n void tarjan(int i) { n   int j; n   Dfn[i] = Low[i] = ++Dindex; n   instack[i] = true; n   Step[++Stop] = i; n   for (int e = head[i]; e != -1; e = edge[e].next) { n     j = edge[e].t; n     if (!Dfn[j]) { n       tarjan(j); n       if (Low[j] < Low[i]) Low[i] = Low[j]; n     } else if (instack[j] && Dfn[j] < Low[i]) n       Low[i] = Dfn[j]; n   } n   if (Dfn[i] == Low[i]) { n     Bcnt++; n     do { n       j = Step[Stop--]; n       instack[j] = false; n       Belong[j] = Bcnt; n     } while (j != i); n   } n } n void init() { n   Ecnt = 0; n   memset(head, -1, sizeof(head)); n } n void solve(int n) { n   int i; n   Stop = Bcnt = Dindex = 0; n   memset(Dfn, 0, sizeof(Dfn)); n   memset(Low, -1, sizeof(Low)); n   memset(instack, 0, sizeof(instack)); n   for (i = 1; i <= n; i++) { n     if (!Dfn[i]) { n       tarjan(i); n     } n   } n } n long long num[N]; n long long Pow(int x, int y) { n   long long a = (long long)x; n   long long b = y; n   long long ans = 1; n   if (b == 0) return 1ll; n   while (b > 0) { n     if (b & 1) { n       ans = (ans * (long long)a) % Mod; n     } n     a *= a; n     a %= Mod; n     b >>= 1; n   } n   return ans; n } n int main() { n   int n, x; n   while (~scanf( %d , &n)) { n     init(); n     for (int i = 1; i <= n; i++) { n       scanf( %d , &x); n       addEdge(i, x); n     } n     solve(n); n     memset(num, 0, sizeof(num)); n     for (int i = 1; i <= n; i++) { n       num[Belong[i]]++; n     } n     long long ans = 1; n     for (int i = 1; i <= n; i++) { n       if (num[i]) { n         if (num[i] == 1) { n           ans = (ans * 2) % Mod; n         } else { n           long long tm = ((Pow(2, num[i]) - 2) % Mod + Mod) % Mod; n           ans = ans * tm % Mod; n         } n       } n     } n     printf( %I64d n , ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long mod = 1e9 + 7; n const long long maxn = 3 * 1e5 + 1; n void swap(long long *xp, long long *yp) { n   long long temp = *xp; n   *xp = *yp; n   *yp = temp; n } n void print(vector<long long> v) { n   long long i, j, n = v.size(); n   for (i = 0; i < n; i++) { n     cout << v[i] <<    ; n   } n   cout <<   n ; n } n void scan(vector<long long> &v, long long n) { n   for (long long i = 0; i < n; i++) cin >> v[i]; n } n long long gcd(long long a, long long b) { n   if (b == 0) return a; n   return gcd(b, a % b); n } n long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); } n long long power(long long x, long long y) { n   long long res = 1; n   while (y > 0) { n     if (y & 1) res = (res * x) % mod; n     y = y / 2; n     x = (x * x) % mod; n   } n   return res % mod; n } n long long modinv(long long x) { return power(x, mod - 2) % mod; } n vector<bool> prime(maxn, true); n void sieve() { n   long long n = maxn; n   prime[0] = false; n   prime[1] = false; n   for (long long p = 2; p * p <= n; p++) { n     if (prime[p] == true) { n       for (long long i = p * p; i <= n; i += p) prime[i] = false; n     } n   } n } n int main() { n   long long int i, j, inc, dec, t, r; n   long long int c, d, e, temp, m, p, w, k, x, y, sum, pre, temp2, mid, n, low, n       high, ans; n   t = 1; n   n = 1; n   while (t--) { n     cin >> n; n     sum = 0; n     vector<long long> a; n     vector<long long> tem(maxn, 0); n     a.push_back(0); n     while (n--) { n       long long type; n       cin >> type; n       if (type == 1) { n         cin >> x >> y; n         sum += (x * y); n         tem[x] += y; n       } else if (type == 2) { n         cin >> k; n         a.push_back(k); n         sum += k; n       } else { n         y = a.size(); n         sum -= (a.back() + tem[y]); n         tem[y - 1] += tem[y]; n         tem[y] = 0; n         a.pop_back(); n       } n       x = a.size(); n       double an = (sum * 1.0) / (x * 1.0); n       cout << fixed << setprecision(10) << an <<   n ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, k, arr[1005][1005]; n void ch_col(int x, int y) { n   for (int i = 1; i <= n; i++) swap(arr[i][x], arr[i][y]); n } n void ch_row(int x, int y) { n   for (int i = 1; i <= m; i++) swap(arr[x][i], arr[y][i]); n } n int row[1005], col[1005]; n int main() { n   for (int i = 1; i <= 1005; i++) { n     row[i] = i; n     col[i] = i; n   } n   scanf( %d %d %d , &n, &m, &k); n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= m; j++) scanf( %d , &arr[i][j]); n   while (k--) { n     char order; n     int x, y; n     scanf(  %c %d %d , &order, &x, &y); n     if (order ==  g ) printf( %d n , arr[row[x]][col[y]]); n     if (order ==  c ) swap(col[x], col[y]); n     if (order ==  r ) swap(row[x], row[y]); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, l, t, a[3000010], gx; n double Ans; n signed main() { n   scanf( %lld%lld%lld , &n, &l, &t); n   t *= 2; n   gx = t / l, t %= l; n   for (long long i = 1; i <= n; i++) scanf( %lld , &a[i + n]); n   for (long long i = 1; i <= n; i++) a[i] = a[i + n] - l; n   for (long long i = 1; i <= n; i++) a[i + n + n] = a[i + n] + l; n   for (long long i = 1, j1 = 1, j2 = i + 1; i <= n; i++) { n     while (a[i + n] - a[j1] > t) j1++; n     while (a[j2 + 1] - a[i + n] <= t && j2 + 1 <= 3 * n) j2++; n     Ans += 0.25 * ((n - 1) * gx + i + n - j1 + (n - 1) * gx + j2 - i - n); n   } n   printf( %.6lf n , Ans / 2); n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1000001; n const long long mod = 1000000009; n long long f[N]; n long long getall(int m) { n   long long res = 2; n   for (int i = 1; i < m; ++i) res = (res * 2) % mod; n   return res - 1; n } n long long solve(int n, int m) { n   long long all = getall(m); n   f[1] = getall(m); n   for (int i = 2; i <= n; ++i) f[i] = ((f[i - 1] * (all - (i - 1))) % mod); n   return f[n]; n } n int main() { n   int n, m; n   cin >> n >> m; n   cout << solve(n, m) << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int n, res = 0, m = 0, mx = 0; n   cin >> n; n   vector<int> v(n); n   for (int i = 0; i < n; i++) cin >> v[i]; n   for (int i = 0; i < n; i++) { n     int x = v[i], c = 1; n     for (int j = i + 1; j < n; j++) { n       if (x >= v[j]) { n         c++; n         x = min(v[j], x); n       } else n         break; n     } n     x = v[i]; n     for (int j = i - 1; j >= 0; j--) { n       if (x >= v[j]) { n         c++; n         x = min(v[j], x); n       } else n         break; n     } n     res = max(res, c); n   } n   cout << res << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n #pragma comment(linker,  /STACK:102400000,102400000 ) n const long long INF = 1e18 + 1LL; n const double Pi = acos(-1.0); n const int N = 3e3 + 10, M = 1e3 + 20, mod = 2017, inf = 2e9; n int b[N][N], m, n, a[N][N]; n vector<int> ans1, ans2, ans3, ans4; n int main() { n   scanf( %d%d , &n, &m); n   for (int i = 1; i <= n; ++i) { n     for (int j = 1; j <= m; ++j) scanf( %d , &a[i][j]), b[i][j] = a[i][j]; n   } n   int fi = 0; n   for (int i = 1; i <= n; ++i) { n     int sum = inf; n     for (int j = 1; j <= m; ++j) { n       sum = min(sum, a[i][j]); n     } n     if (sum) { n       for (int j = 1; j <= sum; ++j) ans1.push_back(i); n       for (int j = 1; j <= m; ++j) a[i][j] -= sum; n     } n   } n   for (int i = 1; i <= m; ++i) { n     int sum = inf; n     for (int j = 1; j <= n; ++j) { n       sum = min(sum, a[j][i]); n     } n     if (sum) { n       for (int j = 1; j <= sum; ++j) ans2.push_back(i); n       for (int j = 1; j <= n; ++j) a[j][i] -= sum; n     } n   } n   fi = ans1.size() + ans2.size(); n   for (int i = 1; i <= n; ++i) { n     for (int j = 1; j <= m; ++j) { n       if (a[i][j]) { n         puts( -1 ); n         return 0; n       } n     } n   } n   for (int i = 1; i <= m; ++i) { n     int sum = inf; n     for (int j = 1; j <= n; ++j) { n       sum = min(sum, b[j][i]); n     } n     if (sum) { n       for (int j = 1; j <= sum; ++j) ans4.push_back(i); n       for (int j = 1; j <= n; ++j) b[j][i] -= sum; n     } n   } n   for (int i = 1; i <= n; ++i) { n     int sum = inf; n     for (int j = 1; j <= m; ++j) { n       sum = min(sum, b[i][j]); n     } n     if (sum) { n       for (int j = 1; j <= sum; ++j) ans3.push_back(i); n       for (int j = 1; j <= m; ++j) b[i][j] -= sum; n     } n   } n   int se = ans3.size() + ans4.size(); n   if (fi <= se) { n     cout << ans1.size() + ans2.size() << endl; n     for (int i = 0; i < ans1.size(); ++i) { n       cout <<  row  n            <<     << ans1[i] << endl; n     } n     for (int i = 0; i < ans2.size(); ++i) { n       cout <<  col  n            <<     << ans2[i] << endl; n     } n   } else { n     cout << ans3.size() + ans4.size() << endl; n     for (int i = 0; i < ans3.size(); ++i) { n       cout <<  row  n            <<     << ans3[i] << endl; n     } n     for (int i = 0; i < ans4.size(); ++i) { n       cout <<  col  n            <<     << ans4[i] << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int SIZE = 1e5 + 10; n int a[SIZE]; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int T, n; n   cin >> T; n   while (T--) { n     cin >> n; n     vector<int> ans; n     for (int i = 1; i <= n; i++) { n       cin >> a[i]; n       if (a[i] % 2 == 0) ans.push_back(i); n     } n     if (ans.size()) { n       cout << 1 << endl << ans[0] << endl; n       continue; n     } n     if (n == 1) { n       cout << -1 << endl; n       continue; n     } n     cout << 2 << endl; n     cout << 1 <<     << 2 << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct Point { n   long long x, y; n   Point(long long x_, long long y_) { n     x = x_; n     y = y_; n   } n   Point() {} n   Point operator-(const Point &other) const { n     return Point(x - other.x, y - other.y); n   } n   long long dist(const Point &other) const { n     long long dx = x - other.x; n     long long dy = y - other.y; n     return dx * dx + dy * dy; n   } n   friend long long operator*(const Point &a, const Point &b) { n     return a.x * b.y - a.y * b.x; n   } n }; n long long up(const Point &a) { return a.y > 0 || (a.y == 0 && a.x >= 0); } n long long solve(long long n, vector<Point> poly, Point to) { n   auto cmp = [&](const Point &a, const Point &b) { n     Point f = a - to; n     Point s = b - to; n     if (up(f) == up(s)) { n       return f * s > 0; n     } else { n       return up(f) < up(s); n     } n   }; n   sort(poly.begin(), poly.end(), cmp); n   long long ans = (n * (n - 1) * (n - 2)) / 6; n   for (long long i = 0; i < n; i++) { n     long long rs = 0; n     { n       long long l = 1; n       long long r = n; n       while (r - l > 1) { n         long long m = (r + l) >> 1; n         if ((poly[(i + m) % n] - poly[i]) * (to - poly[i]) >= 0) { n           l = m; n         } else { n           r = m; n         } n       } n       rs = l; n     } n     long long len = rs; n     ans -= (len) * (len - 1) / 2; n   } n   assert(ans >= 0); n   return ans; n } n signed main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   long long n; n   cin >> n; n   vector<Point> poly(n); n   for (auto &t : poly) { n     cin >> t.x >> t.y; n   } n   long long ans = 0; n   for (long long i = 0; i < n; i++) { n     auto np = poly; n     np.erase(np.begin() + i); n     ans += solve(n - 1, np, poly[i]); n   } n   cout << ans * (n - 4) / 2 << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int n, a[201], dp[201][201][1001]; n const long long int MOD = 1e9 + 7; n int solve(int i, int g, int k) { n   if (g < 0 || k < 0) return 0; n   if (i == n) return (g == 0); n   if (dp[i][g][k] != -1) return dp[i][g][k]; n   long long int ret = 0; n   int nk = k - g * (a[i] - a[i - 1]); n   if (nk >= 0) { n     ret = (ret + 1LL * g * solve(i + 1, g - 1, nk)) % MOD; n     ret = (ret + 1LL * (g + 1) * solve(i + 1, g, nk)) % MOD; n     ret = (ret + 1LL * solve(i + 1, g + 1, nk)) % MOD; n   } n   return dp[i][g][k] = ret; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int k; n   cin >> n >> k; n   for (int i = 0; i < n; i++) cin >> a[i]; n   sort(a, a + n); n   memset(dp, -1, sizeof dp); n   cout << solve(0, 0, k); n } n


#include<stdio.h> n #include<iostream> n #include<string.h> n #include<vector> n #include<queue> n #include<map> n #include<math.h> n #include<algorithm> n #include<stdlib.h> n #include<string> n #include<stack> n #include<set> n using namespace std; n #define pb push_back n #define POP pop_back() n #define DEBUG cout <<  DEBUG n ; n #define ll long long n #define db double n #define endl   n  n #define fo(i,a,b) for(int i = a;i <= b;i++) n #define lowbit(x) (x&-x); n const int maxn = 5e5+5; n const int inf = 0x3f3f3f3f; n const ll inF = 0x3f3f3f3f3f3f3f3f; n const ll mod = 1e8; n const db eps = 1e-8; n struct node{ n  int v , id; n  bool operator < (const node &b)const{ n   return v < b.v; n  } n }; n node cnt[maxn]; n int a[maxn]; n int main(){ n  int t , n;cin >> t; n  while(t--){ n   cin >> n; n   for(int i = 1;i <= n;i++)cnt[i].v = cnt[i].id = 0; n   for(int i = 1;i <= n;i++)scanf( %d ,&a[i]) , cnt[a[i]].v++ , cnt[a[i]].id = i; n   int ans = -1; n   for(int i = 1;i <= n;i++){ n    if(cnt[i].v == 1){ans = cnt[i].id;break;} n   } n   if(ans == -1){ n    cout <<  -1 n ; n   } n   else cout << ans << endl; n  } n  return 0; n }


#include <bits/stdc++.h> n using namespace std; n char s[120][120]; n int n, m; n int main() { n   int i, j, k, res = 30, now = 0; n   string ss =   ; n   scanf( %d%d , &n, &m); n   for (i = 0; i < n; i++) scanf( %s , s[i]); n   for (i = 0; i < n; i++) { n     for (j = 0; j < m; j++) { n       char c = s[i][j]; n       int f = 0; n       for (k = 0; k < n; k++) { n         if (i == k) continue; n         if (s[k][j] == c) f = 1; n       } n       for (k = 0; k < m; k++) { n         if (j == k) continue; n         if (s[i][k] == c) f = 1; n       } n       if (!f) ss += c; n     } n   } n   cout << ss << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool within(int x1, int x2, int y1, int y2, int px, int py) { n   if (x1 <= px and px <= x2 and y1 <= py and py <= y2) { n     return true; n   } n   return false; n } n int main() { n   ios::sync_with_stdio(false); n   int y, x, v, n; n   cin >> y >> x >> v >> n; n   int py[v], px[v]; n   for (int i = 0; i < v; i++) { n     cin >> px[i] >> py[i]; n     py[i]--, px[i]--; n   } n   int res = 0; n   for (int x1 = 0; x1 < x; x1++) { n     for (int x2 = x1; x2 < x; x2++) { n       for (int y1 = 0; y1 < y; y1++) { n         for (int y2 = y1; y2 < y; y2++) { n           int found = 0; n           for (int i = 0; i < v; i++) { n             if (within(x1, x2, y1, y2, py[i], px[i])) { n               found++; n             } n           } n           if (found >= n) { n             res++; n           } n         } n       } n     } n   } n   cout << res; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, x = 4, y = 5; n   scanf( %d , &n); n   if (n == 1 || n == 2) { n     cout << 1; n     return 0; n   } n   while (y < n) { n     if (x & 1) n       x = 2 * y, y = x + 1; n     else n       x = 2 * y - 1, y = x + 1; n   } n   printf( %d , (x == n || y == n)); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 0x3f3f3f3f; n const long long INFF = 0x3f3f3f3f3f3f3f3fll; n const long long M = 1e9 + 7; n const long long maxn = 1e6 + 7; n const double pi = acos(-1.0); n const double eps = 0.0000000001; n long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } n template <typename T> n inline void pr2(T x, int k = 64) { n   long long i; n   for (i = 0; i < k; i++) fprintf(stderr,  %d , (x >> i) & 1); n   putchar(   ); n } n template <typename T> n inline void add_(T &A, int B) { n   A += B; n   (A >= M) && (A -= M); n } n template <typename T> n inline void mul_(T &A, long long B) { n   (A *= B) %= M; n } n template <typename T> n inline void mod_(T &A, long long B = M) { n   A %= M; n } n template <typename T> n inline void max_(T &A, T B) { n   (A < B) && (A = B); n } n template <typename T> n inline void min_(T &A, T B) { n   (A > B) && (A = B); n } n template <typename T> n inline T abs(T a) { n   return a > 0 ? a : -a; n } n template <typename T> n inline T powMM(T a, T b) { n   T ret = 1; n   for (; b; b >>= 1ll, a = (long long)a * a % M) n     if (b & 1) ret = (long long)ret * a % M; n   return ret; n } n int n, m, q; n char str[maxn]; n int TaskA(); n void Task_one() { TaskA(); } n void Task_T() { n   int T; n   scanf( %d , &T); n   while (T--) TaskA(); n } n void Task_more_n() { n   while (~scanf( %d , &n)) TaskA(); n } n void Task_more_n_m() { n   while (~scanf( %d%d , &n, &m)) TaskA(); n } n void Task_more_n_m_q() { n   while (~scanf( %d%d%d , &n, &m, &q)) TaskA(); n } n void Task_more_string() { n   while (~scanf( %s , str)) TaskA(); n } n int A[maxn]; n int TaskA() { n   int i, t, k; n   scanf( %d%d , &n, &k); n   t = k; n   for (i = 1; i <= n; i++) scanf( %d , &A[i]), t = gcd(t, A[i]); n   printf( %d n , k / t); n   for (i = 0; i < k / t; i++) printf( %d  , i * t); n   return 0; n } n void initialize() {} n int main() { n   int startTime = clock(); n   initialize(); n   fprintf(stderr,  /--- initializeTime: %ld milliseconds ---/ n , n           clock() - startTime); n   Task_one(); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   vector<int> arr(n); n   for (int i = 0; i < n; i++) { n     cin >> arr[i]; n   } n   int m; n   cin >> m; n   while (m--) { n     int k, pos; n     cin >> k >> pos; n     pos--; n     vector<vector<int>> ans(k); n     vector<long long> sums(k); n     int last = 0; n     for (int i = 0; i < n; i++) { n       for (int j = last; j >= 0; j--) { n         if (j >= k) continue; n         if (ans[j].size() == 0) { n           if (j == 0) { n             ans[j].push_back(arr[i]); n             sums[j] = arr[i]; n           } else { n             ans[j] = ans[j - 1]; n             ans[j].push_back(arr[i]); n             sums[j] = sums[j - 1] + arr[i]; n           } n         } else { n           if (j == 0) { n             if (arr[i] > sums[j]) { n               ans[j][0] = arr[i]; n               sums[j] = arr[i]; n             } n           } else if (sums[j - 1] + arr[i] > sums[j]) { n             sums[j] = sums[j - 1] + arr[i]; n             ans[j] = ans[j - 1]; n             ans[j].push_back(arr[i]); n           } else if (sums[j - 1] + arr[i] == sums[j]) { n             bool change = 0; n             for (int k = 0; k < ans[j - 1].size(); k++) { n               if (ans[j - 1][k] < ans[j][k]) { n                 change = 1; n                 break; n               } else if (ans[j - 1][k] > ans[j][k]) { n                 break; n               } n             } n             if (change) { n               ans[j] = ans[j - 1]; n               ans[j].push_back(arr[i]); n             } n           } n         } n       } n       last += 1; n     } n     cout << ans[k - 1][pos] <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void Fast() { n   ios::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n } n void File() {} n using ll = long long; n using ull = unsigned long long; n ll gcd(ll a, ll b) { return !b ? a : gcd(b, a % b); } n const int N = 100001; n bool prime[N]; n int n, res[N]; n vector<int> v, primes; n vector<vector<int>> numFactors, primeIdx; n vector<int>::iterator it; n void sieve() { n   for (int i = 0; i < N; i++) prime[i] = 1; n   prime[0] = prime[1] = 0; n   for (int i = 4; i < N; i += 2) { n     prime[i] = 0; n   } n   for (int i = 3; i * i < N; i += 2) { n     if (prime[i]) { n       for (int j = i * i; j < N; j += i + i) { n         prime[j] = 0; n       } n     } n   } n   for (int i = 2; i < N; i++) { n     if (prime[i]) { n       primes.push_back(i); n     } n   } n } n void Prime_Factors_Faster(int n, int id) { n   int temp = n; n   if (prime[n]) { n     primeIdx[n].push_back(id); n     numFactors[temp].push_back(n); n     return; n   } n   int idx = 0; n   while (idx < primes.size() && primes[idx] * primes[idx] <= n) { n     int cnt = 0; n     while (n % primes[idx] == 0) { n       n /= primes[idx]; n       cnt++; n     } n     if (cnt) n       numFactors[temp].push_back(primes[idx]), n           primeIdx[primes[idx]].push_back(id); n     ; n     idx++; n   } n   if (n > 1) { n     primeIdx[n].push_back(id); n     numFactors[temp].push_back(n); n   } n } n int solve(int idx) { n   int& ans = res[idx]; n   if (~ans) return ans; n   ans = 1; n   for (int i = 0; i < numFactors[v[idx]].size(); i++) { n     int pr = numFactors[v[idx]][i]; n     it = upper_bound(primeIdx[pr].begin(), primeIdx[pr].end(), idx); n     if (it != primeIdx[pr].end()) ans = max(ans, solve(*it) + 1); n   } n   return ans; n } n int main() { n   File(), Fast(); n   sieve(); n   numFactors.resize(N), primeIdx.resize(N); n   cin >> n; n   v.resize(n); n   for (int i = 0; i < n; i++) { n     cin >> v[i], Prime_Factors_Faster(v[i], i); n   } n   int* dp = new int[n]; n   for (int i = 0; i < n; i++) dp[i] = 1; n   for (int i = 0; i < n; i++) cin >> v[i], Prime_Factors_Faster(v[i], i); n   for (int i = n - 1; i >= 0; i--) { n     for (int j = 0; j < numFactors[v[i]].size(); j++) { n       int pr = numFactors[v[i]][j]; n       it = upper_bound(primeIdx[pr].begin(), primeIdx[pr].end(), i); n       if (it != primeIdx[pr].end() and v[*it] > v[i]) n         dp[i] = max(dp[i], dp[*it] + 1); n     } n   } n   cout << *max_element(dp, dp + n) <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n int n, k, cnt; n pair<int, int> Ans[100010]; n int main() { n   scanf( %d%d , &n, &k); n   if (k == 1 || k > 3 || n <= 3 || (k == 2 && n == 4)) { n     puts( -1 ); n     return 0; n   } n   if (k == 2) { n     printf( %d n , n - 1); n     for (int i = 1; i < n; i++) printf( %d %d n , i, i + 1); n   } else { n     Ans[++cnt] = make_pair(2, 3); n     for (int i = 5; i <= n; i++) n       Ans[++cnt] = make_pair(2, i), Ans[++cnt] = make_pair(3, i); n     Ans[++cnt] = make_pair(1, 2); n     Ans[++cnt] = make_pair(3, 4); n     printf( %d n , cnt); n     for (int i = 1; i <= cnt; i++) n       printf( %d %d n , Ans[i].first, Ans[i].second); n   } n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native ) n #pragma GCC optimize( unroll-loops ) n #pragma GCC optimize( Ofast ) n #pragma GCC optimize( O3 ) n #pragma GCC target( avx ) n using namespace std; n long long fpow(long long x, long long y, long long m) { n   long long temp; n   if (y == 0 || x == 1) return 1; n   temp = fpow(x, y / 2, m); n   if (y % 2 == 0) n     return ((temp) * (temp)) % m; n   else n     return (((x) % m) * ((temp * temp) % m)) % m; n } n long long gcd(long long a, long long b) { n   if (b == 0) return a; n   return gcd(b, a % b); n } n void sieve(long long n) { n   bool prime[5 * 300005]; n   memset(prime, true, sizeof(prime)); n   for (long long p = 2; p * p <= n; p++) n     if (prime[p] == true) n       for (long long i = p * p; i <= n; i += p) prime[i] = false; n   prime[1] = 0; n } n inline long long read() { n   long long p = 1, ans = 0; n   char ch = getchar(); n   while (ch < 48 || ch > 57) { n     if (ch ==  - ) p = -1; n     ch = getchar(); n   } n   while (ch >= 48 && ch <= 57) { n     ans = (ans << 3) + (ans << 1) + ch - 48; n     ch = getchar(); n   } n   return ans * p; n } n long long cnt, sum, mid, mx = -1e17, mn = 1e17, a[2 * 300005]; n long long n, m, d, t, i, j, k, l, r, x, y, z; n bool f, f1, f2; n string s; n int32_t main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   n = read(); n   vector<long long> s(n + 2); n   for ((i) = 1; (i) <= ((n + 1) / 2); (i)++) { n     a[i] = read(); n     s[i] = a[i] + s[i - 1]; n   } n   x = read(); n   for (; i <= n; i++) s[i] = s[i - 1] + x; n   if (s[n] > 0) { n     cout << n; n     return 0; n   } n   if (x >= 0) { n     cout << -1; n   } else { n     vector<long long> dp(n + 2); n     sum = 0; n     for ((i) = 1; (i) <= ((n + 1) / 2); (i)++) { n       sum += x - a[i]; n       dp[i] = min(dp[i - 1], sum); n     } n     for (k = ((n + 1) >> 1); k <= n; k++) { n       if (s[k] + dp[n - k] > 0) { n         cout << k; n         return 0; n       } n     } n     cout << -1; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int mod = 1000000007; n const double eps = 1e-6; n const int inf = 0x3f3f3f3f; n const long long INF = 100000000000000000ll; n const int MAXN = 4004; n const int MAXM = 300030; n int dp[MAXN][MAXN]; n int main() { n   int n; n   cin >> n; n   dp[0][0] = 1; n   for (int i = 1; i <= n + 1; i++) { n     dp[i][0] = dp[i - 1][i - 1]; n     for (int j = 1; j <= i; j++) { n       dp[i][j] = (dp[i][j - 1] + dp[i - 1][j - 1]) % mod; n     } n   } n   printf( %d n , (dp[n + 1][0] - dp[n][0] + mod) % mod); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int n; n   string second; n   cin >> n >> second; n   int i; n   int p = 0; n   for (i = 0; i < n; i++) { n     if (second[i] ==  8 ) p++; n   } n   int m = (n - p) / 10; n   if (p > m) { n     cout << n / 11; n   } else n     cout << min(p, m); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, u, v, c, a[100005], b[100005]; n vector<int> adj[100005]; n int mod_pow(int a, int b) { n   int rtn = 1; n   while (b) { n     if (b & 1) rtn = (1ll * rtn * a) % 1000000007; n     a = 1ll * a * a % 1000000007; n     b /= 2; n   } n   return rtn; n } n void dfs(int vtx, int p) { n   if (adj[vtx].size() == 1 && vtx) return; n   for (int i = 0; i < adj[vtx].size(); i++) { n     int u = adj[vtx][i] / 10005, w = adj[vtx][i] % 10005; n     b[vtx] = (b[vtx] + w) % 1000000007; n     if (u == p) continue; n     dfs(u, vtx); n     a[vtx] = (a[vtx] + a[u]) % 1000000007, n     b[vtx] = (1ll * b[vtx] + b[u]) % 1000000007; n   } n   a[vtx] = mod_pow((adj[vtx].size() - a[vtx] + 1000000007) % 1000000007, n                    1000000007 - 2); n   b[vtx] = (1ll * a[vtx] * b[vtx]) % 1000000007; n } n int main() { n   scanf( %d , &n); n   for (int i = 0; i < n - 1; i++) { n     scanf( %d %d %d , &u, &v, &c); n     adj[u].push_back(v * 10005 + c); n     adj[v].push_back(u * 10005 + c); n   } n   dfs(0, -1); n   printf( %d , b[0]); n } n


#include <bits/stdc++.h> n template <typename T> n class IntegerIterator { n  public: n   using value_type = T; n   using difference_type = std::ptrdiff_t; n   using pointer = T *; n   using reference = T; n   using iterator_category = std::input_iterator_tag; n   explicit IntegerIterator(T value) : value(value) {} n   IntegerIterator &operator++() { n     ++value; n     return *this; n   } n   IntegerIterator operator++(int) { n     IntegerIterator copy = *this; n     ++value; n     return copy; n   } n   IntegerIterator &operator--() { n     --value; n     return *this; n   } n   IntegerIterator operator--(int) { n     IntegerIterator copy = *this; n     --value; n     return copy; n   } n   T operator*() const { return value; } n   bool operator==(IntegerIterator rhs) const { return value == rhs.value; } n   bool operator!=(IntegerIterator rhs) const { return !(*this == rhs); } n  n  private: n   T value; n }; n template <typename T> n class IntegerRange { n  public: n   IntegerRange(T begin, T end) : begin_(begin), end_(end) { ; } n   IntegerIterator<T> begin() const { return IntegerIterator<T>(begin_); } n   IntegerIterator<T> end() const { return IntegerIterator<T>(end_); } n  n  private: n   T begin_; n   T end_; n }; n template <typename T> n class ReversedIntegerRange { n   using IteratorType = std::reverse_iterator<IntegerIterator<T>>; n  n  public: n   ReversedIntegerRange(T begin, T end) : begin_(begin), end_(end) { ; } n   IteratorType begin() const { n     return IteratorType(IntegerIterator<T>(begin_)); n   } n   IteratorType end() const { return IteratorType(IntegerIterator<T>(end_)); } n  n  private: n   T begin_; n   T end_; n }; n template <typename T> n IntegerRange<T> range(T to) { n   return IntegerRange<T>(0, to); n } n template <typename T> n IntegerRange<T> range(T from, T to) { n   return IntegerRange<T>(from, to); n } n template <typename T> n IntegerRange<T> inclusiveRange(T to) { n   return IntegerRange<T>(0, to + 1); n } n template <typename T> n IntegerRange<T> inclusiveRange(T from, T to) { n   return IntegerRange<T>(from, to + 1); n } n template <typename T> n ReversedIntegerRange<T> downrange(T from) { n   return ReversedIntegerRange<T>(from, 0); n } n template <typename T> n ReversedIntegerRange<T> downrange(T from, T to) { n   return ReversedIntegerRange<T>(from, to); n } n template <typename T> n ReversedIntegerRange<T> inclusiveDownrange(T from) { n   return ReversedIntegerRange<T>(from + 1, 0); n } n template <typename T> n ReversedIntegerRange<T> inclusiveDownrange(T from, T to) { n   return ReversedIntegerRange<T>(from + 1, to); n } n using namespace std; n class CYouAreGivenAWASDString { n  public: n   void solve(std::istream &in, std::ostream &out) { n     int t; n     in >> t; n     while (t--) { n       string str; n       in >> str; n       int n = str.size(); n       vector<int> maxx1(n + 1), minx1(n + 1), maxy1(n + 1), miny1(n + 1), n           maxx2(n + 1), maxy2(n + 1), minx2(n + 1), miny2(n + 1); n       int x = 0, y = 0; n       for (int i : range(n)) { n         if (str[i] ==  W ) { n           y++; n         } else if (str[i] ==  S ) { n           y--; n         } else if (str[i] ==  A ) { n           x--; n         } else { n           x++; n         } n         minx1[i + 1] = min(minx1[i], x); n         maxx1[i + 1] = max(maxx1[i], x); n         miny1[i + 1] = min(miny1[i], y); n         maxy1[i + 1] = max(maxy1[i], y); n       } n       minx2[n] = maxx2[n] = x; n       miny2[n] = maxy2[n] = y; n       for (int i : downrange(n)) { n         if (str[i] ==  W ) { n           y--; n         } else if (str[i] ==  S ) { n           y++; n         } else if (str[i] ==  A ) { n           x++; n         } else { n           x--; n         } n         minx2[i] = min(minx2[i + 1], x); n         maxx2[i] = max(maxx2[i + 1], x); n         miny2[i] = min(miny2[i + 1], y); n         maxy2[i] = max(maxy2[i + 1], y); n       } n       long long res = n           (long long)(maxx1[n] - minx1[n] + 1) * (maxy1[n] - miny1[n] + 1); n       for (int i : inclusiveRange(0, n)) { n         for (int j : range(4)) { n           int dx = 0, dy = 0; n           if (j % 2 == 0) { n             if (j / 2) { n               dx = 1; n             } else { n               dx = -1; n             } n           } else { n             if (j / 2) { n               dy = 1; n             } else { n               dy = -1; n             } n           } n           int maxX = max(maxx1[i], maxx2[i] + dx), n               minX = min(minx1[i], minx2[i] + dx), n               maxY = max(maxy1[i], maxy2[i] + dy), n               minY = min(miny1[i], miny2[i] + dy); n           res = min(res, (long long)(maxX - minX + 1) * (maxY - minY + 1)); n         } n       } n       out << res <<   n ; n     } n   } n   void setup() {} n }; n int main() { n   std::ios_base::sync_with_stdio(false); n   CYouAreGivenAWASDString solver; n   solver.setup(); n   std::istream &in(std::cin); n   std::ostream &out(std::cout); n   in.tie(nullptr); n   out << std::fixed; n   out.precision(20); n   solver.solve(in, out); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void solve() { n   int a = 1, l = -1, r = -1; n   string s; n   for (int i = 1; i <= 30; i++) { n     cout <<  ?   << (1 << i) <<     << (1 << (i - 1)) << endl; n     cin >> s; n     if (s ==  x ) { n       continue; n     } else { n       l = (1 << (i - 1)) + 1; n       r = (1 << i); n       break; n     } n   } n   if (r == 2) { n     cout <<  ! 2  << endl; n     return; n   } else if (l == -1) { n     cout <<  ! 1  << endl; n     return; n   } n   int GUESS1 = r; n   l = 0, r = r >> 1; n   int md, ans; n   while (l < r) { n     md = (l + r) >> 1; n     cout <<  ?   << GUESS1 <<     << md << endl; n     cin >> s; n     if (s ==  x ) { n       l = md + 1; n       ans = md; n     } else { n       r = md; n     } n   } n   cout <<  !   << GUESS1 - ans << endl; n } n int32_t main() { n   string now; n   while (cin >> now) { n     if (now ==  end ) break; n     solve(); n   } n   return 0; n } n


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


#include <bits/stdc++.h> n int a[128][128], v[128], cor[128], bucket[128]; n int m, n; n int main() { n   scanf( %d%d , &n, &m); n   for (int i = 1; i <= m; ++i) { n     scanf( %d , &v[i]); n     cor[i] = 1; n     for (int j = 2; j <= n; ++j) { n       int x; n       scanf( %d , &x); n       if (x > v[i]) { n         v[i] = x; n         cor[i] = j; n       } n     } n   } n   for (int i = 1; i <= m; ++i) { n     bucket[cor[i]]++; n   } n   int rez = bucket[1]; n   int cand = 1; n   for (int i = 2; i <= n; ++i) { n     if (bucket[i] > rez) { n       rez = bucket[i]; n       cand = i; n     } n   } n   printf( %d n , cand); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int Mo = 998244353; n const int N = 2e5 + 50; n const int md = 998244353; n inline void add(int &x, int y) { n   x += y; n   if (x >= md) { n     x -= md; n   } n } n inline void sub(int &x, int y) { n   x -= y; n   if (x < 0) { n     x += md; n   } n } n inline int mul(int x, int y) { return (long long)x * y % md; } n inline int power(int x, int y) { n   int res = 1; n   for (; y; y >>= 1, x = mul(x, x)) { n     if (y & 1) { n       res = mul(res, x); n     } n   } n   return res; n } n inline int inv(int a) { n   a %= md; n   if (a < 0) { n     a += md; n   } n   int b = md, u = 0, v = 1; n   while (a) { n     int t = b / a; n     b -= t * a; n     swap(a, b); n     u -= t * v; n     swap(u, v); n   } n   if (u < 0) { n     u += md; n   } n   return u; n } n namespace ntt { n int base = 1, root = -1, max_base = -1; n vector<int> rev = {0, 1}, roots = {0, 1}; n void init() { n   int temp = md - 1; n   max_base = 0; n   while (temp % 2 == 0) { n     temp >>= 1; n     ++max_base; n   } n   root = 2; n   while (true) { n     if (power(root, 1 << max_base) == 1 && n         power(root, 1 << max_base - 1) != 1) { n       break; n     } n     ++root; n   } n } n void ensure_base(int nbase) { n   if (max_base == -1) { n     init(); n   } n   if (nbase <= base) { n     return; n   } n   assert(nbase <= max_base); n   rev.resize(1 << nbase); n   for (int i = 0; i < 1 << nbase; ++i) { n     rev[i] = rev[i >> 1] >> 1 | (i & 1) << nbase - 1; n   } n   roots.resize(1 << nbase); n   while (base < nbase) { n     int z = power(root, 1 << max_base - 1 - base); n     for (int i = 1 << base - 1; i < 1 << base; ++i) { n       roots[i << 1] = roots[i]; n       roots[i << 1 | 1] = mul(roots[i], z); n     } n     ++base; n   } n } n void dft(vector<int> &a) { n   int n = a.size(), zeros = __builtin_ctz(n); n   ensure_base(zeros); n   int shift = base - zeros; n   for (int i = 0; i < n; ++i) { n     if (i < rev[i] >> shift) { n       swap(a[i], a[rev[i] >> shift]); n     } n   } n   for (int i = 1; i < n; i <<= 1) { n     for (int j = 0; j < n; j += i << 1) { n       for (int k = 0; k < i; ++k) { n         int x = a[j + k], y = mul(a[j + k + i], roots[i + k]); n         a[j + k] = (x + y) % md; n         a[j + k + i] = (x + md - y) % md; n       } n     } n   } n } n vector<int> multiply(vector<int> a, vector<int> b) { n   int need = a.size() + b.size() - 1, nbase = 0; n   while (1 << nbase < need) { n     ++nbase; n   } n   ensure_base(nbase); n   int sz = 1 << nbase; n   a.resize(sz); n   b.resize(sz); n   bool equal = a == b; n   dft(a); n   if (equal) { n     b = a; n   } else { n     dft(b); n   } n   int inv_sz = inv(sz); n   for (int i = 0; i < sz; ++i) { n     a[i] = mul(mul(a[i], b[i]), inv_sz); n   } n   reverse(a.begin() + 1, a.end()); n   dft(a); n   a.resize(need); n   return a; n } n }  // namespace ntt n using ntt::multiply; n vector<int> &operator*=(vector<int> &a, const vector<int> &b) { n   if (min(a.size(), b.size()) < 128) { n     vector<int> c = a; n     a.assign(a.size() + b.size() - 1, 0); n     for (int i = 0; i < c.size(); ++i) { n       for (int j = 0; j < b.size(); ++j) { n         add(a[i + j], mul(c[i], b[j])); n       } n     } n   } else { n     a = multiply(a, b); n   } n   return a; n } n vector<int> operator*(const vector<int> &a, const vector<int> &b) { n   vector<int> c = a; n   return c *= b; n } n int val[26], p[26]; n char s[N], t[N]; n long long ans[N]; n vector<int> A, B, C; n int a[5][N], b[5][N]; n int main(int argc, const char *argv[]) { n   srand((unsigned)time(0)); n   for (int i = 0; i < 26; i++) { n     val[i] = rand() % Mo; n     int x; n     scanf( %d , &x); n     p[x - 1] = i; n   } n   scanf( %s , s); n   int ls = (int)strlen(s); n   scanf( %s , t); n   int lt = (int)strlen(t); n   for (int i = 0; i < lt; i++) { n     int id = t[i] -  a ; n     long long u = val[id], v = val[p[id]]; n     a[4][i] = 1; n     a[3][i] = (-2 * u - 2 * v) % Mo; n     a[2][i] = (u * u % Mo + v * v % Mo + 4 * u * v % Mo) % Mo; n     a[1][i] = -2 * u * v % Mo * (u + v) % Mo; n     a[0][i] = u * u % Mo * v % Mo * v % Mo; n     for (int j = 0; j < 5; j++) { n       if (a[j][i] < 0) { n         a[j][i] += Mo; n       } n     } n   } n   for (int i = 0; i < ls; i++) { n     int id = s[i] -  a ; n     long long u = val[id]; n     b[0][i] = 1; n     for (int j = 1; j < 5; j++) { n       b[j][i] = u * b[j - 1][i] % Mo; n     } n   } n   for (int i = 0; i < 5; i++) { n     A = std::vector<int>(a[i], a[i] + lt); n     reverse(b[i], b[i] + ls); n     B = std::vector<int>(b[i], b[i] + ls); n     C = A * B; n     for (int j = ls - 1; j < lt; j++) { n       ans[j] += C[j]; n     } n   } n   for (int j = ls - 1; j < lt; j++) { n     putchar(ans[j] % Mo == 0 ?  1  :  0 ); n   } n   putchar(10); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct v3 { n   int x, y, z, i; n   v3 cross(const v3& rhs) { n     return {y * rhs.z - z * rhs.y, -(x * rhs.z - z * rhs.x), n             x * rhs.y - y * rhs.x}; n   } n   long long dot(const v3& rhs) { return x * rhs.x + y * rhs.y + z * rhs.z; } n }; n vector<pair<int, int> > ans; n v3 pts[111111]; n int pidx[6][111111]; n bool chk(int n, int k) { n   if (n <= k) { n     for (int i = 0; i < n; i++) ans.push_back({pidx[k][i] + 1, -1}); n     return true; n   } n   if (k == 0) return false; n   int mdel = -1, ma, mb, nn = 0; n   for (int i = 0; i < 100; i++) { n     int a = rand() % n; n     int b = rand() % (n - 1); n     if (b >= a) b++; n     v3 pt = pts[pidx[k][a]].cross(pts[pidx[k][b]]); n     if (pt.z == 0) continue; n     int del = 0; n     for (int j = 0; j < n; j++) { n       if (pt.dot(pts[pidx[k][j]]) == 0LL) del++; n     } n     if (del > mdel) { n       nn = 0; n       for (int j = 0; j < n; j++) { n         if (pt.dot(pts[pidx[k][j]]) != 0LL) pidx[k - 1][nn++] = pidx[k][j]; n       } n       mdel = del; n       ma = pidx[k][a] + 1, mb = pidx[k][b] + 1; n     } n   } n   if (mdel == -1) return false; n   ans.push_back({ma, mb}); n   if (chk(nn, k - 1)) return true; n   ans.pop_back(); n   return false; n } n int N, K; n int main() { n   srand(unsigned(time(0))); n   scanf( %d%d , &N, &K); n   for (int i = 0; i < N; i++) { n     scanf( %d%d%d , &pts[i].x, &pts[i].y, &pts[i].z); n     pidx[K][i] = i; n   } n   if (chk(N, K)) { n     printf( YES n ); n     printf( %d n , (int)ans.size()); n     for (auto it : ans) { n       printf( %d %d n , it.first, it.second); n     } n   } else { n     printf( NO ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double pi = acos(-1.0); n const int mod = 998244353; n void reduce(int &a) { a += a >> 31 & mod; } n int Mod(int x) { return x >= mod ? x - mod : x; } n long long read() { n   long long x = 0; n   int f = 1; n   char ch = getchar(); n   for (; !isdigit(ch); ch = getchar()) n     if (ch ==  - ) f = -1; n   for (; isdigit(ch); ch = getchar()) x = x * 10 + (ch ^ 48); n   return x * f; n } n void print(long long x) { n   if (x < 0) putchar( - ), x = -x; n   if (x > 9) print(x / 10); n   putchar(x % 10 +  0 ); n } n int qpow(int a, int b) { n   int ans = 1; n   for (; b; b >>= 1, a = (long long)a * a % mod) n     if (b & 1) ans = (long long)ans * a % mod; n   return ans; n } n const int N = 800010, G = 3, Gi = 332748118, inv2 = 499122177, img = 86583718; n int rev[N], ul[N], gg[20][N]; n int G_init() { n   for (int i = 0; i < 20; i++) { n     int *G = gg[i]; n     G[0] = 1; n     const int gi = G[1] = qpow(3, (mod - 1) / (1 << i + 1)); n     for (int j = 2; j < (1 << i); j++) G[j] = (long long)G[j - 1] * gi % mod; n   } n   return 0; n } n int I = G_init(); n void NTT(int *a, const int n, const int type) { n   for (int i = 0; i < n; i++) n     if (i < rev[i]) swap(a[i], a[rev[i]]); n   int lim = log(n) / log(2) + 0.5; n   for (int k = 1; k <= lim; k++) { n     const int l = 1 << k, m = l >> 1, *G = gg[k - 1]; n     for (int *p = a; p != a + n; p += l) n       for (int i = 0; i < m; i++) { n         const int t = (long long)p[i + m] * G[i] % mod; n         reduce(p[i + m] = p[i] - t), reduce(p[i] += t - mod); n       } n   } n   if (~type) return; n   const int inv = qpow(n, mod - 2); n   for (int i = 0; i < n; i++) a[i] = (long long)a[i] * inv % mod; n   reverse(a + 1, a + n); n } n void calc_rev(int &n, int &lim, const int m) { n   n = 1, lim = 0; n   while (n < m) n <<= 1, lim++; n   for (int i = 1; i < n; i++) n     rev[i] = (rev[i >> 1] >> 1) | ((i & 1) << lim - 1); n } n void Mul(const int *a, const int *b, int *c, const int m1, const int m2) { n   static int x[N], y[N]; n   int n, lim; n   calc_rev(n, lim, m1 + m2); n   for (int i = 0; i < m1; i++) x[i] = a[i]; n   for (int i = m1; i < n; i++) x[i] = 0; n   for (int i = 0; i < m2; i++) y[i] = b[i]; n   for (int i = m2; i < n; i++) y[i] = 0; n   NTT(x, n, 1), NTT(y, n, 1); n   for (int i = 0; i < n; i++) c[i] = (long long)x[i] * y[i] % mod; n   NTT(c, n, -1); n   for (int i = m1 + m2 - 1; i < n; i++) c[i] = 0; n } n void Inv(const int *a, int *b, const int len) { n   static int c[N]; n   if (len == 1) { n     b[0] = qpow(a[0], mod - 2); n     return; n   } n   Inv(a, b, len + 1 >> 1); n   int n, lim; n   calc_rev(n, lim, len << 1); n   for (int i = 0; i < n; i++) c[i] = a[i]; n   for (int i = len; i < n; i++) c[i] = 0; n   NTT(c, n, 1), NTT(b, n, 1); n   for (int i = 0; i < n; i++) n     b[i] = (2 - (long long)c[i] * b[i] % mod + mod) * b[i] % mod; n   NTT(b, n, -1); n   for (int i = len; i < n; i++) b[i] = 0; n } n void Der(const int *a, int *b, const int len) { n   for (int i = 1; i < len; i++) b[i - 1] = (long long)a[i] * i % mod; n   b[len - 1] = 0; n } n void Inte(const int *a, int *b, const int len) { n   for (int i = len - 1; i; i--) n     b[i] = (long long)a[i - 1] * qpow(i, mod - 2) % mod; n   b[0] = 0; n } n void Ln(const int *a, int *b, const int len) { n   static int c[N], inv[N]; n   memset(inv, 0, len << 4); n   Der(a, c, len), Inv(a, inv, len); n   Mul(c, inv, c, len, len), Inte(c, b, len); n } n void Exp(const int *a, int *b, const int len) { n   static int c[N]; n   if (len == 1) { n     b[0] = 1; n     return; n   } n   Exp(a, b, len + 1 >> 1); n   int lim, n; n   calc_rev(n, lim, len << 1); n   Ln(b, c, len); n   for (int i = 0; i < len; i++) reduce(c[i] = a[i] - c[i]); n   c[0]++; n   for (int i = len; i < n; i++) c[i] = 0; n   Mul(b, c, b, len, len); n   for (int i = len; i < n; i++) b[i] = 0; n } n void Power(const int *a, int *b, const int len, const char *k, int m = -1) { n   int m1 = 0, m2 = 0, m3 = 0; n   if (~m) n     m1 = m2 = m3 = m; n   else { n     int l = strlen(k); n     for (int i = 0; i < l; i++) { n       m1 = ((long long)m1 * 10 + (k[i] ^ 48)) % mod; n       m2 = ((long long)m2 * 10 + (k[i] ^ 48)) % (mod - 1); n     } n     for (int i = 0; i < min(6, l); i++) m3 = m3 * 10 + (k[i] ^ 48); n     if (a[0] == 0 && m3 >= len) { n       for (int i = 0; i < len; i++) b[i] = 0; n       return; n     } n   } n   static int x[N], c[N]; n   long long t = 0; n   while (!a[t]) t++; n   for (int i = 0; i < len; i++) x[i] = a[i + t]; n   t = t * m1; n   const int res = qpow(x[0], m2), inv = qpow(x[0], mod - 2); n   for (int i = 0; i < len; i++) x[i] = (long long)x[i] * inv % mod; n   Ln(x, b, len); n   for (int i = 0; i < len; i++) b[i] = (long long)b[i] * m1 % mod; n   Exp(b, c, len); n   for (int i = 0; i < len; i++) c[i] = (long long)c[i] * res % mod; n   for (int i = 0; i < t; i++) b[i] = 0; n   for (long long i = t; i < len; i++) b[i] = c[i - t]; n } n int fac[N], ifac[N]; n void init(int n) { n   fac[0] = 1; n   for (int i = 1; i <= n; i++) fac[i] = (long long)fac[i - 1] * i % mod; n   ifac[n] = qpow(fac[n], mod - 2); n   for (int i = n; i; i--) ifac[i - 1] = (long long)ifac[i] * i % mod; n } n int n, m, t1[N], t2[N], S[N]; n int H[N], H1[N], H2[N], inv[N]; n int ans[N]; n int main() { n   n = read(), m = n + 2; n   init(n + 2); n   for (int i = 0; i < n + 1; i++) t1[i] = mod - ifac[i + 2]; n   Inv(t1, S, n + 1); n   for (int i = 0; i < n; i++) S[i] = S[i + 1]; n   memset(t1, 0, sizeof(t1)); n   t1[0] = t1[1] = 1; n   Ln(t1, t2, m + 2); n   for (int i = 0; i < m + 1; i++) t1[i] = t2[i + 1]; n   Inv(t1, H, m + 1); n   Power(H, H1, m + 1,   , n + 1); n   Der(H, t1, m + 1); n   Mul(t1, H1, H2, m + 1, m + 1); n   for (int i = 0; i < m; i++) t1[i] = mod - H[i + 1]; n   Inv(t1, inv, m); n   Mul(H1, inv, H1, m, m), Mul(H2, inv, H2, m, m), Mul(H2, inv, H2, m + 1, m); n   int invn = qpow(n + 1, mod - 2); n   for (int k = 0; k < n; k++) { n     int m = n - k + 1; n     reduce(S[k] -= n            ((long long)H1[n - m + 2] * m + H2[n - m + 2]) % mod * invn % mod); n   } n   S[0]--; n   memset(t1, 0, sizeof(t1)), memset(t2, 0, sizeof(t2)); n   for (int i = 0; i < n; i++) n     if (i & 1) n       t1[n - i - 1] = mod - ifac[i]; n     else n       t1[n - i - 1] = ifac[i]; n   for (int i = 0; i < n; i++) t2[i] = (long long)S[i] * fac[i] % mod; n   Mul(t1, t2, ans, n, n); n   for (int i = 0; i < n; i++) n     print((long long)ans[i + n - 1] * ifac[i] % mod * fac[n] % mod), n         putchar(   ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline void pisz(int n) { printf( %d n , n); } n template <typename T, typename TT> n ostream &operator<<(ostream &s, pair<T, TT> t) { n   return s <<  (  << t.first <<  ,  << t.second <<  ) ; n } n template <typename T> n ostream &operator<<(ostream &s, vector<T> t) { n   for (int(i) = 0; (i) < (((int)((t).size()))); ++(i)) s << t[i] <<    ; n   return s; n } n namespace karkkainen { n inline bool leq(int a1, int a2, int b1, int b2) { n   return (a1 < b1 || (a1 == b1 && a2 <= b2)); n } n inline bool leq(int a1, int a2, int a3, int b1, int b2, int b3) { n   return (a1 < b1 || (a1 == b1 && leq(a2, a3, b2, b3))); n } n static void radixPass(int *a, int *b, int *r, int n, int K) { n   vector<int> c(K + 1, 0); n   for (int(i) = 0; (i) < (n); ++(i)) c[r[a[i]]]++; n   int sum = 0; n   for (int(i) = (0); (i) <= (K); ++i) { n     int t = c[i]; n     c[i] = sum; n     sum += t; n   } n   for (int(i) = 0; (i) < (n); ++(i)) b[c[r[a[i]]]++] = a[i]; n } n void suffixArray(int *s, int *SA, int n, int K) { n   int n0 = (n + 2) / 3, n1 = (n + 1) / 3, n2 = n / 3, n02 = n0 + n2; n   int *s12 = new int[n02 + 3]; n   s12[n02] = s12[n02 + 1] = s12[n02 + 2] = 0; n   int *SA12 = new int[n02 + 3]; n   SA12[n02] = SA12[n02 + 1] = SA12[n02 + 2] = 0; n   int *s0 = new int[n0]; n   int *SA0 = new int[n0]; n   for (int i = 0, j = 0; i < n + (n0 - n1); i++) n     if (i % 3 != 0) s12[j++] = i; n   radixPass(s12, SA12, s + 2, n02, K); n   radixPass(SA12, s12, s + 1, n02, K); n   radixPass(s12, SA12, s, n02, K); n   int name = 0, c0 = -1, c1 = -1, c2 = -1; n   for (int(i) = 0; (i) < (n02); ++(i)) { n     if (s[SA12[i]] != c0 || s[SA12[i] + 1] != c1 || s[SA12[i] + 2] != c2) { n       name++; n       c0 = s[SA12[i]]; n       c1 = s[SA12[i] + 1]; n       c2 = s[SA12[i] + 2]; n     } n     if (SA12[i] % 3 == 1) { n       s12[SA12[i] / 3] = name; n     } else { n       s12[SA12[i] / 3 + n0] = name; n     } n   } n   if (name < n02) { n     suffixArray(s12, SA12, n02, name); n     for (int(i) = 0; (i) < (n02); ++(i)) s12[SA12[i]] = i + 1; n   } else { n     for (int(i) = 0; (i) < (n02); ++(i)) SA12[s12[i] - 1] = i; n   } n   for (int i = 0, j = 0; i < n02; ++i) n     if (SA12[i] < n0) s0[j++] = 3 * SA12[i]; n   radixPass(s0, SA0, s, n0, K); n   int p = 0, t = n0 - n1; n   for (int(k) = 0; (k) < (n); ++(k)) { n     int i = (SA12[t] < n0 ? SA12[t] * 3 + 1 : (SA12[t] - n0) * 3 + 2); n     int j = SA0[p]; n     if (SA12[t] < n0 ? leq(s[i], s12[SA12[t] + n0], s[j], s12[j / 3]) n                      : leq(s[i], s[i + 1], s12[SA12[t] - n0 + 1], s[j], n                            s[j + 1], s12[j / 3 + n0])) { n       SA[k] = i; n       t++; n       if (t == n02) { n         for (k++; p < n0; p++, k++) SA[k] = SA0[p]; n       } n     } else { n       SA[k] = j; n       p++; n       if (p == n0) { n         for (k++; t < n02; t++, k++) n           SA[k] = (SA12[t] < n0 ? SA12[t] * 3 + 1 : (SA12[t] - n0) * 3 + 2); n       } n     } n   } n   delete[] s12; n   delete[] SA12; n   delete[] SA0; n   delete[] s0; n } n };  // namespace karkkainen n struct SuffixArray { n   int *sa, *lcp, *revsa; n   SuffixArray(int *arr, bool with_lcp, int n) { n     if (n <= 1) { n       sa = new int[5]; n       sa[0] = 0; n     } else { n       sa = new int[n + 3]; n       arr[n] = arr[n + 1] = arr[n + 2] = 0; n       karkkainen::suffixArray(arr, sa, n, *max_element(arr, arr + n)); n     } n     if (with_lcp) { n       lcp = new int[n + 3]; n       vector<int> rank(n + 3); n       for (int(i) = 0; (i) < (n); ++(i)) rank[sa[i]] = i; n       for (int i = 0, k = 0; i < n; i++) { n         if (k > 0) k--; n         if (rank[i] == n - 1) { n           lcp[n - 1] = -1; n           k = 0; n           continue; n         } n         int j = sa[rank[i] + 1]; n         while (arr[i + k] == arr[j + k]) k++; n         lcp[rank[i]] = k; n       } n     } else { n       lcp = NULL; n     } n     revsa = new int[n + 3]; n     for (int(i) = 0; (i) < (n); ++(i)) revsa[sa[i]] = i; n   } n   ~SuffixArray() { n     delete[] sa; n     if (lcp != NULL) delete[] lcp; n   } n }; n template <typename T, typename Aug> n struct AugTreap { n   struct Node { n     T v; n     int pr; n     Node *le, *ri; n     Aug al, ag; n   }; n   Node *root; n   AugTreap() : root(0) {} n   inline static void recalc(Node *&n) { n     Aug left = n->le ? n->le->ag + n->al : n->al; n     n->ag = n->ri ? left + n->ri->ag : left; n   } n   inline void rotle(Node *&n) { n     Node *syn = n->le; n     n->le = syn->ri; n     syn->ri = n; n     n = syn; n     recalc(n->ri); n     recalc(n); n   } n   inline void rotri(Node *&n) { n     Node *syn = n->ri; n     n->ri = syn->le; n     syn->le = n; n     n = syn; n     recalc(n->le); n     recalc(n); n   } n   void insert_aux(Node *&n, const T &x, const Aug &aug) { n     if (!n) { n       n = new Node; n       n->v = x; n       n->pr = rand(); n       n->le = n->ri = 0; n       n->al = n->ag = aug; n     } else if (x < n->v) { n       insert_aux(n->le, x, aug); n       if (n->pr > n->le->pr) n         rotle(n); n       else n         recalc(n); n     } else if (x > n->v) { n       insert_aux(n->ri, x, aug); n       if (n->pr > n->ri->pr) n         rotri(n); n       else n         recalc(n); n     } else { n       n->al = n->al + aug; n       recalc(n); n     } n   } n   void insert(const T &x, const Aug &aug) { insert_aux(root, x, aug); } n   Aug sumgeq_aux(const T &x, Node *n) { n     if (!n) return Aug(); n     if (x > n->v) return sumgeq_aux(x, n->ri); n     if (x < n->v) { n       Aug left = sumgeq_aux(x, n->le) + n->al; n       return n->ri ? left + n->ri->ag : left; n     } n     return n->ri ? n->al + n->ri->ag : n->al; n   } n   Aug sumgeq(const T &x) { return sumgeq_aux(x, root); } n   Aug sumleq_aux(const T &x, Node *n) { n     if (!n) return Aug(); n     if (x < n->v) return sumleq_aux(x, n->le); n     if (x > n->v) { n       Aug right = n->al + sumleq_aux(x, n->ri); n       return n->le ? n->le->ag + right : right; n     } n     return n->le ? n->le->ag + n->al : n->al; n   } n   Aug sumleq(const T &x) { return sumleq_aux(x, root); } n   Aug sumbetween_aux(const T &x, const T &y, Node *n) { n     if (!n) return Aug(); n     if (y < n->v) return sumbetween_aux(x, y, n->le); n     if (x > n->v) return sumbetween_aux(x, y, n->ri); n     return sumgeq_aux(x, n->le) + n->al + sumleq_aux(y, n->ri); n   } n   Aug sumbetween(const T &x, const T &y) { return sumbetween_aux(x, y, root); } n   struct None {}; n   T minsubtreequery(Node *n, Aug sum) const { n     if (n->le) { n       Aug sum2 = sum + n->le->ag; n       if (enough(sum2)) { n         return minsubtreequery(n->le, sum); n       } n       sum = sum2; n     } n     sum = sum + n->al; n     if (enough(sum)) return n->v; n     return minsubtreequery(n->ri, sum); n   } n   T minquery(const T &s) const { n     vector<Node *> roots; n     Node *n = root; n     while (n) { n       if (n->v < s) { n         n = n->ri; n       } else if (n->v > s) { n         roots.push_back(n); n         n = n->le; n       } else { n         roots.push_back(n); n         break; n       } n     } n     Aug sum; n     for (int(i) = (((int)((roots).size())) - 1); (i) >= (0); --i) { n       sum = sum + roots[i]->al; n       if (enough(sum)) { n         return roots[i]->v; n       } n       if (roots[i]->ri) { n         Aug sum2 = sum + roots[i]->ri->ag; n         if (enough(sum2)) { n           return minsubtreequery(roots[i]->ri, sum); n         } n         sum = sum2; n       } n     } n     throw None(); n   } n   T revminsubtreequery(Node *n, Aug sum) const { n     if (n->ri) { n       Aug sum2 = n->ri->ag + sum; n       if (enough(sum2)) { n         return revminsubtreequery(n->ri, sum); n       } n       sum = sum2; n     } n     sum = n->al + sum; n     if (enough(sum)) return n->v; n     return revminsubtreequery(n->le, sum); n   } n   T revminquery(const T &s) const { n     vector<Node *> roots; n     Node *n = root; n     while (n) { n       if (n->v > s) { n         n = n->le; n       } else if (n->v < s) { n         roots.push_back(n); n         n = n->ri; n       } else { n         roots.push_back(n); n         break; n       } n     } n     Aug sum; n     for (int(i) = (((int)((roots).size())) - 1); (i) >= (0); --i) { n       sum = roots[i]->al + sum; n       if (enough(sum)) { n         return roots[i]->v; n       } n       if (roots[i]->le) { n         Aug sum2 = roots[i]->le->ag + sum; n         if (enough(sum2)) { n           return revminsubtreequery(roots[i]->le, sum); n         } n         sum = sum2; n       } n     } n     throw None(); n   } n }; n struct IntMin { n   int x; n   IntMin(int y = 1001001001) : x(y) {} n   inline IntMin operator+(const IntMin &s) const { return IntMin(min(x, s.x)); } n   operator int() const { return x; } n }; n struct tree { n   int sz; n   vector<vector<int> > V; n   tree(vector<int> val) { n     int n = ((int)((val).size())); n     for (sz = 1; sz < n; sz *= 2) n       ; n     V.assign(2 * sz, vector<int>()); n     for (int(i) = 0; (i) < (n); ++(i)) V[sz + i].push_back(val[i]); n     for (int(i) = (sz - 1); (i) >= (1); --i) { n       V[i].resize(((int)((V[2 * i]).size())) + ((int)((V[2 * i + 1]).size()))); n       merge(V[2 * i].begin(), V[2 * i].end(), V[2 * i + 1].begin(), n             V[2 * i + 1].end(), V[i].begin()); n     } n   } n   int query(int b, int e, int x) { return get(sz + b, sz + e + 1, x); } n   int ile(int v, int x) { n     return upper_bound(V[v].begin(), V[v].end(), x) - V[v].begin(); n   } n   int get(int p, int q, int x) { n     if (p + 1 == q) return ile(p, x); n     if (p & 1) return ile(p, x) + get(p + 1, q, x); n     if (q & 1) return ile(q - 1, x) + get(p, q - 1, x); n     return get(p / 2, q / 2, x); n   } n }; n int inp[200009]; n int word[200009]; n int ans[200009]; n int newword[200009]; n int prog; n bool enough(const IntMin &s) { return s.x < prog; } n int main() { n   int(n); n   scanf( %d , &(n)); n   for (int(i) = 0; (i) < (n); ++(i)) { n     scanf( %d , inp + i); n   } n   for (int(i) = 0; (i) < (n - 1); ++(i)) { n     word[i] = inp[i + 1] - inp[i]; n   } n   word[n - 1] = INT_MAX; n   for (int(i) = 0; (i) < (n - 1); ++(i)) { n     word[n + i] = -word[i]; n   } n   int len = 2 * n - 1; n   map<int, int> mapa; n   int now = 1; n   for (int(i) = 0; (i) < (len); ++(i)) mapa[word[i]] = now++; n   for (int(i) = 0; (i) < (len); ++(i)) newword[i] = mapa[word[i]]; n   SuffixArray sa(newword, 1, len); n   AugTreap<int, IntMin> lcpTreap; n   for (int(i) = 0; (i) < (len - 1); ++(i)) lcpTreap.insert(i, sa.lcp[i]); n   lcpTreap.insert(-1, 0); n   lcpTreap.insert(len - 1, 0); n   vector<int> vec(len, 1001001001); n   for (int(i) = 0; (i) < (len); ++(i)) vec[sa.revsa[i]] = i; n   tree polpr(vec); n   int(queries); n   scanf( %d , &(queries)); n   for (int(query) = 0; (query) < (queries); ++(query)) { n     int(l), (r); n     scanf( %d %d , &(l), &(r)); n     --l; n     --r; n     if (l == r) { n       ans[query] = n - 1; n     } else { n       int indexInSa = sa.revsa[n + l]; n       prog = r - l; n       int a = lcpTreap.revminquery(indexInSa - 1) + 1; n       int b = lcpTreap.minquery(indexInSa); n       ans[query] = 0; n       if (r + 1 <= n - 2) { n         ans[query] += polpr.query(a, b, n - 2) - polpr.query(a, b, r); n       } n       if (0 <= l - (r - l + 1)) { n         ans[query] += polpr.query(a, b, l - (r - l + 1)); n       } n     } n   } n   for (int(query) = 0; (query) < (queries); ++(query)) pisz(ans[query]); n } n


#include <bits/stdc++.h> n using namespace std; n map<pair<int, int>, int> mp; n vector<int> res, low, b; n int ask(int l, int r) { n   if (l == r) return -1; n   if (l > r) swap(l, r); n   if ((res[l] | res[r]) == (low[l] | low[r])) return res[l] | res[r]; n   auto it = mp.find(make_pair(l, r)); n   if (it != mp.end()) return it->second; n   printf( ? %d %d n , l, r); n   fflush(stdout); n   int x; n   scanf( %d , &x); n   mp[make_pair(l, r)] = x; n   res[l] &= x; n   res[r] &= x; n   for (auto p : mp) { n     low[p.first.first] |= p.second ^ res[p.first.second]; n     low[p.first.second] |= p.second ^ res[p.first.first]; n   } n   return x; n } n int n; n void answer() { n   printf( ! ); n   for (int i = 1; i <= n; ++i) { n     printf(  %d , res[i]); n   } n   printf(  n ); n   fflush(stdout); n   exit(0); n } n int main() { n   scanf( %d , &n); n   int full = (1 << 18) - 1; n   res.assign(n + 1, full); n   low.assign(n + 1, 0); n   int cnt = 4269 - n * 2; n   srand(time(0)); n   int p = -1, q = -1; n   while (cnt-- > 0) { n     int x = (rand() % n) + 1; n     int y = (rand() % n) + 1; n     while (x == y) { n       y = (rand() % n) + 1; n     } n     ask(x, y); n     bool found = false; n     for (int i = 1; i <= n; ++i) { n       for (int j = i + 1; j <= n; ++j) { n         if (res[i] & res[j]) continue; n         p = i; n         q = j; n         found = true; n       } n     } n     if (found) break; n   } n   if (p != -1 && q != -1) { n     for (int i = 1; i <= n; ++i) { n       ask(i, p); n       ask(i, q); n     } n     answer(); n   } n   int zero = -1; n   while (true) { n     vector<int> cand; n     for (int i = 1; i <= n; ++i) { n       if (low[i]) continue; n       cand.emplace_back(i); n     } n     sort(cand.begin(), cand.end(), [](int l, int r) { n       return __builtin_popcount(res[l]) < __builtin_popcount(res[r]); n     }); n     for (int x : cand) { n       ask(x, cand[0]); n     } n     zero = -1; n     for (int x : cand) { n       if (res[x] == 0) { n         zero = x; n         break; n       } n     } n     if (zero != -1) break; n   } n   for (int i = 1; i <= n; ++i) { n     ask(zero, i); n   } n   answer(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int32_t main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   long long n, k; n   cin >> n >> k; n   if (k < (n * n + n) / 2) return cout << -1, 0; n   long long t = k; n   k -= (n * n + n) / 2; n   long long a[n + 1]; n   for (long long i = 1; i <= n; i++) a[i] = i; n   for (long long i = 1; i <= n / 2; i++) { n     if (k - (n + 1 - 2 * i) > 0) { n       swap(a[i], a[n - i + 1]); n       k -= (n + 1 - 2 * i); n     } else { n       swap(a[i], a[i + k]); n       cout << t << endl; n       for (long long i = 1; i <= n; i++) cout << i <<    ; n       cout << endl; n       for (long long i = 1; i <= n; i++) cout << a[i] <<    ; n       return 0; n     } n   } n   cout << t - k << endl; n   for (long long i = 1; i <= n; i++) cout << i <<    ; n   cout << endl; n   for (long long i = 1; i <= n; i++) cout << a[i] <<    ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long mod = 1000000007; n string s; n long long dp[1000001][7]; n long long f(int idx, int la = 6) { n   if (idx == s.size()) { n     if (la == 2) return 0; n     if (la == 1) return 0; n     return 1; n   } n   if (dp[idx][la] != -1) return dp[idx][la]; n   long long res = 0; n   if (s[idx] !=  ? ) { n     char c = s[idx]; n     if (la == 0) { n       if (c ==  0 ) n         res = f(idx + 1, 0); n       else if (c ==  1 ) n         res = f(idx + 1, 1); n     } else if (la == 1) { n       if (c ==  * ) res = f(idx + 1, 4); n     } else if (la == 2) { n       if (c ==  * ) res = f(idx + 1, 4); n     } else if (la == 3) { n       if (c ==  0 ) n         res = f(idx + 1, 0); n       else if (c ==  1 ) n         res = f(idx + 1, 1); n     } else if (la == 4) { n       if (c ==  2 ) n         res = f(idx + 1, 2); n       else if (c ==  1 ) n         res = f(idx + 1, 3); n       else if (c ==  * ) n         res = f(idx + 1, 4); n     } else { n       if (c ==  1 ) res = f(idx + 1, 1); n       if (c ==  0 ) res = f(idx + 1, 0); n       if (c ==  * ) res = f(idx + 1, 4); n     } n   } else if (la == 0) { n     res += f(idx + 1, 0); n     res %= mod; n     res += f(idx + 1, 1); n     res %= mod; n   } else if (la == 1 || la == 2) { n     res = f(idx + 1, 4); n   } else if (la == 3) { n     res += f(idx + 1, 0); n     res %= mod; n     res += f(idx + 1, 1); n     res %= mod; n   } else if (la == 4) { n     res = f(idx + 1, 2); n     res %= mod; n     res += f(idx + 1, 3); n     res %= mod; n     res += f(idx + 1, 4); n     res %= mod; n   } else { n     res += f(idx + 1, 0); n     res %= mod; n     res += f(idx + 1, 1); n     res %= mod; n     res += f(idx + 1, 4); n     res %= mod; n   } n   return dp[idx][la] = res; n } n int main() { n   memset(dp, -1, sizeof dp); n   ios::sync_with_stdio(false); n   cin >> s; n   cout << f(0); n } n


#include <bits/stdc++.h> n using namespace std; n int n, s, T, ans; n int ar[101]; n bool ok[301]; n int dp[301][301]; n int res[301][301]; n int tmp[301][301]; n int ways[24][301][301]; n vector<int> v; n int main() { n   scanf( %d%d , &n, &T); n   for (int i = 1; i <= n; i++) { n     scanf( %d , &ar[i]); n     ok[ar[i]] = true; n   } n   for (int i = 1; i < 301; i++) n     if (ok[i]) v.push_back(i); n   s = v.size(); n   for (int h = 0; h < s; h++) { n     int head = v[h]; n     dp[head][head] = 1; n     for (int i = 1; i <= n; i++) { n       int mx = dp[head][ar[i]]; n       for (int j = 1; j <= ar[i]; j++) n         if (dp[head][j]) mx = max(mx, dp[head][j] + 1); n       dp[head][ar[i]] = mx; n     } n   } n   for (int i = 1; i < 301; i++) n     for (int j = 1; j < 301; j++) ways[0][i][j] = max(dp[i][j] - 1, 0); n   for (int kd = 1; (1 << kd) <= T; kd++) n     for (int i = 0; i < s; i++) n       for (int j = i; j < s; j++) n         for (int k = i; k <= j; k++) { n           int vi = v[i]; n           int vj = v[j]; n           int vk = v[k]; n           ways[kd][vi][vj] = max(ways[kd][vi][vj], n                                  ways[kd - 1][vi][vk] + ways[kd - 1][vk][vj]); n         } n   for (int kd = 0; (1 << kd) <= T; kd++) n     if (T & (1 << kd)) { n       memset(tmp, 0, sizeof(tmp)); n       for (int i = 0; i < s; i++) n         for (int j = i; j < s; j++) n           for (int k = i; k <= j; k++) { n             int vi = v[i]; n             int vj = v[j]; n             int vk = v[k]; n             tmp[vi][vj] = max(tmp[vi][vj], res[vi][vk] + ways[kd][vk][vj]); n           } n       for (int i = 0; i < s; i++) n         for (int j = 0; j < s; j++) res[v[i]][v[j]] = tmp[v[i]][v[j]]; n     } n   for (int i = 0; i < s; i++) n     for (int j = 0; j < s; j++) ans = max(ans, res[v[i]][v[j]]); n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n int main(void) { n   char s[1001]; n   scanf( %s , s); n   if (s[0] > 64 && s[0] < 91) n     printf( %s , s); n   else { n     s[0] -= 32; n     for (int i = 0; i < strlen(s); i++) printf( %c , s[i]); n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long n, h; n bool ok(long long x) { n   long long ans = 0; n   if (x >= 2e9) return 1; n   if (x <= h) n     ans = x * (x + 1) / 2; n   else { n     ans = h * (h + 1) / 2 + (x - h) * h; n     long long high = x - h - 1; n     long long t1 = high / 2, t2 = high - t1; n     ans += t1 * (t1 + 1) / 2 + t2 * (t2 + 1) / 2; n   } n   if (ans >= n) n     return 1; n   else n     return 0; n } n int main() { n   cin >> n >> h; n   long long l = 1, r = 1e18 + 1; n   long long mid = (l + r) / 2; n   while (l < r) { n     mid = (l + r) / 2; n     if (ok(mid)) n       r = mid; n     else n       l = mid + 1; n   } n   printf( %lld n , l); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long double mm = 0; n int xs[4]; n int ys[4]; n int mxs[4]; n int mys[4]; n int used[1001][1001]; n long double di(int x1, int y1, int x2, int y2) { n   return sqrt(abs((long double)x1 - (long double)x2) * n                   abs((long double)x1 - (long double)x2) + n               abs((long double)y1 - (long double)y2) * n                   abs((long double)y1 - (long double)y2)); n } n int n, m; n void dfs(int x, int y, int d, long double ma) { n   if (x < 0 || y < 0) return; n   if (x > n || y > m) return; n   if (used[x][y]) return; n   used[x][y] = 1; n   xs[d] = x; n   ys[d] = y; n   if (d == 3) { n     if (ma > mm) { n       mm = ma; n       for (int i = 0; i < 4; i++) { n         mxs[i] = xs[i]; n         mys[i] = ys[i]; n       } n     } n     used[x][y] = 0; n     return; n   } n   for (int i = 0; i < 4; i++) { n     for (int ii = 0; ii < 4; ii++) { n       dfs(i, ii, d + 1, ma + di(x, y, i, ii)); n     } n   } n   for (int i = 0; i < 4; i++) { n     for (int ii = 0; ii < 4; ii++) { n       dfs(n - i, m - ii, d + 1, ma + di(x, y, n - i, m - ii)); n     } n   } n   used[x][y] = 0; n } n int main() { n   cin >> n >> m; n   for (int i = 0; i < 4; i++) { n     for (int ii = 0; ii < 4; ii++) { n       dfs(i, ii, 0, 0); n     } n   } n   for (int i = 0; i < 4; i++) { n     cout << mxs[i] <<     << mys[i] << endl; n   } n } n