#include <bits/stdc++.h>   using namespace std;   int const N = 202020;   long long a[N];   long long l[N], r[N];   int main() {     int n;     long long k;     scanf( %d%I64d , &n, &k);     for (int i = 1; i <= (n); ++i) scanf( %I64d , &a[i]);     for (int i = 1; i <= (n); ++i) l[i] = a[i - 1] == 1 ? 1 + l[i - 1] : 0;     for (int i = n; i >= 1; --i) r[i] = a[i + 1] == 1 ? 1 + r[i + 1] : 0;     long long mx = 0x3FFFFFFFFFFFFFFFLL;     long long ans = 0;     if (k == 1) {       for (int i = 1; i <= (n); ++i)         if (a[i] == 1) ++ans;     }     for (int i = 1; i <= (n); ++i)       if (a[i] != 1) {         long long ts = 0, tr = 1;         for (int j = i; j <= n; ++j) {           if (a[j] == 1) {             ts += r[j - 1];             j += r[j - 1];             j -= 1;             continue;           }           if (tr > mx / a[j]) break;           ts += a[j];           tr *= a[j];           if (tr % k == 0) {             long long need = tr / k - ts;             if (need >= 0) {               long long lc = min(need, l[i]), rc = min(need, r[j]);               long long cnt = lc + rc - need + 1;               cnt = max(cnt, 0LL);               ans += cnt;             }           }         }       }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     scanf( %d , &n);     int s = 0, ans = 0;     for (int i = 1;; i++) {       for (int j = 1; j <= i; j++) s += j;       if (s > n) break;       ans++;     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void zanj0() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }   void solve() {     int n, m;     cin >> n >> m;     int S = int(0.45 * sqrt(n)) + 1;     vector<int> v(n), rev_v(n), s_jump(n);     for (int i = 0; i < n; i++) {       cin >> v[i];       v[i]--;     }     for (int i = 0; i < n; i++) {       rev_v[v[i]] = i;     }     auto compute_s_jump = [&](int index) -> int {       int x = index;       for (int i = 0; i < S; i++) {         x = v[x];       }       return s_jump[index] = x;     };     for (int i = 0; i < n; i++) compute_s_jump(i);     while (m--) {       int type;       cin >> type;       if (type == 2) {         int x, k;         cin >> x >> k;         x--;         while (S <= k) {           k -= S;           x = s_jump[x];         }         while (k--) {           x = v[x];         }         cout << x + 1 <<   n ;       } else {         int x, y;         cin >> x >> y;         x--;         y--;         swap(rev_v[v[x]], rev_v[v[y]]);         swap(v[x], v[y]);         int sx = compute_s_jump(x);         int sy = compute_s_jump(y);         for (int i = 0; i < S; i++) {           s_jump[x] = sx;           s_jump[y] = sy;           x = rev_v[x];           y = rev_v[y];           sx = rev_v[sx];           sy = rev_v[sy];         }       }     }   }   int32_t main() {     zanj0();     solve();     cerr <<  Time :   << 1000 * (long double)clock() / (long double)CLOCKS_PER_SEC          <<  ms n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long int N = 1e6;   ;   int n, m, a, l, r, num;   int arr[2];   int main() {     scanf( %d%d , &n, &m);     while (n--) {       scanf( %d , &a);       if (a == -1)         ++arr[0];       else         ++arr[1];     }     while (m--) {       scanf( %d%d , &l, &r);       if (l == r) {         printf( 0 n );         continue;       }       num = r - l + 1;       if (num % 2 != 0)         printf( 0 n );       else {         if (num / 2 > arr[0] || num / 2 > arr[1])           printf( 0 n );         else           printf( 1 n );       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long Maxn = 1e5 + 7;   const long long Max = 1e3 + 7;   const long long Mod = 1e9 + 7;   const long long Inf = 1e9 + 7;   string s[Maxn], V[Maxn];   long long ans[5];   long long check(char t) {     if (t ==  u  || t ==  o  || t ==  a  || t ==  i  || t ==  e ) return true;     return false;   }   void f(long long a, long long b, long long c, long long d) {     if (V[a] == V[b] && V[c] == V[d])       ;     else       ans[1] = 0;     if (V[a] == V[c] && V[b] == V[d])       ;     else       ans[2] = 0;     if (V[a] == V[d] && V[c] == V[b])       ;     else       ans[3] = 0;     if (V[a] == V[b] && V[c] == V[d] && V[c] == V[b])       ;     else       ans[4] = 0;   }   void print(long long i) {     if (i == 1) cout <<  aabb  << endl;     if (i == 2) cout <<  abab  << endl;     if (i == 3) cout <<  abba  << endl;     if (i == 4) cout <<  aaaa  << endl;   }   int main() {     long long n, k;     cin >> n >> k;     for (long long i = 1; i <= 4 * n; i++) {       cin >> s[i];       long long K = k;       for (long long j = s[i].size() - 1; K && j >= 0; j--) {         V[i] += s[i][j];         if (check(s[i][j])) K--;       }       if (K) {         cout <<  NO  << endl;         return 0;       }     }     ans[1] = ans[2] = ans[3] = ans[4] = 1;     for (long long i = 1; i <= n; i++) {       long long st = (i - 1) * 4;       f(st + 1, st + 2, st + 3, st + 4);     }     for (long long i = 4; i >= 1; i--) {       if (ans[i]) {         print(i);         return 0;       }     }     cout <<  NO  << endl;     return 0;   }


#include <bits/stdc++.h>   #pragma gcc optimize( Ofast )   using namespace std;   using ll = long long;   const int N = 1e6 + 2;   int n, cnt, f[N], vis[N];   int qt, q[N];   vector<int> v;   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     cin >> n;     if (n & 1) return cout <<  -1 n , 0;     v.push_back(0);     for (int i = 0; i < n; ++i) {       int a;       cin >> a;       if (a > 0) {         if (f[a] || vis[a]) return cout <<  -1 n , 0;         ++f[a], ++cnt, vis[a] = 1, q[++qt] = a;       } else {         a = -a;         if (!f[a]) return cout <<  -1 n , 0;         --f[a], --cnt;         if (!cnt) {           v.push_back(i + 1);           while (qt) vis[q[qt--]] = 0;         }       }     }     if (cnt) return cout <<  -1 n , 0;     cout << v.size() - 1 <<   n ;     for (int i = 1; i < v.size(); ++i)       cout << v[i] - v[i - 1] <<    n [i + 1 == v.size()];   }


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


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   const int N = (int)2e5 + 7;   const int inf = (int)1e9 + 7;   const int mod = (int)1e9 + 7;   const long long linf = (long long)1e18 + 7;   const int dx[] = {-1, 0, 1, 0, 1, -1, -1, 1};   const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};   using namespace std;   struct line {     long long k, b;     int id;     line() {}     line(long long k, long long b, int id) : k(k), b(b), id(id) {}     long long get(long long x) { return k * x + b; }     bool operator<(const line &R) const {       if (k != R.k) return k > R.k;       return b > R.b;     }   };   int n;   class CHT {    private:     vector<line> v;       public:     long double inter(line a, line b) {       return (b.b - a.b) / (double)(a.k - b.k);     }     void add(line x) {       while ((int)v.size() > 1 && inter(v[(int)v.size() - 2], x) >=                                       inter(v[(int)v.size() - 2], v.back()))         v.pop_back();       v.push_back(x);     }     void push(line x) { v.push_back(x); }     void build() {       vector<line> b;       sort(v.begin(), v.end());       for (int i = 0; i < (int)v.size(); i++) {         if ((int)b.size() && b.back().k == v[i].k) continue;         b.push_back(v[i]);       }       v.clear();       for (auto it : b) {         add(it);       }     }     line get(long long x) {       int l = 0, r = (int)v.size() - 2, res = 0;       while (l <= r) {         int mid = l + r >> 1;         if (v[mid].get(x) <= v[mid + 1].get(x))           res = mid + 1, l = mid + 1;         else           r = mid - 1;       }       return v[res];     }   };   struct SegTree {     CHT t[N << 2];     void upd(int p, line x, int v = 1, int tl = 1, int tr = n) {       t[v].push(x);       if (tl == tr) return;       int tm = tl + tr >> 1;       if (p <= tm)         upd(p, x, v << 1, tl, tm);       else         upd(p, x, v << 1 | 1, tm + 1, tr);     }     void build(int v = 1, int tl = 1, int tr = n) {       if (tl == tr) return;       int tm = tl + tr >> 1;       build(v << 1, tl, tm);       build(v << 1 | 1, tm + 1, tr);       t[v].build();     }     line maxi(line a, line b, int x) {       if (a.get(x) >= b.get(x)) return a;       return b;     }     line get(int l, int r, int x, int v = 1, int tl = 1, int tr = n) {       if (l <= tl && tr <= r) return t[v].get(x);       int tm = tl + tr >> 1;       if (r <= tm) return get(l, r, x, v << 1, tl, tm);       if (tm < l) return get(l, r, x, v << 1 | 1, tm + 1, tr);       return maxi(get(l, r, x, v << 1, tl, tm),                   get(l, r, x, v << 1 | 1, tm + 1, tr), x);     }   } t;   int a[N];   long long s1[N], s2[N];   int main() {     ios_base ::sync_with_stdio(0), cin.tie(0), cout.tie(0);     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a[i];       s1[i] = (long long)a[i] * i;       s2[i] = a[i];     }     for (int i = n; i >= 1; i--) {       s1[i] += s1[i + 1];       s2[i] += s2[i + 1];       t.upd(i, line(s2[i + 1], -s1[i + 1], i));     }     t.build();     long long ans = 0;     for (int i = 1; i <= n; i++) {       ans = max(ans, t.get(i, n, i - 1).get(i - 1) + s1[i] - (i - 1) * s2[i]);     }     cout << ans;     exit(0);   }


#include <bits/stdc++.h>   using namespace std;   void answer() {     int n;     string s, t;     cin >> n >> s >> t;     int ps[26], pt[26];     int cs[26], ct[26];     memset(ps, -1, sizeof(ps));     memset(pt, -1, sizeof(pt));     memset(cs, 0, sizeof(cs));     memset(ct, 0, sizeof(ct));     for (int i = 0; i < s.size(); i++) {       ps[s[i] -  a ] = i;       cs[s[i] -  a ]++;     }     for (int i = 0; i < t.size(); i++) {       pt[t[i] -  a ] = i;       ct[t[i] -  a ]++;     }     for (int i = 0; i < 26; i++) {       if (cs[i] != ct[i]) {         cout <<  NO  <<   n ;         return;       }     }     int c = 0;     for (int i = 0; i < 26; i++) {       if (cs[i] > 1 || ct[i] > 1) {         cout <<  YES  <<   n ;         return;       }       for (int j = i + 1; j < 26; j++) {         c += ((ps[i] < ps[j]) != (pt[i] < pt[j]));       }     }     if (c % 2)       cout <<  NO  <<   n ;     else       cout <<  YES  <<   n ;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int q;     cin >> q;     for (int i = 0; i < q; i++) answer();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   double tick() {     static clock_t oldtick;     clock_t newtick = clock();     double diff = 1.0 * (newtick - oldtick) / CLOCKS_PER_SEC;     oldtick = newtick;     return diff;   }   long long gcd(long long a, long long b) {     if ((a == 0) || (b == 0)) {       return a + b;     }     return gcd(b, a % b);   }   long long powMod(long long a, long long b) {     long long res = 1;     while (b) {       if (b & 1) res = (res * a) % 1000000007;       a = (a * a) % 1000000007;       b >>= 1;     }     return (res % 1000000007);   }   long long pow2(long long a, long long b) {     long long res = 1;     while (b) {       if (b & 1) res = (res * a);       a = (a * a);       b >>= 1;     }     return res;   }   bool isPrime(long long a) {     for (long long i = 3; (i * i) <= a; i += 2) {       if ((a % i) == 0) return false;     }     if ((a != 2) && ((a % 2) == 0)) {       return false;     }     if (a == 1) {       return false;     }     return true;   }   string conLlToStr(long long a) {     stringstream mystr;     mystr << a;     return mystr.str();   }   long long conStrToLl(string st) {     long long numb = 0;     long long len = st.size(), i, j = 0;     for (long long i = len - 1; i >= 0; i--) {       numb += (pow2(10, j) * (st[i] -  0 ));       j++;     }     return numb;   }   long long basenoToDecimal(string st, long long basee) {     long long i = 0, j, anss = 0;     for (long long j = (int)st.length() - 1; j >= 0; j--) {       anss += (st[j] -  0 ) * pow2(basee, i);       i++;     }     return anss;   }   string decimalToString(long long num, long long basee) {     long long i = 0, j, opop;     string anss =   ;     vector<string> stri;     stri.push_back( 0 );     stri.push_back( 1 );     stri.push_back( 2 );     stri.push_back( 3 );     stri.push_back( 4 );     stri.push_back( 5 );     stri.push_back( 6 );     stri.push_back( 7 );     stri.push_back( 8 );     stri.push_back( 9 );     stri.push_back( A );     stri.push_back( B );     stri.push_back( C );     stri.push_back( D );     stri.push_back( E );     stri.push_back( F );     if (num == 0) {       return  0 ;     }     while (num) {       opop = (num % basee);       anss += stri[opop];       num /= basee;     }     reverse(anss.begin(), anss.end());     return anss;   }   long long my_sqrt(long long x) {     long long y = (long long)(sqrtl((long double)x) + 0.5);     while (y * y < x) {       y++;     }     while (y * y > x) {       y--;     }     if (y * y == x) {       return y;     }     return -1;   }   long long my_crt(long long x) {     long long y = (long long)(powl((long double)x, 1.0 / 3.0) + 0.5);     while (y * y * y < x) {       y++;     }     while (y * y * y > x) {       y--;     }     if (y * y * y == x) {       return y;     }     return -1;   }   const int dx[] = {0, 1, 1, 1, 0, -1, -1, -1};   const int dy[] = {1, 1, 0, -1, -1, -1, 0, 1};   string S[100010];   vector<string> stringContained[100010][30];   vector<pair<string, string> > firstString, secondString;   vector<pair<pair<string, string>, pair<string, string> > > ans;   set<int> numVowel;   vector<string> temp;   bool isVowel(char ch) {     if (ch ==  a  || ch ==  e  || ch ==  i  || ch ==  o  || ch ==  u ) {       return 1;     }     return 0;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int N;     cin >> N;     for (long long i = 1; i <= N; i++) {       cin >> S[i];       int vowel = 0;       char lastVowel;       for (long long j = 0; j <= (int)S[i].length() - 1; j++) {         if (isVowel(S[i][j])) {           vowel++;           lastVowel = S[i][j];         }       }       if (vowel) {         numVowel.insert(vowel);         stringContained[vowel][lastVowel -  a ].push_back(S[i]);       }     }     for (auto it = numVowel.begin(); it != numVowel.end(); ++it) {       int i = (*it);       for (long long j = 0; j <= 25; j++) {         for (int k = 0; k < (int)stringContained[i][j].size(); k += 2) {           if ((k + 1) < (int)stringContained[i][j].size()) {             secondString.push_back(make_pair(stringContained[i][j][k],                                              stringContained[i][j][k + 1]));           }         }         if (stringContained[i][j].size() % 2) {           temp.push_back(stringContained[i][j][stringContained[i][j].size() - 1]);         }       }       for (int k = 0; k < (int)temp.size(); k += 2) {         if ((k + 1) < (int)temp.size()) {           firstString.push_back(make_pair(temp[k], temp[k + 1]));         }       }       temp.clear();     }     int ind1 = 0, ind2 = 0;     while (ind1 < firstString.size() && ind2 < secondString.size()) {       ans.push_back(make_pair(           make_pair(firstString[ind1].first, secondString[ind2].first),           make_pair(firstString[ind1].second, secondString[ind2].second)));       ind1 += 1;       ind2 += 1;     }     for (int k = ind2; k < (int)secondString.size(); k += 2) {       if ((k + 1) < (int)secondString.size()) {         ans.push_back(make_pair(             make_pair(secondString[k].first, secondString[k + 1].first),             make_pair(secondString[k].second, secondString[k + 1].second)));       }     }     cout << ans.size() <<   n ;     for (long long i = 0; i <= (int)ans.size() - 1; i++) {       cout << ans[i].first.first <<     << ans[i].first.second <<   n ;       cout << ans[i].second.first <<     << ans[i].second.second <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline T ABS(T a) {     return a > 0 ? a : -a;   }   template <typename T>   inline T MIN(T a, T b) {     return a < b ? a : b;   }   template <typename T>   inline T MAX(T a, T b) {     return a > b ? a : b;   }   template <typename T>   inline T CHKMIN(T &a, T b) {     if (a > b) a = b;     return a;   }   template <typename T>   inline T CHKMAX(T &a, T b) {     if (a < b) a = b;     return a;   }   template <typename T>   inline void SWAP(T &a, T &b) {     static T c;     c = a;     a = b;     b = c;   }   template <typename T, typename... T0>   T MAX(T a, T b, T0... c) {     return a > b ? MAX(a, c...) : MAX(b, c...);   }   template <typename T, typename... T0>   T MIN(T a, T b, T0... c) {     return a < b ? MIN(a, c...) : MIN(b, c...);   }   template <typename T, int n>   void myin(T a[]) {     for (int i = (0); i < (int)(n); ++i) cin >> a[i];   }   template <typename T>   void myin(T &a) {     cin >> a;   }   template <typename T>   void print(T a) {     cout << a <<    ;   }   template <typename T, typename... T0>   void print(T a, T0... b) {     print(a);     print(b...);   }   template <typename T>   void println(T a) {     cout << a << endl;   }   template <typename T, typename... T0>   void println(T a, T0... b) {     print(a);     println(b...);   }   int n, in[120000];   long long dp[120000];   int main() {     long long sum = 0;     while (cin >> n) {       for (int i = (0); i < (int)(n); ++i) {         scanf( %d , in + i);         sum += in[i];       }       if (sum % 3 != 0) {         puts( 0 );         continue;       }       long long tmp = sum / 3, now = 0, ans = 0;       for (int i = (0); i < (int)(n); ++i) {         now += in[i];         if (i == 0)           dp[i] = 0;         else           dp[i] = dp[i - 1];         if (now == tmp) ++dp[i];       }       tmp += tmp, now = in[0];       for (int i = (1); i < (int)(n - 1); ++i) {         now += in[i];         if (now == tmp) ans += dp[i - 1];       }       println(ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int kN = 1e5 + 10;   const int MOD = 1e9 + 7;   int N, M;   int power(int d, int k) {     int ret = 1, tmp = d;     while (k) {       if (k & 1) {         ret = 1ll * ret * tmp % MOD;       }       tmp = 1ll * tmp * tmp % MOD;       k >>= 1;     }     return ret;   }   void cant() {     printf( 0 );     exit(0);   }   struct Edge {     int u, v;     bool diff;   } es[kN];   struct UFS {     int fa[kN];     int lowbit(int i) { return i & -i; }     void init() {       for (int i = 0; i < kN; i++) fa[i] = i;     }     int getFa(int i) {       if (fa[i] != i) fa[i] = getFa(fa[i]);       return fa[i];     }     bool isSameFa(int u, int v) {       int uf = getFa(u);       int vf = getFa(v);       return uf == vf;     }     void link(int u, int v) {       int uf = getFa(u);       int vf = getFa(v);       fa[uf] = vf;     }   } ufs;   int col[kN];   vector<int> G[kN];   void dfs(int u, int c) {     if (col[u]) {       if (col[u] != c) cant();       return;     }     col[u] = c;     c = c == 1 ? 2 : 1;     for (int i = 0; i < G[u].size(); i++) {       int v = G[u][i];       dfs(v, c);     }   }   int main() {     scanf( %d %d , &N, &M);     for (int i = 1; i <= M; i++) {       int op, u, v;       scanf( %d %d %d , &u, &v, &op);       if (u > v) swap(u, v);       es[i].u = u, es[i].v = v, es[i].diff = !op;     }     ufs.init();     for (int i = 1; i <= M; i++) {       if (es[i].diff == false) {         ufs.link(es[i].u, es[i].v);       }     }     for (int i = 1; i <= M; i++) {       if (es[i].diff) {         int uf = ufs.getFa(es[i].u);         int vf = ufs.getFa(es[i].v);         G[uf].push_back(vf);         G[vf].push_back(uf);       }     }     int cnt = 0;     for (int i = 1; i <= N; i++)       if (ufs.getFa(i) == i && !col[i]) {         dfs(i, 1);         cnt++;       }     int ans = power(2, cnt - 1);     printf( %d , ans);     return 0;   }


#include <bits/stdc++.h>   const int maxn = 100005;   int n, cnt;   int a[maxn], p[maxn];   int main() {     scanf( %d , &n);     p[1] = 1;     for (int i = 2; i <= n; i++)       if (p[i] == 0) {         p[i] = ++cnt;         for (int j = i; j <= n; j += i) a[j] = cnt, p[j] = 1;       }     for (int i = 2; i <= n; i++) printf( %d%c , a[i], i == n ?   n  :    );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int CMax = 5002;   const int CMax2 = 100002;   int m, B[CMax], A[CMax2], ats = 0, sk, pr;   int main() {     scanf( %d , &m);     for (int i = 0; i < CMax; i++) {       B[i] = 0;     }     for (int i = 0; i < m; i++) {       scanf( %d , &sk);       B[sk]++;     }     for (int i = 0; i < CMax; i++) {       if (B[i] > 0) {         B[i]--;         A[ats] = i;         ats++;         pr = i;       }     }     for (int i = pr - 1; i >= 0; i--) {       if (B[i] > 0) {         B[i]--;         A[ats] = i;         ats++;       }     }     printf( %d n , ats);     if (ats > 0) {       for (int i = 0; i < ats - 1; i++) {         printf( %d  , A[i]);       }       printf( %d n , A[ats - 1]);     }   }


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


#include<bits/stdc++.h>   #define fast {ios_base::sync_with_stdio(false);cin.tie(NULL);}   using namespace std;       const int mxn=2e5+5,mod=1e9+7;   int dp[mxn][20],a[mxn],nxt[mxn],n;   vector<int>prime_factors[mxn];      void sieve(){    for(int i=2;i<mxn;i++){     if(prime_factors[i].empty()){      nxt[i]=mxn;      for(int j=1;i*j<mxn;j++)       prime_factors[i*j].push_back(i);     }    }   }      void lifting(){    dp[n+1][0]=n+1;       for(int i=n;i>=1;i--){     dp[i][0]=dp[i+1][0];     for(auto x:prime_factors[a[i]]){      dp[i][0]=min(dp[i][0],nxt[x]);      nxt[x]=i;      }    }    for(int i=1;i<=19;i++){     for(int j=1;j<=n+1;j++)      dp[j][i]=dp[dp[j][i-1]][i-1];    }   }         void solve(){    int q,i,j;    cin>>n>>q;    for(i=1;i<=n;i++)     cin>>a[i];    sieve();    lifting();    while(q--){     int l,r;     cin>>l>>r;     int ans=0;     for(i=19;i>=0;i--){      if(dp[l][i]<=r){       ans+=1<<i;       l=dp[l][i];      }     }     cout<<ans+1<<  n ;    }   }         int main(void){    fast;    solve();   }


#include <bits/stdc++.h>   using namespace std;   bool is_pal(string a) {     string b = a;     reverse(b.begin(), b.end());     return b == a;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     ;     string second;     cin >> second;     for (int i = 0; i < second.size(); i++) {       string temp = second;       for (char j =  a ; j <=  z ; j++) {         if (j == second[i]) continue;         temp[i] = j;         if (is_pal(temp)) {           cout <<  YES n ;           return 0;         }       }     }     cout <<  NO n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, q;   unordered_map<int, pair<int, int>> resi[50 * 3 + 2];   struct FLOW {     int n, *pre, *dist;     FLOW(int n) : n(n) {       pre = (int *)malloc((n + 2) * sizeof(int));       dist = (int *)malloc((n + 2) * sizeof(int));     }     ~FLOW() {       free(pre);       free(dist);     }     pair<int, int> SAP() {       int flow = 0, cost = 0;       for (; SPFA();) {         for (int i = n + 1; i != n; i = pre[i]) {           assert(resi[pre[i]].count(i));           resi[pre[i]][i].first -= pre[n];           if (resi[i].count(pre[i]))             resi[i][pre[i]].first += pre[n];           else             resi[i][pre[i]] = make_pair(pre[n], -resi[pre[i]][i].second);         }         flow += pre[n];         cost += pre[n] * dist[n + 1];       }       return make_pair(flow, cost);     }     bool SPFA() {       int nn = n + 2, q[nn + 1];       bool v[nn];       int h = 0, l = 1, x;       for (int i = 0; i < nn; i++) dist[i] = (50 * 50 * 50);       memset(pre, -1, nn * sizeof(int));       memset(v, false, nn * sizeof(bool));       dist[n] = 0, pre[n] = -1;       q[0] = n, v[n] = true;       while (l != 0) {         x = q[h];         v[q[h]] = false;         l--;         h = (h + 1) % nn;         for (unordered_map<int, pair<int, int>>::const_iterator ix =                  resi[x].begin();              ix != resi[x].end(); ix++) {           if (ix->second.first == 0) continue;           int i = ix->first, p = ix->second.second;           if (dist[x] + p < dist[i]) {             dist[i] = dist[x] + p;             pre[i] = x;             if (!v[i]) v[q[(h + l++) % nn] = i] = true;           }         }       }       if (pre[n + 1] != -1) {         int flow = (50 * 50 * 50);         for (int i = n + 1; i != n; i = pre[i])           if (resi[pre[i]][i].first < flow) flow = resi[pre[i]][i].first;         pre[n] = flow;       }       return pre[n + 1] != -1;     }   };   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n >> q;     int arr[n][2], t, l, r, v;     for (int i = 0; i < n; i++) arr[i][0] = 1, arr[i][1] = n;     for (int iq = 0; iq < q; iq++) {       cin >> t >> l >> r >> v;       if (t == 1)         for (int i = l - 1; i < r; i++) arr[i][0] = max(arr[i][0], v);       else if (t == 2)         for (int i = l - 1; i < r; i++) arr[i][1] = min(arr[i][1], v);     }     for (int i = 0; i < n; i++) {       resi[3 * n][i] = make_pair(1, 0);       resi[2 * n + i][3 * n + 1] = make_pair(n, 2 * i + 1);       for (int j = 0; j < n; j++) resi[n + i][2 * n + j] = make_pair(1, 0);       for (int j = arr[i][0] - 1; j < arr[i][1]; j++)         resi[i][n + j] = make_pair(1, 0);     }     FLOW flow(3 * n);     pair<int, int> ans = flow.SAP();     if (ans.first != n)       cout << -1 << endl;     else       cout << ans.second << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 500500;   long long i, j, k, n, sum, ch, t, ans, num;   long long a[N], b[N], c[N];   void R(long long &x) {     x = 0;     ch = getchar();     while (ch <  0  ||  9  < ch) ch = getchar();     while ( 0  <= ch && ch <=  9 ) x = x * 10 + ch -  0 , ch = getchar();   }   int main() {     R(n);     for (i = 1; i <= n; i++) {       R(a[i]);       R(b[i]);       c[i] = a[i] ^ b[i];       sum ^= a[i];     }     k = 60;     for (i = 1; i <= n; i++) {       for (j = i + 1; j <= n; j++)         if (c[i] < c[j]) t = c[i], c[i] = c[j], c[j] = t;       if (!c[i]) break;       while (!(c[i] & 1ll << k)) k--;       for (j = i + 1; j <= n; j++)         if (c[j] & 1ll << k) c[j] ^= c[i];     }     num = i - 1;     ans = 1ll << num;     j = 60;     for (i = 1; i <= num; i++) {       while (!(c[i] & 1ll << j)) j--;       if (sum & 1ll << j) sum ^= c[i];     }     if (sum)       puts( 1/1 );     else       printf( %I64d/%I64d n , ans - 1, ans);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n, k;     cin >> n >> k;     int answer = 0;     int f[n];     for (int i = 0; i < n; i++) cin >> f[i];     sort(f, f + n);     for (int i = n - 1; i >= 0; i -= k) answer += (2 * (f[i] - 1));     cout << answer << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   int a[102];   int main() {     cin >> n;     for (int i = 0; i < n; ++i) cin >> a[i];     puts((n % 2 == 1) && (a[0] % 2 == 1) && (a[n - 1] % 2 == 1) ?  Yes  :  No );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MX = 100000;   const int N = 1e5 + 5;   const int K = 135;   const int MOD = 1e9 + 7;   int n, first[N], incr[N], x[K];   long long pw[K][N];   int main() {     cin >> n;     for (int i = 0; i < n; ++i) {       int x;       scanf( %d , &x);       incr[x]++;     }     for (int i = 1; i < K; ++i) pw[i][0] = 1;     for (int i = 0; i < N; ++i) pw[0][i] = 1;     for (int j = 1; j < N; ++j)       for (int i = 0; i < K; ++i) pw[i][j] = pw[i][j - 1] * i % MOD;     for (int i = MX; i >= 1; --i) first[i] = first[i + 1] + incr[i];     long long ans = 0;     for (int i = MX; i >= 1; --i)       if (first[i]) {         vector<int> d1, d2, d;         int dd = 1;         for (; dd * dd < i; ++dd)           if (i % dd == 0) {             d1.push_back(dd);             d2.push_back(i / dd);           }         if (dd * dd == i) d1.push_back(dd);         reverse(d2.begin(), d2.end());         merge(d1.begin(), d1.end(), d2.begin(), d2.end(), back_inserter(d));         int prev = 0;         long long p1 = 1, p2 = 1;         for (int j = (int)d.size() - 1; j >= 0; --j) {           x[j + 1] = first[d[j]] - prev;           prev += x[j + 1];           p1 = p1 * pw[j + 1][x[j + 1]] % MOD;           if (j + 1 == d.size())             p2 = p2 * pw[j][x[j + 1]] % MOD;           else             p2 = p2 * pw[j + 1][x[j + 1]] % MOD;         }         ans += p1 - p2;         ans %= MOD;         if (ans < 0) ans += MOD;       }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main(void) {     vector<int> z[26];     string a, b;     cin >> a >> b;     for (int i = 0; i < a.size(); ++i) z[a[i] -  a ].push_back(i);     bool ok = true;     for (int i = 0; i < b.size(); ++i) {       if (z[b[i] -  a ].size() == 0) {         ok = false;         break;       }     }     if (!ok) {       cout << -1 << endl;     } else {       int cnt = 1, cur = -1;       for (int i = 0; i < b.size(); ++i) {         vector<int> &tmp = z[b[i] -  a ];         vector<int>::iterator iter = upper_bound(tmp.begin(), tmp.end(), cur);         if (iter == tmp.end()) {           ++cnt;           cur = tmp[0];         } else {           cur = *iter;         }       }       cout << cnt << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   double a, v, l, d, w, t1, t2, t3, t4, t5, dis1, dis2, dis3, v1;   double chuli(double x) {     double diss = (v + w) * ((v - w) / a) / 2;     if (diss >= x)       return (-2.0 * w + sqrt(4.0 * w * w + 8.0 * a * (x))) / (2.0 * a);     else       return (v - w) / a + (x - diss) / v;   }   int main() {     cin >> a >> v >> l >> d >> w;     if (v >= w) {       t1 = w / a;       dis1 = a * t1 * t1 / 2;       v1 = a * sqrt(2 * d / a);       if (dis1 >= l)         printf( %.12lf n , sqrt(2.0 * l / a));       else if (dis1 >= d)         printf( %.12lf n , t1 + chuli(l - dis1));       else {         dis2 = 2 * (v - w) / a * w + (v - w) * (v - w) / a;         if (dis1 + dis2 >= d) {           t2 = 2.0 * (-2.0 * w + sqrt(4.0 * w * w + 4.0 * a * (d - dis1))) /                (2.0 * a);           t3 = chuli(l - d);           printf( %.12lf n , t1 + t2 + t3);         } else {           t2 = v / a;           t3 = (v - w) / a;           t4 = (d - dis2 - dis1) / v;           t5 = chuli(l - d);           printf( %.12lf n , t2 + t3 + t4 + t5);         }       }     } else {       t1 = v / a;       dis1 = a * t1 * t1 / 2;       if (dis1 < l)         t2 = (l - dis1) / v;       else {         t1 = sqrt(2 * l / a);         t2 = 0.0;       }       printf( %.12lf n , t1 + t2);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int A, B, C, Cans = 214748364, n, r, ansA, ansB;   bool f[1000010];   int gcd(int a, int b) {     if (b == 0)       return a;     else       return gcd(b, a % b);   }   void Work() {     int t, i, a = A, b = B;     for (C = 0; A != 1 || B != 1;) {       if (A > B) {         f[++C] = 0;         A -= B;       } else {         f[++C] = 1;         B -= A;       }       if (C > n) break;     }     f[++C] = 0;     if (C == n) {       t = 0;       for (int i = 2; i <= C; ++i)         if (f[i] == f[i - 1]) ++t;       if (t < Cans) Cans = t, ansA = a, ansB = b;     }   }   void out() {     if (Cans == 214748364)       printf( IMPOSSIBLE n );     else {       printf( %d n , Cans);       A = ansA, B = ansB;       Work();       for (int i = n; i >= 2; --i) printf( %c , f[i] ?  B  :  T );       printf( %c n , f[1] ?  B  :  T );     }   }   int main() {     int i;     scanf( %d%d , &n, &r);     for (int i = 1; i <= r; ++i)       if (gcd(i, r) == 1) {         A = i, B = r;         Work();         A = r, B = i;         Work();       }     out();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct point {     double x, y;   };   double dist(point P, point Q) {     double dx = P.x - Q.x, dy = P.y - Q.y;     return sqrt(dx * dx + dy * dy);   }   vector<point> crossing(point O1, double r1, point O2, double r2) {     double d = dist(O1, O2);     double t = (d * d + r1 * r1 - r2 * r2) / 2.0 / d / d;     double fx = O1.x + (O2.x - O1.x) * t, fy = O1.y + (O2.y - O1.y) * t;     double h = sqrt(r1 * r1 - t * d * t * d);     double dx = (O2.y - O1.y) / d * h, dy = (O1.x - O2.x) / d * h;     vector<point> ans;     point ans1 = {fx + dx, fy + dy};     ans.push_back(ans1);     point ans2 = {fx - dx, fy - dy};     ans.push_back(ans2);     return ans;   }   vector<double> tri[10];   void read(int id) {     point P, Q, R;     cin >> P.x >> P.y >> Q.x >> Q.y >> R.x >> R.y;     tri[id].push_back(dist(P, Q));     tri[id].push_back(dist(P, R));     tri[id].push_back(dist(Q, R));     sort(tri[id].begin(), tri[id].end());   }   bool quad(double a, double b, double c, double d) {     double x[] = {a, b, c, d};     sort(x, x + 4);     return (x[0] + x[1] + x[2] + 1.0E-9 > x[3]);   }   bool triineq(double a, double b, double c) {     double x[] = {a, b, c};     sort(x, x + 3);     return (x[0] + x[1] + 1.0E-9 > x[2]);   }   bool equals(double x, double y) { return (x - y < 1.0E-9 && x - y > -1.0E-9); }   int N;   point P[20];   int a[(1 << 4)], dp[(1 << 4)];   void dfs(int mask) {     int i, x, y, z;     a[mask] = min(a[mask], N);     for ((i) = 0; (i) < (int)(4); (i)++)       if (!(mask & (1 << i))) {         int mask2 = (mask | (1 << i));         bool found = false;         for ((x) = 0; (x) < (int)(N); (x)++)           for ((y) = 0; (y) < (int)(N); (y)++)             for ((z) = 0; (z) < (int)(N); (z)++) {               if (equals(dist(P[x], P[y]), tri[i][0]) &&                   equals(dist(P[x], P[z]), tri[i][1]) &&                   equals(dist(P[y], P[z]), tri[i][2])) {                 dfs(mask2);                 found = true;               }             }         if (!found)           for ((x) = 0; (x) < (int)(N); (x)++)             for ((y) = 0; (y) < (int)(N); (y)++) {               if (equals(dist(P[x], P[y]), tri[i][0])) {                 N++;                 P[N - 1] = crossing(P[x], tri[i][1], P[y], tri[i][2])[0];                 dfs(mask2);                 P[N - 1] = crossing(P[x], tri[i][1], P[y], tri[i][2])[1];                 dfs(mask2);                 N--;               }               if (equals(dist(P[x], P[y]), tri[i][1])) {                 N++;                 P[N - 1] = crossing(P[x], tri[i][0], P[y], tri[i][2])[0];                 dfs(mask2);                 P[N - 1] = crossing(P[x], tri[i][0], P[y], tri[i][2])[1];                 dfs(mask2);                 N--;               }               if (equals(dist(P[x], P[y]), tri[i][2])) {                 N++;                 P[N - 1] = crossing(P[x], tri[i][0], P[y], tri[i][1])[0];                 dfs(mask2);                 P[N - 1] = crossing(P[x], tri[i][0], P[y], tri[i][1])[1];                 dfs(mask2);                 N--;               }             }       }   }   vector<point> crossed(point O1, double r1, point O2, double r2) {     vector<point> ans = crossing(O1, r1, O2, r2);     vector<point> ans2 = crossing(O1, r2, O2, r1);     ans.push_back(ans2[0]);     ans.push_back(ans2[1]);     return ans;   }   void init() {     int a, b, c, i, j, k, x, y, z;     for ((i) = 0; (i) < (int)(4); (i)++) {       N = 3;       P[0].x = P[0].y = P[1].y = 0.0;       P[1].x = tri[i][0];       P[2] = crossing(P[0], tri[i][1], P[1], tri[i][2])[0];       dfs(1 << i);     }     for ((a) = 0; (a) < (int)(4); (a)++)       for ((b) = 0; (b) < (int)(a); (b)++)         for ((c) = 0; (c) < (int)(b); (c)++)           for ((i) = 0; (i) < (int)(3); (i)++)             for ((j) = 0; (j) < (int)(3); (j)++)               for ((k) = 0; (k) < (int)(3); (k)++) {                 if (triineq(tri[a][i], tri[b][j], tri[c][k])) {                   N = 6;                   P[0].x = P[0].y = P[1].y = 0.0;                   P[1].x = tri[a][i];                   P[2] = crossing(P[0], tri[b][j], P[1], tri[c][k])[0];                   vector<point> three = crossed(P[0], tri[a][(i + 1) % 3], P[1],                                                 tri[a][(i + 2) % 3]);                   vector<point> four = crossed(P[0], tri[b][(j + 1) % 3], P[2],                                                tri[b][(j + 2) % 3]);                   vector<point> five = crossed(P[1], tri[c][(k + 1) % 3], P[2],                                                tri[c][(k + 2) % 3]);                   for ((x) = 0; (x) < (int)(4); (x)++)                     for ((y) = 0; (y) < (int)(4); (y)++)                       for ((z) = 0; (z) < (int)(4); (z)++) {                         P[3] = three[x];                         P[4] = four[y];                         P[5] = five[z];                         dfs((1 << a) | (1 << b) | (1 << c));                       }                 }               }   }   int main() {     int i, j, k, l;     for ((i) = 0; (i) < (int)(4); (i)++) read(i);     int ans = 9;     for ((i) = 0; (i) < (int)(3); (i)++)       for ((j) = 0; (j) < (int)(3); (j)++)         for ((k) = 0; (k) < (int)(3); (k)++)           for ((l) = 0; (l) < (int)(3); (l)++)             if (quad(tri[0][i], tri[1][j], tri[2][k], tri[3][l])) ans = 8;     for ((i) = 0; (i) < (int)((1 << 4)); (i)++) a[i] = (1 << 29);     a[0] = 0;     init();     for ((i) = 0; (i) < (int)((1 << 4)); (i)++) {       dp[i] = a[i];       for (j = 1; j < i; j++)         if ((i & j) == j) dp[i] = min(dp[i], dp[j] + a[i ^ j] - 1);     }     ans = min(ans, dp[15]);     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   T mabs(const T &a) {     return a < 0 ? -a : a;   }   const int mod = 1e9 + 9;   const int SZ = 300300;   struct mat {     long long A[2][2];     mat(int a = 0, int b = 0, int c = 0, int d = 0) {       A[0][0] = a;       A[0][1] = b;       A[1][0] = c;       A[1][1] = d;     }     mat operator*(const mat &other) const {       mat res;       for (int i = (0), ei = (2); i < ei; i++)         for (int j = (0), ej = (2); j < ej; j++) {           for (int k = (0), ek = (2); k < ek; k++)             res.A[i][j] += A[i][k] * other.A[k][j];           res.A[i][j] %= mod;         }       return res;     }     mat operator+(const mat &other) const {       mat res;       for (int i = (0), ei = (2); i < ei; i++)         for (int j = (0), ej = (2); j < ej; j++) {           res.A[i][j] = A[i][j] + other.A[i][j];           res.A[i][j] %= mod;         }       return res;     }     mat operator-(const mat &other) const {       mat res;       for (int i = (0), ei = (2); i < ei; i++)         for (int j = (0), ej = (2); j < ej; j++) {           res.A[i][j] = A[i][j] - other.A[i][j];           res.A[i][j] %= mod;         }       return res;     }   };   mat Fib(1, 1, 1, 0);   mat EminusArev(-1, -1, -1, 0);   mat Step[SZ];   long long Sum[4 * SZ];   mat M[4 * SZ];   int A[SZ];   void build(int v, int l, int r) {     if (l == r) {       Sum[v] = A[l];       return;     }     int c = (l + r) / 2;     build(2 * v, l, c);     build(2 * v + 1, c + 1, r);     Sum[v] = (Sum[2 * v] + Sum[2 * v + 1]) % mod;   }   inline mat sumUp(int a, int b) {     mat res = EminusArev * (Step[0] - Step[b - a + 1]);     return Step[a] * res;   }   void add(int v, int l, int r, int ql, int qr, int st) {     Sum[v] = (Sum[v] + sumUp(ql - st, qr - st).A[0][0]) % mod;     if (l == ql && r == qr) {       M[v] = M[v] + Step[ql - st];       return;     }     int c = (l + r) / 2;     if (qr <= c)       add(2 * v, l, c, ql, qr, st);     else if (ql > c)       add(2 * v + 1, c + 1, r, ql, qr, st);     else {       add(2 * v, l, c, ql, c, st);       add(2 * v + 1, c + 1, r, c + 1, qr, st);     }   }   long long getSum(int v, int l, int r, int ql, int qr) {     if (l == ql && r == qr) {       return Sum[v];     }     int c = (l + r) / 2;     long long res = 0;     if (qr <= c)       res = getSum(2 * v, l, c, ql, qr);     else if (ql > c)       res = getSum(2 * v + 1, c + 1, r, ql, qr);     else       res = getSum(2 * v, l, c, ql, c) + getSum(2 * v + 1, c + 1, r, c + 1, qr);     return (res + (M[v] * sumUp(ql - l, qr - l)).A[0][0]) % mod;   }   void run() {     Step[0] = mat(1, 0, 0, 1);     for (int i = (1), ei = (SZ); i < ei; i++) Step[i] = Step[i - 1] * Fib;     int n, m;     cin >> n >> m;     for (int i = (0), ei = (n); i < ei; i++) scanf( %d , A + i);     build(1, 0, n - 1);     for (int i = (0), ei = (m); i < ei; i++) {       int t, a, b;       scanf( %d%d%d , &t, &a, &b);       --a;       --b;       if (t == 1) {         add(1, 0, n - 1, a, b, a);       } else {         int res = getSum(1, 0, n - 1, a, b);         res = (res + mod) % mod;         printf( %d n , res);       }     }   }   int main() {     run();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   char mat[1501][1501];   int visited[1501][1501][3];   int getr(int x) { return (x % n + n) % n; }   int getc(int x) { return (x % m + m) % m; }   int dx[] = {0, -1, 0, 1};   int dy[] = {-1, 0, 1, 0};   bool dfs(int lx, int ly) {     int x = getr(lx), y = getc(ly);     if (visited[x][y][0] && (lx != visited[x][y][1] || ly != visited[x][y][2]))       return 1;     if (mat[x][y] ==  #  || visited[x][y][0]) return 0;     visited[x][y][0] = 1;     visited[x][y][1] = lx;     visited[x][y][2] = ly;     for (int i = 0; i < 4; ++i) {       if (dfs(lx + dx[i], ly + dy[i])) return 1;     }     return 0;   }   int main() {     ios::sync_with_stdio(0);     while (cin >> n >> m) {       int sx, sy;       memset(visited, 0, sizeof(visited));       for (int i = 0; i < n; ++i) {         for (int j = 0; j < m; ++j) {           cin >> mat[i][j];           if (mat[i][j] ==  S ) sx = i, sy = j;         }       }       if (dfs(sx, sy))         cout <<  Yes n ;       else         cout <<  No n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long M = 1e9 + 7;   vector<long long> prime;   bool num[1000005 + 2];   void sieve() {     num[0] = true;     num[1] = true;     for (long long i = 2; i <= 1000005; i++) {       if (num[i] == false) {         prime.push_back(i);         for (long long j = 2 * i; j <= 1000005; j = j + i) {           num[j] = true;         }       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long n, m, i, j, k, l, a, b, c, p, q, r, t, ans, sum;     cin >> t;     vector<pair<long long, long long> > v;     while (t--) {       cin >> n;       m = n;       j = 0;       while (n--) {         cin >> k >> a;         b = a + 1;         c = b + 1;         for (i = 1; i < k; i++) {           cin >> a;           if (a >= c) {             b = b + (a - c) + 1;             c = a + 2;           } else             c++;         }         v.push_back(make_pair(b, k));       }       sort(v.begin(), v.end());       b = v[0].first + v[0].second;       a = v[0].first;       for (i = 1; i < m; i++) {         if (v[i].first > b) {           c = v[i].first - b;           b = v[i].first + v[i].second;           a = a + c;         } else {           b = b + v[i].second;         }       }       cout << a << endl;       v.clear();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1.0);   const double eps = 1e-6;   const int inf = 1e9;   const int mod = 1e9 + 7;   const int maxn = 5e5 + 10;   int n;   int a[1010], b[1010];   int main() {     ios::sync_with_stdio(false);     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a[i];     }     for (int i = 1; i <= n; i++) {       cin >> b[i];     }     int ans = 0;     for (int i = 1; i <= n; i++) {       int r1 = 0, r2 = 0;       for (int j = i; j <= n; j++) {         r1 |= a[j];         r2 |= b[j];         ans = max(r1 + r2, ans);       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, a, b, c;     cin >> n >> a >> b >> c;     long long res = 0;     for (int i = 0; i <= a; ++i) {       for (int j = 0; j <= b; ++j) {         if (2 * n - i - 2 * j >= 0 && !((2 * n - i - 2 * j) % 4) &&             2 * n - i - 2 * j <= 4 * c) {           ++res;         }       }     }     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   const int MAXN = (int)1e5 + 5;   const int MODN = (int)1e9 + 7;   int inf = 0x3f3f3f3f;   using namespace std;   char str[MAXN];   int num[MAXN];   int a[MAXN];   struct Com {     int cost;     int qua;   } c[MAXN];   int cmp(Com a, Com b) { return a.cost < b.cost; }   int main() {     int n, m;     while (scanf( %d , &n) != EOF) {       for (int i = 0; i < n; i++) {         scanf( %d%d , &c[i].cost, &c[i].qua);       }       sort(c, c + n, cmp);       int flag = 0;       for (int i = 1; i < n; i++) {         if (c[i].qua < c[i - 1].qua && c[i].cost > c[i - 1].cost) {           flag = 1;         }       }       if (flag)         puts( Happy Alex );       else         puts( Poor Alex );     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 3e5 + 5;   const int maxm = 15;   const long long INF = 1e18;   int n, m, k;   int a[maxn];   long long dp[maxn][maxm];   void ReadInput() {     cin >> n >> m >> k;     for (int i = 1; i <= n; ++i) cin >> a[i];   }   void Solve() {     fill_n(&dp[0][0], sizeof(dp) / sizeof(dp[0][0]), -INF);     for (int i = 0; i <= n; ++i) dp[i][10] = 0;     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= m; ++j) {         if (j == 1)           dp[i][j] = max((long long)a[i] - k, dp[i - 1][m] + a[i] - k);         else           dp[i][j] = dp[i - 1][j - 1] + a[i];       }     long long ans = 0;     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= m; ++j) ans = max(ans, dp[i][j]);     cout << ans;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     ReadInput();     Solve();   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 5e5 + 10;   char s[maxn], t[maxn];   int nxt[maxn];   void getNxt(int m) {     int i = 1, j = 0;     nxt[0] = 0;     while (i < m) {       if (t[i] == t[j])         nxt[i++] = ++j;       else if (!j)         i++;       else         j = nxt[j - 1];     }   }   int main() {     scanf( %s%s , s, t);     int len1 = strlen(s), len2 = strlen(t);     int len1_0 = 0, len1_1 = 0, len2_0 = 0, len2_1 = 0;     for (int i = 0; i < len1; i++) {       int k = s[i] -  0 ;       if (k == 0)         len1_0++;       else         len1_1++;     }     for (int i = 0; i < len2; i++) {       int k = t[i] -  0 ;       if (k == 0)         len2_0++;       else         len2_1++;     }     getNxt(len2);     int k = nxt[len2 - 1];     if (len1 < len2) {       for (int i = 0; i < len1; i++) cout << s[i];     } else if (len1 == len2) {       if (len1_0 != len2_0 || len1_1 != len2_1) {         for (int i = 0; i < len1; i++) cout << s[i];       } else {         for (int i = 0; i < len1; i++) cout << t[i];       }     } else {       if (len2_0 == 0) {         for (int i = 1; i <= len1_1; i++) {           cout <<  1 ;         }         for (int i = 1; i <= len1_0; i++) {           cout <<  0 ;         }         return 0;       } else if (len2_1 == 0) {         for (int i = 1; i <= len1_1; i++) {           cout <<  1 ;         }         for (int i = 1; i <= len1_0; i++) {           cout <<  0 ;         }         return 0;       }       if (len1_0 < len2_0 || len1_1 < len2_1) {         for (int i = 0; i < len1; i++) cout << s[i];       } else {         if (k == 0) {           int p = min(len1_0 / len2_0, len1_1 / len2_1);           for (int j = 1; j <= p; j++) {             for (int i = 0; i < len2; i++) {               cout << t[i];             }           }           len1_0 = len1_0 - len2_0 * p;           len1_1 = len1_1 - len2_1 * p;           for (int i = 1; i <= len1_0; i++) {             cout <<  0 ;           }           for (int i = 1; i <= len1_1; i++) {             cout <<  1 ;           }         } else {           int f0 = 0, f1 = 0;           for (int i = k; i < len2; i++) {             int p = t[i] -  0 ;             if (p == 0)               f0++;             else               f1++;           }           for (int i = 0; i < len2; i++) {             cout << t[i];           }           len1_0 -= len2_0;           len1_1 -= len2_1;           int p = min(len1_0 / f0, len1_1 / f1);           len1_0 = len1_0 - f0 * p;           len1_1 = len1_1 - f1 * p;           for (int j = 1; j <= p; j++) {             for (int i = k; i < len2; i++) {               cout << t[i];             }           }           for (int i = 1; i <= len1_0; i++) {             cout <<  0 ;           }           for (int i = 1; i <= len1_1; i++) {             cout <<  1 ;           }         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   #pragma GCC optimize(2)   #pragma GCC optimize(3)   inline int read() {     int x = 0, f = 0;     char ch = getchar();     while (!isdigit(ch)) f |= ch ==  - , ch = getchar();     while (isdigit(ch)) x = 10 * x + ch -  0 , ch = getchar();     return f ? -x : x;   }   inline long long llread() {     long long x = 0, f = 0;     char ch = getchar();     while (!isdigit(ch)) f |= ch ==  - , ch = getchar();     while (isdigit(ch)) x = 10 * x + ch -  0 , ch = getchar();     return f ? -x : x;   }   long long fact[110], c[110][110];   long long f[110][110][110];   long long n, m, k, P;   signed main() {     n = llread(), m = llread(), k = llread(), P = llread();     c[0][0] = fact[0] = 1;     for (long long i = (1); i <= (n); i++) {       c[i][0] = c[i][i] = 1;       for (long long j = (1); j <= (i - 1); j++)         c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % P;     }     for (long long i = (1); i <= (n); i++) fact[i] = (fact[i - 1] * i) % P;     for (long long i = (0); i <= (n); i++) f[0][i][0] = 1;     for (long long i = (1); i <= (n); i++) {       f[i][1][1] = fact[i];       for (long long j = (i + 1); j <= (n); j++) f[i][j][0] = fact[i];       for (long long j = (2); j <= (min(i, m)); j++) {         for (long long p = (0); p <= (min(i - j + 1, k)); p++) {           f[i][j][p] = (f[i][j][p] + (f[i - 1][j - 1][p - (j == 1)] * 2)) % P;           for (long long q = (2); q <= (i - 1); q++) {             for (long long w = (0); w <= (p - (j == 1)); w++) {               if (f[q - 1][j - 1][w] && f[i - q][j - 1][p - (j == 1) - w]) {                 f[i][j][p] = (f[i][j][p] + f[q - 1][j - 1][w] *                                                f[i - q][j - 1][p - (j == 1) - w] %                                                P * c[i - 1][q - 1]) %                              P;               }             }           }         }       }     }     printf( %lld n , f[n][m][k]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     char now =    ;     int count = 0, sum = 0, n;     n = s.size();     for (int i = 0; i < n; i++) {       if (now == s[i] and count < 5)         count++;       else         sum++, now = s[i], count = 1;     }     cout << sum <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100005;   int t[N];   int main() {     ios_base::sync_with_stdio(0);     int n;     cin >> n;     t[0] = 0;     t[n + 1] = 0;     for (int i = 1; i <= n; ++i) {       cin >> t[i];       t[i] = min(t[i - 1] + 1, t[i]);     }     for (int i = n; i > 0; --i) {       t[i] = min(t[i + 1] + 1, t[i]);     }     int res = 0;     for (int i = 1; i <= n; ++i) res = max(res, t[i]);     cout << res <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }   const int MAXN = 100000;   const int MAXQ = 100000;   int n, nq;   int x[MAXN];   int qx[MAXQ], qt[MAXQ];   long long qans[MAXQ];   pair<int, int> o[MAXQ];   priority_queue<pair<int, pair<int, int>>> pq;   struct TreapNode {     int prio, sz, l, r, par;   };   struct Treap {     int n, root;     vector<TreapNode> nodes;     void init(int _n) {       n = _n, root = -1;       nodes = vector<TreapNode>(n);       for (int i = (0); i < (n); ++i)         nodes[i].prio =             rand() % 1000 * 1000000 + rand() % 1000 * 1000 + rand() % 1000,         nodes[i].sz = 1, nodes[i].l = nodes[i].r = nodes[i].par = -1;     }     int get(int offset) {       int at = root;       while (true) {         assert(at != -1 && offset < nodes[at].sz);         int l = nodes[at].l, r = nodes[at].r;         if (l != -1) {           if (offset < nodes[l].sz) {             at = l;             continue;           }           offset -= nodes[l].sz;         }         if (offset == 0)           return at;         else           --offset;         if (r != -1) {           if (offset < nodes[r].sz) {             at = r;             continue;           }           offset -= nodes[r].sz;         }         assert(false);       }     }     int find(int at) {       int ret = 0;       if (nodes[at].l != -1) ret += nodes[nodes[at].l].sz;       while (nodes[at].par != -1) {         int to = nodes[at].par;         if (at == nodes[to].r) ret += 1 + getsz(nodes[to].l);         at = to;       }       return ret;     }     int getsz(int a) { return a == -1 ? 0 : nodes[a].sz; }     void setpar(int a, int b) {       if (a != -1) nodes[a].par = b;     }     void split(int res, int &l, int &r, int sz) {       if (res == -1) {         assert(sz == 0);         l = r = -1;       } else if (sz <= getsz(nodes[res].l))         split(nodes[res].l, l, nodes[res].l, sz), setpar(nodes[res].l, res),             r = res;       else         split(nodes[res].r, nodes[res].r, r, sz - 1 - getsz(nodes[res].l)),             setpar(nodes[res].r, res), l = res;       if (l != -1) nodes[l].par = -1;       if (r != -1) nodes[r].par = -1;       if (res != -1)         nodes[res].sz = 1 + getsz(nodes[res].l) + getsz(nodes[res].r);     }     void merge(int &res, int l, int r) {       if (l == -1)         res = r;       else if (r == -1)         res = l;       else if (nodes[l].prio > nodes[r].prio)         merge(nodes[l].r, nodes[l].r, r), setpar(nodes[l].r, l), res = l;       else         merge(nodes[r].l, l, nodes[r].l), setpar(nodes[r].l, r), res = r;       if (res != -1)         nodes[res].sz = 1 + getsz(nodes[res].l) + getsz(nodes[res].r);     }   };   Treap treap;   void initpockets(int sz) {     treap.init(sz);     treap.root = 0;   }   int getpocket(int offset) { return treap.get(offset); }   int getoffset(int pocket) { return treap.find(pocket); }   void insertpocket(int offset, int pocket) {     int l, r;     treap.split(treap.root, l, r, offset);     treap.merge(l, l, pocket);     treap.merge(treap.root, l, r);   }   void solve() {     for (int i = (0); i < (nq); ++i) o[i] = make_pair(qx[i], i);     sort(o, o + nq);     int at = 0;     while (at < nq && o[at].first < x[0]) {       int id = o[at++].second;       qans[id] = qx[id];     }     int cround = 0, coffset = 0, cseen = 1;     initpockets(n);     pq = priority_queue<pair<int, pair<int, int>>>();     for (int i = (0); i < (n); ++i) {       int cx = x[i], nx = i == n - 1 ? INT_MAX : x[i + 1];       while (at < nq && (nx == INT_MAX || o[at].first < nx)) {         int id = o[at++].second;         int qoffset = (coffset + qx[id] - cx) % cseen;         int qround =             cround + (qx[id] - cx) / cseen + (qoffset < coffset ? 1 : 0) + qt[id];         int qpocket = getpocket(qoffset);         pq.push(make_pair(-qround, make_pair(id, qpocket)));       }       int dx = nx == INT_MAX ? INT_MAX : nx - cx;       if (dx != INT_MAX && coffset + dx < cseen) {         cx += dx, coffset += dx;       } else {         int rem = cseen - coffset;         cx += rem, coffset = 0, ++cround;         if (dx != INT_MAX) dx -= rem;         int full = dx == INT_MAX ? INT_MAX : dx / cseen;         while (!pq.empty() &&                (full == INT_MAX || -pq.top().first < cround + full)) {           int qround = -pq.top().first, id = pq.top().second.first,               qpocket = pq.top().second.second;           pq.pop();           int qoffset = getoffset(qpocket);           qans[id] = cx + (long long)(qround - cround) * cseen + qoffset;         }         if (full == INT_MAX) break;         cround += full, cx += full * cseen, dx -= full * cseen, coffset += dx,             cx += dx, dx = 0;       }       insertpocket(coffset, i + 1), ++cseen;     }   }   void run() {     scanf( %d%d , &n, &nq);     for (int i = (0); i < (n); ++i) scanf( %d , &x[i]);     for (int i = (0); i < (nq); ++i) scanf( %d%d , &qx[i], &qt[i]);     solve();     for (int i = (0); i < (nq); ++i) printf( %lld n , qans[i]);   }   long long bfans[MAXQ];   void bf() {     int sz = 0;     for (int i = (0); i < (n); ++i) sz = max(sz, x[i] + 1);     for (int i = (0); i < (nq); ++i) sz = max(sz, qx[i] + 1);     vector<int> cur(sz);     for (int i = (0); i < (sz); ++i) cur[i] = i;     int nxt = sz;     int t = 0;     int rem = nq;     while (rem > 0) {       for (int i = (0); i < (nq); ++i)         if (qt[i] == t) {           bfans[i] = cur[qx[i]];           --rem;         }       int at = 0, idx = 0;       for (int i = (0); i < (sz); ++i) {         if (at < n && x[at] == i) {           ++at;           continue;         }         cur[idx++] = cur[i];       }       while (idx < sz) cur[idx++] = nxt++;       ++t;     }   }   void stress() {     for (int rep = (0); rep < (10000); ++rep) {       n = 100;       nq = 50;       int lim = 5 * n;       for (int i = (0); i < (n); ++i) x[i] = rand() % (lim - n);       sort(x, x + n);       for (int i = (0); i < (n); ++i) x[i] += i;       for (int i = (0); i < (nq); ++i) {         qx[i] = rand() % lim;         qt[i] = rand() % 5;       }       solve();       bf();       bool ok = true;       for (int i = (0); i < (nq); ++i)         if (bfans[i] != qans[i]) ok = false;       if (ok) {         printf( . );         continue;       }       printf( err n );       printf( have: );       for (int i = (0); i < (nq); ++i) printf(  %lld , qans[i]);       puts(  );       printf( want: );       for (int i = (0); i < (nq); ++i) printf(  %lld , bfans[i]);       puts(  );       printf( %d %d n , n, nq);       for (int i = (0); i < (n); ++i) {         if (i != 0) printf(   );         printf( %d , x[i]);       }       puts(  );       for (int i = (0); i < (nq); ++i) printf( %d %d n , qx[i], qt[i]);       break;     }   }   int main() {     run();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 5050;   int c, d;   char ch[N];   int Calc(int b, int e) {     c = 0, d = 0;     int ret = 0, i;     for (i = b; i <= e; i++) {       if (ch[i] ==  ( ) c++;       if (ch[i] ==  ) ) {         if (c)           c--;         else {           if (d > 0)             d--, c++;           else             return ret;         }       }       if (ch[i] ==  ? ) {         if (c)           c--, d++;         else           c++;       }       if (c == 0) {         ret++;       }     }     return ret;   }   int main() {     int n, i, sol = 0;     scanf( %s , ch + 1);     n = strlen(ch + 1);     for (i = 1; i <= n; i++) sol += Calc(i, n);     printf( %i n , sol);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int tt = 1;     cin >> tt;     while (tt--) {       int n;       cin >> n;       int A[n];       for (int i = 0; i < n; i++) {         cin >> A[i];       }       int cnt = 0;       sort(A, A + n);       int left, right;       if (n % 2 == 0) {         left = n / 2 - 1;         right = n / 2;       } else {         left = n / 2;         right = n / 2 + 1;       }       while (cnt < n) {         cout << A[left] <<    ;         left--;         cnt++;         if (cnt == n) {           break;         }         cout << A[right] <<    ;         right++;         cnt++;       }       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int INT_MAX_VAL = (int)0x3F3F3F3F;   int INT_MIN_VAL = (int)-0x3F3F3F3F;   long long LONG_MAX_VAL = (long long)0x3F3F3F3F3F3F3F3F;   long long LONG_MIN_VAL = (long long)-0x3F3F3F3F3F3F3F3F;   long long vx, vy, wx, wy;   long long R;   long double t;   bool solve(long double s, long double dx, long double dy) {     if (s <= t) {       dx -= vx * s;       dy -= vy * s;     } else {       dx -= wx * (s - t) + vx * t;       dy -= wy * (s - t) + vy * t;     }     return (dx * dx + dy * dy) <= (R * R * s * s);   }   int main() {     cin.tie(0);     ios::sync_with_stdio(false);     long long x1, y1, x2, y2;     cin >> x1 >> y1 >> x2 >> y2;     cin >> R >> t;     cin >> vx >> vy >> wx >> wy;     long double l = 0;     long double r = 1.0e9;     while ((abs(r - l) / max(1.l, l)) > 1e-9) {       double c = (l + r) / 2;       if (solve(c, x2 - x1, y2 - y1)) {         r = c;       } else {         l = c;       }     }     cout << setprecision(15) << fixed << l <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, c, p[55], t[55], x = 0, L = 0, R = 0;     cin >> n >> c;     for (int i = 0; i < n; i++) {       cin >> p[i];     }     for (int i = 0; i < n; i++) {       cin >> t[i];     }     for (int i = 0; i < n; i++) {       x += t[i];       L += max(0, p[i] - c * x);     }     x = 0;     for (int i = n - 1; i > -1; i--) {       x += t[i];       R += max(0, p[i] - c * x);     }     if (L > R) {       cout <<  Limak  << endl;     } else if (L < R) {       cout <<  Radewoosh  << endl;     } else       cout <<  Tie  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long a[200005], b[200005];   bool cmp(int a, int b) { return a > b; }   int main() {     long long n;     cin >> n;     for (int i = 0; i < n; ++i) scanf( %I64d , &a[i]);     for (int i = 0; i < n; ++i) scanf( %I64d , &b[i]);     for (long long i = 1; i <= n; ++i) a[i - 1] *= i * (n - i + 1);     sort(a, a + n);     sort(b, b + n, cmp);     long long ans = 0;     for (int i = 0; i < n; ++i) {       ans = (ans + (a[i] % 998244353) * b[i] % 998244353) % 998244353;     }     cout << ans << endl;     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   vector<int> vct;   void DFS(int d, int num) {     if (d == 9) {       return;     } else {       int a = num * 10 + 4;       vct.push_back(a);       DFS(d + 1, a);       int b = num * 10 + 7;       vct.push_back(b);       DFS(d + 1, b);     }   }   long long calc(int a, int b, int l, int r) {     int x = max(a, l);     int y = min(b, r);     if (x > y) {       return 0;     } else {       return y - x + 1;     }   }   int main() {     vct.clear();     DFS(0, 0);     vct.push_back(-1);     vct.push_back(1000000009);     sort(vct.begin(), vct.end());     int ss = vct.size();     int p1, p2, v1, v2;     int k;     while (scanf( %d %d %d %d %d , &p1, &p2, &v1, &v2, &k) != EOF) {       long long ans = 0;       for (int i = 1; i + k < ss; i++) {         int x = vct[i - 1] + 1;         int a = vct[i];         int b = vct[i + k - 1];         int y = vct[i + k] - 1;         long long tmp = 0;         tmp += calc(x, a, p1, p2) * calc(b, y, v1, v2);         tmp += calc(x, a, v1, v2) * calc(b, y, p1, p2);         if (k == 1 && v1 <= a && a <= p2 && tmp > 0) {           tmp--;         }         ans += tmp;       }       double a = 1.0 * ans / (p2 - p1 + 1) / (v2 - v1 + 1);       printf( %.20f n , a);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string a =        What are you doing at the end of the world? Are you busy? Will you save          us? ;   string pref =  What are you doing while sending   ;   string suff =   ? Are you busy? Will you send   ;   string last =   ? ;   long long f[100001];   long long q, n, k, n1, n2, n3, n4;   const long long inf = 1e18 + 10;   char solution(long long n, long long k) {     if (k > f[n]) return  . ;     if (n == 0) return a[k - 1];     if (k <= n2) return pref[k - 1];     k = k - n2;     if (k <= f[n - 1]) return solution(n - 1, k);     k = k - f[n - 1];     if (k <= n3) return suff[k - 1];     k = k - n3;     if (k <= f[n - 1]) return solution(n - 1, k);     k = k - f[n - 1];     if (k <= n4) return last[k - 1];   }   int main() {     n1 = a.length();     n2 = pref.length();     n3 = suff.length();     n4 = last.length();     f[0] = n1;     for (int i = 1; i <= 100000; i++)       f[i] = min(inf, n2 + f[i - 1] + n3 + f[i - 1] + n4);     cin >> q;     while (q > 0) {       cin >> n >> k;       q = q - 1;       cout << solution(n, k);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   const long long INF = 1e9 + 8;   const long double pi = 3.14159265359;   template <class T>   T fac(T n) {     T res = 1, i;     for (i = 2; i <= n; i++) res *= i;     return res;   }   template <class T>   T lcm(T a, T b) {     return (a * b) / __gcd(a, b);   }   template <class T>   T digitsum(T x) {     T sum = 0;     while (x) {       sum += x % 10;       x /= 10;     }     return sum;   }   string tostring(long long a) {     string ans;     while (a) {       ans += char(a % 10 +  0 );       a /= 10;     }     return ans;   }   void nPermute(string str, long long n) {     sort((str).begin(), (str).end());     long long i = 1;     do {       if (i == n) break;       i++;     } while (next_permutation(str.begin(), str.end()));     cout << str << endl;   }   vector<long long> factors(long long n) {     vector<long long> f;     for (long long x = 2; x * x <= n; x++) {       while (n % x == 0) {         f.push_back(x);         n /= x;       }     }     if (n > 1) f.push_back(n);     return f;   }   bool prime(long long n) {     if (n < 2) return false;     for (long long x = 2; x * x <= n; x++)       if (n % x == 0) return false;     return true;   }   long long ncr(long long n, long long k) {     long long res = 1;     if (k > n - k) k = n - k;     for (long long i = 0; i < k; i++) {       res *= (n - i);       res /= (i + 1);     }     return res;   }   tuple<long long, long long, long long> Gcd(long long a, long long b) {     if (b == 0)       return {1, 0, a};     else {       long long x, y, g;       tie(x, y, g) = Gcd(b, a % b);       return {y, x - (a / b) * y, g};     }   }   const long long mod = 1e5;   long long binpow(long long a, long long b, long long m) {     a %= m;     long long res = 1;     while (b > 0) {       if (b & 1) res = res * a % m;       a = a * a % m;       b >>= 1;     }     return res % m;   }   void solve() {     long double n, r;     cin >> n >> r;     long double ang1 = 1 / (tan(pi / (2 * n))), ang2 = 1 / (tan(pi / n));     long double ans = (n * r * r) / (ang1 + ang2);     cout << fixed << setprecision(50) << ans << endl;   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0), cout.tie(0);     solve();     cerr <<  Time elapsed :   << 1.0 * clock() / CLOCKS_PER_SEC <<   sec  n ;   }


#include <bits/stdc++.h>   using namespace std;   int getV(char c) {     if (c >=  0  && c <=  9 ) return c -  0 ;     if (c >=  A  && c <=  Z ) return 10 + c -  A ;     if (c >=  a  && c <=  z ) return 36 + c -  a ;     if (c ==  - ) return 62;     if (c ==  _ ) return 63;   }   int main() {     string s;     cin >> s;     int N = s.length();     long long p3[6 * N + 1];     p3[0] = 1;     for (int i = 1; i < 6 * N + 1; i++) p3[i] = (p3[i - 1] * 3) % 1000000007;     int cnt = 0;     for (int i = 0; i < N; i++) {       int v = getV(s[i]);       for (int j = 0; j < 6; j++)         if ((v & (1 << j)) == 0) cnt++;     }     cout << p3[cnt];     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   struct edge   {    int u, v, w;    bool operator < (const edge &oth) const    {     return w < oth.w;    }   } e[N << 1];   int n, m, x, mn = INT_MAX;   long long ans, rem;   struct disjoint_sets_union   {    int fa[N];    int Query(int p)    {     if(fa[p] == p) return p;     return fa[p] = Query(fa[p]);    }       } dsu;   queue<int> que;   set<int> unvised, G[N];   bool vis[N], type[N];   void FindBlocks()   {    for(int i = 1; i <= n; i++) if(!vis[i])    {     que.push(i);     vis[i] = true;     unvised.erase(i);     dsu.fa[i] = i;     while(!que.empty())     {      int u = que.front();      que.pop();      for(set<int>::iterator it = unvised.begin(); it != unvised.end();)      {       int v = *it;       it++;       if(G[u].count(v)) continue;       dsu.fa[v] = u;       unvised.erase(v);       vis[v] = true;       que.push(v);       rem--;      }     }    }   }   int main()   {    ios::sync_with_stdio(false);    cin >> n >> m;    rem = 1LL * n * (n - 1) / 2 - m;    for(int i = 1; i <= n; i++) unvised.insert(i);    for(int i = 1; i <= m; i++)    {     cin >> e[i].u >> e[i].v >> e[i].w;     G[e[i].u].insert(e[i].v);     G[e[i].v].insert(e[i].u);     x ^= e[i].w;    }    sort(e + 1, e + m + 1);    FindBlocks();     for(int i = 1; i <= m; i++)    {     int fau = dsu.Query(e[i].u), fav = dsu.Query(e[i].v);     if(fau != fav)     {      dsu.fa[fau] = fav;      ans += e[i].w;      type[i] = 1; // type 1     }    }    if(rem > 0) return printf( %lld n , ans) && 0;    for(int i = 1; i <= n; i++) dsu.fa[i] = i;    for(int i = 1; i <= m; i++)    {     int fau = dsu.Query(e[i].u), fav = dsu.Query(e[i].v);     if(fau == fav) continue; // type 2     dsu.fa[fau] = fav;     if(!type[i]) { mn = e[i].w; break; } // type 3    }    printf( %lld n , ans + min(x, mn));    return 0;    }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(nullptr);     int n, k, left = 0, i;     long long int temp;     cin >> n >> k;     vector<int> task(k, 0);     vector<pair<int, int>> idl(n, make_pair(0, 0));     for (i = 0; i < n; i++) {       cin >> temp;       task[temp - 1]++;       idl[i].first = temp;     }     for (i = 0; i < k; i++) left += (int)(task[i] == 0);     for (i = 0; i < n; i++) {       cin >> temp;       if (task[idl[i].first - 1] == 1) temp = INT_MAX;       idl[i].second = temp;     }     if (!left) {       cout << 0 << endl;       return 0;     }     sort(idl.begin(), idl.end(),          [](const pair<int, int> &left, const pair<int, int> &right) {            return left.second < right.second;          });     temp = 0;     for (i = 0; i < n && left; i++) {       if (task[idl[i].first - 1] > 1) {         temp += idl[i].second;         task[idl[i].first - 1]--;         left--;       }     }     cout << temp << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool debug = 0;   int n, m, k;   int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};   string direc =  RDLU ;   long long ln, lk, lm;   void etp(bool f = 0) {     puts(f ?  Possible  :  Impossible );     exit(0);   }   void addmod(int &x, int y, int mod = 1000000007) {     x += y;     if (x >= mod) x -= mod;   }   void et() {     puts( -1 );     exit(0);   }   int x[4], y[4];   pair<int, int> ans[4];   int ansVal = (1 << 30);   void ckeck(int len, int bx, int by) {     int d[4];     pair<int, int> tar[4];     for (int(i) = 0; (i) < (int)(4); (i)++) d[i] = i;     tar[0] = {bx, by};     tar[1] = {bx + len, by};     tar[2] = {bx, by + len};     tar[3] = {bx + len, by + len};     do {       bool ok = 1;       int tmp = 0;       for (int(i) = 0; (i) < (int)(4); (i)++) {         int id = d[i];         if (x[id] != tar[i].first && y[id] != tar[i].second) {           ok = 0;           break;         } else if (x[id] == tar[i].first) {           tmp = max(tmp, abs(y[id] - tar[i].second));         } else           tmp = max(tmp, abs(x[id] - tar[i].first));       }       if (!ok) continue;       if (tmp < ansVal) {         ansVal = tmp;         for (int(i) = 0; (i) < (int)(4); (i)++) ans[d[i]] = tar[i];       }     } while (next_permutation(d, d + 4));   }   void fmain() {     ansVal = (1 << 30);     for (int(i) = 0; (i) < (int)(4); (i)++) scanf( %d%d , x + i, y + i);     set<int> ds;     set<int> px, py;     for (int(i) = 0; (i) < (int)(4); (i)++)       for (int j = i + 1; j < 4; j++) {         if (x[i] != x[j]) ds.insert(abs(x[i] - x[j]));         if (y[i] != y[j]) ds.insert(abs(y[i] - y[j]));       }     for (int d : ds) {       for (int(i) = 0; (i) < (int)(4); (i)++) {         for (int j = -d; j <= d; j += d) {           px.insert(x[i] + j);           py.insert(y[i] + j);         }       }     }     for (int d : ds) {       int id[4];       for (int(i) = 0; (i) < (int)(4); (i)++) id[i] = i;       do {         int mxX = -(1 << 30), miX = (1 << 30), mxY = -(1 << 30), miY = (1 << 30);         int tx[4], ty[4];         tx[0] = x[id[0]];         ty[0] = y[id[0]];         tx[1] = x[id[1]] - d;         ty[1] = y[id[1]];         tx[2] = x[id[2]];         ty[2] = y[id[2]] - d;         tx[3] = x[id[3]] - d;         ty[3] = y[id[3]] - d;         for (int(i) = 0; (i) < (int)(4); (i)++) {           mxX = max(mxX, tx[i]);           miX = min(miX, tx[i]);           mxY = max(mxY, ty[i]);           miY = min(miY, ty[i]);         }         px.insert((mxX + miX) / 2);         py.insert((mxY + miY) / 2);       } while (next_permutation(id, id + 4));     }     for (int d : ds)       for (int xx : px)         for (int yy : py) ckeck(d, xx, yy);     if (ansVal == (1 << 30))       puts( -1 );     else {       printf( %d n , ansVal);       for (int(i) = 0; (i) < (int)(4); (i)++)         printf( %d %d n , ans[i].first, ans[i].second);     }   }   int main() {     int t;     cin >> t;     while (t--) fmain();     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   using namespace std;   void subMain() {     double a, b;     cin >> a >> b;     cout << fixed << (b * b - a * a) / (2 * a);   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     subMain();     cerr <<  Time :   << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC          <<  ms n ;     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /stack:200000000 )   #pragma GCC optimize( Ofast,no-stack-protector )   #pragma GCC target( avx )   using namespace std;   template <class T>   int getbit(T s, int i) {     return (s >> i) & 1;   }   template <class T>   T onbit(T s, int i) {     return s | (T(1) << i);   }   template <class T>   T offbit(T s, int i) {     return s & (~(T(1) << i));   }   template <class T>   int cntbit(T s) {     return __builtin_popcount(s);   }   template <class T>   T gcd(T a, T b) {     T r;     while (b != 0) {       r = a % b;       a = b;       b = r;     }     return a;   }   template <class T>   T lcm(T a, T b) {     return a / gcd(a, b) * b;   }   const int MAXN = 100;   const int MOD = 1e9 + 7;   const long long MAXV = 1e6;   const double eps = 1e-12;   const long long INF = 1e16;   inline string toStr(long long x) {     string tmp =   ;     do tmp = char(x % 10 +  0 ) + tmp;     while (x /= 10);     return tmp;   }   inline long long toInt(string s) {     long long res = 0;     for (auto x : s) res = res * 10 + x -  0 ;     return res;   }   inline string toBinStr(long long x) {     string res =   ;     do res = (x % 2 ?  1  :  0 ) + res;     while (x >>= 1LL);     return res;   }   long long rnd(int k) {     if (!k) return rand() % MAXV + 1;     long long t = rand() % MAXV + 1;     return (rand() % t) + (MAXV - t);   }   long long random_gen(int sign) {     long long x = rnd(rand() % 2);     long long s = rand() % 2;     s = !s ? 1 : -1;     return sign == 1 ? x : sign == -1 ? -x : s * x;   }   inline void debugArray(int a[], int n) {     cerr <<  array =  ;     for (int i = 0; i < n; ++i) cerr << a[i] <<    ;     cerr <<   n ;   }   int n, m;   vector<int> row[MAXN];   bool color[MAXN];   string s[MAXN], actual[MAXN];   int main() {     cin >> n >> m;     for (int i = 0, _a = (n); i < _a; ++i) {       cin >> s[i];       for (int j = 0, _a = (m); j < _a; ++j)         if (s[i][j] ==  # ) row[i].push_back(j);     }     for (int i = 0, _a = (n); i < _a; ++i) {       actual[i] =   ;       for (int j = 0, _a = (m); j < _a; ++j) actual[i] +=  . ;     }     for (int i = 0, _a = (n); i < _a; ++i)       if (!color[i]) {         vector<int> need;         color[i] = true;         need.push_back(i);         for (int j = 0, _a = (n); j < _a; ++j)           if (!color[j])             for (int k = 0, _a = (m); k < _a; ++k)               if (s[i][k] ==  #  && s[j][k] ==  # ) {                 need.push_back(j);                 color[j] = true;                 break;               }         for (auto x : need)           for (auto y : row[i]) actual[x][y] =  # ;       }     bool good = true;     for (int i = 0, _a = (n); i < _a; ++i)       for (int j = 0, _a = (m); j < _a; ++j) good &= actual[i][j] == s[i][j];     puts(good ?  Yes  :  No );   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 1;   int n, k;   int clo[N];   string s;   bool block[N];   int dist(int a, int b) {     if (a > b) swap(a, b);     if (a == -1 || b == n) return n;     return min(b - a, n - (b - a));   }   char neg(char a) {     if (a ==  W )       return  B ;     else       return  W ;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> k >> s;     for (int i = 0; i < n; ++i) {       if (s[i] == s[(i - 1 + n) % n] || s[i] == s[(i + 1) % n]) {         block[i] = 1;       }     }     int cur = -1, l = n, r = -1;     for (int i = 0; i < n; ++i) {       clo[i] = n;       if (block[i]) {         l = min(l, i);         r = max(r, i);       }     }     for (int i = 0; i < n; ++i) {       if (block[i]) {         cur = i;       }       clo[i] = min(clo[i], dist(i, cur));     }     cur = -1;     for (int i = n - 1; i >= 0; --i) {       if (block[i]) {         cur = i;       }       clo[i] = min(clo[i], dist(i, cur));     }     for (int i = 0; i < n; ++i) {       clo[i] = min(clo[i], dist(i, l));       clo[i] = min(clo[i], dist(i, r));     }     for (int i = 0; i < n; ++i) {       if (clo[i] <= k) {         cout << ((clo[i] % 2 == 0) ? s[i] : neg(s[i]));       } else {         cout << ((k % 2 == 0) ? s[i] : neg(s[i]));       }     }   }


#include <bits/stdc++.h>   using namespace std;   struct Node {     int v, index;   } a[100005];   int n, h, big, small, tmp, diff, num;   int ans[100005];   int cmp(const void *i, const void *j) {     Node x = *(Node *)i;     Node y = *(Node *)j;     if (x.v == y.v) {       return x.index > y.index ? 1 : -1;     } else {       return x.v > y.v ? 1 : -1;     }   }   int main() {     while (scanf(  %d %d , &n, &h) != EOF) {       for (int i = 0; i < n; i++) {         scanf(  %d , &a[i].v);         a[i].index = i;       }       qsort(a, n, sizeof(a[0]), cmp);       num = 0, diff = (a[n - 1].v + a[n - 2].v) - (a[0].v + a[1].v);       for (int i = 1; i < n; i++) {         small = a[0].v + a[1].v + h;         if (i >= 2 && small > a[1].v + a[2].v) small = a[1].v + a[2].v;         if (i != n - 1 && small > a[0].v + a[i + 1].v)           small = a[0].v + a[i + 1].v;         if (i == n - 1)           big = a[i].v + a[0].v + h;         else           big = a[n - 1].v + a[i].v + h;         if (big < a[n - 1].v + a[n - 2].v) big = a[n - 1].v + a[n - 2].v;         if (diff > big - small) {           diff = big - small;           num = i;         }       }       fill(ans, ans + n, 1);       for (int i = 1; i <= num; i++) ans[a[i].index] = 2;       printf( %d n , diff);       for (int i = 0; i < n; i++) printf( %d%c , ans[i], i == n - 1 ?   n  :    );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-8;   const double PI = acos(-1.0);   const double e = 2.718281828459;   const int N = 200000;   inline int sgn(double a);   inline long long gcd(long long a, long long b);   inline long long mod_pow(long long x, long long n, long long mod);   vector<int> vv;   vector<int> vis[1005];   int main() {     memset(vis, 0, sizeof(vis));     int n, m;     string s;     string t;     cin >> n >> m;     cin >> s;     cin >> t;     int maxidx = 0;     int maxcount = 0;     for (int i = 0; i <= m - n; i++) {       int count = 0;       for (int j = 0; j < n; j++) {         if (s[j] != t[j + i]) {           vis[i].push_back(j + 1);         } else {           ++count;         }       }       if (maxcount < count) {         maxcount = count;         maxidx = i;       }     }     cout << vis[maxidx].size() << endl;     for (int i = 0; i < vis[maxidx].size(); i++) {       cout << vis[maxidx][i] <<    ;     }     return 0;   }   inline int sgn(double a) { return a < -eps ? -1 : a < eps ? 0 : 1; }   inline long long gcd(long long a, long long b) {     return a == 0 ? b : gcd(b % a, a);   }   long long mod_pow(long long x, long long n, long long mod) {     long long res = 1;     while (n > 0) {       if (n & 1) res = res * x % mod;       x = x * x % mod;       n = n >> 1;     }     return res;   }


#include <bits/stdc++.h>   using namespace std;   const int Maxn = 1e5 + 1e3 + 2;   const int mx = 20;   int n, q, N, ans;   int k[Maxn];   vector<int> V[Maxn];   vector<pair<int, int>> g;   int h[Maxn], par[mx][Maxn];   bool mark[Maxn];   int st[Maxn], en[Maxn], T;   set<pair<int, int>> ver, lca;   void dfs(int u, int DD = 0) {     st[u] = T++;     par[0][u] = DD;     for (int i = 1; i < mx; i++) par[i][u] = par[i - 1][par[i - 1][u]];     for (int i = 0; i < V[u].size(); i++) {       int v = V[u][i];       if (v != DD) h[v] = h[u] + 1, dfs(v, u);     }     en[u] = T++;   }   int LCA(int u, int v) {     if (h[v] < h[u]) swap(u, v);     for (int i = mx; i--;)       if (h[par[i][v]] >= h[u]) v = par[i][v];     if (v == u) return v;     for (int i = mx; i--;)       if (par[i][v] != par[i][u]) v = par[i][v], u = par[i][u];     return par[0][v];   }   bool check() {     bool res = true;     for (int i = 0; i < N; i++) mark[k[i]] = true;     for (int i = 0; i < N; i++)       if (mark[par[0][k[i]]]) res = false;     return res;   }   void solve() {     if (!check()) {       for (int i = 0; i < N; i++) mark[k[i]] = false;       ans = -1;       return;     }     ans = 0;     ver.clear();     lca.clear();     for (int i = 0; i < N; i++) ver.insert(make_pair(st[k[i]], k[i]));     set<pair<int, int>>::iterator it = ver.begin();     for (it++; it != ver.end(); it++) {       int v = (*it).second;       it--;       int u = (*it).second;       it++;       int DD = LCA(u, v);       lca.insert(make_pair(-h[DD], DD));     }     for (; ver.size() > 1;) {       ans++;       pair<int, int> p = (*lca.begin());       lca.erase(p);       int v = p.second;       it = ver.upper_bound(make_pair(st[v], n));       for (; it != ver.end() && ver.size(); it++) {         int u = (*it).second;         if (st[u] > en[v]) break;         if (mark[v]) ans++;         g.push_back(*it);       }       ans -= mark[v];       if (!mark[v] && g.size() < 2) {         g.clear();         ans--;         continue;       }       for (int i = 0; i < g.size(); i++)         ver.erase(g[i]), mark[g[i].second] = false;       g.clear();     }     for (int i = 0; i < N; i++) mark[k[i]] = false;   }   int main() {     cin >> n;     for (int u, v, i = 0; i < n - 1; i++) {       cin >> u >> v;       V[u].push_back(v);       V[v].push_back(u);     }     h[1] = 1;     dfs(1);     cin >> q;     for (int j = 0; j < q; j++) {       cin >> N;       for (int i = 0; i < N; i++) cin >> k[i];       solve();       cout << ans << endl;     }   }


#include <bits/stdc++.h>   using namespace ::std;   int n, m, k, ans;   int a[105][105];   int d[3][105];   int a1[105];   int main() {     scanf( %d %d %d , &n, &m, &k);     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) {         scanf( %d , &a[i][j]);       }     ans = 2140000000;     if (n > 10) {       for (int i = 1; i <= n; i++) {         int an = 0;         for (int j = 1; j <= n; j++) {           int op = 0;           for (int k = 1; k <= m; k++)             if (a[i][k] != a[j][k]) op++;           an += min(op, m - op);         }         ans = min(ans, an);       }     } else {       for (int i = 0; i < (1 << n); i++) {         for (int j = 0; j < n; j++) {           if ((i & (1 << j)) != 0)             a1[j] = 1;           else             a1[j] = 0;         }         int an = 0;         for (int j = 1; j <= m; j++) {           int op = 0;           for (int k = 1; k <= n; k++)             if (a[k][j] != a1[k - 1]) op++;           an += min(op, n - op);         }         ans = min(ans, an);       }     }     if (ans > k)       printf( -1 );     else       printf( %d , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1 << 20;   long long here[N + 100];   int n, m;   long double ter[N + 100];   int go(string &s1, string &s2) {     int val = 0;     for (int i = int(0); i < int(m); ++i)       if (s1[i] == s2[i]) val |= (1 << i);     return val;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout << fixed << setprecision(14);     cin >> n;     vector<string> vec(n);     for (int i = int(0); i < int(n); ++i) cin >> vec[i];     m = int((vec[0]).size());     for (int i = int(0); i < int(n); ++i)       for (int j = int(i + 1); j < int(n); ++j)         if (i != j) {           int mask = go(vec[i], vec[j]);           here[mask] |= (1LL << i) | (1LL << j);         }     int lim = (1 << m) - 1;     for (int mask = int(lim); mask >= int(0); mask--)       for (int i = int(0); i < int(m); ++i) here[mask] |= here[mask | (1 << i)];     ter[lim] = 0;     for (int i = int(lim - 1); i >= int(0); i--) {       ter[i] = __builtin_popcountll(here[i]);       long double val = 0;       for (int j = int(0); j < int(m); ++j)         if (1 - ((i >> j) & 1)) val += ter[i | (1 << j)];       ter[i] += val / (m - __builtin_popcount(i));     }     cout << ter[0] / n << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e6;   int n, k;   int root;   vector<int> G[MAXN + 10];   int res = 0;   int dfs(int u, int p = -1) {     if ((int)G[u].size() == 1) return 0;     vector<int> d;     for (int v : G[u]) {       if (v == p) continue;       d.push_back(dfs(v, u) + 1);     }     sort(d.begin(), d.end(), greater<int>());     while (d.size() > 1) {       int b = d.back();       d.pop_back();       int a = d.back();       d.pop_back();       if (a + b > k) {         res += d.size() + 1;         return b;       } else {         d.push_back(a);       }     }     return d[0];   }   int main() {     scanf( %d%d , &n, &k);     for (int i = 0; i < n - 1; i++) {       int u, v;       scanf( %d%d , &u, &v);       G[u].push_back(v);       G[v].push_back(u);     }     root = 1;     while ((int)G[root].size() == 1) ++root;     dfs(root);     res++;     printf( %d n , res);   }


#include <bits/stdc++.h>   using namespace std;   #pragma comment(linker,  /STACK:64000000 )   int prec[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};   const int mod = 1000000000 + 7;   int n, k;   long long doIt(int m, int bse) {     int b[10];     for (int i = 0; i < 10; i++) b[i] = 0;     int res = 0;     while (!b[m]) {       int can = true;       for (int i = 0; i < m && can; i++) {         int cur = i;         int iter = m + 1;         while (iter && cur) {           cur = b[cur];           iter--;         }         can &= (cur == 0);       }       if (can) res++;       int ind = 0;       b[ind]++;       while (b[ind] >= bse) {         b[ind] = 0;         ind++;         b[ind]++;       }     }     return res % mod;   }   int main() {     cin >> n >> k;     k = min(k, 8);     long long res = 1;     if (k > 1) res = doIt(k, k) % mod;     for (int i = 0; i < n - k; i++) {       res = res * 1LL * (n - k);       res %= mod;     }     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 100000;   int n, a, b;   int scores[MAXN], answer[MAXN];   pair<int, int> tmp_scores[MAXN];   void solve() {     if (a == b) {       for (int i = 0; i < a; ++i) printf( 1  );       for (int i = 0; i < b; ++i) printf( 2  );       printf(  n );       return;     }     if (b < a)       for (int i = 0; i < n; ++i) tmp_scores[i] = make_pair(scores[i], i);     else       for (int i = 0; i < n; ++i) tmp_scores[i] = make_pair(6 - scores[i], i);     sort(&tmp_scores[0], &tmp_scores[n]);     for (int i = 0; i < a; ++i) answer[tmp_scores[i].second] = 1;     for (int i = a; i < n; ++i) answer[tmp_scores[i].second] = 2;     for (int i = 0; i < n; ++i) printf( %d  , answer[i]);     printf(  n );   }   int main() {     scanf( %d%d%d , &n, &a, &b);     for (int i = 0; i < n; ++i) scanf( %d , &scores[i]);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ld = long double;   vector<vector<vector<ll>>> v;   vector<vector<ll>> mat;   vector<vector<ll>> matMal(vector<vector<ll>> mat1, vector<vector<ll>> mat2) {     vector<vector<ll>> mat3((int)(mat1).size(), vector<ll>((int)(mat1).size()));     for (int i = 0; i < (int)(mat1).size(); ++i) {       for (int j = 0; j < (int)(mat1).size(); ++j) {         ll sum = 0;         for (int k = 0; k < (int)(mat1).size(); ++k) {           sum = sum + (ll)mat1[i][k] * mat2[k][j] % 1000000007;         }         mat3[i][j] = sum % 1000000007;       }     }     return mat3;   }   vector<vector<ll>> matMult(vector<vector<ll>> matr, ll x) {     if (x == 1) return matr;     if (x % 2 == 1) return matMal(matMult(matr, x - 1), mat);     vector<vector<ll>> matTemp = matMult(matr, x / 2);     return matMal(matTemp, matTemp);   }   int main() {     int n, k, m;     vector<ll> anzb = {0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4};     cin >> n >> k >> m;     mat.resize((1 << m) * (k + 1), vector<ll>((1 << m) * (k + 1)));     for (int i = 0; i < 1 << m; ++i) {       for (int j = 0; j < k + 1; ++j) {         if (i % 2 == 0) {           mat[(k + 1) * i + j][(k + 1) * (i / 2) + j] = 1;           mat[(k + 1) * i + j][(k + 1) * ((i + (1 << m)) / 2) + j] = 1;         } else if (j != 0) {           mat[(k + 1) * i + j][(k + 1) * (i / 2) + j - 1] = anzb[i / 2] + 1;           mat[(k + 1) * i + j][(k + 1) * ((i + (1 << m)) / 2) + j - 1] =               anzb[(i + (1 << m)) / 2] + 1;         }       }     }     mat = matMult(mat, n);     ll sum = 0;     for (int i = 0; i < 1 << m; ++i) {       sum = (sum + mat[(k + 1) * i + k][0]) % 1000000007;     }     cout << sum << endl;   }


#include <bits/stdc++.h>   using namespace std;   using pii = pair<int, int>;   using ll = long long;   pii operator+(pii& p1, pii& p2) {     return {p1.first + p2.first, p1.second + p2.second};   }   bool isvalidpos(pii& p, int n) {     return p.first >= 0 && p.first < n && p.second >= 0 && p.second < n;   }   int main() {     int n;     cin >> n;     vector<vector<int>> v1(n, vector<int>(n, -1));     vector<vector<int>> v2(n, vector<int>(n, -1));     v1[0][0] = 1;     v1[n - 1][n - 1] = 0;     v2[0][0] = 1;     v2[n - 1][n - 1] = 0;     queue<pii> q;     q.push({0, 0});     pii dyx[] = {{2, 0}, {0, 2}, {1, 1}};     while (!q.empty()) {       pii now = q.front();       q.pop();       for (int i = 0; i < 3; i++) {         pii nxt = now + dyx[i];         if (!isvalidpos(nxt, n)) continue;         if (v1[nxt.first][nxt.second] != -1) continue;         cout <<  ?   << now.first + 1 <<     << now.second + 1 <<                  << nxt.first + 1 <<     << nxt.second + 1 << endl;         cout.flush();         int res;         cin >> res;         if (res == 1)           v2[nxt.first][nxt.second] = v1[nxt.first][nxt.second] =               v1[now.first][now.second];         else           v2[nxt.first][nxt.second] = v1[nxt.first][nxt.second] =               1 - v1[now.first][now.second];         q.push(nxt);       }     }     v1[0][1] = 0;     v2[0][1] = 1;     q.push({0, 1});     while (!q.empty()) {       pii now = q.front();       q.pop();       for (int i = 0; i < 3; i++) {         pii nxt = now + dyx[i];         if (!isvalidpos(nxt, n)) continue;         if (v1[nxt.first][nxt.second] != -1) continue;         cout <<  ?   << now.first + 1 <<     << now.second + 1 <<                  << nxt.first + 1 <<     << nxt.second + 1 << endl;         cout.flush();         int res;         cin >> res;         if (res == 1) {           v2[nxt.first][nxt.second] = v2[now.first][now.second];           v1[nxt.first][nxt.second] = v1[now.first][now.second];         } else {           v2[nxt.first][nxt.second] = 1 - v2[now.first][now.second];           v1[nxt.first][nxt.second] = 1 - v1[now.first][now.second];         }         q.push(nxt);       }     }     for (int i = 1; i < n; i += 2) {       cout <<  ?   << i + 1 <<     << 1 <<     << i + 2 <<     << 2 << endl;       cout.flush();       int res;       cin >> res;       if (res == 1) {         v2[i][0] = v2[i + 1][1];         v1[i][0] = v1[i + 1][1];       } else {         v2[i][0] = 1 - v2[i + 1][1];         v1[i][0] = 1 - v1[i + 1][1];       }     }     bool answer = false;     pii dyx2[][4] = {{{0, 0}, {0, 1}, {0, 2}, {1, 2}},                      {{0, 0}, {0, 1}, {1, 1}, {1, 2}},                      {{0, 0}, {1, 0}, {1, 1}, {1, 2}}};     bool end = false;     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         bool palin1 = false;         bool palin2 = false;         pii now = {i, j};         for (int k1 = 0; k1 < 3; k1++) {           bool check = true;           for (int k2 = 0; k2 < 4; k2++) {             pii nxt = now + dyx2[k1][k2];             if (!isvalidpos(nxt, n)) {               check = false;               break;             }           }           if (!check) continue;           if (v1[now.first + dyx2[k1][0].first]                 [now.second + dyx2[k1][0].second] ==                   v1[now.first + dyx2[k1][3].first]                     [now.second + dyx2[k1][3].second] &&               v1[now.first + dyx2[k1][1].first]                 [now.second + dyx2[k1][1].second] ==                   v1[now.first + dyx2[k1][2].first]                     [now.second + dyx2[k1][2].second])             palin1 = true;           if (v2[now.first + dyx2[k1][0].first]                 [now.second + dyx2[k1][0].second] ==                   v2[now.first + dyx2[k1][3].first]                     [now.second + dyx2[k1][3].second] &&               v2[now.first + dyx2[k1][1].first]                 [now.second + dyx2[k1][1].second] ==                   v2[now.first + dyx2[k1][2].first]                     [now.second + dyx2[k1][2].second])             palin2 = true;         }         if (palin1 || palin2) {           cout <<  ?   << now.first + 1 <<     << now.second + 1 <<                    << now.first + 2 <<     << now.second + 3 << endl;           cout.flush();           int res;           cin >> res;           if (res == 1) {             if (palin1)               answer = true;             else               answer = false;           } else {             if (palin1)               answer = false;             else               answer = true;           }           end = true;           break;         }       }       if (end) break;     }     cout <<  !  << endl;     cout.flush();     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         if (answer)           cout << v1[i][j];         else           cout << v2[i][j];       }       cout << endl;       cout.flush();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[105];   int main() {     int i, n, j = 0, k, l;     cin >> n;     for (i = 0; i < n; i++) {       cin >> a[i];     }     sort(a + 1, a + n);     while (a[0] <= a[n - 1]) {       j++;       a[n - 1]--;       a[0]++;       sort(a + 1, a + n);     }     cout << j << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     cin.tie(NULL);     cout.tie(NULL);     ios_base ::sync_with_stdio(false);     int n;     cin >> n;     vector<pair<long long, long long>> news(n + 1);     for (int i = 1; i <= n; i++) cin >> news[i].first;     for (int i = 1; i <= n; i++) cin >> news[i].second;     long long ans = 0;     priority_queue<long long> q;     sort(news.begin() + 1, news.end());     long long val = news[1].first, sum = 0;     news.push_back(make_pair(2e9, 0));     for (int i = 1; i <= n + 1; i++) {       while (val < news[i].first && q.size() > 0) {         sum -= q.top();         q.pop();         ans += sum;         val++;       }       val = news[i].first;       q.push(news[i].second);       sum += news[i].second;     }     cout << ans;   }