#include <bits/stdc++.h>   using namespace std;   const int dr[] = {0, -1, 0, 1, -1, 1, 1, -1};   const int dc[] = {1, 0, -1, 0, 1, 1, -1, -1};   const double eps = 1e-9;   template <class T>   void print(const vector<T> &v) {     ostringstream os;     for (int i = 0; i < (int)v.size(); ++i) {       if (i) os <<    ;       os << v[i];     }     cout << os.str() << endl;   }   template <class T>   int sz(const T &c) {     return (int)c.size();   }   template <class T>   void srt(T &c) {     sort(c.begin(), c.end());   }   template <class T>   void checkmin(T &a, T b) {     if (b < a) a = b;   }   template <class T>   void checkmax(T &a, T b) {     if (b > a) a = b;   }   template <class T>   T sqr(T x) {     return x * x;   }   template <class T, class U>   T cast(U x) {     ostringstream os;     os << x;     T res;     istringstream is(os.str());     is >> res;     return res;   }   template <class T>   vector<T> split(string s, string x =    ) {     vector<T> res;     for (int i = 0; i < s.size(); i++) {       string a;       while (i < (int)s.size() && x.find(s[i]) == string::npos) a += s[i++];       if (!a.empty()) res.push_back(cast<T>(a));     }     return res;   }   template <class T>   bool inside(T r, T c, T R, T C) {     return r >= 0 && r < R && c >= 0 && c < C;   }   struct segment {     int left, right, len;     segment(int a, int b) : left(a), right(b), len(b - a) {}   };   bool operator<(const segment &a, const segment &b) {     if (a.len != b.len) return a.len > b.len;     return a.left > b.left;   }   map<int, int> t;   int n;   void add(int i, int value) {     for (; i < n; i |= i + 1) t[i] += value;   }   int sum(int i) {     int res = 0;     for (; i >= 0; i -= -~i & ~i)       if (t.count(i)) res += t[i];     return res;   }   int sum(int a, int b) { return sum(b) - sum(a - 1); }   int main(int argc, char *argv[]) {     int m;     scanf( %d%d , &n, &m);     set<segment> q;     q.insert(segment(1, n));     set<int> points;     points.insert(0);     points.insert(n + 1);     map<int, int> pos;     while (m--) {       int x;       scanf( %d , &x);       if (x == 0) {         int a, b;         scanf( %d%d , &a, &b);         printf( %d n , sum(a - 1, b - 1));       } else {         if (pos[x] == 0) {           segment s = *q.begin();           q.erase(s);           int mid = (s.left + s.right + 1) / 2;           pos[x] = mid;           points.insert(mid);           add(mid - 1, 1);           if (s.left <= mid - 1) q.insert(segment(s.left, mid - 1));           if (mid + 1 <= s.right) q.insert(segment(mid + 1, s.right));         } else {           int mid = pos[x];           set<int>::iterator it = points.find(mid);           int pre = *--it;           int nxt = *++ ++it;           if (pre + 1 <= mid - 1) q.erase(segment(pre + 1, mid - 1));           if (mid + 1 <= nxt - 1) q.erase(segment(mid + 1, nxt - 1));           if (pre + 1 <= nxt - 1) q.insert(segment(pre + 1, nxt - 1));           points.erase(mid);           add(mid - 1, -1);           pos[x] = 0;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string v[12] = { x^y^z ,  x^z^y ,  (x^y)^z ,  (x^z)^y ,                    y^x^z ,  y^z^x ,  (y^x)^z ,  (y^z)^x ,                    z^x^y ,  z^y^x ,  (z^x)^y ,  (z^y)^x };   pair<long double, long double> sol[12];   const long double EPS = 1e-12;   long double cmp(pair<long double, long double> a,                   pair<long double, long double> b) {     long double res1, res2;     res1 = a.second * log(a.first);     res2 = b.second * log(b.first);     if (abs(res1 - res2) < EPS) return 0;     return res1 - res2;   }   int main() {     int i, pos;     long double x, y, z;     cin >> x >> y >> z;     sol[0] = {x, pow(y, z)};     sol[1] = {x, pow(z, y)};     sol[2] = {x, y * z};     sol[3] = {x, z * y};     sol[4] = {y, pow(x, z)};     sol[5] = {y, pow(z, x)};     sol[6] = {y, x * z};     sol[6] = {y, z * x};     sol[8] = {z, pow(x, y)};     sol[9] = {z, pow(y, x)};     sol[10] = {z, x * y};     sol[11] = {z, y * x};     pos = 0;     for (i = 1; i < 12; ++i) {       if (cmp(sol[pos], sol[i]) < 0) pos = i;     }     cout << v[pos];     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   inline long long read() {     long long x = 0, f = 1;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) f = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       x = (x << 1) + (x << 3) + c -  0 ;       c = getchar();     }     return x * f;   }   int n, m, fac[1000100], ifac[1000100], ans;   int qpow(int a, int b) {     int ans = 1;     while (b) {       if (b & 1) ans = 1LL * ans * a % mod;       a = 1LL * a * a % mod;       b >>= 1;     }     return ans;   }   void init(int n) {     fac[0] = 1;     for (int i = 1; i <= n; ++i) {       fac[i] = 1LL * fac[i - 1] * i % mod;     }     ifac[n] = qpow(fac[n], mod - 2);     for (int i = n - 1; i >= 0; --i) {       ifac[i] = 1LL * ifac[i + 1] * (i + 1) % mod;     }   }   inline int C(int n, int m) {     if (n < m) return 0;     return 1LL * fac[n] * ifac[m] % mod * ifac[n - m] % mod;   }   int main() {     n = read(), m = read();     read(), read();     init(max(n, m));     ans = 1LL * fac[n - 2] * C(m - 1, n - 2) % mod;     for (int i = 1; i < n - 1; ++i) {       ans = (ans + 1LL * C(m - 1, i - 1) * qpow(m, n - i - 1) % mod *                        C(n - 2, i - 1) % mod * fac[i - 1] % mod * (i + 1) % mod *                        qpow(n, n - i - 2)) %             mod;     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 10;   int gi() {     int x = 0, o = 1;     char ch = getchar();     while (!isdigit(ch) && ch !=  - ) ch = getchar();     if (ch ==  - ) o = -1, ch = getchar();     while (isdigit(ch)) x = x * 10 + ch -  0 , ch = getchar();     return x * o;   }   int n, m, a[N], mx[N], mn[N];   map<pair<int, int>, int> f;   map<int, int> lst;   vector<pair<int, int> > key;   set<pair<int, int> > ban;   void work(int *mx) {     f.clear();     lst.clear();     key.clear();     ban.clear();     for (int i = 1; i <= n; i++) key.push_back(make_pair(0, i));     for (int i = 1; i <= m; i++)       if (a[i] > 1) {         key.push_back(make_pair(i, a[i] - 1));         ban.insert(make_pair(i, a[i]));       }     for (int i = 1; i <= m + 1; i++) {       key.push_back(make_pair(i, n));       ban.insert(make_pair(i, n + 1));     }     sort(key.begin(), key.end());     reverse(key.begin(), key.end());     for (auto t : key) {       if (ban.find(make_pair(t.first, t.second + 1)) != ban.end())         lst[t.first - t.second - 1] = t.first;       if (ban.find(make_pair(t.first, t.second)) != ban.end()) continue;       if (lst.count(t.first - t.second)) {         int x = lst[t.first - t.second], y = x - t.first + t.second;         if (ban.find(make_pair(x, y - 1)) != ban.end())           f[t] = f[make_pair(x, y - 2)];         else           f[t] = f[make_pair(x, y - 1)];       } else         f[t] = t.second + m + 1 - t.first;     }     for (int i = 1; i <= n; i++) mx[i] = f[make_pair(0, i)];   }   int main() {     cin >> n >> m;     for (int i = 1; i <= m; i++) a[i] = gi();     if (n == 1) return cout << 0, 0;     work(mx);     for (int i = 1; i <= m; i++) a[i] = n - a[i] + 1;     work(mn);     reverse(mn + 1, mn + n + 1);     for (int i = 1; i <= n; i++) mn[i] = n - mn[i] + 1;     long long ans = 0;     for (int i = 1; i <= n; i++) ans += mx[i] - mn[i] + 1;     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool checkbit(int mask, int bit) { return mask & (1 << bit); }   int setbit(int mask, int bit) { return mask | (1 << bit); }   int clearbit(int mask, int bit) { return mask & ~(1 << bit); }   int togglebit(int mask, int bit) { return mask ^ (1 << bit); }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n;     int l, r, PR, PL;     cin >> n >> l >> r >> PL >> PR;     int ans = INT_MAX;     int a[n + 1];     int PrefixSum[n + 1];     for (int i = 1; i <= n; i++) {       cin >> a[i];     }     PrefixSum[0] = 0;     for (int i = 1; i <= n; i++) PrefixSum[i] = PrefixSum[i - 1] + a[i];     for (int i = 0; i <= n; i++) {       int usedL = i;       int usedR = n - i;       int now = PrefixSum[i] * l + (PrefixSum[n] - PrefixSum[i]) * r;       if (i > n - i) {         now += (2 * i - n - 1) * PL;       }       if (i < n - i) {         now += (n - 2 * i - 1) * PR;       }       ans = min(ans, now);     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int N = 0;     string s;     cin >> N >> s;     map<char, int> number = {{ 0 , 0}, { 1 , 1}, { 2 , 2}, { 3 , 3}, { 4 , 4},                              { 5 , 5}, { 6 , 6}, { 7 , 7}, { 8 , 8}, { 9 , 9}};     int curr_prefix = 0;     for (int i = 0; i < N; i++) {       curr_prefix += number[s[i]];       int curr = 0;       bool flag = false;       for (int j = i + 1; j < N; j++) {         curr += number[s[j]];         if (curr == curr_prefix) {           curr = 0;           flag = true;         }       }       if (curr == 0 && flag) {         cout <<  YES ;         return 0;       }     }     cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n, x;     cin >> n;     long ans = 0;     vector<int> divisiors, dp(1e6 + 1);     dp[0] = 1;     for (int i = 0; i < n; i++) {       cin >> x;       divisiors.clear();       for (int j = 1; j * j <= x; j++) {         if (x % j == 0) {           divisiors.push_back(j);           if (j != x / j) divisiors.push_back(x / j);         }       }       sort(divisiors.begin(), divisiors.end());       reverse(divisiors.begin(), divisiors.end());       for (int z = 0; z < divisiors.size(); z++) {         dp[divisiors[z]] += dp[divisiors[z] - 1];         dp[divisiors[z]] %= (int)1e9 + 7;       }     }     for (int i = 1; i <= 1e6; i++) {       ans += dp[i];       ans %= (int)1e9 + 7;     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e5 + 10;   int N, arr[MAXN], tid[MAXN], a[MAXN], b[MAXN];   int main() {     scanf( %d , &N);     for (int i = (0), iend = (N); i < iend; ++i) scanf( %d , &arr[i]);     iota(tid, tid + N, 0);     sort(tid, tid + N,          [](const int& x, const int& y) { return arr[x] < arr[y]; });     int cur = 0;     for (int _i = ((N + 2) / 3), _iend = (N); _i < _iend; ++_i) {       int i = tid[_i];       if (cur & 1)         a[i] = cur >> 1, b[i] = arr[i] - a[i];       else         b[i] = cur >> 1, a[i] = arr[i] - b[i];       cur++;     }     for (int i = (0), iend = ((N + 2) / 3); i < iend; ++i)       b[tid[i]] = arr[tid[i]];     puts( YES );     for (int i = (0), iend = (N); i < iend; ++i) printf( %d  , a[i]);     puts(  );     for (int i = (0), iend = (N); i < iend; ++i) printf( %d  , b[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a, b, k;   int main() {     cin >> a >> b >> k;     a %= b;     bool ok = false;     int i;     for (i = 0; i < 1000000; i++) {       a *= 10;       int x = a / b;       a %= b;       if (x == k) {         ok = true;         break;       }     }     if (ok)       cout << i + 1 << endl;     else       cout << -1 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double pi = 3.14159265;   using namespace std;   int a[200000];   int main() {     int n, x, y;     scanf( %d , &n);     scanf( %d , &x);     scanf( %d , &y);     fill(a, a + 200000, 2e9);     int count0 = -1;     for (int i = 0; i < n; i++) {       scanf( %d , &a[i + x]);       ;     }     for (int i = 0; i < n; i++) {       for (int j = 1; j <= x; j++) {         if (a[i + x] > a[i + j]) {           goto l;         }       }       for (int j = 1; j <= y; j++) {         if (a[i + x] > a[i + x + j]) {           goto l;         }       }       printf( %d , i + 1);       printf(  n );       break;     l:       0;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long l[2], r[2], k;     cin >> l[0] >> r[0] >> l[1] >> r[1] >> k;     long long max_ow = min(r[0], r[1]);     long long min_ow = max(l[0], l[1]);     long long ans = max_ow - min_ow;     if (max_ow >= k && min_ow <= k) {       ans--;     }     if (ans < 0) {       cout <<  0  << endl;       return 0;     }     cout << ans + 1 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   const int N = 2e5;   int dep[N], fa[N], cnt[N], ans;   int main() {     ios ::sync_with_stdio(0);     cin >> n;     ans = 1;     for (int i = 2; i <= n; ++i) {       cin >> fa[i];       dep[i] = dep[fa[i]] + 1;       cnt[dep[i]] ^= 1;     }     for (int i = 1; i <= n; ++i) ans += cnt[i];     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1.0);   const long long MOD = 1000000000 + 7;   const int MAXN = 100000 + 5;   long long gcd(long long a, long long b) {     if (b == 0) return a;     return gcd(b, a % b);   }   inline long long readLL() {     char ch;     bool flag = false;     long long a = 0;     while (!((((ch = getchar()) >=  0 ) && (ch <=  9 )) || (ch ==  - )))       ;     if (ch !=  - ) {       a *= 10;       a += ch -  0 ;     } else {       flag = true;     }     while (((ch = getchar()) >=  0 ) && (ch <=  9 )) {       a *= 10;       a += ch -  0 ;     }     if (flag) a = -a;     return a;   }   inline int read() {     char ch;     bool flag = false;     int a = 0;     while (!((((ch = getchar()) >=  0 ) && (ch <=  9 )) || (ch ==  - )))       ;     if (ch !=  - ) {       a *= 10;       a += ch -  0 ;     } else {       flag = true;     }     while (((ch = getchar()) >=  0 ) && (ch <=  9 )) {       a *= 10;       a += ch -  0 ;     }     if (flag) a = -a;     return a;   }   const int N = 1000000;   long long prime[N];   bool check[N];   int totp;   void Eular() {     memset(check, false, sizeof(check));     totp = 0;     for (int i = 2; i < N; i++) {       if (!check[i]) prime[totp++] = i;       for (int j = 0; j < totp; j++) {         if (i * prime[j] >= N) break;         check[i * prime[j]] = true;         if (i % prime[j] == 0) break;       }     }   }   int totfj;   long long fj[20];   int numfj[20];   void fenjie(long long n) {     totfj = 0;     for (int i = 0, __END__ = (int)(totp); i < __END__; i++) {       if (n < prime[i]) break;       if (n % prime[i] == 0) {         numfj[totfj] = 0;         fj[totfj] = prime[i];         while (n % prime[i] == 0) n /= prime[i], numfj[totfj]++;         totfj++;       }     }     if (n > 1) {       fj[totfj++] = n;     }   }   int totys;   long long ys[10010];   void getys(long long n) {     fenjie(n);     totys = 0;     ys[totys++] = 1;     int tmp;     long long mul;     for (int i = 0, __END__ = (int)(totfj); i < __END__; i++) {       tmp = totys;       mul = 1;       for (int j = 0, __END__ = (int)(numfj[i]); j < __END__; j++) {         mul *= fj[i];         for (int k = 0, __END__ = (int)(tmp); k < __END__; k++)           ys[totys++] = mul * ys[k];       }     }   }   long long a[1010];   long long b[1010];   int dp[1010][10010];   pair<pair<int, int>, long long> path[1010][10010];   unordered_map<long long, int> zip;   unordered_map<int, long long> unzip;   const int inf = 100000;   const long long infLL = 9000000000000000000LL;   int main() {     Eular();     int n;     n = read();     long long k;     k = readLL();     for (int i = 1, __END__ = (int)(n); i <= __END__; i++) a[i] = readLL();     for (int i = 1, __END__ = (int)(n); i <= __END__; i++) b[i] = gcd(k, a[i]);     if (k == 1) {       int ans = 1;       for (int i = 1, __END__ = (int)(n); i <= __END__; i++)         if (a[ans] > a[i]) ans = i;       cout <<  1  << endl;       cout << ans << endl;       return 0;     }     getys(k);     if (totys >= 10010) return -1;     for (int i = 0, __END__ = (int)(totys); i < __END__; i++)       zip[ys[i]] = i, unzip[i] = ys[i];     for (int i = 0, __END__ = (int)(n + 1); i < __END__; i++)       for (int j = 0, __END__ = (int)(totys); j < __END__; j++) dp[i][j] = inf;     path[n][totys - 1] = make_pair(make_pair(inf, inf), infLL);     path[0][0] = make_pair(make_pair(inf, inf), 0LL);     long long now;     long long nxt;     int inow;     int inxt;     dp[0][0] = 0;     for (int i = 0, __END__ = (int)(n); i < __END__; i++) {       for (int j = 0, __END__ = (int)(totys); j < __END__; j++)         if (dp[i][j] != inf)           if (dp[i + 1][j] == dp[i][j]) {             if (path[i + 1][j].second > path[i][j].second)               path[i + 1][j] = path[i][j];           }       for (int j = 0, __END__ = (int)(totys); j < __END__; j++)         if (dp[i + 1][j] > dp[i][j]) {           dp[i + 1][j] = dp[i][j];           path[i + 1][j] = path[i][j];         }       for (int j = 0, __END__ = (int)(totys); j < __END__; j++)         if (dp[i][j] != inf) {           now = unzip[j];           nxt = gcd(k / b[i + 1], now) * b[i + 1];           inxt = zip[nxt];           if (dp[i + 1][inxt] == dp[i][j] + 1) {             if (path[i + 1][inxt].second > path[i][j].second + a[i + 1])               path[i + 1][inxt] =                   make_pair(make_pair(i, j), path[i][j].second + a[i + 1]);           }           if (dp[i + 1][inxt] > dp[i][j] + 1) {             dp[i + 1][inxt] = dp[i][j] + 1;             path[i + 1][inxt] =                 make_pair(make_pair(i, j), path[i][j].second + a[i + 1]);           }         }     }     if (dp[n][totys - 1] == inf) {       puts( -1 );       return 0;     }     printf( %d n , dp[n][totys - 1]);     pair<int, int> pit(n, totys - 1);     int flag = 1;     while (pit.first != inf && pit.second != inf) {       pit = path[pit.first][pit.second].first;       if (pit.first == inf) break;       if (flag)         flag = 0;       else         printf(   );       printf( %d , pit.first + 1);     }     puts(  );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1E3 + 5, M = 11;   int n, d;   long long dp[N][M][N], inv[M] = {1}, ans, mo;   inline void upd(long long &x, long long y) {     x += y;     if (x >= mo) x -= mo;   }   long long Pow(long long a, int b = mo - 2) {     long long res = 1;     for (; b; b >>= 1, a = a * a % mo)       if (b & 1) res = res * a % mo;     return res;   }   long long C(int n, int m) {     long long res = inv[m];     for (int i = n - m + 1; i <= n; ++i) res = res * i % mo;     return res;   }   long long f(int i, int j, int k) {     if (dp[i][j][k] != -1) return dp[i][j][k];     if (i == 1) return dp[i][j][k] = !j || j == d - 1;     if (i > j * k + 1) return 0;     long long res = f(i, j, k - 1);     for (int t = 1; t * k < i && t <= j; ++t)       upd(res,           f(i - t * k, j - t, k - 1) * C(f(k, d - 1, k - 1) + t - 1, t) % mo);     return dp[i][j][k] = res;   }   int main() {     scanf( %d%d%lld , &n, &d, &mo);     if (n == 1) return 0 * printf( 1 n );     if ((n - 2) % (d - 1)) return 0 * printf( 0 n );     memset(dp, -1, sizeof dp);     for (long long i = 1, j = 1; i <= d; ++i) {       j = j * i % mo;       inv[i] = Pow(j);     }     ans = f(n, d, n >> 1);     if (n & 1)       ;     else       ans -= C(f(n / 2, d - 1, n / 2 - 1), 2);     printf( %lld n , (ans % mo + mo) % mo);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long t;   long long a[200005];   int main() {     ios_base::sync_with_stdio(false);     cin >> t;     while (t--) {       long long n;       cin >> n;       for (int i = 1; i <= n; i++) {         cin >> a[i];         if (a[i] >= 0)           a[i] %= n;         else {           long long x = abs(a[i] / n);           a[i] = a[i] + n * (x + 5);           a[i] %= n;         }       }       vector<long long> v;       map<long long, long long> m;       for (int i = 1; i <= n; i++) {         v.push_back(((i - 1) + a[i]) % n);         m[((i - 1) + a[i]) % n]++;       }       bool flag = false;       for (auto x : v) {         if (m[x] > 1) {           flag = 1;         }       }       if (!flag)         cout <<  yes ;       else         cout <<  no ;       cout << endl;     }   }


#include <bits/stdc++.h>   time_t st = clock();   using namespace std;   template <class stl>   void DBGSTL(stl a) {     cout <<   tDEBUG: n t ;     for (typeof(a.begin()) i = a.begin(); i != a.end(); i++) {       cerr << *i <<    ;     }     cerr <<   n ;     return;   }   long long gcd(long long a, long long b) { return (b == 0 ? a : gcd(b, a % b)); }   long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }   double mathround(double x) {     int intx = (int)x;     if (x < intx + 0.5) return intx;     return intx + 1;   }   int main() {     int n;     int p[100];     vector<int> ans;     cin >> n;     for (int i = 0; i < n; i++) cin >> p[i];     getchar();     int cnt = 0;     int loss = 0;     for (int i = 0; i < n; i++) {       if (p[i] < 0) loss++;       if (loss == 3) {         loss = 1;         ans.push_back(cnt);         cnt = 0;       }       cnt++;     }     if (cnt > 0) ans.push_back(cnt);     cout << (int)(ans).size() << endl;     for (int i = 0; i < (int)(ans).size(); i++) cout << ans[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   long long a[333333];   const long long MOD = 1000000009;   long long fib[333333];   long long fsum[333333];   inline const long long getFsum(const int l, const int r) {     return ((fsum[r] - fsum[l - 1]) + MOD) % MOD;   }   inline void pllAdd(pair<long long, long long>& des,                      const pair<long long, long long>& toAdd) {     if (des.first < 0) des = pair<long long, long long>(0, 0);     des.first += toAdd.first;     des.second += toAdd.second;     des.first %= MOD;     des.second %= MOD;   }   class a_sum {    public:     vector<long long> c;     vector<pair<long long, long long> > lazy;     a_sum() {       c = vector<long long>(4 * n + 1, 0);       lazy = vector<pair<long long, long long> >(           4 * n + 1, pair<long long, long long>(-1, -1));       for (int i = 1; i <= n; i++) init(i);     }     void init(const int index, const int nodeLeft, const int nodeRight,               const int node) {       c[node] += a[index];       c[node] %= MOD;       if (nodeLeft == nodeRight) return;       int mid = (nodeLeft + nodeRight) / 2;       if (index <= mid)         init(index, nodeLeft, mid, node * 2);       else         init(index, mid + 1, nodeRight, node * 2 + 1);     }     void init(const int index) { init(index, 1, n, 1); }     long long query(const int left, const int right, const int nodeLeft,                     const int nodeRight, const int node) {       int mid = (nodeLeft + nodeRight) / 2;       if (lazy[node].first >= 0) {         const long long a = lazy[node].first, b = lazy[node].second;         int size = nodeRight - nodeLeft + 1;         if (size == 1) {           c[node] += a;           c[node] %= MOD;         } else {           const long long x = getFsum(1, size - 2) + 1, y = getFsum(1, size - 1);           long long toAdd = ((a * x) % MOD + (b * y) % MOD) % MOD;           c[node] += toAdd;           c[node] %= MOD;           pllAdd(lazy[node * 2], pair<long long, long long>(a, b));           int nextIndex = mid - nodeLeft + 2;           pllAdd(lazy[node * 2 + 1],                  pair<long long, long long>(((a * fib[nextIndex - 2]) % MOD +                                              b * fib[nextIndex - 1] % MOD) %                                                 MOD,                                             ((a * fib[nextIndex - 1]) % MOD +                                              (b * fib[nextIndex]) % MOD) %                                                 MOD));         }         lazy[node] = pair<long long, long long>(-1, -1);       }       if (left <= nodeLeft && nodeRight <= right) return c[node];       if (nodeLeft > right || nodeRight < left) return 0;       return (query(left, right, nodeLeft, mid, node * 2) +               query(left, right, mid + 1, nodeRight, node * 2 + 1)) %              MOD;     }     long long query(const int left, const int right) {       return query(left, right, 1, n, 1);     }     void modify(const int left, const int right, const int nodeLeft,                 const int nodeRight, const int node) {       int mid = (nodeLeft + nodeRight) / 2;       if (lazy[node].first >= 0) {         const long long a = lazy[node].first, b = lazy[node].second;         int size = nodeRight - nodeLeft + 1;         if (size == 1) {           c[node] += a;           c[node] %= MOD;         } else {           const long long x = getFsum(1, size - 2) + 1, y = getFsum(1, size - 1);           long long toAdd = ((a * x) % MOD + (b * y) % MOD) % MOD;           c[node] += toAdd;           c[node] %= MOD;           pllAdd(lazy[node * 2], pair<long long, long long>(a, b));           int nextIndex = mid - nodeLeft + 2;           pllAdd(lazy[node * 2 + 1],                  pair<long long, long long>(((a * fib[nextIndex - 2]) % MOD +                                              b * fib[nextIndex - 1] % MOD) %                                                 MOD,                                             ((a * fib[nextIndex - 1]) % MOD +                                              (b * fib[nextIndex]) % MOD) %                                                 MOD));         }         lazy[node] = pair<long long, long long>(-1, -1);       }       if (nodeLeft > right || nodeRight < left) return;       if (left <= nodeLeft && nodeRight <= right) {         long long toAdd = getFsum(nodeLeft - left + 1, nodeRight - left + 1);         c[node] += toAdd;         c[node] %= MOD;         if (nodeLeft != nodeRight) {           pllAdd(lazy[node * 2],                  pair<long long, long long>(fib[nodeLeft - left + 1],                                             fib[nodeLeft - left + 2]));           pllAdd(lazy[node * 2 + 1],                  pair<long long, long long>(fib[mid - left + 2],                                             fib[mid - left + 3]));         }         return;       }       modify(left, right, nodeLeft, mid, node * 2);       modify(left, right, mid + 1, nodeRight, node * 2 + 1);       c[node] = (c[node * 2] + c[node * 2 + 1]) % MOD;     }     void modify(const int left, const int right) { modify(left, right, 1, n, 1); }   };   int main() {     fib[1] = fib[2] = 1;     for (int i = 3; i <= 300000; i++) fib[i] = (fib[i - 1] + fib[i - 2]) % MOD;     for (int i = 1; i <= 300000; i++) fsum[i] = (fsum[i - 1] + fib[i]) % MOD;     cin >> n >> m;     for (int i = 1; i <= n; i++) cin >> a[i];     a_sum g = a_sum();     for (int i = 0; i < m; i++) {       int x, y, z;       cin >> x >> y >> z;       if (x == 1)         g.modify(y, z);       else         cout << g.query(y, z) << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   string s, s2, t1, t2;   int main() {     long long n, l, r, i, j;     cin >> s;     n = s.length();     char mx =  a ;     for (i = n - 1; i >= 0; i--) {       if (s[i] - mx >= 0) {         mx = s[i];         l = i;       }     }     s2 += mx;     r = l;     for (i = mx -  a ; i >= 0; i--) {       char aa =  a  + i;       l = r;       for (j = l + 1; j < n; j++) {         if (s[j] == aa) {           s2 += s[j];           r = j;         }       }     }     cout << s2 << endl;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   void OUT(T x, int n) {     for (int i = 0; i < n; ++i) cout << x[i] <<    ;     cout << endl;   }   template <class T>   void OUT(T x, int n, int m) {     for (int i = 1; i <= n; ++i) OUT(x[i], m);     cout << endl;   }   template <class T>   void checkmod(T& a, T m) {     a = (a % m + m) % m;   }   inline long long mod(long long x, long long y) {     return x - floor(1.0 * x / y + 1e-8) * y;   }   const int maxn = 50005, INF = 0x7fffffff;   int n, m;   int p[105];   char name[105][35];   int c[105], Count = 0;   char s[35];   bool comp(int a, int b) { return a > b; }   int main() {     int i, j, k, t, T, x, y, sum, index;     scanf( %d%d , &n, &m);     for (i = 0; i < n; i++) scanf( %d , p + i);     sort(p, p + n);     for (i = 1; i <= m; i++) {       scanf( %s , s);       for (j = 0; j < Count; j++) {         if (strcmp(s, name[j]) == 0) {           c[j]++;           break;         }       }       if (j == Count) c[Count]++, strcpy(name[Count++], s);     }     sort(c, c + Count, comp);     int minp = 0, maxp = 0;     for (i = 0; i < Count; i++) {       minp += p[i] * c[i];     }     for (i = 0; i < Count; i++) {       maxp += p[n - i - 1] * c[i];     }     printf( %d %d n , minp, maxp);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool binary(vector<int> v, int key) {     int lo = 0, hi = v.size() - 1;     while (lo <= hi) {       int mid = (lo + hi) / 2;       if (v[mid] == key)         return true;       else if (v[mid] < key)         lo = mid + 1;       else         hi = mid - 1;     }     return false;   }   int main() {     int n, ans = 0, l = 0, r = 0, u = 0, d = 0;     cin >> n;     vector<pair<int, int>> v;     for (int i = 0; i < n; i++) {       int t1, t2;       cin >> t1 >> t2;       v.push_back(make_pair(t1, t2));     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         if (v[j].first == v[i].first && v[j].second < v[i].second) d++;         if (v[j].first == v[i].first && v[j].second > v[i].second) u++;         if (v[j].first < v[i].first && v[j].second == v[i].second) l++;         if (v[j].first > v[i].first && v[j].second == v[i].second) r++;       }       if (d && r && l && u) ans++;       d = 0, r = 0, l = 0, u = 0;     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using i64 = int_fast64_t;   using seika = string;   template <class kizuna>   using akari = vector<kizuna>;   template <class yuzuki>   using yukari = akari<akari<yuzuki>>;   template <class tsurumaki>   using maki = akari<yukari<tsurumaki>>;   template <class kotonoha>   using akane = priority_queue<kotonoha, akari<kotonoha>, greater<kotonoha>>;   template <class kotonoha>   using aoi = priority_queue<kotonoha>;   inline void print() { cout << endl; }   template <typename First, typename... Rest>   void print(const First &first, const Rest &...rest) {     cout << first <<    ;     print(rest...);   }   void solve() {     int n;     cin >> n;     akari<int> as(n);     for (int i = 0; i < n; i++) {       cin >> as[i];       as[i] &= 1;     }     stack<int> st;     int now = -1, cur = 0;     as.push_back(-1);     for (int a : as) {       if (a == now) {         cur++;       } else {         if (cur & 1) {           if (!st.empty() && st.top() == now) {             st.pop();           } else if (now != -1) {             st.push(now);           }         }         now = a;         cur = 1;       }     }     if (st.size() < 2) {       cout <<  YES  << endl;     } else {       cout <<  NO  << endl;     }   }   int main() {     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   ostream& operator<<(ostream& os, const vector<T>& v) {     for (auto i : v) os << i <<    ;     return os;   }   template <typename T>   ostream& operator<<(ostream& os, const set<T>& v) {     for (auto i : v) os << i <<    ;     return os;   }   const int N = 41;   const int dx[] = {1, 1, 2, 2, -1, -1, -2, -2};   const int dy[] = {2, -2, 1, -1, 2, -2, 1, -1};   using pii = pair<int, int>;   int db[N][N];   int dw[N][N];   int ex[N][N];   bool vis[N][N];   int n, m;   void init() {     pii S = {n / 2, m / 2};     queue<pii> q;     q.push(S);     memset(dw, 0x3f, sizeof(dw));     dw[n / 2][m / 2] = 0;     while (!q.empty()) {       pii u = q.front();       q.pop();       if (vis[u.first][u.second]) continue;       vis[u.first][u.second] = true;       for (int i = 0; i < 8; ++i) {         pii v;         v.first = u.first + dx[i];         v.second = u.second + dy[i];         if (v.first > 0 && v.first <= n && v.second > 0 && v.second <= m) {           q.push(v);           dw[v.first][v.second] =               min(dw[u.first][u.second] + 1, dw[v.first][v.second]);         }       }     }     S = {n / 2 + 1, m / 2};     memset(db, 0x3f, sizeof(db));     memset(vis, 0, sizeof(vis));     db[n / 2 + 1][m / 2] = 0;     q.push(S);     while (!q.empty()) {       pii u = q.front();       q.pop();       if (vis[u.first][u.second]) continue;       vis[u.first][u.second] = true;       for (int i = 0; i < 8; ++i) {         pii v;         v.first = u.first + dx[i];         v.second = u.second + dy[i];         if (v.first > 0 && v.first <= n && v.second > 0 && v.second <= m) {           q.push(v);           db[v.first][v.second] =               min(db[u.first][u.second] + 1, db[v.first][v.second]);         }       }     }     S = {n / 2, m / 2};     memset(ex, 0x3f, sizeof(ex));     for (int i = 0; i < 8; ++i) {       pii v;       v = {S.first + dx[i], S.second + dy[i]};       q.push(v);       ex[v.first][v.second] = 0;     }     memset(vis, 0, sizeof(vis));     while (!q.empty()) {       pii u = q.front();       q.pop();       if (vis[u.first][u.second]) continue;       vis[u.first][u.second] = true;       for (int i = 0; i < 8; ++i) {         pii v;         v.first = u.first + dx[i];         v.second = u.second + dy[i];         if (v.first > 0 && v.first <= n && v.second > 0 && v.second <= m) {           q.push(v);           ex[v.first][v.second] =               min(ex[u.first][u.second] + 1, ex[v.first][v.second]);         }       }     }     ex[S.first][S.second] = -1;   }   bool inside(pii x) {     return x.first >= 1 && x.second >= 1 && x.first <= n && x.second <= m;   }   int main() {     scanf( %d%d , &n, &m);     init();     pii w, b;     scanf( %d%d%d%d , &w.first, &w.second, &b.first, &b.second);     pii TW = {n / 2, m / 2};     pii TB = {n / 2 + 1, m / 2};     bool atk, reach;     atk = true;     reach = false;     for (int i = 0; i < 8; ++i) {       pii v;       v = {w.first + dx[i], w.second + dy[i]};       if (!inside(v)) continue;       bool flag = false;       for (int j = 0; j < 8; ++j) {         pii w;         w = {b.first + dx[j], b.second + dy[j]};         if (w == v) flag = true;       }       if (!flag) atk = false;       if (v == TW) {         if (flag) atk = true;         reach = true;         break;       }     }     if (reach && !atk) {       printf( WHITE n );       printf( %d %d n , TW.first, TW.second);       fflush(stdout);       return 0;     }     int BB = db[b.first][b.second];     int WW = dw[w.first][w.second];     int BW = dw[b.first][b.second];     int WB = db[w.first][w.second];     if (WW + 1 <= BW && WW <= BB) {       printf( WHITE n );       fflush(stdout);       while (w != TW) {         for (int i = 0; i < 8; ++i) {           pii tmp;           tmp = {w.first + dx[i], w.second + dy[i]};           if (!inside(tmp)) continue;           if (dw[tmp.first][tmp.second] < dw[w.first][w.second]) {             w = tmp;             printf( %d %d n , w.first, w.second);             fflush(stdout);             if (w == b) return 0;             if (w != TW) scanf( %d%d , &b.first, &b.second);             break;           }         }       }       return 0;     }     if (BB + 2 <= WB && BB + 1 <= WW) {       printf( BLACK n );       fflush(stdout);       while (b != TB) {         for (int i = 0; i < 8; ++i) {           pii tmp;           tmp = {b.first + dx[i], b.second + dy[i]};           if (!inside(tmp)) continue;           if (db[tmp.first][tmp.second] < db[b.first][b.second]) {             b = tmp;             printf( %d %d n , tmp.first, tmp.second);             fflush(stdout);             if (b == w) return 0;             if (b != TB) scanf( %d%d , &w.first, &w.second);             break;           }         }       }       return 0;     }     if (((w.first + w.second) & 1) ^ ((b.first + b.second) & 1)) {       printf( WHITE n );       fflush(stdout);       if (WW <= BB) {         while (w != TW) {           for (int i = 0; i < 8; ++i) {             pii tmp;             tmp = {w.first + dx[i], w.second + dy[i]};             if (!inside(tmp)) continue;             if (dw[tmp.first][tmp.second] < dw[w.first][w.second]) {               printf( %d %d n , tmp.first, tmp.second);               fflush(stdout);               w = tmp;               if (w == b) return 0;               scanf( %d%d , &b.first, &b.second);               break;             }           }         }       } else {         while (w != TB) {           for (int i = 0; i < 8; ++i) {             pii tmp;             tmp = {w.first + dx[i], w.second + dy[i]};             if (!inside(tmp)) continue;             if (db[tmp.first][tmp.second] < db[w.first][w.second]) {               printf( %d %d n , tmp.first, tmp.second);               fflush(stdout);               w = tmp;               if (w == b) return 0;               scanf( %d%d , &b.first, &b.second);               break;             }           }         }         for (int i = 0; i < 8; ++i) {           pii tmp;           tmp = {w.first + dx[i], w.second + dy[i]};           if (!inside(tmp)) continue;           if (tmp == b) return 0 * printf( %d %d n , tmp.first, tmp.second);         }         while (w != TW) {           for (int i = 0; i < 8; ++i) {             pii tmp;             tmp = {w.first + dx[i], w.second + dy[i]};             if (!inside(tmp)) continue;             if (dw[tmp.first][tmp.second] < dw[w.first][w.second]) {               printf( %d %d n , tmp.first, tmp.second);               fflush(stdout);               w = tmp;               if (w == b) return 0;               scanf( %d%d , &b.first, &b.second);               break;             }           }         }       }       return 0;     } else {       printf( BLACK n );       fflush(stdout);       scanf( %d%d , &w.first, &w.second);       if (WW >= BB) {         while (b != TB) {           for (int i = 0; i < 8; ++i) {             pii tmp;             tmp = {b.first + dx[i], b.second + dy[i]};             if (!inside(tmp)) continue;             if (db[tmp.first][tmp.second] < db[b.first][b.second]) {               b = tmp;               printf( %d %d n , tmp.first, tmp.second);               fflush(stdout);               if (w == b) return 0;               scanf( %d%d , &w.first, &w.second);               break;             }           }         }       } else {         while (b != TW) {           for (int i = 0; i < 8; ++i) {             pii tmp;             tmp = {b.first + dx[i], b.second + dy[i]};             if (!inside(tmp)) continue;             if (dw[tmp.first][tmp.second] < dw[b.first][b.second]) {               b = tmp;               printf( %d %d n , tmp.first, tmp.second);               fflush(stdout);               if (w == b) return 0;               scanf( %d%d , &w.first, &w.second);               break;             }           }         }         for (int i = 0; i < 8; ++i) {           pii tmp;           tmp = {b.first + dx[i], b.second + dy[i]};           if (!inside(tmp)) continue;           if (tmp == w) return 0 * printf( %d %d n , tmp.first, tmp.second);         }         while (b != TB) {           for (int i = 0; i < 8; ++i) {             pii tmp;             tmp = {b.first + dx[i], b.second + dy[i]};             if (!inside(tmp)) continue;             if (db[tmp.first][tmp.second] < db[b.first][b.second]) {               b = tmp;               printf( %d %d n , tmp.first, tmp.second);               fflush(stdout);               if (w == b) return 0;               scanf( %d%d , &w.first, &w.second);               break;             }           }         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> v[3 * 100005];   int n, m, nr, h[3 * 100005], f[3 * 100005], a[3 * 100005], b[3 * 100005],       t[3 * 100005], q;   void dfs(int x) {     for (auto it : v[x])       if (h[it] == 0) {         t[it] = x;         h[it] = h[x] + 1;         dfs(it);       }   }   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     cin >> n >> m;     for (int i = 1; i <= m; i++) {       int x, y;       cin >> x >> y;       v[x].push_back(y);       v[y].push_back(x);     }     cin >> q;     for (int i = 1; i <= q; i++) {       cin >> a[i] >> b[i];       f[a[i]]++;       f[b[i]]++;     }     for (int i = 1; i <= n; i++)       if (f[i] % 2) nr++;     if (nr) {       cout <<  NO n  << nr / 2;       return 0;     }     cout <<  YES n ;     h[1] = 1;     dfs(1);     for (int i = 1; i <= q; i++) {       vector<int> unu;       vector<int> doi;       while (h[a[i]] > h[b[i]]) {         unu.push_back(a[i]);         a[i] = t[a[i]];       }       while (h[a[i]] < h[b[i]]) {         doi.push_back(b[i]);         b[i] = t[b[i]];       }       while (a[i] != b[i]) {         unu.push_back(a[i]);         doi.push_back(b[i]);         a[i] = t[a[i]];         b[i] = t[b[i]];       }       cout << unu.size() + doi.size() + 1 <<   n ;       for (auto it : unu) cout << it <<    ;       cout << a[i] <<    ;       for (int j = doi.size() - 1; j >= 0; j--) cout << doi[j] <<    ;       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char str[100005];   int main() {     cin.getline(str, 100005);     int y = 0;     int l = strlen(str);     int has = 0;     for (int i = 0; i < l; i++) {       if (y == 1 && str[i] !=    ) {         cout << str[i];         continue;       }       if (str[i] ==    ) {         if (y == 0) {           y = 1;           if (has) {             cout <<  >  << endl;             has = 0;           }           cout <<  < ;         } else if (y == 1) {           cout <<  >  << endl;           y = 0;         }         continue;       }       if (str[i] ==    ) {         if (has) {           cout <<  >  << endl;           has = 0;         }         continue;       }       if (has)         cout << str[i];       else {         has = 1;         cout <<  <  << str[i];       }     }     if (str[l - 1] !=     && str[l - 1] !=    ) cout <<  >  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n, k, p, total = 0;     cin >> n;     k = (n - 11) / 2;     for (int i = 1; i <= n; i++) {       char temp;       cin >> temp;       if (temp ==  8 ) {         total++;         if (total == k + 1) p = i;       }     }     if (total <= k)       cout <<  NO ;     else {       p -= k;       if ((p - 1) <= k)         cout <<  YES ;       else         cout <<  NO ;     }   }


#include <bits/stdc++.h>   using namespace std;   const long long inf = 1e15;   void Tez() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }   int main() {     Tez();     long long n, k;     cin >> n >> k;     long long cap[k];     for (int i = 0; i < k; i++) cin >> cap[i];     long long tp = 1, no = 0, maxam = 0;     for (int i = 0; i < k; i++) {       long long x = n / cap[i];       long long am = x * cap[i];       if (am > maxam) {         no = x;         maxam = am;         tp = i + 1;       }     }     cout << tp <<     << no;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int vis[2000007];   string s;   int main() {     int n, k, i, j, l, x, len = 0, pos;     string in;     cin >> n;     for (i = 0; i < 2000007; i++) s +=  a ;     for (i = 0; i < n; i++) {       cin >> in >> k;       pos = -(int)in.length();       for (j = 1; j <= k; j++) {         cin >> x;         len = max(len, x + (int)in.length());         for (l = max(0, pos + (int)in.length() - x); l < in.length(); l++)           s[l + x] = in[l];         pos = x;       }     }     for (i = 1; i < len; i++) cout << s[i];     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const int maxn = 502;   int a[maxn][maxn];   int izq[maxn][maxn], arr[maxn][maxn];   void solve() {     int n, m;     cin >> n >> m;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         char c;         cin >> c;         if (c ==  . ) a[i][j] = 1;       }     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         izq[i][j] = izq[i][j - 1];         if (a[i][j] && a[i][j - 1]) {           izq[i][j]++;         }       }     }     for (int j = 1; j <= m; j++) {       for (int i = 1; i <= n; i++) {         arr[i][j] = arr[i - 1][j];         if (a[i][j] && a[i - 1][j]) {           arr[i][j]++;         }       }     }     int q;     cin >> q;     while (q--) {       int r1, c1, r2, c2;       cin >> r1 >> c1 >> r2 >> c2;       long long int ans = 0;       for (int f = r1; f <= r2; f++) {         long long int res = izq[f][c2] - izq[f][c1 - 1];         if (a[f][c1] && a[f][c1 - 1]) res--;         ans += res;       }       for (int c = c1; c <= c2; c++) {         long long int res = arr[r2][c] - arr[r1 - 1][c];         if (a[r1][c] && a[r1 - 1][c]) res--;         ans += res;       }       cout << ans <<   n ;     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int t = 1;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   const int dx[] = {1, -1, 0, 0};   const int dy[] = {0, 0, -1, 1};   using namespace std;   long long tests;   long long n, m, b, MOD, dp[5256][5256], a[5256], ans;   void solve() {     scanf( %I64d%I64d%I64d%I64d , &n, &m, &b, &MOD);     for (int i = 1; i <= n; i += 1) {       scanf( %I64d , &a[i]);     }     dp[0][0] = 1;     for (int i = 1; i <= n; i += 1)       for (int j = 0; j <= m; j += 1)         for (int k = 0; k <= b; k += 1)           if (k + a[i] <= b) {             dp[j + 1][k + a[i]] += dp[j][k];             dp[j + 1][k + a[i]] %= MOD;           }     for (int i = 0; i <= b; i += 1) {       ans += dp[m][i];       ans %= MOD;     }     printf( %I64d , ans);   }   int main() { solve(); }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); }   long long min(long long a, long long b) { return a < b ? a : b; }   long long max(long long a, long long b) { return a > b ? a : b; }   long long max3(long long a, long long b, long long c) {     return max(max(a, b), c);   }   long long max4(long long a, long long b, long long c, long long d) {     return max(max(a, b), max(c, d));   }   long long min3(long long a, long long b, long long c) {     return min(min(a, b), c);   }   long long min4(long long a, long long b, long long c, long long d) {     return min(min(a, b), min(c, d));   }   long long po(long long x, long long n, long long mod = 1000000007) {     if (n == 0) {       return 1;     }     long long m = po(x, n / 2, mod);     m *= m;     m %= mod;     if (n % 2) {       m *= x;       m %= mod;     }     return m;   }   long long n, k;   vector<string> v(2005);   vector<string> num{ 1110111 ,  0010010 ,  1011101 ,  1011011 ,  0111010 ,                       1101011 ,  1101111 ,  1010010 ,  1111111 ,  1111011 };   long long check(string a, string b) {     long long count = 0;     for (long long i = 0; i < 7; i++) {       if (a[i] ==  1  && b[i] ==  0 ) {         return -1;       } else if (a[i] ==  0  && b[i] ==  1 ) {         count++;       }     }     return count;   }   bool comp(char a, char b) {     if (b ==  - ) {       return 1;     } else if (a ==  - ) {       return 0;     }     return a >= b;   }   vector<long long> ans;   long long dp[2005][2005];   bool stored[2005][2005];   long long solve(long long rem, long long index) {     if (rem < 0) {       return -1;     }     if (stored[rem][index]) {       return dp[rem][index];     }     if (index == n - 1) {       for (long long j = 9; j >= 0; j--) {         if (check(v[index], num[j]) == rem) {           stored[rem][index] = 1;           ans.push_back(j);           return dp[rem][index] = 1;         }       }       stored[rem][index] = 1;       return dp[rem][index] = -1;     }     stored[rem][index] = 1;     for (long long j = 9; j >= 0; j--) {       if (check(v[index], num[j]) == -1) {         continue;       }       if (solve(rem - check(v[index], num[j]), index + 1) != -1) {         ans.push_back(j);         return dp[rem][index] = 1;       }     }     return dp[rem][index] = -1;   }   int32_t main() {     cin.tie(0);     cout.tie(0);     ios_base::sync_with_stdio(false);     cin.tie(NULL);     clock_t startTime = clock();     cout << fixed << setprecision(12);     cin >> n >> k;     for (long long i = 0; i < n; i++) cin >> v[i];     if (solve(k, 0) == -1) {       cout << -1;     } else {       reverse((ans).begin(), (ans).end());       for (long long i = 0; i < n; i++) {         cout << ans[i];       }     }   }


#include <bits/stdc++.h>   using namespace std;   inline char gc() {     static char buf[100000], *p1 = buf, *p2 = buf;     return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2)                ? EOF                : *p1++;   }   inline long long read() {     long long x = 0;     char ch = getchar();     bool positive = 1;     for (; !isdigit(ch); ch = getchar())       if (ch ==  - ) positive = 0;     for (; isdigit(ch); ch = getchar()) x = x * 10 + ch -  0 ;     return positive ? x : -x;   }   inline void write(long long a) {     if (a < 0) {       a = -a;       putchar( - );     }     if (a >= 10) write(a / 10);     putchar( 0  + a % 10);   }   inline void writeln(long long a) {     write(a);     puts(  );   }   inline void wri(long long a) {     write(a);     putchar(   );   }   const int N = 100005, M = 1 << 18 | 3;   const long long inf = 1e18;   int n, ans, w[N], g[N], h[N];   long long lim, pre[N], suf[N], max_p[M], lazy[M], max_suf[M], sp[M];   vector<int> v[N];   stack<int> q;   inline void cao(int nod, long long de) {     lazy[nod] += de;     max_suf[nod] += de;     sp[nod] += de;   }   inline void pushdown(int nod) {     if (lazy[nod]) {       cao(nod << 1, lazy[nod]);       cao(nod << 1 | 1, lazy[nod]);       lazy[nod] = 0;     }   }   long long calc(int l, int r, long long dq, int nod) {     if (l == r) return dq - max_p[nod];     pushdown(nod);     int mid = (l + r) >> 1;     return dq > max_suf[nod << 1]                ? min(dq - max_p[nod << 1], calc(mid + 1, r, dq, nod << 1 | 1))                : min(sp[nod], calc(l, mid, dq, nod << 1));   }   void build(int l, int r, int nod) {     if (l == r) {       max_suf[nod] = max_p[nod] = suf[l];       return;     }     int mid = (l + r) >> 1;     build(l, mid, nod << 1);     build(mid + 1, r, nod << 1 | 1);     max_p[nod] = max(max_p[nod << 1], max_p[nod << 1 | 1]);     max_suf[nod] = max(max_suf[nod << 1], max_suf[nod << 1 | 1]),     sp[nod] = calc(mid + 1, r, max_suf[nod << 1], nod << 1 | 1);   }   void insert(int l, int r, int i, int j, long long de, int nod) {     if (i > j) return;     if (l == i && r == j) {       cao(nod, de);       return;     }     pushdown(nod);     int mid = (l + r) >> 1;     if (j <= mid)       insert(l, mid, i, j, de, nod << 1);     else if (i > mid)       insert(mid + 1, r, i, j, de, nod << 1 | 1);     else {       insert(l, mid, i, mid, de, nod << 1);       insert(mid + 1, r, mid + 1, j, de, nod << 1 | 1);     }     max_suf[nod] = max(max_suf[nod << 1], max_suf[nod << 1 | 1]),     sp[nod] = calc(mid + 1, r, max_suf[nod << 1], nod << 1 | 1);   }   int solve(int l, int r, long long dq, int nod) {     if (l == r) return dq - max_p[nod] > lim ? 0 : l;     pushdown(nod);     int mid = (l + r) >> 1;     if (dq - max_p[nod << 1 | 1] <= lim)       return solve(mid + 1, r, dq, nod << 1 | 1);     else       return solve(l, mid, dq, nod << 1);   }   int ask(int l, int r, long long dq, int nod) {     if (l == r) return dq - max_p[nod] > lim ? 0 : l;     pushdown(nod);     int mid = (l + r) >> 1;     if (sp[nod] > lim && dq <= max_suf[nod << 1])       return ask(l, mid, dq, nod << 1);     int ans = ask(mid + 1, r, max(dq, max_suf[nod << 1]), nod << 1 | 1);     return ans ? ans : solve(l, mid, dq, nod << 1);   }   void solve(int x) {     h[++*h] = x;     int l = 0, r = *h;     while (l < r) {       int mid = (l + r + 1) >> 1;       if (pre[x] - pre[h[mid]] <= lim)         r = mid - 1;       else         l = mid;     }     insert(1, n, 1, x - 1, -inf, 1);     if (l) insert(1, n, h[l], n, inf, 1);     ans = max(ans, ask(1, n, -inf, 1) - x + 1);     if (l) insert(1, n, h[l], n, -inf, 1);     insert(1, n, 1, x - 1, inf, 1);     for (auto i : v[x]) {       insert(1, n, x - 1, n, pre[i] - pre[x], 1);       solve(i);       insert(1, n, x - 1, n, pre[x] - pre[i], 1);     }     (*h)--;   }   int main() {     n = read();     lim = read();     for (int i = 1; i < n; i++) w[i] = read();     for (int i = 1; i <= n; i++) g[i] = read();     for (int i = 1; i < n; i++) {       pre[i + 1] = pre[i] - w[i] + g[i];       suf[i + 1] = suf[i] - w[i] + g[i + 1];     }     build(1, n, 1);     for (int i = 1; i <= n; i++) {       while (q.size() && pre[i] < pre[q.top()]) {         v[i].push_back(q.top());         q.pop();       }       q.push(i);     }     while (q.size()) {       solve(q.top());       q.pop();     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   string s;   char a;   int b, c, d, i, k, n;   int main() {     cin >> s;     k = s.size();     if (k < 2) d = 1;     while (n < 100 && d == 0) {       while (i < k - 2 && d == 0) {         if (s[i] > s[i + 2]) {           a = s[i + 2];           s[i + 2] = s[i];           s[i] = a;         }         i += 2;       }       n++;       i = 0;     }     cout << s;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, k;   struct Edge {     int u;     int v;   } e[1000000];   int dp[3000][3000];   bool Judge1(int x, int y) {     for (int i = 0; i < n; i++)       if (!(x & (1 << i)) && (y & (1 << i))) return false;     return true;   }   bool Judge2(int u, int v, int x, int y) {     if ((1 << (u - 1)) & x && !((1 << (v - 1)) & x)) return true;     return false;   }   int Count(int x) {     int ret = 0;     for (int i = 0; i < n; i++)       if ((1 << i) & x) ret++;     return ret;   }   void PUT(int x) {     for (int i = 0; i < n; i++)       if (x & (1 << i))         cout << 1;       else         cout << 0;   }   int ans;   int main() {     cin >> n >> m >> k;     for (int i = 1; i <= m; i++) {       cin >> e[i].u >> e[i].v;       int temp = 0;       temp |= (1 << (e[i].u - 1));       temp |= (1 << (e[i].v - 1));       dp[temp][temp] = 1;     }     for (int i = 0; i <= (1 << n) - 1; i++)       for (int j = 0; j <= (1 << n) - 1; j++)         if (Judge1(i, j))           for (int g = 1; g <= m; g++) {             if (Judge2(e[g].u, e[g].v, i, j)) {               int temp = j;               temp |= (1 << (e[g].v - 1));               if (temp & (1 << (e[g].u - 1))) temp ^= (1 << (e[g].u - 1));               bool pd = false;               for (int q = e[g].v + 1; q <= n; q++)                 if ((1 << (q - 1)) & temp) {                   pd = true;                   break;                 }               int st = i;               st |= 1 << (e[g].v - 1);               if (!pd) dp[st][temp] += dp[i][j];             } else if (Judge2(e[g].v, e[g].u, i, j)) {               swap(e[g].v, e[g].u);               int temp = j;               temp |= (1 << (e[g].v - 1));               if (temp & (1 << (e[g].u - 1))) temp ^= (1 << (e[g].u - 1));               bool pd = false;               for (int q = e[g].v + 1; q <= n; q++)                 if ((1 << (q - 1)) & temp) {                   pd = true;                   break;                 }               int st = i;               st |= 1 << (e[g].v - 1);               if (!pd) dp[st][temp] += dp[i][j];             }           }     for (int i = 0; i <= (1 << n) - 1; i++)       for (int j = 0; j <= (1 << n) - 1; j++) {         if (Count(j) == k && (i == ((1 << n) - 1))) ans += dp[i][j];       }     cout << ans << endl;     return 0;   }


#include<bits/stdc++.h>   using namespace std;   int main()   {       int t;       cin>>t;       while(t--)       {           int a,b,c;           cin>>a>>b>>c;           int sum=a+b+c;           if(sum<7)               cout<< No <<endl;           else           {               if(sum%9==0)               {                   sum=sum/9;                   if(a>=sum && b>=sum && c>=sum)                       cout<< Yes <<endl;                   else                       cout<< No <<endl;               }               else                   cout<< No <<endl;           }       }       return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int x, d;     cin >> x >> d;     long long start = 1;     vector<long long> arr;     while (x > 0) {       int toPrint = 1;       while ((1LL << toPrint) - 1 <= x) toPrint++;       toPrint--;       for (long long i = start; i < start + toPrint; i++) arr.push_back(start);       start += toPrint + d + 1;       x -= ((1LL << toPrint) - 1);     }     if (arr.size() > 1e4 || start >= 1e18) {       cout <<  -1 ;       return 0;     }     cout << arr.size() << endl;     for (int i = 0; i < arr.size(); i++) cout << arr[i] <<    ;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   int T, n, m;   int t1, t2;   bool w;   map<pair<int, long long>, int> mex;   int solve(int rem = 60, long long msk = (1 << 60) - 1) {     if (mex.count({rem, msk})) {       return mex[{rem, msk}];     }     mex[{rem, msk}] = 0;     int x = 0;     set<int> s;     for (int i = 1; i <= rem; ++i) {       if ((msk >> i) & 1)         s.insert(             solve(rem - i, ((1ll << (rem - i + 1)) - 1) & (msk & ~(1ll << i))));     }     while (s.count(x)) ++x;     return mex[{rem, msk}] = x;   }   int main() {     scanf( %d , &n);     scanf( %d , &t1);     T = solve(t1, (1ll << t1 + 1) - 1);     for (int i = 1; i < n; ++i) {       scanf( %d , &t1);       T ^= solve(t1, (1ll << t1 + 1) - 1);     }     if (T) {       printf( NO );     } else {       printf( YES );     }     printf(  n );   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 5, M = 2e3 + 5;   const long long INF = 1e18 + 5;   inline long long read() {     long long sum = 0, fh = 1;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) fh = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       sum = sum * 10 + c -  0 ;       c = getchar();     }     return sum * fh;   }   inline int read2() {     char c = getchar();     while (c <  0  || c >  9 ) c = getchar();     return c -  0 ;   }   inline int read3() {     char c = getchar();     while (c <  a  || c >  z ) {       c = getchar();     }     return c -  a ;   }   inline void write(long long x) {     if (x < 0) putchar( - ), x = -x;     if (x > 9) write(x / 10);     putchar(x % 10 +  0 );   }   inline int gcd(int x, int y) { return y == 0 ? x : gcd(y, x % y); }   inline long long ab(long long x) { return x < 0 ? -x : x; }   inline long long fpow(long long qwe, long long asd, long long zxc) {     if (asd < 0) return 0;     long long a = qwe, b = 1, c = asd;     while (c) {       if (c & 1) b = b * a % zxc;       a = a * a % zxc;       c >>= 1;     }     return b;   }   struct miaow {     int f, t, l;     long long c;     miaow(int f = 0, int t = 0, long long c = 0, int l = 0)         : f(f), t(t), c(c), l(l) {}   } imap[N * 2 + 5];   int str[N * 2 + 5] = {0}, cou = 2;   inline void jb(int f, int t, long long c = 0) {     imap[cou] = miaow(f, t, c, str[f]);     str[f] = cou++;     imap[cou] = miaow(t, f, c, str[t]);     str[t] = cou++;   }   struct meow {     long long t, x, y;     meow(long long t = 0, long long x = 0, long long y = 0) : t(t), x(x), y(y) {}     inline bool operator<(const meow& qwe) const {       return t == qwe.t ? x < qwe.x : t > qwe.t;     }   };   int sy[N][2];   long long dp[N][2], zz[N], p = 1e9 + 7, ans = 0;   priority_queue<meow> qwe;   int main() {     int n = read(), m = read();     long long q = read(), ny = fpow(2, p - 2, p);     meow zxczxc = (0, 0, 0);     for (int i = 1; i <= m; ++i) {       int x = read(), y = read(), z = read();       jb(x, y, z);       zxczxc = min(zxczxc, meow(z, x, y));     }     sy[1][0] = 1;     int cs = 1;     for (int i = 1; i <= min(q, m * 2 + (long long)1); ++i) {       for (int j = 1; j <= n; ++j) dp[i][cs] = sy[i][cs] = 0, zz[i] = 0;       long long sum = 0;       for (int j = 2; j < cou; ++j) {         int f = imap[j].f, t = imap[j].t;         long long c = imap[j].c;         if (sy[f][cs ^ 1]) {           sy[t][cs] = 1;           if (dp[t][cs] < dp[f][cs ^ 1] + c) {             dp[t][cs] = dp[f][cs ^ 1] + c;             zz[t] = c;           } else if (dp[t][cs] == dp[f][cs ^ 1] + c && c > zz[t])             zz[t] = c;           sum = max(sum, dp[t][cs]);         }       }       cs ^= 1;       if (i != m * 2 + 1ll || i == q) ans = (ans + sum) % p;     }     long long t = m * 2 + 1, x = 0, y = 0;     vector<meow> zzz;     for (int i = 1; i <= n; ++i) {       long long y1 = zz[i], x1 = dp[i][1];       if (x1 > x) {         x = x1, y = y1;       } else if (x1 == x && y1 > y)         y = y1;       for (int j = i + 1; j <= n; ++j) {         long long y2 = zz[j], x2 = dp[j][1];         long long x3 = x1, y3 = y1;         if (y2 < y3) {           if (x2 <= x3) continue;           swap(y3, y2), swap(x3, x2);         } else if (y2 > y3) {           if (x2 >= x3) continue;         } else           continue;         long long tt = (x3 - x2) / (y2 - y3);         qwe.push(meow(t + tt + 1, x2 + (tt + 1) * y2, y2));         if (x2 + (tt + 1) * y2 < 0) exit(1);       }     }     long long ttt = t, aaa = ans, xxx = x, yyy = y;     if (t > q) {       cout << ans << endl;       return 0;     }     qwe.push(meow(q, 0, 0));     long long tbj = 0;     while (t < q) {       meow asd = qwe.top();       qwe.pop();       long long t2 = asd.t, x2 = asd.x, y2 = asd.y;       if (t2 < t) continue;       if (t2 != t)         ans = (ans + (x + x + (t2 - t - 1) * y) % p * (t2 - t) % p * ny % p) % p;       x = x + y * (t2 - t);       if (x < x2) {         if (!tbj) tbj = t2;         x = x2, y = y2;       } else if (x == x2 && y < y2) {         if (!tbj) tbj = t2;         y = y2;       }       t = t2;     }     ans = (ans + x) % p;     if (ans == 30604365) {       for (int i = 0; i < zzz.size(); ++i)         cout << zzz[i].t <<     << zzz[i].x <<     << zzz[i].y << endl;     }     if (ans == 30604365) cout << x <<     << y <<     << t <<     << tbj << endl;     if (ans == 30604365)       cout << xxx <<     << yyy <<     << ttt <<     << aaa << endl;     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void fre() {     freopen( c://test//input.in ,  r , stdin);     freopen( c://test//output.out ,  w , stdout);   }   template <class T1, class T2>   inline void gmax(T1 &a, T2 b) {     if (b > a) a = b;   }   template <class T1, class T2>   inline void gmin(T1 &a, T2 b) {     if (b < a) a = b;   }   const int N = 0, M = 0, Z = 1e9 + 7, ms63 = 0x3f3f3f3f;   int casenum, casei;   long long n;   void solve1e6(long long n) {     int step = 0;     while (n) {       int x = n;       int mx = 0;       while (x) gmax(mx, x % 10), x /= 10;       n -= mx;       ++step;     }     printf( %d n , step);   }   struct A {     long long x;     int y;     void add(const A &b) {       x += b.x;       y = b.y;     }   };   int a[20];   A f[20][10][10];   A dp(int p, int mx, int tim, int tp) {     if (p == -1) {       if (mx == 0) return {0, 0};       if (tim) return {0, tim - 1};       return {1, mx - 1};     }     if (!tp && ~f[p][mx][tim].x) return f[p][mx][tim];     A ret = {0, tim};     int top = tp ? a[p] : 9;     for (int i = top; i >= 0; --i) {       ret.add(dp(p - 1, max(mx, i), ret.y, tp && i == top));     }     if (!tp) f[p][mx][tim] = ret;     return ret;   }   void solve1e18(long long n) {     int p = -1;     while (n) a[++p] = n % 10, n /= 10;     if (p == -1) a[++p] = 0;     for (int i = 0; i <= p; ++i) {       for (int j = 0; j < 10; ++j) {         for (int k = 0; k < 10; ++k) f[i][j][k].x = -1;       }     }     printf( %lld n , dp(p, 0, 0, 1).x);   }   int main() {     while (~scanf( %lld , &n)) {       solve1e18(n);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct xy {     int x, y;   };   int a[1212121], par[1212121], depth[1212121];   vector<int> C[1212121];   void dfs(int w, int dep) {     depth[w] = dep;     for (int nxt : C[w]) dfs(nxt, dep + 1);   }   int Hn = 0, myH[1212121], sz[1212121], root[1212121], ppar[1212121];   int find(int x) {     if (ppar[x] == x) return x;     return ppar[x] = find(ppar[x]);   }   multiset<int> S[1212121], ansS;   void push(int x) {     sz[x] = 1;     int mx = 0, mxw;     for (int child : C[x]) {       sz[x] += sz[child];       if (mx < sz[child] && S[myH[child]].size() > 0) mx = sz[child], mxw = child;     }     if (mx == 0) {       int hIdx = ++Hn;       myH[x] = hIdx;       root[hIdx] = x;       S[hIdx].insert(depth[x]);       ppar[hIdx] = hIdx;       ansS.insert(0);     } else {       int hIdx = myH[x] = myH[mxw];       root[hIdx] = x;       int dep = (*S[hIdx].rbegin()) - depth[mxw];       ansS.erase(ansS.find(dep));       S[hIdx].insert(depth[x]);       for (int child : C[x])         if (child != mxw) {           if (!S[myH[child]].empty()) {             for (auto &v : S[myH[child]]) S[hIdx].insert(v);             ppar[myH[child]] = hIdx;             int dep = (*S[myH[child]].rbegin()) - depth[child];             ansS.erase(ansS.find(dep));           }           S[myH[child]].clear();         }       dep = (*S[hIdx].rbegin()) - depth[x];       ansS.insert(dep);     }   }   void pop(int x) {     int hIdx = find(myH[x]);     int dep = (*S[hIdx].rbegin()) - depth[root[hIdx]];     ansS.erase(ansS.find(dep));     S[hIdx].erase(S[hIdx].find(depth[x]));     if (S[hIdx].empty()) return;     dep = (*S[hIdx].rbegin()) - depth[root[hIdx]];     ansS.insert(dep);   }   int main() {     int n, k, i, j;     scanf( %d%d , &n, &k);     for (i = 1; i <= n; i++) scanf( %d , &a[i]);     vector<xy> ST;     ST.push_back({n + 1, n + 1});     for (i = n; i >= 1; i--) {       while (ST.back().x <= a[i]) ST.pop_back();       par[i] = ST.back().y;       C[par[i]].push_back(i);       ST.push_back({a[i], i});     }     dfs(n + 1, 0);     for (i = 1; i <= n; i++) {       push(i);       if (k <= i) {         printf( %d  , *ansS.rbegin() + 1);         if (i != n) pop(i - k + 1);       }     }     return 0;   }


#include <bits/stdc++.h>   int main() {     int x, y;     scanf( %d %d , &x, &y);     printf( %d , (x * y - 1) / (y - 1));   }


#include <bits/stdc++.h>   using namespace std;   int a[210][210], b[210][210];   int n, m;   int main() {     while (cin >> n >> m) {       int ra = 1, rb = 1, ca = 1, cb = 1;       for (int i = 1; i <= m; i++)         if (i % 2) {           a[ra++][ca] = i;           if (ra > n) ra = 1, ca++;         } else {           b[rb++][cb] = i;           if (rb > n) rb = 1, cb++;         }       for (int i = 1; i <= n; i++) {         for (int j = ca; j >= 1; j--) {           if (!a[i][j]) continue;           cout << a[i][j] <<    ;         }         for (int j = cb; j >= 1; j--) {           if (!b[i][j]) continue;           cout << b[i][j] <<    ;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, bear, ans, a, aux, votes[128];   priority_queue<int> q;   int Solution() {     int ans = 0;     while (bear <= q.top()) {       aux = q.top();       if (bear <= aux) {         bear++;         aux--;         q.pop();         q.push(aux);         ans++;       }     }     return ans;   }   int main() {     scanf( %d , &n);     scanf( %d , &bear);     for (int i = 0; i < n - 1; ++i) {       scanf( %d , &a);       q.push(a);     }     ans = Solution();     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long fpm(long long b, long long e, long long m) {     long long t = 1;     for (; e; e >>= 1, b = b * b % m) e & 1 ? t = t * b % m : 0;     return t;   }   template <class T>   inline bool chkmin(T &a, T b) {     return a > b ? a = b, true : false;   }   template <class T>   inline bool chkmax(T &a, T b) {     return a < b ? a = b, true : false;   }   template <class T>   inline T sqr(T x) {     return x * x;   }   template <class edge>   struct Graph {     vector<vector<edge> > adj;     Graph(int n) {       adj.clear();       adj.resize(n + 5);     }     void adde(int s, edge e) { adj[s].push_back(e); }     typename vector<edge>::iterator operator[](int t) { return adj[t].begin(); }   };   const int maxn = 1100;   typedef int arr32[maxn];   arr32 col, row, vrow, vcol;   int noans, mod;   int main() {     ios_base::sync_with_stdio(false);     int n, m, K;     cin >> n >> m >> K;     for (int i = 1; i <= n; ++i) row[i] = m, vrow[i] = 1;     for (int j = 1; j <= m; ++j) col[j] = n, vcol[j] = 1;     for (int i = 1, a, b, c; i <= K; ++i)       cin >> a >> b >> c, --row[a], --col[b], vrow[a] *= c, vcol[b] *= c;     int unx = 0;     if (K < n) {       for (int i = 1; i <= n; ++i)         if (row[i])           unx += row[i] - 1;         else if (vrow[i] != -1)           noans = 1;       unx -= m - 1;     } else {       for (int j = 1; j <= m; ++j)         if (col[j])           unx += col[j] - 1;         else if (vcol[j] != -1)           noans = 1;       unx -= n - 1;     }     cin >> mod;     if (noans || (n & 1) != (m & 1))       cout << 0 << endl;     else       cout << fpm(2, unx, mod) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 1e5 + 3;   map<int, vector<int>> sign;   int a[MAX];   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     multiset<int> st;     for (int i = 1; i <= n; i++) {       cin >> a[i];       st.insert(a[i]);     }     vector<pair<int, int>> v;     for (int i = 0; i < n - 1; i++) {       int x = *st.rbegin();       st.erase(st.find(x));       int y = *st.rbegin();       st.erase(st.find(y));       st.insert(x - y);       v.push_back({x, y});     }     int S = *st.rbegin();     sign[S].push_back(1);     for (int i = n - 2; i >= 0; i--) {       int x = v[i].first, y = v[i].second;       int p = sign[x - y].back();       sign[x - y].pop_back();       sign[x].push_back(p), sign[y].push_back(p ^ 1);     }     for (int i = 1; i <= n; i++) {       if (sign[a[i]].back())         cout <<  + ;       else         cout <<  - ;       sign[a[i]].pop_back();     }   }


#include <bits/stdc++.h>   using namespace std;   int num[105];   double cal(int w, int e, int s) {     if (e < s) return 1.0;     double res = 1, dw = (double)w, de = (double)e;     for (int i = 0; i < s; i++) {       res = res * de / dw;       dw--;       de--;     }     return 1.0 - res;   }   int main() {     int n, m, h;     int s;     while (~scanf( %d%d%d , &n, &m, &h)) {       s = 0;       for (int i = 1; i <= m; i++) {         scanf( %d , &num[i]);         s += num[i];       }       if (s < n)         printf( -1.0 n );       else {         printf( %.7lf n , cal(s - 1, s - num[h], n - 1));       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const ll M = 1e4 + 10;   const ll G = 1e3 + 10;   ll n, m, g, r;   vector<ll> d;   ll ansDep = -1;   ll ansT = -1;   bool seen[M][G];   ll ans = 1e17;   void bfs() {     deque<tuple<ll, ll, ll> > q;     q.emplace_front(0, 0, 0);     while (!q.empty()) {       auto at = q.front();       q.pop_front();       ll v = get<0>(at), tempo = get<1>(at), dep = get<2>(at);       if (v == m - 1) {         ans = min(ans, (r + g) * dep + tempo);         continue;       }       seen[v][tempo] = true;       ll distance = d[v + 1] - d[v];       ll nt = distance + tempo;       if (nt <= g and !seen[v + 1][nt % g]) {         seen[v + 1][nt % g] = true;         if (nt == g) {           if (v + 1 != m - 1)             q.emplace_back(v + 1, 0, dep + 1);           else             q.emplace_back(v + 1, g, dep);         } else           q.emplace_front(v + 1, nt, dep);       }       if (v > 0) {         distance = d[v] - d[v - 1];         nt = distance + tempo;         if (nt <= g and !seen[v - 1][nt % g]) {           seen[v - 1][nt % g] = true;           if (nt == g)             q.emplace_back(v - 1, 0, dep + 1);           else             q.emplace_front(v - 1, nt, dep);         }       }     }   }   int main() {     ios::sync_with_stdio(false);     memset(seen, false, sizeof seen);     cin >> n >> m;     d.resize(m);     for (ll &i : d) cin >> i;     sort(d.begin(), d.end());     cin >> g >> r;     bfs();     if (ans == 1e17)       cout <<  -1 n ;     else       cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long res, cur, n, dp[1000006];   struct info {     long long x, y;     long long a;     bool operator<(const info &b) const { return x < b.x; }   };   struct P {     long long x, y;     P operator+(const P &a) const { return (P){x + a.x, y + a.y}; }     P operator-(const P &a) const { return (P){x - a.x, y - a.y}; }     long long operator*(const P &a) const {       double u, v;       if (x == 0 && a.x == 0) return 0;       if (x == 0) {         if (y == 0) return 0;         return 2 * ((y > 0 && a.x < 0) || (y < 0 && a.x > 0)) - 1;       }       if (a.x == 0) {         if (a.y == 0) return 0;         return 2 * ((a.y > 0 && x > 0) || (a.y < 0 && x < 0)) - 1;       }       u = y;       u /= x;       v = a.y;       v /= a.x;       if (u == v) return 0;       return (2 * (v > u) - 1) *              (2 * ((x > 0 && a.x > 0) || (x < 0 && a.x < 0)) - 1);     }     long long V(long long pos, int k) { return (pos - x) * k + y; }   };   vector<info> var;   vector<P> vex;   int main() {     scanf( %d , &n);     var.resize(n + 1);     var[0] = (info){0, INT_MAX, 0};     for (int i = 1; i <= n; i++) {       scanf( %d %d %lld , &var[i].x, &var[i].y, &var[i].a);     }     sort(var.begin(), var.end());     vex.push_back((P){0, 0});     for (int i = 1; i <= n; i++) {       while (cur < vex.size() - 1 &&              vex[cur].V(var[i].x, var[i].y) < vex[cur + 1].V(var[i].x, var[i].y))         cur++;       dp[i] = vex[cur].V(var[i].x, var[i].y) - var[i].a;       P lar = (P){var[i].x, dp[i]};       while (vex.size() > 1 &&              (lar - vex[vex.size() - 2]) *                      (vex[vex.size() - 1] - vex[vex.size() - 2]) <=                  0) {         if (cur == vex.size() - 1) cur--;         vex.pop_back();       }       vex.push_back(lar);     }     for (int i = 0; i <= n; i++) res = max(res, dp[i]);     printf( %lld , res);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   bool chkmin(T &x, T y) {     return x > y ? x = y, 1 : 0;   }   template <typename T>   bool chkmax(T &x, T y) {     return x < y ? x = y, 1 : 0;   }   int readint() {     int x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x * f;   }   const int cys = 1000000009;   int n, m, tot;   long long d[105][105], siz[105], tmp[105], ans[105], v[20005], nxt[20005],       h[105], fac[105], inv[105], rt[105], f[105][105], rs[105];   bool vis[105];   long long mod(long long x) { return x >= cys ? x - cys : x; }   long long qpow(long long x, long long p) {     long long ret = 1;     for (; p; p >>= 1, x = x * x % cys)       if (p & 1) ret = ret * x % cys;     return ret;   }   void addedge(int x, int y) {     v[++tot] = y;     nxt[tot] = h[x];     h[x] = tot;     v[++tot] = x;     nxt[tot] = h[y];     h[y] = tot;   }   void dfs(int u, int r) {     memset(d[u], 0, sizeof(d[u]));     d[u][0] = 1;     siz[u] = 1;     if (r) rt[u] = r;     int cnt = 0;     for (int p = h[u]; p; p = nxt[p]) {       if (vis[v[p]]) {         cnt++;         continue;       }       vis[v[p]] = 1;       dfs(v[p], r);       for (int i = 0; i <= siz[u] + siz[v[p]]; i++) tmp[i] = 0;       for (int i = 0; i < siz[u]; i++)         for (int j = 0; j <= siz[v[p]]; j++)           tmp[i + j] = mod(tmp[i + j] + d[u][i] * d[v[p]][j] % cys * fac[i + j] %                                             cys * inv[i] % cys * inv[j] % cys);       siz[u] += siz[v[p]];       for (int i = 0; i <= siz[u]; i++) d[u][i] = tmp[i];     }     if (cnt <= 1) d[u][siz[u]] = d[u][siz[u] - 1];     if (u == r) rs[u] = siz[u];   }   int main() {     n = readint();     m = readint();     fac[0] = inv[0] = 1;     for (int i = 1; i <= n; i++) fac[i] = fac[i - 1] * i % cys;     inv[n] = qpow(fac[n], cys - 2);     for (int i = n - 1; i >= 1; i--) inv[i] = inv[i + 1] * (i + 1) % cys;     for (int i = 1; i <= m; i++) addedge(readint(), readint());     ans[0] = 1;     for (int i = 1; i <= n; i++) {       if (!vis[i]) {         vis[i] = true;         dfs(i, i);         for (int j = 0; j <= n; j++) f[i][j] = d[i][j];       } else {         for (int j = 1; j <= n; j++)           if (rt[j] == rt[i]) vis[j] = 0;         vis[i] = true;         dfs(i, 0);         for (int j = 0; j <= n; j++) f[rt[i]][j] = mod(f[rt[i]][j] + d[i][j]);       }     }     for (int i = 1; i <= n; i++) {       if (rt[i] == i) {         for (int j = 0; j < rs[i]; j++)           f[i][j] = f[i][j] * fac[rs[i] - j - 1] % cys * inv[rs[i] - j] % cys;         for (int j = 0; j <= n; j++) tmp[j] = 0;         for (int j = 0; j <= n; j++)           for (int k = 0; k <= n; k++)             tmp[j + k] = mod(tmp[j + k] + ans[j] * f[i][k] % cys * fac[j + k] %                                               cys * inv[j] % cys * inv[k] % cys);         for (int j = 0; j <= n; j++) ans[j] = tmp[j];       }     }     for (int i = 0; i <= n; i++) printf( %lld n , ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int gcd(long long int a, long long int b) {     if (b == 0) return a;     return gcd(b, a % b);   }   long long int lcm(long long int a, long long int b) {     return (a / gcd(a, b)) * b;   }   long long int dp[2005][2005];   long long int help(long long int n, long long int k, long long int num) {     if (k <= 0) return 1;     if (dp[k][num] != -1) return dp[k][num];     long long int cnt = 0;     for (long long int j = num; j <= n; j += num) {       cnt = (cnt % 1000000007 + help(n, k - 1, j) % 1000000007) % 1000000007;     }     return dp[k][num] = cnt;   }   void solve() {     long long int n, k;     cin >> n >> k;     long long int ans = help(n, k, 1);     cout << ans << endl;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int t = 1;     memset(dp, -1, sizeof(dp));     while (t--) solve();   }


#include <bits/stdc++.h>   using namespace std;   void calc(int n, long long s, long long m, int i) {     if (n == 0) return;     s = s / 2;     if (s < m) {       calc(n - 1, s, m - s, i + 1);       cout << i <<    ;     } else {       cout << i <<    ;       calc(n - 1, s, m, i + 1);     }   }   int main() {     int N;     long long M;     cin >> N >> M;     long long a = 1;     for (int i = 0; i < N - 1; i++) a *= 2;     calc(N, a, M, 1);     cout << endl;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ld = long double;   using uint = unsigned int;   using ull = unsigned long long;   template <typename T>   using pair2 = pair<T, T>;   using pii = pair<int, int>;   using pli = pair<ll, int>;   using pll = pair<ll, ll>;   mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());   ll myRand(ll B) { return (ull)rng() % B; }   clock_t startTime;   double getCurrentTime() {     return (double)(clock() - startTime) / CLOCKS_PER_SEC;   }   const double eps = 1e-7;   bool eq(double x, double y) { return abs(x - y) < eps; }   bool ls(double x, double y) { return x < y && !eq(x, y); }   bool lseq(double x, double y) { return x < y || eq(x, y); }   double sqr(double x) { return x * x; }   struct Point {     double x, y;     Point() : x(), y() {}     Point(double _x, double _y) : x(_x), y(_y) {}     void scan() { scanf( %lf%lf , &x, &y); }     void print() { printf( %.12lf %.12lf n , x, y); }     Point operator+(const Point &a) const { return Point(x + a.x, y + a.y); }     Point operator-(const Point &a) const { return Point(x - a.x, y - a.y); }     Point operator*(const double &k) const { return Point(x * k, y * k); }     Point operator/(const double &k) const { return Point(x / k, y / k); }     double operator%(const Point &a) const { return x * a.x + y * a.y; }     double operator*(const Point &a) const { return x * a.y - y * a.x; }     double sqrLen() const { return *this % *this; }     double len() const { return sqrt(sqrLen()); }     Point norm() const { return *this / len(); }     Point ort() const { return Point(-y, x); }   };   double getAngle(Point v, Point u) { return atan2(v * u, v % u); }   bool onLine(Point A, Point B, Point C) { return eq((A - B) * (A - C), 0); }   bool onSegm(Point A, Point B, Point C) {     if (!onLine(A, B, C)) return false;     return lseq((A - B) % (C - B), 0);   }   bool intersectLines(Point A, Point a, Point B, Point b, Point &I) {     if (eq(a * b, 0)) return false;     double y = ((A - B) * a) / (b * a);     I = B + b * y;     return true;   }   Point getH(Point P, Point A, Point a) {     return A + a * (((P - A) % a) / a.sqrLen());   }   bool intersectLineCircle(Point A, Point a, Point O, double R, Point &I1,                            Point &I2) {     Point H = getH(O, A, a);     double x = (O - H).len();     if (ls(R, x)) return false;     if (eq(R, x)) {       I1 = I2 = H;       return true;     }     a = a.norm();     x = sqrt(sqr(R) - sqr(x));     I1 = H + a * x;     I2 = H - a * x;     return true;   }   bool intersectCircles(Point O1, double R1, Point O2, double R2, Point &I1,                         Point &I2) {     if (R1 < R2) {       swap(O1, O2);       swap(R1, R2);     }     double L = (O1 - O2).len();     if (ls(R1 + R2, L) || ls(L, R1 - R2) || eq(L, 0)) return false;     if (eq(R1 + R2, L) || eq(L, R1 - R2)) {       I1 = I2 = O1 + (O2 - O1).norm() * R1;       return true;     }     double x = (sqr(R1) - sqr(R2) + sqr(L)) / (2 * L);     Point a = (O2 - O1).norm();     Point H = O1 + a * x;     a = a.ort();     x = sqrt(sqr(R1) - sqr(x));     I1 = H + a * x;     I2 = H - a * x;     return true;   }   bool isInside(Point P, Point O, double R) {     return lseq((P - O).sqrLen(), sqr(R));   }   vector<vector<Point>> a;   vector<double> sz;   bool insidePoly(Point P, vector<Point> w) {     int m = (int)w.size() - 1;     for (int i = 0; i < m; i++)       if (onSegm(w[i], P, w[i + 1])) return true;     double ang = 0;     for (int i = 0; i < m; i++) ang += getAngle(w[i] - P, w[i + 1] - P);     return abs(ang) > 1;   }   bool checkPoly(vector<Point> w, Point O, double R) {     if (insidePoly(O, w)) return true;     int m = (int)w.size() - 1;     for (int i = 0; i < m; i++) {       if (isInside(w[i], O, R)) return true;       Point H = getH(O, w[i], w[i + 1] - w[i]);       if (isInside(H, O, R) && onSegm(w[i], H, w[i + 1])) return true;     }     return false;   }   vector<Point> readPoly() {     int n;     scanf( %d , &n);     vector<Point> a(n + 1);     for (int i = 0; i < n; i++) a[i].scan();     a[n] = a[0];     return a;   }   double sizePoly(vector<Point> w) {     double S = 0;     int m = (int)w.size() - 1;     for (int i = 0; i < m; i++) S += w[i] * w[i + 1];     return abs(S) / 2;   }   int main() {     startTime = clock();     double R;     int n, w;     scanf( %lf%lf%d , &R, &R, &n);     a.resize(n);     sz.resize(n);     for (int i = 0; i < n; i++) {       a[i] = readPoly();       sz[i] = sizePoly(a[i]);     }     int q;     scanf( %d , &q);     while (q--) {       Point O;       O.scan();       scanf( %lf , &R);       vector<int> res;       double S = 0;       for (int i = 0; i < n; i++) {         if (checkPoly(a[i], O, R)) {           res.push_back(i);           S += sz[i];         }       }       printf( %.12lf %d , S, (int)res.size());       for (int x : res) printf(  %d , x);       printf(  n );     }     return 0;   }


#include <bits/stdc++.h>   using std::cin;   using std::cout;   using std::endl;   using std::pair;   using std::string;   using std::swap;   using std::vector;   void doit(int& xk, int& yk, int w, int h, int x, int y, int z) {     for (int i = 0; i < x; ++i) {       swap(xk, yk);       swap(w, h);       xk = w - xk + 1;     }     if (y) {       xk = w - xk + 1;     }     for (int i = 0; i < z; ++i) {       swap(xk, yk);       swap(w, h);       yk = h - yk + 1;     }   }   int main() {     int n, m, x, y, z, p;     scanf( %d %d %d %d %d %d , &n, &m, &x, &y, &z, &p);     x %= 4;     y = y & 1;     z %= 4;     while (p--) {       int xk, yk;       scanf(  n%d %d , &yk, &xk);       doit(xk, yk, m, n, x, y, z);       printf( %d %d n , yk, xk);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const int INF = 0x3f3f3f3f;   const int mxN = 61;   ll level[mxN];   int q;   int getlevel(ll x) {     int res = 0;     while ((1LL << res) <= x) {       res++;     }     return res - 1;   }   int main() {     cin.tie(0)->sync_with_stdio(0);     cin >> q;     ll a, b, c;     for (int i = 0; i < q; ++i) {       cin >> a;       if (a == 1 || a == 2) {         cin >> b >> c;         if (a == 1) {           level[getlevel(b)] += c;         } else {           int l = getlevel(b);           for (int i = l; i < 61; ++i) {             level[i] = (level[i] + c * (1LL << (i - l))) % (1LL << i);           }         }       } else {         cin >> b;         int l = getlevel(b);         ll out = b - (1LL << l);         out = (out + level[l]) % (1LL << l);         if (out < 0) {           out = out + (1LL << l);         }         out = (out + (1LL << l));         for (int i = l; i >= 0; --i) {           ll ans = (out - (1LL << i) - level[i]) % (1LL << i);           if (ans < 0) {             ans += (1LL << i);           }           ans = (ans + (1LL << i));           cout << ans <<    ;           out /= 2;         }         cout <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long int n, i, x = 0;     cin >> n;     string second;     cin >> second;     vector<long long int> v;     if (second.size() == 1 && second[0] ==  ? ) return cout <<  Yes , 0;     for (i = 0; i < second.size(); ++i) {       if (second[i] ==  ? ) v.push_back(i);       if (i != n - 1 && second[i] == second[i + 1] && second[i] !=  ? )         return cout <<  No , 0;     }     for (i = 0; i < v.size(); ++i) {       if (v[i] == 0 || v[i] == second.size() - 1) return cout <<  Yes , 0;       if (i != v.size() - 1 && v[i] == v[i + 1] - 1) return cout <<  Yes , 0;     }     for (i = 0; i < second.size(); ++i) {       if (second[i] ==  ? ) {         if (i >= 0 && i < n - 1) {           if (second[i - 1] == second[i + 1]) return cout <<  Yes , 0;         }       }     }     cout <<  No ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;      #define ll long long   #define mod 1000000007   #define ffor(i,a,b) for(int i=a;i<b;i++)   #define bfor(i,a,b) for(int i=a-1;i>=b;i--)   #define mp make_pair   #define pb push_back   #define ff first   #define ss second   #define mem(x,y) memset(x,y,sizeof(x))   #define all(x) x.begin(),x.end()   #define SP(x) setprecision(x)   #define sz(x) (int)x.size()   #define fast  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)   #define PI 3.14159265358979323846   #define lb lower_bound   #define ub upper_bound   #define bs binary_search   #define endl   n    #define int long long      void solve()   {       int n;       cin>>n;       int c[n];       int a[n], b[n];          ffor(i,0,n) cin>>c[i];       ffor(i,0,n) cin>>a[i];       ffor(i,0,n) cin>>b[i];          int ans=0;       int dp[n];       mem(dp,0);       dp[1]=abs(a[1]-b[1])+c[1]-1+2;          ffor(i,2,n)       {           if(a[i]==b[i]) dp[i]=c[i]-1+2;           else           {               int x=abs(a[i]-b[i])+c[i]-1+2;               int y=c[i]-1+2+dp[i-1]-abs(a[i]-b[i]);               dp[i]=max(x,y);           }       }       cout<< *max_element(dp,dp+n)<<endl;      }      signed main()   {           #ifndef ONLINE_JUDGE       freopen( input.txt ,  r , stdin);       freopen( output.txt ,  w , stdout);       #endif                   int t;       cin>>t;       while(t--)       {           solve();       }          return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e3 + 5;   int N, M;   long long tree[4][MAXN][MAXN];   int ju(int x, int y) {     int tt = 0;     if (x % 2) tt++;     if (y % 2) tt += 2;     return tt;   }   void Update(int x, int y, long long v) {     int ty = ju(x, y);     for (int i = x; i <= N; i += i & -i)       for (int j = y; j <= N; j += j & -j) tree[ty][i][j] ^= v;   }   long long Sum(int x, int y) {     int ty = ju(x, y);     long long ans = 0;     for (int i = x; i > 0; i -= i & -i)       for (int j = y; j > 0; j -= j & -j) ans ^= tree[ty][i][j];     return ans;   }   int main() {     while (~scanf( %d %d , &N, &M)) {       memset(tree, 0, sizeof(tree));       for (int i = 1; i <= M; ++i) {         int a, b, c, d;         int ty;         long long v;         scanf( %d , &ty);         if (ty == 2) {           scanf( %d %d %d %d %lld , &a, &b, &c, &d, &v);           Update(a, b, v);           Update(c + 1, b, v);           Update(a, d + 1, v);           Update(c + 1, d + 1, v);         } else {           long long ans = 0;           scanf( %d %d %d %d , &a, &b, &c, &d);           ans ^= Sum(c, d);           ans ^= Sum(a - 1, d);           ans ^= Sum(c, b - 1);           ans ^= Sum(a - 1, b - 1);           printf( %lld n , ans);         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e9 + 7;   const int N = 4e5 + 10;   vector<int> ans[N];   vector<int> v[N];   int tot;   int vis[N];   int cnt = 0;   void dfs(int x) {     vis[x] = 1;     ans[cnt++ / tot].push_back(x);     for (auto &y : v[x]) {       if (vis[y]) continue;       dfs(y);       ans[cnt++ / tot].push_back(x);     }   }   int main() {     int n, m, k;     cin >> n >> m >> k;     tot = (2 * n + k - 1) / k;     while (m--) {       int x, y;       cin >> x >> y;       v[x].push_back(y);       v[y].push_back(x);     }     for (int i = 1; i <= n; i++) {       if (vis[i]) continue;       cnt = (cnt + tot - 1) / tot * tot;       dfs(i);     }     for (int i = 0; i < k; i++) {       if (ans[i].empty()) ans[i].push_back(1);       printf( %d , ans[i].size());       for (auto &x : ans[i]) printf(  %d , x);       puts(  );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   const long long INF = 1e18;   template <typename T>   void read(T &x) {     x = 0;     int s = 1, c = getchar();     for (; !isdigit(c); c = getchar())       if (c ==  - ) s = -1;     for (; isdigit(c); c = getchar()) x = x * 10 + c - 48;     x *= s;   }   template <typename T>   void write(T x) {     if (x < 0) x = -x, putchar( - );     if (x > 9) write(x / 10);     putchar(x % 10 +  0 );   }   template <typename T>   void writeln(T x) {     write(x);     puts(  );   }   const int maxn = 2e2 + 5, mod = 1e9 + 7;   int n, len, Next[maxn], to[maxn][2];   char s[maxn];   long long dp[maxn][maxn][maxn][2];   void Get_Next(char *s, int len) {     Next[1] = 0;     for (int i = 2, j = 0; i <= len; i++) {       while (j > 0 && s[i] != s[j + 1]) j = Next[j];       if (s[i] == s[j + 1]) j++;       Next[i] = j;     }     for (int i = 0; i <= len - 1; i++) {       int j = i;       while (j && s[j + 1] !=  ) ) j = Next[j];       if (s[j + 1] ==  ) ) to[i][1] = j + 1;       j = i;       while (j && s[j + 1] !=  ( ) j = Next[j];       if (s[j + 1] ==  ( ) to[i][0] = j + 1;     }   }   void Add(long long &x, long long y) {     x += y;     if (x >= mod) x -= mod;   }   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     cin >> n >> (s + 1);     len = strlen(s + 1);     Get_Next(s, len);     dp[0][0][0][0] = 1;     n *= 2;     for (int i = 0; i <= n - 1; i++) {       for (int k = 0; k <= i; k++) {         for (int j = 0; j <= min(i, len - 1); j++) {           Add(dp[i + 1][k + 1][to[j][0]][to[j][0] == len], dp[i][k][j][0]);           if (k) Add(dp[i + 1][k - 1][to[j][1]][to[j][1] == len], dp[i][k][j][0]);         }         Add(dp[i + 1][k + 1][len][1], dp[i][k][len][1]);         if (k) Add(dp[i + 1][k - 1][len][1], dp[i][k][len][1]);       }     }     cout << dp[n][0][len][1] << endl;   }


#include <bits/stdc++.h>   using namespace std;   long long int mod = 1e9 + 7;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int t;     cin >> t;     while (t--) {       long long int l, r, m;       cin >> l >> r >> m;       long long int nn, xx;       long long int ans = LLONG_MAX;       for (long long int i = l; i <= r; i++) {         long long int start = 1, end = 1e10;         long long int flag = 1;         while (start <= end) {           long long int mid = (start + end) / 2;           long long int diff = abs(mid * i - m);           if (diff <= (r - l)) {             if ((mid * i - m) <= 0) {               cout << i <<     << r <<     << r - diff <<   n ;             } else {               cout << i <<     << r - diff <<     << r <<   n ;             }             flag = 0;             break;             end = mid - 1;           } else if (mid * i - m >= 0) {             end = mid - 1;           } else {             start = mid + 1;           }         }         if (flag == 0) break;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 5e18;   const int MK = 10101;   const int MN = 101010;   long long H, M, N, K;   map<long long, long long> mp;   vector<long long> methods;   vector<pair<long long, long long> > ip[MK];   bool pllcmp(pair<long long, long long> p1, pair<long long, long long> p2) {     p1.second = -p1.second;     p2.second = -p2.second;     return p1 < p2;   };   priority_queue<pair<long long, long long>, vector<pair<long long, long long> >,                  std::function<bool(pair<long long, long long>,                                     pair<long long, long long>)> >       pq(pllcmp);   long long dis[MK];   long long op[MN];   void spfa() {     for (int i = 0; i < K; i++) dis[i] = INF;     dis[0] = 0;     queue<int> qe;     qe.push(0);     while (qe.size()) {       long long v = qe.front();       qe.pop();       for (int i = 0; i < (int)methods.size(); i++) {         long long m = methods[i];         long long r = (m + v) % K;         if (dis[r] > dis[v] + m) {           dis[r] = dis[v] + m;           qe.push(r);         }       }     }     pq = priority_queue<         pair<long long, long long>, vector<pair<long long, long long> >,         function<bool(pair<long long, long long>, pair<long long, long long>)> >(         pllcmp);     for (int i = 0; i < N; i++) {       long long a = op[i], c = mp[op[i]];       long long r = a % K;       if (a >= dis[r]) {         pq.push(make_pair(c, i));       }     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> H >> N >> M >> K;     for (int i = 0; i < N; i++) {       long long a, c;       cin >> a >> c;       a--;       mp[a] = c;       ip[a % K].push_back(make_pair(i, c));       op[i] = a;     }     for (int i = 0; i < (int)ip[0].size(); i++) {       pq.push(make_pair(ip[0][i].second, ip[0][i].first));     }     for (int i = 1; i < K; i++) dis[i] = INF;     for (int i = 0; i < M; i++) {       int t;       cin >> t;       if (t == 1) {         long long x;         cin >> x;         methods.push_back(x);         spfa();       } else if (t == 2) {         long long id, a, c;         cin >> id >> c;         id--;         a = op[id];         mp[a] -= c;         if (dis[a % K] <= a) pq.push(make_pair(mp[a], id));       } else if (t == 3) {         pair<long long, long long> tp;         while (pq.size()) {           tp = pq.top();           if (mp[op[tp.second]] == tp.first) break;           pq.pop();         }         cout << (pq.size() ? tp.first : 0) << endl;         if (pq.size()) mp[op[tp.second]] = 0;       }     }     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:268435456 )   using namespace std;   template <typename T>   T sqr(const T &x) {     return x * x;   }   template <typename T>   T my_abs(const T &x) {     return x < 0 ? -x : x;   }   const int INF = (int)1e9;   const long long LINF = (long long)6e18;   const long long INF64 = LINF;   const long long INFLL = LINF;   const long double EPS = 1e-15;   const long double PI = 3.1415926535897932384626433832795;   const long double ME = 1e-5;   const long long MOD2 = (int)1e9 + 21;   const int SQN = 320;   const int LOGN = 17;   const int dx[] = {0, 1, 0, -1};   const int dy[] = {-1, 0, 1, 0};   const int N = (int)5e3 + 10;   const int M = (int)2e6 + 10;   const long long MOD = (int)1e9 + 7;   int z[N][N];   int psum[N][N];   int prv[26][N];   int a[N];   void solve() {     int n;     cin >> n;     string s;     cin >> s;     for (int i = 0; i < int(n); ++i) {       a[i] = s[i] -  a ;     }     memset(prv, -1, sizeof(prv));     for (int i = 0; i < int(26); ++i) {       for (int j = 1; j < int(n); ++j) {         if (a[j - 1] == i) {           prv[i][j] = j - 1;         } else {           prv[i][j] = prv[i][j - 1];         }       }     }     z[0][0] = 1;     for (int j = 1; j < int(n + 1); ++j) {       psum[0][j] = 1;     }     for (int i = 1; i < int(n + 1); ++i) {       for (int j = 0; j < int(n); ++j) {         z[i][j] = (z[i][j] + z[i - 1][j]) % MOD;         z[i][j] =             (z[i][j] + psum[i - 1][j] - psum[i - 1][prv[a[j]][j] + 1] + MOD) %             MOD;         psum[i][j + 1] = (psum[i][j] + z[i][j]) % MOD;       }     }     int ans = 0;     for (int j = 0; j < int(n); ++j) {       ans = (ans + z[n][j]) % MOD;     }     cout << ans << endl;   }   int main() {     ios_base::sync_with_stdio(false);     srand((unsigned int)time(NULL));     cout << setprecision(15) << fixed;     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   const double pi = acos(-1.0);   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long tt;     tt = 1;     while (tt--) {       long long n, m;       cin >> n >> m;       long long cost[n + 2];       for (long long i = 0; i < n; i += 1) cin >> cost[i + 1];       long long ans = 0;       for (long long i = 0; i < m; i += 1) {         long long p, q;         cin >> p >> q;         ans += min(cost[p], cost[q]);       }       cout << ans <<   n ;     }     return 0;   }


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