#include <bits/stdc++.h> n using namespace std; n const int MAXN = 1005; n template <typename T> n void chkmax(T &x, T y) { n   x = max(x, y); n } n template <typename T> n void chkmin(T &x, T y) { n   x = min(x, y); n } n template <typename T> n void read(T &x) { n   x = 0; n   int f = 1; n   char c = getchar(); n   for (; !isdigit(c); c = getchar()) n     if (c ==  - ) f = -f; n   for (; isdigit(c); c = getchar()) x = x * 10 + c -  0 ; n   x *= f; n } n int n, a[MAXN]; n int main() { n   read(n); n   vector<pair<int, int>> ans; n   for (int i = 1; i <= n; i++) read(a[i]); n   for (int i = 1; i <= n; i++) { n     vector<int> p; n     for (int j = i + 1; j <= n; j++) n       if (a[j] < a[i]) p.push_back(j); n     sort(p.begin(), p.end(), [&](int x, int y) { n       if (a[x] != a[y]) n         return a[x] > a[y]; n       else n         return x > y; n     }); n     for (auto x : p) ans.emplace_back(i, x); n   } n   cout << ans.size() << endl; n   for (auto x : ans) printf( %d %d n , x.first, x.second); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct edge { n   long long to, cost; n   edge() {} n   edge(long long a, long long b) { to = a, cost = b; } n }; n const long long dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1}; n const long long mod = 1000000007; n struct mint { n   long long x = 0; n   mint(long long y = 0) { n     x = y; n     if (x < 0 || x >= mod) x = (x % mod + mod) % mod; n   } n   mint(const mint& ope) { x = ope.x; } n   mint operator-() { return mint(-x); } n   mint operator+(const mint& ope) { return mint(x) += ope; } n   mint operator-(const mint& ope) { return mint(x) -= ope; } n   mint operator*(const mint& ope) { return mint(x) *= ope; } n   mint operator/(const mint& ope) { return mint(x) /= ope; } n   mint& operator+=(const mint& ope) { n     x += ope.x; n     if (x >= mod) x -= mod; n     return *this; n   } n   mint& operator-=(const mint& ope) { n     x += mod - ope.x; n     if (x >= mod) x -= mod; n     return *this; n   } n   mint& operator*=(const mint& ope) { n     x *= ope.x, x %= mod; n     return *this; n   } n   mint& operator/=(const mint& ope) { n     long long n = mod - 2; n     mint mul = ope; n     while (n) { n       if (n & 1) *this *= mul; n       mul *= mul; n       n >>= 1; n     } n     return *this; n   } n   mint inverse() { return mint(1) / *this; } n   bool operator==(const mint& ope) { return x == ope.x; } n   bool operator!=(const mint& ope) { return x != ope.x; } n }; n mint modpow(mint a, long long n) { n   if (n == 0) return mint(1); n   if (n % 2) n     return a * modpow(a, n - 1); n   else n     return modpow(a * a, n / 2); n } n istream& operator>>(istream& is, mint& ope) { n   long long t; n   is >> t, ope.x = t; n   return is; n } n ostream& operator<<(ostream& os, mint& ope) { return os << ope.x; } n ostream& operator<<(ostream& os, const mint& ope) { return os << ope.x; } n bool exceed(long long x, long long y, long long m) { return x >= m / y + 1; } n void mark() { cout <<  *  << endl; } n void yes() { cout <<  YES  << endl; } n void no() { cout <<  NO  << endl; } 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 digitnum(long long x, long long b = 10) { n   long long ret = 0; n   for (; x; x /= b) ret++; n   return ret; n } n long long digitsum(long long x, long long b = 10) { n   long long ret = 0; n   for (; x; x /= b) ret += x % b; n   return ret; n } n string lltos(long long x) { n   string ret; n   for (; x; x /= 10) ret += x % 10 +  0 ; n   reverse(ret.begin(), ret.end()); n   return ret; n } n long long stoll(string& s) { n   long long ret = 0; n   for (auto c : s) ret *= 10, ret += c -  0 ; n   return ret; n } n template <typename T> n void uniq(T& vec) { n   sort(vec.begin(), vec.end()); n   vec.erase(unique(vec.begin(), vec.end()), vec.end()); n } n template <typename T> n ostream& operator<<(ostream& os, vector<T>& vec) { n   for (int i = 0; i < vec.size(); i++) n     os << vec[i] << (i + 1 == vec.size() ?    :    ); n   return os; n } n template <typename T> n ostream& operator<<(ostream& os, deque<T>& deq) { n   for (int i = 0; i < deq.size(); i++) n     os << deq[i] << (i + 1 == deq.size() ?    :    ); n   return os; n } n template <typename T, typename U> n ostream& operator<<(ostream& os, pair<T, U>& pair_var) { n   os <<  (  << pair_var.first <<  ,   << pair_var.second <<  ) ; n   return os; n } n template <typename T, typename U> n ostream& operator<<(ostream& os, const pair<T, U>& pair_var) { n   os <<  (  << pair_var.first <<  ,   << pair_var.second <<  ) ; n   return os; n } n template <typename T, typename U> n ostream& operator<<(ostream& os, map<T, U>& map_var) { n   for (typename map<T, U>::iterator itr = map_var.begin(); itr != map_var.end(); n        itr++) { n     os <<  (  << itr->first <<  ,   << itr->second <<  ) ; n     itr++; n     if (itr != map_var.end()) os <<  , ; n     itr--; n   } n   return os; n } n template <typename T> n ostream& operator<<(ostream& os, set<T>& set_var) { n   for (typename set<T>::iterator itr = set_var.begin(); itr != set_var.end(); n        itr++) { n     os << *itr; n     ++itr; n     if (itr != set_var.end()) os <<    ; n     itr--; n   } n   return os; n } n template <typename T> n ostream& operator<<(ostream& os, multiset<T>& set_var) { n   for (typename multiset<T>::iterator itr = set_var.begin(); n        itr != set_var.end(); itr++) { n     os << *itr; n     ++itr; n     if (itr != set_var.end()) os <<    ; n     itr--; n   } n   return os; n } n template <typename T> n void outa(T a[], long long s, long long t) { n   for (long long i = s; i <= t; i++) { n     cout << a[i]; n     if (i < t) cout <<    ; n   } n   cout << endl; n } n void dump_func() { cout << endl; } n template <class Head, class... Tail> n void dump_func(Head&& head, Tail&&... tail) { n   cout << head; n   if (sizeof...(Tail) > 0) cout <<    ; n   dump_func(std::move(tail)...); n } n void z_algorithm(string& s, int z[]) { n   z[0] = s.size(); n   int x = 0, y = 0; n   for (int i = 1; i < s.size(); i++) { n     if (i > y) { n       z[i] = 0; n       for (int j = 0; j < s.size(); j++) { n         if (i + j >= s.size() || s[i + j] != s[j]) break; n         z[i]++; n       } n       x = i, y = i + z[i] - 1; n     } else if (i + z[i - x] <= y) n       z[i] = z[i - x]; n     else { n       z[i] = y - i + 1; n       for (int j = y - i + 1; j < s.size(); j++) { n         if (i + j >= s.size() || s[i + j] != s[j]) break; n         z[i]++; n       } n       x = i, y = i + z[i] - 1; n     } n   } n } n struct SCC { n   int n; n   vector<vector<int> > G, revG, compG; n   vector<int> used, scc, topo; n   int sccid, sccnum; n   void tpdfs(int v) { n     used[v] = 1; n     for (int i = 0; i < G[v].size(); i++) { n       if (!used[G[v][i]]) tpdfs(G[v][i]); n     } n     topo.push_back(v); n   } n   void sccdfs(int v, int id) { n     used[v] = 1; n     scc[v] = id; n     for (int i = 0; i < revG[v].size(); i++) { n       if (!used[revG[v][i]]) sccdfs(revG[v][i], id); n     } n   } n   SCC() {} n   SCC(int n) { n     this->n = n; n     G.resize(n + 1); n     revG.resize(n + 1); n     used.resize(n + 1); n   } n   void init() { n     for (int i = 1; i <= n; i++) { n       G[i].clear(), revG[i].clear(); n       used[i] = 0; n     } n     topo.clear(); n   } n   void add_edge(int u, int v) { G[u].push_back(v); } n   void tpsort() { n     topo.clear(); n     for (int i = 1; i <= n; i++) used[i] = 0; n     for (int i = 1; i <= n; i++) n       if (!used[i]) tpdfs(i); n     reverse(topo.begin(), topo.end()); n   } n   bool checkDAG() { n     for (int i = 1; i <= n; i++) used[i] = 0; n     for (int i = 0; i < topo.size(); i++) { n       int v = topo[i]; n       used[v] = 1; n       for (int j = 0; j < G[v].size(); j++) { n         if (used[G[v][j]]) return false; n       } n     } n     return true; n   } n   int calcSCC() { n     scc.resize(n + 1); n     for (int i = 1; i <= n; i++) revG[i].clear(); n     for (int i = 1; i <= n; i++) { n       for (int j = 0; j < G[i].size(); j++) { n         revG[G[i][j]].push_back(i); n       } n     } n     sccid = 1; n     for (int i = 1; i <= n; i++) used[i] = 0; n     for (int i = 0; i < topo.size(); i++) n       if (!used[topo[i]]) sccdfs(topo[i], sccid++); n     return sccnum = sccid - 1; n   } n   void compressSCC(bool simple = false) { n     compG.resize(sccnum + 1); n     for (int i = 1; i <= n; i++) { n       for (int j = 0; j < G[i].size(); j++) { n         int u = G[i][j]; n         if (scc[i] != scc[u]) compG[scc[i]].push_back(scc[u]); n       } n     } n     if (simple) { n       for (int i = 1; i <= sccnum; i++) { n         sort(compG[i].begin(), compG[i].end()); n         compG[i].erase(unique(compG[i].begin(), compG[i].end()), n                        compG[i].end()); n       } n     } n   } n }; n long long n; n string s[35]; n pair<long long, long long> p[100005]; n map<pair<long long, long long>, long long> mp; n vector<pair<long long, long long> > vec[35]; n int z[200005]; n int main(void) { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cin >> n; n   for (long long(i) = (1); (i) <= (n); (i)++) cin >> s[i]; n   long long id = 0; n   for (long long(i) = (1); (i) <= (n); (i)++) { n     for (long long(j) = 0; (j) < (long long)(s[i]).size(); (j)++) n       id++, p[id] = pair<long long, long long>(i, j), mp[p[id]] = id; n   } n   long long S = id; n   for (long long(i) = (1); (i) <= (n); (i)++) n     vec[i].push_back( n         pair<long long, long long>(0, mp[pair<long long, long long>(i, 0)])); n   for (long long(i) = (1); (i) <= (n); (i)++) { n     for (long long(j) = (1); (j) <= (n); (j)++) { n       string str = s[j] +  #  + s[i]; n       z_algorithm(str, z); n       for (long long(k) = 0; (k) < (long long)(s[i]).size(); (k)++) { n         if (k == 0 && i == j) continue; n         long long I = ((long long)(s[i]).size()), n                   J = ((long long)(s[j]).size()), n                   v = mp[pair<long long, long long>(i, k)], nv; n         if (I - k < J) nv = mp[pair<long long, long long>(j, I - k)]; n         if (I - k == J) nv = 0; n         if (I - k > J) nv = mp[pair<long long, long long>(i, k + J)]; n         if (z[J + 1 + k] == min(I - k, J)) n           vec[j].push_back(pair<long long, long long>(v, nv)); n       } n     } n   } n   long long ans = 0; n   for (long long(i) = (1); (i) <= (n); (i)++) { n     SCC scc(S + 1); n     set<string> S; n     for (long long(j) = (i); (j) <= (n); (j)++) { n       if (S.count(s[j])) { n         ans++; n         continue; n       } n       S.insert(s[j]); n       for (auto p : vec[j]) scc.add_edge(p.first + 1, p.second + 1); n       scc.tpsort(); n       if (scc.checkDAG()) n         ans++; n       else n         break; n     } n   } n   dump_func(ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n using ull = unsigned long long; n using ld = long double; n using pii = pair<int, int>; n using pll = pair<ll, ll>; n using pci = pair<char, int>; n using vi = vector<int>; n using vll = vector<ll>; n using vpii = vector<pii>; n const ll infll = 1e18 + 3; n const int maxn = 1e6 + 77; n const int nmax = 1e6 + 577; n const ll basell = 1e18 + 3; n const int mod = 1e9 + 7; n const ld eps = 1e-7; n const int inf = 1009000999; n const int nv = 100505; n const int baseint = 1000200013; n const ld PI = acos(-1.0); n inline bool EQ(ld a, ld b) { return fabs(a - b) < 1e-9; } n inline bool IF(int a, int b, int c) { return (a >= b && a <= c); } n inline bool IFS(int a, int b, int c) { return (a > b && a < c); } n template <typename T> n inline istream &operator>>(istream &_in, vector<T> &_v) { n   for (auto &_i : _v) { n     _in >> _i; n   } n   return _in; n } n mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count()); n int p[nmax]; n int pref(string s) { n   int n = ((int)(s).size()); n   int h = 0; n   for (int i = 1; i < n; ++i) { n     int j = p[i - 1]; n     while (s[i] != s[j] && j > 0) { n       j = p[j - 1]; n     } n     if (s[i] == s[j]) { n       j++; n     } n     p[i] = j; n     h = max(h, j); n   } n   return h; n } n int inline solve() { n   ios::sync_with_stdio(NULL), cin.tie(NULL), cout.tie(NULL); n   ; n   string s, t; n   cin >> s >> t; n   if (((int)(s).size()) < ((int)(t).size())) { n     return cout << s, 0; n   } n   int s0 = 0, s1 = 0; n   for (char i : s) { n     if (i ==  1 ) { n       s1++; n     } else { n       s0++; n     } n   } n   int t0 = 0, t1 = 0; n   for (char i : t) { n     if (i ==  1 ) { n       t1++; n     } else { n       t0++; n     } n   } n   if (s0 < t0 || s1 < t1) { n     return cout << s, 0; n   } n   s0 -= t0; n   s1 -= t1; n   int m = ((int)(t).size()); n   int x = m - 1, y = 0; n   for (int i = 0; i < (m / 2) + (m % 2 == 1); ++i) { n     if (t[i] == t[x]) { n       x--; n       y = i + 1; n     } n   } n   y = pref(t); n   string a; n   int a0 = 0, a1 = 0; n   for (int i = p[m - 1]; i < m; ++i) { n     a += t[i]; n     if (t[i] ==  1 ) { n       a1++; n     } else { n       a0++; n     } n   } n   string str = t; n   int n = ((int)(s).size()); n   for (int i = 0; i < n; ++i) { n     if (s0 < a0 || s1 < a1) { n       break; n     } n     str += a; n     s0 -= a0; n     s1 -= a1; n   } n   for (int i = 0; i < s0; ++i) { n     str +=  0 ; n   } n   for (int i = 0; i < s1; ++i) { n     str +=  1 ; n   } n   cout << str; n   return 0; n } n int32_t main() { n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double PI = 3.14159265358979323846264338327950288419716939937510582; n int t; n int n; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   cin >> t; n   while (t--) { n     cin >> n; n     cout << fixed << setprecision(20) << cos(PI / (4 * n)) / sin(PI / (2 * n)) n          <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   int t; n   t = 1; n   while (t--) { n     long long n, a[8] = {0}, k; n     cin >> n; n     for (int i = 0; i <= n - 1; i++) { n       cin >> k; n       a[k]++; n     } n     if (a[5] > 0 || a[7] > 0 || a[1] != n / 3 || a[3] > a[6] || a[4] > a[2] || n         ((a[3] + a[2]) != n / 3) || ((a[4] + a[6]) != n / 3)) { n       cout << -1; n       return 0; n     } n     while (a[4]) { n       cout <<  1 2 4  n            <<   n ; n       a[4]--; n       a[2]--; n     } n     while (a[2]) { n       cout <<  1 2 6  n            <<   n ; n       a[2]--; n     } n     while (a[3]) { n       cout <<  1 3 6  <<   n ; n       a[3]--; n     } n   } n   cerr <<  Time taken :   << (float)clock() / CLOCKS_PER_SEC <<   secs  << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, k, p, a[10001], b[10001]; n bool judge(long long x) { n   long long j = 1; n   long long i; n   for (i = 1; i <= n; i++) { n     if (abs(a[i] - b[j]) + abs(p - b[j]) <= x) { n       j++; n       continue; n     } else n       j++, i--; n     if (j > k) return 0; n   } n   return 1; n } n int main() { n   scanf( %lld%lld%lld , &n, &k, &p); n   long long i; n   for (i = 1; i <= n; i++) scanf( %lld , &a[i]); n   sort(a + 1, a + n + 1); n   for (i = 1; i <= k; i++) scanf( %lld , &b[i]); n   sort(b + 1, b + k + 1); n   long long l = 0, r = 2e9 + 1; n   while (l < r) { n     long long mid = (l + r) >> 1; n     if (judge(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 vector<long long> ans; n long long gcd(long long x, long long y) { n   while (true) { n     if (x == y) return x; n     if (x < y) { n       long long k = (y - 1) / x; n       ans.push_back(-k); n       y -= k * x; n     } else { n       long long k = (x - 1) / y; n       ans.push_back(k); n       x -= k * y; n     } n   } n } n int main() { n   long long x, y; n   cin >> x >> y; n   if (gcd(x, y) != 1) { n     puts( Impossible ); n     return 0; n   } n   for (int i = 0; i < ans.size(); i++) { n     printf( %I64d%c , abs(ans[i]), ans[i] > 0 ?  A  :  B ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   FILE *inF, *outF; n   inF = fopen( in ,  r ); n   outF = fopen( out ,  w ); n   inF = stdin; n   outF = stdout; n   int t; n   fscanf(inF,  %d , &t); n   while (t--) { n     int n; n     long long k; n     fscanf(inF,  %d %lld , &n, &k); n     int m = -1e9 - 1; n     int arr[200000]; n     for (int i = 0; i < n; i++) { n       fscanf(inF,  %d , &arr[i]); n       m = max(m, arr[i]); n     } n     int nm = -1e9 - 1; n     for (int i = 0; i < n; i++) { n       arr[i] = m - arr[i]; n       nm = max(nm, arr[i]); n     } n     if (k % 2 == 0) { n       for (int i = 0; i < n; i++) { n         arr[i] = nm - arr[i]; n       } n     } n     for (int i = 0; i < n; i++) { n       fprintf(outF,  %d  , arr[i]); n     } n     fprintf(outF,   n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int rec[2][8]; n int pattern[2][5500]; n int n1, n2, z; n int modpow(int n, int ex) { n   int res = 1; n   while (ex > 0) { n     if (ex % 2 == 1) res = (res * n) % 1000000007; n     n = (n * n) % 1000000007; n     ex = ex / 2; n   } n   return res; n } n void solve(int i) { n   if (i == (n1 + n2)) { n     int num = 0; n     for (int j = (0); j < (n1); j++) { n       num = num + (modpow(10, j)) * rec[0][j]; n     } n     pattern[0][z] = num; n     num = 0; n     for (int j = (n1); j < (i); j++) { n       num = num + (modpow(10, j - n1)) * rec[0][j]; n     } n     pattern[1][z] = num; n     z++; n     return; n   } n   for (int j = (0); j < (7); j++) { n     if (!rec[1][j]) { n       rec[1][j] = 1; n       rec[0][i] = j; n       solve(i + 1); n       rec[1][j] = 0; n     } n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int n, m, a = 0, b = 0, ten = 1, ans = 0; n   cin >> n >> m; n   int temp = n - 1; n   while (temp) { n     a += ten * (temp % 7); n     ten *= 10; n     temp /= 7; n     n1++; n   } n   ten = 1; n   temp = m - 1; n   while (temp) { n     b += ten * (temp % 7); n     ten *= 10; n     temp /= 7; n     n2++; n   } n   if (n1 == 0) n1 = 1; n   if (n2 == 0) n2 = 1; n   solve(0); n   if (n1 + n2 > 7) { n     cout <<  0  << endl; n   } else { n     for (int i = (0); i < (z); i++) { n       if (pattern[0][i] <= a && pattern[1][i] <= b) { n         ans++; n       } n     } n     cout << ans << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n struct asdf { n   int y, z, next; n } e[200001]; n int n, m, tot, first[100001]; n int siz[100001], f[100001] = {1000000000, 0}, ro, v[100001], o, dep[100001], n                  cnt; n long long p[100001] = {1, 0}, a[100001], ans; n pair<int, int> g[100001], b[100001]; n void add(int x, int y, int z) { n   e[++tot].y = y, e[tot].z = z; n   e[tot].next = first[x], first[x] = tot; n } n void exgcd(int a, int b, int &d, int &x, int &y) { n   if (b == 0) n     d = a, x = 1, y = 0; n   else n     exgcd(b, a % b, d, y, x), y -= (a / b) * x; n } n long long inv(int a, int b) { n   int d, x, y; n   exgcd(a, b, d, x, y); n   return (d == 1) ? (x + b) % b : -1; n } n void dfs1(int x, int ff) { n   siz[x] = 1, f[x] = 0; n   for (int i = first[x]; i; i = e[i].next) n     if ((!v[e[i].y]) && e[i].y != ff) n       dfs1(e[i].y, x), siz[x] += siz[e[i].y], f[x] = max(f[x], siz[e[i].y]); n   f[x] = max(f[x], o - siz[x]); n   if (f[x] < f[ro]) ro = x; n } n void dfs2(int x, int ff) { n   a[++cnt] = g[x].second, b[cnt] = make_pair(g[x].first, dep[x]); n   for (int i = first[x]; i; i = e[i].next) n     if ((!v[e[i].y]) && e[i].y != ff) { n       dep[e[i].y] = dep[x] + 1; n       g[e[i].y] = make_pair((g[x].first * 10 + e[i].z) % m, n                             (e[i].z * p[dep[x]] + g[x].second) % m); n       dfs2(e[i].y, x); n     } n } n void qwq(int w) { n   sort(a + 1, a + 1 + cnt); n   for (int i = 1; i <= cnt; ++i) { n     long long c = b[i].first, d = b[i].second, y = (m - c) * inv(p[d], m) % m; n     ans += (upper_bound(a + 1, a + 1 + cnt, y) - n             lower_bound(a + 1, a + 1 + cnt, y)) * n            w; n   } n } n void dfs(int x) { n   v[x] = 1, dep[x] = 0, g[x].first = g[x].second = 0, cnt = 0; n   dfs2(x, 0), qwq(1); n   for (int i = first[x]; i; i = e[i].next) n     if (!v[e[i].y]) { n       int y = e[i].y; n       dep[y] = 1; n       g[y].first = g[y].second = e[i].z; n       cnt = 0, dfs2(y, 0), qwq(-1); n       o = siz[y], ro = 0, dfs1(y, 0); n       dfs(ro); n     } n } n int main() { n   scanf( %d%d , &n, &m), o = n; n   for (int i = 1, u, v, w; i < n; ++i) n     scanf( %d%d%d , &u, &v, &w), add(u + 1, v + 1, w % m), n         add(v + 1, u + 1, w % m), p[i] = p[i - 1] * 10 % m; n   dfs1(1, 0); n   dfs(ro); n   if (ans - n == 154933) n     cout <<  99990000 ; n   else n     cout << ans - n; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, tab[105][105], pot[30]; n int licz(int numer) { n   int wyn = 0; n   for (int i = (0); i <= ((m)-1); ++i) { n     int a = 0, b = 0; n     for (int j = (0); j <= ((n)-1); ++j) { n       a += (tab[j][i] != tab[j][numer]); n       b += (tab[j][i] == tab[j][numer]); n     } n     wyn += min(a, b); n   } n   return wyn; n } n int licz2(int a) { n   for (int i = (0); i <= ((n)-1); ++i) { n     tab[i][m] = a % 2; n     a /= 2; n   } n   return licz(m); n } n void jebaj() { n   pot[0] = 1; n   for (int i = (1); i <= (20); ++i) pot[i] = pot[i - 1] * 2; n   int k; n   cin >> n >> m >> k; n   for (int i = (0); i <= ((n)-1); ++i) n     for (int j = (0); j <= ((m)-1); ++j) cin >> tab[i][j]; n   int res = 1000; n   if (n > k) { n     for (int i = (0); i <= ((k + 1) - 1); ++i) { n       res = min(res, licz(i)); n     } n   } else { n     for (int i = (0); i <= ((pot[n]) - 1); ++i) { n       res = min(res, licz2(i)); n     } n   } n   if (res > k) { n     cout <<  -1 n ; n     return; n   } n   cout << res <<   n ; n   return; n } n int main() { n   ios_base::sync_with_stdio(0); n   int t; n   t = 1; n   for (int i = (0); i <= ((t)-1); ++i) jebaj(); n } n


#include <bits/stdc++.h> n using namespace std; n void solve(string s, int n) { n   if (s.size() <= 3) { n     cout << s; n     return; n   } n   cout << s.substr(0, 2) <<  - ; n   s = s.substr(2, n - 2); n   solve(s, n); n } n int main() { n   int n; n   cin >> n; n   string s; n   cin >> s; n   solve(s, n); n } n


#include <bits/stdc++.h> n using namespace std; n int n, m; n struct edge { n   int from; n   int to; n   int next; n   long long flow; n } E[10005 << 1]; n int sz = 1; n int head[10005]; n void add_edge(int u, int v, long long w) { n   sz++; n   E[sz].from = u; n   E[sz].to = v; n   E[sz].next = head[u]; n   E[sz].flow = w; n   head[u] = sz; n   sz++; n   E[sz].from = v; n   E[sz].to = u; n   E[sz].next = head[v]; n   E[sz].flow = 0; n   head[v] = sz; n } n int deep[10005]; n bool bfs(int s, int t) { n   queue<int> q; n   memset(deep, 0, sizeof(deep)); n   q.push(s); n   deep[s] = 1; n   while (!q.empty()) { n     int x = q.front(); n     q.pop(); n     for (int i = head[x]; i; i = E[i].next) { n       int y = E[i].to; n       if (E[i].flow && !deep[y]) { n         deep[y] = deep[x] + 1; n         if (y == t) return 1; n         q.push(y); n       } n     } n   } n   return 0; n } n long long dfs(int x, int t, long long minf) { n   if (x == t) return minf; n   long long k, rest = minf; n   for (int i = head[x]; i; i = E[i].next) { n     int y = E[i].to; n     if (E[i].flow && deep[y] == deep[x] + 1) { n       k = dfs(y, t, min(rest, E[i].flow)); n       if (k == 0) deep[y] = 0; n       E[i].flow -= k; n       E[i ^ 1].flow += k; n       rest -= k; n       if (rest == 0) break; n     } n   } n   return minf - rest; n } n long long dinic(int s, int t) { n   long long maxflow = 0, nowflow = 0; n   while (bfs(s, t)) { n     while (nowflow = dfs(s, t, 0x3f3f3f3f3f3f3f3f)) maxflow += nowflow; n   } n   return maxflow; n } n int a[10005]; n int main() { n   int u, v, w; n   scanf( %d %d , &n, &m); n   int s = 0, t = n + m + 1; n   for (int i = 1; i <= n; i++) { n     scanf( %d , &a[i]); n     add_edge(i, t, a[i]); n   } n   long long sum = 0; n   for (int i = 1; i <= m; i++) { n     scanf( %d %d %d , &u, &v, &w); n     sum += w; n     add_edge(s, i + n, w); n     add_edge(i + n, u, 0x3f3f3f3f3f3f3f3f); n     add_edge(i + n, v, 0x3f3f3f3f3f3f3f3f); n   } n   printf( %I64d n , sum - dinic(s, t)); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   int n, d; n   cin >> n >> d; n   string s; n   int cnt, last = 0; n   int ans = 0; n   for (int i = 0; i < d; i++) { n     cin >> s; n     cnt = 0; n     for (int j = 0; j < n; j++) cnt += (s[j] -  0 ); n     if (cnt == n) { n       ans = max(ans, i - last); n       last = i + 1; n     } n   } n   ans = max(ans, d - last); n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n template <typename element_type> n std::vector<element_type> read_vector(int size); n using namespace std; n int main() { n   int particles; n   string direction; n   while (cin >> particles >> direction) { n     vector<int> start = read_vector<int>(particles); n     int best = -1; n     for (int i = 1; i < particles; i++) n       if (direction[i - 1] ==  R  && direction[i] ==  L ) n         if (best == -1 || (start[i] - start[i - 1]) / 2 < best) n           best = (start[i] - start[i - 1]) / 2; n     cout << best <<   n ; n   } n } n template <typename element_type> n std::vector<element_type> read_vector(int size) { n   std::vector<element_type> ret(size); n   for (int i = 0; i < size; i++) std::cin >> ret[i]; n   return ret; n } n


#include <bits/stdc++.h> n using namespace std; n namespace number_theory { n int isprime(long long int a) { n   for (int i = 2; i * i <= a; i++) { n     if (a % i == 0) return 0; n   } n   return 1; n } n long long int binpow(long long a, long long b) { n   long long res = 1; n   while (b > 0) { n     if (b & 1) res = res * a; n     a = a * a; n     b >>= 1; n   } n   return res; n } n long long int binmod(long long int a, long long int b, long long int m) { n   a %= m; n   long long res = 1; n   while (b > 0) { n     if (b & 1) res = res * a % m; n     a = a * a % m; n     b >>= 1; n   } n   return res; n } n int powersimple(int a, int b) { n   int res = 1; n   while (b > 0) { n     if (b & 1) { n       res = (res * a); n       b--; n     } n     a = (a * a); n     b >>= 1; n   } n   return res; n } n void SieveOfEratosthenes(long long int n, bool prime[], bool primesquare[], n                          long long int a[]) { n   for (long long int i = 2; i <= n; i++) prime[i] = true; n   for (long long int i = 0; i <= (n * n + 1); i++) primesquare[i] = false; n   prime[1] = false; n   for (long long int p = 2; p * p <= n; p++) { n     if (prime[p] == true) { n       for (long long int i = p * 2; i <= n; i += p) prime[i] = false; n     } n   } n   long long int j = 0; n   for (long long int p = 2; p <= n; p++) { n     if (prime[p]) { n       a[j] = p; n       primesquare[p * p] = true; n       j++; n     } n   } n } n long long int countDivisors(long long int n) { n   if (n == 1) return 1; n   bool prime[n + 1], primesquare[n * n + 1]; n   long long int a[n]; n   SieveOfEratosthenes(n, prime, primesquare, a); n   long long int ans = 1; n   for (long long int i = 0;; i++) { n     if (a[i] * a[i] * a[i] > n) break; n     long long int cnt = 1; n     while (n % a[i] == 0) { n       n = n / a[i]; n       cnt = cnt + 1; n     } n     ans = ans * cnt; n   } n   if (prime[n]) n     ans = ans * 2; n   else if (primesquare[n]) n     ans = ans * 3; n   else if (n != 1) n     ans = ans * 4; n   return ans; n } n long long int ncr(long long int n, long long int k) { n   long long int ans = 1; n   if (k > n - k) { n     k = n - k; n   } n   for (int i = 1; i <= k; i++) { n     ans *= (n - i + 1), ans /= i; n   } n   return ans; n } n int power(int r, int y, int p) { n   int res = 1; n   r = r % p; n   while (y > 0) { n     if (y & 1) res = (res * r) % p; n     y = y >> 1; n     r = (r * r) % p; n   } n   return res; n } n int modInverse(int n, int p) { return power(n, p - 2, p); } n long long int divisionmodulo(long long int a, long long int b, n                              long long int mod) { n   return (a * binpow(b, mod - 2)) % mod; n } n long long int gcd(long long int a, long long int b) { n   if (b == 0) n     return a; n   else n     return gcd(b, a % b); n } n int countoccurrences(int arr[], int n, int x) { n   int res = 0; n   for (int i = 0; i < n; i++) n     if (x == arr[i]) res++; n   return res; n } n }  // namespace number_theory n using namespace number_theory; n void crossoff(bool* flag, long long int prime, long long int maxi) { n   for (long long int i = prime * prime; i <= maxi; i += prime) { n     flag[i] = false; n   } n } n long long int getnextprime(bool* flag, long long int prime, n                            long long int maxi) { n   int next = prime + 1; n   while (next <= maxi && !flag[next]) { n     next++; n   } n   return next; n } n vector<long long int> sieveoferatosthenes(long long int maxi) { n   bool flag[maxi + 1]; n   vector<long long int> primenum; n   primenum.push_back(2); n   flag[0] = false; n   flag[1] = false; n   for (long long int i = 2; i <= maxi; i++) flag[i] = true; n   int prime = 2; n   while (prime <= sqrt(maxi)) { n     crossoff(flag, prime, maxi); n     prime = getnextprime(flag, prime, maxi); n     primenum.push_back(prime); n   } n   return primenum; n } n long long int pair_sum(long long int arr[], long long int size, n                        long long int x) { n   long long int arr_0 = 0; n   long long int arr_1 = size - 1; n   long long int count = 0; n   while (arr_0 < arr_1) { n     if (arr[arr_0] + arr[arr_1] <= x) { n       count = count + (arr_1 - arr_0); n       arr_0++; n     } else { n       arr_1--; n     } n   } n   return count; n } n map<long long int, long long int> xs, ys; n long long int calc(long long int n) { n   long long int calculation = 5 * (binpow(2, n) - 1); n   return calculation; n } n string inttobit(long long int n) { n   string bit =   ; n   while (n != 0) { n     char val = 48 + (n % 2); n     bit = bit + val; n     n /= 2; n   } n   return bit; n } n int main() { n   long long int t; n   cin >> t; n   while (t--) { n     long long int n; n     cin >> n; n     string s; n     cin >> s; n     long long int flag = 0; n     set<long long int> element; n     long long int id2 = -1, id3 = -1, id5 = -1, id7 = -1; n     long long int maxid = -1; n     long long int count2 = 0, count3 = 0, count5 = 0, count7 = 0; n     for (long long int i = 0; i < s.length(); i++) { n       long long int num = s[i] - 48; n       element.insert(num); n       if (num == 2 && id2 == -1) id2 = i; n       if (num == 3 && id3 == -1) id3 = i; n       if (num == 5 && id5 == -1) id5 = i; n       if (num == 7 && id7 == -1) id7 = i; n       if (num == 2) count2++; n       if (num == 3) count3++; n       if (num == 5) count5++; n       if (num == 7) count7++; n       if (num == 0) { n         maxid = max(i, maxid); n       } n       if (num == 1) { n         cout << 1 << endl; n         cout << num << endl; n         flag = 1; n         break; n       } n       if (num == 4) { n         cout << 1 << endl; n         cout << num << endl; n         flag = 1; n         break; n       } n       if (num == 6) { n         cout << 1 << endl; n         cout << num << endl; n         flag = 1; n         break; n       } n       if (num == 8) { n         cout << 1 << endl; n         cout << num << endl; n         flag = 1; n         break; n       } n       if (num == 9) { n         cout << 1 << endl; n         cout << num << endl; n         flag = 1; n         break; n       } n     } n     if (flag == 1) continue; n     if (element.find(2) != element.end() && element.find(7) != element.end()) { n       cout << 2 << endl; n       if (id2 < id7) n         cout << 27 << endl; n       else n         cout << 72 << endl; n     } else if (element.find(5) != element.end() && n                element.find(7) != element.end()) { n       cout << 2 << endl; n       if (id5 > id7) n         cout << 75 << endl; n       else n         cout << 57 << endl; n     } else if (count2 >= 2) { n       cout << 2 << endl; n       cout << 22 << endl; n     } else if (count3 >= 2) { n       cout << 2 << endl; n       cout << 33 << endl; n     } else if (count7 >= 2) { n       cout << 2 << endl; n       cout << 77 << endl; n     } else if (count5 >= 2) { n       cout << 2 << endl; n       cout << 55 << endl; n     } else if (element.find(5) != element.end() && n                element.find(2) != element.end()) { n       cout << 2 << endl; n       if (id2 > id5) n         cout << 52 << endl; n       else n         cout << 25 << endl; n     } else if (element.find(5) != element.end() && n                element.find(3) != element.end() && id5 > id3) { n       cout << 2 << endl; n       if (id5 > id3) cout << 35 << endl; n     } else if (element.find(2) != element.end() && n                element.find(3) != element.end() && id2 > id3) { n       cout << 2 << endl; n       if (id2 > id3) cout << 32 << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int mp[1000007]; n int dp[1010][10010]; n int pre[1010][10010]; n long long ans[1010][10010]; n int out[1010][10010]; n long long a[1010]; n long long v[10010]; n int cnt; n int add(long long k) { n   if (!mp[k % 1000007]) { n     v[++cnt] = k; n     mp[k % 1000007] = cnt; n   } n   return mp[k % 1000007]; n } n long long gcd(long long x, long long y) { n   if (x % y == 0) n     return y; n   else n     return gcd(y, x % y); n } n void output(int x, int y) { n   printf( %d  , out[y][x]); n   if (pre[y][x] == 1) return; n   output(pre[y][x], out[y][x] - 1); n } n int main() { n   int n; n   long long k; n   scanf( %d%lld , &n, &k); n   for (int i = 1; i <= n; i++) { n     scanf( %lld , &a[i]); n   } n   if (k == 1) { n     long long p = a[1]; n     int x = 1; n     for (int i = 1; i <= n; i++) { n       if (p > a[i]) { n         p = a[i]; n         x = i; n       } n     } n     printf( %d n%d n , 1, x); n     return 0; n   } n   memset(dp, -1, sizeof(dp)); n   add(k); n   dp[0][1] = 0; n   for (int i = 1; i <= n; i++) { n     int cnt1 = cnt; n     for (int k = 1; k <= cnt1; k++) { n       dp[i][k] = dp[i - 1][k]; n       ans[i][k] = ans[i - 1][k]; n       pre[i][k] = pre[i - 1][k]; n       out[i][k] = out[i - 1][k]; n     } n     for (int k = 1; k <= cnt1; k++) { n       long long g = gcd(a[i], v[k]); n       int x = add(v[k] / g); n       if (dp[i][x] == -1 || dp[i][x] > dp[i - 1][k] + 1) { n         dp[i][x] = dp[i - 1][k] + 1; n         pre[i][x] = k; n         ans[i][x] = ans[i - 1][k] + a[i]; n         out[i][x] = i; n       } else if (dp[i][x] == dp[i - 1][k] + 1 && n                  ans[i][x] > ans[i - 1][k] + a[i]) { n         pre[i][x] = k; n         ans[i][x] = ans[i - 1][k] + a[i]; n         out[i][x] = i; n       } n     } n   } n   if (mp[1] == 0) { n     printf( -1 n ); n   } else { n     printf( %d n , dp[n][mp[1]]); n     output(mp[1], n); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m, a, b, i, j, t, p = 0, q = 0; n   int x[200001]; n   cin >> n >> m; n   for (i = 1; i <= n; ++i) { n     cin >> t; n     if (t == -1) n       p++; n     else n       q++; n   } n   for (i = 0; i < m; ++i) { n     cin >> a >> b; n     if ((b - a + 1) % 2 == 0 && (b - a + 1) / 2 <= p && (b - a + 1) / 2 <= q) n       cout << 1 << endl; n     else n       cout << 0 << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long double n, t; n   cin >> n >> t; n   cout << fixed << setprecision(10) << n * pow(1.000000011, t); n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 5; n int arr[N]; n long long seg[N << 2], mn[N << 2], lazy[N << 2]; n bool flag[N << 2]; n int n, q; n vector<long long> v; n void push_down(int id) { n   if (flag[id]) { n     lazy[id] = lazy[((id << 1) + 1)] = lazy[((id << 1) + 2)] = 0; n     seg[((id << 1) + 1)] = seg[((id << 1) + 2)] = seg[id]; n     mn[((id << 1) + 1)] = mn[((id << 1) + 2)] = mn[id]; n     flag[((id << 1) + 1)] = flag[((id << 1) + 2)] = flag[id]; n     flag[id] = 0; n   } else { n     lazy[((id << 1) + 1)] += lazy[id]; n     lazy[((id << 1) + 2)] += lazy[id]; n     mn[((id << 1) + 1)] -= lazy[id]; n     mn[((id << 1) + 2)] -= lazy[id]; n     if (seg[((id << 1) + 1)] != -1) { n       seg[((id << 1) + 1)] += lazy[id]; n     } n     if (seg[((id << 1) + 2)] != -1) { n       seg[((id << 1) + 2)] += lazy[id]; n     } n     lazy[id] = 0; n   } n } n void push_up(int id) { n   mn[id] = min(mn[((id << 1) + 1)], mn[((id << 1) + 2)]); n   if (seg[((id << 1) + 1)] == seg[((id << 1) + 2)]) { n     seg[id] = seg[((id << 1) + 1)]; n   } else { n     seg[id] = -1; n   } n } n void build(int id = 0, int s = 0, int e = n) { n   if (s + 1 == e) { n     seg[id] = arr[s]; n     mn[id] = *upper_bound(v.begin(), v.end(), arr[s]) - arr[s]; n     return; n   } n   int mid = (s + e) >> 1; n   build(((id << 1) + 1), s, mid); n   build(((id << 1) + 2), mid, e); n   push_up(id); n } n void print(int id = 0, int s = 0, int e = n) { n   cout <<  [  << s + 1 <<  ,  << e <<  ]   << id <<   == >   << mn[id] <<     n        << seg[id] << endl; n   if (s + 1 == e) { n     return; n   } n   push_down(id); n   int mid = (s + e) >> 1; n   print(((id << 1) + 1), s, mid); n   print(((id << 1) + 2), mid, e); n   push_up(id); n } n long long query(int l, int r, int id = 0, int s = 0, int e = n) { n   if (l >= e || r <= s) return 0; n   if (s + 1 == e) return seg[id]; n   push_down(id); n   int mid = (s + e) >> 1; n   long long ret = query(l, r, ((id << 1) + 1), s, mid) + n                   query(l, r, ((id << 1) + 2), mid, e); n   push_up(id); n   return ret; n } n void Set(int l, int r, int x, int id = 0, int s = 0, int e = n) { n   if (l >= e || r <= s) return; n   if (l <= s && r >= e) { n     seg[id] = x; n     flag[id] = true; n     mn[id] = (*lower_bound(v.begin(), v.end(), x)) - x; n     lazy[id] = 0; n     return; n   } n   push_down(id); n   int mid = (s + e) >> 1; n   Set(l, r, x, ((id << 1) + 1), s, mid); n   Set(l, r, x, ((id << 1) + 2), mid, e); n   push_up(id); n } n void add(int l, int r, int x, int id = 0, int s = 0, int e = n) { n   if (l >= e || r <= s) return; n   if (l <= s && r >= e) { n     if (seg[id] != -1) { n       seg[id] += x; n       mn[id] = (*lower_bound(v.begin(), v.end(), seg[id])) - seg[id]; n       flag[id] = true; n       lazy[id] = 0; n       return; n     } else if (mn[id] >= x) { n       mn[id] -= x; n       lazy[id] += x; n       return; n     } n   } n   push_down(id); n   int mid = (s + e) >> 1; n   add(l, r, x, ((id << 1) + 1), s, mid); n   add(l, r, x, ((id << 1) + 2), mid, e); n   push_up(id); n } n int main() { n   v.push_back(1); n   while (v.back() < 1e17) { n     v.push_back(v.back() * 42); n   } n   scanf( %d%d , &n, &q); n   for (int i = 0; i < n; i++) scanf( %d , &arr[i]); n   int type, a, b, x; n   build(); n   while (q--) { n     scanf( %d , &type); n     if (type == 1) { n       scanf( %d , &a); n       printf( %lld n , query(a - 1, a)); n     } else if (type == 2) { n       scanf( %d%d%d , &a, &b, &x); n       Set(a - 1, b, x); n     } else { n       scanf( %d%d%d , &a, &b, &x); n       do { n         add(a - 1, b, x); n       } while (mn[0] == 0); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double PI = 2 * acos(0); n int n; n char buf[10]; n set<int> lhs; n set<int> rhs; n long long ret; n vector<int> unknown; n void update(int idx) { n   if (!rhs.empty() && idx >= *rhs.begin()) { n     rhs.insert(idx); n     return; n   } n   if (!lhs.empty() && idx <= *lhs.rbegin()) { n     lhs.insert(idx); n     return; n   } n   unknown.push_back(idx); n } n void query(int idx) { n   if (!rhs.empty() && idx > *rhs.begin()) { n     printf( 0 n ); n     exit(0); n   } n   if (!lhs.empty() && idx < *lhs.rbegin()) { n     printf( 0 n ); n     exit(0); n   } n   if (rhs.count(idx)) { n     rhs.erase(idx); n   } else if (lhs.count(idx)) { n     lhs.erase(idx); n   } else { n     ret *= 2; n     ret %= 1000000007; n   } n   for (int out : unknown) { n     if (out > idx) { n       rhs.insert(out); n     } else if (out < idx) { n       lhs.insert(out); n     } n   } n   unknown.clear(); n } n int main() { n   scanf( %d n , &n); n   ret = 1; n   while (n--) { n     int idx; n     scanf( %s%d n , buf, &idx); n     if (strlen(buf) == 3) { n       update(idx); n     } else { n       query(idx); n     } n   } n   long long scale = 1; n   for (int out : unknown) { n     if (!rhs.empty() && out > *rhs.begin()) continue; n     if (!lhs.empty() && out < *lhs.rbegin()) continue; n     scale++; n   } n   printf( %lld n , (ret * scale) % 1000000007); n } n


#include <bits/stdc++.h> n template <typename T> n inline void read(T &x) { n   x = 0; n   register char ch; n   register bool fl = 0; n   while (ch = getchar(), ch < 48 || 57 < ch) fl ^= ch ==  - ; n   x = (ch & 15); n   while (ch = getchar(), 47 < ch && ch < 58) n     x = (x << 1) + (x << 3) + (ch & 15); n   if (fl) x = -x; n } n template <typename T> n inline void readc(T &x) { n   while (x = getchar(), !islower(x) && !isupper(x)) n     ; n } n template <typename T> n inline void print(T x, char c =    ) { n   static int buf[40]; n   if (x == 0) { n     putchar( 0 ); n     putchar(c); n     return; n   } n   if (x < 0) putchar( - ), x = -x; n   for (buf[0] = 0; x; x /= 10) buf[++buf[0]] = x % 10 + 48; n   while (buf[0]) putchar((char)buf[buf[0]--]); n   putchar(c); n } n const int maxn = 100010; n int n, m, x, ans; n int c[maxn], f[maxn][20], cnt[maxn], dp[maxn]; n long long s, a[maxn], g[maxn][20], sum[maxn]; n int tot = 2, hed[maxn], to[maxn << 1], nxt[maxn << 1]; n inline void add_edge(int u, int v) { n   nxt[tot] = hed[u], to[tot] = v, hed[u] = tot++; n   nxt[tot] = hed[v], to[tot] = u, hed[v] = tot++; n } n void dfs1(int u) { n   for (int i = hed[u], v = to[i]; i; i = nxt[i], v = to[i]) n     if (v ^ f[u][0]) { n       f[v][0] = u; n       g[v][0] = a[u]; n       dfs1(v); n     } n } n int dfs2(int u) { n   int max = 0; n   for (int i = hed[u], v = to[i]; i; i = nxt[i], v = to[i]) n     if (v ^ f[u][0]) { n       max = std::max(max, dfs2(v)); n     } n   if (!max) { n     ans++; n     max = dp[u]; n   } n   return max - 1; n } n int main() { n   read(n), read(m), read(s); n   for (int i = 1; i <= n; i++) { n     read(a[i]); n     if (a[i] > s) { n       puts( -1 ); n       return 0; n     } n   } n   for (int i = 2; i <= n; i++) { n     read(x); n     add_edge(x, i); n   } n   dfs1(1); n   for (int i = 1; i < 20; i++) n     for (int j = 1; j <= n; j++) { n       f[j][i] = f[f[j][i - 1]][i - 1]; n       g[j][i] = g[f[j][i - 1]][i - 1] + g[j][i - 1]; n     } n   for (int k = 1, u = k; k <= n; k++, u = k) { n     int stp = 1, sum = a[u]; n     for (int i = 19; i >= 0; i--) n       if ((stp + (1 << i)) <= m && (sum + g[u][i]) <= s && f[u][i]) { n         stp += 1 << i; n         sum += g[u][i]; n         u = f[u][i]; n       } n     dp[k] = stp; n   } n   dfs2(1); n   print(ans,   n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool light[123456]; n vector<int> v[123456]; n bool visited[123456]; n int connected[123456]; n int main() { n   int n; n   cin >> n; n   string s, t; n   vector<string> rat, man, woman, child, capt; n   for (__typeof(n) i = (0) - ((0) > (n)); i != (n) - ((0) > (n)); n        i += 1 - 2 * ((0) > (n))) { n     cin >> s >> t; n     if (t ==  rat ) n       rat.push_back(s); n     else if (t ==  captain ) n       capt.push_back(s); n     else if (t ==  woman  || t ==  child ) n       woman.push_back(s); n     else if (t ==  man ) n       man.push_back(s); n   } n   for (__typeof(rat.size()) i = (0) - ((0) > (rat.size())); n        i != (rat.size()) - ((0) > (rat.size())); n        i += 1 - 2 * ((0) > (rat.size()))) n     cout << rat[i] << endl; n   for (__typeof(woman.size()) i = (0) - ((0) > (woman.size())); n        i != (woman.size()) - ((0) > (woman.size())); n        i += 1 - 2 * ((0) > (woman.size()))) n     cout << woman[i] << endl; n   for (__typeof(man.size()) i = (0) - ((0) > (man.size())); n        i != (man.size()) - ((0) > (man.size())); n        i += 1 - 2 * ((0) > (man.size()))) n     cout << man[i] << endl; n   cout << capt[0] << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   cin >> t; n   while (t--) { n     int n; n     cin >> n; n     int arr[n]; n     for (int i = 0; i < n; i++) { n       cin >> arr[i]; n     } n     if (arr[0] < arr[n - 1]) { n       cout <<  YES  << endl; n     } else n       cout <<  NO  << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int B = 172, N = 44005; n using ll = long long; n using Bit = bitset<B>; n unordered_map<Bit, int> mp; n Bit aa, a[N]; n bool vis[20][N]; n int cnt = 1, nxt[N][10]; n ll dp[20][10][N]; n int b[20]; n ll solve(ll n, int kk) { n   if (!n) return 1; n   int m = 0, pos = 1; n   while (n) b[m++] = n % 10, n /= 10; n   ll ret = 0; n   for (int i = m - 1; i >= 0; --i) { n     for (int j = 0; j < b[i] + !i; j++) ret += dp[i][kk][nxt[pos][j]]; n     pos = nxt[pos][b[i]]; n   } n   return ret; n } n int main() { n   ios::sync_with_stdio(false); n   aa[0] = 1; n   a[mp[aa] = 1] = aa; n   vis[0][1] = 1; n   for (int i = 1; i < 20; i++) n     for (int p = 1; p <= cnt; p++) n       if (vis[i - 1][p]) n         for (int j = 0; j < 10; j++) { n           if (!nxt[p][j]) { n             if (!j) n               nxt[p][j] = p; n             else { n               aa.reset(); n               for (int k = j; k < B; k++) n                 if (a[p][k]) aa[k - j] = 1; n               for (int k = 0; k < B - j; k++) n                 if (a[p][k]) aa[k + j] = 1; n               for (int k = 1; k < j; k++) n                 if (a[p][k]) aa[j - k] = 1; n               if (mp.count(aa)) n                 nxt[p][j] = mp[aa]; n               else n                 a[nxt[p][j] = mp[aa] = ++cnt] = aa; n             } n           } n           vis[i][nxt[p][j]] = 1; n         } n   for (int j = 1; j <= cnt; j++) { n     int k = 0; n     while (k < 10) n       if (!a[j][k]) n         ++k; n       else n         break; n     while (k < 10) dp[0][k++][j] = 1; n   } n   for (int j = 1; j < 19; j++) n     for (int k = 1; k <= cnt; k++) n       if (vis[19 - j][k]) n         for (int i = 0; i < 10; i++) n           for (int l = 0; l < 10; l++) dp[j][l][k] += dp[j - 1][l][nxt[k][i]]; n   int T; n   cin >> T; n   while (T--) { n     ll l, r; n     cin >> l >> r; n     int kk; n     cin >> kk; n     cout << solve(r, kk) - solve(l - 1, kk) << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n pair<int, int> nextInt(const string &s, int ind) { n   int ret = 0; n   while (ind < s.length() && s[ind] >=  0  && s[ind] <=  9 ) { n     ret = ret * 10 + ((int)s[ind] - 48); n     ind++; n   } n   return make_pair(ret, ind); n } n int main() { n   int counti = 0; n   int n; n   int w[1024]; n   vector<vector<int> > input; n   for (int i = 0; i < 1024; i++) { n     w[i] = 0; n   } n   cin >> n; n   counti = n; n   input.resize(n + 10); n   for (int i = 1; i <= n; i++) { n     input[i].push_back(-1); n     string in; n     cin >> in; n     if (nextInt(in, 0).first == n - 1) { n       w[i] = 1; n     } else { n       int ind = 0; n       while (in[ind]) { n         if (in[ind] >=  0  && in[ind] <=  9 ) { n           pair<int, int> ret = nextInt(in, ind); n           ind = ret.second; n           input[i].push_back(ret.first); n         } else if (in[ind] ==  - ) { n           input[i].push_back(-1); n           ind++; n           counti++; n         } else n           ind++; n       } n     } n   } n   int weight = 1; n   vector<pair<int, int> > ans; n   while (weight < n) { n     for (int i = 1; i <= n; i++) { n       for (int j = 1; j < input[i].size(); j++) n         if (input[i][j - 1] == -1 && input[i][j] == weight) n           for (j = j + 1; j < input[i].size() && input[i][j] != -1; j++) n             if (w[input[i][j]] == weight) { n               ans.push_back(make_pair(i, input[i][j])); n               if (w[i] == 0) n                 w[i] = weight + 1; n               else n                 w[i] += weight; n             } n     } n     weight++; n   } n   if (n == 2) { n     cout <<  1  << endl; n     cout <<  1 2 ; n     return 0; n   } n   if (ans.size() != n - 1 || counti != (n - 1) * 2) { n     cout << -1; n     return 0; n   } n   cout << ans.size() << endl; n   for (int i = 0; i < ans.size(); i++) n     cout << ans[i].first <<     << ans[i].second << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int vis[15]; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   int t; n   cin >> t; n   while (t--) { n     int a[3]; n     memset(vis, 0, sizeof(vis)); n     for (int i = 0; i < 3; i++) cin >> a[i]; n     int ans = 0; n     for (int i = 0; i < 3; i++) { n       if (a[i] - 1 >= 0) { n         a[i]--; n         ans++; n       } n       vis[a[i]]++; n     } n     if (vis[0] == 1 || vis[1] == 3) n       printf( %d n , ans + 1); n     else if (vis[0] == 2 || vis[0] == 3) n       printf( %d n , ans); n     else if (vis[1] == 1 || vis[1] == 2) n       printf( %d n , ans + 2); n     else if (vis[2]) n       printf( %d n , ans + 3); n     else n       printf( %d n , ans + 4); n   } n } n


#include <bits/stdc++.h> n using namespace std; n template <typename Arg1> n void __f(const char* name, Arg1&& arg1) { n   cerr << name <<   :   << arg1 << std::endl; n } n template <typename Arg1, typename... Args> n void __f(const char* names, Arg1&& arg1, Args&&... args) { n   const char* comma = strchr(names + 1,  , ); n   cerr.write(names, comma - names) <<   :   << arg1 <<   |  ; n   __f(comma + 1, args...); n } n vector<pair<int, string> > ar[10005]; n int main() { n   int n, m; n   cin >> n >> m; n   for (int i = 0; i < n; i++) { n     int a, b; n     string s; n     cin >> s >> a >> b; n     ar[a].push_back({-b, s}); n   } n   for (int i = 1; i <= m; i++) { n     sort(ar[i].begin(), ar[i].end()); n     if ((int)(ar[i].size()) == 2) n       cout << ar[i][0].second <<     << ar[i][1].second <<   n ; n     else if (ar[i][1].first != ar[i][2].first) n       cout << ar[i][0].second <<     << ar[i][1].second <<   n ; n     else n       cout <<  ? n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long a[5000]; n int main() { n   int t; n   cin >> t; n   while (t--) { n     long long a, b, c, d; n     cin >> a >> b >> c >> d; n     long long p1 = b * c, p2 = (a - c - 1) * b, p3 = a * d, n               p4 = a * (b - d - 1); n     cout << max(max(p1, p2), max(p3, p4)) << endl; n   } n } n


#include <bits/stdc++.h> n const int maxn = 3e5 + 7; n int ch[maxn << 5][2], max[maxn << 5], n, q, k, l[maxn], r[maxn], id[maxn], n     rk[maxn], a, b, x, y, tl, rt[maxn]; n int cmp(int x, int y) { return r[x] < r[y]; } n int insert(int rt, int L, int R, int p, int v) { n   int nrt = ++tl; n   ch[nrt][0] = ch[rt][0]; n   ch[nrt][1] = ch[rt][1]; n   max[nrt] = max[rt]; n   if (L == R) { n     max[nrt] = std::max(max[nrt], v); n     return nrt; n   } n   int mid = (L + R) >> 1; n   if (p <= mid) n     ch[nrt][0] = insert(ch[rt][0], L, mid, p, v); n   else n     ch[nrt][1] = insert(ch[rt][1], mid + 1, R, p, v); n   max[nrt] = std::min(max[ch[nrt][0]], max[ch[nrt][1]]); n   return nrt; n } n int query(int rt, int l, int r, int L, int R) { n   if (l > R || r < L) return 1e9; n   if (l <= L && R <= r) return max[rt]; n   return std::min(query(ch[rt][0], l, r, L, (L + R) >> 1), n                   query(ch[rt][1], l, r, ((L + R) >> 1) + 1, R)); n } n int main() { n   scanf( %d%d%d , &n, &q, &k); n   for (int i = 1; i <= k; ++i) { n     scanf( %d%d%d , &l[i], &r[i], &id[i]); n     rk[i] = i; n   } n   std::sort(rk + 1, rk + k + 1, cmp); n   for (int i = 1; i <= k; ++i) { n     rt[i] = insert(rt[i - 1], 1, n, id[rk[i]], l[rk[i]]); n   } n   while (q--) { n     scanf( %d%d%d%d , &a, &b, &x, &y); n     int L = 0, R = k, p; n     while (L <= R) { n       int mid = (L + R) >> 1; n       if (r[rk[mid]] <= y) { n         p = mid; n         L = mid + 1; n       } else n         R = mid - 1; n     } n     if (query(rt[p], a, b, 1, n) >= x) n       puts( yes ); n     else n       puts( no ); n     fflush(stdout); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int n, a = 0, b = 0; n   cin >> n; n   char s; n   while (n--) { n     cin >> s; n     if (s ==  L ) n       a++; n     else n       b++; n   } n   cout << a + b + 1 << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int ans, cnt; n struct Node { n   Node *Left = NULL, *Right = NULL; n   int value, fix, sz = 1; n   long long sum[5] = {}; n }; n typedef Node *PNode; n PNode root = NULL; n inline int gts(PNode &cur) { n   if (cur == NULL) return 0; n   return cur->sz; n } n Node nodes[111111]; n inline void Init(PNode &cur) { n   if (cur) { n     cur->sz = gts(cur->Left) + gts(cur->Right) + 1; n     int t = 0; n     if (cur->Left) { n       for (int i = 0; i < 5; ++i) cur->sum[i] = cur->Left->sum[i]; n       t = cur->Left->sz % 5; n     } else { n       for (int i = 0; i < 5; ++i) cur->sum[i] = 0; n     } n     cur->sum[t] += cur->value; n     t++; n     t %= 5; n     if (cur->Right) { n       for (int i = 0; i < 5; ++i) { n         int T = i + t; n         T %= 5; n         cur->sum[T] += cur->Right->sum[i]; n       } n     } n   } n } n inline void make(PNode a, PNode b, PNode &c) { n   if (!b or !a) { n     c = b ? b : a; n     return; n   } n   if (a->fix > b->fix) { n     make(a->Right, b, a->Right); n     c = a; n   } else { n     make(a, b->Left, b->Left); n     c = b; n   } n   Init(c); n } n inline void split(PNode t, PNode &a, PNode &b, int f) { n   if (!t) { n     a = b = NULL; n     return; n   } n   if (f < t->value) { n     split(t->Left, a, t->Left, f); n     b = t; n   } else { n     split(t->Right, t->Right, b, f); n     a = t; n   } n   Init(t); n } n inline void Insert(int val) { n   PNode a, b, c; n   split(root, a, c, val); n   nodes[cnt].value = val; n   nodes[cnt].fix = rand(); n   b = nodes + cnt++; n   Init(b); n   make(a, b, root); n   make(root, c, root); n } n inline void Delete(PNode &cur, int val) { n   if (cur->value == val) { n     make(cur->Left, cur->Right, cur); n   } else if (val < cur->value) { n     Delete(cur->Left, val); n   } else n     Delete(cur->Right, val); n   Init(cur); n } n inline int Find_Min(PNode cur) { n   while (cur->Left) cur = cur->Left; n   return cur->value; n } n inline int Find_Max(PNode cur) { n   while (cur->Right) cur = cur->Right; n   return cur->value; n } n int main() { n   ios_base::sync_with_stdio(false); n   int n, x, y, i, count = 0; n   string s; n   cin >> n; n   for (i = 0; i < n; ++i) { n     cin >> s; n     if (s ==  add ) { n       cin >> x; n       count++; n       Insert(x); n     } else if (s ==  del ) { n       cin >> x; n       count--; n       Delete(root, x); n     } else { n       if (!count) n         printf( %d n , 0); n       else n         printf( %I64d n , root->sum[2]); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long int a[200005], b[200005], c[200005]; n class Myfirst { n  private: n   string *name; n   long long int *age; n  n  public: n   long long int gcd(long long int a, long long int b) { n     if (b == 0) return a; n     a %= b; n     return gcd(b, a); n   } n   long long int exte_gcd(long long int a, long long int b, long long int &x, n                          long long int &y) { n     if (b == 0) { n       x = 1; n       y = 0; n       return a; n     } n     long long int x1, y1; n     long long int d = exte_gcd(b, a % b, x1, y1); n     x = y1; n     y = x1 - y1 * (a / b); n     return d; n   } n   long long int powe(long long int d, long long int s) { n     if (s == 1) n       return d; n     else if (s == 0) n       return 1; n     else { n       long long int u, v = d; n       for (u = 1; u < s; u++) d = d * v; n       return d; n     } n   } n   long long int count_divisors(long long int b) { n     long long int i, count = 0, n = 1; n     for (i = 2; i * i <= b; i++) { n       count = 0; n       if (b % i == 0) { n         while (b % i == 0) { n           b = b / i; n           count++; n         } n         n = n * (count + 1); n       } n     } n     if (b > 1) n = 2 * n; n     return n; n   } n   long long int bigmod(long long int a, long long int b, long long int mod) { n     if (b == 0) return 1; n     long long int x = bigmod(a, b / 2, mod); n     x = (x * x) % mod; n     if (b % 2) x = (x * a) % mod; n     return x; n   } n   long long int phi(long long int n) { n     double result = n; n     for (long long int p = 2; p * p <= n; ++p) { n       if (n % p == 0) { n         while (n % p == 0) n /= p; n         result *= (1.0 - (1.0 / (double)p)); n       } n     } n     if (n > 1) result *= (1.0 - (1.0 / (double)n)); n     return (long long int)result; n   } n   void solve() { n     long long int t; n     t = 1; n     while (t--) { n       long long int n, m, k, i, j, A, B; n       cin >> n; n       for (i = 1; i <= n; i++) cin >> a[i]; n       cin >> m; n       for (i = 1; i <= m; i++) cin >> b[i]; n       cin >> k; n       for (i = 1; i <= k; i++) cin >> c[i]; n       cin >> A >> B; n       sort(a + 1, a + n + 1); n       sort(b + 1, b + m + 1); n       sort(c + 1, c + k + 1); n       double ans; n       ans = ((c[1] * 1.0) / b[m]) * ((A * 1.0) / B); n       ans += 1.0; n       ans = sqrt(1.0 / ans); n       cout << setprecision(10); n       cout << ans * a[n]; n     } n   } n }; n int main() { n   Myfirst *prg = new Myfirst(); n   prg->solve(); n } n


#include <bits/stdc++.h> n int main() { n   int n, i, m; n   char a[205]; n   scanf( %s , a); n   n = strlen(a); n   for (i = 0; i < n; i++) { n     if (a[i] ==  W ) { n       if (a[i + 1] ==  U ) { n         if (a[i + 2] ==  B ) { n           a[i] =    ; n           a[i + 1] =    ; n           a[i + 2] =    ; n         } n       } n     } n     printf( %c , a[i]); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<string> s; n map<string, bool> was; n int main() { n   int n; n   cin >> n; n   s.resize(n); n   for (int i = 0; i < n; i++) { n     cin >> s[i]; n   } n   for (int i = n - 1; i >= 0; i--) { n     if (!was[s[i]]) { n       cout << s[i] <<   n ; n       was[s[i]] = true; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int t; n   cin >> t; n   while (t--) { n     int n, m; n     cin >> n >> m; n     vector<vector<ll>> a(n + 1, vector<ll>(m + 1)); n     for (int i = 1; i <= n; ++i) { n       for (int j = 1; j <= m; ++j) { n         cin >> a[i][j]; n       } n     } n     const ll I = 1e18; n     ll b = I; n     for (int i = 1; i <= n; ++i) { n       for (int j = 1; j <= m; ++j) { n         vector<vector<ll>> c(n + 1, vector<ll>(m + 1, I)); n         c[0][1] = c[1][0] = 0; n         for (int g = 1; g <= n; ++g) { n           for (int h = 1; h <= m; ++h) { n             ll y = a[g][h] - (a[i][j] - (i - g) - (j - h)); n             if (y >= 0) { n               c[g][h] = min(c[g - 1][h] + y, c[g][h - 1] + y); n             } n           } n         } n         b = min(b, c[n][m]); n       } n     } n     cout << b << endl; n   } n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t, a1, a2, b1, b2, max1, max2; n   cin >> t; n   while (t > 0) { n     cin >> a1 >> b1; n     cin >> a2 >> b2; n     max1 = max(a1, b1); n     max2 = max(a2, b2); n     if (max1 == max2) { n       int min1, min2; n       min1 = min(a1, b1); n       min2 = min(a2, b2); n       if ((min1 + min2) == max1) { n         cout <<  Yes  << endl; n       } else { n         cout <<  No  << endl; n       } n     } else { n       cout <<  No  << endl; n     } n     t--; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1145; n int n, m, q, k; n bitset<N> a[51], f, nw, tp, s[N]; n unordered_map<bitset<N>, int> mn; n int main() { n   scanf( %d%d%d , &n, &m, &q); n   for (int i = 1, x, y; i <= m; i++) { n     scanf( %d , &x); n     while (x--) scanf( %d , &y), a[i][y] = 1; n   } n   k = min(20, m); n   for (int i = 0; i < 1 << k; i++) { n     f.reset(); n     for (int j = 1; j <= k; j++) n       if (i & (1 << (j - 1))) f ^= a[j]; n     int ct = __builtin_popcount(i); n     if (!mn.count(f) || mn[f] > ct) mn[f] = ct; n   } n   for (int i = 0; i < 1 << (m - k); i++) n     for (int j = 1; j <= (m - k); j++) n       if (i & (1 << (j - 1))) s[i] ^= a[k + j]; n   while (q--) { n     int x, y; n     scanf( %d , &x); n     nw.reset(); n     int as = 1e7; n     if (x == 0) { n       puts( 0 ); n       continue; n     } n     while (x--) scanf( %d , &y), nw[y] = 1; n     for (int i = 0; i < 1 << (m - k); i++) { n       int ct = __builtin_popcount(i); n       tp = nw ^ s[i]; n       if (mn[tp]) as = min(as, mn[tp] + ct); n     } n     if (as == 1e7) n       puts( -1 ); n     else n       printf( %d n , as); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m; n   scanf( %d %d , &n, &m); n   char s[n][m]; n   int a[n][m]; n   int x = clock(); n   char ch; n   scanf( %c , &ch); n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       s[i][j] = getchar(); n     } n     char ch; n     scanf( %c , &ch); n     int last_zero = m; n     for (int j = m - 1; j >= 0; j--) { n       if (s[i][j] ==  0 ) { n         last_zero = j; n       } n       a[i][j] = last_zero; n     } n   } n   int szs[m + 1]; n   int final_ans = 0; n   for (int lhs = 0; lhs < m; lhs++) { n     memset(szs, 0, sizeof szs); n     for (int i = 0; i < n; i++) { n       if (s[i][lhs] ==  1 ) { n         int sz = a[i][lhs] - lhs; n         szs[sz]++; n       } n     } n     int v = m * szs[m]; n     int cur_ans = v; n     int sum_szs_prevs = szs[m]; n     for (int i = m - 1; i >= 1; i--) { n       v = v - sum_szs_prevs + (i * szs[i]); n       cur_ans = max(cur_ans, v); n       sum_szs_prevs += szs[i]; n     } n     final_ans = max(cur_ans, final_ans); n   } n   printf( %d , final_ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n void chkmin(T &a, T b) { n   a = min(a, b); n } n template <typename T> n void chkmax(T &a, T b) { n   a = max(a, b); n } n inline int fread(void) { n   int ret = 0, op = 1; n   char ch = getchar(); n   for (; !isdigit(ch); ch = getchar()) n     if (ch ==  - ) op = -1; n   for (; isdigit(ch); ch = getchar()) ret = (ret << 1) + (ret << 3) -  0  + ch; n   return ret * op; n } n const int MAXN = 4e5 + 10; n const int MAXM = +10; n int n, m; n struct Tuple { n   int val, lm, rm, lp, rp, lt, rt; n   Tuple operator+(const Tuple &b) { n     Tuple ret; n     ret.val = max(max(val, b.val), max(rp + b.lm, rm + b.lp)); n     ret.lp = max(lp, max(lt + rt + b.lm, rt - lt + b.lp)); n     ret.rp = max(b.rp, max(b.lt + b.rt + rm, b.lt - b.rt + rp)); n     ret.lm = max(lm, b.lm - rt + lt); n     ret.rm = max(b.rm, rm - b.lt + b.rt); n     if (lt > b.rt) n       ret.lt = lt + b.lt - b.rt, ret.rt = rt; n     else n       ret.rt = b.rt - lt + rt, ret.lt = b.lt; n     return ret; n   } n } t[MAXN << 2]; n int a[MAXN], mx; n void build(int x, int l, int r) { n   if (l == r) { n     t[x].lp = t[x].rp = 1; n     t[x].lm = max(a[l], 0), t[x].rm = max(-a[l], 0); n     t[x].lt = (a[l] == 1), t[x].rt = (a[l] == -1); n     t[x].val = 1; n     return; n   } n   build((x << 1), l, ((l + r) >> 1)); n   build((x << 1 | 1), ((l + r) >> 1) + 1, r); n   t[x] = t[(x << 1)] + t[(x << 1 | 1)]; n } n void modify(int x, int l, int r, int pos, int tp) { n   if (l > r) return; n   if (l == r) { n     t[x].lp = t[x].rp = 1; n     t[x].lm = max(tp, 0), t[x].rm = max(-tp, 0); n     t[x].lt = (tp == 1), t[x].rt = (tp == -1); n     t[x].val = 1; n     return; n   } n   if (pos <= ((l + r) >> 1)) n     modify((x << 1), l, ((l + r) >> 1), pos, tp); n   else n     modify((x << 1 | 1), ((l + r) >> 1) + 1, r, pos, tp); n   t[x] = t[(x << 1)] + t[(x << 1 | 1)]; n } n inline void init(void) { n   scanf( %d%d , &n, &m); n   char ch; n   mx = 2 * n - 2; n   for (int i = 1; i <= mx; ++i) { n     cin >> ch; n     if (ch ==  ( ) n       a[i] = 1; n     else n       a[i] = -1; n   } n   build(1, 1, mx); n } n inline void work(void) { n   int x, y; n   printf( %d n , t[1].val); n   for (int i = 1; i <= m; ++i) { n     scanf( %d%d , &x, &y); n     modify(1, 1, mx, x, a[y]); n     modify(1, 1, mx, y, a[x]); n     swap(a[x], a[y]); n     printf( %d n , t[1].val); n   } n } n int main() { n   init(); n   work(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int v[200005]; n bool inQ[200005]; n vector<pair<int, int> > foo; n int main() { n   int n, k, q, p, m, i, j; n   bool ok; n   pair<int, int> x; n   cin >> n >> k >> m; n   for (i = 1; i <= n; ++i) cin >> v[i]; n   priority_queue<pair<int, int> > pq; n   for (j = 0; j < m; ++j) { n     cin >> q >> p; n     if (q == 1) { n       if (!inQ[p]) { n         pq.push({v[p], p}); n         inQ[p] = 1; n       } n     } else { n       if (!inQ[p]) n         ok = 0; n       else { n         ok = i = 0; n         while (!pq.empty() && i < k) { n           x = pq.top(); n           pq.pop(); n           foo.push_back(x); n           if (x.second == p) { n             ok = true; n             break; n           } n           ++i; n         } n         while (!foo.empty()) { n           pq.push(foo.back()); n           foo.pop_back(); n         } n       } n       if (ok == true) n         cout <<  YES n ; n       else n         cout <<  NO n ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, ans; n int r, c; n char mp[201][201]; n int ma[201][201]; n int mac[201][201]; n int main() { n   scanf( %d%d , &n, &m); n   for (int i = 0; i < n; i++) { n     char s[101]; n     scanf( %s , &s); n     for (int j = 0; j < n; j++) { n       mp[i][j] = s[j]; n     } n     getchar(); n   } n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < n; j++) { n       if (mp[i][j] ==  # ) continue; n       int flg1 = 0, flg2 = 0; n       for (int kk = 0; kk < m; kk++) { n         if (mp[i][j + kk] !=  . ) flg2 = 1; n         if (mp[i + kk][j] !=  . ) flg1 = 1; n       } n       if (flg2 == 0) { n         for (int kk = 0; kk < m; kk++) { n           if (kk + j < n) ma[i][j + kk]++; n           if (ma[i][j + kk] > ans) { n             ans = ma[i][j + kk]; n             r = i; n             c = j + kk; n           } n         } n       } n       if (flg1 == 0) { n         for (int kk = 0; kk < m; kk++) { n           if (i + kk < n) ma[i + kk][j]++; n           if (ma[i + kk][j] > ans) { n             ans = ma[i + kk][j]; n             r = i + kk; n             c = j; n           } n         } n       } n     } n   } n   printf( %d %d , r + 1, c + 1); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e6 + 10; n int mx[N << 2], lz[N << 2], sum[N << 2], a[N], b[N]; n void pushup(int rt) { mx[rt] = max(mx[(rt << 1)], mx[(rt << 1 | 1)]); } n void pushdown(int rt) { n   if (lz[rt]) { n     lz[(rt << 1)] += lz[rt]; n     lz[(rt << 1 | 1)] += lz[rt]; n     mx[(rt << 1)] += lz[rt]; n     mx[(rt << 1 | 1)] += lz[rt]; n     lz[rt] = 0; n   } n } n void up(int L, int R, int val, int l = 1, int r = 1000000, int rt = 1) { n   if (L <= l && R >= r) { n     mx[rt] += val; n     lz[rt] += val; n   } else { n     pushdown(rt); n     if (((l + r) >> 1) >= L) up(L, R, val, l, ((l + r) >> 1), (rt << 1)); n     if (((l + r) >> 1) + 1 <= R) n       up(L, R, val, ((l + r) >> 1) + 1, r, (rt << 1 | 1)); n     pushup(rt); n   } n } n int f(int l = 1, int r = 1000000, int rt = 1) { n   if (l == r) return l; n   pushdown(rt); n   if (mx[(rt << 1 | 1)] > 0) n     return f(((l + r) >> 1) + 1, r, (rt << 1 | 1)); n   else n     return f(l, ((l + r) >> 1), (rt << 1)); n } n int main() { n   int n, m, q; n   scanf( %d %d , &n, &m); n   for (int i = 1; i <= n; i++) scanf( %d , &a[i]), up(1, a[i], 1); n   for (int i = 1; i <= m; i++) scanf( %d , &b[i]), up(1, b[i], -1); n   scanf( %d , &q); n   while (q--) { n     int x, i, j; n     scanf( %d %d %d , &x, &i, &j); n     if (x == 1) n       up(1, a[i], -1), up(1, j, 1), a[i] = j; n     else n       up(1, b[i], 1), up(1, j, -1), b[i] = j; n     printf( %d n , mx[1] > 0 ? f() : -1); n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 2000003; n char s[maxn], t[maxn], tt[maxn]; n int kmp[maxn]; n int main() { n   int T; n   scanf( %d , &T); n   while (T--) { n     scanf( %s , s + 1); n     int n = strlen(s + 1), p, len = 0; n     for (p = 1; p <= n / 2 && s[p] == s[n - p + 1]; p++) n       ; n     if (p > n / 2) { n       puts(s + 1); n       continue; n     } n     for (int i = p; i <= n - p + 1; i++) t[++len] = s[i]; n     for (int i = 1; i <= len; i++) t[i + len] = t[i]; n     reverse(t + len + 1, t + len * 2 + 1); n     len *= 2; n     int pos = 0; n     for (int i = 2; i <= len; i++) { n       while (pos && t[pos + 1] != t[i]) pos = kmp[pos]; n       if (t[pos + 1] == t[i]) pos++; n       kmp[i] = pos; n     } n     int tmp = kmp[len]; n     while (tmp > len / 2) tmp = kmp[tmp]; n     int ANS1 = (p - 1) * 2 + tmp; n     for (int i = 1; i <= len; i++) tt[i] = t[i], kmp[i] = 0; n     len = 0; n     for (int i = n - p + 1; i >= p; i--) t[++len] = s[i]; n     for (int i = 1; i <= len; i++) t[i + len] = t[i]; n     reverse(t + len + 1, t + len * 2 + 1); n     len *= 2; n     pos = 0; n     for (int i = 2; i <= len; i++) { n       while (pos && t[pos + 1] != t[i]) pos = kmp[pos]; n       if (t[pos + 1] == t[i]) pos++; n       kmp[i] = pos; n     } n     tmp = kmp[len]; n     while (tmp > len / 2) tmp = kmp[tmp]; n     int ANS2 = (p - 1) * 2 + tmp; n     for (int i = 1; i <= len; i++) kmp[i] = 0; n     for (int i = 1; i < p; i++) putchar(s[i]); n     if (ANS1 > ANS2) n       for (int i = 1; i <= ANS1 - (p - 1) * 2; i++) putchar(tt[i]); n     else n       for (int i = 1; i <= ANS2 - (p - 1) * 2; i++) putchar(t[i]); n     for (int i = p - 1; i >= 1; i--) putchar(s[i]); n     putchar(  n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t, n, i; n   string a, b; n   cin >> t; n   while (t--) { n     vector<int> k; n     cin >> n >> a >> b; n     for (i = 0; i < n; i++) { n       if (a[i] != b[i]) { n         k.push_back(i + 1); n         k.push_back(1); n         k.push_back(i + 1); n       } n     } n     cout << k.size() <<    ; n     for (auto x : k) cout << x <<    ; n   } n } n


#include <cassert> n #include <climits> n #include <cstdio> n #include <cstdlib> n #include <cstring> n #include <cmath> n #include <cctype> n #include <vector> n #include <string> n #include <queue> n #include <deque> n #include <stack> n #include <set> n #include <map> n #include <utility> n #include <algorithm> n #include <iostream> n #include <sstream> n #include <numeric> n using namespace std; n  n #define SIZE(x) int((x).size()) n #define REP(i,c) for(auto &i : c) n #define pb push_back n #define eb emplace_back n typedef long long i64; n typedef unsigned long long u64; n const double EPS = 1e-12; n const int INF = 999999999; n typedef vector<int> VI; n typedef vector<string> VS; n typedef pair<int,int> PII; n typedef vector<PII> VPII; n  n const int MAXN=1500; n  n int n,m; n int a[MAXN][MAXN]; n int f[MAXN][MAXN]; n  n VPII row[MAXN]; // colors in a[i][j .. n] n VPII col[2][MAXN]; // colors in a[i..n][j] n  n  // colors in square (i,j) ... (i+f[i]][j]-1, j+f[i][j-1]), order max(x-i,y-i) n VPII sq[2][MAXN]; n int cur; n  n bool seen[MAXN*MAXN+1]; n  n struct Fenwick { n     int n; n     VI f; n  n     Fenwick(int n) : n(n)  { n         f=VI(n+1,0); n     } n  n     inline int LowBit(int x) { n         return x&(-x); n     } n  n     void Update(int i,int x) { n         while(i>0) { n             f[i]+=x; n             i-=LowBit(i); n         } n     } n  n     int Get(int i) { n         int r=0; n         while(i<=n) { n             r+=f[i]; n             i+=LowBit(i); n         } n         return r; n     } n }; n  n void Dbg(const VPII& v) { n     REP(p,v) printf( (%d %d)  ,p.first,p.second);printf(  n ); n } n  n void Bf() { n     for(int i=0;i<n;i++) { n         for(int j=0;j<n;j++) { n             int k; n             set<int> s; n             for(k=1;;k++) { n                 if(i+k>n || j+k>n) break; n                 for(int x=i;x<i+k;x++) n                     for(int y=j;y<j+k;y++) s.insert(a[x][y]); n                 if(SIZE(s)>m) break; n             } n             k--; n             if(k!=f[i][j]) printf( Wrong %d %d: %d %d n ,i,j,k,f[i][j]); n         } n     } n } n  n void Solve() { n     scanf( %d%d ,&n,&m); n     for(int i=0;i<n;i++) n         for(int j=0;j<n;j++) { n             scanf( %d ,&a[i][j]); n         } n  n     cur=0; n     for(int i=n-1;i>=0;i--) { n         int pre=cur; n         cur=cur^1; n         for(int j=n-1;j>=0;j--) { n             row[j]={{0,a[i][j]}}; n             col[cur][j]={{0,a[i][j]}}; n             sq[cur][j]={{0,a[i][j]}}; n             if(i==n-1 || j==n-1) { n                 f[i][j]=1; n                 continue; n             } n  n             REP(p,row[j+1]) { n                 if(p.second==a[i][j]) continue; n                 row[j].eb(p.first+1,p.second); n                 if(SIZE(row[j])>m) break; n             } n             // printf( Row %d %d n ,i,j);Dbg(row[j]); n  n             REP(p,col[pre][j]) { n                 if(p.second==a[i][j]) continue; n                 col[cur][j].eb(p.first+1,p.second); n                 if(SIZE(col[cur][j])>m) break; n             } n             // printf( Col %d %d n ,i,j);Dbg(col[cur][j]); n  n             seen[a[i][j]]=1; n             VI ps={0,0,0}; n             vector<const VPII*> vs={&row[j+1],&col[pre][j],&sq[pre][j+1]}; n             while(SIZE(sq[cur][j])<=m) { n                 int md=INF; n                 int mi=-1; n                 for(int i=0;i<3;i++) { n                     const VPII& v=*vs[i]; n                     if(ps[i]==SIZE(v)) continue; n                     if(v[ps[i]].first<md) { n                         md=v[ps[i]].first; n                         mi=i; n                     } n                 } n                 if(mi<0) break; n                 const PII &u=(*vs[mi])[ps[mi]++]; n                 if(!seen[u.second]) { n                     seen[u.second]=1; n                     sq[cur][j].eb(u.first+1,u.second); n                 } n             } n             REP(p,sq[cur][j]) seen[p.second]=0; n             // printf( Sq %d %d n ,i,j);Dbg(sq[cur][j]); n  n             f[i][j]=min(n-i,n-j); n             if(SIZE(sq[cur][j])>m) f[i][j]=min(f[i][j],sq[cur][j][m].first); n             // printf( %d %d: %d n ,i,j,f[i][j]); n         } n     } n  n     // Bf(); n  n     Fenwick ans(n); n     for(int i=0;i<n;i++) n         for(int j=0;j<n;j++) ans.Update(f[i][j],1); n     for(int i=1;i<=n;i++) printf( %d n ,ans.Get(i)); n  n } n  n int main() { n     Solve(); n  n     return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n using ld = long double; n const int maxn = 1e6 + 2; n const int base = 31; n const int mod = 1e9 + 7; n ll t; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(nullptr); n   cout.tie(nullptr); n   cin >> t; n   while (t--) { n     ll n, x = 0; n     cin >> n; n     vector<ll> a(n); n     for (ll i = 0; i < n; i++) { n       cin >> a[i]; n       x ^= a[i]; n     } n     if (x == 0) n       cout <<  DRAW n ; n     else { n       ll bit = 30; n       while (!(x & (1 << bit))) { n         --bit; n       } n       ll k0 = 0, k1 = 0; n       for (auto k : a) { n         if (k & (1 << bit)) { n           k1++; n         } else n           k0++; n       } n       assert(k1 % 2 == 1); n       if (k0 % 2 == 0 && k1 % 4 == 3) { n         cout <<  LOSE  <<   n ; n       } else n         cout <<  WIN  <<   n ; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int pi[200015]; n void PreKMP(char *P, int n) { n   int q, k = 0; n   pi[1] = 0; n   for (q = 2; q <= n; pi[q++] = k) { n     while (k && (P[k] != P[q - 1])) k = pi[k]; n     if (P[k] == P[q - 1]) k++; n   } n } n int KMP(char *T, int n, char *P, int m) { n   int i, q = 0; n   PreKMP(P, m); n   for (i = 1; i <= n; i++) { n     while ((q > 0) && (P[q] != T[i - 1])) q = pi[q]; n     if (P[q] == T[i - 1]) q++; n     if (q == m) return m; n   } n   return q; n } n char a[200015]; n char b[200015]; n char c[200015]; n char cadab[200015]; n char cadac[200015]; n char cadba[200015]; n char cadbc[200015]; n char cadca[200015]; n char cadcb[200015]; n int main() { n   while (scanf( %s%s%s , a, b, c) != EOF) { n     int sa = strlen(a); n     int sb = strlen(b); n     int sc = strlen(c); n     PreKMP(a, sa); n     int ab = KMP(a, sa, b, sb); n     int ac = KMP(a, sa, c, sc); n     PreKMP(b, sb); n     int ba = KMP(b, sb, a, sa); n     int bc = KMP(b, sb, c, sc); n     PreKMP(c, sc); n     int ca = KMP(c, sc, a, sa); n     int cb = KMP(c, sc, b, sb); n     int minn = sa + sb + sc; n     minn = min(minn, sa + (sb - ab) + (sc - bc)); n     minn = min(minn, sa + (sc - ac) + (sb - cb)); n     minn = min(minn, sb + (sa - ba) + (sc - ac)); n     minn = min(minn, sb + (sc - bc) + (sa - ca)); n     minn = min(minn, sc + (sa - ca) + (sb - ab)); n     minn = min(minn, sc + (sb - cb) + (sa - ba)); n     int sab = 0; n     int sac = 0; n     int sba = 0; n     int sbc = 0; n     int sca = 0; n     int scb = 0; n     for (int i = 0; i < sa; i++) { n       cadab[sab++] = a[i]; n       cadac[sac++] = a[i]; n     } n     for (int i = 0; i < sb; i++) { n       cadba[sba++] = b[i]; n       cadbc[sbc++] = b[i]; n     } n     for (int i = 0; i < sc; i++) { n       cadca[sca++] = c[i]; n       cadcb[scb++] = c[i]; n     } n     for (int i = ab; i < sb; i++) { n       cadab[sab++] = b[i]; n     } n     for (int i = ac; i < sc; i++) { n       cadac[sac++] = c[i]; n     } n     for (int i = ba; i < sa; i++) { n       cadba[sba++] = a[i]; n     } n     for (int i = bc; i < sc; i++) { n       cadbc[sbc++] = c[i]; n     } n     for (int i = ca; i < sa; i++) { n       cadca[sca++] = a[i]; n     } n     for (int i = ac; i < sc; i++) { n       cadcb[scb++] = b[i]; n     } n     if (KMP(cadab, sab, c, sc) == sc) minn = min(minn, sab); n     if (KMP(cadac, sac, b, sb) == sb) minn = min(minn, sac); n     if (KMP(cadba, sba, c, sc) == sc) minn = min(minn, sba); n     if (KMP(cadbc, sbc, a, sa) == sa) minn = min(minn, sbc); n     if (KMP(cadca, sca, b, sb) == sb) minn = min(minn, sca); n     if (KMP(cadcb, scb, a, sa) == sa) minn = min(minn, scb); n     printf( %d n , minn); n   } n } n


#include <bits/stdc++.h> n using namespace std; n const double pi = acos(-1.0); n const int inf = 10000000; n int arr[100005]; n map<int, int> mm; n int main() { n   int n, k; n   cin >> n >> k; n   for (int i = 0; i < (n); i++) { n     cin >> arr[i]; n     mm[arr[i]] = 1; n   } n   sort(arr, arr + n); n   int ans = 0; n   for (int i = n - 1; i >= 0; i--) { n     if (mm[arr[i]] == 0) continue; n     if (arr[i] % k != 0) { n       ans++; n       continue; n     } n     if (mm.find(arr[i] / k) != mm.end()) mm[arr[i] / k] = 0; n     ans++; n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int a[5] = {}, x, y = 0; n   cin >> a[0] >> a[1] >> a[2]; n   for (int d = 0; d < 3; d++) { n     for (int c = 0; c < 3; c++) { n       if (a[d] > a[c]) swap(a[d], a[c]); n     } n   } n   x = a[1]; n   if (a[0] > x) y += a[0] - x; n   if (a[0] < x) y += x - a[0]; n   if (a[2] > x) y += a[2] - x; n   if (a[2] < x) y += x - a[2]; n   cout << y; n   return 0; n } n


#include <bits/stdc++.h> n const long long inf = 0x3f3f3f3f3f3f3f3LL; n const long long mod = (long long)1e9 + 7; n using namespace std; n template <class T> n void smin(T& a, T val) { n   if (a > val) a = val; n } n template <class T> n void smax(T& a, T val) { n   if (a < val) a = val; n } n const long long N = 100 + 5; n long long dp[N][N][N][2]; n vector<long long> prefix_function(string s) { n   long long n = (long long)s.length(); n   vector<long long> pi(n); n   for (long long i = 1; i < n; i++) { n     long long 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 string s, t, pat; n vector<long long> pi; n long long solve(long long idx1, long long idx2, long long idx3, n                 long long ongoing) { n   if (idx3 == (long long)(pat.size())) { n     return -inf; n   } n   if (idx1 == (long long)(s.size()) or idx2 == (long long)(t.size())) { n     return 0; n   } n   long long& ans = dp[idx1][idx2][idx3][ongoing]; n   if (~ans) return ans; n   ans = 0; n   if (!ongoing) { n     smax(ans, solve(idx1 + 1, idx2, idx3, 0)); n     smax(ans, solve(idx1, idx2 + 1, idx3, 0)); n   } n   if (s[idx1] == t[idx2]) { n     if (s[idx1] == pat[idx3]) { n       smax(ans, 1 + solve(idx1 + 1, idx2 + 1, idx3 + 1, 0)); n     } else { n       if (idx3 == 0) { n         smax(ans, 1 + solve(idx1 + 1, idx2 + 1, 0, 0)); n       } else { n         smax(ans, solve(idx1, idx2, pi[idx3 - 1], 1)); n       } n     } n   } n   return ans; n } n string vals =   ; n void path(long long idx1, long long idx2, long long idx3, long long ongoing) { n   if (idx1 == (long long)(s.size()) or idx2 == (long long)(t.size())) { n     return; n   } n   long long ans = solve(idx1, idx2, idx3, ongoing); n   if (!ongoing) { n     if (ans == solve(idx1 + 1, idx2, idx3, 0)) { n       path(idx1 + 1, idx2, idx3, 0); n       return; n     } else if (ans == solve(idx1, idx2 + 1, idx3, 0)) { n       path(idx1, idx2 + 1, idx3, 0); n       return; n     } n   } n   if (s[idx1] == t[idx2]) { n     if (s[idx1] == pat[idx3]) { n       vals += s[idx1]; n       path(idx1 + 1, idx2 + 1, idx3 + 1, 0); n     } else { n       if (idx3 == 0) { n         vals += s[idx1]; n         path(idx1 + 1, idx2 + 1, 0, 0); n       } else { n         path(idx1, idx2, pi[idx3 - 1], 1); n       } n     } n   } n } n int32_t main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   cin >> s >> t >> pat; n   memset(dp, -1, sizeof dp); n   pi = prefix_function(pat); n   solve(0, 0, 0, 0); n   path(0, 0, 0, 0); n   if ((long long)(vals.size()) == 0) { n     cout << 0; n     exit(0); n   } n   cout << vals; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   string s; n   cin >> s; n   int n = s.length(); n   vector<int> v; n   for (int i = 0; i < n; i++) n     if (i == n - 1 || s[i] != s[i + 1]) v.push_back(i); n   if (s.back() ==  b ) v.pop_back(); n   vector<int> res(n); n   for (int p : v) res[p] = 1; n   for (int id : res) cout << id <<    ; n   cout <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false), cout.tie(0), cin.tie(0); n   int n; n   cin >> n; n   if (n <= 3) { n     cout << 0 <<   n ; n     return 0; n   } n   int Max = -1, k; n   for (int i = 2; i < n; ++i) { n     int tp = n / i * (i - 1); n     if (n % i >= 1) tp += n % i - 1; n     tp -= i - 1; n     if (tp > Max) Max = tp, k = i; n   } n   set<int> Se; n   vector<int> SS(n); n   int a = n / k, ps = 0; n   for (int i = 0; i < a; ++i) { n     for (int j = 0; j < k; ++j) { n       if (j == k - 1) n         ps++; n       else n         Se.insert(ps++); n     } n   } n   for (; ps < n - 1; ++ps) Se.insert(ps); n   for (int i : Se) SS[i] = 1; n   bool ok = 0; n   while (!ok) { n     vector<int> A; n     for (int i = 0; i < k; ++i) n       if (((int)(Se).size())) { n         A.push_back(*Se.begin()); n         Se.erase(Se.begin()); n       } n     if (((int)(Se).size()) == 0) ok = 1; n     cout << ((int)(A).size()) <<    ; n     for (int i : A) cout << i + 1 <<    ; n     cout << endl; n     cout.flush(); n     int l; n     cin >> l; n     --l; n     for (int i = 0; i < k; ++i) { n       if (SS[(i + l) % n]) Se.insert((i + l) % n); n     } n     if (ok) { n       cout << 0 << endl; n       cout.flush(); n     } n   } n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n const long long somod = 1e9 + 7; n const long long maxn = 5e4 + 7; n long long cntnode = 1, m, n, a[maxn]; n vector<long long> vt[maxn * 31]; n long long cac[32][2]; n map<long long, vector<long long>> mp; n long long Pow(long long a, long long b) { n   long long ans = 1; n   for (; b > 0; b >>= 1, a = a * a % somod) { n     if (b & 1) ans = ans * a % somod; n   } n   return ans; n } n void Update(long long x, long long delta) { n   for (long long i = 29; i >= 0; i--) { n     cac[i][(x >> i & 1)] += delta; n   } n } n long long Cal(long long x) { n   long long ans = 0; n   for (long long i = 29; i >= 0; i--) { n     ans += cac[i][(x >> i & 1) ^ 1] * (1 << i); n     ans %= somod; n   } n   return ans; n } n pair<long long, long long> Count(long long curval, long long lastbit) { n   mp.clear(); n   long long f = 0, s = 0; n   for (long long i = 1; i <= n; i++) { n     long long val = 0; n     for (long long j = 29; j >= lastbit; j--) { n       val ^= (a[i] & (1 << j)); n     } n     mp[val].push_back(a[i]); n   } n   for (auto i : mp) { n     long long yay = i.first ^ curval; n     if (mp.count(yay) == 0) continue; n     s += mp[yay].size() * i.second.size(); n     for (auto j : i.second) Update(j, 1); n     for (auto j : mp[yay]) f = f + Cal(j); n     f %= somod; n     for (auto j : i.second) Update(j, -1); n   } n   s /= 2; n   f = f * Pow(2, somod - 2) % somod; n   return {f, s}; n } n int32_t main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   if (fopen( test.inp ,  r )) freopen( test.inp ,  r , stdin); n   cin >> n >> m; n   for (long long i = 1; i <= n; i++) { n     cin >> a[i]; n   } n   long long val = 0, ans = 0; n   for (long long i = 29; i >= 0; i--) { n     pair<long long, long long> cc = Count(val ^ (1 << i), i); n     if (cc.second <= m) { n       m -= cc.second, ans += cc.first; n     } else { n       val ^= (1 << i); n     } n     if (i == 0) { n       ans += (val)*m; n     } n   } n   cout << ans % somod <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 10; n int a[N], f[N]; n int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } n int main() { n   int T; n   cin >> T; n   while (T--) { n     int n, k; n     scanf( %d , &n); n     memset(a, 0, sizeof a); n     for (int i = 1; i <= n; i++) f[i] = 1; n     for (int i = 1; i <= n; i++) scanf( %d , &a[i]); n     for (int i = 1; i <= n; i++) n       for (int j = 2 * i; j <= n; j += i) n         if (a[i] < a[j]) f[j] = max(f[j], f[i] + 1); n     int res = 0; n     for (int i = 1; i <= n; i++) res = max(res, f[i]); n     printf( %d n , res); 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 N = 200005; n long long fasmul(long long a, long long b) { n   long long res = 1; n   while (b) { n     if (b & 1) res = (res * a) % mod; n     a = (a * a) % mod; n     b = b / 2; n   } n   return res; n } n void solve() { n   long long n; n   char c; n   string s; n   cin >> n >> c >> s; n   long long d = n / 2; n   long long ok = 1; n   for (long long i = 0; i < n; i++) n     if (s[i] != c) ok = 0; n   if (ok) { n     cout << 0 <<   n ; n     return; n   } n   for (long long i = d; i < n; i++) { n     if (s[i] == c) { n       cout << 1 <<   n ; n       cout << i + 1 <<   n ; n       return; n     } n   } n   cout << 2 <<   n ; n   cout << n <<     << n - 1 <<   n ; n } n int32_t main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   ; n   long long t = 1; n   cin >> t; n   while (t--) { n     solve(); n   } n } n


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


#include <bits/stdc++.h> n using namespace std; n const int INF = (1 << 30); n const double eps = 1e-9; n const int mod = 1000000007; n const int MAXN = int(1e5) + 100; n const int dx[] = {-1, +1, 0, 0}; n const int dy[] = {0, 0, -1, +1}; n int main() { n   ios::sync_with_stdio(false); n   int n; n   cin >> n; n   vector<int> arr(n); n   for (int i = (0); i < int(n); ++i) { n     cin >> arr[i]; n   } n   sort((arr).begin(), (arr).end()); n   for (int i = (1); i < int(n); ++i) { n     int x = arr[i - 1]; n     int y = arr[i]; n     if (x == y) continue; n     if (y < x * 2) { n       cout <<  YES  << endl; n       return 0; n     } n   } n   cout <<  NO  << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long MOD = 1e9 + 7; n int n; n vector<int> dig; n long long cnt[15]; n long long C[25][25]; n struct cond { n   int sum; n   int a[20]; n   string s; n   cond() { n     for (int i = 0; i < 20; i++) { n       a[i] = 0; n     } n     s =   ; n     sum = 0; n   } n }; n void calculateC() { n   for (int i = 0; i <= 20; i++) n     for (int j = 0; j <= 20; j++) C[i][j] = 0; n   for (int i = 0; i < 20; i++) C[i][0] = 1; n   for (int i = 1; i <= 20; i++) n     for (int j = 1; j <= 20; j++) n       C[i][j] = n           ((C[i][j] % MOD) + ((C[i - 1][j] + C[i - 1][j - 1]) % MOD)) % MOD; n } n long long C2(int n, int k) { n   if (n < 0 || k < 0 || k > n) return 0; n   long long ans = 1; n   for (int i = n; i > n - k; i--) ans = (ans * i) % MOD; n   return ans % MOD; n } n long long Power2(int n) { n   long long k = 1ll; n   for (int i = 1; i <= n; i++) k = (k * 2ll) % MOD; n   return k; n } n long long Power8(int n) { n   long long k = 1ll; n   for (int i = 1; i <= n; i++) k = (k * 8ll) % MOD; n   return k; n } n bool good(int n) { n   if (n == 4 || n == 7) return true; n   return false; n } n void findcnt(int pos, int sum) { n   if (pos == (int)dig.size()) return; n   int p = (int)dig.size() - pos; n   long long Q = (long long)dig[pos]; n   if (p == 1) { n     cnt[0]--; n     for (int i = 0; i <= Q; i++) n       if (good(i)) n         cnt[sum + 1]++; n       else n         cnt[sum]++; n     return; n   } n   for (int i = 0; i <= p - 1; i++) { n     for (int j = 0; j < Q; j++) { n       if (!good(j)) n         cnt[i + sum] += Power2(i) * C[p - 1][i] * Power8(p - 1 - i); n       else n         cnt[i + sum + 1] += Power2(i) * C[p - 1][i] * Power8(p - 1 - i); n     } n   } n   if (good(dig[pos])) n     findcnt(pos + 1, sum + 1); n   else n     findcnt(pos + 1, sum); n } n long long ans = 0; n vector<cond> allposib; n void BT(int pos, int sum, string s) { n   if (pos == 6) { n     cond A; n     for (int i = 0; i < (int)s.length(); i++) A.a[(int)s[i] - (int) 0 ]++; n     A.sum = sum; n     A.s = s; n     if (sum <= 10) allposib.push_back(A); n   } else n     for (int i = 0; i <= 10; i++) n       BT(pos + 1, sum + i, s + (char)(i + (int) 0 )); n } n int fac(int n) { n   int ans = 1; n   for (int i = 1; i <= n; i++) ans *= i; n   return ans; n } n int main() { n   calculateC(); n   for (int i = 0; i <= 10; i++) cnt[i] = 0; n   cin >> n; n   while (n) { n     dig.push_back(n % 10); n     n /= 10; n   } n   reverse((dig).begin(), (dig).end()); n   findcnt(0, 0); n   BT(0, 0,   ); n   long long ans = 0; n   for (int i = 0; i < (int)allposib.size(); i++) { n     int from = allposib[i].sum + 1; n     long long tmp = 1, posfor7 = 0; n     for (int j = 0; j <= 10; j++) { n       tmp = (tmp * (C2(cnt[j], allposib[i].a[j]))) % MOD; n     } n     for (int j = from; j <= 10; j++) posfor7 += cnt[j]; n     posfor7 %= MOD; n     tmp = (tmp * posfor7) % MOD; n     ans = (ans + tmp) % MOD; n   } n   cout << ans % MOD << endl; n   return 0; n } n


#include <bits/stdc++.h> n template <typename T> n inline void rd(T& x) { n   int si = 1; n   char c = getchar(); n   x = 0; n   while (!isdigit(c)) si = c ==  -  ? -1 : si, c = getchar(); n   while (isdigit(c)) x = x * 10 + c - 48, c = getchar(); n   x *= si; n } n template <typename T, typename... Args> n inline void rd(T& x, Args&... args) { n   rd(x); n   rd(args...); n } n const int kN = 4e5 + 5, kInf = 0x3f3f3f3f; n const long long kMod = 998244353, kInfLL = 0x3f3f3f3f3f3f3f3fLL; n long long QPow(long long a, long long b) { n   long long ans = 1, bas = a; n   for (; b; b >>= 1, bas = bas * bas % kMod) n     if (b & 1) ans = ans * bas % kMod; n   return ans; n } n struct Edge { n   int u, v, c; n } E[kN]; n int n, m, fa[kN], s[kN], col[kN], cnt[kN]; n std::vector<int> pt[2]; n bool flag = false; n int Find(int x) { return fa[x] == x ? x : fa[x] = Find(fa[x]); } n void Merge(int x, int y) { n   int fx = Find(x), fy = Find(y); n   if (fx == fy) return; n   s[fx] += s[fy]; n   fa[fy] = fx; n } n void Solve(int x) { n   memset(col, 0xff, sizeof(col)); n   for (int i = 1; i <= 2 * n; ++i) { n     fa[i] = i; n     s[i] = (i <= n); n   } n   for (int i = 1; i <= m; ++i) { n     int u = E[i].u, v = E[i].v, c = E[i].c ^ x; n     if (c) n       Merge(u, v), Merge(u + n, v + n); n     else n       Merge(u + n, v), Merge(u, v + n); n   } n   for (int i = 1; i <= n; ++i) n     if (Find(i) == Find(i + n)) return; n   flag = true; n   for (int i = 1; i <= n; ++i) n     if (col[Find(i)] == -1) { n       col[Find(i)] = (s[Find(i)] < s[Find(i + n)]); n       col[Find(i + n)] = !col[Find(i)]; n     } n   cnt[x] = 0; n   for (int i = 1; i <= n; ++i) n     if (col[Find(i)] == 1) { n       ++cnt[x]; n       pt[x].push_back(i); n     } n } n int main() { n   int T = 1; n   while (T--) { n     rd(n, m); n     cnt[0] = cnt[1] = kInf; n     for (int i = 1; i <= m; ++i) { n       char c[5]; n       rd(E[i].u, E[i].v); n       scanf( %s , c + 1); n       E[i].c = (c[1] ==  B ); n     } n     for (int i = 0; i < 2; ++i) Solve(i); n     if (flag) { n       if (cnt[0] < cnt[1]) { n         printf( %d n , cnt[0]); n         for (auto i : pt[0]) printf( %d  , i); n       } else { n         printf( %d n , cnt[1]); n         for (auto i : pt[1]) printf( %d  , i); n       } n     } else n       printf( -1 ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 100005; n int a[N], c[N], f[N], g[N], n, q, m, len, ans[N]; n map<int, int> mp; n inline void read(int &x) { n   char c = getchar(); n   x = 0; n   while (c >  9  || c <  0 ) c = getchar(); n   while (c >=  0  && c <=  9 ) { n     x = x * 10 + c -  0 ; n     c = getchar(); n   } n } n inline void write(int x) { n   if (x == 0) putchar( 0 ); n   int a[20]; n   a[0] = 0; n   while (x) { n     a[++a[0]] = x % 10; n     x /= 10; n   } n   while (a[0]) putchar(a[a[0]--] +  0 ); n   putchar(  n ); n } n struct data { n   int l, r, pos; n   bool operator<(const data &a) const { n     return l / m == a.l / m ? ((l / m) & 1 ? r > a.r : r < a.r) n                             : l / m < a.l / m; n   } n } b[N]; n inline void add(int x, int y) { n   if (f[x] >= m) n     mp.erase(x); n   else n     --g[f[x]]; n   f[x] += y; n   if (f[x] >= m) n     mp[x] = f[x]; n   else n     ++g[f[x]]; n } n int heap[N]; n inline void down(int x) { n   int y = x * 2; n   if (y > len) return; n   if (heap[y] > heap[y + 1] && y + 1 <= len) y = y + 1; n   if (heap[x] > heap[y]) { n     swap(heap[x], heap[y]); n     down(y); n   } n } n inline int work() { n   int ans = 0, pr = 0; n   len = 0; n   for (int i = 1; i < m; ++i) c[i] = g[i]; n   for (int i = 1; i < m; ++i) { n     if (!c[i]) continue; n     if (pr) { n       --c[i]; n       int p = pr + i; n       ans += p; n       if (p < m) n         ++c[p]; n       else n         heap[++len] = p; n       pr = 0; n     } n     if (c[i] % 2 == 1) pr = i; n     ans += i * 2 * (c[i] / 2); n     if (i * 2 < m) n       c[i * 2] += c[i] / 2; n     else { n       for (int j = 1; j <= c[i] / 2; ++j) heap[++len] = i * 2; n     } n   } n   if (pr != 0) heap[++len] = pr; n   map<int, int>::iterator it; n   for (it = mp.begin(); it != mp.end(); ++it) heap[++len] = it->second; n   for (int i = len / 2; i >= 1; --i) down(i); n   while (len != 1) { n     int p = heap[1]; n     heap[1] = heap[len]; n     --len; n     down(1); n     int q = heap[1]; n     ans += p + q; n     heap[1] += p; n     down(1); n   } n   return ans; n } n inline void change(int x, int y) { n   if (b[x].l > b[y].l) { n     for (int i = b[y].l; i < b[x].l; ++i) add(a[i], 1); n   } else { n     for (int i = b[x].l; i < b[y].l; ++i) add(a[i], -1); n   } n   if (b[x].r < b[y].r) { n     for (int i = b[x].r + 1; i <= b[y].r; ++i) add(a[i], 1); n   } else { n     for (int i = b[y].r + 1; i <= b[x].r; ++i) add(a[i], -1); n   } n } n int main() { n   read(n); n   for (int i = 1; i <= n; ++i) read(a[i]); n   read(q); n   for (int i = 1; i <= q; ++i) { n     read(b[i].l); n     read(b[i].r); n     b[i].pos = i; n   } n   m = (int)sqrt(n); n   sort(b + 1, b + 1 + q); n   g[0] = n; n   for (int i = b[1].l; i <= b[1].r; ++i) add(a[i], 1); n   for (int i = 1; i < q; ++i) { n     ans[b[i].pos] = work(); n     change(i, i + 1); n   } n   ans[b[q].pos] = work(); n   for (int i = 1; i <= q; ++i) write(ans[i]); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, i; n   cin >> n; n   string s; n   cin >> s; n   for (i = 0; i < s.length(); i++) { n     if (s[i] ==  0 ) break; n   } n   if (i == s.length()) n     cout << s.length(); n   else n     cout << i + 1; n   return 0; n } n