#include <bits/stdc++.h> n using namespace std; n inline void wait(double seconds) { n   double endtime = clock() + (seconds * CLOCKS_PER_SEC); n   while (clock() < endtime) { n     ; n   } n } n inline int fastIn() { n   register char c = 0; n   register int a = 0; n   while (c < 33) c = getchar(); n   while (c > 33) { n     a = (a * 10) + (c -  0 ); n     c = getchar(); n   } n   return a; n } n int tour_count; n int win_need; n int bag_cap; n const int mx = 210; n struct NODE { n   double p; n   double np; n   int w; n   NODE(int p = 0, int np = 0, int w = 0) : p(p), np(np), w(w) {} n   bool operator<(const NODE &r) const { return this->w > r.w; } n }; n NODE vi[mx]; n inline void read() { n   scanf( %d %d %d , &tour_count, &win_need, &bag_cap); n   for (int i = 0, j1 = tour_count; i < j1; ++i) { n     int tmp = fastIn(); n     vi[i].p = (double)tmp / (double)100; n     vi[i].np = (double)1 - vi[i].p; n   } n   for (int i = 0, j1 = tour_count; i < j1; ++i) { n     scanf( %d , &vi[i].w); n   } n } n struct data { n   bool f; n   double v; n   data(bool f = false, double v = 0) : f(f), v(v) { ; } n }; n double dp[200][200][201]; n bool vis[200][200][201]; n double go(int at, int win, int cap) { n   if (cap < 0) return (double)0; n   if (at >= tour_count) { n     return win >= win_need ? (double)1 : (double)0; n   } n   if (vis[at][win][cap]) return dp[at][win][cap]; n   vis[at][win][cap] = true; n   double v1 = vi[at].p * go(at + 1, win + 1, min(cap + vi[at].w, 200)); n   double v2 = vi[at].np * go(at + 1, win, cap); n   return dp[at][win][cap] = (v1 + v2); n } n inline void proc() { n   memset(vis, false, sizeof(vis)); n   sort(vi, vi + tour_count); n   double res = go(0, 0, bag_cap); n   printf( %.9lf n , res); n } n int main() { n   int kase = 1; n   for (int i = 0, j1 = kase; i < j1; ++i) { n     read(); n     proc(); n   } n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n int gcd(int x, int y) { n   if (x == 0) n     return y; n   else n     return gcd(y % x, x); n } n bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) { n   return (a.second < b.second); n } n bool sortbysize(string &s1, string &s2) { return s1.size() < s2.size(); } n bool sortinrev(const pair<int, int> &a, const pair<int, int> &b) { n   return (a.first > b.first); n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   ; n   int n, k, a, b, i, x, cnt = 0; n   cin >> n >> k; n   vector<pair<int, int>> v; n   map<int, int> mp; n   while (n--) { n     cin >> a >> b; n     v.push_back(make_pair(a, b)); n     mp[a]++; n   } n   sort(v.begin(), v.end(), sortinrev); n   for (i = 0; i < v.size();) { n     if (mp[v[i].first] > 1) { n       sort(v.begin() + i, v.begin() + i + mp[v[i].first], sortbysec); n     } n     i += mp[v[i].first]; n   } n   for (i = 0; i < v.size(); i++) { n     if (v[i].second == v[k - 1].second && v[i].first == v[k - 1].first) cnt++; n   } n   cout << cnt << endl; n   return 0; n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /STACK:102400000,102400000 ) n using namespace std; n const int inf = 1000000007; n const long long linf = 1LL << 62; n const unsigned long long ulinf = 1ULL << 63; n const double eps = 0.000001; n const double pi = 3.14159265358979323846; n template <class T> n T abs(T a) { n   return a >= 0 ? a : -a; n } n template <class T> n T sqr(T a) { n   return a * a; n } n template <class T> n T gcd(T a, T b) { n   return b ? gcd(b, a % b) : a; n } n template <class T> n T mod(T a, T b) { n   return (a % b + b) % b; n } n long long powmod(long long a, long long b, long long c) { n   if (b == 0LL) return 1LL; n   long long ret = powmod(a, b >> 1, c); n   ret = ret * ret % c; n   if (b & 1LL) ret = ret * a % c; n   return ret; n } n long long inv(long long a, long long b) { return powmod(a, b - 2LL, b); } n template <class T> n void maxe(T &a, T b) { n   if (a < b) a = b; n } n template <class T> n void mine(T &a, T b) { n   if (a > b) a = b; n } n int iszero(double a) { return abs(a) <= eps; } n template <class T> n void geti(T &a) { n   a = 0; n   T b = 1; n   char c = getchar(); n   if (c ==  - ) n     b = -1; n   else n     a = c - 48; n   while ((c = getchar()) !=     && c !=   n ) a = a * 10 + c - 48; n   a *= b; n } n void fileio_in_out() { n   freopen( .in ,  r , stdin); n   freopen( .out ,  w , stdout); n } n void fileio_txt() { n   freopen( input.txt ,  r , stdin); n   freopen( output.txt ,  w , stdout); n } n const int N = 222222; n const int M = 1111111; n const int K = 20; n int test; n int n, m, k, ans; n char s[11]; n int main() { n   scanf( %d , &test); n   while (test--) { n     vector<pair<int, int> > v; n     for (int i = 0; i < 8; i++) { n       scanf( %s , s); n       for (int j = 0; j < 8; j++) n         if (s[j] ==  K ) v.push_back(make_pair(i, j)); n     } n     ans = ((v[0].first - v[1].first) % 4 == 0) && n           ((v[0].second - v[1].second) % 4 == 0); n     puts(ans ?  YES  :  NO ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int i, j, k; n   int n; n   cin >> n; n   long arr[n][2]; n   for (i = 0; i < n; i++) cin >> arr[i][0] >> arr[i][1]; n   long long minx, miny, maxx, maxy; n   minx = arr[0][0]; n   miny = arr[0][1]; n   maxx = arr[0][0]; n   maxy = arr[0][1]; n   for (i = 0; i < n; i++) { n     if (minx > arr[i][0]) minx = arr[i][0]; n     if (miny > arr[i][1]) miny = arr[i][1]; n     if (maxx < arr[i][0]) maxx = arr[i][0]; n     if (maxy < arr[i][1]) maxy = arr[i][1]; n   } n   long long l1, l2; n   l1 = (maxx - minx); n   l2 = (maxy - miny); n   if (l1 > l2) n     cout << l1 * l1; n   else n     cout << l2 * l2; n } n


#include <bits/stdc++.h> n using namespace std; n void __print(long long x) { cerr << x; } n void __print(long x) { cerr << x; } n void __print(unsigned x) { cerr << x; } n void __print(unsigned long x) { cerr << x; } n void __print(unsigned long long x) { cerr << x; } n void __print(float x) { cerr << x; } n void __print(double x) { cerr << x; } n void __print(long double x) { cerr << x; } n void __print(char x) { cerr <<      << x <<     ; } n void __print(const char *x) { cerr <<     << x <<    ; } n void __print(const string &x) { cerr <<     << x <<    ; } n void __print(bool x) { cerr << (x ?  true  :  false ); } n template <typename T, typename V> n void __print(const pair<T, V> &x) { n   cerr <<  { ; n   __print(x.first); n   cerr <<  , ; n   __print(x.second); n   cerr <<  } ; n } n template <typename T> n void __print(const T &x) { n   long long f = 0; n   cerr <<  { ; n   for (auto &i : x) cerr << (f++ ?  ,  :   ), __print(i); n   cerr <<  } ; n } n void _print() { cerr <<  ] n ; } n template <typename T, typename... V> n void _print(T t, V... v) { n   __print(t); n   if (sizeof...(v)) cerr <<  ,  ; n   _print(v...); n } n const long long N = 2e5 + 4; n const long long mod = 1e9 + 7; n void solve() { n   long long n; n   cin >> n; n   string a, b; n   cin >> a >> b; n   long long ans = 0; n   for (long long i = 0; i < n / 2; i++) { n     if (a[i] == a[n - i - 1] and b[i] == b[n - i - 1]) continue; n     if (a[i] == b[i] and a[n - i - 1] == b[n - i - 1]) continue; n     if (a[i] == b[n - i - 1] and b[i] == a[n - i - 1]) continue; n     bool f = 0, f2 = 0; n     if (b[i] == b[n - i - 1]) { n       ans++; n       continue; n     } n     if (a[i] != b[i] and a[n - i - 1] != b[n - i - 1]) { n       f = 1; n     } n     if (a[i] != b[n - i - 1] and b[i] != a[n - i - 1]) { n       f2 = 1; n     } n     if (f and f2) { n       ans += 2; n     } else { n       ans++; n     } n   } n   if (a[n / 2] != b[n / 2] and n & 1) { n     ans++; n   } n   cout << ans; n } n int32_t main() { n   long long tt; n   tt = 1; n   for (long long t = 1; t <= tt; t++) { n     solve(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n const long long md = 1e9 + 7; n const long double eps = 1e-8; n struct frac { n   long long x, y; n   frac() {} n   frac(long long x, long long y) : x(x), y(y) {} n   bool operator==(const frac& ot) { return x * ot.y == y * ot.x; } n   bool operator<(const frac& ot) { return x * ot.y < y * ot.x; } n }; n vector<int> tr; n int sz = 1; n void add(int v, int val) { n   v += sz - 1; n   tr[v] += val; n   while (v) { n     v = (v - 1) >> 1; n     tr[v] += val; n   } n   return; n } n int get(int v, int l, int r, int bg, int en) { n   if (bg >= r || l >= en) { n     return 0; n   } n   if (l >= bg && r <= en) { n     return tr[v]; n   } n   int m = (l + r) >> 1; n   return get(2 * v + 1, l, m, bg, en) + get(2 * v + 2, m, r, bg, en); n } n int main() { n   iostream::sync_with_stdio(0); n   cin.tie(0), cout.tie(0); n   int n; n   long long w; n   cin >> n >> w; n   vector<long long> v(n), x(n); n   for (int i = 0; i < n; i++) { n     cin >> x[i] >> v[i]; n   } n   vector<frac> f1(n), f2(n); n   for (int i = 0; i < n; i++) { n     f1[i] = {-x[i], v[i] + w}; n     if (f1[i].y < 0) { n       f1[i].x = -f1[i].x; n       f1[i].y = -f1[i].y; n     } n     f2[i] = {-x[i], v[i] - w}; n     if (f2[i].y < 0) { n       f2[i].x = -f2[i].x; n       f2[i].y = -f2[i].y; n     } n   } n   vector<int> all(n); n   for (int i = 0; i < n; i++) { n     all[i] = i; n   } n   vector<int> F2(n); n   sort(all.begin(), all.end(), [&](int a, int b) { return f2[a] < f2[b]; }); n   F2[all[0]] = 0; n   for (int i = 1; i < n; i++) { n     F2[all[i]] = F2[all[i - 1]] + !(f2[all[i]] == f2[all[i - 1]]); n   } n   sort(all.begin(), all.end(), [&](int a, int b) { n     if (f1[a] < f1[b]) { n       return true; n     } n     if (f1[b] < f1[a]) { n       return false; n     } n     return F2[b] < F2[a]; n   }); n   while (sz < n) { n     sz <<= 1; n   } n   tr.resize(2 * sz - 1, 0); n   long long ans = 0; n   for (int i : all) { n     ans += get(0, 0, sz, F2[i], n); n     add(F2[i], 1); n   } n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m, c; n   cin >> n >> m >> c; n   vector<int> A(n), B(m); n   for (auto &a : A) cin >> a; n   for (auto &b : B) cin >> b; n   int i = 0, x = 0; n   for (int i = 0; i < n; ++i) { n     if (i < m) x = (x + B[i]) % c; n     if (i > n - m) x = (x - B[i - n + m - 1] + c) % c; n     A[i] = (A[i] + x) % c; n   } n   for (auto a : A) cout << a <<    ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 500010; n int n, m; n struct edge { n   int a, b, c, t; n } e[N]; n inline bool operator<(const edge &a, const edge &b) { return a.c < b.c; } n struct union_find { n   int f[N], h[N], sz[N], cnt; n   struct oper { n     int x, fx, hx, szx, tc; n   } op[N * 2]; n   int l; n   void init() { n     l = 0, cnt = n; n     for (int i = 1; i <= n; i++) f[i] = i, h[i] = 0, sz[i] = 1; n   } n   int find(int x) { return f[x] == x ? x : find(f[x]); } n   void rewind(int t) { n     for (int i = l; i >= t + 1; i--) { n       int x = op[i].x; n       f[x] = op[i].fx, h[x] = op[i].hx; n       sz[x] = op[i].szx; n       cnt = op[i].tc; n     } n     l = t; n   } n   void merge(int a, int b) { n     int fa = find(a), fb = find(b); n     if (fa != fb) { n       if (h[fa] > h[fb]) swap(fa, fb); n       op[++l] = (oper){fa, f[fa], h[fa], sz[fa], cnt}, n       op[++l] = (oper){fb, f[fb], h[fb], sz[fb], cnt}; n       if (sz[fa] && sz[fb]) cnt -= 2; n       f[fa] = fb; n       h[fb] = max(h[fb], h[fa] + 1); n       sz[fb] ^= sz[fa]; n     } n   } n } T; n int j = 1, ans[N]; n vector<int> ed[N << 2]; n namespace seg { n int a, b, c; n void add(int x, int l, int r) { n   if (a <= l && r <= b) n     ed[x].push_back(c); n   else { n     if (a <= ((l + r) >> 1)) add((x << 1), l, ((l + r) >> 1)); n     if (b > ((l + r) >> 1)) add(((x << 1) | 1), ((l + r) >> 1) + 1, r); n   } n } n }  // namespace seg n void solve(int x, int l, int r) { n   int len = ed[x].size(), l0 = T.l; n   for (int i = 0; i < len; i++) T.merge(e[ed[x][i]].a, e[ed[x][i]].b); n   if (l == r) { n     ans[l] = ans[l + 1]; n     while (j <= m && T.cnt) { n       if (e[j].t <= l) { n         seg::a = e[j].t, seg::b = l - 1, seg::c = j; n         if (seg::a <= seg::b) seg::add(1, 1, m); n         T.merge(e[j].a, e[j].b); n         ans[l] = e[j].c; n       } n       j++; n     } n     if (T.cnt) ans[l] = -1; n   } else n     solve(((x << 1) | 1), ((l + r) >> 1) + 1, r), n         solve((x << 1), l, ((l + r) >> 1)); n   T.rewind(l0); n } n int main() { n   scanf( %d%d , &n, &m); n   T.init(); n   for (int i = 1; i <= m; i++) n     scanf( %d%d%d , &e[i].a, &e[i].b, &e[i].c), e[i].t = i; n   sort(e + 1, e + m + 1); n   solve(1, 1, m); n   for (int i = 1; i <= m; i++) printf( %d n , ans[i]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long int a[500005], b[500005]; n int main() { n   int i, j, k, l, x, y, z, m, n, t; n   cin >> t; n   while (t--) { n     cin >> x >> y >> z; n     while (x > 20 && y) { n       x = x / 2; n       x += 10; n       y--; n     } n     while (x >= 0 && z) { n       x = x - 10; n       z--; n     } n     x = max(0, x); n     if (x) n       cout <<  NO  << endl; n     else n       cout <<  YES  << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   float a, b, c, t; n   cin >> a >> b; n   if (a > b) swap(a, b); n   c = (b - a) / 2; n   t = floor(c); n   c = ceil(c); n   int f = 0, y = 0; n   for (int i = 1; i <= c; i++) { n     f += i; n   } n   for (int i = 1; i <= t; i++) { n     y += i; n   } n   cout << f + y; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   long long t; n   cin >> t; n   map<long long, long long> cn; n   set<long long> fac; n   while (t--) { n     fac.clear(); n     cn.clear(); n     long long n; n     cin >> n; n     long long temp = n; n     for (long long i = 2; i * i <= n; i++) { n       while (n % i == 0) { n         cn[i]++; n         n /= i; n         fac.insert(i); n       } n     } n     if (n > 1) cn[n]++, fac.insert(n); n     n = temp; n     if (fac.size() >= 3) { n       cout <<  YES n ; n       long long a = *fac.begin(), b = *(++fac.begin()); n       cout << a <<     << b <<     << n / (a * b) <<   n ; n       continue; n     } else if (fac.size() == 1 && cn[*(fac.begin())] >= 6) { n       cout <<  YES n ; n       cout << *(fac.begin()) <<     << (*(fac.begin())) * (*(fac.begin())) n            <<     n            << n / ((*(fac.begin())) * (*(fac.begin())) * (*(fac.begin()))) n            <<   n ; n       continue; n     } n     if (fac.size() == 2) { n       long long a, ac, b, bc; n       a = *(fac.begin()); n       ac = cn[*(fac.begin())]; n       b = *(++fac.begin()); n       bc = cn[*(++fac.begin())]; n       if (ac + bc >= 4) { n         cout <<  YES n ; n         cout << a <<     << b <<     << n / (a * b) <<   n ; n         continue; n       } n     } n     cout <<  NO n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long int a[200005]; n long long int dist[200005]; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   ; n   long long int n; n   cin >> n; n   for (long long int i = 0; i < n; i++) dist[i] = INT_MAX; n   for (long long int i = 0; i < n; i++) cin >> a[i]; n   long long int m = INT_MAX; n   for (long long int i = 0; i < n; i++) { n     if (a[i] == 0) { n       m = i; n       dist[i] = 0; n     } n     if (m == INT_MAX) { n       dist[i] = INT_MAX; n       continue; n     } n     dist[i] = min(dist[i], i - m); n   } n   m = INT_MAX; n   for (long long int i = n - 1; i > -1; i--) { n     if (a[i] == 0) { n       m = i; n       dist[i] = 0; n     } n     dist[i] = min(dist[i], m - i); n   } n   for (long long int i = 0; i < n; i++) cout << dist[i] <<    ; n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimization( O3 ) n using namespace std; n template <typename T> n inline void Cin(T& first) { n   char c; n   T sign = 1; n   first = 0; n   for (c = getchar(); c <  0  || c >  9 ; c = getchar()) n     if (c ==  - ) sign = -1; n   for (; c >=  0  && c <=  9 ; c = getchar()) first = first * 10 + c -  0 ; n   first *= sign; n } n template <typename T> n inline void Out(T first) { n   if (first > 9) Out(first / 10); n   putchar(first % 10 +  0 ); n } n template <typename T> n inline void Cout(T first, char c) { n   if (first < 0) putchar( - ); n   first = abs(first); n   Out(first); n   putchar(c); n } n template <typename T, typename... Args> n inline void Cin(T& a, Args&... args) { n   Cin(a); n   Cin(args...); n } n template <typename T, typename... Args> n inline void Cout(T a, char c, Args... args) { n   Cout(a, c); n   Cout(args...); n } n const int N = 5002; n const int M = int(5e5) + 2; n const long long oo = (long long)1e10; n int n, k, _a[M], cur[3]; n vector<long long> f[3]; n struct TIrene { n   int first, i; n   bool operator<(const TIrene& o) const& { return i < o.i; } n } a[M]; n void Enter() { n   cin >> k >> n; n   for (int i = 0; i < n; ++i) cin >> _a[i]; n   sort(_a, _a + n); n   for (int i = 0; i < n; ++i) { n     if (i) a[i].first = _a[i] - _a[i - 1]; n     a[i].i = i; n   } n   sort(a + 1, a + n, [](const TIrene& a, const TIrene& b) { n     if (a.first != b.first) return a.first < b.first; n     return a.i > b.i; n   }); n   n = min(n, 3 * k); n   sort(a + 1, a + n); n } n void Solve() { n   for (int i = 0; i < 3; ++i) { n     f[i].resize(k + 1); n     fill(f[i].begin(), f[i].end(), oo); n     cur[i] = i; n   } n   for (int i = 1; i < n; ++i) { n     if (i - 1) n       f[cur[2]][1] = min(f[cur[1]][1], (long long)a[i].first); n     else n       f[cur[2]][1] = a[1].first; n     for (int j = 2, l = min(k, i); j <= l; ++j) { n       if (a[i].i > a[i - 1].i + 1) n         f[cur[2]][j] = min(f[cur[1]][j], f[cur[1]][j - 1] + a[i].first); n       else n         f[cur[2]][j] = min(f[cur[1]][j], f[cur[0]][j - 1] + a[i].first); n     } n     int t = cur[0]; n     cur[0] = cur[1], cur[1] = cur[2], cur[2] = t; n   } n   cout << f[cur[1]][k]; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   if (fopen( test  n              .inp , n              r )) { n     freopen( n          test  n          .inp , n          r , stdin); n     freopen( n          test  n          .out , n          w , stdout); n   } n   Enter(), Solve(); n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( O3 ) n #pragma GCC target( tune=native ) n #pragma GCC optimize( unroll-loops ) n using namespace std; n using ll = long long; n const int N = 120005; n struct node_t { n   int tag, time, value, number; n   ll answer; n } tree[N << 2]; n int n, m, top_max, top_min, a[N], stack_max[N], stack_min[N]; n vector<pair<int, int>> queries[N]; n ll answer[N]; n static void add_value(int x, int value) { n   tree[x].value += value; n   tree[x].tag += value; n } n static void add_time(int x, int value) { n   tree[x].time += value; n   tree[x].answer += (ll)value * tree[x].number; n } n static void push_up(int x) { n   tree[x].value = min(tree[x << 1].value, tree[x << 1 | 1].value); n   tree[x].answer = tree[x << 1].answer + tree[x << 1 | 1].answer; n   tree[x].number = 0; n   if (tree[x].value == tree[x << 1].value) { n     tree[x].number += tree[x << 1].number; n   } n   if (tree[x].value == tree[x << 1 | 1].value) { n     tree[x].number += tree[x << 1 | 1].number; n   } n } n static void push_down(int x) { n   if (tree[x].tag) { n     add_value(x << 1, tree[x].tag); n     add_value(x << 1 | 1, tree[x].tag); n     tree[x].tag = 0; n   } n   if (tree[x].time) { n     if (tree[x].value == tree[x << 1].value) { n       add_time(x << 1, tree[x].time); n     } n     if (tree[x].value == tree[x << 1 | 1].value) { n       add_time(x << 1 | 1, tree[x].time); n     } n     tree[x].time = 0; n   } n } n static void build(int x, int l, int r) { n   tree[x].value = l; n   tree[x].number = 1; n   if (l == r) { n     return; n   } n   int mid = (l + r) / 2; n   build(x << 1, l, mid); n   build(x << 1 | 1, mid + 1, r); n } n static void modify(int x, int l, int r, int ql, int qr, int value) { n   if (l == ql && r == qr) { n     add_value(x, value); n     return; n   } n   int mid = (l + r) / 2; n   push_down(x); n   if (qr <= mid) { n     modify(x << 1, l, mid, ql, qr, value); n   } else if (ql > mid) { n     modify(x << 1 | 1, mid + 1, r, ql, qr, value); n   } else { n     modify(x << 1, l, mid, ql, mid, value); n     modify(x << 1 | 1, mid + 1, r, mid + 1, qr, value); n   } n   push_up(x); n } n static ll query(int x, int l, int r, int ql, int qr) { n   if (l == ql && r == qr) { n     return tree[x].answer; n   } n   int mid = (l + r) / 2; n   push_down(x); n   if (qr <= mid) { n     return query(x << 1, l, mid, ql, qr); n   } else if (ql > mid) { n     return query(x << 1 | 1, mid + 1, r, ql, qr); n   } else { n     return query(x << 1, l, mid, ql, mid) + n            query(x << 1 | 1, mid + 1, r, mid + 1, qr); n   } n } n void solve() { n   ios::sync_with_stdio(0); n   cin.tie(nullptr); n   cin >> n; n   for (int i = 1; i <= n; ++i) { n     cin >> a[i]; n   } n   cin >> m; n   for (int i = 1; i <= m; ++i) { n     int l, r; n     cin >> l >> r; n     queries[r].push_back(make_pair(l, i)); n   } n   build(1, 1, n); n   for (int i = 1; i <= n; ++i) { n     add_value(1, -1); n     while (top_max && a[stack_max[top_max]] < a[i]) { n       modify(1, 1, n, stack_max[top_max - 1] + 1, stack_max[top_max], n              a[i] - a[stack_max[top_max]]); n       --top_max; n     } n     stack_max[++top_max] = i; n     while (top_min && a[stack_min[top_min]] > a[i]) { n       modify(1, 1, n, stack_min[top_min - 1] + 1, stack_min[top_min], n              a[stack_min[top_min]] - a[i]); n       --top_min; n     } n     stack_min[++top_min] = i; n     add_time(1, 1); n     for (auto q : queries[i]) { n       answer[q.second] = query(1, 1, n, q.first, i); n     } n   } n   for (int i = 1; i <= m; ++i) { n     cout << answer[i] <<   n ; n   } n } n int main() { n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long a[300005], ans; n int n, num[300005], cnt[2] = {1}, sum[300005]; n int change(long long x) { n   int ans = 0; n   while (x) { n     ans += (x % 2); n     x /= 2; n   } n   return ans; n } n int main() { n   cin >> n; n   for (int i = 1; i <= n; i++) { n     scanf( %lld , &a[i]); n     num[i] = change(a[i]); n     sum[i] = sum[i - 1] + num[i]; n     ans += cnt[sum[i] % 2]; n     int maxn = 0; n     for (int j = i, k = i + 1; j >= 1 && j >= i - 64; j--) { n       while (k > j) { n         k--; n         maxn = max(maxn, num[k]); n       } n       if (maxn * 2 > sum[i] - sum[j - 1] && (sum[i] - sum[j - 1]) % 2 == 0) n         ans--; n     } n     cnt[sum[i] % 2]++; n   } n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX_N = 100000; n const int MAX_E2 = 1 << 18; n const int MAX_A = 100000; n const int INF = 1 << 30; n int uas[MAX_N]; n pair<int, int> ps[MAX_N], cns[MAX_A]; n vector<int> cvs[MAX_A]; n bool used[MAX_A]; n int check(int m, int uan, int c0, int x) { n   memset(used, false, sizeof(used)); n   int c = c0, sum = 0; n   for (int i = uan - 1; i >= 0 && cns[i].first > x; i--) { n     vector<int> &cv = cvs[cns[i].second]; n     int maxj = cns[i].first - x; n     for (int j = 0; j < maxj; j++) n       sum += ps[cv[j]].first, c++, used[cv[j]] = true; n   } n   for (int i = 0; i < m && c <= x; i++) n     if (!used[i]) sum += ps[i].first, c++; n   return (c > x) ? sum : INF; n } n int main() { n   int n; n   scanf( %d , &n); n   int m = 0, c0 = 0; n   for (int i = 0; i < n; i++) { n     int a, b; n     scanf( %d%d , &a, &b); n     if (!a) n       c0++; n     else { n       a--; n       uas[m] = a; n       ps[m++] = pair<int, int>(b, a); n     } n   } n   sort(uas, uas + m); n   int uan = unique(uas, uas + m) - uas; n   for (int i = 0; i < m; i++) { n     int ai = lower_bound(uas, uas + uan, ps[i].second) - uas; n     ps[i].second = ai; n   } n   sort(ps, ps + m); n   for (int i = 0; i < m; i++) cvs[ps[i].second].push_back(i); n   for (int i = 0; i < uan; i++) cns[i] = pair<int, int>(cvs[i].size(), i); n   sort(cns, cns + uan); n   int x0 = 0, x1 = cns[uan - 1].first; n   while (x0 + 2 < x1) { n     int xx0 = (x0 * 2 + x1) / 3; n     int xx1 = (x0 + x1 * 2) / 3; n     int sum0 = check(m, uan, c0, xx0); n     int sum1 = check(m, uan, c0, xx1); n     if (sum0 >= sum1) n       x0 = xx0; n     else n       x1 = xx1; n   } n   int minsum = INF; n   for (int x = x0; x <= x1; x++) { n     int sum = check(m, uan, c0, x); n     if (minsum > sum) minsum = sum; n   } n   printf( %d n , minsum); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int n; n   cin >> n; n   --n; n   int right, left, down, up; n   right = left = down = up = n / 4; n   n = n - up * 4; n   if (n != 0) { n     ++right; n     --n; n   } n   if (n != 0) { n     ++down; n     --n; n   } n   if (n != 0) { n     ++left; n     --n; n   } n   if (n != 0) { n     ++up; n     --n; n   } n   int centerx = 0, centery = 0; n   cout << centerx <<     << centery << endl; n   for (int i = 0; i < right; ++i) { n     cout << centerx + i + 1 <<     << centery << endl; n   } n   for (int i = 0; i < left; ++i) { n     cout << centerx - i - 1 <<     << centery << endl; n   } n   for (int i = 0; i < up; ++i) { n     cout << centerx <<     << centery + i + 1 << endl; n   } n   for (int i = 0; i < down; ++i) { n     cout << centerx <<     << centery - i - 1 << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int t; n   cin >> t; n   while (t--) { n     long long int n; n     cin >> n; n     long long int a[n]; n     long long int freq[200001] = {0}; n     for (long long int i = 0; i < n; i++) { n       cin >> a[i]; n       freq[a[i]]++; n     } n     sort(a, a + n); n     long long int present = 1; n     long long int ans = 1; n     long long int expected = 0; n     long long int count = 0; n     int flag = 0; n     while (count < n) { n       expected = a[count]; n       present += freq[a[count]] - 1; n       if (present >= expected) { n         ans = present + 1; n       } n       count += freq[a[count]]; n       present += 1; n     } n     cout << ans << endl; n   } n   return 0; n } n


// Template begins n #include <iostream> n #include <algorithm> n #include <vector> n #include <set> n #include <stdio.h> n #include <stack> n #include <math.h> n #include <complex> n  n using namespace std; n #define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) n #define ll long long n #define endl   n  n #define lb lower_bound n #define ub upper_bound n #define fo(i,a,b) for(i=a;i<=b;i++) n #define all(v) (v).begin(),(v).end() n #define sort0(v) sort(all(v)) n #define lbb(a,b,arr,x) lower_bound(arr+a,arr+b+1,x)-arr n #define ubb(a,b,arr,x) upper_bound(arr+a,arr+b+1,x)-arr n #define freq(a,b,arr,x) upper_bound(arr+a,arr+b+1,x)-lower_bound(arr+a,arr+b+1,x) n typedef pair<int,int> pii; n typedef pair<ll,ll> pll; n #define d0(x) cout<<(x)<<    n #define d1(x) cout<<(x)<<endl n #define d2(x,y) cout<<(x)<<   <<(y)<<endl n #define d3(x,y,z) cout<<(x)<<   <<(y)<<   <<(z)<<endl n #define d4(a,b,c,d) cout<<(a)<<   <<(b)<<   <<(c)<<   <<(d)<<endl n #define d5(a,b,c,d,e) cout<<(a)<<   <<(b)<<   <<(c)<<   <<(d)<<   <<(e)<<endl n #define d6(a,b,c,d,e,f) cout<<(a)<<   <<(b)<<   <<(c)<<   <<(d)<<   <<(e)<<   <<(f)<<endl n #define max3(a,b,c) max(max((a),(b)),(c)) n #define max4(a,b,c,d) max(max((a),(b)),max((c),(d))) n #define ss second n #define ff first n #define pb push_back n #define mp make_pair n #define printp(x) cout << x.ff <<     << x.ss << endl n template<class T> ostream& operator<<(ostream &os, vector<T> V) { n     for(auto v : V) os << v <<    ; n     return cout <<   ; n } n template<class T> ostream& operator<<(ostream &os, set<T> S){ n     for(auto s:S) os<<s<<   ; n     return cout <<   ; n } n template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) { n     return os << P.first <<     << P.second; n } n const ll mod=1e9+7; n #define inf 9999999999999 n  n ll inv(ll i){if(i==1) return 1;return (mod-((mod/i)*inv(mod%i))%mod)%mod;} n  n ll gcd(ll a,ll b){ if (b==0) return a;return gcd(b,a%b);} n  n ll pwr(ll a, ll b) {a %= mod; ll res = 1;while (b > 0) {if (b & 1) res = res * a % mod; a = a * a % mod; b >>= 1;}return res;} n //Template ends n  n ll a[200010], t[800010],T[800010]; n int n; n void buildm(int v, int tl, int tr){ n     if(tl>tr) return; n     if(tl==tr){ n         t[v] = a[tl]; n         return; n     } n      n     int tm = (tl+tr)/2; n     buildm(2*v,tl,tm); n     buildm(2*v+1,tm+1,tr); n      n     t[v] = min(t[2*v], t[2*v+1]); n } n  n void buildM(int v, int tl, int tr){ n     if(tl>tr) return; n     if(tl==tr){ n         T[v] = a[tl]; n         return; n     } n      n     int tm = (tl+tr)/2; n     buildM(2*v,tl,tm); n     buildM(2*v+1,tm+1,tr); n      n     T[v] = max(T[2*v], T[2*v+1]); n } n  n ll minq(int v, int tl, int tr, int l, int r){ n     if(l>tr or r<tl) return 1000000000; n      n     if(tl==l and tr==r){ n         return t[v]; n     } n      n     int tm = (tl+tr)/2; n     return min(minq(2*v,tl,tm,l,min(r,tm)),minq(2*v+1,tm+1,tr,max(tm+1,l),r)); n } n  n ll minn(int l,int r){ n     return minq(1,1,n,l,r); n } n  n  n ll maxq(int v, int tl, int tr, int l, int r){ n     if(l>tr or r<tl) return 0; n      n     if(tl==l and tr==r){ n         return T[v]; n     } n      n     int tm = (tl+tr)/2; n     return max(maxq(2*v,tl,tm,l,min(r,tm)),maxq(2*v+1,tm+1,tr,max(tm+1,l),r)); n } n  n ll maxx(int l,int r){ n     return maxq(1,1,n,l,r); n } n  n int main(){ n     fio; n     int t0,i; n     cin >> t0; n     while(t0--){ n         cin >> n; n         for(i=1;i<=n;i++) cin >> a[i]; n         buildm(1,1,n); n         buildM(1,1,n); n          n         ll curr = 0; n  n         bool z = false; n          n         for(i=1;i<=n;i++){ n             curr = max(curr, a[i]); n              n             int l = i+1; n             int r = n-1; n              n             while(l<=r){ n                 int mid = (l+r)/2; n                 ll val1 = minn(i+1,mid); n                 ll val2 = maxx(mid+1,n); n                  n                 //d5(i,mid,val1,val2,curr); n                  n                 if(val1 == val2 and val1 == curr){ n                     z = true; n                     d1( YES ); n                     d3(i,mid-i,n-mid); n                     break; n                 } n                  n                 if(val1 < curr or (val1 == curr and val2 < curr)){ n                     r = mid - 1; n                 } n                 else{ n                     l = mid + 1; n                 } n             } n              n             if(z) break; n         } n          n         if(z){ n             continue; n         } n         else{ n             d1( NO ); n         } n     } n } n


#include <bits/stdc++.h> n const int N = 65550; n int ru[N], sum[N]; n int n; n int s[N], t[N], cc = 0; n int main() { n   int i; n   scanf( %d , &n); n   for (i = 0; i < n; i++) scanf( %d%d , &ru[i], &sum[i]); n   for (i = 0; i < n; i++) { n     int now = i; n     while (ru[now] == 1) { n       cc++; n       s[cc] = now; n       t[cc] = sum[now]; n       ru[now]--; n       ru[sum[now]]--; n       sum[sum[now]] ^= now; n       now = sum[now]; n     } n   } n   printf( %d n , cc); n   for (i = 1; i <= cc; i++) printf( %d %d n , s[i], t[i]); n   return 0; n } n


#include <bits/stdc++.h> n int a[200010]; n int main() { n   long long ans = 0; n   int m = 0, n; n   scanf( %d n , &n); n   for (int i = 1; i <= n; i++) { n     int a1, b1, a2, b2; n     scanf( %d%d%d%d n , &a1, &b1, &a2, &b2); n     if (a1 + b1 >= a2 + b2) { n       a[++m] = a1 + b1; n       a[++m] = a2 + b2; n       ans = ans + a1 + a2; n     } else if (a1 > b2) n       ans += a1 - b2; n     else if (a2 < b1) n       ans += a2 - b1; n   } n   std::sort(a + 1, a + m + 1); n   for (int i = 1; i <= m; i++) n     if (i & 1) ans -= a[i]; n   printf( %I64d n , ans); n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 2e5 + 9; n const int MAX = 2e2 + 9; n const double ep = 1e-6; n const int mod = 998244353; n const int INF = 0x3f3f3f3f; n const double inf = 1e20; n const double pi = acos(-1); n vector<int> vec[maxn]; n int n, m, k, d[maxn], cnt1, ans[maxn], tot; n bool vis[maxn]; n bool solve1() { n   queue<int> q; n   cnt1 = 0; n   for (int i = (1); i <= (n); ++i) { n     if (d[i] < k) q.push(i), vis[i] = 1; n   } n   while (!q.empty()) { n     int p = q.front(); n     q.pop(); n     cnt1++; n     if (d[p] == k - 1) { n       ans[tot = 1] = p; n       bool ju = 0; n       for (int i : vec[p]) { n         if (d[i] < k - 1) continue; n         for (int j : vec[p]) { n           if (i == j) break; n           if (d[j] < k - 1) continue; n           auto k = lower_bound(vec[j].begin(), vec[j].end(), i); n           if (k == vec[j].end() || (*k) != i) { n             ju = 1; n             break; n           } n         } n         if (ju) break; n         ans[++tot] = i; n       } n       if (!ju && tot == k) { n         puts( 2 ); n         for (int i = (1); i <= (k); ++i) printf( %d  , (ans[i])); n         puts(  ); n         return 1; n       } n     } n     d[p] = 0; n     for (int to : vec[p]) { n       d[to]--; n       if (vis[to]) continue; n       if (d[to] < k) { n         vis[to] = 1; n         q.push(to); n       } n     } n   } n   if (n - cnt1 < k) return 0; n   printf( %d %d n , (1), (n - cnt1)); n   for (int i = (1); i <= (n); ++i) n     if (!vis[i]) printf( %d  , (i)); n   puts(  ); n   return 1; n } n void solve() { n   scanf( %d%d%d , &n, &m, &k); n   for (int i = (1); i <= (n); ++i) d[i] = 0, vis[i] = 0, vec[i].clear(); n   for (int i = (1); i <= (m); ++i) { n     int u, v; n     scanf( %d%d , &(u), &(v)); n     vec[u].emplace_back(v); n     vec[v].emplace_back(u); n     d[u]++; n     d[v]++; n   } n   if (1ll * k * (k - 1) / 2 > m) { n     puts( -1 ); n     return; n   } n   for (int i = (1); i <= (n); ++i) sort(vec[i].begin(), vec[i].end()); n   if (solve1()) return; n   puts( -1 ); n } n int main() { n   int T = 1; n   scanf( %d , &(T)); n   while (T--) solve(); n } n


#include <bits/stdc++.h> n using namespace std; n vector<long long> v; n int main() { n   long long p, k, rem; n   cin >> p >> k; n   v.push_back(-p / k); n   for (int i = 0;; i++) { n     for (long long x = v.back() / k - 1; x <= v.back() / k + 1; x++) { n       if (v.back() - x * k >= 0 && v.back() - x * k < k) { n         v.push_back(-x); n         break; n       } n     } n     if (v[v.size() - 1] * k + v[v.size() - 2] < k && v.back() < k && n         v.back() >= 0) n       break; n   } n   while (v.back() == 0) v.pop_back(); n   v.push_back(0); n   cout << v.size() << endl; n   for (int i = 0; i < v.size(); i++) { n     if (i) n       cout << v[i] * k + v[i - 1] <<    ; n     else n       cout << v[i] * k + p <<    ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX = 1e5 + 55; n int x[MAX]; n int main() { n   int n; n   cin >> n; n   double sum = 0; n   int a[n + 1]; n   for (int i = 0; i < n; i++) cin >> a[i]; n   sort(a, a + n, greater<int>()); n   for (int i = 0; i < n; i++) { n     if (i % 2 == 0) n       sum += a[i] * a[i]; n     else n       sum -= a[i] * a[i]; n   } n   cout << setprecision(11) << fixed << sum * 3.1415926536; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct edge { n   int u, v, l, id; n   edge() {} n   edge(int a, int b, int c, int d) { u = a, v = b, l = c, id = d; } n   bool operator<(const edge &p) const { n     return l < p.l || (l == p.l && id < p.id); n   } n }; n char *p1, *p2, buffer[10000009]; n int n, m, cur; n int l[1200009], r[1200009]; n vector<int> v[1200009]; n edge e[300009]; n int ans[300009]; n int f[100009], sz[100009]; n pair<int, int> bf[29][100009], bsz[29][100009]; n int tp[29]; n void rd(int &x) { n   char ch = 0; n   x = 0; n   while (ch <  0  || ch >  9 ) n     ch = (p1 == p2 && (p2 = (p1 = buffer) + fread(buffer, 1, 10000000, stdin), n                        p1 == p2) n               ? EOF n               : *p1++); n   while (ch >=  0  && ch <=  9 ) n     x = x * 10 + (ch & 15), n     ch = (p1 == p2 && (p2 = (p1 = buffer) + fread(buffer, 1, 10000000, stdin), n                        p1 == p2) n               ? EOF n               : *p1++); n } n int fnd(int x) { return x == f[x] ? x : fnd(f[x]); } n int uni(int d, int a, int b) { n   a = fnd(a), b = fnd(b); n   if (a == b) return 0; n   if (sz[a] > sz[b]) swap(a, b); n   int ret = 0; n   if ((sz[a] & 1) && (sz[b] & 1)) ret = 2; n   bf[d][++tp[d]] = pair<int, int>(a, f[a]); n   bsz[d][tp[d]] = pair<int, int>(b, sz[b]); n   f[a] = b; n   sz[b] += sz[a]; n   return ret; n } n void roll(int d) { n   for (int &i = tp[d]; i >= 1; i--) { n     pair<int, int> tf = bf[d][i], tsz = bsz[d][i]; n     f[tf.first] = tf.second; n     sz[tsz.first] = tsz.second; n   } n } n void build(int a, int ll, int rr) { n   l[a] = ll; n   r[a] = rr; n   if (ll < rr) { n     int mid = (ll + rr) >> 1; n     build(a << 1, ll, mid); n     build(a << 1 | 1, mid + 1, rr); n   } n } n void add(int a, int ll, int rr, int val) { n   if (ll > rr) return; n   if (l[a] > rr || r[a] < ll) return; n   if (l[a] >= ll && r[a] <= rr) { n     v[a].push_back(val); n     return; n   } n   add(a << 1, ll, rr, val); n   add(a << 1 | 1, ll, rr, val); n } n void solve(int d, int sm, int a) { n   int tsm = sm; n   for (int i = 0; i < (int)v[a].size(); i++) { n     int p = v[a][i]; n     tsm -= uni(d, e[p].u, e[p].v); n   } n   if (l[a] != r[a]) n     solve(d + 1, tsm, a << 1 | 1), solve(d + 1, tsm, a << 1); n   else { n     while (cur <= m && tsm) { n       cur++; n       if (e[cur].id > l[a]) n         continue; n       else { n         tsm -= uni(d, e[cur].u, e[cur].v); n         add(1, e[cur].id, l[a] - 1, cur); n       } n     } n     ans[l[a]] = cur > m ? -1 : e[cur].l; n   } n   roll(d); n } n int main() { n   rd(n), rd(m); n   if (n & 1) { n     for (int i = 1; i <= m; i++) printf( -1 n ); n     return 0; n   } n   for (int i = 1; i <= n; i++) f[i] = i, sz[i] = 1; n   for (int i = 1, a, b, c; i <= m; i++) { n     rd(a), rd(b), rd(c); n     e[i] = edge(a, b, c, i); n   } n   sort(e + 1, e + m + 1); n   build(1, 1, m); n   solve(1, n, 1); n   for (int i = 1; i <= m; i++) printf( %d n , ans[i]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s, t; n   cin >> s >> t; n   vector<int> p; n   int a[27] = {0}; n   for (int i = 0; i < s.size(); i++) { n     if (s[i] ==  ? ) { n       p.push_back(i); n     } else { n       a[int(s[i]) - 96]++; n     } n   } n   if (p.size() == 0) { n     cout << s; n     return 0; n   } n   int i = 0, j = 0; n   while (j < p.size()) { n     if (i == t.size()) { n       i = 0; n     } n     if (a[int(t[i]) - 96] > 0) { n       a[int(t[i]) - 96]--; n     } else { n       s[p[j]] = t[i]; n       j++; n     } n     i++; n   } n   cout << s << endl; n } n


#include <bits/stdc++.h> n const int MAXN = 2e5 + 7; n int a[MAXN]; n int main() { n   int N; n   scanf( %d , &N); n   for (int i = 1; i <= N; ++i) scanf( %d , &a[i]); n   int ans = 0; n   int j = 1, i; n   for (i = 2; i <= N;) { n     while (i <= N && a[i] <= 2 * a[i - 1]) { n       ++i; n       ans = (ans > i - j ? ans : i - j); n     } n     j = i; n     ++i; n   } n   ans = (ans > i - j ? ans : i - j); n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 7, POWN = (1 << N), MOD = 1000 * 1000 * 1000 + 7; n int ans[POWN], res[POWN], a[POWN][POWN], b[POWN][POWN], c[POWN][POWN]; n void powm(int p, int n) { n   for (int i = 0; i < n; i++) n     for (int j = 0; j < n; j++) { n       b[i][j] = a[i][j]; n       a[i][j] = (i == j); n     } n   while (p) { n     if (p & 1) { n       for (int i = 0; i < n; i++) n         for (int j = 0; j < n; j++) { n           c[i][j] = 0; n           for (int k = 0; k < n; k++) n             c[i][j] = (c[i][j] + (long long)a[i][k] * b[k][j]) % MOD; n         } n       for (int i = 0; i < n; i++) n         for (int j = 0; j < n; j++) a[i][j] = c[i][j]; n     } n     p >>= 1; n     for (int i = 0; i < n; i++) n       for (int j = 0; j < n; j++) { n         c[i][j] = 0; n         for (int k = 0; k < n; k++) n           c[i][j] = (c[i][j] + (long long)b[i][k] * b[k][j]) % MOD; n       } n     for (int i = 0; i < n; i++) n       for (int j = 0; j < n; j++) b[i][j] = c[i][j]; n   } n } n void mul(int n) { n   for (int i = 0; i < n; i++) { n     res[i] = 0; n     for (int j = 0; j < n; j++) n       res[i] = (res[i] + (long long)ans[j] * a[j][i]) % MOD; n   } n   for (int i = 0; i < n; i++) ans[i] = res[i]; n } n int main() { n   ios_base::sync_with_stdio(false); n   ans[0] = 1; n   for (int i = 0; i < N; i++) { n     for (int j = 0; j < (1 << i); j++) { n       ans[j | (1 << i)] = ans[j]; n       ans[j] = 0; n     } n     int w; n     cin >> w; n     if (!w) continue; n     for (int j = 0; j < (1 << (i + 1)); j++) n       for (int k = 0; k < (1 << (i + 1)); k++) { n         a[j][k] = 0; n         for (int l = 0; l < (1 << i); l++) { n           int msk = ((1 << (i + 1)) | (l << 1) | 1); n           bool ok = true; n           for (int m = 0; m < i + 1; m++) n             if ((j & (1 << m)) && (k & (1 << m)) && (msk & (1 << m)) && n                 (msk & (1 << (m + 1)))) { n               ok = false; n               break; n             } n           if (ok) a[j][k]++; n         } n       } n     powm(w, 1 << (i + 1)); n     mul(1 << (i + 1)); n   } n   cout << ans[(1 << N) - 1] <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, s, t, g; n int dl[200009], head, last, q[20009]; n int dep[20010]; n int h[20010], top = 1; n struct edge { n   int to, net; n   long long w; n } es[200009]; n void add(int u, int v, long long w) { n   top++; n   es[top].w = w; n   es[top].net = h[u]; n   h[u] = top; n   es[top].to = v; n   return; n } n inline int read() { n   int sum = 0, fh = 1; n   char c = getchar(); n   while (c >  9  || c <  0 ) { n     if (c ==  - ) fh = -1; n     c = getchar(); n   } n   while (c >=  0  && c <=  9 ) { n     sum *= 10; n     sum += c -  0 ; n     c = getchar(); n   } n   return sum * fh; n } n bool bfs() { n   for (int i = 1; i <= t; i++) dep[i] = 0; n   head = 1; n   last = 1; n   dl[1] = s; n   dep[s] = 1; n   while (head <= last) { n     int u = dl[head]; n     head++; n     for (int i = h[u]; i; i = es[i].net) { n       if (dep[es[i].to] == 0 && es[i].w) { n         dep[es[i].to] = dep[u] + 1; n         last++; n         dl[last] = es[i].to; n       } n     } n   } n   return dep[t]; n } n long long ans = 0, ssm = 0; n long long dfs(int now, long long zg) { n   if (now == t) { n     return zg; n   } n   long long sum = 0; n   for (int i = h[now]; i; i = es[i].net) { n     int v = es[i].to; n     if (dep[v] == dep[now] + 1 && es[i].w) { n       long long res = dfs(v, min(es[i].w, zg)); n       sum += res; n       zg -= res; n       es[i].w -= res; n       es[i ^ 1].w += res; n     } n   } n   if (sum == 0) dep[now] = 0; n   return sum; n } n int main() { n   n = read(); n   m = read(); n   g = read(); n   s = 0; n   t = n + m + 2; n   for (int i = 1; i <= n; i++) q[i] = read(); n   for (int i = 1; i <= n; i++) { n     int x = read(); n     if (q[i] == 0) n       add(s, i, x), add(i, s, 0); n     else n       add(i, t, x), add(t, i, 0); n   } n   for (int i = 1; i <= m; i++) { n     int opt = read(), w = read(), k = read(); n     ssm += w; n     for (int j = 1; j <= k; j++) { n       int x = read(); n       if (opt == 0) { n         add(n + i, x, 1e18); n         add(x, n + i, 0); n       } else { n         add(x, n + i, 1e18); n         add(n + i, x, 0); n       } n     } n     int gt = read(); n     if (opt == 0) { n       add(s, n + i, w + g * gt); n       add(n + i, s, 0); n     } else { n       add(n + i, t, w + g * gt); n       add(t, n + i, 0); n     } n   } n   while (bfs()) { n     ans += dfs(s, 1e18); n   } n   cout << ssm - ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int r, c, n, mnm, x, y, ret = 0; n   cin >> r >> c >> n >> mnm; n   vector<vector<int> > mapa(r, vector<int>(c, 1)); n   for (int i = 0; i < n; i++) { n     cin >> x >> y; n     mapa[x - 1][y - 1] = 2; n   } n   for (int i = 1; i <= r; i++) { n     for (int j = 1; j <= c; j++) { n       for (int k = 0; k < r - (i - 1); k++) { n         for (int l = 0; l < c - (j - 1); l++) { n           int cnt = 0; n           for (int m = 0; m < i; m++) { n             for (int n = 0; n < j; n++) { n               if (mapa[k + m][l + n] == 2) cnt++; n             } n           } n           if (cnt >= mnm) ret++; n         } n       } n     } n   } n   cout << ret << endl; n } n


#include <bits/stdc++.h> n using namespace std; n signed main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   long long n; n   cin >> n; n   vector<pair<long long, long long> > v(n); n   for (long long i = 0; i < n; i++) { n     cin >> v[i].first >> v[i].second; n   } n   long long sum = 0; n   for (long long i = 0; i < n; i++) { n     for (long long j = i + 1; j < n; j++) { n       pair<long long, long long> p1 = v[i], p2 = v[j]; n       bool flag = true; n       if (p1.first > p2.first || p1.first == p2.first && i < j) { n         swap(p1, p2); n         flag = false; n       } n       vector<pair<long long, pair<long long, long long> > > p(4); n       if (flag) { n         p[0] = {p1.first, {-i, 1}}; n         p[1] = {p1.first + p1.second, {-i, 2}}; n         p[2] = {p2.first, {-j, 3}}; n         p[3] = {p2.first + p2.second, {-j, 4}}; n       } else { n         p[0] = {p1.first, {-j, 1}}; n         p[1] = {p1.first + p1.second, {-j, 2}}; n         p[2] = {p2.first, {-i, 3}}; n         p[3] = {p2.first + p2.second, {-i, 4}}; n       } n       sort(p.begin(), p.end()); n       vector<long long> g(4); n       for (long long h = 0; h < 4; h++) { n         g[h] = p[h].second.second; n       } n       if (g[0] == 1 && g[2] == 2 && g[1] == 3 && g[3] == 4 || n           g[0] == 2 && g[2] == 1 && g[3] == 3 && g[1] == 4) n         sum += 2; n       else if (g[0] == 1 && g[3] == 2 || g[1] == 2 && g[2] == 1 || n                g[1] == 1 && g[2] == 2 || n                g[1] == 1 && g[2] == 3 && g[3] == 2 && g[0] == 4 || n                g[0] == 1 && g[2] == 2 && g[3] == 3 && g[1] == 4) n         sum++; n     } n   } n   cout << sum; n } n


#include <bits/stdc++.h> n using namespace std; n const long long INF = 1e18; n const long long mod = 1e9 + 7; n const long long modd = 1; n const long long N = 1e5 + 5; n void solve() { n   long long n, m; n   cin >> n >> m; n   long long a[n + 1][m + 1]; n   for (long long i = 0; i < n; i++) n     for (long long j = 0; j < m; j++) cin >> a[i][j]; n   for (long long i = 0; i < n; i++) a[i][m] = a[i][m - 1] + 1; n   for (long long i = 0; i < m; i++) a[n][i] = a[n - 1][i] + 1; n   long long ans = 0; n   for (long long i = n - 1; i >= 0; i = i - 1) { n     for (long long j = m - 1; j >= 0; j = j - 1) { n       if (a[i][j] == 0) a[i][j] = min(a[i + 1][j], a[i][j + 1]) - 1; n       if (a[i][j] >= a[i + 1][j] || a[i][j] >= a[i][j + 1]) { n         cout << -1; n         return; n       } n       ans = ans + a[i][j]; n     } n   } n   cout << ans; n } n int32_t main() { n   std::ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); n   long long t = 1; n   for (long long i = 1; i <= t; i = i + 1) { n     solve(); n     cout << endl; n   } n } n


#include <bits/stdc++.h> n int a, b, i, j, n; n std::string s; n bool isgood(int n) { n   int i; n   for (i = 2; i < n; i++) n     if (n % i == 0) return false; n   return true; n } n void sol() { n   if (!isgood(b)) { n     printf( NO  ); n     return; n   } n   for (i = a + 1; i < b; i++) n     if (isgood(i)) { n       printf( NO  ); n       return; n     } n   printf( YES  ); n } n int main() { n #pragma comment(linker,  /STACK:16777216 ) n   while (scanf( %d %d  , &a, &b) != EOF) { n     sol(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long par[200000]; n long long ran[200000]; n long long cnt[200000]; n void init(long long n) { n   for (long long i = 0; i <= n; i++) { n     par[i] = i; n     ran[i] = 0; n   } n } n long long finds(long long x) { n   if (par[x] == x) n     return x; n   else n     return par[x] = finds(par[x]); n } n void unite(long long x, long long y) { n   x = finds(x); n   y = finds(y); n   if (x == y) return; n   if (ran[x] < ran[y]) { n     par[x] = y; n   } else { n     par[y] = x; n     if (ran[x] == ran[y]) ran[x]++; n   } n } n long long quick_mod(long long a, long long n) { n   long long tmp = a; n   long long ans = 1; n   while (n) { n     if (n % 2 == 1) ans = (tmp * ans) % 1000000007; n     n /= 2; n     tmp = (tmp * tmp) % 1000000007; n   } n   return ans; n } n int main() { n   long long n, k; n   scanf( %lld%lld , &n, &k); n   init(n); n   for (long long i = 0; i < n - 1; i++) { n     long long a, b, c; n     scanf( %lld%lld%lld , &a, &b, &c); n     if (c == 0) unite(a, b); n   } n   for (long long i = 1; i <= n; i++) { n     finds(i); n     cnt[par[i]]++; n   } n   long long ans = quick_mod(n, k); n   for (long long i = 1; i <= n; i++) { n     ans = (ans + 1000000007 - quick_mod(cnt[i], k)) % 1000000007; n   } n   printf( %lld n , ans); n } n


#include <bits/stdc++.h> n const int P = 29; n using namespace std; n inline int read() { n   int x = 0, f = 1; n   char ch = getchar(); n   while (ch <  0  || ch >  9 ) { n     if (ch ==  - ) f = -1; n     ch = getchar(); n   } n   while (ch >=  0  && ch <=  9 ) { n     x = x * 10 + ch -  0 ; n     ch = getchar(); n   } n   return x * f; n } n int n, k, cnt; n int a[20]; n int main() { n   n = read(); n   k = read(); n   for (int i = 1; i <= n; i++) { n     int x = 0, base = 1; n     for (int j = 1; j <= k; j++) { n       int p = read(); n       x = x * base + p; n       base *= 2; n     } n     bool flag = 0; n     for (int j = 1; j <= cnt; j++) n       if (a[j] == x) flag = 1; n     if (!flag) a[++cnt] = x; n   } n   for (int i = 1; i <= cnt; i++) n     for (int j = 1; j <= cnt; j++) n       if ((a[i] & a[j]) == 0) { n         cout <<  YES  << endl; n         return 0; n       } n   cout <<  NO ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int x[3]; n int y[3]; n bool isok(int a, int b, int c) { n   if (b > c && a > c && a < b) return true; n   if (b < c && a > b && a < c) return true; n   return false; n } n bool TP() { n   if (x[1] == x[0] && isok(y[2], y[1], y[0])) return true; n   if (x[2] == x[0] && isok(y[1], y[2], y[0])) return true; n   if (x[2] == x[1] && isok(y[0], y[1], y[2])) return true; n   if (y[1] == y[0] && isok(x[2], x[1], x[0])) return true; n   if (y[2] == y[0] && isok(x[1], x[2], x[0])) return true; n   if (y[2] == y[1] && isok(x[0], x[1], x[2])) return true; n   return false; n } n int main() { n   for (int i = 0; i < 3; i++) cin >> x[i] >> y[i]; n   if (x[0] == x[1] && x[1] == x[2]) n     cout <<  1  << endl; n   else if (y[0] == y[1] && y[1] == y[2]) n     cout <<  1  << endl; n   else if ((x[0] != x[1] && x[1] != x[2] && x[2] != x[0]) && n            (y[0] != y[1] && y[1] != y[2] && y[2] != y[0])) { n     cout <<  3  << endl; n   } else { n     if (TP()) n       cout <<  3  << endl; n     else n       cout <<  2  << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int execute() { n   int n; n   cin >> n; n   string s; n   s.assign(n / 2 - 1,  1 ); n   if (n % 2) { n     cout << 7; n   } else { n     cout << 1; n   } n   cout << s << endl; n   return 0; n } n int TE = true; n bool mTest = true; n int main() { n   ios_base::sync_with_stdio(false); n   if (mTest) cin >> TE; n   while (TE--) { n     execute(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 3 * 100010; n const int maxm = 3 * 100010; n const int BUFF = 10 * 1010 * 1010; n const int block = 400; n int n, m; n int ans[maxm]; n struct DSU { n   int fa[maxn], rk[maxn]; n   int *where[BUFF], val[BUFF]; n   int tot; n   void init() { n     tot = 0; n     for (int i = 0; i <= n; i++) fa[i] = i, rk[i] = 1; n   } n   int Find(int x) { return x == fa[x] ? x : Find(fa[x]); } n   int FastFind(int x) { n     if (x == fa[x]) return x; n     return fa[x] = Find(fa[x]); n   } n   void Union(int x, int y) { n     int a = Find(x), b = Find(y); n     if (a < b) swap(a, b); n     val[tot] = rk[a]; n     where[tot++] = &rk[a]; n     val[tot] = fa[b]; n     where[tot++] = &fa[b]; n     assert(tot <= BUFF); n     rk[a] += rk[b]; n     fa[b] = a; n   } n   void FastUnion(int x, int y) { n     int a = Find(x), b = Find(y); n     if (a < b) swap(a, b); n     rk[a] += rk[b]; n     fa[b] = a; n   } n   void rollback() { n     while (tot) { n       *where[tot - 1] = val[tot - 1]; n       tot--; n     } n   } n }; n DSU dsu; n struct Query { n   int op, x, y; n   int e0, e1; n }; n Query q[maxm]; n struct EDGE { n   int u, v; n   EDGE() {} n   EDGE(int u, int v) : u(u), v(v) {} n   bool operator<(const EDGE &rhs) const { n     if (u == rhs.u) return v < rhs.v; n     return u < rhs.u; n   } n }; n EDGE edge[maxm * 2]; n map<EDGE, int> id; n vector<int> cur; n int addEdge(struct EDGE e) { n   if (e.u > e.v) swap(e.u, e.v); n   if (!id.count(e)) { n     int k = id.size(); n     edge[k] = e; n     id[e] = k; n   } n   return id[e]; n } n int used[maxm * 2]; n int state[maxm * 2]; n void rebuild(int l) { n   int r = min(l + block - 1, m); n   dsu.init(); n   memset(used, 0, sizeof(used)); n   memset(state, 0, sizeof(state)); n   for (int i = 1; i < l; i++) { n     if (q[i].op == 1) { n       int e = ans[i - 1] == 1 ? q[i].e1 : q[i].e0; n       used[e] = 1; n       state[e] ^= 1; n     } n   } n   for (int i = l; i <= r; i++) { n     if (q[i].op == 1) { n       used[q[i].e0] = used[q[i].e1] = 0; n     } n   } n   cur.clear(); n   for (int i = 1; i < l; i++) { n     int e = ans[i - 1] == 1 ? q[i].e1 : q[i].e0; n     if (used[e] && state[e]) { n       state[e] = 0; n       dsu.FastUnion(edge[e].u, edge[e].v); n     } n     if (!used[e] && state[e]) { n       state[e] = 0; n       cur.push_back(e); n     } n   } n } n vector<int> ask; n int main() { n   scanf( %d %d , &n, &m); n   for (int i = 1; i <= m; i++) { n     scanf( %d %d %d , &q[i].op, &q[i].x, &q[i].y); n     if (q[i].op == 1) { n       EDGE e = EDGE(q[i].x % n + 1, q[i].y % n + 1); n       q[i].e1 = addEdge(e); n       e = EDGE((q[i].x - 1) % n + 1, (q[i].y - 1) % n + 1); n       q[i].e0 = addEdge(e); n     } else n       ask.push_back(i); n   } n   for (int i = 1; i <= m; i++) { n     if ((i - 1) % block == 0) { n       rebuild(i); n     } n     if (q[i].op == 1) { n       dsu.rollback(); n       int e = (ans[i - 1] == 1 ? q[i].e1 : q[i].e0); n       auto it = find(cur.begin(), cur.end(), e); n       if (it == cur.end()) n         cur.push_back(e); n       else n         cur.erase(it); n       ans[i] = ans[i - 1]; n     } else { n       for (int i = 0; i < (int)cur.size(); i++) { n         int e = cur[i]; n         dsu.Union(edge[e].u, edge[e].v); n       } n       int u = (q[i].x + ans[i - 1] - 1) % n + 1; n       int v = (q[i].y + ans[i - 1] - 1) % n + 1; n       ans[i] = (dsu.Find(u) == dsu.Find(v)); n     } n   } n   for (int i = 0; i < (int)ask.size(); i++) { n     printf( %d , ans[ask[i]]); n   } n   printf(  n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class node> n struct link_cut_tree { n   bool connected(node* u, node* v) { return lca(u, v) != NULL; } n   int depth(node* u) { n     access(u); n     return get_sz(u->ch[0]); n   } n   node* get_root(node* u) { n     access(u); n     while (u->ch[0]) u = u->ch[0], u->push(); n     return access(u), u; n   } n   node* ancestor(node* u, int k) { n     k = depth(u) - k; n     assert(k >= 0); n     for (;; u->push()) { n       int sz = get_sz(u->ch[0]); n       if (sz == k) return access(u), u; n       if (sz < k) n         k -= sz + 1, u = u->ch[1]; n       else n         u = u->ch[0]; n     } n     assert(0); n   } n   node* lca(node* u, node* v) { n     if (u == v) return u; n     access(u); n     access(v); n     if (!u->p) return NULL; n     u->splay(); n     return u->p ?: u; n   } n   void link(node* u, node* v) { n     make_root(v); n     access(u); n     set_link(v, u, 0); n     v->update(); n   } n   void cut(node* u) { n     access(u); n     u->ch[0]->p = NULL; n     u->ch[0] = NULL; n     u->update(); n   } n   void cut(node* u, node* v) { cut(depth(u) > depth(v) ? u : v); } n   void make_root(node* u) { n     access(u); n     u->reverse(); n     access(u); n     assert(!u->ch[0] && !u->ch[1]); n   } n   void access(node* u) { n     for (node *v = u, *pre = NULL; v; v = v->p) { n       node* tmp = v; n       while (!tmp->is_root()) tmp = tmp->p; n       swap(v->parent, tmp->parent); n       v->splay(); n       if (pre) v->update_vsub(pre, false); n       if (v->ch[1]) v->update_vsub(v->ch[1], true); n       v->ch[1] = pre; n       v->update(); n       pre = v; n     } n     u->splay(); n     assert(!u->ch[1]); n   } n   node* operator[](int i) { return &data[i]; } n   int operator[](node* i) { return i - &data[0]; } n   vector<node> data; n   link_cut_tree(int n) : data(n) {} n }; n template <typename pnode> n struct splay_tree { n   pnode ch[2], p; n   splay_tree() { ch[0] = ch[1] = p = NULL; } n   virtual void update() {} n   virtual void push() {} n   int dir() { n     if (!p) return -2; n     if (p->ch[0] == this) return 0; n     if (p->ch[1] == this) return 1; n     return -1; n   } n   bool is_root() { return dir() < 0; } n   friend void set_link(pnode u, pnode v, int d) { n     if (v) v->p = u; n     if (d >= 0) u->ch[d] = v; n   } n   void rotate() { n     assert(!is_root()); n     int x = dir(); n     pnode g = p; n     set_link(g->p, static_cast<pnode>(this), g->dir()); n     set_link(g, ch[x ^ 1], x); n     set_link(static_cast<pnode>(this), g, x ^ 1); n     g->update(); n   } n   void splay() { n     while (!is_root() && !p->is_root()) { n       p->p->push(), p->push(), push(); n       dir() == p->dir() ? p->rotate() : rotate(); n       rotate(); n     } n     if (!is_root()) p->push(), push(), rotate(); n     push(); n     update(); n   } n }; n template <typename pnode> n struct splay_tree_lct : splay_tree<pnode> { n   using splay_tree<pnode>::ch; n   bool rev; n   splay_tree_lct() : splay_tree<pnode>() { rev = 0; } n   virtual void update() override {} n   virtual void push() override { n     if (rev) { n       if (ch[0]) ch[0]->reverse(); n       if (ch[1]) ch[1]->reverse(); n       rev = 0; n     } n   } n   virtual void reverse() { n     rev ^= 1; n     swap(ch[0], ch[1]); n   } n }; n const int inf = -1e8; n template <typename pnode> n struct splay_tree_vchs : splay_tree<splay_tree_vchs<pnode>*> { n   using splay_tree<splay_tree_vchs<pnode>*>::ch; n   pnode key; n   int x; n   array<int, 4> y; n   splay_tree_vchs(const pnode& key) n       : splay_tree<splay_tree_vchs<pnode>*>(), key(key) { n     build(); n   } n   void build() { n     x = key->x; n     y[0] = key->pp[0]; n     y[1] = 0; n     y[2] = key->pp[1]; n     y[3] = inf; n   } n   void update() override { n     build(); n     for (int c = 0; c < 2; ++c) n       if (ch[c]) { n         x = max(x, ch[c]->x); n         for (int i = 0; i < 4; i += 2) { n           if (ch[c]->y[i] > y[i]) { n             y[i + 1] = y[i]; n             y[i] = ch[c]->y[i]; n             if (ch[c]->y[i + 1] > y[i + 1]) y[i + 1] = ch[c]->y[i + 1]; n           } else if (ch[c]->y[i] > y[i + 1]) n             y[i + 1] = ch[c]->y[i]; n         } n       } n   } n   void push() override {} n   static void push_back(splay_tree_vchs*& u, const pnode& key) { n     if (!u) { n       u = new splay_tree_vchs(key); n       return; n     } n     while (u->ch[1]) u = u->ch[1]; n     u->ch[1] = new splay_tree_vchs(key); n     u->ch[1]->p = u; n     u = u->ch[1]; n     u->splay(); n   } n   static void erase(splay_tree_vchs*& u, splay_tree_vchs* v) { n     v->splay(); n     if (!v->ch[0]) { n       u = v->ch[1]; n     } else if (!v->ch[1]) { n       u = v->ch[0]; n     } else { n       u = v->ch[0]; n       u->p = NULL; n       while (u->ch[1]) u = u->ch[1]; n       u->ch[1] = v->ch[1]; n       v->ch[1]->p = u; n       u->splay(); n     } n     if (u) u->p = NULL; n     delete v; n   } n }; n const array<int, 4> ainf = {0, inf, 0, inf}; n struct node : splay_tree_lct<node*> { n   bool val, len, sval; n   int slen; n   int x; n   array<int, 4> pp; n   splay_tree_vchs<node*>*root, *parent; n   node() : splay_tree_lct() { n     root = parent = NULL; n     val = len = sval = 0; n     slen = x = 0; n     pp = ainf; n   } n   void update() override { n     splay_tree::update(); n     x = 0; n     sval = val; n     slen = len; n     array<int, 4> up = ainf, dw = ainf; n     array<int, 2> v1 = {0, inf}, v2 = v1; n     bool upsval = val; n     int upslen = len; n     bool dwsval = val; n     int dwslen = len; n     if (ch[0]) { n       x = max(x, ch[0]->x); n       up = ch[0]->pp; n       sval ^= ch[0]->sval; n       slen += ch[0]->slen; n       upsval ^= ch[0]->sval; n       upslen += ch[0]->slen; n     } n     if (ch[1]) { n       x = max(x, ch[1]->x); n       dw = ch[1]->pp; n       sval ^= ch[1]->sval; n       slen += ch[1]->slen; n       dwsval ^= ch[1]->sval; n       dwslen += ch[1]->slen; n     } n     if (root) { n       x = max(x, root->x); n       v1[0] = root->y[0]; n       v1[1] = root->y[2]; n       v2[0] = root->y[1]; n       v2[1] = root->y[3]; n     } n     pp[0] = up[0], pp[1] = up[1]; n     pp[2] = dw[2], pp[3] = dw[3]; n     for (int i = 0; i < 2; ++i) { n       x = max(x, len + max({up[2 + i] + dw[i ^ val], up[2 + i] + v1[i ^ val], n                             dw[i] + v1[i ^ val], v1[i] + v2[i ^ val]})); n       pp[i ^ upsval] = max(pp[i ^ upsval], upslen + max(dw[i], v1[i])); n       pp[2 + (i ^ dwsval)] = n           max(pp[2 + (i ^ dwsval)], dwslen + max(up[2 + i], v1[i])); n     } n   } n   void update_vsub(node* v, bool add) { n     if (add) { n       splay_tree_vchs<node*>::push_back(root, v); n       v->parent = root; n     } else { n       splay_tree_vchs<node*>::erase(root, v->parent); n       v->parent = NULL; n     } n   } n   void push() override { splay_tree_lct::push(); } n   void reverse() override { n     splay_tree_lct::reverse(); n     swap(pp[0], pp[2]); n     swap(pp[1], pp[3]); n   } n }; n int main() { n   ios_base::sync_with_stdio(0), cin.tie(0); n   int n; n   cin >> n; n   link_cut_tree<node> lct(2 * n); n   for (int i = 1, u, v, w; i < n; ++i) { n     cin >> u >> v >> w; n     --u, --v; n     lct[n + i]->val = w; n     lct[n + i]->len = true; n     lct[n + i]->update(); n     lct.link(lct[u], lct[n + i]); n     lct.link(lct[n + i], lct[v]); n   } n   int q; n   cin >> q; n   for (int i = 0, u; i < q; ++i) { n     cin >> u; n     lct.access(lct[n + u]); n     lct[n + u]->val ^= 1; n     lct[n + u]->update(); n     cout << lct[n + u]->x <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2e6 + 5; n int n, m; n namespace BCC { n const int N = 202020; n vector<int> bcc[N]; n vector<int> k; n int cnt, dfn[N], low[N], id[N], st[N], _st, _, to[N]; n void dfs(int c, int dep, vector<int> g[]) { n   int cc = 0; n   st[_st++] = c; n   dfn[c] = low[c] = dep; n   for (auto t : g[c]) { n     if (!dfn[t]) { n       dfs(t, dep + 1, g); n       low[c] = min(low[c], low[t]); n     } else if (dfn[t] != dfn[c] - 1 || cc++) n       low[c] = min(low[c], dfn[t]); n   } n   if (low[c] == dfn[c]) { n     to[_] = st[_st - 1]; n     do { n       id[st[--_st]] = _; n     } while (st[_st] != c); n     _++; n   } n } n int solve(int n, vector<int> g[]) { n   cnt = 0; n   fill_n(dfn, n, _ = 0); n   fill_n(low, n, _st = 0); n   fill_n(bcc, n, vector<int>()); n   for (int i = (0); i < (n); i++) n     if (!dfn[i]) dfs(i, 1, g), cnt++; n   for (int i = (0); i < (n); i++) n     for (auto j : g[i]) n       if (id[i] != id[j]) bcc[id[i]].push_back(id[j]); n   return cnt; n } n }  // namespace BCC n vector<int> g[N]; n int main() { n   cin >> n >> m; n   if (n == 2) { n     cout << -1; n     return 0; n   } n   for (int i = (1); i < (m + 1); i++) { n     int u, v; n     cin >> u >> v; n     u--, v--; n     g[u].push_back(v); n     g[v].push_back(u); n   } n   BCC::solve(n, g); n   int leaf = 0; n   vector<int> s; n   for (int i = (0); i < (BCC::_); i++) { n     if ((int)BCC::bcc[i].size() == 1) leaf++, s.push_back(BCC::to[i] + 1); n   } n   int ans = (leaf + 1) / 2; n   cout << ans <<   n ; n   if (leaf & 1) ans--; n   for (int i = ans; i <= leaf - 1; ++i) n     cout << s[i] <<     << s[i - ans] <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2548; n bool g[N][N], c[N][N], v[N][N]; n int ng[N][N], sg[N][N], sc[N][N]; n int c_square, c_circle, n; n template <class T> n inline T sqr(T x) { n   return x * x; n } n int qx[N * N], qy[N * N], tcnt; n inline void solve(int x, int y) { n   const int dx[4] = {0, 0, 1, -1}, dy[4] = {-1, 1, 0, 0}; n   int l(0), r(0); n   pair<int, int> aux(x, y); n   ++r; n   qx[r] = x; n   qy[r] = y; n   v[x][y] = true; n   while (l < r) { n     ++l; n     int cx(qx[l]), cy(qy[l]); n     for (int i = 0; i < 4; ++i) { n       int nx = cx + dx[i], ny = cy + dy[i]; n       if (!v[nx][ny] && g[nx][ny]) { n         ++r; n         qx[r] = nx; n         qy[r] = ny; n         v[nx][ny] = true; n       } n     } n   } n   int sqdmax(0), s(r); n   if (s < 120) { n     ++tcnt; n     return; n   } n   for (int i = 1; i <= r; ++i) aux = min(aux, pair<int, int>(qx[i], qy[i])); n   for (int i = 1; i <= r; ++i) n     sqdmax = max(sqdmax, sqr(qx[i] - aux.first) + sqr(qy[i] - aux.second)); n   if (s < (double)sqdmax * 0.4 || s > (double)sqdmax * 0.86) return; n   if (s > (double)sqdmax * 0.73) n     ++c_circle; n   else n     ++c_square; n } n double calcRatio(int xl, int yl, int xr, int yr) { n   return double(sg[xr][yr] - sg[xl - 1][yr] - sg[xr][yl - 1] + n                 sg[xl - 1][yl - 1]) / n          double(sc[xr][yr] - sc[xl - 1][yr] - sc[xr][yl - 1] + n                 sc[xl - 1][yl - 1]); n } n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; ++i) n     for (int j = 1; j <= n; ++j) { n       int t; n       scanf( %d , &t); n       g[i][j] = t; n       c[i][j] = 1; n       sg[i][j] = sg[i - 1][j] + sg[i][j - 1] - sg[i - 1][j - 1] + g[i][j]; n       sc[i][j] = sc[i - 1][j] + sc[i][j - 1] - sc[i - 1][j - 1] + c[i][j]; n     } n   for (int i = 1; i <= n; ++i) n     for (int j = 1; j <= n; ++j) { n       ng[i][j] |= calcRatio(i - 2, j - 2, i + 2, j + 2) > 0.9; n       ng[i][j] |= calcRatio(i, j, i + 4, j + 4) > 0.6; n       ng[i][j] |= calcRatio(i - 4, j - 4, i, j) > 0.6; n       ng[i][j] |= calcRatio(i - 4, j, i, j + 4) > 0.6; n       ng[i][j] |= calcRatio(i, j - 4, i + 4, j) > 0.6; n     } n   for (int i = 1; i <= n; ++i) n     for (int j = 1; j <= n; ++j) g[i][j] = ng[i][j]; n   for (int i = 1; i <= n; ++i) n     for (int j = 1; j <= n; ++j) n       if (!v[i][j] && g[i][j]) solve(i, j); n   printf( %d %d n , c_circle, c_square); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX = 1e5 + 4; n int main() { n   int n; n   cin >> n; n   int sum[101] = {0}; n   for (int i = 0, num; i < n; ++i) { n     cin >> num; n     sum[i + 1] = sum[i] + num; n   } n   if (sum[n] != 0) { n     cout <<  YES n1 n ; n     cout <<  1   << n << endl; n     return 0; n   } n   int i; n   for (i = 1; i < n; ++i) { n     if (sum[i] != 0 && sum[n] - sum[i] != 0) break; n   } n   if (i == n) n     cout <<  NO n ; n   else { n     cout <<  YES n2 n ; n     cout <<  1   << i << endl; n     cout << i + 1 <<     << n << endl; n   } n   return 0; n } n


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


#include <bits/stdc++.h> n int main() { n   int l, i, flag = 0; n   char s[50]; n   scanf( %s , s); n   l = strlen(s); n   for (i = 0; i < l; i++) { n     if (s[0] == s[i]) flag = flag + 1; n   } n   if (flag == l) { n     printf( %d , 0); n     return 0; n   } n   flag = 0; n   for (i = 0; i < (l / 2); i++) { n     if (s[i] != s[l - i - 1]) { n       flag = flag + 1; n       break; n     } n   } n   if (flag == 0) n     printf( %d , l - 1); n   else n     printf( %d , l); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int flag = 0, i, k; n   string str, s; n   cin >> str; n   if (str.at(0) ==  - ) { n     flag = 1; n     str.erase(0, 1); n   } n   if (flag == 1) cout <<  ( ; n   cout <<  $ ; n   if ((int)str.find( . ) != -1) n     s = str.substr(0, str.find( . )); n   else n     s = str.substr(0); n   k = s.length() % 3; n   for (i = 0; i < s.length(); i++) { n     if (i % 3 == k && i != 0) cout <<  , ; n     cout << str.at(i); n   } n   cout <<  . ; n   if (str.find( . ) == -1) { n     cout <<  00 ; n     goto jump; n   } n   s = str.substr(str.find( . ) + 1); n   s +=  0 ; n   s = s.substr(0, 2); n   cout << s; n jump: n   if (flag == 1) cout <<  ) ; n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char str[100400]; n int len; n long long k; n int r, ret; n long long calc(int x) { return len - x; } n int Q[100400]; n char res[100400]; n void solve(int x) { n   int i, j; n   for (j = 0; j < 26; j++) { n     long long sum = 0; n     queue<int> q; n     for (i = 0; i < r; i++) { n       if (Q[i] + 1 < len && str[Q[i] + 1] ==  a  + j) { n         sum += calc(Q[i] + 1); n         q.push(Q[i] + 1); n       } n     } n     if (sum >= k) { n       r = 0; n       while (!q.empty()) { n         Q[r++] = q.front(); n         q.pop(); n       } n       break; n     } else { n       k -= sum; n     } n   } n   res[ret++] =  a  + j; n   k -= r; n   if (k > 0) solve(j); n } n int main() { n   int i, j; n   while (scanf( %s , str) != EOF) { n     scanf( %d , &k); n     len = strlen(str); n     ret = 0; n     if (k > (1LL * (len + 1) * len) / 2) { n       cout <<  No such line.  << endl; n       continue; n     } n     for (j = 0; j < 26; j++) { n       long long sum = 0; n       r = 0; n       for (i = 0; i < len; i++) { n         if (str[i] ==  a  + j) { n           sum += calc(i); n           Q[r++] = i; n         } n       } n       if (sum >= k) { n         break; n       } else { n         k -= sum; n       } n     } n     res[ret++] =  a  + j; n     k -= r; n     if (k > 0) solve(j); n     res[ret] =   0 ; n     cout << res << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = int(1e9); n const double eps = 1e-4; n const double pi = 4 * atan(double(1)); n const int N = int(3e5) + 100; n const int M = int(1e6) + 100; n const int sizes[] = {3600, 60, 1, -1}; n const int MOD1 = int(1e9) + 7; n const int X1 = 4243; n struct _hash { n   int a; n   _hash() {} n   _hash(int a) : a(a) {} n }; n _hash operator+(const _hash& a, const _hash& b) { n   _hash c(a.a + b.a); n   if (c.a >= MOD1) { n     c.a -= MOD1; n   } n   return c; n } n _hash operator-(const _hash& a, const _hash& b) { n   _hash c(a.a - b.a); n   if (c.a < 0) { n     c.a += MOD1; n   } n   return c; n } n _hash operator*(const _hash& a, const _hash& b) { n   return _hash((1LL * a.a * b.a) % MOD1); n } n bool operator==(const _hash& a, const _hash& b) { return a.a == b.a; } n struct tq { n   int a, b, ab, c, d, cd; n }; n struct node { n   int val; n   node** _next; n }; n const _hash X(X1); n int n; n int h[N], _prev[N], _rank[N], val[N], p[N]; n bool used[N]; n _hash st[N], rev_st[N]; n _hash pw[2 * N]; n vector<pair<int, int*> > lca[N]; n node* ver[N]; n vector<int> g[N]; n tq q[M]; n char s[N]; n int get(int a) { n   if (_prev[a] != a) { n     _prev[a] = get(_prev[a]); n   } n   return _prev[a]; n } n inline void merge(int a, int b, int c) { n   a = get(a); n   b = get(b); n   if (_rank[a] < _rank[b]) { n     swap(a, b); n   } n   _prev[b] = a; n   if (_rank[a] == _rank[b]) { n     ++_rank[a]; n   } n   val[a] = c; n } n inline node* clone(node* v, int lev) { n   node* res = new node(); n   res->val = v->val; n   if (sizes[lev] != -1) { n     int cnt = n         max(((lev == 0 ? n : sizes[lev - 1]) + sizes[lev] - 1) / sizes[lev], 1); n     res->_next = new node*[cnt]; n     for (int i = 0; i < cnt; ++i) { n       res->_next[i] = v->_next[i]; n     } n   } n   return res; n } n node* set_val(node* v, int lev, int pos, int val) { n   v = clone(v, lev); n   if (sizes[lev] == -1) { n     v->val = val; n     return v; n   } n   v->_next[pos / sizes[lev]] = n       set_val(v->_next[pos / sizes[lev]], lev + 1, pos % sizes[lev], val); n   return v; n } n int get_val(node* v, int pos) { n   int lev = 0; n   while (sizes[lev] != -1) { n     v = v->_next[pos / sizes[lev]]; n     pos %= sizes[lev]; n     ++lev; n   } n   return v->val; n } n void dfs(int v, int pv, node* cur) { n   used[v] = true; n   p[v] = pv; n   if (pv != -1) { n     g[v].erase(find((g[v]).begin(), (g[v]).end(), pv)); n     h[v] = h[pv] + 1; n   } else { n     h[v] = 0; n   } n   cur = set_val(cur, 0, h[v], v); n   ver[v] = cur; n   st[v] = (pv == -1 ? _hash(0) : st[pv]) + pw[h[v]] * _hash(s[v]); n   rev_st[v] = (pv == -1 ? _hash(0) : rev_st[pv]) + pw[n - h[v]] * _hash(s[v]); n   for (int i = 0; i < int((lca[v]).size()); ++i) { n     if (used[lca[v][i].first]) { n       *(lca[v][i].second) = val[get(lca[v][i].first)]; n     } n   } n   for (int i = 0; i < int((g[v]).size()); ++i) { n     dfs(g[v][i], v, cur); n     merge(g[v][i], v, v); n   } n } n inline int len(int a, int b, int ab) { return h[a] + h[b] - 2 * h[ab] + 1; } n inline _hash get(int v, int lca) { n   return (rev_st[v] - (p[lca] == -1 ? _hash(0) : rev_st[p[lca]])) * pw[h[v]]; n } n inline int get_ver(int v, int len) { n   len = h[v] - len + 1; n   return get_val(ver[v], len); n } n inline _hash get_hash(int a, int b, int ab, int len) { n   int first = h[a] - h[ab] + 1; n   if (len <= first) { n     return get(a, get_ver(a, len)); n   } n   len -= first; n   int ver = get_ver(b, h[b] - h[ab] + 1 - len); n   return get(a, ab) + (st[ver] - st[ab]) * pw[n + first - (h[ab] + 1)]; n } n int main() { n   scanf( %d , &n); n   gets(s); n   gets(s); n   for (int i = 0; i < n - 1; ++i) { n     int a, b; n     scanf( %d %d , &a, &b); n     --a; n     --b; n     g[a].push_back(b); n     g[b].push_back(a); n   } n   pw[0] = _hash(1); n   for (int i = 1; i <= 2 * n; ++i) { n     pw[i] = pw[i - 1] * X; n   } n   int m; n   scanf( %d , &m); n   for (int i = 0; i < m; ++i) { n     scanf( %d %d %d %d , &q[i].a, &q[i].b, &q[i].c, &q[i].d); n     --q[i].a; n     --q[i].b; n     --q[i].c; n     --q[i].d; n     lca[q[i].a].push_back(make_pair(q[i].b, &q[i].ab)); n     lca[q[i].b].push_back(make_pair(q[i].a, &q[i].ab)); n     lca[q[i].c].push_back(make_pair(q[i].d, &q[i].cd)); n     lca[q[i].d].push_back(make_pair(q[i].c, &q[i].cd)); n   } n   for (int i = 0; i < n; ++i) { n     _prev[i] = i; n     _rank[i] = 1; n     val[i] = i; n   } n   int root = 0; n   node* vers = new node[100]; n   int lev; n   for (lev = 0; sizes[lev] != -1; ++lev) { n     vers[lev]._next = new node*[max( n         ((lev == 0 ? n : sizes[lev - 1]) + sizes[lev] - 1) / sizes[lev], 1)]; n   } n   for (--lev; lev >= 0; --lev) { n     for (int j = 0; j < max(((lev == 0 ? n : sizes[lev - 1]) + sizes[lev] - 1) / n                                 sizes[lev], n                             1); n          ++j) { n       vers[lev]._next[j] = &vers[lev + 1]; n     } n   } n   dfs(root, -1, &vers[0]); n   for (int i = 0; i < m; ++i) { n     int ans = 0, l = 1, n         r = min(len(q[i].a, q[i].b, q[i].ab), len(q[i].c, q[i].d, q[i].cd)); n     while (l <= r) { n       int mid = (l + r) / 2; n       _hash h1 = get_hash(q[i].a, q[i].b, q[i].ab, mid); n       _hash h2 = get_hash(q[i].c, q[i].d, q[i].cd, mid); n       if (h1 == h2) { n         ans = mid; n         l = mid + 1; n       } else { n         r = mid - 1; n       } n     } n     printf( %d n , ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void readn(int &x) { n   char c; n   x = 0; n   do { n     c = getchar(); n   } while (c <  0  || c >  9 ); n   do { n     x = x * 10 + c -  0 ; n     c = getchar(); n   } while (c <=  9  && c >=  0 ); n } n const int MAXN = 101 * 1000; n int k, n, maxb, t, out = 0; n int a[MAXN], fen[MAXN], v[MAXN]; n inline void add(int pos, int val) { n   if (val > out) out = val; n   v[pos] = val; n   while (pos <= maxb) { n     if (fen[pos] < val) fen[pos] = val; n     pos += pos & -pos; n   } n } n inline int rmax(int pos) { n   int tot = 0; n   while (pos) { n     if (tot < fen[pos]) tot = fen[pos]; n     pos -= pos & -pos; n   } n   return tot; n } n int solve() { n   memset(fen, 0, sizeof fen); n   memset(v, 0, sizeof v); n   out = 0; n   for (register int rep = (0); rep < (int)(t); ++rep) n     for (register int i = (0); i < (int)(n); ++i) n       if (a[i]) { n         add(a[i], rmax(a[i] - 1) + 1); n         if (rep + 1 >= a[i] || v[a[i]] == a[i]) a[i] = 0; n         if (out == n || out == maxb) break; n       } n   return out; n } n int main() { n   scanf( %d %d %d %d , &k, &n, &maxb, &t); n   t = min(n, min(t, maxb)); n   while (k--) { n     for (register int i = (0); i < (int)(n); ++i) readn(a[i]); n     printf( %d n , solve()); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long mod = 1e9 + 7; n long long n, k, m, f[100005][15][20]; n long long count(long long x) { n   long long sum = 0; n   while (x) sum++, x -= (x & -x); n   return sum; n } n signed main() { n   scanf( %lld%lld%lld , &n, &k, &m); n   f[0][0][0] = 1; n   for (long long i = 0; i < n; i++) { n     for (long long j = 0; j <= k; j++) { n       for (long long s = 0; s < (1 << m); s++) { n         f[i + 1][j][s >> 1] = (f[i + 1][j][s >> 1] + f[i][j][s]) % mod; n         f[i + 1][j + 1][(s >> 1) | (1 << (m - 1))] = n             (f[i + 1][j + 1][(s >> 1) | (1 << (m - 1))] + n              (1ll + count(s)) * f[i][j][s]) % n             mod; n       } n     } n   } n   long long ans = 0; n   for (long long i = 0; i < (1 << m); i++) ans = (ans + f[n][k][i]) % mod; n   printf( %lld n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 700000; n int n, g, r; n int l[MAXN]; n long long sum[MAXN]; n long long d[MAXN]; n long long cycle; n int m; n long long q[MAXN], code[MAXN]; n int minv[MAXN]; n void build(int l, int r, int v) { n   minv[v] = n + 1; n   if (l != r) n     build(l, (l + r) >> 1, v << 1), build(((l + r) >> 1) + 1, r, (v << 1) + 1); n } n void change(int p, int l, int r, int v, int x) { n   if (l > p || r < p) return; n   minv[v] = x; n   if (l != r) n     change(p, l, (l + r) >> 1, v << 1, x), n         change(p, ((l + r) >> 1) + 1, r, (v << 1) + 1, x); n } n int getmin(int L, int R, int l, int r, int v) { n   if (L > r || l > R) return n + 1; n   if (L <= l && r <= R) return minv[v]; n   return min(getmin(L, R, l, (l + r) >> 1, v << 1), n              getmin(L, R, ((l + r) >> 1) + 1, r, (v << 1) + 1)); n } n int process(int u, int curt) { n   assert(curt < g); n   int l, r; n   l = g - curt; n   r = cycle - 1 - curt; n   l = (1LL * l + code[u]) % cycle; n   r = (1LL * r + code[u]) % cycle; n   int p1, p2; n   p1 = lower_bound(q, q + m, l) - q; n   p2 = lower_bound(q, q + m, r + 1) - q - 1; n   if (l <= r) { n     if (p1 > p2) return n + 1; n     return getmin(p1, p2, 0, m - 1, 1); n   } n   int ret = n + 1; n   if (p1 < m) ret = min(ret, getmin(p1, m - 1, 0, m - 1, 1)); n   assert(p2 >= 0); n   ret = min(ret, getmin(0, p2, 0, m - 1, 1)); n   return ret; n } n int main() { n   scanf( %d%d%d , &n, &g, &r); n   cycle = g + r; n   for (int i = 0; i <= n; i++) scanf( %d , l + i); n   for (int i = 1; i <= n + 1; i++) sum[i] = sum[i - 1] + l[i - 1]; n   for (int i = 1; i <= n + 1; i++) code[i] = sum[i] % cycle; n   for (int i = 0; i <= n + 1; i++) q[m++] = code[i]; n   sort(q, q + m); n   m = unique(q, q + m) - q; n   build(0, m - 1, 1); n   for (int i = n, pos; i > 1; i--) { n     pos = process(i, 0); n     assert(pos == n + 1 || (sum[pos] - sum[i]) % cycle >= g); n     assert(pos > i); n     d[i] = d[pos] + sum[pos] - sum[i]; n     if (pos != n + 1) d[i] += cycle - (sum[pos] - sum[i]) % cycle; n     change(lower_bound(q, q + m, code[i]) - q, 0, m - 1, 1, i); n   } n   int test_num; n   scanf( %d , &test_num); n   for (int pos; test_num--;) { n     long long tim; n     scanf( %I64d , &tim); n     tim += sum[1]; n     if (tim % cycle >= g) tim += cycle - tim % cycle; n     pos = process(1, tim % cycle); n     assert(pos); n     assert((sum[pos] - sum[1] + tim) % cycle >= g || pos == n + 1); n     long long res = d[pos] + sum[pos] - sum[1] + tim; n     if (pos != n + 1) res += cycle - (sum[pos] - sum[1] + tim) % cycle; n     printf( %I64d n , res); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n class Solver { n  public: n   void input() { n     cin >> n; n     a.resize(n); n     for (int i = 0; i < n; i++) { n       cin >> a[i]; n     } n   } n   void print() { cout << solve() << endl; } n  n  private: n   vector<int> a; n   int n; n   long long f(int x) { n     long long ans = 0; n     for (int i = 0; i < n; i++) { n       int j = lower_bound(a.begin(), a.end(), x - a[i]) - a.begin(); n       if (i < j) { n         ans += j - i - 1; n       } else { n         break; n       } n     } n     return ans; n   } n   int solve() { n     int ans = 0; n     for (int i = 30; i >= 0; i--) { n       for (int j = 0; j < n; j++) { n         a[j] = (a[j] & ((1 << (i + 1)) - 1)); n       } n       sort(a.begin(), a.end()); n       long long cur = f(1 << (i + 1)) - f(1 << i); n       cur += f(1 << (i + 2)) - f((1 << i) + (1 << (i + 1))); n       if (cur & 1) { n         ans = (ans | (1 << i)); n       } n     } n     return ans; n   } n }; n int main() { n   ios::sync_with_stdio(false); n   Solver solver; n   solver.input(); n   solver.print(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double eps = 1e-6; n const double PI = 3.14159265358979323846264338f; n const double pi = acos(-1.0); n const int inf = 0x3f3f3f3f; n const long long mod = 1e9 + 7; n const int MAXN = 1005; n inline int read() { n   int c = 0, f = 1; n   char ch = getchar(); n   while (ch <  0  || ch >  9 ) { n     if (ch ==  - ) f = -1; n     ch = getchar(); n   } n   while (ch >=  0  && ch <=  9 ) { n     c = c * 10 + ch -  0 ; n     ch = getchar(); n   } n   return c * f; n } n struct node { n   int w, h; n } e[MAXN]; n int n; n int ans = inf; n bool vis[MAXN]; n int main() { n   n = read(); n   for (int i = 1; i <= n; i++) { n     e[i].w = read(); n     e[i].h = read(); n   } n   auto solve = [](int x) -> void { n     memset(vis, false, sizeof(vis)); n     priority_queue<int> q; n     int tot = 0; n     int w = 0; n     for (int i = 1; i <= n; i++) { n       if (e[i].h > x) { n         vis[i] = true; n         tot++; n         w += e[i].h; n         if (e[i].w > x) return; n       } n     } n     for (int i = 1; i <= n; i++) { n       if (!vis[i]) { n         if (e[i].w <= x) q.push(e[i].w - e[i].h); n         w += e[i].w; n       } n     } n     while (tot < n / 2 && !q.empty()) { n       int ww = q.top(); n       q.pop(); n       if (ww > 0) { n         w -= ww; n         tot++; n       } else n         break; n     } n     if (tot <= n / 2) ans = min(ans, w * x); n   }; n   for (int i = 1; i <= 1000; i++) { n     solve(i); n   } n   cout << ans <<   n ; n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n bool isLeaf[100001] = {0}; n bool isCorrect[100001] = {0}; n bool nowCorrect[100001] = {0}; n bool allVisited[100001] = {0}; n bool visited = false; n vector<int> solution; n vector<vector<int> > old_pony_ville, pony_ville; n bool dfs(int nodo) { n   if (!isLeaf[nodo]) { n     solution.push_back(nodo); n     nowCorrect[nodo] = !nowCorrect[nodo]; n     for (int i = 0; i < pony_ville[nodo].size(); i++) { n       do { n         visited = dfs(pony_ville[nodo][i]); n       } while (!isLeaf[pony_ville[nodo][i]]); n       if (visited) { n         solution.push_back(nodo); n         nowCorrect[nodo] = !nowCorrect[nodo]; n         if (!allVisited[pony_ville[nodo][i]]) { n           visited = dfs(pony_ville[nodo][i]); n           if (visited) { n             solution.push_back(nodo); n             nowCorrect[nodo] = !nowCorrect[nodo]; n           } n         } n       } n     } n     isLeaf[nodo] = true; n     return true; n   } else { n     allVisited[nodo] = true; n     if (nowCorrect[nodo] == isCorrect[nodo]) n       return false; n     else { n       nowCorrect[nodo] = !nowCorrect[nodo]; n       solution.push_back(nodo); n       return true; n     } n   } n } n void MST(int start) { n   bool isVisited[100001] = {0}; n   vector<int> visits; n   visits.push_back(start); n   while (!visits.empty()) { n     start = visits.back(); n     isVisited[start] = true; n     visits.pop_back(); n     for (int i = 0; i < old_pony_ville[start].size(); i++) { n       if (!isVisited[old_pony_ville[start][i]]) { n         pony_ville[start].push_back(old_pony_ville[start][i]); n         visits.push_back(old_pony_ville[start][i]); n         isVisited[old_pony_ville[start][i]] = true; n       } n     } n   } n } n int main() { n   int n, m, a, b, start = 0; n   bool x; n   cin >> n >> m; n   n++; n   old_pony_ville.resize(n); n   pony_ville.resize(n); n   for (int i = 0; i < m; i++) { n     cin >> a >> b; n     old_pony_ville[a].push_back(b); n     old_pony_ville[b].push_back(a); n   } n   for (int i = 1; i < n; i++) { n     cin >> x; n     if (x) start = i; n     isCorrect[i] = x; n   } n   MST(start); n   for (int i = 1; i < n; i++) { n     if (pony_ville[i].size() == 0) isLeaf[i] = true; n   } n   dfs(start); n   allVisited[start] = true; n   if (nowCorrect[start] != isCorrect[start]) solution.pop_back(); n   for (int i = 1; i < n; i++) { n     if (!allVisited[i] && isCorrect[i]) { n       cout << -1; n       return 0; n     } n   } n   cout << solution.size() << endl; n   for (int i = 0; i < solution.size(); i++) { n     cout << solution[i] <<    ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long INFLL = 2 * (long long)1e18 + 100; n const long long INFINT = 2 * (long long)1e9 + 100; n const double PI = atan(1) * 4; n const double EPS = 1e-6; n const long long SEED = (long long)1e3 + 7; n const long long MOD = 998244353; n const long long NMAX = (long long)1e5 + 5; n vector<long long> v; n long long sum[NMAX]; n long long solve(long long n) { n   vector<long long> temp; n   for (long long i = 1; i <= n; i++) temp.push_back(i); n   do { n     for (auto i : temp) v.push_back(i); n   } while (next_permutation(temp.begin(), temp.end())); n   long long sol = 0; n   for (long long i = 1; i <= v.size(); i++) { n     sum[i] = sum[i - 1] + v[i - 1]; n     if (i >= n) { n       long long here = sum[i] - sum[i - n]; n       if (here == n * (n + 1) / 2) sol++; n     } n   } n   return sol; n } n long long fact(long long x) { n   if (x == 1) return 1; n   return x * fact(x - 1) % MOD; n } n int32_t main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   long long n; n   cin >> n; n   long long sol = n * fact(n) % MOD; n   long long prev = 1; n   for (long long i = n; i >= 2; i--) { n     prev = prev * i % MOD; n     sol = sol - prev; n     if (sol < 0) sol += MOD; n   } n   cout << sol; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void positionInFraction(); n int main() { n   positionInFraction(); n   return 0; n } n void positionInFraction() { n   int b, c, rpta, division; n   long long a, posicion; n   cin >> a >> b >> c; n   bool hayRpta = false; n   posicion = 1; n   while (posicion < 100000 and !hayRpta) { n     a = a * 10; n     division = a / b; n     if (division % 10 == c) { n       cout << posicion; n       hayRpta = true; n       break; n     } n     a = a % b; n     posicion++; n   } n   if (hayRpta) { n   } else { n     cout << -1; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const double eps = 1e-5; n template <typename T> n void cmin(T &x, const T &y) { n   if (y < x) x = y; n } n template <typename T> n void cmax(T &x, const T &y) { n   if (y > x) x = y; n } n template <typename T> n void read(T &x) { n   x = 0; n   char c = getchar(); n   bool f = 0; n   while (!isdigit(c) && c !=  - ) c = getchar(); n   if (c ==  - ) f = 1, c = getchar(); n   while (isdigit(c)) x = x * 10 + c -  0 , c = getchar(); n   if (f) x = -x; n } n struct vec { n   double x, y; n   vec(const double &x0 = 0, const double &y0 = 0) : x(x0), y(y0) {} n   vec operator+(const vec &t) const { return vec(x + t.x, y + t.y); } n   vec operator-(const vec &t) const { return vec(x - t.x, y - t.y); } n   vec operator*(const double &t) const { return vec(x * t, y * t); } n   double len2() const { return x * x + y * y; } n   bool operator<(const vec &t) const { n     return (fabs(x - t.x) > eps) ? (x < t.x) : (y < t.y); n   } n   vec rot_90_a() const { return vec(-y, x); } n }; n double crs(const vec &a, const vec &b) { return a.x * b.y - a.y * b.x; } n double dot(const vec &a, const vec &b) { return a.x * b.x + a.y * b.y; } n vector<vec> convex(vector<vec> src) { n   vector<vec> stk; n   sort(src.begin(), src.end()); n   for (auto i = src.begin(); i != src.end(); i++) { n     while (stk.size() >= 2 && n            crs(*i - stk.end()[-1], stk.end()[-1] - stk.end()[-2]) >= -eps) n       stk.pop_back(); n     stk.emplace_back(*i); n   } n   int top = stk.size(); n   for (auto i = src.rbegin(); i != src.rend(); i++) { n     while (stk.size() > top && n            crs(*i - stk.end()[-1], stk.end()[-1] - stk.end()[-2]) >= -eps) n       stk.pop_back(); n     stk.emplace_back(*i); n   } n   stk.pop_back(); n   return stk; n } n int n, m; n vector<vec> A, B; n void input() { n   read(n), read(m); n   for (int i = 1; i <= n; i++) { n     vec tmp; n     read(tmp.x), read(tmp.y); n     A.emplace_back(tmp); n   } n   for (int i = 1; i <= m; i++) { n     vec tmp; n     read(tmp.x), read(tmp.y); n     B.emplace_back(tmp); n   } n } n vec lin_lin_int(vec p1, vec v1, vec p2, vec v2) { n   double k = crs(p2 - p1, v2) / crs(v1, v2); n   return p1 + v1 * k; n } n bool try_plain(vec a, vec b, const vector<vec> &in, const vector<vec> &out) { n   double mxc = +1e30, mnc = -1e30; n   vec mid = (a + b) * 0.5, per = (b - a).rot_90_a(); n   for (auto i : in) n     if (crs(b - a, i - a) > eps) n       cmax(mnc, n            crs(b - a, n                lin_lin_int((i + a) * 0.5, (i - a).rot_90_a(), mid, per) - a)); n     else if (crs(b - a, i - a) < -eps) n       cmin(mxc, n            crs(b - a, n                lin_lin_int((i + a) * 0.5, (i - a).rot_90_a(), mid, per) - a)); n     else if (dot(b - a, i - a) > dot(b - a, b - a) || dot(b - a, i - a) < 0) n       return false; n   for (auto i : out) n     if (crs(b - a, i - a) > eps) n       cmin(mxc, n            crs(b - a, n                lin_lin_int((i + a) * 0.5, (i - a).rot_90_a(), mid, per) - a)); n     else if (crs(b - a, i - a) < -eps) n       cmax(mnc, n            crs(b - a, n                lin_lin_int((i + a) * 0.5, (i - a).rot_90_a(), mid, per) - a)); n     else if (dot(b - a, i - a) < dot(b - a, b - a) && dot(b - a, i - a) > 0) n       return false; n   if (mxc > mnc + eps) n     return true; n   else n     return false; n } n bool check(vector<vec>::iterator in_beg, vector<vec>::iterator in_end, n            const vector<vec> &in, const vector<vec> &out) { n   if (try_plain(*in_beg, *(in_end - 1), in, out)) return true; n   if (in_end - in_beg < 3) return 0; n   vec lft = *in_beg, rgt = *(in_end - 1); n   double mxd = -1e18, tmp; n   vector<vec>::iterator mxp; n   for (auto i = in_beg + 1; i != in_end - 1; i++) { n     double val = -dot(*i - lft, *i - rgt) / crs(*i - lft, *i - rgt); n     if (val > mxd) mxd = val, mxp = i; n   } n   if (check(in_beg, mxp + 1, in, out) || check(mxp, in_end, in, out)) n     return true; n   else n     return false; n } n int main() { n   input(); n   vector<vec> cA = convex(A), cB = convex(B); n   if (check(cA.begin(), cA.end(), A, B)) n     puts( YES ); n   else if (check(cB.begin(), cB.end(), B, A)) n     puts( YES ); n   else n     puts( NO ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int M = 1600; n int dr[] = {-1, 0, 1, 0}, dc[] = {0, 1, 0, -1}; n int n, m, pr[M][M], pc[M][M]; n char g[M][M], f[M][M]; n bool dfs(int r, int c) { n   int u = (r % n + n) % n, v = (c % m + m) % m; n   if ( #  == g[u][v]) return 0; n   if (f[u][v]) return r != pr[u][v] || c != pc[u][v]; n   f[u][v] = 1, pr[u][v] = r, pc[u][v] = c; n   for (int d = 0; d < 4; ++d) n     if (dfs(r + dr[d], c + dc[d])) return 1; n   return 0; n } n int main(void) { n   cin >> n >> m; n   for (int i = 0; i < n; ++i) cin >> g[i]; n   for (int i = 0; i < n; ++i) n     for (int j = 0; j < m; ++j) n       if ( S  == g[i][j]) n         cout << (dfs(i + n * 2, j + m * 2) ?  Yes  :  No ) << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int k; n   cin >> k; n   if (k % 2 != 0) { n     cout <<  -1 ; n     return 0; n   } n   for (int i = 0; i < k; i++) { n     for (int j = 0; j < k; j++) { n       for (int t = 0; t < k; t++) { n         if (i % 2 == 0) { n           if ((j % 4 <= 1 && t % 4 <= 1) || (j % 4 >= 2 && t % 4 >= 2)) { n             cout <<  w ; n           } else { n             cout <<  b ; n           } n         } else { n           if ((j % 4 <= 1 && t % 4 <= 1) || (j % 4 >= 2 && t % 4 >= 2)) { n             cout <<  b ; n           } else { n             cout <<  w ; n           } n         } n       } n       cout << endl; n     } n     cout << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n string i2s(int x) { n   stringstream ss; n   ss << x; n   return ss.str(); n } n int s2i(string str) { n   istringstream ss(str); n   int nro; n   ss >> nro; n   return nro; n } n int n; n int NRO5(int nro) { n   int cnt = 0; n   while (nro % 5 == 0) { n     cnt++; n     nro /= 5; n   } n   return cnt; n } n int main() { n   int A[500005]; n   map<int, vector<int> > mapa; n   map<int, vector<int> >::iterator it; n   for (int i = 1; i < 500005; i++) { n     A[i] = A[i - 1] + NRO5(i); n     mapa[A[i]].push_back(i); n   } n   scanf( %d n , &n); n   if (mapa[n].size() == 0) { n     putchar( 0 ); n     putchar(  n ); n   } else { n     printf( %d n , (int)mapa[n].size()); n     for (int i = 0; i < mapa[n].size(); i++) { n       printf( %d%c , mapa[n][i], i == mapa[n].size() - 1 ? 10 : 32); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5; n long long int n; n long long int t[2 * N]; n int main() { n   long long int n, k; n   cin >> n >> k; n   long long int a[k], ans = 1e18, g = 0; n   for (int i = 0; i < k; i++) { n     cin >> a[i]; n     if (n % a[i] < ans) { n       ans = n % a[i]; n       g = i; n     } n   } n   cout << g + 1 <<     << n / a[g] <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 3e5 + 10; n int n; n set<pair<pair<int, int>, int> > a; n int ans[MAXN]; n inline pair<pair<int, int>, int> mpi(int a, int b, int c) { n   return make_pair(make_pair(a, b), c); n } n void exit() { n   cout <<  Impossible ; n   exit(0); n } n int main() { n   cin >> n; n   for (int i = 1; i <= n; i++) { n     pair<pair<int, int>, int> x; n     scanf( %d , &x.first.second); n     x.first.first = x.first.second % 3; n     x.second = i; n     a.insert(x); n   } n   a.insert(mpi(1000, 1000, 1000)); n   a.insert(mpi(-1000, -1000, -1000)); n   pair<pair<int, int>, int> x; n   int olimp = 0; n   for (int i = 0; i < n; i++) { n     set<pair<pair<int, int>, int> >::iterator it = n         a.lower_bound(mpi(i % 3, i - olimp, 0)); n     x = *it; n     if (i % 3 != x.first.first) { n       it--; n       x = *it; n     } n     if (i % 3 != x.first.first) exit(); n     bool flag = false; n     while (i - olimp + 1 < x.first.second) { n       it--; n       x = *it; n       flag = true; n     } n     if (x.first.second < 0 || i % 3 != x.first.first) exit(); n     olimp = i + 1 - x.first.second; n     ans[i + 1] = x.second; n     a.erase(it); n   } n   cout <<  Possible  << endl; n   for (int i = 1; i <= n; i++) printf( %d  , ans[i]); n } n


#include <bits/stdc++.h> n using namespace std; n const double pp = 0.00000001; n const int maxn = 100005; n double ans, xo, da, mid; n int ci, w, i, n, x[maxn], y[maxn]; n bool pd(double k) { n   double ww, l = -1e9, r = 1e9; n   int i; n   for (i = 1; i <= n; i++) { n     if (k * k < (y[i] - k) * (y[i] - k)) { n       return 0; n     } n     ww = -1.0 * y[i] * y[i] + 2 * y[i] * k; n     ww = sqrt(ww); n     if (l < x[i] - ww) l = x[i] - ww; n     if (r > x[i] + ww) r = x[i] + ww; n   } n   if (l <= r) n     return true; n   else n     return false; n } n int main() { n   scanf( %d , &n); n   for (i = 1; i <= n; i++) { n     scanf( %d%d , &x[i], &y[i]); n     if (y[i] > 0) n       w++; n     else n       y[i] = -y[i]; n   } n   if (w != 0 && w != n) { n     printf( -1 n ); n     return 0; n   } n   xo = 0; n   da = 50000000000000.4949989; n   ci = 0; n   while (ci <= 100) { n     ci++; n     mid = (xo + da) / 2; n     if (pd(mid)) { n       ans = mid; n       da = mid; n     } else n       xo = mid; n   } n   printf( %lf n , mid); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int64_t t, a[200005], n; n   cin >> t; n   while (t--) { n     int64_t dem = 1; n     cin >> n; n     for (int i = 1; i <= n; i++) cin >> a[i]; n     sort(a + 1, a + n + 1); n     for (int i = 1; i < n; i++) { n       if (a[i] != a[i + 1]) dem++; n     } n     cout << dem << endl; n   } n } n