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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


#include <bits/stdc++.h>   using namespace std;   template <typename T>   void chkmax(T &x, T y) {     x = x > y ? x : y;   }   template <typename T>   void chkmin(T &x, T y) {     x = x > y ? y : x;   }   const int INF = 2139062143;   template <typename T>   void read(T &x) {     x = 0;     bool f = 1;     char ch;     do {       ch = getchar();       if (ch ==  - ) f = 0;     } while (ch >  9  || ch <  0 );     do {       x = x * 10 + ch -  0 ;       ch = getchar();     } while (ch >=  0  && ch <=  9 );     x = f ? x : -x;   }   template <typename T>   void write(T x) {     if (x < 0) x = ~x + 1, putchar( - );     if (x > 9) write(x / 10);     putchar(x % 10 +  0 );   }   const int N = 1000 + 5;   const int mod = 998244353;   int n, k, ans, a[N], f[N][N], s[N][N];   int main() {     read(n);     read(k);     for (int i = 1; i <= n; i++) read(a[i]);     sort(a + 1, a + n + 1);     a[0] = -INF;     for (int v = 1; v * (k - 1) <= a[n]; v++) {       f[0][0] = s[0][0] = 1;       int now = 0;       for (int i = 1; i <= n; i++) {         while (a[i] - a[now] >= v) now++;         f[i][0] = 0;         s[i][0] = (s[i - 1][0] + f[i][0]) % mod;         for (int j = 1; j <= k; j++) {           f[i][j] = s[now - 1][j - 1];           s[i][j] = (s[i - 1][j] + f[i][j]) % mod;         }       }       ans = (ans + 1ll * s[n][k]) % mod;     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   const long long INF = 1e18;   signed main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     long long n, r1, r2, r3, d;     cin >> n >> r1 >> r2 >> r3 >> d;     vector<long long> a(n), x(n), y(n);     vector<vector<long long>> dp(n + 1, vector<long long>(2, INF));     dp[0][0] = 0;     for (long long i = 0; i < n; i++) {       cin >> a[i];     }     for (long long i = 0; i < n; i++) {       x[i] = a[i] * r1 + r3;       y[i] = min(r1 + r2, (a[i] + 2) * r1);       y[i] = min(y[i], x[i]);     }     for (long long i = 0; i < n; i++) {       dp[i + 1][0] = min(dp[i][0] + x[i], dp[i][1] + y[i] + d);       dp[i + 1][1] = dp[i][0] + y[i] + d;       if (i == n - 1) dp[i + 1][0] = min(dp[i + 1][0], dp[i][1] + x[i]);     }     long long ans = min(dp[n][0], dp[n][1] + d);     ans += d * (n - 1);     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 5;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long n, c, l = 0, t, ans = 0;     cin >> n >> c;     for (int i = 0; i < n; i++) {       cin >> t;       if (l) {         long long x = min(t, c - l);         l += x;         t -= x;       }       ans += t / c + (l != 0);       l = t % c;     }     ans += l != 0;     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char ch[1000100];   int l;   void dfs(int k) {     if (k >= l) return;     if (ch[k] ==  l ) {       dfs(k + 1);       printf( %d n , k + 1);     } else {       printf( %d n , k + 1);       dfs(k + 1);     }   }   int main() {     scanf( %s , ch);     l = strlen(ch);     dfs(0);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int OO = (int)1e9;   int dx[8] = {0, 0, -1, 1, 1, 1, -1, -1};   int dy[8] = {1, -1, 0, 0, 1, -1, 1, -1};   long long n, x, y;   bool ok;   map<long long, long long> cnt;   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       cin >> x;       for (int j = 0; j < x; j++) {         cin >> y;         cnt[y]++;       }     }     for (int i = 1; i <= 100; i++) {       if (cnt[i] == n) {         cout << i <<    ;       }     }     return 0;   }


#include <bits/stdc++.h>   int a[3005];   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n; ++i) scanf( %d , &a[i]);     int cnt = 0;     for (int i = 1; i < n; ++i)       for (int j = 0; j < i; ++j)         if (a[i] < a[j]) ++cnt;     if (cnt & 1)       printf( %d , cnt * 2 - 1);     else       printf( %d , 2 * cnt);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int M = 1000000007;   int n;   int dp[1000010];   int main() {     while (~scanf( %d , &n)) {       int a = 0;       for (int i = 1; i <= n; i++) {         int x;         scanf( %d , &x);         if (x == 1) a++;       }       dp[0] = dp[1] = 1;       for (int i = 2; i <= a; i++)         dp[i] = (dp[i - 1] + (long long)dp[i - 2] * (i - 1)) % M;       int ans = dp[a];       for (int i = a + 1; i <= n; i++) ans = (long long)ans * i % M;       printf( %d n , ans);     }   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t;     cin >> t;     while (t--) {       ll a, b, n;       cin >> a >> b >> n;       ll cnt = 0;       if (a > b) swap(a, b);       while (max(a, b) <= n) {         a += b;         if (a > b) {           swap(a, b);         }         cnt++;       }       cout << cnt <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   inline int read() {     int x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = (x << 3) + (x << 1) + ch -  0 ;       ch = getchar();     }     return x * f;   }   const int maxn = 2e5 + 10;   int n, q, typ, x, y, cnt, ans;   int a[maxn], in[maxn], out[maxn];   int dep[maxn], fc[21], fa[21][maxn];   vector<int> G[maxn];   pair<int, int> res;   inline void dfs(int u) {     in[u] = ++cnt;     for (int i = 1; fc[i] <= dep[u]; ++i) fa[i][u] = fa[i - 1][fa[i - 1][u]];     for (int i = 0, len = G[u].size(); i < len; ++i) {       dep[G[u][i]] = dep[u] + 1;       fa[0][G[u][i]] = u;       dfs(G[u][i]);     }     out[u] = ++cnt;   }   inline int LCA(int x, int y) {     if (dep[x] < dep[y]) swap(x, y);     for (int i = 0, t = dep[x] - dep[y]; t; ++i)       if (t & fc[i]) x = fa[i][x], t ^= fc[i];     for (int i = 20; ~i; --i)       if (fa[i][x] ^ fa[i][y]) x = fa[i][x], y = fa[i][y];     return x == y ? x : fa[0][x];   }   namespace Segment {   pair<int, int> T[maxn << 2];   bool anc(int x, int y) { return in[x] <= in[y] && out[x] >= out[y]; }   pair<int, int> check(pair<int, int> x, int y) {     if (!x.first || !y) return make_pair(0, 0);     if (anc(x.first, x.second)) swap(x.first, x.second);     if (anc(x.second, x.first)) {       if (anc(x.first, y)) return make_pair(y, x.second);       if (anc(x.second, y)) {         if (anc(y, x.first)) return x;         if (LCA(x.first, y) == x.second) return make_pair(x.first, y);         return make_pair(0, 0);       }       return make_pair(y, x.first);     }     if (anc(x.first, y)) return make_pair(y, x.second);     if (anc(x.second, y)) return make_pair(x.first, y);     if (!anc(LCA(x.first, x.second), y)) return make_pair(0, 0);     if (!anc(y, x.first) && !anc(y, x.second)) return make_pair(0, 0);     return x;   }   pair<int, int> merge(pair<int, int> x, pair<int, int> y) {     if (x.first == -1) return y;     x = check(x, y.first);     x = check(x, y.second);     return x;   }   void update(int rt, int l, int r, int pos, int x) {     if (l == r) {       T[rt] = make_pair(x, x);       return;     }     int mid = l + r >> 1;     if (pos <= mid)       update((rt << 1), l, mid, pos, x);     else       update((rt << 1 | 1), mid + 1, r, pos, x);     T[rt] = merge(T[(rt << 1)], T[(rt << 1 | 1)]);   }   bool query(int rt, int l, int r) {     pair<int, int> tmp = merge(res, T[rt]);     if (tmp.first) {       res = tmp;       ans = r;       return true;     }     if (l == r) return false;     int mid = l + r >> 1;     if (query((rt << 1), l, mid)) query((rt << 1 | 1), mid + 1, r);     return false;   }   }  // namespace Segment   using namespace Segment;   int main() {     n = read();     fc[0] = 1;     for (int i = 1; i <= n; ++i) a[i] = read() + 1;     for (int i = 2; i <= n; ++i) G[read()].push_back(i);     for (int i = 1; i <= 20; ++i) fc[i] = fc[i - 1] << 1;     dfs(1);     for (int i = 1; i <= n; ++i) update(1, 1, n, a[i], i);     q = read();     while (q--) {       typ = read();       if (typ == 1) {         x = read();         y = read();         swap(a[x], a[y]);         update(1, 1, n, a[x], x);         update(1, 1, n, a[y], y);       } else {         res = make_pair(-1, 0);         ans = 1;         query(1, 1, n);         printf( %d n , ans);       }     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC optimize( unroll-loops )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long int n, k;     cin >> n >> k;     long long int arr[n];     long long int i;     for (i = 0; i < n; i++) cin >> arr[i];     double ma = 0.0;     for (i = k; i <= n; i++) {       double s = 0.0;       int j;       for (j = 0; j < i; j++) s += arr[j];       ma = max(ma, s / i);       for (j = i; j < n; j++) {         s -= arr[j - i];         s += arr[j];         ma = max(ma, s / i);       }     }     cout << fixed << setprecision(20) << ma;   }


#include <bits/stdc++.h>   using namespace std;   const long double INF = 1e18 + 7;   long long N = 1e6 * 5;   long double EPS = 1 / 1e18;   long long a[1005];   map<long long, long long> cnt;   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long t;     cin >> t;     for (long long i = 0; i < t; i++) {       long long k = 0, err = 0, n;       cin >> n;       for (long long j = 2; j <= round(sqrt(n)); j++) {         if (!(n % j)) {           a[k++] = j;           cnt[j]++;           a[k++] = n / j;           cnt[n / j]++;         }       }       for (long long i = 0; i < k; i++) {         for (long long j = 0; j < k; j++) {           if (!(a[i] % a[j]) && cnt[a[i] / a[j]] != 0 && a[j] != n / a[i] &&               a[j] != a[i] / a[j] && n / a[i] != a[i] / a[j]) {             cout <<  YES n                   << a[j] <<     << a[i] / a[j] <<     << n / a[i] <<   n ;             err = 1;             break;           }         }         if (err) break;       }       if (!err) cout <<  NO n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     for (int cas = 0; cas < t; cas++) {       int n;       cin >> n;       vector<int> numbers(n);       int sum = 0;       int zer = 0;       int ans;       for (int i = 0; i < n; i++) {         cin >> numbers[i];         sum = sum + numbers[i];         if (numbers[i] == 0) zer++;       }       if (sum > 0) {         ans = zer;       } else if (sum < 0) {         if (sum == -zer) {           ans = zer + 1;         } else {           ans = zer;         }       } else {         if (zer == 0) {           ans = 1;         } else {           ans = zer;         }       }       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct debugger {     template <typename T>     debugger& operator,(const T& v) {       cerr << v <<    ;       return *this;     }   } dbg;   int main() {     int T;     cin >> T;     while (T--) {       char c;       int x1 = -1, y1 = -1, x2 = -1, y2 = -1;       for (int i = (0), _n = (8); i < _n; i++) {         for (int j = (0), _n = (8); j < _n; j++) {           cin >> c;           if (c ==  K  && (x1 == -1 && y1 == -1)) {             x1 = i;             y1 = j;           } else if (c ==  K  && (x2 == -1 && y2 == -1)) {             x2 = i;             y2 = j;           }         }       }       int a = abs(x2 - x1);       int b = abs(y2 - y1);       if (a % 4 == 0 && b % 4 == 0)         cout <<  YES n ;       else         cout <<  NO n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6 + 7;   char s[maxn];   int fa[maxn], siz[maxn];   int l[maxn][2];   int n, k;   int findset(int x) {     if (fa[x] == x) return x;     return fa[x] = findset(fa[x]);   }   void Union(int x, int y) {     int rx = findset(x), ry = findset(y);     if (!ry) swap(rx, ry);     if (rx) siz[rx] += siz[ry];     fa[ry] = rx;   }   int cal(int x) {     int y = x <= k ? x + k : x - k;     x = findset(x), y = findset(y);     if (!x || !y) return siz[x + y];     return min(siz[x], siz[y]);   }   int main() {     scanf( %d%d , &n, &k);     scanf( %s , s + 1);     for (int i = 1; i <= k; i++) {       int m;       scanf( %d , &m);       for (int j = 1; j <= m; j++) {         int x;         scanf( %d , &x);         if (l[x][0] == 0)           l[x][0] = i;         else           l[x][1] = i;       }       siz[i] = 1;       fa[i] = i;       fa[i + k] = i + k;     }     int ans = 0;     for (int i = 1; i <= n; i++) {       int x = l[i][0], y = l[i][1];       int rx = findset(x), ry = findset(y);       int rxk = findset(x + k), ryk = findset(y + k);       if (!y) {         ans -= cal(x);         if (s[i] ==  1 ) fa[rx] = 0;         if (s[i] ==  0 ) fa[rxk] = 0;         ans += cal(x);       } else if (s[i] ==  0  && rx != ryk) {         ans -= cal(x);         ans -= cal(y);         Union(x, y + k);         Union(y, x + k);         ans += cal(x);       } else if (s[i] ==  1  && rx != ry) {         ans -= cal(x);         ans -= cal(y);         Union(x, y);         Union(x + k, y + k);         ans += cal(x);       }       printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using P = pair<ll, ll>;   using PP = pair<ll, P>;   using VB = vector<bool>;   using VI = vector<ll>;   using VS = vector<string>;   using VC = vector<char>;   using VP = vector<P>;   using VPP = vector<PP>;   using VD = vector<double>;   using VVI = vector<VI>;   using VVP = vector<VP>;   using VVC = vector<VC>;   using VVB = vector<VB>;   using VVVI = vector<VVI>;   int main() {     int n, k;     cin >> n >> k;     for (int i = 0; i < k; i++) {       if (n % 10 == 0)         n /= 10;       else         n--;     }     cout << n << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100100, M = 32401000, S = 90, oo = 1000000000;   int i, j, k, n, m, ch, ff;   int s[N];   int F[M];   void R(int &x) {     ff = x = 0;     while (ch <  0  ||  9  < ch) {       if (ch ==  - ) ff = 1;       ch = getchar();     }     while ( 0  <= ch && ch <=  9 ) x = x * 10 + ch -  0 , ch = getchar();     if (ff) x = -x;   }   int P(int l, int r, int k) {     int t = 0;     l--;     r--;     k--;     t = (l * S * 2 + n - r - l + S) * S + k;     return t;   }   int min(const int &x, const int &y) {     if (x < y) return x;     return y;   }   int max(const int &x, const int &y) {     if (x > y) return x;     return y;   }   int f(int l, int r, int k, int o) {     if (r - l + 1 < k) return 0;     if (o == 1) {       int ans = f(l, r - k, k, 0) - s[r] + s[r - k];       if (r - l + 1 >= k + 1)         ans = min(ans, f(l, r - k - 1, k + 1, 0) - s[r] + s[r - k - 1]);       return ans;     } else {       int t = P(l, r, k);       if (F[t] < oo) return F[t];       int ans;       ans = s[l + k - 1] - s[l - 1] + f(l + k, r, k, 1);       if (r - l + 1 >= k + 1)         ans = max(ans, s[l + k] - s[l - 1] + f(l + k + 1, r, k + 1, 1));       return F[t] = ans;     }   }   int main() {     memset(F, 60, sizeof F);     R(n);     for (i = 1; i <= n; i++) R(s[i]), s[i] += s[i - 1];     printf( %d n , f(1, n, 1, 0));   }


#include <bits/stdc++.h>   inline int getx() {     char c;     int x;     for (c = getchar(); c <  0  || c >  9 ; c = getchar())       ;     for (x = 0; c >=  0  && c <=  9 ; c = getchar())       x = (x << 3) + (x << 1) + c -  0 ;     return x;   }   bool upmax(int &a, const int &b) { return a < b ? a = b, 1 : 0; }   const int MAX_N = 10050;   int n, m;   int v[MAX_N], c[MAX_N];   int f[MAX_N];   int main() {     n = getx(), m = getx();     int c0 = getx(), d0 = getx();     for (int i = c0; i <= n; ++i) upmax(f[i], f[i - c0] + d0);     for (int i = 1; i <= m; ++i) {       int a = getx(), b = getx(), c = getx(), d = getx();       for (int p = b; p <= a; p += b) {         for (int j = n; j >= c; --j) upmax(f[j], f[j - c] + d);       }     }     printf( %d n , f[n]);   }


#include <bits/stdc++.h>   using namespace std;   struct guy {     int x;     int y;     int t;   };   int r, n;   vector<guy> arr;   vector<int> dp;   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     cin >> r >> n;     arr = vector<guy>(n);     dp = vector<int>(n, 0);     for (int i = 0; i < n; i++) {       cin >> arr[i].t >> arr[i].x >> arr[i].y;     }     for (int i = n - 1; i >= 0; i--) {       for (int j = i + 1; j < min(n, i + 4 * r); j++) {         if (abs(arr[j].y - arr[i].y) + abs(arr[j].x - arr[i].x) <=             arr[j].t - arr[i].t)           dp[i] = max(dp[i], 1 + dp[j]);       }     }     int ans = 0;     for (int i = 0; i < n; i++) {       if (abs(1 - arr[i].y) + abs(1 - arr[i].x) <= arr[i].t) {         ans = max(ans, 1 + dp[i]);       }     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INFint = 2e9;   const long long INF = 1e18;   const long long MOD = 1000000007ll;   int g[100][100];   vector<int> used;   set<int> roots;   int n, m;   void dfs(int v, int p) {     used[v] = 1;     for (int i = 0; i < n; i++) {       if (i == p || !g[v][i]) continue;       if (used[i] || roots.count(i)) {         cout <<  NO ;         exit(0);       }       dfs(i, v);     }     used[v] = 1;   }   vector<int> anc;   void addCycle(int st, int en) {     int v = en;     while (v != st) {       roots.insert(v);       v = anc[v];     }     roots.insert(st);   }   bool cycle(int v, int p = -1) {     used[v] = 1;     for (int i = 0; i < n; i++) {       if (i == p || !g[v][i]) continue;       if (used[i]) {         addCycle(i, v);         return 1;       }       anc[i] = v;       if (cycle(i, v)) return 1;     }     used[v] = 1;     return 0;   }   vector<int> p;   int get(int v) { return p[v] == v ? v : p[v] = get(p[v]); }   void unite(int a, int b) {     a = get(a);     b = get(b);     if (a == b) return;     if (rand() & 1) swap(a, b);     p[a] = b;   }   int main() {     ios_base::sync_with_stdio(0);     cin >> n >> m;     used.resize(n);     p.resize(n);     for (int i = 0; i < n; i++) p[i] = i;     for (int i = 0; i < m; i++) {       int a, b;       cin >> a >> b;       a--, b--;       unite(a, b);       g[a][b] = g[b][a] = 1;     }     int cnt = 0;     for (int i = 0; i < n; i++)       if (p[i] == i) cnt++;     if (cnt != 1) {       cout <<  NO ;       return 0;     }     anc.resize(n);     for (int i = 0; i < n; i++) {       if (!used[i]) {         if (cycle(i)) break;       }     }     if (roots.size() < 3) {       cout <<  NO ;       return 0;     }     used.assign(n, 0);     for (auto v : roots) {       for (int i = 0; i < n; i++) {         if (g[v][i] && !roots.count(i)) {           dfs(i, v);         }       }     }     cout <<  FHTAGN! ;     fprintf(stderr,   nTIME = %lf n , 1.0 * clock() / CLOCKS_PER_SEC);     ;     return 0;   }


#include <bits/stdc++.h>   long long memo[100005][205];   std::pair<long long, int> pre[100005];   int n;   struct q4 {     int s, t, d, pin;     long long w;     bool operator<(const q4& wx) const {       return ((w > wx.w) || ((w == wx.w) && (d > wx.d)));     }   };   std::vector<q4> Q[100005];   std::multiset<q4> X;   long long BALLIA(int z, int m) {     if (m < 0)       return 100000000000000001;     else if (z > n)       return 0;     if (memo[z][m] != -1) return memo[z][m];     long long ans = 100000000000000001;     if (pre[z] != std::make_pair(0LL, 0))       ans = std::min(pre[z].first + BALLIA(pre[z].second + 1, m),                      BALLIA(z + 1, m - 1));     else       ans = BALLIA(z + 1, m);     memo[z][m] = ans;     return ans;   }   int main(void) {     std::ios_base::sync_with_stdio(false);     std::cin.tie(NULL);     std::cout.tie(NULL);     memset(memo, -1, sizeof(memo));     int m, k;     std::cin >> n >> m >> k;     for (int i = 1; i <= n; i++) pre[i] = std::make_pair(0LL, 0);     for (int i = 1; i <= k; i++) {       int s, t, d;       long long w;       std::cin >> s >> t >> d >> w;       Q[s].push_back({s, t, d, 1, w});       Q[t + 1].push_back({s, t, d, -1, w});     }     for (int i = 1; i <= n; i++) {       for (auto u : Q[i]) {         if (u.pin == 1)           X.insert(u);         else           X.erase(X.find({u.s, u.t, u.d, 1, u.w}));       }       if (!X.empty())         pre[i] = std::make_pair((*X.begin()).w, (*X.begin()).d);       else         pre[i] = std::make_pair(0LL, 0);     }     long long ans = BALLIA(1, m);     std::cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   const int MAX = 2e5 + 5;   long long dis[MAX];   int a[MAX], ans[MAX];   int pos[MAX];   vector<pair<int, int> > adj[MAX];   void dfs(int x, int idx, long long d) {     pos[idx] = x;     dis[idx] = d;     int len = lower_bound(dis, dis + idx + 1, d - a[x]) - dis - 1;     ans[pos[len]]--;     ans[x]++;     for (int i = 0; i < ((int)(adj[x]).size()); i += 1) {       dfs(adj[x][i].first, idx + 1, d + adj[x][i].second);       ans[x] += ans[adj[x][i].first];     }   }   int main(int argc, char* argv[]) {     if (argc == 2 or argc == 3) freopen(argv[1],  r , stdin);     if (argc == 3) freopen(argv[2],  w , stdout);     ios::sync_with_stdio(false);     int n, p, w;     cin >> n;     for (int i = 1; i < n + 1; i += 1) {       cin >> a[i];     }     for (int i = 2; i < n + 1; i += 1) {       cin >> p >> w;       adj[p].push_back(make_pair(i, w));     }     dis[0] = -1;     dfs(1, 1, 0);     for (int i = 1; i < n + 1; i += 1)       if (i == 1)         cout << ans[i] - 1;       else         cout <<     << ans[i] - 1;     cout << endl;     return 0;   }


#include <bits/stdc++.h>   int main(int argc, char const *argv[]) {     int n, a, b;     while (scanf( %d%d%d , &n, &a, &b) != EOF)       printf( %d n , (n - a) < (b + 1) ? (n - a) : (b + 1));     return 0;   }


#include <bits/stdc++.h>   static const int MAXN = 2e5 + 10;   int n, m;   std::pair<int, int> p[MAXN];   int x_idx[MAXN], x[MAXN];   int a_i, l_i;   inline int solve_query(int u, int len) {     while (true) {       int last_len = len;       int p = std::upper_bound(x, x + n, x[u] + len) - x - 1;       len -= (x[p] - x[u]);       int q = std::lower_bound(x, x + n, x[p] - len) - x;       len -= (x[p] - x[q]);       if (p == q)         return q;       else if (u == q)         len %= (last_len - len);       u = q;     }   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i < n; ++i) {       scanf( %d , &p[i].first);       p[i].second = i + 1;     }     std::sort(p, p + n);     for (int i = 0; i < n; ++i) {       x[i] = p[i].first;       x_idx[p[i].second] = i;     }     for (int i = 0; i < m; ++i) {       scanf( %d%d , &a_i, &l_i);       printf( %d n , p[solve_query(x_idx[a_i], l_i)].second);     }     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     long long l;     cin >> n >> l;     long long *lanterns = new long long[n];     for (long long i = 0; i < n; i++) cin >> lanterns[i];     double maxDistance = 0;     sort(lanterns, lanterns + n);     for (long long i = 0; i < n - 1; i++)       if (lanterns[i + 1] - lanterns[i] > maxDistance)         maxDistance = lanterns[i + 1] - lanterns[i];     if (maxDistance < lanterns[0] * 2) maxDistance = lanterns[0] * 2;     if (maxDistance < (l - lanterns[n - 1]) * 2)       maxDistance = (l - lanterns[n - 1]) * 2;     cout << fixed;     cout << maxDistance / 2;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int n;     cin >> n;     set<int> ms;     for (int i = 0; i < n; ++i) {       int x;       cin >> x;       if (x) ms.insert(x);     }     cout << ms.size() <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   double pi = acos(-1);   void Open() {}   long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }   void PrintNumber(int n, int len) {     if (!len) return;     cout << (n & 1);   }   void PrintAllSubset(int n) {     for (int i = 0; i < (1 << n); i++) {       PrintNumber(i, n);       cout <<   n ;     }   }   void trr() {}   int main() {     std::ios_base::sync_with_stdio(0);     cin.tie(NULL);     long long n, m;     cin >> n >> m;     map<pair<int, int>, int> mpp;     map<int, int> mp;     int x, y;     vector<pair<int, int>> a(m);     for (int i = 0; i < m; i++) {       cin >> x >> y;       a[i] = {x, y};       mpp[{x, y}]++;       mpp[{y, x}]++;       mp[x]++;       mp[y]++;     }     long long h = 0;     while (true) {       int c = 0;       vector<int> r;       for (int i = 0; i < a.size(); i++) {         if (mp[a[i].first] == 0 || mp[a[i].second] == 0) continue;         if (mp[a[i].first] == 1 || mp[a[i].second] == 1) {           c++;           r.push_back(i);         }       }       for (int i = 0; i < r.size(); i++) {         mp[a[r[i]].first]--;         mp[a[r[i]].second]--;       }       if (c > 0)         h++;       else         break;     }     cout << h;   }


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


#include <bits/stdc++.h>   using namespace std;   bool visited[100005];   vector<long long> mp[100005];   long long res = 0;   long long ans = 0;   const long long U = 1e8 + 7;   void dfs(long long second) {     visited[second] = true;     ans++;     for (int i = 0; i < mp[second].size(); i++) {       res++;       if (visited[mp[second][i]] == false) {         dfs(mp[second][i]);       }     }   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long n, m;     cin >> n >> m;     memset(visited, false, sizeof visited);     for (int i = 0; i < m; i++) {       long long a, b;       cin >> a >> b;       mp[a].push_back(b);       mp[b].push_back(a);     }     long long x = 0;     for (int i = 0; i < n; i++) {       if (visited[i] == false) {         res = 0;         ans = 0;         dfs(i);         res = res / 2;         if (res == ans - 1) x++;       }     }     cout << x - 1;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int m[100005], v[100005], selected[100005];   vector<pair<pair<int, int>, int> > V;   int k, n, h;   bool check(long double time) {     long double pos = 1.0;     int id = 0;     for (int i = 0; i < n; i++) {       if (V[i].first.second * 1.0 * time >= pos * h) {         selected[id++] = V[i].second;         pos += 1.0;       }     }     return (id >= k);   }   int main() {     V.clear();     cin >> n >> k >> h;     for (int i = 0; i < n; ++i) cin >> m[i];     for (int i = 0; i < n; ++i) cin >> v[i];     for (int i = 0; i < n; ++i) V.push_back(make_pair(make_pair(m[i], v[i]), i));     sort((V).begin(), (V).end());     long double l = 0, r = 1000000009, mid;     for (int i = 0; i < 200; i++) {       mid = (l + r) * 0.5;       if (check(mid))         r = mid;       else         l = mid;     }     check(r);     for (int i = 0; i < k; ++i) {       if (i != 0) cout <<    ;       cout << selected[i] + 1;     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   struct dsu {     int forests = 0, parent[N], groupsize[N];     void add(int x) {       parent[x] = x;       groupsize[x] = 1;       forests++;     }     int findset(int node) {       if (parent[node] == node) return node;       return parent[node] = findset(parent[node]);     }     bool issameset(int x, int y) { return findset(x) == findset(y); }     void link(int i, int j) {       int x = findset(i), y = findset(j);       if (x == y) return;       if (groupsize[x] < groupsize[y]) swap(x, y);       groupsize[x] += groupsize[y];       parent[y] = x;       forests--;     }   };   map<long long, int> mp;   map<int, vector<pair<int, int>>> e;   int main() {     ios::sync_with_stdio(0), ios_base::sync_with_stdio(0), cin.tie(0),         cout.tie(0);     ;     int n, m;     cin >> n >> m;     dsu mst;     for (int i = 1; i <= n; ++i) mst.add(i);     for (int i = 1; i <= m; ++i) {       int x, y, c;       cin >> x >> y >> c;       e[c].push_back({x, y});     }     long long sum = 0, mx = 0;     for (auto u : e) {       int add = 0;       for (auto uu : u.second) {         if (!mst.issameset(uu.first, uu.second)) {           add++;         }       }       for (auto uu : u.second) {         if (!mst.issameset(uu.first, uu.second)) {           add--;           mst.link(uu.first, uu.second);         }       }       sum += add;     }     cout << sum <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string a, b;     long long team1 = 0, team2 = 0;     cin >> a;     cin >> b;     for (int i = 0; i <= a.size(); i++) {       if ((a[i] ==  [  && b[i] ==  ( ) || (a[i] ==  8  && b[i] ==  [ ) ||           (a[i] ==  (  && b[i] ==  8 )) {         team1++;       } else if ((b[i] ==  [  && a[i] ==  ( ) || (b[i] ==  8  && a[i] ==  [ ) ||                  (b[i] ==  (  && a[i] ==  8 )) {         team2++;       }     }     if (team1 > team2) {       cout <<  TEAM 1 WINS ;     } else if (team1 < team2) {       cout <<  TEAM 2 WINS ;     } else {       cout <<  TIE ;     }     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const int N = 1E5;   int main() {     ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);     string s;     cin >> s;     int len = s.size();     int ans = 0;     for (int i = 0; i < len; i++) {       int l = 0, r = 0;       for (int j = i; j < len; j++) {         if (s[j] ==  ( ) {           l++, r++;         } else if (s[j] ==  ) ) {           l--, r--;         } else {           l--, r++;         }         if (r < 0) break;         if (l < 0) {           l += 2;         }         if (l == 0) {           ans++;         }       }     }     cout << ans << endl;   }


/*   Author: Sanskar Agarwal   Nick: sanskaragarwal   Birla Institute Of Technology, Mesra   */   #include <bits/stdc++.h>   using namespace std;   #define ll long long int   #define endl   n    #define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);   #define F(i,a,b) for(ll i = (ll)(a); i <= (ll)(b); i++)   #define RF(i,a,b) for(ll i = (ll)(a); i >= (ll)(b); i--)   #define INF 100009   #define mod 1000000007   #define pb(x) push_back(x)   #define mp(x,y) make_pair(x,y)   #define ff first   #define ss second   #define test while(t--)solve();      void solve()   {    int n;    cin >> n;    int pos[32];    int arr[n];    memset(pos, 0, sizeof(pos));    int xo = 0;    int pre[n];    for (int i = 0; i < n; ++i)    {     cin >> arr[i];     xo ^= arr[i];     pre[i] = xo;    }    bool flag = !xo;    for (int i = 0; i < n; ++i)    {     for (int j = i + 1; j < n; ++j)     {      int sp1 = pre[i];      int sp2 = pre[j] ^ pre[i];      int sp3 = pre[n - 1] ^ pre[j];      flag |= (sp1 == sp2 && sp2 == sp3);     }    }    if (flag)     cout <<  YES  << endl;    else     cout <<  NO  << endl;   }      int main()   {   #ifndef ONLINE_JUDGE    freopen( input.txt ,  r , stdin);    freopen( output.txt ,  w , stdout);   #endif    fast    int t;    // t = 1;    cin >> t;    test;   #ifndef ONLINE_JUDGE    cout <<   nTime Elapsed :   << 1.0 * clock() / CLOCKS_PER_SEC <<   s n ;   #endif    return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 55;   int type;   const long long int mod = 1e9 + 7;   long long C[N][N];   void matrix_mul(long long A[N][N], long long B[N][N]) {     for (int i = 0; i < type; i++) {       for (int j = 0; j < type; j++) {         C[i][j] = 0;         for (int k = 0; k < type; k++) {           C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % mod;         }       }     }     for (int i = 0; i < type; i++) {       for (int j = 0; j < type; j++) {         A[i][j] = C[i][j];       }     }   }   void pow(long long A[N][N], long long m) {     long long res[N][N];     memset(res, 0, sizeof(res));     for (int i = 0; i < type; i++) res[i][i] = 1;     while (m) {       if (m & 1) matrix_mul(res, A);       matrix_mul(A, A);       m >>= 1;     }     for (int i = 0; i < type; i++) {       for (int j = 0; j < type; j++) {         A[i][j] = res[i][j];       }     }   }   int main() {     ios::sync_with_stdio(false);     long long n, m, k;     cin >> n >> m >> k;     type = m;     long long M[N][N];     for (int i = 0; i < m; i++)       for (int j = 0; j < m; j++) M[i][j] = 1;     while (k--) {       string str;       cin >> str;       char x1 = str[0];       int x1n;       char x2 = str[1];       int x2n;       if (x1 >=  a  && x1 <=  z )         x1n = x1 -  a ;       else if (x1 >=  A  && x1 <=  Z )         x1n = x1 -  A  + 26;       if (x2 >=  a  && x2 <=  z )         x2n = x2 -  a ;       else if (x2 >=  A  && x2 <=  Z )         x2n = x2 -  A  + 26;       M[x1n][x2n] = 0;     }     pow(M, n - 1);     long long sum = 0;     for (int i = 0; i < m; i++)       for (int j = 0; j < m; j++) sum = (sum + M[i][j]) % mod;     cout << sum << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class t>   inline void rd(t &s) {     s = 0;     register char c = getchar();     while (!isdigit(c)) c = getchar();     while (isdigit(c)) s = (s << 3) + (s << 1) + (c ^ 48), c = getchar();     return;   }   int ans[5050];   signed main(void) {     register int n, x1, x2, x3, x;     scanf( %d , &n);     printf( ? 1 2 n );     fflush(stdout);     scanf( %d , &x1);     printf( ? 2 3 n );     fflush(stdout);     scanf( %d , &x2);     printf( ? 1 3 n );     fflush(stdout);     scanf( %d , &x3);     ans[2] = (x1 + x2 - x3) / 2;     ans[1] = x1 - ans[2];     ans[3] = x2 - ans[2];     for (int i = 4; i <= n; ++i) {       printf( ? %d %d n , i - 1, i);       fflush(stdout);       scanf( %d , &x);       ans[i] = x - ans[i - 1];     }     printf( !  );     for (int i = 1; i <= n; ++i) printf( %d  , ans[i]);     printf(  n );     fflush(stdout);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int ZIMAX = 3005;   int n, v;   int cnt[ZIMAX];   int main() {     cin >> n >> v;     for (int i = 1; i <= n; ++i) {       int ai, bi;       cin >> ai >> bi;       cnt[ai] += bi;     }     int ans = 0;     int before = 0;     for (int i = 0; i < ZIMAX; ++i) {       int azi = before;       int ramase = v - azi;       if (ramase < 0) {         ans += v;         before = cnt[i];       } else {         azi += (cnt[i] <= ramase ? cnt[i] : ramase);         ans += azi;         before = max(0, cnt[i] - ramase);       }     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k, a[50];     scanf( %d , &n);     scanf( %d , &k);     for (int i = 0; i < n; i++) scanf( %d , &a[i]);     sort(a, a + n);     if (k > n) {       cout << -1 << endl;       return 0;     }     if (n == k) {       cout << 0 <<     << 0 << endl;       return 0;     }     if (a[n - k - 1] < a[n - k])       cout << a[n - k - 1] + 1 <<     << a[n - k - 1] + 1 << endl;     else       cout << -1 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6 + 10, mod = 1e9 + 7;   inline int ad(int x, int y) {     int ans = x + y;     if (ans > mod) ans -= mod;     return ans;   }   inline int mu(int x, int y) { return 1LL * x * y % mod; }   inline int wop(int x, int y) {     int ret = 1;     while (y) {       if (y & 1) ret = mu(ret, x);       y >>= 1;       x = mu(x, x);     }     return ret;   }   int fact[maxn], inv[maxn], lst[maxn], pr[maxn], cnt[maxn];   int num[maxn][20];   int pw[maxn], pww[maxn];   inline void prep() {     int n = maxn - 5;     fact[0] = 1;     for (int i = 1; i < n; i++) fact[i] = mu(fact[i - 1], i);     for (int i = 0; i < n; i++) inv[i] = wop(fact[i], mod - 2);     pr[0] = pr[1] = 1;     for (int i = 2; i < 300005; i++) {       if (pr[i] == 0) {         lst[i] = i;         for (int j = i * 2; j < 300005; j += i) lst[j] = i, pr[j] = 1;       }     }     for (int i = 1; i < n; i++) pw[i] = ad(mu(pw[i - 1], 2), 1);     pww[0] = 1;     for (int i = 1; i < n; i++) pww[i] = ad(pww[i - 1], pww[i - 1]);   }   inline int C(int r, int n) {     if (r < 0 || r > n) return 0;     return mu(mu(fact[n], inv[n - r]), inv[r]);   }   inline int cal(int x, int y) {     if (x < 0 || y < 1) return 0;     if (x == 0) return pw[y];     int ans = 0;     for (int i = 1; i <= y; i++)       ans = ad(ans, mu(pw[i], C(x - 1, x - 1 + y - i)));     return ans;   }   inline int f(int x, int y) {     if (y <= x) return cal(x, y);     int oth = cal(y, x);     int eq = 0;     for (int i = 0; i <= min(x, y); i++) eq = ad(eq, mu(C(i, x), C(i, y)));     oth = ad(oth, eq);     return ad(pww[x + y], mod - oth);   }   inline int ff(int x, int y) { return f(x + 1, y - 1); }   int ps[20], answer[20];   int solve(vector<int> a, bool rev) {     int n = a.size();     for (int i = 1; i <= n; i++) ps[i] = ps[i - 1] + a[i - 1];     int ans = 0;     for (int j = 1; j < n; j++) {       int tmp;       if (rev) tmp = f(ps[j] - 1, ps[n] - ps[j]);       if (!rev) tmp = ff(ps[j] - 1, ps[n] - ps[j]);       answer[j] = tmp;     }     for (int i = 0; i < n; i++) {       int sum = 0;       for (int j = i + 1; j < n; j++) sum = ad(sum, answer[j]);       ans = ad(ans, mu(sum, a[i]));     }     return ans;   }   int main() {     prep();     int n;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       int x;       scanf( %d , &x);       cnt[x]++;     }     for (int i = 1; i <= 1e6; i++) {       if (cnt[i] == 0) continue;       int cur = i;       while (cur != 1) {         int p = lst[cur], tav = 0;         while (cur % p == 0) cur /= p, tav++;         num[p][tav] += cnt[i];       }     }     int ans = 0;     for (int i = 2; i <= 300000; i++) {       if (pr[i]) continue;       vector<int> a;       int sum = 0;       for (int j = 1; j < 20; j++) sum += num[i][j];       if (sum == 0) continue;       a.push_back(n - sum);       for (int j = 1; j < 20; j++) a.push_back(num[i][j]);       ans = ad(ans, solve(a, 0));       reverse(a.begin(), a.end());       ans = ad(ans, solve(a, 1));     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> e[200005], E[200005], v;   int vis[200005];   inline void dfs(int u) {     if (vis[u]) return;     vis[u] = 1;     v.push_back(u);     int x = E[u][0], y = E[u][1];     if (e[x][0] == e[u][0] || e[x][0] == e[u][1] || e[x][1] == e[u][1] ||         e[x][1] == e[u][0])       dfs(x);     dfs(y);   }   int main(int argc, char** argv) {     int n;     cin >> n;     for (int i = 1; i <= n; i++) {       int x, y;       cin >> x >> y;       e[i].push_back(y);       e[i].push_back(x);       E[x].push_back(i);       E[y].push_back(i);     }     dfs(1);     for (int i = v.size() - 1; i >= 0; i--) cout << v[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int n;     cin >> n;     string s1;     cin >> s1;     vector<pair<char, int> > v;     long long int sz = s1.size();     long long int j = 0;     while (j < sz) {       char ch = s1[j];       if (v.empty() || v.back().first != ch)         v.push_back({ch, 1});       else         v.back().second++;       j++;     }     long long int ans;     if (v.front().second > 1) {       ans = v.front().second - 1;     } else       ans = 1;     string s2 =   ;     s2 += v.front().first;     long long int f = 0;     for (long long int i = 1; i < v.size(); i++) {       if (f) {         s2 += v[i].first;         f = 0;       } else {         if (v[i].second == 1) {           s2 += v[i].first;           f = 1;         } else {           s2 += v[i].first;           s2 += v[i].first;         }       }     }     long long int sz2 = s2.size();     if (sz2 == 0 || sz2 % 2 == 0) {       cout << n - sz2 << endl;       cout << s2 << endl;     } else {       cout << n - sz2 + 1 << endl;       s2[sz2 - 1] =   0 ;       long long int j = 0;       while (j < sz2 - 1) {         cout << s2[j];         j++;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct state {     int x, y;   } bl[100005], rec[100005], cur[100005];   long long n, m;   bool cmp(const state& a, const state& b) {     if (a.y == b.y) return a.x < b.x;     return a.y < b.y;   }   bool funct() {     int counter = 1;     rec[0].x = 1, rec[0].y = 1;     for (int i = 0; i < (int)m; i++) {       if (bl[i].y != bl[i - 1].y + 1) {         counter = 1;         rec[0].y = n;       }       int k = i + 1;       int tmp = 0;       int c = 0;       for (k = i + 1; bl[k].y == bl[i].y; k++)         ;       k = k - 1;       for (int j = i; j <= k; j++) {         if (bl[j].x > tmp + 1) {           cur[c].x = tmp + 1;           cur[c].y = bl[j].x - 1;           c++;         }         tmp = bl[j].x;       }       if (n > tmp) {         cur[c].x = tmp + 1;         cur[c].y = n;         c++;       }       int t = 0;       for (int i = 0; i < counter; i++) {         while (cur[t].x <= rec[i].y && t < c) {           if (cur[t].y >= rec[i].x) {             cur[t].x = max(cur[t].x, rec[i].x);           } else {             cur[t].x = cur[t].y = -1;           }           t++;         }         if (t >= c) break;       }       counter = 0;       for (int i = 0; i < t; i++)         if (cur[i].x != -1 && cur[i].y != -1) {           rec[counter].x = cur[i].x;           rec[counter].y = cur[i].y;           counter++;         }       if (counter == 0) return false;       i = k;     }     if (bl[m - 1].y != n) {       return true;     }     if (rec[counter - 1].y == n) {       return true;     } else {       return false;     }   }   int main() {     cin >> n >> m;     int xx;     int yy;     for (int i = 0; i < (int)m; i++) {       cin >> xx >> yy;       bl[i].x = xx;       bl[i].y = yy;     }     sort(bl, bl + m, cmp);     if (funct()) {       cout << 2 * n - 2 << endl;     } else {       printf( -1 n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long x;   int n, d;   int res[100010], a[100010], b[100010];   long long getNextX() {     x = (x * 37 + 10007) % 1000000007;     return x;   }   void initab() {     for (int i = 0; i < n; i++) {       a[i] = i + 1;     }     for (int i = 0; i < n; i++) {       swap(a[i], a[getNextX() % (i + 1)]);     }     for (int i = 0; i < n; i++) {       if (i < d)         b[i] = 1;       else         b[i] = 0;     }     for (int i = 0; i < n; i++) {       swap(b[i], b[getNextX() % (i + 1)]);     }   }   void sol1() {     for (int i = 0; i < n; i++)       if (b[i]) {         for (int j = i; j < n; j++)           if (res[j] < a[j - i]) res[j] = a[j - i];       }   }   void sol2() {     int k = n - sqrt(n);     for (int i = 0; i < n; i++)       if (a[i] >= k) {         int l = n - i;         for (int j = 0; j < l; j++)           if (b[j] && res[j + i] < a[i]) res[j + i] = a[i];       }     for (int i = 0; i < n; i++)       if (!res[i]) {         for (int j = 0; j <= i; j++)           if (b[i - j] && res[i] < a[j]) res[i] = a[j];       }   }   int main() {     cin >> n >> d >> x;     initab();     int sd = sqrt(n) * 4;     if (d <= sd)       sol1();     else       sol2();     for (int i = 0; i < n; i++) printf( %d n , res[i]);   }


#include <bits/stdc++.h>   using namespace std;   const int max_n = 2e5 + 10;   int n, temp;   vector<int> ans;   int main() {     ios_base::sync_with_stdio(false), cin.tie(0);     cin >> n;     for (int i = 0; i < n; i++) {       cin >> temp;       int pos = lower_bound(ans.begin(), ans.end(), temp) - ans.begin();       if (pos == ans.size())         ans.push_back(temp);       else         ans[pos] = temp;     }     cout << ans.size() << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int digit(char c) {     char digits[] = { 0 ,  1 ,  2 ,  3 ,  4 ,  5 ,  6 ,  7 ,  8 ,  9 };     for (int i = 0; i < 10; i++) {       if (c == digits[i]) return 0;     }     return 1;   }   int main() {     int t = 0;     scanf( %d , &t);     while (t--) {       string s;       cin >> s;       int len = s.length();       int d = 1, c = 1, l = 1;       int cd = 0, cc = 0, cl = 0;       int flag = 0;       for (int i = 0; i < len; i++) {         if (int(s[i]) >= 48 && int(s[i]) <= 57) {           d = 0;           ++cd;         } else if (tolower(s[i]) == s[i]) {           l = 0;           ++cl;         } else if (toupper(s[i]) == s[i]) {           c = 0;           ++cc;         }         if ((d + c + l) == 0) {           flag = 1;           break;         }       }       if (flag == 1) {         cout << s << endl;         continue;       }       if ((d + c + l) == 1) {         if (d) {           if (cl <= cc) {             for (int i = 0; i < len; i++) {               if (toupper(s[i]) == s[i]) {                 s[i] =  7 ;                 break;               }             }           } else {             for (int i = 0; i < len; i++) {               if (tolower(s[i]) == s[i]) {                 s[i] =  7 ;                 break;               }             }           }           d = 0;         }         if (c) {           if (cl <= cd) {             for (int i = 0; i < len; i++) {               if (int(s[i]) >= 48 && int(s[i]) <= 57) {                 s[i] =  A ;                 break;               }             }           } else {             for (int i = 0; i < len; i++) {               if (tolower(s[i]) == s[i] && digit(s[i])) {                 s[i] = toupper(s[i]);                 break;               }             }           }           c = 0;         }         if (l) {           if (cc <= cd) {             for (int i = 0; i < len; i++) {               if (int(s[i]) >= 48 && int(s[i]) <= 57) {                 s[i] =  a ;                 break;               }             }           } else {             for (int i = 0; i < len; i++) {               if (toupper(s[i]) == s[i] && digit(s[i])) {                 s[i] = tolower(s[i]);                 break;               }             }           }         }         l = 0;       }       if ((d + c + l) == 2) {         if (!d) {           s[0] =  A ;           s[1] =  a ;         }         if (!c) {           s[0] =  a ;           s[1] =  7 ;         }         if (!l) {           s[0] =  A ;           s[1] =  7 ;         }       }       cout << s << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int root[1000100];   unordered_map<int, int> mp[1000100];   pair<pair<int, int>, int> edge[1000100];   int cnt[1000100];   int find_root(int u) {     if (root[u] == u) return u;     return root[u] = find_root(root[u]);   }   bool cmp(pair<pair<int, int>, int> u, pair<pair<int, int>, int> v) {     return u.second < v.second;   }   int main() {     int n, m;     scanf( %d%d , &n, &m);     while (m--) {       int u, v;       scanf( %d%d , &u, &v);       cnt[u]++;       cnt[v]++;       mp[u][v] = 1;       mp[v][u] = 1;     }     int mn = n, f = 0;     for (int i = 1; i <= n; i++) {       root[i] = i;       if (mn > cnt[i]) {         f = i;         mn = cnt[i];       }     }     vector<int> X, Y;     X.push_back(f);     for (int i = 1; i <= n; i++) {       if (i == f) continue;       if (!mp[f][i]) {         X.push_back(i);         root[i] = f;       } else         Y.push_back(i);     }     m = 0;     for (int i = 0; i < Y.size(); i++) {       for (int j = i + 1; j < Y.size(); j++) {         int u = Y[i], v = Y[j];         edge[++m] = pair<pair<int, int>, int>(pair<int, int>(u, v), mp[u][v]);       }     }     for (int i = 0; i < Y.size(); i++) {       for (int j = 0; j < X.size(); j++) {         int u = Y[i], v = X[j];         edge[++m] = pair<pair<int, int>, int>(pair<int, int>(u, v), mp[u][v]);       }     }     sort(edge + 1, edge + m + 1, cmp);     int ans = 0;     for (int i = 1; i <= m; i++) {       int u = edge[i].first.first, v = edge[i].first.second, w = edge[i].second;       int fu = find_root(u), fv = find_root(v);       if (fu == fv) continue;       root[fu] = fv;       ans += w;     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   double gmin = 100000000000000017;   int a, b;   int Y1[100005], Y2[100005], L[100005];   double dist(double x1, double y1, double x2, double y2) {     return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));   }   double f(int i, int j) {     return dist(0, 0, a, Y1[i]) + L[j] + dist(a, Y1[i], b, Y2[j]);   }   int main() {     int t, i, j, c, d, idx1, idx2, m, n, idx;     scanf( %d , &n);     scanf( %d , &m);     scanf( %d , &a);     scanf( %d , &b);     for (i = 0; i < n; i++) scanf( %d , &Y1[i]);     for (i = 0; i < m; i++) scanf( %d , &Y2[i]);     for (i = 0; i < m; i++) scanf( %d , &L[i]);     for (i = 0; i < m; i++) {       int low = 0, high = n - 1;       while (high - low >= 3) {         int m1 = low + (high - low) / 3;         int m2 = high - (high - low) / 3;         if (f(m1, i) < f(m2, i))           high = m2;         else           low = m1;       }       double mini = 1000000000000;       for (j = low; j <= high; ++j) {         if (f(j, i) < mini) {           mini = f(j, i);           idx = j;         }       }       if (mini < gmin) {         gmin = mini;         idx1 = idx + 1;         idx2 = i + 1;       }     }     printf( %d  , idx1);     printf( %d  , idx2);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct Node {     char s[110];     int x[30];   } a[2010];   int len, k, n;   int main() {     scanf( %d , &k);     scanf( %s , a[1].s);     len = strlen(a[1].s);     memset(a[1].x, 0, sizeof(a[1].x));     for (int i = 0; i < len; i++) a[1].x[a[1].s[i] -  a ]++;     for (int i = 2; i <= k; i++) a[i] = a[i - 1];     scanf( %d , &n);     while (n--) {       int p;       char c;       scanf( %d %c , &p, &c);       int i = 1;       while (p - a[i].x[c -  a ] > 0) {         p -= a[i].x[c -  a ];         i++;       }       for (int j = 0; j < len; j++)         if (a[i].s[j] == c) {           p--;           if (p == 0) {             a[i].s[j] =  ! ;             a[i].x[c -  a ]--;             break;           }         }     }     for (int i = 1; i <= k; i++)       for (int j = 0; j < len; j++)         if (a[i].s[j] !=  ! ) printf( %c , a[i].s[j]);     puts(  );     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize(3)   using namespace std;   const double PI = acos(-1.0);   const double eps = 1e-6;   inline int read() {     int x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x * f;   }   int a[200010];   int main() {     int n = read();     int fen = 0, gu = 0;     for (int i = 1; i <= n; i++) a[i] = read();     bool ok = 1;     for (int i = 2; i <= n; i++) {       if (a[i] == a[i - 1]) ok = 0;     }     if (ok == 0) {       printf( NO );       return 0;     }     for (int i = 2; i <= n - 1; i++) {       if (a[i - 1] < a[i] && a[i] > a[i + 1])         fen++;       else if (a[i - 1] > a[i] && a[i + 1] > a[i])         gu++;     }     if (fen <= 1 && gu == 0)       printf( YES );     else       printf( NO );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inft = 1000000009;   const int MAXN = 2000006;   bool P[MAXN];   int SP[MAXN];   int PAL[MAXN];   char S[123];   bool pal(int a) {     sprintf(S,  %d , a);     reverse(S, S + strlen(S));     int q;     sscanf(S,  %d , &q);     return a == q;   }   int main() {     for (int i = 0; i < (MAXN); ++i) P[i] = 1;     for (int i = 2; i < MAXN; ++i)       if (P[i])         for (int j = 2 * i; j < MAXN; j += i) P[j] = 0;     P[0] = P[1] = 0;     for (int i = 0; i < (MAXN); ++i)       if (i) SP[i] = SP[i - 1] + P[i];     for (int i = 1; i < MAXN; ++i) PAL[i] = PAL[i - 1] + pal(i);     int ret = 0;     int p, q;     scanf( %d%d , &p, &q);     for (int i = 0; i < (MAXN); ++i)       if (i && q * SP[i] <= p * PAL[i]) ret = i;     if (ret)       printf( %d n , ret);     else       printf( Palindromic tree is better than splay tree n );     return 0;   }


#include <bits/stdc++.h>   int main() {     char s[1000000], c;     int x = 0, y = 0, sum = 0, d;     scanf( %d , &d);     for (int i = 0; i < d; i++) {       scanf(  %c , &c);       s[i] = c;     }     for (int i = 0; i < strlen(s); i++) {       if (s[i] ==  L ) x--;       if (s[i] ==  R ) y++;     }     for (int i = x; i <= y; i++) {       sum++;     }     printf( %d n , sum);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void print(int x, int b) {     if (x) {       print(x / b, b);       printf( %d , x % b);     }   }   int main() {     int k;     cin >> k;     for (int i = (1); i <= (k - 1); ++i)       for (int j = (1); j <= (k - 1); ++j)         print(i * j, k), printf( %c , j == k - 1 ?   n  :    );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long x, long long y) { return y == 0 ? x : gcd(y, x % y); }   bool possible(long long p, long long q, long long x, long long y) {     if (q < y) {       return false;     }     if (p < x) {       return false;     }     return q - y >= p - x;   }   int main() {     int t;     cin >> t;     while (t--) {       long long x, y, p, q;       cin >> x >> y >> p >> q;       long long l = 1, r = 1000000000;       while (l < r) {         long long mid = (l + r) / 2;         if (possible(mid * p, mid * q, x, y)) {           r = mid;         } else {           l = mid + 1;         }       }       if (possible(l * p, l * q, x, y)) {         cout << l * q - y << endl;       } else {         cout << -1 << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int q_pow(int x, int n) {     int ret = 1;     for (; n; n >>= 1, x = (long long)x * x % 998244353)       if (n & 1) ret = (long long)ret * x % 998244353;     return ret;   }   int A[100005 << 2], B[100005 << 2], tmp[100005], tx[100005], ty[100005], Q, n,       m;   void NTT(int *a, int len, int flag) {     int i, j, k, t, w, x, tmp;     for (i = k = 0; i < len; i++) {       if (i > k) swap(a[i], a[k]);       for (j = len >> 1; (k ^= j) < j; j >>= 1)         ;     }     for (k = 2; k <= len; k <<= 1) {       t = k >> 1;       x = q_pow(3, (998244353 - 1) / k);       if (flag == -1) x = q_pow(x, 998244353 - 2);       for (i = 0; i < len; i += k)         for (w = 1, j = i; j < i + t; j++) {           tmp = (long long)a[j + t] * w % 998244353;           a[j + t] = (a[j] - tmp + 998244353) % 998244353;           a[j] = (a[j] + tmp) % 998244353;           w = (long long)w * x % 998244353;         }     }     if (flag == -1)       for (t = q_pow(len, 998244353 - 2), i = 0; i < len; i++)         a[i] = (long long)t * a[i] % 998244353;   }   struct poly {     vector<int> a;     int len;     poly() {}     poly(int x) {       len = 1;       a.push_back(x);     }     void clear() {       len = 0;       a.clear();     }     void rev() { reverse(a.begin(), a.end()); }     void resize(int x) {       a.resize(x);       len = x;     }     poly operator+(const poly &b) const {       poly c;       c.len = max(len, b.len);       c.resize(c.len);       for (int i = 0; i < len; i++) c.a[i] = a[i];       for (int i = 0; i < b.len; i++) c.a[i] = (c.a[i] + b.a[i]) % 998244353;       return c;     }     poly operator-(const poly &b) const {       poly c;       c.len = max(len, b.len);       c.resize(c.len);       for (int i = 0; i < len; i++) c.a[i] = a[i];       for (int i = 0; i < b.len; i++)         c.a[i] = (c.a[i] - b.a[i] + 998244353) % 998244353;       return c;     }     poly operator*(const poly &b) const {       poly c;       c.len = len + b.len;       int n = 1;       while (n < c.len) n <<= 1;       for (int i = 0; i < len; i++) A[i] = a[i];       for (int i = len; i < n; i++) A[i] = 0;       for (int i = 0; i < b.len; i++) B[i] = b.a[i];       for (int i = b.len; i < n; i++) B[i] = 0;       NTT(A, n, 1);       NTT(B, n, 1);       for (int i = 0; i < n; i++) A[i] = (long long)A[i] * B[i] % 998244353;       NTT(A, n, -1);       for (int i = 0; i < c.len; i++) c.a.push_back(A[i]);       return c;     }     poly operator+(const int &b) const {       poly c;       c.len = len;       c.a = a;       (c.a[0] += b) %= 998244353;       return c;     }     poly operator*(const int &b) const {       poly c;       c.len = len;       for (int i = 0; i < len; i++)         c.a.push_back((long long)a[i] * b % 998244353);       return c;     }     void get_inv(poly &b, int n) {       if (n == 1) {         b.a.push_back(q_pow(a[0], 998244353 - 2));         b.len = 1;         return;       }       get_inv(b, n >> 1);       int t = n << 1;       int lim = min(len, n);       for (int i = 0; i < lim; i++) A[i] = a[i];       for (int i = lim; i < t; i++) A[i] = 0;       for (int i = 0; i < b.len; i++) B[i] = b.a[i];       for (int i = b.len; i < t; i++) B[i] = 0;       NTT(A, t, 1);       NTT(B, t, 1);       for (int i = 0; i < t; i++)         A[i] = (2 - (long long)A[i] * B[i] % 998244353 + 998244353) * B[i] %                998244353;       NTT(A, t, -1);       for (int i = 0; i < b.len; i++) b.a[i] = A[i];       for (int i = b.len; i < n; i++) b.a.push_back(A[i]);       b.len = n;     }     poly Dao() {       poly c;       c.len = len - 1;       for (int i = 0; i < c.len; i++)         c.a.push_back(a[i + 1] * (i + 1ll) % 998244353);       return c;     }     poly Jifen() {       poly c;       c.len = len + 1;       c.a.push_back(0);       for (int i = 0; i < len; i++)         c.a.push_back((long long)a[i] * q_pow(i + 1, 998244353 - 2) % 998244353);       return c;     }     poly get_ln(int len) {       poly b = Dao();       poly c;       get_inv(c, len);       return (b * c).Jifen();     }     void get_mod(int b) {       for (int i = b; i < len; i++) a.pop_back();       len = b;     }     int get_val(int x) {       int ret = a[0];       for (int i = 1, tmp = x; i < len; tmp = (long long)tmp * x % 998244353, i++)         ret = (ret + (long long)a[i] * tmp) % 998244353;       return ret;     }     poly operator/(poly b) {       rev();       b.rev();       poly c;       int n = 1;       while (n < (len - b.len + 1)) n <<= 1;       b.get_inv(c, n);       c.get_mod(len - b.len + 1);       n = 1;       while (n < len + c.len) n <<= 1;       for (int i = 0; i < len; i++) A[i] = a[i];       for (int i = len; i < n; i++) A[i] = 0;       for (int i = 0; i < c.len; i++) B[i] = c.a[i];       for (int i = c.len; i < n; i++) B[i] = 0;       NTT(A, n, 1);       NTT(B, n, 1);       for (int i = 0; i < n; i++) A[i] = (long long)A[i] * B[i] % 998244353;       NTT(A, n, -1);       for (int i = 0; i < c.len; i++) c.a[i] = A[i];       c.rev();       rev();       b.rev();       return c;     }     poly operator%(poly b) {       rev();       b.rev();       poly c;       int n = 1;       while (n < (len - b.len + 1)) n <<= 1;       b.get_inv(c, n);       c.get_mod(len - b.len + 1);       n = 1;       while (n < len + c.len) n <<= 1;       for (int i = 0; i < len; i++) A[i] = a[i];       for (int i = len; i < n; i++) A[i] = 0;       for (int i = 0; i < c.len; i++) B[i] = c.a[i];       for (int i = c.len; i < n; i++) B[i] = 0;       NTT(A, n, 1);       NTT(B, n, 1);       for (int i = 0; i < n; i++) A[i] = (long long)A[i] * B[i] % 998244353;       NTT(A, n, -1);       for (int i = 0; i < c.len; i++) c.a[i] = A[i];       c.rev();       rev();       b.rev();       for (int i = 0; i < c.len; i++) A[i] = c.a[i];       for (int i = c.len; i < n; i++) A[i] = 0;       for (int i = 0; i < b.len; i++) B[i] = b.a[i];       for (int i = b.len; i < n; i++) B[i] = 0;       NTT(A, n, 1);       NTT(B, n, 1);       for (int i = 0; i < n; i++) A[i] = (long long)A[i] * B[i] % 998244353;       NTT(A, n, -1);       c.len = b.len;       c.resize(c.len);       for (int i = 0; i < c.len; i++)         c.a[i] = (a[i] - A[i] + 998244353) % 998244353;       return c;     }   } a, b;   void get_rot(const poly &a, poly &b, int len) {     if (len == 1) {       b.a.push_back(1);       b.len = 1;       return;     }     get_rot(a, b, len >> 1);     poly c;     c.clear();     b.get_inv(c, len);     b = b + (c * a);     b = b * ((998244353 + 1) / 2);     b.get_mod(len);   }   void get_exp(const poly &a, poly &b, int len) {     if (len == 1) {       b.a.push_back(1);       b.len = 1;       return;     }     get_exp(a, b, len >> 1);     b = b * ((a - b.get_ln(len)) + 1);     b.get_mod(len);   }   int main() {     scanf( %d%d , &n, &m);     a.resize(m + 1);     a.a[0] = 1;     for (int i = 1, x; i <= n; i++) {       scanf( %d , &x);       if (x <= m) a.a[x] = 998244353 - 4;     }     int len = 1;     while (len <= m) len <<= 1;     get_rot(a, b, len);     b.a[0]++;     a.clear();     b.get_inv(a, len);     for (int i = 1; i <= m; i++) printf( %d n , (a.a[i] << 1) % 998244353);   }


#include <bits/stdc++.h>   int main(int argc, char *argv[]) {     int i, j;     unsigned long long n, result, a[10];     a[0] = 0;     a[1] = 9;     for (i = 2; i <= 9; i++) a[i] = a[i - 1] * 10 + 9;     scanf( %llu , &n);     result = 0;     i = 9;     ;     while (n < a[i]) i--;     result = result + (n - a[i]) * (i + 1);     for (j = 1; j <= i; j++) result = result + (a[j] - a[j - 1]) * j;     printf( %llu , result);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   ifstream f( date.in );   queue<long long> q;   long long n, k, fr[1000001];   long long GCD(long long x, long long y) {     long long r;     do {       r = x % y;       x = y;       y = r;     } while (y != 0);     return x;   }   int main() {     long long ans;     cin >> n >> k;     ans = k;     for (int i = 1; i <= n; i++) {       long long x;       cin >> x;       ans = GCD(x, ans);     }     cout << k / ans <<   n ;     for (int i = 0; i < k / ans; i++) cout << i * ans <<    ;   }


#include <bits/stdc++.h>   using namespace std;   int n, a[1000000], k, cnt, ans;   int main() {     cin >> n;     a[0] = 1;     a[1] = 1;     a[2] = 0;     for (int i = 1; i < n; i++) {       if (a[i] == 0) {         for (int j = i * i; j <= n; j += i) {           a[j] = 1;         }       }     }     for (int i = 1; i <= n; i++) {       cnt = 0;       for (int j = i; j > 0; j--) {         if (i % j == 0) {           k = i / j;         } else {           continue;         }         if (a[k] == 0) {           cnt++;         }       }       if (cnt == 2) {         ans++;       }     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string p;     getline(cin, p);     bool f = 0;     for (int i = 0; i < p.size(); i++) {       if (p[i] >=  a  && p[i] <=  z ) {         if (p[i] ==  a  || p[i] ==  i  || p[i] ==  u  || p[i] ==  e  ||             p[i] ==  o  || p[i] ==  y )           f = 1;         else           f = 0;       }       if (p[i] >=  A  && p[i] <=  Z ) {         if (p[i] ==  A  || p[i] ==  I  || p[i] ==  U  || p[i] ==  E  ||             p[i] ==  O  || p[i] ==  Y )           f = 1;         else           f = 0;       }     }     if (f)       cout <<  YES ;     else       cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long summ(long long n) { return (n * (n + 1)) / 2; }   long long sear(long long n, long long k) {     if (n == 1 && k == 1) return 0;     long long lo = 0, hi = n, mid;     long long sum, eaten;     while (lo <= hi) {       mid = lo + (hi - lo) / 2;       sum = summ(n - mid);       if (mid + k == sum)         return mid;       else if (mid + k > sum)         hi = mid - 1;       else         lo = mid + 1;     }     return mid;   }   int main() {     long long n, k;     cin >> n >> k;     if (n == 1 && k == 1) {       cout << 0 << endl;       return 0;     }     long long ans = sear(n, k);     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long query(long long t, long long i, long long j, long long k) {     cout << t <<     << i <<     << j <<     << k <<     <<   n ;     cout.flush();     long long res;     cin >> res;     return res;   }   void solve() {     long long n;     cin >> n;     long long t1 = 1;     long long oo = 5e18;     vector<pair<long long, long long>> area(n + 1, {-oo, -1});     for (long long i = 1; i <= n; ++i) area[i].second = i;     long long t2 = 2;     for (long long i = 3; i <= n; ++i) {       long long q2 = query(2, t1, t2, i);       t2 = (q2 > 0 ? t2 : i);     }     long long mid = 3, max_s = 0;     for (long long i = 2; i <= n; ++i) {       if (i == t2) continue;       long long q1 = query(1, t1, t2, i);       area[i].first = q1;       if (q1 > max_s) {         max_s = q1;         mid = i;       }     }     area[mid].first = 0;     for (long long i = 2; i <= n; ++i) {       if (i == t2 || i == mid) continue;       long long q2 = query(2, t1, mid, i);       if (q2 > 0) area[i].first = oo - area[i].first;       if (q2 < 0) area[i].first = -oo + area[i].first;     }     sort(area.begin() + 1, area.end());     cout <<  0  ;     for (long long i = 1; i <= n; ++i)       cout << area[i].second << (i == n ?   n  :    );   }   int main() {     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, centru;   int l[10];   int r[10];   int vars(int i, int tip) {     if (!tip) {       if (l[i] <= centru && centru <= r[i])         return centru - l[i];       else if (r[i] < centru)         return r[i] - l[i] + 1;       return 0;     } else if (tip == 1)       return ((bool)(l[i] <= centru && centru <= r[i]));     else {       if (l[i] <= centru && centru <= r[i])         return r[i] - centru;       else if (centru < l[i])         return r[i] - l[i] + 1;       return 0;     }   }   int tip[10];   int _s[3];   double sum;   void backtr(int poz) {     if (poz == (n + 1)) {       if (!_s[1]) return;       if (_s[2] >= 2) return;       if (_s[2] == 0) {         if (_s[1] == 1) return;       }       double prod = 1;       for (int i = 1; i <= n; i++) prod *= vars(i, tip[i]);       sum += centru * prod;       return;     }     for (int i = 0; i < 3; i++) {       _s[i]++;       tip[poz] = i;       backtr(poz + 1);       _s[i]--;     }   }   int main() {     cin >> n;     for (int i = 1; i <= n; i++) cin >> l[i] >> r[i];     for (int i = 1; i <= 10000; i++) {       centru = i;       backtr(1);     }     for (int i = 1; i <= n; i++) {       sum /= (r[i] - l[i] + 1);     }     cout << fixed << setprecision(12) << sum <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline T abs(T &a) {     return a > 0 ? a : -a;   }   template <class T>   inline T min(T &a, T &b) {     return a < b ? a : b;   }   template <class T>   inline T max(T &a, T &b) {     return a > b ? a : b;   }   inline void read(int &x) {     char ch;     while ((ch = getchar()) && !(ch >=  0  && ch <=  9 ))       ;     x = ch -  0 ;     while ((ch = getchar()) && (ch >=  0  && ch <=  9 )) x = x * 10 + ch -  0 ;   }   const int N = 2000002;   int n, m, w[N], ans[N], dy[N], T = 1, t[N << 2];   void add(int x, int c) {     for (t[x += T] += c, x >>= 1; x; x >>= 1) t[x] = t[x << 1] + t[(x << 1) + 1];   }   int find(int k, int l, int r) {     int x = 1;     while (l < r) {       int mid = l + r >> 1;       if (t[x << 1] >= k)         x = x << 1, r = mid;       else         k -= t[x << 1], x = x << 1 | 1, l = mid + 1;     }     return l;   }   int main() {     read(n);     read(m);     int Len = n + m, gs = 0;     while (T < Len) T <<= 1, gs++;     T--;     for (int i = m + 1; i <= n + m; i++) w[i] = i - m, add(i, 1);     int x, y;     for (int i = m; i >= 1; i--) {       read(x);       read(y);       int p = find(y, 1, T + 1);       w[i] = w[p];       add(i, 1);       add(p, -1);       if (ans[w[i]] && ans[w[i]] != x) {         puts( -1 );         return 0;       }       ans[w[i]] = x;       if (dy[x] && dy[x] != w[i]) {         puts( -1 );         return 0;       }       dy[x] = w[i];     }     int j = 1;     for (int i = 1; i <= n; i++) {       if (ans[i])         printf( %d  , ans[i]);       else {         for (; dy[j]; j++)           ;         printf( %d  , j++);       }     }   }


#include <bits/stdc++.h>   using namespace std;   long long a[200005];   map<long long, int> mp;   int main() {     int t;     scanf( %d , &t);     while (t--) {       long long n;       scanf( %lld , &n);       long long sum = 0;       mp.clear();       for (int i = 1; i <= n; i++) {         scanf( %lld , &a[i]);         sum += a[i];       }       long long res = 0;       for (int i = 1; i <= n; i++) {         res += mp[2 * sum - n * a[i]];         mp[n * a[i]]++;       }       printf( %lld n , res);     }   }


#include <bits/stdc++.h>   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,abm,mmx,avx,avx2,popcnt,fma )   #pragma GCC optimize( fast-math )   #pragma GCC optimize( unroll-loops )   #pragma GCC optimize( Ofast )   using namespace std;   const long long mod = 1e9 + 7, mod2 = 998244353;   const long double eps = 1e-6;   const long long inf = 1e18;   const int base = 1e9;   const long double PI = 3.1415926;   void deb(long double first){};   int n, a[100 * 1000];   long long k;   unsigned int bitcount(unsigned long long val) {     return __builtin_popcount(val) + __builtin_popcount(val >> 32);   }   void local() { freopen( test.in ,  r , stdin); }   void remote() {}   void read() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     cin >> n >> k;     for (int i = 0; i < n; i++) cin >> a[i];   }   long long cnt(long long bound, vector<int> &v) {     long long res = 0;     for (int i = 0; i < n; i++) {       int l = 0, r = a[i] + 1;       while (r - l > 1) {         int m = (r + l) / 2;         if (a[i] - 3 * 1ll * m * (m - 1) - 1 >= bound)           l = m;         else           r = m;       }       v[i] = l;       res += l;     }     return res;   }   int main() {     remote();     read();     vector<int> v(n);     long long l = -4e18, r = 4e18;     while (l < r) {       long long m = l + (r - l) / 2;       long long val = cnt(m, v);       if (val > k) {         l = m + 1;       } else         r = m;     }     long long val = cnt(l, v);     vector<int> res = v;     long long val2 = cnt(l - 1, v);     for (int i = 0; i < n; i++)       if (v[i] == res[i] + 1 && val < k) res[i]++, val++;     for (int i = 0; i < n; i++) cout << res[i] <<    ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n;     cin >> n;     cout << 1 + 6 * (n) * (n + 1) / 2 << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1000000007;   const int MAX = 200005;   int cnt[MAX], pre[MAX], suf[MAX];   int bpow(int a, int b) {     int ans = 1;     while (b) {       if (b & 1) ans = 1LL * ans * a % MOD;       b >>= 1;       a = 1LL * a * a % MOD;     }     return ans;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n;     cin >> n;     for (int i = 0; i < n; i++) {       int val;       cin >> val;       cnt[val]++;     }     pre[0] = 1;     for (int i = 1; i < MAX; i++)       pre[i] = 1LL * pre[i - 1] * (cnt[i - 1] + 1) % (MOD - 1);     suf[MAX - 1] = 1;     for (int i = MAX - 2; i >= 0; i--)       suf[i] = 1LL * suf[i + 1] * (cnt[i] + 1) % (MOD - 1);     int ans = 1;     for (int i = 0; i < MAX; i++)       for (int j = 1; j <= cnt[i]; j++)         ans = 1LL * ans *               bpow(bpow(i, j), 1LL * pre[i] * suf[i + 1] % (MOD - 1)) % MOD;     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long a[200010];   long long l[200010];   long long r[200010];   int main() {     ios_base::sync_with_stdio(0);     long long n, h;     cin >> n >> h;     vector<long long> rast2(n + 1, 0);     for (int i = 1; i <= n; i++) {       cin >> l[i] >> r[i];       rast2[i] = r[i] - l[i];     }     for (int i = 1; i <= n; i++) {       rast2[i] += rast2[i - 1];     }     vector<long long> rast(n + 1, 0);     for (int i = 1; i < n; i++) {       rast[i] = l[i + 1] - r[i];     }     rast[n] = 2e9;     for (int i = 1; i <= n; i++) {       rast[i] += rast[i - 1];     }     long long ans = 0;     for (int i = 1; i <= n; i++) {       long long r =           lower_bound(rast.begin(), rast.end(), h + rast[i - 1]) - (rast.begin());       if (r <= n) ans = max(ans, (rast2[r] - rast2[i - 1]) + h);     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   int n;   set<pair<int, int> > s;   vector<int> od;   int p[512];   vector<int> v[512];   inline void dfs(int b, int pr = -1) {     od.push_back(b);     p[b] = pr;     auto it = s.lower_bound(make_pair(b, -1));     while (it != s.end() && (*it).first == b) {       if (it->second == pr) {         it = next(it);         continue;       }       dfs(it->second, b);       v[b].push_back(it->second);       v[it->second].push_back(b);       it = next(it);     }   }   bool us[512];   void init() {     for (int i = 0; i <= n; i++) {       v[i].clear();       us[i] = false;     }   }   int sz[512];   inline pair<int, int> cent(int b, int ALL, int pr) {     sz[b] = 1;     pair<int, int> ret = make_pair(INT_MAX, -1);     int mx = -1;     for (int go : v[b]) {       if (us[go]) continue;       if (go == pr) continue;       ret = min(ret, cent(go, ALL, b));       sz[b] += sz[go];       mx = max(mx, sz[go]);     }     mx = max(mx, ALL - sz[b]);     ret = min(ret, make_pair(mx, b));     return ret;   }   inline void er(int a, int b) {     s.erase(make_pair(a, b));     s.erase(make_pair(b, a));   }   inline void ins(int a, int b) {     s.insert(make_pair(a, b));     s.insert(make_pair(b, a));   }   bool ok(vector<int> &vv, int num, int root, int root2) {     cout << 1 << endl;     cout << root << endl;     cout << num + 1 << endl;     for (int j = 0; j <= num; j++) {       if (j) printf(   );       printf( %d , vv[j]);     }     puts(  );     cout << root2 << endl;     fflush(stdout);     int way;     scanf( %d , &way);     if (way == num + 1) {       return true;     }     return false;   }   inline void df(int b, int add) {     cent(b, 0, -1);     b = cent(b, sz[b], -1).second;     vector<int> z;     for (int go : v[b]) {       z.push_back(go);     }     us[b] = true;     int mint = 0;     int maxt = z.size();     if (z.size() && ok(z, 0, add, b) == false) {       maxt = mint;     }     while (mint + 1 < maxt) {       int mid = (mint + maxt) / 2;       if (ok(z, mid, add, b)) {         mint = mid;       } else {         maxt = mid;       }     }     if (maxt == z.size()) {       ins(b, add);       return;     }     if (us[z[maxt]] == false) {       df(z[maxt], add);       return;     }     er(z[maxt], b);     ins(z[maxt], add);     ins(add, b);   }   int zz[512];   vector<int> o;   bool cmp(int a, int b) { return zz[a] > zz[b]; }   int main() {     cin >> n;     zz[1] = n;     for (int i = 2; i <= n; i++) {       cout << 1 << endl;       cout << 1 << endl;       cout << n - 1 << endl;       for (int j = 2; j <= n; j++) {         if (j > 1) printf(   );         printf( %d , j);       }       puts(  );       printf( %d n , i);       fflush(stdout);       int a;       scanf( %d , &a);       zz[i] = a;     }     for (int i = 2; i <= n; i++) o.push_back(i);     sort(o.begin(), o.end(), cmp);     for (int i : o) {       od.clear();       init();       dfs(1);       reverse(od.begin(), od.end());       df(1, i);     }     puts( ANSWER );     for (auto it : s) {       if (it.first > it.second) continue;       printf( %d %d n , it.first, it.second);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int N, M;   map<string, string> m1;   int main() {     cin >> N >> M;     string s1;     string s2;     for (int i = 1; i <= N; i++) {       cin >> s1;       cin >> s2;       m1[s2] = s1;     }     for (int i = 1; i <= M; i++) {       cin >> s1;       cin >> s2;       s2.erase(s2.begin() + s2.size() - 1);       cout << s1 <<    ;       cout << s2 <<  ; #  << m1[s2] << endl;     }     return 0;   }