#include <bits/stdc++.h>   using namespace std;   long long t, n, m;   long long pre[405][405], a[405][405], sum[405];   long long get(long long a, long long b, long long c) {     return pre[b][c] - pre[a - 1][c];   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cin >> t;     while (t--) {       cin >> n >> m;       for (long long i = 1; i <= n; i++) {         for (long long j = 1; j <= m; j++) {           char f;           cin >> f;           a[i][j] = f -  0 ;           pre[i][j] = pre[i - 1][j] + a[i][j];         }       }       long long res = 1000000000000000000;       for (long long l = 1; l <= n - 4; l++) {         for (long long r = l + 4; r <= n; r++) {           long long mx = -1000000000000000000;           for (long long k = 1; k <= 3; k++)             sum[k] = sum[k - 1] + get(l + 1, r - 1, k) + (2 - a[l][k] - a[r][k]);           for (long long k = 4; k <= m; k++) {             sum[k] = sum[k - 1] + get(l + 1, r - 1, k) + (2 - a[l][k] - a[r][k]);             mx = max(mx, sum[k - 3] - (r - l - 1) + get(l + 1, r - 1, k - 3));             res = min(res, sum[k - 1] + (r - l - 1) - get(l + 1, r - 1, k) - mx);           }         }       }       cout << res <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   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 - 48, ch = getchar();     }     return x * f;   }   bool vis[1000100];   int c[100];   int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }   int main() {     srand(time(0));     int n = read(), que = 60;     int l = 0, r = 1e9, op;     while (l <= r) {       int mid = (l + r) / 2;       que--;       printf( > %d n , mid);       fflush(stdout);       scanf( %d , &op);       if (op)         l = mid + 1;       else         r = mid - 1;     }     int mx = l;     for (int i = 1; i <= que && i <= n; i++) {       int p = rand() * rand() % n + 1;       while (vis[p]) p = rand() * rand() % n + 1;       vis[p] = 1;       printf( ? %d n , p);       fflush(stdout);       scanf( %d , &c[i]);     }     int N = min(que, n);     sort(c + 1, c + N + 1);     int g = mx - c[1];     for (int i = 2; i <= N; i++) {       if (c[i] == mx) continue;       g = gcd(g, mx - c[i]);       g = gcd(g, c[i] - c[i - 1]);     }     printf( ! %d %d n , mx - (n - 1) * g, g);     fflush(stdout);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[100002], b[100000];   int main() {     int n;     cin >> n;     set<pair<int, int> > c;     c.clear();     for (int i = 1; i <= n; i++) {       int x, y;       cin >> x >> y;       pair<int, int> a = make_pair(x, y);       c.insert(a);     }     n = 0;     set<pair<int, int> >::iterator j;     for (j = c.begin(); j != c.end(); j++) {       n++;       a[n] = (*j).first;       b[n] = (*j).second;     }     int ans = 0, max = -2000000000;     for (int i = 1; i <= n; i++) {       if (b[i] < max) ans++;       if (b[i] > max) max = b[i];     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   double x[1010], y[1010];   bool vis[1010];   int main() {     int n, cnt = 0;     double x0, y0;     scanf( %d%lf%lf , &n, &x0, &y0);     for (int i = 0; i < n; i++) {       scanf( %lf%lf , &x[i], &y[i]);     }     for (int i = 0; i < n; i++) {       double x1 = x[i], y1 = y[i];       if (vis[i])         continue;       else         cnt++;       vis[i] = 1;       for (int j = 0; j < n; j++) {         if (vis[j]) continue;         if (x1 == x0 && x[j] == x0)           vis[j] = 1;         else if (y1 == y0 && y[j] == y0)           vis[j] = 1;         else if (fabs((y[j] - y0) / (y1 - y0) - (x[j] - x0) / (x1 - x0)) < 1e-9)           vis[j] = 1;       }     }     printf( %d n , cnt);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int arr[2], x;     cin >> arr[0] >> arr[1] >> x;     vector<int> v;     int curr = 1;     if (x % 2 == 1) {       v.push_back(curr);       arr[curr]--;       curr ^= 1;       for (int i = 0; i < x; i++) {         v.push_back(curr);         arr[curr]--;         curr ^= 1;       }       if (arr[1] > 0) {         while (arr[1]--) {           cout <<  1 ;         }       }       for (int i = 0; i < v.size(); i++) cout << v[i];       if (arr[0] > 0) {         while (arr[0]--) cout <<  0 ;       }     } else {       if (arr[0] <= arr[1]) {         v.push_back(curr);         arr[curr]--;         curr ^= 1;         for (int i = 0; i < x; i++) {           v.push_back(curr);           arr[curr]--;           curr ^= 1;         }         if (arr[1] > 0) {           while (arr[1]--) cout <<  1 ;         }         for (int i = 0; i < v.size() - 1; i++) cout << v[i];         if (arr[0] > 0) {           while (arr[0]--) cout <<  0 ;         }         cout <<  1 ;       } else {         curr = 0;         v.push_back(curr);         arr[curr]--;         curr ^= 1;         for (int i = 0; i < x; i++) {           v.push_back(curr);           arr[curr]--;           curr ^= 1;         }         if (arr[0] > 0) {           while (arr[0]--) cout <<  0 ;         }         for (int i = 0; i < v.size() - 1; i++) cout << v[i];         if (arr[1] > 0) {           while (arr[1]--) cout <<  1 ;         }         cout <<  0 ;       }     }     cout << endl;   }


#include <bits/stdc++.h>      using namespace std;      #define ll long long   #define ld long double   #define pii pair <ll, ll>   #define mp make_pair      // const int inf = 1e9 + 111;   const int NMAX = 200111;   const int inf = 1e9 + 7;   const ld eps = 0.00000000001;   const ll mod = 1e9 + 7;      constexpr int64_t MOD = 998244353;      int main() {    cin.tie(0);    cout.tie(0);    cin.sync_with_stdio(0);    cout.sync_with_stdio(0);    cout << setprecision(20) << fixed;       int t;       cin >> t;       for (int i = 0; i < t; ++i) {           int n, k;           cin >> n >> k;           if (k < n) {               if (n % k == 0) {                   cout << 1 << endl;               } else {                   cout << 2 << endl;               }           } else {               cout << (k + n - 1) / n << endl;           }       }       return 0;   }


#include <bits/stdc++.h>   using namespace std;   char s[100050];   bool vis;   int main() {     scanf( %s , s + 1);     int len = strlen(s + 1);     if (len <= 2) {       printf( No n );       return 0;     }     for (int i = 1; i <= len - 2; i++) {       if (s[i] != s[i + 1] && s[i + 1] != s[i + 2] && s[i] != s[i + 2] &&           s[i] !=  .  && s[i + 1] !=  .  && s[i + 2] !=  . ) {         vis = 1;         break;       }     }     if (vis == 1)       printf( Yes n );     else       printf( No n );   }


#include <bits/stdc++.h>   using namespace std;   string s;   long long x;   long long mp[1 << 20];   vector<long long> vec;   long long trans[1 << 20][10];   long long dp[1005][12005];   int main(void) {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> s;     long long n = s.size();     s =  #  + s;     cin >> x;     if (x == 1) {       long long ans = 0;       for (int i = 1; i <= n; i++) {         if (s[i] ==  1 ) ans++;       }       cout << ans << endl;       return 0;     }     long long X = 1 << x;     for (int i = 0; i < X; i++) {       mp[i] = -1;       if (!(i & 1)) continue;       for (int d = 1; d < x; d++) {         if (x % d) continue;         for (int j = 0; j < x; j++) {           if ((i & (1 << j)) && (i & (1 << (j + d)))) goto pass;         }       }       vec.push_back(i);       mp[i] = (int)vec.size() - 1;     pass:;     }     long long m = vec.size();     for (int i = 0; i < m; i++) {       for (int j = 1; j <= 9; j++) {         long long b = vec[i];         b <<= j;         for (int d = 1; d < x; d++) {           if (x % d) continue;           if (b & (1 << d)) {             b %= (1 << d);             break;           }         }         if (b & (1 << x)) {           trans[i][j] = -1;           continue;         }         b %= X;         b |= 1;         trans[i][j] = mp[b];       }     }     for (int i = 0; i <= n; i++) {       for (int j = 0; j < m; j++) {         dp[i][j] = 1e18;       }     }     dp[0][mp[1]] = 0;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         (dp[i + 1][j]) = min((dp[i + 1][j]), (dp[i][j] + 1));         if (trans[j][s[i + 1] -  0 ] != -1)           (dp[i + 1][trans[j][s[i + 1] -  0 ]]) =               min((dp[i + 1][trans[j][s[i + 1] -  0 ]]), (dp[i][j]));       }     }     long long ans = 1e18;     for (int j = 0; j < m; j++) ans = min(ans, dp[n][j]);     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     std::ios_base::sync_with_stdio(false);     std::cin.tie(0);     std::cout.tie(0);     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       vector<int> a(n), b(2 * n);       multiset<int> m;       for (size_t i = 0; i < 2 * n; ++i) m.insert(i + 1);       for (auto& i : a) {         cin >> i;         m.erase(i);       }       bool flg = true;       for (size_t i = 0; i < n; ++i) {         b[2 * i] = a[i];         auto it = upper_bound(m.begin(), m.end(), a[i]);         if (it == m.end()) {           flg = false;           cout << -1 << endl;           break;         }         b[2 * i + 1] = *it;         m.erase(*it);       }       if (!flg) continue;       for (auto& i : b) cout << i <<    ;       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double pi = acos(-1.0);   void solve() {     long long n;     cin >> n;     n = 2 * n;     long double dist, ang;     ang = (360 * 1.0) / (n * 1.0);     ang = ang / 2.0;     long double rad = ang / 180.0;     rad = rad * pi;     dist = tan(rad);     dist = 1.0 / dist;     cout << fixed << setprecision(10) << dist;     cout << endl;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long t = 1;     cin >> t;     while (t--) solve();   }


#include <bits/stdc++.h>   using namespace std;   long long arr[100005], ans[2];   int main() {     int n, m;     scanf( %d%d , &n, &m);     for (int i = 0; i < n; i++) {       scanf( %lld , arr + i);     }     for (int sum = 1; sum <= m << 1; sum++) {       vector<int> vec = {0};       for (int i = 0; i < n; i++) {         vec.push_back(arr[i] % sum);       }       vec.push_back(sum - 1);       sort(vec.begin(), vec.end());       for (int i = n + 1, t = 0; i; i--, t ^= 1) {         int x = max(vec[i - 1], vec[n - t] / 2) + 1, y = min(vec[i], m);         int a = max(x, sum - y), b = min(y, sum - x);         if (a <= b) ans[t] += b - a + 1;       }     }     long long x = ((long long)m * m - ans[0] - ans[1]) / 2;     printf( %lld %lld %lld %lld n , x, x, ans[1], ans[0]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int BLOCK = 250;   const int N = 200100;   const int NB = BLOCK * N;   long long ans = 0ll;   int sm[NB + N], pf[N], n, pr[N];   string s;   int calc(int len, int kol) { return len / kol; }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> s;     n = ((int)s.size());     pf[0] = 0;     for (int i = 1; i <= n; i++) pf[i] = pf[i - 1] + (s[i - 1] ==  1  ? 1 : 0);     for (int k = 1; k < BLOCK; k++) {       for (int i = 0; i <= n; i++) sm[k * pf[i] - i + N] = 0;       for (int i = 0; i <= n; i++) {         int cv = k * pf[i] - i + N;         ans += sm[cv];         sm[cv]++;       }     }     pr[0] = -1;     for (int i = 1; i <= n; i++) {       pr[i] = pr[i - 1];       if (s[i - 1] ==  1 ) pr[i] = i;     }     for (int r = 1; r <= n; r++) {       int i = r;       for (int it = 1; it <= 2 * BLOCK; it++) {         int nw = pr[i];         if (nw < 0) break;         i = nw - 1;         int l = max(0, pr[i]);         int cans = calc(r - l, it) - calc(r - i - 1, it);         int mn = (r - i) / it + bool((r - i) % it > 0);         int mx = (r - l) / it;         mx = min(mx, BLOCK - 1);         cans -= max(0, mx - mn + 1);         ans += cans;       }     }     cout << ans;     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     if (n % 2) {       cout <<  YES  << endl;       for (int i = 1; i <= n; i++) {         if (i % 2)           cout << 2 * i - 1 <<    ;         else           cout << 2 * i <<    ;       }       for (int i = 1; i <= n; i++) {         if (i % 2)           cout << 2 * i <<    ;         else           cout << 2 * i - 1 <<    ;       }       cout << endl;     } else       cout <<  NO  << endl;     return 0;   }


#include <bits/stdc++.h>   inline long long read() {     long long x = 0, f = 1;     char c = getchar();     for (; c >  9  || c <  0 ; c = getchar()) {       if (c ==  - ) f = -1;     }     for (; c >=  0  && c <=  9 ; c = getchar()) {       x = x * 10 + c -  0 ;     }     return x * f;   }   int dp[200005];   int a[85], r[85];   inline void work() {     int n = read(), m = read();     dp[m + 1] = 0;     for (int i = 1; i <= n; i++) a[i] = read(), r[i] = read();     for (int i = m; i; i--) {       dp[i] = dp[i + 1] + 1;       for (int j = 1; j <= n; j++) {         if (a[j] >= i) {           if (a[j] - r[j] <= i) {             dp[i] = std::min(dp[i], dp[std::min(m + 1, a[j] + r[j] + 1)]);           } else {             dp[i] = std::min(                 dp[i], a[j] - r[j] - i + dp[std::min(m + 1, 2 * a[j] - i + 1)]);           }         } else {           if (a[j] + r[j] >= i) {             dp[i] = std::min(dp[i], dp[std::min(m + 1, a[j] + r[j] + 1)]);           }         }       }     }     printf( %d n , dp[1]);   }   int main() {     work();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 2e5 + 10, INF = 1e9;   struct event {     int pos, start, end, val, t, i;     event(int a, int b, int c, int d, int e, int f)         : pos(a), start(b), end(c), val(d), t(e), i(f){};   };   bool comp(event a, event b) {     if (a.pos != b.pos)       return a.pos < b.pos;     else       return a.t < b.t;   }   vector<event> vx, vy;   bool ok[MAXN];   int minx[MAXN], miny[MAXN];   int seg[4 * MAXN];   void clear(int i, int ini, int fim) {     seg[i] = 0;     if (ini == fim)       return;     else {       int mid = (ini + fim) / 2;       clear(i * 2, ini, mid);       clear(i * 2 + 1, mid + 1, fim);     }   }   void update(int i, int ini, int fim, int pos, int val) {     if (pos < ini || pos > fim)       return;     else {       if (ini == fim)         seg[i] = val;       else {         int mid = (ini + fim) / 2;         update(i * 2, ini, mid, pos, val);         update(i * 2 + 1, mid + 1, fim, pos, val);         seg[i] = min(seg[i * 2], seg[i * 2 + 1]);       }     }   }   int query(int i, int ini, int fim, int p, int q) {     if (ini >= p && fim <= q) return seg[i];     if (q < ini || p > fim)       return INF;     else {       int mid = (ini + fim) / 2;       return min(query(i * 2, ini, mid, p, q),                  query(i * 2 + 1, mid + 1, fim, p, q));     }   }   void print(int i, int ini, int fim) {     printf( i %d ini %d fim %d seg %d n , i, ini, fim, seg[i]);     if (ini != fim) {       int mid = (ini + fim) / 2;       print(i * 2, ini, mid);       print(i * 2 + 1, mid + 1, fim);     }   }   int main() {     int n, m, p, q;     scanf( %d %d %d %d , &n, &m, &p, &q);     for (int i = 0, a, b; i < p; i++) {       scanf( %d %d , &a, &b);       vx.push_back(event(a, 0, 0, b, 1, i));       vy.push_back(event(b, 0, 0, a, 1, i));     }     for (int i = 0, a, b, c, d; i < q; i++) {       scanf( %d %d %d %d , &a, &b, &c, &d);       vx.push_back(event(c, b, d, 0, 2, i));       vy.push_back(event(d, a, c, 0, 2, i));       minx[i] = a;       miny[i] = b;     }     sort(vx.begin(), vx.end(), comp);     sort(vy.begin(), vy.end(), comp);     clear(1, 1, max(m, n));     for (int i = 0; i < vx.size(); i++) {       if (vx[i].t == 1) {         update(1, 1, m, vx[i].val, vx[i].pos);       } else {         if (query(1, 1, m, vx[i].start, vx[i].end) >= minx[vx[i].i])           ok[vx[i].i] = 1;       }     }     clear(1, 1, max(m, n));     for (int i = 0; i < vy.size(); i++) {       if (vy[i].t == 1) {         update(1, 1, n, vy[i].val, vy[i].pos);       } else {         if (query(1, 1, n, vy[i].start, vy[i].end) >= miny[vy[i].i])           ok[vy[i].i] = 1;       }     }     for (int i = 0; i < q; i++) {       if (ok[i])         printf( YES n );       else         printf( NO n );     }   }


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


#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-6;   int n, ans;   double a[2000];   struct Line {     double x, y, vx, vy;     void read() {       double t1, t2;       scanf( %lf%lf%lf%lf%lf%lf , &t1, &x, &y, &t2, &vx, &vy);       vx -= x;       vy -= y;       vx /= t2 - t1;       vy /= t2 - t1;       x -= t1 * vx;       y -= t1 * vy;     }   } line[2000];   struct point {     double x, y;     point() {}     point(double x, double y) : x(x), y(y) {}     double det(point res) { return x * res.y - y * res.x; }     bool operator<(const point& rhs) const {       if (abs(x * rhs.y - y * rhs.x) < eps) {         if (abs(x - rhs.x) < eps) return y < rhs.y;         return x < rhs.x;       } else         return x * rhs.y - y * rhs.x < 0;     }   } b[2000];   int main() {     scanf( %d , &n);     if (n) ans = 1;     for (int i = 1; i <= n; i++) line[i].read();     for (int id = 1; id <= n; id++) {       int tot = 0;       for (int j = 1; j <= n; j++)         if (id != j) {           double vx = line[j].vx - line[id].vx, vy = line[j].vy - line[id].vy;           double t = fabs(vx) > eps   ? (line[j].x - line[id].x) / vx                      : fabs(vy) > eps ? (line[j].y - line[id].y) / vy                                       : 0;           if (fabs(line[j].x - line[id].x - t * vx) <= eps &&               fabs(line[j].y - line[id].y - t * vy) <= eps)             a[++tot] = t, b[tot] = point(vx, vy);         }       sort(a + 1, a + 1 + tot);       int cnt = 0;       for (int i = 1; i <= tot; i++) {         if (i == 1 || a[i] - a[i - 1] >= eps)           cnt = 1;         else           cnt++;         ans = max(ans, cnt + 1);       }       sort(b + 1, b + tot + 1);       cnt = 0;       for (int i = 1; i <= tot; i++) {         if (i == 1 || fabs(b[i].det(b[i - 1])) > eps)           cnt = 1;         else if (fabs(b[i].x - b[i - 1].x) > eps ||                  fabs(b[i].y - b[i - 1].y) > eps)           cnt++;         ans = max(ans, cnt + 1);       }     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int k, n, w;     cin >> k >> n >> w;     int s = 0;     for (int i = 1; i <= w; i++) {       s += i * k;     }     if (n < s)       cout << s - n;     else       cout << 0;     return 0;   }


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


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   #pragma GCC target( sse2 )   #pragma GCC target( avx2 )   using namespace std;   inline void opting() {     ios_base::sync_with_stdio(false);     cout.tie(0);     cin.tie(0);   }   int inp() {     int x;     cin >> x;     return x;   }   void make_unique(vector<int> &vec, bool sorted = false) {     if (!sorted) sort((vec).begin(), (vec).end());     vec.resize(unique((vec).begin(), (vec).end()) - vec.begin());   }   const int SQRT = 450, lg = 18 + 2, inlim = 2147483647;   const int maxn = 2e6 + 69, CL = 40, delta = 1e9 + 9, inf = 1e9 + 420;   int last[4 * maxn];   int n;   struct seg_node {     int max_ones = 0;     int pref = 0;     int suff = 0;     int sz = 0;     int l_kid, r_kid;   } emp;   inline seg_node merge_nodes(const seg_node &A, const seg_node &B) {     seg_node X;     X.max_ones = max({A.max_ones, B.max_ones, A.suff + B.pref});     X.sz = A.sz + B.sz;     X.suff = B.suff;     X.pref = A.pref;     if (A.pref == A.sz) X.pref += B.pref;     if (B.suff == B.sz) X.suff += A.suff;     return X;   }   seg_node seg[4 * maxn];   int cur_node = 0;   pair<int, int> kid[maxn];   void show(seg_node A) {     cout << A.max_ones <<     << A.pref <<     << A.suff <<     << A.sz <<   <>            << endl;   }   void add_(int id, int idx, const int cheat, int L = 0, int R = n) {     if (L <= idx and idx < R) {       if (R - L == 1)         seg[id].sz = seg[id].pref = seg[id].suff = seg[id].max_ones = 1;       else {         int mid = (L + R) >> 1;         int lt = seg[cheat].l_kid;         int rt = seg[cheat].r_kid;         if (idx < mid) {           lt = cur_node++;           add_(lt, idx, seg[cheat].l_kid, L, mid);         } else {           rt = cur_node++;           add_(rt, idx, seg[cheat].r_kid, mid, R);         }         seg[id] = merge_nodes(seg[lt], seg[rt]);         seg[id].l_kid = lt;         seg[id].r_kid = rt;       }     }   }   seg_node get_(int id, int l, int r, int L = 0, int R = n) {     if (R <= l or r <= L) return emp;     if (l <= L and R <= r) return seg[id];     int mid = (L + R) >> 1;     seg_node A = get_(seg[id].l_kid, l, r, L, mid);     seg_node B = get_(seg[id].r_kid, l, r, mid, R);     return merge_nodes(A, B);   }   int prime_set(int L = 0, int R = n) {     int id = cur_node++;     seg[id].sz = R - L;     if (R == L + 1) return id;     int mid = (L + R) >> 1;     seg[id].l_kid = prime_set(L, mid);     seg[id].r_kid = prime_set(mid, R);     return id;   }   int starter[maxn];   inline bool check(int l, int r, int w, int H_key) {     return get_(starter[H_key], l, r).max_ones >= w;   }   int bns(int l, int r, int w) {     int st = 0;     int en = n;     while (en - st > 1) {       int mid = (st + en) >> 1;       if (check(l, r, w, mid))         st = mid;       else         en = mid;     }     return st;   }   vector<pair<int, int> > v;   void input() {     cin >> n;     for (int i = 0; i < n; i++) v.push_back(make_pair(inp(), i));   }   void predo() {     prime_set();     sort((v).begin(), (v).end());     int prev = 0;     for (int i = n - 1; i > -1; i--) {       starter[i] = cur_node++;       add_(cur_node - 1, v[i].second, prev);       prev = starter[i];     }   }   void solve() {     int m = inp();     while (m--) {       int l, r, w;       cin >> l >> r >> w;       l--;       cout << v[bns(l, r, w)].first <<    ;     }   }   int main() {     opting();     input();     predo();     solve();   }


#include <bits/stdc++.h>   using namespace std;   namespace red {   inline long long read() {     long long x = 0;     char f = 0, ch;     for (ch = getchar(); (ch <  0  || ch >  9 ) && ch !=  - ; ch = getchar())       ;     if (ch ==  - ) f = 1, ch = getchar();     while (ch >=  0  && ch <=  9 ) {       x = (x << 1) + (x << 3) + ch -  0 ;       ch = getchar();     }     return f ? -x : x;   }   const long long N = 1e5 + 10;   long long T, n;   long long a[N], c[N], pos[N], num;   struct node {     long long l, r, d;   } e[N];   long long tot;   inline void main() {     T = read();     while (T--) {       n = read();       num = tot = 0;       for (long long i = 1; i <= n; ++i) a[i] = read(), c[++num] = a[i];       sort(c + 1, c + num + 1);       for (long long i = 1; i <= n; ++i) {         for (long long j = 1; j <= n; ++j) {           if (a[i] == c[j]) {             a[i] = j;             c[j] = 1e9 + 10;             break;           }         }       }       for (long long pos, i = 1; i <= n; ++i) {         pos = i;         for (long long j = i; j <= n; ++j) {           if (a[j] == i) {             pos = j;             break;           }         }         if (pos == i) continue;         e[++tot].l = i, e[tot].r = pos, e[tot].d = pos - i;         for (long long j = pos; j > i; --j) a[j] = a[j - 1];         a[i] = i;       }       printf( %lld n , tot);       for (long long i = 1; i <= tot; ++i) {         printf( %lld %lld %lld n , e[i].l, e[i].r, e[i].d);       }     }   }   }  // namespace red   signed main() {     red::main();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 2147483647;   const double PI = 3.141592653589793;   int n, k, l, a[105], used[105], suma, i, j, q, b;   double maxx, minn;   vector<int> wek;   int main() {     scanf( %d %d , &n, &k);     l = n / k;     for (i = 0; i < n; i++) {       scanf( %d , &a[i]);       used[i] = 0;     }     maxx = -INF;     minn = INF;     scanf( %d , &q);     for (j = 0; j < q; j++) {       suma = 0;       for (i = 0; i < l; i++) {         scanf( %d , &b);         b--;         suma += a[b];         used[b] = 1;       }       maxx = max(maxx, suma * 1.0 / l);       minn = min(minn, suma * 1.0 / l);     }     wek.resize(0);     for (i = 0; i < n; i++)       if (!used[i]) wek.push_back(a[i]);     sort(wek.begin(), wek.end());     if (wek.size() == n - k * l) {       printf( %.8lf %.8lf n , minn, maxx);       return 0;     }     suma = 0;     for (i = 0; i < l; i++) suma += wek[i];     maxx = max(maxx, suma * 1.0 / l);     minn = min(minn, suma * 1.0 / l);     suma = 0;     for (i = wek.size() - 1; i >= (int)wek.size() - l; i--) suma += wek[i];     maxx = max(maxx, suma * 1.0 / l);     minn = min(minn, suma * 1.0 / l);     printf( %.8lf %.8lf n , minn, maxx);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const unsigned long long hash1 = 201326611;   const double eps = 1e-8;   const long long INF = 0x3f3f3f3f3f3f3f3f;   const int inf = 0x3f3f3f3f;   const long long mod = 1e9 + 7;   const int N = 1e5 + 10;   const int M = 12;   const int dif = 26;   const double PI = acos(-1.0);   inline void Mod(long long& x) {     if (x >= mod) x -= mod;   }   void BinaryBitset(int n) { cout << bitset<sizeof(int) * 4>(n) << endl; }   struct node {     long long l, r, len;   } p[22];   void init() {     p[1].l = 1;     p[1].r = 9;     p[1].len = 9;     for (int i = 2; i <= 18; i++) {       p[i].l = p[i - 1].l * 10;       p[i].r = p[i - 1].r * 10 + 9;       p[i].len = p[i - 1].len * 10;     }   }   int q;   long long k;   bool isOK(long long x, long long k) {     long long ans = 0;     for (int i = 1; i <= 20; i++) {       if (x > p[i].r) {         long long left = x - p[i].r + 1, right = x - p[i].l + 1;         ans += p[i].len * i * (right + left) / 2;       } else {         long long left = 1, right = x - p[i].l + 1;         ans += (right - left + 1) * i * (left + right) / 2;         break;       }       if (ans >= k) return 1;     }     return ans >= k;   }   long long getsum(long long x) {     long long ans = 0;     for (int i = 1; i <= 20; i++) {       if (x > p[i].r) {         long long left = x - p[i].r + 1, right = x - p[i].l + 1;         ans += p[i].len * i * (right + left) / 2;       } else {         long long left = 1, right = x - p[i].l + 1;         ans += (right - left + 1) * i * (left + right) / 2;         return ans;       }     }     return ans;   }   bool isOK2(long long x, long long k) {     long long ans = 0;     for (int i = 1; i <= 20; i++) {       if (x > p[i].r) {         ans += p[i].len * i;       } else {         long long left = 1, right = x - p[i].l + 1;         ans += (right - left + 1) * i;         break;       }       if (ans >= k) return 1;     }     return ans >= k;   }   long long getsum2(long long x) {     long long ans = 0;     for (int i = 1; i <= 20; i++) {       if (x > p[i].r) {         ans += p[i].len * i;       } else {         long long left = 1, right = x - p[i].l + 1;         ans += (right - left + 1) * i;         return ans;       }     }   }   int main() {     init();     scanf( %d , &q);     while (q--) {       scanf( %lld , &k);       long long left = 1, right = 482720320;       while (left <= right) {         long long mid = (left + right) >> 1;         if (isOK(mid, k))           right = mid - 1;         else           left = mid + 1;       }       k -= getsum(left - 1);       left = 1;       right = 1e10;       while (left <= right) {         long long mid = (left + right) >> 1;         if (isOK2(mid, k))           right = mid - 1;         else           left = mid + 1;       }       k -= getsum2(left - 1);       vector<int> ans;       long long x = left;       while (x) {         ans.push_back(x % 10);         x /= 10;       }       int j = 0, h = ans.size() - 1;       while (j <= h) {         swap(ans[j], ans[h]);         j++;         h--;       }       printf( %d n , ans[k - 1]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   map<int, int> card;   void init() {     for (int i = 6, j = 1; i < 15; i++, j++) card.insert(make_pair(i, j));   }   int isCard(char num) {     int res = 0;     if (num >=  0  && num <=  9 )       res = num -  0 ;     else {       if (num ==  T )         res = 10;       else if (num ==  J )         res = 11;       else if (num ==  Q )         res = 12;       else if (num ==  K )         res = 13;       else         res = 14;     }     return res;   }   int main() {     char mn;     string s;     cin >> s;     mn = s[0];     cin >> s;     int id[2];     char ch[2];     id[0] = isCard(s[0]);     ch[0] = s[1];     cin >> s;     id[1] = isCard(s[0]);     ch[1] = s[1];     map<int, bool> mp;     mp.insert(make_pair(mn, true));     if (mp.find(ch[0]) != mp.end() && mp.find(ch[1]) == mp.end())       cout <<  YES ;     else if (mp.find(ch[0]) == mp.end() && mp.find(ch[1]) != mp.end())       cout <<  NO ;     else if (ch[0] != ch[1])       cout <<  NO ;     else if (id[0] > id[1])       cout <<  YES ;     else       cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     int n, k;     cin >> n >> k;     vector<int> table(n), d = {119, 18, 93, 91, 58, 107, 111, 82, 127, 123};     for (int i = 0; i < n; ++i) {       string tmp;       cin >> tmp;       reverse(tmp.begin(), tmp.end());       for (int j = 0; j < 7; ++j) {         if (tmp[j] ==  1 ) {           table[i] += (1 << j);         }       }     }     vector<vector<int>> dp(n + 1, vector<int>(k + 1, -1));     vector<vector<int>> par(n + 1, vector<int>(k + 1, -1));     dp[n][0] = 0;     for (int i = n - 1; i >= 0; --i) {       for (int j = 0; j <= k; ++j) {         for (int k = 9; k >= 0; --k) {           int cnt = __builtin_popcount(d[k] ^ table[i]);           if (j >= cnt && (d[k] | table[i]) == d[k] && dp[i + 1][j - cnt] != -1) {             dp[i][j] = k;             par[i][j] = j - cnt;             break;           }         }       }     }     if (dp[0][k] == -1) {       cout << -1 <<   n ;     } else {       int i = 0, j = k;       while (i < n && j >= 0) {         cout << dp[i][j];         j = par[i][j];         ++i;       }       cout <<   n ;     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     int N = 1000001;     vector<int> count(N);     long long n;     cin >> n;     vector<long long> a(n), ans;     long long sum = 0, i, j, k;     for (i = 0; i < n; i++) cin >> a[i], sum += a[i], count[a[i]]++;     for (i = 0; i < n; i++)       if ((sum - a[i]) % 2 == 0 && (sum - a[i]) / 2 < N &&           (count[(sum - a[i]) / 2] > 1 ||            (count[(sum - a[i]) / 2] == 1 && a[i] != (sum - a[i]) / 2)))         ans.push_back(i + 1);     cout << ans.size() << endl;     for (auto x : ans) cout << x <<    ;     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const ll M = 1000000007;   const ll M1 = 998244353;   using vl = vector<ll>;   using pll = pair<ll, ll>;   ll power(ll x, ll y) {     if (y == 0) return 1;     ll res = power(x, y / 2);     res = (res * res);     if (y & 1) res = (res * x);     return res;   }   ll powermod(ll x, ll y, ll mod) {     if (y == 0) return 1;     ll res = powermod(x, y / 2, mod);     res = (res * res) % mod;     if (y & 1) res = (res * x) % mod;     return res;   }   ll findxor(ll a) {     switch (a & 3) {       case 0:         return a;       case 1:         return 1;       case 2:         return a + 1;       case 3:         return 0;     }     return -1;   }   int n;   vector<int> visi;   vector<string> gr;   void dfs(int node, vector<int> &rec_visit) {     visi[node] = 1;     rec_visit.push_back(node);     for (int con_node = 0; con_node < n; con_node++) {       if (visi[con_node] || gr[node][con_node] ==  0 ) continue;       dfs(con_node, rec_visit);     }   }   void solve() {     cin >> n;     int ans[n];     for (int i = 0; i < n; i++) cin >> ans[i];     gr.resize(n);     visi.resize(n, 0);     for (int i = 0; i < n; i++) cin >> gr[i];     for (int i = 0; i < n; i++) {       if (visi[i]) continue;       vector<int> rec_visit;       dfs(i, rec_visit);       vector<int> val;       for (int j = 0; j < rec_visit.size(); j++) val.push_back(ans[rec_visit[j]]);       sort(val.begin(), val.end());       sort(rec_visit.begin(), rec_visit.end());       for (int j = 0; j < rec_visit.size(); j++) ans[rec_visit[j]] = val[j];     }     for (int i = 0; i < n; i++) cout << ans[i] <<    ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int t = 1;     for (int i = 1; i <= t; i++) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char s[50], c[50];   int t1 = 0, t2 = 0;   int main() {     cin >> s >> c;     for (int i = 0; i < strlen(s); i += 2) {       if ((s[i] ==  8  && c[i] ==  [ ) || (s[i] ==  [  && c[i] ==  ( ) ||           (s[i] ==  (  && c[i] ==  8 ))         t1++;       else if (s[i] != c[i])         t2++;     }     if (t1 > t2)       cout <<  TEAM 1 WINS ;     else if (t2 > t1)       cout <<  TEAM 2 WINS ;     else       cout <<  TIE ;   }


#include <bits/stdc++.h>   using namespace std;   long long f[16][16][1 << 17];   int b[16];   long long dp(int x, int Mx, int sum, bool flag) {     if (x == 0) {       return (sum >> Mx) & 1;     }     if (!flag && f[x][Mx][sum] != -1) return f[x][Mx][sum];     int lm = flag ? b[x] : 15;     long long ans = 0;     for (int i = 0; i <= lm; i++) {       int tmp = sum;       if (x <= 4) tmp |= i << ((x - 1) * 4);       ans += dp(x - 1, max(Mx, i), tmp, flag && i == lm);     }     return flag ? ans : f[x][Mx][sum] = ans;   }   long long solve(long long x) {     int p = 0;     memset(b, 0, sizeof(b));     while (x) {       b[++p] = x % 16;       x /= 16;     }     return dp(p, 0, 0, 1);   }   int main() {     int _;     scanf( %d , &_);     memset(f, -1, sizeof(f));     while (_--) {       long long l, r;       scanf( %I64x%I64x , &l, &r);       printf( %I64d n , solve(r) - solve(l - 1));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n;     long double f;     int i;     cin >> n;     long long int m = n;     for (i = 1; n / pow(10, i) >= 1; ++i)       ;     i--;     f = n / pow(10, i);     if (ceil(f) == f) f++;     f = ceil(f);     n = f * pow(10, i);     cout << n - m;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long A[100001], B[100001];   bool valid[100001];   int main() {     ios::sync_with_stdio(0);     int n;     cin >> n;     for (int i = 0; i < n; ++i) cin >> A[i];     for (int i = 0; i < n; ++i) cin >> B[i];     long long ac = 0, bc = 0;     long long mini = (1LL << 62);     for (int i = 0; i < n; ++i) {       ac += A[i];       bc += B[i];       mini = min(mini, ac - bc);     }     for (int i = 0; i < n; ++i) {       valid[i] = mini >= 0;       mini -= A[i] - B[i];     }     mini = (1LL << 62);     ac = bc = 0;     for (int i = 0; i < n; ++i) {       ac += A[n - i - 1];       bc += B[(n - i - 2 + n) % n];       mini = min(mini, ac - bc);     }     for (int i = 0; i < n; ++i) {       assert(mini <= 0);       valid[n - i - 1] |= mini >= 0;       mini -= A[n - i - 1] - B[(n - i - 2 + n) % n];     }     bool first = true;     int ans = 0;     for (int i = 0; i < n; ++i) ans += valid[i];     cout << ans << endl;     for (int i = 0; i < n; ++i)       if (valid[i]) {         if (not first) cout <<    ;         cout << i + 1;         first = false;       }     cout << endl;   }


#include <bits/stdc++.h>   const long long mod = 998244353;   const int kN = 5e3 + 10;   int n, a[kN], lim[kN];   long long f[kN], fac[kN], invfac[kN];   inline int read() {     int f = 1, w = 0;     char ch = getchar();     for (; !isdigit(ch); ch = getchar())       if (ch ==  - ) f = -1;     for (; isdigit(ch); ch = getchar()) {       w = (w << 3) + (w << 1) + (ch ^  0 );     }     return f * w;   }   void Chkmax(int &fir_, int sec_) {     if (sec_ > fir_) fir_ = sec_;   }   void Chkmin(int &fir_, int sec_) {     if (sec_ < fir_) fir_ = sec_;   }   long long QPow(long long x_, long long y_) {     x_ %= mod;     long long ret = 1;     for (; y_; y_ >>= 1ll) {       if (y_ & 1) ret = ret * x_ % mod;       x_ = x_ * x_ % mod;     }     return ret;   }   long long A(long long n_, long long m_) {     if (n_ < 0 || m_ < 0 || m_ > n_) return 0;     return 1ll * fac[n_] * invfac[n_ - m_] % mod;   }   void Prepare() {     n = read();     invfac[0] = fac[0] = 1;     for (int i = 1; i <= n; ++i) {       a[i] = read();       fac[i] = 1ll * fac[i - 1] * i % mod;       invfac[i] = QPow(fac[i], mod - 2);     }     std::sort(a + 1, a + n + 1);     for (int i = 1, j = 0; i <= n; ++i) {       while (j <= n && 2ll * a[j] <= 1ll * a[i]) ++j;       --j;       lim[i] = j;     }   }   int main() {     Prepare();     if (lim[n] != n - 1) {       printf( 0 n );       return 0;     }     f[0] = 1, lim[0] = -1;     for (int i = 1; i <= n; ++i) {       for (int j = 0; j <= lim[i]; ++j) {         f[i] += 1ll * f[j] *                 A(1ll * n - 2ll - lim[j], 1ll * lim[i] - lim[j] - 1ll) % mod;         f[i] %= mod;       }     }     printf( %lld n , f[n]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 109;   int n, suma, K, sumb, f[10086][N], ans = 0;   struct node {     int a, b;   } c[N];   bool cmp(const node& a, const node& b) { return a.b > b.b; }   int main() {     scanf( %d , &n);     for (register int i = 1; i <= n; i++) scanf( %d , &c[i].a), suma += c[i].a;     for (register int i = 1; i <= n; i++) scanf( %d , &c[i].b);     sort(c + 1, c + n + 1, cmp);     while (sumb < suma) sumb += c[++K].b;     printf( %d  , K);     memset(f, 128, sizeof(f));     f[0][0] = 0;     for (register int i = 1; i <= n; i++)       for (register int j = sumb; j >= c[i].b; j--)         for (register int k = 1; k <= K; k++)           f[j][k] = max(f[j][k], f[j - c[i].b][k - 1] + c[i].a);     for (register int j = suma; j <= sumb; j++) ans = max(ans, f[j][K]);     printf( %d , suma - ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   pair<long long, long long> a[100005];   long long pymax[100005], pymin[100005];   long long symax[100005], symin[100005];   bool trial(long long x) {     for (int i = 0; i < n; i++) {       symax[i] = pymax[i] = a[i].second - x;       symin[i] = pymin[i] = a[i].second + x;     }     for (int i = 1; i < n; i++) {       pymax[i] = max(pymax[i], pymax[i - 1]);       pymin[i] = min(pymin[i], pymin[i - 1]);     }     for (int i = n - 2; i >= 0; i--) {       symax[i] = max(symax[i], symax[i + 1]);       symin[i] = min(symin[i], symin[i + 1]);     }     int e = 0;     for (int i = 0; i < n; i++) {       while (e < n && a[e].first <= a[i].first + x * 2) {         e++;       }       long long maxv = -1e18, minv = 1e18;       if (i) maxv = max(maxv, pymax[i - 1]), minv = min(minv, pymin[i - 1]);       if (e < n) maxv = max(maxv, symax[e]), minv = min(minv, symin[e]);       if (maxv <= minv) {         return 1;       }     }     return 0;   }   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       int x, y;       scanf( %d %d , &x, &y);       a[i] = pair<long long, long long>(x + y, x - y);       a[i].first *= 2ll;       a[i].second *= 2ll;     }     sort(a, a + n);     long long s = 0, e = 1e10;     while (s != e) {       long long m = (s + e) / 2;       if (trial(m))         e = m;       else         s = m + 1;     }     printf( %.10f , s * 0.5);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, a[1007];     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i];     int ans, min = 10000007, sum = 0;     for (int i = 1; i <= 100; i++) {       sum = 0;       for (int j = 0; j < n; j++) {         if (a[j] > i + 1)           sum += a[j] - i - 1;         else if (a[j] < i - 1)           sum += i - 1 - a[j];       }       if (min > sum) min = sum, ans = i;     }     cout << ans <<     << min << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string s;   const int maxN = 1000010;   int len;   int ra[maxN], tra[maxN], sa[maxN], tmpsa[maxN], cnt[maxN];   void countSort(int k) {     int maxr = max(300, len);     memset(cnt, 0, sizeof(cnt[0]) * (maxr + 5));     for (int i = 0; i < len; i++) cnt[sa[i] + k < len ? ra[sa[i] + k] : 0]++;     for (int i = 0, t, sum = 0; i < maxr; i++) t = cnt[i], cnt[i] = sum, sum += t;     for (int i = 0; i < len; i++)       tmpsa[cnt[sa[i] + k < len ? ra[sa[i] + k] : 0]++] = sa[i];     for (int i = 0; i < len; i++) sa[i] = tmpsa[i];   }   void buildsa() {     for (int i = 0; i < len; i++) ra[i] = s[i], sa[i] = i;     for (int k = 1; k < len; k <<= 1) {       countSort(k);       countSort(0);       int r = 0;       tra[sa[0]] = 0;       for (int i = 1; i < len; i++) {         int t1 = (sa[i] + k < len ? ra[sa[i] + k] : 0);         int t2 = (sa[i - 1] + k < len ? ra[sa[i - 1] + k] : 0);         tra[sa[i]] = (ra[sa[i]] == ra[sa[i - 1]] && t1 == t2) ? r : ++r;       }       for (int i = 0; i < len; i++) ra[i] = tra[i];       if (ra[sa[len - 1]] == len - 1) break;     }     string os = s;   }   int phi[maxN], LCP[maxN];   void computeLCP() {     phi[sa[0]] = -1;     for (int i = 1; i < len; i++) phi[sa[i]] = sa[i - 1];     int L = 0;     for (int i = 0; i < len; i++) {       if (phi[i] == -1) {         LCP[ra[i]] = 0;         continue;       }       while (L < len && s[i + L] == s[phi[i] + L]) L++;       int TL = L;       LCP[ra[i]] = TL;       L = max(L - 1, 0);     }   }   int tlft[maxN], trgt[maxN];   void hgram(int data[], int n) {     data[0] = -1;     data[n + 1] = -1;     stack<int> bosta;     bosta.push(0);     for (int i = 1; i <= n + 1; i++) {       while (data[i] < data[bosta.top()]) {         trgt[bosta.top()] = i;         bosta.pop();       }       bosta.push(i);     }     bosta.push(n + 1);     for (int i = n + 1; i >= 0; i--) {       while (data[i] < data[bosta.top()]) {         tlft[bosta.top()] = i;         bosta.pop();       }       bosta.push(i);     }   }   int cross[100100];   long long sum[100010];   vector<pair<long long, pair<long long, long long> > > vv[100010];   void qry(int k) {     for (int i = 1; i < len; i++) {       if (i >= cross[LCP[i]]) {         cross[LCP[i]] = max(cross[LCP[i]], trgt[i]);         long long range = trgt[i] - tlft[i];         long long occ =             min(LCP[i], min(LCP[i] - LCP[tlft[i]], LCP[i] - LCP[trgt[i]]));         long long gain = occ * range;         if (gain) {           vv[tlft[i]].push_back(make_pair(LCP[i] - occ, make_pair(occ, gain)));           sum[tlft[i]] += gain;         }       }     }     long long tot = 0;     for (int i = 1; i < len; i++) {       if (tot + sum[i] >= k) {         sort(vv[i].begin(), vv[i].end());         for (int j = 0; j < vv[i].size(); j++) {           long long cur = vv[i][j].second.second;           if (tot + cur >= k) {             long long st = vv[i][j].first;             long long oc = vv[i][j].second.first;             long long cnt = cur / oc;             long long need = k - tot;             long long pos = ceil(need / (1.00 * cnt));             cout << s.substr(sa[i], st + pos);             return;           }         }         return;       }       tot += sum[i];       long long exgain = len - 1 - sa[i];       long long repitition = LCP[i];       if (i < len - 1) repitition = max(repitition, (long long)LCP[i + 1]);       exgain -= repitition;       if (tot + exgain >= k) {         long long need = k - tot;         cout << s.substr(sa[i], repitition + need) << endl;         return;       }       tot += exgain;     }     cout <<  No such line.  << endl;   }   int main() {     cin >> s;     s +=  & ;     len = s.size();     buildsa();     computeLCP();     hgram(LCP, len - 1);     int k;     cin >> k;     qry(k);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     cout << n << endl;     for (int i = 1; i <= n; ++i) cout <<  1  ;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6 + 20;   int a[105];   int u[105], res[105];   int main() {     int n, m;     scanf( %d%d , &n, &m);     for (int i = 0; i < m; i++) {       scanf( %d , &a[i]);     }     int pos = a[0], ans = 1;     while (ans < m) {       if (a[ans] > pos) {         if (res[pos] == 0) {           if (u[a[ans] - pos]) {             puts( -1 );             return 0;           }           res[pos] = a[ans] - pos;         } else {           if (a[ans] % n != (res[pos] + pos) % n) {             puts( -1 );             return 0;           }         }         u[a[ans] - pos] = 1;       } else {         if (res[pos] == 0) {           if (u[a[ans] + n - pos]) {             puts( -1 );             return 0;           }           res[pos] = a[ans] + n - pos;         } else {           if (a[ans] % n != (res[pos] + pos) % n) {             puts( -1 );             return 0;           }         }         u[a[ans] + n - pos] = 1;       }       pos = a[ans++];     }     for (int i = 1; i <= n; i++) {       if (res[i] == 0) {         for (int j = 1; j <= n; j++) {           if (u[j] == 0) {             res[i] = j;             u[j] = 1;             break;           }         }       }       printf( %d  , res[i]);     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   long long a[10], n, rem[10], par[10], res = N, rem_factors[10], factors[10];   inline bool is_prime(long long u) {     if (u == 1) return false;     if (u == 2) return true;     if (u % 2 == 0) return false;     for (long long i = 3; i * i <= u; i += 2)       if (u % i == 0) return false;     return true;   }   int get(long long u) {     if (u == 1) return 0;     if (is_prime(u)) return 1;     int res = 0;     while (u % 2 == 0) {       u /= 2;       res++;     }     if (u == 1) return res;     if (is_prime(u)) {       return res + 1;     }     for (long long i = 3; i * i <= u; i += 2) {       while (u % i == 0) {         res++;         u /= i;       }     }     if (u > 2) res++;     return res;   }   int PRIME[10];   void backtrack(int idx) {     if (idx == n) {       int val = 0, cnt_par = 0;       for (int i = 0; i < n; i++) {         if (!PRIME[i]) val += rem_factors[i];         cnt_par += (par[i] != -1);       }       if (n - cnt_par > 1)         res = min(res, val + n + 1);       else         res = min(res, val + n);       return;     }     for (int i = idx + 1; i < n; i++) {       if (rem[i] >= a[idx] && a[i] > a[idx] && rem[i] % a[idx] == 0) {         rem[i] /= a[idx];         rem_factors[i] -= factors[idx];         par[idx] = i;         backtrack(idx + 1);         rem_factors[i] += factors[idx];         par[idx] = -1;         rem[i] *= a[idx];       }     }     backtrack(idx + 1);   }   int main() {     ios_base::sync_with_stdio(false);     scanf( %d , &n);     memset(par, -1, sizeof(par));     for (int i = 0; i < n; i++) scanf( %lld , &a[i]);     sort(a, a + n);     for (int i = 0; i < n; i++) rem[i] = a[i];     for (int i = 0; i < n; i++) PRIME[i] = is_prime(a[i]);     for (int i = 0; i < n; i++) {       rem_factors[i] = get(a[i]);       factors[i] = rem_factors[i];     }     backtrack(0);     printf( %d n , res);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   const long long inf = 1e12;   int n, h[N], w[N], u, v;   long long ans, f[N][2];   vector<int> g[N];   void dfs(int u, int fa) {     vector<long long> vec;     long long sum = 0;     for (auto v : g[u]) {       if (v ^ fa) {         dfs(v, u);         sum += f[v][0];         vec.push_back(f[v][1] - f[v][0]);       }     }     sort(vec.begin(), vec.end());     for (int t = 0; t < 2; ++t) {       f[u][t] = inf;       if (u > 1 && ((!t && h[fa] > h[u]) || (t && h[fa] < h[u]))) {         continue;       }       int out = vec.size() + t;       long long cur = sum;       for (int i = 0; ~out; ++i, --out) {         if (i && i <= vec.size()) {           cur += vec[i - 1];         }         f[u][t] =             min(f[u][t], cur + 1ll * w[u] * max(out, (int)g[u].size() - out));       }     }   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) {       scanf( %d , &w[i]);     }     for (int i = 1; i <= n; ++i) {       scanf( %d , &h[i]);     }     for (int i = 1, u, v; i < n; ++i) {       scanf( %d%d , &u, &v);       g[u].push_back(v);       g[v].push_back(u);     }     dfs(1, 0);     printf( %lld n , f[1][0]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 4e5 + 5;   int head[maxn], e[maxn << 1], nxt[maxn << 1], cnt = 1;   void addedge(int u, int v) {     e[++cnt] = v, nxt[cnt] = head[u], head[u] = cnt;     e[++cnt] = u, nxt[cnt] = head[v], head[v] = cnt;   }   int s[maxn], t[maxn];   int f[maxn], num;   int d[maxn];   int n, C = 2e5;   void dfs(int u) {     while (head[u] && f[head[u] >> 1]) head[u] = nxt[head[u]];     if (head[u]) {       f[head[u] >> 1] = ++num;       dfs(e[head[u]]);     }   }   int main() {     scanf( %d , &n);     for (int i = 1, x, y; i <= n; i++) {       scanf( %d%d , &x, &y);       d[x]++, d[y + C]++;       s[i] = x, t[i] = y + C;       addedge(x, y + C);     }     int last, tot = 0;     for (int i = 1; i <= 2 * C; i++)       if (d[i] % 2) addedge(i, 2 * C + 1);     dfs(2 * C + 1);     for (int i = 1; i <= 2 * C; i++) dfs(i);     memset(d, 0, sizeof(d));     for (int i = 1; i <= n; i++) {       if (f[i] % 2)         d[s[i]]++, d[t[i]]++;       else         d[s[i]]--, d[t[i]]--;     }     for (int i = 1; i <= 2 * C; i++)       if (d[i] > 1 || d[i] < -1) {         printf( shaleba n );         return 0;       }     for (int i = 1; i <= n; i++) {       if (f[i] % 2)         printf( r );       else         printf( b );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 1e6 + 5;   const double delta = 1e-6;   const long long mod = 1e9 + 7;   struct ev {     double coord;     int type;     int mincost;   };   const bool operator<(const ev &f, const ev &s) { return f.coord < s.coord; }   int n, m;   const int magic_const = 2e6;   class segment_tree {    private:     vector<int> a;     vector<int> b;     vector<int> a_left;     vector<int> b_right;     int deltaa, deltab, x, n, now_right;     int answer = 0;     void update_vertex(int v, bool is_leaf) {       if (is_leaf) {         int min_t = min(a[v], b[v]);         a_left[v] = a[v] - min_t;         b_right[v] = b[v] - min_t;       } else {         int l = a_left[v * 2];         int r = b_right[v * 2 + 1];         int min_t = min(l, r);         a_left[v] = l - min_t + a_left[v * 2 + 1];         b_right[v] = r - min_t + b_right[v * 2];       }     }     void build(int v, int l, int r, vector<int> &a1, vector<int> &b1) {       bool leaf = is_leaf(l, r);       if (leaf) {         a[v] = a1[l];         b[v] = b1[l];       } else {         int mid = (l + r) / 2;         build(v * 2, l, mid, a1, b1);         build(v * 2 + 1, mid + 1, r, a1, b1);       }       update_vertex(v, leaf);     }     void update(int v, int l, int r) {       bool leaf = is_leaf(l, r);       if (leaf) {         a[v] += deltaa;         b[v] += deltab;       } else {         int mid = (l + r) / 2;         if (contains_x(l, mid)) update(v * 2, l, mid);         if (contains_x(mid + 1, r)) update(v * 2 + 1, mid + 1, r);       }       update_vertex(v, leaf);     }     void get_answer(int v, int l, int r) {       if (is_leaf(l, r))         answer = l;       else {         int mid = (l + r) / 2;         int now_delta = now_right - a_left[v * 2 + 1];         if (now_delta < 0) {           get_answer(v * 2 + 1, mid + 1, r);         } else {           now_right = now_delta + b_right[v * 2 + 1];           get_answer(v * 2, l, mid);         }       }     }     bool is_leaf(int l, int r) { return l == r; }     bool contains_x(int l, int r) { return x >= l && x <= r; }       public:     segment_tree(vector<int> &a1, vector<int> &b1) {       n = a1.size() - 1;       a.resize(a1.size() * 4);       a_left.resize(a1.size() * 4);       b.resize(b1.size() * 4);       b_right.resize(b1.size() * 4);       build(1, 0, n, a1, b1);     }     void update_ab(int x1, int da, int db) {       x = x1;       deltaa = da;       deltab = db;       update(1, 0, n);     }     int get_answer() {       answer = 0;       now_right = 0;       get_answer(1, 0, n);       if (answer == 0) return -1;       return answer;     }   };   void solve() {     cin >> n >> m;     vector<int> a(MAX_N);     vector<int> b(MAX_N);     a[0] = magic_const;     vector<int> an(n);     vector<int> bm(m);     for (auto &i : an) {       cin >> i;       a[i]++;     }     for (auto &i : bm) {       cin >> i;       b[i]++;     }     segment_tree str(a, b);     int q;     cin >> q;     for (int i = 0; i < q; i++) {       int type, num, x;       cin >> type >> num >> x;       num--;       if (type == 1) {         str.update_ab(an[num], -1, 0);         str.update_ab(x, 1, 0);         an[num] = x;       } else {         str.update_ab(bm[num], 0, -1);         str.update_ab(x, 0, 1);         bm[num] = x;       }       cout << str.get_answer() <<   n ;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     srand(58164);     solve();   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 2e5 + 10;   long long n;   long long pre[N];   long long cal(long long x) {     if (x == n * (n - 1) + 1) return 1;     long long p = lower_bound(pre + 1, pre + n + 1, x) - pre;     long long b = x - pre[p - 1];     if (b & 1)       return p;     else       return p + b / 2;   }   signed main() {     long long t;     cin >> t;     while (t--) {       long long l, r;       cin >> n >> l >> r;       for (long long i = 1; i <= n; i++) pre[i] = pre[i - 1] + 2 * (n - i);       for (long long i = l; i <= r; i++) cout << cal(i) <<    ;       puts(  );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int siz = 1e5 + 7;   const int siz2 = 2e5 + 7;   int t, n;   int a[222];   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> t;   A:     while (t--) {       cin >> n;       map<int, int> mp;       vector<int> Ans;       for (int i = 0; i < n; ++i) {         cin >> a[i];         mp[a[i]]++;       }       if (n > 1) {         for (int i = 0; i < n; ++i) {           for (int j = a[i]; j <= 2 * n; ++j) {             if (!mp[j]) {               mp[j]++;               Ans.push_back(a[i]);               Ans.push_back(j);               break;             }           }         }         if (Ans.size() != 2 * n) {           cout << -1 << endl;           goto A;         }       } else {         if (a[0] == 1) {           cout << 1 <<     << 2 << endl;           goto A;         } else {           cout << -1 << endl;           goto A;         }       }       for (auto it : Ans) cout << it <<    ;       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 20 * 1000 + 200;   const int INF = 1000 * 1000 * 1000;   int d[N];   int n, m;   inline void read() { scanf( %d %d , &n, &m); }   inline void solve() {     for (int i = 0; i < N; i++) d[i] = INF;     queue<int> q;     q.push(n);     d[n] = 0;     while (!q.empty()) {       int v = q.front();       q.pop();       if (v * 2 <= 20 * 1000 && d[v * 2] == INF) {         q.push(v * 2);         d[v * 2] = d[v] + 1;       }       if (v - 1 > 0 && d[v - 1] == INF) {         q.push(v - 1);         d[v - 1] = d[v] + 1;       }     }     cout << d[m];   }   int main() {     read();     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9 + 7;   int N, M;   int dist[200000];   int interval[200000];   int cnt[200000];   int main(void) {     cin >> N;     for (int i = 0; i < (int)(N); ++i) scanf( %d , dist + i);     for (int i = 0; i < (int)(N - 1); ++i) interval[i] = dist[i + 1] - dist[i];     cin >> M;     map<int, int> _ma;     for (int i = 0; i < (int)(M); ++i) {       int b;       scanf( %d , &b);       cnt[b - 1]++;       _ma[b - 1]++;     }     vector<int> candid;     for (int i = 1; i < (int)(N - 1); ++i)       if (cnt[i - 1] != cnt[i] or cnt[i] != cnt[i + 1])         if (cnt[i]) candid.push_back(i);     candid.push_back(0);     candid.push_back(N - 1);     long long res = -1;     for (int s : candid) {       for (int sd = -1; sd <= 1; sd += 2) {         map<int, int> ma = _ma;         int now = s, d = sd;         long long sum = 0;         ma[now]--;         if (ma[now] == 0) ma.erase(now);         while (true) {           if (ma.find(now) == ma.end() and ma.size() == 0) {             if (res == -1 or res == sum) {               res = sum;               break;             } else {               cout << -1 << endl;               return 0;             }           }           now = now + d;           if (!(0 <= (now) && (now) < (N))) {             d *= -1;             now += 2 * d;           }           sum += interval[min(now, now - d)];           if (ma[now] == 0) break;           ma[now]--;           if (ma[now] == 0) ma.erase(now);         }       }     }     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int G[100010];   int A[1000];   int g(int q) {     int n = 2, m, i, g, t, nn;     memset(A, 0, sizeof(A));     n = 2;     nn = -1;     while (q >= n * (n + 1) / 2) {       m = q - n * (n + 1) / 2;       if (m % n != 0) {         n++;         continue;       }       m /= n;       t = 0;       for (i = m + 1; i < m + n + 1; i++) {         t ^= G[i];       }       A[t] = 1;       if ((t == 0) && (nn == -1)) nn = n;       n++;     }     for (i = 0; i < 1000; i++)       if (A[i] == 0) break;     G[q] = i;     return nn;   }   int main() {     int i, n, k, j, d;     memset(G, 0xFF, sizeof(G));     scanf( %d , &n);     for (i = 0; i < n; i++) g(i);     printf( %d n , g(n));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e6 + 15;   int cc[N];   long long sum[N];   long long getSeg(int pos, int p, int x, int y) {     int last = pos + p - 1;     int t = x / y;     int ed = max(pos, last - t);     long long ret = (long long)(cc[ed] - cc[pos]) * x;     long long tot = (long long)(cc[last] - cc[ed]);     long long u = pos + p;     tot *= u;     long long totSum = sum[last] - sum[ed];     ret += (tot - totSum) * y;     return ret;   }   bool isPrime[N];   void solve() {     int n, x, y;     scanf( %d%d%d , &n, &x, &y);     for (int i = 0; i < n; ++i) {       int a;       scanf( %d , &a);       ++cc[a];       sum[a] += a;     }     for (int i = 1; i < N; ++i) {       cc[i] += cc[i - 1];       sum[i] += sum[i - 1];     }     for (int i = 2; i < N; ++i) {       if (!isPrime[i]) {         for (int j = i + i; j < N; j += i) isPrime[j] = true;       }     }     long long ret = 1e18;     for (int i = 2; i <= 1e6; ++i) {       if (isPrime[i]) continue;       long long tot = 0;       for (int pos = 0; pos <= 1e6; pos += i) {         tot += getSeg(pos, i, x, y);       }       ret = min(ret, tot);     }     cout << ret << endl;   }   int main() { solve(); }


#include <bits/stdc++.h>   using namespace std;   template <class T>   void Max(T &a, T b) {     if (b > a) a = b;   }   template <class T>   void Min(T &a, T b) {     if (b < a) a = b;   }   template <class T>   T gcd(T a, T b) {     return b ? gcd(b, a % b) : a;   }   int main() {     ios::sync_with_stdio(false);     int n;     cin >> n;     long long ans = 0;     for (int i = (3), _t = (n + 1); i < _t; ++i) {       ans += (i - 1) * i;     }     cout << ans << endl;     return 0;   }


#include<bits/stdc++.h>   #define __fastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)   #define MOD 1000000007   using namespace std;       typedef long long int ll;           int tc;       void solve()   {       int n,w,x;       multiset<int>st;       vector<int>r;       cin>>n>>w;       for(int i=0; i<n; i++){           cin>>x;           r.push_back(x);       }       sort(r.rbegin(),r.rend());           int h=0;       for(int i=0; i<n; i++){           if(!st.empty() && r[i]<= *(st.rbegin()) ){               x=*(st.rbegin());               st.erase( st.lower_bound(x) );               x-=r[i];               if(x>0)st.insert(x);           }           else{               h++;               if(w-r[i]>0)st.insert(w-r[i]);           }       }       cout<<h<<endl;   }       int main()   {           __fastIO;           cin>>tc; while(tc--)solve();           return 0;   }


#include <bits/stdc++.h>   using namespace std;   int x[10], p[50], dp[200][200];   int pp[50], q[50];   int n, k;   int maxi;   double suma;   int nm = 0;   void check(int a, int b, int c, int d) {     nm++;     for (int i = 1; i <= n; i++) p[i] = x[i];     int br = q[a];     for (int j = pp[a]; j <= ((q[a] + pp[a]) >> 1); j++) {       int pom = p[j];       p[j] = p[br];       p[br] = pom;       br--;     }     if (b > 0) {       int br = q[b];       for (int j = pp[b]; j <= ((q[b] + pp[b]) >> 1); j++) {         int pom = p[j];         p[j] = p[br];         p[br] = pom;         br--;       }     }     if (c > 0) {       int br = q[c];       for (int j = pp[c]; j <= ((q[c] + pp[c]) >> 1); j++) {         int pom = p[j];         p[j] = p[br];         p[br] = pom;         br--;       }     }     if (d > 0) {       int br = q[d];       for (int j = pp[d]; j <= ((q[d] + pp[d]) >> 1); j++) {         int pom = p[j];         p[j] = p[br];         p[br] = pom;         br--;       }     }     int cnt = 0;     for (int j = 1; j <= n; j++)       for (int f = (j + 1); f <= n; f++)         if (p[j] > p[f]) cnt++;     suma = suma + cnt;   }   int main() {     srand(0);     scanf( %d%d , &n, &k);     suma = 0.0;     maxi = n * (n + 1) / 2;     int pom = maxi;     for (int i = 2; i <= 4; i++) {       if (k < i) break;       pom = pom * maxi;     }     maxi = pom;     for (int i = 1; i <= n; i++) scanf( %d , &x[i]);     int cnt = 0;     for (int i = 1; i <= n; i++)       for (int j = i; j <= n; j++)         if (x[i] > x[j]) cnt++;     int i, j, i1, i2, j1, j2;     int br = 0;     for (i = 1; i <= n; i++)       for (j = i; j <= n; j++) {         pp[++br] = i;         q[br] = j;       }     int ppp = 0;     for (i = 1; i <= br; i++) {       if (k == 1) {         check(i, 0, 0, 0);         continue;       }       for (j = 1; j <= br; j++) {         if (k == 2) {           check(i, j, 0, 0);           continue;         }         for (i1 = 1; i1 <= br; i1++) {           if (k == 3) {             check(i, j, i1, 0);             continue;           }           for (i2 = 1; i2 <= br; i2++) {             check(i, j, i1, i2);             ppp++;           }         }       }     }     suma = suma / maxi;     printf( %.11lf n , suma);   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:512000000 )   using namespace std;   void solve(bool);   void precalc();   clock_t start;   int main() {     start = clock();     int t = 1;     cout.sync_with_stdio(0);     cin.tie(0);     precalc();     cout.precision(10);     cout << fixed;     int testNum = 1;     while (t--) {       solve(true);     }     cout.flush();     return 0;   }   template <typename T>   T binpow(T q, T w, T mod) {     if (!w) return 1 % mod;     if (w & 1) return q * 1LL * binpow(q, w - 1, mod) % mod;     return binpow(q * 1LL * q % mod, w / 2, mod);   }   template <typename T>   T gcd(T q, T w) {     while (w) {       q %= w;       swap(q, w);     }     return q;   }   template <typename T>   T lcm(T q, T w) {     return q / gcd(q, w) * w;   }   template <typename T>   void make_unique(vector<T>& a) {     sort(a.begin(), a.end());     a.erase(unique(a.begin(), a.end()), a.end());   }   template <typename T>   void relax_min(T& cur, T val) {     cur = min(cur, val);   }   template <typename T>   void relax_max(T& cur, T val) {     cur = max(cur, val);   }   void precalc() {}   void solve(bool read) {     long long n, Q;     cin >> n >> Q;     while (Q--) {       long long x;       cin >> x;       --x;       long long cur_n = n;       long long pref = 0;       long long steps = 0;       bool printed = false;       while (x % 2 != steps) {         if (cur_n == 1) {           cout << pref + 1 <<   n ;           printed = true;           break;         }         long long dec = (cur_n + 1 - steps) / 2;         pref += dec;         steps = steps + 2 * (dec - 1) == cur_n - 1;         cur_n -= dec;         x /= 2;       }       if (!printed) {         cout << pref + (x - steps) / 2 + 1 << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int arr[102][102] = {0};   int main() {     int n, m, a, b, sum = -1, minsum = -1;     scanf( %d%d , &n, &m);     int cost[n + 1];     for (int i = 1; i <= n; i++) {       scanf( %d , &cost[i]);     }     for (int i = 1; i <= m; i++) {       scanf( %d%d , &a, &b);       arr[a][b] = arr[b][a] = 1;     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         for (int k = 1; k <= n; k++) {           if (sum == -1 && j != k && i != j && j != k && arr[i][j] == 1 &&               arr[j][k] == 1 && arr[k][i] == 1)             minsum = sum = cost[i] + cost[j] + cost[k];           else if (j != k && i != j && j != k && arr[i][j] == 1 &&                    arr[j][k] == 1 && arr[k][i] == 1) {             sum = cost[i] + cost[j] + cost[k];             if (minsum > sum) minsum = sum;           }         }       }     }     printf( %d n , minsum);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long maxn = (int)1e6;   long long n, m, a;   int main() {     cin >> a;     if (a == 1) {       cout <<  1 1  n 1 ;       return 0;     }     cout << (a - 1) * 2 <<     << 2 <<   n ;     cout <<  1 2 ;   }


#include <bits/stdc++.h>   using namespace std;   struct node {     bool bracket, flag;     vector<int> op;   };   map<string, node> def;   map<char, int> op;   void del_space(string tmp) {     int x = tmp.find_first_not_of(   );     tmp.erase(0, x);     x = tmp.find_last_not_of(   );     tmp.erase(x + 1, tmp.length());     string s =   ;     for (int i = 0; i < tmp.length(); i++) {       if (tmp[i] !=    ) {         s += tmp[i];       } else {         if (tmp[i + 1] !=    ) s += tmp[i];       }     }     x = s.find( define ) + 7;     int y = x;     while (s[y] !=    ) y++;     string s1, s2;     s1.append(s.begin() + x, s.begin() + y);     for (int i = y + 1; i < s.length(); i++) {       if (s[i] !=    ) s2 += s[i];     }     node tmp_node;     tmp_node.flag = 0;     int cnt = 0;     for (int i = 0; i < s2.length(); i++) {       if (s2[i] ==  ( ) cnt++;       if (s2[i] ==  ) ) cnt--;       if (op[s2[i]] && cnt == 0) {         tmp_node.op.push_back(op[s2[i]]);       }     }     for (int i = 0; i < s2.length(); i++) {       if (s2[i] ==  *  || s2[i] ==  / ) {         string ss1, ss2;         bool bracket = 0;         if (s2[i + 1] ==  ( ) bracket = 1;         for (int j = i + 1; s2[j] !=  )  && !op[s2[j]] && j < s2.length(); j++) {           ss1 += s2[j];         }         map<string, node>::iterator it = def.find(ss1);         if (it != def.end()) {           bracket = bracket | def[ss1].bracket;           if (def[ss1].flag == 1) {             tmp_node.flag = 1;           }           if (bracket == 0) {             for (int k = 0; k < def[ss1].op.size(); k++) {               if (def[ss1].op[k] == 1 || def[ss1].op[k] == 2) {                 tmp_node.flag = 1;               }             }           }         }         bracket = 0;         for (int j = i - 1; s2[j] !=  (  && !op[s2[j]] && j >= 0; j--) {           ss2 += s2[j];         }         reverse(ss2.begin(), ss2.end());         it = def.find(ss2);         if (it != def.end()) {           bracket = bracket | def[ss2].bracket;           if (def[ss2].flag == 1) {             tmp_node.flag = 1;           }           if (bracket == 0) {             for (int k = 0; k < def[ss2].op.size(); k++) {               if (def[ss2].op[k] == 1 || def[ss2].op[k] == 2) {                 tmp_node.flag = 1;               }             }           }         }       }       if (s2[i] ==  - ) {         string ss1;         bool bracket = 0;         if (s2[i + 1] ==  ( ) bracket = 1;         for (int j = i + 1; s2[j] !=  )  && !op[s2[j]] && j < s2.length(); j++) {           ss1 += s2[j];         }         map<string, node>::iterator it = def.find(ss1);         if (it != def.end()) {           bracket = bracket | def[ss1].bracket;           if (def[ss1].flag == 1) {             tmp_node.flag = 1;           }           if (bracket == 0) {             for (int k = 0; k < def[ss1].op.size(); k++) {               if (def[ss1].op[k] == 1 || def[ss1].op[k] == 2) {                 tmp_node.flag = 1;               }             }           }         }       }       if (s2[i] ==  / ) {         string ss1;         bool bracket = 0;         if (s2[i + 1] ==  ( ) bracket = 1;         for (int j = i + 1; s2[j] !=  )  && !op[s2[j]] && j < s2.length(); j++) {           ss1 += s2[j];         }         map<string, node>::iterator it = def.find(ss1);         if (it != def.end()) {           bracket = bracket | def[ss1].bracket;           if (def[ss1].flag == 1 || (bracket == 0 && !def[ss1].op.empty())) {             tmp_node.flag = 1;           }         }       }     }     tmp_node.bracket = 1;     cnt = 0;     if (s2[0] ==  ( ) cnt++;     for (int i = 1; i < s2.length() - 1; i++) {       if (s2[i] ==  ( ) cnt++;       if (s2[i] ==  ) ) cnt--;       if (cnt == 0) tmp_node.bracket = 0;     }     def[s1] = tmp_node;   }   int main() {     op[ + ] = 1;     op[ - ] = 2;     op[ * ] = 3;     op[ / ] = 4;     int n, flag = 1;     cin >> n;     getchar();     while (n--) {       string tmp;       getline(cin, tmp);       del_space(tmp);     }     string tmp, exp;     getline(cin, tmp);     int x = tmp.find_first_not_of(   );     tmp.erase(0, x);     x = tmp.find_last_not_of(   );     tmp.erase(x + 1, tmp.length());     for (int i = 0; i < tmp.length(); i++) {       if (tmp[i] !=    ) {         exp += tmp[i];       }     }     for (map<string, node>::iterator it = def.begin(); it != def.end(); ++it) {       if (exp.find(it->first) != string::npos && it->second.flag == 1) {         cout <<  Suspicious  << endl;         return 0;       }     }     for (int i = 0; i < exp.length(); i++) {       if (exp[i] ==  *  || exp[i] ==  / ) {         string s1, s2;         bool bracket = 0;         if (exp[i + 1] ==  ( ) bracket = 1;         for (int j = i + 1; exp[j] !=  )  && !op[exp[j]] && j < exp.length();              j++) {           s1 += exp[j];         }         map<string, node>::iterator it = def.find(s1);         if (it != def.end()) {           bracket = bracket | def[s1].bracket;           if (def[s1].flag == 1) {             cout <<  Suspicious  << endl;             return 0;           }           if (bracket == 0) {             for (int k = 0; k < def[s1].op.size(); k++) {               if (def[s1].op[k] == 1 || def[s1].op[k] == 2) {                 cout <<  Suspicious  << endl;                 return 0;               }             }           }         }         bracket = 0;         for (int j = i - 1; exp[j] !=  (  && !op[exp[j]] && j >= 0; j--) {           s2 += exp[j];         }         reverse(s2.begin(), s2.end());         it = def.find(s2);         if (it != def.end()) {           bracket = bracket | def[s2].bracket;           if (def[s2].flag == 1) {             cout <<  Suspicious  << endl;             return 0;           }           if (bracket == 0) {             for (int k = 0; k < def[s2].op.size(); k++) {               if (def[s2].op[k] == 1 || def[s2].op[k] == 2) {                 cout <<  Suspicious  << endl;                 return 0;               }             }           }         }       }       if (exp[i] ==  - ) {         string s1;         bool bracket = 0;         if (exp[i + 1] ==  ( ) bracket = 1;         for (int j = i + 1; exp[j] !=  )  && !op[exp[j]] && j < exp.length();              j++) {           s1 += exp[j];         }         map<string, node>::iterator it = def.find(s1);         if (it != def.end()) {           bracket = bracket | def[s1].bracket;           if (def[s1].flag == 1) {             cout <<  Suspicious  << endl;             return 0;           }           if (bracket == 0) {             for (int k = 0; k < def[s1].op.size(); k++) {               if (def[s1].op[k] == 1 || def[s1].op[k] == 2) {                 cout <<  Suspicious  << endl;                 return 0;               }             }           }         }       }       if (exp[i] ==  / ) {         string s1;         bool bracket = 0;         if (exp[i + 1] ==  ( ) bracket = 1;         for (int j = i + 1; exp[j] !=  )  && !op[exp[j]] && j < exp.length();              j++) {           s1 += exp[j];         }         map<string, node>::iterator it = def.find(s1);         if (it != def.end()) {           bracket = bracket | def[s1].bracket;           if (def[s1].flag == 1 || (bracket == 0 && !def[s1].op.empty())) {             cout <<  Suspicious  << endl;             return 0;           }         }       }     }     cout <<  OK  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b;     cin >> a >> b;     cout << a * b / 2 << endl;   }


#include <bits/stdc++.h>   using namespace std;   int MOD = 1000000007;   int dp[1001][1001];   int main() {     int k;     cin >> k;     int balls[1000];     int n = 0;     for (int i = 0; i < k; i++) {       cin >> balls[i];       n += balls[i];     }     long long l = 1;     for (int i = 0; i <= n; i++) {       dp[i][0] = 1;       dp[i][i] = 1;       for (int j = 1; j <= i; j++) {         dp[i][j] = (dp[i - 1][j] + dp[i - 1][j - 1]) % MOD;       }     }     long long ans = 1;     int cur = balls[0];     for (int i = 1; i < k; i++) {       cur += balls[i];       ans = ((ans % MOD) * (dp[cur - 1][balls[i] - 1]) % MOD) % MOD;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 3e5 + 5;   const int inf = 0x3f3f3f3f;   const int mod = 1e9 + 7;   int T, n, m;   string s;   int vis[26];   int pos[maxn][26];   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> T;     while (T--) {       memset(vis, 0, sizeof(vis));       cin >> n >> m;       for (int i = 0; i < 26; ++i) {         for (int j = 0; j <= n + 5; ++j) {           pos[j][i] = 0;         }       }       cin >> s;       for (int i = 0; i < s.size(); ++i) {         for (int j = 0; j < 26; ++j) {           pos[i][j] = pos[i - 1 == -1 ? 0 : i - 1][j];         }         pos[i][s[i] -  a ]++;       }       for (int i = 0, x; i < m; ++i) {         cin >> x;         x--;         for (int j = 0; j < 26; ++j) {           vis[j] += pos[x][j];         }       }       for (int j = 0; j < 26; ++j) {         vis[j] += pos[n - 1][j];       }       for (int i = 0; i < 26; ++i) {         cout << vis[i] <<    ;       }       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   class BIT {     vector<int> tree;       public:     BIT(int n) : tree(n + 1, 0) {}     BIT(const vector<int>& Arg) {       tree.resize(Arg.size());       for (int i = 0; i < tree.size(); i++) increase(i, Arg[i]);     }     void increase(int i, int delta) {       for (; i < (int)tree.size(); i |= i + 1) tree[i] += delta;     }     int getsum(int left, int right) { return sum(right) - sum(left - 1); }     int sum(int ind) {       int sum = 0;       while (ind >= 0) {         sum += tree[ind];         ind &= ind + 1;         ind--;       }       return sum;     }   };   int main(int argc, char const* argv[]) {     int n, k, a, b, q;     scanf( %d %d , &n, &k);     scanf( %d %d , &a, &b);     scanf( %d , &q);     BIT bita(n + 10);     BIT bitb(n + 10);     for (int i = 0; i < q; i += 1) {       int op;       scanf( %d , &op);       if (op == 1) {         int di, ai;         scanf( %d %d , &di, &ai);         bitb.increase(di, min(b, ai));         bita.increase(di, min(a, ai));         int sb = bitb.getsum(di, di);         int sa = bita.getsum(di, di);         if (sb > b) bitb.increase(di, b - sb);         if (sa > a) bita.increase(di, a - sa);       } else {         int p;         scanf( %d , &p);         int nxt = p + k;         int s = 0;         if (p > 1) s += bitb.getsum(1, p - 1);         if (nxt <= n) s += bita.getsum(nxt, n);         printf( %d n , s);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n = 0, cc = 0, cn = 0, ic = 0, in1 = 0;     int pr;     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> pr;       if (pr % 2 == 1) {         cn++;         in1 = i;       } else {         cc++;         ic = i;       }     }     int answer = cn > cc ? ic : in1;     cout << answer;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e3 + 10, oo = maxn;   int n, m;   char s[maxn], t[maxn];   int a[maxn];   int dp[maxn][maxn];   void myMax(int &a, int b) {     if (a < b) {       a = b;     }   }   int main() {     int i, j, k, x, y;     scanf( %s , s + 1);     n = strlen(s + 1);     scanf( %s , t + 1);     m = strlen(t + 1);     for (i = n; i >= m; i--) {       for (j = i, k = 0; j; j--) {         if (s[j] == t[m - k] && ++k == m) {           break;         }       }       a[i] = k == m ? i - j + 1 : oo;     }     for (; i; i--) {       a[i] = oo;     }     dp[0][0] = 0;     for (i = (1); i <= (n); i++) {       for (j = (0); j <= (i); j++) {         dp[i][j] = 0;         if (j < i) {           dp[i][j] = dp[i - 1][j];         }         if (j) {           myMax(dp[i][j], dp[i - 1][j - 1]);         }         if (a[i] != oo && (y = j - a[i] + m) >= 0 && (x = i - a[i]) >= y) {           myMax(dp[i][j], dp[x][y] + 1);         }       }     }     for (i = (0); i <= (n); i++) {       printf( %d%c , dp[n][i],    n [i == n]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int score = 0;     string str;     cin >> str;     for (int j = 0; j < str.size(); ++j) {       if (str[j] ==  A ) score += 1;       if (str[j] ==  D ) {         score -= 1;       }     }     if (score > 0) cout <<  Anton ;     if (score < 0) cout <<  Danik ;     if (score == 0) cout <<  Friendship ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1000 * 1000 * 1000;   const long long INF64 = 1LL * INF * INF;   const long long mod = INF + 7;   int m[10][10];   bool check(int k, int x, int y, int w, int h) {     int ans = 0;     for (int i = x; i <= h; ++i) {       for (int j = y; j <= w; ++j) {         ans += m[i][j];       }     }     return ans >= k;   }   void solve() {     int r, c, n, k;     cin >> r >> c >> n >> k;     for (int i = 0; i < n; ++i) {       int x, y;       cin >> x >> y;       x--;       y--;       m[x][y] = 1;     }     int ans = 0;     for (int i = 0; i < r; ++i) {       for (int j = 0; j < c; ++j) {         for (int w = j; w < c; ++w) {           for (int h = i; h < r; ++h) {             ans += check(k, i, j, w, h);           }         }       }     }     cout << ans << endl;   }   int main() {     ios_base::sync_with_stdio(false);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long n = 0, m = 0;     cin >> n;     vector<int> hit(n, -1);     map<int, pair<int, int> > circle;     for (int i = 0; i < n; i++) {       int c, r;       cin >> c >> r;       circle.insert(make_pair(c, make_pair(r, i)));     }     int hits = 0;     cin >> m;     for (int i = 0; i < m; i++) {       int x, y;       cin >> x >> y;       map<int, pair<int, int> >::iterator it = circle.upper_bound(x);       for (int j = 0; j < 2; j++) {         if (it == circle.end()) it--;         int c = it->first, r = it->second.first, n = it->second.second;         if ((x - c) * (x - c) + y * y <= r * r) {           if (hit[n] < 0) {             hits++;             hit[n] = i + 1;           }         }         if (it == circle.begin()) {           break;         }         --it;       }     }     cout << hits << endl;     for (int i = 0; i < hit.size(); i++) {       cout << hit[i] <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = int(1e9) + 7;   const int maxn = 200010;   int n;   long long a[maxn];   long long fact[maxn];   long long ans;   void read() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) scanf( %I64d , &a[i]);   }   long long exp(long long x) {     long long s = 1, times = mod - 2;     while (times) {       if (times & 1) s = s * x % mod;       x = x * x % mod;       times >>= 1;     }     return s;   }   long long calc(int x, int y) {     return (fact[x] * exp(fact[y] * fact[x - y] % mod) % mod);   }   void solve() {     if (n == 1) {       ans = a[1];       return;     }     if (n & 1) {       for (int i = 1; i < n; ++i) a[i] += ((i & 1) ? a[i + 1] : -a[i + 1]);       --n;     }     fact[0] = 1;     for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i % mod;     ans = 0;     if (n % 4 == 0) {       for (int i = 1; i <= n; ++i) {         long long tmp = calc(n / 2 - 1, (i - 1) / 2) * a[i] % mod;         if (i & 1)           ans = (ans + tmp) % mod;         else           ans = (ans - tmp + mod) % mod;       }     } else {       for (int i = 1; i <= n; ++i)         ans = (ans + calc(n / 2 - 1, (i - 1) / 2) * a[i] % mod) % mod;     }   }   int main() {     read();     solve();     while (ans < 0) ans += mod;     printf( %I64d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int it[1000100 * 5], a[1000100];   char s[1000100];   void incIT(int node, int l, int r, int pos, int k) {     if (pos < l || pos > r) return;     if (l == r) {       it[node] += k;       return;     }     incIT(node * 2, l, (l + r) / 2, pos, k);     incIT(node * 2 + 1, (l + r) / 2 + 1, r, pos, k);     it[node] = it[node * 2] + it[node * 2 + 1];   }   int findAndDec(int node, int l, int r, int pos, int k) {     if (l == r) {       it[node] -= k;       return l;     }     int res = 0;     if (it[node * 2] >= pos)       res = findAndDec(node * 2, l, (l + r) / 2, pos, k);     else       res = findAndDec(node * 2 + 1, (l + r) / 2 + 1, r, pos - it[node * 2], k);     it[node] = it[node * 2] + it[node * 2 + 1];     return res;   }   int main() {     cin.sync_with_stdio(false);     int n, m;     cin >> n >> m;     for (int i = 0; i < m; ++i) cin >> a[i];     int cnt = 0;     for (int i = 0; i < n; ++i) {       int x;       cin >> x;       if (x == -1) {         int mm = upper_bound(a, a + m, it[1]) - a;         for (int j = mm - 1; j >= 0; --j) findAndDec(1, 1, n, a[j], 1);       } else {         s[++cnt] =  0  + x;         incIT(1, 1, n, cnt, 1);       }     }     int len = 0;     while (it[1] > 0) {       int pos = findAndDec(1, 1, n, 1, 1);       s[len++] = s[pos];     }     s[len] =   0 ;     if (len == 0)       cout <<  Poor stack!  << endl;     else       cout << s << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char a[1000005];   char b[1000005];   int main(void) {     int n;     cin >> n >> (a + 1) >> (b + 1);     int ok = 0;     for (int i = 1; i <= n; ++i) ok += a[i] != b[i];     if (!ok) return cout <<  26 n , 0;     if (ok == 1) return cout <<  2 n , 0;     string k =   , l =   ;     for (int i = 1; i <= n; ++i) k += a[i];     for (int i = 1; i <= n; ++i) l += b[i];     int cnt = 0, ans = 0;     while (k[cnt] == l[cnt]) ++cnt;     k.insert(k.begin() + cnt, l[cnt]);     while (k[cnt] == l[cnt]) ++cnt;     l.insert(l.begin() + cnt, k[cnt]);     ans += (k == l);     k =   ;     l =   ;     for (int i = 1; i <= n; ++i) k += a[i];     for (int i = 1; i <= n; ++i) l += b[i];     cnt = 0;     while (k[cnt] == l[cnt]) ++cnt;     l.insert(l.begin() + cnt, k[cnt]);     while (k[cnt] == l[cnt]) ++cnt;     k.insert(k.begin() + cnt, l[cnt]);     ans += (k == l);     return cout << ans <<   n , 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     char s[111111];     scanf( %s , s);     int len = strlen(s);     int i;     if (len == 1 && s[0] ==  a ) {       puts( z );       return 0;     }     i = 0;     while (s[i] ==  a ) {       i++;     }     if (i == len) {       s[len - 1] =  z ;     }     for (; i < len; i++) {       if (s[i] ==  a ) break;       s[i]--;     }     printf( %s n , s);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   inline int add(int x, int y) {     x += y;     if (x >= mod) x -= mod;     return x;   }   inline int sub(int x, int y) {     x -= y;     if (x < 0) x += mod;     return x;   }   inline int mul(int x, int y) { return (x * 1ll * y) % mod; }   inline int powr(int a, long long b) {     int x = 1 % mod;     while (b) {       if (b & 1) x = mul(x, a);       a = mul(a, a);       b >>= 1;     }     return x;   }   inline int inv(int a) { return powr(a, mod - 2); }   vector<pair<int, int> > A, B;   bool cmp(const pair<int, int>& x, const pair<int, int>& y) {     return x.first < y.first || (x.first == y.first && x.second > y.second);   }   void go(vector<pair<int, int> >& X) {     vector<pair<int, int> > ret;     sort(X.begin(), X.end(), cmp);     for (int i = 0; i < X.size(); i++) {       int l1 = X[i].first, r1 = X[i].second;       while (!ret.empty()) {         int l2 = ret.back().first, r2 = ret.back().second;         if (l1 >= l2 && r1 <= r2)           ret.pop_back();         else           break;       }       ret.push_back(X[i]);     }     X = ret;   }   const int inv2 = (mod + 1) >> 1;   const int MAXN = 200005;   int dp[2][2][MAXN];   int dp1[2][2][MAXN];   int dp2[2][2][MAXN];   void ADD(int& a, int b) {     a += b;     if (a >= mod) a -= mod;   }   vector<int> P[2];   int main() {     int k, n, m;     scanf( %d , &(k));     scanf( %d , &(n));     scanf( %d , &(m));     int mn = 2e9, mx = -1;     for (int i = 1; i <= n; i++) {       int a, b;       scanf( %d , &(a));       scanf( %d , &(b));       A.push_back({a, b});     }     for (int i = 1; i <= m; i++) {       int a, b;       scanf( %d , &(a));       scanf( %d , &(b));       B.push_back({a, b});     }     go(A);     go(B);     P[0] = P[1] = {-1};     for (auto it : A) P[0].push_back(it.second);     for (auto it : B) P[1].push_back(it.second);     reverse(A.begin(), A.end());     reverse(B.begin(), B.end());     dp[0][0][0] = dp1[0][0][0] = dp2[0][0][0] = 1;     int cnt[2] = {0, 0};     int f[2] = {powr(2, k), 0};     while (!A.empty() || !B.empty()) {       int L, R, type;       if (A.empty()) {         L = B.back().first;         R = B.back().second;         type = 1;         B.pop_back();       } else if (B.empty()) {         L = A.back().first;         R = A.back().second;         type = 0;         A.pop_back();       } else {         int l1 = A.back().first, r1 = A.back().second;         int l2 = B.back().first, r2 = B.back().second;         if (l1 < l2 || (l1 == l2 && r1 < r2)) {           L = l1;           R = r1;           type = 0;           A.pop_back();         } else {           L = l2;           R = r2;           type = 1;           B.pop_back();         }       }       cnt[type]++;       for (int prevparity = 0; prevparity < 2; prevparity++) {         int newparity = prevparity ^ 1;         int ind =             lower_bound(P[type].begin(), P[type].end(), L) - P[type].begin();         int ind2 = lower_bound(P[type ^ 1].begin(), P[type ^ 1].end(), L) -                    P[type ^ 1].begin();         ADD(dp[type][newparity][cnt[type]],             mul(powr(2, L - 1), add(dp2[type][prevparity][ind - 1],                                     dp2[type ^ 1][prevparity][ind2 - 1])));         ADD(dp[type][newparity][cnt[type]],             sub(dp1[type][prevparity][cnt[type] - 1],                 dp1[type][prevparity][ind - 1]));       }       for (int parity = 0; parity < 2; parity++) {         dp2[type][parity][cnt[type]] =             add(dp2[type][parity][cnt[type] - 1],                 mul(powr(inv2, R), dp[type][parity][cnt[type]]));         dp1[type][parity][cnt[type]] =             add(dp1[type][parity][cnt[type] - 1], dp[type][parity][cnt[type]]);         f[parity] =             add(f[parity], mul(dp[type][parity][cnt[type]], powr(2, k - R)));       }     }     printf( %d n , sub(f[0], f[1]));   }


#include <bits/stdc++.h>   using namespace std;   const int MX = 1005;   struct Edge {     int v, nxt;   } edge[MX * MX];   int head[MX], tot, c[MX], E[MX], V[MX], vis[MX];   void add(int u, int v) {     edge[tot].v = v;     edge[tot].nxt = head[u];     head[u] = tot++;   }   void dfs(int u, int &e, int &v) {     for (int i = head[u]; ~i; i = edge[i].nxt) {       int vv = edge[i].v;       e++;       if (vis[vv]) continue;       v++;       vis[vv] = 1;       dfs(vv, e, v);     }   }   int main() {     int n, m, k;     while (~scanf( %d%d%d , &n, &m, &k)) {       memset(head, -1, sizeof(head));       memset(vis, 0, sizeof(vis));       memset(E, 0, sizeof(E));       memset(V, 0, sizeof(V));       tot = 0;       for (int i = 0; i < k; i++) scanf( %d , &c[i]);       for (int i = 0; i < m; i++) {         int u, v;         scanf( %d%d , &u, &v);         add(u, v);         add(v, u);       }       int ans = 0, mx = 0, c1 = n, c2 = m;       for (int i = 0; i < k; i++) {         int v = c[i];         vis[v] = 1;         V[v]++;         dfs(v, E[v], V[v]);         c1 -= V[v];         c2 -= E[v] / 2;         if (V[mx] < V[v]) mx = v;         ans += V[v] * (V[v] - 1) / 2 - E[v] / 2;       }       ans += (V[mx] + c1) * (V[mx] + c1 - 1) / 2 - c2 - V[mx] * (V[mx] - 1) / 2;       printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   bool check(int num) {     if (1 == num) return true;     for (int i = 2; i <= num / i; i++) {       if (num % i == 0) {         return false;       }     }     return true;   }   int main() {     cin >> n;     if (check(n)) {       printf( 1 n );       printf( %d n , n);     } else if (check(n - 2)) {       printf( 2 n );       printf( 2 %d n , n - 2);     } else if (check(n - 4)) {       printf( 3 n );       printf( 2 2 %d n , n - 4);     } else {       bool result = false;       int i, even;       int prime1, temp, prime2;       for (int num = 3; num < n / 3 + 10; num++) {         if (!check(num)) continue;         even = n - num;         for (prime1 = 3; prime1 <= even / 2; prime1 += 2) {           for (temp = 2; temp <= sqrt(prime1); temp++) {             if (prime1 % temp == 0) break;           }           if (temp > sqrt(prime1))             prime2 = even - prime1;           else             continue;           for (temp = 2; temp <= sqrt(prime2); temp++) {             if (prime2 % temp == 0) break;           }           if (temp > sqrt(prime2)) {             cout << 3 << endl << num <<     << prime1 <<     << prime2 << endl;             result = true;             break;           }         }         if (!result)           continue;         else           break;       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100007;   int n, k, a[N];   bool solve() {     bool exists = false;     for (int i = 0; i < n; ++i) {       cin >> a[i];       if (a[i] == k) {         exists = true;       }     }     if (!exists) {       return false;     }     if (n == 1) return true;     for (int i = 0; i < n; ++i) {       int ct = 0;       for (int j = i; j < i + 3 && j < n; ++j) {         if (a[j] >= k) {           ct++;         }       }       if (ct >= 2) {         return true;       }     }     return false;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t;     cin >> t;     while (t--) {       cin >> n >> k;       if (solve()) {         cout <<  yes n ;       } else {         cout <<  no n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1);   void fft(vector<complex<double> >& a, bool invert) {     int n = (int)a.size();     for (int i = 1, j = 0; i < n; ++i) {       int bit = n >> 1;       for (; j >= bit; bit >>= 1) j -= bit;       j += bit;       if (i < j) swap(a[i], a[j]);     }     for (int len = 2; len <= n; len <<= 1) {       double ang = 2 * PI / len * (invert ? -1 : 1);       complex<double> wlen(cos(ang), sin(ang));       for (int i = 0; i < n; i += len) {         complex<double> w(1);         for (int j = 0; j < len / 2; ++j) {           complex<double> u = a[i + j], v = a[i + j + len / 2] * w;           a[i + j] = u + v;           a[i + j + len / 2] = u - v;           w *= wlen;         }       }     }     if (invert)       for (int i = 0; i < n; ++i) a[i] /= n;   }   void multiply(const vector<long long int>& a, const vector<long long int>& b,                 vector<long long int>& res) {     vector<complex<double> > fa(a.begin(), a.end()), fb(b.begin(), b.end());     size_t n = 1;     while (n < max(a.size(), b.size())) n <<= 1;     n <<= 1;     fa.resize(n), fb.resize(n);     fft(fa, false), fft(fb, false);     for (size_t i = 0; i < n; ++i) fa[i] *= fb[i];     fft(fa, true);     res.resize(n);     for (size_t i = 0; i < n; ++i) res[i] = (long long int)(fa[i].real() + 0.5);   }   vector<long long int> now(1, 1);   int main() {     vector<long long int> res;     int n, x;     cin >> n >> x;     int need = n;     while (n--) {       int u;       cin >> u;       if (u < x) {         now.push_back(1);       } else {         ++now.back();       }     }     long long int w0 = 0;     for (auto e : now) {       w0 += e * (e - 1) / 2;     }     int k = now.size();     vector<long long int> nowr(now.rbegin(), now.rend());     nowr.back() = 0;     multiply(now, nowr, res);     cout << w0 <<    ;     for (int i = k - 2; i >= 0 && res[i]; i--) {       cout << res[i] <<    ;       --need;     }     while (need--) {       cout << 0 <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string proc(int a, int b) {     if (a * 2 > b) return  noob ;     if (a * 5 > b) return  random ;     if (a * 10 > b) return  average ;     if (a * 100 > b) return  hardcore ;     return  pro ;   }   int main() {     int i, n, x;     string s;     map<string, int> score;     cin >> n;     while (n--) {       cin >> s >> x;       if (score.find(s) == score.end()) score[s] = 0;       score[s] = max(score[s], x);     }     vector<int> list;     for (typeof(score.begin()) it = score.begin(); it != score.end(); it++)       list.push_back(it->second);     sort(list.rbegin(), list.rend());     cout << ((int)score.size()) << endl;     for (typeof(score.begin()) it = score.begin(); it != score.end(); it++) {       for (i = 0; i < (int)(((int)list.size())); i++)         if (list[i] == it->second) break;       cout << it->first <<     << proc(i, ((int)list.size())) << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s1, s2;     getline(cin, s1);     getline(cin, s2);     int yek1 = 0, yek2 = 0;     for (int i = 0; i < s1.size(); i++) {       if (s1[i] ==  1 ) yek1++;     }     for (int i = 0; i < s2.size(); i++) {       if (s2[i] ==  1 ) yek2++;     }     if (yek1 % 2 == 1) yek1++;     if (yek1 >= yek2) {       cout <<  YES ;       return 0;     }     cout <<  NO ;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   T min(T a, T b, T c) {     return min(a, min(b, c));   }   template <class T>   T min(T a, T b, T c, T d) {     return min(a, min(b, min(c, d)));   }   template <class T>   T max(T a, T b, T c) {     return max(a, max(b, c));   }   template <class T>   T max(T a, T b, T c, T d) {     return max(a, max(b, max(c, d)));   }   bool cmp(const pair<int, int>& a, const pair<int, int>& b) {     return (a.first > b.first || (a.first == b.first && a.second >= b.second));   }   long long GCD(long long a, long long b) { return (a % b) ? GCD(b, a % b) : b; }   const string namePro =  tmp ;   int nodes[4 * 1000007];   int a[1000007];   void initIT(int root, int left, int right) {     if (left == right) {       nodes[root] = a[left];       return;     }     int mid = (left + right) / 2;     initIT(2 * root, left, mid);     initIT(2 * root + 1, mid + 1, right);     nodes[root] = min(nodes[2 * root], nodes[2 * root + 1]);     return;   }   int queryIT(int root, int left, int right, int val) {     int mid = (left + right) / 2;     if (left == right) return left;     if (nodes[2 * root + 1] < val)       return queryIT(2 * root + 1, mid + 1, right, val);     else       return queryIT(2 * root, left, mid, val);   }   int main() {     int n;     scanf( %d , &n);     for (int i = (1); i <= (n); ++i) scanf( %d , &a[i]);     initIT(1, 1, n);     for (int i = (1); i <= (n); ++i) {       int k = queryIT(1, 1, n, a[i]);       if (k <= i)         printf( -1  );       else         printf( %d  , k - i - 1);     }     return 0;   }