#include <bits/stdc++.h>   using namespace std;   inline int read() {     int x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       f = ch ==  -  ? -1 : 1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) x = x * 10 + ch -  0 , ch = getchar();     return x * f;   }   const int N = 105;   int n, p[N], c[N];   int main() {     int T = read();     while (T--) {       n = read();       for (int i = 1; i <= n; i++) p[i] = read(), c[i] = read();       p[0] = 0;       c[0] = 0;       int fl = 1;       for (int i = 1; i <= n; i++) {         if (c[i] < c[i - 1] || p[i] < p[i - 1]) {           fl = 0;           break;         }         if (c[i] - c[i - 1] > p[i] - p[i - 1]) {           fl = 0;           break;         }       }       if (fl)         puts( YES );       else         puts( NO );     }   }


#include <bits/stdc++.h>   using namespace std;   template <typename S, typename T>   ostream& operator<<(ostream& out, pair<S, T> const& p) {     out <<  (  << p.first <<  ,   << p.second <<  ) ;     return out;   }   template <typename T>   ostream& operator<<(ostream& out, vector<T> const& v) {     int l = v.size();     for (int i = 0; i < l - 1; i++) out << v[i] <<    ;     if (l > 0) out << v[l - 1];     return out;   }   const int N = 10000001;   int lp[N], primes[N], pcnt;   void getSieve() {     for (int i = 2; i <= N; i++) {       if (lp[i] == 0) {         lp[i] = i;         primes[pcnt++] = i;       }       for (int j = 0; j < pcnt and primes[j] <= lp[i] and i * primes[j] <= N; j++)         lp[i * primes[j]] = primes[j];     }     return;   }   const int M = 1000100;   int k, a, cnt[N], mx;   long long cp[N];   int f(long long val) {     long long p, d, tot;     for (int i = 0; i < pcnt and primes[i] <= val; i++) {       d = p = primes[i], tot = 0;       while (d <= val and tot < cp[p]) {         tot += val / d;         d *= p;       }       if (tot < cp[p]) return 0;     }     return 1;   }   int main() {     getSieve();     scanf( %d , &k);     for (int i = 1; i <= k; i++) {       scanf( %d , &a);       mx = max(mx, a);       cnt[1]++;       cnt[a + 1]--;     }     int p, num;     for (int i = 1; i <= mx; i++) {       cnt[i] += cnt[i - 1];       num = i;       while (num > 1) {         p = lp[num];         while (lp[num] == p) {           cp[p] += cnt[i];           num /= p;         }       }     }     long long lo = mx, hi = (1LL << 45), mid;     while (lo < hi) {       mid = (lo / 2) + (hi / 2);       if (f(mid))         hi = mid;       else         lo = mid + 1;     }     cout << hi << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     double r, x, y, z, t;     cin >> r >> x >> y >> z >> t;     double d = (x - z) * (x - z) + (y - t) * (y - t);     d = sqrt(d);     double i;     for (i = 0; i < 10000000; i++) {       if ((i * r) >= d / 2) break;     }     cout << i << endl;   }


#include <bits/stdc++.h>   using namespace std;   int w1, w2, h1, h2;   int main() {     scanf( %d%d%d%d , &w1, &h1, &w2, &h2);     printf( %d n , (h1 + h2) * 2 + 4 + max(w1, w2) * 2);     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O500 )   #pragma comment(linker,  /STACK:1677777216 )   #pragma warning(default : 4)   using namespace std;   const double eps = 1e-12;   const int oo = 0x3F3F3F3F;   const long long ooLL = 0x3F3F3F3F3F3F3F3FLL;   const int MOD = 1000000007;   template <typename T>   T sqr(T x) {     return x * x;   }   template <typename T>   void debpr(const T &);   template <typename T1, typename T2>   void debpr(const pair<T1, T2> &);   template <typename T1, typename T2>   void debpr(const vector<T1, T2> &);   template <typename T>   void debpr(const set<T> &);   template <typename T1, typename T2>   void debpr(const map<T1, T2> &);   template <typename T>   void prcont(T be, T en, const string &st, const string &fi, const string &mi) {     debpr(st);     bool ft = 0;     while (be != en) {       if (ft) debpr(mi);       ft = 1;       debpr(*be);       ++be;     }     debpr(fi);   }   template <typename T>   void debpr(const T &a) {}   template <typename T1, typename T2>   void debpr(const pair<T1, T2> &p) {     debpr( ( );     debpr(p.first);     debpr( ,  );     debpr(p.second);     debpr( ) );   }   template <typename T1, typename T2>   void debpr(const vector<T1, T2> &a) {     prcont(a.begin(), a.end(),  [ ,  ] ,  ,  );   }   template <typename T>   void debpr(const set<T> &a) {     prcont(a.begin(), a.end(),  { ,  } ,  ,  );   }   template <typename T1, typename T2>   void debpr(const map<T1, T2> &a) {     prcont(a.begin(), a.end(),  { ,  } ,  ,  );   }   void deb(){};   template <typename T1>   void deb(const T1 &t1) {     debpr(t1);     debpr(  n );   }   template <typename T1, typename T2>   void deb(const T1 &t1, const T2 &t2) {     debpr(t1);     debpr(   );     debpr(t2);     debpr(  n );   }   template <typename T1, typename T2, typename T3>   void deb(const T1 &t1, const T2 &t2, const T3 &t3) {     debpr(t1);     debpr(   );     debpr(t2);     debpr(   );     debpr(t3);     debpr(  n );   }   template <typename T1, typename T2, typename T3, typename T4>   void deb(const T1 &t1, const T2 &t2, const T3 &t3, const T4 &t4) {     debpr(t1);     debpr(   );     debpr(t2);     debpr(   );     debpr(t3);     debpr(   );     debpr(t4);     debpr(  n );   }   const double PI = acos(-1.);   long long Round(double x) { return x < 0 ? x - .5 : x + .5; }   template <typename T>   void ass(bool v, const T &x, string m =  Fail ) {     if (!v) {       deb(m);       deb(x);       throw;     }   }   int main() {     void run();     run();     return 0;   }   long long a[1 << 20];   int n;   long long gcd(long long a, long long b) {     long long t;     while (a) b %= a, t = a, a = b, b = t;     return b;   }   long long mrand() {     long long rs = 0;     for (int i = (0), _b(60); i < _b; ++i)       if (rand() % 2) rs += 1LL << i;     return rs;   }   void run() {     scanf( %d , &n);     for (int i = (0), _b(n); i < _b; ++i) scanf( %lld , &a[i]);     long long rs = 1;     srand(2);     for (int it = (0), _b(12); it < _b; ++it) {       long long t = a[mrand() % n];       unordered_map<long long, int> m;       m.reserve(1 << 15);       for (int i = (0), _b(n); i < _b; ++i) ++m[gcd(a[i], t)];       vector<pair<long long, long long> > v((m).begin(), (m).end());       for (int i = (0), _b(v.size()); i < _b; ++i) {         int z = 0;         for (int j = (0), _b(v.size()); j < _b; ++j)           if (v[j].first % v[i].first == 0) z += v[j].second;         if (z >= (n + 1) / 2) rs = max(rs, v[i].first);       }     }     cout << rs << endl;   }


#include <bits/stdc++.h>   using namespace std;   int ispalin(string a) {     string b = a;     reverse(b.begin(), b.end());     return a == b;   }   int main() {     string str;     cin >> str;     int N = str.size();     for (int i = 0; i <= N; i++) {       for (char xc =  a ; xc <=  z ; xc++) {         string str1;         for (int j = 0; j < i; j++) str1 += str[j];         str1 += xc;         for (int j = i; j < N; j++) str1 += str[j];         if (ispalin(str1)) {           cout << str1;           return 0;         }       }     }     cout <<  NA ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int h = n / 2;     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         if (i <= h) {           if (j >= h - i && j <= h + i) {             cout <<  D ;           } else {             cout <<  * ;           }         } else {           if (j >= i - h && j <= 3 * n / 2 - 1 - i) {             cout <<  D ;           } else {             cout <<  * ;           }         }       }       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 51;   long long ans[maxn], a[maxn];   long long poww(long long a, long long b) {     long long res = 1;     while (b) {       if (b & 1) res = res * a;       b /= 2;       a = a * a;     }     return res;   }   void init() {     ans[0] = 1;     a[0] = 1;     for (long long i = 1; i <= 38; i++) {       a[i] = poww(3, i);     }     for (long long i = 1; i <= 38; i++) {       ans[i] = ans[i - 1] + a[i];     }   }   int main() {     ios::sync_with_stdio(false);     init();     long long t;     cin >> t;     while (t--) {       long long n;       cin >> n;       long long m = 0;       for (long long i = 38; i >= 1; i--) {         if (ans[i - 1] >= n) continue;         n -= a[i];         m += a[i];       }       if (n > 0) {         m += 1;       }       cout << m << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   char a[1001][1001];   int d[1001][1001];   int n, m, ans;   int main() {     cin >> n >> m;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) cin >> a[i][j];     for (int i = n; i > 0; i--)       for (int j = m; j > 0; j--) {         int cur;         d[i][j] = d[i + 1][j] + d[i][j + 1] - d[i + 1][j + 1];         if (a[i][j] ==  W )           cur = 1;         else           cur = -1;         if (cur != d[i][j]) ans++;         d[i][j] = cur;       }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, k, i, p;   int main() {     cin >> n;     if (n < 3) {       cout << -1;     } else {       for (i = n; i >= 1; i--) {         cout << i <<    ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int64_t MOD = 1e9 + 7;   const int N = 2e5 + 5;      int64_t mpow(int64_t b,int64_t e,int64_t m){       int64_t r = 1;       while(e > 0){           if(e & 1){               r = (r*b)%m;           }           b = (b*b)%m;           e >>= 1;       }       return r;   }      int main(){       ios_base::sync_with_stdio(false);       cin.tie(NULL);          int64_t fact[N],ifact[N];       ifact[0] = fact[0] = 1;       for(int i=1;i<N;i++){           fact[i] = (i * fact[i-1]) % MOD;           ifact[i] = mpow(fact[i],MOD-2,MOD);       }       auto comb = [&](int x,int y){ // xCy           return (fact[x]*ifact[x-y]%MOD*ifact[y])%MOD;       };       int t;       cin >> t;       while(t--){           int n,l,r;           cin >> n >> l >> r;           int x = min(1-l,r-n);           int L=0,R=n+1;           int64_t res = (x*(((n%2)+1)*comb(n,n/2))%MOD)%MOD;           res %= MOD;           for(int i=x+1;;i++){               while(L+1-i < l) L++;               while(R-1+i > r) R--;               if(L > (n+1)/2 || n+1-R > (n+1)/2 || R-L-1 < 0) break;               if(n%2 == 1){                   if(L <= n/2) res = (res+comb(R-L-1,n/2-L))%MOD;                   if(L <= (n+1)/2) res = (res+comb(R-L-1,(n+1)/2-L))%MOD;               }else{                   res = (res+comb(R-L-1,n/2-L))%MOD;               }           }           cout << (res%MOD+MOD)%MOD <<   n ;       }   }


#include <bits/stdc++.h>   using namespace std;   int nxt() {     int x;     cin >> x;     return x;   }   int main() {     int n = nxt(), k = nxt();     vector<int> a(n);     generate(a.begin(), a.end(), nxt);     int s = accumulate(a.begin(), a.end(), 0);     int ans = 0;     while ((s + k * ans) * 1.0 / (n + ans) < k - 0.5) {       ans++;     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline void read(T &x) {     char c;     bool nega = 0;     while ((!isdigit(c = getchar())) && (c !=  - ))       ;     if (c ==  - ) {       nega = 1;       c = getchar();     }     x = c - 48;     while (isdigit(c = getchar())) x = x * 10 + c - 48;     if (nega) x = -x;   }   template <typename T>   inline void writep(T x) {     if (x > 9) writep(x / 10);     putchar(x % 10 + 48);   }   template <typename T>   inline void write(T x) {     if (x < 0) {       putchar( - );       x = -x;     }     writep(x);   }   template <typename T>   inline void writeln(T x) {     write(x);     putchar(  n );   }   int n;   int ans[100001];   const long long inf = 2250000000000;   inline long long cal(const pair<pair<long long, long long>, long long> &first) {     return first.first.first * first.first.first +            first.first.second * first.first.second;   }   inline long long mul(long long first, long long second) {     return first * first + second * second;   }   inline bool cmp(const pair<pair<long long, long long>, long long> &a,                   const pair<pair<long long, long long>, long long> &b) {     return cal(a) < cal(b);   }   pair<pair<long long, long long>, long long> a[100001];   void enter() {     read(n);     for (int i = 0; i < n; i++) {       read(a[i].first.first);       read(a[i].first.second);       a[i].second = i;     }     sort(a, a + n, cmp);   }   void add(long long &first, long long second) { first = first + second; }   void sub(long long &first, long long second) { first = first - second; }   void progress() {     long long first = 0, second = 0;     long long xx = 0, yy = 0;     for (int i = 0; i < n; i++) {       add(xx, a[i].first.first);       add(yy, a[i].first.second);       if (mul(first + a[i].first.first, second + a[i].first.second) <=           mul(first, second)) {         add(second, a[i].first.second);         add(first, a[i].first.first);         ans[a[i].second] = 1;       } else {         sub(second, a[i].first.second);         sub(first, a[i].first.first);         ans[a[i].second] = -1;       }     }     while (mul(first, second) > inf) {       for (int i = n - 1; i >= 0; i--) {         if (ans[a[i].second] == -1 &&             mul(first + 2 * a[i].first.first, second + 2 * a[i].first.second) <=                 inf) {           add(second, 2 * a[i].first.second);           add(first, 2 * a[i].first.first);           ans[a[i].second] = 1;         } else if (ans[a[i].second] == 1 &&                    mul(first - 2 * a[i].first.first,                        second - 2 * a[i].first.second) <= inf) {           sub(first, 2 * a[i].first.first);           sub(second, 2 * a[i].first.second);           ans[a[i].second] = -1;         }       }     }   }   int main() {     enter();     progress();     for (int i = 0; i < n; i++) {       write(ans[i]);       putchar(   );     }   }


#include <bits/stdc++.h>   using namespace std;   bool visited[100005] = {0};   vector<int> v[100005];   int color[100005];   int dfs(int s) {     int result = 0;     visited[s] = 1;     for (int i = 0; i < v[s].size(); i++) {       if (!visited[v[s][i]]) {         if (color[v[s][i]] != color[s])           result += (1 + dfs(v[s][i]));         else           result += dfs(v[s][i]);       }     }     return result;   }   int main() {     int n;     cin >> n;     for (int i = 0; i < 100005; i++) visited[i] = 0;     for (int i = 2; i <= n; i++) {       int a;       cin >> a;       v[i].push_back(a);       v[a].push_back(i);     }     for (int i = 0; i < n; i++) {       cin >> color[i + 1];     }     cout << (1 + dfs(1)) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void dfs(const vector<int> &next, vector<bool> &visited, vector<int> &end,            int x) {     visited[x] = true;     int y = next[x];     if (!visited[y]) {       dfs(next, visited, end, y);       end[x] = end[y];     } else       end[x] = x;   }   int main() {     int n;     scanf( %d , &n);     vector<int> next(n), deg(n);     for (int i = 0; i < n; ++i) {       scanf( %d , &next[i]);       --next[i];       ++deg[next[i]];     }     vector<int> start, end, g_end(n, -1);     vector<bool> visited(n, false);     for (int i = 0; i < n; ++i)       if (deg[i] == 0) {         start.push_back(i);         dfs(next, visited, g_end, i);         end.push_back(g_end[i]);       }     for (int i = 0; i < n; ++i)       if (!visited[i]) {         start.push_back(i);         dfs(next, visited, g_end, i);         end.push_back(g_end[i]);       }     int cnt = int(start.size());     if (cnt == 1 && deg[start[0]] > 0)       printf( 0 n );     else {       printf( %d n , cnt);       for (int i = 0; i < cnt; ++i)         printf( %d %d n , end[i] + 1, start[(i + 1) % cnt] + 1);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = (int)1e9 + 7;   const int AL = 26;   const int N = (int)1e6 + 9;   int powr(int n, int k) {     if (k == 0) return 1;     int v = powr(n, k / 2);     v = (v * 1ll * v) % MOD;     if (k & 1) v = (v * 1ll * n) % MOD;     return v;   }   int cnt[AL];   int f[N];   int inv[N];   int C(int a, int b) {     if (b == 0) return 1;     int v = f[a];     v = (v * 1ll * inv[b]) % MOD;     v = (v * 1ll * inv[a - b]) % MOD;     return v;   }   int ways(string a, string b) {     for (int j = 0; j < AL; j++) cnt[j] = 0;     for (auto x : a) {       cnt[x -  a ]++;     }     int answ = 0;     int mlt;     int sz = a.size();     int nsz;     int y;     bool ok;     for (int i = 0; i < b.size(); i++) {       nsz = sz - 1;       y = b[i] -  a ;       ok = false;       for (int t = 0; t < y; t++) {         if (cnt[t] > 0) ok = true;       }       if (ok) {         mlt = 1;         for (int r = AL - 1; r >= 0; r--) {           mlt = (mlt * 1ll * C(nsz, cnt[r])) % MOD;           nsz -= cnt[r];           nsz += (r == y);         }         answ = (answ + mlt) % MOD;       }       cnt[b[i] -  a ]--;       if (cnt[b[i] -  a ] < 0) break;       sz--;     }     return answ;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     f[0] = 1;     inv[0] = 1;     for (int i = 1; i < N; i++) {       f[i] = (1ll * i * f[i - 1]) % MOD;       inv[i] = powr(f[i], MOD - 2);     }     string a, b;     cin >> a >> b;     cout << (ways(a, b) - ways(a, a) + MOD - 1) % MOD <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solution() {     long long n, x, m = 0, ans = 0;     cin >> n;     ans += 2 * n - 1;     while (n--) {       cin >> x;       ans += abs(x - m);       m = x;     }     cout << ans <<   n ;   }   int main() {     ios ::sync_with_stdio(0);     cin.tie(0);     long long t;     t = 1;     while (t--) {       solution();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int q;     cin >> q;     for (int i = 0; i < q; i++) {       int n, r;       cin >> n >> r;       int arr[n];       for (int j = 0; j < n; j++) {         cin >> arr[j];       }       sort(arr, arr + n);       int shots = 0, act[n], p = 0;       act[0] = arr[0];       p++;       for (int j = 1; j < n; j++) {         if (arr[j] == arr[j - 1]) {         } else {           act[p] = arr[j];           p++;         }       }       for (int j = 0; j < p; j++) {         if (act[p - j - 1] - j * r <= 0) {           break;         }         shots++;       }       cout << shots << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     int ch = 0, nch = 0;     int x;     int b;     if (n >= m) {       b = m;     } else {       b = n;     }     for (int i = 0; i < n; i++) {       cin >> x;       if (x % 2 == 0) {         ch++;       } else {         nch++;       }     }     for (int i = 0; i < m; i++) {       cin >> x;       if (x % 2 == 0) {         ch++;       } else {         nch++;       }     }     if (nch > ch) {       if (ch < b) {         cout << ch << endl;       } else {         cout << b << endl;       }     } else {       if (nch < b) {         cout << nch << endl;       } else {         cout << b << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) {     for (; b; a %= b, swap(a, b))       ;     return a;   }   int n;   pair<int, int> board[1001][1001];   int ans[1001][1001];   int dx[5] = {0, 1, -1, 0, 0};   int dy[5] = {0, 0, 0, 1, -1};   bool isValid(int x, int y) { return 1 <= x && x <= n && 1 <= y && y <= n; }   int main() {     ios::sync_with_stdio(0);     cin.tie(0), cout.tie(0);     memset(ans, -1, sizeof ans);     cin >> n;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++) cin >> board[i][j].first >> board[i][j].second;     queue<pair<int, int> > q;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++) {         if (board[i][j].first == i && board[i][j].second == j) {           ans[i][j] = 0;           q.push({i, j});         }       }     while (!q.empty()) {       pair<int, int> cur = q.front();       q.pop();       int x = cur.first, y = cur.second;       for (int k = 1; k <= 4; k++) {         int cx = x + dx[k], cy = y + dy[k];         if (!isValid(cx, cy)) continue;         if (ans[cx][cy] != -1) continue;         if (board[cx][cy] != board[x][y]) continue;         ans[cx][cy] = k;         q.push({cx, cy});       }     }     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++) {         if (ans[i][j] == -1 && board[i][j] == pair<int, int>(-1, -1)) {           int x = i, y = j;           for (int k = 1; k <= 4; k++) {             int cx = x + dx[k], cy = y + dy[k];             if (!isValid(cx, cy)) continue;             if (ans[cx][cy] != -1) continue;             if (board[cx][cy] != board[x][y]) continue;             q.push({cx, cy});             q.push({x, y});             ans[cx][cy] = k;             if (k == 1)               ans[x][y] = 2;             else if (k == 2)               ans[x][y] = 1;             else if (k == 3)               ans[x][y] = 4;             else if (k == 4)               ans[x][y] = 3;             while (!q.empty()) {               pair<int, int> cur = q.front();               q.pop();               int x = cur.first, y = cur.second;               for (int k = 1; k <= 4; k++) {                 int cx = x + dx[k], cy = y + dy[k];                 if (!isValid(cx, cy)) continue;                 if (ans[cx][cy] != -1) continue;                 if (board[cx][cy] != board[x][y]) continue;                 ans[cx][cy] = k;                 q.push({cx, cy});               }             }             break;           }         }       }     bool isValid = true;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++) {         if (ans[i][j] == -1) isValid = false;       }     if (!isValid) {       cout <<  INVALID ;       return 0;     }     cout <<  VALID n ;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         switch (ans[i][j]) {           case 0:             cout <<  X ;             break;           case 1:             cout <<  U ;             break;           case 2:             cout <<  D ;             break;           case 3:             cout <<  L ;             break;           case 4:             cout <<  R ;             break;         }       }       cout <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100 * 1000 + 5;   int l[N];   int w[N];   int getw(long long s, long long e) {     if (e % 2) {       if (s % 2) {         return 2;       }       return 1;     }     if (s * 2 > e) {       if (s % 2 == e % 2) {         return 2;       }       return 1;     }     if (s * 4 > e) {       return 1;     }     return getw(s, e / 4);   }   int getl(long long s, long long e) {     if (s * 2 > e) {       return 1;     }     return getw(s, e / 2);   }   int main() {     int n;     cin >> n;     w[0] = 2, l[0] = 1;     for (int i = 1; i <= n; i++) {       long long s, e;       cin >> s >> e;       int x = getw(s, e), y = getl(s, e);       if (x == 1) {         w[i] = l[i - 1];       } else {         w[i] = w[i - 1];       }       if (y == 1) {         l[i] = l[i - 1];       } else {         l[i] = w[i - 1];       }     }     cout << (w[n] == 1) <<     << (l[n] == 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int M = 10 + 10;   int minn0[M][M];   int minn[M][M];   int dig[M];   int dignum;   int fac(int x) {     int ans = 1;     for (int i = 1; i <= x; i++) {       ans = ans * i;     }     return ans;   }   int ex(int a, int x) {     int ans = 1;     for (int i = 1; i <= x; i++) {       ans = ans * a;     }     return ans;   }   void mluckyinn0() {     for (int n = 1; n <= 9; n++) {       for (int m = 0; m <= n; m++) {         minn0[0][m] = 1;         int nchm = fac(n) / fac(m) / fac(n - m);         int lucky = ex(2, m);         int unlucky = ex(8, n - m);         minn0[n][m] = nchm * lucky * unlucky;       }     }   }   void mluckyinn() {     minn[1][0] = 7;     minn[1][1] = 2;     for (int n = 2; n <= 9; n++) {       for (int m = 0; m <= n; m++) {         int t1 = 0;         if (m - 1 >= 0 && n - 1 >= 0) {           t1 = minn0[n - 1][m - 1];         }         minn[n][m] = 2 * t1 + 7 * minn0[n - 1][m];       }     }   }   void caldig(int x) {     int idx = 0;     while (x > 0) {       dig[dignum - idx] = x % 10;       x = x / 10;       idx++;     }   }   int lnum[M];   long long int mod = 1000000000 + 7;   int main() {     int m;     cin >> m;     mluckyinn0();     mluckyinn();     int tmp = m;     while (tmp > 0) {       dignum++;       tmp /= 10;     }     caldig(m);     for (int d = 1; d < dignum; d++) {       for (int j = 0; j <= d; j++) {         lnum[j] = lnum[j] + minn[d][j];       }     }     int pre = 0;     int fi = 0;     for (int i = 1; i <= dignum; i++) {       int st = 0;       if (i == 1) {         st = 1;       }       int y47 = 0;       int n47 = 0;       for (int j = st; j < dig[i]; j++) {         if (j == 4 || j == 7) {           y47++;         } else {           n47++;         }       }       int flag = 0;       if (y47 > 0) {         flag = 1;       }       int ndg = dignum - i;       for (int j = 0; j <= ndg; j++) {         lnum[pre + j] = lnum[pre + j] + minn0[ndg][j] * n47;         lnum[pre + j + flag] = lnum[pre + j + flag] + minn0[ndg][j] * y47;       }       if (dig[i] == 4 || dig[i] == 7) {         pre++;       }     }     lnum[pre]++;     long long int ans = 0;     int sta[M];     for (int i1 = 0; i1 <= 9; i1++) {       sta[1] = lnum[i1];       lnum[i1]--;       for (int i2 = 0; i2 <= 9; i2++) {         sta[2] = lnum[i2];         lnum[i2]--;         for (int i3 = 0; i3 <= 9; i3++) {           sta[3] = lnum[i3];           lnum[i3]--;           for (int i4 = 0; i4 <= 9; i4++) {             sta[4] = lnum[i4];             lnum[i4]--;             for (int i5 = 0; i5 <= 9; i5++) {               sta[5] = lnum[i5];               lnum[i5]--;               for (int i6 = 0; i6 <= 9; i6++) {                 sta[6] = lnum[i6];                 lnum[i6]--;                 int st = i1 + i2 + i3 + i4 + i5 + i6;                 for (int i7 = st + 1; i7 <= 9; i7++) {                   sta[7] = lnum[i7];                   lnum[i7]--;                   long long int val = 1;                   for (int j = 1; j <= 7; j++) {                     if (sta[j] <= 0) {                       val = 0;                       break;                     } else {                       val = (val * sta[j]) % mod;                     }                   }                   ans = (ans + val) % mod;                   lnum[i7]++;                 }                 lnum[i6]++;               }               lnum[i5]++;             }             lnum[i4]++;           }           lnum[i3]++;         }         lnum[i2]++;       }       lnum[i1]++;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int32_t main() {     ios::sync_with_stdio(0);     cout.tie(0);     cin.tie(0);     long long k;     cin >> k;     long long sum = 0;     map<long long, long long> m;     vector<long long> ssum(k, 0), g(5005 * k, -1);     vector<vector<long long>> a(k);     vector<pair<long long, long long>> v;     for (long long i = 0; i < k; ++i) {       long long n;       cin >> n;       a[i].resize(n);       for (long long j = 0; j < n; ++j) {         cin >> a[i][j];         m[a[i][j]] = v.size();         v.emplace_back(a[i][j], i);         ssum[i] += a[i][j];       }       sum += ssum[i];     }     if (sum % k) {       cout <<  No n ;       return 0;     }     sum /= k;     for (long long i = 0; i < k; ++i) {       for (long long j = 0; j < (long long)a[i].size(); ++j) {         if (m.count(sum - ssum[i] + a[i][j])) {           long long id = m[sum - ssum[i] + a[i][j]], u = m[a[i][j]];           if (u != id && v[u].second == v[id].second) continue;           g[u] = id;         }       }     }     long long timer = 0;     vector<long long> dp(1 << k, 0), par(1 << k, 0), head(1 << k, -1);     vector<long long> vis(v.size() + 5, 0);     for (long long i = 0; i < k; ++i) {       for (auto j : a[i]) {         long long mask = 0, u = m[j];         ++timer;         if (vis[u] || g[u] == -1) continue;         while (~u && !vis[u]) {           vis[u] = timer;           u = g[u];         }         if (u == -1 || vis[u] != timer) continue;         long long c = 0, x = u, good = 1;         while (x != u || !c) {           if ((mask >> v[x].second) & 1) good = 0;           mask |= (1 << v[x].second);           x = g[x];           ++c;         }         if (good) {           dp[mask] = 1;           head[mask] = u;         }       }     }     dp[0] = 1;     for (long long i = 0; i < (1 << k); ++i) {       for (long long s = i; s; s = (s - 1) & i) {         if (dp[s] && dp[i ^ s]) {           dp[i] = 1;           par[i] = s;         }       }     }     if (!dp[(1 << k) - 1]) {       cout <<  No n ;       return 0;     }     vector<pair<long long, long long>> ans(k);     function<void(long long)> getans = [&](long long mask) {       if (~head[mask]) {         long long u = head[mask], x = g[u];         ans[v[x].second].first = v[x].first;         ans[v[x].second].second = v[u].second + 1;         while (u != x) {           ans[v[g[x]].second].first = v[g[x]].first;           ans[v[g[x]].second].second = v[x].second + 1;           x = g[x];         }       } else {         getans(par[mask]);         getans(mask ^ par[mask]);       }     };     getans((1 << k) - 1);     cout <<  Yes n ;     for (long long i = 0; i < k; ++i)       cout << ans[i].first <<     << ans[i].second <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k, len;     int i = 1;     cin >> n;     cin >> k;     vector<int> a;     while (n > 1) {       if (n % (i + 1) == 0) {         a.push_back(i + 1);         n = n / (i + 1);         i -= 1;       }       i += 1;     }     len = a.size() - k;     if (len >= 0) {       for (int i = 0; i < len; i++) {         a[len + k - i - 2] = a[len + k - i - 1] * a[len + k - i - 2];         a.pop_back();       }       for (int i = 0; i < a.size(); i++) {         cout << a[i] <<    ;       }     } else {       cout << -1;     }   }


#include <bits/stdc++.h>   using namespace std;   long long ar[100010];   unordered_map<long long, long long> um;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long t, n, x, ans, y, prev;     scanf( %lld , &t);     long long sm = 0;     while (t--) {       scanf( %lld , &n);       scanf( %lld , &x);       for (int i = 0; i < n; i++) {         scanf( %lld , &ar[i]);       }       sm = 0;       prev = ans = -1;       for (long long i = 0; i < n; i++) {         sm = (sm + ar[i]) % x;         if (sm && prev == -1) prev = i;         if (sm)           ans = i + 1;         else if (prev != -1)           ans = max(ans, i - prev);       }       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   constexpr long long INF = 2e18;   constexpr long long MOD = 1e9 + 7;   constexpr long long MAXN = 2e5 + 3;   struct Matrix {     static constexpr long long MOD = 1e9 + 7;     static constexpr long long MAXN = 200, MAXM = 200;     array<array<long long, MAXM>, MAXN> mat = {};     long long n, m;     Matrix(const long long n, const long long m) : n(n), m(m) {}     static long long mod(long long n) {       n %= MOD;       if (n < 0) n += MOD;       return n;     }     Matrix identity() {       assert(n == m);       Matrix mat_identity(n, m);       for (long long i = 0; i < n; ++i) mat_identity.mat[i][i] = 1;       return mat_identity;     }     Matrix operator*(const Matrix &other) const {       assert(m == other.n);       Matrix ans(n, other.m);       for (long long i = 0; i < n; ++i)         for (long long j = 0; j < m; ++j)           for (long long k = 0; k < m; ++k)             ans.mat[i][j] = mod(ans.mat[i][j] + mat[i][k] * other.mat[k][j]);       return ans;     }     Matrix expo(long long p) {       assert(p >= 0);       Matrix ans = identity(), cur_power(n, m);       cur_power.mat = mat;       while (p) {         if (p & 1) ans = ans * cur_power;         cur_power = cur_power * cur_power;         p >>= 1;       }       return ans;     }   };   void solve() {     long long n;     cin >> n;     long long b, k, x;     cin >> b >> k >> x;     vector<long long> fq(10);     for (long long i = 0; i < n; ++i) {       long long x;       cin >> x;       ++fq[x];     }     Matrix mat(x, x);     for (long long j = 0; j < x; ++j)       for (long long d = 0; d <= 9; ++d) mat.mat[(10 * j + d) % x][j] += fq[d];     mat = mat.expo(b);     Matrix ini(x, 1);     ini.mat[0][0] = 1;     mat = mat * ini;     cout << mat.mat[k].front() <<   n ;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long t = 1;     while (t--) solve();   }


#include <bits/stdc++.h>   using namespace std;   inline int Read() {     int x(0);     char c = getchar();     while (c <  0  || c >  9 ) c = getchar();     while (c >=  0  && c <=  9 ) x = (x << 3) + (x << 1) + c -  0 , c = getchar();     return x;   }   const int maxn = 1e5 + 9, mod = 998244353, maxm = 409;   int n, k, ans;   int a[maxn], cnt[maxn], lst[maxn], fir[maxn], bl[maxm], br[maxm], col[maxn],       v[maxn], lazy[maxm], f[maxn], sum[maxm][maxn];   inline int G(int x) {     while (x > mod) x -= mod;     return x;   }   inline void Fir() {     int size(sqrt(n)), pieces(ceil(1.0 * n / size));     for (int i = 1; i < pieces; ++i) {       bl[i] = (i - 1) * size + 1;       br[i] = i * size;       for (int j = bl[i]; j <= br[i]; ++j) col[j] = i;     }     bl[pieces] = (pieces - 1) * size + 1;     br[pieces] = n;     for (int j = bl[pieces]; j <= br[pieces]; ++j) col[j] = pieces;     for (int i = 1; i <= n; ++i) {       lst[i] = fir[a[i]];       fir[a[i]] = i;     }   }   inline void Modify(int l, int r, int val) {     int lt(col[l]), rt(col[r]);     if (lt == rt) {       for (int i = l; i <= r; ++i) {         if (val == 1) {           if (v[i] + lazy[lt] == k) ans = G(ans - f[i] + mod);         } else {           if (v[i] + lazy[lt] == k + 1) ans = G(ans + f[i]);         }         sum[lt][v[i]] = G(sum[lt][v[i]] - f[i] + mod), v[i] += val,         sum[lt][v[i]] = G(sum[lt][v[i]] + f[i]);       }     } else {       for (int i = l; i <= br[lt]; ++i) {         if (val == 1) {           if (v[i] + lazy[lt] == k) ans = G(ans - f[i] + mod);         } else {           if (v[i] + lazy[lt] == k + 1) ans = G(ans + f[i]);         }         sum[lt][v[i]] = G(sum[lt][v[i]] - f[i] + mod), v[i] += val,         sum[lt][v[i]] = G(sum[lt][v[i]] + f[i]);       }       for (int i = bl[rt]; i <= r; ++i) {         if (val == 1) {           if (v[i] + lazy[rt] == k) ans = G(ans - f[i] + mod);         } else {           if (v[i] + lazy[rt] == k + 1) ans = G(ans + f[i]);         }         sum[rt][v[i]] = G(sum[rt][v[i]] - f[i] + mod), v[i] += val,         sum[rt][v[i]] = G(sum[rt][v[i]] + f[i]);       }       for (int i = lt + 1; i <= rt - 1; ++i) {         if (val == 1)           ans = G(ans - sum[i][k - lazy[i]] + mod);         else           ans = G(ans + sum[i][k + 1 - lazy[i]]);         lazy[i] += val;       }     }   }   inline void Solve() {     ans = f[1] = sum[1][0] = 1;     for (int i = 1; i <= n; ++i) {       ++cnt[a[i]];       int p(lst[i]), q(lst[p]);       if (cnt[a[i]] == 1)         Modify(1, i, 1);       else if (cnt[a[i]] == 2) {         Modify(p + 1, i, 1);         Modify(1, p, -1);       } else {         Modify(p + 1, i, 1);         Modify(q + 1, p, -1);       }       f[i + 1] = ans;       sum[col[i + 1]][v[i + 1]] = G(sum[col[i + 1]][v[i + 1]] + f[i + 1]);       ans = G(ans + f[i + 1]);     }     printf( %d , f[n + 1]);   }   int main() {     n = Read();     k = Read();     for (int i = 1; i <= n; ++i) a[i] = Read();     Fir();     Solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   void REV(T *a, int n) {     reverse(a + 1, a + 1 + n);   }   template <class T>   void SRT(T *a, int n) {     sort(a + 1, a + 1 + n);   }   template <class T>   int UNI(T *a, int n) {     sort(a + 1, a + 1 + n);     return unique(a + 1, a + 1 + n) - (a + 1);   }   template <class T>   int POS(T *a, int n, T v) {     return lower_bound(a + 1, a + 1 + n, v) - a;   }   template <class T>   void _R(T &x) {     cin >> x;   }   void _R(int &x) { scanf( %d , &x); }   void _R(long long &x) { scanf( %lld , &x); }   void _R(double &x) { scanf( %lf , &x); }   void _R(char &x) { scanf(  %c , &x); }   void _R(char *x) { scanf( %s , x); }   void R() {}   template <class T, class... U>   void R(T &head, U &...tail) {     _R(head);     R(tail...);   }   template <class T>   void _W(const T &x) {     cout << x;   }   void _W(const int &x) { printf( %d , x); }   void _W(const long long &x) { printf( %lld , x); }   void _W(const double &x) { printf( %.12f , x); }   void _W(const char &x) { putchar(x); }   void _W(const char *x) { printf( %s , x); }   template <class T, class U>   void _W(const pair<T, U> &x) {     _W(x.F);     putchar(   );     _W(x.S);   }   template <class T>   void _W(const vector<T> &x) {     for (auto i = x.begin(); i != x.end(); _W(*i++))       if (i != x.cbegin()) putchar(   );   }   void W() {}   template <class T, class... U>   void W(const T &head, const U &...tail) {     _W(head);     putchar(sizeof...(tail) ?     :   n );     W(tail...);   }   template <typename T>   void cmin(T &x, T y) {     if (y < x) x = y;   }   template <typename T>   void cmax(T &x, T y) {     if (y > x) x = y;   }   long long sum;   int n;   int a[200005];   int cnt[64];   void purin_solve() {     R(sum, n);     memset((cnt), 0, sizeof((cnt)));     long long cursum = 0;     for (int i = (1); i <= (n); ++i) {       long long x;       R(x);       cursum += x;       int c = -1;       while (x) {         ++c;         x >>= 1;       }       ++cnt[c];     }     if (cursum < sum) do {         puts( -1 );         return;       } while (false);     ;     long long SUM = 0;     int ans = 0;     for (int i = 0; i < 64; ++i) {       if (SUM >= (1LL << i)) {         SUM -= (1LL << i);         ++cnt[i];       }       if (sum >> i & 1) {         int j;         for (j = i; j < 64; ++j) {           if (cnt[j]) break;         };         if (j == 64) do {             puts( -1 );             return;           } while (false);         while (j > i) {           --cnt[j];           --j;           cnt[j] += 2;           ++ans;         }         assert(cnt[i]);         --cnt[i];       }       while (cnt[i]) {         SUM += (1LL << i);         --cnt[i];       }     }     W(ans);   }   int main() {     cout << fixed << setprecision(12);     cerr << fixed << setprecision(12);     int t = 1;     scanf( %d , &t);     while (t--) purin_solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int k;     cin >> k;     if (k > 36)       cout << -1;     else {       for (int i = 0; i < k / 2; i++) cout << 8;       if (k % 2) cout << 4;     }   }


#include <bits/stdc++.h>   using namespace std;   char N[(int)1e6 + 5], B[(int)1e6 + 5];   long long n, b, c;   inline long long euler(long long n) {     long long ans = n;     for (int i = 2; i * i <= n; i++) {       if (n % i == 0) {         ans = ans / i * (i - 1);         while (n % i == 0) n /= i;       }     }     if (n > 1) ans = ans / n * (n - 1);     return ans;   }   long long qpow(long long x, long long n, long long mod) {     if (n == 0) return 1;     long long ans = qpow(x, n >> 1, mod);     ans = ans * ans % mod;     if (n & 1) ans = ans * x % mod;     return ans % mod;   }   int main() {     cin >> B;     cin >> N;     int xx = strlen(N);     int yy = strlen(B);     cin >> c;     n = 0;     long long u = euler(c);     if (xx < 10) {       for (int i = 0; i < xx; i++) n = n * 10 + N[i] -  0 ;       n--;     } else {       for (int i = 0; i < xx; i++) {         n = n * 10 + N[i] -  0 ;         n = n % u;       }       n = ((n - 1) + u) % u;       n += u;     }     for (int i = 0; i < yy; i++) {       b = b * 10 + B[i] -  0 ;       b = b % c;     }     long long ans = (b - 1 + c) % c;     ans = ans * qpow(b, n, c) % c;     if (!ans)       cout << c << endl;     else       cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   double dp[100111], ans;   int sz[100111], ds[100111];   std::list<int> edge[100111];   int i, j, n;   void dfs(int now, int fa) {     ds[now] = ds[fa] + 1;     ans += 1 / (double)ds[now];     for (std::list<int>::const_iterator it(edge[now].begin());          it != edge[now].end(); ++it)       if (*it != fa) dfs(*it, now);   }   int main() {     scanf( %d , &n);     while (--n) {       scanf( %d %d , &i, &j);       edge[i].push_back(j);       edge[j].push_back(i);     }     dfs(1, 0);     printf( %.10lf n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, jj = 0;   long long a[22], b[22];   long long dp[10000][1000];   long long memo(int idx, int cnt) {     long long res = (long long)(1e18);     if (idx == 2 * n - 1) {       if (cnt == 1) res = b[((idx + jj) % n)];       return dp[idx][cnt] = res;     }     if (dp[idx][cnt] != -1) return dp[idx][cnt];     if (cnt > 0) res = b[((idx + jj) % n)] + memo(idx + 1, cnt - 1);     res = min(res, a[((idx + jj) % n)] + memo(idx + 1, cnt + 1));     return dp[idx][cnt] = res;   }   int main() {     memset(dp, -1, sizeof dp);     cin >> n >> m;     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 0; i < n; i++) cin >> b[i];     long long mn = memo(0, 0);     long long ans = mn;     for (jj = 1; jj < n; jj++) {       memset(dp, -1, sizeof dp);       mn = min(memo(0, 0), mn);     }     cout << (m / 2 - 1) * mn + ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> leftSub[1000005];   vector<int> rightSub[1000005];   int leftSon[1000005], rightSon[1000005];   int maxVal[1000005], minVal[1000005];   int leftMax[1000005];   bool vis[1000005];   bool possible;   int n, c, a, b;   string d;   int cnt;   void findDfs(int u) {     if (vis[u]) return;     vis[u] = true;     maxVal[u] = minVal[u] = u;     int lmax = 0, rmax = 0;     int lmin = n + 1, rmin = n + 1;     int Lmax = 0, Rmin = n + 1;     for (int i = 0; i < leftSub[u].size(); ++i) {       int v = leftSub[u][i];       lmax = max(lmax, v);       lmin = min(lmin, v);       findDfs(v);       Lmax = max(Lmax, maxVal[v]);       maxVal[u] = max(maxVal[u], maxVal[v]);       minVal[u] = min(minVal[u], minVal[v]);     }     for (int i = 0; i < rightSub[u].size(); ++i) {       int v = rightSub[u][i];       rmax = max(rmax, v);       rmin = min(rmin, v);       findDfs(v);       Rmin = min(Rmin, minVal[v]);       maxVal[u] = max(maxVal[u], maxVal[v]);       minVal[u] = min(minVal[u], minVal[v]);     }     if (lmin <= u || lmax >= rmin) {       possible = false;       return;     }     if (Lmax >= Rmin) {       possible = false;       return;     }     leftMax[u] = Lmax;   }   void findBoundary() {     memset(vis, false, sizeof(vis));     for (int i = n; i >= 1; --i) {       if (!vis[i]) {         findDfs(i);       }     }   }   void dfs(int l, int r) {     ++cnt;     int lmin = n + 1, lmax = 0;     int rmin = n + 1, rmax = 0;     if (leftSub[l].size()) {       leftSon[l] = l + 1;       for (int i = 0; i < leftSub[l].size(); ++i) {         int v = leftSub[l][i];         lmin = min(lmin, v);         lmax = max(lmax, v);       }       if (lmin <= l) {         possible = false;         return;       }       dfs(l + 1, lmax);     }     if (rightSub[l].size()) {       for (int i = 0; i < rightSub[l].size(); ++i) {         int v = rightSub[l][i];         rmin = min(rmin, v);         rmax = max(rmax, v);       }       if (rmin <= cnt) {         possible = false;         return;       }       if (leftSub[l].size()) {         rightSon[l] = cnt + 1;         dfs(cnt + 1, max(r, rmax));       } else {         rightSon[l] = l + 1;         dfs(l + 1, max(r, rmax));       }     } else {       if (l == r) return;       int leftBound = max(l, cnt);       if (leftBound < r) {         rightSon[l] = leftBound + 1;         dfs(leftBound + 1, r);       }     }   }   void print(int u) {     if (leftSon[u]) {       print(leftSon[u]);     }     cout << u <<    ;     if (rightSon[u]) {       print(rightSon[u]);     }   }   void init() {     memset(leftSon, 0, sizeof(leftSon));     memset(rightSon, 0, sizeof(rightSon));     possible = true;     cnt = 0;     for (int i = 1; i <= n; ++i) {       leftMax[i] = 0;     }   }   int main() {     while (cin >> n >> c) {       for (int i = 0; i < c; ++i) {         cin >> a >> b >> d;         if (d[0] ==  L ) {           leftSub[a].push_back(b);         } else {           rightSub[a].push_back(b);         }       }       init();       dfs(1, n);       if (!possible) {         puts( IMPOSSIBLE );       } else {         print(1);         puts(  );       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const int MOD = 998244353;   void add(int& a, int b) {     a += b;     if (a >= MOD) a -= MOD;   }   int mul(int a, int b) { return ll(a) * b % MOD; }   int modinv(int a, int m = MOD) {     return a == 1 ? a : m - modinv(m % a, a) * ll(m) / a;   }   const int MAXV = 4242;   int p2[MAXV], invp2[MAXV];   int p2m1[MAXV], invp2m1[MAXV];   void precomp() {     p2[0] = 1;     for (int i = 1; i < MAXV; i++) {       p2[i] = mul(2, p2[i - 1]);     }     for (int i = 0; i < MAXV; i++) {       invp2[i] = modinv(p2[i]);     }     for (int i = 0; i < MAXV; i++) {       p2m1[i] = p2[i] - 1;     }     for (int i = 1; i < MAXV; i++) {       invp2m1[i] = modinv(p2m1[i]);     }   }   const int MAXN = 3010;   int N, C;   int A[MAXN];   int main() {     precomp();     scanf( %d %d , &N, &C);     for (int i = 0; i < N; i++) {       scanf( %d , &A[i]);       A[i]--;     }     vector<vector<int>> dp(N + 1);     dp[0] = {{1}};     if (C > 10) {       for (int i = 0; i < N; i++) {         vector<int> freq(C);         int prod = 1;         int cnt_bad = C - 1;         for (int j = i; j >= 0; j--) {           if (A[i] != A[j]) {             if (!freq[A[j]]) {               cnt_bad--;             } else {               prod = mul(prod, invp2m1[freq[A[j]]]);             }             freq[A[j]]++;             prod = mul(prod, p2m1[freq[A[j]]]);           }           if (cnt_bad == 0) {             if (dp[i + 1].size() < dp[j].size() + 1) {               dp[i + 1].resize(dp[j].size() + 1);             }             for (int l = 0; l < int(dp[j].size()); l++) {               add(dp[i + 1][l + 1], mul(prod, dp[j][l]));             }           }         }       }     } else {       vector<vector<int>> dp2(1 << C);       dp2[0] = {{1}};       for (int i = 0; i < N; i++) {         for (int m = (1 << C) - 1; m >= 0; m--) {           if (dp2[m | (1 << A[i])].size() < dp2[m].size()) {             dp2[m | (1 << A[i])].resize(dp2[m].size());           }           for (int l = 0; l < int(dp2[m].size()); l++) {             add(dp2[m | (1 << A[i])][l], dp2[m][l]);           }         }         swap(dp[i + 1], dp2[(1 << C) - 1]);         dp[i + 1].insert(dp[i + 1].begin(), 0);         if (dp2[0].size() < dp[i + 1].size()) {           dp2[0].resize(dp[i + 1].size());         }         for (int l = 0; l < int(dp[i + 1].size()); l++) {           add(dp2[0][l], dp[i + 1][l]);         }       }     }     vector<int> ans(N + 1);     for (int i = 0; i <= N; i++) {       for (int l = 0; l < int(dp[i].size()); l++) {         add(ans[l], mul(p2[N - i], dp[i][l]));       }     }     ans[0]--;     for (int i = 0; i < N; i++) {       add(ans[i], MOD - ans[i + 1]);     }     for (int i = 0; i <= N; i++) {       printf( %d%c , ans[i],    n [i == N]);     }     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:256000000 );   using namespace std;   const int MAX_ARRAY = 100005;   string num2str(int i) {     stringstream ss;     ss << i;     return ss.str();   }   std::vector<std::string> split(std::string str, std::string pattern) {     std::string::size_type pos;     std::vector<std::string> result;     str += pattern;     int size = str.size();     for (int i = 0; i < size; i++) {       pos = str.find(pattern, i);       if (pos < size) {         std::string s = str.substr(i, pos - i);         result.push_back(s);         i = pos + pattern.size() - 1;       }     }     return result;   }   bool DesCmp(int a, int b) { return a > b; }   int main() {     int n;     cin >> n;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         cout << (j - 1) * n + ((i + j - 1) % n) + 1 <<    ;       }       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void start() {}   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long t;     cin >> t;     while (t--) {       long long a, b;       cin >> a >> b;       if (a < b) swap(a, b);       b = 2 * b;       if (b >= a)         cout << b * b << endl;       else         cout << a * a << endl;     }   }


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


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     char a[n][7];     for (int i = 0; i < n; i++) {       for (int j = 0; j < 7; j++) cin >> a[i][j];     }     int ans = 0, ct = 0;     for (int j = 0; j < 7; j++) {       ct = 0;       for (int i = 0; i < n; i++) {         if (a[i][j] ==  1 ) ct++;       }       ans = max(ans, ct);     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize(2)   using namespace std;   inline long long read() {     long long x = 0, w = 1;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) w = -1;       c = getchar();     }     while (c <=  9  && c >=  0 ) {       x = (x << 1) + (x << 3) + c -  0 ;       c = getchar();     }     return w == 1 ? x : -x;   }   const int N = 1e5 + 10;   int a[N], n;   int main() {     int _ = read();     while (_--) {       long long x1 = read(), y1 = read();       long long x2 = read(), y2 = read();       if (x1 == x2 || y1 == y2) {         puts( 1 );         continue;       }       long long ans = (x2 - x1) * (y2 - y1) + 1;       printf( %lld n , ans);     }   }


#include <bits/stdc++.h>   using namespace std;   mt19937 rng(time(0));   uniform_int_distribution<int> uid(-1e9, 1e9);   vector<int> g[100002];   int d[100002], u[100002], k;   long long res, w[505], v[505];   int find(int x, int px, int sz) {     for (auto& i : g[x])       if (i != px && !u[i] && d[i] > sz / 2) return find(i, x, sz);     return x;   }   int dfs(int x, int px) {     d[x] = 1;     for (auto& i : g[x])       if (i != px && !u[i]) d[x] += dfs(i, x);     return d[x];   }   void dfs1(int x, int px, int dx) {     if (dx <= k) ++w[dx];     for (auto& i : g[x])       if (i != px && !u[i]) dfs1(i, x, dx + 1);   }   void solve(int x) {     int y = find(x, x, dfs(x, x));     u[y] = 1;     fill(v, v + k + 1, 0);     for (auto& i : g[y]) {       if (!u[i]) {         fill(w, w + k + 1, 0);         dfs1(i, i, 1);         res += w[k];         for (int i = 1; i < k; ++i) res += w[i] * v[k - i];         for (int i = 0; i < k; ++i) v[i] += w[i];       }     }     for (auto& i : g[y])       if (!u[i]) solve(i);   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n, x, y;     cin >> n >> k;     for (int i = 0; i < n - 1; ++i) {       cin >> x >> y;       g[--x].push_back(--y);       g[y].push_back(x);     }     solve(0);     cout << res <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int n, len, dp[200][100][2][2];   char x[200];   const int unDEF = 10000, INF = 1000000000;   int solve(int idx, int left, int dir, int isM) {     if (idx < 0) {       if (left + dir == 0) {         return 0;       }       if (isM) {         return -INF;       }       return INF;     }     int &temp = dp[idx][left][dir][isM];     if (temp != unDEF) {       return temp;     }     if (isM) {       temp = -INF;     } else       temp = INF;     int sign = dir ? -1 : 1;     for (int i = 0; i <= left; i++) {       int newDir = (x[idx] !=  T ) ^ (i & 1);       if (newDir) {         if (isM) {           temp = max(temp, solve(idx - 1, left - i, dir, isM) + sign);         } else {           temp = min(temp, solve(idx - 1, left - i, dir, isM) + sign);         }       } else {         if (isM) {           temp = max(temp, solve(idx - 1, left - i, dir ^ 1, isM));         } else {           temp = min(temp, solve(idx - 1, left - i, dir ^ 1, isM));         }       }     }     return temp;   }   int main() {     cin >> x >> n;     len = strlen(x);     for (int i = 0; i < len; i++) {       for (int j = 0; j <= n; j++) {         for (int k = 0; k < 2; k++) {           for (int l = 0; l < 2; l++) {             dp[i][j][k][l] = unDEF;           }         }       }     }     int ans = 0, a = solve(len - 1, n, 0, 0), b = solve(len - 1, n, 0, 1),         c = solve(len - 1, n, 1, 0), d = solve(len - 1, n, 1, 1);     if (a < 1000) ans = max(ans, abs(a));     if (c < 1000) ans = max(ans, abs(c));     if (b > -1000) ans = max(ans, abs(b));     if (d > -1000) ans = max(ans, abs(d));     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   #pragma GCC target( sse4 )   using namespace std;   unsigned int a[100000 + 5], b[100000 + 5], p;   int f(int x) { return ~((x - 1) >> 31); }   int main() {     int n, t, l, r, k, i;     long long ans = 0;     for (scanf( %d , &n); n--;) {       scanf( %d%d%d , &t, &l, &r);       if (t == 1) {         scanf( %d , &k);         p = k > 0 ? k - 1 : -k - 1;         if (k > 0)           for (i = l; i < r; ++i) a[i] = (a[i] - 1 < p ? a[i] - 1 : p) + 1;         else           for (i = l; i < r; ++i) b[i] = (b[i] - 1 < p ? b[i] - 1 : p) + 1;       } else {         for (ans = 0, i = l; i < r; ++i) ans += (a[i] + b[i]) & f(a[i]) & f(b[i]);         printf( %I64d n , ans);       }     }   }


#include <bits/stdc++.h>   using namespace std;   long long mod = 1e9;   void err(istream_iterator<string> it) {}   template <typename T, typename... Args>   void err(istream_iterator<string> it, T a, Args... args) {     cerr << *it <<   =   << a << endl;     err(++it, args...);   }   long long powm(long long a, long long b, long long mod) {     long long res = 1;     while (b) {       if (b & 1) res = (res * a) % mod;       a = (a * a) % mod;       b >>= 1;     }     return res;   }   bool sortinrev(const pair<int, int> &a, const pair<int, int> &b) {     return (a.first > b.first);   }   void solve() {     long long n;     cin >> n;     vector<long long> a(n);     for (long long i = 0; i < (n); i++) {       cin >> a[i];     };     if (n == 1) {       cout <<  YES n ;       cout << 1 <<     << a[0] << endl;       return;     }     long long x = 0, y = 0, m = 0;     for (long long i = 0; i < (n - 1); i++) {       m = max({m, a[i], a[i + 1]});       if (abs(a[i] - a[i + 1]) == 0) {         cout <<  NO n ;         return;       }       if (abs(a[i] - a[i + 1]) != 1 and y == 0) {         y = abs(a[i] - a[i + 1]);       } else if (abs(a[i] - a[i + 1]) != 1 and y != 0) {         if (y != abs(a[i] - a[i + 1])) {           cout <<  NO n ;           return;         }       }     }     if (y == 0) {       cout <<  YES n ;       cout << (mod) <<     << (mod) << endl;       return;     }     for (long long i = 0; i < (n - 1); i++) {       if (abs(a[i] - a[i + 1]) == 1) {         if (a[i] % y == 0 and a[i + 1] == a[i] + 1) {           cout <<  NO n ;           return;         }         if (a[i + 1] % y == 0 and a[i] == a[i + 1] + 1) {           cout <<  NO n ;           return;         }       }     }     cout <<  YES n ;     cout << (m / y) + 1 <<     << y << endl;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     solve();   }


#include <bits/stdc++.h>   long long a[100001];   int main() {     int n;     scanf( %d , &n);     int i, j, k;     int m = n / 2;     for (i = 1; i < n; i += 2) {       scanf( %I64d , &a[i]);     }     long long cur = 100000000000001LL;     for (i = n - 1; i >= 1; i -= 2) {       bool ok = false;       for (k = 2 - a[i] % 2; (long long)(k)*k <= a[i]; k += 2) {         if (a[i] % k) continue;         long long miden = a[i] / k;         if ((miden - k) % 2) continue;         long long upper = (a[i] / k) + (k - 1);         if (upper + 2 < cur) {           ok = true;           long long lower = (a[i] / k) - (k - 1);           a[i + 1] = ((upper + 2) + (cur - 2)) * ((cur - (upper + 2)) / 2) / 2;           cur = lower;           break;         }       }       if (!ok) {         break;       }     }     a[0] = (1 + (cur - 2)) * ((cur - 1) / 2) / 2;     if (a[0] > 0 && i < 1) {       puts( Yes );       for (i = 0; i < n; i++) {         printf( %I64d%c , a[i],    n [i == n - 1]);       }     } else {       puts( No );     }   }


#include <bits/stdc++.h>   using namespace std;   inline int read() {     int x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x * f;   }   using namespace std;   const int N = 20;   pair<double, double> p1[N], p2[N];   int n, m;   bool tag;   int p[N], vis[N];   bool ok(pair<double, double> a, pair<double, double> b, pair<double, double> c,           pair<double, double> d) {     if (!(min(a.first, b.first) <= max(c.first, d.first) &&           min(c.second, d.second) <= max(a.second, b.second) &&           min(c.first, d.first) <= max(a.first, b.first) &&           min(a.second, b.second) <= max(c.second, d.second)))       return 0;     double u, v, w, z;     u = (c.first - a.first) * (b.second - a.second) -         (b.first - a.first) * (c.second - a.second);     v = (d.first - a.first) * (b.second - a.second) -         (b.first - a.first) * (d.second - a.second);     w = (a.first - c.first) * (d.second - c.second) -         (d.first - c.first) * (a.second - c.second);     z = (b.first - c.first) * (d.second - c.second) -         (d.first - c.first) * (b.second - c.second);     return (u * v <= 0.00000001 && w * z <= 0.00000001);   }   void dfs(int now) {     bool flag;     if (tag) return;     if (now > n) {       flag = 1;       for (int i = 1; i <= n; i++)         for (int j = i + 1; j <= n; j++)           if (!ok(p1[i], p2[p[i]], p1[j], p2[p[j]])) return;       tag = 1;       return;     }     for (int i = 1; i <= m; i++)       if (!vis[i]) {         p[now] = i;         dfs(now + 1);       }   }   int main() {     n = read();     m = read();     for (int i = 1; i <= n; i++) scanf( %lf%lf , &p1[i].first, &p1[i].second);     for (int i = 1; i <= m; i++) scanf( %lf%lf , &p2[i].first, &p2[i].second);     if (n != m) {       puts( No );       return 0;     }     tag = 0;     dfs(1);     if (tag)       puts( Yes );     else       puts( No );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int BITS(long long __a) {     short int __c = 0;     __a <<= 1;     while (__a) __c += ((__a >>= 1) & 1);     return __c;   }   inline bool prime(int n) {     for (int i = 3; i * i <= n; i += 2)       if (n % i == 0) return false;     return true;   }   set<int> s;   int N, M, V[100010], A[100010];   int main() {     cin >> N >> M;     for (int i = 0; i < N; i++) cin >> V[i];     s.insert(V[N - 1]);     A[N - 1] = 1;     for (int i = N - 2; i >= 0; i--) {       s.insert(V[i]);       A[i] = ((int)s.size());     }     for (int i = 0; i < M; i++) {       int j;       cin >> j;       cout << A[j - 1] << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char s[100100];   char s1[111];   char s2[110];   int main() {     scanf( %s%s%s , s, s1, s2);     int flag1, flag2;     int n = strlen(s);     int n1 = strlen(s1);     int n2 = strlen(s2);     flag1 = flag2 = 0;     int i, j;     for (i = 0; i < n; i++) {       for (j = 0; j < n1; j++) {         if (s[i + j] != s1[j]) break;       }       if (j == n1) {         break;       }     }     i += n1;     for (; i < n; i++) {       for (j = 0; j < n2; j++) {         if (s[i + j] != s2[j]) break;       }       if (j == n2) {         flag1 = 1;         break;       }     }     for (i = 0; i < n; i++) {       for (j = 0; j < n2; j++) {         if (s[i + n2 - j - 1] != s2[j]) break;       }       if (j == n2) {         break;       }     }     i += n2;     for (; i < n; i++) {       for (j = 0; j < n1; j++) {         if (s[i + n1 - j - 1] != s1[j]) break;       }       if (j == n1) {         flag2 = 1;         break;       }     }     if (flag1 == 0 && flag2 == 0) {       printf( fantasy n );     }     if (flag1 == 0 && flag2 == 1) {       printf( backward n );     }     if (flag1 == 1 && flag2 == 0) {       printf( forward n );     }     if (flag1 == 1 && flag2 == 1) {       printf( both n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, d, sum = 0;     cin >> n >> d;     vector<pair<int, int> > ins(n);     for (int i = 0; i < n; i++) {       cin >> ins[i].first;       ins[i].second = i + 1;     }     sort(ins.begin(), ins.end());     int i = 0;     while (i < n and ((sum + ins[i].first) <= d)) {       sum += ins[i].first;       i++;     }     cout << i << endl;     for (int j = 0; j < i; j++) {       if (j > 0) cout <<    ;       cout << ins[j].second;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   double dp[1050000];   int n, k;   double p[25];   double ans[25];   int main() {     memset(dp, 0, sizeof(dp));     memset(ans, 0, sizeof(ans));     scanf( %d%d , &n, &k);     for (int i = 0; i < n; i++) scanf( %lf , p + i);     dp[0] = 1;     int st = (1 << n);     for (int i = 1; i < st; i++) {       double sp = 0;       int o = 0;       for (int j = 0; j < n; j++) {         if (i & 1 << j)           o++;         else           sp += p[j];       }       if (o > k) continue;       for (int j = 0; j < n; j++)         if ((i & 1 << j) && p[j] > 0.000000001) {           dp[i] += dp[i - (1 << j)] * p[j] / (sp + p[j]);           ans[j] += dp[i - (1 << j)] * p[j] / (sp + p[j]);         }     }     for (int i = 0; i < n; i++) cout << ans[i] <<    ;     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   set<string> st;   const int N = 1e6 + 5;   int a[3000];   int c1 = 0, c2;   string s, c;   int na, nb, m, ans = 0, mx = 0;   int main() {     int n, a, b;     cin >> n;     while (n--) {       cin >> a >> b;       if (a == 2) {         cout << b / a << endl;         continue;       }       if (a == 1) {         cout << b << endl;         continue;       }       if (a % 2 == 1) {         cout << b / (a - a / 2) << endl;       } else         cout << b / (a - (a / 2 - 1)) << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   set<long long> myset;   int base;   int N;   long long A[100005];   map<long long, int> Map;   int ANS[600000];   int T[1200000];   int Lo[300000];   int ql, qu;   int P[300000];   void update(int ind) {     ind += base;     T[ind] = ind - base;     while (1) {       ind /= 2;       if (ind < 1) break;       T[ind] = T[2 * ind];       if (ANS[T[2 * ind + 1]] > ANS[T[ind]]) T[ind] = T[2 * ind + 1];     }   }   int query(int ind, int cl, int cu) {     if (cu < ql || cl > qu) return -1;     if (cl >= ql && cu <= qu) return T[ind];     int ansl = query(2 * ind, cl, (cl + cu) / 2);     int ansr = query(1 + 2 * ind, 1 + (cl + cu) / 2, cu);     if (ansl == -1 || ansr == -1) return (ansl + ansr + 1);     if (ANS[ansl] >= ANS[ansr]) return ansl;     return ansr;   }   int main() {     int n;     int d;     cin >> n >> d;     for (__typeof((__typeof(n))0) i((__typeof(n))0); i < n; i++) {       scanf( %lld , &A[i]);       myset.insert(A[i]);       myset.insert(A[i] - d);       myset.insert(A[i] + d);     }     int c = 0;     for (__typeof(myset.begin()) it(myset.begin()); it != myset.end(); it++)       Map[*it] = c++;     N = c;     base = 1;     while (base < N) base *= 2;     for (int i = base; i < 2 * base; i++) T[i] = i - base;     for (int i = base - 1; i > 0; i--) {       T[i] = T[2 * i];       if (ANS[T[2 * i + 1]] > ANS[T[i]]) T[i] = T[2 * i + 1];     }     for (int i = 0; i < n; i++) {       long long h = A[i];       int x = Map[h];       int ans = -1;       qu = Map[h - d];       ql = 0;       ans = query(1, 0, base - 1);       ql = Map[h + d];       qu = N - 1;       int ans2 = query(1, 0, base - 1);       if (ans == -1 || ANS[ans] < ANS[ans2]) ans = ans2;       if (ans == -1 || ANS[ans] == 0) {         ANS[x] = 1;         P[i] = -1;       } else {         ANS[x] = 1 + ANS[ans];         P[i] = Lo[ans];       }       update(x);       Lo[x] = i;     }     int p = 0;     for (int i = 0; i < N; i++)       if (ANS[i] > ANS[p]) p = i;     p = Lo[p];     vector<int> TP;     while (p >= 0) {       TP.push_back(p + 1);       p = P[p];     }     reverse(TP.begin(), TP.end());     cout << (int)(TP.size()) << endl;     for (__typeof(TP.begin()) i(TP.begin()); i != TP.end(); i++)       cout << *i <<    ;     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, x1, y1, x2, y2;     long long int answ = 0;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> x1 >> y1 >> x2 >> y2;       answ += (x2 - x1 + 1) * (y2 - y1 + 1);     }     cout << answ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MX = 1000006;   const long long inf = 1e18;   long long n, m, p, a[MX], ca[MX], b[MX], cb[MX], mn[MX];   long long x[MX], y[MX], z[MX];   long long st[4 * MX + 20], lz[4 * MX + 20], res = -inf;   vector<int> pos[MX];   void push(int i, int j, int pos) {     if (i < j) {       lz[pos * 2] += lz[pos];       lz[pos * 2 + 1] += lz[pos];     }     st[pos] += lz[pos];     lz[pos] = 0;   }   void update(int i, int j, int pos, int a, int b, long long k) {     if (lz[pos]) push(i, j, pos);     if (j < a || b < i) return;     if (a <= i && j <= b) {       lz[pos] = k;       push(i, j, pos);       return;     }     int m = (i + j) / 2;     update(i, m, pos * 2, a, b, k);     update(m + 1, j, pos * 2 + 1, a, b, k);     st[pos] = max(st[pos * 2], st[pos * 2 + 1]);   }   long long query(int i, int j, int pos, int a, int b) {     if (lz[pos]) push(i, j, pos);     if (j < a || b < i) return -inf;     if (a <= i && j <= b) return st[pos];     int m = (i + j) / 2;     return max(query(i, m, pos * 2, a, b), query(m + 1, j, pos * 2 + 1, a, b));   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m >> p;     fill(mn, mn + MX, inf);     for (int i = 1; i <= n; i++) {       cin >> a[i] >> ca[i];       mn[a[i]] = min(mn[a[i]], ca[i]);     }     for (int i = 1; i < MX; i++) update(1, MX - 1, 1, i, i, -mn[i]);     fill(mn, mn + MX, inf);     for (int i = 1; i <= m; i++) {       cin >> b[i] >> cb[i];       mn[b[i]] = min(mn[b[i]], cb[i]);     }     for (int i = 1; i <= p; i++) {       cin >> x[i] >> y[i] >> z[i];       pos[y[i]].push_back(i);     }     for (int i = 1; i < MX - 1; i++) {       for (int j : pos[i - 1]) update(1, MX - 1, 1, x[j] + 1, MX - 1, z[j]);       push(1, MX - 1, 1);       res = max(res, st[1] - mn[i]);     }     cout << res <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 2e9;   const long long INFL = 2e18;   const int N = 1e6, M = N;   int n, m, G = 0;   vector<int> adj[N + 5];   int gr[N + 5], p[N + 5];   vector<int> pth[N + 5];   vector<int> PTH_myEndlessLove;   int Pos[N + 5];   void dfs(int u) {     gr[u] = G;     PTH_myEndlessLove.push_back(u);     for (int i = (0), _b = (((int)(adj[u]).size())); i < _b; ++i) {       int v = adj[u][i];       if (gr[v]) continue;       dfs(v);     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> n >> m;     for (int i = (1), _b = (n); i <= _b; ++i) cin >> p[i];     int u, v;     while (m--) {       cin >> u >> v;       adj[p[u]].push_back(p[v]);       adj[p[v]].push_back(p[u]);     }     for (int i = (1), _b = (n); i <= _b; ++i)       if (!gr[p[i]]) {         PTH_myEndlessLove.clear();         ++G;         dfs(p[i]);         sort(PTH_myEndlessLove.begin(), PTH_myEndlessLove.end());         reverse(PTH_myEndlessLove.begin(), PTH_myEndlessLove.end());         pth[G] = PTH_myEndlessLove;       }     for (int i = (1), _b = (n); i <= _b; ++i) {       cout << pth[gr[p[i]]][Pos[gr[p[i]]]] <<    ;       ++Pos[gr[p[i]]];     }     cout <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char a[10005];   char b[1000005];   vector<int> poj[10005];   int alen, blen;   long long total;   int pos;   vector<int>::iterator it;   int main() {     scanf( %s , a);     scanf( %s , b);     alen = strlen(a), blen = strlen(b);     pos = 0;     total = 1;     for (int i = 0; i <= alen - 1; i++) {       poj[a[i] -  a ].push_back(i);     }     for (int i = 0; i <= 25; i++) {       sort(poj[i].begin(), poj[i].end());     }     for (int i = 0; i <= blen - 1; i++) {       if (poj[b[i] -  a ].empty()) {         printf( -1 n );         return 0;       }       it = lower_bound(poj[b[i] -  a ].begin(), poj[b[i] -  a ].end(), pos);       if (it == poj[b[i] -  a ].end()) {         it = poj[b[i] -  a ].begin();         total++;       }       pos = (*it) + 1;     }     printf( %d n , total);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n{0}, a{0}, m{0}, s{0};     cin >> n;     for (long long int i = 1; i <= n; i++) {       cin >> a;       s += a;       m = max(m, a);     }     if (s % 2 == 1 || s < 2 * m) {       cout <<  NO ;       return 0;     }     cout <<  YES ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 0xffffff;   int LEN;   class Mcmf {    public:     struct T {       int from, to, val;       int next, cost;     } edge[200001];     int len;     int visit[200001], pre[200001], dist[200001], que[200001], vis[200001],         pos[200001];     void init() {       memset(vis, -1, sizeof(vis));       len = 0;     }     void add(int from, int to, int val, int cost) {       edge[len].from = from, edge[len].to = to, edge[len].val = val,       edge[len].cost = cost;       edge[len].next = vis[from], vis[from] = len++;       edge[len].from = to, edge[len].to = from, edge[len].val = 0,       edge[len].cost = -cost;       edge[len].next = vis[to], vis[to] = len++;     }     int SPFA(int s, int t, int n) {       int i, to, k;       for (i = 0; i <= n; i++) {         pre[i] = -1, visit[i] = 0;       }       int head, tail;       head = tail = 0;       for (i = 0; i <= n; i++) dist[i] = inf;       que[tail++] = s, pre[s] = s, dist[s] = 0, visit[s] = 1;       while (head != tail) {         int from = que[head++];         visit[from] = 0;         for (k = vis[from]; k != -1; k = edge[k].next) {           to = edge[k].to;           if (edge[k].val > 0 && dist[from] + edge[k].cost < dist[to]) {             dist[to] = dist[from] + edge[k].cost;             pre[to] = from;             pos[to] = k;             if (!visit[to]) {               visit[to] = 1;               que[tail++] = to;             }           }         }       }       if (pre[t] != -1 && dist[t] < inf) return 1;       return 0;     }     int mnCostFlow(int s, int t, int n) {       if (s == t) {       }       int flow = 0, cost = 0;       while (SPFA(s, t, n)) {         int from, mn = inf;         for (from = t; from != s; from = pre[from])           mn = min(mn, edge[pos[from]].val);         flow += mn;         cost += dist[t] * mn;         for (from = t; from != s; from = pre[from]) {           edge[pos[from]].val -= mn;           edge[pos[from] ^ 1].val += mn;         }       }       if (flow != LEN) return -1;       return cost;     }   };   int n, q;   char s[10010];   int cnt[27];   int tmp[27];   Mcmf mcf;   int main() {     mcf.init();     scanf( %s , s);     LEN = strlen(s);     for (int i = 0; i < LEN; ++i) {       cnt[s[i] -  a ]++;     }     int len;     scanf( %d , &q);     int st = q + 26, en = st + 1, num;     for (int i = 0; i < q; ++i) {       scanf( %s , s);       len = strlen(s);       memset(tmp, 0, sizeof(tmp));       for (int k = 0; k < len; ++k) ++tmp[s[k] -  a ];       for (int k = 0; k < 26; ++k) mcf.add(i, q + k, tmp[k], 0);       scanf( %d , &num);       mcf.add(st, i, num, i + 1);     }     for (int i = 0; i < 26; ++i) mcf.add(q + i, en, cnt[i], 0);     int ans = mcf.mnCostFlow(st, en, en + 1);     printf( %d n , ans);   }


#include <bits/stdc++.h>   using namespace std;   unsigned int dp[100010][400];   vector<int> nima[100010];   int a[100010], b[100010];   int n, m, s, e;   int solve(int all = s, int c = e) {     unsigned int INF = -1;     vector<int> vt[100010];     int cur = 0;     memset(dp, -1, sizeof(dp));     int cnt = (all + c - 1) / c;     for (int i = 0; i < m; ++i) {       vt[b[i]].push_back(i + 1);     }     int ans = 0;     for (int i = 0; i < n; ++i) {       dp[cur][0] = 0;       cur ^= 1;       memset(dp[cur], -1, sizeof(dp[cur]));       for (int j = 1; j < cnt + 1; ++j) {         unsigned int pre = dp[cur ^ 1][j - 1];         unsigned int p =             upper_bound(vt[a[i]].begin(), vt[a[i]].end(), pre) - vt[a[i]].begin();         if (p == vt[a[i]].size())           p = INF;         else           p = vt[a[i]][p];         dp[cur][j] = min(dp[cur ^ 1][j], p);         if (dp[cur ^ 1][j] > p && p + i + j * c <= all) ans = max(ans, j);       }     }     return ans;   }   int main() {     while (cin >> n >> m >> s >> e) {       memset(dp, -1, sizeof(dp));       for (int i = 0; i < n; ++i) {         scanf( %d , &a[i]);       }       for (int i = 0; i < m; ++i) {         scanf( %d , &b[i]);         nima[b[i]].push_back(i + 1);       }       int ans = 0;       int cnt = s / e;       for (int i = 0; i < n; ++i) {         dp[i][0] = 0;         if (nima[a[i]].size())           dp[i][1] = nima[a[i]][0];         else           dp[i][1] = -1;         if (i == 0) continue;         for (int j = 1; j <= cnt; ++j) {           unsigned int now = -1;           int w = a[i];           int last = dp[i - 1][j - 1];           now =               upper_bound(nima[w].begin(), nima[w].end(), last) - nima[w].begin();           if (now == nima[w].size() || dp[i - 1][j - 1] == -1) {             now = -1;           } else {             now = nima[w][now];           }           dp[i][j] = min(dp[i - 1][j], now);         }       }       for (int i = 0; i < n; ++i)         for (int j = 0; j < cnt + 1; ++j) {           if (dp[i][j] != -1) {             if (i + dp[i][j] + 1 + j * e <= s) ans = max(ans, j);           }         }       cout << ans << endl;       return 0;     }   }


#include <bits/stdc++.h>   using namespace std;   int a[11][5];   bool ok(int l, int j, int k) {     int i, an = 0;     for (i = 0; i < 5; i++) {       an = an + (a[j][i] - a[l][i]) * (a[k][i] - a[l][i]);     }     if (an > 0) return false;     return true;   }   int main() {     ios::sync_with_stdio(false);     int i, j, k, n;     cin >> n;     if (n > 11) {       n *= 5;       while (n--) cin >> i;       cout << 0;     } else {       for (i = 0; i < n; i++)         cin >> a[i][0] >> a[i][1] >> a[i][2] >> a[i][3] >> a[i][4];       vector<int> v;       k = n;       j = n;       for (i = 0; i < n; i++) {         k = n;         for (j = 0; j < n && k == n; j++)           for (k = j + 1; k < n; k++) {             if (!ok(i, j, k)) {               break;             }           }         if (j == n && k == n) v.push_back(i + 1);       }       cout << v.size() << endl;       for (i = 0; i < v.size(); i++) cout << v[i] <<     << endl;       ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long int mx = 70, Mod = 1e9 + 7, mxx = 350000;   int n;   int get(int x, int y, int z) {     if (x > y) swap(x, y);     if (x > z) swap(x, z);     if (y > z) swap(y, z);     return x * mx * mx + y * mx + z;   }   bool mark[mxx];   vector<int> e[mxx];   int dp[mxx];   int par[mxx];   short d[mx][mx];   vector<pair<int, int> > res;   void connect(int u, int v) {     e[u].push_back(v);     e[v].push_back(u);   }   void bfs(int v) {     mark[v] = 1;     vector<int> vc;     vc.clear();     vc.push_back(v);     for (int i = 0; i < vc.size(); i++)       for (int u : e[v = vc[i]])         if (!mark[u]) mark[u] = 1, vc.push_back(u), par[u] = v;   }   void move(int u, int v) {     short a[3], b[3];     bool ma[3], mb[3];     for (int i = 0; i < 3; i++) {       a[i] = u % mx;       b[i] = v % mx;       u /= mx;       v /= mx;       ma[i] = 0;       mb[i] = 0;     }     for (int i = 0; i < 3; i++)       for (int j = 0; j < 3; j++)         if (a[i] == b[j]) ma[i] = 1, mb[j] = 1;     for (int i = 0; i < 3; i++) {       if (!ma[i]) u = a[i];       if (!mb[i]) v = b[i];     }     res.push_back(make_pair(u + 1, v + 1));   }   int main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     int x, y, z, u;     cin >> n >> x >> y >> z;     x--, y--, z--;     string s;     for (int i = 0; i < n; i++) {       cin >> s;       for (int j = 0; j < n; j++) d[i][j] = s[j] -  a  + 1;     }     for (int i = 0; i < n; i++) {       for (int j = i + 1; j < n; j++) {         for (int k = j + 1; k < n; k++) {           u = get(i, j, k);           for (int v = min(min(i, j), k) + 1; v < n; v++)             if (v != i && v != j && v != k) {               if (d[v][i] == d[j][k] && v > i) connect(u, get(v, j, k));               if (d[v][j] == d[i][k] && v > j) connect(u, get(v, i, k));               if (d[v][k] == d[i][j] && v > k) connect(u, get(v, i, j));             }         }       }     }     u = get(x, y, z);     if (u == get(0, 1, 2)) return cout <<  0 n , 0;     bfs(get(0, 1, 2));     if (!par[u]) return cout <<  -1 , 0;     while (par[u]) {       move(u, par[u]);       u = par[u];     }     cout << res.size() <<   n ;     for (pair<int, int> p : res) cout << p.first <<     << p.second <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 100;   long long a[maxn];   long long fac[maxn], inv[maxn];   const int mod = 1e9 + 7;   long long Pow(long long x, long long y) {     long long res = 1;     while (y) {       if (y & 1) res = res * x % mod;       x = x * x % mod;       y >>= 1;     }     return res;   }   long long C(int n, int m) {     if (n < m) return 0;     return fac[n] * inv[n - m] % mod * inv[m] % mod;   }   int main() {     fac[0] = inv[0] = 1;     for (int i = 1; i < maxn; i++) {       fac[i] = 1ll * fac[i - 1] * i % mod;       inv[i] = Pow(fac[i], mod - 2);     }     int n;     cin >> n;     for (int i = 1; i <= n; i++) scanf( %lld , &a[i]), a[i] %= mod;     if (n <= 2) {       cout << (a[1] + a[2]) % mod << endl, exit(0);     }     if (n % 2 != 0) {       for (int i = 1; i < n; i++) {         if (i % 2 != 0)           a[i] = (a[i] + a[i + 1]) % mod;         else           a[i] = (a[i] - a[i + 1]) % mod;       }       n -= 1;     }     long long ans1 = 0, ans2 = 0;     for (int i = 1; i <= n; i += 2) {       ans1 = (ans1 + C(n / 2 - 1, (i - 1) / 2) * a[i] % mod) % mod;       ans2 = (ans2 + C(n / 2 - 1, (i - 1) / 2) * a[i + 1] % mod) % mod;     }     if ((1ll * n * (n - 1) / 2) % 2 == 0)       cout << (ans1 - ans2 + mod) % mod << endl;     else       cout << (ans1 + ans2 + mod) % mod << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int df[26];   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     int n, k;     cin >> n >> k;     string s;     cin >> s;     int mini = s.length();     for (int i = 0; i < s.length(); i++) {       df[s[i] -  A ]++;     }     for (int i = 0; i < k; i++) mini = min(mini, df[i]);     cout << k * mini <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     int n, i;     cin >> n;     int a[n], b[n + 1];     for (i = 0; i < n; i++) {       cin >> a[i];       b[a[i]] = i;     }     int l, r, ans[n + 1];     l = b[1];     r = b[1];     for (i = 2; i <= n; i++) {       l = min(l, b[i]);       r = max(r, b[i]);       if ((r - l + 1) != i)         ans[i] = 0;       else         ans[i] = 1;     }     cout << 1;     for (i = 2; i <= n; i++) cout << ans[i];     cout << endl;   }   int main() {     int t;     cin >> t;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   namespace FGF {   int n, m;   const int N = 2e6 + 5;   const int mo = 1e9 + 7;   char s[N];   long long a[N], pw[N], cnt[N];   long long ans;   void FWTxor(long long *y, int op) {     for (int i = 1; i <= n; i++)       for (int j = 0; j < (1 << n); j += (1 << i))         for (int k = 0; k < (1 << (i - 1)); k++) {           long long c = (y[j | k] + y[j | k | (1 << (i - 1))]) % mo,                     d = (y[j | k] - y[j | k | (1 << (i - 1))] + mo) % mo;           y[j | k] = c * op % mo, y[j | k | (1 << (i - 1))] = d * op % mo;         }   }   void work() {     scanf( %d , &n);     scanf( %s , s);     pw[0] = 1;     for (int i = 0; i < (1 << n); i++) a[i] = s[i] -  0 ;     for (int i = 1; i <= n; i++) pw[i] = 2LL * pw[i - 1] % mo;     for (int i = 1; i < (1 << n); i++) cnt[i] = cnt[i >> 1] + (i & 1);     FWTxor(a, 1);     for (int i = 0; i < (1 << n); i++) a[i] = a[i] * a[i] % mo;     FWTxor(a, (mo + 1) / 2);     for (int i = 0; i < (1 << n); i++)       ans = (ans + 1LL * a[i] * pw[n - cnt[i]]) % mo;     printf( %lld , ans * 3 % mo);   }   }  // namespace FGF   int main() {     FGF::work();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const int N = 2e4 + 5;   int sum[55][N], a[55][N];   int lazy[N << 2], tree[N << 2];   int dp[55][N];   void pushdown(int root) {     if (lazy[root]) {       tree[root << 1] += lazy[root];       tree[root << 1 | 1] += lazy[root];       lazy[root << 1] += lazy[root];       lazy[root << 1 | 1] += lazy[root];       lazy[root] = 0;     }   }   void update(int root, int l, int r, int L, int R, int val) {     if (L <= l && r <= R) {       tree[root] += val;       lazy[root] += val;       return;     }     pushdown(root);     int mid = (l + r) >> 1;     if (L <= mid) update(root << 1, l, mid, L, R, val);     if (R > mid) update(root << 1 | 1, mid + 1, r, L, R, val);     tree[root] = max(tree[root << 1], tree[root << 1 | 1]);   }   int getsum(int x1, int y1, int x2, int y2) {     return sum[x2][y2] - sum[x1 - 1][y2] - sum[x2][y1 - 1] + sum[x1 - 1][y1 - 1];   }   int main() {     int n, m, k;     scanf( %d%d%d , &n, &m, &k);     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         scanf( %d , &a[i][j]);         sum[i][j] = sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] + a[i][j];       }     }     for (int i = 1; i <= m; i++) {       dp[1][i] = getsum(1, i, min(2, n), min(m, i + k - 1));     }     for (int i = 2; i <= n; i++) {       memset(lazy, 0, sizeof lazy);       memset(tree, 0, sizeof tree);       for (int j = 1; j <= m; j++) {         update(1, 1, m, j, j, dp[i - 1][j]);       }       for (int j = 1; j <= k; j++) {         update(1, 1, m, 1, j, -a[i][j]);       }       for (int j = 1; j <= m; j++) {         dp[i][j] = tree[1] + getsum(i, j, min(n, i + 1), min(m, j + k - 1));         update(1, 1, m, max(j - k + 1, 1), j, a[i][j]);         if (j + k <= m) {           update(1, 1, m, j + 1, j + k, -a[i][j + k]);         }       }     }     int ans = 0;     for (int i = 1; i <= m; i++) {       ans = max(ans, dp[n][i]);     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long inf = 707406378;   const int maxn = 1.5e7 + 10;   void read(long long &x) {     char ch;     bool flag = 0;     for (ch = getchar(); !isdigit(ch) && ((flag |= (ch ==  - )) || 1);          ch = getchar())       ;     for (x = 0; isdigit(ch); x = (x << 1) + (x << 3) + ch - 48, ch = getchar())       ;     x *= 1 - 2 * flag;   }   int main() {     long long n, x, y;     cin >> n;     long long ans = 0;     for (int i = 0; i < n; i++) {       cin >> x >> y;       ans = max(ans, x + y);     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   const int p = 998244353;   const int inv2 = 499122177;   const int MAXN = 140000;   inline long long read() {     long long x = 0, f = 1;     char ch = getchar();     while (ch >  9  || ch <  0 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     do x = (x * 10 + ch - 48) % p, ch = getchar();     while (ch >=  0  && ch <=  9 );     return (x * f % p + p) % p;   }   int n, k, r[MAXN];   long long c[MAXN] = {1, 6, 1};   long long s[MAXN], f[MAXN], g[MAXN];   long long fastpow(long long a, int b) {     long long res = 1;     a %= p;     while (b) {       if (b & 1) res = res * a % p;       a = a * a % p;       b >>= 1;     }     return res;   }   void NTT(long long *a, int N) {     for (int i = 0; i < N; i++)       if (i < r[i]) std::swap(a[i], a[r[i]]);     for (int n = 2, m = 1; n <= N; m = n, n <<= 1) {       long long g1 = fastpow(3, (p - 1) / n);       for (int l = 0; l < N; l += n) {         long long g = 1, t1, t2;         for (int i = l; i < l + m; i++) {           t1 = a[i], t2 = g * a[i + m] % p;           a[i] = (t1 + t2) % p;           a[i + m] = (t1 - t2 + p) % p;           g = g * g1 % p;         }       }     }     return;   }   void INTT(long long *a, int N) {     NTT(a, N);     std::reverse(a + 1, a + N);     int invN = fastpow(N, p - 2);     for (int i = 0; i < N; i++) a[i] = a[i] * invN % p;   }   long long a1[MAXN], b1[MAXN];   void Inv(long long *a, long long *b, int n) {     if (n == 1) return void(b[0] = fastpow(a[0], p - 2));     Inv(a, b, (n + 1) >> 1);     int N = 1, l = -1;     while (N <= n << 1) N <<= 1, l++;     for (int i = 1; i < N; i++) r[i] = (r[i >> 1] >> 1) | ((i & 1) << l);     for (int i = 0; i < n; i++) a1[i] = a[i];     for (int i = n; i < N; i++) a1[i] = 0;     NTT(a1, N);     NTT(b, N);     for (int i = 0; i < N; i++)       b[i] = ((b[i] << 1) % p + p - a1[i] * b[i] % p * b[i] % p) % p;     INTT(b, N);     for (int i = n; i < N; i++) b[i] = 0;     return;   }   void Dervt(long long *a, long long *b, int n) {     for (int i = 1; i < n; i++) b[i - 1] = a[i] * i % p;     b[n - 1] = 0;   }   void Integ(long long *a, long long *b, int n) {     for (int i = 1; i < n; i++) b[i] = a[i - 1] * fastpow(i, p - 2) % p;     b[0] = 0;   }   long long f1[MAXN], f2[MAXN];   void Ln(long long *f, long long *g, int n) {     memset(f1, 0, sizeof(f1));     memset(f2, 0, sizeof(f2));     Dervt(f, f1, n);     Inv(f, f2, n);     int N = 1, l = -1;     while (N <= n << 1) N <<= 1, l++;     for (int i = 1; i < N; i++) r[i] = (r[i >> 1] >> 1) | ((i & 1) << l);     NTT(f1, N);     NTT(f2, N);     for (int i = 0; i < N; i++) f1[i] = f1[i] * f2[i] % p;     INTT(f1, N);     Integ(f1, g, n);     return;   }   long long g1[MAXN];   void Exp(long long *f, long long *g, int n) {     if (n == 1) return void(g[0] = 1);     Exp(f, g, (n + 1) >> 1);     Ln(g, g1, n);     int N = 1, l = -1;     while (N <= n << 1) N <<= 1, l++;     for (int i = 1; i < N; i++) r[i] = (r[i >> 1] >> 1) | ((i & 1) << l);     for (int i = 0; i < n; i++) f1[i] = f[i];     for (int i = n; i < N; i++) g1[i] = f1[i] = 0;     for (int i = 0; i < N; i++) f1[i] = ((f1[i] - g1[i]) % p + p) % p;     f1[0] = (f1[0] + 1) % p;     NTT(f1, N);     NTT(g, N);     for (int i = 0; i < N; i++) g[i] = f1[i] * g[i] % p;     INTT(g, N);     for (int i = n; i < N; i++) g[i] = 0;     return;   }   long long lnf[MAXN];   void Pow(long long *f, long long *g, int n, int k) {     Ln(f, lnf, n);     for (int i = 0; i < n; i++) lnf[i] = lnf[i] * k % p;     memset(g, 0, sizeof(g1));     Exp(lnf, g, n);     return;   }   int main() {     n = read();     int t = read();     k = std::min(n, t);     int N = 1, l = -1;     while (N <= (k + 1) << 1) N <<= 1, l++;     for (int i = 1; i < N; i++) r[i] = (r[i >> 1] >> 1) | ((i & 1) << l);     Pow(c, s, k + 1, inv2 - 1);     Pow(c, f, k + 1, inv2);     f[0]++, f[1]++;     for (int i = 0; i <= k; i++) f[i] = f[i] * inv2 % p;     Pow(f, g, k + 1, n + 1);     NTT(s, N);     NTT(g, N);     for (int i = 0; i < N; i++) s[i] = s[i] * g[i] % p;     INTT(s, N);     for (int i = 1; i <= k; i++) std::printf( %lld  , s[i]);     for (int i = k + 1; i <= t; i++) std::printf( 0  );     std::putchar(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int gcd(long long int x, long long int y) {     if (y > x) {       return gcd(y, x);     }     if (y == 0) {       return x;     }     return gcd(y, x % y);   }   bool prime(long long int x) {     for (long long int i = 2; i <= sqrt(x); i++) {       if (x % i == 0) {         return 0;       }     }     return 1;   }   long long int fact(long long int n) {     if (n == 0) {       return 1;     }     return n * fact(n - 1);   }   void solve() {     long long int r, c;     cin >> r >> c;     long long int b = 1;     for (long long int i = 0; i < r; i++) {       if (i % 2 == 0) {         for (long long int j = 0; j < c; j++) cout <<  # ;         cout << endl;       } else {         if (b == 1) {           for (long long int j = 0; j < c - 1; j++) cout <<  . ;           cout <<  # ;           cout << endl;           b = 0;         } else {           cout <<  # ;           for (long long int j = 0; j < c - 1; j++) cout <<  . ;           cout << endl;           b = 1;         }       }     }   }   int32_t main() {     ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);     long long int t = 1;     while (t--) solve();     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<int> v(n);     for (int i = 0; i < n; i++) cin >> v[i];     sort(v.begin(), v.end());     vector<int> w(n, 0);     w[0] = v[0];     for (int i = 1; i < n; i++) w[i] = w[i - 1] + v[i];     int score = 0, penalty = 0;     for (int i = 0; i < n; i++) {       if (w[i] <= 60 * 12 - 10)         score++;       else         break;       if (w[i] > 60 * 6 - 10) penalty += w[i] - 60 * 6 + 10;     }     cout << score <<     << penalty << endl;   }


#include <bits/stdc++.h>   using namespace std;   int freq[200005];   int arr[1005];   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     int n;     cin >> n;     for (int i = 1; i <= n; i++) cin >> arr[i];     for (int i = 1; i <= n; i++)       for (int j = i + 1; j <= n; j++) freq[arr[i] + arr[j]]++;     int ans = 0;     for (int i = 0; i < 2e5 + 5; i++) ans = max(ans, freq[i]);     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct __timestamper {};   struct change {     int s, t, u;   };   vector<long long> solve(vector<int> a, vector<change> b) {     long long sum = 0;     for (auto x : a) sum += x;     vector<long long> ans;     int n = a.size();     vector<int> cntr(n);     auto change_counter = [&](int i, int delta) {       sum -= max(0, a[i] - cntr[i]);       cntr[i] += delta;       sum += max(0, a[i] - cntr[i]);     };     map<pair<int, int>, int> mp;     for (auto c : b) {       auto it = mp.find({c.s, c.t});       if (it != mp.end()) {         change_counter(it->second, -1);         mp.erase(it);       }       if (c.u != -1) {         mp[{c.s, c.t}] = c.u;         change_counter(c.u, +1);       }       ans.push_back(sum);     }     return ans;   }   int main() {     int n;     while (scanf( %d , &n) == 1) {       vector<int> a(n);       for (int i = 0; i < n; i++) {         scanf( %d , &a[i]);       }       int q;       scanf( %d , &q);       vector<change> b(q);       for (int i = 0; i < q; i++) {         scanf( %d%d%d , &b[i].s, &b[i].t, &b[i].u);         b[i].s--;         b[i].u--;       }       auto ans = solve(a, b);       for (auto x : ans) printf( %lld n , x);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int x, y = 0, z = 0;     for (int i = 0; i < n; i++) {       cin >> x;       if (x != y) {         z++;       }       y = x;     }     cout << z;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, t[100001], ans;   double w;   long long lowbit(long long x) { return x & (-x); }   struct rua {     double x, v;     long long id;   } _[100001];   void change(long long x) {     while (x <= n) t[x]++, x += lowbit(x);   }   int sum(long long k) {     long long res = 0;     while (k > 0) res += t[k], k -= lowbit(k);     return res;   }   bool cmp(rua a, rua b) { return fabs(a.x * b.v) < fabs(a.v * b.x); }   int main() {     scanf( %I64d%lf , &n, &w), w += 1e-6;     for (long long i = 1; i <= n; i++)       scanf( %lf%lf , &_[i].x, &_[i].v), _[i].v -= w;     sort(_ + 1, _ + n + 1, cmp);     for (long long i = 1; i <= n; i++) _[i].id = i, _[i].v += 2 * w;     sort(_ + 1, _ + n + 1, cmp);     for (long long i = 1; i <= n; i++)       ans += i - 1 - sum(_[i].id), change(_[i].id);     return printf( %I64d n , ans), 0;   }


#include<cstdio>   #include<cstring>   #include<algorithm>   using namespace std;   char ch;   int t,n,k,h[110],pos;   void read(int &x)   {    x=0;    ch=getchar();    while(ch< 0 ||ch> 9 ) ch=getchar();    while(ch>= 0 &&ch<= 9 )    {      x=x*10+ch- 0 ;     ch=getchar();    }   }   int main()   {    read(t);    while(t--)    {     read(n);read(k);     for (int i=1;i<=n;i++) read(h[i]);     while(k--)     {      pos=0;      for (int j=1;j<=n;j++)       if (j==n) pos=-1;       else if (h[j]<h[j+1]) {h[j]++;pos=j;break;}      if (pos==-1) break;     }      printf( %d n ,pos);    }    return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     scanf( %d , &n);     vector<long long> X(n + 1), Y(n + 1);     for (int i = (1); i <= (n); ++i) scanf( %lld%lld , &X[i], &Y[i]);     long long S = 0;     for (int k = (1); k <= (n); ++k) {       vector<double> V;       for (int i = (1); i <= (n); ++i)         if (i != k) V.push_back(atan2(Y[i] - Y[k], X[i] - X[k]));       sort(V.begin(), V.end());       V.insert(V.end(), V.begin(), V.end());       for (int i = 0, j = 0; i + 1 < n; i++) {         while (V[j] + (j >= n - 1 ? 2 * acos(-1) : 0.0) - V[i] < acos(-1)) j++;         long long x = j - 1 - i, y = n - 2 - x;         S += x * (x - 1) / 2 * y * (y - 1) / 2;       }     }     printf( %lld n , S / 2);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int sum, len;   string s;   int cnt[26][5010][26];   int main() {     cin >> s;     sum = 0;     len = s.length();     s += s;     memset(cnt, 0, sizeof(cnt));     for (int i = 0; i < len; i++) {       for (int j = 1; j < len; j++) {         cnt[s[i] -  a ][j][s[i + j] -  a ]++;       }     }     for (int i = 0; i < 26; i++) {       int mx = 0;       for (int j = 1; j < len; j++) {         int tmp = 0;         for (int k = 0; k < 26; k++)           if (cnt[i][j][k] == 1) tmp++;         mx = max(mx, tmp);       }       sum += mx;     }     printf( %.10lf n , (double)sum / (double)len);   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 5;   bool vis[N];   vector<int> prime;   void sieve() {     for (int i = 2; i * i < N; i++) {       if (vis[i]) continue;       for (int j = 2; j * i < N; j++) {         vis[i * j] = 1;       }     }     for (int i = 2; i < N; i++) {       if (vis[i] == 0) prime.push_back(i);     }   }   int find(int x) {     int ans = upper_bound(prime.begin(), prime.end(), x) - prime.begin() - 1;     return ans;   }   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     sieve();     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       int ans = find(n) - find(sqrt(n)) + 1;       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int Inf = (1 << 30) - 1;   const long long lInf = (1LL << 62) - 1;   const int mInf = 0x7f7f7f7f;   const int Maxn = 200010;   vector<int> a[Maxn];   pair<int, int> S[Maxn << 1];   int f[Maxn];   int t[Maxn];   int n, m, ans;   void solve(int k) {     map<int, int> M;     for (int i = 1; i <= n; i++) M[++f[i]] = i;     for (int i = 1; i <= n; i++) t[i] = a[i][k];     int cnt = 0, tot = 0, minn = Inf;     for (int i = 1; i <= n; i++) {       int tmp = M[t[i]];       if (tmp != 0 && i - tmp != 0)         S[++tot] = make_pair(i - tmp > 0 ? i - tmp : i - tmp + n, 1);       if (tmp != 0)         S[++tot] = make_pair(i - tmp + 1 > 0 ? i - tmp + 1 : i - tmp + n + 1, -1);       if (t[i] == f[i]) cnt++;     }     sort(S + 1, S + tot + 1);     minn = min(minn, n - cnt);     int p = 1;     for (int i = 1; i < n; i++) {       while (S[p].first <= i && p <= tot) cnt += S[p++].second;       minn = min(minn, i + n - cnt);     }     ans += minn;   }   int main() {     ios::sync_with_stdio(false);     cin >> n >> m;     for (int i = 1; i <= n; i++) {       a[i].push_back(0);       for (int x, j = 1; j <= m; j++) cin >> x, a[i].push_back(x);     }     for (int i = 1; i <= n; i++) f[i] = (i - 1) * m;     for (int i = 1; i <= m; i++) solve(i);     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, s, f, add = 0, rund = 1;     cin >> n >> m >> s >> f;     if (s < f)       add = 1;     else       add = -1;     for (int i = 0; i < m; i++) {       int t, l, r;       cin >> t >> l >> r;       while (rund < t) {         if (s == f) break;         if (add == 1)           cout <<  R ;         else if (add == -1)           cout <<  L ;         s += add;         rund++;       }       if (s == f) continue;       if (t == rund) {         rund++;         if (s >= l && s <= r || s + add >= l && s + add <= r)           cout <<  X ;         else if (add == 1) {           cout <<  R ;           s += add;         } else if (add == -1) {           cout <<  L ;           s += add;         }       }     }     while (s != f) {       if (add == 1)         cout <<  R ;       else if (add == -1)         cout <<  L ;       s += add;     }     cout << endl;     return 0;   }