#include <bits/stdc++.h>   using namespace std;   int n, k, tot, arr[105], sum[100050][105], a[100050], s[105];   bool Solved(int x, int y) {     for (int i = 1; i <= tot; ++i)       if (sum[y][i] - sum[x - 1][i] < s[i]) return false;     return true;   }   int main() {     long long ans;     scanf( %d%d , &n, &k);     for (int i = 1; i <= n; ++i) scanf( %d , &a[i]);     int t = k;     for (int i = 2; i * i <= t; ++i)       if (t % i == 0) {         arr[++tot] = i;         for (; t % i == 0; t /= i) s[tot]++;       }     if (t > 1) arr[++tot] = t, s[tot] = 1;     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= tot; ++j)         for (; a[i] % arr[j] == 0; a[i] /= arr[j]) sum[i][j]++;     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= tot; ++j) sum[i][j] += sum[i - 1][j];     ans = 0;     for (int i = 1, L, R, mid; i <= n; ++i) {       L = i - 1;       R = n + 1;       while (L + 1 < R) {         mid = (L + R) / 2;         if (Solved(i, mid))           R = mid;         else           L = mid;       }       ans += n - R + 1;     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   int main() {     int n, m, x, y, it;     int64_t r, min, max, ser, k;     std::cin >> n >> m >> k >> x >> y;     std::vector<std::vector<int64_t>> serg(n);     if (n == 1) {       min = k / m;       max = min + (k % m != 0);       ser = min + (k % m - y >= 0);     } else {       r = k % (2 * m * (n - 1));       min = k / (2 * m * (n - 1));       for (int i = 0; i < n; i++) {         serg[i].resize(m);       }       for (int i = 0; i < m; i++) {         serg[0][i] = min;         serg[n - 1][i] = min;       }       for (int i = 1; i < n - 1; i++) {         for (int j = 0; j < m; j++) {           serg[i][j] = 2 * min;         }       }       for (int i = 0; r != 0; i++) {         if (i >= n) {           it = 2 * n - i - 2;         } else {           it = i;         }         for (int j = 0; r != 0 && j < m; j++) {           serg[it][j]++;           r--;         }       }       ser = serg[x - 1][y - 1];       min += 4;       max = 0;       for (int i = 0; i < n; i++) {         for (int j = 0; j < m; j++) {           max = std::max(max, serg[i][j]);           min = std::min(min, serg[i][j]);         }       }     }     std::cout << max <<     << min <<     << ser;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000007;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     string s;     cin >> s;     int n = s.size();     vector<int> seq(n + 1, 0);     vector<int> ind;     for (int i = 1; i <= n; i++) {       if (s[i - 1] ==  )  || s[i - 1] ==  # ) {         seq[i] = seq[i - 1] - 1;         if (s[i - 1] ==  # ) {           ind.push_back(i - 1);         }       } else {         seq[i] = seq[i - 1] + 1;       }       if (seq[i] < 0) {         cout << -1 << endl;         return 0;       }     }     if (seq[n] == 0) {       for (int i = 0; i < ind.size(); i++) {         cout << 1 << endl;       }     } else {       seq[ind[ind.size() - 1]] -= seq[n];       int val = seq[n];       for (int i = ind[ind.size() - 1] + 1; i <= n; i++) {         if (s[i - 1] ==  )  || s[i - 1] ==  # ) {           seq[i] = seq[i - 1] - 1;         } else {           seq[i] = seq[i - 1] + 1;         }         if (seq[i] < 0) {           cout << -1 << endl;           return 0;         }       }       for (int i = 0; i < (int)ind.size() - 1; i++) {         cout << 1 << endl;       }       cout << 1 + val << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int size(long long a) {     int c = 0;     while (a != 0) {       c++;       a /= 10;     }     return c;   }   int main() {     long long a, b, c;     cin >> a >> b;     long long s = size(b), ns = 1;     for (int i = 1; i <= s; i++) ns *= 10;     s = ns;     while (b != 0) {       long long f = b % 10;       b /= 10;       s /= 10;       a += s * f;     }     cout << a;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int M = 1e9 + 7;   const int MOD = 1e9 + 7;   const double PI = 3.141592653589793238460;   long long power(long long a, long long b) {     long long res = 1;     if (a == 0) return 0;     if (a == 1) return 1;     for (; b > 0; b >>= 1) {       if (b & 1) res = (res * a);       if (res > MOD) res %= MOD;       a = (a * a);       if (a > MOD) a = a % MOD;     }     return res;   }   bool isPrime[1000000 + 1];   vector<long long> prime;   void seive(int limit) {     isPrime[0] = isPrime[1] = 1;     for (int i = 2; i * i <= limit; i++) {       if (!isPrime[i])         for (int j = i * i; j <= limit; j += i) {           isPrime[j] = 1;         }     }     for (int i = 2; i <= limit; i++)       if (!isPrime[i]) prime.push_back(i);   }   int ls;   int maxi = 0;   int mark[300000];   int visited[300000];   void dfsl(int x, vector<int> adj[], int n, int p = -1, int mx = 0) {     if (mx > maxi) {       maxi = mx;       ls = x;     }     for (int y : adj[x]) {       if (y == p) continue;       dfsl(y, adj, n, x, mx + 1);     }   }   int parent[300000];   pair<int, int> dfs(int x, vector<int> adj[], int d = 0, int p = -1) {     pair<int, int> res = {d, x};     parent[x] = p;     for (int y : adj[x]) {       if (y == p) continue;       res = max(res, dfs(y, adj, d + 1, x));     }     return res;   }   int main() {     ios_base::sync_with_stdio(false), cin.tie(0);     int tt;     tt = 1;     while (tt--) {       int n;       cin >> n;       vector<int> adj[n + 1];       for (int i = 0; i < n - 1; i++) {         int u, v;         cin >> u >> v;         adj[v].push_back(u);         adj[u].push_back(v);       }       pair<int, int> da = dfs(1, adj);       pair<int, int> db = dfs(da.second, adj);       int a = da.second;       vector<int> v;       int x = db.second;       int b = x;       while (x != a) {         v.push_back(x);         x = parent[x];       }       v.push_back(a);       if (v.size() == n) {         cout << n - 1 <<   n ;         cout << a <<     << v[1] <<     << b;         return 0;       }       queue<int> q;       for (int i = 0; i < v.size(); i++) q.push(v[i]);       vector<int> d(n + 1, -1);       for (int i = 0; i < v.size(); i++) d[v[i]] = 0;       while (!q.empty()) {         int x = q.front();         q.pop();         for (int y : adj[x]) {           if (d[y] == -1) {             d[y] = d[x] + 1;             q.push(y);           }         }       }       pair<int, int> ans = {0, 0};       for (int i = 1; i <= n; i++) {         ans = max(ans, {d[i], i});       }       cout << (int)v.size() - 1 + ans.first <<   n ;       cout << a <<     << ans.second <<     << b <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int x, y, a;     cin >> x >> y;     vector<int> v;     vector<int> v2;     for (int i = 0; i < x; i++) {       cin >> a;       v.push_back(a);     }     for (int i = 0; i < y; i++) {       cin >> a;       v2.push_back(a);     }     int key = 0, ct = 0, ii = 0, jj = 0, sum = 0;     for (; ii < x; ii++) {       key += v[ii];       for (; jj <= y;) {         if (sum > key) {           break;         }         if (sum == key) {           ct++;           key = 0;           sum = 0;           break;         }         sum += v2[jj++];         if (sum == key) {           ct++;           key = 0;           sum = 0;           break;         }         if (sum > key) {           break;         }       }     }     cout << ct << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, k, t = 0, a, e = 0;   int main() {     cin >> n >> k;     for (long long i = 1; i <= n; i++) {       cin >> a;       if (i > 1 && t - (n - i) * a * (i - e - 1) < k) {         cout << i <<   n ;         e++;       } else         t += a * (i - 1 - e);     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxx = 1e6 + 100;   vector<pair<int, int> > in[maxx], out[maxx];   struct node {     int l;     int r;     long long sum;     long long num;   } p[maxx << 2];   int n, m, k;   void init() {     for (int i = 0; i <= n; i++) {       in[i].clear();       out[i].clear();     }   }   inline void pushup(int cur) {     p[cur].num = p[cur << 1].num + p[cur << 1 | 1].num;     p[cur].sum = p[cur << 1].sum + p[cur << 1 | 1].sum;   }   inline void build(int l, int r, int cur) {     p[cur].l = l;     p[cur].r = r;     p[cur].num = 0;     p[cur].sum = 0;     if (l == r) return;     int mid = l + r >> 1;     build(l, mid, cur << 1);     build(mid + 1, r, cur << 1 | 1);   }   inline void update(int num, int pos, int cur) {     int L = p[cur].l;     int R = p[cur].r;     if (L == R) {       p[cur].num += num;       p[cur].sum += (long long)num * (long long)L;       return;     }     int mid = L + R >> 1;     if (pos <= mid)       update(num, pos, cur << 1);     else       update(num, pos, cur << 1 | 1);     pushup(cur);   }   inline long long query(int num, int cur) {     int L = p[cur].l;     int R = p[cur].r;     if (L == R) return (long long)L * min(p[cur].num, (long long)num);     if (num <= p[cur << 1].num)       return query(num, cur << 1);     else       return (p[cur << 1].sum + query(num - p[cur << 1].num, cur << 1 | 1));   }   int main() {     int l, r, x, y;     while (~scanf( %d%d%d , &n, &k, &m)) {       init();       for (int i = 1; i <= m; i++) {         scanf( %d%d%d%d , &l, &r, &x, &y);         in[l].push_back(make_pair(x, y));         out[r].push_back(make_pair(x, y));       }       long long ans = 0;       build(1, maxx, 1);       for (int i = 1; i <= n; i++) {         for (int j = 0; j < in[i].size(); j++)           update(in[i][j].first, in[i][j].second, 1);         ans += query(k, 1);         for (int j = 0; j < out[i].size(); j++)           update(-out[i][j].first, out[i][j].second, 1);       }       printf( %lld n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     scanf( %d , &t);     while (t--) {       int n;       scanf( %d , &n);       if (n == 1 || n == 2)         printf( 1 n );       else if (n == 3)         printf( 2 n );       else {         if (n % 2 == 1)           printf( %d n , (n - 1) / 2 + 1);         else           printf( %d n , n / 2);       }     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   #pragma GCC target( sse4 )   using namespace std;   template <typename T>   void etch(T V) {     for (auto x : V) cout << x <<    ;     cout <<   n ;   }   vector<string> vec_splitter(string s) {     s +=  , ;     vector<string> res;     while (!s.empty()) {       res.push_back(s.substr(0, s.find( , )));       s = s.substr(s.find( , ) + 1);     }     return res;   }   void debug_out(vector<string> __attribute__((unused)) args,                  __attribute__((unused)) long long int idx,                  __attribute__((unused)) long long int LINE_NUM) {     cerr << endl;   }   template <typename Head, typename... Tail>   void debug_out(vector<string> args, long long int idx, long long int LINE_NUM,                  Head H, Tail... T) {     if (idx > 0)       cerr <<  ,  ;     else       cerr <<  Line(  << LINE_NUM <<  )  ;     stringstream ss;     ss << H;     cerr << args[idx] <<   =   << ss.str();     debug_out(args, idx + 1, LINE_NUM, T...);   }   const long long int MOD = 1e9 + 7;   const long long int MOD1 = 998244353;   const long long int N = 2e5 + 5;   const long long int INF = 1000111000111000111LL;   const long double EPS = 1e-12;   const long double PI = 3.141592653589793116;   long long int d[3005][3005], p[3005][3005];   void solve() {     long long int n;     cin >> n;     long long int a[n + 5];     for (long long int i = 1; i <= n; i++) cin >> a[i];     for (long long int i = 0; i <= n + 2; i++) {       for (long long int j = 0; j <= n + 2; j++) {         d[i][j] = p[i][j] = 0;       }     }     for (long long int i = 1; i <= n; i++) {       d[i][a[i]]++;       for (long long int j = 0; j <= n; j++) {         d[i][j] += d[i - 1][j];       }     }     for (long long int i = n; i >= 1; i--) {       p[i][a[i]]++;       for (long long int j = 0; j <= n; j++) {         p[i][j] += p[i + 1][j];       }     }     long long int ans = 0;     for (long long int i = 1; i <= n; i++) {       for (long long int j = i + 1; j <= n; j++) {         ans += (d[i - 1][a[j]] * p[j + 1][a[i]]);       }     }     cout << ans <<   n ;   }   int32_t main() {     std::ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     long long int T;     cin >> T;     while (T--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MaxN = 4010;   const int MOD = 1000000009;   int n, w, b;   long long p[MaxN], r[MaxN];   long long power(long long x, long long y) {     if (!y) return 1;     long long t = power(x, y / 2);     t = t * t % MOD;     if (y & 1) t = t * x % MOD;     return t;   }   long long C(long long n, long long m) {     return p[n] * r[m] % MOD * r[n - m] % MOD;   }   int main() {     cin >> n >> w >> b;     for (int i = p[0] = r[0] = 1; i < MaxN; ++i) {       p[i] = p[i - 1] * i % MOD;       r[i] = power(p[i], MOD - 2);     }     long long ans = 0;     for (int i = max(1, n - w); i <= min(n - 2, b); ++i)       ans += p[w] * p[b] % MOD * (n - i - 1) % MOD * C(b - 1, i - 1) % MOD *              C(w - 1, n - i - 1) % MOD;     cout << ans % MOD << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     vector<long long int> v(1000005);     long long int i, n, j;     for (i = 2; i < 1000005; i++) {       j = i * 2;       while (j <= 1000005) {         v[j] = 1;         j += i;       }     }     cin >> n;     j = 1;     for (j = 1; j < 1001; j++) {       if (v[n * j + 1] != 0) {         cout << j;         break;       }     }   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const int maxn = 1e5 + 5;   int n, a[maxn];   int b[maxn];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cin >> n;     int sum = 0;     map<int, int> mp;     for (int i = 0; i < n; i++) {       cin >> a[i];       mp[a[i]]++;     }     bool poss = false;     for (int i = 0; i < n; i++) {       if (a[i] > 0) {         if (--mp[a[i]] == 0) mp.erase(a[i]);         ++mp[a[i] - 1];         if (mp.size() == n) {           poss = true;         }         if (--mp[a[i] - 1] == 0) mp.erase(a[i] - 1);         ++mp[a[i]];       }     }     if (!poss) {       cout <<  cslnb  <<   n ;       return 0;     }     sort(a, a + n);     b[0] = 0;     for (int i = 1; i < n; i++) {       b[i] = min(a[i], b[i - 1] + 1);     }     for (int i = 0; i < n; i++) {       sum += (a[i] - b[i] + 2) % 2;       sum %= 2;     }     cout << (sum == 1 ?  sjfnb  :  cslnb ) <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> pf(const string& s) {     int n = s.size();     vector<int> pi(n);     for (int i = 1; i < n; i++) {       int j = pi[i - 1];       while (j > 0 && s[i] != s[j]) j = pi[j - 1];       if (s[i] == s[j]) j++;       pi[i] = j;     }     return pi;   }   int main() {     ios_base::sync_with_stdio(false);     string s;     string t;     cin >> s >> t;     auto a = pf(t);     int val = t.length() - a.back();     int cyc = val;     int c1 = 0, c0 = 0;     for (int i = 0; i < s.length(); i++) {       if (s[i] ==  1 )         c1++;       else         c0++;     }     int p = 0;     while (true) {       if (t[p] ==  0 ) {         if (c0) {           cout << 0;           c0--;         } else           break;       } else {         if (c1) {           cout << 1;           c1--;         } else           break;       }       p++;       p %= cyc;     }     while (c1) {       cout << 1;       c1--;     }     while (c0) {       cout << 0;       c0--;     }     return 0;   }


#include <bits/stdc++.h>   int main() {     int n;     while (scanf( %d , &n) != EOF) {       int sum = 0, i, num, he = 0, div = n + 1;       for (i = 1; i <= n; i++) {         scanf( %d , &num);         sum += num;       }       for (i = 1; i <= 5; i++) {         if ((sum + i) % div == 1) he++;       }       printf( %d n , 5 - he);     }   }


#include <bits/stdc++.h>   using namespace std;   template <class A, class B>   inline bool mina(A &first, B second) {     return (first > second) ? (first = second, 1) : 0;   }   template <class A, class B>   inline bool maxa(A &first, B second) {     return (first < second) ? (first = second, 1) : 0;   }   map<char, int> cnt;   char c[] = { B ,  G ,  R };   int main() {     int N;     cin >> N;     string s;     cin >> s;     for (int(i) = 0; (i) < (N); ++(i)) {       cnt[s[i]]++;     }     if (cnt.size() == 3) {       cout <<  BGR  << endl;       return 0;     } else if (cnt.size() == 1) {       cout << cnt.begin()->first << endl;     } else {       for (int(i) = 0; (i) < (3); ++(i)) {         int cc = cnt[c[i]];         if (cc == 0) {           printf( %c , c[i]);         } else {           bool good = false;           for (int(j) = 0; (j) < (3); ++(j)) {             if (j != i && cnt[c[j]] >= 2) {               good = true;             }           }           if (good) printf( %c , c[i]);         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long double PI = acos(-1);   long long powm(long long a, long long b) {     long long res = 1;     while (b) {       if (b & 1) res = (res * a) % 1000000007;       a = (a * a) % 1000000007;       b >>= 1;     }     return res;   }   long long gcd(long long a, long long b) {     if (b == 0) return a;     return gcd(b, a % b);   }   const long long maxn = 2 * 1e5 + 10;   map<long long, long long> dif;   void solve() {     long long n;     cin >> n;     long long a[n + 2];     for (long long i = 1; i <= n; i++) {       cin >> a[i];     }     sort(a + 1, a + n + 1);     for (long long i = 2; i <= n; i++) {       long long cur = a[i] - a[i - 1];       dif[cur]++;     }     if (dif.size() > 2) {       cout << 0 << endl;     } else if (n == 1) {       cout << -1 << endl;     } else if (n == 2) {       if ((a[2] - a[1]) % 2 == 0 && a[2] != a[1]) {         cout << 3 << endl;         cout << a[1] - (a[2] - a[1]) <<     << a[1] + (a[2] - a[1]) / 2 <<                  << a[2] + (a[2] - a[1]) << endl;       } else if (a[1] == a[2]) {         cout << 1 << endl;         cout << a[1] << endl;       } else {         cout << 2 << endl;         cout << a[1] - (a[2] - a[1]) <<     << a[2] + (a[2] - a[1]) << endl;       }     } else if (dif.size() == 2 && n > 1) {       long long mx = 0, d = 1000000000, z = 0;       vector<long long> s;       for (auto i : dif) {         if (i.first == 0) z = 1;         if (mx <= i.second) {           mx = i.second;           d = min(d, i.first);         }         s.push_back(i.first);       }       if (z || dif[s[0]] < n - 2 || s[1] % 2 != 0 ||           (s[1] % 2 == 0 && s[1] / 2 != s[0]))         cout << 0 << endl;       else {         for (long long i = 2; i <= n; i++) {           if (a[i] - a[i - 1] != d) {             if ((a[i] - a[i - 1]) > d && (a[i] - a[i - 1]) % 2 == 0 &&                 (a[i] - a[i - 1]) / 2 == d) {               cout << 1 << endl;               cout << a[i - 1] + d << endl;             } else {               cout << 0 << endl;               break;             }           }         }       }     } else if (dif.size() == 1) {       long long d = 0;       for (auto i : dif) {         d = i.first;       }       if (d) {         cout << 2 << endl;         cout << a[1] - (a[2] - a[1]) <<     << a[n] + (a[2] - a[1]) << endl;       } else {         cout << 1 << endl;         cout << a[1] << endl;       }     } else       cout << 0 << endl;   }   signed main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long t = 1;     for (long long i = 1; i <= t; i++) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, ans = 0;     cin >> n;     long long a[n + 1];     vector<long long> last;     last.push_back(-1);     for (int i = 0; i < n; i++) {       cin >> a[i];       if (i > 0 && a[i] <= a[i - 1]) last.push_back(i - 1);     }     last.push_back(n - 1);     for (int i = 1; i < (int)last.size(); i++) {       if (last[i - 1] == -1)         ans = max(last[i] + 1, ans);       else         ans = max(ans, last[i] - last[i - 1]);       if (i < (int)last.size() - 1 &&           (a[last[i] + 1] > a[last[i] - 1] || a[last[i] + 2] > a[last[i]])) {         if (i > 1)           ans = max(last[i + 1] - last[i - 1] - 1, ans);         else           ans = max(ans, last[i + 1]);       }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000007;   long long powmod(long long a, long long b) {     long long res = 1;     a %= mod;     for (; b; b >>= 1) {       if (b & 1) res = res * a % mod;       a = a * a % mod;     }     return res;   }   int n, m, q;   int visited[205][205];   int table[205][205];   int g1, g2;   vector<pair<int, int> > ab;   set<int> cans;   string s;   pair<int, int> nxt[205][205];   vector<pair<int, int> > prv[205][205];   int cycleNum[205][205];   vector<pair<int, int> > cycle[40005];   bool has[40005][10];   int idxCycle;   bool addTrigger;   void addCycle(int i, int j) {     if (visited[i][j] == 2) return;     if (visited[i][j] == 1) {       addTrigger = true;       cycle[idxCycle].push_back(make_pair(i, j));       has[idxCycle][table[i][j]] = 1;       cycleNum[i][j] = idxCycle;       visited[i][j] = 2;       return;     }     visited[i][j] = 1;     addCycle(nxt[i][j].first, nxt[i][j].second);     if (visited[i][j] == 1 && addTrigger) {       cycle[idxCycle].push_back(make_pair(i, j));       has[idxCycle][table[i][j]] = 1;       cycleNum[i][j] = idxCycle;     } else       addTrigger = false;     visited[i][j] = 2;   }   bool query(string& s, int pos, int x, int y) {     if (pos >= 0 && table[x][y] == s[pos] -  0 ) pos--;     if (pos == -1) return true;     for (int i = 0; i < (int)prv[x][y].size(); i++) {       if (query(s, pos, prv[x][y][i].first, prv[x][y][i].second)) return true;     }     return false;   }   void query(string& s, vector<int> idxs) {     int n = s.length();     memset(visited, 0, sizeof(visited));     for (int i = 0; i < (int)idxCycle; i++) {       int pos = -1;       for (int j = 0; j < (int)10; j++) {         if (!has[i][j] && idxs[j] != n) {           pos = max(pos, idxs[j]);         }       }       if (pos == -1) {         cout <<  YES  << endl;         return;       }       for (int j = 0; j < (int)cycle[i].size(); j++) {         if (query(s, pos, cycle[i][j].first, cycle[i][j].second)) {           cout <<  YES  << endl;           return;         }       }     }     cout <<  NO  << endl;   }   int main() {     memset(has, 0, sizeof(has));     memset(cycleNum, -1, sizeof(cycleNum));     memset(visited, 0, sizeof(visited));     ab.resize(10);     cin >> n >> m >> q;     for (int i = 0; i < (int)n; i++) {       cin >> s;       for (int j = 0; j < (int)m; j++) {         table[i][j] = s[j] -  0 ;       }     }     for (int i = 0; i < (int)10; i++) cin >> ab[i].first >> ab[i].second;     for (int i = 0; i < (int)n; i++) {       for (int j = 0; j < (int)m; j++) {         int ni = i + ab[table[i][j]].first, nj = j + ab[table[i][j]].second;         if (ni >= 0 && ni < n && nj >= 0 && nj < m) {           nxt[i][j] = make_pair(ni, nj);         } else {           nxt[i][j] = make_pair(i, j);         }       }     }     idxCycle = 0;     for (int i = 0; i < (int)n; i++) {       for (int j = 0; j < (int)m; j++) {         if (!visited[i][j]) {           addCycle(i, j);           if (cycle[idxCycle].size()) idxCycle++;         }       }     }     for (int i = 0; i < (int)n; i++) {       for (int j = 0; j < (int)m; j++) {         if (cycleNum[i][j] == -1) {           prv[nxt[i][j].first][nxt[i][j].second].push_back(make_pair(i, j));         }       }     }     for (int i = 0; i < (int)q; i++) {       cin >> s;       string t =   ;       vector<int> idxs(10, s.length());       for (int j = s.length() - 1; j >= 0; j--) idxs[(s[j] -  0 )] = j, t += s[j];       query(s, idxs);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 3e5 + 3e4;   long long lp[N], rp[N], l, r, first, second, m, so, k, n;   char ch;   int main() {     cin >> n;     for (long long i = (long long)1; i <= (long long)n; i++) {       cin >> ch >> k;       if (ch ==  ? ) {         first = l - lp[k];         second = r - rp[k];         m = l + r;         so = 1e15;         if (rp[k]) {           so = min(so, r - rp[k]);           so = min(so, m - second - 1);         }         if (lp[k]) {           so = min(so, l - lp[k]);           so = min(so, m - first - 1);         }         cout << so <<   n ;       } else {         if (ch ==  L ) lp[k] = ++l;         if (ch ==  R ) rp[k] = ++r;       }     }   }


#include <bits/stdc++.h>   using namespace std;   long long n, s;   void dfs(long long x, long long s4, long long s7) {     if (n <= x && (x < s || s == 0) && s4 == s7) s = x;     if (x <= n * 100) {       dfs(x * 10 + 4, s4 + 1, s7);       dfs(x * 10 + 7, s4, s7 + 1);     }   }   int main() {     cin >> n;     dfs(0, 0, 0);     if (n <= 47) s = 47;     cout << s;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long t;     cin >> t;     long long n, d;     while (t--) {       cin >> n >> d;       long long arr[n];       for (long long i = 0; i < n; i++) cin >> arr[i];       int count = 0;       int i = 1;       while (i < n && d > 0 && d >= i) {         if ((arr[i] * i) <= d) {           count += arr[i];           d = d - (arr[i] * i);         } else {           int t = d / i;           count += t;           d = d % i;         }         i++;       }       cout << arr[0] + count << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n,q,a[100005],np[100005],cnt[100005],nx[19][100005],p1,p2;   vector<int> p,fac[100005];   bool check(int ind) {       for (int i=0; i<fac[ind].size(); i++) {           if (cnt[fac[ind][i]]) return 0;       }       for (int i=0; i<fac[ind].size(); i++) cnt[fac[ind][i]]++;       return 1;   }   void rem(int ind) {       for (int i=0; i<fac[ind].size(); i++) {           cnt[fac[ind][i]]--;       }   }   void fun() {       int l=0,r=0;       while (l<n) {           while (r<n and check(r)) r++;           nx[0][l]=r;           rem(l); l++;       }       nx[0][n]=n;       for (int i=1; i<19; i++) {           for (int j=0; j<=n; j++) {               nx[i][j]=nx[i-1][nx[i-1][j]];           }       }   }   int getans(int l,int r) {       int ind=18,ret=0,cur=l;       while (ind>=0) {           if (nx[ind][cur]<=r) {               ret+=(1<<ind); cur=nx[ind][cur];           }           ind--;       }       return ret+1;   }   int main() {       for (int i=2; i<=1e5; i++) {           if (np[i]) continue;           p.push_back(i);           for (int j=2*i; j<=1e5; j+=i) {               np[j]=1;           }       }       cin>>n>>q;       for (int i=0; i<n; i++) cin>>a[i];       for (int i=0; i<n; i++) {           int ind=0,x=a[i];           while (p[ind]<318) {               bool s=0;               while (x%p[ind]==0) {                   x/=p[ind]; s=1;               }               if (s) fac[i].push_back(p[ind]);               ind++;           }           if (x!=1) {               fac[i].push_back(x);           }       }       fun();       for (int i=0; i<q; i++) {           cin>>p1>>p2; p1--; p2--;           cout<<getans(p1,p2)<<  n ;       }   }


#include <bits/stdc++.h>   using namespace std;   const int MAX_N = int(1e5 + 3);   template <typename T>   void printV(vector<T> v, char sep) {     for (long long unsigned int i = 0; i < v.size() - 1; i++) {       cout << v[i] << sep;     }     cout << v[v.size() - 1];   }   void printVPCI(vector<pair<char, int>> s) {     for (long long unsigned int i = 0; i < s.size(); i++) {       cout << s[i].first <<     << s[i].second <<   n ;     }   }   void cdPr(bool a) { cout << (a ?  YES  :  NO ); }   bool isPrime(int n) {     for (int i = 2; i <= n / 2; ++i) {       if (n % i == 0) {         return false;       }     }     return true;   }   template <typename T>   bool vFind(vector<T> v, T x) {     return find(v.begin(), v.end(), x) != v.end();   }   vector<pair<char, int>> strInfo(string s) {     vector<char> f;     vector<pair<char, int>> r;     for (long long unsigned int i = 0; i < s.size(); i++) {       if (!vFind(f, s[i])) {         f.push_back(s[i]);         r.push_back(make_pair(s[i], count(s.begin(), s.end(), s[i])));       }     }     return r;   }   vector<char> distinctChars(string s) {     vector<char> f;     for (long long unsigned int i = 0; i < s.size(); i++) {       if (!vFind(f, s[i])) f.push_back(s[i]);     }     return f;   }   void solve() {     int n;     cin >> n;     int pos[MAX_N] = {0};     int t = n;     int a;     cin >> a;     int i = 1;     n--;     int min = 99999999;     int r = 0;     pos[0] = a;     int x;     while (n > 0) {       cin >> x;       pos[i] = x;       if (abs(a - x) < min) {         min = abs(a - x);         r = i;       }       a = x;       i++;       n--;     }     if (abs(x - pos[0]) < min) {       r = t;     }     cout << (r) <<     << ((r + 1 > t) ? (r + 1 - t) : (r + 1)) <<   n ;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     solve();     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:64000000 )   using namespace std;   const int infi = 1e9 + 7;   const long long infl = 1e18 + 7;   int ar[101];   bitset<101> dp0[10500];   bitset<101> dp[10500];   bitset<101> ndp[10500];   int main() {     cin.sync_with_stdio(false);     cin.tie(0);     int n;     cin >> n;     for (int i = 0; i < (n); ++i) cin >> ar[i];     vector<pair<int, int> > tmp;     sort(ar, ar + n);     int lst = ar[0];     int sum = ar[0];     int cnt = 1;     for (int i = 1; i < n; ++i) {       sum += ar[i];       if (lst == ar[i])         ++cnt;       else {         tmp.emplace_back(lst, cnt);         lst = ar[i];         cnt = 1;       }     }     tmp.emplace_back(lst, cnt);     if (tmp.size() <= 2) {       cout << n;       return 0;     }     for (auto cur : tmp) {       for (int cnt = 1; cnt <= cur.second; ++cnt) {         int second = cnt * cur.first;         for (int w = 0; w < (10500); ++w) {           ndp[w + second] |= dp0[w] << cnt;           ndp[w + second] |= dp[w] << cnt;         }       }       for (int cnt = 1; cnt <= cur.second; ++cnt) {         dp0[cnt * cur.first][cnt] = 1;       }       for (int i = 0; i < (10500); ++i) dp[i] |= ndp[i];     }     int ans = 0;     for (auto cur : tmp) {       for (int cnt = 1; cnt <= cur.second; ++cnt) {         int second = cnt * cur.first;         if (dp[second][cnt]) continue;         ans = max(ans, cnt);         if (tmp.size() == 2 && cnt == cur.second) ans = n;       }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize(3,  Ofast ,  inline )   #pragma GCC target( avx,avx2 )   using namespace std;   template <class t>   inline t read(t &x) {     char c = getchar();     bool f = 0;     x = 0;     while (!isdigit(c)) f |= c ==  - , c = getchar();     while (isdigit(c)) x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();     if (f) x = -x;     return x;   }   template <class t>   inline void write(t x) {     if (x < 0)       putchar( - ), write(-x);     else {       if (x > 9) write(x / 10);       putchar( 0  + x % 10);     }   }   const long long N = 1005, mod = 1e9 + 7;   long long f[N][N][2][2], g[N], ans[N], n, m, fac[N], inv[N];   long long C(long long n, long long m) {     return fac[n] * inv[m] % mod * inv[n - m] % mod;   }   signed main() {     read(n);     read(m);     fac[0] = inv[0] = inv[1] = 1;     for (long long i = 1; i <= n; i++) fac[i] = fac[i - 1] * i % mod;     for (long long i = 2; i <= n; i++)       inv[i] = inv[mod % i] * (mod - mod / i) % mod;     for (long long i = 1; i <= n; i++) inv[i] = inv[i] * inv[i - 1] % mod;     f[1][0][0][0] = f[1][1][0][1] = 1;     for (long long i = 2; i <= n; i++)       for (long long j = 0; j < i; j++) {         f[i][j][0][0] =             (f[i][j][0][0] + f[i - 1][j][0][0] + f[i - 1][j][1][0]) % mod;         f[i][j][1][0] =             (f[i][j][1][0] + f[i - 1][j][0][1] + f[i - 1][j][1][1]) % mod;         f[i][j + 1][0][0] = f[i - 1][j][0][0];         f[i][j + 1][0][1] = (f[i - 1][j][0][0] + f[i - 1][j][1][0]) % mod;         f[i][j + 1][1][0] = f[i - 1][j][0][1];         f[i][j + 1][1][1] = (f[i - 1][j][0][1] + f[i - 1][j][1][1]) % mod;       }     for (long long i = 0; i <= n; i++)       g[i] = (f[n][i][0][0] + f[n][i][1][0]) * fac[n - i] % mod;     for (long long i = 0; i <= n; i++)       for (long long j = i, op = 1; j <= n; j++, op *= -1)         ans[i] = (ans[i] + mod + op * C(j, i) * g[j] % mod) % mod;     write(ans[m]);   }


#include <bits/stdc++.h>   using namespace std;   long long int mod = 1e9 + 9;   const double error = 1e-7;   const double PI = acos(-1);   mt19937 rng(       (unsigned int)chrono::system_clock::now().time_since_epoch().count());   inline long long int MOD(long long int x, long long int m = mod) {     long long int y = x % m;     return (y >= 0) ? y : y + m;   }   const int inf = 1e9 + 2;   const long long int infl = 1e18 + 1;   const int nmax = 1e6 + 10;   int master[nmax];   void init(int n) {     for (int i = 1; i <= n; i++) master[i] = i;   }   int fnd(int u) {     if (master[u] == u) return u;     return master[u] = fnd(master[u]);   }   int unite(int a, int b) {     a = fnd(a), b = fnd(b);     if (rng() & 1) swap(a, b);     master[b] = a;     return a;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     ;     int n, m;     cin >> n >> m;     init(n);     long long int two = 1;     for (int i = 0; i < m; i++) {       int a, b;       cin >> a >> b;       if (fnd(a) == fnd(b)) {         two *= 2;         two %= mod;       } else         unite(a, b);       cout << MOD(two - 1) <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 3e5 + 10;   int n, m, cnt, k;   struct node {     int l, r, sum = 1999999999;   } g[maxn * 20];   inline int read() {     register int x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch <=  9  && ch >=  0 ) x = x * 10 + ch -  0 , ch = getchar();     return x * f;   }   struct value {     int x, y, id;   } x[maxn];   bool cmp(value v1, value v2) { return v1.x > v2.x; }   int root[maxn];   void update(int num, int wht, int &rt, int l, int r) {     g[++cnt] = g[rt];     if (l == r) {       g[cnt].sum = min(g[rt].sum, wht);       rt = cnt;       return;     }     rt = cnt;     int mid = l + r >> 1;     if (num <= mid)       update(num, wht, g[rt].l, l, mid);     else       update(num, wht, g[rt].r, mid + 1, r);     g[rt].sum = max(g[g[rt].l].sum, g[g[rt].r].sum);   }   int query(int rt, int l, int r, int lb, int rb) {     if (lb >= l && rb <= r) return g[rt].sum;     if (lb > r || l > rb) return -1999999999;     int mid = lb + rb >> 1;     return max(query(g[rt].l, l, r, lb, mid), query(g[rt].r, l, r, mid + 1, rb));   }   int main() {     cnt = 1;     scanf( %d%d%d , &n, &m, &k);     for (int i = 1; i <= k; i++) {       x[i].x = read(), x[i].y = read(), x[i].id = read();     }     sort(x + 1, x + 1 + k, cmp);     for (int i = 1; i <= k; i++) {       root[i] = root[i - 1];       update(x[i].id, x[i].y, root[i], 1, n);     }     while (m--) {       int A = read(), B = read(), X = read(), Y = read();       int lb = 1, asn = -1, rb = k;       while (lb <= rb) {         int mid = lb + rb >> 1;         if (x[mid].x >= X) {           lb = mid + 1;           asn = mid;         } else {           rb = mid - 1;         }       }       int ans = query(root[asn], A, B, 1, n);       if (ans <= Y)         printf( yes n );       else         printf( no n );       fflush(stdout);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k = 0;     cin >> n;     vector<int> adj[n];     for (int i = 1, u, v; i < n; i++) {       cin >> u >> v;       u--;       v--;       adj[u].push_back(v);       adj[v].push_back(u);       k = max(k, max((int)adj[u].size(), (int)adj[v].size()) + 1);     }     cout << k << endl;     int nd_clr[n], prnt[n];     queue<int> Q;     Q.push(0);     nd_clr[0] = 0;     prnt[0] = 0;     while (!Q.empty()) {       int u = Q.front();       Q.pop();       int clr = nd_clr[u];       for (int i = 0; i < adj[u].size(); i++) {         int v = adj[u][i];         if (v != prnt[u]) {           int c = (clr + 1) % k;           if (c == nd_clr[prnt[u]]) c = (c + 1) % k;           nd_clr[v] = c;           clr = c;           prnt[v] = u;           Q.push(v);         }       }     }     for (int i = 0; i < n; i++) cout << nd_clr[i] + 1 <<    ;     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     for (int i = 1; i <= t; i++) {       long long n;       cin >> n;       long long s = sqrt(n);       long long c = cbrt(n);       long long p = sqrt(cbrt(n));       cout << s + c - p <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   inline int read() {     int res = 0, f = 1;     char ch;     while (ch = getchar(), ch <  0  || ch >  9 )       if (ch ==  - ) f = -1;     while (ch >=  0  && ch <=  9 ) res = res * 10 + ch -  0 , ch = getchar();     return res * f;   }   const int N = 14, M = 4782969, P = 1e9 + 7;   inline int qpow(int a, int b) {     int ans = 1, base = a;     while (b) {       if (b & 1) ans = 1ll * ans * base % P;       base = 1ll * base * base % P;       b >>= 1;     }     return ans;   }   int rev[1 << N], cnt[1 << N], n, A, a[N];   int F[1 << N], G[1 << N], v[N][1 << N];   inline int get(int S, int T) {     if (!S) return 1;     if (G[S]) return G[S];     return G[S] = 1ll * get(S & (S - 1), T) * v[rev[S & -S]][T] % P;   }   int main() {     n = read(), A = (1 << n) - 1;     for (int i = 0; i < n; ++i) a[i] = read(), rev[1 << i] = i;     for (int i = 0; i < n; ++i) {       v[i][0] = 1;       for (int S = 1; S < (1 << n); ++S)         v[i][S] = 1ll * v[i][S & (S - 1)] * a[i] % P *                   qpow((a[rev[S & -S]] + a[i]) % P, P - 2) % P;     }     for (int S = 1; S < (1 << n); ++S) {       int tmp = 0;       cnt[S] = cnt[S >> 1] + (S & 1);       for (int T = (S - 1) & S; T; T = (T - 1) & S)         (tmp += 1ll * F[T] * get(S ^ T, A ^ S) % P) %= P;       F[S] = (get(S, A ^ S) - tmp + P) % P;       for (int T = S; T; T = (T - 1) & S) G[T] = 0;     }     int res = 0;     for (int S = 1; S < (1 << n); ++S) (res += 1ll * F[S] * cnt[S] % P) %= P;     printf( %d , res);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int read() {     int x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) f = ch ==  -  ? -1 : 1, ch = getchar();     while (ch >=  0  && ch <=  9 ) x = x * 10 + ch - 48, ch = getchar();     return x * f;   }   const int maxn = 205;   int tot;   int R, G, B;   int r[maxn];   int g[maxn];   int b[maxn];   int f[maxn][maxn][maxn];   struct Stick {     int v, c;   } a[maxn << 3];   inline bool cmp(int u, int v) { return u > v; }   int main() {     R = read(), G = read(), B = read();     for (int i = (1); i <= (R); i++) r[i] = read();     for (int i = (1); i <= (G); i++) g[i] = read();     for (int i = (1); i <= (B); i++) b[i] = read();     sort(r + 1, r + R + 1, cmp), sort(g + 1, g + G + 1, cmp),         sort(b + 1, b + B + 1, cmp);     f[1][1][0] = r[1] * g[1];     f[1][0][1] = r[1] * b[1];     f[0][1][1] = g[1] * b[1];     int ans = 0;     for (int i = (0); i <= (R); i++)       for (int j = (0); j <= (G); j++)         for (int k = (0); k <= (B); k++) {           if (i && j)             f[i][j][k] = max(f[i][j][k], f[i - 1][j - 1][k] + r[i] * g[j]);           if (i && k)             f[i][j][k] = max(f[i][j][k], f[i - 1][j][k - 1] + r[i] * b[k]);           if (j && k)             f[i][j][k] = max(f[i][j][k], f[i][j - 1][k - 1] + g[j] * b[k]);           ans = max(ans, f[i][j][k]);         }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool comp(const pair<int, int> &a, const pair<int, int> &b) {     if (a.first == b.first) return a.second < b.second;     return a.first < b.first;   }   bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) {     if (a.second == b.second) return b.first > a.first;     return (a.second < b.second);   }   bool compmx(int a, int b) { return (a < b); }   long long int bin(long long int n) {     long long int B_Number = 0;     long long int cnt = 0;     while (n != 0) {       long long int rem = n % 2;       long long int c = pow(10, cnt);       B_Number += rem * c;       n /= 2;       cnt++;     }     return B_Number;   }   long long int gcd(long long int a, long long int b) {     if (b == 0)       return a;     else       return gcd(b, a % b);   }   bool is_prime(long long int x) {     if (x == 1) return false;     if (x == 2 || x == 3) return true;     for (long long int i = 2; i * i <= x; i++) {       if (x % i == 0) return false;     }     return true;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long int d, n;     cin >> d >> n;     ;     long long int a[n];     for (long long int i = 0; i < n; i++) {       cin >> a[i];     };     long long int ans = 0;     long long int x;     for (long long int i = 1; i < n; i++) {       x = a[i - 1] + 1;       if (x > d) x = 1;       if (x == 1)         continue;       else         ans += (d - x + 1);     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1073741824;   const int N = 100005;   const double PI = 4 * atan(1);   int dx[] = {1, -1, 0, 0, 1, -1, 1, -1};   int dy[] = {0, 0, 1, -1, 1, 1, -1, -1};   long long gcd(long long a, long long b) { return (b == 0 ? a : gcd(b, a % b)); }   long long lcm(long long a, long long b) { return a * (b / gcd(a, b)); }   bool issquare(long long w) { return trunc(sqrt(w)) * trunc(sqrt(w)) == w; }   bool isprime(long long u) {     for (long long i = 2; i <= (int)sqrt(u); i++) {       if (u % i == 0) return 0;     }     return 1;   }   long long mod(long long to_mod) {     to_mod %= MOD;     while (to_mod < 0) to_mod += MOD;     return to_mod % MOD;   }   long long moduloMultiplication(long long a, long long b, long long mod) {     long long res = 0;     a %= mod;     while (b) {       if (b & 1) res = (res + a) % mod;       a = (2 * a) % mod;       b >>= 1;     }     return res;   }   long long power(long long x, long long y) {     long long res = 1;     x = x;     while (y > 0) {       if (y & 1) res = (res * x);       y = y >> 1;       x = (x * x);     }     return res;   }   long long _sieve_size;   bitset<1000010> bs;   vector<long long> primes;   void sieve(long long upperbound) {     _sieve_size = upperbound + 1;     bs.set();     bs[0] = bs[1] = 0;     for (long long i = 2; i <= _sieve_size; i++)       if (bs[i]) {         for (long long j = i * i; j <= _sieve_size; j += i) bs[j] = 0;         primes.push_back(i);       }   }   long long numDiv(long long N) {     long long PF_idx = 0, PF = primes[PF_idx], ans = 1;     while (PF * PF <= N) {       long long power = 0;       while (N % PF == 0) {         N /= PF;         power++;       }       ans *= (power + 1);       PF = primes[++PF_idx];     }     if (N != 1) ans *= 2;     return ans;   }   int main() {     sieve(1000000);     long long t[1000005];     for (int i = 1; i <= 1000000; i++) {       t[i] = numDiv(i);     }     long long a, b, c, ans = 0;     cin >> a >> b >> c;     for (int i = 1; i <= a; i++) {       for (int j = 1; j <= b; j++) {         for (int k = 1; k <= c; k++) {           ans = mod(ans + t[i * j * k]);         }       }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   int main() {     ios_base::sync_with_stdio(false);     while (cin >> n) {       vector<int> inside(1000006, 0), ans;       int stack = 0, length = 0, x, valid = 1, j = 1;       unordered_map<int, int> used;       for (int i = 0; i < n; ++i) {         cin >> x;         if ((x > 0 && inside[x]) || (x < 0 && !inside[-x]) ||             (x > 0 && used[x])) {           valid = 0;         } else if (x > 0) {           ++inside[x];           ++stack;           ++length;           used[x] = j++;         } else if (x < 0) {           --inside[-x];           --stack;           ++length;         }         if (!stack && valid) {           ans.emplace_back(length);           length = 0;           used.clear();         }       }       if (stack) valid = 0;       if (valid) {         cout << ans.size() << endl;         for (int i : ans) cout << i <<    ;         cout << endl;       } else {         cout << -1 << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   uint64_t ans, fact[21];   long long t, n, cont, val;   bool us[30];   vector<uint64_t> v;   uint64_t calc() {     uint64_t tmp = 1;     uint64_t freq[30];     uint64_t ind = 0;     for (int i = 0; i < 30; i++) freq[i] = 0;     for (int i = 0; i < v.size(); i++) {       while (ind < v.size() && v[ind] < (i + 2)) {         ind++;       }       freq[v[i]]++;       tmp *= max((uint64_t)0, ind - i);     }     for (int i = 0; i < 30; i++) {       tmp /= fact[freq[i]];     }     return tmp;   }   int main() {     fact[0] = 1;     for (int i = 1; i < 21; i++) fact[i] = fact[i - 1] * uint64_t(i);     cin >> t;     while (t--) {       cin >> n;       v.clear();       ans = 0;       memset(us, false, sizeof(us));       cont = 2;       while (n) {         v.push_back(n % cont);         n /= cont;         cont++;       }       sort(v.begin(), v.end());       for (int i = 0; i < v.size(); i++) {         if (v[i] != 0 && us[v[i]] == false) {           val = v[i];           v.erase(v.begin() + i);           ans += calc();           v.insert(v.begin() + i, val);           us[val] = true;         }       }       cout << ans - 1 <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int m, n, cn, nw, res, ans;   int used[533];   int x[1020], y[1020];   int a[1020][1020];   int asjkjas[1020];   bool kuhn(int x) {     if (used[x] == nw) return false;     used[x] = nw;     for (int i = (0); i < (n); ++i)       if (a[x][i] && i != cn && (asjkjas[i] == -1 || kuhn(asjkjas[i]))) {         asjkjas[i] = x;         return true;       }     return false;   }   int main() {     ios::sync_with_stdio(false);     cin >> n >> m;     for (int i = (0); i < (m); ++i) {       cin >> x[i] >> y[i];       x[i]--;       y[i]--;       a[x[i]][y[i]] = 1;     }     int res = 1000000000;     for (int c = (0); c < (n); ++c) {       cn = c;       int ans = 0;       for (int i = (0); i < (n); ++i) {         if (i != c)           ans += 2 - a[i][c] - a[c][i];         else           ans += 1 - a[i][i];       }       for (int i = (0); i < (n); ++i) used[i] = -1, asjkjas[i] = -1;       int ep = 0;       for (int i = (0); i < (n); ++i) {         if (i != c) {           nw = i;           if (kuhn(i)) ++ep;         }       }       ans += (n - 1) - ep;       for (int i = (0); i < (m); ++i)         if (x[i] != c && y[i] != c) ans += 1;       ans -= ep;       res = min(res, ans);     }     cout << res << endl;   }


#include <bits/stdc++.h>   using namespace std;   int n;   int odd, even;   int miny[400001], maxy[400001], min2y[400001], max2y[400001];   vector<int> p[400001];   int main() {     ios::sync_with_stdio(false);     cin >> n;     for (int i = 0; i <= 2e5; i++) {       maxy[i] = -1, miny[i] = 2e5 + 1;     }     for (int i = 1; i <= n; i++) {       int u, v, x, y;       cin >> u >> v;       x = v - u;       y = u + v;       x += 2e5;       y += 2e5;       p[x].push_back(y);     }     for (int i = 0; i <= 4e5; i++) {       sort(p[i].begin(), p[i].end());       miny[i] = min2y[i] = 4e5 + 1;       maxy[i] = max2y[i] = -1;     }     for (int i = 1; i <= 4e5; i++) {       if (i > 1) maxy[i] = maxy[i - 2];       if (i > 1) miny[i] = miny[i - 2];       if (!p[i - 1].empty()) maxy[i] = max(maxy[i], p[i - 1].back() - 1);       if (!p[i - 1].empty()) miny[i] = min(miny[i], p[i - 1][0] + 1);     }     long long ans = 0;     for (int i = 4e5 - 1; i >= 0; i--) {       if (i < 4e5 - 1) max2y[i] = max2y[i + 2];       if (i < 4e5 - 1) min2y[i] = min2y[i + 2];       if (!p[i + 1].empty()) max2y[i] = max(max2y[i], p[i + 1].back() - 1);       if (!p[i + 1].empty()) min2y[i] = min(min2y[i], p[i + 1][0] + 1);       maxy[i] = min(maxy[i], max2y[i]);       miny[i] = max(miny[i], min2y[i]);       if (maxy[i] >= miny[i]) {         ans += (maxy[i] - miny[i]) / 2 + 1;       }     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   template <class C>   void mini(C& a4, C b4) {     a4 = min(a4, b4);   }   template <class C>   void maxi(C& a4, C b4) {     a4 = max(a4, b4);   }   template <class T1, class T2>   ostream& operator<<(ostream& out, pair<T1, T2> pair) {     return out <<  (  << pair.first <<  ,   << pair.second <<  ) ;   }   template <class A, class B, class C>   struct Triple {     A first;     B second;     C third;   };   template <class T>   void ResizeVec(T&, vector<long long>) {}   template <class T>   void ResizeVec(vector<T>& vec, vector<long long> sz) {     vec.resize(sz[0]);     sz.erase(sz.begin());     if (sz.empty()) {       return;     }     for (T& v : vec) {       ResizeVec(v, sz);     }   }   void Pol() {     cout <<  Polycarp n ;     exit(0);   }   void Vas() {     cout <<  Vasiliy n ;     exit(0);   }   int main() {     ios_base::sync_with_stdio(0);     cout << fixed << setprecision(10);     double beg_clock = 1.0 * clock() / CLOCKS_PER_SEC;     long long xp, yp, xv, yv;     cin >> xp >> yp >> xv >> yv;     ;     if (xv < yv) {       swap(xp, yp);       swap(xv, yv);     }     if (xp <= xv && yp <= yv) {       Pol();     }     if (xp + yp <= max(xv, yv)) {       Pol();     }     if (xv < xp) {       Vas();     }     long long tv = max(yv, xv - xp);     long long tp = yp;     if (tp <= tv) {       Pol();     } else {       Vas();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 100005;   set<int> g[maxn];   set<int> vis;   int u[maxn];   void dfs(int x) {     u[x] = 1;     vis.erase(x);     vector<int> ret;     for (int p : vis) {       if (!g[x].count(p)) {         ret.push_back(p);       }     }     for (int t : ret) {       vis.erase(t);     }     for (int t : ret) {       u[t] = 1;       dfs(t);     }   }   int main() {     int n, m;     cin >> n >> m;     for (int i = 0; i < m; i++) {       int x, y;       cin >> x >> y;       x--, y--;       g[x].insert(y);       g[y].insert(x);     }     for (int i = 0; i < n; i++) {       vis.insert(i);     }     int ans = 0;     for (int i = 0; i < n; i++) {       if (!u[i]) {         ans++;         dfs(i);       }     }     cout << ans - 1 << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a[6];     for (int i = 0; i < 6; i++) cin >> a[i];     a[5]++;     int mn = 100000;     for (int i = 0; i < 6; i++) {       if (i == 4) continue;       if (mn > a[i]) mn = a[i];     }     cout << (mn > a[4] ? mn - a[4] : 0) << endl;     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3fffffff;   const int SINF = 0x7fffffff;   const long long LINF = 0x3fffffffffffffff;   const long long SLINF = 0x7fffffffffffffff;   const int MAXN = 2007;   int n, m;   vector<int> es[MAXN];   bitset<MAXN> bs[MAXN];   bool hv[MAXN];   int dp[MAXN];   void init();   void input();   void work();   int main() {     init();     int T;     scanf( %d , &T);     while (T--) {       input();       work();     }   }   void init() { ios::sync_with_stdio(false); }   void input() {     scanf( %d%d , &n, &m);     int u, v;     for (int i = 1; i <= n; ++i) es[i].clear();     for (int i = 1; i <= m; ++i) {       scanf( %d%d , &u, &v);       es[u].push_back(v);       es[v].push_back(u);     }   }   void work() {     bool flag = true;     for (int i = 1; i <= n; ++i) {       if (es[i].size() & 1) {         flag = false;         break;       }     }     if (flag) {       printf( 1 n );       for (int i = 1; i <= n; ++i) printf( 1  );       putchar(  n );       return;     }     bitset<MAXN> nb;     memset(hv, false, sizeof(hv));     for (int i = 1; i <= n; ++i) bs[i] = 0;     for (int i = 1; i <= n; ++i) {       nb = 0;       for (auto x : es[i]) nb[x] = 1;       nb[i] = es[i].size() & 1;       nb[n + 1] = es[i].size() & 1;       for (int j = 1; j <= n; ++j) {         if (nb[j]) {           if (hv[j])             nb ^= bs[j];           else {             hv[j] = true;             bs[j] = nb;             break;           }         }       }     }     memset(dp, 0, sizeof(dp));     for (int i = n; i > 0; --i) {       if (hv[i]) {         dp[i] = bs[i][n + 1];         for (int j = i + 1; j <= n; ++j) {           if (bs[i][j] && hv[j]) dp[i] ^= dp[j];         }       }     }     printf( 2 n );     for (int i = 1; i <= n; ++i) printf( %d  , dp[i] + 1);     putchar(  n );   }


#include <bits/stdc++.h>   using namespace std;   template <typename A, typename B>   ostream& operator<<(ostream& os, const pair<A, B>& x) {     return os <<  (  << x.first <<  ,  << x.second <<  ) ;   }   const int MOD = 998244353;   long long modex(long long a, long long p, long long m = MOD) {     if (!p) return 1;     if (p & 1) return a * modex(a, p - 1, m) % m;     long long v = modex(a, p >> 1, m);     return v * v % m;   }   namespace fft {   const int mod = 998244353;   const int gen = 3;   vector<int> rev(1, 0), roots;   int base = 0;   void precompute(int nbase) {     if (nbase <= base) return;     rev.resize(1 << nbase);     for (int i = 0; i < (1 << nbase); ++i) {       rev[i] = rev[i >> 1] >> 1 | ((i & 1) << nbase - 1);     }     roots.resize(1 << nbase);     for (; base < nbase; ++base) {       int len = 1 << base;       long long root = modex(gen, (mod - 1) >> base + 1, mod);       roots[len] = 1;       for (int i = 1; i < len; ++i)         roots[len + i] = roots[len + i - 1] * root % mod;     }   }   void fft(vector<int>& a) {     int n = a.size();     assert((n & (n - 1)) == 0);     int zeros = __builtin_ctz(n);     precompute(zeros);     int shift = base - zeros;     for (int i = 0; i < n; ++i) {       if (i < (rev[i] >> shift)) swap(a[i], a[rev[i] >> shift]);     }     for (int len = 1; len < n; len <<= 1)       for (int i = 0; i < n; i += 2 * len)         for (int j = 0; j < len; ++j) {           int u = a[i + j], v = (long long)a[i + j + len] * roots[len + j] % mod;           a[i + j] = u + v >= mod ? u + v - mod : u + v;           a[i + j + len] = u - v < 0 ? u - v + mod : u - v;         }   }   vector<int> multiply(vector<int> a, vector<int> b) {     if (a.empty() || b.empty()) return {};     int sz = a.size() + b.size() - 1;     int n = sz == 1 ? 1 : 1 << (32 - __builtin_clz(sz - 1));     bool eq = (a == b);     a.resize(n);     fft(a);     if (eq)       b = a;     else {       b.resize(n);       fft(b);     }     long long inv = modex(n, mod - 2, mod);     for (int i = 0; i < n; ++i) a[i] = (long long)a[i] * b[i] % mod * inv % mod;     fft(a);     reverse(a.begin() + 1, a.end());     a.resize(sz);     return a;   }   vector<int> multiply(const vector<int>& a, const vector<int>& b, int m) {     assert(m == mod);     return multiply(a, b);   }   };  // namespace fft   vector<int> B;   vector<int> multiplyAll(int s, int e) {     if (s == e) {       return {1, B[s]};     }     int m = (s + e) >> 1;     auto a = multiplyAll(s, m);     auto b = multiplyAll(m + 1, e);     return fft::multiply(a, b);   }   int sub(int x, int y) {     x -= y;     if (x < 0) x += MOD;     return x;   }   int main() {     int n, k;     scanf( %d%d , &n, &k);     vector<int> A(n);     B = vector<int>(n);     for (int i = 0; i < n; ++i) {       scanf( %d , &A[i]);       A[i] %= MOD;     }     int Q;     scanf( %d , &Q);     while (Q--) {       int t, q, a, b, d;       scanf( %d%d%d%d , &t, &q, &a, &b);       if (t == 1) {         b %= MOD;         for (int i = 0; i < n; ++i) B[i] = sub(q, A[i]);         B[a - 1] = sub(q, b);       } else {         scanf( %d , &d);         d %= MOD;         for (int i = 0; i < n; ++i) B[i] = sub(q, A[i]);         for (int i = a - 1; i < b; ++i) B[i] = sub(B[i], d);       }       auto p = multiplyAll(0, n - 1);       printf( %d n , p[k]);     }   }


#include <bits/stdc++.h>   using namespace std;   const long double EPS = 1e-10;   const long long MOD = 1000000007ll;   const long long mod1 = 1000000009ll;   const long long mod2 = 1100000009ll;   int INF = (int)1e9 + 5;   long long INFINF = (long long)1e18;   int main() {     int n;     scanf( %d , &n);     int a, b, diff;     diff = INF;     a = -1;     b = -1;     for (int i = 1; i <= n; i++) {       if (n % i == 0) {         int a_t, b_t;         a_t = i;         b_t = n / i;         if (abs(a_t - b_t) < diff) {           diff = abs(a_t - b_t);           a = min(a_t, b_t);           b = max(a_t, b_t);         }       }     }     printf( %d  , a);     printf( %d n , b);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long modpow(long long a, long long p, long long mod) {     long long ret = 1;     while (p) {       if (p & 1) ret = (ret * a) % mod;       a = (a * a) % mod;       p /= 2;     }     return ret;   }   long long power(long long a, long long p) {     long long ret = 1;     while (p) {       if (p & 1) ret = (ret * a);       a = (a * a);       p /= 2;     }     return ret;   }   int n, m;   int dx[] = {-1, 1, 0, 0};   int dy[] = {0, 0, -1, 1};   bool check(int i, int j) {     if (i >= 0 && j >= 0 && i < n && j < m) return 1;     return 0;   }   int v[2015][2015] = {0}, deg[2015][2015] = {0};   string mat[2015];   queue<pair<int, int> > q;   pair<int, int> p;   int main() {     int i, j, tmp;     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cin >> n >> m;     int x, y, xx, yy;     for (i = 0; i < n; i++) cin >> mat[i];     for (i = 0; i < n; i++) {       for (j = 0; j < m; j++) {         if (mat[i][j] ==  . )           for (x = 0; x < 4; x++) {             y = x;             if (check(i + dx[x], j + dy[y]) && mat[i + dx[x]][j + dy[y]] ==  . )               deg[i][j]++;           }         if (deg[i][j] == 1) q.push(make_pair(i, j));       }     }     while (!q.empty()) {       pair<int, int> p;       p = q.front();       q.pop();       i = p.first;       j = p.second;       for (x = 0; x < 4; x++) {         y = x;         if (check(i + dx[x], j + dy[y]) && mat[i + dx[x]][j + dy[y]] ==  . ) {           if (dx[x] == 1) {             mat[i][j] =  ^ ;             mat[i + dx[x]][j + dy[y]] =  v ;           } else if (dx[x] == -1) {             mat[i][j] =  v ;             mat[i + dx[x]][j + dy[y]] =  ^ ;           } else if (dy[y] == 1) {             mat[i][j] =  < ;             mat[i + dx[x]][j + dy[y]] =  > ;           } else if (dy[y] == -1) {             mat[i][j] =  > ;             mat[i + dx[x]][j + dy[y]] =  < ;           }           for (xx = 0; xx < 4; xx++) {             yy = xx;             if (check(i + dx[xx], j + dy[yy])) {               deg[i + dx[xx]][j + dy[yy]]--;               if (mat[i + dx[xx]][j + dy[yy]] ==  .  &&                   deg[i + dx[xx]][j + dy[yy]] == 1)                 q.push(make_pair(i + dx[xx], j + dy[yy]));             }             if (check(i + dx[x] + dx[xx], j + dy[y] + dy[yy])) {               deg[i + dx[x] + dx[xx]][j + dy[y] + dy[yy]]--;               if (mat[i + dx[x] + dx[xx]][j + dy[y] + dy[yy]] ==  .  &&                   deg[i + dx[x] + dx[xx]][j + dy[y] + dy[yy]] == 1)                 q.push(make_pair(i + dx[x] + dx[xx], j + dy[y] + dy[yy]));             }           }           break;         }       }     }     int f = 1;     for (i = 0; i < n; i++)       for (j = 0; j < m; j++)         if (mat[i][j] ==  . ) f = 0;     if (f) {       for (i = 0; i < n; i++) {         for (j = 0; j < m; j++) cout << mat[i][j];         cout << endl;       }     } else       cout <<  Not unique n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool sortmahstyle(const pair<int, int> &a, const pair<int, int> &b) {     if (a.first == b.first && a.second < b.second) return true;     return false;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int n, m, d;     cin >> n >> m >> d;     long long int a[n * m];     for (long long int i = 0; i < n * m; i++) cin >> a[i];     long long int ans = 0;     sort(a, a + (n * m));     for (long long int i = 0; i < n * m; i++) ans += abs(a[i] - a[n * m / 2]);     if (ans % d == 0)       cout << ans / d <<   n ;     else       cout <<  -1 n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 10010;   vector<pair<short int, short int> > G[MAXN];   vector<short int> cul[MAXN], row[MAXN];   pair<short int, short int> p[MAXN];   void add_edge(int u, int v, int d) { G[u].push_back(make_pair(v, d)); }   void init(int n) {     for (int i = 1; i <= n; i++) {       G[i].clear();     }   }   bool vis[MAXN];   int dis[MAXN];   void dijkstra(int s, int n) {     for (int i = 1; i <= n; i++) vis[i] = 0;     for (int i = 1; i <= n; i++) dis[i] = (i == s ? 0 : 0x3FFFFFFF);     priority_queue<pair<short int, short int>,                    vector<pair<short int, short int> >,                    greater<pair<short int, short int> > >         q;     q.push(make_pair(dis[s], s));     while (!q.empty()) {       pair<short int, short int> p = q.top();       int x = p.second;       q.pop();       if (vis[x]) continue;       vis[x] = 1;       for (int i = 0; i < G[x].size(); i++) {         int y = G[x][i].first;         int d = G[x][i].second;         if (!vis[y] && dis[x] + d < dis[y]) {           dis[y] = dis[x] + d;           q.push(make_pair(dis[y], y));         }       }     }   }   map<pair<short int, short int>, short int> mp;   int main() {     int n, m, k, a, b;     scanf( %d%d%d , &n, &m, &k);     for (int i = 1; i <= k; i++) {       scanf( %d%d , &a, &b);       p[i].first = a;       p[i].second = b;       mp[p[i]] = i;       cul[p[i].second].push_back(p[i].first);       row[p[i].first].push_back(p[i].second);     }     init(k);     for (int i = 1; i <= k; i++) {       short int x = p[i].first, y = p[i].second;       for (int j = 0; j < row[x].size(); j++)         if (row[x][j] != y)           add_edge(i, mp[make_pair(x, row[x][j])],                    row[x][j] - 1 != y && row[x][j] + 1 != y);       for (int j = 0; j < cul[y].size(); j++)         if (cul[y][j] != x)           add_edge(i, mp[make_pair(cul[y][j], y)],                    cul[y][j] - 1 != x && cul[y][j] + 1 != x);       for (int l = -1; l <= 1; l += 2) {         for (int j = 0; j < row[x + l].size(); j++)           if (row[x + l][j] != y)             add_edge(i, mp[make_pair(x + l, row[x + l][j])], 1);         for (int j = 0; j < cul[y + l].size(); j++)           if (cul[y + l][j] != x)             add_edge(i, mp[make_pair(cul[y + l][j], y + l)], 1);       }       for (int l = -2; l <= 2; l = l + 4) {         if (x + l > 0 && x + l <= m + 1)           for (int j = 0; j < row[x + l].size(); j++)             add_edge(i, mp[make_pair(x + l, row[x + l][j])], 1);         if (y + l > 0 && y + l <= n + 1)           for (int j = 0; j < cul[y + l].size(); j++)             add_edge(i, mp[make_pair(cul[y + l][j], y + l)], 1);       }     }     dijkstra(1, k);     int ans = 0x3FFFFFFF;     for (int i = 1; i <= k; i++) {       if (dis[i] == 0x3FFFFFFF || dis[i] > ans) continue;       if (n - p[i].first + m - p[i].second <= 1)         ans = min(ans, dis[i] + (mp[make_pair(n, m)] == 0));       else if (n - p[i].first <= 1 || m - p[i].second <= 1)         ans = min(ans, dis[i] + 1);     }     if (ans == 0x3FFFFFFF)       cout << -1 << endl;     else       cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int sum = 0;     while (n) {       if (n % 8 == 1) {         sum++;       }       n = n / 8;     }     cout << sum;     return 0;   }


#include <bits/stdc++.h>   #define maxn 10      using namespace std;      int n, m;   map<vector<int>, int> f, g;   int a[maxn], b[maxn], c[maxn][maxn];      int main(){    scanf( %d%d , &n, &m);    vector<int> v;    for(int i = 1;i <= n;i++) scanf( %d , &a[i]);    for(int i = 1;i <= m;i++) scanf( %d , &b[i]);    for(int i = 1;i <= n;i++) for(int j = 1;j <= m;j++) scanf( %d , &c[i][j]);    f[vector<int>(n + 1)] = 0;    for(int j = 1;j <= m;j++){     for(map<vector<int>, int>::iterator it = f.begin();it != f.end();++it){      vector<int> v = it->first;      v[n] = 0;      if(g.find(v) == g.end()) g[v] = it->second;      else g[v] = min(g[v], it->second);     }     swap(f, g), g.clear();     for(int i = 1;i <= n;i++){      for(map<vector<int>, int>::iterator it = f.begin();it != f.end();++it){       vector<int> v = it->first;        for(int k = 0;k <= min(a[i] - v[i - 1], b[j] - v[n]);k++){        vector<int> w = v;        w[i - 1] += k, w[n] += k;         if(g.find(w) == g.end()) g[w] = it->second + (k ? c[i][j] : 0);        else g[w] = min(g[w], it->second + (k ? c[i][j] : 0));          }      }      swap(f, g), g.clear();     }    }    int ans = 1e9;    for(map<vector<int>, int>::iterator it = f.begin();it != f.end();++it){     vector<int> v = it->first;      bool tag = false;     for(int i = 0;i < n;i++){      if(v[i] < a[i + 1]){       tag = true;       break;      }     }     if(!tag) ans = min(ans, it->second);    }    printf( %d , ans == 1e9 ? -1 : ans);   }


#include <bits/stdc++.h>   using namespace std;   void FAST_IO(string filein =   , string fileout =   , string fileerr =   ) {     if (fopen(filein.c_str(),  r )) {       freopen(filein.c_str(),  r , stdin);       freopen(fileout.c_str(),  w , stdout);     }     cin.tie(0), cout.tie(0)->sync_with_stdio(0);   }   void Hollwo_Pelw();   signed main() {     FAST_IO( hollwo_pelw.inp ,  hollwo_pelw.out );     int testcases = 1;     for (int test = 1; test <= testcases; test++) {       Hollwo_Pelw();     }     return 0;   }   const int N = 2e5 + 5, L = 18;   struct edge {     int t, c, u, v;     edge(int _t = 0, int _c = 0, int _u = 0, int _v = 0)         : t(_t), c(_c), u(_u), v(_v) {}     bool operator<(const edge &o) const { return c != o.c ? c > o.c : t > o.t; }   };   int n, q, res_enj[N], res_tol[N], h[N];   vector<pair<int, int>> adj[N];   pair<int, int> jmp[N][L];   void pre_dfs(int u, int p = 0) {     h[u] = h[p] + 1;     for (int i = 1; i < 18; i++) {       auto [v1, w1] = jmp[u][i - 1];       auto [v2, w2] = jmp[v1][i - 1];       jmp[u][i] = {v2, max(w1, w2)};     }     for (auto [v, w] : adj[u])       if (v != p) {         jmp[v][0] = {u, w};         pre_dfs(v, u);       }   }   inline int get_toll(int u, int v) {     int res = 0;     if (h[u] < h[v]) swap(u, v);     for (int i = 17; ~i; i--)       if (h[u] - h[v] >> i & 1) {         auto [nu, wu] = jmp[u][i];         u = nu, res = max(res, wu);       }     if (u == v) return res;     for (int i = 17; ~i; i--)       if (jmp[u][i].first ^ jmp[v][i].first) {         auto [nu, wu] = jmp[u][i];         u = nu, res = max(res, wu);         auto [nv, wv] = jmp[v][i];         v = nv, res = max(res, wv);       }     return max({res, jmp[u][0].second, jmp[v][0].second});   }   int par[N], max_enj[N], max_pos[N], toll_in[N];   struct disjoint_set {     disjoint_set(int n = N) {       iota(par, par + n, 0);       iota(max_pos, max_pos + n, 0);     }     inline int find(int u) { return par[u] == u ? u : par[u] = find(par[u]); }     inline void merge(int u, int v) {       assert((u = find(u)) != (v = find(v)));       par[v] = u;       if (max_enj[u] < max_enj[v]) {         max_enj[u] = max_enj[v];         max_pos[u] = max_pos[v];         toll_in[u] = toll_in[v];       } else if (max_enj[u] == max_enj[v]) {         toll_in[u] =             max({toll_in[u], toll_in[v], get_toll(max_pos[u], max_pos[v])});       }     }   };   void Hollwo_Pelw() {     cin >> n >> q;     for (int i = 1; i <= n; i++) cin >> max_enj[i];     vector<edge> queries(n + q - 1);     for (int i = 0, u, v, c, t; i < n - 1; i++) {       cin >> u >> v >> c >> t;       adj[u].emplace_back(v, t);       adj[v].emplace_back(u, t);       queries[i] = edge(t, c, u, v);     }     for (int i = 0, u, c; i < q; i++) {       cin >> c >> u;       queries[i + n - 1] = {0, c, u, i};     }     pre_dfs(1);     sort(queries.begin(), queries.end());     disjoint_set dsu(n + 1);     for (auto [t, c, u, v] : queries) {       if (t) {         dsu.merge(u, v);       } else {         int pu = dsu.find(u);         res_enj[v] = max_enj[pu];         res_tol[v] = max(toll_in[pu], get_toll(u, max_pos[pu]));       }     }     for (int i = 0; i < q; i++) cout << res_enj[i] <<     << res_tol[i] <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   struct cell {     long long root_vertix, com_len;     cell() {}     cell(long long x, long long y) {       root_vertix = x;       com_len = y;     }     bool operator<(const cell &x) const { return com_len < x.com_len; }   };   long long root[100002];   long long n, m, p, q;   long long find_root(long long x) {     if (root[x] <= 0) return x;     return root[x] = find_root(root[x]);   }   bool merge(long long x, long long y, long long len) {     x = find_root(x);     y = find_root(y);     if (x == y) {       root[x] -= len;       return false;     } else {       root[x] = root[x] - len + root[y];       root[y] = x;       return 1;     }   }   int main() {     cin >> n >> m >> p >> q;     long long components = n;     fill(root, root + n + 1, 0);     for (int i = 0; i < m; i++) {       long long x, y, z;       cin >> x >> y >> z;       if (merge(x, y, z)) components--;     }     if (components < q || p < (components - q) ||         (components == n && q == n && p > 0)) {       cout <<  NO  << endl;       return 0;     } else       cout <<  YES  << endl;     priority_queue<cell> qq;     for (int i = 1; i <= n; i++)       if (root[i] <= 0) qq.push(cell(i, root[i]));     long long diff = components - q;     long long same = p - diff;     while (diff--) {       cell x, y;       x = qq.top();       qq.pop();       y = qq.top();       qq.pop();       long long len = min((long long)1000000000, -x.com_len - y.com_len + 1);       cout << x.root_vertix <<     << y.root_vertix << endl;       merge(x.root_vertix, y.root_vertix, len);       x.com_len = root[x.root_vertix];       qq.push(x);     }     long long vertix;     for (int i = 1; i <= n; i++)       if (root[i] > 0) {         vertix = i;         break;       }     while (same--) cout << vertix <<     << root[vertix] << endl;     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   bool tu[305][305];   long long pri[305];   int d[305];   int n, m, t;   int bg[1100000];   int top[110000];   int main() {     scanf( %d%d%d , &n, &m, &t);     for (int i = 1; i <= n; i++) scanf( %I64d , &pri[i]);     for (int i = 1; i <= m; i++) {       int b, c;       scanf( %d%d , &b, &c);       tu[b][c] = 1;       d[c]++;     }     for (int kk = 1; kk <= n; kk++) {       int now = 0;       for (int i = 1; i <= n; i++)         if (d[i] == 0) now = i;       if (!now) {         printf( 0 n );         return 0;       }       d[now] = -1;       for (int i = 1; i <= n; i++)         if (tu[now][i]) d[i]--;       top[++top[0]] = now;     }     for (int i = 1; i <= top[0]; i++) {       int x = top[i];       for (int j = 1; j <= n; j++) {         if (tu[x][j]) pri[j] += pri[x], t -= pri[x];         if (t < 0) {           printf( 0 n );           return 0;         }       }     }     if (t < 0) {       printf( 0 n );       return 0;     }     bg[0] = 1;     for (int i = 1; i <= n; i++)       for (long long j = pri[i]; j <= t; j++)         bg[j] = (bg[j] + bg[j - pri[i]]) % 1000000007;     printf( %d n , t >= 0 ? bg[t] : 0);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main()   {       long long tests, a, b, c, i,sum;       cin >> tests;       while (tests--)       {           cin >> a >> b >> c;           if (c / b + 1 >= a)               printf( %lld n ,(a*a-a)/2);           else               printf( %lld n ,(c/b)*(c/b+1)/2+(a-c/b-1)*(c/b));       }   }


#include <bits/stdc++.h>   using namespace std;   const int Maxn = 100020;   char s[Maxn];   int a[Maxn];   int k, n;   bool check(int m) {     for (int i = 1; i <= n; i++) {       if (s[i] ==  1 ) continue;       if (a[i - 1] - a[max(0, i - m - 1)] + a[min(n, i + m)] - a[i] >= k)         return 1;     }     return 0;   }   int main() {     scanf( %d%d , &n, &k);     scanf( %s , s + 1);     for (int i = 1; i <= n; i++) a[i] = a[i - 1] + (s[i] ==  0 );     int l = 1, r = n;     while (l <= r) {       int mid = (l + r) >> 1;       if (check(mid))         r = mid - 1;       else         l = mid + 1;     }     printf( %d n , l);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string x, y, z;     cin >> x;     y += tolower(x[0]);     z += toupper(x[0]);     for (int i = 1; i < x.size(); i++) {       y += toupper(x[i]);       z += toupper(x[i]);     }     if (x == y || x == z || x.size() == 1) {       for (int i = 0; i < x.size(); i++) {         if (x[i] == toupper(x[i]))           x[i] = tolower(x[i]);         else           x[i] = toupper(x[i]);       }     }     cout << x << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, a, x, b, y;     cin >> n >> a >> x >> b >> y;     int flag = 0;     while (flag == 0) {       if (a == b) {         flag = 1;         break;       }       if (a == x) {         break;       }       if (b == y) {         break;       }       a++;       b--;       if (a == n + 1) {         a = 1;       }       if (b == 0) {         b = n;       }     }     if (flag == 1) {       cout <<  YES             <<   n ;     } else if (flag == 0) {       cout <<  NO             <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optmize(2)   using namespace std;   inline int read() {     int X = 0, w = 0;     char ch = 0;     while (!isdigit(ch)) w |= ch ==  - , ch = getchar();     while (isdigit(ch)) X = (X << 3) + (X << 1) + (ch ^ 48), ch = getchar();     return w ? -X : X;   }   int f[1000010];   vector<int> G[1000010];   int vis[1000010];   int tot, s, cnt;   int dfs(int i) {     int res = 1;     vis[i] = 1;     for (int j = 0; j < G[i].size(); j++) {       if (!vis[G[i][j]]) res += dfs(G[i][j]);     }     return res;   }   multiset<int> ss;   int n = read(), m = read(), k = read();   int main() {     for (int i = 1; i <= m; i++) {       int x = read(), y = read();       G[x].push_back(y), G[y].push_back(x);     }     for (int i = 1; i <= n; i++)       if (!vis[i]) f[++tot] = dfs(i);     sort(f + 1, f + tot + 1);     reverse(f + 1, f + tot + 1);     int total = 0;     for (int i = 1; i <= tot; i++) {       f[i] = min(f[i], k);       total += f[i];       ss.insert(f[i]);     }     for (int i = 0;; i++) {       if (total >= 2 * ((int)ss.size() - 1)) {         cout << i << endl;         return 0;       }       int a = *ss.begin();       ss.erase(ss.begin());       int b = *ss.begin();       ss.erase(ss.begin());       total = total - a - b + min(a + b, k);       ss.insert(min(a + b, k));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     int n, x, y;     cin >> n >> x >> y;     char c;     long long s = 0;     bool b = 0;     for (int i = 0; i < n; i++) {       cin >> c;       if (b == 1 && c ==  1 ) {         b = 0;         s++;       } else if (b == 0 && c ==  0 ) {         b = 1;       }     }     if (c ==  0 ) s++;     if (s > 0 && x < y) {       cout << (s - 1) * x + y;     } else       cout << s * y;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n;     cin >> n;     string s;     cin >> s;     vector<long long int> ind;     long long int t = 0;     ind.push_back(0);     for (long long int i = 1; i < n; i++) {       if (s[i] != s[ind[t]]) {         t++;         ind.push_back(i);       }     }     long long int f = 0;     long long int last = 0;     for (long long int i = 1; i <= t; i++) {       if (ind[i] - ind[i - 1] - 1 >= 2) {         f = 1;         break;       }       if (ind[i] - ind[i - 1] - 1 >= 1) {         last++;       }     }     if (n - ind[t] - 1 >= 2) f = 1;     if (n - ind[t] - 1 >= 1) last++;     if (last >= 2) f = 1;     if (f == 1) {       cout << ind.size() + 2 <<   n ;     } else if (last >= 1) {       cout << ind.size() + 1 <<   n ;     } else {       cout << ind.size() <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int d[100][110];   int grad[110];   int dp[1 << 16];   int main() {     int n, m, a, b, c, sum(0);     ios_base ::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m;     for (int i(0); i < n; i++)       for (int j(0); j < n; j++)         if (i != j) d[i][j] = 1e9;     while (m--) {       cin >> a >> b >> c;       a--;       b--;       sum += c;       grad[a]++, grad[b]++;       d[a][b] = d[b][a] = min(d[a][b], c);     }     for (int k(0); k < n; k++)       for (int i(0); i < n; i++)         for (int j(0); j < n; j++) d[i][j] = min(d[i][j], d[i][k] + d[k][j]);     for (int i(0); i < n; i++) {       if (grad[i] && d[0][i] >= 1e9) {         cout << -1;         return 0;       }     }     int mask(0);     for (int i(0); i < n; i++)       if (grad[i] & 1) mask |= (1 << i);     for (int i(0); i <= mask; i++) dp[i] = 1e9;     dp[mask] = 0;     while (mask) {       for (int i(0); i < n; i++) {         if (!(mask & (1 << i))) continue;         for (int j(i + 1); j < n; j++)           if (mask & (1 << j))             dp[mask ^ (1 << i) ^ (1 << j)] =                 min(dp[mask ^ (1 << i) ^ (1 << j)], dp[mask] + d[i][j]);       }       mask--;     }     cout << dp[0] + sum <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int arr[10] = {0};     char S[100001];     cin >> S;     for (int i = 0; S[i]; i++) {       int j = 0;       if (S[i] ==  L ) {         while (arr[j] == 1) j++;         arr[j] = 1;       }       j = 10 - 1;       if (S[i] ==  R ) {         while (arr[j] == 1) j--;         arr[j] = 1;       }       if (S[i] >= 48 && S[i] <= 57) {         arr[S[i] - 48] = 0;       }     }     for (int i = 0; i < 10; i++) cout << arr[i];     cout << endl;   }


#include <bits/stdc++.h>   using namespace std;   string s;   int n;   long long ans;   vector<int> ls, rr;   long long cal(int l, int r) {     long long val = 0;     long long tmp = s[l] -  0 ;     for (int i = l + 1; i < r; i += 2) {       if (s[i] ==  * )         tmp *= s[i + 1] -  0 ;       else {         val += tmp;         tmp = s[i + 1] -  0 ;       }     }     val += tmp;     long long res = 0;     tmp = s[0] -  0 ;     if (l == 0) tmp = val;     for (int i = (l == 0) ? r : 1; i < n; i += 2) {       if (i + 1 == l) {         tmp *= val;         i = r - 2;         continue;       }       if (s[i] ==  * )         tmp *= (long long)(s[i + 1] -  0 );       else {         res += tmp;         tmp = (long long)(s[i + 1] -  0 );       }     }     res += tmp;     return res;   }   int main() {     cin >> s;     n = s.length();     ls.push_back(0);     rr.push_back(n);     for (int i = 1; i < n; i += 2) {       if (s[i] ==  * ) {         ls.push_back(i + 1);         rr.push_back(i);       }     }     for (int l = 0; l < ls.size(); l++)       for (int r = 0; r < rr.size(); r++) {         if (ls[l] >= rr[r]) continue;         ans = max(ans, cal(ls[l], rr[r]));       }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int read() {     int x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x * f;   }   int n, l[200100], r[200100], L[200100], R[200100];   int main() {     n = read();     for (int i = 1; i <= n; i++) {       l[i] = read();       r[i] = read();       r[i] += l[i];     }     L[0] = R[n + 1] = 1e9 + 10;     for (int i = 1; i <= n; i++) L[i] = min(r[i], L[i - 1] + 1);     for (int i = n; i >= 1; i--) R[i] = min(r[i], R[i + 1] + 1);     long long ans = 0, f = 0;     for (int i = 1; i <= n; i++) {       if (min(L[i], R[i]) < l[i]) f = 1;       ans += min(L[i], R[i]) - l[i];     }     if (f) {       puts( -1 );       return 0;     }     printf( %I64d n , ans);     for (int i = 1; i <= n; i++) printf( %d  , min(L[i], R[i]));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long a[100005], c[100005];   vector<pair<long long, long long>> p[100005];   long long check(long long x, long long i) {     long long v = 0;     for (auto j : p[i]) {       long long v1 = j.first, v2 = j.second;       if (v1 != -1) v += abs(v1 - x);       if (v2 != -1) v += abs(v2 - x);     }     return v;   }   int main() {     long long n, m, sum = 0;     cin >> n >> m;     for (long long i = 1; i <= m; i++) {       scanf( %lld , &a[i]);     }     if (m == 1) {       cout << 0 << endl;       return 0;     }     a[0] = a[1], a[m + 1] = a[m];     for (long long i = 1; i <= m; i++) {       long long x = a[i - 1], y = a[i + 1];       if (x == a[i]) x = -1;       if (y == a[i]) y = -1;       p[a[i]].push_back({min(x, y), max(x, y)});     }     for (long long i = 2; i <= m; i++) {       sum += abs(a[i] - a[i - 1]);     }     for (long long i = 1; i <= n; i++) {       c[i] = check(i, i);     }     long long res = 2e18;     for (long long i = 1; i <= n; i++) {       if (p[i].size() == 0) continue;       long long l = 1, r = n, ans = 2e18;       while (r >= l) {         long long midl = l + (r - l) / 3, numl = check(midl, i);         long long midr = r - (r - l) / 3, numr = check(midr, i);         if (numl <= numr)           r = midr - 1, ans = min(ans, numl);         else           l = midl + 1, ans = min(ans, numr);       }       res = min(res, sum - c[i] + ans);     }     cout << res << endl;   }


#include <bits/stdc++.h>   using namespace std;   const long long mxn = 1e5 + 7;   int main() {     long long n, mx = 0, a[mxn];     cin >> n;     for (int i = 1; i <= n; i++) {       int x;       cin >> x;       a[x]++;     }     for (int i = 1; i <= 101; i++) {       mx = max(mx, a[i]);     }     cout << mx;   }


#include <bits/stdc++.h>   using namespace std;   int na, ma, nb, mb;   char s[55][55];   char t[55][55];   int main() {     while (~scanf( %d%d , &na, &ma)) {       for (int i = 0; i < na; i++) scanf( %s , s[i]);       scanf( %d%d , &nb, &mb);       for (int i = 0; i < nb; i++) scanf( %s , t[i]);       int ans = 0, xx = 0, yy = 0;       int n = max(na, nb), m = max(ma, mb);       for (int x = -n; x <= n; x++)         for (int y = -m; y <= m; y++) {           int tmp = 0;           for (int i = 0; i < na; i++)             for (int j = 0; j < ma; j++)               if (i + x < nb && j + y < mb && i + x >= 0 && j + y >= 0)                 tmp += (s[i][j] ==  1 ) & (t[i + x][j + y] ==  1 );           if (ans < tmp) ans = tmp, xx = x, yy = y;         }       printf( %d %d n , xx, yy);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; ++i) putchar( 1 );     puts(  );     for (int i = 1; i < n; ++i) putchar( 8 );     puts( 9 );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int l[10100];   int r[10100];   int per[100100];   int pr(int x) {     if (x == per[x]) return x;     return per[x] = pr(per[x]);   }   int main() {     ios::sync_with_stdio(0);     int n;     cin >> n;     int t = 0;     for (int i = 1; i <= n; i++) {       per[i] = i;       cin >> l[i];       cin >> r[i];       t += l[i] == 0;     }     for (int i = 1; i <= n; i++) {       if (l[i]) {         r[l[i]] = i;         per[pr(i)] = pr(l[i]);       }       if (r[i]) {         l[r[i]] = i;         per[pr(i)] = pr(r[i]);       }     }     for (int i = 1; i <= n; i++) {       if (l[i] == 0) {         if (t == 1) continue;         for (int j = 1; j <= n; j++) {           if (i == j) continue;           if (pr(i) == pr(j)) continue;           if (r[j] == 0) {             r[j] = i;             l[i] = j;             per[pr(i)] = pr(j);             break;           }         }         t--;       }     }     for (int i = 1; i <= n; i++) {       cout << l[i] <<     << r[i] <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   const int maxn = 100001;   int n, a[maxn];   struct Segment {     int val, tag;   } seg[maxn << 1 | 1];   inline int seg_idx(int L, int R) { return (L + R) | (L < R); }   void seg_down(int rt, int lch, int rch) {     if (!seg[rt].tag) return;     seg[lch].val += seg[rt].tag;     seg[lch].tag += seg[rt].tag;     seg[rch].val += seg[rt].tag;     seg[rch].tag += seg[rt].tag;     seg[rt].tag = 0;   }   void seg_up(int rt, int lch, int rch) {     seg[rt].val = std::max(seg[lch].val, seg[rch].val);   }   void seg_upd(int L, int R, int x, int v) {     int rt = seg_idx(L, R);     if (R <= x) {       seg[rt].val += v;       seg[rt].tag += v;       return;     }     int M = (L + R) >> 1, lch = seg_idx(L, M), rch = seg_idx(M + 1, R);     seg_down(rt, lch, rch);     seg_upd(L, M, x, v);     if (x > M) seg_upd(M + 1, R, x, v);     seg_up(rt, lch, rch);   }   int seg_que(int L, int R) {     int rt = seg_idx(L, R);     if (L == R) return L;     int M = (L + R) >> 1, lch = seg_idx(L, M), rch = seg_idx(M + 1, R), ret;     seg_down(rt, lch, rch);     ret = seg[rch].val <= 0 ? seg_que(L, M) : seg_que(M + 1, R);     seg_up(rt, lch, rch);     return ret;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) {       int pos, typ;       scanf( %d%d , &pos, &typ);       if (typ == 1) {         scanf( %d , a + pos);         seg_upd(1, n, pos, 1);       } else         seg_upd(1, n, pos, -1);       if (seg[seg_idx(1, n)].val <= 0)         puts( -1 );       else         printf( %d n , a[seg_que(1, n)]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   bool judge(string& s, string& t) {     auto f = [](string& x, vector<int>& cnt) {       ll res = 0;       for (char c : x) {         int v = c -  a ;         for (int i = v + 1; i < 26; i++) res += cnt[i];         cnt[v]++;       }       return res;     };     vector<int> vecS(26);     vector<int> vecT(26);     int nums = f(s, vecS), numt = f(t, vecT);     return (nums % 2 == numt % 2 ||             *max_element(vecS.begin(), vecS.end()) >= 2) &&            vecS == vecT;   }   int main() {     int q;     cin >> q;     while (q--) {       int n;       cin >> n;       string s, t;       cin >> s >> t;       cout << (judge(s, t) ?  YES  :  NO ) << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int i, j, n, m, k;   int main() {     scanf( %d , &n);     if (n <= 2) {       printf( %d n , -1);     } else {       printf( %d n , 35);       printf( %d n , 77);       for (i = 1; i <= n - 2; i++) printf( %d n , i * 55);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-9;   long long read() {     long long x = 0;     long long f = 1;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) f = -f;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       x = x * 10 + c -  0 ;       c = getchar();     }     x *= f;     return x;   }   long long n, m;   struct matrix {     long long s[315][315];     void inti() {       for (int i = 1; i <= n; i++)         for (int j = 1; j <= n; j++) s[i][j] = -0x3f3f3f3f;       return;     }     matrix operator*(matrix b) const {       matrix f;       f.inti();       for (int k = 1; k <= n; k++)         for (int i = 1; i <= n; i++)           for (int j = 1; j <= n; j++)             f.s[i][j] = max(f.s[i][j], s[i][k] + b.s[k][j]);       return f;     }   } t[10], now, p;   int main() {     n = read(), m = read();     t[0].inti();     for (int i = 1; i <= n; i++) t[0].s[i][i] = 0;     for (int i = 1; i <= m; i++) {       long long u = read(), v = read();       t[0].s[u][v] = read();       t[0].s[v][u] = read();     }     for (int i = 1; i < 10; i++) t[i] = t[i - 1] * t[i - 1];     now.inti(), p.inti();     for (int i = 1; i <= n; i++) now.s[i][i] = 0;     long long ans = 0;     for (int i = 10 - 1; ~i; i--) {       p = now * t[i];       bool flag = 0;       for (int j = 1; j <= n; j++)         if (p.s[j][j] > 0) {           flag = 1;           break;         }       if (flag) continue;       ans += (1 << i), now = p;     }     if (ans > n)       puts( 0 );     else       printf( %lld , ans + 1);   }


#include <bits/stdc++.h>   int S, T, n, m, l, vol[200020];   int dis[400040], pos[400040], q[400040 * 2];   int E, u[200020], v[200020], go[400040], to[400040];   void AE(int s, int t) {     to[++E] = t;     v[s] = u[s] ? go[v[s]] = E : u[s] = E;   }   int spfa(int maxq) {     register int i, j, k, top, tail;     memset(dis, 0x7f, sizeof(dis));     memset(pos, 0, sizeof(pos));     q[1] = S;     dis[S] = top = 0;     pos[S] = tail = 1;     while (++top <= tail) {       i = q[top];       if (dis[i] < maxq)         for (j = u[i]; j; j = go[j]) {           int tmp = vol[to[j]] ? 0 : dis[i] + 1;           if (dis[to[j]] > tmp) {             dis[to[j]] = tmp;             if (!pos[to[j]]) {               q[++tail] = to[j];               pos[to[j]] = 1;             }           }         }       pos[i] = 0;     }     return dis[T] < 0x7f7f7f7f;   }   int main() {     register int i, j, k;     scanf( %d%d%d , &n, &m, &l);     for (i = 1; i <= l; i++) {       scanf( %d , &k);       vol[k] = 1;     }     for (i = 1; i <= m; i++) {       scanf( %d%d , &j, &k);       AE(j, k);       AE(k, j);     }     scanf( %d%d , &S, &T);     int l = 1, r = n, m, ans = -1;     while (l <= r) {       m = l + r + 1 >> 1;       if (spfa(m)) {         ans = m;         r = m - 1;       } else         l = m + 1;     }     printf( %d n , ans < 0 ? -1 : ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int counts = 0, counts2 = 0;     for (int i = 0; i < n; ++i) {       int a, b;       cin >> a >> b;       if (a < 0)         counts++;       else         counts2++;     }     if (counts <= 1 || counts2 <= 1)       cout <<  Yes ;     else       cout <<  No ;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 205, inf = 1 << 27;   int g[maxn][maxn], g1[maxn][maxn];   int qq[maxn], h, t, n, dis[maxn];   char col[maxn];   int aa[maxn], dd[maxn], x[maxn], bb[maxn], l;   int find_min() {     int i, ind, ind1, ans;     ind = 1;     for (i = 2; i <= n; i++) {       if (aa[i] > aa[ind] || aa[i] == aa[ind] && x[i] > x[ind]) {         ind = i;       }     }     ans = aa[ind];     while (x[ind] < l) {       ind1 = -1;       for (i = 1; i <= n; i++) {         if (x[i] + dd[i] > x[ind] + dd[ind] &&             (ind1 == -1 || aa[i] > aa[ind1] ||              aa[i] == aa[ind1] && dd[i] > dd[ind1])) {           ind1 = i;         }       }       if (ind1 == -1) break;       ans = min(ans, (x[ind] + dd[ind] + aa[ind1]) / 2);       ind = ind1;     }     return ans;   }   int main() {     int m, i, j, k, a, b, w;     int cur, ans;     scanf( %d %d , &n, &m);     for (i = 0; i < m; i++) {       scanf( %d %d %d , &a, &b, &w);       g[a][b] = g[b][a] = 2 * w;     }     for (i = 1; i <= n; i++) {       for (j = i + 1; j <= n; j++) {         g1[i][j] = g1[j][i] = (g[i][j] ? g[i][j] : inf);       }     }     for (k = 1; k <= n; k++) {       for (i = 1; i <= n; i++) {         for (j = 1; j <= n; j++) {           g1[i][j] = min(g1[i][j], g1[i][k] + g1[k][j]);         }       }     }     ans = inf;     for (i = 1; i <= n; i++) {       cur = 0;       for (j = 1; j <= n; j++) {         cur = max(cur, g1[i][j]);       }       ans = min(ans, cur);     }     for (i = 1; i <= n; i++) {       for (j = i + 1; j <= n; j++) {         if (!g[i][j]) continue;         cur = 0;         l = g[i][j];         for (k = 1; k <= n; k++) {           aa[k] = g1[i][k];           bb[k] = g1[j][k];           x[k] = (bb[k] + l - aa[k]) / 2;           dd[k] = aa[k] + x[k];         }         cur = find_min();         ans = min(ans, cur);       }     }     printf( %d.%d , ans / 2, 5 * (ans % 2));   }


#include <bits/stdc++.h>   using namespace std;   const int MAX_H = 100;   const int MAX_W = 100;   char s[MAX_W + 4];   int main() {     int h, w;     scanf( %d%d , &h, &w);     for (int y = 0; y < h; y++) scanf( %s , s);     int c = 0;     for (int i = 0; i < w;) {       while (i < w && s[i] ==  . ) i++;       if (i >= w) break;       while (i < w && s[i] ==  B ) i++;       c++;     }     printf( %d n , c);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 10000;   int n;   set<pair<int, int> > a;   set<pair<int, int> >::iterator it;   pair<int, int> b[MAX];   void dive(int s, int e) {     if (e - s == 1) return;     int mid = s + e;     mid /= 2;     dive(s, mid);     dive(mid, e);     for (int i = s; i < e; i++) a.insert(make_pair(b[mid].first, b[i].second));   }   int main() {     cin >> n;     int x, y;     for (int i = 0; i < n; i++) {       cin >> b[i].first >> b[i].second;       a.insert(b[i]);     }     sort(b, b + n);     dive(0, n);     cout << a.size() << endl;     for (it = a.begin(); it != a.end(); it++)       cout << it->first <<     << it->second << endl;     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   int min(int a, int b) {     if (a < b) return a;     return b;   }   double min(double a, double b) {     if (a < b) return a;     return b;   }   int max(int a, int b) {     if (a > b) return a;     return b;   }   int ABS(int a) {     if (a < 0) return -a;     return a;   }   int parent[100004], h[100005];   void make_set(int v) { parent[v] = v; }   int find_set(int v) {     if (v == parent[v]) return v;     return parent[v] = find_set(parent[v]);   }   void union_sets(int a, int b) {     a = find_set(a);     b = find_set(b);     if (a != b) {       if (h[a] > h[b]) swap(a, b);       parent[b] = a;     }   }   pair<int, int> getCharHash(int p1, int p2, char c) {     return make_pair(p1 * (c -  a ), p2 * (c -  a ));   }   vector<pair<int, int> > p;   int double_area(int x1, int y1, int x2, int y2, int x3, int y3) {     return (x1 - x2) * (y2 + y1) + (x2 - x3) * (y3 + y2) + (x3 - x1) * (y1 + y3);   }   int tree[4000000];   int c[1000004];   int pref_xors[1000004];   int next_pos[1000004];   int pref_unique_xors[1000006];   map<int, int> M;   set<int> uniques;   vector<pair<pair<int, int>, int> > q;   vector<pair<int, int> > ans;   int suf_sum(int l, int r, int nl, int nr, int node) {     if (l == nl && r == nr) {       return tree[node];     }     int m = (nr + nl) / 2;     if (r <= m) {       return suf_sum(l, r, nl, m, node * 2);     }     if (l > m) {       return suf_sum(l, r, m + 1, nr, node * 2 + 1);     }     return suf_sum(l, m, nl, m, node * 2) ^            suf_sum(m + 1, r, m + 1, nr, node * 2 + 1);   }   void update(int l, int r, int node, int pos, int value) {     if (l == r) {       tree[node] ^= value;       return;     }     int m = (l + r) / 2;     if (pos <= m) {       update(l, m, node * 2, pos, value);     } else {       update(m + 1, r, node * 2 + 1, pos, value);     }     tree[node] = tree[node * 2] ^ tree[node * 2 + 1];     return;   }   int XOR(int i, int j) {     if (i == 0) {       return pref_xors[j];     }     return pref_xors[j] ^ pref_xors[i - 1];   }   int main() {     int n;     int p = 1;     scanf( %d , &n);     while (p <= n) p *= 2;     for (int i = 0; i < n; ++i) {       scanf( %d , c + i);       if (i == 0)         pref_xors[0] = c[0];       else         pref_xors[i] = pref_xors[i - 1] ^ c[i];     }     for (int i = n - 1; i >= 0; --i) {       if (M[c[i]]) {         next_pos[i] = M[c[i]];       } else {         next_pos[i] = n;       }       M[c[i]] = i;     }     int m;     scanf( %d , &m);     int a, b;     for (int i = 0; i < m; ++i) {       scanf( %d%d , &a, &b);       a--;       b--;       q.push_back(make_pair(make_pair(a, b), i));     }     sort(q.begin(), q.end());     for (int i = q[0].first.first; i < n; ++i) {       if (i == 0) {         pref_unique_xors[0] = c[0];         uniques.insert(c[0]);       } else {         if (uniques.find(c[i]) != uniques.end()) {           pref_unique_xors[i] = pref_unique_xors[i - 1];         } else {           pref_unique_xors[i] = pref_unique_xors[i - 1] ^ c[i];           uniques.insert(c[i]);         }       }     }     int j = q[0].first.first;     for (int i = 0; i < m; ++i) {       a = q[i].first.first;       b = q[i].first.second;       if (a != j) {         for (int k = j; k < a; ++k) {           update(0, p - 1, 1, next_pos[k], c[k]);         }         j = a;       }       int answer =           XOR(a, b) ^ pref_unique_xors[b] ^ suf_sum(b + 1, p - 1, 0, p - 1, 1);       ans.push_back(make_pair(q[i].second, answer));     }     sort(ans.begin(), ans.end());     for (int i = 0; i < m; ++i) {       printf( %d n , ans[i].second);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long k, a, b;     cin >> k >> a >> b;     if (k == 1) {       cout << a + b << endl;       return 0;     }     long long ret = (a / k) + (b / k);     long long la = a % k, lb = b % k;     if ((la / (k - 1) + (la % (k - 1) > 0)) <= b / k &&         (lb / (k - 1) + (lb % (k - 1) > 0)) <= a / k)       cout << ret << endl;     else       cout << -1 << endl;   }