#include <bits/stdc++.h>   using namespace std;   using namespace std;   inline int read() {     char ch;     bool sign = 0;     int res = 0;     while (!isdigit(ch = getchar()))       if (ch ==  - ) sign = 1;     while (isdigit(ch)) res = res * 10 + (ch ^ 48), ch = getchar();     if (sign)       return -res;     else       return res;   }   mt19937 Rnd(chrono::system_clock::now().time_since_epoch().count());   const int maxn = 200000 + 10;   const int inf = 1e9;   const int MAXM = 3;   const long long MOD[] = {469762049, 998244353, 1004535809, 1000000007};   const int mod = 1811939329;   const int apsz = 26;   int a[maxn], n, cnt[maxn], Sqrt;   int mx;   inline int brute(int x) {     vector<int> pos(2 * n + 2, -1);     int now = maxn;     int ans = 0;     pos[n] = 0;     for (auto i = (1); i <= (n); ++i) {       if (now == maxn && a[i] != x && a[i] != mx) continue;       if (now == maxn) now = 0;       if (a[i] == x) {         now++;       } else if (a[i] == mx)         now--;       if (pos[now + n] >= 0) ans = max(ans, i - pos[now + n]);       if (pos[now + n] == -1) pos[now + n] = i;     }     return ans;   }   inline int gao(int c) {     memset(cnt, 0, sizeof(cnt));     int has = 0;     int l, r, ans;     for (ans = 0, r = l = 1; r <= n; ++r) {       ++cnt[a[r]];       if (cnt[a[r]] == c)         has++;       else if (cnt[a[r]] == c + 1)         has--;       while (cnt[a[r]] > c) {         --cnt[a[l]];         if (cnt[a[l]] == c) has++;         if (cnt[a[l]] == c - 1) has--;         l++;       }       assert(has >= 0 && r >= l);       if (has > 1) ans = max(ans, r - l + 1);     }     return ans;   }   inline int solve() {     int mxcnt = 0;     for (auto i = (1); i <= (n); ++i) {       if (++cnt[a[i]] > mxcnt) mxcnt = cnt[a[i]], mx = a[i];     }     for (auto i = (1); i <= (n); ++i) {       if (mx != a[i] && cnt[a[i]] == mxcnt) return n;     }     int ans(0);     Sqrt = sqrt(n + 3);     for (auto i = (1); i <= (n); ++i) {       if (cnt[a[i]] >= Sqrt && a[i] != mx) {         ans = max(brute(a[i]), ans);         cnt[a[i]] = 0;       }     }     for (auto c = (1); c <= (Sqrt); ++c) {       ans = max(ans, gao(c));     }     return ans;   }   int main(void) {     scanf( %d , &(n));     for (auto i = (1); i <= (n); ++i) scanf( %d , &(a[i]));     printf( %d n , solve());     return 0;   }


#include <bits/stdc++.h>   using namespace std;   map<long long, long long> zipx;   long long unzipx[2000];   long long inf = 1LL << 50;   long long compressx(vector<long long>& x) {     sort(x.begin(), x.end());     x.erase(unique(x.begin(), x.end()), x.end());     for (long long i = 0; i < x.size(); i++) {       zipx[x[i]] = i;       unzipx[i] = x[i];     }     return x.size();   }   map<long long, long long> zipy;   long long unzipy[2000];   long long compressy(vector<long long>& x) {     sort(x.begin(), x.end());     x.erase(unique(x.begin(), x.end()), x.end());     for (long long i = 0; i < x.size(); i++) {       zipy[x[i]] = i;       unzipy[i] = x[i];     }     return x.size();   }   template <typename T>   class Dinic {    private:     struct edge {       long long to;       T cap;       long long rev;     };     long long V;     vector<vector<edge> > G;     vector<long long> level, iter;     void bfs(long long s) {       fill(level.begin(), level.end(), -1);       queue<long long> que;       level[s] = 0;       que.push(s);       while (!que.empty()) {         long long v = que.front();         que.pop();         for (auto& e : G[v]) {           if (e.cap > 0 && level[e.to] < 0) {             level[e.to] = level[v] + 1;             que.push(e.to);           }         }       }     }     T dfs(long long v, long long t, T f) {       if (v == t) {         return f;       }       for (long long& i = iter[v]; i < (long long)G[v].size(); i++) {         edge& e = G[v][i];         if (e.cap > 0 && level[v] < level[e.to]) {           T d = dfs(e.to, t, min(f, e.cap));           if (d > 0) {             e.cap -= d;             G[e.to][e.rev].cap += d;             return d;           }         }       }       return 0;     }       public:     Dinic(long long node_size) : V(node_size), G(V), level(V), iter(V) {}     void add_edge(long long from, long long to, T cap) {       G[from].push_back((edge){to, cap, (long long)G[to].size()});       G[to].push_back((edge){from, (T)0, (long long)G[from].size() - 1});     }     T solve(long long s, long long t) {       T flow = 0;       for (;;) {         bfs(s);         if (level[t] < 0) return flow;         fill(iter.begin(), iter.end(), 0);         T f;         while ((f = dfs(s, t, numeric_limits<T>::max())) > 0) {           flow += f;         }       }     }   };   signed main() {     long long n, m;     cin >> n >> m;     vector<pair<long long, long long> > a;     vector<pair<long long, long long> > b;     vector<long long> x;     vector<long long> y;     for (long long i = 0; i < (long long)(m); ++i) {       long long p, q, r, s;       cin >> p >> q >> r >> s;       a.push_back(make_pair(p, q));       b.push_back(make_pair(r + 1, s + 1));       x.push_back(p);       y.push_back(q);       x.push_back(r + 1);       y.push_back(s + 1);     }     long long s = compressx(x);     long long t = compressy(y);     vector<vector<bool> > f(s + 10, vector<bool>(t + 10));     for (long long i = 0; i < (long long)(m); ++i) {       for (long long j = zipx[a[i].first]; j < zipx[b[i].first]; j++) {         for (long long k = zipy[a[i].second]; k < zipy[b[i].second]; k++) {           f[j][k] = 1;         }       }     }     Dinic<long long> dn(s + t + 2);     long long S = s + t;     long long T = s + t + 1;     for (long long i = 0; i < (long long)(s - 1); ++i) {       dn.add_edge(S, i, unzipx[i + 1] - unzipx[i]);     }     for (long long j = 0; j < (long long)(t - 1); ++j) {       dn.add_edge(s + j, T, unzipy[j + 1] - unzipy[j]);     }     for (long long i = 0; i < (long long)(s); ++i) {       for (long long j = 0; j < (long long)(t); ++j) {         if (f[i][j]) {           dn.add_edge(i, s + j, inf);         }       }     }     cout << dn.solve(S, T) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   unordered_map<int, int> mapa;   vector<int> tab;   int main() {     ios_base::sync_with_stdio(false);     int n, k, a;     cin >> n >> k;     int aktIlosc = n;     for (int i = 0; i < n; i++) {       cin >> a;       if (mapa[a] == 0) tab.push_back(a);       mapa[a]++;     }     sort(tab.begin(), tab.end());     for (int i = 0; i + 1 < tab.size(); i++) {       if (tab[i] < tab[i + 1] && tab[i] + k >= tab[i + 1])         aktIlosc -= mapa[tab[i]];     }     cout << aktIlosc;   }


#include <bits/stdc++.h>   using namespace std;   using namespace chrono;   void _print(long long t) { cerr << t; }   void _print(int t) { cerr << t; }   void _print(string t) { cerr << t; }   void _print(char t) { cerr << t; }   void _print(long double t) { cerr << t; }   void _print(double t) { cerr << t; }   void _print(unsigned long long t) { cerr << t; }   template <class T, class V>   void _print(pair<T, V> p);   template <class T>   void _print(vector<T> v);   template <class T>   void _print(set<T> v);   template <class T, class V>   void _print(map<T, V> v);   template <class T>   void _print(multiset<T> v);   template <class T, class V>   void _print(pair<T, V> p) {     cerr <<  { ;     _print(p.first);     cerr <<  , ;     _print(p.second);     cerr <<  } ;   }   template <class T>   void _print(vector<T> v) {     cerr <<  [  ;     for (T i : v) {       _print(i);       cerr <<    ;     }     cerr <<  ] ;   }   template <class T>   void _print(set<T> v) {     cerr <<  [  ;     for (T i : v) {       _print(i);       cerr <<    ;     }     cerr <<  ] ;   }   template <class T>   void _print(multiset<T> v) {     cerr <<  [  ;     for (T i : v) {       _print(i);       cerr <<    ;     }     cerr <<  ] ;   }   template <class T, class V>   void _print(map<T, V> v) {     cerr <<  [  ;     for (auto i : v) {       _print(i);       cerr <<    ;     }     cerr <<  ] ;   }   long long gcd(long long a, long long b) {     if (b > a) {       return gcd(b, a);     }     if (b == 0) {       return a;     }     return gcd(b, a % b);   }   long long expo(long long a, long long b, long long mod) {     long long res = 1;     while (b > 0) {       if (b & 1) res = (res * a) % mod;       a = (a * a) % mod;       b = b >> 1;     }     return res;   }   void extendgcd(long long a, long long b, long long *v) {     if (b == 0) {       v[0] = 1;       v[1] = 0;       v[2] = a;       return;     }     extendgcd(b, a % b, v);     long long x = v[1];     v[1] = v[0] - v[1] * (a / b);     v[0] = x;     return;   }   long long mminv(long long a, long long b) {     long long arr[3];     extendgcd(a, b, arr);     return arr[0];   }   long long mminvprime(long long a, long long b) { return expo(a, b - 2, b); }   bool revsort(long long a, long long b) { return a > b; }   void swap(int &x, int &y) {     int temp = x;     x = y;     y = temp;   }   long long combination(long long n, long long r, long long m, long long *fact,                         long long *ifact) {     long long val1 = fact[n];     long long val2 = ifact[n - r];     long long val3 = ifact[r];     return (((val1 * val2) % m) * val3) % m;   }   void google(int t) { cout <<  Case #  << t <<  :  ; }   vector<long long> sieve(int n) {     int *arr = new int[n + 1]();     vector<long long> vect;     for (int i = 2; i <= n; i++)       if (arr[i] == 0) {         vect.push_back(i);         for (int j = 2 * i; j <= n; j += i) arr[j] = 1;       }     return vect;   }   long long mod_add(long long a, long long b, long long m) {     a = a % m;     b = b % m;     return (((a + b) % m) + m) % m;   }   long long mod_mul(long long a, long long b, long long m) {     a = a % m;     b = b % m;     return (((a * b) % m) + m) % m;   }   long long mod_sub(long long a, long long b, long long m) {     a = a % m;     b = b % m;     return (((a - b) % m) + m) % m;   }   long long mod_div(long long a, long long b, long long m) {     a = a % m;     b = b % m;     return (mod_mul(a, mminvprime(b, m), m) + m) % m;   }   long long phin(long long n) {     long long number = n;     if (n % 2 == 0) {       number /= 2;       while (n % 2 == 0) n /= 2;     }     for (long long i = 3; i <= sqrt(n); i += 2) {       if (n % i == 0) {         while (n % i == 0) n /= i;         number = (number / i * (i - 1));       }     }     if (n > 1) number = (number / n * (n - 1));     return number;   }   int r, c, k;   string arr[100];   vector<char> ans;   vector<vector<char>> ans1;   void put_values(pair<int, int> &p, int x, int i) {     int count = 0;     while (count < x) {       ans1[p.first][p.second] = ans[i];       if (arr[p.first][p.second] ==  R ) {         count++;       }       if (p.first % 2 == 0) {         if (p.second == c - 1) {           p.first++;         } else {           p.second++;         }       } else {         if (p.second == 0) {           p.first++;         } else {           p.second--;         }       }     }   }   void solve() {     int t;     cin >> t;     for (int i = 0; i < 26; i++) {       ans.push_back( a  + i);       ans.push_back( A  + i);     }     for (int i = 0; i < 10; i++) {       ans.push_back( 0  + i);     };     while (t--) {       cin >> r >> c >> k;       vector<vector<char>> ans2(r, vector<char>(c,  ? ));       ans1 = ans2;       for (int i = 0; i < r; i++) cin >> arr[i];       int count = 0;       for (int i = 0; i < r; i++) {         for (int j = 0; j < c; j++) {           count += arr[i][j] ==  R ;         }       }       int value = count / k;       int x = count % k;       pair<int, int> coordinate = {0, 0};       for (int i = 0; i < k; i++) {         if (i < x) {           put_values(coordinate, value + 1, i);         } else {           put_values(coordinate, value, i);         }       }       for (int i = 0; i < r; i++) {         for (int j = 0; j < c; j++) {           if (ans1[i][j] ==  ? ) {             cout << ans[k - 1];           } else {             cout << ans1[i][j];           }         }         cout <<   n ;       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     auto start1 = high_resolution_clock::now();     solve();     auto stop1 = high_resolution_clock::now();     auto duration = duration_cast<microseconds>(stop1 - start1);   }


#include <bits/stdc++.h>   using namespace std;   char dif(char c1) {     if (c1 ==  a ) return  b ;     return  a ;   }   char dif2(char c1, char c2) {     if (c1 !=  a  && c2 !=  a ) return  a ;     if (c1 !=  b  && c2 !=  b ) return  b ;     return  c ;   }   int main() {     int n, t;     cin >> n >> t;     string s1, s2;     cin >> s1 >> s2;     vector<int> com;     vector<int> nocom;     for (long long i = 0; i < (n); i++)       if (s1[i] == s2[i])         com.push_back(i);       else         nocom.push_back(i);     int comsz = com.size();     int nocomsz = nocom.size();     if (!(2 * t >= nocomsz)) {       cout << -1 << endl;       return 0;     }     string s3 = s1;     if (nocomsz & 1) {       int ind = nocom[nocomsz - 1];       s3[ind] = dif2(s1[ind], s2[ind]);       t--;     }     for (int i = 0; (i + 1 < nocomsz) && t > 0; i += 2) {       int ind1 = nocom[i];       s3[ind1] = s2[ind1];       int ind2 = nocom[i + 1];       s3[ind2] = s1[ind2];       t--;     }     for (int i = 0; i < comsz && t > 0; i++) {       int ind = com[i];       s3[ind] = dif(s1[ind]);       t--;     }     for (int i = 0; (i + 1 < nocomsz) && t > 0; i += 2) {       int ind1 = nocom[i];       int ind2 = nocom[i + 1];       s3[ind1] = dif2(s1[ind1], s2[ind1]);       s3[ind2] = dif2(s1[ind2], s2[ind2]);       t--;     }     cout << s3 << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e4 + 10;   const long long mod = 998244353;   int n, m, k, x;   bool a[55][maxn];   int main() {     scanf( %d%d , &m, &n);     for (int i = 1; i <= (m); i++) {       scanf( %d , &k);       for (int j = 1; j <= (k); j++) {         scanf( %d , &x);         a[i][x] = 1;       }     }     for (int i = 1; i <= (m); i++)       for (int j = 1; j <= (m); j++) {         bool flag = 0;         for (int l = 1; l <= n && !flag; l++)           if (a[i][l] && a[j][l]) flag = 1;         if (!flag) {           printf( impossible n );           return 0;         }       }     printf( possible n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int sum(long int c) {     int somme = 0;     while (c) {       somme = somme + c % 10;       c = c / 10;     }     return (somme);   }   int main() {     long int k, c = 19;     cin >> k;     while (k) {       if (sum(c) == 10) k--;       c += 9;     }     cout << c - 9;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const int M = 100005;   const int MOD = 1e9 + 7;   long long c[100005], x, k, tot = 0;   vector<long long> son[100005];   void dfs(int n, int m) {     if (tot >= 100000) return;     if (n == 0 || m == 0) {       printf( %I64d  , c[n]);       ++tot;       return;     }     for (int v : son[n]) dfs(v, m - 1);   }   int main() {     cin >> x >> k;     if (k == 0) {       printf( %I64d n , x);       return 0;     }     int top = 0;     for (int i = 1; i * 1ll * i < x; ++i) {       if (x % i == 0) {         c[top++] = i;         c[top++] = x / i;       }     }     if (sqrt(x) * sqrt(x) == x) c[top++] = sqrt(x);     sort(c, c + top);     for (int i = 0; i < top; ++i)       for (int j = 0; j <= i; ++j)         if (c[i] % c[j] == 0) son[i].push_back(j);     dfs(top - 1, k);     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:16777216 )   using namespace std;   const double PI = acos(-1.0);   long long gcd(long long a, long long b) {     if (b == 0) return a;     return gcd(b, a % b);   }   pair<long long, int> all[2000111];   long long cntA, cntB;   int cnt;   int main() {     long long a, b;     cin >> a >> b;     long long x = a * b / gcd(a, b);     for (int i = (1), _b = (x / a - 1); i <= _b; i++)       all[cnt++] = make_pair(a * i, 0);     for (int i = (1), _b = (x / b - 1); i <= _b; i++)       all[cnt++] = make_pair(b * i, 1);     sort(all, all + cnt);     long long last = 0;     for (int i = 0, _a = (cnt); i < _a; i++) {       if (all[i].second == 0)         cntA += all[i].first - last;       else         cntB += all[i].first - last;       last = all[i].first;     }     if (a > b)       cntA += x - last;     else       cntB += x - last;     if (cntA > cntB)       puts( Dasha );     else if (cntA < cntB)       puts( Masha );     else       puts( Equal );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int stop, n, k, x, i, ind, j, y[1000001], mini[2001][2001];   string s[2001];   struct name {     int a[26];     int cnt;   } trie[1000001];   vector<int> d[1000001];   int m;   void add(int v, int pos) {     if (pos > s[i].length()) return;     if (trie[v].a[s[i][pos] -  a ])       add(trie[v].a[s[i][pos] -  a ], pos + 1);     else {       m++;       trie[v].a[s[i][pos] -  a ] = m;       add(m, pos + 1);     };     trie[v].cnt++;   }   void dp(int v) {     for (int j = 0; j < 26; j++)       if (trie[v].a[j]) dp(trie[v].a[j]);     d[v].resize(trie[v].cnt + 1);     for (int j = 0; j < 26; j++) {       int p = trie[v].a[j];       if (p == 0) continue;       int s = d[p].size() - 1;       for (int k1 = d[v].size() - s - 1; k1 >= 0; k1--)         for (int i = 1; i <= s; i++) {           d[v][k1 + i] = max(d[v][k1 + i], d[v][k1] + d[p][i] + i * (i - 1) / 2);         }     }   }   int main() {     cin >> n >> k;     for (i = 1; i <= n; i++) {       cin >> s[i];       add(0, 0);     };     dp(0);     cout << d[0][k];     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     vector<int> vet, mat;     int n, x;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> x;       if (x != 0) vet.push_back(x);     }     for (int i = 0; i < n; i++) {       cin >> x;       if (x != 0) mat.push_back(x);     }     int aux = 0;     if (n <= 3) {       cout <<  YES ;     } else {       int r;       for (int i = 0; i < n - 1; i++) {         if (mat[i] == vet[0]) {           r = i;           break;         }       }       for (int i = 0; i < n - 1; i++) {         int l = r + i;         if (l >= n - 1) l -= (n - 1);         if (vet[i] != mat[l]) {           aux = 1;           break;         }       }       if (aux) {         cout <<  NO ;       } else         cout <<  YES ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool comp(int a, int b) { return a < b; }   int main() {     stack<int> s;     int N, t;     cin >> N;     while (N--) {       cin >> t;       if (s.empty()) {         s.push(t);       } else {         if (((s.top()) & 1) == (t & 1))           s.pop();         else           s.push(t);       }     }     if (s.size() < 2)       cout <<  YES  << endl;     else       cout <<  NO  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using vi = vector<int>;   using vvi = vector<vi>;   using vll = vector<ll>;   using vvll = vector<vll>;   using vb = vector<bool>;   using vd = vector<double>;   using vs = vector<string>;   using vpii = vector<pair<int, int>>;   using vpll = vector<pair<ll, ll>>;   using pii = pair<int, int>;   using pll = pair<ll, ll>;   int dx[8] = {0, 1, 1, 1, 0, -1, -1, -1};   int dy[8] = {1, 1, 0, -1, -1, -1, 0, 1};   void solve() {     vi a(6);     for (ll i = 0; i < 6; i++) cin >> a[i];     ;     ll ans = ((a[0] + a[1] + a[2]) * (a[0] + a[1] + a[2]) - a[0] * a[0] -               a[2] * a[2] - a[4] * a[4]);     cout << ans <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ll t = 1;     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   int n, h;   char name[10];   long double p[70], cont[70];   int main() {     scanf( %s%d%d , name, &n, &h);     if (name[0] ==  B ) {       printf( %d n , n);       return 0;     }     long double ans = n;     p[0] = cont[0] = 1.0;     for (int i = 1; i <= h; i++) {       p[i] = p[i - 1] / 2.0;       cont[i] = cont[i - 1] * 2.0;     }     for (int i = 1; i <= h; i++)       for (int j = 2; j <= n; j++)         ans += p[i] * p[i] * pow(1.0 - p[i], j - 2) *                (cont[i] - cont[i - 1] * ((j - 2) / (cont[i] - 1.0) + 1.0)) *                (n - j + 1);     printf( %.10f n , (double)ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, m, c1, c2, v, q;   long long xs, xe, ye, ys;   long long pos1[100005];   long long pos2[100005];   long long solve(int pos, int v) {     long long ans = abs(pos - xe) + abs(pos - xs);     long long y = abs(ye - ys);     ans += (y - 1) / v + 1;     return ans;   }   int main() {     cin >> n >> m >> c1 >> c2 >> v;     for (int i = 0; i < c1; i++) cin >> pos1[i];     for (int i = 0; i < c2; i++) cin >> pos2[i];     cin >> q;     while (q--) {       int id;       cin >> ys >> xs >> ye >> xe;       long long ans = 999999999999;       if (ys == ye)         ans = abs(xe - xs);       else {         if (c1) {           id = upper_bound(pos1, pos1 + c1, xs) - pos1;           if (id != c1) ans = min(ans, solve(pos1[id], 1));           if (id - 1 >= 0) ans = min(ans, solve(pos1[id - 1], 1));           id = upper_bound(pos1, pos1 + c1, xe) - pos1;           if (id != c1) ans = min(ans, solve(pos1[id], 1));           if (id - 1 >= 0) ans = min(ans, solve(pos1[id - 1], 1));         }         if (c2) {           id = upper_bound(pos2, pos2 + c2, xs) - pos2;           if (id != c2) ans = min(ans, solve(pos2[id], v));           if (id - 1 >= 0) ans = min(ans, solve(pos2[id - 1], v));           id = upper_bound(pos2, pos2 + c2, xe) - pos2;           if (id != c2) ans = min(ans, solve(pos2[id], v));           if (id - 1 >= 0) ans = min(ans, solve(pos2[id - 1], v));         }       }       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 1;   int n, m, q, p[N], dis[N], far, cur, sz[N];   vector<int> g[N];   unordered_map<int, double> dp[N];   vector<pair<int, long long>> v[N];   int get(int u) { return p[u] == u ? u : p[u] = get(p[u]); }   void dfs(int u, int p, int depth) {     dis[u] = max(dis[u], depth);     if (dis[u] > cur) {       cur = dis[u];       far = u;     }     for (auto i : g[u])       if (i != p) dfs(i, u, depth + 1);   }   double calc(int a, int b) {     if (dp[a].find(b) != dp[a].end()) return dp[a][b];     double ans = 0;     int mx = max(v[a].back().first, v[b].back().first);     for (int i = v[a].size() - 1, j = 0; i + 1; i--) {       while (j < v[b].size() && v[a][i].first + v[b][j].first + 1 <= mx) j++;       ans += mx * 1LL * j;       if (j < v[b].size()) {         ans += v[b].back().second + v[b].size() - j +                v[a][i].first * 1LL * (v[b].size() - j);         if (j) ans -= v[b][j - 1].second;       }     }     ans /= v[a].size() * 1LL * v[b].size();     return dp[a][b] = dp[b][a] = ans;   }   int main() {     scanf( %d%d%d , &n, &m, &q);     int z = sqrt(n);     for (int i = 0; i < n; i++) p[i] = i, sz[i] = 1;     for (int i = 0, a, b; i < m; i++) {       scanf( %d%d , &a, &b);       --a;       --b;       sz[get(b)] += sz[get(a)];       p[get(a)] = get(b);       g[a].push_back(b);       g[b].push_back(a);     }     for (int i = 0; i < n; i++)       if (p[i] == i) {         cur = -1e9;         dfs(i, -1, 0);         cur = -1e9;         dfs(far, -1, 0);         cur = -1e9;         dfs(far, -1, 0);       }     for (int i = 0; i < n; i++) v[get(i)].push_back({dis[i], dis[i]});     for (int i = 0; i < n; i++) sort(v[i].begin(), v[i].end());     for (int i = 0; i < n; i++)       if (i == p[i])         for (int j = 1; j < v[i].size(); j++)           v[i][j].second += v[i][j - 1].second;     for (int i = 0, a, b; i < q; i++) {       scanf( %d%d , &a, &b);       --a;       --b;       a = get(a);       b = get(b);       if (a == b) {         puts( -1 );         continue;       }       if (sz[a] > sz[b]) swap(a, b);       printf( %.10lf n , calc(a, b));     }   }


#include <bits/stdc++.h>   using namespace std;   int n, m, k, arr[105][105];   int check(int c[105], int ctC, int secRow) {     int ans = INT_MAX;     if (ctC > 10) return ans;     for (int i = 0; i < (1 << ctC); i++) {       int ct = 0;       for (int r = 2; r <= n; r++) {         if (r != secRow) {           int same = 0;           for (int j = 1; j <= m; j++) {             int row1El =                 c[j] >= 0 && (i & (1 << c[j])) ? 1 - arr[1][j] : arr[1][j];             if (row1El == arr[r][j]) same++;           }           ct += min(same, m - same);         }       }       ans = min(ctC + ct, ans);     }     return ans;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> n >> m >> k;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         cin >> arr[i][j];       }     }     if (n == 1 || m == 1) {       cout << 0 << endl;       return 0;     }     int ans = INT_MAX;     for (int secRow = 2; secRow <= min(15, n); secRow++) {       int ctA = 0, ctB = 0;       int a[105], b[105];       memset(a, -1, sizeof(a));       memset(b, -1, sizeof(b));       for (int j = 1; j <= m; j++) {         if ((arr[1][j] ^ arr[secRow][j]) == 1) {           a[j] = ctA;           ctA++;         } else {           b[j] = ctB;           ctB++;         }       }       ans = min(check(a, ctA, secRow), check(b, ctB, secRow));     }     cout << (ans > k ? -1 : ans) <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   #define ll long long   #define f(i,n) for(int i=0;i<n;i++)   #define endl (  n )   #define pb push_back   #define mp make_pair   #define pl pair<ll, ll>   #define vl vector<ll>   #define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL);      #define M 1000000007    const int N=2e5+2;    ll gcd(ll a, ll b) {if (b > a) {return gcd(b, a);} if (b == 0) {return a;} return gcd(b, a % b);}   ll expo(ll a, ll b, ll mod) {ll res = 1; while (b > 0) {if (b & 1)res = (res * a) % mod; a = (a * a) % mod; b = b >> 1;} return res;}   ll mminvprime(ll a, ll b) {return expo(a, b - 2, b);}   vector<ll> sieve(int n) {int*arr = new int[n + 1](); vector<ll> vect; for (int i = 2; i <= n; i++)if (arr[i] == 0) {vect.push_back(i); for (int j = 2 * i; j <= n; j += i)arr[j] = 1;} return vect;}   ll mod_add(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a + b) % m) + m) % m;}   ll mod_mul(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a * b) % m) + m) % m;}   ll mod_sub(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a - b) % m) + m) % m;}   ll mod_div(ll a, ll b, ll m) {a = a % m; b = b % m; return (mod_mul(a, mminvprime(b, m), m) + m) % m;}  //only for prime m      int fact[N];              void precalc(){               fact[0]=1;               for(int i=1;i<N;i++){                   fact[i]=mod_mul(fact[i-1],i,M);               }           }    long long mod(long long x){               return ((x%M + M)%M);           }           ll inv(ll x){               return expo(x,M-2,M);           }              ll divide(ll a, ll b){               return mod_mul(a,inv(b),M);           }              ll nCr(ll n, ll r){               return divide(fact[n],mod_mul(fact[r],fact[n-r],M));           }          int main()   {       fastIO     ll t;     cin>>t;     while(t--){         ll a,b;         cin>>a>>b;         ll d=abs(a-b);         ll e=max(a,b);         if(a==b){             cout<<0<<   <<0<<endl;             continue;         }                 ll k=e%d;         ll v;         if(d-k>=0 and d-k<k) v=d-k;         else  v=k;            cout<<d<<   <<v<<endl;     }               }


#include <bits/stdc++.h>   using namespace std;   const int N = 5e5 + 7;   const int M = 60;   const int inf = 1e9 + 7;   const long long base = 1e18;   const double pi = acos(-1);   const double ep = 1e-18;   int n;   int a[N];   void solve() {     cin >> n;     for (int i = 0; i < n; i++) scanf( %d , a + i);     int last = 0;     while (last + 1 < n && a[last + 1] == a[0]) last++;     int i = last + 1;     int ans = 0;     while (i < n) {       int j = i;       while (j < n && a[j] == a[i]) j++;       if (i != n - 1 && j - i == 1) {         i = j;         continue;       } else {         ans = max(ans, (i - last) / 2);         for (int u = last + 1, v = i - 1; u <= v; u++, v--) {           a[u] = a[last];           a[v] = a[i];         }         i = j;         last = i - 1;       }     }     cout << ans << endl;     for (int i = 0; i < n; i++) printf( %d  , a[i]);   }   int main() { solve(); }


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


#include <bits/stdc++.h>   using namespace std;   long long x;   int n, d;   struct cmp {     bool operator()(pair<int, int> x, pair<int, int> y) {       return x.first > y.first;     }   };   set<pair<int, int>, cmp> que;   set<pair<int, int>, cmp>::iterator it;   vector<int> num;   int a[100005], c[100005];   bool b[100005];   long long next() {     x = (x * 37 + 10007) % 1000000007;     return x;   }   void initAB() {     for (int i = 0; i < n; i++) a[i] = i + 1;     for (int i = 0; i < n; i++) swap(a[i], a[next() % (i + 1)]);     for (int i = 0; i < n; i++) {       if (i < d)         b[i] = 1;       else         b[i] = 0;     }     for (int i = 0; i < n; i++) swap(b[i], b[next() % (i + 1)]);   }   int main() {     scanf( %d%d%I64d , &n, &d, &x);     initAB();     if (d < 1000) {       for (int i = 0; i < n; i++) {         if (b[i]) num.push_back(i);         for (int j = 0; j < num.size(); j++) c[i] = max(c[i], a[i - num[j]]);       }     } else {       for (int i = 0; i < n; i++) {         que.insert(make_pair(a[i], i));         for (it = que.begin(); it != que.end(); it++) {           if (b[i - it->second]) {             c[i] = it->first;             break;           }         }       }     }     for (int i = 0; i < n; i++) cout << c[i] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string yes =  YES , no =  NO ;   void solve() {     long long n, k;     scanf( %lli%lli , &n, &k);     long long qwe = n - k + 1;     long long rty = n - 2 * k + 2;     if (qwe > 0 and qwe % 2 == 1) {       cout << yes << endl;       for (int i = 0; i < k - 1; i++) {         printf( 1  );       }       printf( %lli n , qwe);       return;     }     if (rty > 0 && rty % 2 == 0) {       cout << yes << endl;       for (int i = 0; i < k - 1; i++) {         printf( 2  );       }       printf( %lli n , rty);       return;     }     cout << no << endl;   }   int main() {     int t;     scanf( %d , &t);     while (t--) solve();   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 400;   int n, m, wynik, A[N], B[N];   map<double, bitset<120> > mapa;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m;     for (int i = 1; i <= n; i++) cin >> A[i];     for (int i = 1; i <= m; i++) cin >> B[i];     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         double pom = (A[i] + B[j]) / 2.0;         mapa[pom][i - 1] = mapa[pom][n + j - 1] = true;       }     }     for (auto u : mapa)       for (auto v : mapa) wynik = max(wynik, (int)(u.second | v.second).count());     cout << wynik << endl;     getchar();     getchar();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000007;   const long double pi = acos(-1);   const long long maxn = 200001;   template <class T>   ostream &operator<<(ostream &out, vector<T> &A) {     for (auto x : A) out << x <<    ;     return out;   }   template <class T1, class T2>   T1 powr(T1 a, T2 b) {     T1 res = 1;     for (long long i = 1; i < b + 1; i++) res = res * a;     return res;   }   int32_t main() {     long long Q;     cin >> Q;     while (Q--) {       long long n, pos;       cin >> n;       vector<long long> A(n);       for (long long i = 0; i < n; i++) {         cin >> A[i];         if (A[i] == 1) pos = i;       }       bool okl = true, okr = true;       for (long long j = 1; j < n; j++) {         okl &= (A[(pos - j + n) % n] == j + 1);         okr &= (A[(pos + j + n) % n] == j + 1);       }       puts(okl or okr ?  YES  :  NO );     }   }


#include <bits/stdc++.h>   using namespace std;   int mp[2123][2123];   int prehb[2123][2123];   int prehs[2123][2123];   int prelb[2123][2123];   int prels[2123][2123];   int main() {     ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);     int n, m;     cin >> n >> m;     for (int i = 1; i <= n; i++) {       map<int, int> lis;       for (int j = 1; j <= m; j++) {         cin >> mp[i][j];         lis[mp[i][j]] = 1;       }       int cnt = 0;       for (auto &j : lis) {         j.second = ++cnt;       }       int len = lis.size();       for (int j = 1; j <= m; j++) {         prehb[i][j] = len - lis[mp[i][j]];         prehs[i][j] = lis[mp[i][j]] - 1;       }     }     for (int i = 1; i <= m; i++) {       map<int, int> lis;       for (int j = 1; j <= n; j++) {         lis[mp[j][i]] = 1;       }       int cnt = 0;       for (auto &j : lis) {         j.second = ++cnt;       }       int len = lis.size();       for (int j = 1; j <= n; j++) {         prelb[j][i] = len - lis[mp[j][i]];         prels[j][i] = lis[mp[j][i]] - 1;       }     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         int base = max(prehs[i][j], prels[i][j]);         int big = max(prehb[i][j], prelb[i][j]) + base + 1;         cout << big <<    ;       }       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, a, b;   int primect = 0;   int primes[40000];   int arr[1000000];   set<int> pset;   long long costl[1000000];   long long costr[1000000];   long long minCosts[30];   long long inf = numeric_limits<long long>::max();   void fillInPrimes() {     primes[0] = 2;     primect = 1;     for (int i = 3; i <= sqrt(1000000000); i += 2) {       bool isprime = true;       for (int j = 0; j < primect; j++) {         if (i % primes[j] == 0) {           isprime = false;           break;         }       }       if (isprime) {         primes[primect] = i;         primect++;       }     }   }   long long calcCost(int l, int r) {     long long cost = a * (long long)(r - l + 1);     if (l > 0) {       if (costl[l - 1] == inf) {         return inf;       } else {         cost += costl[l - 1];       }     }     if (r < n - 1) {       if (costr[r + 1] == inf) {         return inf;       } else {         cost += costr[r + 1];       }     }     return cost;   }   int main() {     cin >> n >> a >> b;     for (int i = 0; i < n; i++) {       cin >> arr[i];     }     fillInPrimes();     for (int i = 0; i < n; i = n - 1) {       for (int j = -1; j <= 1; j++) {         bool factored = false;         int fac = arr[i] + j;         int k = 0;         if (fac < 2) {           continue;         }         while (k < primect && primes[k] <= fac) {           if (fac % primes[k] == 0) {             pset.insert(primes[k]);             fac /= primes[k];             factored = true;           } else {             k++;           }         }         if (fac > 2) {           pset.insert(fac);         }       }       if (i == n - 1) {         break;       }     }     int pi = 0;     for (auto it = pset.begin(); it != pset.end(); it++) {       int p = *it;       for (int i = 0; i < n; i++) {         int mod = arr[i] % p;         if (mod == 0) {           costl[i] = 0;           costr[i] = 0;         } else if (mod == 1 || mod == p - 1) {           costl[i] = b;           costr[i] = b;         } else {           costl[i] = inf;           costr[i] = inf;         }       }       for (int i = 1; i < n; i++) {         if (costl[i - 1] == inf) {           costl[i] = inf;         } else if (costl[i] != inf) {           costl[i] += costl[i - 1];         }         if (costr[n - i] == inf) {           costr[n - i - 1] = inf;         } else if (costr[n - i - 1] != inf) {           costr[n - i - 1] += costr[n - i];         }       }       int firstInf = n;       int lastInf = 0;       for (int i = 0; i < n; i++) {         if (costl[i] == inf) {           firstInf = i;           break;         }       }       for (int i = n - 1; i >= 0; i--) {         if (costr[i] == inf) {           lastInf = i;           break;         }       }       long long minEndingHere = inf;       long long minLeft = 0;       long long minSoFar = costr[0];       for (int i = 0; i < n; i++) {         int l = min(i, firstInf);         int r = max(i, lastInf);         long long cost;         if (calcCost(minLeft, r) <= calcCost(l, r)) {           cost = calcCost(minLeft, r);         } else {           minLeft = l;           cost = calcCost(l, r);         }         if (cost < minSoFar) {           minSoFar = cost;         }       }       minCosts[pi] = minSoFar;       pi++;     }     long long minn = inf;     for (int i = 0; i < pset.size(); i++) {       minn = min(minn, minCosts[i]);     }     cout << minn << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 998244353;   int type[200010];   int weight[200010];   map<int, long long int> M;   long long int power(long long int a, int b) {     a %= mod;     long long int res = 1;     while (b) {       if (b & 1) res = res * a % mod;       a = a * a % mod;       b >>= 1;     }     return res;   }   long long int inv(int a) {     if (a <= 0) return 0;     if (M.find(a) != M.end()) return M[a];     return M[a] = power(a, mod - 2);   }   long long int dp[3001][3001];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n, m, w1 = 0, w2 = 0;     cin >> n >> m;     for (int i = 1; i <= n; i++) cin >> type[i];     for (int i = 1; i <= n; i++) {       cin >> weight[i];       if (!type[i])         w1 += weight[i];       else         w2 += weight[i];     }     dp[0][0] = 1;     for (int i = 1; i <= m; i++) {       for (int j = 0; j < i; j++)         dp[i][j] = dp[i - 1][j] * (w1 - (i - 1 - j)) % mod *                    inv(w1 - (i - 1 - j) + w2 + j) % mod;       for (int j = 1; j <= i; j++)         dp[i][j] = (dp[i][j] + dp[i - 1][j - 1] * (w2 + j - 1) % mod *                                    inv(w1 - (i - 1 - (j - 1)) + w2 + (j - 1))) %                    mod;     }     long long int c1 = 0, c2 = 0;     for (int i = 0; i <= m; i++) c2 = (c2 + dp[m][i] * (w2 + i)) % mod;     c2 = c2 * inv(w2) % mod;     for (int i = 0; i <= m; i++) c1 = (c1 + dp[m][i] * (w1 - (m - i))) % mod;     c1 = c1 * inv(w1) % mod;     for (int i = 1; i <= n; i++)       if (type[i])         cout << weight[i] * c2 % mod <<   n ;       else         cout << weight[i] * c1 % mod <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline int size(T x) {     return x.size();   }   long long k[3], t[3];   int num_done[100005] = {};   queue<int> waiters[3];   set<pair<long long, int> > Q;   void try_putinto(int pid, int qnr, long long tijd) {     if (!k[qnr]) {       waiters[qnr].push(pid);     } else {       num_done[pid]++;       k[qnr]--;       Q.insert(make_pair(tijd + t[qnr], pid));     }   }   void onefree(int qnr, long long tijd) {     k[qnr]++;     if (!waiters[qnr].empty()) {       int pid_next = waiters[qnr].front();       waiters[qnr].pop();       try_putinto(pid_next, qnr, tijd);     }   }   int main() {     cin >> k[0] >> k[1] >> k[2];     cin >> t[0] >> t[1] >> t[2];     int n;     cin >> n;     vector<long long> arrival;     for (int i = 0; i < n; i++) {       int tmp;       cin >> tmp;       arrival.push_back(tmp);     }     for (int i = 0; i < n; i++) {       Q.insert(make_pair(arrival[i], i));     }     long long t_res = 0;     while (!Q.empty()) {       pair<long long, int> pp = *Q.begin();       long long tijd = pp.first;       int pid = pp.second;       Q.erase(Q.begin());       if (num_done[pid] > 0) {         onefree(num_done[pid] - 1, tijd);       }       if (num_done[pid] == 3) {         t_res = max(t_res, tijd - arrival[pid]);       } else {         try_putinto(pid, num_done[pid], tijd);       }     }     cout << t_res << endl;   }


#include <bits/stdc++.h>   using namespace std;   struct point {     double x;     double y;   };   int compare(const void *a, const void *b) {     point *aa, *bb;     aa = (point *)a;     bb = (point *)b;     if (aa->x > bb->x)       return 1;     else if (aa->x < bb->x)       return -1;     else       return aa->y > bb->y;   }   int main(void) {     double y1, y2, y3, x1, x2, x3;     set<int> X, Y;     int status(0);     point points[8];     for (int i = 0; i < 8; i++) {       std::cin >> points[i].x >> points[i].y;       if (points[i].x < 0 || points[i].y < 0) status = -1;       X.insert(points[i].x);       Y.insert(points[i].y);     }     if (status == -1 || X.size() != 3 || Y.size() != 3) {       std::cout <<  ugly ;       return 0;     }     set<int>::iterator itx = X.begin();     set<int>::iterator ity = Y.begin();     y1 = *ity;     ity++;     y2 = *ity;     ity++;     y3 = *ity;     x1 = *itx;     itx++;     x2 = *itx;     itx++;     x3 = *itx;     if (!(y1 < y2 && y2 < y3 && x1 < x2 && x2 < x3)) {       std::cout <<  ugly ;       return 0;     }     qsort(points, 8, sizeof(point), compare);     if (x1 == points[0].x && x1 == points[1].x && x1 == points[2].x &&         x2 == points[3].x && x2 == points[4].x && x3 == points[5].x &&         x3 == points[6].x && x3 == points[7].x && y1 == points[0].y &&         y1 == points[3].y && y1 == points[5].y && y2 == points[1].y &&         y2 == points[6].y && y3 == points[2].y && y3 == points[4].y &&         y3 == points[7].y)       std::cout <<  respectable ;     else       std::cout <<  ugly ;   }


#include <bits/stdc++.h>   using namespace std;   bool check = false;   string s;   int maxi, n, i, j, a;   int main() {     cin >> n;     vector<int> v;     for (i = 0; i < n; i++) {       maxi = 0;       for (j = 0; j < n; j++) {         cin >> a;         maxi = max(maxi, a);       }       if (check == false && maxi == n - 1) {         maxi = n;         check = true;       }       v.push_back(maxi);     }     for (i = 0; i < v.size(); i++) {       cout << v[i] <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, p[200005];   int ans[200005];   queue<int> q;   int main() {     int Q;     cin >> Q;     while (Q--) {       memset(ans, 0, sizeof(ans));       cin >> n;       for (int i = 1; i <= n; i++) cin >> p[i];       for (int i = 1; i <= n; i++) {         if (ans[i]) continue;         int step = 1;         q.push(i);         for (int j = p[i]; j != i; j = p[j]) {           q.push(j);           step++;         }         while (!q.empty()) {           ans[q.front()] = step;           q.pop();         }       }       for (int i = 1; i <= n; i++) cout << ans[i] <<    ;       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   mt19937 rnd(51);   signed main() {     ios::sync_with_stdio(0);     cin.tie(0);     long long n;     cin >> n;     vector<long long> a(n);     for (long long i = 0; i < n; i++) {       cin >> a[i];     }     deque<pair<long long, long long>> q;     for (long long i = 0; i < n; i++) {       if (q.size() == 0) {         q.push_back({a[i], 1});       } else {         if (q.back().first == a[i]) {           q.back().second++;           if (q.size() > 1 && q[q.size() - 2].first >= q.back().first) {             long long now = q.back().second;             q.pop_back();             q.back().second += now;           }         } else if (q.back().first > a[i]) {           q.push_back({a[i], 1});         } else {           if (q.back().second % 2 == 1) {             cout <<  NO n ;             return 0;           } else {             q.push_back({a[i], 1});           }         }       }     }     while (q.size() > 1 && ((q[q.size() - 2].second % 2 == 0 &&                              q[q.size() - 2].first < q.back().first) ||                             (q.back().second % 2 == 0 &&                              q.back().first < q[q.size() - 2].first))) {       long long now = q.back().second;       long long mx = max(q.back().first, q[q.size() - 2].first);       q.pop_back();       q.back().first = mx;       q.back().second += now;     }     if (q.size() == 1) {       cout <<  YES n ;     } else {       cout <<  NO n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     long long n, k;     cin >> n >> k;     string s;     cin >> s;     vector<long long> l_r, r_l;     long long count = k + 1;     for (long long i = 0; i < n; i++) {       if (s[i] ==  1 ) {         count = 0;         l_r.push_back(0);       } else if (s[i] ==  0 ) {         count++;         if (count > k)           l_r.push_back(1);         else           l_r.push_back(0);       }     }     count = k + 1;     for (long long i = n - 1; i >= 0; i--) {       if (s[i] ==  1 ) {         count = 0;         r_l.push_back(0);       } else if (s[i] ==  0 ) {         count++;         if (count > k)           r_l.push_back(1);         else           r_l.push_back(0);       }     }     reverse(r_l.begin(), r_l.end());     long long i = 0, ans = 0;     while (i < n) {       if (l_r[i] && r_l[i]) {         ans++;         i += k;       }       i++;     }     cout << ans <<   n ;     return;   }   int main() {     long long t;     cin >> t;     for (long long i = 0; i < t; i++) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       string s;       cin >> s;       string ans;       ans = s;       sort(ans.begin(), ans.end());       int cnt = 0;       for (int i = 0; i < n; i++) {         if (ans[i] != s[i]) cnt++;       }       cout << cnt << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ld = long double;   const ld eps = 1e-8;   template <class U, class V>   ostream& operator<<(ostream& out, const pair<U, V>& p) {     return out <<  (  << p.first <<  ,   << p.second <<  ) ;   }   template <size_t i, class T>   ostream& print_tuple_utils(ostream& out, const T& tup) {     if constexpr (i == tuple_size<T>::value)       return out <<  ) ;     else       return print_tuple_utils<i + 1, T>(out << (i ?  ,   :  ( ) << get<i>(tup),                                          tup);   }   template <class... U>   ostream& operator<<(ostream& out, const tuple<U...>& tup) {     return print_tuple_utils<0, tuple<U...>>(out, tup);   }   template <class Con, class = decltype(begin(declval<Con>()))>   typename enable_if<!is_same<Con, string>::value, ostream&>::type operator<<(       ostream& out, const Con& container) {     out <<  { ;     for (auto it = container.begin(); it != container.end(); ++it)       out << (it == container.begin() ?    :  ,  ) << *it;     return out <<  } ;   }   template <int mod_>   struct modint {     static constexpr int mod = mod_;     int x;     modint(int xx = 0) : x(xx) {}     modint(ll xx) : x((int)(xx % mod)) {}     friend inline modint operator+(modint u, const modint& v) { return u += v; }     modint& operator+=(const modint& o) {       if ((x += o.x) >= mod) x -= mod;       return *this;     }     friend inline modint operator-(modint u, const modint& v) { return u -= v; }     modint& operator-=(const modint& o) {       if ((x -= o.x) < 0) x += mod;       return *this;     }     friend inline modint operator*(modint u, const modint& v) { return u *= v; }     modint& operator*=(const modint& o) { return *this = modint(1ll * x * o.x); }     modint pow(ll exp) const {       modint base = *this, ans = 1;       for (; exp > 0; exp >>= 1, base *= base)         if (exp & 1) ans *= base;       return ans;     }     friend inline modint operator/(modint u, const modint& v) { return u /= v; }     modint& operator/=(const modint& o) { return *this *= o.pow(mod - 2); }     friend bool operator==(const modint& u, const modint& v) {       return u.x == v.x;     }     friend ostream& operator<<(ostream& out, const modint& u) {       return out << u.x;     }   };   using mint = modint<(int)1e9 + 7>;   const int maxn = 696;   mint comb[maxn][maxn];   mint fac[maxn];   void precal() {     for (int i = (int)(0); i < (int)(maxn); ++i) {       comb[i][0] = 1;       for (int f = (int)(1); f < (int)(i + 1); ++f) {         comb[i][f] = comb[i - 1][f] + comb[i - 1][f - 1];       }     }     fac[0] = 1;     for (int i = (int)(1); i < (int)(maxn); ++i) fac[i] = fac[i - 1] * i;   }   int reduce_factor(int num) {     int ans = 1;     for (int i = 2; i * i <= num; ++i) {       if (num % i) continue;       int cnt = 0;       while (num % i == 0) {         num /= i;         cnt ^= 1;       }       if (cnt) ans *= i;     }     if (num > 1) ans *= num;     return ans;   }   mint brute(const vector<int>& a) {     auto is_perfect_sqr = [&](ll num) {       ll x = (ll)round(sqrt(num));       return x * x == num;     };     vector<int> pos(((int)a.size()));     for (int i = (int)(0); i < (int)(((int)a.size())); ++i) pos[i] = i;     mint ans = 0;     do {       bool ok = true;       for (int i = (int)(0); i < (int)(((int)a.size()) - 1); ++i) {         if (!is_perfect_sqr(1ll * a[pos[i]] * a[pos[i + 1]])) continue;         ok = false;         break;       }       ans += ok;     } while (next_permutation((pos).begin(), (pos).end()));     return ans;   }   mint solve(const vector<int>& a) {     map<int, int> cnt;     for (auto i : a) {       int rd = reduce_factor(i);       if (0)         cerr <<  [                   i                    =                << (i) <<  ]                <<  [                   rd                    =                << (rd) <<  ]   << endl;       cnt[rd]++;     }     vector<mint> dp = {1};     int cnt_have = 0;     for (auto [val, cur_cnt] : cnt) {       ;       if (0)         cerr <<  [                   val                    =                << (val) <<  ]                <<  [                   cur_cnt                    =                << (cur_cnt) <<  ]   << endl;       vector<mint> new_dp(((int)a.size()) + 2);       auto cur_fac = fac[cur_cnt];       for (int prev_same_pos = (int)(0); prev_same_pos < (int)(((int)dp.size()));            ++prev_same_pos) {         if (dp[prev_same_pos] == 0) continue;         int prev_res_pos = cnt_have + 1 - prev_same_pos;         for (int cnt_group = (int)(1); cnt_group < (int)(cur_cnt + 1);              ++cnt_group) {           ;           if (0)             cerr <<  [                       cnt_group                        =                    << (cnt_group) <<  ]   << endl;           int add_same_pos = cur_cnt - cnt_group;           for (int choose_same_pos = (int)(0);                choose_same_pos < (int)(prev_same_pos + 1); ++choose_same_pos) {             int choose_res_pos = cnt_group - choose_same_pos;             if (choose_res_pos < 0) break;             if (choose_res_pos > prev_res_pos) continue;             int new_same_pos = prev_same_pos + add_same_pos - choose_same_pos;             mint cur_ans = comb[prev_same_pos][choose_same_pos] *                            comb[prev_res_pos][choose_res_pos] *                            comb[cur_cnt - 1][cnt_group - 1] * dp[prev_same_pos];             if (0)               cerr <<  [                         choose_same_pos                          =                      << (choose_same_pos) <<  ]                      <<  [                         new_same_pos                          =                      << (new_same_pos) <<  ]                      <<  [                         cur_ans                          =                      << (cur_ans) <<  ]   << endl;             new_dp[new_same_pos] += cur_fac * cur_ans;           }         }       }       swap(dp, new_dp);       while (dp.size() and dp.back() == 0) dp.pop_back();       cnt_have += cur_cnt;       if (0)         cerr <<  [                   dp                    =                << (dp) <<  ]   << endl;       if (0)         cerr <<  [                   cnt_have                    =                << (cnt_have) <<  ]   << endl;     }     return dp[0];   }   mt19937 rng;   void check() {     while (true) {       int n = ((int)(rng() >> 1)) % 5 + 1;       vector<int> a(n);       for (int i = (int)(0); i < (int)(n); ++i)         a[i] = ((int)(rng() >> 1)) % 100 + 1;       ofstream inp( main.inp );       inp << n << endl;       for (int i = (int)(0); i < (int)(n); ++i) inp << a[i] <<    ;       inp << endl;       auto ans = solve(a);       auto exp = brute(a);       inp <<  [                ans                 =             << (ans) <<  ]             <<  [                exp                 =             << (exp) <<  ]   << endl;       inp.close();       if (ans == exp) {         cout <<  OK  << endl;         continue;       }       cout <<  FAILED  << endl;       exit(0);     }   }   int main() {     precal();     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     vector<int> a(n);     for (int i = (int)(0); i < (int)(n); ++i) cin >> a[i];     cout << solve(a) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<long long int> factors(long long int n) {     vector<long long int> v;     for (long long int i = 1; i * i <= n; i++) {       if (n % i == 0) {         if (i * i == n)           v.push_back(i);         else {           v.push_back(i);           v.push_back(n / i);         }       }     }     sort(v.begin(), v.end());     return v;   }   long long gcd(long long a, long long b) {     if (b == 0)       return a;     else       return gcd(b, a % b);   }   int main() {     std::ios_base::sync_with_stdio(false);     long long int t;     cin >> t;     while (t--) {       long long int n;       cin >> n;       long long int a[n], i, j;       for (i = 0; i < n; i++) {         cin >> a[i];       }       sort(a, a + n);       map<long long int, long long int> m;       long long int temp = a[n - 1];       vector<long long int> sol;       m[n - 1] = 1;       sol.push_back(temp);       long long int ans = temp, index;       for (i = 0; i < n; i++) {         long long int temp_gcd = INT_MIN;         for (j = 0; j < n; j++) {           if (m[j] == 0) {             long long int temp = gcd(ans, a[j]);             if (temp > temp_gcd) {               temp_gcd = temp;               index = j;             }           }         }         m[index] = 1;         sol.push_back(a[index]);         ans = temp_gcd;       }       for (i = 0; i < n; i++) {         cout << sol[i] <<    ;       }       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using vec_i = vector<int>;   using pii = pair<int, int>;   using ll = long long;   using vec_ii = vector<pii>;   using vec_ll = vector<ll>;   template <typename T>   using vec = vector<T>;   ll gcd(ll x, ll y) {     ll m;     while (y > 0) {       m = x % y;       x = y;       y = m;     }     return x;   }   ll powm(ll x, ll n, ll m) {     ll r = 1;     while (n > 0) {       if (n & 1) r = r * x % m;       x = x * x % m;       n /= 2;     }     return r;   }   static const int MOD = 1000000000 + 7;   static const int P = 343434;   const int PA = 257, PB = 983, MODA = 1e9 + 7, MODB = 1e9 + 9;   int n, m;   char ss[256][256];   int tt[256][256];   bool pal[256];   int hash_a[256], hash_b[256];   ll hash_lalaku[256];   int pa_pows[256], pb_pows[256];   inline bool is_pow2(int val) { return val != 0 && (val & (val - 1)) == 0; }   inline bool is_pal(int val, bool odd) {     return (odd && is_pow2(val)) || ((!odd) && (val == 0));   }   int solve() {     pa_pows[0] = 1;     pb_pows[0] = 1;     for (int i = 1; i < 256; ++i) {       pa_pows[i] = pa_pows[i - 1] * 1ll * PA % MODA;       pb_pows[i] = pb_pows[i - 1] * 1ll * PB % MODB;     }     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; ++i) {       scanf( %s , ss[i] + 1);     }     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= m; ++j) {         int val, c;         c = ss[i][j] -  a  + 1;         val = (1 << c);         tt[i][j] = tt[i][j - 1] ^ val;       }     }     ll ans = 0;     for (int i = 1; i <= m; ++i) {       memset(hash_a, 0, sizeof(hash_a));       memset(hash_b, 0, sizeof(hash_b));       for (int j = i; j <= m; ++j) {         bool all_same = true;         for (int k = 1; k <= n; ++k) {           pal[k] = is_pal(tt[k][j] ^ tt[k][i - 1], (j - i + 1) & 1);           hash_a[k] += pa_pows[ss[k][j] -  a  + 1];           hash_b[k] += pb_pows[ss[k][j] -  a  + 1];           if (hash_a[k] >= MODA) hash_a[k] -= MODA;           if (hash_b[k] >= MODB) hash_b[k] -= MODB;           hash_lalaku[k] = ((ll)hash_a[k] << 32) | (hash_b[k]);           all_same = (all_same) && pal[k] &&                      (k == 1 || hash_lalaku[k] == hash_lalaku[k - 1]);         }         if (all_same) {           ans += (n * (n + 1)) / 2;           continue;         }         for (int k = 1; k <= n; ++k) {           if (pal[k]) {             int l = k, r = k;             while (l > 1 && r < n && pal[l - 1] && pal[r + 1] &&                    hash_lalaku[l - 1] == hash_lalaku[r + 1]) {               --l;               ++r;             }             ans += (r - l + 1 + 1) / 2;           }           if (k < n && pal[k + 1] && hash_lalaku[k] == hash_lalaku[k + 1]) {             int l = k, r = k + 1;             while (l > 1 && r < n && pal[l - 1] && pal[r + 1] &&                    hash_lalaku[l - 1] == hash_lalaku[r + 1]) {               --l;               ++r;             }             ans += (r - l + 1) / 2;           }         }       }     }     printf( %lld n , ans);     return 0;   }   int main(int argc, char* argv[]) {     ::std::ios::sync_with_stdio(false);     ::std::cin.tie(0);     ::std::cout.tie(0);     int test_count = 1;     while (test_count--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int read() {     int x = 0, f = 1;     char ch = getchar();     while (ch <  0  ||  9  < ch) f = (ch ^  - ) ? f : -1, ch = getchar();     while ( 0  <= ch && ch <=  9 ) x = x * 10 + ch -  0 , ch = getchar();     return x * f;   }   int const N = 310;   double const EPS = 1e-8;   bool equal0(double x) { return -EPS < x && x < EPS; }   int n, m, T;   double a[N][N];   int b[N], id[N << 1];   void pivot(int x, int y) {     swap(id[n + x], id[y]);     double t = a[x][y];     a[x][y] = 1;     for (int i = 0; i <= n; i++) a[x][i] /= t;     for (int i = 0; i <= m; i++) {       if (i == x || equal0(a[i][y])) continue;       t = a[i][y], a[i][y] = 0;       for (int j = 0; j <= n; j++) a[i][j] -= a[x][j] * t;     }   }   bool simplex() {     while (true) {       int x = 0, y = 0;       for (int j = 1; !y && j <= n; j++)         if (a[0][j] > EPS) y = j;       if (!y) return true;       double minX = 1e18;       for (int i = 1; i <= m; i++)         if (a[i][y] > EPS && minX > a[i][0] / a[i][y])           minX = a[i][0] / a[i][y], x = i;       if (!x) {         puts( Unbounded );         return false;       }       pivot(x, y);     }   }   bool solve() {     for (int i = 1; i <= n; i++) id[i] = i;     while (true) {       int x = 0, y = 0;       for (int i = 1; i <= m; i++)         if (a[i][0] < -EPS && (!x || rand() & 1)) x = i;       if (!x) return simplex();       for (int j = 1; j <= n; j++)         if (a[x][j] < -EPS && (!y || rand() & 1)) y = j;       if (!y) {         puts( Infeasible );         return false;       }       pivot(x, y);     }   }   double ans[N];   int main() {     scanf( %d%d , &n, &m);     int _a, _b, _d;     memset(a, 0, sizeof a);     for (int i = 1; i <= m; i++) {       a[i][0] = -1;     }     for (int i = 1; i <= m; i++) {       scanf( %d%d%d , &_a, &_b, &_d);       a[0][_a] -= _d;       a[0][_b] += _d;       a[i][_a] = -1;       a[i][_b] = 1;     }     T = 1;     if (solve()) {       if (!T) return 0;       for (int i = 1; i <= m; i++) ans[id[n + i]] = a[i][0];       for (int i = 1; i <= n; i++) printf( %d  , (int)ans[i]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   multiset<int, greater<int> > s1;   multiset<int> s2;   int bs1, bs2, n, a[500500], b[500500], ct, nomb[500500], cr, noma[500500];   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d , &a[i]);       noma[a[i]] = i;     }     for (int i = 0; i < n; i++) {       scanf( %d , &b[i]);       nomb[b[i]] = i;     }     s1.clear();     s2.clear();     bs1 = 0;     bs2 = 0;     for (int i = 0; i < n; i++) {       ct = nomb[a[i]] - i;       if (ct <= 0)         s1.insert(ct);       else         s2.insert(ct);     }     for (int i = 0; i < n; i++) {       cr = 1000000000;       if (!s1.empty()) {         int qt = *s1.begin();         cr = min(cr, (-(qt - bs1)));       }       if (!s2.empty()) cr = min(cr, (*s2.begin()) - bs2);       printf( %d n , cr);       ct = 0 - noma[b[i]] + bs1;       s1.erase(s1.find(ct));       ct = n - 1 - noma[b[i]] + bs2 + 1;       s2.insert(ct);       bs1++;       bs2++;       while ((!s2.empty()) && (*s2.begin() == bs2)) {         s2.erase(s2.begin());         s1.insert(0 + bs1);       }     }   }


#include <bits/stdc++.h>   int main() {     int numDominoes;     char dominoes[3005];     int fallen = 0;     int count = 0;     int isL = 0;     int seenR = 0;     scanf( %d , &numDominoes);     for (int i = 0; i <= numDominoes; i++) {       scanf( %c , &dominoes[i]);     }     for (int i = 1; i <= numDominoes; i++) {       if (dominoes[i] ==  . ) {         count++;       } else if (dominoes[i] ==  R ) {         count = 0;         fallen++;         for (int j = i; j <= numDominoes; j++) {           if (dominoes[j] ==  L ) {             isL = 1;             break;           }         }         if (isL == 0) {           fallen += numDominoes - i;         }         isL = 0;         seenR = 1;       } else if (dominoes[i] ==  L ) {         fallen++;         if (count > 0 && seenR == 1) {           if (count % 2 == 0) {             fallen += count;           } else {             fallen += count - 1;           }         } else {           fallen += count;         }         count = 0;       }     }     printf( %d n , numDominoes - fallen);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, a, b;   int M[256 + 1];   int main() {     scanf( %d %d %d , &n, &a, &b);     if (a & 1) a++;     if (b & 1) b++;     int round = 1;     for (;;) {       a /= 2;       b /= 2;       if (a == b) break;       round++;       if (a & 1) a++;       if (b & 1) b++;     }     if (round == (int)log2(n))       printf( Final! n );     else       printf( %d n , round);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a, b, diff, n_div;   int main() {     int i;     cin >> a >> b;     diff = a - b;     if (diff < 0) {       cout <<  0  << endl;     } else if (diff == 0) {       cout <<  infinity  << endl;       return 0;     } else {       for (i = 1; i * i <= diff; i++)         if (diff % i == 0) {           if (i > b) n_div++;           if (diff / i > b && diff / i != i) n_div++;         }       cout << n_div << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2010;   vector<int> G[maxn];   int n, m, d[maxn], par[maxn], a[maxn], vis[maxn], flag = 1;   char s[1005][1005];   int find(int u) {     if (par[u] != u) par[u] = find(par[u]);     return par[u];   }   struct node {     int u, w;     node(int a, int b) { u = a, w = b; }   };   void topo() {     queue<node> q;     for (int i = 1; i <= n + m; i++) {       int fa = find(i);       if (!d[fa] && !vis[fa]) q.push(node(fa, 1)), vis[fa] = 1;     }     while (!q.empty()) {       node e = q.front();       q.pop();       int u = e.u;       a[u] = max(a[u], e.w);       for (int i = 0; i < G[u].size(); i++) {         int v = G[u][i];         a[v] = max(a[u] + 1, a[v]);         d[v]--;         if (d[v] == 0) q.push(node(v, a[v]));       }     }     for (int i = 1; i <= n + m; i++)       if (d[i]) puts( No ), exit(0);   }   void add(int i, int j) {     int fa = find(i), fb = find(j);     if (fa == fb) puts( No ), exit(0);     d[fa]++;     G[fb].push_back(fa);   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n + m; i++) par[i] = i;     for (int i = 1; i <= n; i++) {       scanf( %s , s[i] + 1);       for (int j = 1; j <= m; j++)         if (s[i][j] ==  = ) {           int fa = find(i), fb = find(j + n);           par[fa] = fb;         }     }     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++)         if (s[i][j] ==  > )           add(i, n + j);         else if (s[i][j] ==  < )           add(n + j, i);     topo();     puts( Yes );     for (int i = 1; i < n; i++) printf( %d  , a[find(i)]);     printf( %d n , a[find(n)]);     for (int i = 1; i < m; i++) printf( %d  , a[find(i + n)]);     printf( %d n , a[find(n + m)]);   }


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


#include <bits/stdc++.h>   using namespace std;   const long long M = 1e9 + 7;   const double eps = 1e-8;   const int maxn = 1e6 + 5;   const int INF = 1e9;   const int maxnode = 7e6 + 5;   const int sigma_size = 2;   void tran2(int num, int s[]) {     for (int i = 0; i < 31; i++) {       s[i] = (num >> (30 - i)) & 1;     }   }   struct Trie {     int ch[maxnode][sigma_size];     int val[maxnode], able[maxnode];     int sz;     void init() {       sz = 1;       memset(ch, 0, sizeof(ch));       memset(val, 0, sizeof(val));       memset(able, 0, sizeof(able));     }     int idx(int c) { return c; }     void insert(int *s) {       int u = 0, n = 31;       for (int i = 0; i < n; i++) {         able[u]++;         int c = idx(s[i]);         if (!ch[u][c]) {           val[sz] = 0;           ch[u][c] = sz++;         }         u = ch[u][c];       }       able[u]++;       val[u]++;     }     void del(int *s) {       int u = 0, n = 31;       for (int i = 0; i < n; i++) {         able[u]--;         int c = idx(s[i]);         u = ch[u][c];       }       able[u]--;       val[u]--;     }     int find_min(int *s) {       int u = 0, i = 1, num = 0;       int k = 0;       int r = 0;       for (k = 0; k < 31; k++) {         int y = idx(s[k]);         int x = y ^ 1;         able[u]--;         if (ch[u][y] && able[ch[u][y]] > 0) {           u = ch[u][y];         } else {           r += 1 << (30 - k);           u = ch[u][x];         }       }       able[u]--;       val[u]--;       return r;     }   } trie;   int a[maxn], p[maxn], n, s[maxn];   int main(void) {     scanf( %d , &n);     trie.init();     for (int i = 0; i < n; i++) {       scanf( %d , &a[i]);     }     for (int i = 0; i < n; i++) {       scanf( %d , &p[i]);       tran2(p[i], s);       trie.insert(s);     }     int tmp;     for (int i = 0; i < n; i++) {       tran2(a[i], s);       tmp = trie.find_min(s);       printf( %d  , tmp);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 4 * 100000 + 10;   char ss[MAXN];   int main() {     scanf( %s , ss);     int cis;     int len = strlen(ss);     int l = len;     for (int i = 0; i < len; i++) {       ss[i + len] = ss[i];     }     len = strlen(ss);     int ans = 1;     int maxx = 1;     for (int i = 1; i < len; i++) {       if (ss[i] != ss[i - 1]) {         maxx++;         int dadasdsadadsadada;         ans = max(ans, maxx);       } else {         int sdd;         maxx = 1;       }     }     ans = min(ans, l);     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, ptr;   bool mark[100010];   bool bad[100010];   int ord[100010];   vector<int> dir[100010];   vector<int> rev[100010];   vector<int> adj[100010];   bool dfs(int idx) {     bool ret = bad[idx];     mark[idx] = true;     for (int i = 0; i < adj[idx].size(); i++)       if (!mark[adj[idx][i]]) ret |= dfs(adj[idx][i]);     return ret;   }   void setOrd(int idx) {     mark[idx] = true;     for (int i = 0; i < dir[idx].size(); i++)       if (!mark[dir[idx][i]]) setOrd(dir[idx][i]);     ord[--ptr] = idx;   }   int ccf(int idx) {     int cnt = 1;     mark[idx] = true;     for (int i = 0; i < rev[idx].size(); i++)       if (!mark[rev[idx][i]]) cnt += ccf(rev[idx][i]);     return cnt;   }   int main() {     cin >> n >> m;     ptr = n;     int a, b;     for (int i = 0; i < m; i++) {       cin >> a >> b;       a--, b--;       dir[a].push_back(b);       rev[b].push_back(a);       adj[a].push_back(b);       adj[b].push_back(a);     }     int res = n;     for (int i = 0; i < n; i++)       if (!mark[i]) setOrd(i);     memset(mark, false, sizeof mark);     for (int i = 0; i < n; i++) {       if (!mark[ord[i]]) {         int tmp = ccf(ord[i]);         if (tmp > 1) bad[ord[i]] = true;       }     }     memset(mark, false, sizeof mark);     for (int i = 0; i < n; i++)       if (!mark[i] && !dfs(i)) res--;     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   static int io_sync_off = []() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     return 0;   }();   long long Pow(long long a, long long b, long long mod) {     long long res = 1;     a %= mod;     while (b) {       if (b & 1) (res *= a) %= mod;       (a *= a) %= mod;       b >>= 1;     }     return res % mod;   }   long long inv(long long a, long long p) {     if (a == 1) return 1;     return (p - p / a) * inv(p % a, p) % p;   }   long long C(long long n, long long m, long long p) {     long long res = 1;     for (long long i = 1, j = n - m + 1; i <= m; ++i, ++j) {       res = res * inv(i, p) % p * j % p;     }     return res;   }   const int N = 2e5 + 10;   struct M {     bool operator<(const M &t) const { return x < t.x; }     int x, y, z;   };   long long Max[N * 4], tag[N * 4];   void push_down(int o) {     int lc = 2 * o, rc = 2 * o + 1;     tag[lc] += tag[o];     tag[rc] += tag[o];     Max[lc] += tag[o];     Max[rc] += tag[o];     tag[o] = 0;   }   void update(int a, int b, int v, int o, int l, int r) {     if (a == b) return;     if (a <= l && b >= r) {       tag[o] += v;       Max[o] += v;       return;     }     push_down(o);     int mid = (l + r) >> 1, lc = 2 * o, rc = 2 * o + 1;     if (a < mid) update(a, b, v, lc, l, mid);     if (b > mid) update(a, b, v, rc, mid, r);     Max[o] = max(Max[lc], Max[rc]);   }   M Mon[N];   pair<long long, long long> a[N], b[N];   int d[N];   void build(int o, int l, int r) {     if (r - l == 1) {       Max[o] = -b[l].second;       return;     }     int mid = (l + r) >> 1, lc = 2 * o, rc = 2 * o + 1;     build(lc, l, mid);     build(rc, mid, r);     Max[o] = max(Max[lc], Max[rc]);   }   int main() {     int n, m, p;     scanf( %d%d , &n, &m);     scanf( %d , &p);     for (int i = 0; i < n; ++i) scanf( %d%d , &a[i].first, &a[i].second);     for (int i = 0; i < m; ++i) scanf( %d%d , &b[i].first, &b[i].second);     for (int i = 0; i < p; ++i) scanf( %d%d%d , &Mon[i].x, &Mon[i].y, &Mon[i].z);     sort(a, a + n);     sort(b, b + m);     sort(Mon, Mon + p);     for (int i = 0; i < m; ++i) d[i] = b[i].first;     build(1, 0, m);     long long ans = -1e18;     int j = 0;     for (int i = 0; i < n; ++i) {       while (j < p && Mon[j].x < a[i].first) {         int l = upper_bound(d, d + m, Mon[j].y) - d;         update(l, m, Mon[j++].z, 1, 0, m);       }       ans = max(ans, Max[1] - a[i].second);     }     printf( %lld , ans);     return 0;   }


/*          _/_/_/_/_/_/  _/_/_/_/_/  _/_/_/_/_/  _/_/_/_/_/  _/_/_/_/_/  _/   _/         _/      _/  _/          _/          _/      _/  _/      _/  _/  _/        _/      _/  _/_/_/      _/_/_/      _/_/_/_/_/  _/_/_/_/_/  _/_/       _/      _/  _/          _/          _/          _/      _/  _/  _/    _/_/_/_/_/_/  _/_/_/_/_/  _/_/_/_/_/  _/          _/      _/  _/    _/   */      #include<bits/stdc++.h>   #include<math.h>   #define IOS             ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);   #define int             long long   #define test            int t; cin>>t; while(t--)   #define vi              vector<int> v;   #define pb              push_back   #define input(arr)      int n; cin>>n; int arr[n]; for(int i=0; i<n; i++) {cin>>arr[i];}   #define f(n)            for(int i=0; i<n; i++)   #define OK              if(ok){cout<< YES <<endl;} else{cout<< NO <<endl;}   #define Ok              if(ok){cout<< Yes <<endl;} else{cout<< No <<endl;}   #define mod             1000000007   #define endl   n    using namespace std;   //-----------------------------------------------------------------------------       // to check prime number IN O(sqrt(n))   //bool isPrime(int);   //   //// to get divisors of a number IN O(sqrt(n))   //vector<int> divisors(int);   //   //// to find power using mod using Binary Exponential in TC O(logn)   //int power(int, int, int);   //   //// ternary search to find x in sorted array arr   //int ts(int, int, int, int);   //   //// to find frequencies of a substring in a string or to find all positions of all substrings   //vector<int> count_freq(string ,string);   //   ////to check palindrome   //bool palindrome(int, int);   //   #ifndef ONLINE_JUDGE   // if (fopen( input.txt ,  r ))   // {   //  freopen( input.txt ,  r , stdin);   //  freopen( output.txt ,  w , stdout);   // }   // #endif       //*************************************************************************************************      vector<int> printDivisors(int n, int temp)    {      vector<int> vec;       // Note that this loop runs till square root        for (int i=1; i<=sqrt(n); i++)        {            if (n%i == 0)            {                // If divisors are equal, print only one                if (n/i == i)                {                 if(i >= temp)                   vec.pb(i);               }                     else // Otherwise print both                {                 if(i >= temp)                   vec.pb(i);                 if((n/i) >= temp)                   vec.pb(n/i);               }            }        }        return vec;   }      int32_t main()   {     IOS     #ifndef ONLINE_JUDGE    if (fopen( input.txt ,  r ))    {     freopen( input.txt ,  r , stdin);     freopen( output.txt ,  w , stdout);    }    #endif        test     {       int n;       cin >> n;       int arr[n];       int temp = 0;       int sum = 0;       f(n)       {         cin >> arr[i];         sum += arr[i];         temp = max(temp, arr[i]);       }          vector<int> v = printDivisors(sum, temp);       sort(v.begin(), v.end());          int ans = 0;       int j=0, add=0;       int t1 = v[j];          for(int i=0; i<n; i++)       {         if(arr[i] != t1)         {           add += arr[i];                                ans++;           if(add > t1)           {             ans = 0;             add = 0;             i = -1;             ++j;             t1 = v[j];           }           else if(add == t1)           {             ans--;             add = 0;           }         }         else if(add > 0)         {           add = 0;           ans = 0;           i = -1;           ++j;           t1 = v[j];         }       }       cout << ans << endl;     }     return 0;   }         //******************************************************************************       //getchar() - uses for no extra comments in output section   //toupper() - converts a string in uppercase   //tolower()   //lower_bound((a, a+n, m)-a) - when you have to find total number of small values to m b/w range of a to a+n   //   or finds the lower position of num. eg 10 20 30 30 30 40 50 num=30, ans = 2;   //upper_bound - work as lower_bound but finds the upper position. eg 10 20 30 30 30 40 50 num=30, ans = 5;    //shift+f6+enter - to change a word everywhere   //stringstream - to find number of words in a string or to find frequency of words   //s.substr(1, 3) - geeks - eek   //*max_element(v+2, v+4) - to find max element in an array   //*min_element   //__gcd(2, 10) - to find greatest common devisor, doesn t support float or double   //count(a, a+n, k) - to find frequency of k or frequency of a char in string in an array or in vector   //s =  aaaaa , a[2]++, s = aabaa   //compare() - to campare to string s size   //__builtin_popcountll(n) - number of bit 1 in n   //__builtin_ctzll(n) - number of bit 0 after last 1   //cout<<fixed()<<setprecision(k)<<endl;   //log(n) - to find digits in binary repersatation, returns float value   //floor(1.3) - 3, floor(-1.2) - -2       //******************************************************************************                   //// to check prime number   //bool isPrime(int n)  //IN  O(sqrt(n))   //{   //    if(n<=1) return false;   //    for(int i=2;i*i<=n;i++)   //        if(n%i==0)   //            return false;   //   //    return true;   //}   //   //// to get divisors of a number. Recall - it s not i sorted order   //// vector<int> v = divisors(n); function call   //vector<int> divisors(int n){    //IN  O(sqrt(n))   //   //    vector<int> v;   //    for(int i=1;i*i<=n;i++)   //    {   //        if(n%i==0)   //        {   //            v.pb(i);   //            if((n/i)!=i)   //            v.pb(n/i);   //        }   //    }   //    return v;   //}   //   //// to find power using mod   //int power(int a, int n, int m)  // using Binary Exponential in TC O(logn)   //{   //    int res=1;   //    while(n)   //    {   //        if(n%2)   //        res=(res*a)%m ,n--;   //        else   //        a=(a*a)%m ,n/=2;   //    }   //    return res;   //}   //   //// ternary search to find x in sorted array arr   //int ts(int arr[],int l,int r,int x)   //{   //   //    while(l<=r)   //    {   //        int mid1= l+(r-l)/3;   //        int mid2= r -(r-l)/3;   //        if(arr[mid1]==x || arr[mid2]==x)   //            return 1;   //        if(x<arr[mid1])   //            r=mid1-1;   //        else if(x>arr[mid2])   //            l=mid2+1;   //        else   //        {   //            l=mid1+1;   //            r=mid2-1;   //        }   //    }   //    return 0;   //}   //   //// to find frequencies of a substring in a string or to find all positions of all substrings   //// vector<int> v = count_freq(s1 ,s2); function calling   //// position storing is 0 based indexing add 1 if required 1 based indexing.   ////This code is used to count the frequency of particular substring in a given string using the found function   //vector<int> count_freq(string &str ,string &substr)   //{   // vector<int>pos;   // size_t found = str.find(substr,0);   // while(found!=string::npos)   // {   //  pos.pb(found);   //  found=str.find(substr,found+1);   //    }   //    return pos;   //}   //   //   //bool palindrome(int arr[], int n)   //{   //    int flag = 0;   //    for (int i = 0; i <= n / 2 && n != 0; i++) {   //        if (arr[i] != arr[n - i - 1]) {   //            flag = 1;   //            break;   //        }   //    }   //    if (flag == 1)   //        return true;   //    else   //        return false;   //}


#include <bits/stdc++.h>   using namespace std;   int main() {     int b, k;     cin >> b >> k;     int ans = 0;     for (int i = 1; i <= k; i++) {       int x;       cin >> x;       if (i != k)         ans = (ans + b * x % 2) % 2;       else         ans = (ans + x % 2) % 2;     }     if (ans % 2 == 0) {       cout <<  even ;     } else       cout <<  odd ;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 105;   int n, m;   map<string, int> h;   string name[N], str[N], re[N];   bool f[N][N];   int g[N][N];   void print(int x, int y) {     if (x == 0) {       return;     }     print(x - 1, g[x][y]);     cout << name[y] << re[x - 1] << endl;   }   void work() {     scanf( %d , &n);     h.clear();     for (int i = 0; i < n; ++i) {       cin >> name[i];       h[name[i]] = i;     }     scanf( %d n , &m);     memset(f, 0, sizeof(f));     memset(g, 0, sizeof(g));     f[0][n] = 1;     for (int i = 0; i < m; ++i) {       getline(cin, str[i]);       re[i].clear();     }     for (int i = 0; i < m; ++i) {       string usr, buf = str[i];       int p = 0;       while (p < buf.size() && buf[p] !=  : ) {         usr += buf[p++];       }       int q = p;       while (q < buf.size()) {         re[i] += buf[q++];       }       set<int> mention;       while (p < buf.size()) {         string word;         while (p < buf.size() && isalnum(buf[p])) {           word += buf[p++];         }         if (h.count(word)) {           mention.insert(h[word]);         }         if (p < buf.size()) ++p;       }       if (usr ==  ? ) {         for (int j = 0; j <= n; ++j) {           if (!f[i][j]) continue;           for (int k = 0; k < n; ++k) {             if (mention.count(k) || k == j) continue;             f[i + 1][k] = 1;             g[i + 1][k] = j;           }         }       } else {         if (!h.count(usr)) {           puts( Impossible );           return;         }         int id = h[usr];         if (!mention.count(id)) {           for (int j = 0; j <= n; ++j) {             if (f[i][j] && id != j) {               f[i + 1][id] = 1;               g[i + 1][id] = j;             }           }         }       }     }     int x = -1;     for (int i = 0; i < n; ++i) {       if (f[m][i]) {         x = i;       }     }     if (x == -1) {       puts( Impossible );     } else {       print(m, x);     }   }   int main() {     int T;     scanf( %d , &T);     while (T--) {       work();     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int l, b, M, N;     cin >> M;     cin >> N;     l = std::max(M, N);     b = std::min(M, N);     if (b >= 2) {       cout << (b * (l / 2) + (b / 2) * (l % 2));     } else       cout << (b * (l / 2));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int xa[300005] = {0};     for (int i = 1; i <= 300000; i++) {       xa[i] = (xa[i - 1] ^ i);     }     int t;     cin >> t;     while (t--) {       long long a, b;       cin >> a >> b;       long long x = xa[a - 1];       if (x == b) {         cout << a << endl;       } else {         if ((x ^ b) == a) {           cout << a + 2 << endl;         } else {           cout << a + 1 << endl;         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   int n, m, x[101];   double e[2][101 * 1001], sume[101 * 1001];   int main(int argc, const char* argv[]) {     scanf( %d%d , &n, &m);     for (int i = 0; i < n; i++) scanf( %d , x + i);     if (m == 1) {       puts( 1.00 );       return 0;     }     int cur = 0, pre = 1;     e[pre][0] = m - 1;     for (int i = 0; i < n; i++) {       cur = i % 2;       pre = 1 - cur;       sume[0] = e[pre][0];       for (int j = 1; j <= (i + 1) * m; j++) sume[j] = sume[j - 1] + e[pre][j];       for (int s = 0; s <= (i + 1) * m; s++) {         int l, r;         if (s >= 1) {           l = max(s - m, 0), r = s - 1;           if (l - 1 >= 0)             e[cur][s] = sume[r] - sume[l - 1];           else             e[cur][s] = sume[r];           if (l <= s - x[i] && s - x[i] <= r) e[cur][s] -= e[pre][s - x[i]];           e[cur][s] /= (double)(m - 1.0);         } else           e[cur][s] = 0;       }     }     int sum = 0;     double ans = 0;     for (int i = 0; i < n; i++) sum += x[i];     for (int i = 0; i < sum; i++) ans += e[cur][i];     printf( %.9lf n , ans + 1.0);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long a, b, c, d, e, tp, f, g, h, p[100], pi, q[100], qi, pas;   map<pair<long long, long long>, long long> m;   int main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     cin >> a;     for (b = 1; b <= a; b++) {       cin >> tp;       if (tp == 1) {         cin >> c >> d >> e;         pi = 0;         while (c > 0) {           pi++;           p[pi] = c % 2;           c /= 2;         }         c = d;         for (d = 1; d <= pi / 2; d++) {           swap(p[d], p[pi - d + 1]);         }         d = c;         qi = 0;         while (d > 0) {           qi++;           q[qi] = d % 2;           d /= 2;         }         for (d = 1; d <= qi / 2; d++) {           swap(q[d], q[qi - d + 1]);         }         c = 0;         f = 0;         for (d = 1; d <= min(pi, qi); d++) {           if (p[d] == q[d]) {             g = c;             if (p[d] == 0)               c = c * 2;             else               c = c * 2 + 1;           } else {             break;           }         }         f = d;         h = c;         for (d = f; d <= pi; d++) {           g = c;           if (p[d] == 0)             c = c * 2;           else             c = c * 2 + 1;           m[make_pair(g, c)] += e;         }         c = h;         for (d = f; d <= qi; d++) {           g = c;           if (q[d] == 0)             c = c * 2;           else             c = c * 2 + 1;           m[make_pair(g, c)] += e;         }       } else {         cin >> c >> d;         pas = 0;         pi = 0;         while (c > 0) {           pi++;           p[pi] = c % 2;           c /= 2;         }         c = d;         for (d = 1; d <= pi / 2; d++) {           swap(p[d], p[pi - d + 1]);         }         d = c;         qi = 0;         while (d > 0) {           qi++;           q[qi] = d % 2;           d /= 2;         }         for (d = 1; d <= qi / 2; d++) {           swap(q[d], q[qi - d + 1]);         }         c = 0;         f = 0;         for (d = 1; d <= min(pi, qi); d++) {           if (p[d] == q[d]) {             g = c;             if (p[d] == 0)               c = c * 2;             else               c = c * 2 + 1;           } else {             break;           }         }         f = d;         h = c;         for (d = f; d <= pi; d++) {           g = c;           if (p[d] == 0)             c = c * 2;           else             c = c * 2 + 1;           pas = pas + m[make_pair(g, c)];         }         c = h;         for (d = f; d <= qi; d++) {           g = c;           if (q[d] == 0)             c = c * 2;           else             c = c * 2 + 1;           pas = pas + m[make_pair(g, c)];         }         cout << pas << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 7;   const int K = 20;   int go[N][K];   int tin[N], tout[N];   vector<int> g[N];   int timer = 0;   int perm[N];   int where[N];   pair<int, int> t[4 * N];   int n;   void dfs(int u, int p = 0) {     go[u][0] = p;     tin[u] = timer++;     for (int i = 1; i < K; ++i) {       go[u][i] = go[go[u][i - 1]][i - 1];     }     for (auto v : g[u]) {       if (v != p) {         dfs(v, u);       }     }     tout[u] = timer++;   }   bool anc(int a, int b) { return tin[a] <= tin[b] && tout[b] <= tout[a]; }   int lca(int a, int b) {     if (anc(a, b)) return a;     for (int k = K - 1; k >= 0; --k) {       if (!anc(go[a][k], b)) {         a = go[a][k];       }     }     return go[a][0];   }   pair<int, int> null = {-1, -1};   pair<int, int> empt = {-2, -2};   int d;   bool on_path(int a, int b, int c) {     return anc(d, c) && (anc(c, a) || anc(c, b));   }   bool check(int l, int r, const pair<int, int> &a, const pair<int, int> &b) {     d = lca(l, r);     return on_path(l, r, a.first) && on_path(l, r, a.second) &&            on_path(l, r, b.first) && on_path(l, r, b.second);   }   pair<int, int> merge(const pair<int, int> &a, const pair<int, int> &b) {     if (a == null || b == null) return null;     if (a == empt) return b;     if (b == empt) return a;     if (check(a.first, a.second, a, b)) return a;     if (check(b.first, b.second, a, b)) return b;     if (check(a.first, b.first, a, b)) return {a.first, b.first};     if (check(a.second, b.second, a, b)) return {a.second, b.second};     if (check(a.first, b.second, a, b)) return {a.first, b.second};     if (check(a.second, b.first, a, b)) return {a.second, b.first};     return null;   }   void build(int l, int r, int v) {     if (l == r) {       t[v] = {where[l], where[l]};     } else {       int m = (l + r) >> 1;       build(l, m, 2 * v + 1);       build(m + 1, r, 2 * v + 2);       t[v] = merge(t[2 * v + 1], t[2 * v + 2]);     }   }   void modify(int ind, int l, int r, int v) {     if (l == r) {       t[v] = {where[ind], where[ind]};     } else {       int m = (l + r) >> 1;       if (ind <= m)         modify(ind, l, m, 2 * v + 1);       else         modify(ind, m + 1, r, 2 * v + 2);       t[v] = merge(t[2 * v + 1], t[2 * v + 2]);     }   }   void update(int a, int b) {     int pa = perm[a];     int pb = perm[b];     swap(where[perm[a]], where[perm[b]]);     swap(perm[a], perm[b]);     modify(pa, 0, n - 1, 0);     modify(pb, 0, n - 1, 0);   }   int get(int l, int r, int v, pair<int, int> &pth) {     if (l == r) {       pth = merge(pth, t[v]);       if (pth == null) return l - 1;       return l;     }     int m = (l + r) >> 1;     auto cur = merge(pth, t[2 * v + 1]);     if (cur.first != -1) {       return get(m + 1, r, 2 * v + 2, cur);     }     return get(l, m, 2 * v + 1, pth);   }   int mex() {     pair<int, int> cur = empt;     return get(0, n - 1, 0, cur) + 1;   }   void init() {     cin >> n;     for (int i = 0; i < n; ++i) {       cin >> perm[i];       where[perm[i]] = i;     }     for (int i = 1; i < n; ++i) {       int p;       cin >> p;       --p;       g[p].push_back(i);     }     dfs(0);     build(0, n - 1, 0);   }   void solve() {     int q;     cin >> q;     while (q--) {       int t;       cin >> t;       if (t == 1) {         int a, b;         cin >> a >> b;         --a, --b;         update(a, b);       } else {         cout << mex() <<   n ;       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.setf(ios::fixed);     cout.precision(20);     init();     solve();   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 2e5 + 7;   int n;   int tmp[N];   int a[N], val[N], sta[N];   int dpl[N], dpr[N];   void init(int n, int *dp) {     int top = 0;     int mx = 0;     for (int i = 1; i <= n; i++) {       int ma = 0;       while (top && a[sta[top]] > a[i]) {         ma = max(ma, val[top]);         top--;       }       sta[++top] = i;       if (ma == 0)         val[top] = top;       else         val[top] = ma + 1;       mx = max(mx, val[top]);       dp[i] = mx;     }   }   int main() {     scanf( %d , &n);     if (n == 1) {       printf( %d %d n , 1, 0);       return 0;     }     int mi = 1e9, rt;     for (int i = 1; i <= n; i++) {       scanf( %d , &tmp[i]);       if (tmp[i] < mi) mi = tmp[i], rt = i;     }     for (int i = 1, j = rt - 1; i < n; i++, j--) {       if (j < 1) j += n;       a[i] = tmp[j];     }     init(n - 1, dpl);     for (int i = 1, j = rt + 1; i < n; i++, j++) {       if (j > n) j -= n;       a[i] = tmp[j];     }     init(n - 1, dpr);     int ans = 1e9, shft;     for (int i = 0; i < n; i++) {       if (ans > max(dpl[i], dpr[n - 1 - i]) + 1) {         ans = max(dpl[i], dpr[n - 1 - i]) + 1;         shft = rt - (i + 1);       }     }     if (shft < 0) shft += n;     printf( %d %d n , ans, shft);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1000010;   char s[maxn];   int tp[maxn >> 3], sz[maxn >> 3], n, cnt;   long long ans;   int main() {     scanf( %d , &n);     int l;     for (int i = 1; i <= n; i++) {       scanf( %s , s + 1);       l = strlen(s + 1);       for (int k = 1; k <= l; k++) tp[i] ^= (1 << (int)(s[k] -  a ));     }     sort(tp + 1, tp + 1 + n);     cnt = 1;     for (int i = 1; i <= n; i++) {       if (tp[i] != tp[cnt]) tp[++cnt] = tp[i];       ++sz[cnt];     }     for (int i = 1; i <= cnt; i++) {       ans += 1LL * (sz[i] - 1) * sz[i] >> 1;       for (int k = 0; k <= 25; k++)         if (!((1 << k) & tp[i])) {           int c = tp[i] | (1 << k);           int p = lower_bound(tp + 1, tp + 1 + cnt, c) - tp;           if (tp[p] != c) continue;           ans += 1LL * sz[i] * sz[p];         }     }     printf( %I64d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct comp1 {     bool operator()(const long long &a, const long long &b) { return (a > b); }   };   typedef struct node {     long long num;     vector<node *> des;   } node;   int n;   long long arr[8];   int best;   node *root;   vector<node *> imp;   bool prime[1000000 + 1];   set<long long> primes;   int breakInto(long long num) {     if (num == 0) return 0;     int cnt = 0;     for (set<long long>::iterator i = primes.begin(); i != primes.end(); i++) {       while (num % (*i) == 0) {         cnt++;         num /= (*i);       }       if (num == 1) break;     }     return cnt;   }   int count(node *curr) {     int cnt = 0;     if (curr->des.size() == 0) {       int ret = breakInto(curr->num);       if (ret == 1)         return 1;       else         return ret + 1;     }     cnt = 1 + breakInto(curr->num);     for (int i = 0; i < curr->des.size(); i++) cnt += count(curr->des[i]);     return cnt;   }   void print(node *curr) {     cout << curr->num <<  : ;     for (int i = 0; i < curr->des.size(); i++) print(curr->des[i]);   }   void recurse(int i) {     if (i == 0) {       root = new node();       root->num = arr[0];       imp.push_back(root);       recurse(i + 1);       root->num = 0;       node *nnode = new node();       nnode->num = arr[0];       root->des.push_back(nnode);       imp.push_back(nnode);       recurse(i + 1);       return;     }     if (i == n) {       best = min(best, count(root));       return;     }     for (int j = 0; j < imp.size(); j++) {       long long nnum = imp[j]->num;       if (nnum % arr[i] == 0) {         node *nnode = new node();         nnode->num = arr[i];         imp[j]->des.push_back(nnode);         imp.push_back(nnode);         imp[j]->num /= arr[i];         recurse(i + 1);         imp[j]->num *= arr[i];         imp[j]->des.pop_back();         imp.pop_back();       }     }   }   void precompute(void) {     for (int i = 0; i <= 1000000; i++) prime[i] = 1;     prime[0] = prime[1] = 0;     for (int i = 2; i * i <= 1000000; i++) {       for (int j = i * i; j <= 1000000; j += i) prime[j] = 0;     }   }   int main() {     best = 1000;     root = NULL;     precompute();     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %I64d , &arr[i]);     sort(arr, arr + n, comp1());     for (int i = 0; i < n; i++) {       long long num = arr[i];       for (long long j = 2; j * j <= num; j++) {         if (prime[j]) {           while (num % j == 0) {             primes.insert(j);             num /= j;           }         }         if (num == 1) break;       }       if (num > 1) primes.insert(num);     }     recurse(0);     printf( %d n , best);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 505, mod = 1e9 + 7;   long long c[N][N], s[N][N], p[N], inv[N];   long long l, r;   long long k, ans;   long long add(long long a, long long b) {     return a + b >= mod ? a + b - mod : a + b;   }   long long dec(long long a, long long b) {     return a - b < 0 ? a - b + mod : a - b;   }   long long ksm(long long a, long long b) {     long long ans = 1;     while (b) {       if (b & 1) ans = 1ll * ans * a % mod;       a = 1ll * a * a % mod;       b >>= 1;     }     return ans;   }   struct node {     long long a, b;     node() {}     node(long long aa, long long bb) { a = aa, b = bb; }     inline node operator+(const node& x) const {       return node(add(a, x.a), add(b, x.b));     }     inline node operator+(const long long& x) const { return node(add(a, x), b); }     inline node operator-(const node& x) const {       return node(dec(a, x.a), dec(b, x.b));     }     inline node operator-(const long long& x) const { return node(dec(a, x), b); }     inline node operator*(const node& x) const {       node ans;       ans.a = (a * x.a + b * x.b * 5) % mod;       ans.b = (a * x.b + b * x.a) % mod;       return ans;     }     inline node operator*(const long long& x) const {       return node(a * x % mod, b * x % mod);     }     friend inline node operator/(const node& x, const node& y) {       node ans, z = y;       if (z.b != 0) z.b = mod - z.b;       ans = x * z;       return ans * ksm(dec(y.a * y.a % mod, y.b * y.b * 5 % mod), mod - 2);     }   };   node ksm(node a, long long b) {     node ans = node(1, 0);     while (b) {       if (b & 1) ans = ans * a;       a = a * a;       b >>= 1;     }     return ans;   }   node sum(node a, long long b) { return (ksm(a, b + 1) - a) / (a - 1); }   node query(node x, long long l, long long r) {     if (x.a == 1 && x.b == 0) return x * (r - l + 1);     return sum(x, r) - sum(x, l - 1);   }   signed main() {     scanf( %d%lld%lld , &k, &l, &r);     l += 2, r += 2;     p[0] = p[1] = inv[1] = 1;     for (long long i = 2; i <= max(k, 5ll); i++) {       p[i] = p[i - 1] * i % mod;       inv[i] = (mod - mod / i) * inv[mod % i] % mod;     }     c[0][0] = c[1][0] = c[1][1] = s[0][0] = s[1][1] = 1;     for (long long i = 2; i <= k; i++) {       c[i][0] = 1, s[i][0] = 0;       for (long long j = 1; j <= i; j++)         c[i][j] = add(c[i - 1][j], c[i - 1][j - 1]),         s[i][j] = dec(s[i - 1][j - 1], (i - 1) * s[i - 1][j] % mod);     }     node a = node(0, inv[5]), b = node(0, mod - inv[5]);     node x = node(inv[2], inv[2]), y = node(inv[2], mod - inv[2]);     for (long long i = 0; i <= k; i++) {       node sum = node(0, 0);       for (long long j = 0; j <= i; j++) {         node ss = ksm(a, j) * ksm(b, i - j) *                   query(ksm(x, j) * ksm(y, i - j), l, r) * c[i][j];         sum = sum + ss;       }       sum = sum * s[k][i];       ans = add(ans, sum.a);     }     ans = ans * ksm(p[k], mod - 2) % mod;     printf( %lld , ans);   }