#include <bits/stdc++.h>   using namespace std;   using namespace std;   vector<long long>::iterator ptr;   long long count = 0;   long long cache[10004];   long long dp[100005] = {0};   long long cnt[200005] = {0};   long long a[200005] = {0};   long long b[200005] = {0};   long long r[200005] = {0};   long long pr(long long n) {     if (n % 2 == 0) {       return 2;     }     for (long long i = 3; i <= sqrt(n); i = i + 2) {       if (n % i == 0) return i;     }     if (n > 2) return n;   }   long long power(long long x, unsigned long long y) {     if (y == 0)       return 1;     else if (y % 2 == 0)       return power(x, y / 2) * power(x, y / 2);     else       return x * power(x, y / 2) * power(x, y / 2);   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long n = 0, p, q = 0, k, x = 0, y, m;     cin >> n >> m;     char s[1005][1005];     long long v[1005][5] = {0};     for (long long i = 0; i < m; ++i) {       for (long long j = 0; j < 5; ++j) {         v[i][j] = 0;       }     }     for (long long i = 0; i < n; ++i) {       for (long long j = 0; j < m; ++j) {         cin >> s[i][j];         if (s[i][j] ==  A )           v[j][0]++;         else if (s[i][j] ==  B )           v[j][1]++;         else if (s[i][j] ==  C )           v[j][2]++;         else if (s[i][j] ==  D )           v[j][3]++;         else if (s[i][j] ==  E )           v[j][4]++;       }     }     for (long long i = 0; i < m; ++i) {       cin >> a[i];     }     for (long long i = 0; i < m; ++i) {       p = 0;       for (long long j = 0; j < 5; ++j) {         p = max(p, v[i][j]);       }       x += (a[i] * p);     }     cout << x;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a[105], b[105], t, i, k;     cin >> t;     for (i = 1; i < t + 1; i++) {       scanf( %d , &a[i]);     }     for (i = 1; i < t + 1; i++) {       k = a[i];       b[k] = i;     }     for (i = 1; i < t + 1; i++) {       printf( %d  , b[i]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long int MAX = 100000;   vector<long long int> great[MAX + 1];   vector<long long int> small[MAX + 1];   vector<long long int> v[MAX + 1];   bool gactive[MAX + 1] = {false};   set<long long int> sactive;   long long int sz[MAX + 1] = {0};   struct moves {     long long int from, to, kind;   };   bool in(long long int x, vector<long long int>& p) {     if (lower_bound(p.begin(), p.end(), x) != p.end()) {       return (*lower_bound(p.begin(), p.end(), x) == x);     }     return false;   }   void solve() {     long long int n, m;     cin >> n >> m;     long long int tot = 0;     vector<pair<long long int, long long int>> szv(n + 1);     szv[0] = {0, 0};     for (long long int j = 1; j <= n; j++) {       long long int s;       cin >> s;       tot += s;       sz[j] = s;       szv[j] = {s, j};       for (long long int i = 0; i < s; i++) {         long long int c;         cin >> c;         v[j].push_back(c);       }     }     sort(szv.begin(), szv.end());     vector<long long int> gf(n + 1);     long long int sum = 0;     for (long long int j = 1; j <= n; j++) {       if ((tot / n) * (n - j + 1) == tot - sum) {         gf[j] = tot / n;       } else {         gf[j] = (tot + n - 1) / n;       }       sum += gf[j];     }     vector<long long int> should(n + 1);     for (long long int j = 1; j <= n; j++) {       should[szv[j].second] = gf[n - j + 1];     }     for (long long int j = 1; j <= n; j++) {       if (sz[j] > should[j]) {         gactive[j] = true;         for (auto i : v[j]) {           great[i].push_back(j);         }       } else if (sz[j] < should[j]) {         sactive.insert(j);         for (auto i : v[j]) {           small[i].push_back(j);         }       }     }     vector<moves> out;     for (long long int j = 1; j <= m; j++) {       if (((long long int)great[j].size()) == 0) continue;       long long int m1 = great[j].size(), m2 = small[j].size();       long long int ptr1 = 0, ptr2 = 0;       while (true) {         if (ptr1 == m1) break;         if (gactive[great[j][ptr1]]) break;         ptr1++;       }       if (ptr1 == m1) continue;       set<long long int> todel;       for (auto it : sactive) {         if (in(it, small[j]))           continue;         else {           sz[great[j][ptr1]]--;           sz[it]++;           {             struct moves q;             q.from = great[j][ptr1];             q.to = it;             q.kind = j;             out.push_back(q);           }           if (sz[great[j][ptr1]] <= should[great[j][ptr1]])             gactive[great[j][ptr1]] = false;           if (sz[it] >= should[it]) todel.insert(it);           ptr1++;           while (true) {             if (ptr1 == m1) break;             if (gactive[great[j][ptr1]]) break;             ptr1++;           }           if (ptr1 == m1) break;         }       }       for (auto it : todel) sactive.erase(it);     }     cout << (long long int)out.size() <<   n ;     for (auto q : out) {       cout << q.from <<     << q.to <<     << q.kind <<   n ;     }     return;   }   signed main() {     ios::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     long long int t;     t = 1;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int gcd(int a, int b) {     if (b == 0)       return a;     else       return gcd(b, a % b);   }   void dv(vector<int> v) {     for (int i = 0; i < v.size(); i++) cout << v[i] <<    ;   }   bool check_prime(int a) {     for (int i = sqrt(a); i > 1; i--) {       if (a % i == 0) return false;     }     return true;   }   int ctoil(char c) { return (int)c - 97; }   int ctoiu(char c) { return (int)c - 65; }   void dv_2d(vector<vector<int>> v) {     for (int i = 0; i < v.size(); i++) {       for (int j = 0; j < v[i].size(); j++) {         cout << v[i][j] <<    ;       }       cout <<   n ;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long n, m;     cin >> n >> m;     long long a, b;     if (n <= 2 * m) {       a = 0;     } else {       a = n - 2 * m;     }     if (m == 0) {       b = n;     } else {       b = n - ceil((sqrt(1 + 8 * m) + 1) / 2);     }     cout << a <<     << b << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, c = 0;     cin >> n;     int r = n;     int arr[n];     deque<int> d;     for (int i = 0; i < n; i++) {       scanf( %d , &arr[i]);       d.push_back(arr[i]);     }     sort(arr, arr + n);     for (int i = 0; i < n; i++) {       if (d[i] == arr[i]) {         c++;       }     }     int mid = (n + 1) / 2 - 1;     if (c == n) {       printf( %d n , 0);       ;       return 0;     } else {       c = 0;       while (r--) {         int t = 0;         d.push_front(d.back());         d.pop_back();         c++;         if (arr[0] == d.front() && arr[n - 1] == d.back() && arr[mid] == d[mid]) {           if (mid + 1 < n) {             if (d[mid + 1] >= d[mid] && d[mid - 1] <= d[mid]) {               printf( %d n , c);               ;               return 0;             }           } else {             printf( %d n , c);             ;             return 0;           }         }       }     }     printf( %d n , -1);     ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     long long x, y;     cin >> t;     for (int i = 1; i <= t; i++) {       cin >> x >> y;       if ((x - y) >= 2)         cout <<  YES  << endl;       else         cout <<  NO  << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   int size(const T &x) {     return x.size();   }   const int INF = ~(1 << 31);   const double EPS = 1e-9;   const double pi = acos(-1);   template <class T>   T smod(T a, T b) {     return (a % b + b) % b;   }   int f(char c) { return c -  a ; }   char g(int i) { return (char)(i +  a ); }   int main() {     int n;     cin >> n;     char c;     vector<bool> A(26, true);     int left = 26, cnt = 0;     for (decltype(0) i = (0); i < (n); ++i) {       cin >> c;       if (c ==  . ) {         vector<bool> B(26, true);         string s;         cin >> s;         for (decltype(0) j = (0); j < (size(s)); ++j) {           B[f(s[j])] = false;         }         for (decltype(0) j = (0); j < (26); ++j) {           A[j] = A[j] && B[j];         }       } else if (c ==  ! ) {         if (left == 1) cnt++;         vector<bool> B(26, false);         string s;         cin >> s;         for (decltype(0) j = (0); j < (size(s)); ++j) {           B[f(s[j])] = true;         }         for (decltype(0) j = (0); j < (26); ++j) {           A[j] = A[j] && B[j];         }       } else {         char s;         cin >> s;         if (left == 1 && i != n - 1) cnt++;         A[f(s)] = false;       }       left = 0;       for (decltype(0) j = (0); j < (26); ++j) {         left += A[j];       }     }     cout << cnt << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     int n, k;     cin >> n >> k;     vector<int> a(n), b(n);     for (int i = 0; i < n; ++i) cin >> a[i];     for (int i = 0; i < n; ++i) cin >> b[i];     long long ans = 0;     for (int i = 0; i < n; ++i)       if (b[i] == 1) {         ans += a[i];         a[i] = 0;       }     long long temp = 0, max = 0;     for (int i = 0; i < k; ++i) {       temp += a[i];     }     ans += temp;     max = temp;     for (int i = 1; i <= n - k; ++i) {       temp += (a[i + k - 1] - a[i - 1]);       if (max < temp) {         ans -= max;         max = temp;         ans += max;       }     }     cout << ans <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t = 1;     for (int i = 1; i <= t; ++i) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   using namespace std;   long long z = 1000000007;   long long gcd(long long a, long long b) {     if (a == 0) return b;     if (b == 0) return a;     return gcd(b, a % b);   }   long long power(long long a, long long b) {     long long res = 1;     while (b) {       if (b & 1) {         res = (res * a) % z;         b--;       } else {         a = (a * a) % z;         b = b >> 1;       }     }     return res;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long t;     t = 1;     while (t--) {       long long s, x;       cin >> s >> x;       long long k = s - x;       if (k & 1)         cout <<  0 n ;       else {         long long ans = 1, c = 0;         set<long long> s;         k /= 2;         for (long long i = 0; i < 64; i++)           if (k & ((long long)1 << i)) s.insert(i);         for (long long i = 0; i < 64; i++) {           if (x & ((long long)1 << i)) {             ans *= 2;             if (s.find(i) != s.end()) {               c++;               break;             }           }         }         if (c)           cout <<  0 n ;         else {           if (k == 0)             cout << ans - 2 <<   n ;           else             cout << ans <<   n ;         }       }     }   }


#include <bits/stdc++.h>   const int maxn = 150010;   const int INF = 0x3f3f3f3f;   using namespace std;   vector<int> V;   int a[maxn];   long long ans = 0;   int ok(int i) {     if (i & 1) return a[i] < a[i - 1] && a[i] < a[i + 1];     return a[i] > a[i + 1] && a[i] > a[i - 1];   }   int ok2(int i, int j) {     int f = 1;     swap(a[i], a[j]);     if (!ok(i)) f = 0;     if (!ok(j)) f = 0;     for (int k = 0; k < V.size(); k++) {       if (!ok(V[k])) f = 0;     }     swap(a[i], a[j]);     return f;   }   void fun(int idx, int n) {     for (int i = 1; i <= n; i++) {       if (ok2(idx, i)) {         ++ans;       }     }   }   int main() {     int n, i;     while (~scanf( %d , &n)) {       for (i = 1; i <= n; i++) {         scanf( %d , &a[i]);       }       a[0] = INF;       a[n + 1] = (n + 1) % 2 ? -INF : INF;       V.empty();       for (i = 1; i <= n; i++) {         if (!ok(i)) {           V.push_back(i);         }       }       if (V.size() > 6) {         printf( 0 n );         continue;       }       ans = 0;       for (i = 0; i < V.size(); i++) {         fun(V[i], n);         for (int j = i + 1; j < V.size(); j++) {           if (ok2(V[i], V[j])) {             --ans;           }         }       }       printf( %d n , ans);     }   }


#include <bits/stdc++.h>   using namespace std;   const long double PI = acosl(-1.0);   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int n, m;     cin >> n >> m;     int a[n][m], ans[n][m];     for (long long i = 0; i < n; i++)       for (long long j = 0; j < m; j++) cin >> a[i][j];     vector<map<int, int> > vc1, vc2;     map<int, int> mymap;     vector<int> v1, v11, v22;     for (int i = 0; i < n; i++) {       mymap.clear();       v1.clear();       for (int j = 0; j < m; j++) v1.push_back(a[i][j]);       sort(v1.begin(), v1.end());       int k = 1;       for (int j = 0; j < m; j++) {         if (mymap.find(v1[j]) == mymap.end()) mymap[v1[j]] = k++;       }       v11.push_back(k - 1);       vc1.push_back(mymap);     }     for (int i = 0; i < m; i++) {       mymap.clear();       v1.clear();       for (int j = 0; j < n; j++) v1.push_back(a[j][i]);       sort(v1.begin(), v1.end());       int k = 1;       for (int j = 0; j < n; j++) {         if (mymap.find(v1[j]) == mymap.end()) mymap[v1[j]] = k++;       }       v22.push_back(k - 1);       vc2.push_back(mymap);     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         int x = vc1[i][a[i][j]];         int y = vc2[j][a[i][j]];         if (x < y)           ans[i][j] = max(v11[i] + y - x, v22[j]);         else if (y < x)           ans[i][j] = max(v11[i], v22[j] + x - y);         else           ans[i][j] = max(v11[i], v22[j]);       }     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) cout << ans[i][j] <<    ;       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long u, v, p;   map<long long, int> M;   map<long long, int> pre, pre2;   queue<int> x, y;   bool in(int val, int rn) {     return ((M.find(val) != M.end()) & (((M[val] >> rn) & 1)));   }   long long modpow(long long x, long long n) {     long long res = 1;     while (n > 0) {       if (n & 1) res = res * x % p;       x = x * x % p;       n >>= 1;     }     return res;   }   int main() {     cin >> u >> v >> p;     x.push(u);     y.push(v);     for (int i = 0;; i++) {       int sz = x.size();       bool en = false;       int goal = -1;       while (sz--) {         int q = x.front();         x.pop();         if (in(q, 0)) continue;         M[q] |= 1;         if (M[q] == 3) {           en = true;           goal = q;           break;         }         if (!in((q + p - 1) % p, 0)) {           x.push((q + p - 1) % p);           pre[(q + p - 1) % p] = q;         }         if (!in((q + 1) % p, 0)) {           x.push((q + 1) % p);           pre[(q + 1) % p] = q;         }         long long rev = modpow(q, p - 2);         if (!in(rev, 0)) {           x.push(rev);           pre[rev] = q;         }       }       sz = y.size();       while (sz--) {         int q = y.front();         y.pop();         if (in(q, 1)) continue;         M[q] |= 2;         if (M[q] == 3) {           en = true;           goal = q;           break;         }         if (!in((q + p - 1) % p, 1)) {           y.push((q + p - 1) % p);           pre2[(q + p - 1) % p] = q;         }         if (!in((q + 1) % p, 1)) {           y.push((q + 1) % p);           pre2[(q + 1) % p] = q;         }         long long rev = modpow(q, p - 2);         if (!in(rev, 1)) {           y.push(rev);           pre2[rev] = q;         }       }       if (en) {         vector<int> num;         int cur = goal;         num.push_back(cur);         while (cur != u) {           cur = pre[cur];           num.push_back(cur);         }         reverse(num.begin(), num.end());         cur = goal;         while (cur != v) {           cur = pre2[cur];           num.push_back(cur);         }         cout << num.size() - 1 << endl;         for (int i = 1; i < num.size(); i++) {           long long a = num[i - 1];           long long b = num[i];           if ((a + 1) % p == b) {             printf( 1  );           } else if ((a + p - 1) % p == b) {             printf( 2  );           } else             printf( 3  );         }         puts(  );         return 0;       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 998244353;   int main() {     string a, v[6];     cin >> a;     for (int i = 1; i <= 5; ++i) {       cin >> v[i];       if (v[i][0] == a[0] || v[i][1] == a[1]) {         cout <<  YES n ;         return 0;       }     }     cout <<  NO n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }   int main() {     int n, m, k;     cin >> n >> m >> k;     vector<pair<int, int> > v;     for (int i = 0; i < n; i++) {       int x;       cin >> x;       v.push_back(make_pair(x, i));     }     sort(v.begin(), v.end(), greater<pair<int, int> >());     long long ans = 0;     vector<int> pos;     for (int i = 0; i < (m * k); i++) {       ans += v[i].first;       pos.push_back(v[i].second);     }     sort(pos.begin(), pos.end());     vector<int> div;     for (int i = 0; i < k - 1; i++) {       div.push_back(pos[(i + 1) * m - 1]);     }     cout << ans << endl;     for (int i = 0; i < div.size(); i++) {       cout << div[i] + 1 <<    ;     }     cout << endl;   }


#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1);   const double EPS = 1e-9;   long long dis(pair<long long, long long> a, pair<long long, long long> b) {     return (a.first - b.first) * (a.first - b.first) +            (a.second - b.second) * (a.second - b.second);   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long T, v;     pair<long long, long long> C;     cin >> C.first >> C.second >> v >> T;     long long R = 1.00 * v * T;     long long n;     cin >> n;     vector<pair<double, long long> > cut;     pair<long long, long long> center;     long long radi;     for (long long i = 0; i < n; i++) {       cin >> center.first >> center.second >> radi;       double distance = dis(C, center);       if (distance < 1.0 * radi * radi + EPS) {         cout <<  1.00000 ;         return 0;       }       distance = sqrt(distance);       if (1.00 * radi + R * 1.00 < distance - EPS) continue;       double left, right, ang;       double angM = atan2(center.second - C.second, center.first - C.first);       if (angM < 0) {         angM += 2 * PI;       }       double tLen = sqrt(distance * distance - 1.0 * radi * radi);       if (tLen < R + EPS) {         ang = asin(radi / distance);       } else {         ang = acos((distance * distance + 1.00 * R * R - 1.0 * radi * radi) /                    (2 * distance * 1.00 * R));       }       left = angM - ang;       right = angM + ang;       if (left < 0) {         cut.push_back({left + 2 * PI, 1});         cut.push_back({2 * PI, -1});         cut.push_back({0.00, 1});         cut.push_back({right, -1});       } else if (right > 2 * PI) {         cut.push_back({left, 1});         cut.push_back({2 * PI, -1});         cut.push_back({0.00, 1});         cut.push_back({right - 2 * PI, -1});       } else         cut.push_back({left, 1}), cut.push_back({right, -1});     }     double ans = 0.00;     long long count = 0;     double last = 0;     sort(cut.begin(), cut.end());     for (auto &x : cut) {       if (count > 0) ans += (x.first - last);       last = x.first;       count += (x.second);     }     cout << fixed << setprecision(6) << (ans / (2 * PI));   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n, a, moves = 0;     cin >> n;     while (n--) {       cin >> a;       moves += a - 1;       moves %= 2;       cout << 2 - moves <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int dx[] = {-1, 0, 1, 0};   const int dy[] = {0, -1, 0, 1};   inline int read() {     int ans = 0;     bool f = 1;     char ch = getchar();     while (!isdigit(ch)) f ^= ch ==  - , ch = getchar();     while (isdigit(ch)) ans = ((ans << 2) + ans << 1) + (ch ^ 48), ch = getchar();     return f ? ans : -ans;   }   int n, m;   long long b[100010], g[100010];   long long ans;   int main(int argc, char const *argv[]) {     ios::sync_with_stdio(false);     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) scanf( %I64d , &b[i]);     for (int i = 1; i <= m; i++) scanf( %I64d , &g[i]);     sort(b + 1, b + n + 1);     sort(g + 1, g + m + 1);     if (b[n] > g[1])       cout << -1;     else if (b[n] == g[1]) {       for (int i = 1; i < n; i++) ans += b[i] * m;       for (int i = 1; i <= m; i++) ans += g[i];       cout << ans;     } else {       ans += b[n] + g[1] + b[n - 1] * (m - 1);       for (int i = n - 2; i >= 1; i--) ans += b[i] * m;       for (int i = 2; i <= m; i++) ans += g[i];       cout << ans;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const ll llinf = (1ll << 61) - 1;   const int inf = 1000000007;   int TC = 1, CN, n, r, c[1 << 18 | 5];   signed main() {     cin.tie(0)->sync_with_stdio(0);     cin.exceptions(cin.failbit);     cout.precision(11), cout.setf(ios::fixed);     auto kase = [&]() -> void {       cin >> n >> r;       double sum = 0;       for (int i = 0; i < 1 << n; i++) {         cin >> c[i], sum += c[i];       }       for (int i = 0; i < r; i++) {         cout << sum / (1 << n) <<   n ;         int z, g;         cin >> z >> g;         sum -= c[z], c[z] = g, sum += c[z];       }       cout << sum / (1 << n) <<   n ;     };     while (CN++ != TC) kase();   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 5;   const long long INF = 0x3f3f3f3f;   const double eps = 1e-9;   struct P {     long double x, y;     P() : x(0), y(0) {}     P(long double _x, long double _y) : x(_x), y(_y) {}     P operator+(P& p) { return P(x + p.x, y + p.y); }     P operator-(P& p) { return P(x - p.x, y - p.y); }     P operator*(long double d) { return P(x * d, y * d); }     P operator/(long double d) { return P(x / d, y / d); }     long double abs() { return sqrtl(x * x + y * y); }     long double dot(P p) { return x * p.x + y * p.y; }     long double det(P p) { return x * p.y - y * p.x; }   };   P p[maxn];   long double tg[maxn], d[maxn];   int main() {     ios::sync_with_stdio(false);     cout.setf(ios::fixed);     int n, q;     cin >> n >> q;     for (int i = 1; i <= n; i++) {       cin >> p[i].x >> p[i].y;     }     P g;     long double fzx = 0, fzy = 0, fm = 0;     for (int i = 2; i <= n - 1; i++) {       fzx += (p[1].x + p[i].x + p[i + 1].x) *              ((p[i].x - p[1].x) * (p[i + 1].y - p[1].y) -               (p[i + 1].x - p[1].x) * (p[i].y - p[1].y));       fzy += (p[1].y + p[i].y + p[i + 1].y) *              ((p[i].x - p[1].x) * (p[i + 1].y - p[1].y) -               (p[i + 1].x - p[1].x) * (p[i].y - p[1].y));     }     for (int i = 2; i <= n - 1; i++) {       fm += 3.0 * ((p[i].x - p[1].x) * (p[i + 1].y - p[1].y) -                    (p[i + 1].x - p[1].x) * (p[i].y - p[1].y));     }     g.x = fzx / fm;     g.y = fzy / fm;     for (int i = 1; i <= n; i++) {       P l(p[i] - g);       tg[i] = atan2l(l.y, l.x);       if (tg[i] < 0) tg[i] += 2 * acosl(-1);       d[i] = l.abs();     }     int s1 = 1, s2 = 2;     int flag = 0;     for (int i = 1; i <= q; i++) {       int op;       cin >> op;       if (op == 1) {         int f, t;         cin >> f >> t;         if (f == s1) swap(s1, s2);         s2 = t;         flag = 1;         g.x = p[s1].x;         g.y = p[s1].y - d[s1];         long double _tg = tg[s1] - tg[s2];         p[s2].x = g.x + d[s2] * sinl(_tg);         p[s2].y = g.y + d[s2] * cosl(_tg);       } else {         int v;         cin >> v;         if (!flag) {           cout << fixed << setprecision(6) << p[v].x <<     << p[v].y << endl;         } else {           long double _tg = tg[s1] - tg[v];           P ans;           ans.x = g.x + d[v] * sinl(_tg);           ans.y = g.y + d[v] * cosl(_tg);           cout << fixed << setprecision(6) << ans.x <<     << ans.y << endl;         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   bool debug = 0;   int n, m, k;   int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};   string direc =  RDLU ;   long long ln, lk, lm;   void etp(bool f = 0) {     puts(f ?  YES  :  NO );     exit(0);   }   void addmod(int &x, int y, int mod = 1000000007) {     assert(y >= 0);     x += y;     if (x >= mod) x -= mod;     assert(x >= 0 && x < mod);   }   void et() {     puts( -1 );     exit(0);   }   long long fastPow(long long x, long long y, int mod = 1000000007) {     long long ans = 1;     while (y > 0) {       if (y & 1) ans = (x * ans) % mod;       x = x * x % mod;       y >>= 1;     }     return ans;   }   long long gcd1(long long x, long long y) {     long long z = y;     while (x % y != 0) {       z = x % y;       x = y;       y = z;     }     return z;   }   int a[33];   int dp[(1 << 22) + 5], mn[(1 << 22) + 5], bs;   void fmain(int ID) {     scanf( %d%d , &n, &m);     for (int(i) = 1; (i) <= (int)(m); (i)++) {       int u, v;       scanf( %d%d , &u, &v);       u--;       v--;       a[u] |= 1 << v;       a[v] |= 1 << u;     }     bs = (1 << n) - 1;     for (int(i) = 0; (i) < (int)(n); (i)++) dp[1 << i] = 1;     for (int(i) = 0; (i) < (int)(n); (i)++) a[i] |= 1 << i;     int cc = 0;     for (int(i) = 0; (i) < (int)(n); (i)++)       if (a[i] == (1 << n) - 1) {         cc++;       }     if (cc == n) {       puts( 0 );       return;     }     for (int s = 0; s < (1 << n); s++)       if (dp[s]) {         int tmp = 0;         for (int(j) = 0; (j) < (int)(n); (j)++)           if (s & (1 << j)) {             tmp |= a[j];           }         for (int(j) = 0; (j) < (int)(n); (j)++)           if (tmp & (1 << j)) {             dp[s | (1 << j)] = 1;           }         if (tmp == (1 << n) - 1) {           if (__builtin_popcount(s) < __builtin_popcount(bs)) {             bs = s;           }         }       }     printf( %d n , __builtin_popcount(bs));     for (int(j) = 0; (j) < (int)(n); (j)++)       if (bs & (1 << j)) printf( %d  , j + 1);   }   int main() {     int t = 1;     for (int(i) = 1; (i) <= (int)(t); (i)++) {       fmain(i);     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   int n;   struct vec {     long long x, y, idx;   } a, b;   long double pos_ang_with_x_axis(vec a) {     long double res = atan2(a.y, a.x) * 180 / acos(-1);     if (res < 0) res += 360;     return res;   }   int dot(vec a, vec b) { return a.x * b.x + a.y * b.y; }   long double norm(vec a) { return (long double)sqrt(a.x * a.x + a.y * a.y); }   long double angle(vec a, vec b) {     long double ang1 = pos_ang_with_x_axis(a);     long double ang2 = pos_ang_with_x_axis(b);     return fabs(ang1 - ang2);   }   vector<vec> v;   bool cmp(vec a, vec b) {     vec c;     c.x = c.y = 0;     long double ang1 = pos_ang_with_x_axis(a);     long double ang2 = pos_ang_with_x_axis(b);     return ang1 < ang2;   }   int main() {     ios::sync_with_stdio(0);     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a.x >> a.y;       a.idx = i + 1;       v.push_back(a);     }     sort(v.begin(), v.end(), cmp);     int idx1, idx2;     long double mn = 1e18;     v.push_back(v[0]);     for (int i = 1; i <= n; i++) {       long double d = angle(v[i], v[i - 1]);       d = min(d, (long double)360 - d);       if (d < mn) mn = d, idx1 = v[i - 1].idx, idx2 = v[i].idx;     }     cout << idx1 <<     << idx2 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long last = -1;   void dfs(long long s, vector<vector<pair<long long, long long>>> grf,            vector<long long> &vis, long long &cost) {     vis[s] = 1;     last = s;     for (auto x : grf[s]) {       long long v = x.first, d = x.second;       if (vis[v] == 0) {         cost += d;         dfs(v, grf, vis, cost);       }     }   }   signed main() {     long long n;     cin >> n;     vector<vector<pair<long long, long long>>> grf(n + 1);     long long sum = 0;     for (long long i = 0; i < n; i++) {       long long u, v, w;       cin >> u >> v >> w;       grf[u].push_back({v, w});       grf[v].push_back({u, 0});       sum += w;     }     long long cost = 0;     vector<long long> vis(n + 1, 0);     dfs(1, grf, vis, cost);     if (last != 1) {       for (auto x : grf[last]) {         if (x.first == 1) cost += x.second;       }     }     cout << min(cost, sum - cost);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     vector<int> primes = {2,  4,  3,  9,  5,  25, 7,  49, 11, 13,                           17, 19, 23, 29, 31, 37, 41, 43, 47};     int n = 0;     for (int i = 0; i < primes.size(); i++) {       cout << primes[i] << endl;       string s;       cin >> s;       if (s ==  yes ) n++;       if (n > 1) return cout <<  composite , 0;     }     cout <<  prime ;   }


#include <bits/stdc++.h>   using namespace std;   long long int n, k, nb, a[1005], b[2005], t = -10000, pos = 0, p, d;   long long int save[1005][2005];   long long int time(int i, int j) {     if (save[i][j] != -1) return save[i][j];     if (i == n) return 0;     if (j == k) return 3e9;     return (save[i][j] = min(time(i, j + 1), max(abs(a[i] - b[j]) + abs(p - b[j]),                                                  time(i + 1, j + 1))));   }   int main() {     long long int i, j;     cin >> n >> k >> p;     vector<long long int> v;     v.clear();     for (i = 0; i < n; i++) cin >> a[i];     sort(a, a + n);     for (i = 0; i < k; i++) cin >> b[i];     sort(b, b + k);     memset(save, -1, sizeof save);     t = time(0, 0);     cout << t;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 5;   int n, m, t;   vector<int> e[maxn];   int ecnt[maxn];   queue<int> q;   bool vis[maxn];   int dep[maxn];   int ec[maxn];   bool flag;   int f[maxn];   int g[maxn];   int cnt[maxn];   int read() {     int x;     scanf( %d , &x);     return x;   }   int dfs(int x, int fa) {     int y;     if (!ec[dep[x]]) {       ec[dep[x]] = e[x].size();     } else {       if (ec[dep[x]] != e[x].size()) {         flag = false;         return 0;       }     }     for (auto y : e[x]) {       if (y == fa) continue;       dep[y] = dep[x] + 1;       dfs(y, x);       if (!flag) {         return 0;       }     }     return 0;   }   bool check(int x) {     memset(ec, 0, sizeof(ec));     memset(dep, 0, sizeof(dep));     flag = true;     dep[x] = 1;     dfs(x, -1);     return flag;   }   int solve() {     int i, j;     int x, y;     vector<int> ans;     memset(vis, 0, sizeof(vis));     for (i = 1; i <= n; i++) {       ecnt[i] = e[i].size();       if (e[i].size() == 1) {         vis[i] = true;         q.push(i);         f[i] = 1;         g[i] = i;         cnt[i] = 1;       }     }     while (!q.empty()) {       x = q.front();       q.pop();       for (auto y : e[x]) {         if (vis[y]) continue;         ecnt[y]--;         if (ecnt[y] == 1) {           q.push(y);           vis[y] = true;         }       }       for (auto y : e[x]) {         if (!vis[y]) continue;         if (!f[y]) continue;         if (f[x]) {           if (f[y] + 1 != f[x]) {             if (cnt[x] < cnt[y]) {               ans.push_back(g[x]);             } else if (cnt[x] > cnt[y]) {               ans.push_back(g[y]);             } else {               ans.push_back(g[x]);               ans.push_back(g[y]);             }             break;           } else {             cnt[x] += cnt[y];           }         } else {           f[x] = f[y] + 1;           g[x] = g[y];           cnt[x] += cnt[y];         }       }       if (q.empty() and ans.size() == 0) {         for (auto y : e[x]) {           if (!vis[y]) continue;           if (!f[y]) continue;           if (cnt[y] == 1) {             ans.push_back(g[y]);           }         }       }       if (ans.size()) break;     }     for (auto x : ans) {       if (check(x)) {         printf( %d n , x);         return 0;       }     }     printf( -1 n );     return 0;   }   int main() {     int i, j;     int x = 1, y;     n = read();     for (i = 1; i < n; i++) {       x = read();       y = read();       e[x].push_back(y);       e[y].push_back(x);       ecnt[x]++;       ecnt[y]++;     }     for (i = 1; i <= n; i++) {       if (e[i].size() == 1) {         vis[i] = true;         q.push(i);       }     }     while (!q.empty()) {       x = q.front();       q.pop();       for (auto y : e[x]) {         if (vis[y]) continue;         ecnt[y]--;         if (ecnt[y] == 1) {           q.push(y);           vis[y] = true;         }       }     }     if (check(x)) {       printf( %d n , x);     } else {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MAXN = 200001;   const long long K = 5;   const long long INF = 1e16 + 7;   long long n, k, q;   long long a[MAXN][K];   long long tree[MAXN << 2][1 << K];   void upd(long long v, long long tl, long long tr, long long p) {     if (tl == tr) {       for (long long i = 0; i < k; ++i) {         cin >> a[tl][i];       }       for (long long mask = 0; mask < (1 << k); ++mask) {         long long cost = 0;         for (long long i = 0; i < k; ++i) {           if ((mask >> i) & 1) {             cost += a[tl][i];           } else {             cost -= a[tl][i];           }         }         tree[v][mask] = cost;       }       return;     }     long long tm = (tl + tr) >> 1;     if (p <= tm) {       upd(v * 2 + 1, tl, tm, p);     } else {       upd(v * 2 + 2, tm + 1, tr, p);     }     for (long long mask = 0; mask < (1 << k); ++mask) {       tree[v][mask] = max(tree[v * 2 + 1][mask], tree[v * 2 + 2][mask]);     }   }   long long getmax(long long v, long long tl, long long tr, long long l,                    long long r, long long mask) {     if (tr < l || r < tl) {       return -INF;     }     if (l <= tl && tr <= r) {       return tree[v][mask];     }     long long tm = (tl + tr) >> 1;     return max(getmax(v * 2 + 1, tl, tm, l, r, mask),                getmax(v * 2 + 2, tm + 1, tr, l, r, mask));   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     for (long long i = 0; i < (MAXN << 2); ++i) {       for (long long mask = 0; mask < (1 << K); ++mask) {         tree[i][mask] = -INF;       }     }     cin >> n >> k;     for (long long i = 0; i < n; ++i) {       upd(0, 0, n - 1, i);     }     cin >> q;     for (long long i = 0; i < q; ++i) {       long long t;       cin >> t;       if (t == 1) {         long long p;         cin >> p;         --p;         upd(0, 0, n - 1, p);       } else {         long long l, r;         cin >> l >> r;         --l;         --r;         long long ans = -INF;         for (long long mask = 0; mask < (1 << (k - 1)); ++mask) {           ans = max(ans, getmax(0, 0, n - 1, l, r, mask) +                              getmax(0, 0, n - 1, l, r, mask ^ ((1 << k) - 1)));         }         cout << ans <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     int up, down;     int people = 0;     int max = 0;     cin >> n;     while (n--) {       cin >> up >> down;       people = people - up + down;       if (people > max) max = people;     }     cout << max << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool cmp(pair<long long, long long> a, pair<long long, long long> b) {     return (a.first - a.second) > (b.first - b.second);   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long n;     cin >> n;     vector<long long> hand(n);     vector<long long> pile(n);     unordered_map<long long, long long> hand_map(n);     unordered_map<long long, long long> pile_map(n);     for (long long i = 0; i < n; i++) {       cin >> hand[i];       hand_map[hand[i]]++;     }     for (long long i = 0; i < n; i++) {       cin >> pile[i];       pile_map[pile[i]]++;     }     long long flag = 0;     long long last = pile[n - 1];     long long index;     for (long long i = n - 1; i > 0; i--) {       if (pile[i] == 1) {         index = i;         break;       }       if (pile[i] - 1 == pile[i - 1] && pile[i] != 0) {       } else {         flag = 1;         break;       }     }     long long shift = 0;     if (flag == 1) {       for (long long i = 0; i < n; i++) {         if (pile[i] != 0) shift = max(shift, i + 2 - pile[i]);       }       cout << shift + n;     } else {       long long last = pile[n - 1];       for (long long i = 0; i < n; i++) {         if (pile[i] == 1) {           break;         }         if (pile[i] != 0) {           shift = max(shift, i + 2 - (pile[i] - pile[n - 1]));         }       }       if (shift == 0) {         cout << shift + n - pile[n - 1];       } else {         cout << index + 1 + n;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename Arg1>   void __f(const char* name, Arg1&& arg1) {     if (0) return;     cout << name <<   :   << arg1 <<   n ;   }   template <typename Arg1, typename... Args>   void __f(const char* names, Arg1&& arg1, Args&&... args) {     if (0) return;     const char* comma = strchr(names + 1,  , );     cout.write(names, comma - names) <<   :   << arg1 <<   |  ;     __f(comma + 1, args...);   }   void get_it_done() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);   }   long long gcd(long long a, long long b) {     if (a == 0) return b;     return gcd(b % a, a);   }   const long long N = 1e5 + 5;   long long n, m, k, s;   vector<long long> adjList[N], goods[N], cost[N];   long long arr[N], dp[105][N];   bool visited[N];   int32_t main() {     get_it_done();     long long t = 1;     while (t--) {       cin >> n >> m >> k >> s;       for (long long i = 1; i < n + 1; ++i)         cin >> arr[i], goods[arr[i]].push_back(i);       for (long long i = 0; i < m; ++i) {         long long u, v;         cin >> u >> v;         adjList[u].push_back(v);         adjList[v].push_back(u);       }       if (s == 1) {         for (long long i = 0; i < n; ++i) {           cout << 0 <<    ;         }         cout <<   n ;         continue;       }       for (long long i = 1; i < k + 1; ++i) {         memset(visited, 0, sizeof(visited));         queue<long long> q;         for (auto x : goods[i]) {           visited[x] = 1;           q.push(x);         }         while (!q.empty()) {           long long node = q.front();           q.pop();           for (auto x : adjList[node]) {             if (!visited[x]) {               dp[i][x] = dp[i][node] + 1;               visited[x] = 1;               q.push(x);             }           }         }         for (long long j = 1; j < n + 1; ++j) {           cost[j].push_back(dp[i][j]);         }       }       for (long long i = 1; i < n + 1; ++i) {         sort(cost[i].begin(), cost[i].end());         long long ans = 0;         for (long long j = 0; j < s; ++j) {           ans += cost[i][j];         }         cout << ans <<    ;       }       cout <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int n, x, dd[270000];   int main() {     cin >> n >> x;     int limit = (1 << n) - 1;     vector<int> Q;     Q.push_back(0);     for (int i = 1; i <= limit; i++) {       if (i == x) continue;       if (dd[i]) continue;       Q.push_back(i);       dd[(i ^ x)] = 1;     }     cout << Q.size() - 1 << endl;     for (int i = 1; i < Q.size(); i++) {       cout << (Q[i] ^ Q[i - 1]) <<    ;     }   }


#include <bits/stdc++.h>   int main() {     int n;     scanf( %d , &n);     int r = n + n - 1;     int a = 0;     int b = 0;     int i;     for (i = 0; i < n; i++) {       scanf( %d , &a);       if (a >= b) {         r = r + (a - b);       } else {         r = r + (b - a);       }       b = a;     }     printf( %d , r);   }


#include <bits/stdc++.h>   using namespace std;   int n, m, p, len;   int pos[500020];   int Left[500020];   int Right[500020];   string str;   void Work() {     int t = p;     char op;     int rt;     for (int i = 0; i < m; i++) {       cin >> op;       if (op ==  L )         p = Left[p];       else if (op ==  R )         p = Right[p];       else {         rt = pos[p];         if (rt > p) swap(rt, p);         Right[Left[rt]] = Right[p];         Left[Right[p]] = Left[rt];         if (Right[p] > len)           p = Left[rt];         else           p = Right[p];       }     }     for (int i = 0; i <= len;) {       if (i) cout << str[i - 1];       i = Right[i];     }     cout << endl;   }   int main() {     std::ios::sync_with_stdio(false);     std::cin.tie(0);     while (cin >> n >> m >> p) {       stack<int> s;       cin >> str;       len = str.size();       Right[0] = 1;       Left[1] = 0;       Right[len] = len + 1;       Left[len + 1] = len;       for (int i = 1; i <= len; i++) {         Right[i] = i + 1;         Left[i] = i - 1;         if (str[i - 1] ==  ( )           s.push(i);         else {           pos[i] = s.top();           pos[s.top()] = i;           s.pop();         }       }       Work();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   unsigned long long F(unsigned long long n) {     if (n < 10) return n;     unsigned long long nn = n;     int firstDig = 0;     while (n) {       firstDig = n % 10;       n /= 10;     }     return (nn / 10) + 9 - (firstDig > (nn % 10));   }   int main() {     unsigned long long x, y;     while (cin >> x >> y) cout << F(y) - F(x - 1) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void strange(int t) {     while (t--) {       int n;       cin >> n;       vector<int> p(n);       for (int i = 0; i < n; i++) {         cin >> p[i];         p[i]--;       }       bool g = 1;       int MIN = n;       for (int i = 0; i < n; i++) {         if (p[i] < MIN)           MIN = p[i];         else if (p[i] == p[i - 1] + 1) {         } else {           g = false;           break;         }       }       cout << (g ?  Yes  :  No ) << endl;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     int t;     cin >> t;     strange(t);   }


#include <bits/stdc++.h>   using namespace std;   int arr[1003];   int main() {     int n, x, ans, sum, t, ck;     cin >> t;     while (t--) {       cin >> n >> x;       for (int i = 1; i <= n; i++) cin >> arr[i];       sort(arr + 1, arr + n + 1);       ck = 0;       for (int i = 1; i <= n; i++) {         if (arr[i] == x) ck = 1;       }       sum = 0;       for (int i = 1; i <= n; i++) sum += (arr[i] - x);       if (arr[1] == arr[n] && arr[n] == x)         ans = 0;       else if (sum == 0 || ck)         ans = 1;       else         ans = 2;       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   template <class T>   int ge(const vector<T>& v, T val) {     return distance(v.begin(), lower_bound(v.begin(), v.end(), val));   }   template <class T>   int gt(const vector<T>& v, T val) {     return distance(v.begin(), upper_bound(v.begin(), v.end(), val));   }   template <class T>   int le(const vector<T>& v, T val) {     auto itr = upper_bound(v.begin(), v.end(), val);     if (itr == v.begin()) return v.size();     return distance(v.begin(), --itr);   }   template <class T>   int lt(const vector<T>& v, T val) {     auto itr = lower_bound(v.begin(), v.end(), val);     if (itr == v.begin()) return v.size();     return distance(v.begin(), --itr);   }   template <class T>   struct BIT {     int size;     vector<T> data;     function<T(T, T)> f = [](T a, T b) { return a + b; };     BIT() {}     BIT(int n) { init(n); }     void init(int n) {       size = n;       data.assign(size + 1, 0);     }     T sum(int x) {       T res = 0;       while (x > 0) {         res = f(res, data[x]);         x -= (x & -x);       }       return res;     }     T sum(int lft, int rit) {       if (lft == 0) return sum(rit);       return sum(rit) - sum(lft - 1);     }     void add(int x, T y) {       while (x <= size) {         data[x] = f(data[x], y);         x += (x & -x);       }     }   };   int main(void) {     int n;     ll t;     cin >> n >> t;     vector<ll> a(n + 1, 0), sum(n + 1, 0), v;     for (int i = 1; i <= n; i++) {       cin >> a[i];       sum[i] = sum[i - 1] + a[i];     }     v.assign(sum.begin(), sum.end());     sort(v.begin(), v.end());     v.erase(unique(v.begin(), v.end()), v.end());     int vs = v.size();     BIT<int> bit(vs + 1);     ll ans = 0;     for (int l = n; l >= 0; l--) {       int i = lt(v, sum[l] + t);       if (i < vs) {         ans += bit.sum(i + 1);       }       i = ge(v, sum[l]);       bit.add(i + 1, 1);     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int NMAX = 2 * 1e5 + 2;   int t, n, valeurs[NMAX];   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> t;     for (int test = 1; test <= t; test++) {       cin >> n;       if (n % 4 != 0) {         cout <<  NO n ;       } else {         int moitie = n / 2, somme = 0, cur = 0;         for (int i = 0; i < moitie; i++) {           valeurs[i] = 2 * (i + 1);           somme += valeurs[i];         }         for (int i = 0; i < moitie - 1; i++) {           valeurs[i + moitie] = 2 * i + 1;           cur += valeurs[i + moitie];         }         valeurs[n - 1] = somme - cur;         cout <<  YES n ;         for (int i = 0; i < n; i++) cout << valeurs[i] <<    ;         cout <<   n ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   long long n, k, m;   vector<pair<int, int> > v, u;   int a, b, c;   int main() {     cin >> n >> k >> m;     a = n;     for (int i = 0; i < n; i++) {       int w;       cin >> w;       if (v.size() > 0 && v.back().first == w) {         v.back().second++;         if (v.back().second == k) {           v.pop_back();           a -= k;         }       } else         v.push_back({w, 1});     }     u = v;     int b = a;     int x = 0, y = u.size() - 1;     while (x < y) {       if (u[x].first == u[y].first) {         if (u[x].second + u[y].second == k) {           x++;           y--;           b -= k;         } else {           if (u[x].second + u[y].second > k) b -= k;           break;         }       } else {         break;       }     }     long long r = m * b;     a -= b;     if (x == y) {       r = r % k;       if (r == 0) a = 0;     }     cout << a + r << endl;     return 0;   }


#include<iostream>   using namespace std;      int query(int a, int b) {    cout <<  ?   << a <<     << b << endl;    cout.flush();    int ret;    cin >> ret;    return ret;   }      int main() {    int n;    cin >> n;    int lt = 1, rt = n;    int sec = query(1, n);    while (rt - lt > 0) {     int mid;     if (rt + lt <= 2 * sec) {      mid = (rt + lt + 1) / 2;      if (mid == n) {       rt = n - 1;       break;      }      if (query(mid, n) == sec) lt = mid;      else rt = mid - 1;     }     if (rt+lt > 2*sec) {      mid = (rt + lt) / 2;      if (mid == 1) {       lt = 2;       break;      }      if (query(1, mid) == sec) rt = mid;      else lt = mid + 1;     }    }    cout <<  !   << lt << endl;    cout.flush();   }


#include <bits/stdc++.h>   using namespace std;   long long int fast_expo(long long int x, long long int p) {     if (p == 0)       return 1;     else if (p % 2 == 0) {       long long int t = fast_expo(x, p / 2) % 1000000007;       return (t * t) % 1000000007;     } else       return (x * (fast_expo(x, p - 1)) % 1000000007) % 1000000007;   }   long long int aft_bunk[501][501];   long long int dp[501][501];   vector<long long int> vect[501];   long long int solve(long long int day, long long int bunk) {     if (day == -1 && bunk >= 0) return 0;     if (day < 0 || bunk < 0) return INT_MAX;     if (dp[day][bunk] != -1) return dp[day][bunk];     long long int ans = INT_MAX;     for (long long int i = 0; i <= vect[day].size(); ++i) {       long long int temp = solve(day - 1, bunk - i) + aft_bunk[day][i];       if (ans > temp) ans = temp;     }     return dp[day][bunk] = ans;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     long long int n, m, k;     cin >> n >> m >> k;     char tempo;     for (long long int i = 0; i < n; ++i) {       for (long long int j = 1; j <= m; ++j) {         cin >> tempo;         if (tempo ==  1 ) {           vect[i].push_back(j);         }       }     }     for (long long int i = 0; i < n; ++i) {       for (long long int j = 0; j < 501; ++j) {         aft_bunk[i][j] = INT_MAX;       }     }     long long int temp;     for (long long int i = 0; i < n; ++i) {       for (long long int j = 0; j < vect[i].size(); ++j) {         long long int ptr1 = 0, ptr2 = vect[i].size() - 1 - j;         for (long long int ptr1 = 0; ptr1 <= j; ptr1++, ptr2++) {           temp = vect[i][ptr2] - vect[i][ptr1] + 1;           if (temp < aft_bunk[i][j]) aft_bunk[i][j] = temp;         }       }       aft_bunk[i][vect[i].size()] = 0;     }     for (long long int i = 0; i < 501; ++i) {       for (long long int j = 0; j < 501; ++j) dp[i][j] = -1;     }     cout << solve(n - 1, k);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   #pragma comment(linker,  /STACK:102400000,102400000 )   const int maxn = 5e5 + 5;   struct Point {     char ty;     int x, y;     Point(char ch =  0 , int x = 0, int y = 0) : ty(ch), x(x), y(y) {}   } chess[maxn];   int X0, Y0, n;   bool solve1() {     vector<pair<int, char> > v;     for (int i = 1; i <= n; i++) {       if (chess[i].x == X0) v.push_back(make_pair(chess[i].y, chess[i].ty));     }     if (v.size() == 0) return false;     sort(v.begin(), v.end());     for (int i = 0; i < v.size() - 1; i++) {       if (v[i].first < Y0 && v[i + 1].first > Y0) {         if (v[i].second ==  R  || v[i].second ==  Q  || v[i + 1].second ==  R  ||             v[i + 1].second ==  Q )           return true;         return false;       }     }     int len = v.size();     if (v[len - 1].first < Y0 &&         (v[len - 1].second ==  R  || v[len - 1].second ==  Q ))       return true;     if (v[0].first > Y0 && (v[0].second ==  R  || v[0].second ==  Q ))       return true;     return false;   }   bool solve2() {     vector<pair<int, char> > v;     for (int i = 1; i <= n; i++) {       if (chess[i].y == Y0) v.push_back(make_pair(chess[i].x, chess[i].ty));     }     if (v.size() == 0) return false;     sort(v.begin(), v.end());     for (int i = 0; i < v.size() - 1; i++) {       if (v[i].first < X0 && v[i + 1].first > X0) {         if (v[i].second ==  R  || v[i].second ==  Q  || v[i + 1].second ==  R  ||             v[i + 1].second ==  Q )           return true;         return false;       }     }     int len = v.size();     if (v[len - 1].first < X0 &&         (v[len - 1].second ==  R  || v[len - 1].second ==  Q ))       return true;     if (v[0].first > X0 && (v[0].second ==  R  || v[0].second ==  Q ))       return true;     return false;   }   bool solve3() {     vector<pair<int, char> > v;     for (int i = 1; i <= n; i++) {       if (chess[i].x == chess[i].y)         v.push_back(make_pair(chess[i].x, chess[i].ty));     }     if (v.size() == 0) return false;     sort(v.begin(), v.end());     for (int i = 0; i < v.size() - 1; i++) {       if (v[i].first < X0 && v[i + 1].first > X0) {         if (v[i].second ==  B  || v[i].second ==  Q  || v[i + 1].second ==  B  ||             v[i + 1].second ==  Q )           return true;         return false;       }     }     int len = v.size();     if (v[len - 1].first < X0 &&         (v[len - 1].second ==  B  || v[len - 1].second ==  Q ))       return true;     if (v[0].first > X0 && (v[0].second ==  B  || v[0].second ==  Q ))       return true;     return false;   }   bool solve4() {     vector<pair<int, char> > v;     for (int i = 1; i <= n; i++) {       if (chess[i].x == -chess[i].y)         v.push_back(make_pair(chess[i].x, chess[i].ty));     }     if (v.size() == 0) return false;     sort(v.begin(), v.end());     for (int i = 0; i < v.size() - 1; i++) {       if (v[i].first < X0 && v[i + 1].first > X0) {         if (v[i].second ==  B  || v[i].second ==  Q  || v[i + 1].second ==  B  ||             v[i + 1].second ==  Q )           return true;         return false;       }     }     int len = v.size();     if (v[len - 1].first < X0 &&         (v[len - 1].second ==  B  || v[len - 1].second ==  Q ))       return true;     if (v[0].first > X0 && (v[0].second ==  B  || v[0].second ==  Q ))       return true;     return false;   }   int main() {     cin >> n >> X0 >> Y0;     for (int i = 1; i <= n; i++) {       char ch;       int a, b;       scanf( %s%d%d , &ch, &a, &b);       chess[i] = Point(ch, a - X0, b - Y0);     }     X0 = Y0 = 0;     if (solve1() || solve2() || solve3() || solve4())       printf( YES n );     else       puts( NO );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ld = long double;   using ii = pair<ll, ll>;   using vi = vector<ll>;   using vb = vector<bool>;   using vvi = vector<vi>;   using vii = vector<ii>;   using vvii = vector<vii>;   const int INF = 2000000000;   const ll LLINF = 9000000000000000000;   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     int N;     ll M, T;     cin >> N >> M >> T;     vi S(N, 0LL);     vi D(N, 0LL);     vii Si(N, {0LL, 0LL});     bool lf = false, rf = false;     int dsum = 0;     for (int i = 0; i < N; ++i) {       char c;       cin >> S[i] >> c;       D[i] = (c ==  L  ? -1 : 1);       if (D[i] == -1)         lf = true;       else         rf = true;       dsum += D[i];       Si[i] = {S[i], i};     }     vi pos(N, 0LL);     for (int i = 0; i < N; ++i) {       pos[i] = (S[i] + D[i] * (T % M)) + M;       pos[i] %= M;       if (pos[i] == 0) pos[i] = M;     }     if (!lf || !rf) {       for (int i = 0; i < N; ++i) cout << pos[i] <<    n [i + 1 == N];       return 0;     }     vii crossdir;     for (int i = 0; i < N; ++i) {       ll k = -D[i] * (D[i] == 1 ? (S[i] - 1) : S[i]);       while (k <= 0) k += M;       k %= M;       if (k == 0) k += M;       crossdir.push_back({k, D[i]});     }     sort(crossdir.begin(), crossdir.end());     ll shift = -(T / M) * dsum;     for (size_t j = 0; j < crossdir.size() && crossdir[j].first <= (T % M); ++j) {       shift -= crossdir[j].second;     }     shift = ((shift % N) + N) % N;     sort(pos.begin(), pos.end());     sort(Si.begin(), Si.end());     vi ans(N, 0);     for (int i = 0; i < N; ++i) {       ans[Si[i].second] = pos[(i + N - shift) % N];     }     for (int i = 0; i < N; ++i) cout << ans[i] <<    n [i + 1 == N];     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   long long power(long long a, long long b) {     long long ret = 1;     while (b) {       if (b & 1) ret *= a;       a *= a;       if (ret >= MOD) ret %= MOD;       if (a >= MOD) a %= MOD;       b >>= 1;     }     return ret;   }   long long invmod(long long x) { return power(x, MOD - 2); }   vector<long long> vp[100005];   int vis[100005] = {0};   int dfs(int n) {     if (vp[n].size() < 2) return 10001;     int a[4005] = {0};     vector<long long> vp1;     for (int i = 0; i < vp[n].size(); i++) {       vp1.push_back(vp[n][i]);       a[vp[n][i]] = 1;     }     int min = 10001;     for (int i = 0; i < vp1.size(); i++) {       for (int j = 0; j < vp[vp1[i]].size(); j++) {         if (a[vp[vp1[i]][j]] == 1) {           if (min >               vp[vp[vp1[i]][j]].size() + vp[n].size() + vp[vp1[i]].size() - 6) {             min = vp[vp[vp1[i]][j]].size() + vp[n].size() + vp[vp1[i]].size() - 6;             break;           }         }       }     }     return min;   }   int main() {     int n, m;     cin >> m >> n;     int x, y;     for (int i = 0; i < n; i++) {       cin >> x >> y;       vp[x].push_back(y);       vp[y].push_back(x);     }     int min1 = 10000;     for (int i = 1; i <= m; i++) {       min1 = min(dfs(i), min1);     }     if (min1 == 10000) {       cout <<  -1  << endl;       return 0;     }     cout << min1 << endl;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int a, b, c, d;     cin >> a >> b >> c >> d;     long double t =         (a * 1.0 / b) * (1.0 / (1 - (1 - a * 1.0 / b) * (1 - c * 1.0 / d)));     cout << t << fixed << setprecision(6);   }


#include <bits/stdc++.h>   using namespace std;   int const MAX_N = 600100;   int const INT_INF = 1000000000;   int my_rank[MAX_N], my_parent[MAX_N], diam_ancestor[MAX_N];   int d[MAX_N], och[MAX_N], nnew[MAX_N];   void make_set(int v) {     my_parent[v] = v;     diam_ancestor[v] = 0;     my_rank[v] = 0;   }   int find_set(int v) {     if (v != my_parent[v]) my_parent[v] = find_set(my_parent[v]);     return my_parent[v];   }   void my_Link(int x, int y, int flag) {     if (my_rank[x] > my_rank[y])       my_parent[y] = x;     else       my_parent[x] = y;     my_rank[y] += my_rank[x] == my_rank[y];     if (flag) {       int D1 = diam_ancestor[x];       int D2 = diam_ancestor[y];       int new_VVV = find_set(x);       int val = (D1 + 1) / 2 + (D2 + 1) / 2 + 1;       diam_ancestor[new_VVV] = max(D1, max(D2, val));     }   }   void my_Union(int x, int y, int flag) {     int V1 = find_set(x);     int V2 = find_set(y);     if (V1 == V2) return;     my_Link(V1, V2, flag);   }   vector<int> e[MAX_N];   int main() {     int n, m, q;     scanf( %d%d%d , &n, &m, &q);     for (int i = 0; i < n; i++) make_set(i);     for (int i = 0; i < m; i++) {       int a, b;       scanf( %d%d , &a, &b);       a--;       b--;       my_Union(a, b, 0);       e[a].push_back(b);       e[b].push_back(a);     }     for (int i = 0; i < n; i++) d[i] = INT_INF;     for (int i = 0; i < n; i++)       if (!nnew[i]) {         int p_read = 0, p_write = 1;         och[p_read] = i;         nnew[i] = 1;         d[i] = 0;         while (p_read < p_write) {           int v = och[p_read];           p_read++;           for (int j = 0; j < (int)e[v].size(); j++) {             int new_v = e[v][j];             if (d[new_v] > d[v] + 1) {               d[new_v] = d[v] + 1;               och[p_write] = new_v;               p_write++;               nnew[new_v] = 1;             }           }         }         int mx_dist = -1, ans_vertex = -1;         for (int j = 0; j < p_write; j++)           if (d[och[j]] > mx_dist) {             mx_dist = d[och[j]];             ans_vertex = och[j];           }         for (int j = 0; j < p_write; j++) d[och[j]] = INT_INF;         p_read = 0, p_write = 1;         och[p_read] = ans_vertex;         d[ans_vertex] = 0;         while (p_read < p_write) {           int v = och[p_read];           p_read++;           for (int j = 0; j < (int)e[v].size(); j++) {             int new_v = e[v][j];             if (d[new_v] > d[v] + 1) {               d[new_v] = d[v] + 1;               och[p_write] = new_v;               p_write++;             }           }         }         mx_dist = -1;         for (int j = 0; j < p_write; j++) mx_dist = max(mx_dist, d[och[j]]);         diam_ancestor[find_set(i)] = mx_dist;       }     for (int i = 0; i < q; i++) {       int tp;       scanf( %d , &tp);       if (tp == 2) {         int a, b;         scanf( %d%d , &a, &b);         a--;         b--;         my_Union(a, b, 1);       } else if (tp == 1) {         int v;         scanf( %d , &v);         v--;         int VVV = find_set(v);         printf( %d n , diam_ancestor[VVV]);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char arr[300];   int main() {     ios::sync_with_stdio(false);     string s, t;     cin >> s >> t;     int n = s.size();     memset(arr,  A , sizeof(arr));     if (n != t.size()) {       cout << -1;       return 0;     }     for (int i = 0; i < n; i++) {       if (arr[t[i]] !=  A ) {         if (arr[t[i]] != s[i]) {           cout << -1;           return 0;         }         continue;       }       if (arr[s[i]] ==  A ) {         arr[s[i]] = t[i];         arr[t[i]] = s[i];       }       if (arr[s[i]] != t[i]) {         cout << -1;         return 0;       }     }     vector<pair<char, char> > v;     for (int i = 0; i < 300; i++) {       if (arr[i] !=  A ) {         if (i == arr[i]) continue;         v.push_back(make_pair((char)i, arr[i]));         arr[arr[i]] =  A ;         arr[i] =  A ;       }     }     cout << v.size() << endl;     for (int i = 0; i < v.size(); i++)       cout << v[i].first <<     << v[i].second << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 1110;   const long long inf = 1000000007998244353ll;   struct S {     long long l, r;   } a[N * N];   long long si[N][N];   long long tot;   long long n, m, k;   string s;   long long lcp[N][N];   long long dp[N][N];   long long suffix_sum[N];   long long ri[N];   inline long long add(long long a, long long b) {     return a + b > inf ? inf : a + b;   }   long long cnt(long long S) {     for (long long i = 0; i < n; i++) {       ri[i] = i;       while (ri[i] != n && si[i][ri[i]] <= S) {         ri[i]++;       }     }     for (long long i = 0; i < n; i++) {       dp[i][1] = si[i][n - 1] > si[a[S].l][a[S].r] ? 1 : 0;     }     for (long long j = 2; j <= m; j++) {       suffix_sum[n - 1] = dp[n - 1][j - 1];       for (long long i = n - 2; i >= 0; i--) {         suffix_sum[i] = add(dp[i][j - 1], suffix_sum[i + 1]);       }       for (long long i = 0; i < n; i++) {         dp[i][j] = ri[i] == n ? 0 : suffix_sum[ri[i] + 1];       }     }     return dp[0][m];   }   bool cmp(S i, S j) {     long long p = i.l + lcp[i.l][j.l], q = j.l + lcp[i.l][j.l];     if (p > i.r || q > j.r) {       return i.r - i.l < j.r - j.l;     }     return s[p] < s[q];   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     tot = 0;     cin >> n >> m >> k >> s;     for (long long i = 0; i < n; i++) {       for (long long j = i; j < n; j++) {         a[tot].l = i;         a[tot].r = j;         tot++;       }     }     for (long long i = n - 1; i >= 0; i--) {       for (long long j = n - 1; j >= 0; j--) {         lcp[i][j] = s[i] == s[j] ? lcp[i + 1][j + 1] + 1 : 0;       }     }     sort(a, a + tot, cmp);     for (long long i = 0; i < tot; i++) {       si[a[i].l][a[i].r] = i;     }     long long l = 0, r = tot - 1;     while (l < r) {       long long midd = (r + l) / 2;       if (cnt(midd) >= k) {         l = midd + 1;       } else {         r = midd;       }     }     for (long long i = a[r].l; i <= a[r].r; i++) {       cout << s[i];     }     return 0;   }


#include <bits/stdc++.h>   char ch;   inline void read(int &x) {     x = 0;     ch = getchar();     while (ch <= 32) ch = getchar();     while (ch > 32) {       x = x * 10 + ch - 48;       ch = getchar();     };   };   const int dx[8] = {0, 1, 0, -1, -1, -1, 1, 1};   const int dy[8] = {1, 0, -1, 0, -1, 1, -1, 1};   const int D_cnt = 8;   const int K1 = 3, K2 = 6;   int n, m;   bool a[1605][1605];   bool b[1605][1605];   char dist[1605][1605];   int l1[1605 * 1605], l2[1605 * 1605];   int s, t;   inline void push(int x, int y) {     ++t;     l1[t] = x;     l2[t] = y;   };   inline void bfs1() {     s = t = 0;     int i, j;     for (i = 1; i <= n; i++) {       for (j = 1; j <= m; j++) {         if (!b[i][j]) {           push(i, j);           dist[i][j] = 0;         };       };     };     while (s < t) {       int tx, ty;       ++s;       tx = l1[s];       ty = l2[s];       if (dist[tx][ty] == K1) continue;       for (i = 0; i < D_cnt; i++) {         int nx = tx + dx[i], ny = ty + dy[i];         if (nx < 1 || nx > n || ny < 1 || ny > m) continue;         if (!b[nx][ny]) continue;         b[nx][ny] = 0;         dist[nx][ny] = dist[tx][ty] + 1;         push(nx, ny);       };     };   };   inline void bfs2() {     s = t = 0;     int i, j;     for (i = 1; i <= n; i++) {       for (j = 1; j <= m; j++) {         if (b[i][j]) {           push(i, j);           dist[i][j] = 0;         };       };     };     while (s < t) {       int tx, ty;       ++s;       tx = l1[s];       ty = l2[s];       if (dist[tx][ty] == K2) continue;       for (i = 0; i < D_cnt; i++) {         int nx = tx + dx[i], ny = ty + dy[i];         if (nx < 1 || nx > n || ny < 1 || ny > m) continue;         if (b[nx][ny]) continue;         b[nx][ny] = 1;         dist[nx][ny] = dist[tx][ty] + 1;         push(nx, ny);       };     };   };   int _cnt;   int visit[1605][1605];   int ll1[1605 * 1605], ll2[1605 * 1605];   inline void fill(int x0, int y0) {     s = t = 0;     bool _b = b[x0][y0];     visit[x0][y0] = ++_cnt;     push(x0, y0);     while (s < t) {       int tx, ty;       ++s;       tx = l1[s];       ty = l2[s];       int i;       for (i = 0; i < D_cnt; i++) {         int nx = tx + dx[i], ny = ty + dy[i];         if (nx < 1 || nx > n || ny < 1 || ny > m) continue;         if (visit[nx][ny] == _cnt) continue;         if (!a[nx][ny] || b[nx][ny] != _b) continue;         visit[nx][ny] = _cnt;         push(nx, ny);       };     };   };   int ans[10000];   int cnt;   inline void check(int x0, int y0) {     s = t = 0;     push(x0, y0);     visit[x0][y0] = ++_cnt;     while (s < t) {       int tx, ty;       ++s;       tx = l1[s];       ty = l2[s];       int i;       for (i = 0; i < D_cnt; i++) {         int nx = tx + dx[i], ny = ty + dy[i];         if (nx < 1 || nx > n || ny < 1 || ny > m) continue;         if (visit[nx][ny] == _cnt) continue;         if (!a[nx][ny]) continue;         visit[nx][ny] = _cnt;         push(nx, ny);       };     };     memcpy(ll1, l1, (t + 1) * sizeof(int));     memcpy(ll2, l2, (t + 1) * sizeof(int));     int tmp_cnt = _cnt;     int tmp = 0;     int i;     int T = t;     for (i = 1; i <= T; i++) {       int tx = ll1[i], ty = ll2[i];       if (visit[tx][ty] == tmp_cnt) {         ++tmp;         fill(tx, ty);       };     };     ans[++cnt] = tmp - 1;   };   int main() {     read(n);     read(m);     int i, j;     for (i = 1; i <= n; i++) {       for (j = 1; j <= m; j++) {         int x;         read(x);         a[i][j] = x;       };     };     memcpy(b, a, sizeof(a));     bfs1();     bfs2();     for (i = 1; i <= n; i++) {       for (j = 1; j <= m; j++) {         if (a[i][j] && !visit[i][j]) {           check(i, j);         };       };     };     std::sort(ans + 1, ans + cnt + 1);     printf( %d n , cnt);     for (i = 1; i <= cnt; i++) {       printf( %d  , ans[i]);     };   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   bool cmp(pair<ll, ll> a, pair<ll, ll> b) { return a.second > b.second; }   bool cmp2(vector<ll> a, vector<ll> b) { return a.size() > b.size(); }   int main() {     ll n, m;     cin >> n >> m;     vector<pair<ll, ll>> vp(n);     for (ll i = 0; i < n; i++) {       ll s, r;       cin >> s >> r;       s--;       vp[i] = make_pair(s, r);     }     sort(vp.begin(), vp.end(), cmp);     vector<vector<ll>> g(m, vector<ll>(1));     ll mxsz = 0;     for (ll i = 0; i < n; i++) {       g[vp[i].first].push_back(vp[i].second + g[vp[i].first].back());       mxsz = max(mxsz, (ll)g[vp[i].first].size());     }     sort(g.begin(), g.end(), cmp2);     ll ans = 0;     for (ll i = 0; i < mxsz; i++) {       ll now = 0;       vector<ll> hoge;       for (ll j = 0; j < m; j++) {         if (i < g[j].size()) {           if (g[j][i] > 0) now += g[j][i];         }         if (g[j].size() < i) break;       }       ans = max(ans, now);     }     cout << max(0LL, ans) << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int maxN = 2000;   int main() {     ios_base::sync_with_stdio(0);     int n;     cin >> n;     for (int i = 1; i <= n; i++) {       long long l, r;       cin >> l >> r;       int ans = 0;       long long mn = r;       long long cur = 0;       int cnt = 0;       for (int i = 60; i >= 0; i--) {         long long tmp = r;         if (r & (1ll << i)) {           if (cur + (1ll << i) - 1 >= l) {             if (ans < cnt + i) {               mn = cur + (1ll << i) - 1;               ans = cnt + i;             }           }           cnt++;           cur += (1ll << i);         }       }       if (cnt > ans) {         ans = cnt;         mn = r;       }       cout << mn <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1 << 18;   int uf[N];   int cost[N];   vector<pair<int, int>> h_uf;   vector<pair<int, int>> h_cost;   pair<int, int> query[N];   int ans[N];   bool sample;   struct edge {     int u, v, w;     edge(int u, int v, int w) : u(u), v(v), w(w) {}   };   vector<edge> seg[N * 2];   int find(int u) {     while (uf[u] >= 0) {       u = uf[u];     }     return u;   }   int find_cost(int u) {     int res = 0;     while (uf[u] >= 0) {       res ^= cost[u];       u = uf[u];     }     return res;   }   bool unite(int u, int v, int w) {     int pu = find(u);     int pv = find(v);     if (pu == pv) return false;     w ^= find_cost(u);     w ^= find_cost(v);     u = pu;     v = pv;     if (-uf[u] < -uf[v]) swap(u, v);     h_uf.emplace_back(u, uf[u]);     h_uf.emplace_back(v, uf[v]);     h_cost.emplace_back(v, cost[v]);     uf[u] += uf[v];     uf[v] = u;     cost[v] = w;     return true;   }   void undo() {     auto p = h_uf.back();     h_uf.pop_back();     auto q = h_uf.back();     h_uf.pop_back();     auto r = h_cost.back();     h_cost.pop_back();     uf[p.first] = p.second;     uf[q.first] = q.second;     cost[r.first] = r.second;   }   int find_cost(int u, int v) { return find_cost(u) ^ find_cost(v); }   void init_uf(int n) {     for (int i = 0; i < n; i++) {       uf[i] = -1;     }   }   void insert(int l, int r, edge e, int k = 1, int ll = 0, int rr = N) {     if (rr <= l || r <= ll) return;     if (l <= ll && rr <= r) {       seg[k].emplace_back(e);       return;     }     insert(l, r, e, k * 2 + 0, ll, ll + rr >> 1);     insert(l, r, e, k * 2 + 1, ll + rr >> 1, rr);   }   vector<int> normalize(vector<int> a) {     int r = 0;     for (int j = 29; j >= 0; j--) {       int p = -1;       for (int i = r; i < a.size(); i++) {         if (a[i] >> j & 1) {           p = i;           break;         }       }       if (p == -1) continue;       swap(a[r], a[p]);       for (int i = r + 1; i < a.size(); i++) {         if (a[i] >> j & 1) {           a[i] ^= a[r];         }       }       r++;     }     a.resize(r);     return a;   }   int find_min(int x, vector<int> &a) {     for (int y : a) x = min(x, x ^ y);     return x;   }   void dfs(vector<int> a, int k = 1, int l = 0, int r = N) {     int cnt = 0;     for (edge e : seg[k]) {       if (unite(e.u, e.v, e.w)) {         cnt++;       } else {         a.push_back(e.w ^ find_cost(e.u, e.v));       }     }     a = normalize(a);     if (r - l == 1) {       if (query[l].second != 0) {         ans[l] = find_min(find_cost(query[l].first, query[l].second), a);       }       return;     }     dfs(a, k * 2 + 0, l, l + r >> 1);     dfs(a, k * 2 + 1, l + r >> 1, r);     while (cnt--) undo();   }   int input() {     int n;     scanf( %d , &n);     return n;   }   int main() {     int n, m;     cin >> n >> m;     init_uf(n);     map<pair<int, int>, pair<int, int>> mp;     for (int i = 0; i < m; i++) {       int u = input() - 1;       int v = input() - 1;       int w = input();       mp[{u, v}] = {w, 0};     }     int q = input();     for (int i = 1; i <= q; i++) {       int type = input();       int u = input() - 1;       int v = input() - 1;       if (type == 1) {         int w = input();         mp[{u, v}] = {w, i};       } else if (type == 2) {         auto it = mp.find({u, v});         insert(it->second.second, i, edge(u, v, it->second.first));         mp.erase(it);       } else {         query[i] = {u, v};       }     }     for (auto p : mp) {       int u = p.first.first;       int v = p.first.second;       int w = p.second.first;       int s = p.second.second;       insert(s, q + 1, edge(u, v, w));     }     sample = n <= 10;     dfs({});     for (int i = 1; i <= q; i++) {       if (query[i].second != 0) {         printf( %d n , ans[i]);       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int Maxn = 200010;   const int inf = 2147483647;   const double pi = acos(-1.0);   int read() {     int x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) x = x * 10 + ch -  0 , ch = getchar();     return x * f;   }   int n, pre[Maxn], nxt[Maxn], ed;   long long a[Maxn], sum[Maxn];   void ins(int l, int m, int r) {     pre[m] = l, nxt[m] = r;     if (l != -1) nxt[l] = m;     if (r != -1) pre[r] = m;   }   int main() {     n = read();     sum[0] = 0;     for (int i = 1; i <= n; i++) a[i] = read(), sum[i] = sum[i - 1] + a[i];     int ans = 0;     pre[1] = nxt[1] = -1;     ed = 1;     for (int i = 2; i <= n; i++) {       int t = ed, st;       bool flag = false;       while (t != -1) {         if (!flag && a[t] + sum[t] < sum[i] + a[i]) {           flag = true;           if (nxt[t] == -1) ed = i;           ins(t, i, nxt[t]);         }         if (a[t] + sum[t] >= sum[i - 1] - a[i]) {           if ((a[i] ^ a[t]) == sum[i - 1] - sum[t] && i - t >= 2) ans++;         } else           break;         st = t;         t = pre[t];       }       if (!flag) ins(-1, i, st);     }     printf( %d , ans);   }


#include <bits/stdc++.h>   using namespace std;   vector<long long> Edge[100010];   long long ar[100010];   bool Visit[100010 + 7];   bool InStk[100010 + 7];   long long Low[100010 + 7], I;   long long Ind[100010 + 7];   stack<long long> Stk;   long long ans1, ans2;   void SCC(long long u) {     Visit[u] = true;     InStk[u] = true;     Ind[u] = ++I;     Low[u] = I;     Stk.push(u);     for (int i = 0; i < Edge[u].size(); i++) {       long long v = Edge[u][i];       if (!Visit[v]) {         SCC(v);         Low[u] = min(Low[u], Low[v]);       } else if (InStk[v]) {         Low[u] = min(Low[u], Ind[v]);       }     }     if (Low[u] != Ind[u]) return;     long long mn = LONG_LONG_MAX, num = 0;     while (Stk.top() != u) {       long long v = Stk.top();       if (mn > ar[v]) {         mn = ar[v];         num = 1;       } else if (mn == ar[v]) {         num++;       }       Stk.pop();       InStk[v] = false;     }     long long v = Stk.top();     if (mn > ar[v]) {       mn = ar[v];       num = 1;     } else if (mn == ar[v]) {       num++;     }     ans2 *= num;     ans2 %= 1000000007;     ans1 += mn;     Stk.pop();     InStk[u] = false;   }   int main() {     int n, m;     while (cin >> n) {       for (int i = 0; i < 100010; ++i) Edge[i].clear();       for (int i = 0; i < n; ++i) scanf( %I64d , &ar[i + 1]);       cin >> m;       long long u, v;       for (int i = 0; i < m; ++i) {         scanf( %I64d %I64d , &u, &v);         Edge[u].push_back(v);       }       memset(Visit, 0, sizeof(Visit));       memset(InStk, 0, sizeof(InStk));       memset(Low, 0, sizeof(Low));       memset(Ind, 0, sizeof(Ind));       ans1 = 0;       ans2 = 1;       for (int i = 1; i <= n; i++) {         if (Visit[i]) continue;         SCC(i);       }       cout << ans1 <<     << ans2 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> arr;   int maxNum = -1;   int n;   bool vis[1000000 + 50];   int main() {     memset(vis, false, sizeof(vis));     scanf( %d , &(n));     for (int i = 0; i < n; i++) {       int tmp;       scanf( %d , &(tmp));       if (!vis[tmp]) {         arr.push_back(tmp);         vis[tmp] = true;         if (tmp > maxNum) {           maxNum = tmp;         }       }     }     n = arr.size();     if (arr.size() == 1) {       printf( 0 n );       return 0;     }     sort(arr.begin(), arr.end());     int ans = 0;     for (int i = 0; i < n; i++) {       int num = arr[i];       int t = 2;       while (1) {         int pos = lower_bound(arr.begin(), arr.end(), num * t) - arr.begin() - 1;         int tmp = arr[pos] % num;         if (tmp > ans) {           ans = tmp;         }         if (pos == n - 1) {           break;         }         t++;       }     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6;   int n, a[N * 2], b[N * 2];   pair<int, int> r[N];   int main() {     int n, q;     scanf( %d%d , &n, &q);     for (int i = 0; i < n; i++) {       scanf( %d , &a[i]);       a[n + i] = a[i];     }     while (q--) {       long long sum;       scanf( %lld , &sum);       int ans = 1e9, high = -1;       long long w = 0;       for (int i = 0; i < n; i++) {         for (; high + 1 < n * 2 && w + a[high + 1] <= sum;) {           w += a[++high];         }         w -= a[i];         b[i] = high + 1;       }       for (int i = n - 1; i >= 0; i--) {         if (b[i] >= n) {           r[i] = {b[i], 1};         } else {           r[i] = {r[b[i]].first, r[b[i]].second + 1};         }         if (r[i].first - n >= i) {           ans = min(ans, r[i].second);         }       }       printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   ofstream fo( test.out );   ifstream fi( test.inp );   int n, m, k, dem;   int x[200005], y[200005];   int main() {     long long a;     cin >> a;     for (long long i = 2; i * i <= a; i++) {       while (a % (i * i) == 0) a /= i;     }     cout << a;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 205;   const int maxm = 4005;   int n, m, p, s, t, ss, tt;   namespace Flow {   int tot, S, T, V;   int head[maxn], nxt[maxm * 2], to[maxm * 2], cap[maxm * 2], cost[maxm * 2];   int dist[maxn], parv[maxn], pare[maxn];   bool in[maxn];   queue<int> q;   void init() {     tot = 0;     memset(head, -1, sizeof(head));   }   void addedge(int u, int v, int c, int co) {     nxt[tot] = head[u];     to[tot] = v;     cap[tot] = c;     cost[tot] = co;     head[u] = tot++;     nxt[tot] = head[v];     to[tot] = u;     cap[tot] = 0;     cost[tot] = -co;     head[v] = tot++;   }   int flow() {     for (int i = 0; i < (V); i++) in[i] = false, dist[i] = int(1e9);     dist[S] = 0;     in[S] = true;     q.push(S);     while (!q.empty()) {       int x = q.front();       q.pop();       in[x] = false;       for (int i = head[x]; ~i; i = nxt[i]) {         if (cap[i] && dist[to[i]] > dist[x] + cost[i]) {           dist[to[i]] = dist[x] + cost[i];           parv[to[i]] = x;           pare[to[i]] = i;           if (!in[to[i]]) {             in[to[i]] = true;             q.push(to[i]);           }         }       }     }     if (dist[T] == int(1e9)) return -int(1e9);     int res = 0;     for (int i = T; i != S; i = parv[i]) {       res += cost[pare[i]];       cap[pare[i]]--;       cap[pare[i] ^ 1]++;     }     return res;   }   }  // namespace Flow   int main() {     scanf( %d %d , &n, &m);     s = 1, t = n;     Flow::init();     ss = 0;     tt = n + 1;     Flow::S = n + 2;     Flow::T = Flow::S + 1;     Flow::V = Flow::T + 1;     Flow::addedge(Flow::S, tt, int(1e9), 0);     Flow::addedge(t, Flow::T, int(1e9), 0);     Flow::addedge(ss, s, int(1e9), 0);     Flow::addedge(Flow::S, s, int(1e9), 0);     for (int i = 1; i <= (m); i++) {       int u, v, d, c;       scanf( %d%d%d , &u, &v, &d);       Flow::addedge(u, v, 1, d);     }     for (int i = 1; i <= (n); i++) Flow::addedge(i, tt, int(1e9), 0);     vector<int> data;     for (;;) {       int f = Flow::flow();       if (f == -int(1e9)) break;       data.push_back(f);     }     int q;     scanf( %d , &q);     while (q--) {       int p;       scanf( %d , &p);       long long s = 0;       int c = 0;       double ans = 1e18;       for (int i = 0; i < data.size(); i++) {         s += data[i];         c++;         double cur = double(s + p) / double(c);         if (cur < ans)           ans = cur;         else           break;       }       printf( %.10lf n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int LEN = 100000;   struct fastio {     int it, len;     char s[LEN + 5];     fastio() { it = len = 0; }     char get() {       if (it < len) return s[it++];       it = 0, len = fread(s, 1, LEN, stdin);       return len ? s[it++] : EOF;     }     bool notend() {       char c;       for (c = get(); c ==     || c ==   n  || c ==   r ; c = get())         ;       if (it) it--;       return c != EOF;     }     void put(char c) {       if (it == LEN) fwrite(s, 1, LEN, stdout), it = 0;       s[it++] = c;     }     void flush() { fwrite(s, 1, it, stdout); }   } buff, bufo;   inline int getint() {     char c;     int res = 0, sig = 1;     for (c = buff.get(); c <  0  || c >  9 ; c = buff.get())       if (c ==  - ) sig = -1;     for (; c >=  0  && c <=  9 ; c = buff.get()) res = res * 10 + (c -  0 );     return sig * res;   }   inline long long getll() {     char c;     long long res = 0, sig = 1;     for (c = buff.get(); c <  0  || c >  9 ; c = buff.get())       if (c ==  - ) sig = -1;     for (; c >=  0  && c <=  9 ; c = buff.get()) res = res * 10 + (c -  0 );     return sig * res;   }   inline void putint(int x, char suf) {     if (!x)       bufo.put( 0 );     else {       if (x < 0) bufo.put( - ), x = -x;       int k = 0;       char s[15];       while (x) {         s[++k] = x % 10 +  0 ;         x /= 10;       }       for (; k; k--) bufo.put(s[k]);     }     bufo.put(suf);   }   inline void putll(long long x, char suf) {     if (!x)       bufo.put( 0 );     else {       if (x < 0) bufo.put( - ), x = -x;       int k = 0;       char s[25];       while (x) {         s[++k] = x % 10 +  0 ;         x /= 10;       }       for (; k; k--) bufo.put(s[k]);     }     bufo.put(suf);   }   inline char get_char() {     char c;     for (c = buff.get(); c ==     || c ==   n  || c ==   r ; c = buff.get())       ;     return c;   }   int a[200005];   void solve() {     int n = getint();     for (int i = 1; i <= n; i++) a[i] = getint();     long long ans = 0;     for (int i = 1; i < n; i++)       if (a[i] > a[i + 1]) ans += a[i] - a[i + 1];     putll(ans,   n );   }   int main() {     int T = getint();     while (T--) solve();     bufo.flush();     return 0;   }


#include <bits/stdc++.h>   int main() {     int a, b, c;     scanf( %d%d%d , &a, &b, &c);     int x = 30;     while (a > 0 || b > 0 || c > 0) {       switch (x % 3) {         case 0:           a -= 2;           if (a < 0) a = 0;           break;         case 1:           b -= 2;           if (b < 0) b = 0;           break;         case 2:           c -= 2;           if (c < 0) c = 0;           break;       }       x++;     }     printf( %d n , x - 1);   }


#include <bits/stdc++.h>      using namespace std;   const int N=3e5+10;   typedef long long ll;   int pos[N],a[N],q,n;   void  solve()   {    cin>>n>>q;    for(int i=1;i<=n;i++) cin>>a[i];    for(int i=n;i;i--)pos[a[i]]=i;    while(q--)    {     int x;     cin>>x;     cout<<pos[x]<<   ;     int t=pos[x];     pos[x]=1;     for(int i=1;i<=50;i++)     if(i!=x&&pos[i]<t)     pos[i]++;    }       }   int main()   {    int t=1;    while(t--)    {     solve();    }    //system( pause );    return 0;   }


#include <iostream>   #include <algorithm>      constexpr int N = 100005;      int n;   struct node {       long long a, b;   } a[N];      int main() {       std::ios::sync_with_stdio(false), std::cin.tie(nullptr);       std::cin >> n;       long long ans = 0;       for (int i = 1; i <= n; ++i) std::cin >> a[i].a >> a[i].b, ans += a[i].b;       std::sort(a + 1, a + n + 1, [](node a, node b) { return a.a < b.a; });       int now = 1;       long long max = a[1].a + a[1].b;       while (now <= n) {           int x = now + 1;           while (x <= n && a[x].a + a[x].b <= max) ++x;           if (x > n) break;           ans += std::max(a[x].a - max, 0ll);           max = a[x].a + a[x].b;           now = x;       }       std::cout << ans <<   n ;       return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 998244353;   const int inf = 1 << 30;   const int maxn = 100000 + 5;   int tot, dfn[maxn << 1], ord[maxn << 1];   namespace hld {   const int maxn = ::maxn << 1;   struct edge {     int to, nxt;   } g[maxn];   int head[maxn], ecnt = 0;   void add(int x, int y) {     g[++ecnt] = {y, head[x]};     head[x] = ecnt;   }   int siz[maxn], dep[maxn], fa[maxn], son[maxn], top[maxn];   void dfs(int p, int d, int old) {     dfn[p] = ++tot;     ord[tot] = p;     dep[p] = d;     fa[p] = old;     siz[p] = 1;     int m = -1;     for (int i = head[p]; i; i = g[i].nxt) {       int v = g[i].to;       if (v == fa[p]) continue;       dfs(v, d + 1, p);       siz[p] += siz[v];       if (siz[v] > m) son[p] = v, m = siz[v];     }   }   void dfs(int p, int tp) {     top[p] = tp;     if (!son[p]) return;     dfs(son[p], tp);     for (int i = head[p]; i; i = g[i].nxt) {       int v = g[i].to;       if (v == fa[p] || v == son[p]) continue;       dfs(v, v);     }   }   void build(int rt = 1) {     memset(son, 0, sizeof(son));     dfs(rt, rt, 0);     dfs(rt, rt);   }   int qlca(int x, int y) {     while (top[x] != top[y]) {       if (dep[top[x]] < dep[top[y]]) swap(x, y);       x = fa[top[x]];     }     if (dep[x] > dep[y]) swap(x, y);     return x;   }   }  // namespace hld   vector<int> edge[maxn << 1];   struct sam {     int sz, last, cnt[maxn << 1];     int len[maxn << 1], link[maxn << 1], ch[maxn << 1][26];     void clear() {       for (int i = 1; i <= sz; i++) {         len[i] = link[i] = cnt[i] = 0;         memset(ch[i], 0, sizeof(ch[i]));       }       sz = last = 1;     }     sam() { clear(); }     int insert(int c) {       int cur = ++sz, p = last;       len[cur] = len[last] + 1;       cnt[cur] = 1;       for (; p && !ch[p][c]; p = link[p]) ch[p][c] = cur;       if (!p)         link[cur] = 1;       else {         int q = ch[p][c];         if (len[p] + 1 == len[q])           link[cur] = q;         else {           int nq = ++sz;           len[nq] = len[p] + 1;           link[nq] = link[q];           link[q] = link[cur] = nq;           memcpy(ch[nq], ch[q], sizeof ch[q]);           for (; ch[p][c] == q; p = link[p]) ch[p][c] = nq;         }       }       return last = cur;     }     void build(int tp) {       if (tp == 0) {         for (int i = 1; i <= sz; i++) {           len[i]++;           edge[link[i]].push_back(i);         }       } else {         for (int i = 1; i <= sz; i++) {           len[i]++;           hld::add(link[i], i);         }         hld::build();       }     }   } ta, tb;   int n;   long long ans;   char s[maxn];   int prepos[maxn], sufpos[maxn];   set<int> bag[maxn << 1];   long long val[maxn << 1];   void add(int u, int p) {     auto it = bag[u].lower_bound(p);     int node = -1, d = hld::dep[ord[p]];     if (it != bag[u].end()) {       node = hld::qlca(ord[p], ord[*it]);     }     if (it != bag[u].begin()) {       it--;       int y = hld::qlca(ord[p], ord[*it]);       if (node == -1 || abs(hld::dep[node] - d) > abs(hld::dep[y] - d)) node = y;     }     val[u] += tb.len[ord[p]];     if (node != -1) val[u] -= tb.len[node];     bag[u].insert(p);   }   void dfs(int u) {     for (int v : edge[u]) {       dfs(v);       if (bag[v].size() > bag[u].size()) {         swap(bag[u], bag[v]);         val[u] = val[v];       }       for (auto& x : bag[v]) add(u, x);     }     ans += (val[u] + 1) * (ta.len[u] - ta.len[ta.link[u]]);     ;   }   int main() {     scanf( %s , s + 1);     n = strlen(s + 1);     prepos[0] = sufpos[n + 1] = 1;     for (int i = 1; i <= n; i++) {       prepos[i] = ta.insert(s[i] -  a );     }     for (int i = n; i >= 1; i--) {       sufpos[i] = tb.insert(s[i] -  a );     }     ta.build(0);     tb.build(1);     for (int i = 0; i < n; i++) {       add(prepos[i], dfn[sufpos[i + 2]]);     }     dfs(1);     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int sum[5];   int n;   int main() {     cin >> n;     int res = 0;     for (int i = 1; i <= n; ++i) {       int t;       scanf( %d , &t);       if (t) sum[t]++;     }     int tmp = min(sum[1], sum[2]);     sum[3] += tmp;     res += tmp;     sum[2] -= tmp;     sum[1] -= tmp;     if (sum[1]) {       int t = sum[1] / 3;       res += t * 2;       sum[1] -= t * 3;       sum[3] += t;       if (sum[1]) {         if (sum[3] >= sum[1])           res += sum[1];         else {           if (sum[1] == 2) {             if (sum[4])               res += 2;             else {               printf( -1 n );               return 0;             }           } else {             if (sum[3])               res += 1;             else if (sum[4] >= 2)               res += 2;             else {               printf( -1 n );               return 0;             }           }         }       }     } else if (sum[2]) {       int t = sum[2] / 3;       res += t * 2;       sum[2] -= t * 3;       sum[3] += t * 2;       if (sum[2]) {         if (sum[4] >= sum[2])           res += sum[2];         else {           if (sum[2] == 2)             res += 2;           else {             if (sum[3] >= 2)               res += 2;             else {               printf( -1 n );               return 0;             }           }         }       }     }     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long ans, heavy;   string s;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> s;     for (int i = 0; i <= (int)s.size() - 5; i++) {       if (s.substr(i, 5) ==  heavy ) {         heavy++;       } else if (s.substr(i, 5) ==  metal ) {         ans += heavy;       }     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int K, N;   long double XX, YY, P[101], PP, arr[101][101], obj[101][2], EPS = 1e-9;   double calk(int n, int k) {     if (arr[n][k] != -1) return arr[n][k];     double retAns = 0;     if (n == 1 && k == 1)       arr[n][k] = P[1];     else if (n == 1 && k == 0)       arr[n][k] = 1 - P[1];     else if (n == 0 || k > n || k < 0)       arr[n][k] = 0;     else {       double v1 = calk(n - 1, k - 1) * P[n];       double v2 = calk(n - 1, k) * (1 - P[n]);       arr[n][k] = calk(n - 1, k - 1) * P[n] + calk(n - 1, k) * (1 - P[n]);     }     return arr[n][k];   }   double calcDist(double x, double y) {     return (x - XX) * (x - XX) + (y - YY) * (y - YY);   }   double calk2(double r) {     double retAns = 0;     for (int i = 0; i <= N; i++) {       for (int j = 0; j <= N; j++) arr[i][j] = -1;       if (i) {         double t = calcDist(obj[i][0], obj[i][1]);         if (r * r > EPS && t > r * r)           P[i] = exp(1.0 - t / (r * r));         else           P[i] = 1.0;       }     }     int g;     for (int k = K; k <= N; k++) retAns += calk(N, k);     return retAns;   }   double binS(double l, double r) {     if (fabs(l - r) < EPS) return l;     double mid = l + (r - l) / 2.0;     if (calk2(mid) > PP)       return binS(l, mid);     else       return binS(mid, r);   }   int main() {     cin >> N >> K;     double tp;     cin >> tp;     tp /= 1000;     tp = 1.0 - tp;     PP = tp;     cin >> XX >> YY;     for (int i = 1; i <= N; i++) cin >> obj[i][0] >> obj[i][1];     cout.setf(ios::fixed);     cout.precision(10);     cout << binS(0, 10000);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double pi = acos(-1.0);   const int N = 5000000;   const double eps = 1e-6;   int n, l, m, k, a[N], rev[N], res[N];   bool used[N];   complex<double> b[N], tmp[N];   pair<int, int> p[N];   vector<int> ans;   void fft(bool invert) {     for (int i = 0; i < l; i++) tmp[rev[i]] = b[i];     for (int i = 0; i < l; i++) b[i] = tmp[i];     for (int r = 1; r <= k; r++) {       for (int i = 0; i < l; i += (1 << r)) {         for (int j = i; j < i + (1 << (r - 1)); j++) {           double ang;           if (!invert)             ang = 2.0 * (j - i) * pi / (1 << r);           else             ang = -2.0 * (j - i) * pi / (1 << r);           complex<double> w(cos(ang), sin(ang));           complex<double> t1 = b[j], t2 = b[j + (1 << (r - 1))];           b[j] = t1 + w * t2;           b[j + (1 << (r - 1))] = t1 - w * t2;         }       }     }     if (invert) {       for (int i = 0; i < l; i++) b[i] /= l;     }   }   int main() {     scanf( %d%d , &n, &m);     memset(used, false, sizeof(used));     for (int i = 0; i < n; i++) scanf( %d , &a[i]);     for (int i = 0; i < n; i++) used[a[i]] = true;     m++;     l = 1;     k = 0;     for (int i = 1; i <= 20; i++)       if (l < m) {         l *= 2;         k++;       } else         break;     l *= 2;     k++;     for (int i = 0; i < n; i++) b[a[i]] = complex<double>(1, 0);     for (int i = 0; i < l; i++) {       int mask = 0;       for (int j = 0; j < k; j++)         if (i & (1 << j)) mask |= 1 << (k - j - 1);       rev[i] = mask;     }     fft(0);     for (int i = 0; i < l; i++) b[i] *= b[i];     fft(1);     for (int i = 0; i < l; i++) res[i] = b[i].real() + 0.5;     for (int i = 1; i < m; i++) {       if ((!res[i]) && (used[i]))         ans.push_back(i);       else if ((res[i]) && (!used[i])) {         cout <<  NO ;         return 0;       }     }     cout <<  YES  << endl;     printf( %d n , ans.size());     for (int i = 0; i < ans.size(); i++) printf( %d  , ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double pi = acos(-1.0);   const double eps = 1e-10;   const int MOD = 998244353;   const int INF = 0x3f3f3f3f;   const int maxn = 1e3 + 10;   const int maxm = 2e5 + 10;   char s[maxn];   int len, arr[maxn];   pair<int, long long> dq[maxn];   int main() {     scanf( %d%s , &len, s + 1);     for (int i = 1; i <= len; ++i) s[len + i] = s[i];     int ans = 0;     pair<int, long long> pos;     for (int i = 1; i <= len; ++i)       for (int j = i; j <= len; ++j) {         int cnt = 0;         swap(s[i], s[j]);         swap(s[i + len], s[j + len]);         int top = 500, bk = 499;         for (int k = 1; k <= len * 2; ++k) {           if (s[k] ==  ( )             arr[k] = ++cnt;           else             arr[k] = --cnt;         }         for (int k = 1; k <= len; ++k) {           while (bk >= top && dq[bk].first > arr[k]) --bk;           dq[++bk] = {arr[k], k};         }         int pre = 0, res = 0;         for (int k = 1; k <= len; ++k) {           while (dq[top].second < k) ++top;           while (bk >= top && dq[bk].first >= arr[k + len - 1]) --bk;           dq[++bk] = {arr[k + len - 1], k + len - 1};           if (dq[top].first - pre >= 0 && arr[k + len - 1] - pre == 0) ++res;           pre = arr[k];         }         if (ans < res) {           ans = res;           pos = {i, j};         }         swap(s[i], s[j]);         swap(s[i + len], s[j + len]);       }     printf( %d n , ans);     if (pos.first == 0) pos = {1, 1};     printf( %d %d n , pos.first, pos.second);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long ans = 0;   int a[200005], n, len = 1 << 18;   int mx1[1 << 18], mx2[1 << 18], fa[200005], w1[200005], w2[200005];   int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); }   void add(int x, int w) {     if (find(w) != find(mx1[x]) && a[w] > a[mx1[x]])       mx2[x] = mx1[x], mx1[x] = w;     else if (find(w) != find(mx1[x]) && a[w] > a[mx2[x]])       mx2[x] = w;   }   int query(int x) {     int t = (len - 1) ^ a[x];     if (mx1[t] && find(mx1[t]) != find(x)) return mx1[t];     if (mx2[t] && find(mx2[t]) != find(x)) return mx2[t];     return 0;   }   int merge(int x, int y) {     if (y == 0) return 0;     y = find(y);     if (x == y) return 0;     fa[x] = y;     return 1;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) scanf( %d , &a[i]), ans -= a[i];     ++n;     a[0] = -1;     for (int i = 1; i <= n; ++i) fa[i] = i;     while (1) {       for (int i = 0; i < len; ++i) mx1[i] = mx2[i] = 0;       for (int i = 1; i <= n; ++i) add(a[i], i);       for (int i = 0; i < 18; ++i)         for (int j = 0; j < len; ++j)           if (j & (1 << i)) {             add(j, mx1[j ^ (1 << i)]);             add(j, mx2[j ^ (1 << i)]);           }       for (int i = 1; i <= n; ++i) w1[i] = -1;       for (int i = 1; i <= n; ++i) {         int t = query(i), x = find(i);         if (t != 0 && a[i] + a[t] > w1[x]) w1[x] = a[i] + a[t], w2[x] = t;       }       int f = 0;       for (int i = 1; i <= n; ++i)         if (find(i) == i && merge(i, w2[i])) ans += w1[i], f = 1;       if (!f) break;     }     printf( %lld , ans);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     long arr[n];     for (int i = 0; i < n; i++) cin >> arr[i];     int start = 0, ends = n - 1;     while (start != ends) {       if (arr[ends] < arr[start]) {         reverse(arr + start, arr + ends + 1);         break;       } else if (ends == n && arr[ends] > arr[ends - 1]) {         ends--;         start++;       } else if (arr[ends] < arr[ends + 1] && arr[ends] < arr[ends - 1]) {         if (arr[ends] > arr[start]) {           start++;           ends++;         }       } else if (arr[ends] > arr[ends + 1] && arr[ends] < arr[ends - 1]) {         ends++;         start++;       }       ends--;     }     for (int i = 1; i < n; i++) {       if (arr[i] < arr[i - 1]) {         cout <<  no ;         return 0;       }     }     cout <<  yes  << endl          << min(ends + 1, start + 1) <<     << max(ends + 1, start + 1);     return 0;   }


#include <bits/stdc++.h>   int main() {     int n, l;     std::cin >> n >> l;     int *num = new int[n];     int i;     for (i = 0; i < l; i++) {       num[i] = i + 97;     }     while (i < n) {       num[i] = num[i - l];       i++;     }     for (int i = 0; i < n; i++) std::cout << (char)(num[i]);   }