#include <bits/stdc++.h>   using namespace std;   long long p[222222];   long long sum[222222];   long long max1[222222];   long long max2[222222];   long long get(long long l, long long r) {     long long t = sum[r];     if (l >= 1) {       t -= sum[l - 1];     }     return t;   }   int main() {     long long n, k;     cin >> n >> k;     for (long long i = 0; i < n; i++) {       cin >> p[i];       if (i) {         sum[i] = sum[i - 1] + p[i];       } else {         sum[i] = p[i];       }     }     for (long long i = 0; i < n; i++) {       if (i < k - 1) {         max1[i] = 0;       } else {         max1[i] = max(max1[i - 1], get(i + 1 - k, i));       }     }     long long b = -1;     for (long long i = 0; i < n; i++) {       if (i < 2 * k - 1) {         max2[i] = 0;       } else {         max2[i] = max(max2[i - 1], get(i + 1 - k, i) + max1[i - k]);         ;       }     }     long long i = n - 1;     while (i >= 0) {       if (max2[i - 1] >= get(i + 1 - k, i) + max1[i - k]) {         i--;       } else {         b = i + 1 - k;         break;       }     }     long long se = max2[n - 1] - get(b, b + k - 1);     for (long long i = 0; i < n; i++) {       if (get(i, i + k - 1) == se) {         cout << i + 1 <<    ;         cout << b + 1 <<   n ;         return 0;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long maxn = 9223000000000000000;   struct DATA {     long long v;     long long c;     long double p;   };   long long n, l;   DATA data[31];   bool cmp(DATA x, DATA y) { return x.p < y.p; }   void init() {     scanf( %lld%lld , &n, &l);     for (int i = 1; i <= n; i++) {       scanf( %lld , &data[i].c);       data[i].v = pow(2, i - 1);       data[i].p = (long double)data[i].c / data[i].v;     }     sort(data + 1, data + n + 1, cmp);   }   long long process(long long left) {     long long ans = maxn;     if (left == 0) return 0;     for (int i = 1; i <= n; i++) {       if (data[i].v >= left) ans = min(ans, data[i].c);     }     int id = -1;     for (int i = 1; i <= n; i++)       if (data[i].v < left) {         id = i;         break;       }     if (id != -1) {       long long sum = 0;       long long k = left / data[id].v;       sum = k * data[id].c + process(left - k * data[id].v);       ans = min(ans, sum);     }     return ans;   }   int main() {     init();     printf( %lld , process(l));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using uint = unsigned int;   using ll = long long;   using ld = long double;   using ull = unsigned long long;   using pii = pair<int, int>;   using pll = pair<ll, ll>;   template <typename T1, typename T2>   ostream &operator<<(ostream &out, const pair<T1, T2> &item) {     out <<  (  << item.first <<  ,   << item.second <<  ) ;     return out;   }   template <typename T>   ostream &operator<<(ostream &out, const vector<T> &v) {     for (const auto &item : v) out << item <<    ;     return out;   }   int x[2][2], y[2][2];   void mul(int a[2][2], int b[2][2], int c[2][2], int mod) {     for (int i = 0; i < 2; ++i)       for (int j = 0; j < 2; ++j)         c[i][j] = (1LL * a[i][0] * b[0][j] + 1LL * a[i][1] * b[1][j]) % mod;   }   void pw(ll exp, int mod) {     int aux[2][2];     y[0][0] = y[1][1] = 1 % mod;     y[0][1] = y[1][0] = 0;     for (; exp; exp >>= 1) {       if (exp & 1) {         mul(x, y, aux, mod);         memcpy(y, aux, sizeof aux);       }       mul(x, x, aux, mod);       memcpy(x, aux, sizeof aux);     }   }   int fib(ll n, int mod) {     if (n <= 2) return 1 % mod;     x[0][0] = 0;     x[0][1] = x[1][0] = x[1][1] = 1 % mod;     pw(n - 1, mod);     return (y[0][0] + y[1][0]) % mod;   }   ll l, r, k;   ll collect(ll n) {     if (n == 0) return 0;     ll kk, res = 0;     for (ll x = 1; x * x <= n; ++x) {       if (r / x - (l - 1) / x >= k) res = max(res, x);       kk = n / x;     }     for (; kk; --kk) {       ll x = n / kk;       if (r / x - (l - 1) / x >= k) res = max(res, x);     }     return res;   }   int main() {     ios_base::sync_with_stdio(false);     ll mod;     cin >> mod >> l >> r >> k;     ll ans = collect(l - 1);     ans = max(ans, collect(r));     cout << fib(ans, mod) <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     scanf( %d , &t);     while (t--) {       int n;       scanf( %d , &n);       long long a[100001];       long long y = 0;       long long thissum = 0, maxsum = 0;       int count = 1;       for (int i = 0; i < n; i++) {         scanf( %lld , &a[i]);         y += a[i];       }       thissum = a[0];       maxsum = a[0];       int temp = 1;       for (int i = 1; i < n; i++) {         if (thissum > 0) {           thissum += a[i];           temp++;         } else {           thissum = a[i];           temp = 1;         }         if (thissum > maxsum) {           maxsum = thissum;           count = temp;         }       }       int flag;       if (y > maxsum) {         flag = 1;       } else {         if (y == maxsum && count == n) {           maxsum = maxsum - min(a[0], a[n - 1]);           if (y > maxsum) {             flag = 1;           } else {             flag = 0;           }         } else {           flag = 0;         }       }       if (flag == 1) {         printf( YES n );       } else {         printf( NO n );       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     int t;     cin >> t;     while (t--) {       long long x, y;       cin >> x >> y;       if (x == y + 1) {         cout <<  NO n ;       } else {         cout <<  YES n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int recpow(long long int base, long long int exp) {     long long int result = 1;     while (exp > 0) {       if (exp & 1) result = ((long long int)result * base) % 1000000007;       base =           ((long long int)(base % 1000000007) * (base % 1000000007)) % 1000000007;       exp >>= 1;     }     return (result % 1000000007);   }   bool comp(const pair<long long int, long long int>& a,             const pair<long long int, long long int>& b) {     return ((a.first == b.first and a.second > b.second) or a.first < b.first);   }   bool chk(long long int p, vector<pair<long long int, long long int>>& v) {     int n = v.size();     long long int i = 0;     while (i < n) {       if (p < v[i].first) return 0;       p += v[i].second;       i++;     }     return 1;   }   int main() {     ios_base ::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int tc = 1;     while (tc--) {       long long int n, m;       cin >> n >> m;       vector<long long int> dp(n + 1, 0), pref(n + 1, 0);       dp[1] = 1, pref[1] = 1;       for (long long int i = 2; i < n + 1; i++) {         dp[i] = (dp[i] + pref[i - 1]) % m;         for (long long int j = 1; j * j <= i; ++j) {           long long int tmp = i / j - i / (j + 1);           dp[i] = (dp[i] + (tmp * dp[j]) % m) % m;         }         for (long long int j = 2; j * j <= i; ++j) {           long long int tmp = i / j;           if (tmp * tmp > i) {             dp[i] = (dp[i] + dp[tmp]) % m;           }         }         pref[i] = (pref[i - 1] + dp[i]) % m;       }       cout << dp[n] <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e5 + 10;   int N;   vector<int> adj[MAXN];   map<int, int> dp[MAXN];   int cid;   map<vector<int>, int> idmp;   int getid(vector<int> v) {     if (idmp.count(v)) {       return idmp[v];     }     return idmp[v] = cid++;   }   int dfs(int x, int p);   vector<int> getv(int x, int p) {     vector<int> v;     for (int y : adj[x]) {       if (y == p) {         continue;       }       v.push_back(dfs(y, x));     }     sort((v).begin(), (v).end());     return v;   }   int dfs(int x, int p) {     if (dp[x].count(p)) {       return dp[x][p];     }     return dp[x][p] = getid(getv(x, p));   }   int main() {     idmp[vector<int>()] = cid++;     scanf( %d , &N);     for (int i = 1; i < N; i++) {       int a, b;       scanf( %d %d , &a, &b);       adj[a].push_back(b);       adj[b].push_back(a);     }     for (int i = 1; i <= N; i++) {       for (int j : adj[i]) {         dfs(j, i);       }     }     set<vector<int>> st;     for (int i = 1; i <= N; i++) {       if (adj[i].size() < 4) {         st.insert(getv(i, -1));       }     }     printf( %lu n , st.size());   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);     int t = 1;     while (t--) {       int n;       cin >> n;       map<int, vector<int>> m;       vector<int> v(n);       for (int i = 0; i < n; i++) {         cin >> v[i];         m[v[i]].push_back(i);       }       vector<pair<int, int>> res;       for (auto p : m) {         vector<int> tmp = p.second;         if (tmp.size() == 1) {           res.push_back(make_pair(p.first, 0));           continue;         }         int d = tmp[1] - tmp[0];         int flag = 0;         for (int i = 1; i < tmp.size() - 1; i++) {           int curr = tmp[i + 1] - tmp[i];           if (curr != d) {             flag = 1;             break;           }         }         if (flag == 1) {           continue;         }         res.push_back(make_pair(p.first, d));       }       sort((res).begin(), (res).end());       cout << res.size() << endl;       for (auto p : res) {         cout << p.first <<     << p.second << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct Point {     double x, y;     Point() {}     Point(double x, double y) : x(x), y(y) {}     Point operator+(const Point& other) const {       return {x + other.x, y + other.y};     }     Point operator-(const Point& other) const {       return {x - other.x, y - other.y};     }     Point operator*(double c) const { return {x * c, y * c}; }     double len() const { return sqrt(x * x + y * y); }     bool operator<(const Point& other) const {       if (x != other.x) {         return x < other.x;       }       return y < other.y;     }     double sqrlen() const { return x * x + y * y; }   };   int n, m;   vector<Point> red, blue;   double det(const Point& a, const Point& b, const Point& c) {     return (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x);   }   double dist(const Point& a, const Point& b) { return (b - a).len(); }   ostream& operator<<(ostream& cout, const Point& a) {     cout << a.x <<     << a.y;     return cout;   }   vector<Point> convex_hull(vector<Point>& v) {     sort(v.begin(), v.end());     vector<Point> ch;     int st[2010];     int k = 0;     for (int i = 0; i < v.size(); ++i) {       while (k > 1 && det(v[st[k - 1]], v[st[k]], v[i]) <= 0) --k;       st[++k] = i;     }     for (int i = 1; i <= k; ++i) {       ch.push_back(v[st[i]]);     }     k = 0;     for (int i = v.size() - 1; i >= 0; --i) {       while (k > 1 && det(v[st[k - 1]], v[st[k]], v[i]) <= 0) --k;       st[++k] = i;     }     for (int i = 2; i < k; ++i) {       ch.push_back(v[st[i]]);     }     return ch;   }   Point inverse(const Point& a, const Point& b) {     Point c = b + (a - b) * (1 / (a - b).sqrlen());     return c;   }   double check(int bi) {     auto inv_blue = blue;     inv_blue.erase(inv_blue.begin() + bi);     for (auto& p : inv_blue) {       p = inverse(p, blue[bi]);     }     auto inv_red = red;     for (auto& p : inv_red) {       p = inverse(p, blue[bi]);     }     inv_blue = convex_hull(inv_blue);     if (inv_blue.size() == 0) {       return -1;     }     double closest = 1e20;     if (inv_blue.size() > 1) {       for (int i = 0; i < inv_blue.size(); ++i) {         int ii = (i + 1) % inv_blue.size();         int iii = (i + 2) % inv_blue.size();         double poly_det = det(inv_blue[i], inv_blue[ii], inv_blue[iii]);         double my_det = det(inv_blue[i], inv_blue[ii], blue[bi]);         if (poly_det * my_det < 0) continue;         for (int j = 0; j < inv_red.size(); ++j) {           if (poly_det * det(inv_blue[i], inv_blue[ii], inv_red[j]) <= 0) {             double d = fabs(my_det) / dist(inv_blue[i], inv_blue[ii]);             closest = min(closest, d);             break;           }         }       }     }     for (int i = 0; i < inv_blue.size(); ++i) {       int li = (i - 1 + inv_blue.size()) % inv_blue.size();       int ii = (i + 1) % inv_blue.size();       for (int j = 0; j < inv_red.size(); ++j) {         double poly_det = det(inv_blue[i], inv_red[j], inv_blue[ii]);         double l_poly_det = det(inv_blue[i], inv_red[j], inv_blue[li]);         double my_det = det(inv_blue[i], inv_red[j], blue[bi]);         if (l_poly_det * poly_det >= 0) {           if (my_det * poly_det <= 0 && my_det * l_poly_det <= 0) {             closest = 0;           } else {             double d = fabs(my_det) / dist(inv_blue[i], inv_red[j]);             closest = min(closest, d);           }         }       }     }     if (closest == 1e20) {       return 0;     } else if (closest == 0) {       return -1;     } else {       return 1 / (closest * 2);     }   }   void read(int n, vector<Point>& v) {     for (int i = 1; i <= n; ++i) {       int x, y;       cin >> x >> y;       v.push_back(Point(x, y));     }   }   void solve() {     cin >> n >> m;     read(n, red);     read(m, blue);     double ans = 0;     for (int i = 0; i < m; ++i) {       double cans = check(i);       if (cans == -1) {         cout << -1 <<   n ;         return;       } else {         ans = max(ans, cans);       }     }     cout << fixed << setprecision(9) << ans <<   n ;   }   void reset() {     red.clear();     blue.clear();   }   int main() {     int k = 1;     for (; k <= 1; ++k) {       reset();       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   namespace Flandre_Scarlet {   long long mod;   class Matrix {    private:     long long a[5][5];       public:     long long n;     Matrix() {       memset(a, 0, sizeof(a));       n = 0;     }     Matrix(long long _n) {       memset(a, 0, sizeof(a));       n = _n;     }     Matrix(long long _n, long long _x) {       _x %= mod;       n = _n;       for (long long i = 0; i < 5; ++i) {         for (long long j = 0; j < 5; ++j) {           a[i][j] = _x;         }       }     }     long long* operator[](long long i) { return *(a + i); }     void Set(long long x) {       x %= mod;       for (long long i = 0; i < 5; ++i) {         for (long long j = 0; j < 5; ++j) {           a[i][j] = x;         }       }     }     void Identity() {       memset(a, 0, sizeof(a));       for (long long i = 0; i < 5; ++i) {         a[i][i] = 1;       }     }   };   Matrix operator*(Matrix x, Matrix y) {     Matrix ans(x.n, 0);     long long n = ans.n;     for (long long i = 1; i <= n; ++i) {       for (long long j = 1; j <= n; ++j) {         for (long long k = 1; k <= n; ++k) {           ans[i][j] += x[i][k] * y[k][j];           ans[i][j] %= mod;         }       }     }     return ans;   }   Matrix operator^(Matrix x, long long p) {     Matrix ans(x.n, 1);     ans.Identity();     while (p) {       if (p & 1) ans = ans * x;       x = x * x, p >>= 1;     }     return ans;   }   long long Fib(long long x) {     Matrix Init(2, 0);     Init[1][1] = 0, Init[1][2] = 1;     Matrix Trans(2, 1);     Trans[1][1] = 0;     Matrix Ans = Init * (Trans ^ x);     return Ans[1][1];   }   long long l, r, k;   void R1(long long& x) {     x = 0;     char c = getchar();     long long f = 1;     while (c <  0  or c >  9 ) f = (c ==  - ) ? -1 : 1, c = getchar();     while (c >=  0  and c <=  9 )       x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();     x = (f == 1) ? x : -x;   }   void Input() {     R1(mod);     R1(l), R1(r), R1(k);   }   bool cxk(long long x) { return (r / x - (l - 1) / x) >= k; }   void Soviet() {     long long ans = -0x3f3f3f3f;     for (long long i = 1; i * i <= r; ++i) {       if (cxk(i)) ans = max(ans, i);       if (cxk(r / i)) ans = max(ans, r / i);     }     printf( %lld n , Fib(ans));   }   void IsMyWife() {     Input();     Soviet();   }   }  // namespace Flandre_Scarlet   int main() {     Flandre_Scarlet::IsMyWife();     getchar();     getchar();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int grid[201][201]{0};   int main() {     string s;     cin >> s;     int x = 100;     int y = 100;     grid[x][y] = true;     for (auto& it : s) {       switch (it) {         case  L :           x--;           break;         case  R :           x++;           break;         case  U :           y--;           break;         case  D :           y++;       }       if (grid[x][y] || (it !=  L  && grid[x + 1][y]) ||           (it !=  R  && grid[x - 1][y]) || (it !=  U  && grid[x][y + 1]) ||           (it !=  D  && grid[x][y - 1])) {         cout <<  BUG  << endl;         return 0;       }       grid[x][y] = true;     }     cout <<  OK  << endl;   }


#include <bits/stdc++.h>   using namespace std;   int n, _m, ans = 0;   map<string, int> m;   string s[1010], u[1010], v[1010];   int main() {     cin >> n >> _m;     for (int i = 1; i <= n; i++) cin >> s[i];     sort(s + 1, s + n + 1);     for (int i = 1; i <= n; i++) m[s[i]] = i - 1;     for (int i = 1; i <= _m; i++) cin >> u[i] >> v[i];     for (int i = 1; i <= (1 << n); i++) {       bool flag = 1;       for (int j = 1; j <= _m; j++)         if (((i - 1) & (1 << m[u[j]])) && ((i - 1) & (1 << m[v[j]]))) flag = 0;       if (flag && __builtin_popcount(ans) < __builtin_popcount(i - 1))         ans = i - 1;     }     cout << __builtin_popcount(ans) <<   n ;     for (int i = 1; i <= n; i++)       if (ans & (1 << (i - 1))) cout << s[i] <<   n ;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O2 )   using namespace std;   const int N = 1e5 + 1;   vector<int> co[N];   long long ans = 0;   void dfs(int x, int p) {     ans += (int)co[x].size() * ((int)co[x].size() - 1) / 2;     for (auto y : co[x]) {       if (y == p) continue;       dfs(y, x);     }   }   int main() {     cin.tie(0);     cout.tie(0);     ios::sync_with_stdio(0);     int n;     cin >> n;     for (int i = 0; i < n - 1; i++) {       int a, b;       cin >> a >> b;       co[a].push_back(b);       co[b].push_back(a);     }     dfs(1, 0);     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   int n;   vector<double> first, second;   double eps = 0.0000001;   double ai;   int main() {     std::ios::sync_with_stdio(false);     cin >> n;     for (int i = 0; i < n; i++) {       cin >> ai;       first.push_back(ai);     }     for (int i = 0; i < n; i++) {       cin >> ai;       second.push_back(ai);     }     double s1 = 0;     double s2 = 0;     vector<double> a1, a2;     for (int i = 0; i < n; i++) {       double x = first[i];       double y = second[i];       double a = 1;       double b = -(s1 + x + y - s2);       double c = -(x * s2 + y * s2 - x);       double disc = b * b - 4 * a * c;       if (disc >= -eps && disc < 0) {         disc = 0;       }       disc = sqrt(disc);       double k1 = (-b + disc) / 2;       double k2 = (-b - disc) / 2;       double nn = 0;       if (k1 <= k2) swap(k1, k2);       if (k1 >= -eps && k1 <= x + y + eps) {         s2 += max(k1, nn);         s1 += max(nn, x + y - k1);         a2.push_back(max(k1, nn));         a1.push_back(max(nn, x + y - k1));       } else {         s2 += max(k2, nn);         s1 += max(nn, x + y - k2);         a2.push_back(max(k2, nn));         a1.push_back(max(nn, x + y - k2));       }     }     cout.precision(25);     for (int i = 0; i < n; i++) {       cout << a1[i] <<    ;     }     cout << endl;     for (int i = 0; i < n; i++) {       cout << a2[i] <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, c[8005][8005], fal[8005], dp[8005], len[8005];   char s[8005];   void Init(char *s, int n, int *c) {     fal[1] = 0, fal[2] = 1;     for (int i = 2; i <= n; i++) {       int j = fal[i];       while (j && s[i] != s[j]) j = fal[j];       fal[i + 1] = j + 1;     }     for (int i = 1; i <= n; i++) {       int t = 1, k = i - fal[i + 1] + 1;       if (i % k == 0) t = i / k;       c[i] = i / t + len[t];     }   }   int main() {     scanf( %s , s + 1), n = strlen(s + 1);     for (int i = 1; i <= n; i++) len[i] = len[i / 10] + 1;     for (int i = 1; i <= n; i++) Init(s + i - 1, n - i + 1, c[i] + i - 1);     for (int i = 1; i <= n; i++) {       dp[i] = n + 1;       for (int j = 1; j <= i; j++) dp[i] = min(dp[i], dp[j - 1] + c[j][i]);     }     printf( %d n , dp[n]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 10;   const long long MOD = 1e9 + 7;   long long h[26][N], p[N];   int a[30], b[30];   char s[N + 10];   long long get(int i, int l, int r) {     return (h[i][r] - h[i][l - 1] * p[r - l + 1]) % MOD;   }   int main() {     int n, m, x, y, len;     while (scanf( %d%d , &n, &m) != EOF) {       p[0] = 1;       for (int i = 1; i <= n; i++) p[i] = (p[i - 1] * 2) % MOD;       scanf(  %s , s + 1);       for (int i = 0; i < 26; i++)         for (int j = 1; j <= n; j++)           h[i][j] = (h[i][j - 1] * 2 + (s[j] ==  a  + i)) % MOD;       while (m--) {         scanf( %d%d%d , &x, &y, &len);         for (int i = 0; i < 26; i++) {           a[i] = (get(i, x, x + len - 1) + MOD) % MOD;           b[i] = (get(i, y, y + len - 1) + MOD) % MOD;         }         sort(a, a + 26);         sort(b, b + 26);         bool flag = true;         for (int i = 0; i < 26; i++)           if (a[i] != b[i]) {             flag = false;             break;           }         printf( %s n , flag ?  YES  :  NO );       }     }   }


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


#include <bits/stdc++.h>   using namespace std;   const int MAX_NM = 1000 * 1000;   int dl;   char S[MAX_NM];   void dodaj(char l, int x) {     while (x--) {       dl++;       S[dl] = l;     }   }   int main() {     int n, m, k;     cin >> n >> m >> k;     if (k > 4 * n * m - 2 * n - 2 * m) {       cout <<  NO n ;       return 0;     }     for (int i = 1; i < m; i++) {       dodaj( D , n - 1);       dodaj( U , n - 1);       dodaj( R , 1);     }     dodaj( D , n - 1);     for (int i = n; i > 1; i--) {       dodaj( L , m - 1);       dodaj( R , m - 1);       dodaj( U , 1);     }     dodaj( L , m - 1);     vector<pair<char, int> > w;     char l = S[1];     int a = 1;     for (int i = 2; i <= k; i++) {       if (S[i] != S[i - 1]) {         w.push_back(make_pair(l, a));         l = S[i];         a = 1;       } else {         a++;       }     }     w.push_back(make_pair(l, a));     cout <<  YES  << endl;     cout << w.size() << endl;     for (pair<char, int> p : w) {       cout << p.second <<     << p.first << endl;     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast,unroll-loops )   #pragma GCC target( avx,avx2,fma )   using namespace std;   const long long mod1 = 998244353;   const long long mod = 1e9 + 7;   long long mod_mul(long long a, long long b) {     a = a % mod;     b = b % mod;     return (((a * b) % mod) + mod) % mod;   }   long long inv(long long i) {     if (i == 1) return 1;     return (mod - ((mod / i) * inv(mod % i)) % mod) % mod;   }   long long gcd(long long a, long long b) {     if (b == 0) return a;     return gcd(b, a % b);   }   long long pwr(long long a, long long b) {     a %= mod;     long long res = 1;     while (b > 0) {       if (b & 1) res = res * a % mod;       a = a * a % mod;       b >>= 1;     }     return res;   }   long long findMinNumber(long long n) {     long long count = 0, ans = 1;     while (n % 2 == 0) {       count++;       n /= 2;     }     if (count % 2) ans *= 2;     for (int i = 3; i <= sqrt(n); i += 2) {       count = 0;       while (n % i == 0) {         count++;         n /= i;       }       if (count % 2) ans *= i;     }     if (n > 2) ans *= n;     return ans;   }   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long t;     cin >> t;     while (t--) {       long long n, k, i, j;       cin >> n >> k;       map<long long, long long> m;       vector<long long> ans;       vector<pair<long long, long long> > v;       long long a[k][2];       for (i = 0; i < k; i++) {         cin >> a[i][0] >> a[i][1];         v.push_back({a[i][0], a[i][1]});         m[a[i][0]]++;         m[a[i][1]]++;       }       for (i = 1; i < 2 * n + 1; i++)         if (m[i] == 0) ans.push_back(i);       for (i = 0; i < ans.size() / 2; i++) {         v.push_back({ans[i], ans[ans.size() / 2 + i]});       }       long long cnt = 0;       sort((v).begin(), (v).end());       for (i = 0; i < n; i++) {         for (j = 0; j < n; j++) {           if (i != j) {             long long x = (v[i].second - v[j].first) * (v[i].first - v[j].first);             long long y =                 (v[i].second - v[j].second) * (v[i].first - v[j].second);             if (x * y < 0) {               cnt++;             }           }         }       }       cout << cnt / 2 <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, f[50010];   struct node {     int f[12], g[12], size;   } a[50010];   struct cmp {     bool operator()(node a, node b) {       for (int i = 1; i <= m; i++)         if (a.f[i] > b.g[i]) return 0;       return 1;     }   };   multiset<node, cmp> q;   inline void up(node &a, node b) {     for (int i = 1; i <= m; i++)       a.f[i] = max(a.f[i], b.f[i]), a.g[i] = min(a.g[i], b.g[i]);     a.size += b.size;   }   inline bool operator==(node a, node b) {     int t = 0;     for (int i = 1; i <= m; i++) t |= (a.f[i] > b.g[i]) | (2 * (a.g[i] < b.f[i]));     return t == 3;   }   int main() {     cin >> n >> m;     for (int i = 1; i <= n; i++) f[i] = i;     node p1, p2;     for (int i = 1; i <= m; i++) p1.f[i] = p1.g[i] = 0;     for (int i = 1; i <= m; i++) p2.f[i] = p2.g[i] = 1999999999;     q.insert(p1);     q.insert(p2);     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++)         scanf( %d , &a[i].f[j]), a[i].g[j] = a[i].f[j], a[i].size = 1;     for (int i = 1; i <= n; i++) {       set<node>::iterator it = q.lower_bound(a[i]), it2;       while (*it == a[i]) it2 = it, it2--, up(a[i], *it), q.erase(it), it = it2;       it = q.lower_bound(a[i]);       while (*it == a[i]) it2 = it, it2++, up(a[i], *it), q.erase(it), it = it2;       q.insert(a[i]);       printf( %d n , (--(--q.end()))->size);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }   struct State {     int delta;     map<int, int> pos;     map<int, int> neg;     set<pair<int, pair<int, int>>> matches;     void init() {       delta = 0;       pos.clear();       neg.clear();       matches.clear();     }     int findmatchforpos(int x) {       auto it = neg.lower_bound(x + delta);       return it == neg.end() ? INT_MAX : it->first - delta;     }     int findmatchforneg(int y) {       auto it = pos.upper_bound(y - delta);       return it == pos.begin() ? INT_MIN : prev(it)->first + delta;     }     void erasepos(int x) {       assert(pos.erase(x - delta));       int y = findmatchforpos(x);       if (y != INT_MAX) {         int xx = findmatchforneg(y);         if (xx == INT_MIN || xx <= x)           assert(matches.erase(               make_pair(y - x + 2 * delta, make_pair(x - delta, y + delta))));         if (xx != INT_MIN && xx <= x && findmatchforpos(xx) == y)           matches.insert(               make_pair(y - xx + 2 * delta, make_pair(xx - delta, y + delta)));       }     }     void eraseneg(int y) {       assert(neg.erase(y + delta));       int x = findmatchforneg(y);       if (x != INT_MIN) {         int yy = findmatchforpos(x);         if (yy == INT_MAX || yy >= y)           assert(matches.erase(               make_pair(y - x + 2 * delta, make_pair(x - delta, y + delta))));         if (yy != INT_MAX && yy >= y && findmatchforneg(yy) == x)           matches.insert(               make_pair(yy - x + 2 * delta, make_pair(x - delta, yy + delta)));       }     }     void insertpos(int x, int val) {       if (pos.count(x - delta)) {         pos[x - delta] += val;         return;       }       int y = findmatchforpos(x);       if (y != INT_MAX) {         int xx = findmatchforneg(y);         if (xx != INT_MIN && xx < x && findmatchforpos(xx) == y)           assert(matches.erase(               make_pair(y - xx + 2 * delta, make_pair(xx - delta, y + delta))));         if (xx == INT_MIN || xx < x)           matches.insert(               make_pair(y - x + 2 * delta, make_pair(x - delta, y + delta)));       }       pos[x - delta] = val;     }     void insertneg(int y, int val) {       if (neg.count(y + delta)) {         neg[y + delta] += val;         return;       }       int x = findmatchforneg(y);       if (x != INT_MIN) {         int yy = findmatchforpos(x);         if (yy != INT_MAX && yy > y && findmatchforneg(yy) == x)           assert(matches.erase(               make_pair(yy - x + 2 * delta, make_pair(x - delta, yy + delta))));         if (yy == INT_MAX || yy > y)           matches.insert(               make_pair(y - x + 2 * delta, make_pair(x - delta, y + delta)));       }       neg[y + delta] = val;     }     void grow(int by) {       while (((int)(matches).size()) != 0 &&              matches.begin()->first - 2 * delta < 2 * by) {         int x = matches.begin()->second.first + delta,             y = matches.begin()->second.second - delta;         assert(pos.count(x - delta));         int xval = pos[x - delta];         assert(neg.count(y + delta));         int yval = neg[y + delta];         if (xval < yval) {           neg[y + delta] -= xval;           erasepos(x);         } else if (xval > yval) {           pos[x - delta] -= yval;           eraseneg(y);         } else {           erasepos(x);           eraseneg(y);         }       }       delta += by;     }     void print() {       printf(  tneg: );       for (auto it = neg.begin(); it != neg.end(); ++it)         printf(  %d=%d , it->first - delta, it->second);       puts(  );       printf(  tpos: );       for (auto it = pos.begin(); it != pos.end(); ++it)         printf(  %d=%d , it->first + delta, it->second);       puts(  );       printf(  tmatches: );       for (auto it = matches.begin(); it != matches.end(); ++it)         printf(  %d:%d-%d , it->first - 2 * delta, it->second.first + delta,                it->second.second - delta);       puts(  );     }   };   const int MAXN = 100000;   int n;   vector<pair<int, int>> e[MAXN];   int nq;   vector<pair<int, int>> obs[MAXN];   State state[MAXN];   int merge(int a, int b) {     int asz = ((int)(state[a].pos).size()) + ((int)(state[a].neg).size()),         bsz = ((int)(state[b].pos).size()) + ((int)(state[b].neg).size());     if (asz < bsz) swap(a, b), swap(asz, bsz);     for (auto it = state[b].pos.begin(); it != state[b].pos.end(); ++it)       state[a].insertpos(it->first + state[b].delta, it->second);     for (auto it = state[b].neg.begin(); it != state[b].neg.end(); ++it)       state[a].insertneg(it->first - state[b].delta, it->second);     return a;   }   int dfs(int at, int par, int parlen) {     int ret = at;     state[ret].init();     for (int i = (0); i < (((int)(e[at]).size())); ++i) {       int to = e[at][i].first;       if (to == par) continue;       int cur = dfs(to, at, e[at][i].second);       ret = merge(ret, cur);     }     vector<pair<int, int>> extra;     for (int i = (0); i < (((int)(obs[at]).size())); ++i) {       int t = obs[at][i].first, cnt = obs[at][i].second, rem = cnt;       {         int cur = (state[ret].pos.count(t - state[ret].delta)                        ? state[ret].pos[t - state[ret].delta]                        : 0) +                   (state[ret].pos.count(t - state[ret].delta - 1)                        ? state[ret].pos[t - state[ret].delta - 1]                        : 0);         rem = min(rem, max(0, cnt - cur));       }       {         int cur = (state[ret].neg.count(t + state[ret].delta)                        ? state[ret].neg[t + state[ret].delta]                        : 0) +                   (state[ret].neg.count(t + state[ret].delta + 1)                        ? state[ret].neg[t + state[ret].delta + 1]                        : 0);         rem = min(rem, max(0, cnt - cur));       }       if (rem > 0) extra.push_back(make_pair(t, rem));     }     state[ret].grow(1);     for (int i = (0); i < (((int)(extra).size())); ++i) {       int t = extra[i].first, cnt = extra[i].second;       state[ret].insertneg(t - 1, cnt);       state[ret].insertpos(t + 1, cnt);     }     state[ret].grow(parlen - 1);     return ret;   }   int solve() {     for (int i = (0); i < (n); ++i) sort(obs[i].begin(), obs[i].end());     int res = dfs(0, -1, 1);     map<int, int> all;     for (auto it = state[res].pos.begin(); it != state[res].pos.end(); ++it)       all[2 * (it->first + state[res].delta) + 0] -= it->second;     for (auto it = state[res].neg.begin(); it != state[res].neg.end(); ++it)       all[2 * (it->first - state[res].delta) + 1] += it->second;     int ret = 0, cur = 0;     for (auto it = all.begin(); it != all.end(); ++it) {       cur += it->second;       ret = max(ret, cur);     }     return ret;   }   void run() {     scanf( %d , &n);     for (int i = (0); i < (n - 1); ++i) {       int a, b, c;       scanf( %d%d%d , &a, &b, &c);       --a, --b, c *= 2;       e[a].push_back(make_pair(b, c));       e[b].push_back(make_pair(a, c));     }     scanf( %d , &nq);     for (int i = (0); i < (nq); ++i) {       int t, cnt, idx;       scanf( %d%d%d , &t, &cnt, &idx);       t *= 2;       --idx;       obs[idx].push_back(make_pair(t, cnt));     }     printf( %d n , solve());   }   int main() {     run();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string x, t;     getline(cin, x);     string temp =   ;     int index = -1;     for (int i = 0; i < x.size(); ++i) {       if (x[i] ==  = ) index = i;     }     index += 2;     for (int i = index; i < x.size(); ++i) temp.push_back(x[i]);     int n = stoi(temp.c_str());     int pos = 0;     int neg = 0;     int i = 0;     if (x[0] ==  ? ) {       ++pos;       ++i;     } else {       ++neg;       i += 2;     }     for (int i = 0; i < x.size(); ++i)       if (x[i] ==  + )         ++pos;       else if (x[i] ==  - )         ++neg;     vector<int> ne(neg, 1);     vector<int> po(pos, 1);     int sum = (pos * 1) - neg;     int j = 0, z = 0;     bool in = false;     while (1) {       if (sum == n) break;       if (sum > n) {         if (z == neg) {           cout <<  Impossible  << endl;           return 0;         }         if (ne[z] == n) {           ++z;           continue;         }         in = true;         ++ne[z];         sum -= 1;       } else if (sum < n) {         if (j == pos) {           cout <<  Impossible  << endl;           return 0;         }         if (po[j] == n) {           ++j;           continue;         }         in = true;         ++po[j];         sum += 1;       }     }     cout <<  Possible  << endl;     j = 0, z = 0;     string last =   ;     for (int i = 0; i < x.size(); ++i) {       if (x[i] ==  -  || x[i] ==  +  || i == 0) {         if (i > 0) {           if (x[i] ==  - ) {             last.push_back(x[i]);             stringstream ss;             ss << ne[z++];             last += ss.str();             ;           } else {             last.push_back(x[i]);             stringstream ss;             ss << po[j++];             last += ss.str();           }         }         if (i == 0) {           if (x[i] ==  - ) {             last.push_back(x[i]);             stringstream ss;             ss << ne[z++];             last += ss.str();             ;           } else {             stringstream ss;             ss << po[j++];             last += ss.str();           }         }       } else if (x[i] !=  ? )         last.push_back(x[i]);     }     cout << last << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void setIO(string NAME) {}   inline long long gI() {     char c = getchar();     while ((c <  0  || c >  9 ) && c !=  - ) c = getchar();     long long flag = 1, p = 0;     if (c ==  - ) flag = -1, c = getchar();     while (c >=  0  && c <=  9 ) p = p * 10 + (c -  0 ), c = getchar();     return p * flag;   }   int gs(char* C) {     char c = getchar();     while (c ==     || c ==   n ) c = getchar();     int l = 0;     while (c !=     && c !=   n ) C[l++] = c, c = getchar();     C[l] = 0;     return l;   }   template <class T>   void debug(const T a, const int& n) {     for (int i = 0; i < n; ++i) printf( %d%c , a[i], (i == n - 1) ?   n  :    );   }   const int inf = ~0U >> 1, maxn = 100000 + 10;   int n, m;   long long a[maxn];   vector<long long> b[maxn];   int main() {     setIO( test );     n = gI(), m = gI();     long long ans = 0;     for (int i = 0; i < m; ++i) {       a[i] = gI();       if (i) ans += abs(a[i] - a[i - 1]);     }     long long MAX = 0;     for (int i = 0; i < m; ++i) {       if (i && a[i - 1] != a[i]) b[a[i]].push_back(a[i - 1]);       if (i < m - 1 && a[i] != a[i + 1]) b[a[i]].push_back(a[i + 1]);     }     for (int i = 1; i <= n; ++i)       if (b[i].size()) {         sort(b[i].begin(), b[i].end());         int sz = b[i].size();         int m = (sz - 1) / 2;         long long origin = 0, now = 0;         for (int j = 0; j < sz; ++j) {           origin += abs((long long)b[i][j] - i);           now += abs(b[i][j] - b[i][m]);         }         MAX = max(MAX, origin - now);       }     ans -= MAX;     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct ACfixed {     static const int ASZ = 10;     struct node {       array<int, ASZ> to;       int link = -1;       int tlink = -1;       int id = -1;     };     vector<node> d = {{}};     int add(string s, int id) {       int v = 0;       for (auto C : s) {         int c = C -  0 ;         if (!d[v].to[c]) d[v].to[c] = d.size(), d.emplace_back();         v = d[v].to[c];       }       d[v].id = id;       return v;     }     void init() {       d[0].link = -1;       queue<int> q;       q.push(0);       while (q.size()) {         int v = q.front();         q.pop();         for (int c = 0; c < ASZ; c++) {           int u = d[v].to[c];           if (!u) continue;           d[u].link = d[v].link == -1 ? 0 : d[d[v].link].to[c];           d[u].tlink = (d[d[u].link].id == -1) ? d[d[u].link].tlink : d[u].link;           q.push(u);         }         if (v)           for (int c = 0; c < ASZ; c++)             if (!d[v].to[c]) d[v].to[c] = d[d[v].link].to[c];       }     }     vector<vector<int>> getAll(string &word) {       vector<vector<int>> res(d.size(), vector<int>());       int v = 0;       for (int i = 0; i < word.length(); i++) {         v = d[v].to[word[i] -  0 ];         int cur = v;         while (cur >= 0) {           if (d[cur].id != -1) {             res[d[cur].id].push_back(i);           }           cur = d[cur].tlink;         }       }       return res;     }   };   vector<string> arr;   int n, x;   string s;   string curstr =   ;   ACfixed ac;   void gen(int cur) {     if (cur == 0) {       arr.push_back(curstr);       return;     }     for (int i = 1; i <= 9; i++) {       if (i > cur) continue;       curstr.push_back( 0  + i);       int csum = 0;       bool work = true;       for (int j = curstr.size() - 1; j >= 0; j--) {         csum += curstr[j] -  0 ;         if (csum != x && x % csum == 0) {           work = false;           break;         }       }       if (work) gen(cur - i);       curstr.pop_back();     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cin >> s >> x;     n = s.length();     gen(x);     for (int i = 0; i < arr.size(); i++) ac.add(arr[i], i);     ac.init();     vector<int> dp(ac.d.size(), 1000000009);     dp[0] = 0;     for (auto ch : s) {       vector<int> nextdp(ac.d.size(), 1000000009);       for (int state = 0; state < ac.d.size(); state++) {         if (dp[state] == 1000000009) continue;         nextdp[state] = min(nextdp[state], dp[state] + 1);         int trans = ac.d[state].to[ch -  0 ];         if (ac.d[trans].id == -1) nextdp[trans] = min(nextdp[trans], dp[state]);       }       swap(dp, nextdp);     }     cout << *min_element(dp.begin(), dp.end()) << endl;   }


#include <bits/stdc++.h>   using namespace std;   const long long maxn = 1e6 + 5;   const int INF = 0x7fffffff;   bool p(long long a) {     for (long long i = 2; i <= sqrt(a); i++) {       if (a % i == 0) return 0;     }     return 1;   }   int main() {     int n;     cin >> n;     int c = n;     while (!p(c)) {       c++;     }     cout << c <<   n ;     for (int i = 1; i < n; i++) cout << i <<     << i + 1 <<   n ;     cout << 1 <<     << n <<   n ;     for (int i = 1; i <= c - n; i++) cout << i <<     << n - i <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 200005;   const int G = N;   set<pair<int, int> > S;   set<int> a[N];   int ans[N];   bool was[N];   vector<int> C[G + G];   int n, m;   bool solve() {     while (!S.empty()) {       int idx = S.begin()->second;       if (a[idx].empty()) {         cerr <<  fail   << idx << endl;         return 0;       }       int u = *a[idx].begin();       ans[abs(u)] = u / abs(u);       was[idx] = 1;       S.erase(S.begin());       for (int v : C[u + G])         if (!was[v]) {           was[v] = 1;           auto it = S.find(pair<int, int>(a[v].size(), v));           assert(it != S.end());           S.erase(it);         }       for (int v : C[-u + G])         if (!was[v]) {           auto it = S.find(pair<int, int>(a[v].size(), v));           assert(it != S.end());           a[v].erase(-u);           S.erase(it);           S.insert(pair<int, int>(a[v].size(), v));         }     }     return 1;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m;     int s, u;     for (int i = 1; i <= n; ++i) {       cin >> s;       for (int j = 1; j <= s; ++j) {         cin >> u;         a[i].insert(u);         C[u + G].push_back(i);       }       S.insert(pair<int, int>(a[i].size(), i));     }     bool res = solve();     if (res) {       cout <<  YES n ;       for (int i = 1; i <= m; ++i) cout << (ans[i] == 1);     } else {       cout <<  NO n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   char an[505];   vector<int> b, other[5];   int A[505][505], visited[505], ans[5];   int dfs(int node, int flag) {     int sz = 1;     visited[node] = flag;     other[flag].push_back(node);     for (int i = 0; i < n; ++i)       if (!visited[i] and A[node][i]) sz += dfs(i, flag);     return sz;   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i < m; ++i) {       int a, b;       scanf( %d%d , &a, &b);       --a;       --b;       A[a][b] = A[b][a] = 1;     }     for (int i = 0; i < n; ++i) {       an[i] =  b ;       bool connected = true;       for (int j = 0; j < n and connected; ++j)         if (i != j and !A[i][j]) connected = false;       if (connected) {         visited[i] = 5;         b.push_back(i);       }     }     for (int i = 0; i < (int)b.size(); ++i)       for (int j = 0; j < n; ++j) A[j][b[i]] = A[b[i]][j] = 0;     int cnt = 0;     for (int i = 0; i < n; ++i) {       if (!visited[i]) {         if (cnt == 2) {           printf( No n );           return 0;         }         ans[cnt] = dfs(i, cnt + 1);         ++cnt;       }     }     for (int i = 1; i < 3; ++i)       for (int j = 0; j < (int)other[i].size(); ++j)         for (int k = j + 1; k < (int)other[i].size(); ++k) {           assert(A[other[i][j]][other[i][k]] == A[other[i][k]][other[i][j]]);           if (!A[other[i][j]][other[i][k]]) {             printf( No n );             return 0;           }         }     printf( Yes n );     for (int i = 0; i < ans[0]; ++i) an[other[1][i]] =  a ;     for (int i = 0; i < ans[1]; ++i) an[other[2][i]] =  c ;     an[n] =   0 ;     printf( %s n , an);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long mod = 1e9 + 7;   int dx[] = {-1, 1, 0, 0, -1, 1, -1, 1};   int dy[] = {0, 0, 1, -1, 1, -1, -1, 1};   void fast() {     ios_base::sync_with_stdio(0);     cin.tie(0);   }   long long gcd(long long x, long long y) {     if (!y) return x;     return gcd(y, x % y);   }   long long lcm(long long x, long long y) { return (x / gcd(x, y)) * y; }   long long fastpow(long long a, long long b) {     long long res = 1;     int last;     while (b) {       if (b % 2) res *= a;       b /= 2, a *= a;     }     return res;   }   bool isprime(long long n) {     if (n == 1 || n == 0) return 0;     for (int i = 2; i <= sqrt(n); i++)       if (n % i == 0) return 0;     return 1;   }   int main() {     fast();     int ma = INT_MIN;     int n, a;     cin >> n;     bool found = 1;     stack<int> stk;     for (int i = 0; i < n; i++) {       cin >> a;       ma = max(ma, a);       if (!stk.empty() && a > stk.top()) found = 0;       if (stk.empty() || a != stk.top())         stk.push(a);       else         stk.pop();     }     if (!found || (stk.size() == 1 && stk.top() < ma))       cout <<  NO n ;     else       cout << (stk.size() > 1 ?  NO n  :  YES n );   }


#include <bits/stdc++.h>   using namespace std;   template <typename Tp>   inline void outarr(Tp _begin, Tp _end, const char* _delim =    ) {     for (Tp current = _begin; current != _end; ++current) {       std::cout << *current << _delim;     }     std::cout <<   n ;   }   using ll = int64_t;   using pii = std::pair<int, int>;   constexpr int INF = 0x3f3f3f3f;   constexpr int MOD = static_cast<const int>(1e9 + 7);   int F(int x) {     if (x == 1) {       return 1;     }     return 12 * (x - 1);   }   int main() {     std::ios_base::sync_with_stdio(false);     std::cin.tie(nullptr);     int a;     cin >> a;     ll ans = 0;     for (int i = 1; i <= a; ++i) {       ans += F(i);     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int L = 1e5 + 1;   long long sofar[L], out[L];   struct node {     long long l, r, q;   };   long long ans = 0, counter[3000002], k;   bool comp(node x, node y) { return x.r < y.r; }   void add(long long val) {     ans += counter[val ^ k];     counter[val]++;     return;   }   void remove(long long val) {     counter[val]--;     ans -= counter[val ^ k];     return;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long a, n, m, cur = 0, l, r;     cin >> n >> m >> k;     for (int i = 1; i < n + 1; ++i) {       cin >> a;       sofar[i] ^= sofar[i - 1];       sofar[i] ^= a;     }     std::vector<node> v[n / 316 + 5];     node temp;     for (int i = 0; i < m; ++i) {       cin >> l >> r;       l--, r++;       temp.l = l, temp.r = r, temp.q = i;       v[l / 316].push_back(temp);     }     for (int i = 0; i < n / 316 + 1; ++i) sort(v[i].begin(), v[i].end(), comp);     for (int i = 0; i < n / 316 + 3; ++i) {       l = r = i * 316;       ans = 0;       for (auto &x : v[i]) {         while (r < x.r) {           add(sofar[r]);           ++r;         }         while (l < x.l) {           remove(sofar[l]);           l++;         }         while (l > x.l) {           --l;           add(sofar[l]);         }         out[x.q] = ans;       }       for (int j = l; j < r; ++j) remove(sofar[j]);     }     for (int i = 0; i < m; ++i) cout << out[i] <<   n ;     return 0;   }


#include<bits/stdc++.h>   using namespace std;   #define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);   #define endl   n    typedef long long LL;   const int maxn = 2e5 + 5;      int cnt, id, a[maxn], hea[maxn], siz[maxn], dfsid[maxn], sum[maxn];      map<int, int> exist, tol;      struct node{       int v, next;   }edge[maxn << 1];      inline void add(int u, int v){       edge[++cnt].v = v;       edge[cnt].next = hea[u];       hea[u] = cnt;   }      inline void dfs(int u, int fa){       siz[u] = 1;       dfsid[u] = ++id;       int pre = exist[a[u]]++;       for(int k = hea[u]; k; k = edge[k].next){           int v = edge[k].v;           if(v == fa) continue;           int x = exist[a[u]];           dfs(v, u);           siz[u] += siz[v];           if(x != exist[a[u]]){   // 子树内出现了父节点的值，删除子树外所有点               sum[1]++;               sum[dfsid[v]]--;               sum[dfsid[v] + siz[v]]++;           }       }       if(exist[a[u]] - pre != tol[a[u]]){ // 子树外存在父节点的值，删除子树内所有点           sum[dfsid[u]]++;           sum[dfsid[u] + siz[u]]--;       }   }      int main(){       IOS;       int n, u, v;       cin >> n;       for(int i = 1; i <= n; i++){           cin >> a[i];           tol[a[i]]++;       }       for(int i = 1; i < n; i++){           cin >> u >> v;           add(u, v);           add(v, u);       }       dfs(1, 1);       int ans = 0;       for(int i = 1; i <= n; i++){           sum[i] += sum[i - 1];           ans += sum[i] == 0;       }       cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   template <class T1, class T2>   struct cmpf {     bool rev;     inline bool operator()(const pair<T1, T2>& a, const pair<T1, T2>& b) const {       return (a.first < b.first) ^ rev;     }     cmpf(bool b = false) { rev = b; }   };   template <class T1, class T2>   struct cmps {     bool rev;     inline bool operator()(const pair<T1, T2>& a, const pair<T1, T2>& b) const {       return (a.second < b.second) ^ rev;     }     cmps(bool b = false) { rev = b; }   };   string to_string(const char& c) { return string(1, c); }   string to_string(const string& s) { return     + s +    ; }   string to_string(const char* s) { return to_string((string)s); }   string to_string(const bool& b) { return (b ?  true  :  false ); }   string to_string(const vector<bool>& v, const string& sep =    ) {     string s =  [ ;     for (int i = 0; i < v.size(); i++) {       if (i) {         s += sep;       }       s += to_string(v[i]);     }     return s +  ] ;   }   template <size_t N>   string to_string(const bitset<N>& v) {     string s =  [ ;     for (size_t i = 0; i < N; i++) s += v[i] ?  1  :  0 ;     return s +  ] ;   }   template <class T1, class T2>   string to_string(const pair<T1, T2>& p, const string& sep =  , );   template <class T>   string to_string(const T& v, const string& sep =    ) {     bool first = true;     string s =  { ;     for (const auto& x : v) {       if (!first)         s += sep;       else         first = false;       s += to_string(x);     }     return s +  } ;   }   template <class T>   string to_string(const T& v, const int& sz, const string& sep =    ) {     string s =  [ ;     for (int i = 0; i < sz; i++) {       if (i) {         s += sep;       }       s += to_string(v[i]);     }     return s +  ] ;   }   template <class T1, class T2>   string to_string(const pair<T1, T2>& p, const string& sep) {     return  (  + to_string(p.first) + sep + to_string(p.second) +  ) ;   }   long long binpow(const long long& x, const long long& p, const long long& mod) {     assert(mod > 0);     if (p == 0) return 1;     if (p == 1) return x % mod;     if (p & 1) return (binpow((x * x) % mod, p / 2, mod) * x) % mod;     return binpow((x * x) % mod, p / 2, mod) % mod;   }   template <class T>   void chmn(T& a, const T& b) {     if (a > b) a = b;   }   template <class T>   void chmx(T& a, const T& b) {     if (a < b) a = b;   }   void setIO() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);   }   int chr[8] = {-1, 0, 1, 0, -1, -1, 1, 1};   int chc[8] = {0, 1, 0, -1, -1, 1, -1, 1};   const long long MOD = 1e9 + 7;   const int INIT = 1001001001;   const int MN = 255;   bool mat[MN][MN];   int N, M;   inline const bool out(int r, int c) {     return r <= 0 || r > N || c <= 0 || c > M;   }   inline const bool ok(int r, int c, int skip1, int skip2, int n) {     if (out(r, c) || !mat[r][c]) return false;     for (int i = 0; i < n; i++) {       if (i != skip1 && i != skip2) {         if (mat[r + chr[i]][c + chc[i]]) return false;       }     }     return true;   }   bool side_square(int r, int c, int len) {     if (!ok(r, c, 1, 2, 4)) return false;     if (mat[r - 1][c - 1]) return false;     r++;     for (int i = 0; i + 2 < len; i++) {       if (!ok(r, c, 0, 2, 4)) return false;       r++;     }     if (!ok(r, c, 0, 1, 4)) return false;     if (mat[r + 1][c - 1]) return false;     c++;     for (int i = 0; i + 2 < len; i++) {       if (!ok(r, c, 1, 3, 4)) return false;       c++;     }     if (!ok(r, c, 0, 3, 4)) return false;     if (mat[r + 1][c + 1]) return false;     r--;     for (int i = 0; i + 2 < len; i++) {       if (!ok(r, c, 0, 2, 4)) return false;       r--;     }     if (!ok(r, c, 2, 3, 4)) return false;     if (mat[r - 1][c + 1]) return false;     c--;     for (int i = 0; i + 2 < len; i++) {       if (!ok(r, c, 1, 3, 4)) return false;       c--;     }     return true;   }   bool diag_square(int r, int c, int len) {     if (!ok(r, c, 6, 7, 8)) return false;     r++;     c--;     for (int i = 0; i + 2 < len; i++) {       if (!ok(r, c, 5, 6, 8)) return false;       r++;       c--;     }     if (!ok(r, c, 5, 7, 8)) return false;     r++;     c++;     for (int i = 0; i + 2 < len; i++) {       if (!ok(r, c, 4, 7, 8)) return false;       r++;       c++;     }     if (!ok(r, c, 4, 5, 8)) return false;     r--;     c++;     for (int i = 0; i + 2 < len; i++) {       if (!ok(r, c, 5, 6, 8)) return false;       r--;       c++;     }     if (!ok(r, c, 4, 6, 8)) return false;     r--;     c--;     for (int i = 0; i + 2 < len; i++) {       if (!ok(r, c, 4, 7, 8)) return false;       r--;       c--;     }     return true;   }   void solve() {     cin >> N >> M;     for (int i = 0; i < N + 5; i++) {       for (int j = 0; j < M + 5; j++) {         mat[i][j] = false;       }     }     char c;     for (int i = 1; i <= N; i++) {       for (int j = 1; j <= M; j++) {         cin >> c;         mat[i][j] = c ==  1 ;       }     }     long long ans = 0;     for (int i = 1; i <= N; i++) {       for (int j = 1; j <= M; j++) {         if (mat[i][j]) {           bool stop = false;           for (int len = 2; i + len - 1 <= N && j + len - 1 <= M; len++) {             if (side_square(i, j, len)) {               ++ans;               stop = true;             }             if (diag_square(i, j, len)) {               ++ans;               stop = true;             }             if (stop) break;           }         }       }     }     cout << ans <<   n ;   }   int main() {     setIO();     long long T = 1;     cin >> T;     while (T--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int sq = sqrt(n);     if (n % sq == 0) {       cout << sq <<     << n / sq;     } else {       int i = 0;       while (++i) {         if (n % (sq - i) == 0) {           cout << sq - i <<     << n / (sq - i);           break;         } else if (n % (sq + i) == 0) {           cout << sq + i <<     << n / (sq + i);           break;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int p = 1e9 + 7;   long long binpow(long long a, long long b, long long mod) {     long long res = 1;     while (b > 0) {       if (b & 1) res = res * a % mod;       a = a * a % mod;       b >>= 1;     }     return res % mod;   }   const int dx[] = {1, -1, 0, 0};   const int dy[] = {0, 0, -1, 1};   const int inf = 1e9;   const int N = 1e5 + 9;   void solve() {     int n;     cin >> n;     vector<int> a(n);     for (__typeof(n) i = (0) - ((0) > (n)); i != (n) - ((0) > (n));          i += 1 - 2 * ((0) > (n)))       cin >> a[i];     if (n == 1) {       cout << a[0] <<   n ;       return;     }     int dp[n][2];     dp[0][0] = a[0];     dp[0][1] = 1e9;     dp[1][0] = a[0] + a[1];     dp[1][1] = a[0];     for (__typeof(n) i = (2) - ((2) > (n)); i != (n) - ((2) > (n));          i += 1 - 2 * ((2) > (n))) {       dp[i][0] = min(dp[i - 1][1] + a[i], dp[i - 2][1] + a[i] + a[i - 1]);       dp[i][1] = min(dp[i - 1][0], dp[i - 2][0]);     }     cout << min(dp[n - 1][1], dp[n - 1][0]) <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int t = 1;     cin >> t;     while (t--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long inf = 0x3f3f3f3f3f3f3f3f;   struct port {     int id;     int x, y;   };   void solve() {     int n, m, sx, sy, dx, dy;     cin >> n >> m >> sx >> sy >> dx >> dy;     vector<port> p;     for (int i = 0, x, y; i < m; ++i) {       cin >> x >> y;       p.push_back({i + 1, x, y});     }     vector<array<int, 2>> adj[m + 3];     for (auto &i : p) {       int wt = min(abs(i.x - sx), abs(i.y - sy));       adj[m + 1].push_back({i.id, wt});       adj[i.id].push_back({m + 1, wt});     }     for (auto &i : p) {       int wt = abs(i.x - dx) + abs(i.y - dy);       adj[m + 2].push_back({i.id, wt});       adj[i.id].push_back({m + 2, wt});     }     sort(begin(p), end(p), [&](port a, port b) { return a.x < b.x; });     for (int i = 1; i < m; ++i) {       int j = i - 1, wt = abs(p[i].x - p[j].x);       adj[p[i].id].push_back({p[j].id, wt});       adj[p[j].id].push_back({p[i].id, wt});     }     sort(begin(p), end(p), [&](port a, port b) { return a.y < b.y; });     for (int i = 1; i < m; ++i) {       int j = i - 1, wt = abs(p[i].y - p[j].y);       adj[p[i].id].push_back({p[j].id, wt});       adj[p[j].id].push_back({p[i].id, wt});     }     int wt = abs(dx - sx) + abs(dy - sy);     adj[m + 1].push_back({m + 2, wt});     adj[m + 2].push_back({m + 1, wt});     auto dijkstra = [&](int src, int des) {       vector<long long> dist(m + 3, inf);       priority_queue<array<long long, 2>, vector<array<long long, 2>>,                      greater<array<long long, 2>>>           pq;       dist[src] = 0;       pq.push({0, src});       while (!pq.empty()) {         long long curdist = pq.top()[0];         long long curnode = pq.top()[1];         pq.pop();         if (curdist > dist[curnode]) continue;         for (auto &[v, w] : adj[curnode]) {           if (dist[curnode] + w < dist[v]) {             dist[v] = dist[curnode] + w;             pq.push({dist[v], v});           }         }       }       return dist[des];     };     cout << dijkstra(m + 1, m + 2);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     int tc;     tc = 1;     while (tc--) solve();   }


#include <bits/stdc++.h>   using namespace std;   bool debug = 0;   int n, m, k;   int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};   string direc =  RDLU ;   long long ln, lk, lm;   void etp(bool f = 0) {     puts(f ?  Yes  :  No );     exit(0);   }   void addmod(int &x, int y, int mod = 1000000007) {     assert(y >= 0);     x += y;     if (x >= mod) x -= mod;     assert(x >= 0 && x < mod);   }   void et() {     puts( -1 );     exit(0);   }   long long fastPow(long long x, long long y, int mod = 1000000007) {     long long ans = 1;     while (y > 0) {       if (y & 1) ans = (x * ans) % mod;       x = x * x % mod;       y >>= 1;     }     return ans;   }   long long gcd1(long long x, long long y) {     long long z = y;     while (x % y != 0) {       z = x % y;       x = y;       y = z;     }     return z;   }   int fac[105], inv[105];   void initfac(int n) {     fac[0] = inv[0] = 1;     for (int(i) = 1; (i) <= (int)(n); (i)++) {       fac[i] = (long long)fac[i - 1] * i % 1000000007;       inv[i] = fastPow(fac[i], 1000000007 - 2);     }   }   int C(int n, int m) {     if (n < m) return 0;     return (long long)fac[n] * inv[m] % 1000000007 * inv[n - m] % 1000000007;   }   int d[105];   long long dp[55][55][55], ways[55][55][55];   long long wk(int a, int b, int c) {     if (a < 0 || b < 0) return 0;     if (dp[a][b][c] != -1) return dp[a][b][c];     int ans = 0;     if (c) {       ans = (wk(a - 1, b, c - 1) * a + wk(a + 1, b - 1, c - 1) * b) % 1000000007;     } else if (a) {       ans = (wk(a - 2, b, 0) * (a - 1) + wk(a, b - 1, 0) * b) % 1000000007;     } else if (b > 2) {       for (long long z = 3, x = (b - 1) * (b - 2) / 2; z <= b;            x = x * (b - z++) % 1000000007) {         ans += x * wk(0, b - z, 0) % 1000000007;         ans %= 1000000007;       }     } else       ans = (b == 0);     return dp[a][b][c] = ans;     ;   }   int mdp[55][55];   int cal(int l, int r) {     if (mdp[l][r] != -1) return mdp[l][r];     if (r > n) return 0;     int ans = 0, c2 = 0, c3 = 0;     for (int i = l; i <= r; i++)       if (d[i] == 2)         c2++;       else         c3++;     if (r == n)       ans = wk(c2, c3, 0) % 1000000007;     else {       for (int x = 1; x <= n - r; x++) {         addmod(ans, wk(c2, c3, x) * cal(r + 1, r + x) % 1000000007);       }     }     return mdp[l][r] = ans;   }   void fmain(int tid) {     scanf( %d , &n);     for (int(i) = 1; (i) <= (int)(n); (i)++) scanf( %d , d + i);     initfac(55);     ways[0][0][0] = 1;     memset(dp, -1, sizeof dp);     memset(mdp, -1, sizeof mdp);     int ans = d[1] == 2 ? cal(2, 3) : cal(2, 4);     printf( %d n , ans);   }   int main() {     int t = 1;     for (int(i) = 1; (i) <= (int)(t); (i)++) {       fmain(i);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool s[100005];   int main() {     int n;     cin >> n;     n *= 2;     int ans = 0, rst = 0;     ;     while (n--) {       int tmp;       cin >> tmp;       if (s[tmp])         ans -= 1;       else         s[tmp] = 1, ans++;       rst = max(rst, ans);     }     cout << rst << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     vector<bool> vt(100005);     vector<int> side(100005, 0b111);     set<int> G[100005];     cin >> n >> m;     for (int i = 0; i < m; i++) {       int a, b;       cin >> a >> b;       G[a].insert(b);       G[b].insert(a);     }     bool first = true;     int g2 = 0;     for (int i = 1; i <= n; i++) {       if (G[1].find(i) != G[1].end()) {         if (first) {           g2 = i;           first = false;         }         side[i] &= 0b110;       } else {         side[i] &= 0b001;       }     }     for (int i = 1; i <= n; i++) {       if (G[g2].find(i) != G[g2].end()) {         side[i] &= 0b101;       } else {         side[i] &= 0b010;       }     }     for (int i = 1; i <= n; i++) {       if (side[i] != 1 && side[i] != 2 && side[i] != 4) {         puts( -1 );         return 0;       }     }     int ct1 = 0, ct2 = 0, ct3 = 0;     for (int i = 1; i <= n; i++) {       switch (side[i]) {         case 1:           ct1++;           break;         case 2:           ct2++;           break;         case 4:           ct3++;           break;       }       for (auto e : G[i])         if (side[i] == side[e]) {           puts( -1 );           return 0;         }     }     if (m != ct1 * ct2 + ct2 * ct3 + ct3 * ct1 || !ct1 || !ct2 || !ct3) {       puts( -1 );       return 0;     }     for (int i = 1; i <= n; i++) {       switch (side[i]) {         case 1:           printf( %d  , 1);           break;         case 2:           printf( %d  , 2);           break;         case 4:           printf( %d  , 3);           break;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline int size(const T& c) {     return c.size();   }   using namespace std;   const int maxn = 100000 + 10;   struct student {     int a;     int b;     int cs;   } a[maxn];   int n, p, k, k2;   long long f[maxn];   long long sumgrey, sumplease, resgrey, resplease;   struct cmp {     bool operator()(int u, int v) {       return make_pair(make_pair(a[u].a, a[u].b), u) <              make_pair(make_pair(a[v].a, a[v].b), v);     }   };   set<int, cmp> s;   int vt;   bool mycmp1(student a, student b) {     if (a.b == b.b) {       return a.a < b.a;     }     return a.b < b.b;   }   bool mycmp2(student a, student b) {     if (a.b == b.b) {       return a.a > b.a;     }     return a.b < b.b;   }   void update(int sep) {     if (resgrey < sumgrey || (resgrey == sumgrey && resplease < sumplease)) {       resgrey = sumgrey;       resplease = sumplease;       vt = sep;     }   }   void process() {     for (int i = (1), _b = (n); i <= _b; i++) f[i] = f[i - 1] + a[i].b;     s.clear();     for (int i = (n), _a = (n - k + 1); i >= _a; i--) {       s.insert(i);       sumgrey += a[i].a;       sumplease = f[i - 1] - f[i - k2 - 1];     }     update(n - k + 1);     for (int i = (n - k), _a = (k2 + 1); i >= _a; i--) {       int u = *s.begin();       sumplease = f[i - 1] - f[i - k2 - 1];       if (a[i].a > a[u].a || (a[i].a == a[u].a && a[i].b > a[u].b)) {         s.erase(u);         sumgrey -= a[u].a;         s.insert(i);         sumgrey += a[i].a;       }       update(i);     }   }   void trace() {     s.clear();     for (int i = (n), _a = (n - k + 1); i >= _a; i--) s.insert(i);     for (int i = (n - k), _a = (vt); i >= _a; i--) {       int u = *s.begin();       if (a[i].a > a[u].a || (a[i].a == a[u].a && a[i].b > a[u].b)) {         s.erase(u);         s.insert(i);       }     }     set<int, cmp>::iterator it;     for (__typeof((s).begin()) it = (s).begin(); it != (s).end(); it++)       cout << a[*it].cs <<    ;     for (int i = (vt - k2), _b = (vt - 1); i <= _b; i++) cout << a[i].cs <<    ;   }   int main() {     cin >> n >> p >> k;     for (int i = (1), _b = (n); i <= _b; i++)       cin >> a[i].a >> a[i].b, a[i].cs = i;     k2 = p - k;     sort(a + 1, a + 1 + n, mycmp2);     process();     trace();     fclose(stdin);     fclose(stdout);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int M = 1e9 + 7;   long long gcd(long long a, long long b) {     while (b > 0) {       long long p = a % b;       a = b;       b = p;     }     return a;   }   long long bexp(long long a, int b) {     long long res = 1;     while (b > 0) {       if (b & 1) res = res * a;       a = a * a;       b >>= 1;     }     return res;   }   long long bexpM(long long a, int b) {     long long res = 1;     while (b > 0) {       if (b & 1) res = (res * a) % M;       a = (a * a) % M;       b >>= 1;     }     return res;   }   long long nCk(int n, int k) {     long long res = 1;     for (int i = k + 1; i < n + 1; i++) res = res * i;     long long p = 1;     for (int i = 2; i < n - k + 1; i++) p = p * i;     res = res / p;     return res;   }   long long nCkM(int n, int k) {     long long res = 1;     for (int i = k + 1; i < n + 1; i++) res = (res * i) % M;     long long p = 1;     for (int i = 2; i < n - k + 1; i++) p = (p * i) % M;     res = (res * bexpM(p, M - 2)) % M;     return res;   }   const int N = 2e5;   long long st[N][18];   long long q(int l, int s, int n) {     int i = 0;     while ((1 << (i + 1)) < s) i++;     return gcd(st[l][i], st[l - (1 << i) + s][i]);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int u;     cin >> u;     for (int g = 0; g < u; g++) {       int n;       cin >> n;       long long a[n];       for (int i = 0; i < n; i++) {         cin >> a[i];       }       n--;       for (int i = 0; i < n; i++) {         st[i][0] = abs(a[i + 1] - a[i]);       }       for (int i = 1; i < log2(n); i++) {         for (int j = 0; j < n - (1 << (i - 1)); j++) {           st[j][i] = gcd(st[j][i - 1], st[j + (1 << (i - 1))][i - 1]);         }       }       int l = 1;       int r = n;       while (l < r) {         int m = (l + r + 1) / 2;         long long b[n - m + 1];         for (int i = 0; i < n - m + 1; i++) {           b[i] = q(i, m, n);         }         bool bo = 1;         for (int i = 0; i < n - m + 1; i++) {           if (b[i] != 1) bo = 0;         }         if (bo)           r = m - 1;         else           l = m;       }       bool bo = 1;       for (int i = 0; i < n; i++) {         if (st[i][0] > 1) bo = 0;       }       if (bo)         cout <<  1 n ;       else         cout << l + 1 <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1.1e5;   queue<int> Q[2];   vector<int> E[maxn];   int n, m, cnt, in[maxn], f[maxn];   signed main() {     scanf( %d%d , &n, &m);     for (int i = 0; i < n; ++i) scanf( %d , f + i);     for (int i = 1, x, y; i <= m; ++i)       scanf( %d%d , &x, &y), ++in[x], E[y].push_back(x);     for (int i = 0; i < n; ++i)       if (!in[i]) Q[f[i]].push(i);     while (!(Q[1].empty() && Q[0].empty())) {       while (!Q[0].empty()) {         int u = Q[0].front();         Q[0].pop();         for (auto v : E[u])           if (!--in[v]) Q[f[v]].push(v);       }       if (!Q[1].empty()) ++cnt;       while (!Q[1].empty()) {         int u = Q[1].front();         Q[1].pop();         for (auto v : E[u])           if (!--in[v]) Q[f[v]].push(v);       }     }     printf( %d , cnt);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct Seller {     long long first, second, diff;   } a[200005];   bool cmp(Seller p, Seller q) { return (p.diff > q.diff); }   int main() {     long long n, m, i, j, ans = 0;     cin >> n >> m;     for (i = 0; i < n; i++) cin >> a[i].first;     for (i = 0; i < n; i++) cin >> a[i].second;     for (i = 0; i < n; i++) {       a[i].diff = (a[i].second - a[i].first);     }     sort(a, a + n, cmp);     for (i = 0; i < m; i++) ans += a[i].first;     for (i = m; i < n; i++) ans += min(a[i].first, a[i].second);     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, a, b, c, d;     scanf( %d %d %d %d %d , &n, &a, &b, &c, &d);     long long ans = 0;     for (int i = 1; i <= n; i++) {       int sum = a + b + i;       if (sum - a - c <= 0 || sum - a - c > n) continue;       if (sum - b - d <= 0 || sum - b - d > n) continue;       if (sum - c - d <= 0 || sum - c - d > n) continue;       ans++;     }     ans *= n;     printf( %I64d , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int N, uz[1005], kay;   char ar[1005][1005], k[1005];   int kontrol(int a, int say) {     for (int i = 1; i <= uz[a] - say + 1; i++) {       if (ar[a][i] == k[1]) {         int m = 1, j, k1;         for (j = i + 1, k1 = 2; j <= uz[a] && k1 <= say && m; j++, k1++)           if (ar[a][j] != k[k1]) m = 0;         if (m) {           return 0;         }       }     }     return 1;   }   int maxs = 0;   void oku() {     cin >> N;     for (int i = 1; i <= N; i++) {       scanf(  %s , ar[i] + 1);       uz[i] = strlen(ar[i] + 1);       maxs = max(maxs, uz[i]);     }     int o = 1, l;     k[o] =  a ;     k[o]--;     while (o <= maxs) {       l = 1;       if (k[o] !=  z )         k[o]++;       else {         int p1 = o;         while (p1) {           if (k[p1] !=  z ) {             k[p1]++;             break;           } else             p1--;         }         if (!p1) {           memset(k, 0, sizeof(k));           o++;           for (int i = 1; i <= o; i++) k[i] =  a ;         } else {           p1++;           while (p1 <= o) {             k[p1] =  a ;             p1++;           }         }       }       l = 1;       for (int i = 1; i <= N && l; i++) l = kontrol(i, o);       if (l) {         printf( %s n , k + 1);         return;       }     }   }   int main() {     oku();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char ch[100001];   int N, n, m;   long long a[1 << 20], b[1 << 20];   int g[21][100001];   void FWT(long long p[], int flag) {     int temp = N;     for (int i = 2; i <= temp; i *= 2) {       int t = i / 2;       for (int j = 0; j < temp; j += i) {         for (int k = j; k < j + t; k++) {           long long x = p[k];           long long y = p[k + t];           p[k] = x + y;           p[k + t] = x - y;           if (flag == -1) {             p[k] /= 2;             p[k + t] /= 2;           }         }       }     }   }   int main() {     cin >> n >> m;     N = 1 << n;     for (int i = 1; i <= n; i++) {       scanf( %s , ch + 1);       for (int j = 1; j <= m; j++) {         g[i][j] = ch[j] -  0 ;       }     }     for (int i = 1; i <= m; i++) {       int x = 0;       for (int j = 1; j <= n; j++) {         x = (x * 2) | g[j][i];       }       a[x]++;     }     for (int i = 0; i < N; ++i) b[i] = b[i >> 1] + (i & 1);     for (int i = 0; i < N; ++i) b[i] = min(b[i], n - b[i]);     FWT(a, 1);     FWT(b, 1);     for (int i = 0; i < N; ++i) a[i] *= b[i];     FWT(a, -1);     long long ans = n * m;     for (int i = 0; i < N; ++i) ans = min(ans, a[i]);     printf( %I64d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     vector<pair<long long int, long long int> > v;     long long int n, x, c = 0;     cin >> n;     for (int i = 0; i < n; i++) {       long long int a, b;       cin >> a >> b;       v.push_back(make_pair(a, b));     }     sort(v.begin(), v.end());     long long int i = 0;     x = v[0].second;     while (i < n) {       if (v[i].first <= x) i++;       if (v[i].second < x) x = v[i].second;       if (v[i].first > x || i >= n) {         c++;         x = v[i].second;       }     }     cout << c;   }


#include <bits/stdc++.h>   using namespace std;   #pragma comment(linker,  /STACK:64000000 )   int n;   pair<int, int> a[1 << 10];   int b[1 << 10];   int ans[1 << 10][1 << 10];   int len[1 << 10];   void answer(string s) {     puts(s.c_str());     if (s ==  NO ) exit(0);     for (int i = 0; i < n; ++i) {       for (int j = 0; j < len[i]; ++j) printf( %d , ans[i][j]);       puts(  );     }     exit(0);   }   void init() {     scanf( %d , &n);     for (int i = 0; i < n; ++i) {       scanf( %d , &a[i].first);       a[i].second = i;     }     sort(a, a + n);   }   void add(int x) {     int dif = 1;     while (x >= 0 && dif) {       ++b[x];       dif = 0;       if (b[x] == 2) {         dif = 1;         b[x] = 0;       }       --x;     }     if (dif) answer( NO );   }   int main() {     init();     memset(b, 0, sizeof b);     for (int i = 0; i < n; ++i) {       int x = a[i].second;       len[x] = a[i].first;       for (int j = 0; j < a[i].first; ++j) {         ans[x][j] = b[j];       }       if (i == n - 1) break;       add(a[i].first - 1);     }     answer( YES );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   const int MAX = 2e6 + 5;   int ftree[MAX] = {0};   int sum[MAX] = {0};   int query(int node) {     int sum = 0;     while (node > 0) {       sum += ftree[node];       node -= (node & -node);     }     return sum;   }   void update(int node, int diff, int &mx) {     while (node <= mx) {       ftree[node] += diff;       node += (node & -node);     }   }   int bsearch(int &n, int s) {     int l = 1;     int r = n;     while (l <= r) {       int m = (l + r) >> 1;       int p = query(m);       if (p < s)         l = m + 1;       else         r = m - 1;     }     return l;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     memset(ftree, 0, sizeof(ftree));     memset(sum, 0, sizeof(sum));     int n;     cin >> n;     for (int i = (1); i <= (n); ++i) {       update(i, 1, n);     }     int p;     for (int i = 0; i < (int)(n); ++i) {       cin >> p;       int less = query(p + 1) - 1;       sum[i] += less;       update(p + 1, -1, n);     }     for (int i = (1); i <= (n); ++i) {       update(i, 1, n);     }     for (int i = 0; i < (int)(n); ++i) {       cin >> p;       int less = query(p + 1) - 1;       sum[i] += less;       update(p + 1, -1, n);     }     for (int i = 0; i < n; ++i) {       int carry = sum[n - i - 1] / (i + 1);       sum[n - i - 2] += carry;       sum[n - i - 1] %= (i + 1);       update(i + 1, 1, n);     }     for (int i = 0; i < (int)(n); ++i) {       int f = bsearch(n, sum[i] + 1);       cout << (f - 1) <<    ;       update(f, -1, n);     }     cout <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int Maxn = 1000000;   const int Inf = 0x3f3f3f3f;   int n, m, k;   pair<int, int> edge[Maxn + 5];   int a[Maxn + 5];   map<pair<int, int>, int> mp;   int deg[Maxn + 5], sz[Maxn + 5], st[Maxn + 5], col[Maxn + 5];   vector<pair<int, int> > g[Maxn + 5];   int ans[Maxn + 5];   void match(int u, int fa, int from, int to) {     for (int i = 0; i < (int)g[u].size(); i++) {       if (g[u][i].first == from) {         g[u][i].first = to;         match(g[u][i].second, u, to, from);       }     }     for (int i = 0; i < (int)g[u].size(); i++) {       if (g[u][i].second == fa) {         g[u][i].first = from;       }     }   }   int main() {     scanf( %d%d%d , &n, &m, &k);     for (int i = 1; i <= n; i++) {       scanf( %*d );     }     for (int i = 1; i <= m; i++) {       int u, v;       scanf( %d%d , &u, &v);       if (u > v) {         swap(u, v);       }       edge[i] = make_pair(u, v + n);       deg[u]++;       deg[v + n]++;     }     n = (n << 1);     st[0] = 1;     for (int i = 1; i <= n; i++) {       sz[i] = (deg[i] - 1) / k + 1;       st[i] = st[i - 1] + sz[i - 1];     }     for (int i = 1; i <= m; i++) {       int u = edge[i].first, v = edge[i].second;       g[st[u]].push_back(make_pair(Inf, st[v]));       g[st[v]].push_back(make_pair(Inf, st[u]));       edge[i] = make_pair(st[u], st[v]);       mp[edge[i]] = i;       col[u]++;       col[v]++;       if (col[u] == k) {         st[u]++;         col[u] = 0;       }       if (col[v] == k) {         st[v]++;         col[v] = 0;       }     }     for (int i = 1; i <= m; i++) {       int u = edge[i].first, v = edge[i].second;       int pos_u = 0, pos_v = 0;       sort(g[u].begin(), g[u].end());       sort(g[v].begin(), g[v].end());       for (int j = 0; j < (int)g[u].size(); j++) {         if (j + 1 != g[u][j].first) {           pos_u = j + 1;           break;         }       }       for (int j = 0; j < (int)g[v].size(); j++) {         if (j + 1 != g[v][j].first) {           pos_v = j + 1;           break;         }       }       for (int j = 0; j < (int)g[u].size(); j++) {         if (g[u][j].second == v) {           g[u][j].first = pos_u;         }       }       match(v, u, pos_u, pos_v);     }     for (int i = 1; i <= st[n]; i++) {       for (int j = 0; j < (int)g[i].size(); j++) {         if (i < g[i][j].second) {           ans[mp[make_pair(i, g[i][j].second)]] = g[i][j].first;         }       }     }     for (int i = 1; i <= m; i++) {       printf( %d n , ans[i]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<pair<int, int> > vertices;   vector<pair<int, int> > edges;   int main() {     int v;     cin >> v;     int a, b;     queue<int> q;     for (int i = 0; i < v; i++) {       cin >> a >> b;       vertices.push_back(make_pair(a, b));       if (a == 1) {         q.push(i);       }     }     int size = v;     while (q.empty() == false) {       int i = q.front();       q.pop();       if (vertices[i].first == 1) {         int ver = vertices[i].second;         edges.push_back(make_pair(i, ver));         vertices[ver].first--;         vertices[ver].second ^= i;         if (vertices[ver].first == 1) {           q.push(ver);         }       }     }     cout << edges.size() << endl;     for (int i = 0; i < edges.size(); i++) {       cout << edges[i].first <<     << edges[i].second << endl;     }     return 0;   }


#include <bits/stdc++.h>   using std::max;   const int N = 3e5 + 5;   template <typename T>   void read(T &x) {     bool neg = false;     unsigned char c = getchar();     for (; (c ^ 48) > 9; c = getchar())       if (c ==  - ) neg = true;     for (x = 0; (c ^ 48) < 10; c = getchar()) x = (x << 3) + (x << 1) + (c ^ 48);     if (neg) x = -x;   }   struct line {     int next, to, w;   } e[2 * N];   int n, q, hd[N], cnt, a[N], b[N], fa[N], dep[N], siz[N], hc[N], top[N];   long long s[N], f[N], g[N], h[N], c[N], ff[N];   void adline(int u, int v, int w) {     e[cnt].to = v;     e[cnt].w = w;     e[cnt].next = hd[u];     hd[u] = cnt++;   }   void dfs1(int u) {     hc[u] = -1;     s[u] = s[fa[u]] + a[u] - b[u];     for (int i = hd[u]; ~i; i = e[i].next) {       int v = e[i].to;       if (v == fa[u]) continue;       fa[v] = u;       b[v] = e[i].w;       dep[v] = dep[u] + 1;       dfs1(v);       siz[u] += siz[v];       if (!~hc[u] || siz[v] > siz[hc[u]]) hc[u] = v;       f[u] += max(0ll, f[v] + a[v] - 2 * b[v]);     }     ++siz[u];   }   void dfs2(int u) {     long long sum = (ff[u] = f[u]) + g[u] + a[u];     h[u] = max(h[u], 0ll);     if (~hc[u]) {       int v = hc[u];       top[v] = top[u];       g[v] = max(0ll, sum - 2 * b[v] - max(0ll, h[v] = f[v] + a[v] - 2 * b[v]));       dfs2(v);     }     for (int i = hd[u]; ~i; i = e[i].next) {       int v = e[i].to;       if (v == fa[u] || v == hc[u]) continue;       g[v] = max(0ll, sum - 2 * b[v] - max(0ll, h[v] = f[v] + a[v] - 2 * b[v]));       dfs2(top[v] = v);     }   }   void dfs3(int u) {     for (int i = hd[u]; ~i; i = e[i].next) {       int v = e[i].to;       if (v == fa[u]) continue;       f[v] += f[u];       h[v] += h[u];       dfs3(v);     }   }   int lca(int u, int v) {     while (top[u] != top[v]) {       if (dep[top[u]] > dep[top[v]])         u = fa[top[u]];       else         v = fa[top[v]];     }     return dep[u] < dep[v] ? u : v;   }   int main() {     read(n);     read(q);     for (int i = 0, i_end = n; i < i_end; ++i) read(a[i]);     for (int i = 0, i_end = n; i < i_end; ++i) hd[i] = -1;     for (int i = 0, i_end = n - 1; i < i_end; ++i) {       int u, v, w;       read(u);       read(v);       read(w);       adline(--u, --v, w);       adline(v, u, w);     }     dfs1(0);     dfs2(0);     dfs3(0);     while (q--) {       int u, v, m;       long long ans;       read(u);       read(v);       --u, --v;       m = lca(u, v);       ans = s[u] + s[v] - 2 * s[m] + a[m];       ans += f[u] + f[v] - 2 * f[m] + g[m];       ans -= h[u] + h[v] - 2 * h[m] - ff[m];       printf( %lld n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string s[6] = { 170 ,  020 ,  200 ,  110 ,  050 ,  080 };   int main() {     int n;     cin >> n;     if (n < 3)       cout << -1;     else if (n == 3)       cout << 210;     else {       cout << 1;       for (int i = 0; i < n - 4; i++) cout << 0;       cout << s[n % 6];     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string s1[10], s2[10], score[10];   map<string, int> mp;   string name[10];   int a[10][10];   bool better(int x, int y) {     int n;     int sx = 0, px = 0, mx = 0, sy = 0, py = 0, my = 0;     for (n = 0; n < 4; n++)       if (n != x) {         if (a[x][n] > a[n][x])           sx += 3;         else if (a[x][n] == a[n][x])           sx++;         px += a[x][n];         mx += a[n][x];       }     for (n = 0; n < 4; n++)       if (n != y) {         if (a[y][n] > a[n][y])           sy += 3;         else if (a[y][n] == a[n][y])           sy++;         py += a[y][n];         my += a[n][y];       }     if (sx != sy) return (sx > sy);     if (px - mx != py - my) return (px - mx > py - my);     if (px != py) return (px > py);     return (x < y);   }   bool check(int x, int y) {     int n;     int b = mp[ BERLAND ];     int c;     int rank = 1;     for (n = 0; n < 4; n++)       if (n != b && a[b][n] == -1) c = n;     a[b][c] = x;     a[c][b] = y;     for (n = 0; n < 4; n++)       if (n != b && better(n, b)) rank++;     a[b][c] = -1, a[c][b] = -1;     return (rank <= 2);   }   int main() {     int i, j;     for (i = 0; i < 5; i++) {       cin >> s1[i] >> s2[i] >> score[i];     }     for (i = 0; i < 5; i++) mp[s1[i]] = mp[s2[i]] = 0;     i = 0;     for (__typeof((mp).begin()) itr = (mp).begin(); itr != (mp).end(); itr++) {       (itr->second) = i;       name[i] = (itr->first);       i++;     }     memset(a, -1, sizeof(a));     for (i = 0; i < 5; i++) {       int x = mp[s1[i]], y = mp[s2[i]];       for (j = 0; j < score[i].size(); j++)         if (score[i][j] ==  : ) score[i][j] =    ;       istringstream ss(score[i]);       ss >> a[x][y] >> a[y][x];     }     for (int diff = 1; diff < 100; diff++) {       for (int a = 0; a < 100; a++) {         int b = a + diff;         if (check(b, a)) {           cout << b <<  :  << a << endl;           return 0;         }       }     }     cout <<  IMPOSSIBLE  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace ::std;   const long double PI = acos(-1);   const long long MOD = 1000000000 + 7;   long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }   long long add(long long a, long long b, long long m = MOD) {     if (a >= m) a %= m;     if (b >= m) b %= m;     if (a < 0) a += m;     if (b < 0) b += m;     long long res = a + b;     if (res >= m or res <= -m) res %= m;     if (res < 0) res += m;     return res;   }   long long mul(long long a, long long b, long long m = MOD) {     if (a >= m) a %= m;     if (b >= m) b %= m;     if (a < 0) a += m;     if (b < 0) b += m;     long long res = a * b;     if (res >= m or res <= -m) res %= m;     if (res < 0) res += m;     return res;   }   long long pow_mod(long long a, long long b, long long m = MOD) {     long long res = 1LL;     a = a % m;     while (b) {       if (b & 1) res = mul(res, a, m);       b >>= 1;       a = mul(a, a, m);     }     return res;   }   long long fastexp(long long a, long long b) {     long long res = 1LL;     while (b) {       if (b & 1) res = res * a;       b >>= 1;       a *= a;     }     return res;   }   int gcdExtendido(int a, int b, int *x, int *y) {     if (a == 0) {       *x = 0;       *y = 1;       return b;     }     int x1, y1;     int gcd = gcdExtendido(b % a, a, &x1, &y1);     *x = y1 - (b / a) * x1;     *y = x1;     return gcd;   }   int modInverso(int a, int m) {     int x, y;     int g = gcdExtendido(a, m, &x, &y);     if (g != 1)       return -1;     else       return (x % m + m) % m;   }   const int M = 300000 + 5;   int N, n, m;   vector<int> G[M];   map<pair<int, int>, int> E;   void clearAll() {     for (int i = 1; i <= n; i++) {       G[i].clear();     }   }   int main() {     int t;     scanf( %d , &(t));     int a, b;     while (t--) {       scanf( %d %d , &(N), &(m));       n = N + N + N;       bool forest = true;       E.clear();       vector<bool> used(n + 1, false);       vector<int> matching;       for (int i = 1; i <= m; i++) {         scanf( %d %d , &(a), &(b));         if (a > b) swap(a, b);         G[a].emplace_back(b);         G[b].emplace_back(a);         E[make_pair(a, b)] = i;       }       for (int u = 1; u <= n; u++) {         if (used[u]) continue;         for (int i = 0; i < G[u].size(); i++) {           int v = G[u][i];           if (!used[v]) {             matching.emplace_back(E[make_pair(min(u, v), max(u, v))]);             used[u] = used[v] = true;             break;           }         }       }       if (matching.size() >= N) {         puts( Matching );         for (int i = 0; i < N; i++) {           printf( %d%c , matching[i], (i + 1 == N ?   n  :    ));         }       } else {         puts( IndSet );         int cnt = N;         for (int i = 1; i <= n; i++) {           if (cnt == 0) break;           if (!used[i]) {             cnt -= 1;             printf( %d%c , i, (cnt ?     :   n ));           }         }       }       if (t) clearAll();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, f = 0;     cin >> n;     for (int i = 1; i < 50; i++) {       if ((i * (i + 1)) / 2 == n) {         f = 1;         break;       }       if (i > n) break;     }     if (f)       cout <<  YES  << endl;     else       cout <<  NO  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline T sqr(const T &x) {     return x * x;   }   inline long long sqr(int x) { return sqr<long long>(x); }   template <class T>   T binpow(const T &a, long long n) {     return n == 0 ? 1 : sqr(binpow(a, n / 2)) * (n % 2 ? a : 1);   }   long long binpow(long long a, long long n, long long modulo) {     return n == 0 ? 1                   : sqr(binpow(a, n / 2, modulo)) % modulo * (n % 2 ? a : 1) %                         modulo;   }   long long gcd(long long a, long long b, long long &x, long long &y) {     if (a == 0) {       x = 0;       y = 1;       return b;     }     long long x1, y1;     long long d = gcd(b % a, a, x1, y1);     x = y1 - (b / a) * x1;     y = x1;     return d;   }   inline long long phi(long long n) {     long long result = n;     for (long long i = 2; i * i <= n; ++i)       if (n % i == 0) {         while (n % i == 0) n /= i;         result -= result / i;       }     if (n > 1) result -= result / n;     return result;   }   inline vector<long long> inverseAll(long long m) {     vector<long long> r(m);     r[1] = 1;     for (int i = 2; i < m; ++i) r[i] = (m - (m / i) * r[m % i] % m) % m;     return r;   }   inline long long gcd(long long a, long long b) { return gcd(a, b, a, b); }   inline long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }   inline long long llrand() {     const long long lsbToFill = (sizeof(long long) << 3) - 1;     const long long bitsFilledInIteration = __builtin_popcountll(RAND_MAX);     long long number = 0;     for (long long lsbFilled = 0; lsbFilled <= lsbToFill;          lsbFilled += bitsFilledInIteration) {       number ^= (((long long)rand()) << lsbFilled);     }     return number & numeric_limits<long long>::max();   }   inline long long llrand(long long begin, long long end) {     return begin + llrand() % (end - begin);   }   struct Dinic {     struct Edge {       int u, v;       long long cap, flow;       Edge() {}       Edge(int u, int v, long long cap) : u(u), v(v), cap(cap), flow(0) {}     };     int N;     vector<Edge> E;     vector<vector<int>> g;     vector<int> d, pt;     Dinic(int N) : N(N), E(0), g(N), d(N), pt(N) {}     void AddEdge(int u, int v, long long cap) {       if (u != v) {         E.emplace_back(Edge(u, v, cap));         g[u].emplace_back(E.size() - 1);         E.emplace_back(Edge(v, u, 0));         g[v].emplace_back(E.size() - 1);       }     }     bool BFS(int S, int T) {       queue<int> q({S});       fill(d.begin(), d.end(), N + 1);       d[S] = 0;       while (!q.empty()) {         int u = q.front();         q.pop();         if (u == T) break;         for (int k : g[u]) {           Edge &e = E[k];           if (e.flow < e.cap && d[e.v] > d[e.u] + 1) {             d[e.v] = d[e.u] + 1;             q.emplace(e.v);           }         }       }       return d[T] != N + 1;     }     long long DFS(int u, int T, long long flow = -1) {       if (u == T || flow == 0) return flow;       for (int &i = pt[u]; i < g[u].size(); ++i) {         Edge &e = E[g[u][i]];         Edge &oe = E[g[u][i] ^ 1];         if (d[e.v] == d[e.u] + 1) {           long long amt = e.cap - e.flow;           if (flow != -1 && amt > flow) amt = flow;           if (long long pushed = DFS(e.v, T, amt)) {             e.flow += pushed;             oe.flow -= pushed;             return pushed;           }         }       }       return 0;     }     long long MaxFlow(int S, int T) {       long long total = 0;       while (BFS(S, T)) {         fill(pt.begin(), pt.end(), 0);         while (long long flow = DFS(S, T)) total += flow;       }       return total;     }   };   vector<long long> Dijkstra(const vector<list<pair<int, long long>>> &g, int s) {     vector<long long> d(int((g).size()), numeric_limits<long long>::max() / 2LL);     priority_queue<pair<long long, int>> q;     d[s] = 0;     q.emplace(-0, s);     while (!q.empty()) {       while (q.top().first > d[q.top().second]) {         q.pop();       }       int v = q.top().second;       q.pop();       for (const auto &cw : g[v]) {         if (d[v] + cw.second < d[cw.first]) {           d[cw.first] = d[v] + cw.second;           q.emplace(-d[cw.first], cw.first);         }       }     }     return d;   }   struct BinarySearchIterator       : public std::iterator<std::forward_iterator_tag, bool> {     long long value;     typename iterator_traits<BinarySearchIterator>::difference_type operator-(         const BinarySearchIterator &it) const {       return value - it.value;     }     BinarySearchIterator &operator++() {       ++value;       return *this;     }     bool operator!=(const BinarySearchIterator &it) const {       return value != it.value;     }     bool operator*() const { return true; }   };   template <int ALPHA>   class AhoCorasick {    public:     static const int ILLEGAL_INDEX;     static const int ROOT;     struct Node {       bool leaf;       int parent;       int parentCharacter;       int link;       int next[ALPHA];       int go[ALPHA];       int outputFunction;       Node(int parent = ILLEGAL_INDEX, int parentCharacter = ALPHA)           : leaf(false),             parent(parent),             parentCharacter(parentCharacter),             link(ILLEGAL_INDEX),             outputFunction(ILLEGAL_INDEX) {         fill_n(next, ALPHA, ILLEGAL_INDEX);         fill_n(go, ALPHA, ILLEGAL_INDEX);       }     };     vector<Node> tree = vector<Node>(1);     AhoCorasick() {}     AhoCorasick(int maxStatesNumber) { tree.reserve(maxStatesNumber); }     template <class Iterator>     void add(int length, const Iterator begin) {       int vertex = ROOT;       for (int i = 0; i < length; ++i) {         if (ILLEGAL_INDEX == tree[vertex].next[begin[i]]) {           tree[vertex].next[begin[i]] = int((tree).size());           tree.push_back(Node(vertex, begin[i]));         }         vertex = tree[vertex].next[begin[i]];       }       tree[vertex].leaf = true;     }     int getLink(int vertex) {       assert(0 <= vertex && vertex < tree.size());       if (ILLEGAL_INDEX == tree[vertex].link) {         if (ROOT == vertex || ROOT == tree[vertex].parent) {           tree[vertex].link = ROOT;         } else {           tree[vertex].link =               go(getLink(tree[vertex].parent), tree[vertex].parentCharacter);         }       }       return tree[vertex].link;     }     int go(int vertex, int character) {       assert(0 <= character && character < ALPHA);       assert(0 <= vertex && vertex < tree.size());       if (ILLEGAL_INDEX == tree[vertex].go[character]) {         if (ILLEGAL_INDEX == tree[vertex].next[character]) {           tree[vertex].go[character] =               ROOT == vertex ? ROOT : go(getLink(vertex), character);         } else {           tree[vertex].go[character] = tree[vertex].next[character];         }       }       return tree[vertex].go[character];     }     int getOutputFunction(int vertex) {       assert(0 <= vertex && vertex < tree.size());       if (ILLEGAL_INDEX == tree[vertex].outputFunction) {         if (tree[vertex].leaf || ROOT == vertex) {           tree[vertex].outputFunction = vertex;         } else {           tree[vertex].outputFunction = getOutputFunction(getLink(vertex));         }       }       return tree[vertex].outputFunction;     }   };   template <int ALPHA>   const int AhoCorasick<ALPHA>::ILLEGAL_INDEX = -1;   template <int ALPHA>   const int AhoCorasick<ALPHA>::ROOT = 0;   int main(int argc, const char *argv[]) {     ios::sync_with_stdio(false);     cin.tie(0);     srand((unsigned int)time(NULL));     int n;     while (cin >> n) {       vector<long long> s(n);       for (int i = (0); i < (n); ++i) {         cin >> s[i];       }       vector<long long> ps(n + 1, 0);       partial_sum((s).begin(), (s).end(), ps.begin() + 1);       int q;       cin >> q;       for (int i = (0); i < (q); ++i) {         int l, r;         cin >> l >> r;         --l;         --r;         cout << (ps[r + 1] - ps[l]) / 10 << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   const long long MAXN = 1e5 + 3;   const long long inf = 2e9;   long long max(long long a, long long b) {     if (a > b)       return a;     else       return b;   }   long long min(long long a, long long b) {     if (a < b)       return a;     else       return b;   }   long long dx[] = {1, -1, 0, 0};   long long dy[] = {0, 0, -1, 1};   bool cmp(pair<long long, long long> p1, pair<long long, long long> p2) {     if (p1.first < p2.first)       return true;     else if (p1.first == p2.first) {       if (p1.second < p2.second) return true;       return false;     }     return false;   }   void solve() {     long long n;     cin >> n;     long long li, ri, di;     for (long long i = (long long)0; i < (long long)n; ++i) {       cin >> li >> ri >> di;       long long t1 = li / di;       long long t2 = ri / di;       if (li % di == 0) t1--;       t2++;       if (t1 >= 1)         cout << di <<   n ;       else         cout << t2 * di <<   n ;     }   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long nT = 1;     for (long long i = (long long)1; i <= (long long)nT; ++i) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100010;   struct node {     int c, h, i;     friend bool operator<(const node &a, const node &b) {       if (a.c != b.c) return a.c < b.c;       return a.h > b.h;     }   } t[N];   struct node2 {     int s, t, i, size;     friend bool operator<(const node2 &a, const node2 &b) {       return a.size > b.size;     }   } prepare[N];   int n, ss[N], rest[N], cnt, ans1, ans2;   long long sum[N], Max;   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d %d , &t[i].c, &t[i].h);       t[i].i = i;     }     sort(t + 1, t + n + 1);     for (int i = 1; i <= n; i++) {       int s = 0, j;       for (j = i + 1; t[j].c == t[i].c && j <= n; j++)         ;       ss[++cnt] = j - i;       prepare[cnt].s = i, prepare[cnt].t = j;       prepare[cnt].i = cnt, prepare[cnt].size = j - i;       i = j - 1;     }     sort(prepare + 1, prepare + cnt + 1);     for (int i = 1; i <= cnt; i++) rest[i] = prepare[i].size;     for (int p = cnt, s = 0; p > 1;) {       int delta = 10000000;       for (int i = p; i > 0; i--) delta = min(delta, rest[i]);       for (int i = p; i > 0; i--) {         for (int j = 1; j <= delta; j++) sum[i] += t[prepare[i].s + s + j - 1].h;         rest[i] -= delta;       }       s += delta;       for (int i = p; i > 0; i--)         if (rest[i] > 0) sum[i] += t[prepare[i].s + s].h;       int p1 = 0, p2 = 0;       for (int i = p; i > 0; i--)         if (sum[i] > sum[p1])           p2 = p1, p1 = i;         else if (sum[i] == sum[p1])           p2 = i;         else if (sum[i] > sum[p2])           p2 = i;       if (sum[p1] + sum[p2] > Max) Max = sum[p1] + sum[p2], ans1 = p1, ans2 = p2;       for (int i = p; i > 0; i--)         if (rest[i] > 0) sum[i] -= t[prepare[i].s + s].h;       while (rest[p] == 0 && p > 0) p--;     }     cout << Max << endl;     if (ss[prepare[ans1].i] == ss[prepare[ans2].i]) {       printf( %d n , ss[prepare[ans1].i] * 2);       for (int i = 1; i < ss[prepare[ans1].i]; i++)         printf( %d %d  , t[prepare[ans1].s + i - 1].i,                t[prepare[ans2].s + i - 1].i);       printf( %d %d n , t[prepare[ans1].t - 1].i, t[prepare[ans2].t - 1].i);     } else {       if (ss[prepare[ans1].i] > ss[prepare[ans2].i]) swap(ans1, ans2);       printf( %d n%d , ss[prepare[ans1].i] * 2 + 1, t[prepare[ans2].s].i);       for (int i = 1; i <= ss[prepare[ans1].i]; i++)         printf(  %d %d , t[prepare[ans1].s + i - 1].i, t[prepare[ans2].s + i].i);       printf(  n );     }     return 0;   }