#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   while (cin >> t) { n     string a; n     cin >> a; n     int s = 0; n     for (int i = 0; i < t - 1;) { n       if (a.at(i) == a.at(i + 1)) { n         if (a.at(i) ==  a ) n           a.at(i) =  b ; n         else n           a.at(i) =  a ; n         s++; n       } n       i += 2; n       if (i >= a.size()) break; n     } n     cout << s << endl << a << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   vector<pair<long long, short> > mass; n   long n, k; n   scanf( %li %li , &n, &k); n   long long a, b; n   for (long i = 0; i < n; i++) { n     scanf( %I64d %I64d , &a, &b); n     mass.push_back(make_pair(a, -1)); n     mass.push_back(make_pair(b, 1)); n   } n   sort(mass.begin(), mass.end()); n   vector<pair<long long, long long> > ans(n); n   long long x = 0, balance = 0; n   for (long i = 0; i < n * 2; i++) { n     if (mass[i].second == -1 && balance == k - 1) ans[x].first = mass[i].first; n     if (balance == k && mass[i].second == 1) ans[x++].second = mass[i].first; n     balance -= mass[i].second; n   } n   printf( %I64d  n , x); n   for (long i = 0; i < x; i++) n     printf( %I64d %I64d  n , ans[i].first, ans[i].second); n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 0x3fffffff; n const long long _INF = 0x7ffffffffffffffll; n const double EPS = 1e-9; n const double PI = acos(-1.0); n template <class T, class INT> n inline T pow(T x, INT y) { n   T res(1); n   for (T tt(x); y; y /= 2) { n     if (y & 1) res *= tt; n     tt *= tt; n   } n   return res; n } n template <class T, class INT> n inline T pow(T x, INT y, T p) { n   T res(1); n   for (T tt(x); y; y /= 2) { n     if (y & 1) res = res * tt % p; n     tt = tt * tt % p; n   } n   return res; n } n int toInt(string s) { n   int x = 0; n   istringstream sin(s); n   sin >> x; n   return x; n } n template <class T> n inline string toString(T x) { n   ostringstream sout; n   sout << x; n   return sout.str(); n } n template <class INT> n inline INT gcd(INT x, INT y) { n   return y ? gcd(y, x % y) : x; n } n template <class INT> n inline int calc_bits(INT x) { n   return x ? (x & 1) + calc_bits(x >> 1) : 0; n } n int n, x, xx, y, yy, ans; n int main(int argc, char* argv[]) { n   cin >> n >> x >> y >> xx >> yy; n   ans = abs(x - xx) + abs(y - yy); n   if (x == 0 && xx == n || x == n && xx == 0) n     ans += min(n - max(y, yy), min(y, yy)) * 2; n   if (y == 0 && yy == n || y == n && yy == 0) n     ans += min(n - max(x, xx), min(x, xx)) * 2; n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, a[1001][1001]; n set<int> r[1001], c[1001]; n map<int, int> r_m[1001], c_m[1001]; n int main() { n   scanf( %d%d , &n, &m); n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= m; j++) { n       scanf( %d , &a[i][j]); n       r[i].insert(a[i][j]); n       c[j].insert(a[i][j]); n     } n   } n   for (int i = 1; i <= n; i++) { n     int w = 1; n     for (int x : r[i]) { n       r_m[i][x] = w; n       w++; n     } n   } n   for (int i = 1; i <= m; i++) { n     int w = 1; n     for (int x : c[i]) { n       c_m[i][x] = w; n       w++; n     } n   } n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= m; j++) { n       int x = r_m[i][a[i][j]]; n       int y = c_m[j][a[i][j]]; n       if (x > y) { n         printf( %d  , max((int)r[i].size(), (int)c[j].size() + x - y)); n       } else { n         printf( %d  , max((int)r[i].size() + y - x, (int)c[j].size())); n       } n     } n     printf(  n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = (int)(2e9); n const long long linf = (long long)(2e18); n void solve(); n signed main() { n   ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); n   cout << fixed << setprecision(20); n   solve(); n   return 0; n } n void solve() { n   int n = 8; n   unordered_map<char, int> w, W; n   w[ q ] = 9; n   w[ r ] = 5; n   w[ b ] = 3; n   w[ n ] = 3; n   w[ p ] = 1; n   w[ k ] = 0; n   w[ . ] = 0; n   w[ Q ] = 0; n   w[ R ] = 0; n   w[ B ] = 0; n   w[ N ] = 0; n   w[ P ] = 0; n   w[ K ] = 0; n   W[ q ] = 0; n   W[ r ] = 0; n   W[ b ] = 0; n   W[ n ] = 0; n   W[ p ] = 0; n   W[ k ] = 0; n   W[ . ] = 0; n   W[ Q ] = -9; n   W[ R ] = -5; n   W[ B ] = -3; n   W[ N ] = -3; n   W[ P ] = -1; n   W[ K ] = 0; n   int ans = 0; n   for (int i = 0; i < n; ++i) { n     for (int j = 0; j < n; ++j) { n       char x; n       cin >> x; n       ans += (w[x] + W[x]); n     } n   } n   if (!ans) n     cout <<  Draw n ; n   else if (ans < 0) n     cout <<  White n ; n   else n     cout <<  Black n ; n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> v; n int extgcd(int a, int b, long long &x, long long &y) { n   int d = a; n   if (b != 0) { n     d = extgcd(b, a % b, y, x); n     y -= (a / b) * x; n   } else { n     x = 1; n     y = 0; n   } n   return d; n } n int main() { n   int n; n   scanf( %d , &n); n   int i = 2; n   int t = n; n   while (t > 1 && i <= sqrt(n)) { n     if (t % i == 0) { n       while (t % i == 0) t /= i; n       v.push_back(i); n     } n     i++; n   } n   if (t > 1) v.push_back(t); n   if (v.size() == 1) { n     printf( NO n ); n     return 0; n   } n   int j; n   bool f = true; n   for (i = 0; i < v.size() && f; i++) n     for (j = i + 1; j < v.size(); j++) { n       long long p, q; n       extgcd(v[i], v[j], p, q); n       p *= n - 1; n       q *= n - 1; n       int a = v[i], b = v[j]; n       if (q < 0) { n         swap(a, b); n         swap(p, q); n       } n       long long t = (-p) / b + 1; n       p += b * t; n       q -= a * t; n       if (q > 0) { n         printf( YES n2 n ); n         printf( %d %d n%d %d n , (int)p, (int)n / a, (int)q, (int)n / b); n         f = false; n         break; n       } n     } n   if (f) printf( NO n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a[5050]; n int solve(int l, int r, int h) { n   int m, i; n   if (l > r) n     return 0; n   else if (l == r) n     return (a[l] > h); n   else n     for (i = m = l; i <= r; i++) n       if (a[m] > a[i]) m = i; n   return min(r - l + 1, n              a[m] - h + solve(l, m - 1, a[m]) + solve(m + 1, r, a[m])); n } n int main() { n   int i, j; n   int n; n   cin >> n; n   for (i = 0; i < n; i++) cin >> a[i]; n   cout << solve(0, n - 1, 0) << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long n, m; n   cin >> n >> m; n   tuple<long long, long long, long long> arr[n - 1]; n   long long s1, e1; n   cin >> s1 >> e1; n   for (long long i = 0; i < n - 1; ++i) { n     long long s2, e2; n     cin >> s2 >> e2; n     arr[i] = make_tuple(e2 - s1 + 1, s2 - e1 - 1, i); n     s1 = s2, e1 = e2; n   } n   pair<long long, long long> blen1[m]; n   long long blen2[m]; n   for (long long i = 0; i < m; ++i) { n     long long b; n     cin >> b; n     blen1[i] = make_pair(b, i); n     blen2[i] = b; n   } n   sort(arr, arr + n - 1); n   sort(blen1, blen1 + m); n   sort(blen2, blen2 + m); n   pair<long long, long long> num_b[n - 1]; n   for (long long i = 0; i < n - 1; ++i) { n     long long end, start, idx, u = 0, l = 0; n     tie(end, start, idx) = arr[i]; n     l = upper_bound(blen2, blen2 + m, start) - blen2; n     u = lower_bound(blen2, blen2 + m, end) - blen2; n     if (u - l == 0) { n       cout <<  No  << endl; n       return 0; n     } else { n       num_b[i] = make_pair(l, u); n     } n   } n   set<pair<long long, long long> > bg; n   for (long long i = 0; i < m; ++i) { n     bg.insert(blen1[i]); n   } n   long long ans[n - 1]; n   for (long long i = 0; i < n - 1; ++i) { n     long long u = num_b[i].second, l = num_b[i].first; n     set<pair<long long, long long> >::iterator itr = n         bg.upper_bound({blen2[l], -1}); n     if (itr == bg.end() || (u != m && (*itr).first >= blen2[u])) { n       cout <<  No  << endl; n       return 0; n     } n     ans[get<2>(arr[i])] = (*itr).second + 1; n     bg.erase(itr); n   } n   cout <<  Yes  << endl; n   for (long long i = 0; i < n - 1; ++i) { n     cout << ans[i] <<    ; n   } n   cout << endl; n } n


#include <bits/stdc++.h> n const long double pi = 3.141592654; n using namespace std; n int n, k; n int dx[] = {0, 0, 1, -1, 1, -1, -1, 1}; n int dy[] = {-1, 1, 0, 0, 1, 1, -1, -1}; n bool valid(int r, int c) { return r >= 0 && c >= 0 && r < n && c < n; } n char grid[120][120]; n bool vis[100074]; n vector<int> initial; n vector<vector<int>> graph; n int parent[100074]; n void topological_sort(int student) { n   vis[student] = 1; n   for (auto child : graph[student]) { n     if (!vis[child]) topological_sort(child); n   } n   initial.push_back(student); n } n int main() { n   long long n; n   cin >> n; n   if (n == 2) { n     cout << 2; n   } else { n     if (n % 2 == 0) n       cout << 2; n     else n       cout << 1; n   } n } n


#include <bits/stdc++.h> n using namespace std; n template <class T1, class T2> n inline istream& operator>>(istream& fin, pair<T1, T2>& pr) { n   fin >> pr.first >> pr.second; n   return fin; n } n template <class T0, class T1, class T2> n inline istream& operator>>(istream& fin, tuple<T0, T1, T2>& t) { n   fin >> get<0>(t) >> get<1>(t) >> get<2>(t); n   return fin; n } n template <class T> n inline istream& operator>>(istream& fin, vector<T>& a) { n   for (auto& u : a) fin >> u; n   return fin; n } n template <class T, size_t n> n inline istream& operator>>(istream& fin, array<T, n>& a) { n   for (auto& u : a) fin >> u; n   return fin; n } n template <class FwdIter> n inline auto dump(FwdIter first, FwdIter last, const char* dlm) -> void { n   copy(first, last, n        ostream_iterator<typename iterator_traits<FwdIter>::value_type>(cout, n                                                                        dlm)); n } n inline int64_t powmod(int64_t a, int64_t n, const int64_t mod) { n   if (a == 1 || !n) return mod != 1 ? 1 : 0; n   int64_t out = 1; n   for (; n; n >>= 1) { n     if (n & 1) out = out * a % mod; n     a = a * a % mod; n   } n   return out; n } n int64_t probB() { n   const int64_t mod = 1000000007; n   int64_t p, k; n   cin >> p >> k; n   if (k == 0) { n     return powmod(p, p - 1, mod); n   } n   vector<bool> tag(p, false); n   int64_t out = k == 1 ? p : 1; n   for (int64_t i = 1; i < p; ++i) n     if (!tag[i]) { n       out = (out * p) % mod; n       for (auto j = i; !tag[j]; j = (j * k) % p) tag[j] = true; n     } n   return out; n } n int main(const int argc, char* argv[]) { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cout << probB(); n   return EXIT_SUCCESS; n } n


#include <bits/stdc++.h> n using namespace std; n struct node { n   int left, right, size; n } t[600000]; n int n; n int a[200005], b[200005], sa[200005], sb[200005], s[200005], ans[200005]; n int readint() { n   int x = 0, f = 1; n   char ch = getchar(); n   while (ch <  0  || ch >  9 ) { n     if (ch ==  - ) f = -1; n     ch = getchar(); n   } n   while (ch >=  0  && ch <=  9 ) { n     x = x * 10 + ch -  0 ; n     ch = getchar(); n   } n   return x * f; n } n void build(int id, int l, int r, int x) { n   t[id].left = l, t[id].right = r; n   if (l == r) return (void)(t[id].size = x); n   int mid = (l + r) / 2; n   build(id << 1, l, mid, x); n   build(id << 1 | 1, mid + 1, r, x); n   t[id].size = t[id << 1].size + t[id << 1 | 1].size; n } n int query(int id, int x) { n   if (t[id].left == t[id].right) return t[id].size; n   if (x <= t[id << 1].right) n     return query(id << 1, x); n   else n     return query(id << 1 | 1, x) + t[id << 1].size; n } n void change(int id, int x, int c) { n   if (t[id].left == t[id].right) return (void)(t[id].size = c); n   if (x <= t[id << 1].right) n     change(id << 1, x, c); n   else n     change(id << 1 | 1, x, c); n   t[id].size = t[id << 1].size + t[id << 1 | 1].size; n } n int find(int id, int x) { n   if (t[id].left == t[id].right) return t[id].left; n   if (x <= t[id << 1].size) n     return find(id << 1, x); n   else n     return find(id << 1 | 1, x - t[id << 1].size); n } n int main() { n   n = readint(); n   for (int i = 1; i <= n; i++) a[i] = readint() + 1; n   for (int i = 1; i <= n; i++) b[i] = readint() + 1; n   build(1, 1, n, 0); n   for (int i = n; i >= 1; i--) { n     sa[i] = query(1, a[i]); n     change(1, a[i], 1); n   } n   build(1, 1, n, 0); n   for (int i = n; i >= 1; i--) { n     sb[i] = query(1, b[i]); n     change(1, b[i], 1); n   } n   for (int i = n; i >= 1; i--) { n     s[i] += sa[i] + sb[i]; n     if (s[i] >= n - i + 1) s[i] -= n - i + 1, s[i - 1]++; n   } n   build(1, 1, n, 1); n   for (int i = 1; i <= n; i++) { n     ans[i] = find(1, s[i] + 1); n     change(1, ans[i], 0); n   } n   for (int i = 1; i <= n; i++) printf( %d  , ans[i] - 1); n   printf(  n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a[1000100], g[1000100]; n int main() { n   for (int i = 1; i < 20; i++) { n     int msk = (1 << i) - 1; n     for (int j = (1 << i - 1); j < (1 << i); j++) { n       g[j] = (1 << i - 1) | g[j ^ msk]; n     } n   } n   int n, x; n   scanf( %d , &n); n   for (int i = 0; i < n; i++) { n     scanf( %d , &a[i]); n   } n   for (int i = 19; i >= 0; i--) { n     vector<int> v, piv; n     for (int j = 0; j < n; j++) { n       if (a[j] >= (1 << i)) continue; n       int x = a[j]; n       for (int k = 0; k < v.size(); k++) { n         if (x & (piv[k] & -piv[k])) x ^= piv[k]; n       } n       if (x > 0) { n         v.push_back(a[j]); n         piv.push_back(x); n       } n     } n     if (v.size() == i) { n       printf( %d n , i); n       for (int j = 0; j < (1 << i); j++) { n         int x = 0; n         for (int k = 0; k < i; k++) { n           if (g[j] & (1 << k)) x ^= v[k]; n         } n         printf( %d  , x); n       } n       puts(  ); n       break; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX = 4e5 + 10; n int n, a[MAX]; n int f(int x) { n   vector<int> v(n); n   for (int i = 0; i < n; ++i) { n     v[i] = (a[i] == -1 ? x : a[i]); n   } n   int ret = 0; n   for (int i = 0; i < n - 1; ++i) { n     ret = max(ret, abs(v[i] - v[i + 1])); n   } n   return ret; n } n void solve() { n   cin >> n; n   for (int i = 0; i < n; ++i) cin >> a[i]; n   long long beg = 0, end = 1e9; n   while (end - beg > 3) { n     long long mid1 = (2 * beg + end) / 3; n     long long mid2 = (beg + 2 * end) / 3; n     int f1 = f(mid1); n     int f2 = f(mid2); n     if (f1 > f2) { n       beg = mid1 + 1; n     } else if (f1 <= f2) { n       end = mid2 - 1; n     } n   } n   int ans = 1e9, ind; n   for (int i = beg; i <= end; ++i) { n     int t = f(i); n     if (t < ans) { n       ans = t; n       ind = i; n     } n   } n   cout << ans <<     << ind <<   n ; n } n int main() { n   int q; n   cin >> q; n   while (q--) { n     solve(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n inline void read(int &x) { n   int v = 0, f = 1; n   char c = getchar(); n   while (!isdigit(c) && c !=  - ) c = getchar(); n   if (c ==  - ) n     f = -1; n   else n     v = (c & 15); n   while (isdigit(c = getchar())) v = (v << 1) + (v << 3) + (c & 15); n   x = v * f; n } n inline void read(long long &x) { n   long long v = 0ll, f = 1ll; n   char c = getchar(); n   while (!isdigit(c) && c !=  - ) c = getchar(); n   if (c ==  - ) n     f = -1; n   else n     v = (c & 15); n   while (isdigit(c = getchar())) v = (v << 1) + (v << 3) + (c & 15); n   x = v * f; n } n inline void readc(char &x) { n   char c; n   while (((c = getchar()) ==    ) || c ==   n ) n     ; n   x = c; n } n int t, n, m, i, j, k, l, px[5], py[5], c[5], res, sx[5], sy[5], tx[5], ty[5], n     tt[5]; n void check(int d, int x, int y) { n   tx[1] = tx[2] = x; n   tx[3] = tx[4] = x + d; n   ty[1] = ty[3] = y; n   ty[2] = ty[4] = y + d; n   int i, j; n   for (((i)) = (1); ((i)) <= ((4)); ((i))++) c[i] = i; n   do { n     int s = 0; n     for (((i)) = (1); ((i)) <= ((4)); ((i))++) { n       if (px[i] == tx[c[i]]) { n         s = max(s, abs(py[i] - ty[c[i]])); n         continue; n       } n       if (py[i] == ty[c[i]]) { n         s = max(s, abs(px[i] - tx[c[i]])); n         continue; n       } n       s = 0x3bbbbbbb; n       break; n     } n     if (s < res) { n       res = s; n       for (((i)) = (1); ((i)) <= ((4)); ((i))++) { n         sx[i] = tx[c[i]]; n         sy[i] = ty[c[i]]; n       } n     } n   } while (next_permutation(c + 1, c + 5)); n } n int main() { n   read(t); n   while (t--) { n     for (((i)) = (1); ((i)) <= ((4)); ((i))++) { n       read(px[i]); n       read(py[i]); n     } n     res = 0x3bbbbbbb; n     for (((i)) = (1); ((i)) <= ((4)); ((i))++) n       for ((j) = (i + 1); (j) <= (4); (j)++) { n         for (((k)) = (1); ((k)) <= ((4)); ((k))++) n           for (((l)) = (1); ((l)) <= ((4)); ((l))++) { n             int d = abs(px[i] - px[j]); n             check(d, px[k], py[l]); n             check(d, px[k], py[l] - d); n             check(d, px[k] - d, py[l]); n             check(d, px[k] - d, py[l] - d); n             d = abs(py[i] - py[j]); n             check(d, px[k], py[l]); n             check(d, px[k], py[l] - d); n             check(d, px[k] - d, py[l]); n             check(d, px[k] - d, py[l] - d); n           } n       } n     for (((i)) = (1); ((i)) <= ((4)); ((i))++) n       for ((j) = (i + 1); (j) <= (4); (j)++) { n         k = 1; n         while (k == i || k == j) k++; n         l = 4 ^ i ^ j ^ k; n         if (px[i] == px[j] && px[k] == px[l]) { n           int d = abs(px[i] - px[k]); n           int t1 = min(py[i], py[j]), t2 = max(py[i], py[j]) - d; n           int t3 = min(py[k], py[l]), t4 = max(py[k], py[l]) - d; n           tt[1] = t1; n           tt[2] = t2; n           tt[3] = t3; n           tt[4] = t4; n           sort(tt + 1, tt + 5); n           check(d, min(px[i], px[k]), (tt[1] + tt[4]) / 2); n         } n         if (py[i] == py[j] && py[k] == py[l]) { n           int d = abs(py[i] - py[k]); n           int t1 = min(px[i], px[j]), t2 = max(px[i], px[j]) - d; n           int t3 = min(px[k], px[l]), t4 = max(px[k], px[l]) - d; n           tt[1] = t1; n           tt[2] = t2; n           tt[3] = t3; n           tt[4] = t4; n           sort(tt + 1, tt + 5); n           check(d, (tt[1] + tt[4]) / 2, min(py[i], py[k])); n         } n       } n     if (res >= 0x3bbbbbbb) { n       puts( -1 ); n     } else { n       printf( %d n , res); n       for (((i)) = (1); ((i)) <= ((4)); ((i))++) { n         printf( %d %d n , sx[i], sy[i]); n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m, k; n   while (scanf( %d%d%d , &n, &m, &k) != EOF) { n     if (n == m) { n       if (n == 2 && k == 1) { n         printf( 4 n ); n         printf( 1 2 3 4 n ); n       } else { n         printf( %d n , 2 * k + 1); n         printf( 1 ); n         for (int i = 1; i < k; i++) { n           printf(  1 ); n         } n         printf(  %d , n); n         for (int i = 1; i < k; i++) { n           printf(  %d , n + 1); n         } n         if (k == 1) n           printf(  %d n , 2 * n - 1); n         else n           printf(  %d n , 2 * n); n       } n     } else if (m == n - 1) { n       if (k > 1) { n         printf( %d n , 2 * k); n         printf( 1 ); n         for (int i = 1; i < k; i++) { n           printf(  1 ); n         } n         printf(  %d , n); n         for (int i = 1; i < k; i++) { n           printf(  %d , n + 1); n         } n         printf(  n ); n       } else { n         printf( %d n , 2 * k + 1); n         printf( 1 ); n         for (int i = 1; i < k; i++) { n           printf(  1 ); n         } n         printf(  %d , n); n         for (int i = 1; i < k; i++) { n           printf(  %d , n + 1); n         } n         printf(  %d n , n + m); n       } n     } else { n       printf( %d n , 2 * k); n       printf( 1 ); n       for (int i = 1; i < k; i++) { n         printf(  1 ); n       } n       printf(  %d , n); n       for (int i = 1; i < k; i++) { n         printf(  %d , n + 1); n       } n       printf(  n ); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct EDGE { n   int u, v, l, next; n   bool train; n   EDGE() {} n   EDGE(int a, int b, int c, int d, bool bo) { n     u = a; n     v = b; n     l = c; n     next = d; n     train = bo; n   } n } edge[1000000]; n int n, m, k; n int edgenumber, head[200100], visit[200100], fr[200100]; n long long d[200100]; n void addedge(int u, int v, int l, bool bo) { n   edge[edgenumber] = EDGE(u, v, l, head[u], bo); n   head[u] = edgenumber++; n } n void spfa(int rt) { n   memset(d, 0x3f3f3f3f, sizeof(d)); n   priority_queue<pair<int, long long> > q; n   q.push(make_pair(1, 0)); n   visit[rt] = 1; n   d[rt] = 0; n   while (!q.empty()) { n     int u = q.top().first; n     q.pop(); n     for (int i = head[u]; i != -1; i = edge[i].next) { n       int v = edge[i].v; n       int l = edge[i].l; n       if (d[u] + l < d[v]) { n         d[v] = d[u] + l; n         fr[v] = i; n         if (!visit[v]) { n           visit[v] = 1; n           q.push(make_pair(v, -d[v])); n         } n       } else if (d[v] == d[u] + l && edge[fr[v]].train) { n         fr[v] = i; n       } n     } n     visit[u] = 0; n   } n   for (int i = 2; i <= n; i++) n     if (edge[fr[i]].train) k--; n } n int main() { n   scanf( %d%d%d , &n, &m, &k); n   edgenumber = 0; n   memset(head, -1, sizeof(head)); n   vector<pair<int, int> > kn; n   for (int i = 0; i < m; i++) { n     int u, v, l; n     scanf( %d%d%d , &u, &v, &l); n     addedge(u, v, l, false); n     addedge(v, u, l, false); n   } n   for (int i = 0; i < k; i++) { n     int v, l; n     scanf( %d%d , &v, &l); n     kn.push_back(make_pair(v, l)); n     addedge(1, v, l, true); n   } n   spfa(1); n   printf( %d n , k); n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n typedef long long ll; n int main() n { n   int t; n   cin >> t; n   while(t--) n   { n       string s; n       cin >> s; n       char c =  a ; n       int n = s.size(); n       if(n&1) n       { n            for(int i=0;i<=n/2;i++) n          { n              if(s[n-i-1]!= a ) n              { n                  s = s.substr(0,i)+c+s.substr(i); n                  break; n              } n          } n          if(s.size()==n+1) n           { n               cout <<  YES  << endl; n               cout << s << endl; n           } n           else{ n               bool p = true; n                for(int i=0;i<n/2;i++) n               { n                 if(s[n-i-1]!=s[i]) n                 { n                  p = false; n                  break; n                 } n              } n              if(!p) n              { n                  cout <<  YES  << endl; n                  cout << s+c << endl; n              } n              else n              { n                  cout <<  NO  << endl; n              } n           } n       } n       else{ n          for(int i=0;i<n/2;i++) n          { n              if(s[n-i-1]!= a ) n              { n                  s = s.substr(0,i)+c+s.substr(i); n                  break; n              } n          } n          if(s.size()==n+1) n           { n               cout <<  YES  << endl; n               cout << s << endl; n           } n           else{ n               bool p = true; n                for(int i=0;i<n/2;i++) n               { n                 if(s[n-i-1]!=s[i]) n                 { n                  p = false; n                  break; n                 } n              } n              if(!p) n              { n                  cout <<  YES  << endl; n                  cout << s+c << endl; n              } n              else n              { n                  cout <<  NO  << endl; n              } n           } n       } n        n   } n }


#include <bits/stdc++.h> n #pragma GCC optimize( Ofast ) n #pragma GCC target( avx2,tune=native ) n #pragma GCC optimize( unroll-loops ) n using namespace std; n using ll = long long; n using ld = long double; n using vi = vector<int>; n using vvi = vector<vi>; n using pi = pair<ll, ll>; n const int mod = 1e9 + 7; n const ll inf = 1e18; n mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); n ll n, k, mn[40][100100], sm[40][100100], p[40][100100]; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cin >> n >> k; n   for (int i = 0; i < n; i++) cin >> p[0][i]; n   for (int i = 0; i < n; i++) cin >> mn[0][i], sm[0][i] = mn[0][i]; n   for (int i = 1; i < 34; i++) { n     for (int j = 0; j < n; j++) { n       p[i][j] = p[i - 1][p[i - 1][j]]; n       sm[i][j] = sm[i - 1][j] + sm[i - 1][p[i - 1][j]]; n       mn[i][j] = min(mn[i - 1][j], mn[i - 1][p[i - 1][j]]); n     } n   } n   for (int i = 0; i < n; i++) { n     ll u = i, m = LLONG_MAX, s = 0; n     for (int j = 34; j--;) { n       if (k & (1ll << j)) { n         m = min(m, mn[j][u]); n         s = s + sm[j][u]; n         u = p[j][u]; n       } n     } n     cout << s <<     << m <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int __gcd(int x, int y) { n   if (!y) return x; n   return __gcd(y, x % y); n } n const long long linf = 1e18 + 5; n int mod = (int)1e9; n const int logN = 18; n const int inf = 1e9 + 9; n const int N = 1e5 + 5; n int ff, h[N], n, a[N], x, y, z, p; n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) { n     scanf( %d , &a[i]); n     h[a[i]]++; n   } n   int ff = 0; n   for (int i = 1; i <= 100000; i++) n     if (h[i] & 1) ff = 1; n   if (ff) { n     cout <<  Conan ; n   } else n     cout <<  Agasa ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 5007; n const int MX = 1e9 + 7; n const long long int INF = 1e18 + 9LL; n int n, m; n int in[N]; n vector<int> cows[N]; n int Left[N], Right[N]; n int take[N], poss[N], New[N]; n void update(int t) { n   int canTake = 0; n   if (cows[t][0] <= Left[t] || cows[t][0] <= Right[t]) canTake = 1; n   if (cows[t].size() >= 2) { n     int mn = min(Left[t], Right[t]); n     int mx = max(Left[t], Right[t]); n     if (cows[t][0] <= mn && cows[t][1] <= mx) canTake = 2; n   } n   if (canTake == 0) { n     if (take[t] == 0) return; n     take[t] = 0, poss[t] = 1, New[t] = 1; n     return; n   } n   if (canTake == 1) { n     int xd = 0; n     for (auto v : cows[t]) { n       if (v <= Left[t]) ++xd; n       if (v <= Right[t]) ++xd; n     } n     if (take[t] != canTake) { n       take[t] = 1; n       poss[t] = New[t] = xd; n     } else { n       poss[t] = xd; n       for (auto v : cows[t]) n         if (v == Left[t]) New[t] = 1; n     } n     return; n   } n   int prawo = 0; n   poss[t] = 0; n   for (auto v : cows[t]) n     if (v <= Right[t]) ++prawo; n   for (int i = 0; i < (int)cows[t].size(); ++i) n     if (cows[t][i] <= Left[t]) { n       poss[t] += prawo; n       if (cows[t][i] <= Right[t]) --poss[t]; n     } n   if (canTake != take[t]) { n     take[t] = 2; n     New[t] = poss[t]; n     return; n   } n   for (int i = 0; i < (int)cows[t].size(); ++i) n     if (cows[t][i] == Left[t]) { n       New[t] = prawo; n       if (cows[t][i] <= Right[t]) --New[t]; n     } n } n int main() { n   scanf( %d %d , &n, &m); n   for (int i = 1; i <= n; ++i) scanf( %d , &in[i]); n   for (int i = 1; i <= m; ++i) { n     int f, h; n     scanf( %d %d , &f, &h); n     cows[f].push_back(h); n   } n   for (int i = 1; i <= n; ++i) sort(cows[i].begin(), cows[i].end()); n   for (int i = 1; i <= n; ++i) { n     Right[in[i]]++; n     poss[i] = 1; n   } n   int ans = 0, ans2 = 1; n   for (int i = 1; i <= n; ++i) { n     if (cows[i].size() == 0) continue; n     update(i); n     ans += take[i]; n     ans2 = (1LL * ans2 * poss[i]) % MX; n   } n   for (int i = 1; i <= n; ++i) { n     Right[in[i]]--; n     Left[in[i]]++; n     for (int j = 1; j <= n; ++j) New[j] = 0; n     if (cows[in[i]].size()) update(in[i]); n     int now = 0; n     for (int j = 1; j <= n; ++j) now += take[j]; n     if (now < ans) continue; n     if (now > ans) { n       ans = now; n       ans2 = 0; n     } n     int tmp1 = 1, tmp2 = 1; n     for (int j = 1; j <= n; ++j) { n       tmp1 = (1LL * tmp1 * poss[j]) % MX; n       tmp2 = (1LL * tmp2 * (poss[j] - New[j])) % MX; n     } n     ans2 = (1LL * ans2 + tmp1 + MX - tmp2) % MX; n   } n   printf( %d %d n , ans, ans2); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double PI = acos(-1); n const int inf = 0x3fffffff; n const int maxn = 200005; n int n; n unsigned long long m; n struct P { n   int x, y; n } p[maxn]; n bool cmp(P a, P b) { n   if (a.x == b.x) return a.y < b.y; n   return a.x < b.x; n } n int main() { n   scanf( %d , &n); n   int y = 1; n   for (int i = 1; i <= 2 * n; i++) { n     int x; n     scanf( %d , &x); n     p[i].x = x, p[i].y = y; n     y++; n     if (y > n) y = 1; n   } n   scanf( %I64u , &m); n   sort(p + 1, p + 2 * n + 1, cmp); n   unsigned long long ans = 1, tmpans = 1, cnt = 0; n   int now = -1; n   for (int i = 1; i <= 2 * n; i++) { n     if (now != p[i].x) { n       now = p[i].x; n       ans *= tmpans; n       tmpans = 1LL; n       ans %= m; n       cnt = 0LL; n     } n     if (i < 2 * n) { n       if (p[i + 1].x != p[i].x) { n         tmpans *= (cnt + 1LL); n         tmpans %= m; n       } else { n         if (p[i + 1].y != p[i].y) { n           tmpans *= (cnt + 1LL); n           tmpans %= m; n           cnt++; n         } else { n           unsigned long long tmp1 = cnt + 1LL, tmp2 = cnt + 2LL; n           if (tmp1 % 2LL == 0LL) n             tmp1 /= 2LL; n           else n             tmp2 /= 2LL; n           tmpans *= tmp1; n           tmpans %= m; n           tmpans *= tmp2; n           tmpans %= m; n           cnt += 2LL; n           i++; n           if (i == 2 * n) { n             ans *= tmpans; n             ans %= m; n             break; n           } n         } n       } n     } else { n       tmpans *= (cnt + 1LL); n       tmpans %= m; n       ans *= tmpans; n       ans %= m; n       break; n     } n   } n   printf( %I64u n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n void show(const vector<T> &a) { n   for (T x : a) cout << x <<    ; n   cout <<   n ; n } n const long long N = 1e5 + 10, oo = 1e18 + 500; n const long long mod = 1e9 + 7; n const long double eps = 1e-9, PI = 2 * acos(0.0); n long long n, m, k; n long long cnt = 0; n vector<long long> g[N]; n vector<long long> rg[N]; n vector<long long> visit(N, 0); n vector<vector<long long> > dp(N, vector<long long>(150, -oo)); n signed main() { n   ios::sync_with_stdio(0); n   cout.tie(0); n   cin.tie(0); n   cin >> n >> m >> k; n   vector<vector<long long> > a(n, vector<long long>(m + 1)); n   for (long long i = 0; i < n; i++) { n     cin >> a[i][0]; n   } n   for (long long i = 0; i < n; i++) { n     for (long long j = 0; j < m; j++) cin >> a[i][j + 1]; n   } n   sort(a.rbegin(), a.rend()); n   dp[0][0] = a[0][0]; n   for (long long j = 0; j < m; j++) { n     dp[0][(1 << j)] = a[0][j + 1]; n   } n   for (long long i = 1; i < n; i++) { n     for (long long mask = 0; mask < (1 << m); mask++) { n       long long ex = 0; n       for (long long j = 0; j < m; j++) { n         if (mask & (1 << j)) { n           ex++; n         } n       } n       long long add = 0; n       if (i < k + ex) add = a[i][0]; n       if (dp[i][mask] < dp[i - 1][mask] + add) { n         dp[i][mask] = dp[i - 1][mask] + add; n       } n       for (long long j = 0; j < m; j++) { n         if (!(mask & (1 << j))) { n           if (dp[i][mask | (1 << j)] < dp[i - 1][mask] + a[i][j + 1]) { n             dp[i][mask | (1 << j)] = dp[i - 1][mask] + a[i][j + 1]; n           } n         } n       } n     } n   } n   long long ans = dp[n - 1][(1 << m) - 1]; n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 5000 + 100; n int x[maxn][maxn], p[maxn], tx[maxn]; n int n; n int ask(int i, int j) { n   cout <<  ?   << i <<     << j << endl; n   int r; n   cin >> r; n   return r; n } n void answer(int k) { n   cout <<  !  << endl; n   cout << k << endl; n   for (int i = 0; i < n; ++i) cout << p[i] <<    ; n   cout << endl; n   exit(0); n } n int main() { n   cin >> n; n   for (int i = 0; i < n; ++i) { n     int xo = ask(0, i); n     x[0][i] = xo; n   } n   for (int i = 1; i < n; ++i) { n     int xo = ask(i, i); n     for (int j = 0; j < n; ++j) { n       x[i][j] = xo ^ x[0][i] ^ x[0][j]; n     } n   } n   int xn = 0; n   for (int i = 0; i < n; ++i) xn ^= i; n   if (n & 1) { n     for (int i = 0; i < n; ++i) { n       int xnow = 0; n       for (int j = 0; j < n; ++j) xnow ^= x[i][j]; n       xnow ^= xn; n       p[i] = xnow; n     } n     answer(1); n     return 0; n   } n   for (int i = 0; i < n; ++i) tx[i] = (x[0][0] ^ x[i][0]); n   int ans = 0; n   for (int i = 0; i < n; ++i) { n     vector<int> tp(maxn); n     tp[0] = i; n     for (int j = 1; j < n; ++j) tp[j] = (tx[j] ^ tp[0]); n     bitset<maxn> v; n     bool good = true; n     vector<int> tb(maxn); n     for (int j = 0; j < n && good; ++j) { n       if (tp[j] >= n || tp[j] < 0) { n         good = false; n         break; n       } n       tb[tp[j]] = j; n     } n     for (int j = 0; j < n; ++j) { n       if ((tb[j] ^ tp[j]) != x[j][j]) good = false; n     } n     for (int j = 0; j < n && good; ++j) { n       if (tp[j] >= n || tp[j] < 0) { n         good = false; n         break; n       } n       if (v[tp[j]]) good = false; n       v[tp[j]] = true; n     } n     if (good) { n       ++ans; n       for (int j = 0; j < n; ++j) p[j] = tp[j]; n     } n   } n   answer(ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long sz = 1e5 + 5; n vector<long long> A(sz, 0), Lazy(4 * sz, 0), Tree(4 * sz, 0); n long long n, m; n void Built(long long Node, long long I, long long F) { n   if (I == F) { n     Tree[Node] = A[I]; n     return; n   } n   long long M = (I + F) / 2; n   Built(2 * Node + 1, I, M); n   Built(2 * Node + 2, M + 1, F); n   Tree[Node] = max(Tree[2 * Node + 1], Tree[2 * Node + 2]); n   return; n } n void Update(long long Node, long long I, long long F, long long L, long long R, n             long long Value) { n   if (Lazy[Node] != 0) { n     Tree[Node] += (Lazy[Node]); n     Lazy[2 * Node + 1] += Lazy[Node]; n     Lazy[2 * Node + 2] += Lazy[Node]; n     Lazy[Node] = 0; n   } n   if (L > F || R < I) { n     return; n   } n   if (I >= L && F <= R) { n     Tree[Node] += Value; n     Lazy[2 * Node + 1] += Value; n     Lazy[2 * Node + 2] += Value; n     return; n   } n   long long M = (I + F) / 2; n   Update(2 * Node + 1, I, M, L, R, Value); n   Update(2 * Node + 2, M + 1, F, L, R, Value); n   Tree[Node] = max(Tree[2 * Node + 1], Tree[2 * Node + 2]); n   return; n } n long long Query(long long Node, long long I, long long F, long long L, n                 long long R) { n   if (Lazy[Node] != 0) { n     Tree[Node] += (Lazy[Node]); n     Lazy[2 * Node + 1] += Lazy[Node]; n     Lazy[2 * Node + 2] += Lazy[Node]; n     Lazy[Node] = 0; n   } n   if (L > F || R < I) return INT_MIN; n   if (I >= L && F <= R) { n     return Tree[Node]; n   } n   long long M = (I + F) / 2; n   return max(Query(2 * Node + 1, I, M, L, R), n              Query(2 * Node + 2, M + 1, F, L, R)); n } n int main() { n   cin >> n >> m; n   long long Min = INT_MAX; n   long long Max = INT_MIN; n   long long ansIn = -1; n   for (long long i = 0; i < n; i++) { n     cin >> A[i]; n     Min = min(Min, A[i]); n     Max = max(Max, A[i]); n   } n   long long ans = Max - Min; n   Built(0, 0, n - 1); n   vector<pair<long long, long long> > tmp(m); n   map<pair<long long, long long>, vector<long long> > mp; n   for (long long i = 0; i < m; i++) { n     cin >> tmp[i].first >> tmp[i].second; n     tmp[i].first = tmp[i].first - 1; n     tmp[i].second = tmp[i].second - 1; n     mp[{tmp[i].first, tmp[i].second}].push_back(i + 1); n   } n   sort(tmp.begin(), tmp.end()); n   long long i = 0, j = 0; n   multiset<pair<long long, long long> > Set; n   for (long long k = 0; k < n; k++) { n     while (!Set.empty()) { n       auto it = Set.begin(); n       auto p = *it; n       if (p.first < k) { n         Update(0, 0, n - 1, p.second, p.first, 1); n         Set.erase(it); n       } else n         break; n     } n     while (j < m && tmp[j].first <= k && tmp[j].second >= k) { n       Update(0, 0, n - 1, tmp[j].first, tmp[j].second, -1); n       Set.insert({tmp[j].second, tmp[j].first}); n       j++; n     } n     long long sze = Set.size(); n     long long x = Query(0, 0, n - 1, 0, n - 1); n     long long y = A[k] - sze; n     if (ans < x - y) { n       ans = x - y; n       ansIn = k; n     } n   } n   cout << ans << endl; n   if (ansIn == -1) { n     cout << 0; n     return 0; n   } n   vector<long long> Ans; n   for (long long i = 0; i < m; i++) { n     if (tmp[i].first <= ansIn && tmp[i].second >= ansIn) { n       Ans.push_back(mp[{tmp[i].first, tmp[i].second}] n                       [mp[{tmp[i].first, tmp[i].second}].size() - 1]); n       mp[{tmp[i].first, tmp[i].second}].pop_back(); n     } n   } n   cout << Ans.size() << endl; n   for (auto i : Ans) cout << i <<    ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MOD = 1e9 + 7; n const int N = 2222; n int n, K; n long long sum[N][N], tail[N], f[N][N]; n char s[N]; n long long work() { n   long long ret = 0; n   tail[n + 1] = 1; n   for (int i = n; i >= 1; i--) tail[i] = tail[i + 1] * (s[i] -  a  + 1) % MOD; n   if (K == 0) return tail[1]; n   f[0][0] = 1; n   sum[0][0] = 1; n   for (int i = 1; i <= n; i++) { n     int dt = n - i + 1; n     for (int j = 0; j <= K; j++) { n       for (int k = i - 1; k >= 0 && (i - k) * dt <= j; k--) { n         f[i][j] = (f[i][j] + f[k][j - (i - k) * dt]) % MOD; n       } n       f[i][j] = f[i][j] * ( z  - s[i]) % MOD; n     } n     for (int j = 0; j <= K; j++) { n       f[i][j] = (f[i][j] + sum[i - 1][j] * (s[i] -  a ) % MOD) % MOD; n       sum[i][j] = (sum[i - 1][j] + f[i][j]) % MOD; n     } n   } n   ret = sum[n][K]; n   return ret; n } n int main() { n   scanf( %d%d%s , &n, &K, s + 1); n   printf( %I64d n , work()); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int kd[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; n int n, i, j; n char s[666666]; n int cnt[42][42][42]; n int mx, ad, am, ay; n int main() { n   scanf( %s , s); n   int n = strlen(s); n   memset(cnt, 0, sizeof(cnt)); n   for (i = 0; i + 9 < n; i++) { n     if (s[i + 2] !=  -  || s[i + 5] !=  - ) continue; n     int ok = 1; n     for (j = 0; j < 10; j++) n       if (j != 2 && j != 5 && s[i + j] ==  - ) ok = 0; n     if (!ok) continue; n     int dd = (s[i] - 48) * 10 + (s[i + 1] - 48); n     int mm = (s[i + 3] - 48) * 10 + (s[i + 4] - 48); n     if (s[i + 6] !=  2  || s[i + 7] !=  0  || s[i + 8] !=  1 ) continue; n     int yy = s[i + 9] - 48; n     if (yy < 3 || yy > 5) continue; n     if (mm < 1 || mm > 12) continue; n     if (dd < 1 || dd > kd[mm]) continue; n     cnt[dd][mm][yy]++; n     if (cnt[dd][mm][yy] > mx) { n       mx = cnt[dd][mm][yy]; n       ad = dd; n       am = mm; n       ay = yy; n     } n   } n   printf( %d%d-%d%d-%d n , ad / 10, ad % 10, am / 10, am % 10, 2010 + ay); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a[1000100], b[1000100], cnt[32]; n int solve(int n, int m) { n   int i, j, k, ret = 0; n   memset(cnt, 0, sizeof(cnt)); n   for (i = 0; i < n; ++i) { n     for (j = 0; (1 << j) <= a[i]; ++j) { n       if (a[i] & (1 << j)) ++cnt[j]; n     } n   } n   sort(b, b + m); n   for (i = 0; i < m; ++i) { n     for (j = b[i]; j < 32 && !cnt[j]; ++j) n       ; n     if (j == 32) break; n     ++ret; n     --cnt[j]; n     for (k = b[i]; k < j; ++k) ++cnt[k]; n   } n   return ret; n } n int main() { n   int n, m, i; n   while (~scanf( %d %d , &n, &m)) { n     for (i = 0; i < n; ++i) scanf( %d , &a[i]); n     for (i = 0; i < m; ++i) scanf( %d , &b[i]); n     printf( %d n , solve(n, m)); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long INF = 1e9 + 10; n const long long BINF = 1e18 + 10; n long long get(long long l, long long r) { n   if (l > r) { n     swap(l, r); n   } n   return r * (r + 1) / 2 - l * (l - 1) / 2; n } n long long solve(long long a, long long b, long long lim) { n   long long res = 0; n   if (a > lim) { n     if (b >= lim) { n       res += lim * (a - b + 1); n     } else { n       res += get(b, lim) + lim * (a - lim); n     } n   } else { n     res += get(a, b); n   } n   return res; n } n void source() { n   long long n, x, y, need; n   cin >> n >> x >> y >> need; n   if (need <= 1) { n     cout << 0; n     exit(0); n   } n   long long l = 0, r = 2 * n + 10; n   long long mx_up = n - y + 1, mx_down = y; n   while (r - l > 1) { n     long long mid = (l + r) / 2, sum = 0; n     long long left = max(x - mid, 1ll), right = min(x + mid, n); n     long long a = mid + 1, vl = a - (x - left), vr = a - (right - x); n     sum = solve(a, vl, mx_up) + solve(a, vr, mx_up) - min(mx_up, a); n     sum += solve(a, vl, mx_down) + solve(a, vr, mx_down) - min(mx_down, a); n     sum -= right - left + 1; n     if (sum >= need) { n       r = mid; n     } else { n       l = mid; n     } n   } n   cout << r; n } n signed main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   source(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int num; n   int arr[110]; n   cin >> num; n   for (int i = 0; i < num; i++) { n     cin >> arr[i]; n   } n   for (int i = 1; i <= num; i++) { n     for (int j = 0; j < num; j++) { n       if (arr[j] == i) { n         cout << j + 1 <<    ; n       } n     } n   } n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m; n string we, ns, sol =   ; n void fast() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n } n int main() { n   fast(); n   cin >> n >> m; n   cin >> we; n   cin >> ns; n   sol += we[0]; n   sol += we.back(); n   sol += ns[0]; n   sol += ns.back(); n   if (sol ==  <>v^  || sol ==  ><^v ) { n     cout <<  YES ; n   } else { n     cout <<  NO ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long logN = 20; n const long long M = 1000000007; n const long long INF = 1e12; n const long long N = 100005; n void solve() { n   long long n, k; n   cin >> n >> k; n   set<long long> s; n   while (s.size() < 30 and s.size() < (n - 1)) { n     long long i = rand() % n + 1; n     if (i != 1 and s.find(i) == s.end()) { n       s.insert(i); n       cout <<  ? 1 1  << endl; n       cout << 1 << endl; n       cout << i << endl; n       string gt; n       cin >> gt; n       if (gt ==  SECOND ) { n         cout <<  ! 1  << endl; n         return; n       } n     } n   } n   long long l = 2, r = 2; n   for (long long i = 0; i < 10; i++) { n     long long dif = (r - l + 1); n     cout <<  ?   << dif <<     << dif << endl; n     for (long long i = 1; i < dif + 1; i++) cout << i <<    ; n     cout << endl; n     for (long long i = l; i < l + dif; i++) cout << i <<    ; n     cout << endl; n     string s; n     cin >> s; n     if (s ==  FIRST ) break; n     l = r + 1; n     r = 2 * r; n     r = min(r, n); n   } n   while (r > l) { n     long long m = (l + r) / 2; n     long long dif = (m - l + 1); n     cout <<  ?   << dif <<     << dif << endl; n     for (long long i = 1; i < dif + 1; i++) cout << i <<    ; n     cout << endl; n     for (long long i = l; i < l + dif; i++) cout << i <<    ; n     cout << endl; n     string s; n     cin >> s; n     if (s ==  EQUAL ) n       l = m + 1; n     else n       r = m; n   } n   cout <<  !   << l << endl; n   return; n } n int main() { n   long long no; n   cin >> no; n   while (no--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long int sum[100010], bsum[100010], arr2[100010]; n pair<long long int, long long int> arr[100010]; n void scanStr(char *str) { n   long long int i = 1; n   char ch; n   for (ch = getchar(); ch !=   n  && ch !=    ; ch = getchar()) str[i++] = ch; n   str[i] =   0 ; n   return; n } n inline void fastOut(long long int n) { n   if (n < 10) { n     putchar(n +  0 ); n     return; n   } n   fastOut(n / 10); n   putchar(n % 10 +  0 ); n   return; n } n long long int powerFast(long long int a, long long int b) { n   long long int i = a, j = 1, k = 1; n   while (b) { n     if (b & 1) { n       k = ((k * i) < 1000000007 ? (k * i) : (k * i) % 1000000007); n     } n     i = ((i * i) < 1000000007 ? (i * i) : (i * i) % 1000000007); n     b = b >> 1; n   } n   return k; n } n inline long long int scan() { n   long long int n = 0; n   char c; n   for (c = getchar(); c ==     || c ==   n  || c ==   t ; c = getchar()) n     ; n   for (; c > 0x2f && c < 0x3a; c = getchar()) n = (n * 10) + (c & 0x0f); n   return n; n } n bool comp(pair<long long int, long long int> a, n           pair<long long int, long long int> b) { n   if (a.first < b.first) return false; n   return true; n } n int main() { n   long long int N, A, cf, cm, M, i, j, K, t, tmin, tnA, maxx; n   N = scan(); n   A = scan(); n   cf = scan(); n   cm = scan(); n   M = scan(); n   for (i = 1; i <= N; i++) { n     arr[i].first = scan(); n     arr[i].second = i; n   } n   sort(arr + 1, arr + N + 1, n        std::greater<pair<long long int, long long int> >()); n   for (i = 1; i <= N; i++) { n     sum[i] = sum[i - 1] + arr[i].first; n   } n   long long int loc1, loc2, val; n   maxx = LONG_MIN; n   j = 1; n   for (i = 0; i <= N; i++) { n     K = M - (A * i - sum[i]); n     if (K < 0) { n       break; n     } n     tnA = i; n     tmin = A; n     for (j = max(i + 1, j); j <= N; j++) { n       t = arr[j].first * (N - j + 1); n       t = t - (sum[N] - sum[j - 1]); n       if (t <= K) { n         t = K - t; n         tmin = min(arr[j].first + t / (N - j + 1), A); n         break; n       } n     } n     if ((cf * tnA + cm * tmin) >= maxx) { n       maxx = cf * tnA + cm * tmin; n       loc1 = i; n       loc2 = j; n       val = tmin; n     } n   } n   cout << maxx <<   n ; n   for (i = 1; i <= loc1; i++) { n     arr2[arr[i].second] = A; n   } n   for (i = loc1 + 1; i < loc2; i++) { n     arr2[arr[i].second] = arr[i].first; n   } n   for (i = loc2; i <= N; i++) { n     arr2[arr[i].second] = val; n   } n   for (i = 1; i <= N; i++) { n     fastOut(arr2[i]); n     putchar(   ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void readi(int &x) { n   int v = 0, f = 1; n   char c = getchar(); n   while (!isdigit(c) && c !=  - ) c = getchar(); n   if (c ==  - ) n     f = -1; n   else n     v = v * 10 + c -  0 ; n   while (isdigit(c = getchar())) v = v * 10 + c -  0 ; n   x = v * f; n } n void readll(long long &x) { n   long long v = 0ll, f = 1ll; n   char c = getchar(); n   while (!isdigit(c) && c !=  - ) c = getchar(); n   if (c ==  - ) n     f = -1; n   else n     v = v * 10 + c -  0 ; n   while (isdigit(c = getchar())) v = v * 10 + c -  0 ; n   x = v * f; n } n void readc(char &x) { n   char c; n   while ((c = getchar()) ==    ) n     ; n   x = c; n } n void writes(string s) { puts(s.c_str()); } n void writeln() { writes(  ); } n void writei(int x) { n   if (!x) putchar( 0 ); n   char a[25]; n   int top = 0; n   while (x) { n     a[++top] = (x % 10) +  0 ; n     x /= 10; n   } n   while (top) { n     putchar(a[top]); n     top--; n   } n } n void writell(long long x) { n   if (!x) putchar( 0 ); n   char a[25]; n   int top = 0; n   while (x) { n     a[++top] = (x % 10) +  0 ; n     x /= 10; n   } n   while (top) { n     putchar(a[top]); n     top--; n   } n } n long long n, m, li, ns, i, j, k, l, mod = 1e9 + 7, x, y, dp[123456][12][3], n                                     vis[123456]; n vector<long long> e[123456]; n void dfs(int x, int fa) { n   long long i; n   if (vis[x]) return; n   vis[x] = 1; n   dp[x][0][2] = ns - 1; n   dp[x][1][1] = 1; n   dp[x][0][0] = m - ns; n   for (i = 0; i < e[x].size(); i++) { n     if (e[x][i] == fa) continue; n     dfs(e[x][i], x); n     for (j = li; ~j; j--) { n       long long mem[3] = {0, 0, 0}; n       for (k = 0; k <= j; k++) { n         (mem[0] += n          (dp[x][j - k][0] * (dp[e[x][i]][k][0] + dp[e[x][i]][k][2]))) %= mod; n         (mem[1] += (dp[x][j - k][1] * (dp[e[x][i]][k][2]))) %= mod; n         (mem[2] += (dp[x][j - k][2] * (dp[e[x][i]][k][0] + dp[e[x][i]][k][1] + n                                        dp[e[x][i]][k][2]))) %= mod; n       } n       for (k = 0; k < 3; k++) dp[x][j][k] = mem[k]; n     } n   } n } n int main() { n   readll(n); n   readll(m); n   for (i = 1; i < n; i++) { n     readll(x); n     readll(y); n     e[x].push_back(y); n     e[y].push_back(x); n   } n   readll(ns); n   readll(li); n   dfs(1, 0); n   long long res = 0; n   for (i = 0; i <= li; i++) n     (res += dp[1][i][0] + dp[1][i][1] + dp[1][i][2]) %= mod; n   writell(res); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int T = 1; n   while (T--) { n     int n, m; n     cin >> n >> m; n     map<int, int> mp; n     vector<pair<int, int> > pp; n     for (int i = 0; i < m; i++) { n       int a, b; n       cin >> a >> b; n       pp.push_back({a, b}); n       if (a != b) { n         mp[a]++; n         mp[b]++; n       } else n         mp[a]++; n     } n     vector<pair<int, int> > maxi; n     for (auto x : mp) { n       maxi.push_back({x.second, x.first}); n     } n     sort(maxi.rbegin(), maxi.rend()); n     int mm = min(4, int((maxi).size())); n     for (int q = 0; q < mm; q++) { n       vector<int> v(m, 0); n       int cnt = 0; n       for (int i = 0; i < m; i++) { n         if (pp[i].first == maxi[q].second || pp[i].second == maxi[q].second) { n           v[i] = 1; n           cnt++; n         } n       } n       cnt = m - cnt; n       if (cnt == 0) { n         cout <<  YES ; n         exit(0); n       } n       mp.clear(); n       for (int i = 0; i < m; i++) { n         if (v[i] == 0) { n           if (pp[i].first != pp[i].second) { n             mp[pp[i].first]++; n             mp[pp[i].second]++; n           } else n             mp[pp[i].first]++; n         } n       } n       for (auto x : mp) { n         if (x.second == cnt) { n           cout <<  YES ; n           exit(0); n         } n       } n     } n     cout <<  NO ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e5 + 7; n map<int, int> l, r; n int a[maxn << 1]; n int sum[maxn << 1]; n int main() { n   int t; n   cin >> t; n   while (t--) { n     l.clear(); n     r.clear(); n     int n; n     cin >> n; n     for (int i = 1; i <= 2 * n; i++) cin >> a[i]; n     for (int i = 1; i <= 2 * n; i++) { n       a[i] = (a[i] == 2 ? 1 : -1); n     } n     for (int i = 1; i <= n; i++) sum[i] = sum[i - 1] + a[i]; n     sum[2 * n + 1] = 0; n     for (int i = 2 * n; i >= n + 1; i--) sum[i] = sum[i + 1] + a[i]; n     r[0] = 2 * n + 1; n     l[0] = 0; n     for (int i = 1; i <= n; i++) l[sum[i]] = max(l[sum[i]], i); n     for (int i = 2 * n; i >= n + 1; i--) n       r[sum[i]] ? r[sum[i]] = min(r[sum[i]], i) : r[sum[i]] = i; n     int ans = 2 * n; n     for (int i = 0; i <= n; i++) { n       if (!r[-sum[i]]) continue; n       ans = min(r[-sum[i]] - l[sum[i]] - 1, ans); n     } n     for (int i = 2 * n + 1; i >= n + 1; i--) { n       if (!l[-sum[i]] && sum[i]) continue; n       ans = min(ans, r[sum[i]] - l[-sum[i]] - 1); n     } n     cout << ans << endl; n   } n   return 0; n   ; n } n


#include <bits/stdc++.h> n using namespace std; n int m[10000000]; n int func(int v) { n   int r = 1; n   while (v != 1) { n     if (v % 2 == 0) { n       v /= 2; n     } else { n       v--; n       r++; n     } n   } n   return r; n } n int main() { n   int n, a; n   long long r = 0; n   scanf( %d , &n); n   for (int i = 0; i < n; i++) { n     scanf( %d , &a); n     m[func(a)]++; n   } n   for (int i = 0; i < 10000000; i++) { n     r += (long long)(((long long)m[i] * (long long)(m[i] - 1)) / 2); n   } n   cout << r; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long solve(long long A, long long B, long long C) { n   if (B == 0) { n     return 0; n   } n   long long N = A % B; n   long long X = solve(B, N, C); n   long long Y = (-C - A * X) / B; n   if (A != 0) { n     Y %= A; n   } n   return Y; n } n int abs(int a) { return a > 0 ? a : -a; } n int _gcd(int a, int b) { n   if (b == 0) return a; n   return _gcd(b, a % b); n } n int A, B, C; n int main() { n   scanf( %d %d %d , &A, &B, &C); n   int gcd = _gcd(abs(A), abs(B)); n   if (C % gcd == 0) { n     long long Y = solve(A, B, C); n     long long X = 0; n     if (A != 0) { n       X = (-B * Y - C) / A; n     } n     printf( %I64d %I64d n , X, Y); n   } else { n     printf( -1 n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n int dx[] = {-1, 0, 1, 0}; n int dy[] = {0, 1, 0, -1}; n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   int n; n   cin >> n; n   int a[n]; n   for (int i = 0; i < n; i++) cin >> a[i]; n   bool flag = false; n   for (int i = 1; i < n - 1; i++) { n     if ((1ll * (a[i] - a[0]) * (a[i] - a[i + 1])) > 0) { n       cout << 3 <<   n ; n       cout << 1 <<     << (i + 1) <<     << (i + 2) <<   n ; n       flag = true; n       break; n     } n   } n   if (!flag) cout << 0 <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2e5 + 1; n vector<int> adj[N]; n int numDiv[N]; n int a[N]; n bool cand[N]; n int sz[N], dsu[N]; n int f(int x) { n   if (x == dsu[x]) { n     return x; n   } n   return dsu[x] = f(dsu[x]); n } n void merge(int x, int y) { n   x = f(x), y = f(y); n   if (x != y) { n     dsu[x] = y; n     sz[y] += sz[x]; n   } n } n int val[N]; n int numPrime[N]; n long long all[N]; n vector<int> in[N]; n int lastColor[N]; n int isGood[N]; n int curColorList[N]; n int go[N]; n int bfs(int root, int curColor) { n   int sz = 0; n   queue<int> q; n   q.push(root); n   lastColor[root] = curColor; n   while (!q.empty()) { n     int node = q.front(); n     q.pop(); n     ++sz; n     for (int i = 0; i < (int)adj[node].size(); ++i) { n       int nextNode = adj[node][i]; n       if (isGood[nextNode] == curColor && lastColor[nextNode] < curColor) { n         lastColor[nextNode] = curColor; n         q.push(nextNode); n       } n     } n   } n   return sz; n } n void solve() { n   int n; n   scanf( %d , &n); n   for (int i = 1; i <= n; ++i) { n     scanf( %d , &a[i]); n     in[a[i]].push_back(i); n   } n   for (int i = 0; i < n - 1; ++i) { n     int x, y; n     scanf( %d %d  , &x, &y); n     adj[x].push_back(y); n     adj[y].push_back(x); n   } n   int g = N; n   for (int i = 1; i < N; ++i) { n     val[i] = 1; n   } n   int maxi = 0; n   for (int i = 2; i < N; ++i) { n     if (val[i] == 1) { n       for (int j = i; j < N; j += i) { n         val[j] *= i; n         numPrime[j] ^= 1; n       } n     } n   } n   int curColor = 1; n   int lim = (int)2e5; n   int pos; n   for (int num = lim; num >= 1; --num) { n     ++curColor; n     pos = 0; n     for (int j = num; j <= lim; j += num) { n       for (auto node : in[j]) { n         if (isGood[node] != curColor) { n           isGood[node] = curColor; n           curColorList[pos++] = node; n         } n       } n     } n     long long tmp = 0; n     for (int i = 0; i < pos; ++i) { n       int node = curColorList[i]; n       if (lastColor[node] < curColor) { n         int sz = bfs(node, curColor); n         tmp += (long long)sz * (sz + 1); n       } n     } n     tmp /= 2; n     all[num] = tmp; n   } n   for (int num = 1; num <= lim; ++num) { n     int g = 1; n     long long ret = 0; n     for (int j = num; j <= lim; j += num, ++g) { n       if (val[g] == g) { n         if (numPrime[g]) { n           ret -= all[j]; n         } else { n           ret += all[j]; n         } n       } n     } n     if (ret > 0) { n       printf( %d %lld n , num, ret); n     } n   } n } n int main() { solve(); } n


#include <bits/stdc++.h> n using namespace std; n const int N = 220; n int n, m; n pair<int, double> a[N]; n double Dp[N][N][N]; n double Rec(int i, int j, int k) { n   k = min(k, n); n   if (k < 0) return 0.0; n   if (i == n) return j >= m; n   if (Dp[i][j][k] == Dp[i][j][k]) return Dp[i][j][k]; n   return Dp[i][j][k] = a[i].second * Rec(i + 1, j + 1, k + a[i].first) + n                        (1.0 - a[i].second) * Rec(i + 1, j, k); n } n int main() { n   memset(Dp, -1, sizeof(Dp)); n   int k; n   cin >> n >> m >> k; n   for (int i = 0; i < n; i++) cin >> a[i].second, a[i].second /= 100.0; n   for (int i = 0; i < n; i++) cin >> a[i].first; n   sort(a, a + n); n   reverse(a, a + n); n   printf( %.9f , Rec(0, 0, k)); n } n


#include <bits/stdc++.h> n using namespace std; n inline int read() { n   int x = 0, c = getchar(), f = 0; n   for (; c >  9  || c <  0 ; f = c ==  - , c = getchar()) n     ; n   for (; c >=  0  && c <=  9 ; x = (x << 1) + (x << 3) + c -  0 , c = getchar()) n     ; n   return f ? -x : x; n } n inline void write(int x) { n   if (x < 0) putchar( - ), x = -x; n   if (x >= 10) write(x / 10); n   putchar(x % 10 + 48); n } n const int N = 100000 + 10; n int n, m, cnt = 1, head[N], du[N], layer[N], leader[N], q[N]; n bool vis1[N], vis2[N], vis3[N * 2]; n vector<vector<int> > ans; n vector<int> tmp, _; n vector<pair<int, int> > comp; n struct edge { n   int to, nxt; n } e[N * 4]; n void addedge(int u, int v) { n   e[++cnt] = (edge){v, head[u]}; n   head[u] = cnt; n   e[++cnt] = (edge){u, head[v]}; n   head[v] = cnt; n   du[u]++; n   du[v]++; n } n void dfs(int u, int fa, int lineid) { n   vis1[u] = 1; n   vis2[layer[u]] = 1; n   tmp.push_back(u); n   for (int i = head[u], v; i; i = e[i].nxt) n     if ((i >> 1) != lineid) { n       if (!vis1[v = e[i].to]) { n         dfs(v, u, i >> 1); n         tmp.push_back(u); n         for (; cnt >= 0 && vis2[comp[cnt].second]; cnt--) n           ; n         if (cnt >= 0) { n           vis3[i >> 1] = 1; n           v = leader[comp[cnt].second]; n           ans.push_back(tmp); n           tmp.clear(); n           _.clear(); n           _.push_back(i >> 1); n           _.push_back(u); n           _.push_back(v); n           ans.push_back(_); n           dfs(v, u, i >> 1); n           tmp.push_back(u); n         } n       } else { n         if (vis3[i >> 1]) continue; n         for (; cnt >= 0 && vis2[comp[cnt].second]; cnt--) n           ; n         if (cnt >= 0) { n           vis3[i >> 1] = 1; n           v = leader[comp[cnt].second]; n           ans.push_back(tmp); n           tmp.clear(); n           _.clear(); n           _.push_back(i >> 1); n           _.push_back(u); n           _.push_back(v); n           ans.push_back(_); n           dfs(v, u, i >> 1); n           tmp.push_back(u); n         } n       } n     } n } n void print() { n   puts( YES ); n   write(ans.size() / 2); n   puts(  ); n   for (int i = (int)0; i <= (int)ans.size() - 1; i++) { n     if (i & 1) n       write(ans[i][0]), putchar(   ), write(ans[i][1]), putchar(   ), n           write(ans[i][2]), puts(  ); n     else { n       write(ans[i].size()); n       for (int j = (int)0; j <= (int)ans[i].size() - 1; j++) n         putchar(   ), write(ans[i][j]); n       puts(  ); n     } n   } n } n int findbridge() { n   for (int i = (int)2; i <= (int)n; i++) vis1[i] = 0; n   for (int i = (int)1; i <= (int)m; i++) vis3[i] = 0; n   for (int i = (int)2; i <= (int)n; i++) n     if (!vis1[i]) { n       q[*q = 1] = i; n       vis1[i] = 1; n       for (int j = (int)1; j <= (int)*q; j++) { n         int u = q[j]; n         for (int k = head[u], v; k; k = e[k].nxt) n           if (!vis3[k >> 1]) { n             vis3[k >> 1] = 1; n             if (vis1[v = e[k].to]) n               return k >> 1; n             else n               vis1[v] = 1, q[++*q] = v; n           } n       } n     } n   return 0; n } n int getblo(int l, int r) { n   for (int i = (int)l; i <= (int)r; i++) vis1[i] = 0; n   int blo = 0; n   comp.clear(); n   for (int i = (int)l; i <= (int)r; i++) n     if (!vis1[i]) { n       ++blo; n       q[*q = 1] = i; n       vis1[i] = 1; n       for (int j = (int)1; j <= (int)*q; j++) { n         int u = q[j]; n         for (int k = head[u], v; k; k = e[k].nxt) n           if (!vis1[v = e[k].to]) vis1[v] = 1, q[++*q] = v; n       } n       for (int j = (int)1; j <= (int)*q; j++) layer[q[j]] = blo; n       leader[blo] = q[1]; n       comp.push_back(make_pair(*q, blo)); n     } n   sort(comp.begin(), comp.end()); n   return blo; n } n void go(int id) { n   int u = 1; n   for (int i = (int)2; i <= (int)n; i++) { n     for (int j = head[i], pre; j; pre = j, j = e[j].nxt) n       if ((j >> 1) == id) { n         if (du[i] > 1) u = i; n         du[i]--; n         if (j == head[i]) n           head[i] = e[j].nxt; n         else n           e[pre].nxt = e[j].nxt; n         break; n       } n   } n   getblo(2, n); n   cnt = comp.size() - 1; n   for (int i = (int)1; i <= (int)n; i++) vis1[i] = vis2[i] = 0; n   for (int i = (int)1; i <= (int)m; i++) vis3[i] = 0; n   vis1[1] = 1; n   _.clear(); n   _.push_back(1); n   ans.push_back(_); n   _.clear(); n   _.push_back(id); n   _.push_back(1); n   _.push_back(u); n   ans.push_back(_); n   dfs(u, 1, 0); n   if (tmp.size()) ans.push_back(tmp), tmp.clear(); n   print(); n } n int main() { n   n = read(), m = read(); n   for (int i = (int)1; i <= (int)m; i++) addedge(read(), read()); n   if (n == 1) return puts( YES n0 n1 1 n ), 0; n   int blo = getblo(1, n); n   if (m < blo - 1) return puts( NO ), 0; n   if (du[1]) { n     for (int i = (int)1; i <= (int)n; i++) vis1[i] = vis2[i] = 0; n     for (int i = (int)1; i <= (int)m; i++) vis3[i] = 0; n     cnt = comp.size() - 1; n     dfs(1, 0, 0); n     if (tmp.size()) ans.push_back(tmp), tmp.clear(); n     print(); n   } else { n     int id = findbridge(); n     if (id) n       go(id); n     else { n       if (m < blo) n         puts( NO ); n       else { n         for (int i = (int)2; i <= (int)n; i++) n           if (du[i] > 1) { n             id = head[i] / 2; n             break; n           } n         if (id) n           go(id); n         else n           puts( NO ); n       } n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int oo = (int)1e9; n const double eps = 1e-9; n long long gcd(long long a, long long b); n int main() { n   int n; n   long long maxi = 0, num, g; n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> num; n     maxi = max(maxi, num); n     g = gcd(g, num); n   } n   if ((maxi / g - n) % 2) n     cout <<  Alice  << endl; n   else n     cout <<  Bob  << endl; n } n long long gcd(long long a, long long b) { n   if (b == 0) n     return a; n   else n     return gcd(b, a % b); n } n


#include <bits/stdc++.h> n const int maxn = 0x3f3f3f3f; n const double EI = n     2.71828182845904523536028747135266249775724709369995957496696762772407663035354594571382178525166427; n const double PI = 3.141592653589793238462643383279; n using namespace std; n struct node { n   int l, r; n   double x, y, a; n } tree[300010 * 4]; n int n; n void pushup(int p) { n   double dis = sqrt(tree[2 * p + 1].x * tree[2 * p + 1].x + n                     tree[2 * p + 1].y * tree[2 * p + 1].y); n   double a = atan2(tree[2 * p + 1].y, tree[2 * p + 1].x); n   tree[p].x = tree[2 * p].x + dis * cos(tree[2 * p].a + a); n   tree[p].y = tree[2 * p].y + dis * sin(tree[2 * p].a + a); n   tree[p].a = tree[2 * p].a + tree[2 * p + 1].a; n   return; n } n void build(int l, int r, int p) { n   tree[p].l = l; n   tree[p].r = r; n   if (l + 1 == r) { n     tree[p].x = 1.0; n     tree[p].y = 0.0; n     tree[p].a = 0.0; n     return; n   } n   int k = ((l + r) >> 1); n   build(l, k, p << 1); n   build(k, r, (p << 1) + 1); n   pushup(p); n   return; n } n void update(int pos, double len, double aa, int p) { n   if (tree[p].l + 1 == tree[p].r) { n     double dis = sqrt(tree[p].x * tree[p].x + tree[p].y * tree[p].y); n     double a = atan2(tree[p].y, tree[p].x); n     dis += len, a += aa; n     tree[p].x = dis * cos(a); n     tree[p].y = dis * sin(a); n     tree[p].a = a; n     return; n   } n   if (pos <= tree[p << 1].r) { n     update(pos, len, aa, p << 1); n   } else { n     update(pos, len, aa, (p << 1) + 1); n   } n   pushup(p); n   return; n } n int main() { n   double val; n   int q, op, pos; n   while (~scanf( %d %d , &n, &q)) { n     build(0, n, 1); n     while (q--) { n       scanf( %d %d %lf , &op, &pos, &val); n       if (op == 1) { n         update(pos, val, 0, 1); n       } else { n         update(pos, 0, (1 - val / 360) * 2 * PI, 1); n       } n       printf( %.10f %.10f n , tree[1].x, tree[1].y); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   long long int t; n   cin >> t; n   while (t--) { n     long long int n; n     cin >> n; n     string s; n     cin >> s; n     long long int oc = 0, zc = 0, fpos = -1, lpos; n     for (int i = 0; i < (int)n; i++) { n       if (s[i] ==  0 ) n         zc++; n       else { n         oc++; n         if (fpos == -1) { n           fpos = i; n         } n         lpos = i; n       } n     } n     if (oc == 0) n       cout << n <<   n ; n     else if (zc == 0) n       cout << 2 * n <<   n ; n     else { n       if (s[0] ==  1 ) { n         cout << 2 * n <<   n ; n       } else { n         cout << 2 * max((n - fpos), (lpos + 1)) <<   n ; n       } n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int32_t main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   long long n; n   cin >> n; n   long long a[n + 1]; n   long long diff[n]; n   long long max_count = INT_MIN; n   for (long long i = 1; i <= n; i++) cin >> a[i]; n   multiset<long long> eles; n   eles.insert(a[1]); n   long long i = 2, j = 1; n   while (i <= n && j <= n) { n     eles.insert(a[i]); n     long long mini = *eles.begin(); n     long long maxi = *eles.rbegin(); n     while (maxi - mini > 1) { n       eles.erase(eles.find(a[j])); n       j++; n       maxi = *eles.rbegin(); n       mini = *eles.begin(); n     } n     long long sz = eles.size(); n     max_count = max(max_count, sz); n     i++; n   } n   cout << max_count; n   return 0; n } n


#include <bits/stdc++.h> n int main() { n   int n, i, j, count = 0; n   scanf( %d , &n); n   int ara[n]; n   for (i = 0; i < n; i++) { n     scanf( %d , &ara[i]); n   } n   for (i = 0; i < n - 1; i++) { n     for (j = i + 1; j < n; j++) { n       if (ara[i] == 0) { n         continue; n       } n       if (ara[i] == ara[j]) { n         ara[i] = 0; n       } n     } n     if (ara[i] != 0) { n       count++; n     } n   } n   if (ara[n - 1] != 0) { n     count++; n   } n   printf( %d n , count); n   for (i = 0; i < n; i++) { n     if (ara[i] == 0) { n       continue; n     } n     printf( %d  , ara[i]); n   } n   printf(  n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char s[450000]; n int main() { n   scanf( %s , &s); n   vector<string> list; n   char cur, last =  ! ; n   string word =   ; n   int len = strlen(s); n   for (int i = 0; i < len; i++) { n     cur = s[i]; n     if (last ==  ! ) { n       if (cur !=  . ) { n         word += cur; n       } else { n         printf( NO ); n         return 0; n       } n     } else { n       if (cur ==  . ) { n         if (last !=  . ) { n           if (((word.length() > 11))) { n             printf( NO ); n             return 0; n           } else { n             list.push_back(word); n             word =   ; n           } n         } else { n           printf( NO ); n           return 0; n         } n       } else { n         word += cur; n       } n     } n     last = cur; n   } n   if (last ==  . ) { n     printf( NO ); n     return 0; n   } n   if (word !=   ) { n     if (word.length() < 4) { n       list.push_back(word); n     } else { n       printf( NO ); n       return 0; n     } n   } n   if (list.size() == 2) { n     if (!(list[0].length() > 0 && list[0].length() < 9 && n           list[1].length() > 0 && list[1].length() < 4)) { n       printf( NO ); n       return 0; n     } n   } else { n     if (list.size() == 1) { n       printf( NO ); n       return 0; n     } n   } n   for (int i = 1; i < list.size() - 1; i++) { n     if (list[i].length() == 1) { n       printf( NO ); n       return 0; n     } n   } n   len = list.size(); n   bool was = false; n   for (int i = 0; i < len; i++) { n     if (!was) { n       was = true; n       if (list[i].length() > 8) { n         printf( NO ); n         return 0; n       } else { n         cout <<  YES n ; n         cout << list[i] <<  . ; n       } n     } else { n       if (i != len - 1) { n         if (list[i].length() > 3) { n           cout << list[i].substr(0, 3) <<   n ; n           cout << list[i].substr(3, list[i].length() - 3) <<  . ; n         } else { n           cout << list[i].substr(0, 1) <<   n ; n           cout << list[i].substr(1, list[i].length() - 1) <<  . ; n         } n       } else { n         cout << list[i] <<   n ; n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double EPS = 1.0e-8; n struct Point { n   double x, y; n   Point(double _x = 0, double _y = 0) { n     x = _x; n     y = _y; n   } n   friend Point operator+(const Point &a, const Point &b) { n     return Point(a.x + b.x, a.y + b.y); n   } n   friend Point operator-(const Point &a, const Point &b) { n     return Point(a.x - b.x, a.y - b.y); n   } n   friend double operator^(const Point &a, const Point &b) { n     return a.x * b.y - a.y * b.x; n   } n }; n Point Basic; n set<Point> Set; n double Distance(Point a, Point b) { n   return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y)); n } n bool operator<(Point a, Point b) { n   a = a - Basic; n   b = b - Basic; n   double Ang1 = atan2(a.y, a.x), Ang2 = atan2(b.y, b.x); n   double Len1 = Distance(a, Point(0.0, 0.0)), n          Len2 = Distance(b, Point(0.0, 0.0)); n   if (fabs(Ang1 - Ang2) < EPS) return Len1 < Len2; n   return Ang1 < Ang2; n } n set<Point>::iterator Pre(set<Point>::iterator it) { n   if (it == Set.begin()) it = Set.end(); n   return --it; n } n set<Point>::iterator Nxt(set<Point>::iterator it) { n   ++it; n   return it == Set.end() ? Set.begin() : it; n } n int Query(Point p) { n   set<Point>::iterator it = Set.lower_bound(p); n   if (it == Set.end()) it = Set.begin(); n   return ((p - *(Pre(it))) ^ (*(it) - *(Pre(it)))) < EPS; n } n void Insert(Point p) { n   if (Query(p)) return; n   Set.insert(p); n   set<Point>::iterator it = Nxt(Set.find(p)); n   while (Set.size() > 3 && ((p - *(Nxt(it))) ^ (*(it) - *(Nxt(it)))) < EPS) { n     Set.erase(it); n     it = Nxt(Set.find(p)); n   } n   it = Pre(Set.find(p)); n   while (Set.size() > 3 && ((p - *(it)) ^ (*(it) - *(Pre(it)))) > -EPS) { n     Set.erase(it); n     it = Pre(Set.find(p)); n   } n } n int main() { n   int q; n   scanf( %d , &q); n   Basic = Point(0, 0); n   int oper; n   Point a, str[5]; n   for (int i = 1; i <= 3; ++i) { n     scanf( %d%lf%lf , &oper, &str[i].x, &str[i].y); n     Basic = Basic + str[i]; n   } n   Basic.x /= 3.0; n   Basic.y /= 3.0; n   q -= 3; n   for (int i = 1; i <= 3; ++i) { n     Set.insert(str[i]); n   } n   while (q--) { n     scanf( %d%lf%lf , &oper, &a.x, &a.y); n     if (oper == 1) { n       Insert(a); n     } else { n       if (Query(a)) n         printf( YES n ); n       else n         printf( NO n ); n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n  n #define fast_io                n     ios::sync_with_stdio(0);   n     cin.tie(NULL);             n     cout.tie(NULL); n #define lli long long n #define loop(i, l, r) for (lli i = l; l < r ? i < r : i > r; l < r ? i += 1 : i -= 1) n #define itr(it, a) for (auto it = a.begin(); it != a.end(); it++) n #define it(i, a) for (auto i : a) n #define endl   n  n #define inputarray(arr, start, size)   n     loop(i, start, size) { cin >> arr[i]; } n #define printarray(arr, start, size)                  n     loop(i, start, size) { cout << arr[i] <<    ; }   n     cout << endl; n #define mod 1000000007 n #define inf 1e18 n #define sp(x, y) fixed << setprecision(y) << x << endl; n #define pii pair<lli, lli> n #define mp make_pair n #define pb push_back n #define fi first n #define se second n #define all(x) x.begin(), x.end() n #define clr(x) memset(x, 0, sizeof(x)) n #define sortall(x) sort(all(x)) n #define debug(x) cout << #x <<  =  << x << endl n  n int main() n { n #ifndef ONLINE_JUDGE n     freopen( input.txt ,  r , stdin); n     freopen( output.txt ,  w , stdout); n #endif n     fast_io n         lli t = 1; n     cin >> t; n     while (t--) n     { n         lli n; n         cin >> n; n         vector<lli> v(n); n         inputarray(v, 0, n); n         bool flag = 0; n         lli diff = INT_MAX, md = INT_MIN; n         loop(i, 0, n) n         { n             if (v[i] < 0) n             { n                 flag = 1; n                 break; n             } n         } n         if (flag) n         { n             cout <<  NO  << endl; n             continue; n         } n  n         cout <<  YES  << endl; n         cout <<  101  << endl; n         vector<lli> b; n         loop(i, 0, 101) n         { n             b.push_back(i); n         } n         printarray(b, 0, b.size()); n     } n     return 0; n }


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n using ld = long double; n vector<vector<int>> selfloops; n vector<vector<pair<int, int>>> adjlist; n vector<vector<int>> otherIdx; n vector<int> cycle, validIdx; n void swapEdges(int n, int a, int b) { n   int neighA = adjlist[n][a].first, neighB = adjlist[n][b].first; n   int idxNeighA = otherIdx[n][a], idxNeighB = otherIdx[n][b]; n   swap(adjlist[n][a], adjlist[n][b]); n   swap(otherIdx[n][a], otherIdx[n][b]); n   otherIdx[neighA][idxNeighA] = b; n   otherIdx[neighB][idxNeighB] = a; n } n void removeEdge(int n, int i) { n   int other = adjlist[n][i].first; n   validIdx[n]++; n   int otherIndex = otherIdx[n][i]; n   if (otherIndex != validIdx[other]) { n     swapEdges(other, otherIndex, validIdx[other]); n   } n   validIdx[other]++; n } n void addEdge(int a, int b, int id) { n   otherIdx[a].push_back((ll)(adjlist[b]).size() + (a == b)); n   otherIdx[b].push_back((ll)(adjlist[a]).size()); n   adjlist[a].push_back({b, id}); n   adjlist[b].push_back({a, -id}); n } n void euler(int n) { n   while (validIdx[n] < (ll)(adjlist[n]).size()) { n     ll edge = adjlist[n][validIdx[n]].second; n     int nn = adjlist[n][validIdx[n]].first; n     removeEdge(n, validIdx[n]); n     euler(nn); n     cycle.push_back(edge); n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(nullptr); n   ll n; n   cin >> n; n   vector<pair<ll, ll>> in(n); n   for (ll i = 0; i < n; i++) { n     ll a, b; n     cin >> a >> b; n     in[i] = {a, b}; n   } n   auto ok = [&](ll res) { n     selfloops.assign(1ll << res, {}); n     adjlist.assign(1ll << res, {}); n     otherIdx.assign(1ll << res, {}); n     validIdx.assign(1ll << res, 0); n     cycle.clear(); n     ll mask = (1ll << res) - 1; n     for (ll i = 0; i < n; i++) { n       addEdge(in[i].first & mask, in[i].second & mask, i + 1); n     } n     bool ok = true; n     ll start = 0; n     for (ll i = 0; i < (1ll << res); i++) { n       ok &= ((ll)(adjlist[i]).size() % 2) == 0; n       if (!adjlist[i].empty()) start = i; n     } n     if (ok) euler(start); n     return (ll)(cycle).size() == n; n   }; n   ll l = 0; n   ll r = 21; n   while (l + 1 < r) { n     ll m = (l + r) / 2; n     if (ok(m)) { n       l = m; n     } else { n       r = m; n     } n   } n   ok(l); n   reverse(begin(cycle), end(cycle)); n   cout << l << endl; n   for (ll x : cycle) { n     ll a = 2 * abs(x) - 1; n     ll b = 2 * abs(x); n     ll c = in[abs(x) - 1].first; n     ll d = in[abs(x) - 1].second; n     if (x < 0) swap(a, b); n     if (x < 0) swap(c, d); n     cout << a <<     << b <<    ; n   } n   cout << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string word, type; n   int n; n   cin >> n; n   int j; n   int cur = 0, real = 0, sreal = 0; n   bool t = false, b = false; n   getline(cin, word); n   for (int i = 0; i < n; ++i) { n     getline(cin, word); n     for (j = 0; j < (int)word.size() && word[j] ==    ; ++j) n       ; n     if (j != word.size()) { n       if (word[j] ==  c ) { n         if (t) { n           if (cur <= real) { n             for (; j < (int)word.size() && word[j] !=  ( ; ++j) n               ; n             for (; j < (int)word.size() && word[j] ==  (  || word[j] ==    ; n                  ++j) n               ; n             if (type == word.substr(j, type.size())) { n               for (; j < (int)word.size() && word[j] !=    ; ++j) n                 ; n               ++j; n               for (; j < (int)word.size() && word[j] !=    ; ++j) { n                 cout << word[j]; n               } n               return 0; n             } n           } n           --cur; n           if (b) { n             if (sreal) { n               --sreal; n             } else { n               --real; n             } n           } n         } n       } n       if (word[j] ==  t  && word[j + 1] ==  r ) { n         ++cur; n         if (b) { n           ++sreal; n         } n       } n       if (word[j] ==  t  && word[j + 1] ==  h ) { n         t = true; n         b = true; n         for (; j < word.size() && word[j] !=  ( ; ++j) n           ; n         for (; j < word.size() && word[j] ==  (  || word[j] ==    ; ++j) n           ; n         for (; j < word.size() && word[j] !=     && word[j] !=  ) ; ++j) { n           type.push_back(word[j]); n         } n         real = cur; n       } n     } n   } n   cout <<  Unhandled Exception ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, L, m, head[1000005], cnt, root, sz[1000005], sum, mx; n long long t[1000005], ans; n struct edge { n   int to, next, cost; n } e[1000005 << 1]; n struct dist { n   int len, dis; n   bool operator<(const dist &p) const { return dis < p.dis; } n } dis[1000005], q[1000005]; n bool vis[1000005]; n inline int read() { n   int x = 0, w = 1; n   char c = getchar(); n   while (c <  0  || c >  9 ) { n     if (c ==  - ) w = -1; n     c = getchar(); n   } n   while (c >=  0  && c <=  9 ) { n     x = x * 10 + c -  0 ; n     c = getchar(); n   } n   return x * w; n } n int lowbit(int x) { return x & (-x); } n void add(int x, int y) { n   if (x == 0) return; n   for (int i = x; i <= n + 1; i += lowbit(i)) t[i] += y; n } n long long query(int x) { n   if (x <= 0) return 0; n   long long res = 0; n   for (int i = x; i; i -= lowbit(i)) res += t[i]; n   return res; n } n inline void add(int u, int v, int w) { n   e[++cnt] = (edge){v, head[u], w}; n   head[u] = cnt; n } n void fdrt(int u, int fa) { n   sz[u] = 1; n   int num = 0; n   for (int i = head[u]; i; i = e[i].next) { n     int v = e[i].to; n     if (v == fa || vis[v]) continue; n     fdrt(v, u); n     sz[u] += sz[v]; n     num = max(num, sz[v]); n   } n   num = max(num, sum - sz[u]); n   if (mx > num) mx = num, root = u; n } n void gtds(int u, int fa) { n   q[++cnt] = dis[u]; n   for (int i = head[u]; i; i = e[i].next) { n     int v = e[i].to; n     if (v == fa || vis[v]) continue; n     dis[v].len = dis[u].len + 1; n     dis[v].dis = dis[u].dis + e[i].cost; n     gtds(v, u); n   } n } n long long calc(int u, int len, int d) { n   cnt = 0; n   dis[u].len = len, dis[u].dis = d; n   gtds(u, 0); n   sort(q + 1, q + cnt + 1); n   for (int i = 1; i <= cnt; i++) add(q[i].len + 1, 1); n   int l = 1, r = cnt; n   long long res = 0; n   while (l < r) { n     if (q[l].dis + q[r].dis <= m) { n       add(q[l].len + 1, -1); n       res += query(L - q[l].len + 1); n       l++; n     } else n       add(q[r].len + 1, -1), r--; n   } n   add(q[l].len + 1, -1); n   return res; n } n void solve(int u) { n   ans += calc(u, 0, 0); n   vis[u] = 1; n   for (int i = head[u]; i; i = e[i].next) { n     int v = e[i].to; n     if (vis[v]) continue; n     ans -= calc(v, 1, e[i].cost); n     sum = mx = sz[v]; n     fdrt(v, 0); n     solve(root); n   } n } n int main() { n   n = read(); n   L = read(); n   m = read(); n   for (int i = 2; i <= n; i++) { n     int u = read(), w = read(); n     add(u, i, w); n     add(i, u, w); n   } n   sum = mx = n; n   fdrt(1, 0); n   solve(root); n   printf( %I64d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int sum = 0, n, a[120], x, y, i; n   cin >> n; n   for (i = 0; i < n - 1; ++i) { n     cin >> a[i]; n   } n   cin >> x >> y; n   for (i = x - 1; i < y - 1; ++i) { n     sum += a[i]; n   } n   cout << sum <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1100, M = 2 * 1e5 + 10, INF = 1e9 + 10; n pair<int, int> e[M]; n int dp[N][N]; n vector<pair<pair<int, int>, pair<int, int> > > que[M]; n bool ans[M]; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   int n, m, q; n   cin >> n >> m >> q; n   for (int i = 0; i < m; i++) cin >> e[i].first >> e[i].second; n   for (int i = 0; i < q; i++) { n     int l, r, s, t; n     cin >> l >> r >> s >> t; n     l--; n     que[l].push_back({{s, t}, {r, i}}); n   } n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= n; j++) n       if (i != j) dp[i][j] = INF; n   for (int i = m - 1; i >= 0; i--) { n     int u = e[i].first, v = e[i].second; n     dp[u][v] = dp[v][u] = i; n     for (int j = 1; j <= n; j++) { n       if (j == u || j == v) continue; n       if (dp[u][j] > dp[v][j]) n         dp[u][j] = dp[v][j]; n       else n         dp[v][j] = dp[u][j]; n     } n     for (auto X : que[i]) { n       int s = X.first.first, t = X.first.second, r = X.second.first, n           id = X.second.second; n       if (dp[s][t] < r) n         ans[id] = true; n       else n         ans[id] = false; n     } n   } n   for (int i = 0; i < q; i++) { n     if (ans[i]) n       cout <<  Yes n ; n     else n       cout <<  No n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int col[5001], mid, n, dis[5001][5001], ans; n bool v[5001]; n long long mod = 1e9 + 7; n bool dfs(int x) { n   v[x] = 1; n   for (int i = 1; i <= n; ++i) n     if (i != x && dis[x][i] > mid) n       if (!v[i]) { n         col[i] = col[x] ^ 1; n         if (dfs(i)) return 1; n       } else if (col[x] == col[i]) n         return 1; n   return 0; n } n bool check() { n   memset(v, 0, sizeof(v)); n   for (int i = 1; i <= n; ++i) n     if (!v[i]) n       if (dfs(i)) return 0; n   return 1; n } n void dfss(int x) { n   v[x] = 1; n   for (int i = 1; i <= n; ++i) n     if (!v[i] && dis[x][i] > ans) dfss(i); n } n long long mult(long long x, long long y) { n   long long res = x * 1ll; n   y--; n   while (y) { n     if (y & 1) res = res * x % mod; n     x = x * x % mod; n     y >>= 1; n   } n   return res; n } n int cnt, x[5001], y[5001]; n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; ++i) scanf( %d%d , &x[i], &y[i]); n   for (int i = 1; i <= n; ++i) n     for (int j = 1; j <= n; ++j) n       dis[i][j] = abs(x[i] - x[j]) + abs(y[i] - y[j]); n   int l = 0, r = 10000; n   while (l <= r) { n     mid = l + r >> 1; n     if (check()) { n       ans = mid; n       r = mid - 1; n     } else n       l = mid + 1; n   } n   memset(v, 0, sizeof(v)); n   printf( %d n , ans); n   for (int i = 1; i <= n; ++i) n     if (!v[i]) { n       ++cnt; n       dfss(i); n     } n   printf( %I64d , mult(2ll, (long long)cnt)); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 200 * 1000 + 13; n const long long INF64 = 1e18; n int n, m; n long long a[N]; n vector<pair<int, long long>> g[N]; n long long dist[N]; n void Dijkstra() { n   set<pair<long long, int>> q; n   for (int i = 0; i < int(n); i++) { n     dist[i] = a[i]; n     q.insert({dist[i], i}); n   } n   while (!q.empty()) { n     int v = q.begin()->second; n     q.erase(q.begin()); n     for (auto it : g[v]) { n       int u = it.first; n       long long w = it.second; n       if (dist[u] > dist[v] + w) { n         q.erase({dist[u], u}); n         dist[u] = dist[v] + w; n         q.insert({dist[u], u}); n       } n     } n   } n } n int main() { n   scanf( %d%d , &n, &m); n   for (int _ = 0; _ < int(m); _++) { n     int f, t; n     long long w; n     scanf( %d%d%lld , &f, &t, &w); n     --f, --t; n     w *= 2; n     g[f].push_back({t, w}); n     g[t].push_back({f, w}); n   } n   for (int i = 0; i < int(n); i++) { n     scanf( %lld , &a[i]); n   } n   Dijkstra(); n   for (int i = 0; i < int(n); i++) printf( %lld  , dist[i]); n   puts(  ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int _ = 2e2 + 20; n int n; n struct matrix { n   double a[_][_]; n   matrix operator*(matrix b) { n     matrix c; n     for (int i = 0; i <= n * 2; ++i) n       for (int j = 0; j <= n * 2; ++j) { n         c.a[i][j] = 0; n         for (int k = 0; k <= n * 2; ++k) n           c.a[i][j] = max(c.a[i][j], a[i][k] + b.a[k][j]); n         c.a[i][j] /= 2; n       } n     return c; n   } n } A; n double a[_]; n int main() { n   cin >> n; n   for (int i = 0; i <= n; ++i) cin >> a[i]; n   for (int i = 0; i <= n * 2; ++i) { n     for (int j = 0; j <= n * 2; ++j) { n       if (i + j >= n && (i + n - j & 1) == 0 && i - j <= n && j - i <= n) n         A.a[i][j] = a[(i + n - j) / 2]; n       else n         A.a[i][j] = -1e18; n     } n   } n   double ans = 0; n   for (int i = 1; i <= 50; ++i) A = A * A; n   for (int i = 0; i <= n * 2; ++i) ans = max(ans, A.a[0][i]); n   printf( %.10f n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 3000010; n const int inf = 1e9 + 1; n int n, k, a[N], b[N]; n bool check(long long x) { n   long long s = 0; n   for (int i = 1; i <= n; i++) { n     long long tmp = b[i] - a[i] * x; n     if (tmp < 0) { n       s -= tmp; n     } n     if (s > k) return false; n   } n   return (s <= k); n } n int main() { n   scanf( %d%d , &n, &k); n   for (int i = 1; i <= n; i++) scanf( %d , &a[i]); n   for (int i = 1; i <= n; i++) scanf( %d , &b[i]); n   long long l = 0, r = 2e9; n   while (l + 1 < r) { n     long long m = (l + r) / 2; n     if (check(m)) n       l = m; n     else n       r = m - 1; n   } n   if (check(r)) n     cout << r; n   else n     cout << l; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s; n   cin >> s; n   stack<char> stk; n   int cnt = 0; n   for (int i = s.size() - 1; i >= 0; i--) { n     if (stk.empty()) n       stk.push(s[i]); n     else { n       if (stk.top() == s[i]) { n         cnt++; n         stk.pop(); n       } else n         stk.push(s[i]); n     } n   } n   cout << (cnt & 1 ?  Yes  :  No ) << endl; n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n void File_input() { n   freopen( in.txt ,  r , stdin); n   freopen( out.txt ,  w , stdout); n } n void FastInputOutput() { n   ios_base ::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n } n vector<char> geno[ z  + 1]; n int t, n; n string str; n bool vis[ z  + 1], in[ z  + 1]; n int indeg[ z  + 1]; n void DFS(char a) { n   cout << a; n   for (auto i : geno[a]) { n     if (!vis[i]) { n       vis[i] = 1; n       DFS(i); n     } n   } n } n int main() { n   cin >> t; n   while (t--) { n     cin >> str; n     n = (long long)str.size(); n     for (int i = 0; i < n; i++) in[str[i]] = 1; n     for (int i = 1; i < n; i++) { n       geno[str[i - 1]].push_back(str[i]); n       indeg[str[i]]++; n     } n   } n   for (char a =  a ; a <=  z ; a++) { n     if (!vis[a] && in[a] && !indeg[a]) { n       DFS(a); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n double distance(double x1, double y1, double x2, double y2) { n   return sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1)); n } n int main() { n   double ax, ay, bx, by, tx, ty; n   scanf( %lf%lf%lf%lf%lf%lf , &ax, &ay, &bx, &by, &tx, &ty); n   int n; n   scanf( %d , &n); n   double cdist[n], D = 0; n   pair<double, double> p[n]; n   for (int i = 0; i < n; ++i) { n     scanf( %lf%lf , &p[i].first, &p[i].second); n     cdist[i] = distance(tx, ty, p[i].first, p[i].second); n     D += 2 * cdist[i]; n   } n   set<pair<double, int> > A, B; n   double distA[n], distB[n]; n   for (int i = 0; i < n; ++i) { n     double x = -cdist[i] + distance(ax, ay, p[i].first, p[i].second); n     distA[i] = x; n     A.insert({x, i}); n     x = -cdist[i] + distance(bx, by, p[i].first, p[i].second); n     distB[i] = x; n     B.insert({x, i}); n   } n   double temp1 = D + A.begin()->first; n   double temp2 = D + B.begin()->first; n   double temp3 = D + A.begin()->first; n   int idx = A.begin()->second; n   B.erase({distB[idx], idx}); n   if (not B.empty()) temp3 += B.begin()->first; n   B.insert({distB[idx], idx}); n   double temp4 = D + B.begin()->first; n   idx = B.begin()->second; n   A.erase({distA[idx], idx}); n   if (not A.empty()) temp4 += A.begin()->first; n   double ans = min(min(temp1, temp2), min(temp3, temp4)); n   printf( %lf n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct Activity { n   int gym, contest; n   bool gym_used, contest_used; n }; n int main() { n   int n; n   cin >> n; n   vector<int> v(n); n   for (int &e : v) cin >> e; n   vector<Activity> res(n); n   switch (v[0]) { n     case 0: n       res[0].gym = res[0].contest = 0; n       res[0].gym_used = res[0].contest_used = false; n       break; n     case 1: n       res[0].gym = 0; n       res[0].contest = 1; n       res[0].gym_used = false; n       res[0].contest_used = true; n       break; n     case 2: n       res[0].gym = 1; n       res[0].contest = 0; n       res[0].gym_used = true; n       res[0].contest_used = false; n       break; n     case 3: n       res[0].gym = res[0].contest = 1; n       res[0].gym_used = res[0].contest_used = true; n       break; n   } n   for (int i = 1; i < v.size(); i++) { n     if (v[i] == 1) { n       res[i] = res[i - 1]; n       res[i].contest_used = res[i].gym_used = false; n     } n     if (v[i] == 1 || v[i] == 3) { n       if (res[i - 1].contest_used) { n         if (res[i - 1].gym >= res[i - 1].contest) { n           res[i].contest_used = true; n           res[i].contest = res[i - 1].gym + 1; n         } else { n           res[i].contest_used = false; n           res[i].contest = res[i - 1].contest; n         } n       } else { n         res[i].contest_used = true; n         res[i].contest = max(res[i - 1].gym, res[i - 1].contest) + 1; n       } n     } n     if (v[i] == 0 || v[i] == 1) { n       res[i].gym = res[i - 1].gym; n       res[i].gym_used = false; n     } n     if (v[i] == 0 || v[i] == 2) { n       res[i].contest = res[i - 1].contest; n       res[i].contest_used = false; n     } n     if (v[i] == 2 || v[i] == 3) { n       if (res[i - 1].gym_used) { n         if (res[i - 1].contest >= res[i - 1].gym) { n           res[i].gym_used = true; n           res[i].gym = res[i - 1].contest + 1; n         } else { n           res[i].gym_used = false; n           res[i].gym = res[i - 1].gym; n         } n       } else { n         res[i].gym_used = true; n         res[i].gym = max(res[i - 1].gym, res[i - 1].contest) + 1; n       } n     } n   } n   cout << n - max(res[n - 1].gym, res[n - 1].contest) << endl; n } n


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


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e6 + 60; n const int IN = 0; n const int AND = 1; n const int OR = 2; n const int XOR = 3; n const int NOT = 4; n struct Node { n   int val, p1, p2; n   int op; n } node[maxn]; n int n, p1, p2; n string op; n bool change[maxn]; n int eval(int cur) { n   if (node[cur].op == IN) { n     return node[cur].val; n   } n   if (node[cur].op == AND) { n     return node[cur].val = (eval(node[cur].p1) & eval(node[cur].p2)); n   } n   if (node[cur].op == OR) { n     return node[cur].val = (eval(node[cur].p1) | eval(node[cur].p2)); n   } n   if (node[cur].op == XOR) { n     return node[cur].val = (eval(node[cur].p1) ^ eval(node[cur].p2)); n   } n   if (node[cur].op == NOT) { n     return node[cur].val = (!eval(node[cur].p1)); n   } n } n void process(int cur, int now) { n   int l = node[cur].p1; n   int r = node[cur].p2; n   int vl = node[l].val; n   int vr = node[r].val; n   if (node[cur].op == IN) { n     return; n   } else if (node[cur].op == AND) { n     if (vl == 0 && vr == 0) { n       process(l, change[l] = 0); n       process(r, change[r] = 0); n     } else if (vl == 0 && vr == 1) { n       process(l, change[l] = (now & 1)); n       process(r, change[r] = 0); n     } else if (vl == 1 && vr == 0) { n       process(l, change[l] = 0); n       process(r, change[r] = (now & 1)); n     } else if (vl == 1 && vr == 1) { n       process(l, change[l] = (now & 1)); n       process(r, change[r] = (now & 1)); n     } n   } else if (node[cur].op == OR) { n     if (vl == 0 && vr == 0) { n       process(l, change[l] = (now & 1)); n       process(r, change[r] = (now & 1)); n     } else if (vl == 0 && vr == 1) { n       process(l, change[l] = 0); n       process(r, change[r] = (now & 1)); n     } else if (vl == 1 && vr == 0) { n       process(l, change[l] = (now & 1)); n       process(r, change[r] = 0); n     } else if (vl == 1 && vr == 1) { n       process(l, change[l] = 0); n       process(r, change[r] = 0); n     } n   } else if (node[cur].op == XOR) { n     process(l, change[l] = (now & 1)); n     process(r, change[r] = (now & 1)); n   } else if (node[cur].op == NOT) { n     process(l, change[l] = (now & 1)); n   } n } n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) { n     cin >> op; n     if (op ==  IN ) { n       scanf( %d , &p1); n       node[i] = {p1, 0, 0, IN}; n     } else if (op ==  NOT ) { n       scanf( %d , &p1); n       node[i] = {0, p1, 0, NOT}; n     } else if (op ==  AND ) { n       scanf( %d%d , &p1, &p2); n       node[i] = {0, p1, p2, AND}; n     } else if (op ==  OR ) { n       scanf( %d%d , &p1, &p2); n       node[i] = {0, p1, p2, OR}; n     } else if (op ==  XOR ) { n       scanf( %d%d , &p1, &p2); n       node[i] = {0, p1, p2, XOR}; n     } n   } n   eval(1); n   process(1, 1); n   for (int i = 1; i <= n; i++) { n     if (node[i].op == IN) printf( %d , change[i] ^ node[1].val); n   } n } n


#include <bits/stdc++.h> n using namespace std; n const long long INF = (long long)1e13 + 7LL; n int reqHigh[100100], grow[100100]; n int n, nDay, allow, cut; n struct Tree { n   int id; n   long long finHigh, timeDie; n   Tree() { id = finHigh = timeDie = 0; } n   Tree(int id, long long x) { n     this->id = id; n     finHigh = x - 1LL * grow[id] * nDay; n     timeDie = min((x + 1) / grow[id] + ((x + 1) % grow[id] > 0), nDay + 1LL); n   } n   void cutTree(void) { n     finHigh += cut; n     long long tmp = finHigh + 1LL * grow[id] * nDay + 1; n     timeDie = min(tmp / grow[id] + (tmp % grow[id] > 0), nDay + 1LL); n   } n   bool needCut(void) const { return (finHigh < reqHigh[id]); } n   bool operator>(const Tree &t) const { n     if (timeDie != t.timeDie) return (timeDie < t.timeDie); n     return (reqHigh[id] - finHigh > reqHigh[t.id] - t.finHigh); n   } n   bool operator<(const Tree &t) const { return (t > *this); } n }; n void init(void) { n   scanf( %d%d%d%d , &n, &nDay, &allow, &cut); n   for (int i = (1), _b = (n); i <= _b; i = i + 1) n     scanf( %d%d , &reqHigh[i], &grow[i]); n } n bool ok(long long x) { n   priority_queue<Tree> q; n   for (int i = (1), _b = (n); i <= _b; i = i + 1) q.push(Tree(i, x)); n   for (int i = (1), _b = (nDay); i <= _b; i = i + 1) { n     Tree tmp = q.top(); n     q.pop(); n     if (tmp.timeDie <= i) return (false); n     q.push(tmp); n     int used = 0; n     while (used < allow) { n       Tree tmp = q.top(); n       q.pop(); n       if (!tmp.needCut()) return (true); n       tmp.cutTree(); n       q.push(tmp); n       used++; n     } n   } n   Tree tmp = q.top(); n   q.pop(); n   return (!tmp.needCut()); n } n long long process(void) { n   long long L = 1; n   long long R = INF; n   while (true) { n     if (L == R) return (R); n     if (R - L == 1) return (ok(L) ? L : R); n     long long M = (L + R) >> 1; n     if (ok(M)) n       R = M; n     else n       L = M + 1; n   } n } n int main(void) { n   init(); n   cout << process() << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 105; n int n, m, grid[N][N]; n int val[N][N]; n bool vis[105][105]; n int a[105]; n int b[105]; n int dp[105][105]; n int tot; n int main() { n   scanf( %d%d , &n, &m); n   for (int i = 0; i < n; i++) scanf( %d , a + i), tot ^= a[i]; n   int tmp = 0; n   for (int i = 0; i < m; i++) scanf( %d , b + i), tmp ^= b[i]; n   if (tot != tmp) return puts( NO ); n   for (int x = 0; x < 31; x++) { n     for (int i = 0; i < n; i++) { n       if (a[i] >> x & 1) { n         bool f = false; n         for (int j = 0; j < m; j++) n           if (b[j] >> x & 1) { n             grid[i][j] ^= (1 << x); n             b[j] ^= (1 << x); n             a[i] ^= (1 << x); n             break; n           } n       } n     } n     int cnt = 0; n     for (int j = 0; j < m; j++) cnt += (b[j] >> x & 1); n     if (cnt & 1) return puts( NO ); n     for (int j = 0; j < m; j++) n       if (b[j] >> x & 1) grid[0][j] ^= (1 << x), b[j] ^= (1 << x); n   } n   for (int x = 0; x < 31; x++) { n     for (int j = 0; j < m; j++) { n       if (b[j] >> x & 1) { n         bool f = false; n         for (int i = 0; i < n; i++) n           if (a[i] >> x & 1) { n             grid[i][j] ^= (1 << x); n             b[j] ^= (1 << x); n             a[i] ^= (1 << x); n             break; n           } n       } n     } n     int cnt = 0; n     for (int i = 0; i < n; i++) cnt += (a[i] >> x & 1); n     if (cnt & 1) return puts( NO ); n     for (int i = 0; i < n; i++) n       if (a[i] >> x & 1) grid[i][0] ^= (1 << x), a[i] ^= (1 << x); n   } n   puts( YES ); n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) cout << grid[i][j] <<    ; n     cout <<   n ; n   } n   return 0; n } n