#include <bits/stdc++.h>   using namespace std;   inline long long min2(long long a, long long b) {     return (a) < (b) ? (a) : (b);   }   inline long long max2(long long a, long long b) {     return (a) > (b) ? (a) : (b);   }   inline long long max3(long long a, long long b, long long c) {     return (a) > (b) ? ((a) > (c) ? (a) : (c)) : ((b) > (c) ? (b) : (c));   }   inline long long min3(long long a, long long b, long long c) {     return (a) < (b) ? ((a) < (c) ? (a) : (c)) : ((b) < (c) ? (b) : (c));   }   pair<long long int, long long int> fsi(pair<long long int, long long int> a,                                          pair<long long int, long long int> b) {     pair<long long int, long long int> x;     if (max(a.first, b.first) > min(a.second, b.second)) {       x.first = 10000000000002;       x.second = 10000000000002;     } else {       x.first = max(a.first, b.first);       x.second = min(a.second, b.second);     }     return x;   }   void process() {     long long int n, m, l, h, pt, ct;     pair<long long int, long long int> p, curr;     string ans;     ans =  YES ;     bool and_found = false;     pt = 0;     cin >> n >> m;     p.first = m;     p.second = m;     for (long long int i = 0; i < n; i++) {       cin >> ct >> curr.first >> curr.second;       if (!and_found) {         p.first -= ct - pt;         p.second += ct - pt;         p = fsi(p, curr);         if (p.first == 10000000000002) {           and_found = true;           ans =  NO ;         }         pt = ct;       }     }     cout << ans << endl;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     long long int t;     cin >> t;     ;     while (t--) process();   }


#include <bits/stdc++.h>      using namespace std;      typedef long long ll;      int main()   {    int T;    scanf( %d , &T);    while (T--) {     ll n, m, ans = 0;     scanf( %lld%lld , &n, &m);     for (ll k = 1; k <= n / k; k++) {      ans += max(0ll, min(n / k - 1, m) - k);     }     printf( %lld n , ans);    }    return 0;   }   /*   1   50 3   */


#include <bits/stdc++.h>   using namespace std;   const int N = 100005;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       int a[n + 1];       int sum = 0;       for (int i = 1; i <= n; i++) {         cin >> a[i];         sum += a[i];       }       if (sum % n != 0)         cout << -1 << endl;       else {         vector<tuple<int, int, int>> ans;         int avg = sum / n;         for (int i = 2; i <= n; i++) {           int p = a[i];           a[i] %= i;           if (a[i] > 0) {             ans.push_back({1, i, i - a[i]});             p += (i - a[i]);           }           ans.push_back({i, 1, p / i});           a[i] = 0;         }         a[1] = sum;         for (int i = 2; i <= n; i++) {           int x = avg - a[i];           if (x > 0) {             ans.push_back({1, i, x});             a[1] -= x;           }         }         cout << ans.size() << endl;         for (auto aa : ans) {           cout << get<0>(aa) <<     << get<1>(aa) <<     << get<2>(aa) << endl;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int d[][2] = {{1, -1}, {1, 1}, {-1, -1}, {-1, 1}};   const char* ds[] = { DL ,  DR ,  UL ,  UR };   int gdi(const char* s) {     int i = -1;     while (++i < 4) {       if (!strcmp(s, ds[i])) return i;     }   }   bool sv[4] = {false};   int fdi(const int dr, const int dc) {     int i = -1;     while (++i < 4 && !(dr == d[i][0] && dc == d[i][1]))       ;     return i;   }   void pr1(map<pair<int, int>, bool>& mp) {     map<pair<int, int>, bool>::iterator it = mp.begin();     while (it != mp.end()) {       printf( %d, %d n , it->first.first, it->first.second);       ++it;     }     printf( ------------ n );   }   int main() {     int n, m, xs, ys, di;     char drs[3];     scanf( %d%d%d%d%s , &n, &m, &xs, &ys, drs);     const int n1 = n - 1, m1 = m - 1;     --xs, --ys;     const int xy = ((xs + ys) & 1);     di = gdi(drs);     int dr = d[di][0], dc = d[di][1], cr = xs, cc = ys;     if (n == m && n > 2) {       if ((((!xs && !ys) || (xs == n1 && ys == n1)) && dr * dc > 0) ||           (((!xs && ys == m1) || (xs == n1 && !ys)) && dr * dc < 0)) {         printf( -1 n );         return 0;       }     }     map<pair<int, int>, bool> mp;     int i = -1;     while (++i < n) {       pair<int, int> p1(i, 0), p2(i, m1);       if (((p1.first + p1.second) & 1) == xy) mp[p1] = false;       if (((p2.first + p2.second) & 1) == xy) mp[p2] = false;     }     i = -1;     while (++i < m) {       pair<int, int> p1(0, i), p2(n1, i);       if (((p1.first + p1.second) & 1) == xy) mp[p1] = false;       if (((p2.first + p2.second) & 1) == xy) mp[p2] = false;     }     int nm = mp.size();     long long pn = 1;     pair<int, int> pc(xs, ys);     map<pair<int, int>, bool>::iterator it = mp.find(pc);     if (it != mp.end()) {       it->second = true;       --nm;     }     while (nm) {       int d1, d2;       if (dr < 0) {         d1 = cr;         if (dc > 0) {           d2 = m1 - cc;         } else {           d2 = cc;         }       } else {         d1 = n1 - cr;         if (dc > 0) {           d2 = m1 - cc;         } else {           d2 = cc;         }       }       if (d1 > d2) {         d1 = d2;         cr += d1 * dr;         cc += d1 * dc;         dc = -dc;       } else if (d1 < d2) {         cr += d1 * dr;         cc += d1 * dc;         dr = -dr;       } else {         cr += d1 * dr;         cc += d2 * dc;         dr = -dr;         dc = -dc;       }       pn += d1;       pc.first = cr, pc.second = cc;       it = mp.find(pc);       if (it != mp.end() && !it->second) {         --nm;         it->second = true;       }       if (nm && cr == xs && cc == ys) {         int j = fdi(dr, dc);         if (sv[j]) {           printf( -1 n );           return 0;         } else {           sv[j] = true;         }       }     }     printf( %I64d n , pn);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1000000007;   const long long N = 1e6 + 1;   long long pre[N], sub[N];   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     ;     string str;     cin >> str;     long long a = 0, b = 0, c = 0;     for (long long i = 0; i < str.size(); i++) {       if (str[i] ==  o ) {         b += a;       } else if (i > 0 && str[i - 1] ==  v ) {         a++;         c += b;       }     }     cout << c <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   struct node {     int sum;     int adj[6];     node() {       sum = 0;       memset(adj, -1, sizeof adj);     }   };   int n, m;   vector<node> T;   map<string, int> S;   void add(string x) {     int cur = 0;     for (int i = 0; i < x.size(); i++) {       int c = x[i] -  a ;       if (T[cur].adj[c] == -1) {         T.push_back(node());         T[cur].adj[c] = T.size() - 1;         cur = T.size() - 1;       } else {         cur = T[cur].adj[c];       }       if (i == x.size() - 1) T[cur].sum++;     }   }   int ask(string x) {     string y =   ;     for (int i = 0; i < x.size(); i++) {       if (x[i] ==  ? ) continue;       y += x[i];     }     bool take = true;     if (S.find(y) != S.end()) {       take = false;     } else {       S[y] = 1;     }     int cur = 0;     int ans = 0;     int i = 0;     for (i = 0; i < x.size(); i++) {       if (x[i] ==  ? ) {         string y = x;         for (char a =  a ; a <=  e ; a++) {           y[i] = a;           ans += ask(y);         }         if (i == x.size() - 1 && take) {           ans += T[cur].sum;         }         continue;       }       int c = x[i] -  a ;       if (T[cur].adj[c] != -1) {         cur = T[cur].adj[c];       } else {         break;       }       if (i == x.size() - 1 && take) {         ans += T[cur].sum;       }     }     return ans;   }   int main() {     cin >> n >> m;     T.push_back(node());     for (int i = 0; i < n; i++) {       string x;       cin >> x;       add(x);     }     int ans = 0;     for (int i = 0; i < m; i++) {       S.clear();       ans = 0;       string x;       cin >> x;       ans += ask(x);       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int arr[100009], mark[100009], vis[100009];   map<pair<int, int>, int> mp;   map<pair<int, int>, int>::iterator ii;   int main() {     int n, i;     scanf( %d , &n);     for (i = 0; i < n; ++i) scanf( %d , &arr[i]);     memset(mark, 0, sizeof mark);     for (i = 0; i < n; ++i) mark[arr[i]] += 1;     int cnt = 0;     for (i = 1; i <= 100000; ++i)       if (mark[i] != 0) ++cnt;     long long ans = 0;     memset(vis, -1, sizeof vis);     for (i = 0; i < n; ++i) {       int val = arr[i];       mark[val]--;       if (mark[val] == 0) cnt--;       if (vis[val] == -1) {         vis[val] = 1;         ans = ans + (long long)cnt;       }     }     printf( %lld n , ans);   }


#include <bits/stdc++.h>   using namespace std;   const int MX = (int)2e5 + 10;   const int mod = (int)1e9 + 7;   bool check(string& t) {     bool ok = true;     int n = t.size();     for (int j = 0; j < n / 2; ++j) {       ok &= t[j] == t[n - j - 1];     }     return ok;   }   int main(int argc, char* argv[]) {     cin.tie(0);     cout.tie(0);     ios_base::sync_with_stdio(0);     string s;     cin >> s;     int n = s.size();     int it = 0;     while (it < n && s[it] == s[0]) it++;     if (it == n) {       cout <<  Impossible  << endl;       return 0;     }     for (int i = 1; i < n; ++i) {       string s1 = s.substr(0, i);       string s2 = s.substr(i);       string t = s2 + s1;       if (t != s && check(t)) {         cout << 1 << endl;         return 0;       }     }     if (n % 2 == 0) {       string sx = s.substr(0, n / 2);       if (!check(sx)) {         cout << 1 << endl;         return 0;       }     }     for (int i = 0; i < n / 2; ++i) {       string sx = s.substr(0, i + 1);       if (!check(sx)) {         cout << 2 << endl;         return 0;       }     }     cout <<  Impossible  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   char change(char c) {     if (c ==  B ) {       return  W ;     }     return  B ;   }   int main() {     int n, k;     cin >> n >> k;     string s;     cin >> s;     int good = -1;     vector<int> start(n, -1);     for (int i = 0; i != n; ++i) {       if (s[(i + n - 1) % n] == s[i] || s[i] == s[(i + 1) % n]) {         start[i] = 0;         good = i;       }     }     if (good == -1) {       for (int i = 0; i != n; ++i) {         start[i] = k + 1;       }     } else {       for (int i = (good + 1) % n; i != good;) {         if (start[i]) {           int cnt = 0;           while (start[(i + cnt) % n]) {             ++cnt;           }           int pos = 1;           while (pos != cnt + 1) {             start[(i + pos - 1) % n] = min(pos, cnt - pos + 1);             ++pos;           }           i = (i + cnt) % n;         } else {           i = (i + 1) % n;         }       }     }     for (int i = 0; i != n; ++i) {       if (min(k, start[i]) & 1) {         cout << change(s[i]);       } else {         cout << s[i];       }     }   }


#include <bits/stdc++.h>   void out(int x) {     if (x) {       std::cout << x << std::endl;     } else {       std::cout <<  Impossible  << std::endl;     }     exit(0);   }   bool string_is_palindorome(const std::string& s) {     for (int i = 0, j = s.size() - 1; i < j; i++, j--)       if (s[i] != s[j]) return false;     return true;   }   int main(int argc, char** argv) {     std::cin.tie(0);     std::ios_base::sync_with_stdio(0);     std::cout << std::fixed << std::setprecision(6);     std::cerr << std::fixed << std::setprecision(6);     std::string s, t;     std::cin >> s;     t = s;     int size = s.size();     if (size <= 3) out(0);     for (int i = 1; i < size; i++) {       std::rotate(std::begin(t), std::begin(t) + 1, std::end(t));       if (!string_is_palindorome(t)) continue;       if (t != s) out(1);     }     for (int i = 1; i <= size / 2; i++)       for (int j = 0, k = size - i; j < i; j++, k++) {         assert(k < size);         if (s[k] != s[j]) out(2);       }     out(0);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 1e5 + 300;   const long long mod = 1e9 + 7;   const long long NN = 20 + 1;   vector<pair<long long, long long> > a[N];   long long p[N][NN], t[N], dp[N], dp2[N], sum[N], h[N], dp3[N], dp4[N], n;   void dfs2(long long v, long long par = -1, long long col = -1) {     dp3[v] = dp[v];     dp4[v] = dp2[v];     if (par != -1) {       dp4[v] = 0;       dp3[v] = (dp3[par] + ((n - 2 * t[v] + 2 * mod) * col) % mod) % mod;       dp4[v] = (dp4[par] + (((col * col) % mod) * (n - 1)) % mod +                 2 * (col * dp3[par]) % mod) %                mod;       dp4[v] += 2 * mod - (4 * dp[v] * col) % mod -                 (t[v] * 4 * ((col * col) % mod)) % mod + (col * col) % mod;       dp4[v] %= mod;     }     for (long long i = 0, u, c; i < a[v].size(); i++) {       u = a[v][i].first, c = a[v][i].second;       if (u != par) {         dfs2(u, v, c);       }     }   }   void dfs(long long v, long long par = -1) {     p[v][0] = par;     for (long long i = 1; i < NN; i++) {       if (p[v][i - 1] != -1) p[v][i] = p[p[v][i - 1]][i - 1];     }     t[v] = 1;     for (long long i = 0, u, c; i < a[v].size(); i++) {       u = a[v][i].first, c = a[v][i].second;       if (u != par) {         sum[u] = (sum[v] + c) % mod;         h[u] = h[v] + 1;         dfs(u, v);         t[v] += t[u];         dp[v] += (dp[u] + c * t[u]) % mod;         dp[v] %= mod;         dp2[v] += (dp2[u] + (t[u] * ((c * c) % mod)) % mod) % mod;         dp2[v] %= mod;         dp2[v] += 2 * ((c * dp[u]) % mod);         dp2[v] %= mod;       }     }   }   long long getp(long long v, long long k) {     for (long long i = 0; i < NN; i++) {       if ((k & (1 << i)) != 0) v = p[v][i];     }     return v;   }   long long lca(long long v, long long u) {     if (h[u] > h[v]) swap(u, v);     v = getp(v, h[v] - h[u]);     if (u == v) return v;     for (long long i = NN - 1; i >= 0; i--) {       if (p[u][i] != p[v][i]) u = p[u][i], v = p[v][i];     }     return p[u][0];   }   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     memset(p, -1, sizeof(p));     cin >> n;     for (long long i = 0, u, v, c; i < n - 1; i++) {       cin >> u >> v >> c;       u--;       v--;       a[u].push_back(make_pair(v, c));       a[v].push_back(make_pair(u, c));     }     dfs(0);     dfs2(0);     long long m;     cin >> m;     for (long long _ = 0, u, v; _ < m; _++) {       cin >> u >> v;       u--;       v--;       long long l = lca(u, v);       long long x = sum[u] + sum[v] - 2 * sum[l] + 2 * mod;       x %= mod;       long long ans =           dp2[v] + (t[v] * ((x * x) % mod)) % mod + 2 * ((dp[v] * x) % mod);       if (v == l) {         long long h = (dp4[v] - dp2[v] + mod) % mod +                       ((n - t[v]) * ((x * x) % mod)) % mod +                       (2 * (((dp3[v] - dp[v]) * x) % mod) % mod);         h %= mod;         ans = dp4[u] - h + mod;       }       ans %= mod;       ans *= 2;       ans += mod - dp4[u];       ans %= mod;       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   const double PI = acos(-1.0);   using namespace std;   int t[100010];   void update(int x, int v) {     for (; x < 100010; x += (x & -x)) t[x] += v;   }   int sum(int r) {     int ans = 0;     for (; r > 0; r -= (r & -r)) ans += t[r];     return ans;   }   int sum(int l, int r) {     if (l > r) swap(l, r);     return sum(r) - sum(l - 1);   }   int main() {     int n, q;     scanf( %d %d , &n, &q);     for (int i = 1; i <= n; ++i) update(i, 1);     int ll = 0, rr = n, dir = 1;     while (q--) {       int type;       scanf( %d , &type);       if (type == 1) {         int p;         scanf( %d , &p);         if (2 * p <= abs(ll - rr)) {           for (int j = 1; j <= p; ++j) {             int w = sum(ll + j * dir, ll + j * dir);             update(ll + j * dir, -w);             update(ll + (2 * p - j + 1) * dir, w);           }           ll += p * dir;         } else {           for (int j = abs(ll - rr); j > p; --j) {             int w = sum(ll + j * dir, ll + j * dir);             update(ll + j * dir, -w);             update(ll + (2 * p - j + 1) * dir, w);           }           ll += (p + 1) * dir;           rr = ll - p * dir;           dir *= -1;         }       } else {         int l, r;         scanf( %d %d , &l, &r);         printf( %d n , sum(ll + (l + 1) * dir, ll + r * dir));       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MX = 35;   bitset<MX * MX> bs[MX * MX];   int n, a[MX][MX], m, sz, h, res;   void impr() {     for (int k = 0; k < m; k++) {       cout << k <<  :   <<   n ;       for (int i = 0; i < n; i++) {         for (int j = 0; j < n; j++) cout << bs[k][((i)*n + (j))] <<    ;         cout <<   n ;       }       cout <<   n ;     }   }   int val(int i, int j, bitset<MX * MX> &bs) {     return bs[((i)*n + (j))] ? -a[i][j] : a[i][j];   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n;     h = (n + 1) / 2;     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++) {         cin >> a[i][j];         res += a[i][j];       }     for (int i = 0; i < h; i++)       for (int j = 0; j < h; j++) {         for (int x = 0; x < h; x++)           for (int y = 0; y < h; y++) bs[m][((i + x) * n + (j + y))] = 1;         m++;       }     for (int i = 0; i < n * n; i++) {       int ind = -1;       for (int j = sz; j < m; j++)         if (bs[j][i]) ind = j;       if (ind == -1) continue;       swap(bs[ind], bs[sz]);       for (int j = 0; j < m; j++)         if (j != sz && bs[j][i]) bs[j] ^= bs[sz];       sz++;     }     for (int mk = 0; mk < (1 << h); mk++) {       bitset<MX * MX> act;       for (int i = 0; i < h; i++)         if (mk & (1 << i)) act ^= bs[h * (i + 1) - 1];       int p = 0;       for (int i = 0; i < n; i++) p += val(i, h - 1, act);       for (int j = 0; j < h - 1; j++) {         bitset<MX *MX> a = act, b = act ^ bs[h * (h - 1) + j];         int x = val(h - 1, j, a) + val(h - 1, j + h, a);         int y = val(h - 1, j, b) + val(h - 1, j + h, b);         for (int i = 0; i < h - 1; i++) {           int q = val(i, j, a) + val(i + h, j, a) + val(i, j + h, a) +                   val(i + h, j + h, a);           x += max(q, -q);           q = val(i, j, b) + val(i + h, j, b) + val(i, j + h, b) +               val(i + h, j + h, b);           y += max(q, -q);         }         p += max(x, y);       }       res = max(res, p);     }     cout << res <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long N, A[100];   int main(void) {     cin >> N;     for (long long i = ((long long)0); i < ((long long)N); i++) cin >> A[i];     bool ans = true;     long long p1 = 1, p2 = 2, s = 3;     for (long long i = ((long long)0); i < ((long long)N); i++) {       if (A[i] == p1) {         swap(p2, s);       } else if (A[i] == p2) {         swap(p1, s);       } else {         ans = false;         break;       }     }     cout << (ans ?  YES  :  NO ) << endl;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, s[111];   int f[20][1 << 20];   int bitc[1 << 20];   int act[22];   int who[22];   int picks[22];   inline void upd_max(int i, int j, int val) {     if (f[i][j] > 1000000000)       f[i][j] = val;     else       f[i][j] = max(f[i][j], val);   }   inline void upd_min(int i, int j, int val) {     if (f[i][j] > 1000000000)       f[i][j] = val;     else       f[i][j] = min(f[i][j], val);   }   int solve(int step, int ban) {     if (step == n) return 0;     if (f[step][ban] < 1000000000) return f[step][ban];     int pick, left;     for (pick = 0, left = picks[step];; ++pick) {       if (!(ban & (1 << pick))) --left;       if (left == -1) break;     }     if (act[step] == 1) {       if (who[step] == 1) {         upd_max(step, ban, solve(step + 1, ban) + s[pick]);       } else {         upd_min(step, ban, solve(step + 1, ban) - s[pick]);       }     } else {       for (; pick < n; ++pick) {         if (!(ban & (1 << pick))) {           if (who[step] == 1) {             upd_max(step, ban, solve(step + 1, ban | (1 << pick)));           } else {             upd_min(step, ban, solve(step + 1, ban | (1 << pick)));           }         }       }     }     return f[step][ban];   }   int main() {     cin >> n;     for (int i = 0; i < n; ++i) cin >> s[i];     sort(s, s + n);     reverse(s, s + n);     cin >> m;     if (n > m) n = m;     for (int i = 0; i < m; ++i) {       char ch;       cin >> ch;       if (ch ==  p )         act[i] = 1;       else         act[i] = 0;       cin >> who[i];       if (i) picks[i] = picks[i - 1] + act[i - 1];     }     memset(f, 63, sizeof(f));     bitc[0] = 0;     for (int i = 1; i < (1 << n); ++i) {       bitc[i] = bitc[i / 2] + i % 2;     }     cout << solve(0, 0) << endl;   }


#include <bits/stdc++.h>   std::string a, b;   std::string cal(std::string a) {     if (a.length() % 2) return a;     std::string s1 = cal(a.substr(0, a.length() / 2));     std::string s2 = cal(a.substr(a.length() / 2, a.length()));     if (s1 < s2) return s1 + s2;     return s2 + s1;   }   int main() {     std::cin >> a >> b;     a = cal(a);     b = cal(b);     if (a == b)       puts( YES );     else       puts( NO );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, t1, t2, k;   pair<int, int> res[100001];   bool cmp(pair<int, int> a, pair<int, int> b) {     if (a.second == b.second) {       return a.first < b.first;     }     return a.second > b.second;   }   int cal(int a, int b) { return a * t1 * (100 - k) + b * t2 * 100; }   int main() {     ios_base ::sync_with_stdio(false);     int i;     cin >> n >> t1 >> t2 >> k;     for (i = 0; i < n; i++) {       int a, b;       cin >> a >> b;       res[i].first = i + 1;       res[i].second = max(cal(a, b), cal(b, a));     }     sort(res, res + n, cmp);     for (i = 0; i < n; i++) {       printf( %d %.2f n , res[i].first, (double)res[i].second / 100.0);     }     return 0;   }


#include <bits/stdc++.h>   char a[200005], b[200005];   int cmp(char *p, char *q, int n) {     if (!strncmp(p, q, n)) return 1;     if (n % 2) return 0;     int temp = n / 2;     if (cmp(p, q, temp) && cmp(p + temp, q + temp, temp))       return 1;     else if (cmp(p + temp, q, temp) && cmp(p, q + temp, temp))       return 1;     return 0;   }   int main() {     while (~scanf( %s%s , a, b)) {       if (cmp(a, b, strlen(a)))         printf( YES n );       else         printf( NO n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   map<int, int> mp;   int read() {     int c = 0;     char ch = getchar();     while (ch <  0  ||  9  < ch) ch = getchar();     while ( 0  <= ch && ch <=  9 ) c = c * 10 + ch -  0 , ch = getchar();     return c;   }   int main() {     int n = read(), P = read(), k = read();     for (int i = 1; i <= n; ++i) {       int a = read();       int x = (P + 1LL * a * a % P * a % P * a % P - 1LL * k * a % P) % P;       ++mp[x];     }     long long ans = 0;     for (map<int, int>::iterator it = mp.begin(); it != mp.end(); ++it) {       int x = (*it).second;       ans += x * (x - 1) / 2;     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7, inf = 2e9, mxn = 1e6 + 5;   void solve() {     int n, m, addx = 0, addy = 0, mnx = 0, mxx = 0, mny = 0, mxy = 0, x = 1,               y = 1;     cin >> n >> m;     string second;     cin >> second;     for (auto i : second) {       addx += (i ==  R );       addx -= (i ==  L );       addy += (i ==  U );       addy -= (i ==  D );       mxx = max(mxx, addx);       mnx = min(addx, mnx);       mxy = max(mxy, addy);       mny = min(addy, mny);       if (mxy < n && mxx < m && -mny < n && -mnx < m && mxx - mnx < m &&           mxy - mny < n) {         x = -mnx + 1;         y = mxy + 1;       } else {         break;       }     }     cout << y <<     << x <<   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;   int main() {     ios_base::sync_with_stdio(0);     int n;     cin >> n;     if (n / 36 + 1 == (n + 1) / 36) n++;     cout << n / 36 <<     << round((n - (n / 36) * 36) * 1.0 / 3);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string sd(int n) {     string s;     stringstream ss;     ss << n;     ss >> s;     return s;   }   int main() {     long long int n, k, a[105], c = 0, san = 0;     string s;     cin >> n >> k;     for (int i = 1; i <= n; i++) {       cin >> a[i];       s = sd(a[i]);       if (s.size() <= k) {         c++;       } else {         for (int j = 0; j < s.size(); j++) {           if (s[j] ==  4  or s[j] ==  7 ) san++;         }         if (san <= k) c++;       }       san = 0;     }     cout << c;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int min1, min2, min3, max1, max2, max3;     cin >> min1 >> max1 >> min2 >> max2 >> min3 >> max3;     int c = n;     int ans1 = min1, ans2 = min2, ans3 = min3;     for (int i = min1; i < max1; i++) {       if (ans1 + ans2 + ans3 == n) break;       ans1++;     }     for (int i = min2; i < max2; i++) {       if (ans1 + ans2 + ans3 == n) break;       ans2++;     }     for (int i = min3; i < max3; i++) {       if (ans1 + ans2 + ans3 == n) break;       ans3++;     }     cout << ans1 <<     << ans2 <<     << ans3;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long l, r;     cin >> l >> r;     string s_l = to_string(l), s_r = to_string(r);     long long m = s_l.length(), n = s_r.length();     if (m == n) {       long long num = 4, mx = 9;       for (long long i = 1; i < n; i++) {         num = num * 10 + 9;         mx = mx * 10 + 9;       }       if (l > num + 1) {         cout << 1ll * l * (mx - l) << endl;       } else if (r < num) {         cout << 1ll * r * (mx - r) << endl;       } else {         cout << 1ll * num * (mx - num) << endl;       }     } else {       long long num = 4, mx = 9;       for (long long i = 1; i < n; i++) {         num = num * 10 + 9;         mx = mx * 10 + 9;       }       long long final = min(num, r);       cout << 1ll * final * (mx - final) << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     string str;     cin >> n;     cin >> str;     int a = count(str.begin(), str.end(),  A );     int d = n - a;     if (a == d) {       cout <<  Friendship n ;       return 0;     }     a < d ? cout <<  Danik n  : cout <<  Anton n ;     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:16777222 )   using namespace std;   const long long mod = (long long)1e9 + 7;   const int inf = (int)2e9;   const long long INF = (long long)1e18;   const int base = 1000 * 1000 * 1000;   const int maxn = 505;   const long double pi = acosl(-1.0);   const long double eps = 1e-9;   struct matrix {     long long a[2][2];     matrix(){};     matrix(int x1, int x2, int x3, int x4) {       a[0][0] = x1;       a[0][1] = x2;       a[1][0] = x3;       a[1][1] = x4;     }   };   matrix multi(matrix a, matrix b) {     matrix res(0, 0, 0, 0);     for (int i = 0; i < 2; i++)       for (int j = 0; j < 2; j++)         for (int k = 0; k < 2; k++) {           res.a[i][j] = (res.a[i][j] + a.a[i][k] * b.a[k][j]) % mod;         }     return res;   }   matrix fib(int p) {     if (p == 1) return matrix(0, 1, 1, 1);     matrix res = fib(p / 2);     res = multi(res, res);     if (p & 1) res = multi(res, matrix(0, 1, 1, 1));     return res;   }   matrix sum(matrix a, matrix b) {     matrix res(0, 0, 0, 0);     for (int i = 0; i < 2; i++)       for (int j = 0; j < 2; j++) {         res.a[i][j] = (res.a[i][j] + a.a[i][j] + b.a[i][j]) % mod;       }     return res;   }   struct Tree {     vector<matrix> t;     vector<matrix> add;     int size = 1;     void init(vector<int> &d) {       while (size <= (int)d.size()) size <<= 1;       t.resize(size << 1, matrix(0, 0, 0, 0));       add.resize(size << 1, matrix(1, 0, 0, 1));       for (int i = 0; i < (int)d.size(); i++) t[i + size] = fib(d[i]);       for (int i = size - 1; i >= 1; i--) t[i] = sum(t[2 * i], t[2 * i + 1]);     }     void push(int v) {       add[2 * v] = multi(add[2 * v], add[v]);       add[2 * v + 1] = multi(add[2 * v + 1], add[v]);       add[v] = matrix(1, 0, 0, 1);     }     void update(int v) {       t[v] =           sum(multi(t[2 * v], add[2 * v]), multi(t[2 * v + 1], add[2 * v + 1]));     }     matrix get(int v, int l, int r, int L, int R) {       if (L > R) return matrix(0, 0, 0, 0);       if (l == L && r == R) {         return multi(t[v], add[v]);       }       push(v);       int mid = (l + r) / 2;       matrix a = get(2 * v, l, mid, L, min(R, mid));       matrix b = get(2 * v + 1, mid + 1, r, max(L, mid + 1), R);       update(v);       return sum(a, b);     }     void set(int v, int l, int r, int L, int R, matrix val) {       if (L > R) return;       if (l == L && r == R) {         add[v] = multi(add[v], val);         return;       }       push(v);       int mid = (l + r) / 2;       set(2 * v, l, mid, L, min(R, mid), val);       set(2 * v + 1, mid + 1, r, max(L, mid + 1), R, val);       update(v);     }   };   void solve() {     int n, q;     scanf( %d %d , &n, &q);     vector<int> d(n);     for (int i = 0; i < n; i++) scanf( %d , &d[i]);     Tree tree;     tree.init(d);     while (q--) {       int t, l, r;       scanf( %d %d %d , &t, &l, &r);       l--, r--;       if (t == 1) {         int x;         scanf( %d , &x);         tree.set(1, 0, tree.size - 1, l, r, fib(x));       }       if (t == 2) {         printf( %I64d n , tree.get(1, 0, tree.size - 1, l, r).a[0][1]);       }     }   }   int main() {     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e6 + 10;   int ne[MAXN], l[MAXN];   int one[MAXN];   int n;   int g[MAXN];   void D(int *a, int *b) {     for (int i = 0; i < n; i++) g[i] = b[a[i]];     for (int i = 0; i < n; i++) a[i] = g[i];   }   void Pow(int deg) {     int new_deg = 0;     int cnt = 0;     while (deg > 0) {       cnt++;       new_deg *= 2;       new_deg += (deg % 2);       deg /= 2;     }     while (new_deg > 0 || cnt > 0) {       D(one, one);       if (new_deg % 2) D(one, ne);       new_deg /= 2;       cnt--;     }   }   void solve(int k, int d, string &s) {     for (int i = 0; i < n; i++) one[i] = i;     int cnt = 0;     for (int i = 0; i < d; i++)       for (int j = 0; j * d + i < k; j++) ne[j * d + i] = cnt++;     for (int i = k; i < n; i++) ne[i] = i;     for (int i = 0; i < n; i++) l[i] = (i + n - 1) % n;     D(ne, l);     Pow(n + 1 - k);     string ans = s;     for (int i = 0; i < n; i++) ans[(one[i] + n - k + 1) % n] = s[i];     s = ans;     for (int i = 0; i < s.size(); i++) cout << s[i];     cout <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     string s;     getline(cin, s);     n = s.size();     int m;     cin >> m;     for (int i = 0; i < m; i++) {       int k, d;       cin >> k >> d;       solve(k, d, s);     }     return 0;   }


#include <bits/stdc++.h>   const long double pi = acos(-1);   using namespace std;   char a[105][105], row[105], col[105];   bool vis[105];   int main() {     int n, m;     cin >> n >> m;     bool b = false;     if (n == 1) {       cout <<  0 n ;       return 0;     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         cin >> a[i][j];       }     }     int res = 0, sum = 0;     vector<char> ans;     for (int k = 0; k < m; k++) {       vector<string> ve;       for (int i = 0; i < n; i++) {         string s =   ;         for (int j = k; j >= 0; j--) {           if (!vis[j]) s += a[i][j];         }         reverse(s.begin(), s.end());         ve.push_back(s);       }       vector<string> vec;       for (string s : ve) vec.push_back(s);       sort(vec.begin(), vec.end());       if (ve == vec) {         ans.push_back(a[0][k]);         res++;         sum++;         continue;       }       vis[k] = true;       sum = 0;     }     cout << m - res <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1005;   bool vis[N];   vector<int> temp;   int n, t, num;   int ans[N], L[N], R[N];   void pr() {     return;     for (int i = 0; i < n; i++) printf( %d  , ans[i]);     puts(  );     puts(  );   }   void pr2() {     return;     printf( %d n , temp.size());     for (int i = 0; i < temp.size(); i++) printf( %d  , temp[i]);     puts(  );     puts(  );   }   void check() {     for (int i = 0; i < n; i++) {       int c = 0;       for (int j = 0; j < i; j++) c += (ans[j] > ans[i]);       if (c != L[i]) {         printf( NO );         exit(0);       }       c = 0;       for (int j = i; j < n; j++) c += (ans[j] > ans[i]);       if (c != R[i]) {         printf( NO );         exit(0);       }     }   }   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %d , &L[i]);     for (int i = 0; i < n; i++) scanf( %d , &R[i]);     if (L[0] != 0 || R[n - 1] != 0) {       printf( NO );       return 0;     }     num = 0;     pr();     while (num < n) {       temp.clear();       for (int i = 0; i < n; i++) {         if (L[i] + R[i] == num) {           temp.push_back(i);           vis[i] = 1;         }       }       if (temp.empty()) {         printf( NO );         return 0;       }       pr2();       for (int i = 0; i < temp.size(); i++) {         int x = temp[i];         ans[x] = n - num;       }       pr();       num += temp.size();     }     check();     puts( YES );     for (int i = 0; i < n; i++) printf( %d  , ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void maximize(double &a, double b) { a = max(a, b); }   struct point {     long long int x, y;     point() {}     point(long long int x, long long int y) : x(x), y(y) {}   };   long long int prodesc(point p1, point p2) { return p1.x * p2.x + p1.y * p2.y; }   long long int prodvec(point p1, point p2) { return p1.x * p2.y - p1.y * p2.x; }   point operator-(point p1, point p2) { return point(p1.x - p2.x, p1.y - p2.y); }   struct line {     point p, v;     line() {}     line(point p, point v) : p(p), v(v) {}   };   bool belongs(point p, line l) { return prodvec(l.p - p, l.v) == 0; }   int n;   vector<vector<double> > operator*(vector<vector<double> > m1,                                     vector<vector<double> > m2) {     vector<vector<double> > m(n, vector<double>(n, 0));     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++)         for (int k = 0; k < n; k++) m[i][j] += m1[i][k] * m2[k][j];     return m;   }   vector<double> operator*(vector<double> v, vector<vector<double> > m) {     vector<double> r(n, 0);     for (int j = 0; j < n; j++)       for (int i = 0; i < n; i++) r[j] += v[i] * m[i][j];     return r;   }   const int limit = 205;   point p[limit];   int nl;   vector<int> p2l[limit];   vector<int> l2p[limit * limit];   const int tope = 15;   vector<vector<double> > vm[tope];   int main() {     cout.setf(ios::fixed);     cout.precision(10);     ios::sync_with_stdio(false);     cin >> n;     for (int i = 0; i < n; i++) cin >> p[i].x >> p[i].y;     for (int i = 0; i < n; i++) {       for (int j = i + 1; j < n; j++) {         line l(p[i], p[j] - p[i]);         bool error = false;         for (int k = 0; k < j and not error; k++)           error = k != i and belongs(p[k], l);         if (not error) {           for (int k = 0; k < n; k++) {             if (belongs(p[k], l)) {               p2l[k].push_back(nl);               l2p[nl].push_back(k);             }           }           nl++;         }       }     }     vector<vector<double> > m(n, vector<double>(n, 0));     for (int u = 0; u < n; u++) {       vector<int> &vl = p2l[u];       int nvl = int(vl.size());       for (int ivl = 0; ivl < nvl; ivl++) {         int l = vl[ivl];         vector<int> &vu = l2p[l];         int nvu = int(vu.size());         for (int ivu = 0; ivu < nvu; ivu++) {           int v = vu[ivu];           m[v][u] += 1.0 / nvl / nvu;         }       }     }     vm[0] = m;     for (int steps = 1; steps < tope; steps++)       vm[steps] = vm[steps - 1] * vm[steps - 1];     int cases;     cin >> cases;     for (int cas = 0; cas < cases; cas++) {       int p, t;       cin >> p >> t;       p--;       t--;       vector<double> V(n, 0);       V[p] = 1;       for (int b = 0; b < tope; b++)         if (t & (1 << b)) V = V * vm[b];       double sol = 0;       vector<int> vl = p2l[p];       int nvl = int(vl.size());       for (int ivl = 0; ivl < nvl; ivl++) {         int l = vl[ivl];         double pl = 0;         vector<int> &vu = l2p[l];         int nvu = int(vu.size());         for (int ivu = 0; ivu < nvu; ivu++) {           int v = vu[ivu];           pl += 1.0 / nvu * V[v];         }         maximize(sol, pl);       }       cout << sol << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int arr[20];   int mem[20][20][20];   int n, a, b;   int calc(int ind, int p, int c) {     int x0 = arr[ind - 1] - p, x1 = arr[ind] - c, x2 = arr[ind + 1];     int& res = mem[ind][p][c];     if (res != -1) return res;     if (ind == n - 2) {       res = 0;       while (x0 >= 0 || x1 >= 0 || x2 >= 0) {         ++res;         x0 -= b;         x2 -= b;         x1 -= a;       }       return res;     }     res = ((int)1e9);     int cnt = 0;     while (x0 >= 0) {       ++cnt;       x0 -= b;       x2 -= b;       x1 -= a;     }     res = min(res, cnt + calc(ind + 1, arr[ind] - x1, arr[ind + 1] - x2));     while (x0 >= 0 || x1 >= 0 || x2 >= 0) {       ++cnt;       x0 -= b;       x2 -= b;       x1 -= a;       res = min(res, cnt + calc(ind + 1, arr[ind] - x1, arr[ind + 1] - x2));     }     return res = min(res, cnt + calc(ind + 1, arr[ind] - x1, arr[ind + 1] - x2));   }   int sol[20 * 20 * 20];   int sz;   void build(int ind, int p, int c) {     int x0 = arr[ind - 1] - p, x1 = arr[ind] - c, x2 = arr[ind + 1];     if (ind == n - 2) {       while (x0 >= 0 || x1 >= 0 || x2 >= 0) {         sol[sz++] = ind + 1;         x0 -= b;         x2 -= b;         x1 -= a;       }       return;     }     int cnt = 0;     while (x0 >= 0) {       sol[sz++] = ind + 1;       ++cnt;       x0 -= b;       x2 -= b;       x1 -= a;     }     if (calc(ind, p, c) ==         cnt + calc(ind + 1, arr[ind] - x1, arr[ind + 1] - x2)) {       build(ind + 1, arr[ind] - x1, arr[ind + 1] - x2);       return;     }     while (x0 >= 0 || x1 >= 0 || x2 >= 0) {       ++cnt;       x0 -= b;       x2 -= b;       x1 -= a;       sol[sz++] = ind + 1;       if (calc(ind, p, c) ==           cnt + calc(ind + 1, arr[ind] - x1, arr[ind + 1] - x2)) {         build(ind + 1, arr[ind] - x1, arr[ind + 1] - x2);         return;       }     }     if (calc(ind, p, c) ==         cnt + calc(ind + 1, arr[ind] - x1, arr[ind + 1] - x2)) {       build(ind + 1, arr[ind] - x1, arr[ind + 1] - x2);       return;     }   }   int main() {     while (scanf( %d%d%d , &n, &a, &b) != -1) {       for (int i = 0; i < n; ++i) scanf( %d , arr + i);       memset(mem, -1, sizeof mem);       int res = calc(1, 0, 0);       printf( %d n , res);       sz = 0;       build(1, 0, 0);       for (int i = 0; i < sz; ++i) printf(i ?   %d  :  %d , sol[i]);       printf(  n );       fflush(stdout);     }     return 0;   }


#include <bits/stdc++.h>   const int maxn = 1e5 + 5;   int n, k;   int a[maxn];   int main() {     scanf( %d%d , &n, &k);     int ans = 0;     int l = 0;     while (k--) {       bool flag = false;       int m;       scanf( %d , &m);       for (int i = 1; i <= m; i++) {         scanf( %d , &a[i]);         if (a[1] == 1) flag = true;       }       if (flag) {         l = 1;         for (int i = 2; i <= m; i++) {           if (a[i] == (a[i - 1] + 1))             l++;           else             break;         }         ans += m - l;       } else         ans += m - 1;     }     ans += n - l;     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 3e4 + 10, M = 1e3 + 10;   long long n, p[N], d, dp[N][M + 10];   long long solve(long long pos, long long L) {     if (pos > 30000) return 0;     long long wh = L - d + M / 2;     if (dp[pos][wh] != -1) return dp[pos][wh];     long long ret = 0;     if (L == 1)       ret = max(solve(pos + L, L), solve(pos + L + 1, L + 1));     else       ret = max({solve(pos + L - 1, L - 1), solve(pos + L, L),                  solve(pos + L + 1, L + 1)});     ret += p[pos];     dp[pos][wh] = ret;     return ret;   }   int main() {     for (long long i = 0; i < N; i++)       for (long long j = 0; j < M; j++) dp[i][j] = -1;     cin >> n >> d;     for (long long i = 1; i <= n; i++) {       long long x;       cin >> x;       p[x]++;     }     cout << solve(d, d) <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   ostream& operator<<(ostream& s, vector<T> const& v) {     s <<  { ;     for (int i = 0; i < int(v.size()); i++) s << (i ?  ,  :   ) << v[i];     return s <<  } ;   }   template <typename S, typename T>   ostream& operator<<(ostream& s, pair<S, T> const& p) {     return s <<  (  << p.first <<  ,  << p.second <<  ) ;   }   constexpr int MAXN = 100005;   long long minSum(long long n, long long b, long long init, long long l) {     if (b == 1) return ((n + 1) * (n + 2)) / 2 - 1;     long long rem = n, clev = init, ans = 0;     while (rem > 0) {       long long use = min(rem, clev);       rem -= use;       ans += l * use;       clev *= b;       ++l;     }     return ans;   }   bool sv() {     long long N, S;     scanf( %lld%lld , &N, &S);     long long maxBr = 1;     while (maxBr < N && 1 + minSum(N - 1, maxBr, maxBr, 2) > S) ++maxBr;     if (maxBr == N) return false;     long long remN = N - 1, remS = S - 1, curlev = 2, plev = 1;     vector<long long> layers;     while (remN > 0) {       long long a = 0, b = plev * maxBr;       while (b - a > 1) {         long long c = (a + b) / 2;         if (minSum(remN, maxBr, c, curlev) > remS)           a = c;         else           b = c;       }       layers.push_back(b);       remN -= b;       remS -= curlev * b;       ++curlev;       plev = b;     }     if (remS) return false;     vector<int> ans(N);     long long cur = 1;     for (int i = 0; i < int(layers.size()); i++) {       long long pLayer = i ? layers[i - 1] : 1;       long long oldCur = cur;       long long rem = layers[i];       for (int j = oldCur - pLayer; j < int(oldCur); j++) {         for (int k = 0; k < int(maxBr); k++) {           if (rem > 0) {             ans[cur] = j;             --rem;             ++cur;           } else {             goto dn;           }         }       }     dn:;     }     puts( Yes );     for (int i = 1; i < int(N); i++)       printf( %d%c , ans[i] + 1, i == N - 1 ?   n  :    );     return true;   }   int main() {     if (!sv()) puts( No );   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e3 + 3;   int n, l;   double ans, a[N];   int main() {     scanf( %d %d , &n, &l);     for (int i = 0; i < n; ++i) scanf( %lf , a + i);     sort(a, a + n);     if (a[0] != 0) ans = a[0];     if (a[n - 1] != l) ans = max(ans, l - a[n - 1]);     for (int i = 0; i < n - 1; ++i) {       ans = max(ans, (a[i + 1] - a[i]) / 2);     }     printf( %.10lf n , ans);   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9;   const int MOD = 1e9 + 7;   const int MAXN = 1e6 + 5;   const double eps = 1e-14;   int a[MAXN];   void solve() {     int n;     cin >> n;     for (int i = 1; i <= 9; i++) {       cin >> a[i];     }     int mn = a[1], ciph = 1;     for (int i = 2; i <= 9; i++) {       if (a[i] <= mn) {         mn = min(mn, a[i]);         ciph = i;       }     }     char c = ciph +  0 ;     int q = n / mn;     int r = n % mn;     string s =   ;     for (int i = 0; i < q; i++) s += c;     for (int i = 0; i < q; i++) {       for (int j = 9; j >= 1; j--) {         if (r >= a[j] - mn) {           r -= (a[j] - mn);           s[i] = j +  0 ;           break;         }       }     }     if (s.empty())       cout << -1;     else       cout << s;   }   int main() {     if (!1) {       freopen(            474             .in ,            r , stdin);       freopen(            474             .out ,            w , stdout);     }     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t = (228 & 322) >> 6;     while (t--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     double x1, y1, x2, y2;     cin >> x1 >> y1 >> x2 >> y2;     double vmax, t0, vx, vy, wx, wy;     cin >> vmax >> t0 >> vx >> vy >> wx >> wy;     double dx = (x2 - x1);     double dy = (y2 - y1);     double l = 0, r = 1e16;     double ans = 1e16;     for (int i = 0; i < 200; i++) {       double t = (l + r) / 2;       double xx = vx * (t0 < t ? t0 : t);       double yy = vy * (t0 < t ? t0 : t);       if (t > t0) {         xx += wx * (t - t0);         yy += wy * (t - t0);       }       if ((xx - dx) * (xx - dx) + (yy - dy) * (yy - dy) > vmax * vmax * t * t)         l = t;       else {         r = t;         ans = t;       }     }     printf( %.12f n , ans);   }


#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 1e5 + 10, MOD = 1e9 + 7;   int n, x[MAX_N], y[MAX_N], ordered_x[MAX_N], ordered_y[MAX_N], x_n, y_n,       ans = 1;   int fa[MAX_N * 2], node_cnt[MAX_N * 2], edge_cnt[MAX_N * 2];   void init() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d%d , &x[i], &y[i]);       ordered_x[i] = x[i];       ordered_y[i] = y[i];     }     sort(ordered_x + 1, ordered_x + n + 1);     x_n = unique(ordered_x + 1, ordered_x + n + 1) - ordered_x - 1;     for (int i = 1; i <= n; i++)       x[i] = lower_bound(ordered_x + 1, ordered_x + x_n + 1, x[i]) - ordered_x;     sort(ordered_y + 1, ordered_y + n + 1);     y_n = unique(ordered_y + 1, ordered_y + n + 1) - ordered_y - 1;     for (int i = 1; i <= n; i++)       y[i] = lower_bound(ordered_y + 1, ordered_y + y_n + 1, y[i]) - ordered_y;     for (int i = 1; i <= x_n + y_n; i++) fa[i] = i;   }   int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); }   void merge(int a, int b) { fa[find(a)] = find(b); }   void solve() {     for (int i = 1; i <= n; i++) merge(x[i], x_n + y[i]);     for (int i = 1; i <= x_n; i++) node_cnt[find(i)]++;     for (int i = 1; i <= y_n; i++) node_cnt[find(x_n + i)]++;     for (int i = 1; i <= n; i++) edge_cnt[find(x[i])]++;     for (int i = 1; i <= x_n + y_n; i++) {       if (fa[i] != i) continue;       int fac = 1;       for (int j = 1; j <= node_cnt[i]; j++) fac = fac * 2 % MOD;       if (edge_cnt[i] < node_cnt[i]) fac--;       ans = (long long)ans * fac % MOD;     }     printf( %d n , ans);   }   int main() {     init();     solve();   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1000000001;   template <class T, class U>   ostream &operator<<(ostream &out, const pair<T, U> &p) {     return out << p.first <<     << p.second;   }   template <class T>   ostream &operator<<(ostream &out, const vector<T> &v) {     for (typeof((v).begin()) i = ((v).begin()); i != (v).end(); ++i) {       out << *i <<    ;     }     return out;   }   template <class T, class U>   istream &operator>>(istream &in, pair<T, U> &p) {     return in >> p.first >> p.second;   }   template <class T>   istream &operator>>(istream &in, vector<T> &v) {     for (typeof((v).begin()) i = ((v).begin()); i != (v).end(); ++i) {       in >> (*i);     }     return in;   }   template <class T>   ostream &operator,(ostream &out, const T &t) {     return out << t;   }   template <class T>   istream &operator,(istream &in, T &t) {     return in >> t;   }   int io_init() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cout, fixed, setprecision(9);     return 1;   }   int _io_dummy = io_init();   template <class T, class U>   bool remin(T &a, const U &b) {     return b < a ? a = b, true : false;   }   template <class T, class U>   bool remax(T &a, const U &b) {     return b > a ? a = b, true : false;   }   const int N = 1000000;   int D[N];   void calcPrimes(int n = N) {     for (int i = 2; i * i < n; ++i) {       if (D[i]) {         continue;       }       for (int j = i * i; j < n; j += i) {         D[j] = i;       }     }   }   bool isPrime(int x) { return x > 1 && D[x] == 0; }   int rev(int x) {     ostringstream oss;     oss, x;     string s = oss.str();     reverse((s).begin(), (s).end());     istringstream iss(s);     iss, x;     return x;   }   int main() {     calcPrimes();     string s =          qd ucyhf yi q fhycu dkcruh mxeiu huluhiu yi q tyvvuhudj fhycu dkcruh.            oekh jqia yi je vydt jxu djx ucyhf. n ;     s +=  jxu ydfkj sediyiji ev q iydwbu ydjuwuh d (1 <= d <= 11184) - jxu             edu-rqiut ydtun ev jxu ucyhf je vydt n ;     s +=  ekjfkj q iydwbu dkcruh. ;     for (int i = 0; i < (10); ++i) {       for (typeof((s).begin()) c = ((s).begin()); c != (s).end(); ++c) {         if (!isalpha(*c)) continue;         if ((*c)++ ==  z ) *c =  a ;       }     }     cerr, s,   n ;     int x;     cin, x;     int n = 0, r;     for (int i = 13; i < N; i += 2) {       if (isPrime(i) && (r = rev(i)) != i && isPrime(r)) {         ++n;         if (n == x) {           cout, i,   n ;           break;         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   const int MAXN = 1e6 + 10;   pair<int, pair<int, int> > A[MAXN];   int HX[MAXN], HY[MAXN];   int fa[MAXN];   int X[MAXN], Y[MAXN];   int ans[MAXN];   int Find(int x) { return fa[x] == x ? x : fa[x] = Find(fa[x]); }   void uni(int x, int y) {     int fx = Find(x), fy = Find(y);     if (fx != fy) {       fa[fx] = fy;     }   }   int main() {     while (scanf( %d%d , &n, &m) != EOF) {       for (int i = 0; i < n * m; i++) {         fa[i] = i;       }       for (int i = 0; i < n * m; i++) {         scanf( %d , &A[i].first);         A[i].second.first = i / m;         A[i].second.second = i % m;       }       sort(A, A + n * m);       memset(ans, 0, sizeof(ans));       int j = -1;       for (int i = j + 1; i < n * m; i++) {         if (i + 1 < n * m && A[i].first == A[i + 1].first) continue;         for (int k = j + 1; k <= i; k++) {           int p = A[k].second.first * m + A[k].second.second;           int x = A[k].second.first, y = A[k].second.second;           HX[x] = p;           HY[y] = p;         }         for (int k = j + 1; k <= i; k++) {           int p = A[k].second.first * m + A[k].second.second;           int x = A[k].second.first, y = A[k].second.second;           uni(HX[x], p);           uni(HY[y], p);         }         for (int k = j + 1; k <= i; k++) {           int p = A[k].second.first * m + A[k].second.second;           int x = A[k].second.first, y = A[k].second.second;           int fp = Find(p);           ans[fp] = max(ans[fp], max(X[x], Y[y]) + 1);         }         for (int k = j + 1; k <= i; k++) {           int p = A[k].second.first * m + A[k].second.second;           int x = A[k].second.first, y = A[k].second.second;           int fp = Find(p);           X[x] = max(X[x], ans[fp]);           Y[y] = max(Y[y], ans[fp]);         }         j = i;       }       for (int i = 0; i < n * m; i++) {         printf( %d  , ans[Find(i)]);         if (i % m == m - 1) puts(  );       }     }   }


#include <bits/stdc++.h>   using namespace std;   int n, i;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n;     for (i = 2; i <= n; i++) cout << i <<    ;     cout <<  1  <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int p2[203];   int p5[203];   int dpcur[203][5003][2];   int dpnxt[203][5003][2];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     int n, k;     cin >> n >> k;     for (int i = 1; i <= n; i++) {       long long int x;       cin >> x;       while (x % 2 == 0) {         x /= 2;         p2[i]++;       }       while (x % 5 == 0) {         x /= 5;         p5[i]++;       }     }     memset(dpcur, -1, sizeof(dpcur));     memset(dpnxt, -1, sizeof(dpnxt));     dpcur[k][0][0] = 0;     if (p2[1] >= p5[1]) {       dpcur[k - 1][p2[1] - p5[1]][0] = p5[1];     } else {       dpcur[k - 1][p5[1] - p2[1]][1] = p2[1];     }     for (int i = 2; i <= n; i++) {       for (int K = k; K >= max(0, k - (i - 1)); K--) {         for (int excess_cnt = 0; excess_cnt <= min(5000, 60 * (i - 1));              excess_cnt++) {           if (dpcur[K][excess_cnt][0] != -1) {             dpnxt[K][excess_cnt][0] =                 max(dpnxt[K][excess_cnt][0], dpcur[K][excess_cnt][0]);             int cnt2 = p2[i] + excess_cnt;             int cnt5 = p5[i];             if (cnt2 >= cnt5 && K - 1 >= 0) {               dpnxt[K - 1][min(cnt2 - cnt5, 5000)][0] =                   max(dpnxt[K - 1][min(cnt2 - cnt5, 5000)][0],                       dpcur[K][excess_cnt][0] + cnt5);             } else if (cnt5 > cnt2 && K - 1 >= 0) {               dpnxt[K - 1][min(cnt5 - cnt2, 5000)][1] =                   max(dpnxt[K - 1][min(cnt5 - cnt2, 5000)][1],                       dpcur[K][excess_cnt][0] + cnt2);             }           }           if (dpcur[K][excess_cnt][1] != -1) {             dpnxt[K][excess_cnt][1] =                 max(dpnxt[K][excess_cnt][1], dpcur[K][excess_cnt][1]);             int cnt2 = p2[i];             int cnt5 = p5[i] + excess_cnt;             if (cnt2 >= cnt5 && K - 1 >= 0) {               dpnxt[K - 1][min(cnt2 - cnt5, 5000)][0] =                   max(dpnxt[K - 1][min(cnt2 - cnt5, 5000)][0],                       dpcur[K][excess_cnt][1] + cnt5);             } else if (cnt5 > cnt2 && K - 1 >= 0) {               dpnxt[K - 1][min(cnt5 - cnt2, 5000)][1] =                   max(dpnxt[K - 1][min(cnt5 - cnt2, 5000)][1],                       dpcur[K][excess_cnt][1] + cnt2);             }           }         }       }       for (int K = k; K >= max(0, k - i); K--) {         for (int excess_cnt = 0; excess_cnt <= min(5000, 60 * i); excess_cnt++) {           for (int excess = 0; excess <= 1; excess++) {             dpcur[K][excess_cnt][excess] = dpnxt[K][excess_cnt][excess];           }         }       }       memset(dpnxt, -1, sizeof(dpnxt));     }     int ans = 0;     for (int excess_cnt = 0; excess_cnt <= 5000; excess_cnt++) {       for (int excess = 0; excess <= 1; excess++) {         ans = max(ans, dpcur[0][excess_cnt][excess]);       }     }     cout << ans <<   n ;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx )   using namespace std;   const long long mod = 998244353;   long long binpow(long long a, long long n) {     if (n == 0) return 1;     if (n % 2 == 1) {       return (binpow(a, n - 1) * a) % mod;       ;     } else {       long long b = binpow(a, n / 2);       return (b * b) % mod;     }   }   long long f[500];   long long f_obr[500];   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     f[0] = 1;     f_obr[0] = 1;     for (long long i = 1; i < 500; ++i) {       f[i] = f[i - 1] * i;       f[i] %= mod;       f_obr[i] = binpow(f[i], mod - 2);     }     long long d;     cin >> d;     vector<long long> pr;     pr.reserve(1e7 + 5);     for (long long i = 2; i * i <= d; ++i) {       if (d % i == 0) {         pr.push_back(i);         while (d % i == 0) d /= i;       }     }     if (d > 1) pr.push_back(d);     int q;     cin >> q;     for (int i = 0; i < q; ++i) {       long long v[2];       cin >> v[0] >> v[1];       vector<long long> vc[2];       vector<int> cnt[2];       for (int j = 0; j < 2; ++j)         for (int k = 0; k < int(pr.size()); ++k)           if (v[j] % pr[k] == 0) {             vc[j].push_back(pr[k]);             cnt[j].push_back(0);             while (v[j] % pr[k] == 0) {               cnt[j].back()++;               v[j] /= pr[k];             }           }       int uk = 0;       vector<int> res[2];       for (int j = 0; j < int(cnt[0].size()); ++j) {         while (uk < int(cnt[1].size()) && vc[1][uk] <= vc[0][j]) {           if (vc[1][uk] == vc[0][j]) {             if (cnt[0][j] > cnt[1][uk])               res[0].push_back(cnt[0][j] - cnt[1][uk]);             else               res[1].push_back(cnt[1][uk] - cnt[0][j]);           } else             res[1].push_back(cnt[1][uk]);           ++uk;         }         if (!(uk > 0 && vc[1][uk - 1] == vc[0][j])) res[0].push_back(cnt[0][j]);       }       while (uk < int(cnt[1].size())) {         res[1].push_back(cnt[1][uk]);         ++uk;       }       int sum[2];       sum[0] = 0;       sum[1] = 0;       long long ans = 1;       for (int j = 0; j < 2; ++j)         for (int k = 0; k < int(res[j].size()); ++k) {           sum[j] += res[j][k];           ans *= f_obr[res[j][k]];           ans %= mod;         }       ans *= f[sum[0]];       ans %= mod;       ans *= f[sum[1]];       ans %= mod;       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, m, a[1000001], mx[1000001], cnt, maxi, ans;   int main() {     cin >> n;     for (long long i = 1; i <= n; ++i) {       cin >> a[i];       mx[i] = -1;       for (long long j = 1; j <= a[i]; ++j) {         long long k;         cin >> k;         mx[i] = max(mx[i], k);       }     }     for (long long i = 1; i <= n; ++i) {       maxi = max(maxi, mx[i]);     }     for (long long i = 1; i <= n; ++i) {       cnt += (maxi - mx[i]) * a[i];     }     cout << cnt;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     long long int n, i, x;     cin >> n;     long long int a[2 * n];     for (i = 0; i < 2 * n; i++) {       cin >> a[i];     }     sort(a, a + 2 * n);     x = (a[n - 1] - a[0]) * (a[2 * n - 1] - a[n]);     for (i = 0; i < n; i++) {       x = min(x, (a[i + n - 1] - a[i]) * (a[2 * n - 1] - a[0]));     }     cout << x;   }


#include <bits/stdc++.h>   using namespace std;   char a[300099];   char ans[300099];   int c[200000];   int b;   int main() {     while (~scanf( %s , a)) {       memset(c, 0, sizeof(c));       scanf( %d , &b);       int len = strlen(a);       for (int i = 0; i < b; i++) {         int pt;         scanf( %d , &pt);         pt--;         c[pt]++;       }       for (int i = 0; i < len / 2; i++) {         if (i == 0) {           if (c[i] % 2)             ans[i] = a[len - 1 - i], ans[len - 1 - i] = a[i];           else             ans[i] = a[i], ans[len - 1 - i] = a[len - 1 - i];         } else {           c[i] += c[i - 1];           if (c[i] % 2)             ans[i] = a[len - 1 - i], ans[len - 1 - i] = a[i];           else             ans[i] = a[i], ans[len - 1 - i] = a[len - 1 - i];         }       }       if (len % 2) ans[len / 2] = a[len / 2];       ans[len] =   0 ;       printf( %s n , ans);     }     return 0;   }


#include <bits/stdc++.h>   const int P = 998244353;   using namespace std;   template <typename T>   inline void ckmax(T &a, T b) {     (a < b) && (a = b);   }   template <typename T>   inline void ckmin(T &a, T b) {     (a > b) && (a = b);   }   inline int mul(int a, int b) { return 1ll * a * b % P; }   inline int add(int a, int b) { return a + b >= P ? a + b - P : a + b; }   inline int sub(int a, int b) { return a - b >= 0 ? a - b : a - b + P; }   inline void mulmod(int &a, int b) { a = mul(a, b); }   inline void addmod(int &a, int b) { ((a += b) >= P) && (a -= P); }   inline void submod(int &a, int b) { ((a -= b) < 0) && (a += P); }   inline int ksm(int a, int b) {     int ans = 1;     for (; b; b >>= 1) {       if (b & 1) ans = 1ll * ans * a % P;       a = 1ll * a * a % P;     }     return ans;   }   inline int inv(int a) { return ksm(a, P - 2); }   namespace FastIO {   const int SIZE = 1 << 16;   char buf[SIZE], obuf[SIZE], str[64];   int bi = SIZE, bn = SIZE, opt;   int read(char *s) {     while (bn) {       for (; bi < bn && buf[bi] <=    ; bi++)         ;       if (bi < bn) break;       bn = fread(buf, 1, SIZE, stdin), bi = 0;     }     int sn = 0;     while (bn) {       for (; bi < bn && buf[bi] >    ; bi++) s[sn++] = buf[bi];       if (bi < bn) break;       bn = fread(buf, 1, SIZE, stdin), bi = 0;     }     s[sn] = 0;     return sn;   }   bool read(int &x) {     if (x) x = 0;     int bf = 0, n = read(str);     if (!n) return 0;     int i = 0;     if (str[i] ==  - ) bf = 1, i = 1;     for (x = 0; i < n; i++) x = x * 10 + str[i] -  0 ;     if (bf) x = -x;     return 1;   }   void write(int x) {     if (!x)       obuf[opt++] =  0 ;     else {       if (x < 0) obuf[opt++] =  - , x = -x;       int sn = 0;       while (x) str[sn++] = x % 10 +  0 , x /= 10;       for (int i = sn - 1; i >= 0; i--) obuf[opt++] = str[i];     }     if (opt >= (SIZE >> 1)) {       fwrite(obuf, 1, opt, stdout);       opt = 0;     }   }   void write(char x) {     obuf[opt++] = x;     if (opt >= (SIZE >> 1)) {       fwrite(obuf, 1, opt, stdout);       opt = 0;     }   }   void Fflush() {     if (opt) fwrite(obuf, 1, opt, stdout);     opt = 0;   }   };  // namespace FastIO   inline int read() {     int x;     FastIO::read(x);     return x;   }   const int MN = 1e5 + 5;   int n, dis[MN], dx, dy;   vector<pair<int, int> > e[MN];   void dfs1(int op, int u, int fa) {     if (op == 0 && dis[u] > dis[dx]) dx = u;     if (op == 1 && dis[u] > dis[dy]) dy = u;     for (auto it : e[u]) {       int v = it.first, w = it.second;       if (v == fa) continue;       dis[v] = dis[u] + w;       dfs1(op, v, u);     }   }   struct Tr {     int f[MN][21], g[MN][21], len[MN], top[MN], rk[MN], rt, lf[MN], s[MN], cnt,         sum[MN], lson[MN];     void dfs1(int u, int fa, int fr) {       f[u][0] = fa, g[u][0] = fr;       for (int i = 1; i <= 20; i++)         f[u][i] = f[f[u][i - 1]][i - 1],         g[u][i] = g[f[u][i - 1]][i - 1] + g[u][i - 1];       for (auto it : e[u]) {         int v = it.first, w = it.second;         if (v == fa) continue;         dfs1(v, u, w);         ckmax(len[u], len[v] + w);       }     }     void dfs2(int u, int tp) {       top[u] = tp;       lson[u] = 0;       for (auto it : e[u]) {         int v = it.first, w = it.second;         if (v != f[u][0] && len[v] + w == len[u]) lson[u] = v;       }       if (!lson[u]) return void();       dfs2(lson[u], tp);       for (auto it : e[u]) {         int v = it.first;         if (v != f[u][0] && v != lson[u])           s[lf[++cnt] = v] = len[v] + it.second, dfs2(v, v);       }     }     void init() {       dfs1(rt, 0, 0);       dfs2(rt, rt);       s[lf[++cnt] = rt] = len[rt];       sort(lf + 1, lf + 1 + cnt, [&](int i, int j) { return s[i] > s[j]; });       for (int i = (1); i <= (cnt); i++) {         int u = lf[i];         sum[i] = sum[i - 1] + s[u];         while (u) rk[u] = i, u = lson[u];       }     }     int qry(int x, int y) {       y = 2 * y - 1;       if (rk[x] <= y)         return sum[y];       else {         int z = len[x];         for (int i = 20; i >= 0; i--) {           if (rk[f[x][i]] > y) z += g[x][i], x = f[x][i];         }         return max(sum[y - 1] + z + g[x][0], sum[y] - len[f[x][0]] + z + g[x][0]);       }     }   } t[2];   signed main() {     int q, k = 0, s = 0;     n = read(), q = read();     for (int i = (1); i <= (n - 1); i++) {       int u = read(), v = read(), w = read();       e[u].push_back(make_pair(v, w)), e[v].push_back(make_pair(u, w));       s += w;     }     for (int i = (1); i <= (n); i++) k += e[i].size() == 1;     dfs1(0, 1, 0);     memset(dis, 0, sizeof(dis));     dfs1(1, dx, 0);     t[0].rt = dx, t[1].rt = dy;     t[0].init();     t[1].init();     int lstans = 0;     while (q--) {       int x = (read() + lstans - 1) % n + 1, y = (read() + lstans - 1) % n + 1;       if (2 * y >= k)         printf( %d n , lstans = s);       else         printf( %d n , lstans = max(t[0].qry(x, y), t[1].qry(x, y)));     }     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   const int maxn = 300100;   int n, m, a[maxn], ans = -1;   int f[maxn][30], du[maxn], Time;   char s[maxn];   int dfn[maxn], low[maxn];   vector<int> g[maxn];   vector<int>::iterator it;   bool loop = 0, in[maxn];   stack<int> q;   void dfs(int x) {     dfn[x] = low[x] = ++Time;     in[x] = 1;     q.push(x);     for (int i = 0; i < g[x].size(); ++i) {       int k = g[x][i];       if (!dfn[k]) {         dfs(k);         low[x] = min(low[x], low[k]);       } else if (in[k] && dfn[k] < low[x]) {         low[x] = min(low[x], dfn[k]);       }       for (int j = 0; j < 26; ++j) {         f[x][j] = max(f[x][j], f[k][j]);       }     }     if (dfn[x] == low[x]) {       int cnt = 0;       while (1) {         int tem = q.top();         q.pop();         cnt++;         in[tem] = 0;         if (tem == x) break;       }       if (cnt > 1) loop = 1;     }     ++f[x][a[x]];   }   int main() {     scanf( %d%d , &n, &m);     scanf( %s , s + 1);     for (int i = 1; i <= n; ++i) {       a[i] = s[i] -  a ;     }     for (int i = 1, x, y; i <= m; ++i) {       scanf( %d%d , &x, &y);       if (x == y) loop = 1;       g[x].push_back(y), du[y]++;     }     if (loop) {       printf( -1 n );       return 0;     }     for (int i = 1; i <= n; ++i) {       if (!du[i]) {         dfs(i);         if (loop == 1) {           printf( -1 n );           return 0;         }         for (int j = 0; j < 26; ++j) {           ans = max(f[i][j], ans);         }       }     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int P;   long long int a[501];   long long int dp[501][501];   void solve() {     long long int n, m, b, P, i, j, k;     cin >> n >> m >> b >> P;     for (i = 1; i <= n; i++) {       cin >> a[i];     }     memset(dp, 0, sizeof(dp));     long long int ans = 0;     dp[0][0] = 1;     for (i = 1; i <= n; i++) {       for (j = 0; j < m; j++) {         for (k = 0; k + a[i] <= b; k++) {           dp[j + 1][k + a[i]] = (dp[j + 1][k + a[i]] + dp[j][k]) % P;         }       }     }     for (i = 0; i <= b; i++) {       ans += dp[m][i];       ans %= P;     }     cout << ans % P;   }   int main() {     long long int t = 1;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxp = 22;   const long double EPS = 1e-18;   const long long INF = 2e18;   const int MOD = 1e9 + 7;   const int N = 2e5 + 1;   string s, t =  hard ;   long long dp[N][4];   long long arr[N];   int n;   long long solve(int x, int idx) {     if (idx == 4) return INF;     if (x == n) return 0;     if (dp[x][idx] != -1) return dp[x][idx];     int nxt = idx;     if (s[x] == t[idx]) nxt++;     return dp[x][idx] = min(solve(x + 1, idx) + arr[x], solve(x + 1, nxt));   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cin >> n >> s;     int i, j;     for (i = 0; i < n; i++) cin >> arr[i];     for (i = 0; i < n; i++)       for (j = 0; j < 4; j++) dp[i][j] = -1;     cout << solve(0, 0) <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 4e5 + 10;   int mod = 1e9 + 7;   int qpow(int a, int b) {     int ans = 1;     for (; b >= 1; b >>= 1, a = (long long)a * a % mod)       if (b & 1) ans = (long long)ans * a % mod;     return ans;   }   long long ans[32];   int main() {     int t;     scanf( %d , &t);     while (t--) {       int d, m, c;       scanf( %d%d , &d, &mod);       fill(ans, ans + 30, 0);       for (c = 0; (1 << (c + 1)) <= d; c++)         ;       for (int i = 0; i < c; i++) ans[i] = (1ll << i) % mod;       ans[c] = (d - (1ll << c) + 1) % mod;       long long res = 1;       for (int i = 0; i <= c; i++) res = res * (ans[i] + 1ll) % mod;       res = (res + mod - 1) % mod;       printf( %lld n , res);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long r, g, b;     cin >> r >> g >> b;     long long ans = min(r, min(g, b));     long long mini = ans;     if (r <= 3 && g <= 3 && b <= 3) {       cout << ans << endl;       return 0;     }     long long count = 0;     r = r - ans;     g = g - ans;     b = b - ans;     if (r % 3 == 2) {       ++count;     }     if (g % 3 == 2) {       ++count;     }     if (b % 3 == 2) {       ++count;     }     ans += (r / 3) + (g / 3) + (b / 3);     if (count == 2 && mini != 0) {       ++ans;     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   int const M = 4e5 + 20;   int a[M], ans[M], l[M], r[M], ty[M], cnt[M], sv[M];   vector<pair<int, int> > qu[M];   int main() {     int n, q;     cin >> n >> q;     for (int i = 1; i <= n; i++) cin >> a[i];     for (int i = 1; i <= q; i++) {       int ind, nu;       cin >> ind >> nu;       qu[ind].push_back(make_pair(nu, i));       sv[i] = ind;     }     vector<int> lis;     for (int i = 1; i <= n; i++) {       qu[i].push_back(make_pair(a[i], 0));       for (int j = 0; j < qu[i].size(); j++) {         int now = qu[i][j].first;         if (lis.size() == 0 || now > lis.back()) {           ans[qu[i][j].second] = (int)lis.size() + 1;         } else {           int ind = lower_bound(lis.begin(), lis.end(), now) - lis.begin();           ans[qu[i][j].second] = ind + 1;         }         if (j == (int)qu[i].size() - 1) {           l[i] = ans[0];           if (ans[0] == (int)lis.size() + 1)             lis.push_back(a[i]);           else             lis[ans[0] - 1] = a[i];         }       }     }     int best = lis.size();     lis.clear();     for (int i = n; i >= 1; i--) {       for (int j = 0; j < qu[i].size(); j++) {         int now = qu[i][j].first;         now = -now;         if (lis.size() == 0 || now > lis.back()) {           ans[qu[i][j].second] += (int)lis.size();           if (j == (int)qu[i].size() - 1) {             r[i] = (int)lis.size() + 1;             lis.push_back(now);           }         } else {           int ind = lower_bound(lis.begin(), lis.end(), now) - lis.begin();           ans[qu[i][j].second] += ind;           if (j == (int)qu[i].size() - 1) {             r[i] = ind + 1;             lis[ind] = now;           }         }       }     }     for (int i = 1; i <= n; i++) {       if (l[i] + r[i] != best + 1) {         ty[i] = 3;       } else         cnt[l[i]]++;     }     for (int i = 1; i <= n; i++) {       if (ty[i] != 3 && cnt[l[i]] > 1)         ty[i] = 2;       else if (ty[i] != 3)         ty[i] = 1;     }     for (int i = 1; i <= q; i++) {       int tmp = ans[i];       if (ty[sv[i]] == 1)         tmp = max(tmp, best - 1);       else         tmp = max(tmp, best);       cout << tmp <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int v[4005], d[14005];   long long int p[4005];   bool done[4005];   vector<int> vec;   int main() {     int n, val, ans = 0;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> v[i] >> d[i] >> p[i];     }     for (int i = 0; i < n; i++) {       if (done[i]) continue;       vec.push_back(i + 1);       ans++;       val = 0;       for (int j = i + 1; j < n; j++) {         if (!done[j]) {           if (val == v[i]) break;           p[j] -= v[i] - val;           val++;         }       }       long long int val = 0;       for (int j = i + 1; j < n; j++) {         if (done[j] == 1) continue;         p[j] -= val;         if (p[j] < 0) {           val += d[j];           done[j] = 1;         }       }     }     sort(vec.begin(), vec.end());     cout << ans << endl;     for (int i = 0; i < vec.size(); i++) cout << vec[i] <<    ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     string s;     int total = 0;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> s;       if (s ==  ++X  || s ==  X++ ) {         total++;       } else {         total--;       }     }     cout << total;   }


#include <bits/stdc++.h>   using namespace std;   long long cnt[200010];   void f(long long x) {     while (x) {       cnt[x]++;       x /= 2;     }     cnt[0]++;   }   long long count(long long x, long long y) {     long long sol = INT32_MAX, cnt = 0;     while (x != y) {       if (!x) break;       ++cnt;       x /= 2;     }     if (!x && y) return sol;     return cnt;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     cerr.tie(nullptr);     long long n, k;     cin >> n >> k;     vector<long long> a(n);     long long maxi = 0;     for (auto& i : a) {       cin >> i;       f(i);       maxi = max(maxi, i);     }     long long sol = INT32_MAX;     for (long long i = 0; i <= maxi; ++i) {       if (cnt[i] < k) continue;       long long res = 0;       vector<long long> t;       for (long long j = 0; j < n; ++j) {         t.push_back(count(a[j], i));       }       sort(t.begin(), t.end());       for (long long j = 0; j < k; ++j) res += t[j];       sol = min(sol, res);     }     cout << sol <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   struct comp {     bool operator()(const vector<int>& lhs, const vector<int>& rhs) const {       return lhs.size() > rhs.size();     }   };   struct comps {     bool operator()(const string& lhs, const string& rhs) const {       return lhs > rhs;     }   };   bool ff(pair<int, int> a, pair<int, int> b) { return a.first < b.first; }   double dis(double x1, double y1, double x2, double y2) {     return sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));   }   int gcd(long long unsigned int a, long long unsigned int b) {     return (b == 0) ? a : gcd(b, a % b);   }   int comb(int a, int b) {     if (a == 0) return 1;     if (a < b) return 1;     if (a == b) return 1;     if (b == 1) return a;     if (b == 0) return 1;     long long unsigned int aa = 1, bb = 1;     for (int i = b; i > 0; i--, a--) {       aa *= a;       bb *= i;       int gc = gcd(aa, bb);       if (gc > 1) {         aa /= gc;         bb /= gc;       }     }     return aa % 1000000007;   }   bool isprime(long long unsigned int n) {     for (int i = 2; i <= sqrt(n); i++)       if (n % i == 0) return false;     return true;   }   bool f(pair<int, int> p1, pair<int, int> p2) {     if (p1.first < p2.first)       return true;     else if ((p1.first == p2.first) && (p1.second > p2.second))       return true;     else       return false;   }   int t[100005];   int x[100005];   int v[100005];   int main() {     int n, m;     scanf( %d%d , &n, &m);     for (int i = 0; i < n; i++) cin >> t[i] >> x[i];     int i = 0;     int nn = n;     int kalkis = 0;     int delay = 0;     while (n > 0) {       int p = (n >= m) ? m : n;       n -= p;       kalkis =           (t[i + p - 1] > (kalkis + delay)) ? t[i + p - 1] : (kalkis + delay);       map<int, int> mapp;       map<int, vector<int> > duranlar;       for (int j = i; j < i + p; j++) {         mapp[x[j]]++;         duranlar[x[j]].push_back(j);       }       map<int, int>::iterator it;       delay = 0;       for (it = mapp.begin(); it != mapp.end(); it++) {         for (int k = 0; k < duranlar[it->first].size(); k++) {           v[duranlar[it->first][k]] = kalkis + delay + (it->first);         }         delay += 1 + (it->second) / 2;       }       it--;       delay += 2 * (it->first);       i += p;     }     for (int i = 0; i < nn; i++) cout << v[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> edge[20];   int n, t;   string a, b;   bitset<20> used;   void DFS(int h) {     used[h] = true;     for (auto &i : edge[h])       if (!used[i]) DFS(i);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> t;     while (t--) {       cin >> n;       cin >> a >> b;       for (auto &i : edge) i.clear();       bool check = false;       for (int i = 0; i <= n - 1; i++) {         if (a[i] == b[i]) continue;         if (a[i] > b[i]) {           check = true;           break;         }         edge[a[i] -  a ].push_back(b[i] -  a );         edge[b[i] -  a ].push_back(a[i] -  a );       }       if (check) {         cout << -1 <<   n ;         continue;       }       used.reset();       int ans = 20;       for (int i = 0; i <= 19; i++) {         if (!used[i]) {           DFS(i);           ans--;         }       }       cout << ans <<   n ;     }     return 0;   }


#include<bits/stdc++.h>   #define rep(i,st,en) for(int i=st;i<=en;i++)      using namespace std;   typedef long long ll;   int t,x,y,i,n;      int main()   {    scanf( %d ,&t);    while(t--)    {     scanf( %d ,&n);     rep(i,1,n)scanf( %d ,&x);     printf( %d n ,3*n);     rep(i,1,n/2)     {      x=2*i-1;      y=2*i;      printf( 2 %d %d n ,x,y);      printf( 2 %d %d n ,x,y);      printf( 1 %d %d n ,x,y);      printf( 2 %d %d n ,x,y);      printf( 2 %d %d n ,x,y);      printf( 1 %d %d n ,x,y);     }     //TODO    }    return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e5 + 10;   int n, sz;   vector<int> vec[MAXN];   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> n;     cout << n - 1 <<   n ;     for (int i = 0; i < n - 1; i++) {       int a, b;       cin >> a >> b;       a--, b--;       vec[a].push_back(sz);       vec[b].push_back(sz++);       cout << 2 <<     << a + 1 <<     << b + 1 <<   n ;     }     for (int i = 0; i < n; i++)       for (int j = 1; j < vec[i].size(); j++)         cout << vec[i][j - 1] + 1 <<     << vec[i][j] + 1 <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<char> a;     char x;     for (int i = 0; i < n; i++) {       cin >> x;       a.push_back(x);     }     for (int i = 0; i < a.size(); i++) {       if (a[i] ==  U  && a[i + 1] ==  R ) {         a.erase(a.begin() + i);         a[i] =  D ;       }       if (a[i] ==  R  && a[i + 1] ==  U ) {         {           a.erase(a.begin() + i);           a[i] =  D ;         }       }     }     cout << a.size();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long p[1100000], r[1100000], cnt;   int main() {     long long n, bac;     cin >> n;     if (n == 1) {       printf( 1 n );       return 0;     }     bac = n;     long long i;     for (i = 2; i * i <= n; i++) {       if (bac % i == 0) {         cnt++;         p[cnt] = i;         while (bac % i == 0) {           bac /= i;           r[cnt]++;         }       }     }     if (bac != 1) {       cnt++;       p[cnt] = bac;     }     if (cnt == 1)       cout << p[1] << endl;     else       printf( 1 n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100100;   const int LOGN = 15;   struct TreeGraph {     vector<int> *graph;     vector<int> heights;     vector<int> *d;     vector<int> weights;     vector<int> mapNodes;     int n, nAritculationPoints;     ;     TreeGraph(){};     TreeGraph(int nArtiPoints) : nAritculationPoints(nArtiPoints) {       graph = new vector<int>[N * 2];       d = new vector<int>[LOGN];     }     ~TreeGraph() {       delete[] graph;       heights.clear();       delete[] d;       weights.clear();       mapNodes.clear();     }     void addEdge(int u, int v) {       if (u >= N * 2) cerr << u;       if (v >= N * 2) cerr << v;       graph[u].push_back(v);       graph[v].push_back(u);     }     void print() {       for (int i = 0; i < n; i++) {         printf(  n%d:  , i);         for (auto v : graph[i]) printf( %d  , v);       }       printf(  n______ n );     }     void setN(int n, vector<int> mapNodes) {       this->n = n;       this->mapNodes = mapNodes;       heights = vector<int>(n);       weights = vector<int>(n);       for (int i = 0; i < LOGN; i++) d[i] = vector<int>(n);     }     void preprocess() { dfs(0, -1, 0, 0); }     int lca(int u, int v) {       if (heights[v] > heights[u]) swap(u, v);       int nSteps = heights[u] - heights[v];       while (nSteps > 0) {         int step = log2(nSteps);         u = d[step][u], nSteps -= 1 << step;       }       while (u != v) {         int i = log2(heights[u]);         for (; i >= 0; i--)           if (d[i][u] != d[i][v]) break;         if (i < 0)           u = d[0][u], v = d[0][v];         else           u = d[i][u], v = d[i][v];       }       return u;     }     int sumPath(int u, int v) {       int lcaAndU = lca(u, v);       return weights[u] + weights[v] - 2 * weights[lcaAndU] +              (lcaAndU >= nAritculationPoints);     }     void dfs(int u, int parent, int weight, int height) {       weight += u < nAritculationPoints ? 0 : 1;       weights[u] = weight, heights[u] = height;       d[0][u] = parent;       for (int i = 1; 1 << i <= height; i++) d[i][u] = d[i - 1][d[i - 1][u]];       for (auto v : graph[u]) {         if (v == parent) continue;         dfs(v, u, weight, height + 1);       }     }     int solve(int u, int v) {       u = mapNodes[u], v = mapNodes[v];       if (u == v) return 1;       return sumPath(u, v);     }   };   struct GraphSolver {     vector<int> *graph;     vector<int> low, ids;     vector<bool> isArticulationPoint;     vector<int> stacks;     vector<vector<int>> comps;     int n, id;     GraphSolver();     ~GraphSolver() {       ids.clear();       delete[] graph;       isArticulationPoint.clear();       low.clear();       stacks.clear();     }     GraphSolver(int n)         : low(n), ids(n, -1), isArticulationPoint(n, false), id(0), n(n) {       graph = new vector<int>[n];     };     void addEdge(int u, int v) { graph[u].push_back(v), graph[v].push_back(u); }     void dfs(int u, int parent) {       low[u] = ids[u] = id++;       stacks.push_back(u);       int children = 0;       for (auto v : graph[u]) {         if (v == parent) continue;         if (ids[v] != -1) {           low[u] = min(low[u], ids[v]);         } else {           dfs(v, u);           low[u] = min(low[v], low[u]);           children++;           if ((low[v] >= ids[u] && parent != -1) ||               (parent == -1 && children > 1)) {             isArticulationPoint[u] = true;             vector<int> comp = vector<int>{u};             while (comp.back() != v) {               comp.push_back(stacks.back());               stacks.pop_back();             }             comps.push_back(comp);           }         }       }     }     TreeGraph buildBlockCutTree() {       dfs(0, -1);       if (!stacks.empty()) {         vector<int> comp;         while (!stacks.empty()) {           comp.push_back(stacks.back());           stacks.pop_back();         }         comps.push_back(comp);       }       vector<int> mapNodes = vector<int>(n);       int nNodes = 0;       for (int i = 0; i < n; i++)         if (isArticulationPoint[i]) mapNodes[i] = nNodes++;       auto tree = TreeGraph(nNodes);       for (auto comp : comps) {         for (auto v : comp) {           if (!isArticulationPoint[v])             mapNodes[v] = nNodes;           else             tree.addEdge(mapNodes[v], nNodes);         }         nNodes++;       }       tree.setN(nNodes, mapNodes);       return tree;     }   };   int main() {     int n, m, q;     scanf( %d %d %d n , &n, &m, &q);     int u, v;     GraphSolver *solver = new GraphSolver(n);     for (int i = 0; i < m; i++) {       scanf( %d %d n , &u, &v);       solver->addEdge(u - 1, v - 1);     }     auto tree = solver->buildBlockCutTree();     delete (solver);     tree.preprocess();     for (int i = 0; i < q; i++) {       scanf( %d %d n , &u, &v);       printf( %d n , tree.solve(u - 1, v - 1));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     scanf( %d , &n);     vector<int> r(7, 0);     string den;     for (int i = 0; i < n; i++) {       cin >> den;       for (int j = 0; den[j] !=   0 ; j++) {         r[j] += den[j] ==  1 ;       }     }     int m = 0;     for (int i = 0; i < 7; i++) {       m = max(m, r[i]);     }     printf( %d n , m);     getchar();     getchar();   }


#include <bits/stdc++.h>   using namespace std;   static const int len = 1000010;   struct event {     int t, x, y, tip, num;     event() {}     event(int _t, int _x, int _y, int _tip, int _num)         : t(_t), x(_x), y(_y), tip(_tip), num(_num) {}   };   bool compar(event one, event two) {     return ((one.x < two.x) || (one.x == two.x && one.tip > two.tip));   }   int n, m, globans;   int s[len], f[len], t[len];   int l[len], r[len], b[len], ans[len];   int tt[len * 4], xx[len * 4], tint[len * 4], xint[len * 4];   int tnum, xnum;   vector<event> a;   int tree[len * 4], number[len * 4];   int _count;   inline int findcord(int x) {     int left = 1, right = xnum;     while (left < right) {       int midle = (left + right + 1) / 2;       if (xx[midle] <= x)         left = midle;       else         right = midle - 1;     }     return xint[left];   }   inline int findtime(int x) {     int left = 1, right = tnum;     while (left < right) {       int midle = (left + right + 1) / 2;       if (tt[midle] <= x)         left = midle;       else         right = midle - 1;     }     return tint[left];   }   void update(int root, int l, int r, int x0, int len, int num) {     if (l == r) {       if (tree[root] < len) {         tree[root] = len;         number[root] = num;       }       return;     }     int m = (l + r) / 2;     if (x0 <= m)       update(root * 2, l, m, x0, len, num);     else       update(root * 2 + 1, m + 1, r, x0, len, num);     if (tree[root * 2] > tree[root]) {       tree[root] = tree[root * 2];       number[root] = number[root * 2];     }     if (tree[root * 2 + 1] > tree[root]) {       tree[root] = tree[root * 2 + 1];       number[root] = number[root * 2 + 1];     }   }   pair<int, int> _max(pair<int, int> a, pair<int, int> b) {     if (a.first >= b.first)       return a;     else       return b;   }   pair<int, int> getmax(int root, int l, int r, int L, int R) {     if (r < l || R < L) return make_pair(0, 0);     if (l == L && r == R) {       pair<int, int> t = make_pair(tree[root], number[root]);       return t;     }     int m = (l + r) / 2;     return _max(getmax(root * 2, l, m, L, min(m, R)),                 getmax(root * 2 + 1, m + 1, r, max(m + 1, L), R));   }   int findans(int root, int l, int r, int L, int R, int lim) {     if (r < l || R < L) return -1;     if (l == r) {       return number[root];     }     int m = (l + r) / 2;     pair<int, int> one = getmax(root * 2, l, m, L, min(m, R));     pair<int, int> two = getmax(root * 2 + 1, m + 1, r, max(m + 1, L), R);     if (one.first >= lim)       return findans(root * 2, l, m, L, min(m, R), lim);     else if (two.first >= lim)       return findans(root * 2 + 1, m + 1, r, max(m + 1, L), R, lim);     else       return -1;   }   int main() {     scanf( %d%d , &n, &m);     xnum = tnum = 0;     for (int i = (1); (i) <= (n); (i)++) {       scanf( %d%d%d , &s[i], &f[i], &t[i]);       tt[++tnum] = t[i];       xx[++xnum] = s[i];       xx[++xnum] = f[i];     }     for (int i = (1); (i) <= (m); (i)++) {       scanf( %d%d%d , &l[i], &r[i], &b[i]);       tt[++tnum] = b[i];       xx[++xnum] = l[i];       xx[++xnum] = r[i];       ans[i] = -1;     }     sort(xx + 1, xx + 1 + xnum);     sort(tt + 1, tt + 1 + tnum);     xint[1] = 1;     for (int i = (2); (i) <= (xnum); (i)++)       xint[i] = xint[i - 1] + int(xx[i] != xx[i - 1]);     tint[1] = 1;     for (int i = (2); (i) <= (tnum); (i)++)       tint[i] = tint[i - 1] + int(tt[i] != tt[i - 1]);     for (int i = (1); (i) <= (n); (i)++) {       s[i] = findcord(s[i]);       f[i] = findcord(f[i]);       t[i] = findtime(t[i]);       a.push_back(event(t[i], s[i], f[i], 1, i));     }     for (int i = (1); (i) <= (m); (i)++) {       l[i] = findcord(l[i]);       r[i] = findcord(r[i]);       b[i] = findtime(b[i]);       a.push_back(event(b[i], l[i], r[i], 0, i));     }     _count = tint[tnum];     sort(a.begin(), a.end(), compar);     for (int i = 0; i < a.size(); i++) {       if (a[i].tip == 0) {         int q = findans(1, 1, _count, a[i].t, _count, a[i].y);         ans[a[i].num] = q;       } else {         update(1, 1, _count, a[i].t, a[i].y, a[i].num);       }     }     for (int i = (1); (i) <= (m); (i)++) printf( %d n , ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, i, res = 0, j, mid, a[6] = {}, b[6] = {};     cin >> n;     for (i = 0; i < n; i++) {       cin >> j;       a[j]++;     }     for (i = 0; i < n; i++) {       cin >> j;       b[j]++;     }     for (i = 1; i < 6; i++) {       mid = a[i] + b[i];       if (mid % 2) {         cout << -1 << endl;         return 0;       }       res += abs(a[i] - mid / 2);     }     cout << res / 2 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INFint = 2147483647;   const long long INF = 9223372036854775807ll;   const long long MOD = 1000000007ll;   const long double EPS = 1e-9;   int p[1000];   int a[1000];   int b[1000];   int cnt;   void dfs(int v) {     p[v] = 1;     for (int i = 1; i <= cnt; i++) {       if (!p[i]) {         if ((a[v] > a[i] && a[v] < b[i]) || (b[v] > a[i] && b[v] < b[i])) dfs(i);       }     }   }   int main() {     ios_base::sync_with_stdio(0);     int n;     cin >> n;     for (int i = 0; i < n; i++) {       int t, x, y;       cin >> t >> x >> y;       if (t == 1) {         cnt++;         a[cnt] = x;         b[cnt] = y;       } else {         memset(p, 0, sizeof(p));         dfs(x);         if (p[y]) {           cout <<  YES  << endl;         } else           cout <<  NO  << endl;       }     }     fprintf(stderr,   nTIME = %lf n , 1.0 * clock() / CLOCKS_PER_SEC);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   double dp[100002];   int main() {     double res = 0, prob = 0;     int n;     cin >> n;     dp[0] = 0;     for (int i = 0; i < n; i++) {       double p;       cin >> p;       dp[i] = dp[i - 1] * p;       res = res + p + dp[i] * 2.0;       dp[i] += p;     }     printf( %.7lf n , res);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     vector<int> a(n), b(n), c(n);     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 0; i < n; i++) cin >> b[i];     int ans = INT_MAX;     sort(a.begin(), a.end());     sort(b.begin(), b.end());     for (int i = 0; i < n; i++) {       int x = (b[i] - a[0] + m) % m;       for (int j = 0; j < n; j++) c[j] = (a[j] + x) % m;       sort(c.begin(), c.end());       if (c == b) ans = min(ans, x);     }     cout << ans << endl;   }


#include <bits/stdc++.h>   const int INF = 0x3f3f3f3f;   const long long LINF = 0x3f3f3f3f3f3f3f3fll;   using namespace std;   const double eps = 1e-6;   const long long mod = 1e9 + 7;   const int maxn = 1e5 + 100;   const int maxe = 1e6 + 100;   struct node {     int to;     int next;   };   bool dp[maxn][2], cir;   vector<int> V[maxn];   int vis[maxn][2];   int Next[maxn][2], n, m;   inline bool dfs(int x, int s) {     if (!V[x].size()) return s == 1;     if (vis[x][s] == 2) return dp[x][s];     vis[x][s] = 1;     bool t = 0;     for (int i = 0; i < V[x].size(); i++) {       int v = V[x][i];       if (vis[v][s ^ 1] == 1) {         cir = 1;         continue;       }       if (dfs(v, s ^ 1)) {         t = 1;         Next[x][s] = v;       }     }     vis[x][s] = 2;     return dp[x][s] = t;   }   inline void print(int x, int s) {     printf( %d  , x);     if (Next[x][s]) {       print(Next[x][s], s ^ 1);     }   }   void Solve() {     cin >> n >> m;     int xx, v;     for (int i = 1; i <= n; i++) {       cin >> xx;       for (int j = 0; j < xx; j++) {         cin >> v;         V[i].push_back(v);       }     }     int st;     cin >> st;     if (dfs(st, 0)) {       puts( Win );       print(st, 0);     } else if (cir)       puts( Draw );     else       puts( Lose );   }   int main() {     int Case = 1, cases;     while (Case--) {       Solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using db = long double;   using pll = pair<long long, long long>;   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long t, i, x, j, y, z, k, n;     long long tt;     cin >> tt;     for (long long _tt = 0; _tt < tt; _tt++) {       cin >> n;       z = 0;       while (n != 1) {         if (n % 6 == 0)           n /= 6;         else if ((n * 2) % 6 == 0)           n *= 2;         else {           z = -1;           break;         }         z++;       }       cout << z <<   n ;     }   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:16000000 )   using namespace std;   const int inf = 0x3f3f3f3f;   const long long inf2 = 0x3f3f3f3f3f3f3f3f;   const double eps = 1e-6;   const int mod = 1000000007;   namespace fastio {   char in[100000];   int itr = 0, llen = 0;   char get() {     if (itr == llen) llen = fread(in, 1, 100000, stdin), itr = 0;     if (llen == 0) return EOF;     return in[itr++];   }   char out[100000];   int itr2 = 0;   void put(char c) {     out[itr2++] = c;     if (itr2 == 100000) {       fwrite(out, 1, 100000, stdout);       itr2 = 0;     }   }   int clear() {     fwrite(out, 1, itr2, stdout);     itr2 = 0;     return 0;   }   int getint() {     int r = 0;     bool ng = 0;     char c;     c = get();     while (c !=  -  && (c <  0  || c >  9 )) c = get();     if (c ==  - ) ng = 1, c = get();     while (c >=  0  && c <=  9 ) r = r * 10 + c -  0 , c = get();     return ng ? inf : r;   }   string getstr() {     string ret =   ;     char ch = get();     while (ch ==     || ch ==   n ) ch = get();     while (ch !=     && ch !=   n ) ret.push_back(ch), ch = get();     return ret;   }   void putstr(string s) {     for (int i = 0; i < s.size(); i++) put(s[i]);   }   void putint(int x) {     if (x == 0) {       put( 0 );       return;     }     char c[20];     int pos = 0;     while (x) {       c[pos++] =  0  + x % 10;       x /= 10;     }     for (int i = pos - 1; i >= 0; i--) put(c[i]);   }   void getarr(int arrname[], int size) {     for (int i = 0; i < size; i++) arrname[i] = getint();   }   }  // namespace fastio   using namespace fastio;   int n, m;   bool used[111111 * 5];   vector<int> g[111111 * 5];   int deg[111111 * 5];   vector<pair<int, int> > edges;   vector<int> ans;   void dfs(int x, int par) {     used[x] = true;     ans.push_back(x);     for (auto p : g[x]) {       deg[p]--;       if (deg[p] == 0) dfs(p, x);     }   }   int main() {     n = getint();     m = getint();     vector<vector<int> > vec(n, vector<int>(m));     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) vec[i][j] = getint();     int pre = m;     for (int i = 0; i < n; i++) {       bool buff = (i == 0);       vector<pair<int, int> > V;       for (int j = 0; j < m; j++) V.push_back(make_pair(vec[i][j], j));       sort(V.begin(), V.end());       while (V.back().first == inf) V.pop_back();       if (!V.size()) continue;       int pos = 0;       set<int> Set;       Set.clear();       for (int ii = 0; ii < V.size(); ii++) {         Set.insert(V[ii].first);       }       bool first = true;       for (set<int>::iterator itr = Set.begin(); itr != Set.end(); itr++) {         int p = *itr;         set<int>::iterator itr2 = itr;         itr2++;         bool last = itr2 == Set.end();         for (int &t = pos; t < V.size() && V[t].first == p; t++) {           if (!first)             g[pre].push_back(V[t].second), deg[V[t].second]++,                 cerr << V[t].second << endl;           if (Set.size() != 1 && !last)             g[V[t].second].push_back(pre + 1), deg[pre + 1]++,                 cerr << pre << endl;         }         if (Set.size() != 1) pre++;         first = false;       }     }     cerr <<  Start top sort: n ;     for (int i = 0; i < pre; i++)       if (!used[i] && !deg[i]) dfs(i, -1);     vector<int> ans2;     ans2.clear();     for (int i = 0; i < ans.size(); i++)       if (ans[i] < m) ans2.push_back(ans[i]);     if (ans2.size() < m) {       puts( -1 );       return 0;     } else {       for (int i = 0; i < ans2.size(); i++) putint(ans2[i] + 1), put(   );       return clear();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const long long INFLL = 0x3f3f3f3f3f3f3f3fLL;   inline long long read() {     long long x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x * f;   }   const int maxn = 1e5 + 10;   const int mod = 1e9 + 7;   string s;   int len, match[1005];   long long dp[1000][1000][3][3];   void get_match() {     stack<int> sta;     for (int i = 0; i < len; i++) {       if (s[i] ==  ( )         sta.push(i);       else {         int t = sta.top();         sta.pop();         match[i] = t;         match[t] = i;       }     }   }   void dfs(int l, int r) {     if (l + 1 == r) {       dp[l][r][0][1] = 1;       dp[l][r][1][0] = 1;       dp[l][r][0][2] = 1;       dp[l][r][2][0] = 1;       return;     }     if (match[l] == r) {       dfs(l + 1, r - 1);       for (int i = 0; i < 3; i++)         for (int j = 0; j < 3; j++) {           if (j != 1)             dp[l][r][0][1] = (dp[l][r][0][1] + dp[l + 1][r - 1][i][j]) % mod;           if (i != 1)             dp[l][r][1][0] = (dp[l][r][1][0] + dp[l + 1][r - 1][i][j]) % mod;           if (j != 2)             dp[l][r][0][2] = (dp[l][r][0][2] + dp[l + 1][r - 1][i][j]) % mod;           if (i != 2)             dp[l][r][2][0] = (dp[l][r][2][0] + dp[l + 1][r - 1][i][j]) % mod;         }       return;     } else {       int k = match[l];       dfs(l, k);       dfs(k + 1, r);       for (int i = 0; i < 3; i++)         for (int j = 0; j < 3; j++)           for (int x = 0; x < 3; x++)             for (int y = 0; y < 3; y++) {               if ((x == 1 && y == 1) || (x == 2 && y == 2)) continue;               dp[l][r][i][j] =                   (dp[l][r][i][j] + dp[l][k][i][x] * dp[k + 1][r][y][j]) % mod;             }       return;     }   }   int main() {     memset(dp, 0, sizeof(dp));     cin >> s;     len = s.size();     get_match();     dfs(0, len - 1);     long long ans = 0;     for (int i = 0; i < 3; i++)       for (int j = 0; j < 3; j++) ans = (ans + dp[0][len - 1][i][j]) % mod;     cout << ans << endl;     return 0;   }