#include <bits/stdc++.h>   using namespace std;   int main() {     int h, w, x, y, star = 0, sum, flag;     char arr[505][505];     cin >> h >> w;     for (int i = 1; i <= h; i++) {       for (int j = 1; j <= w; j++) {         cin >> arr[i][j];         if (arr[i][j] ==  * ) {           star++;           if (arr[i][j - 1] ==  *  && arr[i - 1][j] ==  * ) {             sum = 3;             x = i;             y = j;           }         }       }     }     if (sum == 3) {       if (arr[x][y + 1] ==  *  && arr[x + 1][y] ==  * ) {         sum = sum + 2;       }       if (sum == 5) {         flag = 1;         if (x + 2 <= h) {           for (int i = x + 2; i <= h; i++) {             if (arr[i][y] ==  * )               sum++;             else               break;           }         }         if (x - 2 > 0) {           for (int i = x - 2; i > 0; i--) {             if (arr[i][y] ==  * )               sum++;             else               break;           }         }         if (y + 2 <= w)           for (int i = y + 2; i <= w; i++) {             if (arr[x][i] ==  * )               sum++;             else               break;           }         if (y - 2 > 0) {           for (int i = y - 2; i > 0; i--) {             if (arr[x][i] ==  * )               sum++;             else               break;           }         }       }     }     if (star == sum && sum >= 5)       cout <<  YES ;     else       cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   long long s, x;   int main() {     srand(time(NULL));     cin >> n;     n--;     s = 1;     x = 12;     while (n) {       s += x;       x += 12;       n--;     }     cout << s << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int M = 1e5 + 10;   int a[M], col[M], flag;   bool vis[M];   vector<int> vc[M];   vector<pair<int, int> > node[M];   void bfs(int sta) {     col[sta] = 0;     vis[sta] = true;     queue<int> q;     q.push(sta);     while (!q.empty()) {       int u = q.front();       q.pop();       int len = node[u].size();       for (int i = 0; i < len; i++) {         int co = col[u];         pair<int, int> v = node[u][i];         if (v.second == 0) {           co ^= 1;         }         if (vis[v.first] && col[v.first] != co) {           flag = false;           return;         }         if (!vis[v.first]) {           col[v.first] = co;           vis[v.first] = true;           q.push(v.first);         }       }     }   }   int main() {     int n, m;     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);     }     for (int i = 1; i <= m; i++) {       int sz;       scanf( %d , &sz);       for (int j = 1; j <= sz; j++) {         int x;         scanf( %d , &x);         vc[x].push_back(i);       }     }     for (int i = 1; i <= n; i++) {       int u = vc[i][0], v = vc[i][1];       node[v].push_back(make_pair(u, a[i]));       node[u].push_back(make_pair(v, a[i]));     }     memset(vis, false, sizeof(vis));     memset(col, -1, sizeof(col));     flag = true;     for (int i = 1; i <= m; i++) {       if (!vis[i]) {         bfs(i);       }     }     if (flag)       printf( YES n );     else       printf( NO n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a, b, c, n;   int main() {     ios_base::sync_with_stdio(false);     ;     cin >> a >> b >> c >> n;     if (a - c < 0 || b - c < 0) return cout << -1, 0;     if (a + b - c >= n) return cout << -1, 0;     cout << n - (a + b - c);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 5e5 + 5;   int n;   string s;   int main() {     cin >> n;     cin >> s;     bool tmp = false;     for (int i = 0; i <= s.size() - 1; i++) {       if (s[i] > s[i + 1]) {         tmp = true;         s.erase(i, 1);         break;       }     }     if (!tmp) s.erase(s.size() - 1, 1);     cout << s;   }


#include <bits/stdc++.h>   using namespace std;   const int mx = 1e5 + 10;   long long len, ans, val[26], s[mx];   char str[mx];   map<pair<long long, char>, long long> dp;   int main() {     for (int i = 0; i < 26; i++) scanf( %I64d , &val[i]);     scanf( %s , str);     len = strlen(str);     s[0] = val[str[0] -  a ];     for (int i = 1; i < len; i++) s[i] = s[i - 1] + val[str[i] -  a ];     for (int i = 0; i < len; i++) {       ans += dp[make_pair(s[i - 1], str[i])];       dp[make_pair(s[i], str[i])]++;     }     printf( %I64d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, t, sum = 0, x;     cin >> n >> x;     while (n--) {       cin >> t;       sum += t;     }     if (sum < 0) sum *= -1;     int ans = sum / x + bool(sum % x);     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   int main() {     int n;     scanf( %d , &n);     int p = 0;     int a[100100];     for (int i = 0; i < n; i++) scanf( %d , &a[i]);     int s = n + n - 1;     for (int i = 0; i < n; i++) {       s += fabs(a[i] - p);       p = a[i];     }     printf( %d n , s);   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:100000000000000 )   using namespace std;   const long long int INF = 2e9 + 1;   char s[50000], s2[50000];   struct automato {     struct leaf {       int link, len;       map<char, int> nex;       bool cl;       leaf() : cl(false) {}     };     vector<leaf> tree;     vector<int> cnt, used;     int sz, pre;     automato() {}     void init() {       sz = 1;       pre = 0;       tree.resize(2 * 50000);       cnt.resize(2 * 50000, 0);       used.resize(2 * 50000, 0);       tree[0].link = -1;       tree[0].len = 0;     };     void add_s(char c) {       int cur = sz++;       tree[cur].len = tree[pre].len + 1;       int temp = pre;       for (; temp != -1 && !tree[temp].nex.count(c); temp = tree[temp].link) {         tree[temp].nex[c] = cur;       }       if (temp == -1) {         tree[cur].link = 0;       } else {         int p = tree[temp].nex[c];         if (tree[p].len == tree[temp].len + 1) {           tree[cur].link = p;         } else {           int clone = sz++;           tree[clone].nex = tree[p].nex;           tree[clone].len = tree[temp].len + 1;           tree[clone].link = tree[p].link;           tree[clone].cl = true;           tree[p].link = clone;           tree[cur].link = clone;           for (; temp != -1 && tree[temp].nex.count(c) && tree[temp].nex[c] == p;                temp = tree[temp].link) {             tree[temp].nex[c] = clone;           }         }       }       pre = cur;     };     void add_str(char *s) {       int n = strlen(s);       for (int i = 0; i < (n); i++) {         add_s(s[i]);       }     }     void dfs() {       vector<pair<int, int> > len;       for (int i = 0; i < (sz); i++) {         len.push_back(make_pair(tree[i].len, i));       }       sort(len.begin(), len.end());       reverse(len.begin(), len.end());       for (int i = 0; i < (sz); i++) {         int id = len[i].second;         if (!tree[id].cl) cnt[id]++;         if (tree[id].link != -1) cnt[tree[id].link] += cnt[id];       }     }     int nx(int id, char c) {       if (!tree[id].nex.count(c)) return -1;       return tree[id].nex[c];     }     int get_cnt(int now) { return cnt[now]; }   };   int main() {     scanf( %s%s , &s, &s2);     int n = strlen(s), m = strlen(s2);     automato a, b;     a.init();     b.init();     a.add_str(s);     b.add_str(s2);     a.dfs();     b.dfs();     int out = INF;     for (int i = 0; i < n; i++) {       int st = 0, st2 = 0;       for (int j = i; j < n; j++) {         st = a.nx(st, s[j]);         st2 = b.nx(st2, s[j]);         if (st == -1 || st2 == -1) break;         if (a.get_cnt(st) == 1 && b.get_cnt(st2) == 1) {           out = min(out, j - i + 1);           break;         }       }     }     cout << (out == INF ? -1 : out);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     double n, k;     cin >> n >> k;     double a, b;     cin >> a >> b;     n--;     double len = 0;     while (n--) {       double x, y;       cin >> x >> y;       len += ((double)sqrt(pow(x - a, 2) + pow(y - b, 2)));       a = x;       b = y;     }     len *= k;     cout << fixed << setprecision(9) << len / (double)50 <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e4;   const int T = 24 * 60 * 60;   int was, n, M, add, cnt, ans[N];   vector<int> ind[T];   int main() {     scanf( %d%d%d , &n, &M, &add);     for (int i = 0; i < (int)(n); i++) {       int h, m, s;       scanf( %d:%d:%d , &h, &m, &s);       ind[s + 60 * (m + 60 * h)].push_back(i);     }     set<pair<int, int> > s;     for (int i = 0; i < (int)(T); i++) {       while ((int)(s).size() && s.begin()->first <= i) s.erase(s.begin());       for (int j : ind[i]) {         if ((int)(s).size() < M)           ans[j] = ++cnt;         else {           ans[j] = s.rbegin()->second;           s.erase(*s.rbegin());         }         s.insert(pair<int, int>(i + add, ans[j]));       }       was |= (int)(s).size() == M;     }     if (!was)       puts( No solution );     else {       printf( %d n , cnt);       for (int i = 0; i < (int)(n); i++) printf( %d n , ans[i]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 998244353;   int sum(int a, int b) { return (a + b) % MOD; }   int prod(int a, int b) { return a * 1ll * b % MOD; }   int mpow(int b, int e) {     if (e == 0) return 1;     if (e & 1) return prod(b, mpow(b, e - 1));     return mpow(prod(b, b), e / 2);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0), cout.tie(0);     cout << fixed << setprecision(15);     const int HALF = mpow(2, MOD - 2);     int N;     cin >> N;     vector<vector<int> > adj(N);     for (int i = 0; i < N - 1; i++) {       int u, v;       cin >> u >> v;       adj[u - 1].push_back(v - 1);       adj[v - 1].push_back(u - 1);     }     int ans = 0;     function<int(int, int)> calc = [&](int loc, int par) {       int nm = 1;       for (int nbr : adj[loc]) {         if (nbr == par) continue;         int unv = calc(nbr, loc);         unv = sum(unv, prod(HALF, sum(1, MOD - unv)));         nm = prod(nm, unv);       }       nm = sum(1, MOD - nm);       ans = sum(ans, nm);       return nm;     };     calc(0, 0);     for (int i = 0; i < N; i++) ans = prod(ans, 2);     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n;     bool a = false;     cin >> n;     for (long long i = 1; i < n; i++) {       for (long long j = 1; j < n; j++) {         if (((n - i - j) % 3) != 0 && (i % 3) != 0 && (j % 3) != 0) {           cout << i <<     << j <<     << (n - i - j) << endl;           a = true;           break;         }       }       if (a) break;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int gi() {     int x = 0, w = 1;     char ch = getchar();     while ((ch <  0  || ch >  9 ) && ch !=  - ) ch = getchar();     if (ch ==  - ) w = 0, ch = getchar();     while (ch >=  0  && ch <=  9 )       x = (x << 3) + (x << 1) + ch -  0 , ch = getchar();     return w ? x : -x;   }   const int N = 3e5 + 5;   int q, fa[N + N], top;   pair<int, int> sz[N + N], sta[N];   map<pair<int, int>, int> M;   vector<pair<int, int> > vec[N << 2];   long long ans;   pair<int, int> operator+(pair<int, int> a, pair<int, int> b) {     return make_pair(a.first + b.first, a.second + b.second);   }   pair<int, int> operator-(pair<int, int> a, pair<int, int> b) {     return make_pair(a.first - b.first, a.second - b.second);   }   int find(int x) { return x == fa[x] ? x : find(fa[x]); }   void modify(int x, int l, int r, int ql, int qr, pair<int, int> p) {     if (l >= ql && r <= qr) {       vec[x].push_back(p);       return;     }     int mid = l + r >> 1;     if (ql <= mid) modify(x << 1, l, mid, ql, qr, p);     if (qr > mid) modify(x << 1 | 1, mid + 1, r, ql, qr, p);   }   void dfs(int x, int l, int r) {     int tt = top;     for (pair<int, int> p : vec[x])       if (find(p.first) != find(p.second)) {         int u = find(p.first), v = find(p.second);         if (sz[u].first + sz[u].second < sz[v].first + sz[v].second) swap(u, v);         sta[++top] = make_pair(u, v);         ans -= 1ll * sz[u].first * sz[u].second;         ans -= 1ll * sz[v].first * sz[v].second;         fa[v] = u;         sz[u] = sz[u] + sz[v];         ans += 1ll * sz[u].first * sz[u].second;       }     if (l == r)       printf( %lld  , ans);     else {       int mid = l + r >> 1;       dfs(x << 1, l, mid);       dfs(x << 1 | 1, mid + 1, r);     }     while (top > tt) {       int u = sta[top].first, v = sta[top].second;       --top;       ans -= 1ll * sz[u].first * sz[u].second;       fa[v] = v;       sz[u] = sz[u] - sz[v];       ans += 1ll * sz[u].first * sz[u].second;       ans += 1ll * sz[v].first * sz[v].second;     }   }   int main() {     q = gi();     for (int i = 1; i <= q; ++i) {       int x = gi(), y = gi() + N;       if (M.find(make_pair(x, y)) == M.end())         M[make_pair(x, y)] = i;       else         modify(1, 1, q, M[make_pair(x, y)], i - 1, make_pair(x, y)),             M.erase(make_pair(x, y));     }     for (auto it = M.begin(); it != M.end(); ++it)       modify(1, 1, q, (*it).second, q, (*it).first);     for (int i = 1; i < N + N; ++i) fa[i] = i, sz[i] = make_pair(i < N, i >= N);     dfs(1, 1, q);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, s, k;   vector<int> a;   void Input() {     cin >> n >> s >> k;     a.clear();     a.resize(k);     for (auto &z : a) cin >> z;   }   void Solve() {     for (int i = 0; i <= k; i++) {       if (s - i >= 1 && find(a.begin(), a.end(), s - i) == a.end()) {         cout << i <<   n ;         return;       }       if (s + i <= n && find(a.begin(), a.end(), s + i) == a.end()) {         cout << i <<   n ;         return;       }     }     assert(false);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     int T;     cin >> T;     while (T--) {       Input();       Solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, i, j, a[102][102];     scanf( %d , &n);     ;     for (i = 0; i < n; i++) {       for (j = 0; j < n; j++) scanf( %d , &a[i][j]);       ;     }     if (i == 1) {       printf( 0 n );       return 0;     }     for (i = 0; i < n; i++) {       int f[32] = {0};       for (j = 0; j < n; j++) {         if (i == j) continue;         int x = a[i][j], c = 0;         while (x > 0) {           if (x & 1) f[c] = 1;           c++;           x /= 2;         }       }       int ans = 0, k;       j = 1;       for (k = 0; k < 32; k++) {         if (f[k]) ans += j;         j *= 2;       }       printf( %d  , ans);     }     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     int a[t];     for (int i = 0; i < t; i++) {       cin >> a[i];       if (360 % (180 - a[i]) == 0)         cout <<  YES  << endl;       else         cout <<  NO  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   void chmax(T &a, T b) {     if (a < b) a = b;   }   template <class T>   void chmin(T &a, T b) {     if (a > b) a = b;   }   constexpr long long INF = 1000000000000000000;   constexpr long long mod = 1000000007;   constexpr long double eps = 1e-8;   const long double pi = acos(-1);   long long dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};   long long Random(long long mi, long long ma) {     random_device rnd;     mt19937 mt(rnd());     uniform_int_distribution<long long> engine(mi, ma);     return engine(mt);   }   long long gcd(long long a, long long b) {     if (b == 0) return a;     return gcd(b, a % b);   }   long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }   bool prime(long long a) {     if (a == 1) return false;     for (long long i = 2; i * i <= a; i++) {       if (a % i == 0) return false;     }     return true;   }   long long modpow(long long a, long long b) {     if (b == 0) return 1;     if (b % 2) return modpow(a, b - 1) * a % mod;     long long memo = modpow(a, b / 2);     return memo * memo % mod;   }   vector<long long> kaijo, invkaijo;   void init_fact(long long n) {     kaijo.resize(n + 1);     invkaijo.resize(n + 1);     kaijo[0] = 1;     for (long long i = 1; i <= n; i++) {       kaijo[i] = kaijo[i - 1] * i;       kaijo[i] %= mod;     }     for (long long i = 0; i < n + 1; i++) invkaijo[i] = modpow(kaijo[i], mod - 2);   }   long long comb(long long a, long long b) {     if (a < b) return 0;     if (a < 0 || b < 0) return 0;     return kaijo[a] * modpow(kaijo[a - b], mod - 2) % mod *            modpow(kaijo[b], mod - 2) % mod;   }   long long inv(long long x) {     x = modpow(x, mod - 2);     return x;   }   struct BIT {     long long n, beki = 1;     vector<long long> bit;     BIT(long long x) {       bit.resize(x + 1, 0);       n = x;       while (beki * 2 <= n) beki *= 2;     }     long long sum(long long i) {       long long res = 0;       while (i > 0) {         res += bit[i];         i -= i & -i;       }       return res;     }     void add(long long i, long long x) {       while (i <= n) {         bit[i] += x;         i += i & -i;       }     }     long long lowerbound(long long w) {       if (w <= 0) return 0;       long long x = 0;       for (long long k = beki; k > 0; k >>= 1) {         if (x + k <= n && bit[x + k] < w) {           w -= bit[x + k];           x += k;         }       }       return x + 1;     }   };   signed main() {     cin.tie(0);     ios::sync_with_stdio(false);     long long n, k;     cin >> n >> k;     vector<pair<long long, long long> > v[200010];     BIT bit(200001);     for (long long i = 0; i < n; i++) {       long long l, r;       cin >> l >> r;       bit.add(l, 1);       bit.add(r + 1, -1);       v[l].push_back({r, i + 1});     }     priority_queue<pair<long long, long long> > q;     vector<long long> ans;     for (long long i = 1; i <= 200000; i++) {       for (pair<long long, long long> j : v[i]) q.push(j);       while (bit.sum(i) > k) {         bit.add(i, -1);         bit.add(q.top().first + 1, 1);         ans.push_back(q.top().second);         q.pop();       }     }     cout << ans.size() << endl;     for (long long i : ans) cout << i <<    ;     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void data() {}   const int N = 1e6 + 100;   const long long mod = 998244353;   const long long mod2 = 1e9 + 7;   map<int, int> was, was2;   int main() {     data();     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       int a[n + 1];       for (int i = 1; i <= n; i++) {         cin >> a[i];       }       int len = 0;       for (int i = 1; i <= n - 1 && a[i] == 1; i++) {         len++;       }       if (len % 2 == 0) {         cout <<  First n ;       } else {         cout <<  Second n ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   struct edge {     int u, v;     long long w;   };   long long MOD = 1000000007;   long long _MOD = 1000000009;   double EPS = 1e-10;   long long c[100][100];   long long C(long long n, long long k) {     if (n < 100) return c[n][k];     long long ans = 1;     for (int i = 0; i < k; i++) ans *= n - i;     for (int i = 1; i <= k; i++) ans /= i;     return ans;   }   class NumberMagic {    public:     int theMin(int _N, int _M) {       if (_N == 1) return 0;       for (int i = 0; i < 100; i++) {         c[i][0] = 1;         for (int j = 1; j <= i; j++) c[i][j] = c[i - 1][j - 1] + c[i - 1][j];       }       long long N = _N, M = _M;       long long lb = 0, ub = N - 1;       while (ub - lb > 1) {         long long mid = (lb + ub) / 2;         long long n = N, sum = 0;         for (long long k = 0; k <= mid && n; k++) {           long long unko = min(n, C(mid, k));           n -= unko;           sum += k * unko;         }         if (!n && sum <= mid * M)           ub = mid;         else           lb = mid;       }       return ub;     }   };   int main() {     NumberMagic nm;     int T;     cin >> T;     while (T--) {       int N, M;       cin >> N >> M;       cout << nm.theMin(N, M) << endl;     }   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:256000000 )   using namespace std;   mt19937 ggen;   int n, s;   int a[200010];   int ctr[200010];   vector<int> v;   void solve() {     cin >> n >> s;     s--;     for (int i = 0; i < n; i++) cin >> a[i];     int ans = 0;     if (a[s] != 0) ans++;     for (int i = 0; i < n; i++) {       if (i != s) {         if (a[i] == 0) a[i] = 200009;         ctr[a[i]]++;         v.push_back(a[i]);       }     }     sort(v.begin(), v.end());     for (int i = 1; !v.empty() && i <= v.back(); i++) {       if (ctr[i] == 0) {         ans++;         ctr[v.back()]--;         v.pop_back();       }     }     cout << ans;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     ggen = mt19937(13);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T, bool maximum_mode = false>   struct RMQ {     int n = 0, levels = 0;     vector<vector<T>> range_min;     RMQ(const vector<T> &values = {}) {       if (!values.empty()) build(values);     }     static int largest_bit(int x) { return 31 - __builtin_clz(x); }     static T better(T a, T b) { return maximum_mode ? max(a, b) : min(a, b); }     void build(const vector<T> &values) {       n = values.size();       levels = largest_bit(n) + 1;       range_min.resize(levels);       for (int k = 0; k < levels; k++) range_min[k].resize(n - (1 << k) + 1);       if (n > 0) range_min[0] = values;       for (int k = 1; k < levels; k++)         for (int i = 0; i <= n - (1 << k); i++)           range_min[k][i] =               better(range_min[k - 1][i], range_min[k - 1][i + (1 << (k - 1))]);     }     T query_value(int a, int b) const {       assert(0 <= a && a < b && b <= n);       int level = largest_bit(b - a);       return better(range_min[level][a], range_min[level][b - (1 << level)]);     }   };   template <typename T_string>   struct suffix_array {     int n = 0;     T_string str;     vector<int> suffix;     vector<int> rank;     vector<int> lcp;     RMQ<int> rmq;     suffix_array() {}     suffix_array(const T_string &_str, bool build_rmq = true) {       build(_str, build_rmq);     }     void build(const T_string &_str, bool build_rmq = true) {       str = _str;       n = str.size();       suffix.resize(n);       for (int i = 0; i < n; i++) suffix[i] = i;       bool large_alphabet = false;       for (int i = 0; i < n; i++)         if (str[i] < 0 || str[i] >= 128) large_alphabet = true;       if (large_alphabet) {         sort(suffix.begin(), suffix.end(),              [&](int a, int b) { return str[a] < str[b]; });       } else {         vector<int> freq(128, 0);         for (int i = 0; i < n; i++) freq[str[i]]++;         for (int c = 1; c < 128; c++) freq[c] += freq[c - 1];         for (int i = 0; i < n; i++) suffix[--freq[str[i]]] = i;       }       rank.resize(n);       rank[suffix[0]] = 0;       for (int i = 1; i < n; i++)         rank[suffix[i]] =             str[suffix[i]] == str[suffix[i - 1]] ? rank[suffix[i - 1]] : i;       vector<int> next_index(n);       vector<int> values(n);       bool done = false;       for (int len = 1; len < n && !done; len *= 2) {         for (int i = 0; i < n; i++) next_index[i] = i;         for (int i = n - len; i < n; i++) values[next_index[rank[i]]++] = i;         for (int i = 0; i < n; i++) {           int prev = suffix[i] - len;           if (prev >= 0) values[next_index[rank[prev]]++] = prev;         }         swap(suffix, values);         values[suffix[0]] = 0;         done = true;         for (int i = 1; i < n; i++) {           int s = suffix[i], prev = suffix[i - 1];           if (s + len < n && prev + len < n && rank[s] == rank[prev] &&               rank[s + len] == rank[prev + len]) {             values[s] = values[prev];             done = false;           } else {             values[s] = i;           }         }         swap(rank, values);       }       compute_lcp();       if (build_rmq) rmq.build(lcp);     }     void compute_lcp() {       lcp.assign(n, 0);       int match = 0;       for (int i = 0; i < n; i++) {         if (rank[i] == 0) continue;         int a = suffix[rank[i]] + match;         int b = suffix[rank[i] - 1] + match;         while (a < n && b < n && str[a++] == str[b++]) match++;         lcp[rank[i]] = match;         match = max(match - 1, 0);       }     }     int get_lcp_from_ranks(int a, int b) const {       if (a == b) return n - suffix[a];       if (a > b) swap(a, b);       return rmq.query_value(a + 1, b + 1);     }     int get_lcp(int a, int b) const {       if (a >= n || b >= n) return 0;       if (a == b) return n - a;       return get_lcp_from_ranks(rank[a], rank[b]);     }     int compare(int a, int b, int length = -1) const {       if (length < 0) length = n;       if (a == b) return 0;       int common = get_lcp(a, b);       if (common >= length) return 0;       if (a + common >= n || b + common >= n) return a + common >= n ? -1 : 1;       return str[a + common] < str[b + common]                  ? -1                  : (str[a + common] == str[b + common] ? 0 : 1);     }   };   string str;   suffix_array<string> SA;   vector<long long> prefix_sum;   int search_index(int start, int end, int i, int character) {     int low = start, high = end;     while (low < high) {       int mid = (low + high) / 2;       if (str[SA.suffix[mid] + i] >= character)         high = mid;       else         low = mid + 1;     }     return low;   }   long long compute_substring_count(int i, int start, int end) {     return prefix_sum[end] - prefix_sum[start] - (long long)i * (end - start);   }   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     long long K;     cin >> str >> K;     int N = str.size();     if (K > (long long)N * (N + 1) / 2) {       cout <<  No such line.  <<   n ;       return 0;     }     assert(1 <= K && K <= (long long)N * (N + 1) / 2);     SA.build(str);     prefix_sum.assign(N + 1, 0);     for (int i = 0; i < N; i++)       prefix_sum[i + 1] = prefix_sum[i] + N - SA.suffix[i];     int start = 0, end = N;     string substring =   ;     for (int i = 0; i < N; i++) {       if (SA.suffix[start] + i == N) start++;       int low = start, high = end;       while (low < high) {         int mid = (low + high) / 2;         long long additional = compute_substring_count(i, start, mid);         if (additional >= K)           high = mid;         else           low = mid + 1;       }       assert(low > start);       int c = str[SA.suffix[low - 1] + i];       substring += c;       int c_start = search_index(start, low, i, c);       K -= compute_substring_count(i, start, c_start);       start = c_start;       end = search_index(low, end, i, c + 1);       K -= end - start;       if (K <= 0) break;     }     cout << substring <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e4 + 7;   const long long INF = 1e18;   const int maxn = 6e5 + 5;   int n, m, k;   struct edge {     int to, cost;     edge() {}     edge(int to, int cost) : to(to), cost(cost) {}   };   vector<edge> G[maxn];   int d[maxn];   pair<int, int> p[maxn];   map<pair<int, int>, int> mp;   int dx[4] = {0, 0, 1, -1};   int dy[4] = {1, -1, 0, 0};   void dijkstra(int s) {     priority_queue<pair<int, int>, vector<pair<int, int> >,                    greater<pair<int, int> > >         q;     fill(d, d + maxn, 0x7fffffff);     d[s] = 0;     q.push(pair<int, int>(0, s));     while (!q.empty()) {       pair<int, int> p = q.top();       q.pop();       int v = p.second;       if (d[v] < p.first) continue;       for (int i = 0; i < G[v].size(); i++) {         edge e = G[v][i];         if (d[e.to] > d[v] + e.cost) {           d[e.to] = d[v] + e.cost;           q.push(pair<int, int>(d[e.to], e.to));         }       }     }   }   int main() {     cin >> n >> m >> k;     int dd = 1e4 + 5;     mp.clear();     for (int i = 1; i <= k; i++) {       int r, c;       scanf( %d%d , &r, &c);       G[i].push_back(edge(r + dd, 1));       G[i].push_back(edge(c + dd * 2, 1));       G[i].push_back(edge(r + 1 + dd, 1));       G[i].push_back(edge(r - 1 + dd, 1));       G[i].push_back(edge(c + dd * 2 + 1, 1));       G[i].push_back(edge(c + dd * 2 - 1, 1));       G[r + dd].push_back(edge(i, 0));       G[c + dd * 2].push_back(edge(i, 0));       G[r + 1 + dd].push_back(edge(i, 0));       G[r - 1 + dd].push_back(edge(i, 0));       G[c + dd * 2 + 1].push_back(edge(i, 0));       G[c + dd * 2 - 1].push_back(edge(i, 0));       p[i] = pair<int, int>(r, c);       mp[pair<int, int>(r, c)] = i;     }     for (int i = 1; i <= k; i++) {       for (int j = 0; j < 4; j++) {         int x = p[i].first + dx[j];         int y = p[i].second + dy[j];         if (mp.find(pair<int, int>(x, y)) != mp.end())           G[i].push_back(edge(mp[pair<int, int>(x, y)], 0));       }     }     if (mp.find(pair<int, int>(n, m)) == mp.end()) {       G[n + dd].push_back(edge(k + 1, 0));       G[m + 2 * dd].push_back(edge(k + 1, 0));     }     int ans;     dijkstra(mp[pair<int, int>(1, 1)]);     if (mp.find(pair<int, int>(n, m)) == mp.end()) {       ans = d[k + 1];     } else       ans = d[mp[pair<int, int>(n, m)]];     if (ans == 0x7fffffff) ans = -1;     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int a, b, c;     int f1, f2, s1, s2, t1, t2;     cin >> f1 >> f2 >> s1 >> s2 >> t1 >> t2;     int sum1 = f1 + s1 + t1;     a = f1;     b = s1;     c = t1;     n -= sum1;     if (n > 0) {       f2 = f2 - f1;       if (f2 < n) {         a += f2;         s2 = s2 - s1;         n -= f2;         if (s2 < n) {           b += s2;           t2 = t2 - t1;           n -= s2;           if (t2 < n)             c += t2;           else             c += n;         } else           b += n;       } else         a += n;     }     cout << a <<     << b <<     << c << endl;   }


#include <bits/stdc++.h>   using namespace std;   int a[105];   int main() {     int n, c, max = 0, t;     scanf( %d%d , &n, &c);     for (int i = 0; i < n; i++) scanf( %d , &a[i]);     for (int i = 0; i < n - 1; i++) {       t = a[i] - c;       if (t < 0)         continue;       else {         t -= a[i + 1];         if (t > max) max = t;       }     }     printf( %d n , max);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 1e5 + 10;   int main() {     int a, b, c;     while (cin >> a >> b >> c) {       int s[MAX] = {0};       s[a]++;       s[b]++;       s[c]++;       if (s[1] >= 1 || s[2] >= 2 || s[3] >= 3 || (s[2] == 1 && s[4] == 2))         printf( YES n );       else         printf( NO n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1000000000;   const int MAX = 100005;   const int RIGHT = 131072;   const int SIZE = 263000;   double L[MAX], R[MAX], T[SIZE];   int X[MAX], H[MAX], N, M;   pair<int, int> Mush[MAX];   void update(int l, int r, double p, int n, int a, int b) {     if (a > r || b < l) return;     if (a >= l && b <= r) {       T[n] *= p;       return;     }     int mid = (a + b) / 2;     update(l, r, p, 2 * n, a, mid);     update(l, r, p, 2 * n + 1, mid + 1, b);   }   double query(int x, int n, int a, int b) {     if (a > x || b < x) return 1.0;     if (a == b) return T[n];     int mid = (a + b) / 2;     return T[n] * query(x, 2 * n, a, mid) * query(x, 2 * n + 1, mid + 1, b);   }   int main() {     scanf( %d%d , &N, &M);     for (int i = (1); i <= (N); i++)       scanf( %d%d%lf%lf , &X[i], &H[i], &L[i], &R[i]);     for (int i = (1); i <= (N); i++) L[i] /= 100.0, R[i] /= 100.0;     for (int i = (1); i <= (M); i++)       scanf( %d%d , &Mush[i].first, &Mush[i].second);     sort(Mush + 1, Mush + 1 + M);     for (int i = (1); i <= (SIZE - 1); i++) T[i] = 1.0;     for (int i = (1); i <= (N); i++) {       int a, b;       a = lower_bound(Mush + 1, Mush + M + 1, make_pair(X[i] - H[i], 0)) - Mush;       b = lower_bound(Mush + 1, Mush + M + 1, make_pair(X[i], 0)) - Mush - 1;       update(a, b, 1.0 - L[i], 1, 1, RIGHT);       a = upper_bound(Mush + 1, Mush + M + 1, make_pair(X[i], 1000000005)) - Mush;       b = upper_bound(Mush + 1, Mush + M + 1,                       make_pair(X[i] + H[i], 1000000005)) -           Mush - 1;       update(a, b, 1.0 - R[i], 1, 1, RIGHT);     }     double ans = 0;     for (int i = (1); i <= (M); i++)       ans += query(i, 1, 1, RIGHT) * Mush[i].second;     cout << setprecision(15) << fixed << ans;   }


#include <bits/stdc++.h>   using namespace std;   const int N = (int)1e5 + 5, mod = (int)0;   int best[N], q[N];   int main() {     string s;     cin >> s;     int n = (int)s.size();     best[n] = 1e9;     for (int j = n - 1; j >= 0; --j) {       s[j] -=  a ;       best[j] = min(best[j + 1], (int)s[j]);     }     string res =   ;     int t = 0;     for (int j = 0; j < n; ++j) {       q[t++] = s[j];       while (t > 0 && q[t - 1] <= best[j + 1]) res += char(q[t - 1] +  a ), --t;     }     cout << res << endl;   }


#include <bits/stdc++.h>   using namespace std;   string nb;   int main() {     int N;     cin >> N;     cin >> nb;     string m;     m.append(N,  9 );     string act = nb;     for (int shift = 0; shift < N; shift++) {       for (int p = 0; p <= 9; p++) {         m = min(m, act);         for (int i = 0; i < N; i++) act[i] = ((act[i] -  0  + 1) % 10 +  0 );       }       char first = act[0];       for (int i = 1; i < N; i++) act[i - 1] = act[i];       act[N - 1] = first;     }     cout << m << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string b, b1, b2, e1, e2, e;     cin >> b1 >> b2 >> e1 >> e2;     swap(b2[0], b2[1]);     swap(e2[0], e2[1]);     b = b1 + b2;     e = e1 + e2;     b.erase(b.find( X ), 1);     e.erase(e.find( X ), 1);     if ((b + b).find(e) != string::npos) {       cout <<  YES ;     } else       cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct EDGE {     int v, next;   };   EDGE w[222];   long long f[1 << 17], Y;   int ans[22], ww[22], visit[22], N, M, W = 0;   long long work() {     memset(f, 0, sizeof(f));     f[0] = 1;     for (int i = 0; i < 1 << N; ++i)       if (f[i]) {         if (i == 3) int asd = 1;         int u = 0;         for (int ii = i; ii; ii >>= 1) u += (ii & 1);         u++;         int sta = 1, end = N;         if (visit[u]) sta = end = visit[u];         for (int j = sta; j <= end; ++j)           if (!(i & (1 << j - 1))) {             bool flag = 1;             for (int k = ww[j]; k && flag; k = w[k].next)               if (i & (1 << w[k].v - 1)) flag = 0;             if (!flag) continue;             f[i | (1 << j - 1)] += f[i];           }       }     return f[(1 << N) - 1];   }   int main() {     scanf( %d%I64d%d , &N, &Y, &M);     Y -= 2000;     for (int i = 1, u, v; i <= M; ++i) {       scanf( %d%d , &u, &v);       w[++W].v = v;       w[W].next = ww[u];       ww[u] = W;     }     if (work() < Y) {       puts( The times have changed );       exit(0);     }     for (int i = 1; i <= N; ++i) {       for (int j = 1; j <= N; ++j)         if (!visit[j]) {           visit[j] = i;           long long now = work();           if (now >= Y) {             ans[i] = j;             break;           }           Y -= now;           visit[j] = 0;         }     }     for (int i = 1; i <= N; ++i) printf( %d%c , ans[i], (i == N ?   n  :    ));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int t;     cin >> t;     bool flag;     while (t--) {       int n;       cin >> n;       long long int a[n];       for (int i = 0; i < n; i++) cin >> a[i];       flag = true;       sort(a, a + n);       long long int k = a[0] * a[n - 1], tmp;       for (int i = 0; i < n; i++) {         tmp = a[i] * a[n - 1 - i];         if (tmp != k) flag = false;       }       int ptr = 0;       if (flag) {         for (int i = 2; i <= sqrt(k); i++) {           if (k % i == 0) {             if (a[ptr] == i)               ptr++;             else {               flag = false;               break;             }           }         }       }       if (flag)         cout << k << endl;       else         cout << -1 << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   using VV = vector<vector<T>>;   template <class T>   inline T SMIN(T& a, const T b) {     return a = (a > b) ? b : a;   }   template <class T>   inline T SMAX(T& a, const T b) {     return a = (a < b) ? b : a;   }   template <class Iter>   void dumpc(Iter begin, Iter end) {     if (false) {       for (; begin != end; ++begin) {         cerr << *begin <<  , ;       }       cerr << endl;     }   }   int Q;   map<int, int> comp;   int getid(int a) {     if (comp.count(a)) return comp[a];     comp[a] = int((comp).size());     return comp[a];   }   struct UF {    public:     int groupNum;     vector<int> X;     UF(int N) {       uf = vector<int>(N);       rank = vector<int>(N);       X = vector<int>(N);       for (int i = 0; i < N; ++i) uf[i] = i, rank[i] = 0;       groupNum = N;     }     pair<int, int> find(int v) {       int cur = 0;       while (uf[v] != v) {         cur ^= X[v];         v = uf[v];       }       return {v, cur};     }     bool same(int x, int y) { return find(x) == find(y); }     void unite(int x, int y, int z) {       auto px = find(x);       auto py = find(y);       if (px.first == py.first) return;       groupNum--;       x = px.first, y = py.first;       z = px.second ^ py.second ^ z;       if (rank[x] == rank[y]) {         uf[x] = y;         X[x] = z;         rank[y]++;         return;       }       if (rank[x] < rank[y]) {         uf[x] = y;         X[x] = z;       } else {         uf[y] = x;         X[y] = z;         if (rank[x] == rank[y]) ++rank[x];       }     }       private:     vector<int> rank;     vector<int> uf;   };   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cin >> Q;     UF uf(2 * Q + 10);     int last = 0;     while (Q--) {       int t, l, r;       cin >> t >> l >> r;       l ^= last, r ^= last;       if (l > r) swap(l, r);       ++r;       if (false) {         cerr <<  l               <<   =   << (l) <<  ,                <<  r               <<   =   << (r) <<  ,                <<  getid(l)               <<   =   << (getid(l)) <<  ,                <<  getid(r)               <<   =   << (getid(r)) << endl;       };       l = getid(l), r = getid(r);       if (t == 1) {         int x;         cin >> x;         x ^= last;         uf.unite(l, r, x);       } else {         pair<int, int> p1 = uf.find(l), p2 = uf.find(r);         if (false) {           cerr <<  p1.first                 <<   =   << (p1.first) <<  ,                  <<  p2.first                 <<   =   << (p2.first) << endl;         };         if (p1.first != p2.first) {           last = 1;           fprintf(stdout,  %d , -1), putchar(  n );           ;         } else {           if (false) {             cerr <<  Q                   <<   =   << (Q) <<  ,                    <<  p1.second                   <<   =   << (p1.second) <<  ,                    <<  p2.second                   <<   =   << (p2.second) << endl;           };           last = p1.second ^ p2.second;           fprintf(stdout,  %d , last), putchar(  n );           ;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   inline void add(long long &a, long long b) {     a += b;     a %= MOD;   }   inline void sub(long long &a, long long b) {     a -= b;     a %= MOD;   }   inline long long mul(long long a, long long b) {     return (long long)a * b % MOD;   }   const int N = 1e6 + 10;   struct pnt {     long long x, y;     pnt(long long _x = 0, long long _y = 0) : x(_x), y(_y) {}     inline pnt operator+(const pnt &p) const { return pnt(x + p.x, y + p.y); }     inline pnt operator-(const pnt &p) const { return pnt(x - p.x, y - p.y); }     inline pnt &operator+=(const pnt &p) {       add(x, p.x), add(y, p.y);       return *this;     }     inline pnt &operator-=(const pnt &p) {       sub(x, p.x), sub(y, p.y);       return *this;     }     inline pnt operator*(const int &k) const { return pnt(x * k, y * k); }     inline pnt operator/(const int &k) const { return pnt(x / k, y / k); }     inline long long operator*(const pnt &p) const { return x * p.y - y * p.x; }     inline long long operator^(const pnt &p) const { return x * p.x + y * p.y; }     void out() { printf( (%lld,%lld)  , x, y); }   } p[3 * N];   long long get(int i, int j, int k) { return (p[j] - p[i]) * (p[k] - p[j]); };   int main() {     ios_base::sync_with_stdio(0), cin.tie(0);     int n;     cin >> n;     for (int i = 0; i < (int)(n); i++) cin >> p[i].x >> p[i].y;     long long s = 0;     for (int i = 0; i < (int)(n); i++) s += p[i] * p[(i + 1) % n];     if (s < 0) {       s = -s;       reverse(p, p + n);     }     for (int i = 0; i < (int)(n); i++) p[i + 2 * n] = p[i + n] = p[i];     struct Calc {       long long sum, s;       pnt diff, diff2;       Calc() : sum(0), s(0) {}       void inc_r(int l, int r) {         s += get(l, r, r + 1);         assert(s >= 0);         add(sum, s);         diff2 += p[r + 1] - p[r];         diff -= diff2;       }       void inc_l(int l, int r) {         s -= get(l, l + 1, r);         pnt dp = p[l + 1] - p[l];         diff2 -= dp;         diff += dp * (r - l);         add(sum, dp * diff);       }     } c1, c2;     long long res = 0;     int r1 = 0, r2 = 0;     for (int l = 0; l < (int)(n); l++) {       while (r1 - l < n && abs(c1.s + get(l, r1, r1 + 1)) <= s / 2) {         c1.inc_r(l, r1++);       }       assert(r1 - l <= n - 2);       while (r2 - l < n - 2) c2.inc_r(l, r2++);       long long mid = (2 * c1.s == s ? s / 2 : 0LL);       long long big = c2.sum - c1.sum;       long long small = (c1.sum - mid);       add(res, big - small);       c1.inc_l(l, r1);       c2.inc_l(l, r2);     }     cout << ((res) % MOD + MOD) % MOD << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e6 + 10, mod = 1e9 + 7;   int rd() {     int x = 0, w = 1;     char ch = 0;     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) w = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + (ch ^ 48);       ch = getchar();     }     return x * w;   }   int prm[N], pm[N], tt, n, a[N], c[N][2];   bool v[N];   int main() {     for (int i = 2; i <= N - 5; ++i) {       if (!pm[i]) pm[i] = prm[++tt] = i;       for (int j = 1; i * prm[j] <= N - 5; ++j) {         pm[i * prm[j]] = prm[j];         if (i % prm[j] == 0) break;       }     }     n = rd();     for (int i = 1; i <= n; ++i) a[i] = rd();     sort(a + 1, a + n + 1), reverse(a + 1, a + n + 1);     for (int i = 1; i <= n; ++i) {       if (!c[a[i]][0])         v[i] = 1, c[a[i]][0] = c[a[i]][1] = 1;       else {         int x = a[i] - 1;         while (x > 1) {           int np = pm[x], cn = 0;           while (pm[x] == np) ++cn, x /= np;           if (c[np][0] < cn)             c[np][0] = cn, c[np][1] = 1;           else             c[np][1] += c[np][0] == cn;         }       }     }     int ans = 1;     for (int i = 2; i <= N - 5; ++i)       for (int j = 1; j <= c[i][0]; ++j) ans = 1ll * ans * i % mod;     for (int i = 1; i <= n; ++i)       if (!v[i]) {         int x = a[i] - 1, o = 1;         while (x > 1) {           int np = pm[x], cn = 0;           while (pm[x] == np) ++cn, x /= np;           o &= cn < c[np][0] || c[np][1] > 1;         }         if (o) {           ans = (ans + o) % mod;           break;         }       }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   vector<int> edges[(200 * 1000 + 5)];   vector<int> f;   vector<int> a;   int dp[(200 * 1000 + 5)][5];   void read_data() {     cin >> n;     int u, v;     for (int i = 1; i < n; i++) {       scanf( %d %d , &u, &v);       edges[u].push_back(v);       edges[v].push_back(u);     }   }   void bfs() {     int qf, ql;     a.resize(n);     f.resize(n + 1);     vector<int> isv;     isv.resize(n + 1);     qf = ql = 0;     a[ql++] = 1;     isv[1] = true;     while (qf != ql) {       int u = a[qf++];       for (auto &v : edges[u])         if (!isv[v]) {           f[v] = u;           isv[v] = true;           a[ql++] = v;         }     }   }   void deal() {     int sum[5];     for (int i = n - 1; i > 0; i--) {       int u = a[i];       if (edges[u].size() == 1 && u != 1) {         memset(dp[u], 0, sizeof(dp[u]));         dp[u][0] = 1;         dp[u][1] = 0;         dp[u][2] = 1;       } else {         memset(sum, 0, sizeof(sum));         for (auto &v : edges[u])           if (v != f[u]) {             sum[2] += dp[v][2];             sum[1] += dp[v][1];           }         memset(dp[u], 0xff, sizeof(dp[u]));         dp[u][1] = sum[2];         dp[u][0] = sum[1] + 1;         for (auto &v : edges[u])           if (v != f[u]) {             if (dp[u][2] == -1) {               dp[u][2] = sum[2] - dp[v][2] + dp[v][0];             } else {               dp[u][2] = min(dp[u][2], sum[2] - dp[v][2] + dp[v][0]);             }           }         dp[u][2] = min(dp[u][2], dp[u][0]);         dp[u][1] = min(dp[u][1], dp[u][2]);       }     }     int ans = 0;     for (auto &v : edges[1]) ans += dp[v][0];     ans -= edges[1].size();     cout << ans << endl;   }   int main() {     read_data();     bfs();     deal();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void _print(int32_t t) { cerr << t; }   void _print(int64_t t) { cerr << t; }   void _print(string t) { cerr << t; }   void _print(char t) { cerr << t; }   void _print(long double t) { cerr << t; }   void _print(double t) { cerr << t; }   void _print(unsigned long long t) { cerr << t; }   template <class T, class V>   void _print(pair<T, V> p);   template <class T>   void _print(vector<T> v);   template <class T>   void _print(set<T> v);   template <class T, class V>   void _print(map<T, V> v);   template <class T>   void _print(multiset<T> v);   template <class T, class V>   void _print(pair<T, V> p) {     cerr <<  { ;     _print(p.first);     cerr <<  , ;     _print(p.second);     cerr <<  } ;   }   template <class T>   void _print(vector<T> v) {     cerr <<  [  ;     for (T i : v) {       _print(i);       cerr <<    ;     }     cerr <<  ] ;   }   template <class T>   void _print(set<T> v) {     cerr <<  [  ;     for (T i : v) {       _print(i);       cerr <<    ;     }     cerr <<  ] ;   }   template <class T>   void _print(multiset<T> v) {     cerr <<  [  ;     for (T i : v) {       _print(i);       cerr <<    ;     }     cerr <<  ] ;   }   template <class T, class V>   void _print(map<T, V> v) {     cerr <<  [  ;     for (auto i : v) {       _print(i);       cerr <<    ;     }     cerr <<  ] ;   }   int64_t find(int64_t mid) {     int64_t ans = 0;     while (mid != 0) {       mid /= 2;       ans++;     }     return ans;   }   void solve() {     int64_t n, k;     cin >> n >> k;     int64_t low = 1, high = 1;     for (int64_t i = 0; i < n - 1; i += 1) {       high *= 2;       high++;     }     while (low <= high) {       int64_t mid = (low + high) / 2;       if (mid == k) {         cout << find(high - low + 1);         return;       }       if (mid > k) {         high = mid - 1;       }       if (mid < k) low = mid + 1;     }   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int64_t t = 1;     while (t--) {       solve();       cout <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   void printVector(vector<string> &v) {     for (auto x : v) cout << x <<   n ;   }   void printVector(vector<int> &v) {     for (auto x : v) cout << x <<    ;     cout <<   n ;   }   int main() {     cin.tie(0);     cout.tie(0);     ios::sync_with_stdio(0);     int t;     t = 1;     while (t--) {       int n, k, x;       cin >> n >> k >> x;       vector<int> freq(1024, 0);       vector<int> upd(1024, 0);       vector<int> calc(1024);       for (int i = 0; i < 1024; i++) {         calc[i] = i xor x;       }       for (int i = 0; i < n; i++) {         int a;         cin >> a;         freq[a]++;       }       for (int i = 0; i < k; i++) {         int sum = 0;         for (int j = 0; j < 1024; j++) {           int s = freq[j];           if (sum % 2 == 0) s++;           s /= 2;           upd[calc[j]] += s;           sum += freq[j];           freq[j] -= s;         }         for (int j = 0; j < 1024; j++) {           freq[j] += upd[j];           upd[j] = 0;         }       }       int mn, mx;       for (int j = 0; j < 1024; j++) {         if (freq[j] > 0) {           mn = j;           break;         }       }       for (int j = 1023; j >= 0; j--) {         if (freq[j] > 0) {           mx = j;           break;         }       }       cout << mx <<     << mn <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   struct node {     int len, l, r;     bool operator<(const node &a) const { return len > a.len; }   };   int day[200010];   int m[200010];   int main() {     int n, k, c, i, j;     scanf( %d %d , &n, &k);     c = 0;     for (i = 0; i < n; i++) {       scanf( %d , &day[i]);       if (day[i] < 0) c++;     }     if (c > k) {       printf( -1 n );       return 0;     }     int turn = 0;     bool f = 0;     priority_queue<node> q;     for (i = 0; i < n; i++) {       if (day[i] < 0) {         m[i] = 1;         k--;       }       if (!f && day[i] < 0) {         turn++;         f = 1;       }       if (f && day[i] >= 0) {         turn++;         f = 0;       }     }     int l = 0, r = 0;     i = 0;     while (m[i] == 0 && i < n) i++;     for (; i < n; i++) {       if (m[i] == 0) {         l = i;         while (m[i] == 0 && i < n) i++;         r = i - 1;         node tp;         tp.l = l, tp.r = r;         tp.len = r - l + 1;         q.push(tp);         i = i - 1;       }     }     int tt = turn, kk = k;     while (!q.empty()) {       node x = q.top();       q.pop();       if (k < x.len && kk < x.len)         break;       else {         if (k >= x.len) {           k -= x.len;           if (x.r != n - 1) {             turn -= 2;           } else             turn--;         }         if (kk >= x.len) {           if (x.r != n - 1) {             kk -= x.len;             tt -= 2;           }         }       }     }     printf( %d n , min(turn, tt));   }


#include <bits/stdc++.h>   using namespace std;   inline void OPEN(const string &s) {     freopen((s +  .in ).c_str(),  r , stdin);     freopen((s +  .out ).c_str(),  w , stdout);   }   int main() {     int n;     scanf( %d , &n);     int art;     scanf( %d , &art);     int alex;     scanf( %d , &alex);     int ans[110] = {0};     for (int i = 0; i < art; i++) {       int temp;       scanf( %d , &temp);       if (ans[temp] == 0) ans[temp] = 1;     }     for (int i = 0; i < alex; i++) {       int temp;       scanf( %d , &temp);       if (ans[temp] == 0) ans[temp] = 2;     }     for (int i = 1; i < n + 1; i++) {       if (ans[i] == 0)         printf( 1  );       else         printf( %d  , ans[i]);     }   }


#include <bits/stdc++.h>   using namespace std;   int M[2002][2002];   struct TA {     int a[2002], n;     void init(int _n) {       n = _n;       memset(a, 0, sizeof a);     }     int get(int p) {       int ret = 0;       for (p++; p > 0; p -= p & -p) ret ^= a[p - 1];       return ret;     }     void change(int l) {       for (l++; l <= n; l += l & -l) a[l - 1] ^= 1;     }     void change(int l, int r) {       change(l);       change(r + 1);     }   } R[2002], C[2002];   void put(int r, int c) {     R[r].change(min(r, c), max(r, c));     C[c].change(min(r, c), max(r, c));     M[r][c] ^= 1;   }   int get(int r, int c) { return R[r].get(c) ^ C[c].get(r) ^ M[r][c]; }   int main() {     int n;     cin >> n;     for (int i = 0; i < n; ++i) {       scanf(   );       for (int j = 0; j < n; ++j) {         M[i][j] = getchar() ==  1 ;       }       R[i].init(n);       C[i].init(n);     }     int ans = 0;     for (int i = 0; i < n; ++i) {       for (int r = n - 1; r > i; --r) {         if (get(r, i)) {           ++ans;           put(r, i);         }       }       for (int c = n - 1; c > i; --c) {         if (get(i, c)) {           ++ans;           put(i, c);         }       }       if (get(i, i)) {         ++ans;         put(i, i);       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   class MinHeap {     vector<long long int> arr;     long long int size;       public:     MinHeap() { size = 0; }     long long int parent(long long int i) { return (i - 1) / 2; }     long long int lchild(long long int i) { return 2 * i + 1; }     long long int rchild(long long int i) { return 2 * i + 2; }     long long int minimum() { return arr[0]; }     long long int length() { return size; }     void insert(long long int i) {       size++;       arr.push_back(i);       long long int index = size - 1;       while (i != 0 && arr[parent(index)] > arr[index]) {         swap(arr[parent(index)], arr[index]);         index = parent(index);       }     }     void minheapify_down(long long int i) {       while (i < size) {         long long int l = lchild(i);         long long int r = rchild(i);         long long int small = i;         if (l < size) small = arr[small] < arr[l] ? small : l;         if (r < size) small = arr[small] < arr[r] ? small : r;         swap(arr[i], arr[small]);         if (i == small) break;         i = small;       }     }     void minheapify_up(long long int i) {       long long int index = i;       while (i != 0 && arr[parent(index)] > arr[index]) {         swap(arr[parent(index)], arr[index]);         index = parent(index);       }     }     void extractmin() {       long long int min = arr[0];       swap(arr[0], arr[size - 1]);       arr.pop_back();       size--;       minheapify_down(0);     }     void changekey(long long int i, long long int value) {       if (value > arr[i]) {         arr[i] = value;         minheapify_down(i);       } else {         arr[i] = value;         minheapify_up(i);       }     }     void deletekey(long long int i) {       changekey(i, LLONG_MIN);       extractmin();     }   };   int main() {     ;     ios::sync_with_stdio(0);     cin.tie(0);     ;     long long int n, k, t, b, ans = 0, count = 0, sum = 0;     cin >> n >> k;     vector<vector<long long int>> beauti(1000001);     for (long long int i = 0; i < n; i++) {       cin >> t >> b;       beauti[b].push_back(t);     }     MinHeap length;     for (long long int i = 1000000; i >= 1; i--) {       if (beauti[i].size() != 0) {         for (long long int j = 0; j < beauti[i].size(); j++) {           sum += beauti[i][j];           length.insert(beauti[i][j]);           count++;           if (count > k) {             long long int ele = length.minimum();             sum -= ele;             length.deletekey(0);             count--;           }         }         ans = max(ans, i * sum);       }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<long long> invi(long long n) {     int x;     vector<long long> a;     for (long long i = 0; i < n; i++) {       cin >> x;       a.push_back(x);     }     return a;   }   void solve();   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t = 1;     while (t--) solve();   }   void solve() {     long long n, k;     cin >> n >> k;     vector<long long> jobcho = invi(n);     vector<long long> time = invi(n);     vector<long long> ind;     vector<long long> task;     for (long long i = 0; i < k; i++) {       task.push_back(0);       ind.push_back(n + 1);     }     for (long long i = 0; i < n; i++) {       if (task[jobcho[i] - 1] < time[i]) {         task[jobcho[i] - 1] = time[i];         ind[jobcho[i] - 1] = i;       }     }     for (long long i = 0; i < k; i++) {       if (ind[i] < (n + 1)) time[ind[i]] = 1e10;     }     long long jbleft = 0;     for (long long i = 0; i < k; i++) {       if (task[i] == 0) {         jbleft++;       }     }     sort(time.begin(), time.end());     long long sum = 0;     for (long long i = 0; i < jbleft; i++) {       sum += time[i];     }     cout << sum <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     char prev[26], next[26];     for (int i = 0; i < 26; i++) prev[i] = next[i] = -1;     int n;     cin >> n;     for (int i = 0; i < n; i++) {       string s;       cin >> s;       if (prev[s[0] -  a ] == -1) prev[s[0] -  a ] = 0;       if (next[s[(int)s.size() - 1] -  a ] == -1)         next[s[(int)s.size() - 1] -  a ] = 0;       for (int j = 1; j < (int)s.size(); j++) {         prev[s[j] -  a ] = s[j - 1];         next[s[j - 1] -  a ] = s[j];       }     }     for (int i = 0; i < 26; i++) {       if (prev[i] == 0) {         char cur =  a  + i;         while (cur) {           printf( %c , cur);           cur = next[cur -  a ];         }       }     }     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   const int INFint = 2147483547;   const long long INF = 9223372036854775807ll;   const long long MOD = 1000000007ll;   const long double EPS = 1e-13;   string min_cyclic_shift(string s) {     s += s;     int n = (int)s.length();     int i = 0, ans = 0;     while (i < n / 2) {       ans = i;       int j = i + 1, k = i;       while (j < n && s[k] <= s[j]) {         if (s[k] < s[j])           k = i;         else           ++k;         ++j;       }       while (i <= k) i += j - k;     }     return s.substr(ans, n / 2);   }   int main() {     ios_base::sync_with_stdio(0);     vector<string> a(2), b(2);     for (int i = 0; i < 2; i++) cin >> a[i];     for (int i = 0; i < 2; i++) cin >> b[i];     string s;     for (int i = 0; i < 2; i++) {       if (a[0][i] ==  X ) continue;       s += a[0][i];     }     for (int i = 1; i > -1; i--) {       if (a[1][i] ==  X ) continue;       s += a[1][i];     }     string s1;     for (int i = 0; i < 2; i++) {       if (b[0][i] ==  X ) continue;       s1 += b[0][i];     }     for (int i = 1; i > -1; i--) {       if (b[1][i] ==  X ) continue;       s1 += b[1][i];     }     if (min_cyclic_shift(s) == min_cyclic_shift(s1)) {       cout <<  YES ;     } else       cout <<  NO ;     fprintf(stderr,   nTIME = %lf n , 1.0 * clock() / CLOCKS_PER_SEC);     ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   bool isPrime(int n) {     if (n == 1) return false;     for (int i = 2; i * i <= n; ++i) {       if (n % i == 0) return false;     }     return true;   }   void solve() {     int n, sum = 0;     cin >> n;     vector<int> a(n);     for (int i = 0; i < n; ++i) {       cin >> a[i];       sum += a[i];     }     if (!isPrime(sum)) {       cout << n <<   n ;       for (int i = 1; i <= n; ++i) {         cout << i <<    ;       }       cout <<   n ;     } else {       cout << n - 1 <<   n ;       int oddpos = -1;       for (int i = 0; i < n; ++i) {         if (a[i] % 2 != 0) {           oddpos = i;           break;         }       }       for (int i = 0; i < n; ++i) {         if (i != oddpos) cout << i + 1 <<    ;       }       cout <<   n ;     }   }   int main() {     ios_base::sync_with_stdio(false);     int t;     cin >> t;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, x;     int a[100000 + 3], b[100000 + 3];     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];       b[i] = a[i];     }     sort(b, b + n);     int cnt = 1;     for (int i = 0; i < n; i++) {       if (a[i] != b[i]) {         cnt++;       }     }     if (cnt == 3 || cnt == 1) {       cout <<  YES ;       return 0;     }     cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   int n, m, p;   long long ans = -1e18;   struct nd {     int val, c;     friend bool operator<(nd a, nd b) { return a.val < b.val; }   } a[N], b[N];   struct mon {     int x, y, z;     friend bool operator<(mon a, mon b) { return a.x < b.x; }   } c[N];   struct BIT {     int tot;     int ls[N << 1], rs[N << 1];     long long mx[N << 1], tag[N << 1];     void up(int x) { mx[x] = max(mx[ls[x]], mx[rs[x]]); }     void down(int x) {       if (!tag[x]) return;       if (ls[x]) {         mx[ls[x]] += tag[x];         tag[ls[x]] += tag[x];       }       if (rs[x]) {         mx[rs[x]] += tag[x];         tag[rs[x]] += tag[x];       }       tag[x] = 0;     }     int build(int l, int r) {       int x = ++tot;       if (l == r) {         mx[x] = -b[l].c;         return x;       }       int mid = l + r >> 1;       ls[x] = build(l, mid);       rs[x] = build(mid + 1, r);       up(x);       return x;     }     void add(int x, int l, int r, int L, int R, long long d) {       if (L <= l && r <= R) {         mx[x] += d;         tag[x] += d;         return;       }       down(x);       int mid = l + r >> 1;       if (L <= mid) add(ls[x], l, mid, L, R, d);       if (R > mid) add(rs[x], mid + 1, r, L, R, d);       up(x);     }     void init() {       mx[0] = -1e18;       int root = build(1, m);     }   } T;   int main() {     scanf( %d%d%d , &n, &m, &p);     for (int i = 1; i <= n; ++i) scanf( %d%d , &a[i].val, &a[i].c);     for (int i = 1; i <= m; ++i) scanf( %d%d , &b[i].val, &b[i].c);     for (int i = 1; i <= p; ++i) scanf( %d%d%d , &c[i].x, &c[i].y, &c[i].z);     sort(a + 1, a + n + 1);     sort(b + 1, b + m + 1);     sort(c + 1, c + p + 1);     T.init();     for (int i = 1, R = 0; i <= n; ++i) {       while (R < p && c[R + 1].x < a[i].val) {         ++R;         int l = 1, r = m;         while (l != r) {           int mid = l + r >> 1;           if (b[mid].val > c[R].y)             r = mid;           else             l = mid + 1;         }         if (b[l].val > c[R].y) {           T.add(1, 1, m, l, m, c[R].z);         }       }       ans = max(ans, -a[i].c + T.mx[1]);     }     printf( %lld n , ans);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, k, s;     while (cin >> n >> k >> s) {       long long temp = (s / k);       long long rem = s % k;       temp++;       if (((n - 1) * k < s || (k > s))) {         cout <<  NO  << endl;         return 0;       }       cout <<  YES  << endl;       long long ans = 1;       int flag = 0;       for (int i = 1; i <= k; i++) {         if (flag == 0 && rem == 0) {           flag = 1;           temp--;         } else           rem--;         if (ans + temp <= n) {           ans += temp;           cout << ans <<    ;         } else {           ans -= temp;           cout << ans <<    ;         }       }       cout << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int t;   long long a, b, c, d;   long long solve(long long x) {     long long times = x / d + 1;     long long sum = (x / d + 1) * a;     long long finished;     if (x < c) {       finished = 0;     } else {       finished = (x - c) / d + 1;     }     long long left = times - finished;     long long a1 = x - (x / d) * d;     sum -= left * a1 * b + left * (left - 1) / 2 * d * b;     sum -= finished * b * c;     return sum;   }   int main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     cin >> t;     while (t--) {       cin >> a >> b >> c >> d;       if (d >= c) {         if (a > b * c) {           cout << -1 << endl;         } else {           cout << a << endl;         }       } else {         if (a > b * c) {           cout << -1 << endl;         } else {           long long l = 0, r = 1e6 / d;           while (l < r - 5) {             long long ml = (l + r) / 2;             long long mr = (ml + r) / 2;             if (solve(ml * d) <= solve(mr * d)) {               l = ml;             } else {               r = mr;             }           }           long long mx = 0;           for (long long i = l; i <= r; i++) {             mx = max(mx, solve(i * d));           }           cout << mx << endl;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   #pragma comment(linker,  /STACK:1024000000,1024000000 )   const double pi = 2.0 * asin(1.0), eps = 1e-12;   const int maxn = 2100, maxm = 1100000, inf = 0x3f3f3f3f;   char ch[maxn][maxn];   int ans[maxn];   int main() {     int n, m, i, j, l, x;     while (scanf( %d%d%d , &n, &m, &l) == 3) {       memset(ans, 0, sizeof(ans));       for (i = 0; i < n; i++) {         scanf( %s , ch[i]);         for (j = 0; j < m; j++) {           if (ch[i][j] ==  U ) {             if (i % 2 == 0) ans[j]++;           } else if (ch[i][j] ==  L ) {             x = j - i;             if (x >= 0) ans[x]++;           } else if (ch[i][j] ==  R ) {             x = j + i;             if (x < m) ans[x]++;           }         }       }       for (i = 0; i < m; i++) {         if (i != 0) printf(   );         printf( %d , ans[i]);       }       printf(  n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 7;   vector<int> cur;   void split(int x, int p) {     if (p == 1) {       cout << x <<    ;       return;     }     cout << x - 1 <<    ;     split(x - 1, p - 1);   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     ;     long long n, k;     cin >> n >> k;     string s =   ;     while (n > 0) {       s += (char)((n % 2) +  0 );       n /= 2;     }     for (int i = ((int)s.size() - 62); i < (int)s.size(); i++) {       long long cnt = 0;       for (int j = 0; j <= i; j++) {         cnt += (s[j] ==  1 );       }       bool ok = true;       for (long long j = max(i + 1, 0); j < s.size(); j++) {         cnt += (1ll << (j - i)) * (s[j] ==  1 );         if (cnt > k) {           ok = false;           break;         }       }       if (cnt > k) {         ok = false;         continue;       }       if (!ok) continue;       cout <<  Yes  << endl;       cur.clear();       for (int j = 0; j <= i; j++) {         if (s[j] ==  1 ) cur.push_back(j);       }       for (int j = max(i + 1, 0); j < s.size(); j++) {         if (s[j] ==  0 ) continue;         for (long long t = 0; t < (1ll << (j - i)); t++) {           cur.push_back(i);         }       }       for (int j = cur.size() - 1; j > 0; j--) {         cout << cur[j] <<    ;       }       split(cur[0], k - cnt + 1);       cout << endl;       return 0;     }     cout <<  No  << endl;   }


#include <bits/stdc++.h>   using std::cin;   using std::cout;   using std::endl;   using std::sort;   using std::string;   using std::swap;   int main() {     int times = INT_MAX;     int a[6];     while (times-- && ~scanf( %d , &a[0])) {       for (int i = 1; i < 6; ++i) scanf( %d , a + i);       printf( %d n , (a[0] + a[1] + a[2]) * (a[0] + a[1] + a[2]) - a[0] * a[0] -                          a[2] * a[2] - a[4] * a[4]);     };     return 0;   };


#include <bits/stdc++.h>   const double inf = 1e20;   using namespace std;   int n, m, i, j, f;   char a[55][55];   int vis[55][55];   int dx[4] = {1, 0, -1, 0};   int dy[4] = {0, 1, 0, -1};   void dfs(int x, int y, int oldx, int oldy) {     if (x == i && y == j && vis[i][j]) {       f = 1;       return;     }     for (int d = 0; d < 4 && !f; d++) {       int xx = x + dx[d], yy = y + dy[d];       if (a[xx][yy] == a[i][j] && xx >= 0 && yy >= 0 && xx < n && yy < m &&           !vis[xx][yy] && (oldx != xx || oldy != yy))         vis[xx][yy] = 1, dfs(xx, yy, x, y);     }   }   int main() {     cin >> n >> m;     for (i = 0; i < n; i++) cin >> a[i];     for (i = 0; i < n; i++)       for (j = 0; j < m && !f; j++) {         memset(vis, 0, sizeof(vis));         dfs(i, j, -1, -1);       }     if (f)       cout <<  Yes ;     else       cout <<  No ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int a[n], x = 0;     for (int i = 0; i < n; i++) {       cin >> a[i];       if (a[i] == 1) {         x++;       }     }     if (x == n) {       cout << n - 1 <<   n ;     } else {       int p = 0, m = 0;       for (int i = 0; i < n; i++) {         m = 0;         for (int j = i; j < n; j++) {           if (a[j] == 0) {             m++;           } else {             m--;           }           p = max(m, p);         }       }       cout << x + p <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int n;   string sherlock, moriarty;   int algos(bool upper) {     int res = 0;     multiset<int> S;     for (int i = 0; i < n; ++i) S.insert((int)moriarty[i]);     for (int i = 0; i < n; ++i) {       multiset<int>::iterator it;       if (upper)         it = S.upper_bound((int)sherlock[i]);       else         it = S.lower_bound((int)sherlock[i]);       if (it == S.end()) continue;       res++;       S.erase(it);     }     return res;   }   int main() {     cin >> n;     cin >> sherlock >> moriarty;     cout << n - algos(0) << endl << algos(1);   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 100005;   int n;   int firzero = -1;   int a[MAX];   int main() {     scanf( %d , &n);     for (int i = 0; i < n; ++i) {       scanf( %d , &a[i]);       if (!a[i] && firzero == -1) firzero = i;     }     if (a[n - 1])       printf( NO n );     else {       if (n == 1) {         printf( YES n0 n );       } else if (a[n - 2]) {         printf( YES n );         for (int i = 0; i < n; ++i) {           if (i)             printf( ->%d , a[i]);           else             printf( %d , a[i]);         }         printf(  n );       } else if (firzero != n - 2 && firzero != -1) {         printf( YES n );         for (int i = 0; i < firzero; ++i) {           printf( %d-> , a[i]);         }         printf( (0->( );         for (int i = firzero + 1; i < n - 1; ++i) {           if (i == firzero + 1)             printf( %d , a[i]);           else             printf( ->%d , a[i]);         }         printf( ))->0 n );       } else {         printf( NO n );       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int v[100005], goal[100005], parent[100005];   bool used[100005];   int n;   vector<int> A[100005], leaves, sol;   void dfs(int node, int current_xor, int other_xor) {     if (used[node]) return;     used[node] = 1;     if ((v[node] ^ current_xor) != goal[node]) {       sol.push_back(node);       current_xor ^= 1;     }     for (int i = 0; i < A[node].size(); i++) {       dfs(A[node][i], other_xor, current_xor);     }   }   int main() {     scanf( %d , &n);     for (int i = 1, x, y; i < n; i++) {       scanf( %d %d , &x, &y);       A[x].push_back(y);       A[y].push_back(x);     }     for (int i = 1; i <= n; i++) scanf( %d , &v[i]);     for (int i = 1; i <= n; i++) scanf( %d , &goal[i]);     dfs(1, 0, 0);     printf( %d n , sol.size());     for (int i = 0; i < sol.size(); i++) {       printf( %d n , sol[i]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int NN = 150000 + 10;   int N, M, H;   int b[NN], a[NN];   int _max[NN << 2];   int add[NN << 2];   void up(int idx) { _max[idx] = max(_max[idx << 1], _max[idx << 1 | 1]); }   void build(int l, int r, int idx) {     _max[idx] = -100000000;     add[idx] = 0;     if (l == r) {       _max[idx] = -M - 1 + l;       return;     }     int mid = (l + r) >> 1;     build(l, mid, idx << 1);     build(mid + 1, r, idx << 1 | 1);     up(idx);   }   void down(int idx) {     int ls = idx << 1, rs = idx << 1 | 1;     if (add[idx]) {       add[ls] += add[idx];       add[rs] += add[idx];       _max[ls] += add[idx];       _max[rs] += add[idx];       add[idx] = 0;     }   }   void update(int idx, int l, int r, int a, int b, int val) {     if (l == a && r == b) {       _max[idx] += val;       add[idx] += val;       return;     }     down(idx);     int mid = (l + r) >> 1;     if (b <= mid)       update(idx << 1, l, mid, a, b, val);     else if (a > mid)       update(idx << 1 | 1, mid + 1, r, a, b, val);     else {       update(idx << 1, l, mid, a, mid, val);       update(idx << 1 | 1, mid + 1, r, mid + 1, b, val);     }     up(idx);   }   int main() {     while (cin >> N >> M >> H) {       for (int i = 1; i < (int)(M + 1); ++i) cin >> b[i];       sort(b + 1, b + 1 + M);       for (int i = 1; i < (int)(N + 1); ++i) {         cin >> a[i];         a[i] = H - a[i];         a[i] = lower_bound(b + 1, b + 1 + M, a[i]) - b;       }       build(1, M + 1, 1);       int ans = 0;       for (int i = 1; i < (int)(N + 1); ++i) {         update(1, 1, M + 1, 1, a[i], 1);         if (i > M) {           update(1, 1, M + 1, 1, a[i - M], -1);         }         if (i >= M) {           ans += (_max[1] <= 0);         }       }       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     long long N, K;     string X;     cin >> N >> K;     cin >> X;     string foo = X;     for (long long i = 0; i + K < foo.size(); i++) {       foo[i + K] = foo[i];     }     if (foo >= X) {       cout << foo.size() << endl;       cout << foo << endl;       return;     }     string bar = foo.substr(0, K);     bool all_nine = true;     for (auto it : bar)       if (it !=  9 ) {         all_nine = false;         break;       }     if (all_nine) {       cout << N + 1 << endl;       for (long long i = 0; i < (N + 1); i++) {         if (i % K == 0)           cout << 1;         else           cout << 0;       }       cout << endl;       return;     }     for (long long i = 0; i < (bar.size()); i++) {       if (bar[bar.size() - i - 1] ==  9 ) {         bar[bar.size() - i - 1] =  0 ;       } else {         bar[bar.size() - i - 1] += 1;         break;       }     }     cout << N << endl;     ;     for (long long i = 0; i < (N); i++) cout << bar[i % K];     cout << endl;   }   int main(void) {     cin.tie(0);     ios::sync_with_stdio(false);     cout.precision(12);     cout << fixed;     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, x, mx = 0, ans;     cin >> n;     while (n--) {       cin >> x;       if (x > mx) mx = x;     }     ans = mx ^ x;     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   const int INF = 0x3f3f3f3f;   const long long int INFLL = 0x3f3f3f3f3f3f3f3fll;   long long int getint() {     long long int ret = 0;     bool f = 0;     char c;     while ((c = getchar()) <  0  || c >  9 )       if (c ==  - ) f ^= 1;     while (c >=  0  && c <=  9 ) {       ret = ret * 10 + c -  0 ;       c = getchar();     }     return f ? -ret : ret;   }   using namespace std;   const int MAXN = 200000;   int a[MAXN + 10], f[MAXN + 10][20], w[MAXN + 10], lg2[MAXN + 10];   int nxt[MAXN + 10][20], far[MAXN + 10][20];   int query(int l, int r) {     int t = lg2[r - l + 1];     int ret = f[r - (1 << t) + 1][t];     if (w[f[l][t]] > w[ret]) ret = f[l][t];     return ret;   }   int main() {     int n = getint(), N = 2 * n;     for (int i = n; i >= 1; --i) a[i + n] = a[i] = getint();     lg2[0] = -1;     for (int i = 1; i <= N; ++i) {       w[i] = i + a[i];       f[i][0] = i;       lg2[i] = lg2[i >> 1] + 1;     }     for (int j = 1; j <= lg2[N]; ++j)       for (int i = 1; i + (1 << j) - 1 <= N; ++i) {         f[i][j] = f[i + (1 << (j - 1))][j - 1];         if (w[f[i][j - 1]] > w[f[i][j]]) f[i][j] = f[i][j - 1];       }     for (int i = 1; i < N; ++i) {       nxt[i][0] = query(i + 1, min(N, i + a[i]));       far[i][0] = w[i];     }     far[N][0] = nxt[N][0] = N;     for (int j = 1; j <= lg2[N]; ++j)       for (int i = 1; i <= N; ++i) {         nxt[i][j] = nxt[nxt[i][j - 1]][j - 1];         far[i][j] = far[nxt[i][j - 1]][j - 1];       }     long long int output = 0;     for (int i = 1; i <= n; ++i) {       int ans = 0, u = i;       for (int j = lg2[N]; j >= 0; --j)         if (far[u][j] < i + n - 1) ans += 1 << j, u = nxt[u][j];       output += ans + 1;     }     printf( %I64d n , output);     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   int res[1111];   bool sol(int d) {     int g = 1, e;     for (e = 2; e <= sqrt(d); e++) {       if (d % e == 0) {         while (d % e == 0) d /= e;         if (d != 1) {           g = 0;         }         break;       }     }     return g;   }   int main() {     int a, b, c, d, e, f, g, h;     scanf( %d , &a);     if (a < 2) {       printf( 0 n );       return 0;     }     for (d = 2, g = 0; d <= a; d++) {       if (sol(d)) {         res[g++] = d;       }     }     printf( %d n , g);     for (d = 0; d < g; d++) printf( %d%c , res[d], d != g - 1 ?     :   n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int gcd(int f, int s) {     if (s == 0)       return f;     else       return gcd(s, f % s);   }   int const N = 1000006;   long long const M = 1000 * 1000 * 1000 + 7;   long double const ep = .000000000000000001;   int arr[N];   int main() {     int n, m;     cin >> n >> m;     int mx = 0;     long long sum = 0;     for (int i = 0; i < n; i++) {       scanf( %d , arr + i);       sum += arr[i];       mx = max(arr[i], mx);     }     sort(arr, arr + n);     int curr = 1;     long long ans = n;     for (int i = 0; i < n; i++) {       if (curr > mx) curr = mx;       if (arr[i] >= curr) curr++;     }     if (curr > mx) {       printf( %lld n , sum - ans);     } else {       printf( %lld n , sum - (mx - (curr - 1)) - ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int used[550][550];   int main() {     int x, y;     int x0, y0;     cin >> x >> y;     cin >> x0 >> y0;     string s;     cin >> s;     int cnt = 0;     cout << 1 <<    ;     int last = x * y - 1;     for (int i = 0; i < s.size(); i++) {       used[x0][y0] = 1;       bool flag = false;       if (s[i] ==  D ) {         if (x0 < x) {           if (!used[x0 + 1][y0]) flag = true;           x0++;         }       }       if (s[i] ==  U ) {         if (x0 > 1) {           if (!used[x0 - 1][y0]) flag = true;           x0--;         }       }       if (s[i] ==  L ) {         if (y0 > 1) {           if (!used[x0][y0 - 1]) flag = true;           y0--;         }       }       if (s[i] ==  R ) {         if (y0 < y) {           if (!used[x0][y0 + 1]) flag = true;           y0++;         }       }       if (i < s.size() - 1) {         if (flag) {           cnt++;           last--;         }         cout << int(flag) <<    ;       }     }     cout << last << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 200010;   const int oo = 1e9;   int xm, ym, zm, n, m, k, xmn, xmx, ymn, ymx, zmn, zmx;   struct point {     int x, y, z, idx;     bool operator<(const point &rhs) const { return x < rhs.x; }     void print() { cout << x <<     << y <<     << z << endl; }   };   point pnt[N], q[N], org[N];   set<int> seg[4 * N];   vector<int> f[2];   int l, r, x, y, at, val, ans[N];   void update(int n, int s, int e) {     if (s > at || e < at) return;     seg[n].insert(val);     if (s == e) return;     update(2 * n, s, (s + e) / 2);     update(2 * n + 1, (s + e) / 2 + 1, e);   }   bool get(int n, int s, int e) {     if (s > r || e < l) return 0;     if (s >= l && e <= r) {       return seg[n].lower_bound(x) != seg[n].end() && *seg[n].lower_bound(x) <= y;     }     return get(2 * n, s, (s + e) / 2) || get(2 * n + 1, (s + e) / 2 + 1, e);   }   void clear() {     for (int i = 0; i < 4 * N; ++i) seg[i].clear();   }   pair<point, point> nw(int a, int b, int c) {     point f1, f2;     f1.x = xmn, f1.y = ymn, f1.z = zmn;     f2.x = xmx, f2.y = ymx, f2.z = zmx;     f1.x = min(f1.x, a), f2.x = max(f2.x, a);     f1.y = min(f1.y, b), f2.y = max(f2.y, b);     f1.z = min(f1.z, c), f2.z = max(f2.z, c);     return make_pair(f1, f2);   }   bool inside(point c) {     return c.x >= xmn && c.x <= xmx && c.y >= ymn && c.y <= ymx && c.z >= zmn &&            c.z <= zmx;   }   int main() {     cin >> xm >> ym >> zm >> n >> m >> k;     for (int a, b, c, i = 0; i < n; ++i) {       scanf( %d%d%d , &a, &b, &c);       if (!i) xmn = xmx = a, ymn = ymx = b, zmn = zmx = c;       xmn = min(xmn, a), xmx = max(xmx, a);       ymn = min(ymn, b), ymx = max(ymx, b);       zmn = min(zmn, c), zmx = max(zmx, c);     }     for (int i = 0; i < m; ++i) {       scanf( %d%d%d , &pnt[i].x, &pnt[i].y, &pnt[i].z);       if (inside(pnt[i])) {         puts( INCORRECT );         return 0;       }     }     puts( CORRECT );     sort(pnt, pnt + m);     for (int i = 0; i < k; ++i) {       scanf( %d%d%d , &q[i].x, &q[i].y, &q[i].z);       q[i].idx = i;       org[i] = q[i];     }     sort(q, q + k);     for (int i = 0; i < k; ++i) {       if (q[i].x < xmn) {         f[0].push_back(i);       } else {         f[1].push_back(i);       }     }     int idx = 0;     while (idx < m && pnt[idx].x < xmn) ++idx;     for (int i = 0; i < f[1].size(); ++i) {       int cur = f[1][i];       pair<point, point> w = nw(q[cur].x, q[cur].y, q[cur].z);       l = w.first.y, r = w.second.y;       x = w.first.z, y = w.second.z;       while (idx < m && pnt[idx].x <= w.second.x) {         at = pnt[idx].y;         val = pnt[idx].z;         update(1, 1, ym);         idx++;       }       bool res = get(1, 1, ym);       if (res) {         ans[q[cur].idx] = 1;       } else {         ans[q[cur].idx] = 2;         ;       }     }     clear();     idx = m - 1;     while (idx >= 0 && pnt[idx].x > xmx) --idx;     for (int i = f[0].size() - 1; i >= 0; --i) {       int cur = f[0][i];       pair<point, point> w = nw(q[cur].x, q[cur].y, q[cur].z);       l = w.first.y, r = w.second.y;       x = w.first.z, y = w.second.z;       while (idx >= 0 && pnt[idx].x >= w.first.x) {         at = pnt[idx].y;         val = pnt[idx].z;         update(1, 1, ym);         idx--;       }       bool res = get(1, 1, ym);       if (res) {         ans[q[cur].idx] = 1;       } else {         ans[q[cur].idx] = 2;         ;       }     }     for (int i = 0; i < k; ++i) {       if (inside(org[i])) {         puts( OPEN );       } else {         assert(ans[i] != 0);         if (ans[i] == 1) {           puts( CLOSED );         } else {           puts( UNKNOWN );         }       }     }     return 0;   }


#include <bits/stdc++.h>   const long long MAX_N = 2e5 + 100;   const long long MOD = 1e9 + 7;   using namespace std;   long long rm[MAX_N][20];   long long a[MAX_N];   map<int, int> last;   long long ans;   const long long c = (1ll << 50) - 1;   long long ask(long long l, long long r) {     long long len = r - l + 1;     int lg = (int)log2(len);     long long s = r - (1 << lg) + 1;     return (rm[l][lg] | rm[s][lg]);   }   bool check(long long i, long long j) {     j ^= c;     if (j & i) return true;     return false;   }   int main() {     long long n;     cin >> n;     ans = n * (n + 1) / 2;     for (int i = 1; i <= n; ++i) cin >> a[i], last[a[i]] = 0;     for (int i = 1; i <= n; ++i) rm[i][0] = a[i];     for (int i = 1; i < 20; ++i) {       for (int j = 1; j <= n - (1 << i) + 1; ++j) {         rm[j][i] = rm[j][i - 1] | rm[j + (1 << (i - 1))][i - 1];       }     }     for (int i = 1; i <= n; ++i) {       long long l1 = i;       long long r1 = last[a[i]] + 1;       long long l2 = i;       long long r2 = n;       if (!check(ask(r1, i), a[i]))         l1 = r1;       else {         while (l1 - r1 > 1) {           long long mid = (l1 + r1) / 2;           if (!check(ask(mid, i), a[i]))             l1 = mid;           else             r1 = mid;         }       }       if (!check(ask(i, n), a[i]))         l2 = n;       else {         while (r2 - l2 > 1) {           long long mid = (l2 + r2) / 2;           if (!check(ask(i, mid), a[i]))             l2 = mid;           else             r2 = mid;         }       }       ans -= (i - l1 + 1) * (l2 - i + 1);       last[a[i]] = i;     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char A[3][3], B[3][3];   int main() {     scanf( %s , A[0]);     scanf( %s , A[1]);     scanf( %s , B[0]);     scanf( %s , B[1]);     string a = A[0], b = B[0];     a += A[1][1];     a += A[1][0];     b += B[1][1];     b += B[1][0];     for (int i = 0; i < a.length(); i++)       if (a[i] ==  X ) a.erase(a.begin() + i);     for (int i = 0; i < b.length(); i++)       if (b[i] ==  X ) b.erase(b.begin() + i);     for (int i = 0; i < 3; i++) {       a += a[0];       a.erase(a.begin());       if (a == b) {         puts( YES );         return 0;       }     }     puts( NO );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   const long double PI = 3.141592653589793238462643383279502884197;   long long fac[1] = {1}, inv[1] = {1};   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   long long mp(long long a, long long b) {     long long ret = 1;     while (b) {       if (b & 1) ret = ret * a % MOD;       a = a * a % MOD;       b >>= 1;     }     return ret;   }   long long cmb(long long r, long long c) {     return (c > r || c < 0) ? 0 : fac[r] * inv[c] % MOD * inv[r - c] % MOD;   }   pair<int, int> vec[6000];   int cnt[2][2];   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d %d , &vec[i].first, &vec[i].second);       vec[i].first /= 2;       vec[i].second /= 2;       vec[i].first %= 2;       vec[i].second %= 2;       cnt[vec[i].first][vec[i].second]++;     }     long long ans = 0;     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         if (i == j) continue;         int g = 0;         if (vec[i].first != vec[j].first) g = 1;         if (vec[i].second != vec[j].second) g = 1;         for (int q = 0; q < 2; q++) {           for (int w = 0; w < 2; w++) {             int a = 0, b = 0;             if (q != vec[i].first || w != vec[i].second) a = 1;             if (q != vec[j].first || w != vec[j].second) b = 1;             if ((a ^ b ^ g) == 0) ans += cnt[q][w] - !a - !b;           }         }       }     }     printf( %lld n , ans / 6);   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1000100;   struct Vertex {     long long cnt;     long long sum;     Vertex() { cnt = sum = 0; }   };   struct SegmentTree {     Vertex tree[4 * MAXN];     SegmentTree() = default;     void calc(int v) {       int lv = 2 * v + 1;       int rv = 2 * v + 2;       tree[v].cnt = tree[lv].cnt + tree[rv].cnt;       tree[v].sum = tree[lv].sum + tree[rv].sum;     }     void modify(int v, int l, int r, int pos, long long c) {       if (l == r) {         tree[v].cnt += c;         tree[v].sum += c * (long long)pos;         return;       }       int med = (l + r) / 2;       if (pos <= med) {         modify(2 * v + 1, l, med, pos, c);       } else {         modify(2 * v + 2, med + 1, r, pos, c);       }       calc(v);     }     long long rec(int v, int l, int r, long long need) {       if (tree[v].cnt <= need) {         return tree[v].sum;       }       if (l == r) {         return (long long)l * (long long)need;       }       int lv = 2 * v + 1;       int rv = 2 * v + 2;       int med = (l + r) / 2;       if (tree[lv].cnt >= need) {         return rec(lv, l, med, need);       } else {         long long rest = need - tree[lv].cnt;         long long L = rec(lv, l, med, need);         long long R = rec(rv, med + 1, r, rest);         return L + R;       }     }   };   vector<pair<int, int>> events[MAXN];   SegmentTree tr;   int main() {     int n, k, m;     scanf( %d%d%d , &n, &k, &m);     for (int i = 1; i <= m; i++) {       int l, r, c, p;       scanf( %d%d%d%d , &l, &r, &c, &p);       events[l].emplace_back(p, c);       events[r + 1].emplace_back(p, -c);     }     long long ans = 0;     for (int i = 1; i <= n; i++) {       for (auto& ev : events[i]) {         tr.modify(0, 1, 1000000, ev.first, ev.second);       }       long long result = tr.rec(0, 1, 1000000, k);       ans += result;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool condition(int year) {     int year_arr[4];     int boo;     for (int i = 3; i >= 0; i--) {       year_arr[i] = year % 10;       year = year / 10;     }     if (year_arr[0] == year_arr[1] || year_arr[0] == year_arr[2] ||         year_arr[0] == year_arr[3] || year_arr[1] == year_arr[2] ||         year_arr[1] == year_arr[3] || year_arr[2] == year_arr[3]) {       boo = false;     } else {       boo = true;     }     return boo;   }   int main() {     int prev_y, next_y;     cin >> prev_y;     next_y = prev_y + 1;     while (condition(next_y) == false) {       next_y += 1;     }     cout << next_y;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n;     cin >> n;     string s, p, r;     s =  1 ;     cin >> p;     s = s + p;     for (long long int i = 2; i < n - 1; i++) {       if (n % i == 0) {         p = s.substr(1, i);         s = s.substr(i + 1, n);         reverse(p.begin(), p.end());         s =  1  + p + s;       }     }     s = s.substr(1, n);     reverse(s.begin(), s.end());     cout << s << endl;   }


#include <bits/stdc++.h>   #pragma warning(disable : 4996)   using namespace std;   int n, m;   struct GUGAN {     int s, e;     int type;     int idx, x;     bool operator<(const GUGAN &p) const { return e < p.e; }     GUGAN() {}     GUGAN(int s, int e, int type, int idx, int x) {       this->s = s, this->e = e, this->type = type, this->idx = idx, this->x = x;     }   };   bool cmp(GUGAN p, GUGAN q) {     if (p.s != q.s) return p.s < q.s;     return p.type < q.type;   }   vector<GUGAN> v;   multiset<GUGAN> s;   int dab[200000];   int main() {     int i, j, k;     scanf( %d , &n);     for (i = 0; i < n; i++) {       int x, y;       scanf( %d%d , &x, &y);       v.push_back(GUGAN(x, y, 2, i, -1));     }     scanf( %d , &m);     for (i = 0; i < m; i++) {       int x, y, z;       scanf( %d%d%d , &x, &y, &z);       v.push_back(GUGAN(x, y, 1, i, z));     }     sort(v.begin(), v.end(), cmp);     for (auto e : v) {       if (e.type == 1)         s.insert(e);       else {         auto it = s.lower_bound(GUGAN(0, e.e, 0, 0, 0));         if (it == s.end()) return printf( NO ), 0;         GUGAN u = *it;         s.erase(it);         u.x--;         dab[e.idx] = u.idx;         if (u.x != 0) s.insert(u);       }     }     printf( YES n );     for (i = 0; i < n; i++) printf( %d  , dab[i] + 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int f[300010][2];   int dp[300010][2];   int Flag[300010];   int main() {     int n, k;     scanf( %d%d , &n, &k);     for (int i = 1; i <= n; i++) scanf( %d , &f[i][0]);     for (int i = 1; i <= n; i++) scanf( %d , &f[i][1]);     if (k == 1) {       for (int ii = 0; ii < 2; ii++) {         int r = ii, s = ii ^ 1;         for (int i = 1; i <= n; i++) {           int nr = f[i][r], ns = f[i][s];           int ss = nr + ns;           if (nr != ((ss + 1) / 2) || ns != (ss / 2)) {             Flag[ii] = 1;             break;           }           if (ss & 1) swap(r, s);         }       }       if (Flag[1] && Flag[0])         puts( NO );       else         puts( YES );       return 0;     }     dp[0][0] = dp[0][1] = 0;     for (int i = 1; i <= n; i++) {       dp[i][0] = dp[i][1] = 0x3f3f3f3f;       for (int v = 0; v < 2; v++) {         int u = v ^ 1;         int r = dp[i - 1][v];         if (r != 0x3f3f3f3f) {           int x = f[i][v], y = f[i][u];           if (x >= y) {             if (x <= (k - r + (long long)k * y))               dp[i][v] = min((long long)dp[i][v],                              max(1LL, x - (k - r) - (long long)k * (y - 1)));             if (x <= ((long long)k * (y - 1) + k - r))               dp[i][u] = min(dp[i][u], 1);           } else {             if (y <= ((long long)k * (x + 1)))               dp[i][u] = min((long long)dp[i][u], max(1LL, y - (long long)k * x));             if (y <= ((long long)k * x)) dp[i][v] = min(dp[i][v], 1);           }         }       }     }     if (dp[n][0] == 0x3f3f3f3f && dp[n][1] == 0x3f3f3f3f)       puts( NO );     else       puts( YES );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 601000;   struct SuffixArray {     int s[N], sa[N], rk[N], height[N], t[N], t2[N], c[N], n;     void clear() { n = 0; }     void build_sa(int m) {       int *x = t, *y = t2;       for (int i = 0; i < m; i++) c[i] = 0;       for (int i = 0; i < n; i++) c[x[i] = s[i]]++;       for (int i = 1; i < m; i++) c[i] += c[i - 1];       for (int i = n - 1; i >= 0; i--) sa[--c[x[i]]] = i;       for (int k = 1; k <= n; k <<= 1) {         int p = 0;         for (int i = n - k; i < n; i++) y[p++] = i;         for (int i = 0; i < n; i++)           if (sa[i] >= k) y[p++] = sa[i] - k;         for (int i = 0; i < m; i++) c[i] = 0;         for (int i = 0; i < n; i++) c[x[y[i]]]++;         for (int i = 1; i < m; i++) c[i] += c[i - 1];         for (int i = n - 1; i >= 0; i--) sa[--c[x[y[i]]]] = y[i];         swap(x, y);         p = 1;         x[sa[0]] = 0;         for (int i = 1; i < n; i++)           x[sa[i]] = y[sa[i - 1]] == y[sa[i]] && y[sa[i - 1] + k] == y[sa[i] + k]                          ? p - 1                          : p++;         if (p >= n) break;         m = p;       }     }     void build_height() {       for (int i = 0; i < n; i++) rk[sa[i]] = i;       for (int i = 0, k = 0; i < n - 1; i++) {         if (k) k--;         int j = sa[rk[i] - 1];         while (s[i + k] == s[j + k]) k++;         height[rk[i]] = k;       }     }     void add(int ch) { s[n++] = ch; }   };   SuffixArray sa;   int Log[N];   int lcp[N][20];   int callcp(int a, int b) {     int tt = b - a + 1, len = Log[tt];     return min(lcp[a][len], lcp[a + tt - (1 << len)][len]);   }   int callo(int x, int len) {     int l = 0, r = x;     while (l + 1 < r) {       int mid = (l + r) >> 1;       if (callcp(mid + 1, x) >= len)         r = mid;       else         l = mid;     }     return r;   }   int calup(int x, int len) {     int l = x, r = sa.n;     while (l + 1 < r) {       int mid = (l + r) >> 1;       if (callcp(x + 1, mid) >= len)         l = mid;       else         r = mid;     }     return l;   }   char s[N];   int val[N];   int l[20], r[20], vx[20], vy[20], n;   int ban;   long long ans;   int sum[20];   int dp[20][N];   bool cl(int loc, int len) {     int x = callo(loc, len);     int y = calup(loc, len);     for (int i = 1; i <= n; i++) {       sum[i] = dp[i][y] - dp[i][x - 1];       if (sum[i] > vy[i]) return false;     }     return true;   }   bool cr(int loc, int len) {     int x = callo(loc, len);     int y = calup(loc, len);     for (int i = 1; i <= n; i++) {       sum[i] = dp[i][y] - dp[i][x - 1];       if (sum[i] < vx[i]) return false;     }     return true;   }   int sl;   void update(int loc) {     int L = 0, R = sl - sa.sa[loc];     while (L + 1 < R) {       int mid = (L + R) >> 1;       if (cl(loc, mid))         R = mid;       else         L = mid;     }     if (!cl(loc, R)) return;     int aa = R;     L = 1, R = sl - sa.sa[loc] + 1;     while (L + 1 < R) {       int mid = (L + R) >> 1;       if (cr(loc, mid))         L = mid;       else         R = mid;     }     if (!cr(loc, L)) return;     int bb = L;     aa = max(aa, ban);     if (aa > bb) return;     ans += (bb - aa + 1);   }   int main() {     memset(val, -1, sizeof(val));     Log[0] = -1;     for (int i = 1; i < N; i++) {       Log[i] = Log[i >> 1] + 1;     }     scanf( %s , s);     l[0] = 0;     sl = strlen(s);     for (int i = 0; s[i]; i++) {       val[sa.n] = 0;       sa.add(s[i] -  a  + 1);     }     r[0] = sa.n;     int add = 27;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       sa.add(add++);       l[i] = sa.n;       scanf( %s%d%d , s, &vx[i], &vy[i]);       for (int j = 0; s[j]; j++) {         val[sa.n] = i;         sa.add(s[j] -  a  + 1);       }       r[i] = sa.n;     }     sa.add(0);     sa.build_sa(add);     sa.build_height();     for (int i = 1; i < sa.n; i++) {       lcp[i][0] = sa.height[i];     }     for (int j = 1; j < 20; j++) {       for (int i = 1; i + (1 << j) <= sa.n; i++) {         lcp[i][j] = min(lcp[i][j - 1], lcp[i + (1 << (j - 1))][j - 1]);       }     }     for (int i = 1; i < sa.n; i++) {       for (int j = 1; j <= n; j++) {         dp[j][i] = dp[j][i - 1];       }       if (~val[sa.sa[i]]) dp[val[sa.sa[i]]][i]++;     }     int last = 0;     for (int i = 1; i < sa.n; i++) {       if (sa.sa[i] >= l[0] && sa.sa[i] < r[0]) {         if (last) {           ban = callcp(last + 1, i) + 1;         }         last = i;         update(i);       }     }     printf( %I64d n , ans);     return 0;   }


#include <bits/stdc++.h>   using ::std::cin;   using ::std::cout;   using ::std::string;   using ::std::vector;   int binpow(int a, int n) {     if (n == 0) return 1;     if (n % 2 == 0) {       int b = binpow(a, n / 2);       return b * b;     } else       return binpow(a, n - 1) * a;   }   int main() {     int n, l, r;     cin >> n >> l >> r;     cout << binpow(2, l) + n - l - 1 <<              << binpow(2, r) - 1 + (n - r) * binpow(2, r - 1);   }


#include <bits/stdc++.h>   using namespace std;   double PI = acos(-1);   struct point {     long long x, y;     point(long long x = 0, long long y = 0) {       this->x = x;       this->y = y;     }     bool operator==(point& p) { return p.x == x && p.y == y; }   } a[100010], origin;   struct vecto {     long long x, y;     vecto(long long x = 0, long long y = 0) {       this->x = x;       this->y = y;     }   };   vecto toVec(point a, point b) { return vecto(b.x - a.x, b.y - a.y); }   long long crossProduct(vecto a, vecto b) { return a.x * b.y - a.y * b.x; }   long long dotProduct(vecto a, vecto b) { return a.x * b.x + a.y * b.y; }   long long dist(point a, point b) {     return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y);   }   int main() {     ios::sync_with_stdio(0);     int n;     cin >> n;     for (int i = (0); i <= (n - 1); i++) cin >> a[i].x >> a[i].y;     double res = 1e15;     for (int i = (0); i <= (n - 1); i++) {       int prev = (i - 1 + n) % n;       int next = (i + 1) % n;       if (dotProduct(toVec(a[prev], a[next]), toVec(a[next], a[i])) >= 0)         res = min(res, sqrt(dist(a[i], a[next])));       else if (dotProduct(toVec(a[next], a[prev]), toVec(a[prev], a[i])) >= 0)         res = min(res, sqrt(dist(a[i], a[prev])));       else         res =             min(res, crossProduct(toVec(a[prev], a[next]), toVec(a[prev], a[i])) /                          sqrt(dist(a[prev], a[next])));     }     cout << fixed << setprecision(9) << res / 2;     return 0;   }