#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline bool chkmin(T &a, const T &b) {     return a > b ? a = b, 1 : 0;   }   template <typename T>   inline bool chkmax(T &a, const T &b) {     return a < b ? a = b, 1 : 0;   }   const int oo = 0x3f3f3f3f;   const int Mod = 1e9 + 7;   const int maxn = 500000;   struct edge {     int id, nxt;     edge() {}     edge(int _id, int _nxt) : id(_id), nxt(_nxt) {}   };   edge e[(maxn << 1) + 5];   int st[maxn + 5], en = 0;   inline void add_edge(int first, int second) {     e[en] = edge(second, st[first]), st[first] = en++;   }   int n;   set<pair<int, int> > all[maxn + 5];   int id[maxn + 5];   int sz[maxn + 5];   int dep[maxn + 5];   int ans = 0;   void dfs(int first, int f = -1) {     id[first] = first;     for (int i = st[first]; i != -1; i = e[i].nxt) {       int second = e[i].id;       if (second == f) continue;       dep[second] = dep[first] + 1;       dfs(second, first);       if (f == -1) {         chkmax(ans, (--all[id[second]].end())->first - 1);         continue;       }       if (sz[first] < sz[second]) swap(id[first], id[second]);       sz[first] += sz[second];       for (auto u : all[id[second]]) {         for (int v = (u.second), _end_ = (u.first); v < _end_; ++v) {           auto t = all[id[first]].lower_bound(make_pair(v, oo));           if (t == all[id[first]].end() || t->second > v)             all[id[first]].insert(make_pair(v + 1, v));           else {             auto t0 = t;             int from = t->second, to = t->first;             while (1) {               auto pre = t0++;               if (t0 == all[id[first]].end()) break;               if (pre->first < t0->second) break;               to = t0->first;             }             all[id[first]].erase(t, t0);             all[id[first]].insert(make_pair(to + 1, from));           }         }       }     }     if (!(int((all[id[first]]).size())))       all[id[first]].insert(make_pair(dep[first] + 1, dep[first])), sz[first] = 1;   }   int main() {     memset(st, -1, sizeof st), en = 0;     scanf( %d , &n);     for (int i = (0), _end_ = (n - 1); i < _end_; ++i) {       int first, second;       scanf( %d%d , &first, &second), --first, --second;       add_edge(first, second), add_edge(second, first);     }     dfs(0);     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int lft[26];   char s[111111], t[111111];   int n, m;   int main() {     gets(s);     n = (int)strlen(s);     for (int i = 0; i < n; ++i) lft[s[i] -  a ]++;     gets(t);     m = (int)strlen(t);     for (int i = 0; i < n; ++i) {       bool fnd = 0;       for (int let = 0; let < 26; ++let) {         if (!lft[let]) continue;         s[i] =  a  + let;         lft[let]--;         int pos = i + 1;         for (int j = 25; j >= 0; --j) {           for (int k = 0; k < lft[j]; ++k) s[pos++] =  a  + j;         }         s[n] = 0;         if (strcmp(s, t) == 1) {           fnd = 1;           break;         }         lft[let]++;       }       if (!fnd) {         cout <<  -1 n ;         return 0;       }     }     puts(s);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int size = 100010;   const int bound = 100;   int n, m, qq;   int res[size], arr[size], father[size];   vector<pair<int, int> > edge[size];   pair<int, int> q[size];   map<int, int> ans[size];   int find(int x) { return father[x] == -1 ? x : father[x] = find(father[x]); }   void merge(int x, int y) {     int xx = find(x), yy = find(y);     if (xx != yy) {       father[xx] = yy;     }   }   void solve() {     for (int c = 1; c <= m; c++) {       for (auto i : edge[c]) {         merge(i.first, i.second);       }       if (edge[c].size() > bound) {         for (int j = 0; j < qq; j++) {           if (find(q[j].first) == find(q[j].second)) {             ++res[j];           }         }       } else {         int num = 0;         for (auto i : edge[c]) {           arr[num++] = i.first;           arr[num++] = i.second;         }         sort(arr, arr + num);         num = unique(arr, arr + num) - arr;         for (int u = 0; u < num; u++) {           for (int v = u + 1; v < num; v++) {             if (find(arr[u]) == find(arr[v])) {               ++ans[arr[u]][arr[v]];             }           }         }       }       for (auto i : edge[c]) {         father[i.first] = father[i.second] = -1;       }     }   }   int main() {     int a, b, c;     memset(father, -1, sizeof(father));     memset(res, 0, sizeof(res));     cin >> n >> m;     for (int i = 0; i < m; i++) {       cin >> a >> b >> c;       edge[c].push_back(make_pair(a, b));     }     cin >> qq;     for (int i = 0; i < qq; i++) {       cin >> q[i].first >> q[i].second;     }     solve();     for (int i = 0; i < qq; i++) {       cout << res[i] +                   max(ans[q[i].first][q[i].second], ans[q[i].second][q[i].first])            << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int h, g, c, n, m, k, l, a[140] = {};     string s;     cin >> s;     n = s.length();     for (int i = 0; i < s.length(); i++) a[s[i]]++;     int res = 0;     for (int i = 0; i <= 139; i++)       if (a[i] > 0) {         res++;       }     if ((res < 2) || (n < 4) || (res > 4)) {       printf( No );       return 0;     }     int kol = res;     if (res == 4) {       printf( Yes );       return 0;     }     res = 0;     for (int i = 0; i <= 139; i++)       if (a[i] > 1) {         res++;       }     if ((kol == 3) && (res > 0)) {       printf( Yes );       return 0;     }     if ((kol == 2) && (res > 1)) {       printf( Yes );       return 0;     }     printf( No );   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 3e5 + 5;   long long a[N];   int32_t tree[N << 2], bit_cnt[N];   struct seg_tree {     long long combine(long long x, long long y) { return max(x, y); }     void build(long long l, long long r, long long node) {       if (l == r) {         tree[node] = bit_cnt[l];         return;       }       long long mid = (l + r) >> 1, lc = node + node, rc = 1 + lc;       build(l, mid, lc);       build(mid + 1, r, rc);       tree[node] = combine(tree[lc], tree[rc]);     }     long long query(long long l, long long r, long long ql, long long qr,                     long long node) {       if (qr < l || r < ql) return 0;       if (ql <= l and r <= qr) {         return tree[node];       }       long long mid = (l + r) >> 1, lc = node + node, rc = 1 + lc;       return combine(query(l, mid, ql, qr, lc), query(mid + 1, r, ql, qr, rc));     }   };   long long dp[N][2];   long long prefix_sum[N];   void solve() {     long long n;     cin >> n;     for (long long i = 1; i <= n; ++i) {       cin >> a[i];       bit_cnt[i] = __builtin_popcountll(a[i]);     }     seg_tree ins;     ins.build(1, n, 1);     for (long long i = 1; i <= n; ++i) {       prefix_sum[i] = bit_cnt[i] + prefix_sum[i - 1];     }     dp[0][0] = 1;     map<long long, long long> mp;     mp[0] = 1;     long long ans = 0;     for (long long i = 1; i <= n; ++i) {       long long c = prefix_sum[i] & 1LL;       dp[i][0] = dp[i - 1][0];       dp[i][1] = dp[i - 1][1];       dp[i][c] += 1;       ans += dp[i - 1][c];       long long res = -1, mx = bit_cnt[i];       long long sum = 0;       for (long long j = i; i - j <= 62 && j > 0; --j) {         mx = max(mx, (long long)bit_cnt[j]);         sum += bit_cnt[j];         if ((sum - mx < mx) && (sum & 1) == 0) {           --ans;         }       }     }     cout << ans <<   n ;   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long t = 1;     for (long long i = 1; i <= t; ++i) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;      int main() {   #ifndef ONLINE_JUDGE    freopen( input.txt ,  r , stdin);    freopen( output.txt ,  w , stdout);   #endif       ios_base::sync_with_stdio(false);    cin.tie(NULL);    cout.tie(NULL);    cout.precision(10);    int t;    cin >> t;    while (t--) {     int n;     cin >> n;     string s;     cin >> s;     int l[n + 1], r[n + 1];     l[0] = 1;     for (int i = 1; i <= n; i++) {      l[i] = 1;      if (i == 1) {       if (s[i - 1] ==  L ) {        l[i] = 2;       }      } else {       if (s[i - 1] ==  L ) {        l[i] = 2;        if (s[i - 2] ==  R ) {         l[i] = 2 + l[i - 2];        }       }      }     }     r[n] = 1;     for (int i = n - 1; i >= 0; i--) {      r[i] = 1;      if (i == n - 1) {       if (s[i] ==  R ) {        r[i] = 2;       }      } else {       if (s[i] ==  R ) {        r[i] = 2;        if (s[i + 1] ==  L ) {         r[i] = 2 + r[i + 2];        }       }      }     }     for (int i = 0; i <= n; i++) {      cout << l[i] + r[i] - 1 <<    ;     }     cout << endl;    }    return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100002;   int n, m, k, currentOutCost[N], cntOut, cntIn;   struct flight {     int i, d, c;   } in[N], out[N];   multiset<int> a[N];   bool cmp(flight x, flight y) { return x.d < y.d; }   int main() {     scanf( %d%d%d , &n, &m, &k);     for (int i = (1); i <= (int)(m); ++i) {       int d, first, t, c;       scanf( %d%d , &d, &first);       scanf( %d%d , &t, &c);       if (first)         out[++cntOut] = {first, d, c};       else         in[++cntIn] = {t, d, c};     }     sort(out + 1, out + 1 + cntOut, cmp);     sort(in + 1, in + 1 + cntIn, cmp);     long long ans = 1000000000000000000ll, currOut = 0, currInSum = 0,               currOutSum = 0, j = 1;     for (int i = (1); i <= (int)(cntIn); ++i) a[in[i].i].insert(in[i].c);     for (int i = (1); i <= (int)(n); ++i)       if (((int)(a[i]).size()))         currInSum += *a[i].begin();       else         return cout << -1, 0;     for (int i = (1); i <= (int)(cntOut); ++i) {       int node = out[i].i, d = out[i].d, c = out[i].c;       while (j <= cntIn and in[j].d <= d + k) {         currInSum -= *a[in[j].i].begin();         a[in[j].i].erase(a[in[j].i].find(in[j].c));         if (!((int)(a[in[j].i]).size())) goto fn;         currInSum += *a[in[j].i].begin();         ++j;       }       if (!currentOutCost[node]) {         ++currOut;         currInSum += currentOutCost[node] = c;       } else {         currInSum -= currentOutCost[node];         currentOutCost[node] = min(currentOutCost[node], c);         currInSum += currentOutCost[node];       }       if (currOut == n) ans = min(ans, currOutSum + currInSum);     }   fn:     cout << (ans == 1000000000000000000ll ? -1 : ans);   }


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


#include <bits/stdc++.h>   using namespace std;   template <class A, class B>   ostream& operator<<(ostream& out, const pair<A, B>& a) {     return out <<  (  << a.first <<  ,   << a.second <<  ) ;   }   template <class A>   ostream& operator<<(ostream& out, const vector<A>& a) {     out <<  [ ;     for (auto it = a.begin(); it != a.end(); ++it) {       if (it != a.begin()) out <<  ,  ;       out << *it;     }     return out <<  ] ;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     long long n, i, j, x, t, y, d, m;     cin >> d;     cin >> n >> m;     vector<pair<pair<long long, long long>, pair<long long, long long>>> a(d);     for (i = 0; i < d; i++)       cin >> a[i].first.first >> a[i].first.second >> a[i].second.first >>           a[i].second.second;     long long cnt_u, cnt_d, cnt_l, cnt_r;     cin >> cnt_u >> cnt_d >> cnt_l >> cnt_r;     vector<long long> vl(100005, 0), vr(100005, 0), vu(100005, 0), vd(100005, 0);     for (i = 0; i < d; i++) {       vu[min(a[i].first.first, a[i].second.first)]++;       vd[max(a[i].first.first, a[i].second.first)]++;       vl[min(a[i].first.second, a[i].second.second)]++;       vr[max(a[i].first.second, a[i].second.second)]++;     }     for (i = 1; i < 100005; i++) {       vu[i] += vu[i - 1];       vl[i] += vl[i - 1];     }     for (i = 100005 - 4; i >= 0; i--) {       vd[i] += vd[i + 1];       vr[i] += vr[i + 1];     }     for (i = 0; i < d; i++) {       vu[min(a[i].first.first, a[i].second.first)]--;       vd[max(a[i].first.first, a[i].second.first)]--;       vl[min(a[i].first.second, a[i].second.second)]--;       vr[max(a[i].first.second, a[i].second.second)]--;       long long x1, x2, y1, y2;       x1 = vu[max(a[i].first.first, a[i].second.first) - 1];       x2 = vd[min(a[i].first.first, a[i].second.first) + 1];       y1 = vl[max(a[i].first.second, a[i].second.second) - 1];       y2 = vr[min(a[i].first.second, a[i].second.second) + 1];       if (x1 == cnt_u && x2 == cnt_d && y1 == cnt_l && y2 == cnt_r) {         cout << i + 1;         return 0;       }       vu[min(a[i].first.first, a[i].second.first)]++;       vd[max(a[i].first.first, a[i].second.first)]++;       vl[min(a[i].first.second, a[i].second.second)]++;       vr[max(a[i].first.second, a[i].second.second)]++;     }     cout <<  -1 ;   }


#include <bits/stdc++.h>   using namespace std;   struct hren {     long int pos, ob, tim;   };   hren down, up, lin, rech, u1, u2, u3, u4;   long long int c, q = 1, f = 1, g = 1;   long int n, j, i, timer = 0, x, y, p = 0;   void pere1(hren &q) {     if (timer == q.tim) {       q.pos = 1;       q.ob = 1;       return;     }     if (timer > q.tim) {       q.pos += 2;       q.ob += q.pos;       return;     }   }   void pere2(hren &q) {     if (timer == q.tim) {       q.pos = 1;       q.ob = 1;       return;     }     if (timer > q.tim) {       q.pos += 1;       q.ob += q.pos;       return;     }   }   void plusq(hren r) {     if (r.ob > 0) q += r.ob;     return;   }   void minusq(hren r) {     if (r.ob > 0) q -= r.ob;     return;   }   int main() {     scanf( %d%d%d%I64d , &n, &x, &y, &c);     down.tim = x;     up.tim = n - x + 1;     rech.tim = y;     lin.tim = n - y + 1;     u1.tim = n - y + x + 1;     u3.tim = n - x + y + 1;     u2.tim = x + y;     u4.tim = 2 * n + 2 - x - y;     while (1) {       if (g >= c) {         printf( %d , timer);         return 0;       }       timer++;       pere1(up);       pere1(down);       pere1(lin);       pere1(rech);       pere2(u1);       pere2(u2);       pere2(u3);       pere2(u4);       p += 4;       f += p;       q = 0;       plusq(up);       plusq(down);       plusq(lin);       plusq(rech);       minusq(u1);       minusq(u2);       minusq(u3);       minusq(u4);       g = f - q;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 2e6, mod = 998244353;   int arr[101];   int n;   bool rot(int idx, int deg) {     deg %= 360;     if (deg < 0) deg += 360;     if (idx == n) return !deg;     return rot(idx + 1, deg + arr[idx]) | rot(idx + 1, deg - arr[idx]);   }   int main() {     cin >> n;     for (int i = 0; i < n; i++) scanf( %d , arr + i);     if (rot(0, 0))       puts( YES );     else       puts( NO );   }


#include <bits/stdc++.h>   char map[55][55];   int main() {     int n, ans = 2147483647;     std::pair<int, int> s, t;     std::queue<std::pair<int, int> > q;     std::vector<std::pair<int, int> > vec1, vec2;     scanf( %d %d %d %d %d , &n, &s.first, &s.second, &t.first, &t.second);     for (int i = 1; i <= n; ++i) scanf( %s , map[i] + 1);     vec1.push_back(s), map[s.first][s.second] =  2 , q.push(s);     while (!q.empty()) {       std::pair<int, int> p = q.front();       q.pop();       std::pair<int, int> temp = std::make_pair(p.first, p.second + 1);       if (temp.second <= n && map[temp.first][temp.second] ==  0 )         map[temp.first][temp.second] =  2 , vec1.push_back(temp), q.push(temp);       temp = std::make_pair(p.first, p.second - 1);       if (temp.second >= 0 && map[temp.first][temp.second] ==  0 )         map[temp.first][temp.second] =  2 , vec1.push_back(temp), q.push(temp);       temp = std::make_pair(p.first + 1, p.second);       if (temp.first <= n && map[temp.first][temp.second] ==  0 )         map[temp.first][temp.second] =  2 , vec1.push_back(temp), q.push(temp);       temp = std::make_pair(p.first - 1, p.second);       if (temp.first >= 0 && map[temp.first][temp.second] ==  0 )         map[temp.first][temp.second] =  2 , vec1.push_back(temp), q.push(temp);     }     if (map[t.first][t.second] ==  2 ) {       putchar( 0 );       return 0;     }     vec2.push_back(t), map[t.first][t.second] =  2 , q.push(t);     while (!q.empty()) {       std::pair<int, int> p = q.front();       q.pop();       std::pair<int, int> temp = std::make_pair(p.first, p.second + 1);       if (temp.second <= n && map[temp.first][temp.second] ==  0 )         map[temp.first][temp.second] =  2 , vec2.push_back(temp), q.push(temp);       temp = std::make_pair(p.first, p.second - 1);       if (temp.second >= 0 && map[temp.first][temp.second] ==  0 )         map[temp.first][temp.second] =  2 , vec2.push_back(temp), q.push(temp);       temp = std::make_pair(p.first + 1, p.second);       if (temp.first <= n && map[temp.first][temp.second] ==  0 )         map[temp.first][temp.second] =  2 , vec2.push_back(temp), q.push(temp);       temp = std::make_pair(p.first - 1, p.second);       if (temp.first >= 0 && map[temp.first][temp.second] ==  0 )         map[temp.first][temp.second] =  2 , vec2.push_back(temp), q.push(temp);     }     for (auto x1 : vec1)       for (auto x2 : vec2)         ans =             std::min(ans, (x2.first - x1.first) * (x2.first - x1.first) +                               (x2.second - x1.second) * (x2.second - x1.second));     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string a, s;     int c(0);     cin >> a >> s;     sort(s.begin(), s.end()), reverse(s.begin(), s.end());     for (int i = 0; i < a.size(); i++) {       if (a[i] < s[c]) a[i] = s[c++];     }     cout << a << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string a;     cin >> a;     char b[101];     int k = 0;     for (int i = 0; i < a.length() - 1; ++i) {       if (a[i] != a[i + 1] || a[i] !=  / ) {         b[k] = a[i];         ++k;       }     }     if ((k == 0) || (a[a.length() - 1] !=  / )) {       b[k] = a[a.length() - 1];       ++k;     }     for (int i = 0; i < k; ++i) cout << b[i];     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long a[1000006];   int main() {     int n;     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i];     sort(a, a + n);     long long score = 0;     for (int i = 0; i < n - 1; i++) score += 1ll * (i + 2) * a[i];     score += a[n - 1] * n;     cout << score << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   typedef long long ll;   typedef double db;   const int mod=1e9+7;   const int N=1e6+11;   const double eps=0.00000001;   bool check(int u,int v){    int a=0,b=0;        for(int i=0;i<31;i++){     if(u>>i&1) a++;        if(v>>i&1) b++;     if(b){           if(!a) return false;       a--,b--;         }    }    return true;   }   void solve(){    int q;    cin>>q;    while(q--){     int u,v;     cin>>u>>v;     if(u<=v&&check(u,v)) cout<< YES n ;       else cout<< NO n ;    }   }   int main(){    ios_base::sync_with_stdio(false);cin.tie(0);    solve();    return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string x, y;     cin >> x >> y;     const auto n = int(x.size());     auto ok = true;     for (auto i = 0; i < n; i++) ok &= y[i] <= x[i];     if (ok)       cout << y << endl;     else       cout << -1 << endl;   }


#include <bits/stdc++.h>   using namespace std;   int n;   int a, b, h, w, ans = INT_MAX, f[int(1e5 + 10)];   bool cmp(int x, int y) { return x > y; }   void get_answ(long long x, long long y, int d, bool flag) {     if (x >= a && y >= b) {       ans = min(ans, d - 1);       return;     }     if (d == n + 1) return;     if ((!flag || f[d] != f[d - 1]) && x < a)       get_answ(1ll * x * f[d], y, d + 1, 0);     if (y < b) get_answ(x, 1ll * y * f[d], d + 1, 1);   }   int main() {     scanf( %d%d%d%d%d , &a, &b, &h, &w, &n);     for (int i = 1; i <= n; i++) scanf( %d , f + i);     sort(f + 1, f + n + 1, cmp);     get_answ(h, w, 1, 0);     get_answ(w, h, 1, 0);     if (ans != INT_MAX)       printf( %d , ans);     else       printf( -1 );   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int Tests = 1;     while (Tests--) {       long long int N;       cin >> N;       vector<long long int> A(N);       for (long long int i = 0; i < N; i++) cin >> A[i];       if (N == 1) cout << A[0] << endl;       if (N == 3) {         sort((A).begin(), (A).end());         cout << A[1] << endl;       }       if (N == 5) {         sort((A).begin(), (A).end());         cout << A[2] << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   long long bigmod(long long b, long long p, long long md) {     if (p == 0) return 1;     if (p % 2 == 1) {       return ((b % md) * bigmod(b, p - 1, md)) % md;     } else {       long long y = bigmod(b, p / 2, md);       return (y * y) % md;     }   }   set<int> vis;   set<int> st[200005];   vector<int> ans;   int cnt;   void dfs(int s) {     cnt++;     for (auto it = vis.begin(); it != vis.end();) {       if (st[s].find(*it) == st[s].end()) {         int node = *it;         vis.erase(node);         dfs(node);         it = vis.lower_bound(node);       } else         it++;     }   }   int main() {     int n, m;     cin >> n >> m;     for (int i = 0; i < m; i++) {       int a, b;       cin >> a >> b;       st[a].insert(b);       st[b].insert(a);     }     for (int i = 1; i <= n; i++) vis.insert(i);     for (int i = 1; i <= n; i++) {       if (vis.find(i) != vis.end()) {         cnt = 0;         vis.erase(i);         dfs(i);         ans.push_back(cnt);       }     }     cout << ans.size() <<   n ;     sort(ans.begin(), ans.end());     for (int i = 0; i < ans.size(); i++) cout << ans[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     ;     long long k, left;     cin >> k;     long long base = k + 1;     vector<long long> v;     v.push_back(-1);     left = base;     for (long long i = 1; i < 2001; i++) {       left++;       if (left > 1000000) {         v.push_back(1000000);         left -= 1000000;       } else {         v.push_back(left);         break;       }     }     cout << v.size() << endl;     for (long long i = 0; i < v.size(); i++) cout << v[i] <<    ;   }


#include <bits/stdc++.h>   using namespace std;   long long jc[100005], fac[12], vp[12], P[12], s, v[100005][12], r[100005][12];   long long n, L, R, p;   long long fpower(long long x, long long k) {     long long ans = 1;     while (k) {       if (k & 1) ans = ans * x % p;       x = x * x % p;       k >>= 1;     }     if (!ans) return p;     return ans;   }   long long c(long long x, long long y) {     long long m[12] = {}, ans = 0;     for (long long i = 1; i <= s; ++i) {       long long o = v[x][i] - v[y][i] - v[x - y][i];       if (o >= vp[i]) continue;       long long q = fpower(fac[i], vp[i] - o);       m[i] =           fpower(fac[i], o) *           (r[x][i] *            fpower(r[y][i] * r[x - y][i] % q, q / fac[i] * (fac[i] - 1) - 1) % q) %           P[i];       ans += m[i] * fpower(p / P[i], P[i] / fac[i] * (fac[i] - 1)) % p;     }     return ans % p;   }   int main() {     scanf( %I64d%I64d%I64d%I64d , &n, &p, &L, &R);     jc[0] = 1;     for (long long i = 1; i <= n; ++i) jc[i] = jc[i - 1] * i % p;     long long t = p;     for (long long i = 2; i * i <= t; ++i) {       if (t % i) continue;       fac[++s] = i;       while (t % i == 0) vp[s]++, t /= i;       P[s] = fpower(fac[s], vp[s]);     }     if (t > 1) fac[++s] = t, vp[s] = 1, P[s] = t;     for (long long i = 1; i <= s; ++i) {       r[0][i] = 1;       for (long long j = 1; j <= n; ++j) {         long long t = j, sum = 0;         while (t % fac[i] == 0) t /= fac[i], sum++;         v[j][i] = v[j - 1][i] + sum, r[j][i] = r[j - 1][i] * t % P[i];       }     }     long long ans = 0;     for (long long i = 0; i <= n; ++i) {       long long o = 0;       if (i - L >= 0) o += c(i, (i - L) / 2);       if (i - R - 1 >= 0) o -= c(i, (i - R - 1) / 2);       ans = (ans + c(n, i) * o) % p;     }     printf( %I64d n , (p + ans % p) % p);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   long long Inv[1000005];   void inv(int n) {     Inv[1] = 1;     for (int i = 2; i <= n; i++) {       Inv[i] = (mod - mod / i * Inv[mod % i] % mod) % mod;     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     long long tot = 1;     for (int i = 1; i < n + 1; i++) {       tot *= i;       tot %= mod;     }     vector<int> v;     for (int i = 0; i < n; i++) {       int add;       cin >> add;       v.push_back(add);     }     inv(n);     sort(v.rbegin(), v.rend());     long long cur = 0;     long long ans = 0;     int last = 0;     int cnt = 0;     for (int i = 0; i < n; i++) {       if (v[i] == last) {         cur++;         cnt++;         continue;       }       if (last != v[0]) {         ans += tot * last % mod * Inv[cur] % mod * cnt % mod;         ans %= mod;       }       cur++;       cnt = 1;       last = v[i];     }     if (last != v[0]) {       ans += tot * last % mod * Inv[cur] % mod * cnt % mod;       ans %= mod;     }     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int f[100][300] = {0};   int main() {     std::ios::sync_with_stdio(false);     string s1, s2;     cin >> s1 >> s2;     int t1 = 0, t2 = 0, q = 0;     for (int i = 0; i < s1.length(); i += 1) {       if (s1[i] ==  + )         t1++;       else         t1--;     }     for (int i = 0; i < s2.length(); i += 1) {       if (s2[i] ==  + )         t2++;       else if (s2[i] ==  - )         t2--;       else         q++;     }     int w = t1 - t2;     int dta = 20;     f[0][dta] = 1;     for (int i = 1; i <= q; i += 1) {       for (int j = -10; j <= 10; j += 1) {         f[i][j + dta] = f[i - 1][j + dta - 1] + f[i - 1][j + dta + 1];       }     }     double ans = f[q][w + dta] / double(1 << q);     cout << fixed << setprecision(12) << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 15;   struct tree {     int l, r, sum;     tree *left, *right;     tree(int L, int R, int val) {       l = L, r = R, sum = val;       left = right = NULL;     }   };   tree *pq[N], *db[N];   tree *update(tree *cur, int l, int r, int ind, int add) {     tree *ret = new tree(l, r, 0);     ret->sum += cur->sum + add;     if (l == r) {       ret->sum = cur->sum;       ret->sum += add;       return ret;     }     int mid = (l + r) / 2;     if (ind <= mid) {       if (!cur->left) {         cur->left = new tree(l, mid, 0);       }       ret->right = cur->right;       ret->left = update(cur->left, l, mid, ind, add);     } else {       if (!cur->right) {         cur->right = new tree(mid + 1, r, 0);       }       ret->right = update(cur->right, mid + 1, r, ind, add);       ret->left = cur->left;     }     return ret;   }   int getval(tree *cur, int l, int r, int ind) {     if (l == r) {       return cur->sum;     }     int mid = (l + r) / 2;     if (ind <= mid) {       if (!cur->left) return 0;       return getval(cur->left, l, mid, ind);     } else {       if (!cur->right) return 0;       return getval(cur->right, mid + 1, r, ind);     }   }   int count(tree *cur, int l, int r, int ind) {     if (cur == NULL) return 0;     if (ind < l) {       return 0;     }     if (r <= ind) {       return cur->sum;     }     int mid = (l + r) / 2;     int ret = 0;     if (cur->left) ret = count(cur->left, l, mid, ind);     if (cur->right) ret += count(cur->right, mid + 1, r, ind);     return ret;   }   map<string, int> Hash;   int main() {     int q, i;     string s, name;     int pos = 1;     int x;     cin >> q;     int n = 1e5;     int m = 1e9;     int C = 0, v;     pq[C] = new tree(1, n, -1);     db[C] = new tree(1, m, 0);     while (q--) {       cin >> s;       if (s[0] ==  u ) {         scanf( %d , &x);         pq[C + 1] = pq[C - x];         db[C + 1] = db[C - x];       } else {         cin >> name;         if (!Hash.count(name)) {           Hash[name] = pos++;         }         int id = Hash[name];         if (s[0] ==  s ) {           scanf( %d , &x);           v = getval(pq[C], 1, n, id);           if (v != 0) {             pq[C + 1] = update(pq[C], 1, n, id, -v + x);             db[C + 1] = update(db[C], 1, m, v, -1);             db[C + 1] = update(db[C + 1], 1, m, x, 1);           } else {             pq[C + 1] = pq[C], db[C + 1] = db[C];             pq[C + 1] = update(pq[C + 1], 1, n, id, x);             db[C + 1] = update(db[C + 1], 1, m, x, 1);           }         } else if (s[0] ==  q ) {           pq[C + 1] = pq[C];           db[C + 1] = db[C];           v = getval(pq[C + 1], 1, n, id);           if (v != 0) {             printf( %d n , count(db[C + 1], 1, m, v - 1));           } else             printf( -1 n );         } else {           pq[C + 1] = pq[C];           db[C + 1] = db[C];           v = getval(pq[C + 1], 1, n, id);           if (v != 0) {             pq[C + 1] = update(pq[C + 1], 1, n, id, -v);             db[C + 1] = update(db[C + 1], 1, m, v, -1);           }         }       }       ++C;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     std::ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int a, b;     cin >> a >> b;     vector<long long int> m;     vector<long long int> n;     set<long long int> s;     m.push_back(1);     n.push_back(1);     if (a == 1) s.insert(1);     for (long long int i = 1; i <= b;) {       i = i * 2;       m.push_back(i);       if (i >= a && i <= b) s.insert(i);     }     for (long long int i = 1; i <= b;) {       i = i * 3;       n.push_back(i);       if (i >= a && i <= b) s.insert(i);     }     for (int i = 0; i < m.size(); i++) {       for (int j = 0; j < n.size(); j++) {         long long int x = m[i] * n[j];         if (x >= a && x <= b) {           s.insert(x);         }       }     }     cout << s.size() << endl;   }


#include <bits/stdc++.h>   using namespace std;   void rd(int &x) {     x = 0;     int f = 1;     char ch = (getchar());     while (!isdigit(ch)) {       if (ch ==  - ) f = -1;       ch = (getchar());     }     while (isdigit(ch)) x = x * 10 + ch -  0 , ch = (getchar());     x *= f;   }   const int N = 5e5 + 5;   int n, m;   int a[N], c[N], tmp[N];   priority_queue<int, vector<int>, greater<int> > Q;   int main() {     rd(n);     long long ans = 0;     for (int i = 1; i <= n; ++i) rd(a[i]), ans += a[i];     sort(a + 1, a + n + 1, greater<int>());     for (int i = 1; i <= n; ++i) {       int j = i;       a[++m] = a[i];       while (j <= n && a[j + 1] == a[i]) ++j;       c[m] = j - i + 1, i = j;     }     n = m;     int cnt = 0, tmp0 = 0;     for (int i = 1; i <= n; ++i) {       int res = min(cnt - 2 * (int)Q.size(), c[i]),           ok = min(c[i] - res, cnt - res);       tmp0 = 0;       for (int j = 1; j <= res; ++j) tmp[++tmp0] = a[i];       for (int j = 1; j <= ok; j += 2) {         int val = Q.top();         Q.pop();         if (val < a[i]) {           tmp[++tmp0] = a[i];           if (ok - j) tmp[++tmp0] = a[i];         } else {           tmp[++tmp0] = val;           if (ok - j && 2 * a[i] - val > 0) tmp[++tmp0] = 2 * a[i] - val;         }       }       for (int j = 1; j <= tmp0; ++j) Q.push(tmp[j]);       cnt += c[i];     }     while (!Q.empty()) ans -= Q.top(), Q.pop();     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, A[105], B[105], w, ans, tmp;   int main() {     scanf( %d , &n);     n *= 2;     for (int i = (0); i < (n); i++) scanf( %d , &A[i]);     sort(A, A + n);     ans = 123412345;     for (int i = (0); i < (n); i++)       for (int j = (i + 1); j < (n); j++) {         w = 0;         for (int k = (0); k < (n); k++) {           if (k == i || k == j) continue;           B[w++] = A[k];         }         tmp = 0;         for (int k = 0; k < w; k += 2) tmp += B[k + 1] - B[k];         ans = min(ans, tmp);       }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 100;   vector<int> g[maxn];   int father[maxn];   int a[maxn];   int findfather(int x) {     int a = x;     while (x != father[x]) x = father[x];     while (a != father[a]) {       int z = a;       a = father[a];       father[z] = x;     }     return x;   }   int main() {     int n, m;     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       g[a[i]].push_back(i);     }     int wjm = n;     for (int i = 1; i <= m; i++) father[i] = i;     for (int i = 2; i <= n; i++)       if (a[i - 1] == a[i]) wjm--;     printf( %d n , wjm - 1);     for (int i = 1; i < m; i++) {       int x, y;       scanf( %d%d , &x, &y);       int faX = findfather(x);       int faY = findfather(y);       if (g[faX].size() > g[faY].size()) swap(faX, faY);       for (int j : g[faX]) {         if (j + 1 <= n && a[j + 1] == faY) wjm--;         if (j - 1 >= 1 && a[j - 1] == faY) wjm--;         g[faY].push_back(j);       }       for (int j : g[faX]) a[j] = faY;       father[faX] = faY;       printf( %d n , wjm - 1);     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 5, INF = 0x3f3f3f3f;   int a[maxn];   int last[maxn];   int main() {     int n;     while (cin >> n) {       memset(last, INF, sizeof(last));       for (int i = 0; i < n; i++) {         cin >> a[i];         last[a[i]] = i;       }       sort(last, last + maxn);       cout << a[last[0]] << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char seat[10][1005];   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n;     cin >> n;     int mark = 2000;     int flag;     for (int i = 0; i < n; i++) {       cin >> seat[0][i] >> seat[1][i] >> seat[2][i] >> seat[3][i] >> seat[4][i];       if (seat[0][i] ==  O  && seat[1][i] ==  O ) {         mark = i;         flag = 0;       }       if (seat[3][i] ==  O  && seat[4][i] ==  O ) {         mark = i;         flag = 3;       }     }     if (mark == 2000)       cout <<  NO  << endl;     else {       seat[flag][mark] =  + ;       seat[flag + 1][mark] =  + ;       cout <<  YES  << endl;       for (int i = 0; i < n; i++) {         cout << seat[0][i] << seat[1][i] << seat[2][i] << seat[3][i] << seat[4][i]              << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   vector<int> dp[2001][26];   int q[2000];   pair<int, int> ans[2001][2001];   int nxt[2001][26];   pair<int, int> jump(pair<int, int> p, char c) {     if (p.first < m) {       p.second = dp[q[p.first]][c -  a ][p.second];       if (p.second == -1) {         p.first = nxt[p.first + 1][c -  a ];         if (p.first < m) p.second = dp[q[p.first]][c -  a ][0];       }     }     return p;   }   int main() {     ios::sync_with_stdio(false);     cin >> n;     for (int i = 0; i < n; ++i) {       string s;       cin >> s;       for (int j = 0; j < 26; ++j) {         dp[i][j].resize(s.size() + 1);         dp[i][j][s.size()] = -1;         for (int k = s.size() - 1; k >= 0; --k)           dp[i][j][k] = s[k] == j +  a  ? k + 1 : dp[i][j][k + 1];       }     }     cin >> m;     for (int i = 0; i < m; ++i) cin >> q[i], q[i]--;     for (int i = 0; i < 26; ++i) {       nxt[m][i] = m;       for (int j = m - 1; j >= 0; --j)         nxt[j][i] = dp[q[j]][i][0] == -1 ? nxt[j + 1][i] : j;     }     string s;     cin >> s;     for (int i = 0; i <= s.size(); ++i)       for (int j = 0; j <= s.size(); ++j) ans[i][j] = make_pair(1e9, 1e9);     ans[0][0] = make_pair(0, 0);     for (int i = 1; i <= s.size(); ++i)       for (int j = 0; j <= i; ++j) {         ans[i][j] = min(ans[i][j], ans[i - 1][j]);         if (j) ans[i][j] = min(ans[i][j], jump(ans[i - 1][j - 1], s[i - 1]));       }     for (int i = s.size(); i >= 0; --i)       if (ans[s.size()][i].first < m) {         cout << i <<   n ;         break;       }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, k, a, ans, i, b[10000000];   string s, s1;   int main() {     cin >> n >> s;     s1 =  0 ;     s1 += s;     s1 +=  0 ;     s = s1;     a = s.find( 11 );     if (a < 10000) return cout <<  No , 0;     a = s.find( 000 );     if (a < 10000) return cout <<  No , 0;     cout <<  Yes ;   }


#include <bits/stdc++.h>   const long double eps = 1e-9;   const double pi = acos(-1.0);   const long long inf = 1e18;   using namespace std;   int a[33], b[33], p[33], k[33], n, r, u, tt[33], z[33], back[33];   int cnt = 0;   long long ans = -inf;   void update(int step) {     int left = (u - step) % 2;     long long now = 0;     if (left == 0)       for (int i = 1; i <= n; i++) now += 1ll * k[i] * a[i];     if (left == 1)       for (int i = 1; i <= n; i++) now += 1ll * k[i] * (a[i] ^ b[i]);     ans = max(ans, now);   }   void rec(int pos) {     if (pos == u + 1) return;     for (int i = ((z[pos - 1] + 1) & 1); i < 2; i++) {       z[pos] = i;       if (i == 0) {         for (int i = 1; i <= n; i++) a[i] = a[i] ^ b[i];       }       if (i == 1) {         for (int i = 1; i <= n; i++) tt[i] = a[p[i]];         for (int i = 1; i <= n; i++) a[i] = tt[i] + r;       }       update(pos);       rec(pos + 1);       if (i == 0) {         for (int i = 1; i <= n; i++) a[i] = a[i] ^ b[i];       }       if (i == 1) {         for (int i = 1; i <= n; i++) tt[i] = a[back[i]];         for (int i = 1; i <= n; i++) a[i] = tt[i] - r;       }     }   }   int main(int argc, const char* argv[]) {     cin >> n >> u >> r;     for (int i = 1; i <= n; i++) cin >> a[i];     for (int i = 1; i <= n; i++) cin >> b[i];     for (int i = 1; i <= n; i++) cin >> k[i];     for (int i = 1; i <= n; i++) cin >> p[i];     for (int i = 1; i <= n; i++) back[p[i]] = i;     z[0] = 1;     rec(1);     cout << ans;     return 0;   }


#include <bits/stdc++.h>   const int INF = 0x3f3f3f3f;   using namespace std;   void file(bool opt) {     if (opt && fopen( in.txt ,  r ))       freopen( in.txt ,  r , stdin), freopen( out.txt ,  w , stdout);   }   struct node {     double x, y;   } point[100000 + 5], tu[100000 + 5];   int tot = 0;   int n;   double multi(node p0, node p1, node p2) {     return (p1.x - p0.x) * (p2.y - p0.y) - (p2.x - p0.x) * (p1.y - p0.y);   }   double dis(node a, node b) {     return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y);   }   bool cmp(node a, node b) {     double x = multi(a, b, point[1]);     if (x > 0 || (x == 0 && dis(a, point[1]) < dis(b, point[1]))) return 1;     return 0;   }   void Graham() {     int k = 1;     for (int i = 1; i <= n; i++)       if (point[i].y < point[k].y ||           (point[i].y == point[k].y && point[i].x < point[k].x))         k = i;     swap(point[1], point[k]);     sort(point + 2, point + 1 + n, cmp);     tot = 2, tu[1] = point[1], tu[2] = point[2];     for (int i = 3; i <= n; i++) {       while (tot >= 1 && multi(tu[tot], tu[tot - 1], point[i]) >= 0) tot--;       tu[++tot] = point[i];     }   }   int main() {     file(1);     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %lf%lf , &point[i].x, &point[i].y);       point[i].y = point[i].y - point[i].x * point[i].x;     }     if (n == 1) {       puts( 0 );       return 0;     }     Graham();     int ans = 0;     for (int i = 1; i <= tot; i++) {       node a = tu[i], b = tu[(i + 1) > tot ? 1 : (i + 1)],            c = {0, (long long)1e15};       if (a.x != b.x) {         double x = multi(a, b, c);         if (x < 0) ans++;       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   namespace Work {   const int kMaxN = 100010;   multiset<int> set;   int n;   int a[kMaxN], b[kMaxN];   int pos[kMaxN];   void solve(FILE* fin, FILE* fout) {     fscanf(fin,  %d , &n);     for (int i = 1; i <= n; i++) {       fscanf(fin,  %d , a + i);       pos[a[i]] = i;     }     for (int i = 1; i <= n; i++) {       fscanf(fin,  %d , b + i);       set.insert(i - pos[b[i]]);     }     multiset<int>::iterator it = set.lower_bound(0);     int x = *it, y = x;     if (it != set.begin()) {       it--;       y = *it;     }     fprintf(fout,  %d n , min(abs(x), abs(y)));     for (int dt = 1; dt < n; dt++) {       set.erase(set.find(dt - pos[b[dt]]));       set.insert(n - pos[b[dt]] + dt);       it = set.lower_bound(dt);       x = *it, y = x;       if (it != set.begin()) {         it--;         y = *it;       }       fprintf(fout,  %d n , min(abs(x - dt), abs(y - dt)));     }     return;   }   }  // namespace Work   int main() {     Work::solve(stdin, stdout);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string x, y;     cin >> x >> y;     int sum = atoi(x.c_str()) + atoi(y.c_str());     int p = 0, now = 1;     for (; sum; sum /= 10) {       if (sum % 10 != 0) {         p += (sum % 10) * now;         now *= 10;       }     }     x.erase(remove(x.begin(), x.end(),  0 ), x.end());     y.erase(remove(y.begin(), y.end(),  0 ), y.end());     int X = atoi(x.c_str()), Y = atoi(y.c_str());     if (X + Y == p)       cout <<  YES  << endl;     else       cout <<  NO  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<pair<int, int> > vec(n);     vector<int> x(n);     vector<int> y(n);     for (int i = 0; i < n; i++) {       cin >> x[i] >> y[i];       vec[i].first = x[i];       vec[i].second = y[i];     }     long long ans = 0;     sort(x.begin(), x.end());     long long count = 1;     for (int i = 1; i < n; i++) {       if (x[i] != x[i - 1]) {         ans += (count * (count - 1)) / 2;         count = 0;       }       count++;     }     ans += (count * (count - 1)) / 2;     sort(y.begin(), y.end());     count = 1;     for (int i = 1; i < n; i++) {       if (y[i] != y[i - 1]) {         ans += (count * (count - 1)) / 2;         count = 0;       }       count++;     }     ans += (count * (count - 1)) / 2;     sort(vec.begin(), vec.end());     count = 1;     for (int i = 1; i < n; i++) {       if (vec[i].first != vec[i - 1].first ||           vec[i].second != vec[i - 1].second) {         ans -= (count * (count - 1)) / 2;         count = 0;       }       count++;     }     ans -= (count * (count - 1)) / 2;     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   int n;   int main() {     cin >> n;     int ans = 0;     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++) {         int a;         cin >> a;         if (i == j || i + j == n - 1 || i == n / 2 || j == n / 2) ans += a;       }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     if (n == 1)       cout << -1 <<   n ;     else       cout << n <<     << n + 1 <<     << n * 1LL * (n + 1) <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   vector<string> split(const string& s, char c) {     vector<string> v;     stringstream ss(s);     string x;     while (getline(ss, x, c)) v.emplace_back(x);     return move(v);   }   void err(vector<string>::iterator it) {}   template <typename T, typename... Args>   void err(vector<string>::iterator it, T a, Args... args) {     cerr << it->substr((*it)[0] ==    , it->length()) <<   =   << a <<   n ;     err(++it, args...);   }   int check(int x, int l) { return x >= 0 && x < l; }   int solve(vector<string> board, string per, string comm) {     int startx, starty, endx, endy;     int r, c;     r = board.size();     c = board[0].size();     for (int i = 0; i < r; i++) {       for (int j = 0; j < c; j++) {         if (board[i][j] ==  S ) {           startx = i;           starty = j;         } else if (board[i][j] ==  E ) {           endx = i;           endy = j;         }       }     }     int cx, cy;     cx = startx;     cy = starty;     int i = 0;     while (check(cx, r) && check(cy, c)) {       int t = comm[i] -  0 ;       i++;       if (i > comm.length()) return 0;       if (per[t] ==  U )         cy--;       else if (per[t] ==  D )         cy++;       else if (per[t] ==  L )         cx--;       else if (per[t] ==  R )         cx++;       if (!check(cx, r) || !check(cy, c)) return 0;       if (board[cx][cy] ==  E ) return 1;       if (board[cx][cy] ==  # ) return 0;     }     return 0;   }   int main() {     int n, m;     cin >> n >> m;     vector<string> board;     string comm;     for (int i = 0; i < n; i++) {       string temp;       cin >> temp;       board.push_back(temp);     }     cin >> comm;     string per =  DLRU ;     int ans = 0;     while (1) {       ans += solve(board, per, comm);       bool x = next_permutation(per.begin(), per.end());       if (!x) break;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long oo = 1e16;   template <class P>   P gcd(P a, P b) {     return b ? gcd(b, a % b) : a;   };   long long read() {     char c = getchar();     long long d = 0, f = 1;     for (; c <  0  || c >  9 ; c = getchar())       if (c ==  - ) f = -1;     for (; c >=  0  && c <=  9 ; d = d * 10 + c - 48, c = getchar())       ;     return d * f;   }   const int N = 100001;   const int M = 400001;   const int mod = 1e9 + 7;   int n, m, cnt, cyc_amount, head[N];   long long cyc_tot, ans, qz[N], _m2[201], record[62], f[62][2];   bool exist[N];   struct xint {     int to, next;     long long s;   } e[M];   inline void addedge(int x, int y, long long s) {     e[++cnt].to = y;     e[cnt].next = head[x];     e[cnt].s = s;     head[x] = cnt;   }   inline void dfs(int fa, int x, long long s) {     exist[x] = 1;     for (int i = 0; i <= 61; i++) f[i][s >> i & 1]++;     qz[x] = s;     for (int i = head[x]; i; i = e[i].next) {       int y = e[i].to;       if (y == fa) continue;       if (!exist[y])         dfs(x, y, s ^ e[i].s);       else {         long long t = qz[x] ^ qz[y] ^ e[i].s;         cyc_tot |= t;         for (int i = 61; i >= 0; i--) {           if ((t & (1LL << i)) && !record[i]) {             record[i] = t;             cyc_amount++;             break;           }           t = min(t, t ^ record[i]);         }       }     }   }   int main() {     n = read(), m = read();     for (int i = 1; i <= n; i++) exist[i] = 1;     for (int i = 1; i <= m; i++) {       int x = read(), y = read();       long long s = read();       exist[x] = exist[y] = 0;       addedge(x, y, s);       addedge(y, x, s);     }     _m2[0] = 1;     for (int i = 1; i <= 200; i++) _m2[i] = _m2[i - 1] * 2 % mod;     for (int i = 1; i <= n; i++)       if (!exist[i]) {         cyc_amount = cyc_tot = 0;         for (int j = 0; j <= 61; j++) f[j][0] = f[j][1] = record[j] = 0;         memset(qz, 0, sizeof qz);         dfs(0, i, 0);         for (int j = 0; j <= 61; j++)           if (cyc_tot & (1LL << j))             ans = (ans + (f[j][0] + f[j][1]) * (f[j][0] + f[j][1] - 1) / 2 % mod *                              _m2[j + cyc_amount - 1] % mod) %                   mod;           else             ans =                 (ans + f[j][0] * f[j][1] % mod * _m2[j + cyc_amount] % mod) % mod;       }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int maxRounds = 200000;   double p[110], ans, pw[110][maxRounds + 10];   int times[110], n;   int main() {     cin >> n;     if (n == 1) {       cout << 1;       return 0;     }     for (int i = 1; i <= n; ++i) {       int first;       cin >> first;       p[i] = first / 100.0;     }     double initProd = 1;     for (int i = 1; i <= n; ++i) {       initProd *= p[i];       pw[i][0] = 1;       times[i] = 1;       for (int j = 1; j <= maxRounds; ++j) {         pw[i][j] = pw[i][j - 1] * (1 - p[i]);       }     }     ans += initProd * n;     for (int round = n + 1; round <= maxRounds; ++round) {       double best = 0;       int besti = 1;       double prod = 1;       for (int j = 1; j <= n; ++j) prod *= (1 - pw[j][times[j]]);       for (int j = 1; j <= n; ++j) {         double current = prod / (1 - pw[j][times[j]]) * pw[j][times[j]] * p[j];         if (current > best) {           besti = j;           best = current;         }       }       ans += best * round;       times[besti]++;     }     cout << fixed << setprecision(8) << ans;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long a, b, f, k;     scanf( %lld %lld %lld %lld , &a, &b, &f, &k);     long long ans = 0;     long long cfuel = b;     for (int i = 0; i < k - 1; i++) {       if (i % 2 == 0) {         if (cfuel >= 2 * a - f) {           cfuel -= a;         } else if (cfuel >= f && b >= a - f) {           ans++;           cfuel = b - (a - f);         } else {           printf( -1 n );           return 0;         }       } else {         if (cfuel >= a + f) {           cfuel -= a;         } else if (cfuel >= a - f && b >= f) {           ans++;           cfuel = b - f;         } else {           printf( -1 n );           return 0;         }       }     }     if (k % 2) {       if (cfuel >= a) {       } else if (cfuel >= f && b >= a - f) {         ans++;       } else {         printf( -1 n );         return 0;       }     } else {       if (cfuel >= a) {       } else if (cfuel >= a - f && b >= f) {         ans++;       } else {         printf( -1 n );         return 0;       }     }     printf( %lld n , ans);   }


#include <bits/stdc++.h>   using namespace std;   void rs(int &x) { scanf( %d , &x); }   void rsl(long long &x) { scanf( %I64d , &x); }   void rsd(double &x) { scanf( %lf , &x); }   void rss(char *str) { scanf( %s , str); }   void ws(int &x) { printf( %d  , x); }   void wsl(long long &x) { printf( %I64d  , x); }   void wsd(double &x) { printf( %lf  , x); }   void wss(char *str) { printf( %s  , str); }   long long gcd(long long a, long long b) {     if (a == 0) return b;     return gcd(b % a, a);   }   int const N = (2e5) + 5;   int const mod = (1e9) + 7;   int a[N], t[N], suma[N], sumt[N];   priority_queue<int> que;   set<pair<int, int>> ms, mns;   map<int, int> mm;   int ins[N], inns[N];   int main() {     int n, w, k;     cin >> n >> w >> k;     for (int i = 1; i <= n; ++i) {       cin >> a[i];       suma[i] = suma[i - 1] + a[i];     }     for (int i = 1; i <= n; ++i) {       cin >> t[i];       mm[t[i]] = i;       sumt[i] = sumt[i - 1] + t[i];     }     int ans = 0;     int r = 1;     int ct = 0;     int cp = 0;     for (int i = 1; i <= n; ++i) {       r = max(r, i);       while (r <= n) {         int dt = 0;         if (ms.size() < w) {           dt = t[r] / 2 + t[r] % 2;           if (ct + dt <= k) {             ms.insert(make_pair(t[r], r));             ins[r] = 1;             ct += dt;           } else {             break;           }         } else {           int var = ms.begin()->first;           if (t[r] > var) {             int dt = t[r] / 2 + t[r] % 2;             int ddt = (var / 2);             if (ct + dt + ddt <= k) {               ins[ms.begin()->second] = 0;               ins[r] = 1;               mns.insert(*ms.begin());               ms.erase(ms.begin());               ms.insert(make_pair(t[r], r));               ct += dt + ddt;             } else {               break;             }           } else {             int dt = t[r];             if (ct + dt <= k) {               ct += dt;               mns.insert(make_pair(t[r], r));             } else {               break;             }           }         }         r++;       }       ans = max(suma[r - 1] - suma[i - 1], ans);       if (ins[i] == 0) {         ct -= t[i];       } else {         ct -= (t[i] / 2 + t[i] % 2);         ins[i] = 0;         set<pair<int, int>>::iterator it = ms.find(make_pair(t[i], i));         if (it != ms.end()) {           ms.erase(it);         }         while (mns.size() > 0 && ((--mns.end())->second <= i)) {           mns.erase(--mns.end());         }         if (mns.size() > 0) {           it = --mns.end();           ct -= ((it->first) / 2);           ins[it->second] = 1;           ms.insert(*(--mns.end()));           mns.erase((--mns.end()));         }       }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int generateb(int a, long int nos[], long int noa[], long int nob[]) {     int i, minb = 100002;     for (i = 0; i < 26; i++) {       nos[i] = nos[i] - (noa[i] * a);     }     for (i = 0; i < 26; i++) {       if (nob[i] != 0) {         if (nos[i] / nob[i] < minb) {           minb = nos[i] / nob[i];         }       }     }     return minb;   }   int generatea(int b, long int nos[], long int noa[], long int nob[]) {     int i, mina = 100002;     for (i = 0; i < 26; i++) {       nos[i] = nos[i] - (nob[i] * b);     }     for (i = 0; i < 26; i++) {       if (noa[i] != 0) {         if (nos[i] / noa[i] < mina) {           mina = nos[i] / noa[i];         }       }     }     return mina;   }   int main() {     char s[100010], a[100010], b[100010];     long int nos[26] = {0}, i, lens = 0, noa[26] = {0}, nob[26] = {0}, lena = 0,              lenb = 0, j, nos1[26] = {0}, mina = 100002, counta, countb, max = -1,              maxa, maxb, minb = 100002, r;     cin >> s >> a >> b;     for (i = 0; s[i] !=   0 ; i++) {       nos[s[i] -  a ]++;       lens++;     }     for (j = 0; j < 26; j++) {       nos1[j] = nos[j];     }     for (i = 0; a[i] !=   0 ; i++) {       noa[a[i] -  a ]++;       lena++;     }     for (i = 0; b[i] !=   0 ; i++) {       nob[b[i] -  a ]++;       lenb++;     }     for (i = 0; i < 26; i++) {       if (noa[i] != 0) {         if (nos[i] / noa[i] < mina) {           mina = nos[i] / noa[i];         }       }     }     for (i = 0; i <= mina; i++) {       countb = generateb(i, nos, noa, nob);       for (j = 0; j < 26; j++) {         nos[j] = nos1[j];       }       if (i + countb > max) {         max = i + countb;         maxa = i;         maxb = countb;       }     }     for (i = 0; i < 26; i++) {       if (nob[i] != 0) {         if (nos[i] / nob[i] < minb) {           minb = nos[i] / nob[i];         }       }     }     for (i = 0; i <= minb; i++) {       counta = generatea(i, nos, noa, nob);       for (j = 0; j < 26; j++) {         nos[j] = nos1[j];       }       if (i + counta > max) {         max = i + counta;         maxb = i;         maxa = counta;       }     }     for (i = 0; i < maxa; i++) {       cout << a;     }     for (i = 0; i < maxb; i++) {       cout << b;     }     for (i = 0; i < 26; i++) {       nos[i] = nos[i] - (maxa * noa[i]) - (maxb * nob[i]);     }     for (i = 0; i < 26; i++) {       for (j = 0; j < nos[i]; j++) {         cout << char(i +  a );       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   #define F first   #define S second   #define rep(i, a, b) for(int i = a; i < (b); ++i)   #define per(i, a, b) for(int i = b-1; i>=a ; i--)   #define trav(a, x) for(auto& a : x)   #define allin(a , x) for(auto a : x)   #define all(x) begin(x), end(x)   #define sz(x) (int)(x).size()   typedef long long ll;   typedef pair<int, int> pii;   typedef vector<ll> vl;   typedef vector<pii> vpi;   typedef pair<ll,ll> pll;   typedef vector<string> vs;   typedef vector<pll> vpl;   typedef vector<int> vi;   std::mt19937 rng((int) std::chrono::steady_clock::now().time_since_epoch().count());      int ask(int x , int i , vi v){    cout << 2 <<    << x  <<    << i <<    ;    for(int j = 0 ; j < i ; j ++){     cout << v[j]  <<   ;    }    cout << endl;    int ans;    cin >> ans;    return ans;   }                  int32_t main(){    int t;    cin >> t;    while(t--){     int n;     cin >> n;     vector<int> v;     for(int i = 0 ; i < n; i ++)      v.push_back(i);     stable_sort(all(v) , [&](int a , int b){      cout << 1 <<    << a <<    << b << endl;      int ans;      cin >> ans;      return ans;     });     vector< vector<char> > ans(n, vector<char>(n, 0 ));     for(int i = 0 ; i < n ; i ++){      for(int j = i ; j < n; j ++){       ans[v[i]][v[j]] =  1 ;      }     }     int pr = n-1;     vector< vector<int> > g(n);     for(int i = 0 ; i < n - 1; i ++)      g[v[i]].push_back(v[i+1]);     for(int i = n - 1 ; i >= 0 ; i --){      pr = min(pr, i);      while(pr > 0 && ask(v[i] , pr , v)){       pr -- ;      }      g[v[i]].push_back(v[pr]);     }     vector< vector<bool> > vis(n , vector<bool> (n));     for(int i = 0 ; i< n; i ++){      queue<int> q;      q.push(i);      while(sz(q)){       auto u = q.front();       q.pop();       if(vis[i][u])        continue;       vis[i][u] = true;       for(auto w : g[u])        if(!vis[i][w])         q.push(w);      }     }     cout << 3 << endl;     for(int i = 0; i < n; i ++){      for(int j = 0; j < n; j ++)       cout << (vis[i][j] ? 1 : 0);      cout << endl;     }     int ansx;     cin >> ansx;     assert(ansx != -1);    }    exit(0);   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:102400000,102400000 )   using namespace std;   const int maxn = 100086;   const double PI = atan(1.0) * 4.0;   const double eps = 1e-9;   const long long mod = 1000000007;   const int maxe = 10086 * 2;   long long quick_pow(long long a, long long n) {     long long ret = 1;     while (n) {       if (n & 1) ret = ret * a % mod;       a = a * a % mod;       n >>= 1;     }     return ret;   }   char s[maxn];   int n, num[5];   int main() {     scanf( %d%s , &n, s);     memset(num, 0, sizeof num);     for (int i = 0; i < n; i++) {       if (s[i] ==  A )         num[0]++;       else if (s[i] ==  G )         num[1]++;       else if (s[i] ==  T )         num[2]++;       else         num[3]++;     }     int maxx = -1;     for (int i = 0; i < 4; i++) maxx = max(maxx, num[i]);     int a = 0;     for (int i = 0; i < 4; i++)       if (maxx == num[i]) a++;     cout << quick_pow(a, n) << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int mo = 1e9 + 7;   struct node {     int mat[210][210];   } qwq;   int n, k, m;   inline int ha(int x, int y) { return x * (1 << m) + y; }   node ksm(int l) {     if (l == 1) return qwq;     node op = ksm(l / 2), op2;     memset(op2.mat, 0, sizeof(op2.mat));     for (int i = 0; i < (k + 1) * (1 << m); i++)       for (int j = 0; j < (k + 1) * (1 << m); j++)         for (int h = 0; h < (k + 1) * (1 << m); h++)           op2.mat[i][j] =               (op2.mat[i][j] + 1ll * op.mat[i][h] * op.mat[h][j]) % mo;     if (l % 2 == 0) return op2;     node op3;     memset(op3.mat, 0, sizeof(op3.mat));     for (int i = 0; i < (k + 1) * (1 << m); i++)       for (int j = 0; j < (k + 1) * (1 << m); j++)         for (int h = 0; h < (k + 1) * (1 << m); h++)           op3.mat[i][j] =               (op3.mat[i][j] + 1ll * qwq.mat[i][h] * op2.mat[h][j]) % mo;     return op3;   }   int main() {     scanf( %d%d%d , &n, &k, &m);     for (int i = 0; i <= k; i++)       for (int j = 0; j < (1 << m); j++) {         int ovo = (j << 1) % (1 << m);         qwq.mat[ha(i, ovo)][ha(i, j)]++;         if (i > 0) {           int way_to_here = 1;           for (int r = 0; r < m; r++)             if ((1 << r) & j) way_to_here++;           qwq.mat[ha(i, ovo | 1)][ha(i - 1, j)] += way_to_here;         }       }     node uoj = ksm(n);     int ans = 0;     for (int i = 0; i < (1 << m); i++)       ans = (ans + 1ll * uoj.mat[ha(k, i)][0]) % mo;     printf( %d , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5;   const int sqrtN = 320;   int countA[sqrtN], countP[sqrtN];   map<int, int> dm[sqrtN];   void recomp(int ind) {     int a, p;     a = p = 0;     for (auto& x : dm[ind]) {       if (x.second != -1) {         if (p != 0)           p--;         else           (a++);       } else {         p++;       }     }     countA[ind] = a;     countP[ind] = p;   }   int getTop(int ind, int p) {     for (auto& x : dm[ind]) {       if (x.second != -1) {         if (p != 0)           p--;         else           return x.second;       } else {         p++;       }     }   }   int top() {     int p = 0;     for (int i = 0; i < sqrtN; ++i) {       if (p - countA[i] < 0) return getTop(i, p);       p += countP[i] - countA[i];     }     return -1;   }   const long long mod = 1e9 + 7;   long long sums(long long a, long long b) {     long long ans = a + b;     if (ans >= mod) ans -= mod;     return ans;   }   long long mins(long long a, long long b) {     long long ans = a - b;     if (ans < 0) ans += mod;     return ans;   }   int p = 31;   long long nextH(long long h, char a) { return h * p + (a -  a ) + 1; }   int last[26], sum[5010] = {0}, f[5010] = {0};   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int n;     cin >> n;     string str;     cin >> str;     f[0] = 1;     for (int step = 0; step < n; ++step) {       for (int i = 0; i < 26; ++i) last[i] = -1;       sum[0] = 0;       for (int i = 0; i < n; ++i) sum[i + 1] = sums(sum[i], f[i]);       for (int i = 0; i < n; ++i) {         f[i] = mins(sum[i + 1], sum[last[str[i] -  a ] + 1]);         last[str[i] -  a ] = i;       }     }     int ans = 0;     for (int i = 0; i < n; ++i) ans = sums(ans, f[i]);     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   #pragma GCC optimize( Ofast )   int ah = 911382323;   int bh = 972663749;   template <typename F, typename S>   ostream &operator<<(ostream &os, const pair<F, S> &p) {     return os <<  (  << p.first <<  ,   << p.second <<  ) ;   }   template <typename T>   ostream &operator<<(ostream &os, const vector<T> &v) {     os <<  { ;     typename vector<T>::const_iterator it;     for (it = v.begin(); it != v.end(); it++) {       if (it != v.begin()) os <<  ,  ;       os << *it;     }     return os <<  } ;   }   template <typename T>   ostream &operator<<(ostream &os, const set<T> &v) {     os <<  [ ;     typename set<T>::const_iterator it;     for (it = v.begin(); it != v.end(); it++) {       if (it != v.begin()) os <<  ,  ;       os << *it;     }     return os <<  ] ;   }   template <typename F, typename S>   ostream &operator<<(ostream &os, const map<F, S> &v) {     os <<  [ ;     typename map<F, S>::const_iterator it;     for (it = v.begin(); it != v.end(); it++) {       if (it != v.begin()) os <<  ,  ;       os << it->first <<   =   << it->second;     }     return os <<  ] ;   }   long long dx[8] = {1, -1, 0, 0, 1, 1, -1, -1};   long long dy[8] = {0, 0, 1, -1, 1, -1, 1, -1};   int32_t main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long(t);     cin >> (t);     while ((t)--) {       long long n;       cin >> n;       vector<long long> v(n);       for (long long i = 0; i < n; i++) cin >> v[i];       long long ind = 0;       while (ind < n && v[ind] == 1) ind++;       if (ind == n) {         if (n % 2)           cout << ( First ) <<   n ;         else           cout << ( Second ) <<   n ;       } else {         if (ind % 2 == 0)           cout << ( First ) <<   n ;         else           cout << ( Second ) <<   n ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e6;   int cost[N], n, a, b, T;   string s;   long long l[N], r[N];   bool check(int d) {     --d;     long long bst = min(l[d], r[d]);     for (int i = 1; i < d; ++i) {       bst = min(bst, l[i] + r[d - i] + a * i);       bst = min(bst, r[i] + l[d - i] + a * i);     }     return bst + d + 1 + cost[0] <= T;   }   int main() {     ios_base::sync_with_stdio(0);     cin >> n >> a >> b >> T;     cin >> s;     for (int i = 0; i < s.size(); ++i) {       cost[i] = (s[i] ==  w  ? b : 0);     }     for (int i = 1; i < n; ++i) {       r[i] = r[i - 1] + cost[i] + a;     }     for (int i = 1; i < n; ++i) {       l[i] = l[i - 1] + cost[n - i] + a;     }     int L = 0, R = n + 1;     while (R - L > 1) {       int m = (L + R) >> 1;       if (check(m))         L = m;       else         R = m;     }     cout << L;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     long long n;     cin >> n;     long long a(-1), b(-1), ans(INT_MAX), tempA, tempB;     for (int i = 0;; i++) {       if (i * 7 > n) {         break;       }       if ((n - i * 7) % 4 == 0) {         tempA = (n - i * 7) / 4;         tempB = i;         if (tempA + tempB < ans) {           a = tempA;           b = tempB;           ans = a + b;         }       }     }     if (a == -1 && b == -1) {       cout << -1 << endl;     } else {       for (int i = 0; i < a; i++) {         cout << 4;       }       for (int i = 0; i < b; i++) {         cout << 7;       }       cout <<   n ;     }   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.precision(8);     long long t(1);     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long ans;   int n, a, b;   vector<pair<int, int> > v;   int main() {     ans = 0;     scanf( %d , &n);     for (int i = 0; i < n; ++i) {       scanf( %d %d , &a, &b);       v.push_back(make_pair(b, a));     }     sort(v.begin(), v.end());     for (int i = 0, j = 0; i < v.size(); ++i) {       if (v[i].second > j) {         j = v[i].first;         ++ans;       }     }     printf( %I64d , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using cd = complex<double>;   const double PI = acos(-1);   int reverse(int num, int lg_n) {     int res = 0;     for (int i = 0; i < lg_n; i++) {       if (num & (1 << i)) res |= 1 << (lg_n - 1 - i);     }     return res;   }   void fft(vector<cd> &a, bool invert) {     int n = a.size();     int lg_n = 0;     while ((1 << lg_n) < n) lg_n++;     for (int i = 0; i < n; i++) {       if (i < reverse(i, lg_n)) swap(a[i], a[reverse(i, lg_n)]);     }     for (int len = 2; len <= n; len <<= 1) {       double ang = 2 * PI / len * (invert ? -1 : 1);       cd wlen(cos(ang), sin(ang));       for (int i = 0; i < n; i += len) {         cd w(1);         for (int j = 0; j < len / 2; j++) {           cd u = a[i + j], v = a[i + j + len / 2] * w;           a[i + j] = u + v;           a[i + j + len / 2] = u - v;           w *= wlen;         }       }     }     if (invert) {       for (cd &x : a) x /= n;     }   }   vector<int> mult(vector<cd> &a, vector<cd> &b) {     vector<cd> fa(a.begin(), a.end()), fb(b.begin(), b.end());     int n = 1;     while (n < a.size() + b.size()) n <<= 1;     fa.resize(n);     fb.resize(n);     fft(fa, false);     fft(fb, false);     for (int i = 0; i < n; i++) fa[i] *= fb[i];     fft(fa, true);     vector<int> result(n);     for (int i = 0; i < n; i++) {       result[i] = round(fa[i].real());     }     return result;   }   long long mdp[1000010];   void crive() {     for (long long i = 2; i <= 1000000; i++) {       if (mdp[i] == 0) {         mdp[i] = i;         for (long long j = i * i; j <= 1000000; j += i) {           if (mdp[j] == 0) mdp[j] = i;         }       }     }   }   vector<long long> div(int l) {     vector<long long> ans = {1};     int sz = 1;     while (l > 1) {       long long p = mdp[l];       long long it = p;       while (l % it == 0) {         for (int j = 0; j < sz; j++) ans.push_back(it * ans[j]);         it *= p;       }       it /= p;       sz = ans.size();       l /= it;     }     sort(ans.begin(), ans.end());     return ans;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     crive();     long long n, x, y;     cin >> n >> x >> y;     vector<cd> a(x + 1), b(x + 1);     for (int i = 0; i < n + 1; i++) {       int num;       cin >> num;       a[x - num] = 1;       b[num] = 1;     }     vector<int> c = mult(a, b);     int q;     cin >> q;     for (int i = 0; i < q; i++) {       int l;       cin >> l;       vector<long long> d = div(l);       long long resp = -1;       for (int i = d.size() - 1; i >= 0 && d[i] > 2 * y; i--) {         long long u = d[i];         if (u & 1) continue;         if ((u - 2 * y) / 2 + x < c.size() && c[(u - 2 * y) / 2 + x])           resp = u, i = -1;       }       cout << resp <<    ;     }     cout << endl;   }


#include <bits/stdc++.h>   using namespace std;   struct segtree {     int n;     vector<long long> tree;     void init(int s) {       n = s;       tree.resize(4 * s);     }     long long qry(int i, int j) { return qry(i, j, 1, 0, n - 1); }     void upd(int i, long long v) { upd(i, v, 1, 0, n - 1); }     long long qry(int i, int j, int x, int nowi, int nowj) {       if (i <= nowi && nowj <= j) return tree[x];       if (nowi > j || nowj < i) return 0;       int m = (nowi + nowj) / 2;       return qry(i, j, 2 * x, nowi, m) + qry(i, j, 2 * x + 1, m + 1, nowj);     }     void upd(int i, long long v, int x, int nowi, int nowj) {       if (nowi == i && nowj == i) {         tree[x] = v;         return;       }       if (nowi > i || nowj < i) return;       int m = (nowi + nowj) / 2;       upd(i, v, 2 * x, nowi, m);       upd(i, v, 2 * x + 1, m + 1, nowj);       tree[x] = tree[2 * x] + tree[2 * x + 1];     }   };   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n, ans = 0;     cin >> n;     n *= 2;     vector<int> a(n), p(n + 1, -1), v(n + 1);     for (auto &i : a) cin >> i;     for (int i = 0; i < n; ++i) {       if (p[a[i]] == -1) p[a[i]] = i;       v[i] = p[a[i]];     }     segtree s;     s.init(n);     for (int i = n - 1; ~i; --i) {       s.upd(v[i], 1);       if (v[i]) ans += s.qry(0, v[i] - 1);     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   int N, K;   vector<int> arr;   struct Query {     int l, r, p, q;   };   vector<Query> query, tmp;   vector<vector<long long> > dp;   vector<int> cnt;   int lpos, rpos;   long long cost;   void solve(int k) {     query.push_back({0, N - 1, 0, N - 1});     while (query.size()) {       cnt = vector<int>(N, 0);       lpos = rpos = cost = 0;       tmp.clear();       for (int i = 0; i < query.size(); i++) {         int l = query[i].l;         int r = query[i].r;         int p = query[i].p;         int q = query[i].q;         if (l > r) continue;         int m = (l + r) >> 1;         int a = q;         dp[k][m] = 1e18;         while (rpos < max(m + 1, p)) {           cost -= 1LL * cnt[arr[rpos]] * (cnt[arr[rpos]] - 1) / 2;           cnt[arr[rpos]]++;           cost += 1LL * cnt[arr[rpos]] * (cnt[arr[rpos]] - 1) / 2;           rpos++;         }         while (rpos > max(m + 1, p)) {           rpos--;           cost -= 1LL * cnt[arr[rpos]] * (cnt[arr[rpos]] - 1) / 2;           cnt[arr[rpos]]--;           cost += 1LL * cnt[arr[rpos]] * (cnt[arr[rpos]] - 1) / 2;         }         while (lpos < m) {           cost -= 1LL * cnt[arr[lpos]] * (cnt[arr[lpos]] - 1) / 2;           cnt[arr[lpos]]--;           cost += 1LL * cnt[arr[lpos]] * (cnt[arr[lpos]] - 1) / 2;           lpos++;         }         for (int i = max(m + 1, p); i <= q; i++) {           if (dp[k][m] > dp[k - 1][i] + cost) {             dp[k][m] = dp[k - 1][i] + cost;             a = i;           }           cost -= 1LL * cnt[arr[rpos]] * (cnt[arr[rpos]] - 1) / 2;           cnt[arr[rpos]]++;           cost += 1LL * cnt[arr[rpos]] * (cnt[arr[rpos]] - 1) / 2;           rpos++;         }         tmp.push_back({l, m - 1, p, a});         tmp.push_back({m + 1, r, a, q});       }       query = tmp;     }   }   int main() {     scanf( %d %d , &N, &K);     arr.resize(N);     for (int i = 0; i < N; i++) {       scanf( %d , &arr[i]);       arr[i]--;     }     dp = vector<vector<long long> >(K + 1, vector<long long>(N));     cnt = vector<int>(N, 0);     cost = 0;     for (int i = N - 1; i >= 0; i--) {       cost -= 1LL * cnt[arr[i]] * (cnt[arr[i]] - 1) / 2;       cnt[arr[i]]++;       cost += 1LL * cnt[arr[i]] * (cnt[arr[i]] - 1) / 2;       dp[1][i] = cost;     }     for (int i = 2; i <= K; i++) {       solve(i);     }     printf( %lld , dp[K][0]);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     double d, h, v, e;     while (~scanf( %lf%lf%lf%lf , &d, &h, &v, &e)) {       double v1, v2;       v1 = (d / 2) * (d / 2) * 3.1415927 * e;       v2 = (d / 2) * (d / 2) * 3.1415927 * h;       if (v1 >= v)         printf( NO n );       else {         double time = v2 / (v - v1);         printf( YES n );         printf( %lf n , time);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   int tot = 1;   int b[200005], e[200005], h[200005], p[200005], u[200005];   vector<int> ans[200005];   void add(int x, int y) {     b[++tot] = y;     e[tot] = h[x];     h[x] = tot;   }   void dfs(int k, int fa_edge) {     p[k] = 1;     for (int go = h[k]; go; go = e[go])       if (b[go] != b[fa_edge]) {         if (p[b[go]] == 0) dfs(b[go], go ^ 1);         if (u[go] == 0) ans[k].push_back(b[go]), u[go] = u[go ^ 1] = 1;       }     int sum = ans[k].size();     if (sum & 1)       sum++, ans[k].push_back(b[fa_edge]), u[fa_edge] = u[fa_edge ^ 1] = 1;     for (int i = 0; i < sum; i += 2)       printf( %d %d %d n , ans[k][i] + 1, k + 1, ans[k][i + 1] + 1);   }   int main() {     scanf( %d%d , &n, &m);     if (m % 2) {       printf( No solution );       return 0;     }     int x, y;     for (int i = 0; i < m; i++) {       scanf( %d%d , &x, &y);       add(--x, --y);       add(y, x);     }     dfs(0, -1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5;   int n;   int neg = 0;   string s[N + 5];   inline long long pars(int x) {     long long ret = 0LL;     for (int i = 0; i < s[x].size(); i++) {       if (s[x][i] ==  - ) continue;       if (s[x][i] ==  . ) break;       ret *= 10;       ret += s[x][i] -  0 ;     }     if (s[x][0] ==  - ) ret *= -1;     return ret;   }   bool bisa(int x) {     for (int i = s[x].size() - 1; i >= 0; i--) {       if (s[x][i] ==  . ) break;       if (s[x][i] !=  0 ) return 1;     }     return 0;   }   int main() {     cin >> n;     long long ct = 0LL;     for (int i = 1; i <= n; i++) {       cin >> s[i];       if (s[i][0] ==  - ) neg++;       ct += pars(i);     }     for (int i = 1; i <= n; i++) {       long long tmp = pars(i);       if (bisa(i)) {         if (ct > 0) {           if (s[i][0] ==  - ) {             tmp--;             ct--;           }         } else if (ct < 0) {           if (s[i][0] !=  - ) {             tmp++;             ct++;           }         }       }       cout << tmp << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   int sum;   int l, r;   int ans = 360;   int a[360];   int main() {     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i];     while (r < n) {       sum += a[r];       while (sum >= 180) {         ans = min(ans, 2 * abs(180 - sum));         sum -= a[l];         l++;       }       ans = min(ans, 2 * abs(180 - sum));       r++;     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   int n, f, d;   int main() {     cin >> n;     if (n % 3 != 2)       d = n / 3;     else       d = n / 3 + 1;     f = d / 12;     d %= 12;     cout << f <<     << d;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1000000007;   const int INF = 1000000001;   const long long int LLINF = 1000000000000000001LL;   struct ITree {     vector<long long int> T;     int p = 1;     ITree(int n) {       while (p < n) p *= 2;       T.resize(2 * p - 1, 0);     }     int par(int x) { return (x - 1) / 2; }     void Set(int l, long long int v) {       l += p - 1;       T[l] = v;       while (l > 0) {         l = par(l);         T[l] = T[2 * l + 1] + T[2 * l + 2];       }     }     long long int Query(int l, int r) {       l += p - 1;       r += p - 1;       long long int ans = T[l];       if (l < r) ans += T[r];       while (par(l) != par(r)) {         if (l % 2 == 1) ans += T[l + 1];         if (r % 2 == 0) ans += T[r - 1];         l = par(l);         r = par(r);       }       return ans;     }   };   int main() {     ios_base::sync_with_stdio(0);     int n, k, a, b, q;     cin >> n >> k >> a >> b >> q;     ITree treeA(n), treeB(n);     vector<long long int> A(n, 0);     while (q--) {       int type;       cin >> type;       if (type == 1) {         int day, add;         cin >> day >> add;         day--;         A[day] += add;         treeB.Set(day, min((long long int)b, A[day]));         treeA.Set(day, min((long long int)a, A[day]));       } else {         int l;         cin >> l;         l--;         int r = l + k - 1;         long long int ans = 0;         if (l > 0) ans += treeB.Query(0, l - 1);         if (r < n - 1) ans += treeA.Query(r + 1, n - 1);         cout << ans <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using LL = long long;   constexpr int N = 1e5 + 5;   void solve() {     int a, b;     cin >> a >> b;     if (a * 2 <= b)       cout << a <<     << a * 2 <<   n ;     else       cout <<  -1 -1 n ;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     int t;     cin >> t;     while (t--) solve();   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 10;   const int S = 40;   const unsigned long long mod = 998244353;   struct poly {     int a[S + 10];     inline int& operator[](const int& x) { return a[x]; }     poly() {       for (int i = 0; i < S; i++) a[i] = 0;     }     friend poly operator*(poly a, poly b) {       poly c;       for (int i = 0; i < S; i++)         for (int j = 0; j < S && i + j < S; j++) c[i + j] += a[i] * b[j];       return c;     }     friend poly operator+(poly a, poly b) {       poly c;       for (int i = 0; i < S; i++) c[i] = a[i] + b[i];       return c;     }     friend poly operator-(poly a, poly b) {       poly c;       for (int i = 0; i < S; i++) c[i] = a[i] - b[i];       return c;     }     poly operator<<(const int& x) {       poly c;       for (int i = S - 1; i >= x; i--) c[i] = a[i - x];       return c;     }   } a, b, c, q, fz, fm, fz1, fm1;   int n;   unsigned long long f0[N];   unsigned long long c0[N];   unsigned long long f1[N];   unsigned long long c1[N];   unsigned long long f2[N];   unsigned long long c2[N];   unsigned long long g[N];   unsigned long long sqr[N];   inline void calc(poly& fz, poly& fm, unsigned long long* f,                    unsigned long long* c) {     for (int i = 0; i < S; i++) f[i] = (mod + fz[i]) % mod;     for (int i = 0; i < S; i++) c[i] = (mod - fm[i]) % mod;     (c[0] += 1) %= mod;     for (int i = 0; i <= n; i++)       for (int j = 1; j < S && j <= i; j++) (f[i] += f[i - j] * c[j]) %= mod;   }   int main() {     a[8] = 16;     a[6] = 12;     a[4] = 20;     a[2] = 4;     b[8] = 9;     b[6] = 2;     b[4] = 23;     b[2] = 6;     b[0] = 1;     c[8] = 4;     c[6] = -4;     c[4] = 24;     c[2] = 4;     c[0] = 4;     q[12] = -1;     q[10] = -3;     q[6] = +5;     q[2] = -3;     q[0] = +1;     scanf( %d , &n);     fz = ((b * b) << 3) - a * ((c << 3) - q);     fm = ((c << 3) - q) * ((a << 1) - q) - ((b * b) << 4);     calc(fz, fm, f0, c0);     fz = b * q;     fm = ((c << 3) - q) * ((a << 1) - q) - ((b * b) << 4);     calc(fz, fm, f1, c1);     fz1 = c * fm + ((b * fz) << 1);     fm1 = fm * (q - (c << 3));     calc(fz1, fm1, f2, c2);     g[0] = 1;     g[2] = 1;     for (int i = 4; i <= n; i++) g[i] = (g[i - 2] + g[i - 4]) % mod;     for (int i = 1; i <= n; i++) sqr[i] = (unsigned long long)i * i % mod;     unsigned long long ans = (g[n - 1] + g[n - 3]) * sqr[n - 1] % mod * n % mod;     for (int i = 2; i <= n - 2; i++) {       unsigned long long ret = 0;       (ret += g[i - 1] * f0[n - i - 1]) %= mod;       (ret += g[i - 2] * f1[n - i - 2] * 2) %= mod;       if (3 <= i && i <= n - 3) (ret += g[i - 3] * f2[n - i - 3]) %= mod;       (ans += ret * sqr[i - 1] % mod * i) %= mod;     }     printf( %I64d , ans);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     long long n, k, m, x, ans = 0;     cin >> n >> k >> m;     vector<pair<long long, long long> > v;     for (int i = 0; i < n; i++) {       cin >> x;       if (v.empty() || (v.back().first != x)) {         v.push_back({x, 1});       } else if (v.back().first == x) {         v.back().second = (v.back().second + 1) % k;         if (v.back().second == 0) v.pop_back();       }     }     if (v.size() == 0) return cout << 0, 0;     if (v.size() == 1) {       return cout << ((v[0].second * m) % k), 0;     }     for (auto &i : v) {       ans += m * i.second;     }     if (m == 1) return cout << ans, 0;     long long rem = 0;     int back = v.size() - 1, front = 0;     while (back > front) {       if ((v[front].first != v[back].first)) {         break;       } else {         rem += ((v[front].second + v[back].second) -                 ((v[front].second + v[back].second) % k)) *                (m - 1);         if ((v[front].second + v[back].second) % k) break;       }       back--;       front++;     }     if (back == front) {       rem += ((v[back].second) * m) - ((v[back].second) * m) % k;       if (((v[back].second) * m) % k == 0) {         back--;         front++;       }     }     if (back < front)       while (back >= 0) {         if ((v[front].first != v[back].first)) {           break;         } else {           rem += ((v[front].second + v[back].second) -                   ((v[front].second + v[back].second) % k));           if ((v[front].second + v[back].second) % k) break;         }         back--;         front++;       }     cout << (ans - rem);     return 0;   }


#include <bits/stdc++.h>   #pragma optimize( avx )   #pragma optimize( no-stack-protector )   namespace io {   inline char gnc() { return (char)getchar(); }   template <typename T>   inline void gi(T &dx) {     dx = 0;     int yc = gnc();     bool nega = false;     while (yc <  0  || yc >  9 ) {       nega = (yc ==  -  ? true : nega);       yc = gnc();     }     while (yc >=  0  && yc <=  9 ) {       dx = (T)(dx * 10 + yc -  0 );       yc = gnc();     }     if (nega) {       dx = -dx;     }   }   void gc(char &a) {     do a = gnc();     while (!isgraph(a));   }   void gss(char *c) {     *c = gnc();     while (!isgraph(*c)) *c = gnc();     while (isgraph(*c)) *++c = gnc();     *c = 0;   }   template <typename t1, typename t2>   inline void gi(t1 &a, t2 &b) {     gi(a);     gi(b);   }   template <typename t1, typename t2, typename t3>   inline void gi(t1 &a, t2 &b, t3 &c) {     gi(a);     gi(b);     gi(c);   }   template <typename t1, typename t2, typename t3, typename t4>   inline void gi(t1 &a, t2 &b, t3 &c, t4 &d) {     gi(a);     gi(b);     gi(c);     gi(d);   }   template <typename t1, typename t2, typename t3, typename t4, typename t5>   inline void gi(t1 &a, t2 &b, t3 &c, t4 &d, t5 &e) {     gi(a);     gi(b);     gi(c);     gi(d);     gi(e);   }   }  // namespace io   using namespace io;   using namespace std;   inline int gcd(int x, int y) {     return y > x ? gcd(y, x) : y ? gcd(y, x % y) : x;   }   inline void exgcd(int a, int b, int &x, int &y) {     if (!b) {       x = 1;       y = 0;       return;     }     exgcd(b, a % b, x, y);     int t = x;     x = y;     y = t - (a / b) * y;   }   const int INF = 0x3f3f3f3f;   const int MOD = 1e9 + 7;   const int Rev = (MOD + 1) >> 1;   template <typename T>   inline void Sol(T &x) {     if (x >= MOD) x -= MOD;   }   template <typename t1, typename t2>   inline int inc(t1 x, t2 y) {     x += y;     if (x >= MOD) x -= MOD;     return x;   }   template <typename t1, typename t2>   inline int dec(t1 x, t2 y) {     x += MOD - y;     if (x >= MOD) x -= MOD;     return x;   }   template <typename t1, typename t2>   inline long long mul(t1 x, t2 y) {     long long res = (long long)x * y;     return res >= MOD ? res % MOD : res;   }   template <typename t1, typename t2, typename t3>   inline long long mul(t1 x, t2 y, t3 z) {     return mul(mul(x, y), z);   }   template <typename t1, typename t2, typename t3, typename t4>   inline long long mul(t1 a, t2 b, t3 c, t4 d) {     return mul(mul(a, b), mul(c, d));   }   inline long long qpow(long long x, int y) {     long long res = 1;     for (; y; y >>= 1, x = x * x % MOD)       if (y & 1) res = res * x % MOD;     return res;   }   inline long long read() {     int x = 0, f = 1;     char c = getchar();     while (!isdigit(c)) {       if (c ==  - ) f = -1;       c = getchar();     }     while (isdigit(c)) {       x = x * 10 + c -  0 ;       c = getchar();     }     return x * f;   }   template <typename T1, typename T2>   inline void Getmin(T1 &x, T2 y) {     if (x > y) x = y;   }   template <typename T1, typename T2>   inline void Getmax(T1 &x, T2 y) {     if (x < y) x = y;   }   const int MAXN = 52;   int n, d[MAXN], f[2][MAXN][MAXN][MAXN][MAXN];   inline long long binom(long long x) { return 1LL * x * (x - 1) / 2ll % MOD; }   int main() {     n = read();     for (int i = 1; i <= n; i++) d[i] = read();     int np = 0;     f[np][d[1] == 2][d[1] == 3][d[2] == 2][d[2] == 3] = 1;     for (int i = 3; i <= n; i++) {       int p = np, op = d[i] & 1;       np ^= 1;       memset(f[np], 0, sizeof f[np]);       for (int pre1 = 0; pre1 < i; pre1++)         for (int pre2 = 0; pre2 < i - pre1; pre2++) {           int now1up = i - pre1 - pre2, now2up;           for (int now1 = 0; now1 < now1up; now1++) {             now2up = now1up - now1;             for (int now2 = 0; now2 < now2up; now2++)               if (f[p][pre1][pre2][now1][now2]) {                 if (!(now1 || now2 || pre1 || pre2)) continue;                 int val = f[p][pre1][pre2][now1][now2];                 if (!pre1 && !pre2) {                   if (now1)                     f[np][now1 - 1][now2][op ^ 1][op] =                         inc(f[np][now1 - 1][now2][op ^ 1][op], mul(val, now1));                   if (now2)                     f[np][now1 + 1][now2 - 1][op ^ 1][op] = inc(                         f[np][now1 + 1][now2 - 1][op ^ 1][op], mul(val, now2));                 } else {                   if (pre1) {                     int newnow1 = now1 + (op ^ 1), newnow2 = now2 + op;                     long long v = mul(val, pre1);                     int newpre1 = pre1 - 1;                     f[np][newpre1][pre2][newnow1][newnow2] =                         inc(f[np][newpre1][pre2][newnow1][newnow2], v);                     if (now1) {                       f[np][newpre1][pre2][now1 - 1 + op][now2] =                           inc(f[np][newpre1][pre2][now1 - 1 + op][now2],                               mul(v, now1));                       if (op && now1 > 1)                         f[np][newpre1][pre2][now1 - 2][now2] =                             inc(f[np][newpre1][pre2][now1 - 2][now2],                                 mul(v, binom(now1)));                     }                     if (now2) {                       f[np][newpre1][pre2][now1 + op + 1][now2 - 1] =                           inc(f[np][newpre1][pre2][now1 + op + 1][now2 - 1],                               mul(v, now2));                       if (op && now2 > 1)                         f[np][newpre1][pre2][now1 + 2][now2 - 2] =                             inc(f[np][newpre1][pre2][now1 + 2][now2 - 2],                                 mul(v, binom(now2)));                     }                     if (now1 && now2 && op)                       f[np][newpre1][pre2][now1][now2 - 1] =                           inc(f[np][newpre1][pre2][now1][now2 - 1],                               mul(mul(v, now1), now2));                   }                   if (pre2) {                     int newnow1 = now1 + (op ^ 1), newnow2 = now2 + op;                     long long v = mul(val, pre2);                     int newpre1 = pre1 + 1, newpre2 = pre2 - 1;                     f[np][newpre1][newpre2][newnow1][newnow2] =                         inc(f[np][newpre1][newpre2][newnow1][newnow2], v);                     if (now1) {                       f[np][newpre1][newpre2][now1 - 1 + op][now2] =                           inc(f[np][newpre1][newpre2][now1 - 1 + op][now2],                               mul(v, now1));                       if (op && now1 > 1)                         f[np][newpre1][newpre2][now1 - 2][now2] =                             inc(f[np][newpre1][newpre2][now1 - 2][now2],                                 mul(v, binom(now1)));                     }                     if (now2) {                       f[np][newpre1][newpre2][now1 + op + 1][now2 - 1] =                           inc(f[np][newpre1][newpre2][now1 + op + 1][now2 - 1],                               mul(v, now2));                       if (op && now2 > 1)                         f[np][newpre1][newpre2][now1 + 2][now2 - 2] =                             inc(f[np][newpre1][newpre2][now1 + 2][now2 - 2],                                 mul(v, binom(now2)));                     }                     if (now1 && now2 && op)                       f[np][newpre1][newpre2][now1][now2 - 1] =                           inc(f[np][newpre1][newpre2][now1][now2 - 1],                               mul(v, now1, now2));                   }                 }               }           }         }     }     int ans = f[n & 1][0][0][0][0];     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long A = 100000000000000LL, N = 300005;   long long p, d, limit;   long long cal(long long p) {     int x = 0;     if (p % 10 != 9) return 0;     while (p % 10 == 9) {       x++;       p /= 10;     }     return x;   }   int main() {     cin >> p >> d;     limit = p - d;     long long j = p;     long long length = log10(p) + 1;     long long initial = cal(p);     int i = 0;     long long powerr = 10;     while (true) {       j = p - p % powerr - 1;       if (j == -1) break;       if (j < limit) break;       powerr *= 10;     }     powerr /= 10;     j = p - p % powerr - 1;     if (j < limit) j = p;     if (j >= limit and powerr == 1) j = p;     if (initial >= (log10(powerr))) j = p;     cout << j;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int data[100];     int n, x, y;     cin >> n >> x >> y;     int c = 0;     for (int i = 0; i < n; i++) {       cin >> data[i];       if (data[i] <= x) c++;     }     if (x > y) {       cout << n;     } else {       if (c % 2 == 0) {         cout << c / 2;       } else         cout << (c / 2) + 1;     }     char a;     cin >> a;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   map<pair<long long unsigned, long long unsigned>,       pair<long long unsigned, long long unsigned> >       dp;   long long unsigned n;   void read() {     cin >> n;     return;   }   pair<long long unsigned, long long unsigned> find(long long unsigned s,                                                     long long unsigned mx) {     if (s <= 9) return make_pair(0, s);     if (dp.find(make_pair(s, mx)) != dp.end()) return dp[make_pair(s, mx)];     long long unsigned t, r, m;     pair<long long unsigned, long long unsigned> &ans = dp[make_pair(s, mx)];     t = 1;     while (t * 10 <= s) t *= 10;     r = s % t;     s = s / t;     while (1) {       m = max(mx, s);       pair<long long unsigned, long long unsigned> f = find(r, m);       ans.first += f.first;       if (s == 0) {         ans.second = f.second;         break;       }       if (f.second >= m) {         ans.first += 2;         r = t - m;       } else {         ans.first++;         r = t - (m - f.second);       }       s--;     }     return ans;   }   void solve() {     read();     pair<long long unsigned, long long unsigned> cvp = find(n, 0);     cout << cvp.first + !!cvp.second << endl;     return;   }   int main() {     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 10001001;   int min_div[MAXN];   vector<long long> primes;   void criba() {     for (int i = (int)0; i < (int)MAXN; i++) min_div[i] = i;     for (int i = (int)2; i < (int)MAXN; i++) {       if (min_div[i] != i) continue;       primes.push_back(i);       for (int j = i + i; j < MAXN; j += i) {         min_div[j] = i;       }     }   }   void solve(long long* acum) {     long long now = acum[MAXN - 1];     for (int i = MAXN - 2; i > 1; i--) {       now += acum[i];       acum[i] = now;     }     for (int i = MAXN - 1; i > 1; i--)       if (acum[i]) {         if (min_div[i] == i) continue;         int a = min_div[i];         int b = i / min_div[i];         acum[a] += acum[i];         acum[b] += acum[i];         acum[i] = 0;       }   }   long long acum_a[MAXN];   bool test(long long n) {     for (int i = (int)0; i < (int)primes.size(); i++) {       long long e = 0;       long long n_t = n;       while (n_t) {         e += (n_t /= (long long)primes[i]);       }       if (e < acum_a[primes[i]]) return false;     }     return true;   }   int main() {     criba();     int k;     scanf( %d , &k);     long long lo = 1, hi = 0;     for (int i = (int)0; i < (int)k; i++) {       int n = 1000101;       scanf( %d , &n);       acum_a[n]++;       hi += n;     }     solve(acum_a);     while (lo < hi) {       long long mid = (lo + hi) / 2LL;       if (test(mid)) {         hi = mid;       } else {         lo = mid + 1;       }     }     cout << lo << endl;     return 0;   }


#include <bits/stdc++.h>   const int N = 1e5 + 5;   int n;   char c[N];   int main() {     int T = 1;     scanf( %d , &T);     while (T--) {       scanf( %s , c + 1);       n = strlen(c + 1);       printf( %d n , 4);       printf( L 2 n );       printf( L 2 n );       printf( R 2 n );       n += 2;       n += n - 2;       printf( R %d n , n - 1);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char grid[1005][1005];   int lewo[1005][1005], prawo[1005][1005], gora[1005][1005], dol[1005][1005];   bool odwiedzony[1005][1005];   vector<pair<int, int> > przedzialy_x[1005], przedzialy_y[1005];   vector<pair<pair<int, int>, int> > wynik;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int y, x, xd = 0, wszystkie = 0;     cin >> y >> x;     for (int i = 1; i <= y; i++) {       for (int j = 1; j <= x; j++) {         cin >> grid[i][j];         if (grid[i][j] ==  * ) wszystkie++;         if (grid[i][j] ==  . )           lewo[i][j] = j;         else           lewo[i][j] = lewo[i][j - 1];       }       prawo[i][x + 1] = x + 1;       for (int j = x; j > 0; j--) {         if (grid[i][j] ==  . )           prawo[i][j] = j;         else           prawo[i][j] = prawo[i][j + 1];       }     }     for (int i = 1; i <= x; i++) {       for (int j = 1; j <= y; j++) {         if (grid[j][i] ==  . )           gora[j][i] = j;         else           gora[j][i] = gora[j - 1][i];       }       dol[y + 1][i] = y + 1;       for (int j = y; j > 0; j--) {         if (grid[j][i] ==  . )           dol[j][i] = j;         else           dol[j][i] = dol[j + 1][i];       }     }     for (int i = 2; i < y; i++)       for (int j = 2; j < x; j++) {         int pom = min(min(j - lewo[i][j] - 1, prawo[i][j] - j - 1),                       min(i - gora[i][j] - 1, dol[i][j] - i - 1));         if (pom && grid[i][j] ==  * ) {           przedzialy_x[i].push_back({j - pom, j + pom});           przedzialy_y[j].push_back({i - pom, i + pom});           wynik.emplace_back(make_pair(make_pair(i, j), pom));         }       }     for (int i = 1; i <= y; i++) {       przedzialy_x[i].push_back({1e9, 1e9});       sort(przedzialy_x[i].begin(), przedzialy_x[i].end());       int indeks = 0;       for (int j = 1; j <= x; j++) {         while (przedzialy_x[i][indeks].second < j) indeks++;         if (grid[i][j] ==  *  && przedzialy_x[i][indeks].first <= j) {           xd++;           odwiedzony[i][j] = true;         }       }     }     for (int i = 1; i <= x; i++) {       przedzialy_y[i].push_back({1e9, 1e9});       sort(przedzialy_y[i].begin(), przedzialy_y[i].end());       int indeks = 0;       for (int j = 1; j <= y; j++) {         while (przedzialy_y[i][indeks].second < j) indeks++;         if (grid[j][i] ==  *  && przedzialy_y[i][indeks].first <= j &&             !odwiedzony[j][i])           xd++;       }     }     if (xd == wszystkie) {       int aha = wynik.size();       cout << aha <<   n ;       for (int i = 0; i < aha; i++)         cout << wynik[i].first.first <<     << wynik[i].first.second <<                  << wynik[i].second <<   n ;     } else       cout <<  -1 n ;   }


#include <bits/stdc++.h>   using std::bitset;   using std::cin;   using std::cout;   using std::endl;   using std::make_pair;   using std::map;   using std::pair;   using std::priority_queue;   using std::queue;   using std::set;   using std::string;   using std::stringstream;   using std::vector;   class MyTimer {    public:     void reset() {}     void report() {}   } myTimer;   template <typename A, typename B>   std::ostream &operator<<(std::ostream &cout, const pair<A, B> &x) {     return cout <<  (  << x.first <<  ,   << x.second <<  ) ;   }   template <typename T1, typename T2>   inline bool chmin(T1 &a, const T2 &b) {     return a > b ? a = b, true : false;   }   template <typename T1, typename T2>   inline bool chmax(T1 &a, const T2 &b) {     return a < b ? a = b, true : false;   }   const int maxN = 100000 + 233;   int n, m;   int a[maxN], b[maxN], c[maxN], d[maxN], e[maxN];   int ans[maxN];   struct Q {     int t;     int x, y, L, R;     Q(int t, int x, int y, int L, int R) : t(t), x(x), y(y), L(L), R(R) {}     bool operator<(const Q &rhs) const {       return x != rhs.x ? x < rhs.x : y != rhs.y ? y < rhs.y : t > rhs.t;     }   };   vector<Q> q, tmp;   void initialize() {     std::ios::sync_with_stdio(false);     cin >> n >> m;     for (int i = 1; i <= n; ++i) cin >> a[i];     for (int i = 1; i <= n; ++i) cin >> b[i];     for (int i = 1; i <= n; ++i) cin >> c[i];     for (int i = 1; i <= m; ++i) cin >> d[i];     for (int i = 1; i <= m; ++i) cin >> e[i];     for (int i = 1; i <= n; ++i) {       q.emplace_back(i, -c[i] + a[i], c[i] + a[i], a[i], b[i]);     }     for (int i = 1; i <= m; ++i) {       q.emplace_back(-i, -e[i] + d[i], d[i] + e[i], d[i], d[i]);     }     vector<int> t;     for (auto &p : q) t.push_back(p.L), t.push_back(p.R);     std::sort(t.begin(), t.end());     t.erase(std::unique(t.begin(), t.end()), t.end());     for (auto &p : q)       p.L = std::lower_bound(t.begin(), t.end(), p.L) - t.begin() + 1,       p.R = std::lower_bound(t.begin(), t.end(), p.R) - t.begin() + 1;     std::sort(q.begin(), q.end());     tmp.resize(q.size(), Q(0, 0, 0, 0, 0));   }   int C[maxN * 3];   void add(int p, int x) {     p += 2;     for (int i = p; i <= n * 2 + m + 5; i += i & -i) C[i] += x;   }   int sum(int p) {     p += 2;     int r = 0;     for (int i = p; i > 0; i -= i & -i) r += C[i];     return r;   }   void solve(int L, int R) {     if (L >= R) return;     int M = (L + R) >> 1;     solve(L, M);     solve(M + 1, R);     int i = L, j = M + 1, qwq = L;     const auto left = [&](const Q &p) {       tmp[qwq++] = p;       if (p.t > 0) add(p.L, 1), add(p.R + 1, -1);     };     const auto right = [&](const Q &p) {       tmp[qwq++] = p;       if (p.t < 0) ans[-p.t] += sum(p.L);     };     while (i <= M && j <= R) {       if (q[i].y < q[j].y || (q[i].y == q[j].y && q[i].t > 0))         left(q[i++]);       else         right(q[j++]);     }     while (i <= M) left(q[i++]);     while (j <= R) right(q[j++]);     for (int k = L; k <= M; ++k)       if (q[k].t > 0) add(q[k].L, -1), add(q[k].R + 1, 1);     for (int k = L; k <= R; ++k) q[k] = tmp[k];   }   int main() {     initialize();     solve(0, (int)q.size() - 1);     for (int i = 1; i <= m; ++i) printf( %d%c , ans[i],    n [i == m]);     return 0;   }