#include <bits/stdc++.h>   using namespace std;   int A[100005], P[100005];   int other_end[100005];   long long ans[100005], seg[100005];   int main() {     int n;     cin >> n;     for (int i = 1; i <= n; ++i) scanf( %d , &A[i]);     for (int i = 1; i <= n; ++i) scanf( %d , &P[i]);     long long res = 0;     for (int i = n; i >= 1; --i) {       ans[i] = res;       int pos = P[i];       long long sum = A[pos];       int l = pos, r = pos;       if (other_end[pos - 1] != 0) {         l = other_end[pos - 1];         sum += seg[l];       }       if (other_end[pos + 1] != 0) {         sum += seg[pos + 1];         r = other_end[pos + 1];       }       other_end[l] = r;       other_end[r] = l;       seg[l] = sum;       if (sum > res) res = sum;     }     for (int i = 1; i <= n; ++i) cout << ans[i] << endl;     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker, ”/ STACK : 38777216“   using namespace std;   const int N = 100005;   const int inf = 1000 * 1000 * 1000;   const int mod = 1000 * 1000 * 1000 + 7;   string s;   int a, b, c, d, t;   int main() {     cin >> t >> s;     if (t % 4 != 0) {       cout <<  ===  << endl;       return 0;     }     t /= 4;     for (int i = 0; i < 4 * t; i++) {       if (s[i] ==  A ) a++;       if (s[i] ==  C ) b++;       if (s[i] ==  G ) c++;       if (s[i] ==  T ) d++;     }     if (a > t || b > t || c > t || d > t) {       cout <<  ===  << endl;       return 0;     }     a = t - a;     b = t - b;     c = t - c;     d = t - d;     for (int i = 0; i < 4 * t; i++) {       if (s[i] !=  ? ) continue;       if (a > 0) {         s[i] =  A ;         a--;         continue;       }       if (b > 0) {         s[i] =  C ;         b--;         continue;       }       if (c > 0) {         s[i] =  G ;         c--;         continue;       }       s[i] =  T ;       d--;     }     cout << s << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct node {     int degree;     int xorsum;   };   struct Edge {     int src, des;   };   struct node virtex[100000];   vector<struct Edge> edge;   vector<struct Edge>::iterator it;   queue<int> que;   int main() {     struct Edge temp;     int n, d, s, i, src, des;     cin >> n;     for (i = 0; i < n; i++) {       cin >> virtex[i].degree >> virtex[i].xorsum;     }     for (i = 0; i < n; i++) {       if (virtex[i].degree == 1) {         que.push(i);       }     }     while (!que.empty()) {       src = que.front();       que.pop();       if (virtex[src].degree == 1) {         des = virtex[src].xorsum;         temp.src = src;         temp.des = des;         edge.push_back(temp);         virtex[des].degree--;         virtex[des].xorsum ^= src;         if (virtex[des].degree == 1) {           que.push(des);         }       }     }     cout << edge.size() << endl;     it = edge.begin();     while (it != edge.end()) {       cout << it->src <<     << it->des << endl;       it++;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1000010;   int cnt[N];   int a, b, n;   void genPrime() {     for (int i = 2; i < N; ++i) cnt[i] = 1;     for (int i = 2; i <= 1000; ++i)       if (cnt[i])         for (int j = i * i; j < N; cnt[j] = 0, j += i)           ;     for (int i = 1; i < N; ++i) cnt[i] += cnt[i - 1];   }   bool chk(int x) {     for (int i = a; i + x - 1 <= b; ++i) {       int j = i + x - 1;       if (cnt[j] - cnt[i - 1] < n) return false;     }     return true;   }   int main() {     int i, j, k;     genPrime();     scanf( %d%d%d , &a, &b, &n);     if (cnt[b] - cnt[a - 1] < n) {       printf( -1 n );       return 0;     }     int low = 1, up = b - a + 1;     while (up > low) {       int mid = (up + low) / 2;       if (chk(mid))         up = mid;       else         low = mid + 1;     }     printf( %d n , up);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 20;   int n;   int a[N];   int b[N];   vector<string> ans;   int get(int s, int e) {     int res = 0;     for (int i = s; i < e; ++i) {       res = res * 10 + b[i];     }     return res;   }   string getstr(int x, int y, int z, int l) {     string s =   ;     for (int i = 0; i < x; ++i) {       s += b[i] +  0 ;     }     s +=  . ;     for (int i = x; i < y; ++i) {       s += b[i] +  0 ;     }     s +=  . ;     for (int i = y; i < z; ++i) {       s += b[i] +  0 ;     }     s +=  . ;     for (int i = z; i < l; ++i) {       s += b[i] +  0 ;     }     return s;   }   int check(int x, int y, int z, int l) {     if (x > 3) return 0;     if (y - x > 3) return 0;     if (z - y > 3) return 0;     if (l - z > 3) return 0;     if (b[0] == 0 && x != 1 || b[x] == 0 && y - x != 1 ||         b[y] == 0 && z - y != 1 || b[z] == 0 && l - z != 1) {       return 0;     }     int num[4] = {get(0, x), get(x, y), get(y, z), get(z, l)};     for (int i = 0; i < 4; ++i) {       if (num[i] < 0 || num[i] >= 256) {         return 0;       }     }     return 1;   }   int cntsplit(int l) {     int res = 0;     for (int i = 1; i < l; ++i) {       if (i - 0 > 3) break;       for (int j = i + 1; j < l && j <= i + 3; ++j) {         if (j - i > 3) break;         for (int k = j + 1; k < l && k <= j + 3; ++k) {           if (k - j > 3) break;           if (check(i, j, k, l)) {             ans.push_back(getstr(i, j, k, l));             ++res;           }         }       }     }     return res;   }   int cnt(int d) {     int l = 2 * d;     int res = 0;     for (int i = 0; i < d; ++i) {       b[l - i - 1] = b[i];     }     res += cntsplit(l);     --l;     for (int i = 0; i < d - 1; ++i) {       b[l - i - 1] = b[i];     }     res += cntsplit(l);     return res;   }   void dfs(int d, int msk) {     if (msk == (1 << n) - 1) {       cnt(d);     }     if (d >= 6) return;     for (int i = 0; i < n; ++i) {       b[d] = a[i];       dfs(d + 1, msk | (1 << i));     }   }   int main() {     scanf( %d , &n);     for (int i = 0; i < n; ++i) {       scanf( %d , a + i);     }     if (n > 6) {       puts( 0 );       return 0;     }     dfs(0, 0);     printf( %d n , ans.size());     for (int i = 0; i < ans.size(); ++i) {       printf( %s n , ans[i].c_str());     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 5e3 + 9;   const int M = 5e4 + 9;   long long read() {     long long x = 0, op = 1;     char c = getchar();     while (!isdigit(c)) {       if (c ==  - ) op = -1;       c = getchar();     }     while (isdigit(c)) x = x * 10 + c - 48, c = getchar();     return x * op;   }   signed main() {     int T = read();     while (T--) {       int n = read();       if (n & 1) n--;       cout << n / 2 + 1 <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int fx[8] = {0, -1, -1, -1, 0, 1, 1, 1};   const int fy[8] = {1, 1, 0, -1, -1, -1, 0, 1};   const int maxn = 310;   int vis[maxn][maxn][8][30];   int v[maxn][maxn];   int step[40];   queue<pair<int, int> > q;   pair<int, int> mkstate(int x, int y, int d, int t) {     return make_pair(x * 10000 + y, d * 10000 + t);   }   int main() {     int n;     cin >> n;     for (int i = 0; i < n; i++) cin >> step[i];     while (!q.empty()) q.pop();     q.push(mkstate(155, 155, 0, 0));     vis[155][155][0][0] = true;     while (!q.empty()) {       pair<int, int> t = q.front();       q.pop();       int x = t.first / 10000;       int y = t.first % 10000;       int d = t.second / 10000;       int th = t.second % 10000;       for (int i = 0; i < step[th]; i++) {         v[x + fx[d] * i][y + fy[d] * i] = 1;       }       int nx = x + fx[d] * (step[th] - 1);       int ny = y + fy[d] * (step[th] - 1);       int d1 = (d + 1) % 8;       int x1 = nx + fx[d1];       int y1 = ny + fy[d1];       int d2 = (d - 1 + 8) % 8;       int x2 = nx + fx[d2];       int y2 = ny + fy[d2];       pair<int, int> t1 = mkstate(x1, y1, d1, th + 1);       pair<int, int> t2 = mkstate(x2, y2, d2, th + 1);       if (th + 1 < n && !vis[x1][y1][d1][th + 1]) {         q.push(t1);         vis[x1][y1][d1][th + 1] = true;       }       if (th + 1 < n && !vis[x2][y2][d2][th + 1]) {         q.push(t2);         vis[x2][y2][d2][th + 1] = true;       }     }     int ans = 0;     for (int i = 0; i < maxn; i++) {       for (int j = 0; j < maxn; j++) {         if (v[i][j]) ans++;       }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void exitall() {     cout << -1;     exit(0);   }   int main() {     ios::sync_with_stdio(false);     int n;     long long d;     cin >> n >> d;     vector<long long> v(n);     for (int i = 0; i < n; ++i) {       cin >> v[i];     }     long long mx = 0;     int ans = 0;     int lst = -1;     long long b = 0;     for (int i = 0; i < n; ++i) {       if (v[i] == 0) {         if (lst >= 0) {           if (b >= 0) continue;           if (-b <= d - mx) {             mx -= b;             b = 0;           } else {             ans++;             b = 0;             lst = i;             mx = 0;           }         } else {           if (b < 0) {             ans++;             b = 0;             mx = 0;             lst = i;           }         }       } else         mx = max(mx, b = b + v[i]);       if (b > d) {         cout << -1;         return 0;       }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<pair<int, int> > v;     for (int i = (int)0; i < (int)(n); i++) {       int second = 0;       int a;       for (int j = (int)0; j < (int)(4); j++) {         cin >> a;         second += a;       }       v.push_back(make_pair(-second, i));     }     sort(v.begin(), v.end());     for (int i = (int)0; i < (int)(n); i++)       if (v[i].second == 0) cout << i + 1 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 5000;   vector<int> edge[MAX + 5];   int p[MAX + 5], c[MAX + 5], lft[MAX + 5], used[MAX + 5], vis[MAX + 5],       cp[MAX + 5], ans[MAX + 5];   int n, m, d, mex, dfn;   bool dfs(int x) {     for (int i = 0; i < edge[x].size(); i++) {       int j = edge[x][i];       if (used[j] != dfn) {         used[j] = dfn;         if (cp[j] == -1 || dfs(cp[j])) {           cp[j] = x;           return true;         }       }     }     return false;   }   int main() {     memset(cp, -1, sizeof(cp));     int i;     scanf( %d%d , &n, &m);     for (i = 1; i <= n; i++) scanf( %d , &p[i]);     for (i = 1; i <= n; i++) scanf( %d , &c[i]);     scanf( %d , &d);     for (i = 1; i <= d; i++) {       scanf( %d , &lft[i]);       vis[lft[i]] = 1;     }     for (i = 1; i <= n; i++) {       if (!vis[i]) edge[p[i]].push_back(c[i]);     }     for (i = d, mex = -1, dfn = 1; i >= 1; i--) {       while (dfs(mex + 1)) {         mex++;         dfn++;       }       ans[i] = mex + 1;       dfn++;       edge[p[lft[i]]].push_back(c[lft[i]]);     }     for (i = 1; i <= d; i++) {       printf( %d n , ans[i]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s[] = { zero ,     one ,      two ,        three ,     four ,                    five ,     six ,      seven ,      eight ,     nine ,                    ten ,      eleven ,   twelve ,     thirteen ,  fourteen ,                    fifteen ,  sixteen ,  seventeen ,  eighteen ,  nineteen };     string c[] = {  ,        ,       twenty ,   thirty ,  forty ,                    fifty ,  sixty ,  seventy ,  eighty ,  ninety };     int n;     cin >> n;     if (n < 20) {       cout << s[n];     } else {       if (n % 10 == 0)         cout << c[n / 10];       else         cout << c[n / 10] <<  -  << s[n % 10];     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 3e4, SQN = 3e2;   map<int, int> dst_idx, idx_dst;   int n, d, dp[MAXN + 3][SQN + 3], a[MAXN + 3], max_idx;   int fazdp(int idx, int li) {     if (dp[idx][li] != -1) return dp[idx][li];     int di = idx_dst[li];     int ret = 0;     for (int i = -1; i <= 1; i++) {       int dd = di + i;       if (dst_idx.find(dd) == dst_idx.end() || dd <= 0 || idx + dd > max_idx)         continue;       int iidx = idx + dd;       ret = max(ret, fazdp(iidx, dst_idx[dd]));     }     return dp[idx][li] = a[idx] + ret;   }   int main() {     for (int i = 0; i < MAXN + 3; i++)       for (int j = 0; j < SQN + 3; j++) dp[i][j] = -1;     scanf( %d %d , &n, &d);     for (int i = 1; i <= n; i++) {       int aux;       scanf( %d , &aux);       max_idx = max(max_idx, aux);       a[aux]++;     }     int cnt = 0;     for (int i = max(1, d - SQN); i <= min(max_idx, d + SQN); i++) {       dst_idx[i] = cnt;       idx_dst[cnt] = i;       cnt++;     }     printf( %d , a[0] + fazdp(d, dst_idx[d]));   }


#include <bits/stdc++.h>   using namespace std;   long long int d[400001], num[400001];   int decr[400001], inc[400001];   priority_queue<pair<long long int, int>, vector<pair<long long int, int> >,                  greater<pair<long long int, int> > >       H1;   priority_queue<pair<long long int, int> > H2;   int main() {     int i;     int t, m;     long long int n, k, p, o;     scanf( %d , &t);     while (t--) {       scanf( %I64d %d %I64d , &n, &m, &k), o = 0;       for (i = 0; i < m; i++) scanf( %I64d , &p), d[i] = p - o, o = p;       d[m++] = n - o, k += m;       long long int l = 1, r = n;       while (l < r) {         long long int mid = (l + r) / 2;         long long int s = 0;         for (i = 0; i < m; i++) s += (d[i] + mid - 1) / mid;         if (s > k)           l = mid + 1;         else           r = mid;       }       long long int s = 0;       for (i = 0; i < m; i++) num[i] = (d[i] + r - 1) / r, s += num[i];       for (i = 0; i < m; i++) {         if ((s < k) && ((d[i] + num[i] - 1) / num[i] == r)) {           long long int x = (d[i] - 1) / (r - 1) - num[i] + 1;           x = min(x, k - s);           num[i] += x, s += x;         }         l = min(l, d[i] / num[i]);       }       long long int ans = r - l;       for (i = 0; i < m; i++)         H1.push(make_pair(d[i] / num[i], i)),             H2.push(make_pair(d[i] / (num[i] + 1), i));       fill(decr, decr + m, 0), fill(inc, inc + m, 0);       int tt = 10 * m;       while (tt--) {         while (d[H1.top().second] / num[H1.top().second] != H1.top().first)           H1.pop();         while (d[H2.top().second] / (num[H2.top().second] + 1) != H2.top().first)           H2.pop();         int u = H1.top().second, v = H2.top().second;         H1.pop(), H2.pop();         if (u == v) break;         num[u]--, num[v]++;         decr[u] = 1, inc[v] = 1;         if (decr[u] && inc[u]) break;         if (decr[v] && inc[v]) break;         if (num[u] == 0) break;         r = max(r, (d[u] + num[u] - 1) / num[u]);         H1.push(make_pair(d[u] / num[u], u));         if (d[u] / num[u] != d[u] / (num[u] + 1))           H2.push(make_pair(d[u] / (num[u] + 1), u));         if (d[v] / num[v] != d[v] / (num[v] - 1))           H1.push(make_pair(d[v] / num[v], v));         H2.push(make_pair(d[v] / (num[v] + 1), v));         while (d[H1.top().second] / num[H1.top().second] != H1.top().first)           H1.pop();         ans = min(ans, r - H1.top().first);       }       printf( %I64d n , ans);       while (!H1.empty()) H1.pop();       while (!H2.empty()) H2.pop();     }     return 0;   }


#include <bits/stdc++.h>   int main() {     std::ios::sync_with_stdio(false);     std::cin.tie(nullptr);     int a;     std::cin >> a;     int d[6];     for (int i = 0; i < 6; ++i) d[i] = a >> i & 1;     std::cout << (d[0] << 4 | d[1] << 1 | d[2] << 3 | d[3] << 2 | d[4] |                   d[5] << 5)               <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t, a, b, c, d, ans1, ans2, ans3;     cin >> t;     while (t--) {       ans1 = 0;       ans2 = 0;       ans3 = 0;       cin >> a >> b >> c >> d;       ans1 = a / b;       ans2 = (c - 1) / b;       ans3 = d / b;       ans1 -= ans3;       ans1 += ans2;       cout << ans1 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, number;     cin >> n;     int arr[n + 1];     bool marcado[n + 1];     memset(marcado, 0, sizeof marcado);     for (int i = 1; i <= n; i++) {       cin >> number;       if (!marcado[number] && number <= n) {         marcado[number] = true;         arr[i] = number;       } else         arr[i] = 0;     }     int i, j;     for (i = 1, j = 1; i <= n; i++) {       if (arr[i] != 0) {         cout << arr[i] <<    ;       } else {         while (marcado[j]) j++;         cout << j++ <<    ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, tmp, k, gbd;     cin >> n;     k = 1;     while (k < 10) {       tmp = pow(2, k - 1) * (pow(2, k) - 1);       if (n % tmp == 0) gbd = tmp;       k++;     }     cout << gbd;   }


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


#include <bits/stdc++.h>   using namespace std;   int n, ans = -1000001;   int main() {     cin >> n;     float a;     for (int i = 1; i <= n; i++) {       cin >> a;       if (floor(sqrt(a)) != sqrt(a)) {         ans = max(ans, (int)a);       }     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long int n, i, j, s = 0, min1 = INT_MAX, min2 = INT_MIN, od = 0;     cin >> n;     long long int a[n + 5];     for (i = 0; i < n; i++) {       cin >> a[i];       if (a[i] >= 0) {         if (a[i] % 2) od++, min1 = min(min1, a[i]);         s += a[i];       } else {         if (a[i] % 2) min2 = max(min2, a[i]);       }     }     if (s % 2 == 0) {       if (min1 == INT_MAX)         cout << s + min2 <<   n ;       else if (min2 == INT_MIN)         cout << s - min1 <<   n ;       else {         long long int x = s - min1;         long long int y = s + min2;         cout << max(x, y) <<   n ;       }     } else       cout << s <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   long long int gcd(long long int a, long long int b) {     if (b == 0)       return a;     else       return gcd(b, a % b);   }   int main() {     long long int n, x, ans, ans1, y;     cin >> y;     n = (long long int)sqrt((double)y);     for (long long int i = n; i > 0; i--) {       if (y % i == 0) {         x = y / i;         if (gcd(i, x) == 1) {           ans = i;           ans1 = x;           break;         }       }     }     if (y != 1)       cout << ans <<     << ans1 << endl;     else       cout << 1 <<     << 1 << endl;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   ostream& operator<<(ostream& os, const vector<T>& v) {     for (T i : v) os << i <<    ;     return os;   }   template <class T>   ostream& operator<<(ostream& os, const set<T>& v) {     for (T i : v) os << i <<    ;     return os;   }   template <class T, class S>   ostream& operator<<(ostream& os, const pair<T, S>& v) {     os << v.first <<     << v.second;     return os;   }   template <class T, class S>   ostream& operator<<(ostream& os, const unordered_map<T, S>& v) {     for (auto i : v) os <<  (  << i.first <<  =>  << i.second <<  )  <<    ;     return os;   }   #pragma GCC optimize( O3 )   #pragma GCC optimize( unroll-loops )   #pragma GCC target(         avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   const long long inf = 1e18;   const long long mod = 1e9 + 7;   void fast() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);   }   clock_t time_p = clock();   void starboy1299() {     time_p = clock() - time_p;     cerr <<  Time Taken :   << (float)(time_p) / CLOCKS_PER_SEC <<   n ;   }   const long long N = 5e5 + 5;   void solve() {     long long n, p;     cin >> n >> p;     for (long long i = 1; i <= 32; i++) {       long long val = n - p * i;       long long temp = __builtin_popcount(val);       if (temp <= i and val >= i) {         cout << i <<   n ;         return;       }     }     cout << -1 <<   n ;   }   int32_t main() {     fast();     long long t = 1;     for (long long i = 1; i <= t; i++) {       solve();     }     starboy1299();   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, x, k, ans = 0;     cin >> n >> k;     if (n < 3) {       cout << 0;       return 0;     }     for (int i = 0; i < n; ++i) {       cin >> x;       if (5 - x >= k) ans++;     }     cout << ans / 3;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int arr[4];     for (int i = 0; i < 4; i++) cin >> arr[i];     string strips;     cin >> strips;     int n = strips.length();     int cal = 0;     for (int i = 0; i < n; i++) {       if (strips[i] ==  1 )         cal += arr[0];       else if (strips[i] ==  2 )         cal += arr[1];       else if (strips[i] ==  3 )         cal += arr[2];       else if (strips[i] ==  4 )         cal += arr[3];     }     cout << cal;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void Kinishinaide() {     ios_base::sync_with_stdio(0);     cin.tie(0), cout.tie(0);   }   const long long N = 1e2 + 7;   const long long Mod = 1e9 + 7;   const long long Inf = 1e18 + 7;   int M, L;   long long Aq[N];   long long dp[N], Ans;   int main() {     Kinishinaide();     cin >> M >> L;     memset(dp, Inf, sizeof(dp));     for (int i = 0; i < M; i++) {       cin >> Aq[i];       if (i) {         dp[i] = min(Aq[i], (dp[i - 1] << 1));       } else {         dp[i] = Aq[i];       }     }     long long Sum = false, Ans = Inf;     for (int i = M - 1; i >= 0; i--) {       Sum += 1LL * (L / (1 << i)) * dp[i];       L = L % (1 << i);       Ans = min(Ans, Sum + 1LL * (L > 0) * dp[i]);     }     cout << Ans;   }


#include <bits/stdc++.h>   using namespace std;   const int dx[] = {1, 0, -1, 0};   const int dy[] = {0, -1, 0, 1};   const double EPS = 1e-9;   const int days[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};   const int daysleap[] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};   int main() {     int n, k;     cin >> n >> k;     vector<int> A(n);     for (unsigned int i = 0; i < (n); i++) cin >> A[i];     sort(A.begin(), A.end());     vector<int> B = A;     unique(B.begin(), B.end());     reverse(B.begin(), B.end());     vector<int> C = B;     for (unsigned int i = 0; i < (B.size()); i++) {       C[i] = count(A.begin(), A.end(), B[i]);     }     int kk = 0;     for (unsigned int i = 0; i < (B.size()); i++) {       kk += C[i];       if (kk == k) {         cout << B[i] <<     << B[i] << endl;         return 0;       }     }     cout << -1 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long power(long long a, long long b) {     long long x = 1, y = a;     while (b > 0) {       if (b % 2) {         x = (x * y) % 1000000007;       }       y = (y * y) % 1000000007;       b /= 2;     }     return x % 1000000007;   }   int main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     long long int t = 1, n, m, i, j, k, sum = 0;     while (t--) {       cin >> n;       vector<long long int> v(n);       for (i = 0; i < n; i++) cin >> v[i];       sort((v).begin(), (v).end());       for (i = 1; i < n; i++) {         v[i] += v[i - 1];       }       for (i = 1; i < n; i++) {         sum = (sum + (power(2, i - 1) *                       ((v[n - 1] - v[i - 1] - v[n - i - 1]) % 1000000007)) %                          1000000007) %               1000000007;         sum = sum % 1000000007;       }       cout << sum;     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( -O3 )   using namespace std;   const long long N = 1e6 + 5;   const long long MAX = 1e7 + 9;   long long binarySearch(long long arr[], long long l, long long r, long long x) {     if (r >= l) {       long long mid = l + (r - l) / 2;       if (arr[mid] == x) return mid;       if (arr[mid] > x) return binarySearch(arr, l, mid - 1, x);       return binarySearch(arr, mid + 1, r, x);     }     return -1;   }   void pairsort(long long a[], long long b[], long long n) {     pair<long long, long long> pairt[n];     for (long long i = 0; i < n; i++) {       pairt[i].first = a[i];       pairt[i].second = b[i];     }     sort(pairt, pairt + n);     for (long long i = 0; i < n; i++) {       a[i] = pairt[i].first;       b[i] = pairt[i].second;     }   }   long long gcd(long long a, long long b) {     if (b == 0) return a;     return gcd(b, a % b);   }   long long isprime(long long n) {     if (n < 2) return 0;     if (n < 4) return 1;     if (n % 2 == 0 or n % 3 == 0) return 0;     for (long long i = 5; i * i <= n; i += 6)       if (n % i == 0 or n % (i + 2) == 0) return 0;     return 1;   }   long long C(long long n, long long r) {     if (r > n - r) r = n - r;     long long ans = 1;     for (long long i = 1; i <= r; i++) {       ans *= n - r + i;       ans /= i;     }     return ans;   }   long long mod = 1e9 + 7;   long long modexpo(long long x, long long p) {     long long res = 1;     x = x % mod;     while (p) {       if (p % 2) res = res * x;       p >>= 1;       x = x * x % mod;       res %= mod;     }     return res;   }   long long countDistinct(long long arr[], long long n) {     sort(arr, arr + n);     long long res = 0;     for (long long i = 0; i < n; i++) {       while (i < n - 1 && arr[i] == arr[i + 1]) i++;       res++;     }     return res;   }   long long int2Bin(string s) {     reverse(s.begin(), s.end());     long long b = 1;     long long x = 0;     for (long long i = 0; i < s.length(); ++i) {       if (s[i] ==  1 ) x += b;       b *= 2;       ;     }     return x;   }   long long getSum(long long n) {     long long sum;     for (sum = 0; n > 0; sum += n % 10, n /= 10)       ;     return sum;   }   long long nex(long long i) { return (i / 10 + 1) * 10 - i; }   bool up[N];   long long a[N], ind, leave[11];   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long t;     cin >> t;     while (t--) {       long long n;       cin >> n;       pair<long long, long long> a[n];       long long i;       for (i = 0; i < n; i++) {         long long x;         cin >> x;         a[i].first = x;         a[i].second = i;       }       sort(a, a + n);       long long ans = 2 * n;       for (i = 1; i < n; i++) {         if (a[i].first == a[i - 1].first)           ans = min(ans, a[i].second - a[i - 1].second + 1);       }       if (ans == 2 * n)         cout <<  -1 n ;       else         cout << ans <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e6 + 5;   int n;   char str[N];   vector<int> g[N];   inline void init() {     scanf( %d , &n);     for (int i = 1, u, v; i < n; i++) {       scanf( %d%d , &u, &v);       g[u].push_back(v);       g[v].push_back(u);     }     scanf( %s , str + 1);     for (int i = 1; i <= n; i++) {       if (str[i] ==  W ) {         g[i].push_back(++n);         g[n].push_back(i);         g[n].push_back(n + 1);         g[n + 1].push_back(n);         g[n].push_back(n + 2);         g[n + 2].push_back(n);         n = n + 2;       }     }   }   int dfs(int p, int fa, int dest) {     if (p == dest) {       return 1;     }     for (auto e : g[p]) {       if (e ^ fa) {         int ret = dfs(e, p, dest);         if (~ret) {           return ret ^ 1;         }       }     }     return -1;   }   vector<int> d3;   inline void solve() {     d3.clear();     for (int i = 1; i <= n; i++) {       if (g[i].size() >= 4) {         puts( White );         return;       }       if (g[i].size() == 3) {         d3.push_back(i);         int _cnt = 0;         for (auto e : g[i]) {           if (g[e].size() >= 2) {             _cnt++;           }         }         if (_cnt >= 2) {           puts( White );           return;         }       }     }     if (d3.size() >= 3) {       puts( White );       return;     }     if (d3.size() == 2) {       puts((dfs(d3[0], 0, d3[1])) ? ( White ) : ( Draw ));     } else {       puts( Draw );     }   }   inline void clear() {     for (int i = 1; i <= n; i++) {       g[i].clear();     }   }   int T;   int main() {     scanf( %d , &T);     while (T--) {       init();       solve();       clear();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long mod = 1e9 + 7;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     int test = 1;     cin >> test;     while (test--) {       string s;       cin >> s;       int a = -1, b = -1, c = -1;       int ans = s.size();       for (int i = 0; i < s.size(); i++) {         if (s[i] ==  1 )           a = i;         else if (s[i] ==  2 )           b = i;         else           c = i;         if (a != -1 && b != -1 && c != -1) {           int x = min(a, min(b, c));           int y = max(a, max(b, c));           ans = min(ans, y - x + 1);         }       }       if (a != -1 && b != -1 && c != -1)         cout << ans <<   n ;       else         cout << 0 <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   const int BARIER = 0;   class Rng {    private:     static std::mt19937 engine;       public:     static std::mt19937& get_engine() { return engine; }     template <typename T>     static void set_seed(T const& seed) {       engine = std::mt19937(seed);     }     static void timebased_seed() {       engine = std::mt19937(           std::chrono::duration_cast<std::chrono::nanoseconds>(               std::chrono::high_resolution_clock::now().time_since_epoch())               .count());     }     template <typename T>     static typename std::enable_if<std::is_integral<T>::value, T>::type uniform(         T l, T r) {       return std::uniform_int_distribution<T>(l, r)(engine);     }     template <typename T>     static typename std::enable_if<std::is_floating_point<T>::value, T>::type     uniform(T l, T r) {       return std::uniform_real_distribution<T>(l, r)(engine);     }   };   std::mt19937 Rng::engine(       std::chrono::duration_cast<std::chrono::nanoseconds>(           std::chrono::high_resolution_clock::now().time_since_epoch())           .count());   class Timer {    public:     template <typename S, typename T, typename... U>     static S execute_timed(T func, std::string const& name, U&&... u) {       auto time_begin = std::chrono::high_resolution_clock::now();       S ret = func(std::forward<U>(u)...);       auto time_end = std::chrono::high_resolution_clock::now();       auto timespan = std::chrono::duration_cast<std::chrono::nanoseconds>(           time_end - time_begin);       std::cerr <<  Execution of    << name <<    took   << std::fixed                 << std::setprecision(6) << timespan.count() * 1e-9 <<   n ;       return ret;     }   };   using namespace std;   class Bigint_base10 {    public:     static constexpr int64_t BASE = 1e18;     static constexpr int DIGITS = 18;       private:     bool is_neg;     vector<int64_t> data;       public:     Bigint_base10() : is_neg(false), data(1, 0) {}     Bigint_base10(int64_t const& val) : is_neg(val < 0) {       int64_t abs_val = abs(val);       if (abs_val < BASE) {         data = {abs_val};       } else {         data = {abs_val % BASE, abs_val / BASE};       }     }     Bigint_base10 operator+(Bigint_base10 const& o) const {       Bigint_base10 ret;       ret.is_neg = is_neg;       ret.data.assign(1 + max(data.size(), o.data.size()), 0);       copy(data.begin(), data.end(), ret.data.begin());       int64_t carry = 0;       for (unsigned int i = 0; i < o.data.size(); ++i) {         ret.data[i] += o.data[i] + carry;         carry = 0;         if (ret.data[i] >= BASE) {           carry = 1;           ret.data[i] -= BASE;         }       }       for (unsigned int i = o.data.size(); carry; ++i) {         ret.data[i] += carry;         carry = 0;         if (ret.data[i] >= BASE) {           carry = 1;           ret.data[i] -= BASE;         }       }       return ret.trim();     }     Bigint_base10 operator*(int64_t const& o) const {       if (o == 0) {         return Bigint_base10(0);       }       if (o < 0) {         return operator*(-o).negate();       }       if (o & 1) {         return operator+(operator*(o - 1));       }       return operator+(*this) * (o / 2);     }     Bigint_base10& operator+=(Bigint_base10 const& o) {       *this = operator+(o);       return *this;     }     Bigint_base10& operator*=(int64_t const& o) {       *this = operator*(o);       return *this;     }     Bigint_base10& trim() {       while (data.size() > 1 && data.back() == 0) {         data.pop_back();       }       return *this;     }     bool is_zero() const {       for (auto const& e : data)         if (e) return false;       return true;     }     Bigint_base10& negate() {       is_neg = !is_neg;       if (is_zero()) is_neg = false;       return *this;     }     friend ostream& operator<<(ostream& o, Bigint_base10 const& b) {       if (b.is_neg) o <<  - ;       o << b.data.back();       o << setfill( 0 );       for (auto it = next(b.data.rbegin()); it != b.data.rend(); ++it) {         o << setw(9) << *it;       }       o << setw(0) << setfill(   );       return o;     }     friend istream& operator>>(istream& in, Bigint_base10& b) {       static string tmp;       in >> tmp;       if (tmp[0] ==  - ) {         b.is_neg = true;         tmp = tmp.substr(1, -1);       } else {         b.is_neg = false;       }       b.data.resize((tmp.size() + DIGITS - 1) / DIGITS);       unsigned int i, j;       for (i = tmp.size() - DIGITS, j = 0; i > 0; i -= DIGITS, ++j) {         b.data[j] = stoll(tmp.substr(i, DIGITS));       }       b.data[j] = stoll(tmp.substr(0, i + DIGITS));       return in;     }   };   template <size_t len>   struct Bigint_Fixedsize {     unsigned int data[len];     static constexpr unsigned int bits = 31;     Bigint_Fixedsize() { memset(data, 0, sizeof(data)); }     Bigint_Fixedsize(long long const& _a) {       memset(data, 0, sizeof(data));       unsigned long long a = _a;       data[0] = a & ((1u << bits) - 1);       data[1] = a >> bits;       data[1] &= ~(1u << bits);       if (a > ~a) {         for (size_t i = 2; i < len; ++i) {           data[i] = (1u << bits) - 1;         }       }     }     Bigint_Fixedsize& operator+=(Bigint_Fixedsize const& o) {       unsigned int carry = 0;       for (size_t i = 0; i < len; ++i) {         data[i] += o.data[i] + carry;         carry = data[i] >> bits;         data[i] &= ~(1u << bits);       }       return *this;     }     Bigint_Fixedsize& operator-=(Bigint_Fixedsize const& o) {       unsigned int carry = 0;       for (size_t i = 0; i < len; ++i) {         data[i] -= o.data[i] + carry;         carry = data[i] >> bits;         data[i] &= ~(1u << bits);       }       return *this;     }     Bigint_Fixedsize operator+(Bigint_Fixedsize const& o) const {       Bigint_Fixedsize ret(*this);       ret += o;       return ret;     }     Bigint_Fixedsize operator-(Bigint_Fixedsize const& o) const {       Bigint_Fixedsize ret(*this);       ret -= o;       return ret;     }     void multo(Bigint_Fixedsize const& o, Bigint_Fixedsize& ret) const {       static unsigned int tmp[len + 1];       memset(tmp, 0, sizeof(tmp));       for (size_t i = 0; i < len; ++i) {         unsigned long long val = 0;         for (size_t j = 0; j < len - i; ++j) {           val += data[i] * (unsigned long long)o.data[j] + tmp[i + j];           tmp[i + j] = val & ((1u << bits) - 1);           val >>= bits;         }       }       memcpy(ret.data, tmp, sizeof(ret.data));     }     Bigint_Fixedsize& operator*=(Bigint_Fixedsize const& o) {       multo(o, *this);       return *this;     }     Bigint_Fixedsize operator*(Bigint_Fixedsize const& o) const {       Bigint_Fixedsize ret;       multo(o, ret);       return ret;     }     Bigint_Fixedsize& negate() {       unsigned int carry = 0;       for (size_t i = 0; i < len; ++i) {         data[i] = ~data[i] + !carry;         carry = (data[i] >> bits);         data[i] &= ~(1u << bits);       }       return *this;     }     Bigint_Fixedsize operator-() const {       Bigint_Fixedsize ret(*this);       ret.negate();       return ret;     }     bool operator<(Bigint_Fixedsize const& o) const {       if (data[len - 1] >> (bits - 1) != o.data[len - 1] >> (bits - 1)) {         return data[len - 1] >> (bits - 1);       }       for (size_t i = len - 1; ~i; --i) {         if (data[i] != o.data[i]) return data[i] < o.data[i];       }       return false;     }     bool operator>(Bigint_Fixedsize const& o) const { return o < *this; }     bool operator<=(Bigint_Fixedsize const& o) const { return !(operator>(o)); }     bool operator>=(Bigint_Fixedsize const& o) const { return !(operator<(o)); }     bool operator==(Bigint_Fixedsize const& o) const {       for (size_t i = 0; i < len; ++i) {         if (data[i] != o.data[i]) return false;       }       return true;     }     bool operator!=(Bigint_Fixedsize const& o) const { return !operator==(o); }     bool operator!() const {       for (size_t i = 0; i < len; ++i) {         if (data[i]) return false;       }       return true;     }     bool is_negative() const { return data[len - 1] >> (bits - 1); }     void print_binary(ostream& o, Bigint_Fixedsize const& b) {       o <<  [ ;       for (size_t i = len; i > 0; --i) {         o << bitset<bits>(b.data[i - 1]);       }       o <<  ] ;     }     friend ostream& operator<<(ostream& o, Bigint_Fixedsize const& b) {       if (b.is_negative()) {         return o <<  -  << -b <<   n ;       }       Bigint_base10 ret(0);       int64_t base = 1u << bits;       for (int i = len - 1; i >= 0; --i) {         ret *= base;         ret += Bigint_base10(b.data[i]);       }       o << ret;       return o;     }     explicit operator long double() const {       if (is_negative()) {         return (long double)operator-();       }       long double ret = 0.0;       long double base = 1u << bits;       for (int i = len - 1; i >= 0; --i) {         ret = ret * base + data[i];       }       return ret;     }     friend istream& operator>>(istream& i, Bigint_Fixedsize& b) {       int64_t tmp;       i >> tmp;       b = Bigint_Fixedsize(tmp);       return i;     }   };   template <size_t len>   struct Bigint_Fixedsize_Fast {     unsigned int data[len];     uint16_t siz;     bool sign;     static constexpr unsigned int bits = 32;     Bigint_Fixedsize_Fast() {       data[0] = 0;       siz = 1;       sign = false;     }     Bigint_Fixedsize_Fast(long long a) {       sign = false;       if (a < 0) {         sign = true;         a = -a;       }       siz = 0;       do {         long long b = a >> bits;         data[siz] = a - (b << bits);         a = b;         ++siz;       } while (a);     }     void trim() {       while (siz > 1 && !data[siz - 1]) --siz;     }     int comp_unsigned(Bigint_Fixedsize_Fast const& o) const {       uint16_t lim = min(siz, o.siz);       for (unsigned int i = lim; i < siz; ++i) {         if (data[i]) {           return 1;         }       }       for (unsigned int i = lim; i < o.siz; ++i) {         if (o.data[i]) {           return -1;         }       }       for (unsigned int i = lim - 1; i + 1; --i) {         if (data[i] != o.data[i]) {           return data[i] < o.data[i] ? -1 : 1;         }       }       return 0;     }     int comp(Bigint_Fixedsize_Fast const& o) const {       int sign_mul = 1 - 2 * sign;       if (sign != o.sign) {         return sign_mul;       }       return sign_mul * comp_unsigned(o);     }     bool operator<(Bigint_Fixedsize_Fast const& o) const { return comp(o) < 0; }     bool operator>(Bigint_Fixedsize_Fast const& o) const { return comp(o) > 0; }     bool operator<=(Bigint_Fixedsize_Fast const& o) const { return comp(o) <= 0; }     bool operator>=(Bigint_Fixedsize_Fast const& o) const { return comp(o) >= 0; }     bool operator==(Bigint_Fixedsize_Fast const& o) const { return comp(o) == 0; }     bool operator!=(Bigint_Fixedsize_Fast const& o) const { return comp(o) != 0; }     bool operator!() const { return operator==(ZERO); }     Bigint_Fixedsize_Fast operator-() const {       Bigint_Fixedsize_Fast ret(*this);       if (!!ret) {         ret.sign ^= 1;       }       return ret;     }     Bigint_Fixedsize_Fast operator*(Bigint_Fixedsize_Fast const& o) const {       Bigint_Fixedsize_Fast ret;       ret.siz = min(siz + o.siz, (int)len);       ret.sign = (sign != o.sign);       fill(ret.data, ret.data + ret.siz, 0);       for (unsigned int i = 0; i < siz; ++i) {         unsigned long long carry = 0, carry_2;         for (unsigned int j = 0; j < o.siz; ++j) {           carry += data[i] * (unsigned long long)o.data[j] + ret.data[i + j];           carry_2 = carry >> bits;           ret.data[i + j] = carry - (carry_2 << bits);           carry = carry_2;         }         for (unsigned int j = i + o.siz; carry; ++j) {           carry += ret.data[j];           carry_2 = carry >> bits;           ret.data[j] = carry - (carry_2 << bits);           carry = carry_2;         }       }       ret.trim();       return ret;     }     Bigint_Fixedsize_Fast& operator*=(Bigint_Fixedsize_Fast const& o) {       *this = operator*(o);       return *this;     }     static void unsigned_add(Bigint_Fixedsize_Fast& ret,                              Bigint_Fixedsize_Fast const& A,                              Bigint_Fixedsize_Fast const& B) {       const Bigint_Fixedsize_Fast *a = &A, *b = &B;       if (a->siz < b->siz) swap(a, b);       ret.sign = A.sign;       unsigned long long carry = 0, carry_2;       unsigned int j;       for (j = 0; j < b->siz; ++j) {         carry += (unsigned long long)a->data[j] + (unsigned long long)b->data[j];         carry_2 = carry >> bits;         ret.data[j] = carry - (carry_2 << bits);         carry = carry_2;       }       for (; j < a->siz; ++j) {         carry += a->data[j];         carry_2 = carry >> bits;         ret.data[j] = carry - (carry_2 << bits);         carry = carry_2;       }       if (carry) {         ret.data[j++] = carry;       }       ret.siz = j;       ret.trim();     }     static void unsigned_subtract(Bigint_Fixedsize_Fast& ret,                                   Bigint_Fixedsize_Fast const& A,                                   Bigint_Fixedsize_Fast const& B) {       int com = A.comp_unsigned(B);       if (com == 0) {         ret.sign = false;         ret.siz = 1;         ret.data[0] = 0;         return;       }       ret.sign = A.sign;       const Bigint_Fixedsize_Fast *a = &A, *b = &B;       if (com < 0) {         ret.sign ^= true;         swap(a, b);       }       unsigned int min_siz = min(A.siz, B.siz);       unsigned long long carry = 0, carry_2;       unsigned int j;       for (j = 0; j < min_siz; ++j) {         carry += (unsigned long long)a->data[j] - (unsigned long long)b->data[j];         carry_2 = carry >> bits;         ret.data[j] = carry - (carry_2 << bits);         carry = -(carry_2 & 1u);       }       for (; carry; ++j) {         carry += a->data[j];         carry_2 = carry >> bits;         ret.data[j] = carry - (carry_2 << bits);         carry = -(carry_2 & 1u);       }       copy(a->data + j, a->data + a->siz, ret.data + j);       ret.siz = a->siz;       ret.trim();     }     static void add(Bigint_Fixedsize_Fast& ret, Bigint_Fixedsize_Fast const& A,                     Bigint_Fixedsize_Fast const& B) {       if (A.sign == B.sign) {         unsigned_add(ret, A, B);       } else {         unsigned_subtract(ret, A, B);       }     }     static void sub(Bigint_Fixedsize_Fast& ret, Bigint_Fixedsize_Fast const& A,                     Bigint_Fixedsize_Fast const& B) {       if (A.sign != B.sign) {         unsigned_add(ret, A, B);       } else {         unsigned_subtract(ret, A, B);       }     }     Bigint_Fixedsize_Fast operator+(Bigint_Fixedsize_Fast const& o) const {       Bigint_Fixedsize_Fast ret;       add(ret, *this, o);       return ret;     }     Bigint_Fixedsize_Fast& operator+=(Bigint_Fixedsize_Fast const& o) {       add(*this, *this, o);       return *this;     }     Bigint_Fixedsize_Fast operator-(Bigint_Fixedsize_Fast const& o) const {       Bigint_Fixedsize_Fast ret;       sub(ret, *this, o);       return ret;     }     Bigint_Fixedsize_Fast operator-=(Bigint_Fixedsize_Fast const& o) {       sub(*this, *this, o);       return *this;     }     void print_binary(ostream& o, Bigint_Fixedsize_Fast const& b) {       o <<  [ ;       o << sign <<  /  << len <<  / ;       for (size_t i = siz; i > 0; --i) {         o << bitset<bits>(b.data[i - 1]);       }       o <<  ] ;     }     friend ostream& operator<<(ostream& o, Bigint_Fixedsize_Fast const& b) {       if (b.sign) {         return o <<  -  << -b;       }       Bigint_base10 ret(0);       int64_t base = 1ll << bits;       for (int i = b.siz - 1; i >= 0; --i) {         ret *= base;         ret += Bigint_base10(b.data[i]);       }       o << ret;       return o;     }     explicit operator long double() const {       if (sign) {         return (long double)operator-();       }       long double ret = 0.0;       long double base = 1ll << bits;       for (int i = siz - 1; i >= 0; --i) {         ret = ret * base + data[i];       }       return ret;     }     friend istream& operator>>(istream& i, Bigint_Fixedsize_Fast& b) {       int64_t tmp;       i >> tmp;       b = Bigint_Fixedsize_Fast(tmp);       return i;     }     static const Bigint_Fixedsize_Fast ZERO;   };   template <size_t len>   const Bigint_Fixedsize_Fast<len> Bigint_Fixedsize_Fast<len>::ZERO(0);   template <typename FLOAT>   class Lp_Seidel {    private:     vector<FLOAT> proj_down(vector<FLOAT> const& vec, vector<FLOAT> const& plane,                             size_t j) {       vector<FLOAT> ret(vec.size() - 1);       if (plane[j] < FLOAT(0)) {         for (size_t i = 0; i + 1 < vec.size(); ++i) {           ret[i] = vec[j] * plane[i + (i >= j)] - vec[i + (i >= j)] * plane[j];         }       } else {         for (size_t i = 0; i + 1 < vec.size(); ++i) {           ret[i] = vec[i + (i >= j)] * plane[j] - vec[j] * plane[i + (i >= j)];         }       }       return ret;     }     vector<FLOAT> proj_up(vector<FLOAT> const& vec, vector<FLOAT> const& plane,                           size_t j) {       vector<FLOAT> ret(vec.size() + 1);       copy(vec.begin(), vec.begin() + j, ret.begin());       copy(vec.begin() + j, vec.end(), ret.begin() + j + 1);       for (size_t i = 0; i < vec.size(); ++i) {         ret[j] += vec[i] * plane[i + (i >= j)];       }       FLOAT denom = plane[j];       if (denom < FLOAT(0)) {         denom = -denom;       }       for (size_t i = 0; i < vec.size(); ++i) {         ret[i + (i >= j)] *= denom;       }       if (plane[j] >= FLOAT(0)) {         ret[j] = -ret[j];       }       return ret;     }     FLOAT planescal(vector<FLOAT> const& x, vector<FLOAT> const& a) {       FLOAT ret = 0;       for (size_t i = 0; i < x.size(); ++i) {         ret += x[i] * a[i];       }       return ret;     }     vector<FLOAT> solve(vector<vector<FLOAT>> const& A, vector<FLOAT> const& c,                         int d, FLOAT const& barier_loc) {       int n = A.size();       if (d == 1) {         vector<FLOAT> ret(2);         ret[0] = (c[0] < FLOAT(0) ? -barier_loc : barier_loc);         ret[1] = 1ull;         for (int i = 0; i < n; ++i) {           if (ret[0] * A[i][0] + ret[1] * A[i].back() > FLOAT(0)) {             if (!A[i][0]) {               do {               } while (0);               return vector<FLOAT>();             }             ret[0] = -A[i].back();             ret[1] = A[i][0];             if (ret[1] < FLOAT(0)) {               ret[1] = -ret[1];               ret[0] = -ret[0];             }             do {             } while (0);           }         }         for (int i = 0; i < n; ++i) {           if (ret[0] * A[i][0] + ret[1] * A[i].back() > FLOAT(0)) {             do {             } while (0);             return vector<FLOAT>();           }         }         return ret;       }       FLOAT barier_next = barier_loc * barier_loc;       vector<FLOAT> x(d + 1);       for (int i = 0; i < d; ++i) {         x[i] = (c[i] < FLOAT(0) ? -barier_loc : barier_loc);       }       x.back() = FLOAT(1);       for (size_t i = 0; i < A.size(); ++i) {         if (planescal(x, A[i]) > FLOAT(0)) {           int k = 0;           while (k < d && !A[i][k]) ++k;           if (k == d) {             do {             } while (0);             return vector<FLOAT>();           }           vector<vector<FLOAT>> A2(i);           for (size_t j = 0; j < A2.size(); ++j) {             A2[j] = proj_down(A[j], A[i], k);           }           shuffle(A2.begin(), A2.end(), Rng::get_engine());           do {           } while (0);           vector<FLOAT> c2 = proj_down(c, A[i], k);           vector<FLOAT> x2 = solve(A2, c2, d - 1, barier_next);           if (x2.empty()) return x2;           x = proj_up(x2, A[i], k);           do {           } while (0);           do {           } while (0);           do {           } while (0);         }       }       return x;     }       public:     vector<FLOAT> solve(vector<vector<FLOAT>> const& A, vector<FLOAT> const& c,                         const FLOAT& barier = FLOAT((long long)1e9)) {       return solve(A, c, c.size(), barier);     }     vector<FLOAT> solve(vector<vector<FLOAT>> A, vector<FLOAT> const& b,                         vector<FLOAT> const& c) {       for (unsigned int i = 0; i < A.size(); ++i) {         A[i].push_back(-b[i]);       }       return solve(A, c);     }   };   template <typename Big_Int>   class Lp_Clarkson {    private:     vector<int> sample_subset(vector<int64_t> const& weight, unsigned int siz) {       int64_t total_weight = accumulate(weight.begin(), weight.end(), 0ll);       vector<int64_t> samples;       while (samples.size() < siz) {         int64_t new_sample = Rng::uniform<int64_t>(0, total_weight - 1);         if (find(samples.begin(), samples.end(), new_sample) == samples.end()) {           samples.push_back(new_sample);         }       }       sort(samples.begin(), samples.end());       vector<int> ret;       int64_t left_weight = 0;       for (unsigned int i = 0, j = 0; i < weight.size() && j < samples.size();) {         if (samples[j] < left_weight + weight[i]) {           ret.push_back(i);           ++j;         } else {           left_weight += weight[i];           ++i;         }       }       return ret;     }     bool is_satisfied(vector<Big_Int> const& x, vector<Big_Int> const& a) {       Big_Int ret = 0;       for (size_t i = 0; i < x.size(); ++i) {         ret += x[i] * a[i];       }       return ret <= Big_Int(0);     }     vector<Big_Int> solve(vector<vector<Big_Int>> const& A,                           vector<Big_Int> const& c,                           const unsigned int sample_size) {       Lp_Seidel<Big_Int> sub_lp;       if (A.size() < sample_size) {         return sub_lp.solve(A, c);       } else {         int equations = A.size();         int variables = c.size();         vector<int64_t> weight(equations, 1);         vector<Big_Int> x;         vector<vector<Big_Int>> subproblem_A;         vector<char> is_violated(equations, 0);         for (unsigned int iteration = 1;; ++iteration) {           subproblem_A.clear();           vector<int> subspace = sample_subset(weight, sample_size);           for (int const& e : subspace) {             subproblem_A.push_back(A[e]);           }           x = sub_lp.solve(subproblem_A, c);           if (x.empty()) {             return x;           }           int64_t total_violated = 0;           for (int i = 0; i < equations; ++i) {             is_violated[i] = !is_satisfied(x, A[i]);             if (is_violated[i]) {               total_violated += weight[i];             }           }           if (total_violated == 0) {             cerr <<  Iterations:   << iteration;             cerr <<  , max weight:   << *max_element(weight.begin(), weight.end())                  <<   n ;             break;           }           if (total_violated * 3 * variables <=               accumulate(weight.begin(), weight.end(), 0ll)) {             for (int i = 0; i < equations; ++i) {               if (is_violated[i]) {                 weight[i] *= 2;               }             }           }         }         return x;       }     }       public:     vector<Big_Int> solve(vector<vector<Big_Int>> const& A,                           vector<Big_Int> const& c) {       return solve(A, c, c.size() * c.size() * 4);     }     vector<Big_Int> solve(vector<vector<Big_Int>> A, vector<Big_Int> const& b,                           vector<Big_Int> const& c) {       for (unsigned int i = 0; i < A.size(); ++i) {         A[i].push_back(-b[i]);       }       return solve(A, c);     }   };   template <typename Big_Int>   void test_factorial(unsigned int n, bool debug = false) {     std::cout <<  Computing   << n <<  ! n ;     Big_Int val(1);     for (unsigned int i = 1; i <= n; ++i) {       val *= i;       if (debug) std::cerr << i <<   :   << val <<   n ;     }     std::cerr <<  Printing n ;     std::cout << val << endl;   }   template <typename Big_Int>   void test_addsub(int n) {     Big_Int a(5432123456789ll);     Big_Int b(9876543210123ll);     Big_Int c;     for (int it = 0; it < 4 * n; ++it) {       std::cout << a <<   +   << b <<   =   << a + b <<   n ;       std::cout << b <<   +   << a <<   =   << b + a <<   n ;       std::cout << a <<   -   << b <<   =   << a - b <<   n ;       std::cout << b <<   -   << a <<   =   << b - a <<   n ;       c = a;       c += b;       std::cout << a <<   +   << b <<   =   << c <<   n ;       c = b;       c += a;       std::cout << b <<   +   << a <<   =   << c <<   n ;       c = a;       c -= b;       std::cout << a <<   -   << b <<   =   << c <<   n ;       c = b;       c -= a;       std::cout << b <<   -   << a <<   =   << c <<   n ;       a = -a;       if (it % 4 == 3) {         a *= it;       } else {         swap(a, b);       }     }   }   template <typename Big_Int>   void test_addmul(int n, int k) {     std::cout <<  Addmul test   << n <<     << k <<   n ;     ;     Rng::set_seed(635241);     Big_Int ret(0);     for (int i = 0; i < n; ++i) {       Big_Int cur(1);       for (int j = 0; j < k; ++j) {         Big_Int mu(Rng::uniform(1ll, (long long)1e15));         cur *= mu;       }       ret += cur;     }     std::cout << ret <<   n ;   }   void test_timer() {     std::function<int64_t(int64_t)> fib = [&](int64_t x) {       return x < 2 ? x : fib(x - 1) + fib(x - 2);     };     Timer::execute_timed<int64_t>(fib,  Timer test , 35);     Timer::execute_timed<int64_t>(fib,  Timer test , 40);   }   template <typename Big_Int, typename Solver>   void test_lp(std::string const& path) {     std::cerr <<  LP Test:   << path <<   n ;     std::ifstream in;     in.open(path.c_str());     int variables, constraints;     in >> variables >> constraints;     std::vector<std::vector<Big_Int>> A(constraints,                                         std::vector<Big_Int>(variables));     std::vector<Big_Int> b(constraints), c(variables);     for (auto& e : c) in >> e;     for (int i = 0; i < constraints; ++i) {       for (auto& e : A[i]) in >> e;       in >> b[i];     }     std::function<std::vector<Big_Int>()> solve = [&]() {       Solver solver;       return solver.solve(A, b, c);     };     std::vector<Big_Int> solution =         Timer::execute_timed<vector<Big_Int>>(solve,  solve LP );     std::cerr <<  Solution: n ;     for (auto& e : solution) {       std::cerr << e <<    ;     }     cerr <<   n ;   }   template <typename Big_Int, typename Solver>   void test_enclosing_annulus(int n) {     cerr <<  Enclosing annulus test (  << n <<  ) n ;     cerr <<  Int:   << typeid(Big_Int).name()          <<  , Solver:   << typeid(Solver).name() <<   n ;     Rng::set_seed(1234);     vector<pair<int, int>> pts(n);     for (auto& e : pts) {       e.first = Rng::uniform(-10000, 10000);       e.second = Rng::uniform(-10000, 10000);     }     Rng::set_seed(24680);     vector<vector<Big_Int>> A;     vector<Big_Int> b, c;     c = {Big_Int(0), Big_Int(0), -1, 1};     for (auto const& e : pts) {       A.push_back({Big_Int(-2 * e.first), Big_Int(-2 * e.second), -1, 0});       b.emplace_back(-e.first * e.first - e.second * e.second);       A.push_back({Big_Int(2 * e.first), Big_Int(2 * e.second), 0, 1});       b.emplace_back(e.first * e.first + e.second * e.second);     }     std::function<std::vector<Big_Int>()> solve = [&]() {       Solver solver;       return solver.solve(A, b, c);     };     std::vector<Big_Int> solution =         Timer::execute_timed<vector<Big_Int>>(solve,  solve enclosing circle LP );     std::cerr <<  Solution: n ;     for (auto& e : solution) {       std::cerr << e <<    ;     }     cerr <<   n ;     if (!solution.empty()) {       Big_Int r_sq = solution[2] * solution[4] - solution[1] * solution[1] +                      solution[2] * solution[2];       Big_Int R_sq = solution[3] * solution[4] - solution[1] * solution[1] +                      solution[2] * solution[2];       Big_Int area_numerator = solution[3] - solution[2];       cerr <<  area^2:   << (long double)area_numerator / (long double)solution[4]            <<   n ;       cerr <<  r^2:              << (long double)r_sq / (long double)(solution[4] * solution[4])            <<   n ;       cerr <<  R^2:              << (long double)R_sq / (long double)(solution[4] * solution[4])            <<   n ;     }     cerr <<   n ;   }   void test_codeforces_549E() {     auto codeforces_549E = [&]() {       using DOUBLE = Bigint_Fixedsize_Fast<12>;       int N, M;       cin >> N >> M;       vector<vector<DOUBLE>> A;       vector<DOUBLE> b, c(4);       A.reserve(N + M);       vector<pair<int, int>> p2(N), p(M);       for (int i = 0; i < N; ++i) {         cin >> p2[i].first >> p2[i].second;       }       for (int i = 0; i < M; ++i) {         cin >> p[i].first >> p[i].second;       }       for (int it = 0; it < 2; ++it) {         N = p.size();         M = p2.size();         A.clear();         b.clear();         for (int i = 0; i < N; ++i) {           int x, y, z;           tie(x, y) = p[i];           z = x * x + y * y;           A.push_back({x, y, 1, 1});           b.push_back(z);         }         for (int i = 0; i < M; ++i) {           int x, y, z;           tie(x, y) = p2[i];           z = x * x + y * y;           A.push_back({-x, -y, -1, 1});           b.push_back(-z);         }         c[3] = 1;         Lp_Clarkson<DOUBLE> solver;         vector<DOUBLE> x = solver.solve(A, b, c);         if (!x.empty()) {           DOUBLE res = 0;           for (size_t i = 0; i < c.size(); ++i) res += x[i] * c[i];           DOUBLE dist = res;           if (dist > DOUBLE(0)) {             cout <<  YES n ;             return;           }         } else {         }         p.swap(p2);       }       cout <<  NO n ;     };     int TTT = 1;     while (TTT--) {       codeforces_549E();     }   }   signed test_codejam_2017_4_D() {     using DOUBLE = Bigint_Fixedsize_Fast<25>;     freopen( codejam_d.in ,  r , stdin);     freopen( codejam_d.out ,  w , stdout);     cin.tie(0);     ios_base::sync_with_stdio(false);     int T;     cin >> T;     for (int cas = 1; cas <= T; ++cas) {       cout <<  Case #  << cas <<  :  ;       cerr <<  Case #  << cas <<  :  ;       int n;       cin >> n;       vector<vector<DOUBLE>> A;       vector<DOUBLE> b, c(4);       A.reserve(n);       do {       } while (0);       for (int i = 0; i < n; ++i) {         int x, y, z;         cin >> x >> y >> z;         A.push_back({x, y, z, 1});         b.push_back(0);       }       c[3] = 1;       Lp_Clarkson<DOUBLE> solver;       vector<DOUBLE> x = solver.solve(A, b, c);       bool did = false;       if (!x.empty()) {         if (x[3] > DOUBLE(0)) {           did = true;         }       }       if (did)         cout <<  NO n ;       else         cout <<  YES n ;       cerr << (did ?  NO n  :  YES n );     }     return 0;   }   using namespace std;   int main() {     test_codeforces_549E();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long double gr = (1 + sqrt(5)) / 2;   long long n, k, c, res[107], mres;   string s;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> k >> s;     c = 1;     for (int i = 0; i < n; i++) {       if (i > 0) {         if (s[i] == s[i - 1]) {           c++;           if (c == k) {             c = 0;             res[s[i] -  a  + 1]++;           }         } else           c = 1;       }       if (c == k) {         c = 0;         res[s[i] -  a  + 1]++;       }     }     for (int i = 1; i <= 26; i++) mres = max(mres, res[i]);     cout << mres << endl;   }


#include <bits/stdc++.h>   using namespace std;   char s[105];   int main(void) {     int n, f;     while (cin >> n) {       scanf( %s , s);       f = 0;       for (int l = (1); l <= (n); ++l) {         for (int j = (0); j <= (n - 4 * l - 1); ++j) {           if (j + 4 * l >= n) break;           if (s[j] ==  *  && s[j + l] ==  *  && s[j + 2 * l] ==  *  &&               s[j + 3 * l] ==  *  && s[j + 4 * l] ==  * ) {             f = 1;             break;           }         }         if (f) break;       }       if (f)         cout <<  yes n ;       else         cout <<  no n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> thing[20005 * 4], query[20005 * 4];   struct Thing {     int cost, happy;   } d[20005];   int cost[20005], f[4005], tree[20005 * 4], tmp[16][4005], ans[20005];   int x, i, n, m, p, y;   void build1(int k, int l, int r) {     if (x <= l && r <= y) {       thing[k].push_back(i);       return;     }     int mid = (l + r) >> 1;     if (x <= mid) build1(k << 1, l, mid);     if (y > mid) build1(k << 1 | 1, mid + 1, r);   }   void build2(int k, int l, int r) {     tree[k] = 1;     int mid = (l + r) >> 1;     if (l == r) {       query[k].push_back(i);       return;     }     if (x <= mid)       build2(k << 1, l, mid);     else       build2(k << 1 | 1, mid + 1, r);   }   void work(int k, int l, int r, int dep) {     if (thing[k].size()) {       memcpy(tmp[dep], f, sizeof(f));       for (int i = 0; i < thing[k].size(); i++) {         int lose = d[thing[k][i]].cost, win = d[thing[k][i]].happy;         for (int j = 4000; j >= lose; j--) f[j] = max(f[j], f[j - lose] + win);       }     }     if (l == r) {       for (int i = 0; i < query[k].size(); i++)         ans[query[k][i]] = f[cost[query[k][i]]];       if (thing[k].size()) memcpy(f, tmp[dep], sizeof(tmp[dep]));       return;     }     int mid = (l + r) >> 1;     work(k << 1, l, mid, dep + 1);     work(k << 1 | 1, mid + 1, r, dep + 1);     if (thing[k].size()) memcpy(f, tmp[dep], sizeof(tmp[dep]));   }   int main() {     scanf( %d %d , &n, &p);     for (i = 1; i <= n; i++) {       scanf( %d%d%d , &d[i].cost, &d[i].happy, &x);       y = x + p - 1;       build1(1, 1, 20000);     }     scanf( %d , &m);     for (i = 1; i <= m; i++) {       scanf( %d%d , &x, &cost[i]);       build2(1, 1, 20000);     }     work(1, 1, 20000, 0);     for (i = 1; i <= m; i++) printf( %d n , ans[i]);   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   T sqr(T a) {     return a * a;   }   #pragma comment(linker,  /STACK:16777216 )   int n;   char s[105];   string str;   int main() {     gets(s);     str = s;     n = strlen(s);     for (int i = n - 1; i > 0; --i)       for (int j = 0; j <= n - i; ++j)         for (int k = j + 1; k <= n - i; ++k)           if (str.substr(j, i) == str.substr(k, i)) {             printf( %d , i);             return 0;           }     printf( 0 );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 205;   int read() {     int x = 0, f = 1;     char ch;     while (!isdigit(ch = getchar())) (ch ==  - ) && (f = -f);     for (x = ch ^ 48; isdigit(ch = getchar());          x = (x << 3) + (x << 1) + (ch ^ 48))       ;     return x * f;   }   vector<int> vec[N];   int n, s, t, tim, cnt = 1, a[N], head[N], vis[N], level[N], is[20010];   struct edge {     int v, w, nxt;   } e[N * N];   void add(int x, int y, int w) {     e[++cnt] = (edge){y, w, head[x]};     head[x] = cnt;     e[++cnt] = (edge){x, 0, head[y]};     head[y] = cnt;   }   void init(int n) {     is[1] = 1;     for (int i = 2; i <= n; ++i) {       if (is[i]) continue;       for (int j = i + i; j <= n; j += i) is[j] = 1;     }   }   int bfs() {     queue<int> Q;     Q.push(s);     memset(level, 0, sizeof(level));     level[s] = 1;     while (!Q.empty()) {       int x = Q.front();       Q.pop();       for (int i = head[x]; i; i = e[i].nxt) {         int v = e[i].v, w = e[i].w;         if (w && !level[v]) level[v] = level[x] + 1, Q.push(v);       }     }     return level[t] != 0;   }   int dfs(int x, int flow) {     if (x == t || !flow) return flow;     int up = 0;     for (int i = head[x]; i; i = e[i].nxt) {       int v = e[i].v, w = e[i].w;       if (w && level[v] == level[x] + 1) {         int tmp = dfs(v, min(flow, w));         e[i].w -= tmp, e[i ^ 1].w += tmp;         flow -= tmp, up += tmp;         if (!flow) break;       }     }     if (!up) level[x] = 0;     return up;   }   int Dinic() {     int maxflow = 0;     while (bfs()) maxflow += dfs(s, 2e9);     return maxflow;   }   void find(int x) {     vis[x] = 1;     vec[tim].push_back(x);     for (int i = head[x]; i; i = e[i].nxt)       if (!vis[e[i].v] && e[i | 1].w == 1) find(e[i].v);   }   int main() {     n = read();     s = 0;     t = n + 1;     init(20000);     for (int i = 1; i <= n; ++i) a[i] = read();     for (int i = 1; i <= n; ++i)       if (a[i] & 1)         add(i, t, 2);       else         add(s, i, 2);     for (int i = 1; i <= n; ++i) {       if (a[i] & 1) continue;       for (int j = 1; j <= n; ++j)         if (!is[a[i] + a[j]]) add(i, j, 1);     }     if (Dinic() != n) return puts( Impossible ), 0;     for (int i = 1; i <= n; ++i)       if (!vis[i]) ++tim, find(i);     printf( %d n , tim);     for (int i = 1; i <= tim; ++i) {       printf( %d  , vec[i].size());       for (int j = 0; j < vec[i].size(); ++j) printf( %d  , vec[i][j]);       puts(  );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int const maxn = (int)1e4 + 111;   int const inf = (1 << 30) - 1;   int k;   int a[4];   int t[4];   int d[maxn][4];   int first[maxn][4];   int main() {     cin >> k;     for (int i = 1; i <= 3; i++) cin >> a[i];     for (int i = 1; i <= 3; i++) cin >> t[i];     for (int j = 1; j <= 3; j++) {       for (int i = 1; i <= k; i++) {         int v = -1;         for (int q = 1; q <= a[j]; q++) {           if (v == -1 || first[q][j] < first[v][j]) {             v = q;           }         }         d[i][j] = max(d[i][j - 1], first[v][j]) + t[j];         first[v][j] = d[i][j];       }     }     cout << d[k][3] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long a, b, qa, qb, answer;   int i, j, p, k, lcm, d;   int dist[1000000];   char inq[1000000];   int gcd(int x, int y) {     if ((x % y) == 0) return y;     return gcd(y, x % y);   }   void ComputeDist() {     for (i = 0; i <= lcm; i++) {       dist[i] = lcm + 1;       inq[i] = 0;     }     dist[0] = 0;     queue<int> q;     q.push(0);     inq[0] = 1;     while (q.size() > 0) {       i = q.front();       q.pop();       inq[i] = 0;       if (i + 1 <= lcm && (1 + dist[i] < dist[i + 1])) {         dist[i + 1] = 1 + dist[i];         if (!inq[i + 1]) {           q.push(i + 1);           inq[i + 1] = 1;         }       }       for (j = 2; j <= k; j++)         if (i % j == 0) {           for (p = 1; p < j; p++)             if (i + p <= lcm && (1 + dist[i] < dist[i + p])) {               dist[i + p] = 1 + dist[i];               if (!inq[i + p]) {                 q.push(i + p);                 inq[i + p] = 1;               }             }         }     }   }   void ComputeDist2(int end, int start) {     for (i = 0; i <= start; i++) {       dist[i] = start + 1;       inq[i] = 0;     }     dist[start] = 0;     queue<int> q;     q.push(start);     inq[start] = 1;     while (q.size() > 0) {       i = q.front();       q.pop();       inq[i] = 0;       if (i - 1 >= end && (1 + dist[i] < dist[i - 1])) {         dist[i - 1] = 1 + dist[i];         if (!inq[i - 1]) {           q.push(i - 1);           inq[i - 1] = 1;         }       }       for (j = 2; j <= k; j++)         if (i % j > 0) {           p = i % j;           if (i - p >= end && (1 + dist[i] < dist[i - p])) {             dist[i - p] = 1 + dist[i];             if (!inq[i - p]) {               q.push(i - p);               inq[i - p] = 1;             }           }         }     }   }   int main() {     scanf( %I64d %I64d %d , &a, &b, &k);     lcm = 1;     for (i = 2; i <= k; i++) {       d = gcd(i, lcm);       lcm *= (i / d);     }     ComputeDist();     qa = a / lcm;     qb = b / lcm;     answer = 0;     if (qa > qb + 1) {       answer += dist[a % lcm];       answer += dist[lcm] * (qa - qb - 1);       a = (qb + 1) * lcm;     }     ComputeDist2(b % lcm, a - qb * lcm);     answer += dist[b % lcm];     printf( %I64d n , answer);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MaxN = 100005, LOG = 22;   int n, fth[MaxN], poz[MaxN], fr[MaxN], w[MaxN], sz[MaxN], nrzone = 1;   pair<int, int> v[MaxN];   int Find(int x) {     if (!fth[x]) return x;     return fth[x] = Find(fth[x]);   }   void Join(int x, int y) {     int X = Find(x), Y = Find(y);     if (X != Y) fth[X] = Y;   }   void Solve(int a, int b) {     if (a < b) {       fr[sz[Find(a)]]--;       fr[sz[Find(b)]]--;       nrzone--;       fr[sz[Find(a)] + sz[Find(b)]]++;       sz[Find(b)] += sz[Find(a)];       Join(a, b);     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> n;     for (int i = 1; i <= n; ++i) {       cin >> v[i].first;       w[i] = v[i].first;       v[i].second = i;     }     if (n == 1) {       cout << v[1].first + 1 <<   n ;       return 0;     }     sort(v + 1, v + n + 1);     v[n + 1].first = v[n].first + 1;     for (int i = 1; i <= n; ++i) {       poz[i] = v[i].second;       w[v[i].second] = i;     }     int maxk = 1, nrzonemax = 1;     fr[1] = 1;     sz[1] = 1;     for (int k = 2; k < n; ++k) {       int pozz = poz[k];       fr[1]++;       nrzone++;       sz[k] = 1;       if (pozz != 1) Solve(w[pozz - 1], k);       if (pozz != n) Solve(w[pozz + 1], k);       if (fr[sz[Find(k)]] == nrzone && nrzone > nrzonemax) {         maxk = k;         nrzonemax = nrzone;       }     }     cout << v[maxk].first + 1 <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1000006;   const long long MOD = 1000000007;   struct Query {     int a, t, x, id;   } query[MAXN];   map<int, int> cnt;   int n, ans[MAXN], qcnt;   void solve(int l, int r) {     ;     if (l != r - 1) {       int mid = (l + r) >> 1;       solve(l, mid);       solve(mid, r);       cnt.clear();       int lp = l, rp = mid;       while (rp < r) {         if (lp == mid || query[lp].t > query[rp].t) {           if (query[rp].a == 3) {             ;             ans[query[rp].id] += cnt[query[rp].x];           }           rp++;         } else {           if (query[lp].a == 1) {             cnt[query[lp].x]++;           } else if (query[lp].a == 2) {             cnt[query[lp].x]--;           }           lp++;         }       };       sort(query + l, query + r, [&](Query q1, Query q2) { return q1.t < q2.t; });     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     ;     cin >> n;     for (int i = 0; i < n; i++) {       int a, t, x;       cin >> a >> t >> x;       query[i] = {a, t, x, qcnt};       ;       if (a == 3) {         qcnt++;       }     }     solve(0, n);     for (int i = 0; i < qcnt; i++) {       cout << ans[i] <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   int m;   int a[1 << 7];   int min_k, max_k;   bool ok(int ask) {     int need = 0;     for (int i = 0; i < n; i++) {       if (a[i] > ask) {         return false;       }       if (ask > a[i]) {         need += ask - a[i];       }     }     if (need >= m) {       return true;     }     return false;   }   void read(void) {     cin >> n;     cin >> m;     for (int i = 0; i < n; i++) {       cin >> a[i];     }   }   void solve(void) {     for (int i = 0; i < n; i++) {       max_k = max(max_k, a[i] + m);     }     for (int k = 1; k <= 10100; k++) {       if (ok(k)) {         min_k = k;         break;       }     }   }   void print(void) { cout << min_k <<     << max_k << endl; }   int main() {     read();     solve();     print();     return 0;   }


#include <bits/stdc++.h>   constexpr int Maxn = 1e5 + 7;   constexpr int Mod = 1e9 + 7;   int fac[Maxn], ifac[Maxn];   inline int fpm(int a, int b) {     int res = 1;     while (b) {       if (b & 1) res = 1LL * res * a % Mod;       a = 1LL * a * a % Mod;       b >>= 1;     }     return res;   }   inline int C(int n, int m) {     if (n < 0 || m < 0 || n < m) return 0;     return 1LL * fac[n] * ifac[m] % Mod * ifac[n - m] % Mod;   }   std::unordered_map<int, int> cnt, mp;   int n, m, k, f[Maxn], p[Maxn], s[Maxn];   int solve(int x) {     if (mp.count(x)) return mp[x];     int res = 0;     for (int i = 0; i <= m; ++i) res = (res + 1LL * p[i] * s[i + x] % Mod) % Mod;     return mp[x] = res;   }   int main() {     scanf( %d%d , &n, &k);     fac[0] = 1;     for (int i = 1; i <= n; ++i) fac[i] = 1LL * i * fac[i - 1] % Mod;     ifac[n] = fpm(fac[n], Mod - 2);     for (int i = n - 1; i >= 0; --i) ifac[i] = 1LL * (i + 1) * ifac[i + 1] % Mod;     for (int i = 1, x; i <= n; ++i) {       scanf( %d , &x);       ++cnt[x];     }     f[0] = k - 1;     for (int i = 1; i < n; ++i) {       int p = 1LL * i * fpm(n, Mod - 2) % Mod;       int q = 1LL * (n - i) * fpm(n, Mod - 2) % Mod * fpm(k - 1, Mod - 2) % Mod;       f[i] = (1LL * p * f[i - 1] % Mod + 1) * fpm(q, Mod - 2) % Mod;     }     for (int i = n; i; --i) s[i - 1] = (s[i] + f[i - 1]) % Mod;     m = cnt[-1];     for (int i = 0; i <= m; ++i)       p[i] =           1LL * C(m, i) * fpm(k - 1, m - i) % Mod * fpm(fpm(k, m), Mod - 2) % Mod;     int res = 0, tot = k;     for (auto x : cnt)       if (x.first != -1) {         res = (res + solve(x.second)) % Mod;         --tot;       }     res = (res + 1LL * tot * solve(0) % Mod) % Mod;     res = (res - 1LL * (k - 1) * s[0] % Mod + Mod) % Mod;     printf( %d n , 1LL * res * fpm(k - 1, Mod - 2) % Mod);   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   int main() {   y:     cin.tie(0);     cout.tie(0);     cin.sync_with_stdio(0);     ;     ll n = 0, k = 0;     cin >> n >> k;     ll a = 0, b = 0;     ll sum = 0;     ll pos = 0;     for (int i = 0; i < k; ++i) {       cin >> a >> b;       sum += b;       pos += a * b;     }     if (sum < n)       cout << 1 <<   n ;     else {       if (!(pos % n == (n * (n - 1)) / 2 % n))         cout << -1 <<   n ;       else         cout << 1 <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     int a, n;     cin >> n >> s;     for (int i = 0; i < n; ++i) {       for (int j = 1; j < n + 1; ++j) {         if (i + 4 * j >= n) break;         if (s[i] ==  *  && s[i + j] ==  *  && s[i + 2 * j] ==  *  &&             s[i + 3 * j] ==  *  && s[i + 4 * j] ==  * ) {           printf( yes n );           return 0;         }       }     }     printf( no n );   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     int n, m;     cin >> n >> m;     vector<vector<vector<int>>> dp(n + 1,                                    vector<vector<int>>(m + 1, vector<int>(2, 0)));     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) {         dp[i][j][1] = dp[i][j - 1][0] + 1;         dp[i][j][0] = dp[i - 1][j][1] + 1;       }     int ans = 0;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) {         ans += dp[i][j][0] + dp[i][j][1];       }     ans -= n * m;     int q;     cin >> q;     vector<vector<int>> a(n, vector<int>(m, 1));     auto calc_len = [&](int x, int y, int dx, int dy) {       int res = 0;       while (1) {         x += dx;         y += dy;         if (x < 0 || y < 0 || x >= n || y >= m || a[x][y] == 0) {           break;         }         res++;         swap(dx, dy);       }       return res;     };     while (q--) {       int i, j;       cin >> i >> j;       i--, j--;       {         int x = calc_len(i, j, -1, 0);         int y = calc_len(i, j, 0, 1);         ans += (a[i][j] == 1 ? -1 : 1) * ((x + 1) * (y + 1));       }       {         int x = calc_len(i, j, 0, -1);         int y = calc_len(i, j, 1, 0);         ans += (a[i][j] == 1 ? -1 : 1) * ((x + 1) * (y + 1));       }       ans += (a[i][j] == 1 ? 1 : -1);       a[i][j] ^= 1;       cout << ans << endl;     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     int T = 1;     while (T--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   int n, k, a, ans;   set<pair<int, int> > s;   int x, m;   bool used[1000000];   int solve(int x) { return (x + 1) / (a + 1); }   void go(int x) {     set<pair<int, int> >::iterator it = s.upper_bound(make_pair(x, 1000000000));     --it;     pair<int, int> cur = *it;     s.erase(it);     ans -= solve(cur.second - cur.first + 1);     if (x != cur.first) {       ans += solve(x - cur.first);       s.insert(make_pair(cur.first, x - 1));     }     if (x != cur.second) {       ans += solve(cur.second - x);       s.insert(make_pair(x + 1, cur.second));     }   }   int main() {     cin >> n >> k >> a;     s.insert(make_pair(1, n));     ans = solve(n);     cin >> m;     for (int i = 1; i <= m; i++) {       cin >> x;       if (used[x]) continue;       used[x] = 1;       go(x);       if (ans < k) {         cout << i;         return 0;       }     }     cout << -1;   }


#include <bits/stdc++.h>   using namespace std;   const int N =9999999;   const double pi=acos(-1);       int n,t,ans,a[N],k,s1,s2;   int main(){    cin>>t;    while(t--){     cin>>n>>k;     if(n%2==1)cout<<((k-1)+((k-1))/(n/2))%n+1<<endl;     else cout<<(k-1)%n+1<<endl;    }    return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline long long int StrToInt(string& s) {     long long int ans = 0;     for (int i = 0; i < s.size(); i++) ans = ans * 10 + s[i] -  0 ;     return ans;   }   vector<long long int> v, t, pref;   long long int bp(long long int mo) {     long long int l = 0, r = v.size(), m;     while (r - l > 1) {       m = (r + l) / 2;       if (v[m] > mo)         r = m;       else         l = m;     }     return l;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     long long int n;     cin >> n;     v.resize(n);     t.resize(n);     pref.resize(n + 1);     for (int i = 0; i < n; i++) cin >> v[i];     for (int j = 0; j < n; j++) cin >> t[j];     pref[0] = 0;     for (int i = 1; i <= n; ++i) {       pref[i] = pref[i - 1] + t[i - 1];       v[i - 1] += pref[i - 1];     }     sort(v.begin(), v.end());     long long int ans = 0;     for (int i = 0; i < n; i++) {       ans = 0;       long long int m = upper_bound(v.begin(), v.end(), pref[i]) - v.begin();       long long int mm = upper_bound(v.begin(), v.end(), pref[i + 1]) - v.begin();       ans += (i - mm + 1) * t[i];       for (int j = m; j < mm; j++) ans += v[j] - pref[i];       cout << ans <<    ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e6 + 10;   string rs;   int pre[maxn];   void matchprefix() {     int n = rs.length();     pre[0] = 0;     int k = 0;     for (int i = 1; i < n; i++) {       while (k > 0 && rs[k] != rs[i]) k = pre[k - 1];       if (rs[k] == rs[i]) k++;       pre[i] = k;     }   }   int z[maxn];   void Z_function() {     int n = rs.length();     z[0] = 0;     int L = 0, R = 0;     for (int i = 1; i < n; i++) {       z[i] = 0;       if (i <= R) {         if (z[i - L] < R - i + 1)           z[i] = z[i - L];         else {           z[i] = min(z[i - L], R - i + 1);           while (i + z[i] < n && rs[i + z[i]] == rs[z[i]]) z[i]++;           L = i;           R = i + z[i] - 1;         }       } else {         while (i + z[i] < n && rs[i + z[i]] == rs[z[i]]) z[i]++;         L = i;         R = i + z[i] - 1;       }     }   }   int main() {     string s, t;     getline(cin, s);     getline(cin, t);     int n = s.length();     if (n != t.length()) {       cout <<  -1 -1 ;       return 0;     }     rs = s;     reverse(rs.begin(), rs.end());     rs.push_back(  n );     rs += t;     matchprefix();     rs = t +   n  + s +   n ;     Z_function();     int ansi = -1, ansj = -1;     for (int i = 0; i + 1 < n; i++) {       if (s[i] != t[n - 1 - i]) break;       int len_0_i = i + 1;       int len_i_j = z[n + i + 2];       int len_j_n = pre[n + n - i - 1];       if (len_j_n > 0 && len_0_i + len_i_j + len_j_n >= n) {         ansi = i;         ansj = n - len_j_n;       }     }     cout << ansi <<     << ansj;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s1;     int count = 0;     cin >> s1;     char c = s1[0];     for (int i = 0; i < s1.length(); i++) {       if (s1[i] == c)         count++;       else if (s1[i] > c) {         count = 1;         c = s1[i];       }     }     cout << string(count, c);     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast,no-stack-protector )   #pragma GCC optimize( unroll-loops )   #pragma GCC optimize( fast-math )   #pragma GCC optimize( move-loop-invariants )   std::mt19937 rnd(237);   using namespace std;   using ll = long long;   using ld = long double;   const int inf = 1e9 + 8;   const ll linf = 4e18 + 18;   const int N = 1e6 + 6;   const double pi = acos(-1.0);   int n;   vector<int> a, b, p, pp;   vector<vector<int>> g;   vector<ll> sum;   ll ans = 0;   void dfs(int v, int par = -1) {     sum[v] = a[v];     for (auto &u : g[v]) {       if (u != par) dfs(u, v);     }     if (sum[v] > 0) {       if (~par) sum[par] += sum[v];       p.push_back(v);     } else       pp.push_back(v);     ans += sum[v];   }   void solve() {     cin >> n;     a.resize(n);     b = a;     for (int i = 0; i < n; ++i) {       cin >> a[i];     }     g.assign(n, {});     vector<int> indeg(n, 0);     for (int i = 0; i < n; ++i) {       cin >> b[i];       if (~b[i]) {         g[b[i] - 1].push_back(i);         indeg[i]++;       }     }     sum.resize(n);     for (int i = 0; i < n; ++i) {       if (!indeg[i]) dfs(i);     }     cout << ans <<   n ;     for (auto &x : p) cout << x + 1 <<    ;     for (int i = (int)pp.size() - 1; ~i; --i) cout << pp[i] + 1 <<    ;   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int test_case = 1;     for (int t = 0; t < test_case; ++t) {       solve();       cout <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int f[3][4] = {{0, 3, 1, 2}, {}, {0, 2, 3, 1}};   void solve(long long x, int y) {     if (y == 1) {       printf( %lld n , x);       return;     }     long long ans = 0, p = 1;     while (x) {       ans += f[y][x % 4] * p;       x >>= 2, p <<= 2;     }     printf( %lld n , ans);   }   int main() {     int t;     scanf( %d , &t);     while (t--) {       long long n;       scanf( %lld , &n);       long long j = 1, a;       while (j <= n) j <<= 2;       j >>= 2;       if (j + 2 >= n)         a = j;       else         a = j + (n - j) / 3;       solve(a, n % 3);     }   }


#include <bits/stdc++.h>   using namespace std;   string s[1000 + 5];   int nsc[1000 + 5], nsl[1000 + 5];   int main() {     int n, m;     cin >> n >> m;     int i, j, z;     for (i = 0; i < n; i++) cin >> s[i];     for (i = 0; i < n; i++)       for (j = 0; j < m; j++)         if (s[i][j] ==  * ) nsl[i]++, nsc[j]++;     long long ans = 0;     for (i = 0; i < n; i++)       for (j = 0; j < m; j++)         if (s[i][j] ==  * ) ans += 1LL * (nsl[i] - 1) * (nsc[j] - 1);     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename A, typename B>   inline void chmin(A& a, B b) {     if (a > b) a = b;   }   template <typename A, typename B>   inline void chmax(A& a, B b) {     if (a < b) a = b;   }   template <class A, class B>   ostream& operator<<(ostream& ost, const pair<A, B>& p) {     ost <<  {  << p.first <<  ,  << p.second <<  } ;     return ost;   }   template <class T>   ostream& operator<<(ostream& ost, const vector<T>& v) {     ost <<  { ;     for (long long i = 0; i < v.size(); i++) {       if (i) ost <<  , ;       ost << v[i];     }     ost <<  } ;     return ost;   }   template <class T>   struct BinaryIndexedTree {     long long n;     vector<T> dat;     BinaryIndexedTree(long long n = 0) : n(n), dat(n + 1) {}     void add(long long k, T x) {       for (k++; k <= n; k += k & -k) dat[k] += x;     }     T sum(long long k) {       T ret{};       for (k++; k; k -= k & -k) ret += dat[k];       return ret;     }   };   long long N;   long long A[222222];   long long K[222222], P[222222];   long long Q;   signed main() {     scanf( %lld , &N);     for (long long i = 0; i < (N); i++) scanf( %lld , &A[i]);     vector<long long> ord(N);     iota((ord).begin(), (ord).end(), 0);     sort((ord).begin(), (ord).end(), [&](long long i, long long j) {       if (A[i] == A[j]) return i < j;       return A[i] > A[j];     });     scanf( %lld , &Q);     vector<vector<long long> > bucket(N);     for (long long i = 0; i < (Q); i++) {       scanf( %lld%lld , &K[i], &P[i]);       K[i]--;       P[i]--;       bucket[K[i]].push_back(i);     }     BinaryIndexedTree<long long> bit(N + 114);     vector<long long> ans(Q);     for (long long i = 0; i < (N); i++) {       bit.add(ord[i], 1);       for (auto j : bucket[i]) {         long long lb = 0, ub = N;         while (ub - lb > 1) {           long long mid = (ub + lb) / 2;           if (bit.sum(mid - 1) <= P[j])             lb = mid;           else             ub = mid;         }         ans[j] = A[lb];       }     }     for (long long i = 0; i < (Q); i++) printf( %lld n , ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     long long ans = 0;     for (int i = (0); i < (n); ++i) {       long long t, T, x, cost;       cin >> t >> T >> x >> cost;       if (t >= T) {         ans += cost + m * x;         continue;       }       long long aux1 = cost;       if (m > (T - t)) aux1 += m * x;       long long aux2 = (long long)ceil((double)(m - (T - t)) / (T - t)) + 1;       aux2 *= cost;       ans += min(aux1, aux2);     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   int cnt[2], v[2];   bool f(ll val) {     ll f[] = {val / v[0], val / v[1]};     ll b = v[0] * 1ll * v[1];     ll both = val / b;     ll other = val - f[0] - f[1] + both;     f[0] -= both;     f[1] -= both;     ll tcnt[] = {cnt[0] - f[1], cnt[1] - f[0]};     if (tcnt[0] < 0) tcnt[0] = 0;     if (tcnt[1] < 0) tcnt[1] = 0;     return (tcnt[0] + tcnt[1] <= other);   }   int main() {     cin >> cnt[0] >> cnt[1] >> v[0] >> v[1];     ll l = 0;     ll r = ll(1e18);     while (r - l > 1) {       ll mid = (l + r) >> 1;       if (f(mid)) {         r = mid;       } else {         l = mid;       }     }     cout << r << endl;   }


#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1);   const double eps = 1e-9;   const int inf = 2000000000;   const long long infLL = 9000000000000000000;   inline bool checkBit(long long n, int i) { return n & (1LL << i); }   inline long long setBit(long long n, int i) {     return n | (1LL << i);     ;   }   inline long long resetBit(long long n, int i) { return n & (~(1LL << i)); }   int dx[] = {0, 0, +1, -1};   int dy[] = {+1, -1, 0, 0};   inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; }   inline bool isLeapYear(long long year) {     return (year % 400 == 0) || (year % 4 == 0 && year % 100 != 0);   }   inline void normal(long long &a) {     a %= 1000000007;     (a < 0) && (a += 1000000007);   }   inline long long modMul(long long a, long long b) {     a %= 1000000007, b %= 1000000007;     normal(a), normal(b);     return (a * b) % 1000000007;   }   inline long long modAdd(long long a, long long b) {     a %= 1000000007, b %= 1000000007;     normal(a), normal(b);     return (a + b) % 1000000007;   }   inline long long modSub(long long a, long long b) {     a %= 1000000007, b %= 1000000007;     normal(a), normal(b);     a -= b;     normal(a);     return a;   }   inline long long modPow(long long b, long long p) {     long long r = 1;     while (p) {       if (p & 1) r = modMul(r, b);       b = modMul(b, b);       p >>= 1;     }     return r;   }   inline long long modInverse(long long a) { return modPow(a, 1000000007 - 2); }   inline long long modDiv(long long a, long long b) {     return modMul(a, modInverse(b));   }   const int MX = 10100;   int vis[5][5][5], l[5], r[5], curnum, n;   double dp[5][5][5];   double func(int pos, int eNum, int bNum) {     if (bNum > 1) return 0;     if (pos == n) {       if (eNum > 1 && !bNum) return 1;       if (eNum && bNum) return 1;       return 0;     }     if (vis[pos][eNum][bNum]) return dp[pos][eNum][bNum];     vis[pos][eNum][bNum] = 0;     double &ret = dp[pos][eNum][bNum];     ret = 0;     if (curnum >= l[pos] && curnum <= r[pos]) {       double temp = (1.0 / (r[pos] - l[pos] + 1));       temp *= func(pos + 1, eNum + 1, bNum);       ret += temp;     }     if (r[pos] > curnum) {       double temp = 1;       if (l[pos] <= curnum) {         temp *= (double)(r[pos] - curnum) / (double)(r[pos] - l[pos] + 1);       }       temp *= func(pos + 1, eNum, bNum + 1);       ret += temp;     }     if (l[pos] < curnum) {       double temp = 1;       if (r[pos] >= curnum) {         temp *= (double)(curnum - l[pos]) / (double)(r[pos] - l[pos] + 1);       }       temp *= func(pos + 1, eNum, bNum);       ret += temp;     }     return ret;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     cout.unsetf(ios::floatfield);     cout.precision(10);     cout.setf(ios::fixed, ios::floatfield);     ;     cin >> n;     for (int i = 0; i < n; ++i) cin >> l[i] >> r[i];     double ans = 0;     for (int i = 1; i < MX; ++i) {       curnum = i;       ans += i * func(0, 0, 0);       ;       memset(vis, 0, sizeof(vis));     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   const int N = 5050;   int n, t, v = -1, w, p[N], c[N], d[N], l[N];   void U(int x, int* y) {     for (int u = x + 1; u <= n; u += u & -u) ++y[u];   }   int Q(int x, int* y) {     int s = 0;     while (x > 0) s += y[x], x -= x & -x;     return s;   }   int main() {     scanf( %d , &n);     for (int i = 0, s; i < n && 1 == scanf( %d , &p[i]); ++i)       s = Q(p[i], c), l[i] = s, t += i - s, U(p[i], c);     for (int i = 0; i < n; U(p[i++], d))       for (int j = i + 1, a = 0, b; j < n; ++j)         if (p[j] < p[i]) {           b = l[j] - Q(p[j], d);           if (a - b > v)             v = a - b, w = 1;           else if (a - b == v)             ++w;           ++a;         }     printf( %d %d n , t - v - v - 1, w);   }


#include <bits/stdc++.h>   using namespace std;   vector<long long> ve[100005];   long long vis[100005] = {0}, z = 0, i;   void solve() {     vector<long long> v;     vector<pair<long long, long long> > vp;     map<long long, long long> mp, mpp;     map<long long, long long>::iterator itr;     long long n = 0, m = 0, i = 0, j = 0, k = 0, c = 0, l = 0, r = 0, p = 0,               q = 0, x = 0, y = 0, z = 0, flag = 0, sum = 0;     long long a[300005] = {0}, b[1005] = {0}, ans[25][25];     long long s, t;     cin >> n;     for (i = 0; i < pow(n, 2); i++) cin >> a[i];     for (i = 0; i < pow(n, 2); i++) b[a[i]]++;     for (i = 0; i < 1001; i++)       if (b[i] > 0) vp.push_back(make_pair(b[i], i));     sort(vp.begin(), vp.end());     z = vp.size() - 1;     for (j = 0; j < n / 2; j++) {       for (i = 0; i < n / 2; i++) {         if (vp[z].first >= 4) {           k = vp[z].second;           vp[z].first -= 4;           ans[i][j] = k;           ans[n - i - 1][j] = k;           ans[i][n - j - 1] = k;           ans[n - i - 1][n - j - 1] = k;         } else {           z--;           i--;         }         if (z == -1) {           cout <<  No  << endl;           return;         }       }     }     if (n % 2 == 1) {       s = (n - 1) / 2;       sort(vp.begin(), vp.end());       z = vp.size() - 1;       for (i = 0; i < n / 2; i++) {         if (vp[z].first >= 2) {           k = vp[z].second;           vp[z].first -= 2;           ans[s][i] = k;           ans[s][n - i - 1] = k;         } else {           z--;           i--;         }         if (z == -1) {           cout <<  No  << endl;           return;         }       }       sort(vp.begin(), vp.end());       z = vp.size() - 1;       for (i = 0; i < n / 2; i++) {         if (vp[z].first >= 2) {           k = vp[z].second;           vp[z].first -= 2;           ans[i][s] = k;           ans[n - i - 1][s] = k;         } else {           z--;           i--;         }         if (z == -1) {           cout <<  No  << endl;           return;         }       }       sort(vp.begin(), vp.end());       z = vp.size() - 1;       ans[s][s] = vp[z].second;     }     for (i = 0; i < n; i++)       for (j = 0; j < n; j++)         if (ans[i][j] == 0) {           cout <<  No  << endl;           return;         }     cout <<  Yes  << endl;     for (i = 0; i < n; i++) {       for (j = 0; j < n; j++) cout << ans[i][j] <<     ;       cout << endl;     }   }   bool imp = false;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int t = 1;     if (imp) cin >> t;     while (t--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bitset<300000001> b;   int main() {     int l, r, c = 0, i, j;     cin >> l >> r;     for (i = 3; i * i <= r; i += 2)       for (j = i * i; b[i] == 0 and j <= r; j += i) b[j] = 1;     if (l <= 2 and r >= 2) c = 1;     for (i = 5; i <= r; i += 4) c += !b[i] and i >= l;     cout << c;   }


#include <bits/stdc++.h>   using namespace std;   int b[4], c, n, l = 0, a, i;   int main() {     scanf( %d , &n);     for (i = 0; i < n; i++) {       scanf( %d , &a);       b[a]++;     }     cout << n - max(b[1], max(b[2], b[3])) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1000 * 1000 * 1000 + 7;   const double EPS = 1e-9;   int bit_count(int first) {     return first == 0 ? 0 : 1 + bit_count(first & (first - 1));   }   inline int low_bit(int first) { return first & -first; }   inline int sign(double first) {     return first < -EPS ? -1 : first > EPS ? 1 : 0;   }   inline int sign(int first) { return (first > 0) - (first < 0); }   int nextComb(int first) {     if (!first) {       fprintf(stderr,  nextComb(0) called n );       return ((1 << 30) - 1 + (1 << 30));     }     int smallest = first & -first;     int ripple = first + smallest;     int ones = first ^ ripple;     ones = (ones >> 2) / smallest;     return ripple | ones;   }   template <class T>   inline T gcd(T a, T b) {     a = abs(a);     b = abs(b);     while (b) {       int r = a % b;       a = b;       b = r;     }     return a;   }   template <class T>   inline T lcm(T a, T b) {     return a / gcd(a, b) * b;   }   inline int getInt() {     int a;     return scanf( %d , &a) ? a : (fprintf(stderr,  trying to read n ), -1);   }   inline double getDouble() {     double a;     return scanf( %lf , &a) ? a : (fprintf(stderr,  trying to read n ), -1.0);   }   inline double myRand() {     return ((double)rand() / RAND_MAX) + ((double)rand() / RAND_MAX / RAND_MAX);   }   inline string getLine() {     string ret;     getline(cin, ret,  : );     return ret;   }   long long process(string s, int base) {     long long ret = 0;     for (int i = (int)0; i < (int)((int)(s).size()); ++i) {       ret *= base;       if (isdigit(s[i]))         ret += s[i] -  0 ;       else         ret += s[i] -  A  + 10;     }     return ret;   }   bool isValid(string s, int base) {     for (int i = (int)0; i < (int)((int)(s).size()); ++i) {       if (isdigit(s[i]) && s[i] -  0  >= base)         return false;       else if (s[i] -  A  + 10 >= base)         return false;     }     return true;   }   void myCode() {     string hrs, mins;     getline(cin, hrs,  : );     getline(cin, mins);     vector<int> ret;     if (((int)(hrs).size()) < 6 && ((int)(mins).size()) < 7) {       for (int i = (int)2; i < (int)100; ++i) {         if (isValid(hrs, i) == true && isValid(mins, i) == true) {           if (process(hrs, i) < 24 && process(mins, i) < 60) {             ret.push_back(i);           }         }       }     }     if (ret.empty())       printf( 0 n );     else if (ret[((int)(ret).size()) - 1] == 99)       printf( -1 n );     else       for (int i = (int)0; i < (int)((int)(ret).size()); ++i)         printf( %d%c , ret[i], i == ((int)(ret).size()) - 1 ?   n  :    );   }   int main() {     srand(time(NULL));     myCode();     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, k;     cin >> n >> k;     bool count[26] = {0};     char c;     for (int i = 0; i < n; i++) {       cin >> c;       count[c -  a ] = true;     }     int e = -4;     int res = 0;     for (int i = 0; i < 26; i++) {       if ((!count[i]) || (i - e) < 2) continue;       res += i + 1;       e = i;       k--;       if (k == 0) break;     }     if (k > 0) {       cout <<  -1 n ;     } else       cout << res <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     ;     int n;     cin >> n;     int k;     cin >> k;     string s;     cin >> s;     int ig = -1, it = -1;     for (int i = 0; i < n; i++) {       if (s[i] ==  G ) {         ig = i;       }       if (s[i] ==  T ) {         it = i;       }     }     if (it % k != ig % k) {       cout <<  NO  << endl;     } else {       if (ig < it) {         swap(it, ig);       }       for (int i = it; i <= ig; i++) {         if (s[i] ==  #  && (i % k) == (ig % k)) {           cout <<  NO  << endl;           return 0;         }       }       cout <<  YES  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1005;   const long long mod = 1000000007;   int grid[maxn][maxn];   inline void fast() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(0);   }   int main() {     fast();     int h, w;     cin >> h >> w;     for (int i = 0; i < h; i++) {       int x;       cin >> x;       for (int j = 0; j < x; j++) grid[i][j] = 1;       grid[i][x] = 2;     }     for (int j = 0; j < w; j++) {       int x;       cin >> x;       for (int i = 0; i < x; i++) {         if (grid[i][j] == 2) {           cout << 0 << endl;           return 0;         }         grid[i][j] = 1;       }       if (grid[x][j] == 1) {         cout << 0 << endl;         return 0;       }       grid[x][j] = 2;     }     int ans = 1;     for (int i = 0; i < h; i++)       for (int j = 0; j < w; j++) {         if (grid[i][j] == 0) {           ans = ans * 2 % mod;         }       }     cout << ans << endl;     return 0;   }