#include <bits/stdc++.h> n using namespace std; n int main() { n   int h, m; n   scanf( %d:%d , &h, &m); n   double dm = (m) / 60.0, dh = (h % 12 + dm) / 12; n   cout << 360 * (dh) <<     << 360 * (dm) << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a[1005], b[1005]; n int main() { n   int n; n   scanf( %d , &n); n   for (int i = 0; i < n; i++) { n     scanf( %d , &a[i]); n   } n   for (int i = 0; i < n; i++) { n     scanf( %d , &b[i]); n   } n   int ans = 0; n   for (int i = 0; i < n; i++) { n     int p = 0; n     int q = 0; n     for (int j = i; j < n; j++) { n       p |= a[j]; n       q |= b[j]; n       ans = max(ans, p + q); n     } n   } n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long mod = 1000000007; n const long long inf = LLONG_MAX; n void IO() { n   ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); n   cout.setf(ios::fixed); n   srand(chrono::high_resolution_clock::now().time_since_epoch().count()); n } n long long pw(long long x, long long y, long long p = inf) { n   long long res = 1; n   x = x % p; n   if (x == 0) return 0; n   while (y > 0) { n     if (y & 1) res = (res * x) % p; n     y = y >> 1; n     x = (x * x) % p; n   } n   return res; n } n long long invmod(long long a, long long m) { return pw(a, m - 2, m); } n long long cl(long long a, long long x) { n   return a % x == 0 ? a / x : a / x + 1; n } n long long gcd(long long a, long long b) { n   if (a == 0) return b; n   return gcd(b % a, a); n } n void run_time_terror() { n   long long n; n   cin >> n; n   cout <<  ? 1 3  << endl; n   long long a, b; n   cin >> a; n   vector<long long> ans(n); n   cout <<  ? 2 3  << endl; n   cin >> b; n   ans[0] = a - b; n   for (long long i = 0; i < n - 1; ++i) { n     long long x; n     if (i == 1) { n       x = b; n     } else { n       cout <<  ?   << i + 1 <<     << i + 2 << endl; n       cin >> x; n     } n     ans[i + 1] = x - ans[i]; n   } n   cout <<  !  ; n   for (long long i = 0; i < n; ++i) { n     cout << ans[i] <<    ; n   } n } n int32_t main() { n   cout << setprecision(0); n   long long tt = 1; n   for (long long case_no = 1; case_no <= tt; case_no++) { n     run_time_terror(); n   } n   return 0; n } n


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


#include <bits/stdc++.h> n const long long int MOD = 1e9 + 7; n int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1}; n int dy8[] = {1, -1, 1, -1, 0, 0, -1, 1}; n int dx4[] = {0, 0, 1, -1}; n int dy4[] = {1, -1, 0, 0}; n using namespace std; n void vok() { n   ios_base::sync_with_stdio(false); n   cout.tie(NULL); n   cin.tie(NULL); n } n long long int gcd(long long int a, long long int b) { n   if (b == 0) return a; n   return gcd(b, a % b); n } n long long int lcm(long long int a, long long int b) { n   return ((a * b) / gcd(a, b)); n } n vector<long long int> pp; n void gen() { n   vector<bool> prime(33000, true); n   prime[0] = prime[1] = false; n   for (int p = 0; p * p <= 33000; p++) { n     if (prime[p]) { n       for (int i = p * p; i <= 33000; i += p) prime[i] = false; n     } n   } n   for (int i = 0; i < 33000; i++) n     if (prime[i]) pp.push_back(i); n } n long long int find(vector<int>& A, int n) {} n void solve() { n   long long int n, m, x, y, a, b, k; n   a = b = x = y = k = 0; n   long long int ans = 0, res = 0; n   string s1, s2; n   cin >> s1 >> s2; n   n = s1.size(); n   if (s1 == s2) { n     cout <<  YES  << endl; n     return; n   } n   if (n == 1 and s1 != s2) { n     cout <<  NO  << endl; n     return; n   } n   int dp[26]{0}; n   for (int i = 0; i < n; i++) { n     dp[s1[i] -  a ]++; n   } n   for (int i = 0; i < n; i++) { n     if (dp[s2[i] -  a ] >= 1) { n       cout <<  YES  << endl; n       return; n     } n   } n   cout <<  NO  << endl; n } n int main() { n   vok(); n   int t = 1; n   cin >> t; n   while (t--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 100005, M = 50005; n const int inf = 0x3f3f3f3f; n const long long INF = 1000000000000000000ll; n const long long mod = 998244353; n const double pi = acos(-1.0); n const double eps = 1e-6; n vector<int> rec; n struct OP { n   char str[4]; n   int num; n   void get() { n     scanf( %s , str); n     if (str[0] ==  a  || str[0] ==  d ) { n       scanf( %d , &num); n     } n   } n } op[N]; n struct node { n   int l, r, cnt; n   long long num[5]; n   int nt; n   void init() { n     memset(num, 0, sizeof(num)); n     cnt = 0; n   } n   node() {} n   node(int l, int r, int nt) { n     this->l = l; n     this->r = r; n     this->nt = nt; n   } n   void Equal(node tmp) { n     for (int i = 0; i < 5; i++) { n       num[i] = tmp.num[i]; n     } n     nt = tmp.nt; n     cnt = tmp.cnt; n   } n }; n struct segTree { n   node tree[N * 4]; n   void build(int l, int r, int id) { n     tree[id] = node(l, r, 1); n     tree[id].init(); n     if (l == r) return; n     int mid = ((l + r) >> 1); n     build(l, mid, (id << 1)); n     build(mid + 1, r, (id << 1 | 1)); n   } n   void pushUp(int id) { n     tree[id].Equal(tree[(id << 1)]); n     int nt = tree[(id << 1)].nt; n     for (int i = 1, j = nt, cnt = 1; cnt <= 5; n          i = (i + 1) % 5, j = (j + 1) % 5, cnt++) { n       if (tree[(id << 1 | 1)].num[i] == 0) break; n       tree[id].num[j] += tree[(id << 1 | 1)].num[i]; n     } n     tree[id].cnt += tree[(id << 1 | 1)].cnt; n     tree[id].nt = (tree[id].nt + tree[(id << 1 | 1)].cnt) % 5; n   } n   void update(int id, int pos, int val) { n     int l = tree[id].l, r = tree[id].r; n     if (l == r) { n       tree[id].num[1] += val; n       if (val > 0) n         tree[id].nt++, tree[id].cnt++; n       else n         tree[id].nt--, tree[id].cnt--; n       return; n     } n     int mid = ((l + r) >> 1); n     if (pos <= mid) n       update((id << 1), pos, val); n     else n       update((id << 1 | 1), pos, val); n     pushUp(id); n   } n } segT; n map<int, int> mp; n void discre() { n   sort(rec.begin(), rec.end()); n   int siz = rec.size(); n   for (int i = 0; i < siz; i++) { n     mp.insert(pair<int, int>(rec[i], i)); n   } n } n int main() { n   int n; n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) { n     op[i].get(); n     if (op[i].str[0] ==  a ) rec.push_back(op[i].num); n   } n   discre(); n   if (rec.size() == 0) { n     printf( 0 n ); n     return 0; n   } n   segT.build(0, rec.size() - 1, 1); n   for (int i = 1; i <= n; i++) { n     if (op[i].str[0] ==  a ) { n       segT.update(1, mp[op[i].num], op[i].num); n     } else if (op[i].str[0] ==  d ) { n       segT.update(1, mp[op[i].num], -op[i].num); n     } else { n       printf( %lld n , segT.tree[1].num[3]); n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n namespace io { n void _(int &k) { n   char c; n   int e = 1; n   k = 0; n   while ((c = getchar()) >  9  || c <  0 ) n     if (c ==  - ) e = -1; n   k = c -  0 ; n   while ((c = getchar()) <=  9  && c >=  0 ) { n     k *= 10; n     k += c -  0 ; n   } n   k *= e; n } n void _(long long &k) { n   char c; n   int e = 1; n   k = 0; n   while ((c = getchar()) >  9  || c <  0 ) n     if (c ==  - ) e = -1; n   k = c -  0 ; n   while ((c = getchar()) <=  9  && c >=  0 ) { n     k *= 10; n     k += c -  0 ; n   } n   k *= e; n } n void _(char &c) { n   while ((c = getchar()) ==     || c ==   n ) n     ; n } n void _(double &c) { scanf( %lf , &c); } n void _(char *s) { n   char c; n   while ((c = getchar()) != EOF && c !=     && c != 10) *s++ = c; n } n template <class t1, class t2> n void _(t1 &a, t2 &b) { n   _(a); n   _(b); n } n template <class t1, class t2, class t3> n void _(t1 &a, t2 &b, t3 &c) { n   _(a); n   _(b); n   _(c); n } n template <class t1, class t2, class t3, class t4> n void _(t1 &a, t2 &b, t3 &c, t4 &d) { n   _(a); n   _(b); n   _(c); n   _(d); n } n template <class t1, class t2, class t3, class t4, class t5> n void _(t1 &a, t2 &b, t3 &c, t4 &d, t5 &e) { n   _(a); n   _(b); n   _(c); n   _(d); n   _(e); n } n void _p(double k) { printf( %.6lf , k); } n void _p(char *c) { n   for (; *c; putchar(*c++)) n     ; n } n void _p(const char *c) { n   for (; *c; putchar(*c++)) n     ; n } n void _p(char c) { putchar(c); } n template <class T> n void _p0(T k) { n   if (k >= 10) _p0(k / 10); n   putchar(k % 10 +  0 ); n } n template <class T> n void _p(T k) { n   if (k < 0) { n     putchar( - ); n     _p0(-k); n   } else n     _p0(k); n } n template <class T> n void __p(T k) { n   _p(k); n   putchar(   ); n } n template <class T> n void _pn(T k) { n   _p(k); n   putchar(  n ); n } n template <class t1, class t2> n void _p(t1 a, t2 b) { n   __p(a); n   _pn(b); n } n template <class t1, class t2, class t3> n void _p(t1 a, t2 b, t3 c) { n   __p(a); n   __p(b); n   _pn(c); n } n template <class t1, class t2, class t3, class t4> n void _p(t1 a, t2 b, t3 c, t4 d) { n   __p(a); n   __p(b); n   __p(c); n   _pn(d); n } n template <class T> n void op(T *a, int n) { n   int i; n   n--; n   for (i = 1; i <= n; i++) __p(a[i]); n   _pn(a[n + 1]); n } n int gi() { n   int first; n   _(first); n   return first; n } n long long gll() { n   long long first; n   _(first); n   return first; n } n }  // namespace io n int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } n void fcl() { n   fclose(stdin); n   fclose(stdout); n } n void fop(const char *s) { n   char c[256], d[256]; n   memset(c, 0, sizeof(c)); n   memset(d, 0, sizeof(d)); n   strcpy(c, s); n   strcpy(d, s); n   freopen(strcat(c,  .in ),  r , stdin); n   freopen(strcat(d,  .out ),  w , stdout); n } n int eq(double a, double b) { n   return a + 0.00000000001 >= b && b + 0.00000000001 >= a; n } n template <class T> n void _ma(T &a, T b) { n   if (a < b) a = b; n } n template <class T> n void _mi(T &a, T b) { n   if (a > b) a = b; n } n const int N = 1234567, EE = 100000000, GG = 1000000000, ima = 2147483647; n using namespace io; n int n, m, a[N], f[N], an, T; n char s[555][555]; n int main() { n   int i, j, a1, a2; n   _(n); n   for (i = 1; i <= n; i++) n     for (j = 1; j <= n; j++) _(s[i][j]); n   for (i = 1; i <= n; i++) n     for (j = 1; j <= n; j++) n       an += s[i][j] ==  X  && s[i + 1][j + 1] ==  X  && n             s[i + 1][j - 1] ==  X  && s[i - 1][j + 1] ==  X  && n             s[i - 1][j - 1] ==  X ; n   _pn(an); n } n


#include <bits/stdc++.h> n using namespace std; n const long long N = 100010; n long long n, a[N]; n double bit[N]; n inline void add(long long x, double val) { n   for (; x <= n; x += x & -x) bit[x] += val; n } n inline double ask(long long x) { n   double sum = 0; n   for (; x; x -= x & -x) sum += bit[x]; n   return sum; n } n int main() { n   scanf( %lld , &n); n   double tt = 0.0; n   for (long long i = 1; i <= n; i++) { n     scanf( %lld , a + i); n     tt += (ask(n) - ask(a[i])); n     add(a[i], 1.0); n   } n   double ans = 0.0; n   for (long long i = 1; i <= n; i++) { n     ans += (0.25 * i * (i - 1) + tt) * (n - i + 1); n   } n   memset(bit, 0, sizeof(bit)); n   double cur = 0.0; n   for (long long i = 1; i <= n; i++) { n     double tmp = ask(n) - ask(a[i]) + cur; n     ans -= tmp; n     add(a[i], i); n     cur = tmp; n   } n   ans = ans / n / (n + 1) * 2.0; n   printf( %.12lf n , ans); n } n


#include <bits/stdc++.h> n using namespace std; n int mas[100][100], n, used[100], p = 0, s = 0, to; n vector<vector<int> > g; n void dfs(int from) { n   used[from] = 1; n   for (int i = 0; i < 2; i++) { n     to = g[from][i]; n     if (!used[to]) { n       p += mas[from][to]; n       dfs(to); n     } n   } n } n int main() { n   cin >> n; n   g.resize(n); n   for (int i = 0; i < n; i++) { n     int a, b, c; n     cin >> a >> b >> c; n     g[a - 1].push_back(b - 1); n     g[b - 1].push_back(a - 1); n     mas[a - 1][b - 1] = c; n     s += c; n   } n   dfs(0); n   p += mas[to][0]; n   cout << min(p, s - p) << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long int insig; n void Out(vector<long long int> x) { n   for (long long int i = 0; i < x.size(); i++) { n     cout << x[i] <<    ; n   } n   cout << endl; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   long long int N; n   cin >> N; n   vector<pair<long long int, long long int> > p; n   long long int c1, c2; n   for (long long int i = 0; i < N; i++) { n     cin >> c1 >> c2; n     p.push_back(make_pair(c1, c2)); n   } n   long long int ans = n       (long long int)(N * (N - 1LL) * (N - 2LL) * (N - 3LL) * (N - 4LL)) / n       120LL; n   ans *= 5; n   long long int l; n   long long int a = 1; n   long long int b = -1; n   long double val; n   for (long long int i = 0; i < N; i++) { n     long long int x = p[i].first; n     long long int y = p[i].second; n     vector<long double> t1, t2, t3, t4, t5, t6, t7, t8; n     long double val; n     for (long long int j = 0; j < N; j++) { n       if (j == i) { n         continue; n       } n       if (p[j].first != x) { n         val = (long double)(((long double)(p[j].second - y)) / n                             ((long double)(p[j].first - x))); n       } n       if (p[j].first == x && p[j].second > y) { n         t6.push_back(0); n       } else if (p[j].first == x && p[j].second < y) { n         t8.push_back(0); n       } else if (p[j].first > x && p[j].second == y) { n         t5.push_back(val); n       } else if (p[j].first < x && p[j].second == y) { n         t7.push_back(val); n       } else if (p[j].first > x && p[j].second > y) { n         t1.push_back(val); n       } else if (p[j].first > x && p[j].second < y) { n         t4.push_back(-val); n       } else if (p[j].first < x && p[j].second > y) { n         t2.push_back(-val); n       } else if (p[j].first < x && p[j].second < y) { n         t3.push_back(val); n       } n     } n     sort(t1.begin(), t1.end()); n     sort(t2.begin(), t2.end()); n     sort(t3.begin(), t3.end()); n     sort(t4.begin(), t4.end()); n     for (long long int j = 0; j < t1.size(); j++) { n       l = (j + t5.size() + t4.size() + t8.size() + n            (long long int)(t3.end() - n                            lower_bound(t3.begin(), t3.end(), t1[j]))); n       ans -= (long long int)(l * (l - 1LL) * (l - 2LL)) / 6LL; n     } n     for (long long int j = 0; j < t2.size(); j++) { n       l = (t2.size() - j - 1 + t6.size() + t1.size() + t5.size() + n            (long long int)(lower_bound(t4.begin(), t4.end(), t2[j]) - n                            t4.begin())); n       ans -= (long long int)(l * (l - 1LL) * (l - 2LL)) / 6LL; n     } n     for (long long int j = 0; j < t3.size(); j++) { n       l = (j + t7.size() + t2.size() + t6.size() + n            (long long int)(t1.end() - n                            lower_bound(t1.begin(), t1.end(), t3[j]))); n       ans -= (long long int)(l * (l - 1LL) * (l - 2LL)) / 6LL; n     } n     for (long long int j = 0; j < t4.size(); j++) { n       l = (t4.size() - j - 1 + t8.size() + t3.size() + t7.size() + n            (long long int)(lower_bound(t2.begin(), t2.end(), t4[j]) - n                            t2.begin())); n       ans -= (long long int)(l * (l - 1LL) * (l - 2LL)) / 6LL; n     } n     if (t5.size() == 1) { n       l = (t4.size() + t8.size() + t3.size()); n       ans -= (long long int)(l * (l - 1LL) * (l - 2LL)) / 6LL; n     } n     if (t6.size() == 1) { n       l = (t1.size() + t5.size() + t4.size()); n       ans -= (long long int)(l * (l - 1LL) * (l - 2LL)) / 6LL; n     } n     if (t7.size() == 1) { n       l = (t2.size() + t6.size() + t1.size()); n       ans -= (long long int)(l * (l - 1LL) * (l - 2LL)) / 6LL; n     } n     if (t8.size() == 1) { n       l = (t3.size() + t7.size() + t2.size()); n       ans -= (long long int)(l * (l - 1LL) * (l - 2LL)) / 6LL; n     } n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = (int)1e5 + 10; n const long long INF = (long long)1e9; n struct Point { n   long long x, y; n   Point() : x(), y() {} n   void scan() { scanf( %lld%lld , &x, &y); } n   bool operator<(const Point &a) const { n     return y < a.y || (y == a.y && x < a.x); n   } n }; n long long sqr(long long a) { return a * a; } n Point p[N]; n long long prefMinX[N], prefMaxX[N]; n long long suffMinX[N], suffMaxX[N]; n int n; n void precalc() { n   for (int i = 0; i < n; i++) { n     prefMinX[i] = (i == 0 ? p[i].x : min(prefMinX[i - 1], p[i].x)); n     prefMaxX[i] = (i == 0 ? p[i].x : max(prefMaxX[i - 1], p[i].x)); n   } n   for (int i = n - 1; i >= 0; i--) { n     suffMinX[i] = (i == n - 1 ? p[i].x : min(suffMinX[i + 1], p[i].x)); n     suffMaxX[i] = (i == n - 1 ? p[i].x : max(suffMaxX[i + 1], p[i].x)); n   } n } n long long getMaxD(long long y1, long long y2, long long x1, long long x2) { n   long long d = max(sqr(y1 - y2), sqr(x1 - x2)); n   d = max(d, max(sqr(y1), sqr(y2)) + max(sqr(x1), sqr(x2))); n   return d; n } n bool check(long long d) { n   long long xD = sqr(prefMinX[n - 1] - prefMaxX[n - 1]); n   if (xD <= d) return true; n   int it = 0; n   int kek = n; n   42; n   for (int i = 0; i < n; i++) 42; n   42; n   for (int i = 0; i < n; i++) { n     if (i != 0 && p[i].y == p[i - 1].y) continue; n     while (it < n && (it <= i || (sqr(p[it].y - p[i].y) <= d))) it++; n     while (kek > 0 && llabs(p[kek - 1].y) > llabs(p[i].y)) kek--; n     int cur = min(kek, it); n     42; n     if (cur < i) break; n     long long y1 = p[i].y; n     long long y2 = p[cur - 1].y; n     if (i == 0 && cur == n) return true; n     long long x1, x2; n     if (i == 0) { n       x1 = suffMinX[cur]; n       x2 = suffMaxX[cur]; n     } else if (cur == n) { n       x1 = prefMinX[i - 1]; n       x2 = prefMaxX[i - 1]; n     } else { n       x1 = min(suffMinX[cur], prefMinX[i - 1]); n       x2 = max(suffMaxX[cur], prefMaxX[i - 1]); n     } n     long long curD = getMaxD(y1, y2, x1, x2); n     if (curD <= d) return true; n   } n   it = n - 1; n   kek = -1; n   42; n   for (int i = n - 1; i >= 0; i--) { n     if (i != n - 1 && p[i].y == p[i + 1].y) continue; n     while (it >= 0 && (it >= i || (sqr(p[it].y - p[i].y) <= d))) it--; n     while (kek<n - 1 & llabs(p[kek + 1].y)> llabs(p[i].y)) kek++; n     int cur = max(kek, it); n     42; n     if (cur > i) break; n     long long y1 = p[i].y; n     long long y2 = p[cur + 1].y; n     if (i == n - 1 && cur == -1) return true; n     long long x1, x2; n     if (i == n - 1) { n       x1 = prefMinX[cur]; n       x2 = prefMaxX[cur]; n     } else if (cur == -1) { n       x1 = suffMinX[i + 1]; n       x2 = suffMaxX[i + 1]; n     } else { n       x1 = min(prefMinX[cur], suffMinX[i + 1]); n       x2 = max(prefMaxX[cur], suffMaxX[i + 1]); n     } n     long long curD = getMaxD(y1, y2, x1, x2); n     if (curD <= d) return true; n   } n   return false; n } n int main() { n   scanf( %d , &n); n   for (int i = 0; i < n; i++) { n     p[i].scan(); n   } n   sort(p, p + n); n   precalc(); n   long long l = -1, r = (long long)1e18; n   while (r - l > 1) { n     long long mid = (l + r) / 2; n     if (check(mid)) n       r = mid; n     else n       l = mid; n   } n   printf( %lld n , r); n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( O3 ) n #pragma GCC target( avx2 ) n #pragma GCC optimize( unroll-loops ) n using namespace std; n const long long MN = 3005; n long long a[2], b[2], c[2], d[8], first[8], ra[2], rb[2], rc[2]; n inline bool check(long long f3, long long f5, long long f6) { n   for (long long i = 0; i < 2; i++) ra[i] = a[i], rb[i] = b[i], rc[i] = c[i]; n   ra[0] -= f5 + f6, rb[0] -= f3 + f6, rc[0] -= f3 + f5; n   if (ra[0] < 0 || rb[0] < 0 || rc[0] < 0) return 0; n   memset(first, 0, sizeof(first)); n   first[3] = f3, first[5] = f5, first[6] = f6; n   first[7] = min({d[7], ra[0], rb[0], rc[0]}); n   ra[0] -= first[7], rb[0] -= first[7], rc[0] -= first[7]; n   first[4] = min(d[4], ra[0]); n   first[2] = min(d[2], rb[0]); n   first[1] = min(d[1], rc[0]); n   long long sa = 0, sb = 0, sc = 0; n   for (long long i = 1; i <= 7; i++) { n     long long second = d[i] - first[i]; n     if (i & 1) sc += second; n     if (i & 2) sb += second; n     if (i & 4) sa += second; n   } n   if (sa > a[1] || sb > b[1] || sc > c[1]) return 0; n   for (long long i = 7; i >= 1; i--) printf( %lld  , first[i]); n   printf(  n ); n   return 1; n } n int32_t main() { n   cin.tie(0), cin.sync_with_stdio(0); n   long long t; n   cin >> t; n outer: n   while (t--) { n     cin >> a[0] >> b[0] >> c[0] >> a[1] >> b[1] >> c[1]; n     for (long long i = 1; i <= 7; i++) cin >> d[8 - i]; n     long long tota = 0, totb = 0, totc = 0; n     for (long long i = 1; i <= 7; i++) { n       if (i & 1) totc += d[i]; n       if (i & 2) totb += d[i]; n       if (i & 4) tota += d[i]; n     } n     if (tota > a[0] + a[1] || totb > b[0] + b[1] || totc > c[0] + c[1]) { n       printf( -1 n ); n       continue; n     } n     for (long long i = 0; i <= d[3]; i++) { n       for (long long j = 0; j <= d[5]; j++) { n         for (long long k = 0; k <= d[6]; k++) { n           if (check(i, j, k)) goto outer; n         } n       } n     } n     printf( -1 n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using std::sort; n int n; n char s[100000 + 1]; n struct SH { n   unsigned int s, h; n }; n struct SH cnt[100000 + 1]; n unsigned long long ans; n void read() { n   scanf( %d , &n); n   ans = 0; n   for (int i = 1; i <= n; ++i) { n     scanf( %s , s); n     int l = strlen(s); n     unsigned int sum = 0; n     for (int j = 0; j < l; ++j) n       if (s[j] ==  s ) n         ++sum; n       else n         ans += sum; n     cnt[i].s = sum; n     cnt[i].h = l - sum; n   } n } n bool compareSH(struct SH &x, struct SH &y) { return x.s * y.h > y.s * x.h; } n void chief() { n   sort(&cnt[1], &cnt[n] + 1, compareSH); n   unsigned int sum = 0; n   for (int i = 1; i <= n; ++i) { n     ans += (unsigned long long)sum * cnt[i].h; n     sum += cnt[i].s; n   } n } n void write() { printf( %I64u n , ans); } n int main() { n   read(); n   chief(); n   write(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct Data { n   long long l, r; n } a[200100]; n long long n, s, rmax, lmin; n void Docfile() { n   scanf( %lld%lld , &n, &s); n   rmax = 0; n   lmin = 1e18; n   for (int i = 1; i <= n; i++) { n     scanf( %lld%lld , &a[i].l, &a[i].r); n     rmax = max(rmax, a[i].r); n     lmin = min(lmin, a[i].l); n   } n } n bool cmp(Data &a, Data &b) { n   return ((a.l < b.l) || ((a.l == b.l) && (a.r < b.r))); n } n void Xuli() { n   sort(a + 1, a + 1 + n, cmp); n   long long sum1, sum2, dem1, dem2, dem3, F[200100]; n   long long d = lmin, c = rmax, g, kq = 0; n   while (d <= c) { n     g = (d + c) / 2; n     dem1 = dem2 = dem3 = sum1 = sum2 = 0; n     F[0] = 0; n     for (int i = 1; i <= n; i++) { n       if (a[i].r < g) { n         dem1++; n         sum1 += a[i].l; n       } else { n         if (a[i].l > g) { n           dem2++; n           sum2 += a[i].l; n         } else { n           dem3++; n           F[dem3] = F[dem3 - 1] + a[i].l; n         } n       } n     } n     if (dem1 > n / 2) { n       c = g - 1; n       continue; n     } n     if (dem2 > n / 2) { n       d = g + 1; n       continue; n     } n     if (dem1 < n / 2) sum1 += F[n / 2 - dem1]; n     if (dem2 < n / 2) sum2 += g * (n / 2 - dem2); n     if (sum1 + sum2 + g <= s) { n       kq = max(kq, g); n       d = g + 1; n     } else n       c = g - 1; n   } n   printf( %lld n , kq); n } n int main() { n   long t; n   scanf( %d , &t); n   for (int i = 1; i <= t; i++) { n     Docfile(); n     Xuli(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n int size(T& a) { n   return (int)a.size(); n } n template <typename T> n T sqr(T a) { n   return a * a; n } n #pragma comment(linker,  /STACK:60777216 ) n const int INF = int(1e9); n char s[10][10]; n bool can(int i, int j) { return i >= 0 && i < 8 && j >= 0 && j < 8; } n bool statue(int i, int j, int t) { n   for (int u = 0; u < 8; ++u) { n     if (s[u][j] ==  S ) { n       int dif = (i - u); n       if (t == dif) { n         return false; n       } n     } n   } n   return true; n } n struct pos { n   int i, j, t; n   pos() {} n   pos(int i, int j, int t) : i(i), j(j), t(t) {} n }; n int dist[8][8][200]; n int dj[9] = {+1, +1, 0, -1, -1, -1, 0, 1, 0}; n int di[9] = {0, +1, +1, +1, 0, -1, -1, -1, 0}; n int main() { n   queue<pos> q; n   for (int i = (0); i < (8); ++i) gets(s[i]); n   memset((dist), (255), sizeof(dist)); n   for (int i = (0); i < (8); ++i) n     for (int j = (0); j < (8); ++j) n       if (s[i][j] ==  M ) { n         q.push(pos(i, j, 0)); n         dist[i][j][0] = 0; n       } n   while (size(q)) { n     pos p = q.front(); n     q.pop(); n     if (s[p.i][p.j] ==  A ) { n       cout <<  WIN ; n       exit(0); n     } n     for (int u = (0); u < (9); ++u) { n       int ni = p.i + di[u]; n       int nj = p.j + dj[u]; n       if (can(ni, nj) && statue(ni, nj, p.t) && statue(ni, nj, p.t + 1) && n           dist[ni][nj][p.t + 1] == -1) { n         dist[ni][nj][p.t + 1] = 1; n         q.push(pos(ni, nj, p.t + 1)); n       } n     } n   } n   for (int i = (0); i < (8); ++i) n     for (int j = (0); j < (8); ++j) n       if (s[i][j] ==  A ) { n         for (int t = (0); t < (200); ++t) n           if (dist[i][j][t] != -1) { n             cout <<  WIN ; n             exit(0); n           } n       } n   cout <<  LOSE ; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s; n   cin >> s; n   int dot = -1; n   for (int i = 0; i < (int)(s).size(); ++i) { n     if (s[i] ==  . ) { n       dot = i; n     } n   } n   int deg = 0; n   if (dot == -1) { n     deg = (int)(s).size(); n     string t =  0.  + s; n     s = t; n   } else { n     deg = dot; n     string t =  0. ; n     for (int i = 0; i < (int)(s).size(); ++i) { n       if (s[i] !=  . ) { n         t += s[i]; n       } n     } n     s = t; n   } n   int lst = (int)(s).size() - 1; n   while (s[lst] ==  0 ) { n     --lst; n   } n   s = s.substr(0, lst + 1); n   if (s ==  0. ) { n     cout <<  0 n ; n     return 0; n   } n   int fst = 2; n   while (s[fst] ==  0 ) { n     ++fst; n   } n   s = s.substr(fst); n   deg -= fst - 1; n   cout << s[0]; n   if ((int)(s).size() > 1) { n     cout <<  . ; n     for (int i = 1; i < (int)(s).size(); ++i) { n       cout << s[i]; n     } n   } n   if (deg) { n     cout <<  E  << deg; n   } n   cout <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n namespace node_tre { n int tre[100005] = {}; n void update(int x, int val) { tre[x] += val; } n int ask(int x) { return tre[x]; } n void cover(int x) { tre[x] = 0; } n };  // namespace node_tre n using namespace node_tre; n struct node { n   int ty; n   int id; n   int tim; n   int val; n   int w; n } a[100005], b[100005]; n int n; n int ans[100005]; n int cnt; n map<int, int> has; n void cdq(int l, int r) { n   if (r == l) return; n   int mid = (l + r) >> 1; n   cdq(l, mid); n   cdq(mid + 1, r); n   int indl = l, indr = mid + 1, indb = l; n   while (indl <= mid && indr <= r) { n     if (a[indl].tim <= a[indr].tim) { n       if (a[indl].ty == 1) update(a[indl].val, a[indl].w); n       b[indb++] = a[indl++]; n     } else { n       if (a[indr].ty == 2) ans[a[indr].id] += ask(a[indr].val); n       b[indb++] = a[indr++]; n     } n   } n   while (indl <= mid) b[indb++] = a[indl++]; n   while (indr <= r) { n     if (a[indr].ty == 2) ans[a[indr].id] += ask(a[indr].val); n     b[indb++] = a[indr++]; n   } n   for (int i = l; i <= r; i++) { n     a[i] = b[i]; n     cover(a[i].val); n   } n } n int main() { n   memset(ans, -1, sizeof(ans)); n   cin >> n; n   for (int i = 1; i <= n; i++) { n     cin >> a[i].ty >> a[i].tim >> a[i].val; n     a[i].id = i; n     if (a[i].ty == 1) { n       a[i].w = 1; n       continue; n     } n     if (a[i].ty == 2) { n       a[i].ty = 1; n       a[i].w = -1; n       continue; n     } n     if (a[i].ty == 3) { n       ans[i] = 0; n       a[i].ty = 2; n       continue; n     } n   } n   for (int i = 1; i <= n; i++) { n     if (has[a[i].val] == 0) has[a[i].val] = ++cnt; n     a[i].val = has[a[i].val]; n   } n   cdq(1, n); n   for (int i = 1; i <= n; i++) n     if (ans[i] != -1) cout << ans[i] <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n int main() { n   int m, n, i, j, c; n   int coordenadas[3][2]; n   scanf( %d%d , &n, &m); n   char ciudad[n][m]; n   for (i = 0; i < n; i++) { n     for (j = 0; j < m; j++) { n       scanf(  n%c , &ciudad[i][j]); n     } n   } n   c = 0; n   for (i = 0; i < n; i++) { n     for (j = 0; j < m; j++) { n       if (ciudad[i][j] ==  * ) { n         coordenadas[c][0] = i; n         coordenadas[c][1] = j; n         c++; n       } n     } n   } n   if (coordenadas[0][0] != coordenadas[1][0] && n       coordenadas[0][0] != coordenadas[2][0]) n     printf( %d , coordenadas[0][0] + 1); n   else if (coordenadas[1][0] != coordenadas[0][0] && n            coordenadas[1][0] != coordenadas[2][0]) n     printf( %d , coordenadas[1][0] + 1); n   else n     printf( %d , coordenadas[2][0] + 1); n   printf(   ); n   if (coordenadas[0][1] != coordenadas[1][1] && n       coordenadas[0][1] != coordenadas[2][1]) n     printf( %d , coordenadas[0][1] + 1); n   else if (coordenadas[1][1] != coordenadas[0][1] && n            coordenadas[1][1] != coordenadas[2][1]) n     printf( %d , coordenadas[1][1] + 1); n   else n     printf( %d , coordenadas[2][1] + 1); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n signed main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   long long n, k; n   cin >> n >> k; n   string s; n   cin >> s; n   long long x = -1; n   for (long long i = 97; i <= 122; ++i) { n     char c = char(i); n     long long cnt = 0; n     for (long long i = 0; i < n; ++i) { n       if (s[i] == c) { n         long long c1 = 0; n         while (s[i] == c && c1 < k && i < n) { n           i++; n           c1++; n         } n         if (c1 == k) { n           cnt++; n           i--; n         } n       } n     } n     x = max(x, cnt); n   } n   cout << x <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n struct vertex { n   long long x, y; n   int adj[4], k; n } vv[30]; n void dfs(int p, int v, long long x, long long y, long long a, int d) { n   int i; n   vv[v].x = x; n   vv[v].y = y; n   d = (d + 2) % 4; n   for (i = 0; i < vv[v].k; i++) n     if (vv[v].adj[i] != p) { n       long long x_ = x, y_ = y; n       d = (d + 1) % 4; n       if (d == 0) n         x_ += a; n       else if (d == 1) n         y_ += a; n       else if (d == 2) n         x_ -= a; n       else n         y_ -= a; n       dfs(v, vv[v].adj[i], x_, y_, a / 2, d); n     } n } n int main() { n   int n, i, yes; n   scanf( %d , &n); n   yes = 1; n   for (i = 0; i < n; i++) vv[i].k = 0; n   for (i = 1; i < n; i++) { n     int u, v; n     scanf( %d%d , &u, &v); n     u--, v--; n     if (vv[u].k == 4 || vv[v].k == 4) { n       yes = 0; n       break; n     } n     vv[u].adj[vv[u].k++] = v; n     vv[v].adj[vv[v].k++] = u; n   } n   printf( %s n , yes ?  YES  :  NO ); n   if (yes) { n     dfs(-1, 0, 0, 0, 1LL << n, 0); n     for (i = 0; i < n; i++) printf( %lld %lld n , vv[i].x, vv[i].y); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = 0x3f3f3f3f; n const int maxn = 300000 + 10; n int n, m, s; n struct edge { n   bool t; n   int u, v; n } es[maxn]; n bool vis[maxn]; n vector<int> G[maxn]; n char ans[maxn]; n int cnt; n void dfsmax(int u) { n   vis[u] = true; n   cnt++; n   for (int i = 0; i < G[u].size(); i++) { n     edge& e = es[G[u][i]]; n     if (e.t) { n       if (e.u == u) { n         if (!vis[e.v]) { n           ans[G[u][i]] =  + ; n           dfsmax(e.v); n         } n       } else { n         if (!vis[e.u]) { n           ans[G[u][i]] =  - ; n           dfsmax(e.u); n         } n       } n     } else { n       if (!vis[e.v]) { n         dfsmax(e.v); n       } n     } n   } n } n void dfsmin(int u) { n   vis[u] = true; n   cnt++; n   for (int i = 0; i < G[u].size(); i++) { n     edge& e = es[G[u][i]]; n     if (e.t) { n       if (e.u == u) { n         ans[G[u][i]] =  - ; n       } else { n         ans[G[u][i]] =  + ; n       } n     } else if (!vis[e.v]) { n       dfsmin(e.v); n     } n   } n } n int main() { n   scanf( %d%d%d , &n, &m, &s); n   int tmp; n   for (int i = 0; i < m; i++) { n     scanf( %d%d%d , &tmp, &es[i].u, &es[i].v); n     G[es[i].u].push_back(i); n     es[i].t = (tmp == 2); n     if (tmp == 2) G[es[i].v].push_back(i), ans[i] =  + ; n   } n   cnt = 0; n   dfsmax(s); n   printf( %d n , cnt); n   for (int i = 0; i < m; i++) { n     if (es[i].t) printf( %c , ans[i]); n   } n   printf(  n ); n   cnt = 0; n   memset(vis, 0, sizeof(vis)); n   dfsmin(s); n   printf( %d n , cnt); n   for (int i = 0; i < m; i++) { n     if (es[i].t) printf( %c , ans[i]); n   } n   printf(  n ); n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 2e5 + 10; n int c[maxn], up[maxn], h[maxn]; n bool visited[maxn]; n set<int> s[maxn]; n vector<int> g[maxn]; n void dfs(int v, int par = -1) { n   c[v] = v; n   visited[v] = 1; n   up[v] = h[v]; n   int cnt = 0; n   for (auto u : g[v]) { n     if (u == par) n       cnt++; n     else if (!visited[u]) { n       h[u] = h[v] + 1; n       dfs(u, v); n       up[v] = min(up[v], up[u]); n       if (s[c[u]].size() > s[c[v]].size()) c[v] = c[u]; n     } else n       up[v] = min(up[v], h[u]); n   } n   if (cnt > 1) up[v] = min(up[v], h[v] - 1); n   for (auto u : g[v]) { n     if (h[u] == h[v] + 1 and c[u] != c[v]) { n       for (auto it : s[c[u]]) { n         if (s[c[v]].find(-it) != s[c[v]].end()) n           s[c[v]].erase(-it); n         else n           s[c[v]].insert(it); n       } n       s[c[u]].clear(); n     } n   } n   if (c[v] != v) { n     for (auto it : s[v]) { n       if (s[c[v]].find(-it) != s[c[v]].end()) n         s[c[v]].erase(-it); n       else n         s[c[v]].insert(it); n     } n     s[v].clear(); n   } n   if (up[v] < h[v]) return; n   if (s[c[v]].empty()) return; n   int minimum = *s[c[v]].begin(); n   auto it = s[c[v]].end(); n   it--; n   int maximum = *it; n   if (minimum < 0 and maximum > 0) { n     cout <<  No  << endl; n     exit(0); n   } n } n int par[maxn]; n int get_par(int v) { n   if (par[v] < 0) return v; n   return par[v] = get_par(par[v]); n } n void merge(int v, int u) { n   v = get_par(v), u = get_par(u); n   if (v == u) return; n   par[v] = u; n } n int main() { n   ios_base::sync_with_stdio(false); n   memset(par, -1, sizeof par); n   int n, m, q; n   cin >> n >> m >> q; n   for (int i = 0; i < m; i++) { n     int v, u; n     cin >> v >> u; n     g[v].push_back(u); n     g[u].push_back(v); n     merge(v, u); n   } n   string answer =  Yes ; n   for (int i = 0; i < q; i++) { n     int v, u; n     cin >> v >> u; n     if (get_par(v) != get_par(u)) answer =  No ; n     s[v].insert(i + 1); n     s[u].insert(-i - 1); n   } n   if (answer ==  No ) return cout << answer << endl, 0; n   for (int v = 1; v <= n; v++) n     if (!visited[v]) dfs(v); n   cout <<  Yes  << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int n, tt[1005]; n vector<int> a[1005]; n void dfs(int u) { n   if (tt[u] == 1) { n     printf( %d  , u); n     return; n   } n   tt[u] = 1; n   for (int i = 0; i < a[u].size(); ++i) dfs(a[u][i]); n } n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; ++i) { n     int x; n     scanf( %d , &x); n     a[i].push_back(x); n   } n   for (int i = 1; i <= n; ++i) { n     dfs(i); n     for (int j = 1; j <= n; ++j) tt[j] = 0; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long a[1000005]; n long long c[2000015]; n long long n; n int main() { n   ios_base::sync_with_stdio(0); n   cin >> n; n   long long ma = 0; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n     c[a[i]]++; n     ma = max(ma, a[i]); n   } n   long long ans = 0; n   for (int i = 0; i < 2000010; i++) { n     if (c[i] % 2 == 1) { n       c[i + 1] += c[i] / 2; n       c[i] = 1; n     } else { n       c[i + 1] += c[i] / 2; n       c[i] = 0; n     } n   } n   for (int i = 0; i < 2000010; i++) { n     ans += c[i]; n   } n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int ct[300005]; n vector<pair<int, int> > val; n int n, m; n bool check(int vl) { n   for (int i = 0; i < 300005; i++) ct[i] = 0; n   int count = 0; n   for (int i = 0; i < m; i++) { n     if (vl != val[i].first && vl != val[i].second) { n       count++; n       ct[val[i].first]++; n       if (val[i].second != val[i].first) { n         ct[val[i].second]++; n       } n     } n   } n   if (count == 0) return true; n   for (int i = 1; i < 300001; i++) { n     if (ct[i] == count) { n       return true; n     } n   } n   return false; n } n int main() { n   cin >> n >> m; n   for (int i = 0; i < m; i++) { n     int a, b; n     cin >> a >> b; n     val.push_back(make_pair(a, b)); n   } n   int first = val[0].first; n   int second = val[0].second; n   if (check(first)) { n     cout <<  YES n ; n   } else if (check(second)) { n     cout <<  YES n ; n   } else { n     cout <<  NO n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long l[5001], dp[5001][5001]; n void solve() { n   int n, k, ans = 0; n   cin >> n >> k; n   vector<int> v(n, 0); n   for (int i = 0; i < (int)(n); ++i) cin >> v[i]; n   sort(v.begin(), v.end()); n   for (int i = 0, j = 0; i < n; ++i) { n     while (v[i] - v[j] > 5) { n       j++; n     } n     l[i] = j; n   } n   for (int i = 1; i <= k; i++) { n     for (int j = 1; j <= n; j++) { n       dp[i][j] = max(dp[i][j - 1], dp[i - 1][l[j - 1]] + j - l[j - 1]); n     } n   } n   cout << dp[k][n] <<   n ; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   ; n   long long t = 1; n   while (t--) { n     solve(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int n, data, prev = 0, energy = 0; n   cin >> n; n   vector<long long int> v1(n); n   long long int ans = 0; n   for (long long int i = 0; i < n; i++) { n     cin >> data; n     if (energy < (data - prev)) { n       ans += ((data - prev) - energy); n       energy = 0; n       prev = data; n     } else { n       energy += (prev - data); n       prev = data; n     } n   } n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n const long long N = 2e5 + 10, M = N, INF = 0x3f3f3f3f, mod = 1e9 + 7, n                 base = 131; n long long n, t, ans; n long long a[N], s[N]; n long long phi(long long n) { n   long long res, a; n   res = a = n; n   for (long long i = 2; i <= a / i; i++) { n     if (a % i) continue; n     res = res / i * (i - 1); n     while (a % i == 0) a /= i; n   } n   if (a > 1) res = res / a * (a - 1); n   return res; n } n signed main() { n   long long p; n   cin >> p; n   cout << phi(p - 1); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, x, y, t, l[205], qd[205 + 205], qn[205 + 205], h[205], b1, b2, d1, d2, n     ret; n void build(int x, int y) { qd[++t] = y, qn[t] = l[x], l[x] = t; } n void dfs(int x, int y, int *d) { n   h[x] = 0; n   int mx1 = 0, mx2 = 0; n   for (int i = l[x]; i; i = qn[i]) { n     if (i == b1 || i == b2 || qd[i] == y) continue; n     dfs(qd[i], x, d); n     h[x] = max(h[x], h[qd[i]] + 1); n     if (h[qd[i]] + 1 >= mx1) n       mx2 = mx1, mx1 = h[qd[i]] + 1; n     else if (h[qd[i]] + 1 > mx2) n       mx2 = h[qd[i]] + 1; n   } n   *d = max(*d, mx1 + mx2); n } n int main() { n   scanf( %d , &n); n   t = 1; n   for (int i = 1; i < n; i++) scanf( %d%d , &x, &y), build(x, y), build(y, x); n   ret = 0; n   for (int i = 1; i <= n; i++) { n     for (int j = l[i]; j; j = qn[j]) { n       b1 = j; n       b2 = j ^ 1; n       d1 = d2 = 0; n       dfs(i, -1, &d1); n       dfs(qd[j], -1, &d2); n       ret = max(ret, d1 * d2); n     } n   } n   printf( %d n , ret); n   return 0; n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /STACK:1024000000,1024000000 ) n using namespace std; n const int maxn = 510005; n int n, m; n vector<int> g[maxn]; n char s[maxn]; n vector<int> dep[maxn]; n vector<int> op[maxn]; n int id[maxn][2]; n int deep[maxn]; n int mx[maxn]; n int dfs_clock = 1; n void dfs(int u, int d) { n   deep[u] = mx[u] = d; n   id[u][0] = dfs_clock++; n   dep[d].push_back(1 << (s[u] -  a )); n   op[d].push_back(id[u][0]); n   for (int i = 0; i < g[u].size(); i++) { n     dfs(g[u][i], d + 1); n     mx[u] = max(mx[u], mx[g[u][i]]); n   } n   id[u][1] = dfs_clock++; n } n int main() { n   int p; n   scanf( %d%d , &n, &m); n   for (int i = 2; i <= n; i++) { n     scanf( %d , &p); n     g[p].push_back(i); n   } n   scanf( %s , s + 1); n   dfs(1, 1); n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j < dep[i].size(); j++) { n       dep[i][j] ^= dep[i][j - 1]; n     } n   } n   int u, h; n   for (int i = 0; i < m; i++) { n     scanf( %d%d , &u, &h); n     if (h <= deep[u] || h > mx[u]) { n       printf( Yes n ); n     } else { n       int i = upper_bound(op[h].begin(), op[h].end(), id[u][0]) - op[h].begin(); n       int j = n           upper_bound(op[h].begin(), op[h].end(), id[u][1]) - op[h].begin() - 1; n       int a; n       if (i - 1 >= 0) n         a = dep[h][j] ^ dep[h][i - 1]; n       else n         a = dep[h][j]; n       int num = 0; n       for (int i = 0; i < 26; i++) { n         if (a & (1 << i)) num++; n       } n       if (num <= 1) n         printf( Yes n ); n       else n         printf( No n ); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MOD = 1000 * 1000 * 1000 + 7; n const int MAXN = 155; n int i, j, n, m, k, it1, it2, dp[MAXN][MAXN][MAXN][2][2], ans; n int partSum[2][2][MAXN][MAXN]; n void add(int &a, int b) { n   a += b; n   if (a >= MOD) a -= MOD; n } n int getSum(int mon1, int mon2, int leftBound1, int rightBound1, int leftBound2, n            int rightBound2) { n   int ans = 0; n   ans = partSum[mon1][mon2][rightBound1][rightBound2] - n         partSum[mon1][mon2][rightBound1][leftBound2 - 1] - n         partSum[mon1][mon2][leftBound1 - 1][rightBound2] + n         partSum[mon1][mon2][leftBound1 - 1][leftBound2 - 1]; n   while (ans >= MOD) ans -= MOD; n   while (ans < 0) ans += MOD; n   return ans; n } n int main() { n   scanf( %d %d , &n, &m); n   for (i = 1; i <= m; ++i) n     for (j = i; j <= m; ++j) { n       dp[1][i][j][0][0] = 1; n       ans += n; n     } n   for (i = 1; i <= m; ++i) n     for (j = 1; j <= m; ++j) n       partSum[0][0][i][j] = dp[1][i][j][0][0] + partSum[0][0][i - 1][j] + n                             partSum[0][0][i][j - 1] - n                             partSum[0][0][i - 1][j - 1]; n   for (i = 2; i <= n; ++i) { n     int cnt = 0; n     for (j = 1; j <= m; ++j) n       for (k = j; k <= m; ++k) { n         add(dp[i][j][k][0][0], getSum(0, 0, j, m, 1, k)); n         add(dp[i][j][k][1][1], getSum(1, 1, 1, j, k, m)); n         add(dp[i][j][k][1][1], getSum(0, 0, 1, j - 1, k + 1, m)); n         add(dp[i][j][k][1][1], getSum(0, 1, 1, j - 1, k, m)); n         add(dp[i][j][k][1][1], getSum(1, 0, 1, j, k + 1, m)); n         add(dp[i][j][k][0][1], getSum(0, 1, j, k, k, m)); n         add(dp[i][j][k][0][1], getSum(0, 0, j, k, k + 1, m)); n         add(dp[i][j][k][1][0], getSum(1, 0, 1, j, j, k)); n         add(dp[i][j][k][1][0], getSum(0, 0, 1, j - 1, j, k)); n       } n     for (j = 1; j <= m; ++j) n       for (k = 1; k <= m; ++k) n         for (it1 = 0; it1 <= 1; ++it1) n           for (it2 = 0; it2 <= 1; ++it2) { n             partSum[it1][it2][j][k] = dp[i][j][k][it1][it2]; n             add(cnt, dp[i][j][k][it1][it2]); n           } n     add(ans, 1LL * cnt * (n - i + 1) % MOD); n     for (it1 = 0; it1 <= 1; ++it1) n       for (it2 = 0; it2 <= 1; ++it2) n         for (j = 1; j <= m; ++j) n           for (k = 1; k <= m; ++k) { n             add(partSum[it1][it2][j][k], partSum[it1][it2][j - 1][k]); n             add(partSum[it1][it2][j][k], partSum[it1][it2][j][k - 1]); n             partSum[it1][it2][j][k] -= partSum[it1][it2][j - 1][k - 1]; n             if (partSum[it1][it2][j][k] < 0) partSum[it1][it2][j][k] += MOD; n           } n   } n   for (i = 1; i <= n; ++i) n     for (j = i; j <= n; ++j) n       for (it1 = 0; it1 <= 1; ++it1) n         for (it2 = 0; it2 <= 1; ++it2) { n         } n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = (1e5 + 5) * 2; n void Max(int &x, int y) { n   if (x < y) x = y; n } n int n, m; n int a[MAXN]; n int dp[MAXN]; n bool chk1(int s, int x) { n   memset(dp, 0, sizeof(dp)); n   for (int i = s, iend = s + n - 1; i <= iend; ++i) { n     int d = a[i + 1] - a[i] - 1; n     if (dp[i] + x < d) return false; n     if (dp[i] >= d) Max(dp[i + 1], x); n     if (dp[i] + x >= a[i + 2] - a[i] - 1) n       Max(dp[i + 2], x - (a[i + 2] - a[i + 1])); n   } n   int t = s + n - 1, d = a[s] - a[s - 1] - 1; n   if (dp[t] + x < d) n     return false; n   else n     return true; n } n bool chk2(int s, int x) { n   memset(dp, 0, sizeof(dp)); n   if (x < a[s + 1] - a[s] - 1) return false; n   Max(dp[s + 1], x - (a[s + 1] - a[s])); n   for (int i = s + 1, iend = s + n - 1; i <= iend; ++i) { n     int d = a[i + 1] - a[i] - 1; n     if (dp[i] + x < d) return false; n     if (dp[i] >= d) Max(dp[i + 1], x); n     if (dp[i] + x >= a[i + 2] - a[i] - 1) n       Max(dp[i + 2], x - (a[i + 2] - a[i + 1])); n   } n   int t = s + n - 1, d = a[s + 1] - a[s - 1] - 1; n   if (dp[t] + x < d) n     return false; n   else n     return true; n } n bool check(int x) { n   int s = -1; n   for (int i = 1, iend = n; i <= iend; ++i) { n     if (a[i + 1] - a[i] > x + 1) s = i + 1; n   } n   if (s == -1) n     return true; n   else n     return chk1(s, x) || chk2(s, x); n } n int main() { n   cin >> m >> n; n   for (int i = 1, iend = n; i <= iend; ++i) scanf( %d , &a[i]); n   for (int i = 1, iend = n; i <= iend; ++i) a[i + n] = m + a[i]; n   if (n == 1) { n     cout << m - 1 << endl; n     return 0; n   } n   int l = 0, r = m, res; n   while (l <= r) { n     int mid = (l + r) >> 1; n     if (check(mid)) n       res = mid, r = mid - 1; n     else n       l = mid + 1; n   } n   cout << res << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m; n   cin >> n >> m; n   char a[n][m]; n   int c = 0; n   int column_no; n   int row_number; n   for (int i = 0; i < n; i++) n     for (int j = 0; j < m; j++) { n       cin >> a[i][j]; n       if (a[i][j] ==  B  && c == 0) { n         column_no = j + 1; n         row_number = i + 1; n       } n       if (a[i][j] ==  B ) c++; n     } n   double s = sqrt(c); n   if (c == 1) n     cout << row_number <<     << column_no; n   else { n     int r = s / 2; n     cout << row_number + r <<     << column_no + r; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXn = 3000; n vector<pair<int, bool> > adj[MAXn + 2]; n int d[MAXn + 2][MAXn + 2], c[MAXn + 2][MAXn + 2], root; n bool mark[MAXn + 5]; n void DFS(int v) { n   int sum = 0, Min = INT_MAX; n   mark[v] = true; n   for (int i = 0; i < (int)adj[v].size(); i++) n     if (!mark[adj[v][i].first]) { n       DFS(adj[v][i].first); n       sum += d[root][adj[v][i].first] + adj[v][i].second; n     } n   for (int i = 0; i < (int)adj[v].size(); i++) n     if (!mark[adj[v][i].first]) n       Min = min(Min, c[root][adj[v][i].first] + !adj[v][i].second + n                          (sum - d[root][adj[v][i].first] - adj[v][i].second)); n   d[root][v] = sum; n   Min = min(Min, d[root][v]); n   c[root][v] = Min; n   mark[v] = false; n } n int main() { n   int n; n   scanf( %d , &n); n   for (int i = 0; i < n - 1; i++) { n     int u, v; n     scanf( %d%d , &u, &v); n     u--; n     v--; n     adj[u].push_back(make_pair(v, 0)); n     adj[v].push_back(make_pair(u, 1)); n   } n   for (int i = 0; i < n; i++) { n     root = i; n     DFS(i); n   } n   int Min = INT_MAX; n   for (int i = 0; i < n; i++) Min = min(d[i][i], Min); n   for (int i = 0; i < n; i++) n     for (int j = 0; j < n; j++) n       if (i != j) Min = min(Min, d[i][i] - d[i][j] + c[i][j]); n   cout << Min << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1010, M = 200200; n int i, j, k, n, m, ch, now, q; n int a[N][N], ans[M]; n struct cc { n   int x, y; n } A[M]; n struct dd { n   int l, r, s, t, q; n } Q[M]; n void R(int &x) { n   x = 0; n   ch = getchar(); n   while (ch <  0  ||  9  < ch) ch = getchar(); n   while ( 0  <= ch && ch <=  9 ) x = x * 10 + ch -  0 , ch = getchar(); n } n bool cmp(const dd &a, const dd &b) { return a.r < b.r; } n void work() { n   now++; n   int x = A[now].x, y = A[now].y; n   a[x][y] = a[y][x] = now; n   for (int i = 1; i <= n; i++) a[x][i] = a[y][i] = max(a[x][i], a[y][i]); n } n int main() { n   R(n); n   R(m); n   R(q); n   for (i = 1; i <= m; i++) R(A[i].x), R(A[i].y); n   for (i = 1; i <= q; i++) { n     R(Q[i].l); n     R(Q[i].r); n     R(Q[i].s); n     R(Q[i].t); n     Q[i].q = i; n   } n   sort(Q + 1, Q + q + 1, cmp); n   now = 0; n   for (i = 1; i <= q; i++) { n     while (now < Q[i].r) work(); n     if (a[Q[i].t][Q[i].s] >= Q[i].l) ans[Q[i].q] = 1; n   } n   for (i = 1; i <= q; i++) { n     if (ans[i]) n       puts( Yes ); n     else n       puts( No ); n   } n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n inline void read(T &x) { n   x = 0; n   char c = getchar(); n   bool flag = false; n   while (!isdigit(c)) { n     if (c ==  - ) flag = true; n     c = getchar(); n   } n   while (isdigit(c)) { n     x = (x << 1) + (x << 3) + (c ^ 48); n     c = getchar(); n   } n   if (flag) x = -x; n } n int n, m, k, lim = 1, ans, root, tot, cnt; n int ls[3000010], rs[3000010], tag[3000010], sum[3000010], val[3000010]; n struct node { n   int x, l, r, v; n } p[100010]; n bool cmp(const node &a, const node &b) { return a.x < b.x; } n int get(int l, int r) { n   int v = 0; n   for (int i = 1; i <= k; i <<= 1) n     v |= (((r / i - (l - 1) / i) - n            (i * 2 <= k ? r / i / 2 - (l - 1) / i / 2 : 0)) & n           1) * n          i; n   return v; n } n void pushup(int cur, int l, int r) { n   if (tag[cur]) n     sum[cur] = val[cur]; n   else n     sum[cur] = sum[ls[cur]] ^ sum[rs[cur]]; n } n void modify(int L, int R, int l, int r, int v, int &cur) { n   if (!cur) cur = ++tot; n   val[cur] = get(l, r); n   if (L <= l && R >= r) { n     tag[cur] += v, pushup(cur, l, r); n     return; n   } n   if (L <= ((l + r) >> 1)) modify(L, R, l, ((l + r) >> 1), v, ls[cur]); n   if (R > ((l + r) >> 1)) modify(L, R, ((l + r) >> 1) + 1, r, v, rs[cur]); n   pushup(cur, l, r); n } n int main() { n   read(n), read(m), read(k); n   while (lim <= k) lim <<= 1; n   for (int i = 1; i <= m; ++i) { n     int u, d, l, r; n     read(l), read(u), read(r), read(d); n     p[++cnt] = {l, u, d, 1}, p[++cnt] = {r + 1, u, d, -1}; n   } n   sort(p + 1, p + cnt + 1, cmp); n   for (int i = 1; i <= cnt; ++i) { n     if (p[i - 1].x != p[i].x) { n       int v1 = sum[root], v2 = get(p[i - 1].x, p[i].x - 1), s1 = 0, s2 = 0; n       for (int j = lim; j; j >>= 1) { n         s1 += ((v1 & j) != 0), s2 += ((v2 & j) != 0); n         if ((s1 * s2) & 1) ans ^= j; n       } n     } n     modify(p[i].l, p[i].r, 1, n, p[i].v, root); n   } n   if (ans) n     puts( Hamed ); n   else n     puts( Malek ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool Check(int X1, int Y1, int X2, int Y2, int a, int b) { n   bool answ = false; n   if (X1 <= a && X2 <= a && Y1 <= b && Y2 <= b) n     if (!(X1 + X2 > a) || !(Y1 + Y2 > b)) answ = true; n   if (Y1 <= a && X2 <= a && X1 <= b && Y2 <= b) n     if (!(Y1 + X2 > a) || !(X1 + Y2 > b)) answ = true; n   if (X1 <= a && Y2 <= a && Y1 <= b && X2 <= b) n     if (!(X1 + Y2 > a) || !(Y1 + X2 > b)) answ = true; n   if (Y1 <= a && Y2 <= a && X1 <= b && X2 <= b) n     if (!(Y1 + Y2 > a) || !(X1 + X2 > b)) answ = true; n   return answ; n } n int main() { n   int n, a, b; n   cin >> n >> a >> b; n   char XY[n][2]; n   for (int i = 0; i < n; i++) { n     int Xi, Yi; n     cin >> Xi >> Yi; n     XY[i][0] = Xi; n     XY[i][1] = Yi; n   } n   int maxS = 0; n   for (int i = 0; i < n - 1; i++) { n     int X1 = XY[i][0]; n     int Y1 = XY[i][1]; n     for (int j = i + 1; j < n; j++) { n       int X2 = XY[j][0]; n       int Y2 = XY[j][1]; n       if (Check(X1, Y1, X2, Y2, a, b) == true) { n         maxS = max(maxS, X1 * Y1 + X2 * Y2); n       } n     } n   } n   cout << maxS; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count()); n const int N = 2e5 + 10; n const int mod = 998244353; n int a[N], b[N], p[N], l[N]; n int getMin(int l, int r) { n   int x = a[l]; n   for (int i = l; i <= r; i++) x = min(x, a[i]); n   return x; n } n void zero() { n   cout << 0; n   exit(0); n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0), cout.tie(0); n   int n, m; n   cin >> n >> m; n   for (int i = 0; i < n; i++) cin >> a[i]; n   for (int i = 0; i < m; i++) cin >> b[i]; n   int ptr = m - 1; n   for (int i = n - 1; i >= 0; i--) { n     if (a[i] == b[ptr]) { n       p[ptr--] = i; n     } n     if (ptr < 0) break; n   } n   if (ptr >= 0) { n     zero(); n   } n   l[0] = -1; n   for (int i = m - 1; i >= 1; i--) { n     int j = p[i]; n     while (b[i] <= a[j]) j--; n     l[i] = j; n   } n   if (getMin(0, p[0]) != b[0] || getMin(p[m - 1], n - 1) != b[m - 1]) zero(); n   for (int i = 0; i < m - 1; i++) { n     if (getMin(p[i], p[i + 1]) != b[i]) zero(); n   } n   long long ans = 1; n   for (int i = 1; i < m; i++) { n     ans *= (p[i] - l[i]); n     ans %= mod; n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int dp[100100][102]; n int main() { n   cin.sync_with_stdio(false); n   cout.sync_with_stdio(false); n   cin.tie(0); n   long long n; n   cin >> n; n   int ans = 0; n   while (n) { n     ans += (n % 10 == 7 || n % 10 == 4); n     n /= 10; n   } n   cout << (ans == 4 || ans == 7 ?  YES  :  NO ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n namespace fgraph { n const int MAXV = 50; n const int MAXE = 10 * MAXV * MAXV; n const int INF = (1 << 30); n struct edge { n   int to, cap, flow, cost; n   edge *nxt, *rev; n } edges[MAXE + 5], *adj[MAXV + 5], *cur[MAXV + 5], *ecnt = edges; n void addedge(int u, int v, int c, int w) { n   edge *p = (++ecnt), *q = (++ecnt); n   (*p) = (edge){v, c, 0, w, adj[u], q}, adj[u] = p; n   (*q) = (edge){u, 0, 0, -w, adj[v], p}, adj[v] = q; n } n int d[MAXV + 5], h[MAXV + 5], s, t; n bool relabel() { n   for (int i = s; i <= t; i++) h[i] += d[i], d[i] = INF, cur[i] = adj[i]; n   priority_queue<pair<int, int>, vector<pair<int, int> >, n                  greater<pair<int, int> > > n       que; n   que.push(make_pair(d[t] = 0, t)); n   while (!que.empty()) { n     int k = que.top().first, x = que.top().second; n     que.pop(); n     if (k != d[x]) continue; n     for (edge *p = adj[x]; p; p = p->nxt) { n       if (p->rev->cap > p->rev->flow) { n         int dis = k + p->rev->cost + (h[x] - h[p->to]); n         if (dis < d[p->to]) que.push(make_pair(d[p->to] = dis, p->to)); n       } n     } n   } n   return d[s] != INF; n } n bool vis[MAXV + 5]; n int aug(int x, int tot) { n   if (x == t) return tot; n   vis[x] = true; n   int sum = 0; n   for (edge *&p = cur[x]; p; p = p->nxt) { n     int dis = d[p->to] + p->cost + (h[p->to] - h[x]); n     if (d[x] == dis && !vis[p->to] && p->cap > p->flow) { n       int del = aug(p->to, min(tot - sum, p->cap - p->flow)); n       sum += del, p->flow += del, p->rev->flow -= del; n       if (sum == tot) break; n     } n   } n   vis[x] = false; n   return sum; n } n }  // namespace fgraph n int f[55]; n int main() { n   int n, m; n   scanf( %d%d , &n, &m); n   for (int i = 1; i <= m; i++) { n     int u, v, w; n     scanf( %d%d%d , &u, &v, &w); n     fgraph::addedge(u, v, 1, w); n   } n   int cnt = 0; n   fgraph::s = 1, fgraph::t = n; n   for (cnt = 0; fgraph::relabel(); cnt++) n     f[cnt + 1] = f[cnt] + fgraph::d[1] + fgraph::h[1], fgraph::aug(1, 1); n   int q; n   scanf( %d , &q); n   for (int i = 1; i <= q; i++) { n     int x; n     scanf( %d , &x); n     double ans = 1E12; n     for (int j = 1; j <= cnt; j++) ans = min(ans, 1.0 * (x + f[j]) / j); n     printf( %.9f n , ans); n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2e6 + 10; n const int INF = 1e9 + 9; n const int B = 1e9 + 7; n long long p[N], s[N]; n int fp(int first) { n   return first == p[first] ? first : p[first] = fp(p[first]); n } n void u(int a, int b, int d) { n   s[fp(a)] += 4 * d; n   if (fp(a) == fp(b)) return; n   s[fp(b)] += s[fp(a)]; n   p[fp(a)] = fp(b); n } n int main() { n   ios_base ::sync_with_stdio(0); n   cin.tie(0); n   int n; n   cin >> n; n   vector<long long> a(n + 1); n   long long ans = 0; n   for (int i = int(2); i <= int(n); ++i) p[i] = i, s[i] = 0; n   for (int i = int(n); i >= int(2); --i) n     for (int j = 2; i * j <= n; ++j) u(i, i * j, j); n   for (int i = int(2); i <= int(n); ++i) ans = max(ans, s[fp(i)]); n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 1e9 + 1e8; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0), cout.tie(0); n   int tcase; n   cin >> tcase; n   while (tcase--) { n     int n, k; n     cin >> n >> k; n     vector<int> a(n + 1), b(n + 1), id(n + 1); n     for (int i = 1; i <= n; i++) cin >> a[i] >> b[i], id[i] = i; n     sort(id.begin() + 1, id.begin() + n + 1, n          [&](int u, int v) { return b[u] < b[v]; }); n     vector<vector<int>> dp(n + 1, vector<int>(k + 1, -INF)), n         prv(n + 1, vector<int>(k + 1, 0)); n     dp[0][0] = 0; n     for (int i = 1; i <= n; i++) { n       for (int j = 0; j <= k; j++) { n         dp[i][j] = dp[i - 1][j]; n         if (j) { n           if (dp[i][j] < dp[i - 1][j - 1] + a[id[i]] - b[id[i]] * (k - j)) { n             dp[i][j] = dp[i - 1][j - 1] + a[id[i]] - b[id[i]] * (k - j); n             prv[i][j] = 1; n           } n         } n       } n     } n     vector<int> chk(n + 1, 0); n     int cur_i = n, cur_j = k; n     while (cur_i) { n       if (prv[cur_i][cur_j]) n         chk[cur_i] = 1, cur_i--, cur_j--; n       else n         cur_i--; n     } n     vector<int> ans1, ans2; n     for (int i = 1; i <= n; i++) n       if (chk[i]) ans1.push_back(id[i]); n     for (int i = 1; i <= n; i++) n       if (!chk[i]) ans2.push_back(id[i]); n     vector<int> rlt; n     for (int i = 0; i < ans1.size() - 1; i++) rlt.push_back(ans1[i]); n     for (auto it : ans2) rlt.push_back(it), rlt.push_back(-it); n     rlt.push_back(ans1[ans1.size() - 1]); n     cout << rlt.size() <<   n ; n     for (int i = 0; i < rlt.size(); i++) n       cout << rlt[i] <<    n [i == rlt.size() - 1]; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct edge { n   int v, to, cap, scap; n   edge(int a, int b, int c) { v = a, to = b, cap = c, scap = c; } n   edge() {} n }; n struct rect { n   int x1, y1, x2, y2; n }; n struct tri { n   int y1, y2, x; n }; n bool operator<(const tri &a, const tri &b) { return a.y1 < b.y1; }; n const int N = 1e6 + 7; n const int INF = 1e9 + 7; n vector<edge> e; n vector<int> g[N]; n int us[N]; n int usbs = 1; n int d[N]; n int q[N]; n int ded[N]; n int ptr[N]; n vector<rect> fget[N]; n int after_bfs = 1; n int visb = 1; n long long ans = 0; n int qh, qt; n int s, t; n int l; n bool bfs() { n   qh = qt = 0; n   us[s] = usbs; n   q[qt++] = s; n   d[s] = 0; n   while (qh < qt) { n     int v = q[qh++]; n     for (auto c : g[v]) { n       if (us[e[c].to] != usbs && e[c].cap > 0) { n         d[e[c].to] = d[v] + 1; n         us[e[c].to] = usbs; n         q[qt++] = e[c].to; n       } n     } n   } n   return (us[t] == usbs++); n } n int dfs(int v = s, int c = 1e9) { n   if (!c) { n     return 0; n   } n   if (v == t) { n     ans += c; n     return c; n   } n   if (ded[v] != after_bfs) { n     ded[v] = after_bfs; n     ptr[v] = 0; n   } n   for (; ptr[v] < (int)g[v].size(); ptr[v]++) { n     int ind = g[v][ptr[v]]; n     if (e[ind].cap > 0 && d[e[ind].to] == d[v] + 1) { n       int x = dfs(e[ind].to, min(c, e[ind].cap)); n       if (x) { n         e[ind].cap -= x; n         e[ind ^ 1].cap += x; n         return x; n       } n     } n   } n   return 0; n } n void add_edge(int u, int v, int cap) { n   g[u].push_back(e.size()); n   e.push_back({u, v, cap}); n   g[v].push_back(e.size()); n   e.push_back({v, u, 0}); n } n long long dinic(int a, int b) { n   s = a, t = b; n   while (bfs()) { n     after_bfs++; n     while (dfs()) { n       continue; n     } n   } n   return ans; n } n vector<int> inds; n int lel(int v, int l, int r, int i) { n   if (r - l == 1) { n     return v; n   } else { n     int m = (l + r) / 2; n     if (i < m) { n       return lel(v * 2 + 1, l, m, i); n     } else { n       return lel(v * 2 + 2, m, r, i); n     } n   } n } n void get(int v, int l, int r, int tl, int tr) { n   if (tl >= r || tr <= l) { n     return; n   } n   if (tl >= l && tr <= r) { n     inds.push_back(v); n   } else { n     int tm = (tl + tr) / 2; n     get(v * 2 + 1, l, r, tl, tm); n     get(v * 2 + 2, l, r, tm, tr); n   } n } n void build(int v, int l, int r, int ax, int bx, int n) { n   if (r - l == 1) { n     add_edge(l, ax + v, 1); n     add_edge(bx + v, n + l, 1); n   } else { n     int m = (l + r) / 2; n     build(v * 2 + 1, l, m, ax, bx, n); n     build(v * 2 + 2, m, r, ax, bx, n); n     add_edge(ax + v * 2 + 1, ax + v, INF); n     add_edge(ax + v * 2 + 2, ax + v, INF); n     add_edge(bx + v, bx + v * 2 + 1, INF); n     add_edge(bx + v, bx + v * 2 + 2, INF); n   } n } n int main() { n   vector<rect> fre; n   int n, q; n   cin >> n >> q; n   for (int i = 0; i < q; i++) { n     int x1, y1, x2, y2; n     cin >> x1 >> y1 >> x2 >> y2; n     x1--, y1--, x2--, y2--; n     fget[x2].push_back({x1, y1, x2, y2}); n   } n   set<tri> s; n   s.insert({0, n - 1, 0}); n   for (int i = 0; i < n; i++) { n     for (auto c : fget[i]) { n       auto it = s.lower_bound({c.y1, -1, -1}); n       vector<tri> gt; n       if (it != s.begin()) { n         it--; n         gt.push_back(*it); n         it++; n       } n       bool b = false; n       while (it != s.end() && (it->y2 <= c.y2 || !b)) { n         gt.push_back(*it); n         it++; n         if (it != s.end()) { n           if (it->y2 > c.y2) { n             gt.push_back(*it); n             b = true; n           } n         } n       } n       for (auto d : gt) { n         if (max(d.y1, c.y1) > min(d.y2, c.y2)) { n           continue; n         } n         s.erase(d); n         if (c.y1 <= d.y1 && d.y2 <= c.y2) { n           int a = d.x, b = c.x1 - 1; n           if (a <= b) { n             fre.push_back({a, d.y1, b, d.y2}); n           } n         } else { n           if (d.y1 <= c.y1 && c.y2 <= d.y2) { n             auto was = d; n             was.y2 = c.y1 - 1; n             if (was.y1 <= was.y2) { n               s.insert(was); n             } n             was = d; n             was.y1 = c.y2 + 1; n             if (was.y1 <= was.y2) { n               s.insert(was); n             } n             int a = d.x, b = c.x1 - 1; n             if (a <= b) { n               fre.push_back({a, c.y1, b, c.y2}); n             } n           } else if (d.y2 > c.y2) { n             auto was = d; n             was.y1 = c.y2 + 1; n             s.insert(was); n             int a = d.x, b = c.x1 - 1; n             if (a <= b) { n               fre.push_back({a, d.y1, b, c.y2}); n             } n           } else if (d.y1 < c.y1) { n             auto was = d; n             was.y2 = c.y1 - 1; n             s.insert(was); n             int a = d.x, b = c.x1 - 1; n             if (a <= b) { n               fre.push_back({a, c.y1, b, d.y2}); n             } n           } n         } n       } n       if (c.x2 != n - 1) { n         s.insert({c.y1, c.y2, c.x2 + 1}); n       } n     } n   } n   for (auto c : s) { n     fre.push_back({c.x, c.y1, n - 1, c.y2}); n   } n   inds.clear(); n   get(0, n - 1, n, 0, n); n   int cnt = inds[0] + 1; n   for (auto c : fre) { n     int x1 = c.x1, y1 = c.y1, x2 = c.x2, y2 = c.y2; n     inds.clear(); n     get(0, x1, x2 + 1, 0, n); n     vector<int> a = inds; n     inds.clear(); n     get(0, y1, y2 + 1, 0, n); n     vector<int> b = inds; n     for (auto c : a) { n       for (auto d : b) { n         add_edge(n + n + c, n + n + cnt + d, INF); n       } n     } n   } n   build(0, 0, n, n + n, n + n + cnt, n); n   int st = n + n + cnt + cnt, en = n + n + cnt + cnt + 1; n   for (int i = 0; i < n; i++) { n     add_edge(st, i, 1); n     add_edge(i + n, en, 1); n   } n   cout << dinic(st, en) << endl; n } n


#include <bits/stdc++.h> n  n using namespace std; n  n const int N = 2e5+5; n const long long inf = 0x3f3f3f3f3f3f3f3f; n typedef long long ll; n #define pb push_back n  n int n, m; n int a[N]; n int g[N], v[N<<1], nxt[N<<1], tot, fa[N]; n vector<int> c[N]; n ll f[N], ans; n  n inline void add(int x, int y) { n  v[++tot] = y, nxt[tot] = g[x], g[x] = tot; n } n  n void dfs(int x, int ff, int dep) { n  fa[x] = ff, c[dep].pb(x), m = max(m, dep); n  for (int i = g[x]; i; i = nxt[i]) { n   int y = v[i]; n   if (y == ff) continue; n   dfs(y, x, dep + 1); n  } n } n  n inline void solve() { n  scanf( %d , &n); n  for (int i = 2; i <= n; i++) { n   int x; n   scanf( %d , &x); n   add(i, x), add(x, i); n  } n  for (int i = 2; i <= n; i++) scanf( %d , &a[i]); n  dfs(1, 0, 0); n  for (int r = 1; r <= m; r++) { n   ll max0 = -inf, min0 = inf, max1 = -inf, max2 = -inf; n   for (int i = 0; i < (int)c[r].size(); i++) { n    int x = c[r][i]; n    max0 = max(max0, (ll)a[x]), min0 = min(min0, (ll)a[x]); n    max1 = max(max1, f[fa[x]] + a[x]); n    max2 = max(max2, f[fa[x]] - a[x]); n   } n   for (int i = 0; i < (int)c[r].size(); i++) { n    int x = c[r][i]; n    f[x] = max(f[fa[x]] + max(max0 - a[x], a[x] - min0), max(max1 - a[x], max2 + a[x])); n    if (r == m) ans = max(ans, f[x]); n   } n  } n  printf( %lld n , ans); n } n  n inline void init() { n  ans = m = tot = 0; n  for (int i = 1; i <= n; i++) c[i].clear(), g[i] = 0, f[i] = 0; n } n  n int main() n { n  int T; n  scanf( %d , &T); n  while (T--) { n   init(); n   solve(); n  } n  return 0; n }


#include <bits/stdc++.h> n using namespace std; n int n, m; n int a[200005]; n int v[200005]; n int c[200005], lower; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(nullptr); n   cout.tie(nullptr); n   cerr.tie(nullptr); n   int sol = 123123123; n   cin >> n >> m; n   for (int i = 1; i <= n; i++) cin >> a[i]; n   for (int i = 1; i <= m; i++) { n     cin >> v[i]; n     if (c[i] < v[i]) lower++; n   } n   int j = 0; n   for (int i = 1; i <= n; i++) { n     while (j < n && lower > 0) { n       j++; n       c[a[j]]++; n       if (c[a[j]] == v[a[j]]) lower--; n     } n     if (!lower) sol = min(sol, j - i + 1); n     c[a[i]]--; n     if (c[a[i]] == v[a[i]] - 1) lower++; n   } n   if (sol == 123123123) n     sol = -1; n   else n     sol = sol - accumulate(v + 1, v + m + 1, 0); n   cout << sol <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n const long long mod = 1e9 + 7; n const long long mo = 998244353; n const long long N = 2e6 + 5; n long long n, m, noden, tot; n set<long long> S; n long long sum, pre1, pre2, ans, cnt; n struct node { n   long long lc, rc, rnd, val, sz; n } a[N]; n long long giao[N]; n long long fcc[N]; n struct Tree { n   long long maxv[100]; n   void pushup(long long rt) { maxv[rt] = max(maxv[(2 * rt)], maxv[(2 * rt)]); } n   void update(long long rt, long long l, long long r, long long p, n               long long v) { n     if (l == r) { n       maxv[rt] = v; n       return; n     } n     if (p <= ((l + r) / 2)) n       update((2 * rt), l, ((l + r) / 2), p, v); n     else n       update((2 * rt), ((l + r) / 2) + 1, r, p, v); n     pushup(rt); n   } n   long long ask(long long rt, long long l, long long r, long long ql, n                 long long qr) { n     if (ql > qr) return -1e12; n     if (l >= ql && r <= qr) return maxv[rt]; n     long long ans = -1e12; n     if (ql <= ((l + r) / 2)) n       ans = max(ans, ask((2 * rt), l, ((l + r) / 2), ql, qr)); n     if (qr >= ((l + r) / 2) + 1) n       ans = max(ans, ask((2 * rt), ((l + r) / 2) + 1, r, ql, qr)); n     return ans; n   } n } xxx, yyy; n long long cc1, cc2; n struct fhq { n   long long rt; n   long long merge(long long x, long long y) { n     if (!x || !y) return x | y; n     giao[x] = a[x].rnd; n     giao[0] = 0; n     if (a[x].rnd < a[y].rnd && giao[0] == 0) { n       giao[x] = a[x].rnd; n       a[x].rc = merge(a[x].rc, y); n       giao[x] = a[x].rnd; n       pushup(x); n       giao[x] = a[x].rnd; n       return x; n     } else { n       giao[2] = a[2].rnd; n       a[y].lc = merge(x, a[y].lc); n       giao[123] = a[123].rnd; n       pushup(y); n       return y; n     } n   } n   long long Find(long long val) { n     long long res, x, y; n     giao[23] = 23; n     split(rt, val + 1, x, y); n     if (giao[23] == 23) { n       res = a[x].sz + 1; n       rt = merge(x, y); n     } n     return res; n   } n   void split(long long now, long long val, long long &x, long long &y) { n     if (!now) { n       x = y = 0; n       return; n     } n     if (a[now].val >= val) { n       x = now; n       split(a[now].rc, val, a[now].rc, y); n     } else { n       y = now; n       split(a[now].lc, val, x, a[now].lc); n     } n     pushup(now); n   } n   long long NEW(long long val) { n     a[++noden] = (node){0, 0, rand(), val, 1}; n     return noden; n   } n   void pushup(long long x) { a[x].sz = a[a[x].lc].sz + a[a[x].rc].sz + 1; } n   long long getk(long long x, long long k) { n     if (!k || k > a[rt].sz) return 0; n     for (;;) { n       if (k <= a[a[x].lc].sz) n         x = a[x].lc; n       else if (k == a[a[x].lc].sz + 1) n         return x; n       else { n         k -= a[a[x].lc].sz + 1; n         x = a[x].rc; n       } n     } n   } n   long long Kth(long long rank) { return a[getk(rt, rank)].val; } n   void Del(long long val) { n     long long x, y, z; n     split(rt, val, x, z); n     split(x, val + 1, x, y); n     y = merge(a[y].lc, a[y].rc); n     rt = merge(merge(x, y), z); n   } n   void insert(long long val) { n     long long x, y; n     split(rt, val, x, y); n     rt = merge(merge(x, NEW(val)), y); n   } n } T; n long long tree[100]; n long long id[100]; n long long lc[100]; n long long rc[100]; n long long merge(long long x, long long y, long long l, long long r) { n   if (cc1 == cc2) return 0; n   if (!x || !y) return x + y; n   if (l == r) { n     tree[x] += tree[y]; n     id[x] = l; n     return x; n   } n   lc[x] = merge(lc[x], lc[y], l, ((l + r) / 2)); n   rc[x] = merge(rc[x], rc[y], ((l + r) / 2) + 1, r); n   return x; n } n void fun() { n   long long op, v, rk; n   cin >> op; n   cin >> v; n   sum += v; n   rk = T.Find(abs(v)); n   long long ff1 = 3; n   long long ff2 = 233; n   if (v > 0) { n     if (rk <= cnt && fcc[3] == 233) pre1 += v - T.Kth(cnt); n     if (rk <= cnt + 1 && fcc[3] == 233) pre2 += v - T.Kth(cnt + 1); n     T.insert(v); n     if (op && fcc[3] == 233) { n       merge(1, 2, 1, 2); n       cnt++; n       pre1 += T.Kth(cnt); n       merge(1, 1, 1, 1); n       pre2 += T.Kth(cnt + 1); n       S.insert(v); n       merge(1, 3, 1, 3); n     } n     if (cnt && T.Find(*S.begin()) <= cnt) n       ans = sum + pre2 - *S.begin(); n     else n       ans = sum + pre1; n     merge(5, 1, 4, 1); n   } else { n     v = -1 * v; n     if (rk <= cnt && fcc[3] == 233) n       pre1 -= v - 1 - T.Kth(cnt + 1) + 1, merge(1, 1, 1, 1); n     if (rk <= cnt + 1 && fcc[3] == 233) pre2 -= v - 12 - T.Kth(cnt + 2) + 12; n     if (fcc[3] == 233) T.Del(v), merge(1, 1, 1, 1); n     if (op) { n       merge(1, 1, 1, 1); n       merge(3, 4, 1, 1); n       if (fcc[ff1] == ff2) n         merge(1, 1, 1, 1), pre1 -= T.Kth(cnt), pre2 -= T.Kth(cnt + 1); n       merge(3, 4, 1, 1); n       if (fcc[3] == 233) cnt--; n       merge(3, 4, 1, 1); n       if (fcc[ff1] == ff2) S.erase(v); n     } n     if (cnt && T.Find(*S.begin()) <= cnt && fcc[3] == 233) n       ans = sum + pre2 - *S.begin(), merge(1, 1, 1, 1); n     else n       ans = sum + pre1; n   } n   cout << ans << endl; n } n struct St { n   long long n; n   long long m; n   long long table[2][2][2][2]; n   long long lg[100]; n   St() { n     lg[1] = 0; n     for (long long i = 2; i < 3; ++i) n       lg[i] = lg[i - 1] + (i == 1 << lg[i - 1] + 1); n   } n   void build(long long n, long long m, long long mat[][N]) { n     this->n; n     this->m = m; n     for (long long i = 1; i <= n; ++i) n       for (long long j = 1; j <= m; ++j) table[i][j][0][0] = mat[i][j]; n     for (long long ii = 0; (1 << ii) <= n; ii++) n       for (long long jj = 0; (1 << jj) <= m; jj++) n         if (ii + jj) n           for (long long i = 1; i + (1 << ii) - 1 <= n; i++) n             for (long long j = 1; j + (1 << jj) - 1 <= m; j++) n               if (ii) n                 table[i][j][ii][jj] = n                     max(table[i][j][ii - 1][jj], n                         table[i + (1 << (ii - 1))][j][ii - 1][jj]); n               else n                 table[i][j][ii][jj] = n                     max(table[i][j][ii][jj - 1], n                         table[i][j + (1 << (jj - 1))][ii][jj - 1]); n   } n   long long query(long long x1, long long y1, long long x2, long long y2) { n     if (x1 > x2) return -10000; n     if (y1 > y2) return -10000; n     long long dx = lg[x2 - x1 + 1]; n     long long dy = lg[y2 - y1 + 1]; n     long long ret1 = n         max(table[x1][y1][dx][dy], table[x1][y2 - (1 << dy) + 1][dx][dy]); n     long long ret2 = max(table[x2 - (1 << dx) + 1][y1][dx][dy], n                          table[x2 - (1 << dx) + 1][y2 - (1 << dy) + 1][dx][dy]); n     return max(ret1, ret2); n   } n } x1, x2; n int32_t main() { n   cin >> n; n   fcc[3] = 233; n   for (long long i = 1; i <= n; ++i) fun(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 888888; n int n, m, i, j, e; n int ss[N], ff[N], dd[N], x[N], last[N], pred[N], good[N], deg[N], used[N]; n int main() { n   scanf( %d %d , &n, &m); n   for (i = 1; i <= m; i++) { n     scanf( %d %d %d , ss + i, ff + i, dd + i); n     ss[i + m] = ff[i]; n     ff[i + m] = ss[i]; n     dd[i + m] = dd[i]; n   } n   for (i = 1; i <= n; i++) last[i] = 0; n   for (i = 1; i <= m + m; i++) { n     good[i] = 0; n     pred[i] = last[ss[i]]; n     last[ss[i]] = i; n   } n   for (i = 1; i <= n; i++) deg[i] = 0; n   for (i = 1; i <= m + m; i++) deg[ss[i]] += dd[i]; n   for (i = 1; i <= n; i++) deg[i] /= 2; n   for (i = 1; i <= n; i++) used[i] = 0; n   deg[1] = deg[n] = 0; n   i = 1; n   e = 1; n   x[1] = 1; n   while (i <= e) { n     j = last[x[i]]; n     while (j > 0) { n       if (ff[j] == n) good[j] = 1; n       if (used[ff[j]] < deg[ff[j]]) { n         good[j] = 1; n         used[ff[j]] += dd[j]; n         if (used[ff[j]] == deg[ff[j]]) { n           e++; n           x[e] = ff[j]; n         } n       } n       j = pred[j]; n     } n     i++; n   } n   for (i = 1; i <= m; i++) printf( %d n , 1 - good[i]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T, typename U> n inline void smin(T &a, const U &b) { n   if (a > b) a = b; n } n template <typename T, typename U> n inline void smax(T &a, const U &b) { n   if (a < b) a = b; n } n char s[100100], ss[4][100100]; n int nxt[100100][26], N[4]; n int dp[255][255][255], n; n inline void calc(int a_st, int a_ed, int b_st, int b_ed, int c_st, int c_ed) { n   for (int i = a_st; i <= a_ed; i++) { n     for (int j = b_st; j <= b_ed; j++) { n       for (int k = c_st; k <= c_ed; k++) { n         if (!i && !j && !k) n           dp[i][j][k] = 0; n         else { n           dp[i][j][k] = 0x3f3f3f3f; n           if (i && dp[i - 1][j][k] < n) n             smin(dp[i][j][k], nxt[dp[i - 1][j][k] + 1][ss[1][i] -  a ]); n           if (j && dp[i][j - 1][k] < n) n             smin(dp[i][j][k], nxt[dp[i][j - 1][k] + 1][ss[2][j] -  a ]); n           if (k && dp[i][j][k - 1] < n) n             smin(dp[i][j][k], nxt[dp[i][j][k - 1] + 1][ss[3][k] -  a ]); n         } n       } n     } n   } n } n int main() { n   int q; n   scanf( %d %d %s , &n, &q, s + 1); n   for (int i = 26; i--;) nxt[n + 1][i] = n + 1; n   for (int i = n; i >= 1; i--) { n     for (int j = 26; j--;) nxt[i][j] = nxt[i + 1][j]; n     nxt[i][s[i] -  a ] = i; n   } n   while (q--) { n     char c; n     scanf(  %c , &c); n     if (c ==  + ) { n       int id; n       scanf( %d %c , &id, &c); n       ss[id][++N[id]] = c; n       if (id == 1) calc(N[1], N[1], 0, N[2], 0, N[3]); n       if (id == 2) calc(0, N[1], N[2], N[2], 0, N[3]); n       if (id == 3) calc(0, N[1], 0, N[2], N[3], N[3]); n     } else { n       int id; n       scanf( %d , &id); n       N[id]--; n     } n     puts(dp[N[1]][N[2]][N[3]] <= n ?  YES  :  NO ); n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long binaryExponentiation(long long x, long long m) { n   if (x == 1) { n     return 0; n   } else { n     return 1 + (((binaryExponentiation((x / 2), m)))); n   } n } n long long sumd(long long a) { n   long long ans = 0; n   while (a != 0) { n     ans += a % 10; n     a = a / 10; n   } n   return ans; n } n long long check(long long n, long long A[], long long m) { n   long long ans = 0; n   for (long long q = 0; q < m; q++) { n     if ((A[q] - n) > 0) ans += A[q] - n; n   } n   return ans; n } n void solve() { n   long long n; n   cin >> n; n   while (n--) { n     long long a; n     cin >> a; n     cout << -(a - 1) <<     << a << endl; n   } n } n int32_t main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct __s { n   __s() { n     if (1) { n       ios_base::Init i; n       cin.sync_with_stdio(0); n       cin.tie(0); n     } n   } n   ~__s() { n     if (!1) n       fprintf(stderr,  Execution time: %.3lf s. n , n               (double)clock() / CLOCKS_PER_SEC); n     long long n; n     cin >> n; n   } n } __S; n long long a[1111111]; n long long ai[1111111]; n int main(void) { n   long long n; n   cin >> n; n   for (long long i = 0; i < (long long)(n); i++) { n     cin >> a[i]; n     a[i]--; n     ai[a[i]] = i; n   } n   long long cnt = 0; n   for (long long i = 0; i < (long long)(n); i++) { n     if (i == a[i]) continue; n     long long j = ai[i]; n     swap(a[i], a[j]); n     swap(ai[a[i]], ai[a[j]]); n     cnt++; n   } n   long long m1 = 3 * n - cnt; n   long long m2 = 7 * n + 1 - cnt; n   if (m1 % 2 == 0) n     cout <<  Petr  <<   n ; n   else n     cout <<  Um_nik  <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long INF = 1000000000000000; n int main() { n   int t, n; n   cin >> t; n   for (int i = 0; i < t; i++) { n     cin >> n; n     string s, t; n     if (n & 1) { n       if (n == 1) n         cout <<  a  <<   n ; n       else { n         s = string(n / 2,  a ) +  bc  + string(n / 2 - 1,  a ); n         cout << s <<   n ; n       } n     } else { n       s = string(n / 2,  a ) +  b  + string(n / 2 - 1,  a ); n       cout << s <<   n ; n     } n   } n } n


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


#include <bits/stdc++.h> n using namespace std; n double pi = 3.141592653589793238462; n string numkey =  0123456789 ; n string uni =  abcdefghijklmnopqrstuvwxyz ; n bool check(char ch) { n   string s =  aeiou ; n   for (long long int i = 0; i < s.size(); i++) { n     if (s[i] == ch) return true; n   } n   return false; n } n signed main() { n   string s; n   cin >> s; n   long long int n = s.length(), ctr = 0; n   set<char> st; n   for (long long int i = 0; i < n; i++) { n     if (check(s[i]) == false) n       ctr++, st.insert(s[i]); n     else n       ctr = 0, st.clear(); n     if (ctr > 2 && st.size() > 1) { n       st.clear(); n       cout <<    ; n       st.insert(s[i]); n       ctr = 1; n     } n     cout << s[i]; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int q, s, t, n, m, i, j, k, l; n int main() { n   cin >> t >> s >> q; n   int t1; n   while (s < t) { n     s = q * s; n     i++; n   } n   cout << i << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int LIMIT = 1000; n long long n; n long long sqrt2(long long n) { n   long long r = max((long long)sqrt(n) + 1, 0LL); n   while (r * r > n) { n     r--; n   } n   return r; n } n int sum(long long n) { n   int result = 0; n   while (n) { n     result += n % 10; n     n /= 10; n   } n   return result; n } n int main() { n   cin >> n; n   for (long long s = 1; s < LIMIT; ++s) { n     long long d = s * s + 4 * n; n     long long r = sqrt2(d); n     if (r * r == d && (r - s) % 2 == 0) { n       long long x = (r - s) / 2; n       if (sum(x) == s) { n         cout << x << endl; n         return 0; n       } n     } n   } n   cout << -1 << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int t[4000050], tag[4000050]; n vector<int> v[1005000]; n inline void refresh(int now) { t[now] = max(t[now << 1], t[now << 1 | 1]); } n void pushdown(int l, int r, int now) { n   if (l == r) { n     tag[now] = 0; n     return; n   } n   tag[now << 1] += tag[now]; n   tag[now << 1 | 1] += tag[now]; n   int mid = (l + r) >> 1; n   t[now << 1] += tag[now]; n   t[now << 1 | 1] += tag[now]; n   tag[now] = 0; n } n void add(int l, int r, int now, int LL, int RR, int data) { n   if (LL <= l && r <= RR) { n     t[now] += data; n     tag[now] += data; n     return; n   } n   if (tag[now]) pushdown(l, r, now); n   int mid = (l + r) >> 1; n   if (LL <= mid) add(l, mid, now << 1, LL, RR, data); n   if (mid < RR) add(mid + 1, r, now << 1 | 1, LL, RR, data); n   refresh(now); n } n int query(int l, int r, int now, int LL, int RR) { n   if (LL <= l && r <= RR) { n     return t[now]; n   } n   if (tag[now]) pushdown(l, r, now); n   int mid = (l + r) >> 1; n   int ans = -1e9; n   if (LL <= mid) ans = max(query(l, mid, now << 1, LL, RR), ans); n   if (mid < RR) ans = max(ans, query(mid + 1, r, now << 1 | 1, LL, RR)); n   refresh(now); n   return ans; n } n int i, j, k, n, m, st[1005000][2], siz[1005000], id[1005000], it, sb; n void dfs(int x) { n   siz[x]++; n   for (auto i : v[x]) { n     dfs(i); n     siz[x] += siz[i]; n   } n   id[x] = ++it; n } n int main() { n   scanf( %d%d , &n, &sb); n   for (i = 1; i <= n; i++) { n     scanf( %d , &k); n     while (m && st[m][1] < k) { n       v[i].push_back(st[m][0]); n       m--; n     } n     st[++m][0] = i; n     st[m][1] = k; n   } n   n++; n   while (m) { n     v[n].push_back(st[m][0]); n     m--; n   } n   dfs(n); n   for (i = 1; i <= sb; i++) { n     add(1, n, 1, id[i] - siz[i] + 1, id[i], 1); n   } n   for (i = sb; i < n; i++) { n     printf( %d  , t[1]); n     add(1, n, 1, id[i + 1] - siz[i + 1] + 1, id[i + 1], 1); n     add(1, n, 1, id[i - sb + 1] - siz[i - sb + 1] + 1, id[i - sb + 1], -1); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int n; n vector<pair<long long, long long> > a; n set<int> extr; n set<int>::iterator it; n vector<int> e; n int f[300005]; n long long mnx = 999999999999999999, mny = 999999999999999999, n           mxx = -999999999999999999, mxy = -999999999999999999; n int main() { n   cin >> n; n   a.reserve(n); n   for (int i = 0; i < n; i++) { n     long long x, y; n     cin >> x >> y; n     a.push_back({x, y}); n   } n   long long m = 0; n   for (int i = 0; i < n; i++) { n     if (a[i].first <= a[m].first) { n       m = i; n       mnx = a[m].first; n     } n   } n   extr.insert(m); n   f[m] = 1; n   m = 0; n   for (int i = 0; i < n; i++) { n     if (a[i].second <= a[m].second) { n       m = i; n       mny = a[m].second; n     } n   } n   extr.insert(m); n   f[m] = 1; n   m = 0; n   for (int i = 0; i < n; i++) { n     if (a[i].first >= a[m].first) { n       m = i; n       mxx = a[m].first; n     } n   } n   extr.insert(m); n   f[m] = 1; n   m = 0; n   for (int i = 0; i < n; i++) { n     if (a[i].second >= a[m].second) { n       m = i; n       mxy = a[m].second; n     } n   } n   extr.insert(m); n   f[m] = 1; n   for (it = extr.begin(); it != extr.end(); it++) { n     e.push_back(*it); n   } n   long long p = -999999999999999999; n   for (int i = 0; i < e.size(); i++) { n     for (int j = i + 1; j < e.size(); j++) { n       for (int k = 0; k < n; k++) { n         if (k == e[i] || k == e[j]) continue; n         long long minx = min(a[e[i]].first, min(a[e[j]].first, a[k].first)); n         long long maxx = max(a[e[i]].first, max(a[e[j]].first, a[k].first)); n         long long miny = min(a[e[i]].second, min(a[e[j]].second, a[k].second)); n         long long maxy = max(a[e[i]].second, max(a[e[j]].second, a[k].second)); n         if (p < ((maxx - minx) + (maxy - miny)) * 2) { n           p = ((maxx - minx) + (maxy - miny)) * 2; n         } n       } n     } n   } n   cout << p <<    ; n   for (int i = 0; i < n - 3; i++) n     cout << ((mxx - mnx) + (mxy - mny)) * 2 <<    ; n } n


#include <bits/stdc++.h> n using namespace std; n int a[100005]; n map<int, int> s; n int main(void) { n   long long ans = 0, z = 0; n   int k, b, n; n   scanf( %d%d%d , &k, &b, &n); n   int zcnt = 0; n   s[0]++; n   for (int i = 1; i <= n; i++) { n     scanf( %d , &a[i]); n     zcnt = (a[i] ? 0 : zcnt + 1); n     z += zcnt; n     a[i] = (a[i] + a[i - 1]) % (k - 1); n     int P = (a[i] - b + k - 1) % (k - 1); n     ans += s[P]; n     s[a[i]]++; n   } n   if (b == 0) n     ans = z; n   else if (b == k - 1) n     ans -= z; n   printf( %I64d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int fen[100100]; n int n, ans = -1, a[100100]; n int calc(int ind) { n   int ans = 0; n   for (int i = ind; i >= 1; i -= i & (-i)) ans ^= fen[i]; n   return ans; n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   ; n   memset(fen, 0, sizeof(fen)); n   cin >> n; n   for (int i = 2; i <= n; i++) { n     int t; n     int p = 0; n     set<int> s; n     for (int j = 2; j * (j + 1) / 2 <= i; j++) { n       int k = i - j * (j + 1) / 2; n       if (k % j != 0) continue; n       k /= j; n       t = calc(k + j) ^ calc(k); n       if (i == n and ans == -1 and !t) ans = j; n       s.insert(t); n     } n     while (s.count(p)) p++; n     for (int j = i; j <= n; j += j & (-j)) fen[j] ^= p; n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( Ofast ) n #pragma GCC optimize( unroll-loops ) n #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native ) n using std::cin; n using std::cout; n const int maxn = 100100; n int n, m, s; n long long t; n int f[2][maxn], *to = f[0], *lol = f[1]; n int jump[40][maxn]; n inline void cpy(int* a, int b, int len) { n   b %= n; n   if (b + len < n) { n     memcpy(a, to + b, len << 2); n   } else { n     memcpy(a, to + b, n - b << 2); n     memcpy(a + n - b, to, len - (n - b) << 2); n   } n } n int main() { n   std::ios::sync_with_stdio(false), std::cin.tie(0); n   std::cin >> n >> m >> s >> t, --s; n   for (int i = 0; i < n; ++i) to[i] = i; n   for (int T = 0; T < n; ++T) { n     cpy(lol, T, m); n     cpy(lol + m, m - T + n, n - m); n     std::swap(to, lol); n   } n   for (int i = 0; i < n; ++i) jump[0][i] = to[i]; n   for (int i = 1; i < 40; ++i) { n     for (int j = 0; j < n; ++j) { n       jump[i][j] = jump[i - 1][jump[i - 1][j]]; n     } n   } n   for (; t % n != 0; --t) { n     if (s < m) { n       s = (s + t) % n; n     } else { n       s = ((s - t) % n + n) % n; n     } n   } n   t /= n; n   for (int i = 39; i >= 0; --i) n     if (t >> i & 1) { n       s = jump[i][s]; n     } n   cout << s + 1 <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n int d(int a, int b, int a1, int b1) { return abs(a - a1) + abs(b - b1); } n int main() { n   int n; n   cin >> n; n   int x1, x2, y1, y2; n   cin >> x1 >> y1 >> x2 >> y2; n   if (y1 == y2 && (y1 == 0 || y1 == n)) { n     cout << abs(x1 - x2) << endl; n     return 0; n   } n   if (x1 == x2 && (x1 == 0 || x1 == n)) { n     cout << abs(y1 - y2) << endl; n     return 0; n   } n   if (abs(y1 - y2) == n) { n     swap(x1, y1); n     swap(x2, y2); n   } n   if (abs(x1 - x2) == n) { n     cout << n + min(y1 + y2, 2 * n - y1 - y2) << endl; n     return 0; n   } n   int mi = 2 * n; n   for (int i = 0; i <= n; i += n) n     for (int j = 0; j <= n; j += n) { n       mi = min(mi, d(x1, y1, i, j) + d(x2, y2, i, j)); n     } n   cout << mi << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); n inline int rand(int x, int y) { n   ++y; n   return (rng() % (y - x)) + x; n } n int n, m; n string A; n int ind(char ch) { n   if (ch ==  A ) return 0; n   if (ch ==  T ) return 1; n   if (ch ==  G ) return 2; n   return 3; n } n struct node { n   int second, e, m; n   int v; n   node *l, *r; n   node(int _s, int _e) { n     second = _s, e = _e, m = (second + e) / 2; n     v = 0; n     if (second != e) { n     } n     l = NULL; n     r = NULL; n   } n   void update(int x, int nv) { n     if (second == e) { n       v += nv; n       return; n     } n     if (x > m) { n       create(r, m + 1, e); n       assert(r != NULL); n       r->update(x, nv); n     } else { n       create(l, second, m); n       assert(l != NULL); n       l->update(x, nv); n     } n     v = 0; n     v += get(l); n     v += get(r); n   } n   int rmq(int x, int y) { n     if (second == x && e == y) return v; n     if (x > m) n       return rcall(x, y); n     else if (y <= m) n       return lcall(x, y); n     else n       return lcall(x, m) + rcall(m + 1, y); n   } n   int rcall(int x, int y) { n     if (r == NULL) return 0; n     return r->rmq(x, y); n   } n   int lcall(int x, int y) { n     if (l == NULL) return 0; n     return l->rmq(x, y); n   } n   void create(node *&tmp, int x, int y) { n     if (tmp != NULL) return; n     tmp = new node(x, y); n     assert(tmp != NULL); n   } n   int get(node *l) { n     if (l == NULL) return 0; n     return l->v; n   } n } * seg[4][11][10]; n void doo(int i, int op) { n   for (int j = 1; j < 11; j++) { n     { seg[ind(A[i])][j][i % j]->update(i, 1 * op); } n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cin >> A; n   n = A.length(); n   cin >> m; n   for (int i = 0; i < 4; i++) n     for (int j = 0; j < 11; j++) n       for (int k = 0; k < 10; k++) seg[i][j][k] = new node(0, n - 1); n   for (int i = 0; i < n; i++) { n     for (int j = 1; j < 11; j++) { n       { seg[ind(A[i])][j][i % j]->update(i, 1); } n     } n   } n   for (int ii = 0; ii < m; ii++) { n     int op; n     cin >> op; n     if (op == 1) { n       int x, c; n       char ch; n       cin >> x >> ch; n       c = ind(ch); n       --x; n       doo(x, -1); n       A[x] = ch; n       doo(x, 1); n     } else { n       int l, r; n       string e; n       cin >> l >> r >> e; n       --l, --r; n       int ans = 0; n       for (int i = 0; i < e.length(); i++) { n         if (i + l > r) continue; n         ans += n             seg[ind(e[i])][e.length()][((i + l) % (int)e.length())]->rmq(l, r); n       } n       cout << ans <<   n ; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 2005; n const int MOD = 1e9 + 7; n long long int dp[MAXN][MAXN]; n void c() { n   for (int i = 0; i < MAXN; i++) { n     for (int j = 0; j < MAXN; j++) { n       if (i == j) n         dp[i][j] = 1; n       else if (j == 0) n         dp[i][j] = 1; n       else if (i == 0) n         dp[i][j] = 0; n       else { n         dp[i][j] = (dp[i - 1][j - 1] + dp[i - 1][j]) % MOD; n       } n     } n   } n } n int main() { n   c(); n   int n, m, k; n   cin >> n >> m >> k; n   cout << (dp[n - 1][2 * k] * dp[m - 1][2 * k]) % MOD <<   n ; n } n


#include <bits/stdc++.h> n using std::sort; n struct Edge { n   int v, w, next; n } e[200002]; n int ecnt, h[100002]; n inline void add_edge(int u, int v, int w) { n   e[++ecnt] = {v, w, h[u]}; n   h[u] = ecnt; n   e[++ecnt] = {u, w, h[v]}; n   h[v] = ecnt; n } n int size[100002], dis1[100002], dis2[100002], dp[100002]; n int L, W; n int node[100002], cnt; n bool vis[100002]; n inline int max(int x, int y) { return x > y ? x : y; } n void get_root(int u, int fa, int s, int &cur) { n   size[u] = 1, dp[u] = 0; n   for (int i = h[u]; i; i = e[i].next) n     if (!vis[e[i].v] && e[i].v != fa) n       get_root(e[i].v, u, s, cur), size[u] += size[e[i].v], n           dp[u] = max(dp[u], size[e[i].v]); n   dp[u] = max(dp[u], s - size[u]); n   if (dp[u] < dp[cur]) cur = u; n } n void fill(int u, int fa, int w) { n   size[u] = 1; n   dis1[u] = dis1[fa] + w; n   dis2[u] = dis2[fa] + 1; n   for (int i = h[u]; i; i = e[i].next) n     if (!vis[e[i].v] && e[i].v != fa) n       fill(e[i].v, u, e[i].w), size[u] += size[e[i].v]; n } n void get_node(int u, int fa) { n   node[++cnt] = u; n   for (int i = h[u]; i; i = e[i].next) n     if (!vis[e[i].v] && e[i].v != fa) get_node(e[i].v, u); n } n inline bool cmp(int u, int v) { return dis1[u] < dis1[v]; } n int c[100002]; n inline void add(int x, int v) { n   x++; n   for (; x <= 100000; x += ((x) & -(x))) c[x] += v; n } n inline int sum(int x) { n   x++; n   if (x <= 0) return 0; n   int ans = 0; n   for (; x > 0; x -= ((x) & -(x))) ans += c[x]; n   return ans; n } n long long Ans; n inline long long solve() { n   long long ans = 0; n   sort(node + 1, node + cnt + 1, cmp); n   for (int i = 1; i <= cnt; i++) add(dis2[node[i]], 1); n   int j = cnt; n   for (int i = 1; i < j; i++) { n     while (i < j && dis1[node[i]] + dis1[node[j]] > W) n       add(dis2[node[j]], -1), j--; n     if (i >= j) break; n     add(dis2[node[i]], -1); n     ans += sum(L - dis2[node[i]]); n   } n   add(dis2[node[j]], -1); n   return ans; n } n inline void clear() { cnt = 0; } n void dfs(int u) { n   dis1[u] = dis2[u] = 0; n   fill(u, 0, 0); n   for (int i = h[u]; i; i = e[i].next) n     if (!vis[e[i].v]) get_node(e[i].v, u), Ans -= solve(), clear(); n   get_node(u, 0), Ans += solve(), clear(); n   vis[u] = 1; n   for (int i = h[u]; i; i = e[i].next) n     if (!vis[e[i].v]) { n       int rt = 0; n       get_root(e[i].v, 0, size[e[i].v], rt); n       dfs(rt); n     } n } n int main() { n   int n, tu, tw; n   dp[0] = 114514; n   dis2[0] = -1; n   scanf( %d%d%d , &n, &L, &W); n   for (int i = 2; i <= n; i++) scanf( %d%d , &tu, &tw), add_edge(i, tu, tw); n   int rt = 0; n   get_root(1, 0, n, rt); n   dfs(rt); n   printf( %I64d , Ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 100100; n bool isPrime[N]; n vector<int> primes; n vector<int> adj[N]; n void init() { n   memset(isPrime, true, sizeof(isPrime)); n   for (int i = 2; i * i <= N; i++) n     if (isPrime[i]) { n       for (int j = i * i; j < N; j += i) isPrime[j] = false; n     } n   for (int i = (2); i < (N); i++) n     if (isPrime[i]) primes.push_back(i); n } n vector<int> a; n set<pair<int, int> > s; n inline void mySwap(int j, int i) { n   s.erase(make_pair(-a[i], i)); n   s.insert(make_pair(-a[i], j)); n   swap(a[i], a[j]); n } n int main() { n   init(); n   adj[2].push_back(2); n   for (int i = 4; i < N; i += 2) { n     for (int j = 0; primes[j] < i; j++) { n       if (binary_search(primes.begin(), primes.end(), i - primes[j])) { n         adj[i].push_back(primes[j]); n         adj[i].push_back(i - primes[j]); n         break; n       } n     } n     assert((int)adj[i].size() == 2); n   } n   int n; n   cin >> n; n   a.resize(n); n   for (int i = 0; i < (n); i++) { n     cin >> a[i]; n     s.insert(make_pair(-a[i], i)); n   } n   vector<pair<int, int> > ans; n   for (int i = 0; i < (n); i++) { n     pair<int, int> cur = *s.begin(); n     s.erase(s.begin()); n     int pos = cur.second; n     int end = n - i - 1; n     int diff = (end - pos); n     if (diff == 0) continue; n     if (isPrime[diff + 1]) { n       ans.push_back(make_pair(pos, end)); n       mySwap(pos, end); n       continue; n     } else { n       if (diff % 2 == 0) { n         diff += 2; n         assert((int)adj[diff].size() % 2 == 0); n         int len1 = adj[diff][0], len2 = adj[diff][1]; n         assert(len1 + len2 == diff); n         ans.push_back(make_pair(pos, pos + len1 - 1)); n         mySwap(pos, pos + len1 - 1); n         ans.push_back(make_pair(pos + len1 - 1, end)); n         mySwap(pos + len1 - 1, end); n         continue; n       } else { n         ans.push_back(make_pair(pos, pos + 1)); n         mySwap(pos, pos + 1); n         diff += 1; n         pos += 1; n         int len1 = adj[diff][0], len2 = adj[diff][1]; n         assert(len1 + len2 == diff); n         ans.push_back(make_pair(pos, pos + len1 - 1)); n         mySwap(pos, pos + len1 - 1); n         ans.push_back(make_pair(pos + len1 - 1, end)); n         mySwap(pos + len1 - 1, end); n         continue; n       } n     } n   } n   cout << (int)ans.size() << endl; n   for (int i = 0; i < ((int)ans.size()); i++) { n     int l = min(ans[i].first, ans[i].second) + 1; n     int r = max(ans[i].first, ans[i].second) + 1; n     assert(isPrime[r - l + 1]); n     cout << l <<     << r << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   unordered_map<char, int> check; n   int n, count = 0; n   cin >> n; n   string temp; n   cin >> temp; n   for (int i = 0; i < temp.size() - 1; i += 2) { n     check[temp[i]]++; n     char ch = temp[i + 1]; n     ch = tolower(ch); n     if (check.find(ch) != check.end()) { n       if (check[ch] == 1) n         check.erase(ch); n       else n         check[ch]--; n     } else { n       count++; n     } n   } n   cout << count; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 212345, LG = 21, mod = 1000000007; n const double eps = 1e-3, pi = acos(-1.0); n char s[5], t[5], a[3]; n int main() { n   long long n, k; n   scanf( %lld , &n), scanf( %lld , &k); n   if (n / 2 > k) { n     printf( %lld n , k * (2 * k - 1) + (n - 2 * k) * 2 * k); n   } else { n     printf( %lld n , (n * (n - 1)) / 2); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main(void) { n   map<string, string> m; n   int q; n   cin >> q; n   int i; n   string s1, s2; n   while (q--) { n     cin >> s1 >> s2; n     if (m.count(s1) == 0) n       m[s2] = s1; n     else { n       m[s2] = m[s1]; n       m.erase(s1); n     } n   } n   cout << m.size() << endl; n   map<string, string>::iterator it; n   for (it = m.begin(); it != m.end(); it++) n     cout << it->second <<     << it->first << endl; n } n